3
i have an HTML page that works as report page.
It has a table that is fed by the database, however when there are many rows in the query then the HTML table gets very large. It turns out that because of this, if I try to print the page, the last row of the table at the bottom of the page will be "food" by dividing the paper.
I would like to allow javascript to create empty lines at each height range of the table.
For example, I could specify that every 500 pixels high in the table, javascript should insert an empty row.
However, I don’t know how to deploy this.
Any suggestions?
Attempts...
<html>
<head>
<script src="jquery.min.js"></script>
<script type='text/javascript'>
$(document).ready(function(){
var altura = 0;
$('#tabela tr').each(function(index, element){
altura += $(this).height();
if (altura > 100) {
$(this).style.pageBreakBefore="always";
altura = 0;
}
});
});
</script>
<style>
@media print {
tr.page-break {
display: block;
page-break-before: always;
}
}
</style>
</head>
<body>
<table id='tabela' border=1px;>
<tr><td>Linha1</td></tr>
<tr><td>Linha2</td></tr>
<tr class='page-break'><td>Linha3</td></tr>
<tr><td>Linha4</td></tr>
<tr><td>Linha5</td></tr>
<tr><td>Linha6</td></tr>
<tr><td>Linha7</td></tr>
<tr><td>Linha8</td></tr>
<tr><td>Linha9</td></tr>
<tr><td>Linha10</td></tr>
<tr><td>Linha11</td></tr>
<tr><td>Linha12</td></tr>
<tr><td>Linha13</td></tr>
<tr><td>Linha14</td></tr>
<tr><td>Linha15</td></tr>
<tr><td>Linha16</td></tr>
<tr><td>Linha17</td></tr>
<tr><td>Linha18</td></tr>
<tr><td>Linha19</td></tr>
<tr><td>Linha20</td></tr>
<tr><td>Linha21</td></tr>
<tr><td>Linha22</td></tr>
<tr><td>Linha23</td></tr>
<tr><td>Linha24</td></tr>
<tr><td>Linha25</td></tr>
<tr><td>Linha26</td></tr>
<tr><td>Linha27</td></tr>
<tr><td>Linha28</td></tr>
<tr><td>Linha29</td></tr>
<tr><td>Linha30</td></tr>
<tr><td>Linha31</td></tr>
<tr><td>Linha32</td></tr>
<tr><td>Linha33</td></tr>
<tr><td>Linha34</td></tr>
<tr><td>Linha35</td></tr>
<tr><td>Linha36</td></tr>
<tr><td>Linha37</td></tr>
</table>
</body>
</html>
And...
<html>
<head>
<script src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('td').click(function () {
var indice = $(this).index() + 1;
$('tr').each(function (index, element) {
$(this).children('td:nth-child(' + indice + ')').toggleClass('no-print');
});
});
var altura = 0;
$('#tabela tr').each(function(index, element){
altura += $(this).height();
if (altura > 100) {
$('<tr><td colspan="' + $(this).children('td').size() + '"><span class="no-print">quebra de pagina</span></td></tr>').insertBefore($(this));
altura = 0;
}
});
});
</script>
<style>
.no-print {
opacity:.5;
}
@media print {
.no-print {
display:none;
}
}
</style>
</head>
<body>
<table id="tabela">
<tr>
<td>Coluna 1</td>
<td>Coluna 2</td>
<td>Coluna 3</td>
<td class="no-print">Coluna 4</td>
</tr>
<tr>
<td>Coluna 1</td>
<td>Coluna 2</td>
<td>Coluna 3</td>
<td class="no-print">Coluna 4</td>
</tr>
<tr>
<td>Coluna 1</td>
<td>Coluna 2</td>
<td>Coluna 3</td>
<td class="no-print">Coluna 4</td>
</tr>
<tr>
<td>Coluna 1</td>
<td>Coluna 2</td>
<td>Coluna 3</td>
<td class="no-print">Coluna 4</td>
</tr>
<tr>
<td>Coluna 1</td>
<td>Coluna 2</td>
<td>Coluna 3</td>
<td class="no-print">Coluna 4</td>
</tr>
<tr>
<td>Coluna 1</td>
<td>Coluna 2</td>
<td>Coluna 3</td>
<td class="no-print">Coluna 4</td>
</tr>
<tr>
<td>Coluna 1</td>
<td>Coluna 2</td>
<td>Coluna 3</td>
<td class="no-print">Coluna 4</td>
</tr>
<tr>
<td>Coluna 1</td>
<td>Coluna 2</td>
<td>Coluna 3</td>
<td class="no-print">Coluna 4</td>
</tr>
<tr>
<td>Coluna 1</td>
<td>Coluna 2</td>
<td>Coluna 3</td>
<td class="no-print">Coluna 4</td>
</tr>
<tr>
<td>Coluna 1</td>
<td>Coluna 2</td>
<td>Coluna 3</td>
<td class="no-print">Coluna 4</td>
</tr>
<tr>
<td>Coluna 1</td>
<td>Coluna 2</td>
<td>Coluna 3</td>
<td class="no-print">Coluna 4</td>
</tr>
<tr>
<td>Coluna 1</td>
<td>Coluna 2</td>
<td>Coluna 3</td>
<td class="no-print">Coluna 4</td>
</tr>
<tr>
<td>Coluna 1</td>
<td>Coluna 2</td>
<td>Coluna 3</td>
<td class="no-print">Coluna 4</td>
</tr>
<tr>
<td>Coluna 1</td>
<td>Coluna 2</td>
<td>Coluna 3</td>
<td class="no-print">Coluna 4</td>
</tr>
<tr>
<td>Coluna 1</td>
<td>Coluna 2</td>
<td>Coluna 3</td>
<td class="no-print">Coluna 4</td>
</tr>
<tr>
<td>Coluna 1</td>
<td>Coluna 2</td>
<td>Coluna 3</td>
<td class="no-print">Coluna 4</td>
</tr>
</table>
</body>
</html>
In the first example this generating an Exception: "Unable to define the indefinite or null reference 'pageBreakBefore' property" use jquery to define the class:
$(this).addClass('page-break');
– Jader A. Wagner
The second example copied and pasted on the fiddle, works normally...
– Jader A. Wagner