Flex prints DataGrid content 2.0

Source: Internet
Author: User
<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: vbox xmlns: MX = "http://www.adobe.com/2006/mxml" xmlns = "*"
Backgroundcolor = "# ffffff"
Fontfamily = "simsun" fontsize = "12"
Paddingtop = "50" paddingbottom = "50" paddingleft = "30" paddingright = "30"
Height = "268" width = "748">
<Mx: SCRIPT>
<! [CDATA [
Import MX. Controls. datefield;
Import MX. Core .*
Import MX. Collections. arraycollection;
Import MX. Printing .*;

[Bindable]
Private var pagenumber: Number = 1;

[Bindable]
Private var prodtotal: Number = 0;

[Bindable]
Private var reporttitle: String = "report title ";

[Bindable]
Private var datetime: String = "";

Public Static Var footerheight: Number = 20;
Public Static Var prodindex: number;
Public Static Var prodtotal: Number = 0;

Public static function doprint (datap: object, Title: String, columns: array): void {
VaR printjob: flexprintjob = new flexprintjob ();
If (printjob. Start ()){
VaR theprintview: formprintview = new formprintview ();
Application. application. addchild (theprintview );
Theprintview. reporttitle = title;
Theprintview. datetime = mx. Controls. datefield. datetostring (new date (), "Mm DD, YYYY ");
Theprintview. printdatagrid. Columns = columns;
Theprintview. width = printjob. pagewidth;
Theprintview. Height = printjob. pageheight;
Theprintview. prodtotal = (datap as arraycollection). length;
Theprintview. printdatagrid. dataprovider = datap; // Set Data V
Theprintview. showpage ("single ");
If (! Theprintview. printdatagrid. validnextpage ){
Printjob. addobject (theprintview );
}
Else {
Theprintview. showpage ("first ");
Printjob. addobject (theprintview );
Theprintview. pagenumber ++;
While (true ){
Theprintview. printdatagrid. nextpage ();
Theprintview. showpage ("last ");
If (! Theprintview. printdatagrid. validnextpage ){
Printjob. addobject (theprintview );
Break;
}
Else {
Theprintview. showpage ("Middle ");
Printjob. addobject (theprintview );
Theprintview. pagenumber ++;
}
}
}
Application. application. removechild (theprintview );
}
Printjob. Send ();
}

Private function showpage (pagetype: string): void {
If (pagetype = "first" | pagetype = "Middle "){
Footer. includeinlayout = false;
Footer. Visible = false;
}
If (pagetype = "Middle" | pagetype = "last "){
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>

<! -- The template for the printed page, with the contents for all pages. -->
<Mx: vbox width = "100%" horizontalalign = "Left">
<Mx: Label text = "Page {pagenumber}" color = "# 9e9e9e"/>
<Mx: Label id = "Header" text = "{reporttitle}" fontweight = "bold" fontsize = "21" textalign = "center" width = "100%"/>
<Mx: hrule width = "100%" Height = "1" strokecolor = "#000000"/>
</MX: vbox>

<Mx: printdatagrid id = "printdatagrid" width = "100%" Height = "100%" fontfamily = "simsun" fontsize = "12"/>
<Mx: vbox width = "100%" horizontalalign = "Left" id = "footer">
<Mx: Spacer Height = "100%"/>
<Mx: hrule width = "100%" Height = "1" strokecolor = "#000000"/>
<Mx: hbox width = "100%">
<Mx: Label text = "Total record count: {prodtotal}"/>
<Mx: Spacer width = "100%"/>
<Mx: Label text = "print date: {datetime}"/>
</MX: hbox>
</MX: vbox>

</MX: vbox>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.