In this article, we will learn about PrimeNG Picklist and DataView. The Picklist component is used to shift the data from one list to another list. It provides default buttons to move the data between different lists.
In my previous article, we have learned about PrimeNG. You can check my previous article from the below mentioned link.
Step 1
- CREATE TABLE [dbo].[TeamA](
- [ID] [int] IDENTITY(1,1) NOT NULL,
- [Name] [varchar](50) NULL,
- PRIMARY KEY CLUSTERED
- (
- [ID] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
- GO
- SET ANSI_PADDING OFF
- GO
- CREATE TABLE [dbo].[TeamB](
- [ID] [int] IDENTITY(1,1) NOT NULL,
- [Name] [varchar](50) NULL,
- PRIMARY KEY CLUSTERED
- (
- [ID] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
- GO
- SET ANSI_PADDING OFF
- GO
Step 2
Step 3

- 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 and select database name on the next page and click OK.
- Check the Tables checkboxes.
- The internal options will be selected by default. Now, click the "Finish" button.

Step 4
- public class TeamOne
- {
- public int ID { get; set; }
- public string Name { get; set; }
- }
- using PrimeNGDemo.Models;
Now, add a method to fetch data from the database.
- [HttpGet]
- [Route("GetTeam")]
- public object GetTeam()
- {
- angularDemEntities DB = new angularDemEntities();
- return Json(DB.TeamAs.ToList());
- }
Add two new methods for inserting the data into database tables and add the following lines of code.
- [Route("Inserts")]
- [HttpPost]
- public void InsertTeam(List<TeamOne> obj)
- {
- angularDemEntities DB = new angularDemEntities();
- foreach (var item in obj)
- {
- TeamA obA = new TeamA { ID = item.ID, Name = item.Name };
- DB.TeamAs.Add(obA);
- DB.SaveChanges();
- }
- }
- [Route("InsertB")]
- [HttpPost]
- public void InsertTeamB(List<TeamOne> Obj)
- {
- try
- {
- angularDemEntities DB = new angularDemEntities();
- foreach (var item in Obj)
- {
- TeamB ObjB = new TeamB
- {
- ID = item.ID,
- Name = item.Name
- };
- DB.TeamBs.Add(ObjB);
- DB.SaveChanges();
- }
- }
- catch(Exception ex)
- {
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Web.Http;
- using PrimeNGDemo.Models;
- namespace PrimeNGDemo.Controllers
- {
- [RoutePrefix("Api/prime")]
- public class PrimeNGController : ApiController
- {
- [HttpGet]
- [Route("GetTeam")]
- public object GetTeam()
- {
- angularDemEntities DB = new angularDemEntities();
- return Json(DB.TeamAs.ToList());
- }
- [Route("Inserts")]
- [HttpPost]
- public void InsertTeam(List<TeamOne> obj)
- {
- angularDemEntities DB = new angularDemEntities();
- foreach (var item in obj)
- {
- TeamA obA = new TeamA { ID = item.ID, Name = item.Name };
- DB.TeamAs.Add(obA);
- DB.SaveChanges();
- }
- }
- [Route("InsertB")]
- [HttpPost]
- public void InsertTeamB(List<TeamOne> Obj)
- {
- try
- {
- angularDemEntities DB = new angularDemEntities();
- foreach (var item in Obj)
- {
- TeamB ObjB = new TeamB
- {
- ID = item.ID,
- Name = item.Name
- };
- DB.TeamBs.Add(ObjB);
- DB.SaveChanges();
- }
- }
- catch(Exception ex)
- {
- }
- }
- }
- }
Step 7
Step 8
ng new PrimeUIDemo
Step 9
- npm install primeng --save
- npm install primeicons --save
- @import '../node_modules/primeng/resources/themes/omega/theme.css';
- @import '../node_modules/primeicons/primeicons.css';
- @import '../node_modules/primeng/resources/primeng.min.css';
Step 11
- export class Team {
- Id:string;
- Name:string;
- }
Step 13
- import { Injectable } from '@angular/core';
- import { HttpHeaders, HttpClient } from '@angular/common/http';
- import { Team } from "./team";
- @Injectable({
- providedIn: 'root'
- })
- export class TeamService {
- Url = "http://localhost:63683/Api/prime/";
- constructor(private http: HttpClient) { }
- GetTeam() {
- debugger;
- return this.http.get<any>(this.Url + "GetTeam");
- }
- PostTeam(Team: Team) {
- debugger;
- const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };
- return this.http.post<Team[]>(this.Url+"Inserts" , Team, httpOptions);
- }
- PostTeamB(team: Team) {
- debugger;
- const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };
- return this.http.post<Team[]>(this.Url+"/InsertB", team, httpOptions)
- }
- }
- import { Component, OnInit } from '@angular/core';
- import { TeamService } from "../team.service";
- import { Team } from "../team";
- import { TableModule } from 'primeng/table';
- @Component({
- selector: 'app-pick-list',
- templateUrl: './pick-list.component.html',
- styleUrls: ['./pick-list.component.css']
- })
- export class PickListComponent implements OnInit {
- constructor(private teamService: TeamService) { }
- TeamA: any;
- TeamB: any;
- ShotTeam: any;
- ShotTeamA: any;
- ngOnInit() {
- this.GetTeam();
- this.TeamB = [];
- }
- GetTeam() {
- debugger;
- this.teamService.GetTeam().subscribe(
- result => {
- this.TeamA = result;
- this.ShotTeamA = this.TeamA;
- }
- );
- }
- CreateTeam() {
- this.teamService.PostTeam(this.TeamA).subscribe(
- data => {
- }
- )
- }
- CreateTeamB() {
- debugger;
- this.teamService.PostTeamB(this.TeamB).subscribe(
- data => {
- }
- )
- }
- ShowTable() {
- debugger;
- this.ShotTeam = this.TeamB;
- debugger;
- }
- }
- <p-pickList [source]="TeamA" [target]="TeamB" sourceHeader="Team A" targetHeader="Team B" [responsive]="true"
- filterBy="Name" dragdrop="true" sourceFilterPlaceholder="Search by Name" targetFilterPlaceholder="Search by Name"
- [sourceStyle]="{'height':'200px'}" [targetStyle]="{'height':'200px'}">
- <ng-template let-tm pTemplate="TeamA">
- <div class="ui-helper-clearfix">
- <div style="font-size:14px;float:right;margin:15px 5px 0 0">{{tm.Name}}</div>
- </div>
- </ng-template>
- </p-pickList>
- <br>
- <div style="text-align:center">
- <button pButton type="button" label="Display Data" (click)="ShowTable()"></button>
- </div>
- <br>
- <p-dataView #dv [value]="ShotTeam" [paginator]="true" [rows]="2">
- <ng-template let-team pTemplate="listItem">
- <div class="ui-g" style="padding: 2em;border-bottom: 1px solid #d9d9d9">
- <div class="ui-g-12 ui-md-8">
- <div class="ui-g">
- <div class="ui-g-2 ui-sm-6">ID: </div>
- <div class="ui-g-10 ui-sm-6"><b>{{team.ID}}</b></div>
- <div class="ui-g-2 ui-sm-6">Name: </div>
- <div class="ui-g-10 ui-sm-6"><b>{{team.Name}}</b></div>
- </div>
- </div>
- </div>
- </ng-template>
- </p-dataView>
- <br>
- <div style="text-align:center">
- <button pButton type="button" label="Send Into Team A" (click)="CreateTeam()"></button>
- </div>
- <br>
- <div style="text-align:center">
- <button pButton type="button" label="Send Into Team B" (click)="CreateTeamB()"></button>
- </div>
- import {DataViewModule} from 'primeng/dataview';
- import {ButtonModule} from 'primeng/button';
- import {PickListModule} from 'primeng/picklist';
- import { BrowserModule } from '@angular/platform-browser';
- import { NgModule } from '@angular/core';
- import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
- import { AppRoutingModule } from './app-routing.module';
- import { AppComponent } from './app.component';
- import { AccordionModule } from 'primeng/components/accordion/accordion';
- import {OrderListModule} from 'primeng/orderlist';
- import { PickListComponent } from './pick-list/pick-list.component';
- import { HttpClientModule } from '@angular/common/http';
- import { TeamComponent } from './team/team.component';
- import {DataViewModule} from 'primeng/dataview';
- import { DataTableModule } from 'primeng/primeng';
- import {ButtonModule} from 'primeng/button';
- import {PickListModule} from 'primeng/picklist';
- @NgModule({
- declarations: [
- AppComponent,
- PickListComponent,
- TeamComponent
- ],
- imports: [
- BrowserModule,HttpClientModule,DataTableModule,ButtonModule,
- AppRoutingModule,BrowserAnimationsModule,AccordionModule,OrderListModule,PickListModule,DataViewModule
- ],
- providers: [],
- bootstrap: [AppComponent]
- })
- export class AppModule { }
Click on the arrow button to move data from one list to another and reorder the data in the list by clicking on the button given in the left side.

Martin GoffPosted Oct 9, 2019, 9:08 AM
Where is the definition of “angularDemEntities”?
Cris GomezPosted Apr 12, 2019, 1:48 PM
Great tutorial, well done.