Ala*_*nez 2 jquery tablesorter
我正在使用tablesorter jquery进行开发,我的问题是:
有没有办法在过滤后显示数字列的总和?
例如:
+++++++++++
名称
-money
+++++++++++
alan- 10
alan- 10
alan- 10
alan- 10
john- 10
john- 10
john- 10
总金额:70
如果我过滤名称,只显示“ alan”,我想得到这个:
+++++++++++
名称-金钱
+++++++++++
alan-10
alan-10
alan-10
alan-10
总金额:40
谢谢你的帮助 :)
尝试一下...这是此演示中的HTML :
<table class="tablesorter">
<thead>
<tr>
<th>Name</th>
<th>Money</th>
</tr>
</thead>
<tbody>
...
</tbody>
</table>Sum of Money: <span class="total"></span>
Run Code Online (Sandbox Code Playgroud)
和必要的脚本:
$('table')
.on('initialized filterEnd', function(){
var total = 0;
$(this).find('tbody tr:visible').each(function(){
// find money in 2nd column
total += parseFloat( $(this).find('td:eq(1)').text() );
});
$('.total').text(total);
})
.tablesorter({
theme: 'blue',
widgets: ['filter']
});
Run Code Online (Sandbox Code Playgroud)