论坛首页 Web前端技术论坛

[OPEN-848] GroupingStore的一个sort bug

浏览 1918 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-04-16   最后修改:2011-02-16

提交官方bug详情:[OPEN-848] GroupingStore sort have a bug when not set the sortInfo of config

 

GroupingStore配置时未配置sortInfo

现象:不要点击任何列进行排序,隐藏其中一列,出现bug!

 

 

//Ext.data.GroupingStore.prototype.sort function
sorters = [this.sortInfo];//have a bug when not set this.sortInfo

 这里sorters 实际是 [null],在接下来的地方会发生bug

//Ext.data.Store.prototype.sortData function
        //create a sorter function for each sorter field/direction combo
        for (var i=0, j = sorters.length; i < j; i++) {
//in fact sorters[0] === null will throw a exception
            sortFns.push(this.createSortFunction(sorters[i].field, sorters[i].direction));
        }

I fix:

Ext.data.GroupingStore.prototype.sort

sorters = this.sortInfo ? [this.sortInfo] : [];
 //old: sorters = [this.sortInfo];

 完整修复:

if (Ext.version == '3.2.0') {
	Ext.apply(Ext.data.GroupingStore.prototype, {
		sort: function(fieldName, dir) {
		    if (this.remoteSort) {
		        return Ext.data.GroupingStore.superclass.sort.call(this, fieldName, dir);
		    }
		
		    var sorters = [];
		
		    //cater for any existing valid arguments to this.sort, massage them into an array of sorter objects
		    if (Ext.isArray(arguments[0])) {
		        sorters = arguments[0];
		    } else if (fieldName == undefined) {
		        //we preserve the existing sortInfo here because this.sort is called after
		        //clearGrouping and there may be existing sorting
		        sorters = this.sortInfo ? [this.sortInfo] : [];
		    } else {
		        //TODO: this is lifted straight from Ext.data.Store's singleSort function. It should instead be
		        //refactored into a common method if possible
		        var field = this.fields.get(fieldName);
		        if (!field) return false;
		
		        var name       = field.name,
		            sortInfo   = this.sortInfo || null,
		            sortToggle = this.sortToggle ? this.sortToggle[name] : null;
		
		        if (!dir) {
		            if (sortInfo && sortInfo.field == name) { // toggle sort dir
		                dir = (this.sortToggle[name] || 'ASC').toggle('ASC', 'DESC');
		            } else {
		                dir = field.sortDir;
		            }
		        }
		
		        this.sortToggle[name] = dir;
		        this.sortInfo = {field: name, direction: dir};
		
		        sorters = this.sortInfo ? [this.sortInfo] : [];
		    }
		
		    //add the grouping sorter object as the first multisort sorter
		    if (this.groupField) {
		        sorters.unshift({direction: this.groupDir, field: this.groupField});
		    }
		
		    return this.multiSort.call(this, sorters, dir);
		}
	});
}
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics