Hello Friends
User wants to print the available listitems of a list from a ListViewWebpart in a page and they want to print only those records rather than entire page content (Left Navigation, breadcrumbs etc.) .
So we could not provide the "print" functionality from the browser so we have to include below javascript inside the Content Editor Webpat and now you have print functionality available for ListView webpart only.
Add a content editor webpart on same page where your ListViewWebpart resides.
Write this javascript in the content editor webpart.
<input onclick="javascript:void(PrintWebPart())" type="button" value="Print Page"/> <!-- copy and paste in to a content editor source editor web part --><script language="JavaScript">
<!-- Web Part/region to print -->
var WebPartElementID = "MSO_ContentTable";
//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>
Now you all set for print the listitems of listviewwebpart in SharePoint Pae.
User wants to print the available listitems of a list from a ListViewWebpart in a page and they want to print only those records rather than entire page content (Left Navigation, breadcrumbs etc.) .
So we could not provide the "print" functionality from the browser so we have to include below javascript inside the Content Editor Webpat and now you have print functionality available for ListView webpart only.
Add a content editor webpart on same page where your ListViewWebpart resides.
Write this javascript in the content editor webpart.
<input onclick="javascript:void(PrintWebPart())" type="button" value="Print Page"/> <!-- copy and paste in to a content editor source editor web part --><script language="JavaScript">
<!-- Web Part/region to print -->
var WebPartElementID = "MSO_ContentTable";
//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>
Now you all set for print the listitems of listviewwebpart in SharePoint Pae.
No comments:
Post a Comment