![]() |
|
| Javascript sorting issue |
|
Hi Friends,
I am having html table , To reduce the table length I am deviding table in to two parts,and displaying my records as follows rather than using scroll bar. Empno Ename Empno Ename 1 A 2 u 3 x 4 Y 5 t 6 B then I am applying javascript for table sorting,but sorting is happening in row wise like above. My requirement is sorting should happen in column wise as follows Empno Ename Empno Ename 1 A 4 u 2 x 5 Y 3 t 6 B I am using javascript from the following link for sorting http://www.kryogenix.org/code/browser/sorttable/ Any one please give me the code for coulumn wise sorting. Thanks in advance. |
|||||||||||||
|
|
||||||||||||||
| Javascript sorting issue |
|
Senior Journeyman (L6) ![]()
|
|
|||||||||||||||||
|
_________________ Vic http://www.vicsjavascripts.org.uk God loves you and will never love you less. |
||||||||||||||||||
| Javascript sorting issue |
| Javascript sorting issue |
|
Senior Journeyman (L6) ![]()
|
missed this post but better late than never?
|
|||||||||||||||||
|
_________________ Vic http://www.vicsjavascripts.org.uk God loves you and will never love you less. |
||||||||||||||||||
| Javascript sorting issue |
|
Hi,
How can i add up arow and down icons to theads while sorting. If asening up arow and if descending down arow like that. can you give me an idea. Thanks in advance |
|||||||||||||
|
|
||||||||||||||
| Javascript sorting issue |
|
Senior Journeyman (L6) ![]()
|
|
|||||||||||||||||
|
_________________ Vic http://www.vicsjavascripts.org.uk God loves you and will never love you less. |
||||||||||||||||||
| Javascript sorting issue |
|
Hi vwphillips,
first of all thank you very much for your help ,the code you had given is working very fine. can you give me an idea How to sort date fields. for example i am having table as follows <body> Is this the sort of thing you are looking for?<br /> <table id="tst" border="1"> <tr> <td width="100" onclick="zxcSortTable('tst',0,2);" >Empno<img src="http://www.vicsjavascripts.org.uk/StdImages/down[1].gif" /></td> <td width="100" onclick="zxcSortTable('tst',1,3);">Ename<img src="http://www.vicsjavascripts.org.uk/StdImages/down[1].gif" /></td> <td width="100" onclick="zxcSortTable('tst',0,2);">Empno<img src="http://www.vicsjavascripts.org.uk/StdImages/down[1].gif" /></td> <td width="100" onclick="zxcSortTable('tst',1,3);">Ename<img src="http://www.vicsjavascripts.org.uk/StdImages/down[1].gif" /></td> </tr> <tr> <td>1</td> <td>A</td> <td>12/24/2007</td> <td>2</td> <td>u</td> <td>02/24/2006</td> </tr> <tr> <td>3</td> <td>x</td> <td>09/24/2005</td> <td>4</td> <td>Y</td> <td>10/27/2008</td> </tr> <tr> <td>5</td> <td>t</td> <td>07/27/2001</td> <td>6</td> <td>B</td> <td>10/27/2009</td> </tr> <tr> <td>7</td> <td>i</td> <td>01/27/2008</td> <td> </td> <td> </td> </tr> </table> </body> what javascript code i need to add. If i am giving troble to you very sorry. Thanks in adavance. |
|||||||||||||
|
|
||||||||||||||
| Javascript sorting issue |
|
Senior Journeyman (L6) ![]()
|
Not sure I understand
but line
sorts the cells stored in zxcclones using the function
this function sorts by the cells by .firstChild.data but any valid criteria can be specified just noticed you defined date, be back later |
|||||||||||||||||||
|
_________________ Vic http://www.vicsjavascripts.org.uk God loves you and will never love you less. |
||||||||||||||||||||
| Javascript sorting issue |
|
Senior Journeyman (L6) ![]()
|
To save formating the date it is easiest to use a hidden text input
This is true of all sorting types as you may need to have tags in the cell.
I you realy need the sort without the inputs say. |
|||||||||||||||||
|
_________________ Vic http://www.vicsjavascripts.org.uk God loves you and will never love you less. |
||||||||||||||||||
| Javascript sorting issue |
|
Hi friend,
I am having n number of records,I can't define hidden value n times,and also my date formate may change in future from mm/dd/yyyy to dd/mm/yyyy. Please give me another idea. I am having following methods.but i don't know how to call them in our function zxcSortTable() Is this code help full. please give me an idea. possdate = text.match(/^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/); if (possdate) { // looks like a date first = parseInt(possdate[1]); second = parseInt(possdate[2]); if (first > 12) { // definitely dd/mm } else if (second > 12) { return sorttable.sort_mmdd; } else { // looks like a date, but we can't tell which, so assume // that it's dd/mm (English imperialism!) and keep looking sortfn = sorttable.sort_ddmm; } } method for dd/mm/yyyy formate sort_ddmm: function(a,b) { mtch = a[0].match(/^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/); y = mtch[3]; m = mtch[2]; d = mtch[1]; if (m.length == 1) m = '0'+m; if (d.length == 1) d = '0'+d; dt1 = y+m+d; mtch = b[0].match(sorttable.DATE_RE); y = mtch[3]; m = mtch[2]; d = mtch[1]; if (m.length == 1) m = '0'+m; if (d.length == 1) d = '0'+d; dt2 = y+m+d; if (dt1==dt2) return 0; if (dt1<dt2) return -1; return 1; } method for mm/dd/yyyy formate sort_mmdd: function(a,b) { mtch = a[0].match(/^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/); y = mtch[3]; d = mtch[2]; m = mtch[1]; if (m.length == 1) m = '0'+m; if (d.length == 1) d = '0'+d; dt1 = y+m+d; mtch = b[0].match(sorttable.DATE_RE); y = mtch[3]; d = mtch[2]; m = mtch[1]; if (m.length == 1) m = '0'+m; if (d.length == 1) d = '0'+d; dt2 = y+m+d; if (dt1==dt2) return 0; if (dt1<dt2) return -1; return 1; } waiting for ur reply |
|||||||||||||
|
|
||||||||||||||
| Javascript sorting issue |
|
Hi vwphilips,
Please give me an idea for sorting date with out inputs,because i am having n number of records and date formate would be mm/dd/yyyy or dd/mm/yyyy. thank you very much for your help. |
|||||||||||||
|
|
||||||||||||||
| Javascript sorting issue |
|
Senior Journeyman (L6) ![]()
|
|
|||||||||||||||||
|
_________________ Vic http://www.vicsjavascripts.org.uk God loves you and will never love you less. |
||||||||||||||||||
| Javascript sorting issue |
|
Hi vwphillips,
just for understanding erlier i had given that table.the code is working very fine for that example.The previous exaple is similar to my table only difference is i am getting values from my java object. I applied your code to my actual table in my project,sorting is not happening sometimes,sometimes it is happening row wise,not in column wise, that means record1 recorde2 record3 record4 record5 record6 Like this happening but it sould happen like as follows record1 record4 recor2 record5 record3 record6 If you sort out the problem it would be very help full to me. My actual table is as follows. <table id="tst" border="1" width="100%" align="left" cellpadding="0" cellspacing="1" style="font: 8pt Verdana,sans-serif;"> <tr> <td bgcolor="#87a7ce" align="left"> </td> <td bgcolor="#87a7ce" align="left"> </td> <td onclick="zxcSortTable('tst',[2,9]);" bgcolor="#87a7ce" align="left"><b><font size="2" face="Trebuchet MS" color="white">TestCase Name<image src="images/down.gif" /></font></b></td> <td onclick="zxcSortTable('tst',[3,10],'mm/dd/yyyy');" bgcolor="#87a7ce" align="left"><b><font size="2" face="Trebuchet MS" color="white">Created Date<image src="images/down.gif" /></font></b></td> <td onclick="zxcSortTable('tst',[4,11]);" bgcolor="#87a7ce" align="left"><b><font size="2" face="Trebuchet MS" color="white">Created By<image src="images/down.gif" /></font></b></td> <td bgcolor="#87a7ce" align="left"> </td> <td bgcolor="#ffffff" align="center"> </td> <td bgcolor="#87a7ce" align="left"> </td> <td bgcolor="#87a7ce" align="left"> </td> <td onclick="zxcSortTable('tst',[2,9]);" bgcolor="#87a7ce" align="left"><b><font size="2" face="Trebuchet MS" color="white">TestCase Name</font></b><image src="images/down.gif" /></font></b></td> <td onclick="zxcSortTable('tst',[3,10],'mm/dd/yyyyy');" bgcolor="#87a7ce" align="left"><b><font size="2" face="Trebuchet MS" color="white">Created Date</font></b><image src="images/down.gif" /></font></b></td> <td onclick="zxcSortTable('tst',[4,11]);" bgcolor="#87a7ce" align="left"><b><font size="2" face="Trebuchet MS" color="white">Created By</font></b><image src="images/down.gif" /></font></b></td> <td bgcolor="#87a7ce" align="left"> </td> </tr> <% int counter = -1; int valCounter = -1; Iterator itr1 = sessionData.testCasesData.testCaseMap.keySet().iterator(); while (itr1.hasNext()) { 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) { %> <td bgcolor="#ffffff" align="center"> </td> <% } if (!(itr1.hasNext())) { while (counter < 1) { %> <td bgcolor="#b6cef8"> </td> <td bgcolor="#d5eaff"> </td> <td bgcolor="#b3d9ff"> </td> <td bgcolor="#a8cfff"> </td> <td bgcolor="#bfdfff"> </td> <td bgcolor="#d5eaff"> </td> <% counter++; } } %> <% } else { counter = -1; %> </tr> <% } } %> </table> please do the needfull. |
|||||||||||||
|
|
||||||||||||||
| Javascript sorting issue |
|
Senior Journeyman (L6) ![]()
|
I will need a pure HTML code example of your table to assist any further.
|
|||||||||||||||
|
_________________ Vic http://www.vicsjavascripts.org.uk God loves you and will never love you less. |
||||||||||||||||
| Javascript sorting issue |
|
Hi friend,
I wanted to sort date fields which are having following formate mm/dd/yyy hh:mm:ss Please give me code for this |
|||||||||||||
|
|
||||||||||||||
| Javascript sorting issue |
|
||
|
|

