Permalink
Browse files

adding files

  • Loading branch information...
1 parent 1294dc5 commit 5105a45524223c448be86504d974c52e23f9a945 Mike Henke committed Nov 9, 2012
Showing with 324 additions and 0 deletions.
  1. +194 −0 datatables.cfm
  2. +106 −0 datatables_processing.cfm
  3. +24 −0 tableid_action.cfm
View
@@ -0,0 +1,194 @@
+<!--- sort types: num-html, formatted-num, anti-the, string, numeric, date, null, or html --->
+<cfparam name="attributes.tableid" type="string" />
+<cfparam name="attributes.serverside" type="boolean" default="false" />
+<cfparam name="attributes.sorttype" type="string" default="false"/>
+<cfparam name="attributes.sort" type="string" default="false"/>
+<cfparam name="attributes.toolbar" type="boolean" default="true"/>
+<cfparam name="attributes.scroller" type="boolean" default="false"/>
+<cfparam name="attributes.colvis" type="boolean" default="false"/>
+<cfparam name="attributes.reorder" type="boolean" default="false"/>
+<cfparam name="attributes.state" type="boolean" default="false"/>
+<cfparam name="attributes.showentries" type="boolean" default="true"/>
+<cfparam name="attributes.querystring" type="struct" default="#StructNew()#"/>
+<cfparam name="attributes.disablesort" type="string" default=""/>
+<cfparam name="attributes.datefilter" type="array" default="#ArrayNew(1)#"/>
+<cfparam name="attributes.iDisplayLength" type="string" default="10"/>
+
+
+<!--- must have position 1 and 2 and both integers --->
+<!--- default if don't exist 3 (current date mins 30) and 4 (current date plus 30) AND they are both dates--->
+<!--- http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions-pt0_03.html --->
+<cfif ArrayLen(attributes.datefilter)>
+ <div id="baseDateControl">
+ <div align="center">
+ Between <input type="text" name="dateStart" id="dateStart" class="jquerydatepicker" value="<cfoutput>#dateformat(attributes.datefilter[3],"mm/dd/yyyy")#</cfoutput>" size="8" /> and
+ <input type="text" name="dateEnd" id="dateEnd" class="jquerydatepicker" value="<cfoutput>#dateformat(attributes.datefilter[4],"mm/dd/yyyy")#</cfoutput>" size="8"/>
+ </div>
+ </div>
+</cfif>
+
+
+<cfset attributes.sortarray = ListToArray(attributes.sorttype)>
+<cfset attributes.sortarraylen = ArrayLen(attributes.sortarray)>
+
+<!--- on initial request, run query --->
+<cfset "session.#attributes.tableid#" = "" />
+ <script type="text/javascript" charset="utf-8">
+
+ jQuery.fn.dataTableExt.oSort['num-html-asc'] = function(a,b) {
+ var x = a.replace( /<.*?>/g, "" );
+ var y = b.replace( /<.*?>/g, "" );
+ x = parseFloat( x );
+ y = parseFloat( y );
+ return ((x < y) ? -1 : ((x > y) ? 1 : 0));
+ };
+
+ jQuery.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
+ var x = a.replace( /<.*?>/g, "" );
+ var y = b.replace( /<.*?>/g, "" );
+ x = parseFloat( x );
+ y = parseFloat( y );
+ return ((x < y) ? 1 : ((x > y) ? -1 : 0));
+ };
+
+ jQuery.fn.dataTableExt.oSort['formatted-num-asc'] = function(a,b) {
+ /* Remove any formatting */
+ var x = a.match(/\d/) ? a.replace( /[^\d\-\.]/g, "" ) : 0;
+ var y = b.match(/\d/) ? b.replace( /[^\d\-\.]/g, "" ) : 0;
+
+ /* Parse and return */
+ return parseFloat(x) - parseFloat(y);
+ };
+
+ jQuery.fn.dataTableExt.oSort['formatted-num-desc'] = function(a,b) {
+ var x = a.match(/\d/) ? a.replace( /[^\d\-\.]/g, "" ) : 0;
+ var y = b.match(/\d/) ? b.replace( /[^\d\-\.]/g, "" ) : 0;
+
+ return parseFloat(y) - parseFloat(x);
+ };
+
+ jQuery.fn.dataTableExt.oSort['anti-the-asc'] = function(a,b) {
+ var x = a.replace(/^the /i, "");
+ var y = b.replace(/^the /i, "");
+ return ((x < y) ? -1 : ((x > y) ? 1 : 0));
+ };
+
+ jQuery.fn.dataTableExt.oSort['anti-the-desc'] = function(a,b) {
+ var x = a.replace(/^the /i, "");
+ var y = b.replace(/^the /i, "");
+ return ((x < y) ? 1 : ((x > y) ? -1 : 0));
+ };
+
+
+ $(document).ready(function() {
+ var $oTable = $('#<cfoutput>#attributes.tableid#</cfoutput>').dataTable(
+ {
+ <cfif attributes.serverside>
+ "bProcessing": true,
+ "bServerSide": true,
+ "sAjaxSource": "<cfoutput>#attributes.tableid#.cfm?<cfloop collection = #attributes.querystring# item = "urlname">#urlname#=#StructFind(attributes.querystring, urlname)#&</cfloop></cfoutput>",
+ </cfif>
+
+ "sPaginationType": "full_numbers",
+ "aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
+
+ <cfif attributes.state>
+ "bStateSave": true,
+ </cfif>
+
+ <cfif len(attributes.disablesort)>
+ "aoColumnDefs": [
+ { "bSortable": false, "aTargets": [ <cfoutput>#attributes.disablesort#</cfoutput> ] }
+ ],
+ </cfif>
+
+ "iDisplayLength": <cfoutput>#attributes.iDisplayLength#</cfoutput>,
+ "sDom": '<cfif attributes.toolbar>T</cfif><cfif attributes.colvis>C</cfif><cfif attributes.toolbar or attributes.colvis><"clear"></cfif><cfif attributes.reorder>R</cfif><cfif attributes.showentries or attributes.toolbar>l</cfif>frtip<cfif attributes.scroller>S</cfif>'
+
+ <cfif attributes.scroller>
+ , "sScrollY": "200px",
+ "bDeferRender": true,
+ "bPaginate": false
+ </cfif>
+
+ <cfif attributes.toolbar>
+ , "oTableTools": {
+ "sSwfPath": "/solutiontrack/library/swf/copy_cvs_xls_pdf.swf",
+ "sExtends": "text",
+ "bHeader": true,
+ "aButtons": [
+ {
+ "sExtends": "xls",
+ "sFileName": "TableTools.csv"
+ },
+ "pdf",
+ "print"
+ ]
+ }
+ </cfif>
+
+ <cfif attributes.sortarray[1] neq 'false'>
+ , "aoColumns": [
+ <cfloop index="sType" from="1" to="#arrayLen(attributes.sortarray)#">
+ <cfif attributes.sortarray[sType] EQ "null">
+ null
+ <cfelse>
+ { "sType": "<cfoutput>#attributes.sortarray[sType]#</cfoutput>" }
+ </cfif>
+ <cfif arrayLen(attributes.sortarray) neq sType>,</cfif>
+ </cfloop>
+ ]
+ </cfif>
+
+ <cfif attributes.sort neq 'false'>
+ ,"aaSorting": [<cfoutput>#attributes.sort#</cfoutput>]
+ </cfif>
+ }
+ );
+
+ <cfif ArrayLen(attributes.datefilter)>
+ // The plugin function for adding a new filtering routine
+ $.fn.dataTableExt.afnFiltering.push(
+ function(oSettings, aData, iDataIndex){
+ var dateStart = parseDateValue($("#dateStart").val());
+ var dateEnd = parseDateValue($("#dateEnd").val());
+ // aData represents the table structure as an array of columns, so the script access the date value
+ // in the first column of the table via aData[0]
+ var evalDate= parseDateValue(aData[<cfoutput>#attributes.datefilter[2]#</cfoutput>]);
+
+ if (evalDate >= dateStart && evalDate <= dateEnd) {
+ return true;
+ }
+ else {
+ return false;
+ }
+
+ });
+
+ // Function for converting a mm/dd/yyyy date value into a numeric string for comparison (example 08/12/2010 becomes 20100812
+ function parseDateValue(rawDate) {
+ var dateArray= rawDate.split("/");
+ var parsedDate= dateArray[2] + dateArray[0] + dateArray[1];
+ return parsedDate;
+ }
+
+
+
+ <!--- $dateControls= $("#baseDateControl").children("div").clone();
+ $("#<cfoutput>#attributes.tableid#</cfoutput>_filter").prepend($dateControls);
+
+ --->
+
+
+ // Create event listeners that will filter the table whenever the user types in either date range box or
+ // changes the value of either box using the Datepicker pop-up calendar
+ $("#dateStart").keyup ( function() { $oTable.fnDraw(); } );
+ $("#dateStart").change( function() { $oTable.fnDraw(); } );
+ $("#dateEnd").keyup ( function() { $oTable.fnDraw(); } );
+ $("#dateEnd").change( function() { $oTable.fnDraw(); } );
+ </cfif>
+
+} );
+ </script>
+
+
View
@@ -0,0 +1,106 @@
+<!---
+Script: DataTables server-side script for ColdFusion (cfm) and MySQL
+License: GPL v2 or BSD (3-point)
+Notes:
+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 http://www.adobe.com/products/coldfusion/
+or try out the open source railo cfml engine from http://www.getrailo.org/
+or try out the open source openbd cfml engine from http://www.openbluedragon.org/
+--->
+
+<!--- turn off debugging output --->
+<cfsetting showDebugOutput="No">
+<cfset listColumns = "" />
+<cfset listColumnsCast = "" />
+<cfset flag_cast = 0 />
+
+<cfset arrayMetaData = getMetaData(evaluate("session.#filename#")) />
+<cfset qOriginal = replace(de('session.#filename#'),'"','','all') />
+
+<cfloop index="thisColumn" from="1" to="#arraylen(arrayMetaData)#">
+ <cfset listColumns = ListAppend(listColumns, arrayMetaData[thisColumn]["Name"]) />
+ <cfset listColumnsCast = ListAppend(listColumnsCast, "CAST(#arrayMetaData[thisColumn]["Name"]# as VARCHAR) as #arrayMetaData[thisColumn]["Name"]#") />
+
+ <cfif arrayMetaData[thisColumn]["TypeName"] NEQ "VARCHAR">
+ <cfset flag_cast = 1 />
+ </cfif>
+</cfloop>
+
+<!--- set query of queries --->
+<cfset objAttributes.dbtype = "query"/>
+
+<cfif flag_cast>
+ <!--- set columns to varchar --->
+ <cfset objAttributes.name="queryObject" />
+ <cfquery attributecollection="#objAttributes#">
+ SELECT #listColumnsCast#
+ FROM #qOriginal#
+ </cfquery>
+</cfif>
+
+<!--- query name for filtering data set--->
+<cfset objAttributes.name="qFiltered" />
+
+<!---
+Paging
+--->
+<cfparam name="url.iDisplayStart" default="0" type="integer" />
+<cfparam name="url.iDisplayLength" default="10" type="integer" />
+<cfparam name="url.sIndexColumn" default="1" />
+
+<cfparam name="url.sSearch" default="" type="string" />
+
+!---
+Ordering
+--->
+<cfparam name="url.iSortingCols" default="0" type="integer" />
+
+<!--- Data set after filtering --->
+<cfquery attributecollection="#objAttributes#">
+ SELECT #listColumns#
+ FROM #qOriginal#
+
+ <!--- setup where clause --->
+ <cfif len(trim(url.sSearch))>
+ WHERE
+ 1 = 0
+ <!--- filter --->
+ <cfloop index="thisColumn" from="1" to="#arraylen(arrayMetaData)#">
+ OR CAST(UPPER(#arrayMetaData[thisColumn]["Name"]#) AS VARCHAR)
+ LIKE <cfqueryparam value="%#ucase(trim(url.sSearch))#%">
+ </cfloop>
+ </cfif>
+
+ <!--- Ordering --->
+ ORDER BY
+ <cfif url.iSortingCols gt 0>
+ <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>
+ <cfelse>
+ #sIndexColumn#
+ </cfif>
+</cfquery>
+
+<!--- set length for the initial unfiltered data set --->
+<cfset qCount.total = evaluate("session.#filename#.recordcount")>
+
+<!--- Output --->
+<cfcontent reset="Yes" />
+{"sEcho": <cfoutput>#val(url.sEcho)#</cfoutput>,
+"iTotalRecords": <cfoutput>#qCount.total#</cfoutput>,
+"iTotalDisplayRecords": <cfoutput>#qFiltered.recordCount#</cfoutput>,
+"aaData": [
+<cfoutput query="qFiltered" startrow="#val(url.iDisplayStart+1)#" maxrows="#((val(url.iDisplayLength) LT 0) ? val(evaluate('#qOriginal#.recordcount')) : val(url.iDisplayLength))#">
+
+<cfif currentRow gt (url.iDisplayStart+1)>,</cfif>
+[<cfloop list="#listColumns#" index="thisColumn">
+<cfif thisColumn neq listFirst(listColumns)>,</cfif>
+#serializeJSON(qFiltered[thisColumn][qFiltered.currentRow])#
+</cfloop>
+]
+</cfoutput>
+] }
View
@@ -0,0 +1,24 @@
+<cfcontent reset="true" type="application/json" />
+
+<!--- sets filename as session variable --->
+<cfset filename = evaluate("replace(GetFileFromPath(GetCurrentTemplatePath()),'.cfm','')")>
+<cfparam name="session.#evaluate("filename")#" default="">
+
+<!--- if sessions not set on server or initial request, the variable will not be a query --->
+<cfif not IsQuery(evaluate("session.#filename#"))>
+ <!--- initial data set for query of queries --->
+ <CFQUERY name="qrydatatable">
+ <!--- sql here if need links you will need to build them out like
+ '<a href="/mike/rocks/cool.cfm?id=urlencodedformat('+convert(varchar(10),x.id)+')">'+x.name+'</a>' as link
+
+ --->
+</cfquery>
+ <!--- SQL queries Get data to display --->
+ <cfset "session.#filename#" = qrydatatable>
+</cfif>
+
+<!--- initial sorting column --->
+<cfset sIndexColumn = "next_due_date" />
+
+<!--- generic processing (no need to touch)--->
+<cfinclude template="/solutiontrack/library/datatables_processing.cfm" />

0 comments on commit 5105a45

Please sign in to comment.