Reputation: 2139
I am trying to create a table based on an array of data, "tableData".
The number of rows will vary.
To create table you have to match the "alignments" data to the data.
I can not create an array with just .left, .center, or .right variables to match the data. They are not stings or ints, etc...
So how can I set the alignments rows to equal the data rows?
do {
try table.generateCells(
data:tableData,
alignments: [
[.center, .right, .right, .right],
[.center, .right, .right, .right],
[.center, .right, .right, .right],
[.center, .right, .right, .right]
]
)
}
It does not appear you can set all the rows with a single entry. Has to be array with matching numbers of row.
https://github.com/Techprimate/TPPDF
Thank you.
Upvotes: 0
Views: 275
Reputation: 1069
I am the creator of TPPDF.
During development I designed tables to work similar to popular word processing software like Microsoft Office Word or LibreOffice, where you can change the alignment per cell.
As of now it is not possible to set a default alignment, therefore the easiest way is mapping your data to an alignment (as you did in your code example).
If you want a shorter syntax, I can propose this:
let tableData: [[String]] = [...] // This is your nested data
let alignments = tableData.map { $0.map { _ in PDFTableCellAlignment.right }}
We are always open for new features and enhancements, please feel free to create an issue or even better an implementation with a default alignment value and propose a pull request on Github.
Upvotes: 2
Reputation: 2139
I think this works. Maybe someone has a better way?
Setting up the align array with the "PDFTableCellAlignment" allows me to set the .right, .left, .center variables.
var tableData = [[String]]()
var align = [[PDFTableCellAlignment]]()
for item in self.d!{
let c = [ .... ]
tableData.append(c)
align.append([.right, .right, .right, .right])
}
looking forward to anyone else thoughts.
thanks.
Upvotes: 0