datatable sum in a

datatable sum in a

kezaikezai Posts: 1Questions: 0Answers: 0

Hi,

I am looking for a way to make sum of a column in datatable.net with the value in a span balise and not directly in a td balise. can you help me to modify the code below please ?

my html table is like this :

124

i would like to get the 124.

"footerCallback": function(row, data, start, end, display) {
var api = this.api();

                  api.columns('.no-sort', {
                    page: 'current'
                  }).every(function() {
                    var sum = this
                      .data()
                      .reduce(function(a, b) {
                        var x = parseFloat(a) || 0;
                        var y = parseFloat(b) || 0;
                        return x + y;
                      }, 0);
                    console.log(sum); //alert(sum);
                    $(this.footer()).html(sum);
                  });
                }

thanks in advance.
best regards.

Replies

  • kthorngrenkthorngren Posts: 21,171Questions: 26Answers: 4,922

    $(this.footer()).html(sum);

    Change this line to place the sum where you would like. In your code this.footer()) is the selector. Just change it to the span elements id.

    Kevin

This discussion has been closed.