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,_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*/
26 (/** @lends <global> */function($, window, document, undefined) {
28 * DataTables is a plug-in for the jQuery Javascript library. It is a
29 * highly flexible tool, based upon the foundations of progressive
30 * enhancement, which will add advanced interaction controls to any
31 * HTML table. For a full list of features please refer to
32 * <a href="http://datatables.net">DataTables.net</a>.
34 * Note that the <i>DataTable</i> object is not a global variable but is
35 * aliased to <i>jQuery.fn.DataTable</i> and <i>jQuery.fn.dataTable</i> through which
39 * @param {object} [oInit={}] Configuration object for DataTables. Options
40 * are defined by {@link DataTable.defaults}
41 * @requires jQuery 1.3+
44 * // Basic initialisation
45 * $(document).ready( function {
46 * $('#example').dataTable();
50 * // Initialisation with configuration options - in this case, disable
51 * // pagination and sorting.
52 * $(document).ready( function {
53 * $('#example').dataTable( {
59 var DataTable = function( oInit )
64 * Add a column to the list used for the table with default values
65 * @param {object} oSettings dataTables settings object
66 * @param {node} nTh The th element for this column
67 * @memberof DataTable#oApi
69 function _fnAddColumn( oSettings, nTh )
71 var oDefaults = DataTable.defaults.columns;
72 var iCol = oSettings.aoColumns.length;
73 var oCol = $.extend( {}, DataTable.models.oColumn, oDefaults, {
74 "sSortingClass": oSettings.oClasses.sSortable,
75 "sSortingClassJUI": oSettings.oClasses.sSortJUI,
76 "nTh": nTh ? nTh : document.createElement('th'),
77 "sTitle": oDefaults.sTitle ? oDefaults.sTitle : nTh ? nTh.innerHTML : '',
78 "aDataSort": oDefaults.aDataSort ? oDefaults.aDataSort : [iCol],
79 "mDataProp": oDefaults.mDataProp ? oDefaults.oDefaults : iCol
81 oSettings.aoColumns.push( oCol );
83 /* Add a column specific filter */
84 if ( oSettings.aoPreSearchCols[ iCol ] === undefined || oSettings.aoPreSearchCols[ iCol ] === null )
86 oSettings.aoPreSearchCols[ iCol ] = $.extend( {}, DataTable.models.oSearch );
90 var oPre = oSettings.aoPreSearchCols[ iCol ];
92 /* Don't require that the user must specify bRegex, bSmart or bCaseInsensitive */
93 if ( oPre.bRegex === undefined )
98 if ( oPre.bSmart === undefined )
103 if ( oPre.bCaseInsensitive === undefined )
105 oPre.bCaseInsensitive = true;
109 /* Use the column options function to initialise classes etc */
110 _fnColumnOptions( oSettings, iCol, null );
115 * Apply options for a column
116 * @param {object} oSettings dataTables settings object
117 * @param {int} iCol column index to consider
118 * @param {object} oOptions object with sType, bVisible and bSearchable
119 * @memberof DataTable#oApi
121 function _fnColumnOptions( oSettings, iCol, oOptions )
123 var oCol = oSettings.aoColumns[ iCol ];
125 /* User specified column options */
126 if ( oOptions !== undefined && oOptions !== null )
128 if ( oOptions.sType !== undefined )
130 oCol.sType = oOptions.sType;
131 oCol._bAutoType = false;
134 $.extend( oCol, oOptions );
135 _fnMap( oCol, oOptions, "sWidth", "sWidthOrig" );
137 /* iDataSort to be applied (backwards compatibility), but aDataSort will take
138 * priority if defined
140 if ( oOptions.iDataSort !== undefined )
142 oCol.aDataSort = [ oOptions.iDataSort ];
144 _fnMap( oCol, oOptions, "aDataSort" );
147 /* Cache the data get and set functions for speed */
148 oCol.fnGetData = _fnGetObjectDataFn( oCol.mDataProp );
149 oCol.fnSetData = _fnSetObjectDataFn( oCol.mDataProp );
151 /* Feature sorting overrides column specific when off */
152 if ( !oSettings.oFeatures.bSort )
154 oCol.bSortable = false;
157 /* Check that the class assignment is correct for sorting */
158 if ( !oCol.bSortable ||
159 ($.inArray('asc', oCol.asSorting) == -1 && $.inArray('desc', oCol.asSorting) == -1) )
161 oCol.sSortingClass = oSettings.oClasses.sSortableNone;
162 oCol.sSortingClassJUI = "";
164 else if ( oCol.bSortable ||
165 ($.inArray('asc', oCol.asSorting) == -1 && $.inArray('desc', oCol.asSorting) == -1) )
167 oCol.sSortingClass = oSettings.oClasses.sSortable;
168 oCol.sSortingClassJUI = oSettings.oClasses.sSortJUI;
170 else if ( $.inArray('asc', oCol.asSorting) != -1 && $.inArray('desc', oCol.asSorting) == -1 )
172 oCol.sSortingClass = oSettings.oClasses.sSortableAsc;
173 oCol.sSortingClassJUI = oSettings.oClasses.sSortJUIAscAllowed;
175 else if ( $.inArray('asc', oCol.asSorting) == -1 && $.inArray('desc', oCol.asSorting) != -1 )
177 oCol.sSortingClass = oSettings.oClasses.sSortableDesc;
178 oCol.sSortingClassJUI = oSettings.oClasses.sSortJUIDescAllowed;
184 * Adjust the table column widths for new data. Note: you would probably want to
185 * do a redraw after calling this function!
186 * @param {object} oSettings dataTables settings object
187 * @memberof DataTable#oApi
189 function _fnAdjustColumnSizing ( oSettings )
191 /* Not interested in doing column width calculation if autowidth is disabled */
192 if ( oSettings.oFeatures.bAutoWidth === false )
197 _fnCalculateColumnWidths( oSettings );
198 for ( var i=0 , iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
200 oSettings.aoColumns[i].nTh.style.width = oSettings.aoColumns[i].sWidth;
206 * Covert the index of a visible column to the index in the data array (take account
208 * @param {object} oSettings dataTables settings object
209 * @param {int} iMatch Visible column index to lookup
210 * @returns {int} i the data index
211 * @memberof DataTable#oApi
213 function _fnVisibleToColumnIndex( oSettings, iMatch )
217 for ( var i=0 ; i<oSettings.aoColumns.length ; i++ )
219 if ( oSettings.aoColumns[i].bVisible === true )
224 if ( iColumn == iMatch )
235 * Covert the index of an index in the data array and convert it to the visible
236 * column index (take account of hidden columns)
237 * @param {int} iMatch Column index to lookup
238 * @param {object} oSettings dataTables settings object
239 * @returns {int} i the data index
240 * @memberof DataTable#oApi
242 function _fnColumnIndexToVisible( oSettings, iMatch )
245 for ( var i=0 ; i<oSettings.aoColumns.length ; i++ )
247 if ( oSettings.aoColumns[i].bVisible === true )
254 return oSettings.aoColumns[i].bVisible === true ? iVisible : null;
263 * Get the number of visible columns
264 * @returns {int} i the number of visible columns
265 * @param {object} oS dataTables settings object
266 * @memberof DataTable#oApi
268 function _fnVisbleColumns( oS )
271 for ( var i=0 ; i<oS.aoColumns.length ; i++ )
273 if ( oS.aoColumns[i].bVisible === true )
283 * Get the sort type based on an input string
284 * @param {string} sData data we wish to know the type of
285 * @returns {string} type (defaults to 'string' if no type can be detected)
286 * @memberof DataTable#oApi
288 function _fnDetectType( sData )
290 var aTypes = DataTable.ext.aTypes;
291 var iLen = aTypes.length;
293 for ( var i=0 ; i<iLen ; i++ )
295 var sType = aTypes[i]( sData );
296 if ( sType !== null )
307 * Figure out how to reorder a display list
308 * @param {object} oSettings dataTables settings object
309 * @returns array {int} aiReturn index list for reordering
310 * @memberof DataTable#oApi
312 function _fnReOrderIndex ( oSettings, sColumns )
314 var aColumns = sColumns.split(',');
317 for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
319 for ( var j=0 ; j<iLen ; j++ )
321 if ( oSettings.aoColumns[i].sName == aColumns[j] )
334 * Get the column ordering that DataTables expects
335 * @param {object} oSettings dataTables settings object
336 * @returns {string} comma separated list of names
337 * @memberof DataTable#oApi
339 function _fnColumnOrdering ( oSettings )
342 for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
344 sNames += oSettings.aoColumns[i].sName+',';
346 if ( sNames.length == iLen )
350 return sNames.slice(0, -1);
355 * Take the column definitions and static columns arrays and calculate how
356 * they relate to column indexes. The callback function will then apply the
357 * definition found for a column to a suitable configuration object.
358 * @param {object} oSettings dataTables settings object
359 * @param {array} aoColDefs The aoColumnDefs array that is to be applied
360 * @param {array} aoCols The aoColumns array that defines columns individually
361 * @param {function} fn Callback function - takes two parameters, the calculated
362 * column index and the definition for that column.
363 * @memberof DataTable#oApi
365 function _fnApplyColumnDefs( oSettings, aoColDefs, aoCols, fn )
367 var i, iLen, j, jLen, k, kLen;
369 // Column definitions with aTargets
372 /* Loop over the definitions array - loop in reverse so first instance has priority */
373 for ( i=aoColDefs.length-1 ; i>=0 ; i-- )
375 /* Each definition can target multiple columns, as it is an array */
376 var aTargets = aoColDefs[i].aTargets;
377 if ( !$.isArray( aTargets ) )
379 _fnLog( oSettings, 1, 'aTargets must be an array of targets, not a '+(typeof aTargets) );
382 for ( j=0, jLen=aTargets.length ; j<jLen ; j++ )
384 if ( typeof aTargets[j] === 'number' && aTargets[j] >= 0 )
386 /* Add columns that we don't yet know about */
387 while( oSettings.aoColumns.length <= aTargets[j] )
389 _fnAddColumn( oSettings );
392 /* Integer, basic index */
393 fn( aTargets[j], aoColDefs[i] );
395 else if ( typeof aTargets[j] === 'number' && aTargets[j] < 0 )
397 /* Negative integer, right to left column counting */
398 fn( oSettings.aoColumns.length+aTargets[j], aoColDefs[i] );
400 else if ( typeof aTargets[j] === 'string' )
402 /* Class name matching on TH element */
403 for ( k=0, kLen=oSettings.aoColumns.length ; k<kLen ; k++ )
405 if ( aTargets[j] == "_all" ||
406 $(oSettings.aoColumns[k].nTh).hasClass( aTargets[j] ) )
408 fn( k, aoColDefs[i] );
416 // Statically defined columns array
419 for ( i=0, iLen=aoCols.length ; i<iLen ; i++ )
429 * Add a data array to the table, creating DOM node etc. This is the parallel to
430 * _fnGatherData, but for adding rows from a Javascript source, rather than a
432 * @param {object} oSettings dataTables settings object
433 * @param {array} aData data array to be added
434 * @returns {int} >=0 if successful (index of new aoData entry), -1 if failed
435 * @memberof DataTable#oApi
437 function _fnAddData ( oSettings, aDataSupplied )
441 /* Take an independent copy of the data source so we can bash it about as we wish */
442 var aDataIn = ($.isArray(aDataSupplied)) ?
443 aDataSupplied.slice() :
444 $.extend( true, {}, aDataSupplied );
446 /* Create the object for storing information about this new row */
447 var iRow = oSettings.aoData.length;
448 var oData = $.extend( true, {}, DataTable.models.oRow, {
451 oSettings.aoData.push( oData );
453 /* Create the cells */
455 for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
457 oCol = oSettings.aoColumns[i];
459 /* Use rendered data for filtering/sorting */
460 if ( typeof oCol.fnRender === 'function' && oCol.bUseRendered && oCol.mDataProp !== null )
462 _fnSetCellData( oSettings, iRow, i, _fnRender(oSettings, iRow, i) );
465 /* See if we should auto-detect the column type */
466 if ( oCol._bAutoType && oCol.sType != 'string' )
468 /* Attempt to auto detect the type - same as _fnGatherData() */
469 var sVarType = _fnGetCellData( oSettings, iRow, i, 'type' );
470 if ( sVarType !== null && sVarType !== '' )
472 sThisType = _fnDetectType( sVarType );
473 if ( oCol.sType === null )
475 oCol.sType = sThisType;
477 else if ( oCol.sType != sThisType && oCol.sType != "html" )
479 /* String is always the 'fallback' option */
480 oCol.sType = 'string';
486 /* Add to the display array */
487 oSettings.aiDisplayMaster.push( iRow );
489 /* Create the DOM imformation */
490 if ( !oSettings.oFeatures.bDeferRender )
492 _fnCreateTr( oSettings, iRow );
500 * Read in the data from the target table from the DOM
501 * @param {object} oSettings dataTables settings object
502 * @memberof DataTable#oApi
504 function _fnGatherData( oSettings )
506 var iLoop, i, iLen, j, jLen, jInner,
507 nTds, nTrs, nTd, aLocalData, iThisIndex,
508 iRow, iRows, iColumn, iColumns, sNodeName,
512 * Process by row first
513 * Add the data object for the whole table - storing the tr node. Note - no point in getting
514 * DOM based data if we are going to go and replace it with Ajax source data.
516 if ( oSettings.bDeferLoading || oSettings.sAjaxSource === null )
518 nTrs = oSettings.nTBody.childNodes;
519 for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
521 if ( nTrs[i].nodeName.toUpperCase() == "TR" )
523 iThisIndex = oSettings.aoData.length;
524 nTrs[i]._DT_RowIndex = iThisIndex;
525 oSettings.aoData.push( $.extend( true, {}, DataTable.models.oRow, {
529 oSettings.aiDisplayMaster.push( iThisIndex );
530 nTds = nTrs[i].childNodes;
533 for ( j=0, jLen=nTds.length ; j<jLen ; j++ )
535 sNodeName = nTds[j].nodeName.toUpperCase();
536 if ( sNodeName == "TD" || sNodeName == "TH" )
538 _fnSetCellData( oSettings, iThisIndex, jInner, $.trim(nTds[j].innerHTML) );
546 /* Gather in the TD elements of the Table - note that this is basically the same as
547 * fnGetTdNodes, but that function takes account of hidden columns, which we haven't yet
550 nTrs = _fnGetTrNodes( oSettings );
552 for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
554 for ( j=0, jLen=nTrs[i].childNodes.length ; j<jLen ; j++ )
556 nTd = nTrs[i].childNodes[j];
557 sNodeName = nTd.nodeName.toUpperCase();
558 if ( sNodeName == "TD" || sNodeName == "TH" )
565 /* Now process by column */
566 for ( iColumn=0, iColumns=oSettings.aoColumns.length ; iColumn<iColumns ; iColumn++ )
568 oCol = oSettings.aoColumns[iColumn];
570 /* Get the title of the column - unless there is a user set one */
571 if ( oCol.sTitle === null )
573 oCol.sTitle = oCol.nTh.innerHTML;
577 bAutoType = oCol._bAutoType,
578 bRender = typeof oCol.fnRender === 'function',
579 bClass = oCol.sClass !== null,
580 bVisible = oCol.bVisible,
581 nCell, sThisType, sRendered, sValType;
583 /* A single loop to rule them all (and be more efficient) */
584 if ( bAutoType || bRender || bClass || !bVisible )
586 for ( iRow=0, iRows=oSettings.aoData.length ; iRow<iRows ; iRow++ )
588 oData = oSettings.aoData[iRow];
589 nCell = nTds[ (iRow*iColumns) + iColumn ];
592 if ( bAutoType && oCol.sType != 'string' )
594 sValType = _fnGetCellData( oSettings, iRow, iColumn, 'type' );
595 if ( sValType !== '' )
597 sThisType = _fnDetectType( sValType );
598 if ( oCol.sType === null )
600 oCol.sType = sThisType;
602 else if ( oCol.sType != sThisType &&
603 oCol.sType != "html" )
605 /* String is always the 'fallback' option */
606 oCol.sType = 'string';
611 if ( typeof oCol.mDataProp === 'function' )
613 nCell.innerHTML = _fnGetCellData( oSettings, iRow, iColumn, 'display' );
619 sRendered = _fnRender( oSettings, iRow, iColumn );
620 nCell.innerHTML = sRendered;
621 if ( oCol.bUseRendered )
623 /* Use the rendered data for filtering/sorting */
624 _fnSetCellData( oSettings, iRow, iColumn, sRendered );
631 nCell.className += ' '+oCol.sClass;
634 /* Column visability */
637 oData._anHidden[iColumn] = nCell;
638 nCell.parentNode.removeChild( nCell );
642 oData._anHidden[iColumn] = null;
645 if ( oCol.fnCreatedCell )
647 oCol.fnCreatedCell.call( oSettings.oInstance,
648 nCell, _fnGetCellData( oSettings, iRow, iColumn, 'display' ), oData._aData, iRow, iColumn
655 /* Row created callbacks */
656 if ( oSettings.aoRowCreatedCallback.length !== 0 )
658 for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
660 oData = oSettings.aoData[i];
661 _fnCallbackFire( oSettings, 'aoRowCreatedCallback', null, [oData.nTr, oData._aData, i] );
668 * Take a TR element and convert it to an index in aoData
669 * @param {object} oSettings dataTables settings object
670 * @param {node} n the TR element to find
671 * @returns {int} index if the node is found, null if not
672 * @memberof DataTable#oApi
674 function _fnNodeToDataIndex( oSettings, n )
676 return (n._DT_RowIndex!==undefined) ? n._DT_RowIndex : null;
681 * Take a TD element and convert it into a column data index (not the visible index)
682 * @param {object} oSettings dataTables settings object
683 * @param {int} iRow The row number the TD/TH can be found in
684 * @param {node} n The TD/TH element to find
685 * @returns {int} index if the node is found, -1 if not
686 * @memberof DataTable#oApi
688 function _fnNodeToColumnIndex( oSettings, iRow, n )
690 var anCells = _fnGetTdNodes( oSettings, iRow );
692 for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
694 if ( anCells[i] === n )
704 * Get an array of data for a given row from the internal data cache
705 * @param {object} oSettings dataTables settings object
706 * @param {int} iRow aoData row id
707 * @param {string} sSpecific data get type ('type' 'filter' 'sort')
708 * @returns {array} Data array
709 * @memberof DataTable#oApi
711 function _fnGetRowData( oSettings, iRow, sSpecific )
714 for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
716 out.push( _fnGetCellData( oSettings, iRow, i, sSpecific ) );
723 * Get the data for a given cell from the internal cache, taking into account data mapping
724 * @param {object} oSettings dataTables settings object
725 * @param {int} iRow aoData row id
726 * @param {int} iCol Column index
727 * @param {string} sSpecific data get type ('display', 'type' 'filter' 'sort')
728 * @returns {*} Cell data
729 * @memberof DataTable#oApi
731 function _fnGetCellData( oSettings, iRow, iCol, sSpecific )
734 var oCol = oSettings.aoColumns[iCol];
735 var oData = oSettings.aoData[iRow]._aData;
737 if ( (sData=oCol.fnGetData( oData, sSpecific )) === undefined )
739 if ( oSettings.iDrawError != oSettings.iDraw && oCol.sDefaultContent === null )
741 _fnLog( oSettings, 0, "Requested unknown parameter '"+oCol.mDataProp+
742 "' from the data source for row "+iRow );
743 oSettings.iDrawError = oSettings.iDraw;
745 return oCol.sDefaultContent;
748 /* When the data source is null, we can use default column data */
749 if ( sData === null && oCol.sDefaultContent !== null )
751 sData = oCol.sDefaultContent;
753 else if ( typeof sData === 'function' )
755 /* If the data source is a function, then we run it and use the return */
759 if ( sSpecific == 'display' && sData === null )
768 * Set the value for a specific cell, into the internal data cache
769 * @param {object} oSettings dataTables settings object
770 * @param {int} iRow aoData row id
771 * @param {int} iCol Column index
772 * @param {*} val Value to set
773 * @memberof DataTable#oApi
775 function _fnSetCellData( oSettings, iRow, iCol, val )
777 var oCol = oSettings.aoColumns[iCol];
778 var oData = oSettings.aoData[iRow]._aData;
780 oCol.fnSetData( oData, val );
785 * Return a function that can be used to get data from a source object, taking
786 * into account the ability to use nested objects as a source
787 * @param {string|int|function} mSource The data source for the object
788 * @returns {function} Data get function
789 * @memberof DataTable#oApi
791 function _fnGetObjectDataFn( mSource )
793 if ( mSource === null )
795 /* Give an empty string for rendering / sorting etc */
796 return function (data, type) {
800 else if ( typeof mSource === 'function' )
802 return function (data, type) {
803 return mSource( data, type );
806 else if ( typeof mSource === 'string' && mSource.indexOf('.') != -1 )
808 /* If there is a . in the source string then the data source is in a
809 * nested object so we loop over the data for each level to get the next
810 * level down. On each loop we test for undefined, and if found immediatly
811 * return. This allows entire objects to be missing and sDefaultContent to
812 * be used if defined, rather than throwing an error
814 var a = mSource.split('.');
815 return function (data, type) {
816 for ( var i=0, iLen=a.length ; i<iLen ; i++ )
819 if ( data === undefined )
829 /* Array or flat object mapping */
830 return function (data, type) {
831 return data[mSource];
838 * Return a function that can be used to set data from a source object, taking
839 * into account the ability to use nested objects as a source
840 * @param {string|int|function} mSource The data source for the object
841 * @returns {function} Data set function
842 * @memberof DataTable#oApi
844 function _fnSetObjectDataFn( mSource )
846 if ( mSource === null )
848 /* Nothing to do when the data source is null */
849 return function (data, val) {};
851 else if ( typeof mSource === 'function' )
853 return function (data, val) {
854 mSource( data, 'set', val );
857 else if ( typeof mSource === 'string' && mSource.indexOf('.') != -1 )
859 /* Like the get, we need to get data from a nested object. */
860 var a = mSource.split('.');
861 return function (data, val) {
862 for ( var i=0, iLen=a.length-1 ; i<iLen ; i++ )
866 data[ a[a.length-1] ] = val;
871 /* Array or flat object mapping */
872 return function (data, val) {
880 * Return an array with the full table data
881 * @param {object} oSettings dataTables settings object
882 * @returns array {array} aData Master data array
883 * @memberof DataTable#oApi
885 function _fnGetDataMaster ( oSettings )
888 var iLen = oSettings.aoData.length;
889 for ( var i=0 ; i<iLen; i++ )
891 aData.push( oSettings.aoData[i]._aData );
899 * @param {object} oSettings dataTables settings object
900 * @memberof DataTable#oApi
902 function _fnClearTable( oSettings )
904 oSettings.aoData.splice( 0, oSettings.aoData.length );
905 oSettings.aiDisplayMaster.splice( 0, oSettings.aiDisplayMaster.length );
906 oSettings.aiDisplay.splice( 0, oSettings.aiDisplay.length );
907 _fnCalculateEnd( oSettings );
912 * Take an array of integers (index array) and remove a target integer (value - not
914 * @param {array} a Index array to target
915 * @param {int} iTarget value to find
916 * @memberof DataTable#oApi
918 function _fnDeleteIndex( a, iTarget )
920 var iTargetIndex = -1;
922 for ( var i=0, iLen=a.length ; i<iLen ; i++ )
924 if ( a[i] == iTarget )
928 else if ( a[i] > iTarget )
934 if ( iTargetIndex != -1 )
936 a.splice( iTargetIndex, 1 );
942 * Call the developer defined fnRender function for a given cell (row/column) with
943 * the required parameters and return the result.
944 * @param {object} oSettings dataTables settings object
945 * @param {int} iRow aoData index for the row
946 * @param {int} iCol aoColumns index for the column
947 * @returns {*} Return of the developer's fnRender function
948 * @memberof DataTable#oApi
950 function _fnRender( oSettings, iRow, iCol )
952 var oCol = oSettings.aoColumns[iCol];
954 return oCol.fnRender( {
957 "oSettings": oSettings,
958 "aData": oSettings.aoData[iRow]._aData,
959 "mDataProp": oCol.mDataProp
960 }, _fnGetCellData(oSettings, iRow, iCol, 'display') );
965 * Create a new TR element (and it's TD children) for a row
966 * @param {object} oSettings dataTables settings object
967 * @param {int} iRow Row to consider
968 * @memberof DataTable#oApi
970 function _fnCreateTr ( oSettings, iRow )
972 var oData = oSettings.aoData[iRow];
975 if ( oData.nTr === null )
977 oData.nTr = document.createElement('tr');
979 /* Use a private property on the node to allow reserve mapping from the node
980 * to the aoData array for fast look up
982 oData.nTr._DT_RowIndex = iRow;
984 /* Special parameters can be given by the data source to be used on the row */
985 if ( oData._aData.DT_RowId )
987 oData.nTr.id = oData._aData.DT_RowId;
990 if ( oData._aData.DT_RowClass )
992 $(oData.nTr).addClass( oData._aData.DT_RowClass );
995 /* Process each column */
996 for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
998 var oCol = oSettings.aoColumns[i];
999 nTd = document.createElement('td');
1001 /* Render if needed - if bUseRendered is true then we already have the rendered
1002 * value in the data source - so can just use that
1004 nTd.innerHTML = (typeof oCol.fnRender === 'function' && (!oCol.bUseRendered || oCol.mDataProp === null)) ?
1005 _fnRender( oSettings, iRow, i ) :
1006 _fnGetCellData( oSettings, iRow, i, 'display' );
1008 /* Add user defined class */
1009 if ( oCol.sClass !== null )
1011 nTd.className = oCol.sClass;
1014 if ( oCol.bVisible )
1016 oData.nTr.appendChild( nTd );
1017 oData._anHidden[i] = null;
1021 oData._anHidden[i] = nTd;
1024 if ( oCol.fnCreatedCell )
1026 oCol.fnCreatedCell.call( oSettings.oInstance,
1027 nTd, _fnGetCellData( oSettings, iRow, i, 'display' ), oData._aData, iRow, i
1032 _fnCallbackFire( oSettings, 'aoRowCreatedCallback', null, [oData.nTr, oData._aData, iRow] );
1038 * Create the HTML header for the table
1039 * @param {object} oSettings dataTables settings object
1040 * @memberof DataTable#oApi
1042 function _fnBuildHead( oSettings )
1044 var i, nTh, iLen, j, jLen;
1045 var iThs = oSettings.nTHead.getElementsByTagName('th').length;
1049 /* If there is a header in place - then use it - otherwise it's going to get nuked... */
1052 /* We've got a thead from the DOM, so remove hidden columns and apply width to vis cols */
1053 for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
1055 nTh = oSettings.aoColumns[i].nTh;
1056 nTh.setAttribute('role', 'columnheader');
1057 if ( oSettings.aoColumns[i].bSortable )
1059 nTh.setAttribute('tabindex', oSettings.iTabIndex);
1060 nTh.setAttribute('aria-controls', oSettings.sTableId);
1063 if ( oSettings.aoColumns[i].sClass !== null )
1065 $(nTh).addClass( oSettings.aoColumns[i].sClass );
1068 /* Set the title of the column if it is user defined (not what was auto detected) */
1069 if ( oSettings.aoColumns[i].sTitle != nTh.innerHTML )
1071 nTh.innerHTML = oSettings.aoColumns[i].sTitle;
1077 /* We don't have a header in the DOM - so we are going to have to create one */
1078 var nTr = document.createElement( "tr" );
1080 for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
1082 nTh = oSettings.aoColumns[i].nTh;
1083 nTh.innerHTML = oSettings.aoColumns[i].sTitle;
1084 nTh.setAttribute('tabindex', '0');
1086 if ( oSettings.aoColumns[i].sClass !== null )
1088 $(nTh).addClass( oSettings.aoColumns[i].sClass );
1091 nTr.appendChild( nTh );
1093 $(oSettings.nTHead).html( '' )[0].appendChild( nTr );
1094 _fnDetectHeader( oSettings.aoHeader, oSettings.nTHead );
1097 /* ARIA role for the rows */
1098 $(oSettings.nTHead).children('tr').attr('role', 'row');
1100 /* Add the extra markup needed by jQuery UI's themes */
1101 if ( oSettings.bJUI )
1103 for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
1105 nTh = oSettings.aoColumns[i].nTh;
1107 var nDiv = document.createElement('div');
1108 nDiv.className = oSettings.oClasses.sSortJUIWrapper;
1109 $(nTh).contents().appendTo(nDiv);
1111 var nSpan = document.createElement('span');
1112 nSpan.className = oSettings.oClasses.sSortIcon;
1113 nDiv.appendChild( nSpan );
1114 nTh.appendChild( nDiv );
1118 if ( oSettings.oFeatures.bSort )
1120 for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
1122 if ( oSettings.aoColumns[i].bSortable !== false )
1124 _fnSortAttachListener( oSettings, oSettings.aoColumns[i].nTh, i );
1128 $(oSettings.aoColumns[i].nTh).addClass( oSettings.oClasses.sSortableNone );
1133 /* Deal with the footer - add classes if required */
1134 if ( oSettings.oClasses.sFooterTH !== "" )
1136 $(oSettings.nTFoot).children('tr').children('th').addClass( oSettings.oClasses.sFooterTH );
1139 /* Cache the footer elements */
1140 if ( oSettings.nTFoot !== null )
1142 var anCells = _fnGetUniqueThs( oSettings, null, oSettings.aoFooter );
1143 for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
1147 oSettings.aoColumns[i].nTf = anCells[i];
1148 if ( oSettings.aoColumns[i].sClass )
1150 $(anCells[i]).addClass( oSettings.aoColumns[i].sClass );
1159 * Draw the header (or footer) element based on the column visibility states. The
1160 * methodology here is to use the layout array from _fnDetectHeader, modified for
1161 * the instantaneous column visibility, to construct the new layout. The grid is
1162 * traversed over cell at a time in a rows x columns grid fashion, although each
1163 * cell insert can cover multiple elements in the grid - which is tracks using the
1164 * aApplied array. Cell inserts in the grid will only occur where there isn't
1165 * already a cell in that position.
1166 * @param {object} oSettings dataTables settings object
1167 * @param array {objects} aoSource Layout array from _fnDetectHeader
1168 * @param {boolean} [bIncludeHidden=false] If true then include the hidden columns in the calc,
1169 * @memberof DataTable#oApi
1171 function _fnDrawHead( oSettings, aoSource, bIncludeHidden )
1173 var i, iLen, j, jLen, k, kLen, n, nLocalTr;
1176 var iColumns = oSettings.aoColumns.length;
1177 var iRowspan, iColspan;
1179 if ( bIncludeHidden === undefined )
1181 bIncludeHidden = false;
1184 /* Make a copy of the master layout array, but without the visible columns in it */
1185 for ( i=0, iLen=aoSource.length ; i<iLen ; i++ )
1187 aoLocal[i] = aoSource[i].slice();
1188 aoLocal[i].nTr = aoSource[i].nTr;
1190 /* Remove any columns which are currently hidden */
1191 for ( j=iColumns-1 ; j>=0 ; j-- )
1193 if ( !oSettings.aoColumns[j].bVisible && !bIncludeHidden )
1195 aoLocal[i].splice( j, 1 );
1199 /* Prep the applied array - it needs an element for each row */
1200 aApplied.push( [] );
1203 for ( i=0, iLen=aoLocal.length ; i<iLen ; i++ )
1205 nLocalTr = aoLocal[i].nTr;
1207 /* All cells are going to be replaced, so empty out the row */
1210 while( (n = nLocalTr.firstChild) )
1212 nLocalTr.removeChild( n );
1216 for ( j=0, jLen=aoLocal[i].length ; j<jLen ; j++ )
1221 /* Check to see if there is already a cell (row/colspan) covering our target
1222 * insert point. If there is, then there is nothing to do.
1224 if ( aApplied[i][j] === undefined )
1226 nLocalTr.appendChild( aoLocal[i][j].cell );
1229 /* Expand the cell to cover as many rows as needed */
1230 while ( aoLocal[i+iRowspan] !== undefined &&
1231 aoLocal[i][j].cell == aoLocal[i+iRowspan][j].cell )
1233 aApplied[i+iRowspan][j] = 1;
1237 /* Expand the cell to cover as many columns as needed */
1238 while ( aoLocal[i][j+iColspan] !== undefined &&
1239 aoLocal[i][j].cell == aoLocal[i][j+iColspan].cell )
1241 /* Must update the applied array over the rows for the columns */
1242 for ( k=0 ; k<iRowspan ; k++ )
1244 aApplied[i+k][j+iColspan] = 1;
1249 /* Do the actual expansion in the DOM */
1250 aoLocal[i][j].cell.rowSpan = iRowspan;
1251 aoLocal[i][j].cell.colSpan = iColspan;
1259 * Insert the required TR nodes into the table for display
1260 * @param {object} oSettings dataTables settings object
1261 * @memberof DataTable#oApi
1263 function _fnDraw( oSettings )
1268 var iStripes = oSettings.asStripeClasses.length;
1269 var iOpenRows = oSettings.aoOpenRows.length;
1271 /* Provide a pre-callback function which can be used to cancel the draw is false is returned */
1272 var aPreDraw = _fnCallbackFire( oSettings, 'aoPreDrawCallback', 'preDraw', [oSettings] );
1273 if ( $.inArray( false, aPreDraw ) !== -1 )
1278 oSettings.bDrawing = true;
1280 /* Check and see if we have an initial draw position from state saving */
1281 if ( oSettings.iInitDisplayStart !== undefined && oSettings.iInitDisplayStart != -1 )
1283 if ( oSettings.oFeatures.bServerSide )
1285 oSettings._iDisplayStart = oSettings.iInitDisplayStart;
1289 oSettings._iDisplayStart = (oSettings.iInitDisplayStart >= oSettings.fnRecordsDisplay()) ?
1290 0 : oSettings.iInitDisplayStart;
1292 oSettings.iInitDisplayStart = -1;
1293 _fnCalculateEnd( oSettings );
1296 /* Server-side processing draw intercept */
1297 if ( oSettings.bDeferLoading )
1299 oSettings.bDeferLoading = false;
1302 else if ( !oSettings.oFeatures.bServerSide )
1306 else if ( !oSettings.bDestroying && !_fnAjaxUpdate( oSettings ) )
1311 if ( oSettings.aiDisplay.length !== 0 )
1313 var iStart = oSettings._iDisplayStart;
1314 var iEnd = oSettings._iDisplayEnd;
1316 if ( oSettings.oFeatures.bServerSide )
1319 iEnd = oSettings.aoData.length;
1322 for ( var j=iStart ; j<iEnd ; j++ )
1324 var aoData = oSettings.aoData[ oSettings.aiDisplay[j] ];
1325 if ( aoData.nTr === null )
1327 _fnCreateTr( oSettings, oSettings.aiDisplay[j] );
1330 var nRow = aoData.nTr;
1332 /* Remove the old striping classes and then add the new one */
1333 if ( iStripes !== 0 )
1335 var sStripe = oSettings.asStripeClasses[ iRowCount % iStripes ];
1336 if ( aoData._sRowStripe != sStripe )
1338 $(nRow).removeClass( aoData._sRowStripe ).addClass( sStripe );
1339 aoData._sRowStripe = sStripe;
1343 /* Row callback functions - might want to manipule the row */
1344 _fnCallbackFire( oSettings, 'aoRowCallback', null,
1345 [nRow, oSettings.aoData[ oSettings.aiDisplay[j] ]._aData, iRowCount, j] );
1347 anRows.push( nRow );
1350 /* If there is an open row - and it is attached to this parent - attach it on redraw */
1351 if ( iOpenRows !== 0 )
1353 for ( var k=0 ; k<iOpenRows ; k++ )
1355 if ( nRow == oSettings.aoOpenRows[k].nParent )
1357 anRows.push( oSettings.aoOpenRows[k].nTr );
1366 /* Table is empty - create a row with an empty message in it */
1367 anRows[ 0 ] = document.createElement( 'tr' );
1369 if ( oSettings.asStripeClasses[0] )
1371 anRows[ 0 ].className = oSettings.asStripeClasses[0];
1374 var sZero = oSettings.oLanguage.sZeroRecords.replace(
1375 '_MAX_', oSettings.fnFormatNumber(oSettings.fnRecordsTotal()) );
1376 if ( oSettings.iDraw == 1 && oSettings.sAjaxSource !== null && !oSettings.oFeatures.bServerSide )
1378 sZero = oSettings.oLanguage.sLoadingRecords;
1380 else if ( oSettings.oLanguage.sEmptyTable && oSettings.fnRecordsTotal() === 0 )
1382 sZero = oSettings.oLanguage.sEmptyTable;
1385 var nTd = document.createElement( 'td' );
1386 nTd.setAttribute( 'valign', "top" );
1387 nTd.colSpan = _fnVisbleColumns( oSettings );
1388 nTd.className = oSettings.oClasses.sRowEmpty;
1389 nTd.innerHTML = sZero;
1391 anRows[ iRowCount ].appendChild( nTd );
1394 /* Header and footer callbacks */
1395 _fnCallbackFire( oSettings, 'aoHeaderCallback', 'header', [ $(oSettings.nTHead).children('tr')[0],
1396 _fnGetDataMaster( oSettings ), oSettings._iDisplayStart, oSettings.fnDisplayEnd(), oSettings.aiDisplay ] );
1398 _fnCallbackFire( oSettings, 'aoFooterCallback', 'footer', [ $(oSettings.nTFoot).children('tr')[0],
1399 _fnGetDataMaster( oSettings ), oSettings._iDisplayStart, oSettings.fnDisplayEnd(), oSettings.aiDisplay ] );
1402 * Need to remove any old row from the display - note we can't just empty the tbody using
1403 * $().html('') since this will unbind the jQuery event handlers (even although the node
1404 * still exists!) - equally we can't use innerHTML, since IE throws an exception.
1407 nAddFrag = document.createDocumentFragment(),
1408 nRemoveFrag = document.createDocumentFragment(),
1411 if ( oSettings.nTBody )
1413 nBodyPar = oSettings.nTBody.parentNode;
1414 nRemoveFrag.appendChild( oSettings.nTBody );
1416 /* When doing infinite scrolling, only remove child rows when sorting, filtering or start
1417 * up. When not infinite scroll, always do it.
1419 if ( !oSettings.oScroll.bInfinite || !oSettings._bInitComplete ||
1420 oSettings.bSorted || oSettings.bFiltered )
1422 while( (n = oSettings.nTBody.firstChild) )
1424 oSettings.nTBody.removeChild( n );
1428 /* Put the draw table into the dom */
1429 for ( i=0, iLen=anRows.length ; i<iLen ; i++ )
1431 nAddFrag.appendChild( anRows[i] );
1434 oSettings.nTBody.appendChild( nAddFrag );
1435 if ( nBodyPar !== null )
1437 nBodyPar.appendChild( oSettings.nTBody );
1441 /* Call all required callback functions for the end of a draw */
1442 _fnCallbackFire( oSettings, 'aoDrawCallback', 'draw', [oSettings] );
1444 /* Draw is complete, sorting and filtering must be as well */
1445 oSettings.bSorted = false;
1446 oSettings.bFiltered = false;
1447 oSettings.bDrawing = false;
1449 if ( oSettings.oFeatures.bServerSide )
1451 _fnProcessingDisplay( oSettings, false );
1452 if ( !oSettings._bInitComplete )
1454 _fnInitComplete( oSettings );
1461 * Redraw the table - taking account of the various features which are enabled
1462 * @param {object} oSettings dataTables settings object
1463 * @memberof DataTable#oApi
1465 function _fnReDraw( oSettings )
1467 if ( oSettings.oFeatures.bSort )
1469 /* Sorting will refilter and draw for us */
1470 _fnSort( oSettings, oSettings.oPreviousSearch );
1472 else if ( oSettings.oFeatures.bFilter )
1474 /* Filtering will redraw for us */
1475 _fnFilterComplete( oSettings, oSettings.oPreviousSearch );
1479 _fnCalculateEnd( oSettings );
1480 _fnDraw( oSettings );
1486 * Add the options to the page HTML for the table
1487 * @param {object} oSettings dataTables settings object
1488 * @memberof DataTable#oApi
1490 function _fnAddOptionsHtml ( oSettings )
1493 * Create a temporary, empty, div which we can later on replace with what we have generated
1494 * we do it this way to rendering the 'options' html offline - speed :-)
1496 var nHolding = $('<div></div>')[0];
1497 oSettings.nTable.parentNode.insertBefore( nHolding, oSettings.nTable );
1500 * All DataTables are wrapped in a div
1502 oSettings.nTableWrapper = $('<div id="'+oSettings.sTableId+'_wrapper" class="'+oSettings.oClasses.sWrapper+'" role="grid"></div>')[0];
1503 oSettings.nTableReinsertBefore = oSettings.nTable.nextSibling;
1505 /* Track where we want to insert the option */
1506 var nInsertNode = oSettings.nTableWrapper;
1508 /* Loop over the user set positioning and place the elements as needed */
1509 var aDom = oSettings.sDom.split('');
1510 var nTmp, iPushFeature, cOption, nNewNode, cNext, sAttr, j;
1511 for ( var i=0 ; i<aDom.length ; i++ )
1516 if ( cOption == '<' )
1518 /* New container div */
1519 nNewNode = $('<div></div>')[0];
1521 /* Check to see if we should append an id and/or a class name to the container */
1523 if ( cNext == "'" || cNext == '"' )
1527 while ( aDom[i+j] != cNext )
1533 /* Replace jQuery UI constants */
1536 sAttr = "fg-toolbar ui-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix";
1538 else if ( sAttr == "F" )
1540 sAttr = "fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix";
1543 /* The attribute can be in the format of "#id.class", "#id" or "class" This logic
1544 * breaks the string into parts and applies them as needed
1546 if ( sAttr.indexOf('.') != -1 )
1548 var aSplit = sAttr.split('.');
1549 nNewNode.id = aSplit[0].substr(1, aSplit[0].length-1);
1550 nNewNode.className = aSplit[1];
1552 else if ( sAttr.charAt(0) == "#" )
1554 nNewNode.id = sAttr.substr(1, sAttr.length-1);
1558 nNewNode.className = sAttr;
1561 i += j; /* Move along the position array */
1564 nInsertNode.appendChild( nNewNode );
1565 nInsertNode = nNewNode;
1567 else if ( cOption == '>' )
1569 /* End container div */
1570 nInsertNode = nInsertNode.parentNode;
1572 else if ( cOption == 'l' && oSettings.oFeatures.bPaginate && oSettings.oFeatures.bLengthChange )
1575 nTmp = _fnFeatureHtmlLength( oSettings );
1578 else if ( cOption == 'f' && oSettings.oFeatures.bFilter )
1581 nTmp = _fnFeatureHtmlFilter( oSettings );
1584 else if ( cOption == 'r' && oSettings.oFeatures.bProcessing )
1587 nTmp = _fnFeatureHtmlProcessing( oSettings );
1590 else if ( cOption == 't' )
1593 nTmp = _fnFeatureHtmlTable( oSettings );
1596 else if ( cOption == 'i' && oSettings.oFeatures.bInfo )
1599 nTmp = _fnFeatureHtmlInfo( oSettings );
1602 else if ( cOption == 'p' && oSettings.oFeatures.bPaginate )
1605 nTmp = _fnFeatureHtmlPaginate( oSettings );
1608 else if ( DataTable.ext.aoFeatures.length !== 0 )
1610 /* Plug-in features */
1611 var aoFeatures = DataTable.ext.aoFeatures;
1612 for ( var k=0, kLen=aoFeatures.length ; k<kLen ; k++ )
1614 if ( cOption == aoFeatures[k].cFeature )
1616 nTmp = aoFeatures[k].fnInit( oSettings );
1626 /* Add to the 2D features array */
1627 if ( iPushFeature == 1 && nTmp !== null )
1629 if ( typeof oSettings.aanFeatures[cOption] !== 'object' )
1631 oSettings.aanFeatures[cOption] = [];
1633 oSettings.aanFeatures[cOption].push( nTmp );
1634 nInsertNode.appendChild( nTmp );
1638 /* Built our DOM structure - replace the holding div with what we want */
1639 nHolding.parentNode.replaceChild( oSettings.nTableWrapper, nHolding );
1644 * Use the DOM source to create up an array of header cells. The idea here is to
1645 * create a layout grid (array) of rows x columns, which contains a reference
1646 * to the cell that that point in the grid (regardless of col/rowspan), such that
1647 * any column / row could be removed and the new grid constructed
1648 * @param array {object} aLayout Array to store the calculated layout in
1649 * @param {node} nThead The header/footer element for the table
1650 * @memberof DataTable#oApi
1652 function _fnDetectHeader ( aLayout, nThead )
1654 var nTrs = $(nThead).children('tr');
1656 var i, j, k, l, iLen, jLen, iColShifted;
1657 var fnShiftCol = function ( a, i, j ) {
1664 aLayout.splice( 0, aLayout.length );
1666 /* We know how many rows there are in the layout - so prep it */
1667 for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
1672 /* Calculate a layout array */
1673 for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
1677 /* For every cell in the row... */
1678 for ( j=0, jLen=nTrs[i].childNodes.length ; j<jLen ; j++ )
1680 nCell = nTrs[i].childNodes[j];
1682 if ( nCell.nodeName.toUpperCase() == "TD" ||
1683 nCell.nodeName.toUpperCase() == "TH" )
1685 /* Get the col and rowspan attributes from the DOM and sanitise them */
1686 var iColspan = nCell.getAttribute('colspan') * 1;
1687 var iRowspan = nCell.getAttribute('rowspan') * 1;
1688 iColspan = (!iColspan || iColspan===0 || iColspan===1) ? 1 : iColspan;
1689 iRowspan = (!iRowspan || iRowspan===0 || iRowspan===1) ? 1 : iRowspan;
1691 /* There might be colspan cells already in this row, so shift our target
1694 iColShifted = fnShiftCol( aLayout, i, iColumn );
1696 /* If there is col / rowspan, copy the information into the layout grid */
1697 for ( l=0 ; l<iColspan ; l++ )
1699 for ( k=0 ; k<iRowspan ; k++ )
1701 aLayout[i+k][iColShifted+l] = {
1703 "unique": iColspan == 1 ? true : false
1705 aLayout[i+k].nTr = nTrs[i];
1715 * Get an array of unique th elements, one for each column
1716 * @param {object} oSettings dataTables settings object
1717 * @param {node} nHeader automatically detect the layout from this node - optional
1718 * @param {array} aLayout thead/tfoot layout from _fnDetectHeader - optional
1719 * @returns array {node} aReturn list of unique ths
1720 * @memberof DataTable#oApi
1722 function _fnGetUniqueThs ( oSettings, nHeader, aLayout )
1727 aLayout = oSettings.aoHeader;
1731 _fnDetectHeader( aLayout, nHeader );
1735 for ( var i=0, iLen=aLayout.length ; i<iLen ; i++ )
1737 for ( var j=0, jLen=aLayout[i].length ; j<jLen ; j++ )
1739 if ( aLayout[i][j].unique &&
1740 (!aReturn[j] || !oSettings.bSortCellsTop) )
1742 aReturn[j] = aLayout[i][j].cell;
1753 * Update the table using an Ajax call
1754 * @param {object} oSettings dataTables settings object
1755 * @returns {boolean} Block the table drawing or not
1756 * @memberof DataTable#oApi
1758 function _fnAjaxUpdate( oSettings )
1760 if ( oSettings.bAjaxDataGet )
1763 _fnProcessingDisplay( oSettings, true );
1764 var iColumns = oSettings.aoColumns.length;
1765 var aoData = _fnAjaxParameters( oSettings );
1766 _fnServerParams( oSettings, aoData );
1768 oSettings.fnServerData.call( oSettings.oInstance, oSettings.sAjaxSource, aoData,
1770 _fnAjaxUpdateDraw( oSettings, json );
1782 * Build up the parameters in an object needed for a server-side processing request
1783 * @param {object} oSettings dataTables settings object
1784 * @returns {bool} block the table drawing or not
1785 * @memberof DataTable#oApi
1787 function _fnAjaxParameters( oSettings )
1789 var iColumns = oSettings.aoColumns.length;
1790 var aoData = [], mDataProp;
1793 aoData.push( { "name": "sEcho", "value": oSettings.iDraw } );
1794 aoData.push( { "name": "iColumns", "value": iColumns } );
1795 aoData.push( { "name": "sColumns", "value": _fnColumnOrdering(oSettings) } );
1796 aoData.push( { "name": "iDisplayStart", "value": oSettings._iDisplayStart } );
1797 aoData.push( { "name": "iDisplayLength", "value": oSettings.oFeatures.bPaginate !== false ?
1798 oSettings._iDisplayLength : -1 } );
1800 for ( i=0 ; i<iColumns ; i++ )
1802 mDataProp = oSettings.aoColumns[i].mDataProp;
1803 aoData.push( { "name": "mDataProp_"+i, "value": typeof(mDataProp)==="function" ? 'function' : mDataProp } );
1807 if ( oSettings.oFeatures.bFilter !== false )
1809 aoData.push( { "name": "sSearch", "value": oSettings.oPreviousSearch.sSearch } );
1810 aoData.push( { "name": "bRegex", "value": oSettings.oPreviousSearch.bRegex } );
1811 for ( i=0 ; i<iColumns ; i++ )
1813 aoData.push( { "name": "sSearch_"+i, "value": oSettings.aoPreSearchCols[i].sSearch } );
1814 aoData.push( { "name": "bRegex_"+i, "value": oSettings.aoPreSearchCols[i].bRegex } );
1815 aoData.push( { "name": "bSearchable_"+i, "value": oSettings.aoColumns[i].bSearchable } );
1820 if ( oSettings.oFeatures.bSort !== false )
1822 var iFixed = oSettings.aaSortingFixed !== null ? oSettings.aaSortingFixed.length : 0;
1823 var iUser = oSettings.aaSorting.length;
1824 aoData.push( { "name": "iSortingCols", "value": iFixed+iUser } );
1825 for ( i=0 ; i<iFixed ; i++ )
1827 aoData.push( { "name": "iSortCol_"+i, "value": oSettings.aaSortingFixed[i][0] } );
1828 aoData.push( { "name": "sSortDir_"+i, "value": oSettings.aaSortingFixed[i][1] } );
1831 for ( i=0 ; i<iUser ; i++ )
1833 aoData.push( { "name": "iSortCol_"+(i+iFixed), "value": oSettings.aaSorting[i][0] } );
1834 aoData.push( { "name": "sSortDir_"+(i+iFixed), "value": oSettings.aaSorting[i][1] } );
1837 for ( i=0 ; i<iColumns ; i++ )
1839 aoData.push( { "name": "bSortable_"+i, "value": oSettings.aoColumns[i].bSortable } );
1848 * Add Ajax parameters from plugins
1849 * @param {object} oSettings dataTables settings object
1850 * @param array {objects} aoData name/value pairs to send to the server
1851 * @memberof DataTable#oApi
1853 function _fnServerParams( oSettings, aoData )
1855 _fnCallbackFire( oSettings, 'aoServerParams', 'serverParams', [aoData] );
1860 * Data the data from the server (nuking the old) and redraw the table
1861 * @param {object} oSettings dataTables settings object
1862 * @param {object} json json data return from the server.
1863 * @param {string} json.sEcho Tracking flag for DataTables to match requests
1864 * @param {int} json.iTotalRecords Number of records in the data set, not accounting for filtering
1865 * @param {int} json.iTotalDisplayRecords Number of records in the data set, accounting for filtering
1866 * @param {array} json.aaData The data to display on this page
1867 * @param {string} [json.sColumns] Column ordering (sName, comma separated)
1868 * @memberof DataTable#oApi
1870 function _fnAjaxUpdateDraw ( oSettings, json )
1872 if ( json.sEcho !== undefined )
1874 /* Protect against old returns over-writing a new one. Possible when you get
1875 * very fast interaction, and later queires are completed much faster
1877 if ( json.sEcho*1 < oSettings.iDraw )
1883 oSettings.iDraw = json.sEcho * 1;
1887 if ( !oSettings.oScroll.bInfinite ||
1888 (oSettings.oScroll.bInfinite && (oSettings.bSorted || oSettings.bFiltered)) )
1890 _fnClearTable( oSettings );
1892 oSettings._iRecordsTotal = parseInt(json.iTotalRecords, 10);
1893 oSettings._iRecordsDisplay = parseInt(json.iTotalDisplayRecords, 10);
1895 /* Determine if reordering is required */
1896 var sOrdering = _fnColumnOrdering(oSettings);
1897 var bReOrder = (json.sColumns !== undefined && sOrdering !== "" && json.sColumns != sOrdering );
1901 aiIndex = _fnReOrderIndex( oSettings, json.sColumns );
1904 var aData = _fnGetObjectDataFn( oSettings.sAjaxDataProp )( json );
1905 for ( var i=0, iLen=aData.length ; i<iLen ; i++ )
1909 /* If we need to re-order, then create a new array with the correct order and add it */
1910 var aDataSorted = [];
1911 for ( var j=0, jLen=oSettings.aoColumns.length ; j<jLen ; j++ )
1913 aDataSorted.push( aData[i][ aiIndex[j] ] );
1915 _fnAddData( oSettings, aDataSorted );
1919 /* No re-order required, sever got it "right" - just straight add */
1920 _fnAddData( oSettings, aData[i] );
1923 oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
1925 oSettings.bAjaxDataGet = false;
1926 _fnDraw( oSettings );
1927 oSettings.bAjaxDataGet = true;
1928 _fnProcessingDisplay( oSettings, false );
1934 * Generate the node required for filtering text
1935 * @returns {node} Filter control element
1936 * @param {object} oSettings dataTables settings object
1937 * @memberof DataTable#oApi
1939 function _fnFeatureHtmlFilter ( oSettings )
1941 var oPreviousSearch = oSettings.oPreviousSearch;
1943 var sSearchStr = oSettings.oLanguage.sSearch;
1944 sSearchStr = (sSearchStr.indexOf('_INPUT_') !== -1) ?
1945 sSearchStr.replace('_INPUT_', '<input type="text" />') :
1946 sSearchStr==="" ? '<input type="text" />' : sSearchStr+' <input type="text" />';
1948 var nFilter = document.createElement( 'div' );
1949 nFilter.className = oSettings.oClasses.sFilter;
1950 nFilter.innerHTML = '<label>'+sSearchStr+'</label>';
1951 if ( !oSettings.aanFeatures.f )
1953 nFilter.id = oSettings.sTableId+'_filter';
1956 var jqFilter = $("input", nFilter);
1957 jqFilter.val( oPreviousSearch.sSearch.replace('"','"') );
1958 jqFilter.bind( 'keyup.DT', function(e) {
1959 /* Update all other filter input elements for the new display */
1960 var n = oSettings.aanFeatures.f;
1961 for ( var i=0, iLen=n.length ; i<iLen ; i++ )
1963 if ( n[i] != $(this).parents('div.dataTables_filter')[0] )
1965 $('input', n[i]).val( this.value );
1969 /* Now do the filter */
1970 if ( this.value != oPreviousSearch.sSearch )
1972 _fnFilterComplete( oSettings, {
1973 "sSearch": this.value,
1974 "bRegex": oPreviousSearch.bRegex,
1975 "bSmart": oPreviousSearch.bSmart ,
1976 "bCaseInsensitive": oPreviousSearch.bCaseInsensitive
1982 .attr('aria-controls', oSettings.sTableId)
1983 .bind( 'keypress.DT', function(e) {
1984 /* Prevent form submission */
1985 if ( e.keyCode == 13 )
1997 * Filter the table using both the global filter and column based filtering
1998 * @param {object} oSettings dataTables settings object
1999 * @param {object} oSearch search information
2000 * @param {int} [iForce] force a research of the master array (1) or not (undefined or 0)
2001 * @memberof DataTable#oApi
2003 function _fnFilterComplete ( oSettings, oInput, iForce )
2005 var oPrevSearch = oSettings.oPreviousSearch;
2006 var aoPrevSearch = oSettings.aoPreSearchCols;
2007 var fnSaveFilter = function ( oFilter ) {
2008 /* Save the filtering values */
2009 oPrevSearch.sSearch = oFilter.sSearch;
2010 oPrevSearch.bRegex = oFilter.bRegex;
2011 oPrevSearch.bSmart = oFilter.bSmart;
2012 oPrevSearch.bCaseInsensitive = oFilter.bCaseInsensitive;
2015 /* In server-side processing all filtering is done by the server, so no point hanging around here */
2016 if ( !oSettings.oFeatures.bServerSide )
2019 _fnFilter( oSettings, oInput.sSearch, iForce, oInput.bRegex, oInput.bSmart, oInput.bCaseInsensitive );
2020 fnSaveFilter( oInput );
2022 /* Now do the individual column filter */
2023 for ( var i=0 ; i<oSettings.aoPreSearchCols.length ; i++ )
2025 _fnFilterColumn( oSettings, aoPrevSearch[i].sSearch, i, aoPrevSearch[i].bRegex,
2026 aoPrevSearch[i].bSmart, aoPrevSearch[i].bCaseInsensitive );
2029 /* Custom filtering */
2030 _fnFilterCustom( oSettings );
2034 fnSaveFilter( oInput );
2037 /* Tell the draw function we have been filtering */
2038 oSettings.bFiltered = true;
2039 $(oSettings.oInstance).trigger('filter', oSettings);
2041 /* Redraw the table */
2042 oSettings._iDisplayStart = 0;
2043 _fnCalculateEnd( oSettings );
2044 _fnDraw( oSettings );
2046 /* Rebuild search array 'offline' */
2047 _fnBuildSearchArray( oSettings, 0 );
2052 * Apply custom filtering functions
2053 * @param {object} oSettings dataTables settings object
2054 * @memberof DataTable#oApi
2056 function _fnFilterCustom( oSettings )
2058 var afnFilters = DataTable.ext.afnFiltering;
2059 for ( var i=0, iLen=afnFilters.length ; i<iLen ; i++ )
2062 for ( var j=0, jLen=oSettings.aiDisplay.length ; j<jLen ; j++ )
2064 var iDisIndex = oSettings.aiDisplay[j-iCorrector];
2066 /* Check if we should use this row based on the filtering function */
2067 if ( !afnFilters[i]( oSettings, _fnGetRowData( oSettings, iDisIndex, 'filter' ), iDisIndex ) )
2069 oSettings.aiDisplay.splice( j-iCorrector, 1 );
2078 * Filter the table on a per-column basis
2079 * @param {object} oSettings dataTables settings object
2080 * @param {string} sInput string to filter on
2081 * @param {int} iColumn column to filter
2082 * @param {bool} bRegex treat search string as a regular expression or not
2083 * @param {bool} bSmart use smart filtering or not
2084 * @param {bool} bCaseInsensitive Do case insenstive matching or not
2085 * @memberof DataTable#oApi
2087 function _fnFilterColumn ( oSettings, sInput, iColumn, bRegex, bSmart, bCaseInsensitive )
2089 if ( sInput === "" )
2094 var iIndexCorrector = 0;
2095 var rpSearch = _fnFilterCreateSearch( sInput, bRegex, bSmart, bCaseInsensitive );
2097 for ( var i=oSettings.aiDisplay.length-1 ; i>=0 ; i-- )
2099 var sData = _fnDataToSearch( _fnGetCellData( oSettings, oSettings.aiDisplay[i], iColumn, 'filter' ),
2100 oSettings.aoColumns[iColumn].sType );
2101 if ( ! rpSearch.test( sData ) )
2103 oSettings.aiDisplay.splice( i, 1 );
2111 * Filter the data table based on user input and draw the table
2112 * @param {object} oSettings dataTables settings object
2113 * @param {string} sInput string to filter on
2114 * @param {int} iForce optional - force a research of the master array (1) or not (undefined or 0)
2115 * @param {bool} bRegex treat as a regular expression or not
2116 * @param {bool} bSmart perform smart filtering or not
2117 * @param {bool} bCaseInsensitive Do case insenstive matching or not
2118 * @memberof DataTable#oApi
2120 function _fnFilter( oSettings, sInput, iForce, bRegex, bSmart, bCaseInsensitive )
2123 var rpSearch = _fnFilterCreateSearch( sInput, bRegex, bSmart, bCaseInsensitive );
2124 var oPrevSearch = oSettings.oPreviousSearch;
2126 /* Check if we are forcing or not - optional parameter */
2132 /* Need to take account of custom filtering functions - always filter */
2133 if ( DataTable.ext.afnFiltering.length !== 0 )
2139 * If the input is blank - we want the full data set
2141 if ( sInput.length <= 0 )
2143 oSettings.aiDisplay.splice( 0, oSettings.aiDisplay.length);
2144 oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
2149 * We are starting a new search or the new search string is smaller
2150 * then the old one (i.e. delete). Search from the master array
2152 if ( oSettings.aiDisplay.length == oSettings.aiDisplayMaster.length ||
2153 oPrevSearch.sSearch.length > sInput.length || iForce == 1 ||
2154 sInput.indexOf(oPrevSearch.sSearch) !== 0 )
2156 /* Nuke the old display array - we are going to rebuild it */
2157 oSettings.aiDisplay.splice( 0, oSettings.aiDisplay.length);
2159 /* Force a rebuild of the search array */
2160 _fnBuildSearchArray( oSettings, 1 );
2162 /* Search through all records to populate the search array
2163 * The the oSettings.aiDisplayMaster and asDataSearch arrays have 1 to 1
2166 for ( i=0 ; i<oSettings.aiDisplayMaster.length ; i++ )
2168 if ( rpSearch.test(oSettings.asDataSearch[i]) )
2170 oSettings.aiDisplay.push( oSettings.aiDisplayMaster[i] );
2176 /* Using old search array - refine it - do it this way for speed
2177 * Don't have to search the whole master array again
2179 var iIndexCorrector = 0;
2181 /* Search the current results */
2182 for ( i=0 ; i<oSettings.asDataSearch.length ; i++ )
2184 if ( ! rpSearch.test(oSettings.asDataSearch[i]) )
2186 oSettings.aiDisplay.splice( i-iIndexCorrector, 1 );
2196 * Create an array which can be quickly search through
2197 * @param {object} oSettings dataTables settings object
2198 * @param {int} iMaster use the master data array - optional
2199 * @memberof DataTable#oApi
2201 function _fnBuildSearchArray ( oSettings, iMaster )
2203 if ( !oSettings.oFeatures.bServerSide )
2205 /* Clear out the old data */
2206 oSettings.asDataSearch.splice( 0, oSettings.asDataSearch.length );
2208 var aArray = (iMaster && iMaster===1) ?
2209 oSettings.aiDisplayMaster : oSettings.aiDisplay;
2211 for ( var i=0, iLen=aArray.length ; i<iLen ; i++ )
2213 oSettings.asDataSearch[i] = _fnBuildSearchRow( oSettings,
2214 _fnGetRowData( oSettings, aArray[i], 'filter' ) );
2221 * Create a searchable string from a single data row
2222 * @param {object} oSettings dataTables settings object
2223 * @param {array} aData Row data array to use for the data to search
2224 * @memberof DataTable#oApi
2226 function _fnBuildSearchRow( oSettings, aData )
2229 if ( oSettings.__nTmpFilter === undefined )
2231 oSettings.__nTmpFilter = document.createElement('div');
2233 var nTmp = oSettings.__nTmpFilter;
2235 for ( var j=0, jLen=oSettings.aoColumns.length ; j<jLen ; j++ )
2237 if ( oSettings.aoColumns[j].bSearchable )
2239 var sData = aData[j];
2240 sSearch += _fnDataToSearch( sData, oSettings.aoColumns[j].sType )+' ';
2244 /* If it looks like there is an HTML entity in the string, attempt to decode it */
2245 if ( sSearch.indexOf('&') !== -1 )
2247 nTmp.innerHTML = sSearch;
2248 sSearch = nTmp.textContent ? nTmp.textContent : nTmp.innerText;
2250 /* IE and Opera appear to put an newline where there is a <br> tag - remove it */
2251 sSearch = sSearch.replace(/\n/g," ").replace(/\r/g,"");
2258 * Build a regular expression object suitable for searching a table
2259 * @param {string} sSearch string to search for
2260 * @param {bool} bRegex treat as a regular expression or not
2261 * @param {bool} bSmart perform smart filtering or not
2262 * @param {bool} bCaseInsensitive Do case insenstive matching or not
2263 * @returns {RegExp} constructed object
2264 * @memberof DataTable#oApi
2266 function _fnFilterCreateSearch( sSearch, bRegex, bSmart, bCaseInsensitive )
2268 var asSearch, sRegExpString;
2272 /* Generate the regular expression to use. Something along the lines of:
2273 * ^(?=.*?\bone\b)(?=.*?\btwo\b)(?=.*?\bthree\b).*$
2275 asSearch = bRegex ? sSearch.split( ' ' ) : _fnEscapeRegex( sSearch ).split( ' ' );
2276 sRegExpString = '^(?=.*?'+asSearch.join( ')(?=.*?' )+').*$';
2277 return new RegExp( sRegExpString, bCaseInsensitive ? "i" : "" );
2281 sSearch = bRegex ? sSearch : _fnEscapeRegex( sSearch );
2282 return new RegExp( sSearch, bCaseInsensitive ? "i" : "" );
2288 * Convert raw data into something that the user can search on
2289 * @param {string} sData data to be modified
2290 * @param {string} sType data type
2291 * @returns {string} search string
2292 * @memberof DataTable#oApi
2294 function _fnDataToSearch ( sData, sType )
2296 if ( typeof DataTable.ext.ofnSearch[sType] === "function" )
2298 return DataTable.ext.ofnSearch[sType]( sData );
2300 else if ( sType == "html" )
2302 return sData.replace(/[\r\n]/g," ").replace( /<.*?>/g, "" );
2304 else if ( typeof sData === "string" )
2306 return sData.replace(/[\r\n]/g," ");
2308 else if ( sData === null )
2317 * scape a string stuch that it can be used in a regular expression
2318 * @param {string} sVal string to escape
2319 * @returns {string} escaped string
2320 * @memberof DataTable#oApi
2322 function _fnEscapeRegex ( sVal )
2324 var acEscape = [ '/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\', '$', '^' ];
2325 var reReplace = new RegExp( '(\\' + acEscape.join('|\\') + ')', 'g' );
2326 return sVal.replace(reReplace, '\\$1');
2332 * Generate the node required for the info display
2333 * @param {object} oSettings dataTables settings object
2334 * @returns {node} Information element
2335 * @memberof DataTable#oApi
2337 function _fnFeatureHtmlInfo ( oSettings )
2339 var nInfo = document.createElement( 'div' );
2340 nInfo.className = oSettings.oClasses.sInfo;
2342 /* Actions that are to be taken once only for this feature */
2343 if ( !oSettings.aanFeatures.i )
2345 /* Add draw callback */
2346 oSettings.aoDrawCallback.push( {
2347 "fn": _fnUpdateInfo,
2348 "sName": "information"
2352 nInfo.id = oSettings.sTableId+'_info';
2354 oSettings.nTable.setAttribute( 'aria-describedby', oSettings.sTableId+'_info' );
2361 * Update the information elements in the display
2362 * @param {object} oSettings dataTables settings object
2363 * @memberof DataTable#oApi
2365 function _fnUpdateInfo ( oSettings )
2367 /* Show information about the table */
2368 if ( !oSettings.oFeatures.bInfo || oSettings.aanFeatures.i.length === 0 )
2374 iStart = oSettings._iDisplayStart+1, iEnd = oSettings.fnDisplayEnd(),
2375 iMax = oSettings.fnRecordsTotal(), iTotal = oSettings.fnRecordsDisplay(),
2376 sStart = oSettings.fnFormatNumber( iStart ), sEnd = oSettings.fnFormatNumber( iEnd ),
2377 sMax = oSettings.fnFormatNumber( iMax ), sTotal = oSettings.fnFormatNumber( iTotal ),
2380 /* When infinite scrolling, we are always starting at 1. _iDisplayStart is used only
2383 if ( oSettings.oScroll.bInfinite )
2385 sStart = oSettings.fnFormatNumber( 1 );
2388 if ( oSettings.fnRecordsDisplay() === 0 &&
2389 oSettings.fnRecordsDisplay() == oSettings.fnRecordsTotal() )
2391 /* Empty record set */
2392 sOut = oSettings.oLanguage.sInfoEmpty+ oSettings.oLanguage.sInfoPostFix;
2394 else if ( oSettings.fnRecordsDisplay() === 0 )
2396 /* Rmpty record set after filtering */
2397 sOut = oSettings.oLanguage.sInfoEmpty +' '+
2398 oSettings.oLanguage.sInfoFiltered.replace('_MAX_', sMax)+
2399 oSettings.oLanguage.sInfoPostFix;
2401 else if ( oSettings.fnRecordsDisplay() == oSettings.fnRecordsTotal() )
2403 /* Normal record set */
2404 sOut = oSettings.oLanguage.sInfo.
2405 replace('_START_', sStart).
2406 replace('_END_', sEnd).
2407 replace('_TOTAL_', sTotal)+
2408 oSettings.oLanguage.sInfoPostFix;
2412 /* Record set after filtering */
2413 sOut = oSettings.oLanguage.sInfo.
2414 replace('_START_', sStart).
2415 replace('_END_', sEnd).
2416 replace('_TOTAL_', sTotal) +' '+
2417 oSettings.oLanguage.sInfoFiltered.replace('_MAX_',
2418 oSettings.fnFormatNumber(oSettings.fnRecordsTotal()))+
2419 oSettings.oLanguage.sInfoPostFix;
2422 if ( oSettings.oLanguage.fnInfoCallback !== null )
2424 sOut = oSettings.oLanguage.fnInfoCallback.call( oSettings.oInstance,
2425 oSettings, iStart, iEnd, iMax, iTotal, sOut );
2428 var n = oSettings.aanFeatures.i;
2429 for ( var i=0, iLen=n.length ; i<iLen ; i++ )
2431 $(n[i]).html( sOut );
2438 * Draw the table for the first time, adding all required features
2439 * @param {object} oSettings dataTables settings object
2440 * @memberof DataTable#oApi
2442 function _fnInitialise ( oSettings )
2444 var i, iLen, iAjaxStart=oSettings.iInitDisplayStart;
2446 /* Ensure that the table data is fully initialised */
2447 if ( oSettings.bInitialised === false )
2449 setTimeout( function(){ _fnInitialise( oSettings ); }, 200 );
2453 /* Show the display HTML options */
2454 _fnAddOptionsHtml( oSettings );
2456 /* Build and draw the header / footer for the table */
2457 _fnBuildHead( oSettings );
2458 _fnDrawHead( oSettings, oSettings.aoHeader );
2459 if ( oSettings.nTFoot )
2461 _fnDrawHead( oSettings, oSettings.aoFooter );
2464 /* Okay to show that something is going on now */
2465 _fnProcessingDisplay( oSettings, true );
2467 /* Calculate sizes for columns */
2468 if ( oSettings.oFeatures.bAutoWidth )
2470 _fnCalculateColumnWidths( oSettings );
2473 for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
2475 if ( oSettings.aoColumns[i].sWidth !== null )
2477 oSettings.aoColumns[i].nTh.style.width = _fnStringToCss( oSettings.aoColumns[i].sWidth );
2481 /* If there is default sorting required - let's do it. The sort function will do the
2482 * drawing for us. Otherwise we draw the table regardless of the Ajax source - this allows
2483 * the table to look initialised for Ajax sourcing data (show 'loading' message possibly)
2485 if ( oSettings.oFeatures.bSort )
2487 _fnSort( oSettings );
2489 else if ( oSettings.oFeatures.bFilter )
2491 _fnFilterComplete( oSettings, oSettings.oPreviousSearch );
2495 oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
2496 _fnCalculateEnd( oSettings );
2497 _fnDraw( oSettings );
2500 /* if there is an ajax source load the data */
2501 if ( oSettings.sAjaxSource !== null && !oSettings.oFeatures.bServerSide )
2504 _fnServerParams( oSettings, aoData );
2505 oSettings.fnServerData.call( oSettings.oInstance, oSettings.sAjaxSource, aoData, function(json) {
2506 var aData = (oSettings.sAjaxDataProp !== "") ?
2507 _fnGetObjectDataFn( oSettings.sAjaxDataProp )(json) : json;
2509 /* Got the data - add it to the table */
2510 for ( i=0 ; i<aData.length ; i++ )
2512 _fnAddData( oSettings, aData[i] );
2515 /* Reset the init display for cookie saving. We've already done a filter, and
2516 * therefore cleared it before. So we need to make it appear 'fresh'
2518 oSettings.iInitDisplayStart = iAjaxStart;
2520 if ( oSettings.oFeatures.bSort )
2522 _fnSort( oSettings );
2526 oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
2527 _fnCalculateEnd( oSettings );
2528 _fnDraw( oSettings );
2531 _fnProcessingDisplay( oSettings, false );
2532 _fnInitComplete( oSettings, json );
2537 /* Server-side processing initialisation complete is done at the end of _fnDraw */
2538 if ( !oSettings.oFeatures.bServerSide )
2540 _fnProcessingDisplay( oSettings, false );
2541 _fnInitComplete( oSettings );
2547 * Draw the table for the first time, adding all required features
2548 * @param {object} oSettings dataTables settings object
2549 * @param {object} [json] JSON from the server that completed the table, if using Ajax source
2550 * with client-side processing (optional)
2551 * @memberof DataTable#oApi
2553 function _fnInitComplete ( oSettings, json )
2555 oSettings._bInitComplete = true;
2556 _fnCallbackFire( oSettings, 'aoInitComplete', 'init', [oSettings, json] );
2561 * Language compatibility - when certain options are given, and others aren't, we
2562 * need to duplicate the values over, in order to provide backwards compatibility
2563 * with older language files.
2564 * @param {object} oSettings dataTables settings object
2565 * @memberof DataTable#oApi
2567 function _fnLanguageCompat( oLanguage )
2569 /* Backwards compatibility - if there is no sEmptyTable given, then use the same as
2570 * sZeroRecords - assuming that is given.
2572 if ( !oLanguage.sEmptyTable && oLanguage.sZeroRecords )
2574 _fnMap( oLanguage, oLanguage, 'sZeroRecords', 'sEmptyTable' );
2577 /* Likewise with loading records */
2578 if ( !oLanguage.sLoadingRecords && oLanguage.sZeroRecords )
2580 _fnMap( oLanguage, oLanguage, 'sZeroRecords', 'sLoadingRecords' );
2587 * Generate the node required for user display length changing
2588 * @param {object} oSettings dataTables settings object
2589 * @returns {node} Display length feature node
2590 * @memberof DataTable#oApi
2592 function _fnFeatureHtmlLength ( oSettings )
2594 if ( oSettings.oScroll.bInfinite )
2599 /* This can be overruled by not using the _MENU_ var/macro in the language variable */
2600 var sName = 'name="'+oSettings.sTableId+'_length"';
2601 var sStdMenu = '<select size="1" '+sName+'>';
2603 var aLengthMenu = oSettings.aLengthMenu;
2605 if ( aLengthMenu.length == 2 && typeof aLengthMenu[0] === 'object' &&
2606 typeof aLengthMenu[1] === 'object' )
2608 for ( i=0, iLen=aLengthMenu[0].length ; i<iLen ; i++ )
2610 sStdMenu += '<option value="'+aLengthMenu[0][i]+'">'+aLengthMenu[1][i]+'</option>';
2615 for ( i=0, iLen=aLengthMenu.length ; i<iLen ; i++ )
2617 sStdMenu += '<option value="'+aLengthMenu[i]+'">'+aLengthMenu[i]+'</option>';
2620 sStdMenu += '</select>';
2622 var nLength = document.createElement( 'div' );
2623 if ( !oSettings.aanFeatures.l )
2625 nLength.id = oSettings.sTableId+'_length';
2627 nLength.className = oSettings.oClasses.sLength;
2628 nLength.innerHTML = '<label>'+oSettings.oLanguage.sLengthMenu.replace( '_MENU_', sStdMenu )+'</label>';
2631 * Set the length to the current display length - thanks to Andrea Pavlovic for this fix,
2632 * and Stefan Skopnik for fixing the fix!
2634 $('select option[value="'+oSettings._iDisplayLength+'"]', nLength).attr("selected", true);
2636 $('select', nLength).bind( 'change.DT', function(e) {
2637 var iVal = $(this).val();
2639 /* Update all other length options for the new display */
2640 var n = oSettings.aanFeatures.l;
2641 for ( i=0, iLen=n.length ; i<iLen ; i++ )
2643 if ( n[i] != this.parentNode )
2645 $('select', n[i]).val( iVal );
2649 /* Redraw the table */
2650 oSettings._iDisplayLength = parseInt(iVal, 10);
2651 _fnCalculateEnd( oSettings );
2653 /* If we have space to show extra rows (backing up from the end point - then do so */
2654 if ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() )
2656 oSettings._iDisplayStart = oSettings.fnDisplayEnd() - oSettings._iDisplayLength;
2657 if ( oSettings._iDisplayStart < 0 )
2659 oSettings._iDisplayStart = 0;
2663 if ( oSettings._iDisplayLength == -1 )
2665 oSettings._iDisplayStart = 0;
2668 _fnDraw( oSettings );
2672 $('select', nLength).attr('aria-controls', oSettings.sTableId);
2679 * Rcalculate the end point based on the start point
2680 * @param {object} oSettings dataTables settings object
2681 * @memberof DataTable#oApi
2683 function _fnCalculateEnd( oSettings )
2685 if ( oSettings.oFeatures.bPaginate === false )
2687 oSettings._iDisplayEnd = oSettings.aiDisplay.length;
2691 /* Set the end point of the display - based on how many elements there are
2694 if ( oSettings._iDisplayStart + oSettings._iDisplayLength > oSettings.aiDisplay.length ||
2695 oSettings._iDisplayLength == -1 )
2697 oSettings._iDisplayEnd = oSettings.aiDisplay.length;
2701 oSettings._iDisplayEnd = oSettings._iDisplayStart + oSettings._iDisplayLength;
2708 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2709 * Note that most of the paging logic is done in
2710 * DataTable.ext.oPagination
2714 * Generate the node required for default pagination
2715 * @param {object} oSettings dataTables settings object
2716 * @returns {node} Pagination feature node
2717 * @memberof DataTable#oApi
2719 function _fnFeatureHtmlPaginate ( oSettings )
2721 if ( oSettings.oScroll.bInfinite )
2726 var nPaginate = document.createElement( 'div' );
2727 nPaginate.className = oSettings.oClasses.sPaging+oSettings.sPaginationType;
2729 DataTable.ext.oPagination[ oSettings.sPaginationType ].fnInit( oSettings, nPaginate,
2730 function( oSettings ) {
2731 _fnCalculateEnd( oSettings );
2732 _fnDraw( oSettings );
2736 /* Add a draw callback for the pagination on first instance, to update the paging display */
2737 if ( !oSettings.aanFeatures.p )
2739 oSettings.aoDrawCallback.push( {
2740 "fn": function( oSettings ) {
2741 DataTable.ext.oPagination[ oSettings.sPaginationType ].fnUpdate( oSettings, function( oSettings ) {
2742 _fnCalculateEnd( oSettings );
2743 _fnDraw( oSettings );
2746 "sName": "pagination"
2754 * Alter the display settings to change the page
2755 * @param {object} oSettings dataTables settings object
2756 * @param {string|int} mAction Paging action to take: "first", "previous", "next" or "last"
2757 * or page number to jump to (integer)
2758 * @returns {bool} true page has changed, false - no change (no effect) eg 'first' on page 1
2759 * @memberof DataTable#oApi
2761 function _fnPageChange ( oSettings, mAction )
2763 var iOldStart = oSettings._iDisplayStart;
2765 if ( typeof mAction === "number" )
2767 oSettings._iDisplayStart = mAction * oSettings._iDisplayLength;
2768 if ( oSettings._iDisplayStart > oSettings.fnRecordsDisplay() )
2770 oSettings._iDisplayStart = 0;
2773 else if ( mAction == "first" )
2775 oSettings._iDisplayStart = 0;
2777 else if ( mAction == "previous" )
2779 oSettings._iDisplayStart = oSettings._iDisplayLength>=0 ?
2780 oSettings._iDisplayStart - oSettings._iDisplayLength :
2783 /* Correct for underrun */
2784 if ( oSettings._iDisplayStart < 0 )
2786 oSettings._iDisplayStart = 0;
2789 else if ( mAction == "next" )
2791 if ( oSettings._iDisplayLength >= 0 )
2793 /* Make sure we are not over running the display array */
2794 if ( oSettings._iDisplayStart + oSettings._iDisplayLength < oSettings.fnRecordsDisplay() )
2796 oSettings._iDisplayStart += oSettings._iDisplayLength;
2801 oSettings._iDisplayStart = 0;
2804 else if ( mAction == "last" )
2806 if ( oSettings._iDisplayLength >= 0 )
2808 var iPages = parseInt( (oSettings.fnRecordsDisplay()-1) / oSettings._iDisplayLength, 10 ) + 1;
2809 oSettings._iDisplayStart = (iPages-1) * oSettings._iDisplayLength;
2813 oSettings._iDisplayStart = 0;
2818 _fnLog( oSettings, 0, "Unknown paging action: "+mAction );
2820 $(oSettings.oInstance).trigger('page', oSettings);
2822 return iOldStart != oSettings._iDisplayStart;
2828 * Generate the node required for the processing node
2829 * @param {object} oSettings dataTables settings object
2830 * @returns {node} Processing element
2831 * @memberof DataTable#oApi
2833 function _fnFeatureHtmlProcessing ( oSettings )
2835 var nProcessing = document.createElement( 'div' );
2837 if ( !oSettings.aanFeatures.r )
2839 nProcessing.id = oSettings.sTableId+'_processing';
2841 nProcessing.innerHTML = oSettings.oLanguage.sProcessing;
2842 nProcessing.className = oSettings.oClasses.sProcessing;
2843 oSettings.nTable.parentNode.insertBefore( nProcessing, oSettings.nTable );
2850 * Display or hide the processing indicator
2851 * @param {object} oSettings dataTables settings object
2852 * @param {bool} bShow Show the processing indicator (true) or not (false)
2853 * @memberof DataTable#oApi
2855 function _fnProcessingDisplay ( oSettings, bShow )
2857 if ( oSettings.oFeatures.bProcessing )
2859 var an = oSettings.aanFeatures.r;
2860 for ( var i=0, iLen=an.length ; i<iLen ; i++ )
2862 an[i].style.visibility = bShow ? "visible" : "hidden";
2866 $(oSettings.oInstance).trigger('processing', [oSettings, bShow]);
2872 * Add any control elements for the table - specifically scrolling
2873 * @param {object} oSettings dataTables settings object
2874 * @returns {node} Node to add to the DOM
2875 * @memberof DataTable#oApi
2877 function _fnFeatureHtmlTable ( oSettings )
2879 /* Check if scrolling is enabled or not - if not then leave the DOM unaltered */
2880 if ( oSettings.oScroll.sX === "" && oSettings.oScroll.sY === "" )
2882 return oSettings.nTable;
2886 * The HTML structure that we want to generate in this function is:
2889 * div - nScrollHeadInner
2890 * table - nScrollHeadTable
2893 * table - oSettings.nTable
2894 * thead - nTheadSize
2897 * div - nScrollFootInner
2898 * table - nScrollFootTable
2902 nScroller = document.createElement('div'),
2903 nScrollHead = document.createElement('div'),
2904 nScrollHeadInner = document.createElement('div'),
2905 nScrollBody = document.createElement('div'),
2906 nScrollFoot = document.createElement('div'),
2907 nScrollFootInner = document.createElement('div'),
2908 nScrollHeadTable = oSettings.nTable.cloneNode(false),
2909 nScrollFootTable = oSettings.nTable.cloneNode(false),
2910 nThead = oSettings.nTable.getElementsByTagName('thead')[0],
2911 nTfoot = oSettings.nTable.getElementsByTagName('tfoot').length === 0 ? null :
2912 oSettings.nTable.getElementsByTagName('tfoot')[0],
2913 oClasses = oSettings.oClasses;
2915 nScrollHead.appendChild( nScrollHeadInner );
2916 nScrollFoot.appendChild( nScrollFootInner );
2917 nScrollBody.appendChild( oSettings.nTable );
2918 nScroller.appendChild( nScrollHead );
2919 nScroller.appendChild( nScrollBody );
2920 nScrollHeadInner.appendChild( nScrollHeadTable );
2921 nScrollHeadTable.appendChild( nThead );
2922 if ( nTfoot !== null )
2924 nScroller.appendChild( nScrollFoot );
2925 nScrollFootInner.appendChild( nScrollFootTable );
2926 nScrollFootTable.appendChild( nTfoot );
2929 nScroller.className = oClasses.sScrollWrapper;
2930 nScrollHead.className = oClasses.sScrollHead;
2931 nScrollHeadInner.className = oClasses.sScrollHeadInner;
2932 nScrollBody.className = oClasses.sScrollBody;
2933 nScrollFoot.className = oClasses.sScrollFoot;
2934 nScrollFootInner.className = oClasses.sScrollFootInner;
2936 if ( oSettings.oScroll.bAutoCss )
2938 nScrollHead.style.overflow = "hidden";
2939 nScrollHead.style.position = "relative";
2940 nScrollFoot.style.overflow = "hidden";
2941 nScrollBody.style.overflow = "auto";
2944 nScrollHead.style.border = "0";
2945 nScrollHead.style.width = "100%";
2946 nScrollFoot.style.border = "0";
2947 nScrollHeadInner.style.width = "150%"; /* will be overwritten */
2949 /* Modify attributes to respect the clones */
2950 nScrollHeadTable.removeAttribute('id');
2951 nScrollHeadTable.style.marginLeft = "0";
2952 oSettings.nTable.style.marginLeft = "0";
2953 if ( nTfoot !== null )
2955 nScrollFootTable.removeAttribute('id');
2956 nScrollFootTable.style.marginLeft = "0";
2959 /* Move any caption elements from the body to the header */
2960 var nCaptions = $(oSettings.nTable).children('caption');
2961 for ( var i=0, iLen=nCaptions.length ; i<iLen ; i++ )
2963 nScrollHeadTable.appendChild( nCaptions[i] );
2969 /* When xscrolling add the width and a scroller to move the header with the body */
2970 if ( oSettings.oScroll.sX !== "" )
2972 nScrollHead.style.width = _fnStringToCss( oSettings.oScroll.sX );
2973 nScrollBody.style.width = _fnStringToCss( oSettings.oScroll.sX );
2975 if ( nTfoot !== null )
2977 nScrollFoot.style.width = _fnStringToCss( oSettings.oScroll.sX );
2980 /* When the body is scrolled, then we also want to scroll the headers */
2981 $(nScrollBody).scroll( function (e) {
2982 nScrollHead.scrollLeft = this.scrollLeft;
2984 if ( nTfoot !== null )
2986 nScrollFoot.scrollLeft = this.scrollLeft;
2991 /* When yscrolling, add the height */
2992 if ( oSettings.oScroll.sY !== "" )
2994 nScrollBody.style.height = _fnStringToCss( oSettings.oScroll.sY );
2997 /* Redraw - align columns across the tables */
2998 oSettings.aoDrawCallback.push( {
2999 "fn": _fnScrollDraw,
3000 "sName": "scrolling"
3003 /* Infinite scrolling event handlers */
3004 if ( oSettings.oScroll.bInfinite )
3006 $(nScrollBody).scroll( function() {
3007 /* Use a blocker to stop scrolling from loading more data while other data is still loading */
3008 if ( !oSettings.bDrawing && $(this).scrollTop() !== 0 )
3010 /* Check if we should load the next data set */
3011 if ( $(this).scrollTop() + $(this).height() >
3012 $(oSettings.nTable).height() - oSettings.oScroll.iLoadGap )
3014 /* Only do the redraw if we have to - we might be at the end of the data */
3015 if ( oSettings.fnDisplayEnd() < oSettings.fnRecordsDisplay() )
3017 _fnPageChange( oSettings, 'next' );
3018 _fnCalculateEnd( oSettings );
3019 _fnDraw( oSettings );
3026 oSettings.nScrollHead = nScrollHead;
3027 oSettings.nScrollFoot = nScrollFoot;
3034 * Update the various tables for resizing. It's a bit of a pig this function, but
3035 * basically the idea to:
3036 * 1. Re-create the table inside the scrolling div
3037 * 2. Take live measurements from the DOM
3038 * 3. Apply the measurements
3040 * @param {object} o dataTables settings object
3041 * @returns {node} Node to add to the DOM
3042 * @memberof DataTable#oApi
3044 function _fnScrollDraw ( o )
3047 nScrollHeadInner = o.nScrollHead.getElementsByTagName('div')[0],
3048 nScrollHeadTable = nScrollHeadInner.getElementsByTagName('table')[0],
3049 nScrollBody = o.nTable.parentNode,
3050 i, iLen, j, jLen, anHeadToSize, anHeadSizers, anFootSizers, anFootToSize, oStyle, iVis,
3051 iWidth, aApplied=[], iSanityWidth,
3052 nScrollFootInner = (o.nTFoot !== null) ? o.nScrollFoot.getElementsByTagName('div')[0] : null,
3053 nScrollFootTable = (o.nTFoot !== null) ? nScrollFootInner.getElementsByTagName('table')[0] : null,
3054 ie67 = $.browser.msie && $.browser.version <= 7;
3057 * 1. Re-create the table inside the scrolling div
3060 /* Remove the old minimised thead and tfoot elements in the inner table */
3061 var nTheadSize = o.nTable.getElementsByTagName('thead');
3062 if ( nTheadSize.length > 0 )
3064 o.nTable.removeChild( nTheadSize[0] );
3068 if ( o.nTFoot !== null )
3070 /* Remove the old minimised footer element in the cloned header */
3071 nTfootSize = o.nTable.getElementsByTagName('tfoot');
3072 if ( nTfootSize.length > 0 )
3074 o.nTable.removeChild( nTfootSize[0] );
3078 /* Clone the current header and footer elements and then place it into the inner table */
3079 nTheadSize = o.nTHead.cloneNode(true);
3080 o.nTable.insertBefore( nTheadSize, o.nTable.childNodes[0] );
3082 if ( o.nTFoot !== null )
3084 nTfootSize = o.nTFoot.cloneNode(true);
3085 o.nTable.insertBefore( nTfootSize, o.nTable.childNodes[1] );
3089 * 2. Take live measurements from the DOM - do not alter the DOM itself!
3092 /* Remove old sizing and apply the calculated column widths
3093 * Get the unique column headers in the newly created (cloned) header. We want to apply the
3094 * calclated sizes to this header
3096 if ( o.oScroll.sX === "" )
3098 nScrollBody.style.width = '100%';
3099 nScrollHeadInner.parentNode.style.width = '100%';
3102 var nThs = _fnGetUniqueThs( o, nTheadSize );
3103 for ( i=0, iLen=nThs.length ; i<iLen ; i++ )
3105 iVis = _fnVisibleToColumnIndex( o, i );
3106 nThs[i].style.width = o.aoColumns[iVis].sWidth;
3109 if ( o.nTFoot !== null )
3111 _fnApplyToChildren( function(n) {
3113 }, nTfootSize.getElementsByTagName('tr') );
3116 /* Size the table as a whole */
3117 iSanityWidth = $(o.nTable).outerWidth();
3118 if ( o.oScroll.sX === "" )
3120 /* No x scrolling */
3121 o.nTable.style.width = "100%";
3123 /* I know this is rubbish - but IE7 will make the width of the table when 100% include
3124 * the scrollbar - which is shouldn't. When there is a scrollbar we need to take this
3127 if ( ie67 && ($('tbody', nScrollBody).height() > nScrollBody.offsetHeight ||
3128 $(nScrollBody).css('overflow-y') == "scroll") )
3130 o.nTable.style.width = _fnStringToCss( $(o.nTable).outerWidth()-o.oScroll.iBarWidth );
3135 if ( o.oScroll.sXInner !== "" )
3137 /* x scroll inner has been given - use it */
3138 o.nTable.style.width = _fnStringToCss(o.oScroll.sXInner);
3140 else if ( iSanityWidth == $(nScrollBody).width() &&
3141 $(nScrollBody).height() < $(o.nTable).height() )
3143 /* There is y-scrolling - try to take account of the y scroll bar */
3144 o.nTable.style.width = _fnStringToCss( iSanityWidth-o.oScroll.iBarWidth );
3145 if ( $(o.nTable).outerWidth() > iSanityWidth-o.oScroll.iBarWidth )
3147 /* Not possible to take account of it */
3148 o.nTable.style.width = _fnStringToCss( iSanityWidth );
3153 /* All else fails */
3154 o.nTable.style.width = _fnStringToCss( iSanityWidth );
3158 /* Recalculate the sanity width - now that we've applied the required width, before it was
3159 * a temporary variable. This is required because the column width calculation is done
3160 * before this table DOM is created.
3162 iSanityWidth = $(o.nTable).outerWidth();
3164 /* We want the hidden header to have zero height, so remove padding and borders. Then
3165 * set the width based on the real headers
3167 anHeadToSize = o.nTHead.getElementsByTagName('tr');
3168 anHeadSizers = nTheadSize.getElementsByTagName('tr');
3170 _fnApplyToChildren( function(nSizer, nToSize) {
3171 oStyle = nSizer.style;
3172 oStyle.paddingTop = "0";
3173 oStyle.paddingBottom = "0";
3174 oStyle.borderTopWidth = "0";
3175 oStyle.borderBottomWidth = "0";
3178 iWidth = $(nSizer).width();
3179 nToSize.style.width = _fnStringToCss( iWidth );
3180 aApplied.push( iWidth );
3181 }, anHeadSizers, anHeadToSize );
3182 $(anHeadSizers).height(0);
3184 if ( o.nTFoot !== null )
3186 /* Clone the current footer and then place it into the body table as a "hidden header" */
3187 anFootSizers = nTfootSize.getElementsByTagName('tr');
3188 anFootToSize = o.nTFoot.getElementsByTagName('tr');
3190 _fnApplyToChildren( function(nSizer, nToSize) {
3191 oStyle = nSizer.style;
3192 oStyle.paddingTop = "0";
3193 oStyle.paddingBottom = "0";
3194 oStyle.borderTopWidth = "0";
3195 oStyle.borderBottomWidth = "0";
3198 iWidth = $(nSizer).width();
3199 nToSize.style.width = _fnStringToCss( iWidth );
3200 aApplied.push( iWidth );
3201 }, anFootSizers, anFootToSize );
3202 $(anFootSizers).height(0);
3206 * 3. Apply the measurements
3209 /* "Hide" the header and footer that we used for the sizing. We want to also fix their width
3210 * to what they currently are
3212 _fnApplyToChildren( function(nSizer) {
3213 nSizer.innerHTML = "";
3214 nSizer.style.width = _fnStringToCss( aApplied.shift() );
3217 if ( o.nTFoot !== null )
3219 _fnApplyToChildren( function(nSizer) {
3220 nSizer.innerHTML = "";
3221 nSizer.style.width = _fnStringToCss( aApplied.shift() );
3225 /* Sanity check that the table is of a sensible width. If not then we are going to get
3226 * misalignment - try to prevent this by not allowing the table to shrink below its min width
3228 if ( $(o.nTable).outerWidth() < iSanityWidth )
3230 /* The min width depends upon if we have a vertical scrollbar visible or not */
3231 var iCorrection = ((nScrollBody.scrollHeight > nScrollBody.offsetHeight ||
3232 $(nScrollBody).css('overflow-y') == "scroll")) ?
3233 iSanityWidth+o.oScroll.iBarWidth : iSanityWidth;
3235 /* IE6/7 are a law unto themselves... */
3236 if ( ie67 && (nScrollBody.scrollHeight >
3237 nScrollBody.offsetHeight || $(nScrollBody).css('overflow-y') == "scroll") )
3239 o.nTable.style.width = _fnStringToCss( iCorrection-o.oScroll.iBarWidth );
3242 /* Apply the calculated minimum width to the table wrappers */
3243 nScrollBody.style.width = _fnStringToCss( iCorrection );
3244 nScrollHeadInner.parentNode.style.width = _fnStringToCss( iCorrection );
3246 if ( o.nTFoot !== null )
3248 nScrollFootInner.parentNode.style.width = _fnStringToCss( iCorrection );
3251 /* And give the user a warning that we've stopped the table getting too small */
3252 if ( o.oScroll.sX === "" )
3254 _fnLog( o, 1, "The table cannot fit into the current element which will cause column"+
3255 " misalignment. The table has been drawn at its minimum possible width." );
3257 else if ( o.oScroll.sXInner !== "" )
3259 _fnLog( o, 1, "The table cannot fit into the current element which will cause column"+
3260 " misalignment. Increase the sScrollXInner value or remove it to allow automatic"+
3266 nScrollBody.style.width = _fnStringToCss( '100%' );
3267 nScrollHeadInner.parentNode.style.width = _fnStringToCss( '100%' );
3269 if ( o.nTFoot !== null )
3271 nScrollFootInner.parentNode.style.width = _fnStringToCss( '100%' );
3279 if ( o.oScroll.sY === "" )
3281 /* IE7< puts a vertical scrollbar in place (when it shouldn't be) due to subtracting
3282 * the scrollbar height from the visible display, rather than adding it on. We need to
3283 * set the height in order to sort this. Don't want to do it in any other browsers.
3287 nScrollBody.style.height = _fnStringToCss( o.nTable.offsetHeight+o.oScroll.iBarWidth );
3291 if ( o.oScroll.sY !== "" && o.oScroll.bCollapse )
3293 nScrollBody.style.height = _fnStringToCss( o.oScroll.sY );
3295 var iExtra = (o.oScroll.sX !== "" && o.nTable.offsetWidth > nScrollBody.offsetWidth) ?
3296 o.oScroll.iBarWidth : 0;
3297 if ( o.nTable.offsetHeight < nScrollBody.offsetHeight )
3299 nScrollBody.style.height = _fnStringToCss( $(o.nTable).height()+iExtra );
3303 /* Finally set the width's of the header and footer tables */
3304 var iOuterWidth = $(o.nTable).outerWidth();
3305 nScrollHeadTable.style.width = _fnStringToCss( iOuterWidth );
3306 nScrollHeadInner.style.width = _fnStringToCss( iOuterWidth );
3308 if ( o.nTFoot !== null )
3310 nScrollFootInner.style.width = _fnStringToCss( o.nTable.offsetWidth );
3311 nScrollFootTable.style.width = _fnStringToCss( o.nTable.offsetWidth );
3314 /* If sorting or filtering has occurred, jump the scrolling back to the top */
3315 if ( o.bSorted || o.bFiltered )
3317 nScrollBody.scrollTop = 0;
3323 * Apply a given function to the display child nodes of an element array (typically
3324 * TD children of TR rows
3325 * @param {function} fn Method to apply to the objects
3326 * @param array {nodes} an1 List of elements to look through for display children
3327 * @param array {nodes} an2 Another list (identical structure to the first) - optional
3328 * @memberof DataTable#oApi
3330 function _fnApplyToChildren( fn, an1, an2 )
3332 for ( var i=0, iLen=an1.length ; i<iLen ; i++ )
3334 for ( var j=0, jLen=an1[i].childNodes.length ; j<jLen ; j++ )
3336 if ( an1[i].childNodes[j].nodeType == 1 )
3340 fn( an1[i].childNodes[j], an2[i].childNodes[j] );
3344 fn( an1[i].childNodes[j] );
3354 * Convert a CSS unit width to pixels (e.g. 2em)
3355 * @param {string} sWidth width to be converted
3356 * @param {node} nParent parent to get the with for (required for relative widths) - optional
3357 * @returns {int} iWidth width in pixels
3358 * @memberof DataTable#oApi
3360 function _fnConvertToWidth ( sWidth, nParent )
3362 if ( !sWidth || sWidth === null || sWidth === '' )
3369 nParent = document.getElementsByTagName('body')[0];
3373 var nTmp = document.createElement( "div" );
3374 nTmp.style.width = _fnStringToCss( sWidth );
3376 nParent.appendChild( nTmp );
3377 iWidth = nTmp.offsetWidth;
3378 nParent.removeChild( nTmp );
3385 * Calculate the width of columns for the table
3386 * @param {object} oSettings dataTables settings object
3387 * @memberof DataTable#oApi
3389 function _fnCalculateColumnWidths ( oSettings )
3391 var iTableWidth = oSettings.nTable.offsetWidth;
3392 var iUserInputs = 0;
3394 var iVisibleColumns = 0;
3395 var iColums = oSettings.aoColumns.length;
3396 var i, iIndex, iCorrector, iWidth;
3397 var oHeaders = $('th', oSettings.nTHead);
3398 var widthAttr = oSettings.nTable.getAttribute('width');
3400 /* Convert any user input sizes into pixel sizes */
3401 for ( i=0 ; i<iColums ; i++ )
3403 if ( oSettings.aoColumns[i].bVisible )
3407 if ( oSettings.aoColumns[i].sWidth !== null )
3409 iTmpWidth = _fnConvertToWidth( oSettings.aoColumns[i].sWidthOrig,
3410 oSettings.nTable.parentNode );
3411 if ( iTmpWidth !== null )
3413 oSettings.aoColumns[i].sWidth = _fnStringToCss( iTmpWidth );
3421 /* If the number of columns in the DOM equals the number that we have to process in
3422 * DataTables, then we can use the offsets that are created by the web-browser. No custom
3423 * sizes can be set in order for this to happen, nor scrolling used
3425 if ( iColums == oHeaders.length && iUserInputs === 0 && iVisibleColumns == iColums &&
3426 oSettings.oScroll.sX === "" && oSettings.oScroll.sY === "" )
3428 for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
3430 iTmpWidth = $(oHeaders[i]).width();
3431 if ( iTmpWidth !== null )
3433 oSettings.aoColumns[i].sWidth = _fnStringToCss( iTmpWidth );
3439 /* Otherwise we are going to have to do some calculations to get the width of each column.
3440 * Construct a 1 row table with the widest node in the data, and any user defined widths,
3441 * then insert it into the DOM and allow the browser to do all the hard work of
3442 * calculating table widths.
3445 nCalcTmp = oSettings.nTable.cloneNode( false ),
3446 nTheadClone = oSettings.nTHead.cloneNode(true),
3447 nBody = document.createElement( 'tbody' ),
3448 nTr = document.createElement( 'tr' ),
3451 nCalcTmp.removeAttribute( "id" );
3452 nCalcTmp.appendChild( nTheadClone );
3453 if ( oSettings.nTFoot !== null )
3455 nCalcTmp.appendChild( oSettings.nTFoot.cloneNode(true) );
3456 _fnApplyToChildren( function(n) {
3458 }, nCalcTmp.getElementsByTagName('tr') );
3461 nCalcTmp.appendChild( nBody );
3462 nBody.appendChild( nTr );
3464 /* Remove any sizing that was previously applied by the styles */
3465 var jqColSizing = $('thead th', nCalcTmp);
3466 if ( jqColSizing.length === 0 )
3468 jqColSizing = $('tbody tr:eq(0)>td', nCalcTmp);
3471 /* Apply custom sizing to the cloned header */
3472 var nThs = _fnGetUniqueThs( oSettings, nTheadClone );
3474 for ( i=0 ; i<iColums ; i++ )
3476 var oColumn = oSettings.aoColumns[i];
3477 if ( oColumn.bVisible && oColumn.sWidthOrig !== null && oColumn.sWidthOrig !== "" )
3479 nThs[i-iCorrector].style.width = _fnStringToCss( oColumn.sWidthOrig );
3481 else if ( oColumn.bVisible )
3483 nThs[i-iCorrector].style.width = "";
3491 /* Find the biggest td for each column and put it into the table */
3492 for ( i=0 ; i<iColums ; i++ )
3494 if ( oSettings.aoColumns[i].bVisible )
3496 var nTd = _fnGetWidestNode( oSettings, i );
3499 nTd = nTd.cloneNode(true);
3500 if ( oSettings.aoColumns[i].sContentPadding !== "" )
3502 nTd.innerHTML += oSettings.aoColumns[i].sContentPadding;
3504 nTr.appendChild( nTd );
3509 /* Build the table and 'display' it */
3510 var nWrapper = oSettings.nTable.parentNode;
3511 nWrapper.appendChild( nCalcTmp );
3513 /* When scrolling (X or Y) we want to set the width of the table as appropriate. However,
3514 * when not scrolling leave the table width as it is. This results in slightly different,
3515 * but I think correct behaviour
3517 if ( oSettings.oScroll.sX !== "" && oSettings.oScroll.sXInner !== "" )
3519 nCalcTmp.style.width = _fnStringToCss(oSettings.oScroll.sXInner);
3521 else if ( oSettings.oScroll.sX !== "" )
3523 nCalcTmp.style.width = "";
3524 if ( $(nCalcTmp).width() < nWrapper.offsetWidth )
3526 nCalcTmp.style.width = _fnStringToCss( nWrapper.offsetWidth );
3529 else if ( oSettings.oScroll.sY !== "" )
3531 nCalcTmp.style.width = _fnStringToCss( nWrapper.offsetWidth );
3533 else if ( widthAttr )
3535 nCalcTmp.style.width = _fnStringToCss( widthAttr );
3537 nCalcTmp.style.visibility = "hidden";
3539 /* Scrolling considerations */
3540 _fnScrollingWidthAdjust( oSettings, nCalcTmp );
3542 /* Read the width's calculated by the browser and store them for use by the caller. We
3543 * first of all try to use the elements in the body, but it is possible that there are
3544 * no elements there, under which circumstances we use the header elements
3546 var oNodes = $("tbody tr:eq(0)", nCalcTmp).children();
3547 if ( oNodes.length === 0 )
3549 oNodes = _fnGetUniqueThs( oSettings, $('thead', nCalcTmp)[0] );
3552 /* Browsers need a bit of a hand when a width is assigned to any columns when
3553 * x-scrolling as they tend to collapse the table to the min-width, even if
3554 * we sent the column widths. So we need to keep track of what the table width
3555 * should be by summing the user given values, and the automatic values
3557 if ( oSettings.oScroll.sX !== "" )
3561 for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
3563 if ( oSettings.aoColumns[i].bVisible )
3565 if ( oSettings.aoColumns[i].sWidthOrig === null )
3567 iTotal += $(oNodes[iCorrector]).outerWidth();
3571 iTotal += parseInt(oSettings.aoColumns[i].sWidth.replace('px',''), 10) +
3572 ($(oNodes[iCorrector]).outerWidth() - $(oNodes[iCorrector]).width());
3578 nCalcTmp.style.width = _fnStringToCss( iTotal );
3579 oSettings.nTable.style.width = _fnStringToCss( iTotal );
3583 for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
3585 if ( oSettings.aoColumns[i].bVisible )
3587 iWidth = $(oNodes[iCorrector]).width();
3588 if ( iWidth !== null && iWidth > 0 )
3590 oSettings.aoColumns[i].sWidth = _fnStringToCss( iWidth );
3596 var cssWidth = $(nCalcTmp).css('width');
3597 oSettings.nTable.style.width = (cssWidth.indexOf('%') !== -1) ?
3598 cssWidth : _fnStringToCss( $(nCalcTmp).outerWidth() );
3599 nCalcTmp.parentNode.removeChild( nCalcTmp );
3604 oSettings.nTable.style.width = _fnStringToCss( widthAttr );
3610 * Adjust a table's width to take account of scrolling
3611 * @param {object} oSettings dataTables settings object
3612 * @param {node} n table node
3613 * @memberof DataTable#oApi
3615 function _fnScrollingWidthAdjust ( oSettings, n )
3617 if ( oSettings.oScroll.sX === "" && oSettings.oScroll.sY !== "" )
3619 /* When y-scrolling only, we want to remove the width of the scroll bar so the table
3620 * + scroll bar will fit into the area avaialble.
3622 var iOrigWidth = $(n).width();
3623 n.style.width = _fnStringToCss( $(n).outerWidth()-oSettings.oScroll.iBarWidth );
3625 else if ( oSettings.oScroll.sX !== "" )
3627 /* When x-scrolling both ways, fix the table at it's current size, without adjusting */
3628 n.style.width = _fnStringToCss( $(n).outerWidth() );
3634 * Get the widest node
3635 * @param {object} oSettings dataTables settings object
3636 * @param {int} iCol column of interest
3637 * @returns {string} max strlens for each column
3638 * @memberof DataTable#oApi
3640 function _fnGetWidestNode( oSettings, iCol )
3642 var iMaxIndex = _fnGetMaxLenString( oSettings, iCol );
3643 if ( iMaxIndex < 0 )
3648 if ( oSettings.aoData[iMaxIndex].nTr === null )
3650 var n = document.createElement('td');
3651 n.innerHTML = _fnGetCellData( oSettings, iMaxIndex, iCol, '' );
3654 return _fnGetTdNodes(oSettings, iMaxIndex)[iCol];
3659 * Get the maximum strlen for each data column
3660 * @param {object} oSettings dataTables settings object
3661 * @param {int} iCol column of interest
3662 * @returns {string} max strlens for each column
3663 * @memberof DataTable#oApi
3665 function _fnGetMaxLenString( oSettings, iCol )
3670 for ( var i=0 ; i<oSettings.aoData.length ; i++ )
3672 var s = _fnGetCellData( oSettings, i, iCol, 'display' )+"";
3673 s = s.replace( /<.*?>/g, "" );
3674 if ( s.length > iMax )
3686 * Append a CSS unit (only if required) to a string
3687 * @param {array} aArray1 first array
3688 * @param {array} aArray2 second array
3689 * @returns {int} 0 if match, 1 if length is different, 2 if no match
3690 * @memberof DataTable#oApi
3692 function _fnStringToCss( s )
3699 if ( typeof s == 'number' )
3708 /* Check if the last character is not 0-9 */
3709 var c = s.charCodeAt( s.length-1 );
3710 if (c < 0x30 || c > 0x39)
3719 * Get the width of a scroll bar in this browser being used
3720 * @returns {int} width in pixels
3721 * @memberof DataTable#oApi
3723 function _fnScrollBarWidth ()
3725 var inner = document.createElement('p');
3726 var style = inner.style;
3727 style.width = "100%";
3728 style.height = "200px";
3729 style.padding = "0px";
3731 var outer = document.createElement('div');
3732 style = outer.style;
3733 style.position = "absolute";
3736 style.visibility = "hidden";
3737 style.width = "200px";
3738 style.height = "150px";
3739 style.padding = "0px";
3740 style.overflow = "hidden";
3741 outer.appendChild(inner);
3743 document.body.appendChild(outer);
3744 var w1 = inner.offsetWidth;
3745 outer.style.overflow = 'scroll';
3746 var w2 = inner.offsetWidth;
3749 w2 = outer.clientWidth;
3752 document.body.removeChild(outer);
3759 * Change the order of the table
3760 * @param {object} oSettings dataTables settings object
3761 * @param {bool} bApplyClasses optional - should we apply classes or not
3762 * @memberof DataTable#oApi
3764 function _fnSort ( oSettings, bApplyClasses )
3767 i, iLen, j, jLen, k, kLen,
3771 oSort = DataTable.ext.oSort,
3772 aoData = oSettings.aoData,
3773 aoColumns = oSettings.aoColumns,
3774 oAria = oSettings.oLanguage.oAria;
3776 /* No sorting required if server-side or no sorting array */
3777 if ( !oSettings.oFeatures.bServerSide &&
3778 (oSettings.aaSorting.length !== 0 || oSettings.aaSortingFixed !== null) )
3780 if ( oSettings.aaSortingFixed !== null )
3782 aaSort = oSettings.aaSortingFixed.concat( oSettings.aaSorting );
3786 aaSort = oSettings.aaSorting.slice();
3789 /* If there is a sorting data type, and a fuction belonging to it, then we need to
3790 * get the data from the developer's function and apply it for this column
3792 for ( i=0 ; i<aaSort.length ; i++ )
3794 var iColumn = aaSort[i][0];
3795 var iVisColumn = _fnColumnIndexToVisible( oSettings, iColumn );
3796 sDataType = oSettings.aoColumns[ iColumn ].sSortDataType;
3797 if ( DataTable.ext.afnSortData[sDataType] )
3799 var aData = DataTable.ext.afnSortData[sDataType]( oSettings, iColumn, iVisColumn );
3800 for ( j=0, jLen=aoData.length ; j<jLen ; j++ )
3802 _fnSetCellData( oSettings, j, iColumn, aData[j] );
3807 /* Create a value - key array of the current row positions such that we can use their
3808 * current position during the sort, if values match, in order to perform stable sorting
3810 for ( i=0, iLen=oSettings.aiDisplayMaster.length ; i<iLen ; i++ )
3812 aiOrig[ oSettings.aiDisplayMaster[i] ] = i;
3815 /* Build an internal data array which is specific to the sort, so we can get and prep
3816 * the data to be sorted only once, rather than needing to do it every time the sorting
3817 * function runs. This make the sorting function a very simple comparison
3819 var iSortLen = aaSort.length;
3820 var fnSortFormat, aDataSort;
3821 for ( i=0, iLen=aoData.length ; i<iLen ; i++ )
3823 for ( j=0 ; j<iSortLen ; j++ )
3825 aDataSort = aoColumns[ aaSort[j][0] ].aDataSort;
3827 for ( k=0, kLen=aDataSort.length ; k<kLen ; k++ )
3829 sDataType = aoColumns[ aDataSort[k] ].sType;
3830 fnSortFormat = oSort[ (sDataType ? sDataType : 'string')+"-pre" ];
3832 aoData[i]._aSortData[ aDataSort[k] ] = fnSortFormat ?
3833 fnSortFormat( _fnGetCellData( oSettings, i, aDataSort[k], 'sort' ) ) :
3834 _fnGetCellData( oSettings, i, aDataSort[k], 'sort' );
3839 /* Do the sort - here we want multi-column sorting based on a given data source (column)
3840 * and sorting function (from oSort) in a certain direction. It's reasonably complex to
3841 * follow on it's own, but this is what we want (example two column sorting):
3842 * fnLocalSorting = function(a,b){
3844 * iTest = oSort['string-asc']('data11', 'data12');
3847 * iTest = oSort['numeric-desc']('data21', 'data22');
3850 * return oSort['numeric-asc']( aiOrig[a], aiOrig[b] );
3852 * Basically we have a test for each sorting column, if the data in that column is equal,
3853 * test the next column. If all columns match, then we use a numeric sort on the row
3854 * positions in the original data array to provide a stable sort.
3856 oSettings.aiDisplayMaster.sort( function ( a, b ) {
3857 var k, l, lLen, iTest, aDataSort, sDataType;
3858 for ( k=0 ; k<iSortLen ; k++ )
3860 aDataSort = aoColumns[ aaSort[k][0] ].aDataSort;
3862 for ( l=0, lLen=aDataSort.length ; l<lLen ; l++ )
3864 sDataType = aoColumns[ aDataSort[l] ].sType;
3866 iTest = oSort[ (sDataType ? sDataType : 'string')+"-"+aaSort[k][1] ](
3867 aoData[a]._aSortData[ aDataSort[l] ],
3868 aoData[b]._aSortData[ aDataSort[l] ]
3878 return oSort['numeric-asc']( aiOrig[a], aiOrig[b] );
3882 /* Alter the sorting classes to take account of the changes */
3883 if ( (bApplyClasses === undefined || bApplyClasses) && !oSettings.oFeatures.bDeferRender )
3885 _fnSortingClasses( oSettings );
3888 for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
3890 nTh = aoColumns[i].nTh;
3891 nTh.removeAttribute('aria-sort');
3892 nTh.removeAttribute('aria-label');
3894 /* In ARIA only the first sorting column can be marked as sorting - no multi-sort option */
3895 if ( aoColumns[i].bSortable )
3897 if ( aaSort.length > 0 && aaSort[0][0] == i )
3899 nTh.setAttribute('aria-sort', aaSort[0][1]=="asc" ? "ascending" : "descending" );
3901 var nextSort = (aoColumns[i].asSorting[ aaSort[0][2]+1 ]) ?
3902 aoColumns[i].asSorting[ aaSort[0][2]+1 ] : aoColumns[i].asSorting[0];
3903 nTh.setAttribute('aria-label', aoColumns[i].sTitle+
3904 (nextSort=="asc" ? oAria.sSortAscending : oAria.sSortDescending) );
3908 nTh.setAttribute('aria-label', aoColumns[i].sTitle+
3909 (aoColumns[i].asSorting[0]=="asc" ? oAria.sSortAscending : oAria.sSortDescending) );
3914 nTh.setAttribute('aria-label', aoColumns[i].sTitle);
3918 /* Tell the draw function that we have sorted the data */
3919 oSettings.bSorted = true;
3920 $(oSettings.oInstance).trigger('sort', oSettings);
3922 /* Copy the master data into the draw array and re-draw */
3923 if ( oSettings.oFeatures.bFilter )
3925 /* _fnFilter() will redraw the table for us */
3926 _fnFilterComplete( oSettings, oSettings.oPreviousSearch, 1 );
3930 oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
3931 oSettings._iDisplayStart = 0; /* reset display back to page 0 */
3932 _fnCalculateEnd( oSettings );
3933 _fnDraw( oSettings );
3939 * Attach a sort handler (click) to a node
3940 * @param {object} oSettings dataTables settings object
3941 * @param {node} nNode node to attach the handler to
3942 * @param {int} iDataIndex column sorting index
3943 * @param {function} [fnCallback] callback function
3944 * @memberof DataTable#oApi
3946 function _fnSortAttachListener ( oSettings, nNode, iDataIndex, fnCallback )
3948 _fnBindAction( nNode, {}, function (e) {
3949 /* If the column is not sortable - don't to anything */
3950 if ( oSettings.aoColumns[iDataIndex].bSortable === false )
3956 * This is a little bit odd I admit... I declare a temporary function inside the scope of
3957 * _fnBuildHead and the click handler in order that the code presented here can be used
3958 * twice - once for when bProcessing is enabled, and another time for when it is
3959 * disabled, as we need to perform slightly different actions.
3960 * Basically the issue here is that the Javascript engine in modern browsers don't
3961 * appear to allow the rendering engine to update the display while it is still excuting
3962 * it's thread (well - it does but only after long intervals). This means that the
3963 * 'processing' display doesn't appear for a table sort. To break the js thread up a bit
3964 * I force an execution break by using setTimeout - but this breaks the expected
3965 * thread continuation for the end-developer's point of view (their code would execute
3966 * too early), so we on;y do it when we absolutely have to.
3968 var fnInnerSorting = function () {
3969 var iColumn, iNextSort;
3971 /* If the shift key is pressed then we are multipe column sorting */
3974 /* Are we already doing some kind of sort on this column? */
3976 for ( var i=0 ; i<oSettings.aaSorting.length ; i++ )
3978 if ( oSettings.aaSorting[i][0] == iDataIndex )
3981 iColumn = oSettings.aaSorting[i][0];
3982 iNextSort = oSettings.aaSorting[i][2]+1;
3984 if ( !oSettings.aoColumns[iColumn].asSorting[iNextSort] )
3986 /* Reached the end of the sorting options, remove from multi-col sort */
3987 oSettings.aaSorting.splice( i, 1 );
3991 /* Move onto next sorting direction */
3992 oSettings.aaSorting[i][1] = oSettings.aoColumns[iColumn].asSorting[iNextSort];
3993 oSettings.aaSorting[i][2] = iNextSort;
3999 /* No sort yet - add it in */
4000 if ( bFound === false )
4002 oSettings.aaSorting.push( [ iDataIndex,
4003 oSettings.aoColumns[iDataIndex].asSorting[0], 0 ] );
4008 /* If no shift key then single column sort */
4009 if ( oSettings.aaSorting.length == 1 && oSettings.aaSorting[0][0] == iDataIndex )
4011 iColumn = oSettings.aaSorting[0][0];
4012 iNextSort = oSettings.aaSorting[0][2]+1;
4013 if ( !oSettings.aoColumns[iColumn].asSorting[iNextSort] )
4017 oSettings.aaSorting[0][1] = oSettings.aoColumns[iColumn].asSorting[iNextSort];
4018 oSettings.aaSorting[0][2] = iNextSort;
4022 oSettings.aaSorting.splice( 0, oSettings.aaSorting.length );
4023 oSettings.aaSorting.push( [ iDataIndex,
4024 oSettings.aoColumns[iDataIndex].asSorting[0], 0 ] );
4029 _fnSort( oSettings );
4030 }; /* /fnInnerSorting */
4032 if ( !oSettings.oFeatures.bProcessing )
4038 _fnProcessingDisplay( oSettings, true );
4039 setTimeout( function() {
4041 if ( !oSettings.oFeatures.bServerSide )
4043 _fnProcessingDisplay( oSettings, false );
4048 /* Call the user specified callback function - used for async user interaction */
4049 if ( typeof fnCallback == 'function' )
4051 fnCallback( oSettings );
4058 * Set the sorting classes on the header, Note: it is safe to call this function
4059 * when bSort and bSortClasses are false
4060 * @param {object} oSettings dataTables settings object
4061 * @memberof DataTable#oApi
4063 function _fnSortingClasses( oSettings )
4065 var i, iLen, j, jLen, iFound;
4067 var iColumns = oSettings.aoColumns.length;
4068 var oClasses = oSettings.oClasses;
4070 for ( i=0 ; i<iColumns ; i++ )
4072 if ( oSettings.aoColumns[i].bSortable )
4074 $(oSettings.aoColumns[i].nTh).removeClass( oClasses.sSortAsc +" "+ oClasses.sSortDesc +
4075 " "+ oSettings.aoColumns[i].sSortingClass );
4079 if ( oSettings.aaSortingFixed !== null )
4081 aaSort = oSettings.aaSortingFixed.concat( oSettings.aaSorting );
4085 aaSort = oSettings.aaSorting.slice();
4088 /* Apply the required classes to the header */
4089 for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
4091 if ( oSettings.aoColumns[i].bSortable )
4093 sClass = oSettings.aoColumns[i].sSortingClass;
4095 for ( j=0 ; j<aaSort.length ; j++ )
4097 if ( aaSort[j][0] == i )
4099 sClass = ( aaSort[j][1] == "asc" ) ?
4100 oClasses.sSortAsc : oClasses.sSortDesc;
4105 $(oSettings.aoColumns[i].nTh).addClass( sClass );
4107 if ( oSettings.bJUI )
4109 /* jQuery UI uses extra markup */
4110 var jqSpan = $("span."+oClasses.sSortIcon, oSettings.aoColumns[i].nTh);
4111 jqSpan.removeClass(oClasses.sSortJUIAsc +" "+ oClasses.sSortJUIDesc +" "+
4112 oClasses.sSortJUI +" "+ oClasses.sSortJUIAscAllowed +" "+ oClasses.sSortJUIDescAllowed );
4117 sSpanClass = oSettings.aoColumns[i].sSortingClassJUI;
4119 else if ( aaSort[iFound][1] == "asc" )
4121 sSpanClass = oClasses.sSortJUIAsc;
4125 sSpanClass = oClasses.sSortJUIDesc;
4128 jqSpan.addClass( sSpanClass );
4133 /* No sorting on this column, so add the base class. This will have been assigned by
4136 $(oSettings.aoColumns[i].nTh).addClass( oSettings.aoColumns[i].sSortingClass );
4141 * Apply the required classes to the table body
4142 * Note that this is given as a feature switch since it can significantly slow down a sort
4143 * on large data sets (adding and removing of classes is always slow at the best of times..)
4144 * Further to this, note that this code is admitadly fairly ugly. It could be made a lot
4145 * simpiler using jQuery selectors and add/removeClass, but that is significantly slower
4146 * (on the order of 5 times slower) - hence the direct DOM manipulation here.
4147 * Note that for defered drawing we do use jQuery - the reason being that taking the first
4148 * row found to see if the whole column needs processed can miss classes since the first
4149 * column might be new.
4151 sClass = oClasses.sSortColumn;
4153 if ( oSettings.oFeatures.bSort && oSettings.oFeatures.bSortClasses )
4155 var nTds = _fnGetTdNodes( oSettings );
4157 /* Remove the old classes */
4158 if ( oSettings.oFeatures.bDeferRender )
4160 $(nTds).removeClass(sClass+'1 '+sClass+'2 '+sClass+'3');
4162 else if ( nTds.length >= iColumns )
4164 for ( i=0 ; i<iColumns ; i++ )
4166 if ( nTds[i].className.indexOf(sClass+"1") != -1 )
4168 for ( j=0, jLen=(nTds.length/iColumns) ; j<jLen ; j++ )
4170 nTds[(iColumns*j)+i].className =
4171 $.trim( nTds[(iColumns*j)+i].className.replace( sClass+"1", "" ) );
4174 else if ( nTds[i].className.indexOf(sClass+"2") != -1 )
4176 for ( j=0, jLen=(nTds.length/iColumns) ; j<jLen ; j++ )
4178 nTds[(iColumns*j)+i].className =
4179 $.trim( nTds[(iColumns*j)+i].className.replace( sClass+"2", "" ) );
4182 else if ( nTds[i].className.indexOf(sClass+"3") != -1 )
4184 for ( j=0, jLen=(nTds.length/iColumns) ; j<jLen ; j++ )
4186 nTds[(iColumns*j)+i].className =
4187 $.trim( nTds[(iColumns*j)+i].className.replace( " "+sClass+"3", "" ) );
4193 /* Add the new classes to the table */
4194 var iClass = 1, iTargetCol;
4195 for ( i=0 ; i<aaSort.length ; i++ )
4197 iTargetCol = parseInt( aaSort[i][0], 10 );
4198 for ( j=0, jLen=(nTds.length/iColumns) ; j<jLen ; j++ )
4200 nTds[(iColumns*j)+iTargetCol].className += " "+sClass+iClass;
4214 * Save the state of a table in a cookie such that the page can be reloaded
4215 * @param {object} oSettings dataTables settings object
4216 * @memberof DataTable#oApi
4218 function _fnSaveState ( oSettings )
4220 if ( !oSettings.oFeatures.bStateSave || oSettings.bDestroying )
4225 /* Store the interesting variables */
4226 var i, iLen, bInfinite=oSettings.oScroll.bInfinite;
4228 "iCreate": new Date().getTime(),
4229 "iStart": (bInfinite ? 0 : oSettings._iDisplayStart),
4230 "iEnd": (bInfinite ? oSettings._iDisplayLength : oSettings._iDisplayEnd),
4231 "iLength": oSettings._iDisplayLength,
4232 "aaSorting": $.extend( true, [], oSettings.aaSorting ),
4233 "oSearch": $.extend( true, {}, oSettings.oPreviousSearch ),
4234 "aoSearchCols": $.extend( true, [], oSettings.aoPreSearchCols ),
4238 for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
4240 oState.abVisCols.push( oSettings.aoColumns[i].bVisible );
4243 _fnCallbackFire( oSettings, "aoStateSaveParams", 'stateSaveParams', [oSettings, oState] );
4245 oSettings.fnStateSave.call( oSettings.oInstance, oSettings, oState );
4250 * Attempt to load a saved table state from a cookie
4251 * @param {object} oSettings dataTables settings object
4252 * @param {object} oInit DataTables init object so we can override settings
4253 * @memberof DataTable#oApi
4255 function _fnLoadState ( oSettings, oInit )
4257 if ( !oSettings.oFeatures.bStateSave )
4262 var oData = oSettings.fnStateLoad.call( oSettings.oInstance, oSettings );
4268 /* Allow custom and plug-in manipulation functions to alter the saved data set and
4269 * cancelling of loading by returning false
4271 var abStateLoad = _fnCallbackFire( oSettings, 'aoStateLoadParams', 'stateLoadParams', [oSettings, oData] );
4272 if ( $.inArray( false, abStateLoad ) !== -1 )
4277 /* Store the saved state so it might be accessed at any time */
4278 oSettings.oLoadedState = $.extend( true, {}, oData );
4280 /* Restore key features */
4281 oSettings._iDisplayStart = oData.iStart;
4282 oSettings.iInitDisplayStart = oData.iStart;
4283 oSettings._iDisplayEnd = oData.iEnd;
4284 oSettings._iDisplayLength = oData.iLength;
4285 oSettings.aaSorting = oData.aaSorting.slice();
4286 oSettings.saved_aaSorting = oData.aaSorting.slice();
4288 /* Search filtering */
4289 $.extend( oSettings.oPreviousSearch, oData.oSearch );
4290 $.extend( true, oSettings.aoPreSearchCols, oData.aoSearchCols );
4292 /* Column visibility state
4293 * Pass back visibiliy settings to the init handler, but to do not here override
4294 * the init object that the user might have passed in
4296 oInit.saved_aoColumns = [];
4297 for ( var i=0 ; i<oData.abVisCols.length ; i++ )
4299 oInit.saved_aoColumns[i] = {};
4300 oInit.saved_aoColumns[i].bVisible = oData.abVisCols[i];
4303 _fnCallbackFire( oSettings, 'aoStateLoaded', 'stateLoaded', [oSettings, oData] );
4308 * Create a new cookie with a value to store the state of a table
4309 * @param {string} sName name of the cookie to create
4310 * @param {string} sValue the value the cookie should take
4311 * @param {int} iSecs duration of the cookie
4312 * @param {string} sBaseName sName is made up of the base + file name - this is the base
4313 * @param {function} fnCallback User definable function to modify the cookie
4314 * @memberof DataTable#oApi
4316 function _fnCreateCookie ( sName, sValue, iSecs, sBaseName, fnCallback )
4318 var date = new Date();
4319 date.setTime( date.getTime()+(iSecs*1000) );
4322 * Shocking but true - it would appear IE has major issues with having the path not having
4323 * a trailing slash on it. We need the cookie to be available based on the path, so we
4324 * have to append the file name to the cookie name. Appalling. Thanks to vex for adding the
4325 * patch to use at least some of the path
4327 var aParts = window.location.pathname.split('/');
4328 var sNameFile = sName + '_' + aParts.pop().replace(/[\/:]/g,"").toLowerCase();
4329 var sFullCookie, oData;
4331 if ( fnCallback !== null )
4333 oData = (typeof $.parseJSON === 'function') ?
4334 $.parseJSON( sValue ) : eval( '('+sValue+')' );
4335 sFullCookie = fnCallback( sNameFile, oData, date.toGMTString(),
4336 aParts.join('/')+"/" );
4340 sFullCookie = sNameFile + "=" + encodeURIComponent(sValue) +
4341 "; expires=" + date.toGMTString() +"; path=" + aParts.join('/')+"/";
4344 /* Are we going to go over the cookie limit of 4KiB? If so, try to delete a cookies
4345 * belonging to DataTables. This is FAR from bullet proof
4347 var sOldName="", iOldTime=9999999999999;
4348 var iLength = _fnReadCookie( sNameFile )!==null ? document.cookie.length :
4349 sFullCookie.length + document.cookie.length;
4351 if ( iLength+10 > 4096 ) /* Magic 10 for padding */
4353 var aCookies =document.cookie.split(';');
4354 for ( var i=0, iLen=aCookies.length ; i<iLen ; i++ )
4356 if ( aCookies[i].indexOf( sBaseName ) != -1 )
4358 /* It's a DataTables cookie, so eval it and check the time stamp */
4359 var aSplitCookie = aCookies[i].split('=');
4360 try { oData = eval( '('+decodeURIComponent(aSplitCookie[1])+')' ); }
4361 catch( e ) { continue; }
4363 if ( oData.iCreate && oData.iCreate < iOldTime )
4365 sOldName = aSplitCookie[0];
4366 iOldTime = oData.iCreate;
4371 if ( sOldName !== "" )
4373 document.cookie = sOldName+"=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path="+
4374 aParts.join('/') + "/";
4378 document.cookie = sFullCookie;
4383 * Read an old cookie to get a cookie with an old table state
4384 * @param {string} sName name of the cookie to read
4385 * @returns {string} contents of the cookie - or null if no cookie with that name found
4386 * @memberof DataTable#oApi
4388 function _fnReadCookie ( sName )
4391 aParts = window.location.pathname.split('/'),
4392 sNameEQ = sName + '_' + aParts[aParts.length-1].replace(/[\/:]/g,"").toLowerCase() + '=',
4393 sCookieContents = document.cookie.split(';');
4395 for( var i=0 ; i<sCookieContents.length ; i++ )
4397 var c = sCookieContents[i];
4399 while (c.charAt(0)==' ')
4401 c = c.substring(1,c.length);
4404 if (c.indexOf(sNameEQ) === 0)
4406 return decodeURIComponent( c.substring(sNameEQ.length,c.length) );
4415 * Return the settings object for a particular table
4416 * @param {node} nTable table we are using as a dataTable
4417 * @returns {object} Settings object - or null if not found
4418 * @memberof DataTable#oApi
4420 function _fnSettingsFromNode ( nTable )
4422 for ( var i=0 ; i<DataTable.settings.length ; i++ )
4424 if ( DataTable.settings[i].nTable === nTable )
4426 return DataTable.settings[i];
4435 * Return an array with the TR nodes for the table
4436 * @param {object} oSettings dataTables settings object
4437 * @returns {array} TR array
4438 * @memberof DataTable#oApi
4440 function _fnGetTrNodes ( oSettings )
4443 var aoData = oSettings.aoData;
4444 for ( var i=0, iLen=aoData.length ; i<iLen ; i++ )
4446 if ( aoData[i].nTr !== null )
4448 aNodes.push( aoData[i].nTr );
4456 * Return an flat array with all TD nodes for the table, or row
4457 * @param {object} oSettings dataTables settings object
4458 * @param {int} [iIndividualRow] aoData index to get the nodes for - optional
4459 * if not given then the return array will contain all nodes for the table
4460 * @returns {array} TD array
4461 * @memberof DataTable#oApi
4463 function _fnGetTdNodes ( oSettings, iIndividualRow )
4468 var iRow, iRows=oSettings.aoData.length,
4469 iColumn, iColumns, oData, sNodeName, iStart=0, iEnd=iRows;
4471 /* Allow the collection to be limited to just one row */
4472 if ( iIndividualRow !== undefined )
4474 iStart = iIndividualRow;
4475 iEnd = iIndividualRow+1;
4478 for ( iRow=iStart ; iRow<iEnd ; iRow++ )
4480 oData = oSettings.aoData[iRow];
4481 if ( oData.nTr !== null )
4483 /* get the TD child nodes - taking into account text etc nodes */
4485 for ( iColumn=0, iColumns=oData.nTr.childNodes.length ; iColumn<iColumns ; iColumn++ )
4487 sNodeName = oData.nTr.childNodes[iColumn].nodeName.toLowerCase();
4488 if ( sNodeName == 'td' || sNodeName == 'th' )
4490 anTds.push( oData.nTr.childNodes[iColumn] );
4495 for ( iColumn=0, iColumns=oSettings.aoColumns.length ; iColumn<iColumns ; iColumn++ )
4497 if ( oSettings.aoColumns[iColumn].bVisible )
4499 anReturn.push( anTds[iColumn-iCorrector] );
4503 anReturn.push( oData._anHidden[iColumn] );
4515 * Log an error message
4516 * @param {object} oSettings dataTables settings object
4517 * @param {int} iLevel log error messages, or display them to the user
4518 * @param {string} sMesg error message
4519 * @memberof DataTable#oApi
4521 function _fnLog( oSettings, iLevel, sMesg )
4523 var sAlert = (oSettings===null) ?
4524 "DataTables warning: "+sMesg :
4525 "DataTables warning (table id = '"+oSettings.sTableId+"'): "+sMesg;
4529 if ( DataTable.ext.sErrMode == 'alert' )
4539 else if ( console !== undefined && console.log )
4541 console.log( sAlert );
4547 * See if a property is defined on one object, if so assign it to the other object
4548 * @param {object} oRet target object
4549 * @param {object} oSrc source object
4550 * @param {string} sName property
4551 * @param {string} [sMappedName] name to map too - optional, sName used if not given
4552 * @memberof DataTable#oApi
4554 function _fnMap( oRet, oSrc, sName, sMappedName )
4556 if ( sMappedName === undefined )
4558 sMappedName = sName;
4560 if ( oSrc[sName] !== undefined )
4562 oRet[sMappedName] = oSrc[sName];
4568 * Extend objects - very similar to jQuery.extend, but deep copy objects, and shallow
4569 * copy arrays. The reason we need to do this, is that we don't want to deep copy array
4570 * init values (such as aaSorting) since the dev wouldn't be able to override them, but
4571 * we do want to deep copy arrays.
4572 * @param {object} oOut Object to extend
4573 * @param {object} oExtender Object from which the properties will be applied to oOut
4574 * @returns {object} oOut Reference, just for convenience - oOut === the return.
4575 * @memberof DataTable#oApi
4576 * @todo This doesn't take account of arrays inside the deep copied objects.
4578 function _fnExtend( oOut, oExtender )
4580 for ( var prop in oOut )
4582 if ( oOut.hasOwnProperty(prop) && oExtender[prop] !== undefined )
4584 if ( typeof oInit[prop] === 'object' && $.isArray(oExtender[prop]) === false )
4586 $.extend( true, oOut[prop], oExtender[prop] );
4590 oOut[prop] = oExtender[prop];
4600 * Bind an event handers to allow a click or return key to activate the callback.
4601 * This is good for accessability since a return on the keyboard will have the
4602 * same effect as a click, if the element has focus.
4603 * @param {element} n Element to bind the action to
4604 * @param {object} oData Data object to pass to the triggered function
4605 * @param {function) fn Callback function for when the event is triggered
4606 * @memberof DataTable#oApi
4608 function _fnBindAction( n, oData, fn )
4611 .bind( 'click.DT', oData, function (e) {
4613 n.blur(); // Remove focus outline for mouse users
4615 .bind( 'keypress.DT', oData, function (e){
4616 if ( e.which === 13 ) {
4619 .bind( 'selectstart.DT', function () {
4620 /* Take the brutal approach to cancelling text selection */
4627 * Register a callback function. Easily allows a callback function to be added to
4628 * an array store of callback functions that can then all be called together.
4629 * @param {object} oSettings dataTables settings object
4630 * @param {string} sStore Name of the array storeage for the callbacks in oSettings
4631 * @param {function} fn Function to be called back
4632 * @param {string) sName Identifying name for the callback (i.e. a label)
4633 * @memberof DataTable#oApi
4635 function _fnCallbackReg( oSettings, sStore, fn, sName )
4639 oSettings[sStore].push( {
4648 * Fire callback functions and trigger events. Note that the loop over the callback
4649 * array store is done backwards! Further note that you do not want to fire off triggers
4650 * in time sensitive applications (for example cell creation) as its slow.
4651 * @param {object} oSettings dataTables settings object
4652 * @param {string} sStore Name of the array storeage for the callbacks in oSettings
4653 * @param {string} sTrigger Name of the jQuery custom event to trigger. If null no trigger
4655 * @param {array) aArgs Array of arguments to pass to the callback function / trigger
4656 * @memberof DataTable#oApi
4658 function _fnCallbackFire( oSettings, sStore, sTrigger, aArgs )
4660 var aoStore = oSettings[sStore];
4663 for ( var i=aoStore.length-1 ; i>=0 ; i-- )
4665 aRet.push( aoStore[i].fn.apply( oSettings.oInstance, aArgs ) );
4668 if ( sTrigger !== null )
4670 $(oSettings.oInstance).trigger(sTrigger, aArgs);
4678 * JSON stringify. If JSON.stringify it provided by the browser, json2.js or any other
4679 * library, then we use that as it is fast, safe and accurate. If the function isn't
4680 * available then we need to built it ourselves - the insperation for this function comes
4681 * from Craig Buckler ( http://www.sitepoint.com/javascript-json-serialization/ ). It is
4682 * not perfect and absolutely should not be used as a replacement to json2.js - but it does
4683 * do what we need, without requiring a dependency for DataTables.
4684 * @param {object} o JSON object to be converted
4685 * @returns {string} JSON string
4686 * @memberof DataTable#oApi
4688 var _fnJsonString = (window.JSON) ? JSON.stringify : function( o )
4690 /* Not an object or array */
4691 var sType = typeof o;
4692 if (sType !== "object" || o === null)
4695 if (sType === "string")
4702 /* If object or array, need to recurse over it */
4706 bArr = $.isArray(o);
4711 sType = typeof mValue;
4713 if (sType === "string")
4715 mValue = '"'+mValue+'"';
4717 else if (sType === "object" && mValue !== null)
4719 mValue = _fnJsonString(mValue);
4722 json.push((bArr ? "" : '"'+sProp+'":') + mValue);
4725 return (bArr ? "[" : "{") + json + (bArr ? "]" : "}");
4732 * Perform a jQuery selector action on the table's TR elements (from the tbody) and
4733 * return the resulting jQuery object.
4734 * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
4735 * @param {object} [oOpts] Optional parameters for modifying the rows to be included
4736 * @param {string} [oOpts.filter=none] Select TR elements that meet the current filter
4737 * criterion ("applied") or all TR elements (i.e. no filter).
4738 * @param {string} [oOpts.order=current] Order of the TR elements in the processed array.
4739 * Can be either 'current', whereby the current sorting of the table is used, or
4740 * 'original' whereby the original order the data was read into the table is used.
4741 * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
4742 * ("current") or not ("all"). If 'current' is given, then order is assumed to be
4743 * 'current' and filter is 'applied', regardless of what they might be given as.
4744 * @returns {object} jQuery object, filtered by the given selector.
4748 * $(document).ready(function() {
4749 * var oTable = $('#example').dataTable();
4751 * // Highlight every second row
4752 * oTable.$('tr:odd').css('backgroundColor', 'blue');
4756 * $(document).ready(function() {
4757 * var oTable = $('#example').dataTable();
4759 * // Filter to rows with 'Webkit' in them, add a background colour and then
4760 * // remove the filter, thus highlighting the 'Webkit' rows only.
4761 * oTable.fnFilter('Webkit');
4762 * oTable.$('tr', {"filter": "applied"}).css('backgroundColor', 'blue');
4763 * oTable.fnFilter('');
4766 this.$ = function ( sSelector, oOpts )
4768 var i, iLen, a = [];
4769 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
4776 oOpts = $.extend( {}, {
4777 "filter": "none", // applied
4778 "order": "current", // "original"
4779 "page": "all" // current
4782 // Current page implies that order=current and fitler=applied, since it is fairly
4783 // senseless otherwise
4784 if ( oOpts.page == 'current' )
4786 for ( i=oSettings._iDisplayStart, iLen=oSettings.fnDisplayEnd() ; i<iLen ; i++ )
4788 a.push( oSettings.aoData[ oSettings.aiDisplay[i] ].nTr );
4791 else if ( oOpts.order == "current" && oOpts.filter == "none" )
4793 for ( i=0, iLen=oSettings.aiDisplayMaster.length ; i<iLen ; i++ )
4795 a.push( oSettings.aoData[ oSettings.aiDisplayMaster[i] ].nTr );
4798 else if ( oOpts.order == "current" && oOpts.filter == "applied" )
4800 for ( i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ )
4802 a.push( oSettings.aoData[ oSettings.aiDisplay[i] ].nTr );
4805 else if ( oOpts.order == "original" && oOpts.filter == "none" )
4807 for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
4809 a.push( oSettings.aoData[ i ].nTr );
4812 else if ( oOpts.order == "original" && oOpts.filter == "applied" )
4814 for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
4816 if ( $.inArray( i, oSettings.aiDisplay ) !== -1 )
4818 a.push( oSettings.aoData[ i ].nTr );
4824 _fnLog( oSettings, 1, "Unknown selection options" );
4827 /* We need to filter on the TR elements and also 'find' in their descendants
4828 * to make the selector act like it would in a full table - so we need
4829 * to build both results and then combine them together
4832 var jqTRs = jqA.filter( sSelector );
4833 var jqDescendants = jqA.find( sSelector );
4835 return $( [].concat($.makeArray(jqTRs), $.makeArray(jqDescendants)) );
4840 * Almost identical to $ in operation, but in this case returns the data for the matched
4841 * rows - as such, the jQuery selector used should match TR row nodes or TD/TH cell nodes
4842 * rather than any decendents, so the data can be obtained for the row/cell. If matching
4843 * rows are found, the data returned is the original data array/object that was used to
4844 * create the row (or a generated array if from a DOM source).
4846 * This method is often useful incombination with $ where both functions are given the
4847 * same parameters and the array indexes will match identically.
4848 * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
4849 * @param {object} [oOpts] Optional parameters for modifying the rows to be included
4850 * @param {string} [oOpts.filter=none] Select elements that meet the current filter
4851 * criterion ("applied") or all elements (i.e. no filter).
4852 * @param {string} [oOpts.order=current] Order of the data in the processed array.
4853 * Can be either 'current', whereby the current sorting of the table is used, or
4854 * 'original' whereby the original order the data was read into the table is used.
4855 * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
4856 * ("current") or not ("all"). If 'current' is given, then order is assumed to be
4857 * 'current' and filter is 'applied', regardless of what they might be given as.
4858 * @returns {array} Data for the matched elements. If any elements, as a result of the
4859 * selector, were not TR, TD or TH elements in the DataTable, they will have a null
4860 * entry in the array.
4864 * $(document).ready(function() {
4865 * var oTable = $('#example').dataTable();
4867 * // Get the data from the first row in the table
4868 * var data = oTable._('tr:first');
4870 * // Do something useful with the data
4871 * alert( "First cell is: "+data[0] );
4875 * $(document).ready(function() {
4876 * var oTable = $('#example').dataTable();
4878 * // Filter to 'Webkit' and get all data for
4879 * oTable.fnFilter('Webkit');
4880 * var data = oTable._('tr', {"filter": "applied"});
4882 * // Do something with the data
4883 * alert( data.length+" rows matched the filter" );
4886 this._ = function ( sSelector, oOpts )
4889 var i, iLen, iIndex;
4890 var aTrs = this.$( sSelector, oOpts );
4892 for ( i=0, iLen=aTrs.length ; i<iLen ; i++ )
4894 aOut.push( this.fnGetData(aTrs[i]) );
4902 * Add a single new row or multiple rows of data to the table. Please note
4903 * that this is suitable for client-side processing only - if you are using
4904 * server-side processing (i.e. "bServerSide": true), then to add data, you
4905 * must add it to the data source, i.e. the server-side, through an Ajax call.
4906 * @param {array|object} mData The data to be added to the table. This can be:
4908 * <li>1D array of data - add a single row with the data provided</li>
4909 * <li>2D array of arrays - add multiple rows in a single call</li>
4910 * <li>object - data object when using <i>mDataProp</i></li>
4911 * <li>array of objects - multiple data objects when using <i>mDataProp</i></li>
4913 * @param {bool} [bRedraw=true] redraw the table or not
4914 * @returns {array} An array of integers, representing the list of indexes in
4915 * <i>aoData</i> ({@link DataTable.models.oSettings}) that have been added to
4920 * // Global var for counter
4923 * $(document).ready(function() {
4924 * $('#example').dataTable();
4927 * function fnClickAddRow() {
4928 * $('#example').dataTable().fnAddData( [
4938 this.fnAddData = function( mData, bRedraw )
4940 if ( mData.length === 0 )
4948 /* Find settings from table node */
4949 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
4951 /* Check if we want to add multiple rows or not */
4952 if ( typeof mData[0] === "object" && mData[0] !== null )
4954 for ( var i=0 ; i<mData.length ; i++ )
4956 iTest = _fnAddData( oSettings, mData[i] );
4961 aiReturn.push( iTest );
4966 iTest = _fnAddData( oSettings, mData );
4971 aiReturn.push( iTest );
4974 oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
4976 if ( bRedraw === undefined || bRedraw )
4978 _fnReDraw( oSettings );
4985 * This function will make DataTables recalculate the column sizes, based on the data
4986 * contained in the table and the sizes applied to the columns (in the DOM, CSS or
4987 * through the sWidth parameter). This can be useful when the width of the table's
4988 * parent element changes (for example a window resize).
4989 * @param {boolean} [bRedraw=true] Redraw the table or not, you will typically want to
4993 * $(document).ready(function() {
4994 * var oTable = $('#example').dataTable( {
4995 * "sScrollY": "200px",
4996 * "bPaginate": false
4999 * $(window).bind('resize', function () {
5000 * oTable.fnAdjustColumnSizing();
5004 this.fnAdjustColumnSizing = function ( bRedraw )
5006 var oSettings = _fnSettingsFromNode(this[DataTable.ext.iApiIndex]);
5007 _fnAdjustColumnSizing( oSettings );
5009 if ( bRedraw === undefined || bRedraw )
5011 this.fnDraw( false );
5013 else if ( oSettings.oScroll.sX !== "" || oSettings.oScroll.sY !== "" )
5015 /* If not redrawing, but scrolling, we want to apply the new column sizes anyway */
5016 this.oApi._fnScrollDraw(oSettings);
5022 * Quickly and simply clear a table
5023 * @param {bool} [bRedraw=true] redraw the table or not
5027 * $(document).ready(function() {
5028 * var oTable = $('#example').dataTable();
5030 * // Immediately 'nuke' the current rows (perhaps waiting for an Ajax callback...)
5031 * oTable.fnClearTable();
5034 this.fnClearTable = function( bRedraw )
5036 /* Find settings from table node */
5037 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5038 _fnClearTable( oSettings );
5040 if ( bRedraw === undefined || bRedraw )
5042 _fnDraw( oSettings );
5048 * The exact opposite of 'opening' a row, this function will close any rows which
5049 * are currently 'open'.
5050 * @param {node} nTr the table row to 'close'
5051 * @returns {int} 0 on success, or 1 if failed (can't find the row)
5055 * $(document).ready(function() {
5058 * // 'open' an information row when a row is clicked on
5059 * $('#example tbody tr').click( function () {
5060 * if ( oTable.fnIsOpen(this) ) {
5061 * oTable.fnClose( this );
5063 * oTable.fnOpen( this, "Temporary row opened", "info_row" );
5067 * oTable = $('#example').dataTable();
5070 this.fnClose = function( nTr )
5072 /* Find settings from table node */
5073 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5075 for ( var i=0 ; i<oSettings.aoOpenRows.length ; i++ )
5077 if ( oSettings.aoOpenRows[i].nParent == nTr )
5079 var nTrParent = oSettings.aoOpenRows[i].nTr.parentNode;
5082 /* Remove it if it is currently on display */
5083 nTrParent.removeChild( oSettings.aoOpenRows[i].nTr );
5085 oSettings.aoOpenRows.splice( i, 1 );
5094 * Remove a row for the table
5095 * @param {mixed} mTarget The index of the row from aoData to be deleted, or
5096 * the TR element you want to delete
5097 * @param {function|null} [fnCallBack] Callback function
5098 * @param {bool} [bRedraw=true] Redraw the table or not
5099 * @returns {array} The row that was deleted
5103 * $(document).ready(function() {
5104 * var oTable = $('#example').dataTable();
5106 * // Immediately remove the first row
5107 * oTable.fnDeleteRow( 0 );
5110 this.fnDeleteRow = function( mTarget, fnCallBack, bRedraw )
5112 /* Find settings from table node */
5113 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5114 var i, iLen, iAODataIndex;
5116 iAODataIndex = (typeof mTarget === 'object') ?
5117 _fnNodeToDataIndex(oSettings, mTarget) : mTarget;
5119 /* Return the data array from this row */
5120 var oData = oSettings.aoData.splice( iAODataIndex, 1 );
5122 /* Update the _DT_RowIndex parameter */
5123 for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
5125 if ( oSettings.aoData[i].nTr !== null )
5127 oSettings.aoData[i].nTr._DT_RowIndex = i;
5131 /* Remove the target row from the search array */
5132 var iDisplayIndex = $.inArray( iAODataIndex, oSettings.aiDisplay );
5133 oSettings.asDataSearch.splice( iDisplayIndex, 1 );
5135 /* Delete from the display arrays */
5136 _fnDeleteIndex( oSettings.aiDisplayMaster, iAODataIndex );
5137 _fnDeleteIndex( oSettings.aiDisplay, iAODataIndex );
5139 /* If there is a user callback function - call it */
5140 if ( typeof fnCallBack === "function" )
5142 fnCallBack.call( this, oSettings, oData );
5145 /* Check for an 'overflow' they case for dislaying the table */
5146 if ( oSettings._iDisplayStart >= oSettings.aiDisplay.length )
5148 oSettings._iDisplayStart -= oSettings._iDisplayLength;
5149 if ( oSettings._iDisplayStart < 0 )
5151 oSettings._iDisplayStart = 0;
5155 if ( bRedraw === undefined || bRedraw )
5157 _fnCalculateEnd( oSettings );
5158 _fnDraw( oSettings );
5166 * Restore the table to it's original state in the DOM by removing all of DataTables
5167 * enhancements, alterations to the DOM structure of the table and event listeners.
5168 * @param {boolean} [bRemove=false] Completely remove the table from the DOM
5172 * $(document).ready(function() {
5173 * // This example is fairly pointless in reality, but shows how fnDestroy can be used
5174 * var oTable = $('#example').dataTable();
5175 * oTable.fnDestroy();
5178 this.fnDestroy = function ( bRemove )
5180 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5181 var nOrig = oSettings.nTableWrapper.parentNode;
5182 var nBody = oSettings.nTBody;
5185 bRemove = (bRemove===undefined) ? false : true;
5187 /* Flag to note that the table is currently being destroyed - no action should be taken */
5188 oSettings.bDestroying = true;
5190 /* Restore hidden columns */
5191 for ( i=0, iLen=oSettings.aoDestroyCallback.length ; i<iLen ; i++ ) {
5192 oSettings.aoDestroyCallback[i].fn();
5195 /* Restore hidden columns */
5196 for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
5198 if ( oSettings.aoColumns[i].bVisible === false )
5200 this.fnSetColumnVis( i, true );
5204 /* Blitz all DT events */
5205 $(oSettings.nTableWrapper).find('*').andSelf().unbind('.DT');
5207 /* If there is an 'empty' indicator row, remove it */
5208 $('tbody>tr>td.'+oSettings.oClasses.sRowEmpty, oSettings.nTable).parent().remove();
5210 /* When scrolling we had to break the table up - restore it */
5211 if ( oSettings.nTable != oSettings.nTHead.parentNode )
5213 $(oSettings.nTable).children('thead').remove();
5214 oSettings.nTable.appendChild( oSettings.nTHead );
5217 if ( oSettings.nTFoot && oSettings.nTable != oSettings.nTFoot.parentNode )
5219 $(oSettings.nTable).children('tfoot').remove();
5220 oSettings.nTable.appendChild( oSettings.nTFoot );
5223 /* Remove the DataTables generated nodes, events and classes */
5224 oSettings.nTable.parentNode.removeChild( oSettings.nTable );
5225 $(oSettings.nTableWrapper).remove();
5227 oSettings.aaSorting = [];
5228 oSettings.aaSortingFixed = [];
5229 _fnSortingClasses( oSettings );
5231 $(_fnGetTrNodes( oSettings )).removeClass( oSettings.asStripeClasses.join(' ') );
5233 $('th, td', oSettings.nTHead).removeClass( [
5234 oSettings.oClasses.sSortable,
5235 oSettings.oClasses.sSortableAsc,
5236 oSettings.oClasses.sSortableDesc,
5237 oSettings.oClasses.sSortableNone ].join(' ')
5239 if ( oSettings.bJUI )
5241 $('th span.'+oSettings.oClasses.sSortIcon
5242 + ', td span.'+oSettings.oClasses.sSortIcon, oSettings.nTHead).remove();
5244 $('th, td', oSettings.nTHead).each( function () {
5245 var jqWrapper = $('div.'+oSettings.oClasses.sSortJUIWrapper, this);
5246 var kids = jqWrapper.contents();
5247 $(this).append( kids );
5252 /* Add the TR elements back into the table in their original order */
5253 if ( !bRemove && oSettings.nTableReinsertBefore )
5255 nOrig.insertBefore( oSettings.nTable, oSettings.nTableReinsertBefore );
5257 else if ( !bRemove )
5259 nOrig.appendChild( oSettings.nTable );
5262 for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
5264 if ( oSettings.aoData[i].nTr !== null )
5266 nBody.appendChild( oSettings.aoData[i].nTr );
5270 /* Restore the width of the original table */
5271 if ( oSettings.oFeatures.bAutoWidth === true )
5273 oSettings.nTable.style.width = _fnStringToCss(oSettings.sDestroyWidth);
5276 /* If the were originally odd/even type classes - then we add them back here. Note
5277 * this is not fool proof (for example if not all rows as odd/even classes - but
5278 * it's a good effort without getting carried away
5280 $(nBody).children('tr:even').addClass( oSettings.asDestroyStripes[0] );
5281 $(nBody).children('tr:odd').addClass( oSettings.asDestroyStripes[1] );
5283 /* Remove the settings object from the settings array */
5284 for ( i=0, iLen=DataTable.settings.length ; i<iLen ; i++ )
5286 if ( DataTable.settings[i] == oSettings )
5288 DataTable.settings.splice( i, 1 );
5299 * @param {bool} [bComplete=true] Re-filter and resort (if enabled) the table before the draw.
5303 * $(document).ready(function() {
5304 * var oTable = $('#example').dataTable();
5306 * // Re-draw the table - you wouldn't want to do it here, but it's an example :-)
5310 this.fnDraw = function( bComplete )
5312 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5315 _fnCalculateEnd( oSettings );
5316 _fnDraw( oSettings );
5320 _fnReDraw( oSettings );
5326 * Filter the input based on data
5327 * @param {string} sInput String to filter the table on
5328 * @param {int|null} [iColumn] Column to limit filtering to
5329 * @param {bool} [bRegex=false] Treat as regular expression or not
5330 * @param {bool} [bSmart=true] Perform smart filtering or not
5331 * @param {bool} [bShowGlobal=true] Show the input global filter in it's input box(es)
5332 * @param {bool} [bCaseInsensitive=true] Do case-insensitive matching (true) or not (false)
5336 * $(document).ready(function() {
5337 * var oTable = $('#example').dataTable();
5339 * // Sometime later - filter...
5340 * oTable.fnFilter( 'test string' );
5343 this.fnFilter = function( sInput, iColumn, bRegex, bSmart, bShowGlobal, bCaseInsensitive )
5345 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5347 if ( !oSettings.oFeatures.bFilter )
5352 if ( bRegex === undefined || bRegex === null )
5357 if ( bSmart === undefined || bSmart === null )
5362 if ( bShowGlobal === undefined || bShowGlobal === null )
5367 if ( bCaseInsensitive === undefined || bCaseInsensitive === null )
5369 bCaseInsensitive = true;
5372 if ( iColumn === undefined || iColumn === null )
5375 _fnFilterComplete( oSettings, {
5376 "sSearch":sInput+"",
5379 "bCaseInsensitive": bCaseInsensitive
5382 if ( bShowGlobal && oSettings.aanFeatures.f )
5384 var n = oSettings.aanFeatures.f;
5385 for ( var i=0, iLen=n.length ; i<iLen ; i++ )
5387 $('input', n[i]).val( sInput );
5393 /* Single column filter */
5394 $.extend( oSettings.aoPreSearchCols[ iColumn ], {
5395 "sSearch": sInput+"",
5398 "bCaseInsensitive": bCaseInsensitive
5400 _fnFilterComplete( oSettings, oSettings.oPreviousSearch, 1 );
5406 * Get the data for the whole table, an individual row or an individual cell based on the
5407 * provided parameters.
5408 * @param {int|node} [mRow] A TR row node, TD/TH cell node or an integer. If given as
5409 * a TR node then the data source for the whole row will be returned. If given as a
5410 * TD/TH cell node then iCol will be automatically calculated and the data for the
5411 * cell returned. If given as an integer, then this is treated as the aoData internal
5412 * data index for the row (see fnGetPosition) and the data for that row used.
5413 * @param {int} [iCol] Optional column index that you want the data of.
5414 * @returns {array|object|string} If mRow is undefined, then the data for all rows is
5415 * returned. If mRow is defined, just data for that row, and is iCol is
5416 * defined, only data for the designated cell is returned.
5421 * $(document).ready(function() {
5422 * oTable = $('#example').dataTable();
5424 * oTable.$('tr').click( function () {
5425 * var data = oTable.fnGetData( this );
5426 * // ... do something with the array / object of data for the row
5431 * // Individual cell data
5432 * $(document).ready(function() {
5433 * oTable = $('#example').dataTable();
5435 * oTable.$('td').click( function () {
5436 * var sData = oTable.fnGetData( this );
5437 * alert( 'The cell clicked on had the value of '+sData );
5441 this.fnGetData = function( mRow, iCol )
5443 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5445 if ( mRow !== undefined )
5448 if ( typeof mRow === 'object' )
5450 var sNode = mRow.nodeName.toLowerCase();
5451 if (sNode === "tr" )
5453 iRow = _fnNodeToDataIndex(oSettings, mRow);
5455 else if ( sNode === "td" )
5457 iRow = _fnNodeToDataIndex(oSettings, mRow.parentNode);
5458 iCol = _fnNodeToColumnIndex( oSettings, iRow, mRow );
5462 if ( iCol !== undefined )
5464 return _fnGetCellData( oSettings, iRow, iCol, '' );
5466 return (oSettings.aoData[iRow]!==undefined) ?
5467 oSettings.aoData[iRow]._aData : null;
5469 return _fnGetDataMaster( oSettings );
5474 * Get an array of the TR nodes that are used in the table's body. Note that you will
5475 * typically want to use the '$' API method in preference to this as it is more
5477 * @param {int} [iRow] Optional row index for the TR element you want
5478 * @returns {array|node} If iRow is undefined, returns an array of all TR elements
5479 * in the table's body, or iRow is defined, just the TR element requested.
5483 * $(document).ready(function() {
5484 * var oTable = $('#example').dataTable();
5486 * // Get the nodes from the table
5487 * var nNodes = oTable.fnGetNodes( );
5490 this.fnGetNodes = function( iRow )
5492 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5494 if ( iRow !== undefined ) {
5495 return (oSettings.aoData[iRow]!==undefined) ?
5496 oSettings.aoData[iRow].nTr : null;
5498 return _fnGetTrNodes( oSettings );
5503 * Get the array indexes of a particular cell from it's DOM element
5504 * and column index including hidden columns
5505 * @param {node} nNode this can either be a TR, TD or TH in the table's body
5506 * @returns {int} If nNode is given as a TR, then a single index is returned, or
5507 * if given as a cell, an array of [row index, column index (visible)] is given.
5511 * $(document).ready(function() {
5512 * $('#example tbody td').click( function () {
5513 * // Get the position of the current data from the node
5514 * var aPos = oTable.fnGetPosition( this );
5516 * // Get the data array for this row
5517 * var aData = oTable.fnGetData( aPos[0] );
5519 * // Update the data array and return the value
5520 * aData[ aPos[1] ] = 'clicked';
5521 * this.innerHTML = 'clicked';
5524 * // Init DataTables
5525 * oTable = $('#example').dataTable();
5528 this.fnGetPosition = function( nNode )
5530 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5531 var sNodeName = nNode.nodeName.toUpperCase();
5533 if ( sNodeName == "TR" )
5535 return _fnNodeToDataIndex(oSettings, nNode);
5537 else if ( sNodeName == "TD" || sNodeName == "TH" )
5539 var iDataIndex = _fnNodeToDataIndex( oSettings, nNode.parentNode );
5540 var iColumnIndex = _fnNodeToColumnIndex( oSettings, iDataIndex, nNode );
5541 return [ iDataIndex, _fnColumnIndexToVisible(oSettings, iColumnIndex ), iColumnIndex ];
5548 * Check to see if a row is 'open' or not.
5549 * @param {node} nTr the table row to check
5550 * @returns {boolean} true if the row is currently open, false otherwise
5554 * $(document).ready(function() {
5557 * // 'open' an information row when a row is clicked on
5558 * $('#example tbody tr').click( function () {
5559 * if ( oTable.fnIsOpen(this) ) {
5560 * oTable.fnClose( this );
5562 * oTable.fnOpen( this, "Temporary row opened", "info_row" );
5566 * oTable = $('#example').dataTable();
5569 this.fnIsOpen = function( nTr )
5571 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5572 var aoOpenRows = oSettings.aoOpenRows;
5574 for ( var i=0 ; i<oSettings.aoOpenRows.length ; i++ )
5576 if ( oSettings.aoOpenRows[i].nParent == nTr )
5586 * This function will place a new row directly after a row which is currently
5587 * on display on the page, with the HTML contents that is passed into the
5588 * function. This can be used, for example, to ask for confirmation that a
5589 * particular record should be deleted.
5590 * @param {node} nTr The table row to 'open'
5591 * @param {string|node|jQuery} mHtml The HTML to put into the row
5592 * @param {string} sClass Class to give the new TD cell
5593 * @returns {node} The row opened. Note that if the table row passed in as the
5594 * first parameter, is not found in the table, this method will silently
5599 * $(document).ready(function() {
5602 * // 'open' an information row when a row is clicked on
5603 * $('#example tbody tr').click( function () {
5604 * if ( oTable.fnIsOpen(this) ) {
5605 * oTable.fnClose( this );
5607 * oTable.fnOpen( this, "Temporary row opened", "info_row" );
5611 * oTable = $('#example').dataTable();
5614 this.fnOpen = function( nTr, mHtml, sClass )
5616 /* Find settings from table node */
5617 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5619 /* Check that the row given is in the table */
5620 var nTableRows = _fnGetTrNodes( oSettings );
5621 if ( $.inArray(nTr, nTableRows) === -1 )
5626 /* the old open one if there is one */
5627 this.fnClose( nTr );
5629 var nNewRow = document.createElement("tr");
5630 var nNewCell = document.createElement("td");
5631 nNewRow.appendChild( nNewCell );
5632 nNewCell.className = sClass;
5633 nNewCell.colSpan = _fnVisbleColumns( oSettings );
5635 if (typeof mHtml === "string")
5637 nNewCell.innerHTML = mHtml;
5641 $(nNewCell).html( mHtml );
5644 /* If the nTr isn't on the page at the moment - then we don't insert at the moment */
5645 var nTrs = $('tr', oSettings.nTBody);
5646 if ( $.inArray(nTr, nTrs) != -1 )
5648 $(nNewRow).insertAfter(nTr);
5651 oSettings.aoOpenRows.push( {
5661 * Change the pagination - provides the internal logic for pagination in a simple API
5662 * function. With this function you can have a DataTables table go to the next,
5663 * previous, first or last pages.
5664 * @param {string|int} mAction Paging action to take: "first", "previous", "next" or "last"
5665 * or page number to jump to (integer), note that page 0 is the first page.
5666 * @param {bool} [bRedraw=true] Redraw the table or not
5670 * $(document).ready(function() {
5671 * var oTable = $('#example').dataTable();
5672 * oTable.fnPageChange( 'next' );
5675 this.fnPageChange = function ( mAction, bRedraw )
5677 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5678 _fnPageChange( oSettings, mAction );
5679 _fnCalculateEnd( oSettings );
5681 if ( bRedraw === undefined || bRedraw )
5683 _fnDraw( oSettings );
5689 * Show a particular column
5690 * @param {int} iCol The column whose display should be changed
5691 * @param {bool} bShow Show (true) or hide (false) the column
5692 * @param {bool} [bRedraw=true] Redraw the table or not
5696 * $(document).ready(function() {
5697 * var oTable = $('#example').dataTable();
5699 * // Hide the second column after initialisation
5700 * oTable.fnSetColumnVis( 1, false );
5703 this.fnSetColumnVis = function ( iCol, bShow, bRedraw )
5705 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5707 var aoColumns = oSettings.aoColumns;
5708 var aoData = oSettings.aoData;
5709 var nTd, nCell, anTrs, jqChildren, bAppend, iBefore;
5711 /* No point in doing anything if we are requesting what is already true */
5712 if ( aoColumns[iCol].bVisible == bShow )
5717 /* Show the column */
5721 for ( i=0 ; i<iCol ; i++ )
5723 if ( aoColumns[i].bVisible )
5729 /* Need to decide if we should use appendChild or insertBefore */
5730 bAppend = (iInsert >= _fnVisbleColumns( oSettings ));
5732 /* Which coloumn should we be inserting before? */
5735 for ( i=iCol ; i<aoColumns.length ; i++ )
5737 if ( aoColumns[i].bVisible )
5745 for ( i=0, iLen=aoData.length ; i<iLen ; i++ )
5747 if ( aoData[i].nTr !== null )
5751 aoData[i].nTr.appendChild(
5752 aoData[i]._anHidden[iCol]
5757 aoData[i].nTr.insertBefore(
5758 aoData[i]._anHidden[iCol],
5759 _fnGetTdNodes( oSettings, i )[iBefore] );
5766 /* Remove a column from display */
5767 for ( i=0, iLen=aoData.length ; i<iLen ; i++ )
5769 if ( aoData[i].nTr !== null )
5771 nTd = _fnGetTdNodes( oSettings, i )[iCol];
5772 aoData[i]._anHidden[iCol] = nTd;
5773 nTd.parentNode.removeChild( nTd );
5778 /* Clear to set the visible flag */
5779 aoColumns[iCol].bVisible = bShow;
5781 /* Redraw the header and footer based on the new column visibility */
5782 _fnDrawHead( oSettings, oSettings.aoHeader );
5783 if ( oSettings.nTFoot )
5785 _fnDrawHead( oSettings, oSettings.aoFooter );
5788 /* If there are any 'open' rows, then we need to alter the colspan for this col change */
5789 for ( i=0, iLen=oSettings.aoOpenRows.length ; i<iLen ; i++ )
5791 oSettings.aoOpenRows[i].nTr.colSpan = _fnVisbleColumns( oSettings );
5794 /* Do a redraw incase anything depending on the table columns needs it
5795 * (built-in: scrolling)
5797 if ( bRedraw === undefined || bRedraw )
5799 _fnAdjustColumnSizing( oSettings );
5800 _fnDraw( oSettings );
5803 _fnSaveState( oSettings );
5808 * Get the settings for a particular table for external manipulation
5809 * @returns {object} DataTables settings object. See
5810 * {@link DataTable.models.oSettings}
5814 * $(document).ready(function() {
5815 * var oTable = $('#example').dataTable();
5816 * var oSettings = oTable.fnSettings();
5818 * // Show an example parameter from the settings
5819 * alert( oSettings._iDisplayStart );
5822 this.fnSettings = function()
5824 return _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5829 * Sort the table by a particular row
5830 * @param {int} iCol the data index to sort on. Note that this will not match the
5831 * 'display index' if you have hidden data entries
5835 * $(document).ready(function() {
5836 * var oTable = $('#example').dataTable();
5838 * // Sort immediately with columns 0 and 1
5839 * oTable.fnSort( [ [0,'asc'], [1,'asc'] ] );
5842 this.fnSort = function( aaSort )
5844 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5845 oSettings.aaSorting = aaSort;
5846 _fnSort( oSettings );
5851 * Attach a sort listener to an element for a given column
5852 * @param {node} nNode the element to attach the sort listener to
5853 * @param {int} iColumn the column that a click on this node will sort on
5854 * @param {function} [fnCallback] callback function when sort is run
5858 * $(document).ready(function() {
5859 * var oTable = $('#example').dataTable();
5861 * // Sort on column 1, when 'sorter' is clicked on
5862 * oTable.fnSortListener( document.getElementById('sorter'), 1 );
5865 this.fnSortListener = function( nNode, iColumn, fnCallback )
5867 _fnSortAttachListener( _fnSettingsFromNode( this[DataTable.ext.iApiIndex] ), nNode, iColumn,
5873 * Update a table cell or row - this method will accept either a single value to
5874 * update the cell with, an array of values with one element for each column or
5875 * an object in the same format as the original data source. The function is
5876 * self-referencing in order to make the multi column updates easier.
5877 * @param {object|array|string} mData Data to update the cell/row with
5878 * @param {node|int} mRow TR element you want to update or the aoData index
5879 * @param {int} [iColumn] The column to update (not used of mData is an array or object)
5880 * @param {bool} [bRedraw=true] Redraw the table or not
5881 * @param {bool} [bAction=true] Perform predraw actions or not
5882 * @returns {int} 0 on success, 1 on error
5886 * $(document).ready(function() {
5887 * var oTable = $('#example').dataTable();
5888 * oTable.fnUpdate( 'Example update', 0, 0 ); // Single cell
5889 * oTable.fnUpdate( ['a', 'b', 'c', 'd', 'e'], 1, 0 ); // Row
5892 this.fnUpdate = function( mData, mRow, iColumn, bRedraw, bAction )
5894 var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
5895 var iVisibleColumn, i, iLen, sDisplay;
5896 var iRow = (typeof mRow === 'object') ?
5897 _fnNodeToDataIndex(oSettings, mRow) : mRow;
5899 if ( oSettings.__fnUpdateDeep === undefined && $.isArray(mData) && typeof mData === 'object' )
5901 /* Array update - update the whole row */
5902 oSettings.aoData[iRow]._aData = mData.slice();
5904 /* Flag to the function that we are recursing */
5905 oSettings.__fnUpdateDeep = true;
5906 for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
5908 this.fnUpdate( _fnGetCellData( oSettings, iRow, i ), iRow, i, false, false );
5910 oSettings.__fnUpdateDeep = undefined;
5912 else if ( oSettings.__fnUpdateDeep === undefined && mData !== null && typeof mData === 'object' )
5914 /* Object update - update the whole row - assume the developer gets the object right */
5915 oSettings.aoData[iRow]._aData = $.extend( true, {}, mData );
5917 oSettings.__fnUpdateDeep = true;
5918 for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
5920 this.fnUpdate( _fnGetCellData( oSettings, iRow, i ), iRow, i, false, false );
5922 oSettings.__fnUpdateDeep = undefined;
5926 /* Individual cell update */
5927 _fnSetCellData( oSettings, iRow, iColumn, mData );
5928 sDisplay = _fnGetCellData( oSettings, iRow, iColumn, 'display' );
5930 var oCol = oSettings.aoColumns[iColumn];
5931 if ( oCol.fnRender !== null )
5933 sDisplay = _fnRender( oSettings, iRow, iColumn );
5934 if ( oCol.bUseRendered )
5936 _fnSetCellData( oSettings, iRow, iColumn, sDisplay );
5940 if ( oSettings.aoData[iRow].nTr !== null )
5942 /* Do the actual HTML update */
5943 _fnGetTdNodes( oSettings, iRow )[iColumn].innerHTML = sDisplay;
5947 /* Modify the search index for this row (strictly this is likely not needed, since fnReDraw
5948 * will rebuild the search array - however, the redraw might be disabled by the user)
5950 var iDisplayIndex = $.inArray( iRow, oSettings.aiDisplay );
5951 oSettings.asDataSearch[iDisplayIndex] = _fnBuildSearchRow( oSettings,
5952 _fnGetRowData( oSettings, iRow, 'filter' ) );
5954 /* Perform pre-draw actions */
5955 if ( bAction === undefined || bAction )
5957 _fnAdjustColumnSizing( oSettings );
5960 /* Redraw the table */
5961 if ( bRedraw === undefined || bRedraw )
5963 _fnReDraw( oSettings );
5970 * Provide a common method for plug-ins to check the version of DataTables being used, in order
5971 * to ensure compatibility.
5972 * @param {string} sVersion Version string to check for, in the format "X.Y.Z". Note that the
5973 * formats "X" and "X.Y" are also acceptable.
5974 * @returns {boolean} true if this version of DataTables is greater or equal to the required
5975 * version, or false if this version of DataTales is not suitable
5980 * $(document).ready(function() {
5981 * var oTable = $('#example').dataTable();
5982 * alert( oTable.fnVersionCheck( '1.9.0' ) );
5985 this.fnVersionCheck = DataTable.ext.fnVersionCheck;
5989 * This is really a good bit rubbish this method of exposing the internal methods
5990 * publically... - To be fixed in 2.0 using methods on the prototype
5995 * Create a wrapper function for exporting an internal functions to an external API.
5996 * @param {string} sFunc API function name
5997 * @returns {function} wrapped function
5998 * @memberof DataTable#oApi
6000 function _fnExternApiFunc (sFunc)
6003 var aArgs = [_fnSettingsFromNode(this[DataTable.ext.iApiIndex])].concat(
6004 Array.prototype.slice.call(arguments) );
6005 return DataTable.ext.oApi[sFunc].apply( this, aArgs );
6011 * Reference to internal functions for use by plug-in developers. Note that these
6012 * methods are references to internal functions and are considered to be private.
6013 * If you use these methods, be aware that they are liable to change between versions
6014 * (check the upgrade notes).
6018 "_fnExternApiFunc": _fnExternApiFunc,
6019 "_fnInitialise": _fnInitialise,
6020 "_fnInitComplete": _fnInitComplete,
6021 "_fnLanguageCompat": _fnLanguageCompat,
6022 "_fnAddColumn": _fnAddColumn,
6023 "_fnColumnOptions": _fnColumnOptions,
6024 "_fnAddData": _fnAddData,
6025 "_fnCreateTr": _fnCreateTr,
6026 "_fnGatherData": _fnGatherData,
6027 "_fnBuildHead": _fnBuildHead,
6028 "_fnDrawHead": _fnDrawHead,
6030 "_fnReDraw": _fnReDraw,
6031 "_fnAjaxUpdate": _fnAjaxUpdate,
6032 "_fnAjaxParameters": _fnAjaxParameters,
6033 "_fnAjaxUpdateDraw": _fnAjaxUpdateDraw,
6034 "_fnServerParams": _fnServerParams,
6035 "_fnAddOptionsHtml": _fnAddOptionsHtml,
6036 "_fnFeatureHtmlTable": _fnFeatureHtmlTable,
6037 "_fnScrollDraw": _fnScrollDraw,
6038 "_fnAdjustColumnSizing": _fnAdjustColumnSizing,
6039 "_fnFeatureHtmlFilter": _fnFeatureHtmlFilter,
6040 "_fnFilterComplete": _fnFilterComplete,
6041 "_fnFilterCustom": _fnFilterCustom,
6042 "_fnFilterColumn": _fnFilterColumn,
6043 "_fnFilter": _fnFilter,
6044 "_fnBuildSearchArray": _fnBuildSearchArray,
6045 "_fnBuildSearchRow": _fnBuildSearchRow,
6046 "_fnFilterCreateSearch": _fnFilterCreateSearch,
6047 "_fnDataToSearch": _fnDataToSearch,
6049 "_fnSortAttachListener": _fnSortAttachListener,
6050 "_fnSortingClasses": _fnSortingClasses,
6051 "_fnFeatureHtmlPaginate": _fnFeatureHtmlPaginate,
6052 "_fnPageChange": _fnPageChange,
6053 "_fnFeatureHtmlInfo": _fnFeatureHtmlInfo,
6054 "_fnUpdateInfo": _fnUpdateInfo,
6055 "_fnFeatureHtmlLength": _fnFeatureHtmlLength,
6056 "_fnFeatureHtmlProcessing": _fnFeatureHtmlProcessing,
6057 "_fnProcessingDisplay": _fnProcessingDisplay,
6058 "_fnVisibleToColumnIndex": _fnVisibleToColumnIndex,
6059 "_fnColumnIndexToVisible": _fnColumnIndexToVisible,
6060 "_fnNodeToDataIndex": _fnNodeToDataIndex,
6061 "_fnVisbleColumns": _fnVisbleColumns,
6062 "_fnCalculateEnd": _fnCalculateEnd,
6063 "_fnConvertToWidth": _fnConvertToWidth,
6064 "_fnCalculateColumnWidths": _fnCalculateColumnWidths,
6065 "_fnScrollingWidthAdjust": _fnScrollingWidthAdjust,
6066 "_fnGetWidestNode": _fnGetWidestNode,
6067 "_fnGetMaxLenString": _fnGetMaxLenString,
6068 "_fnStringToCss": _fnStringToCss,
6069 "_fnDetectType": _fnDetectType,
6070 "_fnSettingsFromNode": _fnSettingsFromNode,
6071 "_fnGetDataMaster": _fnGetDataMaster,
6072 "_fnGetTrNodes": _fnGetTrNodes,
6073 "_fnGetTdNodes": _fnGetTdNodes,
6074 "_fnEscapeRegex": _fnEscapeRegex,
6075 "_fnDeleteIndex": _fnDeleteIndex,
6076 "_fnReOrderIndex": _fnReOrderIndex,
6077 "_fnColumnOrdering": _fnColumnOrdering,
6079 "_fnClearTable": _fnClearTable,
6080 "_fnSaveState": _fnSaveState,
6081 "_fnLoadState": _fnLoadState,
6082 "_fnCreateCookie": _fnCreateCookie,
6083 "_fnReadCookie": _fnReadCookie,
6084 "_fnDetectHeader": _fnDetectHeader,
6085 "_fnGetUniqueThs": _fnGetUniqueThs,
6086 "_fnScrollBarWidth": _fnScrollBarWidth,
6087 "_fnApplyToChildren": _fnApplyToChildren,
6089 "_fnGetRowData": _fnGetRowData,
6090 "_fnGetCellData": _fnGetCellData,
6091 "_fnSetCellData": _fnSetCellData,
6092 "_fnGetObjectDataFn": _fnGetObjectDataFn,
6093 "_fnSetObjectDataFn": _fnSetObjectDataFn,
6094 "_fnApplyColumnDefs": _fnApplyColumnDefs,
6095 "_fnBindAction": _fnBindAction,
6096 "_fnExtend": _fnExtend,
6097 "_fnCallbackReg": _fnCallbackReg,
6098 "_fnCallbackFire": _fnCallbackFire,
6099 "_fnJsonString": _fnJsonString,
6100 "_fnRender": _fnRender,
6101 "_fnNodeToColumnIndex": _fnNodeToColumnIndex
6104 $.extend( DataTable.ext.oApi, this.oApi );
6106 for ( var sFunc in DataTable.ext.oApi )
6110 this[sFunc] = _fnExternApiFunc(sFunc);
6116 return this.each(function() {
6118 var i=0, iLen, j, jLen, k, kLen;
6119 var sId = this.getAttribute( 'id' );
6120 var bInitHandedOff = false;
6121 var bUsePassedData = false;
6125 if ( this.nodeName.toLowerCase() != 'table' )
6127 _fnLog( null, 0, "Attempted to initialise DataTables on a node which is not a "+
6128 "table: "+this.nodeName );
6132 /* Check to see if we are re-initialising a table */
6133 for ( i=0, iLen=DataTable.settings.length ; i<iLen ; i++ )
6135 /* Base check on table node */
6136 if ( DataTable.settings[i].nTable == this )
6138 if ( oInit === undefined || oInit.bRetrieve )
6140 return DataTable.settings[i].oInstance;
6142 else if ( oInit.bDestroy )
6144 DataTable.settings[i].oInstance.fnDestroy();
6149 _fnLog( DataTable.settings[i], 0, "Cannot reinitialise DataTable.\n\n"+
6150 "To retrieve the DataTables object for this table, pass no arguments or see "+
6151 "the docs for bRetrieve and bDestroy" );
6156 /* If the element we are initialising has the same ID as a table which was previously
6157 * initialised, but the table nodes don't match (from before) then we destroy the old
6158 * instance by simply deleting it. This is under the assumption that the table has been
6159 * destroyed by other methods. Anyone using non-id selectors will need to do this manually
6161 if ( DataTable.settings[i].sTableId == this.id )
6163 DataTable.settings.splice( i, 1 );
6168 /* Ensure the table has an ID - required for accessibility */
6171 sId = "DataTables_Table_"+(DataTable.ext._oExternConfig.iNextUnique++);
6175 /* Create the settings object for this table and set some of the default parameters */
6176 var oSettings = $.extend( true, {}, DataTable.models.oSettings, {
6180 "sDestroyWidth": $(this).width(),
6184 DataTable.settings.push( oSettings );
6186 // Need to add the instance after the instance after the settings object has been added
6187 // to the settings array, so we can self reference the table instance if more than one
6188 oSettings.oInstance = (_that.length===1) ? _that : $(this).dataTable();
6190 /* Setting up the initialisation object */
6196 // Backwards compatibility, before we apply all the defaults
6197 if ( oInit.oLanguage )
6199 _fnLanguageCompat( oInit.oLanguage );
6202 oInit = _fnExtend( $.extend(true, {}, DataTable.defaults), oInit );
6204 // Map the initialisation options onto the settings object
6205 _fnMap( oSettings.oFeatures, oInit, "bPaginate" );
6206 _fnMap( oSettings.oFeatures, oInit, "bLengthChange" );
6207 _fnMap( oSettings.oFeatures, oInit, "bFilter" );
6208 _fnMap( oSettings.oFeatures, oInit, "bSort" );
6209 _fnMap( oSettings.oFeatures, oInit, "bInfo" );
6210 _fnMap( oSettings.oFeatures, oInit, "bProcessing" );
6211 _fnMap( oSettings.oFeatures, oInit, "bAutoWidth" );
6212 _fnMap( oSettings.oFeatures, oInit, "bSortClasses" );
6213 _fnMap( oSettings.oFeatures, oInit, "bServerSide" );
6214 _fnMap( oSettings.oFeatures, oInit, "bDeferRender" );
6215 _fnMap( oSettings.oScroll, oInit, "sScrollX", "sX" );
6216 _fnMap( oSettings.oScroll, oInit, "sScrollXInner", "sXInner" );
6217 _fnMap( oSettings.oScroll, oInit, "sScrollY", "sY" );
6218 _fnMap( oSettings.oScroll, oInit, "bScrollCollapse", "bCollapse" );
6219 _fnMap( oSettings.oScroll, oInit, "bScrollInfinite", "bInfinite" );
6220 _fnMap( oSettings.oScroll, oInit, "iScrollLoadGap", "iLoadGap" );
6221 _fnMap( oSettings.oScroll, oInit, "bScrollAutoCss", "bAutoCss" );
6222 _fnMap( oSettings, oInit, "asStripClasses", "asStripeClasses" ); // legacy
6223 _fnMap( oSettings, oInit, "asStripeClasses" );
6224 _fnMap( oSettings, oInit, "fnServerData" );
6225 _fnMap( oSettings, oInit, "fnFormatNumber" );
6226 _fnMap( oSettings, oInit, "sServerMethod" );
6227 _fnMap( oSettings, oInit, "aaSorting" );
6228 _fnMap( oSettings, oInit, "aaSortingFixed" );
6229 _fnMap( oSettings, oInit, "aLengthMenu" );
6230 _fnMap( oSettings, oInit, "sPaginationType" );
6231 _fnMap( oSettings, oInit, "sAjaxSource" );
6232 _fnMap( oSettings, oInit, "sAjaxDataProp" );
6233 _fnMap( oSettings, oInit, "iCookieDuration" );
6234 _fnMap( oSettings, oInit, "sCookiePrefix" );
6235 _fnMap( oSettings, oInit, "sDom" );
6236 _fnMap( oSettings, oInit, "bSortCellsTop" );
6237 _fnMap( oSettings, oInit, "iTabIndex" );
6238 _fnMap( oSettings, oInit, "oSearch", "oPreviousSearch" );
6239 _fnMap( oSettings, oInit, "aoSearchCols", "aoPreSearchCols" );
6240 _fnMap( oSettings, oInit, "iDisplayLength", "_iDisplayLength" );
6241 _fnMap( oSettings, oInit, "bJQueryUI", "bJUI" );
6242 _fnMap( oSettings, oInit, "fnCookieCallback" );
6243 _fnMap( oSettings, oInit, "fnStateLoad" );
6244 _fnMap( oSettings, oInit, "fnStateSave" );
6245 _fnMap( oSettings.oLanguage, oInit, "fnInfoCallback" );
6247 /* Callback functions which are array driven */
6248 _fnCallbackReg( oSettings, 'aoDrawCallback', oInit.fnDrawCallback, 'user' );
6249 _fnCallbackReg( oSettings, 'aoServerParams', oInit.fnServerParams, 'user' );
6250 _fnCallbackReg( oSettings, 'aoStateSaveParams', oInit.fnStateSaveParams, 'user' );
6251 _fnCallbackReg( oSettings, 'aoStateLoadParams', oInit.fnStateLoadParams, 'user' );
6252 _fnCallbackReg( oSettings, 'aoStateLoaded', oInit.fnStateLoaded, 'user' );
6253 _fnCallbackReg( oSettings, 'aoRowCallback', oInit.fnRowCallback, 'user' );
6254 _fnCallbackReg( oSettings, 'aoRowCreatedCallback', oInit.fnCreatedRow, 'user' );
6255 _fnCallbackReg( oSettings, 'aoHeaderCallback', oInit.fnHeaderCallback, 'user' );
6256 _fnCallbackReg( oSettings, 'aoFooterCallback', oInit.fnFooterCallback, 'user' );
6257 _fnCallbackReg( oSettings, 'aoInitComplete', oInit.fnInitComplete, 'user' );
6258 _fnCallbackReg( oSettings, 'aoPreDrawCallback', oInit.fnPreDrawCallback, 'user' );
6260 if ( oSettings.oFeatures.bServerSide && oSettings.oFeatures.bSort &&
6261 oSettings.oFeatures.bSortClasses )
6263 /* Enable sort classes for server-side processing. Safe to do it here, since server-side
6264 * processing must be enabled by the developer
6266 _fnCallbackReg( oSettings, 'aoDrawCallback', _fnSortingClasses, 'server_side_sort_classes' );
6268 else if ( oSettings.oFeatures.bDeferRender )
6270 _fnCallbackReg( oSettings, 'aoDrawCallback', _fnSortingClasses, 'defer_sort_classes' );
6273 if ( oInit.bJQueryUI )
6275 /* Use the JUI classes object for display. You could clone the oStdClasses object if
6276 * you want to have multiple tables with multiple independent classes
6278 $.extend( oSettings.oClasses, DataTable.ext.oJUIClasses );
6280 if ( oInit.sDom === DataTable.defaults.sDom && DataTable.defaults.sDom === "lfrtip" )
6282 /* Set the DOM to use a layout suitable for jQuery UI's theming */
6283 oSettings.sDom = '<"H"lfr>t<"F"ip>';
6288 $.extend( oSettings.oClasses, DataTable.ext.oStdClasses );
6290 $(this).addClass( oSettings.oClasses.sTable );
6292 /* Calculate the scroll bar width and cache it for use later on */
6293 if ( oSettings.oScroll.sX !== "" || oSettings.oScroll.sY !== "" )
6295 oSettings.oScroll.iBarWidth = _fnScrollBarWidth();
6298 if ( oSettings.iInitDisplayStart === undefined )
6300 /* Display start point, taking into account the save saving */
6301 oSettings.iInitDisplayStart = oInit.iDisplayStart;
6302 oSettings._iDisplayStart = oInit.iDisplayStart;
6305 /* Must be done after everything which can be overridden by a cookie! */
6306 if ( oInit.bStateSave )
6308 oSettings.oFeatures.bStateSave = true;
6309 _fnLoadState( oSettings, oInit );
6310 _fnCallbackReg( oSettings, 'aoDrawCallback', _fnSaveState, 'state_save' );
6313 if ( oInit.iDeferLoading !== null )
6315 oSettings.bDeferLoading = true;
6316 oSettings._iRecordsTotal = oInit.iDeferLoading;
6317 oSettings._iRecordsDisplay = oInit.iDeferLoading;
6320 if ( oInit.aaData !== null )
6322 bUsePassedData = true;
6325 /* Language definitions */
6326 if ( oInit.oLanguage.sUrl !== "" )
6328 /* Get the language definitions from a file - because this Ajax call makes the language
6329 * get async to the remainder of this function we use bInitHandedOff to indicate that
6330 * _fnInitialise will be fired by the returned Ajax handler, rather than the constructor
6332 oSettings.oLanguage.sUrl = oInit.oLanguage.sUrl;
6333 $.getJSON( oSettings.oLanguage.sUrl, null, function( json ) {
6334 _fnLanguageCompat( json );
6335 $.extend( true, oSettings.oLanguage, oInit.oLanguage, json );
6336 _fnInitialise( oSettings );
6338 bInitHandedOff = true;
6342 $.extend( true, oSettings.oLanguage, oInit.oLanguage );
6350 /* Remove row stripe classes if they are already on the table row */
6351 var bStripeRemove = false;
6352 var anRows = $(this).children('tbody').children('tr');
6353 for ( i=0, iLen=oSettings.asStripeClasses.length ; i<iLen ; i++ )
6355 if ( anRows.filter(":lt(2)").hasClass( oSettings.asStripeClasses[i]) )
6357 bStripeRemove = true;
6362 if ( bStripeRemove )
6364 /* Store the classes which we are about to remove so they can be readded on destroy */
6365 oSettings.asDestroyStripes = [ '', '' ];
6366 if ( $(anRows[0]).hasClass(oSettings.oClasses.sStripeOdd) )
6368 oSettings.asDestroyStripes[0] += oSettings.oClasses.sStripeOdd+" ";
6370 if ( $(anRows[0]).hasClass(oSettings.oClasses.sStripeEven) )
6372 oSettings.asDestroyStripes[0] += oSettings.oClasses.sStripeEven;
6374 if ( $(anRows[1]).hasClass(oSettings.oClasses.sStripeOdd) )
6376 oSettings.asDestroyStripes[1] += oSettings.oClasses.sStripeOdd+" ";
6378 if ( $(anRows[1]).hasClass(oSettings.oClasses.sStripeEven) )
6380 oSettings.asDestroyStripes[1] += oSettings.oClasses.sStripeEven;
6383 anRows.removeClass( oSettings.asStripeClasses.join(' ') );
6389 * See if we should load columns automatically or use defined ones
6393 var nThead = this.getElementsByTagName('thead');
6394 if ( nThead.length !== 0 )
6396 _fnDetectHeader( oSettings.aoHeader, nThead[0] );
6397 anThs = _fnGetUniqueThs( oSettings );
6400 /* If not given a column array, generate one with nulls */
6401 if ( oInit.aoColumns === null )
6404 for ( i=0, iLen=anThs.length ; i<iLen ; i++ )
6406 aoColumnsInit.push( null );
6411 aoColumnsInit = oInit.aoColumns;
6414 /* Add the columns */
6415 for ( i=0, iLen=aoColumnsInit.length ; i<iLen ; i++ )
6417 /* Short cut - use the loop to check if we have column visibility state to restore */
6418 if ( oInit.saved_aoColumns !== undefined && oInit.saved_aoColumns.length == iLen )
6420 if ( aoColumnsInit[i] === null )
6422 aoColumnsInit[i] = {};
6424 aoColumnsInit[i].bVisible = oInit.saved_aoColumns[i].bVisible;
6427 _fnAddColumn( oSettings, anThs ? anThs[i] : null );
6430 /* Apply the column definitions */
6431 _fnApplyColumnDefs( oSettings, oInit.aoColumnDefs, aoColumnsInit, function (iCol, oDef) {
6432 _fnColumnOptions( oSettings, iCol, oDef );
6438 * Check the aaSorting array
6440 for ( i=0, iLen=oSettings.aaSorting.length ; i<iLen ; i++ )
6442 if ( oSettings.aaSorting[i][0] >= oSettings.aoColumns.length )
6444 oSettings.aaSorting[i][0] = 0;
6446 var oColumn = oSettings.aoColumns[ oSettings.aaSorting[i][0] ];
6448 /* Add a default sorting index */
6449 if ( oSettings.aaSorting[i][2] === undefined )
6451 oSettings.aaSorting[i][2] = 0;
6454 /* If aaSorting is not defined, then we use the first indicator in asSorting */
6455 if ( oInit.aaSorting === undefined && oSettings.saved_aaSorting === undefined )
6457 oSettings.aaSorting[i][1] = oColumn.asSorting[0];
6460 /* Set the current sorting index based on aoColumns.asSorting */
6461 for ( j=0, jLen=oColumn.asSorting.length ; j<jLen ; j++ )
6463 if ( oSettings.aaSorting[i][1] == oColumn.asSorting[j] )
6465 oSettings.aaSorting[i][2] = j;
6471 /* Do a first pass on the sorting classes (allows any size changes to be taken into
6472 * account, and also will apply sorting disabled classes if disabled
6474 _fnSortingClasses( oSettings );
6479 * Cache the header, body and footer as required, creating them if needed
6481 var thead = $(this).children('thead');
6482 if ( thead.length === 0 )
6484 thead = [ document.createElement( 'thead' ) ];
6485 this.appendChild( thead[0] );
6487 oSettings.nTHead = thead[0];
6489 var tbody = $(this).children('tbody');
6490 if ( tbody.length === 0 )
6492 tbody = [ document.createElement( 'tbody' ) ];
6493 this.appendChild( tbody[0] );
6495 oSettings.nTBody = tbody[0];
6496 oSettings.nTBody.setAttribute( "role", "alert" );
6497 oSettings.nTBody.setAttribute( "aria-live", "polite" );
6498 oSettings.nTBody.setAttribute( "aria-relevant", "all" );
6500 var tfoot = $(this).children('tfoot');
6501 if ( tfoot.length > 0 )
6503 oSettings.nTFoot = tfoot[0];
6504 _fnDetectHeader( oSettings.aoFooter, oSettings.nTFoot );
6507 /* Check if there is data passing into the constructor */
6508 if ( bUsePassedData )
6510 for ( i=0 ; i<oInit.aaData.length ; i++ )
6512 _fnAddData( oSettings, oInit.aaData[ i ] );
6517 /* Grab the data from the page */
6518 _fnGatherData( oSettings );
6521 /* Copy the data index array */
6522 oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
6524 /* Initialisation complete - table can be drawn */
6525 oSettings.bInitialised = true;
6527 /* Check if we need to initialise the table (it might not have been handed off to the
6528 * language processor)
6530 if ( bInitHandedOff === false )
6532 _fnInitialise( oSettings );
6538 * Version string for plug-ins to check compatibility. Allowed format is
6539 * a.b.c.d.e where: a:int, b:int, c:int, d:string(dev|beta), e:int. d and
6543 * @default Version number
6545 DataTable.version = "1.9.0";
6548 * Private data store, containing all of the settings objects that are created for the
6549 * tables on a given page.
6551 * Note that the <i>DataTable.settings</i> object is aliased to <i>jQuery.fn.dataTableExt</i>
6552 * through which it may be accessed and manipulated, or <i>jQuery.fn.dataTable.settings</i>.
6558 DataTable.settings = [];
6561 * Object models container, for the various models that DataTables has available
6562 * to it. These models define the objects that are used to hold the active state
6563 * and configuration of the table.
6566 DataTable.models = {};
6570 * DataTables extension options and plug-ins. This namespace acts as a collection "area"
6571 * for plug-ins that can be used to extend the default DataTables behaviour - indeed many
6572 * of the build in methods use this method to provide their own capabilities (sorting methods
6575 * Note that this namespace is aliased to jQuery.fn.dataTableExt so it can be readily accessed
6576 * and modified by plug-ins.
6579 DataTable.models.ext = {
6581 * Plug-in filtering functions - this method of filtering is complimentary to the default
6582 * type based filtering, and a lot more comprehensive as it allows you complete control
6583 * over the filtering logic. Each element in this array is a function (parameters
6584 * described below) that is called for every row in the table, and your logic decides if
6585 * it should be included in the filtered data set or not.
6588 * Function input parameters:
6590 * <li>{object} DataTables settings object: see {@link DataTable.models.oSettings}.</li>
6591 * <li>{array|object} Data for the row to be processed (same as the original format
6592 * that was passed in as the data source, or an array from a DOM data source</li>
6593 * <li>{int} Row index in aoData ({@link DataTable.models.oSettings.aoData}), which can
6594 * be useful to retrieve the TR element if you need DOM interaction.</li>
6600 * <li>{boolean} Include the row in the filtered result set (true) or not (false)</li>
6608 * // The following example shows custom filtering being applied to the fourth column (i.e.
6609 * // the aData[3] index) based on two input values from the end-user, matching the data in
6610 * // a certain range.
6611 * $.fn.dataTableExt.afnFiltering.push(
6612 * function( oSettings, aData, iDataIndex ) {
6613 * var iMin = document.getElementById('min').value * 1;
6614 * var iMax = document.getElementById('max').value * 1;
6615 * var iVersion = aData[3] == "-" ? 0 : aData[3]*1;
6616 * if ( iMin == "" && iMax == "" ) {
6619 * else if ( iMin == "" && iVersion < iMax ) {
6622 * else if ( iMin < iVersion && "" == iMax ) {
6625 * else if ( iMin < iVersion && iVersion < iMax ) {
6636 * Plug-in sorting functions - this method of sorting is complimentary to the default type
6637 * based sorting that DataTables does automatically, allowing much greater control over the
6638 * the data that is being used to sort a column. This is useful if you want to do sorting
6639 * based on live data (for example the contents of an 'input' element) rather than just the
6640 * static string that DataTables knows of. The way these plug-ins work is that you create
6641 * an array of the values you wish to be sorted for the column in question and then return
6642 * that array. Which pre-sorting function is run here depends on the sSortDataType parameter
6643 * that is used for the column (if any). This is the corollary of <i>ofnSearch</i> for sort
6647 * Function input parameters:
6649 * <li>{object} DataTables settings object: see {@link DataTable.models.oSettings}.</li>
6650 * <li>{int} Target column index</li>
6656 * <li>{array} Data for the column to be sorted upon</li>
6661 * Note that as of v1.9, it is typically preferable to use <i>mDataProp</i> to prepare data for
6662 * the different uses that DataTables can put the data to. Specifically <i>mDataProp</i> when
6663 * used as a function will give you a 'type' (sorting, filtering etc) that you can use to
6664 * prepare the data as required for the different types. As such, this method is deprecated.
6670 * // Updating the cached sorting information with user entered values in HTML input elements
6671 * jQuery.fn.dataTableExt.afnSortData['dom-text'] = function ( oSettings, iColumn )
6674 * $( 'td:eq('+iColumn+') input', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
6675 * aData.push( this.value );
6684 * Feature plug-ins - This is an array of objects which describe the feature plug-ins that are
6685 * available to DataTables. These feature plug-ins are accessible through the sDom initialisation
6686 * option. As such, each feature plug-in must describe a function that is used to initialise
6687 * itself (fnInit), a character so the feature can be enabled by sDom (cFeature) and the name
6688 * of the feature (sFeature). Thus the objects attached to this method must provide:
6690 * <li>{function} fnInit Initialisation of the plug-in
6693 * Function input parameters:
6695 * <li>{object} DataTables settings object: see {@link DataTable.models.oSettings}.</li>
6701 * <li>{node|null} The element which contains your feature. Note that the return
6702 * may also be void if your plug-in does not require to inject any DOM elements
6703 * into DataTables control (sDom) - for example this might be useful when
6704 * developing a plug-in which allows table control via keyboard entry.</li>
6709 * <li>{character} cFeature Character that will be matched in sDom - case sensitive</li>
6710 * <li>{string} sFeature Feature name</li>
6716 * // How TableTools initialises itself.
6717 * $.fn.dataTableExt.aoFeatures.push( {
6718 * "fnInit": function( oSettings ) {
6719 * return new TableTools( { "oDTSettings": oSettings } );
6722 * "sFeature": "TableTools"
6729 * Type detection plug-in functions - DataTables utilises types to define how sorting and
6730 * filtering behave, and types can be either be defined by the developer (sType for the
6731 * column) or they can be automatically detected by the methods in this array. The functions
6732 * defined in the array are quite simple, taking a single parameter (the data to analyse)
6733 * and returning the type if it is a known type, or null otherwise.
6736 * Function input parameters:
6738 * <li>{*} Data from the column cell to be analysed</li>
6744 * <li>{string|null} Data type detected, or null if unknown (and thus pass it
6745 * on to the other type detection functions.</li>
6753 * // Currency type detection plug-in:
6754 * jQuery.fn.dataTableExt.aTypes.push(
6755 * function ( sData ) {
6756 * var sValidChars = "0123456789.-";
6759 * // Check the numeric part
6760 * for ( i=1 ; i<sData.length ; i++ ) {
6761 * Char = sData.charAt(i);
6762 * if (sValidChars.indexOf(Char) == -1) {
6767 * // Check prefixed by currency
6768 * if ( sData.charAt(0) == '$' || sData.charAt(0) == '£' ) {
6769 * return 'currency';
6779 * Provide a common method for plug-ins to check the version of DataTables being used,
6780 * in order to ensure compatibility.
6782 * @param {string} sVersion Version string to check for, in the format "X.Y.Z". Note
6783 * that the formats "X" and "X.Y" are also acceptable.
6784 * @returns {boolean} true if this version of DataTables is greater or equal to the
6785 * required version, or false if this version of DataTales is not suitable
6788 * $(document).ready(function() {
6789 * var oTable = $('#example').dataTable();
6790 * alert( oTable.fnVersionCheck( '1.9.0' ) );
6793 "fnVersionCheck": function( sVersion )
6795 /* This is cheap, but very effective */
6796 var fnZPad = function (Zpad, count)
6798 while(Zpad.length < count) {
6803 var aThis = DataTable.ext.sVersion.split('.');
6804 var aThat = sVersion.split('.');
6805 var sThis = '', sThat = '';
6807 for ( var i=0, iLen=aThat.length ; i<iLen ; i++ )
6809 sThis += fnZPad( aThis[i], 3 );
6810 sThat += fnZPad( aThat[i], 3 );
6813 return parseInt(sThis, 10) >= parseInt(sThat, 10);
6818 * Index for what 'this' index API functions should use
6826 * Pre-processing of filtering data plug-ins - When you assign the sType for a column
6827 * (or have it automatically detected for you by DataTables or a type detection plug-in),
6828 * you will typically be using this for custom sorting, but it can also be used to provide
6829 * custom filtering by allowing you to pre-processing the data and returning the data in
6830 * the format that should be filtered upon. This is done by adding functions this object
6831 * with a parameter name which matches the sType for that target column. This is the
6832 * corollary of <i>afnSortData</i> for filtering data.
6835 * Function input parameters:
6837 * <li>{*} Data from the column cell to be prepared for filtering</li>
6843 * <li>{string|null} Formatted string that will be used for the filtering.</li>
6848 * Note that as of v1.9, it is typically preferable to use <i>mDataProp</i> to prepare data for
6849 * the different uses that DataTables can put the data to. Specifically <i>mDataProp</i> when
6850 * used as a function will give you a 'type' (sorting, filtering etc) that you can use to
6851 * prepare the data as required for the different types. As such, this method is deprecated.
6857 * $.fn.dataTableExt.ofnSearch['title-numeric'] = function ( sData ) {
6858 * return sData.replace(/\n/g," ").replace( /<.*?>/g, "" );
6865 * Container for all private functions in DataTables so they can be exposed externally
6873 * Storage for the various classes that DataTables uses
6881 * Storage for the various classes that DataTables uses - jQuery UI suitable
6889 * Pagination plug-in methods - The style and controls of the pagination can significantly
6890 * impact on how the end user interacts with the data in your table, and DataTables allows
6891 * the addition of pagination controls by extending this object, which can then be enabled
6892 * through the <i>sPaginationType</i> initialisation parameter. Each pagination type that
6893 * is added is an object (the property name of which is what <i>sPaginationType</i> refers
6894 * to) that has two properties, both methods that are used by DataTables to update the
6898 * fnInit - Initialisation of the paging controls. Called only during initialisation
6899 * of the table. It is expected that this function will add the required DOM elements
6900 * to the page for the paging controls to work. The element pointer
6901 * 'oSettings.aanFeatures.p' array is provided by DataTables to contain the paging
6902 * controls (note that this is a 2D array to allow for multiple instances of each
6903 * DataTables DOM element). It is suggested that you add the controls to this element
6907 * Function input parameters:
6909 * <li>{object} DataTables settings object: see {@link DataTable.models.oSettings}.</li>
6910 * <li>{node} Container into which the pagination controls must be inserted</li>
6911 * <li>{function} Draw callback function - whenever the controls cause a page
6912 * change, this method must be called to redraw the table.</li>
6918 * <li>No return required</li>
6924 * fnInit - This function is called whenever the paging status of the table changes and is
6925 * typically used to update classes and/or text of the paging controls to reflex the new
6929 * Function input parameters:
6931 * <li>{object} DataTables settings object: see {@link DataTable.models.oSettings}.</li>
6932 * <li>{function} Draw callback function - in case you need to redraw the table again
6933 * or attach new event listeners</li>
6939 * <li>No return required</li>
6949 * $.fn.dataTableExt.oPagination.four_button = {
6950 * "fnInit": function ( oSettings, nPaging, fnCallbackDraw ) {
6951 * nFirst = document.createElement( 'span' );
6952 * nPrevious = document.createElement( 'span' );
6953 * nNext = document.createElement( 'span' );
6954 * nLast = document.createElement( 'span' );
6956 * nFirst.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sFirst ) );
6957 * nPrevious.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sPrevious ) );
6958 * nNext.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sNext ) );
6959 * nLast.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sLast ) );
6961 * nFirst.className = "paginate_button first";
6962 * nPrevious.className = "paginate_button previous";
6963 * nNext.className="paginate_button next";
6964 * nLast.className = "paginate_button last";
6966 * nPaging.appendChild( nFirst );
6967 * nPaging.appendChild( nPrevious );
6968 * nPaging.appendChild( nNext );
6969 * nPaging.appendChild( nLast );
6971 * $(nFirst).click( function () {
6972 * oSettings.oApi._fnPageChange( oSettings, "first" );
6973 * fnCallbackDraw( oSettings );
6976 * $(nPrevious).click( function() {
6977 * oSettings.oApi._fnPageChange( oSettings, "previous" );
6978 * fnCallbackDraw( oSettings );
6981 * $(nNext).click( function() {
6982 * oSettings.oApi._fnPageChange( oSettings, "next" );
6983 * fnCallbackDraw( oSettings );
6986 * $(nLast).click( function() {
6987 * oSettings.oApi._fnPageChange( oSettings, "last" );
6988 * fnCallbackDraw( oSettings );
6991 * $(nFirst).bind( 'selectstart', function () { return false; } );
6992 * $(nPrevious).bind( 'selectstart', function () { return false; } );
6993 * $(nNext).bind( 'selectstart', function () { return false; } );
6994 * $(nLast).bind( 'selectstart', function () { return false; } );
6997 * "fnUpdate": function ( oSettings, fnCallbackDraw ) {
6998 * if ( !oSettings.aanFeatures.p ) {
7002 * // Loop over each instance of the pager
7003 * var an = oSettings.aanFeatures.p;
7004 * for ( var i=0, iLen=an.length ; i<iLen ; i++ ) {
7005 * var buttons = an[i].getElementsByTagName('span');
7006 * if ( oSettings._iDisplayStart === 0 ) {
7007 * buttons[0].className = "paginate_disabled_previous";
7008 * buttons[1].className = "paginate_disabled_previous";
7011 * buttons[0].className = "paginate_enabled_previous";
7012 * buttons[1].className = "paginate_enabled_previous";
7015 * if ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() ) {
7016 * buttons[2].className = "paginate_disabled_next";
7017 * buttons[3].className = "paginate_disabled_next";
7020 * buttons[2].className = "paginate_enabled_next";
7021 * buttons[3].className = "paginate_enabled_next";
7031 * Sorting plug-in methods - Sorting in DataTables is based on the detected type of the
7032 * data column (you can add your own type detection functions, or override automatic
7033 * detection using sType). With this specific type given to the column, DataTables will
7034 * apply the required sort from the functions in the object. Each sort type must provide
7035 * two mandatory methods, one each for ascending and descending sorting, and can optionally
7036 * provide a pre-formatting method that will help speed up sorting by allowing DataTables
7037 * to pre-format the sort data only once (rather than every time the actual sort functions
7038 * are run). The two sorting functions are typical Javascript sort methods:
7041 * Function input parameters:
7043 * <li>{*} Data to compare to the second parameter</li>
7044 * <li>{*} Data to compare to the first parameter</li>
7050 * <li>{int} Sorting match: <0 if first parameter should be sorted lower than
7051 * the second parameter, ===0 if the two parameters are equal and >0 if
7052 * the first parameter should be sorted height than the second parameter.</li>
7060 * // Case-sensitive string sorting, with no pre-formatting method
7061 * $.extend( $.fn.dataTableExt.oSort, {
7062 * "string-case-asc": function(x,y) {
7063 * return ((x < y) ? -1 : ((x > y) ? 1 : 0));
7065 * "string-case-desc": function(x,y) {
7066 * return ((x < y) ? 1 : ((x > y) ? -1 : 0));
7071 * // Case-insensitive string sorting, with pre-formatting
7072 * $.extend( $.fn.dataTableExt.oSort, {
7073 * "string-pre": function(x) {
7074 * return x.toLowerCase();
7076 * "string-asc": function(x,y) {
7077 * return ((x < y) ? -1 : ((x > y) ? 1 : 0));
7079 * "string-desc": function(x,y) {
7080 * return ((x < y) ? 1 : ((x > y) ? -1 : 0));
7088 * Version string for plug-ins to check compatibility. Allowed format is
7089 * a.b.c.d.e where: a:int, b:int, c:int, d:string(dev|beta), e:int. d and
7092 * @default Version number
7094 "sVersion": DataTable.version,
7098 * How should DataTables report an error. Can take the value 'alert' or 'throw'
7102 "sErrMode": "alert",
7106 * Store information for DataTables to access globally about other instances
7111 /* int:iNextUnique - next unique number for an instance */
7120 * Template object for the way in which DataTables holds information about
7121 * search information for the global filter and individual column filters.
7124 DataTable.models.oSearch = {
7126 * Flag to indicate if the filtering should be case insensitive or not
7130 "bCaseInsensitive": true,
7133 * Applied search term
7135 * @default <i>Empty string</i>
7140 * Flag to indicate if the search term should be interpreted as a
7141 * regular expression (true) or not (false) and therefore and special
7142 * regex characters escaped.
7149 * Flag to indicate if DataTables is to use its smart filtering or not.
7160 * Template object for the way in which DataTables holds information about
7161 * each individual row. This is the object format used for the settings
7165 DataTable.models.oRow = {
7167 * TR element for the row
7174 * Data object from the original data source for the row. This is either
7175 * an array if using the traditional form of DataTables, or an object if
7176 * using mDataProp options. The exact type will depend on the passed in
7177 * data from the data source, or will be an array if using DOM a data
7179 * @type array|object
7185 * Sorting data cache - this array is ostensibly the same length as the
7186 * number of columns (although each index is generated only as it is
7187 * needed), and holds the data that is used for sorting each column in the
7188 * row. We do this cache generation at the start of the sort in order that
7189 * the formatting of the sort data need be done only once for each cell
7190 * per sort. This array should not be read from or written to by anything
7191 * other than the master sorting methods.
7199 * Array of TD elements that are cached for hidden rows, so they can be
7200 * reinserted into the table if a column is made visible again (or to act
7201 * as a store if a column is made hidden). Only hidden columns have a
7202 * reference in the array. For non-hidden columns the value is either
7203 * undefined or null.
7211 * Cache of the class name that DataTables has applied to the row, so we
7212 * can quickly look at this variable rather than needing to do a DOM check
7213 * on className for the nTr property.
7215 * @default <i>Empty string</i>
7224 * Template object for the column information object in DataTables. This object
7225 * is held in the settings aoColumns array and contains all the information that
7226 * DataTables needs about each individual column.
7228 * Note that this object is related to {@link DataTable.defaults.columns}
7229 * but this one is the internal data store for DataTables's cache of columns.
7230 * It should NOT be manipulated outside of DataTables. Any configuration should
7231 * be done through the initialisation options.
7234 DataTable.models.oColumn = {
7236 * A list of the columns that sorting should occur on when this column
7237 * is sorted. That this property is an array allows multi-column sorting
7238 * to be defined for a column (for example first name / last name columns
7239 * would benefit from this). The values are integers pointing to the
7240 * columns to be sorted on (typically it will be a single integer pointing
7241 * at itself, but that doesn't need to be the case).
7247 * Define the sorting directions that are applied to the column, in sequence
7248 * as the column is repeatedly sorted upon - i.e. the first value is used
7249 * as the sorting direction when the column if first sorted (clicked on).
7250 * Sort it again (click again) and it will move on to the next index.
7251 * Repeat until loop.
7257 * Flag to indicate if the column is searchable, and thus should be included
7258 * in the filtering or not.
7261 "bSearchable": null,
7264 * Flag to indicate if the column is sortable or not.
7270 * When using fnRender, you have two options for what to do with the data,
7271 * and this property serves as the switch. Firstly, you can have the sorting
7272 * and filtering use the rendered value (true - default), or you can have
7273 * the sorting and filtering us the original value (false).
7275 * *NOTE* It is it is advisable now to use mDataProp as a function and make
7276 * use of the 'type' that it gives, allowing (potentially) different data to
7277 * be used for sorting, filtering, display and type detection.
7281 "bUseRendered": null,
7284 * Flag to indicate if the column is currently visible in the table or not
7290 * Flag to indicate to the type detection method if the automatic type
7291 * detection should be used, or if a column type (sType) has been specified
7299 * Developer definable function that is called whenever a cell is created (Ajax source,
7300 * etc) or processed for input (DOM source). This can be used as a compliment to fnRender
7301 * allowing you to modify the DOM element (add background colour for example) when the
7302 * element is available (since it is not when fnRender is called).
7304 * @param {element} nTd The TD node that has been created
7305 * @param {*} sData The Data for the cell
7306 * @param {array|object} oData The data for the whole row
7307 * @param {int} iRow The row index for the aoData data store
7310 "fnCreatedCell": null,
7313 * Function to get data from a cell in a column. You should <b>never</b>
7314 * access data directly through _aData internally in DataTables - always use
7315 * the method attached to this property. It allows mDataProp to function as
7316 * required. This function is automatically assigned by the column
7317 * initialisation method
7319 * @param {array|object} oData The data array/object for the array
7320 * (i.e. aoData[]._aData)
7321 * @param {string} sSpecific The specific data type you want to get -
7322 * 'display', 'type' 'filter' 'sort'
7323 * @returns {*} The data for the cell from the given row's data
7329 * Custom display function that will be called for the display of each cell
7332 * @param {object} o Object with the following parameters:
7333 * @param {int} o.iDataRow The row in aoData
7334 * @param {int} o.iDataColumn The column in question
7335 * @param {array o.aData The data for the row in question
7336 * @param {object} o.oSettings The settings object for this DataTables instance
7337 * @returns {string} The string you which to use in the display
7343 * Function to set data for a cell in the column. You should <b>never</b>
7344 * set the data directly to _aData internally in DataTables - always use
7345 * this method. It allows mDataProp to function as required. This function
7346 * is automatically assigned by the column initialisation method
7348 * @param {array|object} oData The data array/object for the array
7349 * (i.e. aoData[]._aData)
7350 * @param {*} sValue Value to set
7356 * Property to read the value for the cells in the column from the data
7357 * source array / object. If null, then the default content is used, if a
7358 * function is given then the return from the function is used.
7359 * @type function|int|string|null
7365 * Unique header TH/TD element for this column - this is what the sorting
7366 * listener is attached to (if sorting is enabled.)
7373 * Unique footer TH/TD element for this column (if there is one). Not used
7374 * in DataTables as such, but can be used for plug-ins to reference the
7375 * footer for each column.
7382 * The class to apply to all TD elements in the table's TBODY for the column
7389 * When DataTables calculates the column widths to assign to each column,
7390 * it finds the longest string in each column and then constructs a
7391 * temporary table and reads the widths from that. The problem with this
7392 * is that "mmm" is much wider then "iiii", but the latter is a longer
7393 * string - thus the calculation can go wrong (doing it properly and putting
7394 * it into an DOM object and measuring that is horribly(!) slow). Thus as
7395 * a "work around" we provide this option. It will append its value to the
7396 * text that is found to be the longest string for the column - i.e. padding.
7399 "sContentPadding": null,
7402 * Allows a default value to be given for a column's data, and will be used
7403 * whenever a null data source is encountered (this can be because mDataProp
7404 * is set to null, or because the data source itself is null).
7408 "sDefaultContent": null,
7411 * Name for the column, allowing reference to the column by name as well as
7412 * by index (needs a lookup to work by name).
7418 * Custom sorting data type - defines which of the available plug-ins in
7419 * afnSortData the custom sorting will use - if any is defined.
7423 "sSortDataType": 'std',
7426 * Class to be applied to the header element when sorting on this column
7430 "sSortingClass": null,
7433 * Class to be applied to the header element when sorting on this column -
7434 * when jQuery UI theming is used.
7438 "sSortingClassJUI": null,
7441 * Title of the column - what is seen in the TH element (nTh).
7447 * Column sorting and filtering type
7454 * Width of the column
7461 * Width of the column when it was first "encountered"
7471 * Initialisation options that can be given to DataTables at initialisation
7475 DataTable.defaults = {
7477 * An array of data to use for the table, passed in at initialisation which
7478 * will be used in preference to any data which is already in the DOM. This is
7479 * particularly useful for constructing tables purely in Javascript, for
7480 * example with a custom Ajax call.
7486 * // Using a 2D array data source
7487 * $(document).ready( function () {
7488 * $('#example').dataTable( {
7490 * ['Trident', 'Internet Explorer 4.0', 'Win 95+', 4, 'X'],
7491 * ['Trident', 'Internet Explorer 5.0', 'Win 95+', 5, 'C'],
7494 * { "sTitle": "Engine" },
7495 * { "sTitle": "Browser" },
7496 * { "sTitle": "Platform" },
7497 * { "sTitle": "Version" },
7498 * { "sTitle": "Grade" }
7504 * // Using an array of objects as a data source (mDataProp)
7505 * $(document).ready( function () {
7506 * $('#example').dataTable( {
7509 * "engine": "Trident",
7510 * "browser": "Internet Explorer 4.0",
7511 * "platform": "Win 95+",
7516 * "engine": "Trident",
7517 * "browser": "Internet Explorer 5.0",
7518 * "platform": "Win 95+",
7524 * { "sTitle": "Engine", "mDataProp": "engine" },
7525 * { "sTitle": "Browser", "mDataProp": "browser" },
7526 * { "sTitle": "Platform", "mDataProp": "platform" },
7527 * { "sTitle": "Version", "mDataProp": "version" },
7528 * { "sTitle": "Grade", "mDataProp": "grade" }
7537 * If sorting is enabled, then DataTables will perform a first pass sort on
7538 * initialisation. You can define which column(s) the sort is performed upon,
7539 * and the sorting direction, with this variable. The aaSorting array should
7540 * contain an array for each column to be sorted initially containing the
7541 * column's index and a direction string ('asc' or 'desc').
7543 * @default [[0,'asc']]
7547 * // Sort by 3rd column first, and then 4th column
7548 * $(document).ready( function() {
7549 * $('#example').dataTable( {
7550 * "aaSorting": [[2,'asc'], [3,'desc']]
7554 * // No initial sorting
7555 * $(document).ready( function() {
7556 * $('#example').dataTable( {
7561 "aaSorting": [[0,'asc']],
7565 * This parameter is basically identical to the aaSorting parameter, but
7566 * cannot be overridden by user interaction with the table. What this means
7567 * is that you could have a column (visible or hidden) which the sorting will
7568 * always be forced on first - any sorting after that (from the user) will
7569 * then be performed as required. This can be useful for grouping rows
7576 * $(document).ready( function() {
7577 * $('#example').dataTable( {
7578 * "aaSortingFixed": [[0,'asc']]
7582 "aaSortingFixed": null,
7586 * This parameter allows you to readily specify the entries in the length drop
7587 * down menu that DataTables shows when pagination is enabled. It can be
7588 * either a 1D array of options which will be used for both the displayed
7589 * option and the value, or a 2D array which will use the array in the first
7590 * position as the value, and the array in the second position as the
7591 * displayed options (useful for language strings such as 'All').
7593 * @default [ 10, 25, 50, 100 ]
7597 * $(document).ready(function() {
7598 * $('#example').dataTable( {
7599 * "aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
7604 * // Setting the default display length as well as length menu
7605 * // This is likely to be wanted if you remove the '10' option which
7606 * // is the iDisplayLength default.
7607 * $(document).ready(function() {
7608 * $('#example').dataTable( {
7609 * "iDisplayLength": 25,
7610 * "aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]]
7614 "aLengthMenu": [ 10, 25, 50, 100 ],
7618 * The aoColumns option in the initialisation parameter allows you to define
7619 * details about the way individual columns behave. For a full list of
7620 * column options that can be set, please see
7621 * {@link DataTable.defaults.columns}. Note that if you use aoColumns to
7622 * define your columns, you must have an entry in the array for every single
7623 * column that you have in your table (these can be null if you don't which
7624 * to specify any options).
7630 * Very similar to aoColumns, aoColumnDefs allows you to target a specific
7631 * column, multiple columns, or all columns, using the aTargets property of
7632 * each object in the array. This allows great flexibility when creating
7633 * tables, as the aoColumnDefs arrays can be of any length, targeting the
7634 * columns you specifically want. aoColumnDefs may use any of the column
7635 * options available: {@link DataTable.defaults.columns}, but it _must_
7636 * have aTargets defined in each object in the array. Values in the aTargets
7639 * <li>a string - class name will be matched on the TH for the column</li>
7640 * <li>0 or a positive integer - column index counting from the left</li>
7641 * <li>a negative integer - column index counting from the right</li>
7642 * <li>the string "_all" - all columns (i.e. assign a default)</li>
7646 "aoColumnDefs": null,
7650 * Basically the same as oSearch, this parameter defines the individual column
7651 * filtering state at initialisation time. The array must be of the same size
7652 * as the number of columns, and each element be an object with the parameters
7653 * "sSearch" and "bEscapeRegex" (the latter is optional). 'null' is also
7654 * accepted and the default will be used.
7660 * $(document).ready( function() {
7661 * $('#example').dataTable( {
7664 * { "sSearch": "My filter" },
7666 * { "sSearch": "^[0-9]", "bEscapeRegex": false }
7675 * An array of CSS classes that should be applied to displayed rows. This
7676 * array may be of any length, and DataTables will apply each class
7677 * sequentially, looping when required.
7679 * @default [ 'odd', 'even' ]
7683 * $(document).ready( function() {
7684 * $('#example').dataTable( {
7685 * "asStripeClasses": [ 'strip1', 'strip2', 'strip3' ]
7689 "asStripeClasses": [ 'odd', 'even' ],
7693 * Enable or disable automatic column width calculation. This can be disabled
7694 * as an optimisation (it takes some time to calculate the widths) if the
7695 * tables widths are passed in using aoColumns.
7701 * $(document).ready( function () {
7702 * $('#example').dataTable( {
7703 * "bAutoWidth": false
7711 * Deferred rendering can provide DataTables with a huge speed boost when you
7712 * are using an Ajax or JS data source for the table. This option, when set to
7713 * true, will cause DataTables to defer the creation of the table elements for
7714 * each row until they are needed for a draw - saving a significant amount of
7721 * $(document).ready(function() {
7722 * var oTable = $('#example').dataTable( {
7723 * "sAjaxSource": "sources/arrays.txt",
7724 * "bDeferRender": true
7728 "bDeferRender": false,
7732 * Replace a DataTable which matches the given selector and replace it with
7733 * one which has the properties of the new initialisation object passed. If no
7734 * table matches the selector, then the new DataTable will be constructed as
7741 * $(document).ready(function() {
7742 * $('#example').dataTable( {
7743 * "sScrollY": "200px",
7744 * "bPaginate": false
7747 * // Some time later....
7748 * $('#example').dataTable( {
7758 * Enable or disable filtering of data. Filtering in DataTables is "smart" in
7759 * that it allows the end user to input multiple words (space separated) and
7760 * will match a row containing those words, even if not in the order that was
7761 * specified (this allow matching across multiple columns). Note that if you
7762 * wish to use filtering in DataTables this must remain 'true' - to remove the
7763 * default filtering input box and retain filtering abilities, please use
7770 * $(document).ready( function () {
7771 * $('#example').dataTable( {
7780 * Enable or disable the table information display. This shows information
7781 * about the data that is currently visible on the page, including information
7782 * about filtered data if that action is being performed.
7788 * $(document).ready( function () {
7789 * $('#example').dataTable( {
7798 * Enable jQuery UI ThemeRoller support (required as ThemeRoller requires some
7799 * slightly different and additional mark-up from what DataTables has
7800 * traditionally used).
7806 * $(document).ready( function() {
7807 * $('#example').dataTable( {
7816 * Allows the end user to select the size of a formatted page from a select
7817 * menu (sizes are 10, 25, 50 and 100). Requires pagination (bPaginate).
7823 * $(document).ready( function () {
7824 * $('#example').dataTable( {
7825 * "bLengthChange": false
7829 "bLengthChange": true,
7833 * Enable or disable pagination.
7839 * $(document).ready( function () {
7840 * $('#example').dataTable( {
7841 * "bPaginate": false
7849 * Enable or disable the display of a 'processing' indicator when the table is
7850 * being processed (e.g. a sort). This is particularly useful for tables with
7851 * large amounts of data where it can take a noticeable amount of time to sort
7858 * $(document).ready( function () {
7859 * $('#example').dataTable( {
7860 * "bProcessing": true
7864 "bProcessing": false,
7868 * Retrieve the DataTables object for the given selector. Note that if the
7869 * table has already been initialised, this parameter will cause DataTables
7870 * to simply return the object that has already been set up - it will not take
7871 * account of any changes you might have made to the initialisation object
7872 * passed to DataTables (setting this parameter to true is an acknowledgement
7873 * that you understand this). bDestroy can be used to reinitialise a table if
7880 * $(document).ready(function() {
7885 * function initTable ()
7887 * return $('#example').dataTable( {
7888 * "sScrollY": "200px",
7889 * "bPaginate": false,
7894 * function tableActions ()
7896 * var oTable = initTable();
7897 * // perform API operations with oTable
7904 * Indicate if DataTables should be allowed to set the padding / margin
7905 * etc for the scrolling header elements or not. Typically you will want
7912 * $(document).ready(function() {
7913 * $('#example').dataTable( {
7914 * "bScrollAutoCss": false,
7915 * "sScrollY": "200px"
7919 "bScrollAutoCss": true,
7923 * When vertical (y) scrolling is enabled, DataTables will force the height of
7924 * the table's viewport to the given height at all times (useful for layout).
7925 * However, this can look odd when filtering data down to a small data set,
7926 * and the footer is left "floating" further down. This parameter (when
7927 * enabled) will cause DataTables to collapse the table's viewport down when
7928 * the result set will fit within the given Y height.
7934 * $(document).ready(function() {
7935 * $('#example').dataTable( {
7936 * "sScrollY": "200",
7937 * "bScrollCollapse": true
7941 "bScrollCollapse": false,
7945 * Enable infinite scrolling for DataTables (to be used in combination with
7946 * sScrollY). Infinite scrolling means that DataTables will continually load
7947 * data as a user scrolls through a table, which is very useful for large
7948 * dataset. This cannot be used with pagination, which is automatically
7949 * disabled. Note - the Scroller extra for DataTables is recommended in
7950 * in preference to this option.
7956 * $(document).ready(function() {
7957 * $('#example').dataTable( {
7958 * "bScrollInfinite": true,
7959 * "bScrollCollapse": true,
7960 * "sScrollY": "200px"
7964 "bScrollInfinite": false,
7968 * Configure DataTables to use server-side processing. Note that the
7969 * sAjaxSource parameter must also be given in order to give DataTables a
7970 * source to obtain the required data for each draw.
7974 * @dtopt Server-side
7977 * $(document).ready( function () {
7978 * $('#example').dataTable( {
7979 * "bServerSide": true,
7980 * "sAjaxSource": "xhr.php"
7984 "bServerSide": false,
7988 * Enable or disable sorting of columns. Sorting of individual columns can be
7989 * disabled by the "bSortable" option for each column.
7995 * $(document).ready( function () {
7996 * $('#example').dataTable( {
8005 * Allows control over whether DataTables should use the top (true) unique
8006 * cell that is found for a single column, or the bottom (false - default).
8007 * This is useful when using complex headers.
8013 * $(document).ready(function() {
8014 * $('#example').dataTable( {
8015 * "bSortCellsTop": true
8019 "bSortCellsTop": false,
8023 * Enable or disable the addition of the classes 'sorting_1', 'sorting_2' and
8024 * 'sorting_3' to the columns which are currently being sorted on. This is
8025 * presented as a feature switch as it can increase processing time (while
8026 * classes are removed and added) so for large data sets you might want to
8033 * $(document).ready( function () {
8034 * $('#example').dataTable( {
8035 * "bSortClasses": false
8039 "bSortClasses": true,
8043 * Enable or disable state saving. When enabled a cookie will be used to save
8044 * table display information such as pagination information, display length,
8045 * filtering and sorting. As such when the end user reloads the page the
8046 * display display will match what thy had previously set up.
8052 * $(document).ready( function () {
8053 * $('#example').dataTable( {
8054 * "bStateSave": true
8058 "bStateSave": false,
8062 * Customise the cookie and / or the parameters being stored when using
8063 * DataTables with state saving enabled. This function is called whenever
8064 * the cookie is modified, and it expects a fully formed cookie string to be
8065 * returned. Note that the data object passed in is a Javascript object which
8066 * must be converted to a string (JSON.stringify for example).
8068 * @param {string} sName Name of the cookie defined by DataTables
8069 * @param {object} oData Data to be stored in the cookie
8070 * @param {string} sExpires Cookie expires string
8071 * @param {string} sPath Path of the cookie to set
8072 * @returns {string} Cookie formatted string (which should be encoded by
8073 * using encodeURIComponent())
8077 * $(document).ready( function () {
8078 * $('#example').dataTable( {
8079 * "fnCookieCallback": function (sName, oData, sExpires, sPath) {
8080 * // Customise oData or sName or whatever else here
8081 * return sName + "="+JSON.stringify(oData)+"; expires=" + sExpires +"; path=" + sPath;
8086 "fnCookieCallback": null,
8090 * This function is called when a TR element is created (and all TD child
8091 * elements have been inserted), or registered if using a DOM source, allowing
8092 * manipulation of the TR element (adding classes etc).
8094 * @param {node} nRow "TR" element for the current row
8095 * @param {array} aData Raw data array for this row
8096 * @param {int} iDataIndex The index of this row in aoData
8100 * $(document).ready(function() {
8101 * $('#example').dataTable( {
8102 * "fnCreatedRow": function( nRow, aData, iDataIndex ) {
8103 * // Bold the grade for all 'A' grade browsers
8104 * if ( aData[4] == "A" )
8106 * $('td:eq(4)', nRow).html( '<b>A</b>' );
8112 "fnCreatedRow": null,
8116 * This function is called on every 'draw' event, and allows you to
8117 * dynamically modify any aspect you want about the created DOM.
8119 * @param {object} oSettings DataTables settings object
8123 * $(document).ready( function() {
8124 * $('#example').dataTable( {
8125 * "fnDrawCallback": function() {
8126 * alert( 'DataTables has redrawn the table' );
8131 "fnDrawCallback": null,
8135 * Identical to fnHeaderCallback() but for the table footer this function
8136 * allows you to modify the table footer on every 'draw' even.
8138 * @param {node} nFoot "TR" element for the footer
8139 * @param {array} aData Full table data (as derived from the original HTML)
8140 * @param {int} iStart Index for the current display starting point in the
8142 * @param {int} iEnd Index for the current display ending point in the
8144 * @param {array int} aiDisplay Index array to translate the visual position
8145 * to the full data array
8149 * $(document).ready( function() {
8150 * $('#example').dataTable( {
8151 * "fnFooterCallback": function( nFoot, aData, iStart, iEnd, aiDisplay ) {
8152 * nFoot.getElementsByTagName('th')[0].innerHTML = "Starting index is "+iStart;
8157 "fnFooterCallback": null,
8161 * When rendering large numbers in the information element for the table
8162 * (i.e. "Showing 1 to 10 of 57 entries") DataTables will render large numbers
8163 * to have a comma separator for the 'thousands' units (e.g. 1 million is
8164 * rendered as "1,000,000") to help readability for the end user. This
8165 * function will override the default method DataTables uses.
8168 * @param {int} iIn number to be formatted
8169 * @returns {string} formatted string for DataTables to show the number
8173 * $(document).ready(function() {
8174 * $('#example').dataTable( {
8175 * "fnFormatNumber": function ( iIn ) {
8176 * if ( iIn < 1000 ) {
8181 * a=s.split(""), out="",
8184 * for ( var i=0 ; i<iLen ; i++ ) {
8185 * if ( i%3 === 0 && i !== 0 ) {
8188 * out = a[iLen-i-1]+out;
8196 "fnFormatNumber": function ( iIn ) {
8199 // A small optimisation for what is likely to be the majority of use cases
8203 var s=(iIn+""), a=s.split(""), out="", iLen=s.length;
8205 for ( var i=0 ; i<iLen ; i++ )
8207 if ( i%3 === 0 && i !== 0 )
8209 out = this.oLanguage.sInfoThousands+out;
8211 out = a[iLen-i-1]+out;
8218 * This function is called on every 'draw' event, and allows you to
8219 * dynamically modify the header row. This can be used to calculate and
8220 * display useful information about the table.
8222 * @param {node} nHead "TR" element for the header
8223 * @param {array} aData Full table data (as derived from the original HTML)
8224 * @param {int} iStart Index for the current display starting point in the
8226 * @param {int} iEnd Index for the current display ending point in the
8228 * @param {array int} aiDisplay Index array to translate the visual position
8229 * to the full data array
8233 * $(document).ready( function() {
8234 * $('#example').dataTable( {
8235 * "fnHeaderCallback": function( nHead, aData, iStart, iEnd, aiDisplay ) {
8236 * nHead.getElementsByTagName('th')[0].innerHTML = "Displaying "+(iEnd-iStart)+" records";
8241 "fnHeaderCallback": null,
8245 * The information element can be used to convey information about the current
8246 * state of the table. Although the internationalisation options presented by
8247 * DataTables are quite capable of dealing with most customisations, there may
8248 * be times where you wish to customise the string further. This callback
8249 * allows you to do exactly that.
8251 * @param {object} oSettings DataTables settings object
8252 * @param {int} iStart Starting position in data for the draw
8253 * @param {int} iEnd End position in data for the draw
8254 * @param {int} iMax Total number of rows in the table (regardless of
8256 * @param {int} iTotal Total number of rows in the data set, after filtering
8257 * @param {string} sPre The string that DataTables has formatted using it's
8259 * @returns {string} The string to be displayed in the information element.
8263 * $('#example').dataTable( {
8264 * "fnInfoCallback": function( oSettings, iStart, iEnd, iMax, iTotal, sPre ) {
8265 * return iStart +" to "+ iEnd;
8269 "fnInfoCallback": null,
8273 * Called when the table has been initialised. Normally DataTables will
8274 * initialise sequentially and there will be no need for this function,
8275 * however, this does not hold true when using external language information
8276 * since that is obtained using an async XHR call.
8278 * @param {object} oSettings DataTables settings object
8279 * @param {object} json The JSON object request from the server - only
8280 * present if client-side Ajax sourced data is used
8284 * $(document).ready( function() {
8285 * $('#example').dataTable( {
8286 * "fnInitComplete": function(oSettings, json) {
8287 * alert( 'DataTables has finished its initialisation.' );
8292 "fnInitComplete": null,
8296 * Called at the very start of each table draw and can be used to cancel the
8297 * draw by returning false, any other return (including undefined) results in
8298 * the full draw occurring).
8300 * @param {object} oSettings DataTables settings object
8301 * @returns {boolean} False will cancel the draw, anything else (including no
8302 * return) will allow it to complete.
8306 * $(document).ready( function() {
8307 * $('#example').dataTable( {
8308 * "fnPreDrawCallback": function( oSettings ) {
8309 * if ( $('#test').val() == 1 ) {
8316 "fnPreDrawCallback": null,
8320 * This function allows you to 'post process' each row after it have been
8321 * generated for each table draw, but before it is rendered on screen. This
8322 * function might be used for setting the row class name etc.
8324 * @param {node} nRow "TR" element for the current row
8325 * @param {array} aData Raw data array for this row
8326 * @param {int} iDisplayIndex The display index for the current table draw
8327 * @param {int} iDisplayIndexFull The index of the data in the full list of
8328 * rows (after filtering)
8332 * $(document).ready(function() {
8333 * $('#example').dataTable( {
8334 * "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
8335 * // Bold the grade for all 'A' grade browsers
8336 * if ( aData[4] == "A" )
8338 * $('td:eq(4)', nRow).html( '<b>A</b>' );
8344 "fnRowCallback": null,
8348 * This parameter allows you to override the default function which obtains
8349 * the data from the server ($.getJSON) so something more suitable for your
8350 * application. For example you could use POST data, or pull information from
8351 * a Gears or AIR database.
8354 * @param {string} sSource HTTP source to obtain the data from (sAjaxSource)
8355 * @param {array} aoData A key/value pair object containing the data to send
8357 * @param {function} fnCallback to be called on completion of the data get
8358 * process that will draw the data on the page.
8359 * @param {object} oSettings DataTables settings object
8361 * @dtopt Server-side
8364 * // POST data to server
8365 * $(document).ready(function() {
8366 * $('#example').dataTable( {
8367 * "bProcessing": true,
8368 * "bServerSide": true,
8369 * "sAjaxSource": "xhr.php",
8370 * "fnServerData": function ( sSource, aoData, fnCallback ) {
8372 * "dataType": 'json',
8376 * "success": fnCallback
8382 "fnServerData": function ( sUrl, aoData, fnCallback, oSettings ) {
8383 oSettings.jqXHR = $.ajax( {
8386 "success": function (json) {
8387 $(oSettings.oInstance).trigger('xhr', oSettings);
8392 "type": oSettings.sServerMethod,
8393 "error": function (xhr, error, thrown) {
8394 if ( error == "parsererror" ) {
8395 alert( "DataTables warning: JSON data from server could not be parsed. "+
8396 "This is caused by a JSON formatting error." );
8404 * It is often useful to send extra data to the server when making an Ajax
8405 * request - for example custom filtering information, and this callback
8406 * function makes it trivial to send extra information to the server. The
8407 * passed in parameter is the data set that has been constructed by
8408 * DataTables, and you can add to this or modify it as you require.
8410 * @param {array} aoData Data array (array of objects which are name/value
8411 * pairs) that has been constructed by DataTables and will be sent to the
8412 * server. In the case of Ajax sourced data with server-side processing
8413 * this will be an empty array, for server-side processing there will be a
8414 * significant number of parameters!
8415 * @returns {undefined} Ensure that you modify the aoData array passed in,
8416 * as this is passed by reference.
8418 * @dtopt Server-side
8421 * $(document).ready(function() {
8422 * $('#example').dataTable( {
8423 * "bProcessing": true,
8424 * "bServerSide": true,
8425 * "sAjaxSource": "scripts/server_processing.php",
8426 * "fnServerParams": function ( aoData ) {
8427 * aoData.push( { "name": "more_data", "value": "my_value" } );
8432 "fnServerParams": null,
8436 * Load the table state. With this function you can define from where, and how, the
8437 * state of a table is loaded. By default DataTables will load from its state saving
8438 * cookie, but you might wish to use local storage (HTML5) or a server-side database.
8441 * @param {object} oSettings DataTables settings object
8442 * @return {object} The DataTables state object to be loaded
8446 * $(document).ready(function() {
8447 * $('#example').dataTable( {
8448 * "bStateSave": true,
8449 * "fnStateSave": function (oSettings, oData) {
8452 * // Send an Ajax request to the server to get the data. Note that
8453 * // this is a synchronous request.
8455 * "url": "/state_load",
8457 * "dataType": "json",
8458 * "success": function (json) {
8468 "fnStateLoad": function ( oSettings ) {
8469 var sData = this.oApi._fnReadCookie( oSettings.sCookiePrefix+oSettings.sInstance );
8473 oData = (typeof $.parseJSON === 'function') ?
8474 $.parseJSON(sData) : eval( '('+sData+')' );
8484 * Callback which allows modification of the saved state prior to loading that state.
8485 * This callback is called when the table is loading state from the stored data, but
8486 * prior to the settings object being modified by the saved state. Note that for
8487 * plug-in authors, you should use the 'stateLoadParams' event to load parameters for
8490 * @param {object} oSettings DataTables settings object
8491 * @param {object} oData The state object that is to be loaded
8495 * // Remove a saved filter, so filtering is never loaded
8496 * $(document).ready(function() {
8497 * $('#example').dataTable( {
8498 * "bStateSave": true,
8499 * "fnStateLoadParams": function (oSettings, oData) {
8500 * oData.oFilter.sSearch = "";
8505 * // Disallow state loading by returning false
8506 * $(document).ready(function() {
8507 * $('#example').dataTable( {
8508 * "bStateSave": true,
8509 * "fnStateLoadParams": function (oSettings, oData) {
8514 "fnStateLoadParams": null,
8518 * Callback that is called when the state has been loaded from the state saving method
8519 * and the DataTables settings object has been modified as a result of the loaded state.
8521 * @param {object} oSettings DataTables settings object
8522 * @param {object} oData The state object that was loaded
8526 * // Show an alert with the filtering value that was saved
8527 * $(document).ready(function() {
8528 * $('#example').dataTable( {
8529 * "bStateSave": true,
8530 * "fnStateLoaded": function (oSettings, oData) {
8531 * alert( 'Saved filter was: '+oData.oFilter.sSearch );
8535 "fnStateLoaded": null,
8539 * Save the table state. This function allows you to define where and how the state
8540 * information for the table is stored - by default it will use a cookie, but you
8541 * might want to use local storage (HTML5) or a server-side database.
8544 * @param {object} oSettings DataTables settings object
8545 * @param {object} oData The state object to be saved
8549 * $(document).ready(function() {
8550 * $('#example').dataTable( {
8551 * "bStateSave": true,
8552 * "fnStateSave": function (oSettings, oData) {
8553 * // Send an Ajax request to the server with the state object
8555 * "url": "/state_save",
8557 * "dataType": "json",
8559 * "success": function () {}
8565 "fnStateSave": function ( oSettings, oData ) {
8566 this.oApi._fnCreateCookie(
8567 oSettings.sCookiePrefix+oSettings.sInstance,
8568 this.oApi._fnJsonString(oData),
8569 oSettings.iCookieDuration,
8570 oSettings.sCookiePrefix,
8571 oSettings.fnCookieCallback
8577 * Callback which allows modification of the state to be saved. Called when the table
8578 * has changed state a new state save is required. This method allows modification of
8579 * the state saving object prior to actually doing the save, including addition or
8580 * other state properties or modification. Note that for plug-in authors, you should
8581 * use the 'stateSaveParams' event to save parameters for a plug-in.
8583 * @param {object} oSettings DataTables settings object
8584 * @param {object} oData The state object to be saved
8588 * // Remove a saved filter, so filtering is never saved
8589 * $(document).ready(function() {
8590 * $('#example').dataTable( {
8591 * "bStateSave": true,
8592 * "fnStateLoadParams": function (oSettings, oData) {
8593 * oData.oFilter.sSearch = "";
8597 "fnStateSaveParams": null,
8601 * Duration of the cookie which is used for storing session information. This
8602 * value is given in seconds.
8604 * @default 7200 <i>(2 hours)</i>
8608 * $(document).ready( function() {
8609 * $('#example').dataTable( {
8610 * "iCookieDuration": 60*60*24 // 1 day
8614 "iCookieDuration": 7200,
8618 * When enabled DataTables will not make a request to the server for the first
8619 * page draw - rather it will use the data already on the page (no sorting etc
8620 * will be applied to it), thus saving on an XHR at load time. iDeferLoading
8621 * is used to indicate that deferred loading is required, but it is also used
8622 * to tell DataTables how many records there are in the full table (allowing
8623 * the information element and pagination to be displayed correctly).
8629 * $(document).ready(function() {
8630 * $('#example').dataTable( {
8631 * "bServerSide": true,
8632 * "sAjaxSource": "scripts/server_processing.php",
8633 * "iDeferLoading": 57
8637 "iDeferLoading": null,
8641 * Number of rows to display on a single page when using pagination. If
8642 * feature enabled (bLengthChange) then the end user will be able to override
8643 * this to a custom setting using a pop-up menu.
8649 * $(document).ready( function() {
8650 * $('#example').dataTable( {
8651 * "iDisplayLength": 50
8655 "iDisplayLength": 10,
8659 * Define the starting point for data display when using DataTables with
8660 * pagination. Note that this parameter is the number of records, rather than
8661 * the page number, so if you have 10 records per page and want to start on
8662 * the third page, it should be "20".
8668 * $(document).ready( function() {
8669 * $('#example').dataTable( {
8670 * "iDisplayStart": 20
8678 * The scroll gap is the amount of scrolling that is left to go before
8679 * DataTables will load the next 'page' of data automatically. You typically
8680 * want a gap which is big enough that the scrolling will be smooth for the
8681 * user, while not so large that it will load more data than need.
8687 * $(document).ready(function() {
8688 * $('#example').dataTable( {
8689 * "bScrollInfinite": true,
8690 * "bScrollCollapse": true,
8691 * "sScrollY": "200px",
8692 * "iScrollLoadGap": 50
8696 "iScrollLoadGap": 100,
8700 * By default DataTables allows keyboard navigation of the table (sorting, paging,
8701 * and filtering) by adding a tabindex attribute to the required elements. This
8702 * allows you to tab through the controls and press the enter key to activate them.
8703 * The tabindex is default 0, meaning that the tab follows the flow of the document.
8704 * You can overrule this using this parameter if you wish. Use a value of -1 to
8705 * disable built-in keyboard navigation.
8711 * $(document).ready(function() {
8712 * $('#example').dataTable( {
8721 * All strings that DataTables uses in the user interface that it creates
8722 * are defined in this object, allowing you to modified them individually or
8723 * completely replace them all as required.
8728 * Strings that are used for WAI-ARIA labels and controls only (these are not
8729 * actually visible on the page, but will be read by screenreaders, and thus
8730 * must be internationalised as well).
8735 * ARIA label that is added to the table headers when the column may be
8736 * sorted ascending by activing the column (click or return when focused).
8737 * Note that the column header is prefixed to this string.
8739 * @default : activate to sort column ascending
8743 * $(document).ready(function() {
8744 * $('#example').dataTable( {
8747 * "sSortAscending": " - click/return to sort ascending"
8753 "sSortAscending": ": activate to sort column ascending",
8756 * ARIA label that is added to the table headers when the column may be
8757 * sorted descending by activing the column (click or return when focused).
8758 * Note that the column header is prefixed to this string.
8760 * @default : activate to sort column ascending
8764 * $(document).ready(function() {
8765 * $('#example').dataTable( {
8768 * "sSortDescending": " - click/return to sort descending"
8774 "sSortDescending": ": activate to sort column descending"
8778 * Pagination string used by DataTables for the two built-in pagination
8779 * control types ("two_button" and "full_numbers")
8784 * Text to use when using the 'full_numbers' type of pagination for the
8785 * button to take the user to the first page.
8791 * $(document).ready(function() {
8792 * $('#example').dataTable( {
8795 * "sFirst": "First page"
8805 * Text to use when using the 'full_numbers' type of pagination for the
8806 * button to take the user to the last page.
8812 * $(document).ready(function() {
8813 * $('#example').dataTable( {
8816 * "sLast": "Last page"
8826 * Text to use when using the 'full_numbers' type of pagination for the
8827 * button to take the user to the next page.
8833 * $(document).ready(function() {
8834 * $('#example').dataTable( {
8837 * "sNext": "Next page"
8847 * Text to use when using the 'full_numbers' type of pagination for the
8848 * button to take the user to the previous page.
8854 * $(document).ready(function() {
8855 * $('#example').dataTable( {
8858 * "sPrevious": "Previous page"
8864 "sPrevious": "Previous"
8868 * This string is shown in preference to sZeroRecords when the table is
8869 * empty of data (regardless of filtering). Note that this is an optional
8870 * parameter - if it is not given, the value of sZeroRecords will be used
8871 * instead (either the default or given value).
8873 * @default No data available in table
8877 * $(document).ready(function() {
8878 * $('#example').dataTable( {
8880 * "sEmptyTable": "No data available in table"
8885 "sEmptyTable": "No data available in table",
8889 * This string gives information to the end user about the information that
8890 * is current on display on the page. The _START_, _END_ and _TOTAL_
8891 * variables are all dynamically replaced as the table display updates, and
8892 * can be freely moved or removed as the language requirements change.
8894 * @default Showing _START_ to _END_ of _TOTAL_ entries
8898 * $(document).ready(function() {
8899 * $('#example').dataTable( {
8901 * "sInfo": "Got a total of _TOTAL_ entries to show (_START_ to _END_)"
8906 "sInfo": "Showing _START_ to _END_ of _TOTAL_ entries",
8910 * Display information string for when the table is empty. Typically the
8911 * format of this string should match sInfo.
8913 * @default Showing 0 to 0 of 0 entries
8917 * $(document).ready(function() {
8918 * $('#example').dataTable( {
8920 * "sInfoEmpty": "No entries to show"
8925 "sInfoEmpty": "Showing 0 to 0 of 0 entries",
8929 * When a user filters the information in a table, this string is appended
8930 * to the information (sInfo) to give an idea of how strong the filtering
8931 * is. The variable _MAX_ is dynamically updated.
8933 * @default (filtered from _MAX_ total entries)
8937 * $(document).ready(function() {
8938 * $('#example').dataTable( {
8940 * "sInfoFiltered": " - filtering from _MAX_ records"
8945 "sInfoFiltered": "(filtered from _MAX_ total entries)",
8949 * If can be useful to append extra information to the info string at times,
8950 * and this variable does exactly that. This information will be appended to
8951 * the sInfo (sInfoEmpty and sInfoFiltered in whatever combination they are
8952 * being used) at all times.
8954 * @default <i>Empty string</i>
8958 * $(document).ready(function() {
8959 * $('#example').dataTable( {
8961 * "sInfoPostFix": "All records shown are derived from real information."
8970 * DataTables has a build in number formatter (fnFormatNumber) which is used
8971 * to format large numbers that are used in the table information. By
8972 * default a comma is used, but this can be trivially changed to any
8973 * character you wish with this parameter.
8979 * $(document).ready(function() {
8980 * $('#example').dataTable( {
8982 * "sInfoThousands": "'"
8987 "sInfoThousands": ",",
8991 * Detail the action that will be taken when the drop down menu for the
8992 * pagination length option is changed. The '_MENU_' variable is replaced
8993 * with a default select list of 10, 25, 50 and 100, and can be replaced
8994 * with a custom select box if required.
8996 * @default Show _MENU_ entries
9000 * // Language change only
9001 * $(document).ready(function() {
9002 * $('#example').dataTable( {
9004 * "sLengthMenu": "Display _MENU_ records"
9010 * // Language and options change
9011 * $(document).ready(function() {
9012 * $('#example').dataTable( {
9014 * "sLengthMenu": 'Display <select>'+
9015 * '<option value="10">10</option>'+
9016 * '<option value="20">20</option>'+
9017 * '<option value="30">30</option>'+
9018 * '<option value="40">40</option>'+
9019 * '<option value="50">50</option>'+
9020 * '<option value="-1">All</option>'+
9021 * '</select> records'
9026 "sLengthMenu": "Show _MENU_ entries",
9030 * When using Ajax sourced data and during the first draw when DataTables is
9031 * gathering the data, this message is shown in an empty row in the table to
9032 * indicate to the end user the the data is being loaded. Note that this
9033 * parameter is not used when loading data by server-side processing, just
9034 * Ajax sourced data with client-side processing.
9036 * @default Loading...
9040 * $(document).ready( function() {
9041 * $('#example').dataTable( {
9043 * "sLoadingRecords": "Please wait - loading..."
9048 "sLoadingRecords": "Loading...",
9052 * Text which is displayed when the table is processing a user action
9053 * (usually a sort command or similar).
9055 * @default Processing...
9059 * $(document).ready(function() {
9060 * $('#example').dataTable( {
9062 * "sProcessing": "DataTables is currently busy"
9067 "sProcessing": "Processing...",
9071 * Details the actions that will be taken when the user types into the
9072 * filtering input text box. The variable "_INPUT_", if used in the string,
9073 * is replaced with the HTML text box for the filtering input allowing
9074 * control over where it appears in the string. If "_INPUT_" is not given
9075 * then the input box is appended to the string automatically.
9081 * // Input text box will be appended at the end automatically
9082 * $(document).ready(function() {
9083 * $('#example').dataTable( {
9085 * "sSearch": "Filter records:"
9091 * // Specify where the filter should appear
9092 * $(document).ready(function() {
9093 * $('#example').dataTable( {
9095 * "sSearch": "Apply filter _INPUT_ to table"
9100 "sSearch": "Search:",
9104 * All of the language information can be stored in a file on the
9105 * server-side, which DataTables will look up if this parameter is passed.
9106 * It must store the URL of the language file, which is in a JSON format,
9107 * and the object has the same properties as the oLanguage object in the
9108 * initialiser object (i.e. the above parameters). Please refer to one of
9109 * the example language files to see how this works in action.
9111 * @default <i>Empty string - i.e. disabled</i>
9115 * $(document).ready(function() {
9116 * $('#example').dataTable( {
9118 * "sUrl": "http://www.sprymedia.co.uk/dataTables/lang.txt"
9127 * Text shown inside the table records when the is no information to be
9128 * displayed after filtering. sEmptyTable is shown when there is simply no
9129 * information in the table at all (regardless of filtering).
9131 * @default No matching records found
9135 * $(document).ready(function() {
9136 * $('#example').dataTable( {
9138 * "sZeroRecords": "No records to display"
9143 "sZeroRecords": "No matching records found"
9148 * This parameter allows you to have define the global filtering state at
9149 * initialisation time. As an object the "sSearch" parameter must be
9150 * defined, but all other parameters are optional. When "bRegex" is true,
9151 * the search string will be treated as a regular expression, when false
9152 * (default) it will be treated as a straight string. When "bSmart"
9153 * DataTables will use it's smart filtering methods (to word match at
9154 * any point in the data), when false this will not be done.
9156 * @extends DataTable.models.oSearch
9160 * $(document).ready( function() {
9161 * $('#example').dataTable( {
9162 * "oSearch": {"sSearch": "Initial search"}
9166 "oSearch": $.extend( {}, DataTable.models.oSearch ),
9170 * By default DataTables will look for the property 'aaData' when obtaining
9171 * data from an Ajax source or for server-side processing - this parameter
9172 * allows that property to be changed. You can use Javascript dotted object
9173 * notation to get a data source for multiple levels of nesting.
9177 * @dtopt Server-side
9180 * // Get data from { "data": [...] }
9181 * $(document).ready(function() {
9182 * var oTable = $('#example').dataTable( {
9183 * "sAjaxSource": "sources/data.txt",
9184 * "sAjaxDataProp": "data"
9189 * // Get data from { "data": { "inner": [...] } }
9190 * $(document).ready(function() {
9191 * var oTable = $('#example').dataTable( {
9192 * "sAjaxSource": "sources/data.txt",
9193 * "sAjaxDataProp": "data.inner"
9197 "sAjaxDataProp": "aaData",
9201 * You can instruct DataTables to load data from an external source using this
9202 * parameter (use aData if you want to pass data in you already have). Simply
9203 * provide a url a JSON object can be obtained from. This object must include
9204 * the parameter 'aaData' which is the data source for the table.
9208 * @dtopt Server-side
9211 * $(document).ready( function() {
9212 * $('#example').dataTable( {
9213 * "sAjaxSource": "http://www.sprymedia.co.uk/dataTables/json.php"
9217 "sAjaxSource": null,
9221 * This parameter can be used to override the default prefix that DataTables
9222 * assigns to a cookie when state saving is enabled.
9224 * @default SpryMedia_DataTables_
9228 * $(document).ready(function() {
9229 * $('#example').dataTable( {
9230 * "sCookiePrefix": "my_datatable_",
9234 "sCookiePrefix": "SpryMedia_DataTables_",
9238 * This initialisation variable allows you to specify exactly where in the
9239 * DOM you want DataTables to inject the various controls it adds to the page
9240 * (for example you might want the pagination controls at the top of the
9241 * table). DIV elements (with or without a custom class) can also be added to
9242 * aid styling. The follow syntax is used:
9244 * <li>The following options are allowed:
9246 * <li>'l' - Length changing</li
9247 * <li>'f' - Filtering input</li>
9248 * <li>'t' - The table!</li>
9249 * <li>'i' - Information</li>
9250 * <li>'p' - Pagination</li>
9251 * <li>'r' - pRocessing</li>
9254 * <li>The following constants are allowed:
9256 * <li>'H' - jQueryUI theme "header" classes ('fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix')</li>
9257 * <li>'F' - jQueryUI theme "footer" classes ('fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix')</li>
9260 * <li>The following syntax is expected:
9262 * <li>'<' and '>' - div elements</li>
9263 * <li>'<"class" and '>' - div with a class</li>
9264 * <li>'<"#id" and '>' - div with an ID</li>
9269 * <li>'<"wrapper"flipt>'</li>
9270 * <li>'<lf<t>ip>'</li>
9275 * @default lfrtip <i>(when bJQueryUI is false)</i> <b>or</b>
9276 * <"H"lfr>t<"F"ip> <i>(when bJQueryUI is true)</i>
9280 * $(document).ready(function() {
9281 * $('#example').dataTable( {
9282 * "sDom": '<"top"i>rt<"bottom"flp><"clear"&lgt;'
9290 * DataTables features two different built-in pagination interaction methods
9291 * ('two_button' or 'full_numbers') which present different page controls to
9292 * the end user. Further methods can be added using the API (see below).
9294 * @default two_button
9298 * $(document).ready( function() {
9299 * $('#example').dataTable( {
9300 * "sPaginationType": "full_numbers"
9304 "sPaginationType": "two_button",
9308 * Enable horizontal scrolling. When a table is too wide to fit into a certain
9309 * layout, or you have a large number of columns in the table, you can enable
9310 * x-scrolling to show the table in a viewport, which can be scrolled. This
9311 * property can by any CSS unit, or a number (in which case it will be treated
9312 * as a pixel measurement).
9314 * @default <i>blank string - i.e. disabled</i>
9318 * $(document).ready(function() {
9319 * $('#example').dataTable( {
9320 * "sScrollX": "100%",
9321 * "bScrollCollapse": true
9329 * This property can be used to force a DataTable to use more width than it
9330 * might otherwise do when x-scrolling is enabled. For example if you have a
9331 * table which requires to be well spaced, this parameter is useful for
9332 * "over-sizing" the table, and thus forcing scrolling. This property can by
9333 * any CSS unit, or a number (in which case it will be treated as a pixel
9336 * @default <i>blank string - i.e. disabled</i>
9340 * $(document).ready(function() {
9341 * $('#example').dataTable( {
9342 * "sScrollX": "100%",
9343 * "sScrollXInner": "110%"
9347 "sScrollXInner": "",
9351 * Enable vertical scrolling. Vertical scrolling will constrain the DataTable
9352 * to the given height, an enable scrolling for any data which overflows the
9353 * current viewport. This can be used as an alternative to paging to display
9354 * a lot of data in a small area (although paging and scrolling can both be
9355 * enabled at the same time). This property can by any CSS unit, or a number
9356 * (in which case it will be treated as a pixel measurement).
9358 * @default <i>blank string - i.e. disabled</i>
9362 * $(document).ready(function() {
9363 * $('#example').dataTable( {
9364 * "sScrollY": "200px",
9365 * "bPaginate": false
9373 * Set the HTTP method that is used to make the Ajax call for server-side
9374 * processing or Ajax sourced data.
9378 * @dtopt Server-side
9381 * $(document).ready(function() {
9382 * $('#example').dataTable( {
9383 * "bServerSide": true,
9384 * "sAjaxSource": "scripts/post.php",
9385 * "sServerMethod": "POST"
9389 "sServerMethod": "GET"
9395 * Column options that can be given to DataTables at initialisation time.
9398 DataTable.defaults.columns = {
9400 * Allows a column's sorting to take multiple columns into account when
9401 * doing a sort. For example first name / last name columns make sense to
9402 * do a multi-column sort over the two columns.
9404 * @default null <i>Takes the value of the column index automatically</i>
9408 * // Using aoColumnDefs
9409 * $(document).ready(function() {
9410 * $('#example').dataTable( {
9412 * { "aDataSort": [ 0, 1 ], "aTargets": [ 0 ] },
9413 * { "aDataSort": [ 1, 0 ], "aTargets": [ 1 ] },
9414 * { "aDataSort": [ 2, 3, 4 ], "aTargets": [ 2 ] }
9420 * // Using aoColumns
9421 * $(document).ready(function() {
9422 * $('#example').dataTable( {
9424 * { "aDataSort": [ 0, 1 ] },
9425 * { "aDataSort": [ 1, 0 ] },
9426 * { "aDataSort": [ 2, 3, 4 ] },
9437 * You can control the default sorting direction, and even alter the behaviour
9438 * of the sort handler (i.e. only allow ascending sorting etc) using this
9441 * @default [ 'asc', 'desc' ]
9445 * // Using aoColumnDefs
9446 * $(document).ready(function() {
9447 * $('#example').dataTable( {
9449 * { "asSorting": [ "asc" ], "aTargets": [ 1 ] },
9450 * { "asSorting": [ "desc", "asc", "asc" ], "aTargets": [ 2 ] },
9451 * { "asSorting": [ "desc" ], "aTargets": [ 3 ] }
9457 * // Using aoColumns
9458 * $(document).ready(function() {
9459 * $('#example').dataTable( {
9462 * { "asSorting": [ "asc" ] },
9463 * { "asSorting": [ "desc", "asc", "asc" ] },
9464 * { "asSorting": [ "desc" ] },
9470 "asSorting": [ 'asc', 'desc' ],
9474 * Enable or disable filtering on the data in this column.
9480 * // Using aoColumnDefs
9481 * $(document).ready(function() {
9482 * $('#example').dataTable( {
9484 * { "bSearchable": false, "aTargets": [ 0 ] }
9489 * // Using aoColumns
9490 * $(document).ready(function() {
9491 * $('#example').dataTable( {
9493 * { "bSearchable": false },
9501 "bSearchable": true,
9505 * Enable or disable sorting on this column.
9511 * // Using aoColumnDefs
9512 * $(document).ready(function() {
9513 * $('#example').dataTable( {
9515 * { "bSortable": false, "aTargets": [ 0 ] }
9520 * // Using aoColumns
9521 * $(document).ready(function() {
9522 * $('#example').dataTable( {
9524 * { "bSortable": false },
9536 * When using fnRender() for a column, you may wish to use the original data
9537 * (before rendering) for sorting and filtering (the default is to used the
9538 * rendered data that the user can see). This may be useful for dates etc.
9540 * *NOTE* It is it is advisable now to use mDataProp as a function and make
9541 * use of the 'type' that it gives, allowing (potentially) different data to
9542 * be used for sorting, filtering, display and type detection.
9548 * // Using aoColumnDefs
9549 * $(document).ready(function() {
9550 * $('#example').dataTable( {
9553 * "fnRender": function ( oObj ) {
9554 * return oObj.aData[0] +' '+ oObj.aData[3];
9556 * "bUseRendered": false,
9564 * // Using aoColumns
9565 * $(document).ready(function() {
9566 * $('#example').dataTable( {
9569 * "fnRender": function ( oObj ) {
9570 * return oObj.aData[0] +' '+ oObj.aData[3];
9572 * "bUseRendered": false
9582 "bUseRendered": true,
9586 * Enable or disable the display of this column.
9592 * // Using aoColumnDefs
9593 * $(document).ready(function() {
9594 * $('#example').dataTable( {
9596 * { "bVisible": false, "aTargets": [ 0 ] }
9601 * // Using aoColumns
9602 * $(document).ready(function() {
9603 * $('#example').dataTable( {
9605 * { "bVisible": false },
9617 * Developer definable function that is called whenever a cell is created (Ajax source,
9618 * etc) or processed for input (DOM source). This can be used as a compliment to fnRender
9619 * allowing you to modify the DOM element (add background colour for example) when the
9620 * element is available (since it is not when fnRender is called).
9622 * @param {element} nTd The TD node that has been created
9623 * @param {*} sData The Data for the cell
9624 * @param {array|object} oData The data for the whole row
9625 * @param {int} iRow The row index for the aoData data store
9626 * @param {int} iCol The column index for aoColumns
9630 * $(document).ready(function() {
9631 * $('#example').dataTable( {
9632 * "aoColumnDefs": [ {
9634 * "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
9635 * if ( sData == "1.7" ) {
9636 * $(nTd).css('color', 'blue')
9643 "fnCreatedCell": null,
9647 * Custom display function that will be called for the display of each cell in
9650 * @param {object} o Object with the following parameters:
9651 * @param {int} o.iDataRow The row in aoData
9652 * @param {int} o.iDataColumn The column in question
9653 * @param {array} o.aData The data for the row in question
9654 * @param {object} o.oSettings The settings object for this DataTables instance
9655 * @param {object} o.mDataProp The data property used for this column
9656 * @param {*} val The current cell value
9657 * @returns {string} The string you which to use in the display
9661 * // Using aoColumnDefs
9662 * $(document).ready(function() {
9663 * $('#example').dataTable( {
9666 * "fnRender": function ( o, val ) {
9667 * return o.aData[0] +' '+ o.aData[3];
9676 * // Using aoColumns
9677 * $(document).ready(function() {
9678 * $('#example').dataTable( {
9680 * { "fnRender": function ( o, val ) {
9681 * return o.aData[0] +' '+ o.aData[3];
9695 * The column index (starting from 0!) that you wish a sort to be performed
9696 * upon when this column is selected for sorting. This can be used for sorting
9697 * on hidden columns for example.
9699 * @default -1 <i>Use automatically calculated column index</i>
9703 * // Using aoColumnDefs
9704 * $(document).ready(function() {
9705 * $('#example').dataTable( {
9707 * { "iDataSort": 1, "aTargets": [ 0 ] }
9713 * // Using aoColumns
9714 * $(document).ready(function() {
9715 * $('#example').dataTable( {
9717 * { "iDataSort": 1 },
9730 * This property can be used to read data from any JSON data source property,
9731 * including deeply nested objects / properties. mDataProp can be given in a
9732 * number of different ways which effect its behaviour:
9734 * <li>integer - treated as an array index for the data source. This is the
9735 * default that DataTables uses (incrementally increased for each column).</li>
9736 * <li>string - read an object property from the data source. Note that you can
9737 * use Javascript dotted notation to read deep properties/arrays from the
9739 * <li>null - the sDafaultContent option will use used for the cell (empty
9740 * string by default. This can be useful on generated columns such as
9741 * edit / delete action columns.</li>
9742 * <li>function - the function given will be executed whenever DataTables
9743 * needs to set or get the data for a cell in the column. The function
9744 * takes three parameters:
9746 * <li>{array|object} The data source for the row</li>
9747 * <li>{string} The type call data requested - this will be 'set' when
9748 * setting data or 'filter', 'display', 'type' or 'sort' when gathering
9750 * <li>{*} Data to set when the second parameter is 'set'.</li>
9752 * The return value from the function is not required when 'set' is the type
9753 * of call, but otherwise the return is what will be used for the data
9756 * @type string|int|function|null
9757 * @default null <i>Use automatically calculated column index</i>
9761 * // Read table data from objects
9762 * $(document).ready(function() {
9763 * var oTable = $('#example').dataTable( {
9764 * "sAjaxSource": "sources/deep.txt",
9766 * { "mDataProp": "engine" },
9767 * { "mDataProp": "browser" },
9768 * { "mDataProp": "platform.inner" },
9769 * { "mDataProp": "platform.details.0" },
9770 * { "mDataProp": "platform.details.1" }
9776 * // Using mDataProp as a function to provide different information for
9777 * // sorting, filtering and display. In this case, currency (price)
9778 * $(document).ready(function() {
9779 * var oTable = $('#example').dataTable( {
9782 * "aTargets": [ 0 ],
9783 * "mDataProp": function ( source, type, val ) {
9784 * if (type === 'set') {
9785 * source.price = val;
9786 * // Store the computed dislay and filter values for efficiency
9787 * source.price_display = val=="" ? "" : "$"+numberFormat(val);
9788 * source.price_filter = val=="" ? "" : "$"+numberFormat(val)+" "+val;
9791 * else if (type === 'display') {
9792 * return source.price_display;
9794 * else if (type === 'filter') {
9795 * return source.price_filter;
9797 * // 'sort' and 'type' both just use the integer
9798 * return source.price;
9808 * Class to give to each cell in this column.
9810 * @default <i>Empty string</i>
9814 * // Using aoColumnDefs
9815 * $(document).ready(function() {
9816 * $('#example').dataTable( {
9818 * { "sClass": "my_class", "aTargets": [ 0 ] }
9824 * // Using aoColumns
9825 * $(document).ready(function() {
9826 * $('#example').dataTable( {
9828 * { "sClass": "my_class" },
9840 * When DataTables calculates the column widths to assign to each column,
9841 * it finds the longest string in each column and then constructs a
9842 * temporary table and reads the widths from that. The problem with this
9843 * is that "mmm" is much wider then "iiii", but the latter is a longer
9844 * string - thus the calculation can go wrong (doing it properly and putting
9845 * it into an DOM object and measuring that is horribly(!) slow). Thus as
9846 * a "work around" we provide this option. It will append its value to the
9847 * text that is found to be the longest string for the column - i.e. padding.
9848 * Generally you shouldn't need this, and it is not documented on the
9849 * general DataTables.net documentation
9851 * @default <i>Empty string<i>
9855 * // Using aoColumns
9856 * $(document).ready(function() {
9857 * $('#example').dataTable( {
9863 * "sContentPadding": "mmm"
9869 "sContentPadding": "",
9873 * Allows a default value to be given for a column's data, and will be used
9874 * whenever a null data source is encountered (this can be because mDataProp
9875 * is set to null, or because the data source itself is null).
9881 * // Using aoColumnDefs
9882 * $(document).ready(function() {
9883 * $('#example').dataTable( {
9886 * "mDataProp": null,
9887 * "sDefaultContent": "Edit",
9888 * "aTargets": [ -1 ]
9895 * // Using aoColumns
9896 * $(document).ready(function() {
9897 * $('#example').dataTable( {
9903 * "mDataProp": null,
9904 * "sDefaultContent": "Edit"
9910 "sDefaultContent": null,
9914 * This parameter is only used in DataTables' server-side processing. It can
9915 * be exceptionally useful to know what columns are being displayed on the
9916 * client side, and to map these to database fields. When defined, the names
9917 * also allow DataTables to reorder information from the server if it comes
9918 * back in an unexpected order (i.e. if you switch your columns around on the
9919 * client-side, your server-side code does not also need updating).
9921 * @default <i>Empty string</i>
9925 * // Using aoColumnDefs
9926 * $(document).ready(function() {
9927 * $('#example').dataTable( {
9929 * { "sName": "engine", "aTargets": [ 0 ] },
9930 * { "sName": "browser", "aTargets": [ 1 ] },
9931 * { "sName": "platform", "aTargets": [ 2 ] },
9932 * { "sName": "version", "aTargets": [ 3 ] },
9933 * { "sName": "grade", "aTargets": [ 4 ] }
9939 * // Using aoColumns
9940 * $(document).ready(function() {
9941 * $('#example').dataTable( {
9943 * { "sName": "engine" },
9944 * { "sName": "browser" },
9945 * { "sName": "platform" },
9946 * { "sName": "version" },
9947 * { "sName": "grade" }
9956 * Defines a data source type for the sorting which can be used to read
9957 * realtime information from the table (updating the internally cached
9958 * version) prior to sorting. This allows sorting to occur on user editable
9959 * elements such as form inputs.
9965 * // Using aoColumnDefs
9966 * $(document).ready(function() {
9967 * $('#example').dataTable( {
9969 * { "sSortDataType": "dom-text", "aTargets": [ 2, 3 ] },
9970 * { "sType": "numeric", "aTargets": [ 3 ] },
9971 * { "sSortDataType": "dom-select", "aTargets": [ 4 ] },
9972 * { "sSortDataType": "dom-checkbox", "aTargets": [ 5 ] }
9978 * // Using aoColumns
9979 * $(document).ready(function() {
9980 * $('#example').dataTable( {
9984 * { "sSortDataType": "dom-text" },
9985 * { "sSortDataType": "dom-text", "sType": "numeric" },
9986 * { "sSortDataType": "dom-select" },
9987 * { "sSortDataType": "dom-checkbox" }
9992 "sSortDataType": "std",
9996 * The title of this column.
9998 * @default null <i>Derived from the 'TH' value for this column in the
9999 * original HTML table.</i>
10003 * // Using aoColumnDefs
10004 * $(document).ready(function() {
10005 * $('#example').dataTable( {
10006 * "aoColumnDefs": [
10007 * { "sTitle": "My column title", "aTargets": [ 0 ] }
10013 * // Using aoColumns
10014 * $(document).ready(function() {
10015 * $('#example').dataTable( {
10017 * { "sTitle": "My column title" },
10030 * The type allows you to specify how the data for this column will be sorted.
10031 * Four types (string, numeric, date and html (which will strip HTML tags
10032 * before sorting)) are currently available. Note that only date formats
10033 * understood by Javascript's Date() object will be accepted as type date. For
10034 * example: "Mar 26, 2008 5:03 PM". May take the values: 'string', 'numeric',
10035 * 'date' or 'html' (by default). Further types can be adding through
10038 * @default null <i>Auto-detected from raw data</i>
10042 * // Using aoColumnDefs
10043 * $(document).ready(function() {
10044 * $('#example').dataTable( {
10045 * "aoColumnDefs": [
10046 * { "sType": "html", "aTargets": [ 0 ] }
10052 * // Using aoColumns
10053 * $(document).ready(function() {
10054 * $('#example').dataTable( {
10056 * { "sType": "html" },
10069 * Defining the width of the column, this parameter may take any CSS value
10070 * (3em, 20px etc). DataTables applys 'smart' widths to columns which have not
10071 * been given a specific width through this interface ensuring that the table
10072 * remains readable.
10074 * @default null <i>Automatic</i>
10078 * // Using aoColumnDefs
10079 * $(document).ready(function() {
10080 * $('#example').dataTable( {
10081 * "aoColumnDefs": [
10082 * { "sWidth": "20%", "aTargets": [ 0 ] }
10088 * // Using aoColumns
10089 * $(document).ready(function() {
10090 * $('#example').dataTable( {
10092 * { "sWidth": "20%" },
10107 * DataTables settings object - this holds all the information needed for a
10108 * given table, including configuration, data and current application of the
10109 * table options. DataTables does not have a single instance for each DataTable
10110 * with the settings attached to that instance, but rather instances of the
10111 * DataTable "class" are created on-the-fly as needed (typically by a
10112 * $().dataTable() call) and the settings object is then applied to that
10115 * Note that this object is related to {@link DataTable.defaults} but this
10116 * one is the internal data store for DataTables's cache of columns. It should
10117 * NOT be manipulated outside of DataTables. Any configuration should be done
10118 * through the initialisation options.
10120 * @todo Really should attach the settings object to individual instances so we
10121 * don't need to create new instances on each $().dataTable() call (if the
10122 * table already exists). It would also save passing oSettings around and
10123 * into every single function. However, this is a very significant
10124 * architecture change for DataTables and will almost certainly break
10125 * backwards compatibility with older installations. This is something that
10126 * will be done in 2.0.
10128 DataTable.models.oSettings = {
10130 * Primary features of DataTables and their enablement state.
10136 * Flag to say if DataTables should automatically try to calculate the
10137 * optimum table and columns widths (true) or not (false).
10138 * Note that this parameter will be set by the initialisation routine. To
10139 * set a default use {@link DataTable.defaults}.
10142 "bAutoWidth": null,
10145 * Delay the creation of TR and TD elements until they are actually
10146 * needed by a driven page draw. This can give a significant speed
10147 * increase for Ajax source and Javascript source data, but makes no
10148 * difference at all fro DOM and server-side processing tables.
10149 * Note that this parameter will be set by the initialisation routine. To
10150 * set a default use {@link DataTable.defaults}.
10153 "bDeferRender": null,
10156 * Enable filtering on the table or not. Note that if this is disabled
10157 * then there is no filtering at all on the table, including fnFilter.
10158 * To just remove the filtering input use sDom and remove the 'f' option.
10159 * Note that this parameter will be set by the initialisation routine. To
10160 * set a default use {@link DataTable.defaults}.
10166 * Table information element (the 'Showing x of y records' div) enable
10168 * Note that this parameter will be set by the initialisation routine. To
10169 * set a default use {@link DataTable.defaults}.
10175 * Present a user control allowing the end user to change the page size
10176 * when pagination is enabled.
10177 * Note that this parameter will be set by the initialisation routine. To
10178 * set a default use {@link DataTable.defaults}.
10181 "bLengthChange": null,
10184 * Pagination enabled or not. Note that if this is disabled then length
10185 * changing must also be disabled.
10186 * Note that this parameter will be set by the initialisation routine. To
10187 * set a default use {@link DataTable.defaults}.
10193 * Processing indicator enable flag whenever DataTables is enacting a
10194 * user request - typically an Ajax request for server-side processing.
10195 * Note that this parameter will be set by the initialisation routine. To
10196 * set a default use {@link DataTable.defaults}.
10199 "bProcessing": null,
10202 * Server-side processing enabled flag - when enabled DataTables will
10203 * get all data from the server for every draw - there is no filtering,
10204 * sorting or paging done on the client-side.
10205 * Note that this parameter will be set by the initialisation routine. To
10206 * set a default use {@link DataTable.defaults}.
10209 "bServerSide": null,
10212 * Sorting enablement flag.
10213 * Note that this parameter will be set by the initialisation routine. To
10214 * set a default use {@link DataTable.defaults}.
10220 * Apply a class to the columns which are being sorted to provide a
10221 * visual highlight or not. This can slow things down when enabled since
10222 * there is a lot of DOM interaction.
10223 * Note that this parameter will be set by the initialisation routine. To
10224 * set a default use {@link DataTable.defaults}.
10227 "bSortClasses": null,
10230 * State saving enablement flag.
10231 * Note that this parameter will be set by the initialisation routine. To
10232 * set a default use {@link DataTable.defaults}.
10240 * Scrolling settings for a table.
10245 * Indicate if DataTables should be allowed to set the padding / margin
10246 * etc for the scrolling header elements or not. Typically you will want
10248 * Note that this parameter will be set by the initialisation routine. To
10249 * set a default use {@link DataTable.defaults}.
10255 * When the table is shorter in height than sScrollY, collapse the
10256 * table container down to the height of the table (when true).
10257 * Note that this parameter will be set by the initialisation routine. To
10258 * set a default use {@link DataTable.defaults}.
10264 * Infinite scrolling enablement flag. Now deprecated in favour of
10265 * using the Scroller plug-in.
10266 * Note that this parameter will be set by the initialisation routine. To
10267 * set a default use {@link DataTable.defaults}.
10273 * Width of the scrollbar for the web-browser's platform. Calculated
10274 * during table initialisation.
10281 * Space (in pixels) between the bottom of the scrolling container and
10282 * the bottom of the scrolling viewport before the next page is loaded
10283 * when using infinite scrolling.
10284 * Note that this parameter will be set by the initialisation routine. To
10285 * set a default use {@link DataTable.defaults}.
10291 * Viewport width for horizontal scrolling. Horizontal scrolling is
10292 * disabled if an empty string.
10293 * Note that this parameter will be set by the initialisation routine. To
10294 * set a default use {@link DataTable.defaults}.
10300 * Width to expand the table to when using x-scrolling. Typically you
10301 * should not need to use this.
10302 * Note that this parameter will be set by the initialisation routine. To
10303 * set a default use {@link DataTable.defaults}.
10310 * Viewport height for vertical scrolling. Vertical scrolling is disabled
10311 * if an empty string.
10312 * Note that this parameter will be set by the initialisation routine. To
10313 * set a default use {@link DataTable.defaults}.
10320 * Language information for the table.
10322 * @extends DataTable.defaults.oLanguage
10326 * Information callback function. See
10327 * {@link DataTable.defaults.fnInfoCallback}
10331 "fnInfoCallback": null
10335 * Array referencing the nodes which are used for the features. The
10336 * parameters of this object match what is allowed by sDom - i.e.
10338 * <li>'l' - Length changing</li>
10339 * <li>'f' - Filtering input</li>
10340 * <li>'t' - The table!</li>
10341 * <li>'i' - Information</li>
10342 * <li>'p' - Pagination</li>
10343 * <li>'r' - pRocessing</li>
10351 * Store data information - see {@link DataTable.models.oRow} for detailed
10359 * Array of indexes which are in the current display (after filtering etc)
10366 * Array of indexes for display - no filtering
10370 "aiDisplayMaster": [],
10373 * Store information about each column that is in use
10380 * Store information about the table's header
10387 * Store information about the table's footer
10394 * Search data array for regular expression searching
10398 "asDataSearch": [],
10401 * Store the applied global search information in case we want to force a
10402 * research or compare the old search to a new one.
10403 * Note that this parameter will be set by the initialisation routine. To
10404 * set a default use {@link DataTable.defaults}.
10406 * @extends DataTable.models.oSearch
10408 "oPreviousSearch": {},
10411 * Store the applied search for each column - see
10412 * {@link DataTable.models.oSearch} for the format that is used for the
10413 * filtering information for each column.
10417 "aoPreSearchCols": [],
10420 * Sorting that is applied to the table. Note that the inner arrays are
10421 * used in the following manner:
10423 * <li>Index 0 - column number</li>
10424 * <li>Index 1 - current sorting direction</li>
10425 * <li>Index 2 - index of asSorting for this column</li>
10427 * Note that this parameter will be set by the initialisation routine. To
10428 * set a default use {@link DataTable.defaults}.
10430 * @todo These inner arrays should really be objects
10435 * Sorting that is always applied to the table (i.e. prefixed in front of
10437 * Note that this parameter will be set by the initialisation routine. To
10438 * set a default use {@link DataTable.defaults}.
10442 "aaSortingFixed": null,
10445 * Classes to use for the striping of a table.
10446 * Note that this parameter will be set by the initialisation routine. To
10447 * set a default use {@link DataTable.defaults}.
10451 "asStripeClasses": null,
10454 * If restoring a table - we should restore its striping classes as well
10458 "asDestroyStripes": [],
10461 * If restoring a table - we should restore its width
10465 "sDestroyWidth": 0,
10468 * Callback functions array for every time a row is inserted (i.e. on a draw).
10472 "aoRowCallback": [],
10475 * Callback functions for the header on each draw.
10479 "aoHeaderCallback": [],
10482 * Callback function for the footer on each draw.
10486 "aoFooterCallback": [],
10489 * Array of callback functions for draw callback functions
10493 "aoDrawCallback": [],
10496 * Array of callback functions for row created function
10500 "aoRowCreatedCallback": [],
10503 * Callback functions for just before the table is redrawn. A return of
10504 * false will be used to cancel the draw.
10508 "aoPreDrawCallback": [],
10511 * Callback functions for when the table has been initialised.
10515 "aoInitComplete": [],
10519 * Callbacks for modifying the settings to be stored for state saving, prior to
10524 "aoStateSaveParams": [],
10527 * Callbacks for modifying the settings that have been stored for state saving
10528 * prior to using the stored values to restore the state.
10532 "aoStateLoadParams": [],
10535 * Callbacks for operating on the settings object once the saved state has been
10540 "aoStateLoaded": [],
10543 * Cache the table ID for quick access
10545 * @default <i>Empty string</i>
10550 * The TABLE node for the main table
10557 * Permanent ref to the thead element
10564 * Permanent ref to the tfoot element - if it exists
10571 * Permanent ref to the tbody element
10578 * Cache the wrapper node (contains all DataTables controlled elements)
10582 "nTableWrapper": null,
10585 * Indicate if when using server-side processing the loading of data
10586 * should be deferred until the second draw.
10587 * Note that this parameter will be set by the initialisation routine. To
10588 * set a default use {@link DataTable.defaults}.
10592 "bDeferLoading": false,
10595 * Indicate if all required information has been read in
10599 "bInitialised": false,
10602 * Information about open rows. Each object in the array has the parameters
10603 * 'nTr' and 'nParent'
10610 * Dictate the positioning of DataTables' control elements - see
10611 * {@link DataTable.model.oInit.sDom}.
10612 * Note that this parameter will be set by the initialisation routine. To
10613 * set a default use {@link DataTable.defaults}.
10620 * Which type of pagination should be used.
10621 * Note that this parameter will be set by the initialisation routine. To
10622 * set a default use {@link DataTable.defaults}.
10624 * @default two_button
10626 "sPaginationType": "two_button",
10629 * The cookie duration (for bStateSave) in seconds.
10630 * Note that this parameter will be set by the initialisation routine. To
10631 * set a default use {@link DataTable.defaults}.
10635 "iCookieDuration": 0,
10638 * The cookie name prefix.
10639 * Note that this parameter will be set by the initialisation routine. To
10640 * set a default use {@link DataTable.defaults}.
10642 * @default <i>Empty string</i>
10644 "sCookiePrefix": "",
10647 * Callback function for cookie creation.
10648 * Note that this parameter will be set by the initialisation routine. To
10649 * set a default use {@link DataTable.defaults}.
10653 "fnCookieCallback": null,
10656 * Array of callback functions for state saving. Each array element is an
10657 * object with the following parameters:
10659 * <li>function:fn - function to call. Takes two parameters, oSettings
10660 * and the JSON string to save that has been thus far created. Returns
10661 * a JSON string to be inserted into a json object
10662 * (i.e. '"param": [ 0, 1, 2]')</li>
10663 * <li>string:sName - name of callback</li>
10671 * Array of callback functions for state loading. Each array element is an
10672 * object with the following parameters:
10674 * <li>function:fn - function to call. Takes two parameters, oSettings
10675 * and the object stored. May return false to cancel state loading</li>
10676 * <li>string:sName - name of callback</li>
10684 * State that was loaded from the cookie. Useful for back reference
10688 "oLoadedState": null,
10691 * Source url for AJAX data for the table.
10692 * Note that this parameter will be set by the initialisation routine. To
10693 * set a default use {@link DataTable.defaults}.
10697 "sAjaxSource": null,
10700 * Property from a given object from which to read the table data from. This
10701 * can be an empty string (when not server-side processing), in which case
10702 * it is assumed an an array is given directly.
10703 * Note that this parameter will be set by the initialisation routine. To
10704 * set a default use {@link DataTable.defaults}.
10707 "sAjaxDataProp": null,
10710 * Note if draw should be blocked while getting data
10714 "bAjaxDataGet": true,
10717 * The last jQuery XHR object that was used for server-side data gathering.
10718 * This can be used for working with the XHR information in one of the
10726 * Function to get the server-side data.
10727 * Note that this parameter will be set by the initialisation routine. To
10728 * set a default use {@link DataTable.defaults}.
10731 "fnServerData": null,
10734 * Functions which are called prior to sending an Ajax request so extra
10735 * parameters can easily be sent to the server
10739 "aoServerParams": [],
10742 * Send the XHR HTTP method - GET or POST (could be PUT or DELETE if
10744 * Note that this parameter will be set by the initialisation routine. To
10745 * set a default use {@link DataTable.defaults}.
10748 "sServerMethod": null,
10751 * Format numbers for display.
10752 * Note that this parameter will be set by the initialisation routine. To
10753 * set a default use {@link DataTable.defaults}.
10756 "fnFormatNumber": null,
10759 * List of options that can be used for the user selectable length menu.
10760 * Note that this parameter will be set by the initialisation routine. To
10761 * set a default use {@link DataTable.defaults}.
10765 "aLengthMenu": null,
10768 * Counter for the draws that the table does. Also used as a tracker for
10769 * server-side processing
10776 * Indicate if a redraw is being done - useful for Ajax
10783 * Draw index (iDraw) of the last error when parsing the returned data
10790 * Paging display length
10794 "_iDisplayLength": 10,
10797 * Paging start point - aiDisplay index
10801 "_iDisplayStart": 0,
10804 * Paging end point - aiDisplay index. Use fnDisplayEnd rather than
10805 * this property to get the end point
10810 "_iDisplayEnd": 10,
10813 * Server-side processing - number of records in the result set
10814 * (i.e. before filtering), Use fnRecordsTotal rather than
10815 * this property to get the value of the number of records, regardless of
10816 * the server-side processing setting.
10821 "_iRecordsTotal": 0,
10824 * Server-side processing - number of records in the current display set
10825 * (i.e. after filtering). Use fnRecordsDisplay rather than
10826 * this property to get the value of the number of records, regardless of
10827 * the server-side processing setting.
10832 "_iRecordsDisplay": 0,
10835 * Flag to indicate if jQuery UI marking and classes should be used.
10836 * Note that this parameter will be set by the initialisation routine. To
10837 * set a default use {@link DataTable.defaults}.
10843 * The classes to use for the table
10850 * Flag attached to the settings object so you can check in the draw
10851 * callback if filtering has been done in the draw. Deprecated in favour of
10857 "bFiltered": false,
10860 * Flag attached to the settings object so you can check in the draw
10861 * callback if sorting has been done in the draw. Deprecated in favour of
10870 * Indicate that if multiple rows are in the header and there is more than
10871 * one unique cell per column, if the top one (true) or bottom one (false)
10872 * should be used for sorting / title by DataTables.
10873 * Note that this parameter will be set by the initialisation routine. To
10874 * set a default use {@link DataTable.defaults}.
10877 "bSortCellsTop": null,
10880 * Initialisation object that is used for the table
10887 * Destroy callback functions - for plug-ins to attach themselves to the
10888 * destroy so they can clean up markup and events.
10892 "aoDestroyCallback": [],
10896 * Get the number of records in the current record set, before filtering
10899 "fnRecordsTotal": function ()
10901 if ( this.oFeatures.bServerSide ) {
10902 return parseInt(this._iRecordsTotal, 10);
10904 return this.aiDisplayMaster.length;
10909 * Get the number of records in the current record set, after filtering
10912 "fnRecordsDisplay": function ()
10914 if ( this.oFeatures.bServerSide ) {
10915 return parseInt(this._iRecordsDisplay, 10);
10917 return this.aiDisplay.length;
10922 * Set the display end point - aiDisplay index
10924 * @todo Should do away with _iDisplayEnd and calculate it on-the-fly here
10926 "fnDisplayEnd": function ()
10928 if ( this.oFeatures.bServerSide ) {
10929 if ( this.oFeatures.bPaginate === false || this._iDisplayLength == -1 ) {
10930 return this._iDisplayStart+this.aiDisplay.length;
10932 return Math.min( this._iDisplayStart+this._iDisplayLength,
10933 this._iRecordsDisplay );
10936 return this._iDisplayEnd;
10941 * The DataTables object for this table
10948 * Unique identifier for each instance of the DataTables object. If there
10949 * is an ID on the table node, then it takes that value, otherwise an
10950 * incrementing internal counter is used.
10957 * tabindex attribute value that is added to DataTables control elements, allowing
10958 * keyboard navigation of the table and its controls.
10964 * Extension object for DataTables that is used to provide all extension options.
10966 * Note that the <i>DataTable.ext</i> object is available through
10967 * <i>jQuery.fn.dataTable.ext</i> where it may be accessed and manipulated. It is
10968 * also aliased to <i>jQuery.fn.dataTableExt</i> for historic reasons.
10970 * @extends DataTable.models.ext
10972 DataTable.ext = $.extend( true, {}, DataTable.models.ext );
10974 $.extend( DataTable.ext.oStdClasses, {
10975 "sTable": "dataTable",
10977 /* Two buttons buttons */
10978 "sPagePrevEnabled": "paginate_enabled_previous",
10979 "sPagePrevDisabled": "paginate_disabled_previous",
10980 "sPageNextEnabled": "paginate_enabled_next",
10981 "sPageNextDisabled": "paginate_disabled_next",
10982 "sPageJUINext": "",
10983 "sPageJUIPrev": "",
10985 /* Full numbers paging buttons */
10986 "sPageButton": "paginate_button",
10987 "sPageButtonActive": "paginate_active",
10988 "sPageButtonStaticDisabled": "paginate_button paginate_button_disabled",
10989 "sPageFirst": "first",
10990 "sPagePrevious": "previous",
10991 "sPageNext": "next",
10992 "sPageLast": "last",
10994 /* Striping classes */
10995 "sStripeOdd": "odd",
10996 "sStripeEven": "even",
10999 "sRowEmpty": "dataTables_empty",
11002 "sWrapper": "dataTables_wrapper",
11003 "sFilter": "dataTables_filter",
11004 "sInfo": "dataTables_info",
11005 "sPaging": "dataTables_paginate paging_", /* Note that the type is postfixed */
11006 "sLength": "dataTables_length",
11007 "sProcessing": "dataTables_processing",
11010 "sSortAsc": "sorting_asc",
11011 "sSortDesc": "sorting_desc",
11012 "sSortable": "sorting", /* Sortable in both directions */
11013 "sSortableAsc": "sorting_asc_disabled",
11014 "sSortableDesc": "sorting_desc_disabled",
11015 "sSortableNone": "sorting_disabled",
11016 "sSortColumn": "sorting_", /* Note that an int is postfixed for the sorting order */
11018 "sSortJUIDesc": "",
11020 "sSortJUIAscAllowed": "",
11021 "sSortJUIDescAllowed": "",
11022 "sSortJUIWrapper": "",
11026 "sScrollWrapper": "dataTables_scroll",
11027 "sScrollHead": "dataTables_scrollHead",
11028 "sScrollHeadInner": "dataTables_scrollHeadInner",
11029 "sScrollBody": "dataTables_scrollBody",
11030 "sScrollFoot": "dataTables_scrollFoot",
11031 "sScrollFootInner": "dataTables_scrollFootInner",
11038 $.extend( DataTable.ext.oJUIClasses, DataTable.ext.oStdClasses, {
11039 /* Two buttons buttons */
11040 "sPagePrevEnabled": "fg-button ui-button ui-state-default ui-corner-left",
11041 "sPagePrevDisabled": "fg-button ui-button ui-state-default ui-corner-left ui-state-disabled",
11042 "sPageNextEnabled": "fg-button ui-button ui-state-default ui-corner-right",
11043 "sPageNextDisabled": "fg-button ui-button ui-state-default ui-corner-right ui-state-disabled",
11044 "sPageJUINext": "ui-icon ui-icon-circle-arrow-e",
11045 "sPageJUIPrev": "ui-icon ui-icon-circle-arrow-w",
11047 /* Full numbers paging buttons */
11048 "sPageButton": "fg-button ui-button ui-state-default",
11049 "sPageButtonActive": "fg-button ui-button ui-state-default ui-state-disabled",
11050 "sPageButtonStaticDisabled": "fg-button ui-button ui-state-default ui-state-disabled",
11051 "sPageFirst": "first ui-corner-tl ui-corner-bl",
11052 "sPageLast": "last ui-corner-tr ui-corner-br",
11055 "sPaging": "dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi "+
11056 "ui-buttonset-multi paging_", /* Note that the type is postfixed */
11059 "sSortAsc": "ui-state-default",
11060 "sSortDesc": "ui-state-default",
11061 "sSortable": "ui-state-default",
11062 "sSortableAsc": "ui-state-default",
11063 "sSortableDesc": "ui-state-default",
11064 "sSortableNone": "ui-state-default",
11065 "sSortJUIAsc": "css_right ui-icon ui-icon-triangle-1-n",
11066 "sSortJUIDesc": "css_right ui-icon ui-icon-triangle-1-s",
11067 "sSortJUI": "css_right ui-icon ui-icon-carat-2-n-s",
11068 "sSortJUIAscAllowed": "css_right ui-icon ui-icon-carat-1-n",
11069 "sSortJUIDescAllowed": "css_right ui-icon ui-icon-carat-1-s",
11070 "sSortJUIWrapper": "DataTables_sort_wrapper",
11071 "sSortIcon": "DataTables_sort_icon",
11074 "sScrollHead": "dataTables_scrollHead ui-state-default",
11075 "sScrollFoot": "dataTables_scrollFoot ui-state-default",
11078 "sFooterTH": "ui-state-default"
11083 * Variable: oPagination
11085 * Scope: jQuery.fn.dataTableExt
11087 $.extend( DataTable.ext.oPagination, {
11089 * Variable: two_button
11090 * Purpose: Standard two button (forward/back) pagination
11091 * Scope: jQuery.fn.dataTableExt.oPagination
11095 * Function: oPagination.two_button.fnInit
11096 * Purpose: Initialise dom elements required for pagination with forward/back buttons only
11098 * Inputs: object:oSettings - dataTables settings object
11099 * node:nPaging - the DIV which contains this pagination control
11100 * function:fnCallbackDraw - draw function which must be called on update
11102 "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
11104 var oLang = oSettings.oLanguage.oPaginate;
11105 var oClasses = oSettings.oClasses;
11106 var fnClickHandler = function ( e ) {
11107 if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) )
11109 fnCallbackDraw( oSettings );
11113 var sAppend = (!oSettings.bJUI) ?
11114 '<a class="'+oSettings.oClasses.sPagePrevDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button">'+oLang.sPrevious+'</a>'+
11115 '<a class="'+oSettings.oClasses.sPageNextDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button">'+oLang.sNext+'</a>'
11117 '<a class="'+oSettings.oClasses.sPagePrevDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button"><span class="'+oSettings.oClasses.sPageJUIPrev+'"></span></a>'+
11118 '<a class="'+oSettings.oClasses.sPageNextDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button"><span class="'+oSettings.oClasses.sPageJUINext+'"></span></a>';
11119 $(nPaging).append( sAppend );
11121 var els = $('a', nPaging);
11122 var nPrevious = els[0],
11125 oSettings.oApi._fnBindAction( nPrevious, {action: "previous"}, fnClickHandler );
11126 oSettings.oApi._fnBindAction( nNext, {action: "next"}, fnClickHandler );
11128 /* ID the first elements only */
11129 if ( !oSettings.aanFeatures.p )
11131 nPaging.id = oSettings.sTableId+'_paginate';
11132 nPrevious.id = oSettings.sTableId+'_previous';
11133 nNext.id = oSettings.sTableId+'_next';
11135 nPrevious.setAttribute('aria-controls', oSettings.sTableId);
11136 nNext.setAttribute('aria-controls', oSettings.sTableId);
11141 * Function: oPagination.two_button.fnUpdate
11142 * Purpose: Update the two button pagination at the end of the draw
11144 * Inputs: object:oSettings - dataTables settings object
11145 * function:fnCallbackDraw - draw function to call on page change
11147 "fnUpdate": function ( oSettings, fnCallbackDraw )
11149 if ( !oSettings.aanFeatures.p )
11154 var oClasses = oSettings.oClasses;
11155 var an = oSettings.aanFeatures.p;
11157 /* Loop over each instance of the pager */
11158 for ( var i=0, iLen=an.length ; i<iLen ; i++ )
11160 if ( an[i].childNodes.length !== 0 )
11162 an[i].childNodes[0].className = ( oSettings._iDisplayStart === 0 ) ?
11163 oClasses.sPagePrevDisabled : oClasses.sPagePrevEnabled;
11165 an[i].childNodes[1].className = ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() ) ?
11166 oClasses.sPageNextDisabled : oClasses.sPageNextEnabled;
11174 * Variable: iFullNumbersShowPages
11175 * Purpose: Change the number of pages which can be seen
11176 * Scope: jQuery.fn.dataTableExt.oPagination
11178 "iFullNumbersShowPages": 5,
11181 * Variable: full_numbers
11182 * Purpose: Full numbers pagination
11183 * Scope: jQuery.fn.dataTableExt.oPagination
11187 * Function: oPagination.full_numbers.fnInit
11188 * Purpose: Initialise dom elements required for pagination with a list of the pages
11190 * Inputs: object:oSettings - dataTables settings object
11191 * node:nPaging - the DIV which contains this pagination control
11192 * function:fnCallbackDraw - draw function which must be called on update
11194 "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
11196 var oLang = oSettings.oLanguage.oPaginate;
11197 var oClasses = oSettings.oClasses;
11198 var fnClickHandler = function ( e ) {
11199 if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) )
11201 fnCallbackDraw( oSettings );
11206 '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPageFirst+'">'+oLang.sFirst+'</a>'+
11207 '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPagePrevious+'">'+oLang.sPrevious+'</a>'+
11209 '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPageNext+'">'+oLang.sNext+'</a>'+
11210 '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPageLast+'">'+oLang.sLast+'</a>'
11212 var els = $('a', nPaging);
11213 var nFirst = els[0],
11218 oSettings.oApi._fnBindAction( nFirst, {action: "first"}, fnClickHandler );
11219 oSettings.oApi._fnBindAction( nPrev, {action: "previous"}, fnClickHandler );
11220 oSettings.oApi._fnBindAction( nNext, {action: "next"}, fnClickHandler );
11221 oSettings.oApi._fnBindAction( nLast, {action: "last"}, fnClickHandler );
11223 /* ID the first elements only */
11224 if ( !oSettings.aanFeatures.p )
11226 nPaging.id = oSettings.sTableId+'_paginate';
11227 nFirst.id =oSettings.sTableId+'_first';
11228 nPrev.id =oSettings.sTableId+'_previous';
11229 nNext.id =oSettings.sTableId+'_next';
11230 nLast.id =oSettings.sTableId+'_last';
11235 * Function: oPagination.full_numbers.fnUpdate
11236 * Purpose: Update the list of page buttons shows
11238 * Inputs: object:oSettings - dataTables settings object
11239 * function:fnCallbackDraw - draw function to call on page change
11241 "fnUpdate": function ( oSettings, fnCallbackDraw )
11243 if ( !oSettings.aanFeatures.p )
11248 var iPageCount = DataTable.ext.oPagination.iFullNumbersShowPages;
11249 var iPageCountHalf = Math.floor(iPageCount / 2);
11250 var iPages = Math.ceil((oSettings.fnRecordsDisplay()) / oSettings._iDisplayLength);
11251 var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1;
11253 var iStartButton, iEndButton, i, iLen;
11254 var oClasses = oSettings.oClasses;
11255 var anButtons, anStatic, nPaginateList;
11256 var an = oSettings.aanFeatures.p;
11257 var fnBind = function (j) {
11258 oSettings.oApi._fnBindAction( this, {"page": j+iStartButton-1}, function(e) {
11259 /* Use the information in the element to jump to the required page */
11260 oSettings.oApi._fnPageChange( oSettings, e.data.page );
11261 fnCallbackDraw( oSettings );
11262 e.preventDefault();
11266 /* Pages calculation */
11267 if (iPages < iPageCount)
11270 iEndButton = iPages;
11272 else if (iCurrentPage <= iPageCountHalf)
11275 iEndButton = iPageCount;
11277 else if (iCurrentPage >= (iPages - iPageCountHalf))
11279 iStartButton = iPages - iPageCount + 1;
11280 iEndButton = iPages;
11284 iStartButton = iCurrentPage - Math.ceil(iPageCount / 2) + 1;
11285 iEndButton = iStartButton + iPageCount - 1;
11288 /* Build the dynamic list */
11289 for ( i=iStartButton ; i<=iEndButton ; i++ )
11291 sList += (iCurrentPage !== i) ?
11292 '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+'">'+oSettings.fnFormatNumber(i)+'</a>' :
11293 '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButtonActive+'">'+oSettings.fnFormatNumber(i)+'</a>';
11296 /* Loop over each instance of the pager */
11297 for ( i=0, iLen=an.length ; i<iLen ; i++ )
11299 if ( an[i].childNodes.length === 0 )
11304 /* Build up the dynamic list forst - html and listeners */
11305 $('span:eq(0)', an[i])
11307 .children('a').each( fnBind );
11309 /* Update the premanent botton's classes */
11310 anButtons = an[i].getElementsByTagName('a');
11312 anButtons[0], anButtons[1],
11313 anButtons[anButtons.length-2], anButtons[anButtons.length-1]
11316 $(anStatic).removeClass( oClasses.sPageButton+" "+oClasses.sPageButtonActive+" "+oClasses.sPageButtonStaticDisabled );
11317 $([anStatic[0], anStatic[1]]).addClass(
11318 (iCurrentPage==1) ?
11319 oClasses.sPageButtonStaticDisabled :
11320 oClasses.sPageButton
11322 $([anStatic[2], anStatic[3]]).addClass(
11323 (iPages===0 || iCurrentPage===iPages || oSettings._iDisplayLength===-1) ?
11324 oClasses.sPageButtonStaticDisabled :
11325 oClasses.sPageButton
11332 $.extend( DataTable.ext.oSort, {
11336 "string-pre": function ( a )
11338 if ( typeof a != 'string' ) { a = ''; }
11339 return a.toLowerCase();
11342 "string-asc": function ( x, y )
11344 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
11347 "string-desc": function ( x, y )
11349 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
11354 * html sorting (ignore html tags)
11356 "html-pre": function ( a )
11358 return a.replace( /<.*?>/g, "" ).toLowerCase();
11361 "html-asc": function ( x, y )
11363 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
11366 "html-desc": function ( x, y )
11368 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
11375 "date-pre": function ( a )
11377 var x = Date.parse( a );
11379 if ( isNaN(x) || x==="" )
11381 x = Date.parse( "01/01/1970 00:00:00" );
11386 "date-asc": function ( x, y )
11391 "date-desc": function ( x, y )
11398 * numerical sorting
11400 "numeric-pre": function ( a )
11402 return (a=="-" || a==="") ? 0 : a*1;
11405 "numeric-asc": function ( x, y )
11410 "numeric-desc": function ( x, y )
11417 $.extend( DataTable.ext.aTypes, [
11420 * Purpose: Check to see if a string is numeric
11421 * Returns: string:'numeric' or null
11422 * Inputs: mixed:sText - string to check
11426 /* Allow zero length strings as a number */
11427 if ( typeof sData === 'number' )
11431 else if ( typeof sData !== 'string' )
11436 var sValidFirstChars = "0123456789-";
11437 var sValidChars = "0123456789.";
11439 var bDecimal = false;
11441 /* Check for a valid first char (no period and allow negatives) */
11442 Char = sData.charAt(0);
11443 if (sValidFirstChars.indexOf(Char) == -1)
11448 /* Check all the other characters are valid */
11449 for ( var i=1 ; i<sData.length ; i++ )
11451 Char = sData.charAt(i);
11452 if (sValidChars.indexOf(Char) == -1)
11457 /* Only allowed one decimal place... */
11473 * Purpose: Check to see if a string is actually a formatted date
11474 * Returns: string:'date' or null
11475 * Inputs: string:sText - string to check
11479 var iParse = Date.parse(sData);
11480 if ( (iParse !== null && !isNaN(iParse)) || (typeof sData === 'string' && sData.length === 0) )
11489 * Purpose: Check to see if a string should be treated as an HTML string
11490 * Returns: string:'html' or null
11491 * Inputs: string:sText - string to check
11495 if ( typeof sData === 'string' && sData.indexOf('<') != -1 && sData.indexOf('>') != -1 )
11505 $.fn.DataTable = DataTable;
11506 $.fn.dataTable = DataTable;
11507 $.fn.dataTableSettings = DataTable.settings;
11508 $.fn.dataTableExt = DataTable.ext;
11511 // Information about events fired by DataTables - for documentation.
11513 * Draw event, fired whenever the table is redrawn on the page, at the same point as
11514 * fnDrawCallback. This may be useful for binding events or performing calculations when
11515 * the table is altered at all.
11516 * @name DataTable#draw
11518 * @param {event} e jQuery event object
11519 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
11523 * Filter event, fired when the filtering applied to the table (using the build in global
11524 * global filter, or column filters) is altered.
11525 * @name DataTable#filter
11527 * @param {event} e jQuery event object
11528 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
11532 * Page change event, fired when the paging of the table is altered.
11533 * @name DataTable#page
11535 * @param {event} e jQuery event object
11536 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
11540 * Sort event, fired when the sorting applied to the table is altered.
11541 * @name DataTable#sort
11543 * @param {event} e jQuery event object
11544 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
11548 * DataTables initialisation complete event, fired when the table is fully drawn,
11549 * including Ajax data loaded, if Ajax data is required.
11550 * @name DataTable#init
11552 * @param {event} e jQuery event object
11553 * @param {object} oSettings DataTables settings object
11554 * @param {object} json The JSON object request from the server - only
11555 * present if client-side Ajax sourced data is used</li></ol>
11559 * State save event, fired when the table has changed state a new state save is required.
11560 * This method allows modification of the state saving object prior to actually doing the
11561 * save, including addition or other state properties (for plug-ins) or modification
11562 * of a DataTables core property.
11563 * @name DataTable#stateSaveParams
11565 * @param {event} e jQuery event object
11566 * @param {object} oSettings DataTables settings object
11567 * @param {object} json The state information to be saved
11571 * State load event, fired when the table is loading state from the stored data, but
11572 * prior to the settings object being modified by the saved state - allowing modification
11573 * of the saved state is required or loading of state for a plug-in.
11574 * @name DataTable#stateLoadParams
11576 * @param {event} e jQuery event object
11577 * @param {object} oSettings DataTables settings object
11578 * @param {object} json The saved state information
11582 * State loaded event, fired when state has been loaded from stored data and the settings
11583 * object has been modified by the loaded data.
11584 * @name DataTable#stateLoaded
11586 * @param {event} e jQuery event object
11587 * @param {object} oSettings DataTables settings object
11588 * @param {object} json The saved state information
11592 * Processing event, fired when DataTables is doing some kind of processing (be it,
11593 * sort, filter or anything else). Can be used to indicate to the end user that
11594 * there is something happening, or that something has finished.
11595 * @name DataTable#processing
11597 * @param {event} e jQuery event object
11598 * @param {object} oSettings DataTables settings object
11599 * @param {boolean} bShow Flag for if DataTables is doing processing or not
11603 * Ajax (XHR) event, fired whenever an Ajax request is completed from a request to
11604 * made to the server for new data (note that this trigger is called in fnServerData,
11605 * if you override fnServerData and which to use this event, you need to trigger it in
11606 * you success function).
11607 * @name DataTable#xhr
11609 * @param {event} e jQuery event object
11610 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
11612 }(jQuery, window, document, undefined));