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

lamba / predicate from grid filters ?

3 Answers 126 Views
GridView
This is a migrated thread and some comments may be shown as answers.
scott
Top achievements
Rank 1
scott asked on 06 Aug 2010, 05:13 PM
I have a gridview with ItemsSource set to a DataTable ... I want to get the results of filtering without actually doing the filtering ... Something like:

IENumberable<DataRow> list = from rows in Grid.ItemsSource select rows;
var newList = rows.Where(Grid.FilterDescriptors);
foreach (DataRow dr in newList)
    // Do Something

In this post: http://www.telerik.com/community/forums/aspnet-mvc/grid/grid-and-nhibernate-linq.aspx the reply from Atanas leads me to believe its easy to do ?   "You can check the implementation of the Where extension method. There is some code which builds a LambdaExpression from the filter descriptors:"

Thank you -
Scott

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 09 Aug 2010, 06:39 AM
Hello,

 You can use the grid Items to get actual grid items after filter. 

Regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
scott
Top achievements
Rank 1
answered on 09 Aug 2010, 02:08 PM
Hi Vlad.   But I want to re-use the filters via LINQ as shown and described ... Can I do this with DataTable rows ?

---------

Hi Carson Wilkins,

You can check the implementation of the Where extension method. There is some code which builds a LambdaExpression from the filter descriptors:

public static IQueryable Where(this IQueryable source, IEnumerable<IFilterDescriptor> filterDescriptors)
        {
            if (filterDescriptors.Count() > 0)
            {
                var parameterExpression = Expression.Parameter(source.ElementType, "item");

                var expressionBuilder = new FilterDescriptorCollectionExpressionBuilder(parameterExpression, filterDescriptors);
                var predicate = expressionBuilder.CreateFilterExpression();
                return source.Where(predicate);
            }

            return source;
        }

Kind regards,
Atanas Korchev
the Telerik team

-----------

Thank you -
Scott
0
Vlad
Telerik team
answered on 13 Aug 2010, 01:22 PM
Hello scott,

 There will be no problem to do this however our extension method is for IQueryable - you need to call AsQueryable():

var rows = table.Rows.AsQueryable().Where(RadGridView1.FilterDescriptors);

Kind regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
scott
Top achievements
Rank 1
Answers by
Vlad
Telerik team
scott
Top achievements
Rank 1
Share this question
or