Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with javascript sorting

 
sirisha makkapati
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic