2014-03-26 39 views
0

我用的tablesorter jQuery的開發之後,我的問題是:的tablesorter jQuery的獲取數字列的總和被過濾

是有辦法顯示過濾後的數值列的總和?

例如:

+++++++++++
名字 - 錢
+++++++++++
alan- 10
alan- 10
alan- 10
alan- 10
john- 10
john- 10
john- 10

筆錢:70

如果我篩選的名稱,只是表示 '艾倫' 我想會得到:

+++++++++++
名字 - 錢
+++++++++++
alan- 10
alan- 10
alan- 10
alan- 10

總和的米oney:這裏40

感謝您的幫助:)

+0

肯定..你有沒有一個例子可以解決? –

+0

我沒理解你的評論!你是說我的真實例子? –

+0

你真實的例子或一個簡單的例子,像你的功能 –

回答

3

試試這個...是this demo的HTML:

<table class="tablesorter"> 
    <thead> 
     <tr> 
      <th>Name</th> 
      <th>Money</th> 
     </tr> 
    </thead> 
    <tbody> 
     ... 
    </tbody> 

</table>Sum of Money: <span class="total"></span> 

和必要的腳本:

$('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'] 
    }); 
+0

非常感謝!有用 ;) –

相關問題