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

Kendo DataSource - Using CompositeFilterDescriptor for filtering data

1 Answer 1178 Views
Grid
This is a migrated thread and some comments may be shown as answers.
VBW
Top achievements
Rank 1
VBW asked on 06 Apr 2019, 11:03 AM

Hello,

I'm using Kendo Grid that displays a set of data based on different filter criteria (Textboxes and DropDownLists values).

I was wondering if using CompositeFilterDescriptor is an ideal way of filtering data instead of using a standard LINQ approach. 

Examples provided below.

I've tested multiple queries with Kendo Filtering with lots of criteria and different kind of operators (equal, contains, greaterThan etc..) and everything looks fine. Will I face any limitations with this approach?

 

The standard LINQ approach:
(Controller)

 

var query =
(from x in products where
x.ProductName == textSearch ||                      
x.Model == textSearch ||                      
x.Category == dropDownValue||                      
x.Seller == dropDown2Value||                      
x.Country == textSearch ||                      
x.Description == textSearch
select new Product(){
ProductId = x.ProductId,
ProductName =  x.ProductName,
Category = x.Category,
Seller = x.Seller,
Country = x.Country,
Description = x.Description
}).ToDataSourceResult(request);

 

 

The Kendo Filtering approach:

(Controller)

CompositeFilterDescriptor filterDescriptor = new CompositeFilterDescriptor
            {
                LogicalOperator = FilterCompositionLogicalOperator.Or,
                FilterDescriptors = new FilterDescriptorCollection()
                {
                    new FilterDescriptor(){Member = "Product", Operator = FilterOperator.IsEqualTo, Value = textSearch},
                    new FilterDescriptor(){Member = "Model", Operator = FilterOperator.IsEqualTo, Value = textSearch},
                    new FilterDescriptor(){Member = "Category", Operator = FilterOperator.IsEqualTo, Value = dropDownValue},
                    new FilterDescriptor(){Member = "Seller", Operator = FilterOperator.IsEqualTo, Value = dropDown2Value},
                    new FilterDescriptor(){Member = "Country", Operator = FilterOperator.IsEqualTo, Value = textSearch},
                    new FilterDescriptor(){Member = "Description", Operator = FilterOperator.IsEqualTo, Value = textSearch},
                }
            };
 
request.Filters.Add(filterDescriptor);
 
 var query = (from x in products
select new Product()
{
ProductId = x.ProductId,
ProductName =  x.ProductName,
Category = x.Category,
Seller = x.Seller,
Country = x.Country,
Description = x.Description
}).ToDataSourceResult(request);

 

Thank you!

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 09 Apr 2019, 11:27 AM
Hello Vasilis,

Internally the ToDataSourceResult creates a Linq expression to filter the data. In other words, both approaches do the very same thing, the only difference is the configuration. You should not face any troubles using either of the approaches.

I would suggest you to use the configuration which is more self explanatory for you and in future will cause less confusion.


Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
VBW
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or