Nov 1, 2018

PrimeFaces Sort Event Example

In DataTable:
<p:column style="text-align: center;" sortBy="#{row[1]}" headerText="Count">
        <h:outputText value="#{row[1]}"/>
</p:column>
<p:column style="text-align: center;" sortBy="#{row[2]}" headerText="Date">
        <h:outputText value="#{row[2]}"/>
</p:column>

Sort Event in Bean:
 public void onSort(SortEvent event) {
    if ("Count".equalsIgnoreCase(event.getSortColumn().getHeaderText())) {
//order by count
    } else if ("Date".equalsIgnoreCase(event.getSortColumn().getHeaderText())) {
//order by date
    }
}