DHTMLX Kanban. Dynamic column grouping example
Different team members may need to view the same set of tasks organized by different criteria: by status, by priority, by assignee. Dynamic grouping lets users switch the board's column structure at runtime without changing the underlying data.
Live example
const { cards, columns, rows, groupData } = getData();
const board = new kanban.Kanban("#root", {
columns,
cards,
editorShape: [
{
type:"text",
key:"label",
label:"Label"
},
{
type:"combo",
key:"priority",
label:"Priority",
},
{
type:"select",
key:"type",
label:"Type",
values: rows
}
],
cardShape:{
label: true,
priority: true,
headerFields: [
{
key:"type",
css:"card-type"
}
]
}
});
document.getElementById("project").addEventListener("change", function (e) {
board.setConfig({
columnKey: e.target.value,
columns: groupData.find(group => group.id == e.target.value).columns
});
});<!-- custom styles -->
<link rel="stylesheet" href="https://snippet.dhtmlx.com/codebase/assets/css/auxiliary_controls.css">
<style>
.card-type {
font-weight: bold;
color: var(--wx-color-font-alt);
}
</style>The code uses setConfig to swap the columnKey and columns when a dropdown value changes. Each grouping option has its own set of columns defined in groupData. The columnKey property tells the Kanban which card field to use for column assignment (instead of the default column). The headerFields in cardShape displays the task type on each card, and the editor includes fields for editing priority and type.
Solution overview
- Define multiple column sets in a
groupDataarray, each with anid(matching a card field) andcolumns - Initialize the board with the default column set
- On user selection, call
board.setConfig({ columnKey: selectedField, columns: newColumns }) - Use
headerFieldsincardShapeto show grouping-relevant metadata on cards
Key points
columnKeychanges the grouping field: By default, cards are grouped by theircolumnproperty. SettingcolumnKeyto another field (likepriorityortype) regroups cards by that field- Column IDs must match field values: When grouping by
priority, column IDs must match the actual priority values in card data setConfigis non-destructive: Switching groups doesn't lose card data. Cards are simply redistributed across the new columns- Combine with
headerFields: Show the current grouping value on cards so users know why a card appears in a given column
API reference
- setConfig: Updates board configuration including column structure
- cardShape: Card appearance including
headerFields - editorShape: Custom editor fields