Author Topic: Batching updates using updateRow with a GroupModel  (Read 2309 times)

mcburley

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 5
    • View Profile
Batching updates using updateRow with a GroupModel
« on: March 14, 2017, 05:11:23 am »
I have a toolbar option to batch update all or filtered rows. In addition I'm using a grouping model. When I trigger the update I loop through the datamodel.data and apply the column change using updateRow(). Works fine without grouping for any number of rows.

With grouping (just one level) on it will update the rows 1 - x less the count of grouped rows. So if I have 200 rows with 20 group row headers only 180 rows gets updates. I'm sure I'm missing something simple, but I've tried everything I can think of.

Thanks in advance.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Batching updates using updateRow with a GroupModel
« Reply #1 on: March 14, 2017, 10:34:50 am »
Please take grid.pageData() instead of dataModel.data

mcburley

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Batching updates using updateRow with a GroupModel
« Reply #2 on: March 15, 2017, 04:36:46 am »
If I understand pageData() correctly, it will only update the rows on the current page? Often there will be many rows that will span multiple pages.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Batching updates using updateRow with a GroupModel
« Reply #3 on: March 15, 2017, 11:10:28 am »
You are right, pageData() updates the rows on current page only in case paging is used.

dataModel.data points to original data without grouping. Grouping changes the row indices of the rows.

So turn off the grouping before updating the rows and turn it on just after you are done with updates.

Code: [Select]
{
type: 'button',
label: 'update rows',
listener: function(){
this.groupOption({on: false});

var list = this.option('dataModel.data').map(function(rd, i){
return {rowIndx: i, newRow: { 'ShipCountry': 'India' }};
});
this.updateRow({
refresh: false,
rowList: list
});
this.groupOption({on: true});
}
}