PDA

View Full Version : strange codding in grid grouping feacture and store



PauloMargarido
10 May 2013, 3:48 AM
Hi all
Digging into code i found a strange coding ... follow me ...

Version 4.1.7

When you have In Ext.grid.feature.Grouping



onGroupMenuItemClick: function(menuItem, e) {
var me = this,
menu = menuItem.parentMenu,
hdr = menu.activeHeader,
view = me.view,
store = view.store;

delete me.lastGroupIndex;
me.block();
me.enable();
store.group(hdr.dataIndex); //means store.group(hdr.dataIndex, undefined);
me.pruneGroupedHeader();
me.unblock();
me.refreshIf();
}


Than in Ext.data.Store you have:


group: function(groupers, direction) { // direction is undefined
var me = this,
hasNew = false,
grouper,
newGroupers;


if (Ext.isArray(groupers)) {
newGroupers = groupers;
} else if (Ext.isObject(groupers)) {
newGroupers = [groupers];
} else if (Ext.isString(groupers)) {
grouper = me.groupers.get(groupers);


if (!grouper) {
grouper = {
property : groupers,
direction: direction
};
newGroupers = [grouper];
} else if (direction === undefined) {
grouper.toggle();
} else {
grouper.setDirection(direction);
}
}

//NOTICE THAT: direction stils undefined

if (newGroupers && newGroupers.length) {
hasNew = true;
newGroupers = me.decodeGroupers(newGroupers);

//now we go into decodeGroupers

me.groupers.clear();
me.groupers.addAll(newGroupers);
}

if (me.remoteGroup) {
if (me.buffered) {
me.pageMap.clear();
me.loadPage(1, { groupChange: true });
} else {
me.load({
scope: me,
callback: me.fireGroupChange
});
}
} else {
// need to explicitly force a sort if we have groupers
me.sort(null, null, null, hasNew);
me.fireGroupChange();
}
},


Than in the same class



decodeGroupers: function(groupers) {
if (!Ext.isArray(groupers)) {
if (groupers === undefined) {
groupers = [];
} else {
groupers = [groupers];
}
}


var length = groupers.length,
Grouper = Ext.util.Grouper,
config, i, result = [];


for (i = 0; i < length; i++) {
config = groupers[i];


if (!(config instanceof Grouper)) {
if (Ext.isString(config)) {
config = {
property: config
};
}
//BUG HERE ?????
config = Ext.apply({
root : 'data',
direction: "ASC"
}, config);

//Ext.apply(object, config,[defaults]) copies the config properties to object
//so we have object ={ root : 'data', direction: "ASC" } config= {..., direction: undefined, ...}
//shouldn't it be the opposite of that
/*
config = Ext.apply(config,{
root : 'data',
direction: "ASC"
});
*/
//or else put it like in 4.0.7, there it was OK
/*
Ext.applyIf(config, {
root : 'data',
direction: "ASC"
});
*/
//why is it changed???


//support for 3.x style sorters where a function can be defined as 'fn'
if (config.fn) {
config.sorterFn = config.fn;
}


//support a function to be passed as a sorter definition
if (typeof config == 'function') {
config = {
sorterFn: config
};
}


// return resulting Groupers in a separate array so as not to mutate passed in data objects.
result.push(new Grouper(config));
} else {
result.push(config);
}
}
return result;
},



So ... does what i can see correct ?? or am i missing anything?
(sorry for my "french", not english native)

slemmon
13 May 2013, 9:58 AM
Are you thinking that setting the grouping shouldn't affect the existing sorters on the store?