anmcgrath / BlazorDatasheet

Simple excel-like datasheet Blazor component
MIT License
131 stars 31 forks source link

How could I trigger an event when a cell is changed on the ObjectEditor? #69

Closed lucasmoraiss closed 1 month ago

lucasmoraiss commented 1 month ago

First of all I want to thank y'all for this amazing project! I recently downloaded the 0.2.0 nuget package for the BlazorDatasheet and I was able to pass on data from my DB to the datasheet. Now I'm struggling to save the data back on DB, my first thought was to create a save button that does a bulk save (saving all the data that is present on the sheet in one operation), however, unfortunately, that wouldn't work, since there could be a scenario where, with a huge amount of data, only one row is changed. That's not the most optimized way to do that, so my solution is to trigger an event whenever a cell value is updated, being able to pass on the row id (User.Id) as parameter, then I'd be able to save only that entity/row. Is there any kind of OnCellChanged()-like event I can call? Or maybe any other smart alternative approach that I could use?

Here is how I set up my simple example of the ObjectEditor:

image

anmcgrath commented 1 month ago

Hi @lucasmoraiss you should be able to add an event listener via

editor.Sheet.Cells.CellsChanged += SheetOnCellsChanged;

lucasmoraiss commented 1 month ago

Brilliant, that is exactly what I was looking for!

I will also leave down here how I manage to get the row and column positions on my handler after the cell being changed:

image

From now on you could just call an API PUT method to change that property value (column) on that specific entity (row).