Access a column's renderer from the footer

Access a column's renderer from the footer

ddrinkaddrinka Posts: 1Questions: 1Answers: 0

Each of my numeric columns defines a renderer:

            "columns": [
                { "data": "PKey" },
                { "data": "Str1", "defaultContent": "" },
                { "data": "Num1", "render": asMoney(), "defaultContent": "" },
                { "data": "Num2", "render": asInt(), "defaultContent": "" },
                { "data": "Num3", "render": asInt(), "defaultContent": "" },
            ]

function asMoney() {
    return $.fn.dataTable.render.number(',', '.', 2, '$');
}

function asInt() {
    return $.fn.dataTable.render.number(',', '.', 0);
}

I total each column in the footer:

            "footerCallback": footerTotals()

function footerTotals() {
    return function (row, data, start, end, display) {
        var api = this.api();

        // Remove the formatting to get numeric data for summation
        var numVal = function (v) {
            return typeof v === 'string' ?
                v.replace(/[\$,]/g, '') * 1 :
                typeof v === 'number' ?
                    v : 0;
        };

        // Total over all pages
        api
            .columns()
            .every(function () {
                var total = this
                    .data()
                    .reduce(function (a, b) {
                        return numVal(a) + numVal(b);
                    }, 0);
                $(this.footer()).html(
                    $.fn.dataTable.render.number(',', '.', 0).display(total)
                );
            });
    }
}

Rather that formatting each footer column with a single renderer, as above, I'd like to use the main column renderer. But I can't figure out how to get that out of the dataTable api. Any wisdom?

This discussion has been closed.