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.
Localization & appearance
Translating the grid's texts and its values, the disabled grid, app-wide defaults through BitParams, the pager and toolbar layout, Style & Class with the CSS variables, and right-to-left grids.
Localization
BitDataGridStrings holds 95 texts. The ones with a
{0} are format strings whose placeholders must be
kept (PagerRangeFormat takes the first row, the last row and the total). EmptyText and
NoMatchesText default to BitStrings.Current, so an app that localizes BitStrings already has them. Hand the
same instance to every grid of an app through BitParams (see
Cascading parameters).
The column titles are yours: set Title in the user's language, since the default is the property name. Format writes numbers and dates in the current culture (the Preis column's
C2 writes the page culture's currency), and
a cell's values themselves can be translated with ValueText (see
Value text).
Disabled
While disabled, the grid keeps showing its sort, filters, selection and page, but none of them can be changed from it: headers do not sort, filters, the search box, checkboxes and the pager are disabled, columns cannot be resized or moved, rows cannot be dragged, nothing opens for editing, and the row and cell events are not raised. Arrow keys still move between the cells and Ctrl/⌘+C still copies. A FilterTemplate gets the state as its context's Disabled, to disable its own control. The API methods are not blocked, so code can still sort, filter or page a disabled grid. The text color is --bit-DataGrid-disabled-color.
Cascading parameters
A value set on the params object applies wherever the grid does not set the parameter itself; one left null leaves the grid's own default. Put the BitParams high in the app - around the router in the layout - to make it app-wide. Since the grid is generic over its rows, only what does not depend on them can be shared: the look (Bordered, Striped, Hoverable, RowHeight, Height, Classes, Styles), the features (Filterable, Pageable, PageSize, Resizable, ShowSearchBox, the export buttons and their icons, ...), Strings, EmptyTemplate and LoadingTemplate. The data, the selectors, the selection, the templates typed over the row, the event callbacks, and the choices that belong to one data set - Editable, SelectionMode, RowReorderable, Virtualize, ToolbarTemplate, ExportFileName - stay on each grid.
Value text
null to keep the default: here four categories get a longer name and the others keep
their own, and the Discontinued flag reads as a status.
The text is used wherever the grid shows the value: the cells (unless a Template draws them) and their tooltips, the group headers (group by Category or Status), a Min or Max aggregate, the options of an enum or boolean column's filter and inline editor, and, with an in-memory source, what the quick search and the text filter operators match - search for "garden". It is display only: CSV, Excel and the clipboard keep writing the value formatted by Format (give a column an ExportValue to export other text), sorting still orders the values themselves, and an IQueryable or OnRead source searches and filters the stored value, except that an IQueryable's quick search matches an enum column's members by their text.
Without ValueText an enum member is shown by the name of its
[Display] attribute (translated when
the attribute names a ResourceType), or else by its own name, and a Format writes the value instead
(D for an enum's number). A new text - another mapping, or a new UI culture - reaches the cells, group
headers and options on the next render; the search and the aggregates follow when the grid refreshes its view, which
handing over another method does, while the same method returning other text needs RefreshAsync.
Pager & toolbar
ToolbarTemplate puts your own content at the start of the toolbar, before the built-in controls (Add row, the search box, Clear filters, the exports and Columns), and shows the toolbar on its own - here, buttons that move the pager and hide the header. A toolbar with nothing in it takes no room. Classes.Toolbar and Classes.Pager (and their Styles) style the two bars.
ShowHeader="false" hides the header rows - the column titles, the Group headers and the filter row - for a grid read as a plain list. Without headers there is nothing to click to sort, resize or reorder a column, so those are left to the API (Programmatic control).
Style & Class
The parts are Root, Toolbar, ColumnChooser, Viewport (the scrolling area), HeaderRow, HeaderCell, FilterRow, Row, SelectedRow, Cell, GroupRow, DetailRow, FooterRow, Pager, Empty, Loading and ReadError. A part's class comes before the per-row and per-column ones (RowClass, a column's HeaderClass and CellClass), which therefore win at equal weight; SelectedRow is added after Row. The classes land on elements the grid renders, so a page's isolated CSS reaches them through
::deep from a plain element of its own - the
div around the first grid (see the stylesheet tab).
RTL
In a right-to-left grid the start edge is the right: Frozen columns pin to the right and FrozenEnd ones to the left, Align's Start and End swap sides (Left and Right do not), and the horizontal arrow keys - cell navigation, a tree node's open and close, a resize handle - follow the reading direction. Pair it with translated Strings and column titles, as here; the category text comes from a Template, where ValueText would also translate the filter options, the group headers and the search.
Feedback
Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.