From 94b058d1ba0595a66e11643d51e09c08fbd4cd24 Mon Sep 17 00:00:00 2001 From: Syed Nizamudeen Date: Wed, 4 Jan 2017 11:53:18 +0800 Subject: [PATCH] added sumselected function this function will help to sum values only from selected rows --- api/sum().js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/api/sum().js b/api/sum().js index 856ebd6..21943a2 100644 --- a/api/sum().js +++ b/api/sum().js @@ -49,3 +49,16 @@ jQuery.fn.dataTable.Api.register( 'sum()', function ( ) { }, 0 ); } ); +jQuery.fn.dataTable.Api.register( 'sumselected()', function ( ) { + // Remove the formatting to get integer data for summation + var intVal = function ( i ) { + return typeof i === 'string' ? + i.replace(/[\$,]/g, '')*1 : + typeof i === 'number' ? + i : 0; + },cellvalue=0; + this.rows( { selected: true } ).every( function ( r ) { + cellvalue=cellvalue+intVal(this.cell(r,11).data()); + } ); + return cellvalue; +} );