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

Grid Group Problem

3 Answers 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
fareedha
Top achievements
Rank 1
fareedha asked on 18 Aug 2010, 06:36 PM
Hi,

I have implemented grouping feature for my rad grid. I set by default ExpandGroup as false so the all grouped cols are collapsed after grid loaded.
After that i did expanded some group columns and fortunately a button is clicked in then page and postback occurs. after post back again those grouped columns are collapsed. but i need those expanded items to be maintained.

Please give the solution to solve this issue. hope my explanation reaches the problem i am facing,

thanks

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Aug 2010, 02:05 PM
Hello Fareedha,

You can try the following code snippet to achieve this.

C#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
   {
       ArrayList expandedItems;
       if (Session["expandedItems"] == null)
       {
           expandedItems = new ArrayList();
       }
       else
       {
           expandedItems = (ArrayList)Session["expandedItems"];
       }
       if (e.CommandName == "ExpandCollapse" )
      {
           GridGroupHeaderItem headerItem = (GridGroupHeaderItem)e.Item;
           if (!headerItem.Expanded)
           {
               string groupIndex = Convert.ToString(headerItem.GroupIndex);
               expandedItems.Add(groupIndex);
               Session["expandedItems"] = expandedItems;
           }
           else
           {
               string groupIndex = Convert.ToString(headerItem.GroupIndex);
               expandedItems.Remove(groupIndex);
               Session["expandedItems"] = expandedItems;
           }
       }
      
   }
   protected void RadGrid1_PreRender(object sender, EventArgs e)
   {
       if (Session["expandedItems"] != null)
       {
           ArrayList expandedItems = (ArrayList)Session["expandedItems"];
           Int16 stackIndex;
           for (stackIndex = 0; stackIndex <= expandedItems.Count - 1; stackIndex++)
           {
               string curItem = expandedItems[stackIndex].ToString();
               foreach (GridGroupHeaderItem item in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
               {
                   if (curItem.Equals(item.GroupIndex.ToString()))
                       {
                           item.Expanded = true;
                           break;
                       }
                }
           }
       }
   }

Also please take a look at the following Code Library which illustrates how to persist group expanded state on rebind.
Persist Groups Expanded State on Rebind

Thanks,
Princy
0
fareedha
Top achievements
Rank 1
answered on 21 Aug 2010, 01:08 PM
i need a solution from the client side script. i set the grouploadmode='client'.when i postback grid in collapsed mode and i cant maintain the expandedgroupitems state.
if u have a solution please reply...


thanks in advance....
0
Maria Ilieva
Telerik team
answered on 26 Aug 2010, 12:24 PM
Hi,

We do not suggest maintaining the group expanded state on the client. I would suggest you to refer to the following code libraries for more information on this matter:
Persist Groups Expanded State on Rebind
http://www.telerik.com/community/code-library/aspnet-ajax/grid/retain-expanded-selected-state-in-hierarchy-on-rebind.aspx



Sincerely yours,
Maria Ilieva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
fareedha
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
fareedha
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or