0

I used the following code to print the HTML table in ASP.NET MVC:

function printdiv(printpage) {
    var headstr = "<html><head><title></title></head><body>";
    var footstr = "</body>";
    var newstr = document.all.item(printpage).innerHTML;
    var oldstr = document.body.innerHTML;

    document.body.innerHTML = headstr + newstr + footstr;

    window.print();
    document.body.innerHTML = oldstr;

    return false;
}

This works perfectly and prints my html table as expected. But the problem is if my table have a lot of rows and more than one page it prints just one page and ignores the rest. How can I fix this issue?

  • If you can get other pages by ajax request, then append all results to one page. – Eisa Mar 01 '17 at 09:50
  • @Eisa I can see all rows in MVC view but when it prints, just prints one page and first rows of the table. –  Mar 01 '17 at 09:53
  • Have you gone through with http://stackoverflow.com/questions/10505006/printing-huge-table-with-window-print-only-prints-one-page & http://stackoverflow.com/questions/10845621/window-print-is-not-printing-the-whole-page ? You may find some relevant stuff in those links. – manika Mar 01 '17 at 10:20
  • @manika Yes. I tried all of them already but none of them seem to works for me. –  Mar 01 '17 at 10:47
  • you could use CSS to create a printable view of the page, instead, using media queries. – ADyson Mar 01 '17 at 11:39

0 Answers0