Virtual columns with aggregated data (COUNT, AVG, SUM) and HAVING filters.
Filters
Drag to reorder, pin columns, and show/hide:
Table definition
app/infotable/companies_table.rb
class CompaniesTable < Infotable::Base
# Virtual/aggregated columns example
query do
Company.select(
"companies.*",
"COUNT(products.id) AS products_count",
"AVG(products.price) AS avg_product_price",
"SUM(products.price) AS total_products_value"
)
.left_joins(:products)
.group("companies.id")
end
column :id,
label: "ID",
type: :integer,
width: "60px",
sortable: true,
visible: true
column :name,
label: "Company Name",
type: :string,
sortable: true,
searchable: true,
filterable: true,
filter_type: :text,
visible: true
column :industry,
label: "Industry",
type: :string,
sortable: true,
filterable: true,
filter_type: :select,
filter_options: -> { Company.distinct.pluck(:industry).compact.sort },
visible: true
column :active,
label: "Active",
type: :boolean,
sortable: true,
filterable: true,
filter_type: :boolean,
visible: true,
formatter: :boolean
column :products_count,
label: "# Products",
type: :integer,
sortable: true,
filterable: true,
filter_type: :number,
virtual: true,
virtual_sql: "COUNT(products.id)",
visible: true
column :avg_product_price,
label: "Avg Price",
type: :decimal,
sortable: true,
filterable: true,
filter_type: :number,
virtual: true,
virtual_sql: "AVG(products.price)",
visible: true,
formatter: :currency,
formatter_options: { precision: 2 }
column :total_products_value,
label: "Total Value",
type: :decimal,
sortable: true,
filterable: true,
filter_type: :number,
virtual: true,
virtual_sql: "SUM(products.price)",
visible: true,
formatter: :currency,
formatter_options: { precision: 2 }
per_page 25
per_page_options [10, 25, 50, 100]
default_sort :name, :asc
table_min_height "500px"
table_max_height "700px"
end