how to mix footerCallback and columnDefs?
how to mix footerCallback and columnDefs?
Hi!
I'm struggling with this question: how can I mix footerCallback and columnDefs?
I did this basic example:
http://jsfiddle.net/bv5qk06k/8/
but I want the column with amount be formatted, footer included, during rendering.
I CANNOT simply format the amount in footerCallback, my goal is to turn on the "Buttons" extension without breaking Excel...
I think the problem is that footer is wrote using .html(), but I haven't found a way to avoid it.
Any suggestion?
Many thanks
Cheers,
Francesco
Answers
Maybe Javascript's toLocaleString will help. Try this:
Updated your example here:
http://jsfiddle.net/pcm5aurf/6/
Kevin
Hi Kevin,
Thanks for the prompt reply.. I fear it will fix the rendering, but will break the Excel... I'll give it a try anyway later today.
BR
Francesco
I tested the solution and I can confirm the Excel is broken...
175,00 will be converted in 17500
I've found a workaround that I post here for future reference...
Using kthorngren suggestion (or "$.fn.dataTable.render.number( '', ',', 2, '' ).display()" or a replace of "." with ",") we display right data in table then we can do the opposite in Excel footer export:
and of course:
as I told this is not a proper fix or solution to the problem!
Have you tried creating a buttons formatting function for the footer?
https://datatables.net/extensions/buttons/examples/html5/outputFormat-function.html
Kevin
It's what I did in the end.. but it's a kind of gross IMHO
@kthorngren I have a column which has a data like
3 days, 14hrs & 30 minutes
. I converted it toseconds
and called it in thefooterCallback
. However, I can't get it working converting it back to the above format. My code looks like this:Converting
seconds
into desired format will be inaccurate (see the comment in the code). And so I tried doing it in the footer update:Hi @alexela8882 ,
This sounds like a different to the main thread, so it would be worth raising separately. What I would say though, is any thing time based, just use Moment.js, as it's excellent for all time/date based operations.
If that doesn't help, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin