Как реализовать сортировку в EXTJS 2.3 по заголовку столбца - PullRequest
0 голосов
/ 23 сентября 2019

Я пробовал разные методы для реализации сортировки, основанной на значении объекта, и не мог заставить ее работать независимо от того, с чем я сталкивался в Интернете.У меня есть сетка со следующей моделью столбца.

this.columnModel = new Ext.grid.ColumnModel([rowNumber, {
            header : 'Employer Id',
            dataIndex : 'employerId',
            width : 100,
            sortable : true
        }, {
            header : 'Name',
            dataIndex : 'name',
            sortable : true,
            width : 200
        }, {
                header: 'Status',
                dataIndex: 'status',
                sortable: true,
                width: 105,
                renderer: function(value) {
                    return value ? value.description : "";
                }
        }]);

Последнее поле с dataIndex 'status' - это объект, содержащий идентификатор и описание.Я хочу отсортировать данные на основе поля id в объекте.Вот JsonStore для сетки:

var employerDataFields = [{name: "employerId", type: "string"}, 
                    {name: "name", type: "string"}, 
                    {name: "status", type: "auto"}];

this.employerStore = new Ext.data.JsonStore({
            proxy : this.proxy,
            remoteSort : false,
            baseParams : {
                pageSize : this.PAGESIZE
            },
            root : 'employerList',
            fields : employerDataFields
        });

1 Ответ

0 голосов
/ 23 сентября 2019

Используйте sortInfo config из store для сортировки по столбцу.

this.employerStore = new Ext.data.JsonStore({
            proxy : this.proxy,
            remoteSort : false,
            baseParams : {
                pageSize : this.PAGESIZE
            },
            root : 'employerList',
            fields : employerDataFields,
            sortInfo:{
                field:'employerId',
                direction:'ASC' 
            }
        });

sorters config доступна, так как extjs 4.1.3

  sorters: [{
         property: 'employerId',
         direction: 'ASC'
      },

Если выхотите сортировать динамически, используйте sort()

employerStore.sort('employerId','ASC')
...