---
url: /reference/concerns/orderable.md
---
# Trek::Orderable

Position tracking with [acts_as_list](https://github.com/brendon/acts_as_list), scoped by parent.

## What it adds

* `acts_as_list scope: :parent, top_of_list: 0`
* An `ordered` scope (position order), which adds nothing on a [closure_tree](https://github.com/ClosureTree/closure_tree) model such as `Page` or `MenuNode`: closure_tree already orders its records by `position`
* All the `acts_as_list` instance methods: `insert_at`, `move_to_top`, `move_to_bottom`, `move_higher`, `move_lower`…

## Requirements

* A `position` integer column (and a `parent_id` column for the scope)

## Usage

```ruby
class MenuNode < ApplicationRecord
  include Trek::Orderable
end

menu.children # ordered by position, through closure_tree
node.move_to_top
```

This is what powers drag & drop reordering (SortableJS) in the admin lists.
