Ext js sorting custom column by contents

前端 未结 3 2115
悲&欢浪女
悲&欢浪女 2021-01-05 13:28

I have a grid in ext with some custom columns, and I want to be able to sort this column - I want to sort it by what is displayed inside of it, but really I just cannot figu

3条回答
  •  忘掉有多难
    2021-01-05 13:44

    There is a convert method on the Ext.data.Model class that allows you to convert the data before it's being used. Then you can just specify this 'dataIndex' in your column and do a normal sort. The column will be sorted by that converted value. Here is the a sample model with just one field (Parent) and with it's corresponding conversion:

    Ext.define('MyModel', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'Parent',   type: 'string', convert: sortParent},
            // other fields...
        ],
        sortParent: function(value, record) {
            var ret = record.raw.Parent;
            if (ret) {
                return ret.Name;
            } else {
                meta.tdCls = 'invisible';
                return record.data.Name;
            }
        }
    });
    

提交回复
热议问题