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
UvesUves 

Rollup Total Jquery

I have created a table using HTML. The table consists of a header and then many rows called Family. Each Family row can have many rows representing individual member of the family (see code below).

    <table width ="100%" class="gridtable">
         <tr>
             <th>Family Name</th>
             <th>Address</th>
             <th>Age Total</th>
        </tr>
         <apex:repeat value="{!Families}" var="Families">
              <apex:repeat value="{!Families}" var="Family">
                  <tr>
                    <td>{!Family.familyName__c}</td>
                    <td>{!Family.address__c</td>
                    <td>
                        <div id="{!Family.id}">
                              <apex:outputText id="RollUp" value="{0,number,#,###,###,###,###,##0.00}">
                                    <apex:param value="{!Family.AgeTotal}"/>
                              </apex:outputText>
                         </div>
                   </td>
               </tr>
                   <apex:repeat value="{!Family.member}" var="line">
                        <td>{!line.firstName__c}</td>
                        <td>{!line.gender__c}</td>
                        <td>
                            <apex:inputField value="{!line.Age}" onchange="rollupSummary('{!Family.id }');">> </apex:inputField>

My question, is it possible use jquery to update Family.AgeTotal field? Below is the JQuery I have started working on but I kind of got stuck? Any chance for any guidance?


    function rollupSummary(familyId)
    {
         //$j('#'+familyId)
         //$j('#'+'001b000000OQirKAAT').children('span').text('xxx');
         var v = $j('#'+familyId).children('span').val();
         var c = $j('#child'+familyId).children('span').val();
         $j('#'+familyId).children('span').text(v)
     }

    Typical Table:
User-added image

So if I change input value for Smith Family, only the total age for Smith should be updated.

Thanks in advance!
Best Answer chosen by Uves
UvesUves
After some playing around with the response you gave me I found a nice solution.

JavaScript Code
        function rollupSummary(val)
        {
            var rolled = 0.00;
            $j('.child_'+val).each(function() {
                rolled = rolled + parseFloat($j(this).val());
            });
            $j('.'+val).text(rolled.toFixed(2));
        }

HTML Code

<table width ="100%" class="gridtable">
     <tr>
         <th>Family Name</th>
         <th>Address</th>
         <th>Age Total</th>
    </tr>
     <apex:repeat value="{!Families}" var="Families">
          <apex:repeat value="{!Families}" var="Family">
              <tr>
                <td>{!Family.familyName__c}</td>
                <td>{!Family.address__c</td>
                <td>
                   <apex:outputText styleClass="{!Family.Id}" value="{!Family.AgeTotal}"/>
               </td>
           </tr>
               <apex:repeat value="{!Family.member}" var="line">
                    <td>{!line.firstName__c}</td>
                    <td>{!line.gender__c}</td>
                    <td>
                        <apex:inputField value="{!line.Age}" onchange="rollupSummary('{!Family.Id}');" styleClass="child_{!Family.Id}"/>

Hope that helps.