2つのカラムに表示される合計を得るために1つのカラムの和に対して働く既存のコードを使用しようとしました。それらは配列ではあるが動作していない。これには単純な配列ソリューションを使用することはできませんか?Datatables "footerCallback"関数はフッタに2つのカラムの結果を表示しません(1つだけ)
これは、これはJSあるhttps://jsfiddle.net/setbon/3mvmhL1v/
ある。)
$(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)');
}。 $(document).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
エリック、私が作った更新版をFiddleが何らかの理由で残念に思っていたのは残念です。新たに保存された参照:https://jsfiddle.net/setbon/3mvmhL1v/ 3行しか表示されず、合計は2つの別々の合計である必要があります.2つの列で同じではありません。私は関数が複数を呼び出させるようにしましたが、今どこにでもゼロをつけています。もう一度見ていただけますか? –
私の編集した答えをチェックしてください。 –
すべて今良いありがとう!なぜあなたは最初の部分を上に移動しましたか? "$(document).ready(function(){"? "$ –