I have a data table which has paginator and a filter. When the table is filtered and not at the first page and I try to remove a row, I want to keep both the filter and the current page. So I tried something like this:
try {
List<Vector> filteredData = incomeTable.getFilteredValue();
Map<String, Object> filterValue = incomeTable.getFilters();
if (filteredData == null) {
filteredData = lstData;
}
int index = filteredData.indexOf(selectedRow);
lstData.remove(selectedRow);
filteredData.remove(selectedRow);
if (filteredData.size() > index) {
selectedRow = filteredData.get(index);
} else {
selectedRow = filteredData.get(index - 1);
}
onRowSelect();
incomeTable.setFilteredValue(filteredData);
incomeTable.setFilters(filterValue);
incomeTable.setFirst(getFirstRecordShow(filteredData));
} catch (Exception e) {
reportException(e);
}
After this function is processed, I update the table on the client side:
update="@([id$=incomeTable])"
I was able to keep the current page, list of filtered data and display the selected row correctly. But the filter I used on the header rows was cleared. I already tried
incomeTable.setFilters(filterValue);
to set the value again, but it's still not working.
Does anyone know how to keep both filter and the current page in this case?
My PrimeFaces version is 5.3.