RayCraftDocs
v1.0.3 raycraft.dev
On this page

DataGrid

Complete

Table with sorting (click a header: ascending, descending, off), per-column filters, paging, row selection and templates.

Example

DataGrid control

Parameters

DataGrid

ParameterTypeDescription
AdaptiveboolShows each row as a card on narrow screens.
AllowAddboolShows an Add button that creates a new item (see NewItemFactory).
AllowCardViewboolAdds a toolbar button that switches between the table and the card view.
AllowDeleteboolShows the Delete command in the command column (asks for confirmation).
AllowEditboolShows the Edit command in the command column.
AllowPasteboolBatch mode: adds a Paste button that fills editable cells from tab separated clipboard text.
AllowViewboolAdds a View command that shows the row read-only in a dialog.
CardViewboolShows every row as a card instead of a table row. Use with @bind-CardView.
CellNavigationboolMakes the grid a keyboard grid: arrow keys, Home, End, Page Up and Page Down move between cells; Enter, F2 or Space activate the control in the cell.
ClassstringExtra CSS classes added to the root element.
ColumnMenuboolAdds a menu button to each header with sorting and hide column commands.
ColumnsRenderFragmentColumn definitions: DataGridColumn elements.
DataProviderFunc<DataGridRequest, ValueTask<DataGridResult<TItem>>>Loads rows from your side: receives the start, count, sort, filters, search, groups and aggregates and a cancellation token (cancelled when a newer request starts or the grid is removed), returns a DataGridResult.
DenseboolUses tighter cell padding.
DetailTemplateRenderFragment<TItem>Content shown under a row when its expand button is pressed.
EditModeDataGridEditModeNone, Row (inline), Dialog or Batch (all rows at once).
EmptyContentRenderFragmentShown when there are no rows.
ExportChoicesboolTurns Export into a menu: CSV or JSON, current view, selected rows, all rows, hidden columns.
ExportFileNamestringFile name of the CSV export, without the extension.
FilterOperatorsboolAdds an operator list (contains, starts with, equals, greater than, is empty...) above each filter box.
FormatRulesIEnumerable<DataGridFormatRule>Rules that colour cells or rows: field, filter operator, value, severity and Cell or Row. The first matching rule wins.
FreezeFirstColumnboolKeeps the first column visible while scrolling sideways.
FrozenColumnsintNumber of leading columns kept in view while the rest scrolls sideways.
FrozenEndColumnsintNumber of columns at the right edge that stay in view while the table scrolls sideways.
FrozenRowsintNumber of rows that stay under the header while the body scrolls (needs Height).
GroupByFunc<TItem, Object>Groups rows by the returned value; each group has a collapsible header.
GroupPanelboolAdds a strip above the table where users group rows by dragging headers or choosing columns.
GroupSummaryboolShows the column aggregates in the group rows (computed locally, or taken from DataGridResult.Groups with a DataProvider).
GroupTitlestringText before the group value in the header.
HeightstringMaximum height of the grid body, for example 24rem (default 28rem with VirtualScroll).
ItemKeyFunc<TItem, Object>Returns a stable key per item, so selection and open details survive reloads.
ItemsIEnumerable<TItem>The options to choose from.
KeyboardShortcutsboolCtrl+A select all, Ctrl+C copy selected rows, Esc clear selection, Alt+arrows change page.
LabelstringVisible label text (charts: accessible name; IconButton: accessible name and tooltip).
LoadingboolShows a progress bar above the rows.
LoadingSkeletonboolShows placeholder rows during the first load.
LoadMoreboolReplaces the pager by a Load more button that appends the next page.
MultiSortboolShift+click on headers sorts by several columns; the headers show the order.
NewItemFactoryFunc<TItem>Creates the item for a new row; default is the parameterless constructor.
NoMatchContentRenderFragmentContent shown when filters or search leave no rows (default: a text with Clear filters).
PageSizeintRows per page.
PageSizeOptionsIEnumerable<int>Row counts offered in a drop-down under the table.
PagingboolShows the paging bar (default true).
PastePreviewboolBatch mode: shows what a paste will change and asks before it is applied (default on).
PersistKeystringRemembers the position and size (Window), the split (Splitter) or the layout of a DataGrid (sort, filters, columns, widths, page) in local storage under this name and restores them next time.
ReorderableboolLets users move columns by dragging headers or with the Columns menu.
ResizableboolAdds a drag handle (and arrow keys) to resize each column.
RowClassFunc<TItem, string>Returns an extra CSS class for a row.
RowHeightintRow height in pixels when VirtualScroll is on (default 44).
RowMenuFunc<TItem, IEnumerable<MenuCommand>>Returns the commands of the context menu of a row.
RowReorderboolLets rows be dragged onto each other; handle RowMoved to change your list.
RowSeverityFunc<TItem, Severity?>Returns a severity to tint a row, or null.
RowValidatorFunc<TItem, IEnumerable<string>>Checks the whole row after the edit is applied; returns error texts.
SelectedItemsIEnumerable<TItem>Selected rows. Use with @bind-SelectedItems.
SelectionSelectionModeNone (default), Single or Multiple.
SelectionActionsRenderFragment<IReadOnlyList<TItem>>Buttons in the selection bar; receives the selected items.
ServerBulkLimitintWith DataProvider: the largest number of rows the grid asks for in one request to select all filtered rows or to export them (default 10000). Above it only the rows on the page are used.
ShowCopyboolShows the copy button.
ShowFiltersboolShows a filter box under each filterable column header.
ShowPrintboolAdds a Print button that prints the table.
ShowSearchboolAdds a search box that finds text in all columns and marks it in the cells.
ShowSelectionBarboolShows the bar with the selected count, select all rows and clear selection (Multiple selection).
ShowToolbarboolShows the toolbar with the column chooser and CSV export.
StripedboolShades every second row.
StylestringInline style added to the root element.
ToolbarContentRenderFragmentExtra content in the toolbar of a grid with ShowToolbar, for example DataGridSpreadsheetButton.
TypedFiltersboolUses number, date and yes/no filter boxes by the type of the column values (default on).
UndoRedoboolAdds Undo and Redo for saved row edits, added rows and deleted rows (buttons and Ctrl+Z / Ctrl+Y).
ValueFiltersboolAdds a value list filter (search, select all, clear) to each filterable header; works on items in memory.
VirtualScrollboolDraws only the visible rows (rows must have the fixed RowHeight).

DataGridColumn

ParameterTypeDescription
AggregateDataGridAggregateAdds a summary row value: Sum, Average, Min, Max or Count.
AlignTextAlignLeft (default), Center or Right.
BadgeSeveritiesIReadOnlyDictionary<string, Severity>Colour of a Badge column per value.
CellSeverityFunc<TItem, Severity?>Returns a severity to tint a cell, or null.
ColumnSpanFunc<TItem, int>Returns how many columns the cell of an item covers.
DataBarboolDraws a bar behind numbers relative to the largest value of the column.
EditableboolLets users edit the cells of the column by clicking them.
EditOnDataGridEditOnAlways, Create (only new rows) or Update (only existing rows).
EditorOptionsIEnumerable<KeyValuePair<string, string>>Value and label pairs; the editor becomes a list.
FieldstringProperty name of the item (nested names such as Address.City work). It reads the cell, sorts and filters when Value is not set, and it is sent to DataProvider as the column identifier (defaults to Title).
FilterableboolShows a filter box for this column (default true).
FormatstringFormat string for numbers and dates, e.g. N0 or d.
GroupstringText of the stacked header above this column; neighbors with the same text share one cell.
HelpTextstringA hint shown under the field in the edit dialog.
HiddenboolHides the column at first; users can show it from the toolbar.
ImageAltFunc<TItem, string>Alternative text of an Image column per row.
ImageHeightintHeight of the picture in pixels (default 32).
LinkHrefFunc<TItem, string>Address of a Link column per row (default: the value).
LinkTargetstringTarget of the link, for example _blank.
MaxDouble?Largest allowed value (ProgressBar: the value that means 100%; Rating: number of stars).
MaxLengthint?Largest number of characters allowed.
MaxWidthstringContainer: fixed maximum width from a breakpoint (Xs to Xxl). DataGridColumn: largest width as a CSS length; the resize handle stops at it.
MergeRowsboolMerges vertically neighboring cells that have the same text.
MinDouble?Smallest allowed value.
MinLengthint?Smallest number of characters accepted when saving an edit.
PatternstringRegular expression the edited text must match.
PatternMessagestringError text shown when Pattern does not match.
ProgressMaxDoubleValue that fills a Progress column (default 100).
RequiredboolThe editor refuses an empty value.
SortableboolAllows sorting by this column (default true).
TemplateRenderFragment<TItem>Custom cell content. The row is available as context.
TitlestringTitle text (drawer header, tab caption, column header, step caption).
TypeDataGridColumnTypeHow the cell is drawn: Text, Check, Image, Progress, Link, Badge or Dropdown.
ValidateFunc<TItem, Object, string>Stepper step: runs before moving on, return false to stay on the step. DataGrid column: receives the item and the parsed value and returns an error text or null.
ValueFunc<TItem, Object>Returns the cell value. Used for display, sorting and filtering.
WidthstringSkeleton: any CSS length. Charts: drawing width in SVG units (the chart still scales to its container).

Events

DataGrid

EventTypeDescription
CardViewChangedEventCallback<bool>Raised when the user switches between the table and the cards.
OnLoadErrorEventCallback<Exception>Raised with the exception when DataProvider fails; the grid then shows no rows. Without a handler the error goes to the error boundary.
OnRowDeletingEventCallback<DataGridRowChange<TItem>>Runs after the confirmation; set Error on the argument to cancel the delete.
OnRowSavingEventCallback<DataGridRowChange<TItem>>Runs before a row is kept; set Error on the argument to cancel and show the text.
PageSizeChangedEventCallback<int>Raised when another page size is chosen.
RowAddedEventCallback<TItem>Raised with the new item after it was saved; add it to your list.
RowDeletedEventCallback<TItem>Raised with the item after the delete was confirmed; remove it from your list.
RowMovedEventCallback<DataGridRowMove<TItem>>Raised when a row is dropped on another row: the item, the page indexes (FromIndex, ToIndex), the indexes in the whole sorted and filtered list (AbsoluteFromIndex, AbsoluteToIndex; PageOffset is the difference) and the item that was dropped on (TargetItem).
RowSavedEventCallback<TItem>Raised with the item after a valid edit was applied to it.
RowsPastedEventCallback<int>Raised with the number of rows filled by Paste.
SelectedItemsChangedEventCallback<IEnumerable<TItem>>Raised when the selection changes.
StateChangedEventCallback<DataGridState>Reports the DataGridState after every change of sort, filters, columns, widths or page.

DataGridColumn

EventTypeDescription
EditedEventCallback<DataGridEdit<TItem>>Raised with the item and the new text when an edit is confirmed.

Package

DataGrid is part of RayCraft Complete. Package: RayCraft.Blazor.Complete. It comes from the private RayCraft feed and needs an active license. See Getting started.