dotnet / DataGridExtensions

Modular extensions for the WPF DataGrid control
MIT License
811 stars 103 forks source link

Filtering is not working with converters #102

Closed KeoSoft closed 1 year ago

KeoSoft commented 1 year ago

if you set a converter on a DataGridTextColumn the filtering is not using the converted value, instead it will search using the binding property, if you use a converter to get the username for example from an int ID property, the search filter will ignore the converter so that if you type "john" for example it will search for "john" in a set of int values and no result return

tom-englert commented 1 year ago

I think that's by design, the SearchMemberPath is the only common thing among all column types, and the built in search woks the same way - it would be confusing if search and filtering would get different results.

KeoSoft commented 1 year ago

What if we could access information about column binding, then we can use the converter to return the actual value ?

tom-englert commented 1 year ago

Does sorting the column work correctly on such a column with a converter?

tom-englert commented 1 year ago

Sorting does not work with a converter either, it sorts by the index, not by the string displayed:

BasicSample_fu49fSpDlf

Now that proves that changing the behavior would introduce inconsistencies between sorting and filtering.

You need to provide a property in your items model that returns the name from the ID, instead of looking up the name in a converter.

KeoSoft commented 1 year ago

I ended up using the [NotMapped] attribute to add extra properties to the entity using partial classes. I hope that the DataGrid sorting behavior will change in the future.

tom-englert commented 1 year ago

I ended up using the [NotMapped] attribute to add extra properties to the entity using partial classes.

Using entities as view models is an anti-pattern, you should strictly avoid this

I hope that the DataGrid sorting behavior will change in the future.

I don't think so, there is no more active feature development on WPF

KeoSoft commented 1 year ago

Using entities as view models is an anti-pattern, you should strictly avoid this

i don't use entities as view models, i just use ObservableCollection of entity type inside my view-models

I don't think so, there is no more active feature development on WPF

In Fact WPF is still under development https://github.com/dotnet/wpf#status