SAPUI5 自动绑定智能表(带过滤器)

tar*_*ppa 2 odata sapui5

我有一个智能表,它绑定到启用了自动绑定的 oData 服务。目前,它返回实体集的所有数据。

我需要的是在从 oData 服务加载数据时过滤数据。我尝试在控制器中添加过滤器,但它不起作用。

看法

<smartTable:SmartTable id=mytable" entitySet="SampleDetail"  tableType="ResponsiveTable"
                    useExportToExcel="false" beforeExport="onBeforeExport" useVariantManagement="false" useTablePersonalisation="true"
                    header="{i18n>tickets_table_header}" showRowCount="true" persistencyKey="ticketsSmartTable_persis" enableAutoBinding="true"
                    demandPopin="true" class="sapUiResponsiveContentPadding">
</smartTable:SmartTable>
Run Code Online (Sandbox Code Playgroud)

和控制器js

var serviceURL = this.getConfiguration("myDestination");
            serviceURL = serviceURL + "sample.xsodata";
            var oModel, oView, that = this;
            var filtersDef = [];
            filtersDef.push(new Filter("STATUS", sap.ui.model.FilterOperator.NE, "D"));

            oView = this.getView();
            oModel = new sap.ui.model.odata.v2.ODataModel(serviceURL, {
                useBatch: false
            });


            oModel.read("/SampleDetail", {
                async: true,
                success: function(e) {
                    that.setModel(oModel);

                },
                error: function(e) {
                    oModel.setData({

                    });
                },
                filters: filtersDef
            });
Run Code Online (Sandbox Code Playgroud)

小智 7

您可以使用智能表的 beforeRebindTable 事件

                <smartTable:SmartTable 
...
                beforeRebindTable="onBeforeRebindTable"
...
            </smartTable:SmartTable>
Run Code Online (Sandbox Code Playgroud)

并在方法上更改过滤器。

onBeforeRebindTable: function(oSource){
    var binding = oSource.getParameter("bindingParams");
    var oFilter = new sap.ui.model.Filter("STATUS", sap.ui.model.FilterOperator.NE, "D");
    binding.filters.push(oFilter);
} 
Run Code Online (Sandbox Code Playgroud)