Guest User

DataTables.js

a guest
Apr 28th, 2012
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 371.48 KB | None | 0 0
  1. /**
  2. * @summary DataTables
  3. * @description Paginate, search and sort HTML tables
  4. * @version 1.9.1
  5. * @file jquery.dataTables.js
  6. * @author Allan Jardine (www.sprymedia.co.uk)
  7. * @contact www.sprymedia.co.uk/contact
  8. *
  9. * @copyright Copyright 2008-2012 Allan Jardine, all rights reserved.
  10. *
  11. * This source file is free software, under either the GPL v2 license or a
  12. * BSD style license, available at:
  13. * http://datatables.net/license_gpl2
  14. * http://datatables.net/license_bsd
  15. *
  16. * This source file is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  18. * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
  19. *
  20. * For details please refer to: http://www.datatables.net
  21. */
  22.  
  23. /*jslint evil: true, undef: true, browser: true */
  24. /*globals $, jQuery,_fnExternApiFunc,_fnInitialise,_fnInitComplete,_fnLanguageCompat,_fnAddColumn,_fnColumnOptions,_fnAddData,_fnCreateTr,_fnGatherData,_fnBuildHead,_fnDrawHead,_fnDraw,_fnReDraw,_fnAjaxUpdate,_fnAjaxParameters,_fnAjaxUpdateDraw,_fnServerParams,_fnAddOptionsHtml,_fnFeatureHtmlTable,_fnScrollDraw,_fnAdjustColumnSizing,_fnFeatureHtmlFilter,_fnFilterComplete,_fnFilterCustom,_fnFilterColumn,_fnFilter,_fnBuildSearchArray,_fnBuildSearchRow,_fnFilterCreateSearch,_fnDataToSearch,_fnSort,_fnSortAttachListener,_fnSortingClasses,_fnFeatureHtmlPaginate,_fnPageChange,_fnFeatureHtmlInfo,_fnUpdateInfo,_fnFeatureHtmlLength,_fnFeatureHtmlProcessing,_fnProcessingDisplay,_fnVisibleToColumnIndex,_fnColumnIndexToVisible,_fnNodeToDataIndex,_fnVisbleColumns,_fnCalculateEnd,_fnConvertToWidth,_fnCalculateColumnWidths,_fnScrollingWidthAdjust,_fnGetWidestNode,_fnGetMaxLenString,_fnStringToCss,_fnDetectType,_fnSettingsFromNode,_fnGetDataMaster,_fnGetTrNodes,_fnGetTdNodes,_fnEscapeRegex,_fnDeleteIndex,_fnReOrderIndex,_fnColumnOrdering,_fnLog,_fnClearTable,_fnSaveState,_fnLoadState,_fnCreateCookie,_fnReadCookie,_fnDetectHeader,_fnGetUniqueThs,_fnScrollBarWidth,_fnApplyToChildren,_fnMap,_fnGetRowData,_fnGetCellData,_fnSetCellData,_fnGetObjectDataFn,_fnSetObjectDataFn,_fnApplyColumnDefs,_fnBindAction,_fnCallbackReg,_fnCallbackFire,_fnJsonString,_fnRender,_fnNodeToColumnIndex,_fnInfoMacros*/
  25.  
  26. (/** @lends <global> */function($, window, document, undefined) {
  27. /**
  28. * DataTables is a plug-in for the jQuery Javascript library. It is a
  29. * highly flexible tool, based upon the foundations of progressive
  30. * enhancement, which will add advanced interaction controls to any
  31. * HTML table. For a full list of features please refer to
  32. * <a href="http://datatables.net">DataTables.net</a>.
  33. *
  34. * Note that the <i>DataTable</i> object is not a global variable but is
  35. * aliased to <i>jQuery.fn.DataTable</i> and <i>jQuery.fn.dataTable</i> through which
  36. * it may be accessed.
  37. *
  38. * @class
  39. * @param {object} [oInit={}] Configuration object for DataTables. Options
  40. * are defined by {@link DataTable.defaults}
  41. * @requires jQuery 1.3+
  42. *
  43. * @example
  44. * // Basic initialisation
  45. * $(document).ready( function {
  46. * $('#example').dataTable();
  47. * } );
  48. *
  49. * @example
  50. * // Initialisation with configuration options - in this case, disable
  51. * // pagination and sorting.
  52. * $(document).ready( function {
  53. * $('#example').dataTable( {
  54. * "bPaginate": false,
  55. * "bSort": false
  56. * } );
  57. * } );
  58. */
  59. var DataTable = function( oInit )
  60. {
  61.  
  62.  
  63. /**
  64. * Add a column to the list used for the table with default values
  65. * @param {object} oSettings dataTables settings object
  66. * @param {node} nTh The th element for this column
  67. * @memberof DataTable#oApi
  68. */
  69. function _fnAddColumn( oSettings, nTh )
  70. {
  71. var oDefaults = DataTable.defaults.columns;
  72. var iCol = oSettings.aoColumns.length;
  73. var oCol = $.extend( {}, DataTable.models.oColumn, oDefaults, {
  74. "sSortingClass": oSettings.oClasses.sSortable,
  75. "sSortingClassJUI": oSettings.oClasses.sSortJUI,
  76. "nTh": nTh ? nTh : document.createElement('th'),
  77. "sTitle": oDefaults.sTitle ? oDefaults.sTitle : nTh ? nTh.innerHTML : '',
  78. "aDataSort": oDefaults.aDataSort ? oDefaults.aDataSort : [iCol],
  79. "mDataProp": oDefaults.mDataProp ? oDefaults.oDefaults : iCol
  80. } );
  81. oSettings.aoColumns.push( oCol );
  82.  
  83. /* Add a column specific filter */
  84. if ( oSettings.aoPreSearchCols[ iCol ] === undefined || oSettings.aoPreSearchCols[ iCol ] === null )
  85. {
  86. oSettings.aoPreSearchCols[ iCol ] = $.extend( {}, DataTable.models.oSearch );
  87. }
  88. else
  89. {
  90. var oPre = oSettings.aoPreSearchCols[ iCol ];
  91.  
  92. /* Don't require that the user must specify bRegex, bSmart or bCaseInsensitive */
  93. if ( oPre.bRegex === undefined )
  94. {
  95. oPre.bRegex = true;
  96. }
  97.  
  98. if ( oPre.bSmart === undefined )
  99. {
  100. oPre.bSmart = true;
  101. }
  102.  
  103. if ( oPre.bCaseInsensitive === undefined )
  104. {
  105. oPre.bCaseInsensitive = true;
  106. }
  107. }
  108.  
  109. /* Use the column options function to initialise classes etc */
  110. _fnColumnOptions( oSettings, iCol, null );
  111. }
  112.  
  113.  
  114. /**
  115. * Apply options for a column
  116. * @param {object} oSettings dataTables settings object
  117. * @param {int} iCol column index to consider
  118. * @param {object} oOptions object with sType, bVisible and bSearchable
  119. * @memberof DataTable#oApi
  120. */
  121. function _fnColumnOptions( oSettings, iCol, oOptions )
  122. {
  123. var oCol = oSettings.aoColumns[ iCol ];
  124.  
  125. /* User specified column options */
  126. if ( oOptions !== undefined && oOptions !== null )
  127. {
  128. if ( oOptions.sType !== undefined )
  129. {
  130. oCol.sType = oOptions.sType;
  131. oCol._bAutoType = false;
  132. }
  133.  
  134. $.extend( oCol, oOptions );
  135. _fnMap( oCol, oOptions, "sWidth", "sWidthOrig" );
  136.  
  137. /* iDataSort to be applied (backwards compatibility), but aDataSort will take
  138. * priority if defined
  139. */
  140. if ( oOptions.iDataSort !== undefined )
  141. {
  142. oCol.aDataSort = [ oOptions.iDataSort ];
  143. }
  144. _fnMap( oCol, oOptions, "aDataSort" );
  145. }
  146.  
  147. /* Cache the data get and set functions for speed */
  148. oCol.fnGetData = _fnGetObjectDataFn( oCol.mDataProp );
  149. oCol.fnSetData = _fnSetObjectDataFn( oCol.mDataProp );
  150.  
  151. /* Feature sorting overrides column specific when off */
  152. if ( !oSettings.oFeatures.bSort )
  153. {
  154. oCol.bSortable = false;
  155. }
  156.  
  157. /* Check that the class assignment is correct for sorting */
  158. if ( !oCol.bSortable ||
  159. ($.inArray('asc', oCol.asSorting) == -1 && $.inArray('desc', oCol.asSorting) == -1) )
  160. {
  161. oCol.sSortingClass = oSettings.oClasses.sSortableNone;
  162. oCol.sSortingClassJUI = "";
  163. }
  164. else if ( oCol.bSortable ||
  165. ($.inArray('asc', oCol.asSorting) == -1 && $.inArray('desc', oCol.asSorting) == -1) )
  166. {
  167. oCol.sSortingClass = oSettings.oClasses.sSortable;
  168. oCol.sSortingClassJUI = oSettings.oClasses.sSortJUI;
  169. }
  170. else if ( $.inArray('asc', oCol.asSorting) != -1 && $.inArray('desc', oCol.asSorting) == -1 )
  171. {
  172. oCol.sSortingClass = oSettings.oClasses.sSortableAsc;
  173. oCol.sSortingClassJUI = oSettings.oClasses.sSortJUIAscAllowed;
  174. }
  175. else if ( $.inArray('asc', oCol.asSorting) == -1 && $.inArray('desc', oCol.asSorting) != -1 )
  176. {
  177. oCol.sSortingClass = oSettings.oClasses.sSortableDesc;
  178. oCol.sSortingClassJUI = oSettings.oClasses.sSortJUIDescAllowed;
  179. }
  180. }
  181.  
  182.  
  183. /**
  184. * Adjust the table column widths for new data. Note: you would probably want to
  185. * do a redraw after calling this function!
  186. * @param {object} oSettings dataTables settings object
  187. * @memberof DataTable#oApi
  188. */
  189. function _fnAdjustColumnSizing ( oSettings )
  190. {
  191. /* Not interested in doing column width calculation if autowidth is disabled */
  192. if ( oSettings.oFeatures.bAutoWidth === false )
  193. {
  194. return false;
  195. }
  196.  
  197. _fnCalculateColumnWidths( oSettings );
  198. for ( var i=0 , iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
  199. {
  200. oSettings.aoColumns[i].nTh.style.width = oSettings.aoColumns[i].sWidth;
  201. }
  202. }
  203.  
  204.  
  205. /**
  206. * Covert the index of a visible column to the index in the data array (take account
  207. * of hidden columns)
  208. * @param {object} oSettings dataTables settings object
  209. * @param {int} iMatch Visible column index to lookup
  210. * @returns {int} i the data index
  211. * @memberof DataTable#oApi
  212. */
  213. function _fnVisibleToColumnIndex( oSettings, iMatch )
  214. {
  215. var iColumn = -1;
  216.  
  217. for ( var i=0 ; i<oSettings.aoColumns.length ; i++ )
  218. {
  219. if ( oSettings.aoColumns[i].bVisible === true )
  220. {
  221. iColumn++;
  222. }
  223.  
  224. if ( iColumn == iMatch )
  225. {
  226. return i;
  227. }
  228. }
  229.  
  230. return null;
  231. }
  232.  
  233.  
  234. /**
  235. * Covert the index of an index in the data array and convert it to the visible
  236. * column index (take account of hidden columns)
  237. * @param {int} iMatch Column index to lookup
  238. * @param {object} oSettings dataTables settings object
  239. * @returns {int} i the data index
  240. * @memberof DataTable#oApi
  241. */
  242. function _fnColumnIndexToVisible( oSettings, iMatch )
  243. {
  244. var iVisible = -1;
  245. for ( var i=0 ; i<oSettings.aoColumns.length ; i++ )
  246. {
  247. if ( oSettings.aoColumns[i].bVisible === true )
  248. {
  249. iVisible++;
  250. }
  251.  
  252. if ( i == iMatch )
  253. {
  254. return oSettings.aoColumns[i].bVisible === true ? iVisible : null;
  255. }
  256. }
  257.  
  258. return null;
  259. }
  260.  
  261.  
  262. /**
  263. * Get the number of visible columns
  264. * @returns {int} i the number of visible columns
  265. * @param {object} oS dataTables settings object
  266. * @memberof DataTable#oApi
  267. */
  268. function _fnVisbleColumns( oS )
  269. {
  270. var iVis = 0;
  271. for ( var i=0 ; i<oS.aoColumns.length ; i++ )
  272. {
  273. if ( oS.aoColumns[i].bVisible === true )
  274. {
  275. iVis++;
  276. }
  277. }
  278. return iVis;
  279. }
  280.  
  281.  
  282. /**
  283. * Get the sort type based on an input string
  284. * @param {string} sData data we wish to know the type of
  285. * @returns {string} type (defaults to 'string' if no type can be detected)
  286. * @memberof DataTable#oApi
  287. */
  288. function _fnDetectType( sData )
  289. {
  290. var aTypes = DataTable.ext.aTypes;
  291. var iLen = aTypes.length;
  292.  
  293. for ( var i=0 ; i<iLen ; i++ )
  294. {
  295. var sType = aTypes[i]( sData );
  296. if ( sType !== null )
  297. {
  298. return sType;
  299. }
  300. }
  301.  
  302. return 'string';
  303. }
  304.  
  305.  
  306. /**
  307. * Figure out how to reorder a display list
  308. * @param {object} oSettings dataTables settings object
  309. * @returns array {int} aiReturn index list for reordering
  310. * @memberof DataTable#oApi
  311. */
  312. function _fnReOrderIndex ( oSettings, sColumns )
  313. {
  314. var aColumns = sColumns.split(',');
  315. var aiReturn = [];
  316.  
  317. for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
  318. {
  319. for ( var j=0 ; j<iLen ; j++ )
  320. {
  321. if ( oSettings.aoColumns[i].sName == aColumns[j] )
  322. {
  323. aiReturn.push( j );
  324. break;
  325. }
  326. }
  327. }
  328.  
  329. return aiReturn;
  330. }
  331.  
  332.  
  333. /**
  334. * Get the column ordering that DataTables expects
  335. * @param {object} oSettings dataTables settings object
  336. * @returns {string} comma separated list of names
  337. * @memberof DataTable#oApi
  338. */
  339. function _fnColumnOrdering ( oSettings )
  340. {
  341. var sNames = '';
  342. for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
  343. {
  344. sNames += oSettings.aoColumns[i].sName+',';
  345. }
  346. if ( sNames.length == iLen )
  347. {
  348. return "";
  349. }
  350. return sNames.slice(0, -1);
  351. }
  352.  
  353.  
  354. /**
  355. * Take the column definitions and static columns arrays and calculate how
  356. * they relate to column indexes. The callback function will then apply the
  357. * definition found for a column to a suitable configuration object.
  358. * @param {object} oSettings dataTables settings object
  359. * @param {array} aoColDefs The aoColumnDefs array that is to be applied
  360. * @param {array} aoCols The aoColumns array that defines columns individually
  361. * @param {function} fn Callback function - takes two parameters, the calculated
  362. * column index and the definition for that column.
  363. * @memberof DataTable#oApi
  364. */
  365. function _fnApplyColumnDefs( oSettings, aoColDefs, aoCols, fn )
  366. {
  367. var i, iLen, j, jLen, k, kLen;
  368.  
  369. // Column definitions with aTargets
  370. if ( aoColDefs )
  371. {
  372. /* Loop over the definitions array - loop in reverse so first instance has priority */
  373. for ( i=aoColDefs.length-1 ; i>=0 ; i-- )
  374. {
  375. /* Each definition can target multiple columns, as it is an array */
  376. var aTargets = aoColDefs[i].aTargets;
  377. if ( !$.isArray( aTargets ) )
  378. {
  379. _fnLog( oSettings, 1, 'aTargets must be an array of targets, not a '+(typeof aTargets) );
  380. }
  381.  
  382. for ( j=0, jLen=aTargets.length ; j<jLen ; j++ )
  383. {
  384. if ( typeof aTargets[j] === 'number' && aTargets[j] >= 0 )
  385. {
  386. /* Add columns that we don't yet know about */
  387. while( oSettings.aoColumns.length <= aTargets[j] )
  388. {
  389. _fnAddColumn( oSettings );
  390. }
  391.  
  392. /* Integer, basic index */
  393. fn( aTargets[j], aoColDefs[i] );
  394. }
  395. else if ( typeof aTargets[j] === 'number' && aTargets[j] < 0 )
  396. {
  397. /* Negative integer, right to left column counting */
  398. fn( oSettings.aoColumns.length+aTargets[j], aoColDefs[i] );
  399. }
  400. else if ( typeof aTargets[j] === 'string' )
  401. {
  402. /* Class name matching on TH element */
  403. for ( k=0, kLen=oSettings.aoColumns.length ; k<kLen ; k++ )
  404. {
  405. if ( aTargets[j] == "_all" ||
  406. $(oSettings.aoColumns[k].nTh).hasClass( aTargets[j] ) )
  407. {
  408. fn( k, aoColDefs[i] );
  409. }
  410. }
  411. }
  412. }
  413. }
  414. }
  415.  
  416. // Statically defined columns array
  417. if ( aoCols )
  418. {
  419. for ( i=0, iLen=aoCols.length ; i<iLen ; i++ )
  420. {
  421. fn( i, aoCols[i] );
  422. }
  423. }
  424. }
  425.  
  426.  
  427.  
  428. /**
  429. * Add a data array to the table, creating DOM node etc. This is the parallel to
  430. * _fnGatherData, but for adding rows from a Javascript source, rather than a
  431. * DOM source.
  432. * @param {object} oSettings dataTables settings object
  433. * @param {array} aData data array to be added
  434. * @returns {int} >=0 if successful (index of new aoData entry), -1 if failed
  435. * @memberof DataTable#oApi
  436. */
  437. function _fnAddData ( oSettings, aDataSupplied )
  438. {
  439. var oCol;
  440.  
  441. /* Take an independent copy of the data source so we can bash it about as we wish */
  442. var aDataIn = ($.isArray(aDataSupplied)) ?
  443. aDataSupplied.slice() :
  444. $.extend( true, {}, aDataSupplied );
  445.  
  446. /* Create the object for storing information about this new row */
  447. var iRow = oSettings.aoData.length;
  448. var oData = $.extend( true, {}, DataTable.models.oRow );
  449. oData._aData = aDataIn;
  450. oSettings.aoData.push( oData );
  451.  
  452. /* Create the cells */
  453. var nTd, sThisType;
  454. for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
  455. {
  456. oCol = oSettings.aoColumns[i];
  457.  
  458. /* Use rendered data for filtering/sorting */
  459. if ( typeof oCol.fnRender === 'function' && oCol.bUseRendered && oCol.mDataProp !== null )
  460. {
  461. _fnSetCellData( oSettings, iRow, i, _fnRender(oSettings, iRow, i) );
  462. }
  463. else
  464. {
  465. _fnSetCellData( oSettings, iRow, i, _fnGetCellData( oSettings, iRow, i ) );
  466. }
  467.  
  468. /* See if we should auto-detect the column type */
  469. if ( oCol._bAutoType && oCol.sType != 'string' )
  470. {
  471. /* Attempt to auto detect the type - same as _fnGatherData() */
  472. var sVarType = _fnGetCellData( oSettings, iRow, i, 'type' );
  473. if ( sVarType !== null && sVarType !== '' )
  474. {
  475. sThisType = _fnDetectType( sVarType );
  476. if ( oCol.sType === null )
  477. {
  478. oCol.sType = sThisType;
  479. }
  480. else if ( oCol.sType != sThisType && oCol.sType != "html" )
  481. {
  482. /* String is always the 'fallback' option */
  483. oCol.sType = 'string';
  484. }
  485. }
  486. }
  487. }
  488.  
  489. /* Add to the display array */
  490. oSettings.aiDisplayMaster.push( iRow );
  491.  
  492. /* Create the DOM imformation */
  493. if ( !oSettings.oFeatures.bDeferRender )
  494. {
  495. _fnCreateTr( oSettings, iRow );
  496. }
  497.  
  498. return iRow;
  499. }
  500.  
  501.  
  502. /**
  503. * Read in the data from the target table from the DOM
  504. * @param {object} oSettings dataTables settings object
  505. * @memberof DataTable#oApi
  506. */
  507. function _fnGatherData( oSettings )
  508. {
  509. var iLoop, i, iLen, j, jLen, jInner,
  510. nTds, nTrs, nTd, aLocalData, iThisIndex,
  511. iRow, iRows, iColumn, iColumns, sNodeName,
  512. oCol, oData;
  513.  
  514. /*
  515. * Process by row first
  516. * Add the data object for the whole table - storing the tr node. Note - no point in getting
  517. * DOM based data if we are going to go and replace it with Ajax source data.
  518. */
  519. if ( oSettings.bDeferLoading || oSettings.sAjaxSource === null )
  520. {
  521. nTrs = oSettings.nTBody.childNodes;
  522. for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
  523. {
  524. if ( nTrs[i].nodeName.toUpperCase() == "TR" )
  525. {
  526. iThisIndex = oSettings.aoData.length;
  527. nTrs[i]._DT_RowIndex = iThisIndex;
  528. oSettings.aoData.push( $.extend( true, {}, DataTable.models.oRow, {
  529. "nTr": nTrs[i]
  530. } ) );
  531.  
  532. oSettings.aiDisplayMaster.push( iThisIndex );
  533. nTds = nTrs[i].childNodes;
  534. jInner = 0;
  535.  
  536. for ( j=0, jLen=nTds.length ; j<jLen ; j++ )
  537. {
  538. sNodeName = nTds[j].nodeName.toUpperCase();
  539. if ( sNodeName == "TD" || sNodeName == "TH" )
  540. {
  541. _fnSetCellData( oSettings, iThisIndex, jInner, $.trim(nTds[j].innerHTML) );
  542. jInner++;
  543. }
  544. }
  545. }
  546. }
  547. }
  548.  
  549. /* Gather in the TD elements of the Table - note that this is basically the same as
  550. * fnGetTdNodes, but that function takes account of hidden columns, which we haven't yet
  551. * setup!
  552. */
  553. nTrs = _fnGetTrNodes( oSettings );
  554. nTds = [];
  555. for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
  556. {
  557. for ( j=0, jLen=nTrs[i].childNodes.length ; j<jLen ; j++ )
  558. {
  559. nTd = nTrs[i].childNodes[j];
  560. sNodeName = nTd.nodeName.toUpperCase();
  561. if ( sNodeName == "TD" || sNodeName == "TH" )
  562. {
  563. nTds.push( nTd );
  564. }
  565. }
  566. }
  567.  
  568. /* Now process by column */
  569. for ( iColumn=0, iColumns=oSettings.aoColumns.length ; iColumn<iColumns ; iColumn++ )
  570. {
  571. oCol = oSettings.aoColumns[iColumn];
  572.  
  573. /* Get the title of the column - unless there is a user set one */
  574. if ( oCol.sTitle === null )
  575. {
  576. oCol.sTitle = oCol.nTh.innerHTML;
  577. }
  578.  
  579. var
  580. bAutoType = oCol._bAutoType,
  581. bRender = typeof oCol.fnRender === 'function',
  582. bClass = oCol.sClass !== null,
  583. bVisible = oCol.bVisible,
  584. nCell, sThisType, sRendered, sValType;
  585.  
  586. /* A single loop to rule them all (and be more efficient) */
  587. if ( bAutoType || bRender || bClass || !bVisible )
  588. {
  589. for ( iRow=0, iRows=oSettings.aoData.length ; iRow<iRows ; iRow++ )
  590. {
  591. oData = oSettings.aoData[iRow];
  592. nCell = nTds[ (iRow*iColumns) + iColumn ];
  593.  
  594. /* Type detection */
  595. if ( bAutoType && oCol.sType != 'string' )
  596. {
  597. sValType = _fnGetCellData( oSettings, iRow, iColumn, 'type' );
  598. if ( sValType !== '' )
  599. {
  600. sThisType = _fnDetectType( sValType );
  601. if ( oCol.sType === null )
  602. {
  603. oCol.sType = sThisType;
  604. }
  605. else if ( oCol.sType != sThisType &&
  606. oCol.sType != "html" )
  607. {
  608. /* String is always the 'fallback' option */
  609. oCol.sType = 'string';
  610. }
  611. }
  612. }
  613.  
  614. if ( typeof oCol.mDataProp === 'function' )
  615. {
  616. nCell.innerHTML = _fnGetCellData( oSettings, iRow, iColumn, 'display' );
  617. }
  618.  
  619. /* Rendering */
  620. if ( bRender )
  621. {
  622. sRendered = _fnRender( oSettings, iRow, iColumn );
  623. nCell.innerHTML = sRendered;
  624. if ( oCol.bUseRendered )
  625. {
  626. /* Use the rendered data for filtering/sorting */
  627. _fnSetCellData( oSettings, iRow, iColumn, sRendered );
  628. }
  629. }
  630.  
  631. /* Classes */
  632. if ( bClass )
  633. {
  634. nCell.className += ' '+oCol.sClass;
  635. }
  636.  
  637. /* Column visability */
  638. if ( !bVisible )
  639. {
  640. oData._anHidden[iColumn] = nCell;
  641. nCell.parentNode.removeChild( nCell );
  642. }
  643. else
  644. {
  645. oData._anHidden[iColumn] = null;
  646. }
  647.  
  648. if ( oCol.fnCreatedCell )
  649. {
  650. oCol.fnCreatedCell.call( oSettings.oInstance,
  651. nCell, _fnGetCellData( oSettings, iRow, iColumn, 'display' ), oData._aData, iRow, iColumn
  652. );
  653. }
  654. }
  655. }
  656. }
  657.  
  658. /* Row created callbacks */
  659. if ( oSettings.aoRowCreatedCallback.length !== 0 )
  660. {
  661. for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
  662. {
  663. oData = oSettings.aoData[i];
  664. _fnCallbackFire( oSettings, 'aoRowCreatedCallback', null, [oData.nTr, oData._aData, i] );
  665. }
  666. }
  667. }
  668.  
  669.  
  670. /**
  671. * Take a TR element and convert it to an index in aoData
  672. * @param {object} oSettings dataTables settings object
  673. * @param {node} n the TR element to find
  674. * @returns {int} index if the node is found, null if not
  675. * @memberof DataTable#oApi
  676. */
  677. function _fnNodeToDataIndex( oSettings, n )
  678. {
  679. return (n._DT_RowIndex!==undefined) ? n._DT_RowIndex : null;
  680. }
  681.  
  682.  
  683. /**
  684. * Take a TD element and convert it into a column data index (not the visible index)
  685. * @param {object} oSettings dataTables settings object
  686. * @param {int} iRow The row number the TD/TH can be found in
  687. * @param {node} n The TD/TH element to find
  688. * @returns {int} index if the node is found, -1 if not
  689. * @memberof DataTable#oApi
  690. */
  691. function _fnNodeToColumnIndex( oSettings, iRow, n )
  692. {
  693. var anCells = _fnGetTdNodes( oSettings, iRow );
  694.  
  695. for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
  696. {
  697. if ( anCells[i] === n )
  698. {
  699. return i;
  700. }
  701. }
  702. return -1;
  703. }
  704.  
  705.  
  706. /**
  707. * Get an array of data for a given row from the internal data cache
  708. * @param {object} oSettings dataTables settings object
  709. * @param {int} iRow aoData row id
  710. * @param {string} sSpecific data get type ('type' 'filter' 'sort')
  711. * @returns {array} Data array
  712. * @memberof DataTable#oApi
  713. */
  714. function _fnGetRowData( oSettings, iRow, sSpecific )
  715. {
  716. var out = [];
  717. for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
  718. {
  719. out.push( _fnGetCellData( oSettings, iRow, i, sSpecific ) );
  720. }
  721. return out;
  722. }
  723.  
  724.  
  725. /**
  726. * Get the data for a given cell from the internal cache, taking into account data mapping
  727. * @param {object} oSettings dataTables settings object
  728. * @param {int} iRow aoData row id
  729. * @param {int} iCol Column index
  730. * @param {string} sSpecific data get type ('display', 'type' 'filter' 'sort')
  731. * @returns {*} Cell data
  732. * @memberof DataTable#oApi
  733. */
  734. function _fnGetCellData( oSettings, iRow, iCol, sSpecific )
  735. {
  736. var sData;
  737. var oCol = oSettings.aoColumns[iCol];
  738. var oData = oSettings.aoData[iRow]._aData;
  739.  
  740. if ( (sData=oCol.fnGetData( oData, sSpecific )) === undefined )
  741. {
  742. if ( oSettings.iDrawError != oSettings.iDraw && oCol.sDefaultContent === null )
  743. {
  744. _fnLog( oSettings, 0, "Requested unknown parameter "+
  745. (typeof oCol.mDataProp=='function' ? '{mDataprop function}' : "'"+oCol.mDataProp+"'")+
  746. " from the data source for row "+iRow );
  747. oSettings.iDrawError = oSettings.iDraw;
  748. }
  749. return oCol.sDefaultContent;
  750. }
  751.  
  752. /* When the data source is null, we can use default column data */
  753. if ( sData === null && oCol.sDefaultContent !== null )
  754. {
  755. sData = oCol.sDefaultContent;
  756. }
  757. else if ( typeof sData === 'function' )
  758. {
  759. /* If the data source is a function, then we run it and use the return */
  760. return sData();
  761. }
  762.  
  763. if ( sSpecific == 'display' && sData === null )
  764. {
  765. return '';
  766. }
  767. return sData;
  768. }
  769.  
  770.  
  771. /**
  772. * Set the value for a specific cell, into the internal data cache
  773. * @param {object} oSettings dataTables settings object
  774. * @param {int} iRow aoData row id
  775. * @param {int} iCol Column index
  776. * @param {*} val Value to set
  777. * @memberof DataTable#oApi
  778. */
  779. function _fnSetCellData( oSettings, iRow, iCol, val )
  780. {
  781. var oCol = oSettings.aoColumns[iCol];
  782. var oData = oSettings.aoData[iRow]._aData;
  783.  
  784. oCol.fnSetData( oData, val );
  785. }
  786.  
  787.  
  788. /**
  789. * Return a function that can be used to get data from a source object, taking
  790. * into account the ability to use nested objects as a source
  791. * @param {string|int|function} mSource The data source for the object
  792. * @returns {function} Data get function
  793. * @memberof DataTable#oApi
  794. */
  795. function _fnGetObjectDataFn( mSource )
  796. {
  797. if ( mSource === null )
  798. {
  799. /* Give an empty string for rendering / sorting etc */
  800. return function (data, type) {
  801. return null;
  802. };
  803. }
  804. else if ( typeof mSource === 'function' )
  805. {
  806. return function (data, type) {
  807. return mSource( data, type );
  808. };
  809. }
  810. else if ( typeof mSource === 'string' && mSource.indexOf('.') != -1 )
  811. {
  812. /* If there is a . in the source string then the data source is in a
  813. * nested object so we loop over the data for each level to get the next
  814. * level down. On each loop we test for undefined, and if found immediatly
  815. * return. This allows entire objects to be missing and sDefaultContent to
  816. * be used if defined, rather than throwing an error
  817. */
  818. var a = mSource.split('.');
  819. return function (data, type) {
  820. for ( var i=0, iLen=a.length ; i<iLen ; i++ )
  821. {
  822. data = data[ a[i] ];
  823. if ( data === undefined )
  824. {
  825. return undefined;
  826. }
  827. }
  828. return data;
  829. };
  830. }
  831. else
  832. {
  833. /* Array or flat object mapping */
  834. return function (data, type) {
  835. return data[mSource];
  836. };
  837. }
  838. }
  839.  
  840.  
  841. /**
  842. * Return a function that can be used to set data from a source object, taking
  843. * into account the ability to use nested objects as a source
  844. * @param {string|int|function} mSource The data source for the object
  845. * @returns {function} Data set function
  846. * @memberof DataTable#oApi
  847. */
  848. function _fnSetObjectDataFn( mSource )
  849. {
  850. if ( mSource === null )
  851. {
  852. /* Nothing to do when the data source is null */
  853. return function (data, val) {};
  854. }
  855. else if ( typeof mSource === 'function' )
  856. {
  857. return function (data, val) {
  858. mSource( data, 'set', val );
  859. };
  860. }
  861. else if ( typeof mSource === 'string' && mSource.indexOf('.') != -1 )
  862. {
  863. /* Like the get, we need to get data from a nested object. */
  864. var a = mSource.split('.');
  865. return function (data, val) {
  866. for ( var i=0, iLen=a.length-1 ; i<iLen ; i++ )
  867. {
  868. data = data[ a[i] ];
  869. if ( data === undefined )
  870. {
  871. return;
  872. }
  873. }
  874. data[ a[a.length-1] ] = val;
  875. };
  876. }
  877. else
  878. {
  879. /* Array or flat object mapping */
  880. return function (data, val) {
  881. data[mSource] = val;
  882. };
  883. }
  884. }
  885.  
  886.  
  887. /**
  888. * Return an array with the full table data
  889. * @param {object} oSettings dataTables settings object
  890. * @returns array {array} aData Master data array
  891. * @memberof DataTable#oApi
  892. */
  893. function _fnGetDataMaster ( oSettings )
  894. {
  895. var aData = [];
  896. var iLen = oSettings.aoData.length;
  897. for ( var i=0 ; i<iLen; i++ )
  898. {
  899. aData.push( oSettings.aoData[i]._aData );
  900. }
  901. return aData;
  902. }
  903.  
  904.  
  905. /**
  906. * Nuke the table
  907. * @param {object} oSettings dataTables settings object
  908. * @memberof DataTable#oApi
  909. */
  910. function _fnClearTable( oSettings )
  911. {
  912. oSettings.aoData.splice( 0, oSettings.aoData.length );
  913. oSettings.aiDisplayMaster.splice( 0, oSettings.aiDisplayMaster.length );
  914. oSettings.aiDisplay.splice( 0, oSettings.aiDisplay.length );
  915. _fnCalculateEnd( oSettings );
  916. }
  917.  
  918.  
  919. /**
  920. * Take an array of integers (index array) and remove a target integer (value - not
  921. * the key!)
  922. * @param {array} a Index array to target
  923. * @param {int} iTarget value to find
  924. * @memberof DataTable#oApi
  925. */
  926. function _fnDeleteIndex( a, iTarget )
  927. {
  928. var iTargetIndex = -1;
  929.  
  930. for ( var i=0, iLen=a.length ; i<iLen ; i++ )
  931. {
  932. if ( a[i] == iTarget )
  933. {
  934. iTargetIndex = i;
  935. }
  936. else if ( a[i] > iTarget )
  937. {
  938. a[i]--;
  939. }
  940. }
  941.  
  942. if ( iTargetIndex != -1 )
  943. {
  944. a.splice( iTargetIndex, 1 );
  945. }
  946. }
  947.  
  948.  
  949. /**
  950. * Call the developer defined fnRender function for a given cell (row/column) with
  951. * the required parameters and return the result.
  952. * @param {object} oSettings dataTables settings object
  953. * @param {int} iRow aoData index for the row
  954. * @param {int} iCol aoColumns index for the column
  955. * @returns {*} Return of the developer's fnRender function
  956. * @memberof DataTable#oApi
  957. */
  958. function _fnRender( oSettings, iRow, iCol )
  959. {
  960. var oCol = oSettings.aoColumns[iCol];
  961.  
  962. return oCol.fnRender( {
  963. "iDataRow": iRow,
  964. "iDataColumn": iCol,
  965. "oSettings": oSettings,
  966. "aData": oSettings.aoData[iRow]._aData,
  967. "mDataProp": oCol.mDataProp
  968. }, _fnGetCellData(oSettings, iRow, iCol, 'display') );
  969. }
  970.  
  971.  
  972. /**
  973. * Create a new TR element (and it's TD children) for a row
  974. * @param {object} oSettings dataTables settings object
  975. * @param {int} iRow Row to consider
  976. * @memberof DataTable#oApi
  977. */
  978. function _fnCreateTr ( oSettings, iRow )
  979. {
  980. var oData = oSettings.aoData[iRow];
  981. var nTd;
  982.  
  983. if ( oData.nTr === null )
  984. {
  985. oData.nTr = document.createElement('tr');
  986.  
  987. /* Use a private property on the node to allow reserve mapping from the node
  988. * to the aoData array for fast look up
  989. */
  990. oData.nTr._DT_RowIndex = iRow;
  991.  
  992. /* Special parameters can be given by the data source to be used on the row */
  993. if ( oData._aData.DT_RowId )
  994. {
  995. oData.nTr.id = oData._aData.DT_RowId;
  996. }
  997.  
  998. if ( oData._aData.DT_RowClass )
  999. {
  1000. $(oData.nTr).addClass( oData._aData.DT_RowClass );
  1001. }
  1002.  
  1003. /* Process each column */
  1004. for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
  1005. {
  1006. var oCol = oSettings.aoColumns[i];
  1007. nTd = document.createElement( oCol.sCellType );
  1008.  
  1009. /* Render if needed - if bUseRendered is true then we already have the rendered
  1010. * value in the data source - so can just use that
  1011. */
  1012. nTd.innerHTML = (typeof oCol.fnRender === 'function' && (!oCol.bUseRendered || oCol.mDataProp === null)) ?
  1013. _fnRender( oSettings, iRow, i ) :
  1014. _fnGetCellData( oSettings, iRow, i, 'display' );
  1015.  
  1016. /* Add user defined class */
  1017. if ( oCol.sClass !== null )
  1018. {
  1019. nTd.className = oCol.sClass;
  1020. }
  1021.  
  1022. if ( oCol.bVisible )
  1023. {
  1024. oData.nTr.appendChild( nTd );
  1025. oData._anHidden[i] = null;
  1026. }
  1027. else
  1028. {
  1029. oData._anHidden[i] = nTd;
  1030. }
  1031.  
  1032. if ( oCol.fnCreatedCell )
  1033. {
  1034. oCol.fnCreatedCell.call( oSettings.oInstance,
  1035. nTd, _fnGetCellData( oSettings, iRow, i, 'display' ), oData._aData, iRow, i
  1036. );
  1037. }
  1038. }
  1039.  
  1040. _fnCallbackFire( oSettings, 'aoRowCreatedCallback', null, [oData.nTr, oData._aData, iRow] );
  1041. }
  1042. }
  1043.  
  1044.  
  1045. /**
  1046. * Create the HTML header for the table
  1047. * @param {object} oSettings dataTables settings object
  1048. * @memberof DataTable#oApi
  1049. */
  1050. function _fnBuildHead( oSettings )
  1051. {
  1052. var i, nTh, iLen, j, jLen;
  1053. var iThs = oSettings.nTHead.getElementsByTagName('th').length;
  1054. var iCorrector = 0;
  1055. var jqChildren;
  1056.  
  1057. /* If there is a header in place - then use it - otherwise it's going to get nuked... */
  1058. if ( iThs !== 0 )
  1059. {
  1060. /* We've got a thead from the DOM, so remove hidden columns and apply width to vis cols */
  1061. for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
  1062. {
  1063. nTh = oSettings.aoColumns[i].nTh;
  1064. nTh.setAttribute('role', 'columnheader');
  1065. if ( oSettings.aoColumns[i].bSortable )
  1066. {
  1067. nTh.setAttribute('tabindex', oSettings.iTabIndex);
  1068. nTh.setAttribute('aria-controls', oSettings.sTableId);
  1069. }
  1070.  
  1071. if ( oSettings.aoColumns[i].sClass !== null )
  1072. {
  1073. $(nTh).addClass( oSettings.aoColumns[i].sClass );
  1074. }
  1075.  
  1076. /* Set the title of the column if it is user defined (not what was auto detected) */
  1077. if ( oSettings.aoColumns[i].sTitle != nTh.innerHTML )
  1078. {
  1079. nTh.innerHTML = oSettings.aoColumns[i].sTitle;
  1080. }
  1081. }
  1082. }
  1083. else
  1084. {
  1085. /* We don't have a header in the DOM - so we are going to have to create one */
  1086. var nTr = document.createElement( "tr" );
  1087.  
  1088. for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
  1089. {
  1090. nTh = oSettings.aoColumns[i].nTh;
  1091. nTh.innerHTML = oSettings.aoColumns[i].sTitle;
  1092. nTh.setAttribute('tabindex', '0');
  1093.  
  1094. if ( oSettings.aoColumns[i].sClass !== null )
  1095. {
  1096. $(nTh).addClass( oSettings.aoColumns[i].sClass );
  1097. }
  1098.  
  1099. nTr.appendChild( nTh );
  1100. }
  1101. $(oSettings.nTHead).html( '' )[0].appendChild( nTr );
  1102. _fnDetectHeader( oSettings.aoHeader, oSettings.nTHead );
  1103. }
  1104.  
  1105. /* ARIA role for the rows */
  1106. $(oSettings.nTHead).children('tr').attr('role', 'row');
  1107.  
  1108. /* Add the extra markup needed by jQuery UI's themes */
  1109. if ( oSettings.bJUI )
  1110. {
  1111. for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
  1112. {
  1113. nTh = oSettings.aoColumns[i].nTh;
  1114.  
  1115. var nDiv = document.createElement('div');
  1116. nDiv.className = oSettings.oClasses.sSortJUIWrapper;
  1117. $(nTh).contents().appendTo(nDiv);
  1118.  
  1119. var nSpan = document.createElement('span');
  1120. nSpan.className = oSettings.oClasses.sSortIcon;
  1121. nDiv.appendChild( nSpan );
  1122. nTh.appendChild( nDiv );
  1123. }
  1124. }
  1125.  
  1126. if ( oSettings.oFeatures.bSort )
  1127. {
  1128. for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
  1129. {
  1130. if ( oSettings.aoColumns[i].bSortable !== false )
  1131. {
  1132. _fnSortAttachListener( oSettings, oSettings.aoColumns[i].nTh, i );
  1133. }
  1134. else
  1135. {
  1136. $(oSettings.aoColumns[i].nTh).addClass( oSettings.oClasses.sSortableNone );
  1137. }
  1138. }
  1139. }
  1140.  
  1141. /* Deal with the footer - add classes if required */
  1142. if ( oSettings.oClasses.sFooterTH !== "" )
  1143. {
  1144. $(oSettings.nTFoot).children('tr').children('th').addClass( oSettings.oClasses.sFooterTH );
  1145. }
  1146.  
  1147. /* Cache the footer elements */
  1148. if ( oSettings.nTFoot !== null )
  1149. {
  1150. var anCells = _fnGetUniqueThs( oSettings, null, oSettings.aoFooter );
  1151. for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
  1152. {
  1153. if ( anCells[i] )
  1154. {
  1155. oSettings.aoColumns[i].nTf = anCells[i];
  1156. if ( oSettings.aoColumns[i].sClass )
  1157. {
  1158. $(anCells[i]).addClass( oSettings.aoColumns[i].sClass );
  1159. }
  1160. }
  1161. }
  1162. }
  1163. }
  1164.  
  1165.  
  1166. /**
  1167. * Draw the header (or footer) element based on the column visibility states. The
  1168. * methodology here is to use the layout array from _fnDetectHeader, modified for
  1169. * the instantaneous column visibility, to construct the new layout. The grid is
  1170. * traversed over cell at a time in a rows x columns grid fashion, although each
  1171. * cell insert can cover multiple elements in the grid - which is tracks using the
  1172. * aApplied array. Cell inserts in the grid will only occur where there isn't
  1173. * already a cell in that position.
  1174. * @param {object} oSettings dataTables settings object
  1175. * @param array {objects} aoSource Layout array from _fnDetectHeader
  1176. * @param {boolean} [bIncludeHidden=false] If true then include the hidden columns in the calc,
  1177. * @memberof DataTable#oApi
  1178. */
  1179. function _fnDrawHead( oSettings, aoSource, bIncludeHidden )
  1180. {
  1181. var i, iLen, j, jLen, k, kLen, n, nLocalTr;
  1182. var aoLocal = [];
  1183. var aApplied = [];
  1184. var iColumns = oSettings.aoColumns.length;
  1185. var iRowspan, iColspan;
  1186.  
  1187. if ( bIncludeHidden === undefined )
  1188. {
  1189. bIncludeHidden = false;
  1190. }
  1191.  
  1192. /* Make a copy of the master layout array, but without the visible columns in it */
  1193. for ( i=0, iLen=aoSource.length ; i<iLen ; i++ )
  1194. {
  1195. aoLocal[i] = aoSource[i].slice();
  1196. aoLocal[i].nTr = aoSource[i].nTr;
  1197.  
  1198. /* Remove any columns which are currently hidden */
  1199. for ( j=iColumns-1 ; j>=0 ; j-- )
  1200. {
  1201. if ( !oSettings.aoColumns[j].bVisible && !bIncludeHidden )
  1202. {
  1203. aoLocal[i].splice( j, 1 );
  1204. }
  1205. }
  1206.  
  1207. /* Prep the applied array - it needs an element for each row */
  1208. aApplied.push( [] );
  1209. }
  1210.  
  1211. for ( i=0, iLen=aoLocal.length ; i<iLen ; i++ )
  1212. {
  1213. nLocalTr = aoLocal[i].nTr;
  1214.  
  1215. /* All cells are going to be replaced, so empty out the row */
  1216. if ( nLocalTr )
  1217. {
  1218. while( (n = nLocalTr.firstChild) )
  1219. {
  1220. nLocalTr.removeChild( n );
  1221. }
  1222. }
  1223.  
  1224. for ( j=0, jLen=aoLocal[i].length ; j<jLen ; j++ )
  1225. {
  1226. iRowspan = 1;
  1227. iColspan = 1;
  1228.  
  1229. /* Check to see if there is already a cell (row/colspan) covering our target
  1230. * insert point. If there is, then there is nothing to do.
  1231. */
  1232. if ( aApplied[i][j] === undefined )
  1233. {
  1234. nLocalTr.appendChild( aoLocal[i][j].cell );
  1235. aApplied[i][j] = 1;
  1236.  
  1237. /* Expand the cell to cover as many rows as needed */
  1238. while ( aoLocal[i+iRowspan] !== undefined &&
  1239. aoLocal[i][j].cell == aoLocal[i+iRowspan][j].cell )
  1240. {
  1241. aApplied[i+iRowspan][j] = 1;
  1242. iRowspan++;
  1243. }
  1244.  
  1245. /* Expand the cell to cover as many columns as needed */
  1246. while ( aoLocal[i][j+iColspan] !== undefined &&
  1247. aoLocal[i][j].cell == aoLocal[i][j+iColspan].cell )
  1248. {
  1249. /* Must update the applied array over the rows for the columns */
  1250. for ( k=0 ; k<iRowspan ; k++ )
  1251. {
  1252. aApplied[i+k][j+iColspan] = 1;
  1253. }
  1254. iColspan++;
  1255. }
  1256.  
  1257. /* Do the actual expansion in the DOM */
  1258. aoLocal[i][j].cell.rowSpan = iRowspan;
  1259. aoLocal[i][j].cell.colSpan = iColspan;
  1260. }
  1261. }
  1262. }
  1263. }
  1264.  
  1265.  
  1266. /**
  1267. * Insert the required TR nodes into the table for display
  1268. * @param {object} oSettings dataTables settings object
  1269. * @memberof DataTable#oApi
  1270. */
  1271. function _fnDraw( oSettings )
  1272. {
  1273. var i, iLen, n;
  1274. var anRows = [];
  1275. var iRowCount = 0;
  1276. var iStripes = oSettings.asStripeClasses.length;
  1277. var iOpenRows = oSettings.aoOpenRows.length;
  1278.  
  1279. /* Provide a pre-callback function which can be used to cancel the draw is false is returned */
  1280. var aPreDraw = _fnCallbackFire( oSettings, 'aoPreDrawCallback', 'preDraw', [oSettings] );
  1281. if ( $.inArray( false, aPreDraw ) !== -1 )
  1282. {
  1283. _fnProcessingDisplay( oSettings, false );
  1284. return;
  1285. }
  1286.  
  1287. oSettings.bDrawing = true;
  1288.  
  1289. /* Check and see if we have an initial draw position from state saving */
  1290. if ( oSettings.iInitDisplayStart !== undefined && oSettings.iInitDisplayStart != -1 )
  1291. {
  1292. if ( oSettings.oFeatures.bServerSide )
  1293. {
  1294. oSettings._iDisplayStart = oSettings.iInitDisplayStart;
  1295. }
  1296. else
  1297. {
  1298. oSettings._iDisplayStart = (oSettings.iInitDisplayStart >= oSettings.fnRecordsDisplay()) ?
  1299. 0 : oSettings.iInitDisplayStart;
  1300. }
  1301. oSettings.iInitDisplayStart = -1;
  1302. _fnCalculateEnd( oSettings );
  1303. }
  1304.  
  1305. /* Server-side processing draw intercept */
  1306. if ( oSettings.bDeferLoading )
  1307. {
  1308. oSettings.bDeferLoading = false;
  1309. oSettings.iDraw++;
  1310. }
  1311. else if ( !oSettings.oFeatures.bServerSide )
  1312. {
  1313. oSettings.iDraw++;
  1314. }
  1315. else if ( !oSettings.bDestroying && !_fnAjaxUpdate( oSettings ) )
  1316. {
  1317. return;
  1318. }
  1319.  
  1320. if ( oSettings.aiDisplay.length !== 0 )
  1321. {
  1322. var iStart = oSettings._iDisplayStart;
  1323. var iEnd = oSettings._iDisplayEnd;
  1324.  
  1325. if ( oSettings.oFeatures.bServerSide )
  1326. {
  1327. iStart = 0;
  1328. iEnd = oSettings.aoData.length;
  1329. }
  1330.  
  1331. for ( var j=iStart ; j<iEnd ; j++ )
  1332. {
  1333. var aoData = oSettings.aoData[ oSettings.aiDisplay[j] ];
  1334. if ( aoData.nTr === null )
  1335. {
  1336. _fnCreateTr( oSettings, oSettings.aiDisplay[j] );
  1337. }
  1338.  
  1339. var nRow = aoData.nTr;
  1340.  
  1341. /* Remove the old striping classes and then add the new one */
  1342. if ( iStripes !== 0 )
  1343. {
  1344. var sStripe = oSettings.asStripeClasses[ iRowCount % iStripes ];
  1345. if ( aoData._sRowStripe != sStripe )
  1346. {
  1347. $(nRow).removeClass( aoData._sRowStripe ).addClass( sStripe );
  1348. aoData._sRowStripe = sStripe;
  1349. }
  1350. }
  1351.  
  1352. /* Row callback functions - might want to manipule the row */
  1353. _fnCallbackFire( oSettings, 'aoRowCallback', null,
  1354. [nRow, oSettings.aoData[ oSettings.aiDisplay[j] ]._aData, iRowCount, j] );
  1355.  
  1356. anRows.push( nRow );
  1357. iRowCount++;
  1358.  
  1359. /* If there is an open row - and it is attached to this parent - attach it on redraw */
  1360. if ( iOpenRows !== 0 )
  1361. {
  1362. for ( var k=0 ; k<iOpenRows ; k++ )
  1363. {
  1364. if ( nRow == oSettings.aoOpenRows[k].nParent )
  1365. {
  1366. anRows.push( oSettings.aoOpenRows[k].nTr );
  1367. break;
  1368. }
  1369. }
  1370. }
  1371. }
  1372. }
  1373. else
  1374. {
  1375. /* Table is empty - create a row with an empty message in it */
  1376. anRows[ 0 ] = document.createElement( 'tr' );
  1377.  
  1378. if ( oSettings.asStripeClasses[0] )
  1379. {
  1380. anRows[ 0 ].className = oSettings.asStripeClasses[0];
  1381. }
  1382.  
  1383. var oLang = oSettings.oLanguage;
  1384. var sZero = oLang.sZeroRecords;
  1385. if ( oSettings.iDraw == 1 && oSettings.sAjaxSource !== null && !oSettings.oFeatures.bServerSide )
  1386. {
  1387. sZero = oLang.sLoadingRecords;
  1388. }
  1389. else if ( oLang.sEmptyTable && oSettings.fnRecordsTotal() === 0 )
  1390. {
  1391. sZero = oLang.sEmptyTable;
  1392. }
  1393.  
  1394. var nTd = document.createElement( 'td' );
  1395. nTd.setAttribute( 'valign', "top" );
  1396. nTd.colSpan = _fnVisbleColumns( oSettings );
  1397. nTd.className = oSettings.oClasses.sRowEmpty;
  1398. nTd.innerHTML = _fnInfoMacros( oSettings, sZero );
  1399.  
  1400. anRows[ iRowCount ].appendChild( nTd );
  1401. }
  1402.  
  1403. /* Header and footer callbacks */
  1404. _fnCallbackFire( oSettings, 'aoHeaderCallback', 'header', [ $(oSettings.nTHead).children('tr')[0],
  1405. _fnGetDataMaster( oSettings ), oSettings._iDisplayStart, oSettings.fnDisplayEnd(), oSettings.aiDisplay ] );
  1406.  
  1407. _fnCallbackFire( oSettings, 'aoFooterCallback', 'footer', [ $(oSettings.nTFoot).children('tr')[0],
  1408. _fnGetDataMaster( oSettings ), oSettings._iDisplayStart, oSettings.fnDisplayEnd(), oSettings.aiDisplay ] );
  1409.  
  1410. /*
  1411. * Need to remove any old row from the display - note we can't just empty the tbody using
  1412. * $().html('') since this will unbind the jQuery event handlers (even although the node
  1413. * still exists!) - equally we can't use innerHTML, since IE throws an exception.
  1414. */
  1415. var
  1416. nAddFrag = document.createDocumentFragment(),
  1417. nRemoveFrag = document.createDocumentFragment(),
  1418. nBodyPar, nTrs;
  1419.  
  1420. if ( oSettings.nTBody )
  1421. {
  1422. nBodyPar = oSettings.nTBody.parentNode;
  1423. nRemoveFrag.appendChild( oSettings.nTBody );
  1424.  
  1425. /* When doing infinite scrolling, only remove child rows when sorting, filtering or start
  1426. * up. When not infinite scroll, always do it.
  1427. */
  1428. if ( !oSettings.oScroll.bInfinite || !oSettings._bInitComplete ||
  1429. oSettings.bSorted || oSettings.bFiltered )
  1430. {
  1431. while( (n = oSettings.nTBody.firstChild) )
  1432. {
  1433. oSettings.nTBody.removeChild( n );
  1434. }
  1435. }
  1436.  
  1437. /* Put the draw table into the dom */
  1438. for ( i=0, iLen=anRows.length ; i<iLen ; i++ )
  1439. {
  1440. nAddFrag.appendChild( anRows[i] );
  1441. }
  1442.  
  1443. oSettings.nTBody.appendChild( nAddFrag );
  1444. if ( nBodyPar !== null )
  1445. {
  1446. nBodyPar.appendChild( oSettings.nTBody );
  1447. }
  1448. }
  1449.  
  1450. /* Call all required callback functions for the end of a draw */
  1451. _fnCallbackFire( oSettings, 'aoDrawCallback', 'draw', [oSettings] );
  1452.  
  1453. /* Draw is complete, sorting and filtering must be as well */
  1454. oSettings.bSorted = false;
  1455. oSettings.bFiltered = false;
  1456. oSettings.bDrawing = false;
  1457.  
  1458. if ( oSettings.oFeatures.bServerSide )
  1459. {
  1460. _fnProcessingDisplay( oSettings, false );
  1461. if ( !oSettings._bInitComplete )
  1462. {
  1463. _fnInitComplete( oSettings );
  1464. }
  1465. }
  1466. }
  1467.  
  1468.  
  1469. /**
  1470. * Redraw the table - taking account of the various features which are enabled
  1471. * @param {object} oSettings dataTables settings object
  1472. * @memberof DataTable#oApi
  1473. */
  1474. function _fnReDraw( oSettings )
  1475. {
  1476. if ( oSettings.oFeatures.bSort )
  1477. {
  1478. /* Sorting will refilter and draw for us */
  1479. _fnSort( oSettings, oSettings.oPreviousSearch );
  1480. }
  1481. else if ( oSettings.oFeatures.bFilter )
  1482. {
  1483. /* Filtering will redraw for us */
  1484. _fnFilterComplete( oSettings, oSettings.oPreviousSearch );
  1485. }
  1486. else
  1487. {
  1488. _fnCalculateEnd( oSettings );
  1489. _fnDraw( oSettings );
  1490. }
  1491. }
  1492.  
  1493.  
  1494. /**
  1495. * Add the options to the page HTML for the table
  1496. * @param {object} oSettings dataTables settings object
  1497. * @memberof DataTable#oApi
  1498. */
  1499. function _fnAddOptionsHtml ( oSettings )
  1500. {
  1501. /*
  1502. * Create a temporary, empty, div which we can later on replace with what we have generated
  1503. * we do it this way to rendering the 'options' html offline - speed :-)
  1504. */
  1505. var nHolding = $('<div></div>')[0];
  1506. oSettings.nTable.parentNode.insertBefore( nHolding, oSettings.nTable );
  1507.  
  1508. /*
  1509. * All DataTables are wrapped in a div
  1510. */
  1511. oSettings.nTableWrapper = $('<div id="'+oSettings.sTableId+'_wrapper" class="'+oSettings.oClasses.sWrapper+'" role="grid"></div>')[0];
  1512. oSettings.nTableReinsertBefore = oSettings.nTable.nextSibling;
  1513.  
  1514. /* Track where we want to insert the option */
  1515. var nInsertNode = oSettings.nTableWrapper;
  1516.  
  1517. /* Loop over the user set positioning and place the elements as needed */
  1518. var aDom = oSettings.sDom.split('');
  1519. var nTmp, iPushFeature, cOption, nNewNode, cNext, sAttr, j;
  1520. for ( var i=0 ; i<aDom.length ; i++ )
  1521. {
  1522. iPushFeature = 0;
  1523. cOption = aDom[i];
  1524.  
  1525. if ( cOption == '<' )
  1526. {
  1527. /* New container div */
  1528. nNewNode = $('<div></div>')[0];
  1529.  
  1530. /* Check to see if we should append an id and/or a class name to the container */
  1531. cNext = aDom[i+1];
  1532. if ( cNext == "'" || cNext == '"' )
  1533. {
  1534. sAttr = "";
  1535. j = 2;
  1536. while ( aDom[i+j] != cNext )
  1537. {
  1538. sAttr += aDom[i+j];
  1539. j++;
  1540. }
  1541.  
  1542. /* Replace jQuery UI constants */
  1543. if ( sAttr == "H" )
  1544. {
  1545. sAttr = "fg-toolbar ui-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix";
  1546. }
  1547. else if ( sAttr == "F" )
  1548. {
  1549. sAttr = "fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix";
  1550. }
  1551.  
  1552. /* The attribute can be in the format of "#id.class", "#id" or "class" This logic
  1553. * breaks the string into parts and applies them as needed
  1554. */
  1555. if ( sAttr.indexOf('.') != -1 )
  1556. {
  1557. var aSplit = sAttr.split('.');
  1558. nNewNode.id = aSplit[0].substr(1, aSplit[0].length-1);
  1559. nNewNode.className = aSplit[1];
  1560. }
  1561. else if ( sAttr.charAt(0) == "#" )
  1562. {
  1563. nNewNode.id = sAttr.substr(1, sAttr.length-1);
  1564. }
  1565. else
  1566. {
  1567. nNewNode.className = sAttr;
  1568. }
  1569.  
  1570. i += j; /* Move along the position array */
  1571. }
  1572.  
  1573. nInsertNode.appendChild( nNewNode );
  1574. nInsertNode = nNewNode;
  1575. }
  1576. else if ( cOption == '>' )
  1577. {
  1578. /* End container div */
  1579. nInsertNode = nInsertNode.parentNode;
  1580. }
  1581. else if ( cOption == 'l' && oSettings.oFeatures.bPaginate && oSettings.oFeatures.bLengthChange )
  1582. {
  1583. /* Length */
  1584. nTmp = _fnFeatureHtmlLength( oSettings );
  1585. iPushFeature = 1;
  1586. }
  1587. else if ( cOption == 'f' && oSettings.oFeatures.bFilter )
  1588. {
  1589. /* Filter */
  1590. nTmp = _fnFeatureHtmlFilter( oSettings );
  1591. iPushFeature = 1;
  1592. }
  1593. else if ( cOption == 'r' && oSettings.oFeatures.bProcessing )
  1594. {
  1595. /* pRocessing */
  1596. nTmp = _fnFeatureHtmlProcessing( oSettings );
  1597. iPushFeature = 1;
  1598. }
  1599. else if ( cOption == 't' )
  1600. {
  1601. /* Table */
  1602. nTmp = _fnFeatureHtmlTable( oSettings );
  1603. iPushFeature = 1;
  1604. }
  1605. else if ( cOption == 'i' && oSettings.oFeatures.bInfo )
  1606. {
  1607. /* Info */
  1608. nTmp = _fnFeatureHtmlInfo( oSettings );
  1609. iPushFeature = 1;
  1610. }
  1611. else if ( cOption == 'p' && oSettings.oFeatures.bPaginate )
  1612. {
  1613. /* Pagination */
  1614. nTmp = _fnFeatureHtmlPaginate( oSettings );
  1615. iPushFeature = 1;
  1616. }
  1617. else if ( DataTable.ext.aoFeatures.length !== 0 )
  1618. {
  1619. /* Plug-in features */
  1620. var aoFeatures = DataTable.ext.aoFeatures;
  1621. for ( var k=0, kLen=aoFeatures.length ; k<kLen ; k++ )
  1622. {
  1623. if ( cOption == aoFeatures[k].cFeature )
  1624. {
  1625. nTmp = aoFeatures[k].fnInit( oSettings );
  1626. if ( nTmp )
  1627. {
  1628. iPushFeature = 1;
  1629. }
  1630. break;
  1631. }
  1632. }
  1633. }
  1634.  
  1635. /* Add to the 2D features array */
  1636. if ( iPushFeature == 1 && nTmp !== null )
  1637. {
  1638. if ( typeof oSettings.aanFeatures[cOption] !== 'object' )
  1639. {
  1640. oSettings.aanFeatures[cOption] = [];
  1641. }
  1642. oSettings.aanFeatures[cOption].push( nTmp );
  1643. nInsertNode.appendChild( nTmp );
  1644. }
  1645. }
  1646.  
  1647. /* Built our DOM structure - replace the holding div with what we want */
  1648. nHolding.parentNode.replaceChild( oSettings.nTableWrapper, nHolding );
  1649. }
  1650.  
  1651.  
  1652. /**
  1653. * Use the DOM source to create up an array of header cells. The idea here is to
  1654. * create a layout grid (array) of rows x columns, which contains a reference
  1655. * to the cell that that point in the grid (regardless of col/rowspan), such that
  1656. * any column / row could be removed and the new grid constructed
  1657. * @param array {object} aLayout Array to store the calculated layout in
  1658. * @param {node} nThead The header/footer element for the table
  1659. * @memberof DataTable#oApi
  1660. */
  1661. function _fnDetectHeader ( aLayout, nThead )
  1662. {
  1663. var nTrs = $(nThead).children('tr');
  1664. var nCell;
  1665. var i, j, k, l, iLen, jLen, iColShifted;
  1666. var fnShiftCol = function ( a, i, j ) {
  1667. while ( a[i][j] ) {
  1668. j++;
  1669. }
  1670. return j;
  1671. };
  1672.  
  1673. aLayout.splice( 0, aLayout.length );
  1674.  
  1675. /* We know how many rows there are in the layout - so prep it */
  1676. for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
  1677. {
  1678. aLayout.push( [] );
  1679. }
  1680.  
  1681. /* Calculate a layout array */
  1682. for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
  1683. {
  1684. var iColumn = 0;
  1685.  
  1686. /* For every cell in the row... */
  1687. for ( j=0, jLen=nTrs[i].childNodes.length ; j<jLen ; j++ )
  1688. {
  1689. nCell = nTrs[i].childNodes[j];
  1690.  
  1691. if ( nCell.nodeName.toUpperCase() == "TD" ||
  1692. nCell.nodeName.toUpperCase() == "TH" )
  1693. {
  1694. /* Get the col and rowspan attributes from the DOM and sanitise them */
  1695. var iColspan = nCell.getAttribute('colspan') * 1;
  1696. var iRowspan = nCell.getAttribute('rowspan') * 1;
  1697. iColspan = (!iColspan || iColspan===0 || iColspan===1) ? 1 : iColspan;
  1698. iRowspan = (!iRowspan || iRowspan===0 || iRowspan===1) ? 1 : iRowspan;
  1699.  
  1700. /* There might be colspan cells already in this row, so shift our target
  1701. * accordingly
  1702. */
  1703. iColShifted = fnShiftCol( aLayout, i, iColumn );
  1704.  
  1705. /* If there is col / rowspan, copy the information into the layout grid */
  1706. for ( l=0 ; l<iColspan ; l++ )
  1707. {
  1708. for ( k=0 ; k<iRowspan ; k++ )
  1709. {
  1710. aLayout[i+k][iColShifted+l] = {
  1711. "cell": nCell,
  1712. "unique": iColspan == 1 ? true : false
  1713. };
  1714. aLayout[i+k].nTr = nTrs[i];
  1715. }
  1716. }
  1717. }
  1718. }
  1719. }
  1720. }
  1721.  
  1722.  
  1723. /**
  1724. * Get an array of unique th elements, one for each column
  1725. * @param {object} oSettings dataTables settings object
  1726. * @param {node} nHeader automatically detect the layout from this node - optional
  1727. * @param {array} aLayout thead/tfoot layout from _fnDetectHeader - optional
  1728. * @returns array {node} aReturn list of unique ths
  1729. * @memberof DataTable#oApi
  1730. */
  1731. function _fnGetUniqueThs ( oSettings, nHeader, aLayout )
  1732. {
  1733. var aReturn = [];
  1734. if ( !aLayout )
  1735. {
  1736. aLayout = oSettings.aoHeader;
  1737. if ( nHeader )
  1738. {
  1739. aLayout = [];
  1740. _fnDetectHeader( aLayout, nHeader );
  1741. }
  1742. }
  1743.  
  1744. for ( var i=0, iLen=aLayout.length ; i<iLen ; i++ )
  1745. {
  1746. for ( var j=0, jLen=aLayout[i].length ; j<jLen ; j++ )
  1747. {
  1748. if ( aLayout[i][j].unique &&
  1749. (!aReturn[j] || !oSettings.bSortCellsTop) )
  1750. {
  1751. aReturn[j] = aLayout[i][j].cell;
  1752. }
  1753. }
  1754. }
  1755.  
  1756. return aReturn;
  1757. }
  1758.  
  1759.  
  1760.  
  1761. /**
  1762. * Update the table using an Ajax call
  1763. * @param {object} oSettings dataTables settings object
  1764. * @returns {boolean} Block the table drawing or not
  1765. * @memberof DataTable#oApi
  1766. */
  1767. function _fnAjaxUpdate( oSettings )
  1768. {
  1769. if ( oSettings.bAjaxDataGet )
  1770. {
  1771. oSettings.iDraw++;
  1772. _fnProcessingDisplay( oSettings, true );
  1773. var iColumns = oSettings.aoColumns.length;
  1774. var aoData = _fnAjaxParameters( oSettings );
  1775. _fnServerParams( oSettings, aoData );
  1776.  
  1777. oSettings.fnServerData.call( oSettings.oInstance, oSettings.sAjaxSource, aoData,
  1778. function(json) {
  1779. _fnAjaxUpdateDraw( oSettings, json );
  1780. }, oSettings );
  1781. return false;
  1782. }
  1783. else
  1784. {
  1785. return true;
  1786. }
  1787. }
  1788.  
  1789.  
  1790. /**
  1791. * Build up the parameters in an object needed for a server-side processing request
  1792. * @param {object} oSettings dataTables settings object
  1793. * @returns {bool} block the table drawing or not
  1794. * @memberof DataTable#oApi
  1795. */
  1796. function _fnAjaxParameters( oSettings )
  1797. {
  1798. var iColumns = oSettings.aoColumns.length;
  1799. var aoData = [], mDataProp, aaSort, aDataSort;
  1800. var i, j;
  1801.  
  1802. aoData.push( { "name": "sEcho", "value": oSettings.iDraw } );
  1803. aoData.push( { "name": "iColumns", "value": iColumns } );
  1804. aoData.push( { "name": "sColumns", "value": _fnColumnOrdering(oSettings) } );
  1805. aoData.push( { "name": "iDisplayStart", "value": oSettings._iDisplayStart } );
  1806. aoData.push( { "name": "iDisplayLength", "value": oSettings.oFeatures.bPaginate !== false ?
  1807. oSettings._iDisplayLength : -1 } );
  1808.  
  1809. for ( i=0 ; i<iColumns ; i++ )
  1810. {
  1811. mDataProp = oSettings.aoColumns[i].mDataProp;
  1812. aoData.push( { "name": "mDataProp_"+i, "value": typeof(mDataProp)==="function" ? 'function' : mDataProp } );
  1813. }
  1814.  
  1815. /* Filtering */
  1816. if ( oSettings.oFeatures.bFilter !== false )
  1817. {
  1818. aoData.push( { "name": "sSearch", "value": oSettings.oPreviousSearch.sSearch } );
  1819. aoData.push( { "name": "bRegex", "value": oSettings.oPreviousSearch.bRegex } );
  1820. for ( i=0 ; i<iColumns ; i++ )
  1821. {
  1822. aoData.push( { "name": "sSearch_"+i, "value": oSettings.aoPreSearchCols[i].sSearch } );
  1823. aoData.push( { "name": "bRegex_"+i, "value": oSettings.aoPreSearchCols[i].bRegex } );
  1824. aoData.push( { "name": "bSearchable_"+i, "value": oSettings.aoColumns[i].bSearchable } );
  1825. }
  1826. }
  1827.  
  1828. /* Sorting */
  1829. if ( oSettings.oFeatures.bSort !== false )
  1830. {
  1831. var iCounter = 0;
  1832.  
  1833. aaSort = ( oSettings.aaSortingFixed !== null ) ?
  1834. oSettings.aaSortingFixed.concat( oSettings.aaSorting ) :
  1835. oSettings.aaSorting.slice();
  1836.  
  1837. for ( i=0 ; i<aaSort.length ; i++ )
  1838. {
  1839. aDataSort = oSettings.aoColumns[ aaSort[i][0] ].aDataSort;
  1840.  
  1841. for ( j=0 ; j<aDataSort.length ; j++ )
  1842. {
  1843. aoData.push( { "name": "iSortCol_"+iCounter, "value": aDataSort[j] } );
  1844. aoData.push( { "name": "sSortDir_"+iCounter, "value": aaSort[i][1] } );
  1845. iCounter++;
  1846. }
  1847. }
  1848. aoData.push( { "name": "iSortingCols", "value": iCounter } );
  1849.  
  1850. for ( i=0 ; i<iColumns ; i++ )
  1851. {
  1852. aoData.push( { "name": "bSortable_"+i, "value": oSettings.aoColumns[i].bSortable } );
  1853. }
  1854. }
  1855.  
  1856. return aoData;
  1857. }
  1858.  
  1859.  
  1860. /**
  1861. * Add Ajax parameters from plugins
  1862. * @param {object} oSettings dataTables settings object
  1863. * @param array {objects} aoData name/value pairs to send to the server
  1864. * @memberof DataTable#oApi
  1865. */
  1866. function _fnServerParams( oSettings, aoData )
  1867. {
  1868. _fnCallbackFire( oSettings, 'aoServerParams', 'serverParams', [aoData] );
  1869. }
  1870.  
  1871.  
  1872. /**
  1873. * Data the data from the server (nuking the old) and redraw the table
  1874. * @param {object} oSettings dataTables settings object
  1875. * @param {object} json json data return from the server.
  1876. * @param {string} json.sEcho Tracking flag for DataTables to match requests
  1877. * @param {int} json.iTotalRecords Number of records in the data set, not accounting for filtering
  1878. * @param {int} json.iTotalDisplayRecords Number of records in the data set, accounting for filtering
  1879. * @param {array} json.aaData The data to display on this page
  1880. * @param {string} [json.sColumns] Column ordering (sName, comma separated)
  1881. * @memberof DataTable#oApi
  1882. */
  1883. function _fnAjaxUpdateDraw ( oSettings, json )
  1884. {
  1885. if ( json.sEcho !== undefined )
  1886. {
  1887. /* Protect against old returns over-writing a new one. Possible when you get
  1888. * very fast interaction, and later queires are completed much faster
  1889. */
  1890. if ( json.sEcho*1 < oSettings.iDraw )
  1891. {
  1892. return;
  1893. }
  1894. else
  1895. {
  1896. oSettings.iDraw = json.sEcho * 1;
  1897. }
  1898. }
  1899.  
  1900. if ( !oSettings.oScroll.bInfinite ||
  1901. (oSettings.oScroll.bInfinite && (oSettings.bSorted || oSettings.bFiltered)) )
  1902. {
  1903. _fnClearTable( oSettings );
  1904. }
  1905. oSettings._iRecordsTotal = parseInt(json.iTotalRecords, 10);
  1906. oSettings._iRecordsDisplay = parseInt(json.iTotalDisplayRecords, 10);
  1907.  
  1908. /* Determine if reordering is required */
  1909. var sOrdering = _fnColumnOrdering(oSettings);
  1910. var bReOrder = (json.sColumns !== undefined && sOrdering !== "" && json.sColumns != sOrdering );
  1911. var aiIndex;
  1912. if ( bReOrder )
  1913. {
  1914. aiIndex = _fnReOrderIndex( oSettings, json.sColumns );
  1915. }
  1916.  
  1917. var aData = _fnGetObjectDataFn( oSettings.sAjaxDataProp )( json );
  1918. for ( var i=0, iLen=aData.length ; i<iLen ; i++ )
  1919. {
  1920. if ( bReOrder )
  1921. {
  1922. /* If we need to re-order, then create a new array with the correct order and add it */
  1923. var aDataSorted = [];
  1924. for ( var j=0, jLen=oSettings.aoColumns.length ; j<jLen ; j++ )
  1925. {
  1926. aDataSorted.push( aData[i][ aiIndex[j] ] );
  1927. }
  1928. _fnAddData( oSettings, aDataSorted );
  1929. }
  1930. else
  1931. {
  1932. /* No re-order required, sever got it "right" - just straight add */
  1933. _fnAddData( oSettings, aData[i] );
  1934. }
  1935. }
  1936. oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
  1937.  
  1938. oSettings.bAjaxDataGet = false;
  1939. _fnDraw( oSettings );
  1940. oSettings.bAjaxDataGet = true;
  1941. _fnProcessingDisplay( oSettings, false );
  1942. }
  1943.  
  1944.  
  1945.  
  1946. /**
  1947. * Generate the node required for filtering text
  1948. * @returns {node} Filter control element
  1949. * @param {object} oSettings dataTables settings object
  1950. * @memberof DataTable#oApi
  1951. */
  1952. function _fnFeatureHtmlFilter ( oSettings )
  1953. {
  1954. var oPreviousSearch = oSettings.oPreviousSearch;
  1955.  
  1956. var sSearchStr = oSettings.oLanguage.sSearch;
  1957. sSearchStr = (sSearchStr.indexOf('_INPUT_') !== -1) ?
  1958. sSearchStr.replace('_INPUT_', '<input type="text" />') :
  1959. sSearchStr==="" ? '<input type="text" />' : sSearchStr+' <input type="text" />';
  1960.  
  1961. var nFilter = document.createElement( 'div' );
  1962. nFilter.className = oSettings.oClasses.sFilter;
  1963. nFilter.innerHTML = '<label>'+sSearchStr+'</label>';
  1964. if ( !oSettings.aanFeatures.f )
  1965. {
  1966. nFilter.id = oSettings.sTableId+'_filter';
  1967. }
  1968.  
  1969. var jqFilter = $('input[type="text"]', nFilter);
  1970.  
  1971. // Store a reference to the input element, so other input elements could be
  1972. // added to the filter wrapper if needed (submit button for example)
  1973. nFilter._DT_Input = jqFilter[0];
  1974.  
  1975. jqFilter.val( oPreviousSearch.sSearch.replace('"','&quot;') );
  1976. jqFilter.bind( 'keyup.DT', function(e) {
  1977. /* Update all other filter input elements for the new display */
  1978. var n = oSettings.aanFeatures.f;
  1979. var val = this.value==="" ? "" : this.value; // mental IE8 fix :-(
  1980.  
  1981. for ( var i=0, iLen=n.length ; i<iLen ; i++ )
  1982. {
  1983. if ( n[i] != $(this).parents('div.dataTables_filter')[0] )
  1984. {
  1985. $(n[i]._DT_Input).val( val );
  1986. }
  1987. }
  1988.  
  1989. /* Now do the filter */
  1990. if ( val != oPreviousSearch.sSearch )
  1991. {
  1992. _fnFilterComplete( oSettings, {
  1993. "sSearch": val,
  1994. "bRegex": oPreviousSearch.bRegex,
  1995. "bSmart": oPreviousSearch.bSmart ,
  1996. "bCaseInsensitive": oPreviousSearch.bCaseInsensitive
  1997. } );
  1998. }
  1999. } );
  2000.  
  2001. jqFilter
  2002. .attr('aria-controls', oSettings.sTableId)
  2003. .bind( 'keypress.DT', function(e) {
  2004. /* Prevent form submission */
  2005. if ( e.keyCode == 13 )
  2006. {
  2007. return false;
  2008. }
  2009. }
  2010. );
  2011.  
  2012. return nFilter;
  2013. }
  2014.  
  2015.  
  2016. /**
  2017. * Filter the table using both the global filter and column based filtering
  2018. * @param {object} oSettings dataTables settings object
  2019. * @param {object} oSearch search information
  2020. * @param {int} [iForce] force a research of the master array (1) or not (undefined or 0)
  2021. * @memberof DataTable#oApi
  2022. */
  2023. function _fnFilterComplete ( oSettings, oInput, iForce )
  2024. {
  2025. var oPrevSearch = oSettings.oPreviousSearch;
  2026. var aoPrevSearch = oSettings.aoPreSearchCols;
  2027. var fnSaveFilter = function ( oFilter ) {
  2028. /* Save the filtering values */
  2029. oPrevSearch.sSearch = oFilter.sSearch;
  2030. oPrevSearch.bRegex = oFilter.bRegex;
  2031. oPrevSearch.bSmart = oFilter.bSmart;
  2032. oPrevSearch.bCaseInsensitive = oFilter.bCaseInsensitive;
  2033. };
  2034.  
  2035. /* In server-side processing all filtering is done by the server, so no point hanging around here */
  2036. if ( !oSettings.oFeatures.bServerSide )
  2037. {
  2038. /* Global filter */
  2039. _fnFilter( oSettings, oInput.sSearch, iForce, oInput.bRegex, oInput.bSmart, oInput.bCaseInsensitive );
  2040. fnSaveFilter( oInput );
  2041.  
  2042. /* Now do the individual column filter */
  2043. for ( var i=0 ; i<oSettings.aoPreSearchCols.length ; i++ )
  2044. {
  2045. _fnFilterColumn( oSettings, aoPrevSearch[i].sSearch, i, aoPrevSearch[i].bRegex,
  2046. aoPrevSearch[i].bSmart, aoPrevSearch[i].bCaseInsensitive );
  2047. }
  2048.  
  2049. /* Custom filtering */
  2050. _fnFilterCustom( oSettings );
  2051. }
  2052. else
  2053. {
  2054. fnSaveFilter( oInput );
  2055. }
  2056.  
  2057. /* Tell the draw function we have been filtering */
  2058. oSettings.bFiltered = true;
  2059. $(oSettings.oInstance).trigger('filter', oSettings);
  2060.  
  2061. /* Redraw the table */
  2062. oSettings._iDisplayStart = 0;
  2063. _fnCalculateEnd( oSettings );
  2064. _fnDraw( oSettings );
  2065.  
  2066. /* Rebuild search array 'offline' */
  2067. _fnBuildSearchArray( oSettings, 0 );
  2068. }
  2069.  
  2070.  
  2071. /**
  2072. * Apply custom filtering functions
  2073. * @param {object} oSettings dataTables settings object
  2074. * @memberof DataTable#oApi
  2075. */
  2076. function _fnFilterCustom( oSettings )
  2077. {
  2078. var afnFilters = DataTable.ext.afnFiltering;
  2079. for ( var i=0, iLen=afnFilters.length ; i<iLen ; i++ )
  2080. {
  2081. var iCorrector = 0;
  2082. for ( var j=0, jLen=oSettings.aiDisplay.length ; j<jLen ; j++ )
  2083. {
  2084. var iDisIndex = oSettings.aiDisplay[j-iCorrector];
  2085.  
  2086. /* Check if we should use this row based on the filtering function */
  2087. if ( !afnFilters[i]( oSettings, _fnGetRowData( oSettings, iDisIndex, 'filter' ), iDisIndex ) )
  2088. {
  2089. oSettings.aiDisplay.splice( j-iCorrector, 1 );
  2090. iCorrector++;
  2091. }
  2092. }
  2093. }
  2094. }
  2095.  
  2096.  
  2097. /**
  2098. * Filter the table on a per-column basis
  2099. * @param {object} oSettings dataTables settings object
  2100. * @param {string} sInput string to filter on
  2101. * @param {int} iColumn column to filter
  2102. * @param {bool} bRegex treat search string as a regular expression or not
  2103. * @param {bool} bSmart use smart filtering or not
  2104. * @param {bool} bCaseInsensitive Do case insenstive matching or not
  2105. * @memberof DataTable#oApi
  2106. */
  2107. function _fnFilterColumn ( oSettings, sInput, iColumn, bRegex, bSmart, bCaseInsensitive )
  2108. {
  2109. if ( sInput === "" )
  2110. {
  2111. return;
  2112. }
  2113.  
  2114. var iIndexCorrector = 0;
  2115. var rpSearch = _fnFilterCreateSearch( sInput, bRegex, bSmart, bCaseInsensitive );
  2116.  
  2117. for ( var i=oSettings.aiDisplay.length-1 ; i>=0 ; i-- )
  2118. {
  2119. var sData = _fnDataToSearch( _fnGetCellData( oSettings, oSettings.aiDisplay[i], iColumn, 'filter' ),
  2120. oSettings.aoColumns[iColumn].sType );
  2121. if ( ! rpSearch.test( sData ) )
  2122. {
  2123. oSettings.aiDisplay.splice( i, 1 );
  2124. iIndexCorrector++;
  2125. }
  2126. }
  2127. }
  2128.  
  2129.  
  2130. /**
  2131. * Filter the data table based on user input and draw the table
  2132. * @param {object} oSettings dataTables settings object
  2133. * @param {string} sInput string to filter on
  2134. * @param {int} iForce optional - force a research of the master array (1) or not (undefined or 0)
  2135. * @param {bool} bRegex treat as a regular expression or not
  2136. * @param {bool} bSmart perform smart filtering or not
  2137. * @param {bool} bCaseInsensitive Do case insenstive matching or not
  2138. * @memberof DataTable#oApi
  2139. */
  2140. function _fnFilter( oSettings, sInput, iForce, bRegex, bSmart, bCaseInsensitive )
  2141. {
  2142. var i;
  2143. var rpSearch = _fnFilterCreateSearch( sInput, bRegex, bSmart, bCaseInsensitive );
  2144. var oPrevSearch = oSettings.oPreviousSearch;
  2145.  
  2146. /* Check if we are forcing or not - optional parameter */
  2147. if ( !iForce )
  2148. {
  2149. iForce = 0;
  2150. }
  2151.  
  2152. /* Need to take account of custom filtering functions - always filter */
  2153. if ( DataTable.ext.afnFiltering.length !== 0 )
  2154. {
  2155. iForce = 1;
  2156. }
  2157.  
  2158. /*
  2159. * If the input is blank - we want the full data set
  2160. */
  2161. if ( sInput.length <= 0 )
  2162. {
  2163. oSettings.aiDisplay.splice( 0, oSettings.aiDisplay.length);
  2164. oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
  2165. }
  2166. else
  2167. {
  2168. /*
  2169. * We are starting a new search or the new search string is smaller
  2170. * then the old one (i.e. delete). Search from the master array
  2171. */
  2172. if ( oSettings.aiDisplay.length == oSettings.aiDisplayMaster.length ||
  2173. oPrevSearch.sSearch.length > sInput.length || iForce == 1 ||
  2174. sInput.indexOf(oPrevSearch.sSearch) !== 0 )
  2175. {
  2176. /* Nuke the old display array - we are going to rebuild it */
  2177. oSettings.aiDisplay.splice( 0, oSettings.aiDisplay.length);
  2178.  
  2179. /* Force a rebuild of the search array */
  2180. _fnBuildSearchArray( oSettings, 1 );
  2181.  
  2182. /* Search through all records to populate the search array
  2183. * The the oSettings.aiDisplayMaster and asDataSearch arrays have 1 to 1
  2184. * mapping
  2185. */
  2186. for ( i=0 ; i<oSettings.aiDisplayMaster.length ; i++ )
  2187. {
  2188. if ( rpSearch.test(oSettings.asDataSearch[i]) )
  2189. {
  2190. oSettings.aiDisplay.push( oSettings.aiDisplayMaster[i] );
  2191. }
  2192. }
  2193. }
  2194. else
  2195. {
  2196. /* Using old search array - refine it - do it this way for speed
  2197. * Don't have to search the whole master array again
  2198. */
  2199. var iIndexCorrector = 0;
  2200.  
  2201. /* Search the current results */
  2202. for ( i=0 ; i<oSettings.asDataSearch.length ; i++ )
  2203. {
  2204. if ( ! rpSearch.test(oSettings.asDataSearch[i]) )
  2205. {
  2206. oSettings.aiDisplay.splice( i-iIndexCorrector, 1 );
  2207. iIndexCorrector++;
  2208. }
  2209. }
  2210. }
  2211. }
  2212. }
  2213.  
  2214.  
  2215. /**
  2216. * Create an array which can be quickly search through
  2217. * @param {object} oSettings dataTables settings object
  2218. * @param {int} iMaster use the master data array - optional
  2219. * @memberof DataTable#oApi
  2220. */
  2221. function _fnBuildSearchArray ( oSettings, iMaster )
  2222. {
  2223. if ( !oSettings.oFeatures.bServerSide )
  2224. {
  2225. /* Clear out the old data */
  2226. oSettings.asDataSearch.splice( 0, oSettings.asDataSearch.length );
  2227.  
  2228. var aArray = (iMaster && iMaster===1) ?
  2229. oSettings.aiDisplayMaster : oSettings.aiDisplay;
  2230.  
  2231. for ( var i=0, iLen=aArray.length ; i<iLen ; i++ )
  2232. {
  2233. oSettings.asDataSearch[i] = _fnBuildSearchRow( oSettings,
  2234. _fnGetRowData( oSettings, aArray[i], 'filter' ) );
  2235. }
  2236. }
  2237. }
  2238.  
  2239.  
  2240. /**
  2241. * Create a searchable string from a single data row
  2242. * @param {object} oSettings dataTables settings object
  2243. * @param {array} aData Row data array to use for the data to search
  2244. * @memberof DataTable#oApi
  2245. */
  2246. function _fnBuildSearchRow( oSettings, aData )
  2247. {
  2248. var sSearch = '';
  2249. if ( oSettings.__nTmpFilter === undefined )
  2250. {
  2251. oSettings.__nTmpFilter = document.createElement('div');
  2252. }
  2253. var nTmp = oSettings.__nTmpFilter;
  2254.  
  2255. for ( var j=0, jLen=oSettings.aoColumns.length ; j<jLen ; j++ )
  2256. {
  2257. if ( oSettings.aoColumns[j].bSearchable )
  2258. {
  2259. var sData = aData[j];
  2260. sSearch += _fnDataToSearch( sData, oSettings.aoColumns[j].sType )+' ';
  2261. }
  2262. }
  2263.  
  2264. /* If it looks like there is an HTML entity in the string, attempt to decode it */
  2265. if ( sSearch.indexOf('&') !== -1 )
  2266. {
  2267. nTmp.innerHTML = sSearch;
  2268. sSearch = nTmp.textContent ? nTmp.textContent : nTmp.innerText;
  2269.  
  2270. /* IE and Opera appear to put an newline where there is a <br> tag - remove it */
  2271. sSearch = sSearch.replace(/\n/g," ").replace(/\r/g,"");
  2272. }
  2273.  
  2274. return sSearch;
  2275. }
  2276.  
  2277. /**
  2278. * Build a regular expression object suitable for searching a table
  2279. * @param {string} sSearch string to search for
  2280. * @param {bool} bRegex treat as a regular expression or not
  2281. * @param {bool} bSmart perform smart filtering or not
  2282. * @param {bool} bCaseInsensitive Do case insenstive matching or not
  2283. * @returns {RegExp} constructed object
  2284. * @memberof DataTable#oApi
  2285. */
  2286. function _fnFilterCreateSearch( sSearch, bRegex, bSmart, bCaseInsensitive )
  2287. {
  2288. var asSearch, sRegExpString;
  2289.  
  2290. if ( bSmart )
  2291. {
  2292. /* Generate the regular expression to use. Something along the lines of:
  2293. * ^(?=.*?\bone\b)(?=.*?\btwo\b)(?=.*?\bthree\b).*$
  2294. */
  2295. asSearch = bRegex ? sSearch.split( ' ' ) : _fnEscapeRegex( sSearch ).split( ' ' );
  2296. sRegExpString = '^(?=.*?'+asSearch.join( ')(?=.*?' )+').*$';
  2297. return new RegExp( sRegExpString, bCaseInsensitive ? "i" : "" );
  2298. }
  2299. else
  2300. {
  2301. sSearch = bRegex ? sSearch : _fnEscapeRegex( sSearch );
  2302. return new RegExp( sSearch, bCaseInsensitive ? "i" : "" );
  2303. }
  2304. }
  2305.  
  2306.  
  2307. /**
  2308. * Convert raw data into something that the user can search on
  2309. * @param {string} sData data to be modified
  2310. * @param {string} sType data type
  2311. * @returns {string} search string
  2312. * @memberof DataTable#oApi
  2313. */
  2314. function _fnDataToSearch ( sData, sType )
  2315. {
  2316. if ( typeof DataTable.ext.ofnSearch[sType] === "function" )
  2317. {
  2318. return DataTable.ext.ofnSearch[sType]( sData );
  2319. }
  2320. else if ( sData === null )
  2321. {
  2322. return '';
  2323. }
  2324. else if ( sType == "html" )
  2325. {
  2326. return sData.replace(/[\r\n]/g," ").replace( /<.*?>/g, "" );
  2327. }
  2328. else if ( typeof sData === "string" )
  2329. {
  2330. return sData.replace(/[\r\n]/g," ");
  2331. }
  2332. return sData;
  2333. }
  2334.  
  2335.  
  2336. /**
  2337. * scape a string stuch that it can be used in a regular expression
  2338. * @param {string} sVal string to escape
  2339. * @returns {string} escaped string
  2340. * @memberof DataTable#oApi
  2341. */
  2342. function _fnEscapeRegex ( sVal )
  2343. {
  2344. var acEscape = [ '/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\', '$', '^' ];
  2345. var reReplace = new RegExp( '(\\' + acEscape.join('|\\') + ')', 'g' );
  2346. return sVal.replace(reReplace, '\\$1');
  2347. }
  2348.  
  2349.  
  2350.  
  2351. /**
  2352. * Generate the node required for the info display
  2353. * @param {object} oSettings dataTables settings object
  2354. * @returns {node} Information element
  2355. * @memberof DataTable#oApi
  2356. */
  2357. function _fnFeatureHtmlInfo ( oSettings )
  2358. {
  2359. var nInfo = document.createElement( 'div' );
  2360. nInfo.className = oSettings.oClasses.sInfo;
  2361.  
  2362. /* Actions that are to be taken once only for this feature */
  2363. if ( !oSettings.aanFeatures.i )
  2364. {
  2365. /* Add draw callback */
  2366. oSettings.aoDrawCallback.push( {
  2367. "fn": _fnUpdateInfo,
  2368. "sName": "information"
  2369. } );
  2370.  
  2371. /* Add id */
  2372. nInfo.id = oSettings.sTableId+'_info';
  2373. }
  2374. oSettings.nTable.setAttribute( 'aria-describedby', oSettings.sTableId+'_info' );
  2375.  
  2376. return nInfo;
  2377. }
  2378.  
  2379.  
  2380. /**
  2381. * Update the information elements in the display
  2382. * @param {object} oSettings dataTables settings object
  2383. * @memberof DataTable#oApi
  2384. */
  2385. function _fnUpdateInfo ( oSettings )
  2386. {
  2387. /* Show information about the table */
  2388. if ( !oSettings.oFeatures.bInfo || oSettings.aanFeatures.i.length === 0 )
  2389. {
  2390. return;
  2391. }
  2392.  
  2393. var
  2394. oLang = oSettings.oLanguage,
  2395. iStart = oSettings._iDisplayStart+1,
  2396. iEnd = oSettings.fnDisplayEnd(),
  2397. iMax = oSettings.fnRecordsTotal(),
  2398. iTotal = oSettings.fnRecordsDisplay(),
  2399. sOut;
  2400.  
  2401. if ( iTotal === 0 && iTotal == iMax )
  2402. {
  2403. /* Empty record set */
  2404. sOut = oLang.sInfoEmpty;
  2405. }
  2406. else if ( iTotal === 0 )
  2407. {
  2408. /* Empty record set after filtering */
  2409. sOut = oLang.sInfoEmpty +' '+ oLang.sInfoFiltered;
  2410. }
  2411. else if ( iTotal == iMax )
  2412. {
  2413. /* Normal record set */
  2414. sOut = oLang.sInfo;
  2415. }
  2416. else
  2417. {
  2418. /* Record set after filtering */
  2419. sOut = oLang.sInfo +' '+ oLang.sInfoFiltered;
  2420. }
  2421.  
  2422. // Convert the macros
  2423. sOut += oLang.sInfoPostFix;
  2424. sOut = _fnInfoMacros( oSettings, sOut );
  2425.  
  2426. if ( oLang.fnInfoCallback !== null )
  2427. {
  2428. sOut = oLang.fnInfoCallback.call( oSettings.oInstance,
  2429. oSettings, iStart, iEnd, iMax, iTotal, sOut );
  2430. }
  2431.  
  2432. var n = oSettings.aanFeatures.i;
  2433. for ( var i=0, iLen=n.length ; i<iLen ; i++ )
  2434. {
  2435. $(n[i]).html( sOut );
  2436. }
  2437. }
  2438.  
  2439.  
  2440. function _fnInfoMacros ( oSettings, str )
  2441. {
  2442. var
  2443. iStart = oSettings._iDisplayStart+1,
  2444. sStart = oSettings.fnFormatNumber( iStart ),
  2445. iEnd = oSettings.fnDisplayEnd(),
  2446. sEnd = oSettings.fnFormatNumber( iEnd ),
  2447. iTotal = oSettings.fnRecordsDisplay(),
  2448. sTotal = oSettings.fnFormatNumber( iTotal ),
  2449. iMax = oSettings.fnRecordsTotal(),
  2450. sMax = oSettings.fnFormatNumber( iMax );
  2451.  
  2452. // When infinite scrolling, we are always starting at 1. _iDisplayStart is used only
  2453. // internally
  2454. if ( oSettings.oScroll.bInfinite )
  2455. {
  2456. sStart = oSettings.fnFormatNumber( 1 );
  2457. }
  2458.  
  2459. return str.
  2460. replace('_START_', sStart).
  2461. replace('_END_', sEnd).
  2462. replace('_TOTAL_', sTotal).
  2463. replace('_MAX_', sMax);
  2464. }
  2465.  
  2466.  
  2467.  
  2468. /**
  2469. * Draw the table for the first time, adding all required features
  2470. * @param {object} oSettings dataTables settings object
  2471. * @memberof DataTable#oApi
  2472. */
  2473. function _fnInitialise ( oSettings )
  2474. {
  2475. var i, iLen, iAjaxStart=oSettings.iInitDisplayStart;
  2476.  
  2477. /* Ensure that the table data is fully initialised */
  2478. if ( oSettings.bInitialised === false )
  2479. {
  2480. setTimeout( function(){ _fnInitialise( oSettings ); }, 200 );
  2481. return;
  2482. }
  2483.  
  2484. /* Show the display HTML options */
  2485. _fnAddOptionsHtml( oSettings );
  2486.  
  2487. /* Build and draw the header / footer for the table */
  2488. _fnBuildHead( oSettings );
  2489. _fnDrawHead( oSettings, oSettings.aoHeader );
  2490. if ( oSettings.nTFoot )
  2491. {
  2492. _fnDrawHead( oSettings, oSettings.aoFooter );
  2493. }
  2494.  
  2495. /* Okay to show that something is going on now */
  2496. _fnProcessingDisplay( oSettings, true );
  2497.  
  2498. /* Calculate sizes for columns */
  2499. if ( oSettings.oFeatures.bAutoWidth )
  2500. {
  2501. _fnCalculateColumnWidths( oSettings );
  2502. }
  2503.  
  2504. for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
  2505. {
  2506. if ( oSettings.aoColumns[i].sWidth !== null )
  2507. {
  2508. oSettings.aoColumns[i].nTh.style.width = _fnStringToCss( oSettings.aoColumns[i].sWidth );
  2509. }
  2510. }
  2511.  
  2512. /* If there is default sorting required - let's do it. The sort function will do the
  2513. * drawing for us. Otherwise we draw the table regardless of the Ajax source - this allows
  2514. * the table to look initialised for Ajax sourcing data (show 'loading' message possibly)
  2515. */
  2516. if ( oSettings.oFeatures.bSort )
  2517. {
  2518. _fnSort( oSettings );
  2519. }
  2520. else if ( oSettings.oFeatures.bFilter )
  2521. {
  2522. _fnFilterComplete( oSettings, oSettings.oPreviousSearch );
  2523. }
  2524. else
  2525. {
  2526. oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
  2527. _fnCalculateEnd( oSettings );
  2528. _fnDraw( oSettings );
  2529. }
  2530.  
  2531. /* if there is an ajax source load the data */
  2532. if ( oSettings.sAjaxSource !== null && !oSettings.oFeatures.bServerSide )
  2533. {
  2534. var aoData = [];
  2535. _fnServerParams( oSettings, aoData );
  2536. oSettings.fnServerData.call( oSettings.oInstance, oSettings.sAjaxSource, aoData, function(json) {
  2537. var aData = (oSettings.sAjaxDataProp !== "") ?
  2538. _fnGetObjectDataFn( oSettings.sAjaxDataProp )(json) : json;
  2539.  
  2540. /* Got the data - add it to the table */
  2541. for ( i=0 ; i<aData.length ; i++ )
  2542. {
  2543. _fnAddData( oSettings, aData[i] );
  2544. }
  2545.  
  2546. /* Reset the init display for cookie saving. We've already done a filter, and
  2547. * therefore cleared it before. So we need to make it appear 'fresh'
  2548. */
  2549. oSettings.iInitDisplayStart = iAjaxStart;
  2550.  
  2551. if ( oSettings.oFeatures.bSort )
  2552. {
  2553. _fnSort( oSettings );
  2554. }
  2555. else
  2556. {
  2557. oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
  2558. _fnCalculateEnd( oSettings );
  2559. _fnDraw( oSettings );
  2560. }
  2561.  
  2562. _fnProcessingDisplay( oSettings, false );
  2563. _fnInitComplete( oSettings, json );
  2564. }, oSettings );
  2565. return;
  2566. }
  2567.  
  2568. /* Server-side processing initialisation complete is done at the end of _fnDraw */
  2569. if ( !oSettings.oFeatures.bServerSide )
  2570. {
  2571. _fnProcessingDisplay( oSettings, false );
  2572. _fnInitComplete( oSettings );
  2573. }
  2574. }
  2575.  
  2576.  
  2577. /**
  2578. * Draw the table for the first time, adding all required features
  2579. * @param {object} oSettings dataTables settings object
  2580. * @param {object} [json] JSON from the server that completed the table, if using Ajax source
  2581. * with client-side processing (optional)
  2582. * @memberof DataTable#oApi
  2583. */
  2584. function _fnInitComplete ( oSettings, json )
  2585. {
  2586. oSettings._bInitComplete = true;
  2587. _fnCallbackFire( oSettings, 'aoInitComplete', 'init', [oSettings, json] );
  2588. }
  2589.  
  2590.  
  2591. /**
  2592. * Language compatibility - when certain options are given, and others aren't, we
  2593. * need to duplicate the values over, in order to provide backwards compatibility
  2594. * with older language files.
  2595. * @param {object} oSettings dataTables settings object
  2596. * @memberof DataTable#oApi
  2597. */
  2598. function _fnLanguageCompat( oLanguage )
  2599. {
  2600. var oDefaults = DataTable.defaults.oLanguage;
  2601.  
  2602. /* Backwards compatibility - if there is no sEmptyTable given, then use the same as
  2603. * sZeroRecords - assuming that is given.
  2604. */
  2605. if ( !oLanguage.sEmptyTable && oLanguage.sZeroRecords &&
  2606. oDefaults.sEmptyTable === "No data available in table" )
  2607. {
  2608. _fnMap( oLanguage, oLanguage, 'sZeroRecords', 'sEmptyTable' );
  2609. }
  2610.  
  2611. /* Likewise with loading records */
  2612. if ( !oLanguage.sLoadingRecords && oLanguage.sZeroRecords &&
  2613. oDefaults.sLoadingRecords === "Loading..." )
  2614. {
  2615. _fnMap( oLanguage, oLanguage, 'sZeroRecords', 'sLoadingRecords' );
  2616. }
  2617. }
  2618.  
  2619.  
  2620.  
  2621. /**
  2622. * Generate the node required for user display length changing
  2623. * @param {object} oSettings dataTables settings object
  2624. * @returns {node} Display length feature node
  2625. * @memberof DataTable#oApi
  2626. */
  2627. function _fnFeatureHtmlLength ( oSettings )
  2628. {
  2629. if ( oSettings.oScroll.bInfinite )
  2630. {
  2631. return null;
  2632. }
  2633.  
  2634. /* This can be overruled by not using the _MENU_ var/macro in the language variable */
  2635. var sName = 'name="'+oSettings.sTableId+'_length"';
  2636. var sStdMenu = '<select size="1" '+sName+'>';
  2637. var i, iLen;
  2638. var aLengthMenu = oSettings.aLengthMenu;
  2639.  
  2640. if ( aLengthMenu.length == 2 && typeof aLengthMenu[0] === 'object' &&
  2641. typeof aLengthMenu[1] === 'object' )
  2642. {
  2643. for ( i=0, iLen=aLengthMenu[0].length ; i<iLen ; i++ )
  2644. {
  2645. sStdMenu += '<option value="'+aLengthMenu[0][i]+'">'+aLengthMenu[1][i]+'</option>';
  2646. }
  2647. }
  2648. else
  2649. {
  2650. for ( i=0, iLen=aLengthMenu.length ; i<iLen ; i++ )
  2651. {
  2652. sStdMenu += '<option value="'+aLengthMenu[i]+'">'+aLengthMenu[i]+'</option>';
  2653. }
  2654. }
  2655. sStdMenu += '</select>';
  2656.  
  2657. var nLength = document.createElement( 'div' );
  2658. if ( !oSettings.aanFeatures.l )
  2659. {
  2660. nLength.id = oSettings.sTableId+'_length';
  2661. }
  2662. nLength.className = oSettings.oClasses.sLength;
  2663. nLength.innerHTML = '<label>'+oSettings.oLanguage.sLengthMenu.replace( '_MENU_', sStdMenu )+'</label>';
  2664.  
  2665. /*
  2666. * Set the length to the current display length - thanks to Andrea Pavlovic for this fix,
  2667. * and Stefan Skopnik for fixing the fix!
  2668. */
  2669. $('select option[value="'+oSettings._iDisplayLength+'"]', nLength).attr("selected", true);
  2670.  
  2671. $('select', nLength).bind( 'change.DT', function(e) {
  2672. var iVal = $(this).val();
  2673.  
  2674. /* Update all other length options for the new display */
  2675. var n = oSettings.aanFeatures.l;
  2676. for ( i=0, iLen=n.length ; i<iLen ; i++ )
  2677. {
  2678. if ( n[i] != this.parentNode )
  2679. {
  2680. $('select', n[i]).val( iVal );
  2681. }
  2682. }
  2683.  
  2684. /* Redraw the table */
  2685. oSettings._iDisplayLength = parseInt(iVal, 10);
  2686. _fnCalculateEnd( oSettings );
  2687.  
  2688. /* If we have space to show extra rows (backing up from the end point - then do so */
  2689. if ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() )
  2690. {
  2691. oSettings._iDisplayStart = oSettings.fnDisplayEnd() - oSettings._iDisplayLength;
  2692. if ( oSettings._iDisplayStart < 0 )
  2693. {
  2694. oSettings._iDisplayStart = 0;
  2695. }
  2696. }
  2697.  
  2698. if ( oSettings._iDisplayLength == -1 )
  2699. {
  2700. oSettings._iDisplayStart = 0;
  2701. }
  2702.  
  2703. _fnDraw( oSettings );
  2704. } );
  2705.  
  2706.  
  2707. $('select', nLength).attr('aria-controls', oSettings.sTableId);
  2708.  
  2709. return nLength;
  2710. }
  2711.  
  2712.  
  2713. /**
  2714. * Rcalculate the end point based on the start point
  2715. * @param {object} oSettings dataTables settings object
  2716. * @memberof DataTable#oApi
  2717. */
  2718. function _fnCalculateEnd( oSettings )
  2719. {
  2720. if ( oSettings.oFeatures.bPaginate === false )
  2721. {
  2722. oSettings._iDisplayEnd = oSettings.aiDisplay.length;
  2723. }
  2724. else
  2725. {
  2726. /* Set the end point of the display - based on how many elements there are
  2727. * still to display
  2728. */
  2729. if ( oSettings._iDisplayStart + oSettings._iDisplayLength > oSettings.aiDisplay.length ||
  2730. oSettings._iDisplayLength == -1 )
  2731. {
  2732. oSettings._iDisplayEnd = oSettings.aiDisplay.length;
  2733. }
  2734. else
  2735. {
  2736. oSettings._iDisplayEnd = oSettings._iDisplayStart + oSettings._iDisplayLength;
  2737. }
  2738. }
  2739. }
  2740.  
  2741.  
  2742.  
  2743. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2744. * Note that most of the paging logic is done in
  2745. * DataTable.ext.oPagination
  2746. */
  2747.  
  2748. /**
  2749. * Generate the node required for default pagination
  2750. * @param {object} oSettings dataTables settings object
  2751. * @returns {node} Pagination feature node
  2752. * @memberof DataTable#oApi
  2753. */
  2754. function _fnFeatureHtmlPaginate ( oSettings )
  2755. {
  2756. if ( oSettings.oScroll.bInfinite )
  2757. {
  2758. return null;
  2759. }
  2760.  
  2761. var nPaginate = document.createElement( 'div' );
  2762. nPaginate.className = oSettings.oClasses.sPaging+oSettings.sPaginationType;
  2763.  
  2764. DataTable.ext.oPagination[ oSettings.sPaginationType ].fnInit( oSettings, nPaginate,
  2765. function( oSettings ) {
  2766. _fnCalculateEnd( oSettings );
  2767. _fnDraw( oSettings );
  2768. }
  2769. );
  2770.  
  2771. /* Add a draw callback for the pagination on first instance, to update the paging display */
  2772. if ( !oSettings.aanFeatures.p )
  2773. {
  2774. oSettings.aoDrawCallback.push( {
  2775. "fn": function( oSettings ) {
  2776. DataTable.ext.oPagination[ oSettings.sPaginationType ].fnUpdate( oSettings, function( oSettings ) {
  2777. _fnCalculateEnd( oSettings );
  2778. _fnDraw( oSettings );
  2779. } );
  2780. },
  2781. "sName": "pagination"
  2782. } );
  2783. }
  2784. return nPaginate;
  2785. }
  2786.  
  2787.  
  2788. /**
  2789. * Alter the display settings to change the page
  2790. * @param {object} oSettings dataTables settings object
  2791. * @param {string|int} mAction Paging action to take: "first", "previous", "next" or "last"
  2792. * or page number to jump to (integer)
  2793. * @returns {bool} true page has changed, false - no change (no effect) eg 'first' on page 1
  2794. * @memberof DataTable#oApi
  2795. */
  2796. function _fnPageChange ( oSettings, mAction )
  2797. {
  2798. var iOldStart = oSettings._iDisplayStart;
  2799.  
  2800. if ( typeof mAction === "number" )
  2801. {
  2802. oSettings._iDisplayStart = mAction * oSettings._iDisplayLength;
  2803. if ( oSettings._iDisplayStart > oSettings.fnRecordsDisplay() )
  2804. {
  2805. oSettings._iDisplayStart = 0;
  2806. }
  2807. }
  2808. else if ( mAction == "first" )
  2809. {
  2810. oSettings._iDisplayStart = 0;
  2811. }
  2812. else if ( mAction == "previous" )
  2813. {
  2814. oSettings._iDisplayStart = oSettings._iDisplayLength>=0 ?
  2815. oSettings._iDisplayStart - oSettings._iDisplayLength :
  2816. 0;
  2817.  
  2818. /* Correct for underrun */
  2819. if ( oSettings._iDisplayStart < 0 )
  2820. {
  2821. oSettings._iDisplayStart = 0;
  2822. }
  2823. }
  2824. else if ( mAction == "next" )
  2825. {
  2826. if ( oSettings._iDisplayLength >= 0 )
  2827. {
  2828. /* Make sure we are not over running the display array */
  2829. if ( oSettings._iDisplayStart + oSettings._iDisplayLength < oSettings.fnRecordsDisplay() )
  2830. {
  2831. oSettings._iDisplayStart += oSettings._iDisplayLength;
  2832. }
  2833. }
  2834. else
  2835. {
  2836. oSettings._iDisplayStart = 0;
  2837. }
  2838. }
  2839. else if ( mAction == "last" )
  2840. {
  2841. if ( oSettings._iDisplayLength >= 0 )
  2842. {
  2843. var iPages = parseInt( (oSettings.fnRecordsDisplay()-1) / oSettings._iDisplayLength, 10 ) + 1;
  2844. oSettings._iDisplayStart = (iPages-1) * oSettings._iDisplayLength;
  2845. }
  2846. else
  2847. {
  2848. oSettings._iDisplayStart = 0;
  2849. }
  2850. }
  2851. else
  2852. {
  2853. _fnLog( oSettings, 0, "Unknown paging action: "+mAction );
  2854. }
  2855. $(oSettings.oInstance).trigger('page', oSettings);
  2856.  
  2857. return iOldStart != oSettings._iDisplayStart;
  2858. }
  2859.  
  2860.  
  2861.  
  2862. /**
  2863. * Generate the node required for the processing node
  2864. * @param {object} oSettings dataTables settings object
  2865. * @returns {node} Processing element
  2866. * @memberof DataTable#oApi
  2867. */
  2868. function _fnFeatureHtmlProcessing ( oSettings )
  2869. {
  2870. var nProcessing = document.createElement( 'div' );
  2871.  
  2872. if ( !oSettings.aanFeatures.r )
  2873. {
  2874. nProcessing.id = oSettings.sTableId+'_processing';
  2875. }
  2876. nProcessing.innerHTML = oSettings.oLanguage.sProcessing;
  2877. nProcessing.className = oSettings.oClasses.sProcessing;
  2878. oSettings.nTable.parentNode.insertBefore( nProcessing, oSettings.nTable );
  2879.  
  2880. return nProcessing;
  2881. }
  2882.  
  2883.  
  2884. /**
  2885. * Display or hide the processing indicator
  2886. * @param {object} oSettings dataTables settings object
  2887. * @param {bool} bShow Show the processing indicator (true) or not (false)
  2888. * @memberof DataTable#oApi
  2889. */
  2890. function _fnProcessingDisplay ( oSettings, bShow )
  2891. {
  2892. if ( oSettings.oFeatures.bProcessing )
  2893. {
  2894. var an = oSettings.aanFeatures.r;
  2895. for ( var i=0, iLen=an.length ; i<iLen ; i++ )
  2896. {
  2897. an[i].style.visibility = bShow ? "visible" : "hidden";
  2898. }
  2899. }
  2900.  
  2901. $(oSettings.oInstance).trigger('processing', [oSettings, bShow]);
  2902. }
  2903.  
  2904.  
  2905.  
  2906. /**
  2907. * Add any control elements for the table - specifically scrolling
  2908. * @param {object} oSettings dataTables settings object
  2909. * @returns {node} Node to add to the DOM
  2910. * @memberof DataTable#oApi
  2911. */
  2912. function _fnFeatureHtmlTable ( oSettings )
  2913. {
  2914. /* Check if scrolling is enabled or not - if not then leave the DOM unaltered */
  2915. if ( oSettings.oScroll.sX === "" && oSettings.oScroll.sY === "" )
  2916. {
  2917. return oSettings.nTable;
  2918. }
  2919.  
  2920. /*
  2921. * The HTML structure that we want to generate in this function is:
  2922. * div - nScroller
  2923. * div - nScrollHead
  2924. * div - nScrollHeadInner
  2925. * table - nScrollHeadTable
  2926. * thead - nThead
  2927. * div - nScrollBody
  2928. * table - oSettings.nTable
  2929. * thead - nTheadSize
  2930. * tbody - nTbody
  2931. * div - nScrollFoot
  2932. * div - nScrollFootInner
  2933. * table - nScrollFootTable
  2934. * tfoot - nTfoot
  2935. */
  2936. var
  2937. nScroller = document.createElement('div'),
  2938. nScrollHead = document.createElement('div'),
  2939. nScrollHeadInner = document.createElement('div'),
  2940. nScrollBody = document.createElement('div'),
  2941. nScrollFoot = document.createElement('div'),
  2942. nScrollFootInner = document.createElement('div'),
  2943. nScrollHeadTable = oSettings.nTable.cloneNode(false),
  2944. nScrollFootTable = oSettings.nTable.cloneNode(false),
  2945. nThead = oSettings.nTable.getElementsByTagName('thead')[0],
  2946. nTfoot = oSettings.nTable.getElementsByTagName('tfoot').length === 0 ? null :
  2947. oSettings.nTable.getElementsByTagName('tfoot')[0],
  2948. oClasses = oSettings.oClasses;
  2949.  
  2950. nScrollHead.appendChild( nScrollHeadInner );
  2951. nScrollFoot.appendChild( nScrollFootInner );
  2952. nScrollBody.appendChild( oSettings.nTable );
  2953. nScroller.appendChild( nScrollHead );
  2954. nScroller.appendChild( nScrollBody );
  2955. nScrollHeadInner.appendChild( nScrollHeadTable );
  2956. nScrollHeadTable.appendChild( nThead );
  2957. if ( nTfoot !== null )
  2958. {
  2959. nScroller.appendChild( nScrollFoot );
  2960. nScrollFootInner.appendChild( nScrollFootTable );
  2961. nScrollFootTable.appendChild( nTfoot );
  2962. }
  2963.  
  2964. nScroller.className = oClasses.sScrollWrapper;
  2965. nScrollHead.className = oClasses.sScrollHead;
  2966. nScrollHeadInner.className = oClasses.sScrollHeadInner;
  2967. nScrollBody.className = oClasses.sScrollBody;
  2968. nScrollFoot.className = oClasses.sScrollFoot;
  2969. nScrollFootInner.className = oClasses.sScrollFootInner;
  2970.  
  2971. if ( oSettings.oScroll.bAutoCss )
  2972. {
  2973. nScrollHead.style.overflow = "hidden";
  2974. nScrollHead.style.position = "relative";
  2975. nScrollFoot.style.overflow = "hidden";
  2976. nScrollBody.style.overflow = "auto";
  2977. }
  2978.  
  2979. nScrollHead.style.border = "0";
  2980. nScrollHead.style.width = "100%";
  2981. nScrollFoot.style.border = "0";
  2982. nScrollHeadInner.style.width = oSettings.oScroll.sXInner !== "" ?
  2983. oSettings.oScroll.sXInner : "100%"; /* will be overwritten */
  2984.  
  2985. /* Modify attributes to respect the clones */
  2986. nScrollHeadTable.removeAttribute('id');
  2987. nScrollHeadTable.style.marginLeft = "0";
  2988. oSettings.nTable.style.marginLeft = "0";
  2989. if ( nTfoot !== null )
  2990. {
  2991. nScrollFootTable.removeAttribute('id');
  2992. nScrollFootTable.style.marginLeft = "0";
  2993. }
  2994.  
  2995. /* Move caption elements from the body to the header, footer or leave where it is
  2996. * depending on the configuration. Note that the DTD says there can be only one caption */
  2997. var nCaption = $(oSettings.nTable).children('caption');
  2998. if ( nCaption.length > 0 )
  2999. {
  3000. nCaption = nCaption[0];
  3001. if ( nCaption._captionSide === "top" )
  3002. {
  3003. nScrollHeadTable.appendChild( nCaption );
  3004. }
  3005. else if ( nCaption._captionSide === "bottom" && nTfoot )
  3006. {
  3007. nScrollFootTable.appendChild( nCaption );
  3008. }
  3009. }
  3010.  
  3011. /*
  3012. * Sizing
  3013. */
  3014. /* When xscrolling add the width and a scroller to move the header with the body */
  3015. if ( oSettings.oScroll.sX !== "" )
  3016. {
  3017. nScrollHead.style.width = _fnStringToCss( oSettings.oScroll.sX );
  3018. nScrollBody.style.width = _fnStringToCss( oSettings.oScroll.sX );
  3019.  
  3020. if ( nTfoot !== null )
  3021. {
  3022. nScrollFoot.style.width = _fnStringToCss( oSettings.oScroll.sX );
  3023. }
  3024.  
  3025. /* When the body is scrolled, then we also want to scroll the headers */
  3026. $(nScrollBody).scroll( function (e) {
  3027. nScrollHead.scrollLeft = this.scrollLeft;
  3028.  
  3029. if ( nTfoot !== null )
  3030. {
  3031. nScrollFoot.scrollLeft = this.scrollLeft;
  3032. }
  3033. } );
  3034. }
  3035.  
  3036. /* When yscrolling, add the height */
  3037. if ( oSettings.oScroll.sY !== "" )
  3038. {
  3039. nScrollBody.style.height = _fnStringToCss( oSettings.oScroll.sY );
  3040. }
  3041.  
  3042. /* Redraw - align columns across the tables */
  3043. oSettings.aoDrawCallback.push( {
  3044. "fn": _fnScrollDraw,
  3045. "sName": "scrolling"
  3046. } );
  3047.  
  3048. /* Infinite scrolling event handlers */
  3049. if ( oSettings.oScroll.bInfinite )
  3050. {
  3051. $(nScrollBody).scroll( function() {
  3052. /* Use a blocker to stop scrolling from loading more data while other data is still loading */
  3053. if ( !oSettings.bDrawing && $(this).scrollTop() !== 0 )
  3054. {
  3055. /* Check if we should load the next data set */
  3056. if ( $(this).scrollTop() + $(this).height() >
  3057. $(oSettings.nTable).height() - oSettings.oScroll.iLoadGap )
  3058. {
  3059. /* Only do the redraw if we have to - we might be at the end of the data */
  3060. if ( oSettings.fnDisplayEnd() < oSettings.fnRecordsDisplay() )
  3061. {
  3062. _fnPageChange( oSettings, 'next' );
  3063. _fnCalculateEnd( oSettings );
  3064. _fnDraw( oSettings );
  3065. }
  3066. }
  3067. }
  3068. } );
  3069. }
  3070.  
  3071. oSettings.nScrollHead = nScrollHead;
  3072. oSettings.nScrollFoot = nScrollFoot;
  3073.  
  3074. return nScroller;
  3075. }
  3076.  
  3077.  
  3078. /**
  3079. * Update the various tables for resizing. It's a bit of a pig this function, but
  3080. * basically the idea to:
  3081. * 1. Re-create the table inside the scrolling div
  3082. * 2. Take live measurements from the DOM
  3083. * 3. Apply the measurements
  3084. * 4. Clean up
  3085. * @param {object} o dataTables settings object
  3086. * @returns {node} Node to add to the DOM
  3087. * @memberof DataTable#oApi
  3088. */
  3089. function _fnScrollDraw ( o )
  3090. {
  3091. var
  3092. nScrollHeadInner = o.nScrollHead.getElementsByTagName('div')[0],
  3093. nScrollHeadTable = nScrollHeadInner.getElementsByTagName('table')[0],
  3094. nScrollBody = o.nTable.parentNode,
  3095. i, iLen, j, jLen, anHeadToSize, anHeadSizers, anFootSizers, anFootToSize, oStyle, iVis,
  3096. nTheadSize, nTfootSize,
  3097. iWidth, aApplied=[], iSanityWidth,
  3098. nScrollFootInner = (o.nTFoot !== null) ? o.nScrollFoot.getElementsByTagName('div')[0] : null,
  3099. nScrollFootTable = (o.nTFoot !== null) ? nScrollFootInner.getElementsByTagName('table')[0] : null,
  3100. ie67 = $.browser.msie && $.browser.version <= 7;
  3101.  
  3102. /*
  3103. * 1. Re-create the table inside the scrolling div
  3104. */
  3105.  
  3106. /* Remove the old minimised thead and tfoot elements in the inner table */
  3107. $(o.nTable).children('thead, tfoot').remove();
  3108.  
  3109. /* Clone the current header and footer elements and then place it into the inner table */
  3110. nTheadSize = $(o.nTHead).clone()[0];
  3111. o.nTable.insertBefore( nTheadSize, o.nTable.childNodes[0] );
  3112.  
  3113. if ( o.nTFoot !== null )
  3114. {
  3115. nTfootSize = $(o.nTFoot).clone()[0];
  3116. o.nTable.insertBefore( nTfootSize, o.nTable.childNodes[1] );
  3117. }
  3118.  
  3119. /*
  3120. * 2. Take live measurements from the DOM - do not alter the DOM itself!
  3121. */
  3122.  
  3123. /* Remove old sizing and apply the calculated column widths
  3124. * Get the unique column headers in the newly created (cloned) header. We want to apply the
  3125. * calclated sizes to this header
  3126. */
  3127. if ( o.oScroll.sX === "" )
  3128. {
  3129. nScrollBody.style.width = '100%';
  3130. nScrollHeadInner.parentNode.style.width = '100%';
  3131. }
  3132.  
  3133. var nThs = _fnGetUniqueThs( o, nTheadSize );
  3134. for ( i=0, iLen=nThs.length ; i<iLen ; i++ )
  3135. {
  3136. iVis = _fnVisibleToColumnIndex( o, i );
  3137. nThs[i].style.width = o.aoColumns[iVis].sWidth;
  3138. }
  3139.  
  3140. if ( o.nTFoot !== null )
  3141. {
  3142. _fnApplyToChildren( function(n) {
  3143. n.style.width = "";
  3144. }, nTfootSize.getElementsByTagName('tr') );
  3145. }
  3146.  
  3147. // If scroll collapse is enabled, when we put the headers back into the body for sizing, we
  3148. // will end up forcing the scrollbar to appear, making our measurements wrong for when we
  3149. // then hide it (end of this function), so add the header height to the body scroller.
  3150. if ( o.oScroll.bCollapse && o.oScroll.sY !== "" )
  3151. {
  3152. nScrollBody.style.height = (nScrollBody.offsetHeight + o.nTHead.offsetHeight)+"px";
  3153. }
  3154.  
  3155. /* Size the table as a whole */
  3156. iSanityWidth = $(o.nTable).outerWidth();
  3157. if ( o.oScroll.sX === "" )
  3158. {
  3159. /* No x scrolling */
  3160. o.nTable.style.width = "100%";
  3161.  
  3162. /* I know this is rubbish - but IE7 will make the width of the table when 100% include
  3163. * the scrollbar - which is shouldn't. When there is a scrollbar we need to take this
  3164. * into account.
  3165. */
  3166. if ( ie67 && ($('tbody', nScrollBody).height() > nScrollBody.offsetHeight ||
  3167. $(nScrollBody).css('overflow-y') == "scroll") )
  3168. {
  3169. o.nTable.style.width = _fnStringToCss( $(o.nTable).outerWidth() - o.oScroll.iBarWidth);
  3170. }
  3171. }
  3172. else
  3173. {
  3174. if ( o.oScroll.sXInner !== "" )
  3175. {
  3176. /* x scroll inner has been given - use it */
  3177. o.nTable.style.width = _fnStringToCss(o.oScroll.sXInner);
  3178. }
  3179. else if ( iSanityWidth == $(nScrollBody).width() &&
  3180. $(nScrollBody).height() < $(o.nTable).height() )
  3181. {
  3182. /* There is y-scrolling - try to take account of the y scroll bar */
  3183. o.nTable.style.width = _fnStringToCss( iSanityWidth-o.oScroll.iBarWidth );
  3184. if ( $(o.nTable).outerWidth() > iSanityWidth-o.oScroll.iBarWidth )
  3185. {
  3186. /* Not possible to take account of it */
  3187. o.nTable.style.width = _fnStringToCss( iSanityWidth );
  3188. }
  3189. }
  3190. else
  3191. {
  3192. /* All else fails */
  3193. o.nTable.style.width = _fnStringToCss( iSanityWidth );
  3194. }
  3195. }
  3196.  
  3197. /* Recalculate the sanity width - now that we've applied the required width, before it was
  3198. * a temporary variable. This is required because the column width calculation is done
  3199. * before this table DOM is created.
  3200. */
  3201. iSanityWidth = $(o.nTable).outerWidth();
  3202.  
  3203. /* We want the hidden header to have zero height, so remove padding and borders. Then
  3204. * set the width based on the real headers
  3205. */
  3206. anHeadToSize = o.nTHead.getElementsByTagName('tr');
  3207. anHeadSizers = nTheadSize.getElementsByTagName('tr');
  3208.  
  3209. _fnApplyToChildren( function(nSizer, nToSize) {
  3210. oStyle = nSizer.style;
  3211. oStyle.paddingTop = "0";
  3212. oStyle.paddingBottom = "0";
  3213. oStyle.borderTopWidth = "0";
  3214. oStyle.borderBottomWidth = "0";
  3215. oStyle.height = 0;
  3216.  
  3217. iWidth = $(nSizer).width();
  3218. nToSize.style.width = _fnStringToCss( iWidth );
  3219. aApplied.push( iWidth );
  3220. }, anHeadSizers, anHeadToSize );
  3221. $(anHeadSizers).height(0);
  3222.  
  3223. if ( o.nTFoot !== null )
  3224. {
  3225. /* Clone the current footer and then place it into the body table as a "hidden header" */
  3226. anFootSizers = nTfootSize.getElementsByTagName('tr');
  3227. anFootToSize = o.nTFoot.getElementsByTagName('tr');
  3228.  
  3229. _fnApplyToChildren( function(nSizer, nToSize) {
  3230. oStyle = nSizer.style;
  3231. oStyle.paddingTop = "0";
  3232. oStyle.paddingBottom = "0";
  3233. oStyle.borderTopWidth = "0";
  3234. oStyle.borderBottomWidth = "0";
  3235. oStyle.height = 0;
  3236.  
  3237. iWidth = $(nSizer).width();
  3238. nToSize.style.width = _fnStringToCss( iWidth );
  3239. aApplied.push( iWidth );
  3240. }, anFootSizers, anFootToSize );
  3241. $(anFootSizers).height(0);
  3242. }
  3243.  
  3244. /*
  3245. * 3. Apply the measurements
  3246. */
  3247.  
  3248. /* "Hide" the header and footer that we used for the sizing. We want to also fix their width
  3249. * to what they currently are
  3250. */
  3251. _fnApplyToChildren( function(nSizer) {
  3252. nSizer.innerHTML = "";
  3253. nSizer.style.width = _fnStringToCss( aApplied.shift() );
  3254. }, anHeadSizers );
  3255.  
  3256. if ( o.nTFoot !== null )
  3257. {
  3258. _fnApplyToChildren( function(nSizer) {
  3259. nSizer.innerHTML = "";
  3260. nSizer.style.width = _fnStringToCss( aApplied.shift() );
  3261. }, anFootSizers );
  3262. }
  3263.  
  3264. /* Sanity check that the table is of a sensible width. If not then we are going to get
  3265. * misalignment - try to prevent this by not allowing the table to shrink below its min width
  3266. */
  3267. if ( $(o.nTable).outerWidth() < iSanityWidth )
  3268. {
  3269. /* The min width depends upon if we have a vertical scrollbar visible or not */
  3270. var iCorrection = ((nScrollBody.scrollHeight > nScrollBody.offsetHeight ||
  3271. $(nScrollBody).css('overflow-y') == "scroll")) ?
  3272. iSanityWidth+o.oScroll.iBarWidth : iSanityWidth;
  3273.  
  3274. /* IE6/7 are a law unto themselves... */
  3275. if ( ie67 && (nScrollBody.scrollHeight >
  3276. nScrollBody.offsetHeight || $(nScrollBody).css('overflow-y') == "scroll") )
  3277. {
  3278. o.nTable.style.width = _fnStringToCss( iCorrection-o.oScroll.iBarWidth );
  3279. }
  3280.  
  3281. /* Apply the calculated minimum width to the table wrappers */
  3282. nScrollBody.style.width = _fnStringToCss( iCorrection );
  3283. nScrollHeadInner.parentNode.style.width = _fnStringToCss( iCorrection );
  3284.  
  3285. if ( o.nTFoot !== null )
  3286. {
  3287. nScrollFootInner.parentNode.style.width = _fnStringToCss( iCorrection );
  3288. }
  3289.  
  3290. /* And give the user a warning that we've stopped the table getting too small */
  3291. if ( o.oScroll.sX === "" )
  3292. {
  3293. _fnLog( o, 1, "The table cannot fit into the current element which will cause column"+
  3294. " misalignment. The table has been drawn at its minimum possible width." );
  3295. }
  3296. else if ( o.oScroll.sXInner !== "" )
  3297. {
  3298. _fnLog( o, 1, "The table cannot fit into the current element which will cause column"+
  3299. " misalignment. Increase the sScrollXInner value or remove it to allow automatic"+
  3300. " calculation" );
  3301. }
  3302. }
  3303. else
  3304. {
  3305. nScrollBody.style.width = _fnStringToCss( '100%' );
  3306. nScrollHeadInner.parentNode.style.width = _fnStringToCss( '100%' );
  3307.  
  3308. if ( o.nTFoot !== null )
  3309. {
  3310. nScrollFootInner.parentNode.style.width = _fnStringToCss( '100%' );
  3311. }
  3312. }
  3313.  
  3314.  
  3315. /*
  3316. * 4. Clean up
  3317. */
  3318. if ( o.oScroll.sY === "" )
  3319. {
  3320. /* IE7< puts a vertical scrollbar in place (when it shouldn't be) due to subtracting
  3321. * the scrollbar height from the visible display, rather than adding it on. We need to
  3322. * set the height in order to sort this. Don't want to do it in any other browsers.
  3323. */
  3324. if ( ie67 )
  3325. {
  3326. nScrollBody.style.height = _fnStringToCss( o.nTable.offsetHeight+o.oScroll.iBarWidth );
  3327. }
  3328. }
  3329.  
  3330. if ( o.oScroll.sY !== "" && o.oScroll.bCollapse )
  3331. {
  3332. nScrollBody.style.height = _fnStringToCss( o.oScroll.sY );
  3333.  
  3334. var iExtra = (o.oScroll.sX !== "" && o.nTable.offsetWidth > nScrollBody.offsetWidth) ?
  3335. o.oScroll.iBarWidth : 0;
  3336. if ( o.nTable.offsetHeight < nScrollBody.offsetHeight )
  3337. {
  3338. nScrollBody.style.height = _fnStringToCss( o.nTable.offsetHeight+iExtra );
  3339. }
  3340. }
  3341.  
  3342. /* Finally set the width's of the header and footer tables */
  3343. var iOuterWidth = $(o.nTable).outerWidth();
  3344. nScrollHeadTable.style.width = _fnStringToCss( iOuterWidth );
  3345. nScrollHeadInner.style.width = _fnStringToCss( iOuterWidth );
  3346.  
  3347. // Figure out if there are scrollbar present - if so then we need a the header and footer to
  3348. // provide a bit more space to allow "overflow" scrolling (i.e. past the scrollbar)
  3349. var bScrolling = $(o.nTable).height() > nScrollBody.clientHeight || $(nScrollBody).css('overflow-y') == "scroll";
  3350. nScrollHeadInner.style.paddingRight = bScrolling ? o.oScroll.iBarWidth+"px" : "0px";
  3351.  
  3352. if ( o.nTFoot !== null )
  3353. {
  3354. nScrollFootTable.style.width = _fnStringToCss( iOuterWidth );
  3355. nScrollFootInner.style.width = _fnStringToCss( iOuterWidth );
  3356. nScrollFootInner.style.paddingRight = bScrolling ? o.oScroll.iBarWidth+"px" : "0px";
  3357. }
  3358.  
  3359. /* Adjust the position of the header incase we loose the y-scrollbar */
  3360. $(nScrollBody).scroll();
  3361.  
  3362. /* If sorting or filtering has occurred, jump the scrolling back to the top */
  3363. if ( o.bSorted || o.bFiltered )
  3364. {
  3365. nScrollBody.scrollTop = 0;
  3366. }
  3367. }
  3368.  
  3369.  
  3370. /**
  3371. * Apply a given function to the display child nodes of an element array (typically
  3372. * TD children of TR rows
  3373. * @param {function} fn Method to apply to the objects
  3374. * @param array {nodes} an1 List of elements to look through for display children
  3375. * @param array {nodes} an2 Another list (identical structure to the first) - optional
  3376. * @memberof DataTable#oApi
  3377. */
  3378. function _fnApplyToChildren( fn, an1, an2 )
  3379. {
  3380. for ( var i=0, iLen=an1.length ; i<iLen ; i++ )
  3381. {
  3382. for ( var j=0, jLen=an1[i].childNodes.length ; j<jLen ; j++ )
  3383. {
  3384. if ( an1[i].childNodes[j].nodeType == 1 )
  3385. {
  3386. if ( an2 )
  3387. {
  3388. fn( an1[i].childNodes[j], an2[i].childNodes[j] );
  3389. }
  3390. else
  3391. {
  3392. fn( an1[i].childNodes[j] );
  3393. }
  3394. }
  3395. }
  3396. }
  3397. }
  3398.  
  3399.  
  3400.  
  3401. /**
  3402. * Convert a CSS unit width to pixels (e.g. 2em)
  3403. * @param {string} sWidth width to be converted
  3404. * @param {node} nParent parent to get the with for (required for relative widths) - optional
  3405. * @returns {int} iWidth width in pixels
  3406. * @memberof DataTable#oApi
  3407. */
  3408. function _fnConvertToWidth ( sWidth, nParent )
  3409. {
  3410. if ( !sWidth || sWidth === null || sWidth === '' )
  3411. {
  3412. return 0;
  3413. }
  3414.  
  3415. if ( !nParent )
  3416. {
  3417. nParent = document.getElementsByTagName('body')[0];
  3418. }
  3419.  
  3420. var iWidth;
  3421. var nTmp = document.createElement( "div" );
  3422. nTmp.style.width = _fnStringToCss( sWidth );
  3423.  
  3424. nParent.appendChild( nTmp );
  3425. iWidth = nTmp.offsetWidth;
  3426. nParent.removeChild( nTmp );
  3427.  
  3428. return ( iWidth );
  3429. }
  3430.  
  3431.  
  3432. /**
  3433. * Calculate the width of columns for the table
  3434. * @param {object} oSettings dataTables settings object
  3435. * @memberof DataTable#oApi
  3436. */
  3437. function _fnCalculateColumnWidths ( oSettings )
  3438. {
  3439. var iTableWidth = oSettings.nTable.offsetWidth;
  3440. var iUserInputs = 0;
  3441. var iTmpWidth;
  3442. var iVisibleColumns = 0;
  3443. var iColums = oSettings.aoColumns.length;
  3444. var i, iIndex, iCorrector, iWidth;
  3445. var oHeaders = $('th', oSettings.nTHead);
  3446. var widthAttr = oSettings.nTable.getAttribute('width');
  3447.  
  3448. /* Convert any user input sizes into pixel sizes */
  3449. for ( i=0 ; i<iColums ; i++ )
  3450. {
  3451. if ( oSettings.aoColumns[i].bVisible )
  3452. {
  3453. iVisibleColumns++;
  3454.  
  3455. if ( oSettings.aoColumns[i].sWidth !== null )
  3456. {
  3457. iTmpWidth = _fnConvertToWidth( oSettings.aoColumns[i].sWidthOrig,
  3458. oSettings.nTable.parentNode );
  3459. if ( iTmpWidth !== null )
  3460. {
  3461. oSettings.aoColumns[i].sWidth = _fnStringToCss( iTmpWidth );
  3462. }
  3463.  
  3464. iUserInputs++;
  3465. }
  3466. }
  3467. }
  3468.  
  3469. /* If the number of columns in the DOM equals the number that we have to process in
  3470. * DataTables, then we can use the offsets that are created by the web-browser. No custom
  3471. * sizes can be set in order for this to happen, nor scrolling used
  3472. */
  3473. if ( iColums == oHeaders.length && iUserInputs === 0 && iVisibleColumns == iColums &&
  3474. oSettings.oScroll.sX === "" && oSettings.oScroll.sY === "" )
  3475. {
  3476. for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
  3477. {
  3478. iTmpWidth = $(oHeaders[i]).width();
  3479. if ( iTmpWidth !== null )
  3480. {
  3481. oSettings.aoColumns[i].sWidth = _fnStringToCss( iTmpWidth );
  3482. }
  3483. }
  3484. }
  3485. else
  3486. {
  3487. /* Otherwise we are going to have to do some calculations to get the width of each column.
  3488. * Construct a 1 row table with the widest node in the data, and any user defined widths,
  3489. * then insert it into the DOM and allow the browser to do all the hard work of
  3490. * calculating table widths.
  3491. */
  3492. var
  3493. nCalcTmp = oSettings.nTable.cloneNode( false ),
  3494. nTheadClone = oSettings.nTHead.cloneNode(true),
  3495. nBody = document.createElement( 'tbody' ),
  3496. nTr = document.createElement( 'tr' ),
  3497. nDivSizing;
  3498.  
  3499. nCalcTmp.removeAttribute( "id" );
  3500. nCalcTmp.appendChild( nTheadClone );
  3501. if ( oSettings.nTFoot !== null )
  3502. {
  3503. nCalcTmp.appendChild( oSettings.nTFoot.cloneNode(true) );
  3504. _fnApplyToChildren( function(n) {
  3505. n.style.width = "";
  3506. }, nCalcTmp.getElementsByTagName('tr') );
  3507. }
  3508.  
  3509. nCalcTmp.appendChild( nBody );
  3510. nBody.appendChild( nTr );
  3511.  
  3512. /* Remove any sizing that was previously applied by the styles */
  3513. var jqColSizing = $('thead th', nCalcTmp);
  3514. if ( jqColSizing.length === 0 )
  3515. {
  3516. jqColSizing = $('tbody tr:eq(0)>td', nCalcTmp);
  3517. }
  3518.  
  3519. /* Apply custom sizing to the cloned header */
  3520. var nThs = _fnGetUniqueThs( oSettings, nTheadClone );
  3521. iCorrector = 0;
  3522. for ( i=0 ; i<iColums ; i++ )
  3523. {
  3524. var oColumn = oSettings.aoColumns[i];
  3525. if ( oColumn.bVisible && oColumn.sWidthOrig !== null && oColumn.sWidthOrig !== "" )
  3526. {
  3527. nThs[i-iCorrector].style.width = _fnStringToCss( oColumn.sWidthOrig );
  3528. }
  3529. else if ( oColumn.bVisible )
  3530. {
  3531. nThs[i-iCorrector].style.width = "";
  3532. }
  3533. else
  3534. {
  3535. iCorrector++;
  3536. }
  3537. }
  3538.  
  3539. /* Find the biggest td for each column and put it into the table */
  3540. for ( i=0 ; i<iColums ; i++ )
  3541. {
  3542. if ( oSettings.aoColumns[i].bVisible )
  3543. {
  3544. var nTd = _fnGetWidestNode( oSettings, i );
  3545. if ( nTd !== null )
  3546. {
  3547. nTd = nTd.cloneNode(true);
  3548. if ( oSettings.aoColumns[i].sContentPadding !== "" )
  3549. {
  3550. nTd.innerHTML += oSettings.aoColumns[i].sContentPadding;
  3551. }
  3552. nTr.appendChild( nTd );
  3553. }
  3554. }
  3555. }
  3556.  
  3557. /* Build the table and 'display' it */
  3558. var nWrapper = oSettings.nTable.parentNode;
  3559. nWrapper.appendChild( nCalcTmp );
  3560.  
  3561. /* When scrolling (X or Y) we want to set the width of the table as appropriate. However,
  3562. * when not scrolling leave the table width as it is. This results in slightly different,
  3563. * but I think correct behaviour
  3564. */
  3565. if ( oSettings.oScroll.sX !== "" && oSettings.oScroll.sXInner !== "" )
  3566. {
  3567. nCalcTmp.style.width = _fnStringToCss(oSettings.oScroll.sXInner);
  3568. }
  3569. else if ( oSettings.oScroll.sX !== "" )
  3570. {
  3571. nCalcTmp.style.width = "";
  3572. if ( $(nCalcTmp).width() < nWrapper.offsetWidth )
  3573. {
  3574. nCalcTmp.style.width = _fnStringToCss( nWrapper.offsetWidth );
  3575. }
  3576. }
  3577. else if ( oSettings.oScroll.sY !== "" )
  3578. {
  3579. nCalcTmp.style.width = _fnStringToCss( nWrapper.offsetWidth );
  3580. }
  3581. else if ( widthAttr )
  3582. {
  3583. nCalcTmp.style.width = _fnStringToCss( widthAttr );
  3584. }
  3585. nCalcTmp.style.visibility = "hidden";
  3586.  
  3587. /* Scrolling considerations */
  3588. _fnScrollingWidthAdjust( oSettings, nCalcTmp );
  3589.  
  3590. /* Read the width's calculated by the browser and store them for use by the caller. We
  3591. * first of all try to use the elements in the body, but it is possible that there are
  3592. * no elements there, under which circumstances we use the header elements
  3593. */
  3594. var oNodes = $("tbody tr:eq(0)", nCalcTmp).children();
  3595. if ( oNodes.length === 0 )
  3596. {
  3597. oNodes = _fnGetUniqueThs( oSettings, $('thead', nCalcTmp)[0] );
  3598. }
  3599.  
  3600. /* Browsers need a bit of a hand when a width is assigned to any columns when
  3601. * x-scrolling as they tend to collapse the table to the min-width, even if
  3602. * we sent the column widths. So we need to keep track of what the table width
  3603. * should be by summing the user given values, and the automatic values
  3604. */
  3605. if ( oSettings.oScroll.sX !== "" )
  3606. {
  3607. var iTotal = 0;
  3608. iCorrector = 0;
  3609. for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
  3610. {
  3611. if ( oSettings.aoColumns[i].bVisible )
  3612. {
  3613. if ( oSettings.aoColumns[i].sWidthOrig === null )
  3614. {
  3615. iTotal += $(oNodes[iCorrector]).outerWidth();
  3616. }
  3617. else
  3618. {
  3619. iTotal += parseInt(oSettings.aoColumns[i].sWidth.replace('px',''), 10) +
  3620. ($(oNodes[iCorrector]).outerWidth() - $(oNodes[iCorrector]).width());
  3621. }
  3622. iCorrector++;
  3623. }
  3624. }
  3625.  
  3626. nCalcTmp.style.width = _fnStringToCss( iTotal );
  3627. oSettings.nTable.style.width = _fnStringToCss( iTotal );
  3628. }
  3629.  
  3630. iCorrector = 0;
  3631. for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
  3632. {
  3633. if ( oSettings.aoColumns[i].bVisible )
  3634. {
  3635. iWidth = $(oNodes[iCorrector]).width();
  3636. if ( iWidth !== null && iWidth > 0 )
  3637. {
  3638. oSettings.aoColumns[i].sWidth = _fnStringToCss( iWidth );
  3639. }
  3640. iCorrector++;
  3641. }
  3642. }
  3643.  
  3644. var cssWidth = $(nCalcTmp).css('width');
  3645. oSettings.nTable.style.width = (cssWidth.indexOf('%') !== -1) ?
  3646. cssWidth : _fnStringToCss( $(nCalcTmp).outerWidth() );
  3647. nCalcTmp.parentNode.removeChild( nCalcTmp );
  3648. }
  3649.  
  3650. if ( widthAttr )
  3651. {
  3652. oSettings.nTable.style.width = _fnStringToCss( widthAttr );
  3653. }
  3654. }
  3655.  
  3656.  
  3657. /**
  3658. * Adjust a table's width to take account of scrolling
  3659. * @param {object} oSettings dataTables settings object
  3660. * @param {node} n table node
  3661. * @memberof DataTable#oApi
  3662. */
  3663. function _fnScrollingWidthAdjust ( oSettings, n )
  3664. {
  3665. if ( oSettings.oScroll.sX === "" && oSettings.oScroll.sY !== "" )
  3666. {
  3667. /* When y-scrolling only, we want to remove the width of the scroll bar so the table
  3668. * + scroll bar will fit into the area avaialble.
  3669. */
  3670. var iOrigWidth = $(n).width();
  3671. n.style.width = _fnStringToCss( $(n).outerWidth()-oSettings.oScroll.iBarWidth );
  3672. }
  3673. else if ( oSettings.oScroll.sX !== "" )
  3674. {
  3675. /* When x-scrolling both ways, fix the table at it's current size, without adjusting */
  3676. n.style.width = _fnStringToCss( $(n).outerWidth() );
  3677. }
  3678. }
  3679.  
  3680.  
  3681. /**
  3682. * Get the widest node
  3683. * @param {object} oSettings dataTables settings object
  3684. * @param {int} iCol column of interest
  3685. * @returns {string} max strlens for each column
  3686. * @memberof DataTable#oApi
  3687. */
  3688. function _fnGetWidestNode( oSettings, iCol )
  3689. {
  3690. var iMaxIndex = _fnGetMaxLenString( oSettings, iCol );
  3691. if ( iMaxIndex < 0 )
  3692. {
  3693. return null;
  3694. }
  3695.  
  3696. if ( oSettings.aoData[iMaxIndex].nTr === null )
  3697. {
  3698. var n = document.createElement('td');
  3699. n.innerHTML = _fnGetCellData( oSettings, iMaxIndex, iCol, '' );
  3700. return n;
  3701. }
  3702. return _fnGetTdNodes(oSettings, iMaxIndex)[iCol];
  3703. }
  3704.  
  3705.  
  3706. /**
  3707. * Get the maximum strlen for each data column
  3708. * @param {object} oSettings dataTables settings object
  3709. * @param {int} iCol column of interest
  3710. * @returns {string} max strlens for each column
  3711. * @memberof DataTable#oApi
  3712. */
  3713. function _fnGetMaxLenString( oSettings, iCol )
  3714. {
  3715. var iMax = -1;
  3716. var iMaxIndex = -1;
  3717.  
  3718. for ( var i=0 ; i<oSettings.aoData.length ; i++ )
  3719. {
  3720. var s = _fnGetCellData( oSettings, i, iCol, 'display' )+"";
  3721. s = s.replace( /<.*?>/g, "" );
  3722. if ( s.length > iMax )
  3723. {
  3724. iMax = s.length;
  3725. iMaxIndex = i;
  3726. }
  3727. }
  3728.  
  3729. return iMaxIndex;
  3730. }
  3731.  
  3732.  
  3733. /**
  3734. * Append a CSS unit (only if required) to a string
  3735. * @param {array} aArray1 first array
  3736. * @param {array} aArray2 second array
  3737. * @returns {int} 0 if match, 1 if length is different, 2 if no match
  3738. * @memberof DataTable#oApi
  3739. */
  3740. function _fnStringToCss( s )
  3741. {
  3742. if ( s === null )
  3743. {
  3744. return "0px";
  3745. }
  3746.  
  3747. if ( typeof s == 'number' )
  3748. {
  3749. if ( s < 0 )
  3750. {
  3751. return "0px";
  3752. }
  3753. return s+"px";
  3754. }
  3755.  
  3756. /* Check if the last character is not 0-9 */
  3757. var c = s.charCodeAt( s.length-1 );
  3758. if (c < 0x30 || c > 0x39)
  3759. {
  3760. return s;
  3761. }
  3762. return s+"px";
  3763. }
  3764.  
  3765.  
  3766. /**
  3767. * Get the width of a scroll bar in this browser being used
  3768. * @returns {int} width in pixels
  3769. * @memberof DataTable#oApi
  3770. */
  3771. function _fnScrollBarWidth ()
  3772. {
  3773. var inner = document.createElement('p');
  3774. var style = inner.style;
  3775. style.width = "100%";
  3776. style.height = "200px";
  3777. style.padding = "0px";
  3778.  
  3779. var outer = document.createElement('div');
  3780. style = outer.style;
  3781. style.position = "absolute";
  3782. style.top = "0px";
  3783. style.left = "0px";
  3784. style.visibility = "hidden";
  3785. style.width = "200px";
  3786. style.height = "150px";
  3787. style.padding = "0px";
  3788. style.overflow = "hidden";
  3789. outer.appendChild(inner);
  3790.  
  3791. document.body.appendChild(outer);
  3792. var w1 = inner.offsetWidth;
  3793. outer.style.overflow = 'scroll';
  3794. var w2 = inner.offsetWidth;
  3795. if ( w1 == w2 )
  3796. {
  3797. w2 = outer.clientWidth;
  3798. }
  3799.  
  3800. document.body.removeChild(outer);
  3801. return (w1 - w2);
  3802. }
  3803.  
  3804.  
  3805.  
  3806. /**
  3807. * Change the order of the table
  3808. * @param {object} oSettings dataTables settings object
  3809. * @param {bool} bApplyClasses optional - should we apply classes or not
  3810. * @memberof DataTable#oApi
  3811. */
  3812. function _fnSort ( oSettings, bApplyClasses )
  3813. {
  3814. var
  3815. i, iLen, j, jLen, k, kLen,
  3816. sDataType, nTh,
  3817. aaSort = [],
  3818. aiOrig = [],
  3819. oSort = DataTable.ext.oSort,
  3820. aoData = oSettings.aoData,
  3821. aoColumns = oSettings.aoColumns,
  3822. oAria = oSettings.oLanguage.oAria;
  3823.  
  3824. /* No sorting required if server-side or no sorting array */
  3825. if ( !oSettings.oFeatures.bServerSide &&
  3826. (oSettings.aaSorting.length !== 0 || oSettings.aaSortingFixed !== null) )
  3827. {
  3828. aaSort = ( oSettings.aaSortingFixed !== null ) ?
  3829. oSettings.aaSortingFixed.concat( oSettings.aaSorting ) :
  3830. oSettings.aaSorting.slice();
  3831.  
  3832. /* If there is a sorting data type, and a fuction belonging to it, then we need to
  3833. * get the data from the developer's function and apply it for this column
  3834. */
  3835. for ( i=0 ; i<aaSort.length ; i++ )
  3836. {
  3837. var iColumn = aaSort[i][0];
  3838. var iVisColumn = _fnColumnIndexToVisible( oSettings, iColumn );
  3839. sDataType = oSettings.aoColumns[ iColumn ].sSortDataType;
  3840. if ( DataTable.ext.afnSortData[sDataType] )
  3841. {
  3842. var aData = DataTable.ext.afnSortData[sDataType].call(
  3843. oSettings.oInstance, oSettings, iColumn, iVisColumn
  3844. );
  3845. if ( aData.length === aoData.length )
  3846. {
  3847. for ( j=0, jLen=aoData.length ; j<jLen ; j++ )
  3848. {
  3849. _fnSetCellData( oSettings, j, iColumn, aData[j] );
  3850. }
  3851. }
  3852. else
  3853. {
  3854. _fnLog( oSettings, 0, "Returned data sort array (col "+iColumn+") is the wrong length" );
  3855. }
  3856. }
  3857. }
  3858.  
  3859. /* Create a value - key array of the current row positions such that we can use their
  3860. * current position during the sort, if values match, in order to perform stable sorting
  3861. */
  3862. for ( i=0, iLen=oSettings.aiDisplayMaster.length ; i<iLen ; i++ )
  3863. {
  3864. aiOrig[ oSettings.aiDisplayMaster[i] ] = i;
  3865. }
  3866.  
  3867. /* Build an internal data array which is specific to the sort, so we can get and prep
  3868. * the data to be sorted only once, rather than needing to do it every time the sorting
  3869. * function runs. This make the sorting function a very simple comparison
  3870. */
  3871. var iSortLen = aaSort.length;
  3872. var fnSortFormat, aDataSort;
  3873. for ( i=0, iLen=aoData.length ; i<iLen ; i++ )
  3874. {
  3875. for ( j=0 ; j<iSortLen ; j++ )
  3876. {
  3877. aDataSort = aoColumns[ aaSort[j][0] ].aDataSort;
  3878.  
  3879. for ( k=0, kLen=aDataSort.length ; k<kLen ; k++ )
  3880. {
  3881. sDataType = aoColumns[ aDataSort[k] ].sType;
  3882. fnSortFormat = oSort[ (sDataType ? sDataType : 'string')+"-pre" ];
  3883.  
  3884. aoData[i]._aSortData[ aDataSort[k] ] = fnSortFormat ?
  3885. fnSortFormat( _fnGetCellData( oSettings, i, aDataSort[k], 'sort' ) ) :
  3886. _fnGetCellData( oSettings, i, aDataSort[k], 'sort' );
  3887. }
  3888. }
  3889. }
  3890.  
  3891. /* Do the sort - here we want multi-column sorting based on a given data source (column)
  3892. * and sorting function (from oSort) in a certain direction. It's reasonably complex to
  3893. * follow on it's own, but this is what we want (example two column sorting):
  3894. * fnLocalSorting = function(a,b){
  3895. * var iTest;
  3896. * iTest = oSort['string-asc']('data11', 'data12');
  3897. * if (iTest !== 0)
  3898. * return iTest;
  3899. * iTest = oSort['numeric-desc']('data21', 'data22');
  3900. * if (iTest !== 0)
  3901. * return iTest;
  3902. * return oSort['numeric-asc']( aiOrig[a], aiOrig[b] );
  3903. * }
  3904. * Basically we have a test for each sorting column, if the data in that column is equal,
  3905. * test the next column. If all columns match, then we use a numeric sort on the row
  3906. * positions in the original data array to provide a stable sort.
  3907. */
  3908. oSettings.aiDisplayMaster.sort( function ( a, b ) {
  3909. var k, l, lLen, iTest, aDataSort, sDataType;
  3910. for ( k=0 ; k<iSortLen ; k++ )
  3911. {
  3912. aDataSort = aoColumns[ aaSort[k][0] ].aDataSort;
  3913.  
  3914. for ( l=0, lLen=aDataSort.length ; l<lLen ; l++ )
  3915. {
  3916. sDataType = aoColumns[ aDataSort[l] ].sType;
  3917.  
  3918. iTest = oSort[ (sDataType ? sDataType : 'string')+"-"+aaSort[k][1] ](
  3919. aoData[a]._aSortData[ aDataSort[l] ],
  3920. aoData[b]._aSortData[ aDataSort[l] ]
  3921. );
  3922.  
  3923. if ( iTest !== 0 )
  3924. {
  3925. return iTest;
  3926. }
  3927. }
  3928. }
  3929.  
  3930. return oSort['numeric-asc']( aiOrig[a], aiOrig[b] );
  3931. } );
  3932. }
  3933.  
  3934. /* Alter the sorting classes to take account of the changes */
  3935. if ( (bApplyClasses === undefined || bApplyClasses) && !oSettings.oFeatures.bDeferRender )
  3936. {
  3937. _fnSortingClasses( oSettings );
  3938. }
  3939.  
  3940. for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
  3941. {
  3942. var sTitle = aoColumns[i].sTitle.replace( /<.*?>/g, "" );
  3943. nTh = aoColumns[i].nTh;
  3944. nTh.removeAttribute('aria-sort');
  3945. nTh.removeAttribute('aria-label');
  3946.  
  3947. /* In ARIA only the first sorting column can be marked as sorting - no multi-sort option */
  3948. if ( aoColumns[i].bSortable )
  3949. {
  3950. if ( aaSort.length > 0 && aaSort[0][0] == i )
  3951. {
  3952. nTh.setAttribute('aria-sort', aaSort[0][1]=="asc" ? "ascending" : "descending" );
  3953.  
  3954. var nextSort = (aoColumns[i].asSorting[ aaSort[0][2]+1 ]) ?
  3955. aoColumns[i].asSorting[ aaSort[0][2]+1 ] : aoColumns[i].asSorting[0];
  3956. nTh.setAttribute('aria-label', sTitle+
  3957. (nextSort=="asc" ? oAria.sSortAscending : oAria.sSortDescending) );
  3958. }
  3959. else
  3960. {
  3961. nTh.setAttribute('aria-label', sTitle+
  3962. (aoColumns[i].asSorting[0]=="asc" ? oAria.sSortAscending : oAria.sSortDescending) );
  3963. }
  3964. }
  3965. else
  3966. {
  3967. nTh.setAttribute('aria-label', sTitle);
  3968. }
  3969. }
  3970.  
  3971. /* Tell the draw function that we have sorted the data */
  3972. oSettings.bSorted = true;
  3973. $(oSettings.oInstance).trigger('sort', oSettings);
  3974.  
  3975. /* Copy the master data into the draw array and re-draw */
  3976. if ( oSettings.oFeatures.bFilter )
  3977. {
  3978. /* _fnFilter() will redraw the table for us */
  3979. _fnFilterComplete( oSettings, oSettings.oPreviousSearch, 1 );
  3980. }
  3981. else
  3982. {
  3983. oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
  3984. oSettings._iDisplayStart = 0; /* reset display back to page 0 */
  3985. _fnCalculateEnd( oSettings );
  3986. _fnDraw( oSettings );
  3987. }
  3988. }
  3989.  
  3990.  
  3991. /**
  3992. * Attach a sort handler (click) to a node
  3993. * @param {object} oSettings dataTables settings object
  3994. * @param {node} nNode node to attach the handler to
  3995. * @param {int} iDataIndex column sorting index
  3996. * @param {function} [fnCallback] callback function
  3997. * @memberof DataTable#oApi
  3998. */
  3999. function _fnSortAttachListener ( oSettings, nNode, iDataIndex, fnCallback )
  4000. {
  4001. _fnBindAction( nNode, {}, function (e) {
  4002. /* If the column is not sortable - don't to anything */
  4003. if ( oSettings.aoColumns[iDataIndex].bSortable === false )
  4004. {
  4005. return;
  4006. }
  4007.  
  4008. /*
  4009. * This is a little bit odd I admit... I declare a temporary function inside the scope of
  4010. * _fnBuildHead and the click handler in order that the code presented here can be used
  4011. * twice - once for when bProcessing is enabled, and another time for when it is
  4012. * disabled, as we need to perform slightly different actions.
  4013. * Basically the issue here is that the Javascript engine in modern browsers don't
  4014. * appear to allow the rendering engine to update the display while it is still excuting
  4015. * it's thread (well - it does but only after long intervals). This means that the
  4016. * 'processing' display doesn't appear for a table sort. To break the js thread up a bit
  4017. * I force an execution break by using setTimeout - but this breaks the expected
  4018. * thread continuation for the end-developer's point of view (their code would execute
  4019. * too early), so we on;y do it when we absolutely have to.
  4020. */
  4021. var fnInnerSorting = function () {
  4022. var iColumn, iNextSort;
  4023.  
  4024. /* If the shift key is pressed then we are multipe column sorting */
  4025. if ( e.shiftKey )
  4026. {
  4027. /* Are we already doing some kind of sort on this column? */
  4028. var bFound = false;
  4029. for ( var i=0 ; i<oSettings.aaSorting.length ; i++ )
  4030. {
  4031. if ( oSettings.aaSorting[i][0] == iDataIndex )
  4032. {
  4033. bFound = true;
  4034. iColumn = oSettings.aaSorting[i][0];
  4035. iNextSort = oSettings.aaSorting[i][2]+1;
  4036.  
  4037. if ( !oSettings.aoColumns[iColumn].asSorting[iNextSort] )
  4038. {
  4039. /* Reached the end of the sorting options, remove from multi-col sort */
  4040. oSettings.aaSorting.splice( i, 1 );
  4041. }
  4042. else
  4043. {
  4044. /* Move onto next sorting direction */
  4045. oSettings.aaSorting[i][1] = oSettings.aoColumns[iColumn].asSorting[iNextSort];
  4046. oSettings.aaSorting[i][2] = iNextSort;
  4047. }
  4048. break;
  4049. }
  4050. }
  4051.  
  4052. /* No sort yet - add it in */
  4053. if ( bFound === false )
  4054. {
  4055. oSettings.aaSorting.push( [ iDataIndex,
  4056. oSettings.aoColumns[iDataIndex].asSorting[0], 0 ] );
  4057. }
  4058. }
  4059. else
  4060. {
  4061. /* If no shift key then single column sort */
  4062. if ( oSettings.aaSorting.length == 1 && oSettings.aaSorting[0][0] == iDataIndex )
  4063. {
  4064. iColumn = oSettings.aaSorting[0][0];
  4065. iNextSort = oSettings.aaSorting[0][2]+1;
  4066. if ( !oSettings.aoColumns[iColumn].asSorting[iNextSort] )
  4067. {
  4068. iNextSort = 0;
  4069. }
  4070. oSettings.aaSorting[0][1] = oSettings.aoColumns[iColumn].asSorting[iNextSort];
  4071. oSettings.aaSorting[0][2] = iNextSort;
  4072. }
  4073. else
  4074. {
  4075. oSettings.aaSorting.splice( 0, oSettings.aaSorting.length );
  4076. oSettings.aaSorting.push( [ iDataIndex,
  4077. oSettings.aoColumns[iDataIndex].asSorting[0], 0 ] );
  4078. }
  4079. }
  4080.  
  4081. /* Run the sort */
  4082. _fnSort( oSettings );
  4083. }; /* /fnInnerSorting */
  4084.  
  4085. if ( !oSettings.oFeatures.bProcessing )
  4086. {
  4087. fnInnerSorting();
  4088. }
  4089. else
  4090. {
  4091. _fnProcessingDisplay( oSettings, true );
  4092. setTimeout( function() {
  4093. fnInnerSorting();
  4094. if ( !oSettings.oFeatures.bServerSide )
  4095. {
  4096. _fnProcessingDisplay( oSettings, false );
  4097. }
  4098. }, 0 );
  4099. }
  4100.  
  4101. /* Call the user specified callback function - used for async user interaction */
  4102. if ( typeof fnCallback == 'function' )
  4103. {
  4104. fnCallback( oSettings );
  4105. }
  4106. } );
  4107. }
  4108.  
  4109.  
  4110. /**
  4111. * Set the sorting classes on the header, Note: it is safe to call this function
  4112. * when bSort and bSortClasses are false
  4113. * @param {object} oSettings dataTables settings object
  4114. * @memberof DataTable#oApi
  4115. */
  4116. function _fnSortingClasses( oSettings )
  4117. {
  4118. var i, iLen, j, jLen, iFound;
  4119. var aaSort, sClass;
  4120. var iColumns = oSettings.aoColumns.length;
  4121. var oClasses = oSettings.oClasses;
  4122.  
  4123. for ( i=0 ; i<iColumns ; i++ )
  4124. {
  4125. if ( oSettings.aoColumns[i].bSortable )
  4126. {
  4127. $(oSettings.aoColumns[i].nTh).removeClass( oClasses.sSortAsc +" "+ oClasses.sSortDesc +
  4128. " "+ oSettings.aoColumns[i].sSortingClass );
  4129. }
  4130. }
  4131.  
  4132. if ( oSettings.aaSortingFixed !== null )
  4133. {
  4134. aaSort = oSettings.aaSortingFixed.concat( oSettings.aaSorting );
  4135. }
  4136. else
  4137. {
  4138. aaSort = oSettings.aaSorting.slice();
  4139. }
  4140.  
  4141. /* Apply the required classes to the header */
  4142. for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
  4143. {
  4144. if ( oSettings.aoColumns[i].bSortable )
  4145. {
  4146. sClass = oSettings.aoColumns[i].sSortingClass;
  4147. iFound = -1;
  4148. for ( j=0 ; j<aaSort.length ; j++ )
  4149. {
  4150. if ( aaSort[j][0] == i )
  4151. {
  4152. sClass = ( aaSort[j][1] == "asc" ) ?
  4153. oClasses.sSortAsc : oClasses.sSortDesc;
  4154. iFound = j;
  4155. break;
  4156. }
  4157. }
  4158. $(oSettings.aoColumns[i].nTh).addClass( sClass );
  4159.  
  4160. if ( oSettings.bJUI )
  4161. {
  4162. /* jQuery UI uses extra markup */
  4163. var jqSpan = $("span."+oClasses.sSortIcon, oSettings.aoColumns[i].nTh);
  4164. jqSpan.removeClass(oClasses.sSortJUIAsc +" "+ oClasses.sSortJUIDesc +" "+
  4165. oClasses.sSortJUI +" "+ oClasses.sSortJUIAscAllowed +" "+ oClasses.sSortJUIDescAllowed );
  4166.  
  4167. var sSpanClass;
  4168. if ( iFound == -1 )
  4169. {
  4170. sSpanClass = oSettings.aoColumns[i].sSortingClassJUI;
  4171. }
  4172. else if ( aaSort[iFound][1] == "asc" )
  4173. {
  4174. sSpanClass = oClasses.sSortJUIAsc;
  4175. }
  4176. else
  4177. {
  4178. sSpanClass = oClasses.sSortJUIDesc;
  4179. }
  4180.  
  4181. jqSpan.addClass( sSpanClass );
  4182. }
  4183. }
  4184. else
  4185. {
  4186. /* No sorting on this column, so add the base class. This will have been assigned by
  4187. * _fnAddColumn
  4188. */
  4189. $(oSettings.aoColumns[i].nTh).addClass( oSettings.aoColumns[i].sSortingClass );
  4190. }
  4191. }
  4192.  
  4193. /*
  4194. * Apply the required classes to the table body
  4195. * Note that this is given as a feature switch since it can significantly slow down a sort
  4196. * on large data sets (adding and removing of classes is always slow at the best of times..)
  4197. * Further to this, note that this code is admitadly fairly ugly. It could be made a lot
  4198. * simpiler using jQuery selectors and add/removeClass, but that is significantly slower
  4199. * (on the order of 5 times slower) - hence the direct DOM manipulation here.
  4200. * Note that for defered drawing we do use jQuery - the reason being that taking the first
  4201. * row found to see if the whole column needs processed can miss classes since the first
  4202. * column might be new.
  4203. */
  4204. sClass = oClasses.sSortColumn;
  4205.  
  4206. if ( oSettings.oFeatures.bSort && oSettings.oFeatures.bSortClasses )
  4207. {
  4208. var nTds = _fnGetTdNodes( oSettings );
  4209.  
  4210. /* Remove the old classes */
  4211. if ( oSettings.oFeatures.bDeferRender )
  4212. {
  4213. $(nTds).removeClass(sClass+'1 '+sClass+'2 '+sClass+'3');
  4214. }
  4215. else if ( nTds.length >= iColumns )
  4216. {
  4217. for ( i=0 ; i<iColumns ; i++ )
  4218. {
  4219. if ( nTds[i].className.indexOf(sClass+"1") != -1 )
  4220. {
  4221. for ( j=0, jLen=(nTds.length/iColumns) ; j<jLen ; j++ )
  4222. {
  4223. nTds[(iColumns*j)+i].className =
  4224. $.trim( nTds[(iColumns*j)+i].className.replace( sClass+"1", "" ) );
  4225. }
  4226. }
  4227. else if ( nTds[i].className.indexOf(sClass+"2") != -1 )
  4228. {
  4229. for ( j=0, jLen=(nTds.length/iColumns) ; j<jLen ; j++ )
  4230. {
  4231. nTds[(iColumns*j)+i].className =
  4232. $.trim( nTds[(iColumns*j)+i].className.replace( sClass+"2", "" ) );
  4233. }
  4234. }
  4235. else if ( nTds[i].className.indexOf(sClass+"3") != -1 )
  4236. {
  4237. for ( j=0, jLen=(nTds.length/iColumns) ; j<jLen ; j++ )
  4238. {
  4239. nTds[(iColumns*j)+i].className =
  4240. $.trim( nTds[(iColumns*j)+i].className.replace( " "+sClass+"3", "" ) );
  4241. }
  4242. }
  4243. }
  4244. }
  4245.  
  4246. /* Add the new classes to the table */
  4247. var iClass = 1, iTargetCol;
  4248. for ( i=0 ; i<aaSort.length ; i++ )
  4249. {
  4250. iTargetCol = parseInt( aaSort[i][0], 10 );
  4251. for ( j=0, jLen=(nTds.length/iColumns) ; j<jLen ; j++ )
  4252. {
  4253. nTds[(iColumns*j)+iTargetCol].className += " "+sClass+iClass;
  4254. }
  4255.  
  4256. if ( iClass < 3 )
  4257. {
  4258. iClass++;
  4259. }
  4260. }
  4261. }
  4262. }
  4263.  
  4264.  
  4265.  
  4266. /**
  4267. * Save the state of a table in a cookie such that the page can be reloaded
  4268. * @param {object} oSettings dataTables settings object
  4269. * @memberof DataTable#oApi
  4270. */
  4271. function _fnSaveState ( oSettings )
  4272. {
  4273. if ( !oSettings.oFeatures.bStateSave || oSettings.bDestroying )
  4274. {
  4275. return;
  4276. }
  4277.  
  4278. /* Store the interesting variables */
  4279. var i, iLen, bInfinite=oSettings.oScroll.bInfinite;
  4280. var oState = {
  4281. "iCreate": new Date().getTime(),
  4282. "iStart": (bInfinite ? 0 : oSettings._iDisplayStart),
  4283. "iEnd": (bInfinite ? oSettings._iDisplayLength : oSettings._iDisplayEnd),
  4284. "iLength": oSettings._iDisplayLength,
  4285. "aaSorting": $.extend( true, [], oSettings.aaSorting ),
  4286. "oSearch": $.extend( true, {}, oSettings.oPreviousSearch ),
  4287. "aoSearchCols": $.extend( true, [], oSettings.aoPreSearchCols ),
  4288. "abVisCols": []
  4289. };
  4290.  
  4291. for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
  4292. {
  4293. oState.abVisCols.push( oSettings.aoColumns[i].bVisible );
  4294. }
  4295.  
  4296. _fnCallbackFire( oSettings, "aoStateSaveParams", 'stateSaveParams', [oSettings, oState] );
  4297.  
  4298. oSettings.fnStateSave.call( oSettings.oInstance, oSettings, oState );
  4299. }
  4300.  
  4301.  
  4302. /**
  4303. * Attempt to load a saved table state from a cookie
  4304. * @param {object} oSettings dataTables settings object
  4305. * @param {object} oInit DataTables init object so we can override settings
  4306. * @memberof DataTable#oApi
  4307. */
  4308. function _fnLoadState ( oSettings, oInit )
  4309. {
  4310. if ( !oSettings.oFeatures.bStateSave )
  4311. {
  4312. return;
  4313. }
  4314.  
  4315. var oData = oSettings.fnStateLoad.call( oSettings.oInstance, oSettings );
  4316. if ( !oData )
  4317. {
  4318. return;
  4319. }
  4320.  
  4321. /* Allow custom and plug-in manipulation functions to alter the saved data set and
  4322. * cancelling of loading by returning false
  4323. */
  4324. var abStateLoad = _fnCallbackFire( oSettings, 'aoStateLoadParams', 'stateLoadParams', [oSettings, oData] );
  4325. if ( $.inArray( false, abStateLoad ) !== -1 )
  4326. {
  4327. return;
  4328. }
  4329.  
  4330. /* Store the saved state so it might be accessed at any time */
  4331. oSettings.oLoadedState = $.extend( true, {}, oData );
  4332.  
  4333. /* Restore key features */
  4334. oSettings._iDisplayStart = oData.iStart;
  4335. oSettings.iInitDisplayStart = oData.iStart;
  4336. oSettings._iDisplayEnd = oData.iEnd;
  4337. oSettings._iDisplayLength = oData.iLength;
  4338. oSettings.aaSorting = oData.aaSorting.slice();
  4339. oSettings.saved_aaSorting = oData.aaSorting.slice();
  4340.  
  4341. /* Search filtering */
  4342. $.extend( oSettings.oPreviousSearch, oData.oSearch );
  4343. $.extend( true, oSettings.aoPreSearchCols, oData.aoSearchCols );
  4344.  
  4345. /* Column visibility state
  4346. * Pass back visibiliy settings to the init handler, but to do not here override
  4347. * the init object that the user might have passed in
  4348. */
  4349. oInit.saved_aoColumns = [];
  4350. for ( var i=0 ; i<oData.abVisCols.length ; i++ )
  4351. {
  4352. oInit.saved_aoColumns[i] = {};
  4353. oInit.saved_aoColumns[i].bVisible = oData.abVisCols[i];
  4354. }
  4355.  
  4356. _fnCallbackFire( oSettings, 'aoStateLoaded', 'stateLoaded', [oSettings, oData] );
  4357. }
  4358.  
  4359.  
  4360. /**
  4361. * Create a new cookie with a value to store the state of a table
  4362. * @param {string} sName name of the cookie to create
  4363. * @param {string} sValue the value the cookie should take
  4364. * @param {int} iSecs duration of the cookie
  4365. * @param {string} sBaseName sName is made up of the base + file name - this is the base
  4366. * @param {function} fnCallback User definable function to modify the cookie
  4367. * @memberof DataTable#oApi
  4368. */
  4369. function _fnCreateCookie ( sName, sValue, iSecs, sBaseName, fnCallback )
  4370. {
  4371. var date = new Date();
  4372. date.setTime( date.getTime()+(iSecs*1000) );
  4373.  
  4374. /*
  4375. * Shocking but true - it would appear IE has major issues with having the path not having
  4376. * a trailing slash on it. We need the cookie to be available based on the path, so we
  4377. * have to append the file name to the cookie name. Appalling. Thanks to vex for adding the
  4378. * patch to use at least some of the path
  4379. */
  4380. var aParts = window.location.pathname.split('/');
  4381. var sNameFile = sName + '_' + aParts.pop().replace(/[\/:]/g,"").toLowerCase();
  4382. var sFullCookie, oData;
  4383.  
  4384. if ( fnCallback !== null )
  4385. {
  4386. oData = (typeof $.parseJSON === 'function') ?
  4387. $.parseJSON( sValue ) : eval( '('+sValue+')' );
  4388. sFullCookie = fnCallback( sNameFile, oData, date.toGMTString(),
  4389. aParts.join('/')+"/" );
  4390. }
  4391. else
  4392. {
  4393. sFullCookie = sNameFile + "=" + encodeURIComponent(sValue) +
  4394. "; expires=" + date.toGMTString() +"; path=" + aParts.join('/')+"/";
  4395. }
  4396.  
  4397. /* Are we going to go over the cookie limit of 4KiB? If so, try to delete a cookies
  4398. * belonging to DataTables. This is FAR from bullet proof
  4399. */
  4400. var sOldName="", iOldTime=9999999999999;
  4401. var iLength = _fnReadCookie( sNameFile )!==null ? document.cookie.length :
  4402. sFullCookie.length + document.cookie.length;
  4403.  
  4404. if ( iLength+10 > 4096 ) /* Magic 10 for padding */
  4405. {
  4406. var aCookies =document.cookie.split(';');
  4407. for ( var i=0, iLen=aCookies.length ; i<iLen ; i++ )
  4408. {
  4409. if ( aCookies[i].indexOf( sBaseName ) != -1 )
  4410. {
  4411. /* It's a DataTables cookie, so eval it and check the time stamp */
  4412. var aSplitCookie = aCookies[i].split('=');
  4413. try { oData = eval( '('+decodeURIComponent(aSplitCookie[1])+')' ); }
  4414. catch( e ) { continue; }
  4415.  
  4416. if ( oData.iCreate && oData.iCreate < iOldTime )
  4417. {
  4418. sOldName = aSplitCookie[0];
  4419. iOldTime = oData.iCreate;
  4420. }
  4421. }
  4422. }
  4423.  
  4424. if ( sOldName !== "" )
  4425. {
  4426. document.cookie = sOldName+"=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path="+
  4427. aParts.join('/') + "/";
  4428. }
  4429. }
  4430.  
  4431. document.cookie = sFullCookie;
  4432. }
  4433.  
  4434.  
  4435. /**
  4436. * Read an old cookie to get a cookie with an old table state
  4437. * @param {string} sName name of the cookie to read
  4438. * @returns {string} contents of the cookie - or null if no cookie with that name found
  4439. * @memberof DataTable#oApi
  4440. */
  4441. function _fnReadCookie ( sName )
  4442. {
  4443. var
  4444. aParts = window.location.pathname.split('/'),
  4445. sNameEQ = sName + '_' + aParts[aParts.length-1].replace(/[\/:]/g,"").toLowerCase() + '=',
  4446. sCookieContents = document.cookie.split(';');
  4447.  
  4448. for( var i=0 ; i<sCookieContents.length ; i++ )
  4449. {
  4450. var c = sCookieContents[i];
  4451.  
  4452. while (c.charAt(0)==' ')
  4453. {
  4454. c = c.substring(1,c.length);
  4455. }
  4456.  
  4457. if (c.indexOf(sNameEQ) === 0)
  4458. {
  4459. return decodeURIComponent( c.substring(sNameEQ.length,c.length) );
  4460. }
  4461. }
  4462. return null;
  4463. }
  4464.  
  4465.  
  4466.  
  4467. /**
  4468. * Return the settings object for a particular table
  4469. * @param {node} nTable table we are using as a dataTable
  4470. * @returns {object} Settings object - or null if not found
  4471. * @memberof DataTable#oApi
  4472. */
  4473. function _fnSettingsFromNode ( nTable )
  4474. {
  4475. for ( var i=0 ; i<DataTable.settings.length ; i++ )
  4476. {
  4477. if ( DataTable.settings[i].nTable === nTable )
  4478. {
  4479. return DataTable.settings[i];
  4480. }
  4481. }
  4482.  
  4483. return null;
  4484. }
  4485.  
  4486.  
  4487. /**
  4488. * Return an array with the TR nodes for the table
  4489. * @param {object} oSettings dataTables settings object
  4490. * @returns {array} TR array
  4491. * @memberof DataTable#oApi
  4492. */
  4493. function _fnGetTrNodes ( oSettings )
  4494. {
  4495. var aNodes = [];
  4496. var aoData = oSettings.aoData;
  4497. for ( var i=0, iLen=aoData.length ; i<iLen ; i++ )
  4498. {
  4499. if ( aoData[i].nTr !== null )
  4500. {
  4501. aNodes.push( aoData[i].nTr );
  4502. }
  4503. }
  4504. return aNodes;
  4505. }
  4506.  
  4507.  
  4508. /**
  4509. * Return an flat array with all TD nodes for the table, or row
  4510. * @param {object} oSettings dataTables settings object
  4511. * @param {int} [iIndividualRow] aoData index to get the nodes for - optional
  4512. * if not given then the return array will contain all nodes for the table
  4513. * @returns {array} TD array
  4514. * @memberof DataTable#oApi
  4515. */
  4516. function _fnGetTdNodes ( oSettings, iIndividualRow )
  4517. {
  4518. var anReturn = [];
  4519. var iCorrector;
  4520. var anTds;
  4521. var iRow, iRows=oSettings.aoData.length,
  4522. iColumn, iColumns, oData, sNodeName, iStart=0, iEnd=iRows;
  4523.  
  4524. /* Allow the collection to be limited to just one row */
  4525. if ( iIndividualRow !== undefined )
  4526. {
  4527. iStart = iIndividualRow;
  4528. iEnd = iIndividualRow+1;
  4529. }
  4530.  
  4531. for ( iRow=iStart ; iRow<iEnd ; iRow++ )
  4532. {
  4533. oData = oSettings.aoData[iRow];
  4534. if ( oData.nTr !== null )
  4535. {
  4536. /* get the TD child nodes - taking into account text etc nodes */
  4537. anTds = [];
  4538. for ( iColumn=0, iColumns=oData.nTr.childNodes.length ; iColumn<iColumns ; iColumn++ )
  4539. {
  4540. sNodeName = oData.nTr.childNodes[iColumn].nodeName.toLowerCase();
  4541. if ( sNodeName == 'td' || sNodeName == 'th' )
  4542. {
  4543. anTds.push( oData.nTr.childNodes[iColumn] );
  4544. }
  4545. }
  4546.  
  4547. iCorrector = 0;
  4548. for ( iColumn=0, iColumns=oSettings.aoColumns.length ; iColumn<iColumns ; iColumn++ )
  4549. {
  4550. if ( oSettings.aoColumns[iColumn].bVisible )
  4551. {
  4552. anReturn.push( anTds[iColumn-iCorrector] );
  4553. }
  4554. else
  4555. {
  4556. anReturn.push( oData._anHidden[iColumn] );
  4557. iCorrector++;
  4558. }
  4559. }
  4560. }
  4561. }
  4562.  
  4563. return anReturn;
  4564. }
  4565.  
  4566.  
  4567. /**
  4568. * Log an error message
  4569. * @param {object} oSettings dataTables settings object
  4570. * @param {int} iLevel log error messages, or display them to the user
  4571. * @param {string} sMesg error message
  4572. * @memberof DataTable#oApi
  4573. */
  4574. function _fnLog( oSettings, iLevel, sMesg )
  4575. {
  4576. var sAlert = (oSettings===null) ?
  4577. "DataTables warning: "+sMesg :
  4578. "DataTables warning (table id = '"+oSettings.sTableId+"'): "+sMesg;
  4579.  
  4580. if ( iLevel === 0 )
  4581. {
  4582. if ( DataTable.ext.sErrMode == 'alert' )
  4583. {
  4584. alert( sAlert );
  4585. }
  4586. else
  4587. {
  4588. throw new Error(sAlert);
  4589. }
  4590. return;
  4591. }
  4592. else if ( window.console && console.log )
  4593. {
  4594. console.log( sAlert );
  4595. }
  4596. }
  4597.  
  4598.  
  4599. /**
  4600. * See if a property is defined on one object, if so assign it to the other object
  4601. * @param {object} oRet target object
  4602. * @param {object} oSrc source object
  4603. * @param {string} sName property
  4604. * @param {string} [sMappedName] name to map too - optional, sName used if not given
  4605. * @memberof DataTable#oApi
  4606. */
  4607. function _fnMap( oRet, oSrc, sName, sMappedName )
  4608. {
  4609. if ( sMappedName === undefined )
  4610. {
  4611. sMappedName = sName;
  4612. }
  4613. if ( oSrc[sName] !== undefined )
  4614. {
  4615. oRet[sMappedName] = oSrc[sName];
  4616. }
  4617. }
  4618.  
  4619.  
  4620. /**
  4621. * Extend objects - very similar to jQuery.extend, but deep copy objects, and shallow
  4622. * copy arrays. The reason we need to do this, is that we don't want to deep copy array
  4623. * init values (such as aaSorting) since the dev wouldn't be able to override them, but
  4624. * we do want to deep copy arrays.
  4625. * @param {object} oOut Object to extend
  4626. * @param {object} oExtender Object from which the properties will be applied to oOut
  4627. * @returns {object} oOut Reference, just for convenience - oOut === the return.
  4628. * @memberof DataTable#oApi
  4629. * @todo This doesn't take account of arrays inside the deep copied objects.
  4630. */
  4631. function _fnExtend( oOut, oExtender )
  4632. {
  4633. for ( var prop in oExtender )
  4634. {
  4635. if ( oExtender.hasOwnProperty(prop) )
  4636. {
  4637. if ( typeof oInit[prop] === 'object' && $.isArray(oExtender[prop]) === false )
  4638. {
  4639. $.extend( true, oOut[prop], oExtender[prop] );
  4640. }
  4641. else
  4642. {
  4643. oOut[prop] = oExtender[prop];
  4644. }
  4645. }
  4646. }
  4647.  
  4648. return oOut;
  4649. }
  4650.  
  4651.  
  4652. /**
  4653. * Bind an event handers to allow a click or return key to activate the callback.
  4654. * This is good for accessability since a return on the keyboard will have the
  4655. * same effect as a click, if the element has focus.
  4656. * @param {element} n Element to bind the action to
  4657. * @param {object} oData Data object to pass to the triggered function
  4658. * @param {function) fn Callback function for when the event is triggered
  4659. * @memberof DataTable#oApi
  4660. */
  4661. function _fnBindAction( n, oData, fn )
  4662. {
  4663. $(n)
  4664. .bind( 'click.DT', oData, function (e) {
  4665. n.blur(); // Remove focus outline for mouse users
  4666. fn(e);
  4667. } )
  4668. .bind( 'keypress.DT', oData, function (e){
  4669. if ( e.which === 13 ) {
  4670. fn(e);
  4671. } } )
  4672. .bind( 'selectstart.DT', function () {
  4673. /* Take the brutal approach to cancelling text selection */
  4674. return false;
  4675. } );
  4676. }
  4677.  
  4678.  
  4679. /**
  4680. * Register a callback function. Easily allows a callback function to be added to
  4681. * an array store of callback functions that can then all be called together.
  4682. * @param {object} oSettings dataTables settings object
  4683. * @param {string} sStore Name of the array storeage for the callbacks in oSettings
  4684. * @param {function} fn Function to be called back
  4685. * @param {string) sName Identifying name for the callback (i.e. a label)
  4686. * @memberof DataTable#oApi
  4687. */
  4688. function _fnCallbackReg( oSettings, sStore, fn, sName )
  4689. {
  4690. if ( fn )
  4691. {
  4692. oSettings[sStore].push( {
  4693. "fn": fn,
  4694. "sName": sName
  4695. } );
  4696. }
  4697. }
  4698.  
  4699.  
  4700. /**
  4701. * Fire callback functions and trigger events. Note that the loop over the callback
  4702. * array store is done backwards! Further note that you do not want to fire off triggers
  4703. * in time sensitive applications (for example cell creation) as its slow.
  4704. * @param {object} oSettings dataTables settings object
  4705. * @param {string} sStore Name of the array storeage for the callbacks in oSettings
  4706. * @param {string} sTrigger Name of the jQuery custom event to trigger. If null no trigger
  4707. * is fired
  4708. * @param {array) aArgs Array of arguments to pass to the callback function / trigger
  4709. * @memberof DataTable#oApi
  4710. */
  4711. function _fnCallbackFire( oSettings, sStore, sTrigger, aArgs )
  4712. {
  4713. var aoStore = oSettings[sStore];
  4714. var aRet =[];
  4715.  
  4716. for ( var i=aoStore.length-1 ; i>=0 ; i-- )
  4717. {
  4718. aRet.push( aoStore[i].fn.apply( oSettings.oInstance, aArgs ) );
  4719. }
  4720.  
  4721. if ( sTrigger !== null )
  4722. {
  4723. $(oSettings.oInstance).trigger(sTrigger, aArgs);
  4724. }
  4725.  
  4726. return aRet;
  4727. }
  4728.  
  4729.  
  4730. /**
  4731. * JSON stringify. If JSON.stringify it provided by the browser, json2.js or any other
  4732. * library, then we use that as it is fast, safe and accurate. If the function isn't
  4733. * available then we need to built it ourselves - the insperation for this function comes
  4734. * from Craig Buckler ( http://www.sitepoint.com/javascript-json-serialization/ ). It is
  4735. * not perfect and absolutely should not be used as a replacement to json2.js - but it does
  4736. * do what we need, without requiring a dependency for DataTables.
  4737. * @param {object} o JSON object to be converted
  4738. * @returns {string} JSON string
  4739. * @memberof DataTable#oApi
  4740. */
  4741. var _fnJsonString = (window.JSON) ? JSON.stringify : function( o )
  4742. {
  4743. /* Not an object or array */
  4744. var sType = typeof o;
  4745. if (sType !== "object" || o === null)
  4746. {
  4747. // simple data type
  4748. if (sType === "string")
  4749. {
  4750. o = '"'+o+'"';
  4751. }
  4752. return o+"";
  4753. }
  4754.  
  4755. /* If object or array, need to recurse over it */
  4756. var
  4757. sProp, mValue,
  4758. json = [],
  4759. bArr = $.isArray(o);
  4760.  
  4761. for (sProp in o)
  4762. {
  4763. mValue = o[sProp];
  4764. sType = typeof mValue;
  4765.  
  4766. if (sType === "string")
  4767. {
  4768. mValue = '"'+mValue+'"';
  4769. }
  4770. else if (sType === "object" && mValue !== null)
  4771. {
  4772. mValue = _fnJsonString(mValue);
  4773. }
  4774.  
  4775. json.push((bArr ? "" : '"'+sProp+'":') + mValue);
  4776. }
  4777.  
  4778. return (bArr ? "[" : "{") + json + (bArr ? "]" : "}");
  4779. };
  4780.  
  4781.  
  4782.  
  4783.  
  4784. /**
  4785. * Perform a jQuery selector action on the table's TR elements (from the tbody) and
  4786. * return the resulting jQuery object.
  4787. * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
  4788. * @param {object} [oOpts] Optional parameters for modifying the rows to be included
  4789. * @param {string} [oOpts.filter=none] Select TR elements that meet the current filter
  4790. * criterion ("applied") or all TR elements (i.e. no filter).
  4791. * @param {string} [oOpts.order=current] Order of the TR elements in the processed array.
  4792. * Can be either 'current', whereby the current sorting of the table is used, or
  4793. * 'original' whereby the original order the data was read into the table is used.
  4794. * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
  4795. * ("current") or not ("all"). If 'current' is given, then order is assumed to be
  4796. * 'current' and filter is 'applied', regardless of what they might be given as.
  4797. * @returns {object} jQuery object, filtered by the given selector.
  4798. * @dtopt API
  4799. *
  4800. * @example
  4801. * $(document).ready(function() {
  4802. * var oTable = $('#example').dataTable();
  4803. *
  4804. * // Highlight every second row
  4805. * oTable.$('tr:odd').css('backgroundColor', 'blue');
  4806. * } );
  4807. *
  4808. * @example
  4809. * $(document).ready(function() {
  4810. * var oTable = $('#example').dataTable();
  4811. *
  4812. * // Filter to rows with 'Webkit' in them, add a background colour and then
  4813. * // remove the filter, thus highlighting the 'Webkit' rows only.
  4814. * oTable.fnFilter('Webkit');
  4815. * oTable.$('tr', {"filter": "applied"}).css('backgroundColor', 'blue');
  4816. * oTable.fnFilter('');
  4817. * } );
  4818. */
  4819. this.$ = function ( sSelector, oOpts )
  4820. {
  4821. var i, iLen, a = [];
  4822. var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
  4823.  
  4824. if ( !oOpts )
  4825. {
  4826. oOpts = {};
  4827. }
  4828.  
  4829. oOpts = $.extend( {}, {
  4830. "filter": "none", // applied
  4831. "order": "current", // "original"
  4832. "page": "all" // current
  4833. }, oOpts );
  4834.  
  4835. // Current page implies that order=current and fitler=applied, since it is fairly
  4836. // senseless otherwise
  4837. if ( oOpts.page == 'current' )
  4838. {
  4839. for ( i=oSettings._iDisplayStart, iLen=oSettings.fnDisplayEnd() ; i<iLen ; i++ )
  4840. {
  4841. a.push( oSettings.aoData[ oSettings.aiDisplay[i] ].nTr );
  4842. }
  4843. }
  4844. else if ( oOpts.order == "current" && oOpts.filter == "none" )
  4845. {
  4846. for ( i=0, iLen=oSettings.aiDisplayMaster.length ; i<iLen ; i++ )
  4847. {
  4848. a.push( oSettings.aoData[ oSettings.aiDisplayMaster[i] ].nTr );
  4849. }
  4850. }
  4851. else if ( oOpts.order == "current" && oOpts.filter == "applied" )
  4852. {
  4853. for ( i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ )
  4854. {
  4855. a.push( oSettings.aoData[ oSettings.aiDisplay[i] ].nTr );
  4856. }
  4857. }
  4858. else if ( oOpts.order == "original" && oOpts.filter == "none" )
  4859. {
  4860. for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
  4861. {
  4862. a.push( oSettings.aoData[ i ].nTr );
  4863. }
  4864. }
  4865. else if ( oOpts.order == "original" && oOpts.filter == "applied" )
  4866. {
  4867. for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
  4868. {
  4869. if ( $.inArray( i, oSettings.aiDisplay ) !== -1 )
  4870. {
  4871. a.push( oSettings.aoData[ i ].nTr );
  4872. }
  4873. }
  4874. }
  4875. else
  4876. {
  4877. _fnLog( oSettings, 1, "Unknown selection options" );
  4878. }
  4879.  
  4880. /* We need to filter on the TR elements and also 'find' in their descendants
  4881. * to make the selector act like it would in a full table - so we need
  4882. * to build both results and then combine them together
  4883. */
  4884. var jqA = $(a);
  4885. var jqTRs = jqA.filter( sSelector );
  4886. var jqDescendants = jqA.find( sSelector );
  4887.  
  4888. return $( [].concat($.makeArray(jqTRs), $.makeArray(jqDescendants)) );
  4889. };
  4890.  
  4891.  
  4892. /**
  4893. * Almost identical to $ in operation, but in this case returns the data for the matched
  4894. * rows - as such, the jQuery selector used should match TR row nodes or TD/TH cell nodes
  4895. * rather than any decendents, so the data can be obtained for the row/cell. If matching
  4896. * rows are found, the data returned is the original data array/object that was used to
  4897. * create the row (or a generated array if from a DOM source).
  4898. *
  4899. * This method is often useful incombination with $ where both functions are given the
  4900. * same parameters and the array indexes will match identically.
  4901. * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
  4902. * @param {object} [oOpts] Optional parameters for modifying the rows to be included
  4903. * @param {string} [oOpts.filter=none] Select elements that meet the current filter
  4904. * criterion ("applied") or all elements (i.e. no filter).
  4905. * @param {string} [oOpts.order=current] Order of the data in the processed array.
  4906. * Can be either 'current', whereby the current sorting of the table is used, or
  4907. * 'original' whereby the original order the data was read into the table is used.
  4908. * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
  4909. * ("current") or not ("all"). If 'current' is given, then order is assumed to be
  4910. * 'current' and filter is 'applied', regardless of what they might be given as.
  4911. * @returns {array} Data for the matched elements. If any elements, as a result of the
  4912. * selector, were not TR, TD or TH elements in the DataTable, they will have a null
  4913. * entry in the array.
  4914. * @dtopt API
  4915. *
  4916. * @example
  4917. * $(document).ready(function() {
  4918. * var oTable = $('#example').dataTable();
  4919. *
  4920. * // Get the data from the first row in the table
  4921. * var data = oTable._('tr:first');
  4922. *
  4923. * // Do something useful with the data
  4924. * alert( "First cell is: "+data[0] );
  4925. * } );
  4926. *
  4927. * @example
  4928. * $(document).ready(function() {
  4929. * var oTable = $('#example').dataTable();
  4930. *
  4931. * // Filter to 'Webkit' and get all data for
  4932. * oTable.fnFilter('Webkit');
  4933. * var data = oTable._('tr', {"filter": "applied"});
  4934. *
  4935. * // Do something with the data
  4936. * alert( data.length+" rows matched the filter" );
  4937. * } );
  4938. */
  4939. this._ = function ( sSelector, oOpts )
  4940. {
  4941. var aOut = [];
  4942. var i, iLen, iIndex;
  4943. var aTrs = this.$( sSelector, oOpts );
  4944.  
  4945. for ( i=0, iLen=aTrs.length ; i<iLen ; i++ )
  4946. {
  4947. aOut.push( this.fnGetData(aTrs[i]) );
  4948. }
  4949.  
  4950. return aOut;
  4951. };
  4952.  
  4953.  
  4954. /**
  4955. * Add a single new row or multiple rows of data to the table. Please note
  4956. * that this is suitable for client-side processing only - if you are using
  4957. * server-side processing (i.e. "bServerSide": true), then to add data, you
  4958. * must add it to the data source, i.e. the server-side, through an Ajax call.
  4959. * @param {array|object} mData The data to be added to the table. This can be:
  4960. * <ul>
  4961. * <li>1D array of data - add a single row with the data provided</li>
  4962. * <li>2D array of arrays - add multiple rows in a single call</li>
  4963. * <li>object - data object when using <i>mDataProp</i></li>
  4964. * <li>array of objects - multiple data objects when using <i>mDataProp</i></li>
  4965. * </ul>
  4966. * @param {bool} [bRedraw=true] redraw the table or not
  4967. * @returns {array} An array of integers, representing the list of indexes in
  4968. * <i>aoData</i> ({@link DataTable.models.oSettings}) that have been added to
  4969. * the table.
  4970. * @dtopt API
  4971. *
  4972. * @example
  4973. * // Global var for counter
  4974. * var giCount = 2;
  4975. *
  4976. * $(document).ready(function() {
  4977. * $('#example').dataTable();
  4978. * } );
  4979. *
  4980. * function fnClickAddRow() {
  4981. * $('#example').dataTable().fnAddData( [
  4982. * giCount+".1",
  4983. * giCount+".2",
  4984. * giCount+".3",
  4985. * giCount+".4" ]
  4986. * );
  4987. *
  4988. * giCount++;
  4989. * }
  4990. */
  4991. this.fnAddData = function( mData, bRedraw )
  4992. {
  4993. if ( mData.length === 0 )
  4994. {
  4995. return [];
  4996. }
  4997.  
  4998. var aiReturn = [];
  4999. var iTest;
  5000.  
  5001. /* Find settings from table node */
  5002. var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
  5003.  
  5004. /* Check if we want to add multiple rows or not */
  5005. if ( typeof mData[0] === "object" && mData[0] !== null )
  5006. {
  5007. for ( var i=0 ; i<mData.length ; i++ )
  5008. {
  5009. iTest = _fnAddData( oSettings, mData[i] );
  5010. if ( iTest == -1 )
  5011. {
  5012. return aiReturn;
  5013. }
  5014. aiReturn.push( iTest );
  5015. }
  5016. }
  5017. else
  5018. {
  5019. iTest = _fnAddData( oSettings, mData );
  5020. if ( iTest == -1 )
  5021. {
  5022. return aiReturn;
  5023. }
  5024. aiReturn.push( iTest );
  5025. }
  5026.  
  5027. oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
  5028.  
  5029. if ( bRedraw === undefined || bRedraw )
  5030. {
  5031. _fnReDraw( oSettings );
  5032. }
  5033. return aiReturn;
  5034. };
  5035.  
  5036.  
  5037. /**
  5038. * This function will make DataTables recalculate the column sizes, based on the data
  5039. * contained in the table and the sizes applied to the columns (in the DOM, CSS or
  5040. * through the sWidth parameter). This can be useful when the width of the table's
  5041. * parent element changes (for example a window resize).
  5042. * @param {boolean} [bRedraw=true] Redraw the table or not, you will typically want to
  5043. * @dtopt API
  5044. *
  5045. * @example
  5046. * $(document).ready(function() {
  5047. * var oTable = $('#example').dataTable( {
  5048. * "sScrollY": "200px",
  5049. * "bPaginate": false
  5050. * } );
  5051. *
  5052. * $(window).bind('resize', function () {
  5053. * oTable.fnAdjustColumnSizing();
  5054. * } );
  5055. * } );
  5056. */
  5057. this.fnAdjustColumnSizing = function ( bRedraw )
  5058. {
  5059. var oSettings = _fnSettingsFromNode(this[DataTable.ext.iApiIndex]);
  5060. _fnAdjustColumnSizing( oSettings );
  5061.  
  5062. if ( bRedraw === undefined || bRedraw )
  5063. {
  5064. this.fnDraw( false );
  5065. }
  5066. else if ( oSettings.oScroll.sX !== "" || oSettings.oScroll.sY !== "" )
  5067. {
  5068. /* If not redrawing, but scrolling, we want to apply the new column sizes anyway */
  5069. this.oApi._fnScrollDraw(oSettings);
  5070. }
  5071. };
  5072.  
  5073.  
  5074. /**
  5075. * Quickly and simply clear a table
  5076. * @param {bool} [bRedraw=true] redraw the table or not
  5077. * @dtopt API
  5078. *
  5079. * @example
  5080. * $(document).ready(function() {
  5081. * var oTable = $('#example').dataTable();
  5082. *
  5083. * // Immediately 'nuke' the current rows (perhaps waiting for an Ajax callback...)
  5084. * oTable.fnClearTable();
  5085. * } );
  5086. */
  5087. this.fnClearTable = function( bRedraw )
  5088. {
  5089. /* Find settings from table node */
  5090. var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
  5091. _fnClearTable( oSettings );
  5092.  
  5093. if ( bRedraw === undefined || bRedraw )
  5094. {
  5095. _fnDraw( oSettings );
  5096. }
  5097. };
  5098.  
  5099.  
  5100. /**
  5101. * The exact opposite of 'opening' a row, this function will close any rows which
  5102. * are currently 'open'.
  5103. * @param {node} nTr the table row to 'close'
  5104. * @returns {int} 0 on success, or 1 if failed (can't find the row)
  5105. * @dtopt API
  5106. *
  5107. * @example
  5108. * $(document).ready(function() {
  5109. * var oTable;
  5110. *
  5111. * // 'open' an information row when a row is clicked on
  5112. * $('#example tbody tr').click( function () {
  5113. * if ( oTable.fnIsOpen(this) ) {
  5114. * oTable.fnClose( this );
  5115. * } else {
  5116. * oTable.fnOpen( this, "Temporary row opened", "info_row" );
  5117. * }
  5118. * } );
  5119. *
  5120. * oTable = $('#example').dataTable();
  5121. * } );
  5122. */
  5123. this.fnClose = function( nTr )
  5124. {
  5125. /* Find settings from table node */
  5126. var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
  5127.  
  5128. for ( var i=0 ; i<oSettings.aoOpenRows.length ; i++ )
  5129. {
  5130. if ( oSettings.aoOpenRows[i].nParent == nTr )
  5131. {
  5132. var nTrParent = oSettings.aoOpenRows[i].nTr.parentNode;
  5133. if ( nTrParent )
  5134. {
  5135. /* Remove it if it is currently on display */
  5136. nTrParent.removeChild( oSettings.aoOpenRows[i].nTr );
  5137. }
  5138. oSettings.aoOpenRows.splice( i, 1 );
  5139. return 0;
  5140. }
  5141. }
  5142. return 1;
  5143. };
  5144.  
  5145.  
  5146. /**
  5147. * Remove a row for the table
  5148. * @param {mixed} mTarget The index of the row from aoData to be deleted, or
  5149. * the TR element you want to delete
  5150. * @param {function|null} [fnCallBack] Callback function
  5151. * @param {bool} [bRedraw=true] Redraw the table or not
  5152. * @returns {array} The row that was deleted
  5153. * @dtopt API
  5154. *
  5155. * @example
  5156. * $(document).ready(function() {
  5157. * var oTable = $('#example').dataTable();
  5158. *
  5159. * // Immediately remove the first row
  5160. * oTable.fnDeleteRow( 0 );
  5161. * } );
  5162. */
  5163. this.fnDeleteRow = function( mTarget, fnCallBack, bRedraw )
  5164. {
  5165. /* Find settings from table node */
  5166. var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
  5167. var i, iLen, iAODataIndex;
  5168.  
  5169. iAODataIndex = (typeof mTarget === 'object') ?
  5170. _fnNodeToDataIndex(oSettings, mTarget) : mTarget;
  5171.  
  5172. /* Return the data array from this row */
  5173. var oData = oSettings.aoData.splice( iAODataIndex, 1 );
  5174.  
  5175. /* Update the _DT_RowIndex parameter */
  5176. for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
  5177. {
  5178. if ( oSettings.aoData[i].nTr !== null )
  5179. {
  5180. oSettings.aoData[i].nTr._DT_RowIndex = i;
  5181. }
  5182. }
  5183.  
  5184. /* Remove the target row from the search array */
  5185. var iDisplayIndex = $.inArray( iAODataIndex, oSettings.aiDisplay );
  5186. oSettings.asDataSearch.splice( iDisplayIndex, 1 );
  5187.  
  5188. /* Delete from the display arrays */
  5189. _fnDeleteIndex( oSettings.aiDisplayMaster, iAODataIndex );
  5190. _fnDeleteIndex( oSettings.aiDisplay, iAODataIndex );
  5191.  
  5192. /* If there is a user callback function - call it */
  5193. if ( typeof fnCallBack === "function" )
  5194. {
  5195. fnCallBack.call( this, oSettings, oData );
  5196. }
  5197.  
  5198. /* Check for an 'overflow' they case for dislaying the table */
  5199. if ( oSettings._iDisplayStart >= oSettings.aiDisplay.length )
  5200. {
  5201. oSettings._iDisplayStart -= oSettings._iDisplayLength;
  5202. if ( oSettings._iDisplayStart < 0 )
  5203. {
  5204. oSettings._iDisplayStart = 0;
  5205. }
  5206. }
  5207.  
  5208. if ( bRedraw === undefined || bRedraw )
  5209. {
  5210. _fnCalculateEnd( oSettings );
  5211. _fnDraw( oSettings );
  5212. }
  5213.  
  5214. return oData;
  5215. };
  5216.  
  5217.  
  5218. /**
  5219. * Restore the table to it's original state in the DOM by removing all of DataTables
  5220. * enhancements, alterations to the DOM structure of the table and event listeners.
  5221. * @param {boolean} [bRemove=false] Completely remove the table from the DOM
  5222. * @dtopt API
  5223. *
  5224. * @example
  5225. * $(document).ready(function() {
  5226. * // This example is fairly pointless in reality, but shows how fnDestroy can be used
  5227. * var oTable = $('#example').dataTable();
  5228. * oTable.fnDestroy();
  5229. * } );
  5230. */
  5231. this.fnDestroy = function ( bRemove )
  5232. {
  5233. var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
  5234. var nOrig = oSettings.nTableWrapper.parentNode;
  5235. var nBody = oSettings.nTBody;
  5236. var i, iLen;
  5237.  
  5238. bRemove = (bRemove===undefined) ? false : true;
  5239.  
  5240. /* Flag to note that the table is currently being destroyed - no action should be taken */
  5241. oSettings.bDestroying = true;
  5242.  
  5243. /* Fire off the destroy callbacks for plug-ins etc */
  5244. _fnCallbackFire( oSettings, "aoDestroyCallback", "destroy", [oSettings] );
  5245.  
  5246. /* Restore hidden columns */
  5247. for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
  5248. {
  5249. if ( oSettings.aoColumns[i].bVisible === false )
  5250. {
  5251. this.fnSetColumnVis( i, true );
  5252. }
  5253. }
  5254.  
  5255. /* Blitz all DT events */
  5256. $(oSettings.nTableWrapper).find('*').andSelf().unbind('.DT');
  5257.  
  5258. /* If there is an 'empty' indicator row, remove it */
  5259. $('tbody>tr>td.'+oSettings.oClasses.sRowEmpty, oSettings.nTable).parent().remove();
  5260.  
  5261. /* When scrolling we had to break the table up - restore it */
  5262. if ( oSettings.nTable != oSettings.nTHead.parentNode )
  5263. {
  5264. $(oSettings.nTable).children('thead').remove();
  5265. oSettings.nTable.appendChild( oSettings.nTHead );
  5266. }
  5267.  
  5268. if ( oSettings.nTFoot && oSettings.nTable != oSettings.nTFoot.parentNode )
  5269. {
  5270. $(oSettings.nTable).children('tfoot').remove();
  5271. oSettings.nTable.appendChild( oSettings.nTFoot );
  5272. }
  5273.  
  5274. /* Remove the DataTables generated nodes, events and classes */
  5275. oSettings.nTable.parentNode.removeChild( oSettings.nTable );
  5276. $(oSettings.nTableWrapper).remove();
  5277.  
  5278. oSettings.aaSorting = [];
  5279. oSettings.aaSortingFixed = [];
  5280. _fnSortingClasses( oSettings );
  5281.  
  5282. $(_fnGetTrNodes( oSettings )).removeClass( oSettings.asStripeClasses.join(' ') );
  5283.  
  5284. $('th, td', oSettings.nTHead).removeClass( [
  5285. oSettings.oClasses.sSortable,
  5286. oSettings.oClasses.sSortableAsc,
  5287. oSettings.oClasses.sSortableDesc,
  5288. oSettings.oClasses.sSortableNone ].join(' ')
  5289. );
  5290. if ( oSettings.bJUI )
  5291. {
  5292. $('th span.'+oSettings.oClasses.sSortIcon
  5293. + ', td span.'+oSettings.oClasses.sSortIcon, oSettings.nTHead).remove();
  5294.  
  5295. $('th, td', oSettings.nTHead).each( function () {
  5296. var jqWrapper = $('div.'+oSettings.oClasses.sSortJUIWrapper, this);
  5297. var kids = jqWrapper.contents();
  5298. $(this).append( kids );
  5299. jqWrapper.remove();
  5300. } );
  5301. }
  5302.  
  5303. /* Add the TR elements back into the table in their original order */
  5304. if ( !bRemove && oSettings.nTableReinsertBefore )
  5305. {
  5306. nOrig.insertBefore( oSettings.nTable, oSettings.nTableReinsertBefore );
  5307. }
  5308. else if ( !bRemove )
  5309. {
  5310. nOrig.appendChild( oSettings.nTable );
  5311. }
  5312.  
  5313. for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
  5314. {
  5315. if ( oSettings.aoData[i].nTr !== null )
  5316. {
  5317. nBody.appendChild( oSettings.aoData[i].nTr );
  5318. }
  5319. }
  5320.  
  5321. /* Restore the width of the original table */
  5322. if ( oSettings.oFeatures.bAutoWidth === true )
  5323. {
  5324. oSettings.nTable.style.width = _fnStringToCss(oSettings.sDestroyWidth);
  5325. }
  5326.  
  5327. /* If the were originally odd/even type classes - then we add them back here. Note
  5328. * this is not fool proof (for example if not all rows as odd/even classes - but
  5329. * it's a good effort without getting carried away
  5330. */
  5331. $(nBody).children('tr:even').addClass( oSettings.asDestroyStripes[0] );
  5332. $(nBody).children('tr:odd').addClass( oSettings.asDestroyStripes[1] );
  5333.  
  5334. /* Remove the settings object from the settings array */
  5335. for ( i=0, iLen=DataTable.settings.length ; i<iLen ; i++ )
  5336. {
  5337. if ( DataTable.settings[i] == oSettings )
  5338. {
  5339. DataTable.settings.splice( i, 1 );
  5340. }
  5341. }
  5342.  
  5343. /* End it all */
  5344. oSettings = null;
  5345. };
  5346.  
  5347.  
  5348. /**
  5349. * Redraw the table
  5350. * @param {bool} [bComplete=true] Re-filter and resort (if enabled) the table before the draw.
  5351. * @dtopt API
  5352. *
  5353. * @example
  5354. * $(document).ready(function() {
  5355. * var oTable = $('#example').dataTable();
  5356. *
  5357. * // Re-draw the table - you wouldn't want to do it here, but it's an example :-)
  5358. * oTable.fnDraw();
  5359. * } );
  5360. */
  5361. this.fnDraw = function( bComplete )
  5362. {
  5363. var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
  5364. if ( bComplete === false )
  5365. {
  5366. _fnCalculateEnd( oSettings );
  5367. _fnDraw( oSettings );
  5368. }
  5369. else
  5370. {
  5371. _fnReDraw( oSettings );
  5372. }
  5373. };
  5374.  
  5375.  
  5376. /**
  5377. * Filter the input based on data
  5378. * @param {string} sInput String to filter the table on
  5379. * @param {int|null} [iColumn] Column to limit filtering to
  5380. * @param {bool} [bRegex=false] Treat as regular expression or not
  5381. * @param {bool} [bSmart=true] Perform smart filtering or not
  5382. * @param {bool} [bShowGlobal=true] Show the input global filter in it's input box(es)
  5383. * @param {bool} [bCaseInsensitive=true] Do case-insensitive matching (true) or not (false)
  5384. * @dtopt API
  5385. *
  5386. * @example
  5387. * $(document).ready(function() {
  5388. * var oTable = $('#example').dataTable();
  5389. *
  5390. * // Sometime later - filter...
  5391. * oTable.fnFilter( 'test string' );
  5392. * } );
  5393. */
  5394. this.fnFilter = function( sInput, iColumn, bRegex, bSmart, bShowGlobal, bCaseInsensitive )
  5395. {
  5396. var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
  5397.  
  5398. if ( !oSettings.oFeatures.bFilter )
  5399. {
  5400. return;
  5401. }
  5402.  
  5403. if ( bRegex === undefined || bRegex === null )
  5404. {
  5405. bRegex = false;
  5406. }
  5407.  
  5408. if ( bSmart === undefined || bSmart === null )
  5409. {
  5410. bSmart = true;
  5411. }
  5412.  
  5413. if ( bShowGlobal === undefined || bShowGlobal === null )
  5414. {
  5415. bShowGlobal = true;
  5416. }
  5417.  
  5418. if ( bCaseInsensitive === undefined || bCaseInsensitive === null )
  5419. {
  5420. bCaseInsensitive = true;
  5421. }
  5422.  
  5423. if ( iColumn === undefined || iColumn === null )
  5424. {
  5425. /* Global filter */
  5426. _fnFilterComplete( oSettings, {
  5427. "sSearch":sInput+"",
  5428. "bRegex": bRegex,
  5429. "bSmart": bSmart,
  5430. "bCaseInsensitive": bCaseInsensitive
  5431. }, 1 );
  5432.  
  5433. if ( bShowGlobal && oSettings.aanFeatures.f )
  5434. {
  5435. var n = oSettings.aanFeatures.f;
  5436. for ( var i=0, iLen=n.length ; i<iLen ; i++ )
  5437. {
  5438. $(n[i]._DT_Input).val( sInput );
  5439. }
  5440. }
  5441. }
  5442. else
  5443. {
  5444. /* Single column filter */
  5445. $.extend( oSettings.aoPreSearchCols[ iColumn ], {
  5446. "sSearch": sInput+"",
  5447. "bRegex": bRegex,
  5448. "bSmart": bSmart,
  5449. "bCaseInsensitive": bCaseInsensitive
  5450. } );
  5451. _fnFilterComplete( oSettings, oSettings.oPreviousSearch, 1 );
  5452. }
  5453. };
  5454.  
  5455.  
  5456. /**
  5457. * Get the data for the whole table, an individual row or an individual cell based on the
  5458. * provided parameters.
  5459. * @param {int|node} [mRow] A TR row node, TD/TH cell node or an integer. If given as
  5460. * a TR node then the data source for the whole row will be returned. If given as a
  5461. * TD/TH cell node then iCol will be automatically calculated and the data for the
  5462. * cell returned. If given as an integer, then this is treated as the aoData internal
  5463. * data index for the row (see fnGetPosition) and the data for that row used.
  5464. * @param {int} [iCol] Optional column index that you want the data of.
  5465. * @returns {array|object|string} If mRow is undefined, then the data for all rows is
  5466. * returned. If mRow is defined, just data for that row, and is iCol is
  5467. * defined, only data for the designated cell is returned.
  5468. * @dtopt API
  5469. *
  5470. * @example
  5471. * // Row data
  5472. * $(document).ready(function() {
  5473. * oTable = $('#example').dataTable();
  5474. *
  5475. * oTable.$('tr').click( function () {
  5476. * var data = oTable.fnGetData( this );
  5477. * // ... do something with the array / object of data for the row
  5478. * } );
  5479. * } );
  5480. *
  5481. * @example
  5482. * // Individual cell data
  5483. * $(document).ready(function() {
  5484. * oTable = $('#example').dataTable();
  5485. *
  5486. * oTable.$('td').click( function () {
  5487. * var sData = oTable.fnGetData( this );
  5488. * alert( 'The cell clicked on had the value of '+sData );
  5489. * } );
  5490. * } );
  5491. */
  5492. this.fnGetData = function( mRow, iCol )
  5493. {
  5494. var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
  5495.  
  5496. if ( mRow !== undefined )
  5497. {
  5498. var iRow = mRow;
  5499. if ( typeof mRow === 'object' )
  5500. {
  5501. var sNode = mRow.nodeName.toLowerCase();
  5502. if (sNode === "tr" )
  5503. {
  5504. iRow = _fnNodeToDataIndex(oSettings, mRow);
  5505. }
  5506. else if ( sNode === "td" )
  5507. {
  5508. iRow = _fnNodeToDataIndex(oSettings, mRow.parentNode);
  5509. iCol = _fnNodeToColumnIndex( oSettings, iRow, mRow );
  5510. }
  5511. }
  5512.  
  5513. if ( iCol !== undefined )
  5514. {
  5515. return _fnGetCellData( oSettings, iRow, iCol, '' );
  5516. }
  5517. return (oSettings.aoData[iRow]!==undefined) ?
  5518. oSettings.aoData[iRow]._aData : null;
  5519. }
  5520. return _fnGetDataMaster( oSettings );
  5521. };
  5522.  
  5523.  
  5524. /**
  5525. * Get an array of the TR nodes that are used in the table's body. Note that you will
  5526. * typically want to use the '$' API method in preference to this as it is more
  5527. * flexible.
  5528. * @param {int} [iRow] Optional row index for the TR element you want
  5529. * @returns {array|node} If iRow is undefined, returns an array of all TR elements
  5530. * in the table's body, or iRow is defined, just the TR element requested.
  5531. * @dtopt API
  5532. *
  5533. * @example
  5534. * $(document).ready(function() {
  5535. * var oTable = $('#example').dataTable();
  5536. *
  5537. * // Get the nodes from the table
  5538. * var nNodes = oTable.fnGetNodes( );
  5539. * } );
  5540. */
  5541. this.fnGetNodes = function( iRow )
  5542. {
  5543. var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
  5544.  
  5545. if ( iRow !== undefined ) {
  5546. return (oSettings.aoData[iRow]!==undefined) ?
  5547. oSettings.aoData[iRow].nTr : null;
  5548. }
  5549. return _fnGetTrNodes( oSettings );
  5550. };
  5551.  
  5552.  
  5553. /**
  5554. * Get the array indexes of a particular cell from it's DOM element
  5555. * and column index including hidden columns
  5556. * @param {node} nNode this can either be a TR, TD or TH in the table's body
  5557. * @returns {int} If nNode is given as a TR, then a single index is returned, or
  5558. * if given as a cell, an array of [row index, column index (visible)] is given.
  5559. * @dtopt API
  5560. *
  5561. * @example
  5562. * $(document).ready(function() {
  5563. * $('#example tbody td').click( function () {
  5564. * // Get the position of the current data from the node
  5565. * var aPos = oTable.fnGetPosition( this );
  5566. *
  5567. * // Get the data array for this row
  5568. * var aData = oTable.fnGetData( aPos[0] );
  5569. *
  5570. * // Update the data array and return the value
  5571. * aData[ aPos[1] ] = 'clicked';
  5572. * this.innerHTML = 'clicked';
  5573. * } );
  5574. *
  5575. * // Init DataTables
  5576. * oTable = $('#example').dataTable();
  5577. * } );
  5578. */
  5579. this.fnGetPosition = function( nNode )
  5580. {
  5581. var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
  5582. var sNodeName = nNode.nodeName.toUpperCase();
  5583.  
  5584. if ( sNodeName == "TR" )
  5585. {
  5586. return _fnNodeToDataIndex(oSettings, nNode);
  5587. }
  5588. else if ( sNodeName == "TD" || sNodeName == "TH" )
  5589. {
  5590. var iDataIndex = _fnNodeToDataIndex( oSettings, nNode.parentNode );
  5591. var iColumnIndex = _fnNodeToColumnIndex( oSettings, iDataIndex, nNode );
  5592. return [ iDataIndex, _fnColumnIndexToVisible(oSettings, iColumnIndex ), iColumnIndex ];
  5593. }
  5594. return null;
  5595. };
  5596.  
  5597.  
  5598. /**
  5599. * Check to see if a row is 'open' or not.
  5600. * @param {node} nTr the table row to check
  5601. * @returns {boolean} true if the row is currently open, false otherwise
  5602. * @dtopt API
  5603. *
  5604. * @example
  5605. * $(document).ready(function() {
  5606. * var oTable;
  5607. *
  5608. * // 'open' an information row when a row is clicked on
  5609. * $('#example tbody tr').click( function () {
  5610. * if ( oTable.fnIsOpen(this) ) {
  5611. * oTable.fnClose( this );
  5612. * } else {
  5613. * oTable.fnOpen( this, "Temporary row opened", "info_row" );
  5614. * }
  5615. * } );
  5616. *
  5617. * oTable = $('#example').dataTable();
  5618. * } );
  5619. */
  5620. this.fnIsOpen = function( nTr )
  5621. {
  5622. var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
  5623. var aoOpenRows = oSettings.aoOpenRows;
  5624.  
  5625. for ( var i=0 ; i<oSettings.aoOpenRows.length ; i++ )
  5626. {
  5627. if ( oSettings.aoOpenRows[i].nParent == nTr )
  5628. {
  5629. return true;
  5630. }
  5631. }
  5632. return false;
  5633. };
  5634.  
  5635.  
  5636. /**
  5637. * This function will place a new row directly after a row which is currently
  5638. * on display on the page, with the HTML contents that is passed into the
  5639. * function. This can be used, for example, to ask for confirmation that a
  5640. * particular record should be deleted.
  5641. * @param {node} nTr The table row to 'open'
  5642. * @param {string|node|jQuery} mHtml The HTML to put into the row
  5643. * @param {string} sClass Class to give the new TD cell
  5644. * @returns {node} The row opened. Note that if the table row passed in as the
  5645. * first parameter, is not found in the table, this method will silently
  5646. * return.
  5647. * @dtopt API
  5648. *
  5649. * @example
  5650. * $(document).ready(function() {
  5651. * var oTable;
  5652. *
  5653. * // 'open' an information row when a row is clicked on
  5654. * $('#example tbody tr').click( function () {
  5655. * if ( oTable.fnIsOpen(this) ) {
  5656. * oTable.fnClose( this );
  5657. * } else {
  5658. * oTable.fnOpen( this, "Temporary row opened", "info_row" );
  5659. * }
  5660. * } );
  5661. *
  5662. * oTable = $('#example').dataTable();
  5663. * } );
  5664. */
  5665. this.fnOpen = function( nTr, mHtml, sClass )
  5666. {
  5667. /* Find settings from table node */
  5668. var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
  5669.  
  5670. /* Check that the row given is in the table */
  5671. var nTableRows = _fnGetTrNodes( oSettings );
  5672. if ( $.inArray(nTr, nTableRows) === -1 )
  5673. {
  5674. return;
  5675. }
  5676.  
  5677. /* the old open one if there is one */
  5678. this.fnClose( nTr );
  5679.  
  5680. var nNewRow = document.createElement("tr");
  5681. var nNewCell = document.createElement("td");
  5682. nNewRow.appendChild( nNewCell );
  5683. nNewCell.className = sClass;
  5684. nNewCell.colSpan = _fnVisbleColumns( oSettings );
  5685.  
  5686. if (typeof mHtml === "string")
  5687. {
  5688. nNewCell.innerHTML = mHtml;
  5689. }
  5690. else
  5691. {
  5692. $(nNewCell).html( mHtml );
  5693. }
  5694.  
  5695. /* If the nTr isn't on the page at the moment - then we don't insert at the moment */
  5696. var nTrs = $('tr', oSettings.nTBody);
  5697. if ( $.inArray(nTr, nTrs) != -1 )
  5698. {
  5699. $(nNewRow).insertAfter(nTr);
  5700. }
  5701.  
  5702. oSettings.aoOpenRows.push( {
  5703. "nTr": nNewRow,
  5704. "nParent": nTr
  5705. } );
  5706.  
  5707. return nNewRow;
  5708. };
  5709.  
  5710.  
  5711. /**
  5712. * Change the pagination - provides the internal logic for pagination in a simple API
  5713. * function. With this function you can have a DataTables table go to the next,
  5714. * previous, first or last pages.
  5715. * @param {string|int} mAction Paging action to take: "first", "previous", "next" or "last"
  5716. * or page number to jump to (integer), note that page 0 is the first page.
  5717. * @param {bool} [bRedraw=true] Redraw the table or not
  5718. * @dtopt API
  5719. *
  5720. * @example
  5721. * $(document).ready(function() {
  5722. * var oTable = $('#example').dataTable();
  5723. * oTable.fnPageChange( 'next' );
  5724. * } );
  5725. */
  5726. this.fnPageChange = function ( mAction, bRedraw )
  5727. {
  5728. var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
  5729. _fnPageChange( oSettings, mAction );
  5730. _fnCalculateEnd( oSettings );
  5731.  
  5732. if ( bRedraw === undefined || bRedraw )
  5733. {
  5734. _fnDraw( oSettings );
  5735. }
  5736. };
  5737.  
  5738.  
  5739. /**
  5740. * Show a particular column
  5741. * @param {int} iCol The column whose display should be changed
  5742. * @param {bool} bShow Show (true) or hide (false) the column
  5743. * @param {bool} [bRedraw=true] Redraw the table or not
  5744. * @dtopt API
  5745. *
  5746. * @example
  5747. * $(document).ready(function() {
  5748. * var oTable = $('#example').dataTable();
  5749. *
  5750. * // Hide the second column after initialisation
  5751. * oTable.fnSetColumnVis( 1, false );
  5752. * } );
  5753. */
  5754. this.fnSetColumnVis = function ( iCol, bShow, bRedraw )
  5755. {
  5756. var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
  5757. var i, iLen;
  5758. var aoColumns = oSettings.aoColumns;
  5759. var aoData = oSettings.aoData;
  5760. var nTd, bAppend, iBefore;
  5761.  
  5762. /* No point in doing anything if we are requesting what is already true */
  5763. if ( aoColumns[iCol].bVisible == bShow )
  5764. {
  5765. return;
  5766. }
  5767.  
  5768. /* Show the column */
  5769. if ( bShow )
  5770. {
  5771. var iInsert = 0;
  5772. for ( i=0 ; i<iCol ; i++ )
  5773. {
  5774. if ( aoColumns[i].bVisible )
  5775. {
  5776. iInsert++;
  5777. }
  5778. }
  5779.  
  5780. /* Need to decide if we should use appendChild or insertBefore */
  5781. bAppend = (iInsert >= _fnVisbleColumns( oSettings ));
  5782.  
  5783. /* Which coloumn should we be inserting before? */
  5784. if ( !bAppend )
  5785. {
  5786. for ( i=iCol ; i<aoColumns.length ; i++ )
  5787. {
  5788. if ( aoColumns[i].bVisible )
  5789. {
  5790. iBefore = i;
  5791. break;
  5792. }
  5793. }
  5794. }
  5795.  
  5796. for ( i=0, iLen=aoData.length ; i<iLen ; i++ )
  5797. {
  5798. if ( aoData[i].nTr !== null )
  5799. {
  5800. if ( bAppend )
  5801. {
  5802. aoData[i].nTr.appendChild(
  5803. aoData[i]._anHidden[iCol]
  5804. );
  5805. }
  5806. else
  5807. {
  5808. aoData[i].nTr.insertBefore(
  5809. aoData[i]._anHidden[iCol],
  5810. _fnGetTdNodes( oSettings, i )[iBefore] );
  5811. }
  5812. }
  5813. }
  5814. }
  5815. else
  5816. {
  5817. /* Remove a column from display */
  5818. for ( i=0, iLen=aoData.length ; i<iLen ; i++ )
  5819. {
  5820. if ( aoData[i].nTr !== null )
  5821. {
  5822. nTd = _fnGetTdNodes( oSettings, i )[iCol];
  5823. aoData[i]._anHidden[iCol] = nTd;
  5824. nTd.parentNode.removeChild( nTd );
  5825. }
  5826. }
  5827. }
  5828.  
  5829. /* Clear to set the visible flag */
  5830. aoColumns[iCol].bVisible = bShow;
  5831.  
  5832. /* Redraw the header and footer based on the new column visibility */
  5833. _fnDrawHead( oSettings, oSettings.aoHeader );
  5834. if ( oSettings.nTFoot )
  5835. {
  5836. _fnDrawHead( oSettings, oSettings.aoFooter );
  5837. }
  5838.  
  5839. /* If there are any 'open' rows, then we need to alter the colspan for this col change */
  5840. for ( i=0, iLen=oSettings.aoOpenRows.length ; i<iLen ; i++ )
  5841. {
  5842. oSettings.aoOpenRows[i].nTr.colSpan = _fnVisbleColumns( oSettings );
  5843. }
  5844.  
  5845. /* Do a redraw incase anything depending on the table columns needs it
  5846. * (built-in: scrolling)
  5847. */
  5848. if ( bRedraw === undefined || bRedraw )
  5849. {
  5850. _fnAdjustColumnSizing( oSettings );
  5851. _fnDraw( oSettings );
  5852. }
  5853.  
  5854. _fnSaveState( oSettings );
  5855. };
  5856.  
  5857.  
  5858. /**
  5859. * Get the settings for a particular table for external manipulation
  5860. * @returns {object} DataTables settings object. See
  5861. * {@link DataTable.models.oSettings}
  5862. * @dtopt API
  5863. *
  5864. * @example
  5865. * $(document).ready(function() {
  5866. * var oTable = $('#example').dataTable();
  5867. * var oSettings = oTable.fnSettings();
  5868. *
  5869. * // Show an example parameter from the settings
  5870. * alert( oSettings._iDisplayStart );
  5871. * } );
  5872. */
  5873. this.fnSettings = function()
  5874. {
  5875. return _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
  5876. };
  5877.  
  5878.  
  5879. /**
  5880. * Sort the table by a particular column
  5881. * @param {int} iCol the data index to sort on. Note that this will not match the
  5882. * 'display index' if you have hidden data entries
  5883. * @dtopt API
  5884. *
  5885. * @example
  5886. * $(document).ready(function() {
  5887. * var oTable = $('#example').dataTable();
  5888. *
  5889. * // Sort immediately with columns 0 and 1
  5890. * oTable.fnSort( [ [0,'asc'], [1,'asc'] ] );
  5891. * } );
  5892. */
  5893. this.fnSort = function( aaSort )
  5894. {
  5895. var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
  5896. oSettings.aaSorting = aaSort;
  5897. _fnSort( oSettings );
  5898. };
  5899.  
  5900.  
  5901. /**
  5902. * Attach a sort listener to an element for a given column
  5903. * @param {node} nNode the element to attach the sort listener to
  5904. * @param {int} iColumn the column that a click on this node will sort on
  5905. * @param {function} [fnCallback] callback function when sort is run
  5906. * @dtopt API
  5907. *
  5908. * @example
  5909. * $(document).ready(function() {
  5910. * var oTable = $('#example').dataTable();
  5911. *
  5912. * // Sort on column 1, when 'sorter' is clicked on
  5913. * oTable.fnSortListener( document.getElementById('sorter'), 1 );
  5914. * } );
  5915. */
  5916. this.fnSortListener = function( nNode, iColumn, fnCallback )
  5917. {
  5918. _fnSortAttachListener( _fnSettingsFromNode( this[DataTable.ext.iApiIndex] ), nNode, iColumn,
  5919. fnCallback );
  5920. };
  5921.  
  5922.  
  5923. /**
  5924. * Update a table cell or row - this method will accept either a single value to
  5925. * update the cell with, an array of values with one element for each column or
  5926. * an object in the same format as the original data source. The function is
  5927. * self-referencing in order to make the multi column updates easier.
  5928. * @param {object|array|string} mData Data to update the cell/row with
  5929. * @param {node|int} mRow TR element you want to update or the aoData index
  5930. * @param {int} [iColumn] The column to update (not used of mData is an array or object)
  5931. * @param {bool} [bRedraw=true] Redraw the table or not
  5932. * @param {bool} [bAction=true] Perform predraw actions or not
  5933. * @returns {int} 0 on success, 1 on error
  5934. * @dtopt API
  5935. *
  5936. * @example
  5937. * $(document).ready(function() {
  5938. * var oTable = $('#example').dataTable();
  5939. * oTable.fnUpdate( 'Example update', 0, 0 ); // Single cell
  5940. * oTable.fnUpdate( ['a', 'b', 'c', 'd', 'e'], 1, 0 ); // Row
  5941. * } );
  5942. */
  5943. this.fnUpdate = function( mData, mRow, iColumn, bRedraw, bAction )
  5944. {
  5945. var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
  5946. var i, iLen, sDisplay;
  5947. var iRow = (typeof mRow === 'object') ?
  5948. _fnNodeToDataIndex(oSettings, mRow) : mRow;
  5949.  
  5950. if ( oSettings.__fnUpdateDeep === undefined && $.isArray(mData) && typeof mData === 'object' )
  5951. {
  5952. /* Array update - update the whole row */
  5953. oSettings.aoData[iRow]._aData = mData.slice();
  5954.  
  5955. /* Flag to the function that we are recursing */
  5956. oSettings.__fnUpdateDeep = true;
  5957. for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
  5958. {
  5959. this.fnUpdate( _fnGetCellData( oSettings, iRow, i ), iRow, i, false, false );
  5960. }
  5961. oSettings.__fnUpdateDeep = undefined;
  5962. }
  5963. else if ( oSettings.__fnUpdateDeep === undefined && mData !== null && typeof mData === 'object' )
  5964. {
  5965. /* Object update - update the whole row - assume the developer gets the object right */
  5966. oSettings.aoData[iRow]._aData = $.extend( true, {}, mData );
  5967.  
  5968. oSettings.__fnUpdateDeep = true;
  5969. for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
  5970. {
  5971. this.fnUpdate( _fnGetCellData( oSettings, iRow, i ), iRow, i, false, false );
  5972. }
  5973. oSettings.__fnUpdateDeep = undefined;
  5974. }
  5975. else
  5976. {
  5977. /* Individual cell update */
  5978. _fnSetCellData( oSettings, iRow, iColumn, mData );
  5979. sDisplay = _fnGetCellData( oSettings, iRow, iColumn, 'display' );
  5980.  
  5981. var oCol = oSettings.aoColumns[iColumn];
  5982. if ( oCol.fnRender !== null )
  5983. {
  5984. sDisplay = _fnRender( oSettings, iRow, iColumn );
  5985. if ( oCol.bUseRendered )
  5986. {
  5987. _fnSetCellData( oSettings, iRow, iColumn, sDisplay );
  5988. }
  5989. }
  5990.  
  5991. if ( oSettings.aoData[iRow].nTr !== null )
  5992. {
  5993. /* Do the actual HTML update */
  5994. _fnGetTdNodes( oSettings, iRow )[iColumn].innerHTML = sDisplay;
  5995. }
  5996. }
  5997.  
  5998. /* Modify the search index for this row (strictly this is likely not needed, since fnReDraw
  5999. * will rebuild the search array - however, the redraw might be disabled by the user)
  6000. */
  6001. var iDisplayIndex = $.inArray( iRow, oSettings.aiDisplay );
  6002. oSettings.asDataSearch[iDisplayIndex] = _fnBuildSearchRow( oSettings,
  6003. _fnGetRowData( oSettings, iRow, 'filter' ) );
  6004.  
  6005. /* Perform pre-draw actions */
  6006. if ( bAction === undefined || bAction )
  6007. {
  6008. _fnAdjustColumnSizing( oSettings );
  6009. }
  6010.  
  6011. /* Redraw the table */
  6012. if ( bRedraw === undefined || bRedraw )
  6013. {
  6014. _fnReDraw( oSettings );
  6015. }
  6016. return 0;
  6017. };
  6018.  
  6019.  
  6020. /**
  6021. * Provide a common method for plug-ins to check the version of DataTables being used, in order
  6022. * to ensure compatibility.
  6023. * @param {string} sVersion Version string to check for, in the format "X.Y.Z". Note that the
  6024. * formats "X" and "X.Y" are also acceptable.
  6025. * @returns {boolean} true if this version of DataTables is greater or equal to the required
  6026. * version, or false if this version of DataTales is not suitable
  6027. * @method
  6028. * @dtopt API
  6029. *
  6030. * @example
  6031. * $(document).ready(function() {
  6032. * var oTable = $('#example').dataTable();
  6033. * alert( oTable.fnVersionCheck( '1.9.0' ) );
  6034. * } );
  6035. */
  6036. this.fnVersionCheck = DataTable.ext.fnVersionCheck;
  6037.  
  6038.  
  6039. /*
  6040. * This is really a good bit rubbish this method of exposing the internal methods
  6041. * publically... - To be fixed in 2.0 using methods on the prototype
  6042. */
  6043.  
  6044.  
  6045. /**
  6046. * Create a wrapper function for exporting an internal functions to an external API.
  6047. * @param {string} sFunc API function name
  6048. * @returns {function} wrapped function
  6049. * @memberof DataTable#oApi
  6050. */
  6051. function _fnExternApiFunc (sFunc)
  6052. {
  6053. return function() {
  6054. var aArgs = [_fnSettingsFromNode(this[DataTable.ext.iApiIndex])].concat(
  6055. Array.prototype.slice.call(arguments) );
  6056. return DataTable.ext.oApi[sFunc].apply( this, aArgs );
  6057. };
  6058. }
  6059.  
  6060.  
  6061. /**
  6062. * Reference to internal functions for use by plug-in developers. Note that these
  6063. * methods are references to internal functions and are considered to be private.
  6064. * If you use these methods, be aware that they are liable to change between versions
  6065. * (check the upgrade notes).
  6066. * @namespace
  6067. */
  6068. this.oApi = {
  6069. "_fnExternApiFunc": _fnExternApiFunc,
  6070. "_fnInitialise": _fnInitialise,
  6071. "_fnInitComplete": _fnInitComplete,
  6072. "_fnLanguageCompat": _fnLanguageCompat,
  6073. "_fnAddColumn": _fnAddColumn,
  6074. "_fnColumnOptions": _fnColumnOptions,
  6075. "_fnAddData": _fnAddData,
  6076. "_fnCreateTr": _fnCreateTr,
  6077. "_fnGatherData": _fnGatherData,
  6078. "_fnBuildHead": _fnBuildHead,
  6079. "_fnDrawHead": _fnDrawHead,
  6080. "_fnDraw": _fnDraw,
  6081. "_fnReDraw": _fnReDraw,
  6082. "_fnAjaxUpdate": _fnAjaxUpdate,
  6083. "_fnAjaxParameters": _fnAjaxParameters,
  6084. "_fnAjaxUpdateDraw": _fnAjaxUpdateDraw,
  6085. "_fnServerParams": _fnServerParams,
  6086. "_fnAddOptionsHtml": _fnAddOptionsHtml,
  6087. "_fnFeatureHtmlTable": _fnFeatureHtmlTable,
  6088. "_fnScrollDraw": _fnScrollDraw,
  6089. "_fnAdjustColumnSizing": _fnAdjustColumnSizing,
  6090. "_fnFeatureHtmlFilter": _fnFeatureHtmlFilter,
  6091. "_fnFilterComplete": _fnFilterComplete,
  6092. "_fnFilterCustom": _fnFilterCustom,
  6093. "_fnFilterColumn": _fnFilterColumn,
  6094. "_fnFilter": _fnFilter,
  6095. "_fnBuildSearchArray": _fnBuildSearchArray,
  6096. "_fnBuildSearchRow": _fnBuildSearchRow,
  6097. "_fnFilterCreateSearch": _fnFilterCreateSearch,
  6098. "_fnDataToSearch": _fnDataToSearch,
  6099. "_fnSort": _fnSort,
  6100. "_fnSortAttachListener": _fnSortAttachListener,
  6101. "_fnSortingClasses": _fnSortingClasses,
  6102. "_fnFeatureHtmlPaginate": _fnFeatureHtmlPaginate,
  6103. "_fnPageChange": _fnPageChange,
  6104. "_fnFeatureHtmlInfo": _fnFeatureHtmlInfo,
  6105. "_fnUpdateInfo": _fnUpdateInfo,
  6106. "_fnFeatureHtmlLength": _fnFeatureHtmlLength,
  6107. "_fnFeatureHtmlProcessing": _fnFeatureHtmlProcessing,
  6108. "_fnProcessingDisplay": _fnProcessingDisplay,
  6109. "_fnVisibleToColumnIndex": _fnVisibleToColumnIndex,
  6110. "_fnColumnIndexToVisible": _fnColumnIndexToVisible,
  6111. "_fnNodeToDataIndex": _fnNodeToDataIndex,
  6112. "_fnVisbleColumns": _fnVisbleColumns,
  6113. "_fnCalculateEnd": _fnCalculateEnd,
  6114. "_fnConvertToWidth": _fnConvertToWidth,
  6115. "_fnCalculateColumnWidths": _fnCalculateColumnWidths,
  6116. "_fnScrollingWidthAdjust": _fnScrollingWidthAdjust,
  6117. "_fnGetWidestNode": _fnGetWidestNode,
  6118. "_fnGetMaxLenString": _fnGetMaxLenString,
  6119. "_fnStringToCss": _fnStringToCss,
  6120. "_fnDetectType": _fnDetectType,
  6121. "_fnSettingsFromNode": _fnSettingsFromNode,
  6122. "_fnGetDataMaster": _fnGetDataMaster,
  6123. "_fnGetTrNodes": _fnGetTrNodes,
  6124. "_fnGetTdNodes": _fnGetTdNodes,
  6125. "_fnEscapeRegex": _fnEscapeRegex,
  6126. "_fnDeleteIndex": _fnDeleteIndex,
  6127. "_fnReOrderIndex": _fnReOrderIndex,
  6128. "_fnColumnOrdering": _fnColumnOrdering,
  6129. "_fnLog": _fnLog,
  6130. "_fnClearTable": _fnClearTable,
  6131. "_fnSaveState": _fnSaveState,
  6132. "_fnLoadState": _fnLoadState,
  6133. "_fnCreateCookie": _fnCreateCookie,
  6134. "_fnReadCookie": _fnReadCookie,
  6135. "_fnDetectHeader": _fnDetectHeader,
  6136. "_fnGetUniqueThs": _fnGetUniqueThs,
  6137. "_fnScrollBarWidth": _fnScrollBarWidth,
  6138. "_fnApplyToChildren": _fnApplyToChildren,
  6139. "_fnMap": _fnMap,
  6140. "_fnGetRowData": _fnGetRowData,
  6141. "_fnGetCellData": _fnGetCellData,
  6142. "_fnSetCellData": _fnSetCellData,
  6143. "_fnGetObjectDataFn": _fnGetObjectDataFn,
  6144. "_fnSetObjectDataFn": _fnSetObjectDataFn,
  6145. "_fnApplyColumnDefs": _fnApplyColumnDefs,
  6146. "_fnBindAction": _fnBindAction,
  6147. "_fnExtend": _fnExtend,
  6148. "_fnCallbackReg": _fnCallbackReg,
  6149. "_fnCallbackFire": _fnCallbackFire,
  6150. "_fnJsonString": _fnJsonString,
  6151. "_fnRender": _fnRender,
  6152. "_fnNodeToColumnIndex": _fnNodeToColumnIndex,
  6153. "_fnInfoMacros": _fnInfoMacros
  6154. };
  6155.  
  6156. $.extend( DataTable.ext.oApi, this.oApi );
  6157.  
  6158. for ( var sFunc in DataTable.ext.oApi )
  6159. {
  6160. if ( sFunc )
  6161. {
  6162. this[sFunc] = _fnExternApiFunc(sFunc);
  6163. }
  6164. }
  6165.  
  6166.  
  6167. var _that = this;
  6168. return this.each(function() {
  6169.  
  6170. var i=0, iLen, j, jLen, k, kLen;
  6171. var sId = this.getAttribute( 'id' );
  6172. var bInitHandedOff = false;
  6173. var bUsePassedData = false;
  6174.  
  6175.  
  6176. /* Sanity check */
  6177. if ( this.nodeName.toLowerCase() != 'table' )
  6178. {
  6179. _fnLog( null, 0, "Attempted to initialise DataTables on a node which is not a "+
  6180. "table: "+this.nodeName );
  6181. return;
  6182. }
  6183.  
  6184. /* Check to see if we are re-initialising a table */
  6185. for ( i=0, iLen=DataTable.settings.length ; i<iLen ; i++ )
  6186. {
  6187. /* Base check on table node */
  6188. if ( DataTable.settings[i].nTable == this )
  6189. {
  6190. if ( oInit === undefined || oInit.bRetrieve )
  6191. {
  6192. return DataTable.settings[i].oInstance;
  6193. }
  6194. else if ( oInit.bDestroy )
  6195. {
  6196. DataTable.settings[i].oInstance.fnDestroy();
  6197. break;
  6198. }
  6199. else
  6200. {
  6201. _fnLog( DataTable.settings[i], 0, "Cannot reinitialise DataTable.\n\n"+
  6202. "To retrieve the DataTables object for this table, pass no arguments or see "+
  6203. "the docs for bRetrieve and bDestroy" );
  6204. return;
  6205. }
  6206. }
  6207.  
  6208. /* If the element we are initialising has the same ID as a table which was previously
  6209. * initialised, but the table nodes don't match (from before) then we destroy the old
  6210. * instance by simply deleting it. This is under the assumption that the table has been
  6211. * destroyed by other methods. Anyone using non-id selectors will need to do this manually
  6212. */
  6213. if ( DataTable.settings[i].sTableId == this.id )
  6214. {
  6215. DataTable.settings.splice( i, 1 );
  6216. break;
  6217. }
  6218. }
  6219.  
  6220. /* Ensure the table has an ID - required for accessibility */
  6221. if ( sId === null || sId === "" )
  6222. {
  6223. sId = "DataTables_Table_"+(DataTable.ext._oExternConfig.iNextUnique++);
  6224. this.id = sId;
  6225. }
  6226.  
  6227. /* Create the settings object for this table and set some of the default parameters */
  6228. var oSettings = $.extend( true, {}, DataTable.models.oSettings, {
  6229. "nTable": this,
  6230. "oApi": _that.oApi,
  6231. "oInit": oInit,
  6232. "sDestroyWidth": $(this).width(),
  6233. "sInstance": sId,
  6234. "sTableId": sId
  6235. } );
  6236. DataTable.settings.push( oSettings );
  6237.  
  6238. // Need to add the instance after the instance after the settings object has been added
  6239. // to the settings array, so we can self reference the table instance if more than one
  6240. oSettings.oInstance = (_that.length===1) ? _that : $(this).dataTable();
  6241.  
  6242. /* Setting up the initialisation object */
  6243. if ( !oInit )
  6244. {
  6245. oInit = {};
  6246. }
  6247.  
  6248. // Backwards compatibility, before we apply all the defaults
  6249. if ( oInit.oLanguage )
  6250. {
  6251. _fnLanguageCompat( oInit.oLanguage );
  6252. }
  6253.  
  6254. oInit = _fnExtend( $.extend(true, {}, DataTable.defaults), oInit );
  6255.  
  6256. // Map the initialisation options onto the settings object
  6257. _fnMap( oSettings.oFeatures, oInit, "bPaginate" );
  6258. _fnMap( oSettings.oFeatures, oInit, "bLengthChange" );
  6259. _fnMap( oSettings.oFeatures, oInit, "bFilter" );
  6260. _fnMap( oSettings.oFeatures, oInit, "bSort" );
  6261. _fnMap( oSettings.oFeatures, oInit, "bInfo" );
  6262. _fnMap( oSettings.oFeatures, oInit, "bProcessing" );
  6263. _fnMap( oSettings.oFeatures, oInit, "bAutoWidth" );
  6264. _fnMap( oSettings.oFeatures, oInit, "bSortClasses" );
  6265. _fnMap( oSettings.oFeatures, oInit, "bServerSide" );
  6266. _fnMap( oSettings.oFeatures, oInit, "bDeferRender" );
  6267. _fnMap( oSettings.oScroll, oInit, "sScrollX", "sX" );
  6268. _fnMap( oSettings.oScroll, oInit, "sScrollXInner", "sXInner" );
  6269. _fnMap( oSettings.oScroll, oInit, "sScrollY", "sY" );
  6270. _fnMap( oSettings.oScroll, oInit, "bScrollCollapse", "bCollapse" );
  6271. _fnMap( oSettings.oScroll, oInit, "bScrollInfinite", "bInfinite" );
  6272. _fnMap( oSettings.oScroll, oInit, "iScrollLoadGap", "iLoadGap" );
  6273. _fnMap( oSettings.oScroll, oInit, "bScrollAutoCss", "bAutoCss" );
  6274. _fnMap( oSettings, oInit, "asStripeClasses" );
  6275. _fnMap( oSettings, oInit, "asStripClasses", "asStripeClasses" ); // legacy
  6276. _fnMap( oSettings, oInit, "fnServerData" );
  6277. _fnMap( oSettings, oInit, "fnFormatNumber" );
  6278. _fnMap( oSettings, oInit, "sServerMethod" );
  6279. _fnMap( oSettings, oInit, "aaSorting" );
  6280. _fnMap( oSettings, oInit, "aaSortingFixed" );
  6281. _fnMap( oSettings, oInit, "aLengthMenu" );
  6282. _fnMap( oSettings, oInit, "sPaginationType" );
  6283. _fnMap( oSettings, oInit, "sAjaxSource" );
  6284. _fnMap( oSettings, oInit, "sAjaxDataProp" );
  6285. _fnMap( oSettings, oInit, "iCookieDuration" );
  6286. _fnMap( oSettings, oInit, "sCookiePrefix" );
  6287. _fnMap( oSettings, oInit, "sDom" );
  6288. _fnMap( oSettings, oInit, "bSortCellsTop" );
  6289. _fnMap( oSettings, oInit, "iTabIndex" );
  6290. _fnMap( oSettings, oInit, "oSearch", "oPreviousSearch" );
  6291. _fnMap( oSettings, oInit, "aoSearchCols", "aoPreSearchCols" );
  6292. _fnMap( oSettings, oInit, "iDisplayLength", "_iDisplayLength" );
  6293. _fnMap( oSettings, oInit, "bJQueryUI", "bJUI" );
  6294. _fnMap( oSettings, oInit, "fnCookieCallback" );
  6295. _fnMap( oSettings, oInit, "fnStateLoad" );
  6296. _fnMap( oSettings, oInit, "fnStateSave" );
  6297. _fnMap( oSettings.oLanguage, oInit, "fnInfoCallback" );
  6298.  
  6299. /* Callback functions which are array driven */
  6300. _fnCallbackReg( oSettings, 'aoDrawCallback', oInit.fnDrawCallback, 'user' );
  6301. _fnCallbackReg( oSettings, 'aoServerParams', oInit.fnServerParams, 'user' );
  6302. _fnCallbackReg( oSettings, 'aoStateSaveParams', oInit.fnStateSaveParams, 'user' );
  6303. _fnCallbackReg( oSettings, 'aoStateLoadParams', oInit.fnStateLoadParams, 'user' );
  6304. _fnCallbackReg( oSettings, 'aoStateLoaded', oInit.fnStateLoaded, 'user' );
  6305. _fnCallbackReg( oSettings, 'aoRowCallback', oInit.fnRowCallback, 'user' );
  6306. _fnCallbackReg( oSettings, 'aoRowCreatedCallback', oInit.fnCreatedRow, 'user' );
  6307. _fnCallbackReg( oSettings, 'aoHeaderCallback', oInit.fnHeaderCallback, 'user' );
  6308. _fnCallbackReg( oSettings, 'aoFooterCallback', oInit.fnFooterCallback, 'user' );
  6309. _fnCallbackReg( oSettings, 'aoInitComplete', oInit.fnInitComplete, 'user' );
  6310. _fnCallbackReg( oSettings, 'aoPreDrawCallback', oInit.fnPreDrawCallback, 'user' );
  6311.  
  6312. if ( oSettings.oFeatures.bServerSide && oSettings.oFeatures.bSort &&
  6313. oSettings.oFeatures.bSortClasses )
  6314. {
  6315. /* Enable sort classes for server-side processing. Safe to do it here, since server-side
  6316. * processing must be enabled by the developer
  6317. */
  6318. _fnCallbackReg( oSettings, 'aoDrawCallback', _fnSortingClasses, 'server_side_sort_classes' );
  6319. }
  6320. else if ( oSettings.oFeatures.bDeferRender )
  6321. {
  6322. _fnCallbackReg( oSettings, 'aoDrawCallback', _fnSortingClasses, 'defer_sort_classes' );
  6323. }
  6324.  
  6325. if ( oInit.bJQueryUI )
  6326. {
  6327. /* Use the JUI classes object for display. You could clone the oStdClasses object if
  6328. * you want to have multiple tables with multiple independent classes
  6329. */
  6330. $.extend( oSettings.oClasses, DataTable.ext.oJUIClasses );
  6331.  
  6332. if ( oInit.sDom === DataTable.defaults.sDom && DataTable.defaults.sDom === "lfrtip" )
  6333. {
  6334. /* Set the DOM to use a layout suitable for jQuery UI's theming */
  6335. oSettings.sDom = '<"H"lfr>t<"F"ip>';
  6336. }
  6337. }
  6338. else
  6339. {
  6340. $.extend( oSettings.oClasses, DataTable.ext.oStdClasses );
  6341. }
  6342. $(this).addClass( oSettings.oClasses.sTable );
  6343.  
  6344. /* Calculate the scroll bar width and cache it for use later on */
  6345. if ( oSettings.oScroll.sX !== "" || oSettings.oScroll.sY !== "" )
  6346. {
  6347. oSettings.oScroll.iBarWidth = _fnScrollBarWidth();
  6348. }
  6349.  
  6350. if ( oSettings.iInitDisplayStart === undefined )
  6351. {
  6352. /* Display start point, taking into account the save saving */
  6353. oSettings.iInitDisplayStart = oInit.iDisplayStart;
  6354. oSettings._iDisplayStart = oInit.iDisplayStart;
  6355. }
  6356.  
  6357. /* Must be done after everything which can be overridden by a cookie! */
  6358. if ( oInit.bStateSave )
  6359. {
  6360. oSettings.oFeatures.bStateSave = true;
  6361. _fnLoadState( oSettings, oInit );
  6362. _fnCallbackReg( oSettings, 'aoDrawCallback', _fnSaveState, 'state_save' );
  6363. }
  6364.  
  6365. if ( oInit.iDeferLoading !== null )
  6366. {
  6367. oSettings.bDeferLoading = true;
  6368. var tmp = $.isArray( oInit.iDeferLoading );
  6369. oSettings._iRecordsDisplay = tmp ? oInit.iDeferLoading[0] : oInit.iDeferLoading;
  6370. oSettings._iRecordsTotal = tmp ? oInit.iDeferLoading[1] : oInit.iDeferLoading;
  6371. }
  6372.  
  6373. if ( oInit.aaData !== null )
  6374. {
  6375. bUsePassedData = true;
  6376. }
  6377.  
  6378. /* Language definitions */
  6379. if ( oInit.oLanguage.sUrl !== "" )
  6380. {
  6381. /* Get the language definitions from a file - because this Ajax call makes the language
  6382. * get async to the remainder of this function we use bInitHandedOff to indicate that
  6383. * _fnInitialise will be fired by the returned Ajax handler, rather than the constructor
  6384. */
  6385. oSettings.oLanguage.sUrl = oInit.oLanguage.sUrl;
  6386. $.getJSON( oSettings.oLanguage.sUrl, null, function( json ) {
  6387. _fnLanguageCompat( json );
  6388. $.extend( true, oSettings.oLanguage, oInit.oLanguage, json );
  6389. _fnInitialise( oSettings );
  6390. } );
  6391. bInitHandedOff = true;
  6392. }
  6393. else
  6394. {
  6395. $.extend( true, oSettings.oLanguage, oInit.oLanguage );
  6396. }
  6397.  
  6398.  
  6399. /*
  6400. * Stripes
  6401. */
  6402. if ( oInit.asStripeClasses === null )
  6403. {
  6404. oSettings.asStripeClasses =[
  6405. oSettings.oClasses.sStripeOdd,
  6406. oSettings.oClasses.sStripeEven
  6407. ];
  6408. }
  6409.  
  6410. /* Remove row stripe classes if they are already on the table row */
  6411. var bStripeRemove = false;
  6412. var anRows = $(this).children('tbody').children('tr');
  6413. for ( i=0, iLen=oSettings.asStripeClasses.length ; i<iLen ; i++ )
  6414. {
  6415. if ( anRows.filter(":lt(2)").hasClass( oSettings.asStripeClasses[i]) )
  6416. {
  6417. bStripeRemove = true;
  6418. break;
  6419. }
  6420. }
  6421.  
  6422. if ( bStripeRemove )
  6423. {
  6424. /* Store the classes which we are about to remove so they can be readded on destroy */
  6425. oSettings.asDestroyStripes = [ '', '' ];
  6426. if ( $(anRows[0]).hasClass(oSettings.oClasses.sStripeOdd) )
  6427. {
  6428. oSettings.asDestroyStripes[0] += oSettings.oClasses.sStripeOdd+" ";
  6429. }
  6430. if ( $(anRows[0]).hasClass(oSettings.oClasses.sStripeEven) )
  6431. {
  6432. oSettings.asDestroyStripes[0] += oSettings.oClasses.sStripeEven;
  6433. }
  6434. if ( $(anRows[1]).hasClass(oSettings.oClasses.sStripeOdd) )
  6435. {
  6436. oSettings.asDestroyStripes[1] += oSettings.oClasses.sStripeOdd+" ";
  6437. }
  6438. if ( $(anRows[1]).hasClass(oSettings.oClasses.sStripeEven) )
  6439. {
  6440. oSettings.asDestroyStripes[1] += oSettings.oClasses.sStripeEven;
  6441. }
  6442.  
  6443. anRows.removeClass( oSettings.asStripeClasses.join(' ') );
  6444. }
  6445.  
  6446.  
  6447. /*
  6448. * Columns
  6449. * See if we should load columns automatically or use defined ones
  6450. */
  6451. var anThs = [];
  6452. var aoColumnsInit;
  6453. var nThead = this.getElementsByTagName('thead');
  6454. if ( nThead.length !== 0 )
  6455. {
  6456. _fnDetectHeader( oSettings.aoHeader, nThead[0] );
  6457. anThs = _fnGetUniqueThs( oSettings );
  6458. }
  6459.  
  6460. /* If not given a column array, generate one with nulls */
  6461. if ( oInit.aoColumns === null )
  6462. {
  6463. aoColumnsInit = [];
  6464. for ( i=0, iLen=anThs.length ; i<iLen ; i++ )
  6465. {
  6466. aoColumnsInit.push( null );
  6467. }
  6468. }
  6469. else
  6470. {
  6471. aoColumnsInit = oInit.aoColumns;
  6472. }
  6473.  
  6474. /* Add the columns */
  6475. for ( i=0, iLen=aoColumnsInit.length ; i<iLen ; i++ )
  6476. {
  6477. /* Short cut - use the loop to check if we have column visibility state to restore */
  6478. if ( oInit.saved_aoColumns !== undefined && oInit.saved_aoColumns.length == iLen )
  6479. {
  6480. if ( aoColumnsInit[i] === null )
  6481. {
  6482. aoColumnsInit[i] = {};
  6483. }
  6484. aoColumnsInit[i].bVisible = oInit.saved_aoColumns[i].bVisible;
  6485. }
  6486.  
  6487. _fnAddColumn( oSettings, anThs ? anThs[i] : null );
  6488. }
  6489.  
  6490. /* Apply the column definitions */
  6491. _fnApplyColumnDefs( oSettings, oInit.aoColumnDefs, aoColumnsInit, function (iCol, oDef) {
  6492. _fnColumnOptions( oSettings, iCol, oDef );
  6493. } );
  6494.  
  6495.  
  6496. /*
  6497. * Sorting
  6498. * Check the aaSorting array
  6499. */
  6500. for ( i=0, iLen=oSettings.aaSorting.length ; i<iLen ; i++ )
  6501. {
  6502. if ( oSettings.aaSorting[i][0] >= oSettings.aoColumns.length )
  6503. {
  6504. oSettings.aaSorting[i][0] = 0;
  6505. }
  6506. var oColumn = oSettings.aoColumns[ oSettings.aaSorting[i][0] ];
  6507.  
  6508. /* Add a default sorting index */
  6509. if ( oSettings.aaSorting[i][2] === undefined )
  6510. {
  6511. oSettings.aaSorting[i][2] = 0;
  6512. }
  6513.  
  6514. /* If aaSorting is not defined, then we use the first indicator in asSorting */
  6515. if ( oInit.aaSorting === undefined && oSettings.saved_aaSorting === undefined )
  6516. {
  6517. oSettings.aaSorting[i][1] = oColumn.asSorting[0];
  6518. }
  6519.  
  6520. /* Set the current sorting index based on aoColumns.asSorting */
  6521. for ( j=0, jLen=oColumn.asSorting.length ; j<jLen ; j++ )
  6522. {
  6523. if ( oSettings.aaSorting[i][1] == oColumn.asSorting[j] )
  6524. {
  6525. oSettings.aaSorting[i][2] = j;
  6526. break;
  6527. }
  6528. }
  6529. }
  6530.  
  6531. /* Do a first pass on the sorting classes (allows any size changes to be taken into
  6532. * account, and also will apply sorting disabled classes if disabled
  6533. */
  6534. _fnSortingClasses( oSettings );
  6535.  
  6536.  
  6537. /*
  6538. * Final init
  6539. * Cache the header, body and footer as required, creating them if needed
  6540. */
  6541.  
  6542. // Work around for Webkit bug 83867 - store the caption-side before removing from doc
  6543. var captions = $(this).children('caption').each( function () {
  6544. this._captionSide = $(this).css('caption-side');
  6545. } );
  6546.  
  6547. var thead = $(this).children('thead');
  6548. if ( thead.length === 0 )
  6549. {
  6550. thead = [ document.createElement( 'thead' ) ];
  6551. this.appendChild( thead[0] );
  6552. }
  6553. oSettings.nTHead = thead[0];
  6554.  
  6555. var tbody = $(this).children('tbody');
  6556. if ( tbody.length === 0 )
  6557. {
  6558. tbody = [ document.createElement( 'tbody' ) ];
  6559. this.appendChild( tbody[0] );
  6560. }
  6561. oSettings.nTBody = tbody[0];
  6562. oSettings.nTBody.setAttribute( "role", "alert" );
  6563. oSettings.nTBody.setAttribute( "aria-live", "polite" );
  6564. oSettings.nTBody.setAttribute( "aria-relevant", "all" );
  6565.  
  6566. var tfoot = $(this).children('tfoot');
  6567. if ( tfoot.length === 0 && captions.length > 0 && (oSettings.oScroll.sX !== "" || oSettings.oScroll.sY !== "") )
  6568. {
  6569. // If we are a scrolling table, and no footer has been given, then we need to create
  6570. // a tfoot element for the caption element to be appended to
  6571. tfoot = [ document.createElement( 'tfoot' ) ];
  6572. this.appendChild( tfoot[0] );
  6573. }
  6574.  
  6575. if ( tfoot.length > 0 )
  6576. {
  6577. oSettings.nTFoot = tfoot[0];
  6578. _fnDetectHeader( oSettings.aoFooter, oSettings.nTFoot );
  6579. }
  6580.  
  6581. /* Check if there is data passing into the constructor */
  6582. if ( bUsePassedData )
  6583. {
  6584. for ( i=0 ; i<oInit.aaData.length ; i++ )
  6585. {
  6586. _fnAddData( oSettings, oInit.aaData[ i ] );
  6587. }
  6588. }
  6589. else
  6590. {
  6591. /* Grab the data from the page */
  6592. _fnGatherData( oSettings );
  6593. }
  6594.  
  6595. /* Copy the data index array */
  6596. oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
  6597.  
  6598. /* Initialisation complete - table can be drawn */
  6599. oSettings.bInitialised = true;
  6600.  
  6601. /* Check if we need to initialise the table (it might not have been handed off to the
  6602. * language processor)
  6603. */
  6604. if ( bInitHandedOff === false )
  6605. {
  6606. _fnInitialise( oSettings );
  6607. }
  6608. } );
  6609. };
  6610.  
  6611.  
  6612.  
  6613. /**
  6614. * Provide a common method for plug-ins to check the version of DataTables being used, in order
  6615. * to ensure compatibility.
  6616. * @param {string} sVersion Version string to check for, in the format "X.Y.Z". Note that the
  6617. * formats "X" and "X.Y" are also acceptable.
  6618. * @returns {boolean} true if this version of DataTables is greater or equal to the required
  6619. * version, or false if this version of DataTales is not suitable
  6620. * @static
  6621. * @dtopt API-Static
  6622. *
  6623. * @example
  6624. * alert( $.fn.dataTable.fnVersionCheck( '1.9.0' ) );
  6625. */
  6626. DataTable.fnVersionCheck = function( sVersion )
  6627. {
  6628. /* This is cheap, but effective */
  6629. var fnZPad = function (Zpad, count)
  6630. {
  6631. while(Zpad.length < count) {
  6632. Zpad += '0';
  6633. }
  6634. return Zpad;
  6635. };
  6636. var aThis = DataTable.ext.sVersion.split('.');
  6637. var aThat = sVersion.split('.');
  6638. var sThis = '', sThat = '';
  6639.  
  6640. for ( var i=0, iLen=aThat.length ; i<iLen ; i++ )
  6641. {
  6642. sThis += fnZPad( aThis[i], 3 );
  6643. sThat += fnZPad( aThat[i], 3 );
  6644. }
  6645.  
  6646. return parseInt(sThis, 10) >= parseInt(sThat, 10);
  6647. };
  6648.  
  6649.  
  6650. /**
  6651. * Check if a TABLE node is a DataTable table already or not.
  6652. * @param {node} nTable The TABLE node to check if it is a DataTable or not (note that other
  6653. * node types can be passed in, but will always return false).
  6654. * @returns {boolean} true the table given is a DataTable, or false otherwise
  6655. * @static
  6656. * @dtopt API-Static
  6657. *
  6658. * @example
  6659. * var ex = document.getElementById('example');
  6660. * if ( ! $.fn.DataTable.fnIsDataTable( ex ) ) {
  6661. * $(ex).dataTable();
  6662. * }
  6663. */
  6664. DataTable.fnIsDataTable = function ( nTable )
  6665. {
  6666. var o = DataTable.settings;
  6667.  
  6668. for ( var i=0 ; i<o.length ; i++ )
  6669. {
  6670. if ( o[i].nTable === nTable || o[i].nScrollHead === nTable || o[i].nScrollFoot === nTable )
  6671. {
  6672. return true;
  6673. }
  6674. }
  6675.  
  6676. return false;
  6677. };
  6678.  
  6679.  
  6680. /**
  6681. * Get all DataTable tables that have been initialised - optionally you can select to
  6682. * get only currently visible tables.
  6683. * @param {boolean} [bVisible=false] Flag to indicate if you want all (default) or
  6684. * visible tables only.
  6685. * @returns {array} Array of TABLE nodes (not DataTable instances) which are DataTables
  6686. * @static
  6687. * @dtopt API-Static
  6688. *
  6689. * @example
  6690. * var table = $.fn.dataTable.fnTables(true);
  6691. * if ( table.length > 0 ) {
  6692. * $(table).dataTable().fnAdjustColumnSizing();
  6693. * }
  6694. */
  6695. DataTable.fnTables = function ( bVisible )
  6696. {
  6697. var out = [];
  6698.  
  6699. jQuery.each( DataTable.settings, function (i, o) {
  6700. if ( !bVisible || (bVisible === true && $(o.nTable).is(':visible')) )
  6701. {
  6702. out.push( o.nTable );
  6703. }
  6704. } );
  6705.  
  6706. return out;
  6707. };
  6708.  
  6709.  
  6710. /**
  6711. * Version string for plug-ins to check compatibility. Allowed format is
  6712. * a.b.c.d.e where: a:int, b:int, c:int, d:string(dev|beta), e:int. d and
  6713. * e are optional
  6714. * @member
  6715. * @type string
  6716. * @default Version number
  6717. */
  6718. DataTable.version = "1.9.1";
  6719.  
  6720. /**
  6721. * Private data store, containing all of the settings objects that are created for the
  6722. * tables on a given page.
  6723. *
  6724. * Note that the <i>DataTable.settings</i> object is aliased to <i>jQuery.fn.dataTableExt</i>
  6725. * through which it may be accessed and manipulated, or <i>jQuery.fn.dataTable.settings</i>.
  6726. * @member
  6727. * @type array
  6728. * @default []
  6729. * @private
  6730. */
  6731. DataTable.settings = [];
  6732.  
  6733. /**
  6734. * Object models container, for the various models that DataTables has available
  6735. * to it. These models define the objects that are used to hold the active state
  6736. * and configuration of the table.
  6737. * @namespace
  6738. */
  6739. DataTable.models = {};
  6740.  
  6741.  
  6742. /**
  6743. * DataTables extension options and plug-ins. This namespace acts as a collection "area"
  6744. * for plug-ins that can be used to extend the default DataTables behaviour - indeed many
  6745. * of the build in methods use this method to provide their own capabilities (sorting methods
  6746. * for example).
  6747. *
  6748. * Note that this namespace is aliased to jQuery.fn.dataTableExt so it can be readily accessed
  6749. * and modified by plug-ins.
  6750. * @namespace
  6751. */
  6752. DataTable.models.ext = {
  6753. /**
  6754. * Plug-in filtering functions - this method of filtering is complimentary to the default
  6755. * type based filtering, and a lot more comprehensive as it allows you complete control
  6756. * over the filtering logic. Each element in this array is a function (parameters
  6757. * described below) that is called for every row in the table, and your logic decides if
  6758. * it should be included in the filtered data set or not.
  6759. * <ul>
  6760. * <li>
  6761. * Function input parameters:
  6762. * <ul>
  6763. * <li>{object} DataTables settings object: see {@link DataTable.models.oSettings}.</li>
  6764. * <li>{array|object} Data for the row to be processed (same as the original format
  6765. * that was passed in as the data source, or an array from a DOM data source</li>
  6766. * <li>{int} Row index in aoData ({@link DataTable.models.oSettings.aoData}), which can
  6767. * be useful to retrieve the TR element if you need DOM interaction.</li>
  6768. * </ul>
  6769. * </li>
  6770. * <li>
  6771. * Function return:
  6772. * <ul>
  6773. * <li>{boolean} Include the row in the filtered result set (true) or not (false)</li>
  6774. * </ul>
  6775. * </il>
  6776. * </ul>
  6777. * @type array
  6778. * @default []
  6779. *
  6780. * @example
  6781. * // The following example shows custom filtering being applied to the fourth column (i.e.
  6782. * // the aData[3] index) based on two input values from the end-user, matching the data in
  6783. * // a certain range.
  6784. * $.fn.dataTableExt.afnFiltering.push(
  6785. * function( oSettings, aData, iDataIndex ) {
  6786. * var iMin = document.getElementById('min').value * 1;
  6787. * var iMax = document.getElementById('max').value * 1;
  6788. * var iVersion = aData[3] == "-" ? 0 : aData[3]*1;
  6789. * if ( iMin == "" && iMax == "" ) {
  6790. * return true;
  6791. * }
  6792. * else if ( iMin == "" && iVersion < iMax ) {
  6793. * return true;
  6794. * }
  6795. * else if ( iMin < iVersion && "" == iMax ) {
  6796. * return true;
  6797. * }
  6798. * else if ( iMin < iVersion && iVersion < iMax ) {
  6799. * return true;
  6800. * }
  6801. * return false;
  6802. * }
  6803. * );
  6804. */
  6805. "afnFiltering": [],
  6806.  
  6807.  
  6808. /**
  6809. * Plug-in sorting functions - this method of sorting is complimentary to the default type
  6810. * based sorting that DataTables does automatically, allowing much greater control over the
  6811. * the data that is being used to sort a column. This is useful if you want to do sorting
  6812. * based on live data (for example the contents of an 'input' element) rather than just the
  6813. * static string that DataTables knows of. The way these plug-ins work is that you create
  6814. * an array of the values you wish to be sorted for the column in question and then return
  6815. * that array. Which pre-sorting function is run here depends on the sSortDataType parameter
  6816. * that is used for the column (if any). This is the corollary of <i>ofnSearch</i> for sort
  6817. * data.
  6818. * <ul>
  6819. * <li>
  6820. * Function input parameters:
  6821. * <ul>
  6822. * <li>{object} DataTables settings object: see {@link DataTable.models.oSettings}.</li>
  6823. * <li>{int} Target column index</li>
  6824. * </ul>
  6825. * </li>
  6826. * <li>
  6827. * Function return:
  6828. * <ul>
  6829. * <li>{array} Data for the column to be sorted upon</li>
  6830. * </ul>
  6831. * </il>
  6832. * </ul>
  6833. *
  6834. * Note that as of v1.9, it is typically preferable to use <i>mDataProp</i> to prepare data for
  6835. * the different uses that DataTables can put the data to. Specifically <i>mDataProp</i> when
  6836. * used as a function will give you a 'type' (sorting, filtering etc) that you can use to
  6837. * prepare the data as required for the different types. As such, this method is deprecated.
  6838. * @type array
  6839. * @default []
  6840. * @deprecated
  6841. *
  6842. * @example
  6843. * // Updating the cached sorting information with user entered values in HTML input elements
  6844. * jQuery.fn.dataTableExt.afnSortData['dom-text'] = function ( oSettings, iColumn )
  6845. * {
  6846. * var aData = [];
  6847. * $( 'td:eq('+iColumn+') input', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
  6848. * aData.push( this.value );
  6849. * } );
  6850. * return aData;
  6851. * }
  6852. */
  6853. "afnSortData": [],
  6854.  
  6855.  
  6856. /**
  6857. * Feature plug-ins - This is an array of objects which describe the feature plug-ins that are
  6858. * available to DataTables. These feature plug-ins are accessible through the sDom initialisation
  6859. * option. As such, each feature plug-in must describe a function that is used to initialise
  6860. * itself (fnInit), a character so the feature can be enabled by sDom (cFeature) and the name
  6861. * of the feature (sFeature). Thus the objects attached to this method must provide:
  6862. * <ul>
  6863. * <li>{function} fnInit Initialisation of the plug-in
  6864. * <ul>
  6865. * <li>
  6866. * Function input parameters:
  6867. * <ul>
  6868. * <li>{object} DataTables settings object: see {@link DataTable.models.oSettings}.</li>
  6869. * </ul>
  6870. * </li>
  6871. * <li>
  6872. * Function return:
  6873. * <ul>
  6874. * <li>{node|null} The element which contains your feature. Note that the return
  6875. * may also be void if your plug-in does not require to inject any DOM elements
  6876. * into DataTables control (sDom) - for example this might be useful when
  6877. * developing a plug-in which allows table control via keyboard entry.</li>
  6878. * </ul>
  6879. * </il>
  6880. * </ul>
  6881. * </li>
  6882. * <li>{character} cFeature Character that will be matched in sDom - case sensitive</li>
  6883. * <li>{string} sFeature Feature name</li>
  6884. * </ul>
  6885. * @type array
  6886. * @default []
  6887. *
  6888. * @example
  6889. * // How TableTools initialises itself.
  6890. * $.fn.dataTableExt.aoFeatures.push( {
  6891. * "fnInit": function( oSettings ) {
  6892. * return new TableTools( { "oDTSettings": oSettings } );
  6893. * },
  6894. * "cFeature": "T",
  6895. * "sFeature": "TableTools"
  6896. * } );
  6897. */
  6898. "aoFeatures": [],
  6899.  
  6900.  
  6901. /**
  6902. * Type detection plug-in functions - DataTables utilises types to define how sorting and
  6903. * filtering behave, and types can be either be defined by the developer (sType for the
  6904. * column) or they can be automatically detected by the methods in this array. The functions
  6905. * defined in the array are quite simple, taking a single parameter (the data to analyse)
  6906. * and returning the type if it is a known type, or null otherwise.
  6907. * <ul>
  6908. * <li>
  6909. * Function input parameters:
  6910. * <ul>
  6911. * <li>{*} Data from the column cell to be analysed</li>
  6912. * </ul>
  6913. * </li>
  6914. * <li>
  6915. * Function return:
  6916. * <ul>
  6917. * <li>{string|null} Data type detected, or null if unknown (and thus pass it
  6918. * on to the other type detection functions.</li>
  6919. * </ul>
  6920. * </il>
  6921. * </ul>
  6922. * @type array
  6923. * @default []
  6924. *
  6925. * @example
  6926. * // Currency type detection plug-in:
  6927. * jQuery.fn.dataTableExt.aTypes.push(
  6928. * function ( sData ) {
  6929. * var sValidChars = "0123456789.-";
  6930. * var Char;
  6931. *
  6932. * // Check the numeric part
  6933. * for ( i=1 ; i<sData.length ; i++ ) {
  6934. * Char = sData.charAt(i);
  6935. * if (sValidChars.indexOf(Char) == -1) {
  6936. * return null;
  6937. * }
  6938. * }
  6939. *
  6940. * // Check prefixed by currency
  6941. * if ( sData.charAt(0) == '$' || sData.charAt(0) == '&pound;' ) {
  6942. * return 'currency';
  6943. * }
  6944. * return null;
  6945. * }
  6946. * );
  6947. */
  6948. "aTypes": [],
  6949.  
  6950.  
  6951. /**
  6952. * Provide a common method for plug-ins to check the version of DataTables being used,
  6953. * in order to ensure compatibility.
  6954. * @type function
  6955. * @param {string} sVersion Version string to check for, in the format "X.Y.Z". Note
  6956. * that the formats "X" and "X.Y" are also acceptable.
  6957. * @returns {boolean} true if this version of DataTables is greater or equal to the
  6958. * required version, or false if this version of DataTales is not suitable
  6959. *
  6960. * @example
  6961. * $(document).ready(function() {
  6962. * var oTable = $('#example').dataTable();
  6963. * alert( oTable.fnVersionCheck( '1.9.0' ) );
  6964. * } );
  6965. */
  6966. "fnVersionCheck": DataTable.fnVersionCheck,
  6967.  
  6968.  
  6969. /**
  6970. * Index for what 'this' index API functions should use
  6971. * @type int
  6972. * @default 0
  6973. */
  6974. "iApiIndex": 0,
  6975.  
  6976.  
  6977. /**
  6978. * Pre-processing of filtering data plug-ins - When you assign the sType for a column
  6979. * (or have it automatically detected for you by DataTables or a type detection plug-in),
  6980. * you will typically be using this for custom sorting, but it can also be used to provide
  6981. * custom filtering by allowing you to pre-processing the data and returning the data in
  6982. * the format that should be filtered upon. This is done by adding functions this object
  6983. * with a parameter name which matches the sType for that target column. This is the
  6984. * corollary of <i>afnSortData</i> for filtering data.
  6985. * <ul>
  6986. * <li>
  6987. * Function input parameters:
  6988. * <ul>
  6989. * <li>{*} Data from the column cell to be prepared for filtering</li>
  6990. * </ul>
  6991. * </li>
  6992. * <li>
  6993. * Function return:
  6994. * <ul>
  6995. * <li>{string|null} Formatted string that will be used for the filtering.</li>
  6996. * </ul>
  6997. * </il>
  6998. * </ul>
  6999. *
  7000. * Note that as of v1.9, it is typically preferable to use <i>mDataProp</i> to prepare data for
  7001. * the different uses that DataTables can put the data to. Specifically <i>mDataProp</i> when
  7002. * used as a function will give you a 'type' (sorting, filtering etc) that you can use to
  7003. * prepare the data as required for the different types. As such, this method is deprecated.
  7004. * @type object
  7005. * @default {}
  7006. * @deprecated
  7007. *
  7008. * @example
  7009. * $.fn.dataTableExt.ofnSearch['title-numeric'] = function ( sData ) {
  7010. * return sData.replace(/\n/g," ").replace( /<.*?>/g, "" );
  7011. * }
  7012. */
  7013. "ofnSearch": {},
  7014.  
  7015.  
  7016. /**
  7017. * Container for all private functions in DataTables so they can be exposed externally
  7018. * @type object
  7019. * @default {}
  7020. */
  7021. "oApi": {},
  7022.  
  7023.  
  7024. /**
  7025. * Storage for the various classes that DataTables uses
  7026. * @type object
  7027. * @default {}
  7028. */
  7029. "oStdClasses": {},
  7030.  
  7031.  
  7032. /**
  7033. * Storage for the various classes that DataTables uses - jQuery UI suitable
  7034. * @type object
  7035. * @default {}
  7036. */
  7037. "oJUIClasses": {},
  7038.  
  7039.  
  7040. /**
  7041. * Pagination plug-in methods - The style and controls of the pagination can significantly
  7042. * impact on how the end user interacts with the data in your table, and DataTables allows
  7043. * the addition of pagination controls by extending this object, which can then be enabled
  7044. * through the <i>sPaginationType</i> initialisation parameter. Each pagination type that
  7045. * is added is an object (the property name of which is what <i>sPaginationType</i> refers
  7046. * to) that has two properties, both methods that are used by DataTables to update the
  7047. * control's state.
  7048. * <ul>
  7049. * <li>
  7050. * fnInit - Initialisation of the paging controls. Called only during initialisation
  7051. * of the table. It is expected that this function will add the required DOM elements
  7052. * to the page for the paging controls to work. The element pointer
  7053. * 'oSettings.aanFeatures.p' array is provided by DataTables to contain the paging
  7054. * controls (note that this is a 2D array to allow for multiple instances of each
  7055. * DataTables DOM element). It is suggested that you add the controls to this element
  7056. * as children
  7057. * <ul>
  7058. * <li>
  7059. * Function input parameters:
  7060. * <ul>
  7061. * <li>{object} DataTables settings object: see {@link DataTable.models.oSettings}.</li>
  7062. * <li>{node} Container into which the pagination controls must be inserted</li>
  7063. * <li>{function} Draw callback function - whenever the controls cause a page
  7064. * change, this method must be called to redraw the table.</li>
  7065. * </ul>
  7066. * </li>
  7067. * <li>
  7068. * Function return:
  7069. * <ul>
  7070. * <li>No return required</li>
  7071. * </ul>
  7072. * </il>
  7073. * </ul>
  7074. * </il>
  7075. * <li>
  7076. * fnInit - This function is called whenever the paging status of the table changes and is
  7077. * typically used to update classes and/or text of the paging controls to reflex the new
  7078. * status.
  7079. * <ul>
  7080. * <li>
  7081. * Function input parameters:
  7082. * <ul>
  7083. * <li>{object} DataTables settings object: see {@link DataTable.models.oSettings}.</li>
  7084. * <li>{function} Draw callback function - in case you need to redraw the table again
  7085. * or attach new event listeners</li>
  7086. * </ul>
  7087. * </li>
  7088. * <li>
  7089. * Function return:
  7090. * <ul>
  7091. * <li>No return required</li>
  7092. * </ul>
  7093. * </il>
  7094. * </ul>
  7095. * </il>
  7096. * </ul>
  7097. * @type object
  7098. * @default {}
  7099. *
  7100. * @example
  7101. * $.fn.dataTableExt.oPagination.four_button = {
  7102. * "fnInit": function ( oSettings, nPaging, fnCallbackDraw ) {
  7103. * nFirst = document.createElement( 'span' );
  7104. * nPrevious = document.createElement( 'span' );
  7105. * nNext = document.createElement( 'span' );
  7106. * nLast = document.createElement( 'span' );
  7107. *
  7108. * nFirst.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sFirst ) );
  7109. * nPrevious.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sPrevious ) );
  7110. * nNext.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sNext ) );
  7111. * nLast.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sLast ) );
  7112. *
  7113. * nFirst.className = "paginate_button first";
  7114. * nPrevious.className = "paginate_button previous";
  7115. * nNext.className="paginate_button next";
  7116. * nLast.className = "paginate_button last";
  7117. *
  7118. * nPaging.appendChild( nFirst );
  7119. * nPaging.appendChild( nPrevious );
  7120. * nPaging.appendChild( nNext );
  7121. * nPaging.appendChild( nLast );
  7122. *
  7123. * $(nFirst).click( function () {
  7124. * oSettings.oApi._fnPageChange( oSettings, "first" );
  7125. * fnCallbackDraw( oSettings );
  7126. * } );
  7127. *
  7128. * $(nPrevious).click( function() {
  7129. * oSettings.oApi._fnPageChange( oSettings, "previous" );
  7130. * fnCallbackDraw( oSettings );
  7131. * } );
  7132. *
  7133. * $(nNext).click( function() {
  7134. * oSettings.oApi._fnPageChange( oSettings, "next" );
  7135. * fnCallbackDraw( oSettings );
  7136. * } );
  7137. *
  7138. * $(nLast).click( function() {
  7139. * oSettings.oApi._fnPageChange( oSettings, "last" );
  7140. * fnCallbackDraw( oSettings );
  7141. * } );
  7142. *
  7143. * $(nFirst).bind( 'selectstart', function () { return false; } );
  7144. * $(nPrevious).bind( 'selectstart', function () { return false; } );
  7145. * $(nNext).bind( 'selectstart', function () { return false; } );
  7146. * $(nLast).bind( 'selectstart', function () { return false; } );
  7147. * },
  7148. *
  7149. * "fnUpdate": function ( oSettings, fnCallbackDraw ) {
  7150. * if ( !oSettings.aanFeatures.p ) {
  7151. * return;
  7152. * }
  7153. *
  7154. * // Loop over each instance of the pager
  7155. * var an = oSettings.aanFeatures.p;
  7156. * for ( var i=0, iLen=an.length ; i<iLen ; i++ ) {
  7157. * var buttons = an[i].getElementsByTagName('span');
  7158. * if ( oSettings._iDisplayStart === 0 ) {
  7159. * buttons[0].className = "paginate_disabled_previous";
  7160. * buttons[1].className = "paginate_disabled_previous";
  7161. * }
  7162. * else {
  7163. * buttons[0].className = "paginate_enabled_previous";
  7164. * buttons[1].className = "paginate_enabled_previous";
  7165. * }
  7166. *
  7167. * if ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() ) {
  7168. * buttons[2].className = "paginate_disabled_next";
  7169. * buttons[3].className = "paginate_disabled_next";
  7170. * }
  7171. * else {
  7172. * buttons[2].className = "paginate_enabled_next";
  7173. * buttons[3].className = "paginate_enabled_next";
  7174. * }
  7175. * }
  7176. * }
  7177. * };
  7178. */
  7179. "oPagination": {},
  7180.  
  7181.  
  7182. /**
  7183. * Sorting plug-in methods - Sorting in DataTables is based on the detected type of the
  7184. * data column (you can add your own type detection functions, or override automatic
  7185. * detection using sType). With this specific type given to the column, DataTables will
  7186. * apply the required sort from the functions in the object. Each sort type must provide
  7187. * two mandatory methods, one each for ascending and descending sorting, and can optionally
  7188. * provide a pre-formatting method that will help speed up sorting by allowing DataTables
  7189. * to pre-format the sort data only once (rather than every time the actual sort functions
  7190. * are run). The two sorting functions are typical Javascript sort methods:
  7191. * <ul>
  7192. * <li>
  7193. * Function input parameters:
  7194. * <ul>
  7195. * <li>{*} Data to compare to the second parameter</li>
  7196. * <li>{*} Data to compare to the first parameter</li>
  7197. * </ul>
  7198. * </li>
  7199. * <li>
  7200. * Function return:
  7201. * <ul>
  7202. * <li>{int} Sorting match: <0 if first parameter should be sorted lower than
  7203. * the second parameter, ===0 if the two parameters are equal and >0 if
  7204. * the first parameter should be sorted height than the second parameter.</li>
  7205. * </ul>
  7206. * </il>
  7207. * </ul>
  7208. * @type object
  7209. * @default {}
  7210. *
  7211. * @example
  7212. * // Case-sensitive string sorting, with no pre-formatting method
  7213. * $.extend( $.fn.dataTableExt.oSort, {
  7214. * "string-case-asc": function(x,y) {
  7215. * return ((x < y) ? -1 : ((x > y) ? 1 : 0));
  7216. * },
  7217. * "string-case-desc": function(x,y) {
  7218. * return ((x < y) ? 1 : ((x > y) ? -1 : 0));
  7219. * }
  7220. * } );
  7221. *
  7222. * @example
  7223. * // Case-insensitive string sorting, with pre-formatting
  7224. * $.extend( $.fn.dataTableExt.oSort, {
  7225. * "string-pre": function(x) {
  7226. * return x.toLowerCase();
  7227. * },
  7228. * "string-asc": function(x,y) {
  7229. * return ((x < y) ? -1 : ((x > y) ? 1 : 0));
  7230. * },
  7231. * "string-desc": function(x,y) {
  7232. * return ((x < y) ? 1 : ((x > y) ? -1 : 0));
  7233. * }
  7234. * } );
  7235. */
  7236. "oSort": {},
  7237.  
  7238.  
  7239. /**
  7240. * Version string for plug-ins to check compatibility. Allowed format is
  7241. * a.b.c.d.e where: a:int, b:int, c:int, d:string(dev|beta), e:int. d and
  7242. * e are optional
  7243. * @type string
  7244. * @default Version number
  7245. */
  7246. "sVersion": DataTable.version,
  7247.  
  7248.  
  7249. /**
  7250. * How should DataTables report an error. Can take the value 'alert' or 'throw'
  7251. * @type string
  7252. * @default alert
  7253. */
  7254. "sErrMode": "alert",
  7255.  
  7256.  
  7257. /**
  7258. * Store information for DataTables to access globally about other instances
  7259. * @namespace
  7260. * @private
  7261. */
  7262. "_oExternConfig": {
  7263. /* int:iNextUnique - next unique number for an instance */
  7264. "iNextUnique": 0
  7265. }
  7266. };
  7267.  
  7268.  
  7269.  
  7270.  
  7271. /**
  7272. * Template object for the way in which DataTables holds information about
  7273. * search information for the global filter and individual column filters.
  7274. * @namespace
  7275. */
  7276. DataTable.models.oSearch = {
  7277. /**
  7278. * Flag to indicate if the filtering should be case insensitive or not
  7279. * @type boolean
  7280. * @default true
  7281. */
  7282. "bCaseInsensitive": true,
  7283.  
  7284. /**
  7285. * Applied search term
  7286. * @type string
  7287. * @default <i>Empty string</i>
  7288. */
  7289. "sSearch": "",
  7290.  
  7291. /**
  7292. * Flag to indicate if the search term should be interpreted as a
  7293. * regular expression (true) or not (false) and therefore and special
  7294. * regex characters escaped.
  7295. * @type boolean
  7296. * @default false
  7297. */
  7298. "bRegex": false,
  7299.  
  7300. /**
  7301. * Flag to indicate if DataTables is to use its smart filtering or not.
  7302. * @type boolean
  7303. * @default true
  7304. */
  7305. "bSmart": true
  7306. };
  7307.  
  7308.  
  7309.  
  7310.  
  7311. /**
  7312. * Template object for the way in which DataTables holds information about
  7313. * each individual row. This is the object format used for the settings
  7314. * aoData array.
  7315. * @namespace
  7316. */
  7317. DataTable.models.oRow = {
  7318. /**
  7319. * TR element for the row
  7320. * @type node
  7321. * @default null
  7322. */
  7323. "nTr": null,
  7324.  
  7325. /**
  7326. * Data object from the original data source for the row. This is either
  7327. * an array if using the traditional form of DataTables, or an object if
  7328. * using mDataProp options. The exact type will depend on the passed in
  7329. * data from the data source, or will be an array if using DOM a data
  7330. * source.
  7331. * @type array|object
  7332. * @default []
  7333. */
  7334. "_aData": [],
  7335.  
  7336. /**
  7337. * Sorting data cache - this array is ostensibly the same length as the
  7338. * number of columns (although each index is generated only as it is
  7339. * needed), and holds the data that is used for sorting each column in the
  7340. * row. We do this cache generation at the start of the sort in order that
  7341. * the formatting of the sort data need be done only once for each cell
  7342. * per sort. This array should not be read from or written to by anything
  7343. * other than the master sorting methods.
  7344. * @type array
  7345. * @default []
  7346. * @private
  7347. */
  7348. "_aSortData": [],
  7349.  
  7350. /**
  7351. * Array of TD elements that are cached for hidden rows, so they can be
  7352. * reinserted into the table if a column is made visible again (or to act
  7353. * as a store if a column is made hidden). Only hidden columns have a
  7354. * reference in the array. For non-hidden columns the value is either
  7355. * undefined or null.
  7356. * @type array nodes
  7357. * @default []
  7358. * @private
  7359. */
  7360. "_anHidden": [],
  7361.  
  7362. /**
  7363. * Cache of the class name that DataTables has applied to the row, so we
  7364. * can quickly look at this variable rather than needing to do a DOM check
  7365. * on className for the nTr property.
  7366. * @type string
  7367. * @default <i>Empty string</i>
  7368. * @private
  7369. */
  7370. "_sRowStripe": ""
  7371. };
  7372.  
  7373.  
  7374.  
  7375. /**
  7376. * Template object for the column information object in DataTables. This object
  7377. * is held in the settings aoColumns array and contains all the information that
  7378. * DataTables needs about each individual column.
  7379. *
  7380. * Note that this object is related to {@link DataTable.defaults.columns}
  7381. * but this one is the internal data store for DataTables's cache of columns.
  7382. * It should NOT be manipulated outside of DataTables. Any configuration should
  7383. * be done through the initialisation options.
  7384. * @namespace
  7385. */
  7386. DataTable.models.oColumn = {
  7387. /**
  7388. * A list of the columns that sorting should occur on when this column
  7389. * is sorted. That this property is an array allows multi-column sorting
  7390. * to be defined for a column (for example first name / last name columns
  7391. * would benefit from this). The values are integers pointing to the
  7392. * columns to be sorted on (typically it will be a single integer pointing
  7393. * at itself, but that doesn't need to be the case).
  7394. * @type array
  7395. */
  7396. "aDataSort": null,
  7397.  
  7398. /**
  7399. * Define the sorting directions that are applied to the column, in sequence
  7400. * as the column is repeatedly sorted upon - i.e. the first value is used
  7401. * as the sorting direction when the column if first sorted (clicked on).
  7402. * Sort it again (click again) and it will move on to the next index.
  7403. * Repeat until loop.
  7404. * @type array
  7405. */
  7406. "asSorting": null,
  7407.  
  7408. /**
  7409. * Flag to indicate if the column is searchable, and thus should be included
  7410. * in the filtering or not.
  7411. * @type boolean
  7412. */
  7413. "bSearchable": null,
  7414.  
  7415. /**
  7416. * Flag to indicate if the column is sortable or not.
  7417. * @type boolean
  7418. */
  7419. "bSortable": null,
  7420.  
  7421. /**
  7422. * When using fnRender, you have two options for what to do with the data,
  7423. * and this property serves as the switch. Firstly, you can have the sorting
  7424. * and filtering use the rendered value (true - default), or you can have
  7425. * the sorting and filtering us the original value (false).
  7426. *
  7427. * *NOTE* It is it is advisable now to use mDataProp as a function and make
  7428. * use of the 'type' that it gives, allowing (potentially) different data to
  7429. * be used for sorting, filtering, display and type detection.
  7430. * @type boolean
  7431. * @deprecated
  7432. */
  7433. "bUseRendered": null,
  7434.  
  7435. /**
  7436. * Flag to indicate if the column is currently visible in the table or not
  7437. * @type boolean
  7438. */
  7439. "bVisible": null,
  7440.  
  7441. /**
  7442. * Flag to indicate to the type detection method if the automatic type
  7443. * detection should be used, or if a column type (sType) has been specified
  7444. * @type boolean
  7445. * @default true
  7446. * @private
  7447. */
  7448. "_bAutoType": true,
  7449.  
  7450. /**
  7451. * Developer definable function that is called whenever a cell is created (Ajax source,
  7452. * etc) or processed for input (DOM source). This can be used as a compliment to fnRender
  7453. * allowing you to modify the DOM element (add background colour for example) when the
  7454. * element is available (since it is not when fnRender is called).
  7455. * @type function
  7456. * @param {element} nTd The TD node that has been created
  7457. * @param {*} sData The Data for the cell
  7458. * @param {array|object} oData The data for the whole row
  7459. * @param {int} iRow The row index for the aoData data store
  7460. * @default null
  7461. */
  7462. "fnCreatedCell": null,
  7463.  
  7464. /**
  7465. * Function to get data from a cell in a column. You should <b>never</b>
  7466. * access data directly through _aData internally in DataTables - always use
  7467. * the method attached to this property. It allows mDataProp to function as
  7468. * required. This function is automatically assigned by the column
  7469. * initialisation method
  7470. * @type function
  7471. * @param {array|object} oData The data array/object for the array
  7472. * (i.e. aoData[]._aData)
  7473. * @param {string} sSpecific The specific data type you want to get -
  7474. * 'display', 'type' 'filter' 'sort'
  7475. * @returns {*} The data for the cell from the given row's data
  7476. * @default null
  7477. */
  7478. "fnGetData": null,
  7479.  
  7480. /**
  7481. * Custom display function that will be called for the display of each cell
  7482. * in this column.
  7483. * @type function
  7484. * @param {object} o Object with the following parameters:
  7485. * @param {int} o.iDataRow The row in aoData
  7486. * @param {int} o.iDataColumn The column in question
  7487. * @param {array o.aData The data for the row in question
  7488. * @param {object} o.oSettings The settings object for this DataTables instance
  7489. * @returns {string} The string you which to use in the display
  7490. * @default null
  7491. */
  7492. "fnRender": null,
  7493.  
  7494. /**
  7495. * Function to set data for a cell in the column. You should <b>never</b>
  7496. * set the data directly to _aData internally in DataTables - always use
  7497. * this method. It allows mDataProp to function as required. This function
  7498. * is automatically assigned by the column initialisation method
  7499. * @type function
  7500. * @param {array|object} oData The data array/object for the array
  7501. * (i.e. aoData[]._aData)
  7502. * @param {*} sValue Value to set
  7503. * @default null
  7504. */
  7505. "fnSetData": null,
  7506.  
  7507. /**
  7508. * Property to read the value for the cells in the column from the data
  7509. * source array / object. If null, then the default content is used, if a
  7510. * function is given then the return from the function is used.
  7511. * @type function|int|string|null
  7512. * @default null
  7513. */
  7514. "mDataProp": null,
  7515.  
  7516. /**
  7517. * Unique header TH/TD element for this column - this is what the sorting
  7518. * listener is attached to (if sorting is enabled.)
  7519. * @type node
  7520. * @default null
  7521. */
  7522. "nTh": null,
  7523.  
  7524. /**
  7525. * Unique footer TH/TD element for this column (if there is one). Not used
  7526. * in DataTables as such, but can be used for plug-ins to reference the
  7527. * footer for each column.
  7528. * @type node
  7529. * @default null
  7530. */
  7531. "nTf": null,
  7532.  
  7533. /**
  7534. * The class to apply to all TD elements in the table's TBODY for the column
  7535. * @type string
  7536. * @default null
  7537. */
  7538. "sClass": null,
  7539.  
  7540. /**
  7541. * When DataTables calculates the column widths to assign to each column,
  7542. * it finds the longest string in each column and then constructs a
  7543. * temporary table and reads the widths from that. The problem with this
  7544. * is that "mmm" is much wider then "iiii", but the latter is a longer
  7545. * string - thus the calculation can go wrong (doing it properly and putting
  7546. * it into an DOM object and measuring that is horribly(!) slow). Thus as
  7547. * a "work around" we provide this option. It will append its value to the
  7548. * text that is found to be the longest string for the column - i.e. padding.
  7549. * @type string
  7550. */
  7551. "sContentPadding": null,
  7552.  
  7553. /**
  7554. * Allows a default value to be given for a column's data, and will be used
  7555. * whenever a null data source is encountered (this can be because mDataProp
  7556. * is set to null, or because the data source itself is null).
  7557. * @type string
  7558. * @default null
  7559. */
  7560. "sDefaultContent": null,
  7561.  
  7562. /**
  7563. * Name for the column, allowing reference to the column by name as well as
  7564. * by index (needs a lookup to work by name).
  7565. * @type string
  7566. */
  7567. "sName": null,
  7568.  
  7569. /**
  7570. * Custom sorting data type - defines which of the available plug-ins in
  7571. * afnSortData the custom sorting will use - if any is defined.
  7572. * @type string
  7573. * @default std
  7574. */
  7575. "sSortDataType": 'std',
  7576.  
  7577. /**
  7578. * Class to be applied to the header element when sorting on this column
  7579. * @type string
  7580. * @default null
  7581. */
  7582. "sSortingClass": null,
  7583.  
  7584. /**
  7585. * Class to be applied to the header element when sorting on this column -
  7586. * when jQuery UI theming is used.
  7587. * @type string
  7588. * @default null
  7589. */
  7590. "sSortingClassJUI": null,
  7591.  
  7592. /**
  7593. * Title of the column - what is seen in the TH element (nTh).
  7594. * @type string
  7595. */
  7596. "sTitle": null,
  7597.  
  7598. /**
  7599. * Column sorting and filtering type
  7600. * @type string
  7601. * @default null
  7602. */
  7603. "sType": null,
  7604.  
  7605. /**
  7606. * Width of the column
  7607. * @type string
  7608. * @default null
  7609. */
  7610. "sWidth": null,
  7611.  
  7612. /**
  7613. * Width of the column when it was first "encountered"
  7614. * @type string
  7615. * @default null
  7616. */
  7617. "sWidthOrig": null
  7618. };
  7619.  
  7620.  
  7621.  
  7622. /**
  7623. * Initialisation options that can be given to DataTables at initialisation
  7624. * time.
  7625. * @namespace
  7626. */
  7627. DataTable.defaults = {
  7628. /**
  7629. * An array of data to use for the table, passed in at initialisation which
  7630. * will be used in preference to any data which is already in the DOM. This is
  7631. * particularly useful for constructing tables purely in Javascript, for
  7632. * example with a custom Ajax call.
  7633. * @type array
  7634. * @default null
  7635. * @dtopt Option
  7636. *
  7637. * @example
  7638. * // Using a 2D array data source
  7639. * $(document).ready( function () {
  7640. * $('#example').dataTable( {
  7641. * "aaData": [
  7642. * ['Trident', 'Internet Explorer 4.0', 'Win 95+', 4, 'X'],
  7643. * ['Trident', 'Internet Explorer 5.0', 'Win 95+', 5, 'C'],
  7644. * ],
  7645. * "aoColumns": [
  7646. * { "sTitle": "Engine" },
  7647. * { "sTitle": "Browser" },
  7648. * { "sTitle": "Platform" },
  7649. * { "sTitle": "Version" },
  7650. * { "sTitle": "Grade" }
  7651. * ]
  7652. * } );
  7653. * } );
  7654. *
  7655. * @example
  7656. * // Using an array of objects as a data source (mDataProp)
  7657. * $(document).ready( function () {
  7658. * $('#example').dataTable( {
  7659. * "aaData": [
  7660. * {
  7661. * "engine": "Trident",
  7662. * "browser": "Internet Explorer 4.0",
  7663. * "platform": "Win 95+",
  7664. * "version": 4,
  7665. * "grade": "X"
  7666. * },
  7667. * {
  7668. * "engine": "Trident",
  7669. * "browser": "Internet Explorer 5.0",
  7670. * "platform": "Win 95+",
  7671. * "version": 5,
  7672. * "grade": "C"
  7673. * }
  7674. * ],
  7675. * "aoColumns": [
  7676. * { "sTitle": "Engine", "mDataProp": "engine" },
  7677. * { "sTitle": "Browser", "mDataProp": "browser" },
  7678. * { "sTitle": "Platform", "mDataProp": "platform" },
  7679. * { "sTitle": "Version", "mDataProp": "version" },
  7680. * { "sTitle": "Grade", "mDataProp": "grade" }
  7681. * ]
  7682. * } );
  7683. * } );
  7684. */
  7685. "aaData": null,
  7686.  
  7687.  
  7688. /**
  7689. * If sorting is enabled, then DataTables will perform a first pass sort on
  7690. * initialisation. You can define which column(s) the sort is performed upon,
  7691. * and the sorting direction, with this variable. The aaSorting array should
  7692. * contain an array for each column to be sorted initially containing the
  7693. * column's index and a direction string ('asc' or 'desc').
  7694. * @type array
  7695. * @default [[0,'asc']]
  7696. * @dtopt Option
  7697. *
  7698. * @example
  7699. * // Sort by 3rd column first, and then 4th column
  7700. * $(document).ready( function() {
  7701. * $('#example').dataTable( {
  7702. * "aaSorting": [[2,'asc'], [3,'desc']]
  7703. * } );
  7704. * } );
  7705. *
  7706. * // No initial sorting
  7707. * $(document).ready( function() {
  7708. * $('#example').dataTable( {
  7709. * "aaSorting": []
  7710. * } );
  7711. * } );
  7712. */
  7713. "aaSorting": [[0,'asc']],
  7714.  
  7715.  
  7716. /**
  7717. * This parameter is basically identical to the aaSorting parameter, but
  7718. * cannot be overridden by user interaction with the table. What this means
  7719. * is that you could have a column (visible or hidden) which the sorting will
  7720. * always be forced on first - any sorting after that (from the user) will
  7721. * then be performed as required. This can be useful for grouping rows
  7722. * together.
  7723. * @type array
  7724. * @default null
  7725. * @dtopt Option
  7726. *
  7727. * @example
  7728. * $(document).ready( function() {
  7729. * $('#example').dataTable( {
  7730. * "aaSortingFixed": [[0,'asc']]
  7731. * } );
  7732. * } )
  7733. */
  7734. "aaSortingFixed": null,
  7735.  
  7736.  
  7737. /**
  7738. * This parameter allows you to readily specify the entries in the length drop
  7739. * down menu that DataTables shows when pagination is enabled. It can be
  7740. * either a 1D array of options which will be used for both the displayed
  7741. * option and the value, or a 2D array which will use the array in the first
  7742. * position as the value, and the array in the second position as the
  7743. * displayed options (useful for language strings such as 'All').
  7744. * @type array
  7745. * @default [ 10, 25, 50, 100 ]
  7746. * @dtopt Option
  7747. *
  7748. * @example
  7749. * $(document).ready(function() {
  7750. * $('#example').dataTable( {
  7751. * "aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
  7752. * } );
  7753. * } );
  7754. *
  7755. * @example
  7756. * // Setting the default display length as well as length menu
  7757. * // This is likely to be wanted if you remove the '10' option which
  7758. * // is the iDisplayLength default.
  7759. * $(document).ready(function() {
  7760. * $('#example').dataTable( {
  7761. * "iDisplayLength": 25,
  7762. * "aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]]
  7763. * } );
  7764. * } );
  7765. */
  7766. "aLengthMenu": [ 10, 25, 50, 100 ],
  7767.  
  7768.  
  7769. /**
  7770. * The aoColumns option in the initialisation parameter allows you to define
  7771. * details about the way individual columns behave. For a full list of
  7772. * column options that can be set, please see
  7773. * {@link DataTable.defaults.columns}. Note that if you use aoColumns to
  7774. * define your columns, you must have an entry in the array for every single
  7775. * column that you have in your table (these can be null if you don't which
  7776. * to specify any options).
  7777. * @member
  7778. */
  7779. "aoColumns": null,
  7780.  
  7781. /**
  7782. * Very similar to aoColumns, aoColumnDefs allows you to target a specific
  7783. * column, multiple columns, or all columns, using the aTargets property of
  7784. * each object in the array. This allows great flexibility when creating
  7785. * tables, as the aoColumnDefs arrays can be of any length, targeting the
  7786. * columns you specifically want. aoColumnDefs may use any of the column
  7787. * options available: {@link DataTable.defaults.columns}, but it _must_
  7788. * have aTargets defined in each object in the array. Values in the aTargets
  7789. * array may be:
  7790. * <ul>
  7791. * <li>a string - class name will be matched on the TH for the column</li>
  7792. * <li>0 or a positive integer - column index counting from the left</li>
  7793. * <li>a negative integer - column index counting from the right</li>
  7794. * <li>the string "_all" - all columns (i.e. assign a default)</li>
  7795. * </ul>
  7796. * @member
  7797. */
  7798. "aoColumnDefs": null,
  7799.  
  7800.  
  7801. /**
  7802. * Basically the same as oSearch, this parameter defines the individual column
  7803. * filtering state at initialisation time. The array must be of the same size
  7804. * as the number of columns, and each element be an object with the parameters
  7805. * "sSearch" and "bEscapeRegex" (the latter is optional). 'null' is also
  7806. * accepted and the default will be used.
  7807. * @type array
  7808. * @default []
  7809. * @dtopt Option
  7810. *
  7811. * @example
  7812. * $(document).ready( function() {
  7813. * $('#example').dataTable( {
  7814. * "aoSearchCols": [
  7815. * null,
  7816. * { "sSearch": "My filter" },
  7817. * null,
  7818. * { "sSearch": "^[0-9]", "bEscapeRegex": false }
  7819. * ]
  7820. * } );
  7821. * } )
  7822. */
  7823. "aoSearchCols": [],
  7824.  
  7825.  
  7826. /**
  7827. * An array of CSS classes that should be applied to displayed rows. This
  7828. * array may be of any length, and DataTables will apply each class
  7829. * sequentially, looping when required.
  7830. * @type array
  7831. * @default null <i>Will take the values determinted by the oClasses.sStripe*
  7832. * options</i>
  7833. * @dtopt Option
  7834. *
  7835. * @example
  7836. * $(document).ready( function() {
  7837. * $('#example').dataTable( {
  7838. * "asStripeClasses": [ 'strip1', 'strip2', 'strip3' ]
  7839. * } );
  7840. * } )
  7841. */
  7842. "asStripeClasses": null,
  7843.  
  7844.  
  7845. /**
  7846. * Enable or disable automatic column width calculation. This can be disabled
  7847. * as an optimisation (it takes some time to calculate the widths) if the
  7848. * tables widths are passed in using aoColumns.
  7849. * @type boolean
  7850. * @default true
  7851. * @dtopt Features
  7852. *
  7853. * @example
  7854. * $(document).ready( function () {
  7855. * $('#example').dataTable( {
  7856. * "bAutoWidth": false
  7857. * } );
  7858. * } );
  7859. */
  7860. "bAutoWidth": true,
  7861.  
  7862.  
  7863. /**
  7864. * Deferred rendering can provide DataTables with a huge speed boost when you
  7865. * are using an Ajax or JS data source for the table. This option, when set to
  7866. * true, will cause DataTables to defer the creation of the table elements for
  7867. * each row until they are needed for a draw - saving a significant amount of
  7868. * time.
  7869. * @type boolean
  7870. * @default false
  7871. * @dtopt Features
  7872. *
  7873. * @example
  7874. * $(document).ready(function() {
  7875. * var oTable = $('#example').dataTable( {
  7876. * "sAjaxSource": "sources/arrays.txt",
  7877. * "bDeferRender": true
  7878. * } );
  7879. * } );
  7880. */
  7881. "bDeferRender": false,
  7882.  
  7883.  
  7884. /**
  7885. * Replace a DataTable which matches the given selector and replace it with
  7886. * one which has the properties of the new initialisation object passed. If no
  7887. * table matches the selector, then the new DataTable will be constructed as
  7888. * per normal.
  7889. * @type boolean
  7890. * @default false
  7891. * @dtopt Options
  7892. *
  7893. * @example
  7894. * $(document).ready(function() {
  7895. * $('#example').dataTable( {
  7896. * "sScrollY": "200px",
  7897. * "bPaginate": false
  7898. * } );
  7899. *
  7900. * // Some time later....
  7901. * $('#example').dataTable( {
  7902. * "bFilter": false,
  7903. * "bDestroy": true
  7904. * } );
  7905. * } );
  7906. */
  7907. "bDestroy": false,
  7908.  
  7909.  
  7910. /**
  7911. * Enable or disable filtering of data. Filtering in DataTables is "smart" in
  7912. * that it allows the end user to input multiple words (space separated) and
  7913. * will match a row containing those words, even if not in the order that was
  7914. * specified (this allow matching across multiple columns). Note that if you
  7915. * wish to use filtering in DataTables this must remain 'true' - to remove the
  7916. * default filtering input box and retain filtering abilities, please use
  7917. * {@link DataTable.defaults.sDom}.
  7918. * @type boolean
  7919. * @default true
  7920. * @dtopt Features
  7921. *
  7922. * @example
  7923. * $(document).ready( function () {
  7924. * $('#example').dataTable( {
  7925. * "bFilter": false
  7926. * } );
  7927. * } );
  7928. */
  7929. "bFilter": true,
  7930.  
  7931.  
  7932. /**
  7933. * Enable or disable the table information display. This shows information
  7934. * about the data that is currently visible on the page, including information
  7935. * about filtered data if that action is being performed.
  7936. * @type boolean
  7937. * @default true
  7938. * @dtopt Features
  7939. *
  7940. * @example
  7941. * $(document).ready( function () {
  7942. * $('#example').dataTable( {
  7943. * "bInfo": false
  7944. * } );
  7945. * } );
  7946. */
  7947. "bInfo": true,
  7948.  
  7949.  
  7950. /**
  7951. * Enable jQuery UI ThemeRoller support (required as ThemeRoller requires some
  7952. * slightly different and additional mark-up from what DataTables has
  7953. * traditionally used).
  7954. * @type boolean
  7955. * @default false
  7956. * @dtopt Features
  7957. *
  7958. * @example
  7959. * $(document).ready( function() {
  7960. * $('#example').dataTable( {
  7961. * "bJQueryUI": true
  7962. * } );
  7963. * } );
  7964. */
  7965. "bJQueryUI": false,
  7966.  
  7967.  
  7968. /**
  7969. * Allows the end user to select the size of a formatted page from a select
  7970. * menu (sizes are 10, 25, 50 and 100). Requires pagination (bPaginate).
  7971. * @type boolean
  7972. * @default true
  7973. * @dtopt Features
  7974. *
  7975. * @example
  7976. * $(document).ready( function () {
  7977. * $('#example').dataTable( {
  7978. * "bLengthChange": false
  7979. * } );
  7980. * } );
  7981. */
  7982. "bLengthChange": true,
  7983.  
  7984.  
  7985. /**
  7986. * Enable or disable pagination.
  7987. * @type boolean
  7988. * @default true
  7989. * @dtopt Features
  7990. *
  7991. * @example
  7992. * $(document).ready( function () {
  7993. * $('#example').dataTable( {
  7994. * "bPaginate": false
  7995. * } );
  7996. * } );
  7997. */
  7998. "bPaginate": true,
  7999.  
  8000.  
  8001. /**
  8002. * Enable or disable the display of a 'processing' indicator when the table is
  8003. * being processed (e.g. a sort). This is particularly useful for tables with
  8004. * large amounts of data where it can take a noticeable amount of time to sort
  8005. * the entries.
  8006. * @type boolean
  8007. * @default false
  8008. * @dtopt Features
  8009. *
  8010. * @example
  8011. * $(document).ready( function () {
  8012. * $('#example').dataTable( {
  8013. * "bProcessing": true
  8014. * } );
  8015. * } );
  8016. */
  8017. "bProcessing": false,
  8018.  
  8019.  
  8020. /**
  8021. * Retrieve the DataTables object for the given selector. Note that if the
  8022. * table has already been initialised, this parameter will cause DataTables
  8023. * to simply return the object that has already been set up - it will not take
  8024. * account of any changes you might have made to the initialisation object
  8025. * passed to DataTables (setting this parameter to true is an acknowledgement
  8026. * that you understand this). bDestroy can be used to reinitialise a table if
  8027. * you need.
  8028. * @type boolean
  8029. * @default false
  8030. * @dtopt Options
  8031. *
  8032. * @example
  8033. * $(document).ready(function() {
  8034. * initTable();
  8035. * tableActions();
  8036. * } );
  8037. *
  8038. * function initTable ()
  8039. * {
  8040. * return $('#example').dataTable( {
  8041. * "sScrollY": "200px",
  8042. * "bPaginate": false,
  8043. * "bRetrieve": true
  8044. * } );
  8045. * }
  8046. *
  8047. * function tableActions ()
  8048. * {
  8049. * var oTable = initTable();
  8050. * // perform API operations with oTable
  8051. * }
  8052. */
  8053. "bRetrieve": false,
  8054.  
  8055.  
  8056. /**
  8057. * Indicate if DataTables should be allowed to set the padding / margin
  8058. * etc for the scrolling header elements or not. Typically you will want
  8059. * this.
  8060. * @type boolean
  8061. * @default true
  8062. * @dtopt Options
  8063. *
  8064. * @example
  8065. * $(document).ready(function() {
  8066. * $('#example').dataTable( {
  8067. * "bScrollAutoCss": false,
  8068. * "sScrollY": "200px"
  8069. * } );
  8070. * } );
  8071. */
  8072. "bScrollAutoCss": true,
  8073.  
  8074.  
  8075. /**
  8076. * When vertical (y) scrolling is enabled, DataTables will force the height of
  8077. * the table's viewport to the given height at all times (useful for layout).
  8078. * However, this can look odd when filtering data down to a small data set,
  8079. * and the footer is left "floating" further down. This parameter (when
  8080. * enabled) will cause DataTables to collapse the table's viewport down when
  8081. * the result set will fit within the given Y height.
  8082. * @type boolean
  8083. * @default false
  8084. * @dtopt Options
  8085. *
  8086. * @example
  8087. * $(document).ready(function() {
  8088. * $('#example').dataTable( {
  8089. * "sScrollY": "200",
  8090. * "bScrollCollapse": true
  8091. * } );
  8092. * } );
  8093. */
  8094. "bScrollCollapse": false,
  8095.  
  8096.  
  8097. /**
  8098. * Enable infinite scrolling for DataTables (to be used in combination with
  8099. * sScrollY). Infinite scrolling means that DataTables will continually load
  8100. * data as a user scrolls through a table, which is very useful for large
  8101. * dataset. This cannot be used with pagination, which is automatically
  8102. * disabled. Note - the Scroller extra for DataTables is recommended in
  8103. * in preference to this option.
  8104. * @type boolean
  8105. * @default false
  8106. * @dtopt Features
  8107. *
  8108. * @example
  8109. * $(document).ready(function() {
  8110. * $('#example').dataTable( {
  8111. * "bScrollInfinite": true,
  8112. * "bScrollCollapse": true,
  8113. * "sScrollY": "200px"
  8114. * } );
  8115. * } );
  8116. */
  8117. "bScrollInfinite": false,
  8118.  
  8119.  
  8120. /**
  8121. * Configure DataTables to use server-side processing. Note that the
  8122. * sAjaxSource parameter must also be given in order to give DataTables a
  8123. * source to obtain the required data for each draw.
  8124. * @type boolean
  8125. * @default false
  8126. * @dtopt Features
  8127. * @dtopt Server-side
  8128. *
  8129. * @example
  8130. * $(document).ready( function () {
  8131. * $('#example').dataTable( {
  8132. * "bServerSide": true,
  8133. * "sAjaxSource": "xhr.php"
  8134. * } );
  8135. * } );
  8136. */
  8137. "bServerSide": false,
  8138.  
  8139.  
  8140. /**
  8141. * Enable or disable sorting of columns. Sorting of individual columns can be
  8142. * disabled by the "bSortable" option for each column.
  8143. * @type boolean
  8144. * @default true
  8145. * @dtopt Features
  8146. *
  8147. * @example
  8148. * $(document).ready( function () {
  8149. * $('#example').dataTable( {
  8150. * "bSort": false
  8151. * } );
  8152. * } );
  8153. */
  8154. "bSort": true,
  8155.  
  8156.  
  8157. /**
  8158. * Allows control over whether DataTables should use the top (true) unique
  8159. * cell that is found for a single column, or the bottom (false - default).
  8160. * This is useful when using complex headers.
  8161. * @type boolean
  8162. * @default false
  8163. * @dtopt Options
  8164. *
  8165. * @example
  8166. * $(document).ready(function() {
  8167. * $('#example').dataTable( {
  8168. * "bSortCellsTop": true
  8169. * } );
  8170. * } );
  8171. */
  8172. "bSortCellsTop": false,
  8173.  
  8174.  
  8175. /**
  8176. * Enable or disable the addition of the classes 'sorting_1', 'sorting_2' and
  8177. * 'sorting_3' to the columns which are currently being sorted on. This is
  8178. * presented as a feature switch as it can increase processing time (while
  8179. * classes are removed and added) so for large data sets you might want to
  8180. * turn this off.
  8181. * @type boolean
  8182. * @default true
  8183. * @dtopt Features
  8184. *
  8185. * @example
  8186. * $(document).ready( function () {
  8187. * $('#example').dataTable( {
  8188. * "bSortClasses": false
  8189. * } );
  8190. * } );
  8191. */
  8192. "bSortClasses": true,
  8193.  
  8194.  
  8195. /**
  8196. * Enable or disable state saving. When enabled a cookie will be used to save
  8197. * table display information such as pagination information, display length,
  8198. * filtering and sorting. As such when the end user reloads the page the
  8199. * display display will match what thy had previously set up.
  8200. * @type boolean
  8201. * @default false
  8202. * @dtopt Features
  8203. *
  8204. * @example
  8205. * $(document).ready( function () {
  8206. * $('#example').dataTable( {
  8207. * "bStateSave": true
  8208. * } );
  8209. * } );
  8210. */
  8211. "bStateSave": false,
  8212.  
  8213.  
  8214. /**
  8215. * Customise the cookie and / or the parameters being stored when using
  8216. * DataTables with state saving enabled. This function is called whenever
  8217. * the cookie is modified, and it expects a fully formed cookie string to be
  8218. * returned. Note that the data object passed in is a Javascript object which
  8219. * must be converted to a string (JSON.stringify for example).
  8220. * @type function
  8221. * @param {string} sName Name of the cookie defined by DataTables
  8222. * @param {object} oData Data to be stored in the cookie
  8223. * @param {string} sExpires Cookie expires string
  8224. * @param {string} sPath Path of the cookie to set
  8225. * @returns {string} Cookie formatted string (which should be encoded by
  8226. * using encodeURIComponent())
  8227. * @dtopt Callbacks
  8228. *
  8229. * @example
  8230. * $(document).ready( function () {
  8231. * $('#example').dataTable( {
  8232. * "fnCookieCallback": function (sName, oData, sExpires, sPath) {
  8233. * // Customise oData or sName or whatever else here
  8234. * return sName + "="+JSON.stringify(oData)+"; expires=" + sExpires +"; path=" + sPath;
  8235. * }
  8236. * } );
  8237. * } );
  8238. */
  8239. "fnCookieCallback": null,
  8240.  
  8241.  
  8242. /**
  8243. * This function is called when a TR element is created (and all TD child
  8244. * elements have been inserted), or registered if using a DOM source, allowing
  8245. * manipulation of the TR element (adding classes etc).
  8246. * @type function
  8247. * @param {node} nRow "TR" element for the current row
  8248. * @param {array} aData Raw data array for this row
  8249. * @param {int} iDataIndex The index of this row in aoData
  8250. * @dtopt Callbacks
  8251. *
  8252. * @example
  8253. * $(document).ready(function() {
  8254. * $('#example').dataTable( {
  8255. * "fnCreatedRow": function( nRow, aData, iDataIndex ) {
  8256. * // Bold the grade for all 'A' grade browsers
  8257. * if ( aData[4] == "A" )
  8258. * {
  8259. * $('td:eq(4)', nRow).html( '<b>A</b>' );
  8260. * }
  8261. * }
  8262. * } );
  8263. * } );
  8264. */
  8265. "fnCreatedRow": null,
  8266.  
  8267.  
  8268. /**
  8269. * This function is called on every 'draw' event, and allows you to
  8270. * dynamically modify any aspect you want about the created DOM.
  8271. * @type function
  8272. * @param {object} oSettings DataTables settings object
  8273. * @dtopt Callbacks
  8274. *
  8275. * @example
  8276. * $(document).ready( function() {
  8277. * $('#example').dataTable( {
  8278. * "fnDrawCallback": function( oSettings ) {
  8279. * alert( 'DataTables has redrawn the table' );
  8280. * }
  8281. * } );
  8282. * } );
  8283. */
  8284. "fnDrawCallback": null,
  8285.  
  8286.  
  8287. /**
  8288. * Identical to fnHeaderCallback() but for the table footer this function
  8289. * allows you to modify the table footer on every 'draw' even.
  8290. * @type function
  8291. * @param {node} nFoot "TR" element for the footer
  8292. * @param {array} aData Full table data (as derived from the original HTML)
  8293. * @param {int} iStart Index for the current display starting point in the
  8294. * display array
  8295. * @param {int} iEnd Index for the current display ending point in the
  8296. * display array
  8297. * @param {array int} aiDisplay Index array to translate the visual position
  8298. * to the full data array
  8299. * @dtopt Callbacks
  8300. *
  8301. * @example
  8302. * $(document).ready( function() {
  8303. * $('#example').dataTable( {
  8304. * "fnFooterCallback": function( nFoot, aData, iStart, iEnd, aiDisplay ) {
  8305. * nFoot.getElementsByTagName('th')[0].innerHTML = "Starting index is "+iStart;
  8306. * }
  8307. * } );
  8308. * } )
  8309. */
  8310. "fnFooterCallback": null,
  8311.  
  8312.  
  8313. /**
  8314. * When rendering large numbers in the information element for the table
  8315. * (i.e. "Showing 1 to 10 of 57 entries") DataTables will render large numbers
  8316. * to have a comma separator for the 'thousands' units (e.g. 1 million is
  8317. * rendered as "1,000,000") to help readability for the end user. This
  8318. * function will override the default method DataTables uses.
  8319. * @type function
  8320. * @member
  8321. * @param {int} iIn number to be formatted
  8322. * @returns {string} formatted string for DataTables to show the number
  8323. * @dtopt Callbacks
  8324. *
  8325. * @example
  8326. * $(document).ready(function() {
  8327. * $('#example').dataTable( {
  8328. * "fnFormatNumber": function ( iIn ) {
  8329. * if ( iIn &lt; 1000 ) {
  8330. * return iIn;
  8331. * } else {
  8332. * var
  8333. * s=(iIn+""),
  8334. * a=s.split(""), out="",
  8335. * iLen=s.length;
  8336. *
  8337. * for ( var i=0 ; i&lt;iLen ; i++ ) {
  8338. * if ( i%3 === 0 &amp;&amp; i !== 0 ) {
  8339. * out = "'"+out;
  8340. * }
  8341. * out = a[iLen-i-1]+out;
  8342. * }
  8343. * }
  8344. * return out;
  8345. * };
  8346. * } );
  8347. * } );
  8348. */
  8349. "fnFormatNumber": function ( iIn ) {
  8350. if ( iIn < 1000 )
  8351. {
  8352. // A small optimisation for what is likely to be the majority of use cases
  8353. return iIn;
  8354. }
  8355.  
  8356. var s=(iIn+""), a=s.split(""), out="", iLen=s.length;
  8357.  
  8358. for ( var i=0 ; i<iLen ; i++ )
  8359. {
  8360. if ( i%3 === 0 && i !== 0 )
  8361. {
  8362. out = this.oLanguage.sInfoThousands+out;
  8363. }
  8364. out = a[iLen-i-1]+out;
  8365. }
  8366. return out;
  8367. },
  8368.  
  8369.  
  8370. /**
  8371. * This function is called on every 'draw' event, and allows you to
  8372. * dynamically modify the header row. This can be used to calculate and
  8373. * display useful information about the table.
  8374. * @type function
  8375. * @param {node} nHead "TR" element for the header
  8376. * @param {array} aData Full table data (as derived from the original HTML)
  8377. * @param {int} iStart Index for the current display starting point in the
  8378. * display array
  8379. * @param {int} iEnd Index for the current display ending point in the
  8380. * display array
  8381. * @param {array int} aiDisplay Index array to translate the visual position
  8382. * to the full data array
  8383. * @dtopt Callbacks
  8384. *
  8385. * @example
  8386. * $(document).ready( function() {
  8387. * $('#example').dataTable( {
  8388. * "fnHeaderCallback": function( nHead, aData, iStart, iEnd, aiDisplay ) {
  8389. * nHead.getElementsByTagName('th')[0].innerHTML = "Displaying "+(iEnd-iStart)+" records";
  8390. * }
  8391. * } );
  8392. * } )
  8393. */
  8394. "fnHeaderCallback": null,
  8395.  
  8396.  
  8397. /**
  8398. * The information element can be used to convey information about the current
  8399. * state of the table. Although the internationalisation options presented by
  8400. * DataTables are quite capable of dealing with most customisations, there may
  8401. * be times where you wish to customise the string further. This callback
  8402. * allows you to do exactly that.
  8403. * @type function
  8404. * @param {object} oSettings DataTables settings object
  8405. * @param {int} iStart Starting position in data for the draw
  8406. * @param {int} iEnd End position in data for the draw
  8407. * @param {int} iMax Total number of rows in the table (regardless of
  8408. * filtering)
  8409. * @param {int} iTotal Total number of rows in the data set, after filtering
  8410. * @param {string} sPre The string that DataTables has formatted using it's
  8411. * own rules
  8412. * @returns {string} The string to be displayed in the information element.
  8413. * @dtopt Callbacks
  8414. *
  8415. * @example
  8416. * $('#example').dataTable( {
  8417. * "fnInfoCallback": function( oSettings, iStart, iEnd, iMax, iTotal, sPre ) {
  8418. * return iStart +" to "+ iEnd;
  8419. * }
  8420. * } );
  8421. */
  8422. "fnInfoCallback": null,
  8423.  
  8424.  
  8425. /**
  8426. * Called when the table has been initialised. Normally DataTables will
  8427. * initialise sequentially and there will be no need for this function,
  8428. * however, this does not hold true when using external language information
  8429. * since that is obtained using an async XHR call.
  8430. * @type function
  8431. * @param {object} oSettings DataTables settings object
  8432. * @param {object} json The JSON object request from the server - only
  8433. * present if client-side Ajax sourced data is used
  8434. * @dtopt Callbacks
  8435. *
  8436. * @example
  8437. * $(document).ready( function() {
  8438. * $('#example').dataTable( {
  8439. * "fnInitComplete": function(oSettings, json) {
  8440. * alert( 'DataTables has finished its initialisation.' );
  8441. * }
  8442. * } );
  8443. * } )
  8444. */
  8445. "fnInitComplete": null,
  8446.  
  8447.  
  8448. /**
  8449. * Called at the very start of each table draw and can be used to cancel the
  8450. * draw by returning false, any other return (including undefined) results in
  8451. * the full draw occurring).
  8452. * @type function
  8453. * @param {object} oSettings DataTables settings object
  8454. * @returns {boolean} False will cancel the draw, anything else (including no
  8455. * return) will allow it to complete.
  8456. * @dtopt Callbacks
  8457. *
  8458. * @example
  8459. * $(document).ready( function() {
  8460. * $('#example').dataTable( {
  8461. * "fnPreDrawCallback": function( oSettings ) {
  8462. * if ( $('#test').val() == 1 ) {
  8463. * return false;
  8464. * }
  8465. * }
  8466. * } );
  8467. * } );
  8468. */
  8469. "fnPreDrawCallback": null,
  8470.  
  8471.  
  8472. /**
  8473. * This function allows you to 'post process' each row after it have been
  8474. * generated for each table draw, but before it is rendered on screen. This
  8475. * function might be used for setting the row class name etc.
  8476. * @type function
  8477. * @param {node} nRow "TR" element for the current row
  8478. * @param {array} aData Raw data array for this row
  8479. * @param {int} iDisplayIndex The display index for the current table draw
  8480. * @param {int} iDisplayIndexFull The index of the data in the full list of
  8481. * rows (after filtering)
  8482. * @dtopt Callbacks
  8483. *
  8484. * @example
  8485. * $(document).ready(function() {
  8486. * $('#example').dataTable( {
  8487. * "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
  8488. * // Bold the grade for all 'A' grade browsers
  8489. * if ( aData[4] == "A" )
  8490. * {
  8491. * $('td:eq(4)', nRow).html( '<b>A</b>' );
  8492. * }
  8493. * }
  8494. * } );
  8495. * } );
  8496. */
  8497. "fnRowCallback": null,
  8498.  
  8499.  
  8500. /**
  8501. * This parameter allows you to override the default function which obtains
  8502. * the data from the server ($.getJSON) so something more suitable for your
  8503. * application. For example you could use POST data, or pull information from
  8504. * a Gears or AIR database.
  8505. * @type function
  8506. * @member
  8507. * @param {string} sSource HTTP source to obtain the data from (sAjaxSource)
  8508. * @param {array} aoData A key/value pair object containing the data to send
  8509. * to the server
  8510. * @param {function} fnCallback to be called on completion of the data get
  8511. * process that will draw the data on the page.
  8512. * @param {object} oSettings DataTables settings object
  8513. * @dtopt Callbacks
  8514. * @dtopt Server-side
  8515. *
  8516. * @example
  8517. * // POST data to server
  8518. * $(document).ready(function() {
  8519. * $('#example').dataTable( {
  8520. * "bProcessing": true,
  8521. * "bServerSide": true,
  8522. * "sAjaxSource": "xhr.php",
  8523. * "fnServerData": function ( sSource, aoData, fnCallback ) {
  8524. * $.ajax( {
  8525. * "dataType": 'json',
  8526. * "type": "POST",
  8527. * "url": sSource,
  8528. * "data": aoData,
  8529. * "success": fnCallback
  8530. * } );
  8531. * }
  8532. * } );
  8533. * } );
  8534. */
  8535. "fnServerData": function ( sUrl, aoData, fnCallback, oSettings ) {
  8536. oSettings.jqXHR = $.ajax( {
  8537. "url": sUrl,
  8538. "data": aoData,
  8539. "success": function (json) {
  8540. $(oSettings.oInstance).trigger('xhr', oSettings);
  8541. fnCallback( json );
  8542. },
  8543. "dataType": "json",
  8544. "cache": false,
  8545. "type": oSettings.sServerMethod,
  8546. "error": function (xhr, error, thrown) {
  8547. if ( error == "parsererror" ) {
  8548. oSettings.oApi._fnLog( oSettings, 0, "DataTables warning: JSON data from "+
  8549. "server could not be parsed. This is caused by a JSON formatting error." );
  8550. }
  8551. }
  8552. } );
  8553. },
  8554.  
  8555.  
  8556. /**
  8557. * It is often useful to send extra data to the server when making an Ajax
  8558. * request - for example custom filtering information, and this callback
  8559. * function makes it trivial to send extra information to the server. The
  8560. * passed in parameter is the data set that has been constructed by
  8561. * DataTables, and you can add to this or modify it as you require.
  8562. * @type function
  8563. * @param {array} aoData Data array (array of objects which are name/value
  8564. * pairs) that has been constructed by DataTables and will be sent to the
  8565. * server. In the case of Ajax sourced data with server-side processing
  8566. * this will be an empty array, for server-side processing there will be a
  8567. * significant number of parameters!
  8568. * @returns {undefined} Ensure that you modify the aoData array passed in,
  8569. * as this is passed by reference.
  8570. * @dtopt Callbacks
  8571. * @dtopt Server-side
  8572. *
  8573. * @example
  8574. * $(document).ready(function() {
  8575. * $('#example').dataTable( {
  8576. * "bProcessing": true,
  8577. * "bServerSide": true,
  8578. * "sAjaxSource": "scripts/server_processing.php",
  8579. * "fnServerParams": function ( aoData ) {
  8580. * aoData.push( { "name": "more_data", "value": "my_value" } );
  8581. * }
  8582. * } );
  8583. * } );
  8584. */
  8585. "fnServerParams": null,
  8586.  
  8587.  
  8588. /**
  8589. * Load the table state. With this function you can define from where, and how, the
  8590. * state of a table is loaded. By default DataTables will load from its state saving
  8591. * cookie, but you might wish to use local storage (HTML5) or a server-side database.
  8592. * @type function
  8593. * @member
  8594. * @param {object} oSettings DataTables settings object
  8595. * @return {object} The DataTables state object to be loaded
  8596. * @dtopt Callbacks
  8597. *
  8598. * @example
  8599. * $(document).ready(function() {
  8600. * $('#example').dataTable( {
  8601. * "bStateSave": true,
  8602. * "fnStateLoad": function (oSettings, oData) {
  8603. * var o;
  8604. *
  8605. * // Send an Ajax request to the server to get the data. Note that
  8606. * // this is a synchronous request.
  8607. * $.ajax( {
  8608. * "url": "/state_load",
  8609. * "async": false,
  8610. * "dataType": "json",
  8611. * "success": function (json) {
  8612. * o = json;
  8613. * }
  8614. * } );
  8615. *
  8616. * return o;
  8617. * }
  8618. * } );
  8619. * } );
  8620. */
  8621. "fnStateLoad": function ( oSettings ) {
  8622. var sData = this.oApi._fnReadCookie( oSettings.sCookiePrefix+oSettings.sInstance );
  8623. var oData;
  8624.  
  8625. try {
  8626. oData = (typeof $.parseJSON === 'function') ?
  8627. $.parseJSON(sData) : eval( '('+sData+')' );
  8628. } catch (e) {
  8629. oData = null;
  8630. }
  8631.  
  8632. return oData;
  8633. },
  8634.  
  8635.  
  8636. /**
  8637. * Callback which allows modification of the saved state prior to loading that state.
  8638. * This callback is called when the table is loading state from the stored data, but
  8639. * prior to the settings object being modified by the saved state. Note that for
  8640. * plug-in authors, you should use the 'stateLoadParams' event to load parameters for
  8641. * a plug-in.
  8642. * @type function
  8643. * @param {object} oSettings DataTables settings object
  8644. * @param {object} oData The state object that is to be loaded
  8645. * @dtopt Callbacks
  8646. *
  8647. * @example
  8648. * // Remove a saved filter, so filtering is never loaded
  8649. * $(document).ready(function() {
  8650. * $('#example').dataTable( {
  8651. * "bStateSave": true,
  8652. * "fnStateLoadParams": function (oSettings, oData) {
  8653. * oData.oSearch.sSearch = "";
  8654. * } );
  8655. * } );
  8656. *
  8657. * @example
  8658. * // Disallow state loading by returning false
  8659. * $(document).ready(function() {
  8660. * $('#example').dataTable( {
  8661. * "bStateSave": true,
  8662. * "fnStateLoadParams": function (oSettings, oData) {
  8663. * return false;
  8664. * } );
  8665. * } );
  8666. */
  8667. "fnStateLoadParams": null,
  8668.  
  8669.  
  8670. /**
  8671. * Callback that is called when the state has been loaded from the state saving method
  8672. * and the DataTables settings object has been modified as a result of the loaded state.
  8673. * @type function
  8674. * @param {object} oSettings DataTables settings object
  8675. * @param {object} oData The state object that was loaded
  8676. * @dtopt Callbacks
  8677. *
  8678. * @example
  8679. * // Show an alert with the filtering value that was saved
  8680. * $(document).ready(function() {
  8681. * $('#example').dataTable( {
  8682. * "bStateSave": true,
  8683. * "fnStateLoaded": function (oSettings, oData) {
  8684. * alert( 'Saved filter was: '+oData.oSearch.sSearch );
  8685. * } );
  8686. * } );
  8687. */
  8688. "fnStateLoaded": null,
  8689.  
  8690.  
  8691. /**
  8692. * Save the table state. This function allows you to define where and how the state
  8693. * information for the table is stored - by default it will use a cookie, but you
  8694. * might want to use local storage (HTML5) or a server-side database.
  8695. * @type function
  8696. * @member
  8697. * @param {object} oSettings DataTables settings object
  8698. * @param {object} oData The state object to be saved
  8699. * @dtopt Callbacks
  8700. *
  8701. * @example
  8702. * $(document).ready(function() {
  8703. * $('#example').dataTable( {
  8704. * "bStateSave": true,
  8705. * "fnStateSave": function (oSettings, oData) {
  8706. * // Send an Ajax request to the server with the state object
  8707. * $.ajax( {
  8708. * "url": "/state_save",
  8709. * "data": oData,
  8710. * "dataType": "json",
  8711. * "method": "POST"
  8712. * "success": function () {}
  8713. * } );
  8714. * }
  8715. * } );
  8716. * } );
  8717. */
  8718. "fnStateSave": function ( oSettings, oData ) {
  8719. this.oApi._fnCreateCookie(
  8720. oSettings.sCookiePrefix+oSettings.sInstance,
  8721. this.oApi._fnJsonString(oData),
  8722. oSettings.iCookieDuration,
  8723. oSettings.sCookiePrefix,
  8724. oSettings.fnCookieCallback
  8725. );
  8726. },
  8727.  
  8728.  
  8729. /**
  8730. * Callback which allows modification of the state to be saved. Called when the table
  8731. * has changed state a new state save is required. This method allows modification of
  8732. * the state saving object prior to actually doing the save, including addition or
  8733. * other state properties or modification. Note that for plug-in authors, you should
  8734. * use the 'stateSaveParams' event to save parameters for a plug-in.
  8735. * @type function
  8736. * @param {object} oSettings DataTables settings object
  8737. * @param {object} oData The state object to be saved
  8738. * @dtopt Callbacks
  8739. *
  8740. * @example
  8741. * // Remove a saved filter, so filtering is never saved
  8742. * $(document).ready(function() {
  8743. * $('#example').dataTable( {
  8744. * "bStateSave": true,
  8745. * "fnStateSaveParams": function (oSettings, oData) {
  8746. * oData.oSearch.sSearch = "";
  8747. * } );
  8748. * } );
  8749. */
  8750. "fnStateSaveParams": null,
  8751.  
  8752.  
  8753. /**
  8754. * Duration of the cookie which is used for storing session information. This
  8755. * value is given in seconds.
  8756. * @type int
  8757. * @default 7200 <i>(2 hours)</i>
  8758. * @dtopt Options
  8759. *
  8760. * @example
  8761. * $(document).ready( function() {
  8762. * $('#example').dataTable( {
  8763. * "iCookieDuration": 60*60*24 // 1 day
  8764. * } );
  8765. * } )
  8766. */
  8767. "iCookieDuration": 7200,
  8768.  
  8769.  
  8770. /**
  8771. * When enabled DataTables will not make a request to the server for the first
  8772. * page draw - rather it will use the data already on the page (no sorting etc
  8773. * will be applied to it), thus saving on an XHR at load time. iDeferLoading
  8774. * is used to indicate that deferred loading is required, but it is also used
  8775. * to tell DataTables how many records there are in the full table (allowing
  8776. * the information element and pagination to be displayed correctly). In the case
  8777. * where a filtering is applied to the table on initial load, this can be
  8778. * indicated by giving the parameter as an array, where the first element is
  8779. * the number of records available after filtering and the second element is the
  8780. * number of records without filtering (allowing the table information element
  8781. * to be shown correctly).
  8782. * @type int | array
  8783. * @default null
  8784. * @dtopt Options
  8785. *
  8786. * @example
  8787. * // 57 records available in the table, no filtering applied
  8788. * $(document).ready(function() {
  8789. * $('#example').dataTable( {
  8790. * "bServerSide": true,
  8791. * "sAjaxSource": "scripts/server_processing.php",
  8792. * "iDeferLoading": 57
  8793. * } );
  8794. * } );
  8795. *
  8796. * @example
  8797. * // 57 records after filtering, 100 without filtering (an initial filter applied)
  8798. * $(document).ready(function() {
  8799. * $('#example').dataTable( {
  8800. * "bServerSide": true,
  8801. * "sAjaxSource": "scripts/server_processing.php",
  8802. * "iDeferLoading": [ 57, 100 ],
  8803. * "oSearch": {
  8804. * "sSearch": "my_filter"
  8805. * }
  8806. * } );
  8807. * } );
  8808. */
  8809. "iDeferLoading": null,
  8810.  
  8811.  
  8812. /**
  8813. * Number of rows to display on a single page when using pagination. If
  8814. * feature enabled (bLengthChange) then the end user will be able to override
  8815. * this to a custom setting using a pop-up menu.
  8816. * @type int
  8817. * @default 10
  8818. * @dtopt Options
  8819. *
  8820. * @example
  8821. * $(document).ready( function() {
  8822. * $('#example').dataTable( {
  8823. * "iDisplayLength": 50
  8824. * } );
  8825. * } )
  8826. */
  8827. "iDisplayLength": 10,
  8828.  
  8829.  
  8830. /**
  8831. * Define the starting point for data display when using DataTables with
  8832. * pagination. Note that this parameter is the number of records, rather than
  8833. * the page number, so if you have 10 records per page and want to start on
  8834. * the third page, it should be "20".
  8835. * @type int
  8836. * @default 0
  8837. * @dtopt Options
  8838. *
  8839. * @example
  8840. * $(document).ready( function() {
  8841. * $('#example').dataTable( {
  8842. * "iDisplayStart": 20
  8843. * } );
  8844. * } )
  8845. */
  8846. "iDisplayStart": 0,
  8847.  
  8848.  
  8849. /**
  8850. * The scroll gap is the amount of scrolling that is left to go before
  8851. * DataTables will load the next 'page' of data automatically. You typically
  8852. * want a gap which is big enough that the scrolling will be smooth for the
  8853. * user, while not so large that it will load more data than need.
  8854. * @type int
  8855. * @default 100
  8856. * @dtopt Options
  8857. *
  8858. * @example
  8859. * $(document).ready(function() {
  8860. * $('#example').dataTable( {
  8861. * "bScrollInfinite": true,
  8862. * "bScrollCollapse": true,
  8863. * "sScrollY": "200px",
  8864. * "iScrollLoadGap": 50
  8865. * } );
  8866. * } );
  8867. */
  8868. "iScrollLoadGap": 100,
  8869.  
  8870.  
  8871. /**
  8872. * By default DataTables allows keyboard navigation of the table (sorting, paging,
  8873. * and filtering) by adding a tabindex attribute to the required elements. This
  8874. * allows you to tab through the controls and press the enter key to activate them.
  8875. * The tabindex is default 0, meaning that the tab follows the flow of the document.
  8876. * You can overrule this using this parameter if you wish. Use a value of -1 to
  8877. * disable built-in keyboard navigation.
  8878. * @type int
  8879. * @default 0
  8880. * @dtopt Options
  8881. *
  8882. * @example
  8883. * $(document).ready(function() {
  8884. * $('#example').dataTable( {
  8885. * "iTabIndex": 1
  8886. * } );
  8887. * } );
  8888. */
  8889. "iTabIndex": 0,
  8890.  
  8891.  
  8892. /**
  8893. * All strings that DataTables uses in the user interface that it creates
  8894. * are defined in this object, allowing you to modified them individually or
  8895. * completely replace them all as required.
  8896. * @namespace
  8897. */
  8898. "oLanguage": {
  8899. /**
  8900. * Strings that are used for WAI-ARIA labels and controls only (these are not
  8901. * actually visible on the page, but will be read by screenreaders, and thus
  8902. * must be internationalised as well).
  8903. * @namespace
  8904. */
  8905. "oAria": {
  8906. /**
  8907. * ARIA label that is added to the table headers when the column may be
  8908. * sorted ascending by activing the column (click or return when focused).
  8909. * Note that the column header is prefixed to this string.
  8910. * @type string
  8911. * @default : activate to sort column ascending
  8912. * @dtopt Language
  8913. *
  8914. * @example
  8915. * $(document).ready(function() {
  8916. * $('#example').dataTable( {
  8917. * "oLanguage": {
  8918. * "oAria": {
  8919. * "sSortAscending": " - click/return to sort ascending"
  8920. * }
  8921. * }
  8922. * } );
  8923. * } );
  8924. */
  8925. "sSortAscending": ": activate to sort column ascending",
  8926.  
  8927. /**
  8928. * ARIA label that is added to the table headers when the column may be
  8929. * sorted descending by activing the column (click or return when focused).
  8930. * Note that the column header is prefixed to this string.
  8931. * @type string
  8932. * @default : activate to sort column ascending
  8933. * @dtopt Language
  8934. *
  8935. * @example
  8936. * $(document).ready(function() {
  8937. * $('#example').dataTable( {
  8938. * "oLanguage": {
  8939. * "oAria": {
  8940. * "sSortDescending": " - click/return to sort descending"
  8941. * }
  8942. * }
  8943. * } );
  8944. * } );
  8945. */
  8946. "sSortDescending": ": activate to sort column descending"
  8947. },
  8948.  
  8949. /**
  8950. * Pagination string used by DataTables for the two built-in pagination
  8951. * control types ("two_button" and "full_numbers")
  8952. * @namespace
  8953. */
  8954. "oPaginate": {
  8955. /**
  8956. * Text to use when using the 'full_numbers' type of pagination for the
  8957. * button to take the user to the first page.
  8958. * @type string
  8959. * @default First
  8960. * @dtopt Language
  8961. *
  8962. * @example
  8963. * $(document).ready(function() {
  8964. * $('#example').dataTable( {
  8965. * "oLanguage": {
  8966. * "oPaginate": {
  8967. * "sFirst": "First page"
  8968. * }
  8969. * }
  8970. * } );
  8971. * } );
  8972. */
  8973. "sFirst": "First",
  8974.  
  8975.  
  8976. /**
  8977. * Text to use when using the 'full_numbers' type of pagination for the
  8978. * button to take the user to the last page.
  8979. * @type string
  8980. * @default Last
  8981. * @dtopt Language
  8982. *
  8983. * @example
  8984. * $(document).ready(function() {
  8985. * $('#example').dataTable( {
  8986. * "oLanguage": {
  8987. * "oPaginate": {
  8988. * "sLast": "Last page"
  8989. * }
  8990. * }
  8991. * } );
  8992. * } );
  8993. */
  8994. "sLast": "Last",
  8995.  
  8996.  
  8997. /**
  8998. * Text to use when using the 'full_numbers' type of pagination for the
  8999. * button to take the user to the next page.
  9000. * @type string
  9001. * @default Next
  9002. * @dtopt Language
  9003. *
  9004. * @example
  9005. * $(document).ready(function() {
  9006. * $('#example').dataTable( {
  9007. * "oLanguage": {
  9008. * "oPaginate": {
  9009. * "sNext": "Next page"
  9010. * }
  9011. * }
  9012. * } );
  9013. * } );
  9014. */
  9015. "sNext": "Next",
  9016.  
  9017.  
  9018. /**
  9019. * Text to use when using the 'full_numbers' type of pagination for the
  9020. * button to take the user to the previous page.
  9021. * @type string
  9022. * @default Previous
  9023. * @dtopt Language
  9024. *
  9025. * @example
  9026. * $(document).ready(function() {
  9027. * $('#example').dataTable( {
  9028. * "oLanguage": {
  9029. * "oPaginate": {
  9030. * "sPrevious": "Previous page"
  9031. * }
  9032. * }
  9033. * } );
  9034. * } );
  9035. */
  9036. "sPrevious": "Previous"
  9037. },
  9038.  
  9039. /**
  9040. * This string is shown in preference to sZeroRecords when the table is
  9041. * empty of data (regardless of filtering). Note that this is an optional
  9042. * parameter - if it is not given, the value of sZeroRecords will be used
  9043. * instead (either the default or given value).
  9044. * @type string
  9045. * @default No data available in table
  9046. * @dtopt Language
  9047. *
  9048. * @example
  9049. * $(document).ready(function() {
  9050. * $('#example').dataTable( {
  9051. * "oLanguage": {
  9052. * "sEmptyTable": "No data available in table"
  9053. * }
  9054. * } );
  9055. * } );
  9056. */
  9057. "sEmptyTable": "No data available in table",
  9058.  
  9059.  
  9060. /**
  9061. * This string gives information to the end user about the information that
  9062. * is current on display on the page. The _START_, _END_ and _TOTAL_
  9063. * variables are all dynamically replaced as the table display updates, and
  9064. * can be freely moved or removed as the language requirements change.
  9065. * @type string
  9066. * @default Showing _START_ to _END_ of _TOTAL_ entries
  9067. * @dtopt Language
  9068. *
  9069. * @example
  9070. * $(document).ready(function() {
  9071. * $('#example').dataTable( {
  9072. * "oLanguage": {
  9073. * "sInfo": "Got a total of _TOTAL_ entries to show (_START_ to _END_)"
  9074. * }
  9075. * } );
  9076. * } );
  9077. */
  9078. "sInfo": "Showing _START_ to _END_ of _TOTAL_ entries",
  9079.  
  9080.  
  9081. /**
  9082. * Display information string for when the table is empty. Typically the
  9083. * format of this string should match sInfo.
  9084. * @type string
  9085. * @default Showing 0 to 0 of 0 entries
  9086. * @dtopt Language
  9087. *
  9088. * @example
  9089. * $(document).ready(function() {
  9090. * $('#example').dataTable( {
  9091. * "oLanguage": {
  9092. * "sInfoEmpty": "No entries to show"
  9093. * }
  9094. * } );
  9095. * } );
  9096. */
  9097. "sInfoEmpty": "Showing 0 to 0 of 0 entries",
  9098.  
  9099.  
  9100. /**
  9101. * When a user filters the information in a table, this string is appended
  9102. * to the information (sInfo) to give an idea of how strong the filtering
  9103. * is. The variable _MAX_ is dynamically updated.
  9104. * @type string
  9105. * @default (filtered from _MAX_ total entries)
  9106. * @dtopt Language
  9107. *
  9108. * @example
  9109. * $(document).ready(function() {
  9110. * $('#example').dataTable( {
  9111. * "oLanguage": {
  9112. * "sInfoFiltered": " - filtering from _MAX_ records"
  9113. * }
  9114. * } );
  9115. * } );
  9116. */
  9117. "sInfoFiltered": "(filtered from _MAX_ total entries)",
  9118.  
  9119.  
  9120. /**
  9121. * If can be useful to append extra information to the info string at times,
  9122. * and this variable does exactly that. This information will be appended to
  9123. * the sInfo (sInfoEmpty and sInfoFiltered in whatever combination they are
  9124. * being used) at all times.
  9125. * @type string
  9126. * @default <i>Empty string</i>
  9127. * @dtopt Language
  9128. *
  9129. * @example
  9130. * $(document).ready(function() {
  9131. * $('#example').dataTable( {
  9132. * "oLanguage": {
  9133. * "sInfoPostFix": "All records shown are derived from real information."
  9134. * }
  9135. * } );
  9136. * } );
  9137. */
  9138. "sInfoPostFix": "",
  9139.  
  9140.  
  9141. /**
  9142. * DataTables has a build in number formatter (fnFormatNumber) which is used
  9143. * to format large numbers that are used in the table information. By
  9144. * default a comma is used, but this can be trivially changed to any
  9145. * character you wish with this parameter.
  9146. * @type string
  9147. * @default ,
  9148. * @dtopt Language
  9149. *
  9150. * @example
  9151. * $(document).ready(function() {
  9152. * $('#example').dataTable( {
  9153. * "oLanguage": {
  9154. * "sInfoThousands": "'"
  9155. * }
  9156. * } );
  9157. * } );
  9158. */
  9159. "sInfoThousands": ",",
  9160.  
  9161.  
  9162. /**
  9163. * Detail the action that will be taken when the drop down menu for the
  9164. * pagination length option is changed. The '_MENU_' variable is replaced
  9165. * with a default select list of 10, 25, 50 and 100, and can be replaced
  9166. * with a custom select box if required.
  9167. * @type string
  9168. * @default Show _MENU_ entries
  9169. * @dtopt Language
  9170. *
  9171. * @example
  9172. * // Language change only
  9173. * $(document).ready(function() {
  9174. * $('#example').dataTable( {
  9175. * "oLanguage": {
  9176. * "sLengthMenu": "Display _MENU_ records"
  9177. * }
  9178. * } );
  9179. * } );
  9180. *
  9181. * @example
  9182. * // Language and options change
  9183. * $(document).ready(function() {
  9184. * $('#example').dataTable( {
  9185. * "oLanguage": {
  9186. * "sLengthMenu": 'Display <select>'+
  9187. * '<option value="10">10</option>'+
  9188. * '<option value="20">20</option>'+
  9189. * '<option value="30">30</option>'+
  9190. * '<option value="40">40</option>'+
  9191. * '<option value="50">50</option>'+
  9192. * '<option value="-1">All</option>'+
  9193. * '</select> records'
  9194. * }
  9195. * } );
  9196. * } );
  9197. */
  9198. "sLengthMenu": "Show _MENU_ entries",
  9199.  
  9200.  
  9201. /**
  9202. * When using Ajax sourced data and during the first draw when DataTables is
  9203. * gathering the data, this message is shown in an empty row in the table to
  9204. * indicate to the end user the the data is being loaded. Note that this
  9205. * parameter is not used when loading data by server-side processing, just
  9206. * Ajax sourced data with client-side processing.
  9207. * @type string
  9208. * @default Loading...
  9209. * @dtopt Language
  9210. *
  9211. * @example
  9212. * $(document).ready( function() {
  9213. * $('#example').dataTable( {
  9214. * "oLanguage": {
  9215. * "sLoadingRecords": "Please wait - loading..."
  9216. * }
  9217. * } );
  9218. * } );
  9219. */
  9220. "sLoadingRecords": "Loading...",
  9221.  
  9222.  
  9223. /**
  9224. * Text which is displayed when the table is processing a user action
  9225. * (usually a sort command or similar).
  9226. * @type string
  9227. * @default Processing...
  9228. * @dtopt Language
  9229. *
  9230. * @example
  9231. * $(document).ready(function() {
  9232. * $('#example').dataTable( {
  9233. * "oLanguage": {
  9234. * "sProcessing": "DataTables is currently busy"
  9235. * }
  9236. * } );
  9237. * } );
  9238. */
  9239. "sProcessing": "Processing...",
  9240.  
  9241.  
  9242. /**
  9243. * Details the actions that will be taken when the user types into the
  9244. * filtering input text box. The variable "_INPUT_", if used in the string,
  9245. * is replaced with the HTML text box for the filtering input allowing
  9246. * control over where it appears in the string. If "_INPUT_" is not given
  9247. * then the input box is appended to the string automatically.
  9248. * @type string
  9249. * @default Search:
  9250. * @dtopt Language
  9251. *
  9252. * @example
  9253. * // Input text box will be appended at the end automatically
  9254. * $(document).ready(function() {
  9255. * $('#example').dataTable( {
  9256. * "oLanguage": {
  9257. * "sSearch": "Filter records:"
  9258. * }
  9259. * } );
  9260. * } );
  9261. *
  9262. * @example
  9263. * // Specify where the filter should appear
  9264. * $(document).ready(function() {
  9265. * $('#example').dataTable( {
  9266. * "oLanguage": {
  9267. * "sSearch": "Apply filter _INPUT_ to table"
  9268. * }
  9269. * } );
  9270. * } );
  9271. */
  9272. "sSearch": "Search:",
  9273.  
  9274.  
  9275. /**
  9276. * All of the language information can be stored in a file on the
  9277. * server-side, which DataTables will look up if this parameter is passed.
  9278. * It must store the URL of the language file, which is in a JSON format,
  9279. * and the object has the same properties as the oLanguage object in the
  9280. * initialiser object (i.e. the above parameters). Please refer to one of
  9281. * the example language files to see how this works in action.
  9282. * @type string
  9283. * @default <i>Empty string - i.e. disabled</i>
  9284. * @dtopt Language
  9285. *
  9286. * @example
  9287. * $(document).ready(function() {
  9288. * $('#example').dataTable( {
  9289. * "oLanguage": {
  9290. * "sUrl": "http://www.sprymedia.co.uk/dataTables/lang.txt"
  9291. * }
  9292. * } );
  9293. * } );
  9294. */
  9295. "sUrl": "",
  9296.  
  9297.  
  9298. /**
  9299. * Text shown inside the table records when the is no information to be
  9300. * displayed after filtering. sEmptyTable is shown when there is simply no
  9301. * information in the table at all (regardless of filtering).
  9302. * @type string
  9303. * @default No matching records found
  9304. * @dtopt Language
  9305. *
  9306. * @example
  9307. * $(document).ready(function() {
  9308. * $('#example').dataTable( {
  9309. * "oLanguage": {
  9310. * "sZeroRecords": "No records to display"
  9311. * }
  9312. * } );
  9313. * } );
  9314. */
  9315. "sZeroRecords": "No matching records found"
  9316. },
  9317.  
  9318.  
  9319. /**
  9320. * This parameter allows you to have define the global filtering state at
  9321. * initialisation time. As an object the "sSearch" parameter must be
  9322. * defined, but all other parameters are optional. When "bRegex" is true,
  9323. * the search string will be treated as a regular expression, when false
  9324. * (default) it will be treated as a straight string. When "bSmart"
  9325. * DataTables will use it's smart filtering methods (to word match at
  9326. * any point in the data), when false this will not be done.
  9327. * @namespace
  9328. * @extends DataTable.models.oSearch
  9329. * @dtopt Options
  9330. *
  9331. * @example
  9332. * $(document).ready( function() {
  9333. * $('#example').dataTable( {
  9334. * "oSearch": {"sSearch": "Initial search"}
  9335. * } );
  9336. * } )
  9337. */
  9338. "oSearch": $.extend( {}, DataTable.models.oSearch ),
  9339.  
  9340.  
  9341. /**
  9342. * By default DataTables will look for the property 'aaData' when obtaining
  9343. * data from an Ajax source or for server-side processing - this parameter
  9344. * allows that property to be changed. You can use Javascript dotted object
  9345. * notation to get a data source for multiple levels of nesting.
  9346. * @type string
  9347. * @default aaData
  9348. * @dtopt Options
  9349. * @dtopt Server-side
  9350. *
  9351. * @example
  9352. * // Get data from { "data": [...] }
  9353. * $(document).ready(function() {
  9354. * var oTable = $('#example').dataTable( {
  9355. * "sAjaxSource": "sources/data.txt",
  9356. * "sAjaxDataProp": "data"
  9357. * } );
  9358. * } );
  9359. *
  9360. * @example
  9361. * // Get data from { "data": { "inner": [...] } }
  9362. * $(document).ready(function() {
  9363. * var oTable = $('#example').dataTable( {
  9364. * "sAjaxSource": "sources/data.txt",
  9365. * "sAjaxDataProp": "data.inner"
  9366. * } );
  9367. * } );
  9368. */
  9369. "sAjaxDataProp": "aaData",
  9370.  
  9371.  
  9372. /**
  9373. * You can instruct DataTables to load data from an external source using this
  9374. * parameter (use aData if you want to pass data in you already have). Simply
  9375. * provide a url a JSON object can be obtained from. This object must include
  9376. * the parameter 'aaData' which is the data source for the table.
  9377. * @type string
  9378. * @default null
  9379. * @dtopt Options
  9380. * @dtopt Server-side
  9381. *
  9382. * @example
  9383. * $(document).ready( function() {
  9384. * $('#example').dataTable( {
  9385. * "sAjaxSource": "http://www.sprymedia.co.uk/dataTables/json.php"
  9386. * } );
  9387. * } )
  9388. */
  9389. "sAjaxSource": null,
  9390.  
  9391.  
  9392. /**
  9393. * This parameter can be used to override the default prefix that DataTables
  9394. * assigns to a cookie when state saving is enabled.
  9395. * @type string
  9396. * @default SpryMedia_DataTables_
  9397. * @dtopt Options
  9398. *
  9399. * @example
  9400. * $(document).ready(function() {
  9401. * $('#example').dataTable( {
  9402. * "sCookiePrefix": "my_datatable_",
  9403. * } );
  9404. * } );
  9405. */
  9406. "sCookiePrefix": "SpryMedia_DataTables_",
  9407.  
  9408.  
  9409. /**
  9410. * This initialisation variable allows you to specify exactly where in the
  9411. * DOM you want DataTables to inject the various controls it adds to the page
  9412. * (for example you might want the pagination controls at the top of the
  9413. * table). DIV elements (with or without a custom class) can also be added to
  9414. * aid styling. The follow syntax is used:
  9415. * <ul>
  9416. * <li>The following options are allowed:
  9417. * <ul>
  9418. * <li>'l' - Length changing</li
  9419. * <li>'f' - Filtering input</li>
  9420. * <li>'t' - The table!</li>
  9421. * <li>'i' - Information</li>
  9422. * <li>'p' - Pagination</li>
  9423. * <li>'r' - pRocessing</li>
  9424. * </ul>
  9425. * </li>
  9426. * <li>The following constants are allowed:
  9427. * <ul>
  9428. * <li>'H' - jQueryUI theme "header" classes ('fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix')</li>
  9429. * <li>'F' - jQueryUI theme "footer" classes ('fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix')</li>
  9430. * </ul>
  9431. * </li>
  9432. * <li>The following syntax is expected:
  9433. * <ul>
  9434. * <li>'&lt;' and '&gt;' - div elements</li>
  9435. * <li>'&lt;"class" and '&gt;' - div with a class</li>
  9436. * <li>'&lt;"#id" and '&gt;' - div with an ID</li>
  9437. * </ul>
  9438. * </li>
  9439. * <li>Examples:
  9440. * <ul>
  9441. * <li>'&lt;"wrapper"flipt&gt;'</li>
  9442. * <li>'&lt;lf&lt;t&gt;ip&gt;'</li>
  9443. * </ul>
  9444. * </li>
  9445. * </ul>
  9446. * @type string
  9447. * @default lfrtip <i>(when bJQueryUI is false)</i> <b>or</b>
  9448. * <"H"lfr>t<"F"ip> <i>(when bJQueryUI is true)</i>
  9449. * @dtopt Options
  9450. *
  9451. * @example
  9452. * $(document).ready(function() {
  9453. * $('#example').dataTable( {
  9454. * "sDom": '&lt;"top"i&gt;rt&lt;"bottom"flp&gt;&lt;"clear"&lgt;'
  9455. * } );
  9456. * } );
  9457. */
  9458. "sDom": "lfrtip",
  9459.  
  9460.  
  9461. /**
  9462. * DataTables features two different built-in pagination interaction methods
  9463. * ('two_button' or 'full_numbers') which present different page controls to
  9464. * the end user. Further methods can be added using the API (see below).
  9465. * @type string
  9466. * @default two_button
  9467. * @dtopt Options
  9468. *
  9469. * @example
  9470. * $(document).ready( function() {
  9471. * $('#example').dataTable( {
  9472. * "sPaginationType": "full_numbers"
  9473. * } );
  9474. * } )
  9475. */
  9476. "sPaginationType": "two_button",
  9477.  
  9478.  
  9479. /**
  9480. * Enable horizontal scrolling. When a table is too wide to fit into a certain
  9481. * layout, or you have a large number of columns in the table, you can enable
  9482. * x-scrolling to show the table in a viewport, which can be scrolled. This
  9483. * property can be any CSS unit, or a number (in which case it will be treated
  9484. * as a pixel measurement).
  9485. * @type string
  9486. * @default <i>blank string - i.e. disabled</i>
  9487. * @dtopt Features
  9488. *
  9489. * @example
  9490. * $(document).ready(function() {
  9491. * $('#example').dataTable( {
  9492. * "sScrollX": "100%",
  9493. * "bScrollCollapse": true
  9494. * } );
  9495. * } );
  9496. */
  9497. "sScrollX": "",
  9498.  
  9499.  
  9500. /**
  9501. * This property can be used to force a DataTable to use more width than it
  9502. * might otherwise do when x-scrolling is enabled. For example if you have a
  9503. * table which requires to be well spaced, this parameter is useful for
  9504. * "over-sizing" the table, and thus forcing scrolling. This property can by
  9505. * any CSS unit, or a number (in which case it will be treated as a pixel
  9506. * measurement).
  9507. * @type string
  9508. * @default <i>blank string - i.e. disabled</i>
  9509. * @dtopt Options
  9510. *
  9511. * @example
  9512. * $(document).ready(function() {
  9513. * $('#example').dataTable( {
  9514. * "sScrollX": "100%",
  9515. * "sScrollXInner": "110%"
  9516. * } );
  9517. * } );
  9518. */
  9519. "sScrollXInner": "",
  9520.  
  9521.  
  9522. /**
  9523. * Enable vertical scrolling. Vertical scrolling will constrain the DataTable
  9524. * to the given height, and enable scrolling for any data which overflows the
  9525. * current viewport. This can be used as an alternative to paging to display
  9526. * a lot of data in a small area (although paging and scrolling can both be
  9527. * enabled at the same time). This property can be any CSS unit, or a number
  9528. * (in which case it will be treated as a pixel measurement).
  9529. * @type string
  9530. * @default <i>blank string - i.e. disabled</i>
  9531. * @dtopt Features
  9532. *
  9533. * @example
  9534. * $(document).ready(function() {
  9535. * $('#example').dataTable( {
  9536. * "sScrollY": "200px",
  9537. * "bPaginate": false
  9538. * } );
  9539. * } );
  9540. */
  9541. "sScrollY": "",
  9542.  
  9543.  
  9544. /**
  9545. * Set the HTTP method that is used to make the Ajax call for server-side
  9546. * processing or Ajax sourced data.
  9547. * @type string
  9548. * @default GET
  9549. * @dtopt Options
  9550. * @dtopt Server-side
  9551. *
  9552. * @example
  9553. * $(document).ready(function() {
  9554. * $('#example').dataTable( {
  9555. * "bServerSide": true,
  9556. * "sAjaxSource": "scripts/post.php",
  9557. * "sServerMethod": "POST"
  9558. * } );
  9559. * } );
  9560. */
  9561. "sServerMethod": "GET"
  9562. };
  9563.  
  9564.  
  9565.  
  9566. /**
  9567. * Column options that can be given to DataTables at initialisation time.
  9568. * @namespace
  9569. */
  9570. DataTable.defaults.columns = {
  9571. /**
  9572. * Allows a column's sorting to take multiple columns into account when
  9573. * doing a sort. For example first name / last name columns make sense to
  9574. * do a multi-column sort over the two columns.
  9575. * @type array
  9576. * @default null <i>Takes the value of the column index automatically</i>
  9577. * @dtopt Columns
  9578. *
  9579. * @example
  9580. * // Using aoColumnDefs
  9581. * $(document).ready(function() {
  9582. * $('#example').dataTable( {
  9583. * "aoColumnDefs": [
  9584. * { "aDataSort": [ 0, 1 ], "aTargets": [ 0 ] },
  9585. * { "aDataSort": [ 1, 0 ], "aTargets": [ 1 ] },
  9586. * { "aDataSort": [ 2, 3, 4 ], "aTargets": [ 2 ] }
  9587. * ]
  9588. * } );
  9589. * } );
  9590. *
  9591. * @example
  9592. * // Using aoColumns
  9593. * $(document).ready(function() {
  9594. * $('#example').dataTable( {
  9595. * "aoColumns": [
  9596. * { "aDataSort": [ 0, 1 ] },
  9597. * { "aDataSort": [ 1, 0 ] },
  9598. * { "aDataSort": [ 2, 3, 4 ] },
  9599. * null,
  9600. * null
  9601. * ]
  9602. * } );
  9603. * } );
  9604. */
  9605. "aDataSort": null,
  9606.  
  9607.  
  9608. /**
  9609. * You can control the default sorting direction, and even alter the behaviour
  9610. * of the sort handler (i.e. only allow ascending sorting etc) using this
  9611. * parameter.
  9612. * @type array
  9613. * @default [ 'asc', 'desc' ]
  9614. * @dtopt Columns
  9615. *
  9616. * @example
  9617. * // Using aoColumnDefs
  9618. * $(document).ready(function() {
  9619. * $('#example').dataTable( {
  9620. * "aoColumnDefs": [
  9621. * { "asSorting": [ "asc" ], "aTargets": [ 1 ] },
  9622. * { "asSorting": [ "desc", "asc", "asc" ], "aTargets": [ 2 ] },
  9623. * { "asSorting": [ "desc" ], "aTargets": [ 3 ] }
  9624. * ]
  9625. * } );
  9626. * } );
  9627. *
  9628. * @example
  9629. * // Using aoColumns
  9630. * $(document).ready(function() {
  9631. * $('#example').dataTable( {
  9632. * "aoColumns": [
  9633. * null,
  9634. * { "asSorting": [ "asc" ] },
  9635. * { "asSorting": [ "desc", "asc", "asc" ] },
  9636. * { "asSorting": [ "desc" ] },
  9637. * null
  9638. * ]
  9639. * } );
  9640. * } );
  9641. */
  9642. "asSorting": [ 'asc', 'desc' ],
  9643.  
  9644.  
  9645. /**
  9646. * Enable or disable filtering on the data in this column.
  9647. * @type boolean
  9648. * @default true
  9649. * @dtopt Columns
  9650. *
  9651. * @example
  9652. * // Using aoColumnDefs
  9653. * $(document).ready(function() {
  9654. * $('#example').dataTable( {
  9655. * "aoColumnDefs": [
  9656. * { "bSearchable": false, "aTargets": [ 0 ] }
  9657. * ] } );
  9658. * } );
  9659. *
  9660. * @example
  9661. * // Using aoColumns
  9662. * $(document).ready(function() {
  9663. * $('#example').dataTable( {
  9664. * "aoColumns": [
  9665. * { "bSearchable": false },
  9666. * null,
  9667. * null,
  9668. * null,
  9669. * null
  9670. * ] } );
  9671. * } );
  9672. */
  9673. "bSearchable": true,
  9674.  
  9675.  
  9676. /**
  9677. * Enable or disable sorting on this column.
  9678. * @type boolean
  9679. * @default true
  9680. * @dtopt Columns
  9681. *
  9682. * @example
  9683. * // Using aoColumnDefs
  9684. * $(document).ready(function() {
  9685. * $('#example').dataTable( {
  9686. * "aoColumnDefs": [
  9687. * { "bSortable": false, "aTargets": [ 0 ] }
  9688. * ] } );
  9689. * } );
  9690. *
  9691. * @example
  9692. * // Using aoColumns
  9693. * $(document).ready(function() {
  9694. * $('#example').dataTable( {
  9695. * "aoColumns": [
  9696. * { "bSortable": false },
  9697. * null,
  9698. * null,
  9699. * null,
  9700. * null
  9701. * ] } );
  9702. * } );
  9703. */
  9704. "bSortable": true,
  9705.  
  9706.  
  9707. /**
  9708. * When using fnRender() for a column, you may wish to use the original data
  9709. * (before rendering) for sorting and filtering (the default is to used the
  9710. * rendered data that the user can see). This may be useful for dates etc.
  9711. *
  9712. * *NOTE* It is it is advisable now to use mDataProp as a function and make
  9713. * use of the 'type' that it gives, allowing (potentially) different data to
  9714. * be used for sorting, filtering, display and type detection.
  9715. * @type boolean
  9716. * @default true
  9717. * @dtopt Columns
  9718. *
  9719. * @example
  9720. * // Using aoColumnDefs
  9721. * $(document).ready(function() {
  9722. * $('#example').dataTable( {
  9723. * "aoColumnDefs": [
  9724. * {
  9725. * "fnRender": function ( oObj ) {
  9726. * return oObj.aData[0] +' '+ oObj.aData[3];
  9727. * },
  9728. * "bUseRendered": false,
  9729. * "aTargets": [ 0 ]
  9730. * }
  9731. * ]
  9732. * } );
  9733. * } );
  9734. *
  9735. * @example
  9736. * // Using aoColumns
  9737. * $(document).ready(function() {
  9738. * $('#example').dataTable( {
  9739. * "aoColumns": [
  9740. * {
  9741. * "fnRender": function ( oObj ) {
  9742. * return oObj.aData[0] +' '+ oObj.aData[3];
  9743. * },
  9744. * "bUseRendered": false
  9745. * },
  9746. * null,
  9747. * null,
  9748. * null,
  9749. * null
  9750. * ]
  9751. * } );
  9752. * } );
  9753. */
  9754. "bUseRendered": true,
  9755.  
  9756.  
  9757. /**
  9758. * Enable or disable the display of this column.
  9759. * @type boolean
  9760. * @default true
  9761. * @dtopt Columns
  9762. *
  9763. * @example
  9764. * // Using aoColumnDefs
  9765. * $(document).ready(function() {
  9766. * $('#example').dataTable( {
  9767. * "aoColumnDefs": [
  9768. * { "bVisible": false, "aTargets": [ 0 ] }
  9769. * ] } );
  9770. * } );
  9771. *
  9772. * @example
  9773. * // Using aoColumns
  9774. * $(document).ready(function() {
  9775. * $('#example').dataTable( {
  9776. * "aoColumns": [
  9777. * { "bVisible": false },
  9778. * null,
  9779. * null,
  9780. * null,
  9781. * null
  9782. * ] } );
  9783. * } );
  9784. */
  9785. "bVisible": true,
  9786.  
  9787.  
  9788. /**
  9789. * Developer definable function that is called whenever a cell is created (Ajax source,
  9790. * etc) or processed for input (DOM source). This can be used as a compliment to fnRender
  9791. * allowing you to modify the DOM element (add background colour for example) when the
  9792. * element is available (since it is not when fnRender is called).
  9793. * @type function
  9794. * @param {element} nTd The TD node that has been created
  9795. * @param {*} sData The Data for the cell
  9796. * @param {array|object} oData The data for the whole row
  9797. * @param {int} iRow The row index for the aoData data store
  9798. * @param {int} iCol The column index for aoColumns
  9799. * @dtopt Columns
  9800. *
  9801. * @example
  9802. * $(document).ready(function() {
  9803. * $('#example').dataTable( {
  9804. * "aoColumnDefs": [ {
  9805. * "aTargets": [3],
  9806. * "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
  9807. * if ( sData == "1.7" ) {
  9808. * $(nTd).css('color', 'blue')
  9809. * }
  9810. * }
  9811. * } ]
  9812. * });
  9813. * } );
  9814. */
  9815. "fnCreatedCell": null,
  9816.  
  9817.  
  9818. /**
  9819. * Custom display function that will be called for the display of each cell in
  9820. * this column.
  9821. * @type function
  9822. * @param {object} o Object with the following parameters:
  9823. * @param {int} o.iDataRow The row in aoData
  9824. * @param {int} o.iDataColumn The column in question
  9825. * @param {array} o.aData The data for the row in question
  9826. * @param {object} o.oSettings The settings object for this DataTables instance
  9827. * @param {object} o.mDataProp The data property used for this column
  9828. * @param {*} val The current cell value
  9829. * @returns {string} The string you which to use in the display
  9830. * @dtopt Columns
  9831. *
  9832. * @example
  9833. * // Using aoColumnDefs
  9834. * $(document).ready(function() {
  9835. * $('#example').dataTable( {
  9836. * "aoColumnDefs": [
  9837. * {
  9838. * "fnRender": function ( o, val ) {
  9839. * return o.aData[0] +' '+ o.aData[3];
  9840. * },
  9841. * "aTargets": [ 0 ]
  9842. * }
  9843. * ]
  9844. * } );
  9845. * } );
  9846. *
  9847. * @example
  9848. * // Using aoColumns
  9849. * $(document).ready(function() {
  9850. * $('#example').dataTable( {
  9851. * "aoColumns": [
  9852. * { "fnRender": function ( o, val ) {
  9853. * return o.aData[0] +' '+ o.aData[3];
  9854. * } },
  9855. * null,
  9856. * null,
  9857. * null,
  9858. * null
  9859. * ]
  9860. * } );
  9861. * } );
  9862. */
  9863. "fnRender": null,
  9864.  
  9865.  
  9866. /**
  9867. * The column index (starting from 0!) that you wish a sort to be performed
  9868. * upon when this column is selected for sorting. This can be used for sorting
  9869. * on hidden columns for example.
  9870. * @type int
  9871. * @default -1 <i>Use automatically calculated column index</i>
  9872. * @dtopt Columns
  9873. *
  9874. * @example
  9875. * // Using aoColumnDefs
  9876. * $(document).ready(function() {
  9877. * $('#example').dataTable( {
  9878. * "aoColumnDefs": [
  9879. * { "iDataSort": 1, "aTargets": [ 0 ] }
  9880. * ]
  9881. * } );
  9882. * } );
  9883. *
  9884. * @example
  9885. * // Using aoColumns
  9886. * $(document).ready(function() {
  9887. * $('#example').dataTable( {
  9888. * "aoColumns": [
  9889. * { "iDataSort": 1 },
  9890. * null,
  9891. * null,
  9892. * null,
  9893. * null
  9894. * ]
  9895. * } );
  9896. * } );
  9897. */
  9898. "iDataSort": -1,
  9899.  
  9900.  
  9901. /**
  9902. * This property can be used to read data from any JSON data source property,
  9903. * including deeply nested objects / properties. mDataProp can be given in a
  9904. * number of different ways which effect its behaviour:
  9905. * <ul>
  9906. * <li>integer - treated as an array index for the data source. This is the
  9907. * default that DataTables uses (incrementally increased for each column).</li>
  9908. * <li>string - read an object property from the data source. Note that you can
  9909. * use Javascript dotted notation to read deep properties/arrays from the
  9910. * data source.</li>
  9911. * <li>null - the sDefaultContent option will be used for the cell (null
  9912. * by default, so you will need to specify the default content you want -
  9913. * typically an empty string). This can be useful on generated columns such
  9914. * as edit / delete action columns.</li>
  9915. * <li>function - the function given will be executed whenever DataTables
  9916. * needs to set or get the data for a cell in the column. The function
  9917. * takes three parameters:
  9918. * <ul>
  9919. * <li>{array|object} The data source for the row</li>
  9920. * <li>{string} The type call data requested - this will be 'set' when
  9921. * setting data or 'filter', 'display', 'type', 'sort' or undefined when
  9922. * gathering data. Note that when <i>undefined</i> is given for the type
  9923. * DataTables expects to get the raw data for the object back</li>
  9924. * <li>{*} Data to set when the second parameter is 'set'.</li>
  9925. * </ul>
  9926. * The return value from the function is not required when 'set' is the type
  9927. * of call, but otherwise the return is what will be used for the data
  9928. * requested.</li>
  9929. * </ul>
  9930. * @type string|int|function|null
  9931. * @default null <i>Use automatically calculated column index</i>
  9932. * @dtopt Columns
  9933. *
  9934. * @example
  9935. * // Read table data from objects
  9936. * $(document).ready(function() {
  9937. * var oTable = $('#example').dataTable( {
  9938. * "sAjaxSource": "sources/deep.txt",
  9939. * "aoColumns": [
  9940. * { "mDataProp": "engine" },
  9941. * { "mDataProp": "browser" },
  9942. * { "mDataProp": "platform.inner" },
  9943. * { "mDataProp": "platform.details.0" },
  9944. * { "mDataProp": "platform.details.1" }
  9945. * ]
  9946. * } );
  9947. * } );
  9948. *
  9949. * @example
  9950. * // Using mDataProp as a function to provide different information for
  9951. * // sorting, filtering and display. In this case, currency (price)
  9952. * $(document).ready(function() {
  9953. * var oTable = $('#example').dataTable( {
  9954. * "aoColumnDefs": [
  9955. * {
  9956. * "aTargets": [ 0 ],
  9957. * "mDataProp": function ( source, type, val ) {
  9958. * if (type === 'set') {
  9959. * source.price = val;
  9960. * // Store the computed dislay and filter values for efficiency
  9961. * source.price_display = val=="" ? "" : "$"+numberFormat(val);
  9962. * source.price_filter = val=="" ? "" : "$"+numberFormat(val)+" "+val;
  9963. * return;
  9964. * }
  9965. * else if (type === 'display') {
  9966. * return source.price_display;
  9967. * }
  9968. * else if (type === 'filter') {
  9969. * return source.price_filter;
  9970. * }
  9971. * // 'sort', 'type' and undefined all just use the integer
  9972. * return source.price;
  9973. * }
  9974. * ]
  9975. * } );
  9976. * } );
  9977. */
  9978. "mDataProp": null,
  9979.  
  9980.  
  9981. /**
  9982. * Change the cell type created for the column - either TD cells or TH cells. This
  9983. * can be useful as TH cells have semantic meaning in the table body, allowing them
  9984. * to act as a header for a row (you may wish to add scope='row' to the TH elements).
  9985. * @type string
  9986. * @default td
  9987. * @dtopt Columns
  9988. *
  9989. * @example
  9990. * // Make the first column use TH cells
  9991. * $(document).ready(function() {
  9992. * var oTable = $('#example').dataTable( {
  9993. * "aoColumnDefs": [
  9994. * {
  9995. * "aTargets": [ 0 ],
  9996. * "sCellType": "th"
  9997. * ]
  9998. * } );
  9999. * } );
  10000. */
  10001. "sCellType": "td",
  10002.  
  10003.  
  10004. /**
  10005. * Class to give to each cell in this column.
  10006. * @type string
  10007. * @default <i>Empty string</i>
  10008. * @dtopt Columns
  10009. *
  10010. * @example
  10011. * // Using aoColumnDefs
  10012. * $(document).ready(function() {
  10013. * $('#example').dataTable( {
  10014. * "aoColumnDefs": [
  10015. * { "sClass": "my_class", "aTargets": [ 0 ] }
  10016. * ]
  10017. * } );
  10018. * } );
  10019. *
  10020. * @example
  10021. * // Using aoColumns
  10022. * $(document).ready(function() {
  10023. * $('#example').dataTable( {
  10024. * "aoColumns": [
  10025. * { "sClass": "my_class" },
  10026. * null,
  10027. * null,
  10028. * null,
  10029. * null
  10030. * ]
  10031. * } );
  10032. * } );
  10033. */
  10034. "sClass": "",
  10035.  
  10036. /**
  10037. * When DataTables calculates the column widths to assign to each column,
  10038. * it finds the longest string in each column and then constructs a
  10039. * temporary table and reads the widths from that. The problem with this
  10040. * is that "mmm" is much wider then "iiii", but the latter is a longer
  10041. * string - thus the calculation can go wrong (doing it properly and putting
  10042. * it into an DOM object and measuring that is horribly(!) slow). Thus as
  10043. * a "work around" we provide this option. It will append its value to the
  10044. * text that is found to be the longest string for the column - i.e. padding.
  10045. * Generally you shouldn't need this, and it is not documented on the
  10046. * general DataTables.net documentation
  10047. * @type string
  10048. * @default <i>Empty string<i>
  10049. * @dtopt Columns
  10050. *
  10051. * @example
  10052. * // Using aoColumns
  10053. * $(document).ready(function() {
  10054. * $('#example').dataTable( {
  10055. * "aoColumns": [
  10056. * null,
  10057. * null,
  10058. * null,
  10059. * {
  10060. * "sContentPadding": "mmm"
  10061. * }
  10062. * ]
  10063. * } );
  10064. * } );
  10065. */
  10066. "sContentPadding": "",
  10067.  
  10068.  
  10069. /**
  10070. * Allows a default value to be given for a column's data, and will be used
  10071. * whenever a null data source is encountered (this can be because mDataProp
  10072. * is set to null, or because the data source itself is null).
  10073. * @type string
  10074. * @default null
  10075. * @dtopt Columns
  10076. *
  10077. * @example
  10078. * // Using aoColumnDefs
  10079. * $(document).ready(function() {
  10080. * $('#example').dataTable( {
  10081. * "aoColumnDefs": [
  10082. * {
  10083. * "mDataProp": null,
  10084. * "sDefaultContent": "Edit",
  10085. * "aTargets": [ -1 ]
  10086. * }
  10087. * ]
  10088. * } );
  10089. * } );
  10090. *
  10091. * @example
  10092. * // Using aoColumns
  10093. * $(document).ready(function() {
  10094. * $('#example').dataTable( {
  10095. * "aoColumns": [
  10096. * null,
  10097. * null,
  10098. * null,
  10099. * {
  10100. * "mDataProp": null,
  10101. * "sDefaultContent": "Edit"
  10102. * }
  10103. * ]
  10104. * } );
  10105. * } );
  10106. */
  10107. "sDefaultContent": null,
  10108.  
  10109.  
  10110. /**
  10111. * This parameter is only used in DataTables' server-side processing. It can
  10112. * be exceptionally useful to know what columns are being displayed on the
  10113. * client side, and to map these to database fields. When defined, the names
  10114. * also allow DataTables to reorder information from the server if it comes
  10115. * back in an unexpected order (i.e. if you switch your columns around on the
  10116. * client-side, your server-side code does not also need updating).
  10117. * @type string
  10118. * @default <i>Empty string</i>
  10119. * @dtopt Columns
  10120. *
  10121. * @example
  10122. * // Using aoColumnDefs
  10123. * $(document).ready(function() {
  10124. * $('#example').dataTable( {
  10125. * "aoColumnDefs": [
  10126. * { "sName": "engine", "aTargets": [ 0 ] },
  10127. * { "sName": "browser", "aTargets": [ 1 ] },
  10128. * { "sName": "platform", "aTargets": [ 2 ] },
  10129. * { "sName": "version", "aTargets": [ 3 ] },
  10130. * { "sName": "grade", "aTargets": [ 4 ] }
  10131. * ]
  10132. * } );
  10133. * } );
  10134. *
  10135. * @example
  10136. * // Using aoColumns
  10137. * $(document).ready(function() {
  10138. * $('#example').dataTable( {
  10139. * "aoColumns": [
  10140. * { "sName": "engine" },
  10141. * { "sName": "browser" },
  10142. * { "sName": "platform" },
  10143. * { "sName": "version" },
  10144. * { "sName": "grade" }
  10145. * ]
  10146. * } );
  10147. * } );
  10148. */
  10149. "sName": "",
  10150.  
  10151.  
  10152. /**
  10153. * Defines a data source type for the sorting which can be used to read
  10154. * realtime information from the table (updating the internally cached
  10155. * version) prior to sorting. This allows sorting to occur on user editable
  10156. * elements such as form inputs.
  10157. * @type string
  10158. * @default std
  10159. * @dtopt Columns
  10160. *
  10161. * @example
  10162. * // Using aoColumnDefs
  10163. * $(document).ready(function() {
  10164. * $('#example').dataTable( {
  10165. * "aoColumnDefs": [
  10166. * { "sSortDataType": "dom-text", "aTargets": [ 2, 3 ] },
  10167. * { "sType": "numeric", "aTargets": [ 3 ] },
  10168. * { "sSortDataType": "dom-select", "aTargets": [ 4 ] },
  10169. * { "sSortDataType": "dom-checkbox", "aTargets": [ 5 ] }
  10170. * ]
  10171. * } );
  10172. * } );
  10173. *
  10174. * @example
  10175. * // Using aoColumns
  10176. * $(document).ready(function() {
  10177. * $('#example').dataTable( {
  10178. * "aoColumns": [
  10179. * null,
  10180. * null,
  10181. * { "sSortDataType": "dom-text" },
  10182. * { "sSortDataType": "dom-text", "sType": "numeric" },
  10183. * { "sSortDataType": "dom-select" },
  10184. * { "sSortDataType": "dom-checkbox" }
  10185. * ]
  10186. * } );
  10187. * } );
  10188. */
  10189. "sSortDataType": "std",
  10190.  
  10191.  
  10192. /**
  10193. * The title of this column.
  10194. * @type string
  10195. * @default null <i>Derived from the 'TH' value for this column in the
  10196. * original HTML table.</i>
  10197. * @dtopt Columns
  10198. *
  10199. * @example
  10200. * // Using aoColumnDefs
  10201. * $(document).ready(function() {
  10202. * $('#example').dataTable( {
  10203. * "aoColumnDefs": [
  10204. * { "sTitle": "My column title", "aTargets": [ 0 ] }
  10205. * ]
  10206. * } );
  10207. * } );
  10208. *
  10209. * @example
  10210. * // Using aoColumns
  10211. * $(document).ready(function() {
  10212. * $('#example').dataTable( {
  10213. * "aoColumns": [
  10214. * { "sTitle": "My column title" },
  10215. * null,
  10216. * null,
  10217. * null,
  10218. * null
  10219. * ]
  10220. * } );
  10221. * } );
  10222. */
  10223. "sTitle": null,
  10224.  
  10225.  
  10226. /**
  10227. * The type allows you to specify how the data for this column will be sorted.
  10228. * Four types (string, numeric, date and html (which will strip HTML tags
  10229. * before sorting)) are currently available. Note that only date formats
  10230. * understood by Javascript's Date() object will be accepted as type date. For
  10231. * example: "Mar 26, 2008 5:03 PM". May take the values: 'string', 'numeric',
  10232. * 'date' or 'html' (by default). Further types can be adding through
  10233. * plug-ins.
  10234. * @type string
  10235. * @default null <i>Auto-detected from raw data</i>
  10236. * @dtopt Columns
  10237. *
  10238. * @example
  10239. * // Using aoColumnDefs
  10240. * $(document).ready(function() {
  10241. * $('#example').dataTable( {
  10242. * "aoColumnDefs": [
  10243. * { "sType": "html", "aTargets": [ 0 ] }
  10244. * ]
  10245. * } );
  10246. * } );
  10247. *
  10248. * @example
  10249. * // Using aoColumns
  10250. * $(document).ready(function() {
  10251. * $('#example').dataTable( {
  10252. * "aoColumns": [
  10253. * { "sType": "html" },
  10254. * null,
  10255. * null,
  10256. * null,
  10257. * null
  10258. * ]
  10259. * } );
  10260. * } );
  10261. */
  10262. "sType": null,
  10263.  
  10264.  
  10265. /**
  10266. * Defining the width of the column, this parameter may take any CSS value
  10267. * (3em, 20px etc). DataTables applys 'smart' widths to columns which have not
  10268. * been given a specific width through this interface ensuring that the table
  10269. * remains readable.
  10270. * @type string
  10271. * @default null <i>Automatic</i>
  10272. * @dtopt Columns
  10273. *
  10274. * @example
  10275. * // Using aoColumnDefs
  10276. * $(document).ready(function() {
  10277. * $('#example').dataTable( {
  10278. * "aoColumnDefs": [
  10279. * { "sWidth": "20%", "aTargets": [ 0 ] }
  10280. * ]
  10281. * } );
  10282. * } );
  10283. *
  10284. * @example
  10285. * // Using aoColumns
  10286. * $(document).ready(function() {
  10287. * $('#example').dataTable( {
  10288. * "aoColumns": [
  10289. * { "sWidth": "20%" },
  10290. * null,
  10291. * null,
  10292. * null,
  10293. * null
  10294. * ]
  10295. * } );
  10296. * } );
  10297. */
  10298. "sWidth": null
  10299. };
  10300.  
  10301.  
  10302.  
  10303. /**
  10304. * DataTables settings object - this holds all the information needed for a
  10305. * given table, including configuration, data and current application of the
  10306. * table options. DataTables does not have a single instance for each DataTable
  10307. * with the settings attached to that instance, but rather instances of the
  10308. * DataTable "class" are created on-the-fly as needed (typically by a
  10309. * $().dataTable() call) and the settings object is then applied to that
  10310. * instance.
  10311. *
  10312. * Note that this object is related to {@link DataTable.defaults} but this
  10313. * one is the internal data store for DataTables's cache of columns. It should
  10314. * NOT be manipulated outside of DataTables. Any configuration should be done
  10315. * through the initialisation options.
  10316. * @namespace
  10317. * @todo Really should attach the settings object to individual instances so we
  10318. * don't need to create new instances on each $().dataTable() call (if the
  10319. * table already exists). It would also save passing oSettings around and
  10320. * into every single function. However, this is a very significant
  10321. * architecture change for DataTables and will almost certainly break
  10322. * backwards compatibility with older installations. This is something that
  10323. * will be done in 2.0.
  10324. */
  10325. DataTable.models.oSettings = {
  10326. /**
  10327. * Primary features of DataTables and their enablement state.
  10328. * @namespace
  10329. */
  10330. "oFeatures": {
  10331.  
  10332. /**
  10333. * Flag to say if DataTables should automatically try to calculate the
  10334. * optimum table and columns widths (true) or not (false).
  10335. * Note that this parameter will be set by the initialisation routine. To
  10336. * set a default use {@link DataTable.defaults}.
  10337. * @type boolean
  10338. */
  10339. "bAutoWidth": null,
  10340.  
  10341. /**
  10342. * Delay the creation of TR and TD elements until they are actually
  10343. * needed by a driven page draw. This can give a significant speed
  10344. * increase for Ajax source and Javascript source data, but makes no
  10345. * difference at all fro DOM and server-side processing tables.
  10346. * Note that this parameter will be set by the initialisation routine. To
  10347. * set a default use {@link DataTable.defaults}.
  10348. * @type boolean
  10349. */
  10350. "bDeferRender": null,
  10351.  
  10352. /**
  10353. * Enable filtering on the table or not. Note that if this is disabled
  10354. * then there is no filtering at all on the table, including fnFilter.
  10355. * To just remove the filtering input use sDom and remove the 'f' option.
  10356. * Note that this parameter will be set by the initialisation routine. To
  10357. * set a default use {@link DataTable.defaults}.
  10358. * @type boolean
  10359. */
  10360. "bFilter": null,
  10361.  
  10362. /**
  10363. * Table information element (the 'Showing x of y records' div) enable
  10364. * flag.
  10365. * Note that this parameter will be set by the initialisation routine. To
  10366. * set a default use {@link DataTable.defaults}.
  10367. * @type boolean
  10368. */
  10369. "bInfo": null,
  10370.  
  10371. /**
  10372. * Present a user control allowing the end user to change the page size
  10373. * when pagination is enabled.
  10374. * Note that this parameter will be set by the initialisation routine. To
  10375. * set a default use {@link DataTable.defaults}.
  10376. * @type boolean
  10377. */
  10378. "bLengthChange": null,
  10379.  
  10380. /**
  10381. * Pagination enabled or not. Note that if this is disabled then length
  10382. * changing must also be disabled.
  10383. * Note that this parameter will be set by the initialisation routine. To
  10384. * set a default use {@link DataTable.defaults}.
  10385. * @type boolean
  10386. */
  10387. "bPaginate": null,
  10388.  
  10389. /**
  10390. * Processing indicator enable flag whenever DataTables is enacting a
  10391. * user request - typically an Ajax request for server-side processing.
  10392. * Note that this parameter will be set by the initialisation routine. To
  10393. * set a default use {@link DataTable.defaults}.
  10394. * @type boolean
  10395. */
  10396. "bProcessing": null,
  10397.  
  10398. /**
  10399. * Server-side processing enabled flag - when enabled DataTables will
  10400. * get all data from the server for every draw - there is no filtering,
  10401. * sorting or paging done on the client-side.
  10402. * Note that this parameter will be set by the initialisation routine. To
  10403. * set a default use {@link DataTable.defaults}.
  10404. * @type boolean
  10405. */
  10406. "bServerSide": null,
  10407.  
  10408. /**
  10409. * Sorting enablement flag.
  10410. * Note that this parameter will be set by the initialisation routine. To
  10411. * set a default use {@link DataTable.defaults}.
  10412. * @type boolean
  10413. */
  10414. "bSort": null,
  10415.  
  10416. /**
  10417. * Apply a class to the columns which are being sorted to provide a
  10418. * visual highlight or not. This can slow things down when enabled since
  10419. * there is a lot of DOM interaction.
  10420. * Note that this parameter will be set by the initialisation routine. To
  10421. * set a default use {@link DataTable.defaults}.
  10422. * @type boolean
  10423. */
  10424. "bSortClasses": null,
  10425.  
  10426. /**
  10427. * State saving enablement flag.
  10428. * Note that this parameter will be set by the initialisation routine. To
  10429. * set a default use {@link DataTable.defaults}.
  10430. * @type boolean
  10431. */
  10432. "bStateSave": null
  10433. },
  10434.  
  10435.  
  10436. /**
  10437. * Scrolling settings for a table.
  10438. * @namespace
  10439. */
  10440. "oScroll": {
  10441. /**
  10442. * Indicate if DataTables should be allowed to set the padding / margin
  10443. * etc for the scrolling header elements or not. Typically you will want
  10444. * this.
  10445. * Note that this parameter will be set by the initialisation routine. To
  10446. * set a default use {@link DataTable.defaults}.
  10447. * @type boolean
  10448. */
  10449. "bAutoCss": null,
  10450.  
  10451. /**
  10452. * When the table is shorter in height than sScrollY, collapse the
  10453. * table container down to the height of the table (when true).
  10454. * Note that this parameter will be set by the initialisation routine. To
  10455. * set a default use {@link DataTable.defaults}.
  10456. * @type boolean
  10457. */
  10458. "bCollapse": null,
  10459.  
  10460. /**
  10461. * Infinite scrolling enablement flag. Now deprecated in favour of
  10462. * using the Scroller plug-in.
  10463. * Note that this parameter will be set by the initialisation routine. To
  10464. * set a default use {@link DataTable.defaults}.
  10465. * @type boolean
  10466. */
  10467. "bInfinite": null,
  10468.  
  10469. /**
  10470. * Width of the scrollbar for the web-browser's platform. Calculated
  10471. * during table initialisation.
  10472. * @type int
  10473. * @default 0
  10474. */
  10475. "iBarWidth": 0,
  10476.  
  10477. /**
  10478. * Space (in pixels) between the bottom of the scrolling container and
  10479. * the bottom of the scrolling viewport before the next page is loaded
  10480. * when using infinite scrolling.
  10481. * Note that this parameter will be set by the initialisation routine. To
  10482. * set a default use {@link DataTable.defaults}.
  10483. * @type int
  10484. */
  10485. "iLoadGap": null,
  10486.  
  10487. /**
  10488. * Viewport width for horizontal scrolling. Horizontal scrolling is
  10489. * disabled if an empty string.
  10490. * Note that this parameter will be set by the initialisation routine. To
  10491. * set a default use {@link DataTable.defaults}.
  10492. * @type string
  10493. */
  10494. "sX": null,
  10495.  
  10496. /**
  10497. * Width to expand the table to when using x-scrolling. Typically you
  10498. * should not need to use this.
  10499. * Note that this parameter will be set by the initialisation routine. To
  10500. * set a default use {@link DataTable.defaults}.
  10501. * @type string
  10502. * @deprecated
  10503. */
  10504. "sXInner": null,
  10505.  
  10506. /**
  10507. * Viewport height for vertical scrolling. Vertical scrolling is disabled
  10508. * if an empty string.
  10509. * Note that this parameter will be set by the initialisation routine. To
  10510. * set a default use {@link DataTable.defaults}.
  10511. * @type string
  10512. */
  10513. "sY": null
  10514. },
  10515.  
  10516. /**
  10517. * Language information for the table.
  10518. * @namespace
  10519. * @extends DataTable.defaults.oLanguage
  10520. */
  10521. "oLanguage": {
  10522. /**
  10523. * Information callback function. See
  10524. * {@link DataTable.defaults.fnInfoCallback}
  10525. * @type function
  10526. * @default
  10527. */
  10528. "fnInfoCallback": null
  10529. },
  10530.  
  10531. /**
  10532. * Array referencing the nodes which are used for the features. The
  10533. * parameters of this object match what is allowed by sDom - i.e.
  10534. * <ul>
  10535. * <li>'l' - Length changing</li>
  10536. * <li>'f' - Filtering input</li>
  10537. * <li>'t' - The table!</li>
  10538. * <li>'i' - Information</li>
  10539. * <li>'p' - Pagination</li>
  10540. * <li>'r' - pRocessing</li>
  10541. * </ul>
  10542. * @type array
  10543. * @default []
  10544. */
  10545. "aanFeatures": [],
  10546.  
  10547. /**
  10548. * Store data information - see {@link DataTable.models.oRow} for detailed
  10549. * information.
  10550. * @type array
  10551. * @default []
  10552. */
  10553. "aoData": [],
  10554.  
  10555. /**
  10556. * Array of indexes which are in the current display (after filtering etc)
  10557. * @type array
  10558. * @default []
  10559. */
  10560. "aiDisplay": [],
  10561.  
  10562. /**
  10563. * Array of indexes for display - no filtering
  10564. * @type array
  10565. * @default []
  10566. */
  10567. "aiDisplayMaster": [],
  10568.  
  10569. /**
  10570. * Store information about each column that is in use
  10571. * @type array
  10572. * @default []
  10573. */
  10574. "aoColumns": [],
  10575.  
  10576. /**
  10577. * Store information about the table's header
  10578. * @type array
  10579. * @default []
  10580. */
  10581. "aoHeader": [],
  10582.  
  10583. /**
  10584. * Store information about the table's footer
  10585. * @type array
  10586. * @default []
  10587. */
  10588. "aoFooter": [],
  10589.  
  10590. /**
  10591. * Search data array for regular expression searching
  10592. * @type array
  10593. * @default []
  10594. */
  10595. "asDataSearch": [],
  10596.  
  10597. /**
  10598. * Store the applied global search information in case we want to force a
  10599. * research or compare the old search to a new one.
  10600. * Note that this parameter will be set by the initialisation routine. To
  10601. * set a default use {@link DataTable.defaults}.
  10602. * @namespace
  10603. * @extends DataTable.models.oSearch
  10604. */
  10605. "oPreviousSearch": {},
  10606.  
  10607. /**
  10608. * Store the applied search for each column - see
  10609. * {@link DataTable.models.oSearch} for the format that is used for the
  10610. * filtering information for each column.
  10611. * @type array
  10612. * @default []
  10613. */
  10614. "aoPreSearchCols": [],
  10615.  
  10616. /**
  10617. * Sorting that is applied to the table. Note that the inner arrays are
  10618. * used in the following manner:
  10619. * <ul>
  10620. * <li>Index 0 - column number</li>
  10621. * <li>Index 1 - current sorting direction</li>
  10622. * <li>Index 2 - index of asSorting for this column</li>
  10623. * </ul>
  10624. * Note that this parameter will be set by the initialisation routine. To
  10625. * set a default use {@link DataTable.defaults}.
  10626. * @type array
  10627. * @todo These inner arrays should really be objects
  10628. */
  10629. "aaSorting": null,
  10630.  
  10631. /**
  10632. * Sorting that is always applied to the table (i.e. prefixed in front of
  10633. * aaSorting).
  10634. * Note that this parameter will be set by the initialisation routine. To
  10635. * set a default use {@link DataTable.defaults}.
  10636. * @type array|null
  10637. * @default null
  10638. */
  10639. "aaSortingFixed": null,
  10640.  
  10641. /**
  10642. * Classes to use for the striping of a table.
  10643. * Note that this parameter will be set by the initialisation routine. To
  10644. * set a default use {@link DataTable.defaults}.
  10645. * @type array
  10646. * @default []
  10647. */
  10648. "asStripeClasses": null,
  10649.  
  10650. /**
  10651. * If restoring a table - we should restore its striping classes as well
  10652. * @type array
  10653. * @default []
  10654. */
  10655. "asDestroyStripes": [],
  10656.  
  10657. /**
  10658. * If restoring a table - we should restore its width
  10659. * @type int
  10660. * @default 0
  10661. */
  10662. "sDestroyWidth": 0,
  10663.  
  10664. /**
  10665. * Callback functions array for every time a row is inserted (i.e. on a draw).
  10666. * @type array
  10667. * @default []
  10668. */
  10669. "aoRowCallback": [],
  10670.  
  10671. /**
  10672. * Callback functions for the header on each draw.
  10673. * @type array
  10674. * @default []
  10675. */
  10676. "aoHeaderCallback": [],
  10677.  
  10678. /**
  10679. * Callback function for the footer on each draw.
  10680. * @type array
  10681. * @default []
  10682. */
  10683. "aoFooterCallback": [],
  10684.  
  10685. /**
  10686. * Array of callback functions for draw callback functions
  10687. * @type array
  10688. * @default []
  10689. */
  10690. "aoDrawCallback": [],
  10691.  
  10692. /**
  10693. * Array of callback functions for row created function
  10694. * @type array
  10695. * @default []
  10696. */
  10697. "aoRowCreatedCallback": [],
  10698.  
  10699. /**
  10700. * Callback functions for just before the table is redrawn. A return of
  10701. * false will be used to cancel the draw.
  10702. * @type array
  10703. * @default []
  10704. */
  10705. "aoPreDrawCallback": [],
  10706.  
  10707. /**
  10708. * Callback functions for when the table has been initialised.
  10709. * @type array
  10710. * @default []
  10711. */
  10712. "aoInitComplete": [],
  10713.  
  10714.  
  10715. /**
  10716. * Callbacks for modifying the settings to be stored for state saving, prior to
  10717. * saving state.
  10718. * @type array
  10719. * @default []
  10720. */
  10721. "aoStateSaveParams": [],
  10722.  
  10723. /**
  10724. * Callbacks for modifying the settings that have been stored for state saving
  10725. * prior to using the stored values to restore the state.
  10726. * @type array
  10727. * @default []
  10728. */
  10729. "aoStateLoadParams": [],
  10730.  
  10731. /**
  10732. * Callbacks for operating on the settings object once the saved state has been
  10733. * loaded
  10734. * @type array
  10735. * @default []
  10736. */
  10737. "aoStateLoaded": [],
  10738.  
  10739. /**
  10740. * Cache the table ID for quick access
  10741. * @type string
  10742. * @default <i>Empty string</i>
  10743. */
  10744. "sTableId": "",
  10745.  
  10746. /**
  10747. * The TABLE node for the main table
  10748. * @type node
  10749. * @default null
  10750. */
  10751. "nTable": null,
  10752.  
  10753. /**
  10754. * Permanent ref to the thead element
  10755. * @type node
  10756. * @default null
  10757. */
  10758. "nTHead": null,
  10759.  
  10760. /**
  10761. * Permanent ref to the tfoot element - if it exists
  10762. * @type node
  10763. * @default null
  10764. */
  10765. "nTFoot": null,
  10766.  
  10767. /**
  10768. * Permanent ref to the tbody element
  10769. * @type node
  10770. * @default null
  10771. */
  10772. "nTBody": null,
  10773.  
  10774. /**
  10775. * Cache the wrapper node (contains all DataTables controlled elements)
  10776. * @type node
  10777. * @default null
  10778. */
  10779. "nTableWrapper": null,
  10780.  
  10781. /**
  10782. * Indicate if when using server-side processing the loading of data
  10783. * should be deferred until the second draw.
  10784. * Note that this parameter will be set by the initialisation routine. To
  10785. * set a default use {@link DataTable.defaults}.
  10786. * @type boolean
  10787. * @default false
  10788. */
  10789. "bDeferLoading": false,
  10790.  
  10791. /**
  10792. * Indicate if all required information has been read in
  10793. * @type boolean
  10794. * @default false
  10795. */
  10796. "bInitialised": false,
  10797.  
  10798. /**
  10799. * Information about open rows. Each object in the array has the parameters
  10800. * 'nTr' and 'nParent'
  10801. * @type array
  10802. * @default []
  10803. */
  10804. "aoOpenRows": [],
  10805.  
  10806. /**
  10807. * Dictate the positioning of DataTables' control elements - see
  10808. * {@link DataTable.model.oInit.sDom}.
  10809. * Note that this parameter will be set by the initialisation routine. To
  10810. * set a default use {@link DataTable.defaults}.
  10811. * @type string
  10812. * @default null
  10813. */
  10814. "sDom": null,
  10815.  
  10816. /**
  10817. * Which type of pagination should be used.
  10818. * Note that this parameter will be set by the initialisation routine. To
  10819. * set a default use {@link DataTable.defaults}.
  10820. * @type string
  10821. * @default two_button
  10822. */
  10823. "sPaginationType": "two_button",
  10824.  
  10825. /**
  10826. * The cookie duration (for bStateSave) in seconds.
  10827. * Note that this parameter will be set by the initialisation routine. To
  10828. * set a default use {@link DataTable.defaults}.
  10829. * @type int
  10830. * @default 0
  10831. */
  10832. "iCookieDuration": 0,
  10833.  
  10834. /**
  10835. * The cookie name prefix.
  10836. * Note that this parameter will be set by the initialisation routine. To
  10837. * set a default use {@link DataTable.defaults}.
  10838. * @type string
  10839. * @default <i>Empty string</i>
  10840. */
  10841. "sCookiePrefix": "",
  10842.  
  10843. /**
  10844. * Callback function for cookie creation.
  10845. * Note that this parameter will be set by the initialisation routine. To
  10846. * set a default use {@link DataTable.defaults}.
  10847. * @type function
  10848. * @default null
  10849. */
  10850. "fnCookieCallback": null,
  10851.  
  10852. /**
  10853. * Array of callback functions for state saving. Each array element is an
  10854. * object with the following parameters:
  10855. * <ul>
  10856. * <li>function:fn - function to call. Takes two parameters, oSettings
  10857. * and the JSON string to save that has been thus far created. Returns
  10858. * a JSON string to be inserted into a json object
  10859. * (i.e. '"param": [ 0, 1, 2]')</li>
  10860. * <li>string:sName - name of callback</li>
  10861. * </ul>
  10862. * @type array
  10863. * @default []
  10864. */
  10865. "aoStateSave": [],
  10866.  
  10867. /**
  10868. * Array of callback functions for state loading. Each array element is an
  10869. * object with the following parameters:
  10870. * <ul>
  10871. * <li>function:fn - function to call. Takes two parameters, oSettings
  10872. * and the object stored. May return false to cancel state loading</li>
  10873. * <li>string:sName - name of callback</li>
  10874. * </ul>
  10875. * @type array
  10876. * @default []
  10877. */
  10878. "aoStateLoad": [],
  10879.  
  10880. /**
  10881. * State that was loaded from the cookie. Useful for back reference
  10882. * @type object
  10883. * @default null
  10884. */
  10885. "oLoadedState": null,
  10886.  
  10887. /**
  10888. * Source url for AJAX data for the table.
  10889. * Note that this parameter will be set by the initialisation routine. To
  10890. * set a default use {@link DataTable.defaults}.
  10891. * @type string
  10892. * @default null
  10893. */
  10894. "sAjaxSource": null,
  10895.  
  10896. /**
  10897. * Property from a given object from which to read the table data from. This
  10898. * can be an empty string (when not server-side processing), in which case
  10899. * it is assumed an an array is given directly.
  10900. * Note that this parameter will be set by the initialisation routine. To
  10901. * set a default use {@link DataTable.defaults}.
  10902. * @type string
  10903. */
  10904. "sAjaxDataProp": null,
  10905.  
  10906. /**
  10907. * Note if draw should be blocked while getting data
  10908. * @type boolean
  10909. * @default true
  10910. */
  10911. "bAjaxDataGet": true,
  10912.  
  10913. /**
  10914. * The last jQuery XHR object that was used for server-side data gathering.
  10915. * This can be used for working with the XHR information in one of the
  10916. * callbacks
  10917. * @type object
  10918. * @default null
  10919. */
  10920. "jqXHR": null,
  10921.  
  10922. /**
  10923. * Function to get the server-side data.
  10924. * Note that this parameter will be set by the initialisation routine. To
  10925. * set a default use {@link DataTable.defaults}.
  10926. * @type function
  10927. */
  10928. "fnServerData": null,
  10929.  
  10930. /**
  10931. * Functions which are called prior to sending an Ajax request so extra
  10932. * parameters can easily be sent to the server
  10933. * @type array
  10934. * @default []
  10935. */
  10936. "aoServerParams": [],
  10937.  
  10938. /**
  10939. * Send the XHR HTTP method - GET or POST (could be PUT or DELETE if
  10940. * required).
  10941. * Note that this parameter will be set by the initialisation routine. To
  10942. * set a default use {@link DataTable.defaults}.
  10943. * @type string
  10944. */
  10945. "sServerMethod": null,
  10946.  
  10947. /**
  10948. * Format numbers for display.
  10949. * Note that this parameter will be set by the initialisation routine. To
  10950. * set a default use {@link DataTable.defaults}.
  10951. * @type function
  10952. */
  10953. "fnFormatNumber": null,
  10954.  
  10955. /**
  10956. * List of options that can be used for the user selectable length menu.
  10957. * Note that this parameter will be set by the initialisation routine. To
  10958. * set a default use {@link DataTable.defaults}.
  10959. * @type array
  10960. * @default []
  10961. */
  10962. "aLengthMenu": null,
  10963.  
  10964. /**
  10965. * Counter for the draws that the table does. Also used as a tracker for
  10966. * server-side processing
  10967. * @type int
  10968. * @default 0
  10969. */
  10970. "iDraw": 0,
  10971.  
  10972. /**
  10973. * Indicate if a redraw is being done - useful for Ajax
  10974. * @type boolean
  10975. * @default false
  10976. */
  10977. "bDrawing": false,
  10978.  
  10979. /**
  10980. * Draw index (iDraw) of the last error when parsing the returned data
  10981. * @type int
  10982. * @default -1
  10983. */
  10984. "iDrawError": -1,
  10985.  
  10986. /**
  10987. * Paging display length
  10988. * @type int
  10989. * @default 10
  10990. */
  10991. "_iDisplayLength": 10,
  10992.  
  10993. /**
  10994. * Paging start point - aiDisplay index
  10995. * @type int
  10996. * @default 0
  10997. */
  10998. "_iDisplayStart": 0,
  10999.  
  11000. /**
  11001. * Paging end point - aiDisplay index. Use fnDisplayEnd rather than
  11002. * this property to get the end point
  11003. * @type int
  11004. * @default 10
  11005. * @private
  11006. */
  11007. "_iDisplayEnd": 10,
  11008.  
  11009. /**
  11010. * Server-side processing - number of records in the result set
  11011. * (i.e. before filtering), Use fnRecordsTotal rather than
  11012. * this property to get the value of the number of records, regardless of
  11013. * the server-side processing setting.
  11014. * @type int
  11015. * @default 0
  11016. * @private
  11017. */
  11018. "_iRecordsTotal": 0,
  11019.  
  11020. /**
  11021. * Server-side processing - number of records in the current display set
  11022. * (i.e. after filtering). Use fnRecordsDisplay rather than
  11023. * this property to get the value of the number of records, regardless of
  11024. * the server-side processing setting.
  11025. * @type boolean
  11026. * @default 0
  11027. * @private
  11028. */
  11029. "_iRecordsDisplay": 0,
  11030.  
  11031. /**
  11032. * Flag to indicate if jQuery UI marking and classes should be used.
  11033. * Note that this parameter will be set by the initialisation routine. To
  11034. * set a default use {@link DataTable.defaults}.
  11035. * @type boolean
  11036. */
  11037. "bJUI": null,
  11038.  
  11039. /**
  11040. * The classes to use for the table
  11041. * @type object
  11042. * @default {}
  11043. */
  11044. "oClasses": {},
  11045.  
  11046. /**
  11047. * Flag attached to the settings object so you can check in the draw
  11048. * callback if filtering has been done in the draw. Deprecated in favour of
  11049. * events.
  11050. * @type boolean
  11051. * @default false
  11052. * @deprecated
  11053. */
  11054. "bFiltered": false,
  11055.  
  11056. /**
  11057. * Flag attached to the settings object so you can check in the draw
  11058. * callback if sorting has been done in the draw. Deprecated in favour of
  11059. * events.
  11060. * @type boolean
  11061. * @default false
  11062. * @deprecated
  11063. */
  11064. "bSorted": false,
  11065.  
  11066. /**
  11067. * Indicate that if multiple rows are in the header and there is more than
  11068. * one unique cell per column, if the top one (true) or bottom one (false)
  11069. * should be used for sorting / title by DataTables.
  11070. * Note that this parameter will be set by the initialisation routine. To
  11071. * set a default use {@link DataTable.defaults}.
  11072. * @type boolean
  11073. */
  11074. "bSortCellsTop": null,
  11075.  
  11076. /**
  11077. * Initialisation object that is used for the table
  11078. * @type object
  11079. * @default null
  11080. */
  11081. "oInit": null,
  11082.  
  11083. /**
  11084. * Destroy callback functions - for plug-ins to attach themselves to the
  11085. * destroy so they can clean up markup and events.
  11086. * @type array
  11087. * @default []
  11088. */
  11089. "aoDestroyCallback": [],
  11090.  
  11091.  
  11092. /**
  11093. * Get the number of records in the current record set, before filtering
  11094. * @type function
  11095. */
  11096. "fnRecordsTotal": function ()
  11097. {
  11098. if ( this.oFeatures.bServerSide ) {
  11099. return parseInt(this._iRecordsTotal, 10);
  11100. } else {
  11101. return this.aiDisplayMaster.length;
  11102. }
  11103. },
  11104.  
  11105. /**
  11106. * Get the number of records in the current record set, after filtering
  11107. * @type function
  11108. */
  11109. "fnRecordsDisplay": function ()
  11110. {
  11111. if ( this.oFeatures.bServerSide ) {
  11112. return parseInt(this._iRecordsDisplay, 10);
  11113. } else {
  11114. return this.aiDisplay.length;
  11115. }
  11116. },
  11117.  
  11118. /**
  11119. * Set the display end point - aiDisplay index
  11120. * @type function
  11121. * @todo Should do away with _iDisplayEnd and calculate it on-the-fly here
  11122. */
  11123. "fnDisplayEnd": function ()
  11124. {
  11125. if ( this.oFeatures.bServerSide ) {
  11126. if ( this.oFeatures.bPaginate === false || this._iDisplayLength == -1 ) {
  11127. return this._iDisplayStart+this.aiDisplay.length;
  11128. } else {
  11129. return Math.min( this._iDisplayStart+this._iDisplayLength,
  11130. this._iRecordsDisplay );
  11131. }
  11132. } else {
  11133. return this._iDisplayEnd;
  11134. }
  11135. },
  11136.  
  11137. /**
  11138. * The DataTables object for this table
  11139. * @type object
  11140. * @default null
  11141. */
  11142. "oInstance": null,
  11143.  
  11144. /**
  11145. * Unique identifier for each instance of the DataTables object. If there
  11146. * is an ID on the table node, then it takes that value, otherwise an
  11147. * incrementing internal counter is used.
  11148. * @type string
  11149. * @default null
  11150. */
  11151. "sInstance": null,
  11152.  
  11153. /**
  11154. * tabindex attribute value that is added to DataTables control elements, allowing
  11155. * keyboard navigation of the table and its controls.
  11156. */
  11157. "iTabIndex": 0,
  11158.  
  11159. /**
  11160. * DIV container for the footer scrolling table if scrolling
  11161. */
  11162. "nScrollHead": null,
  11163.  
  11164. /**
  11165. * DIV container for the footer scrolling table if scrolling
  11166. */
  11167. "nScrollFoot": null
  11168. };
  11169.  
  11170. /**
  11171. * Extension object for DataTables that is used to provide all extension options.
  11172. *
  11173. * Note that the <i>DataTable.ext</i> object is available through
  11174. * <i>jQuery.fn.dataTable.ext</i> where it may be accessed and manipulated. It is
  11175. * also aliased to <i>jQuery.fn.dataTableExt</i> for historic reasons.
  11176. * @namespace
  11177. * @extends DataTable.models.ext
  11178. */
  11179. DataTable.ext = $.extend( true, {}, DataTable.models.ext );
  11180.  
  11181. $.extend( DataTable.ext.oStdClasses, {
  11182. "sTable": "dataTable",
  11183.  
  11184. /* Two buttons buttons */
  11185. "sPagePrevEnabled": "paginate_enabled_previous",
  11186. "sPagePrevDisabled": "paginate_disabled_previous",
  11187. "sPageNextEnabled": "paginate_enabled_next",
  11188. "sPageNextDisabled": "paginate_disabled_next",
  11189. "sPageJUINext": "",
  11190. "sPageJUIPrev": "",
  11191.  
  11192. /* Full numbers paging buttons */
  11193. "sPageButton": "paginate_button",
  11194. "sPageButtonActive": "paginate_active",
  11195. "sPageButtonStaticDisabled": "paginate_button paginate_button_disabled",
  11196. "sPageFirst": "first",
  11197. "sPagePrevious": "previous",
  11198. "sPageNext": "next",
  11199. "sPageLast": "last",
  11200.  
  11201. /* Striping classes */
  11202. "sStripeOdd": "odd",
  11203. "sStripeEven": "even",
  11204.  
  11205. /* Empty row */
  11206. "sRowEmpty": "dataTables_empty",
  11207.  
  11208. /* Features */
  11209. "sWrapper": "dataTables_wrapper",
  11210. "sFilter": "dataTables_filter",
  11211. "sInfo": "dataTables_info",
  11212. "sPaging": "dataTables_paginate paging_", /* Note that the type is postfixed */
  11213. "sLength": "dataTables_length",
  11214. "sProcessing": "dataTables_processing",
  11215.  
  11216. /* Sorting */
  11217. "sSortAsc": "sorting_asc",
  11218. "sSortDesc": "sorting_desc",
  11219. "sSortable": "sorting", /* Sortable in both directions */
  11220. "sSortableAsc": "sorting_asc_disabled",
  11221. "sSortableDesc": "sorting_desc_disabled",
  11222. "sSortableNone": "sorting_disabled",
  11223. "sSortColumn": "sorting_", /* Note that an int is postfixed for the sorting order */
  11224. "sSortJUIAsc": "",
  11225. "sSortJUIDesc": "",
  11226. "sSortJUI": "",
  11227. "sSortJUIAscAllowed": "",
  11228. "sSortJUIDescAllowed": "",
  11229. "sSortJUIWrapper": "",
  11230. "sSortIcon": "",
  11231.  
  11232. /* Scrolling */
  11233. "sScrollWrapper": "dataTables_scroll",
  11234. "sScrollHead": "dataTables_scrollHead",
  11235. "sScrollHeadInner": "dataTables_scrollHeadInner",
  11236. "sScrollBody": "dataTables_scrollBody",
  11237. "sScrollFoot": "dataTables_scrollFoot",
  11238. "sScrollFootInner": "dataTables_scrollFootInner",
  11239.  
  11240. /* Misc */
  11241. "sFooterTH": ""
  11242. } );
  11243.  
  11244.  
  11245. $.extend( DataTable.ext.oJUIClasses, DataTable.ext.oStdClasses, {
  11246. /* Two buttons buttons */
  11247. "sPagePrevEnabled": "fg-button ui-button ui-state-default ui-corner-left",
  11248. "sPagePrevDisabled": "fg-button ui-button ui-state-default ui-corner-left ui-state-disabled",
  11249. "sPageNextEnabled": "fg-button ui-button ui-state-default ui-corner-right",
  11250. "sPageNextDisabled": "fg-button ui-button ui-state-default ui-corner-right ui-state-disabled",
  11251. "sPageJUINext": "ui-icon ui-icon-circle-arrow-e",
  11252. "sPageJUIPrev": "ui-icon ui-icon-circle-arrow-w",
  11253.  
  11254. /* Full numbers paging buttons */
  11255. "sPageButton": "fg-button ui-button ui-state-default",
  11256. "sPageButtonActive": "fg-button ui-button ui-state-default ui-state-disabled",
  11257. "sPageButtonStaticDisabled": "fg-button ui-button ui-state-default ui-state-disabled",
  11258. "sPageFirst": "first ui-corner-tl ui-corner-bl",
  11259. "sPageLast": "last ui-corner-tr ui-corner-br",
  11260.  
  11261. /* Features */
  11262. "sPaging": "dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi "+
  11263. "ui-buttonset-multi paging_", /* Note that the type is postfixed */
  11264.  
  11265. /* Sorting */
  11266. "sSortAsc": "ui-state-default",
  11267. "sSortDesc": "ui-state-default",
  11268. "sSortable": "ui-state-default",
  11269. "sSortableAsc": "ui-state-default",
  11270. "sSortableDesc": "ui-state-default",
  11271. "sSortableNone": "ui-state-default",
  11272. "sSortJUIAsc": "css_right ui-icon ui-icon-triangle-1-n",
  11273. "sSortJUIDesc": "css_right ui-icon ui-icon-triangle-1-s",
  11274. "sSortJUI": "css_right ui-icon ui-icon-carat-2-n-s",
  11275. "sSortJUIAscAllowed": "css_right ui-icon ui-icon-carat-1-n",
  11276. "sSortJUIDescAllowed": "css_right ui-icon ui-icon-carat-1-s",
  11277. "sSortJUIWrapper": "DataTables_sort_wrapper",
  11278. "sSortIcon": "DataTables_sort_icon",
  11279.  
  11280. /* Scrolling */
  11281. "sScrollHead": "dataTables_scrollHead ui-state-default",
  11282. "sScrollFoot": "dataTables_scrollFoot ui-state-default",
  11283.  
  11284. /* Misc */
  11285. "sFooterTH": "ui-state-default"
  11286. } );
  11287.  
  11288.  
  11289. /*
  11290. * Variable: oPagination
  11291. * Purpose:
  11292. * Scope: jQuery.fn.dataTableExt
  11293. */
  11294. $.extend( DataTable.ext.oPagination, {
  11295. /*
  11296. * Variable: two_button
  11297. * Purpose: Standard two button (forward/back) pagination
  11298. * Scope: jQuery.fn.dataTableExt.oPagination
  11299. */
  11300. "two_button": {
  11301. /*
  11302. * Function: oPagination.two_button.fnInit
  11303. * Purpose: Initialise dom elements required for pagination with forward/back buttons only
  11304. * Returns: -
  11305. * Inputs: object:oSettings - dataTables settings object
  11306. * node:nPaging - the DIV which contains this pagination control
  11307. * function:fnCallbackDraw - draw function which must be called on update
  11308. */
  11309. "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
  11310. {
  11311. var oLang = oSettings.oLanguage.oPaginate;
  11312. var oClasses = oSettings.oClasses;
  11313. var fnClickHandler = function ( e ) {
  11314. if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) )
  11315. {
  11316. fnCallbackDraw( oSettings );
  11317. }
  11318. };
  11319.  
  11320. var sAppend = (!oSettings.bJUI) ?
  11321. '<a class="'+oSettings.oClasses.sPagePrevDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button">'+oLang.sPrevious+'</a>'+
  11322. '<a class="'+oSettings.oClasses.sPageNextDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button">'+oLang.sNext+'</a>'
  11323. :
  11324. '<a class="'+oSettings.oClasses.sPagePrevDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button"><span class="'+oSettings.oClasses.sPageJUIPrev+'"></span></a>'+
  11325. '<a class="'+oSettings.oClasses.sPageNextDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button"><span class="'+oSettings.oClasses.sPageJUINext+'"></span></a>';
  11326. $(nPaging).append( sAppend );
  11327.  
  11328. var els = $('a', nPaging);
  11329. var nPrevious = els[0],
  11330. nNext = els[1];
  11331.  
  11332. oSettings.oApi._fnBindAction( nPrevious, {action: "previous"}, fnClickHandler );
  11333. oSettings.oApi._fnBindAction( nNext, {action: "next"}, fnClickHandler );
  11334.  
  11335. /* ID the first elements only */
  11336. if ( !oSettings.aanFeatures.p )
  11337. {
  11338. nPaging.id = oSettings.sTableId+'_paginate';
  11339. nPrevious.id = oSettings.sTableId+'_previous';
  11340. nNext.id = oSettings.sTableId+'_next';
  11341.  
  11342. nPrevious.setAttribute('aria-controls', oSettings.sTableId);
  11343. nNext.setAttribute('aria-controls', oSettings.sTableId);
  11344. }
  11345. },
  11346.  
  11347. /*
  11348. * Function: oPagination.two_button.fnUpdate
  11349. * Purpose: Update the two button pagination at the end of the draw
  11350. * Returns: -
  11351. * Inputs: object:oSettings - dataTables settings object
  11352. * function:fnCallbackDraw - draw function to call on page change
  11353. */
  11354. "fnUpdate": function ( oSettings, fnCallbackDraw )
  11355. {
  11356. if ( !oSettings.aanFeatures.p )
  11357. {
  11358. return;
  11359. }
  11360.  
  11361. var oClasses = oSettings.oClasses;
  11362. var an = oSettings.aanFeatures.p;
  11363.  
  11364. /* Loop over each instance of the pager */
  11365. for ( var i=0, iLen=an.length ; i<iLen ; i++ )
  11366. {
  11367. if ( an[i].childNodes.length !== 0 )
  11368. {
  11369. an[i].childNodes[0].className = ( oSettings._iDisplayStart === 0 ) ?
  11370. oClasses.sPagePrevDisabled : oClasses.sPagePrevEnabled;
  11371.  
  11372. an[i].childNodes[1].className = ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() ) ?
  11373. oClasses.sPageNextDisabled : oClasses.sPageNextEnabled;
  11374. }
  11375. }
  11376. }
  11377. },
  11378.  
  11379.  
  11380. /*
  11381. * Variable: iFullNumbersShowPages
  11382. * Purpose: Change the number of pages which can be seen
  11383. * Scope: jQuery.fn.dataTableExt.oPagination
  11384. */
  11385. "iFullNumbersShowPages": 5,
  11386.  
  11387. /*
  11388. * Variable: full_numbers
  11389. * Purpose: Full numbers pagination
  11390. * Scope: jQuery.fn.dataTableExt.oPagination
  11391. */
  11392. "full_numbers": {
  11393. /*
  11394. * Function: oPagination.full_numbers.fnInit
  11395. * Purpose: Initialise dom elements required for pagination with a list of the pages
  11396. * Returns: -
  11397. * Inputs: object:oSettings - dataTables settings object
  11398. * node:nPaging - the DIV which contains this pagination control
  11399. * function:fnCallbackDraw - draw function which must be called on update
  11400. */
  11401. "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
  11402. {
  11403. var oLang = oSettings.oLanguage.oPaginate;
  11404. var oClasses = oSettings.oClasses;
  11405. var fnClickHandler = function ( e ) {
  11406. if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) )
  11407. {
  11408. fnCallbackDraw( oSettings );
  11409. }
  11410. };
  11411.  
  11412. $(nPaging).append(
  11413. '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPageFirst+'">'+oLang.sFirst+'</a>'+
  11414. '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPagePrevious+'">'+oLang.sPrevious+'</a>'+
  11415. '<span></span>'+
  11416. '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPageNext+'">'+oLang.sNext+'</a>'+
  11417. '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPageLast+'">'+oLang.sLast+'</a>'
  11418. );
  11419. var els = $('a', nPaging);
  11420. var nFirst = els[0],
  11421. nPrev = els[1],
  11422. nNext = els[2],
  11423. nLast = els[3];
  11424.  
  11425. oSettings.oApi._fnBindAction( nFirst, {action: "first"}, fnClickHandler );
  11426. oSettings.oApi._fnBindAction( nPrev, {action: "previous"}, fnClickHandler );
  11427. oSettings.oApi._fnBindAction( nNext, {action: "next"}, fnClickHandler );
  11428. oSettings.oApi._fnBindAction( nLast, {action: "last"}, fnClickHandler );
  11429.  
  11430. /* ID the first elements only */
  11431. if ( !oSettings.aanFeatures.p )
  11432. {
  11433. nPaging.id = oSettings.sTableId+'_paginate';
  11434. nFirst.id =oSettings.sTableId+'_first';
  11435. nPrev.id =oSettings.sTableId+'_previous';
  11436. nNext.id =oSettings.sTableId+'_next';
  11437. nLast.id =oSettings.sTableId+'_last';
  11438. }
  11439. },
  11440.  
  11441. /*
  11442. * Function: oPagination.full_numbers.fnUpdate
  11443. * Purpose: Update the list of page buttons shows
  11444. * Returns: -
  11445. * Inputs: object:oSettings - dataTables settings object
  11446. * function:fnCallbackDraw - draw function to call on page change
  11447. */
  11448. "fnUpdate": function ( oSettings, fnCallbackDraw )
  11449. {
  11450. if ( !oSettings.aanFeatures.p )
  11451. {
  11452. return;
  11453. }
  11454.  
  11455. var iPageCount = DataTable.ext.oPagination.iFullNumbersShowPages;
  11456. var iPageCountHalf = Math.floor(iPageCount / 2);
  11457. var iPages = Math.ceil((oSettings.fnRecordsDisplay()) / oSettings._iDisplayLength);
  11458. var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1;
  11459. var sList = "";
  11460. var iStartButton, iEndButton, i, iLen;
  11461. var oClasses = oSettings.oClasses;
  11462. var anButtons, anStatic, nPaginateList;
  11463. var an = oSettings.aanFeatures.p;
  11464. var fnBind = function (j) {
  11465. oSettings.oApi._fnBindAction( this, {"page": j+iStartButton-1}, function(e) {
  11466. /* Use the information in the element to jump to the required page */
  11467. oSettings.oApi._fnPageChange( oSettings, e.data.page );
  11468. fnCallbackDraw( oSettings );
  11469. e.preventDefault();
  11470. } );
  11471. };
  11472.  
  11473. /* Pages calculation */
  11474. if ( oSettings._iDisplayLength === -1 )
  11475. {
  11476. iStartButton = 1;
  11477. iEndButton = 1;
  11478. iCurrentPage = 1;
  11479. }
  11480. else if (iPages < iPageCount)
  11481. {
  11482. iStartButton = 1;
  11483. iEndButton = iPages;
  11484. }
  11485. else if (iCurrentPage <= iPageCountHalf)
  11486. {
  11487. iStartButton = 1;
  11488. iEndButton = iPageCount;
  11489. }
  11490. else if (iCurrentPage >= (iPages - iPageCountHalf))
  11491. {
  11492. iStartButton = iPages - iPageCount + 1;
  11493. iEndButton = iPages;
  11494. }
  11495. else
  11496. {
  11497. iStartButton = iCurrentPage - Math.ceil(iPageCount / 2) + 1;
  11498. iEndButton = iStartButton + iPageCount - 1;
  11499. }
  11500.  
  11501.  
  11502. /* Build the dynamic list */
  11503. for ( i=iStartButton ; i<=iEndButton ; i++ )
  11504. {
  11505. sList += (iCurrentPage !== i) ?
  11506. '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+'">'+oSettings.fnFormatNumber(i)+'</a>' :
  11507. '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButtonActive+'">'+oSettings.fnFormatNumber(i)+'</a>';
  11508. }
  11509.  
  11510. /* Loop over each instance of the pager */
  11511. for ( i=0, iLen=an.length ; i<iLen ; i++ )
  11512. {
  11513. if ( an[i].childNodes.length === 0 )
  11514. {
  11515. continue;
  11516. }
  11517.  
  11518. /* Build up the dynamic list forst - html and listeners */
  11519. $('span:eq(0)', an[i])
  11520. .html( sList )
  11521. .children('a').each( fnBind );
  11522.  
  11523. /* Update the premanent botton's classes */
  11524. anButtons = an[i].getElementsByTagName('a');
  11525. anStatic = [
  11526. anButtons[0], anButtons[1],
  11527. anButtons[anButtons.length-2], anButtons[anButtons.length-1]
  11528. ];
  11529.  
  11530. $(anStatic).removeClass( oClasses.sPageButton+" "+oClasses.sPageButtonActive+" "+oClasses.sPageButtonStaticDisabled );
  11531. $([anStatic[0], anStatic[1]]).addClass(
  11532. (iCurrentPage==1) ?
  11533. oClasses.sPageButtonStaticDisabled :
  11534. oClasses.sPageButton
  11535. );
  11536. $([anStatic[2], anStatic[3]]).addClass(
  11537. (iPages===0 || iCurrentPage===iPages || oSettings._iDisplayLength===-1) ?
  11538. oClasses.sPageButtonStaticDisabled :
  11539. oClasses.sPageButton
  11540. );
  11541. }
  11542. }
  11543. }
  11544. } );
  11545.  
  11546. $.extend( DataTable.ext.oSort, {
  11547. /*
  11548. * text sorting
  11549. */
  11550. "string-pre": function ( a )
  11551. {
  11552. if ( typeof a != 'string' ) {
  11553. a = (a !== null && a.toString) ? a.toString() : '';
  11554. }
  11555. return a.toLowerCase();
  11556. },
  11557.  
  11558. "string-asc": function ( x, y )
  11559. {
  11560. return ((x < y) ? -1 : ((x > y) ? 1 : 0));
  11561. },
  11562.  
  11563. "string-desc": function ( x, y )
  11564. {
  11565. return ((x < y) ? 1 : ((x > y) ? -1 : 0));
  11566. },
  11567.  
  11568.  
  11569. /*
  11570. * html sorting (ignore html tags)
  11571. */
  11572. "html-pre": function ( a )
  11573. {
  11574. return a.replace( /<.*?>/g, "" ).toLowerCase();
  11575. },
  11576.  
  11577. "html-asc": function ( x, y )
  11578. {
  11579. return ((x < y) ? -1 : ((x > y) ? 1 : 0));
  11580. },
  11581.  
  11582. "html-desc": function ( x, y )
  11583. {
  11584. return ((x < y) ? 1 : ((x > y) ? -1 : 0));
  11585. },
  11586.  
  11587.  
  11588. /*
  11589. * date sorting
  11590. */
  11591. "date-pre": function ( a )
  11592. {
  11593. var x = Date.parse( a );
  11594.  
  11595. if ( isNaN(x) || x==="" )
  11596. {
  11597. x = Date.parse( "01/01/1970 00:00:00" );
  11598. }
  11599. return x;
  11600. },
  11601.  
  11602. "date-asc": function ( x, y )
  11603. {
  11604. return x - y;
  11605. },
  11606.  
  11607. "date-desc": function ( x, y )
  11608. {
  11609. return y - x;
  11610. },
  11611.  
  11612.  
  11613. /*
  11614. * numerical sorting
  11615. */
  11616. "numeric-pre": function ( a )
  11617. {
  11618. return (a=="-" || a==="") ? 0 : a*1;
  11619. },
  11620.  
  11621. "numeric-asc": function ( x, y )
  11622. {
  11623. return x - y;
  11624. },
  11625.  
  11626. "numeric-desc": function ( x, y )
  11627. {
  11628. return y - x;
  11629. }
  11630. } );
  11631.  
  11632.  
  11633. $.extend( DataTable.ext.aTypes, [
  11634. /*
  11635. * Function: -
  11636. * Purpose: Check to see if a string is numeric
  11637. * Returns: string:'numeric' or null
  11638. * Inputs: mixed:sText - string to check
  11639. */
  11640. function ( sData )
  11641. {
  11642. /* Allow zero length strings as a number */
  11643. if ( typeof sData === 'number' )
  11644. {
  11645. return 'numeric';
  11646. }
  11647. else if ( typeof sData !== 'string' )
  11648. {
  11649. return null;
  11650. }
  11651.  
  11652. var sValidFirstChars = "0123456789-";
  11653. var sValidChars = "0123456789.";
  11654. var Char;
  11655. var bDecimal = false;
  11656.  
  11657. /* Check for a valid first char (no period and allow negatives) */
  11658. Char = sData.charAt(0);
  11659. if (sValidFirstChars.indexOf(Char) == -1)
  11660. {
  11661. return null;
  11662. }
  11663.  
  11664. /* Check all the other characters are valid */
  11665. for ( var i=1 ; i<sData.length ; i++ )
  11666. {
  11667. Char = sData.charAt(i);
  11668. if (sValidChars.indexOf(Char) == -1)
  11669. {
  11670. return null;
  11671. }
  11672.  
  11673. /* Only allowed one decimal place... */
  11674. if ( Char == "." )
  11675. {
  11676. if ( bDecimal )
  11677. {
  11678. return null;
  11679. }
  11680. bDecimal = true;
  11681. }
  11682. }
  11683.  
  11684. return 'numeric';
  11685. },
  11686.  
  11687. /*
  11688. * Function: -
  11689. * Purpose: Check to see if a string is actually a formatted date
  11690. * Returns: string:'date' or null
  11691. * Inputs: string:sText - string to check
  11692. */
  11693. function ( sData )
  11694. {
  11695. var iParse = Date.parse(sData);
  11696. if ( (iParse !== null && !isNaN(iParse)) || (typeof sData === 'string' && sData.length === 0) )
  11697. {
  11698. return 'date';
  11699. }
  11700. return null;
  11701. },
  11702.  
  11703. /*
  11704. * Function: -
  11705. * Purpose: Check to see if a string should be treated as an HTML string
  11706. * Returns: string:'html' or null
  11707. * Inputs: string:sText - string to check
  11708. */
  11709. function ( sData )
  11710. {
  11711. if ( typeof sData === 'string' && sData.indexOf('<') != -1 && sData.indexOf('>') != -1 )
  11712. {
  11713. return 'html';
  11714. }
  11715. return null;
  11716. }
  11717. ] );
  11718.  
  11719.  
  11720. // jQuery aliases
  11721. $.fn.DataTable = DataTable;
  11722. $.fn.dataTable = DataTable;
  11723. $.fn.dataTableSettings = DataTable.settings;
  11724. $.fn.dataTableExt = DataTable.ext;
  11725.  
  11726.  
  11727. // Information about events fired by DataTables - for documentation.
  11728. /**
  11729. * Draw event, fired whenever the table is redrawn on the page, at the same point as
  11730. * fnDrawCallback. This may be useful for binding events or performing calculations when
  11731. * the table is altered at all.
  11732. * @name DataTable#draw
  11733. * @event
  11734. * @param {event} e jQuery event object
  11735. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  11736. */
  11737.  
  11738. /**
  11739. * Filter event, fired when the filtering applied to the table (using the build in global
  11740. * global filter, or column filters) is altered.
  11741. * @name DataTable#filter
  11742. * @event
  11743. * @param {event} e jQuery event object
  11744. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  11745. */
  11746.  
  11747. /**
  11748. * Page change event, fired when the paging of the table is altered.
  11749. * @name DataTable#page
  11750. * @event
  11751. * @param {event} e jQuery event object
  11752. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  11753. */
  11754.  
  11755. /**
  11756. * Sort event, fired when the sorting applied to the table is altered.
  11757. * @name DataTable#sort
  11758. * @event
  11759. * @param {event} e jQuery event object
  11760. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  11761. */
  11762.  
  11763. /**
  11764. * DataTables initialisation complete event, fired when the table is fully drawn,
  11765. * including Ajax data loaded, if Ajax data is required.
  11766. * @name DataTable#init
  11767. * @event
  11768. * @param {event} e jQuery event object
  11769. * @param {object} oSettings DataTables settings object
  11770. * @param {object} json The JSON object request from the server - only
  11771. * present if client-side Ajax sourced data is used</li></ol>
  11772. */
  11773.  
  11774. /**
  11775. * State save event, fired when the table has changed state a new state save is required.
  11776. * This method allows modification of the state saving object prior to actually doing the
  11777. * save, including addition or other state properties (for plug-ins) or modification
  11778. * of a DataTables core property.
  11779. * @name DataTable#stateSaveParams
  11780. * @event
  11781. * @param {event} e jQuery event object
  11782. * @param {object} oSettings DataTables settings object
  11783. * @param {object} json The state information to be saved
  11784. */
  11785.  
  11786. /**
  11787. * State load event, fired when the table is loading state from the stored data, but
  11788. * prior to the settings object being modified by the saved state - allowing modification
  11789. * of the saved state is required or loading of state for a plug-in.
  11790. * @name DataTable#stateLoadParams
  11791. * @event
  11792. * @param {event} e jQuery event object
  11793. * @param {object} oSettings DataTables settings object
  11794. * @param {object} json The saved state information
  11795. */
  11796.  
  11797. /**
  11798. * State loaded event, fired when state has been loaded from stored data and the settings
  11799. * object has been modified by the loaded data.
  11800. * @name DataTable#stateLoaded
  11801. * @event
  11802. * @param {event} e jQuery event object
  11803. * @param {object} oSettings DataTables settings object
  11804. * @param {object} json The saved state information
  11805. */
  11806.  
  11807. /**
  11808. * Processing event, fired when DataTables is doing some kind of processing (be it,
  11809. * sort, filter or anything else). Can be used to indicate to the end user that
  11810. * there is something happening, or that something has finished.
  11811. * @name DataTable#processing
  11812. * @event
  11813. * @param {event} e jQuery event object
  11814. * @param {object} oSettings DataTables settings object
  11815. * @param {boolean} bShow Flag for if DataTables is doing processing or not
  11816. */
  11817.  
  11818. /**
  11819. * Ajax (XHR) event, fired whenever an Ajax request is completed from a request to
  11820. * made to the server for new data (note that this trigger is called in fnServerData,
  11821. * if you override fnServerData and which to use this event, you need to trigger it in
  11822. * you success function).
  11823. * @name DataTable#xhr
  11824. * @event
  11825. * @param {event} e jQuery event object
  11826. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  11827. */
  11828.  
  11829. /**
  11830. * Destroy event, fired when the DataTable is destroyed by calling fnDestroy or passing
  11831. * the bDestroy:true parameter in the initialisation object. This can be used to remove
  11832. * bound events, added DOM nodes, etc.
  11833. * @name DataTable#destroy
  11834. * @event
  11835. * @param {event} e jQuery event object
  11836. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  11837. */
  11838. }(jQuery, window, document, undefined));
Add Comment
Please, Sign In to add comment