]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/static/AdminLTE-2.3.7/plugins/datatables/jquery.dataTables.js
2 * ©2008-2014 SpryMedia Ltd - datatables.net/license
7 * @description Paginate, search and order HTML tables
9 * @file jquery.dataTables.js
10 * @author SpryMedia Ltd (www.sprymedia.co.uk)
11 * @contact www.sprymedia.co.uk/contact
12 * @copyright Copyright 2008-2014 SpryMedia Ltd.
14 * This source file is free software, available under the following license:
15 * MIT license - http://datatables.net/license
17 * This source file is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
21 * For details please refer to: http://www.datatables.net
24 /*jslint evil: true, undef: true, browser: true */
25 /*globals $,require,jQuery,define,_selector_run,_selector_opts,_selector_first,_selector_row_indexes,_ext,_Api,_api_register,_api_registerPlural,_re_new_lines,_re_html,_re_formatted_numeric,_re_escape_regex,_empty,_intVal,_numToDecimal,_isNumber,_isHtml,_htmlNumeric,_pluck,_pluck_order,_range,_stripHtml,_unique,_fnBuildAjax,_fnAjaxUpdate,_fnAjaxParameters,_fnAjaxUpdateDraw,_fnAjaxDataSrc,_fnAddColumn,_fnColumnOptions,_fnAdjustColumnSizing,_fnVisibleToColumnIndex,_fnColumnIndexToVisible,_fnVisbleColumns,_fnGetColumns,_fnColumnTypes,_fnApplyColumnDefs,_fnHungarianMap,_fnCamelToHungarian,_fnLanguageCompat,_fnBrowserDetect,_fnAddData,_fnAddTr,_fnNodeToDataIndex,_fnNodeToColumnIndex,_fnGetCellData,_fnSetCellData,_fnSplitObjNotation,_fnGetObjectDataFn,_fnSetObjectDataFn,_fnGetDataMaster,_fnClearTable,_fnDeleteIndex,_fnInvalidate,_fnGetRowElements,_fnCreateTr,_fnBuildHead,_fnDrawHead,_fnDraw,_fnReDraw,_fnAddOptionsHtml,_fnDetectHeader,_fnGetUniqueThs,_fnFeatureHtmlFilter,_fnFilterComplete,_fnFilterCustom,_fnFilterColumn,_fnFilter,_fnFilterCreateSearch,_fnEscapeRegex,_fnFilterData,_fnFeatureHtmlInfo,_fnUpdateInfo,_fnInfoMacros,_fnInitialise,_fnInitComplete,_fnLengthChange,_fnFeatureHtmlLength,_fnFeatureHtmlPaginate,_fnPageChange,_fnFeatureHtmlProcessing,_fnProcessingDisplay,_fnFeatureHtmlTable,_fnScrollDraw,_fnApplyToChildren,_fnCalculateColumnWidths,_fnThrottle,_fnConvertToWidth,_fnScrollingWidthAdjust,_fnGetWidestNode,_fnGetMaxLenString,_fnStringToCss,_fnScrollBarWidth,_fnSortFlatten,_fnSort,_fnSortAria,_fnSortListener,_fnSortAttachListener,_fnSortingClasses,_fnSortData,_fnSaveState,_fnLoadState,_fnSettingsFromNode,_fnLog,_fnMap,_fnBindAction,_fnCallbackReg,_fnCallbackFire,_fnLengthOverflow,_fnRenderer,_fnDataSource,_fnRowAttributes*/
27 (/** @lends <global> */function( window
, document
, undefined ) {
29 (function( factory
) {
32 if ( typeof define
=== 'function' && define
.amd
) {
33 // Define as an AMD module if possible
34 define( 'datatables', ['jquery'], factory
);
36 else if ( typeof exports
=== 'object' ) {
38 module
.exports
= factory( require( 'jquery' ) );
40 else if ( jQuery
&& !jQuery
.fn
.dataTable
) {
41 // Define using browser globals otherwise
42 // Prevent multiple instantiations if the script is loaded twice
46 (/** @lends <global> */function( $ ) {
50 * DataTables is a plug-in for the jQuery Javascript library. It is a highly
51 * flexible tool, based upon the foundations of progressive enhancement,
52 * which will add advanced interaction controls to any HTML table. For a
53 * full list of features please refer to
54 * [DataTables.net](href="http://datatables.net).
56 * Note that the `DataTable` object is not a global variable but is aliased
57 * to `jQuery.fn.DataTable` and `jQuery.fn.dataTable` through which it may
61 * @param {object} [init={}] Configuration object for DataTables. Options
62 * are defined by {@link DataTable.defaults}
63 * @requires jQuery 1.7+
66 * // Basic initialisation
67 * $(document).ready( function {
68 * $('#example').dataTable();
72 * // Initialisation with configuration options - in this case, disable
73 * // pagination and sorting.
74 * $(document).ready( function {
75 * $('#example').dataTable( {
85 * It is useful to have variables which are scoped locally so only the
86 * DataTables functions can access them and they don't leak into global space.
87 * At the same time these functions are often useful over multiple files in the
88 * core and API, so we list, or at least document, all variables which are used
89 * by DataTables as private variables here. This also ensures that there is no
90 * clashing of variable names and that they can easily referenced for reuse.
98 // _selector_row_indexes
100 var _ext
; // DataTable.ext
101 var _Api
; // DataTable.Api
102 var _api_register
; // DataTable.Api.register
103 var _api_registerPlural
; // DataTable.Api.registerPlural
106 var _re_new_lines
= /[\r\n]/g;
107 var _re_html
= /<.*?>/g;
108 var _re_date_start
= /^[\w\+\-]/;
109 var _re_date_end
= /[\w\+\-]$/;
111 // Escape regular expression special characters
112 var _re_escape_regex
= new RegExp( '(\\' + [ '/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\', '$', '^', '-' ].join('|\\') + ')', 'g' );
114 // http://en.wikipedia.org/wiki/Foreign_exchange_market
115 // - \u20BD - Russian ruble.
116 // - \u20a9 - South Korean Won
117 // - \u20BA - Turkish Lira
118 // - \u20B9 - Indian Rupee
119 // - R - Brazil (R$) and South Africa
120 // - fr - Swiss Franc
121 // - kr - Swedish krona, Norwegian krone and Danish krone
122 // - \u2009 is thin space and \u202F is narrow no-break space, both used in many
123 // standards as thousands separators.
124 var _re_formatted_numeric
= /[',$£€¥%\u2009\u202F\u20BD\u20a9\u20BArfk]/gi;
127 var _empty = function ( d
) {
128 return !d
|| d
=== true || d
=== '-' ? true : false;
132 var _intVal = function ( s
) {
133 var integer
= parseInt( s
, 10 );
134 return !isNaN(integer
) && isFinite(s
) ? integer
: null;
137 // Convert from a formatted number with characters other than `.` as the
138 // decimal place, to a Javascript number
139 var _numToDecimal = function ( num
, decimalPoint
) {
140 // Cache created regular expressions for speed as this function is called often
141 if ( ! _re_dic
[ decimalPoint
] ) {
142 _re_dic
[ decimalPoint
] = new RegExp( _fnEscapeRegex( decimalPoint
), 'g' );
144 return typeof num
=== 'string' && decimalPoint
!== '.' ?
145 num
.replace( /\./g, '' ).replace( _re_dic
[ decimalPoint
], '.' ) :
150 var _isNumber = function ( d
, decimalPoint
, formatted
) {
151 var strType
= typeof d
=== 'string';
153 // If empty return immediately so there must be a number if it is a
154 // formatted string (this stops the string "k", or "kr", etc being detected
155 // as a formatted number for currency
160 if ( decimalPoint
&& strType
) {
161 d
= _numToDecimal( d
, decimalPoint
);
164 if ( formatted
&& strType
) {
165 d
= d
.replace( _re_formatted_numeric
, '' );
168 return !isNaN( parseFloat(d
) ) && isFinite( d
);
172 // A string without HTML in it can be considered to be HTML still
173 var _isHtml = function ( d
) {
174 return _empty( d
) || typeof d
=== 'string';
178 var _htmlNumeric = function ( d
, decimalPoint
, formatted
) {
183 var html
= _isHtml( d
);
186 _isNumber( _stripHtml( d
), decimalPoint
, formatted
) ?
192 var _pluck = function ( a
, prop
, prop2
) {
194 var i
=0, ien
=a
.length
;
196 // Could have the test in the loop for slightly smaller code, but speed
198 if ( prop2
!== undefined ) {
199 for ( ; i
<ien
; i
++ ) {
200 if ( a
[i
] && a
[i
][ prop
] ) {
201 out
.push( a
[i
][ prop
][ prop2
] );
206 for ( ; i
<ien
; i
++ ) {
208 out
.push( a
[i
][ prop
] );
217 // Basically the same as _pluck, but rather than looping over `a` we use `order`
218 // as the indexes to pick from `a`
219 var _pluck_order = function ( a
, order
, prop
, prop2
)
222 var i
=0, ien
=order
.length
;
224 // Could have the test in the loop for slightly smaller code, but speed
226 if ( prop2
!== undefined ) {
227 for ( ; i
<ien
; i
++ ) {
228 if ( a
[ order
[i
] ][ prop
] ) {
229 out
.push( a
[ order
[i
] ][ prop
][ prop2
] );
234 for ( ; i
<ien
; i
++ ) {
235 out
.push( a
[ order
[i
] ][ prop
] );
243 var _range = function ( len
, start
)
248 if ( start
=== undefined ) {
257 for ( var i
=start
; i
<end
; i
++ ) {
265 var _removeEmpty = function ( a
)
269 for ( var i
=0, ien
=a
.length
; i
<ien
; i
++ ) {
270 if ( a
[i
] ) { // careful - will remove all falsy values!
279 var _stripHtml = function ( d
) {
280 return d
.replace( _re_html
, '' );
285 * Find the unique elements in a source array.
287 * @param {array} src Source array
288 * @return {array} Array of unique items
291 var _unique = function ( src
)
293 // A faster unique method is to use object keys to identify used values,
294 // but this doesn't work with arrays or objects, which we must also
295 // consider. See jsperf.com/compare-array-unique-versions/4 for more
303 again
: for ( i
=0 ; i
<ien
; i
++ ) {
306 for ( j
=0 ; j
<k
; j
++ ) {
307 if ( out
[j
] === val
) {
322 * Create a mapping object that allows camel case parameters to be looked up
323 * for their Hungarian counterparts. The mapping is stored in a private
324 * parameter called `_hungarianMap` which can be accessed on the source object.
326 * @memberof DataTable#oApi
328 function _fnHungarianMap ( o
)
331 hungarian
= 'a aa ai ao as b fn i m o s ',
336 $.each( o
, function (key
, val
) {
337 match
= key
.match(/^([^A-Z]+?)([A-Z])/);
339 if ( match
&& hungarian
.indexOf(match
[1]+' ') !== -1 )
341 newKey
= key
.replace( match
[0], match
[2].toLowerCase() );
344 if ( match
[1] === 'o' )
346 _fnHungarianMap( o
[key
] );
351 o
._hungarianMap
= map
;
356 * Convert from camel case parameters to Hungarian, based on a Hungarian map
357 * created by _fnHungarianMap.
358 * @param {object} src The model object which holds all parameters that can be
360 * @param {object} user The object to convert from camel case to Hungarian.
361 * @param {boolean} force When set to `true`, properties which already have a
362 * Hungarian value in the `user` object will be overwritten. Otherwise they
364 * @memberof DataTable#oApi
366 function _fnCamelToHungarian ( src
, user
, force
)
368 if ( ! src
._hungarianMap
) {
369 _fnHungarianMap( src
);
374 $.each( user
, function (key
, val
) {
375 hungarianKey
= src
._hungarianMap
[ key
];
377 if ( hungarianKey
!== undefined && (force
|| user
[hungarianKey
] === undefined) )
379 // For objects, we need to buzz down into the object to copy parameters
380 if ( hungarianKey
.charAt(0) === 'o' )
382 // Copy the camelCase options over to the hungarian
383 if ( ! user
[ hungarianKey
] ) {
384 user
[ hungarianKey
] = {};
386 $.extend( true, user
[hungarianKey
], user
[key
] );
388 _fnCamelToHungarian( src
[hungarianKey
], user
[hungarianKey
], force
);
391 user
[hungarianKey
] = user
[ key
];
399 * Language compatibility - when certain options are given, and others aren't, we
400 * need to duplicate the values over, in order to provide backwards compatibility
401 * with older language files.
402 * @param {object} oSettings dataTables settings object
403 * @memberof DataTable#oApi
405 function _fnLanguageCompat( lang
)
407 var defaults
= DataTable
.defaults
.oLanguage
;
408 var zeroRecords
= lang
.sZeroRecords
;
410 /* Backwards compatibility - if there is no sEmptyTable given, then use the same as
411 * sZeroRecords - assuming that is given.
413 if ( ! lang
.sEmptyTable
&& zeroRecords
&&
414 defaults
.sEmptyTable
=== "No data available in table" )
416 _fnMap( lang
, lang
, 'sZeroRecords', 'sEmptyTable' );
419 /* Likewise with loading records */
420 if ( ! lang
.sLoadingRecords
&& zeroRecords
&&
421 defaults
.sLoadingRecords
=== "Loading..." )
423 _fnMap( lang
, lang
, 'sZeroRecords', 'sLoadingRecords' );
426 // Old parameter name of the thousands separator mapped onto the new
427 if ( lang
.sInfoThousands
) {
428 lang
.sThousands
= lang
.sInfoThousands
;
431 var decimal = lang
.sDecimal
;
433 _addNumericSort( decimal );
439 * Map one parameter onto another
440 * @param {object} o Object to map
441 * @param {*} knew The new parameter name
442 * @param {*} old The old parameter name
444 var _fnCompatMap = function ( o
, knew
, old
) {
445 if ( o
[ knew
] !== undefined ) {
446 o
[ old
] = o
[ knew
];
452 * Provide backwards compatibility for the main DT options. Note that the new
453 * options are mapped onto the old parameters, so this is an external interface
455 * @param {object} init Object to map
457 function _fnCompatOpts ( init
)
459 _fnCompatMap( init
, 'ordering', 'bSort' );
460 _fnCompatMap( init
, 'orderMulti', 'bSortMulti' );
461 _fnCompatMap( init
, 'orderClasses', 'bSortClasses' );
462 _fnCompatMap( init
, 'orderCellsTop', 'bSortCellsTop' );
463 _fnCompatMap( init
, 'order', 'aaSorting' );
464 _fnCompatMap( init
, 'orderFixed', 'aaSortingFixed' );
465 _fnCompatMap( init
, 'paging', 'bPaginate' );
466 _fnCompatMap( init
, 'pagingType', 'sPaginationType' );
467 _fnCompatMap( init
, 'pageLength', 'iDisplayLength' );
468 _fnCompatMap( init
, 'searching', 'bFilter' );
470 // Column search objects are in an array, so it needs to be converted
471 // element by element
472 var searchCols
= init
.aoSearchCols
;
475 for ( var i
=0, ien
=searchCols
.length
; i
<ien
; i
++ ) {
476 if ( searchCols
[i
] ) {
477 _fnCamelToHungarian( DataTable
.models
.oSearch
, searchCols
[i
] );
485 * Provide backwards compatibility for column options. Note that the new options
486 * are mapped onto the old parameters, so this is an external interface change
488 * @param {object} init Object to map
490 function _fnCompatCols ( init
)
492 _fnCompatMap( init
, 'orderable', 'bSortable' );
493 _fnCompatMap( init
, 'orderData', 'aDataSort' );
494 _fnCompatMap( init
, 'orderSequence', 'asSorting' );
495 _fnCompatMap( init
, 'orderDataType', 'sortDataType' );
497 // orderData can be given as an integer
498 var dataSort
= init
.aDataSort
;
499 if ( dataSort
&& ! $.isArray( dataSort
) ) {
500 init
.aDataSort
= [ dataSort
];
506 * Browser feature detection for capabilities, quirks
507 * @param {object} settings dataTables settings object
508 * @memberof DataTable#oApi
510 function _fnBrowserDetect( settings
)
512 var browser
= settings
.oBrowser
;
514 // Scrolling feature / quirks detection
517 position
: 'absolute',
527 position
: 'absolute',
534 $('<div class="test"/>')
543 var test
= n
.find('.test');
545 // IE6/7 will oversize a width 100% element inside a scrolling element, to
546 // include the width of the scrollbar, while other browsers ensure the inner
547 // element is contained without forcing scrolling
548 browser
.bScrollOversize
= test
[0].offsetWidth
=== 100;
550 // In rtl text layout, some browsers (most, but not all) will place the
551 // scrollbar on the left, rather than the right.
552 browser
.bScrollbarLeft
= Math
.round( test
.offset().left
) !== 1;
559 * Array.prototype reduce[Right] method, used for browsers which don't support
560 * JS 1.6. Done this way to reduce code size, since we iterate either way
561 * @param {object} settings dataTables settings object
562 * @memberof DataTable#oApi
564 function _fnReduce ( that
, fn
, init
, start
, end
, inc
)
571 if ( init
!== undefined ) {
576 while ( i
!== end
) {
577 if ( ! that
.hasOwnProperty(i
) ) {
582 fn( value
, that
[i
], i
, that
) :
593 * Add a column to the list used for the table with default values
594 * @param {object} oSettings dataTables settings object
595 * @param {node} nTh The th element for this column
596 * @memberof DataTable#oApi
598 function _fnAddColumn( oSettings
, nTh
)
600 // Add column to aoColumns array
601 var oDefaults
= DataTable
.defaults
.column
;
602 var iCol
= oSettings
.aoColumns
.length
;
603 var oCol
= $.extend( {}, DataTable
.models
.oColumn
, oDefaults
, {
604 "nTh": nTh
? nTh
: document
.createElement('th'),
605 "sTitle": oDefaults
.sTitle
? oDefaults
.sTitle
: nTh
? nTh
.innerHTML
: '',
606 "aDataSort": oDefaults
.aDataSort
? oDefaults
.aDataSort
: [iCol
],
607 "mData": oDefaults
.mData
? oDefaults
.mData
: iCol
,
610 oSettings
.aoColumns
.push( oCol
);
612 // Add search object for column specific search. Note that the `searchCols[ iCol ]`
613 // passed into extend can be undefined. This allows the user to give a default
614 // with only some of the parameters defined, and also not give a default
615 var searchCols
= oSettings
.aoPreSearchCols
;
616 searchCols
[ iCol
] = $.extend( {}, DataTable
.models
.oSearch
, searchCols
[ iCol
] );
618 // Use the default column options function to initialise classes etc
619 _fnColumnOptions( oSettings
, iCol
, $(nTh
).data() );
624 * Apply options for a column
625 * @param {object} oSettings dataTables settings object
626 * @param {int} iCol column index to consider
627 * @param {object} oOptions object with sType, bVisible and bSearchable etc
628 * @memberof DataTable#oApi
630 function _fnColumnOptions( oSettings
, iCol
, oOptions
)
632 var oCol
= oSettings
.aoColumns
[ iCol
];
633 var oClasses
= oSettings
.oClasses
;
634 var th
= $(oCol
.nTh
);
636 // Try to get width information from the DOM. We can't get it from CSS
637 // as we'd need to parse the CSS stylesheet. `width` option can override
638 if ( ! oCol
.sWidthOrig
) {
640 oCol
.sWidthOrig
= th
.attr('width') || null;
643 var t
= (th
.attr('style') || '').match(/width:\s*(\d+[pxem%]+)/);
645 oCol
.sWidthOrig
= t
[1];
649 /* User specified column options */
650 if ( oOptions
!== undefined && oOptions
!== null )
652 // Backwards compatibility
653 _fnCompatCols( oOptions
);
655 // Map camel case parameters to their Hungarian counterparts
656 _fnCamelToHungarian( DataTable
.defaults
.column
, oOptions
);
658 /* Backwards compatibility for mDataProp */
659 if ( oOptions
.mDataProp
!== undefined && !oOptions
.mData
)
661 oOptions
.mData
= oOptions
.mDataProp
;
664 if ( oOptions
.sType
)
666 oCol
._sManualType
= oOptions
.sType
;
669 // `class` is a reserved word in Javascript, so we need to provide
670 // the ability to use a valid name for the camel case input
671 if ( oOptions
.className
&& ! oOptions
.sClass
)
673 oOptions
.sClass
= oOptions
.className
;
676 $.extend( oCol
, oOptions
);
677 _fnMap( oCol
, oOptions
, "sWidth", "sWidthOrig" );
679 /* iDataSort to be applied (backwards compatibility), but aDataSort will take
680 * priority if defined
682 if ( oOptions
.iDataSort
!== undefined )
684 oCol
.aDataSort
= [ oOptions
.iDataSort
];
686 _fnMap( oCol
, oOptions
, "aDataSort" );
689 /* Cache the data get and set functions for speed */
690 var mDataSrc
= oCol
.mData
;
691 var mData
= _fnGetObjectDataFn( mDataSrc
);
692 var mRender
= oCol
.mRender
? _fnGetObjectDataFn( oCol
.mRender
) : null;
694 var attrTest = function( src
) {
695 return typeof src
=== 'string' && src
.indexOf('@') !== -1;
697 oCol
._bAttrSrc
= $.isPlainObject( mDataSrc
) && (
698 attrTest(mDataSrc
.sort
) || attrTest(mDataSrc
.type
) || attrTest(mDataSrc
.filter
)
701 oCol
.fnGetData = function (rowData
, type
, meta
) {
702 var innerData
= mData( rowData
, type
, undefined, meta
);
704 return mRender
&& type
?
705 mRender( innerData
, type
, rowData
, meta
) :
708 oCol
.fnSetData = function ( rowData
, val
, meta
) {
709 return _fnSetObjectDataFn( mDataSrc
)( rowData
, val
, meta
);
712 // Indicate if DataTables should read DOM data as an object or array
713 // Used in _fnGetRowElements
714 if ( typeof mDataSrc
!== 'number' ) {
715 oSettings
._rowReadObject
= true;
718 /* Feature sorting overrides column specific when off */
719 if ( !oSettings
.oFeatures
.bSort
)
721 oCol
.bSortable
= false;
722 th
.addClass( oClasses
.sSortableNone
); // Have to add class here as order event isn't called
725 /* Check that the class assignment is correct for sorting */
726 var bAsc
= $.inArray('asc', oCol
.asSorting
) !== -1;
727 var bDesc
= $.inArray('desc', oCol
.asSorting
) !== -1;
728 if ( !oCol
.bSortable
|| (!bAsc
&& !bDesc
) )
730 oCol
.sSortingClass
= oClasses
.sSortableNone
;
731 oCol
.sSortingClassJUI
= "";
733 else if ( bAsc
&& !bDesc
)
735 oCol
.sSortingClass
= oClasses
.sSortableAsc
;
736 oCol
.sSortingClassJUI
= oClasses
.sSortJUIAscAllowed
;
738 else if ( !bAsc
&& bDesc
)
740 oCol
.sSortingClass
= oClasses
.sSortableDesc
;
741 oCol
.sSortingClassJUI
= oClasses
.sSortJUIDescAllowed
;
745 oCol
.sSortingClass
= oClasses
.sSortable
;
746 oCol
.sSortingClassJUI
= oClasses
.sSortJUI
;
752 * Adjust the table column widths for new data. Note: you would probably want to
753 * do a redraw after calling this function!
754 * @param {object} settings dataTables settings object
755 * @memberof DataTable#oApi
757 function _fnAdjustColumnSizing ( settings
)
759 /* Not interested in doing column width calculation if auto-width is disabled */
760 if ( settings
.oFeatures
.bAutoWidth
!== false )
762 var columns
= settings
.aoColumns
;
764 _fnCalculateColumnWidths( settings
);
765 for ( var i
=0 , iLen
=columns
.length
; i
<iLen
; i
++ )
767 columns
[i
].nTh
.style
.width
= columns
[i
].sWidth
;
771 var scroll
= settings
.oScroll
;
772 if ( scroll
.sY
!== '' || scroll
.sX
!== '')
774 _fnScrollDraw( settings
);
777 _fnCallbackFire( settings
, null, 'column-sizing', [settings
] );
782 * Covert the index of a visible column to the index in the data array (take account
784 * @param {object} oSettings dataTables settings object
785 * @param {int} iMatch Visible column index to lookup
786 * @returns {int} i the data index
787 * @memberof DataTable#oApi
789 function _fnVisibleToColumnIndex( oSettings
, iMatch
)
791 var aiVis
= _fnGetColumns( oSettings
, 'bVisible' );
793 return typeof aiVis
[iMatch
] === 'number' ?
800 * Covert the index of an index in the data array and convert it to the visible
801 * column index (take account of hidden columns)
802 * @param {int} iMatch Column index to lookup
803 * @param {object} oSettings dataTables settings object
804 * @returns {int} i the data index
805 * @memberof DataTable#oApi
807 function _fnColumnIndexToVisible( oSettings
, iMatch
)
809 var aiVis
= _fnGetColumns( oSettings
, 'bVisible' );
810 var iPos
= $.inArray( iMatch
, aiVis
);
812 return iPos
!== -1 ? iPos
: null;
817 * Get the number of visible columns
818 * @param {object} oSettings dataTables settings object
819 * @returns {int} i the number of visible columns
820 * @memberof DataTable#oApi
822 function _fnVisbleColumns( oSettings
)
824 return _fnGetColumns( oSettings
, 'bVisible' ).length
;
829 * Get an array of column indexes that match a given property
830 * @param {object} oSettings dataTables settings object
831 * @param {string} sParam Parameter in aoColumns to look for - typically
832 * bVisible or bSearchable
833 * @returns {array} Array of indexes with matched properties
834 * @memberof DataTable#oApi
836 function _fnGetColumns( oSettings
, sParam
)
840 $.map( oSettings
.aoColumns
, function(val
, i
) {
851 * Calculate the 'type' of a column
852 * @param {object} settings dataTables settings object
853 * @memberof DataTable#oApi
855 function _fnColumnTypes ( settings
)
857 var columns
= settings
.aoColumns
;
858 var data
= settings
.aoData
;
859 var types
= DataTable
.ext
.type
.detect
;
860 var i
, ien
, j
, jen
, k
, ken
;
861 var col
, cell
, detectedType
, cache
;
863 // For each column, spin over the
864 for ( i
=0, ien
=columns
.length
; i
<ien
; i
++ ) {
868 if ( ! col
.sType
&& col
._sManualType
) {
869 col
.sType
= col
._sManualType
;
871 else if ( ! col
.sType
) {
872 for ( j
=0, jen
=types
.length
; j
<jen
; j
++ ) {
873 for ( k
=0, ken
=data
.length
; k
<ken
; k
++ ) {
874 // Use a cache array so we only need to get the type data
875 // from the formatter once (when using multiple detectors)
876 if ( cache
[k
] === undefined ) {
877 cache
[k
] = _fnGetCellData( settings
, k
, i
, 'type' );
880 detectedType
= types
[j
]( cache
[k
], settings
);
882 // If null, then this type can't apply to this column, so
883 // rather than testing all cells, break out. There is an
884 // exception for the last type which is `html`. We need to
885 // scan all rows since it is possible to mix string and HTML
887 if ( ! detectedType
&& j
!== types
.length
-1 ) {
891 // Only a single match is needed for html type since it is
892 // bottom of the pile and very similar to string
893 if ( detectedType
=== 'html' ) {
898 // Type is valid for all data points in the column - use this
900 if ( detectedType
) {
901 col
.sType
= detectedType
;
906 // Fall back - if no type was detected, always use string
908 col
.sType
= 'string';
916 * Take the column definitions and static columns arrays and calculate how
917 * they relate to column indexes. The callback function will then apply the
918 * definition found for a column to a suitable configuration object.
919 * @param {object} oSettings dataTables settings object
920 * @param {array} aoColDefs The aoColumnDefs array that is to be applied
921 * @param {array} aoCols The aoColumns array that defines columns individually
922 * @param {function} fn Callback function - takes two parameters, the calculated
923 * column index and the definition for that column.
924 * @memberof DataTable#oApi
926 function _fnApplyColumnDefs( oSettings
, aoColDefs
, aoCols
, fn
)
928 var i
, iLen
, j
, jLen
, k
, kLen
, def
;
929 var columns
= oSettings
.aoColumns
;
931 // Column definitions with aTargets
934 /* Loop over the definitions array - loop in reverse so first instance has priority */
935 for ( i
=aoColDefs
.length
-1 ; i
>=0 ; i
-- )
939 /* Each definition can target multiple columns, as it is an array */
940 var aTargets
= def
.targets
!== undefined ?
944 if ( ! $.isArray( aTargets
) )
946 aTargets
= [ aTargets
];
949 for ( j
=0, jLen
=aTargets
.length
; j
<jLen
; j
++ )
951 if ( typeof aTargets
[j
] === 'number' && aTargets
[j
] >= 0 )
953 /* Add columns that we don't yet know about */
954 while( columns
.length
<= aTargets
[j
] )
956 _fnAddColumn( oSettings
);
959 /* Integer, basic index */
960 fn( aTargets
[j
], def
);
962 else if ( typeof aTargets
[j
] === 'number' && aTargets
[j
] < 0 )
964 /* Negative integer, right to left column counting */
965 fn( columns
.length
+aTargets
[j
], def
);
967 else if ( typeof aTargets
[j
] === 'string' )
969 /* Class name matching on TH element */
970 for ( k
=0, kLen
=columns
.length
; k
<kLen
; k
++ )
972 if ( aTargets
[j
] == "_all" ||
973 $(columns
[k
].nTh
).hasClass( aTargets
[j
] ) )
983 // Statically defined columns array
986 for ( i
=0, iLen
=aoCols
.length
; i
<iLen
; i
++ )
994 * Add a data array to the table, creating DOM node etc. This is the parallel to
995 * _fnGatherData, but for adding rows from a Javascript source, rather than a
997 * @param {object} oSettings dataTables settings object
998 * @param {array} aData data array to be added
999 * @param {node} [nTr] TR element to add to the table - optional. If not given,
1000 * DataTables will create a row automatically
1001 * @param {array} [anTds] Array of TD|TH elements for the row - must be given
1003 * @returns {int} >=0 if successful (index of new aoData entry), -1 if failed
1004 * @memberof DataTable#oApi
1006 function _fnAddData ( oSettings
, aDataIn
, nTr
, anTds
)
1008 /* Create the object for storing information about this new row */
1009 var iRow
= oSettings
.aoData
.length
;
1010 var oData
= $.extend( true, {}, DataTable
.models
.oRow
, {
1011 src
: nTr
? 'dom' : 'data'
1014 oData
._aData
= aDataIn
;
1015 oSettings
.aoData
.push( oData
);
1017 /* Create the cells */
1019 var columns
= oSettings
.aoColumns
;
1020 for ( var i
=0, iLen
=columns
.length
; i
<iLen
; i
++ )
1022 // When working with a row, the data source object must be populated. In
1023 // all other cases, the data source object is already populated, so we
1024 // don't overwrite it, which might break bindings etc
1026 _fnSetCellData( oSettings
, iRow
, i
, _fnGetCellData( oSettings
, iRow
, i
) );
1028 columns
[i
].sType
= null;
1031 /* Add to the display array */
1032 oSettings
.aiDisplayMaster
.push( iRow
);
1034 /* Create the DOM information, or register it if already present */
1035 if ( nTr
|| ! oSettings
.oFeatures
.bDeferRender
)
1037 _fnCreateTr( oSettings
, iRow
, nTr
, anTds
);
1045 * Add one or more TR elements to the table. Generally we'd expect to
1046 * use this for reading data from a DOM sourced table, but it could be
1047 * used for an TR element. Note that if a TR is given, it is used (i.e.
1048 * it is not cloned).
1049 * @param {object} settings dataTables settings object
1050 * @param {array|node|jQuery} trs The TR element(s) to add to the table
1051 * @returns {array} Array of indexes for the added rows
1052 * @memberof DataTable#oApi
1054 function _fnAddTr( settings
, trs
)
1058 // Allow an individual node to be passed in
1059 if ( ! (trs
instanceof $) ) {
1063 return trs
.map( function (i
, el
) {
1064 row
= _fnGetRowElements( settings
, el
);
1065 return _fnAddData( settings
, row
.data
, el
, row
.cells
);
1071 * Take a TR element and convert it to an index in aoData
1072 * @param {object} oSettings dataTables settings object
1073 * @param {node} n the TR element to find
1074 * @returns {int} index if the node is found, null if not
1075 * @memberof DataTable#oApi
1077 function _fnNodeToDataIndex( oSettings
, n
)
1079 return (n
._DT_RowIndex
!==undefined) ? n
._DT_RowIndex
: null;
1084 * Take a TD element and convert it into a column data index (not the visible index)
1085 * @param {object} oSettings dataTables settings object
1086 * @param {int} iRow The row number the TD/TH can be found in
1087 * @param {node} n The TD/TH element to find
1088 * @returns {int} index if the node is found, -1 if not
1089 * @memberof DataTable#oApi
1091 function _fnNodeToColumnIndex( oSettings
, iRow
, n
)
1093 return $.inArray( n
, oSettings
.aoData
[ iRow
].anCells
);
1098 * Get the data for a given cell from the internal cache, taking into account data mapping
1099 * @param {object} settings dataTables settings object
1100 * @param {int} rowIdx aoData row id
1101 * @param {int} colIdx Column index
1102 * @param {string} type data get type ('display', 'type' 'filter' 'sort')
1103 * @returns {*} Cell data
1104 * @memberof DataTable#oApi
1106 function _fnGetCellData( settings
, rowIdx
, colIdx
, type
)
1108 var draw
= settings
.iDraw
;
1109 var col
= settings
.aoColumns
[colIdx
];
1110 var rowData
= settings
.aoData
[rowIdx
]._aData
;
1111 var defaultContent
= col
.sDefaultContent
;
1112 var cellData
= col
.fnGetData( rowData
, type
, {
1118 if ( cellData
=== undefined ) {
1119 if ( settings
.iDrawError
!= draw
&& defaultContent
=== null ) {
1120 _fnLog( settings
, 0, "Requested unknown parameter "+
1121 (typeof col
.mData
=='function' ? '{function}' : "'"+col
.mData
+"'")+
1122 " for row "+rowIdx
, 4 );
1123 settings
.iDrawError
= draw
;
1125 return defaultContent
;
1128 /* When the data source is null, we can use default column data */
1129 if ( (cellData
=== rowData
|| cellData
=== null) && defaultContent
!== null ) {
1130 cellData
= defaultContent
;
1132 else if ( typeof cellData
=== 'function' ) {
1133 // If the data source is a function, then we run it and use the return,
1134 // executing in the scope of the data object (for instances)
1135 return cellData
.call( rowData
);
1138 if ( cellData
=== null && type
== 'display' ) {
1146 * Set the value for a specific cell, into the internal data cache
1147 * @param {object} settings dataTables settings object
1148 * @param {int} rowIdx aoData row id
1149 * @param {int} colIdx Column index
1150 * @param {*} val Value to set
1151 * @memberof DataTable#oApi
1153 function _fnSetCellData( settings
, rowIdx
, colIdx
, val
)
1155 var col
= settings
.aoColumns
[colIdx
];
1156 var rowData
= settings
.aoData
[rowIdx
]._aData
;
1158 col
.fnSetData( rowData
, val
, {
1166 // Private variable that is used to match action syntax in the data property object
1167 var __reArray
= /\[.*?\]$/;
1168 var __reFn
= /\(\)$/;
1171 * Split string on periods, taking into account escaped periods
1172 * @param {string} str String to split
1173 * @return {array} Split string
1175 function _fnSplitObjNotation( str
)
1177 return $.map( str
.match(/(\\.|[^\.])+/g), function ( s
) {
1178 return s
.replace(/\\./g, '.');
1184 * Return a function that can be used to get data from a source object, taking
1185 * into account the ability to use nested objects as a source
1186 * @param {string|int|function} mSource The data source for the object
1187 * @returns {function} Data get function
1188 * @memberof DataTable#oApi
1190 function _fnGetObjectDataFn( mSource
)
1192 if ( $.isPlainObject( mSource
) )
1194 /* Build an object of get functions, and wrap them in a single call */
1196 $.each( mSource
, function (key
, val
) {
1198 o
[key
] = _fnGetObjectDataFn( val
);
1202 return function (data
, type
, row
, meta
) {
1203 var t
= o
[type
] || o
._
;
1204 return t
!== undefined ?
1205 t(data
, type
, row
, meta
) :
1209 else if ( mSource
=== null )
1211 /* Give an empty string for rendering / sorting etc */
1212 return function (data
) { // type, row and meta also passed, but not used
1216 else if ( typeof mSource
=== 'function' )
1218 return function (data
, type
, row
, meta
) {
1219 return mSource( data
, type
, row
, meta
);
1222 else if ( typeof mSource
=== 'string' && (mSource
.indexOf('.') !== -1 ||
1223 mSource
.indexOf('[') !== -1 || mSource
.indexOf('(') !== -1) )
1225 /* If there is a . in the source string then the data source is in a
1226 * nested object so we loop over the data for each level to get the next
1227 * level down. On each loop we test for undefined, and if found immediately
1228 * return. This allows entire objects to be missing and sDefaultContent to
1229 * be used if defined, rather than throwing an error
1231 var fetchData = function (data
, type
, src
) {
1232 var arrayNotation
, funcNotation
, out
, innerSrc
;
1236 var a
= _fnSplitObjNotation( src
);
1238 for ( var i
=0, iLen
=a
.length
; i
<iLen
; i
++ )
1240 // Check if we are dealing with special notation
1241 arrayNotation
= a
[i
].match(__reArray
);
1242 funcNotation
= a
[i
].match(__reFn
);
1244 if ( arrayNotation
)
1247 a
[i
] = a
[i
].replace(__reArray
, '');
1249 // Condition allows simply [] to be passed in
1250 if ( a
[i
] !== "" ) {
1251 data
= data
[ a
[i
] ];
1255 // Get the remainder of the nested object to get
1257 innerSrc
= a
.join('.');
1259 // Traverse each entry in the array getting the properties requested
1260 for ( var j
=0, jLen
=data
.length
; j
<jLen
; j
++ ) {
1261 out
.push( fetchData( data
[j
], type
, innerSrc
) );
1264 // If a string is given in between the array notation indicators, that
1265 // is used to join the strings together, otherwise an array is returned
1266 var join
= arrayNotation
[0].substring(1, arrayNotation
[0].length
-1);
1267 data
= (join
==="") ? out
: out
.join(join
);
1269 // The inner call to fetchData has already traversed through the remainder
1270 // of the source requested, so we exit from the loop
1273 else if ( funcNotation
)
1276 a
[i
] = a
[i
].replace(__reFn
, '');
1277 data
= data
[ a
[i
] ]();
1281 if ( data
=== null || data
[ a
[i
] ] === undefined )
1285 data
= data
[ a
[i
] ];
1292 return function (data
, type
) { // row and meta also passed, but not used
1293 return fetchData( data
, type
, mSource
);
1298 /* Array or flat object mapping */
1299 return function (data
, type
) { // row and meta also passed, but not used
1300 return data
[mSource
];
1307 * Return a function that can be used to set data from a source object, taking
1308 * into account the ability to use nested objects as a source
1309 * @param {string|int|function} mSource The data source for the object
1310 * @returns {function} Data set function
1311 * @memberof DataTable#oApi
1313 function _fnSetObjectDataFn( mSource
)
1315 if ( $.isPlainObject( mSource
) )
1317 /* Unlike get, only the underscore (global) option is used for for
1318 * setting data since we don't know the type here. This is why an object
1319 * option is not documented for `mData` (which is read/write), but it is
1320 * for `mRender` which is read only.
1322 return _fnSetObjectDataFn( mSource
._
);
1324 else if ( mSource
=== null )
1326 /* Nothing to do when the data source is null */
1327 return function () {};
1329 else if ( typeof mSource
=== 'function' )
1331 return function (data
, val
, meta
) {
1332 mSource( data
, 'set', val
, meta
);
1335 else if ( typeof mSource
=== 'string' && (mSource
.indexOf('.') !== -1 ||
1336 mSource
.indexOf('[') !== -1 || mSource
.indexOf('(') !== -1) )
1338 /* Like the get, we need to get data from a nested object */
1339 var setData = function (data
, val
, src
) {
1340 var a
= _fnSplitObjNotation( src
), b
;
1341 var aLast
= a
[a
.length
-1];
1342 var arrayNotation
, funcNotation
, o
, innerSrc
;
1344 for ( var i
=0, iLen
=a
.length
-1 ; i
<iLen
; i
++ )
1346 // Check if we are dealing with an array notation request
1347 arrayNotation
= a
[i
].match(__reArray
);
1348 funcNotation
= a
[i
].match(__reFn
);
1350 if ( arrayNotation
)
1352 a
[i
] = a
[i
].replace(__reArray
, '');
1355 // Get the remainder of the nested object to set so we can recurse
1358 innerSrc
= b
.join('.');
1360 // Traverse each entry in the array setting the properties requested
1361 for ( var j
=0, jLen
=val
.length
; j
<jLen
; j
++ )
1364 setData( o
, val
[j
], innerSrc
);
1365 data
[ a
[i
] ].push( o
);
1368 // The inner call to setData has already traversed through the remainder
1369 // of the source and has set the data, thus we can exit here
1372 else if ( funcNotation
)
1375 a
[i
] = a
[i
].replace(__reFn
, '');
1376 data
= data
[ a
[i
] ]( val
);
1379 // If the nested object doesn't currently exist - since we are
1380 // trying to set the value - create it
1381 if ( data
[ a
[i
] ] === null || data
[ a
[i
] ] === undefined )
1385 data
= data
[ a
[i
] ];
1388 // Last item in the input - i.e, the actual set
1389 if ( aLast
.match(__reFn
) )
1392 data
= data
[ aLast
.replace(__reFn
, '') ]( val
);
1396 // If array notation is used, we just want to strip it and use the property name
1397 // and assign the value. If it isn't used, then we get the result we want anyway
1398 data
[ aLast
.replace(__reArray
, '') ] = val
;
1402 return function (data
, val
) { // meta is also passed in, but not used
1403 return setData( data
, val
, mSource
);
1408 /* Array or flat object mapping */
1409 return function (data
, val
) { // meta is also passed in, but not used
1410 data
[mSource
] = val
;
1417 * Return an array with the full table data
1418 * @param {object} oSettings dataTables settings object
1419 * @returns array {array} aData Master data array
1420 * @memberof DataTable#oApi
1422 function _fnGetDataMaster ( settings
)
1424 return _pluck( settings
.aoData
, '_aData' );
1430 * @param {object} oSettings dataTables settings object
1431 * @memberof DataTable#oApi
1433 function _fnClearTable( settings
)
1435 settings
.aoData
.length
= 0;
1436 settings
.aiDisplayMaster
.length
= 0;
1437 settings
.aiDisplay
.length
= 0;
1442 * Take an array of integers (index array) and remove a target integer (value - not
1444 * @param {array} a Index array to target
1445 * @param {int} iTarget value to find
1446 * @memberof DataTable#oApi
1448 function _fnDeleteIndex( a
, iTarget
, splice
)
1450 var iTargetIndex
= -1;
1452 for ( var i
=0, iLen
=a
.length
; i
<iLen
; i
++ )
1454 if ( a
[i
] == iTarget
)
1458 else if ( a
[i
] > iTarget
)
1464 if ( iTargetIndex
!= -1 && splice
=== undefined )
1466 a
.splice( iTargetIndex
, 1 );
1472 * Mark cached data as invalid such that a re-read of the data will occur when
1473 * the cached data is next requested. Also update from the data source object.
1475 * @param {object} settings DataTables settings object
1476 * @param {int} rowIdx Row index to invalidate
1477 * @param {string} [src] Source to invalidate from: undefined, 'auto', 'dom'
1479 * @param {int} [colIdx] Column index to invalidate. If undefined the whole
1480 * row will be invalidated
1481 * @memberof DataTable#oApi
1483 * @todo For the modularisation of v1.11 this will need to become a callback, so
1484 * the sort and filter methods can subscribe to it. That will required
1485 * initialisation options for sorting, which is why it is not already baked in
1487 function _fnInvalidate( settings
, rowIdx
, src
, colIdx
)
1489 var row
= settings
.aoData
[ rowIdx
];
1491 var cellWrite = function ( cell
, col
) {
1492 // This is very frustrating, but in IE if you just write directly
1493 // to innerHTML, and elements that are overwritten are GC'ed,
1494 // even if there is a reference to them elsewhere
1495 while ( cell
.childNodes
.length
) {
1496 cell
.removeChild( cell
.firstChild
);
1499 cell
.innerHTML
= _fnGetCellData( settings
, rowIdx
, col
, 'display' );
1502 // Are we reading last data from DOM or the data object?
1503 if ( src
=== 'dom' || ((! src
|| src
=== 'auto') && row
.src
=== 'dom') ) {
1504 // Read the data from the DOM
1505 row
._aData
= _fnGetRowElements(
1506 settings
, row
, colIdx
, colIdx
=== undefined ? undefined : row
._aData
1511 // Reading from data object, update the DOM
1512 var cells
= row
.anCells
;
1515 if ( colIdx
!== undefined ) {
1516 cellWrite( cells
[colIdx
], colIdx
);
1519 for ( i
=0, ien
=cells
.length
; i
<ien
; i
++ ) {
1520 cellWrite( cells
[i
], i
);
1526 // For both row and cell invalidation, the cached data for sorting and
1527 // filtering is nulled out
1528 row
._aSortData
= null;
1529 row
._aFilterData
= null;
1531 // Invalidate the type for a specific column (if given) or all columns since
1532 // the data might have changed
1533 var cols
= settings
.aoColumns
;
1534 if ( colIdx
!== undefined ) {
1535 cols
[ colIdx
].sType
= null;
1538 for ( i
=0, ien
=cols
.length
; i
<ien
; i
++ ) {
1539 cols
[i
].sType
= null;
1542 // Update DataTables special `DT_*` attributes for the row
1543 _fnRowAttributes( row
);
1549 * Build a data source object from an HTML row, reading the contents of the
1550 * cells that are in the row.
1552 * @param {object} settings DataTables settings object
1553 * @param {node|object} TR element from which to read data or existing row
1554 * object from which to re-read the data from the cells
1555 * @param {int} [colIdx] Optional column index
1556 * @param {array|object} [d] Data source object. If `colIdx` is given then this
1557 * parameter should also be given and will be used to write the data into.
1558 * Only the column in question will be written
1559 * @returns {object} Object with two parameters: `data` the data read, in
1560 * document order, and `cells` and array of nodes (they can be useful to the
1561 * caller, so rather than needing a second traversal to get them, just return
1563 * @memberof DataTable#oApi
1565 function _fnGetRowElements( settings
, row
, colIdx
, d
)
1569 td
= row
.firstChild
,
1570 name
, col
, o
, i
=0, contents
,
1571 columns
= settings
.aoColumns
,
1572 objectRead
= settings
._rowReadObject
;
1574 // Allow the data object to be passed in, or construct
1575 d
= d
|| objectRead
? {} : [];
1577 var attr = function ( str
, td
) {
1578 if ( typeof str
=== 'string' ) {
1579 var idx
= str
.indexOf('@');
1582 var attr
= str
.substring( idx
+1 );
1583 var setter
= _fnSetObjectDataFn( str
);
1584 setter( d
, td
.getAttribute( attr
) );
1589 // Read data from a cell and store into the data object
1590 var cellProcess = function ( cell
) {
1591 if ( colIdx
=== undefined || colIdx
=== i
) {
1593 contents
= $.trim(cell
.innerHTML
);
1595 if ( col
&& col
._bAttrSrc
) {
1596 var setter
= _fnSetObjectDataFn( col
.mData
._
);
1597 setter( d
, contents
);
1599 attr( col
.mData
.sort
, cell
);
1600 attr( col
.mData
.type
, cell
);
1601 attr( col
.mData
.filter
, cell
);
1604 // Depending on the `data` option for the columns the data can
1605 // be read to either an object or an array.
1607 if ( ! col
._setter
) {
1608 // Cache the setter function
1609 col
._setter
= _fnSetObjectDataFn( col
.mData
);
1611 col
._setter( d
, contents
);
1623 // `tr` element was passed in
1625 name
= td
.nodeName
.toUpperCase();
1627 if ( name
== "TD" || name
== "TH" ) {
1632 td
= td
.nextSibling
;
1636 // Existing row object passed in
1639 for ( var j
=0, jen
=tds
.length
; j
<jen
; j
++ ) {
1640 cellProcess( tds
[j
] );
1650 * Create a new TR element (and it's TD children) for a row
1651 * @param {object} oSettings dataTables settings object
1652 * @param {int} iRow Row to consider
1653 * @param {node} [nTrIn] TR element to add to the table - optional. If not given,
1654 * DataTables will create a row automatically
1655 * @param {array} [anTds] Array of TD|TH elements for the row - must be given
1657 * @memberof DataTable#oApi
1659 function _fnCreateTr ( oSettings
, iRow
, nTrIn
, anTds
)
1662 row
= oSettings
.aoData
[iRow
],
1663 rowData
= row
._aData
,
1668 if ( row
.nTr
=== null )
1670 nTr
= nTrIn
|| document
.createElement('tr');
1673 row
.anCells
= cells
;
1675 /* Use a private property on the node to allow reserve mapping from the node
1676 * to the aoData array for fast look up
1678 nTr
._DT_RowIndex
= iRow
;
1680 /* Special parameters can be given by the data source to be used on the row */
1681 _fnRowAttributes( row
);
1683 /* Process each column */
1684 for ( i
=0, iLen
=oSettings
.aoColumns
.length
; i
<iLen
; i
++ )
1686 oCol
= oSettings
.aoColumns
[i
];
1688 nTd
= nTrIn
? anTds
[i
] : document
.createElement( oCol
.sCellType
);
1691 // Need to create the HTML if new, or if a rendering function is defined
1692 if ( !nTrIn
|| oCol
.mRender
|| oCol
.mData
!== i
)
1694 nTd
.innerHTML
= _fnGetCellData( oSettings
, iRow
, i
, 'display' );
1697 /* Add user defined class */
1700 nTd
.className
+= ' '+oCol
.sClass
;
1703 // Visibility - add or remove as required
1704 if ( oCol
.bVisible
&& ! nTrIn
)
1706 nTr
.appendChild( nTd
);
1708 else if ( ! oCol
.bVisible
&& nTrIn
)
1710 nTd
.parentNode
.removeChild( nTd
);
1713 if ( oCol
.fnCreatedCell
)
1715 oCol
.fnCreatedCell
.call( oSettings
.oInstance
,
1716 nTd
, _fnGetCellData( oSettings
, iRow
, i
), rowData
, iRow
, i
1721 _fnCallbackFire( oSettings
, 'aoRowCreatedCallback', null, [nTr
, rowData
, iRow
] );
1724 // Remove once webkit bug 131819 and Chromium bug 365619 have been resolved
1726 row
.nTr
.setAttribute( 'role', 'row' );
1731 * Add attributes to a row based on the special `DT_*` parameters in a data
1733 * @param {object} DataTables row object for the row to be modified
1734 * @memberof DataTable#oApi
1736 function _fnRowAttributes( row
)
1739 var data
= row
._aData
;
1742 if ( data
.DT_RowId
) {
1743 tr
.id
= data
.DT_RowId
;
1746 if ( data
.DT_RowClass
) {
1747 // Remove any classes added by DT_RowClass before
1748 var a
= data
.DT_RowClass
.split(' ');
1749 row
.__rowc
= row
.__rowc
?
1750 _unique( row
.__rowc
.concat( a
) ) :
1754 .removeClass( row
.__rowc
.join(' ') )
1755 .addClass( data
.DT_RowClass
);
1758 if ( data
.DT_RowAttr
) {
1759 $(tr
).attr( data
.DT_RowAttr
);
1762 if ( data
.DT_RowData
) {
1763 $(tr
).data( data
.DT_RowData
);
1770 * Create the HTML header for the table
1771 * @param {object} oSettings dataTables settings object
1772 * @memberof DataTable#oApi
1774 function _fnBuildHead( oSettings
)
1776 var i
, ien
, cell
, row
, column
;
1777 var thead
= oSettings
.nTHead
;
1778 var tfoot
= oSettings
.nTFoot
;
1779 var createHeader
= $('th, td', thead
).length
=== 0;
1780 var classes
= oSettings
.oClasses
;
1781 var columns
= oSettings
.aoColumns
;
1783 if ( createHeader
) {
1784 row
= $('<tr/>').appendTo( thead
);
1787 for ( i
=0, ien
=columns
.length
; i
<ien
; i
++ ) {
1788 column
= columns
[i
];
1789 cell
= $( column
.nTh
).addClass( column
.sClass
);
1791 if ( createHeader
) {
1792 cell
.appendTo( row
);
1795 // 1.11 move into sorting
1796 if ( oSettings
.oFeatures
.bSort
) {
1797 cell
.addClass( column
.sSortingClass
);
1799 if ( column
.bSortable
!== false ) {
1801 .attr( 'tabindex', oSettings
.iTabIndex
)
1802 .attr( 'aria-controls', oSettings
.sTableId
);
1804 _fnSortAttachListener( oSettings
, column
.nTh
, i
);
1808 if ( column
.sTitle
!= cell
.html() ) {
1809 cell
.html( column
.sTitle
);
1812 _fnRenderer( oSettings
, 'header' )(
1813 oSettings
, cell
, column
, classes
1817 if ( createHeader
) {
1818 _fnDetectHeader( oSettings
.aoHeader
, thead
);
1821 /* ARIA role for the rows */
1822 $(thead
).find('>tr').attr('role', 'row');
1824 /* Deal with the footer - add classes if required */
1825 $(thead
).find('>tr>th, >tr>td').addClass( classes
.sHeaderTH
);
1826 $(tfoot
).find('>tr>th, >tr>td').addClass( classes
.sFooterTH
);
1828 // Cache the footer cells. Note that we only take the cells from the first
1829 // row in the footer. If there is more than one row the user wants to
1830 // interact with, they need to use the table().foot() method. Note also this
1831 // allows cells to be used for multiple columns using colspan
1832 if ( tfoot
!== null ) {
1833 var cells
= oSettings
.aoFooter
[0];
1835 for ( i
=0, ien
=cells
.length
; i
<ien
; i
++ ) {
1836 column
= columns
[i
];
1837 column
.nTf
= cells
[i
].cell
;
1839 if ( column
.sClass
) {
1840 $(column
.nTf
).addClass( column
.sClass
);
1848 * Draw the header (or footer) element based on the column visibility states. The
1849 * methodology here is to use the layout array from _fnDetectHeader, modified for
1850 * the instantaneous column visibility, to construct the new layout. The grid is
1851 * traversed over cell at a time in a rows x columns grid fashion, although each
1852 * cell insert can cover multiple elements in the grid - which is tracks using the
1853 * aApplied array. Cell inserts in the grid will only occur where there isn't
1854 * already a cell in that position.
1855 * @param {object} oSettings dataTables settings object
1856 * @param array {objects} aoSource Layout array from _fnDetectHeader
1857 * @param {boolean} [bIncludeHidden=false] If true then include the hidden columns in the calc,
1858 * @memberof DataTable#oApi
1860 function _fnDrawHead( oSettings
, aoSource
, bIncludeHidden
)
1862 var i
, iLen
, j
, jLen
, k
, kLen
, n
, nLocalTr
;
1865 var iColumns
= oSettings
.aoColumns
.length
;
1866 var iRowspan
, iColspan
;
1873 if ( bIncludeHidden
=== undefined )
1875 bIncludeHidden
= false;
1878 /* Make a copy of the master layout array, but without the visible columns in it */
1879 for ( i
=0, iLen
=aoSource
.length
; i
<iLen
; i
++ )
1881 aoLocal
[i
] = aoSource
[i
].slice();
1882 aoLocal
[i
].nTr
= aoSource
[i
].nTr
;
1884 /* Remove any columns which are currently hidden */
1885 for ( j
=iColumns
-1 ; j
>=0 ; j
-- )
1887 if ( !oSettings
.aoColumns
[j
].bVisible
&& !bIncludeHidden
)
1889 aoLocal
[i
].splice( j
, 1 );
1893 /* Prep the applied array - it needs an element for each row */
1894 aApplied
.push( [] );
1897 for ( i
=0, iLen
=aoLocal
.length
; i
<iLen
; i
++ )
1899 nLocalTr
= aoLocal
[i
].nTr
;
1901 /* All cells are going to be replaced, so empty out the row */
1904 while( (n
= nLocalTr
.firstChild
) )
1906 nLocalTr
.removeChild( n
);
1910 for ( j
=0, jLen
=aoLocal
[i
].length
; j
<jLen
; j
++ )
1915 /* Check to see if there is already a cell (row/colspan) covering our target
1916 * insert point. If there is, then there is nothing to do.
1918 if ( aApplied
[i
][j
] === undefined )
1920 nLocalTr
.appendChild( aoLocal
[i
][j
].cell
);
1923 /* Expand the cell to cover as many rows as needed */
1924 while ( aoLocal
[i
+iRowspan
] !== undefined &&
1925 aoLocal
[i
][j
].cell
== aoLocal
[i
+iRowspan
][j
].cell
)
1927 aApplied
[i
+iRowspan
][j
] = 1;
1931 /* Expand the cell to cover as many columns as needed */
1932 while ( aoLocal
[i
][j
+iColspan
] !== undefined &&
1933 aoLocal
[i
][j
].cell
== aoLocal
[i
][j
+iColspan
].cell
)
1935 /* Must update the applied array over the rows for the columns */
1936 for ( k
=0 ; k
<iRowspan
; k
++ )
1938 aApplied
[i
+k
][j
+iColspan
] = 1;
1943 /* Do the actual expansion in the DOM */
1944 $(aoLocal
[i
][j
].cell
)
1945 .attr('rowspan', iRowspan
)
1946 .attr('colspan', iColspan
);
1954 * Insert the required TR nodes into the table for display
1955 * @param {object} oSettings dataTables settings object
1956 * @memberof DataTable#oApi
1958 function _fnDraw( oSettings
)
1960 /* Provide a pre-callback function which can be used to cancel the draw is false is returned */
1961 var aPreDraw
= _fnCallbackFire( oSettings
, 'aoPreDrawCallback', 'preDraw', [oSettings
] );
1962 if ( $.inArray( false, aPreDraw
) !== -1 )
1964 _fnProcessingDisplay( oSettings
, false );
1971 var asStripeClasses
= oSettings
.asStripeClasses
;
1972 var iStripes
= asStripeClasses
.length
;
1973 var iOpenRows
= oSettings
.aoOpenRows
.length
;
1974 var oLang
= oSettings
.oLanguage
;
1975 var iInitDisplayStart
= oSettings
.iInitDisplayStart
;
1976 var bServerSide
= _fnDataSource( oSettings
) == 'ssp';
1977 var aiDisplay
= oSettings
.aiDisplay
;
1979 oSettings
.bDrawing
= true;
1981 /* Check and see if we have an initial draw position from state saving */
1982 if ( iInitDisplayStart
!== undefined && iInitDisplayStart
!== -1 )
1984 oSettings
._iDisplayStart
= bServerSide
?
1986 iInitDisplayStart
>= oSettings
.fnRecordsDisplay() ?
1990 oSettings
.iInitDisplayStart
= -1;
1993 var iDisplayStart
= oSettings
._iDisplayStart
;
1994 var iDisplayEnd
= oSettings
.fnDisplayEnd();
1996 /* Server-side processing draw intercept */
1997 if ( oSettings
.bDeferLoading
)
1999 oSettings
.bDeferLoading
= false;
2001 _fnProcessingDisplay( oSettings
, false );
2003 else if ( !bServerSide
)
2007 else if ( !oSettings
.bDestroying
&& !_fnAjaxUpdate( oSettings
) )
2012 if ( aiDisplay
.length
!== 0 )
2014 var iStart
= bServerSide
? 0 : iDisplayStart
;
2015 var iEnd
= bServerSide
? oSettings
.aoData
.length
: iDisplayEnd
;
2017 for ( var j
=iStart
; j
<iEnd
; j
++ )
2019 var iDataIndex
= aiDisplay
[j
];
2020 var aoData
= oSettings
.aoData
[ iDataIndex
];
2021 if ( aoData
.nTr
=== null )
2023 _fnCreateTr( oSettings
, iDataIndex
);
2026 var nRow
= aoData
.nTr
;
2028 /* Remove the old striping classes and then add the new one */
2029 if ( iStripes
!== 0 )
2031 var sStripe
= asStripeClasses
[ iRowCount
% iStripes
];
2032 if ( aoData
._sRowStripe
!= sStripe
)
2034 $(nRow
).removeClass( aoData
._sRowStripe
).addClass( sStripe
);
2035 aoData
._sRowStripe
= sStripe
;
2039 // Row callback functions - might want to manipulate the row
2040 // iRowCount and j are not currently documented. Are they at all
2042 _fnCallbackFire( oSettings
, 'aoRowCallback', null,
2043 [nRow
, aoData
._aData
, iRowCount
, j
] );
2045 anRows
.push( nRow
);
2051 /* Table is empty - create a row with an empty message in it */
2052 var sZero
= oLang
.sZeroRecords
;
2053 if ( oSettings
.iDraw
== 1 && _fnDataSource( oSettings
) == 'ajax' )
2055 sZero
= oLang
.sLoadingRecords
;
2057 else if ( oLang
.sEmptyTable
&& oSettings
.fnRecordsTotal() === 0 )
2059 sZero
= oLang
.sEmptyTable
;
2062 anRows
[ 0 ] = $( '<tr/>', { 'class': iStripes
? asStripeClasses
[0] : '' } )
2063 .append( $('<td />', {
2065 'colSpan': _fnVisbleColumns( oSettings
),
2066 'class': oSettings
.oClasses
.sRowEmpty
2067 } ).html( sZero
) )[0];
2070 /* Header and footer callbacks */
2071 _fnCallbackFire( oSettings
, 'aoHeaderCallback', 'header', [ $(oSettings
.nTHead
).children('tr')[0],
2072 _fnGetDataMaster( oSettings
), iDisplayStart
, iDisplayEnd
, aiDisplay
] );
2074 _fnCallbackFire( oSettings
, 'aoFooterCallback', 'footer', [ $(oSettings
.nTFoot
).children('tr')[0],
2075 _fnGetDataMaster( oSettings
), iDisplayStart
, iDisplayEnd
, aiDisplay
] );
2077 var body
= $(oSettings
.nTBody
);
2079 body
.children().detach();
2080 body
.append( $(anRows
) );
2082 /* Call all required callback functions for the end of a draw */
2083 _fnCallbackFire( oSettings
, 'aoDrawCallback', 'draw', [oSettings
] );
2085 /* Draw is complete, sorting and filtering must be as well */
2086 oSettings
.bSorted
= false;
2087 oSettings
.bFiltered
= false;
2088 oSettings
.bDrawing
= false;
2093 * Redraw the table - taking account of the various features which are enabled
2094 * @param {object} oSettings dataTables settings object
2095 * @param {boolean} [holdPosition] Keep the current paging position. By default
2096 * the paging is reset to the first page
2097 * @memberof DataTable#oApi
2099 function _fnReDraw( settings
, holdPosition
)
2102 features
= settings
.oFeatures
,
2103 sort
= features
.bSort
,
2104 filter
= features
.bFilter
;
2107 _fnSort( settings
);
2111 _fnFilterComplete( settings
, settings
.oPreviousSearch
);
2114 // No filtering, so we want to just use the display master
2115 settings
.aiDisplay
= settings
.aiDisplayMaster
.slice();
2118 if ( holdPosition
!== true ) {
2119 settings
._iDisplayStart
= 0;
2122 // Let any modules know about the draw hold position state (used by
2123 // scrolling internally)
2124 settings
._drawHold
= holdPosition
;
2126 _fnDraw( settings
);
2128 settings
._drawHold
= false;
2133 * Add the options to the page HTML for the table
2134 * @param {object} oSettings dataTables settings object
2135 * @memberof DataTable#oApi
2137 function _fnAddOptionsHtml ( oSettings
)
2139 var classes
= oSettings
.oClasses
;
2140 var table
= $(oSettings
.nTable
);
2141 var holding
= $('<div/>').insertBefore( table
); // Holding element for speed
2142 var features
= oSettings
.oFeatures
;
2144 // All DataTables are wrapped in a div
2145 var insert
= $('<div/>', {
2146 id
: oSettings
.sTableId
+'_wrapper',
2147 'class': classes
.sWrapper
+ (oSettings
.nTFoot
? '' : ' '+classes
.sNoFooter
)
2150 oSettings
.nHolding
= holding
[0];
2151 oSettings
.nTableWrapper
= insert
[0];
2152 oSettings
.nTableReinsertBefore
= oSettings
.nTable
.nextSibling
;
2154 /* Loop over the user set positioning and place the elements as needed */
2155 var aDom
= oSettings
.sDom
.split('');
2156 var featureNode
, cOption
, nNewNode
, cNext
, sAttr
, j
;
2157 for ( var i
=0 ; i
<aDom
.length
; i
++ )
2162 if ( cOption
== '<' )
2164 /* New container div */
2165 nNewNode
= $('<div/>')[0];
2167 /* Check to see if we should append an id and/or a class name to the container */
2169 if ( cNext == "'" || cNext == '"' )
2173 while ( aDom[i+j] != cNext )
2179 /* Replace jQuery UI constants @todo depreciated */
2182 sAttr
= classes
.sJUIHeader
;
2184 else if ( sAttr
== "F" )
2186 sAttr
= classes
.sJUIFooter
;
2189 /* The attribute can be in the format of "#id.class", "#id" or "class" This logic
2190 * breaks the string into parts and applies them as needed
2192 if ( sAttr
.indexOf('.') != -1 )
2194 var aSplit
= sAttr
.split('.');
2195 nNewNode
.id
= aSplit
[0].substr(1, aSplit
[0].length
-1);
2196 nNewNode
.className
= aSplit
[1];
2198 else if ( sAttr
.charAt(0) == "#" )
2200 nNewNode
.id
= sAttr
.substr(1, sAttr
.length
-1);
2204 nNewNode
.className
= sAttr
;
2207 i
+= j
; /* Move along the position array */
2210 insert
.append( nNewNode
);
2211 insert
= $(nNewNode
);
2213 else if ( cOption
== '>' )
2215 /* End container div */
2216 insert
= insert
.parent();
2218 // @todo Move options into their own plugins?
2219 else if ( cOption
== 'l' && features
.bPaginate
&& features
.bLengthChange
)
2222 featureNode
= _fnFeatureHtmlLength( oSettings
);
2224 else if ( cOption
== 'f' && features
.bFilter
)
2227 featureNode
= _fnFeatureHtmlFilter( oSettings
);
2229 else if ( cOption
== 'r' && features
.bProcessing
)
2232 featureNode
= _fnFeatureHtmlProcessing( oSettings
);
2234 else if ( cOption
== 't' )
2237 featureNode
= _fnFeatureHtmlTable( oSettings
);
2239 else if ( cOption
== 'i' && features
.bInfo
)
2242 featureNode
= _fnFeatureHtmlInfo( oSettings
);
2244 else if ( cOption
== 'p' && features
.bPaginate
)
2247 featureNode
= _fnFeatureHtmlPaginate( oSettings
);
2249 else if ( DataTable
.ext
.feature
.length
!== 0 )
2251 /* Plug-in features */
2252 var aoFeatures
= DataTable
.ext
.feature
;
2253 for ( var k
=0, kLen
=aoFeatures
.length
; k
<kLen
; k
++ )
2255 if ( cOption
== aoFeatures
[k
].cFeature
)
2257 featureNode
= aoFeatures
[k
].fnInit( oSettings
);
2263 /* Add to the 2D features array */
2266 var aanFeatures
= oSettings
.aanFeatures
;
2268 if ( ! aanFeatures
[cOption
] )
2270 aanFeatures
[cOption
] = [];
2273 aanFeatures
[cOption
].push( featureNode
);
2274 insert
.append( featureNode
);
2278 /* Built our DOM structure - replace the holding div with what we want */
2279 holding
.replaceWith( insert
);
2284 * Use the DOM source to create up an array of header cells. The idea here is to
2285 * create a layout grid (array) of rows x columns, which contains a reference
2286 * to the cell that that point in the grid (regardless of col/rowspan), such that
2287 * any column / row could be removed and the new grid constructed
2288 * @param array {object} aLayout Array to store the calculated layout in
2289 * @param {node} nThead The header/footer element for the table
2290 * @memberof DataTable#oApi
2292 function _fnDetectHeader ( aLayout
, nThead
)
2294 var nTrs
= $(nThead
).children('tr');
2296 var i
, k
, l
, iLen
, jLen
, iColShifted
, iColumn
, iColspan
, iRowspan
;
2298 var fnShiftCol = function ( a
, i
, j
) {
2306 aLayout
.splice( 0, aLayout
.length
);
2308 /* We know how many rows there are in the layout - so prep it */
2309 for ( i
=0, iLen
=nTrs
.length
; i
<iLen
; i
++ )
2314 /* Calculate a layout array */
2315 for ( i
=0, iLen
=nTrs
.length
; i
<iLen
; i
++ )
2320 /* For every cell in the row... */
2321 nCell
= nTr
.firstChild
;
2323 if ( nCell
.nodeName
.toUpperCase() == "TD" ||
2324 nCell
.nodeName
.toUpperCase() == "TH" )
2326 /* Get the col and rowspan attributes from the DOM and sanitise them */
2327 iColspan
= nCell
.getAttribute('colspan') * 1;
2328 iRowspan
= nCell
.getAttribute('rowspan') * 1;
2329 iColspan
= (!iColspan
|| iColspan
===0 || iColspan
===1) ? 1 : iColspan
;
2330 iRowspan
= (!iRowspan
|| iRowspan
===0 || iRowspan
===1) ? 1 : iRowspan
;
2332 /* There might be colspan cells already in this row, so shift our target
2335 iColShifted
= fnShiftCol( aLayout
, i
, iColumn
);
2337 /* Cache calculation for unique columns */
2338 bUnique
= iColspan
=== 1 ? true : false;
2340 /* If there is col / rowspan, copy the information into the layout grid */
2341 for ( l
=0 ; l
<iColspan
; l
++ )
2343 for ( k
=0 ; k
<iRowspan
; k
++ )
2345 aLayout
[i
+k
][iColShifted
+l
] = {
2349 aLayout
[i
+k
].nTr
= nTr
;
2353 nCell
= nCell
.nextSibling
;
2360 * Get an array of unique th elements, one for each column
2361 * @param {object} oSettings dataTables settings object
2362 * @param {node} nHeader automatically detect the layout from this node - optional
2363 * @param {array} aLayout thead/tfoot layout from _fnDetectHeader - optional
2364 * @returns array {node} aReturn list of unique th's
2365 * @memberof DataTable#oApi
2367 function _fnGetUniqueThs ( oSettings
, nHeader
, aLayout
)
2372 aLayout
= oSettings
.aoHeader
;
2376 _fnDetectHeader( aLayout
, nHeader
);
2380 for ( var i
=0, iLen
=aLayout
.length
; i
<iLen
; i
++ )
2382 for ( var j
=0, jLen
=aLayout
[i
].length
; j
<jLen
; j
++ )
2384 if ( aLayout
[i
][j
].unique
&&
2385 (!aReturn
[j
] || !oSettings
.bSortCellsTop
) )
2387 aReturn
[j
] = aLayout
[i
][j
].cell
;
2396 * Create an Ajax call based on the table's settings, taking into account that
2397 * parameters can have multiple forms, and backwards compatibility.
2399 * @param {object} oSettings dataTables settings object
2400 * @param {array} data Data to send to the server, required by
2401 * DataTables - may be augmented by developer callbacks
2402 * @param {function} fn Callback function to run when data is obtained
2404 function _fnBuildAjax( oSettings
, data
, fn
)
2406 // Compatibility with 1.9-, allow fnServerData and event to manipulate
2407 _fnCallbackFire( oSettings
, 'aoServerParams', 'serverParams', [data
] );
2409 // Convert to object based for 1.10+ if using the old array scheme which can
2410 // come from server-side processing or serverParams
2411 if ( data
&& $.isArray(data
) ) {
2413 var rbracket
= /(.*?)\[\]$/;
2415 $.each( data
, function (key
, val
) {
2416 var match
= val
.name
.match(rbracket
);
2419 // Support for arrays
2420 var name
= match
[0];
2422 if ( ! tmp
[ name
] ) {
2425 tmp
[ name
].push( val
.value
);
2428 tmp
[val
.name
] = val
.value
;
2435 var ajax
= oSettings
.ajax
;
2436 var instance
= oSettings
.oInstance
;
2437 var callback = function ( json
) {
2438 _fnCallbackFire( oSettings
, null, 'xhr', [oSettings
, json
, oSettings
.jqXHR
] );
2442 if ( $.isPlainObject( ajax
) && ajax
.data
)
2444 ajaxData
= ajax
.data
;
2446 var newData
= $.isFunction( ajaxData
) ?
2447 ajaxData( data
, oSettings
) : // fn can manipulate data or return
2448 ajaxData
; // an object object or array to merge
2450 // If the function returned something, use that alone
2451 data
= $.isFunction( ajaxData
) && newData
?
2453 $.extend( true, data
, newData
);
2455 // Remove the data property as we've resolved it already and don't want
2456 // jQuery to do it again (it is restored at the end of the function)
2462 "success": function (json
) {
2463 var error
= json
.error
|| json
.sError
;
2465 _fnLog( oSettings
, 0, error
);
2468 oSettings
.json
= json
;
2473 "type": oSettings
.sServerMethod
,
2474 "error": function (xhr
, error
, thrown
) {
2475 var ret
= _fnCallbackFire( oSettings
, null, 'xhr', [oSettings
, null, oSettings
.jqXHR
] );
2477 if ( $.inArray( true, ret
) === -1 ) {
2478 if ( error
== "parsererror" ) {
2479 _fnLog( oSettings
, 0, 'Invalid JSON response', 1 );
2481 else if ( xhr
.readyState
=== 4 ) {
2482 _fnLog( oSettings
, 0, 'Ajax error', 7 );
2486 _fnProcessingDisplay( oSettings
, false );
2490 // Store the data submitted for the API
2491 oSettings
.oAjaxData
= data
;
2493 // Allow plug-ins and external processes to modify the data
2494 _fnCallbackFire( oSettings
, null, 'preXhr', [oSettings
, data
] );
2496 if ( oSettings
.fnServerData
)
2498 // DataTables 1.9- compatibility
2499 oSettings
.fnServerData
.call( instance
,
2500 oSettings
.sAjaxSource
,
2501 $.map( data
, function (val
, key
) { // Need to convert back to 1.9 trad format
2502 return { name
: key
, value
: val
};
2508 else if ( oSettings
.sAjaxSource
|| typeof ajax
=== 'string' )
2510 // DataTables 1.9- compatibility
2511 oSettings
.jqXHR
= $.ajax( $.extend( baseAjax
, {
2512 url
: ajax
|| oSettings
.sAjaxSource
2515 else if ( $.isFunction( ajax
) )
2517 // Is a function - let the caller define what needs to be done
2518 oSettings
.jqXHR
= ajax
.call( instance
, data
, callback
, oSettings
);
2522 // Object to extend the base settings
2523 oSettings
.jqXHR
= $.ajax( $.extend( baseAjax
, ajax
) );
2525 // Restore for next time around
2526 ajax
.data
= ajaxData
;
2532 * Update the table using an Ajax call
2533 * @param {object} settings dataTables settings object
2534 * @returns {boolean} Block the table drawing or not
2535 * @memberof DataTable#oApi
2537 function _fnAjaxUpdate( settings
)
2539 if ( settings
.bAjaxDataGet
) {
2541 _fnProcessingDisplay( settings
, true );
2545 _fnAjaxParameters( settings
),
2547 _fnAjaxUpdateDraw( settings
, json
);
2558 * Build up the parameters in an object needed for a server-side processing
2559 * request. Note that this is basically done twice, is different ways - a modern
2560 * method which is used by default in DataTables 1.10 which uses objects and
2561 * arrays, or the 1.9- method with is name / value pairs. 1.9 method is used if
2562 * the sAjaxSource option is used in the initialisation, or the legacyAjax
2564 * @param {object} oSettings dataTables settings object
2565 * @returns {bool} block the table drawing or not
2566 * @memberof DataTable#oApi
2568 function _fnAjaxParameters( settings
)
2571 columns
= settings
.aoColumns
,
2572 columnCount
= columns
.length
,
2573 features
= settings
.oFeatures
,
2574 preSearch
= settings
.oPreviousSearch
,
2575 preColSearch
= settings
.aoPreSearchCols
,
2576 i
, data
= [], dataProp
, column
, columnSearch
,
2577 sort
= _fnSortFlatten( settings
),
2578 displayStart
= settings
._iDisplayStart
,
2579 displayLength
= features
.bPaginate
!== false ?
2580 settings
._iDisplayLength
:
2583 var param = function ( name
, value
) {
2584 data
.push( { 'name': name
, 'value': value
} );
2587 // DataTables 1.9- compatible method
2588 param( 'sEcho', settings
.iDraw
);
2589 param( 'iColumns', columnCount
);
2590 param( 'sColumns', _pluck( columns
, 'sName' ).join(',') );
2591 param( 'iDisplayStart', displayStart
);
2592 param( 'iDisplayLength', displayLength
);
2594 // DataTables 1.10+ method
2596 draw
: settings
.iDraw
,
2599 start
: displayStart
,
2600 length
: displayLength
,
2602 value
: preSearch
.sSearch
,
2603 regex
: preSearch
.bRegex
2607 for ( i
=0 ; i
<columnCount
; i
++ ) {
2608 column
= columns
[i
];
2609 columnSearch
= preColSearch
[i
];
2610 dataProp
= typeof column
.mData
=="function" ? 'function' : column
.mData
;
2615 searchable
: column
.bSearchable
,
2616 orderable
: column
.bSortable
,
2618 value
: columnSearch
.sSearch
,
2619 regex
: columnSearch
.bRegex
2623 param( "mDataProp_"+i
, dataProp
);
2625 if ( features
.bFilter
) {
2626 param( 'sSearch_'+i
, columnSearch
.sSearch
);
2627 param( 'bRegex_'+i
, columnSearch
.bRegex
);
2628 param( 'bSearchable_'+i
, column
.bSearchable
);
2631 if ( features
.bSort
) {
2632 param( 'bSortable_'+i
, column
.bSortable
);
2636 if ( features
.bFilter
) {
2637 param( 'sSearch', preSearch
.sSearch
);
2638 param( 'bRegex', preSearch
.bRegex
);
2641 if ( features
.bSort
) {
2642 $.each( sort
, function ( i
, val
) {
2643 d
.order
.push( { column
: val
.col
, dir
: val
.dir
} );
2645 param( 'iSortCol_'+i
, val
.col
);
2646 param( 'sSortDir_'+i
, val
.dir
);
2649 param( 'iSortingCols', sort
.length
);
2652 // If the legacy.ajax parameter is null, then we automatically decide which
2653 // form to use, based on sAjaxSource
2654 var legacy
= DataTable
.ext
.legacy
.ajax
;
2655 if ( legacy
=== null ) {
2656 return settings
.sAjaxSource
? data
: d
;
2659 // Otherwise, if legacy has been specified then we use that to decide on the
2661 return legacy
? data
: d
;
2666 * Data the data from the server (nuking the old) and redraw the table
2667 * @param {object} oSettings dataTables settings object
2668 * @param {object} json json data return from the server.
2669 * @param {string} json.sEcho Tracking flag for DataTables to match requests
2670 * @param {int} json.iTotalRecords Number of records in the data set, not accounting for filtering
2671 * @param {int} json.iTotalDisplayRecords Number of records in the data set, accounting for filtering
2672 * @param {array} json.aaData The data to display on this page
2673 * @param {string} [json.sColumns] Column ordering (sName, comma separated)
2674 * @memberof DataTable#oApi
2676 function _fnAjaxUpdateDraw ( settings
, json
)
2678 // v1.10 uses camelCase variables, while 1.9 uses Hungarian notation.
2680 var compat = function ( old
, modern
) {
2681 return json
[old
] !== undefined ? json
[old
] : json
[modern
];
2684 var data
= _fnAjaxDataSrc( settings
, json
);
2685 var draw
= compat( 'sEcho', 'draw' );
2686 var recordsTotal
= compat( 'iTotalRecords', 'recordsTotal' );
2687 var recordsFiltered
= compat( 'iTotalDisplayRecords', 'recordsFiltered' );
2690 // Protect against out of sequence returns
2691 if ( draw
*1 < settings
.iDraw
) {
2694 settings
.iDraw
= draw
* 1;
2697 _fnClearTable( settings
);
2698 settings
._iRecordsTotal
= parseInt(recordsTotal
, 10);
2699 settings
._iRecordsDisplay
= parseInt(recordsFiltered
, 10);
2701 for ( var i
=0, ien
=data
.length
; i
<ien
; i
++ ) {
2702 _fnAddData( settings
, data
[i
] );
2704 settings
.aiDisplay
= settings
.aiDisplayMaster
.slice();
2706 settings
.bAjaxDataGet
= false;
2707 _fnDraw( settings
);
2709 if ( ! settings
._bInitComplete
) {
2710 _fnInitComplete( settings
, json
);
2713 settings
.bAjaxDataGet
= true;
2714 _fnProcessingDisplay( settings
, false );
2719 * Get the data from the JSON data source to use for drawing a table. Using
2720 * `_fnGetObjectDataFn` allows the data to be sourced from a property of the
2721 * source object, or from a processing function.
2722 * @param {object} oSettings dataTables settings object
2723 * @param {object} json Data source object / array from the server
2724 * @return {array} Array of data to use
2726 function _fnAjaxDataSrc ( oSettings
, json
)
2728 var dataSrc
= $.isPlainObject( oSettings
.ajax
) && oSettings
.ajax
.dataSrc
!== undefined ?
2729 oSettings
.ajax
.dataSrc
:
2730 oSettings
.sAjaxDataProp
; // Compatibility with 1.9-.
2732 // Compatibility with 1.9-. In order to read from aaData, check if the
2733 // default has been changed, if not, check for aaData
2734 if ( dataSrc
=== 'data' ) {
2735 return json
.aaData
|| json
[dataSrc
];
2738 return dataSrc
!== "" ?
2739 _fnGetObjectDataFn( dataSrc
)( json
) :
2744 * Generate the node required for filtering text
2745 * @returns {node} Filter control element
2746 * @param {object} oSettings dataTables settings object
2747 * @memberof DataTable#oApi
2749 function _fnFeatureHtmlFilter ( settings
)
2751 var classes
= settings
.oClasses
;
2752 var tableId
= settings
.sTableId
;
2753 var language
= settings
.oLanguage
;
2754 var previousSearch
= settings
.oPreviousSearch
;
2755 var features
= settings
.aanFeatures
;
2756 var input
= '<input type="search" class="'+classes
.sFilterInput
+'"/>';
2758 var str
= language
.sSearch
;
2759 str
= str
.match(/_INPUT_/) ?
2760 str
.replace('_INPUT_', input
) :
2763 var filter
= $('<div/>', {
2764 'id': ! features
.f
? tableId
+'_filter' : null,
2765 'class': classes
.sFilter
2767 .append( $('<label/>' ).append( str
) );
2769 var searchFn = function() {
2770 /* Update all other filter input elements for the new display */
2772 var val
= !this.value
? "" : this.value
; // mental IE8 fix :-(
2774 /* Now do the filter */
2775 if ( val
!= previousSearch
.sSearch
) {
2776 _fnFilterComplete( settings
, {
2778 "bRegex": previousSearch
.bRegex
,
2779 "bSmart": previousSearch
.bSmart
,
2780 "bCaseInsensitive": previousSearch
.bCaseInsensitive
2783 // Need to redraw, without resorting
2784 settings
._iDisplayStart
= 0;
2785 _fnDraw( settings
);
2789 var searchDelay
= settings
.searchDelay
!== null ?
2790 settings
.searchDelay
:
2791 _fnDataSource( settings
) === 'ssp' ?
2795 var jqFilter
= $('input', filter
)
2796 .val( previousSearch
.sSearch
)
2797 .attr( 'placeholder', language
.sSearchPlaceholder
)
2799 'keyup.DT search.DT input.DT paste.DT cut.DT',
2801 _fnThrottle( searchFn
, searchDelay
) :
2804 .bind( 'keypress.DT', function(e
) {
2805 /* Prevent form submission */
2806 if ( e
.keyCode
== 13 ) {
2810 .attr('aria-controls', tableId
);
2812 // Update the input elements whenever the table is filtered
2813 $(settings
.nTable
).on( 'search.dt.DT', function ( ev
, s
) {
2814 if ( settings
=== s
) {
2815 // IE9 throws an 'unknown error' if document.activeElement is used
2816 // inside an iframe or frame...
2818 if ( jqFilter
[0] !== document
.activeElement
) {
2819 jqFilter
.val( previousSearch
.sSearch
);
2831 * Filter the table using both the global filter and column based filtering
2832 * @param {object} oSettings dataTables settings object
2833 * @param {object} oSearch search information
2834 * @param {int} [iForce] force a research of the master array (1) or not (undefined or 0)
2835 * @memberof DataTable#oApi
2837 function _fnFilterComplete ( oSettings
, oInput
, iForce
)
2839 var oPrevSearch
= oSettings
.oPreviousSearch
;
2840 var aoPrevSearch
= oSettings
.aoPreSearchCols
;
2841 var fnSaveFilter = function ( oFilter
) {
2842 /* Save the filtering values */
2843 oPrevSearch
.sSearch
= oFilter
.sSearch
;
2844 oPrevSearch
.bRegex
= oFilter
.bRegex
;
2845 oPrevSearch
.bSmart
= oFilter
.bSmart
;
2846 oPrevSearch
.bCaseInsensitive
= oFilter
.bCaseInsensitive
;
2848 var fnRegex = function ( o
) {
2849 // Backwards compatibility with the bEscapeRegex option
2850 return o
.bEscapeRegex
!== undefined ? !o
.bEscapeRegex
: o
.bRegex
;
2853 // Resolve any column types that are unknown due to addition or invalidation
2854 // @todo As per sort - can this be moved into an event handler?
2855 _fnColumnTypes( oSettings
);
2857 /* In server-side processing all filtering is done by the server, so no point hanging around here */
2858 if ( _fnDataSource( oSettings
) != 'ssp' )
2861 _fnFilter( oSettings
, oInput
.sSearch
, iForce
, fnRegex(oInput
), oInput
.bSmart
, oInput
.bCaseInsensitive
);
2862 fnSaveFilter( oInput
);
2864 /* Now do the individual column filter */
2865 for ( var i
=0 ; i
<aoPrevSearch
.length
; i
++ )
2867 _fnFilterColumn( oSettings
, aoPrevSearch
[i
].sSearch
, i
, fnRegex(aoPrevSearch
[i
]),
2868 aoPrevSearch
[i
].bSmart
, aoPrevSearch
[i
].bCaseInsensitive
);
2871 /* Custom filtering */
2872 _fnFilterCustom( oSettings
);
2876 fnSaveFilter( oInput
);
2879 /* Tell the draw function we have been filtering */
2880 oSettings
.bFiltered
= true;
2881 _fnCallbackFire( oSettings
, null, 'search', [oSettings
] );
2886 * Apply custom filtering functions
2887 * @param {object} oSettings dataTables settings object
2888 * @memberof DataTable#oApi
2890 function _fnFilterCustom( settings
)
2892 var filters
= DataTable
.ext
.search
;
2893 var displayRows
= settings
.aiDisplay
;
2896 for ( var i
=0, ien
=filters
.length
; i
<ien
; i
++ ) {
2899 // Loop over each row and see if it should be included
2900 for ( var j
=0, jen
=displayRows
.length
; j
<jen
; j
++ ) {
2901 rowIdx
= displayRows
[ j
];
2902 row
= settings
.aoData
[ rowIdx
];
2904 if ( filters
[i
]( settings
, row
._aFilterData
, rowIdx
, row
._aData
, j
) ) {
2905 rows
.push( rowIdx
);
2909 // So the array reference doesn't break set the results into the
2911 displayRows
.length
= 0;
2912 displayRows
.push
.apply( displayRows
, rows
);
2918 * Filter the table on a per-column basis
2919 * @param {object} oSettings dataTables settings object
2920 * @param {string} sInput string to filter on
2921 * @param {int} iColumn column to filter
2922 * @param {bool} bRegex treat search string as a regular expression or not
2923 * @param {bool} bSmart use smart filtering or not
2924 * @param {bool} bCaseInsensitive Do case insenstive matching or not
2925 * @memberof DataTable#oApi
2927 function _fnFilterColumn ( settings
, searchStr
, colIdx
, regex
, smart
, caseInsensitive
)
2929 if ( searchStr
=== '' ) {
2934 var display
= settings
.aiDisplay
;
2935 var rpSearch
= _fnFilterCreateSearch( searchStr
, regex
, smart
, caseInsensitive
);
2937 for ( var i
=display
.length
-1 ; i
>=0 ; i
-- ) {
2938 data
= settings
.aoData
[ display
[i
] ]._aFilterData
[ colIdx
];
2940 if ( ! rpSearch
.test( data
) ) {
2941 display
.splice( i
, 1 );
2948 * Filter the data table based on user input and draw the table
2949 * @param {object} settings dataTables settings object
2950 * @param {string} input string to filter on
2951 * @param {int} force optional - force a research of the master array (1) or not (undefined or 0)
2952 * @param {bool} regex treat as a regular expression or not
2953 * @param {bool} smart perform smart filtering or not
2954 * @param {bool} caseInsensitive Do case insenstive matching or not
2955 * @memberof DataTable#oApi
2957 function _fnFilter( settings
, input
, force
, regex
, smart
, caseInsensitive
)
2959 var rpSearch
= _fnFilterCreateSearch( input
, regex
, smart
, caseInsensitive
);
2960 var prevSearch
= settings
.oPreviousSearch
.sSearch
;
2961 var displayMaster
= settings
.aiDisplayMaster
;
2962 var display
, invalidated
, i
;
2964 // Need to take account of custom filtering functions - always filter
2965 if ( DataTable
.ext
.search
.length
!== 0 ) {
2969 // Check if any of the rows were invalidated
2970 invalidated
= _fnFilterData( settings
);
2972 // If the input is blank - we just want the full data set
2973 if ( input
.length
<= 0 ) {
2974 settings
.aiDisplay
= displayMaster
.slice();
2977 // New search - start from the master array
2980 prevSearch
.length
> input
.length
||
2981 input
.indexOf(prevSearch
) !== 0 ||
2982 settings
.bSorted
// On resort, the display master needs to be
2983 // re-filtered since indexes will have changed
2985 settings
.aiDisplay
= displayMaster
.slice();
2988 // Search the display array
2989 display
= settings
.aiDisplay
;
2991 for ( i
=display
.length
-1 ; i
>=0 ; i
-- ) {
2992 if ( ! rpSearch
.test( settings
.aoData
[ display
[i
] ]._sFilterRow
) ) {
2993 display
.splice( i
, 1 );
3001 * Build a regular expression object suitable for searching a table
3002 * @param {string} sSearch string to search for
3003 * @param {bool} bRegex treat as a regular expression or not
3004 * @param {bool} bSmart perform smart filtering or not
3005 * @param {bool} bCaseInsensitive Do case insensitive matching or not
3006 * @returns {RegExp} constructed object
3007 * @memberof DataTable#oApi
3009 function _fnFilterCreateSearch( search
, regex
, smart
, caseInsensitive
)
3013 _fnEscapeRegex( search
);
3016 /* For smart filtering we want to allow the search to work regardless of
3017 * word order. We also want double quoted text to be preserved, so word
3018 * order is important - a la google. So this is what we want to
3021 * ^(?=.*?\bone\b)(?=.*?\btwo three\b)(?=.*?\bfour\b).*$
3023 var a
= $.map( search
.match( /"[^"]+"|[^ ]+/g ) || [''], function ( word
) {
3024 if ( word
.charAt(0) === '"' ) {
3025 var m
= word
.match( /^"(.*)"$/ );
3026 word
= m
? m
[1] : word
;
3029 return word
.replace('"', '');
3032 search
= '^(?=.*?'+a
.join( ')(?=.*?' )+').*$';
3035 return new RegExp( search
, caseInsensitive
? 'i' : '' );
3040 * Escape a string such that it can be used in a regular expression
3041 * @param {string} sVal string to escape
3042 * @returns {string} escaped string
3043 * @memberof DataTable#oApi
3045 function _fnEscapeRegex ( sVal
)
3047 return sVal
.replace( _re_escape_regex
, '\\$1' );
3052 var __filter_div
= $('<div>')[0];
3053 var __filter_div_textContent
= __filter_div
.textContent
!== undefined;
3055 // Update the filtering data for each row if needed (by invalidation or first run)
3056 function _fnFilterData ( settings
)
3058 var columns
= settings
.aoColumns
;
3060 var i
, j
, ien
, jen
, filterData
, cellData
, row
;
3061 var fomatters
= DataTable
.ext
.type
.search
;
3062 var wasInvalidated
= false;
3064 for ( i
=0, ien
=settings
.aoData
.length
; i
<ien
; i
++ ) {
3065 row
= settings
.aoData
[i
];
3067 if ( ! row
._aFilterData
) {
3070 for ( j
=0, jen
=columns
.length
; j
<jen
; j
++ ) {
3071 column
= columns
[j
];
3073 if ( column
.bSearchable
) {
3074 cellData
= _fnGetCellData( settings
, i
, j
, 'filter' );
3076 if ( fomatters
[ column
.sType
] ) {
3077 cellData
= fomatters
[ column
.sType
]( cellData
);
3080 // Search in DataTables 1.10 is string based. In 1.11 this
3081 // should be altered to also allow strict type checking.
3082 if ( cellData
=== null ) {
3086 if ( typeof cellData
!== 'string' && cellData
.toString
) {
3087 cellData
= cellData
.toString();
3094 // If it looks like there is an HTML entity in the string,
3095 // attempt to decode it so sorting works as expected. Note that
3096 // we could use a single line of jQuery to do this, but the DOM
3097 // method used here is much faster http://jsperf.com/html-decode
3098 if ( cellData
.indexOf
&& cellData
.indexOf('&') !== -1 ) {
3099 __filter_div
.innerHTML
= cellData
;
3100 cellData
= __filter_div_textContent
?
3101 __filter_div
.textContent
:
3102 __filter_div
.innerText
;
3105 if ( cellData
.replace
) {
3106 cellData
= cellData
.replace(/[\r\n]/g, '');
3109 filterData
.push( cellData
);
3112 row
._aFilterData
= filterData
;
3113 row
._sFilterRow
= filterData
.join(' ');
3114 wasInvalidated
= true;
3118 return wasInvalidated
;
3123 * Convert from the internal Hungarian notation to camelCase for external
3125 * @param {object} obj Object to convert
3126 * @returns {object} Inverted object
3127 * @memberof DataTable#oApi
3129 function _fnSearchToCamel ( obj
)
3132 search
: obj
.sSearch
,
3135 caseInsensitive
: obj
.bCaseInsensitive
3142 * Convert from camelCase notation to the internal Hungarian. We could use the
3143 * Hungarian convert function here, but this is cleaner
3144 * @param {object} obj Object to convert
3145 * @returns {object} Inverted object
3146 * @memberof DataTable#oApi
3148 function _fnSearchToHung ( obj
)
3151 sSearch
: obj
.search
,
3154 bCaseInsensitive
: obj
.caseInsensitive
3159 * Generate the node required for the info display
3160 * @param {object} oSettings dataTables settings object
3161 * @returns {node} Information element
3162 * @memberof DataTable#oApi
3164 function _fnFeatureHtmlInfo ( settings
)
3167 tid
= settings
.sTableId
,
3168 nodes
= settings
.aanFeatures
.i
,
3170 'class': settings
.oClasses
.sInfo
,
3171 'id': ! nodes
? tid
+'_info' : null
3175 // Update display on each draw
3176 settings
.aoDrawCallback
.push( {
3177 "fn": _fnUpdateInfo
,
3178 "sName": "information"
3182 .attr( 'role', 'status' )
3183 .attr( 'aria-live', 'polite' );
3185 // Table is described by our info div
3186 $(settings
.nTable
).attr( 'aria-describedby', tid
+'_info' );
3194 * Update the information elements in the display
3195 * @param {object} settings dataTables settings object
3196 * @memberof DataTable#oApi
3198 function _fnUpdateInfo ( settings
)
3200 /* Show information about the table */
3201 var nodes
= settings
.aanFeatures
.i
;
3202 if ( nodes
.length
=== 0 ) {
3207 lang
= settings
.oLanguage
,
3208 start
= settings
._iDisplayStart
+1,
3209 end
= settings
.fnDisplayEnd(),
3210 max
= settings
.fnRecordsTotal(),
3211 total
= settings
.fnRecordsDisplay(),
3216 if ( total
!== max
) {
3217 /* Record set after filtering */
3218 out
+= ' ' + lang
.sInfoFiltered
;
3221 // Convert the macros
3222 out
+= lang
.sInfoPostFix
;
3223 out
= _fnInfoMacros( settings
, out
);
3225 var callback
= lang
.fnInfoCallback
;
3226 if ( callback
!== null ) {
3227 out
= callback
.call( settings
.oInstance
,
3228 settings
, start
, end
, max
, total
, out
3232 $(nodes
).html( out
);
3236 function _fnInfoMacros ( settings
, str
)
3238 // When infinite scrolling, we are always starting at 1. _iDisplayStart is used only
3241 formatter
= settings
.fnFormatNumber
,
3242 start
= settings
._iDisplayStart
+1,
3243 len
= settings
._iDisplayLength
,
3244 vis
= settings
.fnRecordsDisplay(),
3248 replace(/_START_/g, formatter
.call( settings
, start
) ).
3249 replace(/_END_/g, formatter
.call( settings
, settings
.fnDisplayEnd() ) ).
3250 replace(/_MAX_/g, formatter
.call( settings
, settings
.fnRecordsTotal() ) ).
3251 replace(/_TOTAL_/g, formatter
.call( settings
, vis
) ).
3252 replace(/_PAGE_/g, formatter
.call( settings
, all
? 1 : Math
.ceil( start
/ len
) ) ).
3253 replace(/_PAGES_/g, formatter
.call( settings
, all
? 1 : Math
.ceil( vis
/ len
) ) );
3259 * Draw the table for the first time, adding all required features
3260 * @param {object} settings dataTables settings object
3261 * @memberof DataTable#oApi
3263 function _fnInitialise ( settings
)
3265 var i
, iLen
, iAjaxStart
=settings
.iInitDisplayStart
;
3266 var columns
= settings
.aoColumns
, column
;
3267 var features
= settings
.oFeatures
;
3269 /* Ensure that the table data is fully initialised */
3270 if ( ! settings
.bInitialised
) {
3271 setTimeout( function(){ _fnInitialise( settings
); }, 200 );
3275 /* Show the display HTML options */
3276 _fnAddOptionsHtml( settings
);
3278 /* Build and draw the header / footer for the table */
3279 _fnBuildHead( settings
);
3280 _fnDrawHead( settings
, settings
.aoHeader
);
3281 _fnDrawHead( settings
, settings
.aoFooter
);
3283 /* Okay to show that something is going on now */
3284 _fnProcessingDisplay( settings
, true );
3286 /* Calculate sizes for columns */
3287 if ( features
.bAutoWidth
) {
3288 _fnCalculateColumnWidths( settings
);
3291 for ( i
=0, iLen
=columns
.length
; i
<iLen
; i
++ ) {
3292 column
= columns
[i
];
3294 if ( column
.sWidth
) {
3295 column
.nTh
.style
.width
= _fnStringToCss( column
.sWidth
);
3299 // If there is default sorting required - let's do it. The sort function
3300 // will do the drawing for us. Otherwise we draw the table regardless of the
3301 // Ajax source - this allows the table to look initialised for Ajax sourcing
3302 // data (show 'loading' message possibly)
3303 _fnReDraw( settings
);
3305 // Server-side processing init complete is done by _fnAjaxUpdateDraw
3306 var dataSrc
= _fnDataSource( settings
);
3307 if ( dataSrc
!= 'ssp' ) {
3308 // if there is an ajax source load the data
3309 if ( dataSrc
== 'ajax' ) {
3310 _fnBuildAjax( settings
, [], function(json
) {
3311 var aData
= _fnAjaxDataSrc( settings
, json
);
3313 // Got the data - add it to the table
3314 for ( i
=0 ; i
<aData
.length
; i
++ ) {
3315 _fnAddData( settings
, aData
[i
] );
3318 // Reset the init display for cookie saving. We've already done
3319 // a filter, and therefore cleared it before. So we need to make
3320 // it appear 'fresh'
3321 settings
.iInitDisplayStart
= iAjaxStart
;
3323 _fnReDraw( settings
);
3325 _fnProcessingDisplay( settings
, false );
3326 _fnInitComplete( settings
, json
);
3330 _fnProcessingDisplay( settings
, false );
3331 _fnInitComplete( settings
);
3338 * Draw the table for the first time, adding all required features
3339 * @param {object} oSettings dataTables settings object
3340 * @param {object} [json] JSON from the server that completed the table, if using Ajax source
3341 * with client-side processing (optional)
3342 * @memberof DataTable#oApi
3344 function _fnInitComplete ( settings
, json
)
3346 settings
._bInitComplete
= true;
3348 // On an Ajax load we now have data and therefore want to apply the column
3351 _fnAdjustColumnSizing( settings
);
3354 _fnCallbackFire( settings
, 'aoInitComplete', 'init', [settings
, json
] );
3358 function _fnLengthChange ( settings
, val
)
3360 var len
= parseInt( val
, 10 );
3361 settings
._iDisplayLength
= len
;
3363 _fnLengthOverflow( settings
);
3365 // Fire length change event
3366 _fnCallbackFire( settings
, null, 'length', [settings
, len
] );
3371 * Generate the node required for user display length changing
3372 * @param {object} settings dataTables settings object
3373 * @returns {node} Display length feature node
3374 * @memberof DataTable#oApi
3376 function _fnFeatureHtmlLength ( settings
)
3379 classes
= settings
.oClasses
,
3380 tableId
= settings
.sTableId
,
3381 menu
= settings
.aLengthMenu
,
3382 d2
= $.isArray( menu
[0] ),
3383 lengths
= d2
? menu
[0] : menu
,
3384 language
= d2
? menu
[1] : menu
;
3386 var select
= $('<select/>', {
3387 'name': tableId
+'_length',
3388 'aria-controls': tableId
,
3389 'class': classes
.sLengthSelect
3392 for ( var i
=0, ien
=lengths
.length
; i
<ien
; i
++ ) {
3393 select
[0][ i
] = new Option( language
[i
], lengths
[i
] );
3396 var div
= $('<div><label/></div>').addClass( classes
.sLength
);
3397 if ( ! settings
.aanFeatures
.l
) {
3398 div
[0].id
= tableId
+'_length';
3401 div
.children().append(
3402 settings
.oLanguage
.sLengthMenu
.replace( '_MENU_', select
[0].outerHTML
)
3405 // Can't use `select` variable as user might provide their own and the
3406 // reference is broken by the use of outerHTML
3408 .val( settings
._iDisplayLength
)
3409 .bind( 'change.DT', function(e
) {
3410 _fnLengthChange( settings
, $(this).val() );
3411 _fnDraw( settings
);
3414 // Update node value whenever anything changes the table's length
3415 $(settings
.nTable
).bind( 'length.dt.DT', function (e
, s
, len
) {
3416 if ( settings
=== s
) {
3417 $('select', div
).val( len
);
3426 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3427 * Note that most of the paging logic is done in
3428 * DataTable.ext.pager
3432 * Generate the node required for default pagination
3433 * @param {object} oSettings dataTables settings object
3434 * @returns {node} Pagination feature node
3435 * @memberof DataTable#oApi
3437 function _fnFeatureHtmlPaginate ( settings
)
3440 type
= settings
.sPaginationType
,
3441 plugin
= DataTable
.ext
.pager
[ type
],
3442 modern
= typeof plugin
=== 'function',
3443 redraw = function( settings
) {
3444 _fnDraw( settings
);
3446 node
= $('<div/>').addClass( settings
.oClasses
.sPaging
+ type
)[0],
3447 features
= settings
.aanFeatures
;
3450 plugin
.fnInit( settings
, node
, redraw
);
3453 /* Add a draw callback for the pagination on first instance, to update the paging display */
3456 node
.id
= settings
.sTableId
+'_paginate';
3458 settings
.aoDrawCallback
.push( {
3459 "fn": function( settings
) {
3462 start
= settings
._iDisplayStart
,
3463 len
= settings
._iDisplayLength
,
3464 visRecords
= settings
.fnRecordsDisplay(),
3466 page
= all
? 0 : Math
.ceil( start
/ len
),
3467 pages
= all
? 1 : Math
.ceil( visRecords
/ len
),
3468 buttons
= plugin(page
, pages
),
3471 for ( i
=0, ien
=features
.p
.length
; i
<ien
; i
++ ) {
3472 _fnRenderer( settings
, 'pageButton' )(
3473 settings
, features
.p
[i
], i
, buttons
, page
, pages
3478 plugin
.fnUpdate( settings
, redraw
);
3481 "sName": "pagination"
3490 * Alter the display settings to change the page
3491 * @param {object} settings DataTables settings object
3492 * @param {string|int} action Paging action to take: "first", "previous",
3493 * "next" or "last" or page number to jump to (integer)
3494 * @param [bool] redraw Automatically draw the update or not
3495 * @returns {bool} true page has changed, false - no change
3496 * @memberof DataTable#oApi
3498 function _fnPageChange ( settings
, action
, redraw
)
3501 start
= settings
._iDisplayStart
,
3502 len
= settings
._iDisplayLength
,
3503 records
= settings
.fnRecordsDisplay();
3505 if ( records
=== 0 || len
=== -1 )
3509 else if ( typeof action
=== "number" )
3511 start
= action
* len
;
3513 if ( start
> records
)
3518 else if ( action
== "first" )
3522 else if ( action
== "previous" )
3533 else if ( action
== "next" )
3535 if ( start
+ len
< records
)
3540 else if ( action
== "last" )
3542 start
= Math
.floor( (records
-1) / len
) * len
;
3546 _fnLog( settings
, 0, "Unknown paging action: "+action
, 5 );
3549 var changed
= settings
._iDisplayStart
!== start
;
3550 settings
._iDisplayStart
= start
;
3553 _fnCallbackFire( settings
, null, 'page', [settings
] );
3556 _fnDraw( settings
);
3566 * Generate the node required for the processing node
3567 * @param {object} settings dataTables settings object
3568 * @returns {node} Processing element
3569 * @memberof DataTable#oApi
3571 function _fnFeatureHtmlProcessing ( settings
)
3573 return $('<div/>', {
3574 'id': ! settings
.aanFeatures
.r
? settings
.sTableId
+'_processing' : null,
3575 'class': settings
.oClasses
.sProcessing
3577 .html( settings
.oLanguage
.sProcessing
)
3578 .insertBefore( settings
.nTable
)[0];
3583 * Display or hide the processing indicator
3584 * @param {object} settings dataTables settings object
3585 * @param {bool} show Show the processing indicator (true) or not (false)
3586 * @memberof DataTable#oApi
3588 function _fnProcessingDisplay ( settings
, show
)
3590 if ( settings
.oFeatures
.bProcessing
) {
3591 $(settings
.aanFeatures
.r
).css( 'display', show
? 'block' : 'none' );
3594 _fnCallbackFire( settings
, null, 'processing', [settings
, show
] );
3598 * Add any control elements for the table - specifically scrolling
3599 * @param {object} settings dataTables settings object
3600 * @returns {node} Node to add to the DOM
3601 * @memberof DataTable#oApi
3603 function _fnFeatureHtmlTable ( settings
)
3605 var table
= $(settings
.nTable
);
3607 // Add the ARIA grid role to the table
3608 table
.attr( 'role', 'grid' );
3610 // Scrolling from here on in
3611 var scroll
= settings
.oScroll
;
3613 if ( scroll
.sX
=== '' && scroll
.sY
=== '' ) {
3614 return settings
.nTable
;
3617 var scrollX
= scroll
.sX
;
3618 var scrollY
= scroll
.sY
;
3619 var classes
= settings
.oClasses
;
3620 var caption
= table
.children('caption');
3621 var captionSide
= caption
.length
? caption
[0]._captionSide
: null;
3622 var headerClone
= $( table
[0].cloneNode(false) );
3623 var footerClone
= $( table
[0].cloneNode(false) );
3624 var footer
= table
.children('tfoot');
3625 var _div
= '<div/>';
3626 var size = function ( s
) {
3627 return !s
? null : _fnStringToCss( s
);
3630 // This is fairly messy, but with x scrolling enabled, if the table has a
3631 // width attribute, regardless of any width applied using the column width
3632 // options, the browser will shrink or grow the table as needed to fit into
3633 // that 100%. That would make the width options useless. So we remove it.
3634 // This is okay, under the assumption that width:100% is applied to the
3635 // table in CSS (it is in the default stylesheet) which will set the table
3636 // width as appropriate (the attribute and css behave differently...)
3637 if ( scroll
.sX
&& table
.attr('width') === '100%' ) {
3638 table
.removeAttr('width');
3641 if ( ! footer
.length
) {
3646 * The HTML structure that we want to generate in this function is:
3649 * div - scroll head inner
3650 * table - scroll head table
3653 * table - table (master table)
3654 * thead - thead clone for sizing
3657 * div - scroll foot inner
3658 * table - scroll foot table
3661 var scroller
= $( _div
, { 'class': classes
.sScrollWrapper
} )
3663 $(_div
, { 'class': classes
.sScrollHead
} )
3666 position
: 'relative',
3668 width
: scrollX
? size(scrollX
) : '100%'
3671 $(_div
, { 'class': classes
.sScrollHeadInner
} )
3673 'box-sizing': 'content-box',
3674 width
: scroll
.sXInner
|| '100%'
3679 .css( 'margin-left', 0 )
3680 .append( captionSide
=== 'top' ? caption
: null )
3682 table
.children('thead')
3688 $(_div
, { 'class': classes
.sScrollBody
} )
3691 height
: size( scrollY
),
3692 width
: size( scrollX
)
3699 $(_div
, { 'class': classes
.sScrollFoot
} )
3703 width
: scrollX
? size(scrollX
) : '100%'
3706 $(_div
, { 'class': classes
.sScrollFootInner
} )
3710 .css( 'margin-left', 0 )
3711 .append( captionSide
=== 'bottom' ? caption
: null )
3713 table
.children('tfoot')
3720 var children
= scroller
.children();
3721 var scrollHead
= children
[0];
3722 var scrollBody
= children
[1];
3723 var scrollFoot
= footer
? children
[2] : null;
3725 // When the body is scrolled, then we also want to scroll the headers
3727 $(scrollBody
).on( 'scroll.DT', function (e
) {
3728 var scrollLeft
= this.scrollLeft
;
3730 scrollHead
.scrollLeft
= scrollLeft
;
3733 scrollFoot
.scrollLeft
= scrollLeft
;
3738 settings
.nScrollHead
= scrollHead
;
3739 settings
.nScrollBody
= scrollBody
;
3740 settings
.nScrollFoot
= scrollFoot
;
3742 // On redraw - align columns
3743 settings
.aoDrawCallback
.push( {
3744 "fn": _fnScrollDraw
,
3745 "sName": "scrolling"
3754 * Update the header, footer and body tables for resizing - i.e. column
3757 * Welcome to the most horrible function DataTables. The process that this
3758 * function follows is basically:
3759 * 1. Re-create the table inside the scrolling div
3760 * 2. Take live measurements from the DOM
3761 * 3. Apply the measurements to align the columns
3764 * @param {object} settings dataTables settings object
3765 * @memberof DataTable#oApi
3767 function _fnScrollDraw ( settings
)
3769 // Given that this is such a monster function, a lot of variables are use
3770 // to try and keep the minimised size as small as possible
3772 scroll
= settings
.oScroll
,
3773 scrollX
= scroll
.sX
,
3774 scrollXInner
= scroll
.sXInner
,
3775 scrollY
= scroll
.sY
,
3776 barWidth
= scroll
.iBarWidth
,
3777 divHeader
= $(settings
.nScrollHead
),
3778 divHeaderStyle
= divHeader
[0].style
,
3779 divHeaderInner
= divHeader
.children('div'),
3780 divHeaderInnerStyle
= divHeaderInner
[0].style
,
3781 divHeaderTable
= divHeaderInner
.children('table'),
3782 divBodyEl
= settings
.nScrollBody
,
3783 divBody
= $(divBodyEl
),
3784 divBodyStyle
= divBodyEl
.style
,
3785 divFooter
= $(settings
.nScrollFoot
),
3786 divFooterInner
= divFooter
.children('div'),
3787 divFooterTable
= divFooterInner
.children('table'),
3788 header
= $(settings
.nTHead
),
3789 table
= $(settings
.nTable
),
3791 tableStyle
= tableEl
.style
,
3792 footer
= settings
.nTFoot
? $(settings
.nTFoot
) : null,
3793 browser
= settings
.oBrowser
,
3794 ie67
= browser
.bScrollOversize
,
3795 headerTrgEls
, footerTrgEls
,
3796 headerSrcEls
, footerSrcEls
,
3797 headerCopy
, footerCopy
,
3798 headerWidths
=[], footerWidths
=[],
3800 idx
, correction
, sanityWidth
,
3801 zeroOut = function(nSizer
) {
3802 var style
= nSizer
.style
;
3803 style
.paddingTop
= "0";
3804 style
.paddingBottom
= "0";
3805 style
.borderTopWidth
= "0";
3806 style
.borderBottomWidth
= "0";
3811 * 1. Re-create the table inside the scrolling div
3814 // Remove the old minimised thead and tfoot elements in the inner table
3815 table
.children('thead, tfoot').remove();
3817 // Clone the current header and footer elements and then place it into the inner table
3818 headerCopy
= header
.clone().prependTo( table
);
3819 headerTrgEls
= header
.find('tr'); // original header is in its own table
3820 headerSrcEls
= headerCopy
.find('tr');
3821 headerCopy
.find('th, td').removeAttr('tabindex');
3824 footerCopy
= footer
.clone().prependTo( table
);
3825 footerTrgEls
= footer
.find('tr'); // the original tfoot is in its own table and must be sized
3826 footerSrcEls
= footerCopy
.find('tr');
3831 * 2. Take live measurements from the DOM - do not alter the DOM itself!
3834 // Remove old sizing and apply the calculated column widths
3835 // Get the unique column headers in the newly created (cloned) header. We want to apply the
3836 // calculated sizes to this header
3839 divBodyStyle
.width
= '100%';
3840 divHeader
[0].style
.width
= '100%';
3843 $.each( _fnGetUniqueThs( settings
, headerCopy
), function ( i
, el
) {
3844 idx
= _fnVisibleToColumnIndex( settings
, i
);
3845 el
.style
.width
= settings
.aoColumns
[idx
].sWidth
;
3849 _fnApplyToChildren( function(n
) {
3854 // If scroll collapse is enabled, when we put the headers back into the body for sizing, we
3855 // will end up forcing the scrollbar to appear, making our measurements wrong for when we
3856 // then hide it (end of this function), so add the header height to the body scroller.
3857 if ( scroll
.bCollapse
&& scrollY
!== "" ) {
3858 divBodyStyle
.height
= (divBody
[0].offsetHeight
+ header
[0].offsetHeight
)+"px";
3861 // Size the table as a whole
3862 sanityWidth
= table
.outerWidth();
3863 if ( scrollX
=== "" ) {
3865 tableStyle
.width
= "100%";
3867 // IE7 will make the width of the table when 100% include the scrollbar
3868 // - which is shouldn't. When there is a scrollbar we need to take this
3870 if ( ie67
&& (table
.find('tbody').height() > divBodyEl
.offsetHeight
||
3871 divBody
.css('overflow-y') == "scroll")
3873 tableStyle
.width
= _fnStringToCss( table
.outerWidth() - barWidth
);
3879 if ( scrollXInner
!== "" ) {
3880 // x scroll inner has been given - use it
3881 tableStyle
.width
= _fnStringToCss(scrollXInner
);
3883 else if ( sanityWidth
== divBody
.width() && divBody
.height() < table
.height() ) {
3884 // There is y-scrolling - try to take account of the y scroll bar
3885 tableStyle
.width
= _fnStringToCss( sanityWidth
-barWidth
);
3886 if ( table
.outerWidth() > sanityWidth
-barWidth
) {
3887 // Not possible to take account of it
3888 tableStyle
.width
= _fnStringToCss( sanityWidth
);
3892 // When all else fails
3893 tableStyle
.width
= _fnStringToCss( sanityWidth
);
3897 // Recalculate the sanity width - now that we've applied the required width,
3898 // before it was a temporary variable. This is required because the column
3899 // width calculation is done before this table DOM is created.
3900 sanityWidth
= table
.outerWidth();
3902 // Hidden header should have zero height, so remove padding and borders. Then
3903 // set the width based on the real headers
3905 // Apply all styles in one pass
3906 _fnApplyToChildren( zeroOut
, headerSrcEls
);
3908 // Read all widths in next pass
3909 _fnApplyToChildren( function(nSizer
) {
3910 headerContent
.push( nSizer
.innerHTML
);
3911 headerWidths
.push( _fnStringToCss( $(nSizer
).css('width') ) );
3914 // Apply all widths in final pass
3915 _fnApplyToChildren( function(nToSize
, i
) {
3916 nToSize
.style
.width
= headerWidths
[i
];
3919 $(headerSrcEls
).height(0);
3921 /* Same again with the footer if we have one */
3924 _fnApplyToChildren( zeroOut
, footerSrcEls
);
3926 _fnApplyToChildren( function(nSizer
) {
3927 footerWidths
.push( _fnStringToCss( $(nSizer
).css('width') ) );
3930 _fnApplyToChildren( function(nToSize
, i
) {
3931 nToSize
.style
.width
= footerWidths
[i
];
3934 $(footerSrcEls
).height(0);
3939 * 3. Apply the measurements
3942 // "Hide" the header and footer that we used for the sizing. We need to keep
3943 // the content of the cell so that the width applied to the header and body
3944 // both match, but we want to hide it completely. We want to also fix their
3945 // width to what they currently are
3946 _fnApplyToChildren( function(nSizer
, i
) {
3947 nSizer
.innerHTML
= '<div class="dataTables_sizing" style="height:0;overflow:hidden;">'+headerContent
[i
]+'</div>';
3948 nSizer
.style
.width
= headerWidths
[i
];
3953 _fnApplyToChildren( function(nSizer
, i
) {
3954 nSizer
.innerHTML
= "";
3955 nSizer
.style
.width
= footerWidths
[i
];
3959 // Sanity check that the table is of a sensible width. If not then we are going to get
3960 // misalignment - try to prevent this by not allowing the table to shrink below its min width
3961 if ( table
.outerWidth() < sanityWidth
)
3963 // The min width depends upon if we have a vertical scrollbar visible or not */
3964 correction
= ((divBodyEl
.scrollHeight
> divBodyEl
.offsetHeight
||
3965 divBody
.css('overflow-y') == "scroll")) ?
3966 sanityWidth
+barWidth
:
3969 // IE6/7 are a law unto themselves...
3970 if ( ie67
&& (divBodyEl
.scrollHeight
>
3971 divBodyEl
.offsetHeight
|| divBody
.css('overflow-y') == "scroll")
3973 tableStyle
.width
= _fnStringToCss( correction
-barWidth
);
3976 // And give the user a warning that we've stopped the table getting too small
3977 if ( scrollX
=== "" || scrollXInner
!== "" ) {
3978 _fnLog( settings
, 1, 'Possible column misalignment', 6 );
3983 correction
= '100%';
3986 // Apply to the container elements
3987 divBodyStyle
.width
= _fnStringToCss( correction
);
3988 divHeaderStyle
.width
= _fnStringToCss( correction
);
3991 settings
.nScrollFoot
.style
.width
= _fnStringToCss( correction
);
3999 /* IE7< puts a vertical scrollbar in place (when it shouldn't be) due to subtracting
4000 * the scrollbar height from the visible display, rather than adding it on. We need to
4001 * set the height in order to sort this. Don't want to do it in any other browsers.
4004 divBodyStyle
.height
= _fnStringToCss( tableEl
.offsetHeight
+barWidth
);
4008 if ( scrollY
&& scroll
.bCollapse
) {
4009 divBodyStyle
.height
= _fnStringToCss( scrollY
);
4011 var iExtra
= (scrollX
&& tableEl
.offsetWidth
> divBodyEl
.offsetWidth
) ?
4015 if ( tableEl
.offsetHeight
< divBodyEl
.offsetHeight
) {
4016 divBodyStyle
.height
= _fnStringToCss( tableEl
.offsetHeight
+iExtra
);
4020 /* Finally set the width's of the header and footer tables */
4021 var iOuterWidth
= table
.outerWidth();
4022 divHeaderTable
[0].style
.width
= _fnStringToCss( iOuterWidth
);
4023 divHeaderInnerStyle
.width
= _fnStringToCss( iOuterWidth
);
4025 // Figure out if there are scrollbar present - if so then we need a the header and footer to
4026 // provide a bit more space to allow "overflow" scrolling (i.e. past the scrollbar)
4027 var bScrolling
= table
.height() > divBodyEl
.clientHeight
|| divBody
.css('overflow-y') == "scroll";
4028 var padding
= 'padding' + (browser
.bScrollbarLeft
? 'Left' : 'Right' );
4029 divHeaderInnerStyle
[ padding
] = bScrolling
? barWidth
+"px" : "0px";
4032 divFooterTable
[0].style
.width
= _fnStringToCss( iOuterWidth
);
4033 divFooterInner
[0].style
.width
= _fnStringToCss( iOuterWidth
);
4034 divFooterInner
[0].style
[padding
] = bScrolling
? barWidth
+"px" : "0px";
4037 /* Adjust the position of the header in case we loose the y-scrollbar */
4040 // If sorting or filtering has occurred, jump the scrolling back to the top
4041 // only if we aren't holding the position
4042 if ( (settings
.bSorted
|| settings
.bFiltered
) && ! settings
._drawHold
) {
4043 divBodyEl
.scrollTop
= 0;
4050 * Apply a given function to the display child nodes of an element array (typically
4051 * TD children of TR rows
4052 * @param {function} fn Method to apply to the objects
4053 * @param array {nodes} an1 List of elements to look through for display children
4054 * @param array {nodes} an2 Another list (identical structure to the first) - optional
4055 * @memberof DataTable#oApi
4057 function _fnApplyToChildren( fn
, an1
, an2
)
4059 var index
=0, i
=0, iLen
=an1
.length
;
4062 while ( i
< iLen
) {
4063 nNode1
= an1
[i
].firstChild
;
4064 nNode2
= an2
? an2
[i
].firstChild
: null;
4067 if ( nNode1
.nodeType
=== 1 ) {
4069 fn( nNode1
, nNode2
, index
);
4072 fn( nNode1
, index
);
4078 nNode1
= nNode1
.nextSibling
;
4079 nNode2
= an2
? nNode2
.nextSibling
: null;
4088 var __re_html_remove
= /<.*?>/g;
4092 * Calculate the width of columns for the table
4093 * @param {object} oSettings dataTables settings object
4094 * @memberof DataTable#oApi
4096 function _fnCalculateColumnWidths ( oSettings
)
4099 table
= oSettings
.nTable
,
4100 columns
= oSettings
.aoColumns
,
4101 scroll
= oSettings
.oScroll
,
4102 scrollY
= scroll
.sY
,
4103 scrollX
= scroll
.sX
,
4104 scrollXInner
= scroll
.sXInner
,
4105 columnCount
= columns
.length
,
4106 visibleColumns
= _fnGetColumns( oSettings
, 'bVisible' ),
4107 headerCells
= $('th', oSettings
.nTHead
),
4108 tableWidthAttr
= table
.getAttribute('width'), // from DOM element
4109 tableContainer
= table
.parentNode
,
4111 i
, column
, columnIdx
, width
, outerWidth
;
4113 var styleWidth
= table
.style
.width
;
4114 if ( styleWidth
&& styleWidth
.indexOf('%') !== -1 ) {
4115 tableWidthAttr
= styleWidth
;
4118 /* Convert any user input sizes into pixel sizes */
4119 for ( i
=0 ; i
<visibleColumns
.length
; i
++ ) {
4120 column
= columns
[ visibleColumns
[i
] ];
4122 if ( column
.sWidth
!== null ) {
4123 column
.sWidth
= _fnConvertToWidth( column
.sWidthOrig
, tableContainer
);
4129 /* If the number of columns in the DOM equals the number that we have to
4130 * process in DataTables, then we can use the offsets that are created by
4131 * the web- browser. No custom sizes can be set in order for this to happen,
4132 * nor scrolling used
4134 if ( ! userInputs
&& ! scrollX
&& ! scrollY
&&
4135 columnCount
== _fnVisbleColumns( oSettings
) &&
4136 columnCount
== headerCells
.length
4138 for ( i
=0 ; i
<columnCount
; i
++ ) {
4139 columns
[i
].sWidth
= _fnStringToCss( headerCells
.eq(i
).width() );
4144 // Otherwise construct a single row, worst case, table with the widest
4145 // node in the data, assign any user defined widths, then insert it into
4146 // the DOM and allow the browser to do all the hard work of calculating
4148 var tmpTable
= $(table
).clone() // don't use cloneNode - IE8 will remove events on the main table
4149 .css( 'visibility', 'hidden' )
4150 .removeAttr( 'id' );
4152 // Clean up the table body
4153 tmpTable
.find('tbody tr').remove();
4154 var tr
= $('<tr/>').appendTo( tmpTable
.find('tbody') );
4156 // Remove any assigned widths from the footer (from scrolling)
4157 tmpTable
.find('tfoot th, tfoot td').css('width', '');
4159 // Apply custom sizing to the cloned header
4160 headerCells
= _fnGetUniqueThs( oSettings
, tmpTable
.find('thead')[0] );
4162 for ( i
=0 ; i
<visibleColumns
.length
; i
++ ) {
4163 column
= columns
[ visibleColumns
[i
] ];
4165 headerCells
[i
].style
.width
= column
.sWidthOrig
!== null && column
.sWidthOrig
!== '' ?
4166 _fnStringToCss( column
.sWidthOrig
) :
4170 // Find the widest cell for each column and put it into the table
4171 if ( oSettings
.aoData
.length
) {
4172 for ( i
=0 ; i
<visibleColumns
.length
; i
++ ) {
4173 columnIdx
= visibleColumns
[i
];
4174 column
= columns
[ columnIdx
];
4176 $( _fnGetWidestNode( oSettings
, columnIdx
) )
4178 .append( column
.sContentPadding
)
4183 // Table has been built, attach to the document so we can work with it
4184 tmpTable
.appendTo( tableContainer
);
4186 // When scrolling (X or Y) we want to set the width of the table as
4187 // appropriate. However, when not scrolling leave the table width as it
4188 // is. This results in slightly different, but I think correct behaviour
4189 if ( scrollX
&& scrollXInner
) {
4190 tmpTable
.width( scrollXInner
);
4192 else if ( scrollX
) {
4193 tmpTable
.css( 'width', 'auto' );
4195 if ( tmpTable
.width() < tableContainer
.offsetWidth
) {
4196 tmpTable
.width( tableContainer
.offsetWidth
);
4199 else if ( scrollY
) {
4200 tmpTable
.width( tableContainer
.offsetWidth
);
4202 else if ( tableWidthAttr
) {
4203 tmpTable
.width( tableWidthAttr
);
4206 // Take into account the y scrollbar
4207 _fnScrollingWidthAdjust( oSettings
, tmpTable
[0] );
4209 // Browsers need a bit of a hand when a width is assigned to any columns
4210 // when x-scrolling as they tend to collapse the table to the min-width,
4211 // even if we sent the column widths. So we need to keep track of what
4212 // the table width should be by summing the user given values, and the
4218 for ( i
=0 ; i
<visibleColumns
.length
; i
++ ) {
4219 column
= columns
[ visibleColumns
[i
] ];
4220 outerWidth
= $(headerCells
[i
]).outerWidth();
4222 total
+= column
.sWidthOrig
=== null ?
4224 parseInt( column
.sWidth
, 10 ) + outerWidth
- $(headerCells
[i
]).width();
4227 tmpTable
.width( _fnStringToCss( total
) );
4228 table
.style
.width
= _fnStringToCss( total
);
4231 // Get the width of each column in the constructed table
4232 for ( i
=0 ; i
<visibleColumns
.length
; i
++ ) {
4233 column
= columns
[ visibleColumns
[i
] ];
4234 width
= $(headerCells
[i
]).width();
4237 column
.sWidth
= _fnStringToCss( width
);
4241 table
.style
.width
= _fnStringToCss( tmpTable
.css('width') );
4243 // Finished with the table - ditch it
4247 // If there is a width attr, we want to attach an event listener which
4248 // allows the table sizing to automatically adjust when the window is
4249 // resized. Use the width attr rather than CSS, since we can't know if the
4250 // CSS is a relative value or absolute - DOM read is always px.
4251 if ( tableWidthAttr
) {
4252 table
.style
.width
= _fnStringToCss( tableWidthAttr
);
4255 if ( (tableWidthAttr
|| scrollX
) && ! oSettings
._reszEvt
) {
4256 var bindResize = function () {
4257 $(window
).bind('resize.DT-'+oSettings
.sInstance
, _fnThrottle( function () {
4258 _fnAdjustColumnSizing( oSettings
);
4262 // IE6/7 will crash if we bind a resize event handler on page load.
4263 // To be removed in 1.11 which drops IE6/7 support
4264 if ( oSettings
.oBrowser
.bScrollOversize
) {
4265 setTimeout( bindResize
, 1000 );
4271 oSettings
._reszEvt
= true;
4277 * Throttle the calls to a function. Arguments and context are maintained for
4278 * the throttled function
4279 * @param {function} fn Function to be called
4280 * @param {int} [freq=200] call frequency in mS
4281 * @returns {function} wrapped function
4282 * @memberof DataTable#oApi
4284 function _fnThrottle( fn
, freq
) {
4286 frequency
= freq
!== undefined ? freq
: 200,
4290 return function () {
4296 if ( last
&& now
< last
+ frequency
) {
4297 clearTimeout( timer
);
4299 timer
= setTimeout( function () {
4301 fn
.apply( that
, args
);
4306 fn
.apply( that
, args
);
4313 * Convert a CSS unit width to pixels (e.g. 2em)
4314 * @param {string} width width to be converted
4315 * @param {node} parent parent to get the with for (required for relative widths) - optional
4316 * @returns {int} width in pixels
4317 * @memberof DataTable#oApi
4319 function _fnConvertToWidth ( width
, parent
)
4326 .css( 'width', _fnStringToCss( width
) )
4327 .appendTo( parent
|| document
.body
);
4329 var val
= n
[0].offsetWidth
;
4337 * Adjust a table's width to take account of vertical scroll bar
4338 * @param {object} oSettings dataTables settings object
4339 * @param {node} n table node
4340 * @memberof DataTable#oApi
4343 function _fnScrollingWidthAdjust ( settings
, n
)
4345 var scroll
= settings
.oScroll
;
4347 if ( scroll
.sX
|| scroll
.sY
) {
4348 // When y-scrolling only, we want to remove the width of the scroll bar
4349 // so the table + scroll bar will fit into the area available, otherwise
4350 // we fix the table at its current size with no adjustment
4351 var correction
= ! scroll
.sX
? scroll
.iBarWidth
: 0;
4352 n
.style
.width
= _fnStringToCss( $(n
).outerWidth() - correction
);
4358 * Get the widest node
4359 * @param {object} settings dataTables settings object
4360 * @param {int} colIdx column of interest
4361 * @returns {node} widest table node
4362 * @memberof DataTable#oApi
4364 function _fnGetWidestNode( settings
, colIdx
)
4366 var idx
= _fnGetMaxLenString( settings
, colIdx
);
4371 var data
= settings
.aoData
[ idx
];
4372 return ! data
.nTr
? // Might not have been created when deferred rendering
4373 $('<td/>').html( _fnGetCellData( settings
, idx
, colIdx
, 'display' ) )[0] :
4374 data
.anCells
[ colIdx
];
4379 * Get the maximum strlen for each data column
4380 * @param {object} settings dataTables settings object
4381 * @param {int} colIdx column of interest
4382 * @returns {string} max string length for each column
4383 * @memberof DataTable#oApi
4385 function _fnGetMaxLenString( settings
, colIdx
)
4387 var s
, max
=-1, maxIdx
= -1;
4389 for ( var i
=0, ien
=settings
.aoData
.length
; i
<ien
; i
++ ) {
4390 s
= _fnGetCellData( settings
, i
, colIdx
, 'display' )+'';
4391 s
= s
.replace( __re_html_remove
, '' );
4393 if ( s
.length
> max
) {
4404 * Append a CSS unit (only if required) to a string
4405 * @param {string} value to css-ify
4406 * @returns {string} value with css unit
4407 * @memberof DataTable#oApi
4409 function _fnStringToCss( s
)
4415 if ( typeof s
== 'number' ) {
4421 // Check it has a unit character already
4422 return s
.match(/\d$/) ?
4429 * Get the width of a scroll bar in this browser being used
4430 * @returns {int} width in pixels
4431 * @memberof DataTable#oApi
4433 function _fnScrollBarWidth ()
4435 // On first run a static variable is set, since this is only needed once.
4436 // Subsequent runs will just use the previously calculated value
4437 var width
= DataTable
.__scrollbarWidth
;
4439 if ( width
=== undefined ) {
4440 var sizer
= $('<p/>').css( {
4441 position
: 'absolute',
4448 visibility
: 'hidden'
4452 width
= sizer
[0].offsetWidth
- sizer
[0].clientWidth
;
4453 DataTable
.__scrollbarWidth
= width
;
4463 function _fnSortFlatten ( settings
)
4469 aoColumns
= settings
.aoColumns
,
4470 aDataSort
, iCol
, sType
, srcCol
,
4471 fixed
= settings
.aaSortingFixed
,
4472 fixedObj
= $.isPlainObject( fixed
),
4474 add = function ( a
) {
4475 if ( a
.length
&& ! $.isArray( a
[0] ) ) {
4477 nestedSort
.push( a
);
4481 nestedSort
.push
.apply( nestedSort
, a
);
4485 // Build the sort array, with pre-fix and post-fix options if they have been
4487 if ( $.isArray( fixed
) ) {
4491 if ( fixedObj
&& fixed
.pre
) {
4495 add( settings
.aaSorting
);
4497 if (fixedObj
&& fixed
.post
) {
4501 for ( i
=0 ; i
<nestedSort
.length
; i
++ )
4503 srcCol
= nestedSort
[i
][0];
4504 aDataSort
= aoColumns
[ srcCol
].aDataSort
;
4506 for ( k
=0, kLen
=aDataSort
.length
; k
<kLen
; k
++ )
4508 iCol
= aDataSort
[k
];
4509 sType
= aoColumns
[ iCol
].sType
|| 'string';
4511 if ( nestedSort
[i
]._idx
=== undefined ) {
4512 nestedSort
[i
]._idx
= $.inArray( nestedSort
[i
][1], aoColumns
[iCol
].asSorting
);
4518 dir
: nestedSort
[i
][1],
4519 index
: nestedSort
[i
]._idx
,
4521 formatter
: DataTable
.ext
.type
.order
[ sType
+"-pre" ]
4530 * Change the order of the table
4531 * @param {object} oSettings dataTables settings object
4532 * @memberof DataTable#oApi
4533 * @todo This really needs split up!
4535 function _fnSort ( oSettings
)
4538 i
, ien
, iLen
, j
, jLen
, k
, kLen
,
4541 oExtSort
= DataTable
.ext
.type
.order
,
4542 aoData
= oSettings
.aoData
,
4543 aoColumns
= oSettings
.aoColumns
,
4544 aDataSort
, data
, iCol
, sType
, oSort
,
4547 displayMaster
= oSettings
.aiDisplayMaster
,
4550 // Resolve any column types that are unknown due to addition or invalidation
4551 // @todo Can this be moved into a 'data-ready' handler which is called when
4552 // data is going to be used in the table?
4553 _fnColumnTypes( oSettings
);
4555 aSort
= _fnSortFlatten( oSettings
);
4557 for ( i
=0, ien
=aSort
.length
; i
<ien
; i
++ ) {
4560 // Track if we can use the fast sort algorithm
4561 if ( sortCol
.formatter
) {
4565 // Load the data needed for the sort, for each cell
4566 _fnSortData( oSettings
, sortCol
.col
);
4569 /* No sorting required if server-side or no sorting array */
4570 if ( _fnDataSource( oSettings
) != 'ssp' && aSort
.length
!== 0 )
4572 // Create a value - key array of the current row positions such that we can use their
4573 // current position during the sort, if values match, in order to perform stable sorting
4574 for ( i
=0, iLen
=displayMaster
.length
; i
<iLen
; i
++ ) {
4575 aiOrig
[ displayMaster
[i
] ] = i
;
4578 /* Do the sort - here we want multi-column sorting based on a given data source (column)
4579 * and sorting function (from oSort) in a certain direction. It's reasonably complex to
4580 * follow on it's own, but this is what we want (example two column sorting):
4581 * fnLocalSorting = function(a,b){
4583 * iTest = oSort['string-asc']('data11', 'data12');
4586 * iTest = oSort['numeric-desc']('data21', 'data22');
4589 * return oSort['numeric-asc']( aiOrig[a], aiOrig[b] );
4591 * Basically we have a test for each sorting column, if the data in that column is equal,
4592 * test the next column. If all columns match, then we use a numeric sort on the row
4593 * positions in the original data array to provide a stable sort.
4595 * Note - I know it seems excessive to have two sorting methods, but the first is around
4596 * 15% faster, so the second is only maintained for backwards compatibility with sorting
4597 * methods which do not have a pre-sort formatting function.
4599 if ( formatters
=== aSort
.length
) {
4600 // All sort types have formatting functions
4601 displayMaster
.sort( function ( a
, b
) {
4603 x
, y
, k
, test
, sort
,
4605 dataA
= aoData
[a
]._aSortData
,
4606 dataB
= aoData
[b
]._aSortData
;
4608 for ( k
=0 ; k
<len
; k
++ ) {
4611 x
= dataA
[ sort
.col
];
4612 y
= dataB
[ sort
.col
];
4614 test
= x
<y
? -1 : x
>y
? 1 : 0;
4616 return sort
.dir
=== 'asc' ? test
: -test
;
4622 return x
<y
? -1 : x
>y
? 1 : 0;
4626 // Depreciated - remove in 1.11 (providing a plug-in option)
4627 // Not all sort types have formatting methods, so we have to call their sorting
4629 displayMaster
.sort( function ( a
, b
) {
4631 x
, y
, k
, l
, test
, sort
, fn
,
4633 dataA
= aoData
[a
]._aSortData
,
4634 dataB
= aoData
[b
]._aSortData
;
4636 for ( k
=0 ; k
<len
; k
++ ) {
4639 x
= dataA
[ sort
.col
];
4640 y
= dataB
[ sort
.col
];
4642 fn
= oExtSort
[ sort
.type
+"-"+sort
.dir
] || oExtSort
[ "string-"+sort
.dir
];
4651 return x
<y
? -1 : x
>y
? 1 : 0;
4656 /* Tell the draw function that we have sorted the data */
4657 oSettings
.bSorted
= true;
4661 function _fnSortAria ( settings
)
4665 var columns
= settings
.aoColumns
;
4666 var aSort
= _fnSortFlatten( settings
);
4667 var oAria
= settings
.oLanguage
.oAria
;
4669 // ARIA attributes - need to loop all columns, to update all (removing old
4670 // attributes as needed)
4671 for ( var i
=0, iLen
=columns
.length
; i
<iLen
; i
++ )
4673 var col
= columns
[i
];
4674 var asSorting
= col
.asSorting
;
4675 var sTitle
= col
.sTitle
.replace( /<.*?>/g, "" );
4678 // IE7 is throwing an error when setting these properties with jQuery's
4679 // attr() and removeAttr() methods...
4680 th
.removeAttribute('aria-sort');
4682 /* In ARIA only the first sorting column can be marked as sorting - no multi-sort option */
4683 if ( col
.bSortable
) {
4684 if ( aSort
.length
> 0 && aSort
[0].col
== i
) {
4685 th
.setAttribute('aria-sort', aSort
[0].dir
=="asc" ? "ascending" : "descending" );
4686 nextSort
= asSorting
[ aSort
[0].index
+1 ] || asSorting
[0];
4689 nextSort
= asSorting
[0];
4692 label
= sTitle
+ ( nextSort
=== "asc" ?
4693 oAria
.sSortAscending
:
4694 oAria
.sSortDescending
4701 th
.setAttribute('aria-label', label
);
4707 * Function to run on user sort request
4708 * @param {object} settings dataTables settings object
4709 * @param {node} attachTo node to attach the handler to
4710 * @param {int} colIdx column sorting index
4711 * @param {boolean} [append=false] Append the requested sort to the existing
4712 * sort if true (i.e. multi-column sort)
4713 * @param {function} [callback] callback function
4714 * @memberof DataTable#oApi
4716 function _fnSortListener ( settings
, colIdx
, append
, callback
)
4718 var col
= settings
.aoColumns
[ colIdx
];
4719 var sorting
= settings
.aaSorting
;
4720 var asSorting
= col
.asSorting
;
4722 var next = function ( a
, overflow
) {
4724 if ( idx
=== undefined ) {
4725 idx
= $.inArray( a
[1], asSorting
);
4728 return idx
+1 < asSorting
.length
?
4735 // Convert to 2D array if needed
4736 if ( typeof sorting
[0] === 'number' ) {
4737 sorting
= settings
.aaSorting
= [ sorting
];
4740 // If appending the sort then we are multi-column sorting
4741 if ( append
&& settings
.oFeatures
.bSortMulti
) {
4742 // Are we already doing some kind of sort on this column?
4743 var sortIdx
= $.inArray( colIdx
, _pluck(sorting
, '0') );
4745 if ( sortIdx
!== -1 ) {
4746 // Yes, modify the sort
4747 nextSortIdx
= next( sorting
[sortIdx
], true );
4749 if ( nextSortIdx
=== null && sorting
.length
=== 1 ) {
4750 nextSortIdx
= 0; // can't remove sorting completely
4753 if ( nextSortIdx
=== null ) {
4754 sorting
.splice( sortIdx
, 1 );
4757 sorting
[sortIdx
][1] = asSorting
[ nextSortIdx
];
4758 sorting
[sortIdx
]._idx
= nextSortIdx
;
4762 // No sort on this column yet
4763 sorting
.push( [ colIdx
, asSorting
[0], 0 ] );
4764 sorting
[sorting
.length
-1]._idx
= 0;
4767 else if ( sorting
.length
&& sorting
[0][0] == colIdx
) {
4768 // Single column - already sorting on this column, modify the sort
4769 nextSortIdx
= next( sorting
[0] );
4772 sorting
[0][1] = asSorting
[ nextSortIdx
];
4773 sorting
[0]._idx
= nextSortIdx
;
4776 // Single column - sort only on this column
4778 sorting
.push( [ colIdx
, asSorting
[0] ] );
4779 sorting
[0]._idx
= 0;
4782 // Run the sort by calling a full redraw
4783 _fnReDraw( settings
);
4785 // callback used for async user interaction
4786 if ( typeof callback
== 'function' ) {
4787 callback( settings
);
4793 * Attach a sort handler (click) to a node
4794 * @param {object} settings dataTables settings object
4795 * @param {node} attachTo node to attach the handler to
4796 * @param {int} colIdx column sorting index
4797 * @param {function} [callback] callback function
4798 * @memberof DataTable#oApi
4800 function _fnSortAttachListener ( settings
, attachTo
, colIdx
, callback
)
4802 var col
= settings
.aoColumns
[ colIdx
];
4804 _fnBindAction( attachTo
, {}, function (e
) {
4805 /* If the column is not sortable - don't to anything */
4806 if ( col
.bSortable
=== false ) {
4810 // If processing is enabled use a timeout to allow the processing
4811 // display to be shown - otherwise to it synchronously
4812 if ( settings
.oFeatures
.bProcessing
) {
4813 _fnProcessingDisplay( settings
, true );
4815 setTimeout( function() {
4816 _fnSortListener( settings
, colIdx
, e
.shiftKey
, callback
);
4818 // In server-side processing, the draw callback will remove the
4819 // processing display
4820 if ( _fnDataSource( settings
) !== 'ssp' ) {
4821 _fnProcessingDisplay( settings
, false );
4826 _fnSortListener( settings
, colIdx
, e
.shiftKey
, callback
);
4833 * Set the sorting classes on table's body, Note: it is safe to call this function
4834 * when bSort and bSortClasses are false
4835 * @param {object} oSettings dataTables settings object
4836 * @memberof DataTable#oApi
4838 function _fnSortingClasses( settings
)
4840 var oldSort
= settings
.aLastSort
;
4841 var sortClass
= settings
.oClasses
.sSortColumn
;
4842 var sort
= _fnSortFlatten( settings
);
4843 var features
= settings
.oFeatures
;
4846 if ( features
.bSort
&& features
.bSortClasses
) {
4847 // Remove old sorting classes
4848 for ( i
=0, ien
=oldSort
.length
; i
<ien
; i
++ ) {
4849 colIdx
= oldSort
[i
].src
;
4851 // Remove column sorting
4852 $( _pluck( settings
.aoData
, 'anCells', colIdx
) )
4853 .removeClass( sortClass
+ (i
<2 ? i
+1 : 3) );
4856 // Add new column sorting
4857 for ( i
=0, ien
=sort
.length
; i
<ien
; i
++ ) {
4858 colIdx
= sort
[i
].src
;
4860 $( _pluck( settings
.aoData
, 'anCells', colIdx
) )
4861 .addClass( sortClass
+ (i
<2 ? i
+1 : 3) );
4865 settings
.aLastSort
= sort
;
4869 // Get the data to sort a column, be it from cache, fresh (populating the
4870 // cache), or from a sort formatter
4871 function _fnSortData( settings
, idx
)
4873 // Custom sorting function - provided by the sort data type
4874 var column
= settings
.aoColumns
[ idx
];
4875 var customSort
= DataTable
.ext
.order
[ column
.sSortDataType
];
4879 customData
= customSort
.call( settings
.oInstance
, settings
, idx
,
4880 _fnColumnIndexToVisible( settings
, idx
)
4884 // Use / populate cache
4886 var formatter
= DataTable
.ext
.type
.order
[ column
.sType
+"-pre" ];
4888 for ( var i
=0, ien
=settings
.aoData
.length
; i
<ien
; i
++ ) {
4889 row
= settings
.aoData
[i
];
4891 if ( ! row
._aSortData
) {
4892 row
._aSortData
= [];
4895 if ( ! row
._aSortData
[idx
] || customSort
) {
4896 cellData
= customSort
?
4897 customData
[i
] : // If there was a custom sort function, use data from there
4898 _fnGetCellData( settings
, i
, idx
, 'sort' );
4900 row
._aSortData
[ idx
] = formatter
?
4901 formatter( cellData
) :
4910 * Save the state of a table
4911 * @param {object} oSettings dataTables settings object
4912 * @memberof DataTable#oApi
4914 function _fnSaveState ( settings
)
4916 if ( !settings
.oFeatures
.bStateSave
|| settings
.bDestroying
)
4921 /* Store the interesting variables */
4924 start
: settings
._iDisplayStart
,
4925 length
: settings
._iDisplayLength
,
4926 order
: $.extend( true, [], settings
.aaSorting
),
4927 search
: _fnSearchToCamel( settings
.oPreviousSearch
),
4928 columns
: $.map( settings
.aoColumns
, function ( col
, i
) {
4930 visible
: col
.bVisible
,
4931 search
: _fnSearchToCamel( settings
.aoPreSearchCols
[i
] )
4936 _fnCallbackFire( settings
, "aoStateSaveParams", 'stateSaveParams', [settings
, state
] );
4938 settings
.oSavedState
= state
;
4939 settings
.fnStateSaveCallback
.call( settings
.oInstance
, settings
, state
);
4944 * Attempt to load a saved table state
4945 * @param {object} oSettings dataTables settings object
4946 * @param {object} oInit DataTables init object so we can override settings
4947 * @memberof DataTable#oApi
4949 function _fnLoadState ( settings
, oInit
)
4952 var columns
= settings
.aoColumns
;
4954 if ( ! settings
.oFeatures
.bStateSave
) {
4958 var state
= settings
.fnStateLoadCallback
.call( settings
.oInstance
, settings
);
4959 if ( ! state
|| ! state
.time
) {
4963 /* Allow custom and plug-in manipulation functions to alter the saved data set and
4964 * cancelling of loading by returning false
4966 var abStateLoad
= _fnCallbackFire( settings
, 'aoStateLoadParams', 'stateLoadParams', [settings
, state
] );
4967 if ( $.inArray( false, abStateLoad
) !== -1 ) {
4971 /* Reject old data */
4972 var duration
= settings
.iStateDuration
;
4973 if ( duration
> 0 && state
.time
< +new Date() - (duration
*1000) ) {
4977 // Number of columns have changed - all bets are off, no restore of settings
4978 if ( columns
.length
!== state
.columns
.length
) {
4982 // Store the saved state so it might be accessed at any time
4983 settings
.oLoadedState
= $.extend( true, {}, state
);
4985 // Restore key features - todo - for 1.11 this needs to be done by
4986 // subscribed events
4987 if ( state
.start
!== undefined ) {
4988 settings
._iDisplayStart
= state
.start
;
4989 settings
.iInitDisplayStart
= state
.start
;
4991 if ( state
.length
!== undefined ) {
4992 settings
._iDisplayLength
= state
.length
;
4996 if ( state
.order
!== undefined ) {
4997 settings
.aaSorting
= [];
4998 $.each( state
.order
, function ( i
, col
) {
4999 settings
.aaSorting
.push( col
[0] >= columns
.length
?
5007 if ( state
.search
!== undefined ) {
5008 $.extend( settings
.oPreviousSearch
, _fnSearchToHung( state
.search
) );
5012 for ( i
=0, ien
=state
.columns
.length
; i
<ien
; i
++ ) {
5013 var col
= state
.columns
[i
];
5016 if ( col
.visible
!== undefined ) {
5017 columns
[i
].bVisible
= col
.visible
;
5021 if ( col
.search
!== undefined ) {
5022 $.extend( settings
.aoPreSearchCols
[i
], _fnSearchToHung( col
.search
) );
5026 _fnCallbackFire( settings
, 'aoStateLoaded', 'stateLoaded', [settings
, state
] );
5031 * Return the settings object for a particular table
5032 * @param {node} table table we are using as a dataTable
5033 * @returns {object} Settings object - or null if not found
5034 * @memberof DataTable#oApi
5036 function _fnSettingsFromNode ( table
)
5038 var settings
= DataTable
.settings
;
5039 var idx
= $.inArray( table
, _pluck( settings
, 'nTable' ) );
5048 * Log an error message
5049 * @param {object} settings dataTables settings object
5050 * @param {int} level log error messages, or display them to the user
5051 * @param {string} msg error message
5052 * @param {int} tn Technical note id to get more information about the error.
5053 * @memberof DataTable#oApi
5055 function _fnLog( settings
, level
, msg
, tn
)
5057 msg
= 'DataTables warning: '+
5058 (settings
!==null ? 'table id='+settings
.sTableId
+' - ' : '')+msg
;
5061 msg
+= '. For more information about this error, please see '+
5062 'http://datatables.net/tn/'+tn
;
5066 // Backwards compatibility pre 1.10
5067 var ext
= DataTable
.ext
;
5068 var type
= ext
.sErrMode
|| ext
.errMode
;
5070 _fnCallbackFire( settings
, null, 'error', [ settings
, tn
, msg
] );
5072 if ( type
== 'alert' ) {
5075 else if ( type
== 'throw' ) {
5076 throw new Error(msg
);
5078 else if ( typeof type
== 'function' ) {
5079 type( settings
, tn
, msg
);
5082 else if ( window
.console
&& console
.log
) {
5089 * See if a property is defined on one object, if so assign it to the other object
5090 * @param {object} ret target object
5091 * @param {object} src source object
5092 * @param {string} name property
5093 * @param {string} [mappedName] name to map too - optional, name used if not given
5094 * @memberof DataTable#oApi
5096 function _fnMap( ret
, src
, name
, mappedName
)
5098 if ( $.isArray( name
) ) {
5099 $.each( name
, function (i
, val
) {
5100 if ( $.isArray( val
) ) {
5101 _fnMap( ret
, src
, val
[0], val
[1] );
5104 _fnMap( ret
, src
, val
);
5111 if ( mappedName
=== undefined ) {
5115 if ( src
[name
] !== undefined ) {
5116 ret
[mappedName
] = src
[name
];
5122 * Extend objects - very similar to jQuery.extend, but deep copy objects, and
5123 * shallow copy arrays. The reason we need to do this, is that we don't want to
5124 * deep copy array init values (such as aaSorting) since the dev wouldn't be
5125 * able to override them, but we do want to deep copy arrays.
5126 * @param {object} out Object to extend
5127 * @param {object} extender Object from which the properties will be applied to
5129 * @param {boolean} breakRefs If true, then arrays will be sliced to take an
5130 * independent copy with the exception of the `data` or `aaData` parameters
5131 * if they are present. This is so you can pass in a collection to
5132 * DataTables and have that used as your data source without breaking the
5134 * @returns {object} out Reference, just for convenience - out === the return.
5135 * @memberof DataTable#oApi
5136 * @todo This doesn't take account of arrays inside the deep copied objects.
5138 function _fnExtend( out
, extender
, breakRefs
)
5142 for ( var prop
in extender
) {
5143 if ( extender
.hasOwnProperty(prop
) ) {
5144 val
= extender
[prop
];
5146 if ( $.isPlainObject( val
) ) {
5147 if ( ! $.isPlainObject( out
[prop
] ) ) {
5150 $.extend( true, out
[prop
], val
);
5152 else if ( breakRefs
&& prop
!== 'data' && prop
!== 'aaData' && $.isArray(val
) ) {
5153 out
[prop
] = val
.slice();
5166 * Bind an event handers to allow a click or return key to activate the callback.
5167 * This is good for accessibility since a return on the keyboard will have the
5168 * same effect as a click, if the element has focus.
5169 * @param {element} n Element to bind the action to
5170 * @param {object} oData Data object to pass to the triggered function
5171 * @param {function} fn Callback function for when the event is triggered
5172 * @memberof DataTable#oApi
5174 function _fnBindAction( n
, oData
, fn
)
5177 .bind( 'click.DT', oData
, function (e
) {
5178 n
.blur(); // Remove focus outline for mouse users
5181 .bind( 'keypress.DT', oData
, function (e
){
5182 if ( e
.which
=== 13 ) {
5187 .bind( 'selectstart.DT', function () {
5188 /* Take the brutal approach to cancelling text selection */
5195 * Register a callback function. Easily allows a callback function to be added to
5196 * an array store of callback functions that can then all be called together.
5197 * @param {object} oSettings dataTables settings object
5198 * @param {string} sStore Name of the array storage for the callbacks in oSettings
5199 * @param {function} fn Function to be called back
5200 * @param {string} sName Identifying name for the callback (i.e. a label)
5201 * @memberof DataTable#oApi
5203 function _fnCallbackReg( oSettings
, sStore
, fn
, sName
)
5207 oSettings
[sStore
].push( {
5216 * Fire callback functions and trigger events. Note that the loop over the
5217 * callback array store is done backwards! Further note that you do not want to
5218 * fire off triggers in time sensitive applications (for example cell creation)
5220 * @param {object} settings dataTables settings object
5221 * @param {string} callbackArr Name of the array storage for the callbacks in
5223 * @param {string} eventName Name of the jQuery custom event to trigger. If
5224 * null no trigger is fired
5225 * @param {array} args Array of arguments to pass to the callback function /
5227 * @memberof DataTable#oApi
5229 function _fnCallbackFire( settings
, callbackArr
, eventName
, args
)
5233 if ( callbackArr
) {
5234 ret
= $.map( settings
[callbackArr
].slice().reverse(), function (val
, i
) {
5235 return val
.fn
.apply( settings
.oInstance
, args
);
5239 if ( eventName
!== null ) {
5240 var e
= $.Event( eventName
+'.dt' );
5242 $(settings
.nTable
).trigger( e
, args
);
5244 ret
.push( e
.result
);
5251 function _fnLengthOverflow ( settings
)
5254 start
= settings
._iDisplayStart
,
5255 end
= settings
.fnDisplayEnd(),
5256 len
= settings
._iDisplayLength
;
5258 /* If we have space to show extra rows (backing up from the end point - then do so */
5264 // Keep the start record on the current page
5265 start
-= (start
% len
);
5267 if ( len
=== -1 || start
< 0 )
5272 settings
._iDisplayStart
= start
;
5276 function _fnRenderer( settings
, type
)
5278 var renderer
= settings
.renderer
;
5279 var host
= DataTable
.ext
.renderer
[type
];
5281 if ( $.isPlainObject( renderer
) && renderer
[type
] ) {
5282 // Specific renderer for this type. If available use it, otherwise use
5284 return host
[renderer
[type
]] || host
._
;
5286 else if ( typeof renderer
=== 'string' ) {
5287 // Common renderer - if there is one available for this type use it,
5288 // otherwise use the default
5289 return host
[renderer
] || host
._
;
5298 * Detect the data source being used for the table. Used to simplify the code
5299 * a little (ajax) and to make it compress a little smaller.
5301 * @param {object} settings dataTables settings object
5302 * @returns {string} Data source
5303 * @memberof DataTable#oApi
5305 function _fnDataSource ( settings
)
5307 if ( settings
.oFeatures
.bServerSide
) {
5310 else if ( settings
.ajax
|| settings
.sAjaxSource
) {
5317 DataTable = function( options
)
5320 * Perform a jQuery selector action on the table's TR elements (from the tbody) and
5321 * return the resulting jQuery object.
5322 * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
5323 * @param {object} [oOpts] Optional parameters for modifying the rows to be included
5324 * @param {string} [oOpts.filter=none] Select TR elements that meet the current filter
5325 * criterion ("applied") or all TR elements (i.e. no filter).
5326 * @param {string} [oOpts.order=current] Order of the TR elements in the processed array.
5327 * Can be either 'current', whereby the current sorting of the table is used, or
5328 * 'original' whereby the original order the data was read into the table is used.
5329 * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
5330 * ("current") or not ("all"). If 'current' is given, then order is assumed to be
5331 * 'current' and filter is 'applied', regardless of what they might be given as.
5332 * @returns {object} jQuery object, filtered by the given selector.
5334 * @deprecated Since v1.10
5337 * $(document).ready(function() {
5338 * var oTable = $('#example').dataTable();
5340 * // Highlight every second row
5341 * oTable.$('tr:odd').css('backgroundColor', 'blue');
5345 * $(document).ready(function() {
5346 * var oTable = $('#example').dataTable();
5348 * // Filter to rows with 'Webkit' in them, add a background colour and then
5349 * // remove the filter, thus highlighting the 'Webkit' rows only.
5350 * oTable.fnFilter('Webkit');
5351 * oTable.$('tr', {"search": "applied"}).css('backgroundColor', 'blue');
5352 * oTable.fnFilter('');
5355 this.$ = function ( sSelector
, oOpts
)
5357 return this.api(true).$( sSelector
, oOpts
);
5362 * Almost identical to $ in operation, but in this case returns the data for the matched
5363 * rows - as such, the jQuery selector used should match TR row nodes or TD/TH cell nodes
5364 * rather than any descendants, so the data can be obtained for the row/cell. If matching
5365 * rows are found, the data returned is the original data array/object that was used to
5366 * create the row (or a generated array if from a DOM source).
5368 * This method is often useful in-combination with $ where both functions are given the
5369 * same parameters and the array indexes will match identically.
5370 * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
5371 * @param {object} [oOpts] Optional parameters for modifying the rows to be included
5372 * @param {string} [oOpts.filter=none] Select elements that meet the current filter
5373 * criterion ("applied") or all elements (i.e. no filter).
5374 * @param {string} [oOpts.order=current] Order of the data in the processed array.
5375 * Can be either 'current', whereby the current sorting of the table is used, or
5376 * 'original' whereby the original order the data was read into the table is used.
5377 * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
5378 * ("current") or not ("all"). If 'current' is given, then order is assumed to be
5379 * 'current' and filter is 'applied', regardless of what they might be given as.
5380 * @returns {array} Data for the matched elements. If any elements, as a result of the
5381 * selector, were not TR, TD or TH elements in the DataTable, they will have a null
5382 * entry in the array.
5384 * @deprecated Since v1.10
5387 * $(document).ready(function() {
5388 * var oTable = $('#example').dataTable();
5390 * // Get the data from the first row in the table
5391 * var data = oTable._('tr:first');
5393 * // Do something useful with the data
5394 * alert( "First cell is: "+data[0] );
5398 * $(document).ready(function() {
5399 * var oTable = $('#example').dataTable();
5401 * // Filter to 'Webkit' and get all data for
5402 * oTable.fnFilter('Webkit');
5403 * var data = oTable._('tr', {"search": "applied"});
5405 * // Do something with the data
5406 * alert( data.length+" rows matched the search" );
5409 this._ = function ( sSelector
, oOpts
)
5411 return this.api(true).rows( sSelector
, oOpts
).data();
5416 * Create a DataTables Api instance, with the currently selected tables for
5417 * the Api's context.
5418 * @param {boolean} [traditional=false] Set the API instance's context to be
5419 * only the table referred to by the `DataTable.ext.iApiIndex` option, as was
5420 * used in the API presented by DataTables 1.9- (i.e. the traditional mode),
5421 * or if all tables captured in the jQuery object should be used.
5422 * @return {DataTables.Api}
5424 this.api = function ( traditional
)
5426 return traditional
?
5428 _fnSettingsFromNode( this[ _ext
.iApiIndex
] )
5435 * Add a single new row or multiple rows of data to the table. Please note
5436 * that this is suitable for client-side processing only - if you are using
5437 * server-side processing (i.e. "bServerSide": true), then to add data, you
5438 * must add it to the data source, i.e. the server-side, through an Ajax call.
5439 * @param {array|object} data The data to be added to the table. This can be:
5441 * <li>1D array of data - add a single row with the data provided</li>
5442 * <li>2D array of arrays - add multiple rows in a single call</li>
5443 * <li>object - data object when using <i>mData</i></li>
5444 * <li>array of objects - multiple data objects when using <i>mData</i></li>
5446 * @param {bool} [redraw=true] redraw the table or not
5447 * @returns {array} An array of integers, representing the list of indexes in
5448 * <i>aoData</i> ({@link DataTable.models.oSettings}) that have been added to
5451 * @deprecated Since v1.10
5454 * // Global var for counter
5457 * $(document).ready(function() {
5458 * $('#example').dataTable();
5461 * function fnClickAddRow() {
5462 * $('#example').dataTable().fnAddData( [
5472 this.fnAddData = function( data
, redraw
)
5474 var api
= this.api( true );
5476 /* Check if we want to add multiple rows or not */
5477 var rows
= $.isArray(data
) && ( $.isArray(data
[0]) || $.isPlainObject(data
[0]) ) ?
5478 api
.rows
.add( data
) :
5479 api
.row
.add( data
);
5481 if ( redraw
=== undefined || redraw
) {
5485 return rows
.flatten().toArray();
5490 * This function will make DataTables recalculate the column sizes, based on the data
5491 * contained in the table and the sizes applied to the columns (in the DOM, CSS or
5492 * through the sWidth parameter). This can be useful when the width of the table's
5493 * parent element changes (for example a window resize).
5494 * @param {boolean} [bRedraw=true] Redraw the table or not, you will typically want to
5496 * @deprecated Since v1.10
5499 * $(document).ready(function() {
5500 * var oTable = $('#example').dataTable( {
5501 * "sScrollY": "200px",
5502 * "bPaginate": false
5505 * $(window).bind('resize', function () {
5506 * oTable.fnAdjustColumnSizing();
5510 this.fnAdjustColumnSizing = function ( bRedraw
)
5512 var api
= this.api( true ).columns
.adjust();
5513 var settings
= api
.settings()[0];
5514 var scroll
= settings
.oScroll
;
5516 if ( bRedraw
=== undefined || bRedraw
) {
5519 else if ( scroll
.sX
!== "" || scroll
.sY
!== "" ) {
5520 /* If not redrawing, but scrolling, we want to apply the new column sizes anyway */
5521 _fnScrollDraw( settings
);
5527 * Quickly and simply clear a table
5528 * @param {bool} [bRedraw=true] redraw the table or not
5530 * @deprecated Since v1.10
5533 * $(document).ready(function() {
5534 * var oTable = $('#example').dataTable();
5536 * // Immediately 'nuke' the current rows (perhaps waiting for an Ajax callback...)
5537 * oTable.fnClearTable();
5540 this.fnClearTable = function( bRedraw
)
5542 var api
= this.api( true ).clear();
5544 if ( bRedraw
=== undefined || bRedraw
) {
5551 * The exact opposite of 'opening' a row, this function will close any rows which
5552 * are currently 'open'.
5553 * @param {node} nTr the table row to 'close'
5554 * @returns {int} 0 on success, or 1 if failed (can't find the row)
5556 * @deprecated Since v1.10
5559 * $(document).ready(function() {
5562 * // 'open' an information row when a row is clicked on
5563 * $('#example tbody tr').click( function () {
5564 * if ( oTable.fnIsOpen(this) ) {
5565 * oTable.fnClose( this );
5567 * oTable.fnOpen( this, "Temporary row opened", "info_row" );
5571 * oTable = $('#example').dataTable();
5574 this.fnClose = function( nTr
)
5576 this.api( true ).row( nTr
).child
.hide();
5581 * Remove a row for the table
5582 * @param {mixed} target The index of the row from aoData to be deleted, or
5583 * the TR element you want to delete
5584 * @param {function|null} [callBack] Callback function
5585 * @param {bool} [redraw=true] Redraw the table or not
5586 * @returns {array} The row that was deleted
5588 * @deprecated Since v1.10
5591 * $(document).ready(function() {
5592 * var oTable = $('#example').dataTable();
5594 * // Immediately remove the first row
5595 * oTable.fnDeleteRow( 0 );
5598 this.fnDeleteRow = function( target
, callback
, redraw
)
5600 var api
= this.api( true );
5601 var rows
= api
.rows( target
);
5602 var settings
= rows
.settings()[0];
5603 var data
= settings
.aoData
[ rows
[0][0] ];
5608 callback
.call( this, settings
, data
);
5611 if ( redraw
=== undefined || redraw
) {
5620 * Restore the table to it's original state in the DOM by removing all of DataTables
5621 * enhancements, alterations to the DOM structure of the table and event listeners.
5622 * @param {boolean} [remove=false] Completely remove the table from the DOM
5624 * @deprecated Since v1.10
5627 * $(document).ready(function() {
5628 * // This example is fairly pointless in reality, but shows how fnDestroy can be used
5629 * var oTable = $('#example').dataTable();
5630 * oTable.fnDestroy();
5633 this.fnDestroy = function ( remove
)
5635 this.api( true ).destroy( remove
);
5641 * @param {bool} [complete=true] Re-filter and resort (if enabled) the table before the draw.
5643 * @deprecated Since v1.10
5646 * $(document).ready(function() {
5647 * var oTable = $('#example').dataTable();
5649 * // Re-draw the table - you wouldn't want to do it here, but it's an example :-)
5653 this.fnDraw = function( complete
)
5655 // Note that this isn't an exact match to the old call to _fnDraw - it takes
5656 // into account the new data, but can hold position.
5657 this.api( true ).draw( complete
);
5662 * Filter the input based on data
5663 * @param {string} sInput String to filter the table on
5664 * @param {int|null} [iColumn] Column to limit filtering to
5665 * @param {bool} [bRegex=false] Treat as regular expression or not
5666 * @param {bool} [bSmart=true] Perform smart filtering or not
5667 * @param {bool} [bShowGlobal=true] Show the input global filter in it's input box(es)
5668 * @param {bool} [bCaseInsensitive=true] Do case-insensitive matching (true) or not (false)
5670 * @deprecated Since v1.10
5673 * $(document).ready(function() {
5674 * var oTable = $('#example').dataTable();
5676 * // Sometime later - filter...
5677 * oTable.fnFilter( 'test string' );
5680 this.fnFilter = function( sInput
, iColumn
, bRegex
, bSmart
, bShowGlobal
, bCaseInsensitive
)
5682 var api
= this.api( true );
5684 if ( iColumn
=== null || iColumn
=== undefined ) {
5685 api
.search( sInput
, bRegex
, bSmart
, bCaseInsensitive
);
5688 api
.column( iColumn
).search( sInput
, bRegex
, bSmart
, bCaseInsensitive
);
5696 * Get the data for the whole table, an individual row or an individual cell based on the
5697 * provided parameters.
5698 * @param {int|node} [src] A TR row node, TD/TH cell node or an integer. If given as
5699 * a TR node then the data source for the whole row will be returned. If given as a
5700 * TD/TH cell node then iCol will be automatically calculated and the data for the
5701 * cell returned. If given as an integer, then this is treated as the aoData internal
5702 * data index for the row (see fnGetPosition) and the data for that row used.
5703 * @param {int} [col] Optional column index that you want the data of.
5704 * @returns {array|object|string} If mRow is undefined, then the data for all rows is
5705 * returned. If mRow is defined, just data for that row, and is iCol is
5706 * defined, only data for the designated cell is returned.
5708 * @deprecated Since v1.10
5712 * $(document).ready(function() {
5713 * oTable = $('#example').dataTable();
5715 * oTable.$('tr').click( function () {
5716 * var data = oTable.fnGetData( this );
5717 * // ... do something with the array / object of data for the row
5722 * // Individual cell data
5723 * $(document).ready(function() {
5724 * oTable = $('#example').dataTable();
5726 * oTable.$('td').click( function () {
5727 * var sData = oTable.fnGetData( this );
5728 * alert( 'The cell clicked on had the value of '+sData );
5732 this.fnGetData = function( src
, col
)
5734 var api
= this.api( true );
5736 if ( src
!== undefined ) {
5737 var type
= src
.nodeName
? src
.nodeName
.toLowerCase() : '';
5739 return col
!== undefined || type
== 'td' || type
== 'th' ?
5740 api
.cell( src
, col
).data() :
5741 api
.row( src
).data() || null;
5744 return api
.data().toArray();
5749 * Get an array of the TR nodes that are used in the table's body. Note that you will
5750 * typically want to use the '$' API method in preference to this as it is more
5752 * @param {int} [iRow] Optional row index for the TR element you want
5753 * @returns {array|node} If iRow is undefined, returns an array of all TR elements
5754 * in the table's body, or iRow is defined, just the TR element requested.
5756 * @deprecated Since v1.10
5759 * $(document).ready(function() {
5760 * var oTable = $('#example').dataTable();
5762 * // Get the nodes from the table
5763 * var nNodes = oTable.fnGetNodes( );
5766 this.fnGetNodes = function( iRow
)
5768 var api
= this.api( true );
5770 return iRow
!== undefined ?
5771 api
.row( iRow
).node() :
5772 api
.rows().nodes().flatten().toArray();
5777 * Get the array indexes of a particular cell from it's DOM element
5778 * and column index including hidden columns
5779 * @param {node} node this can either be a TR, TD or TH in the table's body
5780 * @returns {int} If nNode is given as a TR, then a single index is returned, or
5781 * if given as a cell, an array of [row index, column index (visible),
5782 * column index (all)] is given.
5784 * @deprecated Since v1.10
5787 * $(document).ready(function() {
5788 * $('#example tbody td').click( function () {
5789 * // Get the position of the current data from the node
5790 * var aPos = oTable.fnGetPosition( this );
5792 * // Get the data array for this row
5793 * var aData = oTable.fnGetData( aPos[0] );
5795 * // Update the data array and return the value
5796 * aData[ aPos[1] ] = 'clicked';
5797 * this.innerHTML = 'clicked';
5800 * // Init DataTables
5801 * oTable = $('#example').dataTable();
5804 this.fnGetPosition = function( node
)
5806 var api
= this.api( true );
5807 var nodeName
= node
.nodeName
.toUpperCase();
5809 if ( nodeName
== 'TR' ) {
5810 return api
.row( node
).index();
5812 else if ( nodeName
== 'TD' || nodeName
== 'TH' ) {
5813 var cell
= api
.cell( node
).index();
5826 * Check to see if a row is 'open' or not.
5827 * @param {node} nTr the table row to check
5828 * @returns {boolean} true if the row is currently open, false otherwise
5830 * @deprecated Since v1.10
5833 * $(document).ready(function() {
5836 * // 'open' an information row when a row is clicked on
5837 * $('#example tbody tr').click( function () {
5838 * if ( oTable.fnIsOpen(this) ) {
5839 * oTable.fnClose( this );
5841 * oTable.fnOpen( this, "Temporary row opened", "info_row" );
5845 * oTable = $('#example').dataTable();
5848 this.fnIsOpen = function( nTr
)
5850 return this.api( true ).row( nTr
).child
.isShown();
5855 * This function will place a new row directly after a row which is currently
5856 * on display on the page, with the HTML contents that is passed into the
5857 * function. This can be used, for example, to ask for confirmation that a
5858 * particular record should be deleted.
5859 * @param {node} nTr The table row to 'open'
5860 * @param {string|node|jQuery} mHtml The HTML to put into the row
5861 * @param {string} sClass Class to give the new TD cell
5862 * @returns {node} The row opened. Note that if the table row passed in as the
5863 * first parameter, is not found in the table, this method will silently
5866 * @deprecated Since v1.10
5869 * $(document).ready(function() {
5872 * // 'open' an information row when a row is clicked on
5873 * $('#example tbody tr').click( function () {
5874 * if ( oTable.fnIsOpen(this) ) {
5875 * oTable.fnClose( this );
5877 * oTable.fnOpen( this, "Temporary row opened", "info_row" );
5881 * oTable = $('#example').dataTable();
5884 this.fnOpen = function( nTr
, mHtml
, sClass
)
5886 return this.api( true )
5888 .child( mHtml
, sClass
)
5895 * Change the pagination - provides the internal logic for pagination in a simple API
5896 * function. With this function you can have a DataTables table go to the next,
5897 * previous, first or last pages.
5898 * @param {string|int} mAction Paging action to take: "first", "previous", "next" or "last"
5899 * or page number to jump to (integer), note that page 0 is the first page.
5900 * @param {bool} [bRedraw=true] Redraw the table or not
5902 * @deprecated Since v1.10
5905 * $(document).ready(function() {
5906 * var oTable = $('#example').dataTable();
5907 * oTable.fnPageChange( 'next' );
5910 this.fnPageChange = function ( mAction
, bRedraw
)
5912 var api
= this.api( true ).page( mAction
);
5914 if ( bRedraw
=== undefined || bRedraw
) {
5921 * Show a particular column
5922 * @param {int} iCol The column whose display should be changed
5923 * @param {bool} bShow Show (true) or hide (false) the column
5924 * @param {bool} [bRedraw=true] Redraw the table or not
5926 * @deprecated Since v1.10
5929 * $(document).ready(function() {
5930 * var oTable = $('#example').dataTable();
5932 * // Hide the second column after initialisation
5933 * oTable.fnSetColumnVis( 1, false );
5936 this.fnSetColumnVis = function ( iCol
, bShow
, bRedraw
)
5938 var api
= this.api( true ).column( iCol
).visible( bShow
);
5940 if ( bRedraw
=== undefined || bRedraw
) {
5941 api
.columns
.adjust().draw();
5947 * Get the settings for a particular table for external manipulation
5948 * @returns {object} DataTables settings object. See
5949 * {@link DataTable.models.oSettings}
5951 * @deprecated Since v1.10
5954 * $(document).ready(function() {
5955 * var oTable = $('#example').dataTable();
5956 * var oSettings = oTable.fnSettings();
5958 * // Show an example parameter from the settings
5959 * alert( oSettings._iDisplayStart );
5962 this.fnSettings = function()
5964 return _fnSettingsFromNode( this[_ext
.iApiIndex
] );
5969 * Sort the table by a particular column
5970 * @param {int} iCol the data index to sort on. Note that this will not match the
5971 * 'display index' if you have hidden data entries
5973 * @deprecated Since v1.10
5976 * $(document).ready(function() {
5977 * var oTable = $('#example').dataTable();
5979 * // Sort immediately with columns 0 and 1
5980 * oTable.fnSort( [ [0,'asc'], [1,'asc'] ] );
5983 this.fnSort = function( aaSort
)
5985 this.api( true ).order( aaSort
).draw();
5990 * Attach a sort listener to an element for a given column
5991 * @param {node} nNode the element to attach the sort listener to
5992 * @param {int} iColumn the column that a click on this node will sort on
5993 * @param {function} [fnCallback] callback function when sort is run
5995 * @deprecated Since v1.10
5998 * $(document).ready(function() {
5999 * var oTable = $('#example').dataTable();
6001 * // Sort on column 1, when 'sorter' is clicked on
6002 * oTable.fnSortListener( document.getElementById('sorter'), 1 );
6005 this.fnSortListener = function( nNode
, iColumn
, fnCallback
)
6007 this.api( true ).order
.listener( nNode
, iColumn
, fnCallback
);
6012 * Update a table cell or row - this method will accept either a single value to
6013 * update the cell with, an array of values with one element for each column or
6014 * an object in the same format as the original data source. The function is
6015 * self-referencing in order to make the multi column updates easier.
6016 * @param {object|array|string} mData Data to update the cell/row with
6017 * @param {node|int} mRow TR element you want to update or the aoData index
6018 * @param {int} [iColumn] The column to update, give as null or undefined to
6019 * update a whole row.
6020 * @param {bool} [bRedraw=true] Redraw the table or not
6021 * @param {bool} [bAction=true] Perform pre-draw actions or not
6022 * @returns {int} 0 on success, 1 on error
6024 * @deprecated Since v1.10
6027 * $(document).ready(function() {
6028 * var oTable = $('#example').dataTable();
6029 * oTable.fnUpdate( 'Example update', 0, 0 ); // Single cell
6030 * oTable.fnUpdate( ['a', 'b', 'c', 'd', 'e'], $('tbody tr')[0] ); // Row
6033 this.fnUpdate = function( mData
, mRow
, iColumn
, bRedraw
, bAction
)
6035 var api
= this.api( true );
6037 if ( iColumn
=== undefined || iColumn
=== null ) {
6038 api
.row( mRow
).data( mData
);
6041 api
.cell( mRow
, iColumn
).data( mData
);
6044 if ( bAction
=== undefined || bAction
) {
6045 api
.columns
.adjust();
6048 if ( bRedraw
=== undefined || bRedraw
) {
6056 * Provide a common method for plug-ins to check the version of DataTables being used, in order
6057 * to ensure compatibility.
6058 * @param {string} sVersion Version string to check for, in the format "X.Y.Z". Note that the
6059 * formats "X" and "X.Y" are also acceptable.
6060 * @returns {boolean} true if this version of DataTables is greater or equal to the required
6061 * version, or false if this version of DataTales is not suitable
6064 * @deprecated Since v1.10
6067 * $(document).ready(function() {
6068 * var oTable = $('#example').dataTable();
6069 * alert( oTable.fnVersionCheck( '1.9.0' ) );
6072 this.fnVersionCheck
= _ext
.fnVersionCheck
;
6076 var emptyInit
= options
=== undefined;
6077 var len
= this.length
;
6083 this.oApi
= this.internal = _ext
.internal;
6085 // Extend with old style plug-in API methods
6086 for ( var fn
in DataTable
.ext
.internal ) {
6088 this[fn
] = _fnExternApiFunc(fn
);
6092 this.each(function() {
6093 // For each initialisation we want to give it a clean initialisation
6094 // object that can be bashed around
6096 var oInit
= len
> 1 ? // optimisation for single table case
6097 _fnExtend( o
, options
, true ) :
6100 /*global oInit,_that,emptyInit*/
6101 var i
=0, iLen
, j
, jLen
, k
, kLen
;
6102 var sId
= this.getAttribute( 'id' );
6103 var bInitHandedOff
= false;
6104 var defaults
= DataTable
.defaults
;
6105 var $this = $(this);
6109 if ( this.nodeName
.toLowerCase() != 'table' )
6111 _fnLog( null, 0, 'Non-table node initialisation ('+this.nodeName
+')', 2 );
6115 /* Backwards compatibility for the defaults */
6116 _fnCompatOpts( defaults
);
6117 _fnCompatCols( defaults
.column
);
6119 /* Convert the camel-case defaults to Hungarian */
6120 _fnCamelToHungarian( defaults
, defaults
, true );
6121 _fnCamelToHungarian( defaults
.column
, defaults
.column
, true );
6123 /* Setting up the initialisation object */
6124 _fnCamelToHungarian( defaults
, $.extend( oInit
, $this.data() ) );
6128 /* Check to see if we are re-initialising a table */
6129 var allSettings
= DataTable
.settings
;
6130 for ( i
=0, iLen
=allSettings
.length
; i
<iLen
; i
++ )
6132 var s
= allSettings
[i
];
6134 /* Base check on table node */
6135 if ( s
.nTable
== this || s
.nTHead
.parentNode
== this || (s
.nTFoot
&& s
.nTFoot
.parentNode
== this) )
6137 var bRetrieve
= oInit
.bRetrieve
!== undefined ? oInit
.bRetrieve
: defaults
.bRetrieve
;
6138 var bDestroy
= oInit
.bDestroy
!== undefined ? oInit
.bDestroy
: defaults
.bDestroy
;
6140 if ( emptyInit
|| bRetrieve
)
6144 else if ( bDestroy
)
6146 s
.oInstance
.fnDestroy();
6151 _fnLog( s
, 0, 'Cannot reinitialise DataTable', 3 );
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 ( s
.sTableId
== this.id
)
6163 allSettings
.splice( i
, 1 );
6168 /* Ensure the table has an ID - required for accessibility */
6169 if ( sId
=== null || sId
=== "" )
6171 sId
= "DataTables_Table_"+(DataTable
.ext
._unique
++);
6175 /* Create the settings object for this table and set some of the default parameters */
6176 var oSettings
= $.extend( true, {}, DataTable
.models
.oSettings
, {
6177 "sDestroyWidth": $this[0].style
.width
,
6181 oSettings
.nTable
= this;
6182 oSettings
.oApi
= _that
.internal;
6183 oSettings
.oInit
= oInit
;
6185 allSettings
.push( oSettings
);
6187 // Need to add the instance after the instance after the settings object has been added
6188 // to the settings array, so we can self reference the table instance if more than one
6189 oSettings
.oInstance
= (_that
.length
===1) ? _that
: $this.dataTable();
6191 // Backwards compatibility, before we apply all the defaults
6192 _fnCompatOpts( oInit
);
6194 if ( oInit
.oLanguage
)
6196 _fnLanguageCompat( oInit
.oLanguage
);
6199 // If the length menu is given, but the init display length is not, use the length menu
6200 if ( oInit
.aLengthMenu
&& ! oInit
.iDisplayLength
)
6202 oInit
.iDisplayLength
= $.isArray( oInit
.aLengthMenu
[0] ) ?
6203 oInit
.aLengthMenu
[0][0] : oInit
.aLengthMenu
[0];
6206 // Apply the defaults and init options to make a single init object will all
6207 // options defined from defaults and instance options.
6208 oInit
= _fnExtend( $.extend( true, {}, defaults
), oInit
);
6211 // Map the initialisation options onto the settings object
6212 _fnMap( oSettings
.oFeatures
, oInit
, [
6225 _fnMap( oSettings
, oInit
, [
6241 "fnStateLoadCallback",
6242 "fnStateSaveCallback",
6245 [ "iCookieDuration", "iStateDuration" ], // backwards compat
6246 [ "oSearch", "oPreviousSearch" ],
6247 [ "aoSearchCols", "aoPreSearchCols" ],
6248 [ "iDisplayLength", "_iDisplayLength" ],
6249 [ "bJQueryUI", "bJUI" ]
6251 _fnMap( oSettings
.oScroll
, oInit
, [
6252 [ "sScrollX", "sX" ],
6253 [ "sScrollXInner", "sXInner" ],
6254 [ "sScrollY", "sY" ],
6255 [ "bScrollCollapse", "bCollapse" ]
6257 _fnMap( oSettings
.oLanguage
, oInit
, "fnInfoCallback" );
6259 /* Callback functions which are array driven */
6260 _fnCallbackReg( oSettings
, 'aoDrawCallback', oInit
.fnDrawCallback
, 'user' );
6261 _fnCallbackReg( oSettings
, 'aoServerParams', oInit
.fnServerParams
, 'user' );
6262 _fnCallbackReg( oSettings
, 'aoStateSaveParams', oInit
.fnStateSaveParams
, 'user' );
6263 _fnCallbackReg( oSettings
, 'aoStateLoadParams', oInit
.fnStateLoadParams
, 'user' );
6264 _fnCallbackReg( oSettings
, 'aoStateLoaded', oInit
.fnStateLoaded
, 'user' );
6265 _fnCallbackReg( oSettings
, 'aoRowCallback', oInit
.fnRowCallback
, 'user' );
6266 _fnCallbackReg( oSettings
, 'aoRowCreatedCallback', oInit
.fnCreatedRow
, 'user' );
6267 _fnCallbackReg( oSettings
, 'aoHeaderCallback', oInit
.fnHeaderCallback
, 'user' );
6268 _fnCallbackReg( oSettings
, 'aoFooterCallback', oInit
.fnFooterCallback
, 'user' );
6269 _fnCallbackReg( oSettings
, 'aoInitComplete', oInit
.fnInitComplete
, 'user' );
6270 _fnCallbackReg( oSettings
, 'aoPreDrawCallback', oInit
.fnPreDrawCallback
, 'user' );
6272 var oClasses
= oSettings
.oClasses
;
6274 // @todo Remove in 1.11
6275 if ( oInit
.bJQueryUI
)
6277 /* Use the JUI classes object for display. You could clone the oStdClasses object if
6278 * you want to have multiple tables with multiple independent classes
6280 $.extend( oClasses
, DataTable
.ext
.oJUIClasses
, oInit
.oClasses
);
6282 if ( oInit
.sDom
=== defaults
.sDom
&& defaults
.sDom
=== "lfrtip" )
6284 /* Set the DOM to use a layout suitable for jQuery UI's theming */
6285 oSettings
.sDom
= '<"H"lfr>t<"F"ip>';
6288 if ( ! oSettings
.renderer
) {
6289 oSettings
.renderer
= 'jqueryui';
6291 else if ( $.isPlainObject( oSettings
.renderer
) && ! oSettings
.renderer
.header
) {
6292 oSettings
.renderer
.header
= 'jqueryui';
6297 $.extend( oClasses
, DataTable
.ext
.classes
, oInit
.oClasses
);
6299 $this.addClass( oClasses
.sTable
);
6301 /* Calculate the scroll bar width and cache it for use later on */
6302 if ( oSettings
.oScroll
.sX
!== "" || oSettings
.oScroll
.sY
!== "" )
6304 oSettings
.oScroll
.iBarWidth
= _fnScrollBarWidth();
6306 if ( oSettings
.oScroll
.sX
=== true ) { // Easy initialisation of x-scrolling
6307 oSettings
.oScroll
.sX
= '100%';
6310 if ( oSettings
.iInitDisplayStart
=== undefined )
6312 /* Display start point, taking into account the save saving */
6313 oSettings
.iInitDisplayStart
= oInit
.iDisplayStart
;
6314 oSettings
._iDisplayStart
= oInit
.iDisplayStart
;
6317 if ( oInit
.iDeferLoading
!== null )
6319 oSettings
.bDeferLoading
= true;
6320 var tmp
= $.isArray( oInit
.iDeferLoading
);
6321 oSettings
._iRecordsDisplay
= tmp
? oInit
.iDeferLoading
[0] : oInit
.iDeferLoading
;
6322 oSettings
._iRecordsTotal
= tmp
? oInit
.iDeferLoading
[1] : oInit
.iDeferLoading
;
6325 /* Language definitions */
6326 var oLanguage
= oSettings
.oLanguage
;
6327 $.extend( true, oLanguage
, oInit
.oLanguage
);
6329 if ( oLanguage
.sUrl
!== "" )
6331 /* Get the language definitions from a file - because this Ajax call makes the language
6332 * get async to the remainder of this function we use bInitHandedOff to indicate that
6333 * _fnInitialise will be fired by the returned Ajax handler, rather than the constructor
6337 url
: oLanguage
.sUrl
,
6338 success: function ( json
) {
6339 _fnLanguageCompat( json
);
6340 _fnCamelToHungarian( defaults
.oLanguage
, json
);
6341 $.extend( true, oLanguage
, json
);
6342 _fnInitialise( oSettings
);
6344 error: function () {
6345 // Error occurred loading language file, continue on as best we can
6346 _fnInitialise( oSettings
);
6349 bInitHandedOff
= true;
6355 if ( oInit
.asStripeClasses
=== null )
6357 oSettings
.asStripeClasses
=[
6358 oClasses
.sStripeOdd
,
6359 oClasses
.sStripeEven
6363 /* Remove row stripe classes if they are already on the table row */
6364 var stripeClasses
= oSettings
.asStripeClasses
;
6365 var rowOne
= $this.children('tbody').find('tr').eq(0);
6366 if ( $.inArray( true, $.map( stripeClasses
, function(el
, i
) {
6367 return rowOne
.hasClass(el
);
6369 $('tbody tr', this).removeClass( stripeClasses
.join(' ') );
6370 oSettings
.asDestroyStripes
= stripeClasses
.slice();
6375 * See if we should load columns automatically or use defined ones
6379 var nThead
= this.getElementsByTagName('thead');
6380 if ( nThead
.length
!== 0 )
6382 _fnDetectHeader( oSettings
.aoHeader
, nThead
[0] );
6383 anThs
= _fnGetUniqueThs( oSettings
);
6386 /* If not given a column array, generate one with nulls */
6387 if ( oInit
.aoColumns
=== null )
6390 for ( i
=0, iLen
=anThs
.length
; i
<iLen
; i
++ )
6392 aoColumnsInit
.push( null );
6397 aoColumnsInit
= oInit
.aoColumns
;
6400 /* Add the columns */
6401 for ( i
=0, iLen
=aoColumnsInit
.length
; i
<iLen
; i
++ )
6403 _fnAddColumn( oSettings
, anThs
? anThs
[i
] : null );
6406 /* Apply the column definitions */
6407 _fnApplyColumnDefs( oSettings
, oInit
.aoColumnDefs
, aoColumnsInit
, function (iCol
, oDef
) {
6408 _fnColumnOptions( oSettings
, iCol
, oDef
);
6411 /* HTML5 attribute detection - build an mData object automatically if the
6412 * attributes are found
6414 if ( rowOne
.length
) {
6415 var a = function ( cell
, name
) {
6416 return cell
.getAttribute( 'data-'+name
) !== null ? name
: null;
6419 $.each( _fnGetRowElements( oSettings
, rowOne
[0] ).cells
, function (i
, cell
) {
6420 var col
= oSettings
.aoColumns
[i
];
6422 if ( col
.mData
=== i
) {
6423 var sort
= a( cell
, 'sort' ) || a( cell
, 'order' );
6424 var filter
= a( cell
, 'filter' ) || a( cell
, 'search' );
6426 if ( sort
!== null || filter
!== null ) {
6429 sort
: sort
!== null ? i
+'.@data-'+sort
: undefined,
6430 type
: sort
!== null ? i
+'.@data-'+sort
: undefined,
6431 filter
: filter
!== null ? i
+'.@data-'+filter
: undefined
6434 _fnColumnOptions( oSettings
, i
);
6440 var features
= oSettings
.oFeatures
;
6442 /* Must be done after everything which can be overridden by the state saving! */
6443 if ( oInit
.bStateSave
)
6445 features
.bStateSave
= true;
6446 _fnLoadState( oSettings
, oInit
);
6447 _fnCallbackReg( oSettings
, 'aoDrawCallback', _fnSaveState
, 'state_save' );
6453 * @todo For modularisation (1.11) this needs to do into a sort start up handler
6456 // If aaSorting is not defined, then we use the first indicator in asSorting
6457 // in case that has been altered, so the default sort reflects that option
6458 if ( oInit
.aaSorting
=== undefined )
6460 var sorting
= oSettings
.aaSorting
;
6461 for ( i
=0, iLen
=sorting
.length
; i
<iLen
; i
++ )
6463 sorting
[i
][1] = oSettings
.aoColumns
[ i
].asSorting
[0];
6467 /* Do a first pass on the sorting classes (allows any size changes to be taken into
6468 * account, and also will apply sorting disabled classes if disabled
6470 _fnSortingClasses( oSettings
);
6472 if ( features
.bSort
)
6474 _fnCallbackReg( oSettings
, 'aoDrawCallback', function () {
6475 if ( oSettings
.bSorted
) {
6476 var aSort
= _fnSortFlatten( oSettings
);
6477 var sortedColumns
= {};
6479 $.each( aSort
, function (i
, val
) {
6480 sortedColumns
[ val
.src
] = val
.dir
;
6483 _fnCallbackFire( oSettings
, null, 'order', [oSettings
, aSort
, sortedColumns
] );
6484 _fnSortAria( oSettings
);
6489 _fnCallbackReg( oSettings
, 'aoDrawCallback', function () {
6490 if ( oSettings
.bSorted
|| _fnDataSource( oSettings
) === 'ssp' || features
.bDeferRender
) {
6491 _fnSortingClasses( oSettings
);
6498 * Cache the header, body and footer as required, creating them if needed
6501 /* Browser support detection */
6502 _fnBrowserDetect( oSettings
);
6504 // Work around for Webkit bug 83867 - store the caption-side before removing from doc
6505 var captions
= $this.children('caption').each( function () {
6506 this._captionSide
= $this.css('caption-side');
6509 var thead
= $this.children('thead');
6510 if ( thead
.length
=== 0 )
6512 thead
= $('<thead/>').appendTo(this);
6514 oSettings
.nTHead
= thead
[0];
6516 var tbody
= $this.children('tbody');
6517 if ( tbody
.length
=== 0 )
6519 tbody
= $('<tbody/>').appendTo(this);
6521 oSettings
.nTBody
= tbody
[0];
6523 var tfoot
= $this.children('tfoot');
6524 if ( tfoot
.length
=== 0 && captions
.length
> 0 && (oSettings
.oScroll
.sX
!== "" || oSettings
.oScroll
.sY
!== "") )
6526 // If we are a scrolling table, and no footer has been given, then we need to create
6527 // a tfoot element for the caption element to be appended to
6528 tfoot
= $('<tfoot/>').appendTo(this);
6531 if ( tfoot
.length
=== 0 || tfoot
.children().length
=== 0 ) {
6532 $this.addClass( oClasses
.sNoFooter
);
6534 else if ( tfoot
.length
> 0 ) {
6535 oSettings
.nTFoot
= tfoot
[0];
6536 _fnDetectHeader( oSettings
.aoFooter
, oSettings
.nTFoot
);
6539 /* Check if there is data passing into the constructor */
6542 for ( i
=0 ; i
<oInit
.aaData
.length
; i
++ )
6544 _fnAddData( oSettings
, oInit
.aaData
[ i
] );
6547 else if ( oSettings
.bDeferLoading
|| _fnDataSource( oSettings
) == 'dom' )
6549 /* Grab the data from the page - only do this when deferred loading or no Ajax
6550 * source since there is no point in reading the DOM data if we are then going
6551 * to replace it with Ajax data
6553 _fnAddTr( oSettings
, $(oSettings
.nTBody
).children('tr') );
6556 /* Copy the data index array */
6557 oSettings
.aiDisplay
= oSettings
.aiDisplayMaster
.slice();
6559 /* Initialisation complete - table can be drawn */
6560 oSettings
.bInitialised
= true;
6562 /* Check if we need to initialise the table (it might not have been handed off to the
6563 * language processor)
6565 if ( bInitHandedOff
=== false )
6567 _fnInitialise( oSettings
);
6577 * Computed structure of the DataTables API, defined by the options passed to
6578 * `DataTable.Api.register()` when building the API.
6580 * The structure is built in order to speed creation and extension of the Api
6581 * objects since the extensions are effectively pre-parsed.
6583 * The array is an array of objects with the following structure, where this
6584 * base array represents the Api prototype base:
6588 * name: 'data' -- string - Property name
6589 * val: function () {}, -- function - Api method (or undefined if just an object
6590 * methodExt: [ ... ], -- array - Array of Api object definitions to extend the method result
6591 * propExt: [ ... ] -- array - Array of Api object definitions to extend the property
6596 * methodExt: [ ... ],
6600 * val: function () {},
6601 * methodExt: [ ... ],
6612 var __apiStruct
= [];
6616 * `Array.prototype` reference.
6621 var __arrayProto
= Array
.prototype;
6625 * Abstraction for `context` parameter of the `Api` constructor to allow it to
6626 * take several different forms for ease of use.
6628 * Each of the input parameter types will be converted to a DataTables settings
6629 * object where possible.
6631 * @param {string|node|jQuery|object} mixed DataTable identifier. Can be one
6634 * * `string` - jQuery selector. Any DataTables' matching the given selector
6635 * with be found and used.
6636 * * `node` - `TABLE` node which has already been formed into a DataTable.
6637 * * `jQuery` - A jQuery object of `TABLE` nodes.
6638 * * `object` - DataTables settings object
6639 * * `DataTables.Api` - API instance
6640 * @return {array|null} Matching DataTables settings objects. `null` or
6641 * `undefined` is returned if no matching DataTable is found.
6644 var _toSettings = function ( mixed
)
6647 var settings
= DataTable
.settings
;
6648 var tables
= $.map( settings
, function (el
, i
) {
6655 else if ( mixed
.nTable
&& mixed
.oApi
) {
6656 // DataTables settings object
6659 else if ( mixed
.nodeName
&& mixed
.nodeName
.toLowerCase() === 'table' ) {
6661 idx
= $.inArray( mixed
, tables
);
6662 return idx
!== -1 ? [ settings
[idx
] ] : null;
6664 else if ( mixed
&& typeof mixed
.settings
=== 'function' ) {
6665 return mixed
.settings().toArray();
6667 else if ( typeof mixed
=== 'string' ) {
6671 else if ( mixed
instanceof $ ) {
6672 // jQuery object (also DataTables instance)
6677 return jq
.map( function(i
) {
6678 idx
= $.inArray( this, tables
);
6679 return idx
!== -1 ? settings
[idx
] : null;
6686 * DataTables API class - used to control and interface with one or more
6687 * DataTables enhanced tables.
6689 * The API class is heavily based on jQuery, presenting a chainable interface
6690 * that you can use to interact with tables. Each instance of the API class has
6691 * a "context" - i.e. the tables that it will operate on. This could be a single
6692 * table, all tables on a page or a sub-set thereof.
6694 * Additionally the API is designed to allow you to easily work with the data in
6695 * the tables, retrieving and manipulating it as required. This is done by
6696 * presenting the API class as an array like interface. The contents of the
6697 * array depend upon the actions requested by each method (for example
6698 * `rows().nodes()` will return an array of nodes, while `rows().data()` will
6699 * return an array of objects or arrays depending upon your table's
6700 * configuration). The API object has a number of array like methods (`push`,
6701 * `pop`, `reverse` etc) as well as additional helper methods (`each`, `pluck`,
6702 * `unique` etc) to assist your working with the data held in a table.
6704 * Most methods (those which return an Api instance) are chainable, which means
6705 * the return from a method call also has all of the methods available that the
6706 * top level object had. For example, these two calls are equivalent:
6709 * api.row.add( {...} );
6713 * api.row.add( {...} ).draw();
6715 * @class DataTable.Api
6716 * @param {array|object|string|jQuery} context DataTable identifier. This is
6717 * used to define which DataTables enhanced tables this API will operate on.
6720 * * `string` - jQuery selector. Any DataTables' matching the given selector
6721 * with be found and used.
6722 * * `node` - `TABLE` node which has already been formed into a DataTable.
6723 * * `jQuery` - A jQuery object of `TABLE` nodes.
6724 * * `object` - DataTables settings object
6725 * @param {array} [data] Data to initialise the Api instance with.
6728 * // Direct initialisation during DataTables construction
6729 * var api = $('#example').DataTable();
6732 * // Initialisation using a DataTables jQuery object
6733 * var api = $('#example').dataTable().api();
6736 * // Initialisation as a constructor
6737 * var api = new $.fn.DataTable.Api( 'table.dataTable' );
6739 _Api = function ( context
, data
)
6741 if ( ! (this instanceof _Api
) ) {
6742 return new _Api( context
, data
);
6746 var ctxSettings = function ( o
) {
6747 var a
= _toSettings( o
);
6749 settings
.push
.apply( settings
, a
);
6753 if ( $.isArray( context
) ) {
6754 for ( var i
=0, ien
=context
.length
; i
<ien
; i
++ ) {
6755 ctxSettings( context
[i
] );
6759 ctxSettings( context
);
6762 // Remove duplicates
6763 this.context
= _unique( settings
);
6767 this.push
.apply( this, data
.toArray
? data
.toArray() : data
);
6777 _Api
.extend( this, this, __apiStruct
);
6780 DataTable
.Api
= _Api
;
6782 _Api
.prototype = /** @lends DataTables.Api */{
6785 return this.flatten().length
!== 0;
6789 concat
: __arrayProto
.concat
,
6792 context
: [], // array of table settings objects
6795 each: function ( fn
)
6797 for ( var i
=0, ien
=this.length
; i
<ien
; i
++ ) {
6798 fn
.call( this, this[i
], i
, this );
6805 eq: function ( idx
)
6807 var ctx
= this.context
;
6809 return ctx
.length
> idx
?
6810 new _Api( ctx
[idx
], this[idx
] ) :
6815 filter: function ( fn
)
6819 if ( __arrayProto
.filter
) {
6820 a
= __arrayProto
.filter
.call( this, fn
, this );
6823 // Compatibility for browsers without EMCA-252-5 (JS 1.6)
6824 for ( var i
=0, ien
=this.length
; i
<ien
; i
++ ) {
6825 if ( fn
.call( this, this[i
], i
, this ) ) {
6831 return new _Api( this.context
, a
);
6835 flatten: function ()
6838 return new _Api( this.context
, a
.concat
.apply( a
, this.toArray() ) );
6842 join
: __arrayProto
.join
,
6845 indexOf
: __arrayProto
.indexOf
|| function (obj
, start
)
6847 for ( var i
=(start
|| 0), ien
=this.length
; i
<ien
; i
++ ) {
6848 if ( this[i
] === obj
) {
6855 iterator: function ( flatten
, type
, fn
, alwaysNew
) {
6859 context
= this.context
,
6861 selector
= this.selector
;
6863 // Argument shifting
6864 if ( typeof flatten
=== 'string' ) {
6871 for ( i
=0, ien
=context
.length
; i
<ien
; i
++ ) {
6872 var apiInst
= new _Api( context
[i
] );
6874 if ( type
=== 'table' ) {
6875 ret
= fn
.call( apiInst
, context
[i
], i
);
6877 if ( ret
!== undefined ) {
6881 else if ( type
=== 'columns' || type
=== 'rows' ) {
6882 // this has same length as context - one entry for each table
6883 ret
= fn
.call( apiInst
, context
[i
], this[i
], i
);
6885 if ( ret
!== undefined ) {
6889 else if ( type
=== 'column' || type
=== 'column-rows' || type
=== 'row' || type
=== 'cell' ) {
6890 // columns and rows share the same structure.
6891 // 'this' is an array of column indexes for each context
6894 if ( type
=== 'column-rows' ) {
6895 rows
= _selector_row_indexes( context
[i
], selector
.opts
);
6898 for ( j
=0, jen
=items
.length
; j
<jen
; j
++ ) {
6901 if ( type
=== 'cell' ) {
6902 ret
= fn
.call( apiInst
, context
[i
], item
.row
, item
.column
, i
, j
);
6905 ret
= fn
.call( apiInst
, context
[i
], item
, i
, j
, rows
);
6908 if ( ret
!== undefined ) {
6915 if ( a
.length
|| alwaysNew
) {
6916 var api
= new _Api( context
, flatten
? a
.concat
.apply( [], a
) : a
);
6917 var apiSelector
= api
.selector
;
6918 apiSelector
.rows
= selector
.rows
;
6919 apiSelector
.cols
= selector
.cols
;
6920 apiSelector
.opts
= selector
.opts
;
6927 lastIndexOf
: __arrayProto
.lastIndexOf
|| function (obj
, start
)
6930 return this.indexOf
.apply( this.toArray
.reverse(), arguments
);
6937 map: function ( fn
)
6941 if ( __arrayProto
.map
) {
6942 a
= __arrayProto
.map
.call( this, fn
, this );
6945 // Compatibility for browsers without EMCA-252-5 (JS 1.6)
6946 for ( var i
=0, ien
=this.length
; i
<ien
; i
++ ) {
6947 a
.push( fn
.call( this, this[i
], i
) );
6951 return new _Api( this.context
, a
);
6955 pluck: function ( prop
)
6957 return this.map( function ( el
) {
6962 pop
: __arrayProto
.pop
,
6965 push
: __arrayProto
.push
,
6968 // Does not return an API instance
6969 reduce
: __arrayProto
.reduce
|| function ( fn
, init
)
6971 return _fnReduce( this, fn
, init
, 0, this.length
, 1 );
6975 reduceRight
: __arrayProto
.reduceRight
|| function ( fn
, init
)
6977 return _fnReduce( this, fn
, init
, this.length
-1, -1, -1 );
6981 reverse
: __arrayProto
.reverse
,
6984 // Object with rows, columns and opts
6988 shift
: __arrayProto
.shift
,
6991 sort
: __arrayProto
.sort
, // ? name - order?
6994 splice
: __arrayProto
.splice
,
6997 toArray: function ()
6999 return __arrayProto
.slice
.call( this );
7009 toJQuery: function ()
7017 return new _Api( this.context
, _unique(this) );
7021 unshift
: __arrayProto
.unshift
7025 _Api
.extend = function ( scope
, obj
, ext
)
7027 // Only extend API instances and static properties of the API
7028 if ( ! ext
.length
|| ! obj
|| ( ! (obj
instanceof _Api
) && ! obj
.__dt_wrapper
) ) {
7036 methodScoping = function ( scope
, fn
, struc
) {
7037 return function () {
7038 var ret
= fn
.apply( scope
, arguments
);
7041 _Api
.extend( ret
, ret
, struc
.methodExt
);
7046 for ( i
=0, ien
=ext
.length
; i
<ien
; i
++ ) {
7050 obj
[ struct
.name
] = typeof struct
.val
=== 'function' ?
7051 methodScoping( scope
, struct
.val
, struct
) :
7052 $.isPlainObject( struct
.val
) ?
7056 obj
[ struct
.name
].__dt_wrapper
= true;
7058 // Property extension
7059 _Api
.extend( scope
, obj
[ struct
.name
], struct
.propExt
);
7064 // @todo - Is there need for an augment function?
7065 // _Api.augment = function ( inst, name )
7067 // // Find src object in the structure from the name
7068 // var parts = name.split('.');
7070 // _Api.extend( inst, obj );
7076 // name: 'data' -- string - Property name
7077 // val: function () {}, -- function - Api method (or undefined if just an object
7078 // methodExt: [ ... ], -- array - Array of Api object definitions to extend the method result
7079 // propExt: [ ... ] -- array - Array of Api object definitions to extend the property
7084 // methodExt: [ ... ],
7088 // val: function () {},
7089 // methodExt: [ ... ],
7097 _Api
.register
= _api_register = function ( name
, val
)
7099 if ( $.isArray( name
) ) {
7100 for ( var j
=0, jen
=name
.length
; j
<jen
; j
++ ) {
7101 _Api
.register( name
[j
], val
);
7108 heir
= name
.split('.'),
7109 struct
= __apiStruct
,
7112 var find = function ( src
, name
) {
7113 for ( var i
=0, ien
=src
.length
; i
<ien
; i
++ ) {
7114 if ( src
[i
].name
=== name
) {
7121 for ( i
=0, ien
=heir
.length
; i
<ien
; i
++ ) {
7122 method
= heir
[i
].indexOf('()') !== -1;
7124 heir
[i
].replace('()', '') :
7127 var src
= find( struct
, key
);
7138 if ( i
=== ien
-1 ) {
7150 _Api
.registerPlural
= _api_registerPlural = function ( pluralName
, singularName
, val
) {
7151 _Api
.register( pluralName
, val
);
7153 _Api
.register( singularName
, function () {
7154 var ret
= val
.apply( this, arguments
);
7156 if ( ret
=== this ) {
7157 // Returned item is the API instance that was passed in, return it
7160 else if ( ret
instanceof _Api
) {
7161 // New API instance returned, want the value from the first item
7162 // in the returned array for the singular result.
7164 $.isArray( ret
[0] ) ?
7165 new _Api( ret
.context
, ret
[0] ) : // Array results are 'enhanced'
7170 // Non-API return - just fire it back
7177 * Selector for HTML tables. Apply the given selector to the give array of
7178 * DataTables settings objects.
7180 * @param {string|integer} [selector] jQuery selector string or integer
7181 * @param {array} Array of DataTables settings objects to be filtered
7185 var __table_selector = function ( selector
, a
)
7187 // Integer is used to pick out a table by index
7188 if ( typeof selector
=== 'number' ) {
7189 return [ a
[ selector
] ];
7192 // Perform a jQuery selector on the table nodes
7193 var nodes
= $.map( a
, function (el
, i
) {
7199 .map( function (i
) {
7200 // Need to translate back from the table node to the settings
7201 var idx
= $.inArray( this, nodes
);
7210 * Context selector for the API's context (i.e. the tables the API instance
7213 * @name DataTable.Api#tables
7214 * @param {string|integer} [selector] Selector to pick which tables the iterator
7215 * should operate on. If not given, all tables in the current context are
7216 * used. This can be given as a jQuery selector (for example `':gt(0)'`) to
7217 * select multiple tables or as an integer to select a single table.
7218 * @returns {DataTable.Api} Returns a new API instance if a selector is given.
7220 _api_register( 'tables()', function ( selector
) {
7221 // A new instance is created if there was a selector specified
7223 new _Api( __table_selector( selector
, this.context
) ) :
7228 _api_register( 'table()', function ( selector
) {
7229 var tables
= this.tables( selector
);
7230 var ctx
= tables
.context
;
7232 // Truncate to the first matched table
7234 new _Api( ctx
[0] ) :
7239 _api_registerPlural( 'tables().nodes()', 'table().node()' , function () {
7240 return this.iterator( 'table', function ( ctx
) {
7246 _api_registerPlural( 'tables().body()', 'table().body()' , function () {
7247 return this.iterator( 'table', function ( ctx
) {
7253 _api_registerPlural( 'tables().header()', 'table().header()' , function () {
7254 return this.iterator( 'table', function ( ctx
) {
7260 _api_registerPlural( 'tables().footer()', 'table().footer()' , function () {
7261 return this.iterator( 'table', function ( ctx
) {
7267 _api_registerPlural( 'tables().containers()', 'table().container()' , function () {
7268 return this.iterator( 'table', function ( ctx
) {
7269 return ctx
.nTableWrapper
;
7276 * Redraw the tables in the current context.
7278 * @param {boolean} [reset=true] Reset (default) or hold the current paging
7279 * position. A full re-sort and re-filter is performed when this method is
7280 * called, which is why the pagination reset is the default action.
7281 * @returns {DataTables.Api} this
7283 _api_register( 'draw()', function ( resetPaging
) {
7284 return this.iterator( 'table', function ( settings
) {
7285 _fnReDraw( settings
, resetPaging
===false );
7292 * Get the current page index.
7294 * @return {integer} Current page index (zero based)
7296 * Set the current page.
7298 * Note that if you attempt to show a page which does not exist, DataTables will
7299 * not throw an error, but rather reset the paging.
7301 * @param {integer|string} action The paging action to take. This can be one of:
7302 * * `integer` - The page index to jump to
7303 * * `string` - An action to take:
7304 * * `first` - Jump to first page.
7305 * * `next` - Jump to the next page
7306 * * `previous` - Jump to previous page
7307 * * `last` - Jump to the last page.
7308 * @returns {DataTables.Api} this
7310 _api_register( 'page()', function ( action
) {
7311 if ( action
=== undefined ) {
7312 return this.page
.info().page
; // not an expensive call
7315 // else, have an action to take on all tables
7316 return this.iterator( 'table', function ( settings
) {
7317 _fnPageChange( settings
, action
);
7323 * Paging information for the first table in the current context.
7325 * If you require paging information for another table, use the `table()` method
7326 * with a suitable selector.
7328 * @return {object} Object with the following properties set:
7329 * * `page` - Current page index (zero based - i.e. the first page is `0`)
7330 * * `pages` - Total number of pages
7331 * * `start` - Display index for the first record shown on the current page
7332 * * `end` - Display index for the last record shown on the current page
7333 * * `length` - Display length (number of records). Note that generally `start
7334 * + length = end`, but this is not always true, for example if there are
7335 * only 2 records to show on the final page, with a length of 10.
7336 * * `recordsTotal` - Full data set length
7337 * * `recordsDisplay` - Data set length once the current filtering criterion
7340 _api_register( 'page.info()', function ( action
) {
7341 if ( this.context
.length
=== 0 ) {
7346 settings
= this.context
[0],
7347 start
= settings
._iDisplayStart
,
7348 len
= settings
._iDisplayLength
,
7349 visRecords
= settings
.fnRecordsDisplay(),
7353 "page": all
? 0 : Math
.floor( start
/ len
),
7354 "pages": all
? 1 : Math
.ceil( visRecords
/ len
),
7356 "end": settings
.fnDisplayEnd(),
7358 "recordsTotal": settings
.fnRecordsTotal(),
7359 "recordsDisplay": visRecords
7365 * Get the current page length.
7367 * @return {integer} Current page length. Note `-1` indicates that all records
7370 * Set the current page length.
7372 * @param {integer} Page length to set. Use `-1` to show all records.
7373 * @returns {DataTables.Api} this
7375 _api_register( 'page.len()', function ( len
) {
7376 // Note that we can't call this function 'length()' because `length`
7377 // is a Javascript property of functions which defines how many arguments
7378 // the function expects.
7379 if ( len
=== undefined ) {
7380 return this.context
.length
!== 0 ?
7381 this.context
[0]._iDisplayLength
:
7385 // else, set the page length
7386 return this.iterator( 'table', function ( settings
) {
7387 _fnLengthChange( settings
, len
);
7393 var __reload = function ( settings
, holdPosition
, callback
) {
7394 // Use the draw event to trigger a callback
7396 var api
= new _Api( settings
);
7398 api
.one( 'draw', function () {
7399 callback( api
.ajax
.json() );
7403 if ( _fnDataSource( settings
) == 'ssp' ) {
7404 _fnReDraw( settings
, holdPosition
);
7408 _fnProcessingDisplay( settings
, true );
7410 _fnBuildAjax( settings
, [], function( json
) {
7411 _fnClearTable( settings
);
7413 var data
= _fnAjaxDataSrc( settings
, json
);
7414 for ( var i
=0, ien
=data
.length
; i
<ien
; i
++ ) {
7415 _fnAddData( settings
, data
[i
] );
7418 _fnReDraw( settings
, holdPosition
);
7419 _fnProcessingDisplay( settings
, false );
7426 * Get the JSON response from the last Ajax request that DataTables made to the
7427 * server. Note that this returns the JSON from the first table in the current
7430 * @return {object} JSON received from the server.
7432 _api_register( 'ajax.json()', function () {
7433 var ctx
= this.context
;
7435 if ( ctx
.length
> 0 ) {
7439 // else return undefined;
7444 * Get the data submitted in the last Ajax request
7446 _api_register( 'ajax.params()', function () {
7447 var ctx
= this.context
;
7449 if ( ctx
.length
> 0 ) {
7450 return ctx
[0].oAjaxData
;
7453 // else return undefined;
7458 * Reload tables from the Ajax data source. Note that this function will
7459 * automatically re-draw the table when the remote data has been loaded.
7461 * @param {boolean} [reset=true] Reset (default) or hold the current paging
7462 * position. A full re-sort and re-filter is performed when this method is
7463 * called, which is why the pagination reset is the default action.
7464 * @returns {DataTables.Api} this
7466 _api_register( 'ajax.reload()', function ( callback
, resetPaging
) {
7467 return this.iterator( 'table', function (settings
) {
7468 __reload( settings
, resetPaging
===false, callback
);
7474 * Get the current Ajax URL. Note that this returns the URL from the first
7475 * table in the current context.
7477 * @return {string} Current Ajax source URL
7479 * Set the Ajax URL. Note that this will set the URL for all tables in the
7482 * @param {string} url URL to set.
7483 * @returns {DataTables.Api} this
7485 _api_register( 'ajax.url()', function ( url
) {
7486 var ctx
= this.context
;
7488 if ( url
=== undefined ) {
7490 if ( ctx
.length
=== 0 ) {
7496 $.isPlainObject( ctx
.ajax
) ?
7503 return this.iterator( 'table', function ( settings
) {
7504 if ( $.isPlainObject( settings
.ajax
) ) {
7505 settings
.ajax
.url
= url
;
7508 settings
.ajax
= url
;
7510 // No need to consider sAjaxSource here since DataTables gives priority
7511 // to `ajax` over `sAjaxSource`. So setting `ajax` here, renders any
7512 // value of `sAjaxSource` redundant.
7518 * Load data from the newly set Ajax URL. Note that this method is only
7519 * available when `ajax.url()` is used to set a URL. Additionally, this method
7520 * has the same effect as calling `ajax.reload()` but is provided for
7521 * convenience when setting a new URL. Like `ajax.reload()` it will
7522 * automatically redraw the table once the remote data has been loaded.
7524 * @returns {DataTables.Api} this
7526 _api_register( 'ajax.url().load()', function ( callback
, resetPaging
) {
7527 // Same as a reload, but makes sense to present it for easy access after a
7529 return this.iterator( 'table', function ( ctx
) {
7530 __reload( ctx
, resetPaging
===false, callback
);
7537 var _selector_run = function ( type
, selector
, selectFn
, settings
, opts
)
7542 selectorType
= typeof selector
;
7544 // Can't just check for isArray here, as an API or jQuery instance might be
7545 // given with their array like look
7546 if ( ! selector
|| selectorType
=== 'string' || selectorType
=== 'function' || selector
.length
=== undefined ) {
7547 selector
= [ selector
];
7550 for ( i
=0, ien
=selector
.length
; i
<ien
; i
++ ) {
7551 a
= selector
[i
] && selector
[i
].split
?
7552 selector
[i
].split(',') :
7555 for ( j
=0, jen
=a
.length
; j
<jen
; j
++ ) {
7556 res
= selectFn( typeof a
[j
] === 'string' ? $.trim(a
[j
]) : a
[j
] );
7558 if ( res
&& res
.length
) {
7559 out
.push
.apply( out
, res
);
7564 // selector extensions
7565 var ext
= _ext
.selector
[ type
];
7567 for ( i
=0, ien
=ext
.length
; i
<ien
; i
++ ) {
7568 out
= ext
[i
]( settings
, opts
, out
);
7576 var _selector_opts = function ( opts
)
7582 // Backwards compatibility for 1.9- which used the terminology filter rather
7584 if ( opts
.filter
&& opts
.search
=== undefined ) {
7585 opts
.search
= opts
.filter
;
7596 var _selector_first = function ( inst
)
7598 // Reduce the API instance to the first item found
7599 for ( var i
=0, ien
=inst
.length
; i
<ien
; i
++ ) {
7600 if ( inst
[i
].length
> 0 ) {
7601 // Assign the first element to the first item in the instance
7602 // and truncate the instance and context
7606 inst
.context
= [ inst
.context
[i
] ];
7612 // Not found - return an empty instance
7618 var _selector_row_indexes = function ( settings
, opts
)
7622 displayFiltered
= settings
.aiDisplay
,
7623 displayMaster
= settings
.aiDisplayMaster
;
7626 search
= opts
.search
, // none, applied, removed
7627 order
= opts
.order
, // applied, current, index (original - compatibility with 1.9)
7628 page
= opts
.page
; // all, current
7630 if ( _fnDataSource( settings
) == 'ssp' ) {
7631 // In server-side processing mode, most options are irrelevant since
7632 // rows not shown don't exist and the index order is the applied order
7633 // Removed is a special case - for consistency just return an empty
7635 return search
=== 'removed' ?
7637 _range( 0, displayMaster
.length
);
7639 else if ( page
== 'current' ) {
7640 // Current page implies that order=current and fitler=applied, since it is
7641 // fairly senseless otherwise, regardless of what order and search actually
7643 for ( i
=settings
._iDisplayStart
, ien
=settings
.fnDisplayEnd() ; i
<ien
; i
++ ) {
7644 a
.push( displayFiltered
[i
] );
7647 else if ( order
== 'current' || order
== 'applied' ) {
7648 a
= search
== 'none' ?
7649 displayMaster
.slice() : // no search
7650 search
== 'applied' ?
7651 displayFiltered
.slice() : // applied search
7652 $.map( displayMaster
, function (el
, i
) { // removed search
7653 return $.inArray( el
, displayFiltered
) === -1 ? el
: null;
7656 else if ( order
== 'index' || order
== 'original' ) {
7657 for ( i
=0, ien
=settings
.aoData
.length
; i
<ien
; i
++ ) {
7658 if ( search
== 'none' ) {
7661 else { // applied | removed
7662 tmp
= $.inArray( i
, displayFiltered
);
7664 if ((tmp
=== -1 && search
== 'removed') ||
7665 (tmp
>= 0 && search
== 'applied') )
7677 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
7680 * {} - no selector - use all available rows
7681 * {integer} - row aoData index
7683 * {string} - jQuery selector to apply to the TR elements
7684 * {array} - jQuery array of nodes, or simply an array of TR nodes
7689 var __row_selector = function ( settings
, selector
, opts
)
7691 var run = function ( sel
) {
7692 var selInt
= _intVal( sel
);
7695 // Short cut - selector is a number and no options provided (default is
7696 // all records, so no need to check if the index is in there, since it
7697 // must be - dev error if the index doesn't exist).
7698 if ( selInt
!== null && ! opts
) {
7702 var rows
= _selector_row_indexes( settings
, opts
);
7704 if ( selInt
!== null && $.inArray( selInt
, rows
) !== -1 ) {
7705 // Selector - integer
7713 // Selector - function
7714 if ( typeof sel
=== 'function' ) {
7715 return $.map( rows
, function (idx
) {
7716 var row
= settings
.aoData
[ idx
];
7717 return sel( idx
, row
._aData
, row
.nTr
) ? idx
: null;
7721 // Get nodes in the order from the `rows` array with null values removed
7722 var nodes
= _removeEmpty(
7723 _pluck_order( settings
.aoData
, rows
, 'nTr' )
7727 if ( sel
.nodeName
) {
7728 if ( $.inArray( sel
, nodes
) !== -1 ) {
7729 return [ sel
._DT_RowIndex
]; // sel is a TR node that is in the table
7730 // and DataTables adds a prop for fast lookup
7734 // Selector - jQuery selector string, array of nodes or jQuery object/
7735 // As jQuery's .filter() allows jQuery objects to be passed in filter,
7736 // it also allows arrays, so this will cope with all three options
7740 return this._DT_RowIndex
;
7745 return _selector_run( 'row', selector
, run
, settings
, opts
);
7749 _api_register( 'rows()', function ( selector
, opts
) {
7750 // argument shifting
7751 if ( selector
=== undefined ) {
7754 else if ( $.isPlainObject( selector
) ) {
7759 opts
= _selector_opts( opts
);
7761 var inst
= this.iterator( 'table', function ( settings
) {
7762 return __row_selector( settings
, selector
, opts
);
7765 // Want argument shifting here and in __row_selector?
7766 inst
.selector
.rows
= selector
;
7767 inst
.selector
.opts
= opts
;
7772 _api_register( 'rows().nodes()', function () {
7773 return this.iterator( 'row', function ( settings
, row
) {
7774 return settings
.aoData
[ row
].nTr
|| undefined;
7778 _api_register( 'rows().data()', function () {
7779 return this.iterator( true, 'rows', function ( settings
, rows
) {
7780 return _pluck_order( settings
.aoData
, rows
, '_aData' );
7784 _api_registerPlural( 'rows().cache()', 'row().cache()', function ( type
) {
7785 return this.iterator( 'row', function ( settings
, row
) {
7786 var r
= settings
.aoData
[ row
];
7787 return type
=== 'search' ? r
._aFilterData
: r
._aSortData
;
7791 _api_registerPlural( 'rows().invalidate()', 'row().invalidate()', function ( src
) {
7792 return this.iterator( 'row', function ( settings
, row
) {
7793 _fnInvalidate( settings
, row
, src
);
7797 _api_registerPlural( 'rows().indexes()', 'row().index()', function () {
7798 return this.iterator( 'row', function ( settings
, row
) {
7803 _api_registerPlural( 'rows().remove()', 'row().remove()', function () {
7806 return this.iterator( 'row', function ( settings
, row
, thatIdx
) {
7807 var data
= settings
.aoData
;
7809 data
.splice( row
, 1 );
7811 // Update the _DT_RowIndex parameter on all rows in the table
7812 for ( var i
=0, ien
=data
.length
; i
<ien
; i
++ ) {
7813 if ( data
[i
].nTr
!== null ) {
7814 data
[i
].nTr
._DT_RowIndex
= i
;
7818 // Remove the target row from the search array
7819 var displayIndex
= $.inArray( row
, settings
.aiDisplay
);
7821 // Delete from the display arrays
7822 _fnDeleteIndex( settings
.aiDisplayMaster
, row
);
7823 _fnDeleteIndex( settings
.aiDisplay
, row
);
7824 _fnDeleteIndex( that
[ thatIdx
], row
, false ); // maintain local indexes
7826 // Check for an 'overflow' they case for displaying the table
7827 _fnLengthOverflow( settings
);
7832 _api_register( 'rows.add()', function ( rows
) {
7833 var newRows
= this.iterator( 'table', function ( settings
) {
7837 for ( i
=0, ien
=rows
.length
; i
<ien
; i
++ ) {
7840 if ( row
.nodeName
&& row
.nodeName
.toUpperCase() === 'TR' ) {
7841 out
.push( _fnAddTr( settings
, row
)[0] );
7844 out
.push( _fnAddData( settings
, row
) );
7851 // Return an Api.rows() extended instance, so rows().nodes() etc can be used
7852 var modRows
= this.rows( -1 );
7854 modRows
.push
.apply( modRows
, newRows
.toArray() );
7866 _api_register( 'row()', function ( selector
, opts
) {
7867 return _selector_first( this.rows( selector
, opts
) );
7871 _api_register( 'row().data()', function ( data
) {
7872 var ctx
= this.context
;
7874 if ( data
=== undefined ) {
7876 return ctx
.length
&& this.length
?
7877 ctx
[0].aoData
[ this[0] ]._aData
:
7882 ctx
[0].aoData
[ this[0] ]._aData
= data
;
7884 // Automatically invalidate
7885 _fnInvalidate( ctx
[0], this[0], 'data' );
7891 _api_register( 'row().node()', function () {
7892 var ctx
= this.context
;
7894 return ctx
.length
&& this.length
?
7895 ctx
[0].aoData
[ this[0] ].nTr
|| null :
7900 _api_register( 'row.add()', function ( row
) {
7901 // Allow a jQuery object to be passed in - only a single row is added from
7902 // it though - the first element in the set
7903 if ( row
instanceof $ && row
.length
) {
7907 var rows
= this.iterator( 'table', function ( settings
) {
7908 if ( row
.nodeName
&& row
.nodeName
.toUpperCase() === 'TR' ) {
7909 return _fnAddTr( settings
, row
)[0];
7911 return _fnAddData( settings
, row
);
7914 // Return an Api.rows() extended instance, with the newly added row selected
7915 return this.row( rows
[0] );
7920 var __details_add = function ( ctx
, row
, data
, klass
)
7922 // Convert to array of TR elements
7924 var addRow = function ( r
, k
) {
7925 // Recursion to allow for arrays of jQuery objects
7926 if ( $.isArray( r
) || r
instanceof $ ) {
7927 for ( var i
=0, ien
=r
.length
; i
<ien
; i
++ ) {
7933 // If we get a TR element, then just add it directly - up to the dev
7934 // to add the correct number of columns etc
7935 if ( r
.nodeName
&& r
.nodeName
.toLowerCase() === 'tr' ) {
7939 // Otherwise create a row with a wrapper
7940 var created
= $('<tr><td/></tr>').addClass( k
);
7944 [0].colSpan
= _fnVisbleColumns( ctx
);
7946 rows
.push( created
[0] );
7950 addRow( data
, klass
);
7952 if ( row
._details
) {
7953 row
._details
.remove();
7956 row
._details
= $(rows
);
7958 // If the children were already shown, that state should be retained
7959 if ( row
._detailsShow
) {
7960 row
._details
.insertAfter( row
.nTr
);
7965 var __details_remove = function ( api
, idx
)
7967 var ctx
= api
.context
;
7970 var row
= ctx
[0].aoData
[ idx
!== undefined ? idx
: api
[0] ];
7972 if ( row
._details
) {
7973 row
._details
.remove();
7975 row
._detailsShow
= undefined;
7976 row
._details
= undefined;
7982 var __details_display = function ( api
, show
) {
7983 var ctx
= api
.context
;
7985 if ( ctx
.length
&& api
.length
) {
7986 var row
= ctx
[0].aoData
[ api
[0] ];
7988 if ( row
._details
) {
7989 row
._detailsShow
= show
;
7992 row
._details
.insertAfter( row
.nTr
);
7995 row
._details
.detach();
7998 __details_events( ctx
[0] );
8004 var __details_events = function ( settings
)
8006 var api
= new _Api( settings
);
8007 var namespace = '.dt.DT_details';
8008 var drawEvent
= 'draw'+namespace;
8009 var colvisEvent
= 'column-visibility'+namespace;
8010 var destroyEvent
= 'destroy'+namespace;
8011 var data
= settings
.aoData
;
8013 api
.off( drawEvent
+' '+ colvisEvent
+' '+ destroyEvent
);
8015 if ( _pluck( data
, '_details' ).length
> 0 ) {
8016 // On each draw, insert the required elements into the document
8017 api
.on( drawEvent
, function ( e
, ctx
) {
8018 if ( settings
!== ctx
) {
8022 api
.rows( {page
:'current'} ).eq(0).each( function (idx
) {
8023 // Internal data grab
8024 var row
= data
[ idx
];
8026 if ( row
._detailsShow
) {
8027 row
._details
.insertAfter( row
.nTr
);
8032 // Column visibility change - update the colspan
8033 api
.on( colvisEvent
, function ( e
, ctx
, idx
, vis
) {
8034 if ( settings
!== ctx
) {
8038 // Update the colspan for the details rows (note, only if it already has
8040 var row
, visible
= _fnVisbleColumns( ctx
);
8042 for ( var i
=0, ien
=data
.length
; i
<ien
; i
++ ) {
8045 if ( row
._details
) {
8046 row
._details
.children('td[colspan]').attr('colspan', visible
);
8051 // Table destroyed - nuke any child rows
8052 api
.on( destroyEvent
, function ( e
, ctx
) {
8053 if ( settings
!== ctx
) {
8057 for ( var i
=0, ien
=data
.length
; i
<ien
; i
++ ) {
8058 if ( data
[i
]._details
) {
8059 __details_remove( api
, i
);
8066 // Strings for the method names to help minification
8068 var _child_obj
= _emp
+'row().child';
8069 var _child_mth
= _child_obj
+'()';
8074 // jQuery or array of any of the above
8075 _api_register( _child_mth
, function ( data
, klass
) {
8076 var ctx
= this.context
;
8078 if ( data
=== undefined ) {
8080 return ctx
.length
&& this.length
?
8081 ctx
[0].aoData
[ this[0] ]._details
:
8084 else if ( data
=== true ) {
8088 else if ( data
=== false ) {
8090 __details_remove( this );
8092 else if ( ctx
.length
&& this.length
) {
8094 __details_add( ctx
[0], ctx
[0].aoData
[ this[0] ], data
, klass
);
8102 _child_obj
+'.show()',
8103 _child_mth
+'.show()' // only when `child()` was called with parameters (without
8104 ], function ( show
) { // it returns an object and this method is not executed)
8105 __details_display( this, true );
8111 _child_obj
+'.hide()',
8112 _child_mth
+'.hide()' // only when `child()` was called with parameters (without
8113 ], function () { // it returns an object and this method is not executed)
8114 __details_display( this, false );
8120 _child_obj
+'.remove()',
8121 _child_mth
+'.remove()' // only when `child()` was called with parameters (without
8122 ], function () { // it returns an object and this method is not executed)
8123 __details_remove( this );
8128 _api_register( _child_obj
+'.isShown()', function () {
8129 var ctx
= this.context
;
8131 if ( ctx
.length
&& this.length
) {
8132 // _detailsShown as false or undefined will fall through to return false
8133 return ctx
[0].aoData
[ this[0] ]._detailsShow
|| false;
8140 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
8143 * {integer} - column index (>=0 count from left, <0 count from right)
8144 * "{integer}:visIdx" - visible column index (i.e. translate to column index) (>=0 count from left, <0 count from right)
8145 * "{integer}:visible" - alias for {integer}:visIdx (>=0 count from left, <0 count from right)
8146 * "{string}:name" - column name
8147 * "{string}" - jQuery selector on column header nodes
8151 // can be an array of these items, comma separated list, or an array of comma
8154 var __re_column_selector
= /^(.+):(name|visIdx|visible)$/;
8157 // r1 and r2 are redundant - but it means that the parameters match for the
8158 // iterator callback in columns().data()
8159 var __columnData = function ( settings
, column
, r1
, r2
, rows
) {
8161 for ( var row
=0, ien
=rows
.length
; row
<ien
; row
++ ) {
8162 a
.push( _fnGetCellData( settings
, rows
[row
], column
) );
8168 var __column_selector = function ( settings
, selector
, opts
)
8171 columns
= settings
.aoColumns
,
8172 names
= _pluck( columns
, 'sName' ),
8173 nodes
= _pluck( columns
, 'nTh' );
8175 var run = function ( s
) {
8176 var selInt
= _intVal( s
);
8180 return _range( columns
.length
);
8184 if ( selInt
!== null ) {
8185 return [ selInt
>= 0 ?
8186 selInt
: // Count from left
8187 columns
.length
+ selInt
// Count from right (+ because its a negative value)
8191 // Selector = function
8192 if ( typeof s
=== 'function' ) {
8193 var rows
= _selector_row_indexes( settings
, opts
);
8195 return $.map( columns
, function (col
, idx
) {
8198 __columnData( settings
, idx
, 0, 0, rows
),
8204 // jQuery or string selector
8205 var match
= typeof s
=== 'string' ?
8206 s
.match( __re_column_selector
) :
8210 switch( match
[2] ) {
8213 var idx
= parseInt( match
[1], 10 );
8214 // Visible index given, convert to column index
8216 // Counting from the right
8217 var visColumns
= $.map( columns
, function (col
,i
) {
8218 return col
.bVisible
? i
: null;
8220 return [ visColumns
[ visColumns
.length
+ idx
] ];
8222 // Counting from the left
8223 return [ _fnVisibleToColumnIndex( settings
, idx
) ];
8226 // match by name. `names` is column index complete and in order
8227 return $.map( names
, function (name
, i
) {
8228 return name
=== match
[1] ? i
: null;
8233 // jQuery selector on the TH elements for the columns
8237 return $.inArray( this, nodes
); // `nodes` is column index complete and in order
8243 return _selector_run( 'column', selector
, run
, settings
, opts
);
8247 var __setColumnVis = function ( settings
, column
, vis
, recalc
) {
8249 cols
= settings
.aoColumns
,
8250 col
= cols
[ column
],
8251 data
= settings
.aoData
,
8252 row
, cells
, i
, ien
, tr
;
8255 if ( vis
=== undefined ) {
8256 return col
.bVisible
;
8261 if ( col
.bVisible
=== vis
) {
8267 // Need to decide if we should use appendChild or insertBefore
8268 var insertBefore
= $.inArray( true, _pluck(cols
, 'bVisible'), column
+1 );
8270 for ( i
=0, ien
=data
.length
; i
<ien
; i
++ ) {
8272 cells
= data
[i
].anCells
;
8275 // insertBefore can act like appendChild if 2nd arg is null
8276 tr
.insertBefore( cells
[ column
], cells
[ insertBefore
] || null );
8282 $( _pluck( settings
.aoData
, 'anCells', column
) ).detach();
8287 _fnDrawHead( settings
, settings
.aoHeader
);
8288 _fnDrawHead( settings
, settings
.aoFooter
);
8290 if ( recalc
=== undefined || recalc
) {
8291 // Automatically adjust column sizing
8292 _fnAdjustColumnSizing( settings
);
8294 // Realign columns for scrolling
8295 if ( settings
.oScroll
.sX
|| settings
.oScroll
.sY
) {
8296 _fnScrollDraw( settings
);
8300 _fnCallbackFire( settings
, null, 'column-visibility', [settings
, column
, vis
] );
8302 _fnSaveState( settings
);
8306 _api_register( 'columns()', function ( selector
, opts
) {
8307 // argument shifting
8308 if ( selector
=== undefined ) {
8311 else if ( $.isPlainObject( selector
) ) {
8316 opts
= _selector_opts( opts
);
8318 var inst
= this.iterator( 'table', function ( settings
) {
8319 return __column_selector( settings
, selector
, opts
);
8322 // Want argument shifting here and in _row_selector?
8323 inst
.selector
.cols
= selector
;
8324 inst
.selector
.opts
= opts
;
8329 _api_registerPlural( 'columns().header()', 'column().header()', function ( selector
, opts
) {
8330 return this.iterator( 'column', function ( settings
, column
) {
8331 return settings
.aoColumns
[column
].nTh
;
8335 _api_registerPlural( 'columns().footer()', 'column().footer()', function ( selector
, opts
) {
8336 return this.iterator( 'column', function ( settings
, column
) {
8337 return settings
.aoColumns
[column
].nTf
;
8341 _api_registerPlural( 'columns().data()', 'column().data()', function () {
8342 return this.iterator( 'column-rows', __columnData
, 1 );
8345 _api_registerPlural( 'columns().dataSrc()', 'column().dataSrc()', function () {
8346 return this.iterator( 'column', function ( settings
, column
) {
8347 return settings
.aoColumns
[column
].mData
;
8351 _api_registerPlural( 'columns().cache()', 'column().cache()', function ( type
) {
8352 return this.iterator( 'column-rows', function ( settings
, column
, i
, j
, rows
) {
8353 return _pluck_order( settings
.aoData
, rows
,
8354 type
=== 'search' ? '_aFilterData' : '_aSortData', column
8359 _api_registerPlural( 'columns().nodes()', 'column().nodes()', function () {
8360 return this.iterator( 'column-rows', function ( settings
, column
, i
, j
, rows
) {
8361 return _pluck_order( settings
.aoData
, rows
, 'anCells', column
) ;
8365 _api_registerPlural( 'columns().visible()', 'column().visible()', function ( vis
, calc
) {
8366 return this.iterator( 'column', function ( settings
, column
) {
8367 if ( vis
=== undefined ) {
8368 return settings
.aoColumns
[ column
].bVisible
;
8370 __setColumnVis( settings
, column
, vis
, calc
);
8374 _api_registerPlural( 'columns().indexes()', 'column().index()', function ( type
) {
8375 return this.iterator( 'column', function ( settings
, column
) {
8376 return type
=== 'visible' ?
8377 _fnColumnIndexToVisible( settings
, column
) :
8382 _api_register( 'columns.adjust()', function () {
8383 return this.iterator( 'table', function ( settings
) {
8384 _fnAdjustColumnSizing( settings
);
8388 _api_register( 'column.index()', function ( type
, idx
) {
8389 if ( this.context
.length
!== 0 ) {
8390 var ctx
= this.context
[0];
8392 if ( type
=== 'fromVisible' || type
=== 'toData' ) {
8393 return _fnVisibleToColumnIndex( ctx
, idx
);
8395 else if ( type
=== 'fromData' || type
=== 'toVisible' ) {
8396 return _fnColumnIndexToVisible( ctx
, idx
);
8401 _api_register( 'column()', function ( selector
, opts
) {
8402 return _selector_first( this.columns( selector
, opts
) );
8408 var __cell_selector = function ( settings
, selector
, opts
)
8410 var data
= settings
.aoData
;
8411 var rows
= _selector_row_indexes( settings
, opts
);
8412 var cells
= _removeEmpty( _pluck_order( data
, rows
, 'anCells' ) );
8413 var allCells
= $( [].concat
.apply([], cells
) );
8415 var columns
= settings
.aoColumns
.length
;
8416 var a
, i
, ien
, j
, o
, host
;
8418 var run = function ( s
) {
8419 var fnSelector
= typeof s
=== 'function';
8421 if ( s
=== null || s
=== undefined || fnSelector
) {
8422 // All cells and function selectors
8425 for ( i
=0, ien
=rows
.length
; i
<ien
; i
++ ) {
8428 for ( j
=0 ; j
<columns
; j
++ ) {
8435 // Selector - function
8436 host
= settings
.aoData
[ row
];
8438 if ( s( o
, _fnGetCellData(settings
, row
, j
), host
.anCells
? host
.anCells
[j
] : null ) ) {
8453 if ( $.isPlainObject( s
) ) {
8457 // Selector - jQuery filtered cells
8460 .map( function (i
, el
) {
8461 row
= el
.parentNode
._DT_RowIndex
;
8465 column
: $.inArray( el
, data
[ row
].anCells
)
8471 return _selector_run( 'cell', selector
, run
, settings
, opts
);
8477 _api_register( 'cells()', function ( rowSelector
, columnSelector
, opts
) {
8478 // Argument shifting
8479 if ( $.isPlainObject( rowSelector
) ) {
8481 if ( rowSelector
.row
=== undefined ) {
8482 // Selector options in first parameter
8487 // Cell index objects in first parameter
8488 opts
= columnSelector
;
8489 columnSelector
= null;
8492 if ( $.isPlainObject( columnSelector
) ) {
8493 opts
= columnSelector
;
8494 columnSelector
= null;
8498 if ( columnSelector
=== null || columnSelector
=== undefined ) {
8499 return this.iterator( 'table', function ( settings
) {
8500 return __cell_selector( settings
, rowSelector
, _selector_opts( opts
) );
8504 // Row + column selector
8505 var columns
= this.columns( columnSelector
, opts
);
8506 var rows
= this.rows( rowSelector
, opts
);
8507 var a
, i
, ien
, j
, jen
;
8509 var cells
= this.iterator( 'table', function ( settings
, idx
) {
8512 for ( i
=0, ien
=rows
[idx
].length
; i
<ien
; i
++ ) {
8513 for ( j
=0, jen
=columns
[idx
].length
; j
<jen
; j
++ ) {
8516 column
: columns
[idx
][j
]
8524 $.extend( cells
.selector
, {
8525 cols
: columnSelector
,
8534 _api_registerPlural( 'cells().nodes()', 'cell().node()', function () {
8535 return this.iterator( 'cell', function ( settings
, row
, column
) {
8536 var cells
= settings
.aoData
[ row
].anCells
;
8544 _api_register( 'cells().data()', function () {
8545 return this.iterator( 'cell', function ( settings
, row
, column
) {
8546 return _fnGetCellData( settings
, row
, column
);
8551 _api_registerPlural( 'cells().cache()', 'cell().cache()', function ( type
) {
8552 type
= type
=== 'search' ? '_aFilterData' : '_aSortData';
8554 return this.iterator( 'cell', function ( settings
, row
, column
) {
8555 return settings
.aoData
[ row
][ type
][ column
];
8560 _api_registerPlural( 'cells().render()', 'cell().render()', function ( type
) {
8561 return this.iterator( 'cell', function ( settings
, row
, column
) {
8562 return _fnGetCellData( settings
, row
, column
, type
);
8567 _api_registerPlural( 'cells().indexes()', 'cell().index()', function () {
8568 return this.iterator( 'cell', function ( settings
, row
, column
) {
8572 columnVisible
: _fnColumnIndexToVisible( settings
, column
)
8578 _api_registerPlural( 'cells().invalidate()', 'cell().invalidate()', function ( src
) {
8579 return this.iterator( 'cell', function ( settings
, row
, column
) {
8580 _fnInvalidate( settings
, row
, src
, column
);
8586 _api_register( 'cell()', function ( rowSelector
, columnSelector
, opts
) {
8587 return _selector_first( this.cells( rowSelector
, columnSelector
, opts
) );
8591 _api_register( 'cell().data()', function ( data
) {
8592 var ctx
= this.context
;
8595 if ( data
=== undefined ) {
8597 return ctx
.length
&& cell
.length
?
8598 _fnGetCellData( ctx
[0], cell
[0].row
, cell
[0].column
) :
8603 _fnSetCellData( ctx
[0], cell
[0].row
, cell
[0].column
, data
);
8604 _fnInvalidate( ctx
[0], cell
[0].row
, 'data', cell
[0].column
);
8612 * Get current ordering (sorting) that has been applied to the table.
8614 * @returns {array} 2D array containing the sorting information for the first
8615 * table in the current context. Each element in the parent array represents
8616 * a column being sorted upon (i.e. multi-sorting with two columns would have
8617 * 2 inner arrays). The inner arrays may have 2 or 3 elements. The first is
8618 * the column index that the sorting condition applies to, the second is the
8619 * direction of the sort (`desc` or `asc`) and, optionally, the third is the
8620 * index of the sorting order from the `column.sorting` initialisation array.
8622 * Set the ordering for the table.
8624 * @param {integer} order Column index to sort upon.
8625 * @param {string} direction Direction of the sort to be applied (`asc` or `desc`)
8626 * @returns {DataTables.Api} this
8628 * Set the ordering for the table.
8630 * @param {array} order 1D array of sorting information to be applied.
8631 * @param {array} [...] Optional additional sorting conditions
8632 * @returns {DataTables.Api} this
8634 * Set the ordering for the table.
8636 * @param {array} order 2D array of sorting information to be applied.
8637 * @returns {DataTables.Api} this
8639 _api_register( 'order()', function ( order
, dir
) {
8640 var ctx
= this.context
;
8642 if ( order
=== undefined ) {
8644 return ctx
.length
!== 0 ?
8650 if ( typeof order
=== 'number' ) {
8651 // Simple column / direction passed in
8652 order
= [ [ order
, dir
] ];
8654 else if ( ! $.isArray( order
[0] ) ) {
8655 // Arguments passed in (list of 1D arrays)
8656 order
= Array
.prototype.slice
.call( arguments
);
8658 // otherwise a 2D array was passed in
8660 return this.iterator( 'table', function ( settings
) {
8661 settings
.aaSorting
= order
.slice();
8667 * Attach a sort listener to an element for a given column
8669 * @param {node|jQuery|string} node Identifier for the element(s) to attach the
8670 * listener to. This can take the form of a single DOM node, a jQuery
8671 * collection of nodes or a jQuery selector which will identify the node(s).
8672 * @param {integer} column the column that a click on this node will sort on
8673 * @param {function} [callback] callback function when sort is run
8674 * @returns {DataTables.Api} this
8676 _api_register( 'order.listener()', function ( node
, column
, callback
) {
8677 return this.iterator( 'table', function ( settings
) {
8678 _fnSortAttachListener( settings
, node
, column
, callback
);
8683 // Order by the selected column(s)
8685 'columns().order()',
8687 ], function ( dir
) {
8690 return this.iterator( 'table', function ( settings
, i
) {
8693 $.each( that
[i
], function (j
, col
) {
8694 sort
.push( [ col
, dir
] );
8697 settings
.aaSorting
= sort
;
8703 _api_register( 'search()', function ( input
, regex
, smart
, caseInsen
) {
8704 var ctx
= this.context
;
8706 if ( input
=== undefined ) {
8708 return ctx
.length
!== 0 ?
8709 ctx
[0].oPreviousSearch
.sSearch
:
8714 return this.iterator( 'table', function ( settings
) {
8715 if ( ! settings
.oFeatures
.bFilter
) {
8719 _fnFilterComplete( settings
, $.extend( {}, settings
.oPreviousSearch
, {
8720 "sSearch": input
+"",
8721 "bRegex": regex
=== null ? false : regex
,
8722 "bSmart": smart
=== null ? true : smart
,
8723 "bCaseInsensitive": caseInsen
=== null ? true : caseInsen
8729 _api_registerPlural(
8730 'columns().search()',
8731 'column().search()',
8732 function ( input
, regex
, smart
, caseInsen
) {
8733 return this.iterator( 'column', function ( settings
, column
) {
8734 var preSearch
= settings
.aoPreSearchCols
;
8736 if ( input
=== undefined ) {
8738 return preSearch
[ column
].sSearch
;
8742 if ( ! settings
.oFeatures
.bFilter
) {
8746 $.extend( preSearch
[ column
], {
8747 "sSearch": input
+"",
8748 "bRegex": regex
=== null ? false : regex
,
8749 "bSmart": smart
=== null ? true : smart
,
8750 "bCaseInsensitive": caseInsen
=== null ? true : caseInsen
8753 _fnFilterComplete( settings
, settings
.oPreviousSearch
, 1 );
8762 _api_register( 'state()', function () {
8763 return this.context
.length
?
8764 this.context
[0].oSavedState
:
8769 _api_register( 'state.clear()', function () {
8770 return this.iterator( 'table', function ( settings
) {
8771 // Save an empty object
8772 settings
.fnStateSaveCallback
.call( settings
.oInstance
, settings
, {} );
8777 _api_register( 'state.loaded()', function () {
8778 return this.context
.length
?
8779 this.context
[0].oLoadedState
:
8784 _api_register( 'state.save()', function () {
8785 return this.iterator( 'table', function ( settings
) {
8786 _fnSaveState( settings
);
8793 * Provide a common method for plug-ins to check the version of DataTables being
8794 * used, in order to ensure compatibility.
8796 * @param {string} version Version string to check for, in the format "X.Y.Z".
8797 * Note that the formats "X" and "X.Y" are also acceptable.
8798 * @returns {boolean} true if this version of DataTables is greater or equal to
8799 * the required version, or false if this version of DataTales is not
8805 * alert( $.fn.dataTable.versionCheck( '1.9.0' ) );
8807 DataTable
.versionCheck
= DataTable
.fnVersionCheck = function( version
)
8809 var aThis
= DataTable
.version
.split('.');
8810 var aThat
= version
.split('.');
8813 for ( var i
=0, iLen
=aThat
.length
; i
<iLen
; i
++ ) {
8814 iThis
= parseInt( aThis
[i
], 10 ) || 0;
8815 iThat
= parseInt( aThat
[i
], 10 ) || 0;
8817 // Parts are the same, keep comparing
8818 if (iThis
=== iThat
) {
8822 // Parts are different, return immediately
8823 return iThis
> iThat
;
8831 * Check if a `<table>` node is a DataTable table already or not.
8833 * @param {node|jquery|string} table Table node, jQuery object or jQuery
8834 * selector for the table to test. Note that if more than more than one
8835 * table is passed on, only the first will be checked
8836 * @returns {boolean} true the table given is a DataTable, or false otherwise
8841 * if ( ! $.fn.DataTable.isDataTable( '#example' ) ) {
8842 * $('#example').dataTable();
8845 DataTable
.isDataTable
= DataTable
.fnIsDataTable = function ( table
)
8847 var t
= $(table
).get(0);
8850 $.each( DataTable
.settings
, function (i
, o
) {
8851 var head
= o
.nScrollHead
? $('table', o
.nScrollHead
)[0] : null;
8852 var foot
= o
.nScrollFoot
? $('table', o
.nScrollFoot
)[0] : null;
8854 if ( o
.nTable
=== t
|| head
=== t
|| foot
=== t
) {
8864 * Get all DataTable tables that have been initialised - optionally you can
8865 * select to get only currently visible tables.
8867 * @param {boolean} [visible=false] Flag to indicate if you want all (default)
8868 * or visible tables only.
8869 * @returns {array} Array of `table` nodes (not DataTable instances) which are
8875 * $.each( $.fn.dataTable.tables(true), function () {
8876 * $(table).DataTable().columns.adjust();
8879 DataTable
.tables
= DataTable
.fnTables = function ( visible
)
8881 return $.map( DataTable
.settings
, function (o
) {
8882 if ( !visible
|| (visible
&& $(o
.nTable
).is(':visible')) ) {
8890 * DataTables utility methods
8892 * This namespace provides helper methods that DataTables uses internally to
8893 * create a DataTable, but which are not exclusively used only for DataTables.
8894 * These methods can be used by extension authors to save the duplication of
8901 * Throttle the calls to a function. Arguments and context are maintained
8902 * for the throttled function.
8904 * @param {function} fn Function to be called
8905 * @param {integer} freq Call frequency in mS
8906 * @return {function} Wrapped function
8908 throttle
: _fnThrottle
,
8912 * Escape a string such that it can be used in a regular expression
8914 * @param {string} sVal string to escape
8915 * @returns {string} escaped string
8917 escapeRegex
: _fnEscapeRegex
8922 * Convert from camel case parameters to Hungarian notation. This is made public
8923 * for the extensions to provide the same ability as DataTables core to accept
8924 * either the 1.9 style Hungarian notation, or the 1.10+ style camelCase
8927 * @param {object} src The model object which holds all parameters that can be
8929 * @param {object} user The object to convert from camel case to Hungarian.
8930 * @param {boolean} force When set to `true`, properties which already have a
8931 * Hungarian value in the `user` object will be overwritten. Otherwise they
8934 DataTable
.camelToHungarian
= _fnCamelToHungarian
;
8941 _api_register( '$()', function ( selector
, opts
) {
8943 rows
= this.rows( opts
).nodes(), // Get all rows
8946 return $( [].concat(
8947 jqRows
.filter( selector
).toArray(),
8948 jqRows
.find( selector
).toArray()
8953 // jQuery functions to operate on the tables
8954 $.each( [ 'on', 'one', 'off' ], function (i
, key
) {
8955 _api_register( key
+'()', function ( /* event, handler */ ) {
8956 var args
= Array
.prototype.slice
.call(arguments
);
8958 // Add the `dt` namespace automatically if it isn't already present
8959 if ( ! args
[0].match(/\.dt\b/) ) {
8963 var inst
= $( this.tables().nodes() );
8964 inst
[key
].apply( inst
, args
);
8970 _api_register( 'clear()', function () {
8971 return this.iterator( 'table', function ( settings
) {
8972 _fnClearTable( settings
);
8977 _api_register( 'settings()', function () {
8978 return new _Api( this.context
, this.context
);
8982 _api_register( 'init()', function () {
8983 var ctx
= this.context
;
8984 return ctx
.length
? ctx
[0].oInit
: null;
8988 _api_register( 'data()', function () {
8989 return this.iterator( 'table', function ( settings
) {
8990 return _pluck( settings
.aoData
, '_aData' );
8995 _api_register( 'destroy()', function ( remove
) {
8996 remove
= remove
|| false;
8998 return this.iterator( 'table', function ( settings
) {
8999 var orig
= settings
.nTableWrapper
.parentNode
;
9000 var classes
= settings
.oClasses
;
9001 var table
= settings
.nTable
;
9002 var tbody
= settings
.nTBody
;
9003 var thead
= settings
.nTHead
;
9004 var tfoot
= settings
.nTFoot
;
9005 var jqTable
= $(table
);
9006 var jqTbody
= $(tbody
);
9007 var jqWrapper
= $(settings
.nTableWrapper
);
9008 var rows
= $.map( settings
.aoData
, function (r
) { return r
.nTr
; } );
9011 // Flag to note that the table is currently being destroyed - no action
9013 settings
.bDestroying
= true;
9015 // Fire off the destroy callbacks for plug-ins etc
9016 _fnCallbackFire( settings
, "aoDestroyCallback", "destroy", [settings
] );
9018 // If not being removed from the document, make all columns visible
9020 new _Api( settings
).columns().visible( true );
9023 // Blitz all `DT` namespaced events (these are internal events, the
9024 // lowercase, `dt` events are user subscribed and they are responsible
9025 // for removing them
9026 jqWrapper
.unbind('.DT').find(':not(tbody *)').unbind('.DT');
9027 $(window
).unbind('.DT-'+settings
.sInstance
);
9029 // When scrolling we had to break the table up - restore it
9030 if ( table
!= thead
.parentNode
) {
9031 jqTable
.children('thead').detach();
9032 jqTable
.append( thead
);
9035 if ( tfoot
&& table
!= tfoot
.parentNode
) {
9036 jqTable
.children('tfoot').detach();
9037 jqTable
.append( tfoot
);
9040 // Remove the DataTables generated nodes, events and classes
9044 settings
.aaSorting
= [];
9045 settings
.aaSortingFixed
= [];
9046 _fnSortingClasses( settings
);
9048 $( rows
).removeClass( settings
.asStripeClasses
.join(' ') );
9050 $('th, td', thead
).removeClass( classes
.sSortable
+' '+
9051 classes
.sSortableAsc
+' '+classes
.sSortableDesc
+' '+classes
.sSortableNone
9054 if ( settings
.bJUI
) {
9055 $('th span.'+classes
.sSortIcon
+ ', td span.'+classes
.sSortIcon
, thead
).detach();
9056 $('th, td', thead
).each( function () {
9057 var wrapper
= $('div.'+classes
.sSortJUIWrapper
, this);
9058 $(this).append( wrapper
.contents() );
9063 if ( ! remove
&& orig
) {
9064 // insertBefore acts like appendChild if !arg[1]
9065 orig
.insertBefore( table
, settings
.nTableReinsertBefore
);
9068 // Add the TR elements back into the table in their original order
9069 jqTbody
.children().detach();
9070 jqTbody
.append( rows
);
9072 // Restore the width of the original table - was read from the style property,
9073 // so we can restore directly to that
9075 .css( 'width', settings
.sDestroyWidth
)
9076 .removeClass( classes
.sTable
);
9078 // If the were originally stripe classes - then we add them back here.
9079 // Note this is not fool proof (for example if not all rows had stripe
9080 // classes - but it's a good effort without getting carried away
9081 ien
= settings
.asDestroyStripes
.length
;
9084 jqTbody
.children().each( function (i
) {
9085 $(this).addClass( settings
.asDestroyStripes
[i
% ien
] );
9089 /* Remove the settings object from the settings array */
9090 var idx
= $.inArray( settings
, DataTable
.settings
);
9092 DataTable
.settings
.splice( idx
, 1 );
9098 // Add the `every()` method for rows, columns and cells in a compact form
9099 $.each( [ 'column', 'row', 'cell' ], function ( i
, type
) {
9100 _api_register( type
+'s().every()', function ( fn
) {
9101 return this.iterator( type
, function ( settings
, idx
, idx2
) {
9102 // idx2 is undefined for rows and columns.
9103 fn
.call( new _Api( settings
)[ type
]( idx
, idx2
) );
9109 // i18n method for extensions to be able to use the language object from the
9111 _api_register( 'i18n()', function ( token
, def
, plural
) {
9112 var ctx
= this.context
[0];
9113 var resolved
= _fnGetObjectDataFn( token
)( ctx
.oLanguage
);
9115 if ( resolved
=== undefined ) {
9119 if ( plural
!== undefined && $.isPlainObject( resolved
) ) {
9120 resolved
= resolved
[ plural
] !== undefined ?
9121 resolved
[ plural
] :
9125 return resolved
.replace( '%d', plural
); // nb: plural might be undefined,
9129 * Version string for plug-ins to check compatibility. Allowed format is
9130 * `a.b.c-d` where: a:int, b:int, c:int, d:string(dev|beta|alpha). `d` is used
9131 * only for non-release builds. See http://semver.org/ for more information.
9134 * @default Version number
9136 DataTable
.version
= "1.10.7";
9139 * Private data store, containing all of the settings objects that are
9140 * created for the tables on a given page.
9142 * Note that the `DataTable.settings` object is aliased to
9143 * `jQuery.fn.dataTableExt` through which it may be accessed and
9144 * manipulated, or `jQuery.fn.dataTable.settings`.
9150 DataTable
.settings
= [];
9153 * Object models container, for the various models that DataTables has
9154 * available to it. These models define the objects that are used to hold
9155 * the active state and configuration of the table.
9158 DataTable
.models
= {};
9163 * Template object for the way in which DataTables holds information about
9164 * search information for the global filter and individual column filters.
9167 DataTable
.models
.oSearch
= {
9169 * Flag to indicate if the filtering should be case insensitive or not
9173 "bCaseInsensitive": true,
9176 * Applied search term
9178 * @default <i>Empty string</i>
9183 * Flag to indicate if the search term should be interpreted as a
9184 * regular expression (true) or not (false) and therefore and special
9185 * regex characters escaped.
9192 * Flag to indicate if DataTables is to use its smart filtering or not.
9203 * Template object for the way in which DataTables holds information about
9204 * each individual row. This is the object format used for the settings
9208 DataTable
.models
.oRow
= {
9210 * TR element for the row
9217 * Array of TD elements for each row. This is null until the row has been
9225 * Data object from the original data source for the row. This is either
9226 * an array if using the traditional form of DataTables, or an object if
9227 * using mData options. The exact type will depend on the passed in
9228 * data from the data source, or will be an array if using DOM a data
9230 * @type array|object
9236 * Sorting data cache - this array is ostensibly the same length as the
9237 * number of columns (although each index is generated only as it is
9238 * needed), and holds the data that is used for sorting each column in the
9239 * row. We do this cache generation at the start of the sort in order that
9240 * the formatting of the sort data need be done only once for each cell
9241 * per sort. This array should not be read from or written to by anything
9242 * other than the master sorting methods.
9250 * Per cell filtering data cache. As per the sort data cache, used to
9251 * increase the performance of the filtering in DataTables
9256 "_aFilterData": null,
9259 * Filtering data cache. This is the same as the cell filtering cache, but
9260 * in this case a string rather than an array. This is easily computed with
9261 * a join on `_aFilterData`, but is provided as a cache so the join isn't
9262 * needed on every search (memory traded for performance)
9267 "_sFilterRow": null,
9270 * Cache of the class name that DataTables has applied to the row, so we
9271 * can quickly look at this variable rather than needing to do a DOM check
9272 * on className for the nTr property.
9274 * @default <i>Empty string</i>
9280 * Denote if the original data source was from the DOM, or the data source
9281 * object. This is used for invalidating data, so DataTables can
9282 * automatically read data from the original source, unless uninstructed
9293 * Template object for the column information object in DataTables. This object
9294 * is held in the settings aoColumns array and contains all the information that
9295 * DataTables needs about each individual column.
9297 * Note that this object is related to {@link DataTable.defaults.column}
9298 * but this one is the internal data store for DataTables's cache of columns.
9299 * It should NOT be manipulated outside of DataTables. Any configuration should
9300 * be done through the initialisation options.
9303 DataTable
.models
.oColumn
= {
9305 * Column index. This could be worked out on-the-fly with $.inArray, but it
9306 * is faster to just hold it as a variable
9313 * A list of the columns that sorting should occur on when this column
9314 * is sorted. That this property is an array allows multi-column sorting
9315 * to be defined for a column (for example first name / last name columns
9316 * would benefit from this). The values are integers pointing to the
9317 * columns to be sorted on (typically it will be a single integer pointing
9318 * at itself, but that doesn't need to be the case).
9324 * Define the sorting directions that are applied to the column, in sequence
9325 * as the column is repeatedly sorted upon - i.e. the first value is used
9326 * as the sorting direction when the column if first sorted (clicked on).
9327 * Sort it again (click again) and it will move on to the next index.
9328 * Repeat until loop.
9334 * Flag to indicate if the column is searchable, and thus should be included
9335 * in the filtering or not.
9338 "bSearchable": null,
9341 * Flag to indicate if the column is sortable or not.
9347 * Flag to indicate if the column is currently visible in the table or not
9353 * Store for manual type assignment using the `column.type` option. This
9354 * is held in store so we can manipulate the column's `sType` property.
9359 "_sManualType": null,
9362 * Flag to indicate if HTML5 data attributes should be used as the data
9363 * source for filtering or sorting. True is either are.
9371 * Developer definable function that is called whenever a cell is created (Ajax source,
9372 * etc) or processed for input (DOM source). This can be used as a compliment to mRender
9373 * allowing you to modify the DOM element (add background colour for example) when the
9374 * element is available.
9376 * @param {element} nTd The TD node that has been created
9377 * @param {*} sData The Data for the cell
9378 * @param {array|object} oData The data for the whole row
9379 * @param {int} iRow The row index for the aoData data store
9382 "fnCreatedCell": null,
9385 * Function to get data from a cell in a column. You should <b>never</b>
9386 * access data directly through _aData internally in DataTables - always use
9387 * the method attached to this property. It allows mData to function as
9388 * required. This function is automatically assigned by the column
9389 * initialisation method
9391 * @param {array|object} oData The data array/object for the array
9392 * (i.e. aoData[]._aData)
9393 * @param {string} sSpecific The specific data type you want to get -
9394 * 'display', 'type' 'filter' 'sort'
9395 * @returns {*} The data for the cell from the given row's data
9401 * Function to set data for a cell in the column. You should <b>never</b>
9402 * set the data directly to _aData internally in DataTables - always use
9403 * this method. It allows mData to function as required. This function
9404 * is automatically assigned by the column initialisation method
9406 * @param {array|object} oData The data array/object for the array
9407 * (i.e. aoData[]._aData)
9408 * @param {*} sValue Value to set
9414 * Property to read the value for the cells in the column from the data
9415 * source array / object. If null, then the default content is used, if a
9416 * function is given then the return from the function is used.
9417 * @type function|int|string|null
9423 * Partner property to mData which is used (only when defined) to get
9424 * the data - i.e. it is basically the same as mData, but without the
9425 * 'set' option, and also the data fed to it is the result from mData.
9426 * This is the rendering method to match the data method of mData.
9427 * @type function|int|string|null
9433 * Unique header TH/TD element for this column - this is what the sorting
9434 * listener is attached to (if sorting is enabled.)
9441 * Unique footer TH/TD element for this column (if there is one). Not used
9442 * in DataTables as such, but can be used for plug-ins to reference the
9443 * footer for each column.
9450 * The class to apply to all TD elements in the table's TBODY for the column
9457 * When DataTables calculates the column widths to assign to each column,
9458 * it finds the longest string in each column and then constructs a
9459 * temporary table and reads the widths from that. The problem with this
9460 * is that "mmm" is much wider then "iiii", but the latter is a longer
9461 * string - thus the calculation can go wrong (doing it properly and putting
9462 * it into an DOM object and measuring that is horribly(!) slow). Thus as
9463 * a "work around" we provide this option. It will append its value to the
9464 * text that is found to be the longest string for the column - i.e. padding.
9467 "sContentPadding": null,
9470 * Allows a default value to be given for a column's data, and will be used
9471 * whenever a null data source is encountered (this can be because mData
9472 * is set to null, or because the data source itself is null).
9476 "sDefaultContent": null,
9479 * Name for the column, allowing reference to the column by name as well as
9480 * by index (needs a lookup to work by name).
9486 * Custom sorting data type - defines which of the available plug-ins in
9487 * afnSortData the custom sorting will use - if any is defined.
9491 "sSortDataType": 'std',
9494 * Class to be applied to the header element when sorting on this column
9498 "sSortingClass": null,
9501 * Class to be applied to the header element when sorting on this column -
9502 * when jQuery UI theming is used.
9506 "sSortingClassJUI": null,
9509 * Title of the column - what is seen in the TH element (nTh).
9515 * Column sorting and filtering type
9522 * Width of the column
9529 * Width of the column when it was first "encountered"
9538 * Developer note: The properties of the object below are given in Hungarian
9539 * notation, that was used as the interface for DataTables prior to v1.10, however
9540 * from v1.10 onwards the primary interface is camel case. In order to avoid
9541 * breaking backwards compatibility utterly with this change, the Hungarian
9542 * version is still, internally the primary interface, but is is not documented
9543 * - hence the @name tags in each doc comment. This allows a Javascript function
9544 * to create a map from Hungarian notation to camel case (going the other direction
9545 * would require each property to be listed, which would at around 3K to the size
9546 * of DataTables, while this method is about a 0.5K hit.
9548 * Ultimately this does pave the way for Hungarian notation to be dropped
9549 * completely, but that is a massive amount of work and will break current
9550 * installs (therefore is on-hold until v2).
9554 * Initialisation options that can be given to DataTables at initialisation
9558 DataTable
.defaults
= {
9560 * An array of data to use for the table, passed in at initialisation which
9561 * will be used in preference to any data which is already in the DOM. This is
9562 * particularly useful for constructing tables purely in Javascript, for
9563 * example with a custom Ajax call.
9568 * @name DataTable.defaults.data
9571 * // Using a 2D array data source
9572 * $(document).ready( function () {
9573 * $('#example').dataTable( {
9575 * ['Trident', 'Internet Explorer 4.0', 'Win 95+', 4, 'X'],
9576 * ['Trident', 'Internet Explorer 5.0', 'Win 95+', 5, 'C'],
9579 * { "title": "Engine" },
9580 * { "title": "Browser" },
9581 * { "title": "Platform" },
9582 * { "title": "Version" },
9583 * { "title": "Grade" }
9589 * // Using an array of objects as a data source (`data`)
9590 * $(document).ready( function () {
9591 * $('#example').dataTable( {
9594 * "engine": "Trident",
9595 * "browser": "Internet Explorer 4.0",
9596 * "platform": "Win 95+",
9601 * "engine": "Trident",
9602 * "browser": "Internet Explorer 5.0",
9603 * "platform": "Win 95+",
9609 * { "title": "Engine", "data": "engine" },
9610 * { "title": "Browser", "data": "browser" },
9611 * { "title": "Platform", "data": "platform" },
9612 * { "title": "Version", "data": "version" },
9613 * { "title": "Grade", "data": "grade" }
9622 * If ordering is enabled, then DataTables will perform a first pass sort on
9623 * initialisation. You can define which column(s) the sort is performed
9624 * upon, and the sorting direction, with this variable. The `sorting` array
9625 * should contain an array for each column to be sorted initially containing
9626 * the column's index and a direction string ('asc' or 'desc').
9628 * @default [[0,'asc']]
9631 * @name DataTable.defaults.order
9634 * // Sort by 3rd column first, and then 4th column
9635 * $(document).ready( function() {
9636 * $('#example').dataTable( {
9637 * "order": [[2,'asc'], [3,'desc']]
9641 * // No initial sorting
9642 * $(document).ready( function() {
9643 * $('#example').dataTable( {
9648 "aaSorting": [[0,'asc']],
9652 * This parameter is basically identical to the `sorting` parameter, but
9653 * cannot be overridden by user interaction with the table. What this means
9654 * is that you could have a column (visible or hidden) which the sorting
9655 * will always be forced on first - any sorting after that (from the user)
9656 * will then be performed as required. This can be useful for grouping rows
9662 * @name DataTable.defaults.orderFixed
9665 * $(document).ready( function() {
9666 * $('#example').dataTable( {
9667 * "orderFixed": [[0,'asc']]
9671 "aaSortingFixed": [],
9675 * DataTables can be instructed to load data to display in the table from a
9676 * Ajax source. This option defines how that Ajax call is made and where to.
9678 * The `ajax` property has three different modes of operation, depending on
9679 * how it is defined. These are:
9681 * * `string` - Set the URL from where the data should be loaded from.
9682 * * `object` - Define properties for `jQuery.ajax`.
9683 * * `function` - Custom data get function
9688 * As a string, the `ajax` property simply defines the URL from which
9689 * DataTables will load data.
9694 * As an object, the parameters in the object are passed to
9695 * [jQuery.ajax](http://api.jquery.com/jQuery.ajax/) allowing fine control
9696 * of the Ajax request. DataTables has a number of default parameters which
9697 * you can override using this option. Please refer to the jQuery
9698 * documentation for a full description of the options available, although
9699 * the following parameters provide additional options in DataTables or
9700 * require special consideration:
9702 * * `data` - As with jQuery, `data` can be provided as an object, but it
9703 * can also be used as a function to manipulate the data DataTables sends
9704 * to the server. The function takes a single parameter, an object of
9705 * parameters with the values that DataTables has readied for sending. An
9706 * object may be returned which will be merged into the DataTables
9707 * defaults, or you can add the items to the object that was passed in and
9708 * not return anything from the function. This supersedes `fnServerParams`
9709 * from DataTables 1.9-.
9711 * * `dataSrc` - By default DataTables will look for the property `data` (or
9712 * `aaData` for compatibility with DataTables 1.9-) when obtaining data
9713 * from an Ajax source or for server-side processing - this parameter
9714 * allows that property to be changed. You can use Javascript dotted
9715 * object notation to get a data source for multiple levels of nesting, or
9716 * it my be used as a function. As a function it takes a single parameter,
9717 * the JSON returned from the server, which can be manipulated as
9718 * required, with the returned value being that used by DataTables as the
9719 * data source for the table. This supersedes `sAjaxDataProp` from
9722 * * `success` - Should not be overridden it is used internally in
9723 * DataTables. To manipulate / transform the data returned by the server
9724 * use `ajax.dataSrc`, or use `ajax` as a function (see below).
9729 * As a function, making the Ajax call is left up to yourself allowing
9730 * complete control of the Ajax request. Indeed, if desired, a method other
9731 * than Ajax could be used to obtain the required data, such as Web storage
9732 * or an AIR database.
9734 * The function is given four parameters and no return is required. The
9737 * 1. _object_ - Data to send to the server
9738 * 2. _function_ - Callback function that must be executed when the required
9739 * data has been obtained. That data should be passed into the callback
9740 * as the only parameter
9741 * 3. _object_ - DataTables settings object for the table
9743 * Note that this supersedes `fnServerData` from DataTables 1.9-.
9745 * @type string|object|function
9749 * @name DataTable.defaults.ajax
9753 * // Get JSON data from a file via Ajax.
9754 * // Note DataTables expects data in the form `{ data: [ ...data... ] }` by default).
9755 * $('#example').dataTable( {
9756 * "ajax": "data.json"
9760 * // Get JSON data from a file via Ajax, using `dataSrc` to change
9761 * // `data` to `tableData` (i.e. `{ tableData: [ ...data... ] }`)
9762 * $('#example').dataTable( {
9764 * "url": "data.json",
9765 * "dataSrc": "tableData"
9770 * // Get JSON data from a file via Ajax, using `dataSrc` to read data
9771 * // from a plain array rather than an array in an object
9772 * $('#example').dataTable( {
9774 * "url": "data.json",
9780 * // Manipulate the data returned from the server - add a link to data
9781 * // (note this can, should, be done using `render` for the column - this
9782 * // is just a simple example of how the data can be manipulated).
9783 * $('#example').dataTable( {
9785 * "url": "data.json",
9786 * "dataSrc": function ( json ) {
9787 * for ( var i=0, ien=json.length ; i<ien ; i++ ) {
9788 * json[i][0] = '<a href="/message/'+json[i][0]+'>View message</a>';
9796 * // Add data to the request
9797 * $('#example').dataTable( {
9799 * "url": "data.json",
9800 * "data": function ( d ) {
9802 * "extra_search": $('#extra').val()
9809 * // Send request as POST
9810 * $('#example').dataTable( {
9812 * "url": "data.json",
9818 * // Get the data from localStorage (could interface with a form for
9819 * // adding, editing and removing rows).
9820 * $('#example').dataTable( {
9821 * "ajax": function (data, callback, settings) {
9823 * JSON.parse( localStorage.getItem('dataTablesData') )
9832 * This parameter allows you to readily specify the entries in the length drop
9833 * down menu that DataTables shows when pagination is enabled. It can be
9834 * either a 1D array of options which will be used for both the displayed
9835 * option and the value, or a 2D array which will use the array in the first
9836 * position as the value, and the array in the second position as the
9837 * displayed options (useful for language strings such as 'All').
9839 * Note that the `pageLength` property will be automatically set to the
9840 * first value given in this array, unless `pageLength` is also provided.
9842 * @default [ 10, 25, 50, 100 ]
9845 * @name DataTable.defaults.lengthMenu
9848 * $(document).ready( function() {
9849 * $('#example').dataTable( {
9850 * "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
9854 "aLengthMenu": [ 10, 25, 50, 100 ],
9858 * The `columns` option in the initialisation parameter allows you to define
9859 * details about the way individual columns behave. For a full list of
9860 * column options that can be set, please see
9861 * {@link DataTable.defaults.column}. Note that if you use `columns` to
9862 * define your columns, you must have an entry in the array for every single
9863 * column that you have in your table (these can be null if you don't which
9864 * to specify any options).
9867 * @name DataTable.defaults.column
9872 * Very similar to `columns`, `columnDefs` allows you to target a specific
9873 * column, multiple columns, or all columns, using the `targets` property of
9874 * each object in the array. This allows great flexibility when creating
9875 * tables, as the `columnDefs` arrays can be of any length, targeting the
9876 * columns you specifically want. `columnDefs` may use any of the column
9877 * options available: {@link DataTable.defaults.column}, but it _must_
9878 * have `targets` defined in each object in the array. Values in the `targets`
9881 * <li>a string - class name will be matched on the TH for the column</li>
9882 * <li>0 or a positive integer - column index counting from the left</li>
9883 * <li>a negative integer - column index counting from the right</li>
9884 * <li>the string "_all" - all columns (i.e. assign a default)</li>
9888 * @name DataTable.defaults.columnDefs
9890 "aoColumnDefs": null,
9894 * Basically the same as `search`, this parameter defines the individual column
9895 * filtering state at initialisation time. The array must be of the same size
9896 * as the number of columns, and each element be an object with the parameters
9897 * `search` and `escapeRegex` (the latter is optional). 'null' is also
9898 * accepted and the default will be used.
9903 * @name DataTable.defaults.searchCols
9906 * $(document).ready( function() {
9907 * $('#example').dataTable( {
9910 * { "search": "My filter" },
9912 * { "search": "^[0-9]", "escapeRegex": false }
9921 * An array of CSS classes that should be applied to displayed rows. This
9922 * array may be of any length, and DataTables will apply each class
9923 * sequentially, looping when required.
9925 * @default null <i>Will take the values determined by the `oClasses.stripe*`
9929 * @name DataTable.defaults.stripeClasses
9932 * $(document).ready( function() {
9933 * $('#example').dataTable( {
9934 * "stripeClasses": [ 'strip1', 'strip2', 'strip3' ]
9938 "asStripeClasses": null,
9942 * Enable or disable automatic column width calculation. This can be disabled
9943 * as an optimisation (it takes some time to calculate the widths) if the
9944 * tables widths are passed in using `columns`.
9949 * @name DataTable.defaults.autoWidth
9952 * $(document).ready( function () {
9953 * $('#example').dataTable( {
9954 * "autoWidth": false
9962 * Deferred rendering can provide DataTables with a huge speed boost when you
9963 * are using an Ajax or JS data source for the table. This option, when set to
9964 * true, will cause DataTables to defer the creation of the table elements for
9965 * each row until they are needed for a draw - saving a significant amount of
9971 * @name DataTable.defaults.deferRender
9974 * $(document).ready( function() {
9975 * $('#example').dataTable( {
9976 * "ajax": "sources/arrays.txt",
9977 * "deferRender": true
9981 "bDeferRender": false,
9985 * Replace a DataTable which matches the given selector and replace it with
9986 * one which has the properties of the new initialisation object passed. If no
9987 * table matches the selector, then the new DataTable will be constructed as
9993 * @name DataTable.defaults.destroy
9996 * $(document).ready( function() {
9997 * $('#example').dataTable( {
9998 * "srollY": "200px",
10002 * // Some time later....
10003 * $('#example').dataTable( {
10013 * Enable or disable filtering of data. Filtering in DataTables is "smart" in
10014 * that it allows the end user to input multiple words (space separated) and
10015 * will match a row containing those words, even if not in the order that was
10016 * specified (this allow matching across multiple columns). Note that if you
10017 * wish to use filtering in DataTables this must remain 'true' - to remove the
10018 * default filtering input box and retain filtering abilities, please use
10019 * {@link DataTable.defaults.dom}.
10024 * @name DataTable.defaults.searching
10027 * $(document).ready( function () {
10028 * $('#example').dataTable( {
10029 * "searching": false
10037 * Enable or disable the table information display. This shows information
10038 * about the data that is currently visible on the page, including information
10039 * about filtered data if that action is being performed.
10044 * @name DataTable.defaults.info
10047 * $(document).ready( function () {
10048 * $('#example').dataTable( {
10057 * Enable jQuery UI ThemeRoller support (required as ThemeRoller requires some
10058 * slightly different and additional mark-up from what DataTables has
10059 * traditionally used).
10064 * @name DataTable.defaults.jQueryUI
10067 * $(document).ready( function() {
10068 * $('#example').dataTable( {
10073 "bJQueryUI": false,
10077 * Allows the end user to select the size of a formatted page from a select
10078 * menu (sizes are 10, 25, 50 and 100). Requires pagination (`paginate`).
10083 * @name DataTable.defaults.lengthChange
10086 * $(document).ready( function () {
10087 * $('#example').dataTable( {
10088 * "lengthChange": false
10092 "bLengthChange": true,
10096 * Enable or disable pagination.
10101 * @name DataTable.defaults.paging
10104 * $(document).ready( function () {
10105 * $('#example').dataTable( {
10114 * Enable or disable the display of a 'processing' indicator when the table is
10115 * being processed (e.g. a sort). This is particularly useful for tables with
10116 * large amounts of data where it can take a noticeable amount of time to sort
10122 * @name DataTable.defaults.processing
10125 * $(document).ready( function () {
10126 * $('#example').dataTable( {
10127 * "processing": true
10131 "bProcessing": false,
10135 * Retrieve the DataTables object for the given selector. Note that if the
10136 * table has already been initialised, this parameter will cause DataTables
10137 * to simply return the object that has already been set up - it will not take
10138 * account of any changes you might have made to the initialisation object
10139 * passed to DataTables (setting this parameter to true is an acknowledgement
10140 * that you understand this). `destroy` can be used to reinitialise a table if
10146 * @name DataTable.defaults.retrieve
10149 * $(document).ready( function() {
10154 * function initTable ()
10156 * return $('#example').dataTable( {
10157 * "scrollY": "200px",
10158 * "paginate": false,
10163 * function tableActions ()
10165 * var table = initTable();
10166 * // perform API operations with oTable
10169 "bRetrieve": false,
10173 * When vertical (y) scrolling is enabled, DataTables will force the height of
10174 * the table's viewport to the given height at all times (useful for layout).
10175 * However, this can look odd when filtering data down to a small data set,
10176 * and the footer is left "floating" further down. This parameter (when
10177 * enabled) will cause DataTables to collapse the table's viewport down when
10178 * the result set will fit within the given Y height.
10183 * @name DataTable.defaults.scrollCollapse
10186 * $(document).ready( function() {
10187 * $('#example').dataTable( {
10188 * "scrollY": "200",
10189 * "scrollCollapse": true
10193 "bScrollCollapse": false,
10197 * Configure DataTables to use server-side processing. Note that the
10198 * `ajax` parameter must also be given in order to give DataTables a
10199 * source to obtain the required data for each draw.
10204 * @dtopt Server-side
10205 * @name DataTable.defaults.serverSide
10208 * $(document).ready( function () {
10209 * $('#example').dataTable( {
10210 * "serverSide": true,
10211 * "ajax": "xhr.php"
10215 "bServerSide": false,
10219 * Enable or disable sorting of columns. Sorting of individual columns can be
10220 * disabled by the `sortable` option for each column.
10225 * @name DataTable.defaults.ordering
10228 * $(document).ready( function () {
10229 * $('#example').dataTable( {
10230 * "ordering": false
10238 * Enable or display DataTables' ability to sort multiple columns at the
10239 * same time (activated by shift-click by the user).
10244 * @name DataTable.defaults.orderMulti
10247 * // Disable multiple column sorting ability
10248 * $(document).ready( function () {
10249 * $('#example').dataTable( {
10250 * "orderMulti": false
10254 "bSortMulti": true,
10258 * Allows control over whether DataTables should use the top (true) unique
10259 * cell that is found for a single column, or the bottom (false - default).
10260 * This is useful when using complex headers.
10265 * @name DataTable.defaults.orderCellsTop
10268 * $(document).ready( function() {
10269 * $('#example').dataTable( {
10270 * "orderCellsTop": true
10274 "bSortCellsTop": false,
10278 * Enable or disable the addition of the classes `sorting\_1`, `sorting\_2` and
10279 * `sorting\_3` to the columns which are currently being sorted on. This is
10280 * presented as a feature switch as it can increase processing time (while
10281 * classes are removed and added) so for large data sets you might want to
10287 * @name DataTable.defaults.orderClasses
10290 * $(document).ready( function () {
10291 * $('#example').dataTable( {
10292 * "orderClasses": false
10296 "bSortClasses": true,
10300 * Enable or disable state saving. When enabled HTML5 `localStorage` will be
10301 * used to save table display information such as pagination information,
10302 * display length, filtering and sorting. As such when the end user reloads
10303 * the page the display display will match what thy had previously set up.
10305 * Due to the use of `localStorage` the default state saving is not supported
10306 * in IE6 or 7. If state saving is required in those browsers, use
10307 * `stateSaveCallback` to provide a storage solution such as cookies.
10312 * @name DataTable.defaults.stateSave
10315 * $(document).ready( function () {
10316 * $('#example').dataTable( {
10317 * "stateSave": true
10321 "bStateSave": false,
10325 * This function is called when a TR element is created (and all TD child
10326 * elements have been inserted), or registered if using a DOM source, allowing
10327 * manipulation of the TR element (adding classes etc).
10329 * @param {node} row "TR" element for the current row
10330 * @param {array} data Raw data array for this row
10331 * @param {int} dataIndex The index of this row in the internal aoData array
10334 * @name DataTable.defaults.createdRow
10337 * $(document).ready( function() {
10338 * $('#example').dataTable( {
10339 * "createdRow": function( row, data, dataIndex ) {
10340 * // Bold the grade for all 'A' grade browsers
10341 * if ( data[4] == "A" )
10343 * $('td:eq(4)', row).html( '<b>A</b>' );
10349 "fnCreatedRow": null,
10353 * This function is called on every 'draw' event, and allows you to
10354 * dynamically modify any aspect you want about the created DOM.
10356 * @param {object} settings DataTables settings object
10359 * @name DataTable.defaults.drawCallback
10362 * $(document).ready( function() {
10363 * $('#example').dataTable( {
10364 * "drawCallback": function( settings ) {
10365 * alert( 'DataTables has redrawn the table' );
10370 "fnDrawCallback": null,
10374 * Identical to fnHeaderCallback() but for the table footer this function
10375 * allows you to modify the table footer on every 'draw' event.
10377 * @param {node} foot "TR" element for the footer
10378 * @param {array} data Full table data (as derived from the original HTML)
10379 * @param {int} start Index for the current display starting point in the
10381 * @param {int} end Index for the current display ending point in the
10383 * @param {array int} display Index array to translate the visual position
10384 * to the full data array
10387 * @name DataTable.defaults.footerCallback
10390 * $(document).ready( function() {
10391 * $('#example').dataTable( {
10392 * "footerCallback": function( tfoot, data, start, end, display ) {
10393 * tfoot.getElementsByTagName('th')[0].innerHTML = "Starting index is "+start;
10398 "fnFooterCallback": null,
10402 * When rendering large numbers in the information element for the table
10403 * (i.e. "Showing 1 to 10 of 57 entries") DataTables will render large numbers
10404 * to have a comma separator for the 'thousands' units (e.g. 1 million is
10405 * rendered as "1,000,000") to help readability for the end user. This
10406 * function will override the default method DataTables uses.
10409 * @param {int} toFormat number to be formatted
10410 * @returns {string} formatted string for DataTables to show the number
10413 * @name DataTable.defaults.formatNumber
10416 * // Format a number using a single quote for the separator (note that
10417 * // this can also be done with the language.thousands option)
10418 * $(document).ready( function() {
10419 * $('#example').dataTable( {
10420 * "formatNumber": function ( toFormat ) {
10421 * return toFormat.toString().replace(
10422 * /\B(?=(\d{3})+(?!\d))/g, "'"
10428 "fnFormatNumber": function ( toFormat
) {
10429 return toFormat
.toString().replace(
10430 /\B(?=(\d{3})+(?!\d))/g,
10431 this.oLanguage
.sThousands
10437 * This function is called on every 'draw' event, and allows you to
10438 * dynamically modify the header row. This can be used to calculate and
10439 * display useful information about the table.
10441 * @param {node} head "TR" element for the header
10442 * @param {array} data Full table data (as derived from the original HTML)
10443 * @param {int} start Index for the current display starting point in the
10445 * @param {int} end Index for the current display ending point in the
10447 * @param {array int} display Index array to translate the visual position
10448 * to the full data array
10451 * @name DataTable.defaults.headerCallback
10454 * $(document).ready( function() {
10455 * $('#example').dataTable( {
10456 * "fheaderCallback": function( head, data, start, end, display ) {
10457 * head.getElementsByTagName('th')[0].innerHTML = "Displaying "+(end-start)+" records";
10462 "fnHeaderCallback": null,
10466 * The information element can be used to convey information about the current
10467 * state of the table. Although the internationalisation options presented by
10468 * DataTables are quite capable of dealing with most customisations, there may
10469 * be times where you wish to customise the string further. This callback
10470 * allows you to do exactly that.
10472 * @param {object} oSettings DataTables settings object
10473 * @param {int} start Starting position in data for the draw
10474 * @param {int} end End position in data for the draw
10475 * @param {int} max Total number of rows in the table (regardless of
10477 * @param {int} total Total number of rows in the data set, after filtering
10478 * @param {string} pre The string that DataTables has formatted using it's
10480 * @returns {string} The string to be displayed in the information element.
10483 * @name DataTable.defaults.infoCallback
10486 * $('#example').dataTable( {
10487 * "infoCallback": function( settings, start, end, max, total, pre ) {
10488 * return start +" to "+ end;
10492 "fnInfoCallback": null,
10496 * Called when the table has been initialised. Normally DataTables will
10497 * initialise sequentially and there will be no need for this function,
10498 * however, this does not hold true when using external language information
10499 * since that is obtained using an async XHR call.
10501 * @param {object} settings DataTables settings object
10502 * @param {object} json The JSON object request from the server - only
10503 * present if client-side Ajax sourced data is used
10506 * @name DataTable.defaults.initComplete
10509 * $(document).ready( function() {
10510 * $('#example').dataTable( {
10511 * "initComplete": function(settings, json) {
10512 * alert( 'DataTables has finished its initialisation.' );
10517 "fnInitComplete": null,
10521 * Called at the very start of each table draw and can be used to cancel the
10522 * draw by returning false, any other return (including undefined) results in
10523 * the full draw occurring).
10525 * @param {object} settings DataTables settings object
10526 * @returns {boolean} False will cancel the draw, anything else (including no
10527 * return) will allow it to complete.
10530 * @name DataTable.defaults.preDrawCallback
10533 * $(document).ready( function() {
10534 * $('#example').dataTable( {
10535 * "preDrawCallback": function( settings ) {
10536 * if ( $('#test').val() == 1 ) {
10543 "fnPreDrawCallback": null,
10547 * This function allows you to 'post process' each row after it have been
10548 * generated for each table draw, but before it is rendered on screen. This
10549 * function might be used for setting the row class name etc.
10551 * @param {node} row "TR" element for the current row
10552 * @param {array} data Raw data array for this row
10553 * @param {int} displayIndex The display index for the current table draw
10554 * @param {int} displayIndexFull The index of the data in the full list of
10555 * rows (after filtering)
10558 * @name DataTable.defaults.rowCallback
10561 * $(document).ready( function() {
10562 * $('#example').dataTable( {
10563 * "rowCallback": function( row, data, displayIndex, displayIndexFull ) {
10564 * // Bold the grade for all 'A' grade browsers
10565 * if ( data[4] == "A" ) {
10566 * $('td:eq(4)', row).html( '<b>A</b>' );
10572 "fnRowCallback": null,
10576 * __Deprecated__ The functionality provided by this parameter has now been
10577 * superseded by that provided through `ajax`, which should be used instead.
10579 * This parameter allows you to override the default function which obtains
10580 * the data from the server so something more suitable for your application.
10581 * For example you could use POST data, or pull information from a Gears or
10585 * @param {string} source HTTP source to obtain the data from (`ajax`)
10586 * @param {array} data A key/value pair object containing the data to send
10588 * @param {function} callback to be called on completion of the data get
10589 * process that will draw the data on the page.
10590 * @param {object} settings DataTables settings object
10593 * @dtopt Server-side
10594 * @name DataTable.defaults.serverData
10596 * @deprecated 1.10. Please use `ajax` for this functionality now.
10598 "fnServerData": null,
10602 * __Deprecated__ The functionality provided by this parameter has now been
10603 * superseded by that provided through `ajax`, which should be used instead.
10605 * It is often useful to send extra data to the server when making an Ajax
10606 * request - for example custom filtering information, and this callback
10607 * function makes it trivial to send extra information to the server. The
10608 * passed in parameter is the data set that has been constructed by
10609 * DataTables, and you can add to this or modify it as you require.
10611 * @param {array} data Data array (array of objects which are name/value
10612 * pairs) that has been constructed by DataTables and will be sent to the
10613 * server. In the case of Ajax sourced data with server-side processing
10614 * this will be an empty array, for server-side processing there will be a
10615 * significant number of parameters!
10616 * @returns {undefined} Ensure that you modify the data array passed in,
10617 * as this is passed by reference.
10620 * @dtopt Server-side
10621 * @name DataTable.defaults.serverParams
10623 * @deprecated 1.10. Please use `ajax` for this functionality now.
10625 "fnServerParams": null,
10629 * Load the table state. With this function you can define from where, and how, the
10630 * state of a table is loaded. By default DataTables will load from `localStorage`
10631 * but you might wish to use a server-side database or cookies.
10634 * @param {object} settings DataTables settings object
10635 * @return {object} The DataTables state object to be loaded
10638 * @name DataTable.defaults.stateLoadCallback
10641 * $(document).ready( function() {
10642 * $('#example').dataTable( {
10643 * "stateSave": true,
10644 * "stateLoadCallback": function (settings) {
10647 * // Send an Ajax request to the server to get the data. Note that
10648 * // this is a synchronous request.
10650 * "url": "/state_load",
10652 * "dataType": "json",
10653 * "success": function (json) {
10663 "fnStateLoadCallback": function ( settings
) {
10666 (settings
.iStateDuration
=== -1 ? sessionStorage
: localStorage
).getItem(
10667 'DataTables_'+settings
.sInstance
+'_'+location
.pathname
10675 * Callback which allows modification of the saved state prior to loading that state.
10676 * This callback is called when the table is loading state from the stored data, but
10677 * prior to the settings object being modified by the saved state. Note that for
10678 * plug-in authors, you should use the `stateLoadParams` event to load parameters for
10681 * @param {object} settings DataTables settings object
10682 * @param {object} data The state object that is to be loaded
10685 * @name DataTable.defaults.stateLoadParams
10688 * // Remove a saved filter, so filtering is never loaded
10689 * $(document).ready( function() {
10690 * $('#example').dataTable( {
10691 * "stateSave": true,
10692 * "stateLoadParams": function (settings, data) {
10693 * data.oSearch.sSearch = "";
10699 * // Disallow state loading by returning false
10700 * $(document).ready( function() {
10701 * $('#example').dataTable( {
10702 * "stateSave": true,
10703 * "stateLoadParams": function (settings, data) {
10709 "fnStateLoadParams": null,
10713 * Callback that is called when the state has been loaded from the state saving method
10714 * and the DataTables settings object has been modified as a result of the loaded state.
10716 * @param {object} settings DataTables settings object
10717 * @param {object} data The state object that was loaded
10720 * @name DataTable.defaults.stateLoaded
10723 * // Show an alert with the filtering value that was saved
10724 * $(document).ready( function() {
10725 * $('#example').dataTable( {
10726 * "stateSave": true,
10727 * "stateLoaded": function (settings, data) {
10728 * alert( 'Saved filter was: '+data.oSearch.sSearch );
10733 "fnStateLoaded": null,
10737 * Save the table state. This function allows you to define where and how the state
10738 * information for the table is stored By default DataTables will use `localStorage`
10739 * but you might wish to use a server-side database or cookies.
10742 * @param {object} settings DataTables settings object
10743 * @param {object} data The state object to be saved
10746 * @name DataTable.defaults.stateSaveCallback
10749 * $(document).ready( function() {
10750 * $('#example').dataTable( {
10751 * "stateSave": true,
10752 * "stateSaveCallback": function (settings, data) {
10753 * // Send an Ajax request to the server with the state object
10755 * "url": "/state_save",
10757 * "dataType": "json",
10759 * "success": function () {}
10765 "fnStateSaveCallback": function ( settings
, data
) {
10767 (settings
.iStateDuration
=== -1 ? sessionStorage
: localStorage
).setItem(
10768 'DataTables_'+settings
.sInstance
+'_'+location
.pathname
,
10769 JSON
.stringify( data
)
10776 * Callback which allows modification of the state to be saved. Called when the table
10777 * has changed state a new state save is required. This method allows modification of
10778 * the state saving object prior to actually doing the save, including addition or
10779 * other state properties or modification. Note that for plug-in authors, you should
10780 * use the `stateSaveParams` event to save parameters for a plug-in.
10782 * @param {object} settings DataTables settings object
10783 * @param {object} data The state object to be saved
10786 * @name DataTable.defaults.stateSaveParams
10789 * // Remove a saved filter, so filtering is never saved
10790 * $(document).ready( function() {
10791 * $('#example').dataTable( {
10792 * "stateSave": true,
10793 * "stateSaveParams": function (settings, data) {
10794 * data.oSearch.sSearch = "";
10799 "fnStateSaveParams": null,
10803 * Duration for which the saved state information is considered valid. After this period
10804 * has elapsed the state will be returned to the default.
10805 * Value is given in seconds.
10807 * @default 7200 <i>(2 hours)</i>
10810 * @name DataTable.defaults.stateDuration
10813 * $(document).ready( function() {
10814 * $('#example').dataTable( {
10815 * "stateDuration": 60*60*24; // 1 day
10819 "iStateDuration": 7200,
10823 * When enabled DataTables will not make a request to the server for the first
10824 * page draw - rather it will use the data already on the page (no sorting etc
10825 * will be applied to it), thus saving on an XHR at load time. `deferLoading`
10826 * is used to indicate that deferred loading is required, but it is also used
10827 * to tell DataTables how many records there are in the full table (allowing
10828 * the information element and pagination to be displayed correctly). In the case
10829 * where a filtering is applied to the table on initial load, this can be
10830 * indicated by giving the parameter as an array, where the first element is
10831 * the number of records available after filtering and the second element is the
10832 * number of records without filtering (allowing the table information element
10833 * to be shown correctly).
10834 * @type int | array
10838 * @name DataTable.defaults.deferLoading
10841 * // 57 records available in the table, no filtering applied
10842 * $(document).ready( function() {
10843 * $('#example').dataTable( {
10844 * "serverSide": true,
10845 * "ajax": "scripts/server_processing.php",
10846 * "deferLoading": 57
10851 * // 57 records after filtering, 100 without filtering (an initial filter applied)
10852 * $(document).ready( function() {
10853 * $('#example').dataTable( {
10854 * "serverSide": true,
10855 * "ajax": "scripts/server_processing.php",
10856 * "deferLoading": [ 57, 100 ],
10858 * "search": "my_filter"
10863 "iDeferLoading": null,
10867 * Number of rows to display on a single page when using pagination. If
10868 * feature enabled (`lengthChange`) then the end user will be able to override
10869 * this to a custom setting using a pop-up menu.
10874 * @name DataTable.defaults.pageLength
10877 * $(document).ready( function() {
10878 * $('#example').dataTable( {
10883 "iDisplayLength": 10,
10887 * Define the starting point for data display when using DataTables with
10888 * pagination. Note that this parameter is the number of records, rather than
10889 * the page number, so if you have 10 records per page and want to start on
10890 * the third page, it should be "20".
10895 * @name DataTable.defaults.displayStart
10898 * $(document).ready( function() {
10899 * $('#example').dataTable( {
10900 * "displayStart": 20
10904 "iDisplayStart": 0,
10908 * By default DataTables allows keyboard navigation of the table (sorting, paging,
10909 * and filtering) by adding a `tabindex` attribute to the required elements. This
10910 * allows you to tab through the controls and press the enter key to activate them.
10911 * The tabindex is default 0, meaning that the tab follows the flow of the document.
10912 * You can overrule this using this parameter if you wish. Use a value of -1 to
10913 * disable built-in keyboard navigation.
10918 * @name DataTable.defaults.tabIndex
10921 * $(document).ready( function() {
10922 * $('#example').dataTable( {
10931 * Classes that DataTables assigns to the various components and features
10932 * that it adds to the HTML table. This allows classes to be configured
10933 * during initialisation in addition to through the static
10934 * {@link DataTable.ext.oStdClasses} object).
10936 * @name DataTable.defaults.classes
10942 * All strings that DataTables uses in the user interface that it creates
10943 * are defined in this object, allowing you to modified them individually or
10944 * completely replace them all as required.
10946 * @name DataTable.defaults.language
10950 * Strings that are used for WAI-ARIA labels and controls only (these are not
10951 * actually visible on the page, but will be read by screenreaders, and thus
10952 * must be internationalised as well).
10954 * @name DataTable.defaults.language.aria
10958 * ARIA label that is added to the table headers when the column may be
10959 * sorted ascending by activing the column (click or return when focused).
10960 * Note that the column header is prefixed to this string.
10962 * @default : activate to sort column ascending
10965 * @name DataTable.defaults.language.aria.sortAscending
10968 * $(document).ready( function() {
10969 * $('#example').dataTable( {
10972 * "sortAscending": " - click/return to sort ascending"
10978 "sSortAscending": ": activate to sort column ascending",
10981 * ARIA label that is added to the table headers when the column may be
10982 * sorted descending by activing the column (click or return when focused).
10983 * Note that the column header is prefixed to this string.
10985 * @default : activate to sort column ascending
10988 * @name DataTable.defaults.language.aria.sortDescending
10991 * $(document).ready( function() {
10992 * $('#example').dataTable( {
10995 * "sortDescending": " - click/return to sort descending"
11001 "sSortDescending": ": activate to sort column descending"
11005 * Pagination string used by DataTables for the built-in pagination
11008 * @name DataTable.defaults.language.paginate
11012 * Text to use when using the 'full_numbers' type of pagination for the
11013 * button to take the user to the first page.
11018 * @name DataTable.defaults.language.paginate.first
11021 * $(document).ready( function() {
11022 * $('#example').dataTable( {
11025 * "first": "First page"
11035 * Text to use when using the 'full_numbers' type of pagination for the
11036 * button to take the user to the last page.
11041 * @name DataTable.defaults.language.paginate.last
11044 * $(document).ready( function() {
11045 * $('#example').dataTable( {
11048 * "last": "Last page"
11058 * Text to use for the 'next' pagination button (to take the user to the
11064 * @name DataTable.defaults.language.paginate.next
11067 * $(document).ready( function() {
11068 * $('#example').dataTable( {
11071 * "next": "Next page"
11081 * Text to use for the 'previous' pagination button (to take the user to
11082 * the previous page).
11084 * @default Previous
11087 * @name DataTable.defaults.language.paginate.previous
11090 * $(document).ready( function() {
11091 * $('#example').dataTable( {
11094 * "previous": "Previous page"
11100 "sPrevious": "Previous"
11104 * This string is shown in preference to `zeroRecords` when the table is
11105 * empty of data (regardless of filtering). Note that this is an optional
11106 * parameter - if it is not given, the value of `zeroRecords` will be used
11107 * instead (either the default or given value).
11109 * @default No data available in table
11112 * @name DataTable.defaults.language.emptyTable
11115 * $(document).ready( function() {
11116 * $('#example').dataTable( {
11118 * "emptyTable": "No data available in table"
11123 "sEmptyTable": "No data available in table",
11127 * This string gives information to the end user about the information
11128 * that is current on display on the page. The following tokens can be
11129 * used in the string and will be dynamically replaced as the table
11130 * display updates. This tokens can be placed anywhere in the string, or
11131 * removed as needed by the language requires:
11133 * * `\_START\_` - Display index of the first record on the current page
11134 * * `\_END\_` - Display index of the last record on the current page
11135 * * `\_TOTAL\_` - Number of records in the table after filtering
11136 * * `\_MAX\_` - Number of records in the table without filtering
11137 * * `\_PAGE\_` - Current page number
11138 * * `\_PAGES\_` - Total number of pages of data in the table
11141 * @default Showing _START_ to _END_ of _TOTAL_ entries
11144 * @name DataTable.defaults.language.info
11147 * $(document).ready( function() {
11148 * $('#example').dataTable( {
11150 * "info": "Showing page _PAGE_ of _PAGES_"
11155 "sInfo": "Showing _START_ to _END_ of _TOTAL_ entries",
11159 * Display information string for when the table is empty. Typically the
11160 * format of this string should match `info`.
11162 * @default Showing 0 to 0 of 0 entries
11165 * @name DataTable.defaults.language.infoEmpty
11168 * $(document).ready( function() {
11169 * $('#example').dataTable( {
11171 * "infoEmpty": "No entries to show"
11176 "sInfoEmpty": "Showing 0 to 0 of 0 entries",
11180 * When a user filters the information in a table, this string is appended
11181 * to the information (`info`) to give an idea of how strong the filtering
11182 * is. The variable _MAX_ is dynamically updated.
11184 * @default (filtered from _MAX_ total entries)
11187 * @name DataTable.defaults.language.infoFiltered
11190 * $(document).ready( function() {
11191 * $('#example').dataTable( {
11193 * "infoFiltered": " - filtering from _MAX_ records"
11198 "sInfoFiltered": "(filtered from _MAX_ total entries)",
11202 * If can be useful to append extra information to the info string at times,
11203 * and this variable does exactly that. This information will be appended to
11204 * the `info` (`infoEmpty` and `infoFiltered` in whatever combination they are
11205 * being used) at all times.
11207 * @default <i>Empty string</i>
11210 * @name DataTable.defaults.language.infoPostFix
11213 * $(document).ready( function() {
11214 * $('#example').dataTable( {
11216 * "infoPostFix": "All records shown are derived from real information."
11221 "sInfoPostFix": "",
11225 * This decimal place operator is a little different from the other
11226 * language options since DataTables doesn't output floating point
11227 * numbers, so it won't ever use this for display of a number. Rather,
11228 * what this parameter does is modify the sort methods of the table so
11229 * that numbers which are in a format which has a character other than
11230 * a period (`.`) as a decimal place will be sorted numerically.
11232 * Note that numbers with different decimal places cannot be shown in
11233 * the same table and still be sortable, the table must be consistent.
11234 * However, multiple different tables on the page can use different
11235 * decimal place characters.
11240 * @name DataTable.defaults.language.decimal
11243 * $(document).ready( function() {
11244 * $('#example').dataTable( {
11256 * DataTables has a build in number formatter (`formatNumber`) which is
11257 * used to format large numbers that are used in the table information.
11258 * By default a comma is used, but this can be trivially changed to any
11259 * character you wish with this parameter.
11264 * @name DataTable.defaults.language.thousands
11267 * $(document).ready( function() {
11268 * $('#example').dataTable( {
11279 * Detail the action that will be taken when the drop down menu for the
11280 * pagination length option is changed. The '_MENU_' variable is replaced
11281 * with a default select list of 10, 25, 50 and 100, and can be replaced
11282 * with a custom select box if required.
11284 * @default Show _MENU_ entries
11287 * @name DataTable.defaults.language.lengthMenu
11290 * // Language change only
11291 * $(document).ready( function() {
11292 * $('#example').dataTable( {
11294 * "lengthMenu": "Display _MENU_ records"
11300 * // Language and options change
11301 * $(document).ready( function() {
11302 * $('#example').dataTable( {
11304 * "lengthMenu": 'Display <select>'+
11305 * '<option value="10">10</option>'+
11306 * '<option value="20">20</option>'+
11307 * '<option value="30">30</option>'+
11308 * '<option value="40">40</option>'+
11309 * '<option value="50">50</option>'+
11310 * '<option value="-1">All</option>'+
11311 * '</select> records'
11316 "sLengthMenu": "Show _MENU_ entries",
11320 * When using Ajax sourced data and during the first draw when DataTables is
11321 * gathering the data, this message is shown in an empty row in the table to
11322 * indicate to the end user the the data is being loaded. Note that this
11323 * parameter is not used when loading data by server-side processing, just
11324 * Ajax sourced data with client-side processing.
11326 * @default Loading...
11329 * @name DataTable.defaults.language.loadingRecords
11332 * $(document).ready( function() {
11333 * $('#example').dataTable( {
11335 * "loadingRecords": "Please wait - loading..."
11340 "sLoadingRecords": "Loading...",
11344 * Text which is displayed when the table is processing a user action
11345 * (usually a sort command or similar).
11347 * @default Processing...
11350 * @name DataTable.defaults.language.processing
11353 * $(document).ready( function() {
11354 * $('#example').dataTable( {
11356 * "processing": "DataTables is currently busy"
11361 "sProcessing": "Processing...",
11365 * Details the actions that will be taken when the user types into the
11366 * filtering input text box. The variable "_INPUT_", if used in the string,
11367 * is replaced with the HTML text box for the filtering input allowing
11368 * control over where it appears in the string. If "_INPUT_" is not given
11369 * then the input box is appended to the string automatically.
11374 * @name DataTable.defaults.language.search
11377 * // Input text box will be appended at the end automatically
11378 * $(document).ready( function() {
11379 * $('#example').dataTable( {
11381 * "search": "Filter records:"
11387 * // Specify where the filter should appear
11388 * $(document).ready( function() {
11389 * $('#example').dataTable( {
11391 * "search": "Apply filter _INPUT_ to table"
11396 "sSearch": "Search:",
11400 * Assign a `placeholder` attribute to the search `input` element
11405 * @name DataTable.defaults.language.searchPlaceholder
11407 "sSearchPlaceholder": "",
11411 * All of the language information can be stored in a file on the
11412 * server-side, which DataTables will look up if this parameter is passed.
11413 * It must store the URL of the language file, which is in a JSON format,
11414 * and the object has the same properties as the oLanguage object in the
11415 * initialiser object (i.e. the above parameters). Please refer to one of
11416 * the example language files to see how this works in action.
11418 * @default <i>Empty string - i.e. disabled</i>
11421 * @name DataTable.defaults.language.url
11424 * $(document).ready( function() {
11425 * $('#example').dataTable( {
11427 * "url": "http://www.sprymedia.co.uk/dataTables/lang.txt"
11436 * Text shown inside the table records when the is no information to be
11437 * displayed after filtering. `emptyTable` is shown when there is simply no
11438 * information in the table at all (regardless of filtering).
11440 * @default No matching records found
11443 * @name DataTable.defaults.language.zeroRecords
11446 * $(document).ready( function() {
11447 * $('#example').dataTable( {
11449 * "zeroRecords": "No records to display"
11454 "sZeroRecords": "No matching records found"
11459 * This parameter allows you to have define the global filtering state at
11460 * initialisation time. As an object the `search` parameter must be
11461 * defined, but all other parameters are optional. When `regex` is true,
11462 * the search string will be treated as a regular expression, when false
11463 * (default) it will be treated as a straight string. When `smart`
11464 * DataTables will use it's smart filtering methods (to word match at
11465 * any point in the data), when false this will not be done.
11467 * @extends DataTable.models.oSearch
11470 * @name DataTable.defaults.search
11473 * $(document).ready( function() {
11474 * $('#example').dataTable( {
11475 * "search": {"search": "Initial search"}
11479 "oSearch": $.extend( {}, DataTable
.models
.oSearch
),
11483 * __Deprecated__ The functionality provided by this parameter has now been
11484 * superseded by that provided through `ajax`, which should be used instead.
11486 * By default DataTables will look for the property `data` (or `aaData` for
11487 * compatibility with DataTables 1.9-) when obtaining data from an Ajax
11488 * source or for server-side processing - this parameter allows that
11489 * property to be changed. You can use Javascript dotted object notation to
11490 * get a data source for multiple levels of nesting.
11495 * @dtopt Server-side
11496 * @name DataTable.defaults.ajaxDataProp
11498 * @deprecated 1.10. Please use `ajax` for this functionality now.
11500 "sAjaxDataProp": "data",
11504 * __Deprecated__ The functionality provided by this parameter has now been
11505 * superseded by that provided through `ajax`, which should be used instead.
11507 * You can instruct DataTables to load data from an external
11508 * source using this parameter (use aData if you want to pass data in you
11509 * already have). Simply provide a url a JSON object can be obtained from.
11514 * @dtopt Server-side
11515 * @name DataTable.defaults.ajaxSource
11517 * @deprecated 1.10. Please use `ajax` for this functionality now.
11519 "sAjaxSource": null,
11523 * This initialisation variable allows you to specify exactly where in the
11524 * DOM you want DataTables to inject the various controls it adds to the page
11525 * (for example you might want the pagination controls at the top of the
11526 * table). DIV elements (with or without a custom class) can also be added to
11527 * aid styling. The follow syntax is used:
11529 * <li>The following options are allowed:
11531 * <li>'l' - Length changing</li>
11532 * <li>'f' - Filtering input</li>
11533 * <li>'t' - The table!</li>
11534 * <li>'i' - Information</li>
11535 * <li>'p' - Pagination</li>
11536 * <li>'r' - pRocessing</li>
11539 * <li>The following constants are allowed:
11541 * <li>'H' - jQueryUI theme "header" classes ('fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix')</li>
11542 * <li>'F' - jQueryUI theme "footer" classes ('fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix')</li>
11545 * <li>The following syntax is expected:
11547 * <li>'<' and '>' - div elements</li>
11548 * <li>'<"class" and '>' - div with a class</li>
11549 * <li>'<"#id" and '>' - div with an ID</li>
11554 * <li>'<"wrapper"flipt>'</li>
11555 * <li>'<lf<t>ip>'</li>
11560 * @default lfrtip <i>(when `jQueryUI` is false)</i> <b>or</b>
11561 * <"H"lfr>t<"F"ip> <i>(when `jQueryUI` is true)</i>
11564 * @name DataTable.defaults.dom
11567 * $(document).ready( function() {
11568 * $('#example').dataTable( {
11569 * "dom": '<"top"i>rt<"bottom"flp><"clear">'
11577 * Search delay option. This will throttle full table searches that use the
11578 * DataTables provided search input element (it does not effect calls to
11579 * `dt-api search()`, providing a delay before the search is made.
11584 * @name DataTable.defaults.searchDelay
11587 * $(document).ready( function() {
11588 * $('#example').dataTable( {
11589 * "searchDelay": 200
11593 "searchDelay": null,
11597 * DataTables features four different built-in options for the buttons to
11598 * display for pagination control:
11600 * * `simple` - 'Previous' and 'Next' buttons only
11601 * * 'simple_numbers` - 'Previous' and 'Next' buttons, plus page numbers
11602 * * `full` - 'First', 'Previous', 'Next' and 'Last' buttons
11603 * * `full_numbers` - 'First', 'Previous', 'Next' and 'Last' buttons, plus
11606 * Further methods can be added using {@link DataTable.ext.oPagination}.
11608 * @default simple_numbers
11611 * @name DataTable.defaults.pagingType
11614 * $(document).ready( function() {
11615 * $('#example').dataTable( {
11616 * "pagingType": "full_numbers"
11620 "sPaginationType": "simple_numbers",
11624 * Enable horizontal scrolling. When a table is too wide to fit into a
11625 * certain layout, or you have a large number of columns in the table, you
11626 * can enable x-scrolling to show the table in a viewport, which can be
11627 * scrolled. This property can be `true` which will allow the table to
11628 * scroll horizontally when needed, or any CSS unit, or a number (in which
11629 * case it will be treated as a pixel measurement). Setting as simply `true`
11631 * @type boolean|string
11632 * @default <i>blank string - i.e. disabled</i>
11635 * @name DataTable.defaults.scrollX
11638 * $(document).ready( function() {
11639 * $('#example').dataTable( {
11641 * "scrollCollapse": true
11649 * This property can be used to force a DataTable to use more width than it
11650 * might otherwise do when x-scrolling is enabled. For example if you have a
11651 * table which requires to be well spaced, this parameter is useful for
11652 * "over-sizing" the table, and thus forcing scrolling. This property can by
11653 * any CSS unit, or a number (in which case it will be treated as a pixel
11656 * @default <i>blank string - i.e. disabled</i>
11659 * @name DataTable.defaults.scrollXInner
11662 * $(document).ready( function() {
11663 * $('#example').dataTable( {
11664 * "scrollX": "100%",
11665 * "scrollXInner": "110%"
11669 "sScrollXInner": "",
11673 * Enable vertical scrolling. Vertical scrolling will constrain the DataTable
11674 * to the given height, and enable scrolling for any data which overflows the
11675 * current viewport. This can be used as an alternative to paging to display
11676 * a lot of data in a small area (although paging and scrolling can both be
11677 * enabled at the same time). This property can be any CSS unit, or a number
11678 * (in which case it will be treated as a pixel measurement).
11680 * @default <i>blank string - i.e. disabled</i>
11683 * @name DataTable.defaults.scrollY
11686 * $(document).ready( function() {
11687 * $('#example').dataTable( {
11688 * "scrollY": "200px",
11689 * "paginate": false
11697 * __Deprecated__ The functionality provided by this parameter has now been
11698 * superseded by that provided through `ajax`, which should be used instead.
11700 * Set the HTTP method that is used to make the Ajax call for server-side
11701 * processing or Ajax sourced data.
11706 * @dtopt Server-side
11707 * @name DataTable.defaults.serverMethod
11709 * @deprecated 1.10. Please use `ajax` for this functionality now.
11711 "sServerMethod": "GET",
11715 * DataTables makes use of renderers when displaying HTML elements for
11716 * a table. These renderers can be added or modified by plug-ins to
11717 * generate suitable mark-up for a site. For example the Bootstrap
11718 * integration plug-in for DataTables uses a paging button renderer to
11719 * display pagination buttons in the mark-up required by Bootstrap.
11721 * For further information about the renderers available see
11722 * DataTable.ext.renderer
11723 * @type string|object
11726 * @name DataTable.defaults.renderer
11732 _fnHungarianMap( DataTable
.defaults
);
11737 * Developer note - See note in model.defaults.js about the use of Hungarian
11738 * notation and camel case.
11742 * Column options that can be given to DataTables at initialisation time.
11745 DataTable
.defaults
.column
= {
11747 * Define which column(s) an order will occur on for this column. This
11748 * allows a column's ordering to take multiple columns into account when
11749 * doing a sort or use the data from a different column. For example first
11750 * name / last name columns make sense to do a multi-column sort over the
11753 * @default null <i>Takes the value of the column index automatically</i>
11755 * @name DataTable.defaults.column.orderData
11759 * // Using `columnDefs`
11760 * $(document).ready( function() {
11761 * $('#example').dataTable( {
11763 * { "orderData": [ 0, 1 ], "targets": [ 0 ] },
11764 * { "orderData": [ 1, 0 ], "targets": [ 1 ] },
11765 * { "orderData": 2, "targets": [ 2 ] }
11771 * // Using `columns`
11772 * $(document).ready( function() {
11773 * $('#example').dataTable( {
11775 * { "orderData": [ 0, 1 ] },
11776 * { "orderData": [ 1, 0 ] },
11777 * { "orderData": 2 },
11789 * You can control the default ordering direction, and even alter the
11790 * behaviour of the sort handler (i.e. only allow ascending ordering etc)
11791 * using this parameter.
11793 * @default [ 'asc', 'desc' ]
11795 * @name DataTable.defaults.column.orderSequence
11799 * // Using `columnDefs`
11800 * $(document).ready( function() {
11801 * $('#example').dataTable( {
11803 * { "orderSequence": [ "asc" ], "targets": [ 1 ] },
11804 * { "orderSequence": [ "desc", "asc", "asc" ], "targets": [ 2 ] },
11805 * { "orderSequence": [ "desc" ], "targets": [ 3 ] }
11811 * // Using `columns`
11812 * $(document).ready( function() {
11813 * $('#example').dataTable( {
11816 * { "orderSequence": [ "asc" ] },
11817 * { "orderSequence": [ "desc", "asc", "asc" ] },
11818 * { "orderSequence": [ "desc" ] },
11824 "asSorting": [ 'asc', 'desc' ],
11828 * Enable or disable filtering on the data in this column.
11832 * @name DataTable.defaults.column.searchable
11836 * // Using `columnDefs`
11837 * $(document).ready( function() {
11838 * $('#example').dataTable( {
11840 * { "searchable": false, "targets": [ 0 ] }
11845 * // Using `columns`
11846 * $(document).ready( function() {
11847 * $('#example').dataTable( {
11849 * { "searchable": false },
11857 "bSearchable": true,
11861 * Enable or disable ordering on this column.
11865 * @name DataTable.defaults.column.orderable
11869 * // Using `columnDefs`
11870 * $(document).ready( function() {
11871 * $('#example').dataTable( {
11873 * { "orderable": false, "targets": [ 0 ] }
11878 * // Using `columns`
11879 * $(document).ready( function() {
11880 * $('#example').dataTable( {
11882 * { "orderable": false },
11894 * Enable or disable the display of this column.
11898 * @name DataTable.defaults.column.visible
11902 * // Using `columnDefs`
11903 * $(document).ready( function() {
11904 * $('#example').dataTable( {
11906 * { "visible": false, "targets": [ 0 ] }
11911 * // Using `columns`
11912 * $(document).ready( function() {
11913 * $('#example').dataTable( {
11915 * { "visible": false },
11927 * Developer definable function that is called whenever a cell is created (Ajax source,
11928 * etc) or processed for input (DOM source). This can be used as a compliment to mRender
11929 * allowing you to modify the DOM element (add background colour for example) when the
11930 * element is available.
11932 * @param {element} td The TD node that has been created
11933 * @param {*} cellData The Data for the cell
11934 * @param {array|object} rowData The data for the whole row
11935 * @param {int} row The row index for the aoData data store
11936 * @param {int} col The column index for aoColumns
11938 * @name DataTable.defaults.column.createdCell
11942 * $(document).ready( function() {
11943 * $('#example').dataTable( {
11944 * "columnDefs": [ {
11946 * "createdCell": function (td, cellData, rowData, row, col) {
11947 * if ( cellData == "1.7" ) {
11948 * $(td).css('color', 'blue')
11955 "fnCreatedCell": null,
11959 * This parameter has been replaced by `data` in DataTables to ensure naming
11960 * consistency. `dataProp` can still be used, as there is backwards
11961 * compatibility in DataTables for this option, but it is strongly
11962 * recommended that you use `data` in preference to `dataProp`.
11963 * @name DataTable.defaults.column.dataProp
11968 * This property can be used to read data from any data source property,
11969 * including deeply nested objects / properties. `data` can be given in a
11970 * number of different ways which effect its behaviour:
11972 * * `integer` - treated as an array index for the data source. This is the
11973 * default that DataTables uses (incrementally increased for each column).
11974 * * `string` - read an object property from the data source. There are
11975 * three 'special' options that can be used in the string to alter how
11976 * DataTables reads the data from the source object:
11977 * * `.` - Dotted Javascript notation. Just as you use a `.` in
11978 * Javascript to read from nested objects, so to can the options
11979 * specified in `data`. For example: `browser.version` or
11980 * `browser.name`. If your object parameter name contains a period, use
11981 * `\\` to escape it - i.e. `first\\.name`.
11982 * * `[]` - Array notation. DataTables can automatically combine data
11983 * from and array source, joining the data with the characters provided
11984 * between the two brackets. For example: `name[, ]` would provide a
11985 * comma-space separated list from the source array. If no characters
11986 * are provided between the brackets, the original array source is
11988 * * `()` - Function notation. Adding `()` to the end of a parameter will
11989 * execute a function of the name given. For example: `browser()` for a
11990 * simple function on the data source, `browser.version()` for a
11991 * function in a nested property or even `browser().version` to get an
11992 * object property if the function called returns an object. Note that
11993 * function notation is recommended for use in `render` rather than
11994 * `data` as it is much simpler to use as a renderer.
11995 * * `null` - use the original data source for the row rather than plucking
11996 * data directly from it. This action has effects on two other
11997 * initialisation options:
11998 * * `defaultContent` - When null is given as the `data` option and
11999 * `defaultContent` is specified for the column, the value defined by
12000 * `defaultContent` will be used for the cell.
12001 * * `render` - When null is used for the `data` option and the `render`
12002 * option is specified for the column, the whole data source for the
12003 * row is used for the renderer.
12004 * * `function` - the function given will be executed whenever DataTables
12005 * needs to set or get the data for a cell in the column. The function
12006 * takes three parameters:
12008 * * `{array|object}` The data source for the row
12009 * * `{string}` The type call data requested - this will be 'set' when
12010 * setting data or 'filter', 'display', 'type', 'sort' or undefined
12011 * when gathering data. Note that when `undefined` is given for the
12012 * type DataTables expects to get the raw data for the object back<
12013 * * `{*}` Data to set when the second parameter is 'set'.
12015 * * The return value from the function is not required when 'set' is
12016 * the type of call, but otherwise the return is what will be used
12017 * for the data requested.
12019 * Note that `data` is a getter and setter option. If you just require
12020 * formatting of data for output, you will likely want to use `render` which
12021 * is simply a getter and thus simpler to use.
12023 * Note that prior to DataTables 1.9.2 `data` was called `mDataProp`. The
12024 * name change reflects the flexibility of this property and is consistent
12025 * with the naming of mRender. If 'mDataProp' is given, then it will still
12026 * be used by DataTables, as it automatically maps the old name to the new
12029 * @type string|int|function|null
12030 * @default null <i>Use automatically calculated column index</i>
12032 * @name DataTable.defaults.column.data
12036 * // Read table data from objects
12037 * // JSON structure for each row:
12039 * // "engine": {value},
12040 * // "browser": {value},
12041 * // "platform": {value},
12042 * // "version": {value},
12043 * // "grade": {value}
12045 * $(document).ready( function() {
12046 * $('#example').dataTable( {
12047 * "ajaxSource": "sources/objects.txt",
12049 * { "data": "engine" },
12050 * { "data": "browser" },
12051 * { "data": "platform" },
12052 * { "data": "version" },
12053 * { "data": "grade" }
12059 * // Read information from deeply nested objects
12060 * // JSON structure for each row:
12062 * // "engine": {value},
12063 * // "browser": {value},
12065 * // "inner": {value}
12068 * // {value}, {value}
12071 * $(document).ready( function() {
12072 * $('#example').dataTable( {
12073 * "ajaxSource": "sources/deep.txt",
12075 * { "data": "engine" },
12076 * { "data": "browser" },
12077 * { "data": "platform.inner" },
12078 * { "data": "platform.details.0" },
12079 * { "data": "platform.details.1" }
12085 * // Using `data` as a function to provide different information for
12086 * // sorting, filtering and display. In this case, currency (price)
12087 * $(document).ready( function() {
12088 * $('#example').dataTable( {
12089 * "columnDefs": [ {
12090 * "targets": [ 0 ],
12091 * "data": function ( source, type, val ) {
12092 * if (type === 'set') {
12093 * source.price = val;
12094 * // Store the computed dislay and filter values for efficiency
12095 * source.price_display = val=="" ? "" : "$"+numberFormat(val);
12096 * source.price_filter = val=="" ? "" : "$"+numberFormat(val)+" "+val;
12099 * else if (type === 'display') {
12100 * return source.price_display;
12102 * else if (type === 'filter') {
12103 * return source.price_filter;
12105 * // 'sort', 'type' and undefined all just use the integer
12106 * return source.price;
12113 * // Using default content
12114 * $(document).ready( function() {
12115 * $('#example').dataTable( {
12116 * "columnDefs": [ {
12117 * "targets": [ 0 ],
12119 * "defaultContent": "Click to edit"
12125 * // Using array notation - outputting a list from an array
12126 * $(document).ready( function() {
12127 * $('#example').dataTable( {
12128 * "columnDefs": [ {
12129 * "targets": [ 0 ],
12130 * "data": "name[, ]"
12140 * This property is the rendering partner to `data` and it is suggested that
12141 * when you want to manipulate data for display (including filtering,
12142 * sorting etc) without altering the underlying data for the table, use this
12143 * property. `render` can be considered to be the the read only companion to
12144 * `data` which is read / write (then as such more complex). Like `data`
12145 * this option can be given in a number of different ways to effect its
12148 * * `integer` - treated as an array index for the data source. This is the
12149 * default that DataTables uses (incrementally increased for each column).
12150 * * `string` - read an object property from the data source. There are
12151 * three 'special' options that can be used in the string to alter how
12152 * DataTables reads the data from the source object:
12153 * * `.` - Dotted Javascript notation. Just as you use a `.` in
12154 * Javascript to read from nested objects, so to can the options
12155 * specified in `data`. For example: `browser.version` or
12156 * `browser.name`. If your object parameter name contains a period, use
12157 * `\\` to escape it - i.e. `first\\.name`.
12158 * * `[]` - Array notation. DataTables can automatically combine data
12159 * from and array source, joining the data with the characters provided
12160 * between the two brackets. For example: `name[, ]` would provide a
12161 * comma-space separated list from the source array. If no characters
12162 * are provided between the brackets, the original array source is
12164 * * `()` - Function notation. Adding `()` to the end of a parameter will
12165 * execute a function of the name given. For example: `browser()` for a
12166 * simple function on the data source, `browser.version()` for a
12167 * function in a nested property or even `browser().version` to get an
12168 * object property if the function called returns an object.
12169 * * `object` - use different data for the different data types requested by
12170 * DataTables ('filter', 'display', 'type' or 'sort'). The property names
12171 * of the object is the data type the property refers to and the value can
12172 * defined using an integer, string or function using the same rules as
12173 * `render` normally does. Note that an `_` option _must_ be specified.
12174 * This is the default value to use if you haven't specified a value for
12175 * the data type requested by DataTables.
12176 * * `function` - the function given will be executed whenever DataTables
12177 * needs to set or get the data for a cell in the column. The function
12178 * takes three parameters:
12180 * * {array|object} The data source for the row (based on `data`)
12181 * * {string} The type call data requested - this will be 'filter',
12182 * 'display', 'type' or 'sort'.
12183 * * {array|object} The full data source for the row (not based on
12186 * * The return value from the function is what will be used for the
12189 * @type string|int|function|object|null
12190 * @default null Use the data source value.
12192 * @name DataTable.defaults.column.render
12196 * // Create a comma separated list from an array of objects
12197 * $(document).ready( function() {
12198 * $('#example').dataTable( {
12199 * "ajaxSource": "sources/deep.txt",
12201 * { "data": "engine" },
12202 * { "data": "browser" },
12204 * "data": "platform",
12205 * "render": "[, ].name"
12212 * // Execute a function to obtain data
12213 * $(document).ready( function() {
12214 * $('#example').dataTable( {
12215 * "columnDefs": [ {
12216 * "targets": [ 0 ],
12217 * "data": null, // Use the full data source object for the renderer's source
12218 * "render": "browserName()"
12224 * // As an object, extracting different data for the different types
12225 * // This would be used with a data source such as:
12226 * // { "phone": 5552368, "phone_filter": "5552368 555-2368", "phone_display": "555-2368" }
12227 * // Here the `phone` integer is used for sorting and type detection, while `phone_filter`
12228 * // (which has both forms) is used for filtering for if a user inputs either format, while
12229 * // the formatted phone number is the one that is shown in the table.
12230 * $(document).ready( function() {
12231 * $('#example').dataTable( {
12232 * "columnDefs": [ {
12233 * "targets": [ 0 ],
12234 * "data": null, // Use the full data source object for the renderer's source
12237 * "filter": "phone_filter",
12238 * "display": "phone_display"
12245 * // Use as a function to create a link from the data source
12246 * $(document).ready( function() {
12247 * $('#example').dataTable( {
12248 * "columnDefs": [ {
12249 * "targets": [ 0 ],
12250 * "data": "download_link",
12251 * "render": function ( data, type, full ) {
12252 * return '<a href="'+data+'">Download</a>';
12262 * Change the cell type created for the column - either TD cells or TH cells. This
12263 * can be useful as TH cells have semantic meaning in the table body, allowing them
12264 * to act as a header for a row (you may wish to add scope='row' to the TH elements).
12268 * @name DataTable.defaults.column.cellType
12272 * // Make the first column use TH cells
12273 * $(document).ready( function() {
12274 * $('#example').dataTable( {
12275 * "columnDefs": [ {
12276 * "targets": [ 0 ],
12286 * Class to give to each cell in this column.
12288 * @default <i>Empty string</i>
12290 * @name DataTable.defaults.column.class
12294 * // Using `columnDefs`
12295 * $(document).ready( function() {
12296 * $('#example').dataTable( {
12298 * { "class": "my_class", "targets": [ 0 ] }
12304 * // Using `columns`
12305 * $(document).ready( function() {
12306 * $('#example').dataTable( {
12308 * { "class": "my_class" },
12320 * When DataTables calculates the column widths to assign to each column,
12321 * it finds the longest string in each column and then constructs a
12322 * temporary table and reads the widths from that. The problem with this
12323 * is that "mmm" is much wider then "iiii", but the latter is a longer
12324 * string - thus the calculation can go wrong (doing it properly and putting
12325 * it into an DOM object and measuring that is horribly(!) slow). Thus as
12326 * a "work around" we provide this option. It will append its value to the
12327 * text that is found to be the longest string for the column - i.e. padding.
12328 * Generally you shouldn't need this!
12330 * @default <i>Empty string<i>
12332 * @name DataTable.defaults.column.contentPadding
12336 * // Using `columns`
12337 * $(document).ready( function() {
12338 * $('#example').dataTable( {
12344 * "contentPadding": "mmm"
12350 "sContentPadding": "",
12354 * Allows a default value to be given for a column's data, and will be used
12355 * whenever a null data source is encountered (this can be because `data`
12356 * is set to null, or because the data source itself is null).
12360 * @name DataTable.defaults.column.defaultContent
12364 * // Using `columnDefs`
12365 * $(document).ready( function() {
12366 * $('#example').dataTable( {
12370 * "defaultContent": "Edit",
12371 * "targets": [ -1 ]
12378 * // Using `columns`
12379 * $(document).ready( function() {
12380 * $('#example').dataTable( {
12387 * "defaultContent": "Edit"
12393 "sDefaultContent": null,
12397 * This parameter is only used in DataTables' server-side processing. It can
12398 * be exceptionally useful to know what columns are being displayed on the
12399 * client side, and to map these to database fields. When defined, the names
12400 * also allow DataTables to reorder information from the server if it comes
12401 * back in an unexpected order (i.e. if you switch your columns around on the
12402 * client-side, your server-side code does not also need updating).
12404 * @default <i>Empty string</i>
12406 * @name DataTable.defaults.column.name
12410 * // Using `columnDefs`
12411 * $(document).ready( function() {
12412 * $('#example').dataTable( {
12414 * { "name": "engine", "targets": [ 0 ] },
12415 * { "name": "browser", "targets": [ 1 ] },
12416 * { "name": "platform", "targets": [ 2 ] },
12417 * { "name": "version", "targets": [ 3 ] },
12418 * { "name": "grade", "targets": [ 4 ] }
12424 * // Using `columns`
12425 * $(document).ready( function() {
12426 * $('#example').dataTable( {
12428 * { "name": "engine" },
12429 * { "name": "browser" },
12430 * { "name": "platform" },
12431 * { "name": "version" },
12432 * { "name": "grade" }
12441 * Defines a data source type for the ordering which can be used to read
12442 * real-time information from the table (updating the internally cached
12443 * version) prior to ordering. This allows ordering to occur on user
12444 * editable elements such as form inputs.
12448 * @name DataTable.defaults.column.orderDataType
12452 * // Using `columnDefs`
12453 * $(document).ready( function() {
12454 * $('#example').dataTable( {
12456 * { "orderDataType": "dom-text", "targets": [ 2, 3 ] },
12457 * { "type": "numeric", "targets": [ 3 ] },
12458 * { "orderDataType": "dom-select", "targets": [ 4 ] },
12459 * { "orderDataType": "dom-checkbox", "targets": [ 5 ] }
12465 * // Using `columns`
12466 * $(document).ready( function() {
12467 * $('#example').dataTable( {
12471 * { "orderDataType": "dom-text" },
12472 * { "orderDataType": "dom-text", "type": "numeric" },
12473 * { "orderDataType": "dom-select" },
12474 * { "orderDataType": "dom-checkbox" }
12479 "sSortDataType": "std",
12483 * The title of this column.
12485 * @default null <i>Derived from the 'TH' value for this column in the
12486 * original HTML table.</i>
12488 * @name DataTable.defaults.column.title
12492 * // Using `columnDefs`
12493 * $(document).ready( function() {
12494 * $('#example').dataTable( {
12496 * { "title": "My column title", "targets": [ 0 ] }
12502 * // Using `columns`
12503 * $(document).ready( function() {
12504 * $('#example').dataTable( {
12506 * { "title": "My column title" },
12519 * The type allows you to specify how the data for this column will be
12520 * ordered. Four types (string, numeric, date and html (which will strip
12521 * HTML tags before ordering)) are currently available. Note that only date
12522 * formats understood by Javascript's Date() object will be accepted as type
12523 * date. For example: "Mar 26, 2008 5:03 PM". May take the values: 'string',
12524 * 'numeric', 'date' or 'html' (by default). Further types can be adding
12525 * through plug-ins.
12527 * @default null <i>Auto-detected from raw data</i>
12529 * @name DataTable.defaults.column.type
12533 * // Using `columnDefs`
12534 * $(document).ready( function() {
12535 * $('#example').dataTable( {
12537 * { "type": "html", "targets": [ 0 ] }
12543 * // Using `columns`
12544 * $(document).ready( function() {
12545 * $('#example').dataTable( {
12547 * { "type": "html" },
12560 * Defining the width of the column, this parameter may take any CSS value
12561 * (3em, 20px etc). DataTables applies 'smart' widths to columns which have not
12562 * been given a specific width through this interface ensuring that the table
12563 * remains readable.
12565 * @default null <i>Automatic</i>
12567 * @name DataTable.defaults.column.width
12571 * // Using `columnDefs`
12572 * $(document).ready( function() {
12573 * $('#example').dataTable( {
12575 * { "width": "20%", "targets": [ 0 ] }
12581 * // Using `columns`
12582 * $(document).ready( function() {
12583 * $('#example').dataTable( {
12585 * { "width": "20%" },
12597 _fnHungarianMap( DataTable
.defaults
.column
);
12602 * DataTables settings object - this holds all the information needed for a
12603 * given table, including configuration, data and current application of the
12604 * table options. DataTables does not have a single instance for each DataTable
12605 * with the settings attached to that instance, but rather instances of the
12606 * DataTable "class" are created on-the-fly as needed (typically by a
12607 * $().dataTable() call) and the settings object is then applied to that
12610 * Note that this object is related to {@link DataTable.defaults} but this
12611 * one is the internal data store for DataTables's cache of columns. It should
12612 * NOT be manipulated outside of DataTables. Any configuration should be done
12613 * through the initialisation options.
12615 * @todo Really should attach the settings object to individual instances so we
12616 * don't need to create new instances on each $().dataTable() call (if the
12617 * table already exists). It would also save passing oSettings around and
12618 * into every single function. However, this is a very significant
12619 * architecture change for DataTables and will almost certainly break
12620 * backwards compatibility with older installations. This is something that
12621 * will be done in 2.0.
12623 DataTable
.models
.oSettings
= {
12625 * Primary features of DataTables and their enablement state.
12631 * Flag to say if DataTables should automatically try to calculate the
12632 * optimum table and columns widths (true) or not (false).
12633 * Note that this parameter will be set by the initialisation routine. To
12634 * set a default use {@link DataTable.defaults}.
12637 "bAutoWidth": null,
12640 * Delay the creation of TR and TD elements until they are actually
12641 * needed by a driven page draw. This can give a significant speed
12642 * increase for Ajax source and Javascript source data, but makes no
12643 * difference at all fro DOM and server-side processing tables.
12644 * Note that this parameter will be set by the initialisation routine. To
12645 * set a default use {@link DataTable.defaults}.
12648 "bDeferRender": null,
12651 * Enable filtering on the table or not. Note that if this is disabled
12652 * then there is no filtering at all on the table, including fnFilter.
12653 * To just remove the filtering input use sDom and remove the 'f' option.
12654 * Note that this parameter will be set by the initialisation routine. To
12655 * set a default use {@link DataTable.defaults}.
12661 * Table information element (the 'Showing x of y records' div) enable
12663 * Note that this parameter will be set by the initialisation routine. To
12664 * set a default use {@link DataTable.defaults}.
12670 * Present a user control allowing the end user to change the page size
12671 * when pagination is enabled.
12672 * Note that this parameter will be set by the initialisation routine. To
12673 * set a default use {@link DataTable.defaults}.
12676 "bLengthChange": null,
12679 * Pagination enabled or not. Note that if this is disabled then length
12680 * changing must also be disabled.
12681 * Note that this parameter will be set by the initialisation routine. To
12682 * set a default use {@link DataTable.defaults}.
12688 * Processing indicator enable flag whenever DataTables is enacting a
12689 * user request - typically an Ajax request for server-side processing.
12690 * Note that this parameter will be set by the initialisation routine. To
12691 * set a default use {@link DataTable.defaults}.
12694 "bProcessing": null,
12697 * Server-side processing enabled flag - when enabled DataTables will
12698 * get all data from the server for every draw - there is no filtering,
12699 * sorting or paging done on the client-side.
12700 * Note that this parameter will be set by the initialisation routine. To
12701 * set a default use {@link DataTable.defaults}.
12704 "bServerSide": null,
12707 * Sorting enablement flag.
12708 * Note that this parameter will be set by the initialisation routine. To
12709 * set a default use {@link DataTable.defaults}.
12715 * Multi-column sorting
12716 * Note that this parameter will be set by the initialisation routine. To
12717 * set a default use {@link DataTable.defaults}.
12720 "bSortMulti": null,
12723 * Apply a class to the columns which are being sorted to provide a
12724 * visual highlight or not. This can slow things down when enabled since
12725 * there is a lot of DOM interaction.
12726 * Note that this parameter will be set by the initialisation routine. To
12727 * set a default use {@link DataTable.defaults}.
12730 "bSortClasses": null,
12733 * State saving enablement flag.
12734 * Note that this parameter will be set by the initialisation routine. To
12735 * set a default use {@link DataTable.defaults}.
12743 * Scrolling settings for a table.
12748 * When the table is shorter in height than sScrollY, collapse the
12749 * table container down to the height of the table (when true).
12750 * Note that this parameter will be set by the initialisation routine. To
12751 * set a default use {@link DataTable.defaults}.
12757 * Width of the scrollbar for the web-browser's platform. Calculated
12758 * during table initialisation.
12765 * Viewport width for horizontal scrolling. Horizontal scrolling is
12766 * disabled if an empty string.
12767 * Note that this parameter will be set by the initialisation routine. To
12768 * set a default use {@link DataTable.defaults}.
12774 * Width to expand the table to when using x-scrolling. Typically you
12775 * should not need to use this.
12776 * Note that this parameter will be set by the initialisation routine. To
12777 * set a default use {@link DataTable.defaults}.
12784 * Viewport height for vertical scrolling. Vertical scrolling is disabled
12785 * if an empty string.
12786 * Note that this parameter will be set by the initialisation routine. To
12787 * set a default use {@link DataTable.defaults}.
12794 * Language information for the table.
12796 * @extends DataTable.defaults.oLanguage
12800 * Information callback function. See
12801 * {@link DataTable.defaults.fnInfoCallback}
12805 "fnInfoCallback": null
12809 * Browser support parameters
12814 * Indicate if the browser incorrectly calculates width:100% inside a
12815 * scrolling element (IE6/7)
12819 "bScrollOversize": false,
12822 * Determine if the vertical scrollbar is on the right or left of the
12823 * scrolling container - needed for rtl language layout, although not
12824 * all browsers move the scrollbar (Safari).
12828 "bScrollbarLeft": false
12836 * Array referencing the nodes which are used for the features. The
12837 * parameters of this object match what is allowed by sDom - i.e.
12839 * <li>'l' - Length changing</li>
12840 * <li>'f' - Filtering input</li>
12841 * <li>'t' - The table!</li>
12842 * <li>'i' - Information</li>
12843 * <li>'p' - Pagination</li>
12844 * <li>'r' - pRocessing</li>
12852 * Store data information - see {@link DataTable.models.oRow} for detailed
12860 * Array of indexes which are in the current display (after filtering etc)
12867 * Array of indexes for display - no filtering
12871 "aiDisplayMaster": [],
12874 * Store information about each column that is in use
12881 * Store information about the table's header
12888 * Store information about the table's footer
12895 * Store the applied global search information in case we want to force a
12896 * research or compare the old search to a new one.
12897 * Note that this parameter will be set by the initialisation routine. To
12898 * set a default use {@link DataTable.defaults}.
12900 * @extends DataTable.models.oSearch
12902 "oPreviousSearch": {},
12905 * Store the applied search for each column - see
12906 * {@link DataTable.models.oSearch} for the format that is used for the
12907 * filtering information for each column.
12911 "aoPreSearchCols": [],
12914 * Sorting that is applied to the table. Note that the inner arrays are
12915 * used in the following manner:
12917 * <li>Index 0 - column number</li>
12918 * <li>Index 1 - current sorting direction</li>
12920 * Note that this parameter will be set by the initialisation routine. To
12921 * set a default use {@link DataTable.defaults}.
12923 * @todo These inner arrays should really be objects
12928 * Sorting that is always applied to the table (i.e. prefixed in front of
12930 * Note that this parameter will be set by the initialisation routine. To
12931 * set a default use {@link DataTable.defaults}.
12935 "aaSortingFixed": [],
12938 * Classes to use for the striping of a table.
12939 * Note that this parameter will be set by the initialisation routine. To
12940 * set a default use {@link DataTable.defaults}.
12944 "asStripeClasses": null,
12947 * If restoring a table - we should restore its striping classes as well
12951 "asDestroyStripes": [],
12954 * If restoring a table - we should restore its width
12958 "sDestroyWidth": 0,
12961 * Callback functions array for every time a row is inserted (i.e. on a draw).
12965 "aoRowCallback": [],
12968 * Callback functions for the header on each draw.
12972 "aoHeaderCallback": [],
12975 * Callback function for the footer on each draw.
12979 "aoFooterCallback": [],
12982 * Array of callback functions for draw callback functions
12986 "aoDrawCallback": [],
12989 * Array of callback functions for row created function
12993 "aoRowCreatedCallback": [],
12996 * Callback functions for just before the table is redrawn. A return of
12997 * false will be used to cancel the draw.
13001 "aoPreDrawCallback": [],
13004 * Callback functions for when the table has been initialised.
13008 "aoInitComplete": [],
13012 * Callbacks for modifying the settings to be stored for state saving, prior to
13017 "aoStateSaveParams": [],
13020 * Callbacks for modifying the settings that have been stored for state saving
13021 * prior to using the stored values to restore the state.
13025 "aoStateLoadParams": [],
13028 * Callbacks for operating on the settings object once the saved state has been
13033 "aoStateLoaded": [],
13036 * Cache the table ID for quick access
13038 * @default <i>Empty string</i>
13043 * The TABLE node for the main table
13050 * Permanent ref to the thead element
13057 * Permanent ref to the tfoot element - if it exists
13064 * Permanent ref to the tbody element
13071 * Cache the wrapper node (contains all DataTables controlled elements)
13075 "nTableWrapper": null,
13078 * Indicate if when using server-side processing the loading of data
13079 * should be deferred until the second draw.
13080 * Note that this parameter will be set by the initialisation routine. To
13081 * set a default use {@link DataTable.defaults}.
13085 "bDeferLoading": false,
13088 * Indicate if all required information has been read in
13092 "bInitialised": false,
13095 * Information about open rows. Each object in the array has the parameters
13096 * 'nTr' and 'nParent'
13103 * Dictate the positioning of DataTables' control elements - see
13104 * {@link DataTable.model.oInit.sDom}.
13105 * Note that this parameter will be set by the initialisation routine. To
13106 * set a default use {@link DataTable.defaults}.
13113 * Search delay (in mS)
13117 "searchDelay": null,
13120 * Which type of pagination should be used.
13121 * Note that this parameter will be set by the initialisation routine. To
13122 * set a default use {@link DataTable.defaults}.
13124 * @default two_button
13126 "sPaginationType": "two_button",
13129 * The state duration (for `stateSave`) in seconds.
13130 * Note that this parameter will be set by the initialisation routine. To
13131 * set a default use {@link DataTable.defaults}.
13135 "iStateDuration": 0,
13138 * Array of callback functions for state saving. Each array element is an
13139 * object with the following parameters:
13141 * <li>function:fn - function to call. Takes two parameters, oSettings
13142 * and the JSON string to save that has been thus far created. Returns
13143 * a JSON string to be inserted into a json object
13144 * (i.e. '"param": [ 0, 1, 2]')</li>
13145 * <li>string:sName - name of callback</li>
13153 * Array of callback functions for state loading. Each array element is an
13154 * object with the following parameters:
13156 * <li>function:fn - function to call. Takes two parameters, oSettings
13157 * and the object stored. May return false to cancel state loading</li>
13158 * <li>string:sName - name of callback</li>
13166 * State that was saved. Useful for back reference
13170 "oSavedState": null,
13173 * State that was loaded. Useful for back reference
13177 "oLoadedState": null,
13180 * Source url for AJAX data for the table.
13181 * Note that this parameter will be set by the initialisation routine. To
13182 * set a default use {@link DataTable.defaults}.
13186 "sAjaxSource": null,
13189 * Property from a given object from which to read the table data from. This
13190 * can be an empty string (when not server-side processing), in which case
13191 * it is assumed an an array is given directly.
13192 * Note that this parameter will be set by the initialisation routine. To
13193 * set a default use {@link DataTable.defaults}.
13196 "sAjaxDataProp": null,
13199 * Note if draw should be blocked while getting data
13203 "bAjaxDataGet": true,
13206 * The last jQuery XHR object that was used for server-side data gathering.
13207 * This can be used for working with the XHR information in one of the
13215 * JSON returned from the server in the last Ajax request
13217 * @default undefined
13222 * Data submitted as part of the last Ajax request
13224 * @default undefined
13226 "oAjaxData": undefined,
13229 * Function to get the server-side data.
13230 * Note that this parameter will be set by the initialisation routine. To
13231 * set a default use {@link DataTable.defaults}.
13234 "fnServerData": null,
13237 * Functions which are called prior to sending an Ajax request so extra
13238 * parameters can easily be sent to the server
13242 "aoServerParams": [],
13245 * Send the XHR HTTP method - GET or POST (could be PUT or DELETE if
13247 * Note that this parameter will be set by the initialisation routine. To
13248 * set a default use {@link DataTable.defaults}.
13251 "sServerMethod": null,
13254 * Format numbers for display.
13255 * Note that this parameter will be set by the initialisation routine. To
13256 * set a default use {@link DataTable.defaults}.
13259 "fnFormatNumber": null,
13262 * List of options that can be used for the user selectable length menu.
13263 * Note that this parameter will be set by the initialisation routine. To
13264 * set a default use {@link DataTable.defaults}.
13268 "aLengthMenu": null,
13271 * Counter for the draws that the table does. Also used as a tracker for
13272 * server-side processing
13279 * Indicate if a redraw is being done - useful for Ajax
13286 * Draw index (iDraw) of the last error when parsing the returned data
13293 * Paging display length
13297 "_iDisplayLength": 10,
13300 * Paging start point - aiDisplay index
13304 "_iDisplayStart": 0,
13307 * Server-side processing - number of records in the result set
13308 * (i.e. before filtering), Use fnRecordsTotal rather than
13309 * this property to get the value of the number of records, regardless of
13310 * the server-side processing setting.
13315 "_iRecordsTotal": 0,
13318 * Server-side processing - number of records in the current display set
13319 * (i.e. after filtering). Use fnRecordsDisplay rather than
13320 * this property to get the value of the number of records, regardless of
13321 * the server-side processing setting.
13326 "_iRecordsDisplay": 0,
13329 * Flag to indicate if jQuery UI marking and classes should be used.
13330 * Note that this parameter will be set by the initialisation routine. To
13331 * set a default use {@link DataTable.defaults}.
13337 * The classes to use for the table
13344 * Flag attached to the settings object so you can check in the draw
13345 * callback if filtering has been done in the draw. Deprecated in favour of
13351 "bFiltered": false,
13354 * Flag attached to the settings object so you can check in the draw
13355 * callback if sorting has been done in the draw. Deprecated in favour of
13364 * Indicate that if multiple rows are in the header and there is more than
13365 * one unique cell per column, if the top one (true) or bottom one (false)
13366 * should be used for sorting / title by DataTables.
13367 * Note that this parameter will be set by the initialisation routine. To
13368 * set a default use {@link DataTable.defaults}.
13371 "bSortCellsTop": null,
13374 * Initialisation object that is used for the table
13381 * Destroy callback functions - for plug-ins to attach themselves to the
13382 * destroy so they can clean up markup and events.
13386 "aoDestroyCallback": [],
13390 * Get the number of records in the current record set, before filtering
13393 "fnRecordsTotal": function ()
13395 return _fnDataSource( this ) == 'ssp' ?
13396 this._iRecordsTotal
* 1 :
13397 this.aiDisplayMaster
.length
;
13401 * Get the number of records in the current record set, after filtering
13404 "fnRecordsDisplay": function ()
13406 return _fnDataSource( this ) == 'ssp' ?
13407 this._iRecordsDisplay
* 1 :
13408 this.aiDisplay
.length
;
13412 * Get the display end point - aiDisplay index
13415 "fnDisplayEnd": function ()
13418 len
= this._iDisplayLength
,
13419 start
= this._iDisplayStart
,
13420 calc
= start
+ len
,
13421 records
= this.aiDisplay
.length
,
13422 features
= this.oFeatures
,
13423 paginate
= features
.bPaginate
;
13425 if ( features
.bServerSide
) {
13426 return paginate
=== false || len
=== -1 ?
13428 Math
.min( start
+len
, this._iRecordsDisplay
);
13431 return ! paginate
|| calc
>records
|| len
===-1 ?
13438 * The DataTables object for this table
13445 * Unique identifier for each instance of the DataTables object. If there
13446 * is an ID on the table node, then it takes that value, otherwise an
13447 * incrementing internal counter is used.
13454 * tabindex attribute value that is added to DataTables control elements, allowing
13455 * keyboard navigation of the table and its controls.
13460 * DIV container for the footer scrolling table if scrolling
13462 "nScrollHead": null,
13465 * DIV container for the footer scrolling table if scrolling
13467 "nScrollFoot": null,
13470 * Last applied sort
13477 * Stored plug-in instances
13485 * Extension object for DataTables that is used to provide all extension
13488 * Note that the `DataTable.ext` object is available through
13489 * `jQuery.fn.dataTable.ext` where it may be accessed and manipulated. It is
13490 * also aliased to `jQuery.fn.dataTableExt` for historic reasons.
13492 * @extends DataTable.models.ext
13497 * DataTables extensions
13499 * This namespace acts as a collection area for plug-ins that can be used to
13500 * extend DataTables capabilities. Indeed many of the build in methods
13501 * use this method to provide their own capabilities (sorting methods for
13504 * Note that this namespace is aliased to `jQuery.fn.dataTableExt` for legacy
13509 DataTable
.ext
= _ext
= {
13511 * Buttons. For use with the Buttons extension for DataTables. This is
13512 * defined here so other extensions can define buttons regardless of load
13513 * order. It is _not_ used by DataTables core.
13522 * Element class names
13533 * How should DataTables report an error. Can take the value 'alert',
13534 * 'throw', 'none' or a function.
13536 * @type string|function
13543 * Feature plug-ins.
13545 * This is an array of objects which describe the feature plug-ins that are
13546 * available to DataTables. These feature plug-ins are then available for
13547 * use through the `dom` initialisation option.
13549 * Each feature plug-in is described by an object which must have the
13550 * following properties:
13552 * * `fnInit` - function that is used to initialise the plug-in,
13553 * * `cFeature` - a character so the feature can be enabled by the `dom`
13554 * instillation option. This is case sensitive.
13556 * The `fnInit` function has the following input parameters:
13558 * 1. `{object}` DataTables settings object: see
13559 * {@link DataTable.models.oSettings}
13561 * And the following return is expected:
13563 * * {node|null} The element which contains your feature. Note that the
13564 * return may also be void if your plug-in does not require to inject any
13565 * DOM elements into DataTables control (`dom`) - for example this might
13566 * be useful when developing a plug-in which allows table control via
13572 * $.fn.dataTable.ext.features.push( {
13573 * "fnInit": function( oSettings ) {
13574 * return new TableTools( { "oDTSettings": oSettings } );
13585 * This method of searching is complimentary to the default type based
13586 * searching, and a lot more comprehensive as it allows you complete control
13587 * over the searching logic. Each element in this array is a function
13588 * (parameters described below) that is called for every row in the table,
13589 * and your logic decides if it should be included in the searching data set
13592 * Searching functions have the following input parameters:
13594 * 1. `{object}` DataTables settings object: see
13595 * {@link DataTable.models.oSettings}
13596 * 2. `{array|object}` Data for the row to be processed (same as the
13597 * original format that was passed in as the data source, or an array
13598 * from a DOM data source
13599 * 3. `{int}` Row index ({@link DataTable.models.oSettings.aoData}), which
13600 * can be useful to retrieve the `TR` element if you need DOM interaction.
13602 * And the following return is expected:
13604 * * {boolean} Include the row in the searched result set (true) or not
13607 * Note that as with the main search ability in DataTables, technically this
13608 * is "filtering", since it is subtractive. However, for consistency in
13609 * naming we call it searching here.
13615 * // The following example shows custom search being applied to the
13616 * // fourth column (i.e. the data[3] index) based on two input values
13617 * // from the end-user, matching the data in a certain range.
13618 * $.fn.dataTable.ext.search.push(
13619 * function( settings, data, dataIndex ) {
13620 * var min = document.getElementById('min').value * 1;
13621 * var max = document.getElementById('max').value * 1;
13622 * var version = data[3] == "-" ? 0 : data[3]*1;
13624 * if ( min == "" && max == "" ) {
13627 * else if ( min == "" && version < max ) {
13630 * else if ( min < version && "" == max ) {
13633 * else if ( min < version && version < max ) {
13644 * Selector extensions
13646 * The `selector` option can be used to extend the options available for the
13647 * selector modifier options (`selector-modifier` object data type) that
13648 * each of the three built in selector types offer (row, column and cell +
13649 * their plural counterparts). For example the Select extension uses this
13650 * mechanism to provide an option to select only rows, columns and cells
13651 * that have been marked as selected by the end user (`{selected: true}`),
13652 * which can be used in conjunction with the existing built in selector
13655 * Each property is an array to which functions can be pushed. The functions
13656 * take three attributes:
13658 * * Settings object for the host table
13659 * * Options object (`selector-modifier` object type)
13660 * * Array of selected item indexes
13662 * The return is an array of the resulting item indexes after the custom
13663 * selector has been applied.
13675 * Internal functions, exposed for used in plug-ins.
13677 * Please note that you should not need to use the internal methods for
13678 * anything other than a plug-in (and even then, try to avoid if possible).
13679 * The internal function may change between releases.
13688 * Legacy configuration options. Enable and disable legacy options that
13689 * are available in DataTables.
13695 * Enable / disable DataTables 1.9 compatible server-side processing
13706 * Pagination plug-in methods.
13708 * Each entry in this object is a function and defines which buttons should
13709 * be shown by the pagination rendering method that is used for the table:
13710 * {@link DataTable.ext.renderer.pageButton}. The renderer addresses how the
13711 * buttons are displayed in the document, while the functions here tell it
13712 * what buttons to display. This is done by returning an array of button
13713 * descriptions (what each button will do).
13715 * Pagination types (the four built in options and any additional plug-in
13716 * options defined here) can be used through the `paginationType`
13717 * initialisation parameter.
13719 * The functions defined take two parameters:
13721 * 1. `{int} page` The current page index
13722 * 2. `{int} pages` The number of pages in the table
13724 * Each function is expected to return an array where each element of the
13725 * array can be one of:
13727 * * `first` - Jump to first page when activated
13728 * * `last` - Jump to last page when activated
13729 * * `previous` - Show previous page when activated
13730 * * `next` - Show next page when activated
13731 * * `{int}` - Show page of the index given
13732 * * `{array}` - A nested array containing the above elements to add a
13733 * containing 'DIV' element (might be useful for styling).
13735 * Note that DataTables v1.9- used this object slightly differently whereby
13736 * an object with two functions would be defined for each plug-in. That
13737 * ability is still supported by DataTables 1.10+ to provide backwards
13738 * compatibility, but this option of use is now decremented and no longer
13739 * documented in DataTables 1.10+.
13745 * // Show previous, next and current page buttons only
13746 * $.fn.dataTableExt.oPagination.current = function ( page, pages ) {
13747 * return [ 'previous', page, 'next' ];
13760 * Ordering plug-ins - custom data source
13762 * The extension options for ordering of data available here is complimentary
13763 * to the default type based ordering that DataTables typically uses. It
13764 * allows much greater control over the the data that is being used to
13765 * order a column, but is necessarily therefore more complex.
13767 * This type of ordering is useful if you want to do ordering based on data
13768 * live from the DOM (for example the contents of an 'input' element) rather
13769 * than just the static string that DataTables knows of.
13771 * The way these plug-ins work is that you create an array of the values you
13772 * wish to be ordering for the column in question and then return that
13773 * array. The data in the array much be in the index order of the rows in
13774 * the table (not the currently ordering order!). Which order data gathering
13775 * function is run here depends on the `dt-init columns.orderDataType`
13776 * parameter that is used for the column (if any).
13778 * The functions defined take two parameters:
13780 * 1. `{object}` DataTables settings object: see
13781 * {@link DataTable.models.oSettings}
13782 * 2. `{int}` Target column index
13784 * Each function is expected to return an array:
13786 * * `{array}` Data for the column to be ordering upon
13791 * // Ordering using `input` node values
13792 * $.fn.dataTable.ext.order['dom-text'] = function ( settings, col )
13794 * return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
13795 * return $('input', td).val();
13803 * Type based plug-ins.
13805 * Each column in DataTables has a type assigned to it, either by automatic
13806 * detection or by direct assignment using the `type` option for the column.
13807 * The type of a column will effect how it is ordering and search (plug-ins
13808 * can also make use of the column type if required).
13814 * Type detection functions.
13816 * The functions defined in this object are used to automatically detect
13817 * a column's type, making initialisation of DataTables super easy, even
13818 * when complex data is in the table.
13820 * The functions defined take two parameters:
13822 * 1. `{*}` Data from the column cell to be analysed
13823 * 2. `{settings}` DataTables settings object. This can be used to
13824 * perform context specific type detection - for example detection
13825 * based on language settings such as using a comma for a decimal
13826 * place. Generally speaking the options from the settings will not
13829 * Each function is expected to return:
13831 * * `{string|null}` Data type detected, or null if unknown (and thus
13832 * pass it on to the other type detection functions.
13837 * // Currency type detection plug-in:
13838 * $.fn.dataTable.ext.type.detect.push(
13839 * function ( data, settings ) {
13840 * // Check the numeric part
13841 * if ( ! $.isNumeric( data.substring(1) ) ) {
13845 * // Check prefixed by currency
13846 * if ( data.charAt(0) == '$' || data.charAt(0) == '£' ) {
13847 * return 'currency';
13857 * Type based search formatting.
13859 * The type based searching functions can be used to pre-format the
13860 * data to be search on. For example, it can be used to strip HTML
13861 * tags or to de-format telephone numbers for numeric only searching.
13863 * Note that is a search is not defined for a column of a given type,
13864 * no search formatting will be performed.
13866 * Pre-processing of searching data plug-ins - When you assign the sType
13867 * for a column (or have it automatically detected for you by DataTables
13868 * or a type detection plug-in), you will typically be using this for
13869 * custom sorting, but it can also be used to provide custom searching
13870 * by allowing you to pre-processing the data and returning the data in
13871 * the format that should be searched upon. This is done by adding
13872 * functions this object with a parameter name which matches the sType
13873 * for that target column. This is the corollary of <i>afnSortData</i>
13874 * for searching data.
13876 * The functions defined take a single parameter:
13878 * 1. `{*}` Data from the column cell to be prepared for searching
13880 * Each function is expected to return:
13882 * * `{string|null}` Formatted string that will be used for the searching.
13888 * $.fn.dataTable.ext.type.search['title-numeric'] = function ( d ) {
13889 * return d.replace(/\n/g," ").replace( /<.*?>/g, "" );
13896 * Type based ordering.
13898 * The column type tells DataTables what ordering to apply to the table
13899 * when a column is sorted upon. The order for each type that is defined,
13900 * is defined by the functions available in this object.
13902 * Each ordering option can be described by three properties added to
13905 * * `{type}-pre` - Pre-formatting function
13906 * * `{type}-asc` - Ascending order function
13907 * * `{type}-desc` - Descending order function
13909 * All three can be used together, only `{type}-pre` or only
13910 * `{type}-asc` and `{type}-desc` together. It is generally recommended
13911 * that only `{type}-pre` is used, as this provides the optimal
13912 * implementation in terms of speed, although the others are provided
13913 * for compatibility with existing Javascript sort functions.
13915 * `{type}-pre`: Functions defined take a single parameter:
13917 * 1. `{*}` Data from the column cell to be prepared for ordering
13921 * * `{*}` Data to be sorted upon
13923 * `{type}-asc` and `{type}-desc`: Functions are typical Javascript sort
13924 * functions, taking two parameters:
13926 * 1. `{*}` Data to compare to the second parameter
13927 * 2. `{*}` Data to compare to the first parameter
13931 * * `{*}` Ordering match: <0 if first parameter should be sorted lower
13932 * than the second parameter, ===0 if the two parameters are equal and
13933 * >0 if the first parameter should be sorted height than the second
13940 * // Numeric ordering of formatted numbers with a pre-formatter
13941 * $.extend( $.fn.dataTable.ext.type.order, {
13942 * "string-pre": function(x) {
13943 * a = (a === "-" || a === "") ? 0 : a.replace( /[^\d\-\.]/g, "" );
13944 * return parseFloat( a );
13949 * // Case-sensitive string ordering, with no pre-formatting method
13950 * $.extend( $.fn.dataTable.ext.order, {
13951 * "string-case-asc": function(x,y) {
13952 * return ((x < y) ? -1 : ((x > y) ? 1 : 0));
13954 * "string-case-desc": function(x,y) {
13955 * return ((x < y) ? 1 : ((x > y) ? -1 : 0));
13963 * Unique DataTables instance counter
13973 // The following properties are retained for backwards compatiblity only.
13974 // The should not be used in new projects and will be removed in a future
13979 * Version check function.
13981 * @depreciated Since 1.10
13983 fnVersionCheck
: DataTable
.fnVersionCheck
,
13987 * Index for what 'this' index API functions should use
13989 * @deprecated Since v1.10
13995 * jQuery UI class container
13997 * @deprecated Since v1.10
14005 * @deprecated Since v1.10
14007 sVersion
: DataTable
.version
14012 // Backwards compatibility. Alias to pre 1.10 Hungarian notation counter parts
14015 afnFiltering
: _ext
.search
,
14016 aTypes
: _ext
.type
.detect
,
14017 ofnSearch
: _ext
.type
.search
,
14018 oSort
: _ext
.type
.order
,
14019 afnSortData
: _ext
.order
,
14020 aoFeatures
: _ext
.feature
,
14021 oApi
: _ext
.internal,
14022 oStdClasses
: _ext
.classes
,
14023 oPagination
: _ext
.pager
14027 $.extend( DataTable
.ext
.classes
, {
14028 "sTable": "dataTable",
14029 "sNoFooter": "no-footer",
14031 /* Paging buttons */
14032 "sPageButton": "paginate_button",
14033 "sPageButtonActive": "current",
14034 "sPageButtonDisabled": "disabled",
14036 /* Striping classes */
14037 "sStripeOdd": "odd",
14038 "sStripeEven": "even",
14041 "sRowEmpty": "dataTables_empty",
14044 "sWrapper": "dataTables_wrapper",
14045 "sFilter": "dataTables_filter",
14046 "sInfo": "dataTables_info",
14047 "sPaging": "dataTables_paginate paging_", /* Note that the type is postfixed */
14048 "sLength": "dataTables_length",
14049 "sProcessing": "dataTables_processing",
14052 "sSortAsc": "sorting_asc",
14053 "sSortDesc": "sorting_desc",
14054 "sSortable": "sorting", /* Sortable in both directions */
14055 "sSortableAsc": "sorting_asc_disabled",
14056 "sSortableDesc": "sorting_desc_disabled",
14057 "sSortableNone": "sorting_disabled",
14058 "sSortColumn": "sorting_", /* Note that an int is postfixed for the sorting order */
14061 "sFilterInput": "",
14064 "sLengthSelect": "",
14067 "sScrollWrapper": "dataTables_scroll",
14068 "sScrollHead": "dataTables_scrollHead",
14069 "sScrollHeadInner": "dataTables_scrollHeadInner",
14070 "sScrollBody": "dataTables_scrollBody",
14071 "sScrollFoot": "dataTables_scrollFoot",
14072 "sScrollFootInner": "dataTables_scrollFootInner",
14080 "sSortJUIDesc": "",
14082 "sSortJUIAscAllowed": "",
14083 "sSortJUIDescAllowed": "",
14084 "sSortJUIWrapper": "",
14093 // Reused strings for better compression. Closure compiler appears to have a
14094 // weird edge case where it is trying to expand strings rather than use the
14095 // variable version. This results in about 200 bytes being added, for very
14096 // little preference benefit since it this run on script load only.
14100 var _stateDefault
= _empty
+ 'ui-state-default';
14101 var _sortIcon
= _empty
+ 'css_right ui-icon ui-icon-';
14102 var _headerFooter
= _empty
+ 'fg-toolbar ui-toolbar ui-widget-header ui-helper-clearfix';
14104 $.extend( DataTable
.ext
.oJUIClasses
, DataTable
.ext
.classes
, {
14105 /* Full numbers paging buttons */
14106 "sPageButton": "fg-button ui-button "+_stateDefault
,
14107 "sPageButtonActive": "ui-state-disabled",
14108 "sPageButtonDisabled": "ui-state-disabled",
14111 "sPaging": "dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi "+
14112 "ui-buttonset-multi paging_", /* Note that the type is postfixed */
14115 "sSortAsc": _stateDefault
+" sorting_asc",
14116 "sSortDesc": _stateDefault
+" sorting_desc",
14117 "sSortable": _stateDefault
+" sorting",
14118 "sSortableAsc": _stateDefault
+" sorting_asc_disabled",
14119 "sSortableDesc": _stateDefault
+" sorting_desc_disabled",
14120 "sSortableNone": _stateDefault
+" sorting_disabled",
14121 "sSortJUIAsc": _sortIcon
+"triangle-1-n",
14122 "sSortJUIDesc": _sortIcon
+"triangle-1-s",
14123 "sSortJUI": _sortIcon
+"carat-2-n-s",
14124 "sSortJUIAscAllowed": _sortIcon
+"carat-1-n",
14125 "sSortJUIDescAllowed": _sortIcon
+"carat-1-s",
14126 "sSortJUIWrapper": "DataTables_sort_wrapper",
14127 "sSortIcon": "DataTables_sort_icon",
14130 "sScrollHead": "dataTables_scrollHead "+_stateDefault
,
14131 "sScrollFoot": "dataTables_scrollFoot "+_stateDefault
,
14134 "sHeaderTH": _stateDefault
,
14135 "sFooterTH": _stateDefault
,
14136 "sJUIHeader": _headerFooter
+" ui-corner-tl ui-corner-tr",
14137 "sJUIFooter": _headerFooter
+" ui-corner-bl ui-corner-br"
14144 var extPagination
= DataTable
.ext
.pager
;
14146 function _numbers ( page
, pages
) {
14149 buttons
= extPagination
.numbers_length
,
14150 half
= Math
.floor( buttons
/ 2 ),
14153 if ( pages
<= buttons
) {
14154 numbers
= _range( 0, pages
);
14156 else if ( page
<= half
) {
14157 numbers
= _range( 0, buttons
-2 );
14158 numbers
.push( 'ellipsis' );
14159 numbers
.push( pages
-1 );
14161 else if ( page
>= pages
- 1 - half
) {
14162 numbers
= _range( pages
-(buttons
-2), pages
);
14163 numbers
.splice( 0, 0, 'ellipsis' ); // no unshift in ie6
14164 numbers
.splice( 0, 0, 0 );
14167 numbers
= _range( page
-half
+2, page
+half
-1 );
14168 numbers
.push( 'ellipsis' );
14169 numbers
.push( pages
-1 );
14170 numbers
.splice( 0, 0, 'ellipsis' );
14171 numbers
.splice( 0, 0, 0 );
14174 numbers
.DT_el
= 'span';
14179 $.extend( extPagination
, {
14180 simple: function ( page
, pages
) {
14181 return [ 'previous', 'next' ];
14184 full: function ( page
, pages
) {
14185 return [ 'first', 'previous', 'next', 'last' ];
14188 simple_numbers: function ( page
, pages
) {
14189 return [ 'previous', _numbers(page
, pages
), 'next' ];
14192 full_numbers: function ( page
, pages
) {
14193 return [ 'first', 'previous', _numbers(page
, pages
), 'next', 'last' ];
14196 // For testing and plug-ins to use
14197 _numbers
: _numbers
,
14199 // Number of number buttons (including ellipsis) to show. _Must be odd!_
14204 $.extend( true, DataTable
.ext
.renderer
, {
14206 _: function ( settings
, host
, idx
, buttons
, page
, pages
) {
14207 var classes
= settings
.oClasses
;
14208 var lang
= settings
.oLanguage
.oPaginate
;
14209 var btnDisplay
, btnClass
, counter
=0;
14211 var attach = function( container
, buttons
) {
14212 var i
, ien
, node
, button
;
14213 var clickHandler = function ( e
) {
14214 _fnPageChange( settings
, e
.data
.action
, true );
14217 for ( i
=0, ien
=buttons
.length
; i
<ien
; i
++ ) {
14218 button
= buttons
[i
];
14220 if ( $.isArray( button
) ) {
14221 var inner
= $( '<'+(button
.DT_el
|| 'div')+'/>' )
14222 .appendTo( container
);
14223 attach( inner
, button
);
14229 switch ( button
) {
14231 container
.append('<span class="ellipsis">…</span>');
14235 btnDisplay
= lang
.sFirst
;
14236 btnClass
= button
+ (page
> 0 ?
14237 '' : ' '+classes
.sPageButtonDisabled
);
14241 btnDisplay
= lang
.sPrevious
;
14242 btnClass
= button
+ (page
> 0 ?
14243 '' : ' '+classes
.sPageButtonDisabled
);
14247 btnDisplay
= lang
.sNext
;
14248 btnClass
= button
+ (page
< pages
-1 ?
14249 '' : ' '+classes
.sPageButtonDisabled
);
14253 btnDisplay
= lang
.sLast
;
14254 btnClass
= button
+ (page
< pages
-1 ?
14255 '' : ' '+classes
.sPageButtonDisabled
);
14259 btnDisplay
= button
+ 1;
14260 btnClass
= page
=== button
?
14261 classes
.sPageButtonActive
: '';
14265 if ( btnDisplay
) {
14267 'class': classes
.sPageButton
+' '+btnClass
,
14268 'aria-controls': settings
.sTableId
,
14269 'data-dt-idx': counter
,
14270 'tabindex': settings
.iTabIndex
,
14271 'id': idx
=== 0 && typeof button
=== 'string' ?
14272 settings
.sTableId
+'_'+ button
:
14275 .html( btnDisplay
)
14276 .appendTo( container
);
14279 node
, {action
: button
}, clickHandler
14288 // IE9 throws an 'unknown error' if document.activeElement is used
14289 // inside an iframe or frame. Try / catch the error. Not good for
14290 // accessibility, but neither are frames.
14294 // Because this approach is destroying and recreating the paging
14295 // elements, focus is lost on the select button which is bad for
14296 // accessibility. So we want to restore focus once the draw has
14298 activeEl
= $(document
.activeElement
).data('dt-idx');
14302 attach( $(host
).empty(), buttons
);
14305 $(host
).find( '[data-dt-idx='+activeEl
+']' ).focus();
14313 // Built in type detection. See model.ext.aTypes for information about
14314 // what is required from this methods.
14315 $.extend( DataTable
.ext
.type
.detect
, [
14316 // Plain numbers - first since V8 detects some plain numbers as dates
14317 // e.g. Date.parse('55') (but not all, e.g. Date.parse('22')...).
14318 function ( d
, settings
)
14320 var decimal = settings
.oLanguage
.sDecimal
;
14321 return _isNumber( d
, decimal ) ? 'num'+decimal : null;
14324 // Dates (only those recognised by the browser's Date.parse)
14325 function ( d
, settings
)
14327 // V8 will remove any unknown characters at the start and end of the
14328 // expression, leading to false matches such as `$245.12` or `10%` being
14329 // a valid date. See forum thread 18941 for detail.
14330 if ( d
&& !(d
instanceof Date
) && ( ! _re_date_start
.test(d
) || ! _re_date_end
.test(d
) ) ) {
14333 var parsed
= Date
.parse(d
);
14334 return (parsed
!== null && !isNaN(parsed
)) || _empty(d
) ? 'date' : null;
14337 // Formatted numbers
14338 function ( d
, settings
)
14340 var decimal = settings
.oLanguage
.sDecimal
;
14341 return _isNumber( d
, decimal, true ) ? 'num-fmt'+decimal : null;
14345 function ( d
, settings
)
14347 var decimal = settings
.oLanguage
.sDecimal
;
14348 return _htmlNumeric( d
, decimal ) ? 'html-num'+decimal : null;
14351 // HTML numeric, formatted
14352 function ( d
, settings
)
14354 var decimal = settings
.oLanguage
.sDecimal
;
14355 return _htmlNumeric( d
, decimal, true ) ? 'html-num-fmt'+decimal : null;
14358 // HTML (this is strict checking - there must be html)
14359 function ( d
, settings
)
14361 return _empty( d
) || (typeof d
=== 'string' && d
.indexOf('<') !== -1) ?
14368 // Filter formatting functions. See model.ext.ofnSearch for information about
14369 // what is required from these methods.
14371 // Note that additional search methods are added for the html numbers and
14372 // html formatted numbers by `_addNumericSort()` when we know what the decimal
14376 $.extend( DataTable
.ext
.type
.search
, {
14377 html: function ( data
) {
14378 return _empty(data
) ?
14380 typeof data
=== 'string' ?
14382 .replace( _re_new_lines
, " " )
14383 .replace( _re_html
, "" ) :
14387 string: function ( data
) {
14388 return _empty(data
) ?
14390 typeof data
=== 'string' ?
14391 data
.replace( _re_new_lines
, " " ) :
14398 var __numericReplace = function ( d
, decimalPlace
, re1
, re2
) {
14399 if ( d
!== 0 && (!d
|| d
=== '-') ) {
14403 // If a decimal place other than `.` is used, it needs to be given to the
14404 // function so we can detect it and replace with a `.` which is the only
14405 // decimal place Javascript recognises - it is not locale aware.
14406 if ( decimalPlace
) {
14407 d
= _numToDecimal( d
, decimalPlace
);
14412 d
= d
.replace( re1
, '' );
14416 d
= d
.replace( re2
, '' );
14424 // Add the numeric 'deformatting' functions for sorting and search. This is done
14425 // in a function to provide an easy ability for the language options to add
14426 // additional methods if a non-period decimal place is used.
14427 function _addNumericSort ( decimalPlace
) {
14431 "num": function ( d
) {
14432 return __numericReplace( d
, decimalPlace
);
14435 // Formatted numbers
14436 "num-fmt": function ( d
) {
14437 return __numericReplace( d
, decimalPlace
, _re_formatted_numeric
);
14441 "html-num": function ( d
) {
14442 return __numericReplace( d
, decimalPlace
, _re_html
);
14445 // HTML numeric, formatted
14446 "html-num-fmt": function ( d
) {
14447 return __numericReplace( d
, decimalPlace
, _re_html
, _re_formatted_numeric
);
14450 function ( key
, fn
) {
14451 // Add the ordering method
14452 _ext
.type
.order
[ key
+decimalPlace
+'-pre' ] = fn
;
14454 // For HTML types add a search formatter that will strip the HTML
14455 if ( key
.match(/^html\-/) ) {
14456 _ext
.type
.search
[ key
+decimalPlace
] = _ext
.type
.search
.html
;
14463 // Default sort methods
14464 $.extend( _ext
.type
.order
, {
14466 "date-pre": function ( d
) {
14467 return Date
.parse( d
) || 0;
14471 "html-pre": function ( a
) {
14475 a
.replace( /<.*?>/g, "" ).toLowerCase() :
14480 "string-pre": function ( a
) {
14481 // This is a little complex, but faster than always calling toString,
14482 // http://jsperf.com/tostring-v-check
14485 typeof a
=== 'string' ?
14492 // string-asc and -desc are retained only for compatibility with the old
14494 "string-asc": function ( x
, y
) {
14495 return ((x
< y
) ? -1 : ((x
> y
) ? 1 : 0));
14498 "string-desc": function ( x
, y
) {
14499 return ((x
< y
) ? 1 : ((x
> y
) ? -1 : 0));
14504 // Numeric sorting types - order doesn't matter here
14505 _addNumericSort( '' );
14508 $.extend( true, DataTable
.ext
.renderer
, {
14510 _: function ( settings
, cell
, column
, classes
) {
14511 // No additional mark-up required
14512 // Attach a sort listener to update on sort - note that using the
14513 // `DT` namespace will allow the event to be removed automatically
14514 // on destroy, while the `dt` namespaced event is the one we are
14516 $(settings
.nTable
).on( 'order.dt.DT', function ( e
, ctx
, sorting
, columns
) {
14517 if ( settings
!== ctx
) { // need to check this this is the host
14518 return; // table, not a nested one
14521 var colIdx
= column
.idx
;
14525 column
.sSortingClass
+' '+
14526 classes
.sSortAsc
+' '+
14529 .addClass( columns
[ colIdx
] == 'asc' ?
14530 classes
.sSortAsc
: columns
[ colIdx
] == 'desc' ?
14531 classes
.sSortDesc
:
14532 column
.sSortingClass
14537 jqueryui: function ( settings
, cell
, column
, classes
) {
14539 .addClass( classes
.sSortJUIWrapper
)
14540 .append( cell
.contents() )
14541 .append( $('<span/>')
14542 .addClass( classes
.sSortIcon
+' '+column
.sSortingClassJUI
)
14546 // Attach a sort listener to update on sort
14547 $(settings
.nTable
).on( 'order.dt.DT', function ( e
, ctx
, sorting
, columns
) {
14548 if ( settings
!== ctx
) {
14552 var colIdx
= column
.idx
;
14555 .removeClass( classes
.sSortAsc
+" "+classes
.sSortDesc
)
14556 .addClass( columns
[ colIdx
] == 'asc' ?
14557 classes
.sSortAsc
: columns
[ colIdx
] == 'desc' ?
14558 classes
.sSortDesc
:
14559 column
.sSortingClass
14563 .find( 'span.'+classes
.sSortIcon
)
14565 classes
.sSortJUIAsc
+" "+
14566 classes
.sSortJUIDesc
+" "+
14567 classes
.sSortJUI
+" "+
14568 classes
.sSortJUIAscAllowed
+" "+
14569 classes
.sSortJUIDescAllowed
14571 .addClass( columns
[ colIdx
] == 'asc' ?
14572 classes
.sSortJUIAsc
: columns
[ colIdx
] == 'desc' ?
14573 classes
.sSortJUIDesc
:
14574 column
.sSortingClassJUI
14582 * Public helper functions. These aren't used internally by DataTables, or
14583 * called by any of the options passed into DataTables, but they can be used
14584 * externally by developers working with DataTables. They are helper functions
14585 * to make working with DataTables a little bit easier.
14589 * Helpers for `columns.render`.
14591 * The options defined here can be used with the `columns.render` initialisation
14592 * option to provide a display renderer. The following functions are defined:
14594 * * `number` - Will format numeric data (defined by `columns.data`) for
14595 * display, retaining the original unformatted data for sorting and filtering.
14596 * It takes 4 parameters:
14597 * * `string` - Thousands grouping separator
14598 * * `string` - Decimal point indicator
14599 * * `integer` - Number of decimal points to show
14600 * * `string` (optional) - Prefix.
14603 * // Column definition using the number renderer
14606 * render: $.fn.dataTable.render.number( '\'', '.', 0, '$' )
14611 DataTable
.render
= {
14612 number: function ( thousands
, decimal, precision
, prefix
) {
14614 display: function ( d
) {
14615 if ( typeof d
!== 'number' && typeof d
!== 'string' ) {
14619 var negative
= d
< 0 ? '-' : '';
14620 d
= Math
.abs( parseFloat( d
) );
14622 var intPart
= parseInt( d
, 10 );
14623 var floatPart
= precision
?
14624 decimal+(d
- intPart
).toFixed( precision
).substring( 2 ):
14627 return negative
+ (prefix
||'') +
14628 intPart
.toString().replace(
14629 /\B(?=(\d{3})+(?!\d))/g, thousands
14639 * This is really a good bit rubbish this method of exposing the internal methods
14640 * publicly... - To be fixed in 2.0 using methods on the prototype
14645 * Create a wrapper function for exporting an internal functions to an external API.
14646 * @param {string} fn API function name
14647 * @returns {function} wrapped function
14648 * @memberof DataTable#internal
14650 function _fnExternApiFunc (fn
)
14652 return function() {
14653 var args
= [_fnSettingsFromNode( this[DataTable
.ext
.iApiIndex
] )].concat(
14654 Array
.prototype.slice
.call(arguments
)
14656 return DataTable
.ext
.internal[fn
].apply( this, args
);
14662 * Reference to internal functions for use by plug-in developers. Note that
14663 * these methods are references to internal functions and are considered to be
14664 * private. If you use these methods, be aware that they are liable to change
14665 * between versions.
14668 $.extend( DataTable
.ext
.internal, {
14669 _fnExternApiFunc
: _fnExternApiFunc
,
14670 _fnBuildAjax
: _fnBuildAjax
,
14671 _fnAjaxUpdate
: _fnAjaxUpdate
,
14672 _fnAjaxParameters
: _fnAjaxParameters
,
14673 _fnAjaxUpdateDraw
: _fnAjaxUpdateDraw
,
14674 _fnAjaxDataSrc
: _fnAjaxDataSrc
,
14675 _fnAddColumn
: _fnAddColumn
,
14676 _fnColumnOptions
: _fnColumnOptions
,
14677 _fnAdjustColumnSizing
: _fnAdjustColumnSizing
,
14678 _fnVisibleToColumnIndex
: _fnVisibleToColumnIndex
,
14679 _fnColumnIndexToVisible
: _fnColumnIndexToVisible
,
14680 _fnVisbleColumns
: _fnVisbleColumns
,
14681 _fnGetColumns
: _fnGetColumns
,
14682 _fnColumnTypes
: _fnColumnTypes
,
14683 _fnApplyColumnDefs
: _fnApplyColumnDefs
,
14684 _fnHungarianMap
: _fnHungarianMap
,
14685 _fnCamelToHungarian
: _fnCamelToHungarian
,
14686 _fnLanguageCompat
: _fnLanguageCompat
,
14687 _fnBrowserDetect
: _fnBrowserDetect
,
14688 _fnAddData
: _fnAddData
,
14689 _fnAddTr
: _fnAddTr
,
14690 _fnNodeToDataIndex
: _fnNodeToDataIndex
,
14691 _fnNodeToColumnIndex
: _fnNodeToColumnIndex
,
14692 _fnGetCellData
: _fnGetCellData
,
14693 _fnSetCellData
: _fnSetCellData
,
14694 _fnSplitObjNotation
: _fnSplitObjNotation
,
14695 _fnGetObjectDataFn
: _fnGetObjectDataFn
,
14696 _fnSetObjectDataFn
: _fnSetObjectDataFn
,
14697 _fnGetDataMaster
: _fnGetDataMaster
,
14698 _fnClearTable
: _fnClearTable
,
14699 _fnDeleteIndex
: _fnDeleteIndex
,
14700 _fnInvalidate
: _fnInvalidate
,
14701 _fnGetRowElements
: _fnGetRowElements
,
14702 _fnCreateTr
: _fnCreateTr
,
14703 _fnBuildHead
: _fnBuildHead
,
14704 _fnDrawHead
: _fnDrawHead
,
14706 _fnReDraw
: _fnReDraw
,
14707 _fnAddOptionsHtml
: _fnAddOptionsHtml
,
14708 _fnDetectHeader
: _fnDetectHeader
,
14709 _fnGetUniqueThs
: _fnGetUniqueThs
,
14710 _fnFeatureHtmlFilter
: _fnFeatureHtmlFilter
,
14711 _fnFilterComplete
: _fnFilterComplete
,
14712 _fnFilterCustom
: _fnFilterCustom
,
14713 _fnFilterColumn
: _fnFilterColumn
,
14714 _fnFilter
: _fnFilter
,
14715 _fnFilterCreateSearch
: _fnFilterCreateSearch
,
14716 _fnEscapeRegex
: _fnEscapeRegex
,
14717 _fnFilterData
: _fnFilterData
,
14718 _fnFeatureHtmlInfo
: _fnFeatureHtmlInfo
,
14719 _fnUpdateInfo
: _fnUpdateInfo
,
14720 _fnInfoMacros
: _fnInfoMacros
,
14721 _fnInitialise
: _fnInitialise
,
14722 _fnInitComplete
: _fnInitComplete
,
14723 _fnLengthChange
: _fnLengthChange
,
14724 _fnFeatureHtmlLength
: _fnFeatureHtmlLength
,
14725 _fnFeatureHtmlPaginate
: _fnFeatureHtmlPaginate
,
14726 _fnPageChange
: _fnPageChange
,
14727 _fnFeatureHtmlProcessing
: _fnFeatureHtmlProcessing
,
14728 _fnProcessingDisplay
: _fnProcessingDisplay
,
14729 _fnFeatureHtmlTable
: _fnFeatureHtmlTable
,
14730 _fnScrollDraw
: _fnScrollDraw
,
14731 _fnApplyToChildren
: _fnApplyToChildren
,
14732 _fnCalculateColumnWidths
: _fnCalculateColumnWidths
,
14733 _fnThrottle
: _fnThrottle
,
14734 _fnConvertToWidth
: _fnConvertToWidth
,
14735 _fnScrollingWidthAdjust
: _fnScrollingWidthAdjust
,
14736 _fnGetWidestNode
: _fnGetWidestNode
,
14737 _fnGetMaxLenString
: _fnGetMaxLenString
,
14738 _fnStringToCss
: _fnStringToCss
,
14739 _fnScrollBarWidth
: _fnScrollBarWidth
,
14740 _fnSortFlatten
: _fnSortFlatten
,
14742 _fnSortAria
: _fnSortAria
,
14743 _fnSortListener
: _fnSortListener
,
14744 _fnSortAttachListener
: _fnSortAttachListener
,
14745 _fnSortingClasses
: _fnSortingClasses
,
14746 _fnSortData
: _fnSortData
,
14747 _fnSaveState
: _fnSaveState
,
14748 _fnLoadState
: _fnLoadState
,
14749 _fnSettingsFromNode
: _fnSettingsFromNode
,
14752 _fnBindAction
: _fnBindAction
,
14753 _fnCallbackReg
: _fnCallbackReg
,
14754 _fnCallbackFire
: _fnCallbackFire
,
14755 _fnLengthOverflow
: _fnLengthOverflow
,
14756 _fnRenderer
: _fnRenderer
,
14757 _fnDataSource
: _fnDataSource
,
14758 _fnRowAttributes
: _fnRowAttributes
,
14759 _fnCalculateEnd: function () {} // Used by a lot of plug-ins, but redundant
14760 // in 1.10, so this dead-end function is
14761 // added to prevent errors
14766 $.fn
.dataTable
= DataTable
;
14769 $.fn
.dataTableSettings
= DataTable
.settings
;
14770 $.fn
.dataTableExt
= DataTable
.ext
;
14772 // With a capital `D` we return a DataTables API instance rather than a
14774 $.fn
.DataTable = function ( opts
) {
14775 return $(this).dataTable( opts
).api();
14778 // All properties that are available to $.fn.dataTable should also be
14779 // available on $.fn.DataTable
14780 $.each( DataTable
, function ( prop
, val
) {
14781 $.fn
.DataTable
[ prop
] = val
;
14785 // Information about events fired by DataTables - for documentation.
14787 * Draw event, fired whenever the table is redrawn on the page, at the same
14788 * point as fnDrawCallback. This may be useful for binding events or
14789 * performing calculations when the table is altered at all.
14790 * @name DataTable#draw.dt
14792 * @param {event} e jQuery event object
14793 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
14797 * Search event, fired when the searching applied to the table (using the
14798 * built-in global search, or column filters) is altered.
14799 * @name DataTable#search.dt
14801 * @param {event} e jQuery event object
14802 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
14806 * Page change event, fired when the paging of the table is altered.
14807 * @name DataTable#page.dt
14809 * @param {event} e jQuery event object
14810 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
14814 * Order event, fired when the ordering applied to the table is altered.
14815 * @name DataTable#order.dt
14817 * @param {event} e jQuery event object
14818 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
14822 * DataTables initialisation complete event, fired when the table is fully
14823 * drawn, including Ajax data loaded, if Ajax data is required.
14824 * @name DataTable#init.dt
14826 * @param {event} e jQuery event object
14827 * @param {object} oSettings DataTables settings object
14828 * @param {object} json The JSON object request from the server - only
14829 * present if client-side Ajax sourced data is used</li></ol>
14833 * State save event, fired when the table has changed state a new state save
14834 * is required. This event allows modification of the state saving object
14835 * prior to actually doing the save, including addition or other state
14836 * properties (for plug-ins) or modification of a DataTables core property.
14837 * @name DataTable#stateSaveParams.dt
14839 * @param {event} e jQuery event object
14840 * @param {object} oSettings DataTables settings object
14841 * @param {object} json The state information to be saved
14845 * State load event, fired when the table is loading state from the stored
14846 * data, but prior to the settings object being modified by the saved state
14847 * - allowing modification of the saved state is required or loading of
14848 * state for a plug-in.
14849 * @name DataTable#stateLoadParams.dt
14851 * @param {event} e jQuery event object
14852 * @param {object} oSettings DataTables settings object
14853 * @param {object} json The saved state information
14857 * State loaded event, fired when state has been loaded from stored data and
14858 * the settings object has been modified by the loaded data.
14859 * @name DataTable#stateLoaded.dt
14861 * @param {event} e jQuery event object
14862 * @param {object} oSettings DataTables settings object
14863 * @param {object} json The saved state information
14867 * Processing event, fired when DataTables is doing some kind of processing
14868 * (be it, order, searcg or anything else). It can be used to indicate to
14869 * the end user that there is something happening, or that something has
14871 * @name DataTable#processing.dt
14873 * @param {event} e jQuery event object
14874 * @param {object} oSettings DataTables settings object
14875 * @param {boolean} bShow Flag for if DataTables is doing processing or not
14879 * Ajax (XHR) event, fired whenever an Ajax request is completed from a
14880 * request to made to the server for new data. This event is called before
14881 * DataTables processed the returned data, so it can also be used to pre-
14882 * process the data returned from the server, if needed.
14884 * Note that this trigger is called in `fnServerData`, if you override
14885 * `fnServerData` and which to use this event, you need to trigger it in you
14886 * success function.
14887 * @name DataTable#xhr.dt
14889 * @param {event} e jQuery event object
14890 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
14891 * @param {object} json JSON returned from the server
14894 * // Use a custom property returned from the server in another DOM element
14895 * $('#table').dataTable().on('xhr.dt', function (e, settings, json) {
14896 * $('#status').html( json.status );
14900 * // Pre-process the data returned from the server
14901 * $('#table').dataTable().on('xhr.dt', function (e, settings, json) {
14902 * for ( var i=0, ien=json.aaData.length ; i<ien ; i++ ) {
14903 * json.aaData[i].sum = json.aaData[i].one + json.aaData[i].two;
14905 * // Note no return - manipulate the data directly in the JSON object.
14910 * Destroy event, fired when the DataTable is destroyed by calling fnDestroy
14911 * or passing the bDestroy:true parameter in the initialisation object. This
14912 * can be used to remove bound events, added DOM nodes, etc.
14913 * @name DataTable#destroy.dt
14915 * @param {event} e jQuery event object
14916 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
14920 * Page length change event, fired when number of records to show on each
14921 * page (the length) is changed.
14922 * @name DataTable#length.dt
14924 * @param {event} e jQuery event object
14925 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
14926 * @param {integer} len New length
14930 * Column sizing has changed.
14931 * @name DataTable#column-sizing.dt
14933 * @param {event} e jQuery event object
14934 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
14938 * Column visibility has changed.
14939 * @name DataTable#column-visibility.dt
14941 * @param {event} e jQuery event object
14942 * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
14943 * @param {int} column Column index
14944 * @param {bool} vis `false` if column now hidden, or `true` if visible
14947 return $.fn
.dataTable
;
14950 }(window
, document
));