0

Folks,

I need to be able to print a full list. By using the quoted code below, a new window appears with clear formatting and my browsers print button appears, however, as I need to 'throttle' how many records appear at once when users are viewing the list, the print window only shows the throttled amount of records for printing, which in this case is 30.

I need to be able to show only 30 records, hit the print button (via the afore mentioned code) but then print the full list.

<center><input onclick="javascript:void(PrintWebPart())" type="button" value="Print 
List"/></center>

<script language="JavaScript">

//Controls which Web Part or zone to print
var WebPartElementID = "WebPartWPQ2";
//Function to print Web Part
function PrintWebPart()
{
var bolWebPartFound = false;
if (document.getElementById != null)
{
//Create html to print in new window
var PrintingHTML = '<HTML>\n<HEAD>\n';
//Take data from Head Tag
if (document.getElementsByTagName != null)
{
var HeadData= document.getElementsByTagName("HEAD");
if (HeadData.length > 0)
PrintingHTML += HeadData[0].innerHTML;
}
PrintingHTML += '\n</HEAD>\n<BODY>\n';
var WebPartData = document.getElementById(WebPartElementID);
if (WebPartData != null)
{
PrintingHTML += WebPartData.innerHTML;
bolWebPartFound = true;
}
else
{
bolWebPartFound = false;
alert ('Cannot Find Web Part');
}
}
PrintingHTML += '\n</BODY>\n</HTML>';
//Open new window to print
if (bolWebPartFound)
{
var PrintingWindow = window.open("","PrintWebPart",
"toolbar,width=800,height=600,scrollbars,resizable,menubar");
PrintingWindow.document.open();
PrintingWindow.document.write(PrintingHTML);
// Open Print Window
PrintingWindow.print();
}
}

</script>

Any helpful is greatfully appreciated.

thanks.

1
  • What about creating another view with no throttling and apply this on that page? – Dave Paylor Jan 23 '14 at 9:16
0

i am confused asto what you want doing! so you want to show the throttled ammount as printable but you actually want to print the full list?

how about do what your doing at the moment, but dont print! you can then call this JS function to create an iframe that gets the full list from its url:

function printPage(newUrlPrint) 
{
        var div = document.getElementById("aspnetForm");
        div.innerHTML = '<iframe src="' + newUrlPrint + '" onload="this.contentWindow.print(); window.location.reload();"></iframe>';

}

ok to explain what is going on..... so you ran your js functions to show a new page and display your 30 records. now once that is done you can call the method above.... the first part is its passing the url to the full list called newUrlPrint.

the code is than going to look for the html tag with the id to use:

var div = document.getElementById("aspnetForm");

on the default form you have controls... in my case i want to update most of the page to show the full list.... for you, when creating the page you can create a new div element to add the iframe so the user will still see the 30 records rather than the full list!

so say iv added a div that is invisible on the new page and its currently empty:

<div id="printTempLocation" visibile="false">
</div>

the js code runs and then calls the funtion

function printPage(newUrlPrint) 
{
        var div = document.getElementById("printTempLocation");
        div.innerHTML = '<iframe src="' + newUrlPrint + '" onload="this.contentWindow.print(); window.location.reload();"></iframe>';

}

now the last part is adding within the div an iframe, the iframe will go to the give url and on loading it will print only within the iframe which should be the full list:

the url will be somthing on the lines of:

http://yoursite.com/subsite/Lists/listname/DispForm.aspx?ID=listitemid&Source=http://yoursite.com/subsite/Lists/listname/AllItems.aspx&IsDlg=1";

the url broken down, anything in bold needs changing:

your main site / your subsite /lists/ list name goes here /DispForm.aspx?ID= list item id &Source= your main site / your subsite /lists/ list name goes here / AllItems.aspx&IsDlg=1

the above is for a list item like a row with all fields to print! for a full list only do:

http://yoursite.com/subsite/Lists/listname/AllItems.aspx

if you dont like the way it looks than create a new view and use that url!

also like to note that the js function is only going to print what is in the div that you specified the iframe to be in (print only what is in the iframe) , when user completes it refreshes the page, you could remove window.location.reload(); so that it doesnt or add in some code to close it if you want?

4
  • Thanks for your response. If I could clarify what is currently happening, I'd say that when I open a page, lets call it stock inventory. A web part is displayed showing me a custom list of stock that I have. However, due to the inventory potentially containing several thousand items, the view is 'throttled' to only show 30 records at a time, which saves on the page suffering lag when displaying records. – daryl Jan 23 '14 at 12:28
  • EDIT: To clarify what is happening, when I open a page, lets call it stock inventory, a web part is displayed showing me a custom list. However, due to the list potentially containing hundreds of items, the view is 'throttled' to only show 30 records at a time. Using the code shown above, I have created a 'print' button which opens a new window which displays only the web part for a cleaner print. Problem is that the print window only shows the 30 records. I'd like to change that so the view remains as showing 30 records but the print window shows ALL records. – daryl Jan 23 '14 at 12:42
  • @daryl you can't just make a special print view which shows all records? – Nicole Jan 24 '14 at 21:45
  • yes that's what the js iv shown does! you just need the url to the list and the div to update that already exists on the page, once printed it refreshes page to go back to normal and only prints the info within the iframe – Ali Jafer Jan 24 '14 at 23:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.