VTable icon indicating copy to clipboard operation
VTable copied to clipboard

[Bug] ListTable 的编辑表格中 `editCellTrigger` 字段调用 `updateOption` 方法更新无效

Open libondev opened this issue 1 year ago • 3 comments

Version

1.16.0

Link to Minimal Reproduction

https://visactor.io/vtable/demo/edit/edit-cell

Steps to Reproduce

在官网的编辑示例的代码中即可复现,复现问题的关键代码为:

setTimeout(() => {
  option.editCellTrigger = 'api'
  tableInstance.updateOption(option)

  alert('修改编辑方式为: ' + tableInstance.options.editCellTrigger)
}, 2000)

完整代码如下:

let tableInstance;
// 使用时需要引入插件包@visactor/vtable-editors
// import * as VTable_editors from '@visactor/vtable-editors';
// 正常使用方式 const input_editor = new VTable.editors.InputEditor();
// 官网编辑器中将 VTable.editors重命名成了VTable_editors
const input_editor = new VTable_editors.InputEditor();
const date_input_editor = new VTable_editors.DateInputEditor();
const list_editor = new VTable_editors.ListEditor({ values: ['girl', 'boy'] });
const textArea_editor = new VTable_editors.TextAreaEditor({ readonly: false });
VTable.register.editor('input-editor', input_editor);
VTable.register.editor('date-input-editor', date_input_editor);
VTable.register.editor('list-editor', list_editor);
VTable.register.editor('textArea-editor', textArea_editor);

function generateRandomString(length) {
  let result = '';
  const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  for (let i = 0; i < length; i++) {
    result += characters.charAt(Math.floor(Math.random() * characters.length));
  }
  return result;
}
function generateRandomHobbies() {
  const hobbies = [
    'Reading books',
    'Playing video games',
    'Watching movies',
    'Cooking',
    'Hiking',
    'Traveling',
    'Photography',
    'Playing \n musical /n instruments',
    'Gardening',
    'Painting',
    'Writing',
    'Swimming'
  ];

  const numHobbies = Math.floor(Math.random() * 3) + 1; // 生成 1-3 之间的随机整数
  const selectedHobbies = [];

  for (let i = 0; i < numHobbies; i++) {
    const randomIndex = Math.floor(Math.random() * hobbies.length);
    const hobby = hobbies[randomIndex];
    selectedHobbies.push(hobby);
    hobbies.splice(randomIndex, 1); // 确保每个爱好只选一次
  }

  return selectedHobbies.join(', ');
}
function generateRandomBirthday() {
  const start = new Date('1970-01-01');
  const end = new Date('2000-12-31');
  const randomDate = new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
  const year = randomDate.getFullYear();
  const month = randomDate.getMonth() + 1;
  const day = randomDate.getDate();
  return `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`;
}
function generateRandomPhoneNumber() {
  const areaCode = [
    '130',
    '131',
    '132',
    '133',
    '134',
    '135',
    '136',
    '137',
    '138',
    '139',
    '150',
    '151',
    '152',
    '153',
    '155',
    '156',
    '157',
    '158',
    '159',
    '170',
    '176',
    '177',
    '178',
    '180',
    '181',
    '182',
    '183',
    '184',
    '185',
    '186',
    '187',
    '188',
    '189'
  ];
  const prefix = areaCode[Math.floor(Math.random() * areaCode.length)];
  const suffix = String(Math.random()).substr(2, 8);
  return prefix + suffix;
}
const generatePersons = count => {
  return Array.from(new Array(count)).map((_, i) => {
    const first = generateRandomString(10);
    const last = generateRandomString(4);
    return {
      id: i + 1,
      email1: `${first}_${last}@xxx.com`,
      name: first,
      lastName: last,
      hobbies: generateRandomHobbies(),
      birthday: generateRandomBirthday(),
      tel: generateRandomPhoneNumber(),
      address: `No.${i + 100} ${generateRandomString(10)} ${generateRandomString(5)}\n${generateRandomString(5)}`,
      sex: i % 2 === 0 ? 'boy' : 'girl',
      work: i % 2 === 0 ? 'back-end engineer' : 'front-end engineer',
      city: 'beijing'
    };
  });
};
const records = generatePersons(10);
const columns = [
  {
    field: 'id',
    title: 'ID',
    width: 80,
    sort: true
  },
  // {
  //   field: 'email1',
  //   title: 'email',
  //   width: 'auto',
  //   sort: true,
  //   editor: 'input-editor'
  // },
  {
    field: 'full name',
    title: 'Full name',
    columns: [
      {
        field: 'name',
        title: 'First Name\n(input editor)',
        width: 120,
        editor: 'input-editor'
      },
      {
        field: 'lastName',
        title: 'Last Name\n(input editor)',
        width: 100,
        editor: 'input-editor'
      }
    ]
  },
  // {
  //   field: 'hobbies',
  //   title: 'hobbies',
  //   width: 100,
  //   editor: 'input-editor'
  // },
  {
    field: 'birthday',
    title: 'birthday\n(date editor)',
    width: 120,
    editor: 'date-input-editor'
  },
  {
    field: 'sex',
    title: 'sex\n(list editor)',
    width: 100,
    editor: 'list-editor'
  },
  {
    field: 'address',
    title: 'address\n(textArea editor)',
    width: 300,
    editor: 'textArea-editor'
  },
  {
    field: 'tel',
    title: 'telephone',
    width: 150
  },
  {
    field: 'work',
    title: 'job',
    width: 200
  },
  {
    field: 'city',
    title: 'city',
    width: 150
  }
];
const option = {
  container: document.getElementById(CONTAINER_ID),
  records,
  columns,
  enableLineBreak: true,
  autoWrapText: true,
  limitMaxAutoWidth: 600,
  heightMode: 'autoHeight',
  editCellTrigger: 'click',
  keyboardOptions: {
    copySelected: true,
    pasteValueToCell: true,
    selectAllOnCtrlA: true
  }
};
tableInstance = new VTable.ListTable(option);
tableInstance.on('change_cell_value', arg => {
  console.log(arg);
});

setTimeout(() => {
  option.editCellTrigger = 'api'
  tableInstance.updateOption(option)

  alert('修改编辑方式为: ' + tableInstance.options.editCellTrigger)
}, 2000)

window['tableInstance'] = tableInstance;

Current Behavior

默认触发编辑的行为为 'click',在手动修改为 'api' ,并调用 updateOption 后表格实例内部的选项成功修改为 api,但是界面中的交互逻辑没有受到影响

Expected Behavior

交互行为应该符合传入的新配置(如果变更为 api 时,没有手动调用开启编辑状态时则不应该触发编辑行为)

Environment

- OS: Macos Sequoia 15.3 或任意
- Browser: chrome browser 或任意
- Framework: 任意

Any additional comments?

No response

libondev avatar Feb 15 '25 13:02 libondev

感谢你的反馈!我们已经收到你的问题,并将在后续进行处理。 如果有开发者对这个 issue 感兴趣,请在issue下方留言“认领该issue”,留言后开始你的创作提pr给我们! 欢迎大家参与开源共建!我们非常感激每一位贡献者,提交pr后我们将为参与共建的开发者准备一份礼品。 参与共建可参考:https://visactor.io/vtable/guide/Contribution_Guide 与官方开发者交流问题可以下载飞书app扫码加入飞书群: 飞书20241029-170312 再次感谢你的支持!

Thank you for your feedback! We have received your question and will deal with it later. If any developer is interested in this issue, please leave a message "claim this issue" below the issue. Welcome to participate in open source co-construction! We are very grateful to every contributor. After submitting the PR, we will prepare a gift for the developers who participated in the co-construction. For participation in co-construction, please refer to: https://visactor.io/vtable/guide/Contribution_Guide To communicate with official developers, you can download the Feishu app and scan the QR code to join the Feishu group! Thank you again for your support!

fangsmile avatar Feb 17 '25 02:02 fangsmile

认领该issue

libondev avatar Feb 17 '25 02:02 libondev

Completed in #3438

libondev avatar Feb 24 '25 09:02 libondev