View Full Version : [FIXED] mzPivotGrid sort order bug?

22 Apr 2015, 11:50 AM

Take a look at this fiddle: https://fiddle.sencha.com/#fiddle/lo2

Click to expand 2014. The months are sorted descending even though I changed the sort order to be ascending.

There is one more thing. In Chrome, if you expand 2014-03, 2014-02-28 shows up as the first column which is a weird because under 2014-03 there should be only March dates. And just to make it weirder, in FF and IE 11 2014-03-01 is the first column which is what I expected.

Am I doing something wrong or is it a bug?


Update: I fixed the second issue by using dateFormat: 'c' for the date column:

{ name: 'Date', type: 'date', dateFormat: 'c' },
I also updated the fiddle, so it's not an issue anymore.

Gary Schlosberg
22 Apr 2015, 2:07 PM
Thanks for the report! I have opened a bug in our bug tracker.

22 Apr 2015, 2:20 PM
Is there a workaround for the sort order, if I want to break down the totals by month?


24 Apr 2015, 12:56 AM
Since you already have the date on the model, you could define the fields year and month as convert functions to extract their proper values from date. For month dimension on the pivot grid you could apply a renderer if you need them as Jan, Feb etc.

24 Apr 2015, 9:36 AM
Thank you. I wanted to calculate everything on the server to avoid calculations in the JavaScript. If we purchase the product and you fix this bug, will we be able to get a patch? We are still using Ext Js 4.2. Thanks PS. Mersi f. mult pt. raspunsuri ;-)

27 Apr 2015, 5:14 AM
This override should fix the sorting issue:

Ext.define('overrides.aggregate.matrix.Abstract', {
override: 'Mz.aggregate.matrix.Abstract',

naturalSort: function (s1, s2) {
var rs = /(\d+)|(-\d+)|(\D+)/g,
v1 = s1,
v2 = s2,
i = 0,
a1, a2;

if(s1 instanceof Date && s2 instanceof Date){
v1 = s1.getTime();
v2 = s2.getTime();

v1 = String(v1 || '').match(rs);
v2 = String(v2 || '').match(rs);

if(!v1) { return -1; }
if(!v2) { return 1; }

while(v1.length && v2.length){
a1 = v1.shift();
a2 = v2.shift();
// check if we have to compare numbers
if(Ext.isNumeric(a1) || Ext.isNumeric(a2)){
if(!Ext.isNumeric(a1)) { return 1; }
if(!Ext.isNumeric(a2)) { return -1; }
// negative numbers are relevant only when found at the beginning
if(a1 != a2) { return i === 0 ? a1 - a2 : Math.abs(a1) - Math.abs(a2); }
}else if(a1 != a2) { return a1 > a2 ? 1 : -1; }
return v1.length - v2.length;


Please check it out.

PS: Pentru putin. Spor la treaba! ;)