Datagrid after selection event

Hi, currently the RowSelect/Deselect events fire before the selection actually happens it seems. This makes it harder to do something with the SelectedItems collection on select because the collection has not yet been updated.. It would be nice to have an event that fires after the selection. Or am I missing something? Thanks!

You can use @bind-Value instead similar to this demo:

Yes, I use @bind-Value but when RowSelect/Deselect fire the list of selected items (the @bind-Value) has not yet been updated. I have a scenario where I have a grid and another component that shows some summary of all selected items. So on selection change I want to recompute the summary but inside the RowSelect/Deselect handlers the list of all the selected items has not yet been updated. So I have to have special logic to handle the newly selected/deseected item when computing the summary of all selected items on selection change. It would be nice to have a post select event not just pre select. Or is there a better way? Thanks!

I think you can make your code depend on the selected value and not handle the RowSelect event at all. Blazor will update the UI whenever the selected value changes.

OK, yes, I understand what you mean. I can probably move my logic from a method to a property getter and then bind my component to the getter. Then when selection changes I will need to fire StateHasChanged() on my component, how do I do that? Again I have to use RowSelect/Deselect? Because selection only updates the grid and not the rest of the UI, correct?

We don't know what your component is.

You probably don't.

So far you asked if there is an event that fires after the Value property is updated. There isn't and we probably won't make one. There are many other ways to implement what you are after - for example:

  1. Just use the value property. You don't have to do anything else.
  2. Use the event argument of RowSelect - it is the newly added item to the selection.
  3. Make a property with get and set. Handle the set as you wish.
1 Like

Thanks, I now implemented it as a getter that uses SelectedItems and bound my component to the getter. And I use the setter to fire StateHasChanged on the page which updates my component bound to the getter. It's much cleaner now. Thanks!