Skip to Content
0

search function is not working in master view

Jul 09, 2017 at 06:41 AM

65

avatar image
Former Member

Hi

I created a list in master view and trying to create a search function but it is not working. Couldn't find any error in it. Please help.

This is my code

MasterView.view.xml

<SearchField
           id="searchField"
           width="100%"
           liveChange="onSearch">
</SearchField>

MasterView.controller.js

onSearch : function (evt) {
        // create model filter
        var filters = [];
        var query = evt.getParameter("query");
        if (query && query.length > 0) {
            var filter = new sap.ui.model.Filter("Swapn", sap.ui.model.FilterOperator.Contains, query);
            filters.push(filter);
        }

        // update list binding
        var list = this.getView().byId("SwapList");
        var binding = list.getBinding("items");
        binding.filter(filters); 
    }

and I set the Swapn as filterable in the OData

capture111.png (5.7 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

avatar image
Former Member Jul 10, 2017 at 04:09 AM
0

Try to use the search event instead of the livechange.

https://sapui5.hana.ondemand.com/#docs/api/symbols/sap.m.SearchField.html

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

already tried it, didn't work. Thanks

0
saurabh vakil Jul 10, 2017 at 06:35 AM
0

Are you using OData model or JSON model to bind to your list UI? If it is OData model then the above code won't work. This works only for client side model which a JSON model is.

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

OData model. Do you have any example of OData model?

0

For OData model you will have to handle the search/filter functionality in your OData service and not in the SAPUI5 app. You can only use the filter function at client side (i.e. in the UI5 app) if you use a JSON model.

0