function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
OnkiOnki 

find counter for repeat component

Hi

 

Can any one help me to how can we count the repeat counter.I want display sequeance number when display data using repeat.

Best Answer chosen by Admin (Salesforce Developers) 
mtbclimbermtbclimber

Here are a couple of options you might try....

 

 

<apex:page controller="repeaterCon"> <apex:variable value="{!1}" var="rowNum"/> <apex:repeat value="{!collection}" var="row"> ({!rowNum}){!row}<br/> <apex:variable var="rowNum" value="{!rowNum + 1}"/> </apex:repeat> <apex:dataList value="{!collection}" var="row" type="1"> {!row} </apex:dataList> </apex:page>

 

 

public class repeaterCon { public String[] collection { get; set; } public repeaterCon() { collection = new String[]{'ONE','TWO','THREE'}; } }

 

 

All Answers

mattdarnoldmattdarnold

You could just use a getter in your controller to display the size of the list you're using in the repeat component. For example:

 

Public TestClass {

List<Opportunity> opps = new List<Opportunity>();
public TestClass() {
// Code to populate opps
}

public Integer getOppsSize() {
return this.opps.size();
}

public List<Opportunity> getOpps() {
return this.opps;
}
}

 

Then within your page, reference {!oppsSize} for the number of records in the repeat component and reference {!opps} within the repeat component. Let me know if that helps and answers your question.

 

mtbclimbermtbclimber

Here are a couple of options you might try....

 

 

<apex:page controller="repeaterCon"> <apex:variable value="{!1}" var="rowNum"/> <apex:repeat value="{!collection}" var="row"> ({!rowNum}){!row}<br/> <apex:variable var="rowNum" value="{!rowNum + 1}"/> </apex:repeat> <apex:dataList value="{!collection}" var="row" type="1"> {!row} </apex:dataList> </apex:page>

 

 

public class repeaterCon { public String[] collection { get; set; } public repeaterCon() { collection = new String[]{'ONE','TWO','THREE'}; } }

 

 

This was selected as the best answer
OnkiOnki

Thanks to reply

 

But i need counter means after each and every loop or repeater i want show counter Value  as a sequanc.

 

  <apex:repeat value="{!Opportunies}" var="opp1" first="0" id="theRepeatproduct">

      <apex:outputText value="{!opp1.Name}"></apex:outputText>

  <apex:repeat>

 

Output should be like that

 

1. Opp1Name

2. Opp2Name

.

.

.

.

.

till end of the repeater

mtbclimbermtbclimber
Right, is that not what mine does for you? Or were you responding to mattdarnold?
OnkiOnki

You are right i need what u given. but its not working ,The output for your given code is

 

(1.0)01u80000002PBubAAG
(1.0)01u80000002PBucAAG
(1.0)01u80000002PBudAAG
(1.0)01u80000002PBueAAG
(1.0)01u80000002PBufAAG
...................

mtbclimbermtbclimber

Can you post your code? I'm not seeing what you are seeing....

 

 

 

OnkiOnki

Hey sorry

 

Its working fine i was trying to use it without datalist i added datalist and its working fine with data list. can we do this only with repetar.

 

Thanks Hope it will solve my problem.

 

Thanks again..

 

 

 

mtbclimbermtbclimber
The apex:variable technique should work with any component that does iteration - repeat, dataTable, dataList, etc.   I thought I'd throw in the standard use of dataList in case that would be sufficient for your needs.
jeffdonthemic2jeffdonthemic2

This worked fine with the repeat and dataList components but now with a dataTable. See this post for more info and my workaround.

 

Visualforce Row Counter for Iteration Components

 

Jeff Douglas

Appirio, Inc.

http://blog.jeffdouglas.com