The purpose of this project is to let you easily sort tables in ascending or descending order. It has these features:
Include the JavaScript file, set special classes on your table, and call the init method.
When the table rows get moved to new places in the table, any special formatting gets moved with them. This includes rows that might have been made invisible or rows that have been colored differently.
<script type='text/javascript' src='hfstablesort.js'><script>
<table class="hfstablesort hfssort_haalana">
hfsTableSort.hfsTableSortInit();
function sort_custom_h (a,b) { return (some_comparison (a[0], b[0])); // compare the keys }
The sample below has the following features:
var terms = [ "Spr", "Sum", "Fall" ]; function sort_custom_h (a,b) { // this is a custom sort for "Season, Year" as in column 1 // The a and b variables are arrays as follows: // a[0] is the key value for the first compare item // a[1] is the contents of the entire row // a[2] is the display style on the row (possibly "none," i.e. invisible) // a[3] is the class name on the row, which may be used to stripe it // In general, we use only a[0] and b[0], because we want to compare the keys. var aa = a[0].split(" "); var bb = b[0].split(" "); // start by comparing the years if (aa[1] < bb[1]) return -1; if (aa[1] > bb[1]) return 1; // if year is the same, compare the season/term return (terms.indexOf (aa[0]) - terms.indexOf (bb[0])); }
Term | Course | Description | Instructor | Grade | % | Certificate |
---|---|---|---|---|---|---|
Spr 12 | GDES 047 | Web Animation | Sylvia Min | A | 103 | core |
Spr 12 | GRART 062 | Adobe Illustrator | Sylvia Min | A | 102 | core |
Sum 12 | GDES 035 | Graphic Design | Rick Rivas | A | 92 | core |
Sum 12 | GDES 045 | Web Design | Mark Garrett | A | 98 | core |
Fall 12 | GRART 064 | Photoshop | Rick Rivas | A | 93 | core |
Fall 12 | GDES 046 | Dreamweaver and CSS | Mark Garrett | A | 97 | core |
Fall 12 | CA 086 | PHP and mySQL | Helen Sun | A | 98 | core |
Spr 13 | CA 088A/B | JavaScript | Curtis Pembrook | A | 100 | core |
Spr 13 | CA 084A | Database and SQL | Helen Sun | A | 94.5 | elective |
Spr 13 | GRART 068 | Advanced Photoshop | Rick Rivas | A | 97 | elective |
Sum 13 | Art 031A | Drawing | Mark Engel | A | 94 | core |
Sum 13 | Art 033A | 2D Design | Mark Engel | A | 98 | elective |
Sum 13 | CS 001A | Java Programming | Jesse Cecil | A+ | 101 | elective |
Fall 13 | GRART 063 | Adobe InDesign | Peter Kuo | A | 96 | core |
Fall 13 | CA 046E | Intermediate Powerpoint | Judie Golden | A | 100 | |
Fall 13 | CA 063B | Intermediate Excel | Pat Hudak | A | 113 | |
Fall 13 | CS 001B | Intermediate Java | L. Krishnamurthy | A+ | 100 | elective |
Fall 13 | CS 020A | C# Programming | Hadeel Ammari | A | 96 | elective |
Spr 14 | GDES 051 | Mobile App & Web Design | Mark Garrett | A | 100 | elective |
Spr 14 | CIS 063 | Android Programming | Helen Sun | A | 99 |