Is it possible to add a footer to a table created from data?
Is it possible to add a footer to a table created from data?
I have tables created using column options and populated using data in a JavaScript variable. I want to be able to show a column total - much like the example provided to illustrate the use of footerCallback. However, there appears to be no column option to create a footer and a footer is not created by DataTable when data is read from a variable.
So I added a <tfoot> to the bare table definition and it almost works. Adding just the <tfoot> does not work but adding a <tr> and at least one <td/> means I am able to add information to some columns in the footer. However, the odd thing is that i can't get a footer for the last column (where I want it).
If I add a <td> element to the <tfoot> for each visible column the last one is removed when the table is rendered. That is, there are 'number of columns - 1' <td> elements in the <tfoot> after initialisation. There are four visible columns in an example I am working on and no matter how many <td/> elements I add to the <tfoot><tr> all but three are removed meaning the last column has no footer..
Is there a better way to add a footer?
Answers
I take it back. After refreshing the page using Ctrl-F5 it seems to work
OK, so the answer is that footers will only be retained for columns up to the first column that is not visible. Even if subsequent columns are visible, a foot <td> will not be generated or returned.
Hi @bseddon ,
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