ExtJs4 - Store baseParams config property?

shane87 picture shane87 · May 19, 2011 · Viewed 33.5k times · Source

In extjs3.x I used the stores baseParams config property to specify parameters used to load the store.
This property no longer exists in extjs 4. What should I do instead of this?

Also in extjs3 I was able to specify wether the stores proxy was a GET or a POST method by using the proxy method config property. What should I do instead of this?

My ExtJs 3 code ->

   var store = new Ext.data.JsonStore({
        root: 'Data',
        baseParams: {
           StartDate: '',
           EndDate: '''
        },//baseParams
    proxy: new Ext.data.HttpProxy({
        url: 'Time/Timesheet',
        method: 'POST'
    })//proxy
});//new Ext.data.JsonStore

Answer

Craig picture Craig · May 19, 2011

You need to use the 'extraParams' proxy property in place of the baseParams one from Ext 3. An equivalent JsonStore in ExtJS 4 looks like this:

Ext.define('YourModel', {
    extend: 'Ext.data.Model',
    fields: ['field1', 'field2']
}); 

var store = new Ext.data.Store({
    model: 'YourModel',
    proxy: {
        type: 'ajax',
        url : 'Time/Timesheet',
        root: 'Data',
        extraParams: {
            StartDate: '',
            EndDate: ''
        }
    }
});

As far as I know, the HTTP transport method is set automatically according to RESTful principles according to what you're trying to accomplish. For example, if you load the store a GET request is used; creating a new record uses a POST, etc.

You can override this if necessary though, by overriding the actionMethods property of the proxy:

var store = new Ext.data.Store({
    model: 'YourModel',
    proxy: {
        type: 'ajax',
        url : 'Time/Timesheet',
        root: 'Data',
        actionMethods: {
            read: 'POST'
        },
        extraParams: {
            StartDate: '',
            EndDate: ''
        }
    }
});