I need some help for work. The story goes like this:
I need to make the "Date" Column editable if Item-Id !== null;
We have a "view" where we have an inbox created with AG-Grid. The inbox looks like this:
---| Item-Id | Date | Justification |---
----------------------------------------
---| |24.05 | text |---
----------------------------------------
---| 31 |25.05 | text 2 |---
----------------------------------------
---| 31 |25.05 | text 2 |---
----------------------------------------
---| |24.05 | text |---
----------------------------------------
---| |24.05 | text |---
----------------------------------------
---| 31 |25.05 | text 2 |---
----------------------------------------
To generate the column headers in AG-grid you have an object:
public columnDefs = [
{title: Item-Id, editable: this.editable()},
{title: Date, editable: this.editable()},
{title: Justification, editable: this.editable()}
];
...some code...
in the Get method I have something like this:
http.get(data).subscribe(response(
{
...some code...
this.editableColumns(response);
}));
public editableColumns(item: any) {
//this method need to return true or false;
console.log(response); // [{itemId: null, date: "24.05", justification: "text"},{itemId: 31, date: "24.05", justification: "text"},...etc...}]
}
I would very much appreciate your help.
p.s: you cannot make the cells editable by using methods like column["editable"] = true; It won't work. It needs to be a function that returns true or false.
I don't really know the structure of Angular, but I think you want something as simple as this:
const columnDefs = [
{
headerName: 'Item-Id',
field: 'your_id_field',
},
{
headerName: 'Date',
field: 'your_date_field',
editable: function(params) {
return params.node.data.your_id_field !== null;
}
},
{
headerName: 'Justification',
field: 'your_justification_field',
},
];
That will allow the your_date_field
cell to be edited for rows where your_id_field
is not null.
Modify as needed to get it to work in your code.
来源:https://stackoverflow.com/questions/47462154/ag-grid-make-editable-columns-based-on-response-from-server