How To Add Kanban Board In Angular Application

Introduction

 
In this article, we will learn how to create a kanban board in a Angular 10 Application using Syncfusion kanban component.A kanban board is a tool designed for visualization of data.
 
According to official website,
 
A Kanban board is one of the tools that can be used to implement Kanban to manage work at a personal or organizational level. Kanban boards visually depict work at various stages of a process using cards to represent work items and columns to represent each stage of the process. Cards are moved from left to right to show progress and to help coordinate teams performing the work. A Kanban board may be divided into horizontal "swimlanes" representing different kinds of work or different teams performing the work.
 

Create a Angular Project

 
Create an Angular project by using the following command. 
  1. ng new Kanbandata  
Now install Syncfusion kanban , To install Kanban and its dependent packages, use the following command. 
  1. npm install @syncfusion/ej2-angular-kanban  
Now import  Kanban module in app.module.ts file ,add the following code in this file.
  1. import { NgModule } from '@angular/core';  
  2. import { BrowserModule } from '@angular/platform-browser';  
  3. import { HttpClientModule } from "@angular/common/http";  
  4. import { AppComponent } from './app.component';  
  5. import { KanbanAllModule } from '@syncfusion/ej2-angular-kanban';  
  6. @NgModule({  
  7.   declarations: [  
  8.     AppComponent  
  9.   ],  
  10.   imports: [  
  11.     BrowserModule,KanbanAllModule,HttpClientModule  
  12.   ],  
  13.   providers: [],  
  14.   bootstrap: [AppComponent]  
  15. })  
  16. export class AppModule { }  
Now open app.component.ts file and add the following code, 
  1. import { Component, ViewChild } from '@angular/core';  
  2. import { extend } from '@syncfusion/ej2-base';  
  3. import { KanbanComponent, CardSettingsModel } from '@syncfusion/ej2-angular-kanban';  
  4. import { HttpClient } from "@angular/common/http";  
  5. @Component({  
  6.   selector: 'app-root',  
  7.   templateUrl: './app.component.html',  
  8.   styleUrls: ['./app.component.css']  
  9. })  
  10. export class AppComponent {  
  11.   @ViewChild('kanbanObj') kanbanObj: KanbanComponent;  
  12.   public cardSettings: CardSettingsModel = {  
  13.     headerField: 'Id'  
  14.   };  
  15.   headerdata: any  
  16.   BoradData1: Object;  
  17.   
  18.   constructor(private http: HttpClient) {  
  19.   
  20.   }  
  21.   ngOnInit() {  
  22.     this.http.get('https://localhost:44314/Api/EmployeeInfo/Getemployeeinfo').subscribe(result => {  
  23.       this.BoradData1 = result;  
  24.       console.log(this.BoradData1);  
  25.     })  
  26.     this.headerdata = [  
  27.       { text: 'Jaipur', key: 'Jaipur' },  
  28.       { text: 'Delhi', key: 'Delhi' },  
  29.       { text: 'Bangalore', key: 'Bangalore' },  
  30.       { text: 'Pune', key: 'Pune' },   
  31.     ]  
  32.   }  
  33. }  
Now open app.component.Html file and add the following code,
  1. <div class="row" style="margin-top:10px;margin-bottom: 24px;">  
  2.   <div class="col-sm-12 btn btn-success">  
  3.     How To Add Kanban Board in Angular Application  
  4.   </div>  
  5. </div>  
  6. <div class="control-section">  
  7.   <div class="col-lg-12 content-wrapper">  
  8.     <div id='container'>  
  9.       <ejs-kanban #kanbanObj cssClass='kanban-swimlane' keyField='City' [dataSource]='BoradData1'  
  10.         [cardSettings]='cardSettings'>  
  11.         <e-columns>  
  12.           <e-column *ngFor="let data of headerdata" headerText='{{data.text}}' keyField='{{data.key}}'  
  13.             allowToggle='true'></e-column>  
  14.         </e-columns>  
  15.         <ng-template #cardSettingsTemplate let-data>  
  16.           <div class="card" style="width:400px">  
  17.             <div class="card-body">  
  18.               <h6 class="card-title">{{data.Name}}</h6>  
  19.               <p class="card-text">{{data.Tech}}</p>  
  20.               <p class="card-text">{{data.Age}}</p>  
  21.             </div>  
  22.           </div>  
  23.         </ng-template>  
  24.       </ejs-kanban>  
  25.     </div>  
  26.   </div>  
  27. </div>  
Now open app.component.css file and add the following css classes,
  1. .card {  
  2.     position: relative;  
  3.     display: flex;  
  4.     flex-direction: column;  
  5.     min-width: 0;  
  6.     word-wrap: break-word;  
  7.     background-color: #fff;  
  8.     background-clip: border-box;  
  9.     border: 0px solid rgba(0,0,0,.125) !important;  
  10.     border-radius: .25rem;  
  11. }  
  12. p {  
  13.     margin-top: 0;  
  14.     margin-bottom: 0rem !important  
  15. }  
  16. .kanban-transition .e-card-kanban-image {  
  17.     height: 45px;  
  18.     width: 45px;  
  19.     margin-left: auto;  
  20.   }  
  21.   .kanban-transition .e-card-kanban-image img {  
  22.     height: 100%;  
  23.     width: 100%;  
  24.     border-radius: 50%;  
  25.   }  
  26.   .kanban-transition .e-card .e-card-tag-field {  
  27.     background: #ececec;  
  28.     color: #6b6b6b;  
  29.     margin-right: 5px;  
  30.     line-height: 1.1;  
  31.     font-size: 13px;  
  32.     border-radius: 3px;  
  33.     padding: 4px;  
  34.   }  
  35.   .kanban-transition .e-card-custom-footer {  
  36.     display: flex;  
  37.     padding: 0px 12px 12px;  
  38.     line-height: 1;  
  39.     height: 35px;  
  40.   }  
  41.   .kanban-transition .e-card td {  
  42.     background-color: #fff;  
  43.   }  
  44.   .kanban-transition .e-card .e-card-content {  
  45.     display: flex;  
  46.   }  
  47.   .kanban-transition .e-card .e-text {  
  48.     width: fit-content;  
  49.   }  
Now install Bootstrap by using following command.
  1. npm install bootstrap --save    
Now open styles.css file and add Bootstrap file reference. To add reference in styles.css file add this line. 
  1. @import '~bootstrap/dist/css/bootstrap.min.css';   

Create a database and table

 
Open SQL Server Management Studio, create a database named Employee and in this database, create a table. Give that table a name like Employeeinfo
  1. CREATE TABLE [dbo].[EmployeeInfo](    
  2.     [Id] [int] IDENTITY(1,1) NOT NULL,    
  3.     [Name] [nvarchar](50) NULL,    
  4.     [City] [nvarchar](50) NULL,    
  5.     [Age] [nvarchar](50) NULL,    
  6.     [Tech] [nvarchar](50) NULL,    
  7.  CONSTRAINT [PK_EmployeeInfo] PRIMARY KEY CLUSTERED     
  8. (    
  9.     [Id] ASC    
  10. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFFON [PRIMARY]    
  11. ON [PRIMARY]    
  12. GO     

Create a Web API Project

 
Open Visual Studio and click on create a new project:
 
 
Now select the project and click on the Next button.
 
 
Now select the project name and project location and click on the Create button.
 
 
Choose the template as Web API.
 
 
Right-click the Models folder from Solution Explorer and go to Add >> New Item >> data
 
 
Click on the "ADO.NET Entity Data Model" option and click "Add".
 
 
Select EF Designer from the database and click the "Next" button.
 
 
Add the connection properties, select the database name on the next page, and click OK. 
 
 
Check the "Table" checkbox. The internal options will be selected by default. Now, click the "Finish" button.
 
 
Right-click on the Controllers folder and add a new controller. Name it "Employeeinfo controller" and add the following namespace in the Employeeinfo controller.
  1. using EmployeeInfo.Models;  
Now create a method to Get data from the database.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Net;  
  5. using System.Net.Http;  
  6. using System.Web.Http;  
  7. using EmployeeInfo.Models;  
  8.   
  9. namespace EmployeeInfo.Controllers  
  10. {  
  11.     public class EmployeeInfoController : ApiController  
  12.     {  
  13.         EmployeeEntities DB = new EmployeeEntities();  
  14.         [HttpGet]  
  15.         public object Getemployeeinfo()  
  16.         {  
  17.             return DB.EmployeeInfoes.ToList();  
  18.         }  
  19.     }  
  20. }  
Now, let's enable CORS. Go to Tools, open NuGet Package Manager, search for CORS, and install the "Microsoft.Asp.Net.WebApi.Cors" package. Open Webapiconfig.cs and add the following lines,
  1. EnableCorsAttribute cors = new EnableCorsAttribute("*""*""*");            
  2. config.EnableCors(cors);   
Now go to vs code and run the project using the following command 'npm start'.
 
 
we can drag and drop data.
 
 

Summary

 
In this article, we learned how to create a kanban board in a Angular 10 Application.


Similar Articles