我有一个简单的引导表。这是显示数组的结果。我需要添加分页。意味着它加载第一个40数组,然后在第二个分页中加载这样的40。我找到了一些示例,但是无法通过引导表实现它。如果有人可以帮助您编写代码,谢谢。
<table class="table table-responsive-md text-center">
<thead>
<tr>
<th>ID</th>
<th>NAME</th>
<th>COMPANY</th>
</tr>
</thead>
<tbody *ngIf="data">
<tr *ngFor="let x of data | filterBy: userFilter" (click)="openDeal(deletecontent, x)">
<td>
<span class="text-success">{{x.user_id}}</span>
</td>
<td>
<div style="text-align: left;">
<img [src]="x.userPhoto || 'https://mbtskoudsalg.com/images/user-image-png.png'" class="img-sm" alt="" style="text-align: left;">
{{x.name}} </div>
</td>
<td>{{x.cnic}}</td>
</tr>
</tbody>
</table>
.ts
getClaims(){
this.emp = true;
this.url = 'assets/employe.json?';
this.clientData = this.httpClient.get<any>(this.url,{responseType: 'json'}).
subscribe(data => {
console.log(data);
this.data4 = data.records;
this.data = this.data4.filter(item => item.company_id === this.userFilter.company_id);
this.employesnumber = this.data.count;
console.log(this.employesnumber);
});
}
答案 0 :(得分:1)
尝试使用ngx-pagination模块。
<table class="table table-responsive-md text-center">
<thead>
<tr>
<th>ID</th>
<th>NAME</th>
<th>COMPANY</th>
</tr>
</thead>
<tbody *ngIf="data">
<tr *ngFor="let x of data | filterBy: userFilter | paginate: { itemsPerPage: 40, currentPage: p }"" (click)="openDeal(deletecontent, x)">
<td>
<span class="text-success">{{x.user_id}}</span>
</td>
<td>
<div style="text-align: left;">
<img [src]="x.userPhoto || 'https://mbtskoudsalg.com/images/user-image-
png.png'" class="img-sm" alt="" style="text-align: left;">
{{x.name}} </div>
</td>
<td>{{x.cnic}}</td>
</tr>
<pagination-controls (pageChange)="p = $event"></pagination-controls>
</tbody>
</table>
还要在您的打字稿文件中声明一个变量p
,不要忘记安装npm软件包ngx-pagination并将其导入模块中