Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill the table with the correct number of rows to fit the page height in different screen resolution ?

Tags:

html

jquery

css

I developed my own Web-Admin behind the front-end. It's a typical Admin with container , one menu-navigation in the left and a body content in the right which shows the result (typically a table) related to the clicked menu item.

What is the best way to get the correct number or rows in the table in order to fit the the body page at 100% ?

In my case, i have seen that the number of tow required to fill the space in the table is different while changing the screen resolution.

I know a quick solution could be to calculate the resolution and get the table populated after knowing the screen resolution. I was wondering if if possible to set the TD or TR height at runtime, based on the screen resolution or somehow else.

Thanks,

like image 908
user1611183 Avatar asked Aug 20 '12 12:08

user1611183


People also ask

How do you fix the height of a row in a table?

Change column and row height To make all rows in the table the same height, select Layout > Distribute Rows. To make all the columns in the table the same height, select Layout > Distribute Columns. Note: In Excel, select Home > Format, and then select Row Height.

How do I change the row height in Powerpoint?

Resize rows, columns, or cells Select the table. The contextual tabs, Table Design and Layout, appear in the ribbon. On the Layout tab, you can specify the custom height and width. To resize specific rows or column, click on a cell and then adjust the row/column.

How do you adjust the height of a table in HTML?

To manipulate the height or width of an entire table, place the size attribute (either "WIDTH=" or "HEIGHT=") within the <TABLE> code. To manipulate individual cells, place the size attribute within the code for that cell.

How do I set the height and width of a row in HTML?

To set the cell width and height, use the CSS style. The height and width attribute of the <td> cell isn't supported in HTML5. Use the CSS property width and height to set the width and height of the cell respectively. Just keep in mind, the usage of style attribute overrides any style set globally.


1 Answers

Here is a fiddle that demonstrates the rendering of rows depending on the browser innerHeight.

HTML

<table id="mytable"></table>​

CSS

td {
  height:20px;
}​

JavaScript

var numberOfRows = Math.floor(window.innerHeight / 20);

var table = document.getElementById("mytable");

function createCell() {
    var cell = document.createElement("td");
    cell.innerText = "Cell";
    return cell;
}

function createRow() {
    var row = document.createElement("tr");
    row.appendChild(createCell())
    return row;
}

for (var i = 0; i < numberOfRows; i++) {
    table.appendChild(createRow());
}​

PS. 1 I've set the height of the cell in CSS, this can be done differently
PS. 2 I've floored the number of rows that fit on the screen. So there will be some empty space at the bottom.

like image 132
Split Your Infinity Avatar answered Nov 15 '22 09:11

Split Your Infinity