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

SL RadGridView: Capturing and Reinstating GroupRow IsExpanded

6 Answers 84 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jaye
Top achievements
Rank 1
Jaye asked on 27 Mar 2013, 07:00 PM
Hello,

I've read through countless forums related to this topic, and found the conclusions dubious if outright not applicable/working (different versions, requirements, etc).

I am currently using version [2012.3.1129.1050], possibly upgrading to another version soon.

Problem:
It's simple -- there is a RadGridView with grouping enabled, user may create multiple nested group layers.
AutoExpandGroups="False", so any rebind starts with all groups collapsed.

For particular rebinds, this is not desirable, as the user would like to retain their contextual display state (e.g. expand/collapse state of every group, scroll positions, etc -- for this thread, I'm only seeking feedback on the expand/collapse topic).

Goal:
Before rebind, capture the expand/collapse state of each group.
After rebind, reinstate each group's former state.

Approaches:
(tried several with limited success -- just looking for an official recommendation on approach)

Reinstating seems simple enough, the RadGridView provides convenient methods
  • ExpandGroup(IGroup)
  • CollapseGroup(IGroup)

But capturing has been an unexpected challenge, I'm looking for an efficient way to survey all groups to identify which are expanded.

In case this is helpful for anyone else, here's my painful progression of trials, so you could save yourself time:

1. Instead of rebind, implement a selective update of the bound source items, then notify.
Yes, this retains the grid's overall display state, however the updated item attribute(s) could affect whether the affected row(s) need to be moved to a different group, require refresh of aggregations, etc.

So a rebind would be much cleaner.

2. Loop through RadGridView.Items.Groups.
This involves recursively traversing all subgroup levels for nested situations (doable, but I'm hoping there is a simpler way to interrogate all groups easily). Also, the IsExpanded property is available on GridViewGroupRow, not IGroup itself.

For some reason, couldn't figure out (feel free to knock me) how to access the relevant GridViewGroupRow...

3. Loop through GridViewGroupRows.
Tried to access this via RadGridView.ChildrenOfType<GridViewGroupRow>(), however was empty. Other ideas also failed.

So I still couldn't figure out (feel free to knock me harder) how to access GridViewGroupRows on demand...

4. Leverage the GroupRowIsExpandedChanged event.
This at least provides a handle to the elusive GroupRow (when a group is clicked via UI). I can therefore check IsExpanded at runtime and maintain an internal record of IGroup states up until a rebind, then reinstate after rebind. There are various cycle nuances to this, but no major hurdles.

However, if you programatically expand/collapse (for example, invoke RadGridView.ExpandAllGroups), some unexpected and delightfully frustrating inaccuracies plague the internal record of states. Such as, only a fraction of the expanded groups get recorded. Also, adding/removing groupings lead to additional sync issues. Flaky.

Ideally, I don't want to depend on a realtime event like this, too unreliable. Would prefer the simple ability to just access all of the RadGridGroupRows on demand, and reliably interrogate which have IsExpanded = true.

Please point me toward enlightenment, have been wandering painfully through too many insufficient solutions...
Thanks!



6 Answers, 1 is accepted

Sort by
0
Niko
Top achievements
Rank 1
answered on 17 May 2013, 04:18 PM
Has anyone been able to figure this out? I am also experiencing the same problems...

Thanks
0
Dimitrina
Telerik team
answered on 20 May 2013, 08:55 AM
Hello,

You could save the keys for Groups with expanded state (or with collapsed state):
List<object> expandedGroups = new List<object>();
...
this.expandedGroups.Add(e.Row.Group.Key);

You can then go through the GridView.Items.Groups collection expanding the Groups which Keys you have saved.

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Niko
Top achievements
Rank 1
answered on 20 May 2013, 06:17 PM
Thanks for your response Didie --

The problem with this approach is that the items in "Gridview.Items.Groups" are QueryableCollectionViewGroups, which do not have the 'IsExpanded' property. It seems IsExpanded is not part of the IGroup interface, just within the GridViewGroupRow class.

Is there anyway to get the GridViewGroupRow from Gridview.Items.Groups?

Thanks
0
Dimitrina
Telerik team
answered on 21 May 2013, 08:36 AM
Hi,

You could expand a group with the GridView.ExpandGroup method. Does this work for you?

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Niko
Top achievements
Rank 1
answered on 22 May 2013, 01:44 AM
Didie, yes and No.

Yes -- The ExpandGroup() method successfully expands a given group.

No -- Depending on how many Columns the user has grouped, you need to traverse through the GroupRow's items and check for matching keys. The method below worked well for me (if anyone needs):
private void TraverseAndExpandGroupRows(IGroup row)
       {
           Dispatcher.Invoke(new Action(() => LineStatusGrid.ExpandGroup(row)));
           if (row.HasSubgroups)
           {
               foreach (IGroup subItem in row.Items)
               {
                   if (_expandedGroups.Any(newKey => subItem.Key.ToString() == newKey.ToString()))
                   {
                       TraverseAndExpandGroupRows(subItem);
                   }
               }
           }
       }

Now, the problem is...Each 'root' GroupRow will have the same child keys, some may be expanded some may not. For example:
--"Row 1"
  --"Description"
  -- "Name"
--"Row 2"
  --"Description"
  -- "Name"
If "Description" is expanded and stored in my "expanded" list, how do I know if it's for Row 2 or Row 1? Storing just the Key is not enough, you also need to store the subgroups parent row.

Bottom line -- this is over-complicated and should have better native support for updating.
0
Dimitrina
Telerik team
answered on 24 May 2013, 10:55 AM
Hello,

Indeed you are right. When you also have subgroups which states to persist, then the Key's value would not be unique for them. You should save the entire group, or save some criteria that you can then recognize.

Regards,
Didie
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Jaye
Top achievements
Rank 1
Answers by
Niko
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or