Sorting second level is not working in hierarchical RadGridView

1 Answer 38 Views
GridView
Julian
Top achievements
Rank 1
Iron
Iron
Iron
Julian asked on 30 Oct 2024, 01:21 PM

Hi

I have a GridView with a hierarchy consisting of a second level connected via a manual relation and a template.

Overall it works fine. But I have SortDescriptors defined for the MasterTemplate and other SortDescriptors for the second template.

The first level is sorted as defined, the second level is not sorted at all -  although the sort arrows appear correctly in the header of the lower level rows.

The user can change the sorting manually at runtime, that works fine.

Is this an error or might I be doing something wrong?

1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 31 Oct 2024, 11:58 AM

Hello Julian,

I have tested your scenario and indeed adding a SortDescriptor to the child template won't sort the template programmatically. The sorting functionality of the RadGridView in hierarchy mode works a little bit differently. You will need to add the SortDescriptor to the SortDescriptors collection of the parent template. Let say we have the following structure.

RadGridView SortDescriptors
    Level 1 Template SortDescriptors
   Level 2 Template SortDescriptors

When sorting Level 1, the sort descriptor will be added to the RadGridView SortDescriptors collection.

When sorting Level 2, the sort descriptor will be added to the Level 1 SortDescriptors collection.

This can be observed when the user sorts the child template in run time. To programmatically sort Level 2, you can add the custom SortDescriptor in the parent template SortDescriptors collection.

I hope that I was able to explain it. Can you give it a try and let me know if you were able to sort the child template programmatically?

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Julian
Top achievements
Rank 1
Iron
Iron
Iron
commented on 01 Nov 2024, 12:52 PM

Thank you for the quick answer

I tried it. I added the SortDescriptors for level 1 and level 2 to the RadGridView SortDescriptors collection (MasterTemplate).

At runtime only the SortDescriptor for level 1 exists, level 2 is not sorted.

If the user sorts the child template in runtime, a SortDescriptor is added to level 2 template SortDescriptors collection - so,  contrary to what you described

So, still I am not able to sort the child template programmatically

Dinko | Tech Support Engineer
Telerik team
commented on 04 Nov 2024, 10:01 AM

In that case, can you share how the hierarchy is set to the RadGridView in your application? In my test project, the hierarchy is set in bound mode as described in the Setting the Multi-Level Hierarchy in Bound Mode section. If you can prepare a sample project with dummy data that demonstrates the set-up on your side, that will be of great help, as I will directly think of a solution using your approach.
Julian
Top achievements
Rank 1
Iron
Iron
Iron
commented on 05 Nov 2024, 09:19 AM

The hierarchy in my project is according to Object Relational Hierarchy Mode


this.radGridChoice.MasterTemplate.Templates.AddRange(new Telerik.WinControls.UI.GridViewTemplate[] {this.gridViewTemplateFiles});

gridViewRelation1.ChildColumnNames.Add("Files");
gridViewRelation1.ChildTemplate = this.gridViewTemplateFiles;
gridViewRelation1.ParentTemplate = this.radGridChoice.MasterTemplate;
gridViewRelation1.RelationName = "relationCompoundFiles";

this.radGridChoice.Relations.AddRange(new Telerik.WinControls.UI.GridViewRelation[] {gridViewRelation1});

Dinko | Tech Support Engineer
Telerik team
commented on 05 Nov 2024, 01:28 PM

Thank you for sharing how the hierarchy is built on your side. I can see that several templates are added to the Templates collection using AddRange() method. What I can suggest here is to test which template is holding the sort descriptor created run time. You can sort the child template run time and add some button or subscribe to the mouse click event of the RadGridView. Then you can iterate the Templates collection and check each of the template's SortDescriptors collection to see which template contains the SortDescriptor. This way you can see which template need to be used to sort its child template.

As a note, in my test project, the suggested approach works, so I am assuming that on your side, the wrong template is target.

 
Julian
Top achievements
Rank 1
Iron
Iron
Iron
commented on 05 Nov 2024, 01:48 PM

No, you can see that only one template is added to the collection, in the generated code it is always AddRange.

As mentioned, the MasterTemplate has a SortDescriptor and the other template has two. They are added in the code and at runtime are added to the right templates. The arrows are there - but the rows are not sorted.

If I then remove them manually at runtime and add them again, the SortDescriptors are in the templates just like in the beginning - but working


sortDescriptor1.PropertyName = "Position";
sortDescriptor2.Direction = System.ComponentModel.ListSortDirection.Descending;
sortDescriptor2.PropertyName = "DateXX";
this.gridViewTemplateFiles.SortDescriptors.AddRange(new Telerik.WinControls.Data.SortDescriptor[] {
            sortDescriptor1,
            sortDescriptor2});

sortDescriptor3.Direction = System.ComponentModel.ListSortDirection.Descending;
sortDescriptor3.PropertyName = "DateAA";
this.radGridChoice.MasterTemplate.SortDescriptors.AddRange(new Telerik.WinControls.Data.SortDescriptor[] {
            sortDescriptor3});

Dinko | Tech Support Engineer
Telerik team
commented on 06 Nov 2024, 10:30 AM

If the arrow appears in the column header cell but the rows are not sorted, this leads me to think that I am missing something here. To further investigate this I will need somehow to isolate this scenario. Is it possible to isolate the data with the build hierarchy in a sample project? You can only add a few rows so that I can observe the sorting and the child template. You can also share the type of the properties which are shown in the columns and we are trying to sort.
Julian
Top achievements
Rank 1
Iron
Iron
Iron
commented on 06 Nov 2024, 11:00 AM

I attached the code.

The dataSource is then set to a List of objects which have a List of the objects of the lower level

Dinko | Tech Support Engineer
Telerik team
commented on 10 Nov 2024, 09:20 AM

I appreciate the provided file. I have closely reviewed the code but could not find anything suspicious that could lead to the reported behavior. What you can do is double-check if the hierarchy inside the control is built correctly. More specifically, you can check the text box column which points to the Einstelldatum. The FieldName is pointing to Einstelldatum but the HEaderText is different. 

gridViewTextBoxColumn1.FieldName = "Einstelldatum";
gridViewTextBoxColumn1.FormatString = "{0:d}";
gridViewTextBoxColumn1.HeaderText = "Eingangsdatum";

In general, this is expected to have different strings. However, the is another text box column that points to Eingangsdatum and has the same HeaderText: Eingangsdatum.

gridViewTextBoxColumn7.FieldName = "Eingangsdatum";
			gridViewTextBoxColumn7.FormatString = "{0:d}";
			gridViewTextBoxColumn7.HeaderText = "Eingangsdatum";

This is just something you can double-check.

I am afraid that I will need to reproduce this behavior so that I can further assist you. If you can take some time and try to isolate this in a sample project, that would be great. I check the code but I will need to reproduce this and be able to debug this behavior so that I can further assist you.

Tags
GridView
Asked by
Julian
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or