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.
Left: Item 1, Item 2, Item 3, Item 4
Right: Item A, Item B
Try it
- Drag Item 1 below Item 3:
OnStart, then on the dropOnUpdate,OnSortandOnEnd. -
Drag Item 4 into the right list:
OnRemoveon the left,OnAddon the right,OnSorton both, andOnEndon 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
OnStartandOnEnd. - Tick the box and drag again: an
OnChangeline for every place the item passes through. -
Pick an item up from the keyboard (Space), move it, and press Escape:
OnEndalone, withkeyboardandcanceledin its flags.
The lifecycle
| Event | Raised when | On |
|---|---|---|
OnStart | A drag begins. | The source list. |
OnChange | The dragged item takes a new position during the drag. | The list it moves in. |
OnUpdate | The order of the list changed within the same list. | The list. |
OnRemove | An item was moved out to another list (not raised for a clone). | The source list. |
OnAdd | An item was dropped in from another list. | The destination list. |
OnSort | Any change to a list: add, remove or update. | Each list that changed. |
OnEnd | The 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>:
| Member | What it says |
|---|---|
Item | The dragged item - the copy, in the events after a clone was dropped. |
Items | Every item the drag moved: a multi-drag selection, or just Item. |
OldIndex, NewIndex | Where the item was in the source list when the drag started, and where it is in the destination. |
FromId, ToId | The Id of the source and of the destination list. |
FromGroup, ToGroup | Their Group. |
CrossedLists | true when the item moved between lists. |
Input | How the drag was made: Mouse, Touch, Pen, Keyboard, or Api for a move made by code. |
IsClone | true when a copy goes into another list and the original stays (see cloning). |
Canceled | On 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. |