function stripHTML(strText){ var tmp = strText.replace(/
/gi,"\n"); return tmp.replace(/<[^>]+>/g,""); } /* * function generateCompareFunc * * recieves the column number and the table body object. * The column number is used to examine the column clicked on. * The body object is used in conjunction with the column number to * access the first cell in order to decide what type of data is held in that column. * Depending on the result of the call to getType the data is converted accordingly and then * the comparison is made. */ function generateCompareFunc(iCol, oTableBody){ var sample = getType(oTableBody.rows[0].cells[iCol].firstChild.nodeValue); return function compareTRows(oTRow1, oTRow2){ switch(sample) { case "dateNum": var value1 = convertDateNum(oTRow1.cells[iCol].firstChild.nodeValue); var value2 = convertDateNum(oTRow2.cells[iCol].firstChild.nodeValue); break; case "dateStr": var value1 = convertDateStr(oTRow1.cells[iCol].firstChild.nodeValue); var value2 = convertDateStr(oTRow2.cells[iCol].firstChild.nodeValue); break; case "currency": var value1 = convertCurrency(oTRow1.cells[iCol].firstChild.nodeValue); var value2 = convertCurrency(oTRow2.cells[iCol].firstChild.nodeValue); break; case "time": var value1 = convertTime(oTRow1.cells[iCol].firstChild.nodeValue); var value2 = convertTime(oTRow2.cells[iCol].firstChild.nodeValue); break; case "float": var value1 = convertFloat(oTRow1.cells[iCol].firstChild.nodeValue); var value2 = convertFloat(oTRow2.cells[iCol].firstChild.nodeValue); break; case "int": var value1 = convertInt(oTRow1.cells[iCol].firstChild.nodeValue); var value2 = convertInt(oTRow2.cells[iCol].firstChild.nodeValue); break; default: var value1 = stripHTML(oTRow1.cells[iCol].innerHTML); var value2 = stripHTML(oTRow2.cells[iCol].innerHTML); value1 = value1.toLowerCase(); value2 = value2.toLowerCase(); } if(value1 > value2){ return 1; }else if(value2 > value1){ return -1; }else { return 0; } } } /* * function sortTable * * recieves the TH element clicked on and is used to find the parent table element. * the table object can then be used to find the relative tbody object which * contains the data to be sorted. * */ function sortTable(oTHead){ var oTable = oTHead.parentNode.parentNode.parentNode; var oTableHCells = oTable.tHead.rows[0].cells; // find the column clicked on to establish the column index for(var i=0; i