Skip to content

Events

Every drag fires the SortableJS-style lifecycle callbacks - OnStart, OnChange, OnUpdate, OnRemove, OnAdd, OnSort and OnEnd. Drag items within and between the lists and watch the log - the newest event is on top.

events-left
Item 1
Item 2
Item 3
Item 4
events-right
Item A
Item B

Left: Item 1, Item 2, Item 3, Item 4

Right: Item A, Item B

Each line: [event @list that raised it] item FromId#OldIndex -> ToId#NewIndex (input, flags)
No events yet…

Try it

  • Drag Item 1 below Item 3: OnStart, then on the drop OnUpdate, OnSort and OnEnd.
  • Drag Item 4 into the right list: OnRemove on the left, OnAdd on the right, OnSort on both, and OnEnd on the left - the list the drag started in.
  • Drag an item into the other list and back home before you drop it: nothing changed, so only OnStart and OnEnd.
  • Tick the box and drag again: an OnChange line for every place the item passes through.
  • Pick an item up from the keyboard (Space), move it, and press Escape: OnEnd alone, with keyboard and canceled in its flags.

The lifecycle

EventRaised whenOn
OnStartA drag begins.The source list.
OnChangeThe dragged item takes a new position during the drag.The list it moves in.
OnUpdateThe order of the list changed within the same list.The list.
OnRemoveAn item was moved out to another list (not raised for a clone).The source list.
OnAddAn item was dropped in from another list.The destination list.
OnSortAny change to a list: add, remove or update.Each list that changed.
OnEndThe drag ended, whatever its outcome.The source list.

The completion events are raised after the bound lists have changed and ItemsChanged has been raised, so a handler sees the final state. Within a list: OnUpdate, OnSort, OnEnd. Across lists: OnRemove on the source (unless it is a clone), OnAdd on the destination, OnSort on the source (unless it is a clone) and on the destination, then OnEnd. A cancelled drag raises OnEnd alone. All of them are raised once the drag is over, so a handler that takes its time - a save to a server, say - never holds up the next drag.

The event arguments

Every event passes a BortableEventArgs<TItem>:

MemberWhat it says
ItemThe dragged item - the copy, in the events after a clone was dropped.
ItemsEvery item the drag moved: a multi-drag selection, or just Item.
OldIndex, NewIndexWhere the item was in the source list when the drag started, and where it is in the destination.
FromId, ToIdThe Id of the source and of the destination list.
FromGroup, ToGroupTheir Group.
CrossedListstrue when the item moved between lists.
InputHow the drag was made: Mouse, Touch, Pen, Keyboard, or Api for a move made by code.
IsClonetrue when a copy goes into another list and the original stays (see cloning).
CanceledOn OnEnd: the drag kept nothing - cancelled, spilled with RevertOnSpill, refused by ConfirmDrop or, for a multi-drag's gathering, by CanDrop (see rules), or ended as its list left the page with a ConfirmDrop to ask.
An unhandled error has occurred. Reload 🗙