DataTables logo DataTables

This is a legacy documentation page and the methods described may not work with DataTables 1.10+.
Please see the upgrade notes for 1.10.

Server-side processing | ColdFusion

When you've got a ColdFusion server to hand, this script is ideal for integration with DataTables. To configure it for your server-side up, the main area of interest is in the a 'Easy set variables' area. Simply change the listColumns list to state the columns you wish to include from your database, set sIndexColumn to a column which is indexed (for speed), sTableName to the table name and coldfusionDatasource for the database data source.

Feature set


	Script:    DataTables server-side script for ColdFusion (cfm) and MySQL	
	License:   GPL v2 or BSD (3-point)	
		tested with DataTables 1.6.1 and jQuery 1.2.6+, Adobe ColdFusion 9 (but should work fine on at least 7+)
		to work with pre 1.6 datatables replace both occurances of sSortDir_ with iSortDir_ 
		Get a free developer version of ColdFusion from
		or try out the open source railo cfml engine from
 	Easy set variables
<!--- table name --->
<cfset sTableName = "ajax" />

<!--- list of database columns which should be read and sent back to DataTables --->
<cfset listColumns = "engine,browser,platform,version,grade" />

<!--- Indexed column --->
<cfset sIndexColumn = "id" />
<!--- ColdFusion Datasource for the MySQL connection --->
<cfset coldfusionDatasource = ""/>

If you just want to use the basic configuration for DataTables with ColdFusion server-side, there is no need to edit below this line

Note: there is additional configuration below for the "version" column in query and output 

	ColdFusion Specific Note: I handle Paging, Filtering and Ordering a bit different than some of the other server side versions
	ColdFusion Specific Note: I am handling paging in the cfoutput statement instead of limit.   
<cfparam name="url.iDisplayStart" default="0" type="integer" />
<cfparam name="url.iDisplayLength" default="10" type="integer" />

	NOTE: this does not match the built-in DataTables filtering which does it
	 	word by word on any field. It's possible to do here, but concerned about efficiency
	 	on very large tables, and MySQL's regex functionality is very limited
	ColdFusion Specific Note: 
	I am handling this in the actual query call, because i want the statement parameterized to avoid possible sql injection
<cfparam name="url.sSearch" default="" type="string" />

<cfparam name="url.iSortingCols" default="0" type="integer" />

	SQL queries
	Get data to display

<!--- Data set after filtering --->
<cfquery datasource="#coldfusionDatasource#" name="qFiltered">
		FROM #sTableName# 
	<cfif len(trim(url.sSearch))>
		WHERE <cfloop list="#listColumns#" index="thisColumn"><cfif thisColumn neq listFirst(listColumns)> OR </cfif>#thisColumn# LIKE <cfif thisColumn is "version"><!--- special case ---><cfqueryparam cfsqltype="CF_SQL_FLOAT" value="#val(url.sSearch)#" /><cfelse><cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="%#trim(url.sSearch)#%" /></cfif></cfloop>
	<cfif url.iSortingCols gt 0>
		ORDER BY <cfloop from="0" to="#url.iSortingCols-1#" index="thisS"><cfif thisS is not 0>, </cfif>#listGetAt(listColumns,(url["iSortCol_"&thisS]+1))# <cfif listFindNoCase("asc,desc",url["sSortDir_"&thisS]) gt 0>#url["sSortDir_"&thisS]#</cfif> </cfloop>

<!--- Total data set length --->
<cfquery datasource="#coldfusionDatasource#" name="qCount">
	SELECT COUNT(#sIndexColumn#) as total
	FROM   #sTableName#

<cfcontent reset="Yes" />
{"sEcho": <cfoutput>#val(url.sEcho)#</cfoutput>, 
"iTotalRecords": <cfoutput></cfoutput>, 
"iTotalDisplayRecords": <cfoutput>#qFiltered.recordCount#</cfoutput>, 
"aaData": [ 
	<cfoutput query="qFiltered" startrow="#val(url.iDisplayStart+1)#" maxrows="#val(url.iDisplayLength)#">
		<cfif currentRow gt (url.iDisplayStart+1)>,</cfif>
		[<cfloop list="#listColumns#" index="thisColumn"><cfif thisColumn neq listFirst(listColumns)>,</cfif><cfif thisColumn is "version"><cfif version eq 0>"-"<cfelse>"#jsStringFormat(version)#"</cfif><cfelse>"#jsStringFormat(qFiltered[thisColumn][qFiltered.currentRow])#"</cfif></cfloop>]
	</cfoutput> ] }