FooterCallback of null, render:

FooterCallback of null, render:

mikedmasonmikedmason Posts: 39Questions: 12Answers: 0

Hi Guys,
Quick question. I am using the footerCallback with fields that existed in the database and it worked perfectly. When I added columns that where rendered it would not sum them. I was able to find a solution it had me add a .cache('search') to the null, render: fields.

Should I be using the .cache('search') on all the fields for the footerCallback? is the .cache('search') the proper way to sum null, render fields? It works but not sure if it is the proper way or if it will cause me issues down the road.

           data = api.column( 2 ).data();
           total2 = data.length ?
                data.reduce( function (a, b) {
                        return intVal(a) + intVal(b);
                } ) :
               0;

            data = api.column( 3 ).cache('search');
            total3 = data.length ? 
                data.reduce( function (a, b) {
                        return intVal(a) + intVal(b);
                } ) :
                0;

http://debug.datatables.net/umoxib

Regards,
Mike

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited March 2015 Answer ✓

    Hi Mike,

    You might be better using cells().render() to get the rendered data - just in case you ever decide to turn off searching on that column.

    One other thing, you can use the second parameter of the reduce() method to let you do it all in one expression, even if there are no values.

    Example:

    total3 = api.cells( null, 3 ).render( 'display' ).reduce( function (a, b) {
        return intVal(a) + intVal(b);
    }, 0 );
    

    Allan

  • mikedmasonmikedmason Posts: 39Questions: 12Answers: 0

    Thanks Allan. That work great.

This discussion has been closed.