Pregunta

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!

¿Fue útil?

Solución

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

Otros consejos

It's ok, but now in primefaces 5.1 on the client side you have to do like:

PF('widgetVar').getPaginator().setPage(pageindex);

For me works very nice, but you have to type the entire component name

FacesContext.getCurrentInstance().getViewRoot().findComponent("form:panel:datatable");
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top