Open In App

Angular PrimeNG Table ColumnFilter Properties

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. In this article, we will see the Angular PrimeNG Table ColumnFilter Properties.

The Table component is used to display data in tabular format. The Table component has many properties provided with it that can be used to style and modify the content of the table to suit various needs. The ColumnFilter Properties is used to filter the data according to the filter the column data values.



Angular PrimeNG Table ColumnFilter Properties:

 



Syntax:

<th pSortableColumn="title">
    <div class="flex justify-content-between 
        align-items-center">
        Title
        <p-sortIcon field="title"></p-sortIcon>
        <p-columnFilter
            type="text"
            field="title"
            display="menu"
            class="ml-auto">
        </p-columnFilter>
    </div>
</th>

Creating Angular application & Module Installation:

Step 1: Create an Angular application using the following command.

ng new geeks_angular

Step 2: After creating your project folder i.e. geeks_angular, move to it using the following command.

cd geeks_angular

Step 3: Install PrimeNG in your given directory.

npm install primeng --save
npm install primeicons --save

Project Structure: The project structure will look like the following:

 

Example 1: In the following example, we have a Table with a Column filter.




<h1 style="color:green;text-align:center;">GeeksforGeeks</h1>
<h3>Angular PrimeNG Table ColumnFilter Properties</h3>
  
<p-table
    #dt
    [value]="tutorials"
    dataKey="title"
    [rowHover]="true"
    [showCurrentPageReport]="true"
    [filterDelay]="0"
    [globalFilterFields]="['title', 'category', 'rating']"
>
    <ng-template pTemplate="caption">
        <div class="table-header">List of Tutorials</div>
    </ng-template>
    <ng-template pTemplate="header">
        <tr>
            <th style="width: 3rem">
            <p-tableHeaderCheckbox></p-tableHeaderCheckbox>
            </th>
            <th pSortableColumn="title">
                <div class="flex justify-content-between align-items-center">
                    Title
                    <p-sortIcon field="title"></p-sortIcon>
                    <p-columnFilter
                        type="text"
                        field="title"
                        display="menu"
                        class="ml-auto">
                    </p-columnFilter>
                </div>
            </th>
            <th pSortableColumn="category">
                <div class="flex justify-content-between align-items-center">
                    Category
                    <p-sortIcon field="category"></p-sortIcon>
                    <p-columnFilter
                        type="text"
                        field="category"
                        display="menu"
                        class="ml-auto">
                    </p-columnFilter>
                </div>
            </th>
  
            <th pSortableColumn="rating">
                <div class="flex justify-content-between align-items-center">
                    Rating
                    <p-sortIcon field="rating"></p-sortIcon>
                    <p-columnFilter
                        type="numeric"
                        field="rating"
                        display="menu"
                        class="ml-auto">
                    </p-columnFilter>
                </div>
            </th>
        </tr>
    </ng-template>
  
    <ng-template pTemplate="body" let-tutorial>
        <tr class="p-selectable-row">
            <td>
                <p-tableCheckbox [value]="tutorial"> </p-tableCheckbox>
            </td>
            <td>
                <span class="p-column-title"> Title </span>
                {{ tutorial.title }}
            </td>
            <td>
                <span class="p-column-title"> Category </span>
                <span class="image-text">
                    {{ tutorial.category }}
                </span>
            </td>
            <td>
                <span class="p-column-title"> Rating </span>
                <span class="image-text">
                    {{ tutorial.rating }}
                </span>
            </td>
        </tr>
    </ng-template>
</p-table>




import { Component, OnInit, ViewChild } from '@angular/core';
import { Table } from 'primeng/table';
import { PrimeNGConfig } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
  
export class AppComponent {
    tutorials: Tutorial[];
    @ViewChild('dt') table: Table;
    constructor(private primengConfig: PrimeNGConfig) {}
  
    ngOnInit() {
        this.tutorials = [
            {
                title: 'Queue',
                category: 'Data Structure',
                rating: 8,
            },
            {
                title: 'Circularly LinkedList',
                category: 'Data Structure',
                rating: 1,
            },
            {
                title: 'Doubly LinkedList',
                category: 'Data Structure',
                rating: 3,
            },
            {
                title: 'Singly LinkedList',
                category: 'Data Structure',
                rating: 5,
            },
            {
                title: 'Doubly Ended Queue',
                category: 'Data Structure',
                rating: 10,
            },
            {
                title: 'Binary Search Tree',
                category: 'Data Structure',
                rating: 2,
            },
            {
                title: 'Red Black Tree',
                category: 'Data Structure',
                rating: 9,
            },
            {
                title: 'Breadth First Search',
                category: 'Graph',
                rating: 6,
            },
            {
                title: "Floyd's Cycle",
                category: 'Algorithm',
                rating: 7,
            },
            {
                title: 'Travelling Salesman Problem',
                category: 'Algorithm',
                rating: 4,
            },
            {
                title: 'Bellman Ford',
                category: 'Graph',
                rating: 8,
            },
            {
                title: 'KMP Algorithm',
                category: 'String',
                rating: 10,
            },
        ];
        this.primengConfig.ripple = true;
    }
}
export interface Tutorial {
    title?: string;
    category?: string;
    rating?: number;
}




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';
import { CalendarModule } from 'primeng/calendar';
import { SliderModule } from 'primeng/slider';
import { DialogModule } from 'primeng/dialog';
import { MultiSelectModule } from 'primeng/multiselect';
import { ContextMenuModule } from 'primeng/contextmenu';
import { ButtonModule } from 'primeng/button';
import { InputTextModule } from 'primeng/inputtext';
import { ProgressBarModule } from 'primeng/progressbar';
import { DropdownModule } from 'primeng/dropdown';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        TableModule,
        CalendarModule,
        SliderModule,
        DialogModule,
        MultiSelectModule,
        ContextMenuModule,
        DropdownModule,
        ButtonModule,
        InputTextModule,
        ProgressBarModule,
        HttpClientModule,
        FormsModule,
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
  
export class AppModule {}

Output:

 

Example 2: In the following example, there will be no apply button, the filters will be applied automatically.




<h1 style="color:green;text-align:center;">GeeksforGeeks</h1>
<h3>Angular PrimeNG Table ColumnFilter Properties</h3>
  
<p-table
    #dt
    [value]="tutorials"
    dataKey="title"
    [rowHover]="true"
    [showCurrentPageReport]="true"
    [filterDelay]="0"
    [globalFilterFields]="['title', 'category', 'rating']"
>
    <ng-template pTemplate="caption">
        <div class="table-header">List of Tutorials</div>
    </ng-template>
    <ng-template pTemplate="header">
        <tr>
            <th style="width: 3rem">
                <p-tableHeaderCheckbox></p-tableHeaderCheckbox>
            </th>
            <th pSortableColumn="title">
                <div class="flex justify-content-between align-items-center">
                    Title
                    <p-sortIcon field="title"></p-sortIcon>
                    <p-columnFilter
                        type="text"
                        field="title"
                        display="menu"
                        class="ml-auto"
                        [showClearButton]="false"
                        [showApplyButton]="false">
                    </p-columnFilter>
                </div>
            </th>
            <th pSortableColumn="category">
                <div class="flex justify-content-between align-items-center">
                    Category
                    <p-sortIcon field="category"></p-sortIcon>
                    <p-columnFilter
                        type="text"
                        field="category"
                        display="menu"
                        class="ml-auto"
                        [showClearButton]="false"
                        [showApplyButton]="false">
                    </p-columnFilter>
                </div>
            </th>
  
            <th pSortableColumn="rating">
                <div class="flex justify-content-between align-items-center">
                    Rating
                    <p-sortIcon field="rating"></p-sortIcon>
                    <p-columnFilter
                        type="numeric"
                        field="rating"
                        display="menu"
                        class="ml-auto"
                        [showClearButton]="false"
                        [showApplyButton]="false">
                    </p-columnFilter>
                </div>
            </th>
        </tr>
    </ng-template>
  
    <ng-template pTemplate="body" let-tutorial>
        <tr class="p-selectable-row">
            <td>
                <p-tableCheckbox [value]="tutorial"> </p-tableCheckbox>
                </td>
            <td>
                <span class="p-column-title"> Title </span>
                {{ tutorial.title }}
            </td>
            <td>
                <span class="p-column-title"> Category </span>
                <span class="image-text">
                    {{ tutorial.category }}
                </span>
            </td>
            <td>
                <span class="p-column-title"> Rating </span>
                <span class="image-text">
                    {{ tutorial.rating }}
                </span>
            </td>
        </tr>
    </ng-template>
</p-table>




import { Component, OnInit, ViewChild } from '@angular/core';
import { Table } from 'primeng/table';
import { PrimeNGConfig } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
  
export class AppComponent {
    tutorials: Tutorial[];
    @ViewChild('dt') table: Table;
    constructor(private primengConfig: PrimeNGConfig) {}
  
    ngOnInit() {
        this.tutorials = [
            {
                title: 'Queue',
                category: 'Data Structure',
                rating: 8,
            },
            {
                title: 'Circularly LinkedList',
                category: 'Data Structure',
                rating: 1,
            },
            {
                title: 'Doubly LinkedList',
                category: 'Data Structure',
                rating: 3,
            },
            {
                title: 'Singly LinkedList',
                category: 'Data Structure',
                rating: 5,
            },
            {
                title: 'Doubly Ended Queue',
                category: 'Data Structure',
                rating: 10,
            },
            {
                title: 'Binary Search Tree',
                category: 'Data Structure',
                rating: 2,
            },
            {
                title: 'Red Black Tree',
                category: 'Data Structure',
                rating: 9,
            },
            {
                title: 'Breadth First Search',
                category: 'Graph',
                rating: 6,
            },
            {
                title: "Floyd's Cycle",
                category: 'Algorithm',
                rating: 7,
            },
            {
                title: 'Travelling Salesman Problem',
                category: 'Algorithm',
                rating: 4,
            },
            {
                title: 'Bellman Ford',
                category: 'Graph',
                rating: 8,
            },
            {
                title: 'KMP Algorithm',
                category: 'String',
                rating: 10,
            },
        ];
        this.primengConfig.ripple = true;
    }
}
  
export interface Tutorial {
    title?: string;
    category?: string;
    rating?: number;
}




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';
import { CalendarModule } from 'primeng/calendar';
import { SliderModule } from 'primeng/slider';
import { DialogModule } from 'primeng/dialog';
import { MultiSelectModule } from 'primeng/multiselect';
import { ContextMenuModule } from 'primeng/contextmenu';
import { ButtonModule } from 'primeng/button';
import { InputTextModule } from 'primeng/inputtext';
import { ProgressBarModule } from 'primeng/progressbar';
import { DropdownModule } from 'primeng/dropdown';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        TableModule,
        CalendarModule,
        SliderModule,
        DialogModule,
        MultiSelectModule,
        ContextMenuModule,
        DropdownModule,
        ButtonModule,
        InputTextModule,
        ProgressBarModule,
        HttpClientModule,
        FormsModule,
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
  
export class AppModule {}

Output:

 

Reference: http://primefaces.org/primeng/table


Article Tags :