gridcn2.0.0
Support and upgrades

Migrate to 2.0

Move a grid from 1.3 to 2.0. Replace the lazy rows add-on with server rows, apply each breaking change, and check the changed behavior.

Follow these steps to move a grid from gridcn 1.3 to 2.0. 2.0 breaking changes lists each change with its 1.3 form, its 2.0 form, and the change to make.

Upgrade to 1.3.0 and commit your work first. For an older version, apply the Breaking: entries up to 1.3.0, as Upgrade gridcn shows.

Steps

  1. Reinstall the core and each add-on that you use, as Upgrade gridcn shows. Leave out data-grid-lazy, because 2.0 has no such item. If you used it, install data-grid-server instead.
  2. If you used data-grid-lazy, move each grid to useDataGridServerRows, as Server rows shows. Then delete the components/data-grid-lazy/ folder. A reinstall does not remove it.
  3. Run npx tsc --noEmit. Each error names a removed or renamed identifier. Find the identifier on 2.0 breaking changes and apply its row.
  4. Search your CSS and selectors for data-pinned="left", data-grid-pin-shadow, data-scrolled-left, and --grid-pin-shadow-left-x, and their right forms. Rename them as the pin rows show. The type check does not see these names.
  5. Check the behavior changes, which compile without an error. The type check does not report them:
  6. Run your tests.

The type check and the tests pass. Each grid sorts, checks rows, and writes data as your code expects.

Server rows

useDataGridServerRows({ mode: "scroll" }) from data-grid-server replaces useDataGridLazyRows. DataGridLazyGuard has no replacement. If a client sort or filter changes over unloaded rows, the core warns in development.

1.32.0
fetchRows(start, end, signal) resolves the rowsfetchRows({ start, end, signal }) resolves { rows, totalRowCount?, hasMore?, nextCursor? }
totaltotalRowCount in the answer
batchSizeblockSize
reset(), isLoadingrefresh(), loading
Range from data-grid-lazyRowRange from data-grid
maxFetchRowsnone (one block for each request)
onError(error, range)onError(error)

Remove your onRenderedRowsChange and onDataChange wiring, and spread server.gridProps:

"use client";

import { DataGrid, defineColumns } from "@/components/data-grid/data-grid";
import {
  useDataGridServerRows,
} from "@/components/data-grid-server/data-grid-server";

type Order = { id: string; customer: string };

const columns = defineColumns<Order>()([
  { id: "customer", header: "Customer", accessorKey: "customer" },
]);

export function OrdersGrid() {
  const server = useDataGridServerRows<Order>({
    mode: "scroll",
    blockSize: 100,
    fetchRows: async ({ start, end, signal }) => {
      const query = `offset=${start}&limit=${end - start}`;
      const response = await fetch(`/api/orders?${query}`, { signal });
      const answer = await response.json();
      return { rows: answer.rows, totalRowCount: answer.total };
    },
  });

  return <DataGrid {...server.gridProps} columns={columns} className="h-96" />;
}

Scroll mode starts a block request after loadDelayMs milliseconds (default 100). Pass loadDelayMs: 0 for the 1.3 timing. It keeps at most maxLoadedRows rows (default 10,000). Infinity keeps every row.

On this page