在 PrimeFaces 的 DataTable-Paginator-Dropdown 中显示 "Show All"-Option

Display an "Show All"-Option in DataTable-Paginator-Dropdown in PrimeFaces

我在 Java 中有 Programm,我使用 Primefaces 分页和延迟加载。 我想在 rowsPerPageTemplate.

中添加 "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,"Show all" rowsPerPageAllEntry="true"
                    lazy="true">

要使 commandButton 出现在您的数据表中,请使用此示例:

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

希望对您有所帮助。

似乎对我有用。在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-function。

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

我同意评论部分@Jaqen H'ghar 的说法,这是我见过的最神秘的答案。我 post 在这里提供解决方案,以防其他人在这方面寻找解决方案。

我正在使用 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">