on 03-09-2020 12:08 PM
Hi.
I have the following scenario.
A smartTable with two fields, one for the code and one for its description.
What I want to represent is a single field with the description that will later become a drop-down with different options defined by its code.
I want to get something like this, but only using annotations.
I know that within the SmartTable I can define a table with Smartfields to get it, but it is not what I am looking for, it has to work by annotations.
What I have is the following:
This is my SmartTable:
In the metadata we receive this:
And in the annotations we have declared the LineItems and for the code field the dropdown.
Getting the following functionality:
Reading Mode:
Edit Mode:
But here I have two problems.
In read mode, the code is represented, not its description.
In Edit mode, your displayBehavior shows the description and code, but I just want the description.
How can I get this?, just by annotations.
I answer myself, in case it serves someone.
Finally I couldn't create the dropdown exclusively by annotations, so I had to declare the table by the xml view.
My initial problem not to do it this way, is because I add rows to the table in an inelegant way through the addRow method, mixing odata and local data.
It is also a table whose data is updated with the server causing a constant rebind of the table and therefore the rows added from UI5 are removed.
Problem that is caused when I declare the table in the xml view, however we managed to correct it by overwriting the updateItems method of the table.
It is a particular scenario of our project, but for a conventional implementation the following procedure should be correct.
We need:
2 entities:
Xml view: we declare the table and the smartField.
Annotations: We define the properties of ValueList
Metadata: Required tags on the fields of the entities.
Entities:
Our dropdown is called "Tipo Posición" consisting of the ItemType and ItemDescription fields.
This is our entity for the dropdown: "TipoPosicion" with the key value fields.
XML view:
Don't forget to declare the customData library to enable smartFields.
xmlns:customData="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1"
<smartTable:SmartTable entitySet="{EntitySetTable}" width="100%" direction="Column"
tableType="ResponsiveTable" useTablePersonalisation="true"
enableAutoBinding="true" useExportToExcel="true"
editTogglable="true" customData:useSmartField="true" >
<Table id ="mainTableListaPosiciones" >
<columns>
<Column>
<customData>
<core:CustomData key="p13nData" value='\{"columnKey": "ItemType", "columnIndex":"1", "leadingProperty":"ItemType"}'/>
</customData>
<Text text="{/#EntitySetTable/ItemType/@sap:label}"/>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<smartField:SmartField value="{ItemType}" entitySet="EntitySetTable" >
<smartField:configuration>
<smartField:Configuration displayBehaviour="descriptionOnly"/>
</smartField:configuration>
</smartField:SmartField>
</cells>
</ColumnListItem>
</items>
</Table>
</smartTable:SmartTable>
Annotations:
<Annotations Target="Metadata.EntitySetTable/ItemType">
<Annotation Term="Common.ValueListWithFixedValues" Bool="true"/>
<Annotation Term="Common.ValueList">
<Record Type="Common.ValueListType">
<PropertyValue Property="CollectionPath" String="TipoPosicionSet"/>
<PropertyValue Property="Parameters">
<Collection>
<Record Type="Common.ValueListParameterInOut">
<PropertyValue Property="LocalDataProperty" PropertyPath="ItemType"/>
<PropertyValue Property="ValueListProperty" String="ItemTypeCode"/>
</Record>
<Record Type="Common.ValueListParameterDisplayOnly">
<PropertyValue Property="ValueListProperty" String="Description"/>
</Record>
<Record Type="Common.ValueListParameterInOut">
<PropertyValue Property="LocalDataProperty" PropertyPath="ItemDescription"/>
<PropertyValue Property="ValueListProperty" String="Description"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</Annotation>
</Annotations>
Metadata:
We redefined the DEFINE method of the * MPC_EXT class.
For the table entity we add the sap: text tags in the key field.
DATA(lo_entity_type) = model->get_entity_type( iv_entity_name = 'EntitySetTable' ).
DATA(lo_property) = lo_entity_type->get_property( iv_property_name = 'ItemType' ).
DATA(lo_annotation) =
lo_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( 'sap' ).
lo_annotation->add( iv_key = 'text'
iv_value = 'ItemDescription' ).
In the dropdown entity we add the tags sap:text and in its container sap:semantics = "fixed-values".
lo_entity_type =
model->get_entity_type( iv_entity_name = 'TipoPosicion' ). "#EC NOTEXT
"ItemTypeCode
lo_property = lo_entity_type->get_property( iv_property_name = 'ItemTypeCode' ).
lo_annotation =
lo_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( 'sap' ).
lo_annotation->add( iv_key = 'text'
iv_value = 'Description' ).
lo_entity_set = model->get_entity_set( iv_entity_set_name = 'TipoPosicionSet' ).
lo_annotation = lo_entity_set->create_annotation( iv_annotation_namespace = 'sap' ).
lo_annotation->add(
EXPORTING
iv_key = 'semantics'
iv_value = 'fixed-values'
).
In this way we achieve the desired result:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
70 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.