Status barPro
Show row counts, the number of selected rows and live sum, average, count, minimum and maximum of the selected cells below the grid.
The status bar is a strip below the grid that answers the questions users ask while working with data: how many rows match my filter, how many have I selected, and what do the cells I highlighted add up to.
Rows: 312 of 4,806 Selected: 3 Sum: 48,213.75 Avg: 1,607.13 Count: 30 Min: 120 Max: 9,840Loading demo…
View source
Sample data and small UI helpers are imported from the docs' demos/_shared.ts and demos/_scheduler-data.ts files.
import { createGrid, type ColumnDef } from '@birchui/core';
import { ClipboardModule, FillHandleModule, RangeSelectionModule, StatusBarModule } from '@birchui/grid-pro';
import { docsTheme, layout, onDocsThemeChange, seededRandom } from './_shared';
export const meta = { title: 'Range selection, clipboard and fill handle', height: 480 };
interface ForecastRow {
id: string;
product: string;
jan: number;
feb: number;
mar: number;
apr: number;
may: number;
jun: number;
}
const PRODUCTS = [
'Standing desk',
'Ergonomic chair',
'Monitor arm',
'27" 4K monitor',
'USB-C dock',
'Desk lamp',
'Filing cabinet',
'Headset',
];
const MONTHS = ['jan', 'feb', 'mar', 'apr', 'may', 'jun'] as const;
function makeForecast(): ForecastRow[] {
const random = seededRandom(8);
return PRODUCTS.flatMap((product, p) =>
['North America', 'Europe', 'Asia Pacific'].map((region, r) => {
const row: ForecastRow = {
id: `${p}-${r}`,
product: `${product}, ${region}`,
jan: 0,
feb: 0,
mar: 0,
apr: 0,
may: 0,
jun: 0,
};
for (const month of MONTHS) row[month] = Math.round(40 + random() * 260);
return row;
}),
);
}
const columns: ColumnDef<ForecastRow>[] = [
{ field: 'product', header: 'Product and region', width: 240, pinned: 'left' },
...MONTHS.map((month): ColumnDef<ForecastRow> => ({
field: month,
header: month[0].toUpperCase() + month.slice(1),
type: 'number',
width: 100,
editable: true,
valueParser: (input) => Number(String(input).replace(/[^\d.-]/g, '')),
})),
];
export default function mount(el: HTMLElement): () => void {
const { toolbar, body, status } = layout(el);
toolbar.append(
'Drag across cells or use Shift+arrows. Ctrl/Cmd+C copies as TSV; paste from a spreadsheet with Ctrl/Cmd+V; drag the fill handle to extend a series.',
);
const grid = createGrid<ForecastRow>(body, {
columns,
rows: makeForecast(),
getRowId: (row) => row.id,
modules: [RangeSelectionModule, ClipboardModule, FillHandleModule, StatusBarModule],
rangeSelection: true,
clipboard: true,
fillHandle: true,
statusBar: { rowCount: true, aggregates: ['sum', 'avg', 'count'] },
theme: docsTheme(),
ariaLabel: 'Unit forecast by month',
});
status.textContent = 'Edits from paste and fill arrive as cellValueChanged events.';
const off = grid.on('cellValueChanged', ({ source, colId, row, newValue }) => {
status.textContent = `${source}: ${row.product} ${colId.toUpperCase()} = ${String(newValue)}`;
});
const stopTheme = onDocsThemeChange((theme) => grid.update({ theme }));
return () => {
off();
stopTheme();
grid.destroy();
};
}Enable the status bar#
import { createGrid } from '@birchui/core';
import { StatusBarModule, RangeSelectionModule } from '@birchui/grid-pro';
const api = createGrid(container, {
columns,
rows: ledgerEntries,
getRowId: (row) => row.entryId,
modules: [StatusBarModule, RangeSelectionModule],
rangeSelection: true,
rowSelection: 'multiple',
statusBar: true,
});statusBar: true turns on every item. Pass an object to choose:
createGrid(container, {
columns,
rows: ledgerEntries,
modules: [StatusBarModule, RangeSelectionModule],
rangeSelection: true,
statusBar: {
rowCount: true,
selectedCount: false,
aggregates: ['sum', 'avg'],
},
});rowCount and selectedCount default to true in the object form as well; set them to false to hide them. Set statusBar: false, or leave it out, to remove the bar.
Items#
| Item | Shown | Content |
|---|---|---|
| Rows | When rowCount is on |
The number of rows. When filters hide some, it reads 312 of 4,806. In a grouped grid it counts data rows, not group rows. |
| Selected | When selectedCount is on and at least one row is selected |
The number of selected rows. |
| Sum, Avg, Min, Max | When a range of two or more cells is selected and it contains numbers | Computed over the numeric cells only. |
| Count | When a range of two or more cells is selected | The number of non-empty cells, numeric or not. |
The aggregates available in the status bar are sum, avg, count, min and max, shown in that order unless you list them yourself. Other aggregation names, such as distinct, are ignored here.
How the cell aggregates are computed#
The status bar reads the raw values of the cells in the current range selection:
- Only real numbers take part in sum, average, minimum and maximum. Text such as
'1,200'is counted bycountbut not summed. - With several ranges, a cell covered by more than one range is counted once.
- Collapsed group rows contribute their aggregate values; expanded group rows are skipped, because their children are counted instead. Grand total rows and detail panels are always skipped.
- Numbers are formatted for the grid's
localewith up to two decimals.
Because a single selected cell needs no summary, aggregates appear only when the range covers at least two cells.
Updates and accessibility#
The bar updates after data changes, edits, filtering, selection changes and range changes, batched into one update per change. It is rendered with role="status" and aria-live="polite", so screen readers announce new totals without interrupting the user.
Styling#
The bar is placed in the grid's bottom slot. It uses these classes:
| Class | Element |
|---|---|
lq-status-bar |
The bar. |
lq-status-item |
One item, with a data-key of rows, selected, sum, avg, count, min or max. |
lq-status-label |
The item label, such as Sum:. |
lq-status-value |
The formatted value. |
.lq-status-bar .lq-status-item[data-key='sum'] .lq-status-value {
font-weight: 600;
}Your own summary#
For a summary the status bar does not offer, such as a weighted average, read the range yourself with getRangeValues() and onRangeChanged(); see Range selection. To aggregate a whole column regardless of the selection, use getColumnAggregate() from Aggregation.