Skip to Content

Change SmartFilterBar input from Multi to Single Value

We are developing an ALP app in WebIDE which consumes xsodata. We want one of the filters on the Smart Filter Bar to only accept a single value instead of multiples. The Smart Filter Bar is automatically rendered by the annotations based on the metadata, however we are unable to add the v2 annotation sap:filter-restriction="single-value" which supposedly controls this area.

Upon checking the SmartFilterBar control on the API Reference (https://sapui5.netweaver.ondemand.com/sdk/#/api/sap.ui.comp.smartfilterbar.SmartFilterBar/annotations/FilterExpressionType), I saw that we could add the v4 annotation com.sap.vocabularies.Common.v1.FilterExpressionRestriction to the annotations on the app and set AllowedExpressions to SingleValue. However, I couldn't find that annotation on the Annotation Modeler. Additionally, when checking the content of the Vocabulary (https://wiki.scn.sap.com/wiki/display/EmTech/OData+4.0+Vocabularies+-+SAP+Common#FilterExpressionRestrictionType), I noticed that the annotation FilterExpressionRestriction suggested by the API Reference is actually deprecated, being replaced by Capabilities.FilterRestrictions. But this Vocabulary doesn't mention anything about single/multi values (https://www.odata.org/blog/introducing-a-capabilities-vocabulary/).

Could someone shed some light on how I can set a single field on the filter to allow only a single value?

Best regards,

André

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Sep 18, 2018 at 01:48 PM

    Have you tried a redefinition of the DEFINE method in the implementing class of the OData service?

    If you do something like this (this example is for a date field):

    method DEFINE.
    
    DATA: lo_entity_type TYPE REF TO /iwbep/if_mgw_odata_entity_typ,
              lo_property    TYPE REF TO /iwbep/cl_mgw_odata_property,
              lo_annotation  TYPE REF TO /iwbep/if_mgw_odata_annotation.
    
        super->define( ).
    
        lo_entity_type = model->get_entity_type( iv_entity_name = '[ODataServiceName]Type' ).
        lo_property ?= lo_entity_type->get_property( iv_property_name = '[FieldYouWantToFilter]' ).
    
        CALL METHOD lo_property->/iwbep/if_mgw_odata_annotatabl~create_annotation
          EXPORTING
            iv_annotation_namespace = /iwbep/if_mgw_med_odata_types=>gc_sap_namespace
          RECEIVING
            ro_annotation           = lo_annotation.
    
        lo_annotation->add( iv_key = 'display-format' iv_value = 'Date' ).
        lo_annotation->add( iv_key = 'filter-restriction' iv_value = 'single-value' ).
    
        CALL METHOD lo_property->/iwbep/if_mgw_odata_property~set_type_edm_datetime.
    
        CALL METHOD lo_property->/iwbep/if_mgw_odata_property~set_internal_type
          EXPORTING
            iv_type = cl_abap_typedescr=>typekind_date.
    
    
      endmethod.

    You'll end up with this in your ALP filter.


    capture.png (6.4 kB)
    Add comment
    10|10000 characters needed characters exceeded