Change page of Primefaces Datatable with pagination from commandlink

Alavaros picture Alavaros · Jul 9, 2013 · Viewed 21.8k times · Source

I have a Datatable with pagination and I want to change the current page with a commandlink outside the Datatable, how I can get it?

<p:commandLink title="changePage" action="#{myBean.changeMethod}"
   update="myDataTable" />
<p:dataTable id="myDataTable" var="myItem" paginator="true" rows="1"
   value="#{myBean.ListOfItem}" binding="#{myBean.DataTable}">
  ...
  ...
</p:dataTable>

Greetings!

Answer

Emil Kaminski picture Emil Kaminski · Jul 9, 2013

This will set the page of the table to the first one

public void changeMethod() {
final DataTable d = (DataTable) FacesContext.getCurrentInstance().getViewRoot()
    .findComponent("myDataTable");
int first = 0;
d.setFirst(first);

}

Or on client side:

widgetVar.getPaginator().setPage(pageindex);

EDIT : The "first" attribute indicates the index of the first row to be displayed