Home / Free JavaScripts / Other / Here

Cut & Paste Sortable Table script with alternating row colors

Credit: Joost de Valk based on this code

Description: This is a versatile plug and play sort table script that can be applied to any table on your page. It supports the following unique features:

  • alternating row classes
  • the possibility for making a row unsortable by giving it the class unsortable;
  • default sort icons, showing on all headings of sortable rows.


Numbers Alphabet Dates Currency Unsortable
1 Z 01-01-2006 € 5.00 Unsortable
2 y 04-13-2005 € 6.70 Unsortable
3 X 08-17-2006 € 6.50 Unsortable
4 w 01-01-2005 € 4.20 Unsortable
5 V 05-12-2006 € 7.15 Unsortable
15 € 29.55

Directions: Simply download "", and refer to the html page inside.

As mentioned, this script works seamlessly with existing tables on your page. A quick overview of installing this script is shown below:

Insert the following code in the HEAD section of your page:

<script type="text/javascript" src="sortable.js"></script>

Then, for the table you wish the sort, insert a "class" and "id" attribute inside its <table> tag:

<table class="sortable" id="anyid">
  <th class="unsortable">Unsortable</th>
  <td>&euro; 5.00</td>
  <td>&euro; 6.70</td>
  <td>&euro; 6.50</td>
  <td>&euro; 4.20</td>
  <td>&euro; 7.15</td>
<tr class="sortbottom">
  <td>&euro; 29.55</td>

The class sortable is obligatory, as well as adding a unique id to each table.

  • By adding a class sortbottom to a row, this row wil be inserted last in your table, this is very useful for totals.
  • By adding a class unsortable to a cell in the first row, this row will be made unsortable.

You can use this script to sort multiple tables on one page (that's also the reason why the table needs an id).

JavaScript Tools:
Site Info

CopyRight (c) 2018 JavaScript Kit. NO PART may be reproduced without author's permission. Contact Info