Reputation: 114
In mkyong example, they show How To Display DataTable Row Numbers In JSF. They use javax.faces.model.DataModel to get row index without using backing bean value. How to achieve this by using primfaces p:dataTable. Thanks.
Upvotes: 6
Views: 16406
Reputation: 31
***
<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>
Upvotes: 1
Reputation: 3164
In primefaces p:datatable component, the component has rowIndexVar attribute, which is used to iterate to refer each row index. Thus, you can do like my example below
<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>
Upvotes: 11