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 ¶
- func DataTable(opts ...DataTableOption) g.Node
- func Table(opts ...Option) func(...g.Node) g.Node
- func TableBody(opts ...BodyOption) func(...g.Node) g.Node
- func TableCaption(opts ...Option) func(...g.Node) g.Node
- func TableCell(opts ...CellOption) func(...g.Node) g.Node
- func TableFooter(opts ...Option) func(...g.Node) g.Node
- func TableHeader(opts ...HeaderOption) func(...g.Node) g.Node
- func TableHeaderCell(opts ...CellOption) func(...g.Node) g.Node
- func TableRow(opts ...RowOption) func(...g.Node) g.Node
- type Alignment
- type BodyOption
- type BodyProps
- type CellOption
- type CellProps
- type Column
- type DataTableOption
- type DataTableProps
- type FilterOption
- type HeaderOption
- type HeaderProps
- type Option
- type Props
- type RowOption
- type RowProps
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 ¶
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 ¶
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 ¶
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"))
Types ¶
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 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.
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 ¶
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 ¶
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 ¶
HeaderProps defines the properties for the TableHeader component.
type Option ¶
type Option func(*Props)
Option is a functional option for configuring 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 ¶
WithOnClick adds a click handler to the row.
func WithRowAttr ¶
WithRowAttr adds custom HTML attributes to the table row.
func WithRowClass ¶
WithRowClass adds additional CSS classes to the table row.