ag-grid无法在ngOnInit中设置聚焦单元格

时间:2017-12-15 16:48:20

标签: ag-grid

我正在尝试将焦点设置到我的网格中的第一个可编辑单元格并且出现此错误" TypeError:无法读取属性' setFocusedCell'未定义"。

我在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
        }
    ];
}

1 个答案:

答案 0 :(得分:0)

不是在ngOnInit中调用setFocusedCell,而是在onGridReady(gridReady)中调用它