This is a migrated thread and some comments may be shown as answers.

Total Row Count

8 Answers 216 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Haroon Khokhar
Top achievements
Rank 1
Haroon Khokhar asked on 17 Sep 2009, 06:17 AM
Hi All,

Is there any function available that can get the total number of rows in a Grid on the Client side using Javascipt.

Thanks in advance,

Haroon

8 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 17 Sep 2009, 06:44 AM
Hi Haroon,

Try the following client side code in order to get the number of items in grid.

JavaScript:
 
<script type="text/javascript"
function RowCount() 
    var grid = $find("<%=RadGrid1.ClientID %>"); 
    var MasterTable = grid.get_masterTableView(); 
    var Rows = MasterTable.get_dataItems(); 
    alert(Rows.length); 
</script> 

-Shinu.
0
Haroon Khokhar
Top achievements
Rank 1
answered on 18 Sep 2009, 04:40 AM
Thanks Shinu

It worked :)



0
Najah
Top achievements
Rank 1
answered on 16 Mar 2010, 05:14 PM
Hi,

If I have multiple pages in the grid, the script gives the number of rows for the first page only.

Is there a way to count the number of rows in all the pages of the grid?

Thanks
Sana
0
Yavor
Telerik team
answered on 18 Mar 2010, 02:29 PM
Hello Sunny,

Tha number of items in this manner will indeed reflect only the total for the current page.
If you would like to get all the items in the control, you can use the datasource selected event:

protected void AccessDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
    {
        int totalItems = e.AffectedRows;
    }

If you are using the NeedDataSource event handler, you can also access the total rows in the datatable which is passed as a datasource for the grid.
Alternatively, you can also query the datasource via a separate query/statement, to retrieve the total number of items.
I hope this information helps.

Kind regards,
Yavor
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Brian Azzi
Top achievements
Rank 2
answered on 12 May 2010, 09:52 PM
Ok... this is really frustrating me as well. I have paging turned off... and no matter what, get_dataItems().length always == the default page size (11)... NOT the actual count of rows that I bound (via client binding) to the grid (say 2 or 3 rows). Basically, are you saying that there is no way at all to determine how many rows of data were bound to the grid from the client without going directly back to the data source (which is accessed on the server).... ?


0
Yavor
Telerik team
answered on 13 May 2010, 07:59 AM
Hello Brian,

The get_dataItems().length property will work as expected when binding the control on the server.
When binding the grid on the client,  you can use a different approach instead. Since the data is fetched by a page method, you can populate a hidden input on the page, holding the count of all the items on the page. This can later be accessed on the client. Give this suggestion a try and let me know how it goes.

Regards,
Yavor
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Brian Azzi
Top achievements
Rank 2
answered on 13 May 2010, 01:52 PM
Yes, I can store the data length at bind time... for my purposes, I can do this by storing the size of the client data set prior to binding in a local javascript variable... so I can definitely work around this. BUT... my point is that I shouldn't have to... that's just more coding that I (and my team) need to remember to do everywhere they want to access a relatively common property. I would consider adding this to the client API.... its certainly confusing that the get_dataItems() client API method actually returns rows that are not "really" rows as well... this can cause problems when trying to iterate through the entire dataset / rowset. I understand that from the client perspective its returning a "page"... or essentially the actual table that is rendered, but I'm just not sure this is the best behavior.
0
Yavor
Telerik team
answered on 14 May 2010, 08:14 AM
Hi Brian,

Indeed, this is a good point. This is a limitation in the present binding mechanism of the control, due to the way it is initialized on the client, in order to achieve better performance and responsiveness. Nevertheless, we will consider removing this limitation for one of the upcoming versions of the control, and enhancing the client-side databinding model. At present, I hope that the workaround supplied is a suitable alternative.

Greetings,
Yavor
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Haroon Khokhar
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Haroon Khokhar
Top achievements
Rank 1
Najah
Top achievements
Rank 1
Yavor
Telerik team
Brian Azzi
Top achievements
Rank 2
Share this question
or