10
votes

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.

5

5 Answers

7
votes

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);
3
votes
dataTable.setSortBy(null);

I'm using PrimeFaces 4.0

2
votes

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);
0
votes

First I reset the sort state as in the other answers:

dataTable.setSortBy(null);

However, this didn't reset the displayed codes in the table for me. It was still displaying the previously filtered results since I had set the filteredValue attribute on my datatable to a field in a view scoped bean. I fixed that problem by setting my filteredValue field to the value field, setting the current filtered results to the complete data set.

-2
votes
private DataTable filtervalue;
getter and setter of filtervalue ..........
call resetValue(); method on datatable
as  filtervalue.resetValue();

Hope it works