ag-grid 无法在 ngOnInit 中设置焦点单元格
ag-grid Cannot set focused cell in ngOnInit
我正在尝试将焦点设置到我的网格中的第一个可编辑单元格,但出现此错误 "TypeError: Cannot read property 'setFocusedCell' of undefined"。
我在 ag-grid-angular 组件的 ngOnInit 中调用 setFocusedCell。这是一个片段:
constructor(private mcService: MonteCarloService) {
this.gridOptions = <GridOptions>{
rowData: MCInputGridComponent.createRowData(),
columnDefs: MCInputGridComponent.createColumnDefs()
};
}
ngOnInit() {
this.gridOptions.api.setFocusedCell(1, "histDataType", null);
}
我已经定义了列并通过构造函数方法设置了一些数据。以下是列定义。
private static createColumnDefs() {
return [
{
colKey: "sprint#",
headerName: "Sprint #",
field: "sprint",
width: 80,
editable: false
},
{
colKey: "histDataType",
headerName: "Velocity",
field: "histDataType",
cellEditorFramework: NumericEditorComponent,
editable: true,
width: 102
}
];
}
不在ngOnInit中调用setFocusedCell,而是在onGridReady(gridReady)中调用
我正在尝试将焦点设置到我的网格中的第一个可编辑单元格,但出现此错误 "TypeError: Cannot read property 'setFocusedCell' of undefined"。
我在 ag-grid-angular 组件的 ngOnInit 中调用 setFocusedCell。这是一个片段:
constructor(private mcService: MonteCarloService) {
this.gridOptions = <GridOptions>{
rowData: MCInputGridComponent.createRowData(),
columnDefs: MCInputGridComponent.createColumnDefs()
};
}
ngOnInit() {
this.gridOptions.api.setFocusedCell(1, "histDataType", null);
}
我已经定义了列并通过构造函数方法设置了一些数据。以下是列定义。
private static createColumnDefs() {
return [
{
colKey: "sprint#",
headerName: "Sprint #",
field: "sprint",
width: 80,
editable: false
},
{
colKey: "histDataType",
headerName: "Velocity",
field: "histDataType",
cellEditorFramework: NumericEditorComponent,
editable: true,
width: 102
}
];
}
不在ngOnInit中调用setFocusedCell,而是在onGridReady(gridReady)中调用