Sergey Novikov
Sergey Novikov

Reputation: 4196

ExtJS 4 Set extraParam to the store dynamically

I have a combo with a remote store in the modal window. To obtain the data is necessary to send an extra parameter to the store. This parameter is stored as a property of the window. How can I pass it?

This is my app.js file (I use MVC model, atleast try to use it :) ):

Ext.application( {
    requires: [
        'Ext.Ajax'
    ],
    autoCreateViewport: true,
    name: 'PM',
    stores: [
        ...
        'SourceIps',
        ...
    ],
    models: [
        ...
    ],
    controllers: [
        ...
    ],

    init: function() {
    }
} );

How I show window:

showAddRProbe: function () {
    var data = {
        'deviceId': this.getProbesDeviceCombo().getValue()
    };
    var addProbe = Ext.create( 'PM.view.AddProbe', [true, data] );
    addProbe.show();
}

Window:

Ext.define( 'PM.view.AddProbe', {
    extend: 'Ext.window.Window',
    ...
    constructor: function( data ) {
        this.newProbe = data[0];
        this.probeData = data[1];
    ...

Required parameter passed as probeData.data.deviceId

Combo:

{
    xtype: 'combo',
    allowBlank: false,
    blankText: Locale.gettext( 'Please select a Source IP' ),
    fieldLabel: Locale.gettext( 'Source IP' ),
    name: 'sourceIP',
    triggerAction: 'all',

    store: 'SourceIps',
    value: Ext.getStore( 'SourceIps' ).getAt(0).get('id'),
    valueField: 'id',
    displayField: 'name',
    queryMode: 'local'
}

Store:

Ext.define('PM.store.SourceIps', {
    extend: 'Ext.data.Store',
    model: 'PM.model.IdName',

    autoLoad: true,

    proxy: {
        type: 'ajax',
        api: {
            read: 'data/getDeviceIps.php'
        },
        reader: {
            type: 'json',
            root: 'data',

            successProperty: 'success',
            messageProperty: 'message'
        }
    }
});

I tired to add extraParam as follow, but it does not work:

var probeData = this.getProbeWindow().probeData.data;
this.getSourceIpCombo().getStore().getProxy().setExtraParam( 'deviceId', probeData.deviceId );
this.getSourceIpCombo().getStore().load();

Upvotes: 2

Views: 11999

Answers (2)

kuldarim
kuldarim

Reputation: 1106

You could add storeId property to your store and then use

var store = Ext.data.StoreManager.lookup('myStore');

and use this to apply extra params:

Ext.apply(store.getProxy().extraParams, {
    foo : 'bar',
    ...
});

or

store.getProxy().setExtraParam("countriesId", 1) // add parameter 'countriesId' = 1

Upvotes: 2

dbrin
dbrin

Reputation: 15673

Use

  this.getSourceIpCombo().getStore().load({
       params: {
          deviceId : probeData.deviceId
        }
  });

Upvotes: 4

Related Questions