| Author |
problem with javascript sorting
|
sirisha makkapati
Ranch Hand
Joined: Dec 10, 2006
Posts: 83
|
|
Hi to all, I wanted add up && down icons to my theads,while sorting my code is as follows.for ascending up arow,for descending down arow like that. my code is as follows <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title></title> <script language="JavaScript" type="text/javascript"> /*<![CDATA[*/ function zxcSortTable(zxcid,zxccnus){ var zxcargs=zxcSortTable.arguments var zxctable=document.getElementById(zxcid); var zxcrows=zxctable.rows,zxcscells=[],zxcclones=[],zxcblanks=[],zxccnt=0; for (var zxc0=1;zxc0<zxcargs.length;zxc0++){ for (var zxc0a=1;zxc0a<zxcrows.length;zxc0a++){ var zxccells=zxcrows[zxc0a].cells; zxcscells.push(zxccells[zxcargs[zxc0]]); var zxcdata=zxccells[zxcargs[zxc0]].firstChild.data; if (/[a-z]|[0-9]/i.test(zxcdata)){ zxcclones[zxccnt]=(zxccells[zxcargs[zxc0]].cloneNode(true)); zxcclones[zxccnt++].data=zxcdata; } else{ zxcblanks.push(zxccells[zxcargs[zxc0]].cloneNode(true)); } } } if (!zxcrows[0].cells[zxcargs[1]].ud) zxcrows[0].cells[zxcargs[1]].ud='Up'; zxcrows[0].cells[zxcargs[1]].ud=(zxcrows[0].cells[zxcargs[1]].ud=='Up')?'Down':'Up'; zxcclones=zxcclones.sort(zxcSortTxt); if (zxcrows[0].cells[zxcargs[1]].ud=='Up') zxcclones=zxcclones.reverse(); zxcclones=zxcclones.concat(zxcblanks); for (var zxc1=0;zxc1<zxcclones.length;zxc1++){ zxcscells[zxc1].parentNode.replaceChild(zxcclones[zxc1],zxcscells[zxc1]); } } function zxcSortTxt(zxca,zxcb){ var zxcaa=zxca.firstChild.data; var zxcbb=zxcb.firstChild.data; if (zxcaa>zxcbb) return 1; if (zxcaa<zxcbb) return -1; return 0; } /*]]>*/ </script> any one please help me.
|
 |
Bryce Martin
Ranch Hand
Joined: Nov 19, 2007
Posts: 269
|
|
|
where did you learn to name your variables? Looking at that code gives me a headache. Go back and use descriptive variables and you will get more help. And indentation helps too. I would like to help you but I can't take the kind of time it would require to figure out those names.
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
Because he did not write the code... Did you ask vwphillips about your issue? Not sure what would be hard about it. You would have to add an image to each column and set the source document.getElementById("sortImg" + colNumber).src = "myDirectionImage.gif"; Eric
|
 |
 |
|
|
subject: problem with javascript sorting
|
|
|