Backend
Lists and filters
Describe admin lists in config_list.yaml and columns.yaml, with search, sorting, pagination options and switch, date range and scope filters.
On this page
The List behaviour's config_list.yaml, the model's columns.yaml and the Filter widget's config_filter.yaml keep their WinterCMS shape. cabana compiles them at boot and runs every list query itself, so search, sort and filter parameters from the request apply only to what the YAML declares.
config_list.yaml#
list: ~/plugins/acme/blog/models/post/columns.yaml
modelClass: Post
title: acme.blog::lang.posts.title
recordUrl: acme/blog/posts/update/:id
recordsPerPage: 20
perPageOptions: [20, 50, 100]
showCheckboxes: true
defaultSort:
column: published_at
direction: desc
filter: config_filter.yaml
toolbar:
buttons: [create, delete]
search:
prompt: backend::lang.list.search_prompt
| Key | Sets |
|---|---|
list |
The columns file, with a WinterCMS ~/plugins/... path into the plugin. |
modelClass |
Must equal the controller's model name. |
title, noRecordsMessage |
Translation keys shown by the SPA. |
recordUrl |
Where a click on a row goes; :id is replaced. |
recordsPerPage, perPageOptions |
The page size and the sizes a user may pick. |
showCheckboxes, showSetup, showSorting, showSearch |
Which list controls appear. |
defaultSort |
column and direction of the initial order. |
toolbar |
buttons (the built-in create, delete and reorder and registered actions) and search.prompt. reorder needs a config_reorder.yaml; see Tree reorder. |
filter |
The filter file, relative to the controller's directory. |
headerPartial |
A server-rendered strip above the list; see Partials and widgets. |
bulkActions |
The bulk actions the list offers for the selected rows: a list of names the controller registers through pact.HasAdminBulkActions. Needs showCheckboxes: true. |
A declared bulk action runs on the selected rows in one transaction, after cabana resolved the posted ids through the list's own scope. A selection of which only a part is still in that scope (a row was deleted meanwhile, or lies outside pact.ListExtendQuery) answers 409 and changes nothing; the admin then reloads the list and asks for a new selection. See Bulk actions.
columns.yaml#
columns:
title:
label: acme.blog::lang.posts.title_column
searchable: true
published:
label: acme.blog::lang.posts.published
type: switch
published_at:
label: acme.blog::lang.posts.published_at
type: datetime
A column takes label, type (text, datetime, date, time, switch or money), searchable (default false) and sortable (default true, as in WinterCMS; false for a money column), and, for a column read through a relation, relation and select. Other WinterCMS column types and options are refused at boot, except the alias of a plugin field type, whose column shows the type's list text. When type is omitted, a time.Time column is datetime, a lagoon.Date column is date and a lagoon.TimeOfDay column is time; every other column stays untyped (the admin treats that as text). An explicit type always wins. A searchable relation column matches a record when any related record matches: a categories column with relation: categories and select: name on a blog post finds the posts with at least one matching category, for belongsTo, hasOne, hasMany and belongsToMany relations alike, each through a subquery, so a post is listed and counted once. A sortable hasMany or belongsToMany column sorts by its comma-joined values, the text the list shows. The compiled list keeps the columns in file order:
// The plugin embeds its controllers/ and models/ trees; the example reads
// the same files from testdata.
fsys := os.DirFS("testdata/docs")
list, err := cabana.CompileList("acme.blog", PostsController{}, fsys)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(list.Title, list.RecordsPerPage, list.PerPageOptions, list.ToolbarButtons)
for _, c := range list.Columns {
fmt.Printf("column %s type=%q searchable=%v sortable=%v\n", c.Key, c.Type, c.Searchable, c.Sortable)
}
for _, f := range list.Filters {
fmt.Printf("filter %s type=%s column=%s\n", f.Name, f.Type, f.Column)
}
// Output:
// acme.blog::lang.posts.title 20 [20 50 100] [create delete]
// column title type="" searchable=true sortable=true
// column published type="switch" searchable=false sortable=true
// column published_at type="datetime" searchable=false sortable=true
// filter published type=switch column=published
// filter published_at type=daterange column=published_at
type: date and type: time are for lagoon.Date and lagoon.TimeOfDay columns (a DATE and a TIME column): the admin shows the stored 2026-10-02 or 14:30:00 as it is, with no time zone conversion, where type: datetime would read a date as midnight UTC and could show the previous day. A struct that stores itself in one column (it implements sql.Scanner or driver.Valuer, as both types do) is a plain column, never a relation.
Money columns#
type: money shows an exact decimal amount column (the value of a money field) formatted by the administrator's locale with its ISO code: PLN 39.84 in English, 39,84 PLN in Polish, with at least two and at most four decimals, so a stored 85.4193 is shown in full. The column takes the same currency keys as the field, exactly one of them:
columns:
total:
label: acme.shop::lang.orders.total
type: money
currencyFrom: currency
fee:
label: acme.shop::lang.orders.fee
type: money
currency: EUR
currencyFromnames a string column of the model. Every list row then carries that column's value under its own key, even when the file does not declare it as a column, so the admin formats each row with that row's code; a row whose code is empty shows the amount alone.- A money column is not sortable unless the file says
sortable: true, and is never searchable:searchable: truestops the start-up, as do two currency sources, none, a code that is not three upper-case letters, acurrencyFromthat is not a string column, arelation, or a model column that is neither a string nor asql.Scanneranddriver.Valuertype. - The admin aligns the header and the cells of a money column to the right in tabular numerals and never wraps an amount; an empty value shows a muted dash. The schema reports
currencyorcurrencyFromon the column.
invisible: true keeps a column out of the table while it stays part of the list: the search covers it when it is searchable, it can still be sorted by, and the schema reports it with invisible. The admin SPA renders no header and no cell for it, and the rows of a list response do not carry its value. Use it for a column administrators search by but do not need to read, such as an e-mail address next to a name.
Search runs over the searchable columns only; sort accepts only sortable columns. A request that names any other column is refused, never passed to SQL.
Filters#
config_filter.yaml lists scopes. Three filter types are supported:
scopes:
published:
label: acme.blog::lang.posts.published
type: switch
column: published
published_at:
label: acme.blog::lang.posts.published_at
type: daterange
column: published_at
| Type | Filters |
|---|---|
switch |
A boolean column. With options, the two values are the options' keys, kept as typed scalars. |
daterange |
A date or timestamp column between two dates. |
scope (a scope key with modelClass and nameFrom) |
Records by a model-backed choice. The model implements pact.FilterScope, whose FilterScopes lists the scope names it answers. pact.FilterOptions serves the choices the SPA loads; the controller or the model implements it. |
The choices of a scope filter are asked from the controller first, when it implements pact.FilterOptions, and from the model otherwise. A model is a fresh value with no database handle, so choices that are rows of a table (the groups a user can be filtered by, for example) belong on the controller, which can hold the handle it was built with. The scope that filters the query is always the model's pact.FilterScope. A scope filter with no pact.FilterOptions on either stops the start-up.
WinterCMS conditions SQL fragments are not supported; use a column or a scope the model implements. A scope filter whose name the model does not list in FilterScopes stops the start-up, so request text can never select another method.
Computed columns#
A column can show a value that is not stored on the model, such as the e-mail of a record's owner kept in another table. The model declares the field with a gorm - tag and a column name, and the controller implements pact.ListExtendRecords, which the framework calls once per list page, after the records are loaded and before their columns are read, with the page's records and the list's database handle. One query fills the field for the whole page, as WinterCMS's listExtendRecords does:
package cabana_test
import (
"context"
"git.golem15.com/golem15/summercms/modules/pact"
"gorm.io/gorm"
)
// Ticket is a support ticket. OwnerEmail is not stored: the list's
// owner_email column shows what ListExtendRecords puts there.
type Ticket struct {
ID uint `gorm:"column:id;primaryKey"`
OwnerID uint `gorm:"column:owner_id"`
OwnerEmail string `gorm:"-:all;column:owner_email"`
}
// TicketsController is an admin controller with a computed column.
type TicketsController struct{}
var _ pact.ListExtendRecords = TicketsController{}
// ListExtendRecords fills the owner e-mails of one list page with one
// query. The framework calls it once per page, before the columns are read.
func (TicketsController) ListExtendRecords(ctx context.Context, db *gorm.DB, records []any) error {
ids := make([]uint, 0, len(records))
for _, record := range records {
ids = append(ids, record.(*Ticket).OwnerID)
}
var owners []struct {
ID uint
Email string
}
if err := db.WithContext(ctx).Table("acme_owners").Select("id, email").Where("id IN ?", ids).Scan(&owners).Error; err != nil {
return err
}
emails := make(map[uint]string, len(owners))
for _, owner := range owners {
emails[owner.ID] = owner.Email
}
for _, record := range records {
ticket := record.(*Ticket)
ticket.OwnerEmail = emails[ticket.OwnerID]
}
return nil
}
columns:
owner_email:
label: acme.helpdesk::lang.tickets.owner_email
Such a column is never sorted or searched: it compiles unsortable, and sortable: true or searchable: true on it stops the start-up. An error from the hook fails the list.
Row state#
A list can mark rows with a state, as a WinterCMS list does with listInjectRowClass: a deleted record, a blocked account, an inactive one. The controller implements pact.ListRowStates:
package cabana_test
import (
"context"
"git.golem15.com/golem15/summercms/modules/pact"
"gorm.io/gorm"
)
var _ pact.ListRowStates = PeopleController{}
// ListRowStates marks the rows of one list page. The framework calls it once
// per page with the page's records, in page order; the result is aligned
// with records, and a nil entry means the row has no state. db is the list's
// handle, for a hook that needs one query for the whole page.
func (PeopleController) ListRowStates(_ context.Context, _ *gorm.DB, records []any) ([][]pact.RowState, error) {
states := make([][]pact.RowState, len(records))
for i, record := range records {
person := record.(*Person)
if person.Banned {
states[i] = append(states[i], pact.RowStateNegative)
}
if !person.Active {
states[i] = append(states[i], pact.RowStateDisabled)
}
}
return states, nil
}
cabana calls the hook once per list page, with that page's records and the list's database handle, never once per row. A list does not run in a transaction, so cabana.TxFromContext reports none in this hook; use the handle it is given.
The set of states is fixed: pact.RowStateDeleted, pact.RowStateNegative and pact.RowStateDisabled. A row may carry several. The list response sends them in meta.row_states, keyed by row id, always in that order and each at most once; a value outside the set is dropped and logged, and a controller without the hook sends no row_states key. The admin shows each state as a text badge after the row's first cell and with a text style (a deleted row is struck through and muted, a negative one is red, a disabled one is muted), so the state is never carried by colour alone.
The badge texts are list messages. Override them per list in the messages block of config_list.yaml:
| Key | Default text |
|---|---|
rowStateDeleted |
Deleted |
rowStateNegative |
Blocked |
rowStateDisabled |
Inactive |
A list that shows soft-deleted records includes them in its scope, as withTrashed() does in WinterCMS: return db.Unscoped() (narrowed as needed) from pact.ListExtendQuery and pact.FormExtendQuery. Such a record can then be shown, updated and targeted by bulk and record actions, and it stays soft-deleted through an update. Code that writes to it, such as an action's Run, must use an unscoped handle too (tx.Unscoped()), or GORM adds its deleted_at IS NULL condition and the write matches nothing. Deleting it through the admin soft-deletes again, which changes nothing; a controller that wants the delete to be permanent removes the row in pact.FormAfterDelete.
Tree reorder#
A controller whose records form a tree (a parent_id and a sort_order column, such as menu entries) gets a drag-and-drop reorder page, the successor of WinterCMS's ReorderController. Records without a parent column get the same page as a plain ordered list; see Flat reorder. It needs a config_reorder.yaml next to config_list.yaml and the built-in reorder button in toolbar.buttons:
title: Reorder links
nameFrom: title
modelClass: Link
parentColumn: parent_id
sortColumn: sort_order
maxDepth: 3
partition:
column: group_id
relation: group
label: Group
| Key | Sets |
|---|---|
title |
The page title, a translation key or text. |
nameFrom |
The column a node shows. |
modelClass |
Optional; when set it must equal the controller's model name, as in WinterCMS's reorder_config.yaml. |
parentColumn, sortColumn |
The tree columns, parent_id and sort_order by default. Both are written by a save. Without parentColumn on a record that has no parent_id column the reorder is flat. |
maxDepth |
The deepest level a node may sit at, counting the top level as 1; 0 (the default) is unlimited. |
partition |
Optional: reorder within one value of a column, such as the entries of one menu. column is that column, relation the form's type: relation belongsTo field over it (its options, scoped by pact.RelationExtendOptionsQuery, are the partitions offered), nameFrom an optional label column of the related record and label the selector's label. |
Any other key, a column that is not a column of the controller's record, a partition relation that is not a belongsTo relation field of the form over the partition column, a reorder button without the file, and a reorder button on a controller that registers an action of that name stop the start-up. The list schema then carries reorder with the title and the partition column, and WinterCMS's toolbar key of reorder_config.yaml is not supported.
The page reads GET <prefix>/api/v1/{vendor}/{plugin}/{controller}/reorder?partition=<id>, which answers the title, the partition (its label, the options and the value shown, the first option by default) and every record of the scoped set as nodes with id, parent_id, sort_order and name, ordered by the sort column and then the id. The scoped set is what the list scope (pact.ListExtendQuery) returns within the partition.
A save posts {partition, nodes: [{id, parent_id, sort_order}]} to POST .../reorder, with every node of the set exactly once. One transaction locks the scoped set (SELECT ... FOR UPDATE) and compares it with the posted ids:
- Any difference (a record was added or removed meanwhile, or moved to another partition, or the post names a record of another partition) answers 409 with the error code
reorder_staleand the messagereorder.stale, and writes nothing. The admin reloads the tree. - A duplicate id, a parent outside the set, a cycle and a node deeper than
maxDepthare 422validation_failedonnodes; a partitioned page withoutpartitionis a 422 onpartition. - Otherwise the parent and sort columns of every node are written, without running the model's save hooks, and the answer is the new tree.
The model's save hooks do not run on a reorder, and neither do the controller's pact.FormAfterUpdate hooks. A controller that has to react to a new order implements pact.ReorderAfterSave: ReorderAfterSave(ctx, partition) runs after every node was written, inside the same transaction (cabana.TxFromContext returns it), with the posted partition, or nil when the reorder has none. A returned error rolls the whole reorder back. A cabana.ValidationError is answered 422 and a cabana.ForbiddenError 403, both with their messages translated in the request locale; any other error is the opaque 500. The transaction is a lagoon.Transaction, so work registered with lagoon.AfterCommit runs only once the new order is committed; purging a site's page cache after a menu reorder is the typical case (cooler.PurgeSiteCacheAfterCommit, see Site cache purge).
Both routes need the controller's permissions; the save is a write route (CSRF header, and a personal token needs a scope that allows POST).
In the admin, a list whose schema carries reorder shows a "Reorder records" button before "New record". It opens the reorder page, and when the list is filtered on the partition column it opens that partition. The page shows the tree with a drag handle and move up, move down, outdent and indent buttons on every row. A row can also be dragged before, after or into another row (never into its own subtree), and the arrow keys on a focused handle move it the same way as the buttons. There is no Save button: 400 ms after the last move the page posts the whole set, shows "Order saved", and sends a pending save at once when the administrator leaves. Only one save is in flight at a time: moves made while it runs are sent after it settles, with the tree as it is then, so the stored order never ends older than the screen. A refused save puts the last saved order back, unless a later save is waiting (it carries the whole tree); a 409 reloads the tree. A save that settles after the page switched partition does not touch the new partition's tree. A partitioned page has a selector for the partition.
Flat reorder#
A record with an order but no parent (WinterCMS's Sortable trait: a sort_order column and no parent_id) uses the same config_reorder.yaml without parentColumn. A WinterCMS reorder_config.yaml of such a controller compiles unchanged:
title: Reorder badges
nameFrom: name
modelClass: Badge
The reorder is flat when the file names no parentColumn and the controller's record has no parent_id column, as WinterCMS infers a Sortable model. An explicit parentColumn always means a tree and still stops the start-up when it is not a column, and a record with a parent_id column keeps the tree reorder. nameFrom, sortColumn, modelClass and partition work as on a tree; maxDepth above 0 on a flat reorder stops the start-up.
The list schema's reorder and the data of both reorder routes carry flat: true; a tree reorder omits the key, so its payloads are unchanged. Every node of a flat reorder has parent_id: null. A save writes only the sort column, without running the model's save hooks. A node whose parent_id is not null is a 422 validation_failed on nodes with reorder.flat_parent; the duplicate-id 422 and the 409 reorder_stale set rule are the same as on a tree.
In the admin, a flat reorder page is a plain ordered list: every row has the drag handle and the move up and move down buttons, but no outdent or indent buttons; ArrowUp and ArrowDown on a handle move the row, ArrowRight and ArrowLeft do nothing, and a row dragged onto the middle of another lands after it. Saving works as on a tree, with parent_id: null on every node.
Remembered list state#
The admin keeps a list's search, sort, filters, page and page size in the URL, so a filtered list can be bookmarked or shared. It also remembers the last of these per list in the browser's local storage. When an administrator opens a list without any of these parameters in the URL (from the navigation, a breadcrumb or a form's back, save or delete), the admin restores the remembered query. A URL that carries list parameters wins and replaces the remembered query.
Search terms can contain personal data, so remembered queries belong to one administrator and one session. They are stored under the signed-in administrator's id. Signing in as another administrator on the same browser removes every other administrator's queries, and the remembered queries of older builds, which were not stored per administrator. Every session end removes all of them: logging out, an expired session, and a 401 that the session refresh cannot recover. Only these list parameters are stored, never a token or record data.
A restored query never leaves a list unusable. If the list request built from a restored query fails for any reason (a 422 for a column or filter that no longer exists, a server error, or no connection), the admin forgets the query and loads the plain list once instead. A query that came from the URL keeps the error on screen, because the administrator chose it. A 422 still removes it from storage, and a button next to the error clears search, filters and sorting and loads the plain list.
Scoping every list#
To restrict which records an administrator sees at all, implement pact.ListExtendQuery on the controller. It receives the list query before search, filters and pagination are applied, so the restriction holds for every request. See Admin controllers for the other hooks.