Hello,I'm hoping someone can help me out. I've got a couple of datagrid's in my viewer application containing attribute data. I'm trying to add the ability to print these and have found several examples of doing this with the PrintDataGrid component, looping through the pages of data, etc..My implementation of this does not work even though it is pretty much a line for line copy of some of the examples. The datagrid always seems to indicated that there is additional pages to print, even if there is only a single row. This is resulting in an infinite loop until the flash plugin crashes.Any help would be appreciated, thanks!My code.
public static function printGrid(dg:DataGrid):void
{
try
{
var thePrintJob:FlexPrintJob = new FlexPrintJob();
if (thePrintJob.start())
{
var scaleType:String = FlexPrintJobScaleType.MATCH_WIDTH;
var pDataGrid:PrintDataGrid = new PrintDataGrid();
// copy columns and attributes from passed grid
for (var x:int = 0; x < dg.columns.length; x++)
{
var srcCol:DataGridColumn = dg.columns;
var destCol:DataGridColumn = new DataGridColumn();
destCol.headerText = srcCol.headerText;
destCol.dataField = srcCol.dataField;
pDataGrid.columns.push(destCol);
}
pDataGrid.width = thePrintJob.pageWidth;
pDataGrid.height = thePrintJob.pageHeight;
pDataGrid.visible = false;
pDataGrid.includeInLayout = false;
pDataGrid.dataProvider = dg.dataProvider;
FlexGlobals.topLevelApplication.addElement(pDataGrid);
thePrintJob.addObject(pDataGrid, scaleType);
while(pDataGrid.validNextPage) // ** always returns true
{
pDataGrid.nextPage();
thePrintJob.addObject(pDataGrid, scaleType);
}
FlexGlobals.topLevelApplication.removeElement(pDataGrid);
thePrintJob.send();
}
}
catch(e:Error)
{
Alert.show(e.errorID + " " + e.message);
}
} // method