Call function javascript

2

I have a VB application that builds HTML pages fed by database data. So I can issue reports by inserting the data into an HTML table.

It turns out that sometimes the table becomes too large to be printed and need to remove some columns so that the table structure fits right into the paper. You would then need to hide or remove columns when the table exceeds a certain width. But this action should occur in the onload event, since my table is written by a VB program and then the code in JS only takes effect when the page is opened by the user.

As I would then, to remove the columns so that my table always has the width of 2400px for example.

?!?! could you help me?

    
asked by anonymous 11.08.2014 / 15:13

1 answer

4

You can use CSS to delete the columns only on the print:

CSS:

.no-print {
    opacity:.5;
}
@media print {
    .no-print {
        display:none;
    }
}

HTML:

<table>
<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>

Result:

ImadeajqueryadaptationtoAddorRemovetheclassbyclickingthecolumn:

jquery:

$('td').click(function(){varindice=$(this).index()+1;$(this).parents('table').find('td:nth-child('+indice+')').toggleClass('no-print');});

jsfiddledemo: link

    
11.08.2014 / 15:52