You need to sign in to do that
Don't have an account?
How to apply formatting in the controller to data to be displayed in VF table
Hi
I was expecting to find this information easily but I've not found anything.
In my controller I run a SOQL statement with 'group by rollup' and I then display the records in a visualforce table.
Each time that a subtotal is displayed, I want to either indent or right justify the word 'Subtotal' and do the same for the grand total. I can't find anything that explains how to apply this formatting in the controller.
Any help would be greatly appreciated.
Here's the controller:
Here's the VF:
Here's the ouput:

Wherever 'Subtotal' appears, I want it indented or right justified.
I've not modifed the controller yet to display 'Grand Total' in the last line but will do and will want that formatted too.
Many Thanks,
Mike.
I was expecting to find this information easily but I've not found anything.
In my controller I run a SOQL statement with 'group by rollup' and I then display the records in a visualforce table.
Each time that a subtotal is displayed, I want to either indent or right justify the word 'Subtotal' and do the same for the grand total. I can't find anything that explains how to apply this formatting in the controller.
Any help would be greatly appreciated.
Here's the controller:
public class SummariseQuotedWorks { private final Quote qte; public SummariseQuotedWorks(ApexPages.StandardController controller) { this.qte = (Quote)controller.getRecord(); } /* Use a wrapper class to store the aggregate values in a way that is accessible to Visualforce */ public class WISum{ public String Acct {get; set;} public String WorkItem {get; set;} public Decimal TotalCost {get; set;} public WISum(string a,string w,decimal c){ this.Acct=a; this.WorkItem=w; this.TotalCost=c; } } public List<WISum> WISumList = new List<WISum>(); public List<WISum> getWISumOut(){ String theAcct = ''; AggregateResult[] AgR = [SELECT Account__r.Name AC, WorkItem__r.Name WI, sum(cost1__c) TC FROM Quoted_Work__c where Quote__c=:qte.Id group by rollup(Account__r.Name, WorkItem__r.Name)]; for (AggregateResult WIRecs : AgR) { /* WISumList.add(new WISum((String) WIRecs.get('AC'), (String) WIRecs.get('WI'), (Decimal) WIRecs.get('TC'))); */ WISumList.add(new WISum((String) ((WIRecs.get('AC') == theAcct) ? '' : WIRecs.get('AC')), (String) (WIRecs.get('WI') == null ? 'Subtotal' : WIRecs.get('WI')), (Decimal) WIRecs.get('TC'))); theAcct = (String)WIRecs.get('AC'); } return WISumList; } }
Here's the VF:
<apex:page standardController="Quote" extensions="SummariseQuotedWorks"> <apex:pageBlock title="Summary of Works for Quote: {!Quote.Name}"> <apex:pageBlockSection > <apex:pageBlockTable value="{!WISumOut}" var="WISummary"> <apex:column value="{!WISummary.Acct}"> <apex:facet name="header">Site</apex:facet> </apex:column> <apex:column value="{!WISummary.WorkItem}"> <apex:facet name="header">Work Item</apex:facet> </apex:column> <apex:column value="{!WISummary.TotalCost}"> <apex:facet name="header">Total Cost</apex:facet> </apex:column> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:page>
Here's the ouput:
Wherever 'Subtotal' appears, I want it indented or right justified.
I've not modifed the controller yet to display 'Grand Total' in the last line but will do and will want that formatted too.
Many Thanks,
Mike.
Try this. If you want any additional formating to Subtotal text add it in Style attribute.
<apex:column >
<apex:facet name="header">Work Item</apex:facet>
<apex:outputText value="{!WISummary.WorkItem}" style="font-weight:bold;color:red;text-align: right;" rendered="{!WISummary.WorkItem == 'Subtotal'}" />
<apex:outputText value="{!WISummary.WorkItem}" rendered="{!cmp.Recordtype.Name <> 'Subtotal'}" />
</apex:column>
All Answers
Try this. If you want any additional formating to Subtotal text add it in Style attribute.
<apex:column >
<apex:facet name="header">Work Item</apex:facet>
<apex:outputText value="{!WISummary.WorkItem}" style="font-weight:bold;color:red;text-align: right;" rendered="{!WISummary.WorkItem == 'Subtotal'}" />
<apex:outputText value="{!WISummary.WorkItem}" rendered="{!cmp.Recordtype.Name <> 'Subtotal'}" />
</apex:column>
Unfortunately the right align isn't taking effect. I've Googled the issue, others have experienced it but I didn't find a solution.
I tried adding the style attribute to the column tag and that works, the whole column becomes right aligned I tried left aligning the column and right aligning the subtotal cell but it doesn't affect the individual cell.
Maybe it only works at the column level and not for individual cells.
The bold and red helps to set it apart so that will meet my needs but if it would right align too that would be perfect!
Mike.
Anyways, select the best answer from the comments, so it will be helpful to the others who are searching for the similar solutions.