How to align right column in export PDF, working with columns visibility

How to align right column in export PDF, working with columns visibility

itajackassitajackass Posts: 163Questions: 49Answers: 3

Example with a table with 5 columns:

Col 1 has text
Col 2 has text
Col 3 has currency
Col 4 has number
Col 5 has text

I'd like, when I export in PDF, to align col 3 and col 4 to right.

It can be done with customize option with this code found:

var rowCount = doc.content[1].table.body.length;
for (i = 1; i < rowCount; i++) {
doc.content[1].table.body[i][2].alignment = 'right';
doc.content[1].table.body[i][3].alignment = 'right';
}
;}

But if I want to hide columns before export, for example i want to hide col 2, then then code break the alignment for column CURRENCY cause index = 2 for alignment is now column with NUMBER

Answers

  • itajackassitajackass Posts: 163Questions: 49Answers: 3

    A nice example from another user with same problem: http://live.datatables.net/wafukude/4/edit

    If you hide column POSITION, the script break

  • allanallan Posts: 63,461Questions: 1Answers: 10,466 Site admin

    Hi,

    Yes, in that case you would need to detect how many columns are being included in the export and adjust the code for that. For example you could have the last two columns right aligned. Of course a better solution would actually to be loop over the header to determine which columns are which and mark them as being right aligned. That will allow for your right aligned columns also being hidden!

    Allan

This discussion has been closed.