简体   繁体   English

可排序和可编辑的Ant设计表

[英]Ant Design Table which is both sortable and editable

I'm trying to create an Ant.Design table which is both sortable and editable. 我正在尝试创建一个可排序和可编辑的Ant.Design表。 The Ant.Design docs show sample code of both ( here and here ). Ant.Design文档显示了这两个示例代码( 此处此处 )。 I tried to combine these in a minimal code repository here: https://github.com/Silox/Ant-Design--EditableSortableTable . 我试图将它们合并到一个最小的代码存储库中, 网址为https : //github.com/Silox/Ant-Design--EditableSortableTable

The main problem is that the table gets reordered while editing a value and I haven't found a way to prevent this. 主要问题是在编辑值时表会重新排序,但我还没有找到防止这种情况的方法。 The behaviour I am looking for is that when a user edits a cell, the ordering is put "on hold", and when the user is done editing, the table is resorted. 我正在寻找的行为是,当用户编辑单元格时,排序被“保留”,而当用户完成编辑时,将使用表。 Would anyone have any idea to accomplish this? 有人有什么想法要实现这一目标吗?

How about this: 这个怎么样:

  • Add a boolean state editing to EditableSortableTable . 将布尔状态editing添加到EditableSortableTable
  • Set it in setEditable/setNotEditable to isEditableMap.length > 0 . 将其在setEditable/setNotEditableisEditableMap.length > 0

  • for EditableSortableTable add: EditableSortableTable添加:

shouldComponentUpdate(nextProps, nextState) { return !(nextState.editing && this.state.editing) }

[update] Given the requirement to not use shouldComponentUpdate() you can introduce a new _sortTitle prop on the table objects and sort the rows based on this prop. [更新]鉴于使用shouldComponentUpdate()的要求,您可以在表对象上引入一个新的_sortTitle道具,并根据该道具对行进行排序。 This prop is not rendered, but is set to title when mounting, and then updated only once edit of a title cell is complete. 该道具不会渲染,而是在安装时设置为title ,然后仅在标题单元的编辑完成后才更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM