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
jaysunjaysun 

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?

Prafull G.Prafull G.

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.

jaysunjaysun

It increments once to show same number on all rows...

2 ..................

2................

2...............

2..........

2...........

 

any other clue/hint?

 

Prafull G.Prafull G.

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,

Pratibh PrakashPratibh Prakash

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

 

fgwarb_1fgwarb_1

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)

 

<apex:variable [whatever the rest of this is] />
<apex:pageBlockTable>
     <apex:column>
          <apex:variable [incrementing code] />
          <!-- whatever normal content you want displayed in this column -->
     </apex:column>
</apex:pageBlockTable>

 

TryForce.ax1449TryForce.ax1449
<apex:page standardcontroller="Contact" recordSetVar="Con">
<apex:sectionHeader title="All Contact With Serial Number"/>
 <apex:form >
     <table>
         <tr>
             <td>
                    <apex:variable var="call" value="{!0}" />
                        <apex:repeat var="C" value="{!Con}">
                            <tr>
                                <td><apex:variable var="call" value="{!call+1}"/>
                                    <apex:outputText value="{!call}"/>
                                </td>
                                <td>
                                    {!C.Name}
                                </td>
                                <td>
                                    {!C.Email}
                                </td>
                                <td>
                                    {!C.Phone}
                                </td>
                                <td>
                                    {!C.Account.Name}
                                </td>                                             
                            </tr>                                                  
                    </apex:repeat>            
             </td>
         </tr>
     </table>
</apex:form>
 
</apex:page>
asish1989asish1989

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

Akhilesh DahatAkhilesh Dahat
Correct Code to achive this is below.
            <apex:variable var="rowNum" value="{!0}"/>
            <apex:pageBlockTable>
                 <apex:column headerValue="No">
                     <apex:variable var="rowNum" value="{!rowNum + 1}"/>
                     {!rowNum}
                 </apex:column>
           </apex:pageBlockTable>

 
igoruigoru
If you doing re-select data (for example custom report with picklist) DO NOT FORGET to refresh counter 'ID' - otherwise it brings 'broken' numbers! :)
igoruigoru
I mean something like this: 

    <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}" />&nbsp;&nbsp;
    <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}"/>
Jack D PondJack D Pond
Regarding the header problem, I found an answer to this here (http://salesforce.stackexchange.com/questions/245/dynamic-number-of-columns-in-a-pageblocktable) .  The short answer is to create the dynamic columns first, then after you've defined them, define headers  and hide the created empty cells.
 
<!--Define the headers after you define the dynamic columns, then hide the empty cells that are created -->
<apex:repeat var="header" value="{!headers}">
    <apex:column headerValue="{!header}" styleClass="empty-column-content" />
</apex:repeat>

 
Jeremiah BaylesJeremiah Bayles
Is there any way to do this in a standard report?
Thanks!
Ganesh ThigariGanesh Thigari

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>  
karthickeyan trainingkarthickeyan training
These solution will work fine only if there is no pagination. If we  use pagination the sirial number will reset to intial value. can some one provoid an better solution for that.