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
mobile vistexmobile vistex 

problem in displaying visualforce page

hi i have requirement where i have to built visual force page.. my data will be stored in db like followingUser-added image



i want to show my visual force like following

User-added image



i have written some sample code  to dispaly header..
 
public list<String> getagrmnts(){
        m.put('Name','');
        m.put('Driver__c','');
        period.add('Agreement no');
        period.add('Driver');
        headerKeys.add('name');
        headerKeys.add('driver__c');
        list<String> tempStr = new list<String>{};
        for(Agreement1__c a : al){
            flag = 1;
            tempStr.add(a.name);
            tempStr.add(a.driver__c);
            //if(period.indexOf(a.period__c)==-1)
            for(String p: period ){
                if(p == a.period__c){
                    flag = 0;
                }
            }
            if(flag == 1){
                m.put(a.period__c,'');
                headerKeys.add(a.period__c);
                period.add(a.period__c);
            }    
        }
        return period;    
    }

and page code to display header is
<apex:page controller="header">
<apex:pageBlock >
<table>
<tr>
<apex:repeat value="{!agrmnts}" var="c">
<td>
<apex:outputText value="{!c}"></apex:outputText>
</td>
</apex:repeat>
</table>
</apex:page>

please tell me how can i fill data to that table i want to mshow like above
Patcs_1Patcs_1
Hi

You need to use wrapper class to achive this.
Gil GourévitchGil Gourévitch
Hi,
In my opinion, the fact that the month key is dynamic, the wrapper solution would not be so easy.
Maybe you can use this :
// public class member to iterate in VF page
    public List<Map<String, String>>  elements{get; set;}

    public List<Map<String, String>>  getagrmnts(){
        List<String> months = new List<String>{
            'jan',
            'feb',
            'mar',
            'apr',
            'may',
            'jun',
            'jul',
            'aug',
            'sep',
            'oct',
            'nov',
            'dec'
        };

        // sample code to emulate your custom object
        // use the SOQL request instead
        List<Map<String, String>> objects = new List<Map<String, String>>();
        for(Integer i = 1; i < 4; i++) {
            objects.add(new Map<String, String>{
                'name'          => 'A-000'+i,
                'driver'        => 'D'+i,
                'period'        => months[i],
                'sales'         => i+'0'
            });
        }

        elements = new List<Map<String, String>>();
        for(Map<String, String> obj : objects){
            Map<String, String> elt = new Map<String, String>();
            elt.put('name', obj.get('name'));
            elt.put('driver', obj.get('driver'));
            for(Integer j = 0; j<months.size(); j++){
                elt.put(months[j], '');
            }
            elt.put(obj.get('period'), obj.get('sales'));
            elements.add(elt);
        }

        return elements;
    }
In VF page :
<apex:page controller="header" >
<apex:pageBlock >
	<apex:pageBlockTable value="{!agrmnts}" var="agr">
		<apex:column value="{!agr['name']}"></apex:column>
		<apex:column value="{!agr['driver']}"></apex:column>
		<apex:column value="{!agr['jan']}"></apex:column>
		<apex:column value="{!agr['feb']}"></apex:column>
		<apex:column value="{!agr['mar']}"></apex:column>
		<apex:column value="{!agr['apr']}"></apex:column>
		<apex:column value="{!agr['may']}"></apex:column>
		<apex:column value="{!agr['jun']}"></apex:column>
		<apex:column value="{!agr['jul']}"></apex:column>
		<apex:column value="{!agr['aug']}"></apex:column>
		<apex:column value="{!agr['sep']}"></apex:column>
		<apex:column value="{!agr['oct']}"></apex:column>
		<apex:column value="{!agr['nov']}"></apex:column>
		<apex:column value="{!agr['dec']}"></apex:column>
	</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
Hope this helps
Gil

Question Solved ? Please mark as the best answer to help other users !
Vi$hVi$h
You could give even this a try : 
<apex:page standardController="Agreement__c" recordSetVar="agreements">
 <table>
 <tr>
     <td>
     </td>
     <td>
     </td>
     <apex:repeat value="{!agreements}" var="c" >
     <td>       
       <apex:outputText value="{!c.Period__c}"/><br/>
      </td>
    </apex:repeat>
</tr>
        <apex:variable value="{!1}" var="rowNum"/>
        <apex:repeat value="{!agreements}" var="c" >
        <tr>
        <td>       
           <apex:outputText value="{!c.Name}"/><br/>
        </td>
           <apex:repeat rows="{!rowNum}" value="{!agreements}">
           <td>
           </td>
            <apex:variable var="rowNum" value="{!rowNum + 1}"/>
       </apex:repeat>
       <td>
       <apex:outputText value="{!c.Sales__c}"/><br/>
       </td>
   </tr>
</apex:repeat>
</table>
  
</apex:page>
Not the most elegant solution, but works nonetheless ..

Thanks,
Vishal