Pagination
Enable client pagination to split filtered and sorted rows into fixed pages with built-in footer controls (first/previous/next/last page, rows-per-page selector, and row range readout).
import { Grid, type ColumnDef } from 'next-grid-js';import { createOrders, type OrderRow } from './data/orders';import { syncGridTheme } from './theme';import type { DemoMountContext } from './types';import { addButton } from './ui';
export function mount({ stage, controls, meta,}: DemoMountContext): () => void { const columnDefs: readonly ColumnDef<OrderRow>[] = [ { key: 'id', name: 'ID', width: 96, isSortable: true, }, { key: 'customer', name: 'Customer', width: 175, flex: 1, isSortable: true, }, { key: 'region', name: 'Region', width: 110, isSortable: true, }, { key: 'amount', name: 'Amount', width: 115, cellDataType: 'number', isSortable: true, formatter: ({ value }) => `$${Number(value).toLocaleString('en-US')}`, }, ];
const grid = new Grid<OrderRow>({ container: stage, columnDefs, rowData: createOrders(85), getRowId: (row) => row.id, rowSelection: { mode: 'multiple', showCheckbox: true, }, initialState: { version: 5, pagination: { enabled: true, page: 0, pageSize: 10, }, }, }); const stopTheme = syncGridTheme(stage);
const updateMeta = () => { const p = grid.getPaginationState(); meta.textContent = `Page ${p.page + 1} · Size ${p.pageSize}`; }; grid.addEventListener('paginationChanged', updateMeta);
addButton(controls, 'Select page', () => grid.selectAllRows('page')); addButton(controls, 'Page size 25', () => { grid.setPaginationState({ enabled: true, page: 0, pageSize: 25, }); }); addButton(controls, 'Page size 10', () => { grid.setPaginationState({ enabled: true, page: 0, pageSize: 10, }); }); updateMeta();
return () => { grid.destroy(); stopTheme(); };}Configuration & API
Section titled “Configuration & API”// Enable at construction via initialState, or toggle dynamically:grid.setPaginationState({ enabled: true, page: 0, // 0-based page index pageSize: 25,});
const pagination = grid.getPaginationState();- Automatic Page Clamping: If filtering or row removals shrink the dataset so
pageexceeds the last valid page, NextGrid clampspageautomatically to the new final page. - Page-Scoped Selection & Export:
grid.selectAllRows('page')selects only the rows on the current page.grid.exportData({ format: 'csv', rows: 'page' })exports only the current page (while'filtered'exports all matching rows across all pages).
- Footer Appearance: The footer bar mounts automatically whenever
pagination.enabledistrue,dataExportis configured, or layout recovery buttons appear.