Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prawn-table set header's row background color

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!

like image 585
Andrey Deineko Avatar asked Oct 19 '25 09:10

Andrey Deineko


1 Answers

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).

like image 173
Andrey Deineko Avatar answered Oct 21 '25 23:10

Andrey Deineko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!