PDA

View Full Version : Why ListView gives o is undefined error with store.loadData?



nagarajan.bose
10 Jan 2011, 8:46 AM
Hi,
We are extending a listview and it works fine when I load the data directly from store. However I have a situation, where I need to make an AJAX call and load the data using store.loadData(Ext.decode(response.Text)), it fails with an error "o is undefined".

Working Code:


SearchResults = Ext.extend(Ext.list.ListView, {
id : 'lvresults',
singleSelect : true,
emptyText : '<div style="padding:5px;">No results to display</div>',
title : 'Search Results',
reserveScrollOffset : true,
hideHeaders : true,
fields : ['id', {
name : 'gdate',
type : 'date',
dateFormat : 'c'
}],
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.JsonStore({
url:"/data/json/mmmmm/xxxxx.json",
root : 'rows',
idProperty : 'id',
fields : this.fields
})
SearchResults.superclass.initComponent.apply(this);
},
listeners : {
render : function() {
this.bindStore(this.store);
this.store.load();
}
}// eo listeners
});
Ext.reg(logviewresults', SearchResults);


Fails to load using the below code:


Ext.Ajax.request({
url:"/data/json/mmmmm/xxxxx.json",
success : function(response) {
Ext.getCmp("lvresults").store.loadData(Ext.decode(response.Text))
//Ext.getCmp("lvresults").bindStore(Ext.getCmp("lvresults").store) -->Tried this too... no use
},
failure : function(response){
//TODO: Handle failures here
}
})


Can any one point us where we are failing.

Thanks for your time and help.

Regards,
Nagaraj

skirtle
10 Jan 2011, 4:08 PM
What is response.Text? Do you mean response.responseText?

mitchellsimoens
10 Jan 2011, 4:29 PM
And why are you using Ext.Ajax to load a Store when you can use JsonStore to do it all?

nagarajan.bose
10 Jan 2011, 4:56 PM
Thanks Skirtle and Mitchellsimoens for looking into my problem.

Skirtle: I inspected response.responseText and it contains JSON data. So I am clear here I am not doing anything wrong.

Mitchellsimoens: I have a requirement where I will be building the URL dynamically and make a call. Hence I am using AJAX to load the data and then to refill the store.

mitchellsimoens
10 Jan 2011, 4:59 PM
If the data is the same, you can use same store for multiple grids. Only problem is if you are going to filter one grid. I would still use a store and sync between the two.

skirtle
11 Jan 2011, 1:01 AM
@nagarajan.bose, in the code you posted you're using response.Text, not response.responseText.