全选数据表jsf primefaces [英] select all in datatable jsf primefaces

查看:96
本文介绍了全选数据表jsf primefaces的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个全选按钮或复选框,单击该按钮或复选框将选中所有selectbooleanCheck框。没有简单直接的方法。我开始创建selectcheckbox,当更改selectAll时。谢谢

Im trying to create a select all button or check box that when clicked all the selectbooleanCheck boxes will be checked. is there no straight forward easy way.ive started creating the selectcheckbox that will when changed selectAll. thanks

 <p:dataTable value="#{illRequestModel.list}"  
                        var="illRequestRecord" width="100%" styleClass="request-table"
                        rows="10" paginator="true" id="requestGrid" 
                        currentPageReportTemplate="Viewing Page {currentPage}"
                        paginatorTemplate="{CurrentPageReport}   {PageLinks}  "
                        paginatorPosition="bottom">
                        <p:column >
                        <f:facet name="header">
                                <h:selectBooleanCheckbox id="checkbox2" title="emailUpdates2" onchange="CheckAll()" > 

                                </h:selectBooleanCheckbox>
                            </f:facet>
                            <h:selectBooleanCheckbox id="checkbox" title="emailUpdates"
                                value="#{illRequestRecord.selected}"
                                onchange="addNumber(#{illRequestRecord.localRequestId})"> 
                                <f:ajax listener="#{illRequestRecord.selectmethod}" />
                                </h:selectBooleanCheckbox>
                        </p:column>
                        <p:column id="localRequestIdCol"
                            sortBy="#{illRequestRecord.localRequestId}">
                            <f:facet name="header">
                                <h:outputText value="ID" />
                            </f:facet>
                            <h:commandLink value="#{illRequestRecord.localRequestId}"
                                action="#{requestListController.displaySingleRecord}">
                                <f:param name="selectedItemId"
                                    value="#{illRequestRecord.localRequestId}"></f:param>
                            </h:commandLink>
                        </p:column>


推荐答案

为什么不使用相同的多选数据表 > PrimeFaces DataTable展示
如您所见:

Why don't you use the same multi-selection datatable used in the PrimeFaces DataTable showcase As you can see in:

 <p:dataTable id="multiCars" var="car" value="#{tableBean.mediumCarsModel}" paginator="true" rows="10" selection="#{tableBean.selectedCars}">

它将自动添加全选功能。
如果您希望外部复选框将其全部选中,则可以执行以下操作。
为您的数据表提供一个 widgetVar ,我们将其称为 dataTableWV

It will automatically add a check-all functionality. In case you want an external checkbox to check all, you can do the following. Give a widgetVar to you datatable, let's call it dataTableWV

 <p:dataTable widgetVar="dataTableWV" id="multiCars" var="car" value="#{tableBean.mediumCarsModel}" paginator="true" rows="10" selection="#{tableBean.selectedCars}">  

您有一个复选框:

 <input id="checkAll" type="checkbox" />

您可以像下面一样注册点击事件:

You can register a click event on it like the next:

 <script>
      $(document).ready(function() {
          $('#checkAll').on('click', function() {
               //selects all records on the displayed page if pagination is supported.
               dataTableWV.selectAllRowsOnPage();

               //or you can select all the rows across all pages.
               dataTableWV.selectAllRows();
          });
      });
 </script>

这篇关于全选数据表jsf primefaces的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆