angular - 如何使用 API 中的数据实现 ng-bootstrap 表排序、搜索过滤和分页
问题描述
我正在实现一个事务表,其中填充了我自己创建的 API 中的数据,我想让它可排序、可过滤和分页。我正在尝试使用 ng-bootstrap 来完成它,我看到了文档,但我只是无法让它工作,在完整的示例中他们使用静态数据数组。
我试图调整我在文档页面中看到的内容: https ://ng-bootstrap.github.io/#/components/table/examples#sortable 但我无法让它工作。
// TS
import { Component, OnInit } from '@angular/core';
import { NgxSpinnerService } from 'ngx-spinner';
import { TransactionsService } from '../transactions.service';
import { Transactions, Career, Faculty, RoleType } from 'src/assets/models';
import { RegisterService } from '../register.service';
import { AlertService } from '../alert.service';
@Component({
selector: 'app-admin',
templateUrl: './admin.component.html',
styleUrls: ['./admin.component.scss']
})
export class AdminComponent implements OnInit {
content: Transactions;
analytic = false;
uniFaculties: Faculty;
uniCareers: Career;
uniUsers: RoleType;
constructor(
private modalService: NgbModal,
private spinner: NgxSpinnerService,
private alertService: AlertService,
private transactionService: TransactionsService
) { }
ngOnInit() {
this.spinner.show();
this.transactionService.getAllTransactions()
.subscribe(res => {
this.content = res;
console.log(this.content); // testing all transaction object
});
this.spinner.hide();
}
}
// HTML
<div class="fluid-container admin-transactions" *ngIf="content">
<h1><span class="badge badge-info header-transactions"><i class="fas fa-exchange-alt"></i> Transacciones</span></h1>
<table class="table table-hover fixed_header">
<thead class="thead table-info">
<tr class="row table-info">
<th class="col-1 d-flex justify-content-center" scope="col">ID de Transacción</th>
<th class="col-1 d-flex justify-content-center" scope="col">ID de Usuario</th>
<th class="col-1 d-flex justify-content-center" scope="col">Tipo</th>
<th class="col-4 d-flex justify-content-center" scope="col">Fecha</th>
<th class="col-3 d-flex justify-content-center" scope="col">Descripción</th>
<th class="col-2 d-flex justify-content-center" scope="col">Monto</th>
</tr>
</thead>
<tbody>
<tr class="row" *ngFor='let row of content.transactions'>
<td class="col-1 d-flex justify-content-center id">{{ row.trx_ID }}</td>
<td class="col-1 d-flex justify-content-center id">{{ row.user_ID }}</td>
<td class="col-1 d-flex justify-content-center trx" [ngClass]="{'custom-class': row.trx_type === 'RCH' && row.amount !== 0, 'default-color': row.trx_type !== 'RCH'}">{{ row.trx_type}}</td>
<td class="col-4 d-flex justify-content-center date">{{ row.date | date:'long' }} </td>
<td class="col-3 d-flex justify-content-center description">{{ row.description }}</td>
<td class="col-2 d-flex justify-content-center amount" [ngClass]="{'rch-class': row.trx_type === 'RCH' && row.amount !== 0 , 'pay-class': row.trx_type !== 'RCH'}">{{ row.amount | currency }}</td>
</tr>
</tbody>
</table>
</div>
<hr>
解决方案
推荐阅读
- python - 从 PyPDF2 getOutlines() 解析页码
- python - 是否可以修改`__init__`中的方法?
- python - QTextEdit:如何使用自定义元数据制作只读文本块?
- c++ - 通过正则表达式拆分字符串会删除结果的第一个字母
- vba - 语法错误(缺少运算符)查询表达式
- vuejs2 - Vue2.js - 如何从 json 中获取选定的选项
- azure-devops - 在 Azure DevOps 上构建管道时分离的 Head
- android - 如何使用 Retrofit 在 android 中调用图像上传 Web 服务 (ASP.NET) .asmx 文件
- python - 对列的重复值进行排序、分组和显示
- c# - 当前上下文中不存在名称“权限”