【问题标题】:Primefaces Datatable current row count is not updated correctly in the page after filteringPrimefaces Datatable当前行数在过滤后页面中没有正确更新
【发布时间】:2017-03-07 15:06:51
【问题描述】:

以下代码在应用过滤后未正确更新当前数据表行数。有时我必须在输入文本后在过滤器输入框中按两次回车键,以便正确更新计数。有时它只是在我输入文本并且不按回车键后才起作用。有时我也可以只输入一次回车键,计数就会正确更新。我不明白为什么我会得到这种不同的行为。也许 JSF / Primefaces 专家可以帮助我理解这一点?

              <h:form id="summaryForm">
              ...
              <p:tabView id="summaryTabView">
              ...
              <p:tab id="allTab" title="All">
              ...
              <script type="text/javascript">
                //<![CDATA[
                function updateAllRecordCount(){
                    var rowCount = PF('allTblWidget').paginator.cfg.rowCount;
                    //alert(rowCount);
                    var output = document.getElementById('summaryForm:summaryTabView:allTable:allCount');
                    if (output != null){
                        output.innerHTML = rowCount + " Records";
                    }
                }
                //]]>
              </script>
              <p:dataTable widgetVar="allTblWidget"
                             id="allTable" 
                             var="pb" 
                             value="#{statisticsBean.all}" 
                             emptyMessage="No data available!"
                             rowKey="#{pb.rowId}" 
                             scrollable="true" scrollHeight="440"
                             selection="#{statisticsBean.selectedBean}"
                             selectionMode="single"
                             editable="true"  
                             editMode="cell"
                             paginator="true"
                             rows="300"
                             paginatorAlwaysVisible="false">
                    <p:ajax event="filter"  oncomplete="updateAllRecordCount();"/>
                    <f:facet name="header">
                        <p:menubar styleClass="tableMenuClass">
                            ...
                            <f:facet name="options">
                                <h:outputText id="allCount" style="font-size:14px;" value="#{statisticsBean.all.size()} Records"/>
                            </f:facet>
                        </p:menubar>   
                    </f:facet>
                   ...

【问题讨论】:

  • 是在数据表本身中错误更新还是在您的 javascript 更新附加的“allCount”字段之后?请发布版本信息并将其设为minimal reproducible example(例如标签是否相关?)
  • allCount 字段中的计数错误更新。有时它是以前的计数,有时它是正确的,有时我必须按两次 Enter 键才能正确更新。 PF 版本是 5.1。
  • 标签并不重要。

标签: primefaces datatable primefaces-datatable


【解决方案1】:

下面列出的解决方法允许我在过滤后显示正确的记录数 - 我基本上使用下面数据表元素中列出的最后 3 个分页属性来显示过滤后的正确记录数并取出之前的过滤事件,JavaScript 函数, 和 outputText 字段。这个答案并没有真正回答最初的问题(我认为 PF 5.1 中可能存在错误),但至少它提供了一种解决方法。

<p:dataTable widgetVar="allTblWidget"
                         id="allTable" 
                         var="pb" 
                         value="#{statisticsBean.all}" 
                         emptyMessage="No data available!"
                         rowKey="#{pb.rowId}" 
                         scrollable="true" scrollHeight="440"
                         selection="#{statisticsBean.selectedBean}"
                         selectionMode="single"
                         editable="true"  
                         editMode="cell"
                         paginator="true"
                         rows="300"
                         paginatorAlwaysVisible="true"
                         paginatorTemplate="{CurrentPageReport}"
                         currentPageReportTemplate="{totalRecords} Records">

【讨论】:

  • 然后至少尝试检查它是否适用于较新的版本。如果分页器中的 PF 行数显示正确的数量,则问题出在其他地方
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多