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.
Installation
Section titled “Installation”npm install next-grid-vue next-grid-js vuePeers: 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
shallowReffor largerowDataarrays so Vue does not recursively proxy every row field. Value-compared options (pinnedRows,pivot,cellSpans,columnGroups) can be mutated in place insidereactivestate or replaced. - API Access: Access the underlying
Grid<T>viagrid.value?.gridon the template ref (NextGridExposed<T>).
Cell Renderers & Editors (Teleport)
Section titled “Cell Renderers & Editors (Teleport)”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.
Server Rendering (Nuxt / SSR)
Section titled “Server Rendering (Nuxt / SSR)”On the server, <NextGrid /> renders an empty container element and initializes the grid only on the client.