【问题标题】:Update count of rows of datatable after filtering过滤后更新数据表的行数
【发布时间】:2019-11-06 16:10:35
【问题描述】:

我有一个启用了过滤的带有 Primefaces 数据表的 Java webapp。我想显示表格的行数。我正在使用 ajax 调用来更新行数。问题在于,在过滤之前调用了更新调用。所以每次我过滤我都会看到previois过滤结果的行数。

素面:

<p:outputLabel id=count value="#{myClass.displayedCount}" />
<p:dataTable <!-- filter and all the stuff --> ...>
   <p:ajax event="filter" update=":count"></p:ajax>

Java代码:

public int getDisplayedCount() {
   displayedCount = filteredData != null ? filteredData.size() : data.size();
   return displayedCount;
}

示例: 默认计数为 10,第一次过滤后计数仍为 10,但表中仅显示 5 个条目。再次过滤后,计数为 5,但表中有 7 个条目。

我该如何解决这个问题?

提前致谢。

【问题讨论】:

  • {totalRecords} 中的 paginator templates 键不能解决您的挑战吗?
  • 在不考虑过滤的情况下,{totalRecords} 不显示数据表中所有条目的值吗?因此,如果总共有 10 行,并且由于过滤而只有 1 行是可见的,那它不会仍然显示 10 吗?
  • 我测试了它,它有效,我的假设是错误的。非常感谢

标签: jsf filter primefaces datatable


【解决方案1】:

正如@Selaron 在 cmets 中建议的那样,我在数据表中使用了 {totalRecords}

<p:dataTable ... paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} " currentPageReportTemplate="Showing {startRecord}-{endRecord} out of {totalRecords}">

我将paginatorTemplatecurrentPageReportTemplate 添加到dataTable。但我很确定,paginatorTemplate 做了什么。谁能解释一下?

但问题就这样解决了。

感谢@Selaron。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2022-11-12
  • 2015-08-23
  • 2012-10-06
  • 2018-01-14
  • 1970-01-01
  • 2018-10-10
  • 2013-07-30
  • 1970-01-01
相关资源
最近更新 更多