Skip to content

Instantly share code, notes, and snippets.

@hidakatsuya
Created August 17, 2011 06:51
Show Gist options
  • Save hidakatsuya/1150970 to your computer and use it in GitHub Desktop.
Save hidakatsuya/1150970 to your computer and use it in GitHub Desktop.
ThinReports Example: Advanced List
# coding: utf-8
require 'rubygems'
require 'thinreports'
report = ThinReports::Report.new :layout => 'advanced_list'
report.layout.config.list(:advanced_list) do
# Define the variables used in list.
use_stores :row_count => 0,
:total_row_count => 0
# Dispatched at list-page-footer insertion.
events.on :page_footer_insert do |e|
e.section.item(:page_footer).value("Page row count: #{e.store.row_count}")
e.store.total_row_count += e.store.row_count
e.store.row_count = 0;
end
# Dispatched at list-footer insertion.
events.on :footer_insert do |e|
e.section.item(:footer).value("Row count: #{e.store.total_row_count}")
end
end
report.start_new_page
30.times do |t|
# Internaly #start_new_page() method is called,
# the page break automatically.
report.page.list(:advanced_list) do |list|
list.add_row :detail => "Detail##{t}"
list.store.row_count += 1
end
end
report.generate_file('advanced_list.pdf')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment