Row numbering with p:dataTable

前端 未结 1 1568
青春惊慌失措
青春惊慌失措 2020-12-16 04:40

I have this query:

SELECT @rownum:=@rownum+1 \'no\', m.title, m.author, REPLACE(SUBSTRING_INDEX(m.content, \' \', 20), \'
\', \' \'), m.viewed, m.ha
相关标签:
1条回答
  • 2020-12-16 05:05

    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:

    enter image description here

    0 讨论(0)
提交回复
热议问题