Extras
DataGrid
BitDataGrid displays an information-rich data table and gives people the tools to work through it: sorting, quick search and per-column filters, paging, grouping with aggregates, selection, inline editing, resizable/reorderable/frozen columns, master-detail and tree rows, keyboard cell navigation, row and column virtualization, and CSV/Excel export. Bind a list, an IQueryable executed at the source, or a callback for server-side paging or infinite scrolling. Use a data grid when information density is critical.
Data & performance
The data modes - eager and lazily loaded trees, row and column virtualization, server-side paging with OnRead, infinite scrolling, IQueryable sources - and CSV and Excel export.
Tree data
The selector returns a node's direct children, or
null or an empty list for a leaf. Nodes open collapsed
unless TreeInitiallyExpanded is set, and the first column carries the toggle and the indentation
(--bit-DataGrid-tree-indent per level). Give the tree a KeyField: it is how the grid tells nodes apart,
and the expanded nodes are not part of the GetState snapshot for that reason. A tree shows every row it holds,
so the pager and grouping are set aside, and the rows cannot be reordered by dragging.
The second grid loads lazily: OnLoadChildren (or ChildrenProvider, which takes no cancellation token) fetches a node's children the first time it opens and keeps them for later toggles, and HasChildrenSelector says which unloaded nodes get a toggle - without it a node shows one only once its children are loaded, so none do at first. Set only one of ChildrenSelector, ChildrenProvider and OnLoadChildren. A lazy tree cannot see what it has not loaded, so it has no filter row and no search box, and TreeInitiallyExpanded does not apply to it.
Virtualization
The scroll position is worked out from RowHeight (36 px by default), so every row is exactly that tall while Virtualize is on: RowHeightSelector and WrapCellText are ignored, and an open detail row is not accounted for - use paging with detail rows. Without a Height the grid has no viewport of its own to scroll. With OnRead and no pager, the rows are read from your code window by window as they scroll in (see Server-side data).
VirtualizeColumns replaces the columns scrolled out of view with spacers. It places them from their pixel widths - a column with another unit falls back to a default width - and is not applied while a column has a Group header or a ColSpan. Keyboard navigation reaches only the columns that are rendered, and frozen columns stay rendered.
Server-side data
The request's Skip and Take are the window to return (
Take = null means every row, which
the exports and GetViewItemsAsync ask for); Sorts come primary first, a row has to match every one of the
Filters, Search is the quick-search term to match across the columns you consider searchable, and
Groups names any grouping. Each filter names its column by id, an operator and a value - a collection for
In / NotIn, none for IsEmpty / IsNotEmpty. Pass the token on to your data source so the
work stops. TotalCount is the number of matching rows over every page and drives the pager; the result
refuses a total smaller than the rows it carries.
In this mode the delegates of a column - SortBy, Comparer, ValueText - are not called: sort, filter and search by the column ids yourself. Grouping is not offered. The footer aggregates only the page it holds unless you compute the aggregates the request's Aggregates names over every matching row and return them in the result's Aggregates (the second grid below). A read that throws propagates unless OnReadError is set, which turns it into an error row with a Retry button (the third grid). The grid sets aria-busy while it reads, so Loading is only for a grid that should hide its rows meanwhile. The grid reads only when what it asks for changes (a sort, a filter, the search, the page or the page size), never on a re-render of its parent: after the data behind it changes, call RefreshAsync.
Infinite scrolling
Each request's Skip is the number of rows already loaded and its Take the batch size (50 by default), with the sorts, filters and search as in server mode; return
0 as the TotalCount, which this mode
ignores. A batch shorter than Take tells the grid the data has ended. A change of sort, filter or search, and
RefreshAsync, start again from the first batch. The pager and grouping are not available, the footer
aggregates the loaded rows, and select-all, expand-all-details and the synchronous ToCsv /
GetViewItems cover only the loaded rows - ToCsvAsync, the export buttons and
GetViewItemsAsync read them all.
IQueryable data source
Only what can be written as an expression reaches the provider. The quick search becomes Contains conditions over the text columns (an enum column's members are matched by their text), and the delegates of a column - SortBy, Comparer, ValueText - are not used: a bound column sorts by its property and a template-only column does not sort at all. Grouping is not offered, and a tree's Items are never treated as a query. Select-all and expand-all-details cover the loaded page only.
Like a server grid, a queryable one queries again only when what it asks for changes (a sort, a filter, the search, the page), or when it is handed another Items; call RefreshAsync after the data behind it changes. OnViewChange still works here, at the cost of a query of the whole view whenever it may have changed.
Export
An export follows the view - the filters, the search and the sorts - but not the page: it writes every matching row, in every data mode (OnRead and OnLoadMore are asked once with Take = null). It writes the visible columns that have a value, in their current order, with a header row of their titles; a template-only column needs an ExportValue, which also lets a bound column export something other than its value. Values are formatted with the column's Format; ValueText and templates are display only. The CSV guards against formula injection by prefixing text that starts with =, +, - or @ (numbers excepted) with an apostrophe.
The .xlsx is built in-process, with no other package: numbers, booleans and dates land as typed cells, with the column widths, an AutoFilter, frozen panes and merged ColSpan cells. ExcelExportStyled reads the colors, striping, borders and fonts the grid renders (the active theme and dark mode included) and falls back to a plain bold header where scripts cannot run, as while prerendering. ExportFileName defaults to export. From code: ExportCsvAsync, ExportExcelAsync (download), ToCsvAsync, ToExcelAsync (the text or bytes) and ToCsv, which is synchronous and covers only the loaded rows with OnRead or OnLoadMore.
Feedback
Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.