Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
245
Sorting by an alternative column
posted

Hi,

We have an ObservableCollection of ViewModels bound to a XamDataGrid. This viewModel holds a number of string based values that are exposed as public properties complete with PropertyChanged syntax. These string based values are set from a numeric property on the same viewModel via a ValueConverter when the ViewModel is created. We do this in order to improve performance (as recommended by Infragistics), otherwise scrolling between rows makes the grid unusable as the ValueConverters are continuously called. By setting them when the viewModel is created, we 'bloat' our viewModel with what is a numeric and textual representation of the same value in order to ensure that the ValueConverters will not be needed at the XamDataContext field level.

This presents a problem to us. In this example, I have a viewModel with a 'Quantity' property and a 'QuantityText' property. We use the QuantityText property as a column on the grid. When we sort the QuantityText we do not want this:

  • 1M
  • 10M
  • 7M
  • 9M

We want this:

  • 1M
  • 7M
  • 9M
  • 10M

To get this, I simply want the QuantityText column to sort by the Quantity property on the rows DataContext instead. That ought to be simple.

So far though, I have had no luck in finding a reasonable answer having trawled through endless number of forum posts.

I cannot use an IComparer instance because I only get the QuantityText values passed into X and Y. Unfortunately, The XamDataGrid doesn't work like the XamGrid where we are given the entire DataContext in X and Y, meaning we could then sort appropriately on the relevant viewModel properties.

I have also tried an answer where a GroupEvaluator is used to provide a custom IComparer, but this is no good either because I don't have any grouping on the grid.

I am somewhat loathe to have to write code in the code-behind or in a behaviour in order to get at the GridSorting event and manage it myself - I don't believe it's reasonable that customers would be required to go to such lengths to complete a relatively simple operation on a well-established grid.

Can you please advise what I can do here?

Thanks,
Russell