Skip to content
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

[WIP] Multi-row head export #55

Closed
wants to merge 1 commit into from
Closed

Conversation

Ladel
Copy link

@Ladel Ladel commented Nov 7, 2015

Hi,

Status: WIP (work in process).
TODO:

  • Implementation of colspan
  • Implementation of rowspan

Best regards,

@DataTables
Copy link
Collaborator

Thanks for sending the PR. There are a few gotcha's with multi-row headers and footers (colspan / rowspan just can't be supported in CSV for example) so I'm not going to pull this in immediately. I'll review closely and hopefully pull it in in the not to distant future.

@Ladel
Copy link
Author

Ladel commented Nov 8, 2015

Hi, @DataTables

This is just an outline. I will continue to completion.
I created this PR in order to support the community with advice.

Best regards,

@RaufAli
Copy link

RaufAli commented Jun 27, 2016

Hi @Ladel!

Thanks for solution, it was useful =)

@cat0rgi0
Copy link

cat0rgi0 commented Aug 4, 2016

@DataTables I think for CSV usually rows of header isn't necessary .
Btw i 've tried implementing colspan but on headCells[i][idx].cell i can't understand if there is some property to understand the first element of colspan instead of "firstNode" index ( ugly patch ) ?

for ( var i=0, ien=headCells.length ; i<ien ; i++ ) {
var firstNode = 0 ;
var rowHead = dt.columns( config.columns ).indexes().map( function (idx ,k ) {
if( idx!= firstNode && headCells[i][idx].cell.innerText!= headCells[i][firstNode].cell.innerText){
firstNode= idx ;
return config.format.header( headCells[i][idx].cell.innerText, idx );
}else
return ""
} ).toArray()
header[i] = rowHead;
}

@eng1n88r
Copy link

Is there any plans to include multiple headers export feature in upcoming releases?

@DataTables
Copy link
Collaborator

Yes, but I'm not sure when. It isn't planned in the near future I'm afraid.

@lidinsky
Copy link

Hi, @DataTables

May I ask if this feature could be implemented? Thank you for answer. Good work!

@DataTables
Copy link
Collaborator

It hasn't yet I'm afraid. It is something I'm aware of needing to be done, but I want to change the framework of how it works in DataTables core first.

@mtyszler
Copy link

Dear @DataTables

I had a similar problem/issue, but since I was facing it within R implementation of https://github.com/DataTables/DataTables, I worked on a solution within R.

I was told by @yihui and @shrektan that RStudio version actually imports the code automatically and they suggested that changes were to be made here.

As I see this PR has been opened for quite some time, before I invest any time in translating my solution to here, I would like to know if there's interest in pursuing this at this level. If so, I'd open a new PR, I guess.

Looking forward to hearing from you.

@DataTables
Copy link
Collaborator

Hi! So there are a number of things that need to be addressed as part of the work for multi-row header and footer export, some of which are not trivial unfortunately:

  • How to handle column visibility. DataTables does not expose multi-row header / footer elements via an API. That's going to need a chance in DataTables core.
  • DataTables column visibility doesn't handle colspan / rowspan very well yet.
  • Does pdfmake support colspan / rowspan? I've not looked into that yet
  • Backwards compatibility - the export API explicitly uses single rows at the moment, so this would need to be a major release breaking backwards compatibility.

1 and 2 are actually at least in part addressed in the v2 branch of DataTables. So my intention is to finish exposing that information via the API and then have a branch of Buttons that supports those new features until DT2 alpha / beta is ready.

The trick there is that I don't have a time scale for that yet as I'm working on a number of other things as well.

@mtyszler
Copy link

mtyszler commented Jan 22, 2020

Tks @DataTables for the quick reaction.

Let me highlight a bit what my solution (within R) handles, so you can assess a bit better. First of all, I just want to highlight that my solution was aiming at complex headers, but not complex footers.

Take this table as initial example (this is generated within a R Shiny application):
image

  • How to handle column visibility. DataTables does not expose multi-row header / footer elements via an API. That's going to need a chance in DataTables core.

Indeed this was an issue. The initial solution sketched was missing the mark when colvis was active, or columns where programmatically hidden. This commit specifically handles that.

From my example table above, regardless of the column visibility on screen, the full table is exported, unless specified by code by the programmer (which also works fine). Of course we could test it further to make sure I didn't miss any special case.

  • DataTables column visibility doesn't handle colspan / rowspan very well yet.

I'm not sure I know what you mean here. I have no problems with that. I didn't try extensively with hiding columns by code, but the few trials I had showed me no problem.

  • Does pdfmake support colspan / rowspan? I've not looked into that yet

So far, copy, print, csv and pdf (i.e., everything except excel) handles in the same way, which is having "empty" columns for the spanned cols or rows. For example, the pdf export is:
pdf_example_export.pdf and the csv export is
image

Excel export does merge the cells:
excel_example_export1.xlsx

  • Backwards compatibility - the export API explicitly uses single rows at the moment, so this would need to be a major release breaking backwards compatibility.

I don't see a problem here. See this base commit where the single-row header is replaced by a headerMatrix. Subsequently, the export functions for example here and here were updated to handle multi-row headers. In that sense, the single-row case becomes a special case.

1 and 2 are actually at least in part addressed in the v2 branch of DataTables. So my intention is to finish exposing that information via the API and then have a branch of Buttons that supports those new features until DT2 alpha / beta is ready.

See if my suggestions help here.

The trick there is that I don't have a time scale for that yet as I'm working on a number of other things as well.

I'm very interested in having this feature mainstreamed. I think @yihui and @shrektan would also appreciated it. At the moment I'm using my own fork, but of course I'd prefer to use the main version.

Therefore if you'd be open to me "translating" my solution to here, I can try to find the time to do so.
If you prefer to check my solution and judge if it is helpful, also fine. Just let me know.

@DataTables
Copy link
Collaborator

Backwards compatibility
I don't see a problem here.

The API is changing - buttons.exportData() will no longer have a 1D array for the header and footer, but rather will have a 2D array. It's not a major issue, but it is a change in the API so it would need a Buttons 2 release.

The changes do look useful and it looks feature complete since you are using the internal aoHeader option. I'd like to see the same applied to the footer, but I could potentially add that if needed.

@marcelod
Copy link

I look forward to this feature

@Ladel Ladel closed this Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants