PDA

View Full Version : [SOLVED] emptyText doesn't show up in grid when using autoLoad and data



PranKe01
13 Feb 2010, 6:42 AM
Hi guys,

the JsonStore doesn't fire the load-event. I tried to insert a grid as a tab and to show an emptyText if there were no records. But the text is not showed.


var ds = new Ext.data.JsonStore({
autoLoad: true,
autoDestroy: true,
autoSave: false,
data: data,
root: 'root',
idProperty: 'ID',
fields: fields,
sortInfo: {
field: 'ID',
direction: 'DESC'
}
});
ds.on('load', function(){alert("ok");});

var selModel = new Ext.grid.RowSelectionModel({
singleSelect:true
});

var view = new Ext.grid.GridView({
emptyText: 'Empty!',
forceFit: true
});

var grid = new Ext.grid.GridPanel({
title: title,
id: itemid,
ds: ds,
cm: colModel,
sm: selModel,
view: view,
closable: true,
border: false,
columnLines: true,
viewConfig:{
forceFit: true
}
});

grid.on('rowdblclick', gridDblClickRow, this);
grid.on('rowcontextmenu', gridRightClickRow, this);

tabs.add(grid);

The alert is also not showing up :-?

fay
13 Feb 2010, 11:21 AM
Is the "data" that you're specifying in your JsonStore valid JSON? (And are the "fields" valid?) - You haven't displayed them here.

Add a loadexception handler for ds to see what error is being reported.

Also, why create a separate GridView, when you can specify emptyText in viewconfig?

PranKe01
13 Feb 2010, 11:39 AM
Hi fay,

thanks for your answer! I removed the GridView and used the viewConfig instead. The JSON is empty ( {} ) and when I inserted following code, I didn't get any alert:

ds.on('load', function(){alert("load");});
ds.on('loadexception', function(){alert("loadexception");});

I add the GridPanel to a TabPanel - maybe this is the problem?

PranKe01
14 Feb 2010, 11:27 PM
Hi fay,

the JSON is valid - it's empty and looks like this: {}
When adding a loadexception listener, wether the load nor the loadexception lsitener will be called :-o
I also removed the view and put all in the viewConfig - no results :-?

makana
15 Feb 2010, 12:02 AM
Hey Pranke!
It's just that simple:
Configure your GridPanel with the store!

PranKe01
15 Feb 2010, 12:06 AM
I do so!?

var grid = new Ext.grid.GridPanel({
title: title,
id: itemid,
ds: ds,
...
columnLines: true
});

makana
15 Feb 2010, 12:16 AM
Come on, that are basics...
http://www.extjs.com/deploy/dev/docs/?class=Ext.grid.GridPanel&member=store


var grid = new Ext.grid.GridPanel({
title: title,
id: itemid,
store: ds,
...
columnLines: true
});

~o)

PranKe01
15 Feb 2010, 12:25 AM
Of course it is ;) I use ds, which is the short hand for store :D
ds: ds == store: ds

Anyway, I tried changing ds to store, but it still does not show up.

But when I call the loadData function of the Store after the grid is shown, the emptyText is hown :-?

Edit: I added the following code to the store and now it shows up "ok":

listeners: {
load: function(){alert("ok");},
loadexception: function(){alert("oh");}
}

makana
15 Feb 2010, 12:35 AM
Ah, yes... ds isn't documentated... sorry for that.

Your inline data is loaded into the store before the ds.on('load'... is called and before the grid is initialized... If you configure your store with listeners, these are applied to the store before the inline data is loaded...

You have two possibilities:
- don't configure your store with data. and call
store.loadData(data); after all the code above.
- configure your gridview with
deferEmptyText:false, which does only the right result, if your data is always empty.

bclinton
15 Feb 2010, 12:44 AM
In the docs for the autoLoad option of the JsonStore, it says:


If data (http://www.extjs.com/forum/../deploy/dev/docs/output/Ext.data.Store.html#Ext.data.Store-data) is not specified, and if autoLoad is true or an Object, this store's load (http://www.extjs.com/forum/../deploy/dev/docs/output/Ext.data.Store.html#Ext.data.Store-load) method is automatically called after creation.

Could it be that since you are specifying the 'data' config option, autoLoad: true doesn't call the load method which would trigger your load event handler?

PranKe01
15 Feb 2010, 12:46 AM
I could have sworn, that I tried the deferEmptyText! Damn - now it works :) Maybe it does not work, because I got a viewConfig and a view at that time.

Thanks!

PranKe01
15 Feb 2010, 12:48 AM
@bclinton: I inserted the load-listener to the store and it was called. But I think, that it was called, before the grid was initialized/rendered...