-
29 Sep 2010 11:35 AM #1
dataStore response after sending to server (store.save)
dataStore response after sending to server (store.save)
Hello!
I have a code that sends data from one grid to the server.
Everything works fine, but do not know how to get the server response.
Can you help me?
Thanks!
PHP Code:var writer = new Ext.data.JsonWriter({
encode: true
});
var Cr = Ext.data.Record.create([
{ name: 'DE_CD_UNIDADE' },
{ name: 'VL_PRECO' },
{ name: 'VL_DECORACAO' }
]);
var reader = new Ext.data.JsonReader(
{
root: 'data',
messageProperty: 'message'
}, Cr
);
var proxy = new Ext.data.HttpProxy({
api: {
create: '_CODE/ASPX/_tabvendas/_tab_venda_importacao.aspx'
}
});
var dsTabVendaImportacao = new Ext.data.Store({
proxy: proxy,
reader: reader,
writer: writer,
autoLoad: false,
autoSave: false,
baseParams: { cdEmpreendimento: cdEmpreendimento, cdBloco: cdBloco, cdTabela: cdTabela },
listeners: { 'add': function () {
if (this.getCount() > 0) {
Ext.getCmp('btnSalvar').enable();
} else {
Ext.getCmp('btnSalvar').disable();
}
}
}
});
Win = new Ext.Window({
title: Tit
, width: 450
, height: 220
, layout: 'fit'
, modal: true
, items: [
new Ext.grid.GridPanel({
border: false
, store: dsTabVendaImportacao
, triggerAction: 'all'
, stripeRows: true
, plugins: [Ext.ux.grid.DataDrop]
, columns: [{
dataIndex: 'DE_CD_UNIDADE'
, header: 'Unidade'
, sortable: true
, width: 100
}, {
xtype: 'numbercolumn'
, dataIndex: 'VL_PRECO'
, header: 'Preço'
, sortable: true
, width: 100
, format: 'R$ 0,0.00'
}, {
xtype: 'numbercolumn'
, dataIndex: 'VL_DECORACAO'
, header: 'Valor de Decoração'
, sortable: true
, width: 100
, format: 'R$ 0,0.00'
}]
})],
fbar: {
xtype: 'toolbar',
items: [{
xtype: 'button'
, text: 'Salvar'
, id: 'btnSalvar'
, iconCls: 'icl-save'
, disabled: true
, handler: function () {
dsTabVendaImportacao.save();
}
}, {
xtype: 'button'
, text: 'Cancelar'
, iconCls: 'icl-canc'
, handler: function () {
Win.close();
}
}]
}
}).show();
-
29 Sep 2010 11:58 AM #2
Hi,
Listen to the 'write' event of the store.
-
29 Sep 2010 6:45 PM #3
I tried using the event "write", but not passed by the event.
I used:
Did not work.PHP Code:listeners: ('write': function ()
{
alert ('hello')
}
}
-
30 Sep 2010 5:08 AM #4
When listening to the Ext.data.Store's write event, the data param will contain the content of the 'data' property of the object created from the server response. If you want to retrive the whole data returned by the server, I think you have to listen to the write event of the Ext.data.DataProxy encapsulated in the store.
E.g.
Code:store.proxy.on('write', function(store, action, data, response) { console.log(response); });
-
30 Sep 2010 8:23 AM #5
scarsick,
I tested your solution, but without success.
It may be some problem in json format of my reply?
The server returns: '{success: true}'.
Thanks!
-
1 Oct 2010 5:13 AM #6
The event 'exception' is called, but 'write' no.
Firebug by the server is returning 200.
The code on the server side is perfect.
Any solution?
I am using Asp.net.
-
1 Oct 2010 8:11 AM #7
Well, if the exception event is called, write event won't be called, obviously hehe. If the server returns 200 and exception event is fired, it means that the store reader did not succeed in parsing the value returned by the server.
Log the 'arg' argument passed to the exception event handler function, it should be a javascript Error object. You will then be able to see why the parse failed. But before doing this, I suggest that you add message: "" to your json response, I think it is mandatory to have it.
exception : ( DataProxy this, String type, String action, Object options, Object response, Mixed arg )
E.g. server response:
Code:{ "success": true, "message": "" }
-
1 Oct 2010 8:35 AM #8
Sorry, my English is not good. hehe.Well, if the exception event is called, write event won't be called, obviously hehe
There is no error by the server or the formed JSON returned, sure.
I managed to get the response from the server within the "exception". From what I understand, for the event to "write" sech called I have to return the data that was sent from my datastore. In this example: http://dev.sencha.com/deploy/dev/exa...l/restful.html
Thanks for your help!
Similar Threads
-
Store save with server-side validation errors
By NicoCipo in forum Ext 3.x: Help & DiscussionReplies: 6Last Post: 15 Mar 2011, 10:55 AM -
Editor Grid: how to handle server response when click on "Save" button
By Deeeem in forum Ext 3.x: Help & DiscussionReplies: 2Last Post: 13 Jul 2010, 7:28 AM -
Getting server response on datastore loadexception
By mad_ady in forum Ext 3.x: Help & DiscussionReplies: 3Last Post: 14 Mar 2010, 10:53 PM -
Sending Multiple Response with 1 call to server
By ektanit in forum Ext 3.x: Help & DiscussionReplies: 0Last Post: 14 May 2009, 9:55 AM -
Is it possible to change response from server before storing into Datastore?
By Cyberangel67 in forum Ext 1.x: Help & DiscussionReplies: 2Last Post: 9 Aug 2007, 7:56 AM


Reply With Quote