winter icon indicating copy to clipboard operation
winter copied to clipboard

No longer able to sort relation widget by invisible column

Open ericp-mrel opened this issue 2 years ago • 2 comments

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.

Screen Shot 2022-09-22 at 10 32 05 AM

Screen Shot 2022-09-22 at 10 33 39 AM

Steps to replicate

Test Plugin: acme.zip

  1. Create a new Winter CMS installation
  2. Add relation widget to a backend form with no sortable columns except for the invisible sort_order column.
  3. Create pivot table with sortable column
  4. 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

ericp-mrel avatar Sep 22 '22 15:09 ericp-mrel

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.

Screen Shot 2022-09-22 at 11 01 25 AM

ericp-mrel avatar Sep 22 '22 16:09 ericp-mrel

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.

ericp-mrel avatar Sep 22 '22 21:09 ericp-mrel

Should be fixed by https://github.com/wintercms/winter/commit/c563f20f87409e418e304539efd9f49a5038dd1f.

bennothommo avatar Dec 12 '22 07:12 bennothommo