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

Multiple column and custom sorting

7 Answers 125 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jerry Kurata
Top achievements
Rank 1
Jerry Kurata asked on 14 May 2010, 05:28 PM
Hi,

I am a bit confused on how to implement both multiple column and custom sorting.  Based on the help documentation both appear to use the same sorting event handler.  However, in multiple column case the goal seems to be create a SortDescriptor, and in the custom sort the actual sort is performed.  Could someone describe how the two are integrated into the same Sorting Event handler?

Thanks

7 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 17 May 2010, 08:27 AM
Hello Jerry Kurata,

Let me know the format of your data ( e.g. the types of the fields)  and the desired behavior and I will prepare a small sample for you.

Greetings,
Pavel Pavlov
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
Jerry Kurata
Top achievements
Rank 1
answered on 17 May 2010, 04:16 PM
Hi Pavel,

My data is a bit difficult to access since a cell on the grid is defined by a template that is bound to several fields in the underlying data.  However, each of these fields is a simple data type such as a string, int, or date.  So a sample with any of these simple types would be great.

Thanks,

jerry

0
Pavel Pavlov
Telerik team
answered on 18 May 2010, 08:38 AM
Hi Jerry Kurata,

As mentioned before - to prepare a sample ,  I will need a bit more about the behavior you are trying to achieve.

In general when you handle the sorting event you have the following options :
Add one or more additional  sort descriptors and rely on RadGridView  to preform the sorting for you
or mark the event as handled and perform custom sorting - sort the collection with your own logic and reasign it to the ItemsSource.

In  your case  - since you will mark the event as handled , I believe you will need to custom sort both columns ( e.g. execute your own sorting logic within the event handler  for both columns ) .

Regards,
Pavel Pavlov
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
Jerry Kurata
Top achievements
Rank 1
answered on 19 May 2010, 12:02 AM
Pavel,

I think we need to the later case, handling the sorting in our custom manner.  In this case what happens when the user does a multi-column sort.  Is the sorting routing called multiple times (once for each column being sorted) or is it called once and the custom sort code can find somewhere a list of the columns to sort, the sort order, and sort direction, or is there some other methodology?

Jerry



0
Pavel Pavlov
Telerik team
answered on 20 May 2010, 03:03 PM
Hi Jerry Kurata,

Within the sorting event handler you get the GridViewSortingEventArgs.

e.IsMultipleColumnSorting will be true if the user holds the shift key trying to perform a multiple sort.

For each time the user clicks on a column header to sort , teh event handler will ba called once.

e.DataControl.SortDescriptors  will give you info on what columns has already been sorted.

Sincerely yours,
Pavel Pavlov
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
Jerry Kurata
Top achievements
Rank 1
answered on 02 Jul 2010, 07:58 AM
Hi,

Sorry for taking so long to reply.

Let me make sure I understand this correctly.  If the user decides to sort Columns 1, 2, and 3 the grid's Sorting handler will be called 3 times, once for each column.  Is this correct?  I can determine the "current" column by inspecting the SortDescriptor collection to see which Column has not been sorted.   If I need to a special sort order I just perform this sort on the "current" column only.  That is I do not need to worry about doing something like a LINQ OrderBy and ThenBy.  Is that correct?

Thanks again,

Jerry


0
Accepted
Vlad
Telerik team
answered on 06 Jul 2010, 12:04 PM
Hi Jerry,

 Generally you can do both - sort using LINQ and/or using SortDescriptor however in the first case the grid will be unaware of your sort. For example you can cancel the default grid sorting using Sorting event and desired SortDescriptors to the grid directly. 

Best wishes,
Vlad
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
Tags
GridView
Asked by
Jerry Kurata
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Jerry Kurata
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or