Open In App

Angular PrimeNG Paginator CurrentPageReport

Last Updated : 03 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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 how to use Angular PrimeNG Paginator CurrentPageReport

The Paginator Component is used to display content in paged format. The pagination state information can be rendered can be Current page report item in any template. The ({currentPage} of {totalPages}) is a default value. There are different placeholders are available, which are {currentPage}, {totalPages},{rows},{first}, {last},{totalRecords}. To check the currentPageReport, we can set a property called showCurrentPageReport which specifies whether to display the current page report. It is of boolean data type, the default value is false.

Syntax:

<p-paginator [rows]="1" 
             [totalRecords]="15"
             [showCurrentPageReport]="true"
             currentPageReportTemplate=
                 "{currentPage} of {totalPages}">
</p-paginator>

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 get the currentPageReport as ({currentPage} of {totalPages}) 

  • app.component.html

HTML




<div style="width:80%">
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>
    <h2>
        Angular PrimeNG Paginator CurrentPageReport
    </h2>
    <p-paginator [rows]="1" 
                 [totalRecords]="15" 
                 [showCurrentPageReport]="true"
                 currentPageReportTemplate=
                    "{currentPage} of {totalPages}">
    </p-paginator>
</div>


  • app.component.ts

Javascript




import { Component } from "@angular/core";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ["./app.component.scss"],
})
export class AppComponent { }


  • app.module.ts

Javascript




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


Output:

 

Example 2: In this example, we will see currentPageReport as {first} of {totalRecords}

  • app.component.html

HTML




<div style="width:80%">
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>
    <h2>
        Angular PrimeNG Paginator CurrentPageReport
    </h2>
    <p-paginator [pageLinkSize]="10" 
                 [rows]="1" 
                 [totalRecords]="20" 
                 [rowsPerPageOptions]="[5,15,25]" 
                 [showCurrentPageReport]="true" 
                 currentPageReportTemplate=
                            "{first} of {totalRecords}">
    </p-paginator>
</div>


  • app.component.ts

Javascript




import { Component } from "@angular/core";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ["./app.component.scss"],
})
export class AppComponent { }


  • app.module.ts

Javascript




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


Output:

 

Reference: https://primefaces.org/primeng/paginator



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads