Row numbering with p:dataTable

心已入冬 提交于 2019-11-30 07:14:41

问题


I have this query:

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

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.

Is there a way to show Primefaces column numbering without having to do @rownum:=@rownum+1?

If not, can I construct the above query using purely the CriteriaBuilder method?


回答1:


I am not quite sure whether you want a "numbering column" or "column numbering". I assume the first ;-)

Can't you use rowIndexVar? The Primefaces doc says:

rowIndexVar = Variable name referring to the rowIndex being processed.

This works for me:

<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>

The +1 is for starting with number 1.

UPDATE:

This code produces:



来源:https://stackoverflow.com/questions/5698513/row-numbering-with-pdatatable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!