table(
rows:,
row_href: nil, # ->(row) { url }
current: nil, # ->(row) { true for the open row }
group_by: nil, # ->(row) { group label }
collapsible: false,
collapsed: [], # group labels that start folded
empty: "Nada por aqui.",
min_width: nil
) do |t|
t.column(header, align: :left, width: nil) { |row| … }
t.empty { … } # instead of empty:
end
Simple
Each column block receives the row and returns the cell (a value or ERB). Right-align money and quantities; numbers are tabular.
| Empresa | CNPJ | Município | Notas |
|---|---|---|---|
| Empresa Exemplo Ltda | 12.345.678/0001-90 | São Paulo/SP | 1.204 |
| Fictícia Serviços ME | 98.765.432/0001-10 | Campinas/SP | 318 |
| Demo Consultoria | 11.222.333/0001-44 | Curitiba/PR | 42 |
<% companies = [
{ name: "Empresa Exemplo Ltda", doc: "12.345.678/0001-90", city: "São Paulo/SP", notes: 1204 },
{ name: "Fictícia Serviços ME", doc: "98.765.432/0001-10", city: "Campinas/SP", notes: 318 },
{ name: "Demo Consultoria", doc: "11.222.333/0001-44", city: "Curitiba/PR", notes: 42 }
] %>
<%= table(rows: companies) do |t| %>
<% t.column("Empresa") { |c| c[:name] } %>
<% t.column("CNPJ") { |c| tag.span(c[:doc], class: "tr-num") } %>
<% t.column("Município") { |c| c[:city] } %>
<% t.column("Notas", align: :right) { |c| number_with_delimiter(c[:notes], delimiter: ".") } %>
<% end %>
Grouped, clickable, current row
group_by adds a header row per group with its count. row_href makes whole rows clickable without stealing clicks from links, buttons and checkboxes inside them. current marks the row whose drawer is open. min_width keeps columns readable: the table scrolls sideways inside its box.
| Número | Tomador | Emissão | Valor | Situação |
|---|---|---|---|---|
| Novembro de 2026 · 2 | ||||
| 1234 | Empresa Exemplo Ltda | 05/11/2026 | R$ 1.500,00 | Autorizada |
| 1235 | Fictícia Serviços ME | 07/11/2026 | R$ 820,50 | Autorizada |
| Outubro de 2026 · 1 | ||||
| 1201 | Demo Consultoria | 28/10/2026 | R$ 3.200,00 | Cancelada |
<% notes = [
{ number: 1234, client: "Empresa Exemplo Ltda", issued_on: "05/11/2026", value: "R$ 1.500,00", status: :ok, month: "Novembro de 2026" },
{ number: 1235, client: "Fictícia Serviços ME", issued_on: "07/11/2026", value: "R$ 820,50", status: :ok, month: "Novembro de 2026" },
{ number: 1201, client: "Demo Consultoria", issued_on: "28/10/2026", value: "R$ 3.200,00", status: :bad, month: "Outubro de 2026" }
] %>
<%= table(rows: notes, min_width: "640px", group_by: ->(note) { note[:month] },
row_href: ->(note) { "#nota-#{note[:number]}" }, current: ->(note) { note[:number] == 1235 }) do |t| %>
<% t.column("Número") { |note| note[:number] } %>
<% t.column("Tomador") { |note| note[:client] } %>
<% t.column("Emissão") { |note| note[:issued_on] } %>
<% t.column("Valor", align: :right) { |note| note[:value] } %>
<% t.column("Situação") do |note| %>
<%= status_dot note[:status], style: "margin-right: 7px" %><%= note[:status] == :ok ? "Autorizada" : "Cancelada" %>
<% end %>
<% end %>
Collapsible groups
With collapsible: true each group header becomes a button that folds its rows away (the chevron turns). collapsed: lists the groups that start folded. Each group is its own <tbody>, so folding works without moving rows around.
| Missão | Data |
|---|---|
| Revisar roteiro do vídeo 2 | 20/11/2026 |
| Editar vídeo 2 | 21/11/2026 |
| Publicar vídeo 2 | 27/11/2026 |
| Follow-up com a Demo Consultoria | 24/11/2026 |
| Publicar landing do emissor | 23/11/2026 |
| Emitir invoice de novembro | 20/11/2026 |
<% missions = [
{ title: "Revisar roteiro do vídeo 2", project: "Canal Exemplo", due_on: "20/11/2026" },
{ title: "Editar vídeo 2", project: "Canal Exemplo", due_on: "21/11/2026" },
{ title: "Publicar vídeo 2", project: "Canal Exemplo", due_on: "27/11/2026" },
{ title: "Follow-up com a Demo Consultoria", project: "Produto Exemplo", due_on: "24/11/2026" },
{ title: "Publicar landing do emissor", project: "Produto Exemplo", due_on: "23/11/2026" },
{ title: "Emitir invoice de novembro", project: "Cliente Fictício", due_on: "20/11/2026" }
] %>
<%= table(rows: missions, group_by: ->(m) { m[:project] }, collapsible: true, collapsed: [ "Cliente Fictício" ]) do |t| %>
<% t.column("Missão") { |m| m[:title] } %>
<% t.column("Data", align: :right) { |m| m[:due_on] } %>
<% end %>
Selection, status and row actions
A column header can be any markup, like a select-all checkbox. Put row actions in a narrow right-aligned last column as icon buttons with labels that name the record.
| Empresa | Tipo | Validade | Situação | ||
|---|---|---|---|---|---|
| Empresa Exemplo Ltda | A1 | 14/03/2027 | Válido | ||
| Demo Consultoria | A1 | 04/12/2026 | Vence em 12 dias | ||
| Loja Modelo Eireli | A3 | 02/09/2026 | Vencido |
<% certificates = [
{ company: "Empresa Exemplo Ltda", kind: "A1", expires_on: "14/03/2027", status: :ok, label: "Válido" },
{ company: "Demo Consultoria", kind: "A1", expires_on: "04/12/2026", status: :warn, label: "Vence em 12 dias" },
{ company: "Loja Modelo Eireli", kind: "A3", expires_on: "02/09/2026", status: :bad, label: "Vencido" }
] %>
<%= table(rows: certificates, min_width: "720px") do |t| %>
<% t.column(check_box_tag("all", "1", false, class: "tr-check", aria: { label: "Selecionar todos" }), width: "44px") do |c| %>
<%= check_box_tag "ids[]", c[:company], false, class: "tr-check", id: nil, aria: { label: "Selecionar #{c[:company]}" } %>
<% end %>
<% t.column("Empresa") { |c| c[:company] } %>
<% t.column("Tipo") { |c| c[:kind] } %>
<% t.column("Validade") { |c| c[:expires_on] } %>
<% t.column("Situação") { |c| status_pill c[:label], status: c[:status] } %>
<% t.column("", align: :right, width: "96px") do |c| %>
<%= icon_button "refresh", label: "Trocar certificado de #{c[:company]}" %>
<%= icon_button "trash", label: "Remover #{c[:company]}", variant: :danger %>
<% end %>
<% end %>
Without data
With no rows the table keeps its header, so it still reads as a table, and shows an empty state across the body. empty: takes a plain sentence (first card); t.empty { … } takes any markup, usually an empty_state with an icon, a description that names the filter and a way out (second card).
Notas emitidas
Só com o texto padrão
| Número | Tomador | Emissão | Valor |
|---|---|---|---|
Nenhuma nota por aqui. | |||
Notas emitidas
Com um empty state completo
| Número | Tomador | Emissão | Valor |
|---|---|---|---|
| Nenhuma nota neste filtro Nenhuma nota emitida entre 01/11 e 30/11 para Demo Consultoria. | |||
<%= stack do %>
<%= card(title: "Notas emitidas", subtitle: "Só com o texto padrão", flush: true) do %>
<%= table(rows: [], empty: "Nenhuma nota por aqui.") do |t| %>
<% t.column("Número") { |note| note } %>
<% t.column("Tomador") { |note| note } %>
<% t.column("Emissão") { |note| note } %>
<% t.column("Valor", align: :right) { |note| note } %>
<% end %>
<% end %>
<%= card(title: "Notas emitidas", subtitle: "Com um empty state completo", flush: true) do %>
<%= table(rows: []) do |t| %>
<% t.column("Número") { |note| note } %>
<% t.column("Tomador") { |note| note } %>
<% t.column("Emissão") { |note| note } %>
<% t.column("Valor", align: :right) { |note| note } %>
<% t.empty do %>
<%= empty_state "Nenhuma nota neste filtro", icon: "file-search",
description: "Nenhuma nota emitida entre 01/11 e 30/11 para Demo Consultoria." do |e| %>
<% e.with_action { button "Limpar filtros", icon: "filter-off" } %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
In a card, with pagination
card(flush: true) lets the table fill the card edge to edge; pagination goes in the card footer.
Últimas notas
Página 2 de 12
| Número | Tomador | Valor |
|---|---|---|
| 1239 | Fictícia Serviços ME | R$ 310,00 |
| 1238 | Demo Consultoria | R$ 620,00 |
| 1237 | Empresa Exemplo Ltda | R$ 930,00 |
| 1236 | Fictícia Serviços ME | R$ 1240,00 |
| 1235 | Demo Consultoria | R$ 1550,00 |
<% rows = (1..5).map { |i| { number: 1240 - i, client: [ "Empresa Exemplo Ltda", "Fictícia Serviços ME", "Demo Consultoria" ][i % 3], value: "R$ #{i * 310},00" } } %>
<%= card(title: "Últimas notas", subtitle: "Página 2 de 12", flush: true) do |c| %>
<% c.with_action { button "Ver todas", size: :sm, href: "#notas" } %>
<%= table(rows: rows) do |t| %>
<% t.column("Número") { |n| n[:number] } %>
<% t.column("Tomador") { |n| n[:client] } %>
<% t.column("Valor", align: :right) { |n| n[:value] } %>
<% end %>
<% c.with_footer do %>
<%= pagination page: 2, pages: 12, url: ->(page) { "?page=#{page}" } %>
<% end %>
<% end %>
Options
| Option | What it does |
|---|---|
rows | Any enumerable |
row_href | Lambda row → URL; the row becomes a link |
current | Lambda row → true for the row whose drawer is open |
group_by | Lambda row → group label |
collapsible | Group headers fold and unfold their rows |
collapsed | Group labels that start folded |
empty | Sentence shown when there are no rows (or use t.empty { … }) |
min_width | CSS width that keeps columns readable; the table scrolls inside its box |