The click method can be defined in a <mx:Script> block outside the DataGrid and referenced with outerDocument.myFunc(), ensure it is public, not private.
Change the label and icon by affecting the data in a collection.
Thanks for replying, I m still unsure of how to access the properties of a button in a row? I currently have the code below and am struggling to access the properties of the 'Add' button so I can change the label and icon?
<mx:columns> <mx:DataGridColumn headerText="Group" dataField="groupName" width="130" editable="false" sortable="false" /> <mx:DataGridColumn headerText="Article Number" dataField="articleNumber" width="200" editable="false" sortable="false" /> <mx:DataGridColumn headerText="Article Name" dataField="slideTitle" width="230" editable="false" sortable="false" /> <mx:DataGridColumn headerText="Colourway" dataField="colourway" width="218" editable="false" sortable="false" /> <mx:DataGridColumn editable="false" paddingLeft="5" sortable="false"> <mx:itemRenderer> <mx:Component> <mx:VBox> <mx:Button label="Add" icon="@Embed(source='assets/icons/add.png')"> <mx:click> <![CDATA[ outerDocument.addItemToCart(data); ]]> </mx:click> </mx:Button> </mx:VBox> </mx:Component> </mx:itemRenderer> </mx:DataGridColumn>
Item renderers are "recycled". Whenever the underlying data changes, or when you scroll, the visible ui elements are re-populated with the new underlying item data.
This means that any part of an item renderer that is row dependent, that is, needs to be different for different rows, must be driven by values in the dataProvider item.
So you will never want to get a reference to a button in a renderer, it will not do you any good.
Instead, in your button renderer, update a property on the dataProvider item that controls the appearance of the button, and link the button's UI to that property.
Actually, because they are tightly integrated with the framework to optimize performance, interactive itemRenderers are a bit difficult. I advise you find an example(there are many) that is close to what you want and modify it.