Open In App

Angular PrimeNG OrderList Filtering

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 the Angular PrimeNG OrderList Filtering.

OrderList Component is used to maintain the list of items and products. An OrderList can be filtered by utilizing the property called filterBy, which enables filtering lists by specifying the fields. It also provides to define the Multiple fields by using a comma separate list.



Syntax:

<p-orderList filterBy="..." ></p-orderList>

 



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:

 

Example 1: In this example, we will learn about OrderList filtering.




<div style="width: 50%;">
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
    <h2>
        PrimeNG OrderList Filtering
    </h2>
    <p-orderList [value]="product" 
                 header="OrderList" 
                 controlsPosition="right" 
                 filterBy="category">
        <ng-template let-product pTemplate="item">
            <div class="product-item">
                <div class="product-list-detail">
                    <h5 class="p-mb-2" 
                        style="color:red">
                        {{product.title}}
                    </h5>
                    <h6 class="p-mb-2">
                        {{product.category}}
                    </h6>
                </div>
            </div>
        </ng-template>
    </p-orderList>
</div>




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    product: any[] = [
        {
            title: 'Queue',
            category: 'Data Structure'
        },
        {
            title: 'Circularly LinkedList',
            category: 'Data Structure'
        },
        {
            title: 'Doubly LinkedList',
            category: 'Data Structure'
        },
        {
            title: 'Singly LinkedList',
            category: 'Data Structure'
        },
        {
            title: 'Doubly Ended Queue',
            category: 'Data Structure',
        },
        {
            title: 'Binary Search Tree',
            category: 'Data Structure'
        },
        {
            title: 'Red Black Tree',
            category: 'Data Structure'
        },
        {
            title: 'Breadth First Search',
            category: 'Graph'
  
        },
        {
            title: "Floyd's Cycle",
            category: 'Algorithm'
  
        },
        {
            title: 'Travelling Salesman Problem',
            category: 'Algorithm'
  
        },
        {
            title: 'Bellman Ford',
            category: 'Graph'
  
        },
        {
            title: 'KMP Algorithm',
            category: 'String'
  
        }
    ];
}




import { NgModule } from '@angular/core';
import { BrowserModule } 
    from '@angular/platform-browser';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { OrderListModule } from 'primeng/orderlist';
  
@NgModule({
    imports: [BrowserModule,
        BrowserAnimationsModule,
        OrderListModule],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }

Output:

 

Example 2: In this example, we will learn about OrderList filtering using multiple fields. This is done by providing comma-separated values.




<div style="width: 50%;">
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
    <h2>PrimeNG OrderList Filtering</h2>
  
    <p-orderList [value]="product"
                 header="OrderList"
                 controlsPosition="right" 
                 filterBy="category,title">
        <ng-template let-product pTemplate="item">
            <div class="product-item">
                <div class="product-list-detail">
                    <h5 class="p-mb-2" 
                        style="color:red">
                        {{product.title}}
                    </h5>
                    <h6 class="p-mb-2">
                        {{product.category}}
                    </h6>
                </div>
            </div>
        </ng-template>
    </p-orderList>
</div>




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    product: any[] = [
        {
            title: 'Queue',
            category: 'Data Structure'
        },
        {
            title: 'Circularly LinkedList',
            category: 'Data Structure'
        },
        {
            title: 'Doubly LinkedList',
            category: 'Data Structure'
        },
        {
            title: 'Singly LinkedList',
            category: 'Data Structure'
        },
        {
            title: 'Doubly Ended Queue',
            category: 'Data Structure',
        },
        {
            title: 'Binary Search Tree',
            category: 'Data Structure'
        },
        {
            title: 'Red Black Tree',
            category: 'Data Structure'
        },
        {
            title: 'Breadth First Search',
            category: 'Graph'
  
        },
        {
            title: "Floyd's Cycle",
            category: 'Algorithm'
  
        },
        {
            title: 'Travelling Salesman Problem',
            category: 'Algorithm'
  
        },
        {
            title: 'Bellman Ford',
            category: 'Graph'
  
        },
        {
            title: 'KMP Algorithm',
            category: 'String'
  
        }
    ];
}




import { NgModule } from '@angular/core';
import { BrowserModule } 
    from '@angular/platform-browser';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { OrderListModule } from 'primeng/orderlist';
  
@NgModule({
    imports: [BrowserModule,
        BrowserAnimationsModule,
        OrderListModule],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }

Output:

 

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


Article Tags :