on ‎2016 Jun 03 1:37 PM
Hi Experts ,
I have a search field and List in my master page . When I am searching the list Items by typing in the search field it is working only when i enter correct case . For eg : If my list item is Rizwan , In order to search I have to type Rizwan(R beign caps ) then only its working . If I type rizwan(r being small )its not working . Is there any way to remove this case sensitivity so that it should work with either case (upper and lower ) just like in Explored search functionality .
Please help with the code if possible .
Thanks
Rizwan
Request clarification before answering.
Hi Rizwan,
Basically it depends on your model which you are using. As far as I know JSONModel can be filter case-insensitive but for oData it´s different. For oData it depends on the backend how filter is handled.
Please refer e.g. to this thread: https://scn.sap.com/thread/3511904
As a workaround, if backend is not changeable you may build several search strings in JavaScript to hit the 95% case (assuming sQuery is a String object):
var sQueryLower = sQuery.toLowerCase();
var sQueryUpper = sQuery.toUpperCase();
var sQueryUpLow = sQuery[0].toUpperCase() + sQuery.substr(1).toLowerCase();
aFilter.push(new Filter("ProductID", FilterOperator.Contains, sQueryLower));
aFilter.push(new Filter("ProductID", FilterOperator.Contains, sQueryUpper));
aFilter.push(new Filter("ProductID", FilterOperator.Contains, sQueryUpLow));
This is certainly not perfect but better then nothing if you can´t change the backend.
Best regards,
Sebastian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It seems we have a provision to set insensitive parameter in odata service. Refer below link if it can help with your context.
https://scn.sap.com/thread/3609793
Thanks
Madhu Sudhan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Naveed,
As Sebastian mentioned, it depends on your model.
JSON Model should be case insensitive. But since that is not the case, I am assuming you are using an oData Model.
You can convert your search query and the column values to either lower or upper case, compare and then use those results. Something like mentioned below:
aFilter.push(new Filter("tolower(ProductID)", FilterOperator.Contains, "'" + sQuery.toLowerCase() +
"'"));
The search query can be converted to lowercase using the javascript function and oData has 'tolower' function.
You might also want to escape the single quote character in your search parameter if your column can have values with single Quotes. e.g. Naveed's Item 1. with this:
sQuery.replace(/'/g, "''").
This is required because an odata filter passes the search string in single quotes.
Regards,
Yogesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For your "Searchfield", what does your method/function tied to your "search" event look like? What is your function doing?
Are you using FilterOperator and if so, how?
ie. are you doing something like....
aFilter.push(new Filter("ProductID", FilterOperator.Contains, sQuery));
...and straight from the API documentation on Filter...
"It also depends on the model implementation if the filtering is case sensitive or not. See particular model documentation for details."
JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.Filter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Christopher,
Thanks for the reply . I am using
var aFilter = [];
aFilter.push(new Filter("ProductID", FilterOperator.Contains, sQuery));
var items= this,getView().byId("idList").getBinding("items");
items.filter(aFilter );
Can you tell me which method I should use to resolve this issue , If possible with a sample code.
Many thanks
Naveed
| User | Count |
|---|---|
| 9 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.