【问题标题】:Grid grouping and sorting in ExtJS 4.2.1ExtJS 4.2.1 中的网格分组和排序
【发布时间】:2023-03-03 22:31:01
【问题描述】:

我尝试使用类似于此示例的分组来实现网格: http://dev.sencha.com/deploy/ext-4.0.0/examples/grid/groupgrid.html 此处数据按“Cuisine”列分组,并按此列排序分组。 当我将此示例的代码粘贴到使用 4.2.1 的项目或 ExtJS 4.2.1 文档站点的代码编辑器中时,视图完全相同,排序适用于“名称”列,但它不起作用按“美食”列。 他们是否删除了 4.2.1 中的分组列排序?如果没有,如何使它工作?

【问题讨论】:

    标签: extjs extjs4.2


    【解决方案1】:

    4.2.1 SDK 中存在相同的示例,实际上按分组列排序不再起作用。对我来说听起来像是一种回归,你应该通知 Sencha。

    编辑:

    这是 Ext.data.Store#sort 方法的代码已更改。恢复以前的版本修复了这些行为(请参阅我的 cmets 以找到修改后的行):

    Ext.define(null, {
        override: 'Ext.data.Store'
    
        ,sort: function(sorters, direction, where, doSort) {
            var me = this,
                sorter,
                newSorters;
    
            if (Ext.isArray(sorters)) {
                doSort = where;
                where = direction;
                newSorters = sorters;
            }
            else if (Ext.isObject(sorters)) {
                doSort = where;
                where = direction;
                newSorters = [sorters];
            }
            else if (Ext.isString(sorters)) {
                sorter = me.sorters.get(sorters);
    
                if (!sorter) {
                    sorter = {
                        property : sorters,
                        direction: direction
                    };
                    newSorters = [sorter];
                }
                else if (direction === undefined) {
                    sorter.toggle();
                }
                else {
                    sorter.setDirection(direction);
                }
            }
    
            if (newSorters && newSorters.length) {
                newSorters = me.decodeSorters(newSorters);
                if (Ext.isString(where)) {
                    if (where === 'prepend') {
                        // <code from 4.2.1>
                        // me.sorters.insert(0, newSorters);
                        // </code from 4.2.1>
    
                        // <code from 4.2.0>
                        sorters = me.sorters.clone().items;
    
                        me.sorters.clear();
                        me.sorters.addAll(newSorters);
                        me.sorters.addAll(sorters);
                        // </code from 4.2.0>
                    }
                    else {
                        me.sorters.addAll(newSorters);
                    }
                }
                else {
                    me.sorters.clear();
                    me.sorters.addAll(newSorters);
                }
            }
    
            if (doSort !== false) {
                me.fireEvent('beforesort', me, newSorters);
                me.onBeforeSort(newSorters);
    
                sorters = me.sorters.items;
                if (sorters.length) {
    
                    me.doSort(me.generateComparator());
                }
            }
        }
    });
    

    【讨论】:

      【解决方案2】:

      将sortable: true 设置为分组列的defaults 配置或子列本身的配置。例如

      {
                  // NOTE: these two are grouped columns
                  text: 'Close',
                  columns: [{
                      text: 'Value',
                      minWidth: 100,
                      flex: 100,
                      sortable: true,
                      dataIndex: 'ValueHeld_End'
                  }, {
                      text: 'Total',
                      minWidth: 110,
                      flex: 110,
                      sortable: true,
                      dataIndex: 'TotalPnL'
                  }]
              }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-02-12
        • 2017-02-09
        • 1970-01-01
        • 2023-03-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多