Table API Reference
Complete reference for the Table type and its methods.
Table Type
type Table struct {
// Internal fields (not directly accessible)
}The Table type represents a basic, non-paginated table window. For datasets with more than 100 rows, consider using PaginatedTable instead.
Constructor Functions
New()
Creates a new table with a given title.
func New(title string) *TableParameters:
title(string): The window title
Returns:
*Table: A new table instance
Example:
table := gotableview.New("My Table")
table.Columns("Name", "Age").Row("Alice", "30").Show()Configuration Methods
Columns()
Sets the column headers for the table.
func (t *Table) Columns(cols ...string) *TableParameters:
cols(...string): Variable number of column names
Returns:
*Table: The table instance (for method chaining)
Example:
table.Columns("Name", "Email", "Phone")Alias
ColumnNames() is an alias for Columns() and works identically.
ColumnNames()
Alias for Columns(). Sets the column headers.
func (t *Table) ColumnNames(names ...string) *TableParameters:
names(...string): Variable number of column names
Returns:
*Table: The table instance
Example:
table.ColumnNames("First Name", "Last Name", "Age")ColumnWidths()
Sets custom widths for columns in pixels.
func (t *Table) ColumnWidths(widths ...int) *TableParameters:
widths(...int): Width in pixels for each column
Returns:
*Table: The table instance
Important:
- Number of widths must match number of columns
- If count doesn't match, auto-sizing is used instead
- Widths are in pixels
Example:
table.Columns("ID", "Name", "Description", "Price").
ColumnWidths(50, 150, 300, 100).
Row("1", "Product", "Long description...", "$99.99").
Show()Data Methods
Row()
Adds a single row of data to the table.
func (t *Table) Row(values ...string) *TableParameters:
values(...string): Variable number of cell values (must be strings)
Returns:
*Table: The table instance
Important:
- Number of values should match number of columns
- All values must be strings (convert other types first)
Example:
table.Row("Alice", "30", "NYC")
table.Row("Bob", "25", "LA")Rows()
Adds multiple rows of data at once.
func (t *Table) Rows(data [][]string) *TableParameters:
data([][]string): 2D slice of strings representing rows
Returns:
*Table: The table instance
Example:
data := [][]string{
{"Alice", "30", "NYC"},
{"Bob", "25", "LA"},
{"Carol", "28", "Chicago"},
}
table.Rows(data)Font Customization
HeaderFont()
Sets a custom font for table headers.
func (t *Table) HeaderFont(name string, size int, bold, italic bool) *TableParameters:
name(string): Font name (e.g., "Arial", "Courier New")size(int): Font size in pointsbold(bool): Whether font should be bolditalic(bool): Whether font should be italic
Returns:
*Table: The table instance
Example:
table.HeaderFont("Arial", 12, true, false). // Bold Arial 12pt
Columns("Name", "Age").
Row("Alice", "30").
Show()ContentFont()
Sets a custom font for table content (data rows).
func (t *Table) ContentFont(name string, size int, bold, italic bool) *TableParameters:
name(string): Font namesize(int): Font size in pointsbold(bool): Whether font should be bolditalic(bool): Whether font should be italic
Returns:
*Table: The table instance
Example:
table.ContentFont("Courier New", 10, false, false). // Regular Courier 10pt
Columns("Code", "Value").
Row("ABC123", "42").
Show()Display Method
Show()
Displays the table window and blocks until the window is closed.
func (t *Table) Show()Parameters:
- None
Returns:
- None (void)
Important:
- This method blocks - code after it won't run until window closes
- Must be called last in the method chain
- Only call once per table
Example:
table.Columns("A", "B").Row("1", "2").Show()
// This line runs after the window closes
fmt.Println("Table was closed")Complete Example
package main
import "github.com/mansoldof/goTableView"
func main() {
// Create table with all features
gotableview.New("Employee Directory").
Columns("ID", "Name", "Department", "Salary").
ColumnWidths(60, 180, 150, 120).
HeaderFont("Arial", 11, true, false).
ContentFont("Segoe UI", 10, false, false).
Row("001", "Alice Johnson", "Engineering", "$75,000").
Row("002", "Bob Smith", "Sales", "$60,000").
Row("003", "Carol White", "Marketing", "$65,000").
Show()
}Method Chaining
All methods (except Show()) return *Table, allowing you to chain calls:
// Good - clean and readable ✅
gotableview.New("Title").
Columns("A", "B", "C").
Row("1", "2", "3").
Row("4", "5", "6").
Show()
// Also works, but less clean ❌
table := gotableview.New("Title")
table.Columns("A", "B", "C")
table.Row("1", "2", "3")
table.Row("4", "5", "6")
table.Show()Performance Notes
- Basic Table is optimized for up to ~100 rows
- For larger datasets, use
PaginatedTable - Column auto-sizing is calculated once when window is created
- Custom fonts may affect rendering speed slightly
See Also
- PaginatedTable API - For large datasets
- Helper Functions -
FromStructs(),FromMaps(), etc. - Basic Usage Guide
- Basic Examples