html table with hidden column
Hi! Does the jsPDF does not support exporting html table with hidden column? It seems that only the data can be hidden in the table and if the headers are hidden the whole table will only show the ones with the header. I have been looking around for answers but then I only found none. This is an example of a hidden column. http://jsfiddle.net/riichan/1f8pbpg8/
Here's how I solved this one:
My hidden columns have a .hidden class to each <td> in the column and I omit a row by adding a .omit-row class to the <tr>
Then, I take a clone of the html DOM element and delete the cells and rows out of the clone before I send it over to jspdf
<div id="table">
<table>
...
</table>
</div>
(I realize that I totally abuse jquery's $.each() below... )
source = $('#table')[0];
cln_source = source.cloneNode(true);
//console.log(cln_source);
var deleterows = [];
$(cln_source.childNodes[1].rows).each(function(ri, row){
var deletecells = [];
$(row.cells).each(function(ci, cell){
if( $(cell).hasClass('hidden') )
deletecells.push(ci);
});
console.log(deletecells);
$.each(deletecells.reverse(), function(i, ii){
console.log(ii);
row.deleteCell(ii);
});
if($(row).hasClass('omitted-row'))
deleterows.push(ri);
});
$.each(deleterows.reverse(), function(i, ii){
cln_source.childNodes[1].deleteRow(ii);
});
specialElementHandlers = {
'#bypassme': function (element, renderer) {
return true
}
};
margins = {
top: 100,
bottom: 60,
left: 40
};
pdf.fromHTML(
cln_source,
margins.left,
margins.top, {
'width': margins.width,
'elementHandlers': specialElementHandlers
},
function (dispose) {
pdf.save('Test.pdf');
}, margins);
Wow. Thanks dude! I appreciate your answer.
Sent from Samsung Mobile
(I realize that I totally abuse jquery's $.each() below... )
source = $('#table')[0];
cln_source = source.cloneNode(true);
//console.log(cln_source);
var deleterows = [];
$(cln_source.childNodes[1].rows).each(function(ri, row){
var deletecells = [];
$(row.cells).each(function(ci, cell){
if( $(cell).hasClass('hidden') )
deletecells.push(ci);
});
console.log(deletecells);
$.each(deletecells.reverse(), function(i, ii){
console.log(ii);
row.deleteCell(ii);
});
if($(row).hasClass('omitted-row'))
deleterows.push(ri);
});
$.each(deleterows.reverse(), function(i, ii){
cln_source.childNodes[1].deleteRow(ii);
});
specialElementHandlers = {
'#bypassme': function (element, renderer) {
return true
}
};
margins = {
top: 100,
bottom: 60,
left: 40
};
pdf.fromHTML(
cln_source,
margins.left,
margins.top, {
'width': margins.width,
'elementHandlers': specialElementHandlers
},
function (dispose) {
pdf.save('Test.pdf');
}, margins);
— Reply to this email directly or view it on GitHub.
@neildaemond or @riichii
Do you guys have a working example for this issue? I am also trying to export tables with hidden columns and still no solution. Please help
Up
We are closing this issue, because we will not support any longer fromHTML and addHTML.
Explaination:
We are working on a new html2pdf plugin, which will be based on html2canvas and our context2d plugin. This should lead to more reliable results for your projects. And it will give us the time to focus on the core functionality of pdf-generation because we will not use our energy for writing/supporting/extending 2 html plugins. If you still want to use addHTML or fromHTML you can still use jsPDF 1.4.1.
Best Regards