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

Problem getting correct rowIndex in Detail Table of Hierarchical Grid

1 Answer 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kelvin
Top achievements
Rank 1
Kelvin asked on 07 Feb 2012, 04:29 AM
Hi,

I have a simple hierarchical grid with a master table and a single detail table.  The desired behavior is when the user expands the master table row and clicks on a row in the detail table a js function is called etc.  All of this works fine except for the rowIndex is off by one.  The javascript I have is below...please note it is not the most efficient right now, I have it to this trying to figure out what is wrong.   In the 4th row of the script I originally had var row = DetailTable.get_dataItems()[dataItem.rowIndex]; but for the first row it was returning 1, second 2, etc. like it was 1 based.  I added a -1 to pull back the previous row and this works but not sure if that is the best approach.  Any thoughts on how I could better extract the 'UserID value from the detail table row the user double clicked on?

Thanks in advance,

K


function RowSelected(sender, eventArgs) {
 
     if (eventArgs.get_tableView().get_name() == "UserDetail") {
         var dataItem = $get(eventArgs.get_id());
         var DetailTable = eventArgs.get_tableView();
         var row = DetailTable.get_dataItems()[dataItem.rowIndex-1];  //I had to add -1 in order to return the correct row
         var cell = DetailTable.getCellByColumnUniqueName(row, "UserID");
         var IDu = cell.innerHTML
         $find("<%=RadAjaxPanel.ClientID%>").ajaxRequest("GoToDetails|" + IDu);
               return false;
     }
 }

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 08 Feb 2012, 01:28 PM
Hi Kelvin,

The RowIndex property is 1-based whereas the client-side grid data items collection is 0-based, so your indexing is correct and you are on the right track. However, instead of using the innerHTML of the cell element, I'd recommend that you add the UserID field to the ClientDataKeyNames of the detail table and then use the getDataKeyValue method of the dataItem object.

Hope it helps.
 
Greetings,
Tsvetoslav
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
Grid
Asked by
Kelvin
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or