jqgrid_utils 1.30.3 → 1.31.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 CHANGED
@@ -27,6 +27,14 @@ A module for Jqgrid_utils
27
27
 
28
28
 
29
29
  * [Jqgrid_utils](#module_Jqgrid_utils)
30
+ * [module.exports#_grid_ratio_on()](#exp_module_Jqgrid_utils--module.exports+_grid_ratio_on) ⏏
31
+ * [module.exports#grid_ratio_on(grid, fraction_col, denominator_col, ratio_col)](#exp_module_Jqgrid_utils--module.exports+grid_ratio_on) ⏏
32
+ * [module.exports#_grid_sum_on()](#exp_module_Jqgrid_utils--module.exports+_grid_sum_on) ⏏
33
+ * [module.exports#grid_sum_on(grid, fields)](#exp_module_Jqgrid_utils--module.exports+grid_sum_on) ⏏
34
+ * [module.exports#_grid_avg_on()](#exp_module_Jqgrid_utils--module.exports+_grid_avg_on) ⏏
35
+ * [module.exports#grid_avg_on(grid, fields)](#exp_module_Jqgrid_utils--module.exports+grid_avg_on) ⏏
36
+ * [module.exports#_grid_percent_on()](#exp_module_Jqgrid_utils--module.exports+_grid_percent_on) ⏏
37
+ * [module.exports#grid_percent_on(grid, obj)](#exp_module_Jqgrid_utils--module.exports+grid_percent_on) ⏏
30
38
  * [module.exports#update_row_to_api(_self, api, _ids, row)](#exp_module_Jqgrid_utils--module.exports+update_row_to_api) ⏏
31
39
  * [module.exports#delete_row_to_api(_self, api, rowid, _ids, data)](#exp_module_Jqgrid_utils--module.exports+delete_row_to_api) ⏏
32
40
  * [module.exports#append_seperator_link_column(col_model, url, field_value, base, attr, keys)](#exp_module_Jqgrid_utils--module.exports+append_seperator_link_column) ⏏
@@ -71,6 +79,121 @@ A module for Jqgrid_utils
71
79
  * [module.exports#set_filter(grid, data, fx, append_to)](#exp_module_Jqgrid_utils--module.exports+set_filter) ⏏
72
80
  * [module.exports#_filter()](#exp_module_Jqgrid_utils--module.exports+_filter) ⏏
73
81
 
82
+ <a name="exp_module_Jqgrid_utils--module.exports+_grid_ratio_on"></a>
83
+
84
+ ### module.exports#\_grid\_ratio\_on() ⏏
85
+ Syncron Alias grid_ratio_on
86
+
87
+ **Kind**: Exported function
88
+ <a name="exp_module_Jqgrid_utils--module.exports+grid_ratio_on"></a>
89
+
90
+ ### module.exports#grid\_ratio\_on(grid, fraction_col, denominator_col, ratio_col) ⏏
91
+ Get the ratio the columns values together
92
+
93
+ **Kind**: Exported function
94
+
95
+ | Param | Type | Description |
96
+ | --- | --- | --- |
97
+ | grid | <code>object</code> | Grid Object (required) |
98
+ | fraction_col | <code>string</code> | Column/Field Name for value 1 |
99
+ | denominator_col | <code>string</code> | Column/Field Name for value 2 |
100
+ | ratio_col | <code>string</code> | Column/Field Name to the set the target ratio |
101
+
102
+ **Example**
103
+ ```js
104
+ var jqu = new Jqgrid_utils({page:page});
105
+ gridComplete: function()
106
+ {
107
+ jqu._grid_ratio_on(this, 'actual_days', 'plan_days', 'qc_eta_ratio');
108
+ },
109
+ ```
110
+ <a name="exp_module_Jqgrid_utils--module.exports+_grid_sum_on"></a>
111
+
112
+ ### module.exports#\_grid\_sum\_on() ⏏
113
+ Syncron Alias grid_sum_on
114
+
115
+ **Kind**: Exported function
116
+ <a name="exp_module_Jqgrid_utils--module.exports+grid_sum_on"></a>
117
+
118
+ ### module.exports#grid\_sum\_on(grid, fields) ⏏
119
+ Sum the columns values together
120
+
121
+ **Kind**: Exported function
122
+
123
+ | Param | Type | Description |
124
+ | --- | --- | --- |
125
+ | grid | <code>object</code> | Grid Object (required) |
126
+ | fields | <code>string</code> | Column/Field Name to sum |
127
+
128
+ **Example**
129
+ ```js
130
+ var jqu = new Jqgrid_utils({page:page});
131
+ gridComplete: function () {
132
+ jqu._jqu._grid_sum_on(this, [
133
+ "qty_icollect",
134
+ "qty_ordered",
135
+ "need_for_qty_ordered",
136
+ "wait_icollect",
137
+ ]);
138
+ },
139
+ ```
140
+ <a name="exp_module_Jqgrid_utils--module.exports+_grid_avg_on"></a>
141
+
142
+ ### module.exports#\_grid\_avg\_on() ⏏
143
+ Syncron Alias grid_avg_on
144
+
145
+ **Kind**: Exported function
146
+ <a name="exp_module_Jqgrid_utils--module.exports+grid_avg_on"></a>
147
+
148
+ ### module.exports#grid\_avg\_on(grid, fields) ⏏
149
+ Average the column values together
150
+
151
+ **Kind**: Exported function
152
+
153
+ | Param | Type | Description |
154
+ | --- | --- | --- |
155
+ | grid | <code>object</code> | Grid Object (required) |
156
+ | fields | <code>array</code> | Column/Field Names to where the average of each column should be calculated |
157
+
158
+ **Example**
159
+ ```js
160
+ var jqu = new Jqgrid_utils({page:page});
161
+
162
+ gridComplete: function()
163
+ {
164
+ jqu._grid_avg_on(this, ['diff_plan_to_actual', 'days_early', 'days_late']);
165
+ },
166
+ ```
167
+ <a name="exp_module_Jqgrid_utils--module.exports+_grid_percent_on"></a>
168
+
169
+ ### module.exports#\_grid\_percent\_on() ⏏
170
+ Syncron Alias grid_percent_on
171
+
172
+ **Kind**: Exported function
173
+ <a name="exp_module_Jqgrid_utils--module.exports+grid_percent_on"></a>
174
+
175
+ ### module.exports#grid\_percent\_on(grid, obj) ⏏
176
+ Percent the columns values together
177
+
178
+ **Kind**: Exported function
179
+
180
+ | Param | Type | Description |
181
+ | --- | --- | --- |
182
+ | grid | <code>object</code> | Grid Object (required) |
183
+ | obj | <code>string</code> | Column/Field Name to sum |
184
+
185
+ **Example**
186
+ ```js
187
+ var jqu = new Jqgrid_utils({page:page});
188
+ gridComplete: function () {
189
+ jqu._jqu._grid_sum_on(this, [
190
+ "qty_icollect",
191
+ "qty_ordered",
192
+ "need_for_qty_ordered",
193
+ "wait_icollect",
194
+ ]);
195
+ },
196
+ ```
74
197
  <a name="exp_module_Jqgrid_utils--module.exports+update_row_to_api"></a>
75
198
 
76
199
  ### module.exports#update\_row\_to\_api(_self, api, _ids, row) ⏏
@@ -16,6 +16,225 @@ module.exports = class Vanilla_website_utils {
16
16
  }
17
17
  }
18
18
 
19
+ /**
20
+ * Syncron Alias grid_ratio_on
21
+ @alias module:Jqgrid_utils
22
+ */
23
+ _grid_ratio_on(grid, fraction_col, denominator_col, ratio_col) {
24
+ return this.grid_ratio_on(grid, fraction_col, denominator_col, ratio_col);
25
+ }
26
+
27
+ /**
28
+ * Get the ratio the columns values together
29
+ @alias module:Jqgrid_utils
30
+ @param {object} - Grid Object (required)
31
+ @param {string} - Column/Field Name for value 1
32
+ @param {string} - Column/Field Name for value 2
33
+ @param {string} - Column/Field Name to the set the target ratio
34
+ @example
35
+ var jqu = new Jqgrid_utils({page:page});
36
+ gridComplete: function()
37
+ {
38
+ jqu._grid_ratio_on(this, 'actual_days', 'plan_days', 'qc_eta_ratio');
39
+ },
40
+
41
+ */
42
+ async grid_ratio_on(grid, fraction_col, denominator_col, ratio_col) {
43
+ var allrows = jQuery("#grid").jqGrid("getGridParam", "data");
44
+ let $self = jQuery(grid);
45
+ let rows = $self.jqGrid("getGridParam", "data");
46
+ let footer = {
47
+ invdate: "Total",
48
+ };
49
+ let sum = 0;
50
+ fraction_sum = 0;
51
+ denominator_sum = 0;
52
+ ratio_sum = 0;
53
+ for (let r in rows) {
54
+ if (rows[r].hasOwnProperty(fraction_col)) {
55
+ fraction_sum += rows[r][fraction_col];
56
+ }
57
+ if (rows[r].hasOwnProperty(denominator_col)) {
58
+ denominator_sum += rows[r][denominator_col];
59
+ }
60
+ }
61
+ footer["qc_eta_ratio"] = (fraction_sum / denominator_sum).toFixed(2);
62
+ $self.jqGrid("footerData", "set", footer);
63
+ return footer;
64
+ }
65
+
66
+ /**
67
+ * Syncron Alias grid_sum_on
68
+ @alias module:Jqgrid_utils
69
+ */
70
+ async _grid_sum_on(grid, fields = []) {
71
+ return await this.grid_sum_on(grid, fields);
72
+ }
73
+
74
+ /**
75
+ * Sum the columns values together
76
+ @alias module:Jqgrid_utils
77
+ @param {object} - Grid Object (required)
78
+ @param {string} - Column/Field Name to sum
79
+ @example
80
+ var jqu = new Jqgrid_utils({page:page});
81
+ gridComplete: function () {
82
+ jqu._jqu._grid_sum_on(this, [
83
+ "qty_icollect",
84
+ "qty_ordered",
85
+ "need_for_qty_ordered",
86
+ "wait_icollect",
87
+ ]);
88
+ },
89
+ */
90
+ async grid_sum_on(grid, fields = []) {
91
+ let $self = jQuery(grid);
92
+ let rows = $self.jqGrid("getGridParam", "data");
93
+ let footer = {
94
+ invdate: "Total",
95
+ };
96
+ for (let i in fields) {
97
+ let sum = 0;
98
+ for (let r in rows) {
99
+ if (rows[r].hasOwnProperty(fields[i])) {
100
+ let val = rows[r][fields[i]];
101
+ if (typeof val === "string") {
102
+ if (is_digit(val)) {
103
+ val = parseFloat(val);
104
+ }
105
+ }
106
+ sum += val;
107
+ }
108
+ }
109
+ //let number = new Intl.NumberFormat('en-En', { style: 'currency', currency: 'USD' }).format(sum);
110
+ if (sum != Math.floor(sum)) {
111
+ sum = sum.toFixed(2);
112
+ }
113
+ footer[fields[i]] = sum;
114
+ }
115
+ $self.jqGrid("footerData", "set", footer);
116
+ return footer;
117
+ }
118
+
119
+ /**
120
+ * Syncron Alias grid_avg_on
121
+ @alias module:Jqgrid_utils
122
+ */
123
+ _grid_avg_on(grid, fields = []) {
124
+ return this.grid_avg_on(grid, fields);
125
+ }
126
+
127
+ /**
128
+ * Average the column values together
129
+ @alias module:Jqgrid_utils
130
+ @param {object} - Grid Object (required)
131
+ @param {array} - Column/Field Names to where the average of each column should be calculated
132
+ @example
133
+ var jqu = new Jqgrid_utils({page:page});
134
+
135
+ gridComplete: function()
136
+ {
137
+ jqu._grid_avg_on(this, ['diff_plan_to_actual', 'days_early', 'days_late']);
138
+ },
139
+
140
+
141
+ */
142
+
143
+ async grid_avg_on(grid, fields = []) {
144
+ let $self = jQuery(grid);
145
+ let rows = $self.jqGrid("getGridParam", "data");
146
+ let count = 0;
147
+ let footer = {
148
+ invdate: "Total",
149
+ };
150
+ for (let i in fields) {
151
+ let sum = 0;
152
+ for (let r in rows) {
153
+ if (rows[r].hasOwnProperty(fields[i])) {
154
+ let val = rows[r][fields[i]];
155
+ if (typeof val === "string") {
156
+ if (is_digit(val)) {
157
+ val = parseFloat(val);
158
+ }
159
+ }
160
+ sum += val;
161
+ count++;
162
+ }
163
+ }
164
+ sum = sum / count;
165
+ if (sum != Math.floor(sum)) {
166
+ sum = sum.toFixed(2);
167
+ }
168
+ footer[fields[i]] = sum;
169
+ }
170
+ $self.jqGrid("footerData", "set", footer);
171
+ return footer;
172
+ }
173
+
174
+ /**
175
+ * Syncron Alias grid_percent_on
176
+ @alias module:Jqgrid_utils
177
+ */
178
+ _grid_percent_on(grid, obj) {
179
+ return grid_percent_on(grid, obj);
180
+ }
181
+
182
+ /**
183
+ * Percent the columns values together
184
+ @alias module:Jqgrid_utils
185
+ @param {object} - Grid Object (required)
186
+ @param {string} - Column/Field Name to sum
187
+ @example
188
+ var jqu = new Jqgrid_utils({page:page});
189
+ gridComplete: function () {
190
+ jqu._jqu._grid_sum_on(this, [
191
+ "qty_icollect",
192
+ "qty_ordered",
193
+ "need_for_qty_ordered",
194
+ "wait_icollect",
195
+ ]);
196
+ },
197
+ */
198
+ async grid_percent_on(grid, obj) {
199
+ let $self = jQuery(grid);
200
+ let rows = $self.jqGrid("getGridParam", "data");
201
+ let footer_sum = {};
202
+ let id = obj["id"] ? obj["id"] : "invate";
203
+ footer[id] = "Total";
204
+ let total = obj["total"];
205
+ let sums = JSON.parse(JSON.stringify(obj["percent"]));
206
+ sums.push(total);
207
+ for (let i in sums) {
208
+ let field = sums[i];
209
+ let sum = 0;
210
+ let _rows = 0;
211
+ for (let r in rows) {
212
+ if (rows[r].hasOwnProperty(field)) {
213
+ let val = rows[r][field];
214
+ if (typeof val === "string") {
215
+ if (is_digit(val)) {
216
+ val = parseFloat(val);
217
+ sum += val;
218
+ _rows++;
219
+ }
220
+ } else {
221
+ sum += val;
222
+ _rows++;
223
+ }
224
+ }
225
+ }
226
+ footer_sum[field] = sum;
227
+ }
228
+
229
+ for (let i in sums) {
230
+ let field = sums[i];
231
+ let percent = footer_sum[field] / (footer_sum[total] / 100);
232
+ percent = percent.toFixed(2);
233
+ footer[field] = percent + "%";
234
+ }
235
+ $self.jqGrid("footerData", "set", footer);
236
+ }
237
+
19
238
  /**
20
239
  * Takes the updated columns data and send it to your API post server
21
240
  * loadComplete: async function() for the old record needs to be called, see example !
package/jqgrid_utils.js CHANGED
@@ -15,6 +15,225 @@ module.exports = class Vanilla_website_utils {
15
15
  }
16
16
  }
17
17
 
18
+ /**
19
+ * Syncron Alias grid_ratio_on
20
+ @alias module:Jqgrid_utils
21
+ */
22
+ _grid_ratio_on(grid, fraction_col, denominator_col, ratio_col) {
23
+ return this.grid_ratio_on(grid, fraction_col, denominator_col, ratio_col);
24
+ }
25
+
26
+ /**
27
+ * Get the ratio the columns values together
28
+ @alias module:Jqgrid_utils
29
+ @param {object} - Grid Object (required)
30
+ @param {string} - Column/Field Name for value 1
31
+ @param {string} - Column/Field Name for value 2
32
+ @param {string} - Column/Field Name to the set the target ratio
33
+ @example
34
+ var jqu = new Jqgrid_utils({page:page});
35
+ gridComplete: function()
36
+ {
37
+ jqu._grid_ratio_on(this, 'actual_days', 'plan_days', 'qc_eta_ratio');
38
+ },
39
+
40
+ */
41
+ async grid_ratio_on(grid, fraction_col, denominator_col, ratio_col) {
42
+ var allrows = jQuery("#grid").jqGrid("getGridParam", "data");
43
+ let $self = jQuery(grid);
44
+ let rows = $self.jqGrid("getGridParam", "data");
45
+ let footer = {
46
+ invdate: "Total",
47
+ };
48
+ let sum = 0;
49
+ fraction_sum = 0;
50
+ denominator_sum = 0;
51
+ ratio_sum = 0;
52
+ for (let r in rows) {
53
+ if (rows[r].hasOwnProperty(fraction_col)) {
54
+ fraction_sum += rows[r][fraction_col];
55
+ }
56
+ if (rows[r].hasOwnProperty(denominator_col)) {
57
+ denominator_sum += rows[r][denominator_col];
58
+ }
59
+ }
60
+ footer["qc_eta_ratio"] = (fraction_sum / denominator_sum).toFixed(2);
61
+ $self.jqGrid("footerData", "set", footer);
62
+ return footer;
63
+ }
64
+
65
+ /**
66
+ * Syncron Alias grid_sum_on
67
+ @alias module:Jqgrid_utils
68
+ */
69
+ async _grid_sum_on(grid, fields = []) {
70
+ return await this.grid_sum_on(grid, fields);
71
+ }
72
+
73
+ /**
74
+ * Sum the columns values together
75
+ @alias module:Jqgrid_utils
76
+ @param {object} - Grid Object (required)
77
+ @param {string} - Column/Field Name to sum
78
+ @example
79
+ var jqu = new Jqgrid_utils({page:page});
80
+ gridComplete: function () {
81
+ jqu._jqu._grid_sum_on(this, [
82
+ "qty_icollect",
83
+ "qty_ordered",
84
+ "need_for_qty_ordered",
85
+ "wait_icollect",
86
+ ]);
87
+ },
88
+ */
89
+ async grid_sum_on(grid, fields = []) {
90
+ let $self = jQuery(grid);
91
+ let rows = $self.jqGrid("getGridParam", "data");
92
+ let footer = {
93
+ invdate: "Total",
94
+ };
95
+ for (let i in fields) {
96
+ let sum = 0;
97
+ for (let r in rows) {
98
+ if (rows[r].hasOwnProperty(fields[i])) {
99
+ let val = rows[r][fields[i]];
100
+ if (typeof val === "string") {
101
+ if (is_digit(val)) {
102
+ val = parseFloat(val);
103
+ }
104
+ }
105
+ sum += val;
106
+ }
107
+ }
108
+ //let number = new Intl.NumberFormat('en-En', { style: 'currency', currency: 'USD' }).format(sum);
109
+ if (sum != Math.floor(sum)) {
110
+ sum = sum.toFixed(2);
111
+ }
112
+ footer[fields[i]] = sum;
113
+ }
114
+ $self.jqGrid("footerData", "set", footer);
115
+ return footer;
116
+ }
117
+
118
+ /**
119
+ * Syncron Alias grid_avg_on
120
+ @alias module:Jqgrid_utils
121
+ */
122
+ _grid_avg_on(grid, fields = []) {
123
+ return this.grid_avg_on(grid, fields);
124
+ }
125
+
126
+ /**
127
+ * Average the column values together
128
+ @alias module:Jqgrid_utils
129
+ @param {object} - Grid Object (required)
130
+ @param {array} - Column/Field Names to where the average of each column should be calculated
131
+ @example
132
+ var jqu = new Jqgrid_utils({page:page});
133
+
134
+ gridComplete: function()
135
+ {
136
+ jqu._grid_avg_on(this, ['diff_plan_to_actual', 'days_early', 'days_late']);
137
+ },
138
+
139
+
140
+ */
141
+
142
+ async grid_avg_on(grid, fields = []) {
143
+ let $self = jQuery(grid);
144
+ let rows = $self.jqGrid("getGridParam", "data");
145
+ let count = 0;
146
+ let footer = {
147
+ invdate: "Total",
148
+ };
149
+ for (let i in fields) {
150
+ let sum = 0;
151
+ for (let r in rows) {
152
+ if (rows[r].hasOwnProperty(fields[i])) {
153
+ let val = rows[r][fields[i]];
154
+ if (typeof val === "string") {
155
+ if (is_digit(val)) {
156
+ val = parseFloat(val);
157
+ }
158
+ }
159
+ sum += val;
160
+ count++;
161
+ }
162
+ }
163
+ sum = sum / count;
164
+ if (sum != Math.floor(sum)) {
165
+ sum = sum.toFixed(2);
166
+ }
167
+ footer[fields[i]] = sum;
168
+ }
169
+ $self.jqGrid("footerData", "set", footer);
170
+ return footer;
171
+ }
172
+
173
+ /**
174
+ * Syncron Alias grid_percent_on
175
+ @alias module:Jqgrid_utils
176
+ */
177
+ _grid_percent_on(grid, obj) {
178
+ return grid_percent_on(grid, obj);
179
+ }
180
+
181
+ /**
182
+ * Percent the columns values together
183
+ @alias module:Jqgrid_utils
184
+ @param {object} - Grid Object (required)
185
+ @param {string} - Column/Field Name to sum
186
+ @example
187
+ var jqu = new Jqgrid_utils({page:page});
188
+ gridComplete: function () {
189
+ jqu._jqu._grid_sum_on(this, [
190
+ "qty_icollect",
191
+ "qty_ordered",
192
+ "need_for_qty_ordered",
193
+ "wait_icollect",
194
+ ]);
195
+ },
196
+ */
197
+ async grid_percent_on(grid, obj) {
198
+ let $self = jQuery(grid);
199
+ let rows = $self.jqGrid("getGridParam", "data");
200
+ let footer_sum = {};
201
+ let id = obj["id"] ? obj["id"] : "invate";
202
+ footer[id] = "Total";
203
+ let total = obj["total"];
204
+ let sums = JSON.parse(JSON.stringify(obj["percent"]));
205
+ sums.push(total);
206
+ for (let i in sums) {
207
+ let field = sums[i];
208
+ let sum = 0;
209
+ let _rows = 0;
210
+ for (let r in rows) {
211
+ if (rows[r].hasOwnProperty(field)) {
212
+ let val = rows[r][field];
213
+ if (typeof val === "string") {
214
+ if (is_digit(val)) {
215
+ val = parseFloat(val);
216
+ sum += val;
217
+ _rows++;
218
+ }
219
+ } else {
220
+ sum += val;
221
+ _rows++;
222
+ }
223
+ }
224
+ }
225
+ footer_sum[field] = sum;
226
+ }
227
+
228
+ for (let i in sums) {
229
+ let field = sums[i];
230
+ let percent = footer_sum[field] / (footer_sum[total] / 100);
231
+ percent = percent.toFixed(2);
232
+ footer[field] = percent + "%";
233
+ }
234
+ $self.jqGrid("footerData", "set", footer);
235
+ }
236
+
18
237
  /**
19
238
  * Takes the updated columns data and send it to your API post server
20
239
  * loadComplete: async function() for the old record needs to be called, see example !
package/npmignore CHANGED
@@ -1,2 +1,3 @@
1
1
  .tern-port
2
- *~
2
+ *~
3
+ .github
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.30.3"
32
+ "version": "1.31.0"
33
33
  }