Open In App

Angular PrimeNG DataView Events

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 about Angular PrimeNG DataView Events.

The DataView Component is used to display data in a grid and list layout with pagination and sorting features.



Angular PrimeNG DataView Events:

 



Syntax:

<p-dataView
     (event)=function()>
</p-dataView>

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

 

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

ng serve --save

Example 1: In this example, we will learn about Angular PrimeNG DataView Events onPage.




<div style="width: 80%;">
    <h1 style="color: green;">GeeksforGeeks</h1>
    <h2>Angular PrimeNG DataView Events</h2>
    <div class="card">
        <p-dataView
            #dv
            [value]="productNames"
            [paginator]="true"
            [rows]="2"
            layout="grid"
            (onPage)="onPage()">
            <ng-template let-product pTemplate="gridItem">
                <p-card header="GeeksforGeeks">
                    {{product}}
                </p-card>
            </ng-template>
        </p-dataView>
    </div>
</div>




import { Component } from "@angular/core";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ["./app.component.css"]
})
  
export class AppComponent {
    productNames: string[] = [
        "Java",
        "Python",
        "C++",
        "Angular",
        "React",
        "NodeJS",
        "AWS",
        "R Programming",
        "Machine Learning"
    ];
  
    onPage() {
        alert("Hi Geek!! Pagination is done");
    }
}




import { NgModule } from "@angular/core";
import { BrowserAnimationsModule } 
    from "@angular/platform-browser/animations";
import { CardModule } from "primeng/card";
  
import { AppComponent } from "./app.component";
import { DataViewModule } from "primeng/dataview";
  
@NgModule({
    imports: [
      BrowserAnimationsModule,
      DataViewModule,
      CardModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
  
export class AppModule {}

Output:

 

Example 2: In this example, we will learn about Angular PrimeNG DataView Events onLazyLoad.




<div style="width: 80%;">
    <h1 style="color: green;">GeeksforGeeks</h1>
    <h2>Angular PrimeNG DataView Events</h2>
    <div class="card">
        <p-dataView
            #dv
            [value]="productNames"
            [paginator]="true"
            [rows]="2"
            layout="grid"
            [lazy]="true"
            (onLazyLoad)="onLazyLoad()">
            <ng-template let-product pTemplate="gridItem">
                <p-card header="GeeksforGeeks">
                    {{product}}
                </p-card>
            </ng-template>
        </p-dataView>
    </div>
</div>




import { Component } from "@angular/core";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ["./app.component.css"],
})
  
export class AppComponent {
    productNames: string[] = [
        "Java",
        "Python",
        "C++",
        "Angular",
        "React",
        "NodeJS",
        "AWS",
        "R Programming",
        "Machine Learning"
    ];
  
    onLazyLoad(){
        alert("Hi Geek!! There is Lazy Layout")
    }
}




import { NgModule } from "@angular/core";
import { BrowserAnimationsModule } 
    from "@angular/platform-browser/animations";
import { CardModule } from "primeng/card";
  
import { AppComponent } from "./app.component";
import { DataViewModule } from "primeng/dataview";
  
@NgModule({
    imports: [
      BrowserAnimationsModule,
      DataViewModule,
      CardModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
  
export class AppModule {}

Output:

 

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


Article Tags :