javascript - printing Bootstrap modal data - Stack Overflow

I have a bootstrap modal which contains table, and table consist of multiple pages, when i print the mo

I have a bootstrap modal which contains table, and table consist of multiple pages, when i print the modal it only prints the part of modal that is unscrolled, means it looks like on printing the page JS take the screenshot of modal window. Code i tried:

@media print {
    .modal-body { 
             width: auto;
             height: auto;
             overflow: visible !important;  
    }
    
        body.modal-open {
        visibility: hidden;
    }

    body.modal-open .modal .modal-header,
    body.modal-open .modal .modal-body {
        visibility: visible; 
    }
    .modal-footer{
        visibility:hidden;
    }
    .modal-header{
        visibility:hidden;
    }
}

This is the image i obtained after using jquery printThis library

I have a bootstrap modal which contains table, and table consist of multiple pages, when i print the modal it only prints the part of modal that is unscrolled, means it looks like on printing the page JS take the screenshot of modal window. Code i tried:

@media print {
    .modal-body { 
             width: auto;
             height: auto;
             overflow: visible !important;  
    }
    
        body.modal-open {
        visibility: hidden;
    }

    body.modal-open .modal .modal-header,
    body.modal-open .modal .modal-body {
        visibility: visible; 
    }
    .modal-footer{
        visibility:hidden;
    }
    .modal-header{
        visibility:hidden;
    }
}

This is the image i obtained after using jquery printThis library

Share Improve this question edited Jul 25, 2020 at 15:01 Sybghatallah Marwat asked Jul 25, 2020 at 13:33 Sybghatallah MarwatSybghatallah Marwat 3121 gold badge3 silver badges18 bronze badges 2
  • Take a look at the printThis plugin for jQuery. – Fullslack Commented Jul 25, 2020 at 14:11
  • it didnt helped so much, i am attaching the photo to my question which was obtained after using printThis – Sybghatallah Marwat Commented Jul 25, 2020 at 15:00
Add a ment  | 

1 Answer 1

Reset to default 4

Print Bootstrap Modal Body with jQuery

Make a print function that removes everything. Then append the modal body to the main content after printing your data and append everything back where it belongs. It may not be a perfect solution if you have a more significant site, although this should be enough to figure out how to implement this in your situation.

$(document).on("click", ".print", function () {
  const section = $("section");
  const modalBody = $(".modal-body").detach();

  const content = $(".content").detach();
  section.append(modalBody);
  window.print();
  section.empty();
  section.append(content);
  $(".modal-body-wrapper").append(modalBody);
});
.modal-body-wrapper {  // Make sure that you have a wrapper.
  overflow-y: scroll;  // It allows scrolling, but the body is printed
  height: 60vh;        // in full.
}

See Demo : https://jsfiddle/hexzero/5Lzocqpn/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744401879a4572429.html

相关推荐

  • javascript - printing Bootstrap modal data - Stack Overflow

    I have a bootstrap modal which contains table, and table consist of multiple pages, when i print the mo

    7天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信