Reputation: 4292
The sortBy
attribute of <p:column>
in <p:dataTable>
lets the user to sort a column ascending or descending on each click, is there anyway to sort column descending on the first click of column header. It is ascending by default.
<p:column sortBy="#{bean.col1Value}" headerText="Col Header">
#{bean.col1Value}
</p:column>
Is there any possibility to override this <p:dataTable>
's default setting?
Upvotes: 2
Views: 5519
Reputation: 1174
I think you can use the attribute sortFunction. I quote from the Primefaces 5.1 User Guide page 153-154
Instead of using the default sorting algorithm which uses a java comparator, you can plug-in your own sort method as well
public int sortByModel(Object car1, Object car2) {
car2.compareTo(car1);
}
And then in your html file
<p:dataTable var="car" value="#{carBean.cars}">
<p:column sortBy="#{car.model}" sortFunction="#{carBean.sortByModel}"
headerText="Model">
<h:outputText value="#{car.model}" />
</p:column>
...more columns
</p:dataTable>
Upvotes: 2
Reputation: 1202
You need to use sortFunction="#{testBean.customSort}" and you can customized your sorting.
Upvotes: -1