我正在使用这个 jquery数据表插件来显示来自数据库的信息。我的表如下所示。现在我正在尝试总结分数(请查看下表)并将它们显示为总分,就像在本网站中给出的示例中一样
<script type="text/javascript" src="js/jquery.dataTables.min.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {$('#gtable').dataTable();} );
</script>
<table class="gtable" align="center" id="gtable">
<thead>
<tr>
<th>Sl</th>
<th>Name</th>
<th>Marks</th>
</tr>
</thead>
<tbody>
<tr><td>1</td> <td>Charlie Sheen</td> <td>20</td></tr>
<tr><td>2</td> <td>John Cryer</td> <td>20</td></tr>
<tr><td>3</td> <td>Jason Stathum</td> <td>20</td></tr>
</tbody>
</table
该插件的网站提供了以下代码来执行并显示总和,但我仍然不明白如何使用我上面的数据表。
你能帮我解决这个问题吗?
$(document).ready(function() {
$('#example').dataTable( {
"fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
/*
* Calculate the total market share for all browsers in
this table (ie inc. outside
* the pagination)
*/
var iTotalMarket = 0;
for ( var i=0 ; i<aaData.length ; i++ )
{
iTotalMarket += aaData[i][4]*1;
}
/* Calculate the market share for browsers on this page */
var iPageMarket = 0;
for ( var i=iStart ; i<iEnd ; i++ )
{
iPageMarket += aaData[ aiDisplay[i] ][4]*1;
}
/* Modify the footer row to match what we want */
var nCells = nRow.getElementsByTagName('th');
nCells[1].innerHTML = parseInt(iPageMarket * 100)/100 +
'% ('+ parseInt(iTotalMarket * 100)/100 +'% total)';
}
} );
} );