PDA

View Full Version : Editing records in a store that uses a convert function



rglaze
14 Feb 2011, 2:34 PM
I am having problems when trying to edit a record in a store that uses convert functions for the fields.

For Example:


var myStore = new Ext.data.JsonStore({
url: Foobar,
idProperty: 'id',
fields: [
{ name: 'id' },
{ name: 'startDate', mapping: 'startDate', convert: function (v) { var dt = new Date(Date.parseDate(v, 'M$')); return dt.format('m/d/Y'); } },
{ name: 'endDate', mapping: 'endDate', convert: function (v) { var dt = new Date(Date.parseDate(v, 'M$')); return dt.format('m/d/Y'); } }
]
});


I load the store and life is good. But then I want to edit 1 record in the store. I do this:


var record = myStore.getById(someId);

if (record) {
record.beginEdit();
record.set('startDate', '\/Date(1293858000000)\/');
record.endEdit();
record.commit();
}


The edit works, but it didn't use my covert function to set the value. Is there any way to edit the record and make it use the convert (or mapping if I had any defined)?

Thanks,
Ricky