Remove row after successful delete on view bound datagrid


#1

Hi,
I've created page with a DataGrid set to get data from a view and I've enabled deleting of rows on the grid. When an item gets successfully deleted, the row stays in the datagrid instead of being removed.

This works fine when the DataGrid is bound directly to the table. Just for test purposes, I've created the view to have the same schema as the table because if I get the same data directly from a table, deleting works as expected.

For now, I've made a workaround to retrieved the data again after a successful delete by invoking the datasource again, but that takes an extra request that may be unnecessary. Am I missing something?

Thanks.


#2

Indeed Radzen handles this automatically when a DataGrid is bound to a data source method which returns a table e.g. getXXX where XXX is the name of the table e.g. for GET /odata/Northwind/Products the key is Products. This works behind the scenes by using an internal cache - the cache key is that XXX (table name). I suspect your method uses a different key hence the automatic item deletion doesn't work.

Getting the items is a viable workaround. To avoid the extra request you can try removing the data item from the page property to which your data-grid is bound. After invoking the deleteXXX data source method add a new action with Type: Set property and Value: ${yourProperty.filter(item => item.Id != event.Id)} where yourProperty is the page property which the DataGrid's Data is set to and Id is the primary key of the table.


#3

Thanks for a quick reply. This works great!
I just changed:

to:
${yourProperty.filter(item => item.Id !== event.Id)}


#4

:frowning: of course, you are right. It should have been != - I will update my original response to avoid confusing anybody else.


Data Grid does not update when data change