Why do I run this on all lines?

1

I'm trying to make every X lines insert a tr with a spacer, more or less I have it, but every time I get to the line to put the space, I put it in all the lines instead of in the line who does the jump.

I'm using this code in javascript and jquery to do it:

<script>
var Infactura_Lineanum = Contarlineas('.Lineas_Infactura');

const Infactura_N_Lineas = 35; //defino cuando quiero que salte la pagina

if (Infactura_Lineanum >= Infactura_N_Lineas) {
++Infactura_Pagina;
var Infactura_Lineanum = 0;
$('tbody').after('<tr class="Espaciador" />hola</tr>');
$('#doc_Infactura').append('<page size="A4" id="Pagina'+Infactura_Pagina+'" class="insertarDoc">'
+'<div id="cabeceradoc">Factura</div>'
+'<div class="logo"><img src="../Scripts/Imagenes/Empresas/<?=$_SESSION['Empresa_Id'];?>/<?=$_SESSION['Empresa_Logo'];?>" alt="<?=$_SESSION['Empresa_Nombre'];?>" /></div>'
+'<div class="marca_agua"><img src="../Scripts/Imagenes/Empresas/<?=$_SESSION['Empresa_Id'];?>/<?=$_SESSION['Empresa_MarcaAgua'];?>" /></div>'
+'<div class="Empresa"><?=$_SESSION['Empresa_Nombre'];?></div>'
+'<div class="Registromercantil"><?=$_SESSION['Empresa_Registro'];?></div>'
+'<div id="Infactura_Totales_'+Infactura_Pagina+'">&nbsp;</div>'
+'<div class="Npagina">Pagina '+Infactura_Pagina+'</div>'
+'</page>');
$('#Infactura_Totales_1').appendTo('#Infactura_Totales_'+Infactura_Pagina); 
}
console.log('Linea Jump '+Infactura_Lineanum);
</script>

The line implied that they are supposed to jump is:

$('tbody').after('<tr class="Espaciador" />hola</tr>');

The design is imitating folios in a4 and what I want is that each time you get to line 35 insert another page and put a spacer between the pages so you do not put text in the footer of the previous page or in the header of the next.

In the following image you see how you have put text in the reserved space. The last two lines should be on page 2 but below.

The product lines are grouped by a tbody since I need them to have 2 tr each line (although I could change it by numbered lists if it's easier).

Last but I think it is not relevant the line counter that I use is this:

function Contarlineas(selector) {
    var height = $(selector).height();
    var line_height = $(selector).css('line-height');
    line_height = parseFloat(line_height)
    var rows = height / line_height;
    return Math.round(rows);
}

The space between folios is always the same, although there can be infinite folios and obviously the size of the folios is also always the same.

    
asked by Killpe 13.01.2017 в 20:38
source

1 answer

2
  

I'm trying to make every X lines insert a tr with a spacer

Then why do you add the spacer to the table instead of the rows?

$('tbody').after('<tr class="Espaciador" />hola</tr>');

Also, you are closing the tr tag incorrectly. Look at />Hola . On the other hand, the jQuery#after function adds a element to the end of it ; that is, before the closing of the label itself (after the children).

If you intend to insert a spacer every X lines, then what you should do is add the spacer after the row that is on the X limit.

$('tbody tr').each(function (i) {
  if (i !== 0 && i % 3 === 0) {
    $(this).after('<tr class="Espaciador"></tr>');
  }
});
    
answered by 15.01.2017 в 14:36