Sunil Bamal
Sunil Bamal

Reputation: 117

How to pass parameters to store in ExtJs

I am working on a display where I need to bind a combobox but I am unable to pass parameters. Below is my code please provide me the way to pass parameters.

//store
Ext.define('NetworkStore', {
    extend: 'Ext.data.Store',
    alias: 'NetworkStore',
    fields: ['Id', 'value'],
    storeId: 'NetworkStore', 
    autoLoad: true,
    proxy: {
        type: 'ajax',
        useDefaultXhrHeader: false,
        actionMethods: { create: "POST", read: "GET", update: "POST", destroy: "POST" },
        headers: { 'Content-Type': 'application/x-www-form-urlencode' },
        limitParam: false,
        startParam: false,
        pageParam: false,
        extraParams: {
            Style: 1
        },
        url: 'url',
        reader: {
            type: 'json'
        }
    }
});

xtype: 'combo',
name: 'NetworkIDList',
store: {
        type: 'NetworkStore',
        'Style': 3 //parameter
        //params: {  // tried this way as well but did not work for me.
        //  Style: 3
        //}
        }

Note: Store is defined in a separate file.

Upvotes: 0

Views: 3704

Answers (2)

Sunil Bamal
Sunil Bamal

Reputation: 117

The store should be passed like below format.

store: {
        type: 'NetworkStore',
        proxy: {
                extraParams: {
                    Style: 3
                }
            }
        }

Upvotes: 1

Dinkheller
Dinkheller

Reputation: 5054

You can change the params as follows:

let store = Ext.data.StoreManager.lookup('NetworkStore'),

    // params are part of the proxy, not the store
    proxy = store.getProxy(),

    // make sure you keep the other params
    newParams = Ext.apply(proxy.getExtraParams(), {style: '3'});

// set the params to the proxy    
proxy.setExtraParams(newParams);

// do whatever you plan to do with the store
store.load();

If you want to bind a value to store proxy params, take a look at this fiddle.

Upvotes: 0

Related Questions