2
votes

I am using extjs sencha store for storing data. I make a proxy call to a web-service to get data. I refresh the data using store.load() function.

I am looking to edit the data that is received before it is given to the grid.

I know about the load event, but this function is executed after the load is completed and data is populated with the current data.

listeners : {
        'load' : function(store,records, options) {
    } 
},

I am looking to see how I can edit the returned data from web-service before it is assigned to the store. Basically data returned from my webservice is in different format than the format we give to extjs datagrid. So, want to do a data operation before we give to the grid. Hope we can do this.

Thx

1
You can overwrite the Ext.data.Proxy which has the relevant create, read, update, delete methods so overwrite the read, and you will get the information before you get the results put into your store. - darren102
I tried this function but now I see the data that is shown to the grid is empty - user1402539
read: function(operation, callback, scope) { var thisProxy = this; var cityInfo = [ {name: 'New Jersey', location: 'East Coast'}, {name: 'California', location: 'West Coast'} ]; operation.resultSet = new Ext.data.ResultSet({ records: cityInfo, total : cityInfo.length }); if (typeof callback == "function") { callback.call(scope || thisProxy, operation); } } - user1402539
Anything wrong I am doing ? - user1402539

1 Answers

3
votes

Model mappings can help you do this. There is a conversion function that can be supplied as well. Here is the example from the docs:

Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: [
        {
            name: 'firstName',
            convert: function(value, record) {
                var fullName  = record.get('name'),
                    splits    = fullName.split(" "),
                    firstName = splits[0];

                return firstName;
            }
        },
        'name', 'email',
        {name: 'age', type: 'int'},
        {name: 'gender', type: 'string', defaultValue: 'Unknown'}
    ]
});