Save grid cell value immediately after each edit without update or confirmation

I'm trying to create a grid control that allows editing of each cell (like batch mode), but that saves changes after each edit and does not require the update button or the confirmation dialog. 

Seems other versions have a batchSave() method on the grid instance, which I think would work.  This is what I have for an example:

<SfGrid @ref="@GridInstance" DataSource="@People" >
   <GridEditSettings AllowEditing="true" Mode="EditMode.Batch"></GridEditSettings>
   <GridEvents OnCellSave="CellSaveHandler" TValue="Person"></GridEvents>
   <GridColumns>
      <GridColumn IsPrimaryKey="true" Field=@nameof(Person.Name) HeaderText="Name"></GridColumn>
      <GridColumn Field=@nameof(Person.Age) HeaderText="Age"></GridColumn>
   </GridColumns>
</SfGrid>

@code{

    SfGrid<Person> GridInstance { get; set; }

    public Person[] People { get; set; } = new Person[] {
        new Person(){ Name="Bob", Age=20 },
        new Person(){ Name="Jill",Age=21}
    };

    public void CellSaveHandler(CellSaveArgs<Person> args)
    {
        // Save batch here?
    }

    public class Person
    {
        public string Name { get; set; }
        public int Age { get; set; }
    }


7 Replies 1 reply marked as answer

RS Renjith Singh Rajendran Syncfusion Team July 27, 2020 03:30 PM UTC

Hi Ralph, 

Greetings from Syncfusion support. 

We suggest you to use the EndEdit method of grid in CellSaved event handler. And also ensure to set the ShowConfirmDialog to false to prevent showing of confirmation dialog during save. Please use as like the below code, 

 
<SfGrid @ref="@GridInstance" DataSource="@People"> 
    <GridEditSettings AllowEditing="true" Mode="EditMode.Batch" ShowConfirmDialog="false"></GridEditSettings>
    <GridEvents CellSaved="CellSaveHandler" TValue="Person"></GridEvents> 
    ... 
</SfGrid> 
 
@code{ 
    SfGrid<Person> GridInstance { getset; } 
    ... 
    public void CellSaveHandler(CellSaveArgs<Person> args) 
    { 
        // Save batch here? 
        GridInstance.EndEdit(); 
    } 
    ... 
} 


We have also prepared a sample based on this scenario. Please download the sample from the link below, 
 
Documentations : 
 
Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 


Marked as answer

RW Ralph Wieland July 27, 2020 04:13 PM UTC

Excellent! That is exactly what I was looking for. Thanks for the quick response and the very complete example and references. Syncfusion Rocks!


RS Renjith Singh Rajendran Syncfusion Team July 28, 2020 12:14 PM UTC

Hi Ralph, 

Thanks for your update. 

We are glad to hear that your requirement has been achieved. Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 



DA Dave replied to Renjith Singh Rajendran January 11, 2023 12:15 AM UTC

Hello, is there a way to solve this same problem in Dialog edit mode? Thank you.



VN Vignesh Natarajan Syncfusion Team January 11, 2023 04:22 AM UTC

Hi Dave,


Greetings from Syncfusion support.


Query: “is there a way to solve this same problem in Dialog edit mode? Thank you.


We want to clarify that solution provided in this update is for Batch editing where changes of a particular cell are saved in batch mode and get updated in Grid upon the Update button click. But dialog editing is row-based editing where the entire row is considered and changes get saved in a grid upon clicking the Update or Save button of the Grid edit dialog.


As we are unaware of the issue you are facing, we need some more details about your requirement or problem you are facing. So kindly share more information on this to proceed further.


Regards,

Vignesh Natarajan



DA Dave January 11, 2023 08:25 PM UTC

Vignesh, thank you for your reply. I'd like the functionality the original poster was asking for (saving a change to a cell automatically--i.e., after losing focus with tab, enter, etc. No save button.). However, I'd like to have that functionality in a dialog rather than in the grid. Is this possible?



MS Monisha Saravanan Syncfusion Team January 12, 2023 12:51 PM UTC

Hi Dave,


Before proceeding further with your requirement we need some more clarification. Kindly share us the below details to proceed further.


  1. Share us how you are expecting to close the Dialog. Whether using a customized button or in other way?
  2. Share us some more details about your expectation.


Also we would like to inform that we have support to prevent the data cloning using PreventDataClone property inside OnActionBegin event. It will save the edited data directly to the DataSource and we suggest you to call grid refresh method at the time of closing the SfDialog and it will refresh the records in the DataGrid.


But when using PreventDataClone the edited values will be stored directly to the DataSource and we don’t have possibilities to retrieve the previous value.


 

<SfGrid DataSource="@Orders" @ref="Grid" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })" Height="315">

    <GridEvents OnActionBegin="OnActionBegin" TValue="Order"></GridEvents>

    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Dialog">

        

        <FooterTemplate>

           

            <SfButton OnClick="@Cancel">Cancel</SfButton>

        </FooterTemplate>

    </GridEditSettings>

    <GridColumns>

        ...

   </GridColumns>

</SfGrid>

 

@code {

    public List<Order> Orders { get; set; }

    public SfGrid<Order> Grid;

    public void Cancel()

    {

        Grid.Refresh();

 

    }

    public void OnActionBegin(ActionEventArgs<Order> args)

    {

        if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.BeforeBeginEdit))

        {

            args.PreventDataClone = true;

        }

    }

 

}


Reference :

https://blazor.syncfusion.com/documentation/datagrid/events#onactionbegin


Please check this suggestion from your side and get back to us if you need further assistance.


Regards,

Monisha


Loader.
Up arrow icon