【问题标题】:ag-grid Cannot set focused cell in ngOnInitag-grid 无法在 ngOnInit 中设置焦点单元格
【发布时间】:2018-05-29 22:00:31
【问题描述】:

我正在尝试将焦点设置到网格中的第一个可编辑单元格并收到此错误“TypeError: Cannot read property 'setFocusedCell' of undefined”。

我在我的 ag-grid-angular 组件中的 ngOnInit 中调用 setFocusedCell。这是一个sn-p:

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

【问题讨论】:

    标签: ag-grid


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2018-12-25
      • 2023-01-26
      • 2017-05-13
      • 1970-01-01
      • 2019-08-06
      • 2020-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多