Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

dataTables.fixedColumns.js 61KB

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