Sorting is not working in datatable in PrimeFaces. Please suggest.
See below my .xhtml file
I don't know if it's your case. There's a primefaces issue. A bug on sort of datatable. Take a look here: https://code.google.com/archive/p/primefaces/issues/2476
There are some workarounds:
you can use a lazyDataModel for your datatable, it works.
you can force the sort order.
In your datatable catch the sort event
In your managed bean you set a order by string to add to your query
private String orderBy = "";
public void sortListener(SortEvent event) {
String orderColumn = event.getSortColumn().getValueExpression("sortBy").getExpressionString();
//you will get the content of the attribute SortBy of the column you clicked on, like #{entry.carno}
orderColumn = orderColumn.replace("#{entry.", "");
orderColumn = orderColumn.replace("}", "");
orderBy = " order by " + orderColumn + (event.isAscending()? " asc " : " desc ");
}
public List getList(){
String query = "[...your query...]" + orderBy;
...[execute your query and get your ordered list]
}