pdf.table([header, row1, row2], width: 490, cell_style: { size: 7, align: :center }) do
style(row(0), padding: [4,2], font: "#{Prawn::BASEDIR}/data/fonts/DejaVuSans-Bold.ttf")
# style(row(0).columns(2..3), width: 10 )
# style(row(0), cell_style: {background_color: "#f5f5dc"} )
style(row(1), padding: [16,10])
style(row(1).columns(-2..-1), align: :right)
style(row(2).column(0), borders: [])
style(row(2).column(-2..-1), padding: [6,10], align: :right)
end
I want row(0)
to have a background color, but can't find out how (see the commented out lines - those are not working).
I use prawn-rails and prawn-table gems.
Thanks!
Ok.. I am too quick with asking questions.
Here is how you do that (use row_colors
option):
pdf.table([header, row1, row2], width: 490, cell_style: { size: 7, align: :center}, row_colors: ['F0F0A3', nil, nil]) do
style(row(0), padding: [4,2], font: "#{Prawn::BASEDIR}/data/fonts/DejaVuSans-Bold.ttf")
style(row(1), padding: [16,10])
style(row(1).columns(-2..-1), align: :right)
style(row(2).column(0), borders: [])
style(row(2).column(-2..-1), padding: [6,10], align: :right)
end
I don't think, it is the best way to achieve the header's background color, but what I did is just set the colors for each row (actually color for the first row, and nil for each left).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With