/p/samcrew/tablesort
Directory ยท 5 Files
tablesort
- Sortable markdown tables
Generate sortable markdown tables with clickable column headers. Sorting state is managed via URL query parameters.
Usage
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-")
On-chain Example
API
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 descending
URL Examples:
/users?sort-desc=Name
- Sort by Name descending/page?users-sort-asc=Age&orders-sort-desc=Total
- Multiple tables