...

View Full Version : need sorting table



marhanen
05-03-2006, 03:00 AM
i haven't been able to find a sorting table that could properly sort what i want
here is what i want it to sort
the list is sorted by position
NAME______ID____Lvl_____Rank____Position

Maha_____19923__100_____100____Owner
Thrawl____9550___159_____100____Co-Owner
marhanen_22304___83_____ 99_____Banker
etc.
i need one that could sort it and a way so that i could sort by position with it in a certain order.

thanks
Marhanen

Kor
05-03-2006, 10:30 AM
Something like this? (see also attachment)


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Sortare ascendenta/descendenta pe coloane</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<style type="text/css">
<!--
tr {
background-color: #CCCCCC;
}
.tr1 {
background-color: #F5F5F5;
}
.tr2 {
background-color: #E5E5E5;
}
.point {
cursor:pointer;
}
-->
</style>
<script type="text/JavaScript">
//Genuine code by Corneliu Lucian 'KOR' Rusu -- mailto:cornel@apropo.ro
function sortIt(w){
var r=w.parentNode.parentNode.getElementsByTagName('tr');
var oRows = new Array()//clone lines
var iRows = new Array()//index lines
for(var i=1;i<r.length;i++){
oRows[i]=r[i].cloneNode(true);
iRows[i]=r[i].rowIndex;
}
var q=w.cellIndex;
var oCol = new Array()
var vCol = new Array()
for(var i=0;i<iRows.length;i++){
var v = r[i].cells[q].firstChild.nodeValue;
if(Number(v)){v=Number(v)}
oCol[i]=[v,iRows[i]];
vCol[i]=[v,iRows[i]];
}
oCol.shift();
vCol.shift();
sCol = oCol.sort(function(oCol,sCol){return oCol[0] == sCol[0] ? 0 : (oCol[0] < sCol[0] ? -1 : 1)});
if(vCol.toString()==sCol.toString()){sCol.reverse()}// switch down/up
var q=1;
for(var i=1;i<r.length;i++){//rewrite lines
r[i].parentNode.replaceChild(oRows[sCol[i-1][1]],r[i]);
//START zebra
q=(q>2)?1:q
r[i].className='tr'+q;q++;
// END zebra
}
//switch arrows
var s =['desc.gif','cres.gif','none.gif'];//arrows url
var allS =r[0].getElementsByTagName('img');
var sag = w.getElementsByTagName('img')[0];
var url =(sag.getAttribute('src').indexOf(s[1])>-1||sag.getAttribute('src').indexOf(s[2])>-1)?s[0]:s[1];
sag.setAttribute('src',url);
for(var i=0;i<allS.length;i++){//init arraows
if(allS[i]!=sag){allS[i].setAttribute('src',s[2])}
}
}
</script>
</head>
<body>
<table width="400" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td class="point" onclick="sortIt(this)" title="Sort"><strong>NAME</strong> <img src="none.gif" border="0" alt=""></td>
<td class="point" onclick="sortIt(this)" title="Sort"><strong>ID</strong> <img src="none.gif" border="0" alt=""></td>
<td class="point" onclick="sortIt(this)" title="Sort"><strong>Lvl</strong> <img src="none.gif" border="0" alt=""></td>
<td class="point" onclick="sortIt(this)" title="Sort"><strong>Rank</strong> <img src="none.gif" border="0" alt=""></td>
<td class="point" onclick="sortIt(this)" title="Sort"><strong>Position</strong> <img src="none.gif" border="0" alt=""></td>
</tr>
<tr class="tr1">
<td>Maha</td>
<td>19923</td>
<td>100</td>
<td>100</td>
<td>Owner</td>
</tr>
<tr class="tr2">
<td>Thrawl</td>
<td>9550</td>
<td>159</td>
<td>100</td>
<td>Co-Owner</td>
</tr>
<tr class="tr1">
<td>Marhanen</td>
<td>22304</td>
<td>83</td>
<td>99</td>
<td>Banker</td>
</tr>
</tbody>
</table>
</body>
</html>

marhanen
05-06-2006, 09:30 PM
thanks that worked



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum