diff --git a/webroot/components/datatables-plugins/api/average().js b/webroot/components/datatables-plugins/api/average().js new file mode 100644 index 0000000..cb400d6 --- /dev/null +++ b/webroot/components/datatables-plugins/api/average().js @@ -0,0 +1,32 @@ +/** + * It can sometimes be useful to get the average of data in an API result set, + * be it from a column, or a collection of cells. This method provides exactly + * that ability. + * + * @name average() + * @summary Average the values in a data set. + * @author [Allan Jardine](http://sprymedia.co.uk) + * @requires DataTables 1.10+ + * + * @returns {Number} Calculated average + * + * @example + * // Average a column + * var table = $('#example').DataTable(); + * table.column( 3 ).data().average(); + * + * @example + * // Average two cells + * var table = $('#example').DataTable(); + * table.cells( 0, [3,4] ).data().average(); + */ + +jQuery.fn.dataTable.Api.register( 'average()', function () { + var data = this.flatten(); + var sum = data.reduce( function ( a, b ) { + return (a*1) + (b*1); // cast values in-case they are strings + }, 0 ); + + return sum / data.length; +} ); + diff --git a/webroot/components/datatables-plugins/api/column().title().js b/webroot/components/datatables-plugins/api/column().title().js new file mode 100644 index 0000000..56394ea --- /dev/null +++ b/webroot/components/datatables-plugins/api/column().title().js @@ -0,0 +1,21 @@ +/** + * This plug-in will read the text from the header cell of a column, returning + * that value. + * + * @name column().title() + * @summary Get the title of a column + * @author Alejandro Navarro + * @requires DataTables 1.10+ + * + * @returns {String} Column title + * + * @example + * // Read the title text of column index 3 + * var table = $('#example').DataTable(); + * table.column( 3 ).title(); + */ + +$.fn.dataTable.Api.register( 'column().title()', function () { + var colheader = this.header(); + return $(colheader).text().trim(); +} ); \ No newline at end of file diff --git a/webroot/components/datatables-plugins/api/columns().order().js b/webroot/components/datatables-plugins/api/columns().order().js new file mode 100644 index 0000000..46b6488 --- /dev/null +++ b/webroot/components/datatables-plugins/api/columns().order().js @@ -0,0 +1,46 @@ +/** + * The DataTables core library provides the ability to set the ordering via the + * `dt-api column().order()` method, but there is no plural equivalent. While + * multi-column ordering can be set using `dt-api order()` that method requires + * that column indexes be used. + * + * This plug-in provides the plural `columns().order()` method so you can set + * multi-column ordering, while retaining the benefits of the `dt-api columns()` + * selector options. + * + * @name columns().order() + * @summary Apply multi-column ordering through the columns() API method. + * @author [Allan Jardine](http://sprymedia.co.uk) + * @requires DataTables 1.10+ + * @param {string|array} dir The order to apply to the columns selected. This + * can be a string (`asc` or `desc`) which will be applied to all columns, + * or an array (again `asc` or `desc` as the elements in the array) which is + * the same length as the number of columns selected, and will be applied to + * the columns in sequence. + * + * @returns {DataTables.Api} DataTables API instance + * + * @example + * // Apply multi-column sorting with a common direction + * table.columns( [ 1, 2 ] ).order( 'desc' ).draw(); + * + * @example + * // Multi-column sorting with individual direction for the columns + * table.columns( [ 1, 2 ] ).order( [ 'desc', 'asc' ] ).draw(); + * + * @example + * // Multi-column sorting based on a name selector + * table.columns( [ 'sign_up_date:name', 'user_name:name' ] ).order( 'desc' ).draw(); + */ + +$.fn.dataTable.Api.register( 'columns().order()', function ( dir ) { + return this.iterator( 'columns', function ( settings, columns ) { + var a = []; + + for ( var i=0, ien=columns.length ; i= 0 ) + { + oSettings._iDisplayStart = ( Math.floor(i / oSettings._iDisplayLength) ) * oSettings._iDisplayLength; + if ( this.oApi._fnCalculateEnd ) { + this.oApi._fnCalculateEnd( oSettings ); + } + } + + this.oApi._fnDraw( oSettings ); + return { + "nTr": nAdded, + "iPos": iAdded + }; +}; diff --git a/webroot/components/datatables-plugins/api/fnAddTr.js b/webroot/components/datatables-plugins/api/fnAddTr.js new file mode 100644 index 0000000..594d8e4 --- /dev/null +++ b/webroot/components/datatables-plugins/api/fnAddTr.js @@ -0,0 +1,74 @@ +/** + * This method will add an existing `dt-tag tr` element to a DataTable. This can + * be useful for maintaining custom classes and other attributes which have + * been explicitly assigned to the row. + * + * DataTables 1.10+ has `dt-api row.add()` and `dt-api rows.add()` which have + * this ability built in, and extend it to be able to use jQuery objects as well + * as plain `dt-tag tr` elements. As such this method is marked deprecated, but + * is available for use with legacy version of DataTables. Please use the + * new API if you are used DataTables 1.10 or newer. + * + * @name fnAddTr + * @summary Add a `dt-tag tr` element to the table + * @author [Allan Jardine](http://sprymedia.co.uk) + * @deprecated + * + * @param {node} nTr `dt-tag tr` element to add to the table + * @param {boolean} [bRedraw=false] Indicate if the table should do a redraw or not. + * + * @example + * var table = $('#example').dataTable(); + * table.fnAddTr( $(''+ + * '1'+ + * '2'+ + * '3'+ + * '')[0] + * ); + */ + +jQuery.fn.dataTableExt.oApi.fnAddTr = function ( oSettings, nTr, bRedraw ) { + if ( typeof bRedraw == 'undefined' ) + { + bRedraw = true; + } + + var nTds = nTr.getElementsByTagName('td'); + if ( nTds.length != oSettings.aoColumns.length ) + { + alert( 'Warning: not adding new TR - columns and TD elements must match' ); + return; + } + + var aData = []; + var aInvisible = []; + var i; + for ( i=0 ; i= 0 ; i-- ) + { + oSettings.aoData[iIndex]._anHidden[ i ] = nTds[aInvisible[i]]; + nTr.removeChild( nTds[aInvisible[i]] ); + } + + // Redraw + if ( bRedraw ) + { + this.oApi._fnReDraw( oSettings ); + } +}; diff --git a/webroot/components/datatables-plugins/api/fnColumnIndexToVisible.js b/webroot/components/datatables-plugins/api/fnColumnIndexToVisible.js new file mode 100644 index 0000000..2e106ec --- /dev/null +++ b/webroot/components/datatables-plugins/api/fnColumnIndexToVisible.js @@ -0,0 +1,33 @@ +/** + * When DataTables removes columns from the display (`bVisible` or + * `fnSetColumnVis`) it removes these elements from the DOM, effecting the index + * value for the column positions. This function converts the data column index + * (i.e. all columns regardless of visibility) into a visible column index. + * + * DataTables 1.10+ has this ability built-in through the + * `dt-api column.index()` method. As such this method is marked deprecated, but + * is available for use with legacy version of DataTables. + * + * @name fnColumnIndexToVisible + * @summary Convert a column data index to a visible index. + * @author [Allan Jardine](http://sprymedia.co.uk) + * @deprecated + * + * @param {integer} iMatch Column data index to convert to visible index + * @returns {integer} Visible column index + * + * @example + * var table = $('#example').dataTable( { + * aoColumnDefs: [ + * { bVisible: false, aTargets: [1] } + * ] + * } ); + * + * // This will show 1 + * alert( 'Column 2 visible index: '+table.fnColumnIndexToVisible(2) ); + */ + +jQuery.fn.dataTableExt.oApi.fnColumnIndexToVisible = function ( oSettings, iMatch ) +{ + return oSettings.oApi._fnColumnIndexToVisible( oSettings, iMatch ); +}; diff --git a/webroot/components/datatables-plugins/api/fnDataUpdate.js b/webroot/components/datatables-plugins/api/fnDataUpdate.js new file mode 100644 index 0000000..371e366 --- /dev/null +++ b/webroot/components/datatables-plugins/api/fnDataUpdate.js @@ -0,0 +1,25 @@ +/** + * Update the internal data for a `dt-tag tr` element based on what is used in the + * DOM. You will likely want to call fnDraw() after this function. + * + * DataTables 1.10+ has this ability built-in through the + * `dt-api row().invalidate()` method. As such this method is marked deprecated, + * but is available for use with legacy version of DataTables. Please use the + * new API if you are used DataTables 1.10 or newer. + * + * @name fnDataUpdate + * @summary Update DataTables cached data from the DOM + * @author Lior Gerson + * @deprecated + * + * @param {node} nTr `dt-tag tr` element to get the data from + * @param {integer} iRowIndex Row's position in the table (`fnGetPosition`). + */ + +jQuery.fn.dataTableExt.oApi.fnDataUpdate = function ( oSettings, nRowObject, iRowIndex ) +{ + jQuery(nRowObject).find("TD").each( function(i) { + var iColIndex = oSettings.oApi._fnVisibleToColumnIndex( oSettings, i ); + oSettings.oApi._fnSetCellData( oSettings, iRowIndex, iColIndex, jQuery(this).html() ); + } ); +}; diff --git a/webroot/components/datatables-plugins/api/fnDisplayRow.js b/webroot/components/datatables-plugins/api/fnDisplayRow.js new file mode 100644 index 0000000..ce47834 --- /dev/null +++ b/webroot/components/datatables-plugins/api/fnDisplayRow.js @@ -0,0 +1,46 @@ +/** + * This plug-in will take a `dt-tag tr` element and alter the table's paging + * to make that `dt-tag tr` element (i.e. that row) visible. + * + * @name fnDisplayRow + * @summary Shift the table's paging to display a given `dt-tag tr` element + * @author [Allan Jardine](http://sprymedia.co.uk) + * + * @param {node} nRow Row to display + * + * @example + * // Display the 21st row in the table + * var table = $('#example').dataTable(); + * table.fnDisplayRow( table.fnGetNodes()[20] ); + */ + +jQuery.fn.dataTableExt.oApi.fnDisplayRow = function ( oSettings, nRow ) +{ + // Account for the "display" all case - row is already displayed + if ( oSettings._iDisplayLength == -1 ) + { + return; + } + + // Find the node in the table + var iPos = -1; + for( var i=0, iLen=oSettings.aiDisplay.length ; i= 0 ) + { + oSettings._iDisplayStart = ( Math.floor(i / oSettings._iDisplayLength) ) * oSettings._iDisplayLength; + if ( this.oApi._fnCalculateEnd ) { + this.oApi._fnCalculateEnd( oSettings ); + } + } + + this.oApi._fnDraw( oSettings ); +}; diff --git a/webroot/components/datatables-plugins/api/fnDisplayStart.js b/webroot/components/datatables-plugins/api/fnDisplayStart.js new file mode 100644 index 0000000..4bb273b --- /dev/null +++ b/webroot/components/datatables-plugins/api/fnDisplayStart.js @@ -0,0 +1,32 @@ +/** + * Set the point at which DataTables will start it's display of data in the + * table. + * + * @name fnDisplayStart + * @summary Change the table's paging display start. + * @author [Allan Jardine](http://sprymedia.co.uk) + * @deprecated + * + * @param {integer} iStart Display start index. + * @param {boolean} [bRedraw=false] Indicate if the table should do a redraw or not. + * + * @example + * var table = $('#example').dataTable(); + * table.fnDisplayStart( 21 ); + */ + +jQuery.fn.dataTableExt.oApi.fnDisplayStart = function ( oSettings, iStart, bRedraw ) +{ + if ( typeof bRedraw == 'undefined' ) { + bRedraw = true; + } + + oSettings._iDisplayStart = iStart; + if ( oSettings.oApi._fnCalculateEnd ) { + oSettings.oApi._fnCalculateEnd( oSettings ); + } + + if ( bRedraw ) { + oSettings.oApi._fnDraw( oSettings ); + } +}; diff --git a/webroot/components/datatables-plugins/api/fnFakeRowspan.js b/webroot/components/datatables-plugins/api/fnFakeRowspan.js new file mode 100644 index 0000000..e3d9f48 --- /dev/null +++ b/webroot/components/datatables-plugins/api/fnFakeRowspan.js @@ -0,0 +1,66 @@ +/** + * Creates `rowspan` cells in a column when there are two or more cells in a + * row with the same content, effectively grouping them together visually. + * + * **Note** - this plug-in currently only operates correctly with + * **server-side processing**. + * + * @name fnFakeRowspan + * @summary Create a rowspan for cells which share data + * @author Fredrik Wendel + * + * @param {interger} iColumn Column index to have row span + * @param {boolean} [bCaseSensitive=true] If the data check should be case + * sensitive or not. + * @returns {jQuery} jQuery instance + * + * @example + * $('#example').dataTable().fnFakeRowspan(3); + */ + +jQuery.fn.dataTableExt.oApi.fnFakeRowspan = function ( oSettings, iColumn, bCaseSensitive ) { + /* Fail silently on missing/errorenous parameter data. */ + if (isNaN(iColumn)) { + return false; + } + + if (iColumn < 0 || iColumn > oSettings.aoColumns.length-1) { + alert ('Invalid column number choosen, must be between 0 and ' + (oSettings.aoColumns.length-1)); + return false; + } + + bCaseSensitive = (typeof(bCaseSensitive) != 'boolean' ? true : bCaseSensitive); + + function fakeRowspan () { + var firstOccurance = null, + value = null, + rowspan = 0; + jQuery.each(oSettings.aoData, function (i, oData) { + var val = oData._aData[iColumn], + cell = oData.nTr.childNodes[iColumn]; + /* Use lowercase comparison if not case-sensitive. */ + if (!bCaseSensitive) { + val = val.toLowerCase(); + } + /* Reset values on new cell data. */ + if (val != value) { + value = val; + firstOccurance = cell; + rowspan = 0; + } + + if (val == value) { + rowspan++; + } + + if (firstOccurance !== null && val == value && rowspan > 1) { + oData.nTr.removeChild(cell); + firstOccurance.rowSpan = rowspan; + } + }); + } + + oSettings.aoDrawCallback.push({ "fn": fakeRowspan, "sName": "fnFakeRowspan" }); + + return this; +}; diff --git a/webroot/components/datatables-plugins/api/fnFilterAll.js b/webroot/components/datatables-plugins/api/fnFilterAll.js new file mode 100644 index 0000000..6a4cf92 --- /dev/null +++ b/webroot/components/datatables-plugins/api/fnFilterAll.js @@ -0,0 +1,39 @@ +/** + * Apply the same filter to all DataTable instances on a particular page. The + * function call exactly matches that used by `fnFilter()` so regular expression + * and individual column sorting can be used. + * + * DataTables 1.10+ provides this ability through its new API, which is able to + * to control multiple tables at a time. + * `$('.dataTable').DataTable().search( ... )` for example will apply the same + * filter to all tables on the page. The new API should be used in preference + * to this older method if at all possible. + * + * @name fnFilterAll + * @summary Apply a common filter to all DataTables on a page + * @author [Kristoffer Karlström](http://www.kmmtiming.se/) + * @deprecated + * + * @param {string} sInput Filtering input + * @param {integer} [iColumn=null] Column to apply the filter to + * @param {boolean} [bRegex] Regular expression flag + * @param {boolean} [bSmart] Smart filtering flag + * + * @example + * $(document).ready(function() { + * var table = $(".dataTable").dataTable(); + * + * $("#search").keyup( function () { + * // Filter on the column (the index) of this element + * table.fnFilterAll(this.value); + * } ); + * }); + */ + +jQuery.fn.dataTableExt.oApi.fnFilterAll = function(oSettings, sInput, iColumn, bRegex, bSmart) { + var settings = $.fn.dataTableSettings; + + for ( var i=0 ; i= oSettings.aiDisplay.length ) + { + /* There is no next/previous element */ + return null; + } + + /* Return the target node from the aoData store */ + return oSettings.aoData[ oSettings.aiDisplay[ iDisplayIndex ] ].nTr; +}; diff --git a/webroot/components/datatables-plugins/api/fnGetColumnData.js b/webroot/components/datatables-plugins/api/fnGetColumnData.js new file mode 100644 index 0000000..5d62cdf --- /dev/null +++ b/webroot/components/datatables-plugins/api/fnGetColumnData.js @@ -0,0 +1,83 @@ +/** + * Return an array of table values from a particular column, with various + * filtering options. + * + * DataTables 1.10+ provides the `dt-api column().data()` method, built-in to + * the core, to provide this ability. As such, this method is marked deprecated, + * but is available for use with legacy version of DataTables. Please use the + * new API if you are used DataTables 1.10 or newer. + * + * @name fnGetColumnData + * @summary Get the data from a column + * @author [Benedikt Forchhammer](http://mind2.de) + * @deprecated + * + * @param {integer} iColumn Column to get data from + * @param {boolean} [bFiltered=true] Reduce the data set to only unique values + * @param {boolean} [bUnique=true] Get data from filter results only + * @param {boolean} [bIgnoreEmpty=true] Remove data elements which are empty + * @returns {array} Array of data from the column + * + * @example + * var table = $('#example').dataTable(); + * table.fnGetColumnData( 3 ); + */ + +jQuery.fn.dataTableExt.oApi.fnGetColumnData = function ( oSettings, iColumn, bUnique, bFiltered, bIgnoreEmpty ) { + // check that we have a column id + if ( typeof iColumn == "undefined" ) { + return []; + } + + // by default we only wany unique data + if ( typeof bUnique == "undefined" ) { + bUnique = true; + } + + // by default we do want to only look at filtered data + if ( typeof bFiltered == "undefined" ) { + bFiltered = true; + } + + // by default we do not wany to include empty values + if ( typeof bIgnoreEmpty == "undefined" ) { + bIgnoreEmpty = true; + } + + // list of rows which we're going to loop through + var aiRows; + + // use only filtered rows + if (bFiltered === true) { + aiRows = oSettings.aiDisplay; + } + // use all rows + else { + aiRows = oSettings.aiDisplayMaster; // all row numbers + } + + // set up data array + var asResultData = []; + + for (var i=0,c=aiRows.length; i -1) { + continue; + } + + // else push the value onto the result data array + else { + asResultData.push(sValue); + } + } + + return asResultData; +}; diff --git a/webroot/components/datatables-plugins/api/fnGetColumnIndex.js b/webroot/components/datatables-plugins/api/fnGetColumnIndex.js new file mode 100644 index 0000000..d48c29a --- /dev/null +++ b/webroot/components/datatables-plugins/api/fnGetColumnIndex.js @@ -0,0 +1,31 @@ +/** + * Maintenance of web-sites can often cause unexpected headaches, particularly + * if the hardcoded index of an array (the columns in a DataTables instance) + * needs to change due to an added or removed column. This plug-in function + * will match a given string to the title of a column in the table and return + * the column index, helping to overcome this problem. + * + * @name fnGetColumnIndex + * @summary Get the column index by searching the column titles + * @author [Michael Ross](http://www.rosstechassociates.com/) + * + * @param {string} sCol Column title to search for + * @returns {integer} Column index, or -1 if not found + * + * @example + * var table = $('#example').dataTable(); + * table.fnGetColumnIndex( 'Browser' ); + */ + +jQuery.fn.dataTableExt.oApi.fnGetColumnIndex = function ( oSettings, sCol ) +{ + var cols = oSettings.aoColumns; + for ( var x=0, xLen=cols.length ; x