Skip to main content

Integration with Vue

tip

You should be familiar with the basic concepts and patterns of Vue before reading this documentation. To refresh your knowledge, please refer to the Vue 3 documentation.

DHTMLX Kanban is compatible with Vue. We have prepared code examples on how to use DHTMLX Kanban with Vue 3. For more information, refer to the corresponding Example on GitHub.

Creating a project

info

Before you start to create a new project, install Node.js.

To create a Vue project, run the following command:

npm create vue@latest

This command installs and executes create-vue, the official Vue project scaffolding tool. Check the details in the Vue.js Quick Start.

Let's name the project as my-vue-kanban-app.

Installation of dependencies

Go to the app directory:

cd my-vue-kanban-app

Install dependencies and start the dev server. For this, use a package manager:

  • if you use yarn, run the following commands:
yarn
yarn start // or yarn dev
  • if you use npm, run the following commands:
npm install
npm run dev

The app should run on a localhost (for instance http://localhost:3000).

Creating Kanban

Now you should get the DHTMLX Kanban source code. First of all, stop the app and proceed with installing the Kanban package.

Step 1. Package installation

Download the trial Kanban package and follow steps mentioned in the README file. Note that trial Kanban is available 30 days only.

Step 2. Component creation

Now you need to create a Vue component, to add Kanban with Toolbar into the application. Create a new file in the src/components/ directory and name it Kanban.vue.

Import source files

Open the Kanban.vue file and import Kanban source files. Note that:

  • if you use PRO version and install the Kanban package from a local folder, the import paths look like this:
Kanban.vue
<script>
import { Kanban, Toolbar } from 'dhx-kanban-package';
import 'dhx-kanban-package/dist/kanban.css';
</script>

Note that depending on the used package, the source files can be minified. In this case make sure that you are importing the CSS file as kanban.min.css.

  • if you use the trial version of Kanban, specify the following paths:
Kanban.vue
<script>
import { Kanban, Toolbar } from '@dhx/trial-kanban';
import '@dhx/trial-kanban/dist/kanban.css';
</script>

In this tutorial you can see how to configure the trial version of Kanban.

Setting containers and adding Kanban with Toolbar

To display Kanban with Toolbar on the page, you need to create containers for Kanban and Toolbar, and initialize these components using the corresponding constructors:

Kanban.vue
<script>
import { Kanban, Toolbar } from "@dhx/trial-kanban";
import "@dhx/trial-kanban/dist/kanban.css";

export default {
mounted() {
// initialize the Kanban component
this.kanban = new Kanban(this.$refs.kanban_container, {});

// initialize the Toolbar component
this.toolbar = new Toolbar(this.$refs.toolbar_container, {
api: this.kanban.api, // provide Kanban inner API
// other configuration properties
});
},

unmounted() {
this.kanban.destructor(); // destruct Kanban
this.toolbar.destructor(); // destruct Toolbar
}
};
</script>

<template>
<div class="component_container">
<div ref="toolbar_container"></div>
<div ref="kanban_container" class="widget"></div>
</div>
</template>

Adding styles

To display Kanban correctly, you need to specify important styles for Kanban and its container in the main css file of the project:

main.css
/* specify styles for initial page */
html,
body,
#app { /* make sure that you use the #app root container */
height: 100%;
padding: 0;
margin: 0;
}

/* specify styles for Kanban and Toolbar container */
.component_container {
height: 100%;
margin: 0 auto;
}

/* specify styles for Kanban container */
.widget {
height: calc(100% - 56px);
}

Loading data

To add data into the Kanban, you need to provide a data set. You can create the data.js file in the src/ directory and add some data into it:

data.js
export function getData() {
const columns = [
{
label: "Backlog",
id: "backlog"
},
{
label: "In progress",
id: "inprogress"
},
// ...
];

const cards = [
{
id: 1,
label: "Integration with Angular/React",
priority: 1,
color: "#65D3B3",
start_date: new Date("01/07/2021"),
users: [3, 2],
column: "backlog",
type: "feature",
},
{
label: "Archive the cards/kanbans ",
priority: 3,
color: "#58C3FE",
users: [4],
progress: 1,
column: "backlog",
type: "feature",
},
// ...
];

const rows = [
{
label: "Feature",
id: "feature",
},
{
label: "Task",
id: "task",
}
];

return { columns, cards, rows };
}

Then open the App.vue file, import data, and initialize it via the inner data() method. After this you can pass data into the new created <Kanban/> component as props:

App.vue
<script>
import Kanban from "./components/Kanban.vue";
import { getData } from "./data";

export default {
components: { Kanban },
data() {
const { columns, cards, rows } = getData();
return {
columns,
cards,
rows
};
}
};
</script>

<template>
<Kanban :columns="columns" :cards="cards" :rows="rows"/>
</template>

Go to the Kanban.vue file and apply the passed props to the Kanban configuration object:

Kanban.vue
<script>
import { Kanban, Toolbar } from "@dhx/trial-kanban";
import "@dhx/trial-kanban/dist/kanban.css";

export default {
props: ["cards", "columns", "rows"],

mounted() {
this.kanban = new Kanban(this.$refs.kanban_container, {
cards: this.cards,
columns: this.columns,
rows: this.rows,
rowKey: "type",
// other configuration properties
});

this.toolbar = new Toolbar(this.$refs.toolbar_container, {
api: this.kanban.api,
// other configuration properties
});
},

unmounted() {
this.kanban.destructor();
this.toolbar.destructor();
}
};
</script>

<template>
<div class="component_container">
<div ref="toolbar_container"></div>
<div ref="kanban_container" class="widget"></div>
</div>
</template>

You can also use the parse() method inside the mounted() method of Vue to load data into Kanban:

Kanban.vue
<script>
import { Kanban, Toolbar } from "@dhx/trial-kanban";
import "@dhx/trial-kanban/dist/kanban.css";

export default {
props: ["cards", "columns", "rows"],

mounted() {
this.kanban = new Kanban(this.$refs.kanban_container, {
columns: [],
cards: [],
rows: [],
rowKey: "type",
// other configuration properties
});

this.toolbar = new Toolbar(this.$refs.toolbar_container, {
api: this.kanban.api,
// other configuration properties
});

this.kanban.parse({
cards: this.cards,
columns: this.columns,
rows: this.rows
});
},

unmounted() {
this.kanban.destructor();
this.toolbar.destructor();
}
};
</script>

<template>
<div class="component_container">
<div ref="toolbar_container"></div>
<div ref="kanban_container" class="widget"></div>
</div>
</template>

The parse(data) method provides data reloading on each applied change.

Now the Kanban component is ready to use. When the element will be added to the page, it will initialize the Kanban with data. You can provide necessary configuration settings as well. Visit our Kanban API docs to check the full list of available properties.

Handling events

When a user makes some action in the Kanban, it invokes an event. You can use these events to detect the action and run the desired code for it. See the full list of events.

Open Kanban.vue and complete the mounted() method:

Kanban.vue
<script>
// ...
export default {
// ...
mounted() {
this.kanban = new Kanban(this.$refs.cont, {});

this.kanban.api.on("add-card", (obj) => {
console.log(obj.columnId);
});
},

unmounted() {
this.kanban.destructor();
}
}
</script>

// ...

After that, you can start the app to see Kanban loaded with data on a page.

Kanban initialization

Now you know how to integrate DHTMLX Kanban with Vue. You can customize the code according to your specific requirements. The final advanced example you can find on GitHub.