tablefilter 0.7.6 → 0.7.8

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.
@@ -892,11 +892,23 @@
892
892
  //#region src/number.js
893
893
  /**
894
894
  * Formats a numeric value with configurable separators and affixes.
895
+ *
896
+ * Supported options: `locale`, `decimal`, `integerSeparator`, `precision`,
897
+ * `round`, `prefix` and `suffix`. The `format-number` options `truncate`,
898
+ * `padLeft`, `padRight`, `negativeType`, `negativeLeftSymbol`,
899
+ * `negativeRightSymbol`, `negativeOut`, `decimalsSeparator` and `noUnits`
900
+ * have no effect. `integerSeparator: null` disables grouping. Values of
901
+ * magnitude 1e21 and above are rendered in full instead of exponential
902
+ * notation.
903
+ *
904
+ * Requires `Intl.NumberFormat.prototype.formatToParts` (Chrome 64+, Edge 79+,
905
+ * Firefox 58+, Safari 11+, Node 10+).
895
906
  * @param {Number|String} value Numeric value
896
907
  * @param {Object} [options={}] Formatting options
897
908
  * @param {String} [options.locale='en'] Intl locale
898
909
  * @param {String} [options.decimal] Decimal separator override
899
- * @param {String} [options.integerSeparator] Thousands separator override
910
+ * @param {String|null} [options.integerSeparator] Thousands separator override:
911
+ * `undefined` uses locale default grouping, `null` or `''` disables grouping
900
912
  * @param {Number} [options.precision] Fixed number of fraction digits
901
913
  * @param {Number} [options.round] Maximum number of fraction digits
902
914
  * @param {String} [options.prefix=''] Value prefix
@@ -10285,6 +10297,30 @@
10285
10297
  */
10286
10298
  this.containers = [];
10287
10299
  /**
10300
+ * `<tf-checklist>` hosts, when the bridge is active
10301
+ * @type {Array}
10302
+ * @private
10303
+ */
10304
+ this.ceElms = [];
10305
+ /**
10306
+ * Handlers bound to each `<tf-checklist>` host
10307
+ * @type {Array}
10308
+ * @private
10309
+ */
10310
+ this.ceEvt = [];
10311
+ /**
10312
+ * Selected values reported by each `<tf-checklist>` host
10313
+ * @type {Array}
10314
+ * @private
10315
+ */
10316
+ this.ceValues = [];
10317
+ /**
10318
+ * Trigger names cached per column for `<tf-checklist>` hosts
10319
+ * @type {Array}
10320
+ * @private
10321
+ */
10322
+ this.ceNames = [];
10323
+ /**
10288
10324
  * Css class for the container of the checklist filter (div)
10289
10325
  * @type {String}
10290
10326
  */
@@ -10354,6 +10390,83 @@
10354
10390
  }
10355
10391
  }
10356
10392
  /**
10393
+ * `<tf-checklist>` selection event handler
10394
+ * @param {Number} colIndex Column index
10395
+ * @param {Event} evt `selection-change` event
10396
+ * @private
10397
+ */
10398
+ onCESelectionChange(colIndex, evt) {
10399
+ let tf = this.tf;
10400
+ let host = this.ceElms[colIndex];
10401
+ let values = evt.detail && isArray(evt.detail.values) ? evt.detail.values.slice() : [];
10402
+ values = this.normalizeCESelection(colIndex, values);
10403
+ this.ceValues[colIndex] = values;
10404
+ this.syncCEText(colIndex);
10405
+ this.emitter.emit("filter-focus", tf, host);
10406
+ tf.filter();
10407
+ }
10408
+ /**
10409
+ * `<tf-checklist>` open event handler used by the load-on-demand
10410
+ * feature: the options are rendered on the first expansion
10411
+ * @param {Number} colIndex Column index
10412
+ * @param {Event} evt `open-change` event
10413
+ * @private
10414
+ */
10415
+ onCEOpenChange(colIndex, evt) {
10416
+ let host = this.ceElms[colIndex];
10417
+ if (!evt.detail || !evt.detail.open || !host) return;
10418
+ if (host.getAttribute("filled") !== "1") this.build(colIndex);
10419
+ }
10420
+ /**
10421
+ * Keep the reset option exclusive. The element toggles every option
10422
+ * independently, while the legacy checklist clears the other
10423
+ * selections when the reset item is picked and unchecks the reset
10424
+ * item when another option is picked (checkList.js:391-425).
10425
+ * @param {Number} colIndex Column index
10426
+ * @param {Array} values Selected values reported by the element
10427
+ * @returns {Array} Normalized selection
10428
+ * @private
10429
+ */
10430
+ normalizeCESelection(colIndex, values) {
10431
+ let host = this.ceElms[colIndex];
10432
+ let previous = this.ceValues[colIndex] || [];
10433
+ let hasReset = values.indexOf("") !== -1;
10434
+ if (!host || !hasReset || values.length === 1) return values;
10435
+ let normalized = previous.indexOf("") === -1 ? [""] : values.filter((value) => value !== "");
10436
+ host.setSelectedValues(normalized);
10437
+ return normalized;
10438
+ }
10439
+ /**
10440
+ * Render the trigger text from the column name and the selection
10441
+ * count, and name the listbox from the same column name
10442
+ * (v1-webcomponents-investigation.md:247-289)
10443
+ * @param {Number} colIndex Column index
10444
+ * @private
10445
+ */
10446
+ syncCEText(colIndex) {
10447
+ let host = this.ceElms[colIndex];
10448
+ if (!host) return;
10449
+ let name = this.getCEName(colIndex);
10450
+ let count = (this.ceValues[colIndex] || []).filter((value) => value !== "").length;
10451
+ host.setAttribute("trigger-text", count ? `${name} (${count})` : name);
10452
+ host.setAttribute("listbox-label", `${name} options`);
10453
+ }
10454
+ /**
10455
+ * Return the trigger name for a column: its header text, or a
10456
+ * position-based fallback when the header is empty
10457
+ * @param {Number} colIndex Column index
10458
+ * @returns {String} Column name
10459
+ * @private
10460
+ */
10461
+ getCEName(colIndex) {
10462
+ let name = this.ceNames[colIndex];
10463
+ if (!name) {
10464
+ name = this.tf.getHeadersText()[colIndex] || `Column ${colIndex + 1}`;
10465
+ this.ceNames[colIndex] = name;
10466
+ }
10467
+ return name;
10468
+ }
10469
+ /**
10357
10470
  * Refresh all checklist filters
10358
10471
  */
10359
10472
  refreshAll() {
@@ -10367,6 +10480,61 @@
10367
10480
  * @param {DOMElement} container Dom element containing the filter
10368
10481
  */
10369
10482
  init(colIndex, isExternal, container) {
10483
+ if (!this.initialized) {
10484
+ this.onBuildChecklistFilter = (tf, colIndex, isLinked) => this.build(colIndex, isLinked);
10485
+ this.onSelectChecklistOptions = (tf, colIndex, values) => this.selectOptions(colIndex, values);
10486
+ this.onRowsChanged = () => this.refreshAll();
10487
+ this.onAfterFiltering = () => this.linkFilters();
10488
+ this.emitter.on(["build-checklist-filter"], this.onBuildChecklistFilter);
10489
+ this.emitter.on(["select-checklist-options"], this.onSelectChecklistOptions);
10490
+ this.emitter.on(["rows-changed"], this.onRowsChanged);
10491
+ this.emitter.on(["after-filtering"], this.onAfterFiltering);
10492
+ /** @inherited */
10493
+ this.initialized = true;
10494
+ }
10495
+ if (typeof customElements !== "undefined" && customElements.get("tf-checklist")) this.initCE(colIndex, isExternal, container);
10496
+ else this.initLegacy(colIndex, isExternal, container);
10497
+ }
10498
+ /**
10499
+ * Initialize using the <tf-checklist> custom element
10500
+ * @param {Number} colIndex Column index
10501
+ * @param {Boolean} isExternal External filter flag
10502
+ * @param {DOMElement} container Dom element containing the filter
10503
+ * @private
10504
+ */
10505
+ initCE(colIndex, isExternal, container) {
10506
+ let tf = this.tf;
10507
+ let externalFltTgtId = isExternal ? tf.externalFltIds[colIndex] : null;
10508
+ let host = document.createElement("tf-checklist");
10509
+ host.id = tf.buildFilterId(colIndex);
10510
+ host.className = this.containerCssClass;
10511
+ host.setAttribute("col", String(colIndex));
10512
+ if (externalFltTgtId) elm(externalFltTgtId).appendChild(host);
10513
+ else container.appendChild(host);
10514
+ this.containers[colIndex] = host;
10515
+ this.ceElms[colIndex] = host;
10516
+ this.ceValues[colIndex] = [];
10517
+ tf.fltIds.push(host.id);
10518
+ let evt = this.ceEvt[colIndex] = {
10519
+ selectionChange: (e) => this.onCESelectionChange(colIndex, e),
10520
+ openChange: (e) => this.onCEOpenChange(colIndex, e)
10521
+ };
10522
+ addEvt(host, "selection-change", evt.selectionChange);
10523
+ addEvt(host, "open-change", evt.openChange);
10524
+ if (!tf.loadFltOnDemand) this.build(colIndex);
10525
+ else {
10526
+ host.setAttribute("trigger-text", this.activateText);
10527
+ host.setAttribute("listbox-label", `${this.activateText} options`);
10528
+ }
10529
+ }
10530
+ /**
10531
+ * Initialize using the legacy div/ul/li structure
10532
+ * @param {Number} colIndex Column index
10533
+ * @param {Boolean} isExternal External filter flag
10534
+ * @param {DOMElement} container Dom element containing the filter
10535
+ * @private
10536
+ */
10537
+ initLegacy(colIndex, isExternal, container) {
10370
10538
  let tf = this.tf;
10371
10539
  let externalFltTgtId = isExternal ? tf.externalFltIds[colIndex] : null;
10372
10540
  let divCont = createElm("div", ["id", `${this.prfx}${colIndex}_${tf.id}`], ["ct", colIndex], ["filled", "0"]);
@@ -10380,12 +10548,6 @@
10380
10548
  addEvt(divCont, "click", (evt) => this.onCheckListClick(evt));
10381
10549
  divCont.appendChild(createText(this.activateText));
10382
10550
  }
10383
- this.emitter.on(["build-checklist-filter"], (tf, colIndex, isLinked) => this.build(colIndex, isLinked));
10384
- this.emitter.on(["select-checklist-options"], (tf, colIndex, values) => this.selectOptions(colIndex, values));
10385
- this.emitter.on(["rows-changed"], () => this.refreshAll());
10386
- this.emitter.on(["after-filtering"], () => this.linkFilters());
10387
- /** @inherited */
10388
- this.initialized = true;
10389
10551
  }
10390
10552
  /**
10391
10553
  * Build checklist UI
@@ -10400,9 +10562,6 @@
10400
10562
  this.opts = [];
10401
10563
  /** @inherited */
10402
10564
  this.optsTxt = [];
10403
- let flt = this.containers[colIndex];
10404
- let ul = createElm("ul", ["id", tf.fltIds[colIndex]], ["colIndex", colIndex]);
10405
- ul.className = this.filterCssClass;
10406
10565
  let caseSensitive = tf.caseSensitive;
10407
10566
  /** @inherited */
10408
10567
  this.isCustom = tf.isCustomOptions(colIndex);
@@ -10418,7 +10577,6 @@
10418
10577
  if (isLinked && tf.disableExcludedOptions)
10419
10578
  /** @inherited */
10420
10579
  this.excludedOpts = [];
10421
- flt.innerHTML = "";
10422
10580
  tf.eachRow()((row) => {
10423
10581
  let cellValue = tf.getCellValue(row.cells[colIndex]);
10424
10582
  let cellString = matchCase(cellValue, caseSensitive);
@@ -10435,6 +10593,38 @@
10435
10593
  });
10436
10594
  this.opts = this.sortOptions(colIndex, this.opts);
10437
10595
  if (this.excludedOpts) this.excludedOpts = this.sortOptions(colIndex, this.excludedOpts);
10596
+ if (this.ceElms[colIndex]) this.buildCE(colIndex);
10597
+ else this.buildLegacy(colIndex);
10598
+ }
10599
+ /**
10600
+ * Render the options into a <tf-checklist> host
10601
+ * @param {Number} colIndex Column index
10602
+ * @private
10603
+ */
10604
+ buildCE(colIndex) {
10605
+ let tf = this.tf;
10606
+ let host = this.ceElms[colIndex];
10607
+ host.setOptions(this.getOptionEntries(colIndex).filter((entry) => !entry.hidden).map((entry) => ({
10608
+ value: entry.value,
10609
+ text: entry.text,
10610
+ disabled: entry.disabled
10611
+ })));
10612
+ host.setAttribute("filled", "1");
10613
+ this.ceValues[colIndex] = [];
10614
+ this.syncCEText(colIndex);
10615
+ this.emitter.emit("after-populating-filter", tf, colIndex, host);
10616
+ }
10617
+ /**
10618
+ * Render the options into the legacy ul element
10619
+ * @param {Number} colIndex Column index
10620
+ * @private
10621
+ */
10622
+ buildLegacy(colIndex) {
10623
+ let tf = this.tf;
10624
+ let flt = this.containers[colIndex];
10625
+ let ul = createElm("ul", ["id", tf.fltIds[colIndex]], ["colIndex", colIndex]);
10626
+ ul.className = this.filterCssClass;
10627
+ flt.innerHTML = "";
10438
10628
  this.addChecks(colIndex, ul);
10439
10629
  if (tf.loadFltOnDemand) flt.innerHTML = "";
10440
10630
  flt.appendChild(ul);
@@ -10442,60 +10632,59 @@
10442
10632
  this.emitter.emit("after-populating-filter", tf, colIndex, flt);
10443
10633
  }
10444
10634
  /**
10635
+ * Return the checklist entries in render order: the reset option,
10636
+ * the optional empty and non-empty options, then the column values.
10637
+ * A `hidden` entry is rendered with `display: none` by the legacy
10638
+ * path and skipped by `<tf-checklist>`, which has no hidden option
10639
+ * state (checkList.js:321-324, :345-347).
10640
+ * @param {Number} colIndex Column index
10641
+ * @returns {Array} Option entries
10642
+ * @private
10643
+ */
10644
+ getOptionEntries(colIndex) {
10645
+ let tf = this.tf;
10646
+ let entries = [{
10647
+ value: "",
10648
+ text: tf.getClearFilterText(colIndex),
10649
+ hidden: !this.enableResetOption
10650
+ }];
10651
+ if (tf.enableEmptyOption) entries.push({
10652
+ value: tf.emOperator,
10653
+ text: tf.emptyText
10654
+ });
10655
+ if (tf.enableNonEmptyOption) entries.push({
10656
+ value: tf.nmOperator,
10657
+ text: tf.nonEmptyText
10658
+ });
10659
+ this.opts.forEach((val, y) => {
10660
+ entries.push({
10661
+ value: val,
10662
+ text: this.isCustom ? this.optsTxt[y] : val,
10663
+ disabled: tf.linkedFilters && tf.disableExcludedOptions && has(this.excludedOpts, matchCase(val, tf.caseSensitive), tf.caseSensitive),
10664
+ hidden: val === ""
10665
+ });
10666
+ });
10667
+ return entries;
10668
+ }
10669
+ /**
10445
10670
  * Add checklist options
10446
10671
  * @param {Number} colIndex Column index
10447
10672
  * @param {Object} ul Ul element
10448
10673
  * @private
10449
10674
  */
10450
10675
  addChecks(colIndex, ul) {
10451
- let tf = this.tf;
10452
- let chkCt = this.addTChecks(colIndex, ul);
10453
- for (let y = 0; y < this.opts.length; y++) {
10454
- let val = this.opts[y];
10455
- let lbl = this.isCustom ? this.optsTxt[y] : val;
10456
- let fltId = tf.fltIds[colIndex];
10457
- let lblIdx = y + chkCt;
10458
- let li = createCheckItem(`${fltId}_${lblIdx}`, val, lbl, ["data-idx", lblIdx]);
10676
+ let fltId = this.tf.fltIds[colIndex];
10677
+ this.getOptionEntries(colIndex).forEach((entry, idx) => {
10678
+ let li = createCheckItem(`${fltId}_${idx}`, entry.value, entry.text, ["data-idx", idx]);
10459
10679
  li.className = this.itemCssClass;
10460
- if (tf.linkedFilters && tf.disableExcludedOptions && has(this.excludedOpts, matchCase(val, tf.caseSensitive), tf.caseSensitive)) {
10680
+ if (entry.disabled) {
10461
10681
  addClass(li, this.disabledItemCssClass);
10462
10682
  li.check.disabled = true;
10463
10683
  li.disabled = true;
10464
10684
  } else addEvt(li.check, "click", (evt) => this.optionClick(evt));
10465
10685
  ul.appendChild(li);
10466
- if (val === "") li.style.display = NONE;
10467
- }
10468
- }
10469
- /**
10470
- * Add checklist header option
10471
- * @param {Number} colIndex Column index
10472
- * @param {Object} ul Ul element
10473
- * @private
10474
- */
10475
- addTChecks(colIndex, ul) {
10476
- let tf = this.tf;
10477
- let chkCt = 1;
10478
- let fltId = tf.fltIds[colIndex];
10479
- let li0 = createCheckItem(`${fltId}_0`, "", tf.getClearFilterText(colIndex), ["data-idx", 0]);
10480
- li0.className = this.itemCssClass;
10481
- ul.appendChild(li0);
10482
- addEvt(li0.check, "click", (evt) => this.optionClick(evt));
10483
- if (!this.enableResetOption) li0.style.display = NONE;
10484
- if (tf.enableEmptyOption) {
10485
- let li1 = createCheckItem(`${fltId}_1`, tf.emOperator, tf.emptyText, ["data-idx", 1]);
10486
- li1.className = this.itemCssClass;
10487
- ul.appendChild(li1);
10488
- addEvt(li1.check, "click", (evt) => this.optionClick(evt));
10489
- chkCt++;
10490
- }
10491
- if (tf.enableNonEmptyOption) {
10492
- let li2 = createCheckItem(`${fltId}_2`, tf.nmOperator, tf.nonEmptyText, ["data-idx", 2]);
10493
- li2.className = this.itemCssClass;
10494
- ul.appendChild(li2);
10495
- addEvt(li2.check, "click", (evt) => this.optionClick(evt));
10496
- chkCt++;
10497
- }
10498
- return chkCt;
10686
+ if (entry.hidden) li.style.display = NONE;
10687
+ });
10499
10688
  }
10500
10689
  /**
10501
10690
  * Set/unset value of passed item option in filter's DOM element attribute
@@ -10552,6 +10741,10 @@
10552
10741
  * @param {Array} values Array of option values to select
10553
10742
  */
10554
10743
  selectOptions(colIndex, values = []) {
10744
+ if (this.ceElms[colIndex]) {
10745
+ this.selectOptionsCE(colIndex, values);
10746
+ return;
10747
+ }
10555
10748
  let tf = this.tf;
10556
10749
  let flt = tf.getFilterElement(colIndex);
10557
10750
  if (!flt || values.length === 0) return;
@@ -10569,11 +10762,40 @@
10569
10762
  });
10570
10763
  }
10571
10764
  /**
10765
+ * Select options on a <tf-checklist> host. Values are matched against
10766
+ * the rendered entries the way the legacy `selectOptions()` matches
10767
+ * the checkbox values, and the reset value (`''`) clears the
10768
+ * selection instead of being selected (checkList.js:457-477).
10769
+ * @param {Number} colIndex Column index
10770
+ * @param {Array} values Array of option values to select
10771
+ * @private
10772
+ */
10773
+ selectOptionsCE(colIndex, values) {
10774
+ let tf = this.tf;
10775
+ let host = this.ceElms[colIndex];
10776
+ if (!host) return;
10777
+ if (isArray(values) && values.length === 0) return;
10778
+ let requested = (isArray(values) ? values : []).filter((value) => String(value) !== "");
10779
+ let selected = [];
10780
+ this.getOptionEntries(colIndex).filter((entry) => !entry.hidden).forEach((entry) => {
10781
+ let value = matchCase(String(entry.value), tf.caseSensitive);
10782
+ if (has(requested, value, tf.caseSensitive)) selected.push(entry.value);
10783
+ });
10784
+ host.setSelectedValues(selected);
10785
+ this.ceValues[colIndex] = selected;
10786
+ this.syncCEText(colIndex);
10787
+ }
10788
+ /**
10572
10789
  * Get filter values for a given column index
10573
10790
  * @param {Number} colIndex Column index
10574
10791
  * @returns {Array} values Collection of selected values
10575
10792
  */
10576
10793
  getValues(colIndex) {
10794
+ let host = this.ceElms[colIndex];
10795
+ if (host) {
10796
+ let values = host.getSelectedValues();
10797
+ return values.length === 0 ? [""] : values;
10798
+ }
10577
10799
  let tf = this.tf;
10578
10800
  let flt = tf.getFilterElement(colIndex);
10579
10801
  if (!flt) return [];
@@ -10584,13 +10806,33 @@
10584
10806
  return values;
10585
10807
  }
10586
10808
  /**
10809
+ * Remove the <tf-checklist> hosts and the handlers bound to them
10810
+ * @private
10811
+ */
10812
+ destroyCE() {
10813
+ this.ceElms.forEach((host, colIndex) => {
10814
+ if (!host) return;
10815
+ let evt = this.ceEvt[colIndex];
10816
+ if (evt) {
10817
+ removeEvt(host, "selection-change", evt.selectionChange);
10818
+ removeEvt(host, "open-change", evt.openChange);
10819
+ }
10820
+ if (host.parentNode) removeElm(host);
10821
+ });
10822
+ this.ceElms = [];
10823
+ this.ceEvt = [];
10824
+ this.ceValues = [];
10825
+ }
10826
+ /**
10587
10827
  * Destroy CheckList instance
10588
10828
  */
10589
10829
  destroy() {
10590
- this.emitter.off(["build-checklist-filter"], (tf, colIndex, isLinked) => this.build(colIndex, isLinked));
10591
- this.emitter.off(["select-checklist-options"], (tf, colIndex, values) => this.selectOptions(colIndex, values));
10592
- this.emitter.off(["rows-changed"], () => this.refreshAll());
10593
- this.emitter.off(["after-filtering"], () => this.linkFilters());
10830
+ if (!this.initialized) return;
10831
+ this.emitter.off(["build-checklist-filter"], this.onBuildChecklistFilter);
10832
+ this.emitter.off(["select-checklist-options"], this.onSelectChecklistOptions);
10833
+ this.emitter.off(["rows-changed"], this.onRowsChanged);
10834
+ this.emitter.off(["after-filtering"], this.onAfterFiltering);
10835
+ this.destroyCE();
10594
10836
  this.initialized = false;
10595
10837
  }
10596
10838
  };
@@ -15053,6 +15295,12 @@
15053
15295
  * @private
15054
15296
  */
15055
15297
  this.pgAfter = null;
15298
+ /**
15299
+ * <tf-pager> custom element host, when the bridge is active
15300
+ * @type {DOMElement}
15301
+ * @private
15302
+ */
15303
+ this.pagerEl = null;
15056
15304
  let startRow = tf.refRow;
15057
15305
  let nrows = tf.getRowsNb(true);
15058
15306
  this.nbPages = Math.ceil((nrows - startRow) / this.pageLength);
@@ -15093,6 +15341,7 @@
15093
15341
  }
15094
15342
  },
15095
15343
  slcPagesChange: null,
15344
+ pagerPageChange: null,
15096
15345
  nextEvt: null,
15097
15346
  prevEvt: null,
15098
15347
  lastEvt: null,
@@ -15103,9 +15352,7 @@
15103
15352
  * Initialize DOM elements
15104
15353
  */
15105
15354
  init() {
15106
- let slcPages;
15107
15355
  let tf = this.tf;
15108
- let evt = this.evt;
15109
15356
  if (this.initialized) return;
15110
15357
  this.emitter.emit("initializing-feature", this, !isNull(this.tgtId));
15111
15358
  if (this.hasResultsPerPage) {
@@ -15115,6 +15362,60 @@
15115
15362
  this.setResultsPerPage();
15116
15363
  }
15117
15364
  }
15365
+ let targetEl = !this.tgtId ? tf.feature("toolbar").container(this.toolbarPosition) : elm(this.tgtId);
15366
+ if (typeof customElements !== "undefined" && customElements.get("tf-pager") && !tf.enableIcons && !this.hasBtnHtml()) this.initCE(targetEl);
15367
+ else this.initLegacy(targetEl);
15368
+ this.setPagingInfo();
15369
+ if (!tf.fltGrid) {
15370
+ tf.validateAllRows();
15371
+ this.setPagingInfo(tf.validRowsIndex);
15372
+ }
15373
+ this.emitter.on(["after-filtering"], bound(this.resetPagingInfo, this));
15374
+ this.emitter.on(["change-page"], bound(this.changePageHandler, this));
15375
+ this.emitter.on(["change-page-results"], bound(this.changePageResultsHandler, this));
15376
+ /** @inherited */
15377
+ this.initialized = true;
15378
+ this.emitter.emit("feature-initialized", this);
15379
+ }
15380
+ /**
15381
+ * Initialize using the <tf-pager> custom element
15382
+ * @param {DOMElement} targetEl Target container element
15383
+ * @private
15384
+ */
15385
+ initCE(targetEl) {
15386
+ let evt = this.evt;
15387
+ let tf = this.tf;
15388
+ let pagerEl = document.createElement("tf-pager");
15389
+ pagerEl.className = this.pgCssClass();
15390
+ pagerEl.setAttribute("selector-type", this.pageSelectorType);
15391
+ pagerEl.setAttribute("page-text", this.pageText);
15392
+ pagerEl.setAttribute("of-text", this.ofText);
15393
+ if (!this.hasBtns) pagerEl.setAttribute("buttons", "false");
15394
+ this.setPagerButtons(pagerEl);
15395
+ if (!this.isEnabled()) pagerEl.setAttribute("disabled", "");
15396
+ targetEl.appendChild(pagerEl);
15397
+ this.pagerEl = pagerEl;
15398
+ this.pageSlc = pagerEl.shadowRoot.querySelector(this.pageSelectorType === "input" ? "[part=\"page-input\"]" : "[part=\"page-select\"]");
15399
+ this.bindPagerButton("first", evt.first);
15400
+ this.bindPagerButton("prev", evt.prev);
15401
+ this.bindPagerButton("next", evt.next);
15402
+ this.bindPagerButton("last", evt.last);
15403
+ evt.pagerPageChange = (event) => {
15404
+ let page = parseInt(event.detail.page, 10);
15405
+ if (isNaN(page)) return;
15406
+ if (this.pageSelectorType === "input" && tf.sorted) tf.filter();
15407
+ this.changePage(page - 1);
15408
+ };
15409
+ addEvt(pagerEl, "page-change", evt.pagerPageChange);
15410
+ }
15411
+ /**
15412
+ * Initialize using the legacy spans, controls and select
15413
+ * @param {DOMElement} targetEl Target container element
15414
+ * @private
15415
+ */
15416
+ initLegacy(targetEl) {
15417
+ let slcPages;
15418
+ let evt = this.evt;
15118
15419
  evt.slcPagesChange = (event) => {
15119
15420
  let slc = event.target;
15120
15421
  this.changePage(slc.selectedIndex);
@@ -15171,7 +15472,6 @@
15171
15472
  addEvt(btnFirstSpan, "click", evt.first);
15172
15473
  }
15173
15474
  }
15174
- let targetEl = !this.tgtId ? tf.feature("toolbar").container(this.toolbarPosition) : elm(this.tgtId);
15175
15475
  targetEl.appendChild(btnFirstSpan);
15176
15476
  targetEl.appendChild(btnPrevSpan);
15177
15477
  let pgBeforeSpan = createElm("span");
@@ -15197,17 +15497,87 @@
15197
15497
  this.pgBefore = pgBeforeSpan;
15198
15498
  this.pgAfter = pgAfterSpan;
15199
15499
  this.pageSlc = slcPages;
15200
- this.setPagingInfo();
15201
- if (!tf.fltGrid) {
15202
- tf.validateAllRows();
15203
- this.setPagingInfo(tf.validRowsIndex);
15204
- }
15205
- this.emitter.on(["after-filtering"], bound(this.resetPagingInfo, this));
15206
- this.emitter.on(["change-page"], bound(this.changePageHandler, this));
15207
- this.emitter.on(["change-page-results"], bound(this.changePageResultsHandler, this));
15208
- /** @inherited */
15209
- this.initialized = true;
15210
- this.emitter.emit("feature-initialized", this);
15500
+ }
15501
+ /**
15502
+ * The legacy paging classes, applied to the <tf-pager> host
15503
+ * @return {String} Space-separated class list
15504
+ * @private
15505
+ */
15506
+ pgCssClass() {
15507
+ return [
15508
+ this.btnCssClass,
15509
+ this.pgSlcCssClass,
15510
+ this.pgInpCssClass,
15511
+ this.nbPgSpanCssClass
15512
+ ].join(" ");
15513
+ }
15514
+ /**
15515
+ * Whether a `btn_*_page_html` value is set
15516
+ * @return {Boolean} True when any button HTML is configured
15517
+ * @private
15518
+ */
15519
+ hasBtnHtml() {
15520
+ return Boolean(this.btnFirstPageHtml || this.btnPrevPageHtml || this.btnNextPageHtml || this.btnLastPageHtml);
15521
+ }
15522
+ /**
15523
+ * Set the `btn_*_page_text` captions on the <tf-pager> buttons
15524
+ * (paging.js:390-444).
15525
+ * @param {DOMElement} pagerEl <tf-pager> host
15526
+ * @private
15527
+ */
15528
+ setPagerButtons(pagerEl) {
15529
+ [
15530
+ {
15531
+ part: "first",
15532
+ text: this.btnFirstPageText
15533
+ },
15534
+ {
15535
+ part: "prev",
15536
+ text: this.btnPrevPageText
15537
+ },
15538
+ {
15539
+ part: "next",
15540
+ text: this.btnNextPageText
15541
+ },
15542
+ {
15543
+ part: "last",
15544
+ text: this.btnLastPageText
15545
+ }
15546
+ ].forEach((btn) => {
15547
+ pagerEl.setAttribute(`${btn.part}-text`, btn.text);
15548
+ });
15549
+ }
15550
+ /**
15551
+ * Bind a paging handler to a <tf-pager> button
15552
+ * @param {String} part Button part name
15553
+ * @param {Function} handler Paging handler
15554
+ * @private
15555
+ */
15556
+ bindPagerButton(part, handler) {
15557
+ addEvt(this.pagerEl.shadowRoot.querySelector(`[part="${part}"]`), "click", handler);
15558
+ }
15559
+ /**
15560
+ * Remove a paging handler from a <tf-pager> button
15561
+ * @param {String} part Button part name
15562
+ * @param {Function} handler Paging handler
15563
+ * @private
15564
+ */
15565
+ unbindPagerButton(part, handler) {
15566
+ removeEvt(this.pagerEl.shadowRoot.querySelector(`[part="${part}"]`), "click", handler);
15567
+ }
15568
+ /**
15569
+ * Paging entries shared by the legacy select and <tf-pager>: page
15570
+ * number as visible text, start row as value
15571
+ * @return {Array<Object>} Page entries
15572
+ * @private
15573
+ */
15574
+ pageEntries() {
15575
+ let entries = [];
15576
+ for (let z = 0; z < this.nbPages; z++) entries.push({
15577
+ text: String(z + 1),
15578
+ value: String(z * this.pageLength)
15579
+ });
15580
+ return entries;
15211
15581
  }
15212
15582
  /**
15213
15583
  * Reset paging when filters are already instantiated
@@ -15236,15 +15606,22 @@
15236
15606
  let cont = !this.tgtId ? tf.feature("toolbar").container(this.toolbarPosition) : elm(this.tgtId);
15237
15607
  tf.validRowsIndex = validRows || tf.getValidRows(true);
15238
15608
  this.nbPages = Math.ceil(tf.validRowsIndex.length / this.pageLength);
15239
- this.pgCont.innerHTML = this.nbPages;
15240
- if (this.pageSelectorType === "select") this.pageSlc.innerHTML = "";
15609
+ if (this.pagerEl) {
15610
+ this.pagerEl.setTotalPages(this.nbPages);
15611
+ this.pagerEl.setPages(this.pageEntries());
15612
+ this.pagerEl.setPage(this.currentPageNb);
15613
+ } else {
15614
+ this.pgCont.innerHTML = this.nbPages;
15615
+ if (this.pageSelectorType === "select") this.pageSlc.innerHTML = "";
15616
+ }
15241
15617
  if (this.nbPages > 0) {
15242
15618
  cont.style.visibility = "visible";
15243
- if (this.pageSelectorType === "select") for (let z = 0; z < this.nbPages; z++) {
15244
- let opt = createOpt(z + 1, z * this.pageLength, false);
15245
- this.pageSlc.options[z] = opt;
15619
+ if (!this.pagerEl) {
15620
+ if (this.pageSelectorType === "select") this.pageEntries().forEach((entry, z) => {
15621
+ this.pageSlc.options[z] = createOpt(entry.text, entry.value, false);
15622
+ });
15623
+ else this.pageSlc.value = this.currentPageNb;
15246
15624
  }
15247
- else this.pageSlc.value = this.currentPageNb;
15248
15625
  } else
15249
15626
  /*** if no results paging select and buttons are hidden ***/
15250
15627
  cont.style.visibility = "hidden";
@@ -15363,7 +15740,8 @@
15363
15740
  if (index >= 0 && index <= this.nbPages - 1) {
15364
15741
  this.onBeforeChangePage(this, index + 1);
15365
15742
  this.currentPageNb = parseInt(index, 10) + 1;
15366
- if (this.pageSelectorType === "select") this.pageSlc.options[index].selected = true;
15743
+ if (this.pagerEl) this.pagerEl.setPage(this.currentPageNb);
15744
+ else if (this.pageSelectorType === "select") this.pageSlc.options[index].selected = true;
15367
15745
  else this.pageSlc.value = this.currentPageNb;
15368
15746
  this.startPagingRow = this.pageSelectorType === "select" ? this.pageSlc.value : index * this.pageLength;
15369
15747
  this.groupByPage();
@@ -15395,7 +15773,8 @@
15395
15773
  if (!isNaN(this.pageLength)) {
15396
15774
  if (this.startPagingRow >= tf.nbFilterableRows) this.startPagingRow = tf.nbFilterableRows - this.pageLength;
15397
15775
  this.setPagingInfo();
15398
- if (pageSelectorType === "select") {
15776
+ if (this.pagerEl) this.pagerEl.setPage(Math.min(slcPagesSelIndex, this.nbPages - 1) + 1);
15777
+ else if (pageSelectorType === "select") {
15399
15778
  let slcIdx = pageSlc.options.length - 1 <= slcPagesSelIndex ? pageSlc.options.length - 1 : slcPagesSelIndex;
15400
15779
  pageSlc.options[slcIdx].selected = true;
15401
15780
  }
@@ -15436,10 +15815,53 @@
15436
15815
  this.changeResultsPerPage(pageLength);
15437
15816
  }
15438
15817
  /**
15818
+ * Disable paging and reflect the state on the pager element
15819
+ */
15820
+ disable() {
15821
+ super.disable();
15822
+ if (this.pagerEl) this.pagerEl.setAttribute("disabled", "");
15823
+ }
15824
+ /**
15825
+ * Enable paging and reflect the state on the pager element
15826
+ */
15827
+ enable() {
15828
+ super.enable();
15829
+ if (this.pagerEl) this.pagerEl.removeAttribute("disabled");
15830
+ }
15831
+ /**
15439
15832
  * Remove paging feature
15440
15833
  */
15441
15834
  destroy() {
15442
15835
  if (!this.initialized) return;
15836
+ if (this.pagerEl) this.destroyCE();
15837
+ else this.destroyLegacy();
15838
+ if (this.hasResultsPerPage) this.removeResultsPerPage();
15839
+ this.emitter.off(["after-filtering"], bound(this.resetPagingInfo, this));
15840
+ this.emitter.off(["change-page"], bound(this.changePageHandler, this));
15841
+ this.emitter.off(["change-page-results"], bound(this.changePageResultsHandler, this));
15842
+ this.pageSlc = null;
15843
+ this.nbPages = 0;
15844
+ this.initialized = false;
15845
+ }
15846
+ /**
15847
+ * Remove the <tf-pager> element and the handlers bound to it
15848
+ * @private
15849
+ */
15850
+ destroyCE() {
15851
+ let evt = this.evt;
15852
+ removeEvt(this.pagerEl, "page-change", evt.pagerPageChange);
15853
+ this.unbindPagerButton("first", evt.first);
15854
+ this.unbindPagerButton("prev", evt.prev);
15855
+ this.unbindPagerButton("next", evt.next);
15856
+ this.unbindPagerButton("last", evt.last);
15857
+ removeElm(this.pagerEl);
15858
+ this.pagerEl = null;
15859
+ }
15860
+ /**
15861
+ * Remove the legacy paging controls and the handlers bound to them
15862
+ * @private
15863
+ */
15864
+ destroyLegacy() {
15443
15865
  let evt = this.evt;
15444
15866
  if (this.pageSlc) {
15445
15867
  if (this.pageSelectorType === "select") removeEvt(this.pageSlc, "change", evt.slcPagesChange);
@@ -15478,13 +15900,6 @@
15478
15900
  removeElm(this.pgCont);
15479
15901
  this.pgCont = null;
15480
15902
  }
15481
- if (this.hasResultsPerPage) this.removeResultsPerPage();
15482
- this.emitter.off(["after-filtering"], bound(this.resetPagingInfo, this));
15483
- this.emitter.off(["change-page"], bound(this.changePageHandler, this));
15484
- this.emitter.off(["change-page-results"], bound(this.changePageResultsHandler, this));
15485
- this.pageSlc = null;
15486
- this.nbPages = 0;
15487
- this.initialized = false;
15488
15903
  }
15489
15904
  };
15490
15905
  //#endregion
@@ -15547,7 +15962,7 @@
15547
15962
  * Current version
15548
15963
  * @type {String}
15549
15964
  */
15550
- this.version = "0.7.6";
15965
+ this.version = "0.7.8";
15551
15966
  /**
15552
15967
  * Current year
15553
15968
  * @type {Number}