use extra params in store dynamically

Viewed 52708

I have a form. In the form, I am using a comboBox with a store.

{
    xtype: 'combobox',
    id: 'SubContractor',
    name: 'SubContractor',
    fieldLabel: 'Sub Contractors',
    selectOnFocus: true,
    editable: false,
    displayField: 'FirstName',
    store: 'jsonGetSubContractorsList',
    typeAhead: true,
    allowBlank: false,
    typeAheadDelay: 20,
    valueField: 'SubContractID',
    width: 440,
    labelWidth: 229
}

In store, in proxy I have static extraParams, it's working.

proxy: {              
    type: 'ajax',
    url: '/admin/contract/subcontractors/jsonsubcontractorslist',
    extraParams: {
        cid : 34
    },
    reader: {
        type: 'json',
        root: 'data'
    }
},

But I don't get, how to send the contract ID to my store dynamically.

5 Answers

Sorry guys,

I've spent more time to understand all available options and the different. Too many answers about this problem. I've summarized them and hope the answer will help someone.

When you create a store (Supported in Ext JS 6.x.x, probably in earlier versions):

var store = Ext.create('YourStore', {
    listeners: {
        // Fires before a request is made. op is an Ext.data.Operation object
        beforeload:function(store,op){
            // Set request parameters (without overriding other parameters)
            op.setParams(Ext.apply(op.getParams()||{},{
                par1:'value'
            }));
        },
        ... 

When you define a proxy of a store. Supported since Ext JS 4.x.x:

proxy: {
    type: 'ajax',
    url: 'rest/dse',
    extraParams: {
        par1: 'value'
    }

Note: The params are sent for multiple subsequent queries in this case!

When you load data explicitly. Supported in all versions of Ext JS (since 3.x.x):

store.load({
    params: { par1: "value" }
});

Note: it is not needed to put par1 inside of ‘’ or “”.

Alternative sub-option, which uses access to proxy and its extraParams option:

store.getProxy().extraParams = {
    par1: 'value'
};
store.load();

Be careful with this. This parameter is sent for multiple subsequent queries!

When you create a store. Supported only in Ext JS 3.x version.

var genres1 = new Ext.data.Store({
    baseParams: {
        param1: 'value1',
        param2: 'value2'
    },
    // ...
Related