Modify an element inside a cds view

1.7k views Asked by At

I want to modify an element inside a cds view in order to change the way it is displayed. I tried using virtual elements and it works fine if I take the data from a separate element (storing the original data) and put it into a new virtual element.

However I cannot figure out how to modify the element itself without displaying an redundant one in my table. If I try to hide the original one, the data is not loaded correctly. If I try to make the original element virtual it loses it's own data.

What is the correct way to achieve what I want?

1

There are 1 answers

2
Haojie On

I just did my own testing regarding how to exclude your original column on SmartTable. Below is working on my testing demo.

To exclude your original column from showing in the Column tab of Table setting dialog, there is an annotation sap:visible = false.

Redefine the Define method of your mpc_ext:

data: 
lo_entity_type type ref to /iwbep/if_mgw_odata_entity_typ,
lo_property    type ref to /iwbep/if_mgw_odata_property,
lo_annotation  type ref to /iwbep/if_mgw_odata_annotation.

super->define( ).

lo_entity_type = model->get_entity_type( 'YOUR_ENTITY_TYPE' ).

lo_property = lo_entity_type->get_property( 'YOUR_ORIGINAL_COLUMN' ) .

lo_annotation = lo_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( /iwbep/if_mgw_med_odata_types=>gc_sap_namespace ).
lo_annotation->add(
    iv_key    = 'visible'
    iv_value  = 'false'
).