Search code examples
datagridflex-sparkitemrenderertext-align

Flex 4.5: Setting textAlign GridColumn's itemRenderer through AS3


Maybe this is really simple, but I can't figure out how to set 'textAlign' property for default itemRenderer in AS3 (not mxml). I need to adjust it based on type's properties, 'int' or 'Number' aligned right, 'String' aligned left and so on.

I'm using spark DataGrid and listening FlexEvent.CREATION_COMPLETE event; I can't cast itemRenderer to DefaultGridItemRenderer, and ClassFactory doesn't provide setStyle method.

public function adjustGrid (e:Event):void
{
    for (var i:int=0; i<grd.columns.length; i++)
    {
        var gridColumn:GridColumn = GridColumn(grd.columns.getItemAt(i));
        DefaultGridItemRenderer(gridColumn.itemRenderer).setStyle("textAlign", "right");
    //ClassFactory(gridColumn.itemRenderer).setStyle("textAlign", "right");
    }
}

Any help I will appreciate. Thanks.


Solution

  • extends DefaultGridItemRenderer.......

    override public function getTextStyles():TextFormat{
      var tf:TextFormat = super.getTextStyles();
      tf.align = "right";
      return tf;
    }