footer sum not working with on change in the input column
footer sum not working with on change in the input column
![noodle_lin](https://secure.gravatar.com/avatar/042b72a5d10eff6e89fb53ac31d21f6d/?default=https%3A%2F%2Fvanillicon.com%2F042b72a5d10eff6e89fb53ac31d21f6d_200.png&rating=g&size=120)
in DataTables
Link to test case:
http://live.datatables.net/cepasoda/1/edit
Debugger code (debug.datatables.net):
$(document).ready( function () {
var table = $('#example').DataTable({
"columnDefs": [
{
targets: -1,
render: function (data, type, row, meta) {
if (type === 'display') {
return '<input type="input" name="' + row[1] + '">';
}
return data;
},
}
],
destroy: true,
});
$("#example tbody").on('change', 'input', function () {
var intVal = function (i) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '') * 1 :
typeof i === 'number' ?
i : 0;
};
var total = 0;
table.cells(null, -1, {
page: 'all'
}).nodes()
.each(function (n) {
total += intVal($(n).val());
});
$(table.column(-1).footer()).data(total).draw();
});
} );
Error messages shown:
Description of problem:
This question has an accepted answers - jump to answer
Answers
@colin
You had a few mistakes in the test case, such as
1. console error saying
data().draw()
doesn't exist2. you were summing the
td
, not theinput
element within itPlease see updated test case here: http://live.datatables.net/cepasoda/2/edit
Colin
oh!fabulous!thx so much.