cancel
Showing results for 
Search instead for 
Did you mean: 

How to adddefaultfilter value in smartfilterbar

0 Kudos

Hi,

I am facing issue in adding default value to smartfilterbar controlType dropdown.

I have added this in onAfterRendering of page ,but i am getting getItems as empty.

	onAfterRendering: function(event) {

var defaultPm=this.getView().byId("filterPM").getItems()[0].getKey();

this.getView().byId("filterPM").addDefaultFilterValue(new sap.ui.comp.smartfilterbar.SelectOption().setLow(defaultPm));
}
<smartFilterBar:SmartFilterBar id="smartFilterBar" entitySet="Entityset" persistencyKey="SmartFilterPKey" showClearOnFB="true"
showRestoreOnFB="true" showFilterConfiguration="false" initialise="onFInitialise" search="onFilter" reset="onReset" >
<smartFilterBar:controlConfiguration id="cf" >
<smartFilterBar:ControlConfiguration key="Pm" visibleInAdvancedArea="true" id="filterPM" mandatory="mandatory" controlType="dropDownList"hasTypeAhead="true">
						
	<!--<smartFilterBar:defaultFilterValues>
		<smartFilterBar:SelectOption low="1001"></smartFilterBar:SelectOption>
		</smartFilterBar:defaultFilterValues>-->
		</smartFilterBar:ControlConfiguration>
					</smartFilterBar:controlConfiguration>
					<smartFilterBar:layoutData>
						<FlexItemData shrinkFactor="0"/>
					</smartFilterBar:layoutData>
				</smartFilterBar:SmartFilterBar>

Hello, I faced the same issue.

I suggest you to have a look to this: https://help.sap.com/doc/saphelp_uiaddon20/2.05/en-US/7b/cdffc056a94731b4341db73251e32b/content.htm?...

On this question :"I tried to set default values for a filter field in the control configuration in JavaScript. These default values don’t have any effect."

You have to use setFilterData() because as soon as the Initialise event is triggered, you cannot modify filters using ControlConfiguration (correct me if I am wrong).

Best regards

Accepted Solutions (0)

Answers (1)

Answers (1)

nabheetscn
Active Contributor
0 Kudos

Hi Mounika

I believe you have used Fiori elements to generate it via CDS if yes then you can use annotation insertDefaultFilterValue to set default values. Secondly the control has defaultFilterValues as aggregation which you can use to set the default values.

Thanks

Nabheet

0 Kudos

Hi Nabheet,

Thanks for your quick response.,Im not using CDS here.I have fixed it in initialise event of smartfilterbar by oModel.read.