Browse Source

feat(handsontable): baseEditor增加锁定方法

vian 3 years ago
parent
commit
a5e64c31e9
2 changed files with 25 additions and 0 deletions
  1. 6 0
      handsontable/handsontable.d.ts
  2. 19 0
      handsontable/src/editors/_baseEditor.js

+ 6 - 0
handsontable/handsontable.d.ts

@@ -317,6 +317,12 @@ declare namespace Handsontable {
       saveValue(val?: any, ctrlDown?: boolean): void;
 
       setValue(newValue?: any): void;
+
+      lock(): void;
+
+      unlock(): void;
+
+      getLockState(): boolean;
     }
 
     class Checkbox extends Base {

+ 19 - 0
handsontable/src/editors/_baseEditor.js

@@ -1,5 +1,6 @@
 import { CellCoords } from './../3rdparty/walkontable/src';
 import { stringify } from './../helpers/mixed';
+import EditorManager from './../editorManager';
 
 export const EditorState = {
   VIRGIN: 'STATE_VIRGIN', // before editing
@@ -266,4 +267,22 @@ BaseEditor.prototype.checkEditorSection = function() {
   return section;
 };
 
+// 锁定editor,锁定后,点击事件不会关闭editor
+BaseEditor.prototype.lock = function() {
+  const editorManagerInstance = EditorManager.getInstance(this.instance);
+  editorManagerInstance.lockEditor();
+};
+
+// 解锁editor
+BaseEditor.prototype.unlock = function() {
+  const editorManagerInstance = EditorManager.getInstance(this.instance);
+  editorManagerInstance.unlockEditor();
+};
+
+// 获取editor是否锁定
+BaseEditor.prototype.getLockState = function() {
+  const editorManagerInstance = EditorManager.getInstance(this.instance);
+  return editorManagerInstance.getLockState();
+};
+
 export default BaseEditor;