melondtable 1.18.4 → 1.19.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.
package/LICENSE CHANGED
@@ -0,0 +1 @@
1
+ MIT
@@ -2000,7 +2000,9 @@ class DataManager {
2000
2000
  focusable: false,
2001
2001
  dropdown: false
2002
2002
  };
2003
-
2003
+ if (this.options.data.length > 1000) {
2004
+ cell.resizable = true;
2005
+ }
2004
2006
  this.columns.push(cell);
2005
2007
  }
2006
2008
  }
@@ -2884,7 +2886,6 @@ class CellManager {
2884
2886
 
2885
2887
  _selectArea($cell1, $cell2) {
2886
2888
  if ($cell1 === $cell2) return false;
2887
-
2888
2889
  const cells = this.getCellsInRange($cell1, $cell2);
2889
2890
  if (!cells) return false;
2890
2891
 
@@ -2911,9 +2912,17 @@ class CellManager {
2911
2912
  const cell2 = $.data($cell2);
2912
2913
 
2913
2914
  colIndex1 = +cell1.colIndex;
2914
- rowIndex1 = +cell1.rowIndex;
2915
2915
  colIndex2 = +cell2.colIndex;
2916
- rowIndex2 = +cell2.rowIndex;
2916
+
2917
+ if (this.columnmanager.sortState) {
2918
+ this.sortedColumn = true;
2919
+ rowIndex1 = this.datamanager.rowViewOrder.indexOf(parseInt(cell1.rowIndex, 10));
2920
+ rowIndex2 = this.datamanager.rowViewOrder.indexOf(parseInt(cell2.rowIndex, 10));
2921
+ } else {
2922
+ rowIndex1 = +cell1.rowIndex;
2923
+ rowIndex2 = +cell2.rowIndex;
2924
+ }
2925
+
2917
2926
  }
2918
2927
 
2919
2928
  if (rowIndex1 > rowIndex2) {
@@ -2945,7 +2954,11 @@ class CellManager {
2945
2954
  }
2946
2955
  colIndex = colIndex1;
2947
2956
  });
2948
-
2957
+ if (this.columnmanager.sortState) {
2958
+ cells.forEach(selectedCells => {
2959
+ selectedCells[1] = this.datamanager.rowViewOrder[selectedCells[1]];
2960
+ });
2961
+ }
2949
2962
  return cells;
2950
2963
  }
2951
2964
 
@@ -3735,9 +3748,29 @@ class ColumnManager {
3735
3748
  .then(() => this.instance.unfreeze())
3736
3749
  .then(() => {
3737
3750
  this.fireEvent('onSortColumn', this.getColumn(colIndex));
3751
+ this.setSortState();
3738
3752
  });
3739
3753
  }
3740
3754
 
3755
+ saveSorting(colIndex) {
3756
+ let currentColumn = this.getColumn(colIndex);
3757
+ let saveSorting = {
3758
+ [currentColumn.name]: {
3759
+ colIndex: colIndex,
3760
+ sortOrder: currentColumn.sortOrder
3761
+ }
3762
+ };
3763
+ this.sortingKey = this.options.sortingKey ? `${this.options.sortingKey}::sortedColumns` : 'sortedColumns' ;
3764
+ localStorage.setItem(this.sortingKey, JSON.stringify(saveSorting));
3765
+ }
3766
+ setSortState(sortOrder) {
3767
+ if (sortOrder === 'none') {
3768
+ this.sortState = false;
3769
+ } else {
3770
+ this.sortState = true;
3771
+ }
3772
+ }
3773
+
3741
3774
  removeColumn(colIndex) {
3742
3775
  const removedCol = this.getColumn(colIndex);
3743
3776
  this.instance.freeze();
@@ -3836,6 +3869,19 @@ class ColumnManager {
3836
3869
  }
3837
3870
  }
3838
3871
 
3872
+ applySavedSortOrder() {
3873
+
3874
+ let key = this.options.sortingKey ? `${this.options.sortingKey}::sortedColumns` : 'sortedColumns' ;
3875
+ let sortingConfig = JSON.parse(localStorage.getItem(key));
3876
+ if (sortingConfig) {
3877
+ const columnsToSort = Object.values(sortingConfig);
3878
+ for (let column of columnsToSort) {
3879
+ this.sortColumn(column.colIndex, column.sortOrder);
3880
+ this.sortState = true;
3881
+ }
3882
+ }
3883
+ }
3884
+
3839
3885
  sortRows(colIndex, sortOrder) {
3840
3886
  return this.datamanager.sortRows(colIndex, sortOrder);
3841
3887
  }
@@ -3911,14 +3957,22 @@ class ColumnManager {
3911
3957
 
3912
3958
  getDropdownListHTML() {
3913
3959
  const { headerDropdown: dropdownItems } = this.options;
3914
-
3915
3960
  return `
3916
- <div class="dt-dropdown__list">
3917
- ${dropdownItems.map((d, i) => `
3918
- <div class="dt-dropdown__list-item" data-index="${i}">${d.label}</div>
3919
- `).join('')}
3961
+ <div class="dt-dropdown__list">
3962
+ ${dropdownItems.map((d, i) => `
3963
+ <div
3964
+ class="dt-dropdown__list-item${d.display ? ' dt-hidden' : ''}"
3965
+ data-index="${i}"
3966
+ >
3967
+ ${d.label}
3920
3968
  </div>
3921
- `;
3969
+ `).join('')}
3970
+ </div>
3971
+ `;
3972
+ }
3973
+
3974
+ toggleDropdownItem(index) {
3975
+ $('.dt-dropdown__list', this.instance.dropdownContainer).children[index].classList.toggle('dt-hidden');
3922
3976
  }
3923
3977
  }
3924
3978
 
@@ -4868,9 +4922,7 @@ class BodyRenderer {
4868
4922
  const style = window.getComputedStyle(this.instance.header);
4869
4923
  const matrix = new DOMMatrixReadOnly(style.transform);
4870
4924
  const width = (-matrix.m41) + this.instance.header.clientWidth;
4871
- console.log(width);
4872
4925
  const height = this.bodyScrollable.clientHeight;
4873
- console.log(width);
4874
4926
  return `
4875
4927
  <div
4876
4928
  class="dt-scrollable__no-data"
@@ -5703,6 +5755,10 @@ class DataTable {
5703
5755
  if (this.options.data) {
5704
5756
  this.refresh();
5705
5757
  this.columnmanager.applyDefaultSortOrder();
5758
+ if (this.options.saveSorting) {
5759
+ this.setupSaveSorting();
5760
+ this.columnmanager.applySavedSortOrder();
5761
+ }
5706
5762
  }
5707
5763
  }
5708
5764
 
@@ -5872,6 +5928,9 @@ class DataTable {
5872
5928
  sortColumn(colIndex, sortOrder) {
5873
5929
  this.columnmanager.sortColumn(colIndex, sortOrder);
5874
5930
  }
5931
+ saveSorting(colIndex, nextSortOrder) {
5932
+ this.columnmanager.saveSorting(colIndex, nextSortOrder);
5933
+ }
5875
5934
 
5876
5935
  removeColumn(colIndex) {
5877
5936
  this.columnmanager.removeColumn(colIndex);
@@ -5925,6 +5984,25 @@ class DataTable {
5925
5984
  translate(str, args) {
5926
5985
  return this.translationManager.translate(str, args);
5927
5986
  }
5987
+ setupSaveSorting() {
5988
+ // add options in default headerdropdown
5989
+ let action = {
5990
+ label: this.translate('Save Sorting'),
5991
+ action: function (column) {
5992
+ this.saveSorting(column.colIndex, column.sotOrder);
5993
+ },
5994
+ display: 'hidden'
5995
+ };
5996
+ this.options.headerDropdown.push(action);
5997
+ this.columnmanager.bindDropdown();
5998
+ // add events for onSortColumn
5999
+ this.on('onSortColumn', function (column) {
6000
+ this.columnmanager.toggleDropdownItem(4);
6001
+ if (column.sortOrder === 'none') {
6002
+ localStorage.removeItem(this.columnmanager.sortingKey);
6003
+ }
6004
+ });
6005
+ }
5928
6006
  }
5929
6007
 
5930
6008
  DataTable.instances = 0;
@@ -335,6 +335,10 @@
335
335
  left: -999em;
336
336
  }
337
337
 
338
+ .dt-hidden{
339
+ display: none;
340
+ }
341
+
338
342
  body.dt-resize {
339
343
  cursor: col-resize;
340
344
  }