Snip
|
This is not a new trick, sorting a table using the DOM. ...
|
---|
Categories |
|
---|
For Snip |
loading snip actions ... |
---|---|
For Page |
loading url actions ... |
This is not a new trick, sorting a table using the DOM. However, this mini-library has two nice attributes; the first is, unsurprisingly, that it follows my principles of unobtrusive DHTML, as you'll see below. The second is that, as mentioned above, it knows how to sort a variety of different data types, and it works them out for itself -- you don't have to tell it.
Now, how to use it. To make a table of your choice sortable, there are three steps:
<script src="sorttable.js"></script>
<table class="sortable">
Note that the library's JavaScript file is called
sorttable
(two Ts), but the class you add to the table is
sortable
(one T).And that's all you need. Your table will now have column sorting available by clicking the headers.
HTML |
<p>This is not a new trick, sorting a table using the DOM. However, this mini-library has two nice attributes; the first is, unsurprisingly, that it follows my <a href="../aqlists/">principles of unobtrusive DHTML</a>, as you'll see below. The second is that, as mentioned above, it knows how to sort a variety of different data types, and it works them out for itself -- you don't have to tell it.</p> <p>Now, how to use it. To make a table of your choice sortable, there are three steps:</p> <ol> <li>Download <a href="sorttable.js">the Javascript library</a></li> <li>Include <a href="sorttable.js">the Javascript library</a>, by putting a link to it in the HEAD of your page, like so: <pre><code><script src="<a href="sorttable.js">sorttable.js</a>"></script></code></pre> </li> <li>Mark your table as a sortable one by giving it a class of "sortable": <pre><code><table <strong>class="sortable"</strong>></code></pre> Note that the library's JavaScript file is called <code>sorttable</code> (two Ts), but the class you add to the table is <code>sortable</code> (one T).</li> </ol> <p>And that's all you need. Your table will now have column sorting available by clicking the headers. </p> |
---|