Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use extra params in store dynamically

Tags:

extjs

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.

like image 607
Navdeep Avatar asked Aug 10 '12 05:08

Navdeep


4 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'
    },
    // ...
like image 145
Alexandr Avatar answered Oct 18 '22 11:10

Alexandr


store.getProxy().extraParams = {
    foo: 'bar'
};
store.load();
like image 42
Evan Trimboli Avatar answered Oct 18 '22 09:10

Evan Trimboli


For extjs4, it's rather:

store.load({
    params:{
        'foo1': bar1,
        'foo2': bar2
    } 
});
like image 10
JLavoie Avatar answered Oct 18 '22 10:10

JLavoie


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();
like image 2
Edy Aguirre Avatar answered Oct 18 '22 10:10

Edy Aguirre