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

How to get detail table client id on the OnHierarchyCollapsed/OnHierarchyExpanded

2 Answers 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sudhir singh
Top achievements
Rank 1
sudhir singh asked on 05 May 2010, 06:52 AM
Hi,
I have a grid with 3 level hierarchy. I wanted to get the client id of the expaned/collapsed detailtable when the expand/collapse image button is clicked.The detailtable just below the button expanded/collapse.
I can get this work for two level by the following code
 <ClientSettings AllowExpandCollapse="True"
                                <ClientEvents OnHierarchyCollapsed="Collapsed" /> 
                                <ClientEvents OnHierarchyExpanded="Expanded" /> 
</ClientSettings> 
 
<script type="text/javascript" language="javascript"
 
    function Collapsed(sender, eventArgs) { 
        var radgrid = sender
        var detailTablesArray = radgrid.get_detailTables(); 
        document.getElementById(detailTablesArray[eventArgs.get_itemIndexHierarchical()]._data.ClientID).style.display = "none"
 
    } 
 
    function Expanded(sender, eventArgs) { 
        var radgrid = sender
        var detailTablesArray = radgrid.get_detailTables(); 
        document.getElementById(detailTablesArray[eventArgs.get_itemIndexHierarchical()]._data.ClientID).style.display = "inline"
 
    } 
</script> 



But  incase of 3 level hierarchy i get the value of "eventArgs.get_itemIndexHierarchical()" for the level two "expand/collapse" click as something like "2:0_2" and hence not able to index the detailtable array.
I need to do this for totally different issue though it seems from code above that i am just hiding / showing the detail table. All i need is the client id for the detailtable for the expanded/collapsed row.

Appreciate any help on this.
Thanks,
Sudhir.

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 May 2010, 07:28 AM

Hi Sudhir,

You can access the expanded/collapsed detailtable from the eventArgs object of the event. Here is an example.

JavaScript:

 
<script type="text/javascript">  
    function OnHierarchyExpanded(sender, args) {  
        var detailTable = args.get_gridDataItem().get_nestedViews()[0];  // get_gridDataItem() is not directly available on the client unless OnRowCreating/OnRowCreated events are hooked up.
        alert(detailTable.get_dataItems().length);  
    }  
    function OnHierarchyCollapsed(sender, args) {  
        var detailTable = args.get_gridDataItem().get_nestedViews()[0];  
        alert(detailTable.get_dataItems().length);  
    }  
    function OnRowCreated(sender, args) {  
    }  
</script> 

-Shinu.

0
sudhir singh
Top achievements
Rank 1
answered on 05 May 2010, 03:51 PM
Hi Shinu,
This worked like charm.
Thanks a million,
Cheers Sudhir.
Tags
Grid
Asked by
sudhir singh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
sudhir singh
Top achievements
Rank 1
Share this question
or