Jump to content

Help talk:Sorting

From Meta, a Wikimedia project coordination wiki
This is an archived version of this page, as edited by Patrick (talk | contribs) at 11:24, 19 June 2007 (What about where there's no figure?: display:none). It may differ significantly from the current version.

Latest comment: 17 years ago by Patrick in topic What about where there's no figure?

Modified version

Below is a proposed adapted version of sorttable.js, with my changes indicated as such. It allows proper sorting of e.g. w:List of countries by population density, after a few modifications, see w:User:Patrick/list of countries.--Patrick 15:54, 19 January 2007 (UTC)Reply

However, in the meantime there have been some improvements in the first-mentioned version, with which improvements below could be merged.--Patrick 10:24, 25 March 2007 (UTC)Reply

 * Table sorting script  by Joost de Valk, check it out at http://www.joostdevalk.nl/code/sortable-table/.
 * Based on a script from http://www.kryogenix.org/code/browser/sorttable/.
 * Distributed under the MIT license: http://www.kryogenix.org/code/browser/licence.html .
 *
 * Copyright (c) 1997-2006 Stuart Langridge, Joost de Valk.
 *
 * @todo don't break on colspans/rowspans (bug 8028)
 * @todo language-specific digit grouping/decimals (bug 8063)
 * @todo support all accepted date formats (bug 8226)
 */

var image_path = stylepath+"/common/images/";
var image_up = "sort_up.gif";
var image_down = "sort_down.gif";
var image_none = "sort_none.gif";
var europeandate = wgContentLanguage != "en"; // The non-American-inclined can change to "true"

var alternate_row_colors = true;


hookEvent( "load", sortables_init);

var SORT_COLUMN_INDEX;
var thead = false;

//change by Patrick: added:
function removeSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}

function sortables_init() {
	var idnum = 0;
	// Find all tables with class sortable and make them sortable
	if (!document.getElementsByTagName) return;
	tbls = document.getElementsByTagName("table");
	for (ti=0;ti<tbls.length;ti++) {
		thisTbl = tbls[ti];
		if ( (' '+thisTbl.className+' ').indexOf("sortable") != -1 ) {
			if (!thisTbl.id) {
				thisTbl.setAttribute('id','sortable_table_id_'+idnum);
				++idnum;
			}
			ts_makeSortable(thisTbl);
		}
	}
}

function ts_makeSortable(table) {
	if (table.rows && table.rows.length > 0) {
		if (table.tHead && table.tHead.rows.length > 0) {
			var firstRow = table.tHead.rows[table.tHead.rows.length-1];
			thead = true;
		} else {
			var firstRow = table.rows[0];
		}
	}
	if (!firstRow) return;

	// We have a first row: assume it's the header, and make its contents clickable links
	for (var i=0;i<firstRow.cells.length;i++) {
		var cell = firstRow.cells[i];
		var txt = ts_getInnerText(cell);
		if (cell.className != "unsortable" && cell.className.indexOf("unsortable") == -1) {
//change by Patrick: add link to cell.innerHTML instead of to txt, to allow links in headers
			cell.innerHTML += '  <a href="#" class="sortheader" onclick="ts_resortTable(this);return false;"><span class="sortarrow"><img src="'+ image_path + image_none + '" alt="↓"/></span></a>';
		}
	}
	if (alternate_row_colors) {
		alternate(table);
	}
}

function ts_getInnerText(el) {
	if (typeof el == "string") return el;
	if (typeof el == "undefined") { return el };
	if (el.innerText) return el.innerText;	//Not needed but it is faster
	var str = "";
	
	var cs = el.childNodes;
	var l = cs.length;
	for (var i = 0; i < l; i++) {
		switch (cs[i].nodeType) {
			case 1: //ELEMENT_NODE
				str += ts_getInnerText(cs[i]);
				break;
			case 3:	//TEXT_NODE
				str += cs[i].nodeValue;
				break;
		}
	}
	return str;
}

function ts_resortTable(lnk) {
	// get the span
	var span;
	for (var ci=0;ci<lnk.childNodes.length;ci++) {
		if (lnk.childNodes[ci].tagName && lnk.childNodes[ci].tagName.toLowerCase() == 'span') span = lnk.childNodes[ci];
	}
	var spantext = ts_getInnerText(span);
	var td = lnk.parentNode;
	var column = td.cellIndex;
	var table = getParent(td,'TABLE');

	// Work out a type for the column
	if (table.rows.length <= 1) return;

	for( var i = 1, itm = ""; itm.match(/^([\s]|\n|\ |<!--[^-]+-->)*$/); i++) {
		var itm = ts_getInnerText(table.tBodies[0].rows[i].cells[column]);
		itm = trim(itm);
	}
	sortfn = ts_sort_caseinsensitive;
	if (itm.match(/^\d\d[\/. -][a-zA-Z]{3}[\/. -]\d\d\d\d$/)) sortfn = ts_sort_date;
	if (itm.match(/^\d\d[\/.-]\d\d[\/.-]\d\d\d\d$/)) sortfn = ts_sort_date;
	if (itm.match(/^\d\d[\/.-]\d\d[\/.-]\d\d$/)) sortfn = ts_sort_date;
//change by Patrick: replaced: if (itm.match(/^[£$€Û¢´]/)) sortfn = ts_sort_currency;
	if (itm.match(/^[£$€¢]/)) sortfn = ts_sort_currency;

//change by Patrick: allow point, comma, space, -, e, and E in numbers
     itm = removeSpaces(itm);
     if (itm.match(/^[\d\.\,\-eE]+$/)) sortfn = ts_sort_numeric;
	SORT_COLUMN_INDEX = column;
	var firstRow = new Array();
	var newRows = new Array();

	for (k=0;k<table.tBodies.length;k++) {
		for (i=0;i<table.tBodies[k].rows[0].length;i++) {
			firstRow[i] = table.tBodies[k].rows[0][i];
		}
	}

	for (k=0;k<table.tBodies.length;k++) {
		if (!thead) {
			// Skip the first row
			for (j=1;j<table.tBodies[k].rows.length;j++) {
				newRows[j-1] = table.tBodies[k].rows[j];
			}
		} else {
			// Do NOT skip the first row
			for (j=0;j<table.tBodies[k].rows.length;j++) { 
				newRows[j] = table.tBodies[k].rows[j];
			}
		}
	}

	newRows.sort(sortfn);

	if (span.getAttribute("sortdir") == 'down') {
			ARROW = '<img src="'+ image_path + image_down + '" alt="↓"/>';
			newRows.reverse();
			span.setAttribute('sortdir','up');
	} else {
			ARROW = '<img src="'+ image_path + image_up + '" alt="↑"/>';
			span.setAttribute('sortdir','down');
	} 
	
	// We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
	// don't do sortbottom rows
	for (i=0; i<newRows.length; i++) {
		if (!newRows[i].className || (newRows[i].className && (newRows[i].className.indexOf('sortbottom') == -1))) {
			table.tBodies[0].appendChild(newRows[i]);
		}
	}
	// do sortbottom rows only
	for (i=0; i<newRows.length; i++) {
		if (newRows[i].className && (newRows[i].className.indexOf('sortbottom') != -1))
			table.tBodies[0].appendChild(newRows[i]);
	}

	// Delete any other arrows there may be showing
	var allspans = document.getElementsByTagName("span");
	for (var ci=0;ci<allspans.length;ci++) {
		if (allspans[ci].className == 'sortarrow') {
			if (getParent(allspans[ci],"table") == getParent(lnk,"table")) { // in the same table as us?
				allspans[ci].innerHTML = '<img src="'+ image_path + image_none + '" alt="↓"/>';
			}
		}
	}

	span.innerHTML = ARROW;
	alternate(table);		
}

function getParent(el, pTagName) {
	if (el == null) {
		return null;
	} else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase()) {	// Gecko bug, supposed to be uppercase
		return el;
	} else {
		return getParent(el.parentNode, pTagName);
	}
}

function sort_date(date) {	
	// y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX
	dt = "00000000";
	if (date.length == 11) {
		monthstr = date.substr(3,3);
		monthstr = monthstr.toLowerCase();
		switch(monthstr) {
			case "jan": var month = "01"; break;
			case "feb": var month = "02"; break;
			case "mar": var month = "03"; break;
			case "apr": var month = "04"; break;
			case "may": var month = "05"; break;
			case "jun": var month = "06"; break;
			case "jul": var month = "07"; break;
			case "aug": var month = "08"; break;
			case "sep": var month = "09"; break;
			case "oct": var month = "10"; break;
			case "nov": var month = "11"; break;
			case "dec": var month = "12"; break;
			// default: var month = "00";
		}
		dt = date.substr(7,4)+month+date.substr(0,2);
		return dt;
	} else if (date.length == 10) {
		if (europeandate == false) {
			dt = date.substr(6,4)+date.substr(0,2)+date.substr(3,2);
			return dt;
		} else {
			dt = date.substr(6,4)+date.substr(3,2)+date.substr(0,2);
			return dt;
		}
	} else if (date.length == 8) {
		yr = date.substr(6,2);
		if (parseInt(yr) < 50) { 
			yr = '20'+yr; 
		} else { 
			yr = '19'+yr; 
		}
		if (europeandate == true) {
			dt = yr+date.substr(3,2)+date.substr(0,2);
			return dt;
		} else {
			dt = yr+date.substr(0,2)+date.substr(3,2);
			return dt;
		}
	}
	return dt;
}

function ts_sort_date(a,b) {
	dt1 = sort_date(ts_getInnerText(a.cells[SORT_COLUMN_INDEX]));
	dt2 = sort_date(ts_getInnerText(b.cells[SORT_COLUMN_INDEX]));

	if (dt1==dt2) {
		return 0;
	}
	if (dt1<dt2) {
		return -1;
	}
	return 1;
}

function ts_sort_currency(a,b) {
	aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,'');
	bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,'');
	return compare_numeric(aa,bb);
}
 
function ts_sort_numeric(a,b) {
	aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
	bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
	return compare_numeric(aa,bb);
}
 
function compare_numeric(a,b) {
//change by Patrick: remove spaces and commas
    a = a.replace(/,/g,'');
    a = removeSpaces(a);
    a = parseFloat(a);
    if (isNaN(a)) a = 0;
    b = b.replace(/,/g,'');
    b = removeSpaces(b);
    b = parseFloat(b); 
    if (isNaN(b)) b = 0;
//change by Patrick: replaced: a = parseFloat(a.replace(/,/, ""));
//                             a = (isNaN(a) ? 0 : a);
//                             b = parseFloat(b.replace(/,/, ""));
//                             b = (isNaN(b) ? 0 : b);
	return a - b;
}

function ts_sort_caseinsensitive(a,b) {
	aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).toLowerCase();
	bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).toLowerCase();
	if (aa==bb) {
		return 0;
	}
	if (aa<bb) {
		return -1;
	}
	return 1;
}

function ts_sort_default(a,b) {
	aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
	bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
	if (aa==bb) {
		return 0;
	}
	if (aa<bb) {
		return -1;
	}
	return 1;
}

function addEvent(elm, evType, fn, useCapture)
// addEvent and removeEvent
// cross-browser event handling for IE5+,	NS6 and Mozilla
// By Scott Andrew
{
	if (elm.addEventListener){
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent){
		var r = elm.attachEvent("on"+evType, fn);
		return r;
	} else {
		alert("Handler could not be removed");
	}
} 

function replace(s, t, u) {
	/*
	**  Replace a token in a string
	**    s  string to be processed
	**    t  token to be found and removed
	**    u  token to be inserted
	**  returns new String
	*/
	i = s.indexOf(t);
	r = "";
	if (i == -1) return s;
	r += s.substring(0,i) + u;
	if ( i + t.length < s.length) {
		r += replace(s.substring(i + t.length, s.length), t, u);
	}
	return r;
}

function trim(s) {
	return s.replace(/^([ \t]|\n|\ |<!--[^-]+-->)*/, "").replace(/([ \t]|\n|\ |<!--[^-]+-->)*$/, "");
}

function alternate(table) {
	// Take object table and get all it's tbodies.
	var tableBodies = table.getElementsByTagName("tbody");
	// Loop through these tbodies
	for (var i = 0; i < tableBodies.length; i++) {
		// Take the tbody, and get all it's rows
		var tableRows = tableBodies[i].getElementsByTagName("tr");
		// Loop through these rows
		// Start at 1 because we want to leave the heading row untouched
		for (var j = 0; j < tableRows.length; j++) {
			// Check if j is even, and apply classes for both possible results
			if ( (j % 2) == 0  ) {
				if ( !(tableRows[j].className.indexOf('odd') == -1) ) {
					tableRows[j].className = replace(tableRows[j].className, 'odd', 'even');
				} else {
					if ( tableRows[j].className.indexOf('even') == -1 ) {
						tableRows[j].className += " even";
					}
				}
			} else {
				if ( !(tableRows[j].className.indexOf('even') == -1) ) {
					tableRows[j].className = replace(tableRows[j].className, 'even', 'odd');
				} else {
					if ( tableRows[j].className.indexOf('odd') == -1 ) {
						tableRows[j].className += " odd";
					}
				}
			} 
		}
	}
}

Multirow header bug?

Hello, I waited a long time for the sorting feature and I'm glad it's here. Despite of this I think to have found a bug:

 {| class='sortable' border=1
 !area<br />m^2
 !length<br />m
 |-
 |5
 |10
 |}

produces:

area
m^2
length
m
5 10

while it works for non sorting tables:

area
m^2
length
m
5 10

same for the <table> notation. Workaround? --Ikiwaner 19:37, 11 January 2007 (UTC)Reply

That is also fixed with the proposed version above.--Patrick 16:34, 19 January 2007 (UTC)Reply
Seems like the bug is resolved now as the example above does proper line breaks. --Ikiwaner 09:13, 14 February 2007 (UTC)Reply

Not working properly in Safari 2.0.4

Dynamic sorting is not working properly for me in Safari 2.0.4. The table is always sorted by the first column no matter which column's sort icon you click. 60.242.36.248 01:57, 13 February 2007 (UTC)Reply

I also have this problem. Works fine in Firefox though. Will this bug be fixed anytime soon? --66.91.228.235 06:32, 31 March 2007 (UTC)Reply
Just for the record, the same thing happened for me in Safari 1.3, and, not surprisingly, it still does in 2.0.4. 75.67.255.198 14:10, 5 May 2007 (UTC)Reply

Row/Col Span

Any possibility of being about to sort tables with cells that take of more than one row/column?

Nfearnley 07:36, 13 February 2007 (UTC)Reply

Excluding certain rows

Is it possible to exclude rows from sorting within a table (e.g. last row of table)? 74.139.211.167 05:25, 18 February 2007 (UTC)Reply

Yes, it's possible to keep one or more rows at the bottom of the table like this:
{| class="wikitable sortable"
!Numbers!!Alphabet!!Dates!!Currency!!class="unsortable"|Unsortable
|-
|1||Z||02-02-2004||5.00||This
|-
|2||y||13-apr-2005||||Column
|-
|3||X||17.aug.2006||6.50||Is
|-
|4||w||01.Jan.2005||4.20||Unsortable
|-
|5||V||05/12/2006||7.15||See?
|- class="sortbottom"
!Total: 15!!!!!!Total: 29.55!!
|- class="sortbottom"
!colspan="5"|Example table based on one at [http://www.joostdevalk.nl/code/sortable-table/ this page]
|-
|}
Numbers Alphabet Dates Currency Unsortable
1 Z 02-02-2004 5.00 This
2 y 13-apr-2005 Column
3 X 17.aug.2006 6.50 Is
4 w 01.Jan.2005 4.20 Unsortable
5 V 05/12/2006 7.15 See?
Total: 15 Total: 29.55
Example table based on one at this page

TimR 05:51, 14 March 2007 (UTC)Reply

Somehow the last row disables the sorting of the 2nd and 3rd column, without it everything works:

Numbers Alphabet Dates Currency Unsortable
1 Z 02-02-2004 5.00 This
2 y 13-apr-2005 Column
3 X 17.aug.2006 6.50 Is
4 w 01.Jan.2005 4.20 Unsortable
5 V 05/12/2006 7.15 See?
Total: 15 Total: 29.55

Patrick 09:08, 14 March 2007 (UTC)Reply

Whoops, yes. Sorry. :-) TimR 09:29, 14 March 2007 (UTC)Reply

This information should be moved to the main help page. — cBuckley (TalkContribs) 05:32, 25 March 2007 (UTC)Reply

Partly done -- 87.13.116.74 20:53, 24 April 2007 (UTC)Reply
Completed -- 87.13.116.74 21:25, 24 April 2007 (UTC)Reply
I extended Help:Sorting#Limitations a little.--Patrick 07:46, 25 March 2007 (UTC)Reply

Sort key

Are there any future plans to allow the use of sort keys? I'm specifically thinking of tables with people's names, where you might want to display "John Smith" but sort by "Smith, John". Jwillbur 21:06, 20 February 2007 (UTC)Reply

I have already done this very successfully here by using the method described on the Help:Sorting page itself:
The most versatile is alphabetic sorting using a sortkey which due to CSS is not displayed:
<span style="display:none">...</span>
(however, this more cumbersome method is less often needed after the described fixes are applied)
I have also made some experimental local changes to the MediaWiki table JavaScript code which makes this a whole lot easier. Now I just have to persuade someone to adopt them.... TimR 06:02, 14 March 2007 (UTC)Reply
OK, I've now put together a page describing my progress with sort keys, together with some code to make it work. Details are on the tables page about how to try it, and there are some examples there. Any comments can be left on the corresponding talk page.

Help with dates

We are having trouble with the table here: http://en.wikipedia.org/wiki/List_of_science_fiction_conventions The current attempt tries to use alpha-number sorting with YYYY-MM-DD, Like I would have done with ascii sort. But the table does not take any action at all when you hit the double triangle. at this point an incorrect sort of any kind would be better than no action at all. Feel free to fix the table to make it work. --208.46.106.17 22:57, 27 February 2007 (UTC)Reply

Hurrah! The problem was that some rows did not complete their number of columns all the way out to the end. you must have exactly the right number of ||'s. I discovered the probable cause by making a copy of the table to my user page, and kept cutting it in half, till I found a portion that sorted. That clued me into the nature of the problem. So I fixed all the missing ||'s I could visually find. But some still proved elusive. So I had to keep creating copies of the table, and cutting in half, till I zoomed in on the half that was not working. If I was sure that 1 row of 10 was bad, I could visually find it. But not 1 row out of hundreds. Let us pray for a wysiwyg editor that people can use reliably--Tbmorgan74 20:52, 28 February 2007 (UTC)
Dates still don't sort correctly. I used a sortable table on Wikipedia:Wikipedia:WikiProject Paranormal#Paranormal_Relevant_Deletion_History and it puts 2006 dates after 2007 and puts "November 30, 2006" after May--it's just screwy. Also, can the background not be forced to white but, instead, not be specified so people with darker default background colors (like me) aren't forced to look at an overbearing, glaring, painful white background? -Eep 12:36, 20 May 2007 (UTC)Reply
The allowed date formats are dd-mm-yyyy, dd-mm-yy and "dd aaa dddd". "class=wikitable" is not needed for sorting.--Patrick 22:20, 20 May 2007 (UTC)Reply
Why don't mmmm-dd-yyyy (i.e. January 1, 2000) dates work too? The class on the table is "wikitable sortable". Eep² 01:24, 21 May 2007 (UTC)Reply
(1) That would be nice. Nobody has programmed that yet. (2) These are two classes, you can also just put "class=sortable".--Patrick 10:49, 21 May 2007 (UTC)Reply

Sorting U.S. Radio Station Frequencies

I've read through the main article page, and I'm either missing something, misinterpretting something, or there's no fix for the problem (at least documented).

As an example, if you sort this table by frequency, it should ideally produce a second column of "first, second, third" in order. Anybody have a solution? (en:User:JPG-GR) 68.61.152.219 00:15, 11 April 2007 (UTC)Reply

Frequency Name
100.3 FM Second
89.5 FM First
107.3 FM Third

Due to the texts "FM" the sorting mode is alphabetic, not numeric. With an nbsp code this alphabetic sorting corresponds to numeric:

Frequency Name
100.3 FM Second
 89.5 FM First
107.3 FM Third

Patrick 06:23, 11 April 2007 (UTC)Reply

Doesn't seem to be working entirely as intended. Here's an example with the addition of another station:

Frequency Name
100.3 FM Third
 89.5 FM First
107.3 FM Fourth
 95.3 FM Second

Any recommendations? JPG-GR 05:35, 13 April 2007 (UTC)Reply

I forgot that it depends on the browser: in IE it works, but e.g. not in Firefox. Instead, you can left-pad with invisible zeros using <span style="display:none">..</span>:

Frequency Name
100.3 FM Third
089.5 FM First
107.3 FM Fourth
095.3 FM Second

Patrick 08:44, 13 April 2007 (UTC)Reply

Thanks! A slight tweak of that let me finish my list. :) JPG-GR 22:43, 13 April 2007 (UTC)Reply

Millions

Are there plans to allow the correct sorting of numbers with more than one comma? Having numbers in the millions sorted within the thousands is quite disturbing. w:List of counties in Texas. Searchme 06:05, 11 April 2007 (UTC)Reply

I also hope it will be fixed. It seems easy, "a = a.replace(/,/g,'');" seems the code for removing all commas, i.e., just add the global flag when applying replace. You could ask at bugzilla: if it is not already there [1]. --Patrick 07:22, 11 April 2007 (UTC)Reply

In the meantime it can be fixed in MediaWiki:Common.js. I have done that on Meta, it can also be done on other sites (by a sysop).

Demo:

million test
123.4
2,500,000,000
300,000,000
3,000,000
5,000,000
2,000
4,000
9,999
800,000
900,000

Patrick 09:22, 11 April 2007 (UTC)Reply

Thanks. I don't know who did it, but it's working well now. Searchme 06:50, 14 April 2007 (UTC)Reply
I added it on the English Wikipedia [2].--Patrick 09:30, 14 April 2007 (UTC)Reply

Help talk:Sorting

Hi guys, I need to sort the rows on click of the column header and not just the image. Can anybody provide help on how to achieve this. My code on the jsp is something like this

<table width="100%" class="sortable" id="ExistingList"> <thead> <th> Name </th> <th> Age </th> <th> Date of Birth </th> </thead> </table>

so basically, not only the image but the entire cell should be clickable.

Thanx, --SauravMav 23:31, 16 April 2007 (UTC)Reply

My modifications

Hi all, I'm working on a modification of the sorting script. http://gw.gamewikis.org/wiki/User:PanSola/sortable_mod.js

  • Current changes:
    • Divides the normal rows and "sortBottom" rows before sorting. When re-appending rows back to the body, there's only one traversal through the rows instead of two.
    • Instead of storing properties via table element attributes, keep them in javascript memory to improve speed.
    • Adds the alt fields of images into "innerText"
    • Parses innerText that includes both numbers and letters as "value" and "unit", then sort based on unit first, followed by value. Supports both "(unit) (value)" and "(value) (unit)" ordering. (Issue: ANY item detected as containing both text and numbers will be treated this way.)
  • My to-do list:
    • Allow manual specification of sorttypes via header cell axis (especially to work around the unit-value issue in cases where that behavior is undesired)
    • Allow manual specification of sortkeys via element cell abbr

If anyone else is currently working on, or is interested in working on sorting, please let me know. Thanks! -PanSola 14:38, 19 April 2007 (UTC)Reply

Safari problem

It seems like sorting tables don't work on Safari. I tried on Firefox and it works there. What am I doing wrong? --219.121.89.169 08:08, 22 April 2007 (UTC)Reply

collapsable + sortable?

Is it possible to get a collapsable and sortable table? -Eep² 11:34, 26 May 2007 (UTC)Reply

Yes, I added an example at w:Wikipedia:NavFrame#Collapsible_tableshttp://en.wikipedia.org/wiki/Wikipedia:NavFrame#Collapsible_tables. Use the spelling "collapsible".--Patrick 18:28, 26 May 2007 (UTC)Reply
Thanks for adding that but I'm wondering if there's a way to get the "[hide]/[show]" control to appear to the right of the complete table outside of any cell. Now, it stays in the first header cell, making the cell taller when the "[show]" control appears above the cell's text. Also, is there a way to make the table hidden by default (except the header cells, of course)? (I asked on your talk page too--I forgot we had a discussion going here about it; sorry.) -Eep² 12:00, 27 May 2007 (UTC)Reply
Yes, see two more examples at w:Wikipedia:NavFrame#Auto-collapsing_tableshttp://en.wikipedia.org/wiki/Wikipedia:NavFrame#Auto-collapsing_tables.--Patrick 23:35, 27 May 2007 (UTC)Reply

Initial sorting parameter

is it possible to make a table and define a column which should be initially sorted on opening of this page?

Example: We like to keep track of new books on Wikibooks (NL), I would just like to add a new book at the bottom of the table, but sort the name of the book on alphabetical order. Londenp 19:37, 8 June 2007 (UTC)Reply

No, that does not seem possible. It would be nice, but oddly the main author of the JaveScript code explicitly states that this is not needed because the server could be programmed to do the sorting.[3]--Patrick 23:14, 8 June 2007 (UTC)Reply

Descending Sorting has place value problem

See: http://en.wikipedia.org/wiki/Talk:Religion_in_the_United_States#Full_sortable_table_-_but_descending_sort_has_place_value_problem_still

That happens when a negative number is at the top when pressing the sort button. It has been fixed on Meta in MediaWiki:Common.js, I recommend doing the same on Wikipedia:
Group 1990
x1000
2001
x1000
Numerical
%Change
1990
unadjusted %
2001
unadjusted %
unadjusted
%-%
1990
adjusted %
2001
adjusted %
adjusted
%-%
Adult population, total \1 175,440 207,980 18.55
Adult population, RESPONDED 171,409 196,734 14.77
Total Christian 151,496 159,506 5.29 86.35 76.69 -9.66 88.38 81.08 -7.31
Catholic 46,004 50,873 10.58 26.22 24.46 -1.76 26.84 25.86 -0.98
non-Catholic Xn 105,492 108,633 2.98 60.13 52.23 -7.90 61.54 55.22 -6.33
Baptist 33,964 33,830 -0.39 19.36 16.27 -3.09 19.81 17.20 -2.62
Protestant-no denomination supplied 17,214 4,647 -73.00 9.81 2.23 -7.58 10.04 2.36 -7.68
Methodist/Wesleyan 14,174 14,150 -0.17 8.08 6.80 -1.28 8.27 7.19 -1.08
Lutheran 9,110 9,580 5.16 5.19 4.61 -0.59 5.31 4.87 -0.45
Christian-no denomination supplied 8,073 14,150 75.28 4.60 6.80 2.20 4.71 7.19 2.48
Presbyterian 4,985 5,596 12.26 2.84 2.69 -0.15 2.91 2.84 -0.06
Pentecostal/Charismatic 3,191 4,407 38.11 1.82 2.12 0.30 1.86 2.24 0.38
Episcopalian/Anglican 3,042 3,451 13.45 1.73 1.66 -0.07 1.77 1.75 -0.02
Mormon/Latter-Day Saints 2,487 2,787 12.06 1.42 1.34 -0.08 1.45 1.42 -0.03
Churches of Christ 1,769 2,593 46.58 1.01 1.25 0.24 1.03 1.32 0.29
Jehovah's Witness 1,381 1,331 -3.62 0.79 0.64 -0.15 0.81 0.68 -0.13
Seventh-Day Adventist 668 724 8.38 0.38 0.35 -0.03 0.39 0.37 -0.02
Assemblies of God 660 1,106 67.58 0.38 0.53 0.16 0.39 0.56 0.18
Holiness/Holy 610 569 -6.72 0.35 0.27 -0.07 0.36 0.29 -0.07
Congregational/United Church of Christ 599 1,378 130.05 0.34 0.66 0.32 0.35 0.70 0.35
Church of the Nazarene 549 544 -0.91 0.31 0.26 -0.05 0.32 0.28 -0.04
Church of God 531 944 77.78 0.30 0.45 0.15 0.31 0.48 0.17
Orthodox (Eastern) 502 645 28.49 0.29 0.31 0.02 0.29 0.33 0.03
Evangelical \2 242 1,032 326.45 0.14 0.50 0.36 0.14 0.52 0.38
Mennonite 235 346 47.23 0.13 0.17 0.03 0.14 0.18 0.04
Christian Science 214 194 -9.35 0.12 0.09 -0.03 0.12 0.10 -0.03
Church of the Brethren 206 358 73.79 0.12 0.17 0.05 0.12 0.18 0.06
Born Again \2 204 56 -72.55 0.12 0.03 -0.09 0.12 0.03 -0.09
Nondenominational \2(also included as Xn, despite...) 195 2,489 1,176.41 0.11 1.20 1.09 0.11 1.27 1.15
Disciples of Christ 144 492 241.67 0.08 0.24 0.15 0.08 0.25 0.17
Reformed/Dutch Reform 161 289 79.50 0.09 0.14 0.05 0.09 0.15 0.05
Apostolic/New Apostolic 117 254 117.09 0.07 0.12 0.06 0.07 0.13 0.06
Quaker 67 217 223.88 0.04 0.10 0.07 0.04 0.11 0.07
Full Gospel 51 168 229.41 0.03 0.08 0.05 0.03 0.09 0.06
Christian Reform 40 79 97.50 0.02 0.04 0.02 0.02 0.04 0.02
Foursquare Gospel 28 70 150.00 0.02 0.03 0.02 0.02 0.04 0.02
Fundamentalist 27 61 125.93 0.02 0.03 0.01 0.02 0.03 0.02
Salvation Army 27 25 -7.41 0.02 0.01 0.00 0.02 0.01 0.00
Independent Christian Church 25 71 184.00 0.01 0.03 0.02 0.01 0.04 0.02
Total non Xn religions 5,853 7,740 32.24 3.34 3.72 0.39 3.41 3.93 0.52
Jewish 3,137 2,831 -9.75 1.79 1.36 -0.43 1.83 1.44 -0.39
Muslim/Islamic 527 1,104 109.49 0.30 0.53 0.23 0.31 0.56 0.25
Buddhist 401 1,082 169.83 0.23 0.52 0.29 0.23 0.55 0.32
Unitarian/Universalist 502 629 25.30 0.29 0.30 0.02 0.29 0.32 0.03
Hindu 227 766 237.44 0.13 0.37 0.24 0.13 0.39 0.26
Native American 47 103 119.15 0.03 0.05 0.02 0.03 0.05 0.02
Scientologist 45 55 22.22 0.03 0.03 0.00 0.03 0.03 0.00
Baha'I 28 84 200.00 0.02 0.04 0.02 0.02 0.04 0.03
Taoist 23 40 73.91 0.01 0.02 0.01 0.01 0.02 0.01
New Age 20 68 240.00 0.01 0.03 0.02 0.01 0.03 0.02
Eckankar 18 26 44.44 0.01 0.01 0.00 0.01 0.01 0.00
Rastafarian 14 11 -21.43 0.01 0.01 0.00 0.01 0.01 0.00
Sikh 13 57 338.46 0.01 0.03 0.02 0.01 0.03 0.02
Wiccan 8 134 1,575.00 0.00 0.06 0.06 0.00 0.07 0.06
Deity 6 49 716.67 0.00 0.02 0.02 0.00 0.02 0.02
Druid . 33 . . 0.02 . . 0.02 .
Santeria . 22 . . 0.01 . . 0.01 .
Pagan . 140 . . 0.07 . . 0.07 .
Spiritualist . 116 . . 0.06 . . 0.06 .
Ethical Culture . 4 . . 0.00 . . 0.00 .
Other unclassified non-Xn 837 386 -53.88 0.48 0.19 -0.29 0.49 0.20 -0.29
No religion specified, total 14,331 29,481 105.71 8.17 14.17 6.01 8.36 14.99 6.62
Atheist . 902 . . 0.43 . . 0.46 .
Agnostic 1,186 991 -16.44 0.68 0.48 -0.20 0.69 0.50 -0.19
Humanist 29 49 68.97 0.02 0.02 0.01 0.02 0.02 0.01
Secular . 53 . . 0.03 . . 0.03 .
No religion 13,116 27,486 109.56 7.48 13.22 5.74 7.65 13.97 6.32
Refused to reply to question 4,031 11,246 178.99 2.30 5.41 3.11 2.35 5.72 3.36

Patrick 22:45, 17 June 2007 (UTC)Reply

What about where there's no figure?

Hey people! I just turned the singles list at W:John Mayer discography#Singles into a sortable table, but the flaw I can see with doing this is that if I select to sort by a chart, I would expect the highest charting song to appear at the top, but if something doesn't chart, then it appears to have performed better than the highest charter. Is there a way around this? Something I can enter that doesn't actually affect this? No include or something?

Year Song Album US Hot 100 US AC US Adult Top 40 US Hot AC Airplay
2002 "No Such Thing" Room for Squares 15 11 5 8
2002 "Your Body Is a Wonderland" Room for Squares 18 17 3 15
2003 "Why Georgia" Room for Squares 102 8
2003 "Bigger Than My Body" Heavier Things 33 27 4 21
2004 "Clarity" Heavier Things 125 13
2004 "Daughters" Heavier Things 19 2 1 19
2005 "Who Did You Think I Was" Try! 92
2006 "Waiting on the World to Change" Continuum 14 1 2 18
2007 "Gravity" Continuum 71 10
2007 "Belief" (South Africa only) Continuum

lincalinca

I figured it out (well, I have a workaround at least). I made the chart position "9999" and made it the colour of the cell so it's not visible. You guys can disregard this, unless there's a more appropriate solution to the problem. --202.147.44.80 11:13, 19 June 2007 (UTC) (lincalinca)Reply
<span style="display:none">9999</span> may be more convenient, because it is independent of background colors used.--Patrick 11:24, 19 June 2007 (UTC)Reply