简体   繁体   English

自定义编辑完成后,如何强制ExtJS考虑更改的网格单元中的值?

[英]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. 因此,有许多可能的解决方案,但我不知道如何使它们中的任何一个起作用。

  1. Provide a custom GridEditor for this particular column of the EditorGrid, which considers the startValue to always be some dummy value, so that the 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对其进行控制)。
  2. Somehow get a handle on the GridEditor being used to control my custom Field, from some kind of event. 通过某种事件以某种方式获得用于控制我的自定义字段的GridEditor的句柄。 If I can do that, I can set the startValue (a public property) to some dummy value that is known to be different from the final value. 如果可以的话,可以将startValue(一个公共属性)设置为某个已知值与最终值不同的虚拟值。 Then the normal "changed value" code will work as expected. 然后,正常的“更改值”代码将按预期工作。 I haven't found any reasonable way to get a handle to this editor from within my field, however. 但是,我还没有找到任何合理的方法来从我的领域中使用此编辑器。
  3. Convince Javascript to spit out all of the sub-attributes of my objects into the String representation, so that if my object is 说服Javascript将我对象的所有子属性吐出到String表示形式中,这样我的对象就是

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.

相关问题 (Ag-Grid)在编辑时,如何立即更改值,而不是在单元格失去焦点后? - (Ag-Grid) While editing, how to get value changed immediately, not after cell loses focus? ExtJs 6.0:使用组合框编辑网格单元-不同步id值 - ExtJs 6.0 : Grid Cell Editing with a Combobox - Not Syncing the id value 在extjs 6中编辑后重新加载商店和网格 - Reload the store and grid after editing in extjs 6 如何避免在使用单元格编辑的ExtJS网格上按两次保存按钮 - How to avoid pressing save button twice on an ExtJS grid that uses cell editing 可编辑网格ExtJS,如何在网格上编辑行后更新数据库中的行 - Editable Grid ExtJS, how to update row in database after editing row on grid 如何从单元格编辑网格中获取“列名称”和“先前值” - How to get “Column Name” and “Previous Value” from Cell Editing Grid ExtJS 4提供的建议,帮助:网格:单元格编辑:自动编辑功能 - Advice, help needed with ExtJS 4: grid: cell editing: auto edit feature 更改单元格时如何刷新自定义剑道网格过滤器 - How to refresh a custom kendo grid filter when a cell is changed 单元格编辑如何与 extjs 商店经理一起使用? - How cell editing works with extjs store manager? 如何在另一个网格中为特殊单元格创建单元格编辑器,并在ExtJs中从中选择值? - How to create cell editor for speciall cell in grid with another grid and selection of value from it in ExtJs?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM