Skip to content

Instantly share code, notes, and snippets.

@ricardobeat
Forked from anonymous/gist:132884
Created June 20, 2009 21:40
Show Gist options
  • Save ricardobeat/133298 to your computer and use it in GitHub Desktop.
Save ricardobeat/133298 to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<!--Site-->
<div id="site">
<!--container-->
<div id="container">
<table width="300" border="1" cellspacing="1" cellpadding="3" summary="sum">
<caption>
tabela
</caption>
<thead>
<tr>
<th scope="col">&nbsp;</th>
<th scope="col">jan</th>
<th scope="col">fev</th>
<th scope="col">mar</th>
<th scope="col">abr</th>
<th scope="col">mai</th>
<th scope="col">jun</th>
<th scope="col">jul</th>
<th scope="col">ago</th>
<th scope="col">set</th>
<th scope="col">total</th>
</tr>
</thead>
<tbody>
<?php for ($i=1;$i<=4;$i++):?>
<tr>
<td class="first">linha <?=$i?></td>
<?php for ($j=1;$j<=9;$j++):?>
<td><?=($j*$i)?></td>
<?php endfor; ?>
<td class="somaLinha"></td>
</tr>
<?php endfor; ?>
</tbody>
<tfoot>
<th scope="row">total</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th class="somaLinhas"></th>
</tr>
</tfoot>
</table>
</div>
<!--container-->
</div>
<!--Site-->
</body>
<script language="JavaScript" type="text/javascript" src="jquery/jquery-1.3.2.min.js"></script>
<script>
$(function(){
var $table = $('table')
,$rows = £('tbody', $table)[0].rows
,$footer = $('tfoot th:last', $table)
,row
,i=0
,totalGeral=0;
while (row = rows[i++]) {
var totalLinha = 0;
$.each(row.cells,function(k,td){
$td = $(td);
var val = parseFloat( $td.text() );
if (!isNaN(val)) {
totalLinha += val;
} else if ( $td.is('.somaLinha') ) {
$td.text(totalLinha);
totalGeral += totalLinha;
}
});
}
$footer.text(totalGeral);
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment