[英]Conditional Pagination on Datatable
I need conditional pagination on data-table, that is, need to add pagination only if the number of records is > say 5. 我需要对数据表进行条件分页,也就是说,只有当记录数>> 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.
在最大的情况下,行数仅为5。 So, the intent is to save the screen space for these majority cases.
因此,目的是为这些大多数情况节省屏幕空间。
According to primefaces' documentation: 根据primefaces的文件:
set dataTable paginator like this 像这样设置dataTable paginator
paginator="true" rows="5" paginatorAlwaysVisible="false"
- the paginator will be visible only if there are more than 5 records in the table. - 只有当表中有超过5条记录时,才能看到分页符。
Say you've got this dataTable
(from the showcase ): 假设你有这个
dataTable
(来自展示 ):
<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=""
. 注意在
paginator=""
使用EL的引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.