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
Compass 1Compass 1 

How to Add grand total row in Visualforce Page

I have created a VF page to show the Opportunity data in PDF Output.
How I can add the Grand Total field on my VF Page. For reference please find below the code I have given to show the columns.

I wanted to show the total of Revenue Column.

<apex:datatable value="{!opportunityList}" var="opp" width="100%" styleClass="tableClass" border="1">

<apex:column value="{!opp.account.name}"  headerClass="headerstyle" headerValue="Client"/>
<apex:column value="{!opp.name}" headerClass="headerstyle" headerValue="Project Title"/>
<apex:column style="width:75px" value="{!opp.Facility__c}"  headerClass="headerstyle" headerValue="Facility"/>
<apex:column value="{!opp.Scope_Of_Work__c}"  headerClass="headerstyle" headerValue="Scope Of Work"/>
<apex:column value="{!opp.Pricing_Type__c}" headerClass="headerstyle" headerValue="Pricing Type"/>
<apex:column style="width:90px" value="{!opp.BiddingStatus__c}"  headerClass="headerstyle" headerValue="Bidding Status"/>
<apex:column style="width:90px;text-align:center" value="{!opp.Estimated_Revenue_MM__c}" headerClass="headerstyle" headerValue="Revenue"/>
    
</apex:datatable>

Pankaj_GanwaniPankaj_Ganwani
Hi,

Can you please try below mentioned code?

<apex:datatable value="{!opportunityList}" var="opp" width="100%" styleClass="tableClass" border="1">

<apex:column value="{!opp.account.name}"  headerClass="headerstyle" headerValue="Client"/>
<apex:column value="{!opp.name}" headerClass="headerstyle" headerValue="Project Title"/>
<apex:column style="width:75px" value="{!opp.Facility__c}"  headerClass="headerstyle" headerValue="Facility"/>
<apex:column value="{!opp.Scope_Of_Work__c}"  headerClass="headerstyle" headerValue="Scope Of Work"/>
<apex:column value="{!opp.Pricing_Type__c}" headerClass="headerstyle" headerValue="Pricing Type"/>
<apex:column style="width:90px" value="{!opp.BiddingStatus__c}"  headerClass="headerstyle" headerValue="Bidding Status"/>
<apex:column style="width:90px;text-align:center" headerClass="headerstyle">
    {!opp.Estimated_Revenue_MM__c}
    <apex:facet name="header">Revenue</apex:facet>
    <apex:facet name = "footer">{!total}</apex:facet>
</apex:datatable>

You should replace the {!total} with your controller variables which depicts the grand total.
JayantJayant
Instead of using <apex:DataTable>, use HTML markup to generate table (<table>, <th>, <td>, <tr> etc.).
After <table>, iterate over the list with <apex:repeat> and have one <tr> for each list item.
With in <tr>, use another <apex:repeat> to iterate over a list of fields and display the field value using a <td>.