The Kanban provides built-in support to add, edit and delete a card using dialog module. User can edit a card using the following ways.
When double-click on the cards, the dialog is opened with below fields to edit a card. This dialog contains Delete
, Save
and Cancel
buttons.
Save
button.Delete
button.Cancel
button to cancel the editing action.The dialog displays with the following fields which mapped to dialog fields by default.
Key | Type | Text |
---|---|---|
cardSettings.headerField | Input | ID |
keyField | DropDown | - |
cardSettings.contentField | TextArea | - |
cardSettings.priority(If applicable) | Numeric | - |
swimlaneSettings.keyField(If applicable) | DropDown | - |
var kanbanObj = new ej.kanban.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',
}
});
kanbanObj.appendTo('#Kanban');
<!DOCTYPE html><html lang="en"><head>
<title>Kanban Cards</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Kanban Cards">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-inputs/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-dropdowns/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-layouts/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-navigations/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-kanban/styles/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div class="content-wrapper">
<div id="Kanban"></div>
</div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
You can change the default fields of dialog using fields
property inside the dialogSettings
property. The key
property used to map the dataSource value and rendered the corresponding component based on specified type
property.
The following types are available in dialog fields.
If
type
is not defined in the fields, then it renders as the HTML input element in dialog.
var kanbanObj = new ej.kanban.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'
},
dialogSettings: {
fields: [
{ key: 'Id', type: 'Input' },
{ key: 'Status', type: 'DropDown' },
{ key: 'Assignee', type: 'DropDown' },
{ key: 'Estimate', type: 'Numeric' },
{ key: 'Summary', type: 'TextArea' }
]
}
});
kanbanObj.appendTo('#Kanban');
<!DOCTYPE html><html lang="en"><head>
<title>Kanban Custom Label Dialog</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Kanban Custom Label Dialog">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-inputs/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-dropdowns/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-layouts/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-navigations/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-kanban/styles/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div class="content-wrapper">
<div id="Kanban"></div>
</div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
By default, the fields key
mapping value is considered as a label
and you can change this label by using text
property.
var kanbanObj = new ej.kanban.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'
},
dialogSettings: {
fields: [
{ text: 'ID', key: 'Id', type: 'Input' },
{ key: 'Status', type: 'DropDown' },
{ key: 'Assignee', type: 'DropDown' },
{ key: 'Estimate', type: 'Numeric' },
{ key: 'Summary', type: 'TextArea' }
]
}
});
kanbanObj.appendTo('#Kanban');
<!DOCTYPE html><html lang="en"><head>
<title>Kanban Label Dialog</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Kanban Label Dialog">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-inputs/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-dropdowns/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-layouts/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-navigations/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-kanban/styles/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div class="content-wrapper">
<div id="Kanban"></div>
</div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
The dialog fields can be validated while click on the Save
button. This can be achieved by using validationRules
property.
var kanbanObj = new ej.kanban.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'
},
dialogSettings: {
fields: [
{ text: 'ID', key: 'Id', type: 'Input' },
{ key: 'Status', type: 'DropDown' },
{ key: 'Assignee', type: 'DropDown' },
{ key: 'Estimate', type: 'Numeric', validationRules: { range: [0, 1000] } },
{ key: 'Summary', type: 'TextArea', validationRules: { required: true } }
]
}
});
kanbanObj.appendTo('#Kanban');
<!DOCTYPE html><html lang="en"><head>
<title>Kanban Dialog Fields Validation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Kanban Dialog Fields Validation">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-inputs/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-dropdowns/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-layouts/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-navigations/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-kanban/styles/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div class="content-wrapper">
<div id="Kanban"></div>
</div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Using the dialog template, you can render your own dialog by defining the template
property. Initialize the template as SCRIPT element Id or HTML string which holds the template and map it to the template property.
var kanbanObj = new ej.kanban.Kanban({
dataSource: kanbanData,
keyField: 'Status',
columns: [
{ headerText: 'Backlog', keyField: 'Open' },
{ headerText: 'In Progress', keyField: 'InProgress' },
{ headerText: 'Done', keyField: 'Close' }
],
cardSettings: {
contentField: 'Summary',
headerField: 'Id'
},
dialogSettings: {
template: '#dialogTemplate'
},
dialogOpen: onDialogOpen
});
kanbanObj.appendTo('#Kanban');
var statusData = ['Open', 'InProgress', 'Close'];
var assigneeData = ['Nancy Davloio', 'Andrew Fuller', 'Janet Leverling',
'Steven walker', 'Robert King', 'Margaret hamilt', 'Michael Suyama'];
var priorityData = ['Low', 'Normal', 'Critical', 'Release Breaker', 'High'];
function onDialogOpen(args) {
if (args.requestType !== 'Delete') {
var curData = args.data;
var filledTextBox = new ej.inputs.TextBox({});
filledTextBox.appendTo(args.element.querySelector('#Id'));
var numericObj = new ej.inputs.NumericTextBox({
value: curData.Estimate, placeholder: 'Estimate'
});
numericObj.appendTo(args.element.querySelector('#Estimate'));
var statusDropObj = new ej.dropdowns.DropDownList({
value: curData.Status, popupHeight: '300px',
dataSource: statusData, fields: { text: 'Status', value: 'Status' }, placeholder: 'Status'
});
statusDropObj.appendTo(args.element.querySelector('#Status'));
var assigneeDropObj = new ej.dropdowns.DropDownList({
value: curData.Assignee, popupHeight: '300px',
dataSource: assigneeData, fields: { text: 'Assignee', value: 'Assignee' }, placeholder: 'Assignee'
});
assigneeDropObj.appendTo(args.element.querySelector('#Assignee'));
var priorityObj = new ej.dropdowns.DropDownList({
value: curData.Priority, popupHeight: '300px',
dataSource: priorityData, fields: { text: 'Priority', value: 'Priority' }, placeholder: 'Priority'
});
priorityObj.appendTo(args.element.querySelector('#Priority'));
var textareaObj = new ej.inputs.TextBox({
placeholder: 'Summary',
multiline: true
});
textareaObj.appendTo(args.element.querySelector('#Summary'));
}
}
var count = 31;
document.getElementById('addNew').onclick = function () {
var curData = {
Id: 'Task ' + count, Status: 'Open', Priority: 'Normal', Assignee: 'Andrew Fuller', Estimate: 0, Tags: '', Summary: ''
};
kanbanObj.openDialog('Add', curData);
count++;
};
<!DOCTYPE html><html lang="en"><head>
<title>Kanban Dialog Template</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Kanban Dialog Template">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-inputs/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-dropdowns/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-layouts/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-navigations/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-kanban/styles/material.css" rel="stylesheet">
<script id="dialogTemplate" type="text/x-template">
<table>
<tbody>
<tr>
<td class="e-label">ID</td>
<td>
<input id="Id" name="Id" type="text" class="e-field" value="${Id}" disabled required/>
</td>
</tr>
<tr>
<td class="e-label">Status</td>
<td>
<input type="text" name="Status" id="Status" class="e-field" value=${Status} required />
</td>
</tr>
<tr>
<td class="e-label">Assignee</td>
<td>
<input type="text" name="Assignee" id="Assignee" class="e-field" value=${Assignee} />
</td>
</tr>
<tr>
<td class="e-label">Priority</td>
<td>
<input type="text" name="Priority" id="Priority" class="e-field" value=${Priority} />
</td>
</tr>
<tr>
<td class="e-label">Summary</td>
<td>
<textarea type="text" name="Summary" id="Summary" class="e-field" value=${Summary}>${Summary}</textarea>
<span class="e-float-line"></span>
</td>
</tr>
</tbody>
</table>
</script>
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div class="content-wrapper">
<div id="Kanban"></div>
</div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
The Kanban allows to prevent to open a dialog on card double-click by enabling args.cancel
in dialogOpen
event.
var kanbanObj = new ej.kanban.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'
},
dialogOpen: 'dialogOpen'
});
kanbanObj.appendTo('#Kanban');
function dialogOpen(args) {
args.cancel = true;
}
<!DOCTYPE html><html lang="en"><head>
<title>Kanban Prevent Dialog Open</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Kanban Prevent Dialog Open">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-inputs/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-dropdowns/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-layouts/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-navigations/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet">
<link href="//cdn.syncfusion.com/ej2/ej2-kanban/styles/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div class="content-wrapper">
<div id="Kanban"></div>
</div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
The modified card data can be persisted in the database using the RESTful web services. All the CRUD operations in the Kanban are done through DataManager
. The DataManager
has an option to bind all the CRUD related data in server-side.
For your information, the ODataAdaptor persists data in the server as per OData protocol.
In the below section covers how to get the edited data details on the server-side using the UrlAdaptor
.
You can use the UrlAdaptor
of DataManager
when binding data source for remote data. In the initial load of Kanban, data are fetched from remote data and bound to the Kanban using url
property of DataManager
.
Using the crudUrl
property, the controller action URL can be specified to perform all the CRUD operations at server-side using a single method instead of specifying separate controller action method for CRUD (create, update and delete) operations. The action parameter of crudUrl
is used to get the corresponding CRUD action.
The following code example describes the above behavior.
import { Kanban } from '@syncfusion/ej2-kanban';
import { DataManager, UrlAdaptor } from '@syncfusion/ej2-data';
let data: DataManager = new DataManager({
url: "DataSource",
crudUrl: "UpdateData",
adaptor: new UrlAdaptor
});
let kanbanObj: Kanban = new Kanban({
dataSource: data,
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'
}
});
kanbanObj.appendTo('#Kanban');
The server-side controller code to handle the CRUD operations are as follows.
private NORTHWNDEntities db = new NORTHWNDEntities();
public ActionResult DataSource() {
var DataSource = db.Tasks.ToList();
return Json(DataSource, JsonRequestBehavior.AllowGet);
}
public ActionResult UpdateData(EditParams param) {
if (param.action == "insert" || (param.action == "batch" && param.added != null)) {
if (param.action == "insert") {
db.Tasks.Add(param.value);
} else {
foreach (var temp in param.added) {
db.Tasks.Add(temp);
}
}
}
if (param.action == "update" || (param.action == "batch" && param.changed != null)) {
if (param.action == "update") {
Task old = db.Tasks.Where(o => o.Id == param.value.Id).SingleOrDefault();
if (old != null) {
db.Entry(old).CurrentValues.SetValues(param.value);
}
} else {
foreach (var temp in param.changed) {
Task old = db.Tasks.Where(o => o.Id == temp.Id).SingleOrDefault();
if (old != null) {
db.Entry(old).CurrentValues.SetValues(temp);
}
}
}
}
if (param.action == "remove" || (param.action == "batch" && param.deleted != null)) {
if (param.action == "remove") {
int key = Convert.ToInt32(param.key);
db.Tasks.Remove(db.Tasks.Where(o => o.Id == key).SingleOrDefault());
} else {
foreach (var temp in param.deleted) {
db.Tasks.Remove(db.Tasks.Where(o => o.Id == temp.Id).SingleOrDefault());
}
}
}
db.SaveChanges();
var data = db.Tasks.ToList();
return Json(data, JsonRequestBehavior.AllowGet);
}
public class EditParams {
public string key { get; set; }
public string action { get; set; }
public List<Tasks> added { get; set; }
public List<Tasks> changed { get; set; }
public List<Tasks> deleted { get; set; }
public Tasks value { get; set; }
}