PDA

View Full Version : Updating Records of a Data Store



aconran
21 Feb 2007, 3:28 PM
Searching for some explaination here... First and foremost don't take what I've said here as set in stone advice.... It's how I think things work...

I have a grid that provides some CRUD operations and need to implement the synchronization between the datastore and the actual database. Digging through the code this is what I have found.

First off I can retrieve the currently selected/being edited Record by


var editRecord = sm.getSelected();


Record provides a number of functions to manipulate the in-memory record and also maintains state, meaning that it knows what has been modified while you are editing a record.

After getting the record above we can now beginEdit'ng. This lets the class know that we are now editing a record and to please record any changes/modifications that are made.


editRecord.beginEdit();


We can now use the .set(name, value) method to update each individual field in our record.


editRecord.set('fieldA', 'myValue');
editRecord.set('fieldB', 'my other value');


Please note that set is intelligent enough to know if we passed the same value as the old value. If all fields were set to exactly the same thing as what they were before the record will not be marked as dirty/modified.

After editing our record we can now call the function endEdit


editRecord.endEdit();


If the record is dirty (has been modified) it will call the function afterEdit in the associated store.
store.afterEdit looks for the record in the stores modified property, if it's not there it puts it there. It then fires the update event with a scope of this and an argument of the current record.

Therefore we can now setup an event listener to handle the update event of the datastore.


store.on('update', function(currRecord) {
//make ajax update to my server side

//onSuccess call currRecord.commit();


//onFailure call currRecord.reject();


}



The clarifications I need if all of the above is true:
- How can the data store possibly determine that this record has been finished/committed? data.store.modified is never cleared
- The reject function sets the dirty flag to false.... however there is no way to 'rollback' aside from retrieving the data again from the server side because set directly modifies this.data in addition to modifying this.modified. This is OK behaviour but I just want to be sure this is how it works.

jack.slocum
21 Feb 2007, 3:52 PM
Everything you said is correct.

My recommendation is not to use that stuff yet. It is part of the auto-saving functionality that isn't complete. I actually did some updates on it a little while ago but it hasn't been deployed (needs some testing). I will let you know when I deploy it.

- How can the data store possibly determine that this record has been finished/committed? data.store.modified is never cleared

You can clear it at any time. store.modified = []; When all the saving stuff is complete, I'm sure the "save()" function will do it for you automatically.

- The reject function sets the dirty flag to false.... however there is no way to 'rollback' aside from retrieving the data again from the server side because set directly modifies this.data in addition to modifying this.modified. This is OK behaviour but I just want to be sure this is how it works.

reject was completely wrong. commit was actually reject. :) There was a change in the way the data on a record was changed/accessed and neither of those functions was updated.

The way a record can be rolled back is because it store the old values in modified. modified contains the original value of the field, and data contains the temp value. So to reject, you would copy the old values back into the live data. Make sense?

On a side note, it's nice to see people digging into the source!

jack.slocum
21 Feb 2007, 4:14 PM
I deployed the fixed functions in Rev 8. Feel free to try them out and let me know what kind of results you get. :)

aconran
21 Feb 2007, 4:38 PM
Thanks Jack; I was expecting the fixed functions to take a lot longer than 22 minutes!!

Do you still hold your recommendation not to use this stuff, until the auto marshalling stuff is done? Do you have any sense of time for when that will be? Alpha? Beta? Stable? I am trying to put together a demo to show that it would not be that difficult for my team to purchase/implement ext in our applications.

On a side note, the variable name modified seems very backwards to me!

francoisb
13 Jun 2009, 7:04 PM
So, is the auto marshalling code in or not? I know this thread is from 2007, so if it had been implemented, I should find something in the docs? We're currently on 2.x, but we're not set in stone on that.

I'm implementing an Ajax update similarl to aconran above, but I want the fields to be marked invalid when appropriate. If the store is responsible for doing the update, there's no way to notify the UI about the invalid code.

The only way I'm thinking of right now is to do it in each field individually, where I still have access to the field.

Thanks!

AlexInspired
13 Feb 2015, 4:34 AM
Im using code like this:

var index = Ext.StoreMgr.lookup("LocalStore").findExact('UUID',AM.util.Utilities.CurrentPlace); var rec = Ext.StoreMgr.lookup("LocalStore").getAt(index); var uuid = rec.get('UUID'); rec.set('X', window.event.offsetX);I successfully read row from local store by id - but I can not set new value to a field of thist record.
I get exception like :
Uncaught TypeError: Cannot read property 'type' of undefined
WebStorage.js:391Ext.define.getIds
WebStorage.js:391Ext.define.update
WebStorage.js:190Ext.define.runOperation
Batch.js?_dc=1423826286534:251
Ext.define.start Batch.js?_dc=1423826286534:178
Ext.define.batch Proxy.js?_dc=1423826284661:456
Ext.define.sync AbstractStore.js?_dc=1423826284602:810
Ext.define.afterEdit AbstractStore.js?_dc=1423826284602:906
Ext.define.callStore Model.js?_dc=1423826286536:1814
Ext.define.afterEdit Model.js?_dc=1423826286536:1773
Ext.define.endEdit Model.js?_dc=1423826286536:1326
(anonymous function) Main.js?_dc=1423826286143:28(anonymous function)
VM1259:6wrap
I suppose I get dirty data out of the scope of the store or maybe model or smth like that.
What is the right approach for local store updating?