我的 .xhtml 中有一个数据表,如下所示:
<p:dataTable var="category" value="#{beanView.categories}" paginator="true" rows="5"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10" id="categoryDT" styleClass="categoryClass"
editable="true" lazy="false" rowKey="#{category.id}">
<!-- columns -->
<f:facet name="footer">
<p:commandButton id="btnNewCat"
oncomplete="jQuery('.categoryClass').find('span.ui-icon-pencil').last().click();"
actionListener="#{beanView.onNewCategory}"
update="categoryDT" icon="ui-icon-plus" title="New Category" value="New Category" ></p:commandButton>
</f:facet></p:dataTable>
还有我的 bean beanView :
public void onNewCategory(final ActionEvent actionEvent) {
try {
int rowCount = dataTable.getRowCount();
int rowsPerPage = dataTable.getRows();
int lastPage = rowCount / rowsPerPage;
int rowFirst = (lastPage * rowsPerPage);
if (rowCount >= rowsPerPage) {
dataTable.setFirst(rowFirst);
dataTable.setPageLinks(lastPage + 1);
dataTable.setRowIndex(rowCount - 1);
} else {
....
}
....
}
}
但这实际上行不通!最后一页将不会显示!
可以从 bean 单击我的数据表的最后一页按钮吗?或者有其他方法可以解决吗!
感谢您的帮助
最佳答案
您可以通过 commandButton 的 oncomplete
来实现此目的:
<p:commandButton oncomplete="PF('dataTableWV').paginator.setPage(PF('dataTableWV').paginator.cfg.pageCount - 1);"/>
或者从托管 bean:
RequestContext.getCurrentInstance().execute("PF('dataTableWV').paginator.setPage(PF('dataTableWV').paginator.cfg.pageCount - 1);");
注意:dataTableWV
是dataTable的widgetVar。
关于jquery - 如何从 bean 跳转到 Primefaces 数据表到最后一页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33394352/