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

Default sorting of items

5 Answers 343 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 24 Mar 2015, 01:22 PM
When you group or sort the GridView by one column and afterwards change the corresponding property, the items are more or less randomly inserted in the list.
In my case, the items have some natural sorting by some item number (as indicated by the underlying ItemsSource). There is a property which determines the ordering, however this is not exposed as a column.

Is there any way to force the items to keep this order (inside their respective groups)?

Alex

5 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 25 Mar 2015, 12:40 PM
Hi Alex,

You can specify the SortMemberPath property of the column to be the property determining the ordering. Then, you will need to have the column sorted Ascending or Descending. How does this work for you?

Regards,
Dimitrina
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Alexander
Top achievements
Rank 1
answered on 25 Mar 2015, 02:50 PM
Sorry, I think I didn't make it clear enough.

I am grouping by the column "Group" and then change the group of some items.
Now the items are in the wrong order inside the groups (e.g. M2 comes after M10; and M3 being at the bottom of the grid - not in the window any more and not in the first row of the third group, where I would expect it to be).
So the first column should be kept sorted (without having to specify a SortDescriptor).
0
Dimitrina
Telerik team
answered on 26 Mar 2015, 03:51 PM
Hi Alex,

Would you please share some more details on how do you insert the items? Basically, in case there is not any SortDescriptor added, RadGridView should display them as they are ordered in the bound source collection. The way RadGridView can control the order would be through adding a proper sorting descriptor.

Regards,
Dimitrina
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Alexander
Top achievements
Rank 1
answered on 26 Mar 2015, 04:13 PM
There is no insertion involved.

When there is no Grouping/Sorting active, the items appear in the correct order (as in the source collection, where they are always ordered).
When you activate Grouping and/or Sorting, the order (inside the group) stays correct.
However, when I edit the group of an item while Grouping is active, then it is sometimes moved at the wrong position (and therefore difficult to find).
The order is correct again when we sort by the id column and then remove the sort descriptor again.

I don't want to put a sort descriptor on the first column, as this would have to be "fixed" - but maybe the user wants to sort by some other column...
0
Dimitrina
Telerik team
answered on 27 Mar 2015, 09:31 AM
Hello Alex,

Thank you for clarifying this. As it turns out this logic when RadGridView is grouped cannot be overcame. Basically grouping in RadGridView is a data operation. The default grouping occurs as the user drags a column header and drops it into the GroupPanel. Then, we internally generate and execute a LINQ query appending a GroupBy clause to the source collection. While grouping is active, every time when a CollectionChanged notification is raised (for example as you are editing an item), then the GroupDescriptor is reevaluated and that is why you experience the non-desired effect.

Regards,
Dimitrina
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

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