我在“ 2000 cr”这样的一列中同时具有字符串和数值,并且我只想使用datatable Total来总计数值

时间:2019-09-18 10:27:41

标签: javascript datatable

我在哪里犯错?

"footerCallback": function ( row, data, start, end, display ) 
        {
            var api = this.api(), data;

            // 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;
            };

            // Total over all pages
            total = api
                .column(3)
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );

            // Total over this page
            pageTotal = api
                .column( 3, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );

            // Update footer
            $( api.column(3).footer() ).html('Total : <i class="fa fa-inr" aria-hidden="true"></i> ' + pageTotal  +' <br>Grand total  =  &nbsp;<i class="fa fa-inr" aria-hidden="true"></i>'+ total);
        }

0 个答案:

没有答案