on 2018 Nov 26 5:32 AM
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.
Request clarification before answering.
Its better to put your code inside the code display box as it is not readable at all.
Secondly, its better, preferable and suggested by SAP to use aggregation bindings for these kind of scenarios..
I've used your data and created the filters via binding, see the code below:
// COntroller level, i've created the json model in this format:
var filters = [{
"key": "Emp Id",
"values": [{
"key": "3001"
}, {
"key": "3002"
}, {
"key": "3003"
}]
}, {
"key": "Department",
"values": [{
key: "Electrical"
}, {
key: "Accounts"
}, {
key: "Mechanical"
}]
}];
this.getView().setModel(new sap.ui.model.json.JSONModel({
filters: filters
}), "filterDiloag");
// Now in the view, I've made this changes to fetch the filters from the binding:
//
<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core">
//-> Comment here adding the aggregation filteritems
<ViewSettingsDialog id="FilterDialog" confirm="handleConfirm" filterItems="{filterDiloag>/filters}">
<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>
//-> Comment here adding the aggregation and bindings
<ViewSettingsFilterItem key="{filterDiloag>key}" text="{filterDiloag>key}" items="{filterDiloag>values}">
<items>
<ViewSettingsItem text="{filterDiloag>key}" key="{filterDiloag>key}"></ViewSettingsItem>
</items>
</ViewSettingsFilterItem>
<!-- <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>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
79 | |
12 | |
9 | |
8 | |
7 | |
5 | |
4 | |
4 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.