1 Reply Latest reply on Aug 18, 2006 5:13 AM by peterent

    Can a cell update in a DataGrid trigger an effect on that cell?

    DavidWhewell Level 1
      Hi all, another DataGrid question, seems they are popular these days :)

      I have a DataGrid populated by an ArrayCollection, which is working fine with ArrayCollection.itemUpdated() to keep its display in sync. What I would love to be able to do, however, is to highlight (ie apply an Effect) to the cell that is updated. I had a look at the Effects available to the DataGrid directly but couldn't find a way to do this, could someone point me in a way that would make this possible? I just want to make it have an effect that changes the background colour for a second.


        • 1. Re: Can a cell update in a DataGrid trigger an effect on that cell?
          peterent Level 2
          This is going to be a little/difficult complex. The valueCommitted event on the DataGrid should get triggered whenever anything in the DataGrid changes - whether it is by user action (editing a cell) or programmatic changes as you describe.

          You also need an itemRenderer to make the visual change to the cell. If you are comfortable with itemRenderers, then this is how I would approach it. I have to say that I have not tried this, so use at your own risk.

          You should also understand that itemRenderers are re-used when the DataGrid scrolls - so don't store anything in them that you think will be remembered for a particular cell.

          When you detect that a value has changed, I would set a flag in the data itself - this is the only to guarantee that the information reaches the itemRenderer. For example, if you have 3 fields per record (product, quantity, price) and want to indicate when quantity changes, add a quantity_changed field and set it to true.

          The itemRenderer will automatically be called upon to display the changed data. So you would think that alone would be enough. But keep in mind that the itemRenderer will also be called if the mouse sweeps over a cell or when the row is selected. That's why you need this flag to distinguish between the events.

          In the itemRenderer, override the updateDisplayList function. This is where you will create and run the effect. From what you decribe, I would use states as that would be the easiest way to do this. Set the itemRenderer's backgroundColor (to red for example) and its backgroundAlpha to 0 so you don't see the red. That's the base state. In the "highlight" state, change the backgroundAlpha to 1.

          You can use transitions to make the change happen. You will also need a Timer to change the state back.

          In the updateDisplayList function, check the flag. If it is set, then change the state and start the timer. When the timer goes off, it should change the state back.

          Becareful not to introduce any effect which will change the size of the cell or it will trigger updateDisplayList again and could lead to an infinite loop.

          There are probably other ways to do this, but off the top of my head, I'd go this route and see where it leads.