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
kk045kk045 

Displaying numbers in datatable in the ascending order

hi i want to display seriol numbers for the data table as 1,2,3,4,5,6,7,8,9 for the table so how to write a program

Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Hi,

 

You can acheive this by using a <apex:variable> component in your vf page.

 

Try the following method,

 

<apex:page>
  <apex:variable value="{!1}" var="index">
    <apex:pageblocktable value="{!ListOfItems}" var="item">
         <apex:column>
              <apex:outputlabel value="{!index}">
              </apex:outputlabel>

          </apex:column>
          <apex:column>
             <apex:outputlabel value="{!item.Name}">
                   <apex:variable value="{!index+1}" var="index">
                    </apex:variable>

              </apex:outputlabel>

        </apex:column>
    </apex:pageblocktable>
 </apex:variable>

</apex:page>

 

 

Hope so this helps you...!

Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.

 

 

kk045kk045
how to use the controller in it,
i am acessing pagetable in vfpage for that i need to write
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Hi,

 

You already having a list of records to display in the table know?. So, you don't need to write a controller for that <apex:variable/>.

Just you can include the variable component in the vf pageblocktable. Example am using List of accounts in my organisation. See the below example.

 

<apex:page controller = "AccountController">
  <apex:variable value="{!1}" var="index">
    <apex:pageblocktable value="{!ListOfAccounts}" var="item">
         <apex:column>
              <apex:outputlabel value="{!index}">
              </apex:outputlabel>

          </apex:column>
          <apex:column>
             <apex:outputlabel value="{!item.Name}">
                   <apex:variable value="{!index+1}" var="index">
                    </apex:variable>

              </apex:outputlabel>

        </apex:column>
    </apex:pageblocktable>
 </apex:variable>

</apex:page>

 

 

Controller:

 

public class AccountController{

public List<Account> ListOfAccounts{get;set;}
    public VariableController(){
        ListOfAccounts = [select id,name from Account];
    }

}

 

Hope so this helps you...!

Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.