Gu.Wpf.DataGrid2D
Gu.Wpf.DataGrid2D copied to clipboard
Sort not working with custom cell template
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?
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!
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.
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.