Backend sorting and reordering
The Reorder behavior is a controller behavior that provides features for sorting and reordering database records. The behavior provides a page called Reorder using the controller action
reorder. This page displays a list of records with a drag handle allowing them to be sorted and in some cases restructured.
NOTE: If adding sorting to a previously unsorted model under the control of a third party is desired, you can use the
Winter\Storm\Database\Behaviors\Sortablebehavior, which can be dynamically implemented. However, you will need to ensure that the model table has a
sort_ordercolumn present on it.
In order to use the Reorder behavior you should add the
\Backend\Behaviors\ReorderController::class definition to the
$implement property of the controller class.
class Categories extends Controller
* @var array List of behaviors implemented by this controller
public $implement = [
Configuring the behavior
The Reorder behaviour will load its configuration in the YAML format from a
config_reorder.yaml file located in the controller's views directory (
plugins/myauthor/myplugin/controllers/mycontroller/config_reorder.yaml) by default.
This can be changed by overriding the
$reorderConfig property on your controller to reference a different filename or a full configuration array:
public $reorderConfig = 'my_custom_reorder_config.yaml';
Below is an example of a typical Reorder behavior configuration file:
# Reorder Behavior Config
# Reorder Title
title: Reorder Categories
# Attribute name
# Model Class name
# Toolbar widget configuration
# Partial for toolbar buttons
The configuration options listed below can be used.
|used for the page title.
|specifies which attribute should be used as a label for each record.
|a model class name, the record data is loaded from this model.
|reference to a Toolbar Widget configuration file, or an array with configuration.
Displaying the reorder page
You should provide a view file with the name reorder.htm. This view represents the Reorder page that allows users to reorder records. Since reordering includes the toolbar, the view file will consist solely of the single
reorderRender method call.
<?= $this->reorderRender() ?>
Override Sortable Partials
If you need to override default view of your reorder page, you have to copy
Extending the model query
The lookup query for the list database model can be extended by overriding the
reorderExtendQuery method inside the controller class. This example will ensure that soft deleted records are included in the list data, by applying the withTrashed scope to the query:
public function reorderExtendQuery($query)