jqgrid_utils 1.31.0 → 1.34.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.
@@ -16,6 +16,111 @@ module.exports = class Vanilla_website_utils {
16
16
  }
17
17
  }
18
18
 
19
+ /**
20
+ * Syncron Alias grid_sum_on
21
+ @alias module:Jqgrid_utils
22
+ */
23
+ async _grid_substract_on(
24
+ grid,
25
+ minuend = [],
26
+ subtrahend = [],
27
+ difference,
28
+ no_negative = false,
29
+ ) {
30
+ return await this.grid_substract_on(
31
+ grid,
32
+ minuend,
33
+ subtrahend,
34
+ difference,
35
+ no_negative,
36
+ );
37
+ }
38
+
39
+ /**
40
+ * Sum the columns values together
41
+ @alias module:Jqgrid_utils
42
+ @param {object} - Grid Object (required)
43
+ @param {array} - string array list of field_names used as minuend(number from which the other number is subtracted)
44
+ @param {array} - string array list of field_names used as subtrahend(number which is to be subtracted from the minuend)
45
+ @param {string} - string field name for the difference(number which is to be subtracted from the minuend)
46
+ @param {bolen} - true or 1 to not show negative numbers
47
+
48
+ @example
49
+ var jqu = new Jqgrid_utils({page:page});
50
+ gridComplete: function () {
51
+ jqu._jqu._grid_sum_on(this, [
52
+ "qty_icollect",
53
+ "qty_ordered",
54
+ "need_for_qty_ordered",
55
+ "wait_icollect",
56
+ ]);
57
+ },
58
+ */
59
+ async grid_substract_on(
60
+ grid,
61
+ minuend = [],
62
+ subtrahend = [],
63
+ difference,
64
+ no_negative = false,
65
+ ) {
66
+ let $self = jQuery(grid);
67
+ let rows = $self.jqGrid("getGridParam", "data");
68
+ let footer = { invdate: "Total" };
69
+ let _minuend = 0.0;
70
+ let _subtrahend = 0.0;
71
+ for (let i in minuend) {
72
+ let sum = 0;
73
+ for (let r in rows) {
74
+ if (rows[r].hasOwnProperty(minuend[i])) {
75
+ let val = rows[r][minuend[i]];
76
+ if (typeof val === "string") {
77
+ if (is_digit(val)) {
78
+ val = parseFloat(val);
79
+ }
80
+ }
81
+ sum += val;
82
+ }
83
+ }
84
+ if (sum != Math.floor(sum)) {
85
+ sum = sum.toFixed(2);
86
+ }
87
+ footer[minuend[i]] = sum;
88
+ _minuend = sum;
89
+ }
90
+
91
+ for (let i in subtrahend) {
92
+ let sum = 0;
93
+ for (let r in rows) {
94
+ if (rows[r].hasOwnProperty(subtrahend[i])) {
95
+ let val = rows[r][subtrahend[i]];
96
+ if (typeof val === "string") {
97
+ if (is_digit(val)) {
98
+ val = parseFloat(val);
99
+ }
100
+ }
101
+ sum += val;
102
+ }
103
+ }
104
+ if (sum != Math.floor(sum)) {
105
+ sum = sum.toFixed(2);
106
+ }
107
+ footer[subtrahend[i]] = sum;
108
+ _subtrahend = sum;
109
+ }
110
+
111
+ let diff = _minuend - _subtrahend;
112
+ if (no_negative) {
113
+ if (diff < 0) {
114
+ diff = 0;
115
+ }
116
+ }
117
+ footer[difference] = diff;
118
+
119
+ $self.jqGrid("footerData", "set", footer);
120
+
121
+ return footer;
122
+ }
123
+
19
124
  /**
20
125
  * Syncron Alias grid_ratio_on
21
126
  @alias module:Jqgrid_utils
@@ -1371,16 +1476,66 @@ col_model = await jqu.add_link_details_csv(col_model, host + '/html/report.html'
1371
1476
  @example
1372
1477
  loadComplete: async function()
1373
1478
  {
1374
- await jqu.compare(this,'value','value_report','greenlight');
1479
+ await jqu.compare(this,'first_column','second_column','redlight');
1375
1480
  }
1376
1481
 
1377
1482
  */
1378
- async compare(obj, column1, column2, style) {
1483
+ async compare(obj, column1, column2, css_class) {
1379
1484
  const rows = jQuery(obj).jqGrid("getGridParam", "data");
1380
1485
  for (let i in rows) {
1381
1486
  if (rows[i][column1] != rows[i][column2]) {
1382
- jQuery(obj).jqGrid("setCell", rows[i]["id"], column1, "", "greenlight");
1383
- jQuery(obj).jqGrid("setCell", rows[i]["id"], column2, "", "greenlight");
1487
+ jQuery(obj).jqGrid("setCell", rows[i]["id"], column1, "", css_class);
1488
+ jQuery(obj).jqGrid("setCell", rows[i]["id"], column2, "", css_class);
1489
+ }
1490
+ }
1491
+ }
1492
+
1493
+ /**
1494
+ * Compare 2 columns for smaller and give them a style class
1495
+ * http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
1496
+ @alias module:Jqgrid_utils
1497
+ @param {object} - grid object
1498
+ @param {string} - first column
1499
+ @param {string} - second column
1500
+ @param {string} - css class name
1501
+ @example
1502
+ loadComplete: async function()
1503
+ {
1504
+ await jqu.compare(this,'first_column','second_column','redlight');
1505
+ }
1506
+
1507
+ */
1508
+ async compare_smaller(obj, column1, column2, css_class) {
1509
+ const rows = jQuery(obj).jqGrid("getGridParam", "data");
1510
+ for (let i in rows) {
1511
+ if (rows[i][column1] < rows[i][column2]) {
1512
+ jQuery(obj).jqGrid("setCell", rows[i]["id"], column1, "", css_class);
1513
+ jQuery(obj).jqGrid("setCell", rows[i]["id"], column2, "", css_class);
1514
+ }
1515
+ }
1516
+ }
1517
+
1518
+ /**
1519
+ * Compare 2 columns for bigger and give them a style class
1520
+ * http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
1521
+ @alias module:Jqgrid_utils
1522
+ @param {object} - grid object
1523
+ @param {string} - first column
1524
+ @param {string} - second column
1525
+ @param {string} - css class name
1526
+ @example
1527
+ loadComplete: async function()
1528
+ {
1529
+ await jqu.compare(this,'first_column','second_column','redlight');
1530
+ }
1531
+
1532
+ */
1533
+ async compare_bigger(obj, column1, column2, css_class) {
1534
+ const rows = jQuery(obj).jqGrid("getGridParam", "data");
1535
+ for (let i in rows) {
1536
+ if (rows[i][column1] > rows[i][column2]) {
1537
+ jQuery(obj).jqGrid("setCell", rows[i]["id"], column1, "", css_class);
1538
+ jQuery(obj).jqGrid("setCell", rows[i]["id"], column2, "", css_class);
1384
1539
  }
1385
1540
  }
1386
1541
  }
@@ -1470,7 +1625,7 @@ col_model = await jqu.add_link_details(col_model, host + '/html/table_size.html'
1470
1625
  }
1471
1626
  const _cell_val = self.__cell_format(cell_val, format);
1472
1627
 
1473
- if (t != "") {
1628
+ if (t != "" && _cell_val && t) {
1474
1629
  cell_val =
1475
1630
  "<a " +
1476
1631
  attr +
package/jqgrid_utils.js CHANGED
@@ -15,6 +15,111 @@ module.exports = class Vanilla_website_utils {
15
15
  }
16
16
  }
17
17
 
18
+ /**
19
+ * Syncron Alias grid_sum_on
20
+ @alias module:Jqgrid_utils
21
+ */
22
+ async _grid_substract_on(
23
+ grid,
24
+ minuend = [],
25
+ subtrahend = [],
26
+ difference,
27
+ no_negative = false,
28
+ ) {
29
+ return await this.grid_substract_on(
30
+ grid,
31
+ minuend,
32
+ subtrahend,
33
+ difference,
34
+ no_negative,
35
+ );
36
+ }
37
+
38
+ /**
39
+ * Sum the columns values together
40
+ @alias module:Jqgrid_utils
41
+ @param {object} - Grid Object (required)
42
+ @param {array} - string array list of field_names used as minuend(number from which the other number is subtracted)
43
+ @param {array} - string array list of field_names used as subtrahend(number which is to be subtracted from the minuend)
44
+ @param {string} - string field name for the difference(number which is to be subtracted from the minuend)
45
+ @param {bolen} - true or 1 to not show negative numbers
46
+
47
+ @example
48
+ var jqu = new Jqgrid_utils({page:page});
49
+ gridComplete: function () {
50
+ jqu._jqu._grid_sum_on(this, [
51
+ "qty_icollect",
52
+ "qty_ordered",
53
+ "need_for_qty_ordered",
54
+ "wait_icollect",
55
+ ]);
56
+ },
57
+ */
58
+ async grid_substract_on(
59
+ grid,
60
+ minuend = [],
61
+ subtrahend = [],
62
+ difference,
63
+ no_negative = false,
64
+ ) {
65
+ let $self = jQuery(grid);
66
+ let rows = $self.jqGrid("getGridParam", "data");
67
+ let footer = { invdate: "Total" };
68
+ let _minuend = 0.0;
69
+ let _subtrahend = 0.0;
70
+ for (let i in minuend) {
71
+ let sum = 0;
72
+ for (let r in rows) {
73
+ if (rows[r].hasOwnProperty(minuend[i])) {
74
+ let val = rows[r][minuend[i]];
75
+ if (typeof val === "string") {
76
+ if (is_digit(val)) {
77
+ val = parseFloat(val);
78
+ }
79
+ }
80
+ sum += val;
81
+ }
82
+ }
83
+ if (sum != Math.floor(sum)) {
84
+ sum = sum.toFixed(2);
85
+ }
86
+ footer[minuend[i]] = sum;
87
+ _minuend = sum;
88
+ }
89
+
90
+ for (let i in subtrahend) {
91
+ let sum = 0;
92
+ for (let r in rows) {
93
+ if (rows[r].hasOwnProperty(subtrahend[i])) {
94
+ let val = rows[r][subtrahend[i]];
95
+ if (typeof val === "string") {
96
+ if (is_digit(val)) {
97
+ val = parseFloat(val);
98
+ }
99
+ }
100
+ sum += val;
101
+ }
102
+ }
103
+ if (sum != Math.floor(sum)) {
104
+ sum = sum.toFixed(2);
105
+ }
106
+ footer[subtrahend[i]] = sum;
107
+ _subtrahend = sum;
108
+ }
109
+
110
+ let diff = _minuend - _subtrahend;
111
+ if (no_negative) {
112
+ if (diff < 0) {
113
+ diff = 0;
114
+ }
115
+ }
116
+ footer[difference] = diff;
117
+
118
+ $self.jqGrid("footerData", "set", footer);
119
+
120
+ return footer;
121
+ }
122
+
18
123
  /**
19
124
  * Syncron Alias grid_ratio_on
20
125
  @alias module:Jqgrid_utils
@@ -1370,16 +1475,66 @@ col_model = await jqu.add_link_details_csv(col_model, host + '/html/report.html'
1370
1475
  @example
1371
1476
  loadComplete: async function()
1372
1477
  {
1373
- await jqu.compare(this,'value','value_report','greenlight');
1478
+ await jqu.compare(this,'first_column','second_column','redlight');
1374
1479
  }
1375
1480
 
1376
1481
  */
1377
- async compare(obj, column1, column2, style) {
1482
+ async compare(obj, column1, column2, css_class) {
1378
1483
  const rows = jQuery(obj).jqGrid("getGridParam", "data");
1379
1484
  for (let i in rows) {
1380
1485
  if (rows[i][column1] != rows[i][column2]) {
1381
- jQuery(obj).jqGrid("setCell", rows[i]["id"], column1, "", "greenlight");
1382
- jQuery(obj).jqGrid("setCell", rows[i]["id"], column2, "", "greenlight");
1486
+ jQuery(obj).jqGrid("setCell", rows[i]["id"], column1, "", css_class);
1487
+ jQuery(obj).jqGrid("setCell", rows[i]["id"], column2, "", css_class);
1488
+ }
1489
+ }
1490
+ }
1491
+
1492
+ /**
1493
+ * Compare 2 columns for smaller and give them a style class
1494
+ * http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
1495
+ @alias module:Jqgrid_utils
1496
+ @param {object} - grid object
1497
+ @param {string} - first column
1498
+ @param {string} - second column
1499
+ @param {string} - css class name
1500
+ @example
1501
+ loadComplete: async function()
1502
+ {
1503
+ await jqu.compare(this,'first_column','second_column','redlight');
1504
+ }
1505
+
1506
+ */
1507
+ async compare_smaller(obj, column1, column2, css_class) {
1508
+ const rows = jQuery(obj).jqGrid("getGridParam", "data");
1509
+ for (let i in rows) {
1510
+ if (rows[i][column1] < rows[i][column2]) {
1511
+ jQuery(obj).jqGrid("setCell", rows[i]["id"], column1, "", css_class);
1512
+ jQuery(obj).jqGrid("setCell", rows[i]["id"], column2, "", css_class);
1513
+ }
1514
+ }
1515
+ }
1516
+
1517
+ /**
1518
+ * Compare 2 columns for bigger and give them a style class
1519
+ * http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
1520
+ @alias module:Jqgrid_utils
1521
+ @param {object} - grid object
1522
+ @param {string} - first column
1523
+ @param {string} - second column
1524
+ @param {string} - css class name
1525
+ @example
1526
+ loadComplete: async function()
1527
+ {
1528
+ await jqu.compare(this,'first_column','second_column','redlight');
1529
+ }
1530
+
1531
+ */
1532
+ async compare_bigger(obj, column1, column2, css_class) {
1533
+ const rows = jQuery(obj).jqGrid("getGridParam", "data");
1534
+ for (let i in rows) {
1535
+ if (rows[i][column1] > rows[i][column2]) {
1536
+ jQuery(obj).jqGrid("setCell", rows[i]["id"], column1, "", css_class);
1537
+ jQuery(obj).jqGrid("setCell", rows[i]["id"], column2, "", css_class);
1383
1538
  }
1384
1539
  }
1385
1540
  }
@@ -1469,7 +1624,7 @@ col_model = await jqu.add_link_details(col_model, host + '/html/table_size.html'
1469
1624
  }
1470
1625
  const _cell_val = self.__cell_format(cell_val, format);
1471
1626
 
1472
- if (t != "") {
1627
+ if (t != "" && _cell_val && t) {
1473
1628
  cell_val =
1474
1629
  "<a " +
1475
1630
  attr +
package/package.json CHANGED
@@ -29,5 +29,7 @@
29
29
  {
30
30
  "test": "echo \"Error: no test specified\" && exit 1"
31
31
  },
32
- "version": "1.31.0"
32
+
33
+ "version": "1.34.0"
34
+
33
35
  }