我在我的项目中使用SmartTable。
我需要在开始时从后端请求一些数据,然后在前端处理接收到的数据。
通过数据,我需要从后端发送一些过滤器。
所以我需要在开始时操作模式Server
,并在数据出现后将其更改为Client
我的智能表 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"));
},
在onInit中设置侦听器,以在数据接收后更改操作模式
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));
我还尝试通过以下方式更改操作模式
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
但它不起作用。
如果我在收到数据后进行一些过滤,仍然会请求后端。
通过从一开始就Client
operationMode,onBeforeRebindTable
在请求之前被调用,但过滤器不会随batch
一起发送
创建模型后,无法更新操作模式。即使更新私有属性sDefaultOperationMode
,也不会影响现有绑定。
可以指定每个绑定的operationMode
,例如在列表中:
<List items="{path:'/myset',parameters:{operationMode:'Client'}}" ...>
并使用ListBase.bindItems
重新创建具有不同操作模式的绑定。
但是,对于SmartTable
,您必须修改内部表绑定,这可能会破坏很多东西,因此不鼓励这样做。也许智能表格不是最适合您的用例。