tags:

views:

813

answers:

2

I am currently having trouble of reloading a json store with new parameters. Here is my store:

 newsletters = new Ext.data.JsonStore({
        url: '/newsletters/',
        root: 'results',
        fields: [
             'id',
             'body'
             'recipients'
        ],
        baseParams: { command: 'json', to: dateTo, from: dateFrom },
    autoLoad: true
    });

dateTo and dateFrom are initally empty strings ( '' ) and checking in firebug /newsletters is called with the correct parameters.

Now none of the following techniquest work:

Changing the values of dateTo and dateFrom then calling newsletters.reload() still calls the page with the parameters to and from being empty strings.

Calling newsletters.reload( { to: 'test1', from: 'test2' } ); still sees the parameters as empty strings.

Finally as from the manual I have tried:

lastOptions = newsletters.lastOptions;
Ext.apply(lastOptions.params, {
    to: 'test1',
    from: 'test2'
});
newsletters.reload(lastOptions);

This again does not request /newsletters with the updated parameters.

Any advice appreciated!

+1  A: 

From the docs, you can probably do :

store.setBaseParam('to', dateTo);

Now, if I understand correctly, you want your baseParams to be changed whenever dateTo and dateFrom are changed.

You could try :

var dateTo = '', dateFrom = '';

store.on('beforeload', function(s) {
    s.setBaseParam('to', dateTo);
    s.setBaseParam('from', dateFrom);
});

// This should work :
dateTo = 1;
dateFrom = 2;
store.load();
Drasill
A: 

You can actually pass params object to the load() method

newsletters.load({
  params: {to: 'test1', from: 'test2'}
})
Mchl