1
鑑於此footer_callback數據表示例 這裏是我的FIDDLE。使用footer_callback求和數據表頁腳中的1+列?
這基本上總計每欄的總數爲1列。 任何人都可以建議我怎麼能做到這一點超過1列?
我想我可能需要增加更多的th
標籤我要總結的列:
<tfoot>
<tr>
<th colspan="4" style="text-align:right">Total:</th>
<th></th>
</tr>
</tfoot>
以及每個列添加另一個回調函數,但到目前爲止,我還沒有喜悅。 任何人都可以建議嗎?
"footerCallback": function (row, data, start, end, display) {
var api = this.api(), data;
// Remove the formatting to get integer data for summation
var intVal = function (i) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '')*1 :
typeof i === 'number' ?
i : 0;
};
// Total over all pages
total = api
.column(4)
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
// Total over this page
pageTotal = api
.column(4, { page: 'current'})
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
// Update footer
$(api.column(4).footer()).html(
'$'+pageTotal +' ($'+ total +' total)'
);
}
注:我可能需要與我可以總結上號碼錶/數據集的另一列。
更改了表格,因此有2列可以求和FIDDLE。 在這個小提琴中,它正在第5欄中工作,但是如何讓它在第3欄中工作?
重複'//總共覆蓋所有頁面,'//總共覆蓋此頁面',//更新頁腳3的步驟也是索引3。 –
@SanthoshNayak我已經嘗試過,但可以提供一個例子,tks? – HattrickNZ