Deselecting a row in a grid from code
I would like to deselect one row from the code. I only found oportunity to clear all selection with this:
await Grid10.ClearRowSelectionAsync();
But my problem with it that it clears all selection which I would not want. Just a one with a specific index.
Is there any way it can be done?
Thanks for your help!
Hi Nandor Kalmanchey,
We would like to inform you that the ClearRowSelectionAsync method can be used
to clear all selected rows in the DataGrid. If you want to clear the selection
of only a specific record, we suggest using the GetSelectedRowIndexesAsync()
method to retrieve the selected row indexes. You can then use the
ClearRowSelectionAsync method to clear the selection. From the list of selected
row indexes, you can remove the specific index of the row you want to deselect.
Afterward, you can reselect rows programmatically using the SelectRowsAsync
method to achieve the desired outcome. Please refer to the code snippet and
sample below for more details.
|
<span>@Message</span>
<Syncfusion.Blazor.Buttons.SfButton OnClick="@(async () => await ClearRowSelection(1))"> </Syncfusion.Blazor.Buttons.SfButton> <SfGrid DataSource="@Orders" @ref="Grid" AllowSelection="true" AllowPaging="true"> <GridSelectionSettings Type="Syncfusion.Blazor.Grids.SelectionType.Multiple"></GridSelectionSettings> --------------- </SfGrid> @code {
public string Message { get; set; } SfGrid<Order> Grid { get; set; }
public async Task ClearRowSelection(int index) { List<int> selectedIndexes = await Grid.GetSelectedRowIndexesAsync();
if (selectedIndexes != null && selectedIndexes.Contains(index)) { Message = ""; // Use LINQ to remove the specific index int[] selectedarray = selectedIndexes.Where(i => i != index).ToArray();
await Grid.ClearSelectionAsync();
await Grid.SelectRowsAsync(selectedarray);
} else { Message = $"The given row index {index} is not currently selected."; } }
} |
Reference:
https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_ClearRowSelectionAsync
https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_GetSelectedRowIndexesAsync
Regards,
Prathap Senthil
- 1 Reply
- 2 Participants
-
NK Nandor Kalmanchey
- Aug 15, 2024 08:36 AM UTC
- Aug 16, 2024 10:18 AM UTC