table

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package table provides table components for displaying tabular data.

It includes both basic semantic HTML table elements and an interactive DataTable component with sorting, filtering, and pagination capabilities.

Basic Usage

table.Table(
    table.TableHeader(
        table.TableRow(
            table.TableHeaderCell(g.Text("Name")),
            table.TableHeaderCell(g.Text("Email")),
        ),
    ),
    table.TableBody(
        table.TableRow(
            table.TableCell(g.Text("John Doe")),
            table.TableCell(g.Text("john@example.com")),
        ),
    ),
)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DataTable

func DataTable(opts ...DataTableOption) g.Node

DataTable creates an interactive data table with sorting, filtering, and pagination.

Example:

table.DataTable(
    table.WithColumns(
        table.Column{Key: "name", Label: "Name", Sortable: true},
        table.Column{Key: "email", Label: "Email"},
        table.Column{
            Key: "status",
            Label: "Status",
            Filterable: true,
            FilterOptions: []table.FilterOption{
                {Value: "active", Label: "Active"},
                {Value: "inactive", Label: "Inactive"},
            },
        },
    ),
    table.WithData(userData),
    table.WithPagination(),
    table.WithPageSize(20),
)

func Table

func Table(opts ...Option) func(...g.Node) g.Node

Table creates a table component with responsive container.

The table uses semantic HTML elements with proper accessibility attributes. It's wrapped in a responsive container that enables horizontal scrolling on mobile devices.

Example:

table.Table(
    table.TableHeader(...),
    table.TableBody(...),
    table.WithClass("my-custom-table"),
)

func TableBody

func TableBody(opts ...BodyOption) func(...g.Node) g.Node

TableBody creates a table body (tbody) element.

Example:

table.TableBody()(
    table.TableRow()(
        table.TableCell(g.Text("Data 1")),
        table.TableCell(g.Text("Data 2")),
    ),
)

func TableCaption

func TableCaption(opts ...Option) func(...g.Node) g.Node

TableCaption creates a table caption element.

Example:

table.TableCaption()(g.Text("A list of your recent invoices."))

func TableCell

func TableCell(opts ...CellOption) func(...g.Node) g.Node

TableCell creates a table data cell (td) element.

Example:

table.TableCell(
    table.WithAlign(table.AlignRight),
    table.WithWidth("200px"),
)(g.Text("Cell content"))

func TableFooter

func TableFooter(opts ...Option) func(...g.Node) g.Node

TableFooter creates a table footer (tfoot) element.

Example:

table.TableFooter()(
    table.TableRow(
        table.TableCell(g.Text("Total")),
        table.TableCell(g.Text("$100")),
    ),
)

func TableHeader

func TableHeader(opts ...HeaderOption) func(...g.Node) g.Node

TableHeader creates a table header (thead) element.

Example:

table.TableHeader(
    table.TableRow(
        table.TableHeaderCell(g.Text("Column 1")),
        table.TableHeaderCell(g.Text("Column 2")),
    ),
    table.StickyHeader(),
)

func TableHeaderCell

func TableHeaderCell(opts ...CellOption) func(...g.Node) g.Node

TableHeaderCell creates a table header cell (th) element.

Example:

table.TableHeaderCell(
    table.WithAlign(table.AlignCenter),
)(g.Text("Column Header"))

func TableRow

func TableRow(opts ...RowOption) func(...g.Node) g.Node

TableRow creates a table row (tr) element.

Example:

table.TableRow(table.WithOnClick("handleRowClick()"))(
    table.TableCell(g.Text("Cell 1")),
    table.TableCell(g.Text("Cell 2")),
)

Types

type Alignment

type Alignment string

Alignment represents the text alignment in a table cell.

const (
	AlignLeft   Alignment = "left"
	AlignCenter Alignment = "center"
	AlignRight  Alignment = "right"
)

type BodyOption

type BodyOption func(*BodyProps)

BodyOption is a functional option for configuring the TableBody component.

func WithBodyAttr

func WithBodyAttr(attrs ...g.Node) BodyOption

WithBodyAttr adds custom HTML attributes to the table body.

func WithBodyClass

func WithBodyClass(class string) BodyOption

WithBodyClass adds additional CSS classes to the table body.

type BodyProps

type BodyProps struct {
	Class string
	Attrs []g.Node
}

BodyProps defines the properties for the TableBody component.

type CellOption

type CellOption func(*CellProps)

CellOption is a functional option for configuring table cells.

func WithAlign

func WithAlign(align Alignment) CellOption

WithAlign sets the text alignment for the cell.

func WithCellAttr

func WithCellAttr(attrs ...g.Node) CellOption

WithCellAttr adds custom HTML attributes to the cell.

func WithCellClass

func WithCellClass(class string) CellOption

WithCellClass adds additional CSS classes to the cell.

func WithWidth

func WithWidth(width string) CellOption

WithWidth sets the width of the cell.

type CellProps

type CellProps struct {
	Class string
	Align Alignment
	Width string
	Attrs []g.Node
}

CellProps defines the properties for table cell components.

type Column

type Column struct {
	Key           string
	Label         string
	Sortable      bool
	Filterable    bool
	FilterOptions []FilterOption
	Width         string
	Align         Alignment
}

Column represents a column configuration for DataTable.

type DataTableOption

type DataTableOption func(*DataTableProps)

DataTableOption is a functional option for configuring the DataTable component.

func WithColumns

func WithColumns(columns ...Column) DataTableOption

WithColumns sets the columns for the data table.

func WithData

func WithData(data []map[string]any) DataTableOption

WithData sets the data for the data table.

func WithDataTableAttr

func WithDataTableAttr(attrs ...g.Node) DataTableOption

WithDataTableAttr adds custom HTML attributes to the data table container.

func WithDataTableClass

func WithDataTableClass(class string) DataTableOption

WithDataTableClass adds additional CSS classes to the data table container.

func WithPageSize

func WithPageSize(size int) DataTableOption

WithPageSize sets the number of items per page.

func WithPagination

func WithPagination() DataTableOption

WithPagination enables pagination for the data table.

type DataTableProps

type DataTableProps struct {
	Columns        []Column
	Data           []map[string]any
	PageSize       int
	ShowPagination bool
	Class          string
	Attrs          []g.Node
}

DataTableProps defines the properties for the DataTable component.

type FilterOption

type FilterOption struct {
	Value string
	Label string
}

FilterOption represents a filter option for a column.

type HeaderOption

type HeaderOption func(*HeaderProps)

HeaderOption is a functional option for configuring the TableHeader component.

func StickyHeader() HeaderOption

StickyHeader makes the table header sticky on scroll.

func WithHeaderAttr

func WithHeaderAttr(attrs ...g.Node) HeaderOption

WithHeaderAttr adds custom HTML attributes to the table header.

func WithHeaderClass

func WithHeaderClass(class string) HeaderOption

WithHeaderClass adds additional CSS classes to the table header.

type HeaderProps

type HeaderProps struct {
	Class  string
	Sticky bool
	Attrs  []g.Node
}

HeaderProps defines the properties for the TableHeader component.

type Option

type Option func(*Props)

Option is a functional option for configuring the Table component.

func Bordered

func Bordered() Option

Bordered adds borders to all table cells.

func Hover

func Hover() Option

Hover enables hover effect on table rows.

func Striped

func Striped() Option

Striped applies alternating row background colors.

func WithAttr

func WithAttr(attrs ...g.Node) Option

WithAttr adds custom HTML attributes to the table.

func WithClass

func WithClass(class string) Option

WithClass adds additional CSS classes to the table.

type Props

type Props struct {
	Class    string
	Striped  bool
	Bordered bool
	Hover    bool
	Attrs    []g.Node
}

Props defines the properties for the Table component.

type RowOption

type RowOption func(*RowProps)

RowOption is a functional option for configuring the TableRow component.

func ClickableRow

func ClickableRow() RowOption

ClickableRow makes the row clickable with a cursor pointer.

func WithOnClick

func WithOnClick(handler string) RowOption

WithOnClick adds a click handler to the row.

func WithRowAttr

func WithRowAttr(attrs ...g.Node) RowOption

WithRowAttr adds custom HTML attributes to the table row.

func WithRowClass

func WithRowClass(class string) RowOption

WithRowClass adds additional CSS classes to the table row.

type RowProps

type RowProps struct {
	Class     string
	Clickable bool
	OnClick   string
	Attrs     []g.Node
}

RowProps defines the properties for the TableRow component.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL