For example, when I try this, I don't see any immediate changes to the grid after the original editing is complete:
grid.on({
'afteredit': function(e) {
e.record.data.Description = 'foo';
e.record.data.OnHand = 100;
}
});
See second answer below - the code above is generally an antipattern, should use e.record.set() instead of accessing e.record.data directly.
If you're modifying multiple fields, you'll still want to wrap them in beginEdit/endEdit calls so only a single event gets fired.
Sean's answer is perfect for updating multiple fields, something that I didn't take into account with my initial answer. For updating a single field, you can use the record's set() method
In retrospect, I should have done it this way. I never should have accessed the "data" element directly. My usecase for begin/endEdit was not legit.
You need to use set()
so that the proper event gets fired from the store. If you're changing multiple fields in the record, you should wrap the changes to the data in beginEdit()
and endEdit()
calls so that only one event is fired at the end:
e.record.beginEdit();
e.record.set('Description', 'foo');
e.record.set('OnHand', 100);
e.record.endEdit();
Good point Mikhail, thanks, I've improved the answer to use set()
calls.
The trick is to use the record's set() method instead of directly updating the data. Using that method fires the necessary event handlers to notify the grid that there was a change.