Main Page

text values

<td value=”xls”><img src=”images/excelicon.gif”/></td>
<td>Spring Budget.xls</td>
<td value=”doc”><img src=”images/wordicon.gif”/></td>
<td>Job Description - Web Designer.doc</td>
<td value=”pdf”><img src=”images/acrobaticon.gif”/></td>
<td>Saved Web Page.pdf</td>
<td value=”doc”><img src=”images/wordicon.gif”/></td>
<td>Chapter 1.doc</td>
This HTML code sorts both columns by using strings; therefore, the third argument isn’t necessary when
. Even though the first column contains images, the code uses the value attribute to
sort it in both ascending and descending order.
This chapter explored using JavaScript to move more server-based functionality onto the client: sorting
HTML tables. You learned about using comparison functions along with the
method to
define custom sort order. With this knowledge, you went on to sort columns with string values in
ascending order.
Next, you learned how to sort in descending order by using the
method of the
columns with different values were introduced for sorting as well. After you wrote a small conversion
function, you were able to sort integers, floats, and dates in table columns. Lastly, you learned how to
account for table cells that contained HTML instead of simple text values.
Along the way, you learned about closures in JavaScript, which allow generated functions to contain ref-
erences to variables that are seemingly out of scope. Using closures, you saw how the seemingly limited
definition of comparison functions could be extended to allow the usage of additional data to determine
which of two values should occur first.
Sorting Tables
15_579088 ch12.qxd 3/28/05 11:40 AM Page 385

JavaScript EditorFree JavaScript Editor     Ajax Editor