I have a list of rows having a column Name , now i wan't that on click of the column header label Name the whole list of rows should get sorted in ascending order and on re click of the label the list should now get sorted in descending order . Can some one help me with the code as it is very urgent.
Announcement
Collapse
No announcement yet.
Sorting List
Collapse
X
-
certainly, code below:
Code:if (youHaveAServerSideLanguageAvailable){ with(theServerSideLanguage){ yourdata.shouldbe = InADatabase if(yourDataIsInADatabase){ for (eachColumn in yourData){ runAQueryThatSortsItDifferently() } } } } else{ itsGonnaBeARightPain(true) }
-
Comment
-
Vladdy | KL
"Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"
Comment
-
Now you see Vladdy, I intended to help Parijat. I got interesed in this problem either.
To all.
Well, I started in solving the problem using innerHTML instead of DOM methods. I managed to get something, unfortunately it works NS only. IE gives an bizzare error starting second array, I don't know why...
I'll put my code here also (I put it in another forum, as well) maybe here someone will find out why this strange error in IE
PHP Code:<html>
<head>
<script>
function change(){
t= document.getElementById('tab');
var a = new Array()
for(i=0;i<t.rows.length;i++){
a[i] = t.rows[i].innerHTML;
}
for(i=0;i<t.rows.length;i++){
// the line bellow brings an unexpected runtime error in IE
t.rows[(t.rows.length-1)-i].innerHTML = a[i];
}
}
</script>
</head>
<body>
<table id="tab" width="30%" border="1">
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
<tr>
<td>3</td>
</tr>
</table>
<br>
<input type="button" value="rearange" onclick="change()">
</body>
</html>
Comment
-
I appreciate a plug, Kor. Just wanted to warn him that some part of that code which I wrote about 2 years ago are far from optimumVladdy | KL
"Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"
Comment
-
Solved
I presumed that error occured somehow because IE innerHTML returns tags written with upper caps, don't know why... (silly thing)
Now I decided to replace Cell innerHTML, rather than Row, so here it is:
PHP Code:<html>
<head>
<script>
function ch(){
t= document.getElementById('tab');
a = new Array();
for(i=0;i<t.rows.length;i++){
a[i] = new Array();
for(j=0;j<t.rows[i].cells.length;j++){
a[i][j] = t.rows[i].cells[j].innerHTML;
}
}
for(i=0;i<t.rows.length;i++){
for(j=0;j<t.rows[(t.rows.length-1)-i].cells.length;j++){
t.rows[(t.rows.length-1)-i].cells[j].innerHTML = a[i][j];
}
}
}
</script>
</head>
<body>
<table id="tab" width="30%" border="1">
<tr>
<TD>1</TD>
<TD>oak</TD>
</tr>
<tr>
<TD>2</TD>
<TD>bla</TD>
</tr>
<tr>
<TD>3</TD>
<TD>blabla</TD>
</tr>
</table>
<br>
<input type="button" value="rearange" onclick="ch()">
</body>
</html>
Comment
-
and to match exactly what Parijat wants:
PHP Code:<html>
<head>
<script>
function ch(){
t= document.getElementById('tab');
a = new Array();
for(i=1;i<t.rows.length;i++){
a[i] = new Array();
for(j=0;j<t.rows[i].cells.length;j++){
a[i][j] = t.rows[i].cells[j].innerHTML;
}
}
for(i=1;i<t.rows.length;i++){
for(j=0;j<t.rows[t.rows.length-i].cells.length;j++){
t.rows[t.rows.length-i].cells[j].innerHTML = a[i][j];
}
}
}
</script>
</head>
<body>
<table id="tab" width="30%" border="1">
<tr>
<td><a href="#" onclick="ch()">NAME</a></td>
<td>somestuff</td>
</tr>
<tr>
<td>1</td>
<td>oak</td>
</tr>
<tr>
<td>2</td>
<td>bla</td>
</tr>
<tr>
<td>3</td>
<td>blabla</td>
</tr>
<tr>
<td>4</td>
<td>oak oak</td>
</tr>
</table>
</body>
</html>
Comment
-
Comment
-
yeap, nice...
I was now just thinking what kind of sorting criteria Parijat wants. Presume that alphabetical, so now I try to sort using RegExp, not very good on this, rather begginer...
Comment
-
Well, I myself start in building similar stuff for one of my projects, so your request made me try to solve it in avance...
Anyway, the problem is now only half solved, as I (and maybe you too) need first to sort the colums. Some of our mates here gave me some solutions for the sorting
, so, when ready, I might send you my result (If I will not forget your name...)
Comment
Comment