gridcn2.0.0
Add-on optionsSelection and shortcuts

Status bar options

Look up the props of DataGridStatusBar, the result of useDataGridSelectionStats, and the limits that bound the aggregate walk.

DataGridStatusBar shows the count, sum, average, minimum, and maximum of the selected cells. useDataGridSelectionStats returns the same numbers without markup. Both read committed values and change no cell value. Which cells and values count is on Status bar.

SymbolPurposeGuide
DataGridStatusBarShows the aggregates of the selected cellsStatus bar
useDataGridSelectionStatsReturns the same numbers without markupStatus bar
LimitsBound the aggregate walkStatus bar

DataGridStatusBar

Mount the bar inside DataGridProvider, next to DataGridRoot.

Prop

Type

StatusBarAggregate is "count" | "sum" | "avg" | "min" | "max". The bar renders the aggregates in the order of aggregates. A value that is null does not render. The aggregates show once the selection holds 2 cells whose value is not undefined. The bar also renders for hidden checked rows and the select-all banner. If the walk hits the cell cap, each value takes a ≈ prefix.

The bar is a polite live region with role="status". After a computation ends, its text changes.

useDataGridSelectionStats

The hook takes no arguments and returns SelectionStats:

Prop

Type

sum uses Neumaier summation to limit the rounding error of many additions. For example, ten cells of 0.1 sum to 1, and a plain sum gives 0.9999999999999999. A cell whose raw value is a finite number is numeric.

Limits

LimitValueEffect
Immediate walk5,000 cellsA selection of this area or less computes at once.
Settle delay150 msA larger selection computes after the selection stops changing.
MAX_STATUS_CELLS200,000 cellsThe walk stops here. approximate is true.

When approximate is true, the bar sets a title that names the cap.

Server mode

A lazy source in scroll mode has unloaded rows that count as nothing. The select-all banner of a grid with totalRowCount is on Status bar: Server mode.

Example

This sample shows the sum and the average only, with two decimals:

import {
  DataGridBody,
  DataGridHeader,
  DataGridProvider,
  DataGridRoot,
  defineColumns,
} from "@/components/data-grid/data-grid";
import {
  DataGridStatusBar,
} from "@/components/data-grid-status-bar/data-grid-status-bar";

type Row = { id: string; price: number };

const rows: Row[] = [
  { id: "1", price: 2 },
  { id: "2", price: 8 },
];
const columns = defineColumns<Row>()([
  { id: "price", header: "Price", accessorKey: "price", type: "number" },
]);

export function PricesGrid() {
  return (
    <DataGridProvider defaultData={rows} columns={columns}>
      <DataGridRoot className="h-80">
        <DataGridHeader />
        <DataGridBody />
      </DataGridRoot>
      <DataGridStatusBar
        aggregates={["sum", "avg"]}
        formatValue={(value) => value.toFixed(2)}
      />
    </DataGridProvider>
  );
}

Select both prices. The bar shows "Sum 10.00" and "Avg 5.00".

On this page