I'm using the Blazor TelerikGrid component with SelectionMode="GridSelectionMode.Multiple".
I have an OnRowClick handler to manually toggle selection (see below), and I bind the selected items via SelectedItems="@SearchState.SelectedItems".
<TelerikGrid @ref="SearchGrid"
TItem="@ChargeUIResult"
SelectionMode="GridSelectionMode.Multiple"
SelectedItems="@SearchState.SelectedItems"
SelectedItemsChanged="@((IEnumerable<ChargeUIResult> args) => SetSelectedItem(args))"
OnRowClick="@OnRowClickHandler"
...>
</TelerikGrid>
void OnRowClickHandler(GridRowClickEventArgs args)
{
var currItem = args.Item as ChargeUIResult;
if (SearchState.SelectedItems.Any(x => x.Id == currItem?.Id))
{
SearchState.SelectedItems = SearchState.SelectedItems.Where(x => x.Id != currItem?.Id);
}
else
{
SearchState.SelectedItems = SearchState.SelectedItems.Concat(new[] { currItem });
}
SelectedItem = currItem;
ShouldRenderSelectedItem = true;
args.ShouldRender = false;
}
What I want to achieve is:
When a checkbox is clicked (i.e., selection happens),
I want to get the first selected item from SearchState.SelectedItems and bind or use it immediately (e.g., assign it to SelectedItem or update the UI).
đź’¬ My questions are:
Is there a built-in event for detecting checkbox selection (apart from OnRowClick)?
What's the recommended way to access the first selected item when selection changes via the checkbox — not just row clicks?
Can SelectedItemsChanged help with this, and if so, how should I modify the SetSelectedItem logic?