Reputation: 5972
I have simple table generated with PrawnPDF that looks like the one below
|h1|h2|h3|h4|
-------------
|d1|d2|d3|d4|
|d1|d2|d3|d4|
|d1|d2|d3|d4|
Generated by the code below
tb = [["h1", "h2", "h3", "h4"],
["d1", "d2", "d3", "d4"],
["d1", "d2", "d3", "d4"],
["d1", "d2", "d3", "d4"]]
table(tb)do
row(0).font_style = :bold
end
Now the header needs to be made by two rows as below
|text |
|h1|h2|h3|h4|
-------------
|d1|d2|d3|d4|
|d1|d2|d3|d4|
|d1|d2|d3|d4|
I have tried to make a subtable and to use it as the header but it does not span all the table. It looks like
|text |
|h1|h2|h3|h4|
----------------------
|d1 |d2|d3|d4|
|d1 |d2|d3|d4|
|d1 |d2|d3|d4|
and no row is bold.
Here the code so far
text = make_cell(content: 'text', colspan: 4)
header_array = [[text], ["h1", "h2", "h3", "h4"]]
header = make_table(header_array)
tb = [[header],
["d1", "d2", "d3", "d4"],
["d1", "d2", "d3", "d4"],
["d1", "d2", "d3", "d4"]]
table(tb)do
row(0).font_style = :bold
end
Any ideas how can I span the header?
PS I'm using prawn version 1.3.0 and prawn-table 0.2.2
Thanks
UPDATE - Based on Florent answer, if you want/need to pass a block to the table.
header_text = [[{content: "Text", colspan: 4}]]
tb = [["h1", "h2", "h3", "h4"],
["d1", "d2", "d3", "d4"],
["d1", "d2", "d3", "d4"],
["d1", "d2", "d3", "d4"]]
table(header_text + tb)do
row(0).font_style = :bold
self.header = 2
end
Upvotes: 1
Views: 571
Reputation: 413
Dit you try to use the header param ?
header_text = [[{content: "Text", colspan: 4}]]
tb = [["h1", "h2", "h3", "h4"],
["d1", "d2", "d3", "d4"],
["d1", "d2", "d3", "d4"],
["d1", "d2", "d3", "d4"]]
table(header_text + tb, header: 2)do
row(0).font_style = :bold
end
Upvotes: 4