winter
winter copied to clipboard
No longer able to sort relation widget by invisible column
Winter CMS Build
dev-develop
PHP Version
8.1
Database engine
MySQL/MariaDB
Plugins installed
Winter.Demo
Issue description
In October CMS / Winter CMS v1.0 I was able to sort a relation widget by an invisible column as long as I marked all of the other columns as not sortable (sortable: false
). With Winter CMS v1.1 and v1.2 it seems this doesn't work anymore.
The reason I want to be able to sort by an invisible column is because I've implemented a drag and drop sorting feature for relation widgets to make it easier to sort items for the user. To do this, I utilize a partial column which displays a sort handle icon the user can use to click and drag on and then the actual sort number value was inside an invisible column so the user wouldn't see it and was used so the widget knew what sort order to render everything in.

Steps to replicate
Test Plugin: acme.zip
- Create a new Winter CMS installation
- Add relation widget to a backend form with no sortable columns except for the invisible
sort_order
column. - Create pivot table with sortable column
- Adjust sort_order column on pivot table and notice the ordering is not affected in the backend form.
Example:
# config_relations.yaml
images:
label: 'Image'
view:
showSearch: true
toolbarButtons: create|add|remove|delete
form:
fields:
name:
type: text
label: Name
list:
columns:
name:
type: text
label: Name
sortable: false
'pivot[sort_order]':
type: number
label: Sort Order
invisible: true
sortable: true
defaultSort:
column: pivot[sort_order]
direction: asc
manage:
showSearch: true
recordsPerPage: 10
form:
fields:
name:
type: text
label: Name
list:
columns:
name:
type: text
label: Name
sortable: false
'pivot[sort_order]':
type: number
label: Sort Order
invisible: true
sortable: true
defaultSort:
column: created_at
direction: desc
Workaround
No response
Found a short-term workaround.
It appears I can sort a column which has a type of partial
.
columns:
[...]
'pivot[order]':
label: Sort
type: partial
sortable: true
path: $/acme/test/views/partials/_reorder_handle.php
The only thing I don't like about this approach, is it allows the user to adjust the sort direction when the sort direction should only be displayed in ascending order.
I just discovered you can disable the sorting behavior for the relation widget, so I guess this no longer an issue for me. https://wintercms.com/docs/backend/relations#configuring-relation:~:text=showSorting,true
Not sure if this is actually a bug or not, but I will keep it open for the time being.
Should be fixed by https://github.com/wintercms/winter/commit/c563f20f87409e418e304539efd9f49a5038dd1f.