Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
562 views
in Technique[技术] by (71.8m points)

Antd 表格如何设置表头分组的可编辑行?

表格设置了表头分组后 使用可编辑行无效

image.png

示例代码


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

你需要通过 onCell 方法修改 childrencloumn 的属性。

    const columns = this.columns.map(col => {
      if (!col.editable) {
        return col;
      }

      if (col.children) {
        return {
          ...col,
          children: [
            {
              ...col.children[0],
              onCell: record => {
                return {
                  record,
                  inputType: "text",
                  dataIndex: col.children[0].dataIndex,
                  title: col.children[0].title,
                  editing: this.isEditing(record)
                };
              }
            },
            {
              ...col.children[1],
              onCell: record => {
                return {
                  record,
                  inputType: "text",
                  dataIndex: col.children[0].dataIndex,
                  title: col.children[0].title,
                  editing: this.isEditing(record)
                };
              }
            }
          ]
        };
      } else {
        return {
          ...col,
          onCell: record => {
            return {
              record,
              inputType: col.dataIndex === "age" ? "number" : "text",
              dataIndex: col.dataIndex,
              title: col.title,
              editing: this.isEditing(record)
            };
          }
        };
      }
    });

点击查看示例


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...