Sorting
Sorting reorders cards within each column - by priority, deadline, name, or any criterion you choose - so the most relevant items come first.
Sort criterion
The board accepts a sort criterion in one of three forms:
- Declarative object -
{ field, dir }wherefieldis the card property name anddiris"asc"(default) or"desc". The board compares values using standard</>operators, so strings sort alphabetically and numbers sort numerically. - Custom comparator - a function
(a, b) => number, same contract asArray.prototype.sort. Use it for multi-field logic or custom ordering (e.g., status enums mapped to a custom rank). - Null - clears the sort and restores the original card order.
Sorting works per column. It reorders cards inside each column but never moves a card to another column.
// declarative
const sort = { field: "priority", dir: "desc" };
// comparator
const sort = (a, b) => {
const rank = { High: 3, Medium: 2, Low: 1 };
return (rank[b.status] || 0) - (rank[a.status] || 0);
};
Initial sort
Pass the sort prop to sort cards on first render.
<script>
import { Kanban } from "@svar-ui/svelte-kanban";
const columns = [
{ id: "backlog", label: "Backlog" },
{ id: "doing", label: "In Progress" },
{ id: "done", label: "Done" },
];
const cards = [
{ id: 1, label: "Design landing page", priority: 3, column: "backlog" },
{ id: 2, label: "Fix login bug", priority: 1, column: "doing" },
{ id: 3, label: "Write tests", priority: 2, column: "backlog" },
];
</script>
<Kanban {cards} {columns} sort={{ field: "priority", dir: "desc" }} />
Each column shows its cards from highest to lowest priority. To reverse the order, change dir to "asc".
Runtime sort changes
Dispatch sort-cards through the API to change the criterion at any time. Pass sort: null to clear it and restore the original order.
<script>
import { Kanban } from "@svar-ui/svelte-kanban";
let api;
const columns = [
{ id: "backlog", label: "Backlog" },
{ id: "doing", label: "In Progress" },
];
const cards = [
{ id: 1, label: "Alpha task", priority: 2, column: "backlog" },
{ id: 2, label: "Beta task", priority: 1, column: "doing" },
];
function sortByLabel() {
api.exec("sort-cards", { sort: { field: "label", dir: "asc" } });
}
function clearSort() {
api.exec("sort-cards", { sort: null });
}
</script>
<button onclick={sortByLabel}>Sort A-Z</button>
<button onclick={clearSort}>Clear sort</button>
<Kanban bind:this={api} {cards} {columns} />
Each call replaces the previous criterion. There's no built-in multi-level sort. For composite ordering, pass a comparator that breaks ties across fields.
Built-in sort button
Toolbar ships a ready-made sort menu. Enable it with the sort prop - no extra wiring needed.
<script>
import { Kanban, Toolbar, Editor } from "@svar-ui/svelte-kanban";
let api;
const columns = [
{ id: "backlog", label: "Backlog" },
{ id: "doing", label: "In Progress" },
{ id: "done", label: "Done" },
];
const cards = [
{ id: 1, label: "Design mockups", priority: 3, column: "backlog" },
{ id: 2, label: "API integration", priority: 1, column: "doing" },
{ id: 3, label: "Release notes", priority: 2, column: "done" },
];
</script>
<Toolbar {api} sort={true} />
<Kanban bind:this={api} {cards} {columns} />
{#if api}<Editor {api} />{/if}

The menu offers four options - label ascending/descending and priority ascending/descending - plus a "Clear" entry that resets to the original order. Each dispatches sort-cards internally.
For sort entries beyond label and priority, build a toolbar item array with getToolbarItems, replace or extend the sort section, and pass it to Toolbar via the items prop.