Notifications
Clear all

[Solved] How can I update column B in a grid when column A changes?

7 Posts
3 Users
5 Reactions
801 Views
1
Topic starter

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;
      }
    });
GregMerrill Topic starter 2012-09-24 12:09:00

See second answer below - the code above is generally an antipattern, should use e.record.set() instead of accessing e.record.data directly.

Sean Durkin 2012-09-24 12:09:00

If you're modifying multiple fields, you'll still want to wrap them in beginEdit/endEdit calls so only a single event gets fired.

3 Answers
2

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

GregMerrill Topic starter 2012-09-24 12:09:00

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.

2

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();
Sean Durkin 2017-01-16 12:01:00

Good point Mikhail, thanks, I've improved the answer to use set() calls.

0

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.