spacer
XML Gov Logoflag
spacer

XML.Gov Demos: Cross Browser: JavaScript Sorting

by Manos Batsis

Purpose: This demo is conceptually similar to the sortable table idea of the 107th Congress example on the xml.house.gov site, although the implementation is completely different. In this case, the data comes from a Greek HTML document. There is no XSLT involved. Only JavaScript is used to sort the columns in either ascending or descending order. This illustrates cross-browser, client-side sorting of columns of data. Although the data to be sorted is contained in a static HTML document, it could be replaced by XSLT-generated HTML from an XML source.

Usage: Clicking on any column heading will sort all data in ascending order by that column's criterion. Clicking again on the same column heading will sort in descending order. With Netscape 6+, there is no visual cue that the column heading is active, whereas with IE, a hand cursor appears. Individual cells are selectable, intended to display a file, but since the files aren't present on my server, nothing happens. I've added highlighting on mouseover to the original, border around table headings, and reverse highlighting when column headings are selected. -- kbs

Try the cross-browser sorting of Greek HTML data in either Netscape 6+ or IE 5.5+.

Explanation from Author of Code

	From: m batsis 
	To: Ken Sall ; xml-dev@lists.xml.org 
	Sent: Sunday, Sept. 2, 2002 4:18 AM
	Subject: Re: [xml-dev] Client-side sorting without Microsoft extensions?
	
	Ken,
	
	IMHO, XSLT is a really bad option for what you are asking. JavaScript is 
	much better for sorting tables based on the column type, since XSLT is 
	an overhead and does not have a Date type.
	
	You can find a JavaScript Implementation of a table sorter and a use 
	sample attached. You can use it to sort based on date (various formats), 
	numbers etc. Sorry for the poor documentation (and the example in Greek 
	;-) but I was in a real hurry... you just got written permission to do 
	whatever with it. I'll probably group this script with some other stuff 
	and package it under the GPL or something when I find some time.
	
	If you still want a crossbrowser XSLT API for javascript, I can email 
	you something I'm working on (stable code, no errors or bugs) when I get 
	home (in a day or two). Note however, that the XSLT interfaces for 
	Mozilla/Netscape are not stable, meaning they'll probably change in a 
	future release.
	
	Cheers,
	
	Manos

Return to Demo Home

Last Updated: September 4, 2002