Well, the title looks quite similar to other posts:
Angular Grid ag-grid columnDefs Dynamically change
AG-Grid: Make editable columns based on response from server
but I'm going to ask a slightly different question.
Now I have a bunch of columns stored in tableColumns variable.
Each column has a editable property.
For existing data, some columns are editable and some are not. This is achieved by below function. It is called when I define columnDefs.
checkEditable(columnName: string){
var editable = false;
this.configData.some((el) => {
if (columnName == el.key.columnName){
return el.editable == "Y";
}
});
return editable;
}
However, for newly inserted rows which got appended at the bottom of my grid, I want all columns to be editable for this record only.
This record can be identified by column isChanged = "inserted".
insertNewRow(){
var newItem = this.createNewRowData();
var res = this.gridOptions.api.updateRowData({add: [newItem]});
var updatedColDefs = [];
**//how can I update columnDefs here, so that all fields are editable for this record?**
var col = this.gridOptions.api.setColumnDefs(updatedColDefs);
}
createNewRowData(){
var newData = [];
this.tableColumns.forEach(item => {
if (item.headerName == "isChanged") {
newData["isChanged"] = "inserted";
} else {
newData[item.headerName] = "";
}
});
console.log(newData);
return newData;
}
Most likely I will have to create a function to achieve this, but seems like I am unable to assign function to 'editable' property of the column? What would be the correct syntax?