3 * @description Paginate, search and sort HTML tables
5 * @file jquery.dataTables.js
6 * @author Allan Jardine (www.sprymedia.co.uk)
7 * @contact www.sprymedia.co.uk/contact
9 * @copyright Copyright 2008-2012 Allan Jardine, all rights reserved.
11 * This source file is free software, under either the GPL v2 license or a
12 * BSD style license, available at:
13 * http://datatables.net/license_gpl2
14 * http://datatables.net/license_bsd
16 * This source file is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
20 * For details please refer to: http://www.datatables.net
23 /*jslint evil: true, undef: true, browser: true */
24 /*globals $, jQuery,define,_fnExternApiFunc,_fnInitialise,_fnInitComplete,_fnLanguageCompat,_fnAddColumn,_fnColumnOptions,_fnAddData,_fnCreateTr,_fnGatherData,_fnBuildHead,_fnDrawHead,_fnDraw,_fnReDraw,_fnAjaxUpdate,_fnAjaxParameters,_fnAjaxUpdateDraw,_fnServerParams,_fnAddOptionsHtml,_fnFeatureHtmlTable,_fnScrollDraw,_fnAdjustColumnSizing,_fnFeatureHtmlFilter,_fnFilterComplete,_fnFilterCustom,_fnFilterColumn,_fnFilter,_fnBuildSearchArray,_fnBuildSearchRow,_fnFilterCreateSearch,_fnDataToSearch,_fnSort,_fnSortAttachListener,_fnSortingClasses,_fnFeatureHtmlPaginate,_fnPageChange,_fnFeatureHtmlInfo,_fnUpdateInfo,_fnFeatureHtmlLength,_fnFeatureHtmlProcessing,_fnProcessingDisplay,_fnVisibleToColumnIndex,_fnColumnIndexToVisible,_fnNodeToDataIndex,_fnVisbleColumns,_fnCalculateEnd,_fnConvertToWidth,_fnCalculateColumnWidths,_fnScrollingWidthAdjust,_fnGetWidestNode,_fnGetMaxLenString,_fnStringToCss,_fnDetectType,_fnSettingsFromNode,_fnGetDataMaster,_fnGetTrNodes,_fnGetTdNodes,_fnEscapeRegex,_fnDeleteIndex,_fnReOrderIndex,_fnColumnOrdering,_fnLog,_fnClearTable,_fnSaveState,_fnLoadState,_fnCreateCookie,_fnReadCookie,_fnDetectHeader,_fnGetUniqueThs,_fnScrollBarWidth,_fnApplyToChildren,_fnMap,_fnGetRowData,_fnGetCellData,_fnSetCellData,_fnGetObjectDataFn,_fnSetObjectDataFn,_fnApplyColumnDefs,_fnBindAction,_fnCallbackReg,_fnCallbackFire,_fnJsonString,_fnRender,_fnNodeToColumnIndex,_fnInfoMacros,_fnBrowserDetect,_fnGetColumns*/
26 (/** @lends <global> */function( window, document, undefined ) {
28 (function( factory ) {
31 // Define as an AMD module if possible
32 if ( typeof define === 'function' && define.amd )
34 define( ['jquery'], factory );
36 /* Define using browser globals otherwise
37 * Prevent multiple instantiations if the script is loaded twice
39 else if ( jQuery && !jQuery.fn.dataTable )
44 (/** @lends <global> */function( $ ) {
47 * DataTables is a plug-in for the jQuery Javascript library. It is a
48 * highly flexible tool, based upon the foundations of progressive
49 * enhancement, which will add advanced interaction controls to any
50 * HTML table. For a full list of features please refer to
51 * <a href="http://datatables.net">DataTables.net</a>.
53 * Note that the <i>DataTable</i> object is not a global variable but is
54 * aliased to <i>jQuery.fn.DataTable</i> and <i>jQuery.fn.dataTable</i> through which
58 * @param {object} [oInit={}] Configuration object for DataTables. Options
59 * are defined by {@link DataTable.defaults}
60 * @requires jQuery 1.3+
63 * // Basic initialisation
64 * $(document).ready( function {
65 * $('#example').dataTable();
69 * // Initialisation with configuration options - in this case, disable
70 * // pagination and sorting.
71 * $(document).ready( function {
72 * $('#example').dataTable( {
78 var DataTable = function( oInit )
83 * Add a column to the list used for the table with default values
84 * @param {object} oSettings dataTables settings object
85 * @param {node} nTh The th element for this column
86 * @memberof DataTable#oApi
88 function _fnAddColumn( oSettings, nTh )
90 var oDefaults = DataTable.defaults.columns;
91 var iCol = oSettings.aoColumns.length;
92 var oCol = $.extend( {}, DataTable.models.oColumn, oDefaults, {
93 "sSortingClass": oSettings.oClasses.sSortable,
94 "sSortingClassJUI": oSettings.oClasses.sSortJUI,
95 "nTh": nTh ? nTh : document.createElement('th'),
96 "sTitle": oDefaults.sTitle ? oDefaults.sTitle : nTh ? nTh.innerHTML : '',
97 "aDataSort": oDefaults.aDataSort ? oDefaults.aDataSort : [iCol],
98 "mData": oDefaults.mData ? oDefaults.oDefaults : iCol
100 oSettings.aoColumns.push( oCol );
102 /* Add a column specific filter */
103 if ( oSettings.aoPreSearchCols[ iCol ] === undefined || oSettings.aoPreSearchCols[ iCol ] === null )
105 oSettings.aoPreSearchCols[ iCol ] = $.extend( {}, DataTable.models.oSearch );
109 var oPre = oSettings.aoPreSearchCols[ iCol ];
111 /* Don't require that the user must specify bRegex, bSmart or bCaseInsensitive */
112 if ( oPre.bRegex === undefined )
117 if ( oPre.bSmart === undefined )
122 if ( oPre.bCaseInsensitive === undefined )
124 oPre.bCaseInsensitive = true;
128 /* Use the column options function to initialise classes etc */
129 _fnColumnOptions( oSettings, iCol, null );
134 * Apply options for a column
135 * @param {object} oSettings dataTables settings object
136 * @param {int} iCol column index to consider
137 * @param {object} oOptions object with sType, bVisible and bSearchable etc
138 * @memberof DataTable#oApi
140 function _fnColumnOptions( oSettings, iCol, oOptions )
142 var oCol = oSettings.aoColumns[ iCol ];
144 /* User specified column options */
145 if ( oOptions !== undefined && oOptions !== null )
147 /* Backwards compatibility for mDataProp */
148 if ( oOptions.mDataProp && !oOptions.mData )
150 oOptions.mData = oOptions.mDataProp;
153 if ( oOptions.sType !== undefined )
155 oCol.sType = oOptions.sType;
156 oCol._bAutoType = false;
159 $.extend( oCol, oOptions );
160 _fnMap( oCol, oOptions, "sWidth", "sWidthOrig" );
162 /* iDataSort to be applied (backwards compatibility), but aDataSort will take
163 * priority if defined
165 if ( oOptions.iDataSort !== undefined )
167 oCol.aDataSort = [ oOptions.iDataSort ];
169 _fnMap( oCol, oOptions, "aDataSort" );
172 /* Cache the data get and set functions for speed */
173 var mRender = oCol.mRender ? _fnGetObjectDataFn( oCol.mRender ) : null;
174 var mData = _fnGetObjectDataFn( oCol.mData );
176 oCol.fnGetData = function (oData, sSpecific) {
177 var innerData = mData( oData, sSpecific );
179 if ( oCol.mRender && (sSpecific && sSpecific !== '') )
181 return mRender( innerData, sSpecific, oData );
185 oCol.fnSetData = _fnSetObjectDataFn( oCol.mData );
187 /* Feature sorting overrides column specific when off */
188 if ( !oSettings.oFeatures.bSort )
190 oCol.bSortable = false;
193 /* Check that the class assignment is correct for sorting */
194 if ( !oCol.bSortable ||
195 ($.inArray('asc', oCol.asSorting) == -1 && $.inArray('desc', oCol.asSorting) == -1) )
197 oCol.sSortingClass = oSettings.oClasses.sSortableNone;
198 oCol.sSortingClassJUI = "";
200 else if ( $.inArray('asc', oCol.asSorting) == -1 && $.inArray('desc', oCol.asSorting) == -1 )
202 oCol.sSortingClass = oSettings.oClasses.sSortable;
203 oCol.sSortingClassJUI = oSettings.oClasses.sSortJUI;
205 else if ( $.inArray('asc', oCol.asSorting) != -1 && $.inArray('desc', oCol.asSorting) == -1 )
207 oCol.sSortingClass = oSettings.oClasses.sSortableAsc;
208 oCol.sSortingClassJUI = oSettings.oClasses.sSortJUIAscAllowed;
210 else if ( $.inArray('asc', oCol.asSorting) == -1 && $.inArray('desc', oCol.asSorting) != -1 )
212 oCol.sSortingClass = oSettings.oClasses.sSortableDesc;
213 oCol.sSortingClassJUI = oSettings.oClasses.sSortJUIDescAllowed;
219 * Adjust the table column widths for new data. Note: you would probably want to
220 * do a redraw after calling this function!
221 * @param {object} oSettings dataTables settings object
222 * @memberof DataTable#oApi
224 function _fnAdjustColumnSizing ( oSettings )
226 /* Not interested in doing column width calculation if auto-width is disabled */
227 if ( oSettings.oFeatures.bAutoWidth === false )
232 _fnCalculateColumnWidths( oSettings );
233 for ( var i=0 , iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
235 oSettings.aoColumns[i].nTh.style.width = oSettings.aoColumns[i].sWidth;
241 * Covert the index of a visible column to the index in the data array (take account
243 * @param {object} oSettings dataTables settings object
244 * @param {int} iMatch Visible column index to lookup
245 * @returns {int} i the data index
246 * @memberof DataTable#oApi
248 function _fnVisibleToColumnIndex( oSettings, iMatch )
250 var aiVis = _fnGetColumns( oSettings, 'bVisible' );
252 return typeof aiVis[iMatch] === 'number' ?
259 * Covert the index of an index in the data array and convert it to the visible
260 * column index (take account of hidden columns)
261 * @param {int} iMatch Column index to lookup
262 * @param {object} oSettings dataTables settings object
263 * @returns {int} i the data index
264 * @memberof DataTable#oApi
266 function _fnColumnIndexToVisible( oSettings, iMatch )
268 var aiVis = _fnGetColumns( oSettings, 'bVisible' );
269 var iPos = $.inArray( iMatch, aiVis );
271 return iPos !== -1 ? iPos : null;
276 * Get the number of visible columns
277 * @param {object} oSettings dataTables settings object
278 * @returns {int} i the number of visible columns
279 * @memberof DataTable#oApi
281 function _fnVisbleColumns( oSettings )
283 return _fnGetColumns( oSettings, 'bVisible' ).length;
288 * Get an array of column indexes that match a given property
289 * @param {object} oSettings dataTables settings object
290 * @param {string} sParam Parameter in aoColumns to look for - typically
291 * bVisible or bSearchable
292 * @returns {array} Array of indexes with matched properties
293 * @memberof DataTable#oApi
295 function _fnGetColumns( oSettings, sParam )
299 $.map( oSettings.aoColumns, function(val, i) {
310 * Get the sort type based on an input string
311 * @param {string} sData data we wish to know the type of
312 * @returns {string} type (defaults to 'string' if no type can be detected)
313 * @memberof DataTable#oApi
315 function _fnDetectType( sData )
317 var aTypes = DataTable.ext.aTypes;
318 var iLen = aTypes.length;
320 for ( var i=0 ; i<iLen ; i++ )
322 var sType = aTypes[i]( sData );
323 if ( sType !== null )
334 * Figure out how to reorder a display list
335 * @param {object} oSettings dataTables settings object
336 * @returns array {int} aiReturn index list for reordering
337 * @memberof DataTable#oApi
339 function _fnReOrderIndex ( oSettings, sColumns )
341 var aColumns = sColumns.split(',');
344 for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
346 for ( var j=0 ; j<iLen ; j++ )
348 if ( oSettings.aoColumns[i].sName == aColumns[j] )
361 * Get the column ordering that DataTables expects
362 * @param {object} oSettings dataTables settings object
363 * @returns {string} comma separated list of names
364 * @memberof DataTable#oApi
366 function _fnColumnOrdering ( oSettings )
369 for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
371 sNames += oSettings.aoColumns[i].sName+',';
373 if ( sNames.length == iLen )
377 return sNames.slice(0, -1);
382 * Take the column definitions and static columns arrays and calculate how
383 * they relate to column indexes. The callback function will then apply the
384 * definition found for a column to a suitable configuration object.
385 * @param {object} oSettings dataTables settings object
386 * @param {array} aoColDefs The aoColumnDefs array that is to be applied
387 * @param {array} aoCols The aoColumns array that defines columns individually
388 * @param {function} fn Callback function - takes two parameters, the calculated
389 * column index and the definition for that column.
390 * @memberof DataTable#oApi
392 function _fnApplyColumnDefs( oSettings, aoColDefs, aoCols, fn )
394 var i, iLen, j, jLen, k, kLen;
396 // Column definitions with aTargets
399 /* Loop over the definitions array - loop in reverse so first instance has priority */
400 for ( i=aoColDefs.length-1 ; i>=0 ; i-- )
402 /* Each definition can target multiple columns, as it is an array */
403 var aTargets = aoColDefs[i].aTargets;
404 if ( !$.isArray( aTargets ) )
406 _fnLog( oSettings, 1, 'aTargets must be an array of targets, not a '+(typeof aTargets) );
409 for ( j=0, jLen=aTargets.length ; j<jLen ; j++ )
411 if ( typeof aTargets[j] === 'number' && aTargets[j] >= 0 )
413 /* Add columns that we don't yet know about */
414 while( oSettings.aoColumns.length <= aTargets[j] )
416 _fnAddColumn( oSettings );
419 /* Integer, basic index */
420 fn( aTargets[j], aoColDefs[i] );
422 else if ( typeof aTargets[j] === 'number' && aTargets[j] < 0 )
424 /* Negative integer, right to left column counting */
425 fn( oSettings.aoColumns.length+aTargets[j], aoColDefs[i] );
427 else if ( typeof aTargets[j] === 'string' )
429 /* Class name matching on TH element */
430 for ( k=0, kLen=oSettings.aoColumns.length ; k<kLen ; k++ )
432 if ( aTargets[j] == "_all" ||
433 $(oSettings.aoColumns[k].nTh).hasClass( aTargets[j] ) )
435 fn( k, aoColDefs[i] );
443 // Statically defined columns array
446 for ( i=0, iLen=aoCols.length ; i<iLen ; i++ )
454 * Add a data array to the table, creating DOM node etc. This is the parallel to
455 * _fnGatherData, but for adding rows from a Javascript source, rather than a
457 * @param {object} oSettings dataTables settings object
458 * @param {array} aData data array to be added
459 * @returns {int} >=0 if successful (index of new aoData entry), -1 if failed
460 * @memberof DataTable#oApi
462 function _fnAddData ( oSettings, aDataSupplied )
466 /* Take an independent copy of the data source so we can bash it about as we wish */
467 var aDataIn = ($.isArray(aDataSupplied)) ?
468 aDataSupplied.slice() :
469 $.extend( true, {}, aDataSupplied );
471 /* Create the object for storing information about this new row */
472 var iRow = oSettings.aoData.length;
473 var oData = $.extend( true, {}, DataTable.models.oRow );
474 oData._aData = aDataIn;
475 oSettings.aoData.push( oData );
477 /* Create the cells */
479 for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
481 oCol = oSettings.aoColumns[i];
483 /* Use rendered data for filtering / sorting */
484 if ( typeof oCol.fnRender === 'function' && oCol.bUseRendered && oCol.mData !== null )
486 _fnSetCellData( oSettings, iRow, i, _fnRender(oSettings, iRow, i) );
490 _fnSetCellData( oSettings, iRow, i, _fnGetCellData( oSettings, iRow, i ) );
493 /* See if we should auto-detect the column type */
494 if ( oCol._bAutoType && oCol.sType != 'string' )
496 /* Attempt to auto detect the type - same as _fnGatherData() */
497 var sVarType = _fnGetCellData( oSettings, iRow, i, 'type' );
498 if ( sVarType !== null && sVarType !== '' )
500 sThisType = _fnDetectType( sVarType );
501 if ( oCol.sType === null )
503 oCol.sType = sThisType;
505 else if ( oCol.sType != sThisType && oCol.sType != "html" )
507 /* String is always the 'fallback' option */
508 oCol.sType = 'string';
514 /* Add to the display array */
515 oSettings.aiDisplayMaster.push( iRow );
517 /* Create the DOM information */
518 if ( !oSettings.oFeatures.bDeferRender )
520 _fnCreateTr( oSettings, iRow );
528 * Read in the data from the target table from the DOM
529 * @param {object} oSettings dataTables settings object
530 * @memberof DataTable#oApi
532 function _fnGatherData( oSettings )
534 var iLoop, i, iLen, j, jLen, jInner,
535 nTds, nTrs, nTd, nTr, aLocalData, iThisIndex,
536 iRow, iRows, iColumn, iColumns, sNodeName,
540 * Process by row first
541 * Add the data object for the whole table - storing the tr node. Note - no point in getting
542 * DOM based data if we are going to go and replace it with Ajax source data.
544 if ( oSettings.bDeferLoading || oSettings.sAjaxSource === null )
546 nTr = oSettings.nTBody.firstChild;
549 if ( nTr.nodeName.toUpperCase() == "TR" )
551 iThisIndex = oSettings.aoData.length;
552 nTr._DT_RowIndex = iThisIndex;
553 oSettings.aoData.push( $.extend( true, {}, DataTable.models.oRow, {
557 oSettings.aiDisplayMaster.push( iThisIndex );
558 nTd = nTr.firstChild;
562 sNodeName = nTd.nodeName.toUpperCase();
563 if ( sNodeName == "TD" || sNodeName == "TH" )
565 _fnSetCellData( oSettings, iThisIndex, jInner, $.trim(nTd.innerHTML) );
568 nTd = nTd.nextSibling;
571 nTr = nTr.nextSibling;
575 /* Gather in the TD elements of the Table - note that this is basically the same as
576 * fnGetTdNodes, but that function takes account of hidden columns, which we haven't yet
579 nTrs = _fnGetTrNodes( oSettings );
581 for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
583 nTd = nTrs[i].firstChild;
586 sNodeName = nTd.nodeName.toUpperCase();
587 if ( sNodeName == "TD" || sNodeName == "TH" )
591 nTd = nTd.nextSibling;
595 /* Now process by column */
596 for ( iColumn=0, iColumns=oSettings.aoColumns.length ; iColumn<iColumns ; iColumn++ )
598 oCol = oSettings.aoColumns[iColumn];
600 /* Get the title of the column - unless there is a user set one */
601 if ( oCol.sTitle === null )
603 oCol.sTitle = oCol.nTh.innerHTML;
607 bAutoType = oCol._bAutoType,
608 bRender = typeof oCol.fnRender === 'function',
609 bClass = oCol.sClass !== null,
610 bVisible = oCol.bVisible,
611 nCell, sThisType, sRendered, sValType;
613 /* A single loop to rule them all (and be more efficient) */
614 if ( bAutoType || bRender || bClass || !bVisible )
616 for ( iRow=0, iRows=oSettings.aoData.length ; iRow<iRows ; iRow++ )
618 oData = oSettings.aoData[iRow];
619 nCell = nTds[ (iRow*iColumns) + iColumn ];
622 if ( bAutoType && oCol.sType != 'string' )
624 sValType = _fnGetCellData( oSettings, iRow, iColumn, 'type' );
625 if ( sValType !== '' )
627 sThisType = _fnDetectType( sValType );
628 if ( oCol.sType === null )
630 oCol.sType = sThisType;
632 else if ( oCol.sType != sThisType &&
633 oCol.sType != "html" )
635 /* String is always the 'fallback' option */
636 oCol.sType = 'string';
643 // mRender has been defined, so we need to get the value and set it
644 nCell.innerHTML = _fnGetCellData( oSettings, iRow, iColumn, 'display' );
646 else if ( oCol.mData !== iColumn )
648 // If mData is not the same as the column number, then we need to
649 // get the dev set value. If it is the column, no point in wasting
650 // time setting the value that is already there!
651 nCell.innerHTML = _fnGetCellData( oSettings, iRow, iColumn, 'display' );
657 sRendered = _fnRender( oSettings, iRow, iColumn );
658 nCell.innerHTML = sRendered;
659 if ( oCol.bUseRendered )
661 /* Use the rendered data for filtering / sorting */
662 _fnSetCellData( oSettings, iRow, iColumn, sRendered );
669 nCell.className += ' '+oCol.sClass;
672 /* Column visibility */
675 oData._anHidden[iColumn] = nCell;
676 nCell.parentNode.removeChild( nCell );
680 oData._anHidden[iColumn] = null;
683 if ( oCol.fnCreatedCell )
685 oCol.fnCreatedCell.call( oSettings.oInstance,
686 nCell, _fnGetCellData( oSettings, iRow, iColumn, 'display' ), oData._aData, iRow, iColumn
693 /* Row created callbacks */
694 if ( oSettings.aoRowCreatedCallback.length !== 0 )
696 for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
698 oData = oSettings.aoData[i];
699 _fnCallbackFire( oSettings, 'aoRowCreatedCallback', null, [oData.nTr, oData._aData, i] );
706 * Take a TR element and convert it to an index in aoData
707 * @param {object} oSettings dataTables settings object
708 * @param {node} n the TR element to find
709 * @returns {int} index if the node is found, null if not
710 * @memberof DataTable#oApi
712 function _fnNodeToDataIndex( oSettings, n )
714 return (n._DT_RowIndex!==undefined) ? n._DT_RowIndex : null;
719 * Take a TD element and convert it into a column data index (not the visible index)
720 * @param {object} oSettings dataTables settings object
721 * @param {int} iRow The row number the TD/TH can be found in
722 * @param {node} n The TD/TH element to find
723 * @returns {int} index if the node is found, -1 if not
724 * @memberof DataTable#oApi
726 function _fnNodeToColumnIndex( oSettings, iRow, n )
728 var anCells = _fnGetTdNodes( oSettings, iRow );
730 for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
732 if ( anCells[i] === n )
742 * Get an array of data for a given row from the internal data cache
743 * @param {object} oSettings dataTables settings object
744 * @param {int} iRow aoData row id
745 * @param {string} sSpecific data get type ('type' 'filter' 'sort')
746 * @param {array} aiColumns Array of column indexes to get data from
747 * @returns {array} Data array
748 * @memberof DataTable#oApi
750 function _fnGetRowData( oSettings, iRow, sSpecific, aiColumns )
753 for ( var i=0, iLen=aiColumns.length ; i<iLen ; i++ )
755 out.push( _fnGetCellData( oSettings, iRow, aiColumns[i], sSpecific ) );
762 * Get the data for a given cell from the internal cache, taking into account data mapping
763 * @param {object} oSettings dataTables settings object
764 * @param {int} iRow aoData row id
765 * @param {int} iCol Column index
766 * @param {string} sSpecific data get type ('display', 'type' 'filter' 'sort')
767 * @returns {*} Cell data
768 * @memberof DataTable#oApi
770 function _fnGetCellData( oSettings, iRow, iCol, sSpecific )
773 var oCol = oSettings.aoColumns[iCol];
774 var oData = oSettings.aoData[iRow]._aData;
776 if ( (sData=oCol.fnGetData( oData, sSpecific )) === undefined )
778 if ( oSettings.iDrawError != oSettings.iDraw && oCol.sDefaultContent === null )
780 _fnLog( oSettings, 0, "Requested unknown parameter "+
781 (typeof oCol.mData=='function' ? '{mData function}' : "'"+oCol.mData+"'")+
782 " from the data source for row "+iRow );
783 oSettings.iDrawError = oSettings.iDraw;
785 return oCol.sDefaultContent;
788 /* When the data source is null, we can use default column data */
789 if ( sData === null && oCol.sDefaultContent !== null )
791 sData = oCol.sDefaultContent;
793 else if ( typeof sData === 'function' )
795 /* If the data source is a function, then we run it and use the return */
799 if ( sSpecific == 'display' && sData === null )
808 * Set the value for a specific cell, into the internal data cache
809 * @param {object} oSettings dataTables settings object
810 * @param {int} iRow aoData row id
811 * @param {int} iCol Column index
812 * @param {*} val Value to set
813 * @memberof DataTable#oApi
815 function _fnSetCellData( oSettings, iRow, iCol, val )
817 var oCol = oSettings.aoColumns[iCol];
818 var oData = oSettings.aoData[iRow]._aData;
820 oCol.fnSetData( oData, val );
824 // Private variable that is used to match array syntax in the data property object
825 var __reArray = /\[.*?\]$/;
828 * Return a function that can be used to get data from a source object, taking
829 * into account the ability to use nested objects as a source
830 * @param {string|int|function} mSource The data source for the object
831 * @returns {function} Data get function
832 * @memberof DataTable#oApi
834 function _fnGetObjectDataFn( mSource )
836 if ( mSource === null )
838 /* Give an empty string for rendering / sorting etc */
839 return function (data, type) {
843 else if ( typeof mSource === 'function' )
845 return function (data, type, extra) {
846 return mSource( data, type, extra );
849 else if ( typeof mSource === 'string' && (mSource.indexOf('.') !== -1 || mSource.indexOf('[') !== -1) )
851 /* If there is a . in the source string then the data source is in a
852 * nested object so we loop over the data for each level to get the next
853 * level down. On each loop we test for undefined, and if found immediately
854 * return. This allows entire objects to be missing and sDefaultContent to
855 * be used if defined, rather than throwing an error
857 var fetchData = function (data, type, src) {
858 var a = src.split('.');
859 var arrayNotation, out, innerSrc;
863 for ( var i=0, iLen=a.length ; i<iLen ; i++ )
865 // Check if we are dealing with an array notation request
866 arrayNotation = a[i].match(__reArray);
868 if ( arrayNotation ) {
869 a[i] = a[i].replace(__reArray, '');
871 // Condition allows simply [] to be passed in
877 // Get the remainder of the nested object to get
879 innerSrc = a.join('.');
881 // Traverse each entry in the array getting the properties requested
882 for ( var j=0, jLen=data.length ; j<jLen ; j++ ) {
883 out.push( fetchData( data[j], type, innerSrc ) );
886 // If a string is given in between the array notation indicators, that
887 // is used to join the strings together, otherwise an array is returned
888 var join = arrayNotation[0].substring(1, arrayNotation[0].length-1);
889 data = (join==="") ? out : out.join(join);
891 // The inner call to fetchData has already traversed through the remainder
892 // of the source requested, so we exit from the loop
896 if ( data === null || data[ a[i] ] === undefined )
907 return function (data, type) {
908 return fetchData( data, type, mSource );
913 /* Array or flat object mapping */
914 return function (data, type) {
915 return data[mSource];
922 * Return a function that can be used to set data from a source object, taking
923 * into account the ability to use nested objects as a source
924 * @param {string|int|function} mSource The data source for the object
925 * @returns {function} Data set function
926 * @memberof DataTable#oApi
928 function _fnSetObjectDataFn( mSource )
930 if ( mSource === null )
932 /* Nothing to do when the data source is null */
933 return function (data, val) {};
935 else if ( typeof mSource === 'function' )
937 return function (data, val) {
938 mSource( data, 'set', val );
941 else if ( typeof mSource === 'string' && (mSource.indexOf('.') !== -1 || mSource.indexOf('[') !== -1) )
943 /* Like the get, we need to get data from a nested object */
944 var setData = function (data, val, src) {
945 var a = src.split('.'), b;
946 var arrayNotation, o, innerSrc;
948 for ( var i=0, iLen=a.length-1 ; i<iLen ; i++ )
950 // Check if we are dealing with an array notation request
951 arrayNotation = a[i].match(__reArray);
955 a[i] = a[i].replace(__reArray, '');
958 // Get the remainder of the nested object to set so we can recurse
961 innerSrc = b.join('.');
963 // Traverse each entry in the array setting the properties requested
964 for ( var j=0, jLen=val.length ; j<jLen ; j++ )
967 setData( o, val[j], innerSrc );
968 data[ a[i] ].push( o );
971 // The inner call to setData has already traversed through the remainder
972 // of the source and has set the data, thus we can exit here
976 // If the nested object doesn't currently exist - since we are
977 // trying to set the value - create it
978 if ( data[ a[i] ] === null || data[ a[i] ] === undefined )
985 // If array notation is used, we just want to strip it and use the property name
986 // and assign the value. If it isn't used, then we get the result we want anyway
987 data[ a[a.length-1].replace(__reArray, '') ] = val;
990 return function (data, val) {
991 return setData( data, val, mSource );
996 /* Array or flat object mapping */
997 return function (data, val) {
1005 * Return an array with the full table data
1006 * @param {object} oSettings dataTables settings object
1007 * @returns array {array} aData Master data array
1008 * @memberof DataTable#oApi
1010 function _fnGetDataMaster ( oSettings )
1013 var iLen = oSettings.aoData.length;
1014 for ( var i=0 ; i<iLen; i++ )
1016 aData.push( oSettings.aoData[i]._aData );
1024 * @param {object} oSettings dataTables settings object
1025 * @memberof DataTable#oApi
1027 function _fnClearTable( oSettings )
1029 oSettings.aoData.splice( 0, oSettings.aoData.length );
1030 oSettings.aiDisplayMaster.splice( 0, oSettings.aiDisplayMaster.length );
1031 oSettings.aiDisplay.splice( 0, oSettings.aiDisplay.length );
1032 _fnCalculateEnd( oSettings );
1037 * Take an array of integers (index array) and remove a target integer (value - not
1039 * @param {array} a Index array to target
1040 * @param {int} iTarget value to find
1041 * @memberof DataTable#oApi
1043 function _fnDeleteIndex( a, iTarget )
1045 var iTargetIndex = -1;
1047 for ( var i=0, iLen=a.length ; i<iLen ; i++ )
1049 if ( a[i] == iTarget )
1053 else if ( a[i] > iTarget )
1059 if ( iTargetIndex != -1 )
1061 a.splice( iTargetIndex, 1 );
1067 * Call the developer defined fnRender function for a given cell (row/column) with
1068 * the required parameters and return the result.
1069 * @param {object} oSettings dataTables settings object
1070 * @param {int} iRow aoData index for the row
1071 * @param {int} iCol aoColumns index for the column
1072 * @returns {*} Return of the developer's fnRender function
1073 * @memberof DataTable#oApi
1075 function _fnRender( oSettings, iRow, iCol )
1077 var oCol = oSettings.aoColumns[iCol];
1079 return oCol.fnRender( {
1081 "iDataColumn": iCol,
1082 "oSettings": oSettings,
1083 "aData": oSettings.aoData[iRow]._aData,
1084 "mDataProp": oCol.mData
1085 }, _fnGetCellData(oSettings, iRow, iCol, 'display') );
1088 * Create a new TR element (and it's TD children) for a row
1089 * @param {object} oSettings dataTables settings object
1090 * @param {int} iRow Row to consider
1091 * @memberof DataTable#oApi
1093 function _fnCreateTr ( oSettings, iRow )
1095 var oData = oSettings.aoData[iRow];
1098 if ( oData.nTr === null )
1100 oData.nTr = document.createElement('tr');
1102 /* Use a private property on the node to allow reserve mapping from the node
1103 * to the aoData array for fast look up
1105 oData.nTr._DT_RowIndex = iRow;
1107 /* Special parameters can be given by the data source to be used on the row */
1108 if ( oData._aData.DT_RowId )
1110 oData.nTr.id = oData._aData.DT_RowId;
1113 if ( oData._aData.DT_RowClass )
1115 oData.nTr.className = oData._aData.DT_RowClass;
1118 /* Process each column */
1119 for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
1121 var oCol = oSettings.aoColumns[i];
1122 nTd = document.createElement( oCol.sCellType );
1124 /* Render if needed - if bUseRendered is true then we already have the rendered
1125 * value in the data source - so can just use that
1127 nTd.innerHTML = (typeof oCol.fnRender === 'function' && (!oCol.bUseRendered || oCol.mData === null)) ?
1128 _fnRender( oSettings, iRow, i ) :
1129 _fnGetCellData( oSettings, iRow, i, 'display' );
1131 /* Add user defined class */
1132 if ( oCol.sClass !== null )
1134 nTd.className = oCol.sClass;
1137 if ( oCol.bVisible )
1139 oData.nTr.appendChild( nTd );
1140 oData._anHidden[i] = null;
1144 oData._anHidden[i] = nTd;
1147 if ( oCol.fnCreatedCell )
1149 oCol.fnCreatedCell.call( oSettings.oInstance,
1150 nTd, _fnGetCellData( oSettings, iRow, i, 'display' ), oData._aData, iRow, i
1155 _fnCallbackFire( oSettings, 'aoRowCreatedCallback', null, [oData.nTr, oData._aData, iRow] );
1161 * Create the HTML header for the table
1162 * @param {object} oSettings dataTables settings object
1163 * @memberof DataTable#oApi
1165 function _fnBuildHead( oSettings )
1167 var i, nTh, iLen, j, jLen;
1168 var iThs = $('th, td', oSettings.nTHead).length;
1172 /* If there is a header in place - then use it - otherwise it's going to get nuked... */
1175 /* We've got a thead from the DOM, so remove hidden columns and apply width to vis cols */
1176 for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
1178 nTh = oSettings.aoColumns[i].nTh;
1179 nTh.setAttribute('role', 'columnheader');
1180 if ( oSettings.aoColumns[i].bSortable )
1182 nTh.setAttribute('tabindex', oSettings.iTabIndex);
1183 nTh.setAttribute('aria-controls', oSettings.sTableId);
1186 if ( oSettings.aoColumns[i].sClass !== null )
1188 $(nTh).addClass( oSettings.aoColumns[i].sClass );
1191 /* Set the title of the column if it is user defined (not what was auto detected) */
1192 if ( oSettings.aoColumns[i].sTitle != nTh.innerHTML )
1194 nTh.innerHTML = oSettings.aoColumns[i].sTitle;
1200 /* We don't have a header in the DOM - so we are going to have to create one */
1201 var nTr = document.createElement( "tr" );
1203 for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
1205 nTh = oSettings.aoColumns[i].nTh;
1206 nTh.innerHTML = oSettings.aoColumns[i].sTitle;
1207 nTh.setAttribute('tabindex', '0');
1209 if ( oSettings.aoColumns[i].sClass !== null )
1211 $(nTh).addClass( oSettings.aoColumns[i].sClass );
1214 nTr.appendChild( nTh );
1216 $(oSettings.nTHead).html( '' )[0].appendChild( nTr );
1217 _fnDetectHeader( oSettings.aoHeader, oSettings.nTHead );
1220 /* ARIA role for the rows */
1221 $(oSettings.nTHead).children('tr').attr('role', 'row');
1223 /* Add the extra markup needed by jQuery UI's themes */
1224 if ( oSettings.bJUI )
1226 for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
1228 nTh = oSettings.aoColumns[i].nTh;
1230 var nDiv = document.createElement('div');
1231 nDiv.className = oSettings.oClasses.sSortJUIWrapper;
1232 $(nTh).contents().appendTo(nDiv);
1234 var nSpan = document.createElement('span');
1235 nSpan.className = oSettings.oClasses.sSortIcon;
1236 nDiv.appendChild( nSpan );
1237 nTh.appendChild( nDiv );
1241 if ( oSettings.oFeatures.bSort )
1243 for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
1245 if ( oSettings.aoColumns[i].bSortable !== false )
1247 _fnSortAttachListener( oSettings, oSettings.aoColumns[i].nTh, i );
1251 $(oSettings.aoColumns[i].nTh).addClass( oSettings.oClasses.sSortableNone );
1256 /* Deal with the footer - add classes if required */
1257 if ( oSettings.oClasses.sFooterTH !== "" )
1259 $(oSettings.nTFoot).children('tr').children('th').addClass( oSettings.oClasses.sFooterTH );
1262 /* Cache the footer elements */
1263 if ( oSettings.nTFoot !== null )
1265 var anCells = _fnGetUniqueThs( oSettings, null, oSettings.aoFooter );
1266 for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
1270 oSettings.aoColumns[i].nTf = anCells[i];
1271 if ( oSettings.aoColumns[i].sClass )
1273 $(anCells[i]).addClass( oSettings.aoColumns[i].sClass );
1282 * Draw the header (or footer) element based on the column visibility states. The
1283 * methodology here is to use the layout array from _fnDetectHeader, modified for
1284 * the instantaneous column visibility, to construct the new layout. The grid is
1285 * traversed over cell at a time in a rows x columns grid fashion, although each
1286 * cell insert can cover multiple elements in the grid - which is tracks using the
1287 * aApplied array. Cell inserts in the grid will only occur where there isn't
1288 * already a cell in that position.
1289 * @param {object} oSettings dataTables settings object
1290 * @param array {objects} aoSource Layout array from _fnDetectHeader
1291 * @param {boolean} [bIncludeHidden=false] If true then include the hidden columns in the calc,
1292 * @memberof DataTable#oApi
1294 function _fnDrawHead( oSettings, aoSource, bIncludeHidden )
1296 var i, iLen, j, jLen, k, kLen, n, nLocalTr;
1299 var iColumns = oSettings.aoColumns.length;
1300 var iRowspan, iColspan;
1302 if ( bIncludeHidden === undefined )
1304 bIncludeHidden = false;
1307 /* Make a copy of the master layout array, but without the visible columns in it */
1308 for ( i=0, iLen=aoSource.length ; i<iLen ; i++ )
1310 aoLocal[i] = aoSource[i].slice();
1311 aoLocal[i].nTr = aoSource[i].nTr;
1313 /* Remove any columns which are currently hidden */
1314 for ( j=iColumns-1 ; j>=0 ; j-- )
1316 if ( !oSettings.aoColumns[j].bVisible && !bIncludeHidden )
1318 aoLocal[i].splice( j, 1 );
1322 /* Prep the applied array - it needs an element for each row */
1323 aApplied.push( [] );
1326 for ( i=0, iLen=aoLocal.length ; i<iLen ; i++ )
1328 nLocalTr = aoLocal[i].nTr;
1330 /* All cells are going to be replaced, so empty out the row */
1333 while( (n = nLocalTr.firstChild) )
1335 nLocalTr.removeChild( n );
1339 for ( j=0, jLen=aoLocal[i].length ; j<jLen ; j++ )
1344 /* Check to see if there is already a cell (row/colspan) covering our target
1345 * insert point. If there is, then there is nothing to do.
1347 if ( aApplied[i][j] === undefined )
1349 nLocalTr.appendChild( aoLocal[i][j].cell );
1352 /* Expand the cell to cover as many rows as needed */
1353 while ( aoLocal[i+iRowspan] !== undefined &&
1354 aoLocal[i][j].cell == aoLocal[i+iRowspan][j].cell )
1356 aApplied[i+iRowspan][j] = 1;
1360 /* Expand the cell to cover as many columns as needed */
1361 while ( aoLocal[i][j+iColspan] !== undefined &&
1362 aoLocal[i][j].cell == aoLocal[i][j+iColspan].cell )
1364 /* Must update the applied array over the rows for the columns */
1365 for ( k=0 ; k<iRowspan ; k++ )
1367 aApplied[i+k][j+iColspan] = 1;
1372 /* Do the actual expansion in the DOM */
1373 aoLocal[i][j].cell.rowSpan = iRowspan;
1374 aoLocal[i][j].cell.colSpan = iColspan;
1382 * Insert the required TR nodes into the table for display
1383 * @param {object} oSettings dataTables settings object
1384 * @memberof DataTable#oApi
1386 function _fnDraw( oSettings )
1388 /* Provide a pre-callback function which can be used to cancel the draw is false is returned */
1389 var aPreDraw = _fnCallbackFire( oSettings, 'aoPreDrawCallback', 'preDraw', [oSettings] );
1390 if ( $.inArray( false, aPreDraw ) !== -1 )
1392 _fnProcessingDisplay( oSettings, false );
1399 var iStripes = oSettings.asStripeClasses.length;
1400 var iOpenRows = oSettings.aoOpenRows.length;
1402 oSettings.bDrawing = true;
1404 /* Check and see if we have an initial draw position from state saving */
1405 if ( oSettings.iInitDisplayStart !== undefined && oSettings.iInitDisplayStart != -1 )
1407 if ( oSettings.oFeatures.bServerSide )
1409 oSettings._iDisplayStart = oSettings.iInitDisplayStart;
1413 oSettings._iDisplayStart = (oSettings.iInitDisplayStart >= oSettings.fnRecordsDisplay()) ?
1414 0 : oSettings.iInitDisplayStart;
1416 oSettings.iInitDisplayStart = -1;
1417 _fnCalculateEnd( oSettings );
1420 /* Server-side processing draw intercept */
1421 if ( oSettings.bDeferLoading )
1423 oSettings.bDeferLoading = false;
1426 else if ( !oSettings.oFeatures.bServerSide )
1430 else if ( !oSettings.bDestroying && !_fnAjaxUpdate( oSettings ) )
1435 if ( oSettings.aiDisplay.length !== 0 )
1437 var iStart = oSettings._iDisplayStart;
1438 var iEnd = oSettings._iDisplayEnd;
1440 if ( oSettings.oFeatures.bServerSide )
1443 iEnd = oSettings.aoData.length;
1446 for ( var j=iStart ; j<iEnd ; j++ )
1448 var aoData = oSettings.aoData[ oSettings.aiDisplay[j] ];
1449 if ( aoData.nTr === null )
1451 _fnCreateTr( oSettings, oSettings.aiDisplay[j] );
1454 var nRow = aoData.nTr;
1456 /* Remove the old striping classes and then add the new one */
1457 if ( iStripes !== 0 )
1459 var sStripe = oSettings.asStripeClasses[ iRowCount % iStripes ];
1460 if ( aoData._sRowStripe != sStripe )
1462 $(nRow).removeClass( aoData._sRowStripe ).addClass( sStripe );
1463 aoData._sRowStripe = sStripe;
1467 /* Row callback functions - might want to manipulate the row */
1468 _fnCallbackFire( oSettings, 'aoRowCallback', null,
1469 [nRow, oSettings.aoData[ oSettings.aiDisplay[j] ]._aData, iRowCount, j] );
1471 anRows.push( nRow );
1474 /* If there is an open row - and it is attached to this parent - attach it on redraw */
1475 if ( iOpenRows !== 0 )
1477 for ( var k=0 ; k<iOpenRows ; k++ )
1479 if ( nRow == oSettings.aoOpenRows[k].nParent )
1481 anRows.push( oSettings.aoOpenRows[k].nTr );
1490 /* Table is empty - create a row with an empty message in it */
1491 anRows[ 0 ] = document.createElement( 'tr' );
1493 if ( oSettings.asStripeClasses[0] )
1495 anRows[ 0 ].className = oSettings.asStripeClasses[0];
1498 var oLang = oSettings.oLanguage;
1499 var sZero = oLang.sZeroRecords;
1500 if ( oSettings.iDraw == 1 && oSettings.sAjaxSource !== null && !oSettings.oFeatures.bServerSide )
1502 sZero = oLang.sLoadingRecords;
1504 else if ( oLang.sEmptyTable && oSettings.fnRecordsTotal() === 0 )
1506 sZero = oLang.sEmptyTable;
1509 var nTd = document.createElement( 'td' );
1510 nTd.setAttribute( 'valign', "top" );
1511 nTd.colSpan = _fnVisbleColumns( oSettings );
1512 nTd.className = oSettings.oClasses.sRowEmpty;
1513 nTd.innerHTML = _fnInfoMacros( oSettings, sZero );
1515 anRows[ iRowCount ].appendChild( nTd );
1518 /* Header and footer callbacks */
1519 _fnCallbackFire( oSettings, 'aoHeaderCallback', 'header', [ $(oSettings.nTHead).children('tr')[0],
1520 _fnGetDataMaster( oSettings ), oSettings._iDisplayStart, oSettings.fnDisplayEnd(), oSettings.aiDisplay ] );
1522 _fnCallbackFire( oSettings, 'aoFooterCallback', 'footer', [ $(oSettings.nTFoot).children('tr')[0],
1523 _fnGetDataMaster( oSettings ), oSettings._iDisplayStart, oSettings.fnDisplayEnd(), oSettings.aiDisplay ] );
1526 * Need to remove any old row from the display - note we can't just empty the tbody using
1527 * $().html('') since this will unbind the jQuery event handlers (even although the node
1528 * still exists!) - equally we can't use innerHTML, since IE throws an exception.
1531 nAddFrag = document.createDocumentFragment(),
1532 nRemoveFrag = document.createDocumentFragment(),
1535 if ( oSettings.nTBody )
1537 nBodyPar = oSettings.nTBody.parentNode;
1538 nRemoveFrag.appendChild( oSettings.nTBody );
1540 /* When doing infinite scrolling, only remove child rows when sorting, filtering or start
1541 * up. When not infinite scroll, always do it.
1543 if ( !oSettings.oScroll.bInfinite || !oSettings._bInitComplete ||
1544 oSettings.bSorted || oSettings.bFiltered )
1546 while( (n = oSettings.nTBody.firstChild) )
1548 oSettings.nTBody.removeChild( n );
1552 /* Put the draw table into the dom */
1553 for ( i=0, iLen=anRows.length ; i<iLen ; i++ )
1555 nAddFrag.appendChild( anRows[i] );
1558 oSettings.nTBody.appendChild( nAddFrag );
1559 if ( nBodyPar !== null )
1561 nBodyPar.appendChild( oSettings.nTBody );
1565 /* Call all required callback functions for the end of a draw */
1566 _fnCallbackFire( oSettings, 'aoDrawCallback', 'draw', [oSettings] );
1568 /* Draw is complete, sorting and filtering must be as well */
1569 oSettings.bSorted = false;
1570 oSettings.bFiltered = false;
1571 oSettings.bDrawing = false;
1573 if ( oSettings.oFeatures.bServerSide )
1575 _fnProcessingDisplay( oSettings, false );
1576 if ( !oSettings._bInitComplete )
1578 _fnInitComplete( oSettings );
1585 * Redraw the table - taking account of the various features which are enabled
1586 * @param {object} oSettings dataTables settings object
1587 * @memberof DataTable#oApi
1589 function _fnReDraw( oSettings )
1591 if ( oSettings.oFeatures.bSort )
1593 /* Sorting will refilter and draw for us */
1594 _fnSort( oSettings, oSettings.oPreviousSearch );
1596 else if ( oSettings.oFeatures.bFilter )
1598 /* Filtering will redraw for us */
1599 _fnFilterComplete( oSettings, oSettings.oPreviousSearch );
1603 _fnCalculateEnd( oSettings );
1604 _fnDraw( oSettings );
1610 * Add the options to the page HTML for the table
1611 * @param {object} oSettings dataTables settings object
1612 * @memberof DataTable#oApi
1614 function _fnAddOptionsHtml ( oSettings )
1617 * Create a temporary, empty, div which we can later on replace with what we have generated
1618 * we do it this way to rendering the 'options' html offline - speed :-)
1620 var nHolding = $('<div></div>')[0];
1621 oSettings.nTable.parentNode.insertBefore( nHolding, oSettings.nTable );
1624 * All DataTables are wrapped in a div
1626 oSettings.nTableWrapper = $('<div id="'+oSettings.sTableId+'_wrapper" class="'+oSettings.oClasses.sWrapper+'" role="grid"></div>')[0];
1627 oSettings.nTableReinsertBefore = oSettings.nTable.nextSibling;
1629 /* Track where we want to insert the option */
1630 var nInsertNode = oSettings.nTableWrapper;
1632 /* Loop over the user set positioning and place the elements as needed */
1633 var aDom = oSettings.sDom.split('');
1634 var nTmp, iPushFeature, cOption, nNewNode, cNext, sAttr, j;
1635 for ( var i=0 ; i<aDom.length ; i++ )
1640 if ( cOption == '<' )
1642 /* New container div */
1643 nNewNode = $('<div></div>')[0];
1645 /* Check to see if we should append an id and/or a class name to the container */
1647 if ( cNext == "'" || cNext == '"' )
1651 while ( aDom[i+j] != cNext )
1657 /* Replace jQuery UI constants */
1660 sAttr = oSettings.oClasses.sJUIHeader;
1662 else if ( sAttr == "F" )
1664 sAttr = oSettings.oClasses.sJUIFooter;
1667 /* The attribute can be in the format of "#id.class", "#id" or "class" This logic
1668 * breaks the string into parts and applies them as needed
1670 if ( sAttr.indexOf('.') != -1 )
1672 var aSplit = sAttr.split('.');
1673 nNewNode.id = aSplit[0].substr(1, aSplit[0].length-1);
1674 nNewNode.className = aSplit[1];
1676 else if ( sAttr.charAt(0) == "#" )
1678 nNewNode.id = sAttr.substr(1, sAttr.length-1);
1682 nNewNode.className = sAttr;
1685 i += j; /* Move along the position array */
1688 nInsertNode.appendChild( nNewNode );
1689 nInsertNode = nNewNode;
1691 else if ( cOption == '>' )
1693 /* End container div */
1694 nInsertNode = nInsertNode.parentNode;
1696 else if ( cOption == 'l' && oSettings.oFeatures.bPaginate && oSettings.oFeatures.bLengthChange )
1699 nTmp = _fnFeatureHtmlLength( oSettings );
1702 else if ( cOption == 'f' && oSettings.oFeatures.bFilter )
1705 nTmp = _fnFeatureHtmlFilter( oSettings );
1708 else if ( cOption == 'r' && oSettings.oFeatures.bProcessing )
1711 nTmp = _fnFeatureHtmlProcessing( oSettings );
1714 else if ( cOption == 't' )
1717 nTmp = _fnFeatureHtmlTable( oSettings );
1720 else if ( cOption == 'i' && oSettings.oFeatures.bInfo )
1723 nTmp = _fnFeatureHtmlInfo( oSettings );
1726 else if ( cOption == 'p' && oSettings.oFeatures.bPaginate )
1729 nTmp = _fnFeatureHtmlPaginate( oSettings );
1732 else if ( DataTable.ext.aoFeatures.length !== 0 )
1734 /* Plug-in features */
1735 var aoFeatures = DataTable.ext.aoFeatures;
1736 for ( var k=0, kLen=aoFeatures.length ; k<kLen ; k++ )
1738 if ( cOption == aoFeatures[k].cFeature )
1740 nTmp = aoFeatures[k].fnInit( oSettings );
1750 /* Add to the 2D features array */
1751 if ( iPushFeature == 1 && nTmp !== null )
1753 if ( typeof oSettings.aanFeatures[cOption] !== 'object' )
1755 oSettings.aanFeatures[cOption] = [];
1757 oSettings.aanFeatures[cOption].push( nTmp );
1758 nInsertNode.appendChild( nTmp );
1762 /* Built our DOM structure - replace the holding div with what we want */
1763 nHolding.parentNode.replaceChild( oSettings.nTableWrapper, nHolding );
1768 * Use the DOM source to create up an array of header cells. The idea here is to
1769 * create a layout grid (array) of rows x columns, which contains a reference
1770 * to the cell that that point in the grid (regardless of col/rowspan), such that
1771 * any column / row could be removed and the new grid constructed
1772 * @param array {object} aLayout Array to store the calculated layout in
1773 * @param {node} nThead The header/footer element for the table
1774 * @memberof DataTable#oApi
1776 function _fnDetectHeader ( aLayout, nThead )
1778 var nTrs = $(nThead).children('tr');
1780 var i, k, l, iLen, jLen, iColShifted, iColumn, iColspan, iRowspan;
1782 var fnShiftCol = function ( a, i, j ) {
1790 aLayout.splice( 0, aLayout.length );
1792 /* We know how many rows there are in the layout - so prep it */
1793 for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
1798 /* Calculate a layout array */
1799 for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
1804 /* For every cell in the row... */
1805 nCell = nTr.firstChild;
1807 if ( nCell.nodeName.toUpperCase() == "TD" ||
1808 nCell.nodeName.toUpperCase() == "TH" )
1810 /* Get the col and rowspan attributes from the DOM and sanitise them */
1811 iColspan = nCell.getAttribute('colspan') * 1;
1812 iRowspan = nCell.getAttribute('rowspan') * 1;
1813 iColspan = (!iColspan || iColspan===0 || iColspan===1) ? 1 : iColspan;
1814 iRowspan = (!iRowspan || iRowspan===0 || iRowspan===1) ? 1 : iRowspan;
1816 /* There might be colspan cells already in this row, so shift our target
1819 iColShifted = fnShiftCol( aLayout, i, iColumn );
1821 /* Cache calculation for unique columns */
1822 bUnique = iColspan === 1 ? true : false;
1824 /* If there is col / rowspan, copy the information into the layout grid */
1825 for ( l=0 ; l<iColspan ; l++ )
1827 for ( k=0 ; k<iRowspan ; k++ )
1829 aLayout[i+k][iColShifted+l] = {
1833 aLayout[i+k].nTr = nTr;
1837 nCell = nCell.nextSibling;
1844 * Get an array of unique th elements, one for each column
1845 * @param {object} oSettings dataTables settings object
1846 * @param {node} nHeader automatically detect the layout from this node - optional
1847 * @param {array} aLayout thead/tfoot layout from _fnDetectHeader - optional
1848 * @returns array {node} aReturn list of unique th's
1849 * @memberof DataTable#oApi
1851 function _fnGetUniqueThs ( oSettings, nHeader, aLayout )
1856 aLayout = oSettings.aoHeader;
1860 _fnDetectHeader( aLayout, nHeader );
1864 for ( var i=0, iLen=aLayout.length ; i<iLen ; i++ )
1866 for ( var j=0, jLen=aLayout[i].length ; j<jLen ; j++ )
1868 if ( aLayout[i][j].unique &&
1869 (!aReturn[j] || !oSettings.bSortCellsTop) )
1871 aReturn[j] = aLayout[i][j].cell;
1882 * Update the table using an Ajax call
1883 * @param {object} oSettings dataTables settings object
1884 * @returns {boolean} Block the table drawing or not
1885 * @memberof DataTable#oApi
1887 function _fnAjaxUpdate( oSettings )
1889 if ( oSettings.bAjaxDataGet )
1892 _fnProcessingDisplay( oSettings, true );
1893 var iColumns = oSettings.aoColumns.length;
1894 var aoData = _fnAjaxParameters( oSettings );
1895 _fnServerParams( oSettings, aoData );
1897 oSettings.fnServerData.call( oSettings.oInstance, oSettings.sAjaxSource, aoData,
1899 _fnAjaxUpdateDraw( oSettings, json );
1911 * Build up the parameters in an object needed for a server-side processing request
1912 * @param {object} oSettings dataTables settings object
1913 * @returns {bool} block the table drawing or not
1914 * @memberof DataTable#oApi
1916 function _fnAjaxParameters( oSettings )
1918 var iColumns = oSettings.aoColumns.length;
1919 var aoData = [], mDataProp, aaSort, aDataSort;
1922 aoData.push( { "name": "sEcho", "value": oSettings.iDraw } );
1923 aoData.push( { "name": "iColumns", "value": iColumns } );
1924 aoData.push( { "name": "sColumns", "value": _fnColumnOrdering(oSettings) } );
1925 aoData.push( { "name": "iDisplayStart", "value": oSettings._iDisplayStart } );
1926 aoData.push( { "name": "iDisplayLength", "value": oSettings.oFeatures.bPaginate !== false ?
1927 oSettings._iDisplayLength : -1 } );
1929 for ( i=0 ; i<iColumns ; i++ )
1931 mDataProp = oSettings.aoColumns[i].mData;
1932 aoData.push( { "name": "mDataProp_"+i, "value": typeof(mDataProp)==="function" ? 'function' : mDataProp } );
1936 if ( oSettings.oFeatures.bFilter !== false )
1938 aoData.push( { "name": "sSearch", "value": oSettings.oPreviousSearch.sSearch } );
1939 aoData.push( { "name": "bRegex", "value": oSettings.oPreviousSearch.bRegex } );
1940 for ( i=0 ; i<iColumns ; i++ )
1942 aoData.push( { "name": "sSearch_"+i, "value": oSettings.aoPreSearchCols[i].sSearch } );
1943 aoData.push( { "name": "bRegex_"+i, "value": oSettings.aoPreSearchCols[i].bRegex } );
1944 aoData.push( { "name": "bSearchable_"+i, "value": oSettings.aoColumns[i].bSearchable } );
1949 if ( oSettings.oFeatures.bSort !== false )
1953 aaSort = ( oSettings.aaSortingFixed !== null ) ?
1954 oSettings.aaSortingFixed.concat( oSettings.aaSorting ) :
1955 oSettings.aaSorting.slice();
1957 for ( i=0 ; i<aaSort.length ; i++ )
1959 aDataSort = oSettings.aoColumns[ aaSort[i][0] ].aDataSort;
1961 for ( j=0 ; j<aDataSort.length ; j++ )
1963 aoData.push( { "name": "iSortCol_"+iCounter, "value": aDataSort[j] } );
1964 aoData.push( { "name": "sSortDir_"+iCounter, "value": aaSort[i][1] } );
1968 aoData.push( { "name": "iSortingCols", "value": iCounter } );
1970 for ( i=0 ; i<iColumns ; i++ )
1972 aoData.push( { "name": "bSortable_"+i, "value": oSettings.aoColumns[i].bSortable } );
1981 * Add Ajax parameters from plug-ins
1982 * @param {object} oSettings dataTables settings object
1983 * @param array {objects} aoData name/value pairs to send to the server
1984 * @memberof DataTable#oApi
1986 function _fnServerParams( oSettings, aoData )
1988 _fnCallbackFire( oSettings, 'aoServerParams', 'serverParams', [aoData] );
1993 * Data the data from the server (nuking the old) and redraw the table
1994 * @param {object} oSettings dataTables settings object
1995 * @param {object} json json data return from the server.
1996 * @param {string} json.sEcho Tracking flag for DataTables to match requests
1997 * @param {int} json.iTotalRecords Number of records in the data set, not accounting for filtering
1998 * @param {int} json.iTotalDisplayRecords Number of records in the data set, accounting for filtering
1999 * @param {array} json.aaData The data to display on this page
2000 * @param {string} [json.sColumns] Column ordering (sName, comma separated)
2001 * @memberof DataTable#oApi
2003 function _fnAjaxUpdateDraw ( oSettings, json )
2005 if ( json.sEcho !== undefined )
2007 /* Protect against old returns over-writing a new one. Possible when you get
2008 * very fast interaction, and later queries are completed much faster
2010 if ( json.sEcho*1 < oSettings.iDraw )
2016 oSettings.iDraw = json.sEcho * 1;
2020 if ( !oSettings.oScroll.bInfinite ||
2021 (oSettings.oScroll.bInfinite && (oSettings.bSorted || oSettings.bFiltered)) )
2023 _fnClearTable( oSettings );
2025 oSettings._iRecordsTotal = parseInt(json.iTotalRecords, 10);
2026 oSettings._iRecordsDisplay = parseInt(json.iTotalDisplayRecords, 10);
2028 /* Determine if reordering is required */
2029 var sOrdering = _fnColumnOrdering(oSettings);
2030 var bReOrder = (json.sColumns !== undefined && sOrdering !== "" && json.sColumns != sOrdering );
2034 aiIndex = _fnReOrderIndex( oSettings, json.sColumns );
2037 var aData = _fnGetObjectDataFn( oSettings.sAjaxDataProp )( json );
2038 for ( var i=0, iLen=aData.length ; i<iLen ; i++ )
2042 /* If we need to re-order, then create a new array with the correct order and add it */
2043 var aDataSorted = [];
2044 for ( var j=0, jLen=oSettings.aoColumns.length ; j<jLen ; j++ )
2046 aDataSorted.push( aData[i][ aiIndex[j] ] );
2048 _fnAddData( oSettings, aDataSorted );
2052 /* No re-order required, sever got it "right" - just straight add */
2053 _fnAddData( oSettings, aData[i] );
2056 oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
2058 oSettings.bAjaxDataGet = false;
2059 _fnDraw( oSettings );
2060 oSettings.bAjaxDataGet = true;
2061 _fnProcessingDisplay( oSettings, false );
2067 * Generate the node required for filtering text
2068 * @returns {node} Filter control element
2069 * @param {object} oSettings dataTables settings object
2070 * @memberof DataTable#oApi
2072 function _fnFeatureHtmlFilter ( oSettings )
2074 var oPreviousSearch = oSettings.oPreviousSearch;
2076 var sSearchStr = oSettings.oLanguage.sSearch;
2077 sSearchStr = (sSearchStr.indexOf('_INPUT_') !== -1) ?
2078 sSearchStr.replace('_INPUT_', '<input type="text" />') :
2079 sSearchStr==="" ? '<input type="text" />' : sSearchStr+' <input type="text" />';
2081 var nFilter = document.createElement( 'div' );
2082 nFilter.className = oSettings.oClasses.sFilter;
2083 nFilter.innerHTML = '<label>'+sSearchStr+'</label>';
2084 if ( !oSettings.aanFeatures.f )
2086 nFilter.id = oSettings.sTableId+'_filter';
2089 var jqFilter = $('input[type="text"]', nFilter);
2091 // Store a reference to the input element, so other input elements could be
2092 // added to the filter wrapper if needed (submit button for example)
2093 nFilter._DT_Input = jqFilter[0];
2095 jqFilter.val( oPreviousSearch.sSearch.replace('"','"') );
2096 jqFilter.bind( 'keyup.DT', function(e) {
2097 /* Update all other filter input elements for the new display */
2098 var n = oSettings.aanFeatures.f;
2099 var val = this.value==="" ? "" : this.value; // mental IE8 fix :-(
2101 for ( var i=0, iLen=n.length ; i<iLen ; i++ )
2103 if ( n[i] != $(this).parents('div.dataTables_filter')[0] )
2105 $(n[i]._DT_Input).val( val );
2109 /* Now do the filter */
2110 if ( val != oPreviousSearch.sSearch )
2112 _fnFilterComplete( oSettings, {
2114 "bRegex": oPreviousSearch.bRegex,
2115 "bSmart": oPreviousSearch.bSmart ,
2116 "bCaseInsensitive": oPreviousSearch.bCaseInsensitive
2122 .attr('aria-controls', oSettings.sTableId)
2123 .bind( 'keypress.DT', function(e) {
2124 /* Prevent form submission */
2125 if ( e.keyCode == 13 )
2137 * Filter the table using both the global filter and column based filtering
2138 * @param {object} oSettings dataTables settings object
2139 * @param {object} oSearch search information
2140 * @param {int} [iForce] force a research of the master array (1) or not (undefined or 0)
2141 * @memberof DataTable#oApi
2143 function _fnFilterComplete ( oSettings, oInput, iForce )
2145 var oPrevSearch = oSettings.oPreviousSearch;
2146 var aoPrevSearch = oSettings.aoPreSearchCols;
2147 var fnSaveFilter = function ( oFilter ) {
2148 /* Save the filtering values */
2149 oPrevSearch.sSearch = oFilter.sSearch;
2150 oPrevSearch.bRegex = oFilter.bRegex;
2151 oPrevSearch.bSmart = oFilter.bSmart;
2152 oPrevSearch.bCaseInsensitive = oFilter.bCaseInsensitive;
2155 /* In server-side processing all filtering is done by the server, so no point hanging around here */
2156 if ( !oSettings.oFeatures.bServerSide )
2159 _fnFilter( oSettings, oInput.sSearch, iForce, oInput.bRegex, oInput.bSmart, oInput.bCaseInsensitive );
2160 fnSaveFilter( oInput );
2162 /* Now do the individual column filter */
2163 for ( var i=0 ; i<oSettings.aoPreSearchCols.length ; i++ )
2165 _fnFilterColumn( oSettings, aoPrevSearch[i].sSearch, i, aoPrevSearch[i].bRegex,
2166 aoPrevSearch[i].bSmart, aoPrevSearch[i].bCaseInsensitive );
2169 /* Custom filtering */
2170 _fnFilterCustom( oSettings );
2174 fnSaveFilter( oInput );
2177 /* Tell the draw function we have been filtering */
2178 oSettings.bFiltered = true;
2179 $(oSettings.oInstance).trigger('filter', oSettings);
2181 /* Redraw the table */
2182 oSettings._iDisplayStart = 0;
2183 _fnCalculateEnd( oSettings );
2184 _fnDraw( oSettings );
2186 /* Rebuild search array 'offline' */
2187 _fnBuildSearchArray( oSettings, 0 );
2192 * Apply custom filtering functions
2193 * @param {object} oSettings dataTables settings object
2194 * @memberof DataTable#oApi
2196 function _fnFilterCustom( oSettings )
2198 var afnFilters = DataTable.ext.afnFiltering;
2199 var aiFilterColumns = _fnGetColumns( oSettings, 'bSearchable' );
2201 for ( var i=0, iLen=afnFilters.length ; i<iLen ; i++ )
2204 for ( var j=0, jLen=oSettings.aiDisplay.length ; j<jLen ; j++ )
2206 var iDisIndex = oSettings.aiDisplay[j-iCorrector];
2207 var bTest = afnFilters[i](
2209 _fnGetRowData( oSettings, iDisIndex, 'filter', aiFilterColumns ),
2213 /* Check if we should use this row based on the filtering function */
2216 oSettings.aiDisplay.splice( j-iCorrector, 1 );
2225 * Filter the table on a per-column basis
2226 * @param {object} oSettings dataTables settings object
2227 * @param {string} sInput string to filter on
2228 * @param {int} iColumn column to filter
2229 * @param {bool} bRegex treat search string as a regular expression or not
2230 * @param {bool} bSmart use smart filtering or not
2231 * @param {bool} bCaseInsensitive Do case insenstive matching or not
2232 * @memberof DataTable#oApi
2234 function _fnFilterColumn ( oSettings, sInput, iColumn, bRegex, bSmart, bCaseInsensitive )
2236 if ( sInput === "" )
2241 var iIndexCorrector = 0;
2242 var rpSearch = _fnFilterCreateSearch( sInput, bRegex, bSmart, bCaseInsensitive );
2244 for ( var i=oSettings.aiDisplay.length-1 ; i>=0 ; i-- )
2246 var sData = _fnDataToSearch( _fnGetCellData( oSettings, oSettings.aiDisplay[i], iColumn, 'filter' ),
2247 oSettings.aoColumns[iColumn].sType );
2248 if ( ! rpSearch.test( sData ) )
2250 oSettings.aiDisplay.splice( i, 1 );
2258 * Filter the data table based on user input and draw the table
2259 * @param {object} oSettings dataTables settings object
2260 * @param {string} sInput string to filter on
2261 * @param {int} iForce optional - force a research of the master array (1) or not (undefined or 0)
2262 * @param {bool} bRegex treat as a regular expression or not
2263 * @param {bool} bSmart perform smart filtering or not
2264 * @param {bool} bCaseInsensitive Do case insenstive matching or not
2265 * @memberof DataTable#oApi
2267 function _fnFilter( oSettings, sInput, iForce, bRegex, bSmart, bCaseInsensitive )
2270 var rpSearch = _fnFilterCreateSearch( sInput, bRegex, bSmart, bCaseInsensitive );
2271 var oPrevSearch = oSettings.oPreviousSearch;
2273 /* Check if we are forcing or not - optional parameter */
2279 /* Need to take account of custom filtering functions - always filter */
2280 if ( DataTable.ext.afnFiltering.length !== 0 )
2286 * If the input is blank - we want the full data set
2288 if ( sInput.length <= 0 )
2290 oSettings.aiDisplay.splice( 0, oSettings.aiDisplay.length);
2291 oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
2296 * We are starting a new search or the new search string is smaller
2297 * then the old one (i.e. delete). Search from the master array
2299 if ( oSettings.aiDisplay.length == oSettings.aiDisplayMaster.length ||
2300 oPrevSearch.sSearch.length > sInput.length || iForce == 1 ||
2301 sInput.indexOf(oPrevSearch.sSearch) !== 0 )
2303 /* Nuke the old display array - we are going to rebuild it */
2304 oSettings.aiDisplay.splice( 0, oSettings.aiDisplay.length);
2306 /* Force a rebuild of the search array */
2307 _fnBuildSearchArray( oSettings, 1 );
2309 /* Search through all records to populate the search array
2310 * The the oSettings.aiDisplayMaster and asDataSearch arrays have 1 to 1
2313 for ( i=0 ; i<oSettings.aiDisplayMaster.length ; i++ )
2315 if ( rpSearch.test(oSettings.asDataSearch[i]) )
2317 oSettings.aiDisplay.push( oSettings.aiDisplayMaster[i] );
2323 /* Using old search array - refine it - do it this way for speed
2324 * Don't have to search the whole master array again
2326 var iIndexCorrector = 0;
2328 /* Search the current results */
2329 for ( i=0 ; i<oSettings.asDataSearch.length ; i++ )
2331 if ( ! rpSearch.test(oSettings.asDataSearch[i]) )
2333 oSettings.aiDisplay.splice( i-iIndexCorrector, 1 );
2343 * Create an array which can be quickly search through
2344 * @param {object} oSettings dataTables settings object
2345 * @param {int} iMaster use the master data array - optional
2346 * @memberof DataTable#oApi
2348 function _fnBuildSearchArray ( oSettings, iMaster )
2350 if ( !oSettings.oFeatures.bServerSide )
2352 /* Clear out the old data */
2353 oSettings.asDataSearch = [];
2355 var aiFilterColumns = _fnGetColumns( oSettings, 'bSearchable' );
2356 var aiIndex = (iMaster===1) ?
2357 oSettings.aiDisplayMaster :
2358 oSettings.aiDisplay;
2360 for ( var i=0, iLen=aiIndex.length ; i<iLen ; i++ )
2362 oSettings.asDataSearch[i] = _fnBuildSearchRow(
2364 _fnGetRowData( oSettings, aiIndex[i], 'filter', aiFilterColumns )
2372 * Create a searchable string from a single data row
2373 * @param {object} oSettings dataTables settings object
2374 * @param {array} aData Row data array to use for the data to search
2375 * @memberof DataTable#oApi
2377 function _fnBuildSearchRow( oSettings, aData )
2379 var sSearch = aData.join(' ');
2381 /* If it looks like there is an HTML entity in the string, attempt to decode it */
2382 if ( sSearch.indexOf('&') !== -1 )
2384 sSearch = $('<div>').html(sSearch).text();
2387 // Strip newline characters
2388 return sSearch.replace( /[\n\r]/g, " " );
2392 * Build a regular expression object suitable for searching a table
2393 * @param {string} sSearch string to search for
2394 * @param {bool} bRegex treat as a regular expression or not
2395 * @param {bool} bSmart perform smart filtering or not
2396 * @param {bool} bCaseInsensitive Do case insensitive matching or not
2397 * @returns {RegExp} constructed object
2398 * @memberof DataTable#oApi
2400 function _fnFilterCreateSearch( sSearch, bRegex, bSmart, bCaseInsensitive )
2402 var asSearch, sRegExpString;
2406 /* Generate the regular expression to use. Something along the lines of:
2407 * ^(?=.*?\bone\b)(?=.*?\btwo\b)(?=.*?\bthree\b).*$
2409 asSearch = bRegex ? sSearch.split( ' ' ) : _fnEscapeRegex( sSearch ).split( ' ' );
2410 sRegExpString = '^(?=.*?'+asSearch.join( ')(?=.*?' )+').*$';
2411 return new RegExp( sRegExpString, bCaseInsensitive ? "i" : "" );
2415 sSearch = bRegex ? sSearch : _fnEscapeRegex( sSearch );
2416 return new RegExp( sSearch, bCaseInsensitive ? "i" : "" );
2422 * Convert raw data into something that the user can search on
2423 * @param {string} sData data to be modified
2424 * @param {string} sType data type
2425 * @returns {string} search string
2426 * @memberof DataTable#oApi
2428 function _fnDataToSearch ( sData, sType )
2430 if ( typeof DataTable.ext.ofnSearch[sType] === "function" )
2432 return DataTable.ext.ofnSearch[sType]( sData );
2434 else if ( sData === null )
2438 else if ( sType == "html" )
2440 return sData.replace(/[\r\n]/g," ").replace( /<.*?>/g, "" );
2442 else if ( typeof sData === "string" )
2444 return sData.replace(/[\r\n]/g," ");
2451 * scape a string such that it can be used in a regular expression
2452 * @param {string} sVal string to escape
2453 * @returns {string} escaped string
2454 * @memberof DataTable#oApi
2456 function _fnEscapeRegex ( sVal )
2458 var acEscape = [ '/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\', '$', '^', '-' ];
2459 var reReplace = new RegExp( '(\\' + acEscape.join('|\\') + ')', 'g' );
2460 return sVal.replace(reReplace, '\\$1');
2465 * Generate the node required for the info display
2466 * @param {object} oSettings dataTables settings object
2467 * @returns {node} Information element
2468 * @memberof DataTable#oApi
2470 function _fnFeatureHtmlInfo ( oSettings )
2472 var nInfo = document.createElement( 'div' );
2473 nInfo.className = oSettings.oClasses.sInfo;
2475 /* Actions that are to be taken once only for this feature */
2476 if ( !oSettings.aanFeatures.i )
2478 /* Add draw callback */
2479 oSettings.aoDrawCallback.push( {
2480 "fn": _fnUpdateInfo,
2481 "sName": "information"
2485 nInfo.id = oSettings.sTableId+'_info';
2487 oSettings.nTable.setAttribute( 'aria-describedby', oSettings.sTableId+'_info' );
2494 * Update the information elements in the display
2495 * @param {object} oSettings dataTables settings object
2496 * @memberof DataTable#oApi
2498 function _fnUpdateInfo ( oSettings )
2500 /* Show information about the table */
2501 if ( !oSettings.oFeatures.bInfo || oSettings.aanFeatures.i.length === 0 )
2507 oLang = oSettings.oLanguage,
2508 iStart = oSettings._iDisplayStart+1,
2509 iEnd = oSettings.fnDisplayEnd(),
2510 iMax = oSettings.fnRecordsTotal(),
2511 iTotal = oSettings.fnRecordsDisplay(),
2516 /* Empty record set */
2517 sOut = oLang.sInfoEmpty;
2520 /* Normal record set */
2524 if ( iTotal != iMax )
2526 /* Record set after filtering */
2527 sOut += ' ' + oLang.sInfoFiltered;
2530 // Convert the macros
2531 sOut += oLang.sInfoPostFix;
2532 sOut = _fnInfoMacros( oSettings, sOut );
2534 if ( oLang.fnInfoCallback !== null )
2536 sOut = oLang.fnInfoCallback.call( oSettings.oInstance,
2537 oSettings, iStart, iEnd, iMax, iTotal, sOut );
2540 var n = oSettings.aanFeatures.i;
2541 for ( var i=0, iLen=n.length ; i<iLen ; i++ )
2543 $(n[i]).html( sOut );
2548 function _fnInfoMacros ( oSettings, str )
2551 iStart = oSettings._iDisplayStart+1,
2552 sStart = oSettings.fnFormatNumber( iStart ),
2553 iEnd = oSettings.fnDisplayEnd(),
2554 sEnd = oSettings.fnFormatNumber( iEnd ),
2555 iTotal = oSettings.fnRecordsDisplay(),
2556 sTotal = oSettings.fnFormatNumber( iTotal ),
2557 iMax = oSettings.fnRecordsTotal(),
2558 sMax = oSettings.fnFormatNumber( iMax );
2560 // When infinite scrolling, we are always starting at 1. _iDisplayStart is used only
2562 if ( oSettings.oScroll.bInfinite )
2564 sStart = oSettings.fnFormatNumber( 1 );
2568 replace(/_START_/g, sStart).
2569 replace(/_END_/g, sEnd).
2570 replace(/_TOTAL_/g, sTotal).
2571 replace(/_MAX_/g, sMax);
2577 * Draw the table for the first time, adding all required features
2578 * @param {object} oSettings dataTables settings object
2579 * @memberof DataTable#oApi
2581 function _fnInitialise ( oSettings )
2583 var i, iLen, iAjaxStart=oSettings.iInitDisplayStart;
2585 /* Ensure that the table data is fully initialised */
2586 if ( oSettings.bInitialised === false )
2588 setTimeout( function(){ _fnInitialise( oSettings ); }, 200 );
2592 /* Show the display HTML options */
2593 _fnAddOptionsHtml( oSettings );
2595 /* Build and draw the header / footer for the table */
2596 _fnBuildHead( oSettings );
2597 _fnDrawHead( oSettings, oSettings.aoHeader );
2598 if ( oSettings.nTFoot )
2600 _fnDrawHead( oSettings, oSettings.aoFooter );
2603 /* Okay to show that something is going on now */
2604 _fnProcessingDisplay( oSettings, true );
2606 /* Calculate sizes for columns */
2607 if ( oSettings.oFeatures.bAutoWidth )
2609 _fnCalculateColumnWidths( oSettings );
2612 for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
2614 if ( oSettings.aoColumns[i].sWidth !== null )
2616 oSettings.aoColumns[i].nTh.style.width = _fnStringToCss( oSettings.aoColumns[i].sWidth );
2620 /* If there is default sorting required - let's do it. The sort function will do the
2621 * drawing for us. Otherwise we draw the table regardless of the Ajax source - this allows
2622 * the table to look initialised for Ajax sourcing data (show 'loading' message possibly)
2624 if ( oSettings.oFeatures.bSort )
2626 _fnSort( oSettings );
2628 else if ( oSettings.oFeatures.bFilter )
2630 _fnFilterComplete( oSettings, oSettings.oPreviousSearch );
2634 oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
2635 _fnCalculateEnd( oSettings );
2636 _fnDraw( oSettings );
2639 /* if there is an ajax source load the data */
2640 if ( oSettings.sAjaxSource !== null && !oSettings.oFeatures.bServerSide )
2643 _fnServerParams( oSettings, aoData );
2644 oSettings.fnServerData.call( oSettings.oInstance, oSettings.sAjaxSource, aoData, function(json) {
2645 var aData = (oSettings.sAjaxDataProp !== "") ?
2646 _fnGetObjectDataFn( oSettings.sAjaxDataProp )(json) : json;
2648 /* Got the data - add it to the table */
2649 for ( i=0 ; i<aData.length ; i++ )
2651 _fnAddData( oSettings, aData[i] );
2654 /* Reset the init display for cookie saving. We've already done a filter, and
2655 * therefore cleared it before. So we need to make it appear 'fresh'
2657 oSettings.iInitDisplayStart = iAjaxStart;
2659 if ( oSettings.oFeatures.bSort )
2661 _fnSort( oSettings );
2665 oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
2666 _fnCalculateEnd( oSettings );
2667 _fnDraw( oSettings );
2670 _fnProcessingDisplay( oSettings, false );
2671 _fnInitComplete( oSettings, json );
2676 /* Server-side processing initialisation complete is done at the end of _fnDraw */
2677 if ( !oSettings.oFeatures.bServerSide )
2679 _fnProcessingDisplay( oSettings, false );
2680 _fnInitComplete( oSettings );
2686 * Draw the table for the first time, adding all required features
2687 * @param {object} oSettings dataTables settings object
2688 * @param {object} [json] JSON from the server that completed the table, if using Ajax source
2689 * with client-side processing (optional)
2690 * @memberof DataTable#oApi
2692 function _fnInitComplete ( oSettings, json )
2694 oSettings._bInitComplete = true;
2695 _fnCallbackFire( oSettings, 'aoInitComplete', 'init', [oSettings, json] );
2700 * Language compatibility - when certain options are given, and others aren't, we
2701 * need to duplicate the values over, in order to provide backwards compatibility
2702 * with older language files.
2703 * @param {object} oSettings dataTables settings object
2704 * @memberof DataTable#oApi
2706 function _fnLanguageCompat( oLanguage )
2708 var oDefaults = DataTable.defaults.oLanguage;
2710 /* Backwards compatibility - if there is no sEmptyTable given, then use the same as
2711 * sZeroRecords - assuming that is given.
2713 if ( !oLanguage.sEmptyTable && oLanguage.sZeroRecords &&
2714 oDefaults.sEmptyTable === "No data available in table" )
2716 _fnMap( oLanguage, oLanguage, 'sZeroRecords', 'sEmptyTable' );
2719 /* Likewise with loading records */
2720 if ( !oLanguage.sLoadingRecords && oLanguage.sZeroRecords &&
2721 oDefaults.sLoadingRecords === "Loading..." )
2723 _fnMap( oLanguage, oLanguage, 'sZeroRecords', 'sLoadingRecords' );
2730 * Generate the node required for user display length changing
2731 * @param {object} oSettings dataTables settings object
2732 * @returns {node} Display length feature node
2733 * @memberof DataTable#oApi
2735 function _fnFeatureHtmlLength ( oSettings )
2737 if ( oSettings.oScroll.bInfinite )
2742 /* This can be overruled by not using the _MENU_ var/macro in the language variable */
2743 var sName = 'name="'+oSettings.sTableId+'_length"';
2744 var sStdMenu = '<select size="1" '+sName+'>';
2746 var aLengthMenu = oSettings.aLengthMenu;
2748 if ( aLengthMenu.length == 2 && typeof aLengthMenu[0] === 'object' &&
2749 typeof aLengthMenu[1] === 'object' )
2751 for ( i=0, iLen=aLengthMenu[0].length ; i<iLen ; i++ )
2753 sStdMenu += '<option value="'+aLengthMenu[0][i]+'">'+aLengthMenu[1][i]+'</option>';
2758 for ( i=0, iLen=aLengthMenu.length ; i<iLen ; i++ )
2760 sStdMenu += '<option value="'+aLengthMenu[i]+'">'+aLengthMenu[i]+'</option>';
2763 sStdMenu += '</select>';
2765 var nLength = document.createElement( 'div' );
2766 if ( !oSettings.aanFeatures.l )
2768 nLength.id = oSettings.sTableId+'_length';
2770 nLength.className = oSettings.oClasses.sLength;
2771 nLength.innerHTML = '<label>'+oSettings.oLanguage.sLengthMenu.replace( '_MENU_', sStdMenu )+'</label>';
2774 * Set the length to the current display length - thanks to Andrea Pavlovic for this fix,
2775 * and Stefan Skopnik for fixing the fix!
2777 $('select option[value="'+oSettings._iDisplayLength+'"]', nLength).attr("selected", true);
2779 $('select', nLength).bind( 'change.DT', function(e) {
2780 var iVal = $(this).val();
2782 /* Update all other length options for the new display */
2783 var n = oSettings.aanFeatures.l;
2784 for ( i=0, iLen=n.length ; i<iLen ; i++ )
2786 if ( n[i] != this.parentNode )
2788 $('select', n[i]).val( iVal );
2792 /* Redraw the table */
2793 oSettings._iDisplayLength = parseInt(iVal, 10);
2794 _fnCalculateEnd( oSettings );
2796 /* If we have space to show extra rows (backing up from the end point - then do so */
2797 if ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() )
2799 oSettings._iDisplayStart = oSettings.fnDisplayEnd() - oSettings._iDisplayLength;
2800 if ( oSettings._iDisplayStart < 0 )
2802 oSettings._iDisplayStart = 0;
2806 if ( oSettings._iDisplayLength == -1 )
2808 oSettings._iDisplayStart = 0;
2811 _fnDraw( oSettings );
2815 $('select', nLength).attr('aria-controls', oSettings.sTableId);
2822 * Recalculate the end point based on the start point
2823 * @param {object} oSettings dataTables settings object
2824 * @memberof DataTable#oApi
2826 function _fnCalculateEnd( oSettings )
2828 if ( oSettings.oFeatures.bPaginate === false )
2830 oSettings._iDisplayEnd = oSettings.aiDisplay.length;
2834 /* Set the end point of the display - based on how many elements there are
2837 if ( oSettings._iDisplayStart + oSettings._iDisplayLength > oSettings.aiDisplay.length ||
2838 oSettings._iDisplayLength == -1 )
2840 oSettings._iDisplayEnd = oSettings.aiDisplay.length;
2844 oSettings._iDisplayEnd = oSettings._iDisplayStart + oSettings._iDisplayLength;
2851 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2852 * Note that most of the paging logic is done in
2853 * DataTable.ext.oPagination
2857 * Generate the node required for default pagination
2858 * @param {object} oSettings dataTables settings object
2859 * @returns {node} Pagination feature node
2860 * @memberof DataTable#oApi
2862 function _fnFeatureHtmlPaginate ( oSettings )
2864 if ( oSettings.oScroll.bInfinite )
2869 var nPaginate = document.createElement( 'div' );
2870 nPaginate.className = oSettings.oClasses.sPaging+oSettings.sPaginationType;
2872 DataTable.ext.oPagination[ oSettings.sPaginationType ].fnInit( oSettings, nPaginate,
2873 function( oSettings ) {
2874 _fnCalculateEnd( oSettings );
2875 _fnDraw( oSettings );
2879 /* Add a draw callback for the pagination on first instance, to update the paging display */
2880 if ( !oSettings.aanFeatures.p )
2882 oSettings.aoDrawCallback.push( {
2883 "fn": function( oSettings ) {
2884 DataTable.ext.oPagination[ oSettings.sPaginationType ].fnUpdate( oSettings, function( oSettings ) {
2885 _fnCalculateEnd( oSettings );
2886 _fnDraw( oSettings );
2889 "sName": "pagination"
2897 * Alter the display settings to change the page
2898 * @param {object} oSettings dataTables settings object
2899 * @param {string|int} mAction Paging action to take: "first", "previous", "next" or "last"
2900 * or page number to jump to (integer)
2901 * @returns {bool} true page has changed, false - no change (no effect) eg 'first' on page 1
2902 * @memberof DataTable#oApi
2904 function _fnPageChange ( oSettings, mAction )
2906 var iOldStart = oSettings._iDisplayStart;
2908 if ( typeof mAction === "number" )
2910 oSettings._iDisplayStart = mAction * oSettings._iDisplayLength;
2911 if ( oSettings._iDisplayStart > oSettings.fnRecordsDisplay() )
2913 oSettings._iDisplayStart = 0;
2916 else if ( mAction == "first" )
2918 oSettings._iDisplayStart = 0;
2920 else if ( mAction == "previous" )
2922 oSettings._iDisplayStart = oSettings._iDisplayLength>=0 ?
2923 oSettings._iDisplayStart - oSettings._iDisplayLength :
2926 /* Correct for under-run */
2927 if ( oSettings._iDisplayStart < 0 )
2929 oSettings._iDisplayStart = 0;
2932 else if ( mAction == "next" )
2934 if ( oSettings._iDisplayLength >= 0 )
2936 /* Make sure we are not over running the display array */
2937 if ( oSettings._iDisplayStart + oSettings._iDisplayLength < oSettings.fnRecordsDisplay() )
2939 oSettings._iDisplayStart += oSettings._iDisplayLength;
2944 oSettings._iDisplayStart = 0;
2947 else if ( mAction == "last" )
2949 if ( oSettings._iDisplayLength >= 0 )
2951 var iPages = parseInt( (oSettings.fnRecordsDisplay()-1) / oSettings._iDisplayLength, 10 ) + 1;
2952 oSettings._iDisplayStart = (iPages-1) * oSettings._iDisplayLength;
2956 oSettings._iDisplayStart = 0;
2961 _fnLog( oSettings, 0, "Unknown paging action: "+mAction );
2963 $(oSettings.oInstance).trigger('page', oSettings);
2965 return iOldStart != oSettings._iDisplayStart;
2971 * Generate the node required for the processing node
2972 * @param {object} oSettings dataTables settings object
2973 * @returns {node} Processing element
2974 * @memberof DataTable#oApi
2976 function _fnFeatureHtmlProcessing ( oSettings )
2978 var nProcessing = document.createElement( 'div' );
2980 if ( !oSettings.aanFeatures.r )
2982 nProcessing.id = oSettings.sTableId+'_processing';
2984 nProcessing.innerHTML = oSettings.oLanguage.sProcessing;
2985 nProcessing.className = oSettings.oClasses.sProcessing;
2986 oSettings.nTable.parentNode.insertBefore( nProcessing, oSettings.nTable );
2993 * Display or hide the processing indicator
2994 * @param {object} oSettings dataTables settings object
2995 * @param {bool} bShow Show the processing indicator (true) or not (false)
2996 * @memberof DataTable#oApi
2998 function _fnProcessingDisplay ( oSettings, bShow )
3000 if ( oSettings.oFeatures.bProcessing )
3002 var an = oSettings.aanFeatures.r;
3003 for ( var i=0, iLen=an.length ; i<iLen ; i++ )
3005 an[i].style.visibility = bShow ? "visible" : "hidden";
3009 $(oSettings.oInstance).trigger('processing', [oSettings, bShow]);
3013 * Add any control elements for the table - specifically scrolling
3014 * @param {object} oSettings dataTables settings object
3015 * @returns {node} Node to add to the DOM
3016 * @memberof DataTable#oApi
3018 function _fnFeatureHtmlTable ( oSettings )
3020 /* Check if scrolling is enabled or not - if not then leave the DOM unaltered */
3021 if ( oSettings.oScroll.sX === "" && oSettings.oScroll.sY === "" )
3023 return oSettings.nTable;
3027 * The HTML structure that we want to generate in this function is:
3030 * div - nScrollHeadInner
3031 * table - nScrollHeadTable
3034 * table - oSettings.nTable
3035 * thead - nTheadSize
3038 * div - nScrollFootInner
3039 * table - nScrollFootTable
3043 nScroller = document.createElement('div'),
3044 nScrollHead = document.createElement('div'),
3045 nScrollHeadInner = document.createElement('div'),
3046 nScrollBody = document.createElement('div'),
3047 nScrollFoot = document.createElement('div'),
3048 nScrollFootInner = document.createElement('div'),
3049 nScrollHeadTable = oSettings.nTable.cloneNode(false),
3050 nScrollFootTable = oSettings.nTable.cloneNode(false),
3051 nThead = oSettings.nTable.getElementsByTagName('thead')[0],
3052 nTfoot = oSettings.nTable.getElementsByTagName('tfoot').length === 0 ? null :
3053 oSettings.nTable.getElementsByTagName('tfoot')[0],
3054 oClasses = oSettings.oClasses;
3056 nScrollHead.appendChild( nScrollHeadInner );
3057 nScrollFoot.appendChild( nScrollFootInner );
3058 nScrollBody.appendChild( oSettings.nTable );
3059 nScroller.appendChild( nScrollHead );
3060 nScroller.appendChild( nScrollBody );
3061 nScrollHeadInner.appendChild( nScrollHeadTable );
3062 nScrollHeadTable.appendChild( nThead );
3063 if ( nTfoot !== null )
3065 nScroller.appendChild( nScrollFoot );
3066 nScrollFootInner.appendChild( nScrollFootTable );
3067 nScrollFootTable.appendChild( nTfoot );
3070 nScroller.className = oClasses.sScrollWrapper;
3071 nScrollHead.className = oClasses.sScrollHead;
3072 nScrollHeadInner.className = oClasses.sScrollHeadInner;
3073 nScrollBody.className = oClasses.sScrollBody;
3074 nScrollFoot.className = oClasses.sScrollFoot;
3075 nScrollFootInner.className = oClasses.sScrollFootInner;
3077 if ( oSettings.oScroll.bAutoCss )
3079 nScrollHead.style.overflow = "hidden";
3080 nScrollHead.style.position = "relative";
3081 nScrollFoot.style.overflow = "hidden";
3082 nScrollBody.style.overflow = "auto";
3085 nScrollHead.style.border = "0";
3086 nScrollHead.style.width = "100%";
3087 nScrollFoot.style.border = "0";
3088 nScrollHeadInner.style.width = oSettings.oScroll.sXInner !== "" ?
3089 oSettings.oScroll.sXInner : "100%"; /* will be overwritten */
3091 /* Modify attributes to respect the clones */
3092 nScrollHeadTable.removeAttribute('id');
3093 nScrollHeadTable.style.marginLeft = "0";
3094 oSettings.nTable.style.marginLeft = "0";
3095 if ( nTfoot !== null )
3097 nScrollFootTable.removeAttribute('id');
3098 nScrollFootTable.style.marginLeft = "0";
3101 /* Move caption elements from the body to the header, footer or leave where it is
3102 * depending on the configuration. Note that the DTD says there can be only one caption */
3103 var nCaption = $(oSettings.nTable).children('caption');
3104 if ( nCaption.length > 0 )
3106 nCaption = nCaption[0];
3107 if ( nCaption._captionSide === "top" )
3109 nScrollHeadTable.appendChild( nCaption );
3111 else if ( nCaption._captionSide === "bottom" && nTfoot )
3113 nScrollFootTable.appendChild( nCaption );
3120 /* When x-scrolling add the width and a scroller to move the header with the body */
3121 if ( oSettings.oScroll.sX !== "" )
3123 nScrollHead.style.width = _fnStringToCss( oSettings.oScroll.sX );
3124 nScrollBody.style.width = _fnStringToCss( oSettings.oScroll.sX );
3126 if ( nTfoot !== null )
3128 nScrollFoot.style.width = _fnStringToCss( oSettings.oScroll.sX );
3131 /* When the body is scrolled, then we also want to scroll the headers */
3132 $(nScrollBody).scroll( function (e) {
3133 nScrollHead.scrollLeft = this.scrollLeft;
3135 if ( nTfoot !== null )
3137 nScrollFoot.scrollLeft = this.scrollLeft;
3142 /* When yscrolling, add the height */
3143 if ( oSettings.oScroll.sY !== "" )
3145 nScrollBody.style.height = _fnStringToCss( oSettings.oScroll.sY );
3148 /* Redraw - align columns across the tables */
3149 oSettings.aoDrawCallback.push( {
3150 "fn": _fnScrollDraw,
3151 "sName": "scrolling"
3154 /* Infinite scrolling event handlers */
3155 if ( oSettings.oScroll.bInfinite )
3157 $(nScrollBody).scroll( function() {
3158 /* Use a blocker to stop scrolling from loading more data while other data is still loading */
3159 if ( !oSettings.bDrawing && $(this).scrollTop() !== 0 )
3161 /* Check if we should load the next data set */
3162 if ( $(this).scrollTop() + $(this).height() >
3163 $(oSettings.nTable).height() - oSettings.oScroll.iLoadGap )
3165 /* Only do the redraw if we have to - we might be at the end of the data */
3166 if ( oSettings.fnDisplayEnd() < oSettings.fnRecordsDisplay() )
3168 _fnPageChange( oSettings, 'next' );
3169 _fnCalculateEnd( oSettings );
3170 _fnDraw( oSettings );
3177 oSettings.nScrollHead = nScrollHead;
3178 oSettings.nScrollFoot = nScrollFoot;
3185 * Update the various tables for resizing. It's a bit of a pig this function, but
3186 * basically the idea to:
3187 * 1. Re-create the table inside the scrolling div
3188 * 2. Take live measurements from the DOM
3189 * 3. Apply the measurements
3191 * @param {object} o dataTables settings object
3192 * @returns {node} Node to add to the DOM
3193 * @memberof DataTable#oApi
3195 function _fnScrollDraw ( o )
3198 nScrollHeadInner = o.nScrollHead.getElementsByTagName('div')[0],
3199 nScrollHeadTable = nScrollHeadInner.getElementsByTagName('table')[0],
3200 nScrollBody = o.nTable.parentNode,
3201 i, iLen, j, jLen, anHeadToSize, anHeadSizers, anFootSizers, anFootToSize, oStyle, iVis,
3202 nTheadSize, nTfootSize,
3203 iWidth, aApplied=[], aAppliedFooter=[], iSanityWidth,
3204 nScrollFootInner = (o.nTFoot !== null) ? o.nScrollFoot.getElementsByTagName('div')[0] : null,
3205 nScrollFootTable = (o.nTFoot !== null) ? nScrollFootInner.getElementsByTagName('table')[0] : null,
3206 ie67 = o.oBrowser.bScrollOversize,
3207 zeroOut = function(nSizer) {
3208 oStyle = nSizer.style;
3209 oStyle.paddingTop = "0";
3210 oStyle.paddingBottom = "0";
3211 oStyle.borderTopWidth = "0";
3212 oStyle.borderBottomWidth = "0";
3217 * 1. Re-create the table inside the scrolling div
3220 /* Remove the old minimised thead and tfoot elements in the inner table */
3221 $(o.nTable).children('thead, tfoot').remove();
3223 /* Clone the current header and footer elements and then place it into the inner table */
3224 nTheadSize = $(o.nTHead).clone()[0];
3225 o.nTable.insertBefore( nTheadSize, o.nTable.childNodes[0] );
3226 anHeadToSize = o.nTHead.getElementsByTagName('tr');
3227 anHeadSizers = nTheadSize.getElementsByTagName('tr');
3229 if ( o.nTFoot !== null )
3231 nTfootSize = $(o.nTFoot).clone()[0];
3232 o.nTable.insertBefore( nTfootSize, o.nTable.childNodes[1] );
3233 anFootToSize = o.nTFoot.getElementsByTagName('tr');
3234 anFootSizers = nTfootSize.getElementsByTagName('tr');
3238 * 2. Take live measurements from the DOM - do not alter the DOM itself!
3241 /* Remove old sizing and apply the calculated column widths
3242 * Get the unique column headers in the newly created (cloned) header. We want to apply the
3243 * calculated sizes to this header
3245 if ( o.oScroll.sX === "" )
3247 nScrollBody.style.width = '100%';
3248 nScrollHeadInner.parentNode.style.width = '100%';
3251 var nThs = _fnGetUniqueThs( o, nTheadSize );
3252 for ( i=0, iLen=nThs.length ; i<iLen ; i++ )
3254 iVis = _fnVisibleToColumnIndex( o, i );
3255 nThs[i].style.width = o.aoColumns[iVis].sWidth;
3258 if ( o.nTFoot !== null )
3260 _fnApplyToChildren( function(n) {
3265 // If scroll collapse is enabled, when we put the headers back into the body for sizing, we
3266 // will end up forcing the scrollbar to appear, making our measurements wrong for when we
3267 // then hide it (end of this function), so add the header height to the body scroller.
3268 if ( o.oScroll.bCollapse && o.oScroll.sY !== "" )
3270 nScrollBody.style.height = (nScrollBody.offsetHeight + o.nTHead.offsetHeight)+"px";
3273 /* Size the table as a whole */
3274 iSanityWidth = $(o.nTable).outerWidth();
3275 if ( o.oScroll.sX === "" )
3277 /* No x scrolling */
3278 o.nTable.style.width = "100%";
3280 /* I know this is rubbish - but IE7 will make the width of the table when 100% include
3281 * the scrollbar - which is shouldn't. When there is a scrollbar we need to take this
3284 if ( ie67 && ($('tbody', nScrollBody).height() > nScrollBody.offsetHeight ||
3285 $(nScrollBody).css('overflow-y') == "scroll") )
3287 o.nTable.style.width = _fnStringToCss( $(o.nTable).outerWidth() - o.oScroll.iBarWidth);
3292 if ( o.oScroll.sXInner !== "" )
3294 /* x scroll inner has been given - use it */
3295 o.nTable.style.width = _fnStringToCss(o.oScroll.sXInner);
3297 else if ( iSanityWidth == $(nScrollBody).width() &&
3298 $(nScrollBody).height() < $(o.nTable).height() )
3300 /* There is y-scrolling - try to take account of the y scroll bar */
3301 o.nTable.style.width = _fnStringToCss( iSanityWidth-o.oScroll.iBarWidth );
3302 if ( $(o.nTable).outerWidth() > iSanityWidth-o.oScroll.iBarWidth )
3304 /* Not possible to take account of it */
3305 o.nTable.style.width = _fnStringToCss( iSanityWidth );
3310 /* All else fails */
3311 o.nTable.style.width = _fnStringToCss( iSanityWidth );
3315 /* Recalculate the sanity width - now that we've applied the required width, before it was
3316 * a temporary variable. This is required because the column width calculation is done
3317 * before this table DOM is created.
3319 iSanityWidth = $(o.nTable).outerWidth();
3321 /* We want the hidden header to have zero height, so remove padding and borders. Then
3322 * set the width based on the real headers
3325 // Apply all styles in one pass. Invalidates layout only once because we don't read any
3327 _fnApplyToChildren( zeroOut, anHeadSizers );
3329 // Read all widths in next pass. Forces layout only once because we do not change
3330 // any DOM properties.
3331 _fnApplyToChildren( function(nSizer) {
3332 aApplied.push( _fnStringToCss( $(nSizer).width() ) );
3335 // Apply all widths in final pass. Invalidates layout only once because we do not
3336 // read any DOM properties.
3337 _fnApplyToChildren( function(nToSize, i) {
3338 nToSize.style.width = aApplied[i];
3341 $(anHeadSizers).height(0);
3343 /* Same again with the footer if we have one */
3344 if ( o.nTFoot !== null )
3346 _fnApplyToChildren( zeroOut, anFootSizers );
3348 _fnApplyToChildren( function(nSizer) {
3349 aAppliedFooter.push( _fnStringToCss( $(nSizer).width() ) );
3352 _fnApplyToChildren( function(nToSize, i) {
3353 nToSize.style.width = aAppliedFooter[i];
3356 $(anFootSizers).height(0);
3360 * 3. Apply the measurements
3363 /* "Hide" the header and footer that we used for the sizing. We want to also fix their width
3364 * to what they currently are
3366 _fnApplyToChildren( function(nSizer, i) {
3367 nSizer.innerHTML = "";
3368 nSizer.style.width = aApplied[i];
3371 if ( o.nTFoot !== null )
3373 _fnApplyToChildren( function(nSizer, i) {
3374 nSizer.innerHTML = "";
3375 nSizer.style.width = aAppliedFooter[i];
3379 /* Sanity check that the table is of a sensible width. If not then we are going to get
3380 * misalignment - try to prevent this by not allowing the table to shrink below its min width
3382 if ( $(o.nTable).outerWidth() < iSanityWidth )
3384 /* The min width depends upon if we have a vertical scrollbar visible or not */
3385 var iCorrection = ((nScrollBody.scrollHeight > nScrollBody.offsetHeight ||
3386 $(nScrollBody).css('overflow-y') == "scroll")) ?
3387 iSanityWidth+o.oScroll.iBarWidth : iSanityWidth;
3389 /* IE6/7 are a law unto themselves... */
3390 if ( ie67 && (nScrollBody.scrollHeight >
3391 nScrollBody.offsetHeight || $(nScrollBody).css('overflow-y') == "scroll") )
3393 o.nTable.style.width = _fnStringToCss( iCorrection-o.oScroll.iBarWidth );
3396 /* Apply the calculated minimum width to the table wrappers */
3397 nScrollBody.style.width = _fnStringToCss( iCorrection );
3398 o.nScrollHead.style.width = _fnStringToCss( iCorrection );
3400 if ( o.nTFoot !== null )
3402 o.nScrollFoot.style.width = _fnStringToCss( iCorrection );
3405 /* And give the user a warning that we've stopped the table getting too small */
3406 if ( o.oScroll.sX === "" )
3408 _fnLog( o, 1, "The table cannot fit into the current element which will cause column"+
3409 " misalignment. The table has been drawn at its minimum possible width." );
3411 else if ( o.oScroll.sXInner !== "" )
3413 _fnLog( o, 1, "The table cannot fit into the current element which will cause column"+
3414 " misalignment. Increase the sScrollXInner value or remove it to allow automatic"+
3420 nScrollBody.style.width = _fnStringToCss( '100%' );
3421 o.nScrollHead.style.width = _fnStringToCss( '100%' );
3423 if ( o.nTFoot !== null )
3425 o.nScrollFoot.style.width = _fnStringToCss( '100%' );
3433 if ( o.oScroll.sY === "" )
3435 /* IE7< puts a vertical scrollbar in place (when it shouldn't be) due to subtracting
3436 * the scrollbar height from the visible display, rather than adding it on. We need to
3437 * set the height in order to sort this. Don't want to do it in any other browsers.
3441 nScrollBody.style.height = _fnStringToCss( o.nTable.offsetHeight+o.oScroll.iBarWidth );
3445 if ( o.oScroll.sY !== "" && o.oScroll.bCollapse )
3447 nScrollBody.style.height = _fnStringToCss( o.oScroll.sY );
3449 var iExtra = (o.oScroll.sX !== "" && o.nTable.offsetWidth > nScrollBody.offsetWidth) ?
3450 o.oScroll.iBarWidth : 0;
3451 if ( o.nTable.offsetHeight < nScrollBody.offsetHeight )
3453 nScrollBody.style.height = _fnStringToCss( o.nTable.offsetHeight+iExtra );
3457 /* Finally set the width's of the header and footer tables */
3458 var iOuterWidth = $(o.nTable).outerWidth();
3459 nScrollHeadTable.style.width = _fnStringToCss( iOuterWidth );
3460 nScrollHeadInner.style.width = _fnStringToCss( iOuterWidth );
3462 // Figure out if there are scrollbar present - if so then we need a the header and footer to
3463 // provide a bit more space to allow "overflow" scrolling (i.e. past the scrollbar)
3464 var bScrolling = $(o.nTable).height() > nScrollBody.clientHeight || $(nScrollBody).css('overflow-y') == "scroll";
3465 nScrollHeadInner.style.paddingRight = bScrolling ? o.oScroll.iBarWidth+"px" : "0px";
3467 if ( o.nTFoot !== null )
3469 nScrollFootTable.style.width = _fnStringToCss( iOuterWidth );
3470 nScrollFootInner.style.width = _fnStringToCss( iOuterWidth );
3471 nScrollFootInner.style.paddingRight = bScrolling ? o.oScroll.iBarWidth+"px" : "0px";
3474 /* Adjust the position of the header in case we loose the y-scrollbar */
3475 $(nScrollBody).scroll();
3477 /* If sorting or filtering has occurred, jump the scrolling back to the top */
3478 if ( o.bSorted || o.bFiltered )
3480 nScrollBody.scrollTop = 0;
3486 * Apply a given function to the display child nodes of an element array (typically
3487 * TD children of TR rows
3488 * @param {function} fn Method to apply to the objects
3489 * @param array {nodes} an1 List of elements to look through for display children
3490 * @param array {nodes} an2 Another list (identical structure to the first) - optional
3491 * @memberof DataTable#oApi
3493 function _fnApplyToChildren( fn, an1, an2 )
3495 var index=0, i=0, iLen=an1.length;
3500 nNode1 = an1[i].firstChild;
3501 nNode2 = an2 ? an2[i].firstChild : null;
3504 if ( nNode1.nodeType === 1 )
3508 fn( nNode1, nNode2, index );
3512 fn( nNode1, index );
3516 nNode1 = nNode1.nextSibling;
3517 nNode2 = an2 ? nNode2.nextSibling : null;
3524 * Convert a CSS unit width to pixels (e.g. 2em)
3525 * @param {string} sWidth width to be converted
3526 * @param {node} nParent parent to get the with for (required for relative widths) - optional
3527 * @returns {int} iWidth width in pixels
3528 * @memberof DataTable#oApi
3530 function _fnConvertToWidth ( sWidth, nParent )
3532 if ( !sWidth || sWidth === null || sWidth === '' )
3539 nParent = document.body;
3543 var nTmp = document.createElement( "div" );
3544 nTmp.style.width = _fnStringToCss( sWidth );
3546 nParent.appendChild( nTmp );
3547 iWidth = nTmp.offsetWidth;
3548 nParent.removeChild( nTmp );
3555 * Calculate the width of columns for the table
3556 * @param {object} oSettings dataTables settings object
3557 * @memberof DataTable#oApi
3559 function _fnCalculateColumnWidths ( oSettings )
3561 var iTableWidth = oSettings.nTable.offsetWidth;
3562 var iUserInputs = 0;
3564 var iVisibleColumns = 0;
3565 var iColums = oSettings.aoColumns.length;
3566 var i, iIndex, iCorrector, iWidth;
3567 var oHeaders = $('th', oSettings.nTHead);
3568 var widthAttr = oSettings.nTable.getAttribute('width');
3569 var nWrapper = oSettings.nTable.parentNode;
3571 /* Convert any user input sizes into pixel sizes */
3572 for ( i=0 ; i<iColums ; i++ )
3574 if ( oSettings.aoColumns[i].bVisible )
3578 if ( oSettings.aoColumns[i].sWidth !== null )
3580 iTmpWidth = _fnConvertToWidth( oSettings.aoColumns[i].sWidthOrig,
3582 if ( iTmpWidth !== null )
3584 oSettings.aoColumns[i].sWidth = _fnStringToCss( iTmpWidth );
3592 /* If the number of columns in the DOM equals the number that we have to process in
3593 * DataTables, then we can use the offsets that are created by the web-browser. No custom
3594 * sizes can be set in order for this to happen, nor scrolling used
3596 if ( iColums == oHeaders.length && iUserInputs === 0 && iVisibleColumns == iColums &&
3597 oSettings.oScroll.sX === "" && oSettings.oScroll.sY === "" )
3599 for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
3601 iTmpWidth = $(oHeaders[i]).width();
3602 if ( iTmpWidth !== null )
3604 oSettings.aoColumns[i].sWidth = _fnStringToCss( iTmpWidth );
3610 /* Otherwise we are going to have to do some calculations to get the width of each column.
3611 * Construct a 1 row table with the widest node in the data, and any user defined widths,
3612 * then insert it into the DOM and allow the browser to do all the hard work of
3613 * calculating table widths.
3616 nCalcTmp = oSettings.nTable.cloneNode( false ),
3617 nTheadClone = oSettings.nTHead.cloneNode(true),
3618 nBody = document.createElement( 'tbody' ),
3619 nTr = document.createElement( 'tr' ),
3622 nCalcTmp.removeAttribute( "id" );
3623 nCalcTmp.appendChild( nTheadClone );
3624 if ( oSettings.nTFoot !== null )
3626 nCalcTmp.appendChild( oSettings.nTFoot.cloneNode(true) );
3627 _fnApplyToChildren( function(n) {
3629 }, nCalcTmp.getElementsByTagName('tr') );
3632 nCalcTmp.appendChild( nBody );
3633 nBody.appendChild( nTr );
3635 /* Remove any sizing that was previously applied by the styles */
3636 var jqColSizing = $('thead th', nCalcTmp);
3637 if ( jqColSizing.length === 0 )
3639 jqColSizing = $('tbody tr:eq(0)>td', nCalcTmp);
3642 /* Apply custom sizing to the cloned header */
3643 var nThs = _fnGetUniqueThs( oSettings, nTheadClone );
3645 for ( i=0 ; i<iColums ; i++ )
3647 var oColumn = oSettings.aoColumns[i];
3648 if ( oColumn.bVisible && oColumn.sWidthOrig !== null && oColumn.sWidthOrig !== "" )
3650 nThs[i-iCorrector].style.width = _fnStringToCss( oColumn.sWidthOrig );
3652 else if ( oColumn.bVisible )
3654 nThs[i-iCorrector].style.width = "";
3662 /* Find the biggest td for each column and put it into the table */
3663 for ( i=0 ; i<iColums ; i++ )
3665 if ( oSettings.aoColumns[i].bVisible )
3667 var nTd = _fnGetWidestNode( oSettings, i );
3670 nTd = nTd.cloneNode(true);
3671 if ( oSettings.aoColumns[i].sContentPadding !== "" )
3673 nTd.innerHTML += oSettings.aoColumns[i].sContentPadding;
3675 nTr.appendChild( nTd );
3680 /* Build the table and 'display' it */
3681 nWrapper.appendChild( nCalcTmp );
3683 /* When scrolling (X or Y) we want to set the width of the table as appropriate. However,
3684 * when not scrolling leave the table width as it is. This results in slightly different,
3685 * but I think correct behaviour
3687 if ( oSettings.oScroll.sX !== "" && oSettings.oScroll.sXInner !== "" )
3689 nCalcTmp.style.width = _fnStringToCss(oSettings.oScroll.sXInner);
3691 else if ( oSettings.oScroll.sX !== "" )
3693 nCalcTmp.style.width = "";
3694 if ( $(nCalcTmp).width() < nWrapper.offsetWidth )
3696 nCalcTmp.style.width = _fnStringToCss( nWrapper.offsetWidth );
3699 else if ( oSettings.oScroll.sY !== "" )
3701 nCalcTmp.style.width = _fnStringToCss( nWrapper.offsetWidth );
3703 else if ( widthAttr )
3705 nCalcTmp.style.width = _fnStringToCss( widthAttr );
3707 nCalcTmp.style.visibility = "hidden";
3709 /* Scrolling considerations */
3710 _fnScrollingWidthAdjust( oSettings, nCalcTmp );
3712 /* Read the width's calculated by the browser and store them for use by the caller. We
3713 * first of all try to use the elements in the body, but it is possible that there are
3714 * no elements there, under which circumstances we use the header elements
3716 var oNodes = $("tbody tr:eq(0)", nCalcTmp).children();
3717 if ( oNodes.length === 0 )
3719 oNodes = _fnGetUniqueThs( oSettings, $('thead', nCalcTmp)[0] );
3722 /* Browsers need a bit of a hand when a width is assigned to any columns when
3723 * x-scrolling as they tend to collapse the table to the min-width, even if
3724 * we sent the column widths. So we need to keep track of what the table width
3725 * should be by summing the user given values, and the automatic values
3727 if ( oSettings.oScroll.sX !== "" )
3731 for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
3733 if ( oSettings.aoColumns[i].bVisible )
3735 if ( oSettings.aoColumns[i].sWidthOrig === null )
3737 iTotal += $(oNodes[iCorrector]).outerWidth();
3741 iTotal += parseInt(oSettings.aoColumns[i].sWidth.replace('px',''), 10) +
3742 ($(oNodes[iCorrector]).outerWidth() - $(oNodes[iCorrector]).width());
3748 nCalcTmp.style.width = _fnStringToCss( iTotal );
3749 oSettings.nTable.style.width = _fnStringToCss( iTotal );
3753 for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
3755 if ( oSettings.aoColumns[i].bVisible )
3757 iWidth = $(oNodes[iCorrector]).width();
3758 if ( iWidth !== null && iWidth > 0 )
3760 oSettings.aoColumns[i].sWidth = _fnStringToCss( iWidth );
3766 var cssWidth = $(nCalcTmp).css('width');
3767 oSettings.nTable.style.width = (cssWidth.indexOf('%') !== -1) ?
3768 cssWidth : _fnStringToCss( $(nCalcTmp).outerWidth() );
3769 nCalcTmp.parentNode.removeChild( nCalcTmp );
3774 oSettings.nTable.style.width = _fnStringToCss( widthAttr );
3780 * Adjust a table's width to take account of scrolling
3781 * @param {object} oSettings dataTables settings object
3782 * @param {node} n table node
3783 * @memberof DataTable#oApi
3785 function _fnScrollingWidthAdjust ( oSettings, n )
3787 if ( oSettings.oScroll.sX === "" && oSettings.oScroll.sY !== "" )
3789 /* When y-scrolling only, we want to remove the width of the scroll bar so the table
3790 * + scroll bar will fit into the area avaialble.
3792 var iOrigWidth = $(n).width();
3793 n.style.width = _fnStringToCss( $(n).outerWidth()-oSettings.oScroll.iBarWidth );
3795 else if ( oSettings.oScroll.sX !== "" )
3797 /* When x-scrolling both ways, fix the table at it's current size, without adjusting */
3798 n.style.width = _fnStringToCss( $(n).outerWidth() );
3804 * Get the widest node
3805 * @param {object} oSettings dataTables settings object
3806 * @param {int} iCol column of interest
3807 * @returns {node} widest table node
3808 * @memberof DataTable#oApi
3810 function _fnGetWidestNode( oSettings, iCol )
3812 var iMaxIndex = _fnGetMaxLenString( oSettings, iCol );
3813 if ( iMaxIndex < 0 )
3818 if ( oSettings.aoData[iMaxIndex].nTr === null )
3820 var n = document.createElement('td');
3821 n.innerHTML = _fnGetCellData( oSettings, iMaxIndex, iCol, '' );
3824 return _fnGetTdNodes(oSettings, iMaxIndex)[iCol];
3829 * Get the maximum strlen for each data column
3830 * @param {object} oSettings dataTables settings object
3831 * @param {int} iCol column of interest
3832 * @returns {string} max string length for each column
3833 * @memberof DataTable#oApi
3835 function _fnGetMaxLenString( oSettings, iCol )
3840 for ( var i=0 ; i<oSettings.aoData.length ; i++ )
3842 var s = _fnGetCellData( oSettings, i, iCol, 'display' )+"";
3843 s = s.replace( /<.*?>/g, "" );
3844 if ( s.length > iMax )
3856 * Append a CSS unit (only if required) to a string
3857 * @param {array} aArray1 first array
3858 * @param {array} aArray2 second array
3859 * @returns {int} 0 if match, 1 if length is different, 2 if no match
3860 * @memberof DataTable#oApi
3862 function _fnStringToCss( s )
3869 if ( typeof s == 'number' )
3878 /* Check if the last character is not 0-9 */
3879 var c = s.charCodeAt( s.length-1 );
3880 if (c < 0x30 || c > 0x39)
3889 * Get the width of a scroll bar in this browser being used
3890 * @returns {int} width in pixels
3891 * @memberof DataTable#oApi
3893 function _fnScrollBarWidth ()
3895 var inner = document.createElement('p');
3896 var style = inner.style;
3897 style.width = "100%";
3898 style.height = "200px";
3899 style.padding = "0px";
3901 var outer = document.createElement('div');
3902 style = outer.style;
3903 style.position = "absolute";
3906 style.visibility = "hidden";
3907 style.width = "200px";
3908 style.height = "150px";
3909 style.padding = "0px";
3910 style.overflow = "hidden";
3911 outer.appendChild(inner);
3913 document.body.appendChild(outer);
3914 var w1 = inner.offsetWidth;
3915 outer.style.overflow = 'scroll';
3916 var w2 = inner.offsetWidth;
3919 w2 = outer.clientWidth;
3922 document.body.removeChild(outer);
3927 * Change the order of the table
3928 * @param {object} oSettings dataTables settings object
3929 * @param {bool} bApplyClasses optional - should we apply classes or not
3930 * @memberof DataTable#oApi
3932 function _fnSort ( oSettings, bApplyClasses )
3935 i, iLen, j, jLen, k, kLen,
3939 oSort = DataTable.ext.oSort,
3940 aoData = oSettings.aoData,
3941 aoColumns = oSettings.aoColumns,
3942 oAria = oSettings.oLanguage.oAria;
3944 /* No sorting required if server-side or no sorting array */
3945 if ( !oSettings.oFeatures.bServerSide &&
3946 (oSettings.aaSorting.length !== 0 || oSettings.aaSortingFixed !== null) )
3948 aaSort = ( oSettings.aaSortingFixed !== null ) ?
3949 oSettings.aaSortingFixed.concat( oSettings.aaSorting ) :
3950 oSettings.aaSorting.slice();
3952 /* If there is a sorting data type, and a function belonging to it, then we need to
3953 * get the data from the developer's function and apply it for this column
3955 for ( i=0 ; i<aaSort.length ; i++ )
3957 var iColumn = aaSort[i][0];
3958 var iVisColumn = _fnColumnIndexToVisible( oSettings, iColumn );
3959 sDataType = oSettings.aoColumns[ iColumn ].sSortDataType;
3960 if ( DataTable.ext.afnSortData[sDataType] )
3962 var aData = DataTable.ext.afnSortData[sDataType].call(
3963 oSettings.oInstance, oSettings, iColumn, iVisColumn
3965 if ( aData.length === aoData.length )
3967 for ( j=0, jLen=aoData.length ; j<jLen ; j++ )
3969 _fnSetCellData( oSettings, j, iColumn, aData[j] );
3974 _fnLog( oSettings, 0, "Returned data sort array (col "+iColumn+") is the wrong length" );
3979 /* Create a value - key array of the current row positions such that we can use their
3980 * current position during the sort, if values match, in order to perform stable sorting
3982 for ( i=0, iLen=oSettings.aiDisplayMaster.length ; i<iLen ; i++ )
3984 aiOrig[ oSettings.aiDisplayMaster[i] ] = i;
3987 /* Build an internal data array which is specific to the sort, so we can get and prep
3988 * the data to be sorted only once, rather than needing to do it every time the sorting
3989 * function runs. This make the sorting function a very simple comparison
3991 var iSortLen = aaSort.length;
3992 var fnSortFormat, aDataSort;
3993 for ( i=0, iLen=aoData.length ; i<iLen ; i++ )
3995 for ( j=0 ; j<iSortLen ; j++ )
3997 aDataSort = aoColumns[ aaSort[j][0] ].aDataSort;
3999 for ( k=0, kLen=aDataSort.length ; k<kLen ; k++ )
4001 sDataType = aoColumns[ aDataSort[k] ].sType;
4002 fnSortFormat = oSort[ (sDataType ? sDataType : 'string')+"-pre" ];
4004 aoData[i]._aSortData[ aDataSort[k] ] = fnSortFormat ?
4005 fnSortFormat( _fnGetCellData( oSettings, i, aDataSort[k], 'sort' ) ) :
4006 _fnGetCellData( oSettings, i, aDataSort[k], 'sort' );
4011 /* Do the sort - here we want multi-column sorting based on a given data source (column)
4012 * and sorting function (from oSort) in a certain direction. It's reasonably complex to
4013 * follow on it's own, but this is what we want (example two column sorting):
4014 * fnLocalSorting = function(a,b){
4016 * iTest = oSort['string-asc']('data11', 'data12');
4019 * iTest = oSort['numeric-desc']('data21', 'data22');
4022 * return oSort['numeric-asc']( aiOrig[a], aiOrig[b] );
4024 * Basically we have a test for each sorting column, if the data in that column is equal,
4025 * test the next column. If all columns match, then we use a numeric sort on the row
4026 * positions in the original data array to provide a stable sort.
4028 oSettings.aiDisplayMaster.sort( function ( a, b ) {
4029 var k, l, lLen, iTest, aDataSort, sDataType;
4030 for ( k=0 ; k<iSortLen ; k++ )
4032 aDataSort = aoColumns[ aaSort[k][0] ].aDataSort;
4034 for ( l=0, lLen=aDataSort.length ; l<lLen ; l++ )
4036 sDataType = aoColumns[ aDataSort[l] ].sType;
4038 iTest = oSort[ (sDataType ? sDataType : 'string')+"-"+aaSort[k][1] ](
4039 aoData[a]._aSortData[ aDataSort[l] ],
4040 aoData[b]._aSortData[ aDataSort[l] ]
4050 return oSort['numeric-asc']( aiOrig[a], aiOrig[b] );
4054 /* Alter the sorting classes to take account of the changes */
4055 if ( (bApplyClasses === undefined || bApplyClasses) && !oSettings.oFeatures.bDeferRender )
4057 _fnSortingClasses( oSettings );
4060 for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
4062 var sTitle = aoColumns[i].sTitle.replace( /<.*?>/g, "" );
4063 nTh = aoColumns[i].nTh;
4064 nTh.removeAttribute('aria-sort');
4065 nTh.removeAttribute('aria-label');
4067 /* In ARIA only the first sorting column can be marked as sorting - no multi-sort option */
4068 if ( aoColumns[i].bSortable )
4070 if ( aaSort.length > 0 && aaSort[0][0] == i )
4072 nTh.setAttribute('aria-sort', aaSort[0][1]=="asc" ? "ascending" : "descending" );
4074 var nextSort = (aoColumns[i].asSorting[ aaSort[0][2]+1 ]) ?
4075 aoColumns[i].asSorting[ aaSort[0][2]+1 ] : aoColumns[i].asSorting[0];
4076 nTh.setAttribute('aria-label', sTitle+
4077 (nextSort=="asc" ? oAria.sSortAscending : oAria.sSortDescending) );
4081 nTh.setAttribute('aria-label', sTitle+
4082 (aoColumns[i].asSorting[0]=="asc" ? oAria.sSortAscending : oAria.sSortDescending) );
4087 nTh.setAttribute('aria-label', sTitle);
4091 /* Tell the draw function that we have sorted the data */
4092 oSettings.bSorted = true;
4093 $(oSettings.oInstance).trigger('sort', oSettings);
4095 /* Copy the master data into the draw array and re-draw */
4096 if ( oSettings.oFeatures.bFilter )
4098 /* _fnFilter() will redraw the table for us */
4099 _fnFilterComplete( oSettings, oSettings.oPreviousSearch, 1 );
4103 oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
4104 oSettings._iDisplayStart = 0; /* reset display back to page 0 */
4105 _fnCalculateEnd( oSettings );
4106 _fnDraw( oSettings );
4112 * Attach a sort handler (click) to a node
4113 * @param {object} oSettings dataTables settings object
4114 * @param {node} nNode node to attach the handler to
4115 * @param {int} iDataIndex column sorting index
4116 * @param {function} [fnCallback] callback function
4117 * @memberof DataTable#oApi
4119 function _fnSortAttachListener ( oSettings, nNode, iDataIndex, fnCallback )
4121 _fnBindAction( nNode, {}, function (e) {
4122 /* If the column is not sortable - don't to anything */
4123 if ( oSettings.aoColumns[iDataIndex].bSortable === false )
4129 * This is a little bit odd I admit... I declare a temporary function inside the scope of
4130 * _fnBuildHead and the click handler in order that the code presented here can be used
4131 * twice - once for when bProcessing is enabled, and another time for when it is
4132 * disabled, as we need to perform slightly different actions.
4133 * Basically the issue here is that the Javascript engine in modern browsers don't
4134 * appear to allow the rendering engine to update the display while it is still executing
4135 * it's thread (well - it does but only after long intervals). This means that the
4136 * 'processing' display doesn't appear for a table sort. To break the js thread up a bit
4137 * I force an execution break by using setTimeout - but this breaks the expected
4138 * thread continuation for the end-developer's point of view (their code would execute
4139 * too early), so we only do it when we absolutely have to.
4141 var fnInnerSorting = function () {
4142 var iColumn, iNextSort;
4144 /* If the shift key is pressed then we are multiple column sorting */
4147 /* Are we already doing some kind of sort on this column? */
4149 for ( var i=0 ; i<oSettings.aaSorting.length ; i++ )
4151 if ( oSettings.aaSorting[i][0] == iDataIndex )
4154 iColumn = oSettings.aaSorting[i][0];
4155 iNextSort = oSettings.aaSorting[i][2]+1;
4157 if ( !oSettings.aoColumns[iColumn].asSorting[iNextSort] )
4159 /* Reached the end of the sorting options, remove from multi-col sort */
4160 oSettings.aaSorting.splice( i, 1 );
4164 /* Move onto next sorting direction */
4165 oSettings.aaSorting[i][1] = oSettings.aoColumns[iColumn].asSorting[iNextSort];
4166 oSettings.aaSorting[i][2] = iNextSort;
4172 /* No sort yet - add it in */
4173 if ( bFound === false )
4175 oSettings.aaSorting.push( [ iDataIndex,
4176 oSettings.aoColumns[iDataIndex].asSorting[0], 0 ] );
4181 /* If no shift key then single column sort */
4182 if ( oSettings.aaSorting.length == 1 && oSettings.aaSorting[0][0] == iDataIndex )
4184 iColumn = oSettings.aaSorting[0][0];
4185 iNextSort = oSettings.aaSorting[0][2]+1;
4186 if ( !oSettings.aoColumns[iColumn].asSorting[iNextSort] )
4190 oSettings.aaSorting[0][1] = oSettings.aoColumns[iColumn].asSorting[iNextSort];
4191 oSettings.aaSorting[0][2] = iNextSort;
4195 oSettings.aaSorting.splice( 0, oSettings.aaSorting.length );
4196 oSettings.aaSorting.push( [ iDataIndex,
4197 oSettings.aoColumns[iDataIndex].asSorting[0], 0 ] );
4202 _fnSort( oSettings );
4203 }; /* /fnInnerSorting */
4205 if ( !oSettings.oFeatures.bProcessing )
4211 _fnProcessingDisplay( oSettings, true );
4212 setTimeout( function() {
4214 if ( !oSettings.oFeatures.bServerSide )
4216 _fnProcessingDisplay( oSettings, false );
4221 /* Call the user specified callback function - used for async user interaction */
4222 if ( typeof fnCallback == 'function' )
4224 fnCallback( oSettings );
4231 * Set the sorting classes on the header, Note: it is safe to call this function
4232 * when bSort and bSortClasses are false
4233 * @param {object} oSettings dataTables settings object
4234 * @memberof DataTable#oApi
4236 function _fnSortingClasses( oSettings )
4238 var i, iLen, j, jLen, iFound;
4240 var iColumns = oSettings.aoColumns.length;
4241 var oClasses = oSettings.oClasses;
4243 for ( i=0 ; i<iColumns ; i++ )
4245 if ( oSettings.aoColumns[i].bSortable )
4247 $(oSettings.aoColumns[i].nTh).removeClass( oClasses.sSortAsc +" "+ oClasses.sSortDesc +
4248 " "+ oSettings.aoColumns[i].sSortingClass );
4252 if ( oSettings.aaSortingFixed !== null )
4254 aaSort = oSettings.aaSortingFixed.concat( oSettings.aaSorting );
4258 aaSort = oSettings.aaSorting.slice();
4261 /* Apply the required classes to the header */
4262 for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
4264 if ( oSettings.aoColumns[i].bSortable )
4266 sClass = oSettings.aoColumns[i].sSortingClass;
4268 for ( j=0 ; j<aaSort.length ; j++ )
4270 if ( aaSort[j][0] == i )
4272 sClass = ( aaSort[j][1] == "asc" ) ?
4273 oClasses.sSortAsc : oClasses.sSortDesc;
4278 $(oSettings.aoColumns[i].nTh).addClass( sClass );
4280 if ( oSettings.bJUI )
4282 /* jQuery UI uses extra markup */
4283 var jqSpan = $("span."+oClasses.sSortIcon, oSettings.aoColumns[i].nTh);
4284 jqSpan.removeClass(oClasses.sSortJUIAsc +" "+ oClasses.sSortJUIDesc +" "+
4285 oClasses.sSortJUI +" "+ oClasses.sSortJUIAscAllowed +" "+ oClasses.sSortJUIDescAllowed );
4290 sSpanClass = oSettings.aoColumns[i].sSortingClassJUI;
4292 else if ( aaSort[iFound][1] == "asc" )
4294 sSpanClass = oClasses.sSortJUIAsc;
4298 sSpanClass = oClasses.sSortJUIDesc;
4301 jqSpan.addClass( sSpanClass );
4306 /* No sorting on this column, so add the base class. This will have been assigned by
4309 $(oSettings.aoColumns[i].nTh).addClass( oSettings.aoColumns[i].sSortingClass );
4314 * Apply the required classes to the table body
4315 * Note that this is given as a feature switch since it can significantly slow down a sort
4316 * on large data sets (adding and removing of classes is always slow at the best of times..)
4317 * Further to this, note that this code is admittedly fairly ugly. It could be made a lot
4318 * simpler using jQuery selectors and add/removeClass, but that is significantly slower
4319 * (on the order of 5 times slower) - hence the direct DOM manipulation here.
4320 * Note that for deferred drawing we do use jQuery - the reason being that taking the first
4321 * row found to see if the whole column needs processed can miss classes since the first
4322 * column might be new.
4324 sClass = oClasses.sSortColumn;
4326 if ( oSettings.oFeatures.bSort && oSettings.oFeatures.bSortClasses )
4328 var nTds = _fnGetTdNodes( oSettings );
4330 /* Determine what the sorting class for each column should be */
4331 var iClass, iTargetCol;
4333 for (i = 0; i < iColumns; i++)
4337 for (i = 0, iClass = 1; i < aaSort.length; i++)
4339 iTargetCol = parseInt( aaSort[i][0], 10 );
4340 asClasses[iTargetCol] = sClass + iClass;
4348 /* Make changes to the classes for each cell as needed */
4349 var reClass = new RegExp(sClass + "[123]");
4350 var sTmpClass, sCurrentClass, sNewClass;
4351 for ( i=0, iLen=nTds.length; i<iLen; i++ )
4353 /* Determine which column we're looking at */
4354 iTargetCol = i % iColumns;
4356 /* What is the full list of classes now */
4357 sCurrentClass = nTds[i].className;
4358 /* What sorting class should be applied? */
4359 sNewClass = asClasses[iTargetCol];
4360 /* What would the new full list be if we did a replacement? */
4361 sTmpClass = sCurrentClass.replace(reClass, sNewClass);
4363 if ( sTmpClass != sCurrentClass )
4365 /* We changed something */
4366 nTds[i].className = $.trim( sTmpClass );
4368 else if ( sNewClass.length > 0 && sCurrentClass.indexOf(sNewClass) == -1 )
4370 /* We need to add a class */
4371 nTds[i].className = sCurrentClass + " " + sNewClass;
4380 * Save the state of a table in a cookie such that the page can be reloaded
4381 * @param {object} oSettings dataTables settings object
4382 * @memberof DataTable#oApi
4384 function _fnSaveState ( oSettings )
4386 if ( !oSettings.oFeatures.bStateSave || oSettings.bDestroying )
4391 /* Store the interesting variables */
4392 var i, iLen, bInfinite=oSettings.oScroll.bInfinite;
4394 "iCreate": new Date().getTime(),
4395 "iStart": (bInfinite ? 0 : oSettings._iDisplayStart),
4396 "iEnd": (bInfinite ? oSettings._iDisplayLength : oSettings._iDisplayEnd),
4397 "iLength": oSettings._iDisplayLength,
4398 "aaSorting": $.extend( true, [], oSettings.aaSorting ),
4399 "oSearch": $.extend( true, {}, oSettings.oPreviousSearch ),
4400 "aoSearchCols": $.extend( true, [], oSettings.aoPreSearchCols ),
4404 for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
4406 oState.abVisCols.push( oSettings.aoColumns[i].bVisible );
4409 _fnCallbackFire( oSettings, "aoStateSaveParams", 'stateSaveParams', [oSettings, oState] );
4411 oSettings.fnStateSave.call( oSettings.oInstance, oSettings, oState );
4416 * Attempt to load a saved table state from a cookie
4417 * @param {object} oSettings dataTables settings object
4418 * @param {object} oInit DataTables init object so we can override settings
4419 * @memberof DataTable#oApi
4421 function _fnLoadState ( oSettings, oInit )
4423 if ( !oSettings.oFeatures.bStateSave )
4428 var oData = oSettings.fnStateLoad.call( oSettings.oInstance, oSettings );
4434 /* Allow custom and plug-in manipulation functions to alter the saved data set and
4435 * cancelling of loading by returning false
4437 var abStateLoad = _fnCallbackFire( oSettings, 'aoStateLoadParams', 'stateLoadParams', [oSettings, oData] );
4438 if ( $.inArray( false, abStateLoad ) !== -1 )
4443 /* Store the saved state so it might be accessed at any time */
4444 oSettings.oLoadedState = $.extend( true, {}, oData );
4446 /* Restore key features */
4447 oSettings._iDisplayStart = oData.iStart;
4448 oSettings.iInitDisplayStart = oData.iStart;
4449 oSettings._iDisplayEnd = oData.iEnd;
4450 oSettings._iDisplayLength = oData.iLength;
4451 oSettings.aaSorting = oData.aaSorting.slice();
4452 oSettings.saved_aaSorting = oData.aaSorting.slice();
4454 /* Search filtering */
4455 $.extend( oSettings.oPreviousSearch, oData.oSearch );
4456 $.extend( true, oSettings.aoPreSearchCols, oData.aoSearchCols );
4458 /* Column visibility state
4459 * Pass back visibility settings to the init handler, but to do not here override
4460 * the init object that the user might have passed in
4462 oInit.saved_aoColumns = [];
4463 for ( var i=0 ; i<oData.abVisCols.length ; i++ )
4465 oInit.saved_aoColumns[i] = {};
4466 oInit.saved_aoColumns[i].bVisible = oData.abVisCols[i];
4469 _fnCallbackFire( oSettings, 'aoStateLoaded', 'stateLoaded', [oSettings, oData] );
4474 * Create a new cookie with a value to store the state of a table
4475 * @param {string} sName name of the cookie to create
4476 * @param {string} sValue the value the cookie should take
4477 * @param {int} iSecs duration of the cookie
4478 * @param {string} sBaseName sName is made up of the base + file name - this is the base
4479 * @param {function} fnCallback User definable function to modify the cookie
4480 * @memberof DataTable#oApi
4482 function _fnCreateCookie ( sName, sValue, iSecs, sBaseName, fnCallback )
4484 var date = new Date();
4485 date.setTime( date.getTime()+(iSecs*1000) );
4488 * Shocking but true - it would appear IE has major issues with having the path not having
4489 * a trailing slash on it. We need the cookie to be available based on the path, so we
4490 * have to append the file name to the cookie name. Appalling. Thanks to vex for adding the
4491 * patch to use at least some of the path
4493 var aParts = window.location.pathname.split('/');
4494 var sNameFile = sName + '_' + aParts.pop().replace(/[\/:]/g,"").toLowerCase();
4495 var sFullCookie, oData;
4497 if ( fnCallback !== null )
4499 oData = (typeof $.parseJSON === 'function') ?
4500 $.parseJSON( sValue ) : eval( '('+sValue+')' );
4501 sFullCookie = fnCallback( sNameFile, oData, date.toGMTString(),
4502 aParts.join('/')+"/" );
4506 sFullCookie = sNameFile + "=" + encodeURIComponent(sValue) +
4507 "; expires=" + date.toGMTString() +"; path=" + aParts.join('/')+"/";
4510 /* Are we going to go over the cookie limit of 4KiB? If so, try to delete a cookies
4511 * belonging to DataTables.
4514 aCookies =document.cookie.split(';'),
4515 iNewCookieLen = sFullCookie.split(';')[0].length,
4518 if ( iNewCookieLen+document.cookie.length+10 > 4096 ) /* Magic 10 for padding */
4520 for ( var i=0, iLen=aCookies.length ; i<iLen ; i++ )
4522 if ( aCookies[i].indexOf( sBaseName ) != -1 )
4524 /* It's a DataTables cookie, so eval it and check the time stamp */
4525 var aSplitCookie = aCookies[i].split('=');
4527 oData = eval( '('+decodeURIComponent(aSplitCookie[1])+')' );
4529 if ( oData && oData.iCreate )
4532 "name": aSplitCookie[0],
4533 "time": oData.iCreate
4541 // Make sure we delete the oldest ones first
4542 aOldCookies.sort( function (a, b) {
4543 return b.time - a.time;
4546 // Eliminate as many old DataTables cookies as we need to
4547 while ( iNewCookieLen + document.cookie.length + 10 > 4096 ) {
4548 if ( aOldCookies.length === 0 ) {
4549 // Deleted all DT cookies and still not enough space. Can't state save
4553 var old = aOldCookies.pop();
4554 document.cookie = old.name+"=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path="+
4555 aParts.join('/') + "/";
4559 document.cookie = sFullCookie;
4564 * Read an old cookie to get a cookie with an old table state
4565 * @param {string} sName name of the cookie to read
4566 * @returns {string} contents of the cookie - or null if no cookie with that name found
4567 * @memberof DataTable#oApi
4569 function _fnReadCookie ( sName )
4572 aParts = window.location.pathname.split('/'),
4573 sNameEQ = sName + '_' + aParts[aParts.length-1].replace(/[\/:]/g,"").toLowerCase() + '=',
4574 sCookieContents = document.cookie.split(';');
4576 for( var i=0 ; i<sCookieContents.length ; i++ )
4578 var c = sCookieContents[i];
4580 while (c.charAt(0)==' ')
4582 c = c.substring(1,c.length);
4585 if (c.indexOf(sNameEQ) === 0)
4587 return decodeURIComponent( c.substring(sNameEQ.length,c.length) );
4595 * Return the settings object for a particular table
4596 * @param {node} nTable table we are using as a dataTable
4597 * @returns {object} Settings object - or null if not found
4598 * @memberof DataTable#oApi
4600 function _fnSettingsFromNode ( nTable )
4602 for ( var i=0 ; i<DataTable.settings.length ; i++ )
4604 if ( DataTable.settings[i].nTable === nTable )
4606 return DataTable.settings[i];
4615 * Return an array with the TR nodes for the table
4616 * @param {object} oSettings dataTables settings object
4617 * @returns {array} TR array
4618 * @memberof DataTable#oApi
4620 function _fnGetTrNodes ( oSettings )
4623 var aoData = oSettings.aoData;
4624 for ( var i=0, iLen=aoData.length ; i<iLen ; i++ )
4626 if ( aoData[i].nTr !== null )
4628 aNodes.push( aoData[i].nTr );
4636 * Return an flat array with all TD nodes for the table, or row
4637 * @param {object} oSettings dataTables settings object
4638 * @param {int} [iIndividualRow] aoData index to get the nodes for - optional
4639 * if not given then the return array will contain all nodes for the table
4640 * @returns {array} TD array
4641 * @memberof DataTable#oApi
4643 function _fnGetTdNodes ( oSettings, iIndividualRow )
4648 var iRow, iRows=oSettings.aoData.length,
4649 iColumn, iColumns, oData, sNodeName, iStart=0, iEnd=iRows;
4651 /* Allow the collection to be limited to just one row */
4652 if ( iIndividualRow !== undefined )
4654 iStart = iIndividualRow;
4655 iEnd = iIndividualRow+1;
4658 for ( iRow=iStart ; iRow<iEnd ; iRow++ )
4660 oData = oSettings.aoData[iRow];
4661 if ( oData.nTr !== null )
4663 /* get the TD child nodes - taking into account text etc nodes */
4665 nTd = oData.nTr.firstChild;
4668 sNodeName = nTd.nodeName.toLowerCase();
4669 if ( sNodeName == 'td' || sNodeName == 'th' )
4673 nTd = nTd.nextSibling;
4677 for ( iColumn=0, iColumns=oSettings.aoColumns.length ; iColumn<iColumns ; iColumn++ )
4679 if ( oSettings.aoColumns[iColumn].bVisible )
4681 anReturn.push( anTds[iColumn-iCorrector] );
4685 anReturn.push( oData._anHidden[iColumn] );
4697 * Log an error message
4698 * @param {object} oSettings dataTables settings object
4699 * @param {int} iLevel log error messages, or display them to the user
4700 * @param {string} sMesg error message
4701 * @memberof DataTable#oApi
4703 function _fnLog( oSettings, iLevel, sMesg )
4705 var sAlert = (oSettings===null) ?
4706 "DataTables warning: "+sMesg :
4707 "DataTables warning (table id = '"+oSettings.sTableId+"'): "+sMesg;
4711 if ( DataTable.ext.sErrMode == 'alert' )
4717 throw new Error(sAlert);
4721 else if ( window.console && console.log )
4723 console.log( sAlert );
4729 * See if a property is defined on one object, if so assign it to the other object
4730 * @param {object} oRet target object
4731 * @param {object} oSrc source object
4732 * @param {string} sName property
4733 * @param {string} [sMappedName] name to map too - optional, sName used if not given
4734 * @memberof DataTable#oApi
4736 function _fnMap( oRet, oSrc, sName, sMappedName )
4738 if ( sMappedName === undefined )
4740 sMappedName = sName;
4742 if ( oSrc[sName] !== undefined )
4744 oRet[sMappedName] = oSrc[sName];
4750 * Extend objects - very similar to jQuery.extend, but deep copy objects, and shallow
4751 * copy arrays. The reason we need to do this, is that we don't want to deep copy array
4752 * init values (such as aaSorting) since the dev wouldn't be able to override them, but
4753 * we do want to deep copy arrays.
4754 * @param {object} oOut Object to extend
4755 * @param {object} oExtender Object from which the properties will be applied to oOut
4756 * @returns {object} oOut Reference, just for convenience - oOut === the return.
4757 * @memberof DataTable#oApi
4758 * @todo This doesn't take account of arrays inside the deep copied objects.
4760 function _fnExtend( oOut, oExtender )
4764 for ( var prop in oExtender )
4766 if ( oExtender.hasOwnProperty(prop) )
4768 val = oExtender[prop];
4770 if ( typeof oInit[prop] === 'object' && val !== null && $.isArray(val) === false )
4772 $.extend( true, oOut[prop], val );
4786 * Bind an event handers to allow a click or return key to activate the callback.
4787 * This is good for accessibility since a return on the keyboard will have the
4788 * same effect as a click, if the element has focus.
4789 * @param {element} n Element to bind the action to
4790 * @param {object} oData Data object to pass to the triggered function
4791 * @param {function} fn Callback function for when the event is triggered
4792 * @memberof DataTable#oApi
4794 function _fnBindAction( n, oData, fn )
4797 .bind( 'click.DT', oData, function (e) {
4798 n.blur(); // Remove focus outline for mouse users
4801 .bind( 'keypress.DT', oData, function (e){
4802 if ( e.which === 13 ) {
4805 .bind( 'selectstart.DT', function () {
4806 /* Take the brutal approach to cancelling text selection */
4813 * Register a callback function. Easily allows a callback function to be added to
4814 * an array store of callback functions that can then all be called together.
4815 * @param {object} oSettings dataTables settings object
4816 * @param {string} sStore Name of the array storage for the callbacks in oSettings
4817 * @param {function} fn Function to be called back
4818 * @param {string} sName Identifying name for the callback (i.e. a label)
4819 * @memberof DataTable#oApi
4821 function _fnCallbackReg( oSettings, sStore, fn, sName )
4825 oSettings[sStore].push( {
4834 * Fire callback functions and trigger events. Note that the loop over the callback
4835 * array store is done backwards! Further note that you do not want to fire off triggers
4836 * in time sensitive applications (for example cell creation) as its slow.
4837 * @param {object} oSettings dataTables settings object
4838 * @param {string} sStore Name of the array storage for the callbacks in oSettings
4839 * @param {string} sTrigger Name of the jQuery custom event to trigger. If null no trigger
4841 * @param {array} aArgs Array of arguments to pass to the callback function / trigger
4842 * @memberof DataTable#oApi
4844 function _fnCallbackFire( oSettings, sStore, sTrigger, aArgs )
4846 var aoStore = oSettings[sStore];
4849 for ( var i=aoStore.length-1 ; i>=0 ; i-- )
4851 aRet.push( aoStore[i].fn.apply( oSettings.oInstance, aArgs ) );
4854 if ( sTrigger !== null )
4856 $(oSettings.oInstance).trigger(sTrigger, aArgs);
4864 * JSON stringify. If JSON.stringify it provided by the browser, json2.js or any other
4865 * library, then we use that as it is fast, safe and accurate. If the function isn't
4866 * available then we need to built it ourselves - the inspiration for this function comes
4867 * from Craig Buckler ( http://www.sitepoint.com/javascript-json-serialization/ ). It is
4868 * not perfect and absolutely should not be used as a replacement to json2.js - but it does
4869 * do what we need, without requiring a dependency for DataTables.
4870 * @param {object} o JSON object to be converted
4871 * @returns {string} JSON string
4872 * @memberof DataTable#oApi
4874 var _fnJsonString = (window.JSON) ? JSON.stringify : function( o )
4876 /* Not an object or array */
4877 var sType = typeof o;
4878 if (sType !== "object" || o === null)
4881 if (sType === "string")
4888 /* If object or array, need to recurse over it */
4892 bArr = $.isArray(o);
4897 sType = typeof mValue;
4899 if (sType === "string")
4901 mValue = '"'+mValue+'"';
4903 else if (sType === "object" && mValue !== null)
4905 mValue = _fnJsonString(mValue);
4908 json.push((bArr ? "" : '"'+sProp+'":') + mValue);
4911 return (bArr ? "[" : "{") + json + (bArr ? "]" : "}");
4916 * From some browsers (specifically IE6/7) we need special handling to work around browser
4917 * bugs - this function is used to detect when these workarounds are needed.
4918 * @param {object} oSettings dataTables settings object
4919 * @memberof DataTable#oApi
4921 function _fnBrowserDetect( oSettings )
4923 /* IE6/7 will oversize a width 100% element inside a scrolling element, to include the
4924 * width of the scrollbar, while other browsers ensure the inner element is contained
4925 * without forcing scrolling
4928 '<div style="position:absolute; top:0; left:0; height:1px; width:1px; overflow:hidden">'+
4929 '<div style="position:absolute; top:1px; left:1px; width:100px; overflow:scroll;">'+
4930 '<div id="DT_BrowserTest" style="width:100%; height:10px;"></div>'+
4934 document.body.appendChild( n );
4935 oSettings.oBrowser.bScrollOversize = $('#DT_BrowserTest', n)[0].offsetWidth === 100 ? true : false;
4936 document.body.removeChild( n );
4941 * Perform a jQuery selector action on the table's TR elements (from the tbody) and
4942 * return the resulting jQuery object.
4943 * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
4944 * @param {object} [oOpts] Optional parameters for modifying the rows to be included
4945 * @param {string} [oOpts.filter=none] Select TR elements that meet the current filter
4946 * criterion ("applied") or all TR elements (i.e. no filter).
4947 * @param {string} [oOpts.order=current] Order of the TR elements in the processed array.
4948 * Can be either 'current', whereby the current sorting of the table is used, or
4949 * 'original' whereby the original order the data was read into the table is used.
4950 * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
4951 * ("current") or not ("all"). If 'current' is given, then order is assumed to be
4952 * 'current' and filter is 'applied', regardless of what they might be given as.
4953 * @returns {object} jQuery object, filtered by the given selector.
4957 * $(document).ready(function() {
4958 * var oTable = $('#example').dataTable();
4960 * // Highlight every second row
4961 * oTable.$('tr:odd').css('backgroundColor', 'blue');
4965 * $(document).ready(function() {
4966 * var oTable = $('#example').dataTable();
4968 * // Filter to rows with 'Webkit' in them, add a background colour and then
4969 * // remove the filter, thus highlighting the 'Webkit' rows only.
4970 * oTable.fnFilter('Webkit');
4971 * oTable.$('tr', {"filter": "applied"}).css('backgroundColor', 'blue');
4972 * oTable.fnFilter('');
4975 this.$ = function ( sSelector, oOpts )
4977 var i, iLen, a = [], tr;
4978 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
4979 var aoData = oSettings.aoData;
4980 var aiDisplay = oSettings.aiDisplay;
4981 var aiDisplayMaster = oSettings.aiDisplayMaster;
4988 oOpts = $.extend( {}, {
4989 "filter": "none", // applied
4990 "order": "current", // "original"
4991 "page": "all" // current
4994 // Current page implies that order=current and fitler=applied, since it is fairly
4995 // senseless otherwise
4996 if ( oOpts.page == 'current' )
4998 for ( i=oSettings._iDisplayStart, iLen=oSettings.fnDisplayEnd() ; i<iLen ; i++ )
5000 tr = aoData[ aiDisplay[i] ].nTr;
5007 else if ( oOpts.order == "current" && oOpts.filter == "none" )
5009 for ( i=0, iLen=aiDisplayMaster.length ; i<iLen ; i++ )
5011 tr = aoData[ aiDisplayMaster[i] ].nTr;
5018 else if ( oOpts.order == "current" && oOpts.filter == "applied" )
5020 for ( i=0, iLen=aiDisplay.length ; i<iLen ; i++ )
5022 tr = aoData[ aiDisplay[i] ].nTr;
5029 else if ( oOpts.order == "original" && oOpts.filter == "none" )
5031 for ( i=0, iLen=aoData.length ; i<iLen ; i++ )
5033 tr = aoData[ i ].nTr ;
5040 else if ( oOpts.order == "original" && oOpts.filter == "applied" )
5042 for ( i=0, iLen=aoData.length ; i<iLen ; i++ )
5044 tr = aoData[ i ].nTr;
5045 if ( $.inArray( i, aiDisplay ) !== -1 && tr )
5053 _fnLog( oSettings, 1, "Unknown selection options" );
5056 /* We need to filter on the TR elements and also 'find' in their descendants
5057 * to make the selector act like it would in a full table - so we need
5058 * to build both results and then combine them together
5061 var jqTRs = jqA.filter( sSelector );
5062 var jqDescendants = jqA.find( sSelector );
5064 return $( [].concat($.makeArray(jqTRs), $.makeArray(jqDescendants)) );
5069 * Almost identical to $ in operation, but in this case returns the data for the matched
5070 * rows - as such, the jQuery selector used should match TR row nodes or TD/TH cell nodes
5071 * rather than any descendants, so the data can be obtained for the row/cell. If matching
5072 * rows are found, the data returned is the original data array/object that was used to
5073 * create the row (or a generated array if from a DOM source).
5075 * This method is often useful in-combination with $ where both functions are given the
5076 * same parameters and the array indexes will match identically.
5077 * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
5078 * @param {object} [oOpts] Optional parameters for modifying the rows to be included
5079 * @param {string} [oOpts.filter=none] Select elements that meet the current filter
5080 * criterion ("applied") or all elements (i.e. no filter).
5081 * @param {string} [oOpts.order=current] Order of the data in the processed array.
5082 * Can be either 'current', whereby the current sorting of the table is used, or
5083 * 'original' whereby the original order the data was read into the table is used.
5084 * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
5085 * ("current") or not ("all"). If 'current' is given, then order is assumed to be
5086 * 'current' and filter is 'applied', regardless of what they might be given as.
5087 * @returns {array} Data for the matched elements. If any elements, as a result of the
5088 * selector, were not TR, TD or TH elements in the DataTable, they will have a null
5089 * entry in the array.
5093 * $(document).ready(function() {
5094 * var oTable = $('#example').dataTable();
5096 * // Get the data from the first row in the table
5097 * var data = oTable._('tr:first');
5099 * // Do something useful with the data
5100 * alert( "First cell is: "+data[0] );
5104 * $(document).ready(function() {
5105 * var oTable = $('#example').dataTable();
5107 * // Filter to 'Webkit' and get all data for
5108 * oTable.fnFilter('Webkit');
5109 * var data = oTable._('tr', {"filter": "applied"});
5111 * // Do something with the data
5112 * alert( data.length+" rows matched the filter" );
5115 this._ = function ( sSelector, oOpts )
5118 var i, iLen, iIndex;
5119 var aTrs = this.$( sSelector, oOpts );
5121 for ( i=0, iLen=aTrs.length ; i<iLen ; i++ )
5123 aOut.push( this.fnGetData(aTrs[i]) );
5131 * Add a single new row or multiple rows of data to the table. Please note
5132 * that this is suitable for client-side processing only - if you are using
5133 * server-side processing (i.e. "bServerSide": true), then to add data, you
5134 * must add it to the data source, i.e. the server-side, through an Ajax call.
5135 * @param {array|object} mData The data to be added to the table. This can be:
5137 * <li>1D array of data - add a single row with the data provided</li>
5138 * <li>2D array of arrays - add multiple rows in a single call</li>
5139 * <li>object - data object when using <i>mData</i></li>
5140 * <li>array of objects - multiple data objects when using <i>mData</i></li>
5142 * @param {bool} [bRedraw=true] redraw the table or not
5143 * @returns {array} An array of integers, representing the list of indexes in
5144 * <i>aoData</i> ({@link DataTable.models.oSettings}) that have been added to
5149 * // Global var for counter
5152 * $(document).ready(function() {
5153 * $('#example').dataTable();
5156 * function fnClickAddRow() {
5157 * $('#example').dataTable().fnAddData( [
5167 this.fnAddData = function( mData, bRedraw )
5169 if ( mData.length === 0 )
5177 /* Find settings from table node */
5178 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5180 /* Check if we want to add multiple rows or not */
5181 if ( typeof mData[0] === "object" && mData[0] !== null )
5183 for ( var i=0 ; i<mData.length ; i++ )
5185 iTest = _fnAddData( oSettings, mData[i] );
5190 aiReturn.push( iTest );
5195 iTest = _fnAddData( oSettings, mData );
5200 aiReturn.push( iTest );
5203 oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
5205 if ( bRedraw === undefined || bRedraw )
5207 _fnReDraw( oSettings );
5214 * This function will make DataTables recalculate the column sizes, based on the data
5215 * contained in the table and the sizes applied to the columns (in the DOM, CSS or
5216 * through the sWidth parameter). This can be useful when the width of the table's
5217 * parent element changes (for example a window resize).
5218 * @param {boolean} [bRedraw=true] Redraw the table or not, you will typically want to
5222 * $(document).ready(function() {
5223 * var oTable = $('#example').dataTable( {
5224 * "sScrollY": "200px",
5225 * "bPaginate": false
5228 * $(window).bind('resize', function () {
5229 * oTable.fnAdjustColumnSizing();
5233 this.fnAdjustColumnSizing = function ( bRedraw )
5235 var oSettings = _fnSettingsFromNode(this[DataTable.ext.iApiIndex]);
5236 _fnAdjustColumnSizing( oSettings );
5238 if ( bRedraw === undefined || bRedraw )
5240 this.fnDraw( false );
5242 else if ( oSettings.oScroll.sX !== "" || oSettings.oScroll.sY !== "" )
5244 /* If not redrawing, but scrolling, we want to apply the new column sizes anyway */
5245 this.oApi._fnScrollDraw(oSettings);
5251 * Quickly and simply clear a table
5252 * @param {bool} [bRedraw=true] redraw the table or not
5256 * $(document).ready(function() {
5257 * var oTable = $('#example').dataTable();
5259 * // Immediately 'nuke' the current rows (perhaps waiting for an Ajax callback...)
5260 * oTable.fnClearTable();
5263 this.fnClearTable = function( bRedraw )
5265 /* Find settings from table node */
5266 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5267 _fnClearTable( oSettings );
5269 if ( bRedraw === undefined || bRedraw )
5271 _fnDraw( oSettings );
5277 * The exact opposite of 'opening' a row, this function will close any rows which
5278 * are currently 'open'.
5279 * @param {node} nTr the table row to 'close'
5280 * @returns {int} 0 on success, or 1 if failed (can't find the row)
5284 * $(document).ready(function() {
5287 * // 'open' an information row when a row is clicked on
5288 * $('#example tbody tr').click( function () {
5289 * if ( oTable.fnIsOpen(this) ) {
5290 * oTable.fnClose( this );
5292 * oTable.fnOpen( this, "Temporary row opened", "info_row" );
5296 * oTable = $('#example').dataTable();
5299 this.fnClose = function( nTr )
5301 /* Find settings from table node */
5302 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5304 for ( var i=0 ; i<oSettings.aoOpenRows.length ; i++ )
5306 if ( oSettings.aoOpenRows[i].nParent == nTr )
5308 var nTrParent = oSettings.aoOpenRows[i].nTr.parentNode;
5311 /* Remove it if it is currently on display */
5312 nTrParent.removeChild( oSettings.aoOpenRows[i].nTr );
5314 oSettings.aoOpenRows.splice( i, 1 );
5323 * Remove a row for the table
5324 * @param {mixed} mTarget The index of the row from aoData to be deleted, or
5325 * the TR element you want to delete
5326 * @param {function|null} [fnCallBack] Callback function
5327 * @param {bool} [bRedraw=true] Redraw the table or not
5328 * @returns {array} The row that was deleted
5332 * $(document).ready(function() {
5333 * var oTable = $('#example').dataTable();
5335 * // Immediately remove the first row
5336 * oTable.fnDeleteRow( 0 );
5339 this.fnDeleteRow = function( mTarget, fnCallBack, bRedraw )
5341 /* Find settings from table node */
5342 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5343 var i, iLen, iAODataIndex;
5345 iAODataIndex = (typeof mTarget === 'object') ?
5346 _fnNodeToDataIndex(oSettings, mTarget) : mTarget;
5348 /* Return the data array from this row */
5349 var oData = oSettings.aoData.splice( iAODataIndex, 1 );
5351 /* Update the _DT_RowIndex parameter */
5352 for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
5354 if ( oSettings.aoData[i].nTr !== null )
5356 oSettings.aoData[i].nTr._DT_RowIndex = i;
5360 /* Remove the target row from the search array */
5361 var iDisplayIndex = $.inArray( iAODataIndex, oSettings.aiDisplay );
5362 oSettings.asDataSearch.splice( iDisplayIndex, 1 );
5364 /* Delete from the display arrays */
5365 _fnDeleteIndex( oSettings.aiDisplayMaster, iAODataIndex );
5366 _fnDeleteIndex( oSettings.aiDisplay, iAODataIndex );
5368 /* If there is a user callback function - call it */
5369 if ( typeof fnCallBack === "function" )
5371 fnCallBack.call( this, oSettings, oData );
5374 /* Check for an 'overflow' they case for displaying the table */
5375 if ( oSettings._iDisplayStart >= oSettings.fnRecordsDisplay() )
5377 oSettings._iDisplayStart -= oSettings._iDisplayLength;
5378 if ( oSettings._iDisplayStart < 0 )
5380 oSettings._iDisplayStart = 0;
5384 if ( bRedraw === undefined || bRedraw )
5386 _fnCalculateEnd( oSettings );
5387 _fnDraw( oSettings );
5395 * Restore the table to it's original state in the DOM by removing all of DataTables
5396 * enhancements, alterations to the DOM structure of the table and event listeners.
5397 * @param {boolean} [bRemove=false] Completely remove the table from the DOM
5401 * $(document).ready(function() {
5402 * // This example is fairly pointless in reality, but shows how fnDestroy can be used
5403 * var oTable = $('#example').dataTable();
5404 * oTable.fnDestroy();
5407 this.fnDestroy = function ( bRemove )
5409 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5410 var nOrig = oSettings.nTableWrapper.parentNode;
5411 var nBody = oSettings.nTBody;
5414 bRemove = (bRemove===undefined) ? false : bRemove;
5416 /* Flag to note that the table is currently being destroyed - no action should be taken */
5417 oSettings.bDestroying = true;
5419 /* Fire off the destroy callbacks for plug-ins etc */
5420 _fnCallbackFire( oSettings, "aoDestroyCallback", "destroy", [oSettings] );
5422 /* If the table is not being removed, restore the hidden columns */
5425 for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
5427 if ( oSettings.aoColumns[i].bVisible === false )
5429 this.fnSetColumnVis( i, true );
5434 /* Blitz all DT events */
5435 $(oSettings.nTableWrapper).find('*').andSelf().unbind('.DT');
5437 /* If there is an 'empty' indicator row, remove it */
5438 $('tbody>tr>td.'+oSettings.oClasses.sRowEmpty, oSettings.nTable).parent().remove();
5440 /* When scrolling we had to break the table up - restore it */
5441 if ( oSettings.nTable != oSettings.nTHead.parentNode )
5443 $(oSettings.nTable).children('thead').remove();
5444 oSettings.nTable.appendChild( oSettings.nTHead );
5447 if ( oSettings.nTFoot && oSettings.nTable != oSettings.nTFoot.parentNode )
5449 $(oSettings.nTable).children('tfoot').remove();
5450 oSettings.nTable.appendChild( oSettings.nTFoot );
5453 /* Remove the DataTables generated nodes, events and classes */
5454 oSettings.nTable.parentNode.removeChild( oSettings.nTable );
5455 $(oSettings.nTableWrapper).remove();
5457 oSettings.aaSorting = [];
5458 oSettings.aaSortingFixed = [];
5459 _fnSortingClasses( oSettings );
5461 $(_fnGetTrNodes( oSettings )).removeClass( oSettings.asStripeClasses.join(' ') );
5463 $('th, td', oSettings.nTHead).removeClass( [
5464 oSettings.oClasses.sSortable,
5465 oSettings.oClasses.sSortableAsc,
5466 oSettings.oClasses.sSortableDesc,
5467 oSettings.oClasses.sSortableNone ].join(' ')
5469 if ( oSettings.bJUI )
5471 $('th span.'+oSettings.oClasses.sSortIcon
5472 + ', td span.'+oSettings.oClasses.sSortIcon, oSettings.nTHead).remove();
5474 $('th, td', oSettings.nTHead).each( function () {
5475 var jqWrapper = $('div.'+oSettings.oClasses.sSortJUIWrapper, this);
5476 var kids = jqWrapper.contents();
5477 $(this).append( kids );
5482 /* Add the TR elements back into the table in their original order */
5483 if ( !bRemove && oSettings.nTableReinsertBefore )
5485 nOrig.insertBefore( oSettings.nTable, oSettings.nTableReinsertBefore );
5487 else if ( !bRemove )
5489 nOrig.appendChild( oSettings.nTable );
5492 for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
5494 if ( oSettings.aoData[i].nTr !== null )
5496 nBody.appendChild( oSettings.aoData[i].nTr );
5500 /* Restore the width of the original table */
5501 if ( oSettings.oFeatures.bAutoWidth === true )
5503 oSettings.nTable.style.width = _fnStringToCss(oSettings.sDestroyWidth);
5506 /* If the were originally stripe classes - then we add them back here. Note
5507 * this is not fool proof (for example if not all rows had stripe classes - but
5508 * it's a good effort without getting carried away
5510 iLen = oSettings.asDestroyStripes.length;
5513 var anRows = $(nBody).children('tr');
5514 for ( i=0 ; i<iLen ; i++ )
5516 anRows.filter(':nth-child(' + iLen + 'n + ' + i + ')').addClass( oSettings.asDestroyStripes[i] );
5520 /* Remove the settings object from the settings array */
5521 for ( i=0, iLen=DataTable.settings.length ; i<iLen ; i++ )
5523 if ( DataTable.settings[i] == oSettings )
5525 DataTable.settings.splice( i, 1 );
5537 * @param {bool} [bComplete=true] Re-filter and resort (if enabled) the table before the draw.
5541 * $(document).ready(function() {
5542 * var oTable = $('#example').dataTable();
5544 * // Re-draw the table - you wouldn't want to do it here, but it's an example :-)
5548 this.fnDraw = function( bComplete )
5550 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5551 if ( bComplete === false )
5553 _fnCalculateEnd( oSettings );
5554 _fnDraw( oSettings );
5558 _fnReDraw( oSettings );
5564 * Filter the input based on data
5565 * @param {string} sInput String to filter the table on
5566 * @param {int|null} [iColumn] Column to limit filtering to
5567 * @param {bool} [bRegex=false] Treat as regular expression or not
5568 * @param {bool} [bSmart=true] Perform smart filtering or not
5569 * @param {bool} [bShowGlobal=true] Show the input global filter in it's input box(es)
5570 * @param {bool} [bCaseInsensitive=true] Do case-insensitive matching (true) or not (false)
5574 * $(document).ready(function() {
5575 * var oTable = $('#example').dataTable();
5577 * // Sometime later - filter...
5578 * oTable.fnFilter( 'test string' );
5581 this.fnFilter = function( sInput, iColumn, bRegex, bSmart, bShowGlobal, bCaseInsensitive )
5583 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5585 if ( !oSettings.oFeatures.bFilter )
5590 if ( bRegex === undefined || bRegex === null )
5595 if ( bSmart === undefined || bSmart === null )
5600 if ( bShowGlobal === undefined || bShowGlobal === null )
5605 if ( bCaseInsensitive === undefined || bCaseInsensitive === null )
5607 bCaseInsensitive = true;
5610 if ( iColumn === undefined || iColumn === null )
5613 _fnFilterComplete( oSettings, {
5614 "sSearch":sInput+"",
5617 "bCaseInsensitive": bCaseInsensitive
5620 if ( bShowGlobal && oSettings.aanFeatures.f )
5622 var n = oSettings.aanFeatures.f;
5623 for ( var i=0, iLen=n.length ; i<iLen ; i++ )
5625 // IE9 throws an 'unknown error' if document.activeElement is used
5626 // inside an iframe or frame...
5628 if ( n[i]._DT_Input != document.activeElement )
5630 $(n[i]._DT_Input).val( sInput );
5634 $(n[i]._DT_Input).val( sInput );
5641 /* Single column filter */
5642 $.extend( oSettings.aoPreSearchCols[ iColumn ], {
5643 "sSearch": sInput+"",
5646 "bCaseInsensitive": bCaseInsensitive
5648 _fnFilterComplete( oSettings, oSettings.oPreviousSearch, 1 );
5654 * Get the data for the whole table, an individual row or an individual cell based on the
5655 * provided parameters.
5656 * @param {int|node} [mRow] A TR row node, TD/TH cell node or an integer. If given as
5657 * a TR node then the data source for the whole row will be returned. If given as a
5658 * TD/TH cell node then iCol will be automatically calculated and the data for the
5659 * cell returned. If given as an integer, then this is treated as the aoData internal
5660 * data index for the row (see fnGetPosition) and the data for that row used.
5661 * @param {int} [iCol] Optional column index that you want the data of.
5662 * @returns {array|object|string} If mRow is undefined, then the data for all rows is
5663 * returned. If mRow is defined, just data for that row, and is iCol is
5664 * defined, only data for the designated cell is returned.
5669 * $(document).ready(function() {
5670 * oTable = $('#example').dataTable();
5672 * oTable.$('tr').click( function () {
5673 * var data = oTable.fnGetData( this );
5674 * // ... do something with the array / object of data for the row
5679 * // Individual cell data
5680 * $(document).ready(function() {
5681 * oTable = $('#example').dataTable();
5683 * oTable.$('td').click( function () {
5684 * var sData = oTable.fnGetData( this );
5685 * alert( 'The cell clicked on had the value of '+sData );
5689 this.fnGetData = function( mRow, iCol )
5691 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5693 if ( mRow !== undefined )
5696 if ( typeof mRow === 'object' )
5698 var sNode = mRow.nodeName.toLowerCase();
5699 if (sNode === "tr" )
5701 iRow = _fnNodeToDataIndex(oSettings, mRow);
5703 else if ( sNode === "td" )
5705 iRow = _fnNodeToDataIndex(oSettings, mRow.parentNode);
5706 iCol = _fnNodeToColumnIndex( oSettings, iRow, mRow );
5710 if ( iCol !== undefined )
5712 return _fnGetCellData( oSettings, iRow, iCol, '' );
5714 return (oSettings.aoData[iRow]!==undefined) ?
5715 oSettings.aoData[iRow]._aData : null;
5717 return _fnGetDataMaster( oSettings );
5722 * Get an array of the TR nodes that are used in the table's body. Note that you will
5723 * typically want to use the '$' API method in preference to this as it is more
5725 * @param {int} [iRow] Optional row index for the TR element you want
5726 * @returns {array|node} If iRow is undefined, returns an array of all TR elements
5727 * in the table's body, or iRow is defined, just the TR element requested.
5731 * $(document).ready(function() {
5732 * var oTable = $('#example').dataTable();
5734 * // Get the nodes from the table
5735 * var nNodes = oTable.fnGetNodes( );
5738 this.fnGetNodes = function( iRow )
5740 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5742 if ( iRow !== undefined ) {
5743 return (oSettings.aoData[iRow]!==undefined) ?
5744 oSettings.aoData[iRow].nTr : null;
5746 return _fnGetTrNodes( oSettings );
5751 * Get the array indexes of a particular cell from it's DOM element
5752 * and column index including hidden columns
5753 * @param {node} nNode this can either be a TR, TD or TH in the table's body
5754 * @returns {int} If nNode is given as a TR, then a single index is returned, or
5755 * if given as a cell, an array of [row index, column index (visible),
5756 * column index (all)] is given.
5760 * $(document).ready(function() {
5761 * $('#example tbody td').click( function () {
5762 * // Get the position of the current data from the node
5763 * var aPos = oTable.fnGetPosition( this );
5765 * // Get the data array for this row
5766 * var aData = oTable.fnGetData( aPos[0] );
5768 * // Update the data array and return the value
5769 * aData[ aPos[1] ] = 'clicked';
5770 * this.innerHTML = 'clicked';
5773 * // Init DataTables
5774 * oTable = $('#example').dataTable();
5777 this.fnGetPosition = function( nNode )
5779 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5780 var sNodeName = nNode.nodeName.toUpperCase();
5782 if ( sNodeName == "TR" )
5784 return _fnNodeToDataIndex(oSettings, nNode);
5786 else if ( sNodeName == "TD" || sNodeName == "TH" )
5788 var iDataIndex = _fnNodeToDataIndex( oSettings, nNode.parentNode );
5789 var iColumnIndex = _fnNodeToColumnIndex( oSettings, iDataIndex, nNode );
5790 return [ iDataIndex, _fnColumnIndexToVisible(oSettings, iColumnIndex ), iColumnIndex ];
5797 * Check to see if a row is 'open' or not.
5798 * @param {node} nTr the table row to check
5799 * @returns {boolean} true if the row is currently open, false otherwise
5803 * $(document).ready(function() {
5806 * // 'open' an information row when a row is clicked on
5807 * $('#example tbody tr').click( function () {
5808 * if ( oTable.fnIsOpen(this) ) {
5809 * oTable.fnClose( this );
5811 * oTable.fnOpen( this, "Temporary row opened", "info_row" );
5815 * oTable = $('#example').dataTable();
5818 this.fnIsOpen = function( nTr )
5820 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5821 var aoOpenRows = oSettings.aoOpenRows;
5823 for ( var i=0 ; i<oSettings.aoOpenRows.length ; i++ )
5825 if ( oSettings.aoOpenRows[i].nParent == nTr )
5835 * This function will place a new row directly after a row which is currently
5836 * on display on the page, with the HTML contents that is passed into the
5837 * function. This can be used, for example, to ask for confirmation that a
5838 * particular record should be deleted.
5839 * @param {node} nTr The table row to 'open'
5840 * @param {string|node|jQuery} mHtml The HTML to put into the row
5841 * @param {string} sClass Class to give the new TD cell
5842 * @returns {node} The row opened. Note that if the table row passed in as the
5843 * first parameter, is not found in the table, this method will silently
5848 * $(document).ready(function() {
5851 * // 'open' an information row when a row is clicked on
5852 * $('#example tbody tr').click( function () {
5853 * if ( oTable.fnIsOpen(this) ) {
5854 * oTable.fnClose( this );
5856 * oTable.fnOpen( this, "Temporary row opened", "info_row" );
5860 * oTable = $('#example').dataTable();
5863 this.fnOpen = function( nTr, mHtml, sClass )
5865 /* Find settings from table node */
5866 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5868 /* Check that the row given is in the table */
5869 var nTableRows = _fnGetTrNodes( oSettings );
5870 if ( $.inArray(nTr, nTableRows) === -1 )
5875 /* the old open one if there is one */
5876 this.fnClose( nTr );
5878 var nNewRow = document.createElement("tr");
5879 var nNewCell = document.createElement("td");
5880 nNewRow.appendChild( nNewCell );
5881 nNewCell.className = sClass;
5882 nNewCell.colSpan = _fnVisbleColumns( oSettings );
5884 if (typeof mHtml === "string")
5886 nNewCell.innerHTML = mHtml;
5890 $(nNewCell).html( mHtml );
5893 /* If the nTr isn't on the page at the moment - then we don't insert at the moment */
5894 var nTrs = $('tr', oSettings.nTBody);
5895 if ( $.inArray(nTr, nTrs) != -1 )
5897 $(nNewRow).insertAfter(nTr);
5900 oSettings.aoOpenRows.push( {
5910 * Change the pagination - provides the internal logic for pagination in a simple API
5911 * function. With this function you can have a DataTables table go to the next,
5912 * previous, first or last pages.
5913 * @param {string|int} mAction Paging action to take: "first", "previous", "next" or "last"
5914 * or page number to jump to (integer), note that page 0 is the first page.
5915 * @param {bool} [bRedraw=true] Redraw the table or not
5919 * $(document).ready(function() {
5920 * var oTable = $('#example').dataTable();
5921 * oTable.fnPageChange( 'next' );
5924 this.fnPageChange = function ( mAction, bRedraw )
5926 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5927 _fnPageChange( oSettings, mAction );
5928 _fnCalculateEnd( oSettings );
5930 if ( bRedraw === undefined || bRedraw )
5932 _fnDraw( oSettings );
5938 * Show a particular column
5939 * @param {int} iCol The column whose display should be changed
5940 * @param {bool} bShow Show (true) or hide (false) the column
5941 * @param {bool} [bRedraw=true] Redraw the table or not
5945 * $(document).ready(function() {
5946 * var oTable = $('#example').dataTable();
5948 * // Hide the second column after initialisation
5949 * oTable.fnSetColumnVis( 1, false );
5952 this.fnSetColumnVis = function ( iCol, bShow, bRedraw )
5954 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5956 var aoColumns = oSettings.aoColumns;
5957 var aoData = oSettings.aoData;
5958 var nTd, bAppend, iBefore;
5960 /* No point in doing anything if we are requesting what is already true */
5961 if ( aoColumns[iCol].bVisible == bShow )
5966 /* Show the column */
5970 for ( i=0 ; i<iCol ; i++ )
5972 if ( aoColumns[i].bVisible )
5978 /* Need to decide if we should use appendChild or insertBefore */
5979 bAppend = (iInsert >= _fnVisbleColumns( oSettings ));
5981 /* Which coloumn should we be inserting before? */
5984 for ( i=iCol ; i<aoColumns.length ; i++ )
5986 if ( aoColumns[i].bVisible )
5994 for ( i=0, iLen=aoData.length ; i<iLen ; i++ )
5996 if ( aoData[i].nTr !== null )
6000 aoData[i].nTr.appendChild(
6001 aoData[i]._anHidden[iCol]
6006 aoData[i].nTr.insertBefore(
6007 aoData[i]._anHidden[iCol],
6008 _fnGetTdNodes( oSettings, i )[iBefore] );
6015 /* Remove a column from display */
6016 for ( i=0, iLen=aoData.length ; i<iLen ; i++ )
6018 if ( aoData[i].nTr !== null )
6020 nTd = _fnGetTdNodes( oSettings, i )[iCol];
6021 aoData[i]._anHidden[iCol] = nTd;
6022 nTd.parentNode.removeChild( nTd );
6027 /* Clear to set the visible flag */
6028 aoColumns[iCol].bVisible = bShow;
6030 /* Redraw the header and footer based on the new column visibility */
6031 _fnDrawHead( oSettings, oSettings.aoHeader );
6032 if ( oSettings.nTFoot )
6034 _fnDrawHead( oSettings, oSettings.aoFooter );
6037 /* If there are any 'open' rows, then we need to alter the colspan for this col change */
6038 for ( i=0, iLen=oSettings.aoOpenRows.length ; i<iLen ; i++ )
6040 oSettings.aoOpenRows[i].nTr.colSpan = _fnVisbleColumns( oSettings );
6043 /* Do a redraw incase anything depending on the table columns needs it
6044 * (built-in: scrolling)
6046 if ( bRedraw === undefined || bRedraw )
6048 _fnAdjustColumnSizing( oSettings );
6049 _fnDraw( oSettings );
6052 _fnSaveState( oSettings );
6057 * Get the settings for a particular table for external manipulation
6058 * @returns {object} DataTables settings object. See
6059 * {@link DataTable.models.oSettings}
6063 * $(document).ready(function() {
6064 * var oTable = $('#example').dataTable();
6065 * var oSettings = oTable.fnSettings();
6067 * // Show an example parameter from the settings
6068 * alert( oSettings._iDisplayStart );
6071 this.fnSettings = function()
6073 return _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
6078 * Sort the table by a particular column
6079 * @param {int} iCol the data index to sort on. Note that this will not match the
6080 * 'display index' if you have hidden data entries
6084 * $(document).ready(function() {
6085 * var oTable = $('#example').dataTable();
6087 * // Sort immediately with columns 0 and 1
6088 * oTable.fnSort( [ [0,'asc'], [1,'asc'] ] );
6091 this.fnSort = function( aaSort )
6093 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
6094 oSettings.aaSorting = aaSort;
6095 _fnSort( oSettings );
6100 * Attach a sort listener to an element for a given column
6101 * @param {node} nNode the element to attach the sort listener to
6102 * @param {int} iColumn the column that a click on this node will sort on
6103 * @param {function} [fnCallback] callback function when sort is run
6107 * $(document).ready(function() {
6108 * var oTable = $('#example').dataTable();
6110 * // Sort on column 1, when 'sorter' is clicked on
6111 * oTable.fnSortListener( document.getElementById('sorter'), 1 );
6114 this.fnSortListener = function( nNode, iColumn, fnCallback )
6116 _fnSortAttachListener( _fnSettingsFromNode( this[DataTable.ext.iApiIndex] ), nNode, iColumn,
6122 * Update a table cell or row - this method will accept either a single value to
6123 * update the cell with, an array of values with one element for each column or
6124 * an object in the same format as the original data source. The function is
6125 * self-referencing in order to make the multi column updates easier.
6126 * @param {object|array|string} mData Data to update the cell/row with
6127 * @param {node|int} mRow TR element you want to update or the aoData index
6128 * @param {int} [iColumn] The column to update (not used of mData is an array or object)
6129 * @param {bool} [bRedraw=true] Redraw the table or not
6130 * @param {bool} [bAction=true] Perform pre-draw actions or not
6131 * @returns {int} 0 on success, 1 on error
6135 * $(document).ready(function() {
6136 * var oTable = $('#example').dataTable();
6137 * oTable.fnUpdate( 'Example update', 0, 0 ); // Single cell
6138 * oTable.fnUpdate( ['a', 'b', 'c', 'd', 'e'], 1, 0 ); // Row
6141 this.fnUpdate = function( mData, mRow, iColumn, bRedraw, bAction )
6143 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
6144 var i, iLen, sDisplay;
6145 var iRow = (typeof mRow === 'object') ?
6146 _fnNodeToDataIndex(oSettings, mRow) : mRow;
6148 if ( $.isArray(mData) && iColumn === undefined )
6150 /* Array update - update the whole row */
6151 oSettings.aoData[iRow]._aData = mData.slice();
6153 /* Flag to the function that we are recursing */
6154 for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
6156 this.fnUpdate( _fnGetCellData( oSettings, iRow, i ), iRow, i, false, false );
6159 else if ( $.isPlainObject(mData) && iColumn === undefined )
6161 /* Object update - update the whole row - assume the developer gets the object right */
6162 oSettings.aoData[iRow]._aData = $.extend( true, {}, mData );
6164 for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
6166 this.fnUpdate( _fnGetCellData( oSettings, iRow, i ), iRow, i, false, false );
6171 /* Individual cell update */
6172 _fnSetCellData( oSettings, iRow, iColumn, mData );
6173 sDisplay = _fnGetCellData( oSettings, iRow, iColumn, 'display' );
6175 var oCol = oSettings.aoColumns[iColumn];
6176 if ( oCol.fnRender !== null )
6178 sDisplay = _fnRender( oSettings, iRow, iColumn );
6179 if ( oCol.bUseRendered )
6181 _fnSetCellData( oSettings, iRow, iColumn, sDisplay );
6185 if ( oSettings.aoData[iRow].nTr !== null )
6187 /* Do the actual HTML update */
6188 _fnGetTdNodes( oSettings, iRow )[iColumn].innerHTML = sDisplay;
6192 /* Modify the search index for this row (strictly this is likely not needed, since fnReDraw
6193 * will rebuild the search array - however, the redraw might be disabled by the user)
6195 var iDisplayIndex = $.inArray( iRow, oSettings.aiDisplay );
6196 oSettings.asDataSearch[iDisplayIndex] = _fnBuildSearchRow(
6198 _fnGetRowData( oSettings, iRow, 'filter', _fnGetColumns( oSettings, 'bSearchable' ) )
6201 /* Perform pre-draw actions */
6202 if ( bAction === undefined || bAction )
6204 _fnAdjustColumnSizing( oSettings );
6207 /* Redraw the table */
6208 if ( bRedraw === undefined || bRedraw )
6210 _fnReDraw( oSettings );
6217 * Provide a common method for plug-ins to check the version of DataTables being used, in order
6218 * to ensure compatibility.
6219 * @param {string} sVersion Version string to check for, in the format "X.Y.Z". Note that the
6220 * formats "X" and "X.Y" are also acceptable.
6221 * @returns {boolean} true if this version of DataTables is greater or equal to the required
6222 * version, or false if this version of DataTales is not suitable
6227 * $(document).ready(function() {
6228 * var oTable = $('#example').dataTable();
6229 * alert( oTable.fnVersionCheck( '1.9.0' ) );
6232 this.fnVersionCheck = DataTable.ext.fnVersionCheck;
6236 * This is really a good bit rubbish this method of exposing the internal methods
6237 * publicly... - To be fixed in 2.0 using methods on the prototype
6242 * Create a wrapper function for exporting an internal functions to an external API.
6243 * @param {string} sFunc API function name
6244 * @returns {function} wrapped function
6245 * @memberof DataTable#oApi
6247 function _fnExternApiFunc (sFunc)
6250 var aArgs = [_fnSettingsFromNode(this[DataTable.ext.iApiIndex])].concat(
6251 Array.prototype.slice.call(arguments) );
6252 return DataTable.ext.oApi[sFunc].apply( this, aArgs );
6258 * Reference to internal functions for use by plug-in developers. Note that these
6259 * methods are references to internal functions and are considered to be private.
6260 * If you use these methods, be aware that they are liable to change between versions
6261 * (check the upgrade notes).
6265 "_fnExternApiFunc": _fnExternApiFunc,
6266 "_fnInitialise": _fnInitialise,
6267 "_fnInitComplete": _fnInitComplete,
6268 "_fnLanguageCompat": _fnLanguageCompat,
6269 "_fnAddColumn": _fnAddColumn,
6270 "_fnColumnOptions": _fnColumnOptions,
6271 "_fnAddData": _fnAddData,
6272 "_fnCreateTr": _fnCreateTr,
6273 "_fnGatherData": _fnGatherData,
6274 "_fnBuildHead": _fnBuildHead,
6275 "_fnDrawHead": _fnDrawHead,
6277 "_fnReDraw": _fnReDraw,
6278 "_fnAjaxUpdate": _fnAjaxUpdate,
6279 "_fnAjaxParameters": _fnAjaxParameters,
6280 "_fnAjaxUpdateDraw": _fnAjaxUpdateDraw,
6281 "_fnServerParams": _fnServerParams,
6282 "_fnAddOptionsHtml": _fnAddOptionsHtml,
6283 "_fnFeatureHtmlTable": _fnFeatureHtmlTable,
6284 "_fnScrollDraw": _fnScrollDraw,
6285 "_fnAdjustColumnSizing": _fnAdjustColumnSizing,
6286 "_fnFeatureHtmlFilter": _fnFeatureHtmlFilter,
6287 "_fnFilterComplete": _fnFilterComplete,
6288 "_fnFilterCustom": _fnFilterCustom,
6289 "_fnFilterColumn": _fnFilterColumn,
6290 "_fnFilter": _fnFilter,
6291 "_fnBuildSearchArray": _fnBuildSearchArray,
6292 "_fnBuildSearchRow": _fnBuildSearchRow,
6293 "_fnFilterCreateSearch": _fnFilterCreateSearch,
6294 "_fnDataToSearch": _fnDataToSearch,
6296 "_fnSortAttachListener": _fnSortAttachListener,
6297 "_fnSortingClasses": _fnSortingClasses,
6298 "_fnFeatureHtmlPaginate": _fnFeatureHtmlPaginate,
6299 "_fnPageChange": _fnPageChange,
6300 "_fnFeatureHtmlInfo": _fnFeatureHtmlInfo,
6301 "_fnUpdateInfo": _fnUpdateInfo,
6302 "_fnFeatureHtmlLength": _fnFeatureHtmlLength,
6303 "_fnFeatureHtmlProcessing": _fnFeatureHtmlProcessing,
6304 "_fnProcessingDisplay": _fnProcessingDisplay,
6305 "_fnVisibleToColumnIndex": _fnVisibleToColumnIndex,
6306 "_fnColumnIndexToVisible": _fnColumnIndexToVisible,
6307 "_fnNodeToDataIndex": _fnNodeToDataIndex,
6308 "_fnVisbleColumns": _fnVisbleColumns,
6309 "_fnCalculateEnd": _fnCalculateEnd,
6310 "_fnConvertToWidth": _fnConvertToWidth,
6311 "_fnCalculateColumnWidths": _fnCalculateColumnWidths,
6312 "_fnScrollingWidthAdjust": _fnScrollingWidthAdjust,
6313 "_fnGetWidestNode": _fnGetWidestNode,
6314 "_fnGetMaxLenString": _fnGetMaxLenString,
6315 "_fnStringToCss": _fnStringToCss,
6316 "_fnDetectType": _fnDetectType,
6317 "_fnSettingsFromNode": _fnSettingsFromNode,
6318 "_fnGetDataMaster": _fnGetDataMaster,
6319 "_fnGetTrNodes": _fnGetTrNodes,
6320 "_fnGetTdNodes": _fnGetTdNodes,
6321 "_fnEscapeRegex": _fnEscapeRegex,
6322 "_fnDeleteIndex": _fnDeleteIndex,
6323 "_fnReOrderIndex": _fnReOrderIndex,
6324 "_fnColumnOrdering": _fnColumnOrdering,
6326 "_fnClearTable": _fnClearTable,
6327 "_fnSaveState": _fnSaveState,
6328 "_fnLoadState": _fnLoadState,
6329 "_fnCreateCookie": _fnCreateCookie,
6330 "_fnReadCookie": _fnReadCookie,
6331 "_fnDetectHeader": _fnDetectHeader,
6332 "_fnGetUniqueThs": _fnGetUniqueThs,
6333 "_fnScrollBarWidth": _fnScrollBarWidth,
6334 "_fnApplyToChildren": _fnApplyToChildren,
6336 "_fnGetRowData": _fnGetRowData,
6337 "_fnGetCellData": _fnGetCellData,
6338 "_fnSetCellData": _fnSetCellData,
6339 "_fnGetObjectDataFn": _fnGetObjectDataFn,
6340 "_fnSetObjectDataFn": _fnSetObjectDataFn,
6341 "_fnApplyColumnDefs": _fnApplyColumnDefs,
6342 "_fnBindAction": _fnBindAction,
6343 "_fnExtend": _fnExtend,
6344 "_fnCallbackReg": _fnCallbackReg,
6345 "_fnCallbackFire": _fnCallbackFire,
6346 "_fnJsonString": _fnJsonString,
6347 "_fnRender": _fnRender,
6348 "_fnNodeToColumnIndex": _fnNodeToColumnIndex,
6349 "_fnInfoMacros": _fnInfoMacros,
6350 "_fnBrowserDetect": _fnBrowserDetect,
6351 "_fnGetColumns": _fnGetColumns
6354 $.extend( DataTable.ext.oApi, this.oApi );
6356 for ( var sFunc in DataTable.ext.oApi )
6360 this[sFunc] = _fnExternApiFunc(sFunc);
6366 this.each(function() {
6367 var i=0, iLen, j, jLen, k, kLen;
6368 var sId = this.getAttribute( 'id' );
6369 var bInitHandedOff = false;
6370 var bUsePassedData = false;
6374 if ( this.nodeName.toLowerCase() != 'table' )
6376 _fnLog( null, 0, "Attempted to initialise DataTables on a node which is not a "+
6377 "table: "+this.nodeName );
6381 /* Check to see if we are re-initialising a table */
6382 for ( i=0, iLen=DataTable.settings.length ; i<iLen ; i++ )
6384 /* Base check on table node */
6385 if ( DataTable.settings[i].nTable == this )
6387 if ( oInit === undefined || oInit.bRetrieve )
6389 return DataTable.settings[i].oInstance;
6391 else if ( oInit.bDestroy )
6393 DataTable.settings[i].oInstance.fnDestroy();
6398 _fnLog( DataTable.settings[i], 0, "Cannot reinitialise DataTable.\n\n"+
6399 "To retrieve the DataTables object for this table, pass no arguments or see "+
6400 "the docs for bRetrieve and bDestroy" );
6405 /* If the element we are initialising has the same ID as a table which was previously
6406 * initialised, but the table nodes don't match (from before) then we destroy the old
6407 * instance by simply deleting it. This is under the assumption that the table has been
6408 * destroyed by other methods. Anyone using non-id selectors will need to do this manually
6410 if ( DataTable.settings[i].sTableId == this.id )
6412 DataTable.settings.splice( i, 1 );
6417 /* Ensure the table has an ID - required for accessibility */
6418 if ( sId === null || sId === "" )
6420 sId = "DataTables_Table_"+(DataTable.ext._oExternConfig.iNextUnique++);
6424 /* Create the settings object for this table and set some of the default parameters */
6425 var oSettings = $.extend( true, {}, DataTable.models.oSettings, {
6429 "sDestroyWidth": $(this).width(),
6433 DataTable.settings.push( oSettings );
6435 // Need to add the instance after the instance after the settings object has been added
6436 // to the settings array, so we can self reference the table instance if more than one
6437 oSettings.oInstance = (_that.length===1) ? _that : $(this).dataTable();
6439 /* Setting up the initialisation object */
6445 // Backwards compatibility, before we apply all the defaults
6446 if ( oInit.oLanguage )
6448 _fnLanguageCompat( oInit.oLanguage );
6451 oInit = _fnExtend( $.extend(true, {}, DataTable.defaults), oInit );
6453 // Map the initialisation options onto the settings object
6454 _fnMap( oSettings.oFeatures, oInit, "bPaginate" );
6455 _fnMap( oSettings.oFeatures, oInit, "bLengthChange" );
6456 _fnMap( oSettings.oFeatures, oInit, "bFilter" );
6457 _fnMap( oSettings.oFeatures, oInit, "bSort" );
6458 _fnMap( oSettings.oFeatures, oInit, "bInfo" );
6459 _fnMap( oSettings.oFeatures, oInit, "bProcessing" );
6460 _fnMap( oSettings.oFeatures, oInit, "bAutoWidth" );
6461 _fnMap( oSettings.oFeatures, oInit, "bSortClasses" );
6462 _fnMap( oSettings.oFeatures, oInit, "bServerSide" );
6463 _fnMap( oSettings.oFeatures, oInit, "bDeferRender" );
6464 _fnMap( oSettings.oScroll, oInit, "sScrollX", "sX" );
6465 _fnMap( oSettings.oScroll, oInit, "sScrollXInner", "sXInner" );
6466 _fnMap( oSettings.oScroll, oInit, "sScrollY", "sY" );
6467 _fnMap( oSettings.oScroll, oInit, "bScrollCollapse", "bCollapse" );
6468 _fnMap( oSettings.oScroll, oInit, "bScrollInfinite", "bInfinite" );
6469 _fnMap( oSettings.oScroll, oInit, "iScrollLoadGap", "iLoadGap" );
6470 _fnMap( oSettings.oScroll, oInit, "bScrollAutoCss", "bAutoCss" );
6471 _fnMap( oSettings, oInit, "asStripeClasses" );
6472 _fnMap( oSettings, oInit, "asStripClasses", "asStripeClasses" ); // legacy
6473 _fnMap( oSettings, oInit, "fnServerData" );
6474 _fnMap( oSettings, oInit, "fnFormatNumber" );
6475 _fnMap( oSettings, oInit, "sServerMethod" );
6476 _fnMap( oSettings, oInit, "aaSorting" );
6477 _fnMap( oSettings, oInit, "aaSortingFixed" );
6478 _fnMap( oSettings, oInit, "aLengthMenu" );
6479 _fnMap( oSettings, oInit, "sPaginationType" );
6480 _fnMap( oSettings, oInit, "sAjaxSource" );
6481 _fnMap( oSettings, oInit, "sAjaxDataProp" );
6482 _fnMap( oSettings, oInit, "iCookieDuration" );
6483 _fnMap( oSettings, oInit, "sCookiePrefix" );
6484 _fnMap( oSettings, oInit, "sDom" );
6485 _fnMap( oSettings, oInit, "bSortCellsTop" );
6486 _fnMap( oSettings, oInit, "iTabIndex" );
6487 _fnMap( oSettings, oInit, "oSearch", "oPreviousSearch" );
6488 _fnMap( oSettings, oInit, "aoSearchCols", "aoPreSearchCols" );
6489 _fnMap( oSettings, oInit, "iDisplayLength", "_iDisplayLength" );
6490 _fnMap( oSettings, oInit, "bJQueryUI", "bJUI" );
6491 _fnMap( oSettings, oInit, "fnCookieCallback" );
6492 _fnMap( oSettings, oInit, "fnStateLoad" );
6493 _fnMap( oSettings, oInit, "fnStateSave" );
6494 _fnMap( oSettings.oLanguage, oInit, "fnInfoCallback" );
6496 /* Callback functions which are array driven */
6497 _fnCallbackReg( oSettings, 'aoDrawCallback', oInit.fnDrawCallback, 'user' );
6498 _fnCallbackReg( oSettings, 'aoServerParams', oInit.fnServerParams, 'user' );
6499 _fnCallbackReg( oSettings, 'aoStateSaveParams', oInit.fnStateSaveParams, 'user' );
6500 _fnCallbackReg( oSettings, 'aoStateLoadParams', oInit.fnStateLoadParams, 'user' );
6501 _fnCallbackReg( oSettings, 'aoStateLoaded', oInit.fnStateLoaded, 'user' );
6502 _fnCallbackReg( oSettings, 'aoRowCallback', oInit.fnRowCallback, 'user' );
6503 _fnCallbackReg( oSettings, 'aoRowCreatedCallback', oInit.fnCreatedRow, 'user' );
6504 _fnCallbackReg( oSettings, 'aoHeaderCallback', oInit.fnHeaderCallback, 'user' );
6505 _fnCallbackReg( oSettings, 'aoFooterCallback', oInit.fnFooterCallback, 'user' );
6506 _fnCallbackReg( oSettings, 'aoInitComplete', oInit.fnInitComplete, 'user' );
6507 _fnCallbackReg( oSettings, 'aoPreDrawCallback', oInit.fnPreDrawCallback, 'user' );
6509 if ( oSettings.oFeatures.bServerSide && oSettings.oFeatures.bSort &&
6510 oSettings.oFeatures.bSortClasses )
6512 /* Enable sort classes for server-side processing. Safe to do it here, since server-side
6513 * processing must be enabled by the developer
6515 _fnCallbackReg( oSettings, 'aoDrawCallback', _fnSortingClasses, 'server_side_sort_classes' );
6517 else if ( oSettings.oFeatures.bDeferRender )
6519 _fnCallbackReg( oSettings, 'aoDrawCallback', _fnSortingClasses, 'defer_sort_classes' );
6522 if ( oInit.bJQueryUI )
6524 /* Use the JUI classes object for display. You could clone the oStdClasses object if
6525 * you want to have multiple tables with multiple independent classes
6527 $.extend( oSettings.oClasses, DataTable.ext.oJUIClasses );
6529 if ( oInit.sDom === DataTable.defaults.sDom && DataTable.defaults.sDom === "lfrtip" )
6531 /* Set the DOM to use a layout suitable for jQuery UI's theming */
6532 oSettings.sDom = '<"H"lfr>t<"F"ip>';
6537 $.extend( oSettings.oClasses, DataTable.ext.oStdClasses );
6539 $(this).addClass( oSettings.oClasses.sTable );
6541 /* Calculate the scroll bar width and cache it for use later on */
6542 if ( oSettings.oScroll.sX !== "" || oSettings.oScroll.sY !== "" )
6544 oSettings.oScroll.iBarWidth = _fnScrollBarWidth();
6547 if ( oSettings.iInitDisplayStart === undefined )
6549 /* Display start point, taking into account the save saving */
6550 oSettings.iInitDisplayStart = oInit.iDisplayStart;
6551 oSettings._iDisplayStart = oInit.iDisplayStart;
6554 /* Must be done after everything which can be overridden by a cookie! */
6555 if ( oInit.bStateSave )
6557 oSettings.oFeatures.bStateSave = true;
6558 _fnLoadState( oSettings, oInit );
6559 _fnCallbackReg( oSettings, 'aoDrawCallback', _fnSaveState, 'state_save' );
6562 if ( oInit.iDeferLoading !== null )
6564 oSettings.bDeferLoading = true;
6565 var tmp = $.isArray( oInit.iDeferLoading );
6566 oSettings._iRecordsDisplay = tmp ? oInit.iDeferLoading[0] : oInit.iDeferLoading;
6567 oSettings._iRecordsTotal = tmp ? oInit.iDeferLoading[1] : oInit.iDeferLoading;
6570 if ( oInit.aaData !== null )
6572 bUsePassedData = true;
6575 /* Language definitions */
6576 if ( oInit.oLanguage.sUrl !== "" )
6578 /* Get the language definitions from a file - because this Ajax call makes the language
6579 * get async to the remainder of this function we use bInitHandedOff to indicate that
6580 * _fnInitialise will be fired by the returned Ajax handler, rather than the constructor
6582 oSettings.oLanguage.sUrl = oInit.oLanguage.sUrl;
6583 $.getJSON( oSettings.oLanguage.sUrl, null, function( json ) {
6584 _fnLanguageCompat( json );
6585 $.extend( true, oSettings.oLanguage, oInit.oLanguage, json );
6586 _fnInitialise( oSettings );
6588 bInitHandedOff = true;
6592 $.extend( true, oSettings.oLanguage, oInit.oLanguage );
6599 if ( oInit.asStripeClasses === null )
6601 oSettings.asStripeClasses =[
6602 oSettings.oClasses.sStripeOdd,
6603 oSettings.oClasses.sStripeEven
6607 /* Remove row stripe classes if they are already on the table row */
6608 iLen=oSettings.asStripeClasses.length;
6609 oSettings.asDestroyStripes = [];
6612 var bStripeRemove = false;
6613 var anRows = $(this).children('tbody').children('tr:lt(' + iLen + ')');
6614 for ( i=0 ; i<iLen ; i++ )
6616 if ( anRows.hasClass( oSettings.asStripeClasses[i] ) )
6618 bStripeRemove = true;
6620 /* Store the classes which we are about to remove so they can be re-added on destroy */
6621 oSettings.asDestroyStripes.push( oSettings.asStripeClasses[i] );
6625 if ( bStripeRemove )
6627 anRows.removeClass( oSettings.asStripeClasses.join(' ') );
6633 * See if we should load columns automatically or use defined ones
6637 var nThead = this.getElementsByTagName('thead');
6638 if ( nThead.length !== 0 )
6640 _fnDetectHeader( oSettings.aoHeader, nThead[0] );
6641 anThs = _fnGetUniqueThs( oSettings );
6644 /* If not given a column array, generate one with nulls */
6645 if ( oInit.aoColumns === null )
6648 for ( i=0, iLen=anThs.length ; i<iLen ; i++ )
6650 aoColumnsInit.push( null );
6655 aoColumnsInit = oInit.aoColumns;
6658 /* Add the columns */
6659 for ( i=0, iLen=aoColumnsInit.length ; i<iLen ; i++ )
6661 /* Short cut - use the loop to check if we have column visibility state to restore */
6662 if ( oInit.saved_aoColumns !== undefined && oInit.saved_aoColumns.length == iLen )
6664 if ( aoColumnsInit[i] === null )
6666 aoColumnsInit[i] = {};
6668 aoColumnsInit[i].bVisible = oInit.saved_aoColumns[i].bVisible;
6671 _fnAddColumn( oSettings, anThs ? anThs[i] : null );
6674 /* Apply the column definitions */
6675 _fnApplyColumnDefs( oSettings, oInit.aoColumnDefs, aoColumnsInit, function (iCol, oDef) {
6676 _fnColumnOptions( oSettings, iCol, oDef );
6682 * Check the aaSorting array
6684 for ( i=0, iLen=oSettings.aaSorting.length ; i<iLen ; i++ )
6686 if ( oSettings.aaSorting[i][0] >= oSettings.aoColumns.length )
6688 oSettings.aaSorting[i][0] = 0;
6690 var oColumn = oSettings.aoColumns[ oSettings.aaSorting[i][0] ];
6692 /* Add a default sorting index */
6693 if ( oSettings.aaSorting[i][2] === undefined )
6695 oSettings.aaSorting[i][2] = 0;
6698 /* If aaSorting is not defined, then we use the first indicator in asSorting */
6699 if ( oInit.aaSorting === undefined && oSettings.saved_aaSorting === undefined )
6701 oSettings.aaSorting[i][1] = oColumn.asSorting[0];
6704 /* Set the current sorting index based on aoColumns.asSorting */
6705 for ( j=0, jLen=oColumn.asSorting.length ; j<jLen ; j++ )
6707 if ( oSettings.aaSorting[i][1] == oColumn.asSorting[j] )
6709 oSettings.aaSorting[i][2] = j;
6715 /* Do a first pass on the sorting classes (allows any size changes to be taken into
6716 * account, and also will apply sorting disabled classes if disabled
6718 _fnSortingClasses( oSettings );
6723 * Cache the header, body and footer as required, creating them if needed
6726 /* Browser support detection */
6727 _fnBrowserDetect( oSettings );
6729 // Work around for Webkit bug 83867 - store the caption-side before removing from doc
6730 var captions = $(this).children('caption').each( function () {
6731 this._captionSide = $(this).css('caption-side');
6734 var thead = $(this).children('thead');
6735 if ( thead.length === 0 )
6737 thead = [ document.createElement( 'thead' ) ];
6738 this.appendChild( thead[0] );
6740 oSettings.nTHead = thead[0];
6742 var tbody = $(this).children('tbody');
6743 if ( tbody.length === 0 )
6745 tbody = [ document.createElement( 'tbody' ) ];
6746 this.appendChild( tbody[0] );
6748 oSettings.nTBody = tbody[0];
6749 oSettings.nTBody.setAttribute( "role", "alert" );
6750 oSettings.nTBody.setAttribute( "aria-live", "polite" );
6751 oSettings.nTBody.setAttribute( "aria-relevant", "all" );
6753 var tfoot = $(this).children('tfoot');
6754 if ( tfoot.length === 0 && captions.length > 0 && (oSettings.oScroll.sX !== "" || oSettings.oScroll.sY !== "") )
6756 // If we are a scrolling table, and no footer has been given, then we need to create
6757 // a tfoot element for the caption element to be appended to
6758 tfoot = [ document.createElement( 'tfoot' ) ];
6759 this.appendChild( tfoot[0] );
6762 if ( tfoot.length > 0 )
6764 oSettings.nTFoot = tfoot[0];
6765 _fnDetectHeader( oSettings.aoFooter, oSettings.nTFoot );
6768 /* Check if there is data passing into the constructor */
6769 if ( bUsePassedData )
6771 for ( i=0 ; i<oInit.aaData.length ; i++ )
6773 _fnAddData( oSettings, oInit.aaData[ i ] );
6778 /* Grab the data from the page */
6779 _fnGatherData( oSettings );
6782 /* Copy the data index array */
6783 oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
6785 /* Initialisation complete - table can be drawn */
6786 oSettings.bInitialised = true;
6788 /* Check if we need to initialise the table (it might not have been handed off to the
6789 * language processor)
6791 if ( bInitHandedOff === false )
6793 _fnInitialise( oSettings );
6803 * Provide a common method for plug-ins to check the version of DataTables being used, in order
6804 * to ensure compatibility.
6805 * @param {string} sVersion Version string to check for, in the format "X.Y.Z". Note that the
6806 * formats "X" and "X.Y" are also acceptable.
6807 * @returns {boolean} true if this version of DataTables is greater or equal to the required
6808 * version, or false if this version of DataTales is not suitable
6813 * alert( $.fn.dataTable.fnVersionCheck( '1.9.0' ) );
6815 DataTable.fnVersionCheck = function( sVersion )
6817 /* This is cheap, but effective */
6818 var fnZPad = function (Zpad, count)
6820 while(Zpad.length < count) {
6825 var aThis = DataTable.ext.sVersion.split('.');
6826 var aThat = sVersion.split('.');
6827 var sThis = '', sThat = '';
6829 for ( var i=0, iLen=aThat.length ; i<iLen ; i++ )
6831 sThis += fnZPad( aThis[i], 3 );
6832 sThat += fnZPad( aThat[i], 3 );
6835 return parseInt(sThis, 10) >= parseInt(sThat, 10);
6840 * Check if a TABLE node is a DataTable table already or not.
6841 * @param {node} nTable The TABLE node to check if it is a DataTable or not (note that other
6842 * node types can be passed in, but will always return false).
6843 * @returns {boolean} true the table given is a DataTable, or false otherwise
6848 * var ex = document.getElementById('example');
6849 * if ( ! $.fn.DataTable.fnIsDataTable( ex ) ) {
6850 * $(ex).dataTable();
6853 DataTable.fnIsDataTable = function ( nTable )
6855 var o = DataTable.settings;
6857 for ( var i=0 ; i<o.length ; i++ )
6859 if ( o[i].nTable === nTable || o[i].nScrollHead === nTable || o[i].nScrollFoot === nTable )
6870 * Get all DataTable tables that have been initialised - optionally you can select to
6871 * get only currently visible tables.
6872 * @param {boolean} [bVisible=false] Flag to indicate if you want all (default) or
6873 * visible tables only.
6874 * @returns {array} Array of TABLE nodes (not DataTable instances) which are DataTables
6879 * var table = $.fn.dataTable.fnTables(true);
6880 * if ( table.length > 0 ) {
6881 * $(table).dataTable().fnAdjustColumnSizing();
6884 DataTable.fnTables = function ( bVisible )
6888 jQuery.each( DataTable.settings, function (i, o) {
6889 if ( !bVisible || (bVisible === true && $(o.nTable).is(':visible')) )
6891 out.push( o.nTable );
6900 * Version string for plug-ins to check compatibility. Allowed format is
6901 * a.b.c.d.e where: a:int, b:int, c:int, d:string(dev|beta), e:int. d and
6905 * @default Version number
6907 DataTable.version = "1.9.4";
6910 * Private data store, containing all of the settings objects that are created for the
6911 * tables on a given page.
6913 * Note that the <i>DataTable.settings</i> object is aliased to <i>jQuery.fn.dataTableExt</i>
6914 * through which it may be accessed and manipulated, or <i>jQuery.fn.dataTable.settings</i>.
6920 DataTable.settings = [];
6923 * Object models container, for the various models that DataTables has available
6924 * to it. These models define the objects that are used to hold the active state
6925 * and configuration of the table.
6928 DataTable.models = {};
6932 * DataTables extension options and plug-ins. This namespace acts as a collection "area"
6933 * for plug-ins that can be used to extend the default DataTables behaviour - indeed many
6934 * of the build in methods use this method to provide their own capabilities (sorting methods
6937 * Note that this namespace is aliased to jQuery.fn.dataTableExt so it can be readily accessed
6938 * and modified by plug-ins.
6941 DataTable.models.ext = {
6943 * Plug-in filtering functions - this method of filtering is complimentary to the default
6944 * type based filtering, and a lot more comprehensive as it allows you complete control
6945 * over the filtering logic. Each element in this array is a function (parameters
6946 * described below) that is called for every row in the table, and your logic decides if
6947 * it should be included in the filtered data set or not.
6950 * Function input parameters:
6952 * <li>{object} DataTables settings object: see {@link DataTable.models.oSettings}.</li>
6953 * <li>{array|object} Data for the row to be processed (same as the original format
6954 * that was passed in as the data source, or an array from a DOM data source</li>
6955 * <li>{int} Row index in aoData ({@link DataTable.models.oSettings.aoData}), which can
6956 * be useful to retrieve the TR element if you need DOM interaction.</li>
6962 * <li>{boolean} Include the row in the filtered result set (true) or not (false)</li>
6970 * // The following example shows custom filtering being applied to the fourth column (i.e.
6971 * // the aData[3] index) based on two input values from the end-user, matching the data in
6972 * // a certain range.
6973 * $.fn.dataTableExt.afnFiltering.push(
6974 * function( oSettings, aData, iDataIndex ) {
6975 * var iMin = document.getElementById('min').value * 1;
6976 * var iMax = document.getElementById('max').value * 1;
6977 * var iVersion = aData[3] == "-" ? 0 : aData[3]*1;
6978 * if ( iMin == "" && iMax == "" ) {
6981 * else if ( iMin == "" && iVersion < iMax ) {
6984 * else if ( iMin < iVersion && "" == iMax ) {
6987 * else if ( iMin < iVersion && iVersion < iMax ) {
6998 * Plug-in sorting functions - this method of sorting is complimentary to the default type
6999 * based sorting that DataTables does automatically, allowing much greater control over the
7000 * the data that is being used to sort a column. This is useful if you want to do sorting
7001 * based on live data (for example the contents of an 'input' element) rather than just the
7002 * static string that DataTables knows of. The way these plug-ins work is that you create
7003 * an array of the values you wish to be sorted for the column in question and then return
7004 * that array. Which pre-sorting function is run here depends on the sSortDataType parameter
7005 * that is used for the column (if any). This is the corollary of <i>ofnSearch</i> for sort
7009 * Function input parameters:
7011 * <li>{object} DataTables settings object: see {@link DataTable.models.oSettings}.</li>
7012 * <li>{int} Target column index</li>
7018 * <li>{array} Data for the column to be sorted upon</li>
7023 * Note that as of v1.9, it is typically preferable to use <i>mData</i> to prepare data for
7024 * the different uses that DataTables can put the data to. Specifically <i>mData</i> when
7025 * used as a function will give you a 'type' (sorting, filtering etc) that you can use to
7026 * prepare the data as required for the different types. As such, this method is deprecated.
7032 * // Updating the cached sorting information with user entered values in HTML input elements
7033 * jQuery.fn.dataTableExt.afnSortData['dom-text'] = function ( oSettings, iColumn )
7036 * $( 'td:eq('+iColumn+') input', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
7037 * aData.push( this.value );
7046 * Feature plug-ins - This is an array of objects which describe the feature plug-ins that are
7047 * available to DataTables. These feature plug-ins are accessible through the sDom initialisation
7048 * option. As such, each feature plug-in must describe a function that is used to initialise
7049 * itself (fnInit), a character so the feature can be enabled by sDom (cFeature) and the name
7050 * of the feature (sFeature). Thus the objects attached to this method must provide:
7052 * <li>{function} fnInit Initialisation of the plug-in
7055 * Function input parameters:
7057 * <li>{object} DataTables settings object: see {@link DataTable.models.oSettings}.</li>
7063 * <li>{node|null} The element which contains your feature. Note that the return
7064 * may also be void if your plug-in does not require to inject any DOM elements
7065 * into DataTables control (sDom) - for example this might be useful when
7066 * developing a plug-in which allows table control via keyboard entry.</li>
7071 * <li>{character} cFeature Character that will be matched in sDom - case sensitive</li>
7072 * <li>{string} sFeature Feature name</li>
7078 * // How TableTools initialises itself.
7079 * $.fn.dataTableExt.aoFeatures.push( {
7080 * "fnInit": function( oSettings ) {
7081 * return new TableTools( { "oDTSettings": oSettings } );
7084 * "sFeature": "TableTools"
7091 * Type detection plug-in functions - DataTables utilises types to define how sorting and
7092 * filtering behave, and types can be either be defined by the developer (sType for the
7093 * column) or they can be automatically detected by the methods in this array. The functions
7094 * defined in the array are quite simple, taking a single parameter (the data to analyse)
7095 * and returning the type if it is a known type, or null otherwise.
7098 * Function input parameters:
7100 * <li>{*} Data from the column cell to be analysed</li>
7106 * <li>{string|null} Data type detected, or null if unknown (and thus pass it
7107 * on to the other type detection functions.</li>
7115 * // Currency type detection plug-in:
7116 * jQuery.fn.dataTableExt.aTypes.push(
7117 * function ( sData ) {
7118 * var sValidChars = "0123456789.-";
7121 * // Check the numeric part
7122 * for ( i=1 ; i<sData.length ; i++ ) {
7123 * Char = sData.charAt(i);
7124 * if (sValidChars.indexOf(Char) == -1) {
7129 * // Check prefixed by currency
7130 * if ( sData.charAt(0) == '$' || sData.charAt(0) == '£' ) {
7131 * return 'currency';
7141 * Provide a common method for plug-ins to check the version of DataTables being used,
7142 * in order to ensure compatibility.
7144 * @param {string} sVersion Version string to check for, in the format "X.Y.Z". Note
7145 * that the formats "X" and "X.Y" are also acceptable.
7146 * @returns {boolean} true if this version of DataTables is greater or equal to the
7147 * required version, or false if this version of DataTales is not suitable
7150 * $(document).ready(function() {
7151 * var oTable = $('#example').dataTable();
7152 * alert( oTable.fnVersionCheck( '1.9.0' ) );
7155 "fnVersionCheck": DataTable.fnVersionCheck,
7159 * Index for what 'this' index API functions should use
7167 * Pre-processing of filtering data plug-ins - When you assign the sType for a column
7168 * (or have it automatically detected for you by DataTables or a type detection plug-in),
7169 * you will typically be using this for custom sorting, but it can also be used to provide
7170 * custom filtering by allowing you to pre-processing the data and returning the data in
7171 * the format that should be filtered upon. This is done by adding functions this object
7172 * with a parameter name which matches the sType for that target column. This is the
7173 * corollary of <i>afnSortData</i> for filtering data.
7176 * Function input parameters:
7178 * <li>{*} Data from the column cell to be prepared for filtering</li>
7184 * <li>{string|null} Formatted string that will be used for the filtering.</li>
7189 * Note that as of v1.9, it is typically preferable to use <i>mData</i> to prepare data for
7190 * the different uses that DataTables can put the data to. Specifically <i>mData</i> when
7191 * used as a function will give you a 'type' (sorting, filtering etc) that you can use to
7192 * prepare the data as required for the different types. As such, this method is deprecated.
7198 * $.fn.dataTableExt.ofnSearch['title-numeric'] = function ( sData ) {
7199 * return sData.replace(/\n/g," ").replace( /<.*?>/g, "" );
7206 * Container for all private functions in DataTables so they can be exposed externally
7214 * Storage for the various classes that DataTables uses
7222 * Storage for the various classes that DataTables uses - jQuery UI suitable
7230 * Pagination plug-in methods - The style and controls of the pagination can significantly
7231 * impact on how the end user interacts with the data in your table, and DataTables allows
7232 * the addition of pagination controls by extending this object, which can then be enabled
7233 * through the <i>sPaginationType</i> initialisation parameter. Each pagination type that
7234 * is added is an object (the property name of which is what <i>sPaginationType</i> refers
7235 * to) that has two properties, both methods that are used by DataTables to update the
7239 * fnInit - Initialisation of the paging controls. Called only during initialisation
7240 * of the table. It is expected that this function will add the required DOM elements
7241 * to the page for the paging controls to work. The element pointer
7242 * 'oSettings.aanFeatures.p' array is provided by DataTables to contain the paging
7243 * controls (note that this is a 2D array to allow for multiple instances of each
7244 * DataTables DOM element). It is suggested that you add the controls to this element
7248 * Function input parameters:
7250 * <li>{object} DataTables settings object: see {@link DataTable.models.oSettings}.</li>
7251 * <li>{node} Container into which the pagination controls must be inserted</li>
7252 * <li>{function} Draw callback function - whenever the controls cause a page
7253 * change, this method must be called to redraw the table.</li>
7259 * <li>No return required</li>
7265 * fnInit - This function is called whenever the paging status of the table changes and is
7266 * typically used to update classes and/or text of the paging controls to reflex the new
7270 * Function input parameters:
7272 * <li>{object} DataTables settings object: see {@link DataTable.models.oSettings}.</li>
7273 * <li>{function} Draw callback function - in case you need to redraw the table again
7274 * or attach new event listeners</li>
7280 * <li>No return required</li>
7290 * $.fn.dataTableExt.oPagination.four_button = {
7291 * "fnInit": function ( oSettings, nPaging, fnCallbackDraw ) {
7292 * nFirst = document.createElement( 'span' );
7293 * nPrevious = document.createElement( 'span' );
7294 * nNext = document.createElement( 'span' );
7295 * nLast = document.createElement( 'span' );
7297 * nFirst.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sFirst ) );
7298 * nPrevious.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sPrevious ) );
7299 * nNext.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sNext ) );
7300 * nLast.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sLast ) );
7302 * nFirst.className = "paginate_button first";
7303 * nPrevious.className = "paginate_button previous";
7304 * nNext.className="paginate_button next";
7305 * nLast.className = "paginate_button last";
7307 * nPaging.appendChild( nFirst );
7308 * nPaging.appendChild( nPrevious );
7309 * nPaging.appendChild( nNext );
7310 * nPaging.appendChild( nLast );
7312 * $(nFirst).click( function () {
7313 * oSettings.oApi._fnPageChange( oSettings, "first" );
7314 * fnCallbackDraw( oSettings );
7317 * $(nPrevious).click( function() {
7318 * oSettings.oApi._fnPageChange( oSettings, "previous" );
7319 * fnCallbackDraw( oSettings );
7322 * $(nNext).click( function() {
7323 * oSettings.oApi._fnPageChange( oSettings, "next" );
7324 * fnCallbackDraw( oSettings );
7327 * $(nLast).click( function() {
7328 * oSettings.oApi._fnPageChange( oSettings, "last" );
7329 * fnCallbackDraw( oSettings );
7332 * $(nFirst).bind( 'selectstart', function () { return false; } );
7333 * $(nPrevious).bind( 'selectstart', function () { return false; } );
7334 * $(nNext).bind( 'selectstart', function () { return false; } );
7335 * $(nLast).bind( 'selectstart', function () { return false; } );
7338 * "fnUpdate": function ( oSettings, fnCallbackDraw ) {
7339 * if ( !oSettings.aanFeatures.p ) {
7343 * // Loop over each instance of the pager
7344 * var an = oSettings.aanFeatures.p;
7345 * for ( var i=0, iLen=an.length ; i<iLen ; i++ ) {
7346 * var buttons = an[i].getElementsByTagName('span');
7347 * if ( oSettings._iDisplayStart === 0 ) {
7348 * buttons[0].className = "paginate_disabled_previous";
7349 * buttons[1].className = "paginate_disabled_previous";
7352 * buttons[0].className = "paginate_enabled_previous";
7353 * buttons[1].className = "paginate_enabled_previous";
7356 * if ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() ) {
7357 * buttons[2].className = "paginate_disabled_next";
7358 * buttons[3].className = "paginate_disabled_next";
7361 * buttons[2].className = "paginate_enabled_next";
7362 * buttons[3].className = "paginate_enabled_next";
7372 * Sorting plug-in methods - Sorting in DataTables is based on the detected type of the
7373 * data column (you can add your own type detection functions, or override automatic
7374 * detection using sType). With this specific type given to the column, DataTables will
7375 * apply the required sort from the functions in the object. Each sort type must provide
7376 * two mandatory methods, one each for ascending and descending sorting, and can optionally
7377 * provide a pre-formatting method that will help speed up sorting by allowing DataTables
7378 * to pre-format the sort data only once (rather than every time the actual sort functions
7379 * are run). The two sorting functions are typical Javascript sort methods:
7382 * Function input parameters:
7384 * <li>{*} Data to compare to the second parameter</li>
7385 * <li>{*} Data to compare to the first parameter</li>
7391 * <li>{int} Sorting match: <0 if first parameter should be sorted lower than
7392 * the second parameter, ===0 if the two parameters are equal and >0 if
7393 * the first parameter should be sorted height than the second parameter.</li>
7401 * // Case-sensitive string sorting, with no pre-formatting method
7402 * $.extend( $.fn.dataTableExt.oSort, {
7403 * "string-case-asc": function(x,y) {
7404 * return ((x < y) ? -1 : ((x > y) ? 1 : 0));
7406 * "string-case-desc": function(x,y) {
7407 * return ((x < y) ? 1 : ((x > y) ? -1 : 0));
7412 * // Case-insensitive string sorting, with pre-formatting
7413 * $.extend( $.fn.dataTableExt.oSort, {
7414 * "string-pre": function(x) {
7415 * return x.toLowerCase();
7417 * "string-asc": function(x,y) {
7418 * return ((x < y) ? -1 : ((x > y) ? 1 : 0));
7420 * "string-desc": function(x,y) {
7421 * return ((x < y) ? 1 : ((x > y) ? -1 : 0));
7429 * Version string for plug-ins to check compatibility. Allowed format is
7430 * a.b.c.d.e where: a:int, b:int, c:int, d:string(dev|beta), e:int. d and
7433 * @default Version number
7435 "sVersion": DataTable.version,
7439 * How should DataTables report an error. Can take the value 'alert' or 'throw'
7443 "sErrMode": "alert",
7447 * Store information for DataTables to access globally about other instances
7452 /* int:iNextUnique - next unique number for an instance */
7461 * Template object for the way in which DataTables holds information about
7462 * search information for the global filter and individual column filters.
7465 DataTable.models.oSearch = {
7467 * Flag to indicate if the filtering should be case insensitive or not
7471 "bCaseInsensitive": true,
7474 * Applied search term
7476 * @default <i>Empty string</i>
7481 * Flag to indicate if the search term should be interpreted as a
7482 * regular expression (true) or not (false) and therefore and special
7483 * regex characters escaped.
7490 * Flag to indicate if DataTables is to use its smart filtering or not.
7501 * Template object for the way in which DataTables holds information about
7502 * each individual row. This is the object format used for the settings
7506 DataTable.models.oRow = {
7508 * TR element for the row
7515 * Data object from the original data source for the row. This is either
7516 * an array if using the traditional form of DataTables, or an object if
7517 * using mData options. The exact type will depend on the passed in
7518 * data from the data source, or will be an array if using DOM a data
7520 * @type array|object
7526 * Sorting data cache - this array is ostensibly the same length as the
7527 * number of columns (although each index is generated only as it is
7528 * needed), and holds the data that is used for sorting each column in the
7529 * row. We do this cache generation at the start of the sort in order that
7530 * the formatting of the sort data need be done only once for each cell
7531 * per sort. This array should not be read from or written to by anything
7532 * other than the master sorting methods.
7540 * Array of TD elements that are cached for hidden rows, so they can be
7541 * reinserted into the table if a column is made visible again (or to act
7542 * as a store if a column is made hidden). Only hidden columns have a
7543 * reference in the array. For non-hidden columns the value is either
7544 * undefined or null.
7552 * Cache of the class name that DataTables has applied to the row, so we
7553 * can quickly look at this variable rather than needing to do a DOM check
7554 * on className for the nTr property.
7556 * @default <i>Empty string</i>
7565 * Template object for the column information object in DataTables. This object
7566 * is held in the settings aoColumns array and contains all the information that
7567 * DataTables needs about each individual column.
7569 * Note that this object is related to {@link DataTable.defaults.columns}
7570 * but this one is the internal data store for DataTables's cache of columns.
7571 * It should NOT be manipulated outside of DataTables. Any configuration should
7572 * be done through the initialisation options.
7575 DataTable.models.oColumn = {
7577 * A list of the columns that sorting should occur on when this column
7578 * is sorted. That this property is an array allows multi-column sorting
7579 * to be defined for a column (for example first name / last name columns
7580 * would benefit from this). The values are integers pointing to the
7581 * columns to be sorted on (typically it will be a single integer pointing
7582 * at itself, but that doesn't need to be the case).
7588 * Define the sorting directions that are applied to the column, in sequence
7589 * as the column is repeatedly sorted upon - i.e. the first value is used
7590 * as the sorting direction when the column if first sorted (clicked on).
7591 * Sort it again (click again) and it will move on to the next index.
7592 * Repeat until loop.
7598 * Flag to indicate if the column is searchable, and thus should be included
7599 * in the filtering or not.
7602 "bSearchable": null,
7605 * Flag to indicate if the column is sortable or not.
7611 * <code>Deprecated</code> When using fnRender, you have two options for what
7612 * to do with the data, and this property serves as the switch. Firstly, you
7613 * can have the sorting and filtering use the rendered value (true - default),
7614 * or you can have the sorting and filtering us the original value (false).
7616 * Please note that this option has now been deprecated and will be removed
7617 * in the next version of DataTables. Please use mRender / mData rather than
7622 "bUseRendered": null,
7625 * Flag to indicate if the column is currently visible in the table or not
7631 * Flag to indicate to the type detection method if the automatic type
7632 * detection should be used, or if a column type (sType) has been specified
7640 * Developer definable function that is called whenever a cell is created (Ajax source,
7641 * etc) or processed for input (DOM source). This can be used as a compliment to mRender
7642 * allowing you to modify the DOM element (add background colour for example) when the
7643 * element is available.
7645 * @param {element} nTd The TD node that has been created
7646 * @param {*} sData The Data for the cell
7647 * @param {array|object} oData The data for the whole row
7648 * @param {int} iRow The row index for the aoData data store
7651 "fnCreatedCell": null,
7654 * Function to get data from a cell in a column. You should <b>never</b>
7655 * access data directly through _aData internally in DataTables - always use
7656 * the method attached to this property. It allows mData to function as
7657 * required. This function is automatically assigned by the column
7658 * initialisation method
7660 * @param {array|object} oData The data array/object for the array
7661 * (i.e. aoData[]._aData)
7662 * @param {string} sSpecific The specific data type you want to get -
7663 * 'display', 'type' 'filter' 'sort'
7664 * @returns {*} The data for the cell from the given row's data
7670 * <code>Deprecated</code> Custom display function that will be called for the
7671 * display of each cell in this column.
7673 * Please note that this option has now been deprecated and will be removed
7674 * in the next version of DataTables. Please use mRender / mData rather than
7677 * @param {object} o Object with the following parameters:
7678 * @param {int} o.iDataRow The row in aoData
7679 * @param {int} o.iDataColumn The column in question
7680 * @param {array} o.aData The data for the row in question
7681 * @param {object} o.oSettings The settings object for this DataTables instance
7682 * @returns {string} The string you which to use in the display
7689 * Function to set data for a cell in the column. You should <b>never</b>
7690 * set the data directly to _aData internally in DataTables - always use
7691 * this method. It allows mData to function as required. This function
7692 * is automatically assigned by the column initialisation method
7694 * @param {array|object} oData The data array/object for the array
7695 * (i.e. aoData[]._aData)
7696 * @param {*} sValue Value to set
7702 * Property to read the value for the cells in the column from the data
7703 * source array / object. If null, then the default content is used, if a
7704 * function is given then the return from the function is used.
7705 * @type function|int|string|null
7711 * Partner property to mData which is used (only when defined) to get
7712 * the data - i.e. it is basically the same as mData, but without the
7713 * 'set' option, and also the data fed to it is the result from mData.
7714 * This is the rendering method to match the data method of mData.
7715 * @type function|int|string|null
7721 * Unique header TH/TD element for this column - this is what the sorting
7722 * listener is attached to (if sorting is enabled.)
7729 * Unique footer TH/TD element for this column (if there is one). Not used
7730 * in DataTables as such, but can be used for plug-ins to reference the
7731 * footer for each column.
7738 * The class to apply to all TD elements in the table's TBODY for the column
7745 * When DataTables calculates the column widths to assign to each column,
7746 * it finds the longest string in each column and then constructs a
7747 * temporary table and reads the widths from that. The problem with this
7748 * is that "mmm" is much wider then "iiii", but the latter is a longer
7749 * string - thus the calculation can go wrong (doing it properly and putting
7750 * it into an DOM object and measuring that is horribly(!) slow). Thus as
7751 * a "work around" we provide this option. It will append its value to the
7752 * text that is found to be the longest string for the column - i.e. padding.
7755 "sContentPadding": null,
7758 * Allows a default value to be given for a column's data, and will be used
7759 * whenever a null data source is encountered (this can be because mData
7760 * is set to null, or because the data source itself is null).
7764 "sDefaultContent": null,
7767 * Name for the column, allowing reference to the column by name as well as
7768 * by index (needs a lookup to work by name).
7774 * Custom sorting data type - defines which of the available plug-ins in
7775 * afnSortData the custom sorting will use - if any is defined.
7779 "sSortDataType": 'std',
7782 * Class to be applied to the header element when sorting on this column
7786 "sSortingClass": null,
7789 * Class to be applied to the header element when sorting on this column -
7790 * when jQuery UI theming is used.
7794 "sSortingClassJUI": null,
7797 * Title of the column - what is seen in the TH element (nTh).
7803 * Column sorting and filtering type
7810 * Width of the column
7817 * Width of the column when it was first "encountered"
7827 * Initialisation options that can be given to DataTables at initialisation
7831 DataTable.defaults = {
7833 * An array of data to use for the table, passed in at initialisation which
7834 * will be used in preference to any data which is already in the DOM. This is
7835 * particularly useful for constructing tables purely in Javascript, for
7836 * example with a custom Ajax call.
7842 * // Using a 2D array data source
7843 * $(document).ready( function () {
7844 * $('#example').dataTable( {
7846 * ['Trident', 'Internet Explorer 4.0', 'Win 95+', 4, 'X'],
7847 * ['Trident', 'Internet Explorer 5.0', 'Win 95+', 5, 'C'],
7850 * { "sTitle": "Engine" },
7851 * { "sTitle": "Browser" },
7852 * { "sTitle": "Platform" },
7853 * { "sTitle": "Version" },
7854 * { "sTitle": "Grade" }
7860 * // Using an array of objects as a data source (mData)
7861 * $(document).ready( function () {
7862 * $('#example').dataTable( {
7865 * "engine": "Trident",
7866 * "browser": "Internet Explorer 4.0",
7867 * "platform": "Win 95+",
7872 * "engine": "Trident",
7873 * "browser": "Internet Explorer 5.0",
7874 * "platform": "Win 95+",
7880 * { "sTitle": "Engine", "mData": "engine" },
7881 * { "sTitle": "Browser", "mData": "browser" },
7882 * { "sTitle": "Platform", "mData": "platform" },
7883 * { "sTitle": "Version", "mData": "version" },
7884 * { "sTitle": "Grade", "mData": "grade" }
7893 * If sorting is enabled, then DataTables will perform a first pass sort on
7894 * initialisation. You can define which column(s) the sort is performed upon,
7895 * and the sorting direction, with this variable. The aaSorting array should
7896 * contain an array for each column to be sorted initially containing the
7897 * column's index and a direction string ('asc' or 'desc').
7899 * @default [[0,'asc']]
7903 * // Sort by 3rd column first, and then 4th column
7904 * $(document).ready( function() {
7905 * $('#example').dataTable( {
7906 * "aaSorting": [[2,'asc'], [3,'desc']]
7910 * // No initial sorting
7911 * $(document).ready( function() {
7912 * $('#example').dataTable( {
7917 "aaSorting": [[0,'asc']],
7921 * This parameter is basically identical to the aaSorting parameter, but
7922 * cannot be overridden by user interaction with the table. What this means
7923 * is that you could have a column (visible or hidden) which the sorting will
7924 * always be forced on first - any sorting after that (from the user) will
7925 * then be performed as required. This can be useful for grouping rows
7932 * $(document).ready( function() {
7933 * $('#example').dataTable( {
7934 * "aaSortingFixed": [[0,'asc']]
7938 "aaSortingFixed": null,
7942 * This parameter allows you to readily specify the entries in the length drop
7943 * down menu that DataTables shows when pagination is enabled. It can be
7944 * either a 1D array of options which will be used for both the displayed
7945 * option and the value, or a 2D array which will use the array in the first
7946 * position as the value, and the array in the second position as the
7947 * displayed options (useful for language strings such as 'All').
7949 * @default [ 10, 25, 50, 100 ]
7953 * $(document).ready( function() {
7954 * $('#example').dataTable( {
7955 * "aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
7960 * // Setting the default display length as well as length menu
7961 * // This is likely to be wanted if you remove the '10' option which
7962 * // is the iDisplayLength default.
7963 * $(document).ready( function() {
7964 * $('#example').dataTable( {
7965 * "iDisplayLength": 25,
7966 * "aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]]
7970 "aLengthMenu": [ 10, 25, 50, 100 ],
7974 * The aoColumns option in the initialisation parameter allows you to define
7975 * details about the way individual columns behave. For a full list of
7976 * column options that can be set, please see
7977 * {@link DataTable.defaults.columns}. Note that if you use aoColumns to
7978 * define your columns, you must have an entry in the array for every single
7979 * column that you have in your table (these can be null if you don't which
7980 * to specify any options).
7986 * Very similar to aoColumns, aoColumnDefs allows you to target a specific
7987 * column, multiple columns, or all columns, using the aTargets property of
7988 * each object in the array. This allows great flexibility when creating
7989 * tables, as the aoColumnDefs arrays can be of any length, targeting the
7990 * columns you specifically want. aoColumnDefs may use any of the column
7991 * options available: {@link DataTable.defaults.columns}, but it _must_
7992 * have aTargets defined in each object in the array. Values in the aTargets
7995 * <li>a string - class name will be matched on the TH for the column</li>
7996 * <li>0 or a positive integer - column index counting from the left</li>
7997 * <li>a negative integer - column index counting from the right</li>
7998 * <li>the string "_all" - all columns (i.e. assign a default)</li>
8002 "aoColumnDefs": null,
8006 * Basically the same as oSearch, this parameter defines the individual column
8007 * filtering state at initialisation time. The array must be of the same size
8008 * as the number of columns, and each element be an object with the parameters
8009 * "sSearch" and "bEscapeRegex" (the latter is optional). 'null' is also
8010 * accepted and the default will be used.
8016 * $(document).ready( function() {
8017 * $('#example').dataTable( {
8020 * { "sSearch": "My filter" },
8022 * { "sSearch": "^[0-9]", "bEscapeRegex": false }
8031 * An array of CSS classes that should be applied to displayed rows. This
8032 * array may be of any length, and DataTables will apply each class
8033 * sequentially, looping when required.
8035 * @default null <i>Will take the values determined by the oClasses.sStripe*
8040 * $(document).ready( function() {
8041 * $('#example').dataTable( {
8042 * "asStripeClasses": [ 'strip1', 'strip2', 'strip3' ]
8046 "asStripeClasses": null,
8050 * Enable or disable automatic column width calculation. This can be disabled
8051 * as an optimisation (it takes some time to calculate the widths) if the
8052 * tables widths are passed in using aoColumns.
8058 * $(document).ready( function () {
8059 * $('#example').dataTable( {
8060 * "bAutoWidth": false
8068 * Deferred rendering can provide DataTables with a huge speed boost when you
8069 * are using an Ajax or JS data source for the table. This option, when set to
8070 * true, will cause DataTables to defer the creation of the table elements for
8071 * each row until they are needed for a draw - saving a significant amount of
8078 * $(document).ready( function() {
8079 * var oTable = $('#example').dataTable( {
8080 * "sAjaxSource": "sources/arrays.txt",
8081 * "bDeferRender": true
8085 "bDeferRender": false,
8089 * Replace a DataTable which matches the given selector and replace it with
8090 * one which has the properties of the new initialisation object passed. If no
8091 * table matches the selector, then the new DataTable will be constructed as
8098 * $(document).ready( function() {
8099 * $('#example').dataTable( {
8100 * "sScrollY": "200px",
8101 * "bPaginate": false
8104 * // Some time later....
8105 * $('#example').dataTable( {
8115 * Enable or disable filtering of data. Filtering in DataTables is "smart" in
8116 * that it allows the end user to input multiple words (space separated) and
8117 * will match a row containing those words, even if not in the order that was
8118 * specified (this allow matching across multiple columns). Note that if you
8119 * wish to use filtering in DataTables this must remain 'true' - to remove the
8120 * default filtering input box and retain filtering abilities, please use
8121 * {@link DataTable.defaults.sDom}.
8127 * $(document).ready( function () {
8128 * $('#example').dataTable( {
8137 * Enable or disable the table information display. This shows information
8138 * about the data that is currently visible on the page, including information
8139 * about filtered data if that action is being performed.
8145 * $(document).ready( function () {
8146 * $('#example').dataTable( {
8155 * Enable jQuery UI ThemeRoller support (required as ThemeRoller requires some
8156 * slightly different and additional mark-up from what DataTables has
8157 * traditionally used).
8163 * $(document).ready( function() {
8164 * $('#example').dataTable( {
8173 * Allows the end user to select the size of a formatted page from a select
8174 * menu (sizes are 10, 25, 50 and 100). Requires pagination (bPaginate).
8180 * $(document).ready( function () {
8181 * $('#example').dataTable( {
8182 * "bLengthChange": false
8186 "bLengthChange": true,
8190 * Enable or disable pagination.
8196 * $(document).ready( function () {
8197 * $('#example').dataTable( {
8198 * "bPaginate": false
8206 * Enable or disable the display of a 'processing' indicator when the table is
8207 * being processed (e.g. a sort). This is particularly useful for tables with
8208 * large amounts of data where it can take a noticeable amount of time to sort
8215 * $(document).ready( function () {
8216 * $('#example').dataTable( {
8217 * "bProcessing": true
8221 "bProcessing": false,
8225 * Retrieve the DataTables object for the given selector. Note that if the
8226 * table has already been initialised, this parameter will cause DataTables
8227 * to simply return the object that has already been set up - it will not take
8228 * account of any changes you might have made to the initialisation object
8229 * passed to DataTables (setting this parameter to true is an acknowledgement
8230 * that you understand this). bDestroy can be used to reinitialise a table if
8237 * $(document).ready( function() {
8242 * function initTable ()
8244 * return $('#example').dataTable( {
8245 * "sScrollY": "200px",
8246 * "bPaginate": false,
8251 * function tableActions ()
8253 * var oTable = initTable();
8254 * // perform API operations with oTable
8261 * Indicate if DataTables should be allowed to set the padding / margin
8262 * etc for the scrolling header elements or not. Typically you will want
8269 * $(document).ready( function() {
8270 * $('#example').dataTable( {
8271 * "bScrollAutoCss": false,
8272 * "sScrollY": "200px"
8276 "bScrollAutoCss": true,
8280 * When vertical (y) scrolling is enabled, DataTables will force the height of
8281 * the table's viewport to the given height at all times (useful for layout).
8282 * However, this can look odd when filtering data down to a small data set,
8283 * and the footer is left "floating" further down. This parameter (when
8284 * enabled) will cause DataTables to collapse the table's viewport down when
8285 * the result set will fit within the given Y height.
8291 * $(document).ready( function() {
8292 * $('#example').dataTable( {
8293 * "sScrollY": "200",
8294 * "bScrollCollapse": true
8298 "bScrollCollapse": false,
8302 * Enable infinite scrolling for DataTables (to be used in combination with
8303 * sScrollY). Infinite scrolling means that DataTables will continually load
8304 * data as a user scrolls through a table, which is very useful for large
8305 * dataset. This cannot be used with pagination, which is automatically
8306 * disabled. Note - the Scroller extra for DataTables is recommended in
8307 * in preference to this option.
8313 * $(document).ready( function() {
8314 * $('#example').dataTable( {
8315 * "bScrollInfinite": true,
8316 * "bScrollCollapse": true,
8317 * "sScrollY": "200px"
8321 "bScrollInfinite": false,
8325 * Configure DataTables to use server-side processing. Note that the
8326 * sAjaxSource parameter must also be given in order to give DataTables a
8327 * source to obtain the required data for each draw.
8331 * @dtopt Server-side
8334 * $(document).ready( function () {
8335 * $('#example').dataTable( {
8336 * "bServerSide": true,
8337 * "sAjaxSource": "xhr.php"
8341 "bServerSide": false,
8345 * Enable or disable sorting of columns. Sorting of individual columns can be
8346 * disabled by the "bSortable" option for each column.
8352 * $(document).ready( function () {
8353 * $('#example').dataTable( {
8362 * Allows control over whether DataTables should use the top (true) unique
8363 * cell that is found for a single column, or the bottom (false - default).
8364 * This is useful when using complex headers.
8370 * $(document).ready( function() {
8371 * $('#example').dataTable( {
8372 * "bSortCellsTop": true
8376 "bSortCellsTop": false,
8380 * Enable or disable the addition of the classes 'sorting_1', 'sorting_2' and
8381 * 'sorting_3' to the columns which are currently being sorted on. This is
8382 * presented as a feature switch as it can increase processing time (while
8383 * classes are removed and added) so for large data sets you might want to
8390 * $(document).ready( function () {
8391 * $('#example').dataTable( {
8392 * "bSortClasses": false
8396 "bSortClasses": true,
8400 * Enable or disable state saving. When enabled a cookie will be used to save
8401 * table display information such as pagination information, display length,
8402 * filtering and sorting. As such when the end user reloads the page the
8403 * display display will match what thy had previously set up.
8409 * $(document).ready( function () {
8410 * $('#example').dataTable( {
8411 * "bStateSave": true
8415 "bStateSave": false,
8419 * Customise the cookie and / or the parameters being stored when using
8420 * DataTables with state saving enabled. This function is called whenever
8421 * the cookie is modified, and it expects a fully formed cookie string to be
8422 * returned. Note that the data object passed in is a Javascript object which
8423 * must be converted to a string (JSON.stringify for example).
8425 * @param {string} sName Name of the cookie defined by DataTables
8426 * @param {object} oData Data to be stored in the cookie
8427 * @param {string} sExpires Cookie expires string
8428 * @param {string} sPath Path of the cookie to set
8429 * @returns {string} Cookie formatted string (which should be encoded by
8430 * using encodeURIComponent())
8434 * $(document).ready( function () {
8435 * $('#example').dataTable( {
8436 * "fnCookieCallback": function (sName, oData, sExpires, sPath) {
8437 * // Customise oData or sName or whatever else here
8438 * return sName + "="+JSON.stringify(oData)+"; expires=" + sExpires +"; path=" + sPath;
8443 "fnCookieCallback": null,
8447 * This function is called when a TR element is created (and all TD child
8448 * elements have been inserted), or registered if using a DOM source, allowing
8449 * manipulation of the TR element (adding classes etc).
8451 * @param {node} nRow "TR" element for the current row
8452 * @param {array} aData Raw data array for this row
8453 * @param {int} iDataIndex The index of this row in aoData
8457 * $(document).ready( function() {
8458 * $('#example').dataTable( {
8459 * "fnCreatedRow": function( nRow, aData, iDataIndex ) {
8460 * // Bold the grade for all 'A' grade browsers
8461 * if ( aData[4] == "A" )
8463 * $('td:eq(4)', nRow).html( '<b>A</b>' );
8469 "fnCreatedRow": null,
8473 * This function is called on every 'draw' event, and allows you to
8474 * dynamically modify any aspect you want about the created DOM.
8476 * @param {object} oSettings DataTables settings object
8480 * $(document).ready( function() {
8481 * $('#example').dataTable( {
8482 * "fnDrawCallback": function( oSettings ) {
8483 * alert( 'DataTables has redrawn the table' );
8488 "fnDrawCallback": null,
8492 * Identical to fnHeaderCallback() but for the table footer this function
8493 * allows you to modify the table footer on every 'draw' even.
8495 * @param {node} nFoot "TR" element for the footer
8496 * @param {array} aData Full table data (as derived from the original HTML)
8497 * @param {int} iStart Index for the current display starting point in the
8499 * @param {int} iEnd Index for the current display ending point in the
8501 * @param {array int} aiDisplay Index array to translate the visual position
8502 * to the full data array
8506 * $(document).ready( function() {
8507 * $('#example').dataTable( {
8508 * "fnFooterCallback": function( nFoot, aData, iStart, iEnd, aiDisplay ) {
8509 * nFoot.getElementsByTagName('th')[0].innerHTML = "Starting index is "+iStart;
8514 "fnFooterCallback": null,
8518 * When rendering large numbers in the information element for the table
8519 * (i.e. "Showing 1 to 10 of 57 entries") DataTables will render large numbers
8520 * to have a comma separator for the 'thousands' units (e.g. 1 million is
8521 * rendered as "1,000,000") to help readability for the end user. This
8522 * function will override the default method DataTables uses.
8525 * @param {int} iIn number to be formatted
8526 * @returns {string} formatted string for DataTables to show the number
8530 * $(document).ready( function() {
8531 * $('#example').dataTable( {
8532 * "fnFormatNumber": function ( iIn ) {
8533 * if ( iIn < 1000 ) {
8538 * a=s.split(""), out="",
8541 * for ( var i=0 ; i<iLen ; i++ ) {
8542 * if ( i%3 === 0 && i !== 0 ) {
8545 * out = a[iLen-i-1]+out;
8553 "fnFormatNumber": function ( iIn ) {
8556 // A small optimisation for what is likely to be the majority of use cases
8560 var s=(iIn+""), a=s.split(""), out="", iLen=s.length;
8562 for ( var i=0 ; i<iLen ; i++ )
8564 if ( i%3 === 0 && i !== 0 )
8566 out = this.oLanguage.sInfoThousands+out;
8568 out = a[iLen-i-1]+out;
8575 * This function is called on every 'draw' event, and allows you to
8576 * dynamically modify the header row. This can be used to calculate and
8577 * display useful information about the table.
8579 * @param {node} nHead "TR" element for the header
8580 * @param {array} aData Full table data (as derived from the original HTML)
8581 * @param {int} iStart Index for the current display starting point in the
8583 * @param {int} iEnd Index for the current display ending point in the
8585 * @param {array int} aiDisplay Index array to translate the visual position
8586 * to the full data array
8590 * $(document).ready( function() {
8591 * $('#example').dataTable( {
8592 * "fnHeaderCallback": function( nHead, aData, iStart, iEnd, aiDisplay ) {
8593 * nHead.getElementsByTagName('th')[0].innerHTML = "Displaying "+(iEnd-iStart)+" records";
8598 "fnHeaderCallback": null,
8602 * The information element can be used to convey information about the current
8603 * state of the table. Although the internationalisation options presented by
8604 * DataTables are quite capable of dealing with most customisations, there may
8605 * be times where you wish to customise the string further. This callback
8606 * allows you to do exactly that.
8608 * @param {object} oSettings DataTables settings object
8609 * @param {int} iStart Starting position in data for the draw
8610 * @param {int} iEnd End position in data for the draw
8611 * @param {int} iMax Total number of rows in the table (regardless of
8613 * @param {int} iTotal Total number of rows in the data set, after filtering
8614 * @param {string} sPre The string that DataTables has formatted using it's
8616 * @returns {string} The string to be displayed in the information element.
8620 * $('#example').dataTable( {
8621 * "fnInfoCallback": function( oSettings, iStart, iEnd, iMax, iTotal, sPre ) {
8622 * return iStart +" to "+ iEnd;
8626 "fnInfoCallback": null,
8630 * Called when the table has been initialised. Normally DataTables will
8631 * initialise sequentially and there will be no need for this function,
8632 * however, this does not hold true when using external language information
8633 * since that is obtained using an async XHR call.
8635 * @param {object} oSettings DataTables settings object
8636 * @param {object} json The JSON object request from the server - only
8637 * present if client-side Ajax sourced data is used
8641 * $(document).ready( function() {
8642 * $('#example').dataTable( {
8643 * "fnInitComplete": function(oSettings, json) {
8644 * alert( 'DataTables has finished its initialisation.' );
8649 "fnInitComplete": null,
8653 * Called at the very start of each table draw and can be used to cancel the
8654 * draw by returning false, any other return (including undefined) results in
8655 * the full draw occurring).
8657 * @param {object} oSettings DataTables settings object
8658 * @returns {boolean} False will cancel the draw, anything else (including no
8659 * return) will allow it to complete.
8663 * $(document).ready( function() {
8664 * $('#example').dataTable( {
8665 * "fnPreDrawCallback": function( oSettings ) {
8666 * if ( $('#test').val() == 1 ) {
8673 "fnPreDrawCallback": null,
8677 * This function allows you to 'post process' each row after it have been
8678 * generated for each table draw, but before it is rendered on screen. This
8679 * function might be used for setting the row class name etc.
8681 * @param {node} nRow "TR" element for the current row
8682 * @param {array} aData Raw data array for this row
8683 * @param {int} iDisplayIndex The display index for the current table draw
8684 * @param {int} iDisplayIndexFull The index of the data in the full list of
8685 * rows (after filtering)
8689 * $(document).ready( function() {
8690 * $('#example').dataTable( {
8691 * "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
8692 * // Bold the grade for all 'A' grade browsers
8693 * if ( aData[4] == "A" )
8695 * $('td:eq(4)', nRow).html( '<b>A</b>' );
8701 "fnRowCallback": null,
8705 * This parameter allows you to override the default function which obtains
8706 * the data from the server ($.getJSON) so something more suitable for your
8707 * application. For example you could use POST data, or pull information from
8708 * a Gears or AIR database.
8711 * @param {string} sSource HTTP source to obtain the data from (sAjaxSource)
8712 * @param {array} aoData A key/value pair object containing the data to send
8714 * @param {function} fnCallback to be called on completion of the data get
8715 * process that will draw the data on the page.
8716 * @param {object} oSettings DataTables settings object
8718 * @dtopt Server-side
8721 * // POST data to server
8722 * $(document).ready( function() {
8723 * $('#example').dataTable( {
8724 * "bProcessing": true,
8725 * "bServerSide": true,
8726 * "sAjaxSource": "xhr.php",
8727 * "fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
8728 * oSettings.jqXHR = $.ajax( {
8729 * "dataType": 'json',
8733 * "success": fnCallback
8739 "fnServerData": function ( sUrl, aoData, fnCallback, oSettings ) {
8740 oSettings.jqXHR = $.ajax( {
8743 "success": function (json) {
8744 if ( json.sError ) {
8745 oSettings.oApi._fnLog( oSettings, 0, json.sError );
8748 $(oSettings.oInstance).trigger('xhr', [oSettings, json]);
8753 "type": oSettings.sServerMethod,
8754 "error": function (xhr, error, thrown) {
8755 if ( error == "parsererror" ) {
8756 oSettings.oApi._fnLog( oSettings, 0, "DataTables warning: JSON data from "+
8757 "server could not be parsed. This is caused by a JSON formatting error." );
8765 * It is often useful to send extra data to the server when making an Ajax
8766 * request - for example custom filtering information, and this callback
8767 * function makes it trivial to send extra information to the server. The
8768 * passed in parameter is the data set that has been constructed by
8769 * DataTables, and you can add to this or modify it as you require.
8771 * @param {array} aoData Data array (array of objects which are name/value
8772 * pairs) that has been constructed by DataTables and will be sent to the
8773 * server. In the case of Ajax sourced data with server-side processing
8774 * this will be an empty array, for server-side processing there will be a
8775 * significant number of parameters!
8776 * @returns {undefined} Ensure that you modify the aoData array passed in,
8777 * as this is passed by reference.
8779 * @dtopt Server-side
8782 * $(document).ready( function() {
8783 * $('#example').dataTable( {
8784 * "bProcessing": true,
8785 * "bServerSide": true,
8786 * "sAjaxSource": "scripts/server_processing.php",
8787 * "fnServerParams": function ( aoData ) {
8788 * aoData.push( { "name": "more_data", "value": "my_value" } );
8793 "fnServerParams": null,
8797 * Load the table state. With this function you can define from where, and how, the
8798 * state of a table is loaded. By default DataTables will load from its state saving
8799 * cookie, but you might wish to use local storage (HTML5) or a server-side database.
8802 * @param {object} oSettings DataTables settings object
8803 * @return {object} The DataTables state object to be loaded
8807 * $(document).ready( function() {
8808 * $('#example').dataTable( {
8809 * "bStateSave": true,
8810 * "fnStateLoad": function (oSettings) {
8813 * // Send an Ajax request to the server to get the data. Note that
8814 * // this is a synchronous request.
8816 * "url": "/state_load",
8818 * "dataType": "json",
8819 * "success": function (json) {
8829 "fnStateLoad": function ( oSettings ) {
8830 var sData = this.oApi._fnReadCookie( oSettings.sCookiePrefix+oSettings.sInstance );
8834 oData = (typeof $.parseJSON === 'function') ?
8835 $.parseJSON(sData) : eval( '('+sData+')' );
8845 * Callback which allows modification of the saved state prior to loading that state.
8846 * This callback is called when the table is loading state from the stored data, but
8847 * prior to the settings object being modified by the saved state. Note that for
8848 * plug-in authors, you should use the 'stateLoadParams' event to load parameters for
8851 * @param {object} oSettings DataTables settings object
8852 * @param {object} oData The state object that is to be loaded
8856 * // Remove a saved filter, so filtering is never loaded
8857 * $(document).ready( function() {
8858 * $('#example').dataTable( {
8859 * "bStateSave": true,
8860 * "fnStateLoadParams": function (oSettings, oData) {
8861 * oData.oSearch.sSearch = "";
8867 * // Disallow state loading by returning false
8868 * $(document).ready( function() {
8869 * $('#example').dataTable( {
8870 * "bStateSave": true,
8871 * "fnStateLoadParams": function (oSettings, oData) {
8877 "fnStateLoadParams": null,
8881 * Callback that is called when the state has been loaded from the state saving method
8882 * and the DataTables settings object has been modified as a result of the loaded state.
8884 * @param {object} oSettings DataTables settings object
8885 * @param {object} oData The state object that was loaded
8889 * // Show an alert with the filtering value that was saved
8890 * $(document).ready( function() {
8891 * $('#example').dataTable( {
8892 * "bStateSave": true,
8893 * "fnStateLoaded": function (oSettings, oData) {
8894 * alert( 'Saved filter was: '+oData.oSearch.sSearch );
8899 "fnStateLoaded": null,
8903 * Save the table state. This function allows you to define where and how the state
8904 * information for the table is stored - by default it will use a cookie, but you
8905 * might want to use local storage (HTML5) or a server-side database.
8908 * @param {object} oSettings DataTables settings object
8909 * @param {object} oData The state object to be saved
8913 * $(document).ready( function() {
8914 * $('#example').dataTable( {
8915 * "bStateSave": true,
8916 * "fnStateSave": function (oSettings, oData) {
8917 * // Send an Ajax request to the server with the state object
8919 * "url": "/state_save",
8921 * "dataType": "json",
8923 * "success": function () {}
8929 "fnStateSave": function ( oSettings, oData ) {
8930 this.oApi._fnCreateCookie(
8931 oSettings.sCookiePrefix+oSettings.sInstance,
8932 this.oApi._fnJsonString(oData),
8933 oSettings.iCookieDuration,
8934 oSettings.sCookiePrefix,
8935 oSettings.fnCookieCallback
8941 * Callback which allows modification of the state to be saved. Called when the table
8942 * has changed state a new state save is required. This method allows modification of
8943 * the state saving object prior to actually doing the save, including addition or
8944 * other state properties or modification. Note that for plug-in authors, you should
8945 * use the 'stateSaveParams' event to save parameters for a plug-in.
8947 * @param {object} oSettings DataTables settings object
8948 * @param {object} oData The state object to be saved
8952 * // Remove a saved filter, so filtering is never saved
8953 * $(document).ready( function() {
8954 * $('#example').dataTable( {
8955 * "bStateSave": true,
8956 * "fnStateSaveParams": function (oSettings, oData) {
8957 * oData.oSearch.sSearch = "";
8962 "fnStateSaveParams": null,
8966 * Duration of the cookie which is used for storing session information. This
8967 * value is given in seconds.
8969 * @default 7200 <i>(2 hours)</i>
8973 * $(document).ready( function() {
8974 * $('#example').dataTable( {
8975 * "iCookieDuration": 60*60*24; // 1 day
8979 "iCookieDuration": 7200,
8983 * When enabled DataTables will not make a request to the server for the first
8984 * page draw - rather it will use the data already on the page (no sorting etc
8985 * will be applied to it), thus saving on an XHR at load time. iDeferLoading
8986 * is used to indicate that deferred loading is required, but it is also used
8987 * to tell DataTables how many records there are in the full table (allowing
8988 * the information element and pagination to be displayed correctly). In the case
8989 * where a filtering is applied to the table on initial load, this can be
8990 * indicated by giving the parameter as an array, where the first element is
8991 * the number of records available after filtering and the second element is the
8992 * number of records without filtering (allowing the table information element
8993 * to be shown correctly).
8999 * // 57 records available in the table, no filtering applied
9000 * $(document).ready( function() {
9001 * $('#example').dataTable( {
9002 * "bServerSide": true,
9003 * "sAjaxSource": "scripts/server_processing.php",
9004 * "iDeferLoading": 57
9009 * // 57 records after filtering, 100 without filtering (an initial filter applied)
9010 * $(document).ready( function() {
9011 * $('#example').dataTable( {
9012 * "bServerSide": true,
9013 * "sAjaxSource": "scripts/server_processing.php",
9014 * "iDeferLoading": [ 57, 100 ],
9016 * "sSearch": "my_filter"
9021 "iDeferLoading": null,
9025 * Number of rows to display on a single page when using pagination. If
9026 * feature enabled (bLengthChange) then the end user will be able to override
9027 * this to a custom setting using a pop-up menu.
9033 * $(document).ready( function() {
9034 * $('#example').dataTable( {
9035 * "iDisplayLength": 50
9039 "iDisplayLength": 10,
9043 * Define the starting point for data display when using DataTables with
9044 * pagination. Note that this parameter is the number of records, rather than
9045 * the page number, so if you have 10 records per page and want to start on
9046 * the third page, it should be "20".
9052 * $(document).ready( function() {
9053 * $('#example').dataTable( {
9054 * "iDisplayStart": 20
9062 * The scroll gap is the amount of scrolling that is left to go before
9063 * DataTables will load the next 'page' of data automatically. You typically
9064 * want a gap which is big enough that the scrolling will be smooth for the
9065 * user, while not so large that it will load more data than need.
9071 * $(document).ready( function() {
9072 * $('#example').dataTable( {
9073 * "bScrollInfinite": true,
9074 * "bScrollCollapse": true,
9075 * "sScrollY": "200px",
9076 * "iScrollLoadGap": 50
9080 "iScrollLoadGap": 100,
9084 * By default DataTables allows keyboard navigation of the table (sorting, paging,
9085 * and filtering) by adding a tabindex attribute to the required elements. This
9086 * allows you to tab through the controls and press the enter key to activate them.
9087 * The tabindex is default 0, meaning that the tab follows the flow of the document.
9088 * You can overrule this using this parameter if you wish. Use a value of -1 to
9089 * disable built-in keyboard navigation.
9095 * $(document).ready( function() {
9096 * $('#example').dataTable( {
9105 * All strings that DataTables uses in the user interface that it creates
9106 * are defined in this object, allowing you to modified them individually or
9107 * completely replace them all as required.
9112 * Strings that are used for WAI-ARIA labels and controls only (these are not
9113 * actually visible on the page, but will be read by screenreaders, and thus
9114 * must be internationalised as well).
9119 * ARIA label that is added to the table headers when the column may be
9120 * sorted ascending by activing the column (click or return when focused).
9121 * Note that the column header is prefixed to this string.
9123 * @default : activate to sort column ascending
9127 * $(document).ready( function() {
9128 * $('#example').dataTable( {
9131 * "sSortAscending": " - click/return to sort ascending"
9137 "sSortAscending": ": activate to sort column ascending",
9140 * ARIA label that is added to the table headers when the column may be
9141 * sorted descending by activing the column (click or return when focused).
9142 * Note that the column header is prefixed to this string.
9144 * @default : activate to sort column ascending
9148 * $(document).ready( function() {
9149 * $('#example').dataTable( {
9152 * "sSortDescending": " - click/return to sort descending"
9158 "sSortDescending": ": activate to sort column descending"
9162 * Pagination string used by DataTables for the two built-in pagination
9163 * control types ("two_button" and "full_numbers")
9168 * Text to use when using the 'full_numbers' type of pagination for the
9169 * button to take the user to the first page.
9175 * $(document).ready( function() {
9176 * $('#example').dataTable( {
9179 * "sFirst": "First page"
9189 * Text to use when using the 'full_numbers' type of pagination for the
9190 * button to take the user to the last page.
9196 * $(document).ready( function() {
9197 * $('#example').dataTable( {
9200 * "sLast": "Last page"
9210 * Text to use for the 'next' pagination button (to take the user to the
9217 * $(document).ready( function() {
9218 * $('#example').dataTable( {
9221 * "sNext": "Next page"
9231 * Text to use for the 'previous' pagination button (to take the user to
9232 * the previous page).
9238 * $(document).ready( function() {
9239 * $('#example').dataTable( {
9242 * "sPrevious": "Previous page"
9248 "sPrevious": "Previous"
9252 * This string is shown in preference to sZeroRecords when the table is
9253 * empty of data (regardless of filtering). Note that this is an optional
9254 * parameter - if it is not given, the value of sZeroRecords will be used
9255 * instead (either the default or given value).
9257 * @default No data available in table
9261 * $(document).ready( function() {
9262 * $('#example').dataTable( {
9264 * "sEmptyTable": "No data available in table"
9269 "sEmptyTable": "No data available in table",
9273 * This string gives information to the end user about the information that
9274 * is current on display on the page. The _START_, _END_ and _TOTAL_
9275 * variables are all dynamically replaced as the table display updates, and
9276 * can be freely moved or removed as the language requirements change.
9278 * @default Showing _START_ to _END_ of _TOTAL_ entries
9282 * $(document).ready( function() {
9283 * $('#example').dataTable( {
9285 * "sInfo": "Got a total of _TOTAL_ entries to show (_START_ to _END_)"
9290 "sInfo": "Showing _START_ to _END_ of _TOTAL_ entries",
9294 * Display information string for when the table is empty. Typically the
9295 * format of this string should match sInfo.
9297 * @default Showing 0 to 0 of 0 entries
9301 * $(document).ready( function() {
9302 * $('#example').dataTable( {
9304 * "sInfoEmpty": "No entries to show"
9309 "sInfoEmpty": "Showing 0 to 0 of 0 entries",
9313 * When a user filters the information in a table, this string is appended
9314 * to the information (sInfo) to give an idea of how strong the filtering
9315 * is. The variable _MAX_ is dynamically updated.
9317 * @default (filtered from _MAX_ total entries)
9321 * $(document).ready( function() {
9322 * $('#example').dataTable( {
9324 * "sInfoFiltered": " - filtering from _MAX_ records"
9329 "sInfoFiltered": "(filtered from _MAX_ total entries)",
9333 * If can be useful to append extra information to the info string at times,
9334 * and this variable does exactly that. This information will be appended to
9335 * the sInfo (sInfoEmpty and sInfoFiltered in whatever combination they are
9336 * being used) at all times.
9338 * @default <i>Empty string</i>
9342 * $(document).ready( function() {
9343 * $('#example').dataTable( {
9345 * "sInfoPostFix": "All records shown are derived from real information."
9354 * DataTables has a build in number formatter (fnFormatNumber) which is used
9355 * to format large numbers that are used in the table information. By
9356 * default a comma is used, but this can be trivially changed to any
9357 * character you wish with this parameter.
9363 * $(document).ready( function() {
9364 * $('#example').dataTable( {
9366 * "sInfoThousands": "'"
9371 "sInfoThousands": ",",
9375 * Detail the action that will be taken when the drop down menu for the
9376 * pagination length option is changed. The '_MENU_' variable is replaced
9377 * with a default select list of 10, 25, 50 and 100, and can be replaced
9378 * with a custom select box if required.
9380 * @default Show _MENU_ entries
9384 * // Language change only
9385 * $(document).ready( function() {
9386 * $('#example').dataTable( {
9388 * "sLengthMenu": "Display _MENU_ records"
9394 * // Language and options change
9395 * $(document).ready( function() {
9396 * $('#example').dataTable( {
9398 * "sLengthMenu": 'Display <select>'+
9399 * '<option value="10">10</option>'+
9400 * '<option value="20">20</option>'+
9401 * '<option value="30">30</option>'+
9402 * '<option value="40">40</option>'+
9403 * '<option value="50">50</option>'+
9404 * '<option value="-1">All</option>'+
9405 * '</select> records'
9410 "sLengthMenu": "Show _MENU_ entries",
9414 * When using Ajax sourced data and during the first draw when DataTables is
9415 * gathering the data, this message is shown in an empty row in the table to
9416 * indicate to the end user the the data is being loaded. Note that this
9417 * parameter is not used when loading data by server-side processing, just
9418 * Ajax sourced data with client-side processing.
9420 * @default Loading...
9424 * $(document).ready( function() {
9425 * $('#example').dataTable( {
9427 * "sLoadingRecords": "Please wait - loading..."
9432 "sLoadingRecords": "Loading...",
9436 * Text which is displayed when the table is processing a user action
9437 * (usually a sort command or similar).
9439 * @default Processing...
9443 * $(document).ready( function() {
9444 * $('#example').dataTable( {
9446 * "sProcessing": "DataTables is currently busy"
9451 "sProcessing": "Processing...",
9455 * Details the actions that will be taken when the user types into the
9456 * filtering input text box. The variable "_INPUT_", if used in the string,
9457 * is replaced with the HTML text box for the filtering input allowing
9458 * control over where it appears in the string. If "_INPUT_" is not given
9459 * then the input box is appended to the string automatically.
9465 * // Input text box will be appended at the end automatically
9466 * $(document).ready( function() {
9467 * $('#example').dataTable( {
9469 * "sSearch": "Filter records:"
9475 * // Specify where the filter should appear
9476 * $(document).ready( function() {
9477 * $('#example').dataTable( {
9479 * "sSearch": "Apply filter _INPUT_ to table"
9484 "sSearch": "Search:",
9488 * All of the language information can be stored in a file on the
9489 * server-side, which DataTables will look up if this parameter is passed.
9490 * It must store the URL of the language file, which is in a JSON format,
9491 * and the object has the same properties as the oLanguage object in the
9492 * initialiser object (i.e. the above parameters). Please refer to one of
9493 * the example language files to see how this works in action.
9495 * @default <i>Empty string - i.e. disabled</i>
9499 * $(document).ready( function() {
9500 * $('#example').dataTable( {
9502 * "sUrl": "http://www.sprymedia.co.uk/dataTables/lang.txt"
9511 * Text shown inside the table records when the is no information to be
9512 * displayed after filtering. sEmptyTable is shown when there is simply no
9513 * information in the table at all (regardless of filtering).
9515 * @default No matching records found
9519 * $(document).ready( function() {
9520 * $('#example').dataTable( {
9522 * "sZeroRecords": "No records to display"
9527 "sZeroRecords": "No matching records found"
9532 * This parameter allows you to have define the global filtering state at
9533 * initialisation time. As an object the "sSearch" parameter must be
9534 * defined, but all other parameters are optional. When "bRegex" is true,
9535 * the search string will be treated as a regular expression, when false
9536 * (default) it will be treated as a straight string. When "bSmart"
9537 * DataTables will use it's smart filtering methods (to word match at
9538 * any point in the data), when false this will not be done.
9540 * @extends DataTable.models.oSearch
9544 * $(document).ready( function() {
9545 * $('#example').dataTable( {
9546 * "oSearch": {"sSearch": "Initial search"}
9550 "oSearch": $.extend( {}, DataTable.models.oSearch ),
9554 * By default DataTables will look for the property 'aaData' when obtaining
9555 * data from an Ajax source or for server-side processing - this parameter
9556 * allows that property to be changed. You can use Javascript dotted object
9557 * notation to get a data source for multiple levels of nesting.
9561 * @dtopt Server-side
9564 * // Get data from { "data": [...] }
9565 * $(document).ready( function() {
9566 * var oTable = $('#example').dataTable( {
9567 * "sAjaxSource": "sources/data.txt",
9568 * "sAjaxDataProp": "data"
9573 * // Get data from { "data": { "inner": [...] } }
9574 * $(document).ready( function() {
9575 * var oTable = $('#example').dataTable( {
9576 * "sAjaxSource": "sources/data.txt",
9577 * "sAjaxDataProp": "data.inner"
9581 "sAjaxDataProp": "aaData",
9585 * You can instruct DataTables to load data from an external source using this
9586 * parameter (use aData if you want to pass data in you already have). Simply
9587 * provide a url a JSON object can be obtained from. This object must include
9588 * the parameter 'aaData' which is the data source for the table.
9592 * @dtopt Server-side
9595 * $(document).ready( function() {
9596 * $('#example').dataTable( {
9597 * "sAjaxSource": "http://www.sprymedia.co.uk/dataTables/json.php"
9601 "sAjaxSource": null,
9605 * This parameter can be used to override the default prefix that DataTables
9606 * assigns to a cookie when state saving is enabled.
9608 * @default SpryMedia_DataTables_
9612 * $(document).ready( function() {
9613 * $('#example').dataTable( {
9614 * "sCookiePrefix": "my_datatable_",
9618 "sCookiePrefix": "SpryMedia_DataTables_",
9622 * This initialisation variable allows you to specify exactly where in the
9623 * DOM you want DataTables to inject the various controls it adds to the page
9624 * (for example you might want the pagination controls at the top of the
9625 * table). DIV elements (with or without a custom class) can also be added to
9626 * aid styling. The follow syntax is used:
9628 * <li>The following options are allowed:
9630 * <li>'l' - Length changing</li
9631 * <li>'f' - Filtering input</li>
9632 * <li>'t' - The table!</li>
9633 * <li>'i' - Information</li>
9634 * <li>'p' - Pagination</li>
9635 * <li>'r' - pRocessing</li>
9638 * <li>The following constants are allowed:
9640 * <li>'H' - jQueryUI theme "header" classes ('fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix')</li>
9641 * <li>'F' - jQueryUI theme "footer" classes ('fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix')</li>
9644 * <li>The following syntax is expected:
9646 * <li>'<' and '>' - div elements</li>
9647 * <li>'<"class" and '>' - div with a class</li>
9648 * <li>'<"#id" and '>' - div with an ID</li>
9653 * <li>'<"wrapper"flipt>'</li>
9654 * <li>'<lf<t>ip>'</li>
9659 * @default lfrtip <i>(when bJQueryUI is false)</i> <b>or</b>
9660 * <"H"lfr>t<"F"ip> <i>(when bJQueryUI is true)</i>
9664 * $(document).ready( function() {
9665 * $('#example').dataTable( {
9666 * "sDom": '<"top"i>rt<"bottom"flp><"clear">'
9674 * DataTables features two different built-in pagination interaction methods
9675 * ('two_button' or 'full_numbers') which present different page controls to
9676 * the end user. Further methods can be added using the API (see below).
9678 * @default two_button
9682 * $(document).ready( function() {
9683 * $('#example').dataTable( {
9684 * "sPaginationType": "full_numbers"
9688 "sPaginationType": "two_button",
9692 * Enable horizontal scrolling. When a table is too wide to fit into a certain
9693 * layout, or you have a large number of columns in the table, you can enable
9694 * x-scrolling to show the table in a viewport, which can be scrolled. This
9695 * property can be any CSS unit, or a number (in which case it will be treated
9696 * as a pixel measurement).
9698 * @default <i>blank string - i.e. disabled</i>
9702 * $(document).ready( function() {
9703 * $('#example').dataTable( {
9704 * "sScrollX": "100%",
9705 * "bScrollCollapse": true
9713 * This property can be used to force a DataTable to use more width than it
9714 * might otherwise do when x-scrolling is enabled. For example if you have a
9715 * table which requires to be well spaced, this parameter is useful for
9716 * "over-sizing" the table, and thus forcing scrolling. This property can by
9717 * any CSS unit, or a number (in which case it will be treated as a pixel
9720 * @default <i>blank string - i.e. disabled</i>
9724 * $(document).ready( function() {
9725 * $('#example').dataTable( {
9726 * "sScrollX": "100%",
9727 * "sScrollXInner": "110%"
9731 "sScrollXInner": "",
9735 * Enable vertical scrolling. Vertical scrolling will constrain the DataTable
9736 * to the given height, and enable scrolling for any data which overflows the
9737 * current viewport. This can be used as an alternative to paging to display
9738 * a lot of data in a small area (although paging and scrolling can both be
9739 * enabled at the same time). This property can be any CSS unit, or a number
9740 * (in which case it will be treated as a pixel measurement).
9742 * @default <i>blank string - i.e. disabled</i>
9746 * $(document).ready( function() {
9747 * $('#example').dataTable( {
9748 * "sScrollY": "200px",
9749 * "bPaginate": false
9757 * Set the HTTP method that is used to make the Ajax call for server-side
9758 * processing or Ajax sourced data.
9762 * @dtopt Server-side
9765 * $(document).ready( function() {
9766 * $('#example').dataTable( {
9767 * "bServerSide": true,
9768 * "sAjaxSource": "scripts/post.php",
9769 * "sServerMethod": "POST"
9773 "sServerMethod": "GET"
9779 * Column options that can be given to DataTables at initialisation time.
9782 DataTable.defaults.columns = {
9784 * Allows a column's sorting to take multiple columns into account when
9785 * doing a sort. For example first name / last name columns make sense to
9786 * do a multi-column sort over the two columns.
9788 * @default null <i>Takes the value of the column index automatically</i>
9792 * // Using aoColumnDefs
9793 * $(document).ready( function() {
9794 * $('#example').dataTable( {
9796 * { "aDataSort": [ 0, 1 ], "aTargets": [ 0 ] },
9797 * { "aDataSort": [ 1, 0 ], "aTargets": [ 1 ] },
9798 * { "aDataSort": [ 2, 3, 4 ], "aTargets": [ 2 ] }
9804 * // Using aoColumns
9805 * $(document).ready( function() {
9806 * $('#example').dataTable( {
9808 * { "aDataSort": [ 0, 1 ] },
9809 * { "aDataSort": [ 1, 0 ] },
9810 * { "aDataSort": [ 2, 3, 4 ] },
9821 * You can control the default sorting direction, and even alter the behaviour
9822 * of the sort handler (i.e. only allow ascending sorting etc) using this
9825 * @default [ 'asc', 'desc' ]
9829 * // Using aoColumnDefs
9830 * $(document).ready( function() {
9831 * $('#example').dataTable( {
9833 * { "asSorting": [ "asc" ], "aTargets": [ 1 ] },
9834 * { "asSorting": [ "desc", "asc", "asc" ], "aTargets": [ 2 ] },
9835 * { "asSorting": [ "desc" ], "aTargets": [ 3 ] }
9841 * // Using aoColumns
9842 * $(document).ready( function() {
9843 * $('#example').dataTable( {
9846 * { "asSorting": [ "asc" ] },
9847 * { "asSorting": [ "desc", "asc", "asc" ] },
9848 * { "asSorting": [ "desc" ] },
9854 "asSorting": [ 'asc', 'desc' ],
9858 * Enable or disable filtering on the data in this column.
9864 * // Using aoColumnDefs
9865 * $(document).ready( function() {
9866 * $('#example').dataTable( {
9868 * { "bSearchable": false, "aTargets": [ 0 ] }
9873 * // Using aoColumns
9874 * $(document).ready( function() {
9875 * $('#example').dataTable( {
9877 * { "bSearchable": false },
9885 "bSearchable": true,
9889 * Enable or disable sorting on this column.
9895 * // Using aoColumnDefs
9896 * $(document).ready( function() {
9897 * $('#example').dataTable( {
9899 * { "bSortable": false, "aTargets": [ 0 ] }
9904 * // Using aoColumns
9905 * $(document).ready( function() {
9906 * $('#example').dataTable( {
9908 * { "bSortable": false },
9920 * <code>Deprecated</code> When using fnRender() for a column, you may wish
9921 * to use the original data (before rendering) for sorting and filtering
9922 * (the default is to used the rendered data that the user can see). This
9923 * may be useful for dates etc.
9925 * Please note that this option has now been deprecated and will be removed
9926 * in the next version of DataTables. Please use mRender / mData rather than
9933 "bUseRendered": true,
9937 * Enable or disable the display of this column.
9943 * // Using aoColumnDefs
9944 * $(document).ready( function() {
9945 * $('#example').dataTable( {
9947 * { "bVisible": false, "aTargets": [ 0 ] }
9952 * // Using aoColumns
9953 * $(document).ready( function() {
9954 * $('#example').dataTable( {
9956 * { "bVisible": false },
9968 * Developer definable function that is called whenever a cell is created (Ajax source,
9969 * etc) or processed for input (DOM source). This can be used as a compliment to mRender
9970 * allowing you to modify the DOM element (add background colour for example) when the
9971 * element is available.
9973 * @param {element} nTd The TD node that has been created
9974 * @param {*} sData The Data for the cell
9975 * @param {array|object} oData The data for the whole row
9976 * @param {int} iRow The row index for the aoData data store
9977 * @param {int} iCol The column index for aoColumns
9981 * $(document).ready( function() {
9982 * $('#example').dataTable( {
9983 * "aoColumnDefs": [ {
9985 * "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
9986 * if ( sData == "1.7" ) {
9987 * $(nTd).css('color', 'blue')
9994 "fnCreatedCell": null,
9998 * <code>Deprecated</code> Custom display function that will be called for the
9999 * display of each cell in this column.
10001 * Please note that this option has now been deprecated and will be removed
10002 * in the next version of DataTables. Please use mRender / mData rather than
10005 * @param {object} o Object with the following parameters:
10006 * @param {int} o.iDataRow The row in aoData
10007 * @param {int} o.iDataColumn The column in question
10008 * @param {array} o.aData The data for the row in question
10009 * @param {object} o.oSettings The settings object for this DataTables instance
10010 * @param {object} o.mDataProp The data property used for this column
10011 * @param {*} val The current cell value
10012 * @returns {string} The string you which to use in the display
10020 * The column index (starting from 0!) that you wish a sort to be performed
10021 * upon when this column is selected for sorting. This can be used for sorting
10022 * on hidden columns for example.
10024 * @default -1 <i>Use automatically calculated column index</i>
10028 * // Using aoColumnDefs
10029 * $(document).ready( function() {
10030 * $('#example').dataTable( {
10031 * "aoColumnDefs": [
10032 * { "iDataSort": 1, "aTargets": [ 0 ] }
10038 * // Using aoColumns
10039 * $(document).ready( function() {
10040 * $('#example').dataTable( {
10042 * { "iDataSort": 1 },
10055 * This parameter has been replaced by mData in DataTables to ensure naming
10056 * consistency. mDataProp can still be used, as there is backwards compatibility
10057 * in DataTables for this option, but it is strongly recommended that you use
10058 * mData in preference to mDataProp.
10059 * @name DataTable.defaults.columns.mDataProp
10064 * This property can be used to read data from any JSON data source property,
10065 * including deeply nested objects / properties. mData can be given in a
10066 * number of different ways which effect its behaviour:
10068 * <li>integer - treated as an array index for the data source. This is the
10069 * default that DataTables uses (incrementally increased for each column).</li>
10070 * <li>string - read an object property from the data source. Note that you can
10071 * use Javascript dotted notation to read deep properties / arrays from the
10072 * data source.</li>
10073 * <li>null - the sDefaultContent option will be used for the cell (null
10074 * by default, so you will need to specify the default content you want -
10075 * typically an empty string). This can be useful on generated columns such
10076 * as edit / delete action columns.</li>
10077 * <li>function - the function given will be executed whenever DataTables
10078 * needs to set or get the data for a cell in the column. The function
10079 * takes three parameters:
10081 * <li>{array|object} The data source for the row</li>
10082 * <li>{string} The type call data requested - this will be 'set' when
10083 * setting data or 'filter', 'display', 'type', 'sort' or undefined when
10084 * gathering data. Note that when <i>undefined</i> is given for the type
10085 * DataTables expects to get the raw data for the object back</li>
10086 * <li>{*} Data to set when the second parameter is 'set'.</li>
10088 * The return value from the function is not required when 'set' is the type
10089 * of call, but otherwise the return is what will be used for the data
10093 * Note that prior to DataTables 1.9.2 mData was called mDataProp. The name change
10094 * reflects the flexibility of this property and is consistent with the naming of
10095 * mRender. If 'mDataProp' is given, then it will still be used by DataTables, as
10096 * it automatically maps the old name to the new if required.
10097 * @type string|int|function|null
10098 * @default null <i>Use automatically calculated column index</i>
10102 * // Read table data from objects
10103 * $(document).ready( function() {
10104 * var oTable = $('#example').dataTable( {
10105 * "sAjaxSource": "sources/deep.txt",
10107 * { "mData": "engine" },
10108 * { "mData": "browser" },
10109 * { "mData": "platform.inner" },
10110 * { "mData": "platform.details.0" },
10111 * { "mData": "platform.details.1" }
10117 * // Using mData as a function to provide different information for
10118 * // sorting, filtering and display. In this case, currency (price)
10119 * $(document).ready( function() {
10120 * var oTable = $('#example').dataTable( {
10121 * "aoColumnDefs": [ {
10122 * "aTargets": [ 0 ],
10123 * "mData": function ( source, type, val ) {
10124 * if (type === 'set') {
10125 * source.price = val;
10126 * // Store the computed dislay and filter values for efficiency
10127 * source.price_display = val=="" ? "" : "$"+numberFormat(val);
10128 * source.price_filter = val=="" ? "" : "$"+numberFormat(val)+" "+val;
10131 * else if (type === 'display') {
10132 * return source.price_display;
10134 * else if (type === 'filter') {
10135 * return source.price_filter;
10137 * // 'sort', 'type' and undefined all just use the integer
10138 * return source.price;
10148 * This property is the rendering partner to mData and it is suggested that
10149 * when you want to manipulate data for display (including filtering, sorting etc)
10150 * but not altering the underlying data for the table, use this property. mData
10151 * can actually do everything this property can and more, but this parameter is
10152 * easier to use since there is no 'set' option. Like mData is can be given
10153 * in a number of different ways to effect its behaviour, with the addition of
10154 * supporting array syntax for easy outputting of arrays (including arrays of
10157 * <li>integer - treated as an array index for the data source. This is the
10158 * default that DataTables uses (incrementally increased for each column).</li>
10159 * <li>string - read an object property from the data source. Note that you can
10160 * use Javascript dotted notation to read deep properties / arrays from the
10161 * data source and also array brackets to indicate that the data reader should
10162 * loop over the data source array. When characters are given between the array
10163 * brackets, these characters are used to join the data source array together.
10164 * For example: "accounts[, ].name" would result in a comma separated list with
10165 * the 'name' value from the 'accounts' array of objects.</li>
10166 * <li>function - the function given will be executed whenever DataTables
10167 * needs to set or get the data for a cell in the column. The function
10168 * takes three parameters:
10170 * <li>{array|object} The data source for the row (based on mData)</li>
10171 * <li>{string} The type call data requested - this will be 'filter', 'display',
10172 * 'type' or 'sort'.</li>
10173 * <li>{array|object} The full data source for the row (not based on mData)</li>
10175 * The return value from the function is what will be used for the data
10178 * @type string|int|function|null
10179 * @default null <i>Use mData</i>
10183 * // Create a comma separated list from an array of objects
10184 * $(document).ready( function() {
10185 * var oTable = $('#example').dataTable( {
10186 * "sAjaxSource": "sources/deep.txt",
10188 * { "mData": "engine" },
10189 * { "mData": "browser" },
10191 * "mData": "platform",
10192 * "mRender": "[, ].name"
10199 * // Use as a function to create a link from the data source
10200 * $(document).ready( function() {
10201 * var oTable = $('#example').dataTable( {
10202 * "aoColumnDefs": [
10204 * "aTargets": [ 0 ],
10205 * "mData": "download_link",
10206 * "mRender": function ( data, type, full ) {
10207 * return '<a href="'+data+'">Download</a>';
10217 * Change the cell type created for the column - either TD cells or TH cells. This
10218 * can be useful as TH cells have semantic meaning in the table body, allowing them
10219 * to act as a header for a row (you may wish to add scope='row' to the TH elements).
10225 * // Make the first column use TH cells
10226 * $(document).ready( function() {
10227 * var oTable = $('#example').dataTable( {
10228 * "aoColumnDefs": [ {
10229 * "aTargets": [ 0 ],
10230 * "sCellType": "th"
10239 * Class to give to each cell in this column.
10241 * @default <i>Empty string</i>
10245 * // Using aoColumnDefs
10246 * $(document).ready( function() {
10247 * $('#example').dataTable( {
10248 * "aoColumnDefs": [
10249 * { "sClass": "my_class", "aTargets": [ 0 ] }
10255 * // Using aoColumns
10256 * $(document).ready( function() {
10257 * $('#example').dataTable( {
10259 * { "sClass": "my_class" },
10271 * When DataTables calculates the column widths to assign to each column,
10272 * it finds the longest string in each column and then constructs a
10273 * temporary table and reads the widths from that. The problem with this
10274 * is that "mmm" is much wider then "iiii", but the latter is a longer
10275 * string - thus the calculation can go wrong (doing it properly and putting
10276 * it into an DOM object and measuring that is horribly(!) slow). Thus as
10277 * a "work around" we provide this option. It will append its value to the
10278 * text that is found to be the longest string for the column - i.e. padding.
10279 * Generally you shouldn't need this, and it is not documented on the
10280 * general DataTables.net documentation
10282 * @default <i>Empty string<i>
10286 * // Using aoColumns
10287 * $(document).ready( function() {
10288 * $('#example').dataTable( {
10294 * "sContentPadding": "mmm"
10300 "sContentPadding": "",
10304 * Allows a default value to be given for a column's data, and will be used
10305 * whenever a null data source is encountered (this can be because mData
10306 * is set to null, or because the data source itself is null).
10312 * // Using aoColumnDefs
10313 * $(document).ready( function() {
10314 * $('#example').dataTable( {
10315 * "aoColumnDefs": [
10318 * "sDefaultContent": "Edit",
10319 * "aTargets": [ -1 ]
10326 * // Using aoColumns
10327 * $(document).ready( function() {
10328 * $('#example').dataTable( {
10335 * "sDefaultContent": "Edit"
10341 "sDefaultContent": null,
10345 * This parameter is only used in DataTables' server-side processing. It can
10346 * be exceptionally useful to know what columns are being displayed on the
10347 * client side, and to map these to database fields. When defined, the names
10348 * also allow DataTables to reorder information from the server if it comes
10349 * back in an unexpected order (i.e. if you switch your columns around on the
10350 * client-side, your server-side code does not also need updating).
10352 * @default <i>Empty string</i>
10356 * // Using aoColumnDefs
10357 * $(document).ready( function() {
10358 * $('#example').dataTable( {
10359 * "aoColumnDefs": [
10360 * { "sName": "engine", "aTargets": [ 0 ] },
10361 * { "sName": "browser", "aTargets": [ 1 ] },
10362 * { "sName": "platform", "aTargets": [ 2 ] },
10363 * { "sName": "version", "aTargets": [ 3 ] },
10364 * { "sName": "grade", "aTargets": [ 4 ] }
10370 * // Using aoColumns
10371 * $(document).ready( function() {
10372 * $('#example').dataTable( {
10374 * { "sName": "engine" },
10375 * { "sName": "browser" },
10376 * { "sName": "platform" },
10377 * { "sName": "version" },
10378 * { "sName": "grade" }
10387 * Defines a data source type for the sorting which can be used to read
10388 * real-time information from the table (updating the internally cached
10389 * version) prior to sorting. This allows sorting to occur on user editable
10390 * elements such as form inputs.
10396 * // Using aoColumnDefs
10397 * $(document).ready( function() {
10398 * $('#example').dataTable( {
10399 * "aoColumnDefs": [
10400 * { "sSortDataType": "dom-text", "aTargets": [ 2, 3 ] },
10401 * { "sType": "numeric", "aTargets": [ 3 ] },
10402 * { "sSortDataType": "dom-select", "aTargets": [ 4 ] },
10403 * { "sSortDataType": "dom-checkbox", "aTargets": [ 5 ] }
10409 * // Using aoColumns
10410 * $(document).ready( function() {
10411 * $('#example').dataTable( {
10415 * { "sSortDataType": "dom-text" },
10416 * { "sSortDataType": "dom-text", "sType": "numeric" },
10417 * { "sSortDataType": "dom-select" },
10418 * { "sSortDataType": "dom-checkbox" }
10423 "sSortDataType": "std",
10427 * The title of this column.
10429 * @default null <i>Derived from the 'TH' value for this column in the
10430 * original HTML table.</i>
10434 * // Using aoColumnDefs
10435 * $(document).ready( function() {
10436 * $('#example').dataTable( {
10437 * "aoColumnDefs": [
10438 * { "sTitle": "My column title", "aTargets": [ 0 ] }
10444 * // Using aoColumns
10445 * $(document).ready( function() {
10446 * $('#example').dataTable( {
10448 * { "sTitle": "My column title" },
10461 * The type allows you to specify how the data for this column will be sorted.
10462 * Four types (string, numeric, date and html (which will strip HTML tags
10463 * before sorting)) are currently available. Note that only date formats
10464 * understood by Javascript's Date() object will be accepted as type date. For
10465 * example: "Mar 26, 2008 5:03 PM". May take the values: 'string', 'numeric',
10466 * 'date' or 'html' (by default). Further types can be adding through
10469 * @default null <i>Auto-detected from raw data</i>
10473 * // Using aoColumnDefs
10474 * $(document).ready( function() {
10475 * $('#example').dataTable( {
10476 * "aoColumnDefs": [
10477 * { "sType": "html", "aTargets": [ 0 ] }
10483 * // Using aoColumns
10484 * $(document).ready( function() {
10485 * $('#example').dataTable( {
10487 * { "sType": "html" },
10500 * Defining the width of the column, this parameter may take any CSS value
10501 * (3em, 20px etc). DataTables apples 'smart' widths to columns which have not
10502 * been given a specific width through this interface ensuring that the table
10503 * remains readable.
10505 * @default null <i>Automatic</i>
10509 * // Using aoColumnDefs
10510 * $(document).ready( function() {
10511 * $('#example').dataTable( {
10512 * "aoColumnDefs": [
10513 * { "sWidth": "20%", "aTargets": [ 0 ] }
10519 * // Using aoColumns
10520 * $(document).ready( function() {
10521 * $('#example').dataTable( {
10523 * { "sWidth": "20%" },
10538 * DataTables settings object - this holds all the information needed for a
10539 * given table, including configuration, data and current application of the
10540 * table options. DataTables does not have a single instance for each DataTable
10541 * with the settings attached to that instance, but rather instances of the
10542 * DataTable "class" are created on-the-fly as needed (typically by a
10543 * $().dataTable() call) and the settings object is then applied to that
10546 * Note that this object is related to {@link DataTable.defaults} but this
10547 * one is the internal data store for DataTables's cache of columns. It should
10548 * NOT be manipulated outside of DataTables. Any configuration should be done
10549 * through the initialisation options.
10551 * @todo Really should attach the settings object to individual instances so we
10552 * don't need to create new instances on each $().dataTable() call (if the
10553 * table already exists). It would also save passing oSettings around and
10554 * into every single function. However, this is a very significant
10555 * architecture change for DataTables and will almost certainly break
10556 * backwards compatibility with older installations. This is something that
10557 * will be done in 2.0.
10559 DataTable.models.oSettings = {
10561 * Primary features of DataTables and their enablement state.
10567 * Flag to say if DataTables should automatically try to calculate the
10568 * optimum table and columns widths (true) or not (false).
10569 * Note that this parameter will be set by the initialisation routine. To
10570 * set a default use {@link DataTable.defaults}.
10573 "bAutoWidth": null,
10576 * Delay the creation of TR and TD elements until they are actually
10577 * needed by a driven page draw. This can give a significant speed
10578 * increase for Ajax source and Javascript source data, but makes no
10579 * difference at all fro DOM and server-side processing tables.
10580 * Note that this parameter will be set by the initialisation routine. To
10581 * set a default use {@link DataTable.defaults}.
10584 "bDeferRender": null,
10587 * Enable filtering on the table or not. Note that if this is disabled
10588 * then there is no filtering at all on the table, including fnFilter.
10589 * To just remove the filtering input use sDom and remove the 'f' option.
10590 * Note that this parameter will be set by the initialisation routine. To
10591 * set a default use {@link DataTable.defaults}.
10597 * Table information element (the 'Showing x of y records' div) enable
10599 * Note that this parameter will be set by the initialisation routine. To
10600 * set a default use {@link DataTable.defaults}.
10606 * Present a user control allowing the end user to change the page size
10607 * when pagination is enabled.
10608 * Note that this parameter will be set by the initialisation routine. To
10609 * set a default use {@link DataTable.defaults}.
10612 "bLengthChange": null,
10615 * Pagination enabled or not. Note that if this is disabled then length
10616 * changing must also be disabled.
10617 * Note that this parameter will be set by the initialisation routine. To
10618 * set a default use {@link DataTable.defaults}.
10624 * Processing indicator enable flag whenever DataTables is enacting a
10625 * user request - typically an Ajax request for server-side processing.
10626 * Note that this parameter will be set by the initialisation routine. To
10627 * set a default use {@link DataTable.defaults}.
10630 "bProcessing": null,
10633 * Server-side processing enabled flag - when enabled DataTables will
10634 * get all data from the server for every draw - there is no filtering,
10635 * sorting or paging done on the client-side.
10636 * Note that this parameter will be set by the initialisation routine. To
10637 * set a default use {@link DataTable.defaults}.
10640 "bServerSide": null,
10643 * Sorting enablement flag.
10644 * Note that this parameter will be set by the initialisation routine. To
10645 * set a default use {@link DataTable.defaults}.
10651 * Apply a class to the columns which are being sorted to provide a
10652 * visual highlight or not. This can slow things down when enabled since
10653 * there is a lot of DOM interaction.
10654 * Note that this parameter will be set by the initialisation routine. To
10655 * set a default use {@link DataTable.defaults}.
10658 "bSortClasses": null,
10661 * State saving enablement flag.
10662 * Note that this parameter will be set by the initialisation routine. To
10663 * set a default use {@link DataTable.defaults}.
10671 * Scrolling settings for a table.
10676 * Indicate if DataTables should be allowed to set the padding / margin
10677 * etc for the scrolling header elements or not. Typically you will want
10679 * Note that this parameter will be set by the initialisation routine. To
10680 * set a default use {@link DataTable.defaults}.
10686 * When the table is shorter in height than sScrollY, collapse the
10687 * table container down to the height of the table (when true).
10688 * Note that this parameter will be set by the initialisation routine. To
10689 * set a default use {@link DataTable.defaults}.
10695 * Infinite scrolling enablement flag. Now deprecated in favour of
10696 * using the Scroller plug-in.
10697 * Note that this parameter will be set by the initialisation routine. To
10698 * set a default use {@link DataTable.defaults}.
10704 * Width of the scrollbar for the web-browser's platform. Calculated
10705 * during table initialisation.
10712 * Space (in pixels) between the bottom of the scrolling container and
10713 * the bottom of the scrolling viewport before the next page is loaded
10714 * when using infinite scrolling.
10715 * Note that this parameter will be set by the initialisation routine. To
10716 * set a default use {@link DataTable.defaults}.
10722 * Viewport width for horizontal scrolling. Horizontal scrolling is
10723 * disabled if an empty string.
10724 * Note that this parameter will be set by the initialisation routine. To
10725 * set a default use {@link DataTable.defaults}.
10731 * Width to expand the table to when using x-scrolling. Typically you
10732 * should not need to use this.
10733 * Note that this parameter will be set by the initialisation routine. To
10734 * set a default use {@link DataTable.defaults}.
10741 * Viewport height for vertical scrolling. Vertical scrolling is disabled
10742 * if an empty string.
10743 * Note that this parameter will be set by the initialisation routine. To
10744 * set a default use {@link DataTable.defaults}.
10751 * Language information for the table.
10753 * @extends DataTable.defaults.oLanguage
10757 * Information callback function. See
10758 * {@link DataTable.defaults.fnInfoCallback}
10762 "fnInfoCallback": null
10766 * Browser support parameters
10771 * Indicate if the browser incorrectly calculates width:100% inside a
10772 * scrolling element (IE6/7)
10776 "bScrollOversize": false
10780 * Array referencing the nodes which are used for the features. The
10781 * parameters of this object match what is allowed by sDom - i.e.
10783 * <li>'l' - Length changing</li>
10784 * <li>'f' - Filtering input</li>
10785 * <li>'t' - The table!</li>
10786 * <li>'i' - Information</li>
10787 * <li>'p' - Pagination</li>
10788 * <li>'r' - pRocessing</li>
10796 * Store data information - see {@link DataTable.models.oRow} for detailed
10804 * Array of indexes which are in the current display (after filtering etc)
10811 * Array of indexes for display - no filtering
10815 "aiDisplayMaster": [],
10818 * Store information about each column that is in use
10825 * Store information about the table's header
10832 * Store information about the table's footer
10839 * Search data array for regular expression searching
10843 "asDataSearch": [],
10846 * Store the applied global search information in case we want to force a
10847 * research or compare the old search to a new one.
10848 * Note that this parameter will be set by the initialisation routine. To
10849 * set a default use {@link DataTable.defaults}.
10851 * @extends DataTable.models.oSearch
10853 "oPreviousSearch": {},
10856 * Store the applied search for each column - see
10857 * {@link DataTable.models.oSearch} for the format that is used for the
10858 * filtering information for each column.
10862 "aoPreSearchCols": [],
10865 * Sorting that is applied to the table. Note that the inner arrays are
10866 * used in the following manner:
10868 * <li>Index 0 - column number</li>
10869 * <li>Index 1 - current sorting direction</li>
10870 * <li>Index 2 - index of asSorting for this column</li>
10872 * Note that this parameter will be set by the initialisation routine. To
10873 * set a default use {@link DataTable.defaults}.
10875 * @todo These inner arrays should really be objects
10880 * Sorting that is always applied to the table (i.e. prefixed in front of
10882 * Note that this parameter will be set by the initialisation routine. To
10883 * set a default use {@link DataTable.defaults}.
10887 "aaSortingFixed": null,
10890 * Classes to use for the striping of a table.
10891 * Note that this parameter will be set by the initialisation routine. To
10892 * set a default use {@link DataTable.defaults}.
10896 "asStripeClasses": null,
10899 * If restoring a table - we should restore its striping classes as well
10903 "asDestroyStripes": [],
10906 * If restoring a table - we should restore its width
10910 "sDestroyWidth": 0,
10913 * Callback functions array for every time a row is inserted (i.e. on a draw).
10917 "aoRowCallback": [],
10920 * Callback functions for the header on each draw.
10924 "aoHeaderCallback": [],
10927 * Callback function for the footer on each draw.
10931 "aoFooterCallback": [],
10934 * Array of callback functions for draw callback functions
10938 "aoDrawCallback": [],
10941 * Array of callback functions for row created function
10945 "aoRowCreatedCallback": [],
10948 * Callback functions for just before the table is redrawn. A return of
10949 * false will be used to cancel the draw.
10953 "aoPreDrawCallback": [],
10956 * Callback functions for when the table has been initialised.
10960 "aoInitComplete": [],
10964 * Callbacks for modifying the settings to be stored for state saving, prior to
10969 "aoStateSaveParams": [],
10972 * Callbacks for modifying the settings that have been stored for state saving
10973 * prior to using the stored values to restore the state.
10977 "aoStateLoadParams": [],
10980 * Callbacks for operating on the settings object once the saved state has been
10985 "aoStateLoaded": [],
10988 * Cache the table ID for quick access
10990 * @default <i>Empty string</i>
10995 * The TABLE node for the main table
11002 * Permanent ref to the thead element
11009 * Permanent ref to the tfoot element - if it exists
11016 * Permanent ref to the tbody element
11023 * Cache the wrapper node (contains all DataTables controlled elements)
11027 "nTableWrapper": null,
11030 * Indicate if when using server-side processing the loading of data
11031 * should be deferred until the second draw.
11032 * Note that this parameter will be set by the initialisation routine. To
11033 * set a default use {@link DataTable.defaults}.
11037 "bDeferLoading": false,
11040 * Indicate if all required information has been read in
11044 "bInitialised": false,
11047 * Information about open rows. Each object in the array has the parameters
11048 * 'nTr' and 'nParent'
11055 * Dictate the positioning of DataTables' control elements - see
11056 * {@link DataTable.model.oInit.sDom}.
11057 * Note that this parameter will be set by the initialisation routine. To
11058 * set a default use {@link DataTable.defaults}.
11065 * Which type of pagination should be used.
11066 * Note that this parameter will be set by the initialisation routine. To
11067 * set a default use {@link DataTable.defaults}.
11069 * @default two_button
11071 "sPaginationType": "two_button",
11074 * The cookie duration (for bStateSave) in seconds.
11075 * Note that this parameter will be set by the initialisation routine. To
11076 * set a default use {@link DataTable.defaults}.
11080 "iCookieDuration": 0,
11083 * The cookie name prefix.
11084 * Note that this parameter will be set by the initialisation routine. To
11085 * set a default use {@link DataTable.defaults}.
11087 * @default <i>Empty string</i>
11089 "sCookiePrefix": "",
11092 * Callback function for cookie creation.
11093 * Note that this parameter will be set by the initialisation routine. To
11094 * set a default use {@link DataTable.defaults}.
11098 "fnCookieCallback": null,
11101 * Array of callback functions for state saving. Each array element is an
11102 * object with the following parameters:
11104 * <li>function:fn - function to call. Takes two parameters, oSettings
11105 * and the JSON string to save that has been thus far created. Returns
11106 * a JSON string to be inserted into a json object
11107 * (i.e. '"param": [ 0, 1, 2]')</li>
11108 * <li>string:sName - name of callback</li>
11116 * Array of callback functions for state loading. Each array element is an
11117 * object with the following parameters:
11119 * <li>function:fn - function to call. Takes two parameters, oSettings
11120 * and the object stored. May return false to cancel state loading</li>
11121 * <li>string:sName - name of callback</li>
11129 * State that was loaded from the cookie. Useful for back reference
11133 "oLoadedState": null,
11136 * Source url for AJAX data for the table.
11137 * Note that this parameter will be set by the initialisation routine. To
11138 * set a default use {@link DataTable.defaults}.
11142 "sAjaxSource": null,
11145 * Property from a given object from which to read the table data from. This
11146 * can be an empty string (when not server-side processing), in which case
11147 * it is assumed an an array is given directly.
11148 * Note that this parameter will be set by the initialisation routine. To
11149 * set a default use {@link DataTable.defaults}.
11152 "sAjaxDataProp": null,
11155 * Note if draw should be blocked while getting data
11159 "bAjaxDataGet": true,
11162 * The last jQuery XHR object that was used for server-side data gathering.
11163 * This can be used for working with the XHR information in one of the
11171 * Function to get the server-side data.
11172 * Note that this parameter will be set by the initialisation routine. To
11173 * set a default use {@link DataTable.defaults}.
11176 "fnServerData": null,
11179 * Functions which are called prior to sending an Ajax request so extra
11180 * parameters can easily be sent to the server
11184 "aoServerParams": [],
11187 * Send the XHR HTTP method - GET or POST (could be PUT or DELETE if
11189 * Note that this parameter will be set by the initialisation routine. To
11190 * set a default use {@link DataTable.defaults}.
11193 "sServerMethod": null,
11196 * Format numbers for display.
11197 * Note that this parameter will be set by the initialisation routine. To
11198 * set a default use {@link DataTable.defaults}.
11201 "fnFormatNumber": null,
11204 * List of options that can be used for the user selectable length menu.
11205 * Note that this parameter will be set by the initialisation routine. To
11206 * set a default use {@link DataTable.defaults}.
11210 "aLengthMenu": null,
11213 * Counter for the draws that the table does. Also used as a tracker for
11214 * server-side processing
11221 * Indicate if a redraw is being done - useful for Ajax
11228 * Draw index (iDraw) of the last error when parsing the returned data
11235 * Paging display length
11239 "_iDisplayLength": 10,
11242 * Paging start point - aiDisplay index
11246 "_iDisplayStart": 0,
11249 * Paging end point - aiDisplay index. Use fnDisplayEnd rather than
11250 * this property to get the end point
11255 "_iDisplayEnd": 10,
11258 * Server-side processing - number of records in the result set
11259 * (i.e. before filtering), Use fnRecordsTotal rather than
11260 * this property to get the value of the number of records, regardless of
11261 * the server-side processing setting.
11266 "_iRecordsTotal": 0,
11269 * Server-side processing - number of records in the current display set
11270 * (i.e. after filtering). Use fnRecordsDisplay rather than
11271 * this property to get the value of the number of records, regardless of
11272 * the server-side processing setting.
11277 "_iRecordsDisplay": 0,
11280 * Flag to indicate if jQuery UI marking and classes should be used.
11281 * Note that this parameter will be set by the initialisation routine. To
11282 * set a default use {@link DataTable.defaults}.
11288 * The classes to use for the table
11295 * Flag attached to the settings object so you can check in the draw
11296 * callback if filtering has been done in the draw. Deprecated in favour of
11302 "bFiltered": false,
11305 * Flag attached to the settings object so you can check in the draw
11306 * callback if sorting has been done in the draw. Deprecated in favour of
11315 * Indicate that if multiple rows are in the header and there is more than
11316 * one unique cell per column, if the top one (true) or bottom one (false)
11317 * should be used for sorting / title by DataTables.
11318 * Note that this parameter will be set by the initialisation routine. To
11319 * set a default use {@link DataTable.defaults}.
11322 "bSortCellsTop": null,
11325 * Initialisation object that is used for the table
11332 * Destroy callback functions - for plug-ins to attach themselves to the
11333 * destroy so they can clean up markup and events.
11337 "aoDestroyCallback": [],
11341 * Get the number of records in the current record set, before filtering
11344 "fnRecordsTotal": function ()
11346 if ( this.oFeatures.bServerSide ) {
11347 return parseInt(this._iRecordsTotal, 10);
11349 return this.aiDisplayMaster.length;
11354 * Get the number of records in the current record set, after filtering
11357 "fnRecordsDisplay": function ()
11359 if ( this.oFeatures.bServerSide ) {
11360 return parseInt(this._iRecordsDisplay, 10);
11362 return this.aiDisplay.length;
11367 * Set the display end point - aiDisplay index
11369 * @todo Should do away with _iDisplayEnd and calculate it on-the-fly here
11371 "fnDisplayEnd": function ()
11373 if ( this.oFeatures.bServerSide ) {
11374 if ( this.oFeatures.bPaginate === false || this._iDisplayLength == -1 ) {
11375 return this._iDisplayStart+this.aiDisplay.length;
11377 return Math.min( this._iDisplayStart+this._iDisplayLength,
11378 this._iRecordsDisplay );
11381 return this._iDisplayEnd;
11386 * The DataTables object for this table
11393 * Unique identifier for each instance of the DataTables object. If there
11394 * is an ID on the table node, then it takes that value, otherwise an
11395 * incrementing internal counter is used.
11402 * tabindex attribute value that is added to DataTables control elements, allowing
11403 * keyboard navigation of the table and its controls.
11408 * DIV container for the footer scrolling table if scrolling
11410 "nScrollHead": null,
11413 * DIV container for the footer scrolling table if scrolling
11415 "nScrollFoot": null
11419 * Extension object for DataTables that is used to provide all extension options.
11421 * Note that the <i>DataTable.ext</i> object is available through
11422 * <i>jQuery.fn.dataTable.ext</i> where it may be accessed and manipulated. It is
11423 * also aliased to <i>jQuery.fn.dataTableExt</i> for historic reasons.
11425 * @extends DataTable.models.ext
11427 DataTable.ext = $.extend( true, {}, DataTable.models.ext );
11429 $.extend( DataTable.ext.oStdClasses, {
11430 "sTable": "dataTable",
11432 /* Two buttons buttons */
11433 "sPagePrevEnabled": "paginate_enabled_previous",
11434 "sPagePrevDisabled": "paginate_disabled_previous",
11435 "sPageNextEnabled": "paginate_enabled_next",
11436 "sPageNextDisabled": "paginate_disabled_next",
11437 "sPageJUINext": "",
11438 "sPageJUIPrev": "",
11440 /* Full numbers paging buttons */
11441 "sPageButton": "paginate_button",
11442 "sPageButtonActive": "paginate_active",
11443 "sPageButtonStaticDisabled": "paginate_button paginate_button_disabled",
11444 "sPageFirst": "first",
11445 "sPagePrevious": "previous",
11446 "sPageNext": "next",
11447 "sPageLast": "last",
11449 /* Striping classes */
11450 "sStripeOdd": "odd",
11451 "sStripeEven": "even",
11454 "sRowEmpty": "dataTables_empty",
11457 "sWrapper": "dataTables_wrapper",
11458 "sFilter": "dataTables_filter",
11459 "sInfo": "dataTables_info",
11460 "sPaging": "dataTables_paginate paging_", /* Note that the type is postfixed */
11461 "sLength": "dataTables_length",
11462 "sProcessing": "dataTables_processing",
11465 "sSortAsc": "sorting_asc",
11466 "sSortDesc": "sorting_desc",
11467 "sSortable": "sorting", /* Sortable in both directions */
11468 "sSortableAsc": "sorting_asc_disabled",
11469 "sSortableDesc": "sorting_desc_disabled",
11470 "sSortableNone": "sorting_disabled",
11471 "sSortColumn": "sorting_", /* Note that an int is postfixed for the sorting order */
11473 "sSortJUIDesc": "",
11475 "sSortJUIAscAllowed": "",
11476 "sSortJUIDescAllowed": "",
11477 "sSortJUIWrapper": "",
11481 "sScrollWrapper": "dataTables_scroll",
11482 "sScrollHead": "dataTables_scrollHead",
11483 "sScrollHeadInner": "dataTables_scrollHeadInner",
11484 "sScrollBody": "dataTables_scrollBody",
11485 "sScrollFoot": "dataTables_scrollFoot",
11486 "sScrollFootInner": "dataTables_scrollFootInner",
11495 $.extend( DataTable.ext.oJUIClasses, DataTable.ext.oStdClasses, {
11496 /* Two buttons buttons */
11497 "sPagePrevEnabled": "fg-button ui-button ui-state-default ui-corner-left",
11498 "sPagePrevDisabled": "fg-button ui-button ui-state-default ui-corner-left ui-state-disabled",
11499 "sPageNextEnabled": "fg-button ui-button ui-state-default ui-corner-right",
11500 "sPageNextDisabled": "fg-button ui-button ui-state-default ui-corner-right ui-state-disabled",
11501 "sPageJUINext": "ui-icon ui-icon-circle-arrow-e",
11502 "sPageJUIPrev": "ui-icon ui-icon-circle-arrow-w",
11504 /* Full numbers paging buttons */
11505 "sPageButton": "fg-button ui-button ui-state-default",
11506 "sPageButtonActive": "fg-button ui-button ui-state-default ui-state-disabled",
11507 "sPageButtonStaticDisabled": "fg-button ui-button ui-state-default ui-state-disabled",
11508 "sPageFirst": "first ui-corner-tl ui-corner-bl",
11509 "sPageLast": "last ui-corner-tr ui-corner-br",
11512 "sPaging": "dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi "+
11513 "ui-buttonset-multi paging_", /* Note that the type is postfixed */
11516 "sSortAsc": "ui-state-default",
11517 "sSortDesc": "ui-state-default",
11518 "sSortable": "ui-state-default",
11519 "sSortableAsc": "ui-state-default",
11520 "sSortableDesc": "ui-state-default",
11521 "sSortableNone": "ui-state-default",
11522 "sSortJUIAsc": "css_right ui-icon ui-icon-triangle-1-n",
11523 "sSortJUIDesc": "css_right ui-icon ui-icon-triangle-1-s",
11524 "sSortJUI": "css_right ui-icon ui-icon-carat-2-n-s",
11525 "sSortJUIAscAllowed": "css_right ui-icon ui-icon-carat-1-n",
11526 "sSortJUIDescAllowed": "css_right ui-icon ui-icon-carat-1-s",
11527 "sSortJUIWrapper": "DataTables_sort_wrapper",
11528 "sSortIcon": "DataTables_sort_icon",
11531 "sScrollHead": "dataTables_scrollHead ui-state-default",
11532 "sScrollFoot": "dataTables_scrollFoot ui-state-default",
11535 "sFooterTH": "ui-state-default",
11536 "sJUIHeader": "fg-toolbar ui-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix",
11537 "sJUIFooter": "fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix"
11541 * Variable: oPagination
11543 * Scope: jQuery.fn.dataTableExt
11545 $.extend( DataTable.ext.oPagination, {
11547 * Variable: two_button
11548 * Purpose: Standard two button (forward/back) pagination
11549 * Scope: jQuery.fn.dataTableExt.oPagination
11553 * Function: oPagination.two_button.fnInit
11554 * Purpose: Initialise dom elements required for pagination with forward/back buttons only
11556 * Inputs: object:oSettings - dataTables settings object
11557 * node:nPaging - the DIV which contains this pagination control
11558 * function:fnCallbackDraw - draw function which must be called on update
11560 "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
11562 var oLang = oSettings.oLanguage.oPaginate;
11563 var oClasses = oSettings.oClasses;
11564 var fnClickHandler = function ( e ) {
11565 if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) )
11567 fnCallbackDraw( oSettings );
11571 var sAppend = (!oSettings.bJUI) ?
11572 '<a class="'+oSettings.oClasses.sPagePrevDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button">'+oLang.sPrevious+'</a>'+
11573 '<a class="'+oSettings.oClasses.sPageNextDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button">'+oLang.sNext+'</a>'
11575 '<a class="'+oSettings.oClasses.sPagePrevDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button"><span class="'+oSettings.oClasses.sPageJUIPrev+'"></span></a>'+
11576 '<a class="'+oSettings.oClasses.sPageNextDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button"><span class="'+oSettings.oClasses.sPageJUINext+'"></span></a>';
11577 $(nPaging).append( sAppend );
11579 var els = $('a', nPaging);
11580 var nPrevious = els[0],
11583 oSettings.oApi._fnBindAction( nPrevious, {action: "previous"}, fnClickHandler );
11584 oSettings.oApi._fnBindAction( nNext, {action: "next"}, fnClickHandler );
11586 /* ID the first elements only */
11587 if ( !oSettings.aanFeatures.p )
11589 nPaging.id = oSettings.sTableId+'_paginate';
11590 nPrevious.id = oSettings.sTableId+'_previous';
11591 nNext.id = oSettings.sTableId+'_next';
11593 nPrevious.setAttribute('aria-controls', oSettings.sTableId);
11594 nNext.setAttribute('aria-controls', oSettings.sTableId);
11599 * Function: oPagination.two_button.fnUpdate
11600 * Purpose: Update the two button pagination at the end of the draw
11602 * Inputs: object:oSettings - dataTables settings object
11603 * function:fnCallbackDraw - draw function to call on page change
11605 "fnUpdate": function ( oSettings, fnCallbackDraw )
11607 if ( !oSettings.aanFeatures.p )
11612 var oClasses = oSettings.oClasses;
11613 var an = oSettings.aanFeatures.p;
11616 /* Loop over each instance of the pager */
11617 for ( var i=0, iLen=an.length ; i<iLen ; i++ )
11619 nNode = an[i].firstChild;
11622 /* Previous page */
11623 nNode.className = ( oSettings._iDisplayStart === 0 ) ?
11624 oClasses.sPagePrevDisabled : oClasses.sPagePrevEnabled;
11627 nNode = nNode.nextSibling;
11628 nNode.className = ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() ) ?
11629 oClasses.sPageNextDisabled : oClasses.sPageNextEnabled;
11637 * Variable: iFullNumbersShowPages
11638 * Purpose: Change the number of pages which can be seen
11639 * Scope: jQuery.fn.dataTableExt.oPagination
11641 "iFullNumbersShowPages": 5,
11644 * Variable: full_numbers
11645 * Purpose: Full numbers pagination
11646 * Scope: jQuery.fn.dataTableExt.oPagination
11650 * Function: oPagination.full_numbers.fnInit
11651 * Purpose: Initialise dom elements required for pagination with a list of the pages
11653 * Inputs: object:oSettings - dataTables settings object
11654 * node:nPaging - the DIV which contains this pagination control
11655 * function:fnCallbackDraw - draw function which must be called on update
11657 "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
11659 var oLang = oSettings.oLanguage.oPaginate;
11660 var oClasses = oSettings.oClasses;
11661 var fnClickHandler = function ( e ) {
11662 if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) )
11664 fnCallbackDraw( oSettings );
11669 '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPageFirst+'">'+oLang.sFirst+'</a>'+
11670 '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPagePrevious+'">'+oLang.sPrevious+'</a>'+
11672 '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPageNext+'">'+oLang.sNext+'</a>'+
11673 '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPageLast+'">'+oLang.sLast+'</a>'
11675 var els = $('a', nPaging);
11676 var nFirst = els[0],
11681 oSettings.oApi._fnBindAction( nFirst, {action: "first"}, fnClickHandler );
11682 oSettings.oApi._fnBindAction( nPrev, {action: "previous"}, fnClickHandler );
11683 oSettings.oApi._fnBindAction( nNext, {action: "next"}, fnClickHandler );
11684 oSettings.oApi._fnBindAction( nLast, {action: "last"}, fnClickHandler );
11686 /* ID the first elements only */
11687 if ( !oSettings.aanFeatures.p )
11689 nPaging.id = oSettings.sTableId+'_paginate';
11690 nFirst.id =oSettings.sTableId+'_first';
11691 nPrev.id =oSettings.sTableId+'_previous';
11692 nNext.id =oSettings.sTableId+'_next';
11693 nLast.id =oSettings.sTableId+'_last';
11698 * Function: oPagination.full_numbers.fnUpdate
11699 * Purpose: Update the list of page buttons shows
11701 * Inputs: object:oSettings - dataTables settings object
11702 * function:fnCallbackDraw - draw function to call on page change
11704 "fnUpdate": function ( oSettings, fnCallbackDraw )
11706 if ( !oSettings.aanFeatures.p )
11711 var iPageCount = DataTable.ext.oPagination.iFullNumbersShowPages;
11712 var iPageCountHalf = Math.floor(iPageCount / 2);
11713 var iPages = Math.ceil((oSettings.fnRecordsDisplay()) / oSettings._iDisplayLength);
11714 var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1;
11716 var iStartButton, iEndButton, i, iLen;
11717 var oClasses = oSettings.oClasses;
11718 var anButtons, anStatic, nPaginateList, nNode;
11719 var an = oSettings.aanFeatures.p;
11720 var fnBind = function (j) {
11721 oSettings.oApi._fnBindAction( this, {"page": j+iStartButton-1}, function(e) {
11722 /* Use the information in the element to jump to the required page */
11723 oSettings.oApi._fnPageChange( oSettings, e.data.page );
11724 fnCallbackDraw( oSettings );
11725 e.preventDefault();
11729 /* Pages calculation */
11730 if ( oSettings._iDisplayLength === -1 )
11736 else if (iPages < iPageCount)
11739 iEndButton = iPages;
11741 else if (iCurrentPage <= iPageCountHalf)
11744 iEndButton = iPageCount;
11746 else if (iCurrentPage >= (iPages - iPageCountHalf))
11748 iStartButton = iPages - iPageCount + 1;
11749 iEndButton = iPages;
11753 iStartButton = iCurrentPage - Math.ceil(iPageCount / 2) + 1;
11754 iEndButton = iStartButton + iPageCount - 1;
11758 /* Build the dynamic list */
11759 for ( i=iStartButton ; i<=iEndButton ; i++ )
11761 sList += (iCurrentPage !== i) ?
11762 '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+'">'+oSettings.fnFormatNumber(i)+'</a>' :
11763 '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButtonActive+'">'+oSettings.fnFormatNumber(i)+'</a>';
11766 /* Loop over each instance of the pager */
11767 for ( i=0, iLen=an.length ; i<iLen ; i++ )
11770 if ( !nNode.hasChildNodes() )
11775 /* Build up the dynamic list first - html and listeners */
11776 $('span:eq(0)', nNode)
11778 .children('a').each( fnBind );
11780 /* Update the permanent button's classes */
11781 anButtons = nNode.getElementsByTagName('a');
11783 anButtons[0], anButtons[1],
11784 anButtons[anButtons.length-2], anButtons[anButtons.length-1]
11787 $(anStatic).removeClass( oClasses.sPageButton+" "+oClasses.sPageButtonActive+" "+oClasses.sPageButtonStaticDisabled );
11788 $([anStatic[0], anStatic[1]]).addClass(
11789 (iCurrentPage==1) ?
11790 oClasses.sPageButtonStaticDisabled :
11791 oClasses.sPageButton
11793 $([anStatic[2], anStatic[3]]).addClass(
11794 (iPages===0 || iCurrentPage===iPages || oSettings._iDisplayLength===-1) ?
11795 oClasses.sPageButtonStaticDisabled :
11796 oClasses.sPageButton
11803 $.extend( DataTable.ext.oSort, {
11807 "string-pre": function ( a )
11809 if ( typeof a != 'string' ) {
11810 a = (a !== null && a.toString) ? a.toString() : '';
11812 return a.toLowerCase();
11815 "string-asc": function ( x, y )
11817 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
11820 "string-desc": function ( x, y )
11822 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
11827 * html sorting (ignore html tags)
11829 "html-pre": function ( a )
11831 return a.replace( /<.*?>/g, "" ).toLowerCase();
11834 "html-asc": function ( x, y )
11836 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
11839 "html-desc": function ( x, y )
11841 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
11848 "date-pre": function ( a )
11850 var x = Date.parse( a );
11852 if ( isNaN(x) || x==="" )
11854 x = Date.parse( "01/01/1970 00:00:00" );
11859 "date-asc": function ( x, y )
11864 "date-desc": function ( x, y )
11871 * numerical sorting
11873 "numeric-pre": function ( a )
11875 return (a=="-" || a==="") ? 0 : a*1;
11878 "numeric-asc": function ( x, y )
11883 "numeric-desc": function ( x, y )
11890 $.extend( DataTable.ext.aTypes, [
11893 * Purpose: Check to see if a string is numeric
11894 * Returns: string:'numeric' or null
11895 * Inputs: mixed:sText - string to check
11899 /* Allow zero length strings as a number */
11900 if ( typeof sData === 'number' )
11904 else if ( typeof sData !== 'string' )
11909 var sValidFirstChars = "0123456789-";
11910 var sValidChars = "0123456789.";
11912 var bDecimal = false;
11914 /* Check for a valid first char (no period and allow negatives) */
11915 Char = sData.charAt(0);
11916 if (sValidFirstChars.indexOf(Char) == -1)
11921 /* Check all the other characters are valid */
11922 for ( var i=1 ; i<sData.length ; i++ )
11924 Char = sData.charAt(i);
11925 if (sValidChars.indexOf(Char) == -1)
11930 /* Only allowed one decimal place... */
11946 * Purpose: Check to see if a string is actually a formatted date
11947 * Returns: string:'date' or null
11948 * Inputs: string:sText - string to check
11952 var iParse = Date.parse(sData);
11953 if ( (iParse !== null && !isNaN(iParse)) || (typeof sData === 'string' && sData.length === 0) )
11962 * Purpose: Check to see if a string should be treated as an HTML string
11963 * Returns: string:'html' or null
11964 * Inputs: string:sText - string to check
11968 if ( typeof sData === 'string' && sData.indexOf('<') != -1 && sData.indexOf('>') != -1 )
11978 $.fn.DataTable = DataTable;
11979 $.fn.dataTable = DataTable;
11980 $.fn.dataTableSettings = DataTable.settings;
11981 $.fn.dataTableExt = DataTable.ext;
11984 // Information about events fired by DataTables - for documentation.
11986 * Draw event, fired whenever the table is redrawn on the page, at the same point as
11987 * fnDrawCallback. This may be useful for binding events or performing calculations when
11988 * the table is altered at all.
11989 * @name DataTable#draw
11991 * @param {event} e jQuery event object
11992 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
11996 * Filter event, fired when the filtering applied to the table (using the build in global
11997 * global filter, or column filters) is altered.
11998 * @name DataTable#filter
12000 * @param {event} e jQuery event object
12001 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
12005 * Page change event, fired when the paging of the table is altered.
12006 * @name DataTable#page
12008 * @param {event} e jQuery event object
12009 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
12013 * Sort event, fired when the sorting applied to the table is altered.
12014 * @name DataTable#sort
12016 * @param {event} e jQuery event object
12017 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
12021 * DataTables initialisation complete event, fired when the table is fully drawn,
12022 * including Ajax data loaded, if Ajax data is required.
12023 * @name DataTable#init
12025 * @param {event} e jQuery event object
12026 * @param {object} oSettings DataTables settings object
12027 * @param {object} json The JSON object request from the server - only
12028 * present if client-side Ajax sourced data is used</li></ol>
12032 * State save event, fired when the table has changed state a new state save is required.
12033 * This method allows modification of the state saving object prior to actually doing the
12034 * save, including addition or other state properties (for plug-ins) or modification
12035 * of a DataTables core property.
12036 * @name DataTable#stateSaveParams
12038 * @param {event} e jQuery event object
12039 * @param {object} oSettings DataTables settings object
12040 * @param {object} json The state information to be saved
12044 * State load event, fired when the table is loading state from the stored data, but
12045 * prior to the settings object being modified by the saved state - allowing modification
12046 * of the saved state is required or loading of state for a plug-in.
12047 * @name DataTable#stateLoadParams
12049 * @param {event} e jQuery event object
12050 * @param {object} oSettings DataTables settings object
12051 * @param {object} json The saved state information
12055 * State loaded event, fired when state has been loaded from stored data and the settings
12056 * object has been modified by the loaded data.
12057 * @name DataTable#stateLoaded
12059 * @param {event} e jQuery event object
12060 * @param {object} oSettings DataTables settings object
12061 * @param {object} json The saved state information
12065 * Processing event, fired when DataTables is doing some kind of processing (be it,
12066 * sort, filter or anything else). Can be used to indicate to the end user that
12067 * there is something happening, or that something has finished.
12068 * @name DataTable#processing
12070 * @param {event} e jQuery event object
12071 * @param {object} oSettings DataTables settings object
12072 * @param {boolean} bShow Flag for if DataTables is doing processing or not
12076 * Ajax (XHR) event, fired whenever an Ajax request is completed from a request to
12077 * made to the server for new data (note that this trigger is called in fnServerData,
12078 * if you override fnServerData and which to use this event, you need to trigger it in
12079 * you success function).
12080 * @name DataTable#xhr
12082 * @param {event} e jQuery event object
12083 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
12084 * @param {object} json JSON returned from the server
12088 * Destroy event, fired when the DataTable is destroyed by calling fnDestroy or passing
12089 * the bDestroy:true parameter in the initialisation object. This can be used to remove
12090 * bound events, added DOM nodes, etc.
12091 * @name DataTable#destroy
12093 * @param {event} e jQuery event object
12094 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
12098 }(window, document));