Record reordering API
Per-option reference for the ordering resource class attribute. For task-oriented documentation and worked examples, see the Record reordering guide.
All options are passed as a Hash to self.ordering on the resource:
class Avo::Resources::CourseLink < Avo::BaseResource
self.ordering = {
# options listed below
}
endOrdering actions
-> actions
The lambdas that change a record's position. Each key maps a control to the code that runs when it's used. The reordering controls only render when at least one action is defined.
self.ordering = {
actions: {
higher: -> { record.move_higher },
lower: -> { record.move_lower },
to_top: -> { record.move_to_top },
to_bottom: -> { record.move_to_bottom },
insert_at: -> { record.insert_at position }
}
}Each lambda is evaluated with access to:
record— the instantiated model being movedresource— the current resourceoptions— the fullorderinghashparams— the request paramsdirection— the pressed direction as a String (directional actions only)position— the target position as anInteger(insert_atonly)Type: Hash of Procs, any subset of
:higher,:lower,:to_top,:to_bottom,:insert_atDefault:
nil
-> higher
Runs when the "move up" button is pressed. Should move the record one position up.
higher: -> { record.move_higher }-> lower
Runs when the "move down" button is pressed. Should move the record one position down.
lower: -> { record.move_lower }-> to_top
Runs when the "move to top" button is pressed. Should move the record to the first position.
to_top: -> { record.move_to_top }-> to_bottom
Runs when the "move to bottom" button is pressed. Should move the record to the last position.
to_bottom: -> { record.move_to_bottom }-> insert_at
Runs when a record is dropped in a new position via drag and drop. Should move the record to the position it receives — an Integer computed from where the record was dropped.
insert_at: -> { record.insert_at position }Visibility
-> visible_on
Which views render the reordering controls.
self.ordering = {
visible_on: :index # :index | :association | [:index, :association]
}| Value | Behavior |
|---|---|
:index | Controls appear on the resource's Index view |
:association | Controls appear only in has_many association views |
[:index, :association] | Controls appear in both places |
- Type: Symbol or Array of Symbols
- Default:
nil
No implicit default
Omitting visible_on hides the controls everywhere — it does not fall back to :index. Always set it explicitly.
-> display_inline
Renders the ordering buttons directly in the row instead of tucked behind a popover trigger.
self.ordering = {
display_inline: true
}- Type: Boolean
- Default:
false— buttons render inside a popover
Drag and drop
-> drag_and_drop
Enables reordering by dragging a record to its new position.
self.ordering = {
drag_and_drop: true,
actions: {
insert_at: -> { record.insert_at position }
}
}- Type: Boolean
- Default:
false
Requires insert_at
Drag and drop only activates when drag_and_drop: true and an actions hash with an insert_at key are both present. With either one missing, the drag handles don't render.
-> position
A lambda returning a record's current position. Avo calls it on the first record in the list to compute the target position of a dropped record.
self.ordering = {
position: -> { record.position_in_list }
}The lambda has access to record, resource, options (the full ordering hash), and params.
- Type: Proc
- Default:
nil— Avo readsrecord.position, the attributeacts_as_listprovides