【发布时间】:2017-02-21 03:41:33
【问题描述】:
我尝试使用适用于单列总和的现有代码来使总和显示在两列中 - 我试图将它们放入一个数组中,但它不起作用。不能为此使用简单的数组解决方案吗?
这是https://jsfiddle.net/setbon/3mvmhL1v/
这是JS:
$(document).ready(function() {
var table = $('#example').DataTable( {
rowReorder: {
selector: 'td:nth-child(2)'
},
responsive: true,
scrollX: true,
scrollY: "80vh",
scrollCollapse: true,
paging: true,
lengthChange: false,
lengthMenu: [ [10, 25, -1], [10, 25, "All"] ],
"order": [[ 0, "asc" ]],
"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( [3,4] )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
// Total over this page
pageTotal = api
.column( [3,4], { page: 'current'} )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
// Update footer
$( api.column( [3,4] ).footer() ).html(
total
);
},
buttons: ['pdf']
} );
table.buttons().container()
.appendTo( '#example_wrapper .small-6.columns:eq(0)' );
}); $(文档).foundation();
因为我希望汇总多个列,我现在需要为每个 https://datatables.net/plug-ins/api/sum() 使用一个额外的插件吗?即使对于那个插件,我也无法找到一个示例,其中包含多个汇总的列,我可以复制并轻松自定义。
In this SO question 代码与我所拥有的非常不同,让我感到困惑。还有this SO answer is difficult for me to understand and I don't know how to apply to resolve my problem
【问题讨论】:
标签: datatables datatables-1.10