PDA

View Full Version : Insert element to a store with mysql last_insert_id



dobberph
26 Jun 2013, 1:05 AM
Hi all,

I have a problem. If I insert a new record to my store, the PHP-script saves it correctly and returns:


{
"success":true,
"msg":"insert",
"row":{
"id":"14",
"creation_date":"2013-06-29",
"title":"Test 656",
"msg":"gre z35 thr nh",
"author":"Tobias Dobberphul",
"author_shown":"Tobias Dobberphul"
}
}


The dirty-flag disappears, the mysql-db is fine. If I refresh the store the new mysql_insert_id is shown correctly.
BUT:
How can I achieve, that the new generated mysql_insert_id that is already returned is shown in the grid directly after the successful ajax call. Of course I can refresh the grid in the callback but this is not really for good performance.

Whats the trick? :-/

Thanks for your help,
Tobias

existdissolve
26 Jun 2013, 3:50 AM
How is you Reader (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.reader.Json-cfg-root)configured? For example, for my stores, I set a root of "data" which contains the records returned for populating the grid. On insert/update, I return the inserted/changed data in the same root "data: {fields...}", and it automatically updates the record, as designed.

dobberph
26 Jun 2013, 4:54 AM
Hi,
this was already the hint I needed ;D

Here is my configuration:


reader: {
type: 'json',
idProperty: 'id',
root: 'rows',
useSimpleAccessors: true
}


Obviously the root of "rows" doesn't match the return key "row" in my PHP-Script.
I changed my PHP-Script, so that it returns now the key "row".

Now everything works fine.

Thanks a lot,
Tobias

existdissolve
26 Jun 2013, 6:02 AM
Hi,
this was already the hint I needed ;D

Here is my configuration:


reader: {
type: 'json',
idProperty: 'id',
root: 'rows',
useSimpleAccessors: true
}


Obviously the root of "rows" doesn't match the return key "row" in my PHP-Script.
I changed my PHP-Script, so that it returns now the key "row".

Now everything works fine.

Thanks a lot,
Tobias

Glad it worked! Can you mark as answered so this get updated on the board?