FooterCallback of null, render:
FooterCallback of null, render:
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
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:
Allan
Thanks Allan. That work great.