dataTables.fixedColumns.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399
  1. /*! FixedColumns 3.0.2
  2. * ©2010-2014 SpryMedia Ltd - datatables.net/license
  3. */
  4. /**
  5. * @summary FixedColumns
  6. * @description Freeze columns in place on a scrolling DataTable
  7. * @version 3.0.2
  8. * @file dataTables.fixedColumns.js
  9. * @author SpryMedia Ltd (www.sprymedia.co.uk)
  10. * @contact www.sprymedia.co.uk/contact
  11. * @copyright Copyright 2010-2014 SpryMedia Ltd.
  12. *
  13. * This source file is free software, available under the following license:
  14. * MIT license - http://datatables.net/license/mit
  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. (function(window, document, undefined) {
  23. var factory = function( $, DataTable ) {
  24. "use strict";
  25. /**
  26. * When making use of DataTables' x-axis scrolling feature, you may wish to
  27. * fix the left most column in place. This plug-in for DataTables provides
  28. * exactly this option (note for non-scrolling tables, please use the
  29. * FixedHeader plug-in, which can fix headers, footers and columns). Key
  30. * features include:
  31. *
  32. * * Freezes the left or right most columns to the side of the table
  33. * * Option to freeze two or more columns
  34. * * Full integration with DataTables' scrolling options
  35. * * Speed - FixedColumns is fast in its operation
  36. *
  37. * @class
  38. * @constructor
  39. * @global
  40. * @param {object} dt DataTables instance. With DataTables 1.10 this can also
  41. * be a jQuery collection, a jQuery selector, DataTables API instance or
  42. * settings object.
  43. * @param {object} [init={}] Configuration object for FixedColumns. Options are
  44. * defined by {@link FixedColumns.defaults}
  45. *
  46. * @requires jQuery 1.7+
  47. * @requires DataTables 1.8.0+
  48. *
  49. * @example
  50. * var table = $('#example').dataTable( {
  51. * "scrollX": "100%"
  52. * } );
  53. * new $.fn.dataTable.fixedColumns( table );
  54. */
  55. var FixedColumns = function ( dt, init ) {
  56. var that = this;
  57. /* Sanity check - you just know it will happen */
  58. if ( ! this instanceof FixedColumns )
  59. {
  60. alert( "FixedColumns warning: FixedColumns must be initialised with the 'new' keyword." );
  61. return;
  62. }
  63. if ( typeof init == 'undefined' )
  64. {
  65. init = {};
  66. }
  67. // Use the DataTables Hungarian notation mapping method, if it exists to
  68. // provide forwards compatibility for camel case variables
  69. if ( $.fn.dataTable.camelToHungarian ) {
  70. $.fn.dataTable.camelToHungarian( FixedColumns.defaults, init );
  71. }
  72. // v1.10 allows the settings object to be got form a number of sources
  73. var dtSettings = $.fn.dataTable.Api ?
  74. new $.fn.dataTable.Api( dt ).settings()[0] :
  75. dt.fnSettings();
  76. /**
  77. * Settings object which contains customisable information for FixedColumns instance
  78. * @namespace
  79. * @extends FixedColumns.defaults
  80. * @private
  81. */
  82. this.s = {
  83. /**
  84. * DataTables settings objects
  85. * @type object
  86. * @default Obtained from DataTables instance
  87. */
  88. "dt": dtSettings,
  89. /**
  90. * Number of columns in the DataTable - stored for quick access
  91. * @type int
  92. * @default Obtained from DataTables instance
  93. */
  94. "iTableColumns": dtSettings.aoColumns.length,
  95. /**
  96. * Original outer widths of the columns as rendered by DataTables - used to calculate
  97. * the FixedColumns grid bounding box
  98. * @type array.<int>
  99. * @default []
  100. */
  101. "aiOuterWidths": [],
  102. /**
  103. * Original inner widths of the columns as rendered by DataTables - used to apply widths
  104. * to the columns
  105. * @type array.<int>
  106. * @default []
  107. */
  108. "aiInnerWidths": []
  109. };
  110. /**
  111. * DOM elements used by the class instance
  112. * @namespace
  113. * @private
  114. *
  115. */
  116. this.dom = {
  117. /**
  118. * DataTables scrolling element
  119. * @type node
  120. * @default null
  121. */
  122. "scroller": null,
  123. /**
  124. * DataTables header table
  125. * @type node
  126. * @default null
  127. */
  128. "header": null,
  129. /**
  130. * DataTables body table
  131. * @type node
  132. * @default null
  133. */
  134. "body": null,
  135. /**
  136. * DataTables footer table
  137. * @type node
  138. * @default null
  139. */
  140. "footer": null,
  141. /**
  142. * Display grid elements
  143. * @namespace
  144. */
  145. "grid": {
  146. /**
  147. * Grid wrapper. This is the container element for the 3x3 grid
  148. * @type node
  149. * @default null
  150. */
  151. "wrapper": null,
  152. /**
  153. * DataTables scrolling element. This element is the DataTables
  154. * component in the display grid (making up the main table - i.e.
  155. * not the fixed columns).
  156. * @type node
  157. * @default null
  158. */
  159. "dt": null,
  160. /**
  161. * Left fixed column grid components
  162. * @namespace
  163. */
  164. "left": {
  165. "wrapper": null,
  166. "head": null,
  167. "body": null,
  168. "foot": null
  169. },
  170. /**
  171. * Right fixed column grid components
  172. * @namespace
  173. */
  174. "right": {
  175. "wrapper": null,
  176. "head": null,
  177. "body": null,
  178. "foot": null
  179. }
  180. },
  181. /**
  182. * Cloned table nodes
  183. * @namespace
  184. */
  185. "clone": {
  186. /**
  187. * Left column cloned table nodes
  188. * @namespace
  189. */
  190. "left": {
  191. /**
  192. * Cloned header table
  193. * @type node
  194. * @default null
  195. */
  196. "header": null,
  197. /**
  198. * Cloned body table
  199. * @type node
  200. * @default null
  201. */
  202. "body": null,
  203. /**
  204. * Cloned footer table
  205. * @type node
  206. * @default null
  207. */
  208. "footer": null
  209. },
  210. /**
  211. * Right column cloned table nodes
  212. * @namespace
  213. */
  214. "right": {
  215. /**
  216. * Cloned header table
  217. * @type node
  218. * @default null
  219. */
  220. "header": null,
  221. /**
  222. * Cloned body table
  223. * @type node
  224. * @default null
  225. */
  226. "body": null,
  227. /**
  228. * Cloned footer table
  229. * @type node
  230. * @default null
  231. */
  232. "footer": null
  233. }
  234. }
  235. };
  236. /* Attach the instance to the DataTables instance so it can be accessed easily */
  237. dtSettings._oFixedColumns = this;
  238. /* Let's do it */
  239. if ( ! dtSettings._bInitComplete )
  240. {
  241. dtSettings.oApi._fnCallbackReg( dtSettings, 'aoInitComplete', function () {
  242. that._fnConstruct( init );
  243. }, 'FixedColumns' );
  244. }
  245. else
  246. {
  247. this._fnConstruct( init );
  248. }
  249. };
  250. FixedColumns.prototype = /** @lends FixedColumns.prototype */{
  251. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  252. * Public methods
  253. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  254. /**
  255. * Update the fixed columns - including headers and footers. Note that FixedColumns will
  256. * automatically update the display whenever the host DataTable redraws.
  257. * @returns {void}
  258. * @example
  259. * var table = $('#example').dataTable( {
  260. * "scrollX": "100%"
  261. * } );
  262. * var fc = new $.fn.dataTable.fixedColumns( table );
  263. *
  264. * // at some later point when the table has been manipulated....
  265. * fc.fnUpdate();
  266. */
  267. "fnUpdate": function ()
  268. {
  269. this._fnDraw( true );
  270. },
  271. /**
  272. * Recalculate the resizes of the 3x3 grid that FixedColumns uses for display of the table.
  273. * This is useful if you update the width of the table container. Note that FixedColumns will
  274. * perform this function automatically when the window.resize event is fired.
  275. * @returns {void}
  276. * @example
  277. * var table = $('#example').dataTable( {
  278. * "scrollX": "100%"
  279. * } );
  280. * var fc = new $.fn.dataTable.fixedColumns( table );
  281. *
  282. * // Resize the table container and then have FixedColumns adjust its layout....
  283. * $('#content').width( 1200 );
  284. * fc.fnRedrawLayout();
  285. */
  286. "fnRedrawLayout": function ()
  287. {
  288. this._fnColCalc();
  289. this._fnGridLayout();
  290. this.fnUpdate();
  291. },
  292. /**
  293. * Mark a row such that it's height should be recalculated when using 'semiauto' row
  294. * height matching. This function will have no effect when 'none' or 'auto' row height
  295. * matching is used.
  296. * @param {Node} nTr TR element that should have it's height recalculated
  297. * @returns {void}
  298. * @example
  299. * var table = $('#example').dataTable( {
  300. * "scrollX": "100%"
  301. * } );
  302. * var fc = new $.fn.dataTable.fixedColumns( table );
  303. *
  304. * // manipulate the table - mark the row as needing an update then update the table
  305. * // this allows the redraw performed by DataTables fnUpdate to recalculate the row
  306. * // height
  307. * fc.fnRecalculateHeight();
  308. * table.fnUpdate( $('#example tbody tr:eq(0)')[0], ["insert date", 1, 2, 3 ... ]);
  309. */
  310. "fnRecalculateHeight": function ( nTr )
  311. {
  312. delete nTr._DTTC_iHeight;
  313. nTr.style.height = 'auto';
  314. },
  315. /**
  316. * Set the height of a given row - provides cross browser compatibility
  317. * @param {Node} nTarget TR element that should have it's height recalculated
  318. * @param {int} iHeight Height in pixels to set
  319. * @returns {void}
  320. * @example
  321. * var table = $('#example').dataTable( {
  322. * "scrollX": "100%"
  323. * } );
  324. * var fc = new $.fn.dataTable.fixedColumns( table );
  325. *
  326. * // You may want to do this after manipulating a row in the fixed column
  327. * fc.fnSetRowHeight( $('#example tbody tr:eq(0)')[0], 50 );
  328. */
  329. "fnSetRowHeight": function ( nTarget, iHeight )
  330. {
  331. nTarget.style.height = iHeight+"px";
  332. },
  333. /**
  334. * Get data index information about a row or cell in the table body.
  335. * This function is functionally identical to fnGetPosition in DataTables,
  336. * taking the same parameter (TH, TD or TR node) and returning exactly the
  337. * the same information (data index information). THe difference between
  338. * the two is that this method takes into account the fixed columns in the
  339. * table, so you can pass in nodes from the master table, or the cloned
  340. * tables and get the index position for the data in the main table.
  341. * @param {node} node TR, TH or TD element to get the information about
  342. * @returns {int} If nNode is given as a TR, then a single index is
  343. * returned, or if given as a cell, an array of [row index, column index
  344. * (visible), column index (all)] is given.
  345. */
  346. "fnGetPosition": function ( node )
  347. {
  348. var idx;
  349. var inst = this.s.dt.oInstance;
  350. if ( ! $(node).parents('.DTFC_Cloned').length )
  351. {
  352. // Not in a cloned table
  353. return inst.fnGetPosition( node );
  354. }
  355. else
  356. {
  357. // Its in the cloned table, so need to look up position
  358. if ( node.nodeName.toLowerCase() === 'tr' ) {
  359. idx = $(node).index();
  360. return inst.fnGetPosition( $('tr', this.s.dt.nTBody)[ idx ] );
  361. }
  362. else
  363. {
  364. var colIdx = $(node).index();
  365. idx = $(node.parentNode).index();
  366. var row = inst.fnGetPosition( $('tr', this.s.dt.nTBody)[ idx ] );
  367. return [
  368. row,
  369. colIdx,
  370. inst.oApi._fnVisibleToColumnIndex( this.s.dt, colIdx )
  371. ];
  372. }
  373. }
  374. },
  375. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  376. * Private methods (they are of course public in JS, but recommended as private)
  377. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  378. /**
  379. * Initialisation for FixedColumns
  380. * @param {Object} oInit User settings for initialisation
  381. * @returns {void}
  382. * @private
  383. */
  384. "_fnConstruct": function ( oInit )
  385. {
  386. var i, iLen, iWidth,
  387. that = this;
  388. /* Sanity checking */
  389. if ( typeof this.s.dt.oInstance.fnVersionCheck != 'function' ||
  390. this.s.dt.oInstance.fnVersionCheck( '1.8.0' ) !== true )
  391. {
  392. alert( "FixedColumns "+FixedColumns.VERSION+" required DataTables 1.8.0 or later. "+
  393. "Please upgrade your DataTables installation" );
  394. return;
  395. }
  396. if ( this.s.dt.oScroll.sX === "" )
  397. {
  398. this.s.dt.oInstance.oApi._fnLog( this.s.dt, 1, "FixedColumns is not needed (no "+
  399. "x-scrolling in DataTables enabled), so no action will be taken. Use 'FixedHeader' for "+
  400. "column fixing when scrolling is not enabled" );
  401. return;
  402. }
  403. /* Apply the settings from the user / defaults */
  404. this.s = $.extend( true, this.s, FixedColumns.defaults, oInit );
  405. /* Set up the DOM as we need it and cache nodes */
  406. var classes = this.s.dt.oClasses;
  407. this.dom.grid.dt = $(this.s.dt.nTable).parents('div.'+classes.sScrollWrapper)[0];
  408. this.dom.scroller = $('div.'+classes.sScrollBody, this.dom.grid.dt )[0];
  409. /* Set up the DOM that we want for the fixed column layout grid */
  410. this._fnColCalc();
  411. this._fnGridSetup();
  412. /* Event handlers */
  413. var mouseController;
  414. // When the body is scrolled - scroll the left and right columns
  415. $(this.dom.scroller)
  416. .on( 'mouseover.DTFC touchstart.DTFC', function () {
  417. mouseController = 'main';
  418. } )
  419. .on( 'scroll.DTFC', function () {
  420. if ( mouseController === 'main' ) {
  421. if ( that.s.iLeftColumns > 0 ) {
  422. that.dom.grid.left.liner.scrollTop = that.dom.scroller.scrollTop;
  423. }
  424. if ( that.s.iRightColumns > 0 ) {
  425. that.dom.grid.right.liner.scrollTop = that.dom.scroller.scrollTop;
  426. }
  427. }
  428. } );
  429. var wheelType = 'onwheel' in document.createElement('div') ?
  430. 'wheel.DTFC' :
  431. 'mousewheel.DTFC';
  432. if ( that.s.iLeftColumns > 0 ) {
  433. // When scrolling the left column, scroll the body and right column
  434. $(that.dom.grid.left.liner)
  435. .on( 'mouseover.DTFC touchstart.DTFC', function () {
  436. mouseController = 'left';
  437. } )
  438. .on( 'scroll.DTFC', function () {
  439. if ( mouseController === 'left' ) {
  440. that.dom.scroller.scrollTop = that.dom.grid.left.liner.scrollTop;
  441. if ( that.s.iRightColumns > 0 ) {
  442. that.dom.grid.right.liner.scrollTop = that.dom.grid.left.liner.scrollTop;
  443. }
  444. }
  445. } )
  446. .on( wheelType, function(e) { // xxx update the destroy as well
  447. // Pass horizontal scrolling through
  448. var xDelta = e.type === 'wheel' ?
  449. -e.originalEvent.deltaX :
  450. e.originalEvent.wheelDeltaX;
  451. that.dom.scroller.scrollLeft -= xDelta;
  452. } );
  453. }
  454. if ( that.s.iRightColumns > 0 ) {
  455. // When scrolling the right column, scroll the body and the left column
  456. $(that.dom.grid.right.liner)
  457. .on( 'mouseover.DTFC touchstart.DTFC', function () {
  458. mouseController = 'right';
  459. } )
  460. .on( 'scroll.DTFC', function () {
  461. if ( mouseController === 'right' ) {
  462. that.dom.scroller.scrollTop = that.dom.grid.right.liner.scrollTop;
  463. if ( that.s.iLeftColumns > 0 ) {
  464. that.dom.grid.left.liner.scrollTop = that.dom.grid.right.liner.scrollTop;
  465. }
  466. }
  467. } )
  468. .on( wheelType, function(e) {
  469. // Pass horizontal scrolling through
  470. var xDelta = e.type === 'wheel' ?
  471. -e.originalEvent.deltaX :
  472. e.originalEvent.wheelDeltaX;
  473. that.dom.scroller.scrollLeft -= xDelta;
  474. } );
  475. }
  476. $(window).on( 'resize.DTFC', function () {
  477. that._fnGridLayout.call( that );
  478. } );
  479. var bFirstDraw = true;
  480. var jqTable = $(this.s.dt.nTable);
  481. jqTable
  482. .on( 'draw.dt.DTFC', function () {
  483. that._fnDraw.call( that, bFirstDraw );
  484. bFirstDraw = false;
  485. } )
  486. .on( 'column-sizing.dt.DTFC', function () {
  487. that._fnColCalc();
  488. that._fnGridLayout( that );
  489. } )
  490. .on( 'column-visibility.dt.DTFC', function () {
  491. that._fnColCalc();
  492. that._fnGridLayout( that );
  493. that._fnDraw( true );
  494. } )
  495. .on( 'destroy.dt.DTFC', function () {
  496. jqTable.off( 'column-sizing.dt.DTFC destroy.dt.DTFC draw.dt.DTFC' );
  497. $(that.dom.scroller).off( 'scroll.DTFC mouseover.DTFC' );
  498. $(window).off( 'resize.DTFC' );
  499. $(that.dom.grid.left.liner).off( 'scroll.DTFC mouseover.DTFC '+wheelType );
  500. $(that.dom.grid.left.wrapper).remove();
  501. $(that.dom.grid.right.liner).off( 'scroll.DTFC mouseover.DTFC '+wheelType );
  502. $(that.dom.grid.right.wrapper).remove();
  503. } );
  504. /* Get things right to start with - note that due to adjusting the columns, there must be
  505. * another redraw of the main table. It doesn't need to be a full redraw however.
  506. */
  507. this._fnGridLayout();
  508. this.s.dt.oInstance.fnDraw(false);
  509. },
  510. /**
  511. * Calculate the column widths for the grid layout
  512. * @returns {void}
  513. * @private
  514. */
  515. "_fnColCalc": function ()
  516. {
  517. var that = this;
  518. var iLeftWidth = 0;
  519. var iRightWidth = 0;
  520. this.s.aiInnerWidths = [];
  521. this.s.aiOuterWidths = [];
  522. $.each( this.s.dt.aoColumns, function (i, col) {
  523. var th = $(col.nTh);
  524. var border;
  525. if ( ! th.filter(':visible').length ) {
  526. that.s.aiInnerWidths.push( 0 );
  527. that.s.aiOuterWidths.push( 0 );
  528. }
  529. else
  530. {
  531. // Inner width is used to assign widths to cells
  532. // Outer width is used to calculate the container
  533. var iWidth = th.outerWidth();
  534. // When working with the left most-cell, need to add on the
  535. // table's border to the outerWidth, since we need to take
  536. // account of it, but it isn't in any cell
  537. if ( that.s.aiOuterWidths.length === 0 ) {
  538. border = $(that.s.dt.nTable).css('border-left-width');
  539. iWidth += typeof border === 'string' ? 1 : parseInt( border, 10 );
  540. }
  541. // Likewise with the final column on the right
  542. if ( that.s.aiOuterWidths.length === that.s.dt.aoColumns.length-1 ) {
  543. border = $(that.s.dt.nTable).css('border-right-width');
  544. iWidth += typeof border === 'string' ? 1 : parseInt( border, 10 );
  545. }
  546. that.s.aiOuterWidths.push( iWidth );
  547. that.s.aiInnerWidths.push( th.width() );
  548. if ( i < that.s.iLeftColumns )
  549. {
  550. iLeftWidth += iWidth;
  551. }
  552. if ( that.s.iTableColumns-that.s.iRightColumns <= i )
  553. {
  554. iRightWidth += iWidth;
  555. }
  556. }
  557. } );
  558. this.s.iLeftWidth = iLeftWidth;
  559. this.s.iRightWidth = iRightWidth;
  560. },
  561. /**
  562. * Set up the DOM for the fixed column. The way the layout works is to create a 1x3 grid
  563. * for the left column, the DataTable (for which we just reuse the scrolling element DataTable
  564. * puts into the DOM) and the right column. In each of he two fixed column elements there is a
  565. * grouping wrapper element and then a head, body and footer wrapper. In each of these we then
  566. * place the cloned header, body or footer tables. This effectively gives as 3x3 grid structure.
  567. * @returns {void}
  568. * @private
  569. */
  570. "_fnGridSetup": function ()
  571. {
  572. var that = this;
  573. var oOverflow = this._fnDTOverflow();
  574. var block;
  575. this.dom.body = this.s.dt.nTable;
  576. this.dom.header = this.s.dt.nTHead.parentNode;
  577. this.dom.header.parentNode.parentNode.style.position = "relative";
  578. var nSWrapper =
  579. $('<div class="DTFC_ScrollWrapper" style="position:relative; clear:both;">'+
  580. '<div class="DTFC_LeftWrapper" style="position:absolute; top:0; left:0;">'+
  581. '<div class="DTFC_LeftHeadWrapper" style="position:relative; top:0; left:0; overflow:hidden;"></div>'+
  582. '<div class="DTFC_LeftBodyWrapper" style="position:relative; top:0; left:0; overflow:hidden;">'+
  583. '<div class="DTFC_LeftBodyLiner" style="position:relative; top:0; left:0; overflow-y:scroll;"></div>'+
  584. '</div>'+
  585. '<div class="DTFC_LeftFootWrapper" style="position:relative; top:0; left:0; overflow:hidden;"></div>'+
  586. '</div>'+
  587. '<div class="DTFC_RightWrapper" style="position:absolute; top:0; left:0;">'+
  588. '<div class="DTFC_RightHeadWrapper" style="position:relative; top:0; left:0;">'+
  589. '<div class="DTFC_RightHeadBlocker DTFC_Blocker" style="position:absolute; top:0; bottom:0;"></div>'+
  590. '</div>'+
  591. '<div class="DTFC_RightBodyWrapper" style="position:relative; top:0; left:0; overflow:hidden;">'+
  592. '<div class="DTFC_RightBodyLiner" style="position:relative; top:0; left:0; overflow-y:scroll;"></div>'+
  593. '</div>'+
  594. '<div class="DTFC_RightFootWrapper" style="position:relative; top:0; left:0;">'+
  595. '<div class="DTFC_RightFootBlocker DTFC_Blocker" style="position:absolute; top:0; bottom:0;"></div>'+
  596. '</div>'+
  597. '</div>'+
  598. '</div>')[0];
  599. var nLeft = nSWrapper.childNodes[0];
  600. var nRight = nSWrapper.childNodes[1];
  601. this.dom.grid.dt.parentNode.insertBefore( nSWrapper, this.dom.grid.dt );
  602. nSWrapper.appendChild( this.dom.grid.dt );
  603. this.dom.grid.wrapper = nSWrapper;
  604. if ( this.s.iLeftColumns > 0 )
  605. {
  606. this.dom.grid.left.wrapper = nLeft;
  607. this.dom.grid.left.head = nLeft.childNodes[0];
  608. this.dom.grid.left.body = nLeft.childNodes[1];
  609. this.dom.grid.left.liner = $('div.DTFC_LeftBodyLiner', nSWrapper)[0];
  610. nSWrapper.appendChild( nLeft );
  611. }
  612. if ( this.s.iRightColumns > 0 )
  613. {
  614. this.dom.grid.right.wrapper = nRight;
  615. this.dom.grid.right.head = nRight.childNodes[0];
  616. this.dom.grid.right.body = nRight.childNodes[1];
  617. this.dom.grid.right.liner = $('div.DTFC_RightBodyLiner', nSWrapper)[0];
  618. block = $('div.DTFC_RightHeadBlocker', nSWrapper)[0];
  619. block.style.width = oOverflow.bar+"px";
  620. block.style.right = -oOverflow.bar+"px";
  621. this.dom.grid.right.headBlock = block;
  622. block = $('div.DTFC_RightFootBlocker', nSWrapper)[0];
  623. block.style.width = oOverflow.bar+"px";
  624. block.style.right = -oOverflow.bar+"px";
  625. this.dom.grid.right.footBlock = block;
  626. nSWrapper.appendChild( nRight );
  627. }
  628. if ( this.s.dt.nTFoot )
  629. {
  630. this.dom.footer = this.s.dt.nTFoot.parentNode;
  631. if ( this.s.iLeftColumns > 0 )
  632. {
  633. this.dom.grid.left.foot = nLeft.childNodes[2];
  634. }
  635. if ( this.s.iRightColumns > 0 )
  636. {
  637. this.dom.grid.right.foot = nRight.childNodes[2];
  638. }
  639. }
  640. },
  641. /**
  642. * Style and position the grid used for the FixedColumns layout
  643. * @returns {void}
  644. * @private
  645. */
  646. "_fnGridLayout": function ()
  647. {
  648. var oGrid = this.dom.grid;
  649. var iWidth = $(oGrid.wrapper).width();
  650. var iBodyHeight = $(this.s.dt.nTable.parentNode).outerHeight();
  651. var iFullHeight = $(this.s.dt.nTable.parentNode.parentNode).outerHeight();
  652. var oOverflow = this._fnDTOverflow();
  653. var
  654. iLeftWidth = this.s.iLeftWidth,
  655. iRightWidth = this.s.iRightWidth,
  656. iRight;
  657. // When x scrolling - don't paint the fixed columns over the x scrollbar
  658. if ( oOverflow.x )
  659. {
  660. iBodyHeight -= oOverflow.bar;
  661. }
  662. oGrid.wrapper.style.height = iFullHeight+"px";
  663. if ( this.s.iLeftColumns > 0 )
  664. {
  665. oGrid.left.wrapper.style.width = iLeftWidth+"px";
  666. oGrid.left.wrapper.style.height = "1px";
  667. oGrid.left.body.style.height = iBodyHeight+"px";
  668. if ( oGrid.left.foot ) {
  669. oGrid.left.foot.style.top = (oOverflow.x ? oOverflow.bar : 0)+"px"; // shift footer for scrollbar
  670. }
  671. oGrid.left.liner.style.width = (iLeftWidth+oOverflow.bar)+"px";
  672. oGrid.left.liner.style.height = iBodyHeight+"px";
  673. }
  674. if ( this.s.iRightColumns > 0 )
  675. {
  676. iRight = iWidth - iRightWidth;
  677. if ( oOverflow.y )
  678. {
  679. iRight -= oOverflow.bar;
  680. }
  681. oGrid.right.wrapper.style.width = iRightWidth+"px";
  682. oGrid.right.wrapper.style.left = iRight+"px";
  683. oGrid.right.wrapper.style.height = "1px";
  684. oGrid.right.body.style.height = iBodyHeight+"px";
  685. if ( oGrid.right.foot ) {
  686. oGrid.right.foot.style.top = (oOverflow.x ? oOverflow.bar : 0)+"px";
  687. }
  688. oGrid.right.liner.style.width = (iRightWidth+oOverflow.bar)+"px";
  689. oGrid.right.liner.style.height = iBodyHeight+"px";
  690. oGrid.right.headBlock.style.display = oOverflow.y ? 'block' : 'none';
  691. oGrid.right.footBlock.style.display = oOverflow.y ? 'block' : 'none';
  692. }
  693. },
  694. /**
  695. * Get information about the DataTable's scrolling state - specifically if the table is scrolling
  696. * on either the x or y axis, and also the scrollbar width.
  697. * @returns {object} Information about the DataTables scrolling state with the properties:
  698. * 'x', 'y' and 'bar'
  699. * @private
  700. */
  701. "_fnDTOverflow": function ()
  702. {
  703. var nTable = this.s.dt.nTable;
  704. var nTableScrollBody = nTable.parentNode;
  705. var out = {
  706. "x": false,
  707. "y": false,
  708. "bar": this.s.dt.oScroll.iBarWidth
  709. };
  710. if ( nTable.offsetWidth > nTableScrollBody.clientWidth )
  711. {
  712. out.x = true;
  713. }
  714. if ( nTable.offsetHeight > nTableScrollBody.clientHeight )
  715. {
  716. out.y = true;
  717. }
  718. return out;
  719. },
  720. /**
  721. * Clone and position the fixed columns
  722. * @returns {void}
  723. * @param {Boolean} bAll Indicate if the header and footer should be updated as well (true)
  724. * @private
  725. */
  726. "_fnDraw": function ( bAll )
  727. {
  728. this._fnGridLayout();
  729. this._fnCloneLeft( bAll );
  730. this._fnCloneRight( bAll );
  731. /* Draw callback function */
  732. if ( this.s.fnDrawCallback !== null )
  733. {
  734. this.s.fnDrawCallback.call( this, this.dom.clone.left, this.dom.clone.right );
  735. }
  736. /* Event triggering */
  737. $(this).trigger( 'draw.dtfc', {
  738. "leftClone": this.dom.clone.left,
  739. "rightClone": this.dom.clone.right
  740. } );
  741. },
  742. /**
  743. * Clone the right columns
  744. * @returns {void}
  745. * @param {Boolean} bAll Indicate if the header and footer should be updated as well (true)
  746. * @private
  747. */
  748. "_fnCloneRight": function ( bAll )
  749. {
  750. if ( this.s.iRightColumns <= 0 ) {
  751. return;
  752. }
  753. var that = this,
  754. i, jq,
  755. aiColumns = [];
  756. for ( i=this.s.iTableColumns-this.s.iRightColumns ; i<this.s.iTableColumns ; i++ ) {
  757. if ( this.s.dt.aoColumns[i].bVisible ) {
  758. aiColumns.push( i );
  759. }
  760. }
  761. this._fnClone( this.dom.clone.right, this.dom.grid.right, aiColumns, bAll );
  762. },
  763. /**
  764. * Clone the left columns
  765. * @returns {void}
  766. * @param {Boolean} bAll Indicate if the header and footer should be updated as well (true)
  767. * @private
  768. */
  769. "_fnCloneLeft": function ( bAll )
  770. {
  771. if ( this.s.iLeftColumns <= 0 ) {
  772. return;
  773. }
  774. var that = this,
  775. i, jq,
  776. aiColumns = [];
  777. for ( i=0 ; i<this.s.iLeftColumns ; i++ ) {
  778. if ( this.s.dt.aoColumns[i].bVisible ) {
  779. aiColumns.push( i );
  780. }
  781. }
  782. this._fnClone( this.dom.clone.left, this.dom.grid.left, aiColumns, bAll );
  783. },
  784. /**
  785. * Make a copy of the layout object for a header or footer element from DataTables. Note that
  786. * this method will clone the nodes in the layout object.
  787. * @returns {Array} Copy of the layout array
  788. * @param {Object} aoOriginal Layout array from DataTables (aoHeader or aoFooter)
  789. * @param {Object} aiColumns Columns to copy
  790. * @private
  791. */
  792. "_fnCopyLayout": function ( aoOriginal, aiColumns )
  793. {
  794. var aReturn = [];
  795. var aClones = [];
  796. var aCloned = [];
  797. for ( var i=0, iLen=aoOriginal.length ; i<iLen ; i++ )
  798. {
  799. var aRow = [];
  800. aRow.nTr = $(aoOriginal[i].nTr).clone(true, true)[0];
  801. for ( var j=0, jLen=this.s.iTableColumns ; j<jLen ; j++ )
  802. {
  803. if ( $.inArray( j, aiColumns ) === -1 )
  804. {
  805. continue;
  806. }
  807. var iCloned = $.inArray( aoOriginal[i][j].cell, aCloned );
  808. if ( iCloned === -1 )
  809. {
  810. var nClone = $(aoOriginal[i][j].cell).clone(true, true)[0];
  811. aClones.push( nClone );
  812. aCloned.push( aoOriginal[i][j].cell );
  813. aRow.push( {
  814. "cell": nClone,
  815. "unique": aoOriginal[i][j].unique
  816. } );
  817. }
  818. else
  819. {
  820. aRow.push( {
  821. "cell": aClones[ iCloned ],
  822. "unique": aoOriginal[i][j].unique
  823. } );
  824. }
  825. }
  826. aReturn.push( aRow );
  827. }
  828. return aReturn;
  829. },
  830. /**
  831. * Clone the DataTable nodes and place them in the DOM (sized correctly)
  832. * @returns {void}
  833. * @param {Object} oClone Object containing the header, footer and body cloned DOM elements
  834. * @param {Object} oGrid Grid object containing the display grid elements for the cloned
  835. * column (left or right)
  836. * @param {Array} aiColumns Column indexes which should be operated on from the DataTable
  837. * @param {Boolean} bAll Indicate if the header and footer should be updated as well (true)
  838. * @private
  839. */
  840. "_fnClone": function ( oClone, oGrid, aiColumns, bAll )
  841. {
  842. var that = this,
  843. i, iLen, j, jLen, jq, nTarget, iColumn, nClone, iIndex, aoCloneLayout,
  844. jqCloneThead, aoFixedHeader;
  845. /*
  846. * Header
  847. */
  848. if ( bAll )
  849. {
  850. if ( oClone.header !== null )
  851. {
  852. oClone.header.parentNode.removeChild( oClone.header );
  853. }
  854. oClone.header = $(this.dom.header).clone(true, true)[0];
  855. oClone.header.className += " DTFC_Cloned";
  856. oClone.header.style.width = "100%";
  857. oGrid.head.appendChild( oClone.header );
  858. /* Copy the DataTables layout cache for the header for our floating column */
  859. aoCloneLayout = this._fnCopyLayout( this.s.dt.aoHeader, aiColumns );
  860. jqCloneThead = $('>thead', oClone.header);
  861. jqCloneThead.empty();
  862. /* Add the created cloned TR elements to the table */
  863. for ( i=0, iLen=aoCloneLayout.length ; i<iLen ; i++ )
  864. {
  865. jqCloneThead[0].appendChild( aoCloneLayout[i].nTr );
  866. }
  867. /* Use the handy _fnDrawHead function in DataTables to do the rowspan/colspan
  868. * calculations for us
  869. */
  870. this.s.dt.oApi._fnDrawHead( this.s.dt, aoCloneLayout, true );
  871. }
  872. else
  873. {
  874. /* To ensure that we copy cell classes exactly, regardless of colspan, multiple rows
  875. * etc, we make a copy of the header from the DataTable again, but don't insert the
  876. * cloned cells, just copy the classes across. To get the matching layout for the
  877. * fixed component, we use the DataTables _fnDetectHeader method, allowing 1:1 mapping
  878. */
  879. aoCloneLayout = this._fnCopyLayout( this.s.dt.aoHeader, aiColumns );
  880. aoFixedHeader=[];
  881. this.s.dt.oApi._fnDetectHeader( aoFixedHeader, $('>thead', oClone.header)[0] );
  882. for ( i=0, iLen=aoCloneLayout.length ; i<iLen ; i++ )
  883. {
  884. for ( j=0, jLen=aoCloneLayout[i].length ; j<jLen ; j++ )
  885. {
  886. aoFixedHeader[i][j].cell.className = aoCloneLayout[i][j].cell.className;
  887. // If jQuery UI theming is used we need to copy those elements as well
  888. $('span.DataTables_sort_icon', aoFixedHeader[i][j].cell).each( function () {
  889. this.className = $('span.DataTables_sort_icon', aoCloneLayout[i][j].cell)[0].className;
  890. } );
  891. }
  892. }
  893. }
  894. this._fnEqualiseHeights( 'thead', this.dom.header, oClone.header );
  895. /*
  896. * Body
  897. */
  898. if ( this.s.sHeightMatch == 'auto' )
  899. {
  900. /* Remove any heights which have been applied already and let the browser figure it out */
  901. $('>tbody>tr', that.dom.body).css('height', 'auto');
  902. }
  903. if ( oClone.body !== null )
  904. {
  905. oClone.body.parentNode.removeChild( oClone.body );
  906. oClone.body = null;
  907. }
  908. oClone.body = $(this.dom.body).clone(true)[0];
  909. oClone.body.className += " DTFC_Cloned";
  910. oClone.body.style.paddingBottom = this.s.dt.oScroll.iBarWidth+"px";
  911. oClone.body.style.marginBottom = (this.s.dt.oScroll.iBarWidth*2)+"px"; /* For IE */
  912. if ( oClone.body.getAttribute('id') !== null )
  913. {
  914. oClone.body.removeAttribute('id');
  915. }
  916. $('>thead>tr', oClone.body).empty();
  917. $('>tfoot', oClone.body).remove();
  918. var nBody = $('tbody', oClone.body)[0];
  919. $(nBody).empty();
  920. if ( this.s.dt.aiDisplay.length > 0 )
  921. {
  922. /* Copy the DataTables' header elements to force the column width in exactly the
  923. * same way that DataTables does it - have the header element, apply the width and
  924. * colapse it down
  925. */
  926. var nInnerThead = $('>thead>tr', oClone.body)[0];
  927. for ( iIndex=0 ; iIndex<aiColumns.length ; iIndex++ )
  928. {
  929. iColumn = aiColumns[iIndex];
  930. nClone = $(this.s.dt.aoColumns[iColumn].nTh).clone(true)[0];
  931. nClone.innerHTML = "";
  932. var oStyle = nClone.style;
  933. oStyle.paddingTop = "0";
  934. oStyle.paddingBottom = "0";
  935. oStyle.borderTopWidth = "0";
  936. oStyle.borderBottomWidth = "0";
  937. oStyle.height = 0;
  938. oStyle.width = that.s.aiInnerWidths[iColumn]+"px";
  939. nInnerThead.appendChild( nClone );
  940. }
  941. /* Add in the tbody elements, cloning form the master table */
  942. $('>tbody>tr', that.dom.body).each( function (z) {
  943. var n = this.cloneNode(false);
  944. n.removeAttribute('id');
  945. var i = that.s.dt.oFeatures.bServerSide===false ?
  946. that.s.dt.aiDisplay[ that.s.dt._iDisplayStart+z ] : z;
  947. for ( iIndex=0 ; iIndex<aiColumns.length ; iIndex++ )
  948. {
  949. var aTds = that.s.dt.aoData[i].anCells || that.s.dt.oApi._fnGetTdNodes( that.s.dt, i );
  950. iColumn = aiColumns[iIndex];
  951. if ( aTds.length > 0 )
  952. {
  953. nClone = $( aTds[iColumn] ).clone(true, true)[0];
  954. n.appendChild( nClone );
  955. }
  956. }
  957. nBody.appendChild( n );
  958. } );
  959. }
  960. else
  961. {
  962. $('>tbody>tr', that.dom.body).each( function (z) {
  963. nClone = this.cloneNode(true);
  964. nClone.className += ' DTFC_NoData';
  965. $('td', nClone).html('');
  966. nBody.appendChild( nClone );
  967. } );
  968. }
  969. oClone.body.style.width = "100%";
  970. oClone.body.style.margin = "0";
  971. oClone.body.style.padding = "0";
  972. if ( bAll )
  973. {
  974. if ( typeof this.s.dt.oScroller != 'undefined' )
  975. {
  976. oGrid.liner.appendChild( this.s.dt.oScroller.dom.force.cloneNode(true) );
  977. }
  978. }
  979. oGrid.liner.appendChild( oClone.body );
  980. this._fnEqualiseHeights( 'tbody', that.dom.body, oClone.body );
  981. /*
  982. * Footer
  983. */
  984. if ( this.s.dt.nTFoot !== null )
  985. {
  986. if ( bAll )
  987. {
  988. if ( oClone.footer !== null )
  989. {
  990. oClone.footer.parentNode.removeChild( oClone.footer );
  991. }
  992. oClone.footer = $(this.dom.footer).clone(true, true)[0];
  993. oClone.footer.className += " DTFC_Cloned";
  994. oClone.footer.style.width = "100%";
  995. oGrid.foot.appendChild( oClone.footer );
  996. /* Copy the footer just like we do for the header */
  997. aoCloneLayout = this._fnCopyLayout( this.s.dt.aoFooter, aiColumns );
  998. var jqCloneTfoot = $('>tfoot', oClone.footer);
  999. jqCloneTfoot.empty();
  1000. for ( i=0, iLen=aoCloneLayout.length ; i<iLen ; i++ )
  1001. {
  1002. jqCloneTfoot[0].appendChild( aoCloneLayout[i].nTr );
  1003. }
  1004. this.s.dt.oApi._fnDrawHead( this.s.dt, aoCloneLayout, true );
  1005. }
  1006. else
  1007. {
  1008. aoCloneLayout = this._fnCopyLayout( this.s.dt.aoFooter, aiColumns );
  1009. var aoCurrFooter=[];
  1010. this.s.dt.oApi._fnDetectHeader( aoCurrFooter, $('>tfoot', oClone.footer)[0] );
  1011. for ( i=0, iLen=aoCloneLayout.length ; i<iLen ; i++ )
  1012. {
  1013. for ( j=0, jLen=aoCloneLayout[i].length ; j<jLen ; j++ )
  1014. {
  1015. aoCurrFooter[i][j].cell.className = aoCloneLayout[i][j].cell.className;
  1016. }
  1017. }
  1018. }
  1019. this._fnEqualiseHeights( 'tfoot', this.dom.footer, oClone.footer );
  1020. }
  1021. /* Equalise the column widths between the header footer and body - body get's priority */
  1022. var anUnique = this.s.dt.oApi._fnGetUniqueThs( this.s.dt, $('>thead', oClone.header)[0] );
  1023. $(anUnique).each( function (i) {
  1024. iColumn = aiColumns[i];
  1025. this.style.width = that.s.aiInnerWidths[iColumn]+"px";
  1026. } );
  1027. if ( that.s.dt.nTFoot !== null )
  1028. {
  1029. anUnique = this.s.dt.oApi._fnGetUniqueThs( this.s.dt, $('>tfoot', oClone.footer)[0] );
  1030. $(anUnique).each( function (i) {
  1031. iColumn = aiColumns[i];
  1032. this.style.width = that.s.aiInnerWidths[iColumn]+"px";
  1033. } );
  1034. }
  1035. },
  1036. /**
  1037. * From a given table node (THEAD etc), get a list of TR direct child elements
  1038. * @param {Node} nIn Table element to search for TR elements (THEAD, TBODY or TFOOT element)
  1039. * @returns {Array} List of TR elements found
  1040. * @private
  1041. */
  1042. "_fnGetTrNodes": function ( nIn )
  1043. {
  1044. var aOut = [];
  1045. for ( var i=0, iLen=nIn.childNodes.length ; i<iLen ; i++ )
  1046. {
  1047. if ( nIn.childNodes[i].nodeName.toUpperCase() == "TR" )
  1048. {
  1049. aOut.push( nIn.childNodes[i] );
  1050. }
  1051. }
  1052. return aOut;
  1053. },
  1054. /**
  1055. * Equalise the heights of the rows in a given table node in a cross browser way
  1056. * @returns {void}
  1057. * @param {String} nodeName Node type - thead, tbody or tfoot
  1058. * @param {Node} original Original node to take the heights from
  1059. * @param {Node} clone Copy the heights to
  1060. * @private
  1061. */
  1062. "_fnEqualiseHeights": function ( nodeName, original, clone )
  1063. {
  1064. if ( this.s.sHeightMatch == 'none' && nodeName !== 'thead' && nodeName !== 'tfoot' )
  1065. {
  1066. return;
  1067. }
  1068. var that = this,
  1069. i, iLen, iHeight, iHeight2, iHeightOriginal, iHeightClone,
  1070. rootOriginal = original.getElementsByTagName(nodeName)[0],
  1071. rootClone = clone.getElementsByTagName(nodeName)[0],
  1072. jqBoxHack = $('>'+nodeName+'>tr:eq(0)', original).children(':first'),
  1073. iBoxHack = jqBoxHack.outerHeight() - jqBoxHack.height(),
  1074. anOriginal = this._fnGetTrNodes( rootOriginal ),
  1075. anClone = this._fnGetTrNodes( rootClone ),
  1076. heights = [];
  1077. for ( i=0, iLen=anClone.length ; i<iLen ; i++ )
  1078. {
  1079. iHeightOriginal = anOriginal[i].offsetHeight;
  1080. iHeightClone = anClone[i].offsetHeight;
  1081. iHeight = iHeightClone > iHeightOriginal ? iHeightClone : iHeightOriginal;
  1082. if ( this.s.sHeightMatch == 'semiauto' )
  1083. {
  1084. anOriginal[i]._DTTC_iHeight = iHeight;
  1085. }
  1086. heights.push( iHeight );
  1087. }
  1088. for ( i=0, iLen=anClone.length ; i<iLen ; i++ )
  1089. {
  1090. anClone[i].style.height = heights[i]+"px";
  1091. anOriginal[i].style.height = heights[i]+"px";
  1092. }
  1093. }
  1094. };
  1095. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1096. * Statics
  1097. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1098. /**
  1099. * FixedColumns default settings for initialisation
  1100. * @name FixedColumns.defaults
  1101. * @namespace
  1102. * @static
  1103. */
  1104. FixedColumns.defaults = /** @lends FixedColumns.defaults */{
  1105. /**
  1106. * Number of left hand columns to fix in position
  1107. * @type int
  1108. * @default 1
  1109. * @static
  1110. * @example
  1111. * var = $('#example').dataTable( {
  1112. * "scrollX": "100%"
  1113. * } );
  1114. * new $.fn.dataTable.fixedColumns( table, {
  1115. * "leftColumns": 2
  1116. * } );
  1117. */
  1118. "iLeftColumns": 1,
  1119. /**
  1120. * Number of right hand columns to fix in position
  1121. * @type int
  1122. * @default 0
  1123. * @static
  1124. * @example
  1125. * var table = $('#example').dataTable( {
  1126. * "scrollX": "100%"
  1127. * } );
  1128. * new $.fn.dataTable.fixedColumns( table, {
  1129. * "rightColumns": 1
  1130. * } );
  1131. */
  1132. "iRightColumns": 0,
  1133. /**
  1134. * Draw callback function which is called when FixedColumns has redrawn the fixed assets
  1135. * @type function(object, object):void
  1136. * @default null
  1137. * @static
  1138. * @example
  1139. * var table = $('#example').dataTable( {
  1140. * "scrollX": "100%"
  1141. * } );
  1142. * new $.fn.dataTable.fixedColumns( table, {
  1143. * "drawCallback": function () {
  1144. * alert( "FixedColumns redraw" );
  1145. * }
  1146. * } );
  1147. */
  1148. "fnDrawCallback": null,
  1149. /**
  1150. * Height matching algorthim to use. This can be "none" which will result in no height
  1151. * matching being applied by FixedColumns (height matching could be forced by CSS in this
  1152. * case), "semiauto" whereby the height calculation will be performed once, and the result
  1153. * cached to be used again (fnRecalculateHeight can be used to force recalculation), or
  1154. * "auto" when height matching is performed on every draw (slowest but must accurate)
  1155. * @type string
  1156. * @default semiauto
  1157. * @static
  1158. * @example
  1159. * var table = $('#example').dataTable( {
  1160. * "scrollX": "100%"
  1161. * } );
  1162. * new $.fn.dataTable.fixedColumns( table, {
  1163. * "heightMatch": "auto"
  1164. * } );
  1165. */
  1166. "sHeightMatch": "semiauto"
  1167. };
  1168. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1169. * Constants
  1170. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1171. /**
  1172. * FixedColumns version
  1173. * @name FixedColumns.version
  1174. * @type String
  1175. * @default See code
  1176. * @static
  1177. */
  1178. FixedColumns.version = "3.0.2";
  1179. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1180. * Fired events (for documentation)
  1181. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1182. /**
  1183. * Event fired whenever FixedColumns redraws the fixed columns (i.e. clones the table elements from the main DataTable). This will occur whenever the DataTable that the FixedColumns instance is attached does its own draw.
  1184. * @name FixedColumns#draw.dtfc
  1185. * @event
  1186. * @param {event} e jQuery event object
  1187. * @param {object} o Event parameters from FixedColumns
  1188. * @param {object} o.leftClone Instance's object dom.clone.left for easy reference. This object contains references to the left fixed clumn column's nodes
  1189. * @param {object} o.rightClone Instance's object dom.clone.right for easy reference. This object contains references to the right fixed clumn column's nodes
  1190. */
  1191. // Make FixedColumns accessible from the DataTables instance
  1192. $.fn.dataTable.FixedColumns = FixedColumns;
  1193. $.fn.DataTable.FixedColumns = FixedColumns;
  1194. return FixedColumns;
  1195. }; // /factory
  1196. // Define as an AMD module if possible
  1197. if ( typeof define === 'function' && define.amd ) {
  1198. define( ['jquery', 'datatables'], factory );
  1199. }
  1200. else if ( typeof exports === 'object' ) {
  1201. // Node/CommonJS
  1202. factory( require('jquery'), require('datatables') );
  1203. }
  1204. else if ( jQuery && !jQuery.fn.dataTable.FixedColumns ) {
  1205. // Otherwise simply initialise as normal, stopping multiple evaluation
  1206. factory( jQuery, jQuery.fn.dataTable );
  1207. }
  1208. })(window, document);