javascript - JQuery dynamic table totals -


i have table: http://i.imgur.com/v7hmnei.png

the table has data every month, shows selected date.

so, question is: how can total of actual hours , hours per month (visible data)?

this how build table:

var total = 0 ;     var actualtotal = 0 ;     var totaleh = 0;      var table=document.getelementbyid("fbody");     (var i=0;i<user.length;i++)     {          var row=table.insertrow(-1);         var celldate                =       row.insertcell(-1);         var cell2                   =       row.insertcell(-1);         var cell3                   =       row.insertcell(-1);         var cell4                   =       row.insertcell(-1);         var cell5                   =       row.insertcell(-1);         var cell7                   =       row.insertcell(-1);         var cell8                   =       row.insertcell(-1);          var startam                 =       user[i].reg_start_worktime_am;         var finisham                =       user[i].reg_finish_worktime_am;         var startpm                 =       user[i].reg_start_worktime_pm;         var finishpm                =       user[i].reg_finish_worktime_pm;           celldate.innerhtml          =       user[i].reg_date;         cell2.innerhtml             =       user[i].reg_start_worktime_am;         cell3.innerhtml             =       user[i].reg_finish_worktime_am;         cell4.innerhtml             =       user[i].reg_start_worktime_pm;         cell5.innerhtml             =       user[i].reg_finish_worktime_pm;         cell7.innerhtml             =       calctimedifference(startam.substring(0,2), startam.substring(3,5), finisham.substring(0,2), finisham.substring(3,5), startpm.substring(0,2), startpm.substring(3,5), finishpm.substring(0,2), finishpm.substring(3,5));         cell8.innerhtml             =       (calctimedifference(startam.substring(0,2), startam.substring(3,5), finisham.substring(0,2), finisham.substring(3,5), startpm.substring(0,2), startpm.substring(3,5), finishpm.substring(0,2), finishpm.substring(3,5))-user[i].worktime_fullhours).tofixed(2);          if (cell8.innerhtml != "nan")         {              totaleh                 +=      parsefloat((calctimedifference(startam.substring(0,2), startam.substring(3,5), finisham.substring(0,2), finisham.substring(3,5), startpm.substring(0,2), startpm.substring(3,5), finishpm.substring(0,2), finishpm.substring(3,5))-user[i].worktime_fullhours).tofixed(2));             total                   =       (document.getelementbyid('box-table-a').rows.length-1)*user[0].worktime_fullhours;             actualtotal             +=      parsefloat(calctimedifference(startam.substring(0,2), startam.substring(3,5), finisham.substring(0,2), finisham.substring(3,5), startpm.substring(0,2), startpm.substring(3,5), finishpm.substring(0,2), finishpm.substring(3,5)));         }     } 

thanks

edit:

fixed:

var totalactuals = 0,     totalextras = 0; var totalhours = 0; var trs = $("#fbody tr").each(function(e) { if($(this).css('display')!='none')     if( $("td:eq(6)", this).text() != 'nan' ) {         // alert("horro! "+$("td:eq(6)", this).text() );         totalactuals += parsefloat( $("td:eq(5)", this).text() );         totalextras += parsefloat($("td:eq(6)", this).text());         totalhours++;     } }); totalhours = totalhours*8; 

if understand correctly, table have rows visible, , hidden. and, want calculate totals rows visible.

you can looping through visible rows , accessing columns required calculating totals.

var totalactuals = 0; var totalextras = 0; $.each($('table tr:visible',function() {     totalactuals += $(this).find(".actualhours").val();     totalextras += $(this).find(".totalextras").val(); };) 

but return header row. think should assign class rows of table, , use class in jquery selector - $('table .tablerow:visible')

edit

here had assumed have given class "actualhours", "totalextras" div's in actual hours , total hours shown in each row of table. if haven't done so, can use -

totalactuals += $(this).find("td").eq(5).text(); totalactuals += $(this).find("td").eq(6).text(); 

this select 5th , 6th columns of row.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -