2
votes

I use sorting in primefaces datatable and it's does not work with paginator. Where I made ​​a mistake?

<p:column headerText="Year" sortBy="#{questionnaireListBean.getQuestionnaireData(questionnaire, 'YEAR')}">
    #{questionnaireListBean.getQuestionnaireData(questionnaire, 'YEAR')}
</p:column>

And view scoped bean with init data in @PostConstruct method:

public String getQuestionnaireData(Questionnaire questionnaire, String column) {
    return questionnairesData.get(questionnaire).get(column);
}
1
Which primefaces version are you using ? - Akheloes
Plus : how is questionnaire set in the JSF page ? Is there any exception or type error indicated ? - Akheloes
Primefaces 3.5. When i try to remove paginator sorting is work correctly. With paginator does not work, without exceptions. - dmitrievanthony
Well, pagination and sorting are working along fine here primefaces.org/showcase/ui/datatableComplex.jsf - Akheloes
I try to do how it implement in example and yes, it works correctly. Problem was in 'lazy' parameter... So, is sorting works with lazy data table? - dmitrievanthony

1 Answers

3
votes

So the true title of your question is : "Sorting and pagination not working together in lazy loading datatable, primefaces", that's more of a precise description of your problem.

As for the issue, it apprears that you should expect the problem. In this link, the question was "Is there any datatable JSF component than can perform lazy load pagination, and filtering and sorting on server side. If I need to implement my own solution thanks to the teams that made client side sorting and filtering, they are useless", to which the answer came "No, there isn't. Because the component library cannot know what will be the persistence mechanism.". Of course that dated from 2010...

Taking a look into Primefaces user guide 3.5, it apprears that sorting/paginator/lazy loading can cohabit, but that's more elaborte then just adding sortBy to your columns. In fact, checking page 144 of the guide, you can see that you need to :

  • have a LazyDataModel object in your bean ;
  • Override the load method of this object ;
  • Bind the value of your datatable to this model.

Doing this, you might have sorting along with lazy loading. Haven't tried it, but this seems to adress your issue.

Best of luck.