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.
Interaction & state
Dragging rows into a new order, row and cell events with a custom context menu, the programmatic API and its change events, and saving and restoring the grid's state.
Row reordering
The move is made in place only when Items is a mutable list (IList<T>); otherwise OnRowReorder's FromIndex and ToIndex are
null and the new order is yours to apply
from DraggedItem and TargetItem. Persist the order in the handler. Because a move is made by index in
the bound list, the handle also pauses while a search is on, and is not offered in a tree, with OnRead,
OnLoadMore or an IQueryable. That is why this grid sets Sortable="false": a header click would sort the
rows and pause the handle. A disabled grid moves nothing.
Cell events & context menu
The arguments carry the row (Item), the Column with its ColumnId and ColumnTitle, the cell's raw Value (not its formatted text) and the Mouse event, whose coordinates place the menu here. While OnCellContextMenu is set the browser's own menu is suppressed on the data cells.
A click on a control inside a cell belongs to the control: a button, link or field of a template, an ARIA widget, an element in the tab order, an element marked
data-bit-interactive, the grid's own checkboxes and toggles, and
anything in a dialog or a grid inside the cell raise none of the row and cell events, select nothing and expand
nothing - and a right-click there keeps the browser's menu. Mark an element of a template
data-bit-interactive to treat it so (an icon with an @onclick), or
data-bit-interactive="false" to let a control's clicks reach the cell and the row. A disabled grid raises
none of these events. The menu itself is the page's own markup (see the stylesheet tab); the grid only reports the
click.
Programmatic control
The methods take a column by its id - the ColumnId, or the property path of a bound column (
Price,
Address.City). SortByAsync replaces the sort unless additive is true, and
BitDataGridSortDirection.None removes the column's sort; ApplyFilterAsync replaces the column's filter,
ApplyRangeFilterAsync sets a from-inclusive, to-exclusive range; GoToPageAsync takes a 1-based page and
clamps it; SetPageSizeAsync and SearchAsync go back to the first page; MoveColumnAsync takes a
0-based position among all the columns. ActiveSorts, ActiveFilters, ActiveGroups,
ActiveSearch, CurrentPage, TotalPages and TotalCount read the current view.
The change events fire for the user's changes and the API's alike, with the new descriptors (OnPageChange with the 1-based page, also when the page size changes). OnViewChange tells rows apart by KeyField (by reference without one), so give it a key when the source hands over new instances of the same rows; it is raised with a list, a tree or an IQueryable, while OnRead and OnLoadMore grids hold only a window of the view - GetViewItemsAsync reads it all there, and GetViewItems returns the loaded rows. RevealItemAsync returns
false when the row is not in the view (filtered out, say). RefreshAsync recomputes the
view, or reads it again from a server.
State persistence
The snapshot is a plain BitDataGridState - CurrentPage, PageSize (null while the PageSize parameter applies), Search, Sorts, Filters, Groups, GroupsCollapsed with the GroupExpansionOverrides, and a BitDataGridColumnState per column (ColumnId, Visible, the resized Width and the Order) - so it serializes as it is, to local storage or a user profile. It does not hold the selection, the open detail rows or the open tree nodes (a tree node is known only by its KeyField, which need not serialize). Columns are matched by id, so a template-only column needs a ColumnId of its own for its layout to come back.
Apply the state once the grid has rendered and its columns have registered - from OnAfterRenderAsync, as here. ApplyStateAsync does not raise OnStateChange; every other change does, the user's and the API's alike, after the grid has re-rendered.
Feedback
Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.