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

[Solved] Initialize filter dynamically

1 Answer 127 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Vinicius
Top achievements
Rank 1
Vinicius asked on 17 Nov 2011, 01:57 PM

Hi, I would like to initialize the grid filter using a GridCommand, for that I need to create an Expression Tree of type Expression<Func<T, string>> so a can pass it to the .Add method:

grid.Filters(y => y.Add(HERE))

Does anyone knows how to create this expression tree using System.Linq.Expression instead of passing a lambda expression?

1 Answer, 1 is accepted

Sort by
0
Vinicius
Top achievements
Rank 1
answered on 17 Nov 2011, 07:30 PM
Here is the solution:

ParameterExpression p = Expression.Parameter(typeof(T));
var exp = Expression.Lambda<Func<T, string>>(Expression.Property(p, filter.Member), p);
grid.Filterable(x => x.Filters(y => y.Add(exp).Contains(filter.Value.ToString())));
Tags
Grid
Asked by
Vinicius
Top achievements
Rank 1
Answers by
Vinicius
Top achievements
Rank 1
Share this question
or