gpt4 book ai didi

Angular 客户端分页

转载 作者:行者123 更新时间:2023-12-02 10:51:03 25 4
gpt4 key购买 nike

我正在从数据库中提取一组数据并用一个简单的表格显示它。我想做的是向该表添加分页功能。例如,每个页面将有 5 行。在本例中 courseData是数组。

<table  style="border-spacing: 5rem">
<tr >
<td style="font-size: 20px;">CRN</td>
<pre> </pre>
<td style = "font-size: 20px;" >Name</td>
<pre> </pre>
<td style ="font-size: 20px;" >Lecturer</td>
<pre> </pre>
<td style = "font-size: 20px;" >Level</td>
<pre> </pre>
<td style = "font-size: 20px;" >Days</td>
<pre> </pre>
<td style = "font-size: 20px;" >Time</td>



</tr>
<ng-container *ngFor="let data of courseData">
<tr>
<td style="text-decoration: underline;" (click)="crnClicked(data.crn)">{{data.crn}}</td>
<pre> </pre>
<td *ngIf="data.specialapp !=1" >{{data.name}}</td>
<td style="font-weight: bold;"*ngIf="data.specialapp==1" >{{data.name}}</td>
<pre> </pre>
<td>{{data.lecturer}}</td>
<pre> </pre>
<td>{{data.level}}</td>
<pre> </pre>
<td>{{data.days}}</td>
<pre> </pre>
<td>{{data.hours}}</td>


<button *ngIf="data.specialapp!=1" ion-button small round (click)="addCrn(data.crn)" color="primary" block>+</button>

</tr>

</ng-container>
</table>

最佳答案

您可以使用ngx-pagination模块。请尝试

<ng-container *ngFor="let data of courseData | paginate: { id: 'foo',
itemsPerPage: pageSize,
currentPage: p,
totalItems: total>

</ng-container>

app.module.ts:

import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {NgxPaginationModule} from 'ngx-pagination'; // <-- import the module
import {MyComponent} from './my.component';

@NgModule({
imports: [BrowserModule, NgxPaginationModule], // <-- include it in your app module
declarations: [MyComponent],
bootstrap: [MyComponent]
})
export class MyAppModule {}

my.component.ts:

import {Component} from '@angular/core';

@Component({
selector: 'my-component',
template: `
<ul>
<li *ngFor="let item of collection | paginate: { itemsPerPage: 10, currentPage: p }"> ... </li>
</ul>

<pagination-controls (pageChange)="p = $event"></pagination-controls>
`
})
export class MyComponent {
p: number = 1;
collection: any[] = someArrayOfThings;
}

关于Angular 客户端分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50216890/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com