Skip to Content
Technical Articles
Author's profile photo Krishna Kishor Kammaje

‘Dynamic Date’ control in SmartFilter

Dynamic Date is a very useful control within SmartFilter. Dynamic Date is possible ONLY within a SmartFilter. But it is very tricky to get this control to work. I got it to work recently and wanted to share this quick ‘How To’.

Step 1.

Ensure that you have a SmartFilter control

Step 2.

Within the SmartFilter ensure that you have set property ‘useDateRangeType=”true”‘.

Step 3.

Ensure that oData property is of type Edm.DateTime.

Step 4.

Ensure that the date oData property has below annotation

sap:display-format=”Date sap:filter-restriction=”interval

For setting these annotations you can write the below code in MPC_EXT class, DEFINE method.

super->define( ).    
DATA(lo_txt_property) = model->get_entity_type( <EntityType Name> )->get_property( <Property Name> ).  
"DynamicDate Control    
DATA(lo_text_anno) = lo_txt_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( 'sap' ).    
lo_text_anno->add( iv_key = 'filter-restriction' iv_value = 'interval')
lo_text_anno->add( iv_key = 'display-format' iv_value = 'Date').

If you are using Fiori OVP

In the app’s manifest/descriptor file

"sap.ovp": {//section for ovp-specific app descriptor settings
	....
	“useDateRangeType”: true, //Flag to enable or disable Dynamic Date. The default value is false.

	“cards”: {  
	“card01”: { 

Assigned Tags

      10 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Mahesh Palavalli
      Mahesh Palavalli

      Nice tip Krishna Kishor Kammaje, I tried with list report temp. app and it didn't work 🙁 🙁 Or do i have to do some extra steps for template based smart filterbars?

      Author's profile photo Krishna Kishor Kammaje
      Krishna Kishor Kammaje
      Blog Post Author

      Hi Mahesh, It is strange. Did you ensure that all the steps are followed and reflecting in the oData metadata?

      Author's profile photo Muthukumaran Pandian
      Muthukumaran Pandian

      Hi Krishna,

      Thanks for the information.

      It is working as expected without the property "useDateRangeType='true' ", I have just added the annotation in the MPC_EXT.

       

      Also when I use the property "useDateRangeType='true' ", I am getting invalid property name as shown below:

      "The property or event name does not exist for the control. Please enter the correct property or event name. [SAPUI5: (xml_invalid_property_name)]"

      BR,

      Muthu.

      Author's profile photo Krishna Kishor Kammaje
      Krishna Kishor Kammaje
      Blog Post Author

      Hi Muthu, As you see here, it is available only from SAPUI5 version 1.46. So you will need it from that version.

      Author's profile photo Muthukumaran Pandian
      Muthukumaran Pandian

      Thanks Krishna.

      BR,

      Muthu.

      Author's profile photo Rajesh Kuppa
      Rajesh Kuppa

      Hi Krishna Kishor Kammaje,

      Can you please help me with the below issues related to smart filter.

      1. In one our application we are using normal filter bar, now we are replacing it to smart filter bar, so a separate entity has been created in OData for the list of fields which are required and accordingly I adjusted my xml code in the view and assignee the entity as well, When I load the application no field is coming by default, until and unless i create a smart filter control configuration in view for each field. That means creating control configuration is required for all the fields to display in filter bar can we handle this in OData annotations?
      2. Am using Date range as explained above in my filter bar, as per our requirement in the initialization event of smart filter bar i have to set some default values, previously with help of low and high am setting date in filter bar, now those are not working, I tried in API reference unable to get method information for this control, can you help me providing any sample code for this.

      Thanks in advance for your inputs.

      Rajesh K

      Author's profile photo Deepesh Saxena
      Deepesh Saxena

      Hi,

      How to default the values on date filter for this interval.

      Author's profile photo Hassan MOUBTAKIR
      Hassan MOUBTAKIR

      Hi Rajesh

      Thanks for this blog

      When I try to implement this functionality, some labels of my smartfilterbar disappeared

      Have you ever encounter this issue

      Thanks

      Author's profile photo Nary Nantenaina RAJAONARIVO
      Nary Nantenaina RAJAONARIVO

      If you are using oData service based on CDS View (BOPF, ABAP Restfull, exposing CDS views on segw,...) you can use the annotation below on your CDS view to set the annotation sap:filter-restriction=”interval“ on your metadata

      @Consumption.filter.selectionType: #INTERVAL

      ,

      Author's profile photo Ghaith Mkhinini
      Ghaith Mkhinini

      I have seen the option to add the annotation directly in CDS, which is cool & good.

       

      Does anyone know if it is also possible to achieve sap:display-format=”Date“ through local SAPUI5 annotations?

       

      Thank you in advance!