TaskDrag

This feature allows cards on the TaskBoard to be dragged across swimlanes and columns but also vertically in the same column to change the order:

Task drag
//<code-header>
fiddle.title = 'Task drag';
//</code-header>
const taskBoard = new TaskBoard({
    appendTo : targetElement,

    features : {
        taskDrag       : true,
        columnToolbars : false
    },

    // Url for resource avatar images
    resourceImagePath : 'data/Grid/images/transparent-users/',

    // Columns to display
    columns : [
        'todo',
        'doing',
        'done'
    ],

    // Field used to pair a task to a column
    columnField : 'status',

    // Project using inline data
    project : {
        tasks : [
            { id : 1, name : 'Try TaskBoard', status : 'doing' },
            { id : 2, name : 'Test Scheduler', status : 'done' },
            { id : 3, name : 'Evaluate Gantt', status : 'doing' },
            { id : 4, name : 'Download Grid', status : 'todo' },
            { id : 5, name : 'Install Scheduler Pro', status : 'todo' }
        ],

        resources : [
            { id : 1, name : 'Angelo', image : 'angelo.png' },
            { id : 2, name : 'Celia', image : 'celia.png' },
            { id : 3, name : 'Dave', image : 'dave.png' },
            { id : 4, name : 'Emilia', image : 'emilia.png' }
        ],

        assignments : [
            { id : 1, event : 1, resource : 1 },
            { id : 2, event : 2, resource : 2 },
            { id : 3, event : 3, resource : 3 },
            { id : 4, event : 4, resource : 4 },
            { id : 5, event : 5, resource : 1 },
            { id : 6, event : 1, resource : 2 },
            { id : 7, event : 2, resource : 3 },
            { id : 29, event : 3, resource : 1 }
        ]
    }
});

When a task is dropped, its columnField, swimlaneField and/or weight fields are updated to reflect the new location.

Note that when moving a task to a catch-all column (a column with id *), the task's field will be set to null.

Drag events

The different stages of a drag operation trigger different events, in order of appearance:

Event Description
beforeTaskDrag Preventable event fired before a drag starts
taskDragStart Fired when dragging starts
taskDrag Fired when movement during a drag will lead to changes
beforeTaskDrop Preventable event fired before finalizing a valid drop. Allows async listeners
taskDrop Fired after finalizing a valid drop
taskDragAbort Fired when a drag is aborted (ESC, drop out of bounds or by a listener)
taskDragEnd Fired when a started drag ends, no matter the outcome

The beforeTaskDrop is useful for example to request user confirmation for a drop:

Task drag events
//<code-header>
fiddle.title = 'Task drag events';
//</code-header>
const taskBoard = new TaskBoard({
    appendTo : targetElement,

    features : {
        taskDrag       : true,
        columnToolbars : false
    },

    // Columns to display
    columns : [
        'todo',
        'doing',
        'done'
    ],

    // Field used to pair a task to a column
    columnField : 'status',

    listeners : {
        // beforeTaskDrop is triggered before a drop is finalized, returning false will abort the operation.
        // It accepts async listeners that will block the drop until they resolve, in this case used to show a basic
        // confirmation dialog
        async beforeTaskDrop({ taskRecords, targetColumn }) {
            // Show confirmation dialog
            const result = await MessageDialog.confirm({
                title   : 'Verify drop',
                message : `Please confirm moving ${taskRecords.map(t => `"${t.name}"`).join(', ')} to ${targetColumn.text}?`
            });

            // Returning false will abort the drop (if user pressed Cancel)
            return result === MessageDialog.okButton;
        },

        // taskDrop is triggered after a successful drop
        taskDrop({ taskRecords, targetColumn }) {
            Toast.show(`${taskRecords.map(t => `"${t.name}"`).join(', ')} was moved to ${targetColumn.text}`);
        },

        // taskDragAbort is triggered if a drag is aborted using ESC or if the drop was invalid
        taskDragAbort({ taskRecords }) {
            Toast.show(`Drag of ${taskRecords.map(t => `"${t.name}"`).join(', ')} aborted`);
        }
    },

    // Project using inline data
    project : {
        tasks : [
            { id : 1, name : 'Drag me', description : 'To another column', status : 'doing' }
        ]
    }
});

This feature is enabled by default.

Configs

11

Common

disabledInstancePlugin
listenersEvents

Other

dragTouchStartDelay: Number= 300

The number of milliseconds that must elapse after a touchstart event before it is considered a drag. If movement occurs before this time, the drag is aborted. This is to allow touch swipes and scroll gestures.

reorderTaskRecords: Boolean= false

Specify true to enable the old behavior of moving tasks in the store on drop.

This behaviour was made opt in since it does not play well when sharing data with other components.

If you are sorting tasks by a field other than `weight` and want predictable results on drop, you should enable this config.

Misc

clientInstancePlugin
localeClassLocalizable
localizableLocalizable

Properties

17

Common

disabledInstancePlugin

Class hierarchy

isTaskDrag: Boolean= truereadonly
Identifies an object as an instance of TaskDrag class, or subclass thereof.
isTaskDrag: Boolean= truereadonlystatic
Identifies an object as an instance of TaskDrag class, or subclass thereof.
isEventsEvents
isInstancePluginInstancePlugin
isLocalizableLocalizable
isTaskBoardFeatureTaskBoardFeature

Other

isDragging: Booleanreadonly

Returns true if a drag operation is active

Lifecycle

configBase

Misc

clientInstancePlugin
localeHelperLocalizable
localeManagerLocalizable

Functions

28

Configuration

applyDefaultsstaticBase

Events

Lifecycle

destroystaticBase

Misc

doDisableInstancePlugin
initClassstaticBase
isOfTypeNamestaticBase
mixinstaticBase
optionalLstaticLocalizable

Other

LstaticLocalizable
onEvents
relayAllEvents
triggerEvents
unEvents

Events

12

Fires on the owning TaskBoard before task dragging starts. Return false to prevent the action

// Adding a listener using the "on" method
taskDrag.on('beforeTaskDrag', ({ source, taskRecords, domEvent }) => {

});
ParameterTypeDescription
sourceTaskBoard

Owning TaskBoard

taskRecordsTaskModel[]

Tasks to be dragged

domEventEvent

The mouse event

Fires on the owning TaskBoard when tasks are dropped, before the operation completes. Handles async listeners, returning false from one will abort the operation

const taskBoard = new TaskBoard({
   listeners : {
       async beforeTaskDrop({ taskRecords, targetColumn }) {
           // Show confirmation dialog
           const result = await MessageDialog.confirm({
               title   : 'Verify drop',
               message : `Please confirm moving ${taskRecords.map(t => `"${t.name}"`).join(', ')} to ${targetColumn.text}?`
           });

           // Returning false will abort the drop (if user pressed Cancel)
           return result === MessageDialog.okButton;
       }
   }
});
// Adding a listener using the "on" method
taskDrag.on('beforeTaskDrop', ({ source, taskRecords, targetColumn, targetSwimlane, domEvent }) => {

});
ParameterTypeDescription
sourceTaskBoard

Owning TaskBoard

taskRecordsTaskModel[]

Dropped tasks

targetColumnColumnModel

Dropped on this column

targetSwimlaneSwimlaneModel

Dropped in this swimlane (if used)

domEventEvent

The mouse event

Fires on the owning TaskBoard when tasks are dragged, if the drag leads to any changes compared to the last taskDrag event (moved to a new column or changed order within a column).

Returning false from a listener will flag the drag as invalid (by default turning the drop indicator red)

// Adding a listener using the "on" method
taskDrag.on('taskDrag', ({ source, taskRecords, targetColumn, targetSwimlane, domEvent }) => {

});
ParameterTypeDescription
sourceTaskBoard

Owning TaskBoard

taskRecordsTaskModel[]

Dragged tasks

targetColumnColumnModel

Currently over this column

targetSwimlaneSwimlaneModel

Currently over this swimlane (if used)

domEventEvent

The mouse event

Fires on the owning TaskBoard when a drag operation is aborted (invalid drop or aborted using ESC)

// Adding a listener using the "on" method
taskDrag.on('taskDragAbort', ({ source, taskRecords }) => {

});
ParameterTypeDescription
sourceTaskBoard

Owning TaskBoard

taskRecordsTaskModel[]

Dragged tasks

Fires on the owning TaskBoard when a previously started drag operation ends, no matter the outcome of it (whether valid, invalid or aborted)

// Adding a listener using the "on" method
taskDrag.on('taskDragEnd', ({ source, taskRecords, domEvent }) => {

});
ParameterTypeDescription
sourceTaskBoard

Owning TaskBoard

taskRecordsTaskModel[]

Affected tasks

domEventEvent

The mouse event

Fires on the owning TaskBoard when task dragging starts

// Adding a listener using the "on" method
taskDrag.on('taskDragStart', ({ source, taskRecords, domEvent }) => {

});
ParameterTypeDescription
sourceTaskBoard

Owning TaskBoard

taskRecordsTaskModel[]

Tasks to be dragged

domEventEvent

The mouse event

Fires on the owning TaskBoard when tasks are successfully dropped (after the drop transition has finished)

// Adding a listener using the "on" method
taskDrag.on('taskDrop', ({ source, taskRecords, targetColumn, targetSwimlane, domEvent }) => {

});
ParameterTypeDescription
sourceTaskBoard

Owning TaskBoard

taskRecordsTaskModel[]

Dropped tasks

targetColumnColumnModel

Dropped on this column

targetSwimlaneSwimlaneModel

Dropped in this swimlane (if used)

domEventEvent

The mouse event

catchAllEvents
destroyEvents
disableInstancePlugin
enableInstancePlugin

Event handlers

12

Called on the owning TaskBoard before task dragging starts. Return false to prevent the action

new TaskDrag({
    onBeforeTaskDrag({ source, taskRecords, domEvent }) {

    }
});
ParameterTypeDescription
sourceTaskBoard

Owning TaskBoard

taskRecordsTaskModel[]

Tasks to be dragged

domEventEvent

The mouse event

Called on the owning TaskBoard when tasks are dropped, before the operation completes. Handles async listeners, returning false from one will abort the operation

const taskBoard = new TaskBoard({
   listeners : {
       async beforeTaskDrop({ taskRecords, targetColumn }) {
           // Show confirmation dialog
           const result = await MessageDialog.confirm({
               title   : 'Verify drop',
               message : `Please confirm moving ${taskRecords.map(t => `"${t.name}"`).join(', ')} to ${targetColumn.text}?`
           });

           // Returning false will abort the drop (if user pressed Cancel)
           return result === MessageDialog.okButton;
       }
   }
});
new TaskDrag({
    onBeforeTaskDrop({ source, taskRecords, targetColumn, targetSwimlane, domEvent }) {

    }
});
ParameterTypeDescription
sourceTaskBoard

Owning TaskBoard

taskRecordsTaskModel[]

Dropped tasks

targetColumnColumnModel

Dropped on this column

targetSwimlaneSwimlaneModel

Dropped in this swimlane (if used)

domEventEvent

The mouse event

Called on the owning TaskBoard when tasks are dragged, if the drag leads to any changes compared to the last taskDrag event (moved to a new column or changed order within a column).

Returning false from a listener will flag the drag as invalid (by default turning the drop indicator red)

new TaskDrag({
    onTaskDrag({ source, taskRecords, targetColumn, targetSwimlane, domEvent }) {

    }
});
ParameterTypeDescription
sourceTaskBoard

Owning TaskBoard

taskRecordsTaskModel[]

Dragged tasks

targetColumnColumnModel

Currently over this column

targetSwimlaneSwimlaneModel

Currently over this swimlane (if used)

domEventEvent

The mouse event

Called on the owning TaskBoard when a drag operation is aborted (invalid drop or aborted using ESC)

new TaskDrag({
    onTaskDragAbort({ source, taskRecords }) {

    }
});
ParameterTypeDescription
sourceTaskBoard

Owning TaskBoard

taskRecordsTaskModel[]

Dragged tasks

Called on the owning TaskBoard when a previously started drag operation ends, no matter the outcome of it (whether valid, invalid or aborted)

new TaskDrag({
    onTaskDragEnd({ source, taskRecords, domEvent }) {

    }
});
ParameterTypeDescription
sourceTaskBoard

Owning TaskBoard

taskRecordsTaskModel[]

Affected tasks

domEventEvent

The mouse event

Called on the owning TaskBoard when task dragging starts

new TaskDrag({
    onTaskDragStart({ source, taskRecords, domEvent }) {

    }
});
ParameterTypeDescription
sourceTaskBoard

Owning TaskBoard

taskRecordsTaskModel[]

Tasks to be dragged

domEventEvent

The mouse event

Called on the owning TaskBoard when tasks are successfully dropped (after the drop transition has finished)

new TaskDrag({
    onTaskDrop({ source, taskRecords, targetColumn, targetSwimlane, domEvent }) {

    }
});
ParameterTypeDescription
sourceTaskBoard

Owning TaskBoard

taskRecordsTaskModel[]

Dropped tasks

targetColumnColumnModel

Dropped on this column

targetSwimlaneSwimlaneModel

Dropped in this swimlane (if used)

domEventEvent

The mouse event

onDestroyEvents
onDisableInstancePlugin
onEnableInstancePlugin

Typedefs

1

CSS variables

6
NameDescription
--b-task-board-task-drag-card-box-shadowDragged cards box shadow
--b-task-board-task-drag-card-transformDragged cards transform (slight rotation by default)
--b-task-board-task-drag-drop-backgroundDrop indicator background
--b-task-board-task-drag-drop-borderDrop indicator border
--b-task-board-task-drag-invalid-backgroundInvalid drop indicator background
--b-task-board-task-drag-invalid-colorInvalid drop indicator border color