Wolfram Research

Function Repository Resource:

DragRearrange

Source Notebook

A dynamic interface for ordering items in a list

Contributed by: Jon McLoone

ResourceFunction["DragRearrange"][Dynamic[list]]

creates a dynamic interface in which you can reorder the elements of list by dragging them with the mouse.

Examples

Basic Examples

Define a symbol containing a list of items and then create a dynamic interface for reordering the items in the list:

In[1]:=
list = {"Red", "Green", "Blue"};
In[2]:=
ResourceFunction["DragRearrange"][Dynamic[list]]
Out[2]=
In[3]:=
Dynamic[list]
Out[3]=

Options

Make items that are draggable horizontally with Appearance:

In[4]:=
ResourceFunction["DragRearrange"][Dynamic[list], Appearance -> "Horizontal"]
Out[4]=

Standard options for Graphics are supported:

In[5]:=
ResourceFunction["DragRearrange"][Dynamic[list], Appearance -> "Horizontal", AspectRatio -> 1/5]
Out[5]=

You can create custom graphics for the draggable items, by providing a function that accepts the label, a Boolean and Graphics options:

In[6]:=
myItem[label_, selectedQ_, opts___] := Graphics[{If[selectedQ, Pink, Yellow], EdgeForm[Black], Disk[{0, 0}, 1], Black, Text[label, {0, 0}]}, AspectRatio -> 1/3, PlotRange -> {{-2, 2}, {-2, 2}}, opts]
In[7]:=
ResourceFunction["DragRearrange"][Dynamic[list], "DragElementFunction" -> myItem]
Out[7]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

License Information