473,842 Members | 1,680 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Column order reversed when adding rows to a dynamic table

This appears to be a feature of IE JavaScript. I am running IE 6.0
with the latest patches from Microsoft. Are there any workarounds
other than re-coding the source HTML to place all the non-visible
columns at the front?

I have a page with a dynamic table. The table has some visible columns
and some non-visible columns. The style "hide" is .hide {
display:none; }

<table id="SelectedLis t">
<tr class="columnhe ader">
<td>Value</td>
<td class="hide">Co de</td>
<td class="hide">Ty pe</td>
</tr>
</table>

When I add rows to this table, the order of the columns depends on
whether the hidden columns are at the beginning or end of the row.
Here is the resulting HTML for the table. Note how in the second case,
the order of the last two columns is reversed even though the function
adds them in order: column1, column2, column3.

<TBODY>
<TR class=columnhea der>
<TD class=hide>Code </TD>
<TD class=hide>Type </TD>
<TD class="">Value</TD></TR>
<TR>
<TD class=hide>colu mn1</TD>
<TD class=hide>colu mn2</TD>
<TD>column3</TD></TR>
<TR>
<TD>column1</TD>
<TD class=hide>colu mn3</TD>
<TD class=hide>colu mn2</TD></TR></TBODY>

addItem('Select edList');
function addItem(gridID)
{
var grid = document.getEle mentById(gridID );

// Test #1: first two columns hidden, las column visible
var row1 = grid.insertRow( grid.rows.lengt h);
for (i=0;i<3;i++)
{
cell = row1.insertCell (i);

if (i==0) cell.innerHTML = "column1"; //document.test.c ode.value;
else if (i==1) cell.innerHTML = "column2";
//document.test.c ateg.value;
else cell.innerHTML = "column3"; //document.test.v al.value;

if (i!=2) cell.className = "hide";
}

// Test #2: first column visible, last two hidden
var row2 = grid.insertRow( grid.rows.lengt h);
for (i=0;i<3;i++)
{
cell = row2.insertCell (i);

if (i==0) cell.innerHTML = "column1"; //document.test.c ode.value;
else if (i==1) cell.innerHTML = "column2";
//document.test.c ateg.value;
else cell.innerHTML = "column3"; //document.test.v al.value;

if (i!=0) cell.className = "hide";
}

//document.test.t blhtml.value = grid.innerHTML;
alert(grid.inne rHTML);
}

Jan 23 '06 #1
2 4969
ds********@yaho o.com wrote:
This appears to be a feature of IE JavaScript. I am running IE 6.0
with the latest patches from Microsoft. Are there any workarounds
other than re-coding the source HTML to place all the non-visible
columns at the front?

I have a page with a dynamic table. The table has some visible columns
and some non-visible columns. The style "hide" is .hide {
display:none; }

<table id="SelectedLis t">
<tr class="columnhe ader">
<td>Value</td>
<td class="hide">Co de</td>
<td class="hide">Ty pe</td>
</tr>
</table>

When I add rows to this table, the order of the columns depends on
whether the hidden columns are at the beginning or end of the row.
Here is the resulting HTML for the table. Note how in the second case,
the order of the last two columns is reversed even though the function
adds them in order: column1, column2, column3.
Yup, same result here. You can fix two ways: add the cells in one loop,
then hide them using a separate loop, or use createElement and add them
that way (see below):

<TBODY>
<TR class=columnhea der>
<TD class=hide>Code </TD>
<TD class=hide>Type </TD>
<TD class="">Value</TD></TR>
<TR>
<TD class=hide>colu mn1</TD>
<TD class=hide>colu mn2</TD>
<TD>column3</TD></TR>
<TR>
<TD>column1</TD>
<TD class=hide>colu mn3</TD>
<TD class=hide>colu mn2</TD></TR></TBODY>

addItem('Select edList');
function addItem(gridID)
{
var grid = document.getEle mentById(gridID );

// Test #1: first two columns hidden, las column visible
var row1 = grid.insertRow( grid.rows.lengt h);
for (i=0;i<3;i++)
{
cell = row1.insertCell (i);

if (i==0) cell.innerHTML = "column1"; //document.test.c ode.value;
else if (i==1) cell.innerHTML = "column2";
//document.test.c ateg.value;
else cell.innerHTML = "column3"; //document.test.v al.value;
The whole if..else bit can be replaced with:

cell.appendChil d(document.crea teTextNode("col umn" + (i+1)));


if (i!=2) cell.className = "hide";
}

// Test #2: first column visible, last two hidden
var row2 = grid.insertRow( grid.rows.lengt h);

Replace from here:
for (i=0;i<3;i++)
{
cell = row2.insertCell (i);
if (i==0) cell.innerHTML = "column1"; //document.test.c ode.value;
else if (i==1) cell.innerHTML = "column2";
//document.test.c ateg.value;
else cell.innerHTML = "column3"; //document.test.v al.value;

if (i!=0) cell.className = "hide";
}
to here with either the following createElement solution:

for (var i=0; i<3; i++)
{
cell = document.create Element('td');
cell.appendChil d(document.crea teTextNode("col umn" + (i+1)));
row2.appendChil d(cell);
if (i!=0) cell.className = "hide";
}
Or this 2 loop solution:

for (var i=0; i<3; i++)
{
cell = row2.insertCell (i);
cell.appendChil d(document.crea teTextNode("col umn" + (i+1)));
}

for (var j=1, len=row2.length ; j<len ; ++j){
row2.cells[j].className = "hide";
}


//document.test.t blhtml.value = grid.innerHTML;
alert(grid.inne rHTML);
}


--
Rob
Jan 23 '06 #2
Thanks for the tip.

Jan 31 '06 #3

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

Similar topics

1
9914
by: Not Me | last post by:
Hi, I'm sure this is a common problem.. to create a single field from a whole column, where each row would be separated by a comma. I can do this for a specified table, and column.. and I've created a function using VBA to achieve a more dynamic (and very slow) solution.. so I would like to implement it using a user defined function in sql server. The problems I'm facing are, that I can't use dynamic sql in a
2
1600
by: muzamil | last post by:
Hi Your help for the following query will be highly apprecaited. I've wasted alot of time on it. Data definition is at the bottom. Thanks -----------------------------------
5
50684
by: Robert Stearns | last post by:
Either I missed something, or ALTER TABLE does not have this capability. Is there any way of doing it except DROPping all constraints which mention this table, EXPORTing the data, DROPping the table, reCREATEing the table without the 'NOT NULL property, reCREATEing the INDEXes, reloading the data, redefining all of DROPped constraints reCREATE the view which were marked inactive by the above.
2
23968
by: Joe | last post by:
Hi All, I am new to using the Access DB and I need some help if someone is able to give it to me. What I want to do is get the names of the columns of certain tables. Not the data in the table but the table column names. I've seen other posts that suggest using the SQL command DESCRIBE but I can't get it to work for some reason. Other posts have code samples but they're written in VB which I am not familiar with. I
16
2496
by: Geoff Jones | last post by:
Hi Can anybody help me with the following, hopefully simple, question? I have a table which I've connected to a dataset. I wish to add a new column to the beginning of the table and to fill it with incremental values e.g. if the tables looks like this: 23 56
9
4050
by: cavassinif | last post by:
I need to dynamic select a column in which insert a vale based on a parameter value, I have this code, but it throws an incorrect syntax error. How do I dinamically select a column to insert based on a parameter? Create PROCEDURE dbo.UpdateDetalleOT ( @eotId int, )
6
2437
by: Steve | last post by:
I realize that this probably isn't a best practice, but I'm working with legacy code that has a query stored in one column of a table. Because the queries vary, the JSP page that selects a query and runs it cannot add any additional information (like a WHERE clause). I need to add a few more records to the the table, and would like the query to include a value from another field in the current row in a WHERE clause -- something like...
13
22073
by: annecarterfredi | last post by:
I'd like to add a new column to an existing table at a specific column location... Existing table definition: MyTable(Col1, Col2, Col3) I want to add a new column in MyTable and the new column's position is in between Col2 and Col3: MyTable(Col1, Col2, New_Column, Col3)
4
10690
tjc0ol
by: tjc0ol | last post by:
Hi guys, I'm a newbie in php and I got error in my index.php which is: 1054 - Unknown column 'p.products_id' in 'on clause' select p.products_image, pd.products_name, p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from products_description pd,...
0
9715
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10612
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10314
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9453
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7858
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5696
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4499
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3145
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.