I have extended Ext.data.Operation to implement a custom commitRecords method.
The Ext.data.Operation class is used for all communication between stores and their proxy.
The commitRecords method specifically is used to update the data in a data store according to data returned from a proxy writer.
I can’t seem to get a grip on how to set up my proxies to use my extended version of Ext.data.Operation.
I’ve been rifling through the Ext.data.* package but can’t seem to find where the Ext.data.Operation is created so I will know what class to tell to use this new extended Ext.data.Operation class with the custom commitRecords method.
Has anyone else extended this before, could give me some pointers?
I found it, the
batchmethod ofExt.data.Proxyis where anExt.data.Operationobject is created to send to the server.I extended
Ext.data.proxy.Ajaxwith a newbatchmethod where I just switch out thenew Ext.data.Operationfor my own Operation class.EDIT
Only because you asked DmitryB. The short story about why I had to implement my own commitRecords method is that I needed my data models “internalId” fields to match the actual database record ID field. I won’t go into why exactly, it’s too convoluted for me to express, but here’s what I did:
How I understand it, the
commitRecordsmethod is fired as one of the last actions when callingstore.sync()it automatically replaces the dirty records on the client side with the new server side records as long as you write your server side controller to return the new server record in the Ajax response, it does this whenever the sync request does an insert or update.The official implementation of
commitRecordstries to match this returned server record to the dirty client record by using the “internalId” field of the data model.Obviously, I have no idea what the next incremental database ID is going to be for new records, so I cannot assign it on the client side as the ID before the record syncs with the database, therefore the server record will never match be able to match up against the dirty client record’s internalId when commitRecords is called, i.e. the client record will not get the correct database ID, which I need.
So, because all of my writable data models for this app have a “create_time” field I decided to make the commitRecords method match the server records with the client records using the “create_time” field instead of “internalId”.
Here is the extended Ext.data.Operation class, where I did this:
As I mentioned in the answer, I found that I had to extend proxy to make use of my new Operation class. The only thing I extended was the
batchmethod, replacing only two lines in the method which saidnew Ext.data.Operationto now saynew MyApp.ux.QueryOperation(my new Operation class above). This then called my own commitRecords method when a response came back from the server. I also gave the extended proxy an alias “proxy.query” so that I could tell my stores to use it like this:(If it seems like I am going about this wrong way or missed something in the docs, please let me know. I would be happier with a built in method of achieving this functionality.)