Hi.
I want to align text in the header of DataGrid. I’ve googled the problem and found some solutions:
- Using custom HeaderRenderer
package controls
{
import fl.controls.dataGridClasses.HeaderRenderer;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
public class CenterHeaderRenderer extends HeaderRenderer
{
private var tf:TextFormat;
public function CenterHeaderRenderer()
{
init();
}
private function init():void
{
tf = new TextFormat();
tf.align = TextFormatAlign.CENTER;
tf.bold = true;
}
override protected function drawLayout():void
{
textField.width = this.width;
textField.setTextFormat(tf);
super.drawLayout();
}
}
}
- Using setStyle property for DataGrid
The problem is - both solutions doesn’t work. I’ve tried to play with super.drawLayout() string, put in on the top. The result changes a little bit, but still bugs.
With the help of trace I’ve found some tips - I think flash calculates wrongly the width of header cell. For example, cell’s width is 200, and cell text’s width is 30. And flash thinks that the cell’s width is 30 (instead of 200).
Any help would be appreciated.
ADDED
Well, It looks stupid but it works:
override protected function drawLayout():void
{
super.drawLayout();
textField.x = 0;
textField.width = this.width;
textField.setTextFormat(tf);
}