jqgrid_utils 1.6.0 → 1.8.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.
@@ -101,7 +101,32 @@ var jqu = new Jqgrid_utils();
101
101
  return col_model;
102
102
  }
103
103
 
104
+ /**
105
+ * Replace a Binaery 0 or 1 to other given value
106
+ @alias module:Jqgrid_utils
107
+ @param {string} - cell value
108
+ @param {string} - string replacement for 0
109
+ @param {string} - string replacement for 1
110
+ @example
111
+ var jqu = new Jqgrid_utils();
112
+ let _data = jqu.binery_replace(0,'zero','one');
113
+ or for column formatter
114
+ download_formatter:"var jqu = new Jqgrid_utils();jqu.binary_replace({0},'zero','one')"});
115
+ */
116
+ binary_replace(cell_value, a='zero',b='one')
117
+ {
118
+ let value = a;
119
+ if(cell_value == 1 || cell_value == 0 )
120
+ {
121
+ if(cell_value == 1)
122
+ {
123
+ value = b;
124
+ }
125
+ }
126
+ return value;
127
+ }
104
128
 
129
+
105
130
  /**
106
131
  * Convert a 112 date string to a DMY format with sepertaor - sync function
107
132
  @alias module:Jqgrid_utils
@@ -170,7 +195,36 @@ console.log(_data);
170
195
  return col_model;
171
196
  }
172
197
 
198
+ /**
199
+ * Add Formatter
200
+ @alias module:Jqgrid_utils
201
+ @param {array} - grid col_model
202
+ @param {string} - string columns names what will be formatted
203
+ @param {object} - formatter object like { formatter: "select", formatoptions: {value: "1:ok;0:fail", defaultValue: "1" }}
204
+ @example
205
+ var jqu = new Jqgrid_utils();
206
+ col_model = await jqu.add_formatter(col_model,'select',{ formatter: "select", formatoptions: {value: "1:ok;0:fail", defaultValue: "1" }})
207
+ */
208
+
209
+ async add_formatter(col_model,edit_field, formatter)
210
+ {
211
+ for(let i=0;i< col_model.length;i++)
212
+ {
213
+ if(col_model[i]['name'] === edit_field)
214
+ {
215
+ if(formatter.hasOwnProperty('formatter') && formatter.hasOwnProperty('formatoptions'))
216
+ {
217
+ col_model[i]['formatter'] = formatter['formatter'];
218
+ col_model[i]['formatoptions'] = formatter['formatoptions'];
219
+ col_model[i]['edittype'] = formatter['formatter'];
220
+ col_model[i]['editoptions'] = formatter['formatoptions'];
221
+ }
222
+ }
223
+ }
224
+ return col_model;
225
+ }
173
226
 
227
+
174
228
  /**
175
229
  * Add HTML Formatter
176
230
  @alias module:Jqgrid_utils
package/jqgrid_utils.js CHANGED
@@ -100,7 +100,32 @@ var jqu = new Jqgrid_utils();
100
100
  return col_model;
101
101
  }
102
102
 
103
+ /**
104
+ * Replace a Binaery 0 or 1 to other given value
105
+ @alias module:Jqgrid_utils
106
+ @param {string} - cell value
107
+ @param {string} - string replacement for 0
108
+ @param {string} - string replacement for 1
109
+ @example
110
+ var jqu = new Jqgrid_utils();
111
+ let _data = jqu.binery_replace(0,'zero','one');
112
+ or for column formatter
113
+ download_formatter:"var jqu = new Jqgrid_utils();jqu.binary_replace({0},'zero','one')"});
114
+ */
115
+ binary_replace(cell_value, a='zero',b='one')
116
+ {
117
+ let value = a;
118
+ if(cell_value == 1 || cell_value == 0 )
119
+ {
120
+ if(cell_value == 1)
121
+ {
122
+ value = b;
123
+ }
124
+ }
125
+ return value;
126
+ }
103
127
 
128
+
104
129
  /**
105
130
  * Convert a 112 date string to a DMY format with sepertaor - sync function
106
131
  @alias module:Jqgrid_utils
@@ -169,7 +194,36 @@ console.log(_data);
169
194
  return col_model;
170
195
  }
171
196
 
197
+ /**
198
+ * Add Formatter
199
+ @alias module:Jqgrid_utils
200
+ @param {array} - grid col_model
201
+ @param {string} - string columns names what will be formatted
202
+ @param {object} - formatter object like { formatter: "select", formatoptions: {value: "1:ok;0:fail", defaultValue: "1" }}
203
+ @example
204
+ var jqu = new Jqgrid_utils();
205
+ col_model = await jqu.add_formatter(col_model,'select',{ formatter: "select", formatoptions: {value: "1:ok;0:fail", defaultValue: "1" }})
206
+ */
207
+
208
+ async add_formatter(col_model,edit_field, formatter)
209
+ {
210
+ for(let i=0;i< col_model.length;i++)
211
+ {
212
+ if(col_model[i]['name'] === edit_field)
213
+ {
214
+ if(formatter.hasOwnProperty('formatter') && formatter.hasOwnProperty('formatoptions'))
215
+ {
216
+ col_model[i]['formatter'] = formatter['formatter'];
217
+ col_model[i]['formatoptions'] = formatter['formatoptions'];
218
+ col_model[i]['edittype'] = formatter['formatter'];
219
+ col_model[i]['editoptions'] = formatter['formatoptions'];
220
+ }
221
+ }
222
+ }
223
+ return col_model;
224
+ }
172
225
 
226
+
173
227
  /**
174
228
  * Add HTML Formatter
175
229
  @alias module:Jqgrid_utils
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.6.0"
32
+ "version": "1.8.0"
33
33
  }