我想从自定义编辑器的构造函数中取消编辑并导致活动单元格失去焦点。目前,我可以cancelEdit
从传递给构造函数的对象中调用,但我还必须在 , 中使用标志,loadValue
并检查是否发生过早取消。此外,发生这种情况时,单元格不会失去焦点。isValueChanged
serializeValue
destroy
这可能吗?
编辑
下面是编辑器构造函数的片段。它允许注册(添加)一个编辑器并为其分配一个名称。在调用时,编辑器获取 的值args.item.type
并尝试检索为该值注册的编辑器。未显示的是仅遵循委托模式的代码,这会导致MyConstructor
实例将工作委托给其内部编辑器实例。
如果没有与 的值匹配的编辑器args.item.type
,则构造函数会尝试取消编辑。
MyConstructor = (function(){
var editors = {}
var defaultEditor = TextCellEditor
constructorFn = function(args){
this.init(args)
}
constructorFn.overridesEnabled = false
constructorFn.defaultEditorEnabled = true;
constructorFn.prototype.init = function(args){
var editorExists = function(dataType){
if(dataType in editors){
return true
}
if(constructorFn.defaultEditorEnabled){
return true
}
return false
}
var getEditor = function(args){
if(args.item.type in editors){
editorConstructor = editors[args.item.type]
return new editorConstructor(args)
}
else{
editorConstructor = defaultEditor
return new editorConstructor(args)
}
}
if(editorExists(args.item.type))
{
this.superClass.init.call(args)
this.editor = getEditor(args)
}
else{
debug.error("Prematurely destroying editor")
args.cancelChanges()
this.mumps = true
}
}
constructorFn.registerEditor = function(name, constructor){
if(name in editors){
if(constructorFn.overridesEnabled){
editors[name] = constructor
}
else{
//Log error
debug.error("Cannot override existing constructor: " + name)
}
}
else{
editors[name] = constructor
}
}
})()