set page on p:datatable

后端 未结 4 598
小蘑菇
小蘑菇 2020-12-14 20:59

I\'ve a datatable in primefaces and I want, when I add a row in it, view the last page of the datatable.

My .xhtml page is:


...         


        
4条回答
  •  心在旅途
    2020-12-14 21:04

    In your managed bean you can try this code:

    public void setPageDataTable() {
        final DataTable d = (DataTable) FacesContext.getCurrentInstance().getViewRoot()
            .findComponent("form:templateTable");
        int first = 1;
        if (d.getRowCount() % ROWS_DATATABLE == 0) {
            first = (d.getRowCount() - ROWS_DATATABLE);
        }
        else 
        {
            first = (d.getRowCount()/ROWS_DATATABLE)*ROWS_DATATABLE;
        }
        d.setFirst(first);
    }
    

    Call this method when you add a new row

提交回复
热议问题