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:
//<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:
//<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
Configs
11Other
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.
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.
Misc
Properties
17
Properties
17Common
Class hierarchy
Other
Returns true if a drag operation is active
Functions
28
Functions
28Configuration
Events
Misc
Other
Events
12
Events
12Fires 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | Owning TaskBoard |
taskRecords | TaskModel[] | Tasks to be dragged |
domEvent | Event | 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | Owning TaskBoard |
taskRecords | TaskModel[] | Dropped tasks |
targetColumn | ColumnModel | Dropped on this column |
targetSwimlane | SwimlaneModel | Dropped in this swimlane (if used) |
domEvent | Event | 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | Owning TaskBoard |
taskRecords | TaskModel[] | Dragged tasks |
targetColumn | ColumnModel | Currently over this column |
targetSwimlane | SwimlaneModel | Currently over this swimlane (if used) |
domEvent | Event | 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | Owning TaskBoard |
taskRecords | TaskModel[] | 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | Owning TaskBoard |
taskRecords | TaskModel[] | Affected tasks |
domEvent | Event | 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | Owning TaskBoard |
taskRecords | TaskModel[] | Tasks to be dragged |
domEvent | Event | 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | Owning TaskBoard |
taskRecords | TaskModel[] | Dropped tasks |
targetColumn | ColumnModel | Dropped on this column |
targetSwimlane | SwimlaneModel | Dropped in this swimlane (if used) |
domEvent | Event | The mouse event |
Event handlers
12
Event handlers
12Called on the owning TaskBoard before task dragging starts. Return false to prevent the action
new TaskDrag({
onBeforeTaskDrag({ source, taskRecords, domEvent }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | Owning TaskBoard |
taskRecords | TaskModel[] | Tasks to be dragged |
domEvent | Event | 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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | Owning TaskBoard |
taskRecords | TaskModel[] | Dropped tasks |
targetColumn | ColumnModel | Dropped on this column |
targetSwimlane | SwimlaneModel | Dropped in this swimlane (if used) |
domEvent | Event | 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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | Owning TaskBoard |
taskRecords | TaskModel[] | Dragged tasks |
targetColumn | ColumnModel | Currently over this column |
targetSwimlane | SwimlaneModel | Currently over this swimlane (if used) |
domEvent | Event | 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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | Owning TaskBoard |
taskRecords | TaskModel[] | 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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | Owning TaskBoard |
taskRecords | TaskModel[] | Affected tasks |
domEvent | Event | The mouse event |
Called on the owning TaskBoard when task dragging starts
new TaskDrag({
onTaskDragStart({ source, taskRecords, domEvent }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | Owning TaskBoard |
taskRecords | TaskModel[] | Tasks to be dragged |
domEvent | Event | 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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | Owning TaskBoard |
taskRecords | TaskModel[] | Dropped tasks |
targetColumn | ColumnModel | Dropped on this column |
targetSwimlane | SwimlaneModel | Dropped in this swimlane (if used) |
domEvent | Event | The mouse event |
Typedefs
1
Typedefs
1CSS variables
6
CSS variables
6| Name | Description |
|---|---|
--b-task-board-task-drag-card-box-shadow | Dragged cards box shadow |
--b-task-board-task-drag-card-transform | Dragged cards transform (slight rotation by default) |
--b-task-board-task-drag-drop-background | Drop indicator background |
--b-task-board-task-drag-drop-border | Drop indicator border |
--b-task-board-task-drag-invalid-background | Invalid drop indicator background |
--b-task-board-task-drag-invalid-color | Invalid drop indicator border color |