Technical Articles
‘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”: {
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?
Hi Mahesh, It is strange. Did you ensure that all the steps are followed and reflecting in the oData metadata?
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.
Hi Muthu, As you see here, it is available only from SAPUI5 version 1.46. So you will need it from that version.
Thanks Krishna.
BR,
Muthu.
Hi Krishna Kishor Kammaje,
Can you please help me with the below issues related to smart filter.
Thanks in advance for your inputs.
Rajesh K
Hi,
How to default the values on date filter for this interval.
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
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
,
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!