How do I get the total number of rows in a grid?

5 posts, 0 answers
  1. Elliot
    Elliot avatar
    59 posts
    Member since:
    May 2012

    Posted 27 Jun 2013 Link to this post

    I want to enable/disable menu items based on whether there are any rows in the grid.  How do I find if there are any rows?
  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2190 posts

    Posted 28 Jun 2013 Link to this post

    Hi Elliot,

     
    You can use the grid dataSource API methods to check if there is any records in the grid:

    var grid = $("#Grid").data("kendoGrid");
    var dataSource = grid.dataSource;
     
    //records on current view / page   
    var recordsOnCurrentView = dataSource.view().length;
    //total records
    var totalRecords = dataSource.total();
    Kind Regards,
    Vladimir Iliev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Antoine
    Antoine avatar
    2 posts
    Member since:
    May 2017

    Posted 01 Sep in reply to Vladimir Iliev Link to this post

    Hi, I'm also trying to get the number of rows to display it on the top of the page.
    So I did the thing you did, but both functions are returning 0 ...

    Here is my code : 

    var grid = $("#objectsGrid").data("kendoGrid");
    var dataSource = grid.dataSource;
     
    //records on current view / page  
    var recordsOnCurrentView = dataSource.view().length;
    //total records
    var totalRecords = dataSource.total();
     
    console.log(dataSource);
    console.log("totalRecords : " + totalRecords);
    console.log("recordsOnCurrentView : " + recordsOnCurrentView);

     

    And this is what I see in the Chrome console : 

    Can you help me ? Thank you 

  4. Stefan
    Admin
    Stefan avatar
    1394 posts

    Posted 05 Sep Link to this post

    Hello Antoine,

    Thank you for the example.

    After testing it, I can assume that this is a timing issue.

    I can suggest using an event which will be fired after the Grid is initialized or a large enough timeout:

    http://dojo.telerik.com/eWepO

    Regards,
    Stefan
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Antoine
    Antoine avatar
    2 posts
    Member since:
    May 2017

    Posted 05 Sep in reply to Stefan Link to this post

    It works great !

    I just increased the delay, because I have a lot of records in my grid.

    Thank you very much 

Back to Top