jquery.dgtable 0.5.48 → 0.5.52

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jquery.dgtable",
3
3
  "description": "High-performance table View for jQuery",
4
- "version": "0.5.48",
4
+ "version": "0.5.52",
5
5
  "main": "dist/jquery.dgtable.cjs.min.js",
6
6
  "module": "dist/jquery.dgtable.es6.min.js",
7
7
  "broswer": "dist/jquery.dgtable.umd.min.js",
@@ -34,21 +34,22 @@
34
34
  }
35
35
  ],
36
36
  "dependencies": {
37
- "@danielgindi/dom-utils": "^1.0.3"
37
+ "@danielgindi/dom-utils": "^1.0.5"
38
38
  },
39
39
  "devDependencies": {
40
- "@babel/core": "^7.15.0",
41
- "@babel/preset-env": "^7.15.0",
42
- "@babel/runtime": "^7.15.3",
40
+ "@babel/core": "^7.16.7",
41
+ "@babel/preset-env": "^7.16.7",
42
+ "@babel/runtime": "^7.16.7",
43
43
  "@rollup/plugin-babel": "^5.3.0",
44
- "@rollup/plugin-commonjs": "^20.0.0",
45
- "@rollup/plugin-node-resolve": "^13.0.4",
46
- "core-js": "^3.16.1",
47
- "eslint": "^7.32.0",
44
+ "@rollup/plugin-commonjs": "^21.0.1",
45
+ "@rollup/plugin-node-resolve": "^13.1.3",
46
+ "core-js": "^3.20.2",
47
+ "eslint": "^8.6.0",
48
+ "eslint-formatter-codeframe": "^7.32.1",
48
49
  "fs-extra": "^10.0.0",
49
- "husky": "^7.0.1",
50
+ "husky": "^7.0.4",
50
51
  "pinst": "^2.1.6",
51
- "rollup": "^2.56.2",
52
+ "rollup": "^2.63.0",
52
53
  "rollup-plugin-terser": "^7.0.2"
53
54
  }
54
55
  }
package/src/index.js CHANGED
@@ -28,6 +28,8 @@ let hasIeDragAndDropBug = ieVersion && ieVersion < 10;
28
28
  let createElement = document.createElement.bind(document);
29
29
  const hasOwnProperty = Object.prototype.hasOwnProperty;
30
30
 
31
+ const IsSafeSymbol = ('safe');
32
+
31
33
  function webkitRenderBugfix(el) {
32
34
  // BUGFIX: WebKit has a bug where it does not relayout, and this affects us because scrollbars
33
35
  // are still calculated even though they are not there yet. This is the last resort.
@@ -221,7 +223,7 @@ DGTable.prototype.initialize = function (options) {
221
223
 
222
224
  /**
223
225
  * @private
224
- * @field {Function(String,Boolean)Function(a,b)Boolean} onComparatorRequired */
226
+ * @field {function(columnName: string, descending: boolean, defaultComparator: function(a,b):number):(function(a,b):number)} onComparatorRequired */
225
227
  o.onComparatorRequired = options.onComparatorRequired === undefined ? null : options.onComparatorRequired;
226
228
  if (!o.onComparatorRequired && typeof options['comparatorCallback'] === 'function') {
227
229
  o.onComparatorRequired = options['comparatorCallback'];
@@ -286,9 +288,9 @@ DGTable.prototype.initialize = function (options) {
286
288
 
287
289
  /** @field {RowCollection} _rows */
288
290
  p.rows = new RowCollection({ sortColumn: sortColumns });
289
- p.rows.onComparatorRequired = function(column, descending){
291
+ p.rows.onComparatorRequired = (column, descending, defaultComparator) => {
290
292
  if (o.onComparatorRequired) {
291
- return o.onComparatorRequired(column, descending);
293
+ return o.onComparatorRequired(column, descending, defaultComparator);
292
294
  }
293
295
  };
294
296
 
@@ -1116,12 +1118,15 @@ DGTable.prototype.removeColumn = function (column, render) {
1116
1118
  * @returns {DGTable} self
1117
1119
  */
1118
1120
  DGTable.prototype.setCellFormatter = function (formatter) {
1121
+ if (!formatter) {
1122
+ formatter = val => (typeof val === 'string') ? htmlEncode(val) : val;
1123
+ formatter[IsSafeSymbol] = true;
1124
+ }
1125
+
1119
1126
  /**
1120
1127
  * @private
1121
1128
  * @field {Function} cellFormatter */
1122
- this.o.cellFormatter = formatter || function (val) {
1123
- return (typeof val === 'string') ? htmlEncode(val) : val;
1124
- };
1129
+ this.o.cellFormatter = formatter;
1125
1130
 
1126
1131
  return this;
1127
1132
  };
@@ -1636,7 +1641,7 @@ DGTable.prototype.getResizableColumns = function () {
1636
1641
  /**
1637
1642
  * @public
1638
1643
  * @expose
1639
- * @param {{function(string,boolean):{function(a:*,b:*):boolean}}} comparatorCallback a callback function that returns the comparator for a specific column
1644
+ * @param {{function(columnName: string, descending: boolean, defaultComparator: function(a,b):number):{function(a,b):number}}} comparatorCallback a callback function that returns the comparator for a specific column
1640
1645
  * @returns {DGTable} self
1641
1646
  */
1642
1647
  DGTable.prototype.setComparatorCallback = function (comparatorCallback) {
@@ -1801,7 +1806,21 @@ DGTable.prototype._getHtmlForCell = function (rowData, column) {
1801
1806
  colValue = colValue && colValue[dataPath[dataPathIndex]];
1802
1807
  }
1803
1808
 
1804
- let content = this.o.cellFormatter(colValue, column.name, rowData);
1809
+ const formatter = this.o.cellFormatter;
1810
+ let content;
1811
+
1812
+ if (formatter[IsSafeSymbol]) {
1813
+ content = formatter(colValue, column.name, rowData);
1814
+ } else {
1815
+ try {
1816
+ content = formatter(colValue, column.name, rowData);
1817
+ } catch (err) {
1818
+ content = '[ERROR]';
1819
+ // eslint-disable-next-line no-console
1820
+ console.error('Failed to generate content for cell ' + column.name, err);
1821
+ }
1822
+ }
1823
+
1805
1824
  if (content === undefined || content === null) {
1806
1825
  content = '';
1807
1826
  }
@@ -3981,25 +4000,10 @@ DGTable.prototype._cellMouseOverEvent = function(el) {
3981
4000
  p._bindCellHoverOut(el);
3982
4001
  p._bindCellHoverOut(previewCell);
3983
4002
 
3984
- $previewCell.on('mousewheel', (event) => {
3985
- let originalEvent = event.originalEvent;
3986
- let xy = originalEvent.wheelDelta || -originalEvent.detail,
3987
- x = originalEvent.wheelDeltaX || (originalEvent.axis === 1 ? xy : 0),
3988
- y = originalEvent.wheelDeltaY || (originalEvent.axis === 2 ? xy : 0);
3989
-
3990
- if (xy) {
3991
- this.hideCellPreview();
3992
- }
3993
-
3994
- if (y && p.table.scrollHeight > p.table.clientHeight) {
3995
- let scrollTop = (y * -1) + p.$table.scrollTop();
3996
- p.$table.scrollTop(scrollTop);
3997
- }
3998
-
3999
- if (x && p.table.scrollWidth > p.table.clientWidth) {
4000
- let scrollLeft = (x * -1) + p.$table.scrollLeft();
4001
- p.$table.scrollLeft(scrollLeft);
4002
- }
4003
+ // Avoid interfering with wheel scrolling the table
4004
+ $previewCell.on('wheel', () => {
4005
+ // Let the table naturally scroll with the wheel
4006
+ this.hideCellPreview();
4003
4007
  });
4004
4008
  }
4005
4009
  };
@@ -70,7 +70,7 @@ RowCollection.prototype.reset = function (rows) {
70
70
  RowCollection.prototype.filteredCollection = function (filterFunc, args) {
71
71
  if (filterFunc && args) {
72
72
  let rows = new RowCollection({ sortColumn: this.sortColumn });
73
-
73
+
74
74
  for (let i = 0, len = this.length, row; i < len; i++) {
75
75
  row = this[i];
76
76
  if (filterFunc(row, args)) {
@@ -85,7 +85,7 @@ RowCollection.prototype.filteredCollection = function (filterFunc, args) {
85
85
  };
86
86
 
87
87
  /**
88
- * @type {Function|null|undefined}
88
+ * @type {function(columnName: string, descending: boolean, defaultComparator: function(a,b):number)|null|undefined}
89
89
  */
90
90
  RowCollection.prototype.onComparatorRequired = null;
91
91
 
@@ -134,11 +134,12 @@ RowCollection.prototype.sort = function (silent) {
134
134
 
135
135
  for (i = 0; i < this.sortColumn.length; i++) {
136
136
  comparator = null;
137
+ const defaultComparator = getDefaultComparator(this.sortColumn[i], this.sortColumn[i].descending);
137
138
  if (this.onComparatorRequired) {
138
- comparator = this.onComparatorRequired(this.sortColumn[i].column, this.sortColumn[i].descending);
139
+ comparator = this.onComparatorRequired(this.sortColumn[i].column, this.sortColumn[i].descending, defaultComparator);
139
140
  }
140
141
  if (!comparator) {
141
- comparator = getDefaultComparator(this.sortColumn[i], this.sortColumn[i].descending);
142
+ comparator = defaultComparator;
142
143
  }
143
144
  comparators.push(comparator.bind(this));
144
145
  }
@@ -171,4 +172,4 @@ RowCollection.prototype.sort = function (silent) {
171
172
  return this;
172
173
  };
173
174
 
174
- export default RowCollection;
175
+ export default RowCollection;