Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save trycf/ec5aa6e708d5d179358bb0a024c42171 to your computer and use it in GitHub Desktop.
Save trycf/ec5aa6e708d5d179358bb0a024c42171 to your computer and use it in GitHub Desktop.
TryCF Gist
<cffunction name="GetData" access="remote" returnformat="json" returntype="any" output="false">
<cfargument name="start" type="numeric" default="1">
<cfargument name="length" type="numeric" default="200">
<cfparam name="draw" default="1" type="integer" />
<cfparam name="search" default="" type="string" />
<cfset var aData = arrayNew(1) />
<cfset var sGridData = StructNew() />
<cfif len(inparam["search[value]"]) gt 0>
<cfset search=inparam["search[value]"]>
</cfif>
<cfset var rsQuery = ''>
<cfset rsQuery = orders(inparam,search,start,length)>
<cfset rQuery = rsQuery.query>
<cfset rCount = rsQuery.count>
<cfset var totalRecords = val(rCount.totalcount)>
<cfset aData = getJSONData('query',rQuery,aData,sGridData)>
<cfset sGridReturn["draw"] = val(draw) />
<cfset sGridReturn["recordsTotal"] = totalRecords />
<cfset sGridReturn["recordsFiltered"] = totalRecords />
<cfset sGridReturn["data"] = aData />
<cfreturn sGridReturn />
</cffunction>
<cffunction name="orders" returntype="any">
<cfargument name="inparam" required="false" default="" type="any">
<cfargument name="search" required="false" default="">
<cfargument name="start" type="numeric" default="1">
<cfargument name="length" type="numeric" default="200">
<cfset var offset = (start-1) * length>
<cfset var rsQuery = ''>
<cfsavecontent variable="MainQuery">
SELECT *
FROM
bills
WHERE
billtype = 'Bill'
</cfsavecontent>
<cfquery name="rsQuery" datasource="#Application.dsn#">
#preserveSingleQuotes(MainQuery)#
<cfif len(trim(search))>
AND
(
<cfloop list="#listColumns#" index="thisColumn">
<cfif thisColumn neq listFirst(listColumns)>
OR
</cfif>
#thisColumn# LIKE <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="%#trim(search)#%" />
</cfloop>
)
</cfif>
ORDER BY BillID desc
LIMIT #length# OFFSET #offset#
</cfquery>
<cfreturn rsQuery>
</cffunction>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment