Skip to content

Table

Table lays out rows and columns with a header, dividers and rounded borders. Cells contain arbitrary views and can span rows and columns, rows and cells can be clicked. For collections with search, sorting and selection, use the Data View.

Table

func view(wnd core.Window) core.View {
    type order struct {
        ID, Customer, Status, Total string
    }

    orders := []order{
        {"#1042", "Ada Lovelace", "Shipped", "129.00 €"},
        {"#1043", "Grace Hopper", "Processing", "48.50 €"},
        {"#1044", "Alan Turing", "Delivered", "312.20 €"},
    }

    return Table(
        TableColumn(Text("Order")),
        TableColumn(Text("Customer")),
        TableColumn(Text("Status")),
        TableColumn(Text("Total")).Alignment(Trailing),
    ).Rows(
        ForEach(orders, func(o order) TTableRow {
            return TableRow(
                TableCell(Text(o.ID)),
                TableCell(Text(o.Customer)),
                TableCell(Text(o.Status)),
                TableCell(Text(o.Total)).Alignment(Trailing),
            ).Action(func() {
                // open the order
            }).HoveredBackgroundColor(ColorCardFooter)
        })...,
    ).
        CellPadding(Padding{}.Horizontal(L16).Vertical(L12)).
        Border(Border{}.Radius(L16)).
        Frame(Frame{Width: L560})
}

Constructors

func Table(columns ...TTableColumn) TTable

Table creates a new table with the specified columns and default styling.

Methods

MethodDescription
BackgroundColor(backgroundColor Color) TTableBackgroundColor sets the background color of the table.
Border(border Border) TTableBorder sets the border of the table.
CellPadding(padding Padding) TTableCellPadding sets the default cell padding for all cells.
Columns(columns ...TTableColumn) TTableColumns replaces the columns of the table.
Frame(frame Frame) TTableFrame sets the frame of the table.
HeaderDividerColor(color Color) TTableHeaderDividerColor sets the divider color between header and body.
RowDividerColor(color Color) TTableRowDividerColor sets the divider color between rows.
Rows(rows ...TTableRow) TTableRows appends one or more rows to the table.

Related