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

Custom Sort a column: Sort/Group/FilterMemberPath containing indexer expression

1 Answer 59 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bas
Top achievements
Rank 1
Bas asked on 08 May 2014, 08:06 AM
I'm building a way to generate columns based on an IEnumerable inside a ViewModel bound to a single row. 
When creating a cell element, the DataContext of that element is set to something based on a property path.

Consider the following example:

class Order {
       public List<OrderLine> Lines { get; }
}
 
class OrderLine {
        public int Index { get; }
      public string Data { get; }
}
  • A GridViewRow would be bound to an Order object.
  • For each line in this example a column will be created.

To achieve this, I created a custom column:

public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
{
       // more code to create item etc.
       item.SetBinding(FrameworkElement.DataContextProperty,
           new Binding(DataMemberBindingPath) { Source = dataItem });
}

The DataMemberBindingPath contains something like Lines[0] or Lines[1]. This works fine since the WPF data binding engine can handle this. When I try to define the SortMemberPath containing an Indexer, nothing happens and the expression does not seem to be parsed.

Looking at the GridViewColumn source code, there is a method of interest:

internal virtual Expression CreateSortKeyExpression(ParameterExpression parameterExpression, ExpressionBuilderOptions options)
    {
        var builder = CreateBuilder(parameterExpression, this.EffectiveSortMemberType, this.EffectiveSortMemberPath, options);
 
        return builder.CreateMemberAccessExpression();
    }

However the method is Internal and I cannot override this to allow working with indexers.

Is there any workaround available to override the sort behavior for a custom column?

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 09 May 2014, 11:38 AM
Hello,

You can check the possibility to define your own generic SortDescriptor and add it to RadGridView.SortDescriptors colleciton. How do you consider this option?

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Bas
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or