1 var FrozenColumns =
function(table){
4 this.rightColumns = [];
8 this.initializationMode =
"left";
10 this.scrollEndTimer =
false;
14 FrozenColumns.prototype.reset =
function(){
15 this.initializationMode =
"left";
16 this.leftColumns = [];
17 this.rightColumns = [];
23 this.table.columnManager.headersElement.style.marginLeft = 0;
24 this.table.columnManager.element.style.paddingRight = 0;
28 FrozenColumns.prototype.initializeColumn =
function(column){
29 var config = {margin:0, edge:
false};
31 if(column.definition.frozen){
33 if(!column.parent.isGroup){
37 config.position = this.initializationMode;
39 if(this.initializationMode ==
"left"){
40 this.leftColumns.push(column);
42 this.rightColumns.unshift(column);
47 column.modules.frozen = config;
49 console.warn(
"Frozen Column Error - Column Groups cannot be frozen");
52 console.warn(
"Frozen Column Error - Grouped columns cannot be frozen");
56 this.initializationMode =
"right";
61 FrozenColumns.prototype.scrollHorizontal =
function(){
65 clearTimeout(this.scrollEndTimer);
68 this.scrollEndTimer = setTimeout(() => {
72 rows = this.table.rowManager.getVisibleRows();
76 this.layoutColumnPosition();
78 this.layoutCalcRows();
80 rows.forEach((row) => {
81 if(row.type ===
"row"){
86 this.table.rowManager.tableElement.style.marginRight = this.rightMargin;
91 FrozenColumns.prototype.calcMargins =
function(){
92 this.leftMargin = this._calcSpace(this.leftColumns, this.leftColumns.length) +
"px";
93 this.table.columnManager.headersElement.style.marginLeft = this.leftMargin;
95 this.rightMargin = this._calcSpace(this.rightColumns, this.rightColumns.length) +
"px";
96 this.table.columnManager.element.style.paddingRight = this.rightMargin;
99 this.rightPadding = this.table.rowManager.element.clientWidth + this.table.columnManager.scrollLeft;
103 FrozenColumns.prototype.layoutCalcRows =
function(){
104 if(this.table.modExists(
"columnCalcs")){
105 if(this.table.modules.columnCalcs.topInitialized &&
this.table.modules.columnCalcs.topRow){
106 this.layoutRow(this.table.modules.columnCalcs.topRow);
108 if(this.table.modules.columnCalcs.botInitialized &&
this.table.modules.columnCalcs.botRow){
109 this.layoutRow(this.table.modules.columnCalcs.botRow);
115 FrozenColumns.prototype.layoutColumnPosition =
function( allCells){
116 this.leftColumns.forEach((column, i) => {
117 column.modules.frozen.margin = (this._calcSpace(this.leftColumns, i) + this.table.columnManager.scrollLeft) +
"px";
119 if(i == this.leftColumns.length - 1){
120 column.modules.frozen.edge =
true;
122 column.modules.frozen.edge =
false;
125 this.layoutElement(column.getElement(), column);
128 column.cells.forEach((cell) => {
129 this.layoutElement(cell.getElement(), column);
134 this.rightColumns.forEach((column, i) => {
135 column.modules.frozen.margin = (this.rightPadding - this._calcSpace(this.rightColumns, i + 1)) +
"px";
137 if(i == this.rightColumns.length - 1){
138 column.modules.frozen.edge =
true;
140 column.modules.frozen.edge =
false;
143 this.layoutElement(column.getElement(), column);
146 column.cells.forEach((cell) => {
147 this.layoutElement(cell.getElement(), column);
154 FrozenColumns.prototype.layout =
function(){
168 self.table.rowManager.getDisplayRows().forEach(
function(row){
169 if(row.type ===
"row"){
175 this.layoutCalcRows();
178 this.layoutColumnPosition(
true);
184 this.table.rowManager.tableElement.style.marginRight = this.rightMargin;
189 FrozenColumns.prototype.layoutRow =
function(row){
190 var rowEl = row.getElement();
192 rowEl.style.paddingLeft = this.leftMargin;
195 this.leftColumns.forEach((column) => {
196 var cell = row.getCell(column);
199 this.layoutElement(cell.getElement(), column);
203 this.rightColumns.forEach((column) => {
204 var cell = row.getCell(column);
207 this.layoutElement(cell.getElement(), column);
212 FrozenColumns.prototype.layoutElement =
function(element, column){
214 if(column.modules.frozen){
215 element.style.position =
"absolute";
216 element.style.left = column.modules.frozen.margin;
218 element.classList.add(
"tabulator-frozen");
220 if(column.modules.frozen.edge){
221 element.classList.add(
"tabulator-frozen-" + column.modules.frozen.position);
226 FrozenColumns.prototype._calcSpace =
function(columns, index){
229 for (let i = 0; i < index; i++){
230 if(columns[i].visible){
231 width += columns[i].getWidth();
238 Tabulator.prototype.registerModule(
"frozenColumns", FrozenColumns);