使用p:dataTable进行行编号 [英] Row numbering with p:dataTable

查看:185
本文介绍了使用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.

有没有一种方法可以显示Primefaces列编号而不必执行@rownum:=@rownum+1?

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.

更新:

此代码产生:

这篇关于使用p:dataTable进行行编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆