Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set table headers in Prawn?

I'm following this tutorial to create a pdf file using prawn gem, and I found this reference documentation to generate a table.

How do I set the header row and the header titles to each column?

invoiceData = [["foo","bar"]]
pdf.table(invoiceData) do |table|
table.rows(1..3).width = 72
end
like image 952
Mr_Nizzle Avatar asked Apr 15 '11 15:04

Mr_Nizzle


2 Answers

If you pass :header => true as an option it should use the first row of your array as a repeating header. From the docs:

data = [["This row should be repeated on every new page"]]
data += [["..."]] * 30
table(data, :header => true)
like image 112
dogenpunk Avatar answered Nov 03 '22 00:11

dogenpunk


this works for me:

pdf.table data, :headers => ['foo', 'bar']
like image 45
Peter Vojtek Avatar answered Nov 02 '22 23:11

Peter Vojtek