【发布时间】:2017-01-04 17:26:44
【问题描述】:
我正在开发一个 SAPUI5 应用程序,并希望使用 sap.ui.comp.smarttable.SmartTable 显示数据记录列表。
摆弄Smart Table samples from the SAPUI5 Explored App 我能够让智能表在模拟服务器提供的 OData 服务上运行。
XML 视图中的智能表格
<smartTable:SmartTable tableType="ResponsiveTable"
entitySet="RecordSet" enableAutoBinding="true" />
metadata.xml的对应行
<Schema Namespace="my.namespace" sap:schema-version="1" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<ComplexType Name="ShortReference">
<Property Name="Type" Type="Edm.String" Nullable="false" sap:label="Reference type" />
<Property Name="Key" Type="Edm.String" Nullable="false" sap:label="Reference key" />
</ComplexType>
<EntityType Name="Record" sap:label="Record" sap:content-version="1">
<Key>
<PropertyRef Name="RecordID" />
</Key>
<Property Name="RecordID" Type="Edm.String" Nullable="false" sap:label="Record ID" sap:creatable="false" sap:updatable="false" />
<Property Name="ShortReference" Type="my.namespace.ShortReference" />
</EntityType>
<EntityContainer Name="my.namespace.Entities" m:IsDefaultEntityContainer="true" sap:supported-formats="atom json xlsx">
<EntitySet Name="RecordSet" EntityType="my.namespace.Record" />
</EntityContainer>
<!-- Default columns shown by Smart Table -->
<Annotations Target="my.namespace.Record" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<Annotation Term="com.sap.vocabularies.UI.v1.LineItem">
<Collection>
<Record Type="com.sap.vocabularies.UI.v1.DataField">
<PropertyValue Property="Value" Path="RecordID" />
</Record>
<!-- The following doesn't work - it won't be shown in a Smart Table column -->
<Record Type="com.sap.vocabularies.UI.v1.DataField">
<PropertyValue Property="Value" Path="ShortReference/Key" />
</Record>
<Record Type="com.sap.vocabularies.UI.v1.DataField">
<PropertyValue Property="Value" Path="ShortReference/Type" />
</Record>
</Collection>
</Annotation>
</Annotations>
</Schema>
如您所见,数据记录具有my.namespace.ShortReference 类型的复杂属性。我希望这两个属性在智能表中显示为单独的列,以便能够过滤它们。
使用<customData> 聚合确实收效甚微,如下所示,
但是由于我拥有的不仅仅是这个单一的复杂实体(包括一个具有另一个复杂实体的复杂实体),我正在寻找一种更简单、更强大的方法来实现这一目标。此外,使用<customData>,我在 p13n 对话框中的过滤能力有限(无法使用像 contains、starts with 等过滤器)。
带有自定义数据的智能表格
<smartTable:SmartTable tableType="ResponsiveTable"
entitySet="RecordSet" enableAutoBinding="true" >
<Table>
<!-- http://stackoverflow.com/questions/32114675/sapui5-smart-table-how-to-inject-my-own-column-into-smart-table-default-colum -->
<!-- Smart Table Developer Guide: https://sapui5.hana.ondemand.com/#docs/guide/bed8274140d04fc0b9bcb2db42d8bac2.html -->
<columns>
<!-- Reference -->
<Column>
<customData>
<core:CustomData
key="p13nData"
value='\{
"columnKey": "ReferenceType",
"leadingProperty": "ShortReference/Type",
"sortProperty": "ShortReference/Type",
"filterProperty": "ShortReference/Type",
"columnIndex": "9"
}' />
</customData>
<Label text="Reference type"/>
</Column>
<Column>
<customData>
<core:CustomData
key="p13nData"
value='\{
"columnKey": "ReferenceKey",
"leadingProperty": "ShortReference/Key",
"sortProperty": "ShortReference/Key",
"filterProperty": "ShortReference/Key",
"columnIndex": "10"
}' />
</customData>
<Label text="Reference key"/>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<Text text="{ShortReference/Type}" />
<Text text="{ShortReference/Key}" />
</cells>
</ColumnListItem>
</items>
</Table>
</smartTable:SmartTable>
那么,这甚至可能实现吗?还是我必须展平我的 OData 实体?
如果更容易的话,我也会更改为普通的sap.m.Table。我选择 Smart Table 是因为它具有排序、过滤、分组功能和变体管理(我需要所有这些)。
【问题讨论】:
标签: annotations odata sapui5