Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Grid > Get total number of records in grid client side

Not answered Get total number of records in grid client side

Feed from this thread
  • Posted on May 5, 2009 (permalink)

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

    Reply

  • Posted on May 5, 2009 (permalink)

    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

    Reply

  • Say Hello to Telerik's PivotGrid for ASP.NET AJAX, Silverlight, WPF and WinForms. Now packed with OLAP support.
  • Posted on May 6, 2009 (permalink)

    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

    Reply

  • Posted on May 6, 2009 (permalink)

    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

    Reply

  • Posted on May 6, 2009 (permalink)

    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

    Reply

  • Say Hello to Telerik's PivotGrid for ASP.NET AJAX, Silverlight, WPF and WinForms. Now packed with OLAP support.

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Grid > Get total number of records in grid client side
Related resources for "Get total number of records in grid client side"

ASP.NET Grid Features  |  Documentation  |  Demos  |  Step-by-step Tutorial  ]