This is a migrated thread and some comments may be shown as answers.

Get total number of records in grid client side

4 Answers 429 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Arni Gunnar Ragnarsson
Top achievements
Rank 2
Arni Gunnar Ragnarsson asked on 05 May 2009, 10:15 AM
Hi.

I am trying to count the number of records in a paged grid from client side. I can't see in the documentation this method for the GridTableView.

If the number of records is less than the pageSize, then I can use get_dataItems().length to find the number of rows, but that is too slow. Shouldn't there be a quicker way ?

This is the code I have now:
var masterTableView = $find(clientID).get_masterTableView(); 
 
if (masterTableView != null) { 
    var dataItems = masterTableView.get_dataItems(); 
    var pageCount = parseInt(masterTableView.get_pageCount()); 
    var pageSize = parseInt(masterTableView.get_pageSize()); 
 
    if (pageCount > 1) { 
        return dataItems.length 
    } else { 
        return dataItems.length; 
    } 

4 Answers, 1 is accepted

Sort by
0
Todd Anglin
Top achievements
Rank 2
answered on 06 May 2009, 04:59 AM
Hello Arni-

When doing server-side binding, I don't think there is a way to directly get the total items count client-side (other than getting a "approximate" count by calculating PageSize * PageCount). With client-side binding, though, you can usually get the total item count from the virtualItemCount property, like this:

var tableView = $find("RadGrid1").get_masterTableView();
var count = tableView.get_virtualItemCount();

I'm not certain that this property is not available with server binding, but I'm pretty sure it's only available when set directly with the count value during JS binding. Hope this helps.

-Todd
0
Arni Gunnar Ragnarsson
Top achievements
Rank 2
answered on 06 May 2009, 08:41 AM
Hi Todd, thanks for the quick reply.

I had already tryed the virtualItemCount() property, but with no success. I am doing serverside bindings, but updating the grids clientside, so their rowcount changes without me doing a whole page-load.

As it seems not doable right now, I ask that this be put in the roadmap for the Grid to be added later, I am definately not the only one wanting this feature.

.ág
0
Todd Anglin
Top achievements
Rank 2
answered on 06 May 2009, 03:29 PM
I'll definitely follow-up with the Grid Team and see if this is a feature that can be added. In the mean time, I expect you could easily do something manually that would give you access to this value client side. For example, during your server-side binding, you could store the Grid's total item count in a HiddenField and then access the value client-side with your JS. Or, you could register a StartupScript that would call a JS function that would use the "set_virtualItemCount()" to manually fill this property with your Grid's total item count. Once set, you could use the normal Grid client-side API for getting the ItemCount in your code.

Clearly, not as easy as automatic, but hopefully workarounds that can work in the meantime. Hope that helps.

-Todd
0
Arni Gunnar Ragnarsson
Top achievements
Rank 2
answered on 06 May 2009, 03:40 PM
Thanks again for the reply, good to know you will follow this up ...

There are definately workarounds, but as you say, not as simple as getting the total rowcount in the grid. We will definately figure something out ... :)

.ág
Tags
Grid
Asked by
Arni Gunnar Ragnarsson
Top achievements
Rank 2
Answers by
Todd Anglin
Top achievements
Rank 2
Arni Gunnar Ragnarsson
Top achievements
Rank 2
Share this question
or