PDA

View Full Version : JSON Writer Submitting the entire data store on sync()



mcryan
15 Sep 2011, 11:08 AM
I have a grid that opens a window on selection of a row. In the window is a form, bound to the selected record. I have a save button that updates the forms record:



var active = this.up('form').getRecord();
var form = this.up('form').getForm();

if (!active) {
return;
}
if (form.isValid()) {
form.updateRecord(active);
}

For some reason, when this happens all rows in the data store are being sent to the server, rather than the record or row that I am working with. Any ideas on this?

mankz
15 Sep 2011, 12:21 PM
Post your store, reader, proxy code.

mcryan
15 Sep 2011, 1:33 PM
var store = Ext.create('Ext.data.Store', {
model: 'model',
autoLoad: true,
autoSync: true,
proxy: {
type: 'ajax',
actionMethods: 'POST',
extraParams: {
'action': 'get_list',
},
url: 'data.php',
api: {
read: 'data.php',
update: 'data.php?action=update_ticket'
},
reader: {
type: 'json',
root: 'data'
},
writer: {
type: 'json',
writeAllFields: true
}
}
});


And then I have a button on the form that triggers the update:


buttons: [{
text: 'Save',
handler: function() {
if (this.up('form').getForm().isValid()) {
Ext.apply(store.proxy.extraParams, {
'action': 'update_ticket'
});
var active = this.up('form').getRecord(),
form = this.up('form').getForm();

if (!active) {
return;
}
if (form.isValid()) {
form.updateRecord(active);
}
}
}
}]

mankz
15 Sep 2011, 1:35 PM
model definition?

mcryan
15 Sep 2011, 1:38 PM
Model:


Ext.define('model', {
extend: 'Ext.data.Model',
fields: [
{name: 'ID', type: 'int'},
{name: 'Status'},
{name: 'WhenOpened', type: 'date', dateFormat: 'Y-m-d H:i'},
{name: 'AssignedTo'},
{name: 'AssignedName'},
{name: 'WhenAssigned', type: 'date', dateFormat: 'Y-m-d H:i'},
{name: 'Subject'},
{name: 'ClosedBy'},
{name: 'WhenClosed', type: 'date', dateFormat: 'Y-m-d H:i'},
{name: 'StartTime', type: 'date', dateFormat: 'H:i'},
{name: 'EndTime', type: 'date', dateFormat: 'H:i'},
{name: 'Costs', type: 'int'}
]
});

mankz
15 Sep 2011, 1:51 PM
Try setting



idProperty : 'ID'


on your model.

mcryan
15 Sep 2011, 2:01 PM
Magic! Mankz, thanks for the help. I wasted far too much time on this!