jqgrid_utils 1.5.0 → 1.5.3

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,7 @@ A module for Jqgrid_utils
27
27
 
28
28
 
29
29
  * [Jqgrid_utils](#module_Jqgrid_utils)
30
+ * [module.exports#get_col_model_from_data(obj, data, exclude, col_model)](#exp_module_Jqgrid_utils--module.exports+get_col_model_from_data) ⇒ <code>array</code> ⏏
30
31
  * [module.exports#_date112_to_DMY(cell_value, seperator)](#exp_module_Jqgrid_utils--module.exports+_date112_to_DMY) ⏏
31
32
  * [module.exports#date112_to_DMY(col_model, edit_field, seperator)](#exp_module_Jqgrid_utils--module.exports+date112_to_DMY) ⏏
32
33
  * [module.exports#add_ok_button(col_model, fields)](#exp_module_Jqgrid_utils--module.exports+add_ok_button) ⇒ <code>array</code> ⏏
@@ -57,6 +58,31 @@ A module for Jqgrid_utils
57
58
  * [module.exports#set_filter(grid, data, fx, append_to)](#exp_module_Jqgrid_utils--module.exports+set_filter) ⏏
58
59
  * [module.exports#_filter()](#exp_module_Jqgrid_utils--module.exports+_filter) ⏏
59
60
 
61
+ <a name="exp_module_Jqgrid_utils--module.exports+get_col_model_from_data"></a>
62
+
63
+ ### module.exports#get\_col\_model\_from\_data(obj, data, exclude, col_model) ⇒ <code>array</code> ⏏
64
+ Get basic colModel data from raw data
65
+
66
+ **Kind**: Exported function
67
+ **Returns**: <code>array</code> - - col_model
68
+
69
+ | Param | Type | Description |
70
+ | --- | --- | --- |
71
+ | obj | <code>array</code> | grid object |
72
+ | data | <code>array</code> | raw data object from loadComplete |
73
+ | exclude | <code>array</code> | list of columns to exclude (optional) |
74
+ | col_model | <code>array</code> | existing colModel (optional) |
75
+
76
+ **Example**
77
+ ```js
78
+ var jqu = new Jqgrid_utils();
79
+ ,loadComplete: async function(data)
80
+ {
81
+ let col_model = jQuery(this).jqGrid('getGridParam',"colModel");
82
+ const new_col_model= await update_col_model(this, data, ['id','cust_qty','waiting_supplier_orders','waiting_assemblies','pending_components','pending_customer_order',col_model);
83
+ jQuery(this).jqGrid('setGridParam',{colModel:new_col_model});
84
+ },
85
+ ```
60
86
  <a name="exp_module_Jqgrid_utils--module.exports+_date112_to_DMY"></a>
61
87
 
62
88
  ### module.exports#\_date112\_to\_DMY(cell_value, seperator) ⏏
@@ -22,6 +22,56 @@ module.exports = class Vanilla_website_utils
22
22
 
23
23
  }
24
24
 
25
+ /**
26
+ * Get basic colModel data from raw data
27
+ @alias module:Jqgrid_utils
28
+ @param {array} - grid object
29
+ @param {array} - raw data object from loadComplete
30
+ @param {array} - list of columns to exclude (optional)
31
+ @param {array} - existing colModel (optional)
32
+ @returns {array} - col_model
33
+ @example
34
+ var jqu = new Jqgrid_utils();
35
+ ,loadComplete: async function(data)
36
+ {
37
+ let col_model = jQuery(this).jqGrid('getGridParam',"colModel");
38
+ const new_col_model= await update_col_model(this, data, ['id','cust_qty','waiting_supplier_orders','waiting_assemblies','pending_components','pending_customer_order',col_model);
39
+ jQuery(this).jqGrid('setGridParam',{colModel:new_col_model});
40
+ },
41
+ */
42
+ async get_col_model_from_data(obj, data, exclude=[],col_model=[])
43
+ {
44
+ let cols = [];
45
+ for(let i in data)
46
+ {
47
+ const keys = Object.keys(data[i]);
48
+ for(let ii in keys)
49
+ {
50
+ const key = keys[ii];
51
+ cols.push(key);
52
+ }
53
+ }
54
+ cols = cols.filter((item, pos) => cols.indexOf(item) === pos);
55
+ let mcols = [];
56
+ for(let i in col_model)
57
+ {
58
+ mcols.push(col_model[i]['name']);
59
+ }
60
+
61
+
62
+ let diff = cols.filter(x => !mcols.includes(x));
63
+ const _exclude = new Set(exclude);
64
+ diff = diff.filter((name) => {return !_exclude.has(name); });
65
+ diff.sort();
66
+
67
+ for(let x=0; x < diff.length; x++)
68
+ {
69
+ col_model.push({'name': diff[x],'label': diff[x]});
70
+ }
71
+ //console.log(col_model);
72
+ return col_model;
73
+ }
74
+
25
75
 
26
76
  /**
27
77
  * Convert a 112 date string to a DMY format with sepertaor - sync function
@@ -67,6 +117,7 @@ console.log(_data);
67
117
  {
68
118
  col_model[i]['formatter'] = function (cell_value, o)
69
119
  {
120
+ cell_value = cell_value.toString();
70
121
  let value = cell_value;
71
122
  if(cell_value.length >= 8 && cell_value.indexOf(seperator) === -1)
72
123
  {
@@ -677,15 +728,19 @@ async add_link_details(col_model, url, edit_field, attr = '', keys, format)
677
728
  {
678
729
  pref = pref.slice(0, -1);
679
730
  }
680
-
681
- const _cell_val = self.__cell_format(cell_val, format);
682
-
683
- cell_val = '<a ' + attr + 'href="' + url + pref + '"> ' + _cell_val + '</a>';
731
+ const _cell_val = self.__cell_format(cell_val, format);
732
+ cell_val = '<a ' + attr + 'href="' + url + pref + '"> ' + _cell_val + '</a>';
684
733
  }
685
734
 
686
735
  }
687
-
688
- return cell_val;
736
+ if(cell_val)
737
+ {
738
+ return cell_val;
739
+ }
740
+ else
741
+ {
742
+ return '';
743
+ }
689
744
  };
690
745
  }
691
746
 
package/jqgrid_utils.js CHANGED
@@ -21,6 +21,56 @@ module.exports = class Vanilla_website_utils
21
21
 
22
22
  }
23
23
 
24
+ /**
25
+ * Get basic colModel data from raw data
26
+ @alias module:Jqgrid_utils
27
+ @param {array} - grid object
28
+ @param {array} - raw data object from loadComplete
29
+ @param {array} - list of columns to exclude (optional)
30
+ @param {array} - existing colModel (optional)
31
+ @returns {array} - col_model
32
+ @example
33
+ var jqu = new Jqgrid_utils();
34
+ ,loadComplete: async function(data)
35
+ {
36
+ let col_model = jQuery(this).jqGrid('getGridParam',"colModel");
37
+ const new_col_model= await update_col_model(this, data, ['id','cust_qty','waiting_supplier_orders','waiting_assemblies','pending_components','pending_customer_order',col_model);
38
+ jQuery(this).jqGrid('setGridParam',{colModel:new_col_model});
39
+ },
40
+ */
41
+ async get_col_model_from_data(obj, data, exclude=[],col_model=[])
42
+ {
43
+ let cols = [];
44
+ for(let i in data)
45
+ {
46
+ const keys = Object.keys(data[i]);
47
+ for(let ii in keys)
48
+ {
49
+ const key = keys[ii];
50
+ cols.push(key);
51
+ }
52
+ }
53
+ cols = cols.filter((item, pos) => cols.indexOf(item) === pos);
54
+ let mcols = [];
55
+ for(let i in col_model)
56
+ {
57
+ mcols.push(col_model[i]['name']);
58
+ }
59
+
60
+
61
+ let diff = cols.filter(x => !mcols.includes(x));
62
+ const _exclude = new Set(exclude);
63
+ diff = diff.filter((name) => {return !_exclude.has(name); });
64
+ diff.sort();
65
+
66
+ for(let x=0; x < diff.length; x++)
67
+ {
68
+ col_model.push({'name': diff[x],'label': diff[x]});
69
+ }
70
+ //console.log(col_model);
71
+ return col_model;
72
+ }
73
+
24
74
 
25
75
  /**
26
76
  * Convert a 112 date string to a DMY format with sepertaor - sync function
@@ -66,6 +116,7 @@ console.log(_data);
66
116
  {
67
117
  col_model[i]['formatter'] = function (cell_value, o)
68
118
  {
119
+ cell_value = cell_value.toString();
69
120
  let value = cell_value;
70
121
  if(cell_value.length >= 8 && cell_value.indexOf(seperator) === -1)
71
122
  {
@@ -676,15 +727,19 @@ async add_link_details(col_model, url, edit_field, attr = '', keys, format)
676
727
  {
677
728
  pref = pref.slice(0, -1);
678
729
  }
679
-
680
- const _cell_val = self.__cell_format(cell_val, format);
681
-
682
- cell_val = '<a ' + attr + 'href="' + url + pref + '"> ' + _cell_val + '</a>';
730
+ const _cell_val = self.__cell_format(cell_val, format);
731
+ cell_val = '<a ' + attr + 'href="' + url + pref + '"> ' + _cell_val + '</a>';
683
732
  }
684
733
 
685
734
  }
686
-
687
- return cell_val;
735
+ if(cell_val)
736
+ {
737
+ return cell_val;
738
+ }
739
+ else
740
+ {
741
+ return '';
742
+ }
688
743
  };
689
744
  }
690
745
 
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.5.0"
32
+ "version": "1.5.3"
33
33
  }