使用datatable汇总列值

我想将列值加到代码末尾的总数中。 我正在使用Jquery datatable数据表通过此代码过滤记录但无法编写总数的代码。我也tried footer callback of datatable但没有获得所需的结果。

        $(document).ready(function(){ $.datepicker.regional[""].dateFormat = 'dd/mm/yy'; $.datepicker.setDefaults($.datepicker.regional['']); $('#example').dataTable({ "aoColumns": [{}, ] } ) .columnFilter({ sPlaceHolder: "head:before", aoColumns: [ { type: "hidden" }, { type: "hidden" }, { type: "hidden" }, { type: "hidden" }, { type: "hidden" }, { type: "hidden" }, { type: "hidden" }, { type: "hidden" }, { type: "hidden" }, { type: "date-range", sRangeFormat: "From Date{from} To Date {to}" }, { type: "hidden" }, { type: "hidden" }, { type: "hidden" } ], "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) { /* * Calculate the total market share for all browsers in this table (ie inc. outside * the pagination) */ var iTotalMarket = 0; for ( var i=0 ; i<aaData.length ; i++ ) { iTotalMarket += aaData[i][11]*1; } /* Calculate the market share for browsers on this page */ var iPageMarket = 0; for ( var i=iStart ; i<iEnd ; i++ ) { iPageMarket += aaData[ aiDisplay[i] ][11]*1; } /* Modify the footer row to match what we want */ var nCells = nRow.getElementsByTagName('th'); nCells[1].innerHTML = parseInt(iPageMarket * 100)/100 + '% ('+ parseInt(iTotalMarket * 100)/100 +'% total)'; } }); });    
Agent Code Agent Name Designation Account No. Customer Name Plan No. Invoice Bill Amt. Bill Date Pay Date Insta. No. Earning Remark
                         
Total:

以下是解决方案: – 使用页脚回调函数执行此操作。 每次抽奖都会运行此回调。 因此,无论何时更改表的内容,此函数都会运行并更改页面总薪水。

 
Name Salary
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 500
abc 100
abc 200
abc 200
abc 200
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
lod 100
abc 100
abc 100
aeda 100
xyz 100
abc 100
abc 100
abc 100
xyz 100
xyz 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
abc 100
dsada

工作演示: http : //jsfiddle.net/ishandemon/tb058mLq/2/

看起来您在columnFilter init选项中定义了页脚回调,而不是在dataTable init选项中定义 – 我不希望它在那里工作。