Welcome to WebmasterWorld Guest from 54.197.66.254

Forum Moderators: open

Message Too Old, No Replies

efficient sorting function using javascript

     

manjumurthy

6:15 am on May 6, 2002 (gmt 0)

Inactive Member
Account Expired

 
 


Hi all,
I have a prograp in asp. This pgm fetches large number of records from the database & display's these records on the browser in the form of html table. I have a requirement wherein , onclick of the column heading the table should get sorted accordingly. I have a javascript sorting function that responds to the click event & uses bubble sort, but script function takes a lot of time to do the sorting & hence the browser hangs. Can anyone tell me an alternatine sorting function which takes less time to sort records.
Thanks & regards
manjumurthy
12:16 pm on May 6, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Sept 1, 2001
posts:4392
votes: 0


if you are already using ASP, I would make the click on the column heading another server call, with the appropriate change in the ORDER BY clause of your SQL. You can use directives for this:

<a href="mypage.asp?Sort1">Sort 1</a>

<a href="mypage.asp?Sort2">Sort 2</a>

In your ASP code:
if Request.QueryString == "Sort1" then
sql = sql & " order by field1"
elseif Request.QueryString == "Sort2" then
sql = sql & " order by field2"
end if

Much faaster than trying to do it client side.

I can show you an example if you sticky me.

manjumurthy

12:33 pm on May 6, 2002 (gmt 0)

Inactive Member
Account Expired

 
 


Thanks for the solution,Can u send me the example? I have a concern. Won't I be hitting the database everytime I sort ,which will reduce the response time.

Thanks
manjumurthy

12:50 pm on May 6, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:May 26, 2000
posts:37301
votes: 0


There is another style of sorting algo called "quicksort" [ciips.ee.uwa.edu.au]. It is faster than "bubble sort" because it works by creating partitions in the data, and sorting within each partition, rather than the inefficient side-by-side sorting of all elements.
6:01 pm on May 6, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Sept 1, 2001
posts:4392
votes: 0


I'm not sure how long this URL will last here (we don't generally like to post URLs on WW) but if you can get to it you'll see what I do.

***www.charmsmusic.com/charms/pmlb.asp?eve=109&gr1=1

Clicking on a column heading will go back to the db and bring it back in a different sort.

Yes, it takes resources, but the server side processing is generally much faster than client side processing.

(edited by: tedster at 6:15 pm (utc) on May 6, 2002)

8:10 pm on May 6, 2002 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 31, 2002
posts:7575
votes: 0


I'd suggest you see if you can pre-sort and then cache the result sets based on all of the possible combinations. Superfast response time because there's no need to sort. You'll need to choose an appropriate time period for updating the cached results based upon how often you update the db.

manjumurthy

4:28 am on May 8, 2002 (gmt 0)

Inactive Member
Account Expired

 
 


Thanks for the URL, I was able to view it. Can u send me the pmlb.asp file coz' I get the following error when I tried to achieve the same

Microsoft OLE DB Provider for ODBC Drivers (0x80040E07)
[Microsoft][ODBC SQL Server Driver][SQL Server]The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value.