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
wherex.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!