如何修改smartfilterbar过滤器?

时间:2020-09-09 08:20:40

标签: sapui5

我已经定义了一个智能过滤栏,如下所示:


<smartFilterBar:SmartFilterBar id="smartFilterBar" entitySet="DamageReportSet" persistencyKey="SmartFilter_Explored" initialized="onFilterInit">
    <!-- layout data used to make the table growing but the filter bar fixed -->
    <smartFilterBar:layoutData>
        <FlexItemData shrinkFactor="0"/>
    </smartFilterBar:layoutData>
    <smartFilterBar:controlConfiguration>
        <smartFilterBar:ControlConfiguration key="Id" visibleInAdvancedArea="true" preventInitialDataFetchInValueHelpDialog="true" index="1"/>
        <smartFilterBar:ControlConfiguration key="Plant" visibleInAdvancedArea="true" preventInitialDataFetchInValueHelpDialog="true" index="2" id="plantFilterBox">
            <smartFilterBar:defaultFilterValues>
                <smartFilterBar:SelectOption low="{appView>/Role/Plantid}"></smartFilterBar:SelectOption>
            </smartFilterBar:defaultFilterValues>
        </smartFilterBar:ControlConfiguration>      
</smartFilterBar:SmartFilterBar>

在某些情况下,{appView>/Role/Plantid}属性为空。现在的问题是,如何修改智能过滤器栏并删除默认值或过滤器为空时的过滤器!?。

实际上,当它为空时,它将为空值应用过滤器!

enter image description here

我尝试了类似的方法,但没有答案:

onFilterInit: function(oEvent){
    this.byId("plantFilterBox").destroyDefaultFilterValues();
    oEvent.getSource().clearVariantSelection();
}

1 个答案:

答案 0 :(得分:0)

最后我找到了一种方法:


onFilterInit: function (oEvent) {
    var oFilterBar = oEvent.getSource(),
        oFilterData = oFilterBar.getFilterData(),
        oAppViewModel = this.getOwnerComponent().getAggregation("rootControl").getModel("appView");
    if (!oFilterData) {
        oFilterData = {};
    }
    if (oAppViewModel.getProperty("/Role/Plantid") === "" || !oAppViewModel.getProperty("/Role/Plantid")) {
        oFilterData.Plant = {
            items: [],
            ranges: [],
            value: null
        };
        this.byId("plantFilterBox").removeAllDefaultFilterValues();
    }
    oFilterBar.setFilterData(oFilterData, true);
}
相关问题