In an ExtJS Grid, how do I get access to the data store fields that are part of the sort set

Go To StackoverFlow.com

2

How do I get access to the columns/datastore fields that are part of the sort set.

I am looking to modify the a grid's sort parameters for remote sorting. I need the remote sort param's sort key to match the column's field's mapping property. I need these things to happen though the normal 'column header click sorts the data' functionality.

2012-04-05 23:53
by gbegley
I need to determine which columns are sorted, then get the column's field, and then determine the 'mapping' of those fields, and finally use the mapping to set the sort parameter for remote sorting (e.g on 'beforeload' - gbegley 2012-04-06 11:53
The docs show a store has a 'sorters' property, which is a collection of 'Ext.util.Sorter' objects. The source indicates we should be able to access a sorter's 'property' method, although it's not in the docs - gbegley 2012-04-06 13:43


2

Remote sorting and field mapping (ExtJS 4.1)

This functionality seems not to be implemented in ExtJS. Here is a solution using the encodeSorters function provided since ExtJS 4. Accessing fields map throught the model's prototype is a bit dirty but it does the job :

var store = Ext.create('Ext.data.Store', {
    ...,
    proxy: {
        ...,
        encodeSorters: function (sorters) {
            var model = store.proxy.model,
                map = model.prototype.fields.map;
            return Ext.encode(Ext.Array.map(sorters, function (sorter) {
                return {
                    property : map[sorter.property].mapping || sorter.property,
                    direction: sorter.direction
                };
            }));
        }
    }
});

However, it would be more relevant to override the original method :

Ext.data.proxy.Server.override({
    encodeSorters: function(sorters) {
        var min, map = this.model.prototype.fields.map;
        min = Ext.Array.map(sorters, function (sorter) {
            return {
                property : map[sorter.property].mapping || sorter.property,
                direction: sorter.direction
            };
        });
        return this.applyEncoding(min);
    }
});
2012-08-30 15:47
by leaf


0

Assuming you are using simpleSortMode, you could do something like this in your store.

listeners: {
        beforeload: function( store, operation, eOpts ) {
            if (store.sorters.length > 0) {


                var sorter = store.sorters.getAt(0),
                dir = sorter.direction,
                prop = sorter.property,
                fields = store.model.getFields(),
                i,
                applyProp = prop;

                for (i = 0; i < fields.length; i++) {
                    if (fields[i].name == prop) {
                        applyProp = fields[i].mapping || prop;
                        break;
                    }
                } 

                //clearing the sorters since the simpleSortMode is true so there will be only one sorter
                store.sorters.clear();
                store.sorters.insert(0, applyProp, new Ext.util.Sorter({
                     property : applyProp,
                     direction: dir
                 }));
            }

        }

    },
2013-07-26 15:57
by ssinganamalla
Ads