Navdeep
Navdeep

Reputation: 335

use extra params in store dynamically

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.

Upvotes: 11

Views: 55167

Answers (5)

Alexandr
Alexandr

Reputation: 9505

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'
    },
    // ...

Upvotes: 2

Edy Aguirre
Edy Aguirre

Reputation: 2143

Try this:

  .
  . 
  proxy: {
    type: 'ajax',
    api: {
        create: CONTEXT_PATH + '/mvc/odon/create', 
        read: CONTEXT_PATH + '/mvc/odon/list',
        update: CONTEXT_PATH + '/mvc/odon/update',
        destroy: CONTEXT_PATH + '/mvc/odon/delete'
    },
    .
    .

Passing the parameter:

 var storeDiagnostico= down('gridpanel').getStore();//Ext.create('store.odont.DStore');
        storeDiagnostico.getProxy().setExtraParam("idOdontologia", value);
        storeDiagnostico.load();

Upvotes: 2

DarkKnightFan
DarkKnightFan

Reputation: 1953

In Chrome and FF even this will work:

store.proxy.extraParams.foo= 'bar';

But in IE8 (had this problem personally) got to do it the way mentioned by Evan

store.proxy.extraParams = {foo: 'bar'};

Check this...

Upvotes: 1

JLavoie
JLavoie

Reputation: 17596

For extjs4, it's rather:

store.load({
    params:{
        'foo1': bar1,
        'foo2': bar2
    } 
});

Upvotes: 11

Evan Trimboli
Evan Trimboli

Reputation: 30082

store.getProxy().extraParams = {
    foo: 'bar'
};
store.load();

Upvotes: 22

Related Questions