add colspan support for footer
When printing a table with colspan in footer the cell is repeated with no colspan.
Example:
<tfoot>
<tr>
<th colspan="3">a</th>
<th>b</th>
</tr>
</tfoot>
results in
| a | a | a | b |
|---|
I think this is a duplicate of #60. The issue is that there is no way to represent the colspan in CSV or TSV.
Indeed, but it should work for print and pdf.
Atm I'm using a customize for print:
customize: function (win) {
var footer = $('tfoot');
if (footer.length > 0) {
var exportFooter = $(win.document.body).find('thead:eq(1)');
exportFooter.after(footer.clone());
exportFooter.remove();
}
}
Note the thead:eq(1) should be replaced by tfoot when the fix is released.
In my pull request: https://github.com/DataTables/Buttons/pull/74 I introduce the ability to modify the data before it is exported, for instance in CSV and TSV. In my example I show one approach to dealing with colspans. There, it fills blank cells for trailing columns, but feel free to use the code if it helps.
While it does not automate things for the developer, it at least releases some control to the developer, to modify the exported data. In the future you can add formatting options; for instance:
- _colspans-repeat_ (boolean) :
optional format; when a colspan is encountered, its value will be repeated for n number of columns in the span (alternative is to fill columns with empty strings, as in my example) - _colspans-col-value-first_ | _colspans-col-value-last_ (boolean) ;
_colspans-col-value-position_ (integer) :
optional format; when colspan value does not repeat, let the user decide what cell the value should appear in.- If first is true, then the value will appear in the first column, followed by blank strings.
- If last is true, then the value will appear in the last column, with empty strings appearing before it.
- If the position is selected the value will appear in that respective column within the colspan, with empty strings in the columns that come before and after for the duration of the span.
Thanks @vol7ron, that's a great idea. Being able to customize the data in geneal is the way to go in my opinion. For example in some cases I want to export footers with more than one row, but the default behavior is to export only the first. Similarly for headers, only the last table row is exported now.
Indeed, but it should work for print and pdf.
Atm I'm using a customize for print:
customize: function (win) { var footer = $('tfoot'); if (footer.length > 0) { var exportFooter = $(win.document.body).find('thead:eq(1)'); exportFooter.after(footer.clone()); exportFooter.remove(); } }Note the
thead:eq(1)should be replaced bytfootwhen the fix is released.
For pdf this is not working, "Uncaught TypeError: Cannot read property 'body' of undefined" this error is coming in "var exportFooter = $(win.document.body).find('tfoot:eq(1)');"
This has finally been done and will ship in Buttons 3 alongside DataTables 2.