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