Jump to content
xisto Community
Sign in to follow this  
sanbeand

Print With Flash And Datagrids Without Resizing!

Recommended Posts

hey hi guys..this is a code i used to print data from a datagrid and it is so useful in ur RIAs hope it helps...
cheers!


mybtn.onPress=function(){doPrint(mydg, true)}function doPrint(datagrid:mx.controls.DataGrid, fitPage:Boolean):Void {	if (fitPage == undefined) fitPage = true;	var pj:PrintJob = new PrintJob();	// position of currently visible rows stored	var prev_vPosition:Number = datagrid.vPosition;	var prev_width:Number = datagrid.width;	var prev_height:Number = datagrid.height;	var prev_vScroll = datagrid.vScrollPolicy;	var prev_selectedIndex = datagrid.selectedIndex;	var dgPrintWidth:Number = 0;	var dgPrintHeight:Number = 0;		if (pj.start() != true) {  return;	}	// hide scrollbar for print 	datagrid.vScrollPolicy = "off";	// hide the selection	datagrid.selectedIndex = undefined;		// datagrid width for printing	if (fitPage) {  dgPrintWidth = pj.pageWidth;	} else {  if (prev_width < pj.pageWidth) {  	dgPrintWidth = prev_width;  } else {  	dgPrintWidth = pj.pageWidth;  }	}	// number of rows per view, ignoring fractions (floor)	var rowsPerPage:Number = Math.floor((pj.pageHeight-datagrid.headerHeight)/datagrid.rowHeight);	// total number of pages to be printed, if there are any fractions, have one page for that (ceil)	var total_pages:Number = Math.ceil(datagrid.dataProvider.length/rowsPerPage);	// number of full pages to be printed, ignoring fractions (floor)	var full_pages:Number = Math.floor(datagrid.dataProvider.length/rowsPerPage);	// number of rows on last page if partial	var last_page_rows:Number = 0;	// height of last page if partial	var last_page_height:Number = 0;	// partial last page ? 	if (total_pages != full_pages) {  last_page_rows = datagrid.dataProvider.length - (full_pages*rowsPerPage);  last_page_height = datagrid.headerHeight + (datagrid.rowHeight * last_page_rows);	}	// datagrid height for printing	dgPrintHeight = datagrid.headerHeight + (datagrid.rowHeight * rowsPerPage);	datagrid.setSize(dgPrintWidth, dgPrintHeight);  	for (var i = 0; i<total_pages; i++) {  // if last page and partial - resize grid  if ((i == total_pages - 1) && (last_page_rows > 0)) {  	datagrid.setSize(dgPrintWidth, last_page_height);  }  // move the visible row position.  datagrid.vPosition = i*rowsPerPage;  // size box relative to the grid  var b = {xMin:0, xMax:datagrid.width, yMin:0, yMax:datagrid.height};  if (!fitPage && prev_width < pj.pageWidth) {  	var x0 = (pj.pageWidth - prev_width) / 2;  	b = {xMin:(-x0), xMax:(datagrid.width+x0), yMin:0, yMax:datagrid.height};  }  pj.addPage(datagrid, B);	}	pj.send();	delete pj;	// previous scrollPolicy	datagrid.vScrollPolicy = prev_vScroll;	// position of currently visible rows restored	datagrid.setSize(prev_width, prev_height);	datagrid.selectedIndex = prev_selectedIndex;	datagrid.vPosition = prev_vPosition;}

Notice from BuffaloHELP:
Last caution note. I PMed you about using CODE tags. You ignored it. Credits reduced.

Edited by BuffaloHELP (see edit history)

Share this post


Link to post
Share on other sites

Print script is usefull for me

Print With Flash And Datagrids Without Resizing!

 

Hey fri thanks for this useful script, its very useful

 

-reply by Rahul Kathet

Share this post


Link to post
Share on other sites

A title

Print With Flash And Datagrids Without Resizing!

 

Hello,

 

Useful truely this function. She is really amazing for anything concerning the printing of the Datagrid.

 

But I have a question is it possible to print a title to the table.

 

Thanks a lot for this work.

 

Aj

 

-reply by Anje

Share this post


Link to post
Share on other sites

Great work

Print With Flash And Datagrids Without Resizing!

 

Useful truely this function. She is really amazing for anything concerning the printing of the Datagrid.

 

But I have a question is it possible to print a title to the table.

 

Thank's a lot

 

-reply by Anje

Share this post


Link to post
Share on other sites
Thank you Print With Flash And Datagrids Without Resizing!I found this Flash Action Script very handy. I put my DataGrid on a new movie clip instance so I could add titles.This worked well until I added a custom cellrender to load images into a column. The images only show up on the printed page if they are shown on the stage.To get around this I had to put my movie clip instance off the stage and make the size bigger than the print page. Now it works well, I have title and images printing on multiple pages.I then added a new datagrid instance onto the stage and set its dataprovider so it is the same as the off stage datagrid. Users can now browse and print the data and images.Cheers,Paul.http://forums.xisto.com/no_longer_exists/ by PaulKeywords:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.