Search code examples
sapui5

How to do oData client filter in sap.m.SelectDialog?


I'm using sap.m.SelectDialog with sap.ui.model.odata.v2.ODataModel, the implementation of search in SelectDialog follows the sample

    handleSearch: function(oEvent) {
        var sValue = oEvent.getParameter("value");
        var oFilter = new Filter("Name", sap.ui.model.FilterOperator.Contains, sValue);
        var oBinding = oEvent.getSource().getBinding("items");
        oBinding.filter([oFilter]);
    },

handleSearch will trigger substringof method of EntitySet, But our oData service did not implement substringof, skip, top.

So my question is since front-end has get the whole data, can I do filter in client side?


I tried to set DefaultOperationMode in handleSearch:

this._oModel.sDefaultOperationMode = "Client";

not working.

Also tried to operate data in model directly, but this._oModel.oData returned not the whole data. but when I scroll down, new items are added with no new GET is triggered. Feel very confused about this.


BTW, if this can be done, how to hide search box in SelectDialog, the corresponding method seems not provided.


Solution

  • Thanks to @Medera, found an elegant way:

        items="{
            path: '/PackageSet',
            parameters: {operationMode: 'Client'}
        }">
    

    Also marked my questions as duplicate.


    @Not recommend

    Thanks to @Jorg, fixed this by changing oData model to JSON model:

    this._oModel.read("/PackageSet", {
        success: this.successGetPackgeCallback.bind(this), 
        error: this.errorCallback.bind(this)
    });
    
    successGetPackgeCallback: function(oResult) {
        var oModel = new JSONModel(oResult.results);
    
        this.selectDialog.setModel(oModel);
    },
    

    The OData model is a server-side model, meaning that the data set is only available on the server and the client only knows the currently visible (requested) data. Operations, such as sorting and filtering, are done on the server.

    The JSON model is a client-side model and, therefore, intended for small data sets, which are completely available on the client.