使用 p:dataTable 进行行编号
我有这个查询:
SELECT @rownum:=@rownum+1 'no', m.title, m.author, REPLACE(SUBSTRING_INDEX(m.content, ' ', 20), '<br>', ' '), m.viewed, m.hashid FROM book m, (SELECT @rownum:=0) r WHERE m.lang = ?1 AND m.title like CONCAT('%',?2,'%') ORDER BY m.title asc
MySQL 查询的 @rownum:=@rownum+1
部分将结果编号作为 Primefaces 目前没有显示编号列的功能.
The @rownum:=@rownum+1
part of the MySQL query for result numbering as Primefaces currently does not have a facility to display a numbering column.
有没有办法不用@rownum:=@rownum+1
就可以显示Primefaces的列编号?
Is there a way to show Primefaces column numbering without having to do @rownum:=@rownum+1
?
如果不是,我可以仅使用 CriteriaBuilder 方法构造上述查询吗?
If not, can I construct the above query using purely the CriteriaBuilder method?
推荐答案
我不太确定您想要编号列"还是列编号".我假设第一个 ;-)
I am not quite sure whether you want a "numbering column" or "column numbering". I assume the first ;-)
你不能使用 rowIndexVar
吗?Primefaces 文档说:
Can't you use rowIndexVar
? The Primefaces doc says:
rowIndexVar = 变量名引用rowIndex 正在处理中.
rowIndexVar = Variable name referring to the rowIndex being processed.
这对我有用:
<p:dataTable value="#{testBean.selectOptions}" rowIndexVar="rowIndex" var="item">
<p:column headerText="#">
#{rowIndex+1}
</p:column>
<p:column headerText="Option">
#{item}
</p:column>
</p:dataTable>
+1 表示从数字 1 开始.
The +1 is for starting with number 1.
更新:
此代码产生:
相关文章