-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi-row headers + rowspan/colspan in xlsx headers #418
Comments
@chrisvwn Hi, Chris! Can you please share with me all these .js files that you have modified to fix multiple row header issue. It would be helpful. Thank you! |
Hi @PawanAgarawal . Let me create a fork with the code. |
Hi @PawanAgarawal Apologies for the delay. Please find the forked code at https://github.com/chrisvwn/DT |
…lspan in xlsx headers
…lspan in xlsx headers
Thank you very much for the solution! Can someone please share with me the files:
with the multiple row header fix? Thank you very much! Paolo |
@chrisvwn |
@chrisvwn Excellent work |
@javg15 You're welcome @avinashvalluru Thanks. It should be possible to replicate the same in the footer by making similar changes in the appropriate sections. |
This is a very well thought out solution. @yihui, are there plans to incorporate this into a future release of DT? The ability to preserve multi-row headers when exporting tables built with custom containers would be very useful. |
@larssoneg I believe @yihui is waiting for someone to adopt the task and make a pull request so that the changes can be incorporated. I am not a javascript programmer myself and am afraid that I will soon run out of my depth which is why I have not made the pull request. For example I found this change does not work in at least one browser and I am unable to fix that. My hope is that a more skilled javascript programmer can take over this issue, bring the changes to an acceptable standard and see it through to incorporation. I am willing to give any assistance that may be required where I can. In fact, I would recommend rewriting the code to use a more modular approach to allow for easier improvements in future. So I guess this is a call to javascript programmers - volunteers needed. |
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! |
Thanks and good catch @MichaelC77 ! |
Can't we simply merge @chrisvwn fork into this? His solution seems to work and would greatly benefit others by being taken onto the master repo. |
…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.
…justments to what is suggested. This alloes the output function 'Print' to handle multiple row headers
…n commit ed15f2f allowing the outputfunction pdfHtml5 to print pdf with multi-row headers
…n commit ed15f2f improves the outputfunction excelHtml5 to export excel files with multi-row headers, without the merges. On top of what is described rstudio#418, it makes other modifications needed to match the latest rstudio/DT version.
…n commit 6b56d58 and process the col/row span information to merge the cells at the excel output via the function excelHtml5
…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 It changes:
which can be found at: https://github.com/mtyszler/DT/tree/feature/complex_headers/inst/htmlwidgets/lib/datatables-extensions/Buttons/js |
Good work @mtyszler ! |
hi @mtyszler i have a problem, i can't export footer. |
Hi @Taufikismail . As you can see in the upstream PR DataTables/Buttons#170, I handled both complex headers and footers. Since @yihui and @shrektan pointed out that it was best to handle it at origin, I did not expand/continued the work on #751. I hope upstream can pick it up quickly. I suggest you add at comment at the PR DataTables/Buttons#170 and/or refer to @DataTables |
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. |
Thanks a lot @chrisvwn. It works just perfect. |
You're welcome @alaaseada You may want to use the more complete code for DT buttons by @mtyszler at #751. |
im tring from last 2 weeks finally got solution thank you so much.... Chris Njuguna chrisvwn |
Hi all,
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.
Disclaimer: I am not a javascript programmer and so this code is not tested, might have bugs and might affect the currently functioning DT code. Use at your own risk and feel free to edit the code as you see fit. Any questions, comments or critique are welcome.
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
m.background = function(...
and similar codeb. Replace this code:
with this code:
c. Replace this code:
with this code:
d. Then replace:
with:
2.In "buttons.html5.min.js" file
a. Add multiple headers in xlsx
i. Find the section s.ext.buttons.excelHtml5 and the action: function
ii. Replace this code:
with this code:
b. Add multiple headers in pdf
i. Find the section s.ext.buttons.pdfHtml5 and the action: function
ii. Replace this code:
with
3.In "buttons.print.min.js"
c. Add multiple headers in print
i. Find the action: function
ii. Replace this code:
with
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
b. Replace the code we added earlier for multiple headers:
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: