在 Ag-Grid 中如何读取所有页面特定的单元格数据并存储到数组中
in Ag-Grid how to read all pages specific cell data and store into array
export class AppComponent {
gridApi: any;
columnApi: any;
title = 'AgGridPro';
constructor(private httpClient : HttpClient){
}
column = [
{
"headerName": "Name",
"field": "name",
sortable: true,
editable: true
},
{
"headerName": "Mobile",
"field": "mobile"
},
{
"headerName": "Age",
"field": "age"
},
{
field: 'age',
minWidth: 120,
aggFunc: 'sum',
},
{
"headerName": "Address",
"field": "Address"
}
]
onGridReady(params: any) {
this.gridApi = params.api;
this.columnApi = params.columnApi;
}
}
在上面的代码中,我们有 200 行数据和 8 页,但如果尝试使用 griApi,我们只能读取 25 条记录的一页,但无法读取另一页数据,想要从行名中获取记录列表如果名称中的任何一个为空,则存储到新数组中需要为该记录创建错误,因此需要将该空单元格名称数据列表存储到数组中
您可以使用网格 api 方法遍历所有行数据 forEachNode
:
https://www.ag-grid.com/javascript-data-grid/grid-api/
forEachNode
Iterates through each node (row) in the grid and calls the callback
for each node. This works similar to the forEach method on a
JavaScript array. This is called for every node, ignoring any
filtering or sorting applied within the grid. If using the Infinite
Row Model, then this gets called for each page loaded in the page
cache.
function forEachNode(
callback: (rowNode: RowNode, index: number) => void ): void;
export class AppComponent {
gridApi: any;
columnApi: any;
title = 'AgGridPro';
constructor(private httpClient : HttpClient){
}
column = [
{
"headerName": "Name",
"field": "name",
sortable: true,
editable: true
},
{
"headerName": "Mobile",
"field": "mobile"
},
{
"headerName": "Age",
"field": "age"
},
{
field: 'age',
minWidth: 120,
aggFunc: 'sum',
},
{
"headerName": "Address",
"field": "Address"
}
]
onGridReady(params: any) {
this.gridApi = params.api;
this.columnApi = params.columnApi;
}
}
在上面的代码中,我们有 200 行数据和 8 页,但如果尝试使用 griApi,我们只能读取 25 条记录的一页,但无法读取另一页数据,想要从行名中获取记录列表如果名称中的任何一个为空,则存储到新数组中需要为该记录创建错误,因此需要将该空单元格名称数据列表存储到数组中
您可以使用网格 api 方法遍历所有行数据 forEachNode
:
https://www.ag-grid.com/javascript-data-grid/grid-api/
forEachNode
Iterates through each node (row) in the grid and calls the callback for each node. This works similar to the forEach method on a JavaScript array. This is called for every node, ignoring any filtering or sorting applied within the grid. If using the Infinite Row Model, then this gets called for each page loaded in the page cache.
function forEachNode( callback: (rowNode: RowNode, index: number) => void ): void;