antd v3.0 升级问题

刚刚将 antd 的版本升级到了 v3.0 ,table 组件中的 column 里的 onCell 不是很了解,

我本来在 column 中是这样使用的:

onCellClick: (record, event) => {  
     //单元格点击回调
},
Warning: column[onCellClick] is deprecated, please use column[onCell] instead.

但是按照警告我直接改成了 onCell 就报 render pure function 的错误。

onCell 是会先渲染的,但是不知道怎么加单元格的点击回调,我试着在里面加了 onClick 是没用的。

阅读 7.1k
2 个回答

旧写法:

const columns = [{
  ...,
  onCellClick: (record, event) => {  
    // balah balah
  },
}]

新写法:

const columns = [{
  ...,
  onCell: (record) => ({
    onClick: (e) => {
      // balah balah
    }
  })
}];

onCell 的返回值会作为 tdprops

你应该在onCell的函数体里返回的组件上注册onClick事件

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