• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with sorting table  RSS feed

 
sirisha makkapati
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all,

I am having javascript for table sort which is working for static html table(where i hard coded values ),
but the same script not working for my Html table where i am getting values from java object ,can any body help.

My table is as follows:
<table border="1" width="100%" align="left" cellpadding="0" cellspacing="0" style="font: 8pt Verdana,sans-serif;">
<tr>
<td>
<table class="sortable" id="anyid" border="" width="100%" align="left" cellpadding="0" cellspacing="1" style="font: 8pt Verdana,sans-serif;">
<tr>
<td class="unsortable" bgcolor="#87a7ce" align="left"> </td>
<td class="unsortable" bgcolor="#87a7ce" align="left"> </td>
<td bgcolor="#87a7ce" align="left"><b><font size="2" face="Trebuchet MS" color="white">TestCase Name</b></td>
<td bgcolor="#87a7ce" align="left"><b><font size="2" face="Trebuchet MS" color="white">Created Date</b></td>
<td bgcolor="#87a7ce" align="left"><b><font size="2" face="Trebuchet MS" color="white">Created By</b></td>
<td class="unsortable" bgcolor="#87a7ce" align="left"> </td>
<td class="unsortable" bgcolor="#ffffff" align="center">  </td>

</tr>
<%
int counter = -1;
int valCounter = -1;
Iterator itr1 = sessionData.testCasesData.testCaseMap.keySet().iterator();
int noOfRec = sessionData.testCasesData.testCaseMap.size();
int noOfRecByTwo = noOfRec/2;
for(int i=0; i<=noOfRecByTwo;i++) {


counter++;
valCounter++;
if(counter==0){
%>
<tr>
<%
}
if (counter < 2) {
testCase = (String) itr1.next();
TestCasesData.TestCaseData testCaseData = (TestCasesData.TestCaseData) sessionData.testCasesData.testCaseMap.get(testCase);

%>
<td bgcolor="#b6cef8" align="center">
<a href="javascript:showTree(searchForm,'<%=testCase%>','TREE');" title="View Tree">
<img src="images/nolines_plus.gif" width="22" height="22" border="0" title="View Tree Versions">
</a>
</td>

<td bgcolor="#d5eaff" align="center">
<a href="javascript:showTree(searchForm,'<%=testCase%>','');" title="View Tree">
<img src="images/folderopen.gif" width="20" height="20" border="0" title="View Versions">
</a>
</td>

<td bgcolor="#b3d9ff" align="left">
<font size="2" face="Trebuchet MS" color="#0000A0">
<a href="javascript:getLatestTestCase(searchForm,'<%=testCase%>');" title="Get Latest TestCase">
<input type="hidden" name=<%= TestCasesData.VIEW_TEST_CASE %><%= valCounter %> value="<%= testCase %>"><%= testCase %>
</a>
</font>
</td>
<td bgcolor="#a8cfff" align="left"><font size="2" face="Trebuchet MS" color="#0000A0"> <%=testCaseData.createdDate%></font></td>
<td bgcolor="#bfdfff" align="left"><font size="2" face="Trebuchet MS" color="#0000A0"> <%=testCaseData.createdUser%></font></td>
<td bgcolor="#d5eaff" align="center">
<a href="javascript:deleteTestCase(searchForm,'<%=testCase%>');" title="DeleteTestCase"><img src="images/delete.gif" width="20" height="20" border="0" title="Delete TestCase">
</a>
</td>
<%
if (counter < 1) {
}
if (!(itr1.hasNext())) {
while (counter < 1) {
%>

counter++;
}
}
%>
<%

} else {
counter = -1;

%>

</tr>
<%
}
}

%>

</table>

My script
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
function zxcES(zxcele,zxcstyle,zxcp,zxctxt){
if (typeof(zxcele)=='string'){ zxcele=document.createElement(zxcele); }
for (key1 in zxcstyle){
document.Show.Show1.value=key1;

zxcele.style[key1]=zxcstyle[key1]; }

if (zxcp){ zxcp.appendChild(zxcele); }
if (zxctxt){ zxcele.appendChild(document.createTextNode(zxctxt)); }
return zxcele;
}
function zxcMonth(zxcm){
var zxcmonths={jan:'01',feb:'02',mar:'03',apr:'04',may:'05',jun:'06',jul:'07',aug:'08',sep:'09',nov:'11',dec:'12'};
for (key1 in zxcmonths){
if (key1==zxcm) return zxcmonths[key1];
}
}


function zxcSortTable(zxcid,zxccnus,zxctype){
zxctype=zxctype||'std';
//zxcES('DIV',{'width':'0px'});
var zxcargs=zxcSortTable.arguments
var zxctable=document.getElementById(zxcid);
var zxcrows=zxctable.rows,zxcscells=[],zxcclones=[],zxcblanks=[],zxccnt=0;
var zxcmonths={jan:'01',feb:'02',mar:'03',apr:'04',may:'05',jun:'06',jul:'07',aug:'08',sep:'09',nov:'11',dec:'12'};
for (var zxc0=0;zxc0<zxccnus.length;zxc0++){
for (var zxc0a=1;zxc0a<zxcrows.length;zxc0a++){
var zxccells=zxcrows[zxc0a].cells;
zxcscells.push(zxccells[zxccnus[zxc0]]);
var zxcdata=zxccells[zxccnus[zxc0]].firstChild.data;
if (/[a-z]|[0-9]/i.test(zxcdata)){
zxcclones[zxccnt]=(zxccells[zxccnus[zxc0]].cloneNode(true));
if (zxctype=='dd/mm/yyyy'||zxctype=='mm/dd/yyyy'||zxctype=='dd/mmm/yyyy'||zxctype=='mmm/dd/yyyy'){
var zxcsep=zxcdata.charAt(zxcdata.length-5);
zxcdata=zxcdata=zxcdata.split(zxcsep)[2]+((zxctype.match('mmm'))?zxcmonths[zxcdata.split(zxcsep)[(zxctype=='dd/mmm/yyyy')?1:0].toLowerCase().substring(0,3)]:zxcdata.split(zxcsep)[(zxctype.charAt(0)=='m')?0:1])+(zxcdata.split(zxcsep)[(zxctype.charAt(0)=='d')?0:1]);//zxcdata.split(zxcsep).reverse().join('');
}
zxcclones[zxccnt++].data=zxcdata;
}
else zxcblanks.push(zxccells[zxccnus[zxc0]].cloneNode(true));
}
}
if (!zxcrows[0].cells[zxccnus[0]].ud) zxcrows[0].cells[zxccnus[0]].ud='Up';
zxcrows[0].cells[zxccnus[0]].ud=(zxcrows[0].cells[zxccnus[0]].ud=='Up')?'Down':'Up';
zxcclones=zxcclones.sort(zxcSortTxt);
if (zxcrows[0].cells[zxccnus[0]].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]);
for (var zxc2=0;zxc2<zxccnus.length;zxc2++) zxcrows[0].cells[zxccnus[zxc2]].getElementsByTagName('IMG')[0].src=(zxcrows[0].cells[zxccnus[0]].ud=='Up')?'http://www.vicsjavascripts.org.uk/StdImages/down[1].gif':'http://www.vicsjavascripts.org.uk/StdImages/up[1].gif';
}

function zxcSortTxt(zxca,zxcb){
var zxcaa=zxca.data;
var zxcbb=zxcb.data;
if (zxcaa>zxcbb) return 1;
if (zxcaa<zxcbb) return -1;
return 0;
}
can any body help
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and most people will just go elsewhere. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!