DHTMLX Kanban. Switching between projects example
When managing multiple projects in a single interface, users need to switch between different sets of tasks without leaving the page. Reloading the board data via parse lets you swap entire project datasets while keeping the same column structure.
Live example
const { columns, cards } = getData();
const board = new kanban.Kanban("#root", {
columns,
cards
});
document.getElementById("project").addEventListener("change", function (e) {
board.parse({
cards:
e.target.value == "kanban"?
cards:
supportCards
})
});<!-- custom styles -->
<link rel="stylesheet" href="https://snippet.dhtmlx.com/codebase/assets/css/auxiliary_controls.css">
<!-- component containers -->
<section class="dhx_sample-controls">
<label for="project" class="dhx_sample-label">Select project:</label>
<select name="project" class="dhx_select dhx_sample-input" id="project">
<option value="kanban" selected>Kanban</option>
<option value="support">Support</option>
</select>
</section>
<div id="root" style="height: 100%;"></div>
<!-- dataset -->
<script src="https://snippet.dhtmlx.com/codebase/data/kanban/01/dataset.js"></script>
<script>
const supportCards = [
{
label: "Complete the documentation",
column: "inprogress",
},
{
label: "Write new tests",
column: "backlog",
},
];
</script>The code listens to a <select> dropdown and calls board.parse({ cards: newCards }) when the selection changes. The parse method replaces the current card data with the new dataset while preserving the existing columns. Each project has its own cards array, and the dropdown value determines which one is loaded.
Solution overview
- Initialize the board with the default project's cards and columns
- Listen for changes on a project selector (dropdown, tabs, etc.)
- Call
board.parse({ cards: projectCards })to replace the board data
Key points
parsereplaces data: UnlikeaddCard,parsewipes existing cards and loads new ones. It's a full data refresh, not an incremental update- Columns persist: Passing only
cardstoparsekeeps the existing column structure. Passcolumnstoo if they differ per project - No reinitialization needed:
parseupdates the board in place without creating a new Kanban instance parseis an alias ofsetConfig: alternatively, if you change several props at once, e.g. parse new data and set a differentcolumnKeyorrowKey, you can safely callsetConfig({ cards: [...], ..., columnKey: "col" }), parse is an alias ofsetConfigfor data properties.
API reference
- parse: Loads new data into an existing board