jqgrid_utils 1.2.10 → 1.2.14

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
 
@@ -79,6 +54,8 @@ A module for Jqgrid_utils
79
54
  * [module.exports#__cell_format()](#exp_module_Jqgrid_utils--module.exports+__cell_format) ⏏
80
55
  * [module.exports#subgrid(_id, id, data_url, col_model, caption)](#exp_module_Jqgrid_utils--module.exports+subgrid) ⏏
81
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) ⏏
58
+ * [module.exports#_filter()](#exp_module_Jqgrid_utils--module.exports+_filter) ⏏
82
59
 
83
60
  <a name="exp_module_Jqgrid_utils--module.exports+set_link"></a>
84
61
 
@@ -223,3 +200,35 @@ let col_model = JSON.parse(await vwu.aget_api(col_model_url))
223
200
  ```js
224
201
  col_model = await jqu.add_image(col_model, 'image', 60, false);
225
202
  ```
203
+ <a name="exp_module_Jqgrid_utils--module.exports+set_filter"></a>
204
+
205
+ ### module.exports#set\_filter(grid, data, fx, append_to) ⏏
206
+ Add a filter to the website beside the grid
207
+
208
+ **Kind**: Exported function
209
+
210
+ | Param | Type | Default | Description |
211
+ | --- | --- | --- | --- |
212
+ | grid | <code>object</code> | | grid object or grid string name |
213
+ | data | <code>object</code> | | the grid data object |
214
+ | fx | <code>object</code> | | a dict with a array what should be filterd by the grid |
215
+ | append_to | <code>string</code> | <code>&quot;#filter&quot;</code> | id name of the DOM oject where the filter should be appened |
216
+
217
+ **Example**
218
+ ```js
219
+ var jqu = new Jqgrid_utils();
220
+ var run_me_once = true;
221
+ gridComplete: async function(){
222
+ if(run_me_once)
223
+ {
224
+ await jqu.set_filter(this, data, {material:[],section:[]}, '#filter');
225
+ run_me_once = false;
226
+ }
227
+ },
228
+ ```
229
+ <a name="exp_module_Jqgrid_utils--module.exports+_filter"></a>
230
+
231
+ ### module.exports#\_filter() ⏏
232
+ private function of set_filter
233
+
234
+ **Kind**: Exported function
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
 
@@ -84,7 +84,7 @@ loadComplete: function(){
84
84
  */
85
85
  s_resize_saved_cell_width(col_model, page=false, grid=false)
86
86
  {
87
- this.grid_set_captain(col_model, page, grid);
87
+ this.grid_set_caption(col_model, page, grid);
88
88
  }
89
89
 
90
90
 
@@ -545,6 +545,117 @@ async add_image(col_model, edit_field, size, link=false)
545
545
 
546
546
 
547
547
 
548
+
549
+ /**
550
+ * Add a filter to the website beside the grid
551
+ @alias module:Jqgrid_utils
552
+ @param {object} - grid object or grid string name
553
+ @param {object} - the grid data object
554
+ @param {object} - a dict with a array what should be filterd by the grid
555
+ @param {string} - id name of the DOM oject where the filter should be appened
556
+ @example
557
+ var jqu = new Jqgrid_utils();
558
+ var run_me_once = true;
559
+ gridComplete: async function(){
560
+ if(run_me_once)
561
+ {
562
+ await jqu.set_filter(this, data, {material:[],section:[]}, '#filter');
563
+ run_me_once = false;
564
+ }
565
+ },
566
+ */
567
+ async set_filter(grid, data, fx, append_to="#filter")
568
+ {
569
+ jQuery(grid).jqGrid('setGridParam', { fdata: data });
570
+ let f = document.querySelector(append_to);
571
+ for(const i in data)
572
+ {
573
+ for(let x in fx)
574
+ {
575
+ fx[x].push(data[i][x]);
576
+ }
577
+ }
578
+
579
+ for(let x in fx)
580
+ {
581
+ fx[x]= fx[x].filter((val, ind, arr) => arr.indexOf(val) === ind);
582
+ fx[x].sort();
583
+ }
584
+
585
+ for(let x in fx)
586
+ {
587
+ let ul = document.createElement('ul');
588
+ let lh = document.createElement('lh');
589
+ lh.innerHTML = x;
590
+ ul.appendChild(lh);
591
+ for(let i in fx[x])
592
+ {
593
+ let li = document.createElement('li');
594
+ let l = document.createElement('label');
595
+ l.innerHTML = fx[x][i];
596
+ let c = document.createElement('input');
597
+ c.setAttribute('type','checkbox');
598
+ c.setAttribute('class',x);
599
+ c.setAttribute('id', x + '_' + fx[x][i]);
600
+ l.setAttribute('for',x + '_' + fx[x][i]);
601
+ c.value = fx[x][i];
602
+ c.onchange = async () => { await this._filter(grid,fx);};
603
+ li.appendChild(l);
604
+ li.appendChild(c);
605
+ ul.appendChild(li);
606
+ }
607
+ f.appendChild(ul);
608
+ }
609
+ }
610
+
611
+
612
+ /**
613
+ * private function of set_filter
614
+ @alias module:Jqgrid_utils
615
+ */
616
+ async _filter(grid, fx)
617
+ {
618
+ let _data = [];
619
+ let data = jQuery(grid).jqGrid('getGridParam','fdata');
620
+ let filter = [];
621
+ for(let x in fx)
622
+ {
623
+ let m = document.querySelectorAll("." + x);
624
+ filter[x] = [];
625
+ for(let i in m)
626
+ {
627
+ if(m[i].checked)
628
+ {
629
+ filter[x].push(m[i].value);
630
+ }
631
+ }
632
+ }
633
+ for(let i in data)
634
+ {
635
+ let include = false;
636
+ for(let x in fx)
637
+ {
638
+ if(filter[x].indexOf(data[i][x]) != -1)
639
+ {
640
+ include = true;
641
+ }
642
+ }
643
+ if(include)
644
+ {
645
+ _data.push(data[i]);
646
+ }
647
+ }
648
+ jQuery(grid).jqGrid('clearGridData');
649
+ jQuery(grid).jqGrid('setGridParam', {data: _data});
650
+ jQuery(grid).trigger('reloadGrid');
651
+ }
652
+
653
+
654
+
655
+
656
+
657
+
658
+
548
659
  };
549
660
 
550
661
 
package/jqgrid_utils.js CHANGED
@@ -83,7 +83,7 @@ loadComplete: function(){
83
83
  */
84
84
  s_resize_saved_cell_width(col_model, page=false, grid=false)
85
85
  {
86
- this.grid_set_captain(col_model, page, grid);
86
+ this.grid_set_caption(col_model, page, grid);
87
87
  }
88
88
 
89
89
 
@@ -544,6 +544,117 @@ async add_image(col_model, edit_field, size, link=false)
544
544
 
545
545
 
546
546
 
547
+
548
+ /**
549
+ * Add a filter to the website beside the grid
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
+ * private function of set_filter
613
+ @alias module:Jqgrid_utils
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
+
547
658
  };
548
659
 
549
660
 
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.10"
32
+ "version": "1.2.14"
33
33
  }