PDA

View Full Version : Update table with PHP/JSON



hallikpapa
22 Jul 2007, 7:30 PM
I was using a tutorial found on this site about adding, updating, and deleting records.
http://extjs.com/learn/Tutorial:Using_Ext_grid_form_dialog_to_achieve_paging_list%2C_create%2C_edit%2C_delete_function

It using ScriptTagProxy, but I needed to use HttpProxy. I got it loading the data properly, but trying out the update user function, the window pops up, but all fields are populated with undefined. I thought because the getAt function is definted in the ext.data.store, it would still work fine with HttpProxy, but so far it's not. Here is the code when I double click on a user:



grid.on('rowdblclick', function(grid, rowIndex, e) {
var selectedId = ds.data.items[rowIndex].id;

// get information from DB and set form now...
var account_data = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:'scripts/acctmgmt.php?action=loadData&id=' + selectedId}),
reader: new Ext.data.JsonReader({
root: 'meUsers',
id: 'id'
},
[
{name: 'ID', mapping: 'id', type: 'string'},
{name: 'Password', mapping: 'password', type: 'string'},
{name: 'UserName', mapping: 'username', type: 'string'},
{name: 'FirstName', mapping: 'firstname', type: 'string'},
{name: 'lastname', mapping: 'lastname', type: 'string'}
])
});

account_data.on('load', function() {

// set value now
var updateId = account_data.getAt(0).data['id'];
username_show.setValue(account_data.getAt(0).data['username']);
firstname_show.setValue(account_data.getAt(0).data['firstname']);
lastname_show.setValue(account_data.getAt(0).data['lastname']);
password_show.setValue(account_data.getAt(0).data['password']);
cPassword_show.setValue(account_data.getAt(0).data['password']);

var updateInstanceDlg;


Here is what the PHP script returns when I double click on a row:


{"meUsers":[{"id":"1","username":"USERNAME","password":"PASSWORD","firstname":"FIRSTNAME","lastname":"LASTNAME"}]}


Help?

<edit> Just noticed that only the Last Name field works. All others are undefined. Looks like I shouldn't have pointed at the mapping field, and the Name field.

fyasar
4 Oct 2007, 3:47 AM
reader: new Ext.data.JsonReader({
root: 'meUsers',
id: 'id'
},[
{name: 'id'},
{name: 'password'},
{name: 'username'},
{name: 'firstname'},
{name: 'lastname'}
]),
remoteSort: false
});




this way works fine :)