jqgrid_utils 1.27.3 → 1.29.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.
@@ -507,6 +507,73 @@ col_model = await jqu.add_formatter(col_model,'select',{ formatter: "select", fo
507
507
  return col_model;
508
508
  }
509
509
 
510
+ /**
511
+ * Natural Sort Column
512
+ @alias module:Jqgrid_utils
513
+ @param {array} - grid col_model
514
+ @param {string} - string columns names for natural sorting
515
+ @returns {array} - col_model
516
+ @example
517
+ var jqu = new Jqgrid_utils();
518
+ col_model = await jqu.natural_sort(col_model,'colunmename');
519
+ */
520
+
521
+ async natural_sort(col_model, column_name)
522
+ {
523
+ for(let i=0;i< col_model.length;i++)
524
+ {
525
+ if(col_model[i]['name'] === column_name)
526
+ {
527
+
528
+ col_model[i]['sortfunc'] = function (a, b, d) {
529
+
530
+ if(d===undefined) { d=1; }
531
+ var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
532
+ sre = /(^[ ]*|[ ]*$)/g,
533
+ dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
534
+ hre = /^0x[0-9a-f]+$/i,
535
+ ore = /^0/,
536
+ i = function(s) { return self.insensitive && (''+s).toLowerCase() || ''+s },
537
+ // convert all to strings strip whitespace
538
+ x = i(a).replace(sre, '') || '',
539
+ y = i(b).replace(sre, '') || '',
540
+ // chunk/tokenize
541
+ xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
542
+ yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
543
+ // numeric, hex or date detection
544
+ xD = parseInt(x.match(hre)) || (xN.length != 1 && x.match(dre) && Date.parse(x)),
545
+ yD = parseInt(y.match(hre)) || xD && y.match(dre) && Date.parse(y) || null,
546
+ oFxNcL, oFyNcL;
547
+ // first try and sort Hex codes or Dates
548
+ if (yD)
549
+ if ( xD < yD ) return -d;
550
+ else if ( xD > yD ) return d;
551
+ // natural sorting through split numeric strings and default strings
552
+ for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
553
+ // find floats not starting with '0', string or 0 if not defined (Clint Priest)
554
+ oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
555
+ oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
556
+ // handle numeric vs string comparison - number < string - (Kyle Adams)
557
+ if (isNaN(oFxNcL) !== isNaN(oFyNcL)) { return (isNaN(oFxNcL)) ? d : -d; }
558
+ // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
559
+ else if (typeof oFxNcL !== typeof oFyNcL) {
560
+ oFxNcL += '';
561
+ oFyNcL += '';
562
+ }
563
+ if (oFxNcL < oFyNcL) return -d;
564
+ if (oFxNcL > oFyNcL) return d;
565
+ }
566
+ return 0;
567
+ };
568
+
569
+
570
+
571
+ }
572
+ }
573
+ return col_model;
574
+ }
575
+
576
+
510
577
 
511
578
  /**
512
579
  * Add HTML Formatter
@@ -1184,6 +1251,33 @@ col_model = await jqu.add_link_details_csv(col_model, host + '/html/report.html'
1184
1251
  }
1185
1252
 
1186
1253
 
1254
+ /**
1255
+ * Compare 2 columns and give them a style class when they have different content
1256
+ * http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
1257
+ @alias module:Jqgrid_utils
1258
+ @param {object} - grid object
1259
+ @param {string} - first column
1260
+ @param {string} - second column
1261
+ @param {string} - css class name
1262
+ @example
1263
+ loadComplete: async function()
1264
+ {
1265
+ await jqu.compare(this,'value','value_report','greenlight');
1266
+ }
1267
+
1268
+ */
1269
+ async compare(obj, column1, column2, style)
1270
+ {
1271
+ const rows = jQuery(obj).jqGrid('getGridParam','data');
1272
+ for(let i in rows) {
1273
+ if( rows[i][column1] != rows[i][column2] )
1274
+ {
1275
+ jQuery(obj).jqGrid('setCell',rows[i]['id'], column1, "" ,'greenlight');
1276
+ jQuery(obj).jqGrid('setCell',rows[i]['id'], column2, "" ,'greenlight');
1277
+ }
1278
+ }
1279
+ }
1280
+
1187
1281
  /**
1188
1282
  * Set styles to individual cells, what are defined in a dedicated column
1189
1283
  @alias module:Jqgrid_utils
@@ -1214,7 +1308,7 @@ var jqu = new Jqgrid_utils();
1214
1308
  }
1215
1309
  }
1216
1310
  }
1217
-
1311
+
1218
1312
  }
1219
1313
 
1220
1314
 
package/jqgrid_utils.js CHANGED
@@ -506,6 +506,73 @@ col_model = await jqu.add_formatter(col_model,'select',{ formatter: "select", fo
506
506
  return col_model;
507
507
  }
508
508
 
509
+ /**
510
+ * Natural Sort Column
511
+ @alias module:Jqgrid_utils
512
+ @param {array} - grid col_model
513
+ @param {string} - string columns names for natural sorting
514
+ @returns {array} - col_model
515
+ @example
516
+ var jqu = new Jqgrid_utils();
517
+ col_model = await jqu.natural_sort(col_model,'colunmename');
518
+ */
519
+
520
+ async natural_sort(col_model, column_name)
521
+ {
522
+ for(let i=0;i< col_model.length;i++)
523
+ {
524
+ if(col_model[i]['name'] === column_name)
525
+ {
526
+
527
+ col_model[i]['sortfunc'] = function (a, b, d) {
528
+
529
+ if(d===undefined) { d=1; }
530
+ var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
531
+ sre = /(^[ ]*|[ ]*$)/g,
532
+ dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
533
+ hre = /^0x[0-9a-f]+$/i,
534
+ ore = /^0/,
535
+ i = function(s) { return self.insensitive && (''+s).toLowerCase() || ''+s },
536
+ // convert all to strings strip whitespace
537
+ x = i(a).replace(sre, '') || '',
538
+ y = i(b).replace(sre, '') || '',
539
+ // chunk/tokenize
540
+ xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
541
+ yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
542
+ // numeric, hex or date detection
543
+ xD = parseInt(x.match(hre)) || (xN.length != 1 && x.match(dre) && Date.parse(x)),
544
+ yD = parseInt(y.match(hre)) || xD && y.match(dre) && Date.parse(y) || null,
545
+ oFxNcL, oFyNcL;
546
+ // first try and sort Hex codes or Dates
547
+ if (yD)
548
+ if ( xD < yD ) return -d;
549
+ else if ( xD > yD ) return d;
550
+ // natural sorting through split numeric strings and default strings
551
+ for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
552
+ // find floats not starting with '0', string or 0 if not defined (Clint Priest)
553
+ oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
554
+ oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
555
+ // handle numeric vs string comparison - number < string - (Kyle Adams)
556
+ if (isNaN(oFxNcL) !== isNaN(oFyNcL)) { return (isNaN(oFxNcL)) ? d : -d; }
557
+ // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
558
+ else if (typeof oFxNcL !== typeof oFyNcL) {
559
+ oFxNcL += '';
560
+ oFyNcL += '';
561
+ }
562
+ if (oFxNcL < oFyNcL) return -d;
563
+ if (oFxNcL > oFyNcL) return d;
564
+ }
565
+ return 0;
566
+ };
567
+
568
+
569
+
570
+ }
571
+ }
572
+ return col_model;
573
+ }
574
+
575
+
509
576
 
510
577
  /**
511
578
  * Add HTML Formatter
@@ -1183,6 +1250,33 @@ col_model = await jqu.add_link_details_csv(col_model, host + '/html/report.html'
1183
1250
  }
1184
1251
 
1185
1252
 
1253
+ /**
1254
+ * Compare 2 columns and give them a style class when they have different content
1255
+ * http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
1256
+ @alias module:Jqgrid_utils
1257
+ @param {object} - grid object
1258
+ @param {string} - first column
1259
+ @param {string} - second column
1260
+ @param {string} - css class name
1261
+ @example
1262
+ loadComplete: async function()
1263
+ {
1264
+ await jqu.compare(this,'value','value_report','greenlight');
1265
+ }
1266
+
1267
+ */
1268
+ async compare(obj, column1, column2, style)
1269
+ {
1270
+ const rows = jQuery(obj).jqGrid('getGridParam','data');
1271
+ for(let i in rows) {
1272
+ if( rows[i][column1] != rows[i][column2] )
1273
+ {
1274
+ jQuery(obj).jqGrid('setCell',rows[i]['id'], column1, "" ,'greenlight');
1275
+ jQuery(obj).jqGrid('setCell',rows[i]['id'], column2, "" ,'greenlight');
1276
+ }
1277
+ }
1278
+ }
1279
+
1186
1280
  /**
1187
1281
  * Set styles to individual cells, what are defined in a dedicated column
1188
1282
  @alias module:Jqgrid_utils
@@ -1213,7 +1307,7 @@ var jqu = new Jqgrid_utils();
1213
1307
  }
1214
1308
  }
1215
1309
  }
1216
-
1310
+
1217
1311
  }
1218
1312
 
1219
1313
 
package/package.json CHANGED
@@ -29,5 +29,5 @@
29
29
  {
30
30
  "test": "echo \"Error: no test specified\" && exit 1"
31
31
  },
32
- "version": "1.27.3"
32
+ "version": "1.29.0"
33
33
  }