You need to sign in to do that
Don't have an account?
Rakesh Sahoo
Accessing Column header as map-key and data as map-value of a map in visualforce page
I want to display the map-key in the header and map-value in data in visulforce page, how can i do this help me.
<apex:page controller="RMDKChart1CountryAllRevenue" tabStyle="Opportunity" sidebar="false"> <apex:pageBlock > <apex:pageBlockSection title="Revnue Type - Hire"> <apex:pageBlockTable value="{!MyReportHireData}" var="r" title="Report data"> <!-- <apex:column value="{!r.os.OpportunityLineItem.Opportunity.Id}"/> <apex:column value="{!r.os.OpportunityLineItem.PricebookEntry.Name}"/> --> <apex:column value="{!r.os.OpportunityLineItem.Opportunity.Name}"/> <apex:column value="{!r.os.OpportunityLineItem.Opportunity.Account.Name}"/> <apex:column value="{!r.os.OpportunityLineItem.Opportunity.Probability}"/> <apex:column value="{!r.os.OpportunityLineItem.Opportunity.OwnerID}"/> <apex:repeat value="{!r.mpkeys}" var="month"> <apex:column headerValue="{!month}"> <apex:outputText value="{!r.MonthMap[month]}"/> </apex:column> </apex:repeat> <!-- <apex:column value="{!r.MonthMap}"/> --> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:page>
COntroller---
public with sharing class RMDKChart1CountryAllRevenue { public list<OpportunityLineItemSchedule> oppSchList = new list<OpportunityLineItemSchedule>(); public map<Id,MyReport> myReportHireMap = new map<Id,MyReport>(); public list<OpportunityLineItemSchedule> getoppSchList() { return oppSchList; } public list<MyReport> getMyReportHireData() { return myReportHireMap.values(); } public class MyReport { Public OpportunityLineItemSchedule os {get;set;} Public Map<Integer, Decimal> monthMap{get;set;} public MyReport(OpportunityLineItemSchedule ops,Map<Integer, Decimal> mp) { os = ops; monthMap = mp; } } public RMDKChart1CountryAllRevenue() { //For Hire oppSchList = [Select OpportunityLineItem.Opportunity.Id, ScheduleDate,OpportunityLineItem.Opportunity.Name,OpportunityLineItem.Opportunity.Account.Name, OpportunityLineItem.PricebookEntry.Name,OpportunityLineItem.Opportunity.Sales_Region__c,OpportunityLineItem.Opportunity.Phase_Detail__c,OpportunityLineItem.Opportunity.Revenue_Start_Date__c,OpportunityLineItem.Opportunity.Revenue_End_Date__c, Revenue,OpportunityLineItem.Opportunity.StageName, OpportunityLineItem.Opportunity.Probability, OpportunityLineItem.Opportunity.OwnerID From OpportunityLineItemSchedule where CALENDAR_YEAR(ScheduleDate)=2013 and OpportunityLineItem.PricebookEntry.Name = 'Hire' order by scheduleDate]; for(OpportunityLineItemSchedule os : oppSchList) { if(!myReportHireMap.containsKey(os.OpportunityLineItem.Opportunity.Id)) { Map<Integer,Decimal> monthMap = new Map<Integer, Decimal>{1=>0,2=>0,3=>0,4=>0,5=>0,6=>0,7=>0,8=>0,9=>0,10=>0,11=>0,12=>0}; monthMap.put((os.ScheduleDate).month(),os.revenue); MyReport myr = new Myreport(os,monthMap); myReportHireMap.put(os.OpportunityLineItem.Opportunity.Id,myr); } else { myReportHireMap.get(os.OpportunityLineItem.Opportunity.Id).monthMap.put((os.ScheduleDate).month(),os.revenue); } } } }
Hello Rakesh!
Check this out: http://harshesh7487.blogspot.ro/2011/05/using-map-in-pageblock-table-in.html
Word of caution: make sure that yourmap[key] doesn't return any null values... otherwise bad stuff is gonna happen.
Thank you,
Adrian