Added assets + dependencies

This commit is contained in:
Bill Zimmerman
2015-02-25 14:08:14 +01:00
parent cb37f12f56
commit d5678d622e
748 changed files with 154165 additions and 0 deletions

View File

@@ -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
} );
return sum / data.length;
} );

View File

@@ -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();
} );

View File

@@ -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<ien ; i++ ) {
a.push( [ columns[i], $.isArray(dir) ? dir[i] : dir ] );
}
new $.fn.dataTable.Api( settings ).order( a );
} );
} );

View File

@@ -0,0 +1,63 @@
/**
* Add a new row to the table and display it on the screen by jumping the
* pagination to the required location. This function also returns an object
* with the added `dt-tag TR` element and it's index in `aoData` such that you
* could provide an effect (fade for example) to show which row has been added.
*
* This function is a drop in replacement for `fnAddData` with one important
* exception, it will only take a 1D array or an object, and not a 2D array
* (i.e. it will not add multiple rows like `fnAddData`).
*
* @name fnAddDataAndDisplay
* @summary Add data and shift the paging to display it immediately
* @author [Allan Jardine](http://sprymedia.co.uk)
*
* @param {data} aData Data to add to the table
* @returns {object} Object with `nTr` and `iPos` parameters, where the former
* is the added `dt-tag tr` element and the latter is the row's index.
*
* @example
* $(document).ready(function() {
* var table = $('#example').dataTable();
* table.fnAddDataAndDisplay( [ 1, 2, 3, 4, 5, ... ] );
* } );
*/
jQuery.fn.dataTableExt.oApi.fnAddDataAndDisplay = function ( oSettings, aData )
{
/* Add the data */
var iAdded = this.oApi._fnAddData( oSettings, aData );
var nAdded = oSettings.aoData[ iAdded ].nTr;
/* Need to re-filter and re-sort the table to get positioning correct, not perfect
* as this will actually redraw the table on screen, but the update should be so fast (and
* possibly not alter what is already on display) that the user will not notice
*/
this.oApi._fnReDraw( oSettings );
/* Find it's position in the table */
var iPos = -1;
for( var i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ )
{
if( oSettings.aoData[ oSettings.aiDisplay[i] ].nTr == nAdded )
{
iPos = i;
break;
}
}
/* Get starting point, taking account of paging */
if( iPos >= 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
};
};

View File

@@ -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( $('<tr>'+
* '<td>1</td>'+
* '<td>2</td>'+
* '<td>3</td>'+
* '</tr>')[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<nTds.length ; i++ )
{
aData.push( nTds[i].innerHTML );
if (!oSettings.aoColumns[i].bVisible)
{
aInvisible.push( i );
}
}
/* Add the data and then replace DataTable's generated TR with ours */
var iIndex = this.oApi._fnAddData( oSettings, aData );
nTr._DT_RowIndex = iIndex;
oSettings.aoData[ iIndex ].nTr = nTr;
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
// Hidding invisible columns
for ( i = (aInvisible.length - 1) ; i >= 0 ; i-- )
{
oSettings.aoData[iIndex]._anHidden[ i ] = nTds[aInvisible[i]];
nTr.removeChild( nTds[aInvisible[i]] );
}
// Redraw
if ( bRedraw )
{
this.oApi._fnReDraw( oSettings );
}
};

View File

@@ -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 );
};

View File

@@ -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() );
} );
};

View File

@@ -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<iLen ; i++ )
{
if( oSettings.aoData[ oSettings.aiDisplay[i] ].nTr == nRow )
{
iPos = i;
break;
}
}
// Alter the start point of the paging display
if( iPos >= 0 )
{
oSettings._iDisplayStart = ( Math.floor(i / oSettings._iDisplayLength) ) * oSettings._iDisplayLength;
if ( this.oApi._fnCalculateEnd ) {
this.oApi._fnCalculateEnd( oSettings );
}
}
this.oApi._fnDraw( oSettings );
};

View File

@@ -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 );
}
};

View File

@@ -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;
};

View File

@@ -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<settings.length ; i++ ) {
settings[i].oInstance.fnFilter( sInput, iColumn, bRegex, bSmart);
}
};

View File

@@ -0,0 +1,63 @@
/**
* Remove all filtering that has been applied to a DataTable, be it column
* based filtering or global filtering.
*
* DataTables 1.10+ new API can achieve the same effect as this plug-in, without
* the requirement for plug-ins using the following chaining:
*
* ```js
* var table = $('#example').DataTable();
* table
* .search( '' )
* .columns().search( '' )
* .draw();
* ```
*
* Please use the new API in DataTables 1.10+ is you are able to do so.
*
* @name fnFilterClear
* @summary Remove all column and global filters applied to a table
* @author [Allan Jardine](http://sprymedia.co.uk)
* @deprecated
*
* @example
* $(document).ready(function() {
* var table = $('#example').dataTable();
*
* // Perform a filter
* table.fnFilter('Win');
* table.fnFilter('Trident', 0);
*
* // Remove all filtering
* table.fnFilterClear();
* } );
*/
jQuery.fn.dataTableExt.oApi.fnFilterClear = function ( oSettings )
{
var i, iLen;
/* Remove global filter */
oSettings.oPreviousSearch.sSearch = "";
/* Remove the text of the global filter in the input boxes */
if ( typeof oSettings.aanFeatures.f != 'undefined' )
{
var n = oSettings.aanFeatures.f;
for ( i=0, iLen=n.length ; i<iLen ; i++ )
{
$('input', n[i]).val( '' );
}
}
/* Remove the search text for the column filters - NOTE - if you have input boxes for these
* filters, these will need to be reset
*/
for ( i=0, iLen=oSettings.aoPreSearchCols.length ; i<iLen ; i++ )
{
oSettings.aoPreSearchCols[i].sSearch = "";
}
/* Redraw */
oSettings.oApi._fnReDraw( oSettings );
};

View File

@@ -0,0 +1,36 @@
/**
* This plug-in removes the default behaviour of DataTables to filter on each
* keypress, and replaces with it the requirement to press the enter key to
* perform the filter.
*
* @name fnFilterOnReturn
* @summary Require the return key to be pressed to filter a table
* @author [Jon Ranes](http://www.mvccms.com/)
*
* @returns {jQuery} jQuery instance
*
* @example
* $(document).ready(function() {
* $('.dataTable').dataTable().fnFilterOnReturn();
* } );
*/
jQuery.fn.dataTableExt.oApi.fnFilterOnReturn = function (oSettings) {
var _that = this;
this.each(function (i) {
$.fn.dataTableExt.iApiIndex = i;
var $this = this;
var anControl = $('input', _that.fnSettings().aanFeatures.f);
anControl
.unbind('keyup search input')
.bind('keypress', function (e) {
if (e.which == 13) {
$.fn.dataTableExt.iApiIndex = i;
_that.fnFilter(anControl.val());
}
});
return this;
});
return this;
};

View File

@@ -0,0 +1,55 @@
/**
* Search through a table looking for a given string (optionally the search
* can be restricted to a single column). The return value is an array with
* the data indexes (from DataTables' internal data store) for any rows which
* match.
*
* @name fnFindCellRowIndexes
* @summary Search for data, returning row indexes
* @author [Allan Jardine](http://sprymedia.co.uk)
*
* @param {string} sSearch Data to search for
* @param {integer} [iColumn=null] Limit search to this column
* @returns {array} Array of row indexes with this data
*
* @example
* $(document).ready(function() {
* var table = $('#example').dataTable();
*
* var a = table.fnFindCellRowIndexes( '1.7' ); // Search all columns
*
* var b = table.fnFindCellRowIndexes( '1.7', 3 ); // Search only column 3
* } );
*/
jQuery.fn.dataTableExt.oApi.fnFindCellRowIndexes = function ( oSettings, sSearch, iColumn )
{
var
i,iLen, j, jLen, val,
aOut = [], aData,
columns = oSettings.aoColumns;
for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
{
aData = oSettings.aoData[i]._aData;
if ( iColumn === undefined )
{
for ( j=0, jLen=columns.length ; j<jLen ; j++ )
{
val = this.fnGetData(i, j);
if ( val == sSearch )
{
aOut.push( i );
}
}
}
else if (this.fnGetData(i, iColumn) == sSearch )
{
aOut.push( i );
}
}
return aOut;
};

View File

@@ -0,0 +1,55 @@
/**
* Much like `fnFindCellRowIndexes` this plug-in will search a table for
* matching data (optionally the search can be restricted to a single column),
* but in this case the returned array contains `dt-tag tr` nodes of the
* matching rows, rather than data indexes.
*
* @name fnFindCellRowNodes
* @summary Search for data, returning row nodes
* @author [Allan Jardine](http://sprymedia.co.uk)
*
* @param {string} sSearch Data to search for
* @param {integer} [iColumn=null] Limit search to this column
* @returns {array} Array of `dt-tag tr` element with this data
*
* @example
* $(document).ready(function() {
* var table = $('#example').dataTable();
*
* var a = table.fnFindCellRowNodes( '1.7' ); // Search all columns
*
* var b = table.fnFindCellRowNodes( '1.7', 3 ); // Search only column 3
* } );
*/
jQuery.fn.dataTableExt.oApi.fnFindCellRowNodes = function ( oSettings, sSearch, iColumn )
{
var
i,iLen, j, jLen, val,
aOut = [], aData,
columns = oSettings.aoColumns;
for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
{
aData = oSettings.aoData[i]._aData;
if ( iColumn === undefined )
{
for ( j=0, jLen=columns.length ; j<jLen ; j++ )
{
val = this.fnGetData(i, j);
if ( val == sSearch )
{
aOut.push( oSettings.aoData[i].nTr );
}
}
}
else if (this.fnGetData(i, iColumn) == sSearch )
{
aOut.push( oSettings.aoData[i].nTr );
}
}
return aOut;
};

View File

@@ -0,0 +1,55 @@
/**
* Due to the fact that DataTables moves DOM elements around (mainly `dt-tag tr`
* elements for sorting and filtering) it can at times be a little tricky to get
* the next row based on another, while taking into account pagination,
* filtering, sorting etc.
*
* This function is designed to address exactly this situation. It takes two
* parameters, the target node, and a boolean indicating if the adjacent row
* retrieved should be the next (`true`, or no value) or the previous (`false`).
*
* @name fnGetAdjacentTr
* @summary Get the adjacent `dt-tag tr` element for a row.
* @author [Allan Jardine](http://sprymedia.co.uk)
*
* @param {node} nTr `dt-tag tr` element to get the adjacent element of
* @param {boolean} [bNext=true] Get the next (`true`), or previous (`false`)
* `dt-tag tr` element.
* @returns {node} `dt-tag tr` element or null if not found.
*
* @example
* $(document).ready(function() {
* var table = $('#example').dataTable();
*
* var n1 = $('#example tbody tr').eq(2)[0];
* var next = table.fnGetAdjacentTr( n1 );
* var prev = table.fnGetAdjacentTr( n1, false );
* } );
*/
jQuery.fn.dataTableExt.oApi.fnGetAdjacentTr = function ( oSettings, nTr, bNext )
{
/* Find the node's position in the aoData store */
var iCurrent = oSettings.oApi._fnNodeToDataIndex( oSettings, nTr );
/* Convert that to a position in the display array */
var iDisplayIndex = $.inArray( iCurrent, oSettings.aiDisplay );
if ( iDisplayIndex == -1 )
{
/* Not in the current display */
return null;
}
/* Move along the display array as needed */
iDisplayIndex += (typeof bNext=='undefined' || bNext) ? 1 : -1;
/* Check that it within bounds */
if ( iDisplayIndex < 0 || iDisplayIndex >= 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;
};

View File

@@ -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<c; i++) {
var iRow = aiRows[i];
var sValue = this.fnGetData(iRow, iColumn);
// ignore empty values?
if (bIgnoreEmpty === true && sValue.length === 0) {
continue;
}
// ignore unique values?
else if (bUnique === true && jQuery.inArray(sValue, asResultData) > -1) {
continue;
}
// else push the value onto the result data array
else {
asResultData.push(sValue);
}
}
return asResultData;
};

View File

@@ -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<xLen ; x++ )
{
if ( cols[x].sTitle.toLowerCase() == sCol.toLowerCase() )
{
return x;
}
}
return -1;
};

View File

@@ -0,0 +1,43 @@
/**
* Get a list of all `dt-tag tr` nodes in the table which are not currently
* visible (useful for building forms).
*
* This function is marked as deprecated as using the `dt-api rows()` method in
* DataTables 1.10+ is preferred to this approach.
*
* @name fnGetHiddenNodes
* @summary Get the `dt-tag tr` elements which are not in the DOM
* @author [Allan Jardine](http://sprymedia.co.uk)
* @deprecated
*
* @example
* var table = $('#example').dataTable();
* var nodes = table.fnGetHiddenNodes();
*/
jQuery.fn.dataTableExt.oApi.fnGetHiddenNodes = function ( settings )
{
var nodes;
var display = jQuery('tbody tr', settings.nTable);
if ( jQuery.fn.dataTable.versionCheck ) {
// DataTables 1.10
var api = new jQuery.fn.dataTable.Api( settings );
nodes = api.rows().nodes().toArray();
}
else {
// 1.9-
nodes = this.oApi._fnGetTrNodes( settings );
}
/* Remove nodes which are being displayed */
for ( var i=0 ; i<display.length ; i++ ) {
var iIndex = jQuery.inArray( display[i], nodes );
if ( iIndex != -1 ) {
nodes.splice( iIndex, 1 );
}
}
return nodes;
};

View File

@@ -0,0 +1,59 @@
/**
* Get a `dt-tag td` node from a row, taking into account column visibility.
* While getting a `dt-tag td` node is easy when it is visible on the page by
* using normal DOM methods, jQuery or whatever, it becomes a lot more
* complicated when taking into account hidden rows and columns. This function
* can be used to overcome these difficulties.
*
* DataTables 1.10+'s new API provides the `dt-api cell()` and `dt-api cells()`
* methods which are preferable for use over this 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 fnGetTd
* @summary Get the `dt-tag td` element for a cell.
* @author [Allan Jardine](http://sprymedia.co.uk)
* @deprecated
*
* @param {node} mTr `dt-tag tr` element to get the `dt-tag td` of
* @param {integer} iTd Column index to get the node of
* @param {boolean} bVisOnly Consider visible columns only
* @returns {node} `dt-tag td` element in question
*
* @example
* $(document).ready(function() {
* var table = $('#example').dataTable();
*
* // Sort in the order that was origially in the HTML
* var nTd = table.fnGetTd( $('#example tbody tr:eq(1)')[0], 1 );
* console.log( nTd );
* } );
*/
jQuery.fn.dataTableExt.oApi.fnGetTd = function ( oSettings, mTr, iTd, bVisOnly )
{
/* Take either a TR node or aoData index as the mTr property */
var iRow = (typeof mTr == 'object') ?
oSettings.oApi._fnNodeToDataIndex(oSettings, mTr) : mTr;
if ( typeof bVisOnly == 'undefined' && !bVisOnly )
{
/* Looking at both visible and hidden TD elements - convert to visible index, if not present
* then it must be hidden. Return as appropriate
*/
var iCalcVis = oSettings.oApi._fnColumnIndexToVisible( oSettings, iTd );
if ( iCalcVis !== null )
{
return oSettings.aoData[ iRow ].nTr.getElementsByTagName('td')[ iCalcVis ];
}
else
{
return oSettings.aoData[ iRow ]._anHidden[ iTd ];
}
}
else
{
/* Only looking at visible TD elements, so just use getElements... */
return oSettings.aoData[ iRow ].nTr.getElementsByTagName('td')[ iTd ];
}
};

View File

@@ -0,0 +1,65 @@
/**
* Get an array of `dt-tag td` nodes from DataTables for a given row, including
* any column elements which are hidden.
*
* DataTables 1.10 has the `dt-api cells().nodes()` method, built-in, to provide
* this functionality. 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 fnGetTds
* @summary Get the `dt-tag td` elements for a row
* @author [Allan Jardine](http://sprymedia.co.uk)
* @deprecated
*
* @param {node} mTr `dt-tag tr` element to get the `dt-tag td` of
* @returns {array} Array of `dt-tag td` elements
*
* @example
* $(document).ready(function() {
* var oTable = $('#example').dataTable();
*
* // Sort in the order that was origially in the HTML
* var anTds = oTable.fnGetTds( $('#example tbody tr:eq(1)')[0] );
* console.log( anTds );
* } );
*/
jQuery.fn.dataTableExt.oApi.fnGetTds = function ( oSettings, mTr )
{
var anTds = [];
var anVisibleTds = [];
var iCorrector = 0;
var nTd, iColumn, iColumns;
/* Take either a TR node or aoData index as the mTr property */
var iRow = (typeof mTr == 'object') ?
oSettings.oApi._fnNodeToDataIndex(oSettings, mTr) : mTr;
var nTr = oSettings.aoData[iRow].nTr;
/* Get an array of the visible TD elements */
for ( iColumn=0, iColumns=nTr.childNodes.length ; iColumn<iColumns ; iColumn++ )
{
nTd = nTr.childNodes[iColumn];
if ( nTd.nodeName.toUpperCase() == "TD" )
{
anVisibleTds.push( nTd );
}
}
/* Construct and array of the combined elements */
for ( iColumn=0, iColumns=oSettings.aoColumns.length ; iColumn<iColumns ; iColumn++ )
{
if ( oSettings.aoColumns[iColumn].bVisible )
{
anTds.push( anVisibleTds[iColumn-iCorrector] );
}
else
{
anTds.push( oSettings.aoData[iRow]._anHidden[iColumn] );
iCorrector++;
}
}
return anTds;
};

View File

@@ -0,0 +1,48 @@
/**
* Change the number of records that can be viewed on a single page in
* DataTables.
*
* DataTables 1.10 provides the `dt-api page.len()` method to get and set the
* page length using the built-in API. 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 fnLengthChange
* @summary Change the paging display length
* @author [Pedro Alves](http://www.webdetails.pt/)
* @deprecated
*
* @example
* $(document).ready(function() {
* var table = $('#example').dataTable();
* table.fnLengthChange( 100 );
* } );
*/
jQuery.fn.dataTableExt.oApi.fnLengthChange = function ( oSettings, iDisplay )
{
oSettings._iDisplayLength = iDisplay;
oSettings.oApi._fnCalculateEnd( oSettings );
/* If we have space to show extra rows (backing up from the end point - then do so */
if ( oSettings._iDisplayEnd == oSettings.aiDisplay.length )
{
oSettings._iDisplayStart = oSettings._iDisplayEnd - oSettings._iDisplayLength;
if ( oSettings._iDisplayStart < 0 )
{
oSettings._iDisplayStart = 0;
}
}
if ( oSettings._iDisplayLength == -1 )
{
oSettings._iDisplayStart = 0;
}
oSettings.oApi._fnDraw( oSettings );
if ( oSettings.aanFeatures.l )
{
$('select', oSettings.aanFeatures.l).val( iDisplay );
}
};

View File

@@ -0,0 +1,63 @@
/**
* This plug-in adds to DataTables the ability to set multiple column filtering
* terms in a single call (particularly useful if using server-side processing).
* Used in combination with the column sName parameter, simply pass in an object
* with the key/value pair being the column you wish to search on, and the value
* you wish to search for.
*
* DataTables 1.10's API provides a easy built-in way to apply multiple filters
* to the table without redrawing until required. For example, the example below
* with the DataTables 1.10 API could be written as:
*
* ```js
* var table = $('#example').DataTable();
* table
* .column( 0 ).search( 'Gecko' )
* .column( 1 ).search( 'Cam' )
* .draw();
* ```
*
* 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 fnMultiFilter
* @summary Apply multiple column filters together
* @author _mrkevans_
* @deprecated
*
* @param {object} oData Data to search for
*
* @example
* $(document).ready(function() {
* var table = $('#example').dataTable( {
* "aoColumns": [
* { "sName": "engine" },
* { "sName": "browser" },
* { "sName": "platform" },
* { "sName": "version" },
* { "sName": "grade" }
* ]
* } );
* table.fnMultiFilter( { "engine": "Gecko", "browser": "Cam" } );
* } );
*/
jQuery.fn.dataTableExt.oApi.fnMultiFilter = function( oSettings, oData ) {
for ( var key in oData )
{
if ( oData.hasOwnProperty(key) )
{
for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
{
if( oSettings.aoColumns[i].sName == key )
{
/* Add single column filter */
oSettings.aoPreSearchCols[ i ].sSearch = oData[key];
break;
}
}
}
}
this.oApi._fnReDraw( oSettings );
};

View File

@@ -0,0 +1,39 @@
/**
* Get information about the paging settings that DataTables is currently
* using to display each page, including the number of records shown, start
* and end points in the data set etc.
*
* DataTables 1.10+ provides the `dt-api page.info()` method, built-in, provide
* the same information as this 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 fnPagingInfo
* @summary Get information about the paging state of the table
* @author [Allan Jardine](http://sprymedia.co.uk)
* @deprecated
*
* @example
* $(document).ready(function() {
* $('#example').dataTable( {
* "fnDrawCallback": function () {
* alert( 'Now on page'+ this.fnPagingInfo().iPage );
* }
* } );
* } );
*/
jQuery.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
{
return {
"iStart": oSettings._iDisplayStart,
"iEnd": oSettings.fnDisplayEnd(),
"iLength": oSettings._iDisplayLength,
"iTotal": oSettings.fnRecordsTotal(),
"iFilteredTotal": oSettings.fnRecordsDisplay(),
"iPage": oSettings._iDisplayLength === -1 ?
0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
"iTotalPages": oSettings._iDisplayLength === -1 ?
0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
};
};

View File

@@ -0,0 +1,26 @@
/**
* When doing some heavy processing of your own (for example using fnOpen with
* data loading from the server) it can be useful to make use of the
* 'processing' indicator built-into DataTables. This plug-in function exposes
* the internal DataTables function so it can be used for exactly this.
*
* @name fnProcessingIndicator
* @summary Show and hide the DataTables processing element through the API.
* @author Allan Chappell
*
* @param {boolean} [onoff=true] Show (`true`) or hide (`false`) the processing
* element.
*
* @example
* var table = $('#example').dataTable();
* table.fnProcessingIndicator(); // On
* table.fnProcessingIndicator(false); // Off
*/
jQuery.fn.dataTableExt.oApi.fnProcessingIndicator = function ( oSettings, onoff )
{
if ( onoff === undefined ) {
onoff = true;
}
this.oApi._fnProcessingDisplay( oSettings, onoff );
};

View File

@@ -0,0 +1,102 @@
/**
* By default DataTables only uses the sAjaxSource variable at initialisation
* time, however it can be useful to re-read an Ajax source and have the table
* update. Typically you would need to use the `fnClearTable()` and
* `fnAddData()` functions, however this wraps it all up in a single function
* call.
*
* DataTables 1.10 provides the `dt-api ajax.url()` and `dt-api ajax.reload()`
* methods, built-in, to give the same functionality as this plug-in. 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 fnReloadAjax
* @summary Reload the table's data from the Ajax source
* @author [Allan Jardine](http://sprymedia.co.uk)
* @deprecated
*
* @param {string} [sNewSource] URL to get the data from. If not give, the
* previously used URL is used.
* @param {function} [fnCallback] Callback that is executed when the table has
* redrawn with the new data
* @param {boolean} [bStandingRedraw=false] Standing redraw (don't changing the
* paging)
*
* @example
* var table = $('#example').dataTable();
*
* // Example call to load a new file
* table.fnReloadAjax( 'media/examples_support/json_source2.txt' );
*
* // Example call to reload from original file
* table.fnReloadAjax();
*/
jQuery.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback, bStandingRedraw )
{
// DataTables 1.10 compatibility - if 1.10 then `versionCheck` exists.
// 1.10's API has ajax reloading built in, so we use those abilities
// directly.
if ( jQuery.fn.dataTable.versionCheck ) {
var api = new jQuery.fn.dataTable.Api( oSettings );
if ( sNewSource ) {
api.ajax.url( sNewSource ).load( fnCallback, !bStandingRedraw );
}
else {
api.ajax.reload( fnCallback, !bStandingRedraw );
}
return;
}
if ( sNewSource !== undefined && sNewSource !== null ) {
oSettings.sAjaxSource = sNewSource;
}
// Server-side processing should just call fnDraw
if ( oSettings.oFeatures.bServerSide ) {
this.fnDraw();
return;
}
this.oApi._fnProcessingDisplay( oSettings, true );
var that = this;
var iStart = oSettings._iDisplayStart;
var aData = [];
this.oApi._fnServerParams( oSettings, aData );
oSettings.fnServerData.call( oSettings.oInstance, oSettings.sAjaxSource, aData, function(json) {
/* Clear the old information from the table */
that.oApi._fnClearTable( oSettings );
/* Got the data - add it to the table */
var aData = (oSettings.sAjaxDataProp !== "") ?
that.oApi._fnGetObjectDataFn( oSettings.sAjaxDataProp )( json ) : json;
for ( var i=0 ; i<aData.length ; i++ )
{
that.oApi._fnAddData( oSettings, aData[i] );
}
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
that.fnDraw();
if ( bStandingRedraw === true )
{
oSettings._iDisplayStart = iStart;
that.oApi._fnCalculateEnd( oSettings );
that.fnDraw( false );
}
that.oApi._fnProcessingDisplay( oSettings, false );
/* Callback user function - for event handlers etc */
if ( typeof fnCallback == 'function' && fnCallback !== null )
{
fnCallback( oSettings );
}
}, oSettings );
};

View File

@@ -0,0 +1,51 @@
/**
* Enables filtration delay for keeping the browser more responsive while
* searching for a longer keyword.
*
* This can be particularly useful when working with server-side processing,
* where you wouldn't typically want an Ajax request to be made with every key
* press the user makes when searching the table.
*
* @name fnSetFilteringDelay
* @summary Add a key debouce delay to the global filtering input of a table
* @author [Zygimantas Berziunas](http://www.zygimantas.com/),
* [Allan Jardine](http://www.sprymedia.co.uk/) and _vex_
*
* @example
* $(document).ready(function() {
* $('.dataTable').dataTable().fnSetFilteringDelay();
* } );
*/
jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
var _that = this;
if ( iDelay === undefined ) {
iDelay = 250;
}
this.each( function ( i ) {
$.fn.dataTableExt.iApiIndex = i;
var
$this = this,
oTimerId = null,
sPreviousSearch = null,
anControl = $( 'input', _that.fnSettings().aanFeatures.f );
anControl.unbind( 'keyup search input' ).bind( 'keyup search input', function() {
var $$this = $this;
if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
window.clearTimeout(oTimerId);
sPreviousSearch = anControl.val();
oTimerId = window.setTimeout(function() {
$.fn.dataTableExt.iApiIndex = i;
_that.fnFilter( anControl.val() );
}, iDelay);
}
});
return this;
} );
return this;
};

View File

@@ -0,0 +1,36 @@
/**
* This function will restore the order in which data was read into a DataTable
* (for example from an HTML source). Although you can set aaSorting to be an
* empty array (`[ ]`) in order to prevent sorting during initialisation, it can
* sometimes be useful to restore the original order after sorting has already
* occurred - which is exactly what this function does.
*
* @name fnSortNeutral
* @summary Change ordering of the table to its data load order
* @author [Allan Jardine](http://sprymedia.co.uk)
*
* @example
* $(document).ready(function() {
* var table = $('#example').dataTable();
*
* // Sort in the order that was originally in the HTML
* table.fnSortNeutral();
* } );
*/
jQuery.fn.dataTableExt.oApi.fnSortNeutral = function ( oSettings )
{
/* Remove any current sorting */
oSettings.aaSorting = [];
/* Sort display arrays so we get them in numerical order */
oSettings.aiDisplay.sort( function (x,y) {
return x-y;
} );
oSettings.aiDisplayMaster.sort( function (x,y) {
return x-y;
} );
/* Redraw */
oSettings.oApi._fnReDraw( oSettings );
};

View File

@@ -0,0 +1,35 @@
/**
* Redraw the table (i.e. `fnDraw`) to take account of sorting and filtering,
* but retain the current pagination settings.
*
* DataTables 1.10+ provide the `dt-api draw()` method which has this ability
* built-in (pass the first parameter to the function as `false`). 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 fnStandingRedraw
* @summary Redraw the table without altering the paging
* @author Jonathan Hoguet
* @deprecated
*
* @example
* $(document).ready(function() {
* var table = $('.dataTable').dataTable()
* table.fnStandingRedraw();
* } );
*/
jQuery.fn.dataTableExt.oApi.fnStandingRedraw = function(oSettings) {
if(oSettings.oFeatures.bServerSide === false){
var before = oSettings._iDisplayStart;
oSettings.oApi._fnReDraw(oSettings);
// iDisplayStart has been reset to zero - so lets change it back
oSettings._iDisplayStart = before;
oSettings.oApi._fnCalculateEnd(oSettings);
}
// draw the 'current' page
oSettings.oApi._fnDraw(oSettings);
};

View File

@@ -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 visible column index into a data
* column index (i.e. all columns regardless of visibility).
*
* 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 fnVisibleToColumnIndex
* @summary Convert a column visible index to a data index.
* @author [Allan Jardine](http://sprymedia.co.uk)
* @deprecated
*
* @param {integer} iMatch Column data index to convert to data index
* @returns {integer} Visible column index
*
* @example
* var table = $('#example').dataTable( {
* aoColumnDefs: [
* { bVisible: false, aTargets: [1] }
* ]
* } );
*
* // This will show 2
* alert( 'Visible Column 1 data index: '+table.fnVisibleToColumnIndex(1) );
*/
jQuery.fn.dataTableExt.oApi.fnVisibleToColumnIndex = function ( oSettings, iMatch )
{
return oSettings.oApi._fnVisibleToColumnIndex( oSettings, iMatch );
};

View File

@@ -0,0 +1,36 @@
<h2>Custom API functions</h2>
<p>One of the most common interactions with DataTables for a developer (other than initialisation of the table of course!) is to make use of the <a href="/api">API functions</a> provided by DataTables. While allowing for a fairly extensive range of code interactions, the default API set can be greatly enhanced by making use of the functions provided below, as suitable for your application.</p>
<ul>
<li><a href="#how_to">How to use DataTables plug-in API functions</a></li>
<li><a href="#functions">Plug-in API functions</a></li>
</ul>
<a name="how_to"></a>
<h3>How to use DataTables plug-in API functions</h3>
<p>To make use of one of the plug-in API functions below, you simply need to include it in the Javascript available for your page, after you load the DataTables library, but before you initialise the DataTable. After that, you will be able to initialise the table, and call the function on the resulting object. As an example the code below makes use of <a href="#fnGetHiddenNodes">fnGetHiddenNodes</a> saved into a file (<a href="/examples/plug-ins/plugin_api.html">live example</a>):</p>
<pre class="brush: html">&lt;script type="text/javascript" src="jquery.dataTables.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="dataTables.fnGetHiddenNodes.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
$(document).ready(function() {
var oTable = $('#example').dataTable();
$('#button').click( function () {
var nHidden = oTable.fnGetHiddenNodes();
alert( nHidden.length +' nodes were returned' );
} );
} );
&lt;/script&gt;
</pre>
<p>Please note that DataTables will automatically pass the settings object as the first parameter. As such, you do not need to pass the settings object, which you will see if you look at the plug-in API's code.</p>
<a name="functions"></a>
<h3>Plug-in API functions</h3>
include(`build.1.inc')

View File

@@ -0,0 +1,38 @@
/**
* It can be quite useful to jump straight to a page which contains a certain
* piece of data (a user name for example). This plug-in provides exactly that
* ability, searching for a given data parameter from a given column and
* immediately shifting the paging of the table to jump to that point.
*
* If multiple data points match the requested data, the paging will be shifted
* to show the first instance. If there are no matches, the paging will not
* change.
*
* Note that unlike the core DataTables API methods, this plug-in will
* automatically call `dt-api draw()` to redraw the table with the current page
* shown.
*
* @name page.JumpToData()
* @summary Jump to a page by searching for data from a column
* @author [Allan Jardine](http://sprymedia.co.uk)
* @requires DataTables 1.10+
*
* @param {*} data Data to search for
* @param {integer} column Column index
* @returns {Api} DataTables API instance
*
* @example
* var table = $('#example').DataTable();
* table.page.jumpToData( "Allan Jardine", 0 );
*/
jQuery.fn.dataTable.Api.register( 'page.jumpToData()', function ( data, column ) {
var pos = this.column(column, {order:'current'}).data().indexOf( data );
if ( pos >= 0 ) {
var page = Math.floor( pos / this.page.info().length );
this.page( page ).draw( false );
}
return this;
} );

View File

@@ -0,0 +1,36 @@
/**
* Fairly simply, this plug-in will take the data from an API result set
* and sum it, returning the summed value. The data can come from any data
* source, including column data, cells or rows.
*
* @name sum()
* @summary Sum the values in a data set.
* @author [Allan Jardine](http://sprymedia.co.uk)
* @requires DataTables 1.10+
*
* @returns {Number} Summed value
*
* @example
* // Simply get the sum of a column
* var table = $('#example').DataTable();
* table.column( 3 ).data().sum();
*
* @example
* // Insert the sum of a column into the columns footer, for the visible
* // data on each draw
* $('#example').DataTable( {
* drawCallback: function () {
* var api = this.api();
* api.table().footer().to$().html(
* api.column( 4, {page:'current'} ).data().sum()
* );
* }
* } );
*/
jQuery.fn.dataTable.Api.register( 'sum()', function () {
return this.flatten().reduce( function ( a, b ) {
return (a*1) + (b*1); // cast values in-case they are strings
} );
} );