Synertech Web/ui v0.57.5 Site Storybook

Documentation / Data

DataGrid

Client@synertech/uiOpen in Storybook

The library’s data grid: a table driven by column definitions (columns) and an array of objects (data), which can sort, paginate, search, filter, select, edit, group, aggregate and export. For a plain presentational table, Table is enough.

Every piece of state (sort, page, selection, search, filters, expanded rows, hidden columns) exists in an uncontrolled version — the grid holds it itself — or controlled through the matching prop and its callback (sort / onSort, selectedRows / onSelectionChange…). In mode="server", the grid no longer applies sorting, filtering or pagination: it shows data as is and lets the application reload the requested page (totalItems then gives the total row count).

A view — sort, filters, search, hidden columns, column order and widths, page size — is read and put back in one piece: defaultView to start from one, onViewChange to save it on every change, getView() / setView() through the ref. bulkActions puts a bar of actions above the selected rows.

From the keyboard, the header does what the pointer does: a button sorts the column (Enter or Space), its handle resizes it with the arrows (Shift for a larger step, Home and End for its bounds), and the column menu of the toolbar moves it one place.

Always pass rowKey (a key of the model or a function): the selection, the expanded rows and the edits are held by that key. Without it, a row is known by its position in data: that holds while data keeps its order, and shifts as soon as it is refetched or paged by a server. A ref gives access to an imperative API (DataGridRef). The component is marked "use client".

Examples

Sorting and pagination

Sorting is declared per column (sortable); defaultSort sets the initial order and pagination splits the rows into pages.

Open in a tab
import { DataGrid, type ColumnDef } from "@synertech/ui";

interface Invoice {
  id: string;
  client: string;
  city: string;
  amount: number;
  status: "Payée" | "En attente" | "En retard";
  date: string;
}

const euro = new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR" });

const columns: ColumnDef<Invoice>[] = [
  { key: "id", header: "Facture", sortable: true, width: 110 },
  { key: "client", header: "Client", sortable: true },
  { key: "city", header: "Ville", sortable: true },
  {
    key: "amount",
    header: "Montant",
    sortable: true,
    align: "right",
    render: (value) => euro.format(value as number),
  },
  { key: "status", header: "Statut" },
];

const invoices: Invoice[] = [
  {
    id: "F-031",
    client: "Atelier Dupont",
    city: "Lyon",
    amount: 1250,
    status: "Payée",
    date: "2026-09-02",
  },
  {
    id: "F-032",
    client: "Boulangerie Petit",
    city: "Paris",
    amount: 380,
    status: "En attente",
    date: "2026-09-08",
  },
  {
    id: "F-033",
    client: "Garage Moreau",
    city: "Lyon",
    amount: 2140,
    status: "En retard",
    date: "2026-09-15",
  },
  {
    id: "F-034",
    client: "Cabinet Leroy",
    city: "Bordeaux",
    amount: 960,
    status: "Payée",
    date: "2026-09-21",
  },
  {
    id: "F-035",
    client: "Fleurs Bernard",
    city: "Paris",
    amount: 215,
    status: "Payée",
    date: "2026-10-01",
  },
  {
    id: "F-036",
    client: "Imprimerie Roux",
    city: "Nantes",
    amount: 1780,
    status: "En attente",
    date: "2026-10-04",
  },
  {
    id: "F-037",
    client: "Traiteur Garnier",
    city: "Bordeaux",
    amount: 640,
    status: "En retard",
    date: "2026-10-12",
  },
];

export function Basic() {
  return (
    <DataGrid
      columns={columns}
      data={invoices}
      rowKey="id"
      defaultSort={[{ key: "amount", direction: "desc" }]}
      pagination={{ pageSize: 5, showPageSizeSelector: false }}
      striped
    />
  );
}

Controlled row selection

selectable adds a checkbox column; with selectedRows and onSelectionChange, the application knows the checked keys.

Open in a tab
import { useState } from "react";
import { DataGrid, type ColumnDef } from "@synertech/ui";

interface Invoice {
  id: string;
  client: string;
  city: string;
  amount: number;
  status: "Payée" | "En attente" | "En retard";
  date: string;
}

const invoices: Invoice[] = [
  {
    id: "F-031",
    client: "Atelier Dupont",
    city: "Lyon",
    amount: 1250,
    status: "Payée",
    date: "2026-09-02",
  },
  {
    id: "F-032",
    client: "Boulangerie Petit",
    city: "Paris",
    amount: 380,
    status: "En attente",
    date: "2026-09-08",
  },
  {
    id: "F-033",
    client: "Garage Moreau",
    city: "Lyon",
    amount: 2140,
    status: "En retard",
    date: "2026-09-15",
  },
  {
    id: "F-034",
    client: "Cabinet Leroy",
    city: "Bordeaux",
    amount: 960,
    status: "Payée",
    date: "2026-09-21",
  },
  {
    id: "F-035",
    client: "Fleurs Bernard",
    city: "Paris",
    amount: 215,
    status: "Payée",
    date: "2026-10-01",
  },
  {
    id: "F-036",
    client: "Imprimerie Roux",
    city: "Nantes",
    amount: 1780,
    status: "En attente",
    date: "2026-10-04",
  },
  {
    id: "F-037",
    client: "Traiteur Garnier",
    city: "Bordeaux",
    amount: 640,
    status: "En retard",
    date: "2026-10-12",
  },
];

const euro = new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR" });

const columns: ColumnDef<Invoice>[] = [
  { key: "id", header: "Facture", sortable: true, width: 110 },
  { key: "client", header: "Client", sortable: true },
  { key: "city", header: "Ville", sortable: true },
  {
    key: "amount",
    header: "Montant",
    sortable: true,
    align: "right",
    render: (value) => euro.format(value as number),
  },
  { key: "status", header: "Statut" },
];

export function Selection() {
  const [selected, setSelected] = useState<string[]>([]);
  const total = invoices
    .filter((invoice) => selected.includes(invoice.id))
    .reduce((sum, invoice) => sum + invoice.amount, 0);

  return (
    <div className="space-y-3">
      <DataGrid
        columns={columns}
        data={invoices}
        rowKey="id"
        selectable
        selectionMode="multiple"
        selectedRows={selected}
        onSelectionChange={setSelected}
        density="compact"
      />
      <p className="text-sm">
        {selected.length} facture(s) sélectionnée(s) — {euro.format(total)}
      </p>
    </div>
  );
}

Bulk actions

bulkActions shows a bar while rows are checked: how many, the application’s actions and a button that empties the selection. Passed as a function, it receives the selection — the keys, the rows of data they name, across every page, and clear().

Open in a tab
import { useState } from "react";
import { Button, DataGrid, type ColumnDef } from "@synertech/ui";

interface Invoice {
  id: string;
  client: string;
  city: string;
  amount: number;
  status: "Payée" | "En attente" | "En retard";
  date: string;
}

const invoices: Invoice[] = [
  {
    id: "F-031",
    client: "Atelier Dupont",
    city: "Lyon",
    amount: 1250,
    status: "Payée",
    date: "2026-09-02",
  },
  {
    id: "F-032",
    client: "Boulangerie Petit",
    city: "Paris",
    amount: 380,
    status: "En attente",
    date: "2026-09-08",
  },
  {
    id: "F-033",
    client: "Garage Moreau",
    city: "Lyon",
    amount: 2140,
    status: "En retard",
    date: "2026-09-15",
  },
  {
    id: "F-034",
    client: "Cabinet Leroy",
    city: "Bordeaux",
    amount: 960,
    status: "Payée",
    date: "2026-09-21",
  },
  {
    id: "F-035",
    client: "Fleurs Bernard",
    city: "Paris",
    amount: 215,
    status: "Payée",
    date: "2026-10-01",
  },
  {
    id: "F-036",
    client: "Imprimerie Roux",
    city: "Nantes",
    amount: 1780,
    status: "En attente",
    date: "2026-10-04",
  },
  {
    id: "F-037",
    client: "Traiteur Garnier",
    city: "Bordeaux",
    amount: 640,
    status: "En retard",
    date: "2026-10-12",
  },
];

const euro = new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR" });

const columns: ColumnDef<Invoice>[] = [
  { key: "id", header: "Facture", sortable: true, width: 110 },
  { key: "client", header: "Client", sortable: true },
  { key: "city", header: "Ville", sortable: true },
  {
    key: "amount",
    header: "Montant",
    sortable: true,
    align: "right",
    render: (value) => euro.format(value as number),
  },
  { key: "status", header: "Statut" },
];

export function BulkActions() {
  const [rows, setRows] = useState(invoices);

  return (
    <DataGrid
      columns={columns}
      data={rows}
      rowKey="id"
      selectable
      pagination={{ pageSize: 5, showPageSizeSelector: false }}
      bulkActions={(selection) => (
        <>
          <span>
            Total : {euro.format(selection.rows.reduce((sum, row) => sum + row.amount, 0))}
          </span>
          <Button
            size="sm"
            onClick={() => {
              setRows((current) =>
                current.map((row) =>
                  selection.keys.includes(row.id) ? { ...row, status: "Payée" } : row
                )
              );
              selection.clear();
            }}
          >
            Marquer comme payées
          </Button>
        </>
      )}
    />
  );
}

Search and column filters

searchable searches every visible column; filterable adds a filter to the header suited to the filterType (text, number, list, date). The filters in force are written above the grid, each removed in one click (showActiveFilters={false} leaves them out). emptyState says why nothing shows, with an EmptyState.

Open in a tab
import { DataGrid, EmptyState, type ColumnDef } from "@synertech/ui";

interface Invoice {
  id: string;
  client: string;
  city: string;
  amount: number;
  status: "Payée" | "En attente" | "En retard";
  date: string;
}

const euro = new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR" });

const columns: ColumnDef<Invoice>[] = [
  { key: "id", header: "Facture", sortable: true, width: 110 },
  { key: "client", header: "Client", sortable: true },
  { key: "city", header: "Ville", sortable: true },
  {
    key: "amount",
    header: "Montant",
    sortable: true,
    align: "right",
    render: (value) => euro.format(value as number),
  },
  { key: "status", header: "Statut" },
];

const filterColumns: ColumnDef<Invoice>[] = [
  { key: "client", header: "Client", sortable: true, filterable: true, filterType: "text" },
  {
    key: "city",
    header: "Ville",
    filterable: true,
    filterType: "select",
    filterOptions: ["Bordeaux", "Lyon", "Nantes", "Paris"],
  },
  { key: "amount", header: "Montant", align: "right", filterable: true, filterType: "number" },
  { key: "date", header: "Date", sortable: true, filterable: true, filterType: "date" },
];

const invoices: Invoice[] = [
  {
    id: "F-031",
    client: "Atelier Dupont",
    city: "Lyon",
    amount: 1250,
    status: "Payée",
    date: "2026-09-02",
  },
  {
    id: "F-032",
    client: "Boulangerie Petit",
    city: "Paris",
    amount: 380,
    status: "En attente",
    date: "2026-09-08",
  },
  {
    id: "F-033",
    client: "Garage Moreau",
    city: "Lyon",
    amount: 2140,
    status: "En retard",
    date: "2026-09-15",
  },
  {
    id: "F-034",
    client: "Cabinet Leroy",
    city: "Bordeaux",
    amount: 960,
    status: "Payée",
    date: "2026-09-21",
  },
  {
    id: "F-035",
    client: "Fleurs Bernard",
    city: "Paris",
    amount: 215,
    status: "Payée",
    date: "2026-10-01",
  },
  {
    id: "F-036",
    client: "Imprimerie Roux",
    city: "Nantes",
    amount: 1780,
    status: "En attente",
    date: "2026-10-04",
  },
  {
    id: "F-037",
    client: "Traiteur Garnier",
    city: "Bordeaux",
    amount: 640,
    status: "En retard",
    date: "2026-10-12",
  },
];

export function SearchAndFilters() {
  return (
    <DataGrid
      columns={filterColumns}
      data={invoices}
      rowKey="id"
      searchable
      searchPlaceholder="Rechercher une facture…"
      columnToggle
      locale="fr-FR"
      defaultView={{ filters: [{ column: "amount", operator: "gte", value: "500" }] }}
      emptyState={
        <EmptyState
          size="sm"
          title="Aucune facture ne correspond"
          description="Changez la recherche ou retirez un filtre."
        />
      }
    />
  );
}

Inline editing

With editable, a double-click opens the cell; Enter confirms, Escape cancels. onCellEdit receives the row key, the column and the new value (a string).

Open in a tab
import { useState } from "react";
import { DataGrid, type ColumnDef } from "@synertech/ui";

interface Invoice {
  id: string;
  client: string;
  city: string;
  amount: number;
  status: "Payée" | "En attente" | "En retard";
  date: string;
}

const invoices: Invoice[] = [
  {
    id: "F-031",
    client: "Atelier Dupont",
    city: "Lyon",
    amount: 1250,
    status: "Payée",
    date: "2026-09-02",
  },
  {
    id: "F-032",
    client: "Boulangerie Petit",
    city: "Paris",
    amount: 380,
    status: "En attente",
    date: "2026-09-08",
  },
  {
    id: "F-033",
    client: "Garage Moreau",
    city: "Lyon",
    amount: 2140,
    status: "En retard",
    date: "2026-09-15",
  },
  {
    id: "F-034",
    client: "Cabinet Leroy",
    city: "Bordeaux",
    amount: 960,
    status: "Payée",
    date: "2026-09-21",
  },
  {
    id: "F-035",
    client: "Fleurs Bernard",
    city: "Paris",
    amount: 215,
    status: "Payée",
    date: "2026-10-01",
  },
  {
    id: "F-036",
    client: "Imprimerie Roux",
    city: "Nantes",
    amount: 1780,
    status: "En attente",
    date: "2026-10-04",
  },
  {
    id: "F-037",
    client: "Traiteur Garnier",
    city: "Bordeaux",
    amount: 640,
    status: "En retard",
    date: "2026-10-12",
  },
];

const euro = new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR" });

const columns: ColumnDef<Invoice>[] = [
  { key: "id", header: "Facture", sortable: true, width: 110 },
  { key: "client", header: "Client", sortable: true },
  { key: "city", header: "Ville", sortable: true },
  {
    key: "amount",
    header: "Montant",
    sortable: true,
    align: "right",
    render: (value) => euro.format(value as number),
  },
  { key: "status", header: "Statut" },
];

export function InlineEditing() {
  const [rows, setRows] = useState(invoices.slice(0, 4));

  return (
    <DataGrid
      columns={[
        { key: "id", header: "Facture", editable: false },
        { key: "client", header: "Client" },
        { key: "city", header: "Ville" },
        { key: "amount", header: "Montant (€)", align: "right" },
      ]}
      data={rows}
      rowKey="id"
      editable
      bordered
      onCellEdit={(rowKey, columnKey, value) =>
        setRows((current) =>
          current.map((row) =>
            row.id === rowKey
              ? { ...row, [columnKey]: columnKey === "amount" ? Number(value) : value }
              : row
          )
        )
      }
    />
  );
}

Export and imperative API

exportable shows the CSV / JSON buttons; the ref triggers the same actions from the application, as well as resetting the sort and the filters. The CSV follows RFC 4180, and text that starts like a formula (=, +, -, @) is written with an apostrophe in front: the file is opened by someone other than whoever typed its values. exportNeutralizeFormulas={false} writes it as is.

Open in a tab
import { useRef, useState } from "react";
import { Button, DataGrid, type ColumnDef, type DataGridRef, type SortState } from "@synertech/ui";

interface Invoice {
  id: string;
  client: string;
  city: string;
  amount: number;
  status: "Payée" | "En attente" | "En retard";
  date: string;
}

const euro = new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR" });

const columns: ColumnDef<Invoice>[] = [
  { key: "id", header: "Facture", sortable: true, width: 110 },
  { key: "client", header: "Client", sortable: true },
  { key: "city", header: "Ville", sortable: true },
  {
    key: "amount",
    header: "Montant",
    sortable: true,
    align: "right",
    render: (value) => euro.format(value as number),
  },
  { key: "status", header: "Statut" },
];

const invoices: Invoice[] = [
  {
    id: "F-031",
    client: "Atelier Dupont",
    city: "Lyon",
    amount: 1250,
    status: "Payée",
    date: "2026-09-02",
  },
  {
    id: "F-032",
    client: "Boulangerie Petit",
    city: "Paris",
    amount: 380,
    status: "En attente",
    date: "2026-09-08",
  },
  {
    id: "F-033",
    client: "Garage Moreau",
    city: "Lyon",
    amount: 2140,
    status: "En retard",
    date: "2026-09-15",
  },
  {
    id: "F-034",
    client: "Cabinet Leroy",
    city: "Bordeaux",
    amount: 960,
    status: "Payée",
    date: "2026-09-21",
  },
  {
    id: "F-035",
    client: "Fleurs Bernard",
    city: "Paris",
    amount: 215,
    status: "Payée",
    date: "2026-10-01",
  },
  {
    id: "F-036",
    client: "Imprimerie Roux",
    city: "Nantes",
    amount: 1780,
    status: "En attente",
    date: "2026-10-04",
  },
  {
    id: "F-037",
    client: "Traiteur Garnier",
    city: "Bordeaux",
    amount: 640,
    status: "En retard",
    date: "2026-10-12",
  },
];

export function ExportAndRef() {
  const gridRef = useRef<DataGridRef>(null);
  const [sort, setSort] = useState<SortState[]>([]);

  return (
    <div className="space-y-3">
      <div className="flex flex-wrap gap-2">
        <Button size="sm" onClick={() => gridRef.current?.exportData("csv")}>
          Exporter en CSV
        </Button>
        <Button size="sm" onClick={() => gridRef.current?.resetSort()}>
          Réinitialiser le tri
        </Button>
        <Button size="sm" onClick={() => console.log(gridRef.current?.getVisibleData())}>
          Lignes affichées
        </Button>
      </div>
      <DataGrid
        ref={gridRef}
        columns={columns}
        data={invoices}
        rowKey="id"
        sort={sort}
        onSort={setSort}
        multiSort
        exportable
        exportFormats={["csv", "json"]}
        exportFilename="factures-octobre"
      />
    </div>
  );
}

Saved views

getView() reads the view in force, setView() puts one back — and returns to the first page. A saved view may carry fields of its own (a name): setView reads the grid’s only. To keep it between two visits, onViewChange receives the whole view on every change.

Open in a tab
import { useRef, useState } from "react";
import { Button, DataGrid, type ColumnDef, type DataGridRef, type DataGridView } from "@synertech/ui";

const presetViews: { name: string; view: Partial<DataGridView> }[] = [
  { name: "Toutes", view: { sort: [], filters: [], search: "", hiddenColumns: [] } },
  {
    name: "Relances",
    view: {
      sort: [{ key: "amount", direction: "desc" }],
      filters: [{ column: "status", operator: "equals", value: "En retard" }],
      hiddenColumns: ["city"],
    },
  },
];

interface Invoice {
  id: string;
  client: string;
  city: string;
  amount: number;
  status: "Payée" | "En attente" | "En retard";
  date: string;
}

const euro = new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR" });

const columns: ColumnDef<Invoice>[] = [
  { key: "id", header: "Facture", sortable: true, width: 110 },
  { key: "client", header: "Client", sortable: true },
  { key: "city", header: "Ville", sortable: true },
  {
    key: "amount",
    header: "Montant",
    sortable: true,
    align: "right",
    render: (value) => euro.format(value as number),
  },
  { key: "status", header: "Statut" },
];

const viewColumns: ColumnDef<Invoice>[] = [
  { key: "id", header: "Facture", sortable: true },
  { key: "client", header: "Client", sortable: true },
  {
    key: "city",
    header: "Ville",
    filterable: true,
    filterType: "select",
    filterOptions: ["Bordeaux", "Lyon", "Nantes", "Paris"],
  },
  {
    key: "amount",
    header: "Montant",
    sortable: true,
    align: "right",
    filterable: true,
    filterType: "number",
    render: (value) => euro.format(value as number),
  },
  {
    key: "status",
    header: "Statut",
    filterable: true,
    filterType: "select",
    filterOptions: ["Payée", "En attente", "En retard"],
  },
];

const invoices: Invoice[] = [
  {
    id: "F-031",
    client: "Atelier Dupont",
    city: "Lyon",
    amount: 1250,
    status: "Payée",
    date: "2026-09-02",
  },
  {
    id: "F-032",
    client: "Boulangerie Petit",
    city: "Paris",
    amount: 380,
    status: "En attente",
    date: "2026-09-08",
  },
  {
    id: "F-033",
    client: "Garage Moreau",
    city: "Lyon",
    amount: 2140,
    status: "En retard",
    date: "2026-09-15",
  },
  {
    id: "F-034",
    client: "Cabinet Leroy",
    city: "Bordeaux",
    amount: 960,
    status: "Payée",
    date: "2026-09-21",
  },
  {
    id: "F-035",
    client: "Fleurs Bernard",
    city: "Paris",
    amount: 215,
    status: "Payée",
    date: "2026-10-01",
  },
  {
    id: "F-036",
    client: "Imprimerie Roux",
    city: "Nantes",
    amount: 1780,
    status: "En attente",
    date: "2026-10-04",
  },
  {
    id: "F-037",
    client: "Traiteur Garnier",
    city: "Bordeaux",
    amount: 640,
    status: "En retard",
    date: "2026-10-12",
  },
];

export function SavedViews() {
  const gridRef = useRef<DataGridRef>(null);
  const [views, setViews] = useState(presetViews);

  return (
    <div className="space-y-3">
      <div className="flex flex-wrap gap-2">
        {views.map(({ name, view }) => (
          <Button key={name} size="sm" onClick={() => gridRef.current?.setView(view)}>
            {name}
          </Button>
        ))}
        <Button
          size="sm"
          onClick={() => {
            const view = gridRef.current?.getView();
            if (view)
              setViews((current) => [...current, { name: `Vue ${current.length + 1}`, view }]);
          }}
        >
          Enregistrer la vue
        </Button>
      </div>
      <DataGrid
        ref={gridRef}
        columns={viewColumns}
        data={invoices}
        rowKey="id"
        searchable
        columnToggle
        columnReorderable
        locale="fr-FR"
        pagination={{ pageSize: 5, pageSizeOptions: [5, 10] }}
      />
    </div>
  );
}

Payment tracking

A complete case: grouping by status, totals in the grid footer, an expandable row for the details and a sticky header within a bounded height.

Open in a tab
import { DataGrid, type ColumnDef } from "@synertech/ui";

interface Invoice {
  id: string;
  client: string;
  city: string;
  amount: number;
  status: "Payée" | "En attente" | "En retard";
  date: string;
}

const euro = new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR" });

const columns: ColumnDef<Invoice>[] = [
  { key: "id", header: "Facture", sortable: true, width: 110 },
  { key: "client", header: "Client", sortable: true },
  { key: "city", header: "Ville", sortable: true },
  {
    key: "amount",
    header: "Montant",
    sortable: true,
    align: "right",
    render: (value) => euro.format(value as number),
  },
  { key: "status", header: "Statut" },
];

const invoices: Invoice[] = [
  {
    id: "F-031",
    client: "Atelier Dupont",
    city: "Lyon",
    amount: 1250,
    status: "Payée",
    date: "2026-09-02",
  },
  {
    id: "F-032",
    client: "Boulangerie Petit",
    city: "Paris",
    amount: 380,
    status: "En attente",
    date: "2026-09-08",
  },
  {
    id: "F-033",
    client: "Garage Moreau",
    city: "Lyon",
    amount: 2140,
    status: "En retard",
    date: "2026-09-15",
  },
  {
    id: "F-034",
    client: "Cabinet Leroy",
    city: "Bordeaux",
    amount: 960,
    status: "Payée",
    date: "2026-09-21",
  },
  {
    id: "F-035",
    client: "Fleurs Bernard",
    city: "Paris",
    amount: 215,
    status: "Payée",
    date: "2026-10-01",
  },
  {
    id: "F-036",
    client: "Imprimerie Roux",
    city: "Nantes",
    amount: 1780,
    status: "En attente",
    date: "2026-10-04",
  },
  {
    id: "F-037",
    client: "Traiteur Garnier",
    city: "Bordeaux",
    amount: 640,
    status: "En retard",
    date: "2026-10-12",
  },
];

export function Dashboard() {
  return (
    <DataGrid
      columns={[
        {
          key: "client",
          header: "Client",
          aggregate: "count",
          renderAggregate: (n) => `${n} factures`,
        },
        { key: "city", header: "Ville" },
        {
          key: "amount",
          header: "Montant",
          align: "right",
          render: (value) => euro.format(value as number),
          aggregate: "sum",
          renderAggregate: (total) => euro.format(total),
        },
      ]}
      data={invoices}
      rowKey="id"
      groupBy="status"
      showFooter
      expandable
      expandedContent={(row) => (
        <p className="text-sm">
          Facture {row.id} émise le {new Date(row.date).toLocaleDateString("fr-FR")}.
        </p>
      )}
      stickyHeader
      maxHeight={360}
    />
  );
}

API reference

Components

DataGrid

ComponentClient
import { DataGrid } from "@synertech/ui";

Props — DataGridProps

PropTypeDefaultDescription
columns• ColumnDef<T>[] —

Column definitions

data• T[] —

Data array

bordered boolean false

Show borders between cells

borderless boolean false

Borderless style

bulkActions ReactNode | ((selection: DataGridSelection<T>) => ReactNode) —

Actions on the selected rows, in a bar shown above the grid as soon as a row is selected, beside the count and a button that clears the selection. A function receives the selection: every selected key, and the selected rows data holds.

cellClassName string —

Custom cell class name

className string —

Additional class names for the wrapper

columnOrder string[] —

Keys of the columns in the order shown (controlled), the hidden ones included. A column it does not name comes after the others, in the order of columns; a key that names no column is passed over.

columnReorderable boolean false

Lets the columns be reordered: dragged from one header to another, or moved one place at a time from the column menu of the toolbar, which the keyboard reaches.

columnToggle boolean false

Enable column visibility toggle

columnWidths Record<string, number> —

Widths in pixels of the columns resized by hand (controlled), by key. A column it does not name keeps its width.

defaultSort SortState[] —

Default sort state

defaultView Partial<DataGridView> —

Where an uncontrolled grid starts: a view saved earlier, whole or in part. Read at mount only. A part the grid receives through its own prop (sort, filters…) is read from that prop, and defaultSort is read when the view holds no sort.

density Density "default"

Density / padding

editable boolean false

Enable inline cell editing

emptyState ReactNode —

What the grid shows when it has no row, in place of its own "no data" state: usually an EmptyState saying why, and what to do.

expandable boolean false

Enable expandable rows

expandedContent (row: T, index: number) => ReactNode —

Render expanded row content

expandedRows string[] —

Controlled expanded row keys

exportable boolean false

Enable export functionality

exportFilename string "export"

Custom export filename

exportFormats ("csv" | "json")[] ["csv", "json"]

Supported export formats

exportNeutralizeFormulas boolean —

Keeps a cell from running as a formula in the exported CSV. A file is opened by someone other than whoever typed its values: text starting with =, +, - or @ is written with an apostrophe in front, so a spreadsheet shows it instead of computing it. Numbers are never touched. On unless it is false; the JSON file is not concerned.

filters FilterValue[] —

Active column filters (controlled)

groupBy string | string[] —

Group rows by column key(s). The rows of a group are kept together, the groups in the order their first row comes in once sorted; pagination and virtualization then count those rows, and a page shows the groups it holds.

headerClassName string —

Custom header class name

hiddenColumns string[] —

Hidden column keys (controlled)

labels UILabelsOf<"dataGrid"> —

The strings the grid writes itself, for this instance: any dataGrid… key of UILabels. Wins over UILabelsProvider; searchPlaceholder and emptyState win over both.

loading boolean false

Loading state

loadingRows number 5

Number of skeleton rows to show when loading

locale string —

BCP 47 tag the footer aggregates and the active filters are written in. Defaults to the locale of UILabelsProvider, then to the language of the runtime.

maxHeight string | number —

Max height with scroll (CSS value)

mode DataGridMode "client"

Data processing mode

multiSort boolean false

Enable multi-column sorting

onCellEdit (rowKey: string, columnKey: string, value: unknown) => void —

Cell edit callback

onColumnOrderChange (order: string[]) => void —

Called with the new order of every column when one is dropped on another, or moved from the column menu.

onColumnReorder (fromKey: string, toKey: string) => void —

Called with the column moved and the column whose place it takes, by a drop or from the column menu.

onColumnVisibilityChange (hiddenKeys: string[]) => void —

Column visibility change callback

onColumnWidthsChange (widths: Record<string, number>) => void —

Called once a column has been resized, when the pointer is released or at each press of an arrow key on its handle, with every width set by hand. The column follows the pointer while it moves.

onExpandChange (expandedKeys: string[]) => void —

Expand change callback

onFilterChange (filters: FilterValue[]) => void —

Column filter change callback

onPageChange (page: number) => void —

Page change callback

onPageSizeChange (pageSize: number) => void —

Page size change callback

onReorder (fromIndex: number, toIndex: number) => void —

Reorder callback. Both indices are positions in data, not on screen, so they stay right on any page and under a filter. Rows cannot be dragged while the grid sorts them itself: the row would jump back to where the sort puts it.

onRowClick (row: T, index: number) => void —

Row click callback

onRowContextMenu (row: T, index: number, event: MouseEvent) => void —

Row context menu callback

onRowDoubleClick (row: T, index: number) => void —

Row double-click callback

onSearch (value: string) => void —

Search change callback

onSelectionChange (selectedKeys: string[]) => void —

Selection change callback

onSort (sort: SortState[]) => void —

Sort change callback

onViewChange (view: DataGridView) => void —

Called with the whole view whenever a part of it changes from inside the grid — a sort, a filter, the search, a column hidden, moved or resized, the page size — or through setView. What an application stores to give each user the grid as they left it.

page number —

Current page (controlled, 1-based)

pageSize number —

Rows per page (controlled). The size selector calls onPageSizeChange and shows what this says; pagination.pageSize is where an uncontrolled grid starts.

pagination boolean | PaginationConfig false

Enable pagination

ref React.Ref<DataGridRef> —
renderGroupHeader (groupKey: string, groupValue: unknown, rows: T[]) => ReactNode —

Render custom group header. rows is the whole group, on every page it runs over.

reorderable boolean false

Enable row drag & drop reorder

rowClassName string | ((row: T, index: number) => string) —

Custom row class name

rowHeight number 40

Height of every row under virtualized (px): the rows are drawn at it, and the scroll is computed from it.

rowKey string | ((row: T, index: number) => string) —

Unique key extractor for rows. Selection, expansion and edits are held by this key, so a row keeps them wherever sorting, filtering and paging put it. Without it a row is known by its position in data: enough while data keeps its order, wrong as soon as it is refetched or paged by a server. The function receives that position as index.

searchable boolean false

Enable global search

searchPlaceholder string —

Search placeholder

searchValue string —

Controlled search value

selectable boolean false

Enable row selection

selectedRows string[] —

Selected row keys (controlled)

selectionMode SelectionMode "multiple"

Selection mode

showActiveFilters boolean true

Writes the column filters in force in a row above the grid, each removed in one click, with a button that removes them all. On unless it is false: a filter on a column out of sight is otherwise nowhere to be seen.

showFooter boolean false

Show footer with aggregates

sort SortState[] —

Controlled sort state

sortable boolean false

Enable sorting

stickyHeader boolean false

Sticky header on vertical scroll

striped boolean false

Striped rows

totalItems number —

Total items for server-mode pagination

virtualHeight number 400

Height of the scrolling area under virtualized (px), when maxHeight does not set one. The rows drawn are those the area really shows.

virtualized boolean false

Enable virtual scrolling for large datasets. Every row is drawn exactly rowHeight tall, its cells on one line, and a group header takes the place of a row. The content of an expanded row is not counted: a virtualized grid is not meant to be expandable.

Types

ColumnDef

Interface
interface ColumnDef<T = unknown>
FieldTypeDefaultDescription
header• ReactNode —

Header text or ReactNode

key• string —

Unique key matching a property in the data object

aggregate AggregateFunction —

Aggregate function for footer

align "left" | "center" | "right" —

Text alignment

cellClassName string —

Custom class for cells in this column

colSpan (row: T, rowIndex: number) => number —

Column span function

editable boolean —

false keeps the column out of the grid's editable. An edited cell shows its render until it is double-clicked, and a cell that held a number hands back a number.

filterable boolean —

Enable filtering on this column: a text filter unless filterType says otherwise.

filterOptions string[] —

Options for select filter

filterType FilterType —

What the filter compares: text, a number, a value among filterOptions, or a date — a Date, a timestamp or an ISO string, read by its local day.

headerClassName string —

Custom class for the header cell

hidden boolean —

Column is hidden

maxWidth number —

Maximum column width for resizing

minWidth number —

Minimum column width for resizing

render (value: unknown, row: T, rowIndex: number) => ReactNode —

Custom cell renderer

renderAggregate (value: number, data: T[]) => ReactNode —

Custom aggregate renderer. Empty cells are left out of every aggregate; value is 0 when the column holds no number to average or compare, which data tells apart from a real zero.

renderHeader (column: ColumnDef<T>) => ReactNode —

Custom header renderer. In a column that sorts, it is drawn inside the sort button: no button, link or field in it.

resizable boolean —

Column is resizable

sortable boolean —

Enable sorting on this column

sortComparator (a: T, b: T) => number —

Custom sort comparator

sticky "left" | "right" —

Keeps the column on one side while the grid scrolls sideways. Several columns on one side stack after one another: each one before the last needs a width.

type "data" | "actions" | "selection" | "expand" —

Column type for special behavior

width string | number —

Column width (CSS value)

DataGridRef

Interface
interface DataGridRef
FieldTypeDefaultDescription
deselectAll• () => void —

Deselect all rows

exportData• (format: "csv" | "json") => void —

Export data

getView• () => DataGridView —

The view the grid shows now: sort, filters, search, columns, page size.

getVisibleData• () => unknown[] —

Get currently visible data (after sort/filter/pagination)

resetFilters• () => void —

Reset all filters and search

resetSort• () => void —

Reset sort state

scrollToRow• (index: number) => void —

Scroll to a specific row by index

selectAll• () => void —

Select all visible rows, on top of what is selected on other pages

setView• (view: Partial<DataGridView>) => void —

Shows a view: each part it holds replaces the grid's own — a controlled one through its callback — and the grid goes back to page 1.

What a bulkActions function receives: the selection, and a way to clear it.

interface DataGridSelection<T = unknown>
FieldTypeDefaultDescription
clear• () => void —

Clears the selection.

keys• string[] —

Every selected key, on every page.

rows• T[] —

The selected rows data holds, in its order: in server mode, those of the page shown.

DataGridView

Interface

What a user arranges in a grid and expects to find again: what a saved view holds. Read with getView(), shown with setView(), reported by onViewChange.

interface DataGridView
FieldTypeDefaultDescription
columnOrder• string[] —

Keys of every column, the hidden ones included, in the order shown.

columnWidths• Record<string, number> —

Widths in pixels of the columns resized by hand, by key.

filters• FilterValue[] —

The column filters in force.

hiddenColumns• string[] —

Keys of the hidden columns.

pageSize• number —

Rows per page.

sort• SortState[] —

The sort criteria, in order.

FilterValue

Interface
interface FilterValue
FieldTypeDefaultDescription
column• string —
operator• FilterOperator —
value• string —
valueTo string —

The upper bound of between, included. value is the lower one.

FieldTypeDefaultDescription
pageSize number —

Rows per page the grid starts with. The size selector changes it from there; passing another value later sets it again.

pageSizeOptions number[] —
showPageSizeSelector boolean —
showTotalItems boolean —

SortState

Interface
interface SortState
FieldTypeDefaultDescription
direction• SortDirection —
key• string —
type AggregateFunction = "sum" | "avg" | "count" | "min" | "max"
type DataGridMode = "client" | "server"
type Density = "compact" | "default" | "comfortable"
type FilterOperator = | "contains"
  | "equals"
  | "startsWith"
  | "endsWith"
  | "gt"
  | "gte"
  | "lt"
  | "lte"
  | "between"
  | "isEmpty"
  | "isNotEmpty"
type FilterType = "text" | "number" | "select" | "date"
type SelectionMode = "single" | "multiple"
type SortDirection = "asc" | "desc" | null