tabulator-tables 5.0.10 → 5.1.0

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.
Files changed (100) hide show
  1. package/.editorconfig +6 -0
  2. package/LICENSE +1 -1
  3. package/bower.json +1 -1
  4. package/build/rollup.js +1 -1
  5. package/dist/css/tabulator.css +15 -6
  6. package/dist/css/tabulator.css.map +1 -1
  7. package/dist/css/tabulator.min.css +1 -1
  8. package/dist/css/tabulator.min.css.map +1 -1
  9. package/dist/css/tabulator_bootstrap3.css +15 -6
  10. package/dist/css/tabulator_bootstrap3.css.map +1 -1
  11. package/dist/css/tabulator_bootstrap3.min.css +1 -1
  12. package/dist/css/tabulator_bootstrap3.min.css.map +1 -1
  13. package/dist/css/tabulator_bootstrap4.css +15 -6
  14. package/dist/css/tabulator_bootstrap4.css.map +1 -1
  15. package/dist/css/tabulator_bootstrap4.min.css +1 -1
  16. package/dist/css/tabulator_bootstrap4.min.css.map +1 -1
  17. package/dist/css/tabulator_bulma.css +15 -6
  18. package/dist/css/tabulator_bulma.css.map +1 -1
  19. package/dist/css/tabulator_bulma.min.css +1 -1
  20. package/dist/css/tabulator_bulma.min.css.map +1 -1
  21. package/dist/css/tabulator_materialize.css +22 -10
  22. package/dist/css/tabulator_materialize.css.map +1 -1
  23. package/dist/css/tabulator_materialize.min.css +1 -1
  24. package/dist/css/tabulator_materialize.min.css.map +1 -1
  25. package/dist/css/tabulator_midnight.css +19 -6
  26. package/dist/css/tabulator_midnight.css.map +1 -1
  27. package/dist/css/tabulator_midnight.min.css +1 -1
  28. package/dist/css/tabulator_midnight.min.css.map +1 -1
  29. package/dist/css/tabulator_modern.css +15 -6
  30. package/dist/css/tabulator_modern.css.map +1 -1
  31. package/dist/css/tabulator_modern.min.css +1 -1
  32. package/dist/css/tabulator_modern.min.css.map +1 -1
  33. package/dist/css/tabulator_semanticui.css +15 -6
  34. package/dist/css/tabulator_semanticui.css.map +1 -1
  35. package/dist/css/tabulator_semanticui.min.css +1 -1
  36. package/dist/css/tabulator_semanticui.min.css.map +1 -1
  37. package/dist/css/tabulator_simple.css +15 -6
  38. package/dist/css/tabulator_simple.css.map +1 -1
  39. package/dist/css/tabulator_simple.min.css +1 -1
  40. package/dist/css/tabulator_simple.min.css.map +1 -1
  41. package/dist/css/tabulator_site.css +19 -6
  42. package/dist/css/tabulator_site.css.map +1 -1
  43. package/dist/css/tabulator_site.min.css +1 -1
  44. package/dist/css/tabulator_site.min.css.map +1 -1
  45. package/dist/js/tabulator.js +853 -390
  46. package/dist/js/tabulator.js.map +1 -1
  47. package/dist/js/tabulator.min.js +2 -2
  48. package/dist/js/tabulator.min.js.map +1 -1
  49. package/dist/js/tabulator_esm.js +1106 -656
  50. package/dist/js/tabulator_esm.js.map +1 -1
  51. package/dist/js/tabulator_esm.min.js +2 -2
  52. package/dist/js/tabulator_esm.min.js.map +1 -1
  53. package/package.json +1 -1
  54. package/src/js/core/RowManager.js +7 -7
  55. package/src/js/core/Tabulator.js +0 -43
  56. package/src/js/core/cell/Cell.js +5 -1
  57. package/src/js/core/column/Column.js +19 -4
  58. package/src/js/core/column/ColumnComponent.js +4 -0
  59. package/src/js/core/column/defaults/options.js +1 -0
  60. package/src/js/core/defaults/options.js +2 -2
  61. package/src/js/core/modules/optional.js +1 -0
  62. package/src/js/core/rendering/renderers/BasicVertical.js +2 -1
  63. package/src/js/core/rendering/renderers/VirtualDomHorizontal.js +17 -8
  64. package/src/js/core/row/Row.js +2 -2
  65. package/src/js/core/tools/DataLoader.js +4 -4
  66. package/src/js/core/tools/InteractionMonitor.js +6 -2
  67. package/src/js/modules/Ajax/Ajax.js +62 -82
  68. package/src/js/modules/ColumnCalcs/ColumnCalcs.js +1 -1
  69. package/src/js/modules/DataTree/DataTree.js +5 -0
  70. package/src/js/modules/Download/defaults/downloaders/json.js +1 -1
  71. package/src/js/modules/Download/defaults/downloaders/jsonLines.js +32 -0
  72. package/src/js/modules/Download/defaults/downloaders.js +2 -0
  73. package/src/js/modules/Edit/Edit.js +23 -31
  74. package/src/js/modules/Filter/Filter.js +1 -1
  75. package/src/js/modules/Format/defaults/formatters/datetime.js +1 -1
  76. package/src/js/modules/Format/defaults/formatters/datetimediff.js +2 -1
  77. package/src/js/modules/FrozenRows/FrozenRows.js +9 -0
  78. package/src/js/modules/GroupRows/Group.js +2 -61
  79. package/src/js/modules/GroupRows/GroupRows.js +2 -2
  80. package/src/js/modules/Import/Import.js +197 -0
  81. package/src/js/modules/Import/defaults/importers/csv.js +63 -0
  82. package/src/js/modules/Import/defaults/importers/json.js +8 -0
  83. package/src/js/modules/Import/defaults/importers.js +7 -0
  84. package/src/js/modules/Interaction/Interaction.js +5 -0
  85. package/src/js/modules/Keybindings/Keybindings.js +9 -14
  86. package/src/js/modules/Keybindings/defaults/bindings.js +3 -3
  87. package/src/js/modules/Localize/defaults/langs.js +6 -0
  88. package/src/js/modules/Menu/Menu.js +200 -155
  89. package/src/js/modules/MoveRows/MoveRows.js +4 -0
  90. package/src/js/modules/Page/Page.js +271 -173
  91. package/src/js/modules/Page/defaults/pageCounters/pages.js +33 -0
  92. package/src/js/modules/Page/defaults/pageCounters/rows.js +32 -0
  93. package/src/js/modules/Page/defaults/pageCounters.js +8 -0
  94. package/src/js/modules/ResizeRows/ResizeRows.js +1 -1
  95. package/src/js/modules/Sort/defaults/sorters/datetime.js +2 -2
  96. package/src/js/modules/Validate/Validate.js +7 -5
  97. package/src/scss/tabulator.scss +20 -6
  98. package/src/scss/themes/materialize/tabulator_materialize.scss +5 -4
  99. package/src/scss/themes/tabulator_midnight.scss +4 -0
  100. package/src/scss/themes/tabulator_site.scss +4 -0
@@ -1,42 +1,50 @@
1
1
  import Module from '../../core/Module.js';
2
2
 
3
- import Helpers from '../../core/tools/Helpers.js';
3
+ import defaultPageCounters from './defaults/pageCounters.js';
4
4
 
5
5
  class Page extends Module{
6
-
6
+
7
7
  constructor(table){
8
8
  super(table);
9
-
9
+
10
10
  this.mode = "local";
11
11
  this.progressiveLoad = false;
12
-
12
+
13
+ this.element = null;
14
+ this.pageCounterElement = null;
15
+ this.pageCounter = null;
16
+
13
17
  this.size = 0;
14
18
  this.page = 1;
15
19
  this.count = 5;
16
20
  this.max = 1;
17
21
 
22
+ this.remoteRowCountEstimate = null;
23
+
18
24
  this.displayIndex = 0; //index in display pipeline
19
-
25
+
20
26
  this.initialLoad = true;
21
27
  this.dataChanging = false; //flag to check if data is being changed by this module
22
-
28
+
23
29
  this.pageSizes = [];
24
-
30
+
25
31
  this.registerTableOption("pagination", false); //set pagination type
26
32
  this.registerTableOption("paginationMode", "local"); //local or remote pagination
27
33
  this.registerTableOption("paginationSize", false); //set number of rows to a page
28
34
  this.registerTableOption("paginationInitialPage", 1); //initial page to show on load
35
+ this.registerTableOption("paginationCounter", false); // set pagination counter
36
+ this.registerTableOption("paginationCounterElement", false); // set pagination counter
29
37
  this.registerTableOption("paginationButtonCount", 5); // set count of page button
30
38
  this.registerTableOption("paginationSizeSelector", false); //add pagination size selector element
31
39
  this.registerTableOption("paginationElement", false); //element to hold pagination numbers
32
40
  // this.registerTableOption("paginationDataSent", {}); //pagination data sent to the server
33
41
  // this.registerTableOption("paginationDataReceived", {}); //pagination data received from the server
34
42
  this.registerTableOption("paginationAddRow", "page"); //add rows on table or page
35
-
43
+
36
44
  this.registerTableOption("progressiveLoad", false); //progressive loading
37
45
  this.registerTableOption("progressiveLoadDelay", 0); //delay between requests
38
46
  this.registerTableOption("progressiveLoadScrollMargin", 0); //margin before scroll begins
39
-
47
+
40
48
  this.registerTableFunction("setMaxPage", this.setMaxPage.bind(this));
41
49
  this.registerTableFunction("setPage", this.setPage.bind(this));
42
50
  this.registerTableFunction("setPageToRow", this.userSetPageToRow.bind(this));
@@ -46,11 +54,11 @@ class Page extends Module{
46
54
  this.registerTableFunction("nextPage", this.nextPage.bind(this));
47
55
  this.registerTableFunction("getPage", this.getPage.bind(this));
48
56
  this.registerTableFunction("getPageMax", this.getPageMax.bind(this));
49
-
57
+
50
58
  //register component functions
51
59
  this.registerComponentFunction("row", "pageTo", this.setPageToRow.bind(this));
52
60
  }
53
-
61
+
54
62
  initialize(){
55
63
  if(this.table.options.pagination){
56
64
  this.subscribe("row-deleted", this.rowsUpdated.bind(this));
@@ -58,40 +66,41 @@ class Page extends Module{
58
66
  this.subscribe("row-added", this.rowsUpdated.bind(this));
59
67
  this.subscribe("data-processed", this.initialLoadComplete.bind(this));
60
68
  this.subscribe("table-built", this.calculatePageSizes.bind(this));
61
-
69
+
62
70
  if(this.table.options.paginationMode === "remote"){
63
71
  this.subscribe("data-params", this.remotePageParams.bind(this));
64
72
  this.subscribe("data-loaded", this._parseRemoteData.bind(this));
65
73
  }
66
-
74
+
67
75
  if(this.table.options.progressiveLoad){
68
76
  console.error("Progressive Load Error - Pagination and progressive load cannot be used at the same time");
69
77
  }
70
-
78
+
71
79
  this.registerDisplayHandler(this.restOnRenderBefore.bind(this), 40);
72
80
  this.registerDisplayHandler(this.getRows.bind(this), 50);
73
-
81
+
74
82
  this.createElements();
83
+ this.initializePageCounter();
75
84
  this.initializePaginator();
76
85
  }else if(this.table.options.progressiveLoad){
77
86
  this.subscribe("data-params", this.remotePageParams.bind(this));
78
87
  this.subscribe("data-loaded", this._parseRemoteData.bind(this));
79
88
  this.subscribe("table-built", this.calculatePageSizes.bind(this));
80
89
  this.subscribe("data-processed", this.initialLoadComplete.bind(this));
81
-
90
+
82
91
  this.initializeProgressive(this.table.options.progressiveLoad)
83
-
92
+
84
93
  if(this.table.options.progressiveLoad === "scroll"){
85
94
  this.subscribe("scroll-vertical", this.scrollVertical.bind(this));
86
95
  }
87
96
  }
88
97
  }
89
-
98
+
90
99
  rowAddingPosition(row, top){
91
100
  var rowManager = this.table.rowManager,
92
101
  dispRows = rowManager.getDisplayRows(),
93
102
  index;
94
-
103
+
95
104
  if(top){
96
105
  if(dispRows.length){
97
106
  index = dispRows[0];
@@ -107,74 +116,74 @@ class Page extends Module{
107
116
  top = dispRows.length < this.size ? false : true;
108
117
  }
109
118
  }
110
-
119
+
111
120
  return {index, top}
112
121
  }
113
-
122
+
114
123
  calculatePageSizes(){
115
124
  var testElRow, testElCell;
116
-
125
+
117
126
  if(this.table.options.paginationSize){
118
127
  this.size = this.table.options.paginationSize;
119
128
  }else{
120
129
  testElRow = document.createElement("div");
121
130
  testElRow.classList.add("tabulator-row");
122
131
  testElRow.style.visibility = "hidden";
123
-
132
+
124
133
  testElCell = document.createElement("div");
125
134
  testElCell.classList.add("tabulator-cell");
126
135
  testElCell.innerHTML = "Page Row Test";
127
-
136
+
128
137
  testElRow.appendChild(testElCell);
129
-
138
+
130
139
  this.table.rowManager.getTableElement().appendChild(testElRow);
131
-
140
+
132
141
  this.size = Math.floor(this.table.rowManager.getElement().clientHeight / testElRow.offsetHeight);
133
-
142
+
134
143
  this.table.rowManager.getTableElement().removeChild(testElRow);
135
144
  }
136
-
145
+
137
146
  this.generatePageSizeSelectList();
138
147
  }
139
-
148
+
140
149
  initialLoadComplete(){
141
150
  this.initialLoad = false;
142
151
  }
143
-
152
+
144
153
  remotePageParams(data, config, silent, params){
145
154
  if(!this.initialLoad){
146
155
  if((this.progressiveLoad && !silent) || (!this.progressiveLoad && !this.dataChanging)){
147
156
  this.reset(true);
148
157
  }
149
158
  }
150
-
159
+
151
160
  //configure request params
152
161
  params.page = this.page;
153
-
162
+
154
163
  //set page size if defined
155
164
  if(this.size){
156
165
  params.size = this.size;
157
166
  }
158
-
167
+
159
168
  return params;
160
169
  }
161
-
170
+
162
171
  ///////////////////////////////////
163
172
  ///////// Table Functions /////////
164
173
  ///////////////////////////////////
165
-
174
+
166
175
  userSetPageToRow(row){
167
176
  if(this.table.options.pagination){
168
177
  row = this.rowManager.findRow(row);
169
-
178
+
170
179
  if(row){
171
180
  return this.setPageToRow(row)
172
181
  }
173
182
  }
174
-
183
+
175
184
  return Promise.reject();
176
185
  }
177
-
186
+
178
187
  userSetPageSize(size){
179
188
  if(this.table.options.pagination){
180
189
  this.setPageSize(size);
@@ -186,102 +195,102 @@ class Page extends Module{
186
195
  ///////////////////////////////////
187
196
  ///////// Internal Logic //////////
188
197
  ///////////////////////////////////
189
-
198
+
190
199
  scrollVertical(top, dir){
191
200
  var element, diff, margin;
192
201
  if(!dir && !this.table.dataLoader.loading){
193
202
  element = this.table.rowManager.getElement();
194
203
  diff = element.scrollHeight - element.clientHeight - top;
195
204
  margin = this.table.options.progressiveLoadScrollMargin || (element.clientHeight * 2);
196
-
205
+
197
206
  if(diff < margin){
198
207
  this.nextPage()
199
208
  .catch(() => {}); //consume the exception thrown when on the last page
200
209
  }
201
210
  }
202
211
  }
203
-
212
+
204
213
  restOnRenderBefore(rows, renderInPosition){
205
214
  if(!renderInPosition){
206
215
  if(this.mode === "local"){
207
216
  this.reset();
208
217
  }
209
218
  }
210
-
219
+
211
220
  return rows;
212
221
  }
213
-
222
+
214
223
  rowsUpdated(){
215
224
  this.refreshData(true, "all");
216
225
  }
217
-
226
+
218
227
  createElements(){
219
228
  var button;
220
-
229
+
221
230
  this.element = document.createElement("span");
222
231
  this.element.classList.add("tabulator-paginator");
223
-
232
+
224
233
  this.pagesElement = document.createElement("span");
225
234
  this.pagesElement.classList.add("tabulator-pages");
226
-
235
+
227
236
  button = document.createElement("button");
228
237
  button.classList.add("tabulator-page");
229
238
  button.setAttribute("type", "button");
230
239
  button.setAttribute("role", "button");
231
240
  button.setAttribute("aria-label", "");
232
241
  button.setAttribute("title", "");
233
-
242
+
234
243
  this.firstBut = button.cloneNode(true);
235
244
  this.firstBut.setAttribute("data-page", "first");
236
-
245
+
237
246
  this.prevBut = button.cloneNode(true);
238
247
  this.prevBut.setAttribute("data-page", "prev");
239
-
248
+
240
249
  this.nextBut = button.cloneNode(true);
241
250
  this.nextBut.setAttribute("data-page", "next");
242
-
251
+
243
252
  this.lastBut = button.cloneNode(true);
244
253
  this.lastBut.setAttribute("data-page", "last");
245
-
254
+
246
255
  if(this.table.options.paginationSizeSelector){
247
256
  this.pageSizeSelect = document.createElement("select");
248
257
  this.pageSizeSelect.classList.add("tabulator-page-size");
249
258
  }
250
259
  }
251
-
260
+
252
261
  generatePageSizeSelectList(){
253
262
  var pageSizes = [];
254
-
263
+
255
264
  if(this.pageSizeSelect){
256
-
265
+
257
266
  if(Array.isArray(this.table.options.paginationSizeSelector)){
258
267
  pageSizes = this.table.options.paginationSizeSelector;
259
268
  this.pageSizes = pageSizes;
260
-
269
+
261
270
  if(this.pageSizes.indexOf(this.size) == -1){
262
271
  pageSizes.unshift(this.size);
263
272
  }
264
273
  }else{
265
-
274
+
266
275
  if(this.pageSizes.indexOf(this.size) == -1){
267
276
  pageSizes = [];
268
-
277
+
269
278
  for (let i = 1; i < 5; i++){
270
279
  pageSizes.push(this.size * i);
271
280
  }
272
-
281
+
273
282
  this.pageSizes = pageSizes;
274
283
  }else{
275
284
  pageSizes = this.pageSizes;
276
285
  }
277
286
  }
278
-
287
+
279
288
  while(this.pageSizeSelect.firstChild) this.pageSizeSelect.removeChild(this.pageSizeSelect.firstChild);
280
-
289
+
281
290
  pageSizes.forEach((item) => {
282
291
  var itemEl = document.createElement("option");
283
292
  itemEl.value = item;
284
-
293
+
285
294
  if(item === true){
286
295
  this.langBind("pagination|all", function(value){
287
296
  itemEl.innerHTML = value;
@@ -289,136 +298,180 @@ class Page extends Module{
289
298
  }else{
290
299
  itemEl.innerHTML = item;
291
300
  }
292
-
293
-
294
-
301
+
302
+
303
+
295
304
  this.pageSizeSelect.appendChild(itemEl);
296
305
  });
297
-
306
+
298
307
  this.pageSizeSelect.value = this.size;
299
308
  }
300
309
  }
301
-
302
- //setup pageination
310
+
311
+ initializePageCounter(){
312
+ var counter = this.table.options.paginationCounter,
313
+ pageCounter = null;
314
+
315
+ if(counter){
316
+ if(typeof counter === "function"){
317
+ pageCounter = counter;
318
+ }else{
319
+ pageCounter = Page.pageCounters[counter];
320
+ }
321
+
322
+ if(pageCounter){
323
+ this.pageCounter = pageCounter;
324
+
325
+ this.pageCounterElement = document.createElement("span");
326
+ this.pageCounterElement.classList.add("tabulator-page-counter");
327
+ }else{
328
+ console.warn("Pagination Error - No such page counter found: ", counter);
329
+ }
330
+ }
331
+ }
332
+
333
+ //setup pagination
303
334
  initializePaginator(hidden){
304
- var pageSelectLabel;
305
-
335
+ var pageSelectLabel, paginationCounterHolder;
336
+
306
337
  if(!hidden){
307
338
  //build pagination element
308
-
339
+
309
340
  //bind localizations
310
341
  this.langBind("pagination|first", (value) => {
311
342
  this.firstBut.innerHTML = value;
312
343
  });
313
-
344
+
314
345
  this.langBind("pagination|first_title", (value) => {
315
346
  this.firstBut.setAttribute("aria-label", value);
316
347
  this.firstBut.setAttribute("title", value);
317
348
  });
318
-
349
+
319
350
  this.langBind("pagination|prev", (value) => {
320
351
  this.prevBut.innerHTML = value;
321
352
  });
322
-
353
+
323
354
  this.langBind("pagination|prev_title", (value) => {
324
355
  this.prevBut.setAttribute("aria-label", value);
325
356
  this.prevBut.setAttribute("title", value);
326
357
  });
327
-
358
+
328
359
  this.langBind("pagination|next", (value) => {
329
360
  this.nextBut.innerHTML = value;
330
361
  });
331
-
362
+
332
363
  this.langBind("pagination|next_title", (value) => {
333
364
  this.nextBut.setAttribute("aria-label", value);
334
365
  this.nextBut.setAttribute("title", value);
335
366
  });
336
-
367
+
337
368
  this.langBind("pagination|last", (value) => {
338
369
  this.lastBut.innerHTML = value;
339
370
  });
340
-
371
+
341
372
  this.langBind("pagination|last_title", (value) => {
342
373
  this.lastBut.setAttribute("aria-label", value);
343
374
  this.lastBut.setAttribute("title", value);
344
375
  });
345
-
376
+
346
377
  //click bindings
347
378
  this.firstBut.addEventListener("click", () => {
348
379
  this.setPage(1)
349
380
  });
350
-
381
+
351
382
  this.prevBut.addEventListener("click", () => {
352
383
  this.previousPage()
353
384
  });
354
-
385
+
355
386
  this.nextBut.addEventListener("click", () => {
356
387
  this.nextPage()
357
388
  });
358
-
389
+
359
390
  this.lastBut.addEventListener("click", () => {
360
391
  this.setPage(this.max)
361
392
  });
362
-
393
+
363
394
  if(this.table.options.paginationElement){
364
395
  this.element = this.table.options.paginationElement;
365
396
  }
366
-
397
+
367
398
  if(this.pageSizeSelect){
368
399
  pageSelectLabel = document.createElement("label");
369
-
400
+
370
401
  this.langBind("pagination|page_size", (value) => {
371
402
  this.pageSizeSelect.setAttribute("aria-label", value);
372
403
  this.pageSizeSelect.setAttribute("title", value);
373
404
  pageSelectLabel.innerHTML = value;
374
405
  });
375
-
406
+
376
407
  this.element.appendChild(pageSelectLabel);
377
408
  this.element.appendChild(this.pageSizeSelect);
378
-
409
+
379
410
  this.pageSizeSelect.addEventListener("change", (e) => {
380
411
  this.setPageSize(this.pageSizeSelect.value == "true" ? true : this.pageSizeSelect.value);
381
412
  this.setPage(1)
382
413
  });
383
414
  }
384
-
415
+
385
416
  //append to DOM
386
417
  this.element.appendChild(this.firstBut);
387
418
  this.element.appendChild(this.prevBut);
388
419
  this.element.appendChild(this.pagesElement);
389
420
  this.element.appendChild(this.nextBut);
390
421
  this.element.appendChild(this.lastBut);
391
-
422
+
392
423
  if(!this.table.options.paginationElement && !hidden){
424
+ if(this.table.options.paginationCounter){
425
+
426
+ paginationCounterHolder
427
+
428
+ if(this.table.options.paginationCounterElement){
429
+ if(this.table.options.paginationCounterElement instanceof HTMLElement){
430
+ this.table.options.paginationCounterElement.appendChild(this.pageCounterElement);
431
+ }else if(typeof this.table.options.paginationCounterElement === "string"){
432
+ paginationCounterHolder = document.querySelector(this.table.options.paginationCounterElement);
433
+
434
+ if(paginationCounterHolder){
435
+ paginationCounterHolder.appendChild(this.pageCounterElement);
436
+ }else{
437
+ console.warn("Pagination Error - Unable to find element matching paginationCounterElement selector:", this.table.options.paginationCounterElement);
438
+ }
439
+ }
440
+ }else{
441
+ this.table.footerManager.append(this.pageCounterElement);
442
+ }
443
+
444
+ }
445
+
393
446
  this.table.footerManager.append(this.element, this);
394
447
  }
395
-
448
+
396
449
  this.page = this.table.options.paginationInitialPage;
397
450
  this.count = this.table.options.paginationButtonCount;
398
451
  }
399
-
452
+
400
453
  //set default values
401
454
  this.mode = this.table.options.paginationMode;
402
455
  }
403
-
456
+
404
457
  initializeProgressive(mode){
405
458
  this.initializePaginator(true);
406
459
  this.mode = "progressive_" + mode;
407
460
  this.progressiveLoad = true;
408
461
  }
409
-
462
+
410
463
  trackChanges(){
411
464
  this.dispatch("page-changed");
412
465
  }
413
-
466
+
414
467
  setDisplayIndex(index){
415
468
  this.displayIndex = index;
416
469
  }
417
-
470
+
418
471
  getDisplayIndex(){
419
472
  return this.displayIndex;
420
473
  }
421
-
474
+
422
475
  //calculate maximum page from number of rows
423
476
  setMaxRows(rowCount){
424
477
  if(!rowCount){
@@ -426,12 +479,12 @@ class Page extends Module{
426
479
  }else{
427
480
  this.max = this.size === true ? 1 : Math.ceil(rowCount/this.size);
428
481
  }
429
-
482
+
430
483
  if(this.page > this.max){
431
484
  this.page = this.max;
432
485
  }
433
486
  }
434
-
487
+
435
488
  //reset to first page without triggering action
436
489
  reset(force){
437
490
  if(!this.initialLoad){
@@ -440,95 +493,132 @@ class Page extends Module{
440
493
  }
441
494
  }
442
495
  }
443
-
496
+
444
497
  //set the maximum page
445
498
  setMaxPage(max){
446
-
499
+
447
500
  max = parseInt(max);
448
-
501
+
449
502
  this.max = max || 1;
450
-
503
+
451
504
  if(this.page > this.max){
452
505
  this.page = this.max;
453
506
  this.trigger();
454
507
  }
455
508
  }
456
-
509
+
457
510
  //set current page number
458
511
  setPage(page){
459
512
  switch(page){
460
513
  case "first":
461
514
  return this.setPage(1);
462
515
  break;
463
-
516
+
464
517
  case "prev":
465
518
  return this.previousPage();
466
519
  break;
467
-
520
+
468
521
  case "next":
469
522
  return this.nextPage();
470
523
  break;
471
-
524
+
472
525
  case "last":
473
526
  return this.setPage(this.max);
474
527
  break;
475
528
  }
476
-
477
-
529
+
478
530
  page = parseInt(page);
479
-
531
+
480
532
  if((page > 0 && page <= this.max) || this.mode !== "local"){
481
533
  this.page = page;
482
-
534
+
483
535
  this.trackChanges();
484
-
536
+
485
537
  return this.trigger();
486
538
  }else{
487
539
  console.warn("Pagination Error - Requested page is out of range of 1 - " + this.max + ":", page);
488
540
  return Promise.reject();
489
541
  }
490
542
  }
491
-
543
+
492
544
  setPageToRow(row){
493
545
  var rows = this.table.rowManager.getDisplayRows(this.displayIndex - 1);
494
546
  var index = rows.indexOf(row);
495
-
547
+
496
548
  if(index > -1){
497
549
  var page = this.size === true ? 1 : Math.ceil((index + 1) / this.size);
498
-
550
+
499
551
  return this.setPage(page)
500
552
  }else{
501
553
  console.warn("Pagination Error - Requested row is not visible");
502
554
  return Promise.reject();
503
555
  }
504
556
  }
505
-
557
+
506
558
  setPageSize(size){
507
559
  if(size !== true){
508
560
  size = parseInt(size);
509
561
  }
510
-
562
+
511
563
  if(size > 0){
512
564
  this.size = size;
513
565
  }
514
-
566
+
515
567
  if(this.pageSizeSelect){
516
568
  // this.pageSizeSelect.value = size;
517
569
  this.generatePageSizeSelectList();
518
570
  }
519
-
571
+
520
572
  this.trackChanges();
521
573
  }
574
+
575
+ _setPageCounter(totalRows){
576
+ var content, currentRow;
577
+
578
+ if(this.pageCounter){
579
+ currentRow = ((this.page - 1) * this.size) + 1;
522
580
 
581
+ if(this.mode === "remote"){
582
+ totalRows = this.remoteRowCountEstimate;
583
+ }
584
+
585
+ content = this.pageCounter.call(this, this.size, currentRow, this.page, totalRows, this.max);
586
+
587
+ switch(typeof content){
588
+ case "object":
589
+ if(content instanceof Node){
590
+
591
+ //clear previous cell contents
592
+ while(this.pageCounterElement.firstChild) this.pageCounterElement.removeChild(this.pageCounterElement.firstChild);
593
+
594
+ this.pageCounterElement.appendChild(content);
595
+ }else{
596
+ this.pageCounterElement.innerHTML = "";
597
+
598
+ if(content != null){
599
+ console.warn("Page Counter Error - Page Counter has returned a type of object, the only valid page counter object return is an instance of Node, the page counter returned:", content);
600
+ }
601
+ }
602
+ break;
603
+ case "undefined":
604
+ case "null":
605
+ this.pageCounterElement.innerHTML = "";
606
+ break;
607
+ default:
608
+ this.pageCounterElement.innerHTML = content;
609
+ }
610
+ }
611
+ }
612
+
523
613
  //setup the pagination buttons
524
614
  _setPageButtons(){
525
615
  let leftSize = Math.floor((this.count-1) / 2);
526
616
  let rightSize = Math.ceil((this.count-1) / 2);
527
617
  let min = this.max - this.page + leftSize + 1 < this.count ? this.max-this.count+1: Math.max(this.page-leftSize,1);
528
618
  let max = this.page <= rightSize? Math.min(this.count, this.max) :Math.min(this.page+rightSize, this.max);
529
-
619
+
530
620
  while(this.pagesElement.firstChild) this.pagesElement.removeChild(this.pagesElement.firstChild);
531
-
621
+
532
622
  if(this.page == 1){
533
623
  this.firstBut.disabled = true;
534
624
  this.prevBut.disabled = true;
@@ -536,7 +626,7 @@ class Page extends Module{
536
626
  this.firstBut.disabled = false;
537
627
  this.prevBut.disabled = false;
538
628
  }
539
-
629
+
540
630
  if(this.page == this.max){
541
631
  this.lastBut.disabled = true;
542
632
  this.nextBut.disabled = true;
@@ -544,66 +634,66 @@ class Page extends Module{
544
634
  this.lastBut.disabled = false;
545
635
  this.nextBut.disabled = false;
546
636
  }
547
-
637
+
548
638
  for(let i = min; i <= max; i++){
549
639
  if(i>0 && i <= this.max){
550
640
  this.pagesElement.appendChild(this._generatePageButton(i));
551
641
  }
552
642
  }
553
-
643
+
554
644
  this.footerRedraw();
555
645
  }
556
-
646
+
557
647
  _generatePageButton(page){
558
648
  var button = document.createElement("button");
559
-
649
+
560
650
  button.classList.add("tabulator-page");
561
651
  if(page == this.page){
562
652
  button.classList.add("active");
563
653
  }
564
-
654
+
565
655
  button.setAttribute("type", "button");
566
656
  button.setAttribute("role", "button");
567
-
657
+
568
658
  this.langBind("pagination|page_title", (value) => {
569
659
  button.setAttribute("aria-label", value + " " + page);
570
660
  button.setAttribute("title", value + " " + page);
571
661
  });
572
-
662
+
573
663
  button.setAttribute("data-page", page);
574
664
  button.textContent = page;
575
-
665
+
576
666
  button.addEventListener("click", (e) => {
577
667
  this.setPage(page)
578
668
  });
579
-
669
+
580
670
  return button;
581
671
  }
582
-
672
+
583
673
  //previous page
584
674
  previousPage(){
585
675
  if(this.page > 1){
586
676
  this.page--;
587
-
677
+
588
678
  this.trackChanges();
589
-
679
+
590
680
  return this.trigger()
591
-
681
+
592
682
  }else{
593
683
  console.warn("Pagination Error - Previous page would be less than page 1:", 0);
594
684
  return Promise.reject();
595
685
  }
596
686
  }
597
-
687
+
598
688
  //next page
599
689
  nextPage(){
600
690
  if(this.page < this.max){
601
691
  this.page++;
602
-
692
+
603
693
  this.trackChanges();
604
-
694
+
605
695
  return this.trigger();
606
-
696
+
607
697
  }else{
608
698
  if(!this.progressiveLoad){
609
699
  console.warn("Pagination Error - Next page would be greater than maximum page of " + this.max + ":", this.max + 1);
@@ -611,34 +701,34 @@ class Page extends Module{
611
701
  return Promise.reject();
612
702
  }
613
703
  }
614
-
704
+
615
705
  //return current page number
616
706
  getPage(){
617
707
  return this.page;
618
708
  }
619
-
709
+
620
710
  //return max page number
621
711
  getPageMax(){
622
712
  return this.max;
623
713
  }
624
-
714
+
625
715
  getPageSize(size){
626
716
  return this.size;
627
717
  }
628
-
718
+
629
719
  getMode(){
630
720
  return this.mode;
631
721
  }
632
-
722
+
633
723
  //return appropriate rows for current page
634
724
  getRows(data){
635
725
  var output, start, end;
636
-
726
+
637
727
  if(this.mode == "local"){
638
728
  output = [];
639
-
729
+
640
730
  this.setMaxRows(data.length);
641
-
731
+
642
732
  if(this.size === true){
643
733
  start = 0;
644
734
  end = data.length;
@@ -646,39 +736,42 @@ class Page extends Module{
646
736
  start = this.size * (this.page - 1);
647
737
  end = start + parseInt(this.size);
648
738
  }
649
-
650
-
739
+
740
+
651
741
  this._setPageButtons();
652
-
742
+
653
743
  for(let i = start; i < end; i++){
654
744
  if(data[i]){
655
745
  output.push(data[i]);
656
746
  }
657
747
  }
658
748
 
749
+ this._setPageCounter(data.length);
750
+
659
751
  return output;
660
752
  }else{
661
753
  this._setPageButtons();
662
-
754
+ this._setPageCounter(data.length);
755
+
663
756
  return data.slice(0);
664
757
  }
665
758
  }
666
-
759
+
667
760
  trigger(){
668
761
  var left;
669
-
762
+
670
763
  switch(this.mode){
671
764
  case "local":
672
765
  left = this.table.rowManager.scrollLeft;
673
-
766
+
674
767
  this.refreshData();
675
768
  this.table.rowManager.scrollHorizontal(left);
676
-
769
+
677
770
  this.dispatchExternal("pageLoaded", this.getPage());
678
-
771
+
679
772
  return Promise.resolve();
680
773
  break;
681
-
774
+
682
775
  case "remote":
683
776
  this.dataChanging = true;
684
777
  return this.reloadData(null)
@@ -686,52 +779,54 @@ class Page extends Module{
686
779
  this.dataChanging = false;
687
780
  })
688
781
  break;
689
-
782
+
690
783
  case "progressive_load":
691
784
  case "progressive_scroll":
692
785
  return this.reloadData(null, true);
693
786
  break;
694
-
787
+
695
788
  default:
696
789
  console.warn("Pagination Error - no such pagination mode:", this.mode);
697
790
  return Promise.reject();
698
791
  }
699
792
  }
700
-
793
+
701
794
  _parseRemoteData(data){
702
795
  var left, data, margin;
703
-
796
+
704
797
  if(typeof data.last_page === "undefined"){
705
798
  console.warn("Remote Pagination Error - Server response missing '" + (this.options("dataReceiveParams").last_page || "last_page") + "' property");
706
799
  }
707
-
800
+
708
801
  if(data.data){
709
802
  this.max = parseInt(data.last_page) || 1;
710
803
 
804
+ this.remoteRowCountEstimate = typeof data.last_row !== "undefined" ? data.last_row : (data.last_page * this.size - (this.page == data.last_page ? (this.size - data.data.length) : 0));
805
+
711
806
  if(this.progressiveLoad){
712
807
  switch(this.mode){
713
808
  case "progressive_load":
714
-
809
+
715
810
  if(this.page == 1){
716
811
  this.table.rowManager.setData(data.data, false, this.page == 1)
717
812
  }else{
718
813
  this.table.rowManager.addRows(data.data);
719
814
  }
720
-
815
+
721
816
  if(this.page < this.max){
722
817
  setTimeout(() => {
723
818
  this.nextPage();
724
819
  }, this.table.options.progressiveLoadDelay);
725
820
  }
726
821
  break;
727
-
822
+
728
823
  case "progressive_scroll":
729
824
  data = this.page === 1 ? data.data : this.table.rowManager.getData().concat(data.data);
730
-
825
+
731
826
  this.table.rowManager.setData(data, this.page !== 1, this.page == 1);
732
-
827
+
733
828
  margin = this.table.options.progressiveLoadScrollMargin || (this.table.rowManager.element.clientHeight * 2);
734
-
829
+
735
830
  if(this.table.rowManager.element.scrollHeight <= (this.table.rowManager.element.clientHeight + margin)){
736
831
  setTimeout(() => {
737
832
  this.nextPage();
@@ -739,7 +834,7 @@ class Page extends Module{
739
834
  }
740
835
  break;
741
836
  }
742
-
837
+
743
838
  return false;
744
839
  }else{
745
840
  // left = this.table.rowManager.scrollLeft;
@@ -747,23 +842,23 @@ class Page extends Module{
747
842
  // this.table.rowManager.scrollHorizontal(left);
748
843
  // this.table.columnManager.scrollHorizontal(left);
749
844
  }
750
-
845
+
751
846
  }else{
752
847
  console.warn("Remote Pagination Error - Server response missing '" + (this.options("dataReceiveParams").data || "data") + "' property");
753
848
  }
754
-
849
+
755
850
  return data.data;
756
851
  }
757
-
852
+
758
853
  //handle the footer element being redrawn
759
854
  footerRedraw(){
760
855
  var footer = this.table.footerManager.element;
761
-
856
+
762
857
  if((Math.ceil(footer.clientWidth) - footer.scrollWidth) < 0){
763
858
  this.pagesElement.style.display = 'none';
764
859
  }else{
765
860
  this.pagesElement.style.display = '';
766
-
861
+
767
862
  if((Math.ceil(footer.clientWidth) - footer.scrollWidth) < 0){
768
863
  this.pagesElement.style.display = 'none';
769
864
  }
@@ -773,4 +868,7 @@ class Page extends Module{
773
868
 
774
869
  Page.moduleName = "page";
775
870
 
871
+ //load defaults
872
+ Page.pageCounters = defaultPageCounters;
873
+
776
874
  export default Page;