English 中文(简体)
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?!?!

问题回答

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




相关问题
Discuss on Commercial Component libraries of silverlight

I am now looking forward to buy a component library of silverlight for increase the productivity. I find there are number of them. Telerik ComponentOne ComponentArt Infragistics Syncfusion I found ...

Telerik RadGrid: grid clientside pagination

I have a web service which returns me some data,I am massaging this data and using this as datasource for my radgrid (telerik). The datasource is quite large, and would like to paginate it. I found ...

Binding a radgrid to a tree like data structure

I have a structure that looks following Class TreeNode { public TreeNode Parent { get; } public IEnumerable<TreeNode> Children { get; } public . . . . } I want to bind this to a ...

IQueryable into a hierarchy

I currently have an IQueryable of Questions. In my Question object I have and "id" and a "parentId" which can be used to create a hierarchy. Currently, I bind a RadTreeView to the IQueryable of ...

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 ...

热门标签