Get total number of records in grid client side

5 posts, 0 answers
  1. Arni Gunnar Ragnarsson
    Arni Gunnar Ragnarsson avatar
    13 posts
    Member since:
    Jul 2007

    Posted 05 May 2009 Link to this post

    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; 
        } 

  2. Todd Anglin
    Todd Anglin avatar
    2040 posts
    Member since:
    Aug 2005

    Posted 05 May 2009 Link to this post

    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

  3. Arni Gunnar Ragnarsson
    Arni Gunnar Ragnarsson avatar
    13 posts
    Member since:
    Jul 2007

    Posted 06 May 2009 Link to this post

    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

  4. Todd Anglin
    Todd Anglin avatar
    2040 posts
    Member since:
    Aug 2005

    Posted 06 May 2009 Link to this post

    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

  5. Arni Gunnar Ragnarsson
    Arni Gunnar Ragnarsson avatar
    13 posts
    Member since:
    Jul 2007

    Posted 06 May 2009 Link to this post

    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

Back to Top