PDA

View Full Version : Extraparams value in Ajax proxy not working (Ext JS 4; Firefox 5)



dp_vl
6 Jul 2011, 12:16 PM
Hello, I am new to Ext JS (using version 4) and have the following question:

I am trying to reload a grid base on the value of another field on the screen, the reloading is invoked when a button is clicked.

Here is the def of my datastore for the grid:

var dsGrid = new Ext.data.JsonStore({
autoLoad : false,
fields: ['fld1', 'fld2'],
proxy : {
type: 'ajax',
url: 'test.pgm',
extraparams: polnum : Ext.getCmp('NUMFLD').getValue()
reader: {
type: 'json',
root: 'somedata'
}
}
});


And in the button click event, I coded:
dsGrid.load();

As I can see the app is running cause everytime I click the button, the browser invokes the program on my server, yet the "polnum" parameter is not reflecting to the NUMFLD's value on the screen. It's always 0, or if I set NUMFLD's value after the "Ext.onReady(function()" statement, then it's always that static value gets passed to the server program.

Could anyone point out what I've done wrong?

Thanks,
DP

mailisa
7 Jul 2011, 5:08 AM
Try adding this listener to your store:


var dsGrid = new Ext.data.JsonStore({
//...blabla
listeners: {
beforeload: function(store, operation){
this.proxy.extraParams['polnum'] = Ext.getCmp('NUMFLD').getValue()
}
}
});


I don't think it redoes the extraParam value when you load unless you explicitly tell it to update.

dp_vl
7 Jul 2011, 12:42 PM
Thanks very much, Mailisa. That does it.

DP

stevil
9 Jul 2011, 6:41 PM
Mailisa's solution was correct, in terms of getting the current dynamic value before loading. However, your extraParams as specified should never have worked in the first place. You configured:




extraparams: polnum: Ext.getCmp('NUMFLD').getValue()



when it should have been:




extraParams: { polnum: Ext.getCmp('NUMFLD').getValue() }



Note the spelling, and formatting of extraParams as an object...
stevil

gmangrum
15 Sep 2011, 12:04 PM
Nice

mberrie
17 Sep 2011, 9:50 AM
@dp_vl

please mark the question as answered.