Conditional Pagination on Datatable
primefaces
Solution
Say you've got this `dataTable` (from the showcase):
<p:dataTable id="dataTable" var="car" value="#{tableBean.cars}"
paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
You could turn the paginator conditionally off like this:
<p:dataTable id="dataTable" var="car" value="#{tableBean.cars}"
paginator="#{tableBean.exceedsFive}" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
The bean:
public boolean isExceedsFive() {
return cars.size() > 5;
}
Notice the reference with EL in `paginator=""`.
Problem
I need conditional pagination on data-table, that is, need to add pagination only if the number of records is > say 5. The reason is when the pagination is included in the data table, it occupies the space of a row on screen. In maximum cases, the number of rows would be 5 only. So, the intent is to save the screen space for these majority cases.