AG-Grid:根据服务器的响应制作可编辑的列

And*_*ise 4 javascript typescript ag-grid angular

我需要一些工作帮助。故事是这样的:

如果 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        |---
    ----------------------------------------
Run Code Online (Sandbox Code Playgroud)

要在 AG-grid 中生成列标题,您有一个对象:

    public columnDefs = [
        {title: Item-Id, editable: this.editable()},
        {title: Date, editable: this.editable()},
        {title: Justification, editable: this.editable()}
    ];
Run Code Online (Sandbox Code Playgroud)

...一些代码...

在 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...}]
    }
Run Code Online (Sandbox Code Playgroud)

我非常感谢你的帮助。

ps:您不能使用诸如column["editable"] = true;之类的方法使单元格可编辑。这是行不通的。它必须是一个返回 true 或 false 的函数。

thi*_*dot 5

我真的不知道 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',
    },
];
Run Code Online (Sandbox Code Playgroud)

这将允许your_date_field编辑单元格中your_id_field不为空的行。

根据需要进行修改以使其在您的代码中运行。