JSFiddle for this question: http://jsfiddle.net/nhg5ej4s/
I use the 1.10.15 version of Datatables.
I have this sum() function registered in API:
$.fn.dataTable.Api.register('sum()', function () {
var data = this.flatten().toArray();
return data.reduce(function (a, b) {
return (a * 1) + (b * 1); // cast strings
}, 0);
});
When I need to use this function, for example, in drawCallback option for update totals in footer (see JSFiddle for context):
var table = $('#example').DataTable({
drawCallback: function (settings) {
var api = this.api();
$(api.column(5).footer()).html('Total: ' + api.column(5).data().sum());
}
});
The function works, but when I apply filter on the table with any search, the values passed to sum() take all rows, not that filtered by search.
There is a way to identify the search context inside the sum() function?
PS: While writing this questions, I realize that I can pass a option in column call that will filter only searched rows: api().column(5, {'search': 'applied'}).data().sum() but I decide to keep the question to know if there is a way to do this inside the sum() code. JSFidlle with this update