PDA

View Full Version : Help. getTotalCount() is empty. Why???



TTT
17 Jun 2008, 10:59 PM
have a simple code:

var GridUI = function() {
var list_ds;
var list_grid;
var list_columnModel;
var list_gridForm;
var list_count;
function list_buildGrid() {
list_ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:'/cgi-bin/profiles/get_table.cgi'}),
reader: new Ext.data.JsonReader(
{root: 'data',totalProperty: 'count'},
[
{name: 'ID_GLOBAL',type:'int'},
{name: 'comp_name',type:'string'}
]
)
});
list_ds.load();
if(!list_columnModel) {
list_columnModel = new Ext.grid.ColumnModel(
[
{
header:'ID',
dataIndex:'ID_GLOBAL',
sortable:true,
width:50
},
{
header:'Comp_name',
dataIndex:'comp_name',
sortable:true,
width:195,
css:'white-space:normal;'
}
]
);
}
list_grid = new Ext.grid.EditorGrid('list',
{
ds:list_ds,
cm:list_columnModel,
autoExpandColumn:'1',
enableColLock:false,
selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
loadMask: true
}
);
list_grid.render();
var list_gridHeaderPanel = list_grid.getView().getHeaderPanel(true);
var list_tb_top = new Ext.Toolbar(
list_gridHeaderPanel,
[
{
text: 'Count:' + list_ds.getTotalCount() + '.', // #1
handler: function(){
alert(list_ds.getTotalCount()); // #2
}
}
]
);
alert(list_ds.getTotalCount()); // #3
}
return {
init : function() {
list_buildGrid();
}
}
} ();
Ext.onReady(GridUI.init, GridUI);

#1 and #3 shows zero, but when pressed the button (#2) popup shows the current number of loaded rows. Why?

evant
17 Jun 2008, 11:40 PM
Think about it.

It takes a while for the store to load, it has to make a request to the server.

By the time 1 & 3 run, it won't have finished yet.

By the time you click on the button, it will have loaded.

TTT
17 Jun 2008, 11:51 PM
Ok
and how to make the following: while the store is loaded - show the current rows in store

evant
18 Jun 2008, 12:02 AM
Look at the store documentation, the 'load' event.

TTT
18 Jun 2008, 9:52 AM
Thanks, its work