9
function setJQuery(jq) {
11
dataTable = $.fn.dataTable;
13
var FixedColumns = (function () {
14
function FixedColumns(settings, opts) {
17
if (!dataTable || !dataTable.versionCheck || !dataTable.versionCheck('1.10.0')) {
18
throw new Error('StateRestore requires DataTables 1.10 or newer');
20
var table = new dataTable.Api(settings);
21
this.classes = $.extend(true, {}, FixedColumns.classes);
23
this.c = $.extend(true, {}, FixedColumns.defaults, opts);
25
if (opts.left === undefined && this.c.leftColumns !== undefined) {
26
this.c.left = this.c.leftColumns;
29
if (opts.right === undefined && this.c.rightColumns !== undefined) {
30
this.c.right = this.c.rightColumns;
35
rtl: $(table.table().node()).css('direction') === 'rtl'
38
if (this.s.dt.settings()[0].oInit.scrollY === true) {
39
this.s.barWidth = this.s.dt.settings()[0].oBrowser.barWidth;
43
'background-color': 'white',
46
'position': 'absolute',
47
'width': this.s.barWidth + 1 + 'px'
50
leftBottomBlocker: $('<div>')
53
.addClass(this.classes.leftBottomBlocker),
54
leftTopBlocker: $('<div>')
60
.addClass(this.classes.leftTopBlocker),
61
rightBottomBlocker: $('<div>')
64
.addClass(this.classes.rightBottomBlocker),
65
rightTopBlocker: $('<div>')
71
.addClass(this.classes.rightTopBlocker)
73
if (this.s.dt.settings()[0]._bInitComplete) {
76
this._setKeyTableListener();
79
table.one('preInit.dt', function () {
82
_this._setKeyTableListener();
86
table.settings()[0]._fixedColumns = this;
95
FixedColumns.prototype.left = function (newVal) {
97
if (newVal !== undefined) {
110
FixedColumns.prototype.right = function (newVal) {
112
if (newVal !== undefined) {
114
this.c.right = newVal;
122
FixedColumns.prototype._addStyles = function () {
123
var parentDiv = null;
125
var header = this.s.dt.column(0).header();
126
var headerHeight = null;
127
if (header !== null) {
129
headerHeight = header.outerHeight() + 1;
130
parentDiv = $(header.closest('div.dataTables_scroll')).css('position', 'relative');
133
var footer = this.s.dt.column(0).footer();
134
var footerHeight = null;
135
if (footer !== null) {
137
footerHeight = footer.outerHeight();
139
if (parentDiv === null) {
140
parentDiv = $(footer.closest('div.dataTables_scroll')).css('position', 'relative');
144
var numCols = this.s.dt.columns().data().toArray().length;
148
var rows = $(this.s.dt.table().node()).children('tbody').children('tr');
151
for (var i = 0; i < numCols; i++) {
152
var column = this.s.dt.column(i);
153
if (!column.visible()) {
158
var colHeader = $(column.header());
159
var colFooter = $(column.footer());
161
if (i < this.c.left) {
162
$(this.s.dt.table().node()).addClass(this.classes.tableFixedLeft);
163
parentDiv.addClass(this.classes.tableFixedLeft);
166
var prevCol = this.s.dt.column(i - 1);
167
if (prevCol.visible()) {
168
distLeft += $(prevCol.nodes()[0]).outerWidth();
172
for (var _i = 0, rows_1 = rows; _i < rows_1.length; _i++) {
173
var row = rows_1[_i];
174
$($(row).children()[i - invisibles])
175
.css(this._getCellCSS(false, distLeft, 'left'))
176
.addClass(this.classes.fixedLeft);
180
.css(this._getCellCSS(true, distLeft, 'left'))
181
.addClass(this.classes.fixedLeft);
183
.css(this._getCellCSS(true, distLeft, 'left'))
184
.addClass(this.classes.fixedLeft);
188
for (var _a = 0, rows_2 = rows; _a < rows_2.length; _a++) {
189
var row = rows_2[_a];
190
var cell = $($(row).children()[i - invisibles]);
192
if (cell.hasClass(this.classes.fixedLeft)) {
194
.css(this._clearCellCSS('left'))
195
.removeClass(this.classes.fixedLeft);
199
if (colHeader.hasClass(this.classes.fixedLeft)) {
201
.css(this._clearCellCSS('left'))
202
.removeClass(this.classes.fixedLeft);
205
if (colFooter.hasClass(this.classes.fixedLeft)) {
207
.css(this._clearCellCSS('left'))
208
.removeClass(this.classes.fixedLeft);
213
if (header !== null && !header.hasClass('index')) {
215
this.dom.leftTopBlocker.outerHeight(headerHeight);
216
parentDiv.append(this.dom.leftTopBlocker);
219
this.dom.rightTopBlocker.outerHeight(headerHeight);
220
parentDiv.append(this.dom.rightTopBlocker);
224
if (footer !== null && !footer.hasClass('index')) {
226
this.dom.leftBottomBlocker.outerHeight(footerHeight);
227
parentDiv.append(this.dom.leftBottomBlocker);
230
this.dom.rightBottomBlocker.outerHeight(footerHeight);
231
parentDiv.append(this.dom.rightBottomBlocker);
236
for (var i = numCols - 1; i >= 0; i--) {
237
var column = this.s.dt.column(i);
239
var colHeader = $(column.header());
240
var colFooter = $(column.footer());
241
if (!column.visible()) {
245
if (i >= numCols - this.c.right) {
246
$(this.s.dt.table().node()).addClass(this.classes.tableFixedRight);
247
parentDiv.addClass(this.classes.tableFixedLeft);
249
if (i !== numCols - 1) {
250
var prevCol = this.s.dt.column(i + 1);
251
if (prevCol.visible()) {
252
distRight += $(prevCol.nodes()[0]).outerWidth();
256
for (var _b = 0, rows_3 = rows; _b < rows_3.length; _b++) {
257
var row = rows_3[_b];
258
$($(row).children()[i + invisibles])
259
.css(this._getCellCSS(false, distRight, 'right'))
260
.addClass(this.classes.fixedRight);
264
.css(this._getCellCSS(true, distRight, 'right'))
265
.addClass(this.classes.fixedRight);
267
.css(this._getCellCSS(true, distRight, 'right'))
268
.addClass(this.classes.fixedRight);
272
for (var _c = 0, rows_4 = rows; _c < rows_4.length; _c++) {
273
var row = rows_4[_c];
274
var cell = $($(row).children()[i + invisibles]);
276
if (cell.hasClass(this.classes.fixedRight)) {
278
.css(this._clearCellCSS('right'))
279
.removeClass(this.classes.fixedRight);
283
if (colHeader.hasClass(this.classes.fixedRight)) {
285
.css(this._clearCellCSS('right'))
286
.removeClass(this.classes.fixedRight);
289
if (colFooter.hasClass(this.classes.fixedRight)) {
291
.css(this._clearCellCSS('right'))
292
.removeClass(this.classes.fixedRight);
299
this.dom.rightTopBlocker.outerHeight(headerHeight);
300
parentDiv.append(this.dom.rightTopBlocker);
303
this.dom.leftTopBlocker.outerHeight(headerHeight);
304
parentDiv.append(this.dom.leftTopBlocker);
310
this.dom.rightBottomBlocker.outerHeight(footerHeight);
311
parentDiv.append(this.dom.rightBottomBlocker);
314
this.dom.leftBottomBlocker.outerHeight(footerHeight);
315
parentDiv.append(this.dom.leftBottomBlocker);
327
FixedColumns.prototype._getCellCSS = function (header, dist, lr) {
336
right: dist + (header ? this.s.barWidth : 0) + 'px'
343
right: dist + (header ? this.s.barWidth : 0) + 'px'
357
FixedColumns.prototype._clearCellCSS = function (lr) {
381
FixedColumns.prototype._setKeyTableListener = function () {
383
this.s.dt.on('key-focus', function (e, dt, cell) {
384
var cellPos = $(cell.node()).offset();
385
var scroll = $($(_this.s.dt.table().node()).closest('div.dataTables_scrollBody'));
387
if (_this.c.left > 0) {
389
var rightMost = $(_this.s.dt.column(_this.c.left - 1).header());
390
var rightMostPos = rightMost.offset();
391
var rightMostWidth = rightMost.outerWidth();
393
if (cellPos.left < rightMostPos.left + rightMostWidth) {
395
var currScroll = scroll.scrollLeft();
396
scroll.scrollLeft(currScroll - (rightMostPos.left + rightMostWidth - cellPos.left));
400
if (_this.c.right > 0) {
402
var numCols = _this.s.dt.columns().data().toArray().length;
403
var cellWidth = $(cell.node()).outerWidth();
405
var leftMost = $(_this.s.dt.column(numCols - _this.c.right).header());
406
var leftMostPos = leftMost.offset();
408
if (cellPos.left + cellWidth > leftMostPos.left) {
410
var currScroll = scroll.scrollLeft();
411
scroll.scrollLeft(currScroll - (leftMostPos.left - (cellPos.left + cellWidth)));
417
this.s.dt.on('draw', function () {
420
this.s.dt.on('column-reorder', function () {
423
this.s.dt.on('column-visibility', function () {
427
FixedColumns.version = '4.0.0';
428
FixedColumns.classes = {
429
fixedLeft: 'dtfc-fixed-left',
430
fixedRight: 'dtfc-fixed-right',
431
leftBottomBlocker: 'dtfc-left-bottom-blocker',
432
leftTopBlocker: 'dtfc-left-top-blocker',
433
rightBottomBlocker: 'dtfc-right-bottom-blocker',
434
rightTopBlocker: 'dtfc-right-top-blocker',
435
tableFixedLeft: 'dtfc-has-left',
436
tableFixedRight: 'dtfc-has-right'
438
FixedColumns.defaults = {
440
button: 'FixedColumns'
454
(function (factory) {
455
if (typeof define === 'function' && define.amd) {
457
define(['jquery', 'datatables.net'], function ($) {
458
return factory($, window, document);
461
else if (typeof exports === 'object') {
463
module.exports = function (root, $) {
467
if (!$ || !$.fn.dataTable) {
469
$ = require('datatables.net')(root, $).$;
471
return factory($, root, root.document);
476
factory(window.jQuery, window, document);
478
}(function ($, window, document) {
480
var dataTable = $.fn.dataTable;
481
$.fn.dataTable.FixedColumns = FixedColumns;
482
$.fn.DataTable.FixedColumns = FixedColumns;
483
var apiRegister = $.fn.dataTable.Api.register;
484
apiRegister('fixedColumns()', function () {
487
apiRegister('fixedColumns().left()', function (newVal) {
488
var ctx = this.context[0];
489
if (newVal !== undefined) {
490
ctx._fixedColumns.left(newVal);
494
return ctx._fixedColumns.left();
497
apiRegister('fixedColumns().right()', function (newVal) {
498
var ctx = this.context[0];
499
if (newVal !== undefined) {
500
ctx._fixedColumns.right(newVal);
504
return ctx._fixedColumns.right();
507
$.fn.dataTable.ext.buttons.fixedColumns = {
508
action: function (e, dt, node, config) {
509
if ($(node).attr('active')) {
510
$(node).removeAttr('active').removeClass('active');
511
dt.fixedColumns().left(0);
512
dt.fixedColumns().right(0);
515
$(node).attr('active', true).addClass('active');
516
dt.fixedColumns().left(config.config.left);
517
dt.fixedColumns().right(config.config.right);
524
init: function (dt, node, config) {
525
if (dt.settings()[0]._fixedColumns === undefined) {
526
_init(dt.settings(), config);
528
$(node).attr('active', true).addClass('active');
529
dt.button(node).text(config.text || dt.i18n('buttons.fixedColumns', dt.settings()[0]._fixedColumns.c.i18n.button));
533
function _init(settings, options) {
534
if (options === void 0) { options = null; }
535
var api = new dataTable.Api(settings);
538
: api.init().fixedColumns || dataTable.defaults.fixedColumns;
539
var fixedColumns = new FixedColumns(api, opts);
544
$(document).on('init.dt.dtfc', function (e, settings) {
545
if (e.namespace !== 'dt') {
548
if (settings.oInit.fixedColumns ||
549
dataTable.defaults.fixedColumns) {
550
if (!settings._fixedColumns) {
551
_init(settings, null);