Main Page

rows

<tbody>
<tr>
<td>Smith</td>
</tr>
<tr>
<td>Johnson</td>
</tr>
<tr>
<td>Henderson</td>
</tr>
<tr>
<td>Williams</td>
</tr>
<tr>
<td>Gilliam</td>
</tr>
<tr>
<td>Walker</td>
</tr>
</tbody>
</table>
With this setup, it’s easy to distinguish between the header rows and the data rows (obviously, you don’t
want to sort the header rows along with the data, so this is an important distinction). Using the table’s
tBodies
collection (which you may remember from earlier in the book), you can get a reference to the
<tbody/>
element as well as to the rows it contains:
var oTBody = oTable.tBodies[0];
var colDataRows = oTBody.rows;
To get the value in a table cell using the DOM is a bit involved, although not necessarily difficult. Each of
the
<tr/>
elements contained in the
rows
collection contains a child
<td/>
element. Each <td/> element
has a child text node that contains the actual value to be sorted on. Figure 12-1 shows this DOM hierarchy.
Figure 12-1
<td>
<td>
<tr>
<tr>
<tbody>
<tbody>
<tr>
<tr>
Smith
370
Chapter 12
15_579088 ch12.qxd 3/28/05 11:40 AM Page 370


JavaScript EditorFree JavaScript Editor     Ajax Editor


©