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.
| Symbol | Purpose | Guide |
|---|---|---|
DataGridStatusBar | Shows the aggregates of the selected cells | Status bar |
useDataGridSelectionStats | Returns the same numbers without markup | Status bar |
| Limits | Bound the aggregate walk | Status 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
| Limit | Value | Effect |
|---|---|---|
| Immediate walk | 5,000 cells | A selection of this area or less computes at once. |
| Settle delay | 150 ms | A larger selection computes after the selection stops changing. |
MAX_STATUS_CELLS | 200,000 cells | The 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".
Related
- Status bar: which cells and values count, and how the bar formats them.
- Pinned rows options: a fixed totals band.
- Selection model: the selection channels the bar reads.
Shortcut remapping options
Look up the keymap and commands props, the binding string syntax, and the options of the shortcuts dialog hook, the dialog props, and BindingChips.
Comments options
Look up the options and result of useDataGridComments, the callback matrix, the save answers, the fetch rules, and the bounds.