RadzenGrid - datagrid revert changes on 'cancel' btn

Hello,

Firstly a shout out to Radzen and the team, the Blazor components really are excellent!!

Following your example (for the DataGrid) and having some difficulty with Cancel button. The event gets properly dispatched to my handler 'CancelEdit(MyObj mObj)' however having difficulty getting the data to correctly revert for the selected row!

Note: not using scaffolding (Radzen-UI); rather a basic Server-Side RadzenGrid that follows the DataGrid example. The only difference - using a REST API rather than Northwind.

Behavior observed:

  • when clicking on 'pencil' to update a row, the editable fields permit me to make a change.
    • back-end correctly updated (REST API) with changes when I click Save
    • if I try 'backing out' of the change (clicking Cancel) -> the updated data is not reverted.
      • I have to move to another screen (and come back) which presumably re-renders the list/grid.

I have tried saving (restoring) the entity under edit/change at EditRow() inception, and restoring it - on cancel, but that seems not to work either.

I am certain I am doing something incorrectly, hopefully the Radzen guru's can help guide me in the right direction!

Environment: Visual C#, using Radzen.Blazor v2.11.3

Thanks,
Brian.

Hi Brian,

EF Core can track, save and revert changes - the grid itself cannot. Here is the relevant code from our example:

    void CancelEdit(Order order)
    {
        ordersGrid.CancelEditRow(order);

        // For production
        var orderEntry = dbContext.Entry(order);
        orderEntry.CurrentValues.SetValues(orderEntry.OriginalValues);
        orderEntry.State = EntityState.Unchanged;
    }

Since you are using plain REST service you will need to get original values by yourself - for example you can save the original values in a variable before editing and restore them on cancel.

Thank you Vladimir!

I was saving my original values (prior to my posting) but alas was incorrectly restoring the values. I was incorrectly assigning my edited object to refer-to object holding orig/saved values. I then focused on restoring values vs. assigning object references and all working correctly!

BR/Brian.