Author Topic: Bug in grouping dates  (Read 2512 times)

TeeJT

  • Pro Ultimate
  • Jr. Member
  • *
  • Posts: 88
    • View Profile
Bug in grouping dates
« on: July 18, 2017, 03:03:22 pm »
I used your standard demo for grouped rows for Pro version at https://paramquery.com/pro/demos/group_rows

I just removed all groupings and added "Shipping Date" as only group.

The result is that the shipping dates are not sorted. Do I need to sort the grouped column?
I expected my empty or null date to be on top.




paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Bug in grouping dates
« Reply #1 on: July 18, 2017, 09:23:23 pm »
Grouping and sorting are made independent of each other since v3.4.0, so yes you have to sort the column to get it sorted.

TeeJT

  • Pro Ultimate
  • Jr. Member
  • *
  • Posts: 88
    • View Profile
Re: Bug in grouping dates
« Reply #2 on: July 18, 2017, 10:09:07 pm »
If I want the previous behavior, I would need to remove this sort if found and introduce it at the head.
Similarly for the second grouping, I would need to remove this sort if found and introduce it as the second sort. etc.

TeeJT

  • Pro Ultimate
  • Jr. Member
  • *
  • Posts: 88
    • View Profile
Re: Bug in grouping dates
« Reply #3 on: July 19, 2017, 07:17:50 am »
I tried to add this code at refreshHeader event but it does not sort correctly.

Code: [Select]
// Get Group Model
var gModel = $(gridDiv).pqGrid( "option", "groupModel");
// Get Sort List
var sortModel = $(gridDiv).pqGrid( "option", "sortModel");
var sortList = sortModel.sorter;
var groupList = gModel.dataIndx;
// add the grouped columns to the front of sort list
for (var i=groupList.length-1; i>=0; i--) {
var grpIdx = groupList[i];
// remove grpIdx from sortList
sortList = $.grep(sortList, function (el) { return el.dataIndx!= grpIdx; });
// add grpIdx to front of sortList
sortList.splice(0,0,{dataIndx:grpIdx, dir: "up"})
}
// Apply new sortList
sortModel.sorter = sortList;
$(gridDiv).pqGrid( "option", "sortModel", sortModel );

« Last Edit: July 19, 2017, 08:10:48 am by TeeJT »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Bug in grouping dates
« Reply #4 on: July 19, 2017, 11:23:22 am »
groupChange and complete events can be used to sort the groupby columns whenever there is change in grouping.

Code: [Select]
groupChange: function(){
var GM = this.option("groupModel"), sorter = [];
GM.dataIndx.forEach(function(di){
sorter.push({dataIndx: di, dir: 'up' });
});
this.sort( {sorter: sorter});
},
complete: function(){
this.option('groupChange').call(this);
},