Open In App

Angular PrimeNG OrderList DragDrop

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 learn about OrderList DragDrop in Angular PrimeNG.

The OrderList component is used to maintain the list of items and products. The OrderList DragDrop Items in the order list can be reordered if we set dragdrop attribute to true.

Syntax:



<p-orderList [value]="..." 
    [dragdrop]="true">
    <ng-template let-... 
        pTemplate="item">
        ...
    </ng-template>
</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
npm install @angular/cdk --save

Project Structure: It will look like the following

 

Steps to run the application: Run the below command to see the output

ng serve --save

Example 1: Below is the example code that illustrates the use of Angular PrimeNG OrderList DragDrop. In this example, we will learn about dragdrop=true.




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




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"];
}




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: Below is another example code that illustrates the use of Angular PrimeNG OrderList DragDrop. In this example, we will learn about dragdrop=false.




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




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'];
}




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: https://primefaces.org/primeng/orderlist


Article Tags :