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

Lose Expand value when using SwapColumns

2 Answers 26 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Todd A
Top achievements
Rank 1
Todd A asked on 21 May 2010, 10:11 PM
See code below.

The SwapColumns works in all cases.

The expand logic for the group works when the swap columns does not occur.

When the swap columns logic does occur, I loose the expand value and everything is expanded.

Any ideas would be greatly appreciated.

Thanks,
Todd.

 

    protected void ScheduleGrid_PreRender(object sender, EventArgs e)  
    {  
        //Swap  
        if (divisionObj.SwapHomeAndAway)  
            ScheduleGrid.MasterTableView.SwapColumns("Home", "Away");  
 
        //Expand/Collapse groups  
        ArrayList groupItems = new ArrayList(ScheduleGrid.MasterTableView.GetItems(GridItemType.GroupHeader));  
          
        foreach (GridGroupHeaderItem item in groupItems)  
        {  
            bool expanded = false;  
 
            ArrayList childItems = new ArrayList(item.GetChildItems());  
 
            foreach (GridItem child in childItems)  
            {  
                RadComboBox rcb = (RadComboBox)child.FindControl("DispositionComboBox");  
 
                if (rcb != null && rcb.SelectedValue != "")  
                {  
                    if (Convert.ToInt32(rcb.SelectedValue) == DispositionTypes.PENDING)  
                    {  
                        expanded = true;  
                        break;  
                    }  
                }  
 
            }  
 
            item.Expanded = expanded;  
        }  
 
    } 

 

 

2 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 27 May 2010, 12:12 PM
Hello Todd A,

Please note that the SwapColumns() method rebinds the grid. Since the expanded state of the group header items is not persisted in the viewstate and the GroupsDefaultExpanded="true" (the default value) then the items would always be expanded after you call that method.

To workaround this behavior you have to save the state of the group header items when you expand / collapse them and reapply that state after the grid is rebound. I have attached a small sample project that demonstrates this approach. Please give it a try and let me know if further assistance is needed.

Regards,
Martin
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.
0
Todd A
Top achievements
Rank 1
answered on 27 May 2010, 05:09 PM
Thanks Martin for the sample -- I will try it out.
Tags
Grid
Asked by
Todd A
Top achievements
Rank 1
Answers by
Martin
Telerik team
Todd A
Top achievements
Rank 1
Share this question
or