简体   繁体   中英

How to call method on ticking the SelectAll checkbox in p:dataTable through ajax

I need your help in calling a method from a backing bean once I ticked the SelectAll checkbox at the top of a dataTable. I am able to call the method ShowTotal once I ticked or unticked the checkbox of each individual item, however when I tick the SelectAll checkbox from the top, no listener is called. Here is my code:

<p:dataTable id="PendingRequests" var="hr" selection="#{hrdirector.selectedRequests}"
             value="#{hrdirector.listPendingRequests}" rowKey="#{hr.requestNo}"
             filteredValue="#{hrdirector.filteredRequests}" widgetVar="dataTableWidgetVar">
  <p:ajax event="rowSelectCheckbox" listener="#{hrdirector.ShowTotal}" process="@this" 
          update=":form:PendingRequests:sum"/>

  <p:ajax event="rowUnselectCheckbox" listener="#{hrdirector.ShowTotal}" process="@this"
          update=":form:PendingRequests:sum"/>

        <p:column selectionMode="multiple" style="width:16px;text-align:center"></p:column>
        <p:column headerText="Request No.">
            <h:outputText value="#{hr.requestNo}"/>
        </p:column>
        <p:column headerText="Request Amount">
            <h:outputText value="#{hr.requestAmount}"/>
        </p:column>
    </p:dataTable>

    <h:outputText id="Sum" value="#{hr.Sum}"/>

I tried to add the below code in the column which it has the selection, but it gave me an error:

<p:column selectionMode="multiple" style="width:16px;text-align:center">
<p:ajax listener="#{hrdirector.ShowTotal}" />
</p:column>

Page 172 of the fabulous PrimeFaces documentation has the answer for you. What you need is called the toggleSelect event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM