Help us shape the future of Go! Take the 2026 Go Developer Survey

datatable

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package datatable renders a server-driven table (REQ-REG-10). Sort, filter and paging state live in typed GET routes; the component only renders one page and links the next one.

Index

Constants

This section is empty.

Variables

View Source
var DataTableFixtures = gx.Fixtures[DataTableProps[FixtureRow]]{
	"Three": {
		Columns: FixtureColumns,
		Rows:    []FixtureRow{{Name: "Alpha", Total: 10}, {Name: "Beta", Total: 20}, {Name: "Gamma", Total: 30}},
		Page:    Page{Number: 1, Size: 10, Total: 3},
		Href:    FixtureHref,
	},
	"Empty": {
		Columns: FixtureColumns,
		Page:    Page{Number: 1, Size: 10, Total: 0},
		Href:    FixtureHref,
	},
}
View Source
var FixtureColumns = []Column[FixtureRow]{
	{Key: "name", Label: "Name", Sort: "name", Cell: func(r FixtureRow) gx.Node { return gx.Text(r.Name) }},
	{Key: "total", Label: "Total", Cell: func(r FixtureRow) gx.Node { return gx.Text(strconv.Itoa(r.Total)) }},
}

FixtureColumns are the columns of the data table fixtures. The name column is a sort link.

Functions

func DataTable

func DataTable[T any](p DataTableProps[T]) gx.Node

DataTable renders one page of a server-driven table with sortable headers and paging links (REQ-REG-10).

func FixtureHref

func FixtureHref(sort, dir string, page int) gx.URL

FixtureHref is the Href of the data table fixtures. An app returns its own typed route here.

Types

type Column

type Column[T any] struct {
	// Key identifies the column in the row data.
	Key string
	// Label is the visible header text.
	Label string
	// Cell renders one cell.
	Cell func(T) gx.Node
	// Sort is the query value of the column when the header is a sort
	// link. Empty makes the column unsortable.
	Sort string
}

Column is one typed column of a data table.

type DataTableProps

type DataTableProps[T any] struct {
	// Columns are the typed columns, in display order.
	Columns []Column[T]
	// Rows are the rows of the current page.
	Rows []T
	// Page is the paging state: the page number, the page size and the
	// total row count.
	Page Page
	// Sort is the Sort value of the column the rows are sorted by. Empty
	// means no sort.
	Sort string
	// Dir is the sort direction: "asc" or "desc".
	Dir string
	// Href builds the URL of a sort link and of a paging link.
	Href Href
	// Empty renders in place of the rows when the page holds none.
	Empty gx.Node
}

DataTableProps holds one rendered table.

type FixtureRow

type FixtureRow struct {
	Name  string
	Total int
}

FixtureRow is the row type of the data table fixtures.

type Href

type Href func(sort, dir string, page int) gx.URL

Href builds the typed GET URL of one table state. The app returns its own route value, so the query stays typed.

type Page

type Page struct {
	Number int
	Size   int
	Total  int
}

Page is the paging state of one table render.

Jump to

Keyboard shortcuts

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