开发者

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 = gri开发者_高级运维d.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?!?!


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

Dick


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.


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;
    } 
  } 
}      


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;
                    }
                }
            }
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜