我正在开发一个将master-detail设置为true的ag-grid,master-detail的第一行具有可编辑的单元格,即“ contractID”,我想根据获取的contractID填充master-detail的其他单元格
我尝试在columnDef中添加cellValueChanged,并且还尝试在detailGrid的onFirstDataRendered方法中显式设置params.api.rowModel.gridApi.cellValueChanged,但是没有任何帮助。
主要详细信息网格代码:
detailCellRendererParams = {
detailGridOptions: {
columnDefs: [
{ headerName: "Contact ID", field: "contractId", editable: true, [cellValueChanged]: "cellValueChanged()" },
{ headerName: "Contact Name", field: "contractName" },
{ headerName: "Category", field: "category" }]
}
}
onFirstDataRendered(params) {
params.api.rowModel.gridApi.cellValueChanged = function (params) {
console.log("cellChanged");
}
}
答案 0 :(得分:0)
使用自定义cellRenderer修复了该问题,并为更改事件添加了eventListener。我只想在网格的第一行上具有此功能,因此为rowIndex添加了一个条件。
detailCellRendererParams = {
detailGridOptions: {
columnDefs: [{headerName: "Contact ID",field: "contractId",editable: true,
cellRenderer: (params) => {
params.eGridCell.addEventListener('change', (e) => {
this.getDetails(e.target.value);
})
},
{headerName: "Contact Name", field: "contractName"},
{headerName: "Category",field: "category"}]
}
}
getDetails(id): void {
this.apiService.getDetails(id)
.subscribe(result => {
this.gridApi.detailGridInfoMap.detail_0.api.forEachNode(node=> {
if(node.rowIndex == 0){
node.data = result;
node.gridApi.refreshCells();
}}
);
})}
答案 1 :(得分:0)
如果有人仍然想知道,请详细地添加GridOptions:
onCellValueChanged: function ($event) {
// your code here
},
这将在您每次更改单元格值时触发。