Добавление итога в строку нижнего колонтитула таблицы данных - PullRequest
0 голосов
/ 26 августа 2018

Я хочу добавить сумму (сумму) столбца в строку нижнего колонтитула.Я попробовал следующий код и не получил никакого результата.

$(document).ready(function() {
    // SUM PLUGIN
    jQuery.fn.dataTable.Api.register( 'sum()', function ( ) {
        return this.flatten().reduce( function ( a, b ) {
            if ( typeof a === 'string' ) {
                a = a.replace(/[^\d.-]/g, '') * 1;
            }
            if ( typeof b === 'string' ) {
                b = b.replace(/[^\d.-]/g, '') * 1;
            }

            return a + b;
        }, 0 );
    } );

    $('#userTable1').DataTable({
        "footerCallback": function () {
            var api = this.api(),
                columns = [7,8,9,10,11,12]; // Add columns here

            for (var i = 0; i < columns.length; i++) {
                $('tfoot th').eq(columns[i]).html('Total: ' + api.column(columns[i], {filter: 'applied'}).data().sum() + '<br>');
                $('tfoot th').eq(columns[i]).append('Page: ' + api.column(columns[i], { filter: 'applied', page: 'current' }).data().sum());
            }
        }
    });
});

</script>
<tfoot align="right">
    <tr class="totalColumn">
        <td colspan='6'>Total:</td>
        <td class="totalCol"><?php ?></td>
        <td class="totalCol"></td>
        <td class="totalCol"></td>
        <td class="totalCol"></td>
        <td class="totalCol"></td>
        <td class="totalCol"></td>
    </tr>
</tfoot>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...