Custom header in DataGrid - part 2
Monday, November 19th, 2007- Custom header in DataGrid
- Custom header in DataGrid - part 2
- “Filter results in DataGrid” Flex Tutorial
This is answer of my question asked at the end of tutorial Custom header in DataGrid. Question was if it is possible to set as many custom properties to custom header renderer as you want, and how can it be done. So here are answer…
First of all I want to thank Tink for pointing me to the right direction with extending DataGridColumn. Afterward I’ve found tutorial Thinking About Item Renderers and there were my answer…
So, you have to extend DataGridColumn to MyDataGridColumn to add there our custom properties for header. In our case there are new properties text and topText.
[as]
package controls
{
import mx.controls.dataGridClasses.DataGridColumn;
public class MyDataGridColumn extends DataGridColumn
{
private var _text:String;
private var _topText:String;
public function get text():String
{
return _text;
}
public function set text( value:String ):void
{
_text = value;
}
public function get topText():String
{
return _topText;
}
public function set topText( value:String ):void
{
_topText = value;
}
}
}
[/as]
Pretty simple, and now you can change your commitProperties function in MyDataGrid class where you’re creating DataGrid columns. Just set your new properties there
[as]
var colName:MyDataGridColumn = new MyDataGridColumn();
colName.headerRenderer = new ClassFactory(MyDataGridHeader);
colName.text = “Name”;
colName.topText = “Web”;
colName.dataField = “name”;
var colLink:MyDataGridColumn = new MyDataGridColumn();
colLink.headerRenderer = new ClassFactory(MyDataGridHeader);
colLink.text = “Link”;
colLink.topText = “URL”;
colLink.dataField = “url”;
[/as]
all other parts of MyDataGrid class are same from previous example (look to the source code on right click or download them).
And we’re done. Simple when you know how to do it
And here you can try this example (Source code is available on right click):

If you want another Flex or AIR tutorial, please ask in comments here
tagged under:





1 Comments
Greg
• Visit Site
January 13th, 2008
Very useful, thanks. I’ve just started learning Flex recently, but wonder why you don’t just include the MyDataGridHeader code in the MyDataGridColumn class itself. It wouldn’t be difficult to refactor as a pure actionscript class, and then you could just put it in MyDataGridColumn.as as a private class, right?
Live Preview
Leave a comment