+ Start a Discussion
GMASJGMASJ 

How to add grand total in column footer in visualforce

Hi,

   I have a requirement to show the grand total of quantity, quantity is a input field user can change the value as the user change it should automatically dispaly the grand total in the column fotter please suggest me how to implement this feature. 


  <apex:page standardController="Opportunity" extensions="OptyLineEditCnt" id="pg" sidebar="false">
     <apex:form id="frm">
      <apex:pageBlock title="Edit Opportunity Lines" id="pb2">
        <apex:pageBlockTable   Width="100%" id="pbt2">
           <apex:inputfield id="Quantity" value="{!Quantity}" > </apex:inputfield>
      </apex:pageBlockTable>
     </apex:pageBlock>
     </apex:form>       
  </apex:page>

Thanks
Sudhir
Best Answer chosen by GMASJ
Ankur Saini 9Ankur Saini 9
Hi Sudhir Narayanaswamy,

try this:
 
public with sharing class OptyLineEditCnt {
public list<Opportunity> opp{get;set;}
public decimal totalquant{get;set;} 
    public OptyLineEditCnt(ApexPages.StandardController controller) {
       opp=[select id, name, TotalOpportunityQuantity from Opportunity];
    }

  public pagereference total(){
    decimal total=0;
    for(integer i=0;i<opp.size();i++){
        total=total+opp[i].TotalOpportunityQuantity;
    }
        totalquant=total;
        return null;
    }
}



<apex:page standardController="Opportunity" extensions="OptyLineEditCnt" sidebar="false">
   <apex:form >
     <apex:pageBlock title="Edit Opportunity Lines">
      <apex:pageBlockTable value="{!opp}" var="oppo">
        <apex:column headerValue="Name">
           <apex:outputfield value="{!oppo.name}"/>
        </apex:column>
        <apex:column headerValue="Quantity">
           <apex:inputText value="{!oppo.TotalOpportunityQuantity}"> 
           <apex:actionSupport event="onchange" action="{!total}" reRender="value"/>         
           </apex:inputText>         
        </apex:column>      
      </apex:pageBlockTable>
        <apex:outputText value="{!totalquant}" label="Total" id="value"/>
     </apex:pageBlock>
   </apex:form>       
 </apex:page>

Thanks 
Ankur Saini
http://mirketa.com

All Answers

Ankur Saini 9Ankur Saini 9
Hi Sudhir Narayanaswamy,

try this:
 
public with sharing class OptyLineEditCnt {
public list<Opportunity> opp{get;set;}
public decimal totalquant{get;set;} 
    public OptyLineEditCnt(ApexPages.StandardController controller) {
       opp=[select id, name, TotalOpportunityQuantity from Opportunity];
    }

  public pagereference total(){
    decimal total=0;
    for(integer i=0;i<opp.size();i++){
        total=total+opp[i].TotalOpportunityQuantity;
    }
        totalquant=total;
        return null;
    }
}



<apex:page standardController="Opportunity" extensions="OptyLineEditCnt" sidebar="false">
   <apex:form >
     <apex:pageBlock title="Edit Opportunity Lines">
      <apex:pageBlockTable value="{!opp}" var="oppo">
        <apex:column headerValue="Name">
           <apex:outputfield value="{!oppo.name}"/>
        </apex:column>
        <apex:column headerValue="Quantity">
           <apex:inputText value="{!oppo.TotalOpportunityQuantity}"> 
           <apex:actionSupport event="onchange" action="{!total}" reRender="value"/>         
           </apex:inputText>         
        </apex:column>      
      </apex:pageBlockTable>
        <apex:outputText value="{!totalquant}" label="Total" id="value"/>
     </apex:pageBlock>
   </apex:form>       
 </apex:page>

Thanks 
Ankur Saini
http://mirketa.com
This was selected as the best answer
GMASJGMASJ
Thanks Ankur it worked your genious