Yousuf Mohammed
Top achievements
Rank 1
Yousuf Mohammed
asked on 15 May 2012, 09:12 PM
Hello,
I am trying to filter datasource on multiple fields.
Below is my Filter 1 -
The above javascript code works great when filtering on 1 field.
I am trying to add one more filter, the below filter should do a logical and to the results from first filter.
Basically what I want is
(TypeID = 1 OR TypeID = 2 OR TypeID = 3) AND (StatusID = 1 OR StatusID = 2)
I am trying to do local filtering. Please let me know if this is doable.
Thanks,
I am trying to filter datasource on multiple fields.
Below is my Filter 1 -
var _flt = { logic: "or", filters: [] }; $("#mySelection").find(':checkbox').each(function () { if (this.checked) { _flt.filters.push({ field: "TypeID", operator: "eq", value: parseInt(this.value) }); } }); dataSource1.query({ filter: _flt});
The above javascript code works great when filtering on 1 field.
I am trying to add one more filter, the below filter should do a logical and to the results from first filter.
var _fltStatus = { logic: "or", filters: [] };
$("#myStatusSelection").find(':checkbox').each(function () {
if (this.checked) {
_fltStatus.filters.push({ field: "StatusID", operator: "eq", value: parseInt(this.value) });
}
});
dataSource1.query({ filter: _fltStatus });
Basically what I want is
(TypeID = 1 OR TypeID = 2 OR TypeID = 3) AND (StatusID = 1 OR StatusID = 2)
I am trying to do local filtering. Please let me know if this is doable.
Thanks,
10 Answers, 1 is accepted
0
Accepted
Hello Yousuf,
It is possible to pass an array of more complex filter objects to the filter method of the dataSource. In order to illustrate this functionality I created a small example.
Alternatively in this forum topic you can find information about how to create a custom filter operator. You could use this functionality to build your own filtering logic.
Regards,
Alexander Valchev
the Telerik team
It is possible to pass an array of more complex filter objects to the filter method of the dataSource. In order to illustrate this functionality I created a small example.
Alternatively in this forum topic you can find information about how to create a custom filter operator. You could use this functionality to build your own filtering logic.
Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Yousuf Mohammed
Top achievements
Rank 1
answered on 16 May 2012, 06:51 PM
Thank you very much for your reply. I will give it a try.
0
Greg Lavelle
Top achievements
Rank 1
answered on 28 May 2012, 10:42 AM
Hi
This 'AND' and 'OR' filtering is exactly what I am looking for, although I would like to build the filter up dynamically via javascript in response to button clicks. Is there any way to do this?
This 'AND' and 'OR' filtering is exactly what I am looking for, although I would like to build the filter up dynamically via javascript in response to button clicks. Is there any way to do this?
0
Yousuf Mohammed
Top achievements
Rank 1
answered on 28 May 2012, 09:26 PM
Hi Greq,
I created dynamic filters based on the checkbox selected . Below is my code
I created dynamic filters based on the checkbox selected . Below is my code
var _fltMain = [];
var _flt = { logic: "or", filters: [] }; $("#mySelection").find(':checkbox').each(function () { if (this.checked) { _flt.filters.push({ field: "TypeID", operator: "eq", value: parseInt(this.value) }); } });
var _fltStatus = { logic: "or", filters: [] }; $("#myStatusSelection").find(':checkbox').each(function () { if (this.checked) { _fltStatus.filters.push({ field: "StatusID", operator: "eq", value: parseInt(this.value) }); } });_fltMain .push(_flt);_fltMain .push(_fltStatus);
dataSource1.query({ filter: _fltMain });
0
Greg Lavelle
Top achievements
Rank 1
answered on 29 May 2012, 12:05 PM
Thanks Yousuf, that got it working
0
Fazlur
Top achievements
Rank 1
answered on 12 Sep 2012, 08:11 AM
Can i get the same AND/OR expression in C# code. I have the following code
DataSourceRequest dsRequest = new DataSourceRequest();
FilterDescriptor newDesc = new FilterDescriptor("FirstName", FilterOperator.Contains, 'fazlur');
dsRequest.Filters.Add(newDesc);
newDesc = new FilterDescriptor("LastName", FilterOperator.Contains, 'fazlur');
dsRequest.Filters.Add(newDesc);
This gives me AND expression. But i want OR. For example
FirstName LIKE '%fazlur%' OR LastName LIKE '%fazlur%'.
Can you please help.
DataSourceRequest dsRequest = new DataSourceRequest();
FilterDescriptor newDesc = new FilterDescriptor("FirstName", FilterOperator.Contains, 'fazlur');
dsRequest.Filters.Add(newDesc);
newDesc = new FilterDescriptor("LastName", FilterOperator.Contains, 'fazlur');
dsRequest.Filters.Add(newDesc);
This gives me AND expression. But i want OR. For example
FirstName LIKE '%fazlur%' OR LastName LIKE '%fazlur%'.
Can you please help.
0
Hello,
Regards,
Daniel
the Telerik team
This is possible by using a composite descriptor e.g.
CompositeFilterDescriptor compositeDescriptor =
new
CompositeFilterDescriptor();
compositeDescriptor.LogicalOperator = FilterCompositionLogicalOperator.Or;
FilterDescriptor newDesc =
new
FilterDescriptor(
"FirstName"
, FilterOperator.Contains,
'fazlur'
);
compositeDescriptor.FilterDescriptors.Add(newDesc);
newDesc =
new
FilterDescriptor(
"LastName"
, FilterOperator.Contains,
'fazlur'
);
compositeDescriptor.FilterDescriptors.Add(newDesc);
DataSourceRequest dsRequest =
new
DataSourceRequest();
dsRequest.Filters.Add(compositeDescriptor);
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Benjamin
Top achievements
Rank 2
answered on 19 Dec 2012, 06:20 AM
after running the sample javascript to push a filter to array of filters, an error occurred
Line: 356
Error: Function expected
on
Line: 356
Error: Function expected
on
_flt.filters.push
0
Hello Benjamin,
I am afraid that the provided information is not sufficient enough in order to determine what is going wrong. Is it possible for you to reproduce the problem in jsBin/jsFiddle and send me back a link? In this way I would be able to examine your current implementation in details and assist you further.
Alternatively you may open a support ticket with a small but runnable example attached.
Kind regards,
Alexander Valchev
the Telerik team
I am afraid that the provided information is not sufficient enough in order to determine what is going wrong. Is it possible for you to reproduce the problem in jsBin/jsFiddle and send me back a link? In this way I would be able to examine your current implementation in details and assist you further.
Alternatively you may open a support ticket with a small but runnable example attached.
Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Christos
Top achievements
Rank 1
answered on 26 Mar 2019, 03:53 AM
Thank you!