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">
<tr>
<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}"/>
</tr>
</apex:repeat>
Controller Code Snippet:-
public with sharing class TestController {
public integer rowNum;
public integer getrowNum()
{
return rowNum;
}
}
======================================================

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me..
    I am a regular follower of your blog. Really very informative post you shared here.
    Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai .
    or Javascript Training in Chennai.
    Nowadays JavaScript has tons of job opportunities on various vertical industry. ES6 Training in Chennai

    ReplyDelete