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

Expand/Collapse one or several rows

4 Answers 159 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Jürgen
Top achievements
Rank 1
Jürgen asked on 05 Apr 2013, 11:34 AM
Hello,

how to expand/collapse one or several rows/colums in codebehind?

Thanks in advance!

4 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 10 Apr 2013, 07:27 AM
Hello Jürgen,

I am not completely sure whether you want to expand/collapse hierarchy grid or a grid groups. If you want to expand/collapse hierarchy items you could hook OnPreRender event handler and loop through all items and set their Expanded property to true/false. Check out the following code snippet.
protected void gridView_PreRender(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
            {
                item.Expanded = true;
            }
        }
    }

If you want to expand/collapse grid groups you could use the same approach but instead looping through the RadGrid items you should loop through the GridGroupHeaderItem collection.
protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            foreach (GridGroupHeaderItem item in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
            {
                if (int.Parse(item.GroupIndex) % 2 == 0)
                {
                    item.Expanded = false;
                }
            }
        }
    }


Greetings,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Jürgen
Top achievements
Rank 1
answered on 16 Apr 2013, 11:32 AM
Hello Kostadin,

Thanks, it's working as expected.
0
Roman
Top achievements
Rank 1
answered on 15 Jul 2013, 07:36 AM
Hi,

This is not working for RadPivotGrid because RadPivotGrid do not have MasterTableView definition. Pasted code works for RadGrid, but not for RadPivotGrid. Is this possible for RadPivotGrid?
0
Kostadin
Telerik team
answered on 18 Jul 2013, 07:18 AM
Hello Roman,

Please review the following live example where only one of the column groups is expanded.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
PivotGrid
Asked by
Jürgen
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Jürgen
Top achievements
Rank 1
Roman
Top achievements
Rank 1
Share this question
or