Data grid
The <FluentDataGrid>
component is used to display tabular data. The <FluentDataGridRow>
and <FluentDataGridCell>
components are typically created programmatically by the parent grid but some
authors may find it useful to create them manually.
Important
As of version 4.11.0, the DataGrid uses standard HTML table elements for rendering the grid (previously web components were used for this). When upgrading to this version, please be aware of the following:- A lot of changes have been made to the structure of the rendered content and the class names used. If you have been overriding grid classes in your own code, these probably no longer work.
- When you have rows in a table with content that needs to span multiple lines, you now need to use and set the new MultiLine (bool) parameter of the FluentDataGrid. Previously this could be done by setting a RowClass on a column but that does not work anymore
-
The parameter
ResizeLabel
has been removed in favor of 3 new parameters. This makes changing strings in the DataGrid UI easier. SeeChange strings used in the UI for more information. - It is currently not possible to use the
OnRowFocus
andOnCellFocus
event callbacks. You can use theOnRowClick
,OnRowDoubleClick
andOnCellClick
alternatives. As of v4.11.1 theOnCellFocus
event callback will be operational again. ForOnRowFocus
, we are waiting for the necessary support being added by the different browsers. See https://chromestatus.com/feature/6237396851228672 for more information.
Do not use the RowStyle
parameter to dynamically update a row style after rendering (for example to highlight a row which was clicked on)
as this will interfere with the DataGrid scripts that use this attribute as well. Use the RowClass
instead.
Accessibility
You can use the Arrow keys to navigate through a DataGrid. When a header cell is focused and the column is sortable, you can use the Tab key to select the sort button. Pressing the Enter key will toggle the sorting direction. Pressing Ctrl+Enter removes the column sorting and restores the default/start situation with regards to sorting. You cannot remove the default grid sorting with this key combination.
When a header cell is focused and the column allows setting options, you can use the Tab key to select the options button. Pressing the Enter key then will toggle the options popover. Pressing Esc closes the popover .
When a grid allows resizing of the columns, you can use the + and - keys to resize the column the focused header belongs to. Incrementing/decrementing width is done in steps of 10 pixels at a time. You can reset to the original initial column widths by pressing Shift + r.
When a row cell is focused and the grid contains a SelectColumn
column, you can use the Enter key to select or unselect the current row.
Sorting
The DataGrid supports sorting by clicking on the column headers. The default sort direction is ascending. Clicking on the same column header again will toggle the sort direction. A sort can be removed by right clicking (or by pressing Shift+R) on the header column (with exception of the default sort).
Row size
As of v4.11.0, the Datagrid offers a RowSize
parameter which allows you to use different preset row heights. The value uses the DataGridRowSize
enumeration for its type.
When using Virtualize
, the ItemSize
value is used is still used to indicate the row height.
Resizing columns
The DataGrid supports resizing columns by both dragging and through column option popups in exact or discrete mode. As of v4.12.0,
the default behavior is to initiate a resize action by dragging the column edge on every row. In earlier versions this could only be done
on the header column edge. To go back to the previous behavior, the new (as of v4.12.1) ResizeColumnOnAllRows
parameter can be set to false.
The following parameters can be used to tweak the resize handle appearance:
.fluent-data-grid {
--fluent-data-grid-resize-handle-color: var(--accent-fill-rest);
--fluent-data-grid-resize-handle-width: 1px;
--fluent-data-grid-header-opacity: 0.5;
DisplayMode
The DataGrid supports 2 different display modes through the DisplayMode
parameter: DataGridDisplayMode.Grid
(default) and
DataGridDisplayMode.Table
. When set to Grid
, the GridTableColumns
parameter cam be used set specify column
widths in fractions. It basically provides an HTML table element with a display: grid;
style. The Table
mode uses standard
HTML table elements and rendering. Column widths in that mode are best specified through the Width
parameter of the columns.
Specifically when using Virtualize
, it is higly recommended to use the Table
display mode as the Grid
mode
can exhibit some odd behaviour when scrolling.
Change strings used in the UI
The DataGrid has a number of strings that are used in the UI. These can be changed by setting the ColumnOptionLabels
, ColumnResizeLabels
and ColumnSortLabels
parameters.
Each of these parameters is a record that contains properties for the strings that that specific piece of UI is using. There is a default implementation for each record.
See below for a simplified example on how you can change these strings.
private ColumnResizeLabels _resizeLabels = ColumnResizeLabels.Default;
:
:
protected override async Task OnInitializedAsync()
{
_resizeLabels = ColumnResizeLabels.Default with
{
ExactLabel = "...",
ResizeMenu = "..."
};
:
:
You only need to override the values that you actually want to change.
Using the DataGrid component with EF Core
If you want to use the FluentDataGrid
with data provided through EF Core, you need to install an additional package so the
grid knows how to resolve queries asynchronously for efficiency.
Installation
Install the package by running the command:dotnet add package Microsoft.FluentUI.AspNetCore.Components.DataGrid.EntityFrameworkAdapter
Usage
In yourProgram.cs
file you need to add the following after the builder.Services.AddFluentUIComponents();
line:
builder.Services.AddDataGridEntityFrameworkAdapter();
Using the DataGrid component with OData
Added in 4.11.0
If you want to use the FluentDataGrid
with data provided through OData, you need to install an additional package so the
grid knows how to resolve queries asynchronously for efficiency.
Installation
Install the package by running the command:dotnet add package Microsoft.FluentUI.AspNetCore.Components.DataGrid.ODataAdapter
Usage
In yourProgram.cs
file you need to add the following after the builder.Services.AddFluentUIComponents();
line:
builder.Services.AddDataGridODataAdapter();
Examples
See the following pages for examples and additional documentation on the situations that ech example shows.
Basics
Layout
Sorting
Columns
Advanced
Documentation
FluentDataGrid<TGridItem> Class
Parameters
Name | Type | Default | Description |
---|---|---|---|
AutoFit | bool | False | Sets GridTemplateColumns to automatically fit the columns to the available width as best it can. |
AutoFocus | bool | False | Gets or sets a value indicating whether the grids' first cell should be focused. |
AutoItemsPerPage | bool | False | Automatically fit the number of items per page to the available height. |
ChildContent | RenderFragment? | Gets or sets the child components of this instance. For example, you may define columns by adding components derived from the ColumnBase base class. | |
ColumnOptionsLabels | ColumnOptionsLabels | Labels used in the column options UI. | |
ColumnResizeLabels | ColumnResizeLabels | (Aria) Labels used in the column resize UI. | |
ColumnSortLabels | ColumnSortLabels | Labels used in the column sort UI. | |
DisplayMode | DataGridDisplayMode | Grid | Gets or set the DataGridDisplayMode of the grid.Default is 'Grid'. When set to Grid, GridTemplateColumns can be used to specify column widths.When set to Table, widths need to be specified at the column level. When using Virtualize , it is recommended to use Table. |
EmptyContent | RenderFragment? | If specified, grids render this fragment when there is no content. | |
GenerateHeader | GenerateHeaderOption? | Default | Gets or sets a value indicating whether the grid should automatically generate a header row and its type. See GenerateHeaderOption |
GridTemplateColumns | string? | Gets or sets the value that gets applied to the css gridTemplateColumns attribute of child rows. Can be specified here or on the column level with the Width parameter but not both. Needs to be a valid CSS string of space-separated values, such as 'auto 1fr 2fr 100px'. | |
HeaderCellAsButtonWithMenu | bool | False | If true, enables the new style of header cell that includes a button to display all column options through a menu. |
IsFixed | bool | False | Gets or sets a value indicating whether the grid's dataset is not expected to change during its lifetime. When set to true, reduces automatic refresh checks for better performance with static datasets. Default is false to maintain backward compatibility. |
ItemKey | Func<TGridItem, Object> | Optionally defines a value for @key on each rendered row. Typically this should be used to specify a unique identifier, such as a primary key value, for each data item. This allows the grid to preserve the association between row elements and data items based on their unique identifiers, even when the example, after a new query against the underlying data store). If not set, the @key will be the | |
Items | IQueryable<TGridItem>? | Gets or sets a queryable source of data for the grid. This could be in-memory data converted to queryable using the Queryable.AsQueryable(IEnumerable) extension method,or an EntityFramework DataSet or an IQueryable derived from it.You should supply either Items or ItemsProvider , but not both. | |
ItemSize | float | 32 | This is applicable only when using Virtualize . It defines an expected height in pixels foreach row, allowing the virtualization mechanism to fetch the correct number of items to match the display size and to ensure accurate scrolling. |
ItemsProvider | GridItemsProvider<TGridItem>? | Gets or sets a callback that supplies data for the rid. You should supply either Items or ItemsProvider , but not both. | |
Loading | bool? | Gets or sets a value to indicate the grid loading data state. If not set and a ItemsProvider is present, the grid will show LoadingContent until the provider's first return. | |
LoadingContent | RenderFragment? | Gets or sets the content to render when Loading is true.A default fragment is used if loading content is not specified. | |
MultiLine | bool | False | Gets or sets a value indicating whether the grid should allow multiple lines of text in cells. Cannot be used together with Virtualize. |
NoTabbing | bool | False | Gets or sets a value indicating whether the component will not add itself to the tab queue. Default is false. |
OverscanCount | int | 3 | This is applicable only when using Virtualize . It defines how many additional items will be renderedbefore and after the visible region to reduce rendering frequency during scrolling. While higher values can improve scroll smoothness by rendering more items off-screen, they can also increase initial load times. Finding a balance based on your data set size and user experience requirements is recommended. The default value is 3. |
Pagination | PaginationState? | Optionally links this FluentDataGrid instance with a PaginationState model,causing the grid to fetch and render only the current page of data. This is normally used in conjunction with a FluentPaginator component or some other UI logicthat displays and updates the supplied PaginationState instance. | |
RefreshItems | Func<GridItemsProviderRequest<TGridItem>, Task>? | Gets or sets a callback which will be called if there is a change in pagination, ordering or if a RefreshDataAsync is forced. You must supply Items if you use this callback. | |
ResizableColumns | bool | False | If true, renders draggable handles around the column headers and adds a button to invoke a resize UI. This allows the user to resize columns manually. Size changes are not persisted. |
ResizeColumnOnAllRows | bool | True | Gets or sets a value indicating whether column resize handles should extend the full height of the grid. When true, columns can be resized by dragging from any row. When false, columns can only be resized by dragging from the column header. Default is true. |
ResizeType | DataGridResizeType? | To comply with WCAG 2.2, a one-click option should be offered to change column widths. We provide such an option through the ColumnOptions UI. This parameter allows you to enable or disable this resize UI.Enable it by setting the type of resize to perform Discrete: resize by a 10 pixels at a time Exact: resize to the exact width specified (in pixels) Note: This does not affect resizing by mouse dragging, just the keyboard driven resize. | |
RowClass | Func<TGridItem, string>? | Optionally defines a class to be applied to a rendered row. | |
RowSize | DataGridRowSize | Small | Gets or sets the size of each row in the grid based on the DataGridRowSize enum. |
RowStyle | Func<TGridItem, string>? | Optionally defines a style to be applied to a rendered row. Do not use to dynamically update a row style after rendering as this will interfere with the script that use this attribute. Use RowClass instead. | |
SaveStateInUrl | bool | False | Gets or sets a value indicating whether the grid should save its paging state in the URL. |
SaveStatePrefix | string? | Gets or sets a prefix to use when saving the grid state in the URL. | |
ShowHover | bool | False | Gets or sets a value indicating whether the grid should show a hover effect on rows. |
SortByAscending | bool? | False | |
UseMenuService | bool | True | Use IMenuService to create the menu, if this service was injected. This value must be defined before the component is rendered (you can't change it during the component lifecycle). Default, true. |
Virtualize | bool | False | If true, the grid will be rendered with virtualization. This is normally used in conjunction with scrolling and causes the grid to fetch and render only the data around the current scroll viewport. This can greatly improve the performance when scrolling through large data sets. If you use Virtualize , you should supply a value for ItemSize and mustensure that every row renders with the same constant height. Generally it's preferable not to use Virtualize if the amount of data being renderedis small or if you are using pagination. |
EventCallbacks
Name | Type | Description |
---|---|---|
OnCellClick | EventCallback<FluentDataGridCell<TGridItem>> | Gets or sets a callback when a cell is clicked. |
OnCellFocus | EventCallback<FluentDataGridCell<TGridItem>> | Gets or sets a callback when a row is focused. |
OnRowClick | EventCallback<FluentDataGridRow<TGridItem>> | Gets or sets a callback when a row is clicked. |
OnRowDoubleClick | EventCallback<FluentDataGridRow<TGridItem>> | Gets or sets a callback when a row is double-clicked. |
OnRowFocus | EventCallback<FluentDataGridRow<TGridItem>> | Gets or sets a callback when a row is focused. As of 4.11 a row is a tr element with a 'display: contents'. Browsers can not focus such elements currently, but work is underway to fix that. |
Methods
Name | Parameters | Type | Description |
---|---|---|---|
CloseColumnOptionsAsync | Task | Closes the ColumnBase UI that was previously displayed. | |
DisposeAsync | ValueTask | ||
OnKeyDownAsync | FluentKeyCodeEventArgs args | Task | |
RefreshDataAsync | bool force | Task | Instructs the grid to re-fetch and render the current data from the supplied data source (either Items or ItemsProvider ). |
RemoveSortByColumnAsync | ColumnBase<TGridItem> column | Task | Removes the grid's sort on double click for the currently sorted column if it's not a default sort column. |
RemoveSortByColumnAsync | Task | Removes the grid's sort on double click for the currently sorted column if it's not a default sort column. | |
ResetColumnWidthsAsync | Task | Resets the column widths to their initial values as specified with the GridTemplateColumns parameter.If no value is specified, the default value is '1fr' for each column. | |
SetColumnWidthDiscreteAsync | int? columnIndex float widthChange | Task | Resizes the column width by a discrete amount. |
SetColumnWidthExactAsync | int columnIndex int width | Task | Resizes the column width to the exact width specified (in pixels). |
SetLoadingState | bool? loading | void | |
ShowColumnOptionsAsync | ColumnBase<TGridItem> column | Task | Displays the ColumnBase UI for the specified column index,closing any other column options UI that was previously displayed. If the index is out of range, nothing happens. |
ShowColumnOptionsAsync | string title | Task | Displays the ColumnBase UI for the specified column index,closing any other column options UI that was previously displayed. If the index is out of range, nothing happens. |
ShowColumnOptionsAsync | int index | Task | Displays the ColumnBase UI for the specified column index,closing any other column options UI that was previously displayed. If the index is out of range, nothing happens. |
ShowColumnResizeAsync | ColumnBase<TGridItem> column | Task | Displays the column resize UI for the specified column, closing any other column resize UI that was previously displayed. |
ShowColumnResizeAsync | string title | Task | Displays the column resize UI for the specified column, closing any other column resize UI that was previously displayed. |
ShowColumnResizeAsync | int index | Task | Displays the column resize UI for the specified column, closing any other column resize UI that was previously displayed. |
SortByColumnAsync | ColumnBase<TGridItem> column SortDirection direction | Task | Sorts the grid by the specified column index. If the index is out of range, nothing happens. |
SortByColumnAsync | string title SortDirection direction | Task | Sorts the grid by the specified column index. If the index is out of range, nothing happens. |
SortByColumnAsync | int index SortDirection direction | Task | Sorts the grid by the specified column index. If the index is out of range, nothing happens. |
UpdateItemsPerPageAsync | int visibleRows | Task | Updates the Pagination s ItemPerPage parameter.Guards the CurrentPageIndex from getting greater than the LastPageIndex |
PropertyColumn<TGridItem, TProp> Class
Parameters
Name | Type | Default | Description |
---|---|---|---|
Align | Align | Start | If specified, controls the justification of header and grid cells for this column. |
ColumnOptions | RenderFragment? | If specified, indicates that this column has this associated options UI. A button to display this UI will be included in the header cell by default. If ColumnBase is used, it is left up to that template to render any relevant'show options' UI and invoke the grid's ShowColumnOptionsAsync(ColumnBase{}) ). | |
Comparer | IComparer<TProp>? | Optionally specifies how to compare values in this column when sorting. Using this requires the System.IComparable . | |
Filtered | bool? | Gets or sets a value indicating whether the data is currently filtered by this column. The default value is false. | |
Format | string? | Optionally specifies a format string for the value. Using this requires the System.IFormattable . | |
HeaderCellItemTemplate | RenderFragment<ColumnBase<TGridItem>>? | Gets or sets an optional template for this column's header cell. If not specified, the default header template includes the ColumnBase along with any applicable sort indicators and options buttons. | |
HeaderCellTitleTemplate | RenderFragment<ColumnBase<TGridItem>>? | Gets or sets a template for the title content of this column's header cell. If not specified, the default header template includes the ColumnBase . | |
HeaderTooltip | string? | Gets or sets the tooltip text for the column header. | |
Index | int | 0 | Gets or sets the index (1-based) of the column |
InitialSortDirection | SortDirection | Auto | Gets or sets the initial sort direction. if ColumnBase is true. |
IsDefaultSortColumn | bool | False | Gets or sets a value indicating whether this column should be sorted by default. |
PlaceholderTemplate | RenderFragment<PlaceholderContext>? | If specified, virtualized grids will use this template to render cells whose data has not yet been loaded. | |
Property | Expression<Func<TGridItem, TProp>> | Defines the value to be displayed in this column's cells. | |
PropertyInfo | PropertyInfo? | ||
Sortable | bool? | Gets or sets a value indicating whether the data should be sortable by this column. The default value may vary according to the column type (for example, a TemplateColumn or PropertyColumn`2 is sortable by default if anyTemplateColumn or PropertyColumn`2.SortBy parameter is specified). | |
SortBy | IGridSort<TGridItem>? | Gets or sets the sorting rules for a column. | |
Title | string? | Gets or sets the title text for the column. This is rendered automatically if ColumnBase is not used. | |
Tooltip | bool | False | If true, generates a title and aria-label attribute for the cell contents |
TooltipText | Func<TGridItem, string>? | Gets or sets the function that defines the value to be used as the tooltip and aria-label in this column's cells | |
Width | string? | Gets or sets the width of the column. Use either this or the FluentDataGrid GridTemplateColumns parameter but not both.Needs to be a valid CSS width value like '100px', '10%' or '0.5fr'. |
TemplateColumn<TGridItem> Class
Parameters
Name | Type | Default | Description |
---|---|---|---|
Align | Align | Start | If specified, controls the justification of header and grid cells for this column. |
ChildContent | RenderFragment<TGridItem> | Gets or sets the content to be rendered for each row in the table. | |
ColumnOptions | RenderFragment? | If specified, indicates that this column has this associated options UI. A button to display this UI will be included in the header cell by default. If ColumnBase is used, it is left up to that template to render any relevant'show options' UI and invoke the grid's ShowColumnOptionsAsync(ColumnBase{}) ). | |
Filtered | bool? | Gets or sets a value indicating whether the data is currently filtered by this column. The default value is false. | |
HeaderCellItemTemplate | RenderFragment<ColumnBase<TGridItem>>? | Gets or sets an optional template for this column's header cell. If not specified, the default header template includes the ColumnBase along with any applicable sort indicators and options buttons. | |
HeaderCellTitleTemplate | RenderFragment<ColumnBase<TGridItem>>? | Gets or sets a template for the title content of this column's header cell. If not specified, the default header template includes the ColumnBase . | |
HeaderTooltip | string? | Gets or sets the tooltip text for the column header. | |
Index | int | 0 | Gets or sets the index (1-based) of the column |
InitialSortDirection | SortDirection | Auto | Gets or sets the initial sort direction. if ColumnBase is true. |
IsDefaultSortColumn | bool | False | Gets or sets a value indicating whether this column should be sorted by default. |
PlaceholderTemplate | RenderFragment<PlaceholderContext>? | If specified, virtualized grids will use this template to render cells whose data has not yet been loaded. | |
Sortable | bool? | Gets or sets a value indicating whether the data should be sortable by this column. The default value may vary according to the column type (for example, a TemplateColumn or PropertyColumn`2 is sortable by default if anyTemplateColumn or PropertyColumn`2.SortBy parameter is specified). | |
SortBy | IGridSort<TGridItem>? | ||
Title | string? | Gets or sets the title text for the column. This is rendered automatically if ColumnBase is not used. | |
Tooltip | bool | False | If true, generates a title and aria-label attribute for the cell contents |
TooltipText | Func<TGridItem, string>? | Gets or sets the function that defines the value to be used as the tooltip and aria-label in this column's cells | |
Width | string? | Gets or sets the width of the column. Use either this or the FluentDataGrid GridTemplateColumns parameter but not both.Needs to be a valid CSS width value like '100px', '10%' or '0.5fr'. |
SelectColumn<TGridItem> Class
Parameters
Name | Type | Default | Description |
---|---|---|---|
Align | Align | Start | If specified, controls the justification of header and grid cells for this column. |
ChildContent | RenderFragment<TGridItem> | Gets or sets the content to be rendered for each row in the table. | |
ColumnOptions | RenderFragment? | If specified, indicates that this column has this associated options UI. A button to display this UI will be included in the header cell by default. If ColumnBase is used, it is left up to that template to render any relevant'show options' UI and invoke the grid's ShowColumnOptionsAsync(ColumnBase{}) ). | |
Filtered | bool? | Gets or sets a value indicating whether the data is currently filtered by this column. The default value is false. | |
HeaderCellItemTemplate | RenderFragment<ColumnBase<TGridItem>>? | Gets or sets an optional template for this column's header cell. If not specified, the default header template includes the ColumnBase along with any applicable sort indicators and options buttons. | |
HeaderCellTitleTemplate | RenderFragment<ColumnBase<TGridItem>>? | Gets or sets a template for the title content of this column's header cell. If not specified, the default header template includes the ColumnBase . | |
HeaderTooltip | string? | Gets or sets the tooltip text for the column header. | |
IconChecked | Icon? | Gets or sets the Icon to be rendered when the row is selected. | |
IconIndeterminate | Icon? | Preview:
| Gets or sets the Icon to be rendered when some but not all rows are selected. Only when SelectColumn is Multiple. |
IconUnchecked | Icon? | Gets or sets the Icon to be rendered when the row is non selected. | |
Index | int | 0 | Gets or sets the index (1-based) of the column |
InitialSortDirection | SortDirection | Auto | Gets or sets the initial sort direction. if ColumnBase is true. |
IsDefaultSortColumn | bool | False | Gets or sets a value indicating whether this column should be sorted by default. |
PlaceholderTemplate | RenderFragment<PlaceholderContext>? | If specified, virtualized grids will use this template to render cells whose data has not yet been loaded. | |
Property | Func<TGridItem, bool> | Gets or sets the function to executed to determine checked/unchecked status. | |
Selectable | Func<TGridItem, bool>? | Gets or sets the function executed to determine if the item can be selected. | |
SelectAll | bool? | False | Gets or sets the value indicating whether the [All] checkbox is selected. Null is undefined. |
SelectAllDisabled | bool | False | Gets or sets whether the [All] checkbox is disabled (not clickable). |
SelectAllTemplate | RenderFragment<SelectAllTemplateArgs>? | Gets or sets the template for the [All] checkbox column template. | |
SelectedItems | IEnumerable<TGridItem> | Gets or sets the list of selected items. | |
SelectFromEntireRow | bool | True | Gets or sets whether the selection of rows is restricted to the SelectColumn (false) or if the whole row can be clicked to toggled the selection (true). Default is True. |
SelectMode | DataGridSelectMode | Single | Gets or sets the selection mode (Single, SingleSticky or Multiple). |
Sortable | bool? | Gets or sets a value indicating whether the data should be sortable by this column. The default value may vary according to the column type (for example, a TemplateColumn or PropertyColumn`2 is sortable by default if anyTemplateColumn or PropertyColumn`2.SortBy parameter is specified). | |
SortBy | IGridSort<TGridItem>? | ||
Title | string? | Gets or sets the title text for the column. This is rendered automatically if ColumnBase is not used. | |
TitleAllChecked | string | All rows are selected. | Gets or sets the Icon title display as a tooltip and used with Accessibility. The default text is 'All rows are selected.'. |
TitleAllIndeterminate | string | Some rows are selected. | Gets or sets the Icon title display as a tooltip and used with Accessibility. The default text is 'Some rows are selected.'. |
TitleAllUnchecked | string | No rows are selected. | Gets or sets the Icon title display as a tooltip and used with Accessibility. The default text is 'No rows are selected.'. |
TitleChecked | string | Row selected. | Gets or sets the Icon title display as a tooltip and used with Accessibility. The default text is 'Row selected'. |
TitleUnchecked | string | Row unselected | Gets or sets the Icon title display as a tooltip and used with Accessibility. The default text is 'Row unselected'. |
Tooltip | bool | False | If true, generates a title and aria-label attribute for the cell contents |
TooltipText | Func<TGridItem, string>? | Gets or sets the function that defines the value to be used as the tooltip and aria-label in this column's cells | |
Width | string? | 50px | Gets or sets the width of the column. Use either this or the FluentDataGrid GridTemplateColumns parameter but not both.Needs to be a valid CSS width value like '100px', '10%' or '0.5fr'. |
EventCallbacks
Name | Type | Description |
---|---|---|
OnSelect | EventCallback<(TGridItem Item, bool Selected)> | Gets or sets the action to be executed when the row is selected or unselected. This action is required to update you data model. |
SelectAllChanged | EventCallback<bool?> | Gets or sets the action to be executed when the [All] checkbox is clicked. When this action is defined, the [All] checkbox is displayed. This action is required to update you data model. |
SelectedItemsChanged | EventCallback<IEnumerable<TGridItem>> | Gets or sets a callback when list of selected items changed. |
Methods
Name | Parameters | Type | Description |
---|---|---|---|
ClearSelection | void | Allows to clear the selection. | |
ClearSelectionAsync | Task | Allows to clear the selection. |
Column menu labels and icons
For customizing/translating the labels and icons used in the column menus, the following records
are available. They can be applied
to a grid by setting the respective parameters to an instance of these records. If you do not want to use an icon for a menu item, supply a null
value to the Icon property in a record:
ColumnResizeLabels resizeLabels = ColumnResizeLabels.Default with
{
DiscreteLabel = "Abcd efg",
ResetAriaLabel = "hij klm",
Icon = null
};
ColumnSortLabels Class
Properties
Name | Type | Default | Description |
---|---|---|---|
Default | ColumnSortLabels | Gets the default labels for the sort UI. | |
Icon | Icon? | Preview:
| Gets or sets the icon to show in the column menu |
IconPositionStart | bool | True | Gets or sets whether the icon is positioned at the start (true) or at the end (false) of the menu item |
SortMenu | string | Sort | Gets or sets the text shown in the column menu |
SortMenuAscendingLabel | string | Sort (ascending) | Gets or sets the text shown in the column menu when in ascending order |
SortMenuDescendingLabel | string | Sort (descending) | Gets or sets the text shown in the column menu when in descending order |
Methods
Name | Parameters | Type | Description |
---|---|---|---|
<Clone>$ | ColumnSortLabels |
ColumnOptionsLabels Class
Properties
Name | Type | Default | Description |
---|---|---|---|
Default | ColumnOptionsLabels | Gets the default labels for the options UI. | |
Icon | Icon? | Preview:
| Gets or sets the icon to show in the column menu |
IconPositionStart | bool | True | Gets or sets whether the icon is positioned at the start (true) or at the end (false) of the menu item |
OptionsMenu | string | Filter | Gets or sets the text shown in the column menu |
Methods
Name | Parameters | Type | Description |
---|---|---|---|
<Clone>$ | ColumnOptionsLabels |
ColumnResizeLabels Class
Properties
Name | Type | Default | Description |
---|---|---|---|
Default | ColumnResizeLabels | Gets the default labels for the resize UI. | |
DiscreteLabel | string | Column width | Gets or sets the label in the discrete mode resize UI |
ExactLabel | string | Column width (in pixels) | Gets or sets the label in the exact mode resize UI |
GrowAriaLabel | string? | Grow column width | Gets or sets the aria label for the grow button in the discrete resize UI |
Icon | Icon? | Preview:
| Gets or sets the icon to show in the column menu |
IconPositionStart | bool | True | Gets or sets whether the icon is positioned at the start (true) or at the end (false) of the menu item |
ResetAriaLabel | string? | Reset column widths | Gets or sets the aria label for the reset button in the resize UI |
ResizeMenu | string | Resize | Gets or sets the text shown in the column menu |
ShrinkAriaLabel | string? | Shrink column width | Gets or sets the aria label for the shrink button in the discrete resize UI |
SubmitAriaLabel | string? | Set column widths | Gets or sets the aria label for the submit button in the resize UI |
Methods
Name | Parameters | Type | Description |
---|---|---|---|
<Clone>$ | ColumnResizeLabels |
The FluentDataGridRow
and FluentDataGridCell
API's are usually not used directly
FluentDataGridRow<TGridItem> Class
Parameters
Name | Type | Default | Description |
---|---|---|---|
ChildContent | RenderFragment? | Gets or sets the content to be rendered inside the component. | |
Columns | IReadOnlyList<ColumnBase<TGridItem>> | Gets the columns associated with this data grid row. | |
GridTemplateColumns | string? | Gets or sets the string that gets applied to the css gridTemplateColumns attribute for the row. | |
Item | TGridItem? | Gets or sets the reference to the item that holds this row's values. | |
RowIndex | int? | Gets or sets the index of this row. When FluentDataGrid is virtualized, this value is not used. | |
RowType | DataGridRowType? | Default | Gets or sets the type of row. See DataGridRowType . |
VerticalAlignment | VerticalAlignment | Center |
EventCallbacks
Name | Type | Description |
---|---|---|
OnCellFocus | EventCallback<FluentDataGridCell<TGridItem>> |
FluentDataGridCell<TGridItem> Class
Parameters
Name | Type | Default | Description |
---|---|---|---|
CellType | DataGridCellType | Default | Gets or sets the cell type. See DataGridCellType . |
ChildContent | RenderFragment? | Gets or sets the content to be rendered inside the component. | |
Column | ColumnBase<TGridItem> | Gets a reference to the column that this cell belongs to. | |
GridColumn | int | 0 | Gets or sets the column index of the cell. This will be applied to the css grid-column-index value applied to the cell. |
Item | TGridItem? | Gets or sets the reference to the item that holds this cell's values. |
FluentPaginator Class
Parameters
Name | Type | Default | Description |
---|---|---|---|
Disabled | bool | False | Disables the pagination buttons |
PaginationTextTemplate | RenderFragment? | Optionally supplies a template for rendering the pagination summary. The following values can be included: {your State parameter name}.CurrentPageIndex (zero-based, so +1 for the current page number) {your State parameter name}.LastPageIndex (zero-based, so +1 for the total number of pages) | |
State | PaginationState | Gets or sets the associated PaginationState . This parameter is required. | |
SummaryTemplate | RenderFragment? | Optionally supplies a template for rendering the page count summary. The following values can be included: {your State parameter name}.TotalItemCount (for the total number of items) |
EventCallbacks
Name | Type | Description |
---|---|---|
CurrentPageIndexChanged | EventCallback<int> |
PaginationState Class
Properties
Name | Type | Default | Description |
---|---|---|---|
CurrentPageIndex | int | 0 | Gets the current zero-based page index. To set it, call PaginationState.SetCurrentPageIndexAsync(System.Int32) . |
ItemsPerPage | int | 10 | Gets or sets the number of items on each page. To set it and update any associated FluentDataGrid , call PaginationState.SetItemsPerPageAsync(System.Int32) |
LastPageIndex | int? | Gets the zero-based index of the last page, if known. The value will be null until PaginationState.TotalItemCount is known. | |
TotalItemCount | int? | Gets the total number of items across all pages, if known. The value will be null until an associated FluentDataGrid assigns a value after loading data. |
Methods
Name | Parameters | Type | Description |
---|---|---|---|
SetCurrentPageIndexAsync | int pageIndex | Task | Sets the current page index, and notifies any associated FluentDataGrid to fetch and render updated data. |
SetItemsPerPageAsync | int itemsPerPage | Task | Sets the items per page and notifies any associated FluentDataGrid to fetch and render updated data. |
SetTotalItemCountAsync | int totalItemCount bool force | Task | Sets the total number of items nd makes sure the current page index stays valid. |
Refreshing data programmatically
Sometimes you might know that the data source's contents will have changed. For example, the user may have saved some changes that will affect the data, or they might have changed the current query parameters. In any such case, you can call the grid's RefreshDataAsync
method:
<FluentDataGrid ... @ref="myGrid">
...
</FluentDataGrid>
@code {
FluentDataGrid<MyDataType> myGrid;
async Task HandleSomeEvent()
{
...
// We can force the grid to reload the current data
await myGrid.RefreshDataAsync();
}
}