dlw760
7/15/2013 - 7:17 PM

A function for the jQuery plugin Datatables. It will total a column and add it to the footer.

A function for the jQuery plugin Datatables. It will total a column and add it to the footer.

                    var oTable = $('#viewSessions .datatable').dataTable( {
                        "fnFooterCallback": function(  nRow, aaData, iStart, iEnd, aiDisplay  ) {   
                            
                            var totalTurnover = 0,
                                totalBonus = 0;
                            for ( var i=iStart ; i<iEnd ; i++ )
                            {
                                console.log(aaData[ aiDisplay[i] ][2]);

                                var value = aaData[ aiDisplay[i] ][2].replace(/[^0-9\.]/g, '');                                    
                                totalTurnover += parseInt(value);  

                                var value = aaData[ aiDisplay[i] ][3].replace(/[^0-9\.]/g, '');                                    
                                totalBonus += parseInt(value);                                
                            }                                               
                            
                            $('tfoot td:eq(2)').text(accounting.formatMoney(totalTurnover, '£', ","));
                            $('tfoot td:eq(3)').text(accounting.formatMoney(totalBonus, '£', ","));                            
                        

                        }

                    } );