1

I've been using Sharepoint lists as a reporting method, recently I was requested to print out my lists just the way they looked, with sorting and grouping and filters applied. I've also enabled the 'Sum' feature on some of my lists to sum up grouped items in certain columns.

I've looked at several tutorials but they were all made for Sharepoint 2010, while Sharepoint 2013 does not allow its contents to be opened in a popup window...

Has anyone else had similar problems or a work around?

Thanks, Fan

2

it is possible to print a section of the page with the help of some javascript

Below code sample may be helpful for you to get started:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Untitled Page</title>

    <script language="javascript" type="text/javascript">
        function printDiv(divID) {
            //Get the HTML of div
            var divElements = document.getElementById(divID).innerHTML;
            //Get the HTML of whole page
            var oldPage = document.body.innerHTML;

            //Reset the page's HTML with div's HTML only
            document.body.innerHTML = 
              "<html><head><title></title></head><body>" + 
              divElements + "</body>";

            //Print Page
            window.print();

            //Restore orignal HTML
            document.body.innerHTML = oldPage;


        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div id="printablediv" style="width: 100%; background-color: Blue; height: 200px">
        Print me I am in 1st Div
    </div>
    <div id="donotprintdiv" style="width: 100%; background-color: Gray; height: 200px">
        I am not going to print
    </div>
    <input type="button" value="Print 1st Div" onclick="javascript:printDiv('printablediv')" />
    </form>
</body>
</html> 

Code Project Reference

SharePoint 2013 allows list forms to be opened in a dialog box by changing this setting: List Settings>Advanced settings> Launch forms in a dialog? Yes/No.

  • Thanks Harry! I will try this out and let you know if it works or not~ – user2686465 Dec 10 '15 at 22:41
  • Hi Harry, I have pasted the provided code into a content editor webpart and tried to print the sample page... worked perfectly, this must be a viable solution but I am not very tech-savvy and the instruction article did not give much explanation on how to alter the code. Would you be so kind to provide me with some more detail on how to use this code? I have my list in another webpart on the same page, I'd like to print the current view being displayed. How do I get that div id value and where do I pass these values to? Thanks again! – user2686465 Dec 14 '15 at 21:41
  • To get the id of the element that shows your view you will need to look at the source of the page/ select "inspect element" by right clicking on the view tilte. From there you can make note of the element that contains your view and replace the printablediv with the id of your view in the onclick event of the button. – HarryB Dec 17 '15 at 12:42

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.