开发者

print advanceddatagrid in flex 4.1

I need help with printing my advanceddatagrid. I tried different ways but all I get is a blank table.

The table is there but there are no headers or data in it. Here's my code:

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx" width="95%" height="95%" fontFamily="Arial" fontSize="12">
    <fx:Script>
        <![CDATA[
            import valueObjects.SummaryCollectionsDeposits;

            [Bindable]
            public var report:Object;
            [Bindable]
            public var scdno:String;
            [Bindable]
            public var pageNumber:Number = 1;

            public function showPage(pageType:String):void {

            }

            private function getReceiptNumber(o:Object, column:AdvancedDataGridColumn) {
                return o.receipt.receiptNumber;
            }

            private function getPayor(o:Object, column:AdvancedDataGridColumn) {
                return o.receipt.payor;
            }
            private function getParticular(o:Object, column:AdvancedDataGridColumn) {
                if(o.natureOfCollection.accountTitle=="Others")
                    return o.description;
                else
                    return o.natureOfCollection.accountTitle;

            }
            private function getBrgyAmount(o:Object, column:AdvancedDataGridColumn) {
                return Currency.format(o.amount);
            }
            private function getGridDate(o:Object, column:AdvancedDataGridColumn) {
                return gridDateFormat.format(o.receipt.receiptDate);
            }

            private function getBrgyDeposites(o:Object, column:AdvancedDataGridColumn) {
                if(o.natureOfCollection.accountTitle=="Others")
                    return Currency.format(o.amount);
                else
                    return "";

            }
            private function getBrgyBalance(o:Object, column:AdvancedDataGridColumn) {
                if(o.natureOfCollection.accountTitle=="Others")
                    return "";
                else
                    return Currency.format(o.amount);

            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <mx:DateFormatter id="gridDateFormat" formatString="MM/DD/YY"/>
        <mx:DateFormatter id="dateFormat" formatString="MMMM DD, YYYY"/>
        <mx:CurrencyFormatter id="Currency" precision="2" rounding="none" decimalSeparatorTo="." thousandsSeparatorTo=","
                              useThousandsSeparator="true" currencySymbol="" useNegativeSign="true"/>   </fx:Declarations>

    <s:layout>
        <s:VerticalLayout verticalAlign="top" horizontalAlign="center" >

        </s:VerticalLayout>
    </s:layout>

    <s:Group width="100%" id="header">
        <s:layout>
            <s:VerticalLayout verticalAlign="top" horizontalAlign="center" >

            </s:VerticalLayout>
        </s:layout>
        <s:Group  width="100%">
            <s:layout>
                <s:VerticalLayout horizontalAlign="center"/>

            </s:layout>

            <s:Label text="{report.TITLE}" fontWeight="bold" fontSize="14"/>
            <s:Label text="for {dateFormat.format(report.reportDate)}"/>
        </s:Group>
        <mx:HRule width="100%"/>

    </s:Group>

    <mx:PrintAdvancedDataGrid dataProvider="{report.collections}"
                         width="100%"  id="adg" height="{adg.measureHeightOfItems(0, report.collections.length) + adg.headerHeight}"
                         designViewDataType="flat" allowInteraction="true" >

        <mx:groupedColumns>
            <mx:AdvancedDataGridColumn headerText="Date"  wordWrap="true" labelFunction="getGridDate"/>
            <mx:AdvancedDataGridColumn  headerText="OR/VDS/SCR No" labelFunction="getReceiptNumber" wordWrap="true"/>
            <mx:AdvancedDataGridColumn  headerText="Payor/Bank" labelFunction="getPayor" wordWrap="true"/>
            <mx:AdvancedDataGridColumn  h开发者_如何学PythoneaderText="Particulars" labelFunction="getParticular" wordWrap="true"/>
            <mx:AdvancedDataGridColumnGroup headerText="Barangay">
                <mx:AdvancedDataGridColumn  headerText="Collections" labelFunction="getBrgyAmount" textAlign="right" />
                <mx:AdvancedDataGridColumn  headerText="Deposits" textAlign="right" labelFunction="getBrgyDeposites"/>
                <mx:AdvancedDataGridColumn  headerText="Balance" textAlign="right" labelFunction="getBrgyBalance"/>
            </mx:AdvancedDataGridColumnGroup>
            <mx:AdvancedDataGridColumnGroup headerText="As Deputized by City/Municipality">
                <mx:AdvancedDataGridColumn headerText="Collections" textAlign="right" />
                <mx:AdvancedDataGridColumn  headerText="Deposits" textAlign="right"/>
                <mx:AdvancedDataGridColumn  headerText="Balance" textAlign="right"/>
            </mx:AdvancedDataGridColumnGroup>
        </mx:groupedColumns>

    </mx:PrintAdvancedDataGrid >


</s:Group>

here's my print function in the main code:

private function doPrint():void {

                var printJob:FlexPrintJob = new FlexPrintJob();


                if (printJob.start()) {
                    // Create a FormPrintView control
                    // as a child of the application.
                    var thePrintView:SCDPrintTemplate = new SCDPrintTemplate();
                    thePrintView.report=report;
                    thePrintView.scdno=scdno.text;

                    // Exclude the PrintAdvancedDataGrid control from layout.


                    addElement(thePrintView);

                    // Set the print view properties.
                    thePrintView.width=printJob.pageWidth;
                    thePrintView.height=printJob.pageHeight;
                    //thePrintView.prodTotal = prodTotal;

                    // Create a single-page image.
                    thePrintView.showPage("single");
                    // If the print image's DataGrid can hold all the
                    // data provider's rows, add the page to the print job.
                    if(!thePrintView.adg.validNextPage)
                    {
                        printJob.addObject(thePrintView);
                    }
                        // Otherwise, the job requires multiple pages.
                    else
                    {
                        // Create the first page and add it to the print job.
                        thePrintView.showPage("first");
                        printJob.addObject(thePrintView);
                        thePrintView.pageNumber++;
                        // Loop through the following code
                        // until all pages are queued.
                        while(true)
                        {
                            // Move the next page of data to the top of
                            // the PrintDataGrid.
                            thePrintView.adg.nextPage();
                            // Try creating a last page.
                            thePrintView.showPage("last");
                            // If the page holds the remaining data, or if
                            // the last page was completely filled by the last
                            // grid data, queue it for printing.
                            // Test if there is data for another
                            // PrintDataGrid page.
                            if(!thePrintView.adg.validNextPage)
                            {
                                // This is the last page;
                                // queue it and exit the print loop.
                                printJob.addObject(thePrintView);
                                break;
                            }
                            else
                                // This is not the last page. Queue a middle page.
                            {
                                thePrintView.showPage("middle");
                                printJob.addObject(thePrintView);
                                thePrintView.pageNumber++;
                            }
                        }

                    }
                    // All pages are queued; remove the FormPrintView
                    // control to free memory.
                    removeElement(thePrintView);
                }
                // Send the job to the printer.
                printJob.send();

            }

Thanks :)


Try calling

thePrintView.validateNow(); 

Before calling

thePrintView.showPage("single");

Also, we've already done a lot of work around adding built in support for this. Check it out. at http://blog.flexicious.com/post/Customizing-the-PrintExcel-Output.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜