swimlaneAccessor
The functionality is available in PRO Edition only
PROControls how the store reads and writes a card's swimlane (lane) membership. Works the same way as columnAccessor. Accepts a property name as a string, or an object with get/set callbacks for derived membership.
Usage
swimlaneAccessor?: string | {
get: (card: KanbanCard) => SwimlaneID;
set: (card: KanbanCard, value: SwimlaneID) => KanbanCard;
};
Default: "swimlane"
With a string, the store reads card[swimlaneAccessor] to find the card's lane and writes the same key when a card moves to another lane. With an object:
get(card)- returns the lane ID for a given cardset(card, value)- returns the card with its lane membership updated tovalue
Without the swimlanes prop, the store builds lanes from the values the accessor reads - one lane per distinct value, labelled with String(id). The board doesn't show cards whose lane ID doesn't match a lane, but getCards() still returns them.
Example
String shorthand:
import { Kanban } from "@svar-ui/react-kanban";
const cards = [
{ id: 1, label: "Task A", column: "todo", team: "product" },
{ id: 2, label: "Task B", column: "doing", team: "platform" },
];
const columns = [
{ id: "todo", label: "To Do" },
{ id: "doing", label: "In Progress" },
];
const swimlanes = [
{ id: "product", label: "Product" },
{ id: "platform", label: "Platform" },
];
<Kanban
cards={cards}
columns={columns}
swimlanes={swimlanes}
swimlaneAccessor="team"
/>;
Object form that sends cards without a team to an "Unassigned" lane:
import { Kanban } from "@svar-ui/react-kanban";
const swimlanes = [
{ id: "product", label: "Product" },
{ id: "platform", label: "Platform" },
{ id: "none", label: "Unassigned" },
];
const swimlaneAccessor = {
get: (card) => card.team ?? "none",
set: (card, value) => ({ ...card, team: value === "none" ? null : value }),
};
<Kanban
cards={cards}
columns={columns}
swimlanes={swimlanes}
swimlaneAccessor={swimlaneAccessor}
/>;
Related
- columnAccessor - the same mechanism for column membership
- cards - card objects whose lane membership the accessor reads
- move-card - moves a card to another lane with the
swimlanefield