move-card
Moves a card to a different column, reorders it within the same column, or both. With swimlanes (PRO), it can also move the card to a different lane.
Usage
api.exec("move-card", {
id: CardID,
column?: ColumnID,
swimlane?: SwimlaneID,
before?: CardID | null,
});
| Field | Type | Description |
|---|---|---|
id | string | number | ID of the card to move. Required. |
column | string | number | Target column ID. When omitted, the card stays in its current column. |
swimlane | string | number | Target swimlane ID (PRO). When omitted, the card stays in its current lane. |
before | string | number | null | Place the card before this card in source order. null moves it to the end. Omit to append. |
The store rejects the move when:
iddoesn't match any cardcolumnorswimlanedoesn't match any configured column or lanebeforepoints to a card outside the target column (the card can be in any lane of that column)- an object
columnAccessororswimlaneAccessorreturns fromseta card that doesn't read back as the target column or lane
For a rejected move, the store handler returns false and leaves card data and order unchanged. The action isn't forwarded to data providers or on… props, such as onMoveCard.
An object accessor's set receives a shallow copy of the card, so it can modify and return that copy. When history is on, a move that changes both the column and the lane is one undo step.
Trigger
// Move card 3 to the "done" column, at the end
api.exec("move-card", { id: 3, column: "done", before: null });
// Reorder card 3 before card 7 within the same column
api.exec("move-card", { id: 3, before: 7 });
// Move card 3 to the "done" column and the "urgent" lane (PRO)
api.exec("move-card", { id: 3, column: "done", swimlane: "urgent" });
Observe
api.on("move-card", ({ id, column, before }) => {
console.log(`Card ${id} moved to column ${column}`);
});
Intercept
// Prevent cards from moving into the "done" column
api.intercept("move-card", ({ column }) => {
return column !== "done";
});
Component handler
<Kanban
cards={cards}
columns={columns}
onMoveCard={({ id, column }) => {
console.log(`Card ${id} moved to ${column}`);
}}
/>
Related
- Cards guide - card data shape and card actions
- columns - the column definitions cards move between
- columnAccessor - controls how column membership is written on move
- Swimlanes guide - lanes as a secondary grouping (PRO)