0
votes

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

1

1 Answers

0
votes

OK so I eventually resolved this problem. In the examples above I had assumed that I was manipulating the filter that would be applied to the model endpoint. This is not the case. All I was doing in this example code was manipulating the filters displayed on the Table, in the drop down box etc.

To save and reapply the filters I had to access the row binding on the table:

columns.aFilters = oTable.getBinding("rows").aFilters;

However I still had problems because there are two filters: control and application binding. The application filters are as follows:

columns.aApplicationFilters = oTable.getBinding("rows").aApplicationFilters;

Then when I select a different set of filters, they need to be bound to the rows aggregation as follows:

          oTable.bindAggregation("rows", {
                path: sObjectPath,
                parameters: expand,
                filters:filters,
                sorter:sorter
            });

where filters is either

columns.aFilters or columns.aApplicationFilters