繁体   English   中英

角客户端分页

[英]Angular Client Side Pagination

我正在从数据库中提取一个数据数组并用一个简单的表显示它。我想做的是在此表中添加分页功能。例如,每页中将有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;  
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM