cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Filter with case insensitivity

Former Member
0 Likes
9,062

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

Accepted Solutions (1)

Accepted Solutions (1)

sebastianraemsch
Product and Topic Expert
Product and Topic Expert

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

Answers (3)

Answers (3)

former_member82178
Active Participant
0 Likes

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

yogesh_beria
Product and Topic Expert
Product and Topic Expert
0 Likes

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

sumita_nagpal
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Yogesh,

I have the same issue. I tried your logic but it still doesn't work.

It takes the query lower case method but doesn't work with odata tolower.

Can you suggest what else can be done?

Thanks

ChrisSolomon
Active Contributor
0 Likes

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

Former Member
0 Likes

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