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

Sorting does not work on inherited properties

13 Answers 35 Views
GridView
This is a migrated thread and some comments may be shown as answers.
almostEric
Top achievements
Rank 1
Iron
almostEric asked on 11 Apr 2019, 09:13 PM

I have a grid that has some columns that are bound to properties that come from an inherited class. 

All properties display fine - whether they are from the base class or the inherited class.

The properties that come from the inherited class can not be sorted.

This sure seems like a bug, and I'd really rather not have to go the whole custom sorting implementation.

13 Answers, 1 is accepted

Sort by
0
almostEric
Top achievements
Rank 1
Iron
answered on 11 Apr 2019, 09:14 PM
Forgot to mention - setting SortMemberPath had no effect whether it was there or not
0
Martin Ivanov
Telerik team
answered on 15 Apr 2019, 01:00 PM
Hello Eric,

Thank you for the provided description. 

This behavior is expected and it appears because of the gridview properties finding mechanisms. Basically, only the properties of the concrete class used for the row model's property will be found. In your case this is the abstract "bar" class.

In order to achieve your requirement you can use couple of different approaches.
  • The first one is to use a single non-inherited model that contains all necessary properties that should be display in the gridview. This will the wrapper that could be used in the control.
  • The second approach is to implement a custom filtering using the Sorting event of RadGridView. This approach is shown in the attached project.
Can you please try those suggestions and let me know if they help?

Regards,
Martin Ivanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
almostEric
Top achievements
Rank 1
Iron
answered on 15 Apr 2019, 05:21 PM
Why would this be expected? If the binding works on all the properties, why doesn't sorting? That seems totally inconsistent
0
almostEric
Top achievements
Rank 1
Iron
answered on 15 Apr 2019, 10:19 PM

I have implemented the Sorting event. That is some really ugly code that completely breaks the WVVM model, but fine, it works. sort of.

 

The behavior of these columns with custom sorting is different then the columns based on the concrete class' properties. They act like the shift or control key is being held down, so when you click on another column, both are highlighted in the column header (since I am implementing the sort, only one column is sorted).

Additionally, it would appear I would need to write even more custom code to handle the situation where sorting is being done on multiple columns..

All in all, this is really a totally inadequate solution to bug in your product. The original WPF DataGrid had plenty of limitations, but sorting worked on it properly :/

 

 

0
Martin Ivanov
Telerik team
answered on 17 Apr 2019, 08:12 AM
Hello Eric,

It is expected within the context of the RadGridView current implementation. However, after further discussion with the development team, we've decided that this should be improved. This is why I've logged an item in our feedback portal where you can track its status. I also updated your Telerik points as a small gesture of gratitude for reporting this.

Regards,
Martin Ivanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
almostEric
Top achievements
Rank 1
Iron
answered on 16 Sep 2019, 12:36 PM

Hi, I checked the Feedback portal and there does not seem to have been any movement on this issue. I bring this up, because it would be really nice to get this fixed. I have run into another issue with the kludgey workaround code with custom sorting that we currently have to use.

 

The issue is that if the grid is currently sorted on one of these columns using custom sorting, if the underlying bound data is updated, the grid does not reflect it unless the grid is resorted. This is causing a *lot* of problems

0
Martin Ivanov
Telerik team
answered on 17 Sep 2019, 08:59 AM

Hello Eric,

I am sorry to hear that the workaround doesn't work as expected. Currently, this is not included in our planning, but I will bring it to the attention of our management. I can't promise that this will get added to the queue for the next release, but stay tuned by following the feedback item.

About the new issues you are experiencing, can you tell me how you update the data, how the grid is resorted and what are the exact problems you are hitting? A runnable example showing this will be useful too. This way we can think of a solution for your case. Also, can you try resetting the sorting by calling the Reset() method of the SortDescriptors collection and see if the issues appear?

this.gridView.SortDescriptors.Reset();
Regards,
Martin Ivanov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
almostEric
Top achievements
Rank 1
Iron
answered on 17 Sep 2019, 09:18 AM

That is very disappointing to hear, especially after your earlier post :

"It is expected within the context of the RadGridView current implementation. However, after further discussion with the development team, we've decided that this should be improved. This is why I've logged an item in our feedback portal where you can track its status. I also updated your Telerik points as a small gesture of gratitude for reporting this."

 

The sort logic is pretty much a copy of the custom sorting example you provided: determine which column is being sorted:

 

IEnumerable<MenuItem> items = e.DataControl.ItemsSource as IEnumerable<MenuItem>;


                if (items == null)
                {
                    e.Cancel = true;
                    return;
                }

                if (e.OldSortingState == SortingState.None || e.OldSortingState == SortingState.Descending)
                {
                    e.NewSortingState = SortingState.Ascending;
                    items = SortAscendingByColumnUniqueName(e.Column.UniqueName, items);
                }
                else if (e.OldSortingState == SortingState.Ascending)
                {
                    e.NewSortingState = SortingState.Descending;
                    items = SortDescendingByColumnUniqueName(e.Column.UniqueName, items);
                }
                //else
                //{
                //    e.NewSortingState = SortingState.None;
                //    items = items.OrderBy(mi => mi.MenuItemDisplayDetail.DisplayOrder);
                //}

                e.DataControl.SortDescriptors.Clear();
                e.DataControl.ItemsSource = items;
                e.Cancel = true;

 

where MenuItems is my domain object. The control is bound to an observable collection of said MenuItems. The issues is if the grid is sorted by a column that doesn't use customsorting, when the Observable collection is updated, the grid updates as expected. If the grid is currently being sorted by a column that is using custom sorting, nothing happens to the grid when the observable collection is changed until you click on a column (any column) to cause a resort.

per your example, you can see I am already clearing the SortDescriptors. Do I need to reset them instead/addition to?

Sure would be better if you just fixed the grid like you said you would

 

 

 

0
Martin Ivanov
Telerik team
answered on 19 Sep 2019, 07:02 AM

Hello Eric,

Thank you for the additional information. I've tested this in the project attached to one of the older replies here and I can confirm that there is an issue. Actually, this is my mistake. The sorted "items" collection is an OrderedEnumerable which doesn't report collection changed, so when you add a new item in RadGridView after the custom sorting, the UI doesn't get notified that the collection has been changed, thus not updating the view. 

To resolve this, convert the sorted collection to ObservableCollection.

e.DataControl.SortDescriptors.Clear();
e.DataControl.ItemsSource = new ObservableCollection<MenuItem>(items.ToList());
e.Cancel = true;

Note that because the collection is manually sorted, when you add/remove items from it, you will need to manually apply the sorting.

private void OnCollectionChanged(IEnumerable collection)
{
	// Apply the custom sorting to the ItemsSource collection of RadGridView
}

About the fix, please note that we acknowledged this behavior as an issue, but we haven't bound to a concrete timeframe for fixing it. What I would recommend is to follow the feedback item. This way, when its status changes you will get a notification.

Regards,
Martin Ivanov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
almostEric
Top achievements
Rank 1
Iron
answered on 20 Sep 2019, 10:24 AM

Hi,

I tried this fix. It made the situation worse - now no changes are reflected, even after a manual resort. :/

 

Eric

0
Martin Ivanov
Telerik team
answered on 25 Sep 2019, 09:02 AM

Hello Eric,

Can you elaborate a bit more on this case? What changes are not reflect? Also, would it be possible to isolate this in a project and send it over? This will give me a better idea of your setup and I can think how to improve this behavior on your side.

Regards,
Martin Ivanov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
almostEric
Top achievements
Rank 1
Iron
answered on 25 Sep 2019, 04:18 PM

Hi,

Not quite sure how I can isolate this as it is part of a rather large project.

What I meant above, is that in the original code, doing an update to the Observable Collection that the grid is bound to would not be reflected if the grid is being sorted by one of these columns with CustomSorting enabled - annoying as it is, clicking on any column header to resort the grid would make the changes appear.

When using the new code:

e.DataControl.ItemsSource = new ObservableCollection<MenuItem>(items.ToList());

 

It appears that the binding is now broken, as manually resorting the columns does not show the changed data.

 

0
Martin Ivanov
Telerik team
answered on 30 Sep 2019, 02:35 PM

Hello Eric,

To resolve this, you can reset also the collection the view model (bound to ItemsSource) or apply to sorting directly on it.

Also, changes in the ObservableCollection doesn't trigger the custom sorting automatically. To achieve this you can implement a custom trigger that starts the custom sorting manually.

I've updated my last project to show this. I hope it helps.

Regards,
Martin Ivanov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
almostEric
Top achievements
Rank 1
Iron
Answers by
almostEric
Top achievements
Rank 1
Iron
Martin Ivanov
Telerik team
Share this question
or