SfGrid in Edit mode - not getting updated data on saving

Hi, 


I'm using a Sfgrid in edit mode, my idea is to use the command column to edit the values of a specific row. Once I click on the Command Column Edit button, I manage to update the values of the row, but when I click on save and the OnCommandClicked event is triggered, I don't get the updated values in the args.RowData, but the original values of the datasource.


Please find the code attached for reference (SfGrid and OnCommandClicked method).

Is there something I am missing to have the values binded?


Thanks.


Attachment: SfGrid_ea732fe0.zip

3 Replies

RN Rahul Narayanasamy Syncfusion Team October 1, 2021 12:28 PM UTC

Hi Mario, 

Greetings from Syncfusion. 

Query: SfGrid in Edit mode - not getting updated data on saving 

We have validated your query and you want to get the updated data while saving the data using command button. We suggest you to get the updated data using OnActionBegin event with RequestType as Save. Find the below code snippets for your reference. 

 
<SfGrid DataSource="@Orders" AllowPaging="true" Height="315"> 
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings> 
    <GridEvents OnActionBegin="ActionBeginHandler" CommandClicked="OnCommandClicked" TValue="Order"></GridEvents> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
        . . . 
        <GridColumn HeaderText="Manage Records" Width="150"> 
            <GridCommandColumns> 
                <GridCommandColumn Type="CommandButtonType.Edit" ButtonOption="@(new CommandButtonOptions() { IconCss = "e-icons e-edit", CssClass = "e-flat" })"></GridCommandColumn> 
                <GridCommandColumn Type="CommandButtonType.Delete" ButtonOption="@(new CommandButtonOptions() { IconCss = "e-icons e-delete", CssClass = "e-flat" })"></GridCommandColumn> 
                <GridCommandColumn Type="CommandButtonType.Save" ButtonOption="@(new CommandButtonOptions() { IconCss = "e-icons e-update", CssClass = "e-flat" })"></GridCommandColumn> 
                <GridCommandColumn Type="CommandButtonType.Cancel" ButtonOption="@(new CommandButtonOptions() { IconCss = "e-icons e-cancel-icon", CssClass = "e-flat" })"></GridCommandColumn> 
            </GridCommandColumns> 
         </GridColumn> 
    </GridColumns> 
</SfGrid> 
 
@code{ 
    public List<Order> Orders { get; set; } 
 
    . ..  
    public void OnCommandClicked(CommandClickEventArgs<Order> args) 
    { 
        // Perform required operations here 
    } 
    public void ActionBeginHandler(ActionEventArgs<Order> args) 
    { 
        if(args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Save)) 
        { 
            var editedData = args.Data;     //you can get the updated data using args.Data 
        } 
        // Here you can customize your code 
    } 
} 


Please let us know if you have any concerns. 

Regards, 
Rahul 



MS Mario Sanchez Mecho October 4, 2021 05:55 AM UTC

Hi Rahul,


thanks for your answer, it is working now.


Thanks,

M






RN Rahul Narayanasamy Syncfusion Team October 5, 2021 05:02 AM UTC

Hi Mario, 
 
Thanks for the update. 
 
We are glad to hear that the provided solution was helpful to achieve your requirement. Please get back to us if you need further assistance. 
 
Regards, 
Rahul 


Loader.
Up arrow icon