【问题标题】:ExtJS6 - Change Grid Column Default Sort Direction from ASC to DESCExtJS6 - 将网格列默认排序方向从 ASC 更改为 DESC
【发布时间】:2016-03-29 17:46:34
【问题描述】:

我有一个链接到远程商店的网格,并启用了远程排序。

当我第一次单击网格的标题时,它会将列顺序设置为升序,然后在第二次单击时降序。

有没有办法让第一次点击进入某些列的降序?

【问题讨论】:

    标签: extjs extjs6


    【解决方案1】:

    嗯.. 花了很多时间才弄明白,好像没有直接的 API 可以改变默认方向。

    这是我最后想到的,你需要更新商店中分拣机的 defaultSortDirection。

        store.getSorters().$sortable.setDefaultSortDirection('DESC');
    

    这里是Fiddle

    更新

    如果您想在列级别应用默认排序方向,那么您可以在列级别覆盖 toggleSortState 方法。

           columns: [{
                dataIndex: 'id',
                text: 'ID',
                width: 50,
                /**
                 * Overriding this function to Change the Default Sort Order.
                 */
                toggleSortState: function() {
                    if (this.isSortable()) {
                        var me = this,
                            grid = me.up('tablepanel'),
                            store = grid.store,
                            sortParam = me.getSortParam(),
                            direction = undefined;
    
                        if(!store.getSorters().get(sortParam)) {
                            direction = 'DESC';
                        }                        
                        this.sort(direction);
                    }
                },
            }
    

    这里是Fiddle

    【讨论】:

    • 谢谢它的工作,唯一的缺点是它改变了所有领域,你认为有办法让它只应用于选定的领域吗?
    • 更新了我的答案,请检查。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-23
    • 2015-03-05
    • 1970-01-01
    • 2020-06-30
    • 2017-10-27
    • 2014-07-11
    相关资源
    最近更新 更多