Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deselect the selected rows in Datatable programmatically

In my application in a dialog I displayed a dataTable in each column there are a check box to select corresponding row. At the bottom of dialog I paced two button one for display selected rows another for reset the datatable means to deselect the selected rows.

.xhtml code is given below:

<p:dialog id="popUp" header="Activity Detail" widgetVar="popUpWidget" 
 showEffect="fade" hideEffect="explode" resizable="false" modal="true">
<h:panelGrid>
    <p:row>
        <p:column colspan="2">
            <p:dataTable id="userListForAdminpopup" value="#{activityListController.activityUsers}" var="user"
                paginator="true" paginatorPosition="bottom" widgetVar="userListForAdminpopUp"
                paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                rows="10" selection="#{activityListController.selectedActivityUsers}">

                <p:column headerText="#{adbBundle['fullName']}"
                    sortBy="#{user.lastName}" filterBy="#{user.fullName}"
                    filterMatchMode="contains" styleClass="userName">
                    <h:outputLabel value="#{user.firstName}" />
                </p:column>

                <p:column selectionMode="multiple" />
            </p:dataTable>
        </p:column>
    </p:row>
    <p:row>
        <p:column colspan="2">
            <h:panelGroup layout="block">
                <p:commandButton value="Update" oncomplete="confirmation.show()"/>
                <p:commandButton value="Reset"/>
            </h:panelGroup>
        </p:column>
    </p:row>
</h:panelGrid></p:dialog>

I want to deselect the rows when click on reset button. How it can be done?

like image 713
Diganta Avatar asked Apr 11 '13 08:04

Diganta


2 Answers

We can deselect p:dataTable rows using unselectAllRows()

<p:dataTable
    id="dataTableId"                             
    widgetVar="dtWidgetVar"
    value="#{myBean.items}"
    var="item"
    ....>
</p:dataTable>

<p:commandButton value="Reset" onclick="PF('dtWidgetVar').unselectAllRows()" />

From the bean

PrimeFaces.current().executeScript("PF('dtWidgetVar').unselectAllRows()");
like image 74
swaps Avatar answered Oct 06 '22 07:10

swaps


You try:

<p:commandButton value="Reset" update="userListForAdminpopup" process="@this" actionListener="#{activityListController.hand}"/>

Bean:

public void hand(){
   selectedActivityUsers = new ActivityUsers(); // Type of element of list
}
like image 22
Rong Nguyen Avatar answered Oct 06 '22 07:10

Rong Nguyen