prawn-table set header's row background color

自作多情 提交于 2019-12-11 00:53:50

问题


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:


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



来源:https://stackoverflow.com/questions/33733061/prawn-table-set-headers-row-background-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!