ExtJS JSON records with null values
If I have a JSON returned with null values for a property, how do I force a grid to recognise a value has changed from null and mark it as isDirty?
{
"prop1": null,
"prop2": "",
"prop3": "my val"
}
The first time a user edits the prop1 cell in a Ext.grid.EditorGridPanel it is not marked as dirty, however as soon as it is edited a second time it is. Empty strings work correctly on the first edit.
On further debugging it seems that using record.set() where a JSON property has a null value returns before setting the data for the record
set : function(name, value){
var encode = Ext.isPrimitive(value) ? String : Ext.encode;
if(encode(this.data[name]) == encode(value)) {
return; //if null it always returns here
}
Update:
The workaround is to set the raw value for the data property of a record:
data开发者_Go百科 = segments[i]; //my JSON
recMetadata = Ext.data.Record.create(store.fields.items);
r = new recMetadata({}, data.MyID); //blank record with ID
for (j in data) {
//r.set(j, data[j]); //does not set the data property if null
r.data[j] = data[j]; //set raw value and all is fine with isDirty etc.
}
store.insert(0, r);
You can manually set the record as dirty on every afteredit to be sure...
In your EditorGridPanel config:
listeners: {
'afteredit': function(e) {
if(e.value != e.originalValue) {
e.record.markDirty();
}
}
}
This is a known problem with the ExtJS isDirty method, I think they're planning to address it in the next major release.
What are you using to load the JSON? Would it be possible to change the output so it return an empty string instead?
精彩评论