質問

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!

役に立ちましたか?

解決

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

他のヒント

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");
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top