angular - 为什么使用 p-table 的 p-pagination 不起作用
问题描述
我正在实施p 分页,p 表中的数据应该相应地反映。如果我在p-table中通过[pagination]="true"使用它,但我想实现的是使用 paginationModule。在这种情况下,数据不会根据分页中的页面选择显示。请帮我。
<p-dialog
[(visible)]="mSerivce.isAuditDialogVisible"
[draggable]="false"
[closable]="true"
showEffect="fade"
[contentStyle]="{width:'800px', height:'400px'}" >
<p-header>
Audit History
</p-header>
<p-table [value]="auditHistoryList" [columns]="auditGridColumns" [responsive]="true">
<ng-template pTemplate="colgroup" let-columns>
<colgroup>
<col *ngFor="let col of columns" [style.width]="col.style" />
</colgroup>
</ng-template>
<ng-template pTemplate="header" let-columns>
<tr class="st-sub-header">
<th *ngFor="let col of columns">
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" class="tb-body" let-rowIndex="rowIndex" let-rowData let-expanded="expanded" let-columns="columns">
<tr>
<td class="h-90 mh-20">{{rowData.action || '-'}}</td>
<td class="h-90">{{rowData.user}}</td>
<td class="h-90">{{rowData.createdDate || '-'}}</td>
<td class="h-90" [innerHTML]="rowData?.comments || '-'"></td>
</tr>
</ng-template>
<ng-template pTemplate="emptymessage" let-columns>
<tr>
<td colspan="4">
No records found
</td>
</tr>
</ng-template>
</p-table>
<p-footer>
<p-paginator [rows]="2" [totalRecords]="auditHistoryList.length" pageLinkSize="3"></p-paginator>
</p-footer>
</p-dialog>
解决方案
我有一个类似的问题。但是,我可以看到您的代码和我的代码之间的唯一区别是您使用分页器的方式。也许您可以尝试以这种方式更改它:
<p-table #myTable [value]="auditHistoryList" [paginator]="true" [rows]="2">
...
在您的 .ts 中,如果您添加新行,您可以通过以下方式更新 totalRecords:
this.auditHistoryList.push(auditHistory);
this.myTable.totalRecords = this.auditHistoryList.value.length;
考虑到 myTable 是 p-table 组件的 ViewChild:
import { Table } from 'primeng/table';
...
@ViewChild(Table, {static: false}) myTable : Table;
我希望这会有所帮助。
推荐阅读
- git - Windows 上的 Git 远程推送部署工作流
- javascript - 如何通过可内容编辑的 div 输入保留附加到列表的元素的换行符(格式)?
- javascript - onClick 事件在 Safari iOS 上不起作用
- android - 自定义注释,如用于 android viewBinding 的 Butterknifes "@OnClick"
- node.js - 我们如何动态生成 Angular 中的 sitemap.xml
- ubuntu-16.04 - 在 Ubuntu 中更改 Kodi 用户
- sql - 获取 SQLite 中每个值的百分比?
- javascript - 根据特定行中的单选按钮选择显示/隐藏文本框
请参阅随附的代码以进行理解。HTML 表格根据特定标准显示元素。每当“Extra KM/Hr”中的单选按钮?是,则应启用其右侧的所有列,否则应禁用。我在这个“displayTable”id 上使用 PHP 填充表值。
<html lang="en"> <head> <!-- Meta tags --> <me
- powershell - 如何杀死在文件夹下运行的所有进程?
- javascript - 如何指定 Puppeteer 启动的监视器?