Multi Select
The same example, adding a SelectColumn
, to allow multi-select rows.
To utilize the SelectColumn feature in the Fluent DataGrid, there are two approaches available:
Automatic Management via SelectedItems
- Provide a list of data via the
Items
property. - Let the grid handle selected rows entirely through the
SelectedItems
property.
Manual Management via Property
and OnSelect
:
- Control how selected lines are saved manually.
- Utilize the
Property
,OnSelect
, andSelectAll
attributes.
Virtualize
or directly managing a custom IsSelected
property.
By default the Fluent Design System recommends to only use the checkbox to indicate selected rows.
It is possible to change this behavior by using a CSS style like this to set a background on selected rows:
.fluent-data-grid-row:has([row-selected]) > td {
background-color: var(--neutral-fill-stealth-hover)
}
Using SelectedItems
ID | Name | BirthDate | |
---|---|---|---|
10895 | Jean Martin | 1985-03-16 | |
10944 | António Langa | 1991-12-01 | |
11203 | Julie Smith | 1958-10-10 | |
11205 | Nur Sari | 1922-04-27 | |
11898 | Jose Hernandez | 2011-05-03 | |
12130 | Kenji Sato | 2004-01-09 |
SelectedItems:
Jean Martin
Download:
Using this SelectColumn
, you can customize the checkboxes by using ChildContent
to define the contents of the selection for each row of the grid;
or SelectAllTemplate
to customize the header of this column.
If you don't want the user to be able to interact (click and change) on the SelectAll header, you can set the SelectAllDisabled="true"
attribute.
Example:
<SelectAllTemplate>
@(context.AllSelected == true ? "✅" : context.AllSelected == null ? "➖" : "⬜")
</SelectAllTemplate>
<ChildContent>
@(SelectedItems.Contains(context) ? "✅" : " ") @* Using SelectedItems *@
@(context.Selected ? "✅" : " ") @* Using Property and OnSelect *@
</ChildContent>