Search code examples
jsf-2primefaces

Reset PrimeFaces DataTable state (filter, sorting, paging)


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.


Solution

  • 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);