Search code examples
data-bindingsapui5smart-listing

Read OData Service and rebind List


I have a List, bound to an entityset from mainService. Same view contains a filter field. Once user enters some filtering criteria, the read should happen. I am already reading the OData entityset, results are coming back. But I have no luck to let the table be bound to that result

The binding in XML View

        <List
            id="list"
            width="auto"
            class="sapFDynamicPageAlignContent"
            items= "{/ItProjHeadSet}"

            busyIndicatorDelay="{masterView>/delay}"
            noDataText="{masterView>/noDataText}"
            mode="{= ${device>/system/phone} ? 'None' : 'SingleSelectMaster'}"
            growing="true"
            growingScrollToLoad="true"
            updateFinished=".onUpdateFinished"
            selectionChange=".onSelectionChange">

Then, when the GO button of the smart filter bar is clicked, I am triggering the onSearch event as follows:

        onSearchProjects : function (oEvent) {
        var oMasterPage = this.getView().byId("masterPage");
        var that = this;
        
        var aTokens = this._oMultiInput.getTokens();
        var aMultiFilters = aTokens.map(function (oToken) {
            var oProperties = oToken.data("range");
            return new Filter({
                path: oProperties.keyField,
                operator: FilterOperator[oProperties.operation],
                value1: oProperties.value1,
                value2: oProperties.value2
            });
        });         
        
        oMasterPage.setBusy(true);

        //Filter
        this.getOwnerComponent().getModel().read("/ItProjHeadSet", {
            filters: aMultiFilters,
            success: function (oData) {
                var list = that.getView().byId("list");
                var projectModel = new JSONModel(oData);
                
                var oModel = that.getView().getModel("/ItProjHeadSet");
                oModel.setData(projectModel);
                oModel.updateBindings(true);
                
            error: function (oData) {
                MessageToast.show(that.getResourceBundle().getText("noProjectsFetched"));
            }
        });
        oMasterPage.setBusy(false);
        
    },

The problem then is that although I am receiving the corresponding successful results in the read, the setData seems that it is happening to a different model than the one bound to the list. Am I doing the right model update in the Success read?

Regards, Martin


Solution

  • Solved by my own, by getting the list binding then applying filters:

    List.getBinding("items").filter(aMultiFilters, "Application");
    

    then there was no need to getOwnerComponent and all that