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.

6 Responses to “Flex DataGrid and Buttons in Rows”

  1. hammet Says:

    you stupid asshole look at the posted code!!! Whata fuck’a is dat?

  2. stevex Says:

    Oops. Fixed it.

  3. David Says:

    Curios what was the code earlier?

  4. Bob Says:

    And… why does Hammet need to be such an ass?
    Stevex: Thanks ton’s it worked like a charm.
    Bob

  5. Jonathan Says:

    @Bob It takes all kinds! @stevex Thanks!

  6. migue Says:

    this does not work for me i grabbed your code dumped it on a flex page and i get a blank page?…

Leave a Reply