sortering
jeg har følgende sortering:----------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="da">
<head>
<title>Framework01</title>
<style>
thead td{
cursor:hand;
}
</style>
<script type="text/javascript">
currentCol = 0
previousCol = -1
function CompareAlpha(a, b) {
if (a[currentCol] < b[currentCol]) { return -1; }
if (a[currentCol] > b[currentCol]) { return 1; }
return 0;
}
function CompareAlphaIgnore(a, b) {
strA = a[currentCol].toLowerCase();
strB = b[currentCol].toLowerCase();
if (strA < strB) { return -1; }
else {
if (strA > strB) { return 1; }
else { return 0; }
}
}
function CompareDate(a, b) {
// this one works with date formats conforming to Javascript specifications, e.g. m/d/yyyy
datA = new Date(a[currentCol]);
datB = new Date(b[currentCol]);
if (datA < datB) { return -1; }
else {
if (datA > datB) { return 1; }
else { return 0; }
}
}
function CompareDateEuro(a, b) {
// this one works with european date formats, e.g. d.m.yyyy
strA = a[currentCol].split(".");
strB = b[currentCol].split(".")
datA = new Date(strA[2], strA[1], strA[0]);
datB = new Date(strB[2], strB[1], strB[0]);
if (datA < datB) { return -1; }
else {
if (datA > datB) { return 1; }
else { return 0; }
}
}
function CompareNumeric(a, b) {
//window.alert ("CompareNumeric");
numA = a[currentCol]
numB = b[currentCol]
if (isNaN(numA)) { return 0;}
else {
if (isNaN(numB)) { return 0; }
else { return numA - numB; }
}
}
function TableSort(myTable, myCol, myType) {
// Create a two-dimensional array and fill it with the table's content
var mySource = document.all(myTable);
var myRows = mySource.tBodies[0].rows.length;
var myCols = mySource.tBodies[0].rows(0).cells.length;
currentCol = myCol
myArray = new Array(myRows)
for (i=0; i < myRows; i++) {
myArray[i] = new Array(myCols)
for (j=0; j < myCols; j++) {
myArray[i][j] = document.all(myTable).tBodies[0].rows(i).cells(j).innerHTML
}
}
myArray.reverse();
if (myCol == previousCol) {
}else { // clicked on a new column - sort as indicated
switch (myType) {
case "a": myArray.sort(CompareAlpha);break;
case "ai":myArray.sort(CompareAlphaIgnore);break;
case "d":myArray.sort(CompareDate);break;
case "de":myArray.sort(CompareDateEuro);break;
case "n":myArray.sort(CompareNumeric);break;
default:myArray.sort()
}
}
// Re-write the table contents
for (i=0; i < myRows; i++) {
for (j=0; j < myCols; j++) {
mySource.tBodies[0].rows(i).cells(j).innerHTML = myArray[i][j]
}
}
previousCol = myCol; // remember the current sort column for the next pass
return 0;
}
</script>
</head>
<body>
<div class="standardList03">
<table id="inventory1" class="listContent">
<thead>
<tr>
<td onclick="TableSort('inventory1', 0, 'ai')"><p><strong>Dato</strong></p></td>
<td onclick="TableSort('inventory1', 1, 'ai')"><p><strong>Ticker</strong></p></td>
<td onclick="TableSort('inventory1', 2, 'ai')"><p><strong>Hændelse</strong></p></td>
<td onclick="TableSort('inventory1', 3, 'n')"><p><strong>Tal</strong></p></td>
</tr>
</thead>
<tbody>
<tr style="background-color:#E7E9D1;">
<td class="td1"><p>03.10.1988</p></td>
<td class="td2"><p>johnny</p></td>
<td class="td3"><p><a href="#">Seminar du der g</a></p></td>
<td class="td3"><p>1.234.545,87</p></td>
</tr>
<tr>
<td class="td1"><p>10.8.2000</p></td>
<td class="td2"><p>Benny</p></td>
<td class="td3"><p><a href="#">Seminar du der h</a></p></td>
<td class="td3"><p>3.534.545,87</p></td>
</tr>
<tr style="background-color:#E7E9D1;">
<td class="td1"><p>08.10.2001</p></td>
<td class="td2"><p>PGS</p></td>
<td class="td3"><p><a href="#">Seminar du der g</a></p></td>
<td class="td3"><p>49.900,00</p></td>
</tr>
<tr>
<td class="td1"><p>10.8.2000</p></td>
<td class="td2"><p>DOM</p></td>
<td class="td3"><p><a href="#">Seminar du der h</a></p></td>
<td class="td3"><p>534.545,87</p></td>
</tr>
<tr>
<td class="td1"><p>10.8.2000</p></td>
<td class="td2"><p>DOM</p></td>
<td class="td3"><p><a href="#">Seminar du der h</a></p></td>
<td class="td3"><p>872,44</p></td>
</tr>
</tbody>
</table>
</div>
-----------------------------------------------------------
Mit problem er sorteringen af rækken ' tal '
funktionen kan godt sorterer hvis tallene ikke ikke indeholder både punktum og komma! Problemet er , at jeg ikke kan styre disse data.
T
