我是Primefaces的新手。
我正在使用Primefaces 5.1和jsf 2.2开发一个项目。
我不知道如何计算p:dataTable
中的行数?
我需要根据行数设置饼图。
有什么想法吗?
我是Primefaces的新手。
我正在使用Primefaces 5.1和jsf 2.2开发一个项目。
我不知道如何计算p:dataTable
中的行数?
我需要根据行数设置饼图。
有什么想法吗?
p:datatable
中设置一个 widgetVar
。<p:dataTable value="#{tableBean.myTable}" widgetVar="myTable">...</p:dataTable>
然后您可以使用它轻松从Javascript中访问您的表
要计算您的表中的行数
PF('myTable').tbody[0].children.length
PF('myTable').cfg.paginator.rowCount
number of rows
。public int getNumberOfRows() {
return this.myDataTableList.size();
}
如果你所说的“行数”是指在我的 p:datatable
中当前可见的数据量,并且你使用了一个 paginator
,那么答案就是你选择初始化datatable时的相同数字(除了最后一页可能)。
如果你想在客户端访问行数,你必须使用类似这样的东西:
$("#YOUR_DATATABLE_ID").find(".ui-datatable-tablewrapper").find(".ui-datatable-data").find(".ui-widget-content").length
但这只会显示当前可见的行(如果您正在使用分页器)。如果您想获取所有行并使其更容易,可以像上面所示,在后端bean中让行数可访问。
如果有人仍然需要此功能,只是为了显示目的。从版本5开始,您在分页器模板中拥有所谓的{CurrentPageReport}元素。它允许通过搜索“currentPageReportTemplate”在Primefaces文档中进行自定义,它有点隐藏:) {{link1:Primefaces 5.1 Docu}}
使用{totalRecords},您可以输出表中记录的数量。它还可以与活动过滤器一起使用。这是一个例子:
<p:dataTable var="entry" value="#{mbvHandler.entries}"
widgetVar="carsTable" id="carsTable"
scrollable="true" scrollWidth="100%"
filteredValue="#{mbvHandler.filteredEntries}"
rows="25" paginator="true" resizableColumns="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown} {Exporters}"
currentPageReportTemplate="{currentPage} of {totalPages} ({totalRecords})"
rowsPerPageTemplate="10,15,25,50">
<p:dataTable value="#{tableBean.myTable}">...</p:dataTable>
<h:outputText value="#{tableBean.myTable.size()}"/>