I'd have to agree with Bill's warnings - Javascript breaks fast. Also let's say you're viewing records 11-20 and you sort with javascript, this will only sort the records displayed on the page and not the whole recordset.
For searching/sorting/pagination I usually have one function in my gateway that returns the following struct: - SearchResult.Query - SearchResult.TotalRows And takes the following arguments: - StartRow - MaxRows - OrderBy The SearchResult.Query variable contains the resulting query with only the number of rows that will be displayed (MaxRows). So if MaxRows is 10 and my table has 1000 rows, the resulting query will only have 10 rows. The SearchResult.TotalRows variable counts how many rows match the criteria regardless of how many are returned in the query. This is mainly for the "Displaying results 11 to 20 of 455" line. This function has treated me very well with large data sets. The biggest mistake you can make is to return a 1000 rows only to display 10 using cfoutput's maxrows attribute. Right now I use 2 queries to do this - one for the query resultset and one to count(TotalRows). Even though it's quite efficient, I don't think it's optimal. MySQL has an SQL_CALC_FOUND_ROWS function that is supposed to tell you how many rows match your criteria even if you LIMIT how many records are returned - but I'm not sure how to use it or if its even possible to use it in CF. If anyone would like to shed some light on that... please feel free... Cheers, Baz -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bill Rawlinson Sent: Wednesday, November 23, 2005 3:22 PM To: [email protected] Subject: Re: [CFCDev] Sorting results I can't say much about the technique other than be careful with javascript based table sorting. If you have an largeish table (100+) rows with more than 4 or 5 columns the Javascript sort can be very slow. Javascript isn't the fastest language around and unless you have very optimized sort algorithims it can cause the page to seemingly hang to the user. The browser might also warn the user a script is taking a long time to execute and give them the option of aborting it - they wont know they are killing the sort though and will wonder why their sort didn't happen. For general javascript table sorting I wrote a nice unobtrusive routine (that incorporates some work of others as noted in the documentation) that works pretty well (with the exception of the conditions previously listed). It is freely available at: http://rawlinson.us/blog/?p=147 Bill On 11/23/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Under an MVC design is there any best place to sort results? My natural > inclination is to say this would occur at the view stage since a particular > sorted order is most appropriate to how and why the user is viewing the > data. The model shouldn't care about the order of things. > > Generally I accomplish this by running a query of a query in the view or > controller before display. > > <cfquery dbtype="query" name="sortedQuery"> > select * from myQuery > order by #sortOrder# > </cfquery> > > > I've also been using table sorting javascript to reorder the table rather > than performing a page refresh. > > More recently I've been returning unsorted arrays of objects instead of > queries. This means when the page first loads it is unsorted and a > javascript call must be made to sort it. > > > Any comments on this technique? > > > Jason Cronk > > > > > ---------------------------------------------------------- > You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email. > > CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com). > > An archive of the CFCDev list is available at www.mail-archive.com/[email protected] > > > -- [EMAIL PROTECTED] http://blog.rawlinson.us If you want Gmail - just ask. ---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email. CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com). An archive of the CFCDev list is available at www.mail-archive.com/[email protected] ---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email. CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com). An archive of the CFCDev list is available at www.mail-archive.com/[email protected]
