Reputation: 2046
I am using the jsPDF AutoTable plugin (v3.1.1) and my table needs 4 columns but the first row of my form has only 2 columns so I need to use colspans in the first row. AutoTable doesn't seem to do colspans right if the first row doesn't have all the columns there will be. If my first row contains 4 blank cells, everything works fine but I get an unnecessary row on the top of my table. Here's some code that demonstrates the issue:
var doc = new jsPDF();
var desiredDefinition = [
[{"content":"Field 1","colSpan":2}, {"content":"201901300654","colSpan":2}],
[{"content":"Field 2"},{"content":"Field 3"},{"content":"Field 4"},{"content":"Field 5"}],
];
doc.autoTable({ body: desiredDefinition });
var workaroundDefinition = [
[{"content":""},{"content":""},{"content":""},{"content":""}],
[{"content":"Field 1","colSpan":2}, {"content":"201901300654","colSpan":2}],
[{"content":"Field 2"},{"content":"Field 3"},{"content":"Field 4"},{"content":"Field 5"}],
];
doc.autoTable({ body: workaroundDefinition });
doc.save("table.pdf");
Here's a codepen with the issue: https://codepen.io/sirhcybe/pen/rgpKEJ
I played around with the columns property but couldn't find any way to tell AutoTable how many columns I need without creating an extra row. Is there a work around for this issue?
Upvotes: 1
Views: 1430
Reputation: 2046
This has been marked as a bug in the jsPDF AutoTable repo: https://github.com/simonbengtsson/jsPDF-AutoTable/issues/500
I did not find a decent workaround but since I am using my own fork of jsPDF AutoTable I was able to make the code fix described in the GitHub issue.
EDIT: This was fixed as a bug in jsPDF-AutoTable v3.2.
Upvotes: 1