Angular PrimeNG Paginator Rows and TotalRecords
Angular PrimeNG是一个开源框架,拥有丰富的原生Angular UI组件,可用于出色的造型,该框架可用于制作响应式网站,非常方便。在这篇文章中,我们将学习如何在Angular PrimeNG中使用Paginator Rows和TotalRecords组件。我们还将学习属性,以及代码中会用到的语法。
分页器组件用于以分页形式显示内容。分页器应该显示多少页是由rows和totalRecords决定的。
语法:
<p-paginator
[rows]="..."
[totalRecords]="..."
[rowsPerPageOptions]="...">
</p-paginator>
Angular PrimeNG Paginator Rows 和 TotalRecords 属性:
- totalRecords。它是要显示的总记录页的总数。它是数字数据类型,默认值为0。
- rows。它是每页要显示的数据数。它是数字数据类型,默认值是0。
- rowsPerPageOptions。它是整数/对象值的数组,用于显示在每页下拉的行中。它是数组数据类型,默认值为空。
创建Angular应用程序和模块安装。
第1步:使用以下命令创建一个Angular应用程序。
ng new appname
第2步:创建你的项目文件夹即appname后,使用以下命令移动到它。
cd appname
第3步在你给定的目录中安装PrimeNG。
npm install primeng --save
npm install primeicons --save
项目结构:它将看起来像如下。
运行应用程序的步骤:运行以下命令以查看输出。
ng serve --open
例子1:下面的例子说明了Angular PrimeNG Paginator Rows和TotalRecords的使用。
- app.component.html:
<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Paginator Rows and TotalRecords</h5>
<p-paginator
[rows]="2"
[totalRecords]="100">
</p-paginator>
- app.component.ts:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
})
export class AppComponent {}
- app.module.ts:
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 {}
输出:
例子2:下面的例子说明了Angular PrimeNG Paginator Rows和TotalRecords使用rowsPerPageOptions。
- app.component.html:
<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Paginator Rows and TotalRecords</h5>
<p-paginator
[rows]="2"
[totalRecords]="100"
[rowsPerPageOptions]="[5,10,15,20]">
</p-paginator>
- app.component.ts:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
})
export class AppComponent {}
- app.module.ts:
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 {}
输出: