【问题标题】:How to deselect the selected rows in Datatable programmatically如何以编程方式取消选择 Datatable 中的选定行
【发布时间】:2013-04-03 08:54:52
【问题描述】:

在我的应用程序中,dialog 显示了dataTable,在每一列中都有一个复选框来选择相应的行。在dialog的底部,我踱了两个 一个用于显示选定行的按钮,另一个用于重置数据表的按钮意味着取消选择选定的行。

.xhtml代码如下:

<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>

我想在单击重置按钮时取消选择行。怎么做?

【问题讨论】:

  • 您将 selection="#{activityListController.selectedActivityUsers}" 设置为要设置的对象,然后在 ajax 中更新数据表。
  • 感谢您的回复。有什么例子吗?

标签: jsf-2 primefaces datatable


【解决方案1】:

我们可以使用unselectAllRows()取消选择p:dataTable

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

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

从豆子

PrimeFaces.current().executeScript("PF('dtWidgetVar').unselectAllRows()");

【讨论】:

  • 它将是 onclick="PF('dtWidgetVar').unselectAllRows();"根据 PrimeFaces 5.2
  • 如果您只想执行一些 JavaScript,则不应使用 p:commandButton。请改用p:button
【解决方案2】:

你试试:

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

豆子:

public void hand(){
   selectedActivityUsers = new ActivityUsers(); // Type of element of list
}

【讨论】:

    【解决方案3】:

    试试这个:

    DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("form:dataTable"); 
    dataTable.reset();
    

    【讨论】:

      猜你喜欢
      • 2019-07-18
      • 1970-01-01
      • 2019-03-21
      • 2016-01-20
      • 1970-01-01
      • 2014-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多