package pagination import "git.haelnorr.com/h/oslstats/internal/db" import "fmt" // TableColumn defines a sortable column in a paginated table type TableColumn struct { Field string // database field name for sorting (e.g., "created_at") Label string // display label (e.g., "Timestamp") Sortable bool // whether this column can be sorted } // TableHeader renders a table header with sortable columns // Use this inside ... templ TableHeader(opts db.PageOpts, columns []TableColumn) { for _, col := range columns { if col.Sortable { @sortableHeaderCell(col.Field, col.Label, opts.OrderBy, string(opts.Order)) } else { { col.Label } } } } templ sortableHeaderCell(field string, label string, currentField string, currentOrder string) { {{ isActive := currentField == field baseClasses := "px-4 py-3 text-left text-sm font-semibold text-text cursor-pointer select-none hover:text-blue transition-colors" arrow := "" if isActive { if currentOrder == "ASC" { arrow = " ↑" } else { arrow = " ↓" } } }} { label } if arrow != "" { { arrow } } }