显示p:dataTable行号

6
在mkyong的示例中,他们展示了如何在JSF中显示数据表行号。他们使用javax.faces.model.DataModel获取行索引,而不使用后端bean值。如何通过使用primfaces p:dataTable来实现这一点。谢谢。

请参见 https://dev59.com/KWct5IYBdhLWcg3wXsbH。 - acaruci
请参见 https://dev59.com/KWct5IYBdhLWcg3wXsbH。 - acaruci
2个回答

11
在PrimeFaces的p:dataTable组件中,该组件具有rowIndexVar属性,用于迭代引用每一行的索引。因此,您可以像下面我的示例那样操作。
<p:dataTable 
             var="cmr01Forms" 
             value="#{cmr01Bean.cmr01Forms}"
             rowIndexVar="index">
    <p:column>
        <f:facet name="header">
            <h:outputText value="index" />
        </f:facet>
        <h:outputText 
            value="#{index + 1}" />
    </p:column>
</p:dataTable>

1
 ***
  • 您可以使用rowIndex。rowIndexVar =“rowIndex”。它从0开始,因此您需要在每行上加1

<p:dataTable var="kat" value="#{kategoriBean.kategoriler}" rowIndexVar="rowIndex">
        <!--        <p:column headerText="Kategori Id"> -->
        <!--            <h:outputText value="#{kat.Id}" /> -->
        <!--        </p:column> -->
        <p:column headerText="NO">
            <h:outputText value="#{rowIndex+1}"></h:outputText>
        </p:column>
        <p:column headerText="Kategori Adı">
            <h:outputText value="#{kat.kategoriAdi}" />
        </p:column>
        <p:column>
            <h:outputText value="#{kat.kategoriKisaAciklama}"></h:outputText>
        </p:column>
    </p:dataTable>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接