我有像这样的Primefaces DataTable
<p:dataTable
value="#{valueList.value}"
var="value"
selection="#{valueList.selected}"
id="measurementTable"
paginator="true"
rows="20"
rowsPerPageTemplate="20,25,30,35,40"/>
和带有此
的动态列<p:columns
value="#{valueList.columns}"
var="column"
columnIndexVar="colIndex"
/>
这很好,我的Datatable看起来不错,但是当我添加
时 sortBy="#{value.charge}"
到p:columns
,我点击了列来排序css样式是destroyd并且我得到了一个List,我的数据不是DataTable,这非常难看。
我的代码
<p:dataTable
value="#{measurementList.measurements}"
var="measurement"
selection="#{measurementList.selected}"
id="measurementTable"
paginator="true"
rows="20"
rowsPerPageTemplate="20,25,30,35,40"
rowKey="#{measurement.mdkFid}"
emptyMessage="#{measurementList.getCapString('no_records_found')}">
<p:column selectionMode="multiple" style="width:18px" />
<p:column>
<p:commandLink title="#{measurementList.getString('edit')}" update=":contentPanel">
<h:outputText styleClass="ui-icon ui-icon-pencil" />
<f:actionListener binding="#{measurementList.editSelected(measurement) }" />
<f:actionListener binding="#{navigation.goTo('/xhtml/measurements/editMeasurement.xhtml') }" />
</p:commandLink>
</p:column>
<p:columns
value="#{measurementList.columns}"
var="column"
columnIndexVar="colIndex"
styleClass="measurementListDatatableColumn"
sortBy="#{column.displayName}"
>
<f:facet name="header">#{column.displayName}</f:facet>
<p:column>
#{measurement[column.methodName]}
</p:column>
</p:columns>
答案 0 :(得分:4)
您的排序应该类似于
sortBy="#{value[column.charge]}"
查看展示示例DataTable - Dynamic Columns
更改
<p:columns
value="#{measurementList.columns}"
var="column"
columnIndexVar="colIndex"
styleClass="measurementListDatatableColumn"
sortBy="#{column.displayName}"
>
<f:facet name="header">#{column.displayName}</f:facet>
<p:column>
#{measurement[column.methodName]}
</p:column>
</p:columns>
到
<p:columns
value="#{measurementList.columns}"
var="column"
columnIndexVar="colIndex"
styleClass="measurementListDatatableColumn"
sortBy="#{measurement[column.methodName]}"
>
<f:facet name="header">
#{column.displayName}
</f:facet>
#{measurement[column.methodName]}
</p:columns>
通常:用于显示列数据的相同EL表达式应该用于sortBy