首页 文章

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

提问于
浏览
0

我有一个智能表,它绑定到启用了自动绑定的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>

和控制器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
            });

1 回答

  • 1

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

    <smartTable:SmartTable 
    ...
                    beforeRebindTable="onBeforeRebindTable"
    ...
                </smartTable:SmartTable>
    

    并在方法上更改过滤器 .

    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);
    }
    

相关问题