0 Replies Latest reply on Feb 19, 2009 2:09 PM by iz1

    Printing AdvancedDataGrid

    iz1
      I am using modified example from LiveDocs to print AdvancedDataGrid

      -- here is a print component --

      <?xml version="1.0"?>
      <!--printViewGrid.mxml -->
      <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml"
      backgroundColor="#FFFFFF"
      fontSize="8"
      paddingTop="20"
      paddingBottom="20"
      paddingLeft="30"
      paddingRight="20">

      <mx:Script>
      <![CDATA[
      import mx.core.*
      import mx.printing.PrintAdvancedDataGrid;

      [Bindable]
      public var pageNumber:Number = 1;
      [Bindable]
      public var gridTitle:String = "tasks";

      public function showPage(pageType:String):void {

      if(pageType == "first" || pageType == "middle") {
      // Hide the footer.
      //footer.includeInLayout = false;
      //footer.visible = false;
      }
      if(pageType == "middle" || pageType == "last") {
      // The header won't be used again; hide it.
      header.includeInLayout = false;
      header.visible = false;
      }
      if(pageType == "last") {
      // Show the footer.
      //footer.includeInLayout = true;
      //footer.visible = true;
      }
      //Update the DataGrid layout to reflect the results.
      validateNow();
      }
      ]]>
      </mx:Script>
      <mx:VBox id="pnum" width="100%" horizontalAlign="right">
      <mx:Label text="Page {pageNumber}"/>
      </mx:VBox>
      <mx:Label id="header" text="{gridTitle}" fontSize="12">
      </mx:Label>
      <mx:PrintAdvancedDataGrid id="printDG"
      designViewDataType="tree"
      variableRowHeight="true"
      headerStyleName="centered"
      wordWrap="true"
      height="100%"
      width="100%">
      </mx:PrintAdvancedDataGrid>
      </mx:VBox>

      -- fragment of the doPrint() function --

      var thePrintView:printViewGrid = new printViewGrid();
      thePrintView.includeInLayout = false;
      addChild(thePrintView);

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

      thePrintView.gridTitle = gridTitle;

      // thePrintView.printDG.dataProvider = grid.dataProvider;
      // thePrintView.printDG.columns = grid.columns;
      // or
      thePrintView.printDG.source = grid;

      thePrintView.printDG.percentHeight = 100;
      thePrintView.printDG.percentWidth = 100;
      ...

      If I assign provider and columns, it is printing almost fine (print has last row missing or partially printed)

      But after the print is done, the Grid is messed up:
      -- rows that were hiden are not displayed correctly when scrolled up or down
      -- grid columns are not responding to visible (true/false) command

      during the assignment :
      // thePrintView.printDG.columns = grid.columns;
      Columns owner property is changed to PrintAdvancedDataGrid from AdvancedDataGrid (original owner)

      if I use:
      thePrintView.printDG.source = grid;

      printed page is the size of the original grid and not a full page as it should.

      following code doesn't do anything:

      thePrintView.printDG.percentHeight = 100;
      thePrintView.printDG.percentWidth = 100;

      The only choice I see now is to define columns for PrintAdvancedDataGrid in a print component
      Complications:
      -- I would need a separate print component for every grid I have.
      -- also I would need to repeat all formatting and field functions for each column of a grid
      Sounds like a very bad programming practice.

      I would appreciate any suggestions to fix the problem.

      Irina.