[英]Primefaces datatable - sorting and filtering not working
I have a datatable with dynamic header and columns based on the selected period and infomation to display. 我有一个基于所选时间段和要显示的信息的带有动态标题和列的数据表。 The problem is that I keep getting and exception while trying to either sort or filter data. 问题是在尝试对数据进行排序或过滤时,我不断遇到异常。
I am using Primefaces 5.0 and my datatable looks as follows: 我正在使用Primefaces 5.0,我的数据表如下所示:
<p:scrollPanel id="reportsScroll" style= "#{reportsMB.gridSize}" >
<p:dataTable id="reportsTable" var="rowData" value="#{reportsMB.gridData}" widgetVar="reportsTable"
filteredValue="#{reportsMB.filteredValues}" paginator="true" rows="100"
currentPageReportTemplate="Displaying {startRecord} - {endRecord} of
{totalRecords} teams, Page: {currentPage}/{totalPages}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks}
{NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5,10,15,25,50,100">
<f:facet name="header">
<p:outputPanel style="float:left">
<h:outputText value="Search all fields:" />
<p:inputText id="globalFilter" onkeyup="PF('reportsTable').filter()" style="width:150px;" placeholder="Enter keyword"/>
</p:outputPanel>
</f:facet>
<p:columnGroup type="header">
<p:row>
<c:forEach items="#{reportsMB.sumaryInfo}" var="sumary">
<p:column rowspan="#{sumary.rows}" sortBy="#{rowData[sumary.key]}" rendered="#{sumary.name == 'User display name'}"
filterStyle="display:none" styleClass="#{reportsMB.detailsSelected ? 'userHeaderSize' : ''}" filterBy="#{rowData[sumary.key]}"
filterMatchMode="contains" headerText="#{sumary.name}" />
<p:column rowspan="#{sumary.rows}" sortBy="#{rowData[sumary.key]}" rendered="#{sumary.name != 'User display name'}"
filterStyle="display:none" styleClass="#{reportsMB.detailsSelected ? 'headerSize' : ''}" filterBy="#{rowData[sumary.key]}"
filterMatchMode="contains" headerText="#{sumary.name}" />
</c:forEach>
<c:forEach items="#{reportsMB.months}" var="month">
<p:column rendered="#{reportsMB.detailsSelected}" colspan="#{month.columns}" headerText="#{month.name}" />
</c:forEach>
</p:row>
<p:row rendered="#{reportsMB.detailsSelected}">
<c:forEach items="#{reportsMB.weeks}" var="week">
<p:column colspan="#{week.columns}" headerText="#{week.name}" />
</c:forEach>
</p:row>
<p:row rendered="#{reportsMB.detailsSelected}">
<c:forEach items="#{reportsMB.daysNames}" var="dayName">
<p:column headerText="#{dayName}" />
</c:forEach>
</p:row>
<p:row rendered="#{reportsMB.detailsSelected}">
<c:forEach items="#{reportsMB.days}" var="day">
<p:column headerText="#{day.name}" width="20" sortBy="#{rowData[day.key]}" />
</c:forEach>
</p:row>
</p:columnGroup>
<p:columns value="#{reportsMB.sumaryInfo}" var="sumary">
<h:outputText value="#{rowData[sumary.key]}"> </h:outputText>
</p:columns>
<p:columns rendered="#{reportsMB.detailsSelected}" value="#{reportsMB.days}" var="day" id="idul">
<h:outputText style="color:green;" rendered="#{rowData[day.key] == 'OH'}" value="#{rowData[day.key]}"> </h:outputText>
<h:outputText style="color:#1cd5ed;" rendered="#{rowData[day.key] == 'REG' or rowData[day.key] == 'RES'}" value="#{rowData[day.key]}"> </h:outputText>
<h:outputText style="color:red;" rendered="#{rowData[day.key] == 'SICK'}" value="#{rowData[day.key]}"> </h:outputText>
<h:outputText style="color:black;" rendered="#{rowData[day.key] == 'UNP'}" value="#{rowData[day.key]}"> </h:outputText>
<h:outputText style="color:#ff69b4;" rendered="#{rowData[day.key] == 'SPEC'}" value="#{rowData[day.key]}"> </h:outputText>
<h:outputText style="color:orange;" rendered="#{rowData[day.key] == 'OVRT'}" value="#{rowData[day.key]}"> </h:outputText>
<h:outputText style="color:gray;" rendered="#{rowData[day.key] == 'WE'}" value="#{rowData[day.key]}"> </h:outputText>
<h:outputText style="color:black;" rendered="#{rowData[day.key] == 'NH' or rowData[day.key] == 'GONE'}" value="#{rowData[day.key]}"> </h:outputText>
</p:columns>
The exception is : 例外是:
May 30, 2014 11:13:27 AM com.sun.faces.context.PartialViewContextImpl processPartial
INFO: javax.faces.FacesException: Cannot find column with key: datatable:reportsTable:j_idt99
javax.faces.FacesException: Cannot find column with key: datatable:reportsTable:j_idt99
at org.primefaces.component.datatable.DataTable.findColumn(DataTable.java:773)
at org.primefaces.component.datatable.feature.SortFeature.decode(SortFeature.java:87)
at org.primefaces.component.datatable.DataTableRenderer.decode(DataTableRenderer.java:61)
May 30, 2014 11:13:27 AM com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback visit
SEVERE: javax.el.ELException: Error Parsing: #{rowData.null}
Can anyone tell me how to make it work? 谁能告诉我如何使其运作? Thanks! 谢谢!
This line, onkeyup="PF('reportsTable').filter()"
, is incorrect since reportsTable
is defined as an id. 这行onkeyup="PF('reportsTable').filter()"
是错误的,因为reportsTable
被定义为一个id。 It should be defined as a widgetVar. 应该将其定义为widgetVar。 So add widgetVar="reportsTable"
will probably solve your problem. 因此,添加widgetVar="reportsTable"
可能会解决您的问题。
Last time something similar happened to me, I had forgotten to enclose the dataTable with a form tag. 上次发生类似的事情时,我忘记了用表格标签将dataTable括起来。 It's a simple idea, but it took me some time trying to find the problem. 这是一个简单的主意,但花了我一些时间才能找到问题所在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.