Monday, April 22, 2013

ExtJS passing parameters to a store proxy

I came across a need to pass parameters to a GET rest request. In my case, the server code was filtering which columns to return based on a parameter received. I started looking for a way to pass along such a parameter to my store proxy. Many solutions suggested to call the load method manually, which would allow you to pass in some parameters with it.

However, this was not possible for my application architecture because the store had to be on autoLoad: true. It is possible to pass an extraParams config to a proxy.



Ext.define('myStore', {
    extend: 'Ext.data.Store',
    model: 'myModel',
    storeId: 'mystore',
    proxy: {
        type: 'rest',
        url: buildServiceUrl('users'),
        simpleSortMode: true,
        extraParams: {
            inclProps: '{userId, shortDesc}'
        },
        reader: {
            type: 'json',
            root: 'data'
        },
        writer: {
            nameProperty: 'mapping'
        }
    },
    
    autoLoad: true
});

1 comment: