Agie
Agie

Reputation: 114

Display p:dataTable Row Numbers

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

Answers (2)

fatih bayhan
fatih bayhan

Reputation: 31

 ***
  • you can use rowindex. rowIndexVar="rowIndex". it starts with 0 so you ve to plus 1 every row

<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

wittakarn
wittakarn

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

Related Questions