Svelte 5
next-grid-svelte provides the use:nextGrid action and Svelte 5 component cell renderers/editors over next-grid-js/core.
Installation
Section titled “Installation”npm install next-grid-svelte next-grid-js sveltePeers: next-grid-js 0.1, svelte 5.46 or later. The package ships compiled JavaScript and requires no custom Svelte preprocessor.
<script lang="ts"> import { getAllContexts } from 'svelte'; import type { ColumnDef, Grid } from 'next-grid-js/core'; import { nextGrid } from 'next-grid-svelte'; import 'next-grid-js/styles.css';
interface Order { id: string; customer: string; total: number; }
let { orders }: { orders: Order[] } = $props(); let grid: Grid<Order> | null = null; const columnDefs: ColumnDef<Order>[] = [ { colId: 'customer', key: 'customer', isSortable: true }, { colId: 'total', key: 'total', cellDataType: 'number' }, ]; const context = getAllContexts();</script>
<div style="height: 400px" use:nextGrid={{ columnDefs, rowData: orders, getRowId: (order: Order) => order.id, context, onGrid: (created) => (grid = created), onSortChanged: (event) => console.log(event.sort), }}></div>$state.rawfor Rows: KeeprowDatain$state.raw(or plain props) rather than deep$stateproxies.context&onGrid: Both are read once when the action mounts (onGridreceivesGrid<T>on mount andnullon destroy).- Remounting: Wrap the element in
{#key ...}when changing construction-only options such asdensityorlocaleText.
Cell Renderers & Editors
Section titled “Cell Renderers & Editors”import { svelteCellEditor, svelteCellRenderer } from 'next-grid-svelte';
const columnDefs = [ { colId: 'total', key: 'total', isEditable: true, cellRenderer: svelteCellRenderer(Total), cellEditor: svelteCellEditor(TotalEditor), },];- Renderers receive
paramsas a Svelte store ($params.value) insideSvelteCellRendererProps<T>. - Editors receive
paramsas a plain object (params.setValue(...),params.commit(),params.cancel()) insideSvelteCellEditorProps<T>.
Server Rendering (SvelteKit)
Section titled “Server Rendering (SvelteKit)”Svelte actions do not execute on the server; the host element renders empty during SSR and mounts the grid on the client.