Simple table:
Code: Select all
<p:dataTable var="car" value="#{controller.cars}">
<p:column headerText="Name" sortBy="#{car.name}" >
<h:outputText value="#{car.name}" />
</p:column>
</p:dataTable>
Case 1: Datable with sorting only
Ajax request goes to the server 2 times in the function getCars on load table.
If you try to sort the column, ajax request goes to the server 6 times (on my case) in the function getCars.
Every time that you click on sort, primefaces request data on the server and tables never get sorted.
Workaround:
In fuction getCars do:
Code: Select all
private Cars cars;
public List<Cars> getCars(){
if (cars == null){
cars = DATABASE.getCars();
}
return cars;
}
Case 2: Datable with sorting and filter
Ajax request goes to the server 1 time in the function getCars.
If you Do NOT use the filter and then use de sort, primefaces call getCars from server 6 times and no sort effect.
If you use the filter (and clean the filter) and then use de sort, primefaces DO NOT call getCars from server and Sort works.
Case 3: showCase demo.
The demo works because getCars get a variable with initialization on the contructor.
In our model the data came from DataBase everu time that you use table interations ....
Question:
What is the real behavior of sort a column? Every time the primefaces goes to the server or not?