Pravin
Pravin

Reputation: 6662

Grouped and sorted list in sencha touch 2

I have following code

Ext.regModel('Centre', {
   fields: ['name', 'url']
}); 

Ext.application({
    name: 'Sencha',

    launch: function() {

         var panel = new Ext.Panel({
        fullscreen: true,
        dockedItems: [
          {
            xtype: "toolbar",
            dock: "top",
            title: "DEMO APP"

          },
          {
            xtype: "toolbar",
            items: [
              {
                iconMask: true,
                iconCls: "download"
              },
              {
                iconMask: true,
                iconCls: "favorites"
              },
              {
                iconMask: true,
                iconCls: "search"
              },
              {
                iconMask: true,
                iconCls: "user"
              }
            ]  
          },
          {
            xtype: 'list',
            itemTpl: '{name}',
            sorters: 'name',

            store: {
                fields: ['name', 'url'],
                   data: centers
            },
            itemConfig: {
              tpl: '{url}'
            },
            listeners: {
              itemtap:function(data,index){
                var record = data.getStore().getAt(index);
                redirect_url = record.raw.url
                 // the record that has been clicked.
                 window.location = redirect_url
              }
            }
          },


        ]
      });   


   }
});

centers has a list of centers. I want to sort and group the list. Tried getGroupString() but didn't help. May be I am missing something..

Upvotes: 2

Views: 4654

Answers (2)

Brandon Hawkins
Brandon Hawkins

Reputation: 63

For anyone using 2.1+, the syntax is now to define a group object with a groupFn function in the config:

grouper: {
    groupFn: function(record) {
        return record.get('name').substr(0, 1);
    },
    sortProperty: 'name'
}

Upvotes: 2

stan229
stan229

Reputation: 2607

Your list needs to have the config property grouped:true

(// indexBar:true as well if you want the alphabet on the side)

Your store needs to have the getGroupString function implemented

getGroupString: function(record) { return record.get('name') }

Upvotes: 3

Related Questions