PDA

View Full Version : How to set Dynamic URL to the store?



msuresh
27 Dec 2010, 6:32 AM
Hi,
I have a list view, which should be loaded after user searches a form. Initially I am not setting the URL, however after the search I need to change the URL. I am using ExtJs 3.3 and trying to use setUrl, however it is not working as expected.

Please let me know where i am making a mistake.



UTP.logview.SearchResults = Ext.extend(Ext.list.ListView, {
id : 'lvresults',
multiSelect:false,
emptyText: 'No results to display',
style:{padding:'5px'},
title : 'Search Results',
reserveScrollOffset: true,
hideHeaders:true,
fields:['id',{name: 'gdate', type: 'date', dateFormat:'timestamp'},'url'],
columns: [{
dataIndex : 'gdate',
xtype: 'datecolumn',
format: 'D M d Y, G:i T'
}],
initComponent : function() {
this.tpl = new Ext.XTemplate('<tpl for="rows">',
'<dl class="x-grid3-row {[xindex % 2 === 0 ? "" : "x-grid3-row-alt"]}">',
'<tpl for="parent.columns">',
'<dt style="width:{[values.width*100]}%;text-align:{align};">',
'<em unselectable="on"<tpl if="cls"> class="{cls}"</tpl>>{[values.tpl.apply(parent)]}',
'</em></dt></tpl><div class="x-clear"></div></dl></tpl>'
)

this.store = new Ext.data.Store({
proxy : new Ext.data.DataProxy({
//url:'/data/json/logview/clvresults.json',
method : 'GET'
//autoLoad:true
}),
reader : new Ext.data.JsonReader({
root : 'rows',
idProperty : 'id',
totalProperty : 'totalCount',
fields : this.fields
})
});
UTP.logview.SearchResults.superclass.initComponent.apply(this);
},
listeners : {
/**
* First time rendering.
*/
render : function() {
this.bindStore(this.store);
}
}// eo listeners
});

//Then from Firebug i tried this, but didn't work
var store = Ext.getCmp("lvresults").getStore();
store.proxy.setUrl('/data/json/logview/clvresults.json'); //Not at all setting, says Undefined
store.load();



Thanks.
Suresh

Condor
27 Dec 2010, 6:35 AM
You can't set the url of a DataProxy. You want a HttpProxy instead!

msuresh
27 Dec 2010, 6:45 AM
I changed new Ext.data.DataProxy to new Ext.data.HttpProxy, however I am receiving the following error when i execute.
Now, no where I am using DataProxy, I cleared cache also...

Error: Ext.data.DataProxy: DataProxy attempted to execute an API-action but found an undefined url / function. Please review your Proxy url/api-configuration. { arg="read", more...}



var store = Ext.getCmp("lvresults").getStore();
store.proxy.setUrl('/data/json/logview/clvresults.json');
store.load();

msuresh
27 Dec 2010, 6:55 AM
Class Ext.data.HttpProxy extends DataProxy, so what the firebug is showing is valid. But where I am doing wrong to get an error message

Ext.data.DataProxy: DataProxy attempted to execute an API-action but found an undefined url / function. Please review your Proxy url/api-configuration. { arg="read", more...

even after changing to Ext.data.HttpProxy

Condor
27 Dec 2010, 9:59 AM
Are you sure you are not calling load() (or using autoLoad:true) before you set an url?