Jasker
Jasker

Reputation: 53

How to reset the sorting on dynamic colums at PrimeFaces?

I have dynamic columns which are sorted as well as filtered. I managed to clear the filters, but according to Primefaces there is no function to clear the sorting for the client API.

My .xhtml:

<p:dataTable id="tableId" value="#{statisticCreateBean.tableData}"
                    var="data" widgetVar="dataTbl"
                    rendered="#{not empty statisticCreateBean.tableData}">
    <p:columns id="columnId" value="#{statisticCreateBean.columnModel}"
                        var="column" sortBy="#{data[column.fieldName]}"
                        filterBy="#{data[column.fieldName]}">
            <f:facet name="header">
                    #{column.displayName}
            </f:facet>
            <h:outputText value="#{data[column.fieldName]}" />
    </p:columns>
</p:dataTable>

My Java-code:

    Columns columns = (Columns)FacesContext.getCurrentInstance().getViewRoot().findComponent("statisticForm:tableId:columnId");
    columns.setSortBy(null);
    PrimeFaces.current().executeScript("PF('dataTbl').clearFilters();");

Is there a way to clear the sorting on dynamic columns?

Upvotes: 3

Views: 2169

Answers (1)

Melloware
Melloware

Reputation: 12019

To reset sorts and filters properly get the Datatable and call reset.

DataTable datatable= (DataTable )FacesContext.getCurrentInstance().getViewRoot().findComponent("statisticForm:tableId");
datatable.reset();

Upvotes: 4

Related Questions