There doesn't seem to be a way to deselect the selected row either by clicking on a selected row again or by two-way-binding and setting it to an empty list.
This would be pretty handy as currently the only way that makes sense for me is to make no use of selection mode at all.
Hello Lutz,
You can use the OnRowClick event to achieve the desired behavior.
In order to achieve the desired behavior, you should handle both the selection and deselection of the items in the OnRowClick event handler. One important thing that should be done is the cancellation of the SelectedItemsChanged event. This is required because the SelectedItemsChanged event would fire after the OnRowClick.
As an attached file you can see a demo application that showcases such an implementation.
That being said, I am marking this thread as "Completed" because such behavior can already be achieved using the existing events.
Regards,
Svetoslav Dimitrov
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.
Hello Lutz,
I checked in more detail and confirm that it is not possible to trigger deselection specifically in the row click event.
If Ctrl + Click will not be intuitive for your users, please consider adding a checkbox column, which will produce the desired ability to unselect a selected row in a straightforward way.
In the meantime, we will review this use case in the product team.
Regards,
Dimo
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.
Hi Dimo,
yes - I tried that, but it does not seem to work (the former selected row stays red - might be an issue on doing it in the rowClick event as it might overwrite the selected items later):
<TelerikGrid Data="@customers"
Pageable="true" Sortable="true" Groupable="true"
FilterMode="Telerik.Blazor.GridFilterMode.FilterRow"
Resizable="true" Reorderable="true" PageSize="20" SelectionMode="GridSelectionMode.Single" OnRowClick="RowClick" @bind-SelectedItems="SelectedItems">
<GridColumns>
<GridColumn Field="@(nameof(Customer.id))" Width="120px" Title="id" />
<GridColumn Field="@(nameof(Customer.Name))" Title="Name" Groupable="false" />
<GridColumn Field="@(nameof(Customer.City))" Title="City" />
<GridColumn Field="@(nameof(Customer.Country))" Title="Country" />
</GridColumns>
</TelerikGrid>
@code {
private int selectedCustomerId = 0;
public IEnumerable<Customer> SelectedItems { get; set; } = Enumerable.Empty<Customer>();
private Customer CustomerDetails;
private async Task RowClick(GridRowClickEventArgs args)}
Hi Lutz,
The Grid allows users to deselect rows in two ways:
If the user should be able to deselect a row via a simple click, this may create inconsistency with other well-known interfaces (such as Windows Explorer or Excel), which don't behave that way. Also, deselecting multiple rows with a single click on any row will become impossible.
On the other hand, programmatic selection and deselection is demonstrated in the online demo:
https://demos.telerik.com/blazor-ui/grid/selection
If you want to deselect all rows, you can assign an empty List, e.g.:
SelectedItems = new List<Customer>();
Have you tried this approach? Let me know if you have any comments on all of the above.
Regards,
Dimo
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.