angular - 如何在Angular中为表格添加分页?
问题描述
我是 Angular 的新手,如果有人能帮我在表格中添加分页,我将不胜感激。我创建了一个 CRUD 项目,其中后端在 Spring boot 中完成,前端在 Angular 中完成。要进行布局,我想直接使用 bootstrap,而无需在 springboot 中为布局创建特定代码,然后直接在 Angular 中工作。我在网上看到了一些,但在我的情况下找不到简单的东西。这是我与感兴趣的表相关的 html 代码:
<div class="panel-heading">
<h1 style="text-align: center">Students</h1><br>
<div class="form-group">
<input type="text" class="form-control search-input" placeholder="Search..." [(ngModel)]="filterTerm">
</div>
<div class="panel-body">
<table class="table table-hover table-sm">
<thead class="thead-light">
<tr>
<th>Student code</th>
<th>Student name</th>
<th>Student date</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let student of students| filter:filterTerm">
<td>{{student.codestudent}}</td>
<td>{{student.namestudent}}</td>
<td>{{student.datestudent}}</td>
<td><button (click)="deleteStudent(student.codestudent)" class='btn btn-primary'><i
class="fa fa-futboll-0">Delete</i></button>
</td>
</tr>
</tbody><br>
</table>
</div>
任何人都可以帮助我吗?我无限感谢你。
解决方案
您打算进行客户端分页还是服务器端?上面这个不清楚!
如果客户端:因为您已经在使用Bootstrap
库,我建议您检查这个以获得快速简便的解决方案:https://getbootstrap.com/docs/5.0/components/pagination/
,但不要将其用于大型数据集(的定义large ds
是有争议的,假设< 3000
您在中提到的字段的记录编码)。
如果是服务器端:Spring Boot 自己不能做任何事情,但对于数据库之ORM
类的Hibernate
或.ODM
NoSQL
MongoDB
例如:MySQL
orPostgreSQL
将使用 ....offset().limit()
而MongoDB
将使用...skip().limit()
. 您需要创建一个带有GET
请求的 API parameters
(更容易在浏览器上添加书签)。这些参数的编号进入上述方法以创建分页。在点击每个页码或在UI 上按下 、 和First
按钮Previous
时调用此 API!Next
Last
请查看相应的数据库文档以获取更多信息。
推荐阅读
- mongodb - MongoError: E11000 使用数组对象收集重复键错误
- mysql - 为什么当我启动/停止/重新启动运行烧瓶休息应用程序的 uWSGI 时我的数据库会清空
- python - 如何使用输入对该功能进行单元测试?
- aframe - 获取aframe的相机角度
- python - 如何重命名,熊猫中没有列名?
- flutter - 如何在颤动的主题中设置TextFormField的样式
- c++ - 将整个自我可执行文件复制到内存c ++
- python - 可以更改 Altair 或 Pandas 上的日期语言吗?
- javascript - if 语句未在异步函数内运行
- java - 嵌套异常是 org.hibernate.id.IdentifierGenerationException:必须在调用 save() 之前手动分配此类的 id: