Welcome to WebmasterWorld Guest from 107.20.59.213

Forum Moderators: open

Message Too Old, No Replies

efficient sorting function using javascript

     

manjumurthy

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

10+ Year Member



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

txbakers

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

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



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)

10+ Year Member



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

tedster

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

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



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.

txbakers

6:01 pm on May 6, 2002 (gmt 0)

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



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)

lorax

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

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



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)

10+ Year Member



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.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month