Angular PrimeNG Table Selection
Last Updated :
26 Apr, 2025
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use Table Filtering in Angular PrimeNG.
Angular PrimeNG Table Selection enables single and multiple node selection modes in the Table component so that we can select single or multiple table nodes at once. So, using table selection, we can make the table more user-friendly and efficient.
Angular PrimeNG Table Selection properties:
- selectionMode: It is the selection mode by which we can select the table nodes.
Syntax:
<p-table
#tableref
selectionMode="single | multiple">
<ng-template pTemplate="body">
<tr [pSelectableRow]="row">
...
</tr>
</ng-template>
</p-table>
Creating Angular application & Module Installation:
Step 1: Create an Angular application using the following command.
ng new appname
Step 2: After creating your project folder i.e. appname, move to it using the following command.
cd appname
Step 3: Install PrimeNG in your given directory.
npm install primeng --save
npm install primeicons --save
Project Structure: It will look like the following:

Project Structure
Example 1: Below is a simple example demonstrating the use of the Angular PrimeNG Table Selection.
HTML
< h2 style = "color: green" >GeeksforGeeks</ h2 >
< h4 >Angular PrimeNG Table Selection</ h4 >
< p-table
#myTab
[value]="tableData"
[scrollable]="true"
scrollHeight = "400px"
selectionMode = "single" >
< ng-template pTemplate = "header" >
< tr >
< th >First Name</ th >
< th >Last Name</ th >
< th >Age</ th >
</ tr >
</ ng-template >
< ng-template pTemplate = "body" let-people>
< tr [pSelectableRow]="people">
< td >
{{ people.firstname }}
</ td >
< td >
{{ people.lastname }}
</ td >
< td >
{{ people.age }}
</ td >
</ tr >
</ ng-template >
</ p-table >
|
Javascript
import { Component } from "@angular/core" ;
interface People {
firstname?: string;
lastname?: string;
age?: string;
}
@Component({
selector: "app-root" ,
templateUrl: "./app.component.html" ,
})
export class AppComponent {
tableData: People[] = [];
cols: any[] = [];
constructor() { }
ngOnInit() {
this .cols = [
{ field: "firstname" , header: "First Name" },
{ field: "lastname" , header: "Last Name" },
{ field: "age" , header: "Age" },
];
this .tableData = [
{
firstname: "David" ,
lastname: "ace" ,
age: "40" ,
},
{
firstname: "AJne" ,
lastname: "west" ,
age: "40" ,
},
{
firstname: "Mak" ,
lastname: "Lame" ,
age: "40" ,
},
{
firstname: "Peter" ,
lastname: "raw" ,
age: "40" ,
},
{
firstname: "Kane" ,
lastname: "James" ,
age: "40" ,
},
];
}
}
|
Javascript
import { NgModule } from '@angular/core' ;
import { BrowserModule }
from '@angular/platform-browser' ;
import { FormsModule } from '@angular/forms' ;
import { HttpClientModule }
from '@angular/common/http' ;
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations' ;
import { AppComponent } from './app.component' ;
import { TableModule } from 'primeng/table' ;
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
TableModule,
HttpClientModule,
FormsModule
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule { }
|
Output:
Example 2: Below is another example demonstrating the use of the Angular PrimeNG Table Selection. In this example, we are using multiple selections.
HTML
< h2 style = "color: green" >GeeksforGeeks</ h2 >
< h4 >Angular PrimeNG Table Selection</ h4 >
< p-table
#myTab
[value]="tableData"
[scrollable]="true"
scrollHeight = "400px"
selectionMode = "multiple" >
< ng-template pTemplate = "header" >
< tr >
< th >First Name</ th >
< th >Last Name</ th >
< th >Age</ th >
</ tr >
</ ng-template >
< ng-template pTemplate = "body" let-people>
< tr [pSelectableRow]="people">
< td >
{{ people.firstname }}
</ td >
< td >
{{ people.lastname }}
</ td >
< td >
{{ people.age }}
</ td >
</ tr >
</ ng-template >
</ p-table >
|
Javascript
import { Component } from "@angular/core" ;
interface People {
firstname?: string;
lastname?: string;
age?: string;
}
@Component({
selector: "app-root" ,
templateUrl: "./app.component.html" ,
})
export class AppComponent {
tableData: People[] = [];
cols: any[] = [];
constructor() { }
ngOnInit() {
this .cols = [
{ field: "firstname" , header: "First Name" },
{ field: "lastname" , header: "Last Name" },
{ field: "age" , header: "Age" },
];
this .tableData = [
{
firstname: "David" ,
lastname: "ace" ,
age: "40" ,
},
{
firstname: "AJne" ,
lastname: "west" ,
age: "40" ,
},
{
firstname: "Mak" ,
lastname: "Lame" ,
age: "40" ,
},
{
firstname: "Peter" ,
lastname: "raw" ,
age: "40" ,
},
{
firstname: "Kane" ,
lastname: "James" ,
age: "40" ,
},
];
}
}
|
Javascript
import { NgModule } from '@angular/core' ;
import { BrowserModule }
from '@angular/platform-browser' ;
import { FormsModule } from '@angular/forms' ;
import { HttpClientModule }
from '@angular/common/http' ;
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations' ;
import { AppComponent } from './app.component' ;
import { TableModule } from 'primeng/table' ;
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
TableModule,
HttpClientModule,
FormsModule
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule { }
|
Output:
Example 3: Below is one more example demonstrating the use of the Angular PrimeNG Table Selection. In this example, we are using checkbox-based multiple selections.
HTML
< h2 style = "color: green" >GeeksforGeeks</ h2 >
< h4 >Angular PrimeNG Table Selection</ h4 >
< p-table
#myTab
[value]="tableData"
[scrollable]="true"
scrollHeight = "400px"
selectionMode = "multiple" >
< ng-template pTemplate = "header" >
< tr >
< th style = "width: 3rem" >
< p-tableHeaderCheckbox >
</ p-tableHeaderCheckbox >
</ th >
< th >First Name</ th >
< th >Last Name</ th >
< th >Age</ th >
</ tr >
</ ng-template >
< ng-template pTemplate = "body" let-people>
< tr [pSelectableRow]="people">
< td >
< p-tableCheckbox
[value]="people">
</ p-tableCheckbox >
</ td >
< td >
{{ people.firstname }}
</ td >
< td >
{{ people.lastname }}
</ td >
< td >
{{ people.age }}
</ td >
</ tr >
</ ng-template >
</ p-table >
|
Javascript
import { Component } from "@angular/core" ;
interface People {
firstname?: string;
lastname?: string;
age?: string;
}
@Component({
selector: "app-root" ,
templateUrl: "./app.component.html" ,
})
export class AppComponent {
tableData: People[] = [];
cols: any[] = [];
constructor() { }
ngOnInit() {
this .cols = [
{ field: "firstname" , header: "First Name" },
{ field: "lastname" , header: "Last Name" },
{ field: "age" , header: "Age" },
];
this .tableData = [
{
firstname: "David" ,
lastname: "ace" ,
age: "40" ,
},
{
firstname: "AJne" ,
lastname: "west" ,
age: "40" ,
},
{
firstname: "Mak" ,
lastname: "Lame" ,
age: "40" ,
},
{
firstname: "Peter" ,
lastname: "raw" ,
age: "40" ,
},
{
firstname: "Kane" ,
lastname: "James" ,
age: "40" ,
},
];
}
}
|
Javascript
import { NgModule } from '@angular/core' ;
import { BrowserModule }
from '@angular/platform-browser' ;
import { FormsModule } from '@angular/forms' ;
import { HttpClientModule }
from '@angular/common/http' ;
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations' ;
import { AppComponent } from './app.component' ;
import { TableModule } from 'primeng/table' ;
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
TableModule,
HttpClientModule,
FormsModule
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule { }
|
Output:
Example 4: Below is one more example demonstrating the use of the Angular PrimeNG Table Selection. In this example, we are using radio button-based selections.
HTML
< h2 style = "color: green" >GeeksforGeeks</ h2 >
< h4 >Angular PrimeNG Table Selection</ h4 >
< p-table
#myTab
[value]="tableData"
[scrollable]="true"
scrollHeight = "400px"
selectionMode = "multiple" >
< ng-template pTemplate = "header" >
< tr >
< th style = "width: 3rem" >
Radio Controls
</ th >
< th >First Name</ th >
< th >Last Name</ th >
< th >Age</ th >
</ tr >
</ ng-template >
< ng-template pTemplate = "body" let-people>
< tr [pSelectableRow]="people">
< td >
< p-tableRadioButton
[value]="people">
</ p-tableRadioButton >
</ td >
< td >
{{ people.firstname }}
</ td >
< td >
{{ people.lastname }}
</ td >
< td >
{{ people.age }}
</ td >
</ tr >
</ ng-template >
</ p-table >
|
Javascript
import { Component } from '@angular/core' ;
interface People {
firstname?: string;
lastname?: string;
age?: string;
}
@Component({
selector: 'app-root' ,
templateUrl: './app.component.html' ,
})
export class AppComponent {
tableData: People[] = [];
cols: any[] = [];
constructor() { }
ngOnInit() {
this .cols = [
{ field: 'firstname' , header: 'First Name' },
{ field: 'lastname' , header: 'Last Name' },
{ field: 'age' , header: 'Age' },
];
this .tableData = [
{
firstname: 'David' ,
lastname: 'ace' ,
age: '40' ,
},
{
firstname: 'AJne' ,
lastname: 'west' ,
age: '40' ,
},
{
firstname: 'Mak' ,
lastname: 'Lame' ,
age: '40' ,
},
{
firstname: 'Peter' ,
lastname: 'raw' ,
age: '40' ,
},
{
firstname: 'Kane' ,
lastname: 'James' ,
age: '40' ,
},
];
}
}
|
Javascript
import { NgModule } from '@angular/core' ;
import { BrowserModule }
from '@angular/platform-browser' ;
import { FormsModule } from '@angular/forms' ;
import { HttpClientModule }
from '@angular/common/http' ;
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations' ;
import { AppComponent } from './app.component' ;
import { TableModule } from 'primeng/table' ;
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
TableModule,
HttpClientModule,
FormsModule,
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule { }
|
Output:
Example 5: Below is one more example demonstrating the use of the Angular PrimeNG Table Selection. In this example, we are using events-based selections.
HTML
< h2 style = "color: green" >GeeksforGeeks</ h2 >
< h4 >Angular PrimeNG Table Selection</ h4 >
< p-table
#myTab
[value]="tableData"
[scrollable]="true"
scrollHeight = "400px"
(onRowSelect)="onRowSelect($event)">
< ng-template pTemplate = "header" >
< tr >
< th style = "width: 3rem" >
Radio Controls
</ th >
< th >First Name</ th >
< th >Last Name</ th >
< th >Age</ th >
</ tr >
</ ng-template >
< ng-template pTemplate = "body" let-people>
< tr [pSelectableRow]="people">
< td >
< p-tableRadioButton
[value]="people">
</ p-tableRadioButton >
</ td >
< td >
{{ people.firstname }}
</ td >
< td >
{{ people.lastname }}
</ td >
< td >
{{ people.age }}
</ td >
</ tr >
</ ng-template >
</ p-table >
|
Javascript
import { Component } from '@angular/core' ;
interface People {
firstname?: string;
lastname?: string;
age?: string;
}
@Component({
selector: 'app-root' ,
templateUrl: './app.component.html' ,
})
export class AppComponent {
tableData: People[] = [];
cols: any[] = [];
constructor() { }
ngOnInit() {
this .cols = [
{ field: 'firstname' , header: 'First Name' },
{ field: 'lastname' , header: 'Last Name' },
{ field: 'age' , header: 'Age' },
];
this .tableData = [
{
firstname: 'David' ,
lastname: 'ace' ,
age: '40' ,
},
{
firstname: 'AJne' ,
lastname: 'west' ,
age: '40' ,
},
{
firstname: 'Mak' ,
lastname: 'Lame' ,
age: '40' ,
},
{
firstname: 'Peter' ,
lastname: 'raw' ,
age: '40' ,
},
{
firstname: 'Kane' ,
lastname: 'James' ,
age: '40' ,
},
];
}
onRowSelect(event: any) {
alert( 'Row Selected' )
}
}
|
Javascript
import { NgModule } from '@angular/core' ;
import { BrowserModule }
from '@angular/platform-browser' ;
import { FormsModule } from '@angular/forms' ;
import { HttpClientModule }
from '@angular/common/http' ;
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations' ;
import { AppComponent } from './app.component' ;
import { TableModule } from 'primeng/table' ;
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
TableModule,
HttpClientModule,
FormsModule,
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule { }
|
Output:
Reference: https://primefaces.org/primeng/table/selection
Similar Reads
Angular PrimeNG Table Sections
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use Table Column Grouping in Angular PrimeNG. Angular PrimeNG Table
5 min read
Angular PrimeNG TreeTable Selection
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. It provides a lot of templates, components, theme design, an extensive icon library, and much more.
6 min read
Angular PrimeNG TabView Selection
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use the TabView Selection in Angular PrimeNG. We will also lear
3 min read
Angular PrimeNG Tree Selection
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use Tree Selection in Angular PrimeNG. Angular PrimeNG Tree Selecti
6 min read
Angular PrimeNG TreeTable Sections
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. It provides a lot of templates, components, theme design, an extensive icon library, and much more.
6 min read
Angular PrimeNG Table Styling
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use Table Styling in Angular PrimeNG. The Table component shows som
4 min read
Angular PrimeNG Table Sorting
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use Table Sorting in Angular PrimeNG. Angular PrimeNG Table Sorting
5 min read
Angular PrimeNG Tree Sections
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use Tree Sections in Angular PrimeNG. Angular PrimeNG Tree Sections
4 min read
Angular PrimeNG Table Style
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use TreeTable Column Resize in Angular PrimeNG. Angular PrimeNG Tab
4 min read
Angular PrimeNG Table Sticky
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will see how to use Table Sticky in Angular PrimeNG. The Table Sticky implements
5 min read