This is a discussion on "How to sort columns in ascending and descending order" within the Other Programming Languages section. This forum, and the thread "How to sort columns in ascending and descending order are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
How to sort columns in ascending and descending order
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
How to sort columns in ascending and descending order
I want to be able to sort any column in my JSP [dynamic HTML table] page in ascending or descending order by clicking on the header of the column. So if a user clicks on a header column the first time that column should be sorted in ascending order then if that same header column gets click again the column should be sorted in descending order and so forth.
So far I can only sort any column in ascending order. When a user clicks on a column header I pass the SQL table column name to a JavaScript method which sets a hidden tag value to the SQL table column name and then it is set to a String variable which in turn gets set to a String variable [the ORDER BY clause] in the JavaBean which then builds the SQL statement with the ORDER BY clause Please advise, thanks. |
|
|
|
|||
|
Re: How to sort columns in ascending and descending order
All,
For future reference, the following code snippet is the core idea of what I did to make a dynamic HTML table sortable in a JSP page. <html> <head> <title>Sortable HTML table :: Demo</title> <script language="JavaScript" type="text/JavaScript"> <!-- /** * Make modifications to the sort column and sort order. */ function reSortData( sortColumn ) { if ( sortColumn == document.form_searchSort_report.hd_sortCol.value ) { // The same column was selected. Toggle the sort order. if ( document.form_searchSort_report.hd_sortOrd.value == 'ASC' ) { document.form_searchSort_report.hd_sortOrd.value = 'DESC'; } else { document.form_searchSort_report.hd_sortOrd.value = 'ASC'; } } else { // A different column was selected. document.form_searchSort_report.hd_sortCol.value = sortColumn; document.form_searchSort_report.hd_sortOrd.value = 'ASC'; } // Submit the form. document.form_searchSort_report.submit(); } --> </script> </head> <body> <% %> <form name="form_searchSort_report" method="POST" action="sortableDemo.jsp"> <%-- These are hidden inputs that will be populated by the reSortData() JavaScript function. --%> <input type="hidden" name="hd_sortCol" value="<%=request.getParameter("hd_sortCol")%>"> <input type="hidden" name="hd_sortOrd" value="<%=request.getParameter("hd_sortOrd")%>"> <p> <a href="#" onClick="reSortData('userID');">User ID</a> <a href="#" onClick="reSortData('userName');">User Name</a> </p> </form> </body> </html> Best Regards, Gibran Castillo |
![]() |
| Tags |
| sort, columns, ascending, descending, order |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sort a three dimensional array?? | nate2099 | PHP Forum | 3 | Aug 1st, 2007 16:21 |
| Some sort of database in flash? | Throntel | Flash & Multimedia Forum | 3 | Jan 6th, 2007 05:54 |
| filter xml and sort xml | alcove | Other Programming Languages | 1 | Apr 17th, 2006 03:01 |
| New Member needs help to sort out website! | nico7_uk | Introduce Yourself | 1 | Jun 29th, 2005 09:17 |
| sort mailbody | si2n | Classic ASP | 8 | Jan 6th, 2004 15:19 |