0
votes

When a grid panel sort is triggered on column 'Email', how do I force a ASC sort on column 'Name' first and then for EXTJS to perform a sort on column 'Email' next.

I found the following example which is in the right direction.. http://cdn.sencha.com/ext/gpl/4.2.0/examples/grid/multiple-sorting.html

...but I cannot see how I would implement this in a gridpanel when a user clicks on a column sort, the example uses buttons against the store directly...the only event I think I can use is gridpanel sortchange but it is a post sort event.

I create a fiddle example https://fiddle.sencha.com/#fiddle/imt where I put a sorter in the store

sorters: [{
    property: 'Name',
    direction: 'ASC'
}],

but after playing around with the other columns sorts in the grid, the sorter does not prioritize on 'Name' anymore.

Any recommendations ?

3
Not sure why I got down voted for a legitimate question?? - user2574678

3 Answers

0
votes

How about using the headerclick event on the grid. This takes the clicked column config as one of the params so based on that you could apply your own custom sorting to the underlying store.

0
votes

But is it really a problem sorting twice? Otherwise you could override the headertriggerclick event of Ext.grid.header.ContainerView.

sortchange: function (ct, column, direction, eOpts ) {

 var store = column.up('gridpanel').getStore();

 store.sort([{
  property : 'name',
  direction: 'ASC'
 }, {
  property : column.dataIndex,
  direction: direction
 }]);

}
0
votes

The problem was with the naming of the fields. You capitalized 'Name' in the sorters, but the actual field is 'name'.

 fields: [
    {name:'name'},
    {name:'summaryId'},
    {name: 'id'},
    {name:'email'},
    {name:'phone'},
],

When I changed it to 'name', it sorted with that and any other sorters supplied.

    sorters: [{
    property: 'name',
    direction: 'ASC'
    },{
    property:'email',
    direction: 'DESC'
    }],