[英]AG-Grid: Make editable columns based on response from server
我需要工作上的帮助。 故事是这样的:
如果Item-Id!== null,则需要使“日期”列可编辑。
我们有一个“视图”,其中有一个使用AG-Grid创建的收件箱。 收件箱如下所示:
---| 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 |---
----------------------------------------
要在AG-grid中生成列标题,您有一个对象:
public columnDefs = [
{title: Item-Id, editable: this.editable()},
{title: Date, editable: this.editable()},
{title: Justification, editable: this.editable()}
];
...一些代码...
在Get方法中,我有类似以下内容:
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...}]
}
非常感谢您的帮助。
ps:您无法使用诸如column [“ editable”] = true之类的方法来使单元格可编辑; 它不会工作。 它必须是一个返回true或false的函数。
我真的不知道Angular的结构,但是我想您想要这样简单的东西:
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',
},
];
这将允许your_date_field
细胞进行编辑的行,其中your_id_field
不为空。
根据需要进行修改以使其在您的代码中起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.