Dan Appleyard
Dan Appleyard

Reputation: 7445

Expand all items in RadGrid Hierarchy

I am using a RadGrid (2009 Q2) with a hierarchy. Is there a way in the client api to expand all rows and vice-versa?

thanks!

Update: I have written a javascript function based off the api documentation suggested by Dick Lampard below to expand/collapse all rows in a radgrid with three levels. It expands all the mastertableview rows and all the nested detailtableview rows in both sub levels of the first mastertableview row, but it breaks when it goes the to detailtableview rows for the second mastertableview row (whew!). The error I am getting is "_350 is undefined". This is coming from a Telerik.Web.UI.WebResource file.

function ExpandCollapseAll(expand) {
    var grid = $find("<%= rgHistory.ClientID %>");

    master = grid.get_masterTableView();
    var masterRowCount = master.get_dataItems().length;

    for (masterIndex = 0; masterIndex < masterRowCount; masterIndex++) {
        if (expand) {
            master.expandItem(masterIndex);
        }
        else {
            master.collapseItem(masterIndex);
        }
    } 

    var detailTables = grid.get_detailTables();
    var detailTableCount = detailTables.length;

    for (detailTableIndex = 0; detailTableIndex < detailTableCount; detailTableIndex++) {
        var detailTable = detailTables[detailTableIndex];
        var rowCount = detailTable.get_dataItems().length;
        for (rowIndex = 0; rowIndex < rowCount; rowIndex++) {
            if (expand) {
                //expandItem is failing!  detailTableIndex and rowIndex are correct
                detailTables[detailTableIndex].expandItem(rowIndex);
            }
            else {
                detailTables[detailTableIndex].collapseItem(rowIndex);
            }
        }
    }            
}

ANY IDEAS?!?!

Upvotes: 1

Views: 24836

Answers (4)

R.Akhlaghi
R.Akhlaghi

Reputation: 760

after radGrid.DataBind()

use this Mehtod

private void ExpanadAllRadGridNodes()
        {
            foreach (GridDataItem item_L1 in radgridQuestionGroups.MasterTableView.Items)
            {
                foreach (GridTableView item_L2 in (item_L1 as GridDataItem).ChildItem.NestedTableViews)
                {
                    foreach (GridDataItem item_L3 in item_L2.Items)
                    {
                        item_L3.Expanded = true;
                    }
                }
            }
        }

Upvotes: 0

Prasad kodumuri
Prasad kodumuri

Reputation: 41

Try This

protected void Page_PreRenderComplete() {   
 if (!Page.IsPostBack) {    
   foreach (GridItem item in MyGrid.MasterTableView.Controls[0].Controls) {      
      if (item is GridGroupHeaderItem)
        if (item.GroupIndex.ToString() != "0")
          item.Expanded = !item.Expanded;
    } 
  } 
}      

Upvotes: 0

user007
user007

Reputation: 1740

If you would like to see all the hierarchy levels, Set HierarchyDefaultExpanded to the MasterTableView and all the GridTableViews. See this link for more details.

Upvotes: 1

Dick Lampard
Dick Lampard

Reputation:

There is client API for hierarchy expansion as well as ExpandHierarchyToTop() server method. Check out this demo.

Dick

Upvotes: 3

Related Questions