Greg Lafrance
Greg Lafrance

Reputation: 809

Why is my ExtJS 4.2 gridpanel sort not working?

Not sure why my sort is not working for this gridpanel.

I set the sorters property, I believe correctly.

And I set the sortOnLoad property as well.

Not sure why this simple case is not working.

I don't think I need to do a remote sort in this case, so just not sure why this is not working.

Ext.onReady(function() {
    Ext.define('com.myCompany.MyGridModel', {
        extend : 'Ext.data.Model',
        fields : [{
            name : 'name',
            type : 'string'
        }, {
            name : 'address',
            type : 'string'
        }, {
            name : 'type',
            type : 'string'
        }]
    });
    var store = Ext.create('Ext.data.Store', {
        model: 'com.myCompany.MyGridModel',
        proxy: {
            type: 'ajax',
            url: 'centers.json',
            reader: {
                type: 'json',
                root: 'centers'
            },
            sortOnLoad: true,
            sorters: { property: 'name', direction : 'ASC' }
       }
    });
    store.load();
    var grid = Ext.create('Ext.grid.Panel', {
        layout: 'fit',
        store: store,
        columns: [{
            text: 'Name',
            dataIndex: 'name',
            name: 'name'
        }, {
            text: 'IP Address',
            dataIndex: 'address',
            name: 'address'
        }, {
            text: 'Type',
            dataIndex: 'type',
            name: 'type'
        }],
        renderTo: Ext.getBody(),
    });
    grid.getView().refresh();
});

{
  "centers": [
    {
      "name": "South Test Center",
      "address": "30.40.50.60",
      "type": "TestType2"
    },
    {
      "name": "East Test Center",
      "address": "50.60.70.80",
      "type": "TestType1"
    },
    {
      "name": "West Test Center",
      "address": "40.50.60.70",
      "type": "TestType3"
    },
    {
      "name": "North Test Center",
      "address": "20.30.40.50",
      "type": "TestType4"
    }
]
}

Upvotes: 2

Views: 5783

Answers (1)

Bob Obringer
Bob Obringer

Reputation: 68

The sortOnLoad and sorters configuration options should be placed directly on the store, not on the model.

See the Ext.data.Store documentation here:

http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.Store-cfg-sorters http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.Store-cfg-sortOnLoad

Upvotes: 2

Related Questions