func Render
Render generates a Markdown table from a Table struct with sortable columns based on URL params. paramPrefix is an optional prefix for in the URL to identify the tablesort Renders (e.g. "members-").
Package tablesort provides functionality to render a Markdown table with sortable columns. It allows users to click o...
tablesort - Sortable markdown tablesGenerate sortable markdown tables with clickable column headers. Sorting state is managed via URL query parameters.
1import "gno.land/p/samcrew/tablesort"
2
3table := &tablesort.Table{
4 Headings: []string{"Name", "Age", "City"},
5 Rows: [][]string{
6 {"Alice", "25", "New York"},
7 {"Bob", "30", "London"},
8 {"Charlie", "22", "Paris"},
9 },
10}
11
12// Basic usage
13u, _ := url.Parse("/users")
14markdown := tablesort.Render(u, table, "")
15
16// Multiple tables on same page (use prefix to avoid conflicts)
17markdown1 := tablesort.Render(u, table, "table1-")
18markdown2 := tablesort.Render(u, table, "table2-")
1type Table struct {
2 Headings []string // Column headers
3 Rows [][]string // Table data rows
4}
5
6// `u`: Current URL for generating sort links
7// `table`: Table data structure
8// `paramPrefix`: Prefix for URL params (use for multiple tables)
9func Render(u *url.URL, table *Table, paramPrefix string) string
URL Parameters:
{prefix}sort-asc={column}: Sort column ascending{prefix}sort-desc={column}: Sort column descendingURL Examples:
/users?sort-desc=Name - Sort by Name descending/page?users-sort-asc=Age&orders-sort-desc=Total - Multiple tablesPackage tablesort provides functionality to render a Markdown table with sortable columns. It allows users to click on column headers to sort the table in ascending or descending sort direction. The sorting state is managed via URL query parameters. It displays an error if the table is malformed (e.g. rows with missing cells). Multiple tablesort can be rendered on the same page by using a paramPrefix for each Render (See the Render function).