Cards in EJ2 TypeScript Kanban control
18 Apr 202315 minutes to read
The cards are main elements in Kanban board, which represent the task information with header and content. The header and content of a card is fetched from the corresponding mapping fields. The card layout can be customized with template also.
Drag-and-drop
Transit or change the card position using the drag-and-drop functionality. By default, the allowDragAndDrop
property is enabled on the Kanban board, which is used to change the card position by column-to-column or within the column.
Added dotted border on Kanban cells except the dragged clone cells when dragging, which indicates the possible ways for dropping the cards into the cells.
Header
The card header is achieved by mapping the headerField
property, which is placed inside the cardSettings
property. By default, the showHeader
property enabled by Kanban board that is used to show the header at the top of the card.
The
headerField
property ofcardSettings
is mandatory to render the cards in the Kanban board. It acts as a unique field that is used to avoid the duplication of card data. You can not change theheaderField
of mapped data value using theupdateCard
public method or server-side update of data.
In the following demo, the showHeader
property is disabled on Kanban board.
import { Kanban } from '@syncfusion/ej2-kanban';
import { kanbanData } from './datasource.ts';
let kanbanObj: Kanban = new Kanban({
dataSource: kanbanData,
keyField: 'Status',
columns: [
{ headerText: 'Backlog', keyField: 'Open' },
{ headerText: 'In Progress', keyField: 'InProgress' },
{ headerText: 'Testing', keyField: 'Testing' },
{ headerText: 'Done', keyField: 'Close' }
],
cardSettings: {
showHeader: false,
contentField: 'Summary',
headerField: 'Id'
}
});
kanbanObj.appendTo('#Kanban');
<!DOCTYPE html>
<html lang="en">
<head>
<title>Kanban Card without Header</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Kanban card without header" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-dropdowns/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-layouts/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-kanban/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js" type="text/javascript"></script>
<script src="systemjs.config.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>LOADING....</div>
<div id='container'>
<div class="content-wrapper">
<div id="Kanban"></div>
</div>
</div>
</body>
</html>
Content
The card’s content is fetched from data source using the contentField
property, which is placed inside the cardSettings
property. If the contentField
property is not used, card is rendered with empty content.
Template
You can customize the default card layout using template as per your application needs. This can be achieved by template of the cardSettings
property.
import { Kanban } from '@syncfusion/ej2-kanban';
import { kanbanData } from './datasource.ts';
let kanbanObj: Kanban = new Kanban({
dataSource: kanbanData,
keyField: 'Status',
columns: [
{ headerText: 'Backlog', keyField: 'Open' },
{ headerText: 'In Progress', keyField: 'InProgress' },
{ headerText: 'Done', keyField: 'Close' }
],
cardSettings: {
contentField: 'Summary',
headerField: 'Id',
template: '#cardTemplate'
}
});
kanbanObj.appendTo('#Kanban');
<!DOCTYPE html>
<html lang="en">
<head>
<title>Kanban Card Template</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Kanban card template" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-dropdowns/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-layouts/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-kanban/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js" type="text/javascript"></script>
<script src="systemjs.config.js" type="text/javascript"></script>
<script id="cardTemplate" type="text/x-jsrender">
<div class='e-card-content'>
<table class="card-template-wrap">
<tbody>
<tr>
<td class="CardHeader">Id:</td>
<td>${Id}</td>
</tr>
<tr>
<td class="CardHeader">Type:</td>
<td>${Type}</td>
</tr>
<tr>
<td class="CardHeader">Priority:</td>
<td>${Priority}</td>
</tr>
<tr>
<td class="CardHeader">Summary:</td>
<td>${Summary}</td>
</tr>
</tbody>
</table>
</div>
</script>
<style type="text/css">
.prop-grid .row {
padding: 10px 0;
}
.e-kanban .card-template-wrap td {
background: none !important;
}
.e-kanban .card-template-wrap .CardHeader {
font-weight: 500;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>LOADING....</div>
<div id='container'>
<div class="content-wrapper">
<div id="Kanban"></div>
</div>
</div>
</body>
</html>
Selection
Kanban board allows to select single and multiple selection of cards when mouse or keyboard interactions using selectionType
property. The property contains following types.
- None: No cards are allowed to select from Kanban board.
- Single: Only one card allowed to select at a time in the Kanban board.
- Multiple: Multiple cards are allowed to select in a board.
Multiple Selection
Select the multiple cards randomly using Ctrl + mouse click and select the multiple cards continuously using Shift + mouse click action on Kanban board. Set Multiple
in selectionType
to enable the multiple selection in a board.
import { Kanban } from '@syncfusion/ej2-kanban';
import { kanbanData } from './datasource.ts';
let kanbanObj: Kanban = new Kanban({
dataSource: kanbanData,
keyField: 'Status',
columns: [
{ headerText: 'Backlog', keyField: 'Open' },
{ headerText: 'In Progress', keyField: 'InProgress' },
{ headerText: 'Testing', keyField: 'Testing' },
{ headerText: 'Done', keyField: 'Close' }
],
cardSettings: {
contentField: 'Summary',
headerField: 'Id',
selectionType: 'Multiple'
}
});
kanbanObj.appendTo('#Kanban');
<!DOCTYPE html>
<html lang="en">
<head>
<title>Multiple Cards Selection</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Kanban multiple cards selection" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-dropdowns/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-layouts/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-kanban/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js" type="text/javascript"></script>
<script src="systemjs.config.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>LOADING....</div>
<div id='container'>
<div class="content-wrapper">
<div id="Kanban"></div>
</div>
</div>
</body>
</html>