2
votes

How can an mxColumn.itemRenderer be set by copying a sparkColumn.itemRenderer during runtime?

I have an app that uses mx:DataGrid, mx:AdvancedDataGrid, and s:DataGrid.

We're implementing a "print" feature, using mx:PrintDataGrid and mx:PrintAdvancedDataGrid.

We set the printable dataGrid's columns to the columns of the dataGrid we want to print, like this:
printDataGrid.columns = targetDataGrid.columns; //or
printAdvancedDataGrid.columns = targetDataGrid.columns;

Doing it this way, the print retains the format of the itemRenderers.

When the dataGrid-to-print is spark, the columns are iterated, and new spark columns made

for (var i:uint; i < sparkColumns.length; i++)
{

    sparkColumn = sparkColumns.getItemAt(i) as GridColumn;<br/>
    mxColumn = new DataGridColumn();<br/>
    mxColumn.headerText = sparkColumn.headerText;<br/>
    mxColumn.dataField = sparkColumn.dataField;<br/>
    //mxColumn.itemRenderer =  sparkColumn.itemRenderer;<br/>
    mxColumns.push(mxColumn);

}

The dataField and headerText properties translate easily from mx to spark columns, but the itemRenderers are trickier.

How can the mxColumn.itemRenderer be set to the sparkColumn.itemRenderer?

Does anyone know how to scoop out the components/functions/properties in the spark itemRenderer? How to "type-cast" that to an mx itemRenderer?

1

1 Answers

0
votes

Does anyone know how to scoop out the components/functions/properties in the spark itemRenderer? How to "type-cast" that to an mx itemRenderer?

Even if it is possible with reflection I think that would be very tough task.

If I had such requirement I would consider two options.

First is to create itemRenderers for each column by extending UIComponent and implementing interfaces so that Spark Grid and Mx Grid could use them. Then you will be able to unmark remarked line.

Second is to extend spark column and add field "type", that will hold, for example: "Label", "Date", "CustomType", "usdType", etc.

Then create descriptor, that would hold type of the column, class of mx renderer and class of spark renderer.

For Example,

var columnsDescripor:Object = {};
columnsDescripor["label"] = {mx: mx.controls.Label, s: spark.components.Label};
columnsDescripor["usd"] = {mx: MXusdRenderer, s: SusdRenderer};

Then,

sparkColumn = ExtendedGridColumn(sparkColumns.getItemAt(i));
mxColumn.itemRenderer = new (columnsDescripor[sparkColumn.type].mx);