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

RadGridview grouping

1 Answer 502 Views
GridView
This is a migrated thread and some comments may be shown as answers.
harsha
Top achievements
Rank 1
harsha asked on 12 Mar 2018, 09:26 AM

Hi,

I am using radgridview in my wpf application.When I drag and drop a column to the group panel, the sorting of groups is not done numerically as it is a string field.

I want the grouped data to be sorted numerically.

Any help would be really appreciated.

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 14 Mar 2018, 01:25 PM
Hello harsha,

There are two approaches you can try in such a scenario:

1) Handle the Grouping and replace the default ColumnGroupDescriptor with a generic one as demonstrated by my colleague in this forum thread. Here's an example:

private void ClubsGrid_Grouping(object sender, GridViewGroupingEventArgs e)
{
    if (e.Action == GroupingEventAction.Place)
    {
        var columnGroup = e.GroupDescriptor as ColumnGroupDescriptor;
        if (columnGroup != null && columnGroup.Column.UniqueName == "Id")
        {
            // cancel the default grouping
            e.Cancel = true;
 
            // define a generic GroupDescriptor
            var descriptor = new GroupDescriptor<Club, string, int>
            {
                GroupingExpression = o => o.Id,
                GroupSortingExpression = group => int.Parse(group.Key),
                SortDirection = e.GroupDescriptor.SortDirection,
                DisplayContent = "Id"
            };
            // add the new descriptor
            clubsGrid.GroupDescriptors.Add(descriptor);
        }
    }
}

2) Introduce a new calculated property in your business objects which holds the numeric representation of the string value and bind the column to that property.

public int IdInt
{
    get { return int.Parse(this.Id); }
    set { this.Id = value.ToString(); }
}

<telerik:GridViewDataColumn DataMemberBinding="{Binding IdInt}"/>

Please let me know if any of these methods works for you. I look forward to your reply.

Regards,
Dilyan Traykov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
harsha
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or