-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Description
In my project, I use info.AddField to add virtual (computed) columns to the list page that are not present in the database table — for example:
info.AddField("Groupe", "display_count", db.Varchar).
FieldDisplay(func(model types.FieldModel) interface{} {
cnt, _ := db.WithDriverAndConnection("default", condb).
Table("map_message_groups").
Where("message_id", "=", model.Row["uid"]).Count()
return cnt
}).
FieldSortable()The problem is:
FieldSortable()works only for real DB columns.- Virtual columns computed in
FieldDisplaycannot currently be sorted, because there is noFieldOrderBy()(or similar) API forAddFieldto define a custom SQL expression for ordering.
I want to keep these virtual columns without altering the database schema, but still allow server‑side sorting via a correlated subquery or custom SQL expression.
Impact:
- Common for dashboards to show counts or derived data without adding DB columns.
- Without this capability, sorting requires either:
- Fetching all rows and sorting in memory (slow, breaks pagination), or
- Creating extra DB columns just for ordering (undesirable for many projects).
Suggested enhancement:
- Add an API similar to
ColumnOrderByforAddField, e.g.:
.FieldOrderBy(func(order string, table string) string {
return fmt.Sprintf("(SELECT COUNT(1) FROM map_message_groups mg WHERE mg.message_id = %s.uid) %s", table, order)
})This would let developers provide a custom ORDER BY expression for non‑DB fields while keeping current pagination and efficiency.
Metadata
Metadata
Assignees
Labels
No labels