【问题标题】:How to show complex OData property types in sap.ui.comp.smarttable.SmartTable?如何在 sap.ui.comp.smarttable.SmartTable 中显示复杂的 OData 属性类型?
【发布时间】: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 类型的复杂属性。我希望这两个属性在智能表中显示为单独的列,以便能够过滤它们。

使用&lt;customData&gt; 聚合确实收效甚微,如下所示, 但是由于我拥有的不仅仅是这个单一的复杂实体(包括一个具有另一个复杂实体的复杂实体),我正在寻找一种更简单、更强大的方法来实现这一目标。此外,使用&lt;customData&gt;,我在 p13n 对话框中的过滤能力有限(无法使用像 containsstarts 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


    【解决方案1】:

    我已经找了一段时间的解决方案,但是我没有找到与我上面的实体结构相匹配的满意解决方案。

    因此我必须如下回答我的问题

    • 那么,这有可能实现吗?没有。
    • 或者我是否必须展平我的 OData 实体? 是的。

    我的列表概述了特定记录集并导航到详细信息页面。在我的概览列表中,我不需要每个属性,因此我创建了一个新实体 RecordOverview 来运行我的智能表。

    metadata.xml(仅显示添加和更改)

    <Schema Namespace="my.namespace" sap:schema-version="1" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
    
        ...
    
        <EntityType Name="RecordOverview" 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="ReferenceKey" Type="Edm.String" Nullable="false" sap:label="Reference key" />
        </EntityType>
    
        <EntityContainer Name="my.namespace.Entities" m:IsDefaultEntityContainer="true" sap:supported-formats="atom json xlsx">
            <EntitySet Name="RecordSet" EntityType="my.namespace.Record" />
            <EntitySet Name="RecordOverviewSet" EntityType="my.namespace.RecordOverview" />
        </EntityContainer>
    
        <!-- Default columns shown by Smart Table -->
        <Annotations Target="my.namespace.RecordOverview" 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>
                    <Record Type="com.sap.vocabularies.UI.v1.DataField">
                        <PropertyValue Property="Value" Path="ReferenceKey" />
                    </Record>
                    ...
                </Collection>
            </Annotation>
        </Annotations>
    </Schema>
    

    但是,一个不错的(副作用)效果是我不再需要在我的 XML 视图中指定列。

    XML 视图

    <smartTable:SmartTable entitySet="RecordOverviewSet" enableAutoBinding="true">
        <Table>
            <items>
                <ColumnListItem vAlign="Middle" type="Navigation" press="onListItemPressed" />
            </items>
        </Table>
    </smartTable:SmartTable>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-04
      • 2013-12-03
      • 2013-05-26
      • 2012-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多