BatchUpdate - Marking all Records as 'Changed'

Hi

I want to mark all the rows in my Grid as Changed, so they are triggered in my function public ActionResult BatchUpdate(List<SubscriptionItem> changed, List<SubscriptionItem> added, List<SubscriptionItem> deleted).

The grid is with data that is pre-calculated maybe dont need changes from the end-user.

So far I have tried the following javascript in the BeforeBatchSave Event

 function beforebatchSave(args) {
        try
        {
            var obj = $("#MainGrid").ejGrid("instance");
            var rc = $("#MainGrid").ejGrid("getRows").length;
            if (rc != null) {
                for (var i = 0; i < rc; i++) {
                   obj.selectRows(i);
                    this.batchChanges.changed.push({ sSubscriptionID: obj.getSelectedRecords()[0].sSubscriptionID, SubscriptionItemID: obj.getSelectedRecords()[0].SubscriptionItemID, NewInvoiceWeek: obj.getSelectedRecords()[0].NewInvoiceWeek, NewInvoiceYear: obj.getSelectedRecords()[0].NewInvoiceYear, NewShipmentWeek: obj.getSelectedRecords()[0].NewShipmentWeek, NewShipmentYear: obj.getSelectedRecords()[0].NewShipmentYear  });
                }
            }
        }
        catch (err)
        {
            alert(err);
        }
    }

But running this javascript on large recordset(500+) is just to slow, selecting each row with selectRows(i) is just to "expensive".

Is there any other way perform this task ? Simply marking all records/row as changed.

Best Regards
Jakob




5 Replies

MP Manivannan Padmanaban Syncfusion Team May 7, 2018 12:17 PM UTC

Hi Jakob, 

Thanks for contacting syncfusion support. We are happy to assist you. 

We have analyzed your query and we are able to understand that, you need to push all the records in the batchchanges. For your convenience we have created the sample based on your code example. We have marked the total 500 records into the batch changes and we are getting the time delay of 15 – 30 secs.  


Please confirm whether are you getting the same time delay or more than that and also please share the following details to resolve the issue as early as possible. 

  1. Share the Essential studio version.
  2. How many records are binding in the single page.
  3. Share the time delay are you facing.
  4. Share the issue reproducing sample (or) reproduce the issue in the provided sample.

Regards, 

Manivannan Padmanaban. 



JH Jakob Harper May 14, 2018 06:58 AM UTC

Thank you for the reply and project.

Maybe am misunderstanding something but I dont see the 500 records being marked as changed and posted in your sample project.

I need to make a change on a record or a new button to make the BatchSave command to trigger the  beforeBatchSave.

If I modify the Grid from

    @(Html.EJ().Grid<object>("FlatGrid")
        .Datasource((IEnumerable<object>)ViewBag.datasource)
to

    @(Html.EJ().Grid<object>("FlatGrid")
                    .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.datasource).BatchURL("BatchUpdate").Adaptor(AdaptorType.RemoteSaveAdaptor))

and monitor the Controller/BatchUpdate code, not 500 records are being posted as change only the actual number of  records changed ?

Thx.




MP Manivannan Padmanaban Syncfusion Team May 15, 2018 12:10 PM UTC

Hi Jakob,  
 
Query : the Controller/BatchUpdate code, not 500 records are being posted as change only the actual number of  records changed ? 
 
If we try to push the 500 (or ) all the records in the page to batchchanges.changed may lead to internal server error because in the batchupdate method we pass the deserialized data. So,  if the json request is too large we can’t desterilized. 
 
Instead of that you can pass the page records count to the batchupdate method using addparams method. Based on the record count you can done the batch changes . Please refer the below code example , 
 
 
  @(Html.EJ().Grid<object>("Edit") 
                .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.datasource).BatchURL("BatchUpdate").Adaptor(AdaptorType.RemoteSaveAdaptor)) 
                                    .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Batch); }) 
                                    .Columns(col => 
                                    { 
                                       ….. 
                                    }) 
                                    .ClientSideEvents(eve => 
        { 
            eve.BeforeBatchSave("beforebatchSave"); 
        }) 
    ) 
 
<script> 
 
    function beforebatchSave(args) { 
 
        var rc = this.getRows().length; 
        this.model.query.addParams("recordcount",rc);     
    } 
 
 
</script> 
 
public ActionResult BatchUpdate(List<EditableOrder> changed , List<EditableOrder> added, List<EditableOrder> deleted , int recordcount) 
        { 
           if (recordcount == 200)  
                OrderRepository.ComplexUpdate(changed); 
             
            …………….. 
           var data = OrderRepository.GetComplexRecords(); 
            return Json(data, JsonRequestBehavior.AllowGet); 
       } 
 
 
 
For your convenience we have created the sample please refer the below link, 
 
 
Regards, 

Manivannan Padmanaban. 



JH Jakob Harper May 15, 2018 01:04 PM UTC

Okay Thank you for the answer.

I have decided to change my method/flow as selectRows(i) in the javascript on my grid simply is to slow.

No need to spend mroe time on this, but Thank you.

Jakob


MP Manivannan Padmanaban Syncfusion Team May 16, 2018 04:36 AM UTC

Hi Jakob, 
 
Thanks for the update. 
 
Please get back to us, if you need further assistance. 
 
Regards, 
 
Manivannan Padmanaban. 


Loader.
Up arrow icon