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

7 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. Thomas
    Thomas avatar
    2 posts
    Member since:
    May 2017

    Posted 01 Sep 2017 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
    1653 posts

    Posted 05 Sep 2017 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. Thomas
    Thomas avatar
    2 posts
    Member since:
    May 2017

    Posted 05 Sep 2017 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 

  6. Nathan
    Nathan avatar
    2 posts
    Member since:
    Jan 2018

    Posted 06 Mar in reply to Stefan Link to this post

    Has this recently changed? I have been attempting to return the count of rows, but when i use the .data for the kendo grid the console return undefined.
  7. Stefan
    Admin
    Stefan avatar
    1653 posts

    Posted 08 Mar Link to this post

    Hello, Nathan,

    In general, the best place to take the number of items is on the dataBound event of the Grid as this will ensure that it will be available:

    http://dojo.telerik.com/oDawiDUf

    Regards,
    Stefan
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top