2
votes

I have a grid with row-editing enabled. When I add a row and call store.sync(), the server generates certain fields on that record, and returns the full record info in the response. However, ExtJS does not seem to update its copy of the record, except for the id. Is there a way to make it do that, or do I need to write custom code?

This is an excerpt of the grid's controller:

doneEdit: function (editor, e, eOpts) {

    var me = this;

    //
    // Set up loading mask on grid during update (if record changed and is valid)
    //
    if (e.record.dirty && e.record.isValid()) {
        e.grid.showUpdatingMask();

        e.store.sync({
            success: me.onSaveSuccess,
            failure: me.onSaveFailure,
            scope: me
        });
    }
    else {
        me.cancelEdit(editor, e, eOpts);
    }
},

//
// onSaveSuccess() is only used for row editor grids
//
onSaveSuccess: function (batch, options) {

    var me = this,
        grid = me.getGrid();

    grid.getStore().filter([]); // re-run whatever filters already exist, and sort.

    grid.hideMask();

    // update read-only active store if specified by sub-class
    if(me.activeStore) {
        // $TODO: handle load failure
        me.activeStore.load();
    }
},
1
Short answer is that it should be doing that automatically. When I call store.sync() it updates the whole record with the returned data, I'll see if I can spot what the difference is. - egerardus
Can you share what your solution was? Possible duplicate here stackoverflow.com/questions/10637959/… - HDave
@HDave: I don't really remember at this point what fixed the problem. One hunch is that it may have been a problem with what the server was returning and/or the model could not properly create a record from the response. Note that Ext JS silently ignores response data that it can not convert into a model. You won't see any exception or other error. - jacob

1 Answers

1
votes

I had the same problem (Ext 4.2.1). The reason was that I forgot to set the idProperty on the reader default is "id", mine is "_id". Ext silently failed to update the record because it didn't recognize a matching id. Now it works like a charm.

So make sure the response is in the correct format expected by your reader (root, idProperty, model definition, ...)