↑
Main Page
Advanced sorting
<tr>
<td>Smith</td>
<td>John</td>
<td>7/12/1978</td>
<td>2</td>
</tr>
<tr>
<td>Johnson</td>
<td>Betty</td>
<td>10/15/1977</td>
<td>4</td>
</tr>
<tr>
<td>Henderson</td>
<td>Nathan</td>
<td>2/25/1949</td>
<td>1</td>
</tr>
<tr>
<td>Williams</td>
<td>James</td>
<td>7/8/1980</td>
<td>4</td>
</tr>
<tr>
<td>Gilliam</td>
<td>Michael</td>
<td>7/22/1949</td>
<td>1</td>
</tr>
<tr>
<td>Walker</td>
<td>Matthew</td>
<td>1/14/2000</td>
<td>3</td>
</tr>
</tbody>
</table>
Note that the code in the column headers has also been updated to include the new data type argument.
For the first two columns, you don’t have to change the function call because both columns contain
strings. The third and fourth columns, however, contain dates and integers, respectively. For each of
these column headers, you must include the data type argument.
Advanced sorting
At this point, you’ve already learned how to sort different data types in the same table in both ascending
and descending order. Unfortunately, it’s very rare that a table contains only regular data types. The
truth is that you will always end up with links, images, or some other sort of HTML in tables; and users
will still want to sort. The most common situation is probably a column that contains icons. Whether the
icon is indicative of something (for instance, an attachment on an e-mail) or just decorative, people want
to be able to sort by it. The previous code does not support such a thing, but that can be fixed.
381
Sorting Tables
15_579088 ch12.qxd 3/28/05 11:40 AM Page 381
Free JavaScript Editor
Ajax Editor
©
→