otsdaq_utilities  v2_05_02_indev
frozen_rows.js
1 /* Tabulator v4.5.3 (c) Oliver Folkerd */
2 
3 var FrozenRows = function FrozenRows(table) {
4  this.table = table; //hold Tabulator object
5  this.topElement = document.createElement("div");
6  this.rows = [];
7  this.displayIndex = 0; //index in display pipeline
8 };
9 
10 FrozenRows.prototype.initialize = function () {
11  this.rows = [];
12 
13  this.topElement.classList.add("tabulator-frozen-rows-holder");
14 
15  // this.table.columnManager.element.append(this.topElement);
16  this.table.columnManager.getElement().insertBefore(this.topElement, this.table.columnManager.headersElement.nextSibling);
17 };
18 
19 FrozenRows.prototype.setDisplayIndex = function (index) {
20  this.displayIndex = index;
21 };
22 
23 FrozenRows.prototype.getDisplayIndex = function () {
24  return this.displayIndex;
25 };
26 
27 FrozenRows.prototype.isFrozen = function () {
28  return !!this.rows.length;
29 };
30 
31 //filter frozen rows out of display data
32 FrozenRows.prototype.getRows = function (rows) {
33  var self = this,
34  frozen = [],
35  output = rows.slice(0);
36 
37  this.rows.forEach(function (row) {
38  var index = output.indexOf(row);
39 
40  if (index > -1) {
41  output.splice(index, 1);
42  }
43  });
44 
45  return output;
46 };
47 
48 FrozenRows.prototype.freezeRow = function (row) {
49  if (!row.modules.frozen) {
50  row.modules.frozen = true;
51  this.topElement.appendChild(row.getElement());
52  row.initialize();
53  row.normalizeHeight();
54  this.table.rowManager.adjustTableSize();
55 
56  this.rows.push(row);
57 
58  this.table.rowManager.refreshActiveData("display");
59 
60  this.styleRows();
61  } else {
62  console.warn("Freeze Error - Row is already frozen");
63  }
64 };
65 
66 FrozenRows.prototype.unfreezeRow = function (row) {
67  var index = this.rows.indexOf(row);
68 
69  if (row.modules.frozen) {
70 
71  row.modules.frozen = false;
72 
73  var rowEl = row.getElement();
74  rowEl.parentNode.removeChild(rowEl);
75 
76  this.table.rowManager.adjustTableSize();
77 
78  this.rows.splice(index, 1);
79 
80  this.table.rowManager.refreshActiveData("display");
81 
82  if (this.rows.length) {
83  this.styleRows();
84  }
85  } else {
86  console.warn("Freeze Error - Row is already unfrozen");
87  }
88 };
89 
90 FrozenRows.prototype.styleRows = function (row) {
91  var self = this;
92 
93  this.rows.forEach(function (row, i) {
94  self.table.rowManager.styleRow(row, i);
95  });
96 };
97 
98 Tabulator.prototype.registerModule("frozenRows", FrozenRows);