jquery.dgtable 0.5.52 → 0.5.55

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/README.md CHANGED
@@ -129,6 +129,12 @@ To create a new table, just use `var myTable = new DGTable(INIT_OPTIONS)`.
129
129
  * 2nd argument: Row's index in the data set
130
130
  * 3nd argument: Row's DOM element
131
131
  * 4th argument: Row's data
132
+ * `rowclick`: A row has just been created
133
+ * 1st argument: Native `MouseEvent`
134
+ * 2nd argument: Row's index in the currently filtered data set
135
+ * 3rd argument: Row's index in the data set
136
+ * 4th argument: Row's DOM element
137
+ * 5th argument: Row's data
132
138
  * `rowdestroy`: Called just before removing a physical row element from the table
133
139
  * 1st argument: Row's DOM element
134
140
  * `addrows`: Data rows have been added to the table
@@ -154,8 +160,9 @@ To create a new table, just use `var myTable = new DGTable(INIT_OPTIONS)`.
154
160
  * 1st argument: The options passed to the filter method
155
161
  * `filterclear`: A filter was cleared
156
162
  * `sort`: The data was sorted
157
- * 1st argument: Array of sort constructs `[{ "column": "column's name", "descending": true/false }, ...]`
158
- * 2nd argument: Boolean that determines whether this is a direct sort or indirect (sort() vs resort(), addRows(), etc.). If `false`, this is an indirect sort.
163
+ * 1st argument: `Array` of sort constructs `[{ "column": "column's name", "descending": true/false }, ...]`
164
+ * 2nd argument: `Boolean` that determines whether this is a primary sort or a resort (sort()/header click, vs resort(), addRows(), etc.). If `true`, this is a resort.
165
+ * 3rd argument: `Function` - the comparator that was used to sort.
159
166
  * `headercontextmenu`: A context menu should be shown for a header cell
160
167
  * 1st argument: The column's name
161
168
  * 2nd argument: pageX of the pointer event
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * jquery.dgtable 0.5.52
2
+ * jquery.dgtable 0.5.55
3
3
  * git://github.com/danielgindi/jquery.dgtable.git
4
4
  */
5
5
  'use strict';
@@ -1348,13 +1348,15 @@ function getDefaultComparator(column, descending) {
1348
1348
 
1349
1349
  /**
1350
1350
  * @param {Boolean=false} silent
1351
- * @returns {RowCollection} self
1351
+ * @returns {Function|undefined} the comparator that was used
1352
1352
  */
1353
1353
  RowCollection.prototype.sort = function (silent) {
1354
+ let comparator;
1355
+
1354
1356
  if (this.sortColumn.length) {
1355
- let comparators = [],i,comparator;
1357
+ let comparators = [];
1356
1358
 
1357
- for (i = 0; i < this.sortColumn.length; i++) {
1359
+ for (let i = 0; i < this.sortColumn.length; i++) {
1358
1360
  comparator = null;
1359
1361
  const defaultComparator = getDefaultComparator(this.sortColumn[i], this.sortColumn[i].descending);
1360
1362
  if (this.onComparatorRequired) {
@@ -1367,13 +1369,14 @@ RowCollection.prototype.sort = function (silent) {
1367
1369
  }
1368
1370
 
1369
1371
  if (comparators.length === 1) {
1370
- nativeSort.call(this, comparators[0]);
1372
+ comparator = comparators[0];
1373
+ nativeSort.call(this, comparator);
1371
1374
  } else {
1372
1375
  let len = comparators.length,
1373
1376
  value;
1374
1377
 
1375
1378
  comparator = function (leftRow, rightRow) {
1376
- for (i = 0; i < len; i++) {
1379
+ for (let i = 0; i < len; i++) {
1377
1380
  value = comparators[i](leftRow, rightRow);
1378
1381
  if (value !== 0) {
1379
1382
  return value;
@@ -1387,11 +1390,12 @@ RowCollection.prototype.sort = function (silent) {
1387
1390
 
1388
1391
  if (!silent) {
1389
1392
  if (this.onSort) {
1390
- this.onSort();
1393
+ this.onSort(comparator);
1391
1394
  }
1392
1395
  }
1393
1396
  }
1394
- return this;
1397
+
1398
+ return comparator;
1395
1399
  };
1396
1400
 
1397
1401
  function ColumnCollection() {
@@ -2475,6 +2479,7 @@ DGTable.prototype.renderRows = function (first, last) {
2475
2479
 
2476
2480
  let tableClassName = o.tableClassName,
2477
2481
  rowClassName = tableClassName + '-row',
2482
+ altRowClassName = tableClassName + '-row-alt',
2478
2483
  cellClassName = tableClassName + '-cell',
2479
2484
  rows = p.filteredRows || p.rows,
2480
2485
  isDataFiltered = !!p.filteredRows,
@@ -2483,8 +2488,7 @@ DGTable.prototype.renderRows = function (first, last) {
2483
2488
  isVirtual = o.virtualTable,
2484
2489
  virtualRowHeightFirst = p.virtualRowHeightFirst,
2485
2490
  virtualRowHeight = p.virtualRowHeight,
2486
- top,
2487
- physicalRowIndex;
2491
+ top;
2488
2492
 
2489
2493
  let colCount = visibleColumns.length;
2490
2494
  for (let colIndex = 0, column; colIndex < colCount; colIndex++) {
@@ -2504,10 +2508,13 @@ DGTable.prototype.renderRows = function (first, last) {
2504
2508
  i++) {
2505
2509
 
2506
2510
  let rowData = rows[i];
2507
- physicalRowIndex = isDataFiltered ? rowData['__i'] : i;
2511
+ let physicalRowIndex = isDataFiltered ? rowData['__i'] : i;
2508
2512
 
2509
2513
  let row = createElement('div');
2510
2514
  row.className = rowClassName;
2515
+ if (i % 2 === 1)
2516
+ row.className += ' ' + altRowClassName;
2517
+
2511
2518
  row['rowIndex'] = i;
2512
2519
  row['physicalRowIndex'] = physicalRowIndex;
2513
2520
 
@@ -2545,6 +2552,11 @@ DGTable.prototype.renderRows = function (first, last) {
2545
2552
  bodyFragment.appendChild(row);
2546
2553
 
2547
2554
  this.trigger('rowcreate', i, physicalRowIndex, row, rowData);
2555
+
2556
+ let rowIndex = i;
2557
+ row.addEventListener('click', (event) => {
2558
+ this.trigger('rowclick', event, rowIndex, physicalRowIndex, row, rowData);
2559
+ });
2548
2560
  }
2549
2561
 
2550
2562
  return bodyFragment;
@@ -3045,8 +3057,9 @@ DGTable.prototype.sort = function (column, descending, add) {
3045
3057
 
3046
3058
  p.rows.sortColumn = currentSort;
3047
3059
 
3060
+ let comparator;
3048
3061
  if (currentSort.length) {
3049
- p.rows.sort(!!p.filteredRows);
3062
+ comparator = p.rows.sort(!!p.filteredRows);
3050
3063
  if (p.filteredRows) {
3051
3064
  p.filteredRows.sort(!!p.filteredRows);
3052
3065
  }
@@ -3057,7 +3070,7 @@ DGTable.prototype.sort = function (column, descending, add) {
3057
3070
  for (let i = 0; i < currentSort.length; i++) {
3058
3071
  sorts.push({ 'column': currentSort[i].column, 'descending': currentSort[i].descending });
3059
3072
  }
3060
- this.trigger('sort', sorts, true /* direct sort */);
3073
+ this.trigger('sort', sorts, true /* direct sort */, comparator);
3061
3074
 
3062
3075
  return this;
3063
3076
  };
@@ -3081,9 +3094,10 @@ DGTable.prototype.resort = function () {
3081
3094
  }
3082
3095
  }
3083
3096
 
3097
+ let comparator;
3084
3098
  p.rows.sortColumn = currentSort;
3085
3099
  if (currentSort.length) {
3086
- p.rows.sort(!!p.filteredRows);
3100
+ comparator = p.rows.sort(!!p.filteredRows);
3087
3101
  if (p.filteredRows) {
3088
3102
  p.filteredRows.sort(!!p.filteredRows);
3089
3103
  }
@@ -3094,10 +3108,9 @@ DGTable.prototype.resort = function () {
3094
3108
  for (let i = 0; i < currentSort.length; i++) {
3095
3109
  sorts.push({ 'column': currentSort[i].column, 'descending': currentSort[i].descending });
3096
3110
  }
3097
- this.trigger('sort', sorts, false /* indirect sort */);
3111
+ this.trigger('sort', sorts, false /* indirect sort */, comparator);
3098
3112
  }
3099
3113
 
3100
-
3101
3114
  return this;
3102
3115
  };
3103
3116