cancel
Showing results for 
Search instead for 
Did you mean: 

Change SmartFilterBar input from Multi to Single Value

andrefernandes
Participant

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é

former_member542756
Discoverer

Maybe thomas.jung can help?

Accepted Solutions (0)

Answers (3)

Answers (3)

Hi,

Can you please share, How to add the same annotation in the CDS itself?

Thanks,

Muthu.

0 Kudos

Tried using annotations and faced the same problem. it seems they do not work as described by the documentation. see below for DisplayView

		
				<Annotation Term="Org.OData.Capabilities.V1.FilterRestrictions">
					<Record>
						<PropertyValue Property="FilterExpressionRestrictions">
							<Collection>
								<Record>
									<PropertyValue Property="Property" PropertyPath="DisplayView"/>
									<PropertyValue Property="AllowedExpressions" String="SingleValue"/>
								</Record>
							</Collection>
						</PropertyValue>
					</Record>
				</Annotation>

I will use the workaround by creating a custom Value help via the smartfilterbars custom control. Maybe others facing this issue can do the same.

mdcastle
Active Participant
0 Kudos

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.