You need to sign in to do that
Don't have an account?
Hugo Stoupe
Grand total for a column in VisualForce
I have been trying various "examples" to create a sub-total for columns in a visualforce page and have had no luck. The closest I have gotten is the one below, however, the <script> doesn't seem to be working as I don't get any value in the <span></span> block when I render the page.
Could anyone take a look to see if my code is missing anything ? See the <apex:facet> at the bottom which references the place that should be populated with the total. I have a variable that should be holding the total, but not sure how to check this.
Could anyone take a look to see if my code is missing anything ? See the <apex:facet> at the bottom which references the place that should be populated with the total. I have a variable that should be holding the total, but not sure how to check this.
<apex:page controller="fetchTimeCardEntryDataController" tabStyle="Account" docType="HTML-5.0"> <apex:form > <!-- Variables to hold Totals --> <apex:variable value="{!0.00}" var="tMon"/> <apex:variable value="{!0.00}" var="Total_Tuesday"/> <apex:variable value="{!0.00}" var="Total_Wednesday"/> <apex:variable value="{!0.00}" var="Total_Thursday"/> <apex:variable value="{!0.00}" var="Total_Friday"/> <apex:variable value="{!0.00}" var="Total_Saturday"/> <apex:variable value="{!0.00}" var="Total_Sunday"/> <apex:variable value="{!0.00}" var="Total_Grand"/> <apex:pageBlock Title="Time Card Entry Report"> <!--Start and End block along with fetch button --> <apex:pageBlockButtons > <b>Starting Date</b><apex:inputfield value="{!dum.dateOne__c}"/> <b>Ending Date</b><apex:inputfield value="{!dum.dateTwo__c}"/> <apex:commandButton value="Fetch Time Entries" action="{!fetch}"/> </apex:pageBlockButtons> <!-- Debug - SQL statement --> <!-- <apex:pageBlockSection columns="1" title="DEBUG - Dynamic SOQL Query" collapsible="True"> <apex:outputText value="{!query}"> </apex:outputText> </apex:pageBlockSection> --> <!-- Display Time Entry Date --> <apex:pageblocktable value="{!TEList}" var="tec1" id="list1"> <apex:column width="10" title="Week Starting" value="{!tec1.Monday_Date__c}"/> <apex:column headerValue="Mon"> <apex:outputfield value="{!tec1.Monday__c}"/> <apex:variable var="tMon" value="{!tMon+1+tec1.Monday__c}"/> <apex:facet name="footer"> t<span ID="tMonday"></span> </apex:facet> </apex:column> </apex:pageblocktable> </apex:pageBlock> <!-- Script for generating Totals--> <script> document.getElementsByID('tMonday')[0].innerHTML='{!tMon}'; </script> </apex:form> </apex:page>
use <input type="hidden" value="{tec1.monday__c}" id="mon"> in apex:column
then use this script
function total(){
var sum=0;
var values =document.getElementsByTagName("input");
for(var i=0; i<values.length; i++){
if(values[i].id.indexOf('mon'))
sum=sum+parseInt(values[i]);
}
document.getElementById('id which you have given for last column') =sum;
}
<script>
function total(){
var sum=0;
var values =document.getElementsByTagName("input");
for(var i=0; i<values.length; i++)
{
if(values[i].id.indexOf('mon')) {
sum=sum+parseInt(values[i].value);
}
document.getElementById('itMonday') =sum;
}
}
total();
</script>
try this one hugo...
Does anyone have a working sample (visualforce page) that does show the totals so I could use it to troubleshoot my code?
Hugo