Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 686
micfra Avatar asked Aug 19 '13 11:08

micfra


3 Answers

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);
like image 92
micfra Avatar answered Nov 13 '22 14:11

micfra


dataTable.setSortBy(null);

I'm using PrimeFaces 4.0

like image 26
focusing Avatar answered Nov 13 '22 14:11

focusing


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);
like image 3
criscan Avatar answered Nov 13 '22 13:11

criscan