Multi-row headers + rowspan/colspan in xlsx headers #418
This is an extension of lisarush 's and dfader 's code over at (https://datatables.net/forums/discussion/40854/how-to-add-second-footer-to-print-in-tfoot?) to get multiple headers to work in csv, xlsx, pdf and print.
I also have added a basic merge working for colspan and rowspan headers in xlsx. It does not work in firefox but does in chrome and opera browsers and I don't know why yet. Hopefully someone can help with that. It should be possible to port this (at least the logic) for the footer and body as well.
I am not sure if the rstudio/DT code is modified from the datatables.net code but I found some differences and the edit suggestions at the datatables.net forums had to be altered to work. So these changes should work directly in rstudio/DT and with modification at datatables.net. Anyway, hopefully, this will help somebody.
A. Add multiple headers
1.In "dataTables.buttons.min.js" file
(You will need to deminify the files first)
a. Add this function: Insert in the section with
b. Replace this code:
with this code:
c. Replace this code:
with this code:
d. Then replace:
2.In "buttons.html5.min.js" file
a. Add multiple headers in xlsx
with this code:
b. Add multiple headers in pdf
c. Add multiple headers in print
B. Merge colspan/rowspan headers in xlsx
(Note: This will only work if you have gone through the earlier steps in part A)
1.Edit the "buttons.html5.min.js" file
a. Back in the s.ext.buttons.excelHtml5 section
with this code:
c. In between this code:
and this code:
add this code:
That's it. You're done!
The text was updated successfully, but these errors were encountered:
I second @larssoneg's comments above. If I had the skills to do this I would take it on myself, but unfortunately I am not even close. Not being able to export all the headers really makes those buttons unusable for the project that I was hoping to use them for... :-(
The complex headers works perfect for tables with complex headers, however I ran into an issue when I tried to export tables that didn't have complex headers. The issue arrised with this section
/* Old */
I was able to correct this error by changing the code to the following
/* New */
Instead of checking the length of the children attributes for greater than 0 it now just checks if any children exist which doesn't cause the error to raise anymore and works for both kinds of tables.
Good work on the solution @chrisvwn!
…g with minor adjustments changes from https://github.com/chrisvwn/DT/blob/master/inst/htmlwidgets/lib/datatables-extensions/Buttons/js/dataTables.buttons.min.js, which is inpired by https://datatables.net/forums/discussion/comment/106434/#Comment_106434 This prepares the dataTables.buttons.min.js to handle multiple row headers. Without further adjustments this change actually create problems for all output functions, which expect a single row header instead of an array.
…roduced on ed15f2f. Here the main improvements are: * It includes all headers, including the ones which are hidden using colvis, for example. This if done via using aoHeader instead of nThead, and then using the cellIndex property instead of the colspan of the shown table on screen. * After extracting a complete rawHeaderMatrix, it process it to remove hidden columns and format the content. (similar to the original single row header code)
Dear all. I took on the original suggestions by @chrisvwn , @MichaelC77 and what was discussed at https://datatables.net/forums/discussion/comment/106434/ and made some additional changes.
First of all, all changes are matching the current (latest) version of https://github.com/rstudio/DT.
Second it improves the getHeaders function to handle the hidden and (un)selected columns. The problem was that the initial code suggested by https://datatables.net/forums/discussion/comment/106434/ introduces two problems:
This version corrects that, and is more complete than the previous solution from @chrisvwn as it handles not only excel, pdf and print, but also the copy and csv functions.
Moreover, the merge colspan/rowspan suggested by @chrisvwn does not take into account message top and headers, and therefore has incorrect row numbers. My version corrects that.
It does not handle the flash counter parts of the html5 functions, as I understand the flash versions are being deprecated.
The latest files are available at https://github.com/mtyszler/DT/tree/feature/complex_headers
I found a solution to replace header and add merged cells instead
I didn't try, but messageTop option can add another row. It can be replaced too.