How to sort columns in ascending and descending order

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.



Go Back   Webforumz.com > Main Forums > Program Your Website > Other Programming Languages

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Feb 1st, 2006, 13:50
Junior Member
Join Date: May 2005
Location: Virginia US
Age: 30
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Reply With Quote

  #2 (permalink)  
Old Feb 8th, 2006, 14:27
Junior Member
Join Date: May 2005
Location: Virginia US
Age: 30
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote
Reply

Tags
sort, columns, ascending, descending, order

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 22:24.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43