Gu.Wpf.DataGrid2D icon indicating copy to clipboard operation
Gu.Wpf.DataGrid2D copied to clipboard

Sort not working with custom cell template

Open mennowo opened this issue 3 years ago • 3 comments

When using the option to have custom cell template, eg.:

dataGrid2D:Cell.Template="{StaticResource CellTemplate}"

sorting via clicking on columns is no longer possible. Even if, for example, I simply bind double values. It would be nice to have this option, would it be doable?

mennowo avatar Nov 23 '21 10:11 mennowo

I've been trying my hand at this a little. I added an attached property on the Cell, in order to set the SortMemberPath property. This works, I am now able to click on the column headers and the small sorting arrow appears, however, no sorting happens. I am unsure how to proceed.

The code is here: https://github.com/mennowo/Gu.Wpf.DataGrid2D

Any help appreciated!

mennowo avatar Nov 24 '21 10:11 mennowo

This may be a limitation of the framework DataGrid try handling the Sort event and set a custom comparer. At least when binding with MultiBining sorting does nothing by default. Alternatively specifying SortMemberPath may work if that is an option.

JohanLarsson avatar Feb 28 '22 06:02 JohanLarsson

Thanks for your reply. Where would you go about and handle the Sort event? Since these are all attached properties, I'm not sure what is a good way of doing this without repeating it each time the grid is rebuilt. Also, I'm unsure how to set the comparer in the Sort event: would one get the default view via CollectionViewSource and add a SortDescription?.

In the current implementation, I'm not using a MultiBinding. I already set the SortMemeberPath, here. It has the effect of being able to click on column headers, however, that has no sorting effect. I'm unsure if I properly set up registration and manipulation of SortMemberPath (in Cell.cs), but equally unsure how to check this and proceed.

mennowo avatar Feb 28 '22 10:02 mennowo