tabulator-tables 5.1.2 → 5.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -575,17 +575,18 @@ class Page extends Module{
575
575
  this.trackChanges();
576
576
  }
577
577
 
578
- _setPageCounter(totalRows){
579
- var content, currentRow;
578
+ _setPageCounter(totalRows, size, currentRow){
579
+ var content;
580
580
 
581
581
  if(this.pageCounter){
582
- currentRow = ((this.page - 1) * this.size) + 1;
583
582
 
584
583
  if(this.mode === "remote"){
584
+ size = this.size;
585
+ currentRow = ((this.page - 1) * this.size) + 1;
585
586
  totalRows = this.remoteRowCountEstimate;
586
587
  }
587
588
 
588
- content = this.pageCounter.call(this, this.size, currentRow, this.page, totalRows, this.max);
589
+ content = this.pageCounter.call(this, size, currentRow, this.page, totalRows, this.max);
589
590
 
590
591
  switch(typeof content){
591
592
  case "object":
@@ -725,7 +726,12 @@ class Page extends Module{
725
726
 
726
727
  //return appropriate rows for current page
727
728
  getRows(data){
728
- var output, start, end;
729
+ var actualRowPageSize = 0,
730
+ output, start, end, actualStartRow;
731
+
732
+ var actualRows = data.filter((row) => {
733
+ return row.type === "row";
734
+ });
729
735
 
730
736
  if(this.mode == "local"){
731
737
  output = [];
@@ -740,21 +746,30 @@ class Page extends Module{
740
746
  end = start + parseInt(this.size);
741
747
  }
742
748
 
743
-
744
749
  this._setPageButtons();
745
750
 
746
751
  for(let i = start; i < end; i++){
747
- if(data[i]){
748
- output.push(data[i]);
752
+ let row = data[i];
753
+
754
+ if(row){
755
+ output.push(row);
756
+
757
+ if(row.type === "row"){
758
+ if(!actualStartRow){
759
+ actualStartRow = row;
760
+ }
761
+
762
+ actualRowPageSize++;
763
+ }
749
764
  }
750
765
  }
751
-
752
- this._setPageCounter(data.length);
766
+
767
+ this._setPageCounter(actualRows.length, actualRowPageSize, actualStartRow ? (actualRows.indexOf(actualStartRow) + 1) : 0);
753
768
 
754
769
  return output;
755
770
  }else{
756
771
  this._setPageButtons();
757
- this._setPageCounter(data.length);
772
+ this._setPageCounter(actualRows.length);
758
773
 
759
774
  return data.slice(0);
760
775
  }
@@ -857,8 +872,8 @@ class Page extends Module{
857
872
 
858
873
  //handle the footer element being redrawn
859
874
  footerRedraw(){
860
- var footer = this.table.footerManager.element;
861
-
875
+ var footer = this.table.footerManager.containerElement;
876
+
862
877
  if((Math.ceil(footer.clientWidth) - footer.scrollWidth) < 0){
863
878
  this.pagesElement.style.display = 'none';
864
879
  }else{
@@ -5,28 +5,36 @@ export default function(pageSize, currentRow, currentPage, totalRows, totalPages
5
5
  ofEl = document.createElement("span"),
6
6
  totalEl = document.createElement("span"),
7
7
  rowsEl = document.createElement("span");
8
-
8
+
9
9
  this.table.modules.localize.langBind("pagination|counter|showing", (value) => {
10
10
  showingEl.innerHTML = value;
11
11
  });
12
-
13
- valueEl.innerHTML = " " + currentRow + "-" + Math.min((currentRow + pageSize - 1), totalRows) + " ";
14
-
12
+
15
13
  this.table.modules.localize.langBind("pagination|counter|of", (value) => {
16
14
  ofEl.innerHTML = value;
17
15
  });
18
-
19
- totalEl.innerHTML = " " + totalRows + " ";
20
-
16
+
21
17
  this.table.modules.localize.langBind("pagination|counter|rows", (value) => {
22
18
  rowsEl.innerHTML = value;
23
19
  });
24
-
25
- el.appendChild(showingEl);
26
- el.appendChild(valueEl);
27
- el.appendChild(ofEl);
28
- el.appendChild(totalEl);
29
- el.appendChild(rowsEl);
20
+
21
+ if(totalRows){
22
+ valueEl.innerHTML = " " + currentRow + "-" + Math.min((currentRow + pageSize - 1), totalRows) + " ";
23
+
24
+ totalEl.innerHTML = " " + totalRows + " ";
25
+
26
+ el.appendChild(showingEl);
27
+ el.appendChild(valueEl);
28
+ el.appendChild(ofEl);
29
+ el.appendChild(totalEl);
30
+ el.appendChild(rowsEl);
31
+ }else{
32
+ valueEl.innerHTML = " 0 ";
33
+
34
+ el.appendChild(showingEl);
35
+ el.appendChild(valueEl);
36
+ el.appendChild(rowsEl);
37
+ }
30
38
 
31
39
  return el;
32
40
  };
@@ -13,12 +13,12 @@ export default {
13
13
 
14
14
  //if cookie exists, decode and load column data into tabulator
15
15
  if(cookiePos > -1){
16
- cookie = cookie.substr(cookiePos);
16
+ cookie = cookie.slice(cookiePos);
17
17
 
18
18
  end = cookie.indexOf(";");
19
19
 
20
20
  if(end > -1){
21
- cookie = cookie.substr(0, end);
21
+ cookie = cookie.slice(0, end);
22
22
  }
23
23
 
24
24
  data = cookie.replace(key + "=", "");
@@ -26,4 +26,4 @@ export default {
26
26
 
27
27
  return data ? JSON.parse(data) : false;
28
28
  }
29
- };
29
+ };
@@ -1,186 +1,196 @@
1
1
  import Module from '../../core/Module.js';
2
2
 
3
3
  class ResizeColumns extends Module{
4
-
4
+
5
5
  constructor(table){
6
6
  super(table);
7
-
7
+
8
8
  this.startColumn = false;
9
9
  this.startX = false;
10
10
  this.startWidth = false;
11
11
  this.handle = null;
12
12
  this.prevHandle = null;
13
-
13
+
14
14
  this.registerColumnOption("resizable", true);
15
15
  }
16
-
16
+
17
17
  initialize(){
18
18
  // if(this.table.options.resizableColumns){
19
- this.subscribe("cell-layout", this.layoutCellHandles.bind(this));
20
- this.subscribe("column-init", this.layoutColumnHeader.bind(this));
19
+ this.subscribe("cell-layout", this.layoutCellHandles.bind(this));
20
+ this.subscribe("column-init", this.layoutColumnHeader.bind(this));
21
21
  // }
22
22
  }
23
-
23
+
24
24
  layoutCellHandles(cell){
25
25
  if(cell.row.type === "row"){
26
26
  this.initializeColumn("cell", cell.column, cell.element);
27
27
  }
28
28
  }
29
-
29
+
30
30
  layoutColumnHeader(column){
31
31
  this.initializeColumn("header", column, column.element);
32
32
  }
33
-
33
+
34
34
  initializeColumn(type, column, element){
35
35
  var self = this,
36
36
  variableHeight = false,
37
37
  mode = column.definition.resizable;
38
-
38
+
39
39
  //set column resize mode
40
40
  if(type === "header"){
41
41
  variableHeight = column.definition.formatter == "textarea" || column.definition.variableHeight;
42
42
  column.modules.resize = {variableHeight:variableHeight};
43
43
  }
44
-
44
+
45
45
  if(mode === true || mode == type){
46
-
46
+
47
47
  var handle = document.createElement('div');
48
48
  handle.className = "tabulator-col-resize-handle";
49
-
50
-
49
+
50
+
51
51
  var prevHandle = document.createElement('div');
52
52
  prevHandle.className = "tabulator-col-resize-handle prev";
53
-
53
+
54
54
  handle.addEventListener("click", function(e){
55
55
  e.stopPropagation();
56
56
  });
57
-
57
+
58
58
  var handleDown = function(e){
59
59
  var nearestColumn = column.getLastColumn();
60
-
60
+
61
61
  if(nearestColumn && self._checkResizability(nearestColumn)){
62
62
  self.startColumn = column;
63
63
  self._mouseDown(e, nearestColumn, handle);
64
64
  }
65
65
  };
66
-
66
+
67
67
  handle.addEventListener("mousedown", handleDown);
68
68
  handle.addEventListener("touchstart", handleDown, {passive: true});
69
-
69
+
70
70
  //reszie column on double click
71
71
  handle.addEventListener("dblclick", function(e){
72
- var col = column.getLastColumn();
73
-
72
+ var col = column.getLastColumn(),
73
+ oldWidth;
74
+
74
75
  if(col && self._checkResizability(col)){
76
+ oldWidth = col.getWidth();
77
+
75
78
  e.stopPropagation();
76
79
  col.reinitializeWidth(true);
80
+
81
+ if(oldWidth !== col.getWidth()){
82
+ self.dispatch("column-resized", col);
83
+ self.table.externalEvents.dispatch("columnResized", col.getComponent());
84
+ }
77
85
  }
78
86
  });
79
-
80
-
87
+
88
+
81
89
  prevHandle.addEventListener("click", function(e){
82
90
  e.stopPropagation();
83
91
  });
84
-
92
+
85
93
  var prevHandleDown = function(e){
86
94
  var nearestColumn, colIndex, prevColumn;
87
-
95
+
88
96
  nearestColumn = column.getFirstColumn();
89
-
97
+
90
98
  if(nearestColumn){
91
99
  colIndex = self.table.columnManager.findColumnIndex(nearestColumn);
92
100
  prevColumn = colIndex > 0 ? self.table.columnManager.getColumnByIndex(colIndex - 1) : false;
93
-
101
+
94
102
  if(prevColumn && self._checkResizability(prevColumn)){
95
103
  self.startColumn = column;
96
104
  self._mouseDown(e, prevColumn, prevHandle);
97
105
  }
98
106
  }
99
107
  };
100
-
108
+
101
109
  prevHandle.addEventListener("mousedown", prevHandleDown);
102
110
  prevHandle.addEventListener("touchstart", prevHandleDown, {passive: true});
103
-
111
+
104
112
  //resize column on double click
105
113
  prevHandle.addEventListener("dblclick", function(e){
106
114
  var nearestColumn, colIndex, prevColumn;
107
-
115
+
108
116
  nearestColumn = column.getFirstColumn();
109
-
117
+
110
118
  if(nearestColumn){
111
119
  colIndex = self.table.columnManager.findColumnIndex(nearestColumn);
112
120
  prevColumn = colIndex > 0 ? self.table.columnManager.getColumnByIndex(colIndex - 1) : false;
113
-
121
+
114
122
  if(prevColumn && self._checkResizability(prevColumn)){
115
123
  e.stopPropagation();
116
124
  prevColumn.reinitializeWidth(true);
117
125
  }
118
126
  }
119
127
  });
120
-
128
+
121
129
  element.appendChild(handle);
122
130
  element.appendChild(prevHandle);
123
131
  }
124
132
  }
125
-
133
+
126
134
  _checkResizability(column){
127
135
  return column.definition.resizable;
128
136
  }
129
-
137
+
130
138
  _mouseDown(e, column, handle){
131
139
  var self = this;
132
-
140
+
133
141
  self.table.element.classList.add("tabulator-block-select");
134
142
 
135
143
  function mouseMove(e){
136
144
  // self.table.columnManager.tempScrollBlock();
137
-
145
+
138
146
  if(self.table.rtl){
139
147
  column.setWidth(self.startWidth - ((typeof e.screenX === "undefined" ? e.touches[0].screenX : e.screenX) - self.startX));
140
148
  }else{
141
149
  column.setWidth(self.startWidth + ((typeof e.screenX === "undefined" ? e.touches[0].screenX : e.screenX) - self.startX));
142
150
  }
143
-
151
+
144
152
  self.table.columnManager.renderer.rerenderColumns(true);
145
-
153
+
146
154
  if(!self.table.browserSlow && column.modules.resize && column.modules.resize.variableHeight){
147
155
  column.checkCellHeights();
148
156
  }
149
157
  }
150
-
158
+
151
159
  function mouseUp(e){
152
-
160
+
153
161
  //block editor from taking action while resizing is taking place
154
162
  if(self.startColumn.modules.edit){
155
163
  self.startColumn.modules.edit.blocked = false;
156
164
  }
157
-
165
+
158
166
  if(self.table.browserSlow && column.modules.resize && column.modules.resize.variableHeight){
159
167
  column.checkCellHeights();
160
168
  }
161
-
169
+
162
170
  document.body.removeEventListener("mouseup", mouseUp);
163
171
  document.body.removeEventListener("mousemove", mouseMove);
164
-
172
+
165
173
  handle.removeEventListener("touchmove", mouseMove);
166
174
  handle.removeEventListener("touchend", mouseUp);
167
-
175
+
168
176
  self.table.element.classList.remove("tabulator-block-select");
169
177
 
170
- self.dispatch("column-resized", column);
171
- self.table.externalEvents.dispatch("columnResized", column.getComponent());
178
+ if(self.startWidth !== column.getWidth()){
179
+ self.dispatch("column-resized", column);
180
+ self.table.externalEvents.dispatch("columnResized", column.getComponent());
181
+ }
172
182
  }
173
-
183
+
174
184
  e.stopPropagation(); //prevent resize from interfereing with movable columns
175
-
185
+
176
186
  //block editor from taking action while resizing is taking place
177
187
  if(self.startColumn.modules.edit){
178
188
  self.startColumn.modules.edit.blocked = true;
179
189
  }
180
-
190
+
181
191
  self.startX = typeof e.screenX === "undefined" ? e.touches[0].screenX : e.screenX;
182
192
  self.startWidth = column.getWidth();
183
-
193
+
184
194
  document.body.addEventListener("mousemove", mouseMove);
185
195
  document.body.addEventListener("mouseup", mouseUp);
186
196
  handle.addEventListener("touchmove", mouseMove, {passive: true});