douliandan7340 2019-04-14 17:55
浏览 56

表列和JQuery Live Search的总和

I've integrated the total sum for the table columns and it works great. The same page has a JQuery live search. When I do a search, the results appear just fine but the total sum is showing the total for all data not the filtered data by JQuery Search.

Now, we want the total sum to change upon doing a search to show only the filtered results. So on doing a search, table data will be filtered and accordingly, the total sum amounts will be recalculated based on the filtered results.

I've tried to disable the live search capability so the page will reload each time I do a search. And accordingly, the total sums will be recalculated. But I couldn't get it to work like this.

<script>
$(document).ready(function()
{
$('table thead th').each(function(i)
{
calculateColumn(i);
});
});
function calculateColumn(index)
{
var total = 0;
$('table tr').each(function()
{
var value = parseInt($('td', this).eq(index).text());
if (!isNaN(value))
{
total += value;
}
}); 
$('table tfoot td').eq(index).text('' + total);
}
</script>

<tfoot>
    <tr class="sum" height="50px">
        <td></td>
        <td></td>
        <td></td>
    </tr>
</tfoot>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 网络设备配置与管理这个该怎么弄
    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器