login/register

Snip!t from collection of Alan Dix

see all channels for Alan Dix

Snip
summary

This is not a new trick, sorting a table using the DOM. ...
Now, how to use it. To make a table of your choice sorta ...
Download the Javascript library
Include the Javascript library, by putting a link to ...
... w have column sorting available

sorttable: Make all your tables sortable
http://www.kryogenix.org/code/browser/sorttable/

Categories

/Channels/techie/JavaScript

[ go to category ]

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:

  1. Download the Javascript library
  2. Include the Javascript library, by putting a link to it in the HEAD of your page, like so:
    <script src="sorttable.js"></script>
  3. Mark your table as a sortable one by giving it a class of "sortable":
    <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>&lt;script src="<a href="sorttable.js">sorttable.js</a>"&gt;&lt;/script&gt;</code></pre> </li> <li>Mark your table as a sortable one by giving it a class of "sortable": <pre><code>&lt;table <strong>class="sortable"</strong>&gt;</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>