Vikas Hire
Vikas Hire

Reputation: 628

How to update single record in Ext JS Store?

My problem is that If I edit information of any record/row on 2nd or 3rd or any page after editing it brings me back to 1st page,instead of that bring that to same page after update record/row.(I think it because of grid's store get update and grid focuses on first page).

I want to update store record and gridview row locally. that's why after the updating record I can hold the same grid page.

is there any good options for this?

Upvotes: 3

Views: 6133

Answers (2)

nik
nik

Reputation: 21

Just if someone needs it:

onSaved: function (scope , response, options) {
    var grid = scope.getGrid();
    if (grid == null){return;}
    var store = grid.getStore();
    if (store == null) {return;}
    // find if store has the record. quit if not
    var record = store.findRecord('id', response.responseJSON.id);
    if (record) {
        //update only THE record , not all store
        record.set(response.responseJSON);
    } else {
        return;
    }
}

record.set - Sets the given field to the given value, marks the instance as dirty and triggers a view refresh. And in the back we refresh only the updated record, and not all the store like, store.load() or store.reload().

Upvotes: 1

inQstvJS
inQstvJS

Reputation: 303

You need to call store.reload() instead of store.load() after updating the record.

var me = this;
record.save({
  scope: this,
  success: function(record) {
    me.reloadGrid(record);
  },
  failure: function(record, operation) {}
});

reloadGrid: function(record){
  var gridStore; /*Get the reference to the grid store here*/
  gridStore.reload();
}

Reload will maintain all the existing store parameters such as page number, start, limit, etc. If you want to load a specific page, then do the following

reloadGrid: function(record){
  var gridStore; /*Get the reference to the grid store here*/
  gridStore.loadPage(3);
}

Of course, this would work if you are not actually editing the record in a way that affects the sort order on the store. In which case, your store would be sorted based on sort property and the record can occur anywhere on any page.

Upvotes: 1

Related Questions