Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store with custom sorting in Sencha Touch

I have a store + model which is connected to a 3rd party plugin (Ext.ux.TouchGridPanel). The plugin calls the store's sort() method properly with the relevant mapping. Everything is working fine, and the store sorts itself. However, I would prefer to add customer sorting to the store. I have tried adding a sortType field into my model:

Ext.regModel("Transactions", {
    fields: [
        {
            name: 'unit',
            type: 'string',
            sortType: function(value) {
                console.log('PRINT GDAMNIT');
                return 0;
            }
        },

        ...

    ]
});

This, however, is not working, and the sortType is not getting called.

TLDR: How to make custom sorting work for stores?

like image 789
Nicodemuz Avatar asked Dec 21 '22 15:12

Nicodemuz


1 Answers

Your store will need a sorter added that will sort on that field before it will call the sortType function.

var store = new Ext.data.Store({ 
   model: 'Transactions',
   sorters: [
      {
        property: 'unit',
        direction: 'DESC'
      }
   ]}
);

Sort type converts the value of a field into another value to ensure proper ordering. If you aren't sorting on that field than there is no reason to call that function. You could add the sortDir to the field which would sort the field into ascending/descending order based on the type of the field alone.

like image 61
mistagrooves Avatar answered Jan 26 '23 01:01

mistagrooves