Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Angular PrimeNG OrderList Multiple Selection

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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 Multiple Selection.

OrderList Component is used to maintain the list of items and products. Multiple Selection helps us to select multiple items in the orderlist with the help of a property called metaKeySelection. The metaKeySelection property helps to select multiple items either by using the metaKey or toggled individually, depending upon the metaKeySelection property value. Its default value is true.  If we make it false, then we will be able to select multiple items at once in the orderlist. This property will automatically be turned off for touch-enabled devices.

Syntax:

<p-orderList [value]="product" 
             header="OrderList Component"
             [metaKeySelection]="false">
    ...
</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 Multiple Selection by setting  metaKeySelection=false. (We will be able to select multiple items in the list).

  • app.component.html

HTML




<div style="width: 50%;">
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
    <h2>
        PrimeNG OrderList Multiple Selection
    </h2>
    <p-orderList [value]="product" 
                 header="OrderList Component" 
                 [metaKeySelection]="false">
        <ng-template let-product pTemplate="item">
            <div class="product-item">
                <div class="product-list-detail">
                    <h5 class="p-mb-2">
                        {{product}}
                    </h5>
                    <h6 class="p-mb-2">
                        {{gfg}}
                    </h6>
                </div>
            </div>
        </ng-template>
    </p-orderList>
</div>

  • app.component.ts

Javascript




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    product: string[] = ['Geek1', 'Geek2', 'Geek3', 'Geek4'];
  
    gfg: string[] = ['200'];
}

  • app.module.ts

Javascript




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 Multiple Selection by setting  metaKeySelection=true (We won’t be able to select multiple items in the list).

  • app.component.html

HTML




<div style="width: 50%;">
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
    <h2>PrimeNG OrderList Multiple Selection</h2>
    <p-orderList [value]="product" 
                 header="OrderList Component" 
                 [metaKeySelection]="true">
        <ng-template let-product pTemplate="item">
            <div class="product-item">
                <div class="product-list-detail">
                    <h5 class="p-mb-2">
                        {{product}}
                    </h5>
                    <h6 class="p-mb-2">
                        {{gfg}}
                    </h6>
                </div>
            </div>
        </ng-template>
    </p-orderList>
</div>

  • app.component.ts

Javascript




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    product: string[] = ['Geek1', 'Geek2', 'Geek3', 'Geek4'];
  
    gfg: string[] = ['200'];
}

  • app.module.ts

Javascript




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


My Personal Notes arrow_drop_up
Last Updated : 04 Jan, 2023
Like Article
Save Article
Similar Reads
Related Tutorials