cancel
Showing results for 
Search instead for 
Did you mean: 

Sapui5 sap.m.search multiple item search

former_member198924
Participant
0 Kudos

Hi All,

          I have a search field in that field i have to enter id means it should search that particular id and if i give name means it should show that particular person name only. please assist me.

Accepted Solutions (0)

Answers (6)

Answers (6)

sandroramos
Active Participant

Hi,

You have to create the filter like new sap.ui.model.Filter({ filters: [...], and: true|false }), as mentioned in SAPUI5 SDK - Demo Kit


var searchValue = oEvent.getParameter("query");


var filters = [ new sap.ui.model.Filter("Id", sap.ui.model.FilterOperator.Contains, searchValue),

                       new sap.ui.model.Filter("Name", sap.ui.model.FilterOperator.Contains, searchValue) ];

oFilter = new sap.ui.model.Filter( filters, false ); //False means it will apply an OR logic, if you want AND pass true

//Get binding of component and apply it, let's suppose it's a List

this.getView().byId("list").getBinding("items").filter(oFilter); //

Regards,

Sandro Ramos

Former Member
0 Kudos

you mean you have two search feilds where in one you enter id and in another you enter Name at the same time..? and it should filter based on those two right..?

former_member198924
Participant
0 Kudos

Hi Naveen,

yes, when i enter name it should filter based on the name and when i enter the Id it should filter based on the Id. please give some suggestion.

santhu_gowdaz
Active Contributor
0 Kudos

Refer this thread, it will resolve your issue,

SAPUI5: How to filter data with 2 or more values - Stack Overflow

Former Member
0 Kudos

Hi,

it may help you,

var dropdownval=oDropdown.getValue();

var oFilters = [new sap.ui.model.Filter("ID",sap.ui.model.FilterOperator.EQ, dropdownval)];

    alert(oFilters);

    sap.ui.getCore().byId("Products").bindRows("/Products",null,null,oFilters);

"Products" is the ID of the table.. i am filtering using ID entered in the dropdownbox..

former_member198924
Participant
0 Kudos

Hi Naveen,

                 You are searching Id keyword only but i have to search Id and Name. When I search Id only means its working fine but when I search name its not working. how to search multiple keywords in searchfield

former_member182372
Active Contributor
0 Kudos

that is not about sap.m.SearchField, that is more about filtering logic in binding i guess.

in seach event assemble a filter array and pass it to filter function of the binding

          

var filterValue = oControlEvent.getParameter("query");

binding.filter([

                new sap.ui.model.Filter("userName", sap.ui.model.FilterOperator.EQ, filterValue),

                new sap.ui.model.Filter("userID", sap.ui.model.FilterOperator.EQ, filterValue)]);

former_member198924
Participant
0 Kudos

Hi Maksim,

                  Thank you, I'm trying this filtering logic. once its done let you know.

former_member198924
Participant
0 Kudos

Hi Maksim,

                    I tried but its not working fine.This is my function. Where I'm doing wrong.

InDetails_Search: function(oEvent) {

    var tpmla = oEvent.getParameter("newValue");

       var filters = new Array();

       var oFilter = new sap.ui.model.Filter("Id", sap.ui.model.FilterOperator.Contains, tpmla);

       filters.push(oFilter);

       this.oList = sap.ui.getCore().byId("list");

       this.oList.getBinding("items").filter(filters);

  },

former_member182372
Active Contributor
0 Kudos

does tpmla  has a right value when you debug?

does the structure bound to items has property Id?

any errors in console?

Qualiture
Active Contributor
0 Kudos

Can you show some code with what you have tried so far?

seVladimirs
Active Contributor
0 Kudos

Hi,

Kindly ask you to share your code snippet.

Regards,

Vladimirs