amrit_neo
amrit_neo

Reputation: 1759

Sencha Touch list store disable sorting

I have my list which is getting data from php service, the data received is in the order I need. But sencha automatically sort my list alphabetically. Below is my code:

Ext.define('MyList', {
    extend: 'Ext.dataview.List',

    config:     {
        grouped: true,
        plugins: [
            {
                xclass:          'Ext.plugin.PullRefresh',
                pullRefreshText: 'Pull down to refresh'

            },
            {
                xclass:     'Ext.plugin.ListPaging',
                autoPaging: true,
                noMoreRecordsText: 'No More Records'

            }
        ]
    },
    initialize: function () {
        this.callParent(arguments);
        var store = Ext.create('Ext.data.Store', {

            pageParam: 'page',
            grouper: {
                groupFn: function (record) {
                    return record.data.group_label;
                }
            },
            model:   'ListItem',
            proxy:   {
                type:   'ajax',
                url:    '/m/services/activity_list_items.php',
                reader: {
                    type:         'json',
                    rootProperty: 'root.results'
                }
            }
        });

        var template = Ext.create('GenericListItem', {
            hascounts: true,
            hasicon:   true,
            varmap:    {
                descr:  'subtext',
                count:  'sub_item_cnt',
                itemid: 'itemid',
                uniqid: 'uniqid'
            }
        });

        var emptyText = 'Recent Activity Items';
        this.setStore(store);
        this.setItemTpl(template);
        this.setEmptyText(emptyText);
    }
});

How can I avoid the auto sorting of list?

Upvotes: 3

Views: 1869

Answers (2)

Sivakumar
Sivakumar

Reputation: 305

Add the following to your store config.

remoteSort : true,

remoteSort defaults to false in sencha. So sencha automatically sorts in the client side. Check the link for more details http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Store-cfg-remoteSort

Upvotes: 7

Eli
Eli

Reputation: 14827

Just remove this:

grouped: true

from your list config if you don't want a header for each item and compulsory to remove this:

grouper: {
    groupFn: function (record) {
        return record.data.group_label;
    }
}

from your store because basically in your situation grouper property are using for grouping your item alphabetically based on your group_label field. Hope it helps :)

Upvotes: 2

Related Questions