2
votes

ExtJS version is ext-4.0.7-gpl.

When syncing a Store, the server returns me the same object in JSON format, but populated with generated Ids, that I need to put into my store data. The identifiers are in enclosed entities, like this:

{
    "id": 46,
    "name": "Excel",
    "typeExt": [{
        "ext": "xls",
        "id": "137",
        "isMain": "false",
    }, {
        "ext": "xslx",
        "id": "136",
        "isMain": "false",
    }]
}

So the ids 137 and 136 are generated on server-side.

I am trying to make it in a store's proxy (edit: Ajax type) (which itself could be wrong):

proxy.afterRequest = function(request) {
     if (request.action === 'create' && request.records.length == 1) {
         me.store.autoSync = false;
         var created = Ext.JSON.decode(request.operation.response.responseText);
         request.records[0].set('id', created.id);
         request.records[0].set('typeExt', created.typeExt);
         //request.records[0].modified = {};
         //request.records[0].dirty = false;
         me.store.autoSync = true;
     }
     if (request.action === 'update' && request.records.length == 1) {
         var updated = Ext.JSON.decode(request.operation.response.responseText);
         me.store.autoSync = false;
         request.records[0].set('typeExt', updated.typeExt);
         me.store.autoSync = true;
     }

 };

See the commented variants.

If I don't set autoSync to false, it gets looped infinitely.

If I don't clear those read-only fields modified and dirty, the modified records are included in the next syncronization request, if I edited another record, it sends an Array of records which breaks my server-side service.

If I clear dirty and modified like it is shown in the commented lines, the update operation works only once. I press Update button in RowEditing plugin dialog, but it never sends the needed request to the server for the second time.

In the latter case I guess I broke something by hand-editing the readonly fields, but I can not find what.

How do people usually handle issues liek this?

PS.

request.records[0].commit(true); || request.records[0].editing = false; 

|| request.records[0].beginEdit(); 

Were tried with no seccess too.

2

2 Answers

2
votes

I have this working for grids stores with Ext 4.0.7, but having similar issues with tree stores. All this with a direct proxy (and autosync true)

If you look at the code of Ext.data.Store::onCreateRecords, you'll see that the store records are replaced by those returned from the server, given the order is the same.

So, it is pretty straight-forward: just return from the server the same json/object sent to the create method, but with the id set and it should update them automatically on the store.

I know this is of not much help, but perhaps will give you some direction.

I think it would help if you mention:

  • the type of proxy you're using
  • the exact ext version
  • perhaps the code initiating the creation of the record
3
votes

While this won't do you much good on Ext 4.0.7, the suspendAutoSync and resumeAutoSync methods were added in Ext 4.1.0. Hopefully this will be useful to someone else.