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
@@ -0,0 +1,250 @@
1
+ // Grouping module
2
+ ;(function($){
3
+ $.jgrid.extend({
4
+ groupingSetup : function () {
5
+ return this.each(function (){
6
+ var $t = this,
7
+ grp = $t.p.groupingView;
8
+ if(grp !== null && ( (typeof grp === 'object') || $.isFunction(grp) ) ) {
9
+ if(!grp.groupField.length) {
10
+ $t.p.grouping = false;
11
+ } else {
12
+ for(var i=0;i<grp.groupField.length;i++) {
13
+ if(!grp.groupOrder[i]) {
14
+ grp.groupOrder[i] = 'asc';
15
+ }
16
+ if(!grp.groupText[i]) {
17
+ grp.groupText[i] = '{0}';
18
+ }
19
+ if( typeof(grp.groupColumnShow[i]) != 'boolean') {
20
+ grp.groupColumnShow[i] = true;
21
+ }
22
+ if( typeof(grp.groupSummary[i]) != 'boolean') {
23
+ grp.groupSummary[i] = false;
24
+ }
25
+ if(grp.groupColumnShow[i] === true) {
26
+ $($t).jqGrid('showCol',grp.groupField[i]);
27
+ } else {
28
+ $($t).jqGrid('hideCol',grp.groupField[i]);
29
+ }
30
+ grp.sortitems[i] = [];
31
+ grp.sortnames[i] = [];
32
+ grp.summaryval[i] = [];
33
+ if(grp.groupSummary[i]) {
34
+ grp.summary[i] =[];
35
+ var cm = $t.p.colModel;
36
+ for(var j=0, cml = cm.length; j < cml; j++) {
37
+ if(cm[j].summaryType) {
38
+ grp.summary[i].push({nm:cm[j].name,st:cm[j].summaryType, v:''});
39
+ }
40
+ }
41
+ }
42
+ }
43
+ $t.p.scroll = false;
44
+ $t.p.rownumbers = false;
45
+ $t.p.subGrid = false;
46
+ $t.p.treeGrid = false;
47
+ $t.p.gridview = true;
48
+ }
49
+ } else {
50
+ $t.p.grouping = false;
51
+ }
52
+ });
53
+ },
54
+ groupingPrepare : function (rData, items, gdata, record) {
55
+ this.each(function(){
56
+ // currently only one level
57
+ // Is this a good idea to do it so!!!!?????
58
+ items[0] += "";
59
+ var itm = items[0].toString().split(' ').join('');
60
+
61
+ var grp = this.p.groupingView, $t= this;
62
+ if(gdata.hasOwnProperty(itm)) {
63
+ gdata[itm].push(rData);
64
+ } else {
65
+ gdata[itm] = [];
66
+ gdata[itm].push(rData);
67
+ grp.sortitems[0].push(itm);
68
+ grp.sortnames[0].push($.trim(items[0].toString()));
69
+ grp.summaryval[0][itm] = $.extend(true,[],grp.summary[0]);
70
+ }
71
+ if(grp.groupSummary[0]) {
72
+ $.each(grp.summaryval[0][itm],function(i,n) {
73
+ if ($.isFunction(this.st)) {
74
+ this.v = this.st.call($t, this.v, this.nm, record);
75
+ } else {
76
+ this.v = $($t).jqGrid('groupingCalculations.'+this.st, this.v, this.nm, record);
77
+ }
78
+ });
79
+ }
80
+ });
81
+ return gdata;
82
+ },
83
+ groupingToggle : function(hid){
84
+ this.each(function(){
85
+ var $t = this,
86
+ grp = $t.p.groupingView,
87
+ strpos = hid.lastIndexOf('_'),
88
+ uid = hid.substring(0,strpos+1),
89
+ num = parseInt(hid.substring(strpos+1),10)+1,
90
+ minus = grp.minusicon,
91
+ plus = grp.plusicon;
92
+ if( $("#"+hid+" span").hasClass(minus) ) {
93
+ if(grp.showSummaryOnHide && grp.groupSummary[0]) {
94
+ $("#"+hid).nextUntil(".jqfoot").hide();
95
+ } else {
96
+ $("#"+hid).nextUntil("#"+uid+String(num)).hide();
97
+ }
98
+ $("#"+hid+" span").removeClass(minus).addClass(plus);
99
+ } else {
100
+ $("#"+hid).nextUntil("#"+uid+String(num)).show();
101
+ $("#"+hid+" span").removeClass(plus).addClass(minus);
102
+ }
103
+ });
104
+ return false;
105
+ },
106
+ groupingRender : function (grdata, colspans ) {
107
+ return this.each(function(){
108
+ var $t = this,
109
+ grp = $t.p.groupingView,
110
+ str = "", icon = "", hid, pmrtl ="", gv, cp, ii;
111
+ //only one level for now
112
+ if(!grp.groupDataSorted) {
113
+ // ???? TO BE IMPROVED
114
+ grp.sortitems[0].sort();
115
+ grp.sortnames[0].sort();
116
+ if(grp.groupOrder[0].toLowerCase() == 'desc')
117
+ {
118
+ grp.sortitems[0].reverse();
119
+ grp.sortnames[0].reverse();
120
+ }
121
+ }
122
+ if(grp.groupCollapse) { pmrtl = grp.plusicon; }
123
+ else {pmrtl = grp.minusicon;}
124
+ pmrtl += " tree-wrap-"+$t.p.direction;
125
+ ii = 0;
126
+ while(ii < colspans) {
127
+ if($t.p.colModel[ii].name == grp.groupField[0]) {
128
+ cp = ii;
129
+ break;
130
+ }
131
+ ii++;
132
+ }
133
+ $.each(grp.sortitems[0],function(i,n){
134
+ hid = $t.p.id+"ghead_"+i;
135
+ icon = "<span style='cursor:pointer;' class='ui-icon "+pmrtl+"' onclick=\"jQuery('#"+$t.p.id+"').jqGrid('groupingToggle','"+hid+"');return false;\"></span>";
136
+ try {
137
+ gv = $t.formatter(hid, grp.sortnames[0][i], cp, grp.sortitems[0] );
138
+ } catch (egv) {
139
+ gv = grp.sortnames[0][i];
140
+ }
141
+ str += "<tr id=\""+hid+"\" role=\"row\" class= \"ui-widget-content jqgroup ui-row-"+$t.p.direction+"\"><td colspan=\""+colspans+"\">"+icon+$.jgrid.format(grp.groupText[0], gv, grdata[n].length)+"</td></tr>";
142
+ for(var kk=0;kk<grdata[n].length;kk++) {
143
+ str += grdata[n][kk].join('');
144
+ }
145
+ if(grp.groupSummary[0]) {
146
+ var hhdr = "";
147
+ if(grp.groupCollapse && !grp.showSummaryOnHide) {
148
+ hhdr = " style=\"display:none;\"";
149
+ }
150
+ str += "<tr"+hhdr+" role=\"row\" class=\"ui-widget-content jqfoot ui-row-"+$t.p.direction+"\">";
151
+ var fdata = grp.summaryval[0][n],
152
+ cm = $t.p.colModel,
153
+ vv, grlen = grdata[n].length;
154
+ for(var k=0; k<colspans;k++) {
155
+ var tmpdata = "<td "+$t.formatCol(k,1,'')+">&#160;</td>",
156
+ tplfld = "{0}";
157
+ $.each(fdata,function(){
158
+ if(this.nm == cm[k].name) {
159
+ if(cm[k].summaryTpl) {
160
+ tplfld = cm[k].summaryTpl;
161
+ }
162
+ if(this.st == 'avg') {
163
+ if(this.v && grlen > 0) {
164
+ this.v = (this.v/grlen);
165
+ }
166
+ }
167
+ try {
168
+ vv = $t.formatter('', this.v, k, this);
169
+ } catch (ef) {
170
+ vv = this.v;
171
+ }
172
+ tmpdata= "<td "+$t.formatCol(k,1,'')+">"+$.jgrid.format(tplfld,vv)+ "</td>";
173
+ return false;
174
+ }
175
+ });
176
+ str += tmpdata;
177
+ }
178
+ str += "</tr>";
179
+ }
180
+ });
181
+ $("#"+$t.p.id+" tbody:first").append(str);
182
+ // free up memory
183
+ str = null;
184
+ });
185
+ },
186
+ groupingGroupBy : function (name, options, current) {
187
+ return this.each(function(){
188
+ var $t = this;
189
+ if(typeof(name) == "string") {
190
+ name = [name];
191
+ }
192
+ var grp = $t.p.groupingView;
193
+ $t.p.grouping = true;
194
+ // show previoous hidden groups if they are hidden
195
+ for(var i=0;i<grp.groupField.length;i++) {
196
+ if(!grp.groupColumnShow[i]) {
197
+ $($t).jqGrid('showCol',grp.groupField[i]);
198
+ }
199
+ }
200
+ $t.p.groupingView = $.extend($t.p.groupingView, options || {});
201
+ grp.groupField = name;
202
+ $($t).trigger("reloadGrid");
203
+ });
204
+ },
205
+ groupingRemove : function (current) {
206
+ return this.each(function(){
207
+ var $t = this;
208
+ if(typeof(current) == 'undefined') {
209
+ current = true;
210
+ }
211
+ $t.p.grouping = false;
212
+ if(current===true) {
213
+ $("tr.jqgroup, tr.jqfoot","#"+$t.p.id+" tbody:first").remove();
214
+ $("tr.jqgrow:hidden","#"+$t.p.id+" tbody:first").show();
215
+ } else {
216
+ $($t).trigger("reloadGrid");
217
+ }
218
+ });
219
+ },
220
+ groupingCalculations : {
221
+ "sum" : function(v, field, rc) {
222
+ return parseFloat(v||0) + parseFloat((rc[field]||0));
223
+ },
224
+ "min" : function(v, field, rc) {
225
+ if(v==="") {
226
+ return parseFloat(rc[field]||0);
227
+ }
228
+ return Math.min(parseFloat(v),parseFloat(rc[field]||0));
229
+ },
230
+ "max" : function(v, field, rc) {
231
+ if(v==="") {
232
+ return parseFloat(rc[field]||0);
233
+ }
234
+ return Math.max(parseFloat(v),parseFloat(rc[field]||0));
235
+ },
236
+ "count" : function(v, field, rc) {
237
+ if(v==="") {v=0;}
238
+ if(rc.hasOwnProperty(field)) {
239
+ return v+1;
240
+ } else {
241
+ return 0;
242
+ }
243
+ },
244
+ "avg" : function(v, field, rc) {
245
+ // the same as sum, but at end we divide it
246
+ return parseFloat(v||0) + parseFloat((rc[field]||0));
247
+ }
248
+ }
249
+ });
250
+ })(jQuery);
@@ -1,201 +1,201 @@
1
- ;(function($){
2
- /*
3
- * jqGrid extension for constructing Grid Data from external file
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
- jqGridImport : function(o) {
12
- o = $.extend({
13
- imptype : "xml", // xml, json, xmlstring, jsonstring
14
- impstring: "",
15
- impurl: "",
16
- mtype: "GET",
17
- impData : {},
18
- xmlGrid :{
19
- config : "roots>grid",
20
- data: "roots>rows"
21
- },
22
- jsonGrid :{
23
- config : "grid",
24
- data: "data"
25
- },
26
- ajaxOptions :{}
27
- }, o || {});
28
- return this.each(function(){
29
- var $t = this;
30
- var XmlConvert = function (xml,o) {
31
- var cnfg = $(o.xmlGrid.config,xml)[0];
32
- var xmldata = $(o.xmlGrid.data,xml)[0], jstr, jstr1;
33
- if(xmlJsonClass.xml2json && $.jgrid.parse) {
34
- jstr = xmlJsonClass.xml2json(cnfg," ");
35
- jstr = $.jgrid.parse(jstr);
36
- for(var key in jstr) {
37
- if(jstr.hasOwnProperty(key)) {
38
- jstr1=jstr[key];
39
- }
40
- }
41
- if(xmldata) {
42
- // save the datatype
43
- var svdatatype = jstr.grid.datatype;
44
- jstr.grid.datatype = 'xmlstring';
45
- jstr.grid.datastr = xml;
46
- $($t).jqGrid( jstr1 ).jqGrid("setGridParam",{datatype:svdatatype});
47
- } else {
48
- $($t).jqGrid( jstr1 );
49
- }
50
- jstr = null;jstr1=null;
51
- } else {
52
- alert("xml2json or parse are not present");
53
- }
54
- };
55
- var JsonConvert = function (jsonstr,o){
56
- if (jsonstr && typeof jsonstr == 'string') {
57
- var json = $.jgrid.parse(jsonstr);
58
- var gprm = json[o.jsonGrid.config];
59
- var jdata = json[o.jsonGrid.data];
60
- if(jdata) {
61
- var svdatatype = gprm.datatype;
62
- gprm.datatype = 'jsonstring';
63
- gprm.datastr = jdata;
64
- $($t).jqGrid( gprm ).jqGrid("setGridParam",{datatype:svdatatype});
65
- } else {
66
- $($t).jqGrid( gprm );
67
- }
68
- }
69
- };
70
- switch (o.imptype){
71
- case 'xml':
72
- $.ajax($.extend({
73
- url:o.impurl,
74
- type:o.mtype,
75
- data: o.impData,
76
- dataType:"xml",
77
- complete: function(xml,stat) {
78
- if(stat == 'success') {
79
- XmlConvert(xml.responseXML,o);
80
- if($.isFunction(o.importComplete)) {
81
- o.importComplete(xml);
82
- }
83
- }
84
- xml=null;
85
- }
86
- }, o.ajaxOptions));
87
- break;
88
- case 'xmlstring' :
89
- // we need to make just the conversion and use the same code as xml
90
- if(o.impstring && typeof o.impstring == 'string') {
91
- var xmld = $.jgrid.stringToDoc(o.impstring);
92
- if(xmld) {
93
- XmlConvert(xmld,o);
94
- if($.isFunction(o.importComplete)) {
95
- o.importComplete(xmld);
96
- }
97
- o.impstring = null;
98
- }
99
- xmld = null;
100
- }
101
- break;
102
- case 'json':
103
- $.ajax($.extend({
104
- url:o.impurl,
105
- type:o.mtype,
106
- data: o.impData,
107
- dataType:"json",
108
- complete: function(json,stat) {
109
- if(stat == 'success') {
110
- JsonConvert(json.responseText,o );
111
- if($.isFunction(o.importComplete)) {
112
- o.importComplete(json);
113
- }
114
- }
115
- json=null;
116
- }
117
- }, o.ajaxOptions ));
118
- break;
119
- case 'jsonstring' :
120
- if(o.impstring && typeof o.impstring == 'string') {
121
- JsonConvert(o.impstring,o );
122
- if($.isFunction(o.importComplete)) {
123
- o.importComplete(o.impstring);
124
- }
125
- o.impstring = null;
126
- }
127
- break;
128
- }
129
- });
130
- },
131
- jqGridExport : function(o) {
132
- o = $.extend({
133
- exptype : "xmlstring",
134
- root: "grid",
135
- ident: "\t"
136
- }, o || {});
137
- var ret = null;
138
- this.each(function () {
139
- if(!this.grid) { return;}
140
- var gprm = $.extend({},$(this).jqGrid("getGridParam"));
141
- // we need to check for:
142
- // 1.multiselect, 2.subgrid 3. treegrid and remove the unneded columns from colNames
143
- if(gprm.rownumbers) {
144
- gprm.colNames.splice(0,1);
145
- gprm.colModel.splice(0,1);
146
- }
147
- if(gprm.multiselect) {
148
- gprm.colNames.splice(0,1);
149
- gprm.colModel.splice(0,1);
150
- }
151
- if(gprm.subGrid) {
152
- gprm.colNames.splice(0,1);
153
- gprm.colModel.splice(0,1);
154
- }
155
- gprm.knv = null;
156
- if(gprm.treeGrid) {
157
- for (var key in gprm.treeReader) {
158
- if(gprm.treeReader.hasOwnProperty(key)) {
159
- gprm.colNames.splice(gprm.colNames.length-1);
160
- gprm.colModel.splice(gprm.colModel.length-1);
161
- }
162
- }
163
- }
164
- switch (o.exptype) {
165
- case 'xmlstring' :
166
- ret = "<"+o.root+">"+xmlJsonClass.json2xml(gprm,o.ident)+"</"+o.root+">";
167
- break;
168
- case 'jsonstring' :
169
- ret = "{"+ xmlJsonClass.toJson(gprm,o.root,o.ident)+"}";
170
- if(gprm.postData.filters !== undefined) {
171
- ret=ret.replace(/filters":"/,'filters":');
172
- ret=ret.replace(/}]}"/,'}]}');
173
- }
174
- break;
175
- }
176
- });
177
- return ret;
178
- },
179
- excelExport : function(o) {
180
- o = $.extend({
181
- exptype : "remote",
182
- url : null,
183
- oper: "oper",
184
- tag: "excel",
185
- exportOptions : {}
186
- }, o || {});
187
- return this.each(function(){
188
- if(!this.grid) { return;}
189
- var url;
190
- if(o.exptype == "remote") {
191
- var pdata = $.extend({},this.p.postData);
192
- pdata[o.oper] = o.tag;
193
- var params = jQuery.param(pdata);
194
- if(o.url.indexOf("?") != -1) { url = o.url+"&"+params; }
195
- else { url = o.url+"?"+params; }
196
- window.location = url;
197
- }
198
- });
199
- }
200
- });
1
+ ;(function($){
2
+ /*
3
+ * jqGrid extension for constructing Grid Data from external file
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
+ jqGridImport : function(o) {
12
+ o = $.extend({
13
+ imptype : "xml", // xml, json, xmlstring, jsonstring
14
+ impstring: "",
15
+ impurl: "",
16
+ mtype: "GET",
17
+ impData : {},
18
+ xmlGrid :{
19
+ config : "roots>grid",
20
+ data: "roots>rows"
21
+ },
22
+ jsonGrid :{
23
+ config : "grid",
24
+ data: "data"
25
+ },
26
+ ajaxOptions :{}
27
+ }, o || {});
28
+ return this.each(function(){
29
+ var $t = this;
30
+ var XmlConvert = function (xml,o) {
31
+ var cnfg = $(o.xmlGrid.config,xml)[0];
32
+ var xmldata = $(o.xmlGrid.data,xml)[0], jstr, jstr1;
33
+ if(xmlJsonClass.xml2json && $.jgrid.parse) {
34
+ jstr = xmlJsonClass.xml2json(cnfg," ");
35
+ jstr = $.jgrid.parse(jstr);
36
+ for(var key in jstr) {
37
+ if(jstr.hasOwnProperty(key)) {
38
+ jstr1=jstr[key];
39
+ }
40
+ }
41
+ if(xmldata) {
42
+ // save the datatype
43
+ var svdatatype = jstr.grid.datatype;
44
+ jstr.grid.datatype = 'xmlstring';
45
+ jstr.grid.datastr = xml;
46
+ $($t).jqGrid( jstr1 ).jqGrid("setGridParam",{datatype:svdatatype});
47
+ } else {
48
+ $($t).jqGrid( jstr1 );
49
+ }
50
+ jstr = null;jstr1=null;
51
+ } else {
52
+ alert("xml2json or parse are not present");
53
+ }
54
+ };
55
+ var JsonConvert = function (jsonstr,o){
56
+ if (jsonstr && typeof jsonstr == 'string') {
57
+ var json = $.jgrid.parse(jsonstr);
58
+ var gprm = json[o.jsonGrid.config];
59
+ var jdata = json[o.jsonGrid.data];
60
+ if(jdata) {
61
+ var svdatatype = gprm.datatype;
62
+ gprm.datatype = 'jsonstring';
63
+ gprm.datastr = jdata;
64
+ $($t).jqGrid( gprm ).jqGrid("setGridParam",{datatype:svdatatype});
65
+ } else {
66
+ $($t).jqGrid( gprm );
67
+ }
68
+ }
69
+ };
70
+ switch (o.imptype){
71
+ case 'xml':
72
+ $.ajax($.extend({
73
+ url:o.impurl,
74
+ type:o.mtype,
75
+ data: o.impData,
76
+ dataType:"xml",
77
+ complete: function(xml,stat) {
78
+ if(stat == 'success') {
79
+ XmlConvert(xml.responseXML,o);
80
+ if($.isFunction(o.importComplete)) {
81
+ o.importComplete(xml);
82
+ }
83
+ }
84
+ xml=null;
85
+ }
86
+ }, o.ajaxOptions));
87
+ break;
88
+ case 'xmlstring' :
89
+ // we need to make just the conversion and use the same code as xml
90
+ if(o.impstring && typeof o.impstring == 'string') {
91
+ var xmld = $.jgrid.stringToDoc(o.impstring);
92
+ if(xmld) {
93
+ XmlConvert(xmld,o);
94
+ if($.isFunction(o.importComplete)) {
95
+ o.importComplete(xmld);
96
+ }
97
+ o.impstring = null;
98
+ }
99
+ xmld = null;
100
+ }
101
+ break;
102
+ case 'json':
103
+ $.ajax($.extend({
104
+ url:o.impurl,
105
+ type:o.mtype,
106
+ data: o.impData,
107
+ dataType:"json",
108
+ complete: function(json,stat) {
109
+ if(stat == 'success') {
110
+ JsonConvert(json.responseText,o );
111
+ if($.isFunction(o.importComplete)) {
112
+ o.importComplete(json);
113
+ }
114
+ }
115
+ json=null;
116
+ }
117
+ }, o.ajaxOptions ));
118
+ break;
119
+ case 'jsonstring' :
120
+ if(o.impstring && typeof o.impstring == 'string') {
121
+ JsonConvert(o.impstring,o );
122
+ if($.isFunction(o.importComplete)) {
123
+ o.importComplete(o.impstring);
124
+ }
125
+ o.impstring = null;
126
+ }
127
+ break;
128
+ }
129
+ });
130
+ },
131
+ jqGridExport : function(o) {
132
+ o = $.extend({
133
+ exptype : "xmlstring",
134
+ root: "grid",
135
+ ident: "\t"
136
+ }, o || {});
137
+ var ret = null;
138
+ this.each(function () {
139
+ if(!this.grid) { return;}
140
+ var gprm = $.extend({},$(this).jqGrid("getGridParam"));
141
+ // we need to check for:
142
+ // 1.multiselect, 2.subgrid 3. treegrid and remove the unneded columns from colNames
143
+ if(gprm.rownumbers) {
144
+ gprm.colNames.splice(0,1);
145
+ gprm.colModel.splice(0,1);
146
+ }
147
+ if(gprm.multiselect) {
148
+ gprm.colNames.splice(0,1);
149
+ gprm.colModel.splice(0,1);
150
+ }
151
+ if(gprm.subGrid) {
152
+ gprm.colNames.splice(0,1);
153
+ gprm.colModel.splice(0,1);
154
+ }
155
+ gprm.knv = null;
156
+ if(gprm.treeGrid) {
157
+ for (var key in gprm.treeReader) {
158
+ if(gprm.treeReader.hasOwnProperty(key)) {
159
+ gprm.colNames.splice(gprm.colNames.length-1);
160
+ gprm.colModel.splice(gprm.colModel.length-1);
161
+ }
162
+ }
163
+ }
164
+ switch (o.exptype) {
165
+ case 'xmlstring' :
166
+ ret = "<"+o.root+">"+xmlJsonClass.json2xml(gprm,o.ident)+"</"+o.root+">";
167
+ break;
168
+ case 'jsonstring' :
169
+ ret = "{"+ xmlJsonClass.toJson(gprm,o.root,o.ident)+"}";
170
+ if(gprm.postData.filters !== undefined) {
171
+ ret=ret.replace(/filters":"/,'filters":');
172
+ ret=ret.replace(/}]}"/,'}]}');
173
+ }
174
+ break;
175
+ }
176
+ });
177
+ return ret;
178
+ },
179
+ excelExport : function(o) {
180
+ o = $.extend({
181
+ exptype : "remote",
182
+ url : null,
183
+ oper: "oper",
184
+ tag: "excel",
185
+ exportOptions : {}
186
+ }, o || {});
187
+ return this.each(function(){
188
+ if(!this.grid) { return;}
189
+ var url;
190
+ if(o.exptype == "remote") {
191
+ var pdata = $.extend({},this.p.postData);
192
+ pdata[o.oper] = o.tag;
193
+ var params = jQuery.param(pdata);
194
+ if(o.url.indexOf("?") != -1) { url = o.url+"&"+params; }
195
+ else { url = o.url+"?"+params; }
196
+ window.location = url;
197
+ }
198
+ });
199
+ }
200
+ });
201
201
  })(jQuery);