7 Replies Latest reply on Jun 2, 2007 1:18 PM by AwesomeDigital3

    Printing A Stinkin Grid!

    AwesomeDigital3 Level 1
      I have a hidden PrintDataGrid like this

      <mx:HBox visible="false" height="1000" width="100%" id="myPrintArea" backgroundColor="#FFFFFF">
      <mx:PrintDataGrid id="individualsGridPrint" height="100%" width="100%">
      <mx:columns>
      <mx:DataGridColumn headerText="Last Name" dataField="LastN" />
      <mx:DataGridColumn headerText="First Name" dataField="FirstN"/>
      <mx:DataGridColumn headerText="Phone" dataField="Phone"/>
      <mx:DataGridColumn headerText="Department" dataField="Dept"/>
      </mx:columns>
      </mx:PrintDataGrid>
      </mx:HBox>

      The numbers of rows may vary, but it looks like I have to hard code a HUGH number in the height of my print area to make sure that I show all?

      Is there a way to make it dynamic so it just prints all of the rows in the PrintDataGrid without the extra sheets of paper?

      Also is there a way to contol the font size on the print so it does not look like you are printing it for your 77 year old grandmother?

      Thanks
      Mathias

        • 1. Re: Printing A Stinkin Grid!
          AwesomeDigital3 Level 1
          Ok never mind on the font size, I figured that part out
          • 2. Re: Printing A Stinkin Grid!
            Level 7
            remove the height attribute all together. Then it show expand as needed.

            Bill


            "AwesomeDigital3" <webforumsuser@macromedia.com> wrote in message
            news:f3s6t0$as7$1@forums.macromedia.com...
            >I have a hidden PrintDataGrid like this
            >
            > <mx:HBox visible="false" height="1000" width="100%" id="myPrintArea"
            > backgroundColor="#FFFFFF">
            > <mx:PrintDataGrid id="individualsGridPrint" height="100%" width="100%">
            > <mx:columns>
            > <mx:DataGridColumn headerText="Last Name" dataField="LastN" />
            > <mx:DataGridColumn headerText="First Name" dataField="FirstN"/>
            > <mx:DataGridColumn headerText="Phone" dataField="Phone"/>
            > <mx:DataGridColumn headerText="Department" dataField="Dept"/>
            > </mx:columns>
            > </mx:PrintDataGrid>
            > </mx:HBox>
            >
            > The numbers of rows may vary, but it looks like I have to hard code a
            > HUGH
            > number in the height of my print area to make sure that I show all?
            >
            > Is there a way to make it dynamic so it just prints all of the rows in the
            > PrintDataGrid without the extra sheets of paper?
            >
            > Also is there a way to contol the font size on the print so it does not
            > look
            > like you are printing it for your 77 year old grandmother?
            >
            > Thanks
            > Mathias
            >
            >
            >


            • 3. Re: Printing A Stinkin Grid!
              AwesomeDigital3 Level 1
              No, that doesn't work. I already tried that.

              Then it only prints a little line at the top of the page.
              • 4. Re: Printing A Stinkin Grid!
                Level 7
                is there maybe a style definition in a css file pulling it ??

                Bill

                "AwesomeDigital3" <webforumsuser@macromedia.com> wrote in message
                news:f3s87t$cb8$1@forums.macromedia.com...
                > No, that doesn't work. I already tried that.
                >
                > Then it only prints a little line at the top of the page.


                • 5. Re: Printing A Stinkin Grid!
                  AwesomeDigital3 Level 1
                  Nope, it's just a simple application
                  • 6. Re: Printing A Stinkin Grid!
                    AwesomeDigital3 Level 1
                    Here is all of the code.

                    I tried moving this around. Now, if I put no height attribute on the myPrintArea tag, all I get is the title row of the data grid

                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:Application
                    xmlns:mx=" http://www.adobe.com/2006/mxml"
                    layout="absolute"
                    xmlns:actionScript="actionScript.*"
                    creationComplete="directoryXMLFile.send();setBrowserFocus();" >


                    <mx:Script>
                    <![CDATA[

                    // Set focus code found here
                    // http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=60&catid=585&threadid =1244083&highlight_key=y&keyword1=setfocus

                    import mx.collections.*;
                    import mx.controls.*;
                    import mx.rpc.events.*;
                    import mx.events.*;


                    [Bindable]
                    private var individualsArray:ArrayCollection = null;

                    [Bindable]
                    private var orphansArray:ArrayCollection = null;

                    [Bindable]
                    private var dateModified:Date = null;


                    private function dataRPCResult(event:ResultEvent):void {

                    //load the people into an array
                    orphansArray = new ArrayCollection();
                    orphansArray = event.result.PhoneDirectory.OrphanPhones.Phone as ArrayCollection;

                    //load the orphan phones into an array
                    individualsArray = new ArrayCollection();
                    individualsArray = event.result.PhoneDirectory.People.Person as ArrayCollection;

                    //dateModified = directoryXMLFile.lastResult.PhoneDirectory.MetaData.GeneratedOn;

                    // the function to call for filtering (searches)
                    individualsArray.filterFunction=processSearchFilter;

                    // sort the people by the last name
                    var individualsSort:Sort = new Sort();
                    var individualsSortField:SortField = new SortField("LastN");
                    individualsSort.fields = new Array(individualsSortField);
                    individualsArray.sort=individualsSort;
                    individualsArray.refresh();

                    //individualsArray.addItem(NextAnniversaryDate:Object):void;

                    }

                    public function processSearchFilter(item:Object):Boolean {
                    var result:Boolean=false;

                    if (
                    ( textSearch.text == '' ||
                    (item.LastN != null && String(item.LastN).toUpperCase().indexOf(textSearch.text.toUpperCase()) >= 0) ||
                    (
                    (item.FirstN != null && String(item.FirstN).toUpperCase().indexOf(textSearch.text.toUpperCase()) >= 0)
                    ) ||
                    (
                    (item.Phone != null && String(item.Phone).toUpperCase().indexOf(textSearch.text.toUpperCase()) >= 0)
                    ) ||
                    (
                    (item.Dept != null && String(item.Dept).toUpperCase().indexOf(textSearch.text.toUpperCase()) >= 0)
                    )||
                    (
                    (item.Loc != null && String(item.Loc).toUpperCase().indexOf(textSearch.text.toUpperCase()) >= 0)
                    )
                    )
                    )
                    {
                    result=true;
                    }
                    return result;
                    }

                    private function clearSearch():void{
                    textSearch.text = '';
                    individualsArray.refresh();
                    }

                    private function Filter():void{
                    textSearch.text = '';
                    individualsArray.refresh();
                    }

                    public function BuildPhoneString():String{
                    var thePhoneString:String= "qwqwe";
                    return thePhoneString;
                    }


                    // the code to print the phone list
                    import mx.printing.FlexPrintJob

                    private function printJob():void
                    {
                    var myPrintJob:FlexPrintJob = new FlexPrintJob();
                    if(myPrintJob.start() != true)
                    {
                    return;
                    }

                    // populate the hidden data grid
                    individualsGridPrint.dataProvider = individualsGrid.dataProvider;

                    //before.text = myPrintArea.height.toString();
                    //rowcount.text = individualsGridPrint.rowCount.toString();


                    // make sure the height of the print is enough to print all of the rows
                    //myPrintArea.height = individualsGridPrint.rowCount * (individualsGridPrint.rowHeight + 3);

                    //after.text = myPrintArea.height.toString();


                    myPrintJob.addObject(myPrintArea);
                    myPrintJob.send();
                    }



                    ]]>
                    </mx:Script>

                    <mx:HTTPService id="directoryXMLFile" url="PhoneDirectory.xml" result="dataRPCResult(event)"/>



                    <mx:Panel fontSize="12" x="10" y="10" width="800" height="600" layout="absolute" title="{directoryXMLFile.lastResult.PhoneDirectory.MetaData.Title}" id="panel3">

                    <mx:TabNavigator width="100%" height="100%" horizontalGap="1">

                    <mx:Canvas label="Search" width="100%" height="100%">

                    <mx:VBox>
                    <mx:HBox paddingTop="5" paddingBottom="5" paddingLeft="10" >

                    <mx:Label text="Search" textAlign="right" fontWeight="bold"/>
                    <mx:TextInput id="textSearch" change="individualsArray.refresh();"/>
                    <mx:Button label="Clear Search" click="clearSearch()" height="20" />
                    <!--<mx:Button label="Refresh List" click="individualsArray.refresh();"/> -->
                    </mx:HBox>

                    <mx:HBox paddingTop="5" paddingBottom="5" paddingLeft="10" >
                    <!--<mx:Button id="myButton" label="Print" click="printIndividualsGrid();"/> -->
                    <mx:Button label="Print" click="printJob()" />

                    <mx:DataGrid width="585" id="individualsGrid" height="375" dataProvider="{individualsArray}" fontSize="11" paddingLeft="150">
                    <mx:columns>
                    <mx:DataGridColumn width="110" headerText="Last Name" dataField="LastN" />
                    <mx:DataGridColumn width="110" headerText="First Name" dataField="FirstN"/>
                    <mx:DataGridColumn width="75" headerText="Phone" dataField="{BuildPhoneString()}"/>
                    <mx:DataGridColumn width="150" headerText="Department" dataField="Dept"/>
                    <mx:DataGridColumn width="125" headerText="Location" dataField="Loc"/>
                    </mx:columns>
                    </mx:DataGrid>

                    </mx:HBox>

                    <mx:HBox height="500" visible="false" id="myPrintArea" backgroundColor="#FFFFFF">
                    <mx:PrintDataGrid id="individualsGridPrint" fontSize="11">
                    <mx:columns>
                    <mx:DataGridColumn headerText="Last Name" dataField="LastN" />
                    <mx:DataGridColumn headerText="First Name" dataField="FirstN"/>
                    <mx:DataGridColumn headerText="Phone" dataField="Phone"/>
                    <mx:DataGridColumn headerText="Department" dataField="Dept"/>
                    </mx:columns>
                    </mx:PrintDataGrid>
                    </mx:HBox>


                    <mx:HBox paddingTop="10" paddingLeft="10" paddingBottom="0">
                    <mx:Label text="This information is maintained by:" textAlign="right" fontWeight="bold" />
                    <mx:Label text="{directoryXMLFile.lastResult.PhoneDirectory.MetaData.MaintainedBy}" textAlign="left"/>
                    </mx:HBox>
                    <mx:HBox paddingLeft="10" paddingTop="0">
                    <mx:Label text="Last updated:" textAlign="right" fontWeight="bold" />
                    <mx:Label text="{directoryXMLFile.lastResult.PhoneDirectory.MetaData.GeneratedOn}" textAlign="left" />
                    </mx:HBox>
                    <mx:HBox paddingLeft="10" paddingTop="0">
                    <mx:Button fontSize="11" height="20" label="Load Latest Data" click="directoryXMLFile.send();"/>
                    </mx:HBox>

                    </mx:VBox>
                    </mx:Canvas>

                    <mx:Canvas label="Anniversaries" width="100%" height="100%">
                    <mx:Label text="* These dates may not correspond to the true HR date" textAlign="right" bottom="25" left="25" width="351"/>
                    </mx:Canvas>

                    <mx:Canvas label="Birthdays" width="100%" height="100%">
                    <mx:Label text="Let us know if we can add your birth month and day" textAlign="right" bottom="25" left="25" />
                    </mx:Canvas>

                    <mx:Canvas label="Phone Use Info" width="100%" height="100%">
                    </mx:Canvas>

                    </mx:TabNavigator>

                    </mx:Panel>

                    <mx:Script>
                    <![CDATA[
                    import flash.external.ExternalInterface;

                    private function setBrowserFocus():void
                    {
                    ExternalInterface.call ("setBrowserFocus");
                    textSearch.setFocus()
                    }
                    ]]>
                    </mx:Script>

                    <actionScript:JavaScript>
                    <![CDATA[
                    function setBrowserFocus()
                    {
                    PhoneDirectory.focus();
                    }
                    ]]>
                    </actionScript:JavaScript>
                    </mx:Application>


                    • 7. Printing A Stinkin Grid!
                      AwesomeDigital3 Level 1
                      I think (GUESS) this is happening because the number of records in the grid is dynamic.

                      So If I set the height of the printing area AND grid before I print them, all of the rows print.

                      // make sure the height of the print data grid and print ares are tall
                      // enough to print all of the rows

                      // Number of Rows * The Height Of The Rows (Plus the height of two extra rows)
                      myPrintArea.height = (individualsArray.length * individualsGridPrint.rowHeight ) + (individualsGridPrint.rowHeight * 2);
                      individualsGridPrint.height = (individualsArray.length * individualsGridPrint.rowHeight) + (individualsGridPrint.rowHeight * 2);


                      If anyone has a more elegant solution, let me know.

                      Thanks
                      Mathias