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

[Solved] How to group and sort by another column

3 Answers 349 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jack
Top achievements
Rank 1
Jack asked on 25 May 2009, 09:06 PM
I have a parent/child relationship in some data and I've flattened it out to remove the hierarchy but just contained enough data to maintain all the grouping / sorting I need.  Basically I have the following hierarchy:

ParentTask - Name/Key/SortOrder
    ChildTask - Name/Key/SortOrder
    ChildTask - Name/Key/SortOrder
ParentTask - Name/Key/SortOrder
    ChildTask - Name/Key/SortOrder

My ChildTask BO's have references to the parents so I am able to include the parentTask data keys in my bindable row.  I would like to create grouped data to essentially maintain my hierarchy.  However I can't see clearly how to set the sort order of my groupings so that they don't sort by the grouping columns.

For example my parent tasks are labelled:
Baseline Visit , Visit One, Visit Two, Visit Three, End of Study

I have matching SortOrder keys: 0,1,2,3,4

However when I predefine a RadGroupDesc I cannot see how to specify that the sorting should be done by Parent.SortOrder not by alphabetical on ParentTask.Name which skews the order to Baseline, End of Study, Visit One, Visit Three, Visit Two.

Thanks

jack

3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 29 May 2009, 12:42 PM
Hi Jack,

Unfortunately RadGridView does not support this feature directly. However there is a workarround.

I understand that the aim is to group by the Task.Name but sort the resulting groups by the Task.SortOrder property rather than the Task.Name.

So what we can do here is to "lie" the internal logic of the RadGridView the following way:
If the property we are grouping by implements IComparable the RadGridView will respect it . In the "CompareTo" method we can check the sort order rather than the name. 

I believe  the following change to the Task business object  would do the trick :
public class Task  
    {  
        public int Key { get; set; }  
        public TaskInfo Name { get; set; }  
    }  
 
    public class TaskInfo : IComparable  
    {  
        private readonly string name;  
        public int sortOrder;  
 
        public TestSubject(string name, string sortOrder)  
        {  
            this.name = name;  
            this.sortOrder = sortOrder;  
        }  
 
        public override string ToString()  
        {  
            return this.name;  
        }  
 
        public int CompareTo(object obj)  
        {  
            if ((TaskInfo) obj).sortOrder > this.sortOrder)  
                return 1  
            else if((TaskInfo) obj).sortOrder < this.sortOrder  
                return -1;  
 
            return 0;  
        }  
    } 
What we do here is - in the CompareTo method we force the comparison to be made by the SortOrder rather than the string in the Name.

In order this to work we have to store the Name in the TaskInfo object , rather than in a string. The same for the SortOrder.

Let me know if you have troubles adaping this to your project .

Kind regards,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jack
Top achievements
Rank 1
answered on 29 May 2009, 01:22 PM
Okay that makes sense ... I don't think that will have any other consequences and seems simple enough.  I'm assuming that the TestSubjects is suppose to read TaskInfo on about line 12.

I'll ask a couple of questions back then:

1) Could I group by the SortOrder and then manipulate the group header row such that it displays the TaskName?

2) Would my scenario work in default with a Hierarchial grid?  I really actually have two distinct sets of data - I just prefered the grouping by visual to the hierarchial... although maybe I should play with it.

3) Would I hierarchial grid have more or less overhead than maintaining a sorted grouped grid view?  I'm curious what happens when I re-sort the non-grouped columns.  In my implementation I am sorting the whole grid?  in the Hier grid would I just be sorting the 2nd level or would it re-sort all second levels?

4) Is this something a future version could implement ?  A GroupSortProperty that defaults to the current value but can be overridden.

Thanks for the reply,

Jack
0
Pavel Pavlov
Telerik team
answered on 01 Jun 2009, 12:35 PM
Hi Jack,

1) Could I group by the SortOrder and then manipulate the group header row such that it displays the TaskName?

I am afraid that this is not possible ( or at least not easy to achieve)  with the current version of RadGridView

2) Would my scenario work in default with a Hierarchial grid?  I really actually have two distinct sets of data - I just preferred the grouping by visual to the hierarchial... although maybe I should play with it.

You may regard the hierarchy as nested instances of RadGridView.  It may be easier to get the hierarchy  displayed, However since each child table will be a GridView , you will get a nested scrollbar.

3) Would I hierarchial grid have more or less overhead than maintaining a sorted grouped grid view?  I'm curious what happens when I re-sort the non-grouped columns.  In my implementation I am sorting the whole grid?  in the Hier grid would I just be sorting the 2nd level or would it re-sort all second levels?

In hierarchy sorting will sort only master rows. If you need to sort the nested records, you will have to click on the headers of the nested RadGridView.

4) Is this something a future version could implement ?  A GroupSortProperty that defaults to the current value but can be overridden.

We are working on a new data engine for RadGridView. I have already put that feature in our TODO list. Thanks for the suggestion!


All the best,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Jack
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Jack
Top achievements
Rank 1
Share this question
or