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

[Solved] Row Count-Getting Close

2 Answers 221 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Philip
Top achievements
Rank 1
Philip asked on 09 Feb 2008, 01:02 AM
I'm getting close on this, but I just can't seem to make the final step.

I have a label outside my grid that I want to populate with the number of rows in the grid via client-side scripting.

I have my ClientSettings defined with:

<Selecting AllowRowSelect="true" /> 
<ClientEvents onGridCreated="GridCreated" /> 

I have a JavaScript with the following:

function GridCreated(sender, eventArgs)  
{  
    var label = document.getElementById('ctl100_MainContent_gridCount');  
    var grid = sender.get_masterTableView();  
    label.innerHTML = grid.get_pageCount();  

The reason I have get_pageCount() in there was just to make sure I could populate the label. What I want to put in that label is the number of rows in the grid.

I found previous examples of people using Rows.length or MasterTableView.Rows.length, but these throw an error. I think they may have been for the non-Promethius version of the grid.

Can anyone point me in the right direction to get this number? Can I loop through the grid rows somehow to count them or is there any property I can access that will give me what I'm looking for? I need this to be client side so that I can update the row count when a record is added or deleted. Thanks.

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 11 Feb 2008, 09:48 AM
Hi Philip,

Here is an example how to achieve this:

var count = sender.get_masterTableView().get_dataItems().length;

you can populate this without call to get_dataItems() method:

var count = <%= RadGrid1.Items.Count %>;

Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Philip
Top achievements
Rank 1
answered on 11 Feb 2008, 05:00 PM
You the man!

var count = sender.get_masterTableView().get_dataItems().length;

worked perfectly! Thanks!!!
Tags
Grid
Asked by
Philip
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Philip
Top achievements
Rank 1
Share this question
or