Skip to content

Vue 3

next-grid-vue wraps next-grid-js/core as a generic <NextGrid /> component for Vue 3.4+ with Teleport-mounted renderers and editors.

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

Peers: next-grid-js 0.1, vue 3.4 or later.

<script setup lang="ts">
import { shallowRef } from 'vue';
import type { ColumnDef } from 'next-grid-js/core';
import { NextGrid, type NextGridExposed } from 'next-grid-vue';
import 'next-grid-js/styles.css';
interface Order {
id: string;
customer: string;
total: number;
}
const props = defineProps<{ orders: Order[] }>();
const grid = shallowRef<NextGridExposed<Order> | null>(null);
const columnDefs: ColumnDef<Order>[] = [
{ colId: 'customer', key: 'customer', isSortable: true },
{ colId: 'total', key: 'total', cellDataType: 'number' },
];
</script>
<template>
<NextGrid
ref="grid"
style="height: 400px"
:column-defs="columnDefs"
:row-data="props.orders"
:get-row-id="(order: Order) => order.id"
@sort-changed="(event) => console.log(event.sort)"
/>
</template>
  • Events: Pass listeners as @sort-changed, @selection-changed, etc.
  • Reactivity: Prefer shallowRef for large rowData arrays so Vue does not recursively proxy every row field. Value-compared options (pinnedRows, pivot, cellSpans, columnGroups) can be mutated in place inside reactive state or replaced.
  • API Access: Access the underlying Grid<T> via grid.value?.grid on the template ref (NextGridExposed<T>).
import { vueCellEditor, vueCellRenderer } from 'next-grid-vue';
const columnDefs = [
{
colId: 'total',
key: 'total',
isEditable: true,
cellRenderer: vueCellRenderer(Total),
cellEditor: vueCellEditor(TotalEditor),
},
];

Cell components receive params (CellRendererParams<T> or VueCellEditorParams<T>) and render via Teleport, keeping provide/inject, Vue Router, and Pinia stores accessible.

On the server, <NextGrid /> renders an empty container element and initializes the grid only on the client.