0

I've got a dataGrid that has some columns, those columns have usually a fixed dataField, everything works ok.

However, under special circumstances, I need to change that dataField to another one, but I'm not sure how to do it.

I've tried to capture the moment when the data is being populated and somehow intercept the dataField and change it for the one I want.. but no luck so far.

Any idea?.

Artemix
  • 8,497
  • 14
  • 48
  • 75
  • Can you clarify your problem a little? Do you want to sometimes change the dataField used for the entire column, or change the value based on an item's values? – Bill Turner Apr 22 '14 at 20:29

1 Answers1

0

Depending on what exactly you're trying to do, I can think of three ways to do it.

1) If you're trying to swap the entire column at a time (like a button to select which column to show), you can set the GridColumn's dataField and headerText field values:

<s:GridColumn id="fieldToChange" dataField="name" headerText="Name"> ... protected function changeToRank(event:MouseEvent):void { fieldToChange.dataField = "rank"; fieldToChange.headerText = "Rank"; }

2) Similar to the above, if you're using states you can specify the dataField and headerText for each state:

<s:GridColumn dataField.nameState="name" dataField.rankState="rank" ...>

3) If you want to change what's displayed for a single row based on some criterion of the data item, you can use the labelFunction to set whatever you want to display.

<s:GridColumn labelFunction="nameOrRank" ...> ... protected function nameOrRank(item:Object):String { if (item.foo == xyzzy) return item.name; else return item.rank; }

Bill Turner
  • 980
  • 1
  • 6
  • 23