You need to sign in to do that
Don't have an account?
Prasanna1838
How to use For loop(using list) to display various values for each record in a pageblocktable
I have created a page which performs a search and displays the matching records using List by a pageblocktable.
Along with the records names,I need to show some dummy percentage values assoicated to these records.I tried displaying the data using for loop,but all the records are getting displayed with same percentage.
<apex:column headerValue="Account"> <apex:outputLink value="/{!a.Id}" target="_blank">{!a.Name}</apex:outputLink> {!percentage} % Match </apex:column>
I have created accList which performs my search
Public Integer percentage{get;set;}
for(Account acc:accList) { percentage=78; }
. How to display different values for each record using pageblocktable.
Thanks,
prasanna
Hi sai,
There is no such field called percentage on "Account" object.I just need some random dummy values allocated to each record in the table to just show the % matched while searched.
Can't we write a for loop to allocate diff values to each record in a table.Please let me know.
If you need to add some additional value to the list which is not available on the record , then you can create a wrapper class to combine your record and the percentage value.
Then you can use the list of wrapper class in your datatable to display both the record and the percentage value.
Hi,
Yes, if you want a certain value to be associated with each of your record in your list ,you need to use a wrapper class.
It will help you bind a specific value for each record in your collection.
An example:
Suppose you have the search result records stored in the List<Account> lstResults
Create a wrapper class which will have a decimal variable and an Account (because you'll bind one % for each Account)
public class accountMatch
{
public Decimal percentageMatch{get;set;}
public Account objAccount {get;set;}
public accountMatch(Decimal per, Account acc)
{
percentageMatch = per;
objAccount = acc;
}
}
Now, iterate through each of your record and pass them to the wrapper class list:
List<accountMatch> lstRecords = new List<accountMatch>(); // use this list on your vf page in pageblocktable
for(Account a : lstResults)
{
Decimal perMatch = 15; // or any calculation
accountMatch am = new accountMatch(perMatch, a);
}