Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 768
Agie Avatar asked Oct 14 '14 06:10

Agie


2 Answers

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>
like image 112
wittakarn Avatar answered Nov 12 '22 06:11

wittakarn


 ***
  • 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>
like image 24
fatih bayhan Avatar answered Nov 12 '22 08:11

fatih bayhan