rails_jq_grid 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYRIGHT.txt +17 -0
- data/GPL-LICENSE +675 -0
- data/README.rdoc +176 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/app/helpers/rails_jq_grid/jq_grid_css_helper.rb +29 -0
- data/app/helpers/rails_jq_grid/jq_grid_helper.rb +21 -0
- data/app/helpers/rails_jq_grid/jq_grid_js_helper.rb +30 -0
- data/app/models/rails_jq_grid/jq_grid.rb +315 -0
- data/app/models/rails_jq_grid/jq_grid_column.rb +33 -0
- data/app/models/rails_jq_grid/jq_grid_method_missing.rb +50 -0
- data/app/models/rails_jq_grid/jq_grid_option_or_method.rb +46 -0
- data/lib/rails_jq_grid/acts_as_jq_grid_able.rb +76 -0
- data/lib/rails_jq_grid/acts_as_jq_grid_data_source.rb +34 -0
- data/lib/rails_jq_grid/engine.rb +23 -0
- data/lib/rails_jq_grid.rb +7 -0
- data/lib/tasks/rails_jq_grid.rake +1 -0
- data/public/javascripts/rails-jqgrid/Changes.txt +1160 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-bg.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-bg1251.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-cat.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-cn.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-cs.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-de.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-dk.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-el.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-en.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-es.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-fa.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-fi.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-fr.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-he.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-hu.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-is.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-it.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-ja.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-nl.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-no.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-pl.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-pt-br.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-pt.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-ro.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-ru.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-sk.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-sv.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-tr.js +1 -0
- data/public/javascripts/rails-jqgrid/i18n/grid.locale-ua.js +1 -0
- data/public/javascripts/rails-jqgrid/install.txt +43 -0
- data/public/javascripts/rails-jqgrid/jquery-1.4.2.min.js +154 -0
- data/public/javascripts/rails-jqgrid/jquery-ui-1.8.4.custom.min.js +763 -0
- data/public/javascripts/rails-jqgrid/jquery.jqGrid.min.js +445 -0
- data/public/javascripts/rails-jqgrid/src/JsonXml.js +330 -0
- data/public/javascripts/rails-jqgrid/src/css/ellipsis-xbl.xml +13 -0
- data/public/javascripts/rails-jqgrid/src/css/jquery.searchFilter.css +7 -0
- data/public/javascripts/rails-jqgrid/src/css/ui.jqgrid.css +129 -0
- data/public/javascripts/rails-jqgrid/src/css/ui.multiselect.css +30 -0
- data/public/javascripts/rails-jqgrid/src/grid.base.js +3003 -0
- data/public/javascripts/rails-jqgrid/src/grid.celledit.js +486 -0
- data/public/javascripts/rails-jqgrid/src/grid.common.js +636 -0
- data/public/javascripts/rails-jqgrid/src/grid.custom.js +818 -0
- data/public/javascripts/rails-jqgrid/src/grid.formedit.js +1872 -0
- data/public/javascripts/rails-jqgrid/src/grid.import.js +201 -0
- data/public/javascripts/rails-jqgrid/src/grid.inlinedit.js +250 -0
- data/public/javascripts/rails-jqgrid/src/grid.jqueryui.js +503 -0
- data/public/javascripts/rails-jqgrid/src/grid.loader.js +47 -0
- data/public/javascripts/rails-jqgrid/src/grid.postext.js +64 -0
- data/public/javascripts/rails-jqgrid/src/grid.setcolumns.js +126 -0
- data/public/javascripts/rails-jqgrid/src/grid.subgrid.js +260 -0
- data/public/javascripts/rails-jqgrid/src/grid.tbltogrid.js +106 -0
- data/public/javascripts/rails-jqgrid/src/grid.treegrid.js +483 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-bg.js +132 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-bg1251.js +132 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cat.js +128 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cn.js +132 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cs.js +128 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-de.js +128 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-dk.js +128 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-el.js +126 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-en.js +128 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-es.js +128 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fa.js +125 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fi.js +130 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fr.js +126 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-he.js +127 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-hu.js +129 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-is.js +126 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-it.js +1 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ja.js +155 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-nl.js +149 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-no.js +1 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pl.js +127 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pt-br.js +127 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pt.js +125 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ro.js +139 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ru.js +127 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-sk.js +127 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-sv.js +127 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-tr.js +126 -0
- data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ua.js +127 -0
- data/public/javascripts/rails-jqgrid/src/jqDnR.js +68 -0
- data/public/javascripts/rails-jqgrid/src/jqModal.js +69 -0
- data/public/javascripts/rails-jqgrid/src/jquery.fmatter.js +542 -0
- data/public/javascripts/rails-jqgrid/src/jquery.searchFilter.js +716 -0
- data/public/javascripts/rails-jqgrid/src/ui.multiselect.js +314 -0
- data/public/stylesheets/rails-jqgrid/ellipsis-xbl.xml +13 -0
- data/public/stylesheets/rails-jqgrid/themes/AUTHORS.txt +30 -0
- data/public/stylesheets/rails-jqgrid/themes/GPL-LICENSE.txt +278 -0
- data/public/stylesheets/rails-jqgrid/themes/MIT-LICENSE.txt +25 -0
- data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/smoothness/jquery-ui-1.8.4.custom.css +572 -0
- data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_flat_55_999999_40x100.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_flat_75_aaaaaa_40x100.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_glass_45_0078ae_1x400.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_glass_55_f8da4e_1x400.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_glass_75_79c9ec_1x400.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_gloss-wave_45_e14f1c_500x100.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_gloss-wave_50_6eac2c_500x100.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_gloss-wave_75_2191c0_500x100.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_inset-hard_100_fcfdfd_1x100.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_0078ae_256x240.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_056b93_256x240.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_d8e7f3_256x240.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_e0fdff_256x240.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_f5e175_256x240.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_f7a50d_256x240.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_fcd113_256x240.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/start/jquery-ui-1.8.4.custom.css +573 -0
- data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_flat_30_cccccc_40x100.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_flat_50_5c5c5c_40x100.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_glass_20_555555_1x400.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_glass_40_0078a3_1x400.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_glass_40_ffc73d_1x400.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_gloss-wave_25_333333_500x100.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_highlight-soft_80_eeeeee_1x100.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_inset-soft_25_000000_1x100.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_inset-soft_30_f58400_1x100.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-icons_222222_256x240.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-icons_4b8e0b_256x240.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-icons_a83300_256x240.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-icons_cccccc_256x240.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-icons_ffffff_256x240.png +0 -0
- data/public/stylesheets/rails-jqgrid/themes/ui-darkness/jquery-ui-1.8.4.custom.css +572 -0
- data/public/stylesheets/rails-jqgrid/themes/version.txt +1 -0
- data/public/stylesheets/rails-jqgrid/ui.jqgrid.css +2 -0
- data/rails_jq_grid.gemspec +200 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +8 -0
- metadata +240 -0
@@ -0,0 +1,818 @@
|
|
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> </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
|
+
});
|
818
|
+
})(jQuery);
|