on 10-04-2015 7:40 AM
Hello,
We are trying to implement multiple filters for searchField as below:
var filters = [];
var query = this.getView().byId("searchField").getValue();
if(query && query.length > 0)
{
filters = [new sap.ui.model.Filter("Firstname", sap.ui.model.FilterOperator.EQ, query),
new sap.ui.model.Filter("Lastname", sap.ui.model.FilterOpeator.EQ, query)];
}
this.getView().byId("list").getBinding("items").filter(new sap.ui.model.Filter(filters, false));
The single filter is working.
Seeking help.
Regards,
Ajay
Hi Ajay,
Filter is the property which can associated with n number of filter condition.
For ex
filters = [new sap.ui.model.Filter("Firstname", sap.ui.model.FilterOperator.EQ, query),
new sap.ui.model.Filter("Lastname", sap.ui.model.FilterOpeator.EQ, query)];
}
this.getView().byId("list").getBinding("items").filter(filters);
Use this...
First it will check all the records inside this filter array. And it will return the appropriate results to you.
If you want or operator, you should create one radio button to specify the filter,
For ex,
1. FilterbyFirstName 2.Filterbysecondname
According to the selection add filter to the array.
Thanks,
Karthik A
Thanks,
Karthik A
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sai,
I need filters on client side only.
But I as per my understanding, same filter logic should be there at back end too. Right?
I am using OData model.
When I do filter with OR condition, i.e pushing two filters as below:
http://<server -ip>:<port>/<------path----->/ServiceUrl/EntitySet?$filter=FirstName eq 'Abc' or LastName eq 'Abc'
Then, when we debug at back end, this OR condition is not at all hitting the filter_options condition where the filter logic is present for the both properties.
Can you please tell me any other changes at back end for this OR condition to work.
Regards,
Ajay
Hi Ajay,
http://<server -ip>:<port>/<------path----->/ServiceUrl/EntitySet?$filter=(FirstName eq 'Abc' or LastName eq 'Abc')
You are doing serverside filtering here.If you need only client side filtering.Get data from odata and put in json model.Odata model is server side model and json model is client side model.
Refer these threads for client side filtering
Regards
Hi Ajay,
From ABAP side filter...you should refer below link
http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/50ad7227-68a9-2e10-b191-
905cb9b6c31a?QuickLink=index&overridelayout=true&52175262718629
Thanks,
Karthik A
Will this help? JS Bin - Collaborative JavaScript Debugging
You can search using LastName / FirstName.
Regards,
Sai Vellanki.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ajay,
If you want both filters to work, then try this -
this.getView().byId("list").getBinding("items").filter(new sap.ui.model.Filter(filters, true));
If you use false, the 'or' conjunction will be applied. If it is true then 'and' conjunction will be applied.
Check the API for more info: JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.Filter
Regards,
Sai Vellanki.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ajay,
Got it, try like this -
var filters = [];
var query = this.getView().byId("searchField").getValue();
if(query && query.length > 0)
{
var oFilter1 = [new sap.ui.model.Filter("Firstname", sap.ui.model.FilterOperator.EQ, query),new sap.ui.model.Filter("Lastname", sap.ui.model.FilterOperator.EQ, query)];
var allFilters = new sap.ui.model.Filter(oFilter1, false);
filters.push(allFilters);
}
this.getView().byId("list").getBinding("items").filter(filters, "Application");
Regards,
Sai Vellanki.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.