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

Save Group Expand/Collapse State

6 Answers 151 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nick Wood
Top achievements
Rank 1
Nick Wood asked on 18 Jan 2012, 06:14 AM
Hi There, I know that this has been asked several times, such as here:
http://www.telerik.com/community/forums/silverlight/gridview/rebinding-updating-while-maintaining-selection-position-expansion.aspx

But I want to get clarify what I am trying to do. My situation is that I cannot update the items in the itemssource, I have to rebind as I am binding to a view but updating from the entity item. It obviously requires a refresh of the view results and therefore a rebind.

I need to preserve the grid grouping expand/collapse state so that after the rebind the user sees the same grid layout.

Any help please.

6 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 18 Jan 2012, 08:06 AM
Hello,

 Please check this demo for Persistence Framework on how to save/load settings:
http://demos.telerik.com/silverlight/#PersistenceFramework/GridViewCustomSerialization 

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Mike Shilkov
Top achievements
Rank 1
answered on 26 Jun 2012, 10:53 AM
Hello Didie,

Your post doesn't seem to be a full reply to initial question.
What Nick needed (and I need) was to save the expand/collapse state of all groups after Rebind operation. 
The example that you mentioned shows how to save the grouping itself, not the expand/collapse state. I had a try: groupped by Country, expanded Agrentina, Saved, then expanded Canada and clicked Load; nothing happened, the expand/collapse state was not restored.
Do you have a working sample of what we need? Or do I have to write it myself with getting the current state of grid and then re-applying it after rebind?

Thanks
0
Dimitrina
Telerik team
answered on 27 Jun 2012, 01:41 PM
Hello,

In regard to your question, I would recommend you to check this forum thread where a sample project is attached.

I hope this is what you need.

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Serguei
Top achievements
Rank 1
answered on 19 Jul 2013, 09:37 PM
Here is my solution:

        private struct GroupNameHeader
        {
            public string GroupName;
            public string GroupHeader;
            public string ParentGroupHeader;
        }
 
        private List<GroupNameHeader> _expandedGroups;
 
        protected void SaveExpandedGroups()
        {
            _expandedGroups.Clear();
            SaveExpandedGroups(Grid.Groups);
        }
 
        protected void RestoreExpandedGroups()
        {
            RestoreExpandedGroups(Grid.Groups);
        }
 
        private void SaveExpandedGroups(DataGroupCollection Groups)
        {
            foreach (DataGroup group in Groups)
            {
                if (group.IsExpanded)
                {
                    GroupNameHeader expandedGroup;
                    expandedGroup.GroupName = group.GroupDescriptor.GroupNames[0].PropertyName;
                    expandedGroup.GroupHeader = group.Header;
                    if (group.Parent == null)
                    {
                        expandedGroup.ParentGroupHeader = null;
                    }
                    else
                    {
                        expandedGroup.ParentGroupHeader = group.Parent.Header;
                    }
                    _expandedGroups.Add(expandedGroup);
                    SaveExpandedGroups(group.Groups);
                }
            }
        }
 
        private void RestoreExpandedGroups(DataGroupCollection Groups)
        {
            if (_expandedGroups.Count > 0)
            {
                foreach (DataGroup group in Groups)
                {
                    foreach (GroupNameHeader expandedGroup in _expandedGroups)
                    {
                        string parentGroupHeader = null;
                        if (group.Parent != null)
                        {
                            parentGroupHeader = group.Parent.Header;
                        }
                        if (group.GroupDescriptor.GroupNames[0].PropertyName == expandedGroup.GroupName &&
                            group.Header == expandedGroup.GroupHeader &&
                            parentGroupHeader == expandedGroup.ParentGroupHeader)
                        {
                            group.Expand();
                        }
                    }
                    RestoreExpandedGroups(group.Groups);
                }
            }
        }

You can use SaveExpandedGroups() before bind and RestoreExpandedGroups() after.

Serguei
0
Dimitrina
Telerik team
answered on 22 Jul 2013, 07:32 AM
Hello,

Thank you for sharing your solution with the community. As an additional note I would like to mention that you could also save the keys for the Groups and not the entire groups.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Serguei
Top achievements
Rank 1
answered on 25 Jul 2013, 09:48 PM
Hello Didie,
I am actually saving keys represented by
        private struct GroupNameHeader
        {
            public string GroupName;
            public string GroupHeader;
            public string ParentGroupHeader;
        }
and not the entire groups.

Cheers,
Serguei
Tags
GridView
Asked by
Nick Wood
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Mike Shilkov
Top achievements
Rank 1
Serguei
Top achievements
Rank 1
Share this question
or