Skip to content

Svelte 5

next-grid-svelte provides the use:nextGrid action and Svelte 5 component cell renderers/editors over next-grid-js/core.

Terminal window
npm install next-grid-svelte next-grid-js svelte

Peers: 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.raw for Rows: Keep rowData in $state.raw (or plain props) rather than deep $state proxies.
  • context & onGrid: Both are read once when the action mounts (onGrid receives Grid<T> on mount and null on destroy).
  • Remounting: Wrap the element in {#key ...} when changing construction-only options such as density or localeText.
import { svelteCellEditor, svelteCellRenderer } from 'next-grid-svelte';
const columnDefs = [
{
colId: 'total',
key: 'total',
isEditable: true,
cellRenderer: svelteCellRenderer(Total),
cellEditor: svelteCellEditor(TotalEditor),
},
];
  • Renderers receive params as a Svelte store ($params.value) inside SvelteCellRendererProps<T>.
  • Editors receive params as a plain object (params.setValue(...), params.commit(), params.cancel()) inside SvelteCellEditorProps<T>.

Svelte actions do not execute on the server; the host element renders empty during SSR and mounts the grid on the client.