Skip to Content
avatar image
Former Member

Apply filter with * selection property in sap ui5

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • May 10, 2017 at 10:45 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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

  • May 10, 2017 at 01:26 PM

    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

    Add comment
    10|10000 characters needed characters exceeded