Ala Varos
Ala Varos

Reputation: 1725

Update component at change of page on primefaces datagrid with pagination

I have a datagrid with pagination. When I change the page I want to update some components in the page, but I don't know how to get the event. Some code:

<p:panelGrid id="buttons">
  <p:commandLink value="Link1" action="#{myBean.method1}" disabled="#{myBean.boolean1}" />
  <p:commandLink value="Link2" action="#{myBean.method2}" disabled="#{myBean.boolean2}" />
</p:panelGrid>
<p:dataGrid var="myVar" paginator="true" value="#{myBean.listOfObjects}">
  ...
  ...
</p:dataGrid>

I want something like update="buttons" in the dataGrid, so when the page changes, update the buttons depending on disabled="" attribute of the buttons, is it possible?

Greetings.

Upvotes: 9

Views: 18869

Answers (1)

Ala Varos
Ala Varos

Reputation: 1725

Finally, instead of <p:dataGrid ... /> i used <p:dataTable ... /> with <p:ajax ... /> inside, this is my code:

<p:dataTable var="myVar" paginator="true" rows="1" value="#{myBean.listOfObjects}">
  <p:ajax event="page" update="buttons" listener="#{myBean.update}" />
  ...
  ...
</p:dataTable>

And update method:

public void update(PageEvent event) {
  int var = event.getPage();
  ...
  (update components values of dataTable and buttons using var)
  ...
}

Upvotes: 20

Related Questions