PDA

View Full Version : EditorGridPanel: message from the server



stivlo
12 Sep 2010, 4:26 AM
Hello Everyone,

I've a EditorGridPanel, configured with a JsonStore. It updates the data automatically for every cell update, which is fine for me, because only one cell per row is editable, while the other cells are for information only. All the basic works fine: I can send the data to the server and update it.

However, I've added some validation on the server, that has a complex logic and can't be done on the client and I would like to display a message when it's not empty.

Here is an example Json reply of my CRUD URL:



{"success":false,"msg":"Test Message"}
Here is my JsonStore definition:



configStore = new Ext.data.JsonStore({
url: 'index.php?page=mrn_jconfig_crud',
root: 'param',
idProperty: 'name', //used to specify the id
successProperty: 'success', //used to know whether a CRUD operation succeded
fields: ['name', 'setting', 'description'],
writer: new Ext.data.JsonWriter()
});
I could post my EditorGridPanel code but I don't think is necessary to understand the problem.

I tried to play with the afteredit event on the EditorGridPanel, but it's fired just after the edit and not when the Json reply arrives. Also the update event on JsonStore is fired immediately and JsonWriter doesn't have public events.

To show the message coming from the server when a cell is updated I've two problems:

1) Find a suitable event fired after the response from the server.
2) Access to the Json response, so I can extract the msg field.

I've been banging my head for some time and tried searching online but I could not solve the problem. Anyone can give me a hint?

Thank you in advance!
Stivlo

UPDATE: Actually I found out by putting a sleep(10) in my PHP script that the update event on JsonStore fires two times: after the update and after the response has arrived. So probably the problem number 1 is solved and I've to find out how to access the message field from there.

Animal
12 Sep 2010, 5:22 AM
Add a listener to the Store's exception event.

stivlo
12 Sep 2010, 6:33 AM
Great hint Animal! Thank you so much. So I've added an exception handler to the JsonStore in this way:



//DataProxy this, String type, String action, Object options, Object response, Mixed arg
function exception(dataProxy, type, action, options, response) {
var msg;
if (type === 'response') {
msg = 'It wasn\'t possible to save the data';
} else if (type === 'remote') {
msg = response.raw.msg;
}
Ext.MessageBox.alert('', msg);
}
configStore.on('exception', exception, this);
and everything works as expected. http://62.0.5.133/www.sencha.com/forum/images/icons/icon7.png