Sorting
Model
type Sort struct {
ID string `json:"id"`
Desc bool `json:"desc"`
}
Slice order = SQL precedence (primary sort first).
Mapping
sortMap := datatable.SortColumnNameByID(columns)
// only EnableSorting: true; uses SortSQLColumn when set
order := datatable.OrderByClause(q.Sorts, sortMap)
// " ORDER BY email DESC, name ASC"
postgresql.Find applies GORM .Order() per sort entry.
FindRaw appends OrderByClause to the built SQL.
Example request
sorting=[{"id":"created_at","desc":true},{"id":"email","desc":false}]
Tips
- Hidden id columns can still be sortable (
Hidden: true,EnableSorting: true). - Unknown sort IDs are ignored during parse.
- For display expressions, set
SortSQLColumnto a stable indexed column when possible.