Skip to main content
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

This topic has been closed for replies.

3 replies

May 20, 2009

Ack!!!

This line:

  col.cellRenderer =  new RedTextCellRenderer();

... should be:

   col.cellRenderer = RedTextCellRenderer;

You pass the classname of the cell renderer, not an instance.

Wish someone would have seen this - three days of jabbing self in eye with a sharp stick would have been more productive...

May 19, 2009

Hm.  No response.

I'm getting a few thoughts about all of this:

  1. Flash AS3 appears to be a poor sister to Flex AS3, at least in the controls implementation - Adobe seems to be throwing all of their efforts into the Flex versions and leaving the Flash versions to dangle.

  2. 'fl' DataGrid is buggy/arcane/subject to sequencing issues/all of the above.  Trying to follow even the basic examples to do something out of the ordinary seems to run into a rat's nest of issues, for which no-one seems to know the answers (evidenced by the multiple threads in this topic that appear to be unanswered on such things as resizing columns to content, or just putting a picture in a column.)

Maybe I can use the 'mx' version...

Or maybe I should just go over to Flex....

rickb

May 18, 2009

... ignore the 'cvar' which is really 'var' in the code....

problems in transcribing to the forum format...

rickb