A minimal Javascript library that makes table columns sortable.

Usage

Just add the script and, optionally, the CSS link to the page header. Then add the class sortable to any table that shall be sortable.

<html>
<head>
    <link rel="stylesheet" href="/css/tablesort.css">
    <script type="text/javascript" src="/js/tablesort.js"></script>
</head>
<body>
    <table class="sortable">
        <thead>
            <tr><th>Text</th><th>Numbers</th></tr>
        </thead>
        <tbody>
            <tr><td>foo</td><td>30</td></tr>
            <tr><td>bar</td><td>40</td></tr>
            <tr><td>baz</td><td>30</td></tr>
        </tbody>
    </table>
</body>
</html>

Clicking on a header cell sorts all table rows in ascending order, based on the values in the corresponding column. Clicking again reverses the sort order. If two cells in the sort column have the same value, their rows will be sorted based on the previously sorted column.

Example

TextNumbers
foo30
bar40
baz30

Download