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.
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>
***
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With