【问题标题】:Display an "Show All"-Option in DataTable-Paginator-Dropdown in PrimeFaces在 PrimeFaces 的 DataTable-Paginator-Dropdown 中显示“全部显示”选项
【发布时间】:2017-02-13 12:59:19
【问题描述】:

我有 Java 程序,我使用 Primefaces 分页和延迟加载。 我想在 rowsPerPageTemplate 中添加“全部显示”。

<p:dataTable var="info"
                    value="#{infoMB.lazyModel}"
                    id="infoTable"
                    width="100%"
                    liveResize="true"
                    paginator="true"
                    rows="50"
                    paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                    rowsPerPageTemplate="50,100,"Show all" rowsPerPageAllEntry="true"
                    lazy="true">

【问题讨论】:

  • 为什么不放在表头中
  • 感谢您的评论,如何在 Header 中?
  • 它看起来像这样&lt;f:facet name="header" &gt; &lt;p:commandButton value="Validate button" action="#{managedBean.method()}" &gt; &lt;/p:commandButton&gt; &lt;/f:facet&gt;它会直接在&lt;p:dataTable&gt;

标签: primefaces jsf-2 pagination


【解决方案1】:

我同意 cmets 部分下的 @Jaqen H'ghar 声明,即这是我见过的最神秘的接受答案。我在这里发布解决方案,以防其他人寻求解决方案。

我用的是Primefaces-7.0,看了org/primefaces/component/paginator/RowsPerPageDropDownRenderer.class的代码,发现代码如下:

if (option.trim().startsWith("{ShowAll|")) {
    optionText = option.substring(option.indexOf("'") + 1, option.lastIndexOf("'"));
    rows = pageable.getRowCount();
  } else {
    optionText = option.trim();
    rows = Integer.parseInt(optionText);
  }

因此,为了使示例正常工作,您应该添加 {ShowAll|'Show All',这将在下拉选择器中添加一个 **Show All ** 选项,它将在一页中显示列表的所有行。

Primefaces-7.0 示例 ({ShowAll|'Show All')

<p:dataTable var="info"
                value="#{infoMB.lazyModel}"
                id="infoTable"
                width="100%"
                liveResize="true"
                paginator="true"
                rows="50"
                paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                rowsPerPageTemplate="50,100,{ShowAll|'Show All' " rowsPerPageAllEntry="true"
                lazy="true">

示例 Primefaces 6.2*All rows

<p:dataTable var="info"
            value="#{infoMB.lazyModel}"
            id="infoTable"
            width="100%"
            liveResize="true"
            paginator="true"
            rows="50"
            paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
            rowsPerPageTemplate="50,100,*" rowsPerPageAllEntry="true"
            lazy="true">

【讨论】:

    【解决方案2】:

    似乎对我有用。在rowsPerPageTemplate 999999999 中选择最后一个选项。

        <script>
            function updateShowAll() {
                $('.ui-paginator-rpp-options').children().each(function() {if ($(this).text() === '999999999'){$(this).text('Show all')}});
            }
            updateShowAll();
            $(document).on('pfAjaxComplete', updateShowAll);
        </script>
    

    事件处理程序是为了避免在数据表的update之后必须记住手动调用js函数。

    似乎这将通过使用“*”在 PF 6.1 中内置。

    【讨论】:

      【解决方案3】:

      要让命令按钮出现在你的 dataTable 中,这个例子:

      <p:dataTable ... >
      
         <f:facet name="header" > <p:commandButton value="Validate button" action="#{managedBean.method()}" > </p:commandButton> </f:facet>
      
       </p:dataTable ... >
      

      你甚至可以像这样在数据表的底部显示它

       <p:dataTable ... >
      
         <f:facet name="footer" > <p:commandButton value="Validate button" action="#{managedBean.method()}" > </p:commandButton> </f:facet>
      
       </p:dataTable ... >
      

      希望对您有所帮助。

      【讨论】:

      • 感谢您的宝贵时间和帮助
      • 我是 Java 初学者,action="#{managedBean.method()}" 是什么意思?
      • @AllexFerra 可以是任何java方法public void method(){ ... }
      • @AllexFerra 有什么新东西吗?!?
      • 这是我见过的最神秘的答案
      猜你喜欢
      • 2013-04-24
      • 2016-01-03
      • 2012-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-28
      • 2013-10-01
      相关资源
      最近更新 更多