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

1 Answer 19500 Views
Grid
Elliot
Top achievements
Rank 1
Elliot asked on 27 Jun 2013, 02:34 PM
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?

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 28 Jun 2013, 07:27 AM
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!
Thomas
Top achievements
Rank 1
commented on 01 Sep 2017, 08:52 AM

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 

Stefan
Telerik team
commented on 05 Sep 2017, 05:29 AM

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.
Thomas
Top achievements
Rank 1
commented on 05 Sep 2017, 08:26 AM

It works great !

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

Thank you very much 

Nathan
Top achievements
Rank 1
commented on 06 Mar 2018, 03:37 PM

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.
Stefan
Telerik team
commented on 08 Mar 2018, 08:09 AM

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.
Tags
Grid
Asked by
Elliot
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or