footer sum not working with on change in the input column

footer sum not working with on change in the input column

noodle_linnoodle_lin Posts: 6Questions: 2Answers: 0

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

Sign In or Register to comment.