1. 01. Incoming
  2. 02. Hifi
  3. 03. Lofi
  4. 04. The Lab
  5. 05. Tags

frequency decoder

Unobtrusive Table Sort Script (revisited)

Posted Saturday September 16, 2006

frequency decoder

A rewrite of the original table sort script that includes a few more features and a much faster sort routine architecture

My first free Sunday morning in what seems like an epoch produces a complete rewrite of the original (and by far most popular) lab experiment, the “Unobtrusive Table Sort Script”, that addresses speed issues present within version #1.

At a glance…

  • Plays nicely with the JavaScript global namespace (the script creates and reuses only one JavaScript object)
  • Multiple columns can be sorted at once by pressing Shift while selecting the columns using either the keyboard or mouse
  • The new script sorts (on average – based on my very non-scientific calculations), 5 times faster than its predecessor
  • The plug-in architecture makes writing custom sort functions a breeze
  • The script can highlight both alternate rows and full columns on a table by table basis.
  • Like its predecessor, the script is fully keyboard accessible
  • The script can correctly determine a columns datatype should a datatype not be explicitly defined (datatypes determined are limited to numbers, text, currency values and dates)
  • The script is smart enough not to sort columns containing identical data
  • Sort routines can be initiated using JavaScript
  • Tables can be automatically sorted on a column (or columns) of your choice, even in reverse order
  • Before-sort and after-sort callback functions (or Object.methods) can be defined for individual tables

The Slowdown

The original script attempted to grab the inner text of every TD node within the column to be sorted, each and every time the sort routine was activated. This was an extremely processor intensive action and the main cause of slowdown during the sort of large tables. While a limited “cache” system was offered, it relied heavily on use of the JavaScript “in” operator, which is itself notoriously slow to process.

Speeding things up

The new script addresses these issues by creating and storing an internal representation of the parsed table data the very first time that one of the table’s sortable TH nodes is activated (a 2D matrix of the table data). The data stored within this internal object is then reused during each subsequent sort action. This means that there is a slight processing overhead the first time the sort is activated (as an internal representation of the table’s data has to be created) but subsequent sorts, on any of the table’s columns, are much faster than in the previous incarnation of the script.

A listing of sample sort times for a 100 row table can be located within the dynamic table creation demo.

Initiating the sort process using JavaScript

As it was an uncommonly-common request for the first version of the script, the abilty to initiate the sort using JavaScript has been integrated into the rewrite. To initiate a sort, call the following method:

  
 fdTableSort.jsWrapper(yourTableId, colNums); 
  
  

Passing in the id of the table to be sorted and either an Integer stipulating the position of a single column to be sorted, or an array stipulating a set of columns to be sorted i.e. the following JavaScript statement:

  
 fdTableSort.jsWrapper("salesTax", [0,1,4]); 
  
  

will initiate the sort routine on columns 0, 1 and 4 of the table with an id of “salesTax”. An example of initiating the sort routine in this way can be seen within the JavaScript initiated sort demo.

Please note, if a callback function has been defined, in this case, it is not called after the sort routine completes.

Sortable datatypes

The script can currently sort dates (dd-mm-yyyy, mm-dd-yyyy or yyyy-mm-dd formats accepted), currency values (£, $, €, ¥ and ¤), numbers/floats and finally, plain-text (sorted in a case-insensitive manner). Additionally, the character used as the date divider (i.e. the character that separates the date parts) can be “/”, “-”, “.” or “ “ (space).

A note on the date format

The script currently favours the American date format of “mm-dd-yyyy”. This is the first format that all dates are tested against during the data preparation phase, which means that European dates such as 10-08-2006 (i.e. the 10th August 2006) will be parsed as the 8th October 2006.

Should your dates be of the European format “dd-mm-yyyy”, add the class sortable-date-dmy to the TH node instead of the class sortable-date, this will tell the script to attempt to parse a DMY format date before attempting to parse a MDY format date.

A note on sorting numeric data

The sortNumeric method bundled with the source code is quite ruthless with the data passed to it. It will replace any character not valid for use within a floating point number and then attempt to parse a float from the result.

This means that the sortNumeric method can be used to sort all manner of numeric column data, for example; columns containing percentages e.g. -22%, 34.6% etc do not require a bespoke sort function in order to be sorted – giving the column the className sort-numeric will suffice.

Row and column highlighting

The script enables both row and column highlighting.

Zebra striping the table rows

Should the table be given the class rowstyle-something, each alternate table row is given the class something after the table has been sorted i.e giving the table a class of rowstyle-alternate will tell the script to give each alternate row the class alternate.

Highlighting the currently sorted column

Should the table be given the class of colstyle-something, each TD node within the sorted column is given the class something after the table has been sorted i.e giving the table the class colstyle-alternate will tell the script to give each TD node within the sorted column the class alternate.

Making any column sortable

To make any table column sortable, just give the associated table header (TH) tag the class sortable, the script will automatically determine the column datatype, make the entire table header clickable (and not just the text contained within) and create the appropriate up/down arrow within the header when clicked (using the ↑ & ↓ characters).

Forcing a columns sort algorithm

Should a column contain a mix of datatypes (or should you know the column datatype), it is advised that you explicitly set the sort algorithm by adding one of the following classNames to the associated table header (TH) tag: sortable-numeric, sortable-currency, sortable-text , sortable-date, sortable-date-dmy or sortable-keep (which keeps the row in it’s original order).

Sorting multiple columns

The script can now sort multiple columns. Just hold down the Shift key while selecting the columns to sort (either with the keyboard or with the mouse).

Forcing a column to “reverse sort” by default

Should you wish to sort a column in reverse order by default, just give the associated TH node the className favour-reverse (Note the English spelling of favour). The default reverse sort is only taken into consideration when sorting on a single column.

Stipulating custom sort functions

Should you wish to stipulate your own custom sort function, add the class sortable-yourCustomFunctionName to the table header (TH) tag; for example, adding the class sortable-myCustomSortFunction will tell the script to call a JavaScript function named myCustomSortFunction in order to sort that column’s data.

The name of your custom sort function may only contain letters (a-Z) and the underscore character. Function names containing other characters will not be recognised.

The function name has been limited in this way as it is defined within a className, which itself can only contain a subset of the full ASCII character set i.e. while “$” is a valid JavaScript function name, it is not a valid character to use within a className.

Available custom sort functions

A few custom sort functions have been written and made available for those who might need them. They currently include:

  • A function to sort by IP address
  • A function to sort English longhand date formats e.g. 12th April 2006
  • A function to sort (English) dateTime e.g. 12th April 1992 at 13:44:23
  • A function to sort twelve-hour timestamps e.g. 12:32a.m.
  • A function to sort numbers stipulated in Scientific Notation e.g. -32.45 e 0.32
  • A function to sort on fileSize i.e. 22kb, 3mb, 1.3gb
  • A function to sort images on the value of their “src” attribute
  • A function to sort alphaNumeric data e.g. a, b, 1a, 2d, 33.4z, -2.4s

The functions can now be seen in action on their own custom function demo page.

Preprocessing the column data

Should your custom sort function require more than just the inner text of the TD node or should you wish to keep your custom sort as fast as possible, it is necessary to write a complimentary “prepare data” function. This function is called just once, during the creation of the data object for the table. The function should have the same name as your custom sort function with “PrepareData” added to the end.

An example custom sort function

In order to write a custom sort function “sortImage” that sorts images within the table’s TD cells using the value of their “src” attribute, two functions are required; “sortImage” and “sortImagePrepareData”.

The “sortImagePrepareData” function will be used to parse the image’s “src” attribute, which is then stored within the table’s data object to be used during the sort routine e.g.

    
  // Returns the "src" attribute of the first image 
  // "PrepareData" functions are passed both the TD node
  // and the TD node's inner text. In this case, we use the
  // tdNode and not the inner text.
  function sortImagePrepareData(tdNode, innerText) {
        var img = tdNode.getElementsByTagName('img');
        return img.length ? img[ 0 ].src : "";
  }
    
  

The “sortImage” function will then use this data during the sort i.e:

    
   // Uses the data prepared in “sortImagePrepareData”
  function sortImage(a, b) {
        // Get the data for the current column from the
        // two arrays passed in as arguments like so…
        var aa = a[fdTableSort.pos];
        var bb = b[fdTableSort.pos];

        // Sort the data 
        if(aa == bb) return 0;
        if(aa < bb)  return -1;
        return 1;
  }
   
  

The “PrepareData” functions are not obligatory and are only called by the script if they exist.

It is worthwhile to note though, that sort routines will be much faster whenever the column data has been parsed in advance by an associated “PrepareData” function.

A few more custom sort function examples (including the above “sortImage” function) can be viewed in the custom sort functions demo

Sorting the table automatically

The script will automatically sort any table that has been given the class sortable-onload-N immediately after the window.onload event fires – where N specifies a className of the form “-colNumber[ r ]” – with “colNumber” being replaced by the integer value of the column to sort and the optional “r” (remove the square brackets and spaces!) stipulating that the
column is to be sorted in reverse.

Multiple columns can be stipulated at once, for example, the classname sortable-onload-3r-4r-5 will automatically sort the table on column 4 (reverse sort), then column 5 (again, using a reverse sort) and finally, column 6.

Please note: the column index starts at 0 and not 1.

Preparing an already sorted column

If you have already sorted the table on a specific column or set of columns when the page is generated, it is necessary to indicate this to the script.

This can be done by adding the following className to the table sortable-onload-show-N, where N specifies a className of the form “-colNumber[ r ]” i.e. an identical className to the form discussed above.

This enables the script to create the appropriate up/down arrows within and set the appropriate className on the table headers without it having to actually sort the table data.

Zebra-striping the table

If you are not using the “sortable-onload-X” or “sortable-show-X” classNames but still want the table to be zebra-striped on page load, just give the table the className “onload-zebra”.

Indicating the sort is underway

Very large tables may take a while to sort which, without some sort of feedback, may leave users slightly bewildered as to why nothing seems to be happening after they have just clicked the table header.

To enable you to provide this feedback, both the page BODY and the TH node clicked by the user are temporarily assigned the class sort-active. This enables you to create appropriate styles that visually indicate to the user that the sort is underway (adding an animated gif to the background of the TH node for example). After the sort is complete, the class sort-active is removed from both the BODY and the TH nodes.

An example of using the sort-active className can be viewed within the Dynamic table creation demo – the currently active TH node displays an hourglass during the sort.

The callback functions

The script now includes the ability to call bespoke “callback” functions. The first function “sortInitiatedCallback()” is called immediately before the sort routine fires, the second function “sortCompleteCallback()” is called immediately after the sort routine completes. The two callback functions are passed the ID of the table as an argument.

Additionally, callBack functions can now be created for individual tables by creating a function named sortInitiatedCallbackXXX or sortCompleteCallbackXXX where XXX represents the ID of the table; for example, the script will attempt to call the function sortInitiatedCallbackTestTable and sortCompleteCallbackTestTable for a table with an ID of “TestTable”.

Stipulating Object.methods or bespoke JavaScript functions as a callback

You may wish to use an Object.method or a bespoke JavaScript function as a callback, to do this, just add one (or both) of the following class’s to the table’s className:

The className sortinitiatedcallback-XXX stipulates a function that will be called before the sort initiates, where XXX should be replaced with the name of the function in question.

Object.methods can be stipulated by converting the “dots” (i.e. the full-stops) to minus signs (-); for example, the className “sortinitiatedcallback-myObject-myMethod” will tell the script to call the “myMethod” method of the JavaScript Object “myObject” e.g. myObject.myMethod();

The className sortcompletecallback-XXX stipulates a function to be called after the sort has taken place. again, the XXX is replaced in an identical fashion to the XXX within sortinitiatedcallback-XXX.

Please Note: callback functions are only called should they exist so don’t fret about creating them should you not require the callback functionality.

An example of using a callback function can now be viewed within the callback function demo.

Creating your own progress indicator

Using callback functions in this way enables you to define your own progress indicator that appears whenever a sort is initiated and disappears when the sort completes.

Table pagination

As lots of people have been asking for the functionality, I’ve written a table pagination script that, as the name suggests, paginates tables automatically (i.e. splits large tables into smaller chunks). More information on the pagination script can be located within the article Client-Side Table Pagination Script.

Please Note: The pagination script does not rely on the tableSort script and can therefore be used independently of it.

Using images for the arrows

This version of the script enables images to be used in place of the arrows. The images should be defined within your CSS as follows:

    
   th.forwardSort
        {
        background:transparent url(your-down-arrow-image) no-repeat 0 0;
        }
  th.reverseSort
        {
        background:transparent url(your-up-arrow-image) no-repeat 0 0;
        }    
    
  

Additionally, the table should be given the class no-arrow which tells the script not to create the default arrow characters within the TH node.

Keeping things fast…

There are a few things that you can do to keep the script from slowing down:

  1. Always stipulate the column datatype by using one of the explicit classNames sortable-date, sortable-date-dmy, sortable-numeric, sortable-currency, sortable-keep or sortable-text. Explicitly defining the datatype in this way means that the script does not have to try to deduce the column datatype and therefore saves many clock cycles during the initial data preparation phase.
  2. Don’t use column highlighting on large tables as it takes time to grab the TD nodes and add or delete the appropriate class.
  3. Write an associated “PrepareData” function for each of your bespoke sort functions.

A note for the Ajax’ers

Whenever you re-render a table (from an Ajax callback), just call the method fdTableSort.init, passing in the ID of the table that was just re-rendered. This will remove the original cached data object for the table in question and make sure an up-to-date version is created the first time the table is again sorted.

Calling the fdTableSort.init method with no arguments will clear all of the currently cached data objects and re-initialise all sortable tables.

Installing the script

Just add the following code within the HEAD section of your HTML document (remember to change the filepath to suit your installation):

    
 <script type="text/javascript" src="/the/path/to/tablesort.js"></script>
    
  

...and give both the TABLE and TH tags the required classNames (all classNames have been described within the article). Thats all there is too it.

The “table actions” plug-in

After countless requests, I’ve written a table actions plug-in to the script that enables zebra-striping, row selection and complex row, cell and column highlighting effects. More information can be found within the table actions post.

The License

The script is now released under a creative commons Attribution-ShareAlike 2.5 license. Should you use the script within a commercial context please think about clicking the payPal donate button – it’s certainly not an obligation but it would most certainly put a smile on my face.

Translations

An Italian translation of this article has been located at Consulente Informatico. Many thanks to Sergio Gandrus.

Demo, downloads and updates

Tested in Internet Explorer 6 & 7, Opera 9.01, Safari 3.0.3 (Windows) and Firefox 2.

View the table-sort demo, the custom sort functions demo page, the basic pagination demo, the sortCompleteCallback demo, the Dynamic table creation demo, the secondary/tertiary sort demo or download the uncompressed JavaScript source code (you can compress the script using Dean Edwards Packer if the size is an issue).

15/04/2008 (v4.9):

  • Fixed a bug that didn’t zebra-stripe identical columns stipulated as “sortable-onload”

22/03/2008 (v4.8):

  • Fixed a column highlighting bug

06/03/2008 (v4.7):

  • Fixed a bug that stopped the hourglass showing during sorts

03/03/2008 (v4.6):

  • Fixed a bug with the “sortable-onload-” functionality
  • Integrated the “favour-reverse” functionality that means you can now stipulate that columns are to be sorted by default in reverse order
  • Added the secondary/tertiary sort demo

01/02/2008 (v4.5):

  • Changed the code to not remove child IMG nodes from sortable TH nodes

21/01/2008 (v4.4):

  • zebra table support when the table className contains “onload-zebra”

27/12/2007 (v4.3):

  • Embedded table support

19/12/2007 (v4.2):

  • Added the ability to stipulate Object.methods as a callback function
  • Better integration with the pagination script to remove the “flicker” present in previous versions as the pagination script redrew the table

14/12/2007 (v4.1):

  • Added the ability to sort multiple columns onload
  • Added the ability to “show” multiple presorted columns onload
  • Changed the addClass and removeClass methods
  • Separated the “redraw” code into it’s own method

15/11/2007 (v4.0):

  • Fixed a Safari2 bug

23/10/2007 (v3.9):

  • Added the “sortable-onload-show-N-reverse” functionality (thanks to Brett Harrison)

04/10/2007 (v3.8):

  • Added the multi-column sort functionality
  • Deprecated the sortDate method

28/05/2007 (v3.7):

  • Fixed a bug that referenced getElementsByClassName and not getElementsByTagName

16/05/2007 (v3.6):

  • Fixed a bug introduced within the last revision

05/04/2007 (v3.5):

  • Fixed an identical column data bug

03/04/2007 (v3.4):

  • Added a fix to support nested tables (Note: the solution requires that the parent table must have a tbody) – thanks to Chris for the fix

22/03/2007 (v3.3):

  • Worked on Internet Explorer memory leaks
  • Added code to correctly cleanup internal objects for the Ajax’ers

20/03/2007 (v3.2):

  • Added a “sortable-keep” option
  • Altered the jsWrapper function to not use the callback functions
  • Unique callback functions can now be created for each table

02/03/2007 (v3.1):

  • Fixed a bug in the parseDate method
  • Removed a block of code that caused problems with dynamically created tables
  • Fixed a few bugs in the custom sort functions

19/02/2007 (v3.0):

  • Fixed a bug in the jsWrapper method
  • Added rowspan support
  • Many internal changes dealing with colspan & rowspan support

30/11/2006 (v2.9):

  • Added the ability to have colspan’s within the non-sortable TH nodes
  • Added a workaround for a Netscape 8.1.2. bug that crashed the browser when the script was initiated
  • Added a disableTextSelection method that, not suprisingly, disables text selection on sortable TH nodes (in order to stop the browser highlighting the text within the node when the onclick event fires)

07/11/2006 (v2.8):

  • Added the “automatic reverse sort” code.
  • Changed the dateFormat function to accept a second parameter that tells the script to favour European d-m-y format dates
  • The sortInitiated and sortComplete callback functions now get passed the ID of the table as an argument

02/11/2006 (v2.7):

  • Changed the code to handle multiple TR’s within the table’s THEAD.
  • Fixed an uppercase TFOOT reference

19/10/2006 (v2.6):

  • Changed the license

12/10/2006 (v2.5):

  • Fixed a bug when setting previously undefined classNames

04/10/2006 (v2.4):

  • Altered the “prepareTableData” method to accept TD nodes that have no child nodes

02/10/2006 (v2.3):

  • Altered the “prepareTableData” method to trim whitespace from the TD node’s innerText

18/09/2006 (v2.2):

  • Fixed a bug within the sortNumeric method when sorting zero values

18/09/2006 (v2.1):

  • Changed the sortNumeric method to be more robust
  • Added a check to see if a TD node is a child of a TFOOT
  • Changed the script to work with tables that have no THEAD or TBODY
  • Rewrote the custom sort functions to adhere to the new “PrepareData” architecture

Tags: javascript, sort, table, unobtrusive

Previous Comments ~

Luis Prill Sempere
#1 · Sunday September 17, 2006

Hi,

nice script. I am going to use this for my hobby testpage. Very usefulll…
I do not understand too much of JS but I think your script is bettter then the one I used before: http://www.workingwith.me.uk/articles/scripting/standardista_table_sorting
Can I still use this script, once my page becomes comercial?
Could you post an install instruction (I had to go into your demo scource code to install it)
thanks in advance,

Luis

Me · http://www.svnforum.org
#2 · Sunday September 17, 2006

Great, was always wondering if this was possible. Nice webpage

Int
#3 · Sunday September 17, 2006

Please use a little biger default text size. People abobe 37 do not read small fonts easily. Thanks.

scotts
#4 · Sunday September 17, 2006

I am having trouble using your script. (win/nix,ie,ff)
The error message I am receiving is “txt has no properties”

I scanned over your code and I believe the reason it’s breaking in my application is related to the line:
  “var start = table.getElementsByTagName(‘tbody’);”

Our legacy code builds datagrid tables but does not use the tbody tag.

Is there a way to use your script on tables that do not use tbody?

Thanks.

John
#5 · Sunday September 17, 2006

It’s great, but it would be perfect if you could constrain the height and have a vertical scrollbar appear appropriately . . .

Björn Olsen
#6 · Sunday September 17, 2006

Nice script.

One pedantic point, though: the possessive form of the word “it” is not “it’s” but “its”.

Frequency Decoder
#7 · Monday September 18, 2006

@ Louis: Yes, this script is free for commercial use – but you can always use the “PayPal Donate” button should you be feeling generous! I’ll try to add a short “Installation notes” paragraph to the write-up.

@ Int: Do you mean the main article text-size (which should be set as 12px) or the comment text size (which should be set at 10px)? Thanks in advance.

@ John: Hi John, I think that your looking for something like Cody’s Pushpin header technique

@ Me: Ummm, thanks!

@ Scotts: Thanks for the warning. I’ve altered the script to fix the problem.

@ Björn: Yep, your right, after speaking almost no English for four years my English language “powers” have diminished rather rapidly. I shall update the post tout de suite.

James Howard · http://www.monkeymagic.co.uk
#8 · Monday September 18, 2006

Great script, especially the caching. Really well written JavaScript, too, which is rarely seen!

Frequency Decoder
#9 · Monday September 18, 2006

@ James: Hi James, thanks for the kind words (when I start to write JavaScript as well as Dean Edwards I’ll be a happy man indeed).

James Howard · http://www.monkeymagician.co.uk
#10 · Monday September 18, 2006

Ah yes, but when your website design gets as bad you’ll be an unhappy man.

Jon Baer · http://www.jonbaer.com
#11 · Monday September 18, 2006

This is a very nice script … one small request or item to build on …

Im wondering if its possible to virtually paginate over a large result set via Ajax using this script. For example, 100 items, 10 per page, on sort repopulate the same DOM structure. I guess what Im trying to find out is if the data portion of the script is plugable to allow it to populate over records not visible in the table?

Im probably not making sense, just that I already have a paginated table + want to add this sorting library to it but need it to span over all the records. Any ideas?

Dinesha
#12 · Tuesday September 19, 2006

Great script.

Frequency Decoder
#13 · Tuesday September 19, 2006

@ Jon: Hi Jon, the current script creates it’s data object using the innerText of the TD nodes and currently isn’t “pluggable” (is that even a valid word?). You could add a method to the script that accepts a JSON response from the Ajax callback and recreates the data object using the JSON data.

Calling the fdTableSort.init() method after the Ajax callback i.e. after the new table has been rendered, will reinitialise the script but the sort will only ever sort cell data that is present on screen (and I think that you want to sort the 100 records, not just the 10 present on the screen).

Particle Tree have an article about preloading data using Ajax that might be helpfull.

Sorry I can’t be more help,
Brian

@ Dinesha: Thanks.

Arnaud
#14 · Tuesday September 19, 2006

You state earlier that

@ Louis: Yes, this script is free for commercial use…

In the source code though the licence is creative commons nc-sa which means “Noncommercial. You may not use this work for commercial purposes”

So, which one is it ? :)

Thanks for making that code available in any case.

Frequency Decoder
#15 · Tuesday September 19, 2006

@ Arnaud: The script is released under a Creative Commons Attribution-NoDerivs 2.5 license.

This is now stated within the source code.

Regards,
Brian.

Matt
#16 · Tuesday September 19, 2006

You can extend this script with simple css to a fixed header scrolling table by adding the following css attributes:

tbody {
overflow-y:auto;
overflow:-moz-scrollbars-vertical;
width:100%;
height: 500px;
}

Arnaud
#17 · Tuesday September 19, 2006

@brian: thank you !

Emil Stenström · http://friendlybit.com
#18 · Tuesday September 19, 2006

Damn well done! This certainly goes into the bookmarks, the list of features just goes on and one.

Oolon Coluphid
#19 · Wednesday September 20, 2006

Cool except the sort direction arrows are going the wrong way in the demos

V should be largest on top to smallest on bottom, and ^ should be smallest on top to largest on bottom

Frequency Decoder
#20 · Wednesday September 20, 2006

@ Matt: Thanks for that, it’s a useful modification.

@ Arnaud: No problem, glad you find it useful.

@ Emil: Hi Emil, it’s always a pleasure to be bookmarked. You just gotta love your gravatar B.T.W. (note to self: get a bleeden gravatar that doesn’t suck)

@ Oolon: A clear case of “I looked at it so much that I just didn’t notice” (it made me chuckle though). I’ve changed the CSS to display the arrows properly. Thanks for the info.

Bill
#21 · Wednesday September 20, 2006

On my numeric columns, the zero values are sorted before the negative values. For example, the sort is 0, -1, 1, but I am expecting -1, 0, 1. I have tested letting the script determine class, and setting the sort class.

Frequency Decoder
#22 · Wednesday September 20, 2006

@ Bill: Yeah, a bug!

In fact, it was a dumb error within the sortNumeric method (I used ”==” and not ”===” when comparing values). I’ve fixed the problem and updated the downloads. Apologies to everyone who has already downloaded the source code (as you will need to download it again)!

Thanks for the info,
Brian.

cody lindley · http://www.codylindley.com
#23 · Thursday September 21, 2006

You Rock!

Charles
#24 · Tuesday September 26, 2006

Brian,
I took your suggestion from above, and i run re-initialize the table onComplete of an ajax.Updater call. This works perfectly, except that the alternate row styles lump together. On your demo, they maintain proper spacing. When I do it, they maintain their original position, so you have clumps of alternate rows together as well as clumps of non-alternate rows.

Do you have a suggestion on what might be causing this?

thanks!
Charles

Charles
#25 · Tuesday September 26, 2006

Brian, it was user error :P
I must have messed up the CSS somehow which caused issues.
I haven’t done a diff yet to see what I did wrong the first time. I took your demo code and modified it a piece at a time until the format matched what i originally wanted. There has to be a typo in there somewhere…

thanks again :P
This is just like how your cold goes away once you visit the doctor…hehe

Frequency Decoder
#26 · Wednesday September 27, 2006

@ Cody: Hey Cody… your wrong man, you rock (and wasn’t that your mugshot I saw in jQuery magazine ?)

@ Charles: It must have been the class “rowstyle-something” that was missing from the table className. Glad to hear it’s fixed.

Regards,
Brian

Daniel · http://daanro@gmail.com
#27 · Thursday September 28, 2006

wow, the best version ever
need it for a little project, thanks dude

bryan
#28 · Friday September 29, 2006

Very nice page(appearance,reaction).

Stephen Hill · http://gatekiller.blogspot.com
#29 · Friday September 29, 2006

I really love this script, however, I have a problem with sorting large numbers.

if these numbers: 1,5,8,100,800 where sorted in descending order, it should produce: 800, 100, 8, 5, 1 however, it produce 8, 800, 5, 1, 100 which is very wrong.

I hope there is some simple way to sort this out :)

Cheers
GK

Frequency Decoder
#30 · Friday September 29, 2006

@ Bryan: Thanks.

@ Stephen: Hi stephen, I can’t reproduce the problem (a test table containing identical data sorts properly for me). Have you stipulated “sortable-numeric” within the associated TH node’s calssName? If not, perhaps the script is resorting to a text based sort (it shouldn’t, the script should realise the data is all numeric – this might be another bug entirely!) which might skew the results.

Regards,
Brian.

Stephen Hill · http://gatekiller.blogspot.com
#31 · Friday September 29, 2006

@ Brian: Whoopse, I was putting class=”sortable sortable-numeric” hoping it would sort it but it didn’t. Having removed the first sortable it now works :) but it must be some sort of bug no detecting the datatype correctly since all the data in the column are integers.

Update: Hi Stephen, it was indeed a bug within the code. I've updated the download to include a fix for the problem.

Many Thanks
GK

Brian Cooper
#32 · Tuesday October 3, 2006

I have to say this is an awsome js. I have noticed some strange behavior though and was wondering if anyone else has the same problem. If you have a table where every row has the exact same data in the 1st collumn and you set sortable-onload-0, it won’t zebra stripe the rows when the page first loads. Anyone know what a possible fix might be for this?

Brian Cooper
#33 · Tuesday October 3, 2006

Typo in previous post:

sortable-onload-0

should be “sortable-onload-1”

Frequency Decoder
#34 · Wednesday October 4, 2006

@ Brian: Hi Brian, the script will not actually sort a column that has identical data, this is intended functionality. It’s really up to you to create the initial table with the zebra-stripes – this way, users that have javascript turned off will still get a nice zebra-striped table.

Should you really wish to zebra-stripe tables with identical column data, then remove lines 314 – 318 within the “initSort” method (but be aware that this means that the script will now sort columns containing identical data which means that adjacent column data gets moved in a somewhat nonsensical manner).

Hope this helps,
Brian.

Renerea
#35 · Thursday October 5, 2006

I can’t zebra-stripe tables. If the table class is class=”rowstyle-alternative”, then in the rendered javascript source I can see this alternative TR classes:
class=”” and
class=”rowstyle-alternative”

Notice the white space before word “alternative” in the tr class.

Thanks anyway for this very nice script.
Renerea.

Renerea
#36 · Thursday October 5, 2006

Sorry, there is a mistake in my previous comment:

I can’t zebra-stripe tables. If the table class is class=”rowstyle-alternative”, then in the rendered javascript source I can see this alternative TR classes:
class=””
class=” alternative”

Notice the white space before word “alternative” in the tr class.

Thanks anyway for this very nice script.
Renerea.

Renerea
#37 · Thursday October 5, 2006

One more.
In your demo page: http://www.frequency-decoder.com/demo/table-sort-revisited/, look at this alternative tr classes that the script makes:

The firt time page loads: – TR class=undefined – TR class=”undefined alternative”

When you sort first time: – TR class=”undefined undefined” – TR class=”undefined undefined alternative”

When you sort second time: – TR class=”undefined undefined” – TR class=”undefined undefined undefined alternative”

The third time: – TR class=”undefined undefined” – TR class=”undefined undefined undefined undefined alternative”

And so on.

Frequency Decoder
#38 · Thursday October 5, 2006

@ Renerea: I’ll look into it. It appears easy enough to fix.

Update: Well, that's a FireFox "quirk" I've never seen before. Normally, polling the className of a DOM node will return an empty String whenever the DOM node has not yet been assigned any classes. The latest FireFox seems to return "undefined".

I've changed the code to check the "typeof" the className before setting the column/row classes and it appears to have fixed the problem.

P.S. I haven't tried using the node.getAttribute method (which might just return an empty string - then again, it might just return "false").

Thanks for the heads-up.

Regards,
Brian

JavaScript Noob
#39 · Tuesday October 10, 2006

Your demo of this scripts looks fantastic.

I would love to implement this script on a site I am working on, but I have a small problem…

I can’t seem to get the script to initiate.

The JS is included in the head properly (and I have not made any changes to the .js file whatsoever. Also, I have replaced the opening < with a # to get it to display here): #script type="text/javascript" src="/_scripts/table-sorter/tablesort.js">#/script>

The table is created with a proper structure; I show up to and including the thead (I have replaced the opening < with a # to get it to display here):

#table id=”theTable” class=”sortable rowstyle-alternative” width=”100%”>

#thead>

#tr>

#th class=”sortable-text”>Name#/th> #th>Address#/th> #th class=”sortable-text”>City#/th> #th class=”sortable-text”>Postcode#/th> #th>Telephone#/th>

#/tr>

#/thead>

I am sure I am just being an idiot; can anybody shed some light on how to ensure the script is picking up the table and doing its magic to it?

Frequency Decoder
#40 · Tuesday October 10, 2006

@ JavaScript Noob: Hi, try adding an alert(‘hello world’) as the first line of the tablesort.js “init” method (line 42).

If you reload the page and don’t get the “hello world” alert then something included after the file has overridden the window.onload event (has you page a BODY onload=... for example ?)

Hope this helps,
Brian.

JavaScript Noob
#41 · Tuesday October 10, 2006

Hi,

I have tried this; I don’t appear to be getting the alert message.

I have now created a new page, with the JS being linked within the head of the document.

A simple 6-column table has been added, with the table tag having a class of “sortable-onload-6 rowstyle-alternate”

The table headers have a class of “sortable-text” and the rows below are filled with single letters (see example below):

| a | g | z |
===

| p | r | e |
===

| c | e | u |

This doesn’t seem to work either. No alert. No sorting (even with the alert removed from the JS). No alternate row classes applied.

There doesn’t appear to be no client-side JavaScript issues, as sIFR is working on the rest of the site (but is not included with the simple page I have created).

Any ideas what I am doing wrong?

Lucas Williams · http://www.beyondthepixel.com
#42 · Tuesday October 10, 2006

How do I change the color of the headers? They’re all white I’d like to make them somethin different please :D

Lucas Williams · http://www.beyondthepixel.com
#43 · Tuesday October 10, 2006

nevermind LoL… had some conflicting CSS… great script though :D thanks a lot

Chris
#44 · Wednesday October 11, 2006

I have a really basic question (I hope). First off, the script works wonderfully, from a functionality standpoint. However, the table that I’m sorting is heavily formatted with an internal CSS which is now being overwritten by the formatting of the script; essentially everything that’s been tagged with ‘th’ (only the columns I want to sort). I’m trying to get around this and so far the only concept that seems like it will work is for me to create a custome sort-type for each column and then format them using something akin to ‘th.newsorttype’. The problem is that I have no java experience so when I tried to look at the .js source code in hopes to “copy/paste” the code for the text/date/numeric sort types to create my own…. well, I have no idea where to begin or how to write my own from scratch.

If anyone has any thoughts, suggestion or help – I would be so totally greatful.

Chris
#45 · Wednesday October 11, 2006

I’ve been playing around with it some more and have made some headway; though I’ve had no success in creating any custom sort functions, I’ve just been “working” with the existing ones: sortable-text, etc. If anyone has any input on that, I’d still GREATLY appreciate it.

For some reason I’m unable to get the text of the column headers to all stay a single color, and that color’s “white.” I think I’ve copied over every possible “th” tag that’s in the demo’s source and implimented it into my own; and changed every single value to #FFFFFF but still they refuse to change and revert back to the “default” blue. I have been able to get the “active” sorted text to stay white…. but that’s not quite good enough… :(

Frequency Decoder
#46 · Wednesday October 11, 2006

@ JavaScript Noob: Send the .html (if it’s a dynamically created page, do a “view source”, copy, paste, save; and send me the saved file) to brian [at] modernartcafe [d0t] net and I’ll look into it.

@ Lucas: Good to hear you sorted it out.

@ Chris: Hi Chris, the script only sorts and rearranges the table rows, all of the row’s “styles” will be kept after the sort (the table overwrites no classNames etc) so I don’t understand how the script is restyling the table. Again, send the .html and the .css files to brian [at] modernartcafe [d0t] net and I’ll look into it.

Regards,
Brian.

Frequency Decoder
#47 · Wednesday October 11, 2006

@ Chris: Check that out, you posted your comment 4 seconds before me! Anyway, were talking a CSS problem here, not a JavaScript problem. If you want all the TH nodes to contain white text, this has to be specified within the CSS, for example:

th, th a { color:#fff !important; }

Hope this helps,
Brian.

Merucry · http://emailer.utilstore.com/
#48 · Wednesday October 11, 2006

It seems that you have not been updating the european version. It didnt worked, but the other one did.

Merucry · http://emailer.utilstore.com/
#49 · Wednesday October 11, 2006

The problem stated in the #37 seems to be still present. I am using Firefox 1.5.0.7

Thanks again.

Chris
#50 · Wednesday October 11, 2006

th, th a { color:#fff !important; }
Hope this helps,
Brian.

Well, I’m not sure how the format for the CSS was being tossed aside…wait, yes I do (I think). Each of those headers that now has a class of “sortable-___” previously was defined by a class from my CSS, so I think that’s what the problem has been. I would like to note however that that one (fricken) line you gave me totally fixed the problem I was having :) Yea!!!—————————————————————————————————————-
If at all possible, I would still like to get the code for creating those custom functions for numeric and text because I think my code – while working – is extremely bloated now… but it works!! Brian, your script is awesome and your help phenomenal, thanks!

Frequency Decoder
#51 · Thursday October 12, 2006

@ Merucry: Hi, the “undefined” className problem has been fixed and the European version updated accordingly (I’m using the FireFox “View Source Chart” extension to check the classNames). Remember to clear the browser cache in order to download the new version (when looking at the demo).

@ Chris: Glad you got it sorted out. I’m still unsure as to why you want to write custom functions for numeric and text values when the script contains two such functions already.

Regards,
Brian.

Bill Maas · http://www.edam-volendam650.nl/reportages.php
#52 · Thursday October 12, 2006

Hi Brian,
Your table sort functions work perfectly on my site.
Fantastic peace of software!
But when I switched over to the European date version, I got a syntax error on line 346 char. 10.
The errror is not obvious to me, so I can not fix it.
Please have a look into this.
Keep up the good work!
Bill

Frequency Decoder
#53 · Thursday October 12, 2006

@ Bill: Download the updated version.

Regards,
Brian.

Max M.
#54 · Friday October 13, 2006

First of all, thank you for spending your time supporting your script.

I am using your script right now and everything is great, but being a javascript newbie i’m not sure how to modify the code to reverse sort a column or sort it twice on load? Do you think you can point me into the right direction?

-THANKS

Frequency Decoder
#55 · Friday October 13, 2006

@ Max M: Off the top of my head, you could try this…

function myDoubleSortOnLoad() {

fdTableSort.jsWrapper(“yourTableId”, colNum);
}

fdTableSort.addEvent(window, “load”, function() {

setTimeout(“myDoubleSortOnLoad()”, 2000);
});

it’s a dirty hack and extremely bad programming practice but there you go…

binbarn
#56 · Friday October 13, 2006

How can I store the sort order in a cookie? Is there a step by step explaination anywhere for dumb people?

Max M.
#57 · Friday October 13, 2006

Hmm when I tried your dirty hack, it didn’t work and made it where the table became unsortable.

The double sort actually isn’t too important to me, but what i would like to be able to do is have alternating colors without having to identify a class, because i update the table often often and everytime i do that i have to go through and change all the classes to their opposite, so that when the page loads it initially has colored rows. When i update the table i add it to the top of the table so most recent additions are at the top. If i could get it to double sort onload by date i figured i could have most recent on top and have the sort cause the rows to be alternated colors.

any suggestions?

Thank you

Luis
#58 · Saturday October 14, 2006

I would like to have a sortable tabel in which I could sort two rows as a group.
I would use this in order to get some sortable data into the first row and a hidden div into the second one.
Then I could load info on the data of the first line through ajax and show this in the downsliding div just under the data.
The best would be to still able to sort the table with this active info divs underneath.

Is this somehow possible??

thanks in advance and great work

Max M.
#59 · Saturday October 14, 2006

i actually found a solution to my problem. i have a hidden column that has a really big number like 1 billion and everytime I add a new row to the table i will make the value of that 1 less, then sort onload by that. It’s kind of a hokey solution but oh well.

-thx

Xavier
#60 · Saturday October 14, 2006

I’m seriously impressed. That’s what javascript should be about. enhancing the browsing experience, without messing the layout and let the content accessible where it belongs in the html page.

Then, I discovered your date picker. Another great one. I see a pattern, beware, you’ve got a fan !

Ok, a question/suggestion:

I’d like to be able to filter on the top/instead of sorting. I have in mind some drop-down menu, ala what you can get with access. Would it make sense for your to add a fitrable class ? This would parse the content of the table, and populate the drop-down list for that.

Chapeau bas, monsieur

Frequency Decoder
#61 · Monday October 16, 2006

@ binbarn: Hi binbarn, there’s currently no inbuilt functionality that enables you to store the sort position within a cookie. Sorry.

@ Max M: Hi Max, if all you want to do is color the rows, you should write a small script that does this for you. If you need a bit of help, mail me at brian [at] modernartcafe [d0t] net and I’ll send you a function that does just that.

@ Luis: Luis, just add the div to the first row (as the last child of the TD node) and forget about the second row, this way, the script will work “out of the box” so to speak.

@ Xavier: Hi Xavier, I’m glad you like the script. I’m a bit dumb this fine Monday morning and can’t quite figure out what you mean by “filter” (sorry). – can you explain in a bit more detail (or point me to a page that has this Access feature explained). Thanks.

Regards,
Brian.

Max M.
#62 · Monday October 16, 2006

Me again! Hey…what toLowerCase parts would i have to take out if i wanted to make the sort case sensitive? Or would taking those out without adding something else not do the trick?

Thank You

Max M.
#63 · Monday October 16, 2006

Also I was trying to do the reverse sort on the date mostly. Right now i have that hidden sortable column that has 10000 as a value and everytime i add a row i subtract 1 from the value. So each newer addition has a lower value and will sort to the top. If making it sort twice or reverse sort is something you have time to explain I would love to hear it through e-mail or this commenting section.

thanks again

Xavier
#64 · Tuesday October 17, 2006

Brian,

Let me clarify the filtering thing.

Say that on one of your column, you’ve got discreet values (coutries, gender, boolean, month…).
Right now, you can sort them (Austria, Belgium, Canada…). What I’d like to be able to do is to filter them to get only the people in France (or Belgium or… ;)

This is a feature often used in excel (sorry not access, didn’t help the previous explaination) for instance.

I see how to build the filter select, I don’t know what would be the clevest way of applying the filter to hide all the rows that haven’t that value (all the rows that aren’t France).

Am I clearer this morning ?

Feel free to contact me by mail.

Kenshin
#65 · Tuesday October 17, 2006

Great work Brian!

I noticed that when I don’t presort the table

(i.e. using class=”sortable-onload rowstyle-alternative no-arrow” instead of class=”sortable-onload-1 rowstyle-alternative no-arrow”)

the alternate table coloring doesn’t work until I sort the table for the first time. Am I doing something wrong or is that just the way it is?

Thanks again!

Simon
#66 · Tuesday October 17, 2006

Thank you very much for the great script. I desperately need to store the current sort in a cookie. This is so that the sort can be persisted over my paginated script etc. I’d really appreciate it if you can could give me an idea of how the cookie can be applied and used. Many thanks.

Francois
#67 · Tuesday October 17, 2006

how to adjust the sort method to get the correct alphabetic order with danish letters like å ø æ, which should go after the Z letter : a,b,c, ... x,y,z,å,æ,ø.
Thanks for your help!

Frequency Decoder
#68 · Wednesday October 18, 2006

@ Max M: Hi Max, change lines 203 and 220 from:

txt = txt.toLowerCase();

to

txt = String(txt);

to remove the case-sensitivity. Alternatively, you could write a bespoke sortInsensitive function like so:

function sortCaseInsensitive(a,b) {

return fdTableSort.sortText(a,b);
}

and give your TH tags the classname “sortable-sortCaseInsensitive”.

@ Xavier: Hi Xavier, you would need to write another widgit entirely to handle the data filter. The “prepareTableData” method could easily be altered to also save an array of unique column data (and this could be used to create the dropdown filter). It’s more scripting than I currently have the time to tackle so, unfortunately, I can’t offer to help. Sorry…

@ Simon: Hi Simon, there’s currently no cookie based save integrated into the script. Storing sort patterns in this way is made more complicated by the fact that the stored column state could be “reverseSort” which means the script would untimatly need to sort the column twice on page load (once to forwardSort and once to reverseSort). It’s entirely feasable though – I just haven’t got the time to write the code. Again, sorry!

@ Kenshin: The “sortable-onload” requires a column number (the script needs to be told which column to use when sorting the table). Hope this helps.

@ Francois: I would have thought that all of these characters were automatically sorted correctly by the sort-text function? If not, you could write a bespoke sort function and associated prepareData function. The prepareData method could replace any of these danish characters with any ASCII character having a character code value larger than “Z” and the sort function could then just call the inbuilt fdTableSort.sortText method as shown above in the response to Max M.

Regards,
Brian.

Ajnasz
#69 · Wednesday October 18, 2006

Hi!

Your script is amazing, it’s faster than any other, so I decided, I will use it for large tables. But I need some new feature, like line filtering or selecting lines. I start write these functions, but I read your licence just now, which is not allow me, to modify your code.
So I ask you to permit me to modify your code. I still not publicate and use any code, but naturally I will share everything when I finished.
Can I add these new functions or not?

Regards,
Ajnasz

Rich · http://none
#70 · Wednesday October 18, 2006

If you click on the arrow the text disappears. :(

Do you have an example of the sortable-onload- ???

Frequency Decoder
#71 · Thursday October 19, 2006

@ Ajnasz: Hi Ajnasz, I’ll be updating the license this week. Stay tuned.

@ Rich: ‘The text disappears’? Can you give me a little bit more detail; the browser and O/S etc – thanks. Also, the very first table within the demo is the sort-onload example. Look at the source code to see how it was initiated.

Regards,
Brian.

Santiago
#72 · Friday October 20, 2006

hi, does anybody knows if this Script will work with EzResults?
i need that the sort by column persist on links of paginations.

:( Sorry my bad english.

Andy Ford · http://analogpanda.com
#73 · Friday October 20, 2006

Wow. This script is really handy! Thank you so much for sharing you hard work with the community. I’m using it on a table with 10 columns – one of which is “comments”. These comments can be very long, so they’re tuncated in PHP and I’m using Dustin Diaz’s SweetTitles so users may hover over the truncated comment to see the full text. I’m very pleased with the results. I’m also using the Silk Icons from famfamfam.com – it’s wonderful to be able to leverage so many open source resources these days!

One question (I’m at home with xhtml/css, but my javascript skills are nil)... Currently the script takes the entire contents of TH’s and transforms them to a link. Could this be limited to perhaps just transforming what’s inside a STRONG within the TH?? That would allow me to keep my SMALL ”(hover for more details)” /SMALL inside the TH without transforming it to a link. – thanks!

edu ser
#74 · Saturday October 21, 2006

Hi and thanks for this fabulous script.
I was using a previous version of this script in a project, when I realised that you have a new version. Downloaded and upgraded. But know with the new version I keep getting an error in some tables, can you check it?

The colume is an “area” and the data like “400 m2” beeing “m2” the unit. Another one is in date format.
The problem is that it doesn’t sort and then posts an errot in line 171 char 17 ”’undefined’ is null or not an object”.

Regards,
Edu.

Chris
#75 · Saturday October 21, 2006

I wanted to revisit the reverse sort that you mentioned Brian on #55… namely that’s exactly what I’m after, I have a date format I’d like to sort in descending order (newest to oldest) and I tried plugging in that bit of code, but to no avail. So I’m not sure where I’ve gone wrong, here’s the code as I had it in the tablesort.js (at the bottom of the script)
—————————————————————-
function myDoubleSortOnLoad() {
fdTableSort.jsWrapper(“reviewArc”, 4);
}

fdTableSort.addEvent(window, “load”, function() {
setTimeout(“myDoubleSortOnLoad()”, 2000);
});
—————————————————————-
So basically the table’s ID is “reviewArc” and the column I’m after to sort is #4. The class of the column is “sortEnglishLonghandDateFormat”. Now, when the page loads it does sort it twice, once in Ascending order and then the second time in a random order… it’s very strange.

ps. I gave up on the idea of creating a bunch of custom classes (#50 above); I don’t really need them right now anyway :)

frequency decoder
#76 · Monday October 23, 2006

@ Santiago: Hi Santiago I have no idea if the script works with ezResults but it most probably will not if were talking Ajax and result paginations. Sorry.

@ Andy Ford: Hi Andy, (off the top of my head) changing the following few lines of code should do the trick:

change…

89: thtext = fdTableSort.getInnerText(th);
91: while(th.firstChild) th.removeChild(th.firstChild);
98: th.appendChild(aclone);

to…

89: thtext = fdTableSort.getInnerText(th.getElementsByTagName(‘strong’)[0]);
91: var strong = th.getElementsByTagName(‘strong’)[0];

while(strong.firstChild) strong.removeChild(strong.firstChild);
98: strong.appendChild(aclone);

@ edu ser: Hi edu, I’m going to need a bit more info in order to help you out. Can you send the HTML for the table (or tables) you are atempting to sort (as a .txt file or my spam filters will automatically delete the mail) to brian [at] modernartcafe [d0t] net and I’ll attempt to track the problem down for you.

@ Chris: Hi Chris, Here’s a quick testcase that I have working that uses the callback functionality:

var sorted = false;
function sortCompleteCallback() {

if(!sorted) { sorted = true; fdTableSort.jsWrapper(“theTable”, 0); }
}

Just add the above code snippet to the HTML document (between script tags within the head section of course).

In researching your problem, I also fixed a rather nasty bug when using the jsWrapper method (I’m suprised that no one has noticed it before!) so you will have to download the updated source again.

Regards,
Brian.

Lucas Williams · http://www.beyondthepixel.com
#77 · Monday October 23, 2006

Is there a way to make it so the “non-alternate” row is another color besides white. In the CSS if I give the TRs a value of say… background: #0066ff; then it’ll just convert all the TRs to that color and ignore the alternating row color. Thanks for any help anyone can provide :)

-Lucas

frequency decoder
#78 · Tuesday October 24, 2006

@ Lucas: Hi Lucas, I don’t have any such problem using the following CSS (tested on Internet Explorer 6 and Firefox):

tr { background: #0066ff; }
tr.alternative { background: #f5fafa; }

It must be a specifity problem within your CSS. Check the CSS declarations and try to spot a more specific rule (an id applied to the table may be out-weighing the generic tr rule for example).

Regards,
Brian.

Lucas Williams · http://www.beyondthepixel.com
#79 · Tuesday October 24, 2006

Ahhh…. I got it I didn’t have it declared as tr.alternate… I just had plain old .alternate which apparently it wasn’t feelin’, thanks for the hook up :)

Andy Ford · http://analogpanda.com
#80 · Tuesday October 24, 2006

@Brian – Thanks for your assistance (#73/#76) – unfortunately I couldn’t get it working. As I mentioned my JS abilities are virtually non-existant. However, when reading through your code changes it looked to be making sense. I wasn’t sure where to put:

while(strong.firstChild) strong.removeChild(strong.firstChild);

so I tried it directly below line 91 as well as directly above line 98 – but still no luck. I did notice that the SMALL elements were being treated differently than in the original code, but nothing inside the TH elements were being turned into sort links.

I got to thinking though, that having anything inside a TH besides the actual heading may not be very semantic (such as my hover for full text “helper” instruction). So my workaround is to add a new TR inside the THEAD so it won’t be sorted and so I can put my extra instructions (“hover” etc) inside regular TD’s… I can’t decide if it’s semantically any better or worse than having the extra STRONG and SMALL elements inside the TH element (although I’m thinking it’s a tad more semantic… maybe) – but I think it makes sense and it works for me

Ajnasz · http://ajnasz.hu
#81 · Wednesday October 25, 2006

Hi!

I’m here again. Thank you for change the licence. Now I realized the first version of my script, so you (and everyone) can try it on the following address: http://viala.hu/html/tablesort.html

Thanks again,
Ajnasz

Xavier
#82 · Wednesday October 25, 2006

@Ajnasz,

Like a good start, but it doesn’t seem to work with firefox. For instance, the double click is always seen as a single one and couldn’t find a way to apply the filter I typed.

Moreover, a little ergonomic concern: I’m not sure the double click to sort is the most obvious solution.

What about adding a “filter” icon next to the title instead ?

X+