We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Batch Edit

Hi,

EditMode.Batch.

Is it possible to save changes to each row in the grid after moving to the next one, instead of saving the entire batch? 

1 Reply

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team April 3, 2017 11:57 AM UTC

Hi Avi Segal, 


Thanks for contacting syncfusion support. 


We have achieved your requirement “save changes to each row in the grid instead of saving the entire batch” using “CellSave” event of the grid. In the cellSave event, we can get the batch changes by using “getBatchChanges” method and finally save the records in the “batchSave” method instead of saving the entire batch. CellSave event will be triggered at each cell save. If you have called the batchSave method within this event, it will update the Grid DataSource instantly. 


Please refer the API reference link:- 








Please refer to the code example:- 

    
@(Html.EJ().Grid<object>("FlatGrid") 
     .Datasource((IEnumerable<object>)ViewBag.datasource) 
     .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Batch); }) 
     .ToolbarSettings(toolbar =>{ 
                        toolbar.ShowToolbar().ToolbarItems(items => 
                        { 
                            items.AddTool(ToolBarItems.Add); 
                            items.AddTool(ToolBarItems.Edit); 
                            items.AddTool(ToolBarItems.Delete); 
                            items.AddTool(ToolBarItems.Update); 
                            items.AddTool(ToolBarItems.Cancel); 
              }); 
           }) 
   .AllowPaging() 
   .ClientSideEvents(eve => { eve.CellSave("cellsave"); }) 
   .Columns(col => 
   { 
       col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Add(); 
       col.Field("CustomerID").HeaderText("Customer ID").Add(); 
        .  .  . 
  }) 
 
) 
   
<script type="text/javascript"> 
    var flag = true; 
    function cellsave(args) { 
        if (flag) { 
            args.cancel = true; 
            if ($.inArray(args.rowData, this.batchChanges.changed) == -1 && $.inArray(args.rowData, this.batchChanges.added) == -1) 
               this.batchChanges.changed.push(args.rowData); 
            var batchData = this.getBatchChanges(); 
            var batchDetails = this._bulkEditCellDetails; 
            if (batchData.added.length > 0 || batchData.changed.length > 0 || batchData.deleted.length > 0) { 
                flag = false; 
                this.batchSave(); 
                this._bulkEditCellDetails = batchDetails;//reassigning the values  
            } 
        } 
        else 
            flag = true; 
    }; 
 
</script>  




Regards, 

Farveensulthana T 


Loader.
Up arrow icon