My example (just click "export PDF"): https://jsfiddle.net/j9vaqpnz/7/
My example exports my table which looks like this:
.
The table then is exported to pdf using libraries jspdf and autotable.
During the export function I use the "drawCell" function and for all columns which contain a number i right-align them as follows:
drawCell: function (cell, data) {
var col = data.column.index;
if(col==3 || col==5 || col==6 || col==7 || col==8 || col==9 || col==10){
cell.styles.halign = 'right';
}
}
.
Problem: In the PDF all the columns which I have right-aligned are positioned inproperly, it looks like this:
Is this a bug? Or maybe I am using "drawCell" inproperly?
When using "didParseCell" (v3.x) the right align positions the elements properly.
Updated example: https://jsfiddle.net/j9vaqpnz/10/
New Code:
...
didParseCell: function (cell, data) {
alignCol(cell, data);
}
...
function alignCol(data){
var col = data.column.index;
if(col==3 || col==5 || col==6 || col==7 || col==8 || col==9 || col==10){
data.cell.styles.halign = 'right';
}
}
You can align cells using the columnStyles
property
const pdf = new jsPDF();
pdf.autoTable({
...
columnStyles: {
3: {
halign: 'right'
},
5: {
halign: 'right'
},
6: {
halign: 'right'
},
7: {
halign: 'right'
},
8: {
halign: 'right'
},
9: {
halign: 'right'
},
10: {
halign: 'right'
}
}
});
jsPDF-AutoTable documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With