DHTMLX Spreadsheet. Svelte integration example
Demo of DHTMLX Spreadsheet integration with Svelte using the official GitHub demo. Shows initialization and cleanup for a Svelte-based DHTMLX Spreadsheet component.
View on GitHub - open the repository and click "Open in Codespaces" on the README page to launch a fully configured Svelte app with DHTMLX Spreadsheet in seconds. No local setup required.
DHTMLX Spreadsheet integrates with Svelte using standard lifecycle functions: onMount for initialization and onDestroy for cleanup. The component binds a container element with bind:this, creates the Spreadsheet instance on mount, loads data via parse(), and destroys the instance when the component is removed from the DOM.
The demo component imports the Spreadsheet class and CSS, receives data as a prop from the parent App.svelte, and initializes the widget inside onMount. The parent component calls getData(), which returns an object with sheets (sheet configurations with cell values and formulas), styles (custom CSS class definitions), and formats (number, date, and currency format masks), and passes it as a prop. The onDestroy callback calls spreadsheet.destructor() to release all resources and prevent memory leaks.
The linked GitHub repository provides a complete Svelte project with data generation, container styling, and Codespaces support. One click on "Open in Codespaces" launches a fully functional development environment.
Solution overview
- Bind a container element with
bind:this={container} - Initialize the Spreadsheet in
onMountwithnew Spreadsheet(container, config) - Load data via
spreadsheet.parse(data)from the component prop - Call
spreadsheet.destructor()inonDestroy
Key points
- Lifecycle alignment:
onMountandonDestroymap directly to the Spreadsheet's create/destroy cycle - Container binding: Svelte's
bind:thisprovides the DOM reference needed by the Spreadsheet constructor - Package options: Import from
@dhx/trial-spreadsheetfor evaluation or the PRO package for production