prawn-table icon indicating copy to clipboard operation
prawn-table copied to clipboard

Subtables: borders cannot be turned off?

Open ruckus opened this issue 8 years ago • 5 comments

I'm attempting to generate a document using tables & subtables and I cannot see how to turn off borders on the sub-table.

The sub-table itself is created using make_cell so additional formatting options can be used.

Here is an example which illustrates the problem:

@pdf = Prawn::Document.new(:page_layout => :portrait, :page_size => "LETTER")


data = [["Hello, World"]]

subtable = @pdf.make_table([["I'm a subtable"]]) do |t|
  t.cells.border_width = 0
end

row = ["Left Side", subtable]
cell_subtable = @pdf.make_cell([row], :border_width => 0, :borders => [])
data << [cell_subtable]

@pdf.table(data) do |t|
  t.cells.border_width = 0
end

@pdf.render_file("foo.pdf")

This generates a document like this. In the code I have disabled all borders - yet the single border around the whole subtable/row is still being rendered:

screen shot 2016-09-14 at 10 52 33 am

I feel like I am doing something wrong and I am missing a simple action.

Thanks!

ruckus avatar Sep 14 '16 17:09 ruckus

Versions:

prawn (2.1.0) prawn-table (0.2.2)

ruckus avatar Sep 14 '16 17:09 ruckus

I've been monkeying around with this and if I hard-code something like:

          options[:borders] = []
          options[:border_widths] = [0,0,0,0]

In Prawn::Table::Cell:Subtable#initialize ala:

https://github.com/prawnpdf/prawn-table/blob/master/lib/prawn/table/cell/subtable.rb#L21

Then it properly over-rides the border drawing. The downside is that this affectively disables borders for all sub-tables.

My next challenge is to determine how to properly pass the options hash around from the top-level Document#make_table() call such that it gets all the way down into my Subtable initializer.

ruckus avatar Sep 16 '16 18:09 ruckus

@ruckus were you able to fix this? I'm having similar problem

iamtheschmitzer avatar Aug 10 '17 11:08 iamtheschmitzer

@iamtheschmitzer I had to fork prawn-table and update some methods to take an options hash, which allowed me to specify no border params in calling code:

https://github.com/ruckus/prawn-table/commit/6387b6914985f003462a801efc3fe526f9fe2ed8

ruckus avatar Aug 10 '17 16:08 ruckus

While patching the code, I realized this is not needed. It makes sense how it works, but is not easy to see and the documentation says nothing about it.

Just define no borders in all cells of the sub-table and in the cell containing the sub-table.

subtable_full_bordered = [["subtable row 1"],["subtable row 2"]]
table_full_bordered = [["row 1"], subtable_full_bordered, ["row 2"]] # will show borders, everywhere

subtable_no_borders = [[{content:"subtable row 1", borders: []}],[{content:"subtable row 2", borders: []}]]
table_bordered = [["row 1"], subtable_no_borders, ["row 2"]] # will show borders, around the table, as they are from the table, and not the subtable

table_no_borders = [
  [{content:"row 1", borders: []}],
  [{content: subtable_no_borders, , borders: []}],
  [{content:"row 2", borders: []}]
] # will show no borders at all

If using make_cell this would behave the same

estani avatar Jul 19 '21 14:07 estani