javascript - How to force ExtJS to consider value in grid cell changed after custom editing completes? -
i have extjs editorgridpanel several columns. 1 of columns bound complex data type (an array of objects), , uses custom editor modify values in pop-up window. part tested , works fine - jsonstore keeping complex values, setting custom editor's value when it's focused , editing begins, , picking final value when editing complete.
the problem is, complex data type, javascript string value not appear include sub-attributes, instead represented "[object object]". therefore, if array contains 2 items when editing begins, , 2 items after editing complete, if of sub-attributes of 2 items have changed, grid editor doesn't know this, because (string)value === (string)startvalue
(that is, '[object object],[object object]' === '[object object],[object object]'
).
i'm problem, because if custom sub-editor increases number of items in list, string values are different ('[object object],[object object],[object object]' !== '[object object],[object object]'
), , value changes (with change event propagating store).
the complete oneditcomplete function of editorgridpanel shown below (full source here):
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 number of possible solutions, don't know how make of them work.
- provide custom grideditor particular column of editorgrid, considers startvalue dummy value,
string(value) !== string(startvalue))
clause above true. seems difficult because don't have access grideditor within custom field (since in field hierarchy , doesn't know grideditor controlling it). - somehow handle on grideditor being used control custom field, kind of event. if can that, can set startvalue (a public property) dummy value known different final value. normal "changed value" code work expected. haven't found reasonable way handle editor within field, however.
- convince javascript spit out of sub-attributes of objects string representation, if object is
var myobj = { 'objid': 1, 'objvalue': value };
var myvalue = [myobj];
then instead of (string)myvalue being '[object object]'
, instead '[{objid:1,objvalue:value}]'
.
nevermind, appears wasn't correctly adding tostring() function objects. doing fixes 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, string value of myvalue
above [myobj {objid:1,objvalue:value}]
instead of [object object]
and problem solved - grideditor correctly updates record when 1 of underlying objects' attributes have changed.
Comments
Post a Comment