我最近将 EXT JS 的版本更新为 5,并且覆盖 doSort 函数不再起作用。有人知道该怎么做吗?
覆盖示例:
{
text: 'Custom',
sortable : true,
dataIndex: 'customsort',
doSort: function(state) {
var ds = this.up('grid').getStore();
var field = this.getSortParam();
ds.sort({
property: field,
direction: state,
sorterFn: function(v1, v2){
v1 = v1.get(field);
v2 = v2.get(field);
return v1.length > v2.length ? 1 : (v1.length < v2.length ? -1 : 0);
}
});
}
}
编辑 1: 我只是尝试@tomgranerod 的解决方案,但 me.sortState 始终是“未定义”。所以我这样做是为了更新我的变量:
sort: function () {
var me = this,
grid = me.up('tablepanel'),
store = grid.store;
me.sortState = me.sortState === 'ASC' ? 'DESC' : 'ASC';
Ext.suspendLayouts();
me.sorting = true;
store.sort({
property: me.getSortParam(),
direction: me.sortState,
sortFn: function (v1, v2) {
v1 = v1.get(field);
v2 = v2.get(field);
return v1.length > v2.length ? 1 : (v1.length < v2.length ? -1 : 0);
}
});
delete me.sorting;
Ext.resumeLayouts(true);
}
但是 sortFn 函数永远不会被调用。我不知道为什么。===> !!!! 它适用于 EXT JS 5.0.1,但永远不会调用 sortFin 函数。!!!!
编辑2: 这是我试图拥有的:
升压:
if (v1 and v2 are numbers) return v1 > v2;
else if (v1 is a number and v2 a string) return false;
else if (v1 is a string and v2 a number) return true;
else if (v1 and v2 are strings) return v1 > v2;
描述:
if (v1 and v2 are numbers) return v1 < v2;
else if (v1 is a number and v2 a string) return true;
else if (v1 is a string and v2 a number) return false;
else if (v1 and v2 are strings) return v1 < v2;