Javascript Sourced Footer and Export Footer

Javascript Sourced Footer and Export Footer

JLegaultJLegault Posts: 31Questions: 6Answers: 2

Link to test case: http://live.datatables.net/tagoyayi/530/edit
Debugger code (debug.datatables.net): N/A
Error messages shown: N/A
Description of problem: From my understanding there is no way currently to modify this table to generate a footer along with it's header and table. I have seen examples that show adding the footer either in the HTML or via jQuery before table creation, but my table is not supporting footerCallback. I've tried adding a <tfoot/> tag within the <table> tag but it appears that I will need to fully describe my footer prior to DataTable conversion.

What I'm really looking to do is include a total footer only on export via the html5 export options, but I don't see a good way to do that without also including the footer on the normal table as well (something that forum members have mentioned previously).

Optimally I would be able to utilize the 'format.footer' 'exportOptions' for the buttons, but that appears to need a footer to exist in the table.

Is there really no support for creating a footer on table creation? If so I may wind up using RowGroup to artificially create a single parent group for the entire table and use endRender to build my footer, but that would both be a large amount of coding and a very obtuse way to do this.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949
    edited May 2021 Answer ✓

    The problem in your example is you have defined only a table element but you are trying to clone the header (which doesn't exist) into the footer. I've seen ways to build the footer dynamically such as in the footerCallback but Datatable won't know about it and any of the footer APIs like column().footer() won't work. I don't think enabling the footer like this example will work for the same reason.

    What I'm really looking to do is include a total footer only on export via the html5 export options,

    Maybe messageBottom as a function will work as shown in this example.

    Kevin

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    Another option is to build both the header and footer in JS, like this:
    http://live.datatables.net/tagoyayi/533/edit

    Then Datatables will know about it and you can still use columns.title. The only requirement is knowing the number of columns the table has before initialization so you can build the appropriate number of header and footer columns.

    Kevin

  • JLegaultJLegault Posts: 31Questions: 6Answers: 2

    I think I'm going to use messageBottom as I don't always know the number of columns my table will have.

    Thanks for all your help!

This discussion has been closed.