class RatatuiRuby::Table
Displays structured data in rows and columns.
Data is often multidimensional. You need to show relationships between fields (Name, Age, ID). Aligning columns manually in a monospaced environment is painful and error-prone.
This widget creates a grid. It enforces column widths using constraints. It renders headers, rows, and footers aligned perfectly.
Use it to display database records, logs, or file lists.
Examples
Table.new( header: ["ID", "Name", "Status"], rows: [ ["1", "Hideo", "Active"], ["2", "Kojima", "Idle"] ], widths: [ Constraint.length(5), Constraint.fill(1), Constraint.length(10) ] )
Attributes
Optional wrapping block.
Style for the selected cell (intersection of row and column).
Style for the selected column.
Spacing between columns (Integer, default 1).
Flex mode for column distribution.
Header row content (Array of Strings).
When to show the highlight symbol column (:always, :when_selected, :never).
Style for the selected row.
Symbol for the selected row.
Data rows (Array of Arrays of Strings).
Index of the selected column (Integer or nil).
Index of the selected row (Integer or nil).
Base style for the entire table.
Column width constraints (Array of Constraint).
Public Class Methods
Source
# File lib/ratatui_ruby/schema/table.rb, line 108 def initialize(header: nil, rows: [], widths: [], highlight_style: nil, highlight_symbol: "> ", highlight_spacing: :when_selected, column_highlight_style: nil, cell_highlight_style: nil, selected_row: nil, selected_column: nil, block: nil, footer: nil, flex: :legacy, style: nil, column_spacing: 1) super( header: header, rows: rows, widths: widths, highlight_style: highlight_style, highlight_symbol: highlight_symbol, highlight_spacing: highlight_spacing, column_highlight_style: column_highlight_style, cell_highlight_style: cell_highlight_style, selected_row: selected_row.nil? ? nil : Integer(selected_row), selected_column: selected_column.nil? ? nil : Integer(selected_column), block: block, footer: footer, flex: flex, style: style, column_spacing: Integer(column_spacing) ) end
Creates a new Table.
- header
-
Array of strings/paragraphs.
- rows
-
2D Array of strings/paragraphs.
- widths
-
Array of Constraints.
highlight_style-
Styleobject. highlight_symbol-
String.
highlight_spacing-
Symbol (optional, default:
:when_selected). column_highlight_style-
Styleobject. cell_highlight_style-
Styleobject. selected_row-
Integer (nullable).
selected_column-
Integer (nullable).
- block
-
Block(optional). - footer
-
Array of strings/paragraphs (optional).
- flex
-
Symbol (optional, default:
:legacy). - style
-
Styleobject or Hash (optional). column_spacing-
Integer (optional, default: 1).