TermUI.Widgets.Table.Column (TermUI v0.2.0)
View SourceColumn specification for Table widget.
Defines how a column is displayed and how data is extracted from rows.
Usage
Column.new(:name, "Name")
Column.new(:age, "Age", width: Constraint.length(10))
Column.new(:status, "Status", render: &format_status/1)Width Constraints
Columns support the full constraint system:
Constraint.length(20)- Fixed 20 cellsConstraint.ratio(2)- Proportional shareConstraint.percentage(50)- 50% of availableConstraint.fill()- Take remaining space
Custom Renderers
The render function transforms the cell value to a string:
Column.new(:date, "Date", render: fn date ->
Calendar.strftime(date, "%Y-%m-%d")
end)
Summary
Functions
Aligns text within a given width.
Creates a new column specification.
Extracts and renders the cell value from a row.
Types
Functions
@spec align_text(String.t(), non_neg_integer(), :left | :center | :right) :: String.t()
Aligns text within a given width.
Parameters
text- The text to alignwidth- The available widthalign- Alignment (:left, :center, :right)
Returns
The aligned text, padded to width.
Creates a new column specification.
Parameters
key- The map key to extract from row dataheader- The header text to displayopts- Additional options
Options
:width- Width constraint (default:Constraint.fill()):render- Custom render function (default:to_string/1):sortable- Whether column can be sorted (default: true):align- Text alignment :left, :center, :right (default: :left)
Examples
Column.new(:name, "Name")
Column.new(:age, "Age", width: Constraint.length(10), align: :right)
Extracts and renders the cell value from a row.
Parameters
column- The column specificationrow- The row data (map or struct)
Returns
The rendered string value for the cell.
Examples
column = Column.new(:name, "Name")
Column.render_cell(column, %{name: "Alice"})
# => "Alice"