View Full Version : CRUD Store write event not firing

28 Sep 2009, 1:42 AM

I've been scratching my head at this one for a while now, and I would really like some help.

This is my store:

var HeaderRow = new Ext.data.Record.create([
{name: 'ID', type: 'int'},
{name: 'SITE_ID', type: 'int'},
{name: 'RELEASE_ID', type: 'string'},
{name: 'DDATE', type: 'string', dateFormat: 'Y-m-d'},
{name: 'DTIME', type: 'string'}]);
var headerDataStore = new Ext.data.Store({
id: 'header',
proxy: new Ext.data.HttpProxy({
api: {
read: {url: 'deploymentLog', method: 'GET'},
create: 'deploymentLog',
update: 'deploymentLog',
destroy: 'deploymentLog'
reader: new Ext.data.JsonReader({
idProperty: 'ID',
successProperty: 'success',
root: 'DataItem'
}, HeaderRow ),
writer: new Ext.data.JsonWriter({
encode: true,
writeAllFields: false
autoSave: true,
baseParams: { "Fetch": "Head" },
listeners: {
beforeLoad: function(store, options) {
Ext.apply(options.params, {"applicationID": selAppId}, this.baseParams)
load: function(store, records, options) {
if (records.length > 0) {
selLogId = records[0].get('ID');
write: function(store, action, result, response, rs) {
console.log('WRITE', arguments);
loadexception: { fn: loadException }
This is the code generating one row in the store, which in turn will post the row to the server:

var row = new HeaderRow({
'ID': null,
'SITE_ID': selSiteId,
'RELEASE_ID': selRelease,
'DDATE': Ext.getCmp('DepDate').getValue(),
'DTIME': Ext.getCmp('DepStart').getValue()
The server is completing the registration, and returning a 200 Ok message, including the following JSON:

.. but the store's write event is never fired. Why?

28 Sep 2009, 1:44 AM
Your server not only needs to return {success:true}, but also the data of the newly added record (including the assigned id).

28 Sep 2009, 2:18 AM
Thank you ever so much. This solved it, and saved me the trouble of another http request fetching the new row ID. Brilliant. :D

7 Apr 2010, 9:09 AM
would u pls post the exact json response? i think i've tried everything and nothing seems to work.
i've put the write listener in both store and proxy classes and nothing.

16 Aug 2010, 11:40 AM
I have tried the same thing and my server is responding with 200 and I include the new record with the new ID but the store's write event still never fires.

Andrew Peacock
17 Aug 2010, 6:04 AM
Raulooo, Mark,

Hopefully my post on this will help:


17 Aug 2010, 11:58 AM

Thanks. I had seen your solution earlier, but it did not resolve my issue.

The issue appears to be that HttpProxy{api{create,update,destroy}} methods for JsonStore don't function.

Only the read operation does.

So a JsonStore will work to read rows into a grid, but a JsonStore won't work to create, update or destroy rows in a grid if you require a url or api.

You are required to manually build AJAX callbacks to create, update or destroy records and then manually refresh your grid. Strangely, the very same operations the JsonStore always errors out on work perfectly when you do it manually.

I can find no working examples anywhere of a JsonStore HttpProxy{api{create,update,destroy}} actually working. Instead, for the examples where it is declared, the developer always manually created AJAX callbacks for all non read operations.

Someone please prove me wrong and give me a working JsonStore HttpProxy{api{create,update,destroy}} example.

Andrew Peacock
17 Aug 2010, 2:35 PM
Hi Mark,
Have you had a look at http://dev.sencha.com/deploy/dev/examples/writer/writer.html ?

I know this is using a Store with JSON reader, but that should be the same as a jsonstore?

Could you post some sample code?


18 Aug 2010, 6:34 AM
Hi Andrew,

Yes, I have looked at the writer.html example but it also doesn't work.

Ext.onReady(function() {
var crmgrid = new Ext.grid.GridPanel({
renderTo: 'divgrid',
id: 'gridCRMPriorities',
viewConfig: {
forceFit: true
border: false,
loadMask: true,
sortable: false,
store: crmstore = new Ext.data.JsonStore({
proxy: crmproxy = new Ext.data.HttpProxy({
api: {
read: 'JsonStore.aspx?store=query_crm_priorities',
create: 'JsonStore.aspx?store=query_crm_priorities&action=C',
update: 'JsonStore.aspx?store=query_crm_priorities&action=U',
destroy: 'JsonStore.aspx?store=query_crm_priorities&action=D'
method: 'POST',
headers: { 'Content-type': 'application/json' }
reader: crmreader = new Ext.data.JsonReader({
totalProperty: 'totalRows',
successProperty: 'success',
idProperty: 'id',
root: 'crm_properties',
messageProperty: 'message'
{name: 'id', mapping: 'id'},
{name: 'Priority', mapping: 'id'},
{name: 'Ticket', mapping: 'id'},
{name: 'IncidentDes', mapping: 'id'}
writer: crmwriter = new Ext.data.JsonWriter({
encode: false,
writeAllFields: false
autoLoad: true,
autoSave: false,
remoteSort: true,
listeners: {
exception: function(proxy,type,action,options,res) {
title: 'Exception',
msg: res.statusText,
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
remove: function() { alert('remove'); }
plugins: [
crmeditor = new Ext.ux.grid.RowEditor({
saveText: 'Save',
errorText: 'You must enter a Ticket and Description',
listeners: {
afteredit: function() {
canceledit: function() { crmstore.removeAt(0); }
columns: [
{ id: 'crm_priorities', header: 'ID', hidden: true, dataIndex: 'id' },
{ header: "#", width: 30, align: 'right', fixed: true, sortable: false, menuDisabled: true, dataIndex: 'Priority' },
{ header: "Ticket",
width: 75,
fixed: true,
sortable: false,
menuDisabled: true,
dataIndex: 'Ticket',
editor: {
xtype: 'textfield',
allowBlank: false
header: "Incident",
width: 200,
resizable: false,
sortable: false,
menuDisabled: true,
dataIndex: 'IncidentDes',
editor: {
xtype: 'textfield',
allowBlank: false
tbar: [{
iconCls: 'add16',
text: 'Add Ticket',
handler: function() {
var r = new crmstore.recordType({Priority: crmstore.getCount() + 1, Ticket: '', IncidentDes: ''});
crmstore.insert(0, r);
iconCls: 'delete16',
text: 'Delete Ticket',
handler: function() {

I have compared my POST and RESPONSE to exactly what is happening in writer.html and with the exception of the field count and names, the results in Firebug are identical.

But since I am persisting data while the writer.html example is not, I can only think that must have something to do with it.

The events fire up to the exception which tells me "communication error" but the proxy, type, action, options, and res params in the exception give no indication about that the problem is.