leiño wrote:
Hi,
i am adding table rows dynamically with javascript. This works fine.
Without seeing the code, we only have your word for that.
The table is inside a div with scrolls, initially with 6 rows:
....
<div style='overflow:auto; width:100%; height:100;'>
<table>
<tr><td>nothing</tr></td>
<tr><td>nothing</tr></td>
<tr><td>nothing</tr></td>
<tr><td>nothing</tr></td>
<tr><td>nothing</tr></td>
<tr><td>nothing</tr></td>
</table>
</div>
....
My problem is that when i add new rows using javascript, the scroll
doesn´t adjust to new table rows, and i can`t navigate for all table,
only for initial rows. Basically, the scroll doesn´t update when i add
new rows
Any idea?
Test it outside the div, if you still can't see the new rows then it is
because you are adding the new rows using appendChild to the table, not
a tableSection element (such as the tbody), which is an IE
requirement[1].
You have two options:
1. use appendChild to add rows to a table Section
element (say a tbody)
2. use table.insertRow()
The following works for me in IE 6, it uses the first method though the
second is probably better in many circumstances:
<div style='overflow:auto; width:100%; height:100;'>
<table>
<tr><td>nothing</tr></td>
<tr><td>nothing</tr></td>
<tr><td>nothing</tr></td>
<tr><td>nothing</tr></td>
<tr><td>nothing</tr></td>
<tr id="lastRow"><td>nothing</tr></td>
</table>
</div>
<button onclick="
var lastRow = document.getElementById('lastRow');
for (var i=0; i<10; i++){
lastRow.parentNode.appendChild(lastRow.cloneNode(t rue));
}
">Add rows</button>
1. Tables will have at least one tbody element whether you include the
tags in your source HTML or not - the tags are optional, the element
isn't.
--
Rob