Javascript AG网格:根据服务器的响应生成可编辑列

Javascript AG网格:根据服务器的响应生成可编辑列,javascript,angular,typescript,ag-grid,Javascript,Angular,Typescript,Ag Grid,我需要一些工作上的帮助。故事是这样的: ---| Item-Id | Date | Justification |--- ---------------------------------------- ---| |24.05 | text |--- ---------------------------------------- ---| 31 |25.05 | text 2 |---

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

    ---| 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        |---
    ----------------------------------------
    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...}]
    }
如果项目Id!=我需要使“日期”列可编辑无效

我们有一个“视图”,其中有一个使用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        |---
    ----------------------------------------
    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...}]
    }
要在AG grid中生成列标题,您需要一个对象:

    public columnDefs = [
        {title: Item-Id, editable: this.editable()},
        {title: Date, editable: this.editable()},
        {title: Justification, editable: this.editable()}
    ];
…一些代码

在Get方法中,我有如下内容:

    ---| 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        |---
    ----------------------------------------
    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...}]
    }
我非常感谢你的帮助


p、 s:不能使用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\u date\u字段
单元格中
your\u id\u字段
不为空的行


根据需要进行修改以使其在代码中工作。

我认为您想做的应该很简单,但是您的代码示例看起来有点混乱……它工作了。非常感谢