DataTable clearFilter() not working properly

To clear all the inputs of the filters you can do it by javascript:

<p:commandButton onclick="PF('vtWidget').clearFilters()" />

vtWidget is the widgetVar of the datatable.

Basically clearFilters() will clear the fields for you and call filter(), and the filter function would update your datatable, which in turns will empty the filtered list.

Note: This would work only if the filters were inputText. If you have custom components then you should implement your own clear based on the components that you have.

Sometimes if you have custom components, you need to empty the filtered list manually, as you did in the comments!


This is how i solved my problem.

 RequestContext requestContext = RequestContext.getCurrentInstance();
 requestContext.execute("PF('widget_orderDataTable').clearFilters()");

Hope its help.


For clearing custom filters you can use primefaces resetInput, along with clearFilters() discussed in other answers, and a custom actionListener method. See code snippets below:

<p:dataTable id="dataTable" widgetVar="dataTable"
    value="#{bean.listOfObjects}" var="object">

<p:commandButton value="Clear All Filters"
    onclick="PF('dataTable').clearFilters()" 
    actionListener="#{controller.clearAllFilters}"
    update="dataTable">
    <p:resetInput target="dataTable" />
</p:commandButton>

Controller.java

public void clearAllFilters() {

    DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("form:dataTable");
    if (!dataTable.getFilters().isEmpty()) {
        dataTable.reset();

        RequestContext requestContext = RequestContext.getCurrentInstance();
        requestContext.update("form:dataTable");
    }
}

I hope this helps anyone looking to clear custom filters.