SOURCE CODE: Basic Table Sort

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
  <title>Basic Table Sort | JavaScript Examples | UIZE JavaScript Framework</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <meta name="keywords" content="widget Uize.Widget.TableSort"/>
  <meta name="description" content="Make your data tables sortable with little to no changes needed to your table HTML. Sort on string columns, date columns, and numerical value columns."/>
  <link rel="alternate" type="application/rss+xml" title="UIZE JavaScript Framework - Latest News" href=""/>
  <link rel="stylesheet" href="../css/page.css"/>
  <link rel="stylesheet" href="../css/page.example.css"/>
  <link rel="stylesheet" href="../css/widget.datatable.css"/>


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

<h1 class="header">
  <a id="page-homeLink" href="../index.html" title="UIZE JavaScript Framework home"></a>
  <a href="../index.html" class="homeLinkText" title="UIZE JavaScript Framework home">UIZE JavaScript Framework</a>

<div class="main">
  <h1 class="document-title">
    <a href="../javascript-examples.html" class="breadcrumb breadcrumbWithArrow">JAVASCRIPT EXAMPLES</a>
    Basic Table Sort
    <div class="pageActionsShell">
      <div id="page-actions" class="pageActions"><a href="source-code/table-sort-basic.html" class="buttonLink">SOURCE</a></div>

  <!-- explanation copy -->

  <div class="explanation">
    <p>This example demonstrates how the <a href="../reference/Uize.Widget.TableSort.html"><code>Uize.Widget.TableSort</code></a> widget class can be used to add sorting capability to a table on a page - without the table having to be generated by JavaScript, and without the table having to have messy JavaScript event handlers inside the HTML markup, and - most importantly - without the table having to be destroyed and rebuilt. This is an example of one of the several progressive enhancement (aka "unobtrusive JavaScript") features provided by the UIZE JavaScript Framework.</p>
    <p>Move your mouse over the table's column headings and notice how the heading becomes highlighted. Also, a tooltip indicates what action will result from clicking a heading. Click a heading and see how the table is instantaneously sorted by the data in that column. Click again to reverse the sort order. The <code>Uize.Widget.TableSort</code> class adds a few other progressive enhancements. Move your mouse over the rows of data and see how the current row is highlighted. This makes it easier for the eye to follow the row from left to right, allowing you to make sure you're reading data for the row that you think you're reading it for - something that is notoriously difficult for wide tables. Notice also, how a tooltip for each column's data displays the heading of the column - helping with large tables that get scrolled so the user can no longer see the headings.</p>

  <!-- table of data to which a Uize.Widget.TableSort instance will be attached -->

  <table id="friendsTable" class="data" cellspacing="0" cellpadding="2" style="margin:auto;">
    <tr class="title">
      <td colspan="8">Table of Friends</td>
    <tr class="heading">
      <td>First Name</td>
      <td>Last Name</td>
      <td>Hair Color</td>
      <td>Eye Color</td>
      <td>Date of Birth</td>
      <td>Known for How Long</td>
      <td>189 lbs</td>
      <td>brown, light</td>
      <td>May 5 1963</td>
      <td>5 years</td>
      <td>154 lbs</td>
      <td>brown, dark</td>
      <td>2 years</td>
      <td>182 lbs</td>
      <td>brown, graying</td>
      <td>gray, blueish</td>
      <td>10 years</td>
      <td>165 lbs</td>
      <td>brown, dark</td>
      <td>15 December 1966</td>
      <td>3 years</td>
      <td>Diego Rodriguez</td>
      <td>173 lbs</td>
      <td>4 years</td>
      <td>191 lbs</td>
      <td>blue green</td>
      <td>1 year</td>
      <td>159 lbs</td>
      <td>10 February 1975</td>
      <td>2 years</td>
      <td>152 lbs</td>
      <td>brown, medium</td>
      <td>1 year</td>
      <td>232 lbs</td>
      <td>blonde, sandy</td>
      <td>blue, grayish</td>
      <td>17 March 1962</td>
      <td>3 years</td>
      <td>van Doren</td>
      <td>149 lbs</td>
      <td>October 23 1974</td>
      <td>.5 years</td>

<!-- JavaScript code to make the table sortable -->

<script type="text/javascript">

Uize.require (
  function () {
    'use strict';

    /*** create the example page widget ***/
      var page = = UizeSite.Page.Example ();

    /*** spawn (and automatically wire) the Uize.Widget.TableSort instance ***/
      Uize.Widget.TableSort.spawn (

    /*** wire up the page widget ***/
      page.wireUi ();