How to set table headers in Prawn?

I am following this tutorial to create a pdf file using a shrimp gem, and I found this link to create a table.

How to set header row and header headers in each column?

invoiceData = [["foo","bar"]] pdf.table(invoiceData) do |table| table.rows(1..3).width = 72 end 
+6
source share
3 answers

If you pass: header => true as an option, it should use the first line 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) 
+8
source

this works for me:

 pdf.table data, :headers => ['foo', 'bar'] 
+1
source

In addition to @dogenpunk's answer, you can also set the title bar style:

 table_data = generate_lots_of_table_data table_data.unshift %w(id name address) # add headers table(table_data, header: true) do row(0).style font_style: :bold # header style end 
0
source

Source: https://habr.com/ru/post/886001/


All Articles