Total Pageviews

Monday, September 17, 2012

Simple Row Counter while using Iterators/ Repeats in Visual Force

A simple way to display serial number in a repeater (Visual Force):-
I have always found it a bit awkward to use either javascript or wrapper class to display serial numbers while using repeaters in apex. Its a basic requirement in any VF UI involving iterators but till now I had been taking the torturous route of "wrapper class" or "Javascript".
In case you too faced the same issue, perhaps the following code snippet will resolves your coding owes and make things easier and simpler for you.
The counter variable used here " rowCtr  " has to be defined as a property in your controller class.

VF Page code snippet using the Iterator (repeater) and the row counter:-
<apex:variable value="{!1}" var="  rowCtr  "/>
<apex:repeat value="{!RepeaterVar}" var="cb">
<td>{!FLOOR(  rowCtr  )}</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
<apex:variable var=" rowCtr " value="{!  rowCtr  + 1}"/>
Controller Code Snippet:-
public with sharing class TestController {
public integer rowNum;
public integer getrowNum()
return rowNum;

No comments:

Post a Comment