prawn-table set header's row background color

2019-08-09 04:52发布

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!

1条回答
走好不送
2楼-- · 2019-08-09 05:11

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

查看更多
登录 后发表回答