如何从Bean中将Primefaces dataTable跳转到最后一页? [英] How to jump in Primefaces dataTable to last page from the bean?

查看:136
本文介绍了如何从Bean中将Primefaces dataTable跳转到最后一页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.xhtml中有一个像这样的数据表:

I have into my .xhtml a datatable looking like this :

<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 {
            ....
        }

        ....
     }
 }

但这实际上不起作用!最后一页将不会显示!

But this actually doesnt work! the last page will not be show!

是否可以从bean中单击我的数据表的最后一页按钮?还是有另一种解决方法!

It's possible to Click on the last Page button of my datatable from the bean? or is there another way to solve it!

感谢您的帮助

推荐答案

您可以通过commandButton的oncomplete来实现:

You can achieve this by the oncomplete of the commandButton:

<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.

Note: dataTableWV is the widgetVar of the dataTable.

这篇关于如何从Bean中将Primefaces dataTable跳转到最后一页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆