h1. Description p. ar_to_html_table renders an ActiveRecord result set into an html_table. For example: bc. Product.all.to_table p. will produce a table with default characteristics. These characteristics are primarily driven by class names and hence styling is defined in CSS. h1. Usage p. ar_to_html_table consists of two parts: * Defining column formats in the ActiveRecord model * Rendering an ActiveRecord result set h2. Column definitions p. Columns in the table are formatted based upon a column definition applied in the Model. Some examples: bc. class Product < ActiveRecord::Base column_format :name, :order => 1 column_format :orders, :total => :sum column_format :revenue, :total => :sum, :order => 5, :class => 'right' column_format :age, :total => :avg, :order => 20, :class => 'right', :formatter => :number_with_delimiter .... end p. The general form of a column definition is: bc. column_format :column_name, options h2. Column names and calculated columns p. Column names are generally the model attribute name however a limited set of calculated columns can also be derived. For example: bc. column_format :percentage_of_revenue, :order => 9, :class => 'right' p. Will define a column that renders the percentage of total revenue that this row's revenue represents. The regexp used to recognize calculated columns is: bc. /(percent|percentage|difference|diff)_of_(.*)/ p. Where the match is the name of the column against which the calculation if made. Therefore percentage and difference (plus their variants) are the two available calculated column types. h2. Column options |_. Option|_. Description| |:order|Positions a column order relative to other columns. The number isn't important, just its relative value compared to other columns. Columns are sorted by order and rendered in that order. The default order is the order in which the columns are defined.| |:total|Renders a table footer with a calculation of all the values in the column. The available totaling methods are **:sum**, **:count** and **:average** (or :avg or :mean)| |:class|The CSS class for this column. Note that a **colgroup** is defined for each column and each **colgroup** has as CSS class that is the column name| |:formatter|Used to format the value of each table cell. There are several predefined formatters. This value can also be a lambda for arbitrary formatting.| h2. Predefined formatters |_. Formatter|_. Description| |:float_with_precision|Calls **#number_with_precision** after **#to_f** on the value.| |:integer_with_delimiter|Calls **#integer_with_delimiter** unless **I18n::Backend::Simple.included_modules.include? Cldr::Format** is true in which case **I18n.localize** is called.| |:seconds_to_time|Formats an integer as hh:mm:ss, mostly used for durations, not time or datetime columns| |:hours_to_time|Formats an integer as hh:00.| |:currency_without_sign|Calls **#number_with_precision** with precision 2.| |:percentage|An integer rendered as a percentage. Calls **#number_to_percentage** with a precision of 1.| |:bar_and_percentage|Displays a CSS bar and a percentage.| |:unknown_on_blank|Displays **(unknown)** when **column.blank?** is true. This is a localized value. The key **I18n.t('tables.unknown')** is used.| |:not_set_on_blank|Displays **(not set)** when **column.blank?** is true. This is a localized value. The key **I18n.t('tables.not_set')** is used.| p. If no formatter is specified then **#to_s** is called on the value unless the value is a **Fixnumn** in which case **#number_with_delimiter** is called. h2. Table rendering To render the html table, call **#to_table(options)** on any ActiveRecord result set. The default options are: bc. :exclude => EXCLUDE_COLUMNS, :exclude_ids => true, :odd_row => "odd", :even_row => "even", :totals => true, :total_one => 'tables.total_one', :total_many => 'tables.total_many', :unknown_key => 'tables.unknown', :not_set_key => 'tables.not_set' |_. Option|_. Description| |:include|Array of columns that should be rendered| |:exclude|Array of columns that should not be rendered| |:exclude_ids|Don't render columns that end in **_id**| |:sort|A **Proc** that is called to sort the rows. Called as **results.sort(options[:sort])**.| |:heading|A table heading that is placed in the first row of a table| |:caption|A table caption applied with