PDA

View Full Version : RESTful proxy and Store Qestion



TampaBay55
3 Jan 2012, 1:14 PM
Greeting all:

I need some help for an issue I cannot figure out. I have the following store and model:


Ext.define('LSIPay.model.UsrData',{
extend: 'Ext.data.Model',
idProperty: 'recordid',
fields:[
{name: 'recordid', type: 'string'},
{name: 'sysdataid', type: 'string'},
{name: 'recorddate', type: 'date'},
{name: 'deleted', type: 'int'},
{name: 'lastname', type: 'string'},
{name: 'firstname', type: 'string'},
{name: 'middleinitial', type: 'string'},
{name: 'loginid', type:'string'},
{name: 'password', type:'string'},
{name: 'lastlogin', type:'date'},
{name: 'isadmin', type:'int'}
],
proxy: {
type: 'rest',
url: 'data/usrdata.php',
reader: {
type: 'json',
root: 'record',
successProperty: 'success'
},
writer:{
type: 'json'
}
}
});

Ext.define('LSIPay.store.UsrDataStore',{
extend: 'Ext.data.Store',
model: 'LSIPay.model.UsrData'
});


When I issue an update on a record in the store, my grid displays the update immediately. Update is made on the back-end as well.

When I issue a .destroy on one of the records in the store, the grid does not remove the record from the grid. I have to reload the page to see that the record was actually removed. Same issue with an add (create a record and .save() it before I send the record to a form to be edited) - the added record does not show in the grid until I do a page refresh. Why would an update show changes immediately but not an add or delete?

Code snippet to show what I am firing on my button clicks (in the controller):


...
addRecord: function(button){
var newRecord = Ext.create('LSIPay.model.UsrData');
var store = this.getUsrDataStoreStore();
newRecord.save({
success: function(newRecord){
store.sync();
var view = Ext.widget('usrdataform');
view.down('form').loadRecord(newRecord);
}
});
},
updateRecord: function(button){
var grid=button.up('usrdatabrowse');
var rowNdx = grid.getSelectionModel().getSelection()[0].index;
var record = this.getUsrDataStoreStore().getAt(rowNdx);
var view = Ext.widget('usrdataform');
view.down('form').loadRecord(record);
},
deleteRecord: function(button){
var grid=button.up('usrdatabrowse');
var rowNdx = grid.getSelectionModel().getSelection()[0].index;
var record = this.getUsrDataStoreStore().getAt(rowNdx);
var store = this.getUsrDataStoreStore();
record.destroy();
store.sync();
},
...


I would like the grid to be updated after a delete or add. Any help or insight would greatly be appreciated. Thanks!

TampaBay55
4 Jan 2012, 5:30 AM
Update:

If I set autoSync: true on the store and remove the store.sync entries in my code the following code generates two (2) PUT url's on a record update:



saveRecord: function(button){
var win = button.up('window');
var form = win.down('form');
var store = this.getUsrDataStoreStore();
record = form.getRecord();
values = form.getValues();
record.set(values);
record.save({
success: function(){
win.close();
}
});
}


Can someone point me in the right direction. Thanks to all.