473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

add table rows dynamically and scroll

Hi,
i am adding table rows dynamically with javascript. This works fine.
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?

(I use IE)

Oct 30 '06 #1
7 13453
ASM
leiño a écrit :
Hi,
i am adding table rows dynamically with javascript. This works fine.
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?
easiest (no tested) : an anchor on tfoot

<tfoot id="goal"><tr><th>the end </th></tr></tfoot>
</table>

function addRow() {
blah to add row
location='#goal';
}
Oct 30 '06 #2
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

Oct 30 '06 #3
ASM
RobG a écrit :
<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));
AaRrrgggHhhh ! 10 elements with same id !
}
">Add rows</button>
Oct 31 '06 #4
ASM wrote:
RobG a écrit :
<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));

AaRrrgggHhhh ! 10 elements with same id !
11 actually, and 10 more each time the button is clicked. I'll claim
the streakers' defence - it seemed like a good idea at the time!.

I should have picked a different row to clone (or fixed the dup ids)
but I didn't. :-(
--
Rob

Oct 31 '06 #5
Code is something like this.

<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Documento sin t&iacute;tulo</title>
</head>
<link rel="StyleSheet" href="styles.css" type="text/css" media="all" />
<script language="javascript" type="text/javascript">
var i=0;
function addEstado(){

var elements=document.getElementsByName("estadoExpedie nteVacio");
var fila, clase;
var file_to_change=elements.item(elements.length -4-1);
file_to_change.id="identificador1"+i;

fila=elements.item(elements.length -1); //use last like template
var tabla = document.getElementById('bodyEstado');
tabla.appendChild(fila.cloneNode(true));

var columns=file_to_change.cells;
var td3=columns.item(2);
var td4=columns.item(3);
td3.innerHTML='date'+i;
td4.innerHTML='coments'+i;
i++;

}

</script>

<body>

<table class="estadoExpediente" border=1 cellpadding=0 cellspacing=0
width=100% id="estadoExpediente">
<thead>
<tr>
<td align="center" width="8%">&nbsp;</td>
<td align="center" width="8%">&nbsp;</td>
<td align="center" width="20%">Date</td>
<td align="center" width="64%">Coment</td>
</tr>
</thead>

<tbody>
<tr><td colspan="4" width="100%">
<div style="overflow:auto; width:99%;height:90px;">
<table id="bodyEstado" width="100%">
<tr id="estadoExpedienteVacio">
<td align=center width="7%"><img
src='./Imagenes/borrar.jpg' alt='borrar' ></td>
<td align=center width="8%"><img
src='./Imagenes/lupita.jpg' alt='ver' ></td>
<td align=center width="22%">&nbsp;</td>
<td align=center width="63%">&nbsp;</td>
</tr>
<tr id="estadoExpedienteVacio">
<td align=center><img src='./Imagenes/borrar.jpg'
alt='borrar' ></td>
<td align=center><img src='./Imagenes/lupita.jpg'
alt='ver'></td>
<td align=center>&nbsp;</td>
<td align=center>&nbsp;</td>
</tr>
<tr id="estadoExpedienteVacio">
<td align=center><img src='./Imagenes/borrar.jpg'
alt='borrar' ></td>
<td align=center><img src='./Imagenes/lupita.jpg'
alt='ver'></td>
<td align=center>&nbsp;</td>
<td align=center>&nbsp;</td>
</tr>
<tr id="estadoExpedienteVacio">
<td align=center><img src='./Imagenes/borrar.jpg'
alt='borrar' ></td>
<td align=center><img src='./Imagenes/lupita.jpg'
alt='ver'></td>
<td align=center>&nbsp;</td>
<td align=center>&nbsp;</td>
</tr>
<tr id="estadoExpedienteVacio">
<td align=center><img src='./Imagenes/borrar.jpg'
alt='borrar' ></td>
<td align=center><img src='./Imagenes/lupita.jpg'
alt='ver'></td>
<td align=center>&nbsp;</td>
<td align=center>&nbsp;</td>
</tr>
</table>
</div>
</td></tr>

</tbody>

</table>

<img src='./Imagenes/anadir.jpg'><a class=linkcabecera
href="javascript:addEstado();">Add</a>

</body>
</html>

Oct 31 '06 #6
solved
I needed to put tbody and appendchild to tbody instead of table

Thanks to all

Oct 31 '06 #7

leiño wrote:
Code is something like this.
Use 2 or 4 spaces for indents and manually wrap code at about 70
characters, it will help to prevent autowrapping which almost always
introduces errors. The harder you make it for people to help, the less
likely you are to get any.

<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Documento sin t&iacute;tulo</title>
</head>
<link rel="StyleSheet" href="styles.css" type="text/css" media="all" />
Link elements can only appear in the head element. HTML should use
HTML markup, not XHTML.
<script language="javascript" type="text/javascript">
The language attribute is deprecated, remove it. Keep type.
var i=0;
Why is i global?

function addEstado(){

var elements=document.getElementsByName("estadoExpedie nteVacio");
There are no elements named "estadoExpedienteVacio", you have used it
in multiple id attributes (which creates invalid HTML). You might
think of changing the id attributes to name attributes, which works in
some browsers but is invalid HTML - tr elements can't have a name
attribute.

Use a browser with error reporting turned on (and preferably decent
debugging support - Firefox with Firebug is pretty good), it will let
you know about such basic mistakes.

[...]
>
<table class="estadoExpediente" border=1 cellpadding=0 cellspacing=0
width=100% id="estadoExpediente">
Attribute values that include a % must be quoted:

<URL: http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2 >

[...]
<img src='./Imagenes/anadir.jpg'><a class=linkcabecera
href="javascript:addEstado();">Add</a>
Why use a link when what you really want is a button?
--
Rob

Oct 31 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: rufus | last post by:
I am created a table dynamically and I have wrapped it in a div tag so that the user can scroll the table horizontally ie I have added an overflow property to the div. I dont want the user to be...
2
by: Jure Erznoznik | last post by:
I made a table that shows 20 rows of a table at a time. When the user presses down or up arrow, the table will scroll as necessary filling new rows. But I have a problem with the following code...
7
by: Just Dummy | last post by:
Hi all, I am struggling with a problem for a long time. Problem statement: I have a table and the table can contain n number of rows. i.e., the table rows will be generataed out of a xml...
11
by: Norman L. DeForest | last post by:
Am I misunderstanding the CSS specifications or is Firefox (version 1.0.6) (and Opera) doing the wrong thing? It appears that Firefox 1.0.6 includes the border in width calculations for tables...
1
by: dschectman | last post by:
I have an interesting issue. I need to implement a dynamic table to mimic a select list. Each time you double click from the master list, a row is added to the list of selected items. The list...
2
by: buran | last post by:
Dear ASP.NET Programmers, I have a HTML table (running as server control with the control ID: tblInsertSP). The table has 16 rows with textboxes. Depending on the value of the ddlSPType, which...
0
by: Davey P | last post by:
I have an asp.net table which I am populating with controls dynamically at runtime. The controls themselves get/set values in a datatable which is stored in viewstate over postbacks. Here is...
1
by: wattem | last post by:
Hi, This is my first post on this forum. Hello everyone! I am developing a .Net web app in C# and I am using javascript pretty extensively (to provide a richer experience). My server code...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.