DataTable clearFilter() not working properly

前端 未结 4 945
失恋的感觉
失恋的感觉 2021-02-02 14:33

I have a complicate JSF that contain dataTable with filter in each one of the columns. In order to make sure that the generate button will fetch all the data first I need to cle

4条回答
  •  轮回少年
    2021-02-02 14:33

    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:

    
    
    
        
    
    

    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.

提交回复
热议问题