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

SortDescriptor and GroupDescriptor broke in Q3 release

4 Answers 116 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gareth Parris
Top achievements
Rank 1
Gareth Parris asked on 17 Nov 2010, 09:16 PM
Hi there, as I read in your breaking changes post regarding the Q3 release SortDescriptor and GroupDescriptor functionality has been changed. I have two code segments that no longer work and I am unsure how to change them in order to get them to work with the new functionality. Please could you help?

Firstly the GroupDescriptor has lost it's member property...

private void GridView_Grouped(object sender, Telerik.Windows.Controls.GridViewGroupedEventArgs e)
{
    if (e.Action == Telerik.Windows.Controls.GroupingEventAction.Place)
    {
        this.GridView.Columns[e.GroupDescriptor.Member].IsVisible = false;
    }
    else if (e.Action == Telerik.Windows.Controls.GroupingEventAction.Remove)
    {
        this.GridView.Columns[e.GroupDescriptor.Member].IsVisible = true;
    }
}


And similarly SortDescriptor has the same problem...

GridViewColumn column = headerCell.Column;
 
using (grid.DeferRefresh())
{
    Telerik.Windows.Data.SortDescriptor sd = (from d in grid.SortDescriptors
                              where d.Member == column.UniqueName
                              select d).FirstOrDefault();

Anyone able to point me in the right direction?

Thanks,
Gareth.

4 Answers, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 18 Nov 2010, 12:26 PM
Hello Gareth Parris,

 As noted in the breaking changes post, the GroupDescriptor property of GridViewGroupingEventArgs and GridViewGroupedEventArgs is of type IGroupDescriptor, which lacks the Member property. However, one of its implementors, GroupDescriptor does have the Member property.

 RadGridView now generates the new ColumnGroupDescriptor internally when the user performs grouping in the UI, so you need to cast the GroupDescriptor property of GridViewGroupedEventArgs to ColumnGroupDescriptor and you can get a direct reference to the grouped column from the Column property of ColumnGroupDescriptor.

 Likewise, SortDescriptors is now a collection of ISortDescriptor and RadGridView generates the new ColumnSortDescriptor internally when the user sorts from the UI. Filtering the SortDescriptors collection to a collection of ColumnSortDescriptor using the OfType<ColumnSortDescriptor>() extension method will allow you to iterate over every ColumnSortDescriptor in RadGridView and directly access the sorted column from its Column property.

Greetings,
Yavor Georgiev
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
ErrolM
Top achievements
Rank 1
answered on 05 May 2011, 01:06 AM
Hello Yavor,

Is there somewhere I can make a request for the Member property to be exposed by IGroupDescriptor and implemented by ColumnGroupDescriptor (mapped back to Column.x.y.z)?

I am combining the functionality of the RadGridView and the RadChart and doing quite a bit of work with placement of grouping fields etc programatically. With this breaking change, I have two ways of rewriting but either way I have literally double the code (and it is messy which irks my OCD :-)

1. Have two separate .OfType<> loops which is not easy given that the business logic involved relates to the whole group.
or
2. Have a typeof test in the loop, but the test would have to be extended from const == Member to const == Member || const == Column.x.y.z for every comparison.

Thanks
Errol
0
Yavor Georgiev
Telerik team
answered on 05 May 2011, 02:05 AM
Hello Errol Melvin,

 Here is a neat extension method you can use on IGroupDescriptor to get the member name, if available:
public static string GetMemberName(this IGroupDescriptor descriptor)
{
    var groupDescriptor = descriptor as GroupDescriptor;
    if (groupDescriptor != null)
    {
        return groupDescriptor.Member;
    }
     
    var columnGroupDescriptor = descriptor as ColumnGroupDescriptor;
    if (columnGroupDescriptor != null)
    {
        var boundColumn = columnGroupDescriptor.Column as GridViewBoundColumnBase;
        if (boundColumn != null)
        {
            return boundColumn.GetDataMemberName();
        }
    }
     
    return null;
}

You can use it like this:
private void OnGrouping(object sender, GridViewGroupingEventArgs e)
{
    if (e.GroupDescriptor.GetMemberName() == "FamilyName")
    {
        // do something here
    }
}


Greetings,
Yavor Georgiev
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
ErrolM
Top achievements
Rank 1
answered on 05 May 2011, 03:11 AM
Thanks Yavor,

My OCD likes that more than the gettype based extension I started to write :-)

With more investigation it seems we have been dynamically re-assigning the Member and DisplayContent of the GroupDescriptors based on parameters. So in the end I have a rewrite to suit the new concrete types and restore the previous functionality, however your extension will provide the starting point for that.

Cheers,
Errol
Tags
GridView
Asked by
Gareth Parris
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
ErrolM
Top achievements
Rank 1
Share this question
or