Rather than subclass DataGrid I wrapped it in a class and have my own
addColumn() methods. Here's the relevant code in my
TotalDataGrid.addColumn() method.
public function addColumn(name:String, dataField:String,
labelFunction:Function=null):void
{
var dgcd:DataGridColumn = new DataGridColumn(name);
dgcd.dataField = dataField;
if (labelFunction != null) dgcd.labelFunction = labelFunction;
// add the column to the datagrid.
// this has to be done in this weird way because of how the datagrid works
// the getter for the columns returns a new array so you cannot
operate on
// the internal array of columns held by the datagrid. You have to get a
// copy, add one to it, and then give the array back via a setter.
var a:Array;
a = dg_Data.columns;
a.push(dgcd);
dg_Data.columns = a;
}
I also do a bit more because I have specialised formatters and a total
row in my custom component, but the basics are in that code.
There is probably a way of doing this which is purely data driven,
i.e. you don't have to inspect the incoming data tables for its
columns, but I'd have to think a bit more about that and my app
doesn't need it. Maybe some bright spark will have an answer for that.
HTH
Simon
--- In [email protected], "Richard Rodseth" <[EMAIL PROTECTED]> wrote:
>
> Any suggestions for the best way to do a datagrid-like object with a
> variable data-driven number of rows *and* columns? I see that the the
> columns array can be set.
>