I'd like to reset the filter, sort and paging state of an PrimeFaces DataTable. Unfortunately, there is no easy way to do so. Especially reseting the sort state is difficult.
What I did until now is:
DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent(componentId);
if (dataTable != null) {
dataTable.setSortOrder("ascending"); // reset sortOrder
dataTable.setFirst(0); // reset page
dataTable.setFilteredValue(null); // reset filter
dataTable.setFilters(null);
}
I'm using PrimeFaces 3.4.1.
Finally, I found the solution, hidden in this sample http://www.primefaces.org/showcase/ui/data/datatable/columns.xhtml on tab ColumnsView.java
:
table.setValueExpression("sortBy", null);
dataTable.setSortBy(null);
I'm using PrimeFaces 4.0
Inside the LazyDataModel load I call the method with this code:
DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("form:dataTableItem");
dataTable.setFirst(0);
dataTable.reset();
dataTable.setSortBy(null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With