PDA

View Full Version : Xmlstore URL change fails as params are undefined



Raymi
26 Oct 2010, 12:19 AM
Hi,

I am new to ExtJS so if the question looks to be silly I apologies...

I am trying to reload an XML store depending on some input from the user: In the URL, depending on dates selected by the user, a set of data being in the range of 'from' and 'to' must reloaded and displayed into a GridPanel.

I've been tring a lot of stuff; having read this FAQ (http://www.sencha.com/learn/Ext_FAQ_Grid#Reload_a_Grid_from_a_different_URL.3F), I now get a strange error with the code below:

The store code:

MyStore = Ext.extend(Ext.data.XmlStore, {
constructor: function(cfg) {
cfg = cfg || {};
MyStore.superclass.constructor.call(this, Ext.apply({
storeId: 'MyStore',
url:'/xds_index.html?$Command&Section=Log&From=19800101000000&To=20991231235959',
record: 'Record',
autoSave: false,
autoLoad: true,
autoDestroy: true,
fields: [
{
name: 'FieldID',
mapping: 'Field[@Name=\'pk\']'
},
{
name: 'FieldDT',
mapping: 'Field[@Name=\'log_datetime\']'
},
{
name: 'FieldTP',
mapping: 'Field[@Name=\'log_type\']'
},
{
name: 'FieldMSG',
mapping: 'Field[@Name=\'log_message\']'
}
],
}, cfg));
}
});
new MyStore();The code to update the store:

var store_url = '/xds_index.html?$Command&Section=Log&From=' + Ext.getCmp
('From_Date').getValue() + '&To=' + Ext.getCmp('To_Date').getValue();

Ext.getCmp('MyGrid').getStore().proxy.conn.url = store_url;
Ext.getCmp('MyGrid').getStore().proxy.doRequest();
Executing the code, Firebug displays the following:
params is undefined
if (params.jsonData) {

ext-all-debug.js (line 24997)

What am I doing wrong?

Many thanks for your help.

KR
Raymi

raj_plays
26 Oct 2010, 2:31 AM
Change your store config to


MyStore.superclass.constructor.call(this, Ext.apply({
storeId: 'MyStore',
url:'/xds_index.html' (http://www.sencha.com/forum/'/xds_index.html'),
baseParams: {params: '$Command&Section=Log&From=19800101000000&To=20991231235959'},
record: 'Record',
autoSave: false,
autoLoad: true,
autoDestroy: true,
fields: [
{
name: 'FieldID',
mapping: 'Field[@Name=\'pk\']'
},
{
name: 'FieldDT',
mapping: 'Field[@Name=\'log_datetime\']'
},
{
name: 'FieldTP',
mapping: 'Field[@Name=\'log_type\']'
},
{
name: 'FieldMSG',
mapping: 'Field[@Name=\'log_message\']'
}
],
}, cfg));


However if you want to pass params dynamically, use store.load({params: {}})

Raymi
26 Oct 2010, 6:47 AM
Thanks for your answer.

Indeed, using [baseParams] enables at least the first call.

But when using load({params: {}} I get now another error:

var log_store = Ext.StoreMgr.lookup('MyStore');
var store_url = '$Command...';

log_store.load({params: {store_url}});invalid object initializer

I tried with reload with resulting error.

I must miss something...

Raymi
26 Oct 2010, 7:05 AM
Moreover, I just noticed the call is using POST method whereas I absolutely need GET...

Argh just get the feeling running around the bush :-)

raj_plays
26 Oct 2010, 8:22 AM
The usage of load() is wrong.
It should be


store.load({params: {start: 0, limit: pageSize}});


For GET, configure your store with a proxy...


var Grid1DataStore = new Ext.data.Store({

proxy: new Ext.data.HttpProxy({url: 'index.html', method: 'GET'}),

reader: new Ext.data.XmlReader({
record: 'Table',
totalProperty: 'total',
idProperty: 'id'
}, Record1)
});

Raymi
26 Oct 2010, 12:56 PM
Great, thanks for the recommendations.

It is ok as I don't get any errors. However, I would like to clearly understand what is happening.

Looking in Firebug at what is being passed:
with baseParams:

http://win2k8_srv/xds_index.html?_dc=1288124728138&params=%24Command%26Section%3DLog%26From%3D19800101000000%26To%3D20991231235959

with store.load({params{'From': fvalue, 'To': tvalue}});

http://win2k8_srv/xds_index.html?params=&From=20101025000000&To=20101025235959%24Command%26Section%3DLog%26From%3D19800101000000%26To%3D20991231235959

So it looks like with .load({params{}}) does not replace existing params but appends new ones. Is it right or is it because of url encoding (?) in such case how to solve then?

Thx again

raj_plays
27 Oct 2010, 12:21 AM
It should be


store.load({params{From: fvalue, To: tvalue}});

Raymi
27 Oct 2010, 7:17 AM
Actually, does not change anything... The result is that existing params are not replaced but readjusted params are added, whatever I am using quotes or not.

raj_plays
27 Oct 2010, 8:27 AM
store.load does not append params, it creates fresh key value-pairs

Raymi
28 Oct 2010, 1:18 AM
OK. I think I grabbed the right way for achieving...

What I was doing:

autoLoad: true,
baseParams: {params: {'$Command&Section=Log&From=19800101000000&To=20991231235959'}}, //to set default parameters to the store
...
store.load({params: {From: fvalue, To: tvalue}});//fvalue=20101025000000, tvalue=20101025235959The resulting URL call being after store.load

...?params=&From=20101025000000&To=20101025235959%26params%3D%24Command%26Section%3DLog%26From%3D19800101000000%26To%3D20991231235959where From and To parameters are referenced twice:

%26From%3D19800101000000 AND &From=20101025000000
%26To%3D20991231235959 AND &To=20101025235959First parameters being url encoded but actually meaning the same when decoded... (Note that even params is referenced twice)

What I am doing now:

autoLoad: false,
baseParams: {params: {'$Command&Section=Log'}}, //to set default parameters to the store
...
store.load({params: {From: fvalue, To: tvalue}});//fvalue=20101025000000, tvalue=20101025235959The resulting URL call being after store.load

...?params=&From=20101025000000&To=20101025235959%26params%3D%24Command%26Section%3DLogwhere params keeps referenced twice but ok...

Many thanks for your help!

Cheers,
Raymi