rails_jq_grid 0.0.3.pre2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/VERSION +1 -1
  2. data/public/javascripts/rails-jqgrid/Changes.txt +0 -0
  3. data/public/javascripts/rails-jqgrid/i18n/grid.locale-bg.js +132 -1
  4. data/public/javascripts/rails-jqgrid/i18n/grid.locale-bg1251.js +132 -1
  5. data/public/javascripts/rails-jqgrid/i18n/grid.locale-cat.js +128 -1
  6. data/public/javascripts/rails-jqgrid/i18n/grid.locale-cn.js +132 -1
  7. data/public/javascripts/rails-jqgrid/i18n/grid.locale-cs.js +128 -1
  8. data/public/javascripts/rails-jqgrid/i18n/grid.locale-da.js +128 -0
  9. data/public/javascripts/rails-jqgrid/i18n/grid.locale-de.js +133 -1
  10. data/public/javascripts/rails-jqgrid/i18n/grid.locale-el.js +126 -1
  11. data/public/javascripts/rails-jqgrid/i18n/grid.locale-en.js +128 -1
  12. data/public/javascripts/rails-jqgrid/i18n/grid.locale-es.js +128 -1
  13. data/public/javascripts/rails-jqgrid/i18n/grid.locale-fa.js +145 -1
  14. data/public/javascripts/rails-jqgrid/i18n/grid.locale-fi.js +130 -1
  15. data/public/javascripts/rails-jqgrid/i18n/grid.locale-fr.js +126 -1
  16. data/public/javascripts/rails-jqgrid/i18n/grid.locale-gl.js +126 -0
  17. data/public/javascripts/rails-jqgrid/i18n/grid.locale-he.js +127 -1
  18. data/public/javascripts/rails-jqgrid/i18n/grid.locale-hu.js +129 -1
  19. data/public/javascripts/rails-jqgrid/i18n/grid.locale-is.js +126 -1
  20. data/public/javascripts/rails-jqgrid/i18n/grid.locale-it.js +1 -1
  21. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ja.js +155 -1
  22. data/public/javascripts/rails-jqgrid/i18n/grid.locale-nl.js +149 -1
  23. data/public/javascripts/rails-jqgrid/i18n/grid.locale-no.js +1 -1
  24. data/public/javascripts/rails-jqgrid/i18n/grid.locale-pl.js +127 -1
  25. data/public/javascripts/rails-jqgrid/i18n/grid.locale-pt-br.js +127 -1
  26. data/public/javascripts/rails-jqgrid/i18n/grid.locale-pt.js +125 -1
  27. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ro.js +139 -1
  28. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ru.js +127 -1
  29. data/public/javascripts/rails-jqgrid/i18n/grid.locale-sk.js +127 -1
  30. data/public/javascripts/rails-jqgrid/i18n/grid.locale-sr.js +128 -0
  31. data/public/javascripts/rails-jqgrid/i18n/grid.locale-sv.js +127 -1
  32. data/public/javascripts/rails-jqgrid/i18n/grid.locale-tr.js +126 -1
  33. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ua.js +127 -1
  34. data/public/javascripts/rails-jqgrid/install.txt +0 -0
  35. data/public/javascripts/rails-jqgrid/jquery.jqGrid.min.js +445 -432
  36. data/public/javascripts/rails-jqgrid/src/JsonXml.js +329 -329
  37. data/public/javascripts/rails-jqgrid/src/css/ellipsis-xbl.xml +0 -0
  38. data/public/javascripts/rails-jqgrid/src/css/ui.jqgrid.css +139 -129
  39. data/public/javascripts/rails-jqgrid/src/css/ui.multiselect.css +0 -0
  40. data/public/javascripts/rails-jqgrid/src/grid.base.js +3078 -3003
  41. data/public/javascripts/rails-jqgrid/src/grid.celledit.js +486 -486
  42. data/public/javascripts/rails-jqgrid/src/grid.common.js +646 -636
  43. data/public/javascripts/rails-jqgrid/src/grid.custom.js +820 -817
  44. data/public/javascripts/rails-jqgrid/src/grid.formedit.js +1954 -1872
  45. data/public/javascripts/rails-jqgrid/src/grid.grouping.js +250 -0
  46. data/public/javascripts/rails-jqgrid/src/grid.import.js +200 -200
  47. data/public/javascripts/rails-jqgrid/src/grid.inlinedit.js +255 -250
  48. data/public/javascripts/rails-jqgrid/src/grid.jqueryui.js +504 -503
  49. data/public/javascripts/rails-jqgrid/src/grid.loader.js +1 -0
  50. data/public/javascripts/rails-jqgrid/src/grid.postext.js +63 -63
  51. data/public/javascripts/rails-jqgrid/src/grid.setcolumns.js +125 -125
  52. data/public/javascripts/rails-jqgrid/src/grid.subgrid.js +260 -260
  53. data/public/javascripts/rails-jqgrid/src/grid.tbltogrid.js +106 -106
  54. data/public/javascripts/rails-jqgrid/src/grid.treegrid.js +489 -482
  55. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-bg.js +132 -132
  56. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-bg1251.js +132 -132
  57. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cat.js +128 -128
  58. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cn.js +132 -132
  59. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cs.js +128 -128
  60. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-da.js +128 -0
  61. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-de.js +132 -127
  62. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-dk.js +0 -0
  63. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-el.js +126 -126
  64. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-en.js +128 -128
  65. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-es.js +128 -128
  66. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fa.js +145 -125
  67. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fi.js +130 -130
  68. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fr.js +2 -2
  69. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-gl.js +126 -0
  70. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-he.js +127 -127
  71. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-hu.js +129 -129
  72. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-is.js +126 -126
  73. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-it.js +0 -0
  74. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ja.js +155 -155
  75. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-nl.js +148 -148
  76. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-no.js +0 -0
  77. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pl.js +126 -126
  78. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pt-br.js +127 -127
  79. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pt.js +125 -125
  80. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ro.js +139 -139
  81. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ru.js +127 -127
  82. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-sk.js +127 -127
  83. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-sr.js +128 -0
  84. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-sv.js +127 -127
  85. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-tr.js +126 -126
  86. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ua.js +127 -127
  87. data/public/javascripts/rails-jqgrid/src/jqDnR.js +68 -67
  88. data/public/javascripts/rails-jqgrid/src/jqModal.js +68 -68
  89. data/public/javascripts/rails-jqgrid/src/jquery.fmatter.js +563 -541
  90. data/public/javascripts/rails-jqgrid/src/jquery.searchFilter.js +1 -1
  91. data/public/javascripts/rails-jqgrid/src/ui.multiselect.js +0 -0
  92. data/public/stylesheets/rails-jqgrid/ellipsis-xbl.xml +0 -0
  93. data/public/stylesheets/rails-jqgrid/ui.jqgrid.css +139 -2
  94. data/rails_jq_grid.gemspec +10 -3
  95. metadata +15 -11
@@ -1,818 +1,821 @@
1
- ;(function($){
2
- /**
3
- * jqGrid extension for custom methods
4
- * Tony Tomov tony@trirand.com
5
- * http://trirand.com/blog/
6
- * Dual licensed under the MIT and GPL licenses:
7
- * http://www.opensource.org/licenses/mit-license.php
8
- * http://www.gnu.org/licenses/gpl-2.0.html
9
- **/
10
- $.jgrid.extend({
11
- getColProp : function(colname){
12
- var ret ={}, $t = this[0];
13
- if ( !$t.grid ) { return; }
14
- var cM = $t.p.colModel;
15
- for ( var i =0;i<cM.length;i++ ) {
16
- if ( cM[i].name == colname ) {
17
- ret = cM[i];
18
- break;
19
- }
20
- }
21
- return ret;
22
- },
23
- setColProp : function(colname, obj){
24
- //do not set width will not work
25
- return this.each(function(){
26
- if ( this.grid ) {
27
- if ( obj ) {
28
- var cM = this.p.colModel;
29
- for ( var i =0;i<cM.length;i++ ) {
30
- if ( cM[i].name == colname ) {
31
- $.extend(this.p.colModel[i],obj);
32
- break;
33
- }
34
- }
35
- }
36
- }
37
- });
38
- },
39
- sortGrid : function(colname,reload, sor){
40
- return this.each(function(){
41
- var $t=this,idx=-1;
42
- if ( !$t.grid ) { return;}
43
- if ( !colname ) { colname = $t.p.sortname; }
44
- for ( var i=0;i<$t.p.colModel.length;i++ ) {
45
- if ( $t.p.colModel[i].index == colname || $t.p.colModel[i].name==colname ) {
46
- idx = i;
47
- break;
48
- }
49
- }
50
- if ( idx!=-1 ){
51
- var sort = $t.p.colModel[idx].sortable;
52
- if ( typeof sort !== 'boolean' ) { sort = true; }
53
- if ( typeof reload !=='boolean' ) { reload = false; }
54
- if ( sort ) { $t.sortData("jqgh_"+colname, idx, reload, sor); }
55
- }
56
- });
57
- },
58
- GridDestroy : function () {
59
- return this.each(function(){
60
- if ( this.grid ) {
61
- if ( this.p.pager ) { // if not part of grid
62
- $(this.p.pager).remove();
63
- }
64
- var gid = this.id;
65
- try {
66
- $("#gbox_"+gid).remove();
67
- } catch (_) {}
68
- }
69
- });
70
- },
71
- GridUnload : function(){
72
- return this.each(function(){
73
- if ( !this.grid ) {return;}
74
- var defgrid = {id: $(this).attr('id'),cl: $(this).attr('class')};
75
- if (this.p.pager) {
76
- $(this.p.pager).empty().removeClass("ui-state-default ui-jqgrid-pager corner-bottom");
77
- }
78
- var newtable = document.createElement('table');
79
- $(newtable).attr({id:defgrid.id});
80
- newtable.className = defgrid.cl;
81
- var gid = this.id;
82
- $(newtable).removeClass("ui-jqgrid-btable");
83
- if( $(this.p.pager).parents("#gbox_"+gid).length === 1 ) {
84
- $(newtable).insertBefore("#gbox_"+gid).show();
85
- $(this.p.pager).insertBefore("#gbox_"+gid);
86
- } else {
87
- $(newtable).insertBefore("#gbox_"+gid).show();
88
- }
89
- $("#gbox_"+gid).remove();
90
- });
91
- },
92
- setGridState : function(state) {
93
- return this.each(function(){
94
- if ( !this.grid ) {return;}
95
- var $t = this;
96
- if(state == 'hidden'){
97
- $(".ui-jqgrid-bdiv, .ui-jqgrid-hdiv","#gview_"+$t.p.id).slideUp("fast");
98
- if($t.p.pager) {$($t.p.pager).slideUp("fast");}
99
- if($t.p.toppager) {$($t.p.toppager).slideUp("fast");}
100
- if($t.p.toolbar[0]===true) {
101
- if( $t.p.toolbar[1]=='both') {
102
- $($t.grid.ubDiv).slideUp("fast");
103
- }
104
- $($t.grid.uDiv).slideUp("fast");
105
- }
106
- if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$t.p.id).slideUp("fast"); }
107
- $(".ui-jqgrid-titlebar-close span",$t.grid.cDiv).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s");
108
- $t.p.gridstate = 'hidden';
109
- } else if(state=='visible') {
110
- $(".ui-jqgrid-hdiv, .ui-jqgrid-bdiv","#gview_"+$t.p.id).slideDown("fast");
111
- if($t.p.pager) {$($t.p.pager).slideDown("fast");}
112
- if($t.p.toppager) {$($t.p.toppager).slideDown("fast");}
113
- if($t.p.toolbar[0]===true) {
114
- if( $t.p.toolbar[1]=='both') {
115
- $($t.grid.ubDiv).slideDown("fast");
116
- }
117
- $($t.grid.uDiv).slideDown("fast");
118
- }
119
- if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$t.p.id).slideDown("fast"); }
120
- $(".ui-jqgrid-titlebar-close span",$t.grid.cDiv).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n");
121
- $t.p.gridstate = 'visible';
122
- }
123
-
124
- });
125
- },
126
- updateGridRows : function (data, rowidname, jsonreader) {
127
- var nm, success=false, title;
128
- this.each(function(){
129
- var t = this, vl, ind, srow, sid;
130
- if(!t.grid) {return false;}
131
- if(!rowidname) { rowidname = "id"; }
132
- if( data && data.length >0 ) {
133
- $(data).each(function(j){
134
- srow = this;
135
- ind = t.rows.namedItem(srow[rowidname]);
136
- if(ind) {
137
- sid = srow[rowidname];
138
- if(jsonreader === true){
139
- if(t.p.jsonReader.repeatitems === true) {
140
- if(t.p.jsonReader.cell) {srow = srow[t.p.jsonReader.cell];}
141
- for (var k=0;k<srow.length;k++) {
142
- vl = t.formatter( sid, srow[k], k, srow, 'edit');
143
- title = t.p.colModel[k].title ? {"title":$.jgrid.stripHtml(vl)} : {};
144
- if(t.p.treeGrid===true && nm == t.p.ExpandColumn) {
145
- $("td:eq("+k+") > span:first",ind).html(vl).attr(title);
146
- } else {
147
- $("td:eq("+k+")",ind).html(vl).attr(title);
148
- }
149
- }
150
- success = true;
151
- return true;
152
- }
153
- }
154
- $(t.p.colModel).each(function(i){
155
- nm = jsonreader===true ? this.jsonmap || this.name :this.name;
156
- if( srow[nm] !== undefined) {
157
- vl = t.formatter( sid, srow[nm], i, srow, 'edit');
158
- title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
159
- if(t.p.treeGrid===true && nm == t.p.ExpandColumn) {
160
- $("td:eq("+i+") > span:first",ind).html(vl).attr(title);
161
- } else {
162
- $("td:eq("+i+")",ind).html(vl).attr(title);
163
- }
164
- success = true;
165
- }
166
- });
167
- }
168
- });
169
- }
170
- });
171
- return success;
172
- },
173
- filterGrid : function(gridid,p){
174
- p = $.extend({
175
- gridModel : false,
176
- gridNames : false,
177
- gridToolbar : false,
178
- filterModel: [], // label/name/stype/defval/surl/sopt
179
- formtype : "horizontal", // horizontal/vertical
180
- autosearch: true, // if set to false a serch button should be enabled.
181
- formclass: "filterform",
182
- tableclass: "filtertable",
183
- buttonclass: "filterbutton",
184
- searchButton: "Search",
185
- clearButton: "Clear",
186
- enableSearch : false,
187
- enableClear: false,
188
- beforeSearch: null,
189
- afterSearch: null,
190
- beforeClear: null,
191
- afterClear: null,
192
- url : '',
193
- marksearched: true
194
- },p || {});
195
- return this.each(function(){
196
- var self = this;
197
- this.p = p;
198
- if(this.p.filterModel.length === 0 && this.p.gridModel===false) { alert("No filter is set"); return;}
199
- if( !gridid) {alert("No target grid is set!"); return;}
200
- this.p.gridid = gridid.indexOf("#") != -1 ? gridid : "#"+gridid;
201
- var gcolMod = $(this.p.gridid).jqGrid("getGridParam",'colModel');
202
- if(gcolMod) {
203
- if( this.p.gridModel === true) {
204
- var thegrid = $(this.p.gridid)[0];
205
- var sh;
206
- // we should use the options search, edittype, editoptions
207
- // additionally surl and defval can be added in grid colModel
208
- $.each(gcolMod, function (i,n) {
209
- var tmpFil = [];
210
- this.search = this.search === false ? false : true;
211
- if(this.editrules && this.editrules.searchhidden === true) {
212
- sh = true;
213
- } else {
214
- if(this.hidden === true ) {
215
- sh = false;
216
- } else {
217
- sh = true;
218
- }
219
- }
220
- if( this.search === true && sh === true) {
221
- if(self.p.gridNames===true) {
222
- tmpFil.label = thegrid.p.colNames[i];
223
- } else {
224
- tmpFil.label = '';
225
- }
226
- tmpFil.name = this.name;
227
- tmpFil.index = this.index || this.name;
228
- // we support only text and selects, so all other to text
229
- tmpFil.stype = this.edittype || 'text';
230
- if(tmpFil.stype != 'select' ) {
231
- tmpFil.stype = 'text';
232
- }
233
- tmpFil.defval = this.defval || '';
234
- tmpFil.surl = this.surl || '';
235
- tmpFil.sopt = this.editoptions || {};
236
- tmpFil.width = this.width;
237
- self.p.filterModel.push(tmpFil);
238
- }
239
- });
240
- } else {
241
- $.each(self.p.filterModel,function(i,n) {
242
- for(var j=0;j<gcolMod.length;j++) {
243
- if(this.name == gcolMod[j].name) {
244
- this.index = gcolMod[j].index || this.name;
245
- break;
246
- }
247
- }
248
- if(!this.index) {
249
- this.index = this.name;
250
- }
251
- });
252
- }
253
- } else {
254
- alert("Could not get grid colModel"); return;
255
- }
256
- var triggerSearch = function() {
257
- var sdata={}, j=0, v;
258
- var gr = $(self.p.gridid)[0], nm;
259
- gr.p.searchdata = {};
260
- if($.isFunction(self.p.beforeSearch)){self.p.beforeSearch();}
261
- $.each(self.p.filterModel,function(i,n){
262
- nm = this.index;
263
- switch (this.stype) {
264
- case 'select' :
265
- v = $("select[name="+nm+"]",self).val();
266
- if(v) {
267
- sdata[nm] = v;
268
- if(self.p.marksearched){
269
- $("#jqgh_"+this.name,gr.grid.hDiv).addClass("dirty-cell");
270
- }
271
- j++;
272
- } else {
273
- if(self.p.marksearched){
274
- $("#jqgh_"+this.name,gr.grid.hDiv).removeClass("dirty-cell");
275
- }
276
- try {
277
- delete gr.p.postData[this.index];
278
- } catch (e) {}
279
- }
280
- break;
281
- default:
282
- v = $("input[name="+nm+"]",self).val();
283
- if(v) {
284
- sdata[nm] = v;
285
- if(self.p.marksearched){
286
- $("#jqgh_"+this.name,gr.grid.hDiv).addClass("dirty-cell");
287
- }
288
- j++;
289
- } else {
290
- if(self.p.marksearched){
291
- $("#jqgh_"+this.name,gr.grid.hDiv).removeClass("dirty-cell");
292
- }
293
- try {
294
- delete gr.p.postData[this.index];
295
- } catch(e) {}
296
- }
297
- }
298
- });
299
- var sd = j>0 ? true : false;
300
- $.extend(gr.p.postData,sdata);
301
- var saveurl;
302
- if(self.p.url) {
303
- saveurl = $(gr).jqGrid("getGridParam",'url');
304
- $(gr).jqGrid("setGridParam",{url:self.p.url});
305
- }
306
- $(gr).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]);
307
- if(saveurl) {$(gr).jqGrid("setGridParam",{url:saveurl});}
308
- if($.isFunction(self.p.afterSearch)){self.p.afterSearch();}
309
- };
310
- var clearSearch = function(){
311
- var sdata={}, v, j=0;
312
- var gr = $(self.p.gridid)[0], nm;
313
- if($.isFunction(self.p.beforeClear)){self.p.beforeClear();}
314
- $.each(self.p.filterModel,function(i,n){
315
- nm = this.index;
316
- v = (this.defval) ? this.defval : "";
317
- if(!this.stype){this.stype='text';}
318
- switch (this.stype) {
319
- case 'select' :
320
- var v1;
321
- $("select[name="+nm+"] option",self).each(function (i){
322
- if(i===0) { this.selected = true; }
323
- if ($(this).text() == v) {
324
- this.selected = true;
325
- v1 = $(this).val();
326
- return false;
327
- }
328
- });
329
- if(v1) {
330
- // post the key and not the text
331
- sdata[nm] = v1;
332
- if(self.p.marksearched){
333
- $("#jqgh_"+this.name,gr.grid.hDiv).addClass("dirty-cell");
334
- }
335
- j++;
336
- } else {
337
- if(self.p.marksearched){
338
- $("#jqgh_"+this.name,gr.grid.hDiv).removeClass("dirty-cell");
339
- }
340
- try {
341
- delete gr.p.postData[this.index];
342
- } catch (e) {}
343
- }
344
- break;
345
- case 'text':
346
- $("input[name="+nm+"]",self).val(v);
347
- if(v) {
348
- sdata[nm] = v;
349
- if(self.p.marksearched){
350
- $("#jqgh_"+this.name,gr.grid.hDiv).addClass("dirty-cell");
351
- }
352
- j++;
353
- } else {
354
- if(self.p.marksearched){
355
- $("#jqgh_"+this.name,gr.grid.hDiv).removeClass("dirty-cell");
356
- }
357
- try {
358
- delete gr.p.postData[this.index];
359
- } catch (e) {}
360
- }
361
- break;
362
- }
363
- });
364
- var sd = j>0 ? true : false;
365
- $.extend(gr.p.postData,sdata);
366
- var saveurl;
367
- if(self.p.url) {
368
- saveurl = $(gr).jqGrid("getGridParam",'url');
369
- $(gr).jqGrid("setGridParam",{url:self.p.url});
370
- }
371
- $(gr).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]);
372
- if(saveurl) {$(gr).jqGrid("setGridParam",{url:saveurl});}
373
- if($.isFunction(self.p.afterClear)){self.p.afterClear();}
374
- };
375
- var formFill = function(){
376
- var tr = document.createElement("tr");
377
- var tr1, sb, cb,tl,td;
378
- if(self.p.formtype=='horizontal'){
379
- $(tbl).append(tr);
380
- }
381
- $.each(self.p.filterModel,function(i,n){
382
- tl = document.createElement("td");
383
- $(tl).append("<label for='"+this.name+"'>"+this.label+"</label>");
384
- td = document.createElement("td");
385
- var $t=this;
386
- if(!this.stype) { this.stype='text';}
387
- switch (this.stype)
388
- {
389
- case "select":
390
- if(this.surl) {
391
- // data returned should have already constructed html select
392
- $(td).load(this.surl,function(){
393
- if($t.defval) { $("select",this).val($t.defval); }
394
- $("select",this).attr({name:$t.index || $t.name, id: "sg_"+$t.name});
395
- if($t.sopt) { $("select",this).attr($t.sopt); }
396
- if(self.p.gridToolbar===true && $t.width) {
397
- $("select",this).width($t.width);
398
- }
399
- if(self.p.autosearch===true){
400
- $("select",this).change(function(e){
401
- triggerSearch();
402
- return false;
403
- });
404
- }
405
- });
406
- } else {
407
- // sopt to construct the values
408
- if($t.sopt.value) {
409
- var oSv = $t.sopt.value;
410
- var elem = document.createElement("select");
411
- $(elem).attr({name:$t.index || $t.name, id: "sg_"+$t.name}).attr($t.sopt);
412
- var so, sv, ov;
413
- if(typeof oSv === "string") {
414
- so = oSv.split(";");
415
- for(var k=0; k<so.length;k++){
416
- sv = so[k].split(":");
417
- ov = document.createElement("option");
418
- ov.value = sv[0]; ov.innerHTML = sv[1];
419
- if (sv[1]==$t.defval) { ov.selected ="selected"; }
420
- elem.appendChild(ov);
421
- }
422
- } else if(typeof oSv === "object" ) {
423
- for ( var key in oSv) {
424
- if(oSv.hasOwnProperty(key)) {
425
- i++;
426
- ov = document.createElement("option");
427
- ov.value = key; ov.innerHTML = oSv[key];
428
- if (oSv[key]==$t.defval) { ov.selected ="selected"; }
429
- elem.appendChild(ov);
430
- }
431
- }
432
- }
433
- if(self.p.gridToolbar===true && $t.width) {
434
- $(elem).width($t.width);
435
- }
436
- $(td).append(elem);
437
- if(self.p.autosearch===true){
438
- $(elem).change(function(e){
439
- triggerSearch();
440
- return false;
441
- });
442
- }
443
- }
444
- }
445
- break;
446
- case 'text':
447
- var df = this.defval ? this.defval: "";
448
- $(td).append("<input type='text' name='"+(this.index || this.name)+"' id='sg_"+this.name+"' value='"+df+"'/>");
449
- if($t.sopt) { $("input",td).attr($t.sopt); }
450
- if(self.p.gridToolbar===true && $t.width) {
451
- if($.browser.msie) {
452
- $("input",td).width($t.width-4);
453
- } else {
454
- $("input",td).width($t.width-2);
455
- }
456
- }
457
- if(self.p.autosearch===true){
458
- $("input",td).keypress(function(e){
459
- var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
460
- if(key == 13){
461
- triggerSearch();
462
- return false;
463
- }
464
- return this;
465
- });
466
- }
467
- break;
468
- }
469
- if(self.p.formtype=='horizontal'){
470
- if(self.p.gridToolbar===true && self.p.gridNames===false) {
471
- $(tr).append(td);
472
- } else {
473
- $(tr).append(tl).append(td);
474
- }
475
- $(tr).append(td);
476
- } else {
477
- tr1 = document.createElement("tr");
478
- $(tr1).append(tl).append(td);
479
- $(tbl).append(tr1);
480
- }
481
- });
482
- td = document.createElement("td");
483
- if(self.p.enableSearch === true){
484
- sb = "<input type='button' id='sButton' class='"+self.p.buttonclass+"' value='"+self.p.searchButton+"'/>";
485
- $(td).append(sb);
486
- $("input#sButton",td).click(function(){
487
- triggerSearch();
488
- return false;
489
- });
490
- }
491
- if(self.p.enableClear === true) {
492
- cb = "<input type='button' id='cButton' class='"+self.p.buttonclass+"' value='"+self.p.clearButton+"'/>";
493
- $(td).append(cb);
494
- $("input#cButton",td).click(function(){
495
- clearSearch();
496
- return false;
497
- });
498
- }
499
- if(self.p.enableClear === true || self.p.enableSearch === true) {
500
- if(self.p.formtype=='horizontal') {
501
- $(tr).append(td);
502
- } else {
503
- tr1 = document.createElement("tr");
504
- $(tr1).append("<td>&#160;</td>").append(td);
505
- $(tbl).append(tr1);
506
- }
507
- }
508
- };
509
- var frm = $("<form name='SearchForm' style=display:inline;' class='"+this.p.formclass+"'></form>");
510
- var tbl =$("<table class='"+this.p.tableclass+"' cellspacing='0' cellpading='0' border='0'><tbody></tbody></table>");
511
- $(frm).append(tbl);
512
- formFill();
513
- $(this).append(frm);
514
- this.triggerSearch = triggerSearch;
515
- this.clearSearch = clearSearch;
516
- });
517
- },
518
- filterToolbar : function(p){
519
- p = $.extend({
520
- autosearch: true,
521
- searchOnEnter : true,
522
- beforeSearch: null,
523
- afterSearch: null,
524
- beforeClear: null,
525
- afterClear: null,
526
- searchurl : '',
527
- stringResult: false,
528
- groupOp: 'AND'
529
- },p || {});
530
- return this.each(function(){
531
- var $t = this;
532
- var triggerToolbar = function() {
533
- var sdata={}, j=0, v, nm, sopt={};
534
- $.each($t.p.colModel,function(i,n){
535
- nm = this.index || this.name;
536
- var so = (this.searchoptions && this.searchoptions.sopt) ? this.searchoptions.sopt[0] : "bw";
537
- switch (this.stype) {
538
- case 'select' :
539
- v = $("select[name="+nm+"]",$t.grid.hDiv).val();
540
- if(v) {
541
- sdata[nm] = v;
542
- sopt[nm] = so;
543
- j++;
544
- } else {
545
- try {
546
- delete $t.p.postData[nm];
547
- } catch (e) {}
548
- }
549
- break;
550
- case 'text':
551
- v = $("input[name="+nm+"]",$t.grid.hDiv).val();
552
- if(v) {
553
- sdata[nm] = v;
554
- sopt[nm] = so;
555
- j++;
556
- } else {
557
- try {
558
- delete $t.p.postData[nm];
559
- } catch (e) {}
560
- }
561
- break;
562
- }
563
- });
564
- var sd = j>0 ? true : false;
565
- if(p.stringResult === true || $t.p.datatype == "local") {
566
- var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
567
- var gi=0;
568
- $.each(sdata,function(i,n){
569
- if (gi > 0) {ruleGroup += ",";}
570
- ruleGroup += "{\"field\":\"" + i + "\",";
571
- ruleGroup += "\"op\":\"" + sopt[i] + "\",";
572
- ruleGroup += "\"data\":\"" + n + "\"}";
573
- gi++;
574
- });
575
- ruleGroup += "]}";
576
- $.extend($t.p.postData,{filters:ruleGroup});
577
- } else {
578
- $.extend($t.p.postData,sdata);
579
- }
580
- var saveurl;
581
- if($t.p.searchurl) {
582
- saveurl = $t.p.url;
583
- $($t).jqGrid("setGridParam",{url:$t.p.searchurl});
584
- }
585
- var bsr = false;
586
- if($.isFunction(p.beforeSearch)){bsr = p.beforeSearch.call($t);}
587
- if(!bsr) { $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]); }
588
- if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});}
589
- if($.isFunction(p.afterSearch)){p.afterSearch();}
590
- };
591
- var clearToolbar = function(trigger){
592
- var sdata={}, v, j=0, nm;
593
- trigger = (typeof trigger != 'boolean') ? true : trigger;
594
- $.each($t.p.colModel,function(i,n){
595
- v = (this.searchoptions && this.searchoptions.defaultValue) ? this.searchoptions.defaultValue : "";
596
- nm = this.index || this.name;
597
- switch (this.stype) {
598
- case 'select' :
599
- var v1;
600
- $("select[name="+nm+"] option",$t.grid.hDiv).each(function (i){
601
- if(i===0) { this.selected = true; }
602
- if ($(this).text() == v) {
603
- this.selected = true;
604
- v1 = $(this).val();
605
- return false;
606
- }
607
- });
608
- if (v1) {
609
- // post the key and not the text
610
- sdata[nm] = v1;
611
- j++;
612
- } else {
613
- try {
614
- delete $t.p.postData[nm];
615
- } catch(e) {}
616
- }
617
- break;
618
- case 'text':
619
- $("input[name="+nm+"]",$t.grid.hDiv).val(v);
620
- if(v) {
621
- sdata[nm] = v;
622
- j++;
623
- } else {
624
- try {
625
- delete $t.p.postData[nm];
626
- } catch (e){}
627
- }
628
- break;
629
- }
630
- });
631
- var sd = j>0 ? true : false;
632
- if(p.stringResult === true || $t.p.datatype == "local") {
633
- var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
634
- var gi=0;
635
- $.each(sdata,function(i,n){
636
- if (gi > 0) {ruleGroup += ",";}
637
- ruleGroup += "{\"field\":\"" + i + "\",";
638
- ruleGroup += "\"op\":\"" + "eq" + "\",";
639
- ruleGroup += "\"data\":\"" + n + "\"}";
640
- gi++;
641
- });
642
- ruleGroup += "]}";
643
- $.extend($t.p.postData,{filters:ruleGroup});
644
- } else {
645
- $.extend($t.p.postData,sdata);
646
- }
647
- var saveurl;
648
- if($t.p.searchurl) {
649
- saveurl = $t.p.url;
650
- $($t).jqGrid("setGridParam",{url:$t.p.searchurl});
651
- }
652
- var bcv = false;
653
- if($.isFunction(p.beforeClear)){bcv = p.beforeClear.call($t);}
654
- if(!bcv) {
655
- if(trigger) {
656
- $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]);
657
- }
658
- }
659
- if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});}
660
- if($.isFunction(p.afterClear)){p.afterClear();}
661
- };
662
- var toggleToolbar = function(){
663
- var trow = $("tr.ui-search-toolbar",$t.grid.hDiv);
664
- if(trow.css("display")=='none') { trow.show(); }
665
- else { trow.hide(); }
666
- };
667
- // create the row
668
- function bindEvents(selector, events) {
669
- var jElem = $(selector);
670
- if (jElem[0]) {
671
- jQuery.each(events, function() {
672
- if (this.data !== undefined) {
673
- jElem.bind(this.type, this.data, this.fn);
674
- } else {
675
- jElem.bind(this.type, this.fn);
676
- }
677
- });
678
- }
679
- }
680
- var tr = $("<tr class='ui-search-toolbar' role='rowheader'></tr>");
681
- var timeoutHnd;
682
- $.each($t.p.colModel,function(i,n){
683
- var cm=this, thd , th, soptions,surl,self;
684
- th = $("<th role='columnheader' class='ui-state-default ui-th-column ui-th-"+$t.p.direction+"'></th>");
685
- thd = $("<div style='width:100%;position:relative;height:100%;padding-right:0.3em;'></div>");
686
- if(this.hidden===true) { $(th).css("display","none");}
687
- this.search = this.search === false ? false : true;
688
- if(typeof this.stype == 'undefined' ) {this.stype='text';}
689
- soptions = $.extend({},this.searchoptions || {});
690
- if(this.search){
691
- switch (this.stype)
692
- {
693
- case "select":
694
- surl = this.surl || soptions.dataUrl;
695
- if(surl) {
696
- // data returned should have already constructed html select
697
- // primitive jQuery load
698
- self = thd;
699
- $.ajax($.extend({
700
- url: surl,
701
- dataType: "html",
702
- complete: function(res,status) {
703
- if(soptions.buildSelect !== undefined) {
704
- var d = soptions.buildSelect(res);
705
- if (d) { $(self).append(d); }
706
- } else {
707
- $(self).append(res.responseText);
708
- }
709
- if(soptions.defaultValue) { $("select",self).val(soptions.defaultValue); }
710
- $("select",self).attr({name:cm.index || cm.name, id: "gs_"+cm.name});
711
- if(soptions.attr) {$("select",self).attr(soptions.attr);}
712
- $("select",self).css({width: "100%"});
713
- // preserve autoserch
714
- if(soptions.dataInit !== undefined) { soptions.dataInit($("select",self)[0]); }
715
- if(soptions.dataEvents !== undefined) { bindEvents($("select",self)[0],soptions.dataEvents); }
716
- if(p.autosearch===true){
717
- $("select",self).change(function(e){
718
- triggerToolbar();
719
- return false;
720
- });
721
- }
722
- res=null;
723
- }
724
- }, $.jgrid.ajaxOptions, $t.p.ajaxSelectOptions || {} ));
725
- } else {
726
- var oSv;
727
- if(cm.searchoptions && cm.searchoptions.value) {
728
- oSv = cm.searchoptions.value;
729
- } else if(cm.editoptions && cm.editoptions.value) {
730
- oSv = cm.editoptions.value;
731
- }
732
- if (oSv) {
733
- var elem = document.createElement("select");
734
- elem.style.width = "100%";
735
- $(elem).attr({name:cm.index || cm.name, id: "gs_"+cm.name});
736
- var so, sv, ov;
737
- if(typeof oSv === "string") {
738
- so = oSv.split(";");
739
- for(var k=0; k<so.length;k++){
740
- sv = so[k].split(":");
741
- ov = document.createElement("option");
742
- ov.value = sv[0]; ov.innerHTML = sv[1];
743
- elem.appendChild(ov);
744
- }
745
- } else if(typeof oSv === "object" ) {
746
- for ( var key in oSv) {
747
- if(oSv.hasOwnProperty(key)) {
748
- ov = document.createElement("option");
749
- ov.value = key; ov.innerHTML = oSv[key];
750
- elem.appendChild(ov);
751
- }
752
- }
753
- }
754
- if(soptions.defaultValue) { $(elem).val(soptions.defaultValue); }
755
- if(soptions.attr) {$(elem).attr(soptions.attr);}
756
- if(soptions.dataInit !== undefined) { soptions.dataInit(elem); }
757
- if(soptions.dataEvents !== undefined) { bindEvents(elem, soptions.dataEvents); }
758
- $(thd).append(elem);
759
- if(p.autosearch===true){
760
- $(elem).change(function(e){
761
- triggerToolbar();
762
- return false;
763
- });
764
- }
765
- }
766
- }
767
- break;
768
- case 'text':
769
- var df = soptions.defaultValue ? soptions.defaultValue: "";
770
- $(thd).append("<input type='text' style='width:95%;padding:0px;' name='"+(cm.index || cm.name)+"' id='gs_"+cm.name+"' value='"+df+"'/>");
771
- if(soptions.attr) {$("input",thd).attr(soptions.attr);}
772
- if(soptions.dataInit !== undefined) { soptions.dataInit($("input",thd)[0]); }
773
- if(soptions.dataEvents !== undefined) { bindEvents($("input",thd)[0], soptions.dataEvents); }
774
- if(p.autosearch===true){
775
- if(p.searchOnEnter) {
776
- $("input",thd).keypress(function(e){
777
- var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
778
- if(key == 13){
779
- triggerToolbar();
780
- return false;
781
- }
782
- return this;
783
- });
784
- } else {
785
- $("input",thd).keydown(function(e){
786
- var key = e.which;
787
- switch (key) {
788
- case 13:
789
- return false;
790
- case 9 :
791
- case 16:
792
- case 37:
793
- case 38:
794
- case 39:
795
- case 40:
796
- case 27:
797
- break;
798
- default :
799
- if(timeoutHnd) { clearTimeout(timeoutHnd); }
800
- timeoutHnd = setTimeout(function(){triggerToolbar();},500);
801
- }
802
- });
803
- }
804
- }
805
- break;
806
- }
807
- }
808
- $(th).append(thd);
809
- $(tr).append(th);
810
- });
811
- $("table thead",$t.grid.hDiv).append(tr);
812
- this.triggerToolbar = triggerToolbar;
813
- this.clearToolbar = clearToolbar;
814
- this.toggleToolbar = toggleToolbar;
815
- });
816
- }
817
- });
1
+ ;(function($){
2
+ /**
3
+ * jqGrid extension for custom methods
4
+ * Tony Tomov tony@trirand.com
5
+ * http://trirand.com/blog/
6
+ * Dual licensed under the MIT and GPL licenses:
7
+ * http://www.opensource.org/licenses/mit-license.php
8
+ * http://www.gnu.org/licenses/gpl-2.0.html
9
+ **/
10
+ $.jgrid.extend({
11
+ getColProp : function(colname){
12
+ var ret ={}, $t = this[0];
13
+ if ( !$t.grid ) { return false; }
14
+ var cM = $t.p.colModel;
15
+ for ( var i =0;i<cM.length;i++ ) {
16
+ if ( cM[i].name == colname ) {
17
+ ret = cM[i];
18
+ break;
19
+ }
20
+ }
21
+ return ret;
22
+ },
23
+ setColProp : function(colname, obj){
24
+ //do not set width will not work
25
+ return this.each(function(){
26
+ if ( this.grid ) {
27
+ if ( obj ) {
28
+ var cM = this.p.colModel;
29
+ for ( var i =0;i<cM.length;i++ ) {
30
+ if ( cM[i].name == colname ) {
31
+ $.extend(this.p.colModel[i],obj);
32
+ break;
33
+ }
34
+ }
35
+ }
36
+ }
37
+ });
38
+ },
39
+ sortGrid : function(colname,reload, sor){
40
+ return this.each(function(){
41
+ var $t=this,idx=-1;
42
+ if ( !$t.grid ) { return;}
43
+ if ( !colname ) { colname = $t.p.sortname; }
44
+ for ( var i=0;i<$t.p.colModel.length;i++ ) {
45
+ if ( $t.p.colModel[i].index == colname || $t.p.colModel[i].name==colname ) {
46
+ idx = i;
47
+ break;
48
+ }
49
+ }
50
+ if ( idx!=-1 ){
51
+ var sort = $t.p.colModel[idx].sortable;
52
+ if ( typeof sort !== 'boolean' ) { sort = true; }
53
+ if ( typeof reload !=='boolean' ) { reload = false; }
54
+ if ( sort ) { $t.sortData("jqgh_"+colname, idx, reload, sor); }
55
+ }
56
+ });
57
+ },
58
+ GridDestroy : function () {
59
+ return this.each(function(){
60
+ if ( this.grid ) {
61
+ if ( this.p.pager ) { // if not part of grid
62
+ $(this.p.pager).remove();
63
+ }
64
+ var gid = this.id;
65
+ try {
66
+ $("#gbox_"+gid).remove();
67
+ } catch (_) {}
68
+ }
69
+ });
70
+ },
71
+ GridUnload : function(){
72
+ return this.each(function(){
73
+ if ( !this.grid ) {return;}
74
+ var defgrid = {id: $(this).attr('id'),cl: $(this).attr('class')};
75
+ if (this.p.pager) {
76
+ $(this.p.pager).empty().removeClass("ui-state-default ui-jqgrid-pager corner-bottom");
77
+ }
78
+ var newtable = document.createElement('table');
79
+ $(newtable).attr({id:defgrid.id});
80
+ newtable.className = defgrid.cl;
81
+ var gid = this.id;
82
+ $(newtable).removeClass("ui-jqgrid-btable");
83
+ if( $(this.p.pager).parents("#gbox_"+gid).length === 1 ) {
84
+ $(newtable).insertBefore("#gbox_"+gid).show();
85
+ $(this.p.pager).insertBefore("#gbox_"+gid);
86
+ } else {
87
+ $(newtable).insertBefore("#gbox_"+gid).show();
88
+ }
89
+ $("#gbox_"+gid).remove();
90
+ });
91
+ },
92
+ setGridState : function(state) {
93
+ return this.each(function(){
94
+ if ( !this.grid ) {return;}
95
+ var $t = this;
96
+ if(state == 'hidden'){
97
+ $(".ui-jqgrid-bdiv, .ui-jqgrid-hdiv","#gview_"+$t.p.id).slideUp("fast");
98
+ if($t.p.pager) {$($t.p.pager).slideUp("fast");}
99
+ if($t.p.toppager) {$($t.p.toppager).slideUp("fast");}
100
+ if($t.p.toolbar[0]===true) {
101
+ if( $t.p.toolbar[1]=='both') {
102
+ $($t.grid.ubDiv).slideUp("fast");
103
+ }
104
+ $($t.grid.uDiv).slideUp("fast");
105
+ }
106
+ if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$t.p.id).slideUp("fast"); }
107
+ $(".ui-jqgrid-titlebar-close span",$t.grid.cDiv).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s");
108
+ $t.p.gridstate = 'hidden';
109
+ } else if(state=='visible') {
110
+ $(".ui-jqgrid-hdiv, .ui-jqgrid-bdiv","#gview_"+$t.p.id).slideDown("fast");
111
+ if($t.p.pager) {$($t.p.pager).slideDown("fast");}
112
+ if($t.p.toppager) {$($t.p.toppager).slideDown("fast");}
113
+ if($t.p.toolbar[0]===true) {
114
+ if( $t.p.toolbar[1]=='both') {
115
+ $($t.grid.ubDiv).slideDown("fast");
116
+ }
117
+ $($t.grid.uDiv).slideDown("fast");
118
+ }
119
+ if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$t.p.id).slideDown("fast"); }
120
+ $(".ui-jqgrid-titlebar-close span",$t.grid.cDiv).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n");
121
+ $t.p.gridstate = 'visible';
122
+ }
123
+
124
+ });
125
+ },
126
+ updateGridRows : function (data, rowidname, jsonreader) {
127
+ var nm, success=false, title;
128
+ this.each(function(){
129
+ var t = this, vl, ind, srow, sid;
130
+ if(!t.grid) {return false;}
131
+ if(!rowidname) { rowidname = "id"; }
132
+ if( data && data.length >0 ) {
133
+ $(data).each(function(j){
134
+ srow = this;
135
+ ind = t.rows.namedItem(srow[rowidname]);
136
+ if(ind) {
137
+ sid = srow[rowidname];
138
+ if(jsonreader === true){
139
+ if(t.p.jsonReader.repeatitems === true) {
140
+ if(t.p.jsonReader.cell) {srow = srow[t.p.jsonReader.cell];}
141
+ for (var k=0;k<srow.length;k++) {
142
+ vl = t.formatter( sid, srow[k], k, srow, 'edit');
143
+ title = t.p.colModel[k].title ? {"title":$.jgrid.stripHtml(vl)} : {};
144
+ if(t.p.treeGrid===true && nm == t.p.ExpandColumn) {
145
+ $("td:eq("+k+") > span:first",ind).html(vl).attr(title);
146
+ } else {
147
+ $("td:eq("+k+")",ind).html(vl).attr(title);
148
+ }
149
+ }
150
+ success = true;
151
+ return true;
152
+ }
153
+ }
154
+ $(t.p.colModel).each(function(i){
155
+ nm = jsonreader===true ? this.jsonmap || this.name :this.name;
156
+ if( srow[nm] !== undefined) {
157
+ vl = t.formatter( sid, srow[nm], i, srow, 'edit');
158
+ title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
159
+ if(t.p.treeGrid===true && nm == t.p.ExpandColumn) {
160
+ $("td:eq("+i+") > span:first",ind).html(vl).attr(title);
161
+ } else {
162
+ $("td:eq("+i+")",ind).html(vl).attr(title);
163
+ }
164
+ success = true;
165
+ }
166
+ });
167
+ }
168
+ });
169
+ }
170
+ });
171
+ return success;
172
+ },
173
+ filterGrid : function(gridid,p){
174
+ p = $.extend({
175
+ gridModel : false,
176
+ gridNames : false,
177
+ gridToolbar : false,
178
+ filterModel: [], // label/name/stype/defval/surl/sopt
179
+ formtype : "horizontal", // horizontal/vertical
180
+ autosearch: true, // if set to false a serch button should be enabled.
181
+ formclass: "filterform",
182
+ tableclass: "filtertable",
183
+ buttonclass: "filterbutton",
184
+ searchButton: "Search",
185
+ clearButton: "Clear",
186
+ enableSearch : false,
187
+ enableClear: false,
188
+ beforeSearch: null,
189
+ afterSearch: null,
190
+ beforeClear: null,
191
+ afterClear: null,
192
+ url : '',
193
+ marksearched: true
194
+ },p || {});
195
+ return this.each(function(){
196
+ var self = this;
197
+ this.p = p;
198
+ if(this.p.filterModel.length === 0 && this.p.gridModel===false) { alert("No filter is set"); return;}
199
+ if( !gridid) {alert("No target grid is set!"); return;}
200
+ this.p.gridid = gridid.indexOf("#") != -1 ? gridid : "#"+gridid;
201
+ var gcolMod = $(this.p.gridid).jqGrid("getGridParam",'colModel');
202
+ if(gcolMod) {
203
+ if( this.p.gridModel === true) {
204
+ var thegrid = $(this.p.gridid)[0];
205
+ var sh;
206
+ // we should use the options search, edittype, editoptions
207
+ // additionally surl and defval can be added in grid colModel
208
+ $.each(gcolMod, function (i,n) {
209
+ var tmpFil = [];
210
+ this.search = this.search === false ? false : true;
211
+ if(this.editrules && this.editrules.searchhidden === true) {
212
+ sh = true;
213
+ } else {
214
+ if(this.hidden === true ) {
215
+ sh = false;
216
+ } else {
217
+ sh = true;
218
+ }
219
+ }
220
+ if( this.search === true && sh === true) {
221
+ if(self.p.gridNames===true) {
222
+ tmpFil.label = thegrid.p.colNames[i];
223
+ } else {
224
+ tmpFil.label = '';
225
+ }
226
+ tmpFil.name = this.name;
227
+ tmpFil.index = this.index || this.name;
228
+ // we support only text and selects, so all other to text
229
+ tmpFil.stype = this.edittype || 'text';
230
+ if(tmpFil.stype != 'select' ) {
231
+ tmpFil.stype = 'text';
232
+ }
233
+ tmpFil.defval = this.defval || '';
234
+ tmpFil.surl = this.surl || '';
235
+ tmpFil.sopt = this.editoptions || {};
236
+ tmpFil.width = this.width;
237
+ self.p.filterModel.push(tmpFil);
238
+ }
239
+ });
240
+ } else {
241
+ $.each(self.p.filterModel,function(i,n) {
242
+ for(var j=0;j<gcolMod.length;j++) {
243
+ if(this.name == gcolMod[j].name) {
244
+ this.index = gcolMod[j].index || this.name;
245
+ break;
246
+ }
247
+ }
248
+ if(!this.index) {
249
+ this.index = this.name;
250
+ }
251
+ });
252
+ }
253
+ } else {
254
+ alert("Could not get grid colModel"); return;
255
+ }
256
+ var triggerSearch = function() {
257
+ var sdata={}, j=0, v;
258
+ var gr = $(self.p.gridid)[0], nm;
259
+ gr.p.searchdata = {};
260
+ if($.isFunction(self.p.beforeSearch)){self.p.beforeSearch();}
261
+ $.each(self.p.filterModel,function(i,n){
262
+ nm = this.index;
263
+ switch (this.stype) {
264
+ case 'select' :
265
+ v = $("select[name="+nm+"]",self).val();
266
+ if(v) {
267
+ sdata[nm] = v;
268
+ if(self.p.marksearched){
269
+ $("#jqgh_"+this.name,gr.grid.hDiv).addClass("dirty-cell");
270
+ }
271
+ j++;
272
+ } else {
273
+ if(self.p.marksearched){
274
+ $("#jqgh_"+this.name,gr.grid.hDiv).removeClass("dirty-cell");
275
+ }
276
+ try {
277
+ delete gr.p.postData[this.index];
278
+ } catch (e) {}
279
+ }
280
+ break;
281
+ default:
282
+ v = $("input[name="+nm+"]",self).val();
283
+ if(v) {
284
+ sdata[nm] = v;
285
+ if(self.p.marksearched){
286
+ $("#jqgh_"+this.name,gr.grid.hDiv).addClass("dirty-cell");
287
+ }
288
+ j++;
289
+ } else {
290
+ if(self.p.marksearched){
291
+ $("#jqgh_"+this.name,gr.grid.hDiv).removeClass("dirty-cell");
292
+ }
293
+ try {
294
+ delete gr.p.postData[this.index];
295
+ } catch(e) {}
296
+ }
297
+ }
298
+ });
299
+ var sd = j>0 ? true : false;
300
+ $.extend(gr.p.postData,sdata);
301
+ var saveurl;
302
+ if(self.p.url) {
303
+ saveurl = $(gr).jqGrid("getGridParam",'url');
304
+ $(gr).jqGrid("setGridParam",{url:self.p.url});
305
+ }
306
+ $(gr).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]);
307
+ if(saveurl) {$(gr).jqGrid("setGridParam",{url:saveurl});}
308
+ if($.isFunction(self.p.afterSearch)){self.p.afterSearch();}
309
+ };
310
+ var clearSearch = function(){
311
+ var sdata={}, v, j=0;
312
+ var gr = $(self.p.gridid)[0], nm;
313
+ if($.isFunction(self.p.beforeClear)){self.p.beforeClear();}
314
+ $.each(self.p.filterModel,function(i,n){
315
+ nm = this.index;
316
+ v = (this.defval) ? this.defval : "";
317
+ if(!this.stype){this.stype='text';}
318
+ switch (this.stype) {
319
+ case 'select' :
320
+ var v1;
321
+ $("select[name="+nm+"] option",self).each(function (i){
322
+ if(i===0) { this.selected = true; }
323
+ if ($(this).text() == v) {
324
+ this.selected = true;
325
+ v1 = $(this).val();
326
+ return false;
327
+ }
328
+ });
329
+ if(v1) {
330
+ // post the key and not the text
331
+ sdata[nm] = v1;
332
+ if(self.p.marksearched){
333
+ $("#jqgh_"+this.name,gr.grid.hDiv).addClass("dirty-cell");
334
+ }
335
+ j++;
336
+ } else {
337
+ if(self.p.marksearched){
338
+ $("#jqgh_"+this.name,gr.grid.hDiv).removeClass("dirty-cell");
339
+ }
340
+ try {
341
+ delete gr.p.postData[this.index];
342
+ } catch (e) {}
343
+ }
344
+ break;
345
+ case 'text':
346
+ $("input[name="+nm+"]",self).val(v);
347
+ if(v) {
348
+ sdata[nm] = v;
349
+ if(self.p.marksearched){
350
+ $("#jqgh_"+this.name,gr.grid.hDiv).addClass("dirty-cell");
351
+ }
352
+ j++;
353
+ } else {
354
+ if(self.p.marksearched){
355
+ $("#jqgh_"+this.name,gr.grid.hDiv).removeClass("dirty-cell");
356
+ }
357
+ try {
358
+ delete gr.p.postData[this.index];
359
+ } catch (e) {}
360
+ }
361
+ break;
362
+ }
363
+ });
364
+ var sd = j>0 ? true : false;
365
+ $.extend(gr.p.postData,sdata);
366
+ var saveurl;
367
+ if(self.p.url) {
368
+ saveurl = $(gr).jqGrid("getGridParam",'url');
369
+ $(gr).jqGrid("setGridParam",{url:self.p.url});
370
+ }
371
+ $(gr).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]);
372
+ if(saveurl) {$(gr).jqGrid("setGridParam",{url:saveurl});}
373
+ if($.isFunction(self.p.afterClear)){self.p.afterClear();}
374
+ };
375
+ var tbl;
376
+ var formFill = function(){
377
+ var tr = document.createElement("tr");
378
+ var tr1, sb, cb,tl,td;
379
+ if(self.p.formtype=='horizontal'){
380
+ $(tbl).append(tr);
381
+ }
382
+ $.each(self.p.filterModel,function(i,n){
383
+ tl = document.createElement("td");
384
+ $(tl).append("<label for='"+this.name+"'>"+this.label+"</label>");
385
+ td = document.createElement("td");
386
+ var $t=this;
387
+ if(!this.stype) { this.stype='text';}
388
+ switch (this.stype)
389
+ {
390
+ case "select":
391
+ if(this.surl) {
392
+ // data returned should have already constructed html select
393
+ $(td).load(this.surl,function(){
394
+ if($t.defval) { $("select",this).val($t.defval); }
395
+ $("select",this).attr({name:$t.index || $t.name, id: "sg_"+$t.name});
396
+ if($t.sopt) { $("select",this).attr($t.sopt); }
397
+ if(self.p.gridToolbar===true && $t.width) {
398
+ $("select",this).width($t.width);
399
+ }
400
+ if(self.p.autosearch===true){
401
+ $("select",this).change(function(e){
402
+ triggerSearch();
403
+ return false;
404
+ });
405
+ }
406
+ });
407
+ } else {
408
+ // sopt to construct the values
409
+ if($t.sopt.value) {
410
+ var oSv = $t.sopt.value;
411
+ var elem = document.createElement("select");
412
+ $(elem).attr({name:$t.index || $t.name, id: "sg_"+$t.name}).attr($t.sopt);
413
+ var so, sv, ov;
414
+ if(typeof oSv === "string") {
415
+ so = oSv.split(";");
416
+ for(var k=0; k<so.length;k++){
417
+ sv = so[k].split(":");
418
+ ov = document.createElement("option");
419
+ ov.value = sv[0]; ov.innerHTML = sv[1];
420
+ if (sv[1]==$t.defval) { ov.selected ="selected"; }
421
+ elem.appendChild(ov);
422
+ }
423
+ } else if(typeof oSv === "object" ) {
424
+ for ( var key in oSv) {
425
+ if(oSv.hasOwnProperty(key)) {
426
+ i++;
427
+ ov = document.createElement("option");
428
+ ov.value = key; ov.innerHTML = oSv[key];
429
+ if (oSv[key]==$t.defval) { ov.selected ="selected"; }
430
+ elem.appendChild(ov);
431
+ }
432
+ }
433
+ }
434
+ if(self.p.gridToolbar===true && $t.width) {
435
+ $(elem).width($t.width);
436
+ }
437
+ $(td).append(elem);
438
+ if(self.p.autosearch===true){
439
+ $(elem).change(function(e){
440
+ triggerSearch();
441
+ return false;
442
+ });
443
+ }
444
+ }
445
+ }
446
+ break;
447
+ case 'text':
448
+ var df = this.defval ? this.defval: "";
449
+ $(td).append("<input type='text' name='"+(this.index || this.name)+"' id='sg_"+this.name+"' value='"+df+"'/>");
450
+ if($t.sopt) { $("input",td).attr($t.sopt); }
451
+ if(self.p.gridToolbar===true && $t.width) {
452
+ if($.browser.msie) {
453
+ $("input",td).width($t.width-4);
454
+ } else {
455
+ $("input",td).width($t.width-2);
456
+ }
457
+ }
458
+ if(self.p.autosearch===true){
459
+ $("input",td).keypress(function(e){
460
+ var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
461
+ if(key == 13){
462
+ triggerSearch();
463
+ return false;
464
+ }
465
+ return this;
466
+ });
467
+ }
468
+ break;
469
+ }
470
+ if(self.p.formtype=='horizontal'){
471
+ if(self.p.gridToolbar===true && self.p.gridNames===false) {
472
+ $(tr).append(td);
473
+ } else {
474
+ $(tr).append(tl).append(td);
475
+ }
476
+ $(tr).append(td);
477
+ } else {
478
+ tr1 = document.createElement("tr");
479
+ $(tr1).append(tl).append(td);
480
+ $(tbl).append(tr1);
481
+ }
482
+ });
483
+ td = document.createElement("td");
484
+ if(self.p.enableSearch === true){
485
+ sb = "<input type='button' id='sButton' class='"+self.p.buttonclass+"' value='"+self.p.searchButton+"'/>";
486
+ $(td).append(sb);
487
+ $("input#sButton",td).click(function(){
488
+ triggerSearch();
489
+ return false;
490
+ });
491
+ }
492
+ if(self.p.enableClear === true) {
493
+ cb = "<input type='button' id='cButton' class='"+self.p.buttonclass+"' value='"+self.p.clearButton+"'/>";
494
+ $(td).append(cb);
495
+ $("input#cButton",td).click(function(){
496
+ clearSearch();
497
+ return false;
498
+ });
499
+ }
500
+ if(self.p.enableClear === true || self.p.enableSearch === true) {
501
+ if(self.p.formtype=='horizontal') {
502
+ $(tr).append(td);
503
+ } else {
504
+ tr1 = document.createElement("tr");
505
+ $(tr1).append("<td>&#160;</td>").append(td);
506
+ $(tbl).append(tr1);
507
+ }
508
+ }
509
+ };
510
+ var frm = $("<form name='SearchForm' style=display:inline;' class='"+this.p.formclass+"'></form>");
511
+ tbl =$("<table class='"+this.p.tableclass+"' cellspacing='0' cellpading='0' border='0'><tbody></tbody></table>");
512
+ $(frm).append(tbl);
513
+ formFill();
514
+ $(this).append(frm);
515
+ this.triggerSearch = triggerSearch;
516
+ this.clearSearch = clearSearch;
517
+ });
518
+ },
519
+ filterToolbar : function(p){
520
+ p = $.extend({
521
+ autosearch: true,
522
+ searchOnEnter : true,
523
+ beforeSearch: null,
524
+ afterSearch: null,
525
+ beforeClear: null,
526
+ afterClear: null,
527
+ searchurl : '',
528
+ stringResult: false,
529
+ groupOp: 'AND',
530
+ defaultSearch : "bw"
531
+ },p || {});
532
+ return this.each(function(){
533
+ var $t = this;
534
+ var triggerToolbar = function() {
535
+ var sdata={}, j=0, v, nm, sopt={},so;
536
+ $.each($t.p.colModel,function(i,n){
537
+ nm = this.index || this.name;
538
+ switch (this.stype) {
539
+ case 'select' :
540
+ so = (this.searchoptions && this.searchoptions.sopt) ? this.searchoptions.sopt[0] : 'eq';
541
+ v = $("select[name="+nm+"]",$t.grid.hDiv).val();
542
+ if(v) {
543
+ sdata[nm] = v;
544
+ sopt[nm] = so;
545
+ j++;
546
+ } else {
547
+ try {
548
+ delete $t.p.postData[nm];
549
+ } catch (e) {}
550
+ }
551
+ break;
552
+ case 'text':
553
+ so = (this.searchoptions && this.searchoptions.sopt) ? this.searchoptions.sopt[0] : p.defaultSearch;
554
+ v = $("input[name="+nm+"]",$t.grid.hDiv).val();
555
+ if(v) {
556
+ sdata[nm] = v;
557
+ sopt[nm] = so;
558
+ j++;
559
+ } else {
560
+ try {
561
+ delete $t.p.postData[nm];
562
+ } catch (e) {}
563
+ }
564
+ break;
565
+ }
566
+ });
567
+ var sd = j>0 ? true : false;
568
+ if(p.stringResult === true || $t.p.datatype == "local") {
569
+ var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
570
+ var gi=0;
571
+ $.each(sdata,function(i,n){
572
+ if (gi > 0) {ruleGroup += ",";}
573
+ ruleGroup += "{\"field\":\"" + i + "\",";
574
+ ruleGroup += "\"op\":\"" + sopt[i] + "\",";
575
+ ruleGroup += "\"data\":\"" + n + "\"}";
576
+ gi++;
577
+ });
578
+ ruleGroup += "]}";
579
+ $.extend($t.p.postData,{filters:ruleGroup});
580
+ } else {
581
+ $.extend($t.p.postData,sdata);
582
+ }
583
+ var saveurl;
584
+ if($t.p.searchurl) {
585
+ saveurl = $t.p.url;
586
+ $($t).jqGrid("setGridParam",{url:$t.p.searchurl});
587
+ }
588
+ var bsr = false;
589
+ if($.isFunction(p.beforeSearch)){bsr = p.beforeSearch.call($t);}
590
+ if(!bsr) { $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]); }
591
+ if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});}
592
+ if($.isFunction(p.afterSearch)){p.afterSearch();}
593
+ };
594
+ var clearToolbar = function(trigger){
595
+ var sdata={}, v, j=0, nm;
596
+ trigger = (typeof trigger != 'boolean') ? true : trigger;
597
+ $.each($t.p.colModel,function(i,n){
598
+ v = (this.searchoptions && this.searchoptions.defaultValue) ? this.searchoptions.defaultValue : "";
599
+ nm = this.index || this.name;
600
+ switch (this.stype) {
601
+ case 'select' :
602
+ var v1;
603
+ $("select[name="+nm+"] option",$t.grid.hDiv).each(function (i){
604
+ if(i===0) { this.selected = true; }
605
+ if ($(this).text() == v) {
606
+ this.selected = true;
607
+ v1 = $(this).val();
608
+ return false;
609
+ }
610
+ });
611
+ if (v1) {
612
+ // post the key and not the text
613
+ sdata[nm] = v1;
614
+ j++;
615
+ } else {
616
+ try {
617
+ delete $t.p.postData[nm];
618
+ } catch(e) {}
619
+ }
620
+ break;
621
+ case 'text':
622
+ $("input[name="+nm+"]",$t.grid.hDiv).val(v);
623
+ if(v) {
624
+ sdata[nm] = v;
625
+ j++;
626
+ } else {
627
+ try {
628
+ delete $t.p.postData[nm];
629
+ } catch (e){}
630
+ }
631
+ break;
632
+ }
633
+ });
634
+ var sd = j>0 ? true : false;
635
+ if(p.stringResult === true || $t.p.datatype == "local") {
636
+ var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
637
+ var gi=0;
638
+ $.each(sdata,function(i,n){
639
+ if (gi > 0) {ruleGroup += ",";}
640
+ ruleGroup += "{\"field\":\"" + i + "\",";
641
+ ruleGroup += "\"op\":\"" + "eq" + "\",";
642
+ ruleGroup += "\"data\":\"" + n + "\"}";
643
+ gi++;
644
+ });
645
+ ruleGroup += "]}";
646
+ $.extend($t.p.postData,{filters:ruleGroup});
647
+ } else {
648
+ $.extend($t.p.postData,sdata);
649
+ }
650
+ var saveurl;
651
+ if($t.p.searchurl) {
652
+ saveurl = $t.p.url;
653
+ $($t).jqGrid("setGridParam",{url:$t.p.searchurl});
654
+ }
655
+ var bcv = false;
656
+ if($.isFunction(p.beforeClear)){bcv = p.beforeClear.call($t);}
657
+ if(!bcv) {
658
+ if(trigger) {
659
+ $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]);
660
+ }
661
+ }
662
+ if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});}
663
+ if($.isFunction(p.afterClear)){p.afterClear();}
664
+ };
665
+ var toggleToolbar = function(){
666
+ var trow = $("tr.ui-search-toolbar",$t.grid.hDiv);
667
+ if(trow.css("display")=='none') { trow.show(); }
668
+ else { trow.hide(); }
669
+ };
670
+ // create the row
671
+ function bindEvents(selector, events) {
672
+ var jElem = $(selector);
673
+ if (jElem[0]) {
674
+ jQuery.each(events, function() {
675
+ if (this.data !== undefined) {
676
+ jElem.bind(this.type, this.data, this.fn);
677
+ } else {
678
+ jElem.bind(this.type, this.fn);
679
+ }
680
+ });
681
+ }
682
+ }
683
+ var tr = $("<tr class='ui-search-toolbar' role='rowheader'></tr>");
684
+ var timeoutHnd;
685
+ $.each($t.p.colModel,function(i,n){
686
+ var cm=this, thd , th, soptions,surl,self;
687
+ th = $("<th role='columnheader' class='ui-state-default ui-th-column ui-th-"+$t.p.direction+"'></th>");
688
+ thd = $("<div style='width:100%;position:relative;height:100%;padding-right:0.3em;'></div>");
689
+ if(this.hidden===true) { $(th).css("display","none");}
690
+ this.search = this.search === false ? false : true;
691
+ if(typeof this.stype == 'undefined' ) {this.stype='text';}
692
+ soptions = $.extend({},this.searchoptions || {});
693
+ if(this.search){
694
+ switch (this.stype)
695
+ {
696
+ case "select":
697
+ surl = this.surl || soptions.dataUrl;
698
+ if(surl) {
699
+ // data returned should have already constructed html select
700
+ // primitive jQuery load
701
+ self = thd;
702
+ $.ajax($.extend({
703
+ url: surl,
704
+ dataType: "html",
705
+ complete: function(res,status) {
706
+ if(soptions.buildSelect !== undefined) {
707
+ var d = soptions.buildSelect(res);
708
+ if (d) { $(self).append(d); }
709
+ } else {
710
+ $(self).append(res.responseText);
711
+ }
712
+ if(soptions.defaultValue) { $("select",self).val(soptions.defaultValue); }
713
+ $("select",self).attr({name:cm.index || cm.name, id: "gs_"+cm.name});
714
+ if(soptions.attr) {$("select",self).attr(soptions.attr);}
715
+ $("select",self).css({width: "100%"});
716
+ // preserve autoserch
717
+ if(soptions.dataInit !== undefined) { soptions.dataInit($("select",self)[0]); }
718
+ if(soptions.dataEvents !== undefined) { bindEvents($("select",self)[0],soptions.dataEvents); }
719
+ if(p.autosearch===true){
720
+ $("select",self).change(function(e){
721
+ triggerToolbar();
722
+ return false;
723
+ });
724
+ }
725
+ res=null;
726
+ }
727
+ }, $.jgrid.ajaxOptions, $t.p.ajaxSelectOptions || {} ));
728
+ } else {
729
+ var oSv;
730
+ if(cm.searchoptions && cm.searchoptions.value) {
731
+ oSv = cm.searchoptions.value;
732
+ } else if(cm.editoptions && cm.editoptions.value) {
733
+ oSv = cm.editoptions.value;
734
+ }
735
+ if (oSv) {
736
+ var elem = document.createElement("select");
737
+ elem.style.width = "100%";
738
+ $(elem).attr({name:cm.index || cm.name, id: "gs_"+cm.name});
739
+ var so, sv, ov;
740
+ if(typeof oSv === "string") {
741
+ so = oSv.split(";");
742
+ for(var k=0; k<so.length;k++){
743
+ sv = so[k].split(":");
744
+ ov = document.createElement("option");
745
+ ov.value = sv[0]; ov.innerHTML = sv[1];
746
+ elem.appendChild(ov);
747
+ }
748
+ } else if(typeof oSv === "object" ) {
749
+ for ( var key in oSv) {
750
+ if(oSv.hasOwnProperty(key)) {
751
+ ov = document.createElement("option");
752
+ ov.value = key; ov.innerHTML = oSv[key];
753
+ elem.appendChild(ov);
754
+ }
755
+ }
756
+ }
757
+ if(soptions.defaultValue) { $(elem).val(soptions.defaultValue); }
758
+ if(soptions.attr) {$(elem).attr(soptions.attr);}
759
+ if(soptions.dataInit !== undefined) { soptions.dataInit(elem); }
760
+ if(soptions.dataEvents !== undefined) { bindEvents(elem, soptions.dataEvents); }
761
+ $(thd).append(elem);
762
+ if(p.autosearch===true){
763
+ $(elem).change(function(e){
764
+ triggerToolbar();
765
+ return false;
766
+ });
767
+ }
768
+ }
769
+ }
770
+ break;
771
+ case 'text':
772
+ var df = soptions.defaultValue ? soptions.defaultValue: "";
773
+ $(thd).append("<input type='text' style='width:95%;padding:0px;' name='"+(cm.index || cm.name)+"' id='gs_"+cm.name+"' value='"+df+"'/>");
774
+ if(soptions.attr) {$("input",thd).attr(soptions.attr);}
775
+ if(soptions.dataInit !== undefined) { soptions.dataInit($("input",thd)[0]); }
776
+ if(soptions.dataEvents !== undefined) { bindEvents($("input",thd)[0], soptions.dataEvents); }
777
+ if(p.autosearch===true){
778
+ if(p.searchOnEnter) {
779
+ $("input",thd).keypress(function(e){
780
+ var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
781
+ if(key == 13){
782
+ triggerToolbar();
783
+ return false;
784
+ }
785
+ return this;
786
+ });
787
+ } else {
788
+ $("input",thd).keydown(function(e){
789
+ var key = e.which;
790
+ switch (key) {
791
+ case 13:
792
+ return false;
793
+ case 9 :
794
+ case 16:
795
+ case 37:
796
+ case 38:
797
+ case 39:
798
+ case 40:
799
+ case 27:
800
+ break;
801
+ default :
802
+ if(timeoutHnd) { clearTimeout(timeoutHnd); }
803
+ timeoutHnd = setTimeout(function(){triggerToolbar();},500);
804
+ }
805
+ });
806
+ }
807
+ }
808
+ break;
809
+ }
810
+ }
811
+ $(th).append(thd);
812
+ $(tr).append(th);
813
+ });
814
+ $("table thead",$t.grid.hDiv).append(tr);
815
+ this.triggerToolbar = triggerToolbar;
816
+ this.clearToolbar = clearToolbar;
817
+ this.toggleToolbar = toggleToolbar;
818
+ });
819
+ }
820
+ });
818
821
  })(jQuery);