jqgrid_utils 1.2.9 → 1.2.12

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
@@ -20,39 +20,14 @@ Example Usage:
20
20
 
21
21
  ```
22
22
 
23
- Discover All Functions:
24
-
25
- * To add the Qty of rows to the Caption text
26
- * grid_set_captain(_grid, data)
27
- * _grid: the DOM ID of grid(type: string), example: '#grid'
28
- * data: the grid data(type: array) (Optional)
23
+ Init
29
24
  * example:
30
25
  ```javascript
31
- let gu = new Jqgrid_utils();
32
- loadComplete: function(data)
33
- {
34
- await gu.grid_set_captain(_grid, data);
35
- }
36
- ```
37
-
38
- ## Functions:
26
+ let jqu = new Jqgrid_utils();
39
27
 
40
- ### add grid_load_complete to don't show the delete icon
41
- ```javascript
42
- loadComplete: async function(data)
43
- {
44
- jqu.s_hide_del_icon();
45
- grid_load_complete;
46
- },
47
28
  ```
48
29
 
49
- ```javascript
50
- loadComplete: async function(data)
51
- {
52
- await jqu.hide_del_icon();
53
- grid_load_complete;
54
- },
55
- ```
30
+
56
31
 
57
32
  <a name="module_Jqgrid_utils"></a>
58
33
 
@@ -62,8 +37,10 @@ A module for Jqgrid_utils
62
37
 
63
38
  * [Jqgrid_utils](#module_Jqgrid_utils)
64
39
  * [module.exports#set_link()](#exp_module_Jqgrid_utils--module.exports+set_link) ⏏
65
- * [module.exports#grid_set_captain()](#exp_module_Jqgrid_utils--module.exports+grid_set_captain) ⏏
40
+ * [module.exports#grid_set_caption(_grid, data)](#exp_module_Jqgrid_utils--module.exports+grid_set_caption) ⏏
41
+ * [module.exports#s_resize_saved_cell_width()](#exp_module_Jqgrid_utils--module.exports+s_resize_saved_cell_width) ⏏
66
42
  * [module.exports#resize_saved_cell_width(col_model, page, grid)](#exp_module_Jqgrid_utils--module.exports+resize_saved_cell_width) ⏏
43
+ * [module.exports#resize_cell(the, column, not)](#exp_module_Jqgrid_utils--module.exports+resize_cell) ⏏
67
44
  * [module.exports#upsert_row()](#exp_module_Jqgrid_utils--module.exports+upsert_row) ⏏
68
45
  * [module.exports#insert_row()](#exp_module_Jqgrid_utils--module.exports+insert_row) ⏏
69
46
  * [module.exports#update_row()](#exp_module_Jqgrid_utils--module.exports+update_row) ⏏
@@ -77,14 +54,32 @@ A module for Jqgrid_utils
77
54
  * [module.exports#__cell_format()](#exp_module_Jqgrid_utils--module.exports+__cell_format) ⏏
78
55
  * [module.exports#subgrid(_id, id, data_url, col_model, caption)](#exp_module_Jqgrid_utils--module.exports+subgrid) ⏏
79
56
  * [module.exports#add_image(col_model, edit_field, size, link)](#exp_module_Jqgrid_utils--module.exports+add_image) ⏏
57
+ * [module.exports#set_filter(grid, data, fx, append_to)](#exp_module_Jqgrid_utils--module.exports+set_filter) ⏏
80
58
 
81
59
  <a name="exp_module_Jqgrid_utils--module.exports+set_link"></a>
82
60
 
83
61
  ### module.exports#set\_link() ⏏
84
62
  **Kind**: Exported function
85
- <a name="exp_module_Jqgrid_utils--module.exports+grid_set_captain"></a>
63
+ <a name="exp_module_Jqgrid_utils--module.exports+grid_set_caption"></a>
86
64
 
87
- ### module.exports#grid\_set\_captain() ⏏
65
+ ### module.exports#grid\_set\_caption(_grid, data) ⏏
66
+ **Kind**: Exported function
67
+
68
+ | Param | Type | Description |
69
+ | --- | --- | --- |
70
+ | _grid | <code>object</code> | gridobject; |
71
+ | data | <code>object</code> | grid data (optional); |
72
+
73
+ **Example**
74
+ ```js
75
+ var jqu = new Jqgrid_utils();
76
+ loadComplete: function(){
77
+ jqu.grid_set_caption(this);
78
+ },
79
+ ```
80
+ <a name="exp_module_Jqgrid_utils--module.exports+s_resize_saved_cell_width"></a>
81
+
82
+ ### module.exports#s\_resize\_saved\_cell\_width() ⏏
88
83
  **Kind**: Exported function
89
84
  <a name="exp_module_Jqgrid_utils--module.exports+resize_saved_cell_width"></a>
90
85
 
@@ -101,6 +96,22 @@ A module for Jqgrid_utils
101
96
  ```js
102
97
  col_model = await jqu.resize_saved_cell_width(col_model);
103
98
  ```
99
+ <a name="exp_module_Jqgrid_utils--module.exports+resize_cell"></a>
100
+
101
+ ### module.exports#resize\_cell(the, column, not) ⏏
102
+ **Kind**: Exported function
103
+
104
+ | Param | Type | Description |
105
+ | --- | --- | --- |
106
+ | the | <code>string</code> | width of the resized column |
107
+ | column | <code>string</code> | number what get resized |
108
+ | not | <code>string</code> | in use yet |
109
+
110
+ **Example**
111
+ ```js
112
+ var jqu = new Jqgrid_utils({page:'mypage'});
113
+ resizeStop: jqu.resize_cell,
114
+ ```
104
115
  <a name="exp_module_Jqgrid_utils--module.exports+upsert_row"></a>
105
116
 
106
117
  ### module.exports#upsert\_row() ⏏
@@ -188,3 +199,27 @@ let col_model = JSON.parse(await vwu.aget_api(col_model_url))
188
199
  ```js
189
200
  col_model = await jqu.add_image(col_model, 'image', 60, false);
190
201
  ```
202
+ <a name="exp_module_Jqgrid_utils--module.exports+set_filter"></a>
203
+
204
+ ### module.exports#set\_filter(grid, data, fx, append_to) ⏏
205
+ **Kind**: Exported function
206
+
207
+ | Param | Type | Default | Description |
208
+ | --- | --- | --- | --- |
209
+ | grid | <code>object</code> | | grid object or grid string name |
210
+ | data | <code>object</code> | | the grid data object |
211
+ | fx | <code>object</code> | | a dict with a array what should be filterd by the grid |
212
+ | append_to | <code>string</code> | <code>&quot;#filter&quot;</code> | id name of the DOM oject where the filter should be appened |
213
+
214
+ **Example**
215
+ ```js
216
+ var jqu = new Jqgrid_utils();
217
+ var run_me_once = true;
218
+ gridComplete: async function(){
219
+ if(run_me_once)
220
+ {
221
+ await jqu.set_filter(this, data, {material:[],section:[]}, '#filter');
222
+ run_me_once = false;
223
+ }
224
+ },
225
+ ```
package/_README.md CHANGED
@@ -20,37 +20,12 @@ Example Usage:
20
20
 
21
21
  ```
22
22
 
23
- Discover All Functions:
24
-
25
- * To add the Qty of rows to the Caption text
26
- * grid_set_captain(_grid, data)
27
- * _grid: the DOM ID of grid(type: string), example: '#grid'
28
- * data: the grid data(type: array) (Optional)
23
+ Init
29
24
  * example:
30
25
  ```javascript
31
- let gu = new Jqgrid_utils();
32
- loadComplete: function(data)
33
- {
34
- await gu.grid_set_captain(_grid, data);
35
- }
36
- ```
26
+ let jqu = new Jqgrid_utils();
37
27
 
38
- ## Functions:
39
-
40
- ### add grid_load_complete to don't show the delete icon
41
- ```javascript
42
- loadComplete: async function(data)
43
- {
44
- jqu.s_hide_del_icon();
45
- grid_load_complete;
46
- },
47
28
  ```
48
29
 
49
- ```javascript
50
- loadComplete: async function(data)
51
- {
52
- await jqu.hide_del_icon();
53
- grid_load_complete;
54
- },
55
- ```
30
+
56
31
 
@@ -46,15 +46,22 @@ module.exports = class Vanilla_website_utils
46
46
  }
47
47
 
48
48
 
49
- s_grid_set_captain(_grid, data=[])
49
+ s_grid_set_caption(_grid, data=[])
50
50
  {
51
- this.grid_set_captain(_grid, data=[]);
51
+ this.grid_set_captionn(_grid, data=[]);
52
52
  }
53
53
 
54
54
  /**
55
55
  @alias module:Jqgrid_utils
56
+ @param {object} - gridobject;
57
+ @param {object} - grid data (optional);
58
+ @example
59
+ var jqu = new Jqgrid_utils();
60
+ loadComplete: function(){
61
+ jqu.grid_set_caption(this);
62
+ },
56
63
  */
57
- async grid_set_captain(_grid, data=[])
64
+ async grid_set_caption(_grid, data=[])
58
65
  {
59
66
  const grid = jQuery(_grid);
60
67
  let count = 0;
@@ -67,17 +74,18 @@ module.exports = class Vanilla_website_utils
67
74
  count = data.length;
68
75
  }
69
76
  let caption = grid.jqGrid("getGridParam", "caption");
70
- if(caption.indexOf(count+'x') === -1 )
71
- {
72
- grid.jqGrid('setCaption', caption + ' - ' + count + 'x');
77
+ const reg = /\d.*x/;
78
+ const new_caption = caption.replace(reg, "");
79
+ grid.jqGrid('setCaption', new_caption + count + 'x');
73
80
  }
74
- }
75
-
76
81
 
77
- s_resize_saved_cell_width(col_model, page=false, grid=false)
78
- {
79
- this.grid_set_captain(col_model, page, grid);
80
- }
82
+ /**
83
+ @alias module:Jqgrid_utils
84
+ */
85
+ s_resize_saved_cell_width(col_model, page=false, grid=false)
86
+ {
87
+ this.grid_set_caption(col_model, page, grid);
88
+ }
81
89
 
82
90
 
83
91
  /**
@@ -86,7 +94,7 @@ module.exports = class Vanilla_website_utils
86
94
  @param {string} - the name of the page(optional)
87
95
  @param {object} - the grid objec(optional)
88
96
  @example
89
- * col_model = await jqu.resize_saved_cell_width(col_model);
97
+ col_model = await jqu.resize_saved_cell_width(col_model);
90
98
  */
91
99
  async resize_saved_cell_width(col_model,page=false, grid=false)
92
100
  {
@@ -456,9 +464,9 @@ __cell_format(cell_value, format)
456
464
  @param {object} - col_model for the table
457
465
  @param {string} - Add to the caption of the subgrid
458
466
  @example
459
- * let data_url = api + '/phone_detail?f=data&_id=';
460
- * let col_model_url = api + '/phone_detail?f=col_model';
461
- * let col_model = JSON.parse(await vwu.aget_api(col_model_url))
467
+ let data_url = api + '/phone_detail?f=data&_id=';
468
+ let col_model_url = api + '/phone_detail?f=col_model';
469
+ let col_model = JSON.parse(await vwu.aget_api(col_model_url))
462
470
  */
463
471
  async subgrid(_id, id, data_url, col_model, caption='' )
464
472
  {
@@ -487,7 +495,7 @@ async subgrid(_id, id, data_url, col_model, caption='' )
487
495
  @param {int} - size of the picture
488
496
  @param {bolen} - image path should be a link
489
497
  @example
490
- * col_model = await jqu.add_image(col_model, 'image', 60, false);
498
+ col_model = await jqu.add_image(col_model, 'image', 60, false);
491
499
  */
492
500
  async add_image(col_model, edit_field, size, link=false)
493
501
  {
@@ -537,6 +545,116 @@ async add_image(col_model, edit_field, size, link=false)
537
545
 
538
546
 
539
547
 
548
+
549
+ /**
550
+ @alias module:Jqgrid_utils
551
+ @param {object} - grid object or grid string name
552
+ @param {object} - the grid data object
553
+ @param {object} - a dict with a array what should be filterd by the grid
554
+ @param {string} - id name of the DOM oject where the filter should be appened
555
+ @example
556
+ var jqu = new Jqgrid_utils();
557
+ var run_me_once = true;
558
+ gridComplete: async function(){
559
+ if(run_me_once)
560
+ {
561
+ await jqu.set_filter(this, data, {material:[],section:[]}, '#filter');
562
+ run_me_once = false;
563
+ }
564
+ },
565
+ */
566
+ async set_filter(grid, data, fx, append_to="#filter")
567
+ {
568
+ jQuery(grid).jqGrid('setGridParam', { fdata: data });
569
+ let f = document.querySelector(append_to);
570
+ for(const i in data)
571
+ {
572
+ for(let x in fx)
573
+ {
574
+ fx[x].push(data[i][x]);
575
+ }
576
+ }
577
+
578
+ for(let x in fx)
579
+ {
580
+ fx[x]= fx[x].filter((val, ind, arr) => arr.indexOf(val) === ind);
581
+ fx[x].sort();
582
+ }
583
+
584
+ for(let x in fx)
585
+ {
586
+ let ul = document.createElement('ul');
587
+ let lh = document.createElement('lh');
588
+ lh.innerHTML = x;
589
+ ul.appendChild(lh);
590
+ for(let i in fx[x])
591
+ {
592
+ let li = document.createElement('li');
593
+ let l = document.createElement('label');
594
+ l.innerHTML = fx[x][i];
595
+ let c = document.createElement('input');
596
+ c.setAttribute('type','checkbox');
597
+ c.setAttribute('class',x);
598
+ c.setAttribute('id', x + '_' + fx[x][i]);
599
+ l.setAttribute('for',x + '_' + fx[x][i]);
600
+ c.value = fx[x][i];
601
+ c.onchange = async () => { await this._filter(grid,fx);};
602
+ li.appendChild(l);
603
+ li.appendChild(c);
604
+ ul.appendChild(li);
605
+ }
606
+ f.appendChild(ul);
607
+ }
608
+ }
609
+
610
+
611
+ /**
612
+ @alias module:Jqgrid_utils
613
+ private function for set_filter
614
+ */
615
+ async _filter(grid, fx)
616
+ {
617
+ let _data = [];
618
+ let data = jQuery(grid).jqGrid('getGridParam','fdata');
619
+ let filter = [];
620
+ for(let x in fx)
621
+ {
622
+ let m = document.querySelectorAll("." + x);
623
+ filter[x] = [];
624
+ for(let i in m)
625
+ {
626
+ if(m[i].checked)
627
+ {
628
+ filter[x].push(m[i].value);
629
+ }
630
+ }
631
+ }
632
+ for(let i in data)
633
+ {
634
+ let include = false;
635
+ for(let x in fx)
636
+ {
637
+ if(filter[x].indexOf(data[i][x]) != -1)
638
+ {
639
+ include = true;
640
+ }
641
+ }
642
+ if(include)
643
+ {
644
+ _data.push(data[i]);
645
+ }
646
+ }
647
+ jQuery(grid).jqGrid('clearGridData');
648
+ jQuery(grid).jqGrid('setGridParam', {data: _data});
649
+ jQuery(grid).trigger('reloadGrid');
650
+ }
651
+
652
+
653
+
654
+
655
+
656
+
657
+
540
658
  };
541
659
 
542
660
 
package/jqgrid_utils.js CHANGED
@@ -45,15 +45,22 @@ module.exports = class Vanilla_website_utils
45
45
  }
46
46
 
47
47
 
48
- s_grid_set_captain(_grid, data=[])
48
+ s_grid_set_caption(_grid, data=[])
49
49
  {
50
- this.grid_set_captain(_grid, data=[]);
50
+ this.grid_set_captionn(_grid, data=[]);
51
51
  }
52
52
 
53
53
  /**
54
54
  @alias module:Jqgrid_utils
55
+ @param {object} - gridobject;
56
+ @param {object} - grid data (optional);
57
+ @example
58
+ var jqu = new Jqgrid_utils();
59
+ loadComplete: function(){
60
+ jqu.grid_set_caption(this);
61
+ },
55
62
  */
56
- async grid_set_captain(_grid, data=[])
63
+ async grid_set_caption(_grid, data=[])
57
64
  {
58
65
  const grid = jQuery(_grid);
59
66
  let count = 0;
@@ -66,17 +73,18 @@ module.exports = class Vanilla_website_utils
66
73
  count = data.length;
67
74
  }
68
75
  let caption = grid.jqGrid("getGridParam", "caption");
69
- if(caption.indexOf(count+'x') === -1 )
70
- {
71
- grid.jqGrid('setCaption', caption + ' - ' + count + 'x');
76
+ const reg = /\d.*x/;
77
+ const new_caption = caption.replace(reg, "");
78
+ grid.jqGrid('setCaption', new_caption + count + 'x');
72
79
  }
73
- }
74
-
75
80
 
76
- s_resize_saved_cell_width(col_model, page=false, grid=false)
77
- {
78
- this.grid_set_captain(col_model, page, grid);
79
- }
81
+ /**
82
+ @alias module:Jqgrid_utils
83
+ */
84
+ s_resize_saved_cell_width(col_model, page=false, grid=false)
85
+ {
86
+ this.grid_set_caption(col_model, page, grid);
87
+ }
80
88
 
81
89
 
82
90
  /**
@@ -85,7 +93,7 @@ module.exports = class Vanilla_website_utils
85
93
  @param {string} - the name of the page(optional)
86
94
  @param {object} - the grid objec(optional)
87
95
  @example
88
- * col_model = await jqu.resize_saved_cell_width(col_model);
96
+ col_model = await jqu.resize_saved_cell_width(col_model);
89
97
  */
90
98
  async resize_saved_cell_width(col_model,page=false, grid=false)
91
99
  {
@@ -455,9 +463,9 @@ __cell_format(cell_value, format)
455
463
  @param {object} - col_model for the table
456
464
  @param {string} - Add to the caption of the subgrid
457
465
  @example
458
- * let data_url = api + '/phone_detail?f=data&_id=';
459
- * let col_model_url = api + '/phone_detail?f=col_model';
460
- * let col_model = JSON.parse(await vwu.aget_api(col_model_url))
466
+ let data_url = api + '/phone_detail?f=data&_id=';
467
+ let col_model_url = api + '/phone_detail?f=col_model';
468
+ let col_model = JSON.parse(await vwu.aget_api(col_model_url))
461
469
  */
462
470
  async subgrid(_id, id, data_url, col_model, caption='' )
463
471
  {
@@ -486,7 +494,7 @@ async subgrid(_id, id, data_url, col_model, caption='' )
486
494
  @param {int} - size of the picture
487
495
  @param {bolen} - image path should be a link
488
496
  @example
489
- * col_model = await jqu.add_image(col_model, 'image', 60, false);
497
+ col_model = await jqu.add_image(col_model, 'image', 60, false);
490
498
  */
491
499
  async add_image(col_model, edit_field, size, link=false)
492
500
  {
@@ -536,6 +544,116 @@ async add_image(col_model, edit_field, size, link=false)
536
544
 
537
545
 
538
546
 
547
+
548
+ /**
549
+ @alias module:Jqgrid_utils
550
+ @param {object} - grid object or grid string name
551
+ @param {object} - the grid data object
552
+ @param {object} - a dict with a array what should be filterd by the grid
553
+ @param {string} - id name of the DOM oject where the filter should be appened
554
+ @example
555
+ var jqu = new Jqgrid_utils();
556
+ var run_me_once = true;
557
+ gridComplete: async function(){
558
+ if(run_me_once)
559
+ {
560
+ await jqu.set_filter(this, data, {material:[],section:[]}, '#filter');
561
+ run_me_once = false;
562
+ }
563
+ },
564
+ */
565
+ async set_filter(grid, data, fx, append_to="#filter")
566
+ {
567
+ jQuery(grid).jqGrid('setGridParam', { fdata: data });
568
+ let f = document.querySelector(append_to);
569
+ for(const i in data)
570
+ {
571
+ for(let x in fx)
572
+ {
573
+ fx[x].push(data[i][x]);
574
+ }
575
+ }
576
+
577
+ for(let x in fx)
578
+ {
579
+ fx[x]= fx[x].filter((val, ind, arr) => arr.indexOf(val) === ind);
580
+ fx[x].sort();
581
+ }
582
+
583
+ for(let x in fx)
584
+ {
585
+ let ul = document.createElement('ul');
586
+ let lh = document.createElement('lh');
587
+ lh.innerHTML = x;
588
+ ul.appendChild(lh);
589
+ for(let i in fx[x])
590
+ {
591
+ let li = document.createElement('li');
592
+ let l = document.createElement('label');
593
+ l.innerHTML = fx[x][i];
594
+ let c = document.createElement('input');
595
+ c.setAttribute('type','checkbox');
596
+ c.setAttribute('class',x);
597
+ c.setAttribute('id', x + '_' + fx[x][i]);
598
+ l.setAttribute('for',x + '_' + fx[x][i]);
599
+ c.value = fx[x][i];
600
+ c.onchange = async () => { await this._filter(grid,fx);};
601
+ li.appendChild(l);
602
+ li.appendChild(c);
603
+ ul.appendChild(li);
604
+ }
605
+ f.appendChild(ul);
606
+ }
607
+ }
608
+
609
+
610
+ /**
611
+ @alias module:Jqgrid_utils
612
+ private function for set_filter
613
+ */
614
+ async _filter(grid, fx)
615
+ {
616
+ let _data = [];
617
+ let data = jQuery(grid).jqGrid('getGridParam','fdata');
618
+ let filter = [];
619
+ for(let x in fx)
620
+ {
621
+ let m = document.querySelectorAll("." + x);
622
+ filter[x] = [];
623
+ for(let i in m)
624
+ {
625
+ if(m[i].checked)
626
+ {
627
+ filter[x].push(m[i].value);
628
+ }
629
+ }
630
+ }
631
+ for(let i in data)
632
+ {
633
+ let include = false;
634
+ for(let x in fx)
635
+ {
636
+ if(filter[x].indexOf(data[i][x]) != -1)
637
+ {
638
+ include = true;
639
+ }
640
+ }
641
+ if(include)
642
+ {
643
+ _data.push(data[i]);
644
+ }
645
+ }
646
+ jQuery(grid).jqGrid('clearGridData');
647
+ jQuery(grid).jqGrid('setGridParam', {data: _data});
648
+ jQuery(grid).trigger('reloadGrid');
649
+ }
650
+
651
+
652
+
653
+
654
+
655
+
656
+
539
657
  };
540
658
 
541
659
 
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.2.9"
32
+ "version": "1.2.12"
33
33
  }