I'm curious how others would tackle this:
Consider a DataGrid with every column using a Label subclass as its itemRenderer (for toolTip stuff or etc). In the first column I'd like to display a button inside each cell (for example a pencil icon which would enable editing of the cell text when clicked). The examples I've found either involve subclassing Button as the itemRenderer or adding the button via a new inline mxml itemRenderer...
Is there a way to do it that retains functionality of or subclasses the current itemRenderer? Thank you!
Here's my grid:
<mx:DataGrid id="dg_myGrid" width="100%" allowMultipleSelection="true">
<mx:columns>
<mx:DataGridColumn width="80" dataField="@currCode"
headerText="Current Code"
dataTipField="@codeDescription"
itemRenderer="com.foo.bar.components.LabelCustom"/>
<mx:DataGridColumn width="80" dataField="@codeDescription
headerText="Description"
itemRenderer="com.foo.bar.components.LabelCustom"/>
</mx:columns>
</mx:DataGrid>
And here's the Label subclass being used as the dataGridColumn itemRenderer:
package com.foo.bar.components{
public class LabelCustom extends Label{
private function getToolTip():String{
var dg:DataGrid = listData.owner as DataGrid;
if(dg.columns[listData.columnIndex].dataTipField!=null){
return data[dg.columns[listData.columnIndex].dataTipField];
}else{
return "";
}
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
var tip:String = getToolTip();
if (tip != "") this.toolTip = tip;
super.updateDisplayList(unscaledWidth, unscaledHeight);
}
}
}