PDF export

Fabien Dobat edited this page Dec 4, 2015 · 2 revisions

Datagrid provides you a table like structure with data:

report = MyGrid.new

report.header # => ["Group", "Name", "Activated"]
report.rows   # => [
              #      ["Steve", "Spammers", true],
              #      [ "John", "Spoilers", true],
              #      ["Berry", "Good people", false]
              #    ]
report.data   # => [ header, *rows]

You can use this data for export.

There are some gems available that can give you export.

Easy way (using ruport):

require 'ruport' # gem install ruport

f = File.new("report.pdf", "w") 
f.write Ruport::Data::Table(:column_names =>report.header, :data => report.rows).to_pdf
f.close

Hard way with custom formatting: https://github.com/mileszs/wicked_pdf

Anyway I think PDF export is not under scope of this gem.