jqgrid_utils 1.2.11 → 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
@@ -54,6 +54,7 @@ A module for Jqgrid_utils
54
54
  * [module.exports#__cell_format()](#exp_module_Jqgrid_utils--module.exports+__cell_format) ⏏
55
55
  * [module.exports#subgrid(_id, id, data_url, col_model, caption)](#exp_module_Jqgrid_utils--module.exports+subgrid) ⏏
56
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) ⏏
57
58
 
58
59
  <a name="exp_module_Jqgrid_utils--module.exports+set_link"></a>
59
60
 
@@ -198,3 +199,27 @@ let col_model = JSON.parse(await vwu.aget_api(col_model_url))
198
199
  ```js
199
200
  col_model = await jqu.add_image(col_model, 'image', 60, false);
200
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
+ ```
@@ -545,6 +545,116 @@ async add_image(col_model, edit_field, size, link=false)
545
545
 
546
546
 
547
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
+
548
658
  };
549
659
 
550
660
 
package/jqgrid_utils.js CHANGED
@@ -544,6 +544,116 @@ async add_image(col_model, edit_field, size, link=false)
544
544
 
545
545
 
546
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
+
547
657
  };
548
658
 
549
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.11"
32
+ "version": "1.2.12"
33
33
  }