jqgrid_utils 1.28.0 → 1.30.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/README.md +42 -0
- package/dist/jqgrid_utils.js +67 -0
- package/jqgrid_utils.js +67 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,6 +37,7 @@ A module for Jqgrid_utils
|
|
|
37
37
|
* [module.exports#_date112_to_DMY(cell_value, seperator)](#exp_module_Jqgrid_utils--module.exports+_date112_to_DMY) ⏏
|
|
38
38
|
* [module.exports#date112_to_DMY(col_model, edit_field, seperator)](#exp_module_Jqgrid_utils--module.exports+date112_to_DMY) ⏏
|
|
39
39
|
* [module.exports#add_formatter(col_model, edit_field, formatter)](#exp_module_Jqgrid_utils--module.exports+add_formatter) ⏏
|
|
40
|
+
* [module.exports#natural_sort(col_model, column_name)](#exp_module_Jqgrid_utils--module.exports+natural_sort) ⇒ <code>array</code> ⏏
|
|
40
41
|
* [module.exports#add_html_formatter(col_model, edit_field, html)](#exp_module_Jqgrid_utils--module.exports+add_html_formatter) ⇒ <code>array</code> ⏏
|
|
41
42
|
* [module.exports#add_ok_button(col_model, fields)](#exp_module_Jqgrid_utils--module.exports+add_ok_button) ⇒ <code>array</code> ⏏
|
|
42
43
|
* [module.exports#get_filled_cell_table_data(_grid, fields)](#exp_module_Jqgrid_utils--module.exports+get_filled_cell_table_data) ⇒ <code>array</code> ⏏
|
|
@@ -59,6 +60,7 @@ A module for Jqgrid_utils
|
|
|
59
60
|
* [module.exports#s_hide_del_icon()](#exp_module_Jqgrid_utils--module.exports+s_hide_del_icon) ⏏
|
|
60
61
|
* [module.exports#hide_del_icon()](#exp_module_Jqgrid_utils--module.exports+hide_del_icon) ⏏
|
|
61
62
|
* [module.exports#add_link_details_csv(col_model, url, edit_field, attr, keys, format, seperator)](#exp_module_Jqgrid_utils--module.exports+add_link_details_csv) ⏏
|
|
63
|
+
* [module.exports#compare(obj, column1, column2, style)](#exp_module_Jqgrid_utils--module.exports+compare) ⏏
|
|
62
64
|
* [module.exports#set_styles(obj, style_column)](#exp_module_Jqgrid_utils--module.exports+set_styles) ⏏
|
|
63
65
|
* [module.exports#add_link_details(col_model, url, edit_field, attr, keys)](#exp_module_Jqgrid_utils--module.exports+add_link_details) ⏏
|
|
64
66
|
* [module.exports#add_link_details_separator(col_model, url, edit_field, attr, keys)](#exp_module_Jqgrid_utils--module.exports+add_link_details_separator) ⏏
|
|
@@ -301,6 +303,24 @@ Add Formatter
|
|
|
301
303
|
var jqu = new Jqgrid_utils();
|
|
302
304
|
col_model = await jqu.add_formatter(col_model,'select',{ formatter: "select", formatoptions: {value: "1:ok;0:fail", defaultValue: "1" }})
|
|
303
305
|
```
|
|
306
|
+
<a name="exp_module_Jqgrid_utils--module.exports+natural_sort"></a>
|
|
307
|
+
|
|
308
|
+
### module.exports#natural\_sort(col_model, column_name) ⇒ <code>array</code> ⏏
|
|
309
|
+
Natural Sort Column
|
|
310
|
+
|
|
311
|
+
**Kind**: Exported function
|
|
312
|
+
**Returns**: <code>array</code> - - col_model
|
|
313
|
+
|
|
314
|
+
| Param | Type | Description |
|
|
315
|
+
| --- | --- | --- |
|
|
316
|
+
| col_model | <code>array</code> | grid col_model |
|
|
317
|
+
| column_name | <code>string</code> | string columns names for natural sorting |
|
|
318
|
+
|
|
319
|
+
**Example**
|
|
320
|
+
```js
|
|
321
|
+
var jqu = new Jqgrid_utils();
|
|
322
|
+
col_model = await jqu.natural_sort(col_model,'colunmename');
|
|
323
|
+
```
|
|
304
324
|
<a name="exp_module_Jqgrid_utils--module.exports+add_html_formatter"></a>
|
|
305
325
|
|
|
306
326
|
### module.exports#add\_html\_formatter(col_model, edit_field, html) ⇒ <code>array</code> ⏏
|
|
@@ -702,6 +722,28 @@ Convert a cell into a link/url with data from another cell and spit the value by
|
|
|
702
722
|
var jqu = new Jqgrid_utils();
|
|
703
723
|
col_model = await jqu.add_link_details_csv(col_model, host + '/html/report.html' , 'tags','target="_blank"',{"tags":"tags"},',');
|
|
704
724
|
```
|
|
725
|
+
<a name="exp_module_Jqgrid_utils--module.exports+compare"></a>
|
|
726
|
+
|
|
727
|
+
### module.exports#compare(obj, column1, column2, style) ⏏
|
|
728
|
+
Compare 2 columns and give them a style class when they have different content
|
|
729
|
+
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
|
|
730
|
+
|
|
731
|
+
**Kind**: Exported function
|
|
732
|
+
|
|
733
|
+
| Param | Type | Description |
|
|
734
|
+
| --- | --- | --- |
|
|
735
|
+
| obj | <code>object</code> | grid object |
|
|
736
|
+
| column1 | <code>string</code> | first column |
|
|
737
|
+
| column2 | <code>string</code> | second column |
|
|
738
|
+
| style | <code>string</code> | css class name |
|
|
739
|
+
|
|
740
|
+
**Example**
|
|
741
|
+
```js
|
|
742
|
+
loadComplete: async function()
|
|
743
|
+
{
|
|
744
|
+
await jqu.compare(this,'value','value_report','greenlight');
|
|
745
|
+
}
|
|
746
|
+
```
|
|
705
747
|
<a name="exp_module_Jqgrid_utils--module.exports+set_styles"></a>
|
|
706
748
|
|
|
707
749
|
### module.exports#set\_styles(obj, style_column) ⏏
|
package/dist/jqgrid_utils.js
CHANGED
|
@@ -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
|
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
|
package/package.json
CHANGED