0

Actually, I have a Datagrid with 2 RadioButton controls inside of a cell for each row. Something like this:

======================================================
|             |             |   (o) Radiobutton #1   |
|   cell #1   |   cell #2   |   (o) Radiobutton #2   |
======================================================

If I remove one row and add other one after this, Flex is automatically reusing the previously removed RadioButtons (to optimize resources I think).

Associating creationComplete event handler to each RadioButton I confirmed my suspects:

  1. I create one row with 2 RadioButtons in an specific cell: both creationComplete handlers executes successfully.
  2. I remove this row, and add another one.
  3. Now, creationComplete handlers didn't execute, so Flex is using the previously RadioButtons.

But I don't want this behaviour in my app. Is there any way to force Flex to create the components every single time (avoiding reuse)? Thanks!

Fran Verona
  • 5,438
  • 6
  • 46
  • 85

2 Answers2

1
But I don't want this behaviour in my app.

If you care about performance and memory usage, then you do want this behavior in your app. Please read up on creating Renderers. Pay special attention to the section on creating recyclable renderers.

Is there any way to force Flex to create the components every single time (avoiding reuse)?

You can size your DataGrid so that every item in the dataProvider is displayed on screen.

If you're using the Spark DataGrid, most likely you can set a property on the layout to not use virtual layouts; but I haven't delved in the Spark DataGrid API too much, so I'm not sure if it is there.

I wholeheartedly recommend that you re-write your renderer to listen to the dataChange() event and modify the display elements of the renderer (AKA RadioButton) instead of trying to have a single renderer instance for each elements of your dataProvider.

JeffryHouser
  • 39,401
  • 4
  • 38
  • 59
  • Even better is to override the data setter and then make the appropriate adjustments in commitProperties. – Amy Blankenship May 28 '12 at 18:29
  • @AmyBlankenship "Better" is always subjective; in the case of renderers I prefer to use the dataChange event instead of overriding the set data method; but that is primarily because most of the time when people override set data they do not call super, which bugs me. Making use of the Component Lifecycle for relevant changes makes a lot of sense. – JeffryHouser May 28 '12 at 18:34
  • I think that "most of the time" is a stretch. I think that most developers will only make this mistake once or twice, since the consequences are pretty dire. – Amy Blankenship May 28 '12 at 18:36
  • @AmyBlankenship I was referring to the 'set data' method explicitly; not generic use of calling super. There are usually no consequences for not calling super in the set data method; so many developers [that I have spoken to] prefer not to set it. I've had arguments about this. – JeffryHouser May 28 '12 at 18:52
  • Yes, I was referring to not calling super.data as well. There are lots of components where if you don't call this, things blow up. – Amy Blankenship May 28 '12 at 19:31
  • @AmyBlankenship Even better with `GridItemRenderer`s is to override the `prepare(hasBeenRecycled:Boolean)` method. – RIAstar May 28 '12 at 20:26
0

In Flex 4/spark Lists, you can turn this on and off with the useVirtualLayout property (http://help.adobe.com/en_US/flex/using/WSc2368ca491e3ff92-1483ec4a12136246e76-8000.html). However, I don't think there's a spark version of ADG yet, so you're "stuck" with a component that assumes you care about memory and CPU usage, and you can't tell it otherwise.

Amy Blankenship
  • 6,485
  • 2
  • 22
  • 45