View Full Version : Record Count

2 Jan 2010, 1:50 PM
I'm still learning so please bear with me. I am loading an XML file from the server with 195 records of data. I put this into a grid and I can see the data. I also have a statusbar which I would like to show the total number of records. Right now I am just using console.log() to try and get this information but with no luck. I thought this came directly from the Ext.XML.Reader can someone help me out?

2 Jan 2010, 9:04 PM

3 Jan 2010, 2:52 PM
Trying this I get an error that grid is not defined? Not sure why this would be. I am using a FormGrid, actually the one from the examples. Any ideas?

david l
3 Jan 2010, 3:08 PM
are you using the same variables as the example?

if so, use gridForm.getStore().getCount()

3 Jan 2010, 4:15 PM
Yes, I am using the same variables as the example did. The error I get now says - gridForm.getStore is not a function. Is there anything that could affect this in the XML reader perhaps?

david l
3 Jan 2010, 6:00 PM
sorry about that, i was looking at the wrong variable...

it should be ds.getCount();

3 Jan 2010, 6:47 PM
Hi David -
I have this working sort of. I have assigned a variable like this -

var tot_recs = ds.getCount();
console.log("Number of records:" + tot_recs);

But it only works when I run this from a button click function. I am assuming that the datastore has not actually loaded in time for this to work for some reason. Shouldn't this work after the ds.load() function?

Mike Robinson
4 Jan 2010, 7:41 AM
The data is available only after the 'load' event fires. You do not know, per se, when that will be.

In particular, a call like "ds.load()" only initiates the request ... "fills out the postcard and drops it in the mailbox," if you will. There's an indeterminate amount of time that will pass between the request and the subsequent response.

To finish my crappy analogy: "on the postcard that you dropped into the mailbox you wrote down two phone-numbers: one to call if the request succeeded; another to call if it failed." Eventually, one or the other phone will ring. You don't sit around spinning your wheels waiting for the bell. Instead, you arrange in advance what should happen in each case. Then you go on about your business. Eventually, the "success" phone will ring, and then you will know the record-count.

4 Jan 2010, 9:34 AM
Hi Mike -
I like your analogy. I am finding it difficult to find all of this information. So I create my datastore (ds) then call the ds.load() function and then check to see that the data is loaded befroe using the getCount() function - this makes good sense. So how do I check to see when the data is loaded? (phone #2 call) Is this a property in the Ext.data.Store() ?

4 Jan 2010, 9:57 AM
Mike -
I have this working now. I am using the following code -

ds.on('load', function(){
Ext.MessageBox.alert('Total records', 'Total: ' + ds.getCount());
But when I assign the count to a variable on my status bar it doesn't work. I think the status bar is expecting text and this returns a number. Is there an easy way to fix this?

4 Jan 2010, 10:18 AM
//bbar in object construction
bbar: ['<span id=\'total\'>Total:</span>']

ds.on('load', function(){
Ext.get('total').update('Total: ' + ds.getCount());

4 Jan 2010, 10:27 AM
Hi dlbjr -
Thanks! I have it working now. The Status bar that I am using is different but your code solved the issue! Thanks for your help and all the others that have helped as well!

Mike Robinson
4 Jan 2010, 3:07 PM
Look at the displayMsg property of PagingToolbar. This is the template that is normally used to display the current record-position as well as the record count. Once the data store has this information available, the PagingToolbar should automagically pick it up.

I find with ExtJS that "there's one right way to do it," and that's the way it should be done. Don't "get jiggy wid' it." Skip the special effects. Do it exactly like the demos do... those have been well-tested and they look acceptable. (After all, ExtJS is designed for building the "boring stuffy corporate-looking web apps" of which this world is so stuffed. 8-| Visual creativity does not get high marks in "apps like that" ... but "apps like that" pay well.)