Skip to Content

How to hide SmartTable column defined by local annotation file?

Hi,
I created a local annotation file that I use to show an entityset in a SmartTable. I want to hide some fields from the table initially. There is the function SmartTable.setInitiallyVisibleFields but the fields that are defined there are added to the fields defined in the annotation file (see docu).

How can I then define a datafield (column) in the annotation file to be not shown initially. I've tried something (see snippet below) but all of them don't work.

<Annotation Term="UI.LineItem">
    <Collection>
        <Record Type="UI.DataField">
            <PropertyValue Property="Value" Path="Zlctbukrs"/>
            <PropertyValue Property="Label" String="{@i18n>ZLCTBUKRS}"/>
        </Record>
        <Record Type="UI.DataField">
            <PropertyValue Property="Value" Path="Zlegid"/>
            <PropertyValue Property="Label" String="{@i18n>ZLEGID}"/>
        </Record>
        <Record Type="UI.DataField">
            <PropertyValue Property="Value" Path="Zcontrnbr"/>
            <PropertyValue Property="Label" String="{@i18n>ZCONTRNBR}"/>
        </Record>
        <Record Type="UI.DataField">
            <PropertyValue Property="Value" Path="Zvalidfr1"/>
            <PropertyValue Property="Label" String="{@i18n>ZVALIDFR1}"/>
        </Record>
        <Record Type="UI.DataField">
            <PropertyValue Property="Value" Path="Zvalidto1"/>
            <PropertyValue Property="Label" String="{@i18n>ZVALIDTO1}"/>
        </Record>
        <Record Type="UI.DataField">
            <PropertyValue Property="Value" Path="Zlctconkind"/>
            <PropertyValue Property="Label" String="{@i18n>ZLCTCONKIND}"/>
        </Record>
        <Record Type="UI.DataField">
            <PropertyValue Property="Value" Path="Zcondlfd"/>
            <PropertyValue Property="Label" String="{@i18n>ZCONDLFD}">
                <Annotation Term="Common.QuickInfo" String="{@i18n>ZLCTCONKIND_T}"/>
            </PropertyValue>
            <Annotation Term="Common.FieldControl" EnumMember="Common.FieldControlType/Hidden"/>
            <Annotation Term="UI.PartOfPreview"/>
            <Annotation Term="UI.Importance" EnumMember="UI.ImportanceType/Low"/>
        </Record>
    </Collection>
</Annotation>

Thx Helmut

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    Mar 16 at 12:42 PM

    Ok, I've got it. As supposed in my last comment I have to create an annotation for each property of my EntityType.

    Here is the resulting excerpt of the annotation file (just showing the first three columns)

    <Annotations Target="ZLCT_HEAD_LINE_SRV.ZLCT_CONTRACT_LIST2/Zlctbukrs">
    	<Annotation Term="Common.Label" String="{@i18n>ZLCTBUKRS}"/>
    	<Annotation Term="Common.QuickInfo" String="{@i18n>ZLCTBUKRS_T}"/>
    </Annotations>
    <Annotations Target="ZLCT_HEAD_LINE_SRV.ZLCT_CONTRACT_LIST2/Zlegid">
    	<Annotation Term="Common.Label" String="{@i18n>ZLEGID}"/>
    	<Annotation Term="Common.QuickInfo" String="{@i18n>ZLEGID_T}"/>
    </Annotations>
    <Annotations Target="ZLCT_HEAD_LINE_SRV.ZLCT_CONTRACT_LIST2/Zcontrnbr">
    	<Annotation Term="Common.Label" String="{@i18n>ZCONTRNBR}"/>
    	<Annotation Term="Common.QuickInfo" String="{@i18n>ZCONTRNBR_T}"/>
    </Annotations>
    <Annotations Target="ZLCT_HEAD_LINE_SRV.ZLCT_CONTRACT_LIST2">
    	<Annotation Term="UI.LineItem">
    		<Collection>
    			<Record Type="UI.DataField">
    				<PropertyValue Property="Value" Path="Zlctbukrs"/>
    			</Record>
    			<Record Type="UI.DataField">
    				<PropertyValue Property="Value" Path="Zlegid"/>
    			</Record>
    			<Record Type="UI.DataField">
    				<PropertyValue Property="Value" Path="Zcontrnbr"/>
    			</Record>
    		</Collection>
    	</Annotation>
    </Annotations>
    

    And here you see the result including a tooltip from I18N.

    Thank you very much Guilherme Maeda for your help and your inspiration.

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 08 at 10:38 PM

    You can use the term "com.sap.vocabularies.UI.v1.Hidden".

    Example:

    <Annotations Target="mynamespace.MyEntityType/ThisFieldIWantToHide">
      <Annotation Term="com.sap.vocabularies.UI.v1.Hidden" />
      <Annotation Term="com.sap.vocabularies.Common.v1.FieldControl" EnumMember="Common.FieldControlType/Hidden" />
    </Annotations>
    

    These are the same as the sap:visible Edmx property:

    https://openui5.hana.ondemand.com/#/topic/6c47b2b39db9404582994070ec3d57a2

    Add comment
    10|10000 characters needed characters exceeded

    • Thank you for your answer but this does not solve my problem.
      Your solution hides the field completely. I also don't see it in the list of available fields of the P13N dialog of the SmartTable. I just want to hide a column from the initially shown columns of the SmartTable but the user should be able to add it later via the P13N dialog and save her settings as a variant.

      Regards Helmut

  • Mar 15 at 08:43 PM

    In the local annotations file you can define exactly which fields are to be initially visible as columns.

    Here's an example:

    I've created a List Report app (Fiori Elements) to display the Orders entity set from the Northwind test service. Then created the following local annotations file:

    <edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
      <edmx:DataServices>
        <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="test.northwind.annotations">
          <Annotations Target="NorthwindModel.Order">
            <!--
              Here we define which fields are to be displayed by default in tables.
              (Users can select more columns via P13N).
            -->
            <Annotation Term="com.sap.vocabularies.UI.v1.LineItem">
              <Collection>
                <Record Type="com.sap.vocabularies.UI.v1.DataField">
                  <PropertyValue Property="Value" Path="CustomerID"/>
                </Record>
                <Record Type="com.sap.vocabularies.UI.v1.DataField">
                  <PropertyValue Property="Value" Path="EmployeeID"/>
                </Record>
                <Record Type="com.sap.vocabularies.UI.v1.DataField">
                  <PropertyValue Property="Value" Path="OrderDate"/>
                </Record>
                <Record Type="com.sap.vocabularies.UI.v1.DataField">
                  <PropertyValue Property="Value" Path="ShipName"/>
                </Record>
                <Record Type="com.sap.vocabularies.UI.v1.DataField">
                  <PropertyValue Property="Value" Path="ShipAddress"/>
                </Record>
                <Record Type="com.sap.vocabularies.UI.v1.DataField">
                  <PropertyValue Property="Value" Path="ShipCity"/>
                </Record>
              </Collection>
            </Annotation>
          </Annotations>
        </Schema>
      </edmx:DataServices>
    </edmx:Edmx>
    

    In this file I annotate the Order entity type to display 5 specific columns by default.

    This will make these 5 columns visible when the app is loaded. The user can then open the P13N dialog to select other fields.

    PS: If you need some field to be always requested from the OData service (say, if you programatically reads its value), then use property requestAtLeastFields of the SmartTable control.

    Add comment
    10|10000 characters needed characters exceeded

    • I think that's what Helmut Tammen is looking for, isn't it? Would it be possible to make your code available as a running example on plunkr? That would allow everybody to use your answer in their apps.

  • Mar 16 at 11:34 AM

    Hi Guilherme Maeda,

    I think I have to be more precise with my requirements cause your solution does not help me in my project.

    Here is an excerpt of my annotations file.

    <Annotations Target="ZLCT_HEAD_LINE_SRV.ZLCT_CONTRACT_LIST2">
    	<Annotation Term="UI.LineItem">
    		<Collection>
    			<Record Type="UI.DataField">
    				<PropertyValue Property="Value" Path="Zlctbukrs"/>
    				<PropertyValue Property="Label" String="{@i18n>ZLCTBUKRS}"/>
    			</Record>
    			<Record Type="UI.DataField">
    				<PropertyValue Property="Value" Path="Zlegid"/>
    				<PropertyValue Property="Label" String="{@i18n>ZLEGID}"/>
    			</Record>
    			<Record Type="UI.DataField">
    				<PropertyValue Property="Value" Path="Zcontrnbr"/>
    				<PropertyValue Property="Label" String="{@i18n>ZCONTRNBR}"/>
    			</Record>
    			<Record Type="UI.DataField">
    				<PropertyValue Property="Value" Path="Zvalidfr1"/>
    				<PropertyValue Property="Label" String="{@i18n>ZVALIDFR1}"/>
    			</Record>
    			<Record Type="UI.DataField">
    				<PropertyValue Property="Value" Path="Zvalidto1"/>
    				<PropertyValue Property="Label" String="{@i18n>ZVALIDTO1}"/>
    			</Record>
    			<Record Type="UI.DataField">
    				<PropertyValue Property="Value" Path="Zlctconkind"/>
    				<PropertyValue Property="Label" String="{@i18n>ZLCTCONKIND}"/>
    			</Record>
    			<Record Type="UI.DataField">
    				<PropertyValue Property="Value" Path="Zcondlfd"/>
    				<PropertyValue Property="Label" String="{@i18n>ZCONDLFD}">
    					<Annotation Term="Common.QuickInfo" String="{@i18n>ZLCTCONKIND_T}"/>
    				</PropertyValue>
    				<Annotation Term="Common.FieldControl" EnumMember="Common.FieldControlType/Hidden"/>
    				<Annotation Term="UI.PartOfPreview" Bool="false"/>
    				<Annotation Term="UI.Importance" EnumMember=""/>
    			</Record>
    		</Collection>
    	</Annotation>
    </Annotations>
    

    As you can see I'm setting the label from the i18n resources. For the last DataField I also set the tooltip accordingly. This is required for all fields cause of accessibility reasons.
    I know that I can set the label via the OData metadata annotations in GW but this is not option in our project. We decided to use i18n files at frontend side and use them for various purposes in the application. There should only be one source for texts and translations which are the i18n files.

    With your solution I cannot force all the columns of our about 20 SmartTables with appr. 350-400 fields to retrieve the texts for labels and tooltips from i18n files. In your example the texts for the not initially visible columns like Freight, OrderId, ... are taken from the sap:label annotation of OData metadata file.

    To fulfill my requirement I guess I have to define an annotation for each entity type and each property somehow. When I've done that I can use your approach for creating the SmartTables, correct?

    Regards Helmut

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 16 at 07:20 PM

    I understand your needs now.

    What you can do is the following:

    Use the term LineItem only to define which columns are displayed by default in the tables.
    Use the terms Label and QuickInfo directly on each property to define their translatable texts.
    (If you have that many fields, I advise you to generate the XML using a regex enabled text editor such as Notepad++).

    <Annotations Target="NorthwindModel.Order/CustomerID">
      <Annotation Term="com.sap.vocabularies.Common.v1.Label" String="{@i18n>customerIDlabel}" />
      <Annotation Term="com.sap.vocabularies.Common.v1.QuickInfo" String="{@i18n>customerIDtooltip}" />
    </Annotations>
    <Annotations Target="NorthwindModel.Order/EmployeeID">
      <Annotation Term="com.sap.vocabularies.Common.v1.Label" String="{@i18n>employeeIDlabel}" />
      <Annotation Term="com.sap.vocabularies.Common.v1.QuickInfo" String="{@i18n>employeeIDtooltip}" />
    </Annotations>
    <Annotations Target="NorthwindModel.Order/Freight">
      <Annotation Term="com.sap.vocabularies.Common.v1.Label" String="{@i18n>freightIDlabel}" />
      <Annotation Term="com.sap.vocabularies.Common.v1.QuickInfo" String="{@i18n>freightIDtooltip}" />
    </Annotations>
    

    Here's a working example:
    https://plnkr.co/a5iDzEBpPQ9loUwwNDLI

    (Former Member Thanks for suggesting Plunker!)

    Add comment
    10|10000 characters needed characters exceeded