A
Anonymous
May 18, 2009
Question
More DataGrid Problems w/ custom CellRenderer
- May 18, 2009
- 3 replies
- 667 views
Here's a program that creates a little data grid, populates it, and then tries to set the column one cell renderer to a very simple custom CellRenderer derived class:
import fl.controls.DataGrid;
import fl.controls.dataGridClasses.DataGridColumn;
import fl.controls.listClasses.CellRenderer;
import fl.data.DataProvider;
import RedTextCellRenderer;
import com.kis_systems.utils.PicCellRenderer;
var keys:Array = ["tname", "birthday", "pic_square"];
var dpArray = [
{ tname:"Shakira", birthday:"May 24, 1978",
pic:"pic_1_url" },
{ tname:"Alouitious Hornblower", birthday:"June 21, 1822",
pic:"pic_2_url" },
{ tname:"Batman Robin", birthday:"January 4, 1951",
pic:"pic_3_url" },
{ tname:"Franklin D. Roosevelt", birthday:"April 19, 1898",
pic:"pic_4_url" },
{ tname:"Carol Hirunsipachoti", birthday:"December 25, 1973",
pic:"pic_5_url" }
];
var colWidths:Array = [200, 120, 60];
var fpGrid:DataGrid = new DataGrid();
fpGrid.editable = false;
fpGrid.resizableColumns = false;
fpGrid.showHeaders = false;
fpGrid.rowHeight = 60;
var gridWidth:uint = 0;
fpGrid.columns = keys;
fpGrid.dataProvider = new DataProvider(dpArray);
// doc says I gotta do this *before* applying a new CellRenderer
cvar col:DataGridColumn;
col = fpGrid.getColumnAt(0);
col.cellRenderer = new RedTextCellRenderer();
// provide a new cell renderer for column 0...
fpGrid.x = fpGrid.y = 15; gridWidth = 0; for (var lx:uint = 0; lx < 3; lx++) { fpGrid.columns[lx].width = colWidths[lx]; gridWidth += colWidths[lx]; } fpGrid.setSize(gridWidth, fpGridBgd.height - 30); addChild(fpGrid);
And here is RedTextCellRenderer.as
package
{
import fl.controls.listClasses.CellRenderer;
import flash.text.TextField;
public class RedTextCellRenderer extends CellRenderer
{
public function RedTextCellRenderer():void
{
textField.background = true;
textField.backgroundColor = 0xff8888;
}
}
}
I've attached the resulting .swf
In the first column, the one for which the custom cell is applied, it only draws the last cell. The other columns get drawn fine.
I'm working off the 'Setting styles for an individual column' example in the 'Customizing the DataGrid' section of the 'Flash AS3 Components Help' document for a guide.
Among other glaring errors in the example code, seems to be this:
var col3:DataGridCoumn = new DataGridColumn(); col3 = aDg.getColumnAt(2); col3.cellRenderer = MultiLineCell;
Isn't the col3 instance in the first line clobbered by the instance retrieved from the DataGrid 'aDg' in line 2?
Anyway.... thoughts appreciated...
rickb