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

Issues regarding self-hierarchy grid (retrieving values, indenting detail rows)

3 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 23 Mar 2009, 02:11 PM
I've got a self-referencing hierarchical grid that displays the information as desired.  When the user clicks a row, s/he can then either view the row's details, reply to the thread or delete the thread.

The problem I'm having is capturing the Id of the selected row.  The Id is stored in the first column of the grid, which also contains the [+] button code (visible or not, depending on whether there's a child row).  For other columns, the following to retrieve the cell's contents as desired:

                        var rgGrid = $find("<%= grdNotes.ClientID %>");
                        var MasterTable = rgGrid.get_masterTableView();
                        var selectedRows = MasterTable.get_selectedItems();
                        for (var i = 0; i < selectedRows.length; i++)
                        {
                            var row = selectedRows[i];
                            var cell = MasterTable.getCellByColumnUniqueName(row, uniqueColName)
                            parentId = cell.innerHTML;
                        }                       

However, when the uniqueColName is the "Id" column, I also get back the HTML that creates the [+] button (when all I want is 21):

<input type="submit" name="ctl00$DetailBodyPlaceHolder$ucNotesGrid$grdNotes$ctl00$ctl10$MyExpandCollapseButton" value="" id="ctl00_DetailBodyPlaceHolder_ucNotesGrid_grdNotes_ctl00_ctl10_MyExpandCollapseButton" class="rgExpand" style="visibility:hidden;" />&nbsp;21

I've tried moving the button to its own column, but have been unsuccessful.

How can I read the Id value w/o getting the [+] code back as well?  Is there another property that will just return the value (e.g., 21)?

Also, how can I make the detail row line up with the parent row vs. being indented?

3 Answers, 1 is accepted

Sort by
0
Matt
Top achievements
Rank 1
answered on 24 Mar 2009, 04:09 PM
Alright, making progress.  For first level rows, I simply use the following on RowSelected:

function RowSelected(sender, eventArgs)
        {
            var noteId = eventArgs.getDataKeyValue("Id");
...

This gives me the noteId for the main table, however, for detail windows, noteId is set to NULL.

I've traversed the eventArgs parameter and can't find anything that displays the desired property (either as a property or returned via a method call).

Is there a way to simply make the same call (e.g., getDataKeyValue) on the detail table corresponding to the row to which the note belongs?  It doesn't seem like it should be this difficult.  What am I missing?!?



0
Matt
Top achievements
Rank 1
answered on 24 Mar 2009, 08:49 PM
I'm surprised this post wasn't answered in five minutes by one of the Telerik folk.  I can't be the only one who had issues in getting sub-table cell values...or am I the only one using self-hierarchical tables?  Whatever.

Anyway, Instead of using cell.innerHTML (as suggested elsewhere in other posts and in various demos) to get a cell's value, use cell.innerText (as shown below).  This will return ONLY the value displayed on the screen.  I added it to my RowSelected function and then store it in a hidden field for use later on as necessary.

        function RowSelected(sender, eventArgs)
        {
            var noteId = -1;
            
            var rows = eventArgs.get_tableView().get_selectedItems();    

            for (var i = 0; i < rows.length; i++)
            {
                var row = rows[i];
                var cell = eventArgs.get_tableView().getCellByColumnUniqueName(row, "Id");
                
                noteId = cell.innerText;
            }

            document.getElementsByName("hfldCurrentNoteId").value = noteId;
        }
 
This only works if you allow users to select a single row at a time.
0
D
Top achievements
Rank 1
answered on 16 Sep 2011, 07:26 PM
to perhaps save someone else a little time:  Please pay special attention to this line from Matt's very helpful post:  "This will return ONLY the value displayed on the screen. ".  I was attempting to do this with an Id field that I was not displaying in the RadGrid (visible="false").  Once I made this value visible, this method worked for me.  So, keep in mind, you can't get the innerHTML of a value that isn't displayed on the page.
Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
Matt
Top achievements
Rank 1
D
Top achievements
Rank 1
Share this question
or