我没有在Ext6中找到与网格列相关的doSort函数,也没有在任何升级说明中找到它。可能是因为它是一个私有函数,谁能告诉我doSort在Ext4中做同样的事情的替代方法是什么?
我试着用排序器代替,
{
text: 'columnText',
dataIndex: 'columnIndex',
sorter: me.sort
}
sort: function(v1,v2) {
...
}但我没有在v1中找到像dataIndex或columnName这样的smth,v2参数可以进行排序。(这只是一个模型)
我需要空单元格在升序排序后从下面开始,空单元格在降序排序后从上面开始
谢谢。
发布于 2016-09-05 18:02:02
这里的问题是什么?您可以使用模型对象检索要排序的列数据。从文档中:
sorter: function(record1, record2) {
var name1 = record1.data.columnIndex;
var name2 = record2.data.columnIndex;
return name1 > name2 ? 1 : (name1 === name2) ? 0 : -1;
}编辑:如果你不想为每一列重写它,那么你可以这样做:
sorter: (function(columnIndex){ return function(v1, v2){ me.sort(v1, v2, columnIndex);} })("column1")现在,您可以将列名作为排序函数中的第三个参数。
发布于 2016-09-05 18:36:06
您希望对存储进行排序,而不是对列进行排序。我们来看一下ExtJS 4中的doSort函数:
doSort: function(state) {
var tablePanel = this.up('tablepanel'),
store = tablePanel.store;
// If the owning Panel's store is a NodeStore, this means that we are the unlocked side
// of a locked TreeGrid. We must use the TreeStore's sort method because we cannot
// reorder the NodeStore - that would break the tree.
if (tablePanel.ownerLockable && store.isNodeStore) {
store = tablePanel.ownerLockable.lockedGrid.store;
}
store.sort({
property: this.getSortParam(),
direction: state
});
},
/**
* Returns the parameter to sort upon when sorting this header. By default this returns the dataIndex and will not
* need to be overriden in most cases.
* @return {String}
*/
getSortParam: function() {
return this.dataIndex;
},现在,这段代码仍然在ExtJS 6中工作,只是它不再是框架的一部分。你可以“把它放回框架中”(例如,作为一个重写),它应该会再次工作。或者您可以直接使用column事件中的相关部分,例如
columns:[{
dataIndex:'ABC',
listeners:{
headercontextmenu:function(ct, column) {
column.mySortState = column.mySortState=='ASC'?'DESC':'ASC';
ct.up('grid').getStore().sort({
property:column.dataIndex;
direction:column.mySortState
});
}
}
}]发布于 2017-04-21 18:41:38
也许你需要在模型中这样定义它:
fields: [{
name: "textField",
type: 'string',
//sortType: 'asInt'
}]https://stackoverflow.com/questions/39327384
复制相似问题