找回密码
 立即注册

QQ登录

只需一步,快速开始

aubreyqian

注册会员

3

主题

7

帖子

44

积分

注册会员

积分
44
aubreyqian
注册会员   /  发表于:2020-8-24 01:09  /   查看:2743  /  回复:3
20金币
您好:
我这边做AutoComplete的时候  用的antd的autocomplete.
我想请问下这个自定义单元格显示以后,是在单元格什么时候结束编辑的。
我这边遇到的情况是在autoComplete点击悬浮的选项后,直接调用了getEditorValue,deactivateEditor事件。好像就是直接结束了该单元格的编辑状态  导致自定义单元格关闭。好像是我定义的组件的事件执行之前 editorContext 这块元素就销毁了

我有什么办法控制这个关闭事件么。就是AutoComplete例子 这个例子里 ,怎样能让这个autoComplete一直显示,然后手动的去结束编辑状态  ,手动的让这个autoComplete变回正常的cell

  1. const AutoNode = ({ AllTag, context }: { AllTag: string[]; context: any }) => {
  2.       const [tagList, setTagList] = useState<string[]>([]);
  3.       const [tagValue, setTagValue] = useState('');
  4.       const handleAutoCompleteChange = (st: any) => {
  5.         const newTagList = AllTag.filter(t => t.indexOf(st) > -1);
  6.         setTagList([...newTagList]);
  7.       };
  8.       const hanleAutoSelect = (s: any) => {
  9.         // 无法触发
  10.         // setTagValue(s);
  11.       };
  12.       const handleAutoChange = (c: any) => {
  13.         // 无法触发
  14.         // setTagValue(c);
  15.       };
  16.       const handleBlur = () => {
  17.         console.log('handleBlur---', tagValue);
  18.         console.log(context);
  19.         context.sheet.startEdit(true);
  20.       };
  21.       useEffect(() => {
  22.         setTagList([...taxReconTagList]);
  23.       }, [taxReconTagList]);
  24.       return (
  25.         <AutoComplete
  26.           // value={tagValue}
  27.           style={{ height: 19, width: '100%' }}
  28.           dataSource={tagList}
  29.           onSearch={searchText => handleAutoCompleteChange(searchText)}
  30.           onSelect={selectText => hanleAutoSelect(selectText)}
  31.           onChange={changeText => handleAutoChange(changeText)}
  32.           onBlur={handleBlur}
  33.         />
  34.       );
  35.     };
复制代码


  1. class AutocompleteCellType extends GC.Spread.Sheets.CellTypes.Base {
  2.         value: string;
  3.         allTag: string[];
  4.         constructor(tl: string[]) {
  5.           super();
  6.           this.value = '';
  7.           this.allTag = [...tl];
  8.         }
  9.       }
  10.       AutocompleteCellType.prototype.createEditorElement = function() {
  11.         return document.createElement('div');
  12.       };
  13.       AutocompleteCellType.prototype.activateEditor = function(
  14.         editorContext,
  15.         cellStyle,
  16.         cellRect,
  17.         context,
  18.       ) {
  19.         ReactDOM.render(<AutoNode AllTag={this.allTag} context={context} />, editorContext);
  20.       };
  21.       AutocompleteCellType.prototype.deactivateEditor = function(editorContext, context) {
  22.         console.log('deactivateEditor');
  23.         GC.Spread.Sheets.CellTypes.Base.prototype.deactivateEditor.call(
  24.           this,
  25.           editorContext,
  26.           context,
  27.         );
  28.         return;
  29.       };
  30.       AutocompleteCellType.prototype.setEditorValue = function(editorContext, value, context) {
  31.         return;
  32.       };
  33.       AutocompleteCellType.prototype.getEditorValue = function(editorContext, context) {
  34.         // context.sheet.endEdit(false)
  35.         return 111;
  36.       };
  37.       AutocompleteCellType.prototype.updateEditor = function(
  38.         editorContext,
  39.         cellStyle,
  40.         cellRect,
  41.         context,
  42.       ) {
  43.         cellRect.y += 47;
  44.         cellRect.x -= 2;
  45.         cellRect.height = 100;
  46.         if (editorContext) {
  47.           editorContext.style.width = `${cellRect.width}px`;
  48.           editorContext.style.height = '100px'; // `${cellRect.height}px`;
  49.         }
  50.         return cellRect;
  51.       };
  52.       AutocompleteCellType.prototype.isReservedKey = function(event, context) {
  53.         if (context.isEditing && (event.keyCode === 40 || event.keyCode === 38)) {
  54.           return true;
  55.         }
  56.         return false;
  57.       };
  58.       sheet.getRange(-1, 4, -1, 1).cellType(new AutocompleteCellType(taxReconTagList));
复制代码




最佳答案

查看完整内容

您说的是这个例子把? 这个点击到其他单元格时 当前单元格就结束编辑状态,悬浮框就消失,这种行为是符合预期效果的, 您说的问题可以具体在我附近的Demo中修改复现下吗?

3 个回复

倒序浏览
最佳答案
最佳答案
Fiooona
论坛元老   /  发表于:2020-8-24 01:09:21
来自 2#
image.png553188781.png
您说的是这个例子把?
这个点击到其他单元格时 当前单元格就结束编辑状态,悬浮框就消失,这种行为是符合预期效果的,
您说的问题可以具体在我附近的Demo中修改复现下吗?

Demo.zip

2.04 MB, 下载次数: 73

组件化表格编辑器(预览版)试用进行中,点击了解详情!
请点击评分,对我的服务做出评价!5分为非常满意!
回复 使用道具 举报
小鱼
注册会员   /  发表于:2021-9-7 12:01:15
3#
你这个后来解决了吗?cell 可以兼容atnd的组件吗
回复 使用道具 举报
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-9-7 16:12:27
4#
您好,
本贴时间较久,已做结帖处理。
建议您在求助中心版本另开新帖,并详细描述您当前的问题,
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部