【问题标题】:AG-Grid: Make editable columns based on response from serverAG-Grid:根据服务器的响应制作可编辑的列
【发布时间】:2018-05-07 19:29:53
【问题描述】:

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

如果 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...}]
    }

非常感谢您的帮助。

p.s:您不能使用 column["editable"] = true; 等方法使单元格可编辑。它行不通。它需要是一个返回 true 或 false 的函数。

【问题讨论】:

  • 我觉得你想做的应该很简单,但是你的代码示例看起来有点糊涂...

标签: javascript angular typescript ag-grid


【解决方案1】:

我不太了解 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_id_field 不为空的行编辑your_date_field 单元格。

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

【讨论】:

  • 成功了。非常感谢
猜你喜欢
  • 2019-06-29
  • 2020-03-30
  • 2018-10-24
  • 2019-03-10
  • 1970-01-01
  • 1970-01-01
  • 2019-07-21
  • 2021-03-14
  • 2023-02-07
相关资源
最近更新 更多