Hi all, I have data in AdvancedDataGrid and want to print it. If I only print 
data is provided by Results(ArrayCollection), it will print ok. But I want to 
print data is showed in AdvancedDataGrid because it is grouped by some grouping 
field. 

Here is my old code, it  print data in multi page ok

FormPrintView.mxml copmponent

<?xml version="1.0"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"; 
    backgroundColor="#FFFFFF"
    paddingTop="30" paddingBottom="30" paddingLeft="30">
    <mx:PrintAdvancedDataGrid id="myDataGrid" width="95%" height="100%">
        <mx:columns>
                <mx:AdvancedDataGridColumn headerText="Index" dataField="Index" 
width="120"/>
            <mx:AdvancedDataGridColumn headerText="Data" dataField="Data"/>
            <mx:AdvancedDataGridColumn headerText="Note" dataField="Note" 
width="160"/>
        </mx:columns>
    </mx:PrintAdvancedDataGrid>    
</mx:VBox>

Main.mxml

...
private function openNewWindow():void{

var newWindow:Window = new Window;
//add a datagrid to the new window                              
var client:AdvancedDataGrid = new AdvancedDataGrid;
client.dataProvider = Results; // Results is ArrayCollection
var col1:AdvancedDataGridColumn = new AdvancedDataGridColumn();
col1.dataField = "Index";
col1.headerText = "Index";
col1.width = 120;
var col2:AdvancedDataGridColumn = new AdvancedDataGridColumn();
col2.dataField = "Data";
col2.headerText = "Data";
var col3:AdvancedDataGridColumn = new AdvancedDataGridColumn();
col3.dataField = "Note";
col3.headerText = "Note";
col3.width = 160;
client.groupedColumns = [col1,col2,col3];                       
                                
var mygroup:GroupingCollection=new GroupingCollection();
mygroup.source = Results
var group:Grouping = new Grouping();
var gf:GroupingField = new GroupingField("Index");
gf.numeric = true;      
gf.groupingFunction = utils.groupFunction; // private function
gf.groupingObjectFunction = utils.groupObjFunction; // private function
group.fields = [gf];
mygroup.grouping = group;
mygroup.refresh();
client.dataProvider = mygroup;
client.validateNow();
client.displayItemsExpanded = true;
newWindow.addChild(client);
                                
                                                                
var btn2:Button = new Button();
btn2.label = "Print";
                                btn2.addEventListener(MouseEvent.CLICK, 
function(evt:MouseEvent):void
{
  var printJob:FlexPrintJob = new FlexPrintJob();                   
  if (printJob.start()) 
  {
    var thePrintView:FormPrintView = new FormPrintView();
    addChild(thePrintView);
    thePrintView.width=printJob.pageWidth;                            
    thePrintView.height=printJob.pageHeight;            
    thePrintView.myDataGrid.dataProvider = Results
                                                                

    if(!thePrintView.myDataGrid.validNextPage)
    {
      printJob.addObject(thePrintView);
    }
    else
    {
      printJob.addObject(thePrintView);
      while(true)
      {
        thePrintView.myDataGrid.nextPage();
        if(!thePrintView.myDataGrid.validNextPage) 
        {
          printJob.addObject(thePrintView);
          break;
        }
        else
        {                                        
          printJob.addObject(thePrintView);                           
        }
      }
    }
    removeChild(thePrintView);
    printJob.send();
  }
  else
    Alert.show("Not connect to Printer", "Message", Alert.OK, newWindow);       
                    
});

newWindow.addChild(btn2);                               
//show the new window
newWindow.open();
newWindow.activate();

}

Now I want print data is provide by AdvandcedDataGrid and I change code

thePrintView.myDataGrid.dataProvider = Results

-> thePrintView.myDataGrid.dataProvider = client.dataProvider

But the code doesn't run. I run in debug mode and see:

client.dataProvider = (mx.collections.HierarchicalCollectionView) 
mx.collections.HierarchicalCollectionView (@493f281)  
thePrintView.myDataGrid.dataProvider = null. 

It print only first page of AdvancedDataGrid. I don't know why?
Any one can help me what is false?

Hai Anh



Reply via email to