You need to sign in to do that
Don't have an account?

how to dispaly recordID or rowindex in pageblocktable
In a pageblock table I want to render more than one records returned by statndardcontroller or extension controoler.
How can I specify the recordId or the record index in pageblock table?
e.g.
sr no. name age city
1) tom 22 boston
2) jim 33 ny
3) shaun 34 LA
I can retrieve name,aga and city.. but my controller can not get record index
i.e 1 for Tom
2 for Jim
3 for shaun etc.
Is there any way to render dynamically in visualforce?
You can make use of apex:variable component.
<apex:variable var="sr" value="{!1}"/>
<apex:pageBlockTable>
.
<!-- columns code here -->
.
<apex:variable var="sr" value="{!sr + 1}"/>
</apex:pageBlockTable>
Give it a try and let me know if it works for you.
It increments once to show same number on all rows...
2 ..................
2................
2...............
2..........
2...........
any other clue/hint?
You have to made some changes into your code.
The variable doesn't work with datatable and pageblocktable. However it works perfect with the repeat and datalist component.
check the link
http://blog.jeffdouglas.com/2010/04/02/visualforce-row-counter-for-iteration-components/
This is exactly what you want.
Regards,
Hello,
Create a javascript funciton in page as:
var index =1;
function getValue(){
index = index +1;
}
and then use a outputText as:
<apex:outputText value="<script>document.write(index);getValue();</script>" escape="false"/>
Regards,
PP
You have to put the statement which increments the variable inside a column for some reason, but if the table refreshes the variable doesn't necessarily reset as well (maybe it will if you refresh the defining statement as well, I didn't bother to test this just switched to a different method)
HI
Try this code
<apex:variable var="sr" value="{!0}"/>
<apex:pageBlockTable>
.
<!-- columns code here -->
.<apex:column value="Serial No">
<apex:variable var="sr" value="{!sr + 1}"/>
{!sr}
.</apex:column>
</apex:pageBlockTable>
Did this post answers your question If so please mark as solution and give kudos for this post
Thanks
<apex:variable var="rowNum" value="{!0}"/>
<apex:pageBlockTable>
<apex:column headerValue="No">
<apex:variable var="rowNum" value="{!rowNum + 1}"/>
{!rowNum}
</apex:column>
</apex:pageBlockTable>
<div style="padding-top: 20px;">
<apex:outputPanel id="thePanel" styleClass="printButtonClass" >
<apex:outputLabel style="font-weight:bold;color:black" id="plUnionlabel" value="{!$Label.Select_Union}" for="plUnion" rendered="{!bShow}" />
<apex:selectList style="width:140px;" id="plUnion" value="{!selectedUnion}" size="1" multiselect="false" rendered="{!bShow}" >
<apex:selectOptions value="{!unionOptions}" />
<apex:actionSupport event="onchange" action="{!changeOptionUnion}" rerender="counter,error,theTable,summary" />
</apex:selectList>
</apex:outputPanel>
<input id="buttonPrint" type="button" value="{!$Label.Print}" onclick="printForm();" class="printButtonClass"/>
</div>
<!-- skippped -->
<apex:variable id="counter" var="i" value="{!1}"/>
Thanks!
Final working code for Autoincrement the Table Column values
<tr>
<th style="background-color:#58D68D">Sample Data1</th>
<th style="background-color:#58D68D">Sample Data2</th>
<th style="background-color:#58D68D">Sample Data3</th>
<th style="background-color:#58D68D">Sample Data4</th>
<th style="background-color:#58D68D">Sample Data5</th>
<th style="background-color:#58D68D">Sample Data6</th>
<th style="background-color:#58D68D"> Sample Data7</th>
</tr>
<apex:variable var="count" value="{!0}" />
<apex:repeat value="{!VariableName}" var="pass">
<apex:variable var="count" value="{!count+1}"/>
<tr>
<td><apex:outputText value="{!count}"/></td>
<td> {!pass.Variable1} </td>
<td> {!pass.Variable2} </td>
<td> {!pass.Variable3} </td>
<td> {!pass.Variable4} </td>
<td> {!pass.Variable5} </td>
<td> {!pass.Variable6} </td>
</tr>
</apex:repeat>
</table>