PDA

View Full Version : Problem getCount or getTotalCount in a store



marxan
24 Nov 2010, 6:07 AM
Hi,

I want to display in the grid's title the number of record of my grid. But it seems that the getTotalCount keeps the store size before the reload... I've read some explanation that we should use getCount but getCount always returns me 0.


var ProjectGridWarning = Ext.getCmp('ProjectGridWarning');
ProjectGridWarning.store.removeAll();
ProjectGridWarning.store.reload({
params: {phase: phase,directorate:directorate,unit:unit}
});
nbRecord= ProjectGridWarning.store.getTotalCount();
ProjectGridWarning.setTitle('Warnings ('+nbRecord+')');


Thanks to explain me why it's behaving like that.

Marxan

Animal
24 Nov 2010, 7:25 AM
Important: loading is asynchronous! This call will return before the new data has been loaded. To perform any post-processing where information from the load call is required, specify the callback function to be called, or use a a 'load' event handler.


 

marxan
25 Nov 2010, 12:55 AM
Below the good code :-)


var ProjectGridWarning = Ext.getCmp('ProjectGridWarning');
ProjectGridWarning.store.removeAll();
ProjectGridWarning.store.reload({
params: {phase: phase,directorate:directorate,unit:unit}
});

ProjectGridWarning.getStore().on('load', function() {
var count = ProjectGridWarning.getStore().getCount();
ProjectGridWarning.setTitle('Warnings ('+count+')');
});

Animal
25 Nov 2010, 1:04 AM
If you execute that reload more than once, it looks like you are going to add a load listener each time!

marxan
25 Nov 2010, 1:26 AM
If you execute that reload more than once, it looks like you are going to add a load listener each time!


I execute the reload each time I select a value on a combo Box, So I guess I also need to call the listener each time to get the refreshed totalcount of my store.

Animal
25 Nov 2010, 3:01 AM
Think.

You ADD.

ADD a listener each time.

So you add a new listener.

Each time. Add one. Can you see?