Ext js sorting custom column by contents

前端 未结 3 2111
悲&欢浪女
悲&欢浪女 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 14:00

    You should be able to override the doSort method of the column. Here's the gist of it. I also created a working fiddle (http://jsfiddle.net/cfarmerga/LG5uA/). The fiddle uses the string length of a field as the property to sort on, but of course you could apply your own custom sort logic.

    var grid = Ext.create('Ext.grid.Panel',{
        //...
        columns: [
            { text: 'name', dataIndex: 'name', sortable: true },
            {
                text: 'Custom',
                sortable : true,
                dataIndex: 'customsort',
                doSort: function(state) {
                    var ds = this.up('grid').getStore();
                    var field = this.getSortParam();
                    ds.sort({
                        property: field,
                        direction: state,
                        sorterFn: function(v1, v2){
                            v1 = v1.get(field);
                            v2 = v2.get(field);
                            return v1.length > v2.length ? 1 : (v1.length < v2.length ? -1 : 0);
                        }
                    });
                }
            }
        ]
       //....  
    });
    

提交回复
热议问题