I have a sap.ui.table.Table bound to an OData.V4 data source. The filterProperty of each column is correctly set.
With this I can successfully set a filter value, either using the cell rightClick or in the column header popup menu. This behaves exactly as expected in that an updated request is sent to the OData source with the correct filtering.
For reasons based on the overall requirements, I wish to save the filter settings which I do to a JSON model:
var oTable = this.byId("table");
var aColumns = oTable.getColumns();
var columns={};
var settings=[];
var filtered=false;
for (var i = 0; i < aColumns.length; i++) {
if(aColumns[i].getFilterValue()) filtered=true;
settings.push({
"index": i,
"id":aColumns[i].getId(),
"sorted": aColumns[i].getSorted(),
"sortOrder": aColumns[i].getSortOrder(),
"filterValue": aColumns[i].getFilterValue(),
"filtered": aColumns[i].getFiltered(),
"visible": aColumns[i].getVisible()
});
}
columns.settings = settings;
columns.filtered = filtered;
A user can then try and recall a set of filter and sort settings, the code for which is shown below, where thisCrumb contains the saved settings:
var oTable = this.byId("table");
var columns = thisCrumb.columns;
if(columns){
if(columns.search )this.byId("searchField").setValue(columns.search);
for(var columnIndex in columns.settings){
var column = oTable.getColumns()[columns.settings[columnIndex].index ]
column.setFilterValue(columns.settings[columnIndex].filterValue );
oTable.filter(column, columns.settings[columnIndex].filterValue);
column.setFiltered(columns.settings[columnIndex].filtered );
column.setSortOrder(columns.settings[columnIndex].sortOrder );
column.setSorted(columns.settings[columnIndex].sorted );
column.setVisible(columns.settings[columnIndex].visible);
}
}else{
this.clearAllFilters();
this.clearAllSorts();
}
Although the values show up on the table, for example the filter icon is set on the column header, and the filter value is also set, the OData query to refresh the data does not include the filter values.
The API documentation suggest that the sap.ui.table.Table.filter method should be called for each column, which I have done (as above) but with no success:
oTable.filter(column, columns.settings[columnIndex].filterValue);
If I interactively use the column header contextmenu and 'touch' the filter value, the table does get refreshed including the corresponding filter.
I would like to be able to recover a saved set of filter and/or sort values, apply them to each column, and then refresh the Table to show the filtered set