I need to keep filtered data when I navigate between pages. After entering data into a filter cell of a data table, it displays correct filtered rows. If last entered data in the filter cell doesn't match any data rows to display and when I navigate to another page and return back - column headers and filter cells are not rendered. There is only paginator are displayed. It works fine if last entered data in the filter cell matches some data rows. It work properly also if I don't leave the page with data table.
jsf code:
<p:dataTable id="tableId" var="intance" widgetVar="instance"
value="#{model.rows}" filteredValue="#{model.filteredRows}"
sortBy="#{model.sortBy}" sortMode="multiple" rows="5"
rowsPerPageTemplate="5, 15" paginator="true" paginatorPosition="bottom">
<p:ajax event="filter" listener="#{model.onFilter}"/>
<p:ajax event="sort" listener="#{model.onSort}"/>
<p:columns id="columnId" value="#{instance.columnsData}"
var="instanceColumn" columnIndexVar="ind" rendered="true"
sortBy="#{instance.columnsData[ind]}"
filterBy="#{instance.columnsData[ind]}" filterMatchMode="contains"
filterValue="#{model.tableFilters[''.concat(ind)]}"
headerText="#{labels[ind]}">
<h:outputText value="#{instance.columnsData[ind]}"/>
</p:columns>
</p:dataTable>
java code:
public class Model {
private List<MyRow> filteredRows;
private List<MyRow> rows;
private Map<String, String> tableFilters;
public void onFilter(FilterEvent event) {
tableFilters = event.getFilters();
if (MapUtils.isEmpty(tableFilters)) {
filteredRows = null;
}
}
public void List<MyRow> getRows() {
//retreve data from service and transform to List<MyRow>)
return rows;
}
/* getters and setter */
}
public class MyRow {
private List<Object> columnsData;
/* getters and setters */
}
Any thoughts? The code looks fine to me and should work. I use primefaces 3.5.
Thanks