Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternating "row_colors" reset after page break #116

Open
supermitch opened this issue Aug 24, 2019 · 0 comments
Open

Alternating "row_colors" reset after page break #116

supermitch opened this issue Aug 24, 2019 · 0 comments

Comments

@supermitch
Copy link

supermitch commented Aug 24, 2019

I noticed that when a table breaks across pages, the first alternating row_color "resets". Here is an example: (This is one table, broken by a page break. Notice how it should be green on white, but changes to red on white after the break)

If you also use cell.row % 2 to modify your text_color, they will go out of sync, because the row number is (correctly) maintained.

Simple reproduction here:

require 'prawn'
require 'prawn/table'

headers = [%w[Header1 Header2 Header3]]
data = headers + Array.new(30) { %w[Column1 Column2 Column3] }

Prawn::Document.generate('row-colors-test.pdf', page_layout: :landscape) do
  move_down 30
  font_size 9
  table(
    data,
    header: true,
    row_colors: %w[FFFFFF CCCCEE],
    cell_style: { border_width: 0.5 }
  ) do
    row(0).background_color = 'FCF6F2'
    cells.style do |c|
      if c.row > 0 && c.column == 2 # Skip headers & only modify col 3
        # c.row doesn't "reset" on new page, but row_color does
        c.text_color = (c.row % 2).zero? ? 'CC0000' : '00CC00'
      end
    end
  end
end

I believe that the row_color should not reset when a table breaks for a new page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant