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, and SelectAll attributes.
This method offers more flexibility but requires additional configuration, making it particularly useful when using 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)
}
Example
SingleSingleStickyMultiple Use `SelectedItems` property Use `SelectFromEntireRow` property Use `Selectable` property
Using SelectedItems
ID
Name
BirthDate
10895Jean Martin1985-03-16
10944António Langa1991-12-01
11203Julie Smith1958-10-10
11205Nur Sari1922-04-27
11898Jose Hernandez2011-05-03
12130Kenji Sato2004-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>
    

An error has occurred. This application may no longer respond until reloaded. Reload 🗙