Angular Data table pagination

  • step1:
npm install ngx-pagination
  • step2: Import the ngx-pagination in the app.module.ts file.
import { NgxPaginationModule} from 'ngx-pagination';
 imports: [
    ...
    NgxPaginationModule
  ],
  • step3: In the component where you load your table, use the ngx-pagination as a pipe.
<table>
...
<tbody>
    <tr *ngFor="let person of message | paginate:{itemsPerPage:15, currentPage: p}; let i = index ">
      <td scope="row">{{i}}</td>
      <td>{{person.firstname}}</td>
      <td>{{person.lastname}}</td>
      <td>{{person.gender}}</td>
      <td>{{person.phone}}</td>
      <td>{{person.email}}</td>
      <td><a style="color: #ff0000;" href="#">Delete</a>
        <span> |</span>
        <a style="color: #007bff;" href="#"> Edit</a></td>
    </tr>
  </tbody>
</table>

<pagination-controls (pageChange)="p = $event" style="float: right;"></pagination-controls>

And that's it!

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容