How to print flex spark datagrid by using the mx PrintDataGrid? Or is there other way to achieve this without using the mx PrintDataGrid?

ⅰ亾dé卋堺 提交于 2019-12-23 12:15:40

问题


this is my first time to ask here since my question is not answerable in the adobe flex forum. So at least finally, I've come to manage it here.

Well, Flex 4.5+ is I guess everyone is working on nowadays so I asked this question since I haven't yet find working both spark datagrid and the mx printdatagrid components together.

What I'm trying to achieve is to print all the data inside my spark datagrid. So when I do my research, we use the PrintJob or the FlexPrintJob classes. It works fine but when I need to print multiple pages since the data on my spark datagrid is quite long, I can't somehow find a way how to do it. The print output is only upto where the height of my spark datagrid. So in my research, they somehow managed it to use the mx:PrintDataGrid component. But sad to say, they did it with an mx:DataGrid also. Now here comes my problem - how to use the mx:PrintDataGrid along with s:DataGrid.

var printJob:PrintJob = new PrintJob();

if (printJob.start())
{
    var printGrid:PrintDataGrid = new PrintDataGrid();
    printGrid.width = printJob.pageWidth;
    printGrid.height = printJob.pageHeight;
    printGrid.columns = mySparkDataGrid.columns; // this line throws an exception
    printGrid.dataProvider = mySparkDataGrid.dataProvider;
    printGrid.visible = false;
    FlexGlobals.topLevelApplication.addElement(printGrid);

    while (printGrid.validNextPage)
    {
        printGrid.nextPage();
        printJob.addPage(printGrid);
    }

    printJob.send();
    parentApplication.removeElement(printGrid);
}  

So please, can anyone here help me with this? If converting a spark datagrid columns to the mx datagrid columns is not possible, is there a way that I can print all the data on the spark datagrid using multiple pages?

Big thanks in advance.

-Ted


回答1:


Try somethink like this(it works to me)

for (var i:int = 0; i < mySparkDataGrid.columns.length - 1; i++) {

    var tmpColumn:DataGridColumn = new DataGridColumn();
    tmpColumn.headerText = (mySparkDataGrid.columns.getItemAt(i) as GridColumn).headerText;
    tmpColumns.push(tmpColumn);

}

printGrid.columns = tmpColumns;

Now i have to find way,how use ItemRender.My dataprovider has bigger object and I have to parse it for display correct data in grid.The same I have to do for print.



来源:https://stackoverflow.com/questions/7649244/how-to-print-flex-spark-datagrid-by-using-the-mx-printdatagrid-or-is-there-othe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!