我有一张智能桌子。如何在智能表的一列或多列上设置初始排序顺序?
<mvc:View xmlns:m="sap.m" xmlns:mvc="sap.ui.core.mvc" xmlns:semantic="sap.m.semantic" xmlns:footerbar="sap.ushell.ui.footerbar"
xmlns:smartFilterBar="sap.ui.comp.smartfilterbar" xmlns:smartTable="sap.ui.comp.smarttable"
xmlns:app="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1"
controllerName="audi.project.definition.controller.Worklist">
<semantic:SemanticPage id="page">
<semantic:content>
<smartTable:SmartTable id="smartTable" entitySet="ProjectHeaderSet" tableBindingPath="/ProjectHeaderSet"
app:p13nDialogSettings="{sort:{items:[{
columnKey: 'Description',
operation: 'Ascending'
}]}}"
header="{i18n>/X000558}" showRowCount="true" tableType="Responsive" smartFilterId="prdefWorklistFilterBarId"
showFullScreenButton="true" useVariantManagement="false" enableAutoBinding="true" ignoredFields="WbsElement,Method,Refnumber"
initiallyVisibleFields="ProjectDefinition,Description,ZProjecttypeName,ZMsSchemeText">
<smartTable:customToolbar>
<m:OverflowToolbar design="Transparent">
<m:ToolbarSpacer/>
<m:SearchField id="searchField" tooltip="{i18n>/X000559}" width="auto" search="onSearch" liveChange="onSearchLiveChange"></m:SearchField>
<m:Button type="Transparent" press="onCreateBtnPress" icon="sap-icon://add" tooltip="{i18n>/X000053}"/>
<m:Button type="Transparent" press="onDeleteBtnPress" icon="sap-icon://delete" tooltip="{i18n>/X000058}"/>
</m:OverflowToolbar>
</smartTable:customToolbar>
<m:Table id="table" mode="MultiSelect">
<m:items>
<m:ColumnListItem type="Navigation" press="onPress"/>
</m:items>
</m:Table>
</smartTable:SmartTable>
</semantic:content>
</semantic:SemanticPage>
</mvc:View>
Run Code Online (Sandbox Code Playgroud)
唯一可能成为一种解决方案的部分在这里:
app:p13nDialogSettings="{sort:{items:[{
columnKey: 'Description',
operation: 'Ascending'
}]}}"
Run Code Online (Sandbox Code Playgroud)
感谢本页中为我的另一个问题提供的答案,我终于找到了这个问题的答案。我必须在视图的或函数applyVariant中使用函数。因此,每次启动视图或匹配路线时,我都可以调用如下函数。onBindingChangeonInit
setInitialSortOrder: function() {
var oSmartTable = this.getView().byId("mySmartTableId");
oSmartTable.applyVariant({
sort: {
sortItems: [{
columnKey: "ColumnId",
operation:"Ascending"}
]
}
});
}
Run Code Online (Sandbox Code Playgroud)
更新的解决方案
另一种可能性是使用注释。与以前的解决方案相比,使用注释有一些好处。您可以按照以下注释设置在集合上添加排序顺序:
我在这里的一条评论中找到了这张照片。
注意:不要忘记将以下定义放入注释文件中:
<Annotations xmlns="http://docs.oasis-open.org/odata/ns/edm" Target="namespace.EntityContainerName">
<Annotation Term="Common.ApplyMultiUnitBehaviorForSortingAndFiltering"/>
</Annotations>
Run Code Online (Sandbox Code Playgroud)
不要忘记namespace.EntityContainerName根据您的命名空间和实体容器的名称进行更新。
它还仅在网格表上显示排序标志!