DHTMLX Pivot. Vue demo example
Demo of DHTMLX Pivot integration with Vue.js. Access the official GitHub repository with a ready-to-run Vue application featuring DHTMLX Pivot, launchable directly via GitHub Codespaces.
View on GitHub - open the repository and click "Open in Codespaces" on the README page to launch a fully configured Vue app with DHTMLX Pivot in seconds. No local setup required.
DHTMLX Pivot integrates with Vue using the Options API - the mounted() hook for initialization and unmounted() for cleanup. The official demo wraps the entire pivot in a single reusable component that uses this.$refs.container for DOM access, working like any other Vue component in your application.
The demo component creates a Pivot instance in mounted(), passing this.$refs.container as the mount point along with configuration for fields, data, headerShape, tableShape, columnShape, and config (rows, columns, values). The unmounted() hook calls this.table.destructor() for proper resource management. Props fields and dataset flow from the parent App.vue, keeping data management in Vue's layer.
This example links to the official DHTMLX Pivot Vue demo on GitHub, which demonstrates the recommended integration pattern. You can launch the demo directly in GitHub Codespaces from the repository's README page. The demo covers this.$refs container binding, mounted() initialization, and cleanup on component destruction.
Solution overview
To integrate DHTMLX Pivot with Vue, follow the standard widget lifecycle pattern:
- Bind the container using a template
ref="container"attribute and access it viathis.$refs.containerin the component - Vue resolves template refs before themounted()hook runs, so the DOM element is guaranteed to be available. - Initialize in
mounted()- callnew Pivot(this.$refs.container, config)after Vue renders the template, passingfields,data, and pivot configuration (headerShape,tableShape,columnShape,configwith rows, columns, values). - Pass data via props - the parent
App.vueprovidesfieldsanddatasetprops, keeping data loading separate from the widget lifecycle. - Clean up in
unmounted()by callingthis.table.destructor()to remove all event listeners and internal state, preventing memory leaks during route navigation.
Key points
this.$refs.containerfor DOM binding: The templaterefattribute provides a stable reference to the container<div>, accessed in themounted()hook when the DOM is guaranteed to be ready- Initialization in
mounted(): Creates thePivotinstance usingthis.$refs.containeras the mount point, with full configuration for fields, data, header/table/column shapes, and row/column/value definitions - Mandatory
destructor()inunmounted(): Callsthis.table.destructor()to prevent memory leaks, especially in single-page applications with Vue Router where components mount and unmount during navigation - GitHub Codespaces support: The official demo repository supports one-click launch via "Open in Codespaces", providing a fully configured development environment without local setup