Flex DataGrid and Buttons in Rows

So you’re working in Flex, and you’ve got a DataGrid.  The grid’s showing some data you’ve bound it to, and you want to have a button in a row that, when you click it, does something to one of the properties of the row.

Easy.  In the click event for your button, the ‘data’ property is the current row.  Here’s a button that sets the lastDone property of the row to the current date:

1
2
3
4
5
6
7
8
9
10
<mx:DataGridColumn editable="false">
  <mx:itemRenderer>
    <mx:Component>
      <mx:VBox>
        <mx:Button label="Done Today"
          click="<strong>data.lastDone = new Date();</strong>"/>
      </mx:VBox>
    </mx:Component>
  </mx:itemRenderer>
</mx:DataGridColumn>

This gives me a column with a button in it, whose click event sets the lastDone property of the current row to the current date.  No extra code anywhere else; that’s all there is to it.