Skip to content

Backend reorder not working correctly #881

@ericp-mrel

Description

@ericp-mrel

Winter CMS Build

1.1

PHP Version

8.0

Database engine

MySQL/MariaDB

Plugins installed

No response

Issue description

There is an issue where sorting from the backend reorder list view does not work when records all contain the same/duplicate sort order value since the winter.reorder.js file does not recalculate the sort order value and re-uses the existing sort order values from the DB and just switches what record that value is applied to. This is a problem if you add sorting functionality to an existing table with records already created and then the migration assigns a default sort order value of 0 to every record and when you create a new record, it will contain the sort order of 0 which will also cause sorting for that record to stop working if it conflicts with another.

Screenshot 2023-04-03 at 10 10 52 AM

Screenshot 2023-04-03 at 10 11 33 AM

Steps to replicate

  1. Create records in a table without sorting functionality.
  2. Add new sort_order column to table and have the migration assign default sort_order value of 0 to every record.
  3. Implement Reorder Controller functionality
  4. Try to re-order list of records from backend, but notice the new order of the records is not reflected in the DB / after reloading the page.

Workaround

  1. During migration, loop through every record and adjust the sort_order to be the same as the primary key.
  2. When creating new records, override default sort_order so it matches the primary key as well so we don't run into duplicates.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions