//using an HTML table as a limited database table, will sort rows by the column specified
//Judas Gutenberg Dec 04 2007
//to use: first set the id of your table to sort to "idsorttable"
//second call NumberRows(intTDMinCount) (where intTDMinCount is the minimum number of columns for a table row to be in play)
//that will set consecutive ids for all the TR nodes in the table whose ID is idsorttable
//then create hyperlinks on the headings of the HTML table columns
//something like foreign PK"
//which is labeled "foreign PK" and will, if clicked, sort column 3 (these columns are zero-based) starting with row #2
//This code is covered under the GNU General Public License
//info here: http://www.gnu.org/copyleft/gpl.html
//the digest is as follows: you cannot modify this code without
//publishing your source code under the same license
//contact the developer at gus@asecular.com http://asecular.com
var arrDirection=new Array(); //stores global sort directions for the columns so they can be reversed with next click
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
return this.replace(/\s+$/,"");
}
function GetParent(thisnode)
{
var thisparent;
if(thisnode)
{
if (thisnode.parentNode)
{
thisparent=thisnode.parentNode
}
else
{
thisparent=thisnode.parentElement
}
return (thisparent);
}
}
function NumberRows(idsorttable, intTDMinCount)
{
var idprefix=idsorttable + "idrow";
var thistable=document.getElementById(idsorttable);
var arrTRs=document.getElementsByTagName('tr');
var intTRCount=0;
for(i=0; i-1)
{
bwlHeaderFail=true;
}
}
for(j=0; j-1)
{
bwlHeaderFail=true;
}
}
}
if (ClimbTreeToTagFromObj(thistr, "table")==thistable )
{
if(tdcount>intTDMinCount && !bwlHeaderFail)
{
thistr.id=idprefix + intTRCount;
}
else
{
thistr.id=idprefix + "x" + intTRCount;
}
intTRCount++;
}
}
arrDirection=strDirection.split(" ");
}
function SortTable(idsorttable, intColumn, intStart)
{
var out="";
var i;
var arrContainer=CreateColumnArray(idsorttable, intColumn, 0, arrDirection[intColumn]);
var idprefix=idsorttable + "idrow";
var sortcontainer=document.createElement('tbody'); //for IE this has to be tbody.
var strClass1="", strClass2="" ;
//var idsorttable="idsorttable";
var thistable=document.getElementById(idsorttable);
var thistbody=document.getElementById(idsorttable + "body");
if(intStart==undefined || intStart=="")
{
intStart=1;
}
if(arrDirection[intColumn]=="b")
{
arrDirection[intColumn]="f";
}
else
{
arrDirection[intColumn]="b";
}
//beginning rows that are not sorted
for(i=0; i<4; i++)
{
var thisid=idprefix + "x" + i;
var thistr=document.getElementById(thisid);
if(thistr)
{
sortcontainer.appendChild(thistr);
}
}
intMeatcount=0;
for(i=0; i1)
{
for(i=0; i-1)//possibly a decimal number
{
var arrContent=thiscontent.split(".");
if (arrContent.length==2)
{
if(parseInt(arrContent[0])==arrContent[0] && parseInt(arrContent[1])==arrContent[1])
{
thiscontent= pad(arrContent[0], 9, "0", 1) + "." + pad(arrContent[0], 9, "0", 2);
}
}
}
else if(parseInt(thiscontent)==thiscontent)
{
thiscontent= pad(thiscontent, 9, "0", 1) ;
}
arrContainers[i]=thiscontent + "^" + i;
out+=thiscontent + "\n";
}
}
arrContainers.sort();
if(strDirection=="b")
{
arrContainers.reverse();
}
for(i=0; i= str.length)
{
switch (dir)
{
case 1:
str = Array(len + 1 - str.length).join(pad) + str;
break;
case 3:
var right = Math.ceil((padlen = len - str.length) / 2);
var left = padlen - right;
str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
break;
default:
str = str + Array(len + 1 - str.length).join(pad);
break;
}
}
return str;
}
function ClimbTreeToTagFromObj(thisItem, tag)
//returns the node of the nearest specified HTML tag above our element described by thisId
//judas gutenberg june 12 2006
{
var i=0;
//we loop through a max of ten times and if there's no tr by then there's not gonna be one
for(i=0; i<10; i++)
{
thisItem= GetParent(thisItem);
if (thisItem)
{
if (thisItem.nodeName.toLowerCase()==tag)
{
return thisItem;
}
}
}
}