ag-grid - AgGrid 中的行数
问题描述
我想在我的 AgGrid 中显示行数,但我遇到了问题。
ngOnInit() {
console.log(this.gridOptions.api.getDisplayedRowCount());
}
错误:
ERROR TypeError: Cannot read property 'getDisplayedRowCount' of undefined
at ProjectListComponent.webpackJsonp../src/app/project-list/project-list.component.ts.ProjectListComponent.ngOnInit (project-list.component.ts:178)
at checkAndUpdateDirectiveInline (core.js:12411)
at checkAndUpdateNodeInline (core.js:13935)
at checkAndUpdateNode (core.js:13878)
at debugCheckAndUpdateNode (core.js:14771)
at debugCheckDirectivesFn (core.js:14712)
at Object.eval [as updateDirectives] (ProjectListComponent_Host.ngfactory.js? [sm]:1)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:14697)
at checkAndUpdateView (core.js:13844)
at callViewAction (core.js:14195)
Api AgGrid:
getDisplayedRowCount() Returns the total number of displayed rows.
我不明白为什么我有这个问题......
解决方案
(你提到 ngOnInit 所以我假设你使用
的是 Angular)问题是 api 在ngOnInit
. gridReady
如果您需要网格 api,您应该监听该事件。
gridReady: ag-Grid 已初始化。例如,如果您需要使用网格的 API 来固定列的大小,请使用此事件。 文档
html:
<ag-grid-angular style="width: 100%; height: 372px;"
(gridReady)="onGridReady()">
</ag-grid-angular>
组件 ts:
onGridReady(params: any) {
console.log('grid ready');
console.log(this.gridOptions.api.getDisplayedRowCount());
}
您还应该记住,此站点上有一条注释:
有时网格事件会在 Angular 组件准备好接收它之前触发,因此在 Angular 环境中,在使用 API 之前
gridReady
依赖它更安全。AfterViewInit
gridReady
尽管如此,我在使用该活动时从未遇到任何问题。
推荐阅读
- php - 在 php 中使用“echo”或“print”语句会干扰网站的外观
- javascript - 具有 1 个手柄和 2 个值输入的范围滑块
- mongodb - 我的 mongo 数据库中不存在集合
- java - 如何从包含列表的地图中检索特定值?
- entity-framework - 使用 .NET core MVC 上传和读取 excel 文件
- c# - 如何使用 JSON.NET 或任何其他包使用动态密钥解析 c# JSON
- javascript - 将鼠标悬停在文本上时更改带有文本的指针
- lora - 我如何定义 AppEUI?
- python - Python MySQL INSERT 抛出 ProgrammingError: 1064
- nativescript - Nativescript-vue,如何更改 BarSeries(Radchart) 图形“条形”颜色?