callback to sum data-sort

callback to sum data-sort

sphawksphawk Posts: 4Questions: 2Answers: 0
edited September 2019 in Free community support

I'm trying to sum column data-sort values.
With this code

      "footerCallback": function(row, data, start, end, display) {
        var api = this.api();
        api.columns('.sum', {
          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);
          $(this.footer()).html(sum);
        });
      }  

I can sum the values of the cells but in my case, the values are: 1 hour, 18 seconds, etc.
obviously the sum "19" is wrong.
I'm using data-sort="<seconds>" for each cell but I don't know how to get this value into callback.

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @sphawk ,

    You can grab the nodes and do the sum based on those - something like this here.

    Cheers,

    Colin

  • sphawksphawk Posts: 4Questions: 2Answers: 0

    like a charm!
    tnx a lot colin!

This discussion has been closed.