深埋在 dom 里面有一个setSortState
关于Ext.grid.header.Container
类和Ext.grid.column.Column
类的函数。这些不会出现在 4.1.0 文档中的任何地方,但它们仍然存在于代码中。
您可以自己查看这些函数,以全面了解它们的作用,但它们的要点是在第一个参数中查找 a或 a'DESC'
的switch 语句,例如:'ASC'
null
setSortState(`DESC`);
setSortState(`ASC`);
setSortState(null);
使用单个null
参数调用此函数的标题版本或列版本将删除列上的排序类。唯一真正的区别是标题版本查看网格的存储以在存储sorters
属性中找到活动的排序器,然后使用该数据来确定在哪一列上调用此函数 - 列版本只是运行它所在的列对象从调用。
在我的用例中,我没有向 storesorters
属性添加排序器,因此我使用的是列版本(即setSortState
从Ext.grid.column.Column
对象调用)。
首先,这是我实现允许本地(客户端)排序的缓冲存储的示例:
Ext.define('MyApp.store.TheBufferedStoreWithLocalSorting', {
extend: 'Ext.data.Store',
requires: [
'Ext.ux.data.PagingMemoryProxy',
'Ext.util.MixedCollection'
],
model: 'MyApp.model.SomeModel',
buffered: true,
pageSize: 100,
remoteSort: true, // this just keeps sorting from being disabled
proxy: {
type: 'pagingmemory',
reader: 'json'
},
/*
* Custom sort function that overrides the normal store sort function.
* Basically this pulls all the buffered data into a MixedCollection
* and applies the sort to that, then it puts the SORTED data back
* into the buffered store.
*/
sort: function(sorters) {
var collection = new Ext.util.MixedCollection();
collection.addAll(this.proxy.data);
collection.sort(sorters);
this.pageMap.clear();
this.getProxy().data = collection.getRange();
this.load();
}
});
现在,为了回答我的问题,每当商店重新加载时删除排序器类,我只需要这样做:
Ext.each(myGrid.columns, function(column, index) {
if (column.hasCls('x-column-header-sort-ASC') ||
column.hasCls('x-column-header-sort-DESC')) {
myGrid.columns[index].setSortState(null);
return false;
}
});