Skip to Content
0
Nov 26, 2018 at 05:32 AM

Filters are not getting added dynamically to view settings dialog control in sapui5

2023 Views

Hi friends,

I am trying to add filters dynamically to sap.m.ViewSettingsDialog, but the filters and filter items are not getting added. And there was no error that is coming up in browser console to analyze this issue.

Can somebody help me on this issue.

Here I have added my application code below. So please take a look into the code.

FilterDialog.fragment.xml

<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core"> <ViewSettingsDialog id="FilterDialog" confirm="handleConfirm"> <sortItems> <ViewSettingsItem text="Field 1" key="1" selected="true" /> <ViewSettingsItem text="Field 2" key="2" /> <ViewSettingsItem text="Field 3" key="3" /> </sortItems> <groupItems> <ViewSettingsItem text="Field 1" key="1" selected="true" /> <ViewSettingsItem text="Field 2" key="2" /> <ViewSettingsItem text="Field 3" key="3" /> </groupItems> <filterItems> <!-- <ViewSettingsFilterItem text="Field1" key="1"> <items> <ViewSettingsItem text="Value A" key="1a" /> <ViewSettingsItem text="Value B" key="1b" /> <ViewSettingsItem text="Value C" key="1c" /> </items> </ViewSettingsFilterItem> --> </filterItems> </ViewSettingsDialog> </core:FragmentDefinition>

Controller

addFilterToDialog: function(filters){

filters = [ { "key" : "Emp Id", "values" : ["3001","3002","3003"] }, { "key" : "Department", "values" : ["Electrical","Accounts","Mechanical"] } ];

var filterDialog = this._oFilterDialog;

this._oFilterDialog.removeAllFilterItems();

this._oFilterDialog.destroyFilterItems();

for(var i=0; i<filters.length; i++){ var oFilter = new sap.m.ViewSettingsFilterItem({ text: filters[i].key, key: filters[i].key }); for(var j=0;j<filters[i].values.length; j++){ var oFilterItem = new sap.m.ViewSettingsItem({text:filters[i].values[j], key:filters[i].values[j]}); oFilter.addItem(oFilterItem); } filterDialog.addFilterItem(oFilter); }

}

Here I am trying to add the filters dynamically based on backend data.But here I have used the sample data i.e., filters array.

Thanks in advance.