Jump to content

dynamic content in tables


garry27

Recommended Posts

i have a table and two buttons which allow me to move rows up and down a html table.  the code i've used to implement is borrowed from http://friedcellcollective.net/js/SortedTable/Event.js and
http://friedcellcollective.net/js/SortedTable/SortedTable.js

the code in the two scripts use the DOM to retrieve elements from a html table and i haven't had much trouble implementing it to existing html content. however if i change the dom using javascript like when i add new rows to the table using insertRow, the new rows do not inherit the behaviour or presentation. how can i fix it so that new rows inherit the same behaviour of the rows generated with html?
Link to comment
Share on other sites

as far as i can tell, the scripts are designed so that they reference the tables by id or if tagname has class 'sort' then they do whatever with what was outputed to the webpage. if you make changes to the dom however, like adding a new row-it treats these differently to the html in the webpage.

a sample of the html table ouputted:

[code]<table id='pubList' class="sorted" width="300px" border="1">
<thead>
  <tr>
    <th  id='PubID' >PubID</th>
    <th  id='Pub' >Pub</th>
    <th  id='Postcode'>Postcode</th>
  </tr>
</thead>
<tbody>
  <tr id='table1_row1'>
    <td>tt</td>
    <td>tt</td>
    <td>tt</td>
  </tr>
  <tr>
    <td>rr</td>
    <td>rr</td>
    <td>rr</td>
  </tr>
  <tr>
    <td>ee</td>
    <td>ee</td>
    <td>ee</td>
  </tr>
 
</table>[/code]

Link to comment
Share on other sites

that's what i thought, but i don't understand enough of the code to figure it out.

i'm now going to update the rows on the table as needed rather than insert and delete new rows. this should work just as well if i use a bit of css to hide the empty rows. 

..i'm trying to loop through a table to find the next row with empty td elements. i've put alert events along the way to try and debug it (normally i'd have (txt=='') in the if control structure.

the first alert popup says [object text], the second says undefined. how do i change the code so nextEmptyRow reads the next empty row index or id?

[code]
insRow:function(elm){
  var tbl = elm.parentNode;
  for (var i=0;i<tbl.rows.length;i++) {
    var currTr = tbl.rows[i];
var td = currTr.firstChild;
var txt = td.firstChild;
alert(td);
    if (txt == '3'){
  var nextEmptyRow = tbl.rows[i];
  break;
}
  }
  alert(nextEmptyRow);[/code]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.