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

Best way to get row index in javascript

3 Answers 199 Views
Grid
This is a migrated thread and some comments may be shown as answers.
staron
Top achievements
Rank 1
staron asked on 12 Dec 2008, 08:04 AM
Hi,
I'm trying to get a hold of the rowindex in javascript. I'm currently getting it by using code found in another post in this forum. However; when the grid has lots of rows, the code becomes very slow and sometimes even freezes the browser.
My current code:
function RowClick(sender, eventArgs) {  
    try {  
  
        sender.get_masterTableView().get_dataItems();  
        var selectedItem = sender.get_masterTableView().get_selectedItems()[0];  
        var index = selectedItem._itemIndexHierarchical;  
... 
Is there a better, more optimalized way to do this?

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 12 Dec 2008, 08:59 AM
Hello Staron,

To get the Item index of a first selected row:
.... 
    var index = sender.get_masterTableView().get_selectedItems()[0]._itemIndexHierarchical; 

It would be better to move the get_dataItems() method to GridCreated event.
function GridCreated(sender, args) 
    sender.get_masterTableView().get_dataItems(); 

Let me know if I missed something.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
staron
Top achievements
Rank 1
answered on 12 Dec 2008, 09:33 AM
Thanks for the reply,
Problem is that sender.get_masterTableView().get_dataItems kills performance on large datasets.
0
Daniel
Telerik team
answered on 12 Dec 2008, 09:59 AM
Hello Staron,

Thank you for the clarification.

For such scenarios you may extract the item index from the ID as shown below:
var selected = radGrid.get_selectedItems()[0]; 
var ids = selected.get_element().id.split("__"); 
alert("Selected index: " + ids[ids.length - 1]); 

I hope this helps.

Kind regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
staron
Top achievements
Rank 1
Answers by
Daniel
Telerik team
staron
Top achievements
Rank 1
Share this question
or