Skip to Content
0

Apply filter with * selection property in sap ui5

May 10, 2017 at 07:16 AM

61

avatar image
Former Member

Hi,

I want to apply filter with * selection property in sap ui5. I couldn't get it. Normal fiter is working finely.

For suppose, If I put a filter on city name and write S*N*F*C* for filter. After filtering, It should get result : SAN FRANCISCO

Thanks in advance

Regards

Sukhram Bhamboo

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

VIPLOVE KHUSHALANI May 10, 2017 at 10:45 AM
1

HI Sukhram Bhamboo,

There is no redefine operator for this scenario .

Just create a custom filter and apply it to your list binding.

new sap.ui.model.Filter('<path on which filter needs to be applied>', <custom function >)

reference :

https://openui5.hana.ondemand.com/#docs/api/symbols/sap.ui.model.Filter.html#constructor

thanks

Viplove

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi VIPLOVE KHUSHALANI,

Thanks for your reply, But this concept is not that much clear to proceed further.

Actually I am displaying table data on sap ui5 screen using odata services. Now I am applying filter with * selection for one of my table column.

So can you explain how custom filter can be built for it and what would be path just by an example?

Regards

Sukhram Bhamboo

0

Hi Sukhram ,

So you need to apply filter on that column binding .. lets say you have input field which filter your table data on the basis of city.

view

<Input placeholder = "Enter your filter" id="filterInput" />

<Button text = "Apply" press="onApplyFilter" / >

<Table id ="table" items="{path:'/resultSet'}">

<columns>

...

<Column >

<Text text="City"/>\

</Column>

...

<columns>

<items>

<ColumnListItem>

<Text text="{city}"></ColumnListItem>

</items>

</Table>

controller

onInit:function(){},

onApplyFilter:function(){

var fValue = this.getView().byId("filterInput").getValue();

var filters = [];

var filter = new sap.ui.model.filter("city",function(value){

var split = fValue.split("*");

for(var i=0;i<split.length;i++)

{

if(value.indexOf(split[i]) > -1)

{

var index = value.indexOf(split[i]) + split[i].length ;

value = value.substr(index);

}

}

if(i=== split.length)

{return true;}

else

{return false;}

});

filters.push(filter);

this.getView().byId("table").getBinding("items").filter(filters);

}

Note : the logic for the custom filter function might not be upto the mark .. but this will make you understand how we are writing the custom filter

thanks

Viplove

0
Sharath M G May 10, 2017 at 01:26 PM
1

The filter operators are:

sap.ui.model.FilterOperator.BTFilterOperator between.

sap.ui.model.FilterOperator.ContainsFilterOperator contains

sap.ui.model.FilterOperator.EndsWithFilterOperator ends with

sap.ui.model.FilterOperator.EQFilterOperator equals

sap.ui.model.FilterOperator.GEFilterOperator greater or equals

sap.ui.model.FilterOperator.GTFilterOperator greater than

sap.ui.model.FilterOperator.LEFilterOperator less or equals

sap.ui.model.FilterOperator.LTFilterOperator less than

sap.ui.model.FilterOperator.NEFilterOperator not equals

sap.ui.model.FilterOperator.StartsWithFilterOperator starts wit

You can choose to apply according to user entry but there is no default way to interpret * and get the results accordingly.

Regards,

Sharath

Share
10 |10000 characters needed characters left characters exceeded