刚添加项目时,ag-grid 中的 startEditingCell 不起作用
startEditingCell in ag-grid does not work when Item has just been added
我正在尝试让我的 ag-grid 在添加新项目后立即开始编辑。它在网格已经有数据时有效,但如果它是网格中的第一个项目则无效。
var a = $scope.gridOptions.api.updateRowData({add: [newItem]});
$scope.gridOptions.api.refreshCells({force:true}); // does not help
$scope.gridOptions.api.startEditingCell({
rowIndex: a.add[0].rowIndex,
colKey: 'Note'
});
使用 ag-grid 版本 12.0.2。控制台什么都不显示。
似乎 updateRowData
不会自动启动 $digest
循环。添加 $scope.$apply
或 $timeout
或任何类似的东西可以缓解问题。
题目显示AngularJS代码。
这是您需要使用常规 Angular 执行的示例。
getContextMenuItems(params) {
var result = [
{
name: 'Add new row',
action: function() {
// Add a new row at the start of our agGrid's data array
params.context.rowData.unshift({});
params.api.setRowData(params.context.rowData);
params.api.refreshCells();
// Get the name of the first column in our grid
let columnField = params.column.userProvidedColDef.field;
// Highlight the left-hand cell in our new row, and start editing it
params.api.setFocusedCell(0, columnField, null);
params.api.startEditingCell({
rowIndex: 0,
colKey: columnField,
rowPinned: null
});
},
icon: '<img src="../../assets/images/icnAdd.png" width="14"/>'
}
];
return result;
}
希望对您有所帮助。
我正在尝试让我的 ag-grid 在添加新项目后立即开始编辑。它在网格已经有数据时有效,但如果它是网格中的第一个项目则无效。
var a = $scope.gridOptions.api.updateRowData({add: [newItem]});
$scope.gridOptions.api.refreshCells({force:true}); // does not help
$scope.gridOptions.api.startEditingCell({
rowIndex: a.add[0].rowIndex,
colKey: 'Note'
});
使用 ag-grid 版本 12.0.2。控制台什么都不显示。
似乎 updateRowData
不会自动启动 $digest
循环。添加 $scope.$apply
或 $timeout
或任何类似的东西可以缓解问题。
题目显示AngularJS代码。
这是您需要使用常规 Angular 执行的示例。
getContextMenuItems(params) {
var result = [
{
name: 'Add new row',
action: function() {
// Add a new row at the start of our agGrid's data array
params.context.rowData.unshift({});
params.api.setRowData(params.context.rowData);
params.api.refreshCells();
// Get the name of the first column in our grid
let columnField = params.column.userProvidedColDef.field;
// Highlight the left-hand cell in our new row, and start editing it
params.api.setFocusedCell(0, columnField, null);
params.api.startEditingCell({
rowIndex: 0,
colKey: columnField,
rowPinned: null
});
},
icon: '<img src="../../assets/images/icnAdd.png" width="14"/>'
}
];
return result;
}
希望对您有所帮助。