SAPUI5:当我向智能表添加自定义列时,它们不会显示在过滤器选项卡中

时间:2017-12-07 16:32:21

标签: annotations odata sapui5 data-annotations smart-table

我想使用带有命名模型的智能表。如果我们使用命名模型,那么它不会显示数据。一种可能性是使用自定义列表和自定义列。但是,只要我使用自定义列表,它就会显示数据,但它会从“过滤器,组和排序”选项卡中删除已定义的自定义列。这意味着在P13N对话框中,您可以只使用列的位置进行播放(只要为所有字段定义自定义列,它就会从P13N对话框中删除“过滤,分组和排序”选项卡)。

由于某些原因,我需要使用命名模型。然后我需要使用自定义列表项和列。现在的问题是我如何在P13N对话框中的过滤,排序和分组选项卡中保留这些字段或列。

<smartTable:SmartTable id="__smartTableMlst" entitySet="ProjectHeaderMstSet" tableBindingPath="TableMlstJsonModel>/ProjectHeaderMstSet"
header="{i18n>tableMlstTitle}" showRowCount="true" tableType="Responsive" showFullScreenButton="false" useVariantManagement="false"
enableAutoBinding="true" ignoredFields="ProjectDefinition,Method,Refnumber" useExportToExcel="false"
initiallyVisibleFields="MilestoneNumber,Description,OffsetMilestoneDate,OffsetMilestoneDateUnit">
<smartTable:customToolbar>
    <m:OverflowToolbar design="Transparent">
        <m:ToolbarSpacer/>
        <m:Button type="Transparent" press="onRefreshMlstBtnPress" icon="sap-icon://refresh" tooltip="{i18n>refreshBtnTooltip}"/>
        <m:Button type="Transparent" press="onAddMlstBtnPress" icon="sap-icon://add" tooltip="{i18n>createBtnTooltip}"
            enabled="{objectView>/tableMlstBtnAddEnabledFinal}"/>
        <m:Button type="Transparent" press="onDeleteMlstBtnPress" icon="sap-icon://delete" tooltip="{i18n>deleteBtnTooltip}"
            enabled="{objectView>/tableMlstBtnDelEnabledFinal}"/>
    </m:OverflowToolbar>
</smartTable:customToolbar>
<m:Table id="tableMlst" mode="MultiSelect" busy="{objectView>/tableMlstBusy}">
    <m:columns>
        <m:Column>
            <m:customData>
                <core:CustomData key="p13nData" value='\{"columnKey": "MilestoneNumber", "leadingProperty": "MilestoneNumber"}'/>
            </m:customData>
            <m:Text text="{/#ProjectHeaderMst/MilestoneNumber/@sap:label}"/>
        </m:Column>
    </m:columns>
    <m:items>
        <m:ColumnListItem type="Navigation" press="onPress">
            <m:cells>
                <m:Text text="{path: 'TableMlstJsonModel>MilestoneNumber', formatter: '.formatter.intNumber'}"/>
                <m:Text text="{TableMlstJsonModel>Description}"/>
                <m:Text text="{TableMlstJsonModel>OffsetMilestoneDate}"/>
                <m:Text text="{TableMlstJsonModel>OffsetMilestoneDateUnit}"/>
                <m:Text text="{TableMlstJsonModel>Activity}"/>
                <m:Text text="{TableMlstJsonModel>ActivityName}"/>
                <m:Text text="{TableMlstJsonModel>Aedat}"/>
                <m:Text text="{TableMlstJsonModel>Aenam}"/>
                <m:Text text="{TableMlstJsonModel>Erdat}"/>
                <m:Text text="{TableMlstJsonModel>Ernam}"/>
                <m:Text text="{TableMlstJsonModel>MlstSmlnr}"/>
                <m:Text text="{TableMlstJsonModel>Network}"/>
                <m:Text text="{TableMlstJsonModel>NetworkName}"/>
            </m:cells>
        </m:ColumnListItem>
    </m:items>
</m:Table>
</smartTable:SmartTable>

我知道智能表中注释文件的用法,但是可以使用带有命名JSON模型的注释文件吗?在下图中,您可以看到如何从筛选器列表中删除MilestoneNumber。

You can see how the MilestoneNumber has been removed from the filter list

1 个答案:

答案 0 :(得分:2)

您只需在自定义列中传递filterPropertysortProperty即可。您甚至可以使用列的起始位置或其可见性。

这些是你答案的关键点

我为你的代码的两列添加了它们。请注意,通过定义列,属性initiallyVisibleFields将被忽略。然后你需要传递Column的可见性,如下所示:

以下是修改后的代码:

    <smartTable:SmartTable id="__smartTableMlst" entitySet="ProjectHeaderMstSet" tableBindingPath="TableMlstJsonModel>/ProjectHeaderMstSet"
header="{i18n>tableMlstTitle}" showRowCount="true" tableType="Responsive" showFullScreenButton="false" useVariantManagement="false"
enableAutoBinding="true" ignoredFields="ProjectDefinition,Method,Refnumber" useExportToExcel="false">
<smartTable:customToolbar>
<m:OverflowToolbar design="Transparent">
<m:ToolbarSpacer/>
<m:Button type="Transparent" press="onRefreshMlstBtnPress" icon="sap-icon://refresh" tooltip="{i18n>refreshBtnTooltip}"/>
<m:Button type="Transparent" press="onAddMlstBtnPress" icon="sap-icon://add" tooltip="{i18n>createBtnTooltip}"
enabled="{objectView>/tableMlstBtnAddEnabledFinal}"/>
<m:Button type="Transparent" press="onDeleteMlstBtnPress" icon="sap-icon://delete" tooltip="{i18n>deleteBtnTooltip}"
enabled="{objectView>/tableMlstBtnDelEnabledFinal}"/>
</m:OverflowToolbar>
</smartTable:customToolbar>
<m:Table id="tableMlst" mode="MultiSelect" busy="{objectView>/tableMlstBusy}">
<m:columns>
<m:Column visible="true">
<m:customData >
<core:CustomData key="p13nData" value='\{"sortProperty": "MilestoneNumber", "filterProperty": "MilestoneNumber", "columnKey": "MilestoneNumber", "leadingProperty": "MilestoneNumber", "columnIndex":"0"}'/>
</m:customData>
<m:Text text="{/#ProjectHeaderMst/MilestoneNumber/@sap:label}"/>
</m:Column>
<m:Column visible="false">
<m:customData>
<core:CustomData key="p13nData" value='\{"sortProperty": "Description", "filterProperty": "Description", "columnKey": "Description", "leadingProperty": "Description", "columnIndex":"1"}'/>
</m:customData>
<m:Text text="{/#ProjectHeaderMst/Description/@sap:label}"/>
</m:Column>
</m:columns>
<m:items>
<m:ColumnListItem type="Navigation" press="onPress">
<m:cells>
<m:Text text="{path: 'TableMlstJsonModel>MilestoneNumber', formatter: '.formatter.intNumber'}"/>
<m:Text text="{TableMlstJsonModel>Description}"/>
<m:Text text="{TableMlstJsonModel>OffsetMilestoneDate}"/>
<m:Text text="{TableMlstJsonModel>OffsetMilestoneDateUnit}"/>
<m:Text text="{TableMlstJsonModel>Activity}"/>
<m:Text text="{TableMlstJsonModel>ActivityName}"/>
<m:Text text="{TableMlstJsonModel>Aedat}"/>
<m:Text text="{TableMlstJsonModel>Aenam}"/>
<m:Text text="{TableMlstJsonModel>Erdat}"/>
<m:Text text="{TableMlstJsonModel>Ernam}"/>
<m:Text text="{TableMlstJsonModel>MlstSmlnr}"/>
<m:Text text="{TableMlstJsonModel>Network}"/>
<m:Text text="{TableMlstJsonModel>NetworkName}"/>
</m:cells>
</m:ColumnListItem>
</m:items>
</m:Table>
</smartTable:SmartTable>

玩得开心