Question:
Is it possible to not allow select for specific row in DataGrid?
Scenario:
In the DataGrid, I enable row selection with AllowRowSelectOnRowClick=true
. In each Item
row, it has a property IsAvailable
and it determines whether the row can be ticked/selected (refer to Code section OnSelectRow
).
While I have another set of List, OriSelectData
with store the Item
with IsAvailable=false
. With this OriSelectData
list, I can hide the checkbox so it is not allowed to be selected.
Problem:
It seems even with this OnSelectRow
method, the row (with IsAvailable=false
) is still able to be selected. And I checked the SelectedData
, the row was added after RowClick
or RowSelect
event.
I am not able to block the IsAvailable=false
item to be selected.
Expected result:
When user click the row (IsAvailable=false
a.k.a no checkbox), the row should not be selected, highlighted.
Actual result:
The row (IsAvailable=false
a.k.a no checkbox), the row was selected, highlighted.
Code:
DataGrid
<RadzenDataGrid @ref="grid" AllowRowSelectOnRowClick="@allowRowSelectOnRowClick" AllowFiltering="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
AllowSorting="true" Data="@Data" TItem="Item" ColumnWidth="200px"
SelectionMode="@SelectionMode"
@bind-Value=@SelectedData
RowSelect="@(args => OnSelectRow(args))" RowClick="@(args => OnSelectRow(args.Data))">
<Columns>
<RadzenDataGridColumn TItem="Item" Width="40px" Sortable="false" Filterable="false">
<HeaderTemplate>
<RadzenCheckBox TriState="false" TValue="bool" Value="@(Data.Any(i => SelectedData != null && SelectedData.Contains(i)))"
Change="@(args => SelectedData = args ? Data.ToList() : null)" />
</HeaderTemplate>
<Template Context="data">
<RadzenCheckBox TriState="false" Value="@(SelectedData != null && SelectedData.Contains(data))"
TValue="bool" Change=@(args => OnSelectRow(data))
Disabled="@(OriSelectedData != null && OriSelectedData.Contains(data.DisplayName))"
Visible="@(!(OriSelectedData!= null && OriSelectedData.Contains(data.DisplayName)))"/>
</Template>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="Data" Property="Name" Title="Name" />
</Columns>
</RadzenDataGrid>
public void OnSelectRow(Item item)
{
// Allow row to be select
if (!allowRowSelectOnRowClick && item.IsAvailable)
{
grid.SelectRow(data);
return;
}
// Remove row from select (This part fail)
//var selected = SelectedData?.First(x => x.DisplayName == item.DisplayName);
//SelectedData?.Remove(selected);
}
Model
public record Item(string DisplayName, bool IsAvailable);
Thanks in advance for the assist.