Add table footer with Javascript only
Add table footer with Javascript only
ifischer
Posts: 6Questions: 1Answers: 1
I prefer to define my tables without using any HTML besides the base table element and do all the work inside the jquery-datatables definition.
I also use colvis to toggle column visibility.
What would be a clean way to add the footer HTML via Javascript, so I can fill it inside the fnFooterCallback?
In which callback should I do it?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
JSFiddle:
http://jsfiddle.net/ifischer/mg43ukjb/1/
You need to add the footer before you create the table as DataTables doesn't provide a method for creating a footer at the moment. You could use something like:
But you need to create the header before the table is initialised as well! Or just put it in the HTML.
Allan
Thanks Allen!
Unfortunately I cannot simply clone the header as I need an empty footer but a sum column in one row.
This is how I did it in the end - as you said I need to add the footer beforehands:
javascript:
Demo fiddle:
http://jsfiddle.net/ifischer/Ljwgrkq0/3/
Not perfect, but at least I can keep my HTML file "clean". Since I reuse the table in many different views, I would always have to change each HTML separately which is prone to errors.
Thanks for posting back - good ot hear you got it working!
Allan