0 Replies Latest reply on Nov 30, 2009 8:41 AM by kenji776

    Feedback on record browser implimentation

    kenji776 Level 1

      Hey guys.

      I am building a next-N record browser system, with a few extra little features. Basically I am going for your classic, type of list, a first button, last button, and then numbered pages that display a certain number of reocords. If there are a lot of pages, it shows just a few in either direction of your current page. I have a working implimentation but it feels rather inefficient. I am looking for any way to optimize this and make it ready for production use. Either way, if you have any feedback (suggestions, critisizm, hell even compliments) please let me know. I do plan on turning this into an Ajax style application once I get all the basics worked out. Thanks!

       

      You can also see a quick and dirty example of its functionality here:
      http://portal.fpitesters.com/test.cfm

       

      <cfparam name="url.startrow" default="1" type="numeric">
      <cfparam name="url.display" default="5" type="numeric">
      <cfparam name="url.pagenum" default="1" type="numeric">
      <cfparam name="url.browsesize" default="5" type="numeric">
      <cfoutput>
      <cffunction name="GetRecords">
      
           <cfquery name="GetFields" datasource="Webserver">
                Select * 
                From RespondentEditableFields
           </cfquery>
           
           <cfreturn GetFields>
      </cffunction>
      
      <cffunction name="GetRecordsPage">
           <cfargument name="Query" type="query">
           <cfargument name="StartRow" type="numeric" default="1">
           <cfargument name="Display" type="numeric" default="10">
           
           <cfquery name="GetRecordsPage" dbtype="query" maxrows="#arguments.display#">
                Select *
                From arguments.query
                Where ID >= <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.startrow#">
           </cfquery>
           
           <cfreturn GetRecordsPage>     
      </cffunction>
      
      <cffunction name="RecordBrowser">
           <cfargument name="Query" type="query">
           <cfargument name="Display" type="numeric" default="1">
           
           <cfset counter = 0>
           <cfset pageNum = 1>
           <cfset PageStarts = arraynew(1)>
           
      
      
           <cfset PageStarts[PageNum] = arguments.query['id'][1]>      
           
           <cfloop query="arguments.query">
                <cfset counter = counter + 1>
                
                <cfif counter eq arguments.display>
                     <cfset pageNum = pageNum+1>
                     <cfset PageStarts[PageNum] = arguments.query.id> 
                     <cfset counter = 0>
                </cfif>
                
           </cfloop>
           
           <cfreturn PageStarts>
      </cffunction>     
      
      <cffunction name="CreateLinkList">
           <cfargument name="LinkIDArray" required="yes" type="array" hint="An array with the ID's of the records that begin each page">
           <cfargument name="Display" required="no" type="numeric" default="10" hint="How many records to show at per page">
           <cfargument name="StartRow" required="no" type="numeric" default="1" hint="What current row are we on so we know where to start displaying from">
           <cfargument name="PageNumber" required="no" type="numeric" default="0" hint="What current page are we on, so we know which link to bold">
           <cfargument name="BrowseSize" required="no" type="numeric" default="5" hint="How many link on either side of the current one should we show to prevent clutter?">
           
           <cfsavecontent variable="LinkList">
                <a href="#cgi.scriptname#?startrow=#arguments.LinkIDArray[1]#&display=#url.display#&pagenum=1&browsesize=#arguments.browsesize#"><< </a> 
                | 
                <cfloop from="1" to="#arraylen(RecordBrowseLinks)#" index="i">
                     <cfif (i-arguments.browsesize) LTE arguments.pagenumber and (i+arguments.browsesize) GTE arguments.pagenumber>
                          <cfif url.pagenum eq i>
                               <strong><a href="#cgi.scriptname#?startrow=#arguments.LinkIDArray[i]#&display=#arguments.display#&pagenum=#i#&browsesize=#arguments.browsesize#">#i#</a></strong> | 
                               <cfelse>
                                    <a href="#cgi.scriptname#?startrow=#arguments.LinkIDArray[i]#&display=#arguments.display#&pagenum=#i#&browsesize=#arguments.browsesize#">#i#</a> | 
                          </cfif>
                     </cfif>
                </cfloop>
                <a href="#cgi.scriptname#?startrow=#arguments.LinkIDArray[arraylen(RecordBrowseLinks)]#&display=#arguments.display#&pagenum=#arraylen(RecordBrowseLinks)#&browsesize=#arguments.browsesize#">>></a> 
           </cfsavecontent>
           
           <cfreturn LinkList>
      
      </cffunction>
      
      <cfset QueryData = GetRecords()>
      
      <cfset RecordBrowseLinks = RecordBrowser(QueryData,url.display)>
      
      <cfset GetDisplayableRecords = GetRecordsPage(QueryData,url.startrow,url.display)>
      
      <cfdump var="#GetDisplayableRecords#">
      
      <cfset LinkList = CreateLinkList(RecordBrowseLinks,url.display,url.startrow,url.pagenum,url.browsesize)>
      
      #linklist#
      </cfoutput>