3
My web page is powered by database data and has a report format, with data inserted into an html table. The point is that the database has tables with many columns, which sometimes make the page very large by replicating the structure of the table within the page and consequently prevent printing from falling on paper.
I developed a method in javascript/jquery, responsible for hiding columns until they fill a predetermined space. For example, I can force the table to be 1500pixels wide, so the method eliminates columns until the table occupies this space.
However, it does not happen well... because in the beginning, the columns will be hidden and the table width will decrease, but after a while, the columns will be removed but the table continues to occupy the same size, because the columns will increase in width.
if(dimensao() == false){
wt = document.getElementById('tabela').offsetWidth;
col = document.getElementById('tabela').rows[0].cells.length;
aux = 0;
for(col;col>=2;col--){
if(wt>1500){
$('td:nth-child(' + col + ')').hide();
//alert('Coluna ' + col + ' Removida! - Largura : ' + wt);
wt = document.getElementById('tabela').offsetWidth;
aux++;
}
}
alert(aux + ' Colunas tiveram de ser removidas!.');
}
});
I wonder, how to hide the columns and prevent the remaining columns from increasing their own width, thus making the table decrease its length.
And can you erase columns inexcusably? or have columns to "keep"? I suggest having the column inside a wrapper and giving an overflow: scroll. Then take out columns until the width of the table is less than or equal to the wrapper.
– Sergio