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

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

image.png

示例代码

阅读 5k
1 个回答

你需要通过 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)
            };
          }
        };
      }
    });

点击查看示例

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题