0

I want to display Grand Total Amount and Total Amount(Particular Column total) but its not working.

Please help me to achieve this. 1)Here Grand total is total of Amount__c in Expensive__c object and 2)Total Amount is Particular Column total displayed in pageblocktable, in below image you can see its only showing Total amount is 56.

enter image description here

VF Page:

<apex:page controller="ExpensesClass" >

<apex:form >
<!-- Need this variables for totals generation -->
<apex:variable value="{!0}" var="total1"/>

<apex:pageBlock >

<apex:pageBlockTable value="{!expensesList}" var="e" rendered="{!isTableExit}" >

<apex:column value="{!e.Date__c}"/>
<!--<apex:column value="{!e.Item__c}"/>-->
<apex:column >
<apex:outputLink target="_blank" value="/{!e.id}">{!e.Item__c}</apex:outputLink>
</apex:column>

<apex:column headerValue="Amount">
<apex:outputField value="{!e.Amount__c}" />
<apex:variable var="total1" value="{!e.Amount__c}" />
<apex:facet name="footer">
               Total: <span class="t1"></span>   
</apex:facet>
</apex:column>

</apex:pageBlockTable>
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel value="Grand Total Amount:"/>
<apex:outputText value="{!totalsum1}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
<script>
// Here we will set the generated subtotals to the footer cells

document.getElementsByClassName('t1')[0].innerHTML = '{!total1}'; 
</script>
</apex:form>
</apex:page>

Class:

public class ExpensesClass {
public string nameQuery{get;set;}
public List<Expense__c> expensesList{get;set;}
public Boolean isTableExit {get;set;}
public Date fromdate {get; set;}
public Date todate {get; set;}
public list<AggregateResult> totalsum {get;set;}
public integer totalsum1{get;set;}

//public List<Expense__c> expensesList {get; set;}
public ExpensesClass(){
totalsize=[Select count() From Expense__c];
totalsum=new list<AggregateResult>();
//totalsum=[Select sum(Amount__c) From Expense__c];
}

public PageReference executeSearch(){
string str='%'+nameQuery+'%';
if(nameQuery==null || nameQuery==''){
    //errormessage ='Name cannot be null or empty. Please Try Again.';
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Enter Owner Name'));
}else{
expensesList=[Select id, Item__c, owner.name,Amount__c, Date__c From Expense__c where owner.name LIKE:str Limit:limitsize Offset:offsetsize];
}

return null;
}

public Void gettotalsum1(){
AggregateResult[] groupedresult=[Select sum(Amount__c) From Expense__c];
object totalsum1=groupedresult[0].get('total');
//return totalsum;
}
}

Thanks in advance Shaik

4

Completely in the context in what you posted / are asking, you are not adding the values which is why it only shows the last value....

You need to:

<apex:variable var="total1" value="{!e.Amount__c + total1}" />
|improve this answer|||||
  • Hi, Thanks for your response, now column total working fine. how to display grand total. – Shaik Aug 25 '15 at 16:24
  • 2
    @Shaik - Please mark as accepted answer then so others looking for similar questions can find ones with an answer – Eric Aug 25 '15 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.