[英]How to force ExtJS to consider value in grid cell changed after custom editing completes?
I have an ExtJS EditorGridPanel with several columns. 我有一个带有几列的ExtJS EditorGridPanel。 One of the columns is bound to a complex data type (an array of objects), and uses a custom editor to modify those values in a pop-up window. 其中一列绑定到复杂的数据类型(对象数组),并使用自定义编辑器在弹出窗口中修改这些值。 That part is tested and all works fine - the JsonStore is keeping the complex values, setting the custom editor's value when it's focused and editing begins, and picking up the final value when editing is complete. 该部分已经过测试,并且一切正常-JsonStore保留了复杂的值,在聚焦并开始编辑时设置了自定义编辑器的值,并在完成编辑后选择了最终值。
The only problem is, for this complex data type, the Javascript string value does not appear to include the sub-attributes, but is instead represented as "[object Object]". 唯一的问题是,对于这种复杂的数据类型,Javascript字符串值似乎不包含子属性,而是表示为“ [object Object]”。 Therefore, if the array contains two items when editing begins, and two items after editing is complete, even if some of the sub-attributes of the two items have changed, the grid editor doesn't know this, because (String)value === (String)startValue
(that is, '[object Object],[object Object]' === '[object Object],[object Object]'
). 因此,如果数组在开始编辑时包含两个项目,并且在编辑完成后包含两个项目,即使两个项目的某些子属性已更改,网格编辑器也不知道这一点,因为(String)value === (String)startValue
(即'[object Object],[object Object]' === '[object Object],[object Object]'
)。
I'm certain this is the problem, because if the custom sub-editor increases the number of items in the list, the string values are different ( '[object Object],[object Object],[object Object]' !== '[object Object],[object Object]'
), and the value properly changes (with change event propagating to the store). 我确定这是问题所在,因为如果自定义子编辑器增加了列表中的项目数,则字符串值会有所不同( '[object Object],[object Object],[object Object]' !== '[object Object],[object Object]'
),并且值正确更改(随着change事件传播到商店)。
The complete onEditComplete function of the EditorGridPanel is shown below (full source here ): 下面显示了EditorGridPanel的完整onEditComplete函数( 此处完整源代码):
onEditComplete : function(ed, value, startValue){ this.editing = false; this.lastActiveEditor = this.activeEditor; this.activeEditor = null; var r = ed.record, field = this.colModel.getDataIndex(ed.col); value = this.postEditValue(value, startValue, r, field); if(this.forceValidation === true || String(value) !== String(startValue)){ var e = { grid: this, record: r, field: field, originalValue: startValue, value: value, row: ed.row, column: ed.col, cancel:false }; if(this.fireEvent("validateedit", e) !== false && !e.cancel && String(value) !== String(startValue)){ r.set(field, e.value); delete e.cancel; this.fireEvent("afteredit", e); } } this.view.focusCell(ed.row, ed.col); },
So there are a number of possible solutions, but I don't know how to make any of them work. 因此,有许多可能的解决方案,但我不知道如何使它们中的任何一个起作用。
String(value) !== String(startValue))
clause above is always true. 为EditorGrid的此特定列提供一个自定义GridEditor,它认为startValue始终是一些伪值,因此上面的String(value) !== String(startValue))
子句始终为true。 This seems difficult because you don't have access to the GridEditor from within the custom field (since it is in the Field hierarchy and doesn't know about the GridEditor controlling it). 这似乎很困难,因为您无法从自定义字段访问GridEditor(因为它位于Field层次结构中,并且不知道GridEditor对其进行控制)。 var myObj = { 'objId': 1, 'objValue': value }; var myObj = {'objId':1,'objValue':value};
var myValue = [myObj]; var myValue = [myObj];
then instead of (String)myValue being '[object Object]'
, it will instead be something like '[{objId:1,objValue:value}]'
. 然后,而不是(String)myValue是'[object Object]'
,它将是类似'[{objId:1,objValue:value}]'
。
Nevermind, it appears that I wasn't correctly adding the toString() function to my objects. 没关系,看来我没有正确地将toString()函数添加到我的对象中。 Doing so fixes the problem. 这样做可以解决问题。
var myObj = {'objId':1,'objValue':'value'};
myObj.toString = function(){ return String.format('MyObj {objId:{0},objValue:{1}}',this.objId,this.objValue);};
var myValue = [myObj];
Now, the String value of myValue
above is [MyObj {objId:1,objValue:value}]
instead of [object Object]
and the problem is solved - the GridEditor correctly updates the record when any one of the underlying objects' attributes have changed. 现在,上面的myValue
的String值为[MyObj {objId:1,objValue:value}]
而不是[object Object]
,问题已解决-当任何基础对象的属性发生更改时,GridEditor都会正确更新记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.