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

[Solved] Filterable() usage w/DataTable source

2 Answers 87 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.
Jason
Top achievements
Rank 1
Jason asked on 31 Mar 2011, 10:12 PM
None of the GridFilterDescriptorFactory<TModel> Add methods play nice with DataRows, so I ended up having to use reflection to wedge in a solution:

public static class GridFilterDescriptorFactoryExtensions
{
    public static GridFilterStringDescriptorBuilder Add<T>(this GridFilterDescriptorFactory<T> factory, string columnName) where T : class
    {
        var composite = new CompositeFilterDescriptor
        {
            LogicalOperator = FilterCompositionLogicalOperator.And
        };
 
        var descriptor = new FilterDescriptor { Member = columnName };
 
        composite.FilterDescriptors.Add(descriptor);
 
        var pi = typeof(GridFilterDescriptorFactory<T>).GetProperty("Filters", BindingFlags.Instance | BindingFlags.NonPublic);
        if (pi != null)
        {
            var filters = (IList<CompositeFilterDescriptor>)pi.GetValue(factory, null);
            filters.Add(composite);
        }
 
        return new GridFilterStringDescriptorBuilder(composite);
    }
}

DataTable support seems to be getting better throughout the MVC grid, it would be nice to have filtering support added as well. Thanks!

2 Answers, 1 is accepted

Sort by
0
Poubelle
Top achievements
Rank 1
answered on 06 Apr 2011, 06:07 PM
Hello Jason,

Do you think it is possible to explain and show us your solution, because at this time I’ve the same problem and I can not find a solution.
How you apply your class GridFilterDescriptorFactoryExtensions in the solution?
Thanks for your help
0
Jason
Top achievements
Rank 1
answered on 18 May 2011, 03:17 PM
As long as you're using the extension's namespace in the view, you should just be able to use it like the normal filtering syntax, although with column names instead of lambdas for properties:

.Filterable(filtering => filtering.Filters(filters =>
{
    filters.Add(columnName).IsEqualTo(value);
}))
Tags
Grid
Asked by
Jason
Top achievements
Rank 1
Answers by
Poubelle
Top achievements
Rank 1
Jason
Top achievements
Rank 1
Share this question
or