Search code examples
odatasapui5

How do I set the `search` URL parameter in SAPUI5 OData requests?


I want my SAPUI5 ODataModel to send OData requests of the form

https://<my-server>/<my-service>/<my-resource>?search='lalaland'

There are tons of examples how to add a filter with model.filter(new Filter(...)); but this is not what I want. Filtering means I directly address a certain property with a certain comparator. Searching means I address the resource in general and let the OData service decide which properties to search, and how.

The one thing that seems to be possible is:

model.bindRows(..., { "customData": {"search": "lalaland"}});

But this is also not what I want because that sets the search term once when the model is created, but cannot update it later on when the user enters.

Funnily, SAPUI5's own implementation of the SmartTable performs exactly the kind of query I want - but doesn't reveal a possibility how I could do that without a SmartTable.


Solution

  • Found one solution:

    oList = this.byId("list"); // or oTable
    oBindingInfo = oList.getBindingInfo("items"); // or "rows"
    if (!oBindingInfo.parameters) {
      oBindingInfo.parameters = {};
    }
    if (!oBindingInfo.parameters.custom) {
      oBindingInfo.parameters.custom = {};
    }
    oBindingInfo.parameters.custom.search = sValue;
    oList.bindItems(oBindingInfo);
    

    However, I don't specifically like the bindItems part. Looks a bit over-the-top to require this to re-bind the whole entity set again and again. So leaving this question open in case somebody has a better idea.