Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[table] edit模式失焦多次获取的值异常 #2577

Closed
huangpiqiao opened this issue Jul 12, 2023 · 4 comments
Closed

[table] edit模式失焦多次获取的值异常 #2577

huangpiqiao opened this issue Jul 12, 2023 · 4 comments
Assignees
Labels
🐞 bug Something isn't working 💪🏻 enhancement New feature or request

Comments

@huangpiqiao
Copy link
Contributor

tdesign-vue 版本

1.4.7

重现链接

https://stackblitz.com/edit/xvkuiw?file=package.json,src%2Fdemo.vue

重现步骤

  1. 先输入1失焦
  2. 再输入1再失焦
57bb28744ac2adb2359147bb3dd6fedc.mov

期望结果

每次都能得到结果2

实际结果

第一次得到结果2,第二次以后得到结果1

框架版本

No response

浏览器版本

No response

系统版本

No response

Node版本

No response

补充说明

No response

@github-actions
Copy link
Contributor

👋 @huangpiqiao,感谢给 TDesign 提出了 issue。
请根据 issue 模版确保背景信息的完善,我们将调查并尽快回复你。

@github-actions
Copy link
Contributor

♥️ 有劳 @chaishi @nined9 @yanxugong @chuyueZhang 尽快确认问题。
确认有效后将下一步计划和可能需要的时间回复给 @huangpiqiao

@chaishi chaishi added the 🐞 bug Something isn't working label Jul 12, 2023
@chaishi
Copy link
Collaborator

chaishi commented Jul 23, 2023

原因分析:表格数据必须有 2 个变量控制,一个是正在输入过程中 保存之前存储的临时变量,一个是原始数据。

methods: {
  handleBlur({ rowIndex, editedRow }) {
    /**
     * 输入框里面输入的数据都是临时变量,存储变更。只有保存成功后,才会真正的改变成表格的数据 data。
     * 但此处的做法是还没有保存,就直接改变了的输入框的数据,不符合可编辑单元格保存后才更新表格数据的逻辑。
     */
    this.$set(this.data[rowIndex], 'a', String(Number(editedRow.a) + 1));
  },
},

@chaishi
Copy link
Collaborator

chaishi commented Jul 23, 2023

待 PR #2605 合并后,使用如下示例代码方法更新编辑状态的数据 updateEditedCellValue

computed: {
  columns() {
    return [
      {
        colKey: 'a',
        edit: {
          component: Input,
          showEditIcon: false,
          props: ({ editedRow, updateEditedCellValue }) => {
            return {
              onBlur: () => this.handleBlur({ editedRow, updateEditedCellValue }),
            };
          },
        },
      },
    ];
  },
},
methods: {
  handleBlur({ editedRow, updateEditedCellValue }) {
    updateEditedCellValue(String(Number(editedRow.a) + 1));
  },
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 💪🏻 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants