0

inside jquery datatable I'm using sum plugin in order to sum values from particular column

 $('#example').DataTable( {
    drawCallback: function () {
      var api = this.api();
      $( api.table().footer() ).html(
        api.column( 4, {page:'current'} ).data().sum()
      );
    }
  } );

How can use this api call to calculate another column (for example column 6).

$( api.table().footer() ).html(
    api.column( 4, {page:'current'} ).data().sum()
    // calculate column 7 
);

also calculate result is injected inside first column of the footer instead of 4.

1 Answer 1

1

You were nearly there but your reference to api.table().footer() got the whole footer. To target specific column footers you need to use api.column(?).footer(). That way your issue should be addressed like this:

$(api.column(4).footer()).html(
  api.column(4, {
    page: 'current'
  }).data().sum()
);
$(api.column(6).footer()).html(
  api.column(6, {
    page: 'current'
  }).data().sum()
);

Here's a working example, hope that helps.

Sign up to request clarification or add additional context in comments.

1 Comment

There was mention of totaling durations. I've updated the JSFiddle with a solution which uses momentJSs duration (momentjs.com/docs/#/durations) object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.