marina
marina

Reputation: 1680

SAPUI5 change operationMode to client in runtime

I am using SmartTable in my project.

I need to request some data from backend at begin and then work on received data in frontend.

By data, that i need from backend i must send some filter.

So i need at begin the operationMode Server, and after data come change it to Client

My SmartTable xml

<smartTable:SmartTable id="ReportSmartTable" entitySet="OwnSet"
    tableBindingPath="/OwnSet" tableType="AnalyticalTable"
    beforeRebindTable="onBeforeRebindTable" >

onBeforeRebindTable

onBeforeRebindTable: function (oEvent) {
    console.log("onBeforeRebindTable");
    var oBindingParams = oEvent.getParameter("bindingParams");
    oBindingParams.filters.push(new sap.ui.model.Filter("Prop", "EQ", "Value"));
},

in onInit i set listener, to change the operation mode after data receiving

var oTable = this.getView().byId("ReportSmartTable"); //Get Hold of the table control
oTable.attachDataReceived(function (oEvent) { //Hits when the data is received from back-end server
    this.getModel().defaultOperationMode = "Client"; //Set operation mode to Client
    var oSource = oEvent.getSource();
    oSource.bClientOperation = true; //Set Client Operation to true
    oSource.sOperationMode = "Client"; //Set operation mode to Client
}.bind(this));

i have also tried to change operationMode by following

this.getOwnerComponent().getModel().sDefaultOperationMode = "Client";
this.getOwnerComponent().getModel().defaultOperationMode = "Client";
this.getModel().sDefaultOperationMode = "Client"; //Set operation mode to Client
this.getModel().defaultOperationMode = "Client"; //Set operation mode to Client

but it doesn't work.

If i make some filter after data is received, there still comes request to backend.

By making Client operationMode from begin, onBeforeRebindTable is called before request, but the filter is not sended with batch

Upvotes: 1

Views: 2103

Answers (1)

Carsten
Carsten

Reputation: 943

You can't update the operation mode after a model is created. Even if you update the private attribute sDefaultOperationMode, it will not affect existing bindings.

You can specify the operationMode per binding, for example in a list:

<List items="{path:'/myset',parameters:{operationMode:'Client'}}" ...>

and use ListBase.bindItems to re-create a binding with a different operation mode.

For a SmartTable, however, you'd have to modify the internal table bindings and this would probably break a lot of things, therefore it's discouraged. Maybe the Smart Table is not the best fit for your use case.

Upvotes: 1

Related Questions