Skip to Content

SmartFilterBar - Default values using Annotations not working

Hi Team,

I am using SmartFilterBar control to display the selection fields using the annotations and it is working correctly. I would like to default values for one of the selections fields. I found sample example which does the same thing and populates selection fields Company Code as an example. I defined Location entity type entity-type.jpg which has property "RangeId". Initialization of the property is done using annotations.jpg. Selection screen is displayed correctly but default value not shown. Also checked console and there are no errors. Please provide the solution or direct me in the right direction.

Note: I tried downloading sample example into web ide and and it doesn't work there. It appears to be I am missing something.

Regards,

Yellappa.

entity-type.jpg (123.9 kB)
annotations.jpg (43.6 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • 2 days ago

    Hello @Yellappa Madigonde (or anyone having this issue)

    I had this same issue today.

    The root cause is that this feature is only available since 1.48.0 and in my case I'm using 1.44.7.

    In my scenario, I had to enter the low and high values of a date range inside the smartfilterbar.

    I tried to create a polyfill using 1.48.0 code but the effort is insane so I did the trick inside my Controller (I believe something similar could be achieved when using Fiori Elements, which is not my scenario).

    	_setDefaultDate: function (oEvent) {
    			/** 
    			 * Unfortunately, annotation SelectionVariant is not handled in UI5 1.44.x
    			 * As a result, it's not possible to set a default value for the date range field using annotations.
    			 * This function is a workaround that sets the default value for the date range.
    			 * When upgrading to 1.48.x or later version of UI5, please use SelectionVariant annotation 
    			 * as commented in the 'annotation.xml' file.
    			 */
    			var oSelectionSet = this._oSmartFilterBar._retrieveCurrentSelectionSet(false, true);
    
    
    			var oFilterColumns = {
    				DATE_RANGE: "DateRange" // Property linked with the DateRange field in the smartfilterbar
    			};
    
    
    			for (var i = 0; i < oSelectionSet.length; i++) {
    				var oControl = oSelectionSet[i];
    				var sId = oControl.getId();
    
    				if (sId.search(oFilterColumns.DATE_RANGE) >= 0) {
    					var oDataRange = oControl;
    					var dLowDate = new Date();
    					var dHighDate = new Date();
    					dHighDate.setDate(dHighDate.getDate() + 14); // 2 weeks
    					oDataRange.setDateValue(dLowDate);
    					oDataRange.setSecondDateValue(dHighDate);
    					return;
    				}
    			}
    		},
    
    
    Add comment
    10|10000 characters needed characters exceeded