Limit max number of selected items in SfGrid
Hello, I'm using SfGrid in blazor with checkbox multiselection. I need to limit the max number of checked items, how can I do that? I have tried using the RowSelected method and if > max, call args.Cancel = true; but it doesn't seem to work.
public void RowSelectHandler(RowSelectEventArgs args)
{
if (SfGrid.SelectedRecords.Count > max)
{
args.Cancel = true;
}
}
Thanks
SIGN IN To post a reply.
4 Replies
1 reply marked as answer
JP
Jeevakanth Palaniappan
Syncfusion Team
December 21, 2020 12:57 PM UTC
Hi Alessandro,
Greetings from Syncfusion support.
We have validated your query and we suggest you to do the same operation in the RowSelecting event of the grid. Please refer the below documentation link for your reference.
https://blazor.syncfusion.com/documentation/datagrid/events/#rowselecting - RowSelecting event will be triggered before the selection action.
https://blazor.syncfusion.com/documentation/datagrid/events/#rowselected - RowSelected event will be triggered after performing the selection action
Regards,
Jeevakanth SP.
JP
Jeevakanth Palaniappan
Syncfusion Team
December 21, 2020 01:00 PM UTC
Hi Alessandro,
Greetings from Syncfusion support.
We have validated your query and we suggest you to do the same operation in the RowSelecting event of the grid. Please refer the below documentation link for your reference.
https://blazor.syncfusion.com/documentation/datagrid/events/#rowselecting - RowSelecting event will be triggered before the selection action.
https://blazor.syncfusion.com/documentation/datagrid/events/#rowselected - RowSelected event will be triggered after performing the selection action
Regards,
Jeevakanth SP.
AS
Alessandro Spisso
January 4, 2021 02:49 PM UTC
Hello,
Thank you for your response.
I can confirm that using the Selecting event works as expected.
I wanted to also prevent the header checkbox from selecting all items, but I can't find a way. I tried the code below and it works only once because IsHeaderCheckboxClicked remains true forever after the first time.
if (args.IsHeaderCheckboxClicked)
{
args.Cancel = true;
return;
}
Thank you,
Alessandro
JP
Jeevakanth Palaniappan
Syncfusion Team
January 5, 2021 01:25 PM UTC
Hi Alessandro,
We have validated your query and we suggest you to use the below styles to prevent the header checkbox from selecting the grid records.
|
<style>
.e-headercelldiv.e-headerchkcelldiv .e-checkbox-wrapper.e-css {
pointer-events: none;
}
</style> |
Please get back to us if you have any other queries.
Regards,
Jeevakanth SP.
Marked as answer
SIGN IN To post a reply.
- 4 Replies
- 2 Participants
- Marked answer
-
AS Alessandro Spisso
- Dec 18, 2020 10:41 AM UTC
- Jan 5, 2021 01:25 PM UTC