$(document).ready(function() {
   $('.main-spinner').show();
        $('#datatable_accounting_libility_report').DataTable({
           "serverSide": true,
           "lengthMenu": [[20, 30, 50, 100, 200,500,1000], [20, 30, 50, 100, 200,500,1000]],
           ajax: "/realty/datatable-libility-report",
               columns: [
                   {"data": "DT_RowIndex",'searchable':false},
                   {"data": "liability_date",'name':'nso007_liability.liability_date'},
                   {"data": "liability_item",'name':'nso007_account_chart.acc_name'},
                   {"data": "liability_invoice",'name':'nso007_liability.liability_invoice'},
                   {"data": "liability_from",'name':'nso007_liability.liability_from'},
                   {"data": "liability_des",'name':'nso007_liability.liability_des'},
                   {"data": "liability_amount",'name':'nso007_liability.liability_amount'},
                 
               ],

              "initComplete": function(settings, json) {
                  $('.main-spinner').hide();
              },
              "footerCallback": function ( row, data, start, end, display ) {
                  var api = this.api(), data;
       
                  // converting to interger to find total
                  var intVal = function ( i ) {
                      return typeof i === 'string' ?
                          i.replace(/[\$,]/g, '')*1 :
                          typeof i === 'number' ?
                              i : 0;
                  };
       
                  var total = api
                      .column( 6 )
                      .data()
                      .reduce( function (a, b) {
                          return intVal(a) + intVal(b);
                      }, 0 );

                  var numFormat = $.fn.dataTable.render.number( '\,', '.', 2, '$ ' ).display;
                  $( api.column( 6 ).footer() ).html(numFormat(total));
                },          
    });

   $.fn.dataTable.ext.errMode = 'throw';
});