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,3003 @@
|
|
1
|
+
;(function ($) {
|
2
|
+
/*
|
3
|
+
* jqGrid 3.7.2 - jQuery Grid
|
4
|
+
* Copyright (c) 2008, Tony Tomov, tony@trirand.com
|
5
|
+
* Dual licensed under the MIT and GPL licenses
|
6
|
+
* http://www.opensource.org/licenses/mit-license.php
|
7
|
+
* http://www.gnu.org/licenses/gpl-2.0.html
|
8
|
+
* Date: 2010-07-12
|
9
|
+
*/
|
10
|
+
$.jgrid = $.jgrid || {};
|
11
|
+
$.extend($.jgrid,{
|
12
|
+
htmlDecode : function(value){
|
13
|
+
if(value==' ' || value==' ' || (value.length==1 && value.charCodeAt(0)==160)) { return "";}
|
14
|
+
return !value ? value : String(value).replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, '"');
|
15
|
+
},
|
16
|
+
htmlEncode : function (value){
|
17
|
+
return !value ? value : String(value).replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/\"/g, """);
|
18
|
+
},
|
19
|
+
format : function(format){ //jqgformat
|
20
|
+
var args = $.makeArray(arguments).slice(1);
|
21
|
+
if(format===undefined) { format = ""; }
|
22
|
+
return format.replace(/\{(\d+)\}/g, function(m, i){
|
23
|
+
return args[i];
|
24
|
+
});
|
25
|
+
},
|
26
|
+
getCellIndex : function (cell) {
|
27
|
+
var c = $(cell);
|
28
|
+
if (c.is('tr')) { return -1; }
|
29
|
+
c = (!c.is('td') && !c.is('th') ? c.closest("td,th") : c)[0];
|
30
|
+
if ($.browser.msie) { return $.inArray(c, c.parentNode.cells); }
|
31
|
+
return c.cellIndex;
|
32
|
+
},
|
33
|
+
stripHtml : function(v) {
|
34
|
+
v = v+"";
|
35
|
+
var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
|
36
|
+
if (v) {
|
37
|
+
v = v.replace(regexp,"");
|
38
|
+
return (v && v !== ' ' && v !== ' ') ? v.replace(/\"/g,"'") : "";
|
39
|
+
} else {
|
40
|
+
return v;
|
41
|
+
}
|
42
|
+
},
|
43
|
+
stringToDoc : function (xmlString) {
|
44
|
+
var xmlDoc;
|
45
|
+
if(typeof xmlString !== 'string') { return xmlString; }
|
46
|
+
try {
|
47
|
+
var parser = new DOMParser();
|
48
|
+
xmlDoc = parser.parseFromString(xmlString,"text/xml");
|
49
|
+
}
|
50
|
+
catch(e) {
|
51
|
+
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
|
52
|
+
xmlDoc.async=false;
|
53
|
+
xmlDoc.loadXML(xmlString);
|
54
|
+
}
|
55
|
+
return (xmlDoc && xmlDoc.documentElement && xmlDoc.documentElement.tagName != 'parsererror') ? xmlDoc : null;
|
56
|
+
},
|
57
|
+
parse : function(jsonString) {
|
58
|
+
var js = jsonString;
|
59
|
+
if (js.substr(0,9) == "while(1);") { js = js.substr(9); }
|
60
|
+
if (js.substr(0,2) == "/*") { js = js.substr(2,js.length-4); }
|
61
|
+
if(!js) { js = "{}"; }
|
62
|
+
return ($.jgrid.useJSON===true && typeof (JSON) === 'object' && typeof (JSON.parse) === 'function') ?
|
63
|
+
JSON.parse(js) :
|
64
|
+
eval('(' + js + ')');
|
65
|
+
},
|
66
|
+
parseDate : function(format, date) {
|
67
|
+
var tsp = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0},k,hl,dM, ft;
|
68
|
+
if(date && date !== null && date !== undefined){
|
69
|
+
date = $.trim(date);
|
70
|
+
date = date.split(/[\\\/:_;.\t\T\s-]/);
|
71
|
+
format = format.split(/[\\\/:_;.\t\T\s-]/);
|
72
|
+
var dfmt = $.jgrid.formatter.date.monthNames;
|
73
|
+
var afmt = $.jgrid.formatter.date.AmPm;
|
74
|
+
var h12to24 = function(ampm, h){
|
75
|
+
if (ampm === 0){ if (h == 12) { h = 0;} }
|
76
|
+
else { if (h != 12) { h += 12; } }
|
77
|
+
return h;
|
78
|
+
};
|
79
|
+
for(k=0,hl=format.length;k<hl;k++){
|
80
|
+
if(format[k] == 'M') {
|
81
|
+
dM = $.inArray(date[k],dfmt);
|
82
|
+
if(dM !== -1 && dM < 12){date[k] = dM+1;}
|
83
|
+
}
|
84
|
+
if(format[k] == 'F') {
|
85
|
+
dM = $.inArray(date[k],dfmt);
|
86
|
+
if(dM !== -1 && dM > 11){date[k] = dM+1-12;}
|
87
|
+
}
|
88
|
+
if(format[k] == 'a') {
|
89
|
+
dM = $.inArray(date[k],afmt);
|
90
|
+
if(dM !== -1 && dM < 2 && date[k] == afmt[dM]){
|
91
|
+
date[k] = dM;
|
92
|
+
tsp.h = h12to24(date[k], tsp.h);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
if(format[k] == 'A') {
|
96
|
+
dM = $.inArray(date[k],afmt);
|
97
|
+
if(dM !== -1 && dM > 1 && date[k] == afmt[dM]){
|
98
|
+
date[k] = dM-2;
|
99
|
+
tsp.h = h12to24(date[k], tsp.h);
|
100
|
+
}
|
101
|
+
}
|
102
|
+
if(date[k] !== undefined) {
|
103
|
+
tsp[format[k].toLowerCase()] = parseInt(date[k],10);
|
104
|
+
}
|
105
|
+
}
|
106
|
+
tsp.m = parseInt(tsp.m,10)-1;
|
107
|
+
var ty = tsp.y;
|
108
|
+
if (ty >= 70 && ty <= 99) {tsp.y = 1900+tsp.y;}
|
109
|
+
else if (ty >=0 && ty <=69) {tsp.y= 2000+tsp.y;}
|
110
|
+
}
|
111
|
+
return new Date(tsp.y, tsp.m, tsp.d, tsp.h, tsp.i, tsp.s,0);
|
112
|
+
},
|
113
|
+
jqID : function(sid){
|
114
|
+
sid = sid + "";
|
115
|
+
return sid.replace(/([\.\:\[\]])/g,"\\$1");
|
116
|
+
},
|
117
|
+
getAccessor : function(obj, expr) {
|
118
|
+
var ret,p,prm, i;
|
119
|
+
if( typeof expr === 'function') { return expr(obj); }
|
120
|
+
ret = obj[expr];
|
121
|
+
if(ret===undefined) {
|
122
|
+
try {
|
123
|
+
if ( typeof expr === 'string' ) {
|
124
|
+
prm = expr.split('.');
|
125
|
+
}
|
126
|
+
i = prm.length;
|
127
|
+
if( i ) {
|
128
|
+
ret = obj;
|
129
|
+
while (ret && i--) {
|
130
|
+
p = prm.shift();
|
131
|
+
ret = ret[p];
|
132
|
+
}
|
133
|
+
}
|
134
|
+
} catch (e) {}
|
135
|
+
}
|
136
|
+
return ret;
|
137
|
+
},
|
138
|
+
ajaxOptions: {},
|
139
|
+
from : function(source,initalQuery){
|
140
|
+
// Original Author Hugo Bonacci
|
141
|
+
// License MIT http://jlinq.codeplex.com/license
|
142
|
+
var queryObject=function(d,q){
|
143
|
+
if(typeof(d)=="string"){
|
144
|
+
d=$.data(d);
|
145
|
+
}
|
146
|
+
var self=this,
|
147
|
+
_data=d,
|
148
|
+
_usecase=true,
|
149
|
+
_trim=false,
|
150
|
+
_query=q,
|
151
|
+
_stripNum = /[\$,%]/g,
|
152
|
+
_lastCommand=null,
|
153
|
+
_lastField=null,
|
154
|
+
_negate=false,
|
155
|
+
_queuedOperator="",
|
156
|
+
_sorting=[],
|
157
|
+
_useProperties=true;
|
158
|
+
if(typeof(d)=="object"&&d.push) {
|
159
|
+
if(d.length>0){
|
160
|
+
if(typeof(d[0])!="object"){
|
161
|
+
_useProperties=false;
|
162
|
+
}else{
|
163
|
+
_useProperties=true;
|
164
|
+
}
|
165
|
+
}
|
166
|
+
}else{
|
167
|
+
throw "data provides is not an array";
|
168
|
+
}
|
169
|
+
this._hasData=function(){
|
170
|
+
return _data===null?false:_data.length===0?false:true;
|
171
|
+
};
|
172
|
+
this._getStr=function(s){
|
173
|
+
var phrase=[];
|
174
|
+
if(_trim){
|
175
|
+
phrase.push("jQuery.trim(");
|
176
|
+
}
|
177
|
+
phrase.push("String("+s+")");
|
178
|
+
if(_trim){
|
179
|
+
phrase.push(")");
|
180
|
+
}
|
181
|
+
if(!_usecase){
|
182
|
+
phrase.push(".toLowerCase()");
|
183
|
+
}
|
184
|
+
return phrase.join("");
|
185
|
+
};
|
186
|
+
this._strComp=function(val){
|
187
|
+
if(typeof(val)=="string"){
|
188
|
+
return".toString()";
|
189
|
+
}else{
|
190
|
+
return"";
|
191
|
+
}
|
192
|
+
};
|
193
|
+
this._group=function(f,u){
|
194
|
+
return({field:f.toString(),unique:u,items:[]});
|
195
|
+
};
|
196
|
+
this._toStr=function(phrase){
|
197
|
+
if(_trim){
|
198
|
+
phrase=$.trim(phrase);
|
199
|
+
}
|
200
|
+
if(!_usecase){
|
201
|
+
phrase=phrase.toLowerCase();
|
202
|
+
}
|
203
|
+
phrase=phrase.toString().replace(new RegExp('\\"',"g"),'\\"');
|
204
|
+
return phrase;
|
205
|
+
};
|
206
|
+
this._funcLoop=function(func){
|
207
|
+
var results=[];
|
208
|
+
$.each(_data,function(i,v){
|
209
|
+
results.push(func(v));
|
210
|
+
});
|
211
|
+
return results;
|
212
|
+
};
|
213
|
+
this._append=function(s){
|
214
|
+
if(_query===null){
|
215
|
+
_query="";
|
216
|
+
} else {
|
217
|
+
_query+=_queuedOperator==""?" && ":_queuedOperator;
|
218
|
+
}
|
219
|
+
if(_negate){
|
220
|
+
_query+="!";
|
221
|
+
}
|
222
|
+
_query+="("+s+")";
|
223
|
+
_negate=false;
|
224
|
+
_queuedOperator="";
|
225
|
+
};
|
226
|
+
this._setCommand=function(f,c){
|
227
|
+
_lastCommand=f;
|
228
|
+
_lastField=c;
|
229
|
+
};
|
230
|
+
this._resetNegate=function(){
|
231
|
+
_negate=false;
|
232
|
+
};
|
233
|
+
this._repeatCommand=function(f,v){
|
234
|
+
if(_lastCommand===null){
|
235
|
+
return self;
|
236
|
+
}
|
237
|
+
if(f!=null&&v!=null){
|
238
|
+
return _lastCommand(f,v);
|
239
|
+
}
|
240
|
+
if(_lastField===null){
|
241
|
+
return _lastCommand(f);
|
242
|
+
}
|
243
|
+
if(!_useProperties){
|
244
|
+
return _lastCommand(f);
|
245
|
+
}
|
246
|
+
return _lastCommand(_lastField,f);
|
247
|
+
};
|
248
|
+
this._equals=function(a,b){
|
249
|
+
return(self._compare(a,b,1)===0);
|
250
|
+
};
|
251
|
+
this._compare=function(a,b,d){
|
252
|
+
if( d === undefined) { d = 1; }
|
253
|
+
if(a===undefined) { a = null; }
|
254
|
+
if(b===undefined) { b = null; }
|
255
|
+
if(a===null && b===null){
|
256
|
+
return 0;
|
257
|
+
}
|
258
|
+
if(a===null&&b!==null){
|
259
|
+
return 1;
|
260
|
+
}
|
261
|
+
if(a!==null&&b===null){
|
262
|
+
return -1;
|
263
|
+
}
|
264
|
+
if(!_usecase) {
|
265
|
+
a=a.toLowerCase();
|
266
|
+
b=b.toLowerCase();
|
267
|
+
}
|
268
|
+
if(a<b){return -d;}
|
269
|
+
if(a>b){return d;}
|
270
|
+
return 0;
|
271
|
+
};
|
272
|
+
this._performSort=function(){
|
273
|
+
if(_sorting.length===0){return;}
|
274
|
+
_data=self._doSort(_data,0);
|
275
|
+
};
|
276
|
+
this._doSort=function(d,q){
|
277
|
+
var by=_sorting[q].by,
|
278
|
+
dir=_sorting[q].dir,
|
279
|
+
type = _sorting[q].type,
|
280
|
+
dfmt = _sorting[q].datefmt;
|
281
|
+
if(q==_sorting.length-1){
|
282
|
+
return self._getOrder(d, by, dir, type, dfmt);
|
283
|
+
}
|
284
|
+
q++;
|
285
|
+
var values=self._getGroup(d,by,dir,type,dfmt);
|
286
|
+
var results=[];
|
287
|
+
for(var i=0;i<values.length;i++){
|
288
|
+
var sorted=self._doSort(values[i].items,q);
|
289
|
+
for(var j=0;j<sorted.length;j++){
|
290
|
+
results.push(sorted[j]);
|
291
|
+
}
|
292
|
+
}
|
293
|
+
return results;
|
294
|
+
};
|
295
|
+
this._getOrder=function(data,by,dir,type, dfmt){
|
296
|
+
var sortData=[],_sortData=[], newDir = dir=="a" ? 1 : -1, i,ab,j,
|
297
|
+
findSortKey;
|
298
|
+
|
299
|
+
if(type === undefined ) { type = "text"; }
|
300
|
+
if (type == 'float' || type== 'number' || type== 'currency' || type== 'numeric') {
|
301
|
+
findSortKey = function($cell) {
|
302
|
+
var key = parseFloat( String($cell).replace(_stripNum, ''));
|
303
|
+
return isNaN(key) ? 0.00 : key;
|
304
|
+
};
|
305
|
+
} else if (type=='int' || type=='integer') {
|
306
|
+
findSortKey = function($cell) {
|
307
|
+
return $cell ? parseFloat(String($cell).replace(_stripNum, '')) : 0;
|
308
|
+
};
|
309
|
+
} else if(type == 'date' || type == 'datetime') {
|
310
|
+
findSortKey = function($cell) {
|
311
|
+
return $.jgrid.parseDate(dfmt,$cell).getTime();
|
312
|
+
};
|
313
|
+
} else {
|
314
|
+
findSortKey = function($cell) {
|
315
|
+
if(!$cell) {$cell ="";}
|
316
|
+
return $.trim($cell.toUpperCase());
|
317
|
+
};
|
318
|
+
}
|
319
|
+
$.each(data,function(i,v){
|
320
|
+
ab = $.jgrid.getAccessor(v,by);
|
321
|
+
if(ab === undefined) { ab = ""; }
|
322
|
+
ab = findSortKey(ab);
|
323
|
+
_sortData.push({ 'vSort': ab,'index':i});
|
324
|
+
});
|
325
|
+
|
326
|
+
_sortData.sort(function(a,b){
|
327
|
+
a = a.vSort;
|
328
|
+
b = b.vSort;
|
329
|
+
return self._compare(a,b,newDir);
|
330
|
+
});
|
331
|
+
j=0;
|
332
|
+
var nrec= data.length;
|
333
|
+
// overhead, but we do not change the original data.
|
334
|
+
while(j<nrec) {
|
335
|
+
i = _sortData[j].index;
|
336
|
+
sortData.push(data[i]);
|
337
|
+
j++;
|
338
|
+
}
|
339
|
+
return sortData;
|
340
|
+
};
|
341
|
+
this._getGroup=function(data,by,dir,type, dfmt){
|
342
|
+
var results=[],
|
343
|
+
group=null,
|
344
|
+
last=null, val;
|
345
|
+
$.each(self._getOrder(data,by,dir,type, dfmt),function(i,v){
|
346
|
+
val = $.jgrid.getAccessor(v, by);
|
347
|
+
if(val === undefined) { val = ""; }
|
348
|
+
if(!self._equals(last,val)){
|
349
|
+
last=val;
|
350
|
+
if(group!=null){
|
351
|
+
results.push(group);
|
352
|
+
}
|
353
|
+
group=self._group(by,val);
|
354
|
+
}
|
355
|
+
group.items.push(v);
|
356
|
+
});
|
357
|
+
if(group!=null){
|
358
|
+
results.push(group);
|
359
|
+
}
|
360
|
+
return results;
|
361
|
+
};
|
362
|
+
this.ignoreCase=function(){
|
363
|
+
_usecase=false;
|
364
|
+
return self;
|
365
|
+
};
|
366
|
+
this.useCase=function(){
|
367
|
+
_usecase=true;
|
368
|
+
return self;
|
369
|
+
};
|
370
|
+
this.trim=function(){
|
371
|
+
_trim=true;
|
372
|
+
return self;
|
373
|
+
};
|
374
|
+
this.noTrim=function(){
|
375
|
+
_trim=false;
|
376
|
+
return self;
|
377
|
+
};
|
378
|
+
this.combine=function(f){
|
379
|
+
var q=$.from(_data);
|
380
|
+
if(!_usecase){ q.ignoreCase(); }
|
381
|
+
if(_trim){ q.trim(); }
|
382
|
+
result=f(q).showQuery();
|
383
|
+
self._append(result);
|
384
|
+
return self;
|
385
|
+
};
|
386
|
+
this.execute=function(){
|
387
|
+
var match=_query, results=[];
|
388
|
+
if(match === null){
|
389
|
+
return self;
|
390
|
+
}
|
391
|
+
$.each(_data,function(i){
|
392
|
+
if(eval(match)){results.push(this);}
|
393
|
+
});
|
394
|
+
_data=results;
|
395
|
+
return self;
|
396
|
+
};
|
397
|
+
this.data=function(){
|
398
|
+
return _data;
|
399
|
+
};
|
400
|
+
this.select=function(f){
|
401
|
+
self._performSort();
|
402
|
+
if(!self._hasData()){ return[]; }
|
403
|
+
self.execute();
|
404
|
+
if($.isFunction(f)){
|
405
|
+
var results=[];
|
406
|
+
$.each(_data,function(i,v){
|
407
|
+
results.push(f(v));
|
408
|
+
});
|
409
|
+
return results;
|
410
|
+
}
|
411
|
+
return _data;
|
412
|
+
};
|
413
|
+
this.hasMatch=function(f){
|
414
|
+
if(!self._hasData()) { return false; }
|
415
|
+
self.execute();
|
416
|
+
return _data.length>0;
|
417
|
+
};
|
418
|
+
this.showQuery=function(cmd){
|
419
|
+
var queryString=_query;
|
420
|
+
if(queryString === null) { queryString="no query found"; }
|
421
|
+
if($.isFunction(cmd)){
|
422
|
+
cmd(queryString);return self;
|
423
|
+
}
|
424
|
+
return queryString;
|
425
|
+
};
|
426
|
+
this.andNot=function(f,v,x){
|
427
|
+
_negate=!_negate;
|
428
|
+
return self.and(f,v,x);
|
429
|
+
};
|
430
|
+
this.orNot=function(f,v,x){
|
431
|
+
_negate=!_negate;
|
432
|
+
return self.or(f,v,x);
|
433
|
+
};
|
434
|
+
this.not=function(f,v,x){
|
435
|
+
return self.andNot(f,v,x);
|
436
|
+
};
|
437
|
+
this.and=function(f,v,x){
|
438
|
+
_queuedOperator=" && ";
|
439
|
+
if(f===undefined){
|
440
|
+
return self;
|
441
|
+
}
|
442
|
+
return self._repeatCommand(f,v,x);
|
443
|
+
};
|
444
|
+
this.or=function(f,v,x){
|
445
|
+
_queuedOperator=" || ";
|
446
|
+
if(f===undefined) { return self; }
|
447
|
+
return self._repeatCommand(f,v,x);
|
448
|
+
};
|
449
|
+
this.isNot=function(f){
|
450
|
+
_negate=!_negate;
|
451
|
+
return self.is(f);
|
452
|
+
};
|
453
|
+
this.is=function(f){
|
454
|
+
self._append('this.'+f);
|
455
|
+
self._resetNegate();
|
456
|
+
return self;
|
457
|
+
};
|
458
|
+
this._compareValues=function(func,f,v,how,t){
|
459
|
+
var fld;
|
460
|
+
if(_useProperties){
|
461
|
+
fld='this.'+f;
|
462
|
+
}else{
|
463
|
+
fld='this';
|
464
|
+
}
|
465
|
+
if(v===undefined) { v = null; }
|
466
|
+
var val=v===null?f:v,
|
467
|
+
swst = t.stype === undefined ? "text" : t.stype;
|
468
|
+
switch(swst) {
|
469
|
+
case 'int':
|
470
|
+
case 'integer':
|
471
|
+
val = isNaN(Number(val)) ? '0' : val; // To be fixed with more inteligent code
|
472
|
+
fld = 'parseInt('+fld+',10)';
|
473
|
+
val = 'parseInt('+val+',10)';
|
474
|
+
break;
|
475
|
+
case 'float':
|
476
|
+
case 'number':
|
477
|
+
case 'numeric':
|
478
|
+
val = String(val).replace(_stripNum, '');
|
479
|
+
val = isNaN(Number(val)) ? '0' : val; // To be fixed with more inteligent code
|
480
|
+
fld = 'parseFloat('+fld+')';
|
481
|
+
val = 'parseFloat('+val+')';
|
482
|
+
break;
|
483
|
+
case 'date':
|
484
|
+
case 'datetime':
|
485
|
+
val = String($.jgrid.parseDate(t.newfmt || 'Y-m-d',val).getTime());
|
486
|
+
fld = 'jQuery.jgrid.parseDate("'+t.srcfmt+'",'+fld+').getTime()';
|
487
|
+
break;
|
488
|
+
default :
|
489
|
+
fld=self._getStr(fld);
|
490
|
+
val=self._getStr('"'+self._toStr(val)+'"');
|
491
|
+
}
|
492
|
+
self._append(fld+' '+how+' '+val);
|
493
|
+
self._setCommand(func,f);
|
494
|
+
self._resetNegate();
|
495
|
+
return self;
|
496
|
+
};
|
497
|
+
this.equals=function(f,v,t){
|
498
|
+
return self._compareValues(self.equals,f,v,"==",t);
|
499
|
+
};
|
500
|
+
this.greater=function(f,v,t){
|
501
|
+
return self._compareValues(self.greater,f,v,">",t);
|
502
|
+
};
|
503
|
+
this.less=function(f,v,t){
|
504
|
+
return self._compareValues(self.less,f,v,"<",t);
|
505
|
+
};
|
506
|
+
this.greaterOrEquals=function(f,v,t){
|
507
|
+
return self._compareValues(self.greaterOrEquals,f,v,">=",t);
|
508
|
+
};
|
509
|
+
this.lessOrEquals=function(f,v,t){
|
510
|
+
return self._compareValues(self.lessOrEquals,f,v,"<=",t);
|
511
|
+
};
|
512
|
+
this.startsWith=function(f,v){
|
513
|
+
var val = (v===undefined || v===null) ? f: v,
|
514
|
+
length=_trim ? $.trim(val.toString()).length : val.toString().length;
|
515
|
+
if(_useProperties){
|
516
|
+
self._append(self._getStr('this.'+f)+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(v)+'"'));
|
517
|
+
}else{
|
518
|
+
length=_trim?$.trim(v.toString()).length:v.toString().length;
|
519
|
+
self._append(self._getStr('this')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(f)+'"'));
|
520
|
+
}
|
521
|
+
self._setCommand(self.startsWith,f);
|
522
|
+
self._resetNegate();
|
523
|
+
return self;
|
524
|
+
};
|
525
|
+
this.endsWith=function(f,v){
|
526
|
+
var val = (v===undefined || v===null) ? f: v,
|
527
|
+
length=_trim ? $.trim(val.toString()).length:val.toString().length;
|
528
|
+
if(_useProperties){
|
529
|
+
self._append(self._getStr('this.'+f)+'.substr('+self._getStr('this.'+f)+'.length-'+length+','+length+') == "'+self._toStr(v)+'"');
|
530
|
+
} else {
|
531
|
+
self._append(self._getStr('this')+'.substr('+self._getStr('this')+'.length-"'+self._toStr(f)+'".length,"'+self._toStr(f)+'".length) == "'+self._toStr(f)+'"');
|
532
|
+
}
|
533
|
+
self._setCommand(self.endsWith,f);self._resetNegate();
|
534
|
+
return self;
|
535
|
+
};
|
536
|
+
this.contains=function(f,v){
|
537
|
+
if(_useProperties){
|
538
|
+
self._append(self._getStr('this.'+f)+'.indexOf("'+self._toStr(v)+'",0) > -1');
|
539
|
+
}else{
|
540
|
+
self._append(self._getStr('this')+'.indexOf("'+self._toStr(f)+'",0) > -1');
|
541
|
+
}
|
542
|
+
self._setCommand(self.contains,f);
|
543
|
+
self._resetNegate();
|
544
|
+
return self;
|
545
|
+
};
|
546
|
+
this.where=function(cmd){
|
547
|
+
if($.isFunction(cmd)){
|
548
|
+
self.execute();
|
549
|
+
var results=[];
|
550
|
+
$.each(_data,function(i,v){
|
551
|
+
if(cmd(v)){
|
552
|
+
results.push(v);
|
553
|
+
}
|
554
|
+
});
|
555
|
+
return $.from(results,self.showQuery());
|
556
|
+
}
|
557
|
+
self._append(cmd);
|
558
|
+
self._setCommand(this.where,null);
|
559
|
+
self._resetNegate();
|
560
|
+
return self;
|
561
|
+
};
|
562
|
+
this.groupBy=function(by,dir,type, datefmt){
|
563
|
+
if(!self._hasData()){
|
564
|
+
return null;
|
565
|
+
}
|
566
|
+
return self._getGroup(_data,by,dir,type, datefmt);
|
567
|
+
};
|
568
|
+
this.distinct=function(by,dir){
|
569
|
+
var groups=self.groupBy(by,dir);
|
570
|
+
var results=[];
|
571
|
+
$.each(groups,function(i,v){
|
572
|
+
results.push(v.unique);
|
573
|
+
});
|
574
|
+
return results;
|
575
|
+
};
|
576
|
+
this.orderBy=function(by,dir,stype, dfmt){
|
577
|
+
dir = dir === undefined || dir === null ? "a" :$.trim(dir.toString().toLowerCase());
|
578
|
+
if(stype === null || stype === undefined) { stype = "text"; }
|
579
|
+
if(dfmt === null || dfmt === undefined) { dfmt = "Y-m-d"; }
|
580
|
+
if(dir=="desc"||dir=="descending"){dir="d";}
|
581
|
+
if(dir=="asc"||dir=="ascending"){dir="a";}
|
582
|
+
_sorting.push({by:by,dir:dir,type:stype, datefmt: dfmt});
|
583
|
+
return self;
|
584
|
+
};
|
585
|
+
return self;
|
586
|
+
};
|
587
|
+
return new queryObject(source,null);
|
588
|
+
},
|
589
|
+
extend : function(methods) {
|
590
|
+
$.extend($.fn.jqGrid,methods);
|
591
|
+
if (!this.no_legacy_api) {
|
592
|
+
$.fn.extend(methods);
|
593
|
+
}
|
594
|
+
}
|
595
|
+
});
|
596
|
+
|
597
|
+
$.fn.jqGrid = function( pin ) {
|
598
|
+
if (typeof pin == 'string') {
|
599
|
+
var fn = $.fn.jqGrid[pin];
|
600
|
+
if (!fn) {
|
601
|
+
throw ("jqGrid - No such method: " + pin);
|
602
|
+
}
|
603
|
+
var args = $.makeArray(arguments).slice(1);
|
604
|
+
return fn.apply(this,args);
|
605
|
+
}
|
606
|
+
return this.each( function() {
|
607
|
+
if(this.grid) {return;}
|
608
|
+
|
609
|
+
var p = $.extend(true,{
|
610
|
+
url: "",
|
611
|
+
height: 150,
|
612
|
+
page: 1,
|
613
|
+
rowNum: 20,
|
614
|
+
rowTotal : null,
|
615
|
+
records: 0,
|
616
|
+
pager: "",
|
617
|
+
pgbuttons: true,
|
618
|
+
pginput: true,
|
619
|
+
colModel: [],
|
620
|
+
rowList: [],
|
621
|
+
colNames: [],
|
622
|
+
sortorder: "asc",
|
623
|
+
sortname: "",
|
624
|
+
datatype: "xml",
|
625
|
+
mtype: "GET",
|
626
|
+
altRows: false,
|
627
|
+
selarrrow: [],
|
628
|
+
savedRow: [],
|
629
|
+
shrinkToFit: true,
|
630
|
+
xmlReader: {},
|
631
|
+
jsonReader: {},
|
632
|
+
subGrid: false,
|
633
|
+
subGridModel :[],
|
634
|
+
reccount: 0,
|
635
|
+
lastpage: 0,
|
636
|
+
lastsort: 0,
|
637
|
+
selrow: null,
|
638
|
+
beforeSelectRow: null,
|
639
|
+
onSelectRow: null,
|
640
|
+
onSortCol: null,
|
641
|
+
ondblClickRow: null,
|
642
|
+
onRightClickRow: null,
|
643
|
+
onPaging: null,
|
644
|
+
onSelectAll: null,
|
645
|
+
loadComplete: null,
|
646
|
+
gridComplete: null,
|
647
|
+
loadError: null,
|
648
|
+
loadBeforeSend: null,
|
649
|
+
afterInsertRow: null,
|
650
|
+
beforeRequest: null,
|
651
|
+
onHeaderClick: null,
|
652
|
+
viewrecords: false,
|
653
|
+
loadonce: false,
|
654
|
+
multiselect: false,
|
655
|
+
multikey: false,
|
656
|
+
editurl: null,
|
657
|
+
search: false,
|
658
|
+
caption: "",
|
659
|
+
hidegrid: true,
|
660
|
+
hiddengrid: false,
|
661
|
+
postData: {},
|
662
|
+
userData: {},
|
663
|
+
treeGrid : false,
|
664
|
+
treeGridModel : 'nested',
|
665
|
+
treeReader : {},
|
666
|
+
treeANode : -1,
|
667
|
+
ExpandColumn: null,
|
668
|
+
tree_root_level : 0,
|
669
|
+
prmNames: {page:"page",rows:"rows", sort: "sidx",order: "sord", search:"_search", nd:"nd", id:"id",oper:"oper",editoper:"edit",addoper:"add",deloper:"del", subgridid:"id", npage: null, totalrows:"totalrows"},
|
670
|
+
forceFit : false,
|
671
|
+
gridstate : "visible",
|
672
|
+
cellEdit: false,
|
673
|
+
cellsubmit: "remote",
|
674
|
+
nv:0,
|
675
|
+
loadui: "enable",
|
676
|
+
toolbar: [false,""],
|
677
|
+
scroll: false,
|
678
|
+
multiboxonly : false,
|
679
|
+
deselectAfterSort : true,
|
680
|
+
scrollrows : false,
|
681
|
+
autowidth: false,
|
682
|
+
scrollOffset :18,
|
683
|
+
cellLayout: 5,
|
684
|
+
subGridWidth: 20,
|
685
|
+
multiselectWidth: 20,
|
686
|
+
gridview: false,
|
687
|
+
rownumWidth: 25,
|
688
|
+
rownumbers : false,
|
689
|
+
pagerpos: 'center',
|
690
|
+
recordpos: 'right',
|
691
|
+
footerrow : false,
|
692
|
+
userDataOnFooter : false,
|
693
|
+
hoverrows : true,
|
694
|
+
altclass : 'ui-priority-secondary',
|
695
|
+
viewsortcols : [false,'vertical',true],
|
696
|
+
resizeclass : '',
|
697
|
+
autoencode : false,
|
698
|
+
remapColumns : [],
|
699
|
+
ajaxGridOptions :{},
|
700
|
+
direction : "ltr",
|
701
|
+
toppager: false,
|
702
|
+
headertitles: false,
|
703
|
+
scrollTimeout: 200,
|
704
|
+
data : [],
|
705
|
+
_index : {}
|
706
|
+
}, $.jgrid.defaults, pin || {});
|
707
|
+
var grid={
|
708
|
+
headers:[],
|
709
|
+
cols:[],
|
710
|
+
footers: [],
|
711
|
+
dragStart: function(i,x,y) {
|
712
|
+
this.resizing = { idx: i, startX: x.clientX, sOL : y[0]};
|
713
|
+
this.hDiv.style.cursor = "col-resize";
|
714
|
+
this.curGbox = $("#rs_m"+p.id,"#gbox_"+p.id);
|
715
|
+
this.curGbox.css({display:"block",left:y[0],top:y[1],height:y[2]});
|
716
|
+
if($.isFunction(p.resizeStart)) { p.resizeStart.call(this,x,i); }
|
717
|
+
document.onselectstart=function(){return false;};
|
718
|
+
},
|
719
|
+
dragMove: function(x) {
|
720
|
+
if(this.resizing) {
|
721
|
+
var diff = x.clientX-this.resizing.startX,
|
722
|
+
h = this.headers[this.resizing.idx],
|
723
|
+
newWidth = p.direction === "ltr" ? h.width + diff : h.width - diff, hn, nWn;
|
724
|
+
if(newWidth > 33) {
|
725
|
+
this.curGbox.css({left:this.resizing.sOL+diff});
|
726
|
+
if(p.forceFit===true ){
|
727
|
+
hn = this.headers[this.resizing.idx+p.nv];
|
728
|
+
nWn = p.direction === "ltr" ? hn.width - diff : hn.width + diff;
|
729
|
+
if(nWn >33) {
|
730
|
+
h.newWidth = newWidth;
|
731
|
+
hn.newWidth = nWn;
|
732
|
+
}
|
733
|
+
} else {
|
734
|
+
this.newWidth = p.direction === "ltr" ? p.tblwidth+diff : p.tblwidth-diff;
|
735
|
+
h.newWidth = newWidth;
|
736
|
+
}
|
737
|
+
}
|
738
|
+
}
|
739
|
+
},
|
740
|
+
dragEnd: function() {
|
741
|
+
this.hDiv.style.cursor = "default";
|
742
|
+
if(this.resizing) {
|
743
|
+
var idx = this.resizing.idx,
|
744
|
+
nw = this.headers[idx].newWidth || this.headers[idx].width;
|
745
|
+
nw = parseInt(nw,10);
|
746
|
+
this.resizing = false;
|
747
|
+
$("#rs_m"+p.id).css("display","none");
|
748
|
+
p.colModel[idx].width = nw;
|
749
|
+
this.headers[idx].width = nw;
|
750
|
+
this.headers[idx].el.style.width = nw + "px";
|
751
|
+
if(this.cols.length>0) {this.cols[idx].style.width = nw+"px";}
|
752
|
+
if(this.footers.length>0) {this.footers[idx].style.width = nw+"px";}
|
753
|
+
if(p.forceFit===true){
|
754
|
+
nw = this.headers[idx+p.nv].newWidth || this.headers[idx+p.nv].width;
|
755
|
+
this.headers[idx+p.nv].width = nw;
|
756
|
+
this.headers[idx+p.nv].el.style.width = nw + "px";
|
757
|
+
if(this.cols.length>0) { this.cols[idx+p.nv].style.width = nw+"px"; }
|
758
|
+
if(this.footers.length>0) {this.footers[idx+p.nv].style.width = nw+"px";}
|
759
|
+
p.colModel[idx+p.nv].width = nw;
|
760
|
+
} else {
|
761
|
+
p.tblwidth = this.newWidth || p.tblwidth;
|
762
|
+
$('table:first',this.bDiv).css("width",p.tblwidth+"px");
|
763
|
+
$('table:first',this.hDiv).css("width",p.tblwidth+"px");
|
764
|
+
this.hDiv.scrollLeft = this.bDiv.scrollLeft;
|
765
|
+
if(p.footerrow) {
|
766
|
+
$('table:first',this.sDiv).css("width",p.tblwidth+"px");
|
767
|
+
this.sDiv.scrollLeft = this.bDiv.scrollLeft;
|
768
|
+
}
|
769
|
+
}
|
770
|
+
if($.isFunction(p.resizeStop)) { p.resizeStop.call(this,nw,idx); }
|
771
|
+
}
|
772
|
+
this.curGbox = null;
|
773
|
+
document.onselectstart=function(){return true;};
|
774
|
+
},
|
775
|
+
populateVisible: function() {
|
776
|
+
if (grid.timer) { clearTimeout(grid.timer); }
|
777
|
+
grid.timer = null;
|
778
|
+
|
779
|
+
var dh = $(grid.bDiv).height();
|
780
|
+
if (!dh) { return; }
|
781
|
+
var table = $("table:first", grid.bDiv);
|
782
|
+
var rows = $("> tbody > tr:visible:first", table);
|
783
|
+
var rh = rows.outerHeight() || grid.prevRowHeight;
|
784
|
+
if (!rh) { return; }
|
785
|
+
grid.prevRowHeight = rh;
|
786
|
+
var rn = p.rowNum;
|
787
|
+
var scrollTop = grid.scrollTop = grid.bDiv.scrollTop;
|
788
|
+
var ttop = Math.round(table.position().top) - scrollTop;
|
789
|
+
var tbot = ttop + table.height();
|
790
|
+
var div = rh * rn;
|
791
|
+
var page, npage, empty;
|
792
|
+
// tbot < dh &&
|
793
|
+
if (tbot < dh && ttop <= 0 &&
|
794
|
+
(p.lastpage===undefined||parseInt((tbot + scrollTop + div - 1) / div,10) <= p.lastpage))
|
795
|
+
{
|
796
|
+
npage = parseInt((dh - tbot + div - 1) / div,10);
|
797
|
+
if (tbot >= 0 || npage < 2 || p.scroll === true) {
|
798
|
+
page = Math.round((tbot + scrollTop) / div) + 1;
|
799
|
+
ttop = -1;
|
800
|
+
} else {
|
801
|
+
ttop = 1;
|
802
|
+
}
|
803
|
+
}
|
804
|
+
if (ttop > 0) {
|
805
|
+
page = parseInt(scrollTop / div,10) + 1;
|
806
|
+
npage = parseInt((scrollTop + dh) / div,10) + 2 - page;
|
807
|
+
empty = true;
|
808
|
+
}
|
809
|
+
if (npage) {
|
810
|
+
if (p.lastpage && page > p.lastpage || p.lastpage==1) {
|
811
|
+
return;
|
812
|
+
}
|
813
|
+
if (grid.hDiv.loading) {
|
814
|
+
grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
|
815
|
+
} else {
|
816
|
+
p.page = page;
|
817
|
+
if (empty) {
|
818
|
+
grid.selectionPreserver(table[0]);
|
819
|
+
grid.emptyRows(grid.bDiv,false);
|
820
|
+
}
|
821
|
+
grid.populate(npage);
|
822
|
+
}
|
823
|
+
}
|
824
|
+
},
|
825
|
+
scrollGrid: function() {
|
826
|
+
if(p.scroll) {
|
827
|
+
var scrollTop = grid.bDiv.scrollTop;
|
828
|
+
if(grid.scrollTop === undefined) { grid.scrollTop = 0; }
|
829
|
+
if (scrollTop != grid.scrollTop) {
|
830
|
+
grid.scrollTop = scrollTop;
|
831
|
+
if (grid.timer) { clearTimeout(grid.timer); }
|
832
|
+
grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
|
833
|
+
}
|
834
|
+
}
|
835
|
+
grid.hDiv.scrollLeft = grid.bDiv.scrollLeft;
|
836
|
+
if(p.footerrow) {
|
837
|
+
grid.sDiv.scrollLeft = grid.bDiv.scrollLeft;
|
838
|
+
}
|
839
|
+
},
|
840
|
+
selectionPreserver : function(ts) {
|
841
|
+
var p = ts.p;
|
842
|
+
var sr = p.selrow, sra = p.selarrrow ? $.makeArray(p.selarrrow) : null;
|
843
|
+
var left = ts.grid.bDiv.scrollLeft;
|
844
|
+
var complete = p.gridComplete;
|
845
|
+
p.gridComplete = function() {
|
846
|
+
p.selrow = null;
|
847
|
+
p.selarrrow = [];
|
848
|
+
if(p.multiselect && sra && sra.length>0) {
|
849
|
+
for(var i=0;i<sra.length;i++){
|
850
|
+
if (sra[i] != sr) {
|
851
|
+
$(ts).jqGrid("setSelection",sra[i],false);
|
852
|
+
}
|
853
|
+
}
|
854
|
+
}
|
855
|
+
if (sr) {
|
856
|
+
$(ts).jqGrid("setSelection",sr,false);
|
857
|
+
}
|
858
|
+
ts.grid.bDiv.scrollLeft = left;
|
859
|
+
p.gridComplete = complete;
|
860
|
+
if (p.gridComplete) {
|
861
|
+
complete();
|
862
|
+
}
|
863
|
+
};
|
864
|
+
}
|
865
|
+
};
|
866
|
+
this.p = p ;
|
867
|
+
var i, dir,ts;
|
868
|
+
if(this.p.colNames.length === 0) {
|
869
|
+
for (i=0;i<this.p.colModel.length;i++){
|
870
|
+
this.p.colNames[i] = this.p.colModel[i].label || this.p.colModel[i].name;
|
871
|
+
}
|
872
|
+
}
|
873
|
+
if( this.p.colNames.length !== this.p.colModel.length ) {
|
874
|
+
alert($.jgrid.errors.model);
|
875
|
+
return;
|
876
|
+
}
|
877
|
+
var gv = $("<div class='ui-jqgrid-view'></div>"), ii,
|
878
|
+
isMSIE = $.browser.msie ? true:false,
|
879
|
+
isSafari = $.browser.safari ? true : false;
|
880
|
+
ts = this;
|
881
|
+
ts.p.direction = $.trim(ts.p.direction.toLowerCase());
|
882
|
+
if($.inArray(ts.p.direction,["ltr","rtl"]) == -1) { ts.p.direction = "ltr"; }
|
883
|
+
dir = ts.p.direction;
|
884
|
+
|
885
|
+
$(gv).insertBefore(this);
|
886
|
+
$(this).appendTo(gv).removeClass("scroll");
|
887
|
+
var eg = $("<div class='ui-jqgrid ui-widget ui-widget-content ui-corner-all'></div>");
|
888
|
+
$(eg).insertBefore(gv).attr({"id" : "gbox_"+this.id,"dir":dir});
|
889
|
+
$(gv).appendTo(eg).attr("id","gview_"+this.id);
|
890
|
+
if (isMSIE && $.browser.version <= 6) {
|
891
|
+
ii = '<iframe style="display:block;position:absolute;z-index:-1;filter:Alpha(Opacity=\'0\');" src="javascript:false;"></iframe>';
|
892
|
+
} else { ii="";}
|
893
|
+
$("<div class='ui-widget-overlay jqgrid-overlay' id='lui_"+this.id+"'></div>").append(ii).insertBefore(gv);
|
894
|
+
$("<div class='loading ui-state-default ui-state-active' id='load_"+this.id+"'>"+this.p.loadtext+"</div>").insertBefore(gv);
|
895
|
+
$(this).attr({cellSpacing:"0",cellPadding:"0",border:"0","role":"grid","aria-multiselectable":!!this.p.multiselect,"aria-labelledby":"gbox_"+this.id});
|
896
|
+
var sortkeys = ["shiftKey","altKey","ctrlKey"],
|
897
|
+
intNum = function(val,defval) {
|
898
|
+
val = parseInt(val,10);
|
899
|
+
if (isNaN(val)) { return defval ? defval : 0;}
|
900
|
+
else {return val;}
|
901
|
+
},
|
902
|
+
formatCol = function (pos, rowInd, tv){
|
903
|
+
var cm = ts.p.colModel[pos],
|
904
|
+
ral = cm.align, result="style=\"", clas = cm.classes, nm = cm.name;
|
905
|
+
if(ral) { result += "text-align:"+ral+";"; }
|
906
|
+
if(cm.hidden===true) { result += "display:none;"; }
|
907
|
+
if(rowInd===0) {
|
908
|
+
result += "width: "+grid.headers[pos].width+"px;";
|
909
|
+
}
|
910
|
+
result += "\"" + (clas !== undefined ? (" class=\""+clas+"\"") :"") + ((cm.title && tv) ? (" title=\""+$.jgrid.stripHtml(tv)+"\"") :"");
|
911
|
+
result += " aria-describedby=\""+ts.p.id+"_"+nm+"\"";
|
912
|
+
return result;
|
913
|
+
},
|
914
|
+
cellVal = function (val) {
|
915
|
+
return val === undefined || val === null || val === "" ? " " : (ts.p.autoencode ? $.jgrid.htmlEncode(val) : val+"");
|
916
|
+
},
|
917
|
+
formatter = function (rowId, cellval , colpos, rwdat, _act){
|
918
|
+
var cm = ts.p.colModel[colpos],v;
|
919
|
+
if(typeof cm.formatter !== 'undefined') {
|
920
|
+
var opts= {rowId: rowId, colModel:cm, gid:ts.p.id };
|
921
|
+
if($.isFunction( cm.formatter ) ) {
|
922
|
+
v = cm.formatter.call(ts,cellval,opts,rwdat,_act);
|
923
|
+
} else if($.fmatter){
|
924
|
+
v = $.fn.fmatter(cm.formatter, cellval,opts, rwdat, _act);
|
925
|
+
} else {
|
926
|
+
v = cellVal(cellval);
|
927
|
+
}
|
928
|
+
} else {
|
929
|
+
v = cellVal(cellval);
|
930
|
+
}
|
931
|
+
return v;
|
932
|
+
},
|
933
|
+
addCell = function(rowId,cell,pos,irow, srvr) {
|
934
|
+
var v,prp;
|
935
|
+
v = formatter(rowId,cell,pos,srvr,'add');
|
936
|
+
prp = formatCol( pos,irow, v);
|
937
|
+
return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
|
938
|
+
},
|
939
|
+
addMulti = function(rowid,pos,irow){
|
940
|
+
var v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+rowid+"\" class=\"cbox\" name=\"jqg_"+rowid+"\"/>",
|
941
|
+
prp = formatCol(pos,irow,'');
|
942
|
+
return "<td role=\"gridcell\" aria-describedby=\""+ts.p.id+"_cb\" "+prp+">"+v+"</td>";
|
943
|
+
},
|
944
|
+
addRowNum = function (pos,irow,pG,rN) {
|
945
|
+
var v = (parseInt(pG,10)-1)*parseInt(rN,10)+1+irow,
|
946
|
+
prp = formatCol(pos,irow,'');
|
947
|
+
return "<td role=\"gridcell\" aria-describedby=\""+ts.p.id+"_rn\" class=\"ui-state-default jqgrid-rownum\" "+prp+">"+v+"</td>";
|
948
|
+
},
|
949
|
+
reader = function (datatype) {
|
950
|
+
var field, f=[], j=0, i;
|
951
|
+
for(i =0; i<ts.p.colModel.length; i++){
|
952
|
+
field = ts.p.colModel[i];
|
953
|
+
if (field.name !== 'cb' && field.name !=='subgrid' && field.name !=='rn') {
|
954
|
+
f[j] = (datatype=="xml") ? field.xmlmap || field.name : field.jsonmap || field.name;
|
955
|
+
j++;
|
956
|
+
}
|
957
|
+
}
|
958
|
+
return f;
|
959
|
+
},
|
960
|
+
orderedCols = function (offset) {
|
961
|
+
var order = ts.p.remapColumns;
|
962
|
+
if (!order || !order.length) {
|
963
|
+
order = $.map(ts.p.colModel, function(v,i) { return i; });
|
964
|
+
}
|
965
|
+
if (offset) {
|
966
|
+
order = $.map(order, function(v) { return v<offset?null:v-offset; });
|
967
|
+
}
|
968
|
+
return order;
|
969
|
+
},
|
970
|
+
emptyRows = function (parent, scroll) {
|
971
|
+
if(ts.p.deepempty) { $("tbody:first tr", parent).remove(); }
|
972
|
+
else { $("tbody:first", parent).empty(); }
|
973
|
+
if (scroll && ts.p.scroll) {
|
974
|
+
$(">div:first", parent).css({height:"auto"}).children("div:first").css({height:0,display:"none"});
|
975
|
+
parent.scrollTop = 0;
|
976
|
+
}
|
977
|
+
},
|
978
|
+
addXmlData = function (xml,t, rcnt, more, adjust) {
|
979
|
+
var startReq = new Date(),
|
980
|
+
locdata = (ts.p.datatype != "local" && ts.p.loadonce) || ts.p.datatype == "xmlstring",
|
981
|
+
xmlid;
|
982
|
+
if(locdata) {
|
983
|
+
ts.p.data = [];
|
984
|
+
ts.p._index = {};
|
985
|
+
ts.p.localReader.id = xmlid = "_id_";
|
986
|
+
}
|
987
|
+
ts.p.reccount = 0;
|
988
|
+
if($.isXMLDoc(xml)) {
|
989
|
+
if(ts.p.treeANode===-1 && !ts.p.scroll) {
|
990
|
+
emptyRows(t,false);
|
991
|
+
rcnt=0;
|
992
|
+
} else { rcnt = rcnt > 0 ? rcnt :0; }
|
993
|
+
} else { return; }
|
994
|
+
var i,fpos,ir=0,v,row,gi=0,si=0,ni=0,idn, getId,f=[],F,rd ={}, rl= ts.rows.length, xmlr,rid, rowData=[],ari=0, cn=(ts.p.altRows === true) ? " "+ts.p.altclass:"",cn1;
|
995
|
+
if(!ts.p.xmlReader.repeatitems) {f = reader("xml");}
|
996
|
+
if( ts.p.keyIndex===false) {
|
997
|
+
idn = ts.p.xmlReader.id;
|
998
|
+
} else {
|
999
|
+
idn = ts.p.keyIndex;
|
1000
|
+
}
|
1001
|
+
if(f.length>0 && !isNaN(idn)) {
|
1002
|
+
if (ts.p.remapColumns && ts.p.remapColumns.length) {
|
1003
|
+
idn = $.inArray(idn, ts.p.remapColumns);
|
1004
|
+
}
|
1005
|
+
idn=f[idn];
|
1006
|
+
}
|
1007
|
+
if( (idn+"").indexOf("[") === -1 ) {
|
1008
|
+
if (f.length) {
|
1009
|
+
getId = function( trow, k) {return $(idn,trow).text() || k;};
|
1010
|
+
} else {
|
1011
|
+
getId = function( trow, k) {return $(ts.p.xmlReader.cell,trow).eq(idn).text() || k;};
|
1012
|
+
}
|
1013
|
+
}
|
1014
|
+
else {
|
1015
|
+
getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;};
|
1016
|
+
}
|
1017
|
+
ts.p.userData = {};
|
1018
|
+
$(ts.p.xmlReader.page,xml).each(function() {ts.p.page = this.textContent || this.text || 0; });
|
1019
|
+
$(ts.p.xmlReader.total,xml).each(function() {ts.p.lastpage = this.textContent || this.text; if(ts.p.lastpage===undefined) { ts.p.lastpage=1; } } );
|
1020
|
+
$(ts.p.xmlReader.records,xml).each(function() {ts.p.records = this.textContent || this.text || 0; } );
|
1021
|
+
$(ts.p.xmlReader.userdata,xml).each(function() {ts.p.userData[this.getAttribute("name")]=this.textContent || this.text;});
|
1022
|
+
var gxml = $(ts.p.xmlReader.root+" "+ts.p.xmlReader.row,xml),gl = gxml.length, j=0;
|
1023
|
+
if(gxml && gl){
|
1024
|
+
var rn = parseInt(ts.p.rowNum,10),br=ts.p.scroll?(parseInt(ts.p.page,10)-1)*rn+1:1,altr;
|
1025
|
+
if (adjust) { rn *= adjust+1; }
|
1026
|
+
var afterInsRow = $.isFunction(ts.p.afterInsertRow);
|
1027
|
+
while (j<gl) {
|
1028
|
+
xmlr = gxml[j];
|
1029
|
+
rid = getId(xmlr,br+j);
|
1030
|
+
altr = rcnt === 0 ? 0 : rcnt+1;
|
1031
|
+
cn1 = (altr+j)%2 == 1 ? cn : '';
|
1032
|
+
rowData[ari++] = "<tr id=\""+rid+"\" role=\"row\" class =\"ui-widget-content jqgrow ui-row-"+ts.p.direction+""+cn1+"\">";
|
1033
|
+
if(ts.p.rownumbers===true) {
|
1034
|
+
rowData[ari++] = addRowNum(0,j,ts.p.page,ts.p.rowNum);
|
1035
|
+
ni=1;
|
1036
|
+
}
|
1037
|
+
if(ts.p.multiselect===true) {
|
1038
|
+
rowData[ari++] = addMulti(rid,ni,j);
|
1039
|
+
gi=1;
|
1040
|
+
}
|
1041
|
+
if (ts.p.subGrid===true) {
|
1042
|
+
rowData[ari++]= $(ts).jqGrid("addSubGridCell",gi+ni,j+rcnt);
|
1043
|
+
si= 1;
|
1044
|
+
}
|
1045
|
+
if(ts.p.xmlReader.repeatitems){
|
1046
|
+
if (!F) { F=orderedCols(gi+si+ni); }
|
1047
|
+
var cells = $(ts.p.xmlReader.cell,xmlr);
|
1048
|
+
$.each(F, function (k) {
|
1049
|
+
var cell = cells[this];
|
1050
|
+
if (!cell) { return false; }
|
1051
|
+
v = cell.textContent || cell.text;
|
1052
|
+
rd[ts.p.colModel[k+gi+si+ni].name] = v;
|
1053
|
+
rowData[ari++] = addCell(rid,v,k+gi+si+ni,j+rcnt,xmlr);
|
1054
|
+
});
|
1055
|
+
} else {
|
1056
|
+
for(i = 0; i < f.length;i++) {
|
1057
|
+
v = $(f[i],xmlr).text();
|
1058
|
+
rd[ts.p.colModel[i+gi+si+ni].name] = v;
|
1059
|
+
rowData[ari++] = addCell(rid, v, i+gi+si+ni, j+rcnt, xmlr);
|
1060
|
+
}
|
1061
|
+
}
|
1062
|
+
rowData[ari++] = "</tr>";
|
1063
|
+
if(locdata) {
|
1064
|
+
rd[xmlid] = rid;
|
1065
|
+
ts.p.data.push(rd);
|
1066
|
+
}
|
1067
|
+
if(ts.p.gridview === false ) {
|
1068
|
+
if( ts.p.treeGrid === true) {
|
1069
|
+
fpos = ts.p.treeANode >= -1 ? ts.p.treeANode: 0;
|
1070
|
+
row = $(rowData.join(''))[0]; // speed overhead
|
1071
|
+
if(rl === 0) { $("tbody:first",t).append(row); } else { $(ts.rows[j+fpos+rcnt]).after(row); }
|
1072
|
+
try {$(ts).jqGrid("setTreeNode",rd,row);} catch (e) {}
|
1073
|
+
} else {
|
1074
|
+
$("tbody:first",t).append(rowData.join(''));
|
1075
|
+
}
|
1076
|
+
if (ts.p.subGrid===true) {
|
1077
|
+
try {$(ts).jqGrid("addSubGrid",ts.rows[ts.rows.length-1],gi+ni);} catch (_){}
|
1078
|
+
}
|
1079
|
+
if(afterInsRow) {ts.p.afterInsertRow.call(ts,rid,rd,xmlr);}
|
1080
|
+
rowData=[];ari=0;
|
1081
|
+
}
|
1082
|
+
rd={};
|
1083
|
+
ir++;
|
1084
|
+
j++;
|
1085
|
+
if(ir==rn) {break;}
|
1086
|
+
}
|
1087
|
+
}
|
1088
|
+
if(ts.p.gridview === true) {
|
1089
|
+
$("tbody:first",t).append(rowData.join(''));
|
1090
|
+
}
|
1091
|
+
ts.p.totaltime = new Date() - startReq;
|
1092
|
+
if(ir>0) { ts.grid.cols = ts.rows[0].cells; if(ts.p.records===0) { ts.p.records=gl;} }
|
1093
|
+
rowData =null;
|
1094
|
+
if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
|
1095
|
+
ts.p.reccount=ir;
|
1096
|
+
ts.p.treeANode = -1;
|
1097
|
+
if(ts.p.userDataOnFooter) { $(ts).jqGrid("footerData","set",ts.p.userData,true); }
|
1098
|
+
if(locdata) {
|
1099
|
+
ts.p.records = gl;
|
1100
|
+
ts.p.lastpage = Math.ceil(gl/ rn);
|
1101
|
+
}
|
1102
|
+
if (!more) { updatepager(false,true); }
|
1103
|
+
if(locdata) {
|
1104
|
+
while (ir<gl) {
|
1105
|
+
xmlr = gxml[ir];
|
1106
|
+
rid = getId(xmlr,ir);
|
1107
|
+
if(ts.p.xmlReader.repeatitems){
|
1108
|
+
if (!F) { F=orderedCols(gi+si+ni); }
|
1109
|
+
var cells = $(ts.p.xmlReader.cell,xmlr);
|
1110
|
+
$.each(F, function (k) {
|
1111
|
+
var cell = cells[this];
|
1112
|
+
if (!cell) { return false; }
|
1113
|
+
v = cell.textContent || cell.text;
|
1114
|
+
rd[ts.p.colModel[k+gi+si+ni].name] = v;
|
1115
|
+
});
|
1116
|
+
} else {
|
1117
|
+
for(i = 0; i < f.length;i++) {
|
1118
|
+
v = $(f[i],xmlr).text();
|
1119
|
+
rd[ts.p.colModel[i+gi+si+ni].name] = v;
|
1120
|
+
}
|
1121
|
+
}
|
1122
|
+
rd[xmlid] = rid;
|
1123
|
+
ts.p.data.push(rd);
|
1124
|
+
rd = {};
|
1125
|
+
ir++;
|
1126
|
+
}
|
1127
|
+
refreshIndex();
|
1128
|
+
}
|
1129
|
+
},
|
1130
|
+
addJSONData = function(data,t, rcnt, more, adjust) {
|
1131
|
+
var startReq = new Date();
|
1132
|
+
if(data) {
|
1133
|
+
if(ts.p.treeANode === -1 && !ts.p.scroll) {
|
1134
|
+
emptyRows(t,false);
|
1135
|
+
rcnt=0;
|
1136
|
+
} else { rcnt = rcnt > 0 ? rcnt :0; }
|
1137
|
+
} else { return; }
|
1138
|
+
|
1139
|
+
var dReader = ts.p.datatype == "local" ? ts.p.localReader : ts.p.jsonReader, locid,
|
1140
|
+
locdata = (ts.p.datatype != "local" && ts.p.loadonce) || ts.p.datatype == "jsonstring";
|
1141
|
+
if(locdata) { ts.p.data = []; ts.p._index = {}; locid = ts.p.localReader.id = "_id_";}
|
1142
|
+
ts.p.reccount = 0;
|
1143
|
+
|
1144
|
+
var ir=0,v,i,j,row,f=[],F,cur,gi=0,si=0,ni=0,len,drows,idn,rd={}, fpos,rl = ts.rows.length,idr,rowData=[],ari=0,cn=(ts.p.altRows === true) ? " "+ts.p.altclass:"",cn1,lp;
|
1145
|
+
ts.p.page = $.jgrid.getAccessor(data,dReader.page) || 0;
|
1146
|
+
lp = $.jgrid.getAccessor(data,dReader.total);
|
1147
|
+
ts.p.lastpage= lp === undefined ? 1 : lp;
|
1148
|
+
ts.p.records= $.jgrid.getAccessor(data,dReader.records) || 0;
|
1149
|
+
ts.p.userData = $.jgrid.getAccessor(data,dReader.userdata) || {};
|
1150
|
+
if(!dReader.repeatitems) {
|
1151
|
+
F = f = reader("json");
|
1152
|
+
}
|
1153
|
+
if( ts.p.keyIndex===false ) {
|
1154
|
+
idn = dReader.id;
|
1155
|
+
} else {
|
1156
|
+
idn = ts.p.keyIndex;
|
1157
|
+
}
|
1158
|
+
if(f.length>0 && !isNaN(idn)) {
|
1159
|
+
if (ts.p.remapColumns && ts.p.remapColumns.length) {
|
1160
|
+
idn = $.inArray(idn, ts.p.remapColumns);
|
1161
|
+
}
|
1162
|
+
idn=f[idn];
|
1163
|
+
}
|
1164
|
+
drows = $.jgrid.getAccessor(data,dReader.root);
|
1165
|
+
if (drows) {
|
1166
|
+
len = drows.length; i=0;
|
1167
|
+
var rn = parseInt(ts.p.rowNum,10),br=ts.p.scroll?(parseInt(ts.p.page,10)-1)*rn+1:1, altr;
|
1168
|
+
if (adjust) { rn *= adjust+1; }
|
1169
|
+
var afterInsRow = $.isFunction(ts.p.afterInsertRow);
|
1170
|
+
while (i<len) {
|
1171
|
+
cur = drows[i];
|
1172
|
+
idr = $.jgrid.getAccessor(cur,idn);
|
1173
|
+
if(idr === undefined) {
|
1174
|
+
idr = br+i;
|
1175
|
+
if(f.length===0){
|
1176
|
+
if(dReader.cell){
|
1177
|
+
var ccur = cur[dReader.cell];
|
1178
|
+
idr = ccur[idn] || idr;
|
1179
|
+
ccur=null;
|
1180
|
+
}
|
1181
|
+
}
|
1182
|
+
}
|
1183
|
+
altr = rcnt === 0 ? 0 : rcnt+1;
|
1184
|
+
cn1 = (altr+i)%2 == 1 ? cn : '';
|
1185
|
+
rowData[ari++] = "<tr id=\""+ idr +"\" role=\"row\" class= \"ui-widget-content jqgrow ui-row-"+ts.p.direction+""+cn1+"\">";
|
1186
|
+
if(ts.p.rownumbers===true) {
|
1187
|
+
rowData[ari++] = addRowNum(0,i,ts.p.page,ts.p.rowNum);
|
1188
|
+
ni=1;
|
1189
|
+
}
|
1190
|
+
if(ts.p.multiselect){
|
1191
|
+
rowData[ari++] = addMulti(idr,ni,i);
|
1192
|
+
gi = 1;
|
1193
|
+
}
|
1194
|
+
if (ts.p.subGrid) {
|
1195
|
+
rowData[ari++]= $(ts).jqGrid("addSubGridCell",gi+ni,i+rcnt);
|
1196
|
+
si= 1;
|
1197
|
+
}
|
1198
|
+
if (dReader.repeatitems) {
|
1199
|
+
if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell);}
|
1200
|
+
if (!F) { F=orderedCols(gi+si+ni); }
|
1201
|
+
}
|
1202
|
+
for (j=0;j<F.length;j++) {
|
1203
|
+
v = $.jgrid.getAccessor(cur,F[j]);
|
1204
|
+
rowData[ari++] = addCell(idr,v,j+gi+si+ni,i+rcnt,cur);
|
1205
|
+
rd[ts.p.colModel[j+gi+si+ni].name] = v;
|
1206
|
+
}
|
1207
|
+
rowData[ari++] = "</tr>";
|
1208
|
+
if(locdata) { rd[locid] = idr; ts.p.data.push(rd); }
|
1209
|
+
if(ts.p.gridview === false ) {
|
1210
|
+
if( ts.p.treeGrid === true) {
|
1211
|
+
fpos = ts.p.treeANode >= -1 ? ts.p.treeANode: 0;
|
1212
|
+
row = $(rowData.join(''))[0];
|
1213
|
+
if(rl === 0) { $("tbody:first",t).append(row); } else { $(ts.rows[i+fpos+rcnt]).after(row); }
|
1214
|
+
try {$(ts).jqGrid("setTreeNode",rd,row);} catch (e) {}
|
1215
|
+
} else {
|
1216
|
+
$("tbody:first",t).append(rowData.join(''));
|
1217
|
+
}
|
1218
|
+
if(ts.p.subGrid === true ) {
|
1219
|
+
try { $(ts).jqGrid("addSubGrid",ts.rows[ts.rows.length-1],gi+ni);} catch (_){}
|
1220
|
+
}
|
1221
|
+
if(afterInsRow) {ts.p.afterInsertRow.call(ts,idr,rd,cur);}
|
1222
|
+
rowData=[];ari=0;
|
1223
|
+
}
|
1224
|
+
rd={};
|
1225
|
+
ir++;
|
1226
|
+
i++;
|
1227
|
+
if(ir==rn) { break; }
|
1228
|
+
}
|
1229
|
+
if(ts.p.gridview === true ) {
|
1230
|
+
$("tbody:first",t).append(rowData.join(''));
|
1231
|
+
}
|
1232
|
+
ts.p.totaltime = new Date() - startReq;
|
1233
|
+
if(ir>0) {ts.grid.cols = ts.rows[0].cells; if(ts.p.records===0) { ts.p.records=len; } }
|
1234
|
+
}
|
1235
|
+
if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
|
1236
|
+
ts.p.reccount=ir;
|
1237
|
+
ts.p.treeANode = -1;
|
1238
|
+
if(ts.p.userDataOnFooter) { $(ts).jqGrid("footerData","set",ts.p.userData,true); }
|
1239
|
+
if(locdata) {
|
1240
|
+
ts.p.records = len;
|
1241
|
+
ts.p.lastpage = Math.ceil(len/ rn);
|
1242
|
+
}
|
1243
|
+
if (!more) { updatepager(false,true); }
|
1244
|
+
if(locdata) {
|
1245
|
+
while (ir<len) {
|
1246
|
+
cur = drows[ir];
|
1247
|
+
idr = $.jgrid.getAccessor(cur,idn);
|
1248
|
+
if(idr === undefined) {
|
1249
|
+
idr = br+ir;
|
1250
|
+
if(f.length===0){
|
1251
|
+
if(dReader.cell){
|
1252
|
+
var ccur = cur[dReader.cell];
|
1253
|
+
idr = ccur[idn] || idr;
|
1254
|
+
ccur=null;
|
1255
|
+
}
|
1256
|
+
}
|
1257
|
+
}
|
1258
|
+
if(cur) {
|
1259
|
+
if (dReader.repeatitems) {
|
1260
|
+
if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell);}
|
1261
|
+
if (!F) { F=orderedCols(gi+si+ni); }
|
1262
|
+
}
|
1263
|
+
|
1264
|
+
for (j=0;j<F.length;j++) {
|
1265
|
+
v = $.jgrid.getAccessor(cur,F[j]);
|
1266
|
+
rd[ts.p.colModel[j+gi+si+ni].name] = v;
|
1267
|
+
}
|
1268
|
+
rd[locid] = idr;
|
1269
|
+
ts.p.data.push(rd);
|
1270
|
+
rd = {};
|
1271
|
+
}
|
1272
|
+
ir++;
|
1273
|
+
}
|
1274
|
+
refreshIndex();
|
1275
|
+
}
|
1276
|
+
},
|
1277
|
+
addLocalData = function() {
|
1278
|
+
var st, fndsort=false, cmtypes=[], srcformat, sortype, newformat;
|
1279
|
+
if(!ts.p.data.length) {
|
1280
|
+
return;
|
1281
|
+
}
|
1282
|
+
$.each(ts.p.colModel,function(i,v){
|
1283
|
+
sorttype = this.sorttype || "text";
|
1284
|
+
if(sorttype == "date" || sorttype == "datetime") {
|
1285
|
+
if(this.formatter && typeof(this.formatter) === 'string' && this.formatter == 'date') {
|
1286
|
+
if(this.formatoptions && this.formatoptions.srcformat) {
|
1287
|
+
srcformat = this.formatoptions.srcformat;
|
1288
|
+
} else {
|
1289
|
+
srcformat = $.jgrid.formatter.date.srcformat;
|
1290
|
+
}
|
1291
|
+
if(this.formatoptions && this.formatoptions.newformat) {
|
1292
|
+
newformat = this.formatoptions.newformat;
|
1293
|
+
} else {
|
1294
|
+
newformat = $.jgrid.formatter.date.newformat;
|
1295
|
+
}
|
1296
|
+
} else {
|
1297
|
+
srcformat = newformat = this.datefmt || "Y-m-d";
|
1298
|
+
}
|
1299
|
+
cmtypes[this.name] = {"stype": sorttype, "srcfmt": srcformat,"newfmt":newformat};
|
1300
|
+
} else {
|
1301
|
+
cmtypes[this.name] = {"stype": sorttype, "srcfmt":'',"newfmt":''};
|
1302
|
+
}
|
1303
|
+
if(!fndsort && (this.index == ts.p.sortname || this.name == ts.p.sortname)){
|
1304
|
+
st = this.name; // ???
|
1305
|
+
fndsort = true;
|
1306
|
+
}
|
1307
|
+
});
|
1308
|
+
if(ts.p.treeGrid) {
|
1309
|
+
$(ts).jqGrid("SortTree",ts.p.sortname,ts.p.sortorder, cmtypes[st].stype, cmtypes[st].srcfmt);
|
1310
|
+
return;
|
1311
|
+
}
|
1312
|
+
var compareFnMap = {
|
1313
|
+
'eq':function(queryObj) {return queryObj.equals;},
|
1314
|
+
'ne':function(queryObj) {return queryObj.not().equals;},
|
1315
|
+
'lt':function(queryObj) {return queryObj.less;},
|
1316
|
+
'le':function(queryObj) {return queryObj.lessOrEquals;},
|
1317
|
+
'gt':function(queryObj) {return queryObj.greater;},
|
1318
|
+
'ge':function(queryObj) {return queryObj.greaterOrEquals;},
|
1319
|
+
'cn':function(queryObj) {return queryObj.contains;},
|
1320
|
+
'nc':function(queryObj) {return queryObj.not().contains;},
|
1321
|
+
'bw':function(queryObj) {return queryObj.startsWith;},
|
1322
|
+
'bn':function(queryObj) {return queryObj.not().startsWith;},
|
1323
|
+
'en':function(queryObj) {return queryObj.not().endsWith;},
|
1324
|
+
'ew':function(queryObj) {return queryObj.endsWith;},
|
1325
|
+
'ni':function(queryObj) {return queryObj.not().equals;},
|
1326
|
+
'in':function(queryObj) {return queryObj.equals;}
|
1327
|
+
|
1328
|
+
},
|
1329
|
+
query = $.jgrid.from(ts.p.data);
|
1330
|
+
if (ts.p.search === true) {
|
1331
|
+
var srules = ts.p.postData.filters;
|
1332
|
+
if(srules) {
|
1333
|
+
if(typeof srules == "string") { srules = $.jgrid.parse(srules);}
|
1334
|
+
for (var i=0, l= srules.rules.length, rule; i<l; i++) {
|
1335
|
+
var rule = srules.rules[i], opr = srules.groupOp;
|
1336
|
+
if (compareFnMap[rule.op] && rule.field && rule.data && opr) {
|
1337
|
+
if(opr.toUpperCase() == "OR") {
|
1338
|
+
query = compareFnMap[rule.op](query)(rule.field, rule.data, cmtypes[rule.field]).or();
|
1339
|
+
} else {
|
1340
|
+
query = compareFnMap[rule.op](query)(rule.field, rule.data, cmtypes[rule.field]);
|
1341
|
+
}
|
1342
|
+
}
|
1343
|
+
}
|
1344
|
+
} else {
|
1345
|
+
try {
|
1346
|
+
query = compareFnMap[ts.p.postData.searchOper](query)(ts.p.postData.searchField, ts.p.postData.searchString,cmtypes[ts.p.postData.searchField]);
|
1347
|
+
} catch (se){}
|
1348
|
+
}
|
1349
|
+
}
|
1350
|
+
|
1351
|
+
if (st && ts.p.sortorder) {
|
1352
|
+
if(ts.p.sortorder.toUpperCase() == "DESC") {
|
1353
|
+
query.orderBy(st,"d",cmtypes[st].stype, cmtypes[st].srcfmt);
|
1354
|
+
} else {
|
1355
|
+
query.orderBy(st,"a",cmtypes[st].stype, cmtypes[st].srcfmt);
|
1356
|
+
}
|
1357
|
+
}
|
1358
|
+
var queryResults = query.select(),
|
1359
|
+
recordsperpage = parseInt(ts.p.rowNum,10),
|
1360
|
+
total = queryResults.length,
|
1361
|
+
page = parseInt(ts.p.page,10),
|
1362
|
+
totalpages = Math.ceil(total / recordsperpage),
|
1363
|
+
retresult = {};
|
1364
|
+
queryResults = queryResults.slice( (page-1)*recordsperpage , page*recordsperpage );
|
1365
|
+
query = null;
|
1366
|
+
cmtypes = null;
|
1367
|
+
retresult[ts.p.localReader.total] = totalpages;
|
1368
|
+
retresult[ts.p.localReader.page] = page;
|
1369
|
+
retresult[ts.p.localReader.records] = total;
|
1370
|
+
retresult[ts.p.localReader.root] = queryResults;
|
1371
|
+
queryResults = null;
|
1372
|
+
return retresult;
|
1373
|
+
},
|
1374
|
+
updatepager = function(rn, dnd) {
|
1375
|
+
var cp, last, base, from,to,tot,fmt, pgboxes = "";
|
1376
|
+
base = parseInt(ts.p.page,10)-1;
|
1377
|
+
if(base < 0) { base = 0; }
|
1378
|
+
base = base*parseInt(ts.p.rowNum,10);
|
1379
|
+
to = base + ts.p.reccount;
|
1380
|
+
if (ts.p.scroll) {
|
1381
|
+
var rows = $("tbody:first > tr", ts.grid.bDiv);
|
1382
|
+
base = to - rows.length;
|
1383
|
+
ts.p.reccount = rows.length;
|
1384
|
+
var rh = rows.outerHeight();
|
1385
|
+
if (rh) {
|
1386
|
+
var top = base * rh;
|
1387
|
+
var height = parseInt(ts.p.records,10) * rh;
|
1388
|
+
$(">div:first",ts.grid.bDiv).css({height : height}).children("div:first").css({height:top,display:top?"":"none"});
|
1389
|
+
}
|
1390
|
+
ts.grid.bDiv.scrollLeft = ts.grid.hDiv.scrollLeft;
|
1391
|
+
}
|
1392
|
+
pgboxes = ts.p.pager ? ts.p.pager : "";
|
1393
|
+
pgboxes += ts.p.toppager ? (pgboxes ? "," + ts.p.toppager : ts.p.toppager) : "";
|
1394
|
+
if(pgboxes) {
|
1395
|
+
fmt = $.jgrid.formatter.integer || {};
|
1396
|
+
cp = intNum(ts.p.page);
|
1397
|
+
last = intNum(ts.p.lastpage);
|
1398
|
+
$(".selbox",pgboxes).attr("disabled",false);
|
1399
|
+
if(ts.p.pginput===true) {
|
1400
|
+
$('.ui-pg-input',pgboxes).val(ts.p.page);
|
1401
|
+
$('#sp_1',pgboxes).html($.fmatter ? $.fmatter.util.NumberFormat(ts.p.lastpage,fmt):ts.p.lastpage);
|
1402
|
+
|
1403
|
+
}
|
1404
|
+
if (ts.p.viewrecords){
|
1405
|
+
if(ts.p.reccount === 0) {
|
1406
|
+
$(".ui-paging-info",pgboxes).html(ts.p.emptyrecords);
|
1407
|
+
} else {
|
1408
|
+
from = base+1;
|
1409
|
+
tot=ts.p.records;
|
1410
|
+
if($.fmatter) {
|
1411
|
+
from = $.fmatter.util.NumberFormat(from,fmt);
|
1412
|
+
to = $.fmatter.util.NumberFormat(to,fmt);
|
1413
|
+
tot = $.fmatter.util.NumberFormat(tot,fmt);
|
1414
|
+
}
|
1415
|
+
$(".ui-paging-info",pgboxes).html($.jgrid.format(ts.p.recordtext,from,to,tot));
|
1416
|
+
}
|
1417
|
+
}
|
1418
|
+
if(ts.p.pgbuttons===true) {
|
1419
|
+
if(cp<=0) {cp = last = 0;}
|
1420
|
+
if(cp==1 || cp === 0) {
|
1421
|
+
$("#first, #prev",ts.p.pager).addClass('ui-state-disabled').removeClass('ui-state-hover');
|
1422
|
+
if(ts.p.toppager) { $("#first_t, #prev_t",ts.p.toppager).addClass('ui-state-disabled').removeClass('ui-state-hover'); }
|
1423
|
+
} else {
|
1424
|
+
$("#first, #prev",ts.p.pager).removeClass('ui-state-disabled');
|
1425
|
+
if(ts.p.toppager) { $("#first_t, #prev_t",ts.p.toppager).removeClass('ui-state-disabled'); }
|
1426
|
+
}
|
1427
|
+
if(cp==last || cp === 0) {
|
1428
|
+
$("#next, #last",ts.p.pager).addClass('ui-state-disabled').removeClass('ui-state-hover');
|
1429
|
+
if(ts.p.toppager) { $("#next_t, #last_t",ts.p.toppager).addClass('ui-state-disabled').removeClass('ui-state-hover'); }
|
1430
|
+
} else {
|
1431
|
+
$("#next, #last",ts.p.pager).removeClass('ui-state-disabled');
|
1432
|
+
if(ts.p.toppager) { $("#next_t, #last_t",ts.p.toppager).removeClass('ui-state-disabled'); }
|
1433
|
+
}
|
1434
|
+
}
|
1435
|
+
}
|
1436
|
+
if(rn===true && ts.p.rownumbers === true) {
|
1437
|
+
$("td.jqgrid-rownum",ts.rows).each(function(i){
|
1438
|
+
$(this).html(base+1+i);
|
1439
|
+
});
|
1440
|
+
}
|
1441
|
+
if(dnd && ts.p.jqgdnd) { $(ts).jqGrid('gridDnD','updateDnD');}
|
1442
|
+
if($.isFunction(ts.p.gridComplete)) {ts.p.gridComplete.call(ts);}
|
1443
|
+
},
|
1444
|
+
populate = function (npage) {
|
1445
|
+
if(!ts.grid.hDiv.loading) {
|
1446
|
+
var pvis = ts.p.scroll && npage === false;
|
1447
|
+
var prm = {}, dt, dstr, pN=ts.p.prmNames;
|
1448
|
+
if(ts.p.page <=0) { ts.p.page = 1; }
|
1449
|
+
if(pN.search !== null) {prm[pN.search] = ts.p.search;} if(pN.nd !== null) {prm[pN.nd] = new Date().getTime();}
|
1450
|
+
if(pN.rows !== null) {prm[pN.rows]= ts.p.rowNum;} if(pN.page !== null) {prm[pN.page]= ts.p.page;}
|
1451
|
+
if(pN.sort !== null) {prm[pN.sort]= ts.p.sortname;} if(pN.order !== null) {prm[pN.order]= ts.p.sortorder;}
|
1452
|
+
if(ts.p.rowTotal !== null && pN.totalrows !== null) { prm[pN.totalrows]= ts.p.rowTotal; }
|
1453
|
+
var lc = ts.p.loadComplete;
|
1454
|
+
var lcf = $.isFunction(lc);
|
1455
|
+
if (!lcf) { lc = null; }
|
1456
|
+
var adjust = 0;
|
1457
|
+
npage = npage || 1;
|
1458
|
+
if (npage > 1) {
|
1459
|
+
if(pN.npage !== null) {
|
1460
|
+
prm[pN.npage] = npage;
|
1461
|
+
adjust = npage - 1;
|
1462
|
+
npage = 1;
|
1463
|
+
} else {
|
1464
|
+
lc = function(req) {
|
1465
|
+
ts.p.page++;
|
1466
|
+
ts.grid.hDiv.loading = false;
|
1467
|
+
if (lcf) {
|
1468
|
+
ts.p.loadComplete.call(ts,req);
|
1469
|
+
}
|
1470
|
+
populate(npage-1);
|
1471
|
+
};
|
1472
|
+
}
|
1473
|
+
} else if (pN.npage !== null) {
|
1474
|
+
delete ts.p.postData[pN.npage];
|
1475
|
+
}
|
1476
|
+
$.extend(ts.p.postData,prm);
|
1477
|
+
var rcnt = !ts.p.scroll ? 0 : ts.rows.length-1;
|
1478
|
+
if ($.isFunction(ts.p.datatype)) { ts.p.datatype.call(ts,ts.p.postData,"load_"+ts.p.id); return;}
|
1479
|
+
else if($.isFunction(ts.p.beforeRequest)) {ts.p.beforeRequest.call(ts);}
|
1480
|
+
dt = ts.p.datatype.toLowerCase();
|
1481
|
+
switch(dt)
|
1482
|
+
{
|
1483
|
+
case "json":
|
1484
|
+
case "jsonp":
|
1485
|
+
case "xml":
|
1486
|
+
case "script":
|
1487
|
+
$.ajax($.extend({
|
1488
|
+
url:ts.p.url,
|
1489
|
+
type:ts.p.mtype,
|
1490
|
+
dataType: dt ,
|
1491
|
+
data: $.isFunction(ts.p.serializeGridData)? ts.p.serializeGridData.call(ts,ts.p.postData) : ts.p.postData,
|
1492
|
+
success:function(req,st) {
|
1493
|
+
if(dt === "xml") { addXmlData(req,ts.grid.bDiv,rcnt,npage>1,adjust); }
|
1494
|
+
else { addJSONData(req,ts.grid.bDiv,rcnt,npage>1,adjust); }
|
1495
|
+
if(lc) { lc.call(ts,req); }
|
1496
|
+
if (pvis) { ts.grid.populateVisible(); }
|
1497
|
+
if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";}
|
1498
|
+
req=null;
|
1499
|
+
endReq();
|
1500
|
+
},
|
1501
|
+
error:function(xhr,st,err){
|
1502
|
+
if($.isFunction(ts.p.loadError)) { ts.p.loadError.call(ts,xhr,st,err); }
|
1503
|
+
endReq();
|
1504
|
+
xhr=null;
|
1505
|
+
},
|
1506
|
+
beforeSend: function(xhr){
|
1507
|
+
beginReq();
|
1508
|
+
if($.isFunction(ts.p.loadBeforeSend)) { ts.p.loadBeforeSend.call(ts,xhr); }
|
1509
|
+
}
|
1510
|
+
},$.jgrid.ajaxOptions, ts.p.ajaxGridOptions));
|
1511
|
+
break;
|
1512
|
+
case "xmlstring":
|
1513
|
+
beginReq();
|
1514
|
+
dstr = $.jgrid.stringToDoc(ts.p.datastr);
|
1515
|
+
if(lcf) {ts.p.loadComplete.call(ts,dstr);}
|
1516
|
+
addXmlData(dstr,ts.grid.bDiv);
|
1517
|
+
ts.p.datatype = "local";
|
1518
|
+
ts.p.datastr = null;
|
1519
|
+
endReq();
|
1520
|
+
break;
|
1521
|
+
case "jsonstring":
|
1522
|
+
beginReq();
|
1523
|
+
if(typeof ts.p.datastr == 'string') { dstr = $.jgrid.parse(ts.p.datastr); }
|
1524
|
+
else { dstr = ts.p.datastr; }
|
1525
|
+
if(lcf) {ts.p.loadComplete.call(ts,dstr);}
|
1526
|
+
addJSONData(dstr,ts.grid.bDiv);
|
1527
|
+
ts.p.datatype = "local";
|
1528
|
+
ts.p.datastr = null;
|
1529
|
+
endReq();
|
1530
|
+
break;
|
1531
|
+
case "local":
|
1532
|
+
case "clientside":
|
1533
|
+
beginReq();
|
1534
|
+
ts.p.datatype = "local";
|
1535
|
+
var req = addLocalData();
|
1536
|
+
addJSONData(req,ts.grid.bDiv,rcnt,npage>1,adjust);
|
1537
|
+
if(lc) { lc.call(ts,req); }
|
1538
|
+
if (pvis) { ts.grid.populateVisible(); }
|
1539
|
+
endReq();
|
1540
|
+
break;
|
1541
|
+
}
|
1542
|
+
}
|
1543
|
+
},
|
1544
|
+
refreshIndex = function() {
|
1545
|
+
var datalen = ts.p.data.length, idname, i, val,
|
1546
|
+
ni = ts.p.rownumbers===true ? 1 :0,
|
1547
|
+
gi = ts.p.multiselect ===true ? 1 :0,
|
1548
|
+
si = ts.p.subGrid===true ? 1 :0;
|
1549
|
+
|
1550
|
+
if(ts.p.keyIndex === false || ts.p.loadonce === true) {
|
1551
|
+
idname = ts.p.localReader.id;
|
1552
|
+
} else {
|
1553
|
+
idname = ts.p.colModel[ts.p.keyIndex+gi+si+ni].name;
|
1554
|
+
}
|
1555
|
+
for(i =0;i < datalen; i++) {
|
1556
|
+
val = $.jgrid.getAccessor(ts.p.data[i],idname);
|
1557
|
+
ts.p._index[val] = i;
|
1558
|
+
}
|
1559
|
+
},
|
1560
|
+
beginReq = function() {
|
1561
|
+
ts.grid.hDiv.loading = true;
|
1562
|
+
if(ts.p.hiddengrid) { return;}
|
1563
|
+
switch(ts.p.loadui) {
|
1564
|
+
case "disable":
|
1565
|
+
break;
|
1566
|
+
case "enable":
|
1567
|
+
$("#load_"+ts.p.id).show();
|
1568
|
+
break;
|
1569
|
+
case "block":
|
1570
|
+
$("#lui_"+ts.p.id).show();
|
1571
|
+
$("#load_"+ts.p.id).show();
|
1572
|
+
break;
|
1573
|
+
}
|
1574
|
+
},
|
1575
|
+
endReq = function() {
|
1576
|
+
ts.grid.hDiv.loading = false;
|
1577
|
+
switch(ts.p.loadui) {
|
1578
|
+
case "disable":
|
1579
|
+
break;
|
1580
|
+
case "enable":
|
1581
|
+
$("#load_"+ts.p.id).hide();
|
1582
|
+
break;
|
1583
|
+
case "block":
|
1584
|
+
$("#lui_"+ts.p.id).hide();
|
1585
|
+
$("#load_"+ts.p.id).hide();
|
1586
|
+
break;
|
1587
|
+
}
|
1588
|
+
},
|
1589
|
+
setPager = function (pgid, tp){
|
1590
|
+
var sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='ui-separator'></span></td>",
|
1591
|
+
pginp = "",
|
1592
|
+
pgl="<table cellspacing='0' cellpadding='0' border='0' style='table-layout:auto;' class='ui-pg-table'><tbody><tr>",
|
1593
|
+
str="", pgcnt, lft, cent, rgt, twd, tdw, i,
|
1594
|
+
clearVals = function(onpaging){
|
1595
|
+
var ret;
|
1596
|
+
if ($.isFunction(ts.p.onPaging) ) { ret = ts.p.onPaging.call(ts,onpaging); }
|
1597
|
+
ts.p.selrow = null;
|
1598
|
+
if(ts.p.multiselect) {ts.p.selarrrow =[];$('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.hDiv).attr("checked",false);}
|
1599
|
+
ts.p.savedRow = [];
|
1600
|
+
if(ret=='stop') {return false;}
|
1601
|
+
return true;
|
1602
|
+
};
|
1603
|
+
pgid = pgid.substr(1);
|
1604
|
+
pgcnt = "pg_"+pgid;
|
1605
|
+
lft = pgid+"_left"; cent = pgid+"_center"; rgt = pgid+"_right";
|
1606
|
+
$("#"+pgid)
|
1607
|
+
.append("<div id='"+pgcnt+"' class='ui-pager-control' role='group'><table cellspacing='0' cellpadding='0' border='0' class='ui-pg-table' style='width:100%;table-layout:fixed;' role='row'><tbody><tr><td id='"+lft+"' align='left'></td><td id='"+cent+"' align='center' style='white-space:pre;'></td><td id='"+rgt+"' align='right'></td></tr></tbody></table></div>")
|
1608
|
+
.attr("dir","ltr"); //explicit setting
|
1609
|
+
if(ts.p.rowList.length >0){
|
1610
|
+
str = "<td dir='"+dir+"'>";
|
1611
|
+
str +="<select class='ui-pg-selbox' role='listbox'>";
|
1612
|
+
for(i=0;i<ts.p.rowList.length;i++){
|
1613
|
+
str +="<option role='option' value='"+ts.p.rowList[i]+"'"+((ts.p.rowNum == ts.p.rowList[i])?' selected':'')+">"+ts.p.rowList[i]+"</option>";
|
1614
|
+
}
|
1615
|
+
str +="</select></td>";
|
1616
|
+
}
|
1617
|
+
if(dir=="rtl") { pgl += str; }
|
1618
|
+
if(ts.p.pginput===true) { pginp= "<td dir='"+dir+"'>"+$.jgrid.format(ts.p.pgtext || "","<input class='ui-pg-input' type='text' size='2' maxlength='7' value='0' role='textbox'/>","<span id='sp_1'></span>")+"</td>";}
|
1619
|
+
if(ts.p.pgbuttons===true) {
|
1620
|
+
var po=["first"+tp,"prev"+tp, "next"+tp,"last"+tp]; if(dir=="rtl") { po.reverse(); }
|
1621
|
+
pgl += "<td id='"+po[0]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-first'></span></td>";
|
1622
|
+
pgl += "<td id='"+po[1]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-prev'></span></td>";
|
1623
|
+
pgl += pginp !="" ? sep+pginp+sep:"";
|
1624
|
+
pgl += "<td id='"+po[2]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-next'></span></td>";
|
1625
|
+
pgl += "<td id='"+po[3]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-end'></span></td>";
|
1626
|
+
} else if (pginp !="") { pgl += pginp; }
|
1627
|
+
if(dir=="ltr") { pgl += str; }
|
1628
|
+
pgl += "</tr></tbody></table>";
|
1629
|
+
if(ts.p.viewrecords===true) {$("td#"+pgid+"_"+ts.p.recordpos,"#"+pgcnt).append("<div dir='"+dir+"' style='text-align:"+ts.p.recordpos+"' class='ui-paging-info'></div>");}
|
1630
|
+
$("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).append(pgl);
|
1631
|
+
tdw = $(".ui-jqgrid").css("font-size") || "11px";
|
1632
|
+
$(document.body).append("<div id='testpg' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:"+tdw+";visibility:hidden;' ></div>");
|
1633
|
+
twd = $(pgl).clone().appendTo("#testpg").width();
|
1634
|
+
$("#testpg").remove();
|
1635
|
+
if(twd > 0) {
|
1636
|
+
if(pginp !="") { twd += 50; } //should be param
|
1637
|
+
$("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).width(twd);
|
1638
|
+
}
|
1639
|
+
ts.p._nvtd = [];
|
1640
|
+
ts.p._nvtd[0] = twd ? Math.floor((ts.p.width - twd)/2) : Math.floor(ts.p.width/3);
|
1641
|
+
ts.p._nvtd[1] = 0;
|
1642
|
+
pgl=null;
|
1643
|
+
$('.ui-pg-selbox',"#"+pgcnt).bind('change',function() {
|
1644
|
+
ts.p.page = Math.round(ts.p.rowNum*(ts.p.page-1)/this.value-0.5)+1;
|
1645
|
+
ts.p.rowNum = this.value;
|
1646
|
+
if(tp) { $('.ui-pg-selbox',ts.p.pager).val(this.value); }
|
1647
|
+
else if(ts.p.toppager) { $('.ui-pg-selbox',ts.p.toppager).val(this.value); }
|
1648
|
+
if(!clearVals('records')) { return false; }
|
1649
|
+
populate();
|
1650
|
+
return false;
|
1651
|
+
});
|
1652
|
+
if(ts.p.pgbuttons===true) {
|
1653
|
+
$(".ui-pg-button","#"+pgcnt).hover(function(e){
|
1654
|
+
if($(this).hasClass('ui-state-disabled')) {
|
1655
|
+
this.style.cursor='default';
|
1656
|
+
} else {
|
1657
|
+
$(this).addClass('ui-state-hover');
|
1658
|
+
this.style.cursor='pointer';
|
1659
|
+
}
|
1660
|
+
},function(e) {
|
1661
|
+
if($(this).hasClass('ui-state-disabled')) {
|
1662
|
+
} else {
|
1663
|
+
$(this).removeClass('ui-state-hover');
|
1664
|
+
this.style.cursor= "default";
|
1665
|
+
}
|
1666
|
+
});
|
1667
|
+
$("#first"+tp+", #prev"+tp+", #next"+tp+", #last"+tp,"#"+pgid).click( function(e) {
|
1668
|
+
var cp = intNum(ts.p.page,1),
|
1669
|
+
last = intNum(ts.p.lastpage,1), selclick = false,
|
1670
|
+
fp=true, pp=true, np=true,lp=true;
|
1671
|
+
if(last ===0 || last===1) {fp=false;pp=false;np=false;lp=false; }
|
1672
|
+
else if( last>1 && cp >=1) {
|
1673
|
+
if( cp === 1) { fp=false; pp=false; }
|
1674
|
+
else if( cp>1 && cp <last){ }
|
1675
|
+
else if( cp===last){ np=false;lp=false; }
|
1676
|
+
} else if( last>1 && cp===0 ) { np=false;lp=false; cp=last-1;}
|
1677
|
+
if( this.id === 'first'+tp && fp ) { ts.p.page=1; selclick=true;}
|
1678
|
+
if( this.id === 'prev'+tp && pp) { ts.p.page=(cp-1); selclick=true;}
|
1679
|
+
if( this.id === 'next'+tp && np) { ts.p.page=(cp+1); selclick=true;}
|
1680
|
+
if( this.id === 'last'+tp && lp) { ts.p.page=last; selclick=true;}
|
1681
|
+
if(selclick) {
|
1682
|
+
if(!clearVals(this.id)) { return false; }
|
1683
|
+
populate();
|
1684
|
+
}
|
1685
|
+
return false;
|
1686
|
+
});
|
1687
|
+
}
|
1688
|
+
if(ts.p.pginput===true) {
|
1689
|
+
$('input.ui-pg-input',"#"+pgcnt).keypress( function(e) {
|
1690
|
+
var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
|
1691
|
+
if(key == 13) {
|
1692
|
+
ts.p.page = ($(this).val()>0) ? $(this).val():ts.p.page;
|
1693
|
+
if(!clearVals('user')) { return false; }
|
1694
|
+
populate();
|
1695
|
+
return false;
|
1696
|
+
}
|
1697
|
+
return this;
|
1698
|
+
});
|
1699
|
+
}
|
1700
|
+
},
|
1701
|
+
sortData = function (index, idxcol,reload,sor){
|
1702
|
+
if(!ts.p.colModel[idxcol].sortable) { return; }
|
1703
|
+
var so;
|
1704
|
+
if(ts.p.savedRow.length > 0) {return;}
|
1705
|
+
if(!reload) {
|
1706
|
+
if( ts.p.lastsort == idxcol ) {
|
1707
|
+
if( ts.p.sortorder == 'asc') {
|
1708
|
+
ts.p.sortorder = 'desc';
|
1709
|
+
} else if(ts.p.sortorder == 'desc') { ts.p.sortorder = 'asc';}
|
1710
|
+
} else { ts.p.sortorder = ts.p.colModel[idxcol].firstsortorder || 'asc'; }
|
1711
|
+
ts.p.page = 1;
|
1712
|
+
}
|
1713
|
+
if(sor) {
|
1714
|
+
if(ts.p.lastsort == idxcol && ts.p.sortorder == sor && !reload) { return; }
|
1715
|
+
else { ts.p.sortorder = sor; }
|
1716
|
+
}
|
1717
|
+
var thd= $("thead:first",ts.grid.hDiv).get(0);
|
1718
|
+
$("tr th:eq("+ts.p.lastsort+") span.ui-grid-ico-sort",thd).addClass('ui-state-disabled');
|
1719
|
+
$("tr th:eq("+ts.p.lastsort+")",thd).attr("aria-selected","false");
|
1720
|
+
$("tr th:eq("+idxcol+") span.ui-icon-"+ts.p.sortorder,thd).removeClass('ui-state-disabled');
|
1721
|
+
$("tr th:eq("+idxcol+")",thd).attr("aria-selected","true");
|
1722
|
+
if(!ts.p.viewsortcols[0]) {
|
1723
|
+
if(ts.p.lastsort != idxcol) {
|
1724
|
+
$("tr th:eq("+ts.p.lastsort+") span.s-ico",thd).hide();
|
1725
|
+
$("tr th:eq("+idxcol+") span.s-ico",thd).show();
|
1726
|
+
}
|
1727
|
+
}
|
1728
|
+
index = index.substring(5);
|
1729
|
+
ts.p.sortname = ts.p.colModel[idxcol].index || index;
|
1730
|
+
so = ts.p.sortorder;
|
1731
|
+
if($.isFunction(ts.p.onSortCol)) {if (ts.p.onSortCol.call(ts,index,idxcol,so)=='stop') {ts.p.lastsort = idxcol; return;}}
|
1732
|
+
if(ts.p.datatype == "local") {
|
1733
|
+
if(ts.p.deselectAfterSort) {$(ts).jqGrid("resetSelection");}
|
1734
|
+
} else {
|
1735
|
+
ts.p.selrow = null;
|
1736
|
+
if(ts.p.multiselect){$("#cb_"+$.jgrid.jqID(ts.p.id),ts.grid.hDiv).attr("checked",false);}
|
1737
|
+
ts.p.selarrrow =[];
|
1738
|
+
ts.p.savedRow =[];
|
1739
|
+
}
|
1740
|
+
if(ts.p.scroll) {
|
1741
|
+
var sscroll = ts.grid.bDiv.scrollLeft;
|
1742
|
+
emptyRows(ts.grid.bDiv,true);
|
1743
|
+
ts.grid.hDiv.scrollLeft = sscroll;
|
1744
|
+
}
|
1745
|
+
if(ts.p.subGrid && ts.p.datatype=='local') {
|
1746
|
+
$("td.sgexpanded","#"+ts.p.id).each(function(){
|
1747
|
+
$(this).trigger("click");
|
1748
|
+
});
|
1749
|
+
}
|
1750
|
+
populate();
|
1751
|
+
ts.p.lastsort = idxcol;
|
1752
|
+
if(ts.p.sortname != index && idxcol) {ts.p.lastsort = idxcol;}
|
1753
|
+
},
|
1754
|
+
setColWidth = function () {
|
1755
|
+
var initwidth = 0, brd=ts.p.cellLayout, vc=0, lvc, scw=ts.p.scrollOffset,cw,hs=false,aw,tw=0,gw=0,
|
1756
|
+
cl = 0, cr;
|
1757
|
+
if (isSafari) { brd=0; }
|
1758
|
+
$.each(ts.p.colModel, function(i) {
|
1759
|
+
if(typeof this.hidden === 'undefined') {this.hidden=false;}
|
1760
|
+
if(this.hidden===false){
|
1761
|
+
initwidth += intNum(this.width,0);
|
1762
|
+
if(this.fixed) {
|
1763
|
+
tw += this.width;
|
1764
|
+
gw += this.width+brd;
|
1765
|
+
} else {
|
1766
|
+
vc++;
|
1767
|
+
}
|
1768
|
+
cl++;
|
1769
|
+
}
|
1770
|
+
});
|
1771
|
+
if(isNaN(ts.p.width)) {ts.p.width = grid.width = initwidth;}
|
1772
|
+
else { grid.width = ts.p.width;}
|
1773
|
+
ts.p.tblwidth = initwidth;
|
1774
|
+
if(ts.p.shrinkToFit ===false && ts.p.forceFit === true) {ts.p.forceFit=false;}
|
1775
|
+
if(ts.p.shrinkToFit===true && vc > 0) {
|
1776
|
+
aw = grid.width-brd*vc-gw;
|
1777
|
+
if(isNaN(ts.p.height)) {
|
1778
|
+
} else {
|
1779
|
+
aw -= scw;
|
1780
|
+
hs = true;
|
1781
|
+
}
|
1782
|
+
initwidth =0;
|
1783
|
+
$.each(ts.p.colModel, function(i) {
|
1784
|
+
if(this.hidden === false && !this.fixed){
|
1785
|
+
cw = Math.round(aw*this.width/(ts.p.tblwidth-tw));
|
1786
|
+
this.width =cw;
|
1787
|
+
initwidth += cw;
|
1788
|
+
lvc = i;
|
1789
|
+
}
|
1790
|
+
});
|
1791
|
+
cr =0;
|
1792
|
+
if (hs) {
|
1793
|
+
if(grid.width-gw-(initwidth+brd*vc) !== scw){
|
1794
|
+
cr = grid.width-gw-(initwidth+brd*vc)-scw;
|
1795
|
+
}
|
1796
|
+
} else if(!hs && Math.abs(grid.width-gw-(initwidth+brd*vc)) !== 1) {
|
1797
|
+
cr = grid.width-gw-(initwidth+brd*vc);
|
1798
|
+
}
|
1799
|
+
ts.p.colModel[lvc].width += cr;
|
1800
|
+
ts.p.tblwidth = initwidth+cr+tw+cl*brd;
|
1801
|
+
if(ts.p.tblwidth > ts.p.width) {
|
1802
|
+
ts.p.colModel[lvc].width -= (ts.p.tblwidth - parseInt(ts.p.width,10));
|
1803
|
+
ts.p.tblwidth = ts.p.width;
|
1804
|
+
}
|
1805
|
+
}
|
1806
|
+
},
|
1807
|
+
nextVisible= function(iCol) {
|
1808
|
+
var ret = iCol, j=iCol, i;
|
1809
|
+
for (i = iCol+1;i<ts.p.colModel.length;i++){
|
1810
|
+
if(ts.p.colModel[i].hidden !== true ) {
|
1811
|
+
j=i; break;
|
1812
|
+
}
|
1813
|
+
}
|
1814
|
+
return j-ret;
|
1815
|
+
},
|
1816
|
+
getOffset = function (iCol) {
|
1817
|
+
var i, ret = {}, brd1 = isSafari ? 0 : ts.p.cellLayout;
|
1818
|
+
ret[0] = ret[1] = ret[2] = 0;
|
1819
|
+
for(i=0;i<=iCol;i++){
|
1820
|
+
if(ts.p.colModel[i].hidden === false ) {
|
1821
|
+
ret[0] += ts.p.colModel[i].width+brd1;
|
1822
|
+
}
|
1823
|
+
}
|
1824
|
+
if(ts.p.direction=="rtl") { ret[0] = ts.p.width - ret[0]; }
|
1825
|
+
ret[0] = ret[0] - ts.grid.bDiv.scrollLeft;
|
1826
|
+
if($(ts.grid.cDiv).is(":visible")) {ret[1] += $(ts.grid.cDiv).height() +parseInt($(ts.grid.cDiv).css("padding-top"),10)+parseInt($(ts.grid.cDiv).css("padding-bottom"),10);}
|
1827
|
+
if(ts.p.toolbar[0]===true && (ts.p.toolbar[1]=='top' || ts.p.toolbar[1]=='both')) {ret[1] += $(ts.grid.uDiv).height()+parseInt($(ts.grid.uDiv).css("border-top-width"),10)+parseInt($(ts.grid.uDiv).css("border-bottom-width"),10);}
|
1828
|
+
if(ts.p.toppager) {ret[1] += $(ts.grid.topDiv).height()+parseInt($(ts.grid.topDiv).css("border-bottom-width"),10);}
|
1829
|
+
ret[2] += $(ts.grid.bDiv).height() + $(ts.grid.hDiv).height();
|
1830
|
+
return ret;
|
1831
|
+
};
|
1832
|
+
this.p.id = this.id;
|
1833
|
+
if ($.inArray(ts.p.multikey,sortkeys) == -1 ) {ts.p.multikey = false;}
|
1834
|
+
ts.p.keyIndex=false;
|
1835
|
+
for (i=0; i<ts.p.colModel.length;i++) {
|
1836
|
+
if (ts.p.colModel[i].key===true) {
|
1837
|
+
ts.p.keyIndex = i;
|
1838
|
+
break;
|
1839
|
+
}
|
1840
|
+
}
|
1841
|
+
ts.p.sortorder = ts.p.sortorder.toLowerCase();
|
1842
|
+
if(this.p.treeGrid === true) {
|
1843
|
+
try { $(this).jqGrid("setTreeGrid");} catch (_) {}
|
1844
|
+
if(ts.p.datatype != "local") { ts.p.localReader = {id: "_id_"}; }
|
1845
|
+
}
|
1846
|
+
if(this.p.subGrid) {
|
1847
|
+
try { $(ts).jqGrid("setSubGrid");} catch (_){}
|
1848
|
+
}
|
1849
|
+
if(this.p.multiselect) {
|
1850
|
+
this.p.colNames.unshift("<input role='checkbox' id='cb_"+this.p.id+"' class='cbox' type='checkbox'/>");
|
1851
|
+
this.p.colModel.unshift({name:'cb',width:isSafari ? ts.p.multiselectWidth+ts.p.cellLayout : ts.p.multiselectWidth,sortable:false,resizable:false,hidedlg:true,search:false,align:'center',fixed:true});
|
1852
|
+
}
|
1853
|
+
if(this.p.rownumbers) {
|
1854
|
+
this.p.colNames.unshift("");
|
1855
|
+
this.p.colModel.unshift({name:'rn',width:ts.p.rownumWidth,sortable:false,resizable:false,hidedlg:true,search:false,align:'center',fixed:true});
|
1856
|
+
}
|
1857
|
+
ts.p.xmlReader = $.extend(true,{
|
1858
|
+
root: "rows",
|
1859
|
+
row: "row",
|
1860
|
+
page: "rows>page",
|
1861
|
+
total: "rows>total",
|
1862
|
+
records : "rows>records",
|
1863
|
+
repeatitems: true,
|
1864
|
+
cell: "cell",
|
1865
|
+
id: "[id]",
|
1866
|
+
userdata: "userdata",
|
1867
|
+
subgrid: {root:"rows", row: "row", repeatitems: true, cell:"cell"}
|
1868
|
+
}, ts.p.xmlReader);
|
1869
|
+
ts.p.jsonReader = $.extend(true,{
|
1870
|
+
root: "rows",
|
1871
|
+
page: "page",
|
1872
|
+
total: "total",
|
1873
|
+
records: "records",
|
1874
|
+
repeatitems: true,
|
1875
|
+
cell: "cell",
|
1876
|
+
id: "id",
|
1877
|
+
userdata: "userdata",
|
1878
|
+
subgrid: {root:"rows", repeatitems: true, cell:"cell"}
|
1879
|
+
},ts.p.jsonReader);
|
1880
|
+
ts.p.localReader = $.extend(true,{
|
1881
|
+
root: "rows",
|
1882
|
+
page: "page",
|
1883
|
+
total: "total",
|
1884
|
+
records: "records",
|
1885
|
+
repeatitems: false,
|
1886
|
+
cell: "cell",
|
1887
|
+
id: "id",
|
1888
|
+
userdata: "userdata",
|
1889
|
+
subgrid: {root:"rows", repeatitems: true, cell:"cell"}
|
1890
|
+
},ts.p.localReader);
|
1891
|
+
if(ts.p.scroll){
|
1892
|
+
ts.p.pgbuttons = false; ts.p.pginput=false; ts.p.rowList=[];
|
1893
|
+
}
|
1894
|
+
if(ts.p.data.length) { refreshIndex(); }
|
1895
|
+
var thead = "<thead><tr class='ui-jqgrid-labels' role='rowheader'>",
|
1896
|
+
tdc, idn, w, res, sort,
|
1897
|
+
td, ptr, tbody, imgs,iac="",idc="";
|
1898
|
+
if(ts.p.shrinkToFit===true && ts.p.forceFit===true) {
|
1899
|
+
for (i=ts.p.colModel.length-1;i>=0;i--){
|
1900
|
+
if(!ts.p.colModel[i].hidden) {
|
1901
|
+
ts.p.colModel[i].resizable=false;
|
1902
|
+
break;
|
1903
|
+
}
|
1904
|
+
}
|
1905
|
+
}
|
1906
|
+
if(ts.p.viewsortcols[1] == 'horizontal') {iac=" ui-i-asc";idc=" ui-i-desc";}
|
1907
|
+
tdc = isMSIE ? "class='ui-th-div-ie'" :"";
|
1908
|
+
imgs = "<span class='s-ico' style='display:none'><span sort='asc' class='ui-grid-ico-sort ui-icon-asc"+iac+" ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-"+dir+"'></span>";
|
1909
|
+
imgs += "<span sort='desc' class='ui-grid-ico-sort ui-icon-desc"+idc+" ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-"+dir+"'></span></span>";
|
1910
|
+
for(i=0;i<this.p.colNames.length;i++){
|
1911
|
+
var tooltip = ts.p.headertitles ? (" title=\""+$.jgrid.stripHtml(ts.p.colNames[i])+"\"") :"";
|
1912
|
+
thead += "<th id='"+ts.p.id+"_"+ts.p.colModel[i].name+"' role='columnheader' class='ui-state-default ui-th-column ui-th-"+dir+"'"+ tooltip+">";
|
1913
|
+
idn = ts.p.colModel[i].index || ts.p.colModel[i].name;
|
1914
|
+
thead += "<div id='jqgh_"+ts.p.colModel[i].name+"' "+tdc+">"+ts.p.colNames[i];
|
1915
|
+
if(!ts.p.colModel[i].width) { ts.p.colModel[i].width = 150; }
|
1916
|
+
else { ts.p.colModel[i].width = parseInt(ts.p.colModel[i].width,10); }
|
1917
|
+
if(typeof(ts.p.colModel[i].title) !== "boolean") { ts.p.colModel[i].title = true; }
|
1918
|
+
if (idn == ts.p.sortname) {
|
1919
|
+
ts.p.lastsort = i;
|
1920
|
+
}
|
1921
|
+
thead += imgs+"</div></th>";
|
1922
|
+
}
|
1923
|
+
thead += "</tr></thead>";
|
1924
|
+
$(this).append(thead);
|
1925
|
+
$("thead tr:first th",this).hover(function(){$(this).addClass('ui-state-hover');},function(){$(this).removeClass('ui-state-hover');});
|
1926
|
+
if(this.p.multiselect) {
|
1927
|
+
var emp=[], chk;
|
1928
|
+
$('#cb_'+$.jgrid.jqID(ts.p.id),this).bind('click',function(){
|
1929
|
+
if (this.checked) {
|
1930
|
+
$("[id^=jqg_]",ts.rows).attr("checked",true);
|
1931
|
+
$(ts.rows).each(function(i) {
|
1932
|
+
if(!$(this).hasClass("subgrid")){
|
1933
|
+
$(this).addClass("ui-state-highlight").attr("aria-selected","true");
|
1934
|
+
ts.p.selarrrow[i]= ts.p.selrow = this.id;
|
1935
|
+
}
|
1936
|
+
});
|
1937
|
+
chk=true;
|
1938
|
+
emp=[];
|
1939
|
+
}
|
1940
|
+
else {
|
1941
|
+
$("[id^=jqg_]",ts.rows).attr("checked",false);
|
1942
|
+
$(ts.rows).each(function(i) {
|
1943
|
+
if(!$(this).hasClass("subgrid")){
|
1944
|
+
$(this).removeClass("ui-state-highlight").attr("aria-selected","false");
|
1945
|
+
emp[i] = this.id;
|
1946
|
+
}
|
1947
|
+
});
|
1948
|
+
ts.p.selarrrow = []; ts.p.selrow = null;
|
1949
|
+
chk=false;
|
1950
|
+
}
|
1951
|
+
if($.isFunction(ts.p.onSelectAll)) {ts.p.onSelectAll.call(ts, chk ? ts.p.selarrrow : emp,chk);}
|
1952
|
+
});
|
1953
|
+
}
|
1954
|
+
|
1955
|
+
if(ts.p.autowidth===true) {
|
1956
|
+
var pw = $(eg).innerWidth();
|
1957
|
+
ts.p.width = pw > 0? pw: 'nw';
|
1958
|
+
}
|
1959
|
+
setColWidth();
|
1960
|
+
$(eg).css("width",grid.width+"px").append("<div class='ui-jqgrid-resize-mark' id='rs_m"+ts.p.id+"'> </div>");
|
1961
|
+
$(gv).css("width",grid.width+"px");
|
1962
|
+
thead = $("thead:first",ts).get(0);
|
1963
|
+
var tfoot = "";
|
1964
|
+
if(ts.p.footerrow) { tfoot += "<table role='grid' style='width:"+ts.p.tblwidth+"px' class='ui-jqgrid-ftable' cellspacing='0' cellpadding='0' border='0'><tbody><tr role='row' class='ui-widget-content footrow footrow-"+dir+"'>"; }
|
1965
|
+
var thr = $("tr:first",thead);
|
1966
|
+
ts.p.disableClick=false;
|
1967
|
+
$("th",thr).each(function ( j ) {
|
1968
|
+
w = ts.p.colModel[j].width;
|
1969
|
+
if(typeof ts.p.colModel[j].resizable === 'undefined') {ts.p.colModel[j].resizable = true;}
|
1970
|
+
if(ts.p.colModel[j].resizable){
|
1971
|
+
res = document.createElement("span");
|
1972
|
+
$(res).html(" ").addClass('ui-jqgrid-resize ui-jqgrid-resize-'+dir);
|
1973
|
+
if(!$.browser.opera) { $(res).css("cursor","col-resize"); }
|
1974
|
+
$(this).addClass(ts.p.resizeclass);
|
1975
|
+
} else {
|
1976
|
+
res = "";
|
1977
|
+
}
|
1978
|
+
$(this).css("width",w+"px").prepend(res);
|
1979
|
+
if( ts.p.colModel[j].hidden ) { $(this).css("display","none"); }
|
1980
|
+
grid.headers[j] = { width: w, el: this };
|
1981
|
+
sort = ts.p.colModel[j].sortable;
|
1982
|
+
if( typeof sort !== 'boolean') {ts.p.colModel[j].sortable = true; sort=true;}
|
1983
|
+
var nm = ts.p.colModel[j].name;
|
1984
|
+
if( !(nm == 'cb' || nm=='subgrid' || nm=='rn') ) {
|
1985
|
+
if(ts.p.viewsortcols[2]){
|
1986
|
+
$("div",this).addClass('ui-jqgrid-sortable');
|
1987
|
+
}
|
1988
|
+
}
|
1989
|
+
if(sort) {
|
1990
|
+
if(ts.p.viewsortcols[0]) {$("div span.s-ico",this).show(); if(j==ts.p.lastsort){ $("div span.ui-icon-"+ts.p.sortorder,this).removeClass("ui-state-disabled");}}
|
1991
|
+
else if( j == ts.p.lastsort) {$("div span.s-ico",this).show();$("div span.ui-icon-"+ts.p.sortorder,this).removeClass("ui-state-disabled");}
|
1992
|
+
}
|
1993
|
+
if(ts.p.footerrow) { tfoot += "<td role='gridcell' "+formatCol(j,0,'')+"> </td>"; }
|
1994
|
+
}).mousedown(function(e) {
|
1995
|
+
if ($(e.target).closest("th>span.ui-jqgrid-resize").length != 1) { return; }
|
1996
|
+
var ci = $.jgrid.getCellIndex(this);
|
1997
|
+
if(ts.p.forceFit===true) {ts.p.nv= nextVisible(ci);}
|
1998
|
+
grid.dragStart(ci, e, getOffset(ci));
|
1999
|
+
return false;
|
2000
|
+
}).click(function(e) {
|
2001
|
+
if (ts.p.disableClick) {
|
2002
|
+
ts.p.disableClick = false;
|
2003
|
+
return false;
|
2004
|
+
}
|
2005
|
+
var s = "th>div.ui-jqgrid-sortable",r,d;
|
2006
|
+
if (!ts.p.viewsortcols[2]) { s = "th>div>span>span.ui-grid-ico-sort"; }
|
2007
|
+
var t = $(e.target).closest(s);
|
2008
|
+
if (t.length != 1) { return; }
|
2009
|
+
var ci = $.jgrid.getCellIndex(this);
|
2010
|
+
if (!ts.p.viewsortcols[2]) { r=true;d=t.attr("sort"); }
|
2011
|
+
sortData($('div',this)[0].id,ci,r,d);
|
2012
|
+
return false;
|
2013
|
+
});
|
2014
|
+
if (ts.p.sortable && $.fn.sortable) {
|
2015
|
+
try {
|
2016
|
+
$(ts).jqGrid("sortableColumns", thr);
|
2017
|
+
} catch (e){}
|
2018
|
+
}
|
2019
|
+
if(ts.p.footerrow) { tfoot += "</tr></tbody></table>"; }
|
2020
|
+
|
2021
|
+
tbody = document.createElement("tbody");
|
2022
|
+
this.appendChild(tbody);
|
2023
|
+
$(this).addClass('ui-jqgrid-btable');
|
2024
|
+
var hTable = $("<table class='ui-jqgrid-htable' style='width:"+ts.p.tblwidth+"px' role='grid' aria-labelledby='gbox_"+this.id+"' cellspacing='0' cellpadding='0' border='0'></table>").append(thead),
|
2025
|
+
hg = (ts.p.caption && ts.p.hiddengrid===true) ? true : false,
|
2026
|
+
hb = $("<div class='ui-jqgrid-hbox" + (dir=="rtl" ? "-rtl" : "" )+"'></div>");
|
2027
|
+
grid.hDiv = document.createElement("div");
|
2028
|
+
$(grid.hDiv)
|
2029
|
+
.css({ width: grid.width+"px"})
|
2030
|
+
.addClass("ui-state-default ui-jqgrid-hdiv")
|
2031
|
+
.append(hb);
|
2032
|
+
$(hb).append(hTable);
|
2033
|
+
if(hg) { $(grid.hDiv).hide(); }
|
2034
|
+
if(ts.p.pager){
|
2035
|
+
if(typeof ts.p.pager == "string") {if(ts.p.pager.substr(0,1) !="#") { ts.p.pager = "#"+ts.p.pager;} }
|
2036
|
+
else { ts.p.pager = "#"+ $(ts.p.pager).attr("id");}
|
2037
|
+
$(ts.p.pager).css({width: grid.width+"px"}).appendTo(eg).addClass('ui-state-default ui-jqgrid-pager ui-corner-bottom');
|
2038
|
+
if(hg) {$(ts.p.pager).hide();}
|
2039
|
+
setPager(ts.p.pager,'');
|
2040
|
+
}
|
2041
|
+
if( ts.p.cellEdit === false && ts.p.hoverrows === true) {
|
2042
|
+
$(ts).bind('mouseover',function(e) {
|
2043
|
+
ptr = $(e.target).closest("tr.jqgrow");
|
2044
|
+
if($(ptr).attr("class") !== "subgrid") {
|
2045
|
+
$(ptr).addClass("ui-state-hover");
|
2046
|
+
}
|
2047
|
+
return false;
|
2048
|
+
}).bind('mouseout',function(e) {
|
2049
|
+
ptr = $(e.target).closest("tr.jqgrow");
|
2050
|
+
$(ptr).removeClass("ui-state-hover");
|
2051
|
+
return false;
|
2052
|
+
});
|
2053
|
+
}
|
2054
|
+
var ri,ci;
|
2055
|
+
$(ts).before(grid.hDiv).click(function(e) {
|
2056
|
+
td = e.target;
|
2057
|
+
var scb = $(td).hasClass("cbox");
|
2058
|
+
ptr = $(td,ts.rows).closest("tr.jqgrow");
|
2059
|
+
if($(ptr).length === 0 ) {
|
2060
|
+
return this;
|
2061
|
+
}
|
2062
|
+
var cSel = true;
|
2063
|
+
if($.isFunction(ts.p.beforeSelectRow)) { cSel = ts.p.beforeSelectRow.call(ts,ptr[0].id, e); }
|
2064
|
+
if (td.tagName == 'A' || ((td.tagName == 'INPUT' || td.tagName == 'TEXTAREA' || td.tagName == 'OPTION' || td.tagName == 'SELECT' ) && !scb) ) { return this; }
|
2065
|
+
if(cSel === true) {
|
2066
|
+
if(ts.p.cellEdit === true) {
|
2067
|
+
if(ts.p.multiselect && scb){
|
2068
|
+
$(ts).jqGrid("setSelection",ptr[0].id,true);
|
2069
|
+
} else {
|
2070
|
+
ri = ptr[0].rowIndex;
|
2071
|
+
ci = $.jgrid.getCellIndex(td);
|
2072
|
+
try {$(ts).jqGrid("editCell",ri,ci,true);} catch (_) {}
|
2073
|
+
}
|
2074
|
+
} else if ( !ts.p.multikey ) {
|
2075
|
+
if(ts.p.multiselect && ts.p.multiboxonly) {
|
2076
|
+
if(scb){$(ts).jqGrid("setSelection",ptr[0].id,true);}
|
2077
|
+
else {
|
2078
|
+
$(ts.p.selarrrow).each(function(i,n){
|
2079
|
+
var ind = ts.rows.namedItem(n);
|
2080
|
+
$(ind).removeClass("ui-state-highlight");
|
2081
|
+
$("#jqg_"+$.jgrid.jqID(n),ind).attr("checked",false);
|
2082
|
+
});
|
2083
|
+
ts.p.selarrrow = [];
|
2084
|
+
$("#cb_"+$.jgrid.jqID(ts.p.id),ts.grid.hDiv).attr("checked",false);
|
2085
|
+
$(ts).jqGrid("setSelection",ptr[0].id,true);
|
2086
|
+
}
|
2087
|
+
} else {
|
2088
|
+
$(ts).jqGrid("setSelection",ptr[0].id,true);
|
2089
|
+
}
|
2090
|
+
} else {
|
2091
|
+
if(e[ts.p.multikey]) {
|
2092
|
+
$(ts).jqGrid("setSelection",ptr[0].id,true);
|
2093
|
+
} else if(ts.p.multiselect && scb) {
|
2094
|
+
scb = $("[id^=jqg_]",ptr).attr("checked");
|
2095
|
+
$("[id^=jqg_]",ptr).attr("checked",!scb);
|
2096
|
+
}
|
2097
|
+
}
|
2098
|
+
if($.isFunction(ts.p.onCellSelect)) {
|
2099
|
+
ri = ptr[0].id;
|
2100
|
+
ci = $.jgrid.getCellIndex(td);
|
2101
|
+
ts.p.onCellSelect.call(ts,ri,ci,$(td).html(),e);
|
2102
|
+
}
|
2103
|
+
e.stopPropagation();
|
2104
|
+
} else {
|
2105
|
+
return this;
|
2106
|
+
}
|
2107
|
+
}).bind('reloadGrid', function(e,opts) {
|
2108
|
+
if(ts.p.treeGrid ===true) {
|
2109
|
+
ts.p.datatype = ts.p.treedatatype;
|
2110
|
+
if( ts.p.postData.hasOwnProperty('nodeid') && ts.p.postData.nodeid == '') {
|
2111
|
+
ts.p.data = []; _index={};
|
2112
|
+
}
|
2113
|
+
}
|
2114
|
+
if (opts && opts.current) {
|
2115
|
+
ts.grid.selectionPreserver(ts);
|
2116
|
+
}
|
2117
|
+
if(ts.p.datatype=="local"){ $(ts).jqGrid("resetSelection");}
|
2118
|
+
else if(!ts.p.treeGrid) {
|
2119
|
+
ts.p.selrow=null;
|
2120
|
+
if(ts.p.multiselect) {ts.p.selarrrow =[];$('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.hDiv).attr("checked",false);}
|
2121
|
+
ts.p.savedRow = [];
|
2122
|
+
}
|
2123
|
+
if(ts.p.scroll) {emptyRows(ts.grid.bDiv,true);}
|
2124
|
+
if (opts && opts.page) {
|
2125
|
+
var page = opts.page;
|
2126
|
+
if (page > ts.p.lastpage) { page = ts.p.lastpage; }
|
2127
|
+
if (page < 1) { page = 1; }
|
2128
|
+
ts.p.page = page;
|
2129
|
+
if (ts.grid.prevRowHeight) {
|
2130
|
+
ts.grid.bDiv.scrollTop = (page - 1) * ts.grid.prevRowHeight * ts.p.rowNum;
|
2131
|
+
} else {
|
2132
|
+
ts.grid.bDiv.scrollTop = 0;
|
2133
|
+
}
|
2134
|
+
}
|
2135
|
+
if (ts.grid.prevRowHeight && ts.p.scroll) {
|
2136
|
+
delete ts.p.lastpage;
|
2137
|
+
ts.grid.populateVisible();
|
2138
|
+
} else {
|
2139
|
+
ts.grid.populate();
|
2140
|
+
}
|
2141
|
+
return false;
|
2142
|
+
});
|
2143
|
+
if( $.isFunction(this.p.ondblClickRow) ) {
|
2144
|
+
$(this).dblclick(function(e) {
|
2145
|
+
td = e.target;
|
2146
|
+
ptr = $(td,ts.rows).closest("tr.jqgrow");
|
2147
|
+
if($(ptr).length === 0 ){return false;}
|
2148
|
+
ri = ptr[0].rowIndex;
|
2149
|
+
ci = $.jgrid.getCellIndex(td);
|
2150
|
+
ts.p.ondblClickRow.call(ts,$(ptr).attr("id"),ri,ci, e);
|
2151
|
+
return false;
|
2152
|
+
});
|
2153
|
+
}
|
2154
|
+
if ($.isFunction(this.p.onRightClickRow)) {
|
2155
|
+
$(this).bind('contextmenu', function(e) {
|
2156
|
+
td = e.target;
|
2157
|
+
ptr = $(td,ts.rows).closest("tr.jqgrow");
|
2158
|
+
if($(ptr).length === 0 ){return false;}
|
2159
|
+
if(!ts.p.multiselect) { $(ts).jqGrid("setSelection",ptr[0].id,true); }
|
2160
|
+
ri = ptr[0].rowIndex;
|
2161
|
+
ci = $.jgrid.getCellIndex(td);
|
2162
|
+
ts.p.onRightClickRow.call(ts,$(ptr).attr("id"),ri,ci, e);
|
2163
|
+
return false;
|
2164
|
+
});
|
2165
|
+
}
|
2166
|
+
grid.bDiv = document.createElement("div");
|
2167
|
+
$(grid.bDiv)
|
2168
|
+
.append($('<div style="position:relative;'+(isMSIE && $.browser.version < 8 ? "height:0.01%;" : "")+'"></div>').append('<div></div>').append(this))
|
2169
|
+
.addClass("ui-jqgrid-bdiv")
|
2170
|
+
.css({ height: ts.p.height+(isNaN(ts.p.height)?"":"px"), width: (grid.width)+"px"})
|
2171
|
+
.scroll(grid.scrollGrid);
|
2172
|
+
$("table:first",grid.bDiv).css({width:ts.p.tblwidth+"px"});
|
2173
|
+
if( isMSIE ) {
|
2174
|
+
if( $("tbody",this).size() == 2 ) { $("tbody:first",this).remove();}
|
2175
|
+
if( ts.p.multikey) {$(grid.bDiv).bind("selectstart",function(){return false;});}
|
2176
|
+
} else {
|
2177
|
+
if( ts.p.multikey) {$(grid.bDiv).bind("mousedown",function(){return false;});}
|
2178
|
+
}
|
2179
|
+
if(hg) {$(grid.bDiv).hide();}
|
2180
|
+
grid.cDiv = document.createElement("div");
|
2181
|
+
var arf = ts.p.hidegrid===true ? $("<a role='link' href='javascript:void(0)'/>").addClass('ui-jqgrid-titlebar-close HeaderButton').hover(
|
2182
|
+
function(){ arf.addClass('ui-state-hover');},
|
2183
|
+
function() {arf.removeClass('ui-state-hover');})
|
2184
|
+
.append("<span class='ui-icon ui-icon-circle-triangle-n'></span>").css((dir=="rtl"?"left":"right"),"0px") : "";
|
2185
|
+
$(grid.cDiv).append(arf).append("<span class='ui-jqgrid-title"+(dir=="rtl" ? "-rtl" :"" )+"'>"+ts.p.caption+"</span>")
|
2186
|
+
.addClass("ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix");
|
2187
|
+
$(grid.cDiv).insertBefore(grid.hDiv);
|
2188
|
+
if( ts.p.toolbar[0] ) {
|
2189
|
+
grid.uDiv = document.createElement("div");
|
2190
|
+
if(ts.p.toolbar[1] == "top") {$(grid.uDiv).insertBefore(grid.hDiv);}
|
2191
|
+
else if (ts.p.toolbar[1]=="bottom" ) {$(grid.uDiv).insertAfter(grid.hDiv);}
|
2192
|
+
if(ts.p.toolbar[1]=="both") {
|
2193
|
+
grid.ubDiv = document.createElement("div");
|
2194
|
+
$(grid.uDiv).insertBefore(grid.hDiv).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id);
|
2195
|
+
$(grid.ubDiv).insertAfter(grid.hDiv).addClass("ui-userdata ui-state-default").attr("id","tb_"+this.id);
|
2196
|
+
if(hg) {$(grid.ubDiv).hide();}
|
2197
|
+
} else {
|
2198
|
+
$(grid.uDiv).width(grid.width).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id);
|
2199
|
+
}
|
2200
|
+
if(hg) {$(grid.uDiv).hide();}
|
2201
|
+
}
|
2202
|
+
if(ts.p.toppager) {
|
2203
|
+
ts.p.toppager = ts.p.id+"_toppager";
|
2204
|
+
grid.topDiv = $("<div id='"+ts.p.toppager+"'></div>")[0];
|
2205
|
+
ts.p.toppager = "#"+ts.p.toppager;
|
2206
|
+
$(grid.topDiv).insertBefore(grid.hDiv).addClass('ui-state-default ui-jqgrid-toppager').width(grid.width);
|
2207
|
+
setPager(ts.p.toppager,'_t');
|
2208
|
+
}
|
2209
|
+
if(ts.p.footerrow) {
|
2210
|
+
grid.sDiv = $("<div class='ui-jqgrid-sdiv'></div>")[0];
|
2211
|
+
hb = $("<div class='ui-jqgrid-hbox"+(dir=="rtl"?"-rtl":"")+"'></div>");
|
2212
|
+
$(grid.sDiv).append(hb).insertAfter(grid.hDiv).width(grid.width);
|
2213
|
+
$(hb).append(tfoot);
|
2214
|
+
grid.footers = $(".ui-jqgrid-ftable",grid.sDiv)[0].rows[0].cells;
|
2215
|
+
if(ts.p.rownumbers) { grid.footers[0].className = 'ui-state-default jqgrid-rownum'; }
|
2216
|
+
if(hg) {$(grid.sDiv).hide();}
|
2217
|
+
}
|
2218
|
+
if(ts.p.caption) {
|
2219
|
+
var tdt = ts.p.datatype;
|
2220
|
+
if(ts.p.hidegrid===true) {
|
2221
|
+
$(".ui-jqgrid-titlebar-close",grid.cDiv).click( function(e){
|
2222
|
+
var onHdCl = $.isFunction(ts.p.onHeaderClick);
|
2223
|
+
if(ts.p.gridstate == 'visible') {
|
2224
|
+
$(".ui-jqgrid-bdiv, .ui-jqgrid-hdiv","#gview_"+ts.p.id).slideUp("fast");
|
2225
|
+
if(ts.p.pager) {$(ts.p.pager).slideUp("fast");}
|
2226
|
+
if(ts.p.toppager) {$(ts.p.toppager).slideUp("fast");}
|
2227
|
+
if(ts.p.toolbar[0]===true) {
|
2228
|
+
if( ts.p.toolbar[1]=='both') {
|
2229
|
+
$(grid.ubDiv).slideUp("fast");
|
2230
|
+
}
|
2231
|
+
$(grid.uDiv).slideUp("fast");
|
2232
|
+
}
|
2233
|
+
if(ts.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+ts.p.id).slideUp("fast"); }
|
2234
|
+
$("span",this).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s");
|
2235
|
+
ts.p.gridstate = 'hidden';
|
2236
|
+
if($("#gbox_"+ts.p.id).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+ts.p.id).hide(); }
|
2237
|
+
if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}}
|
2238
|
+
} else if(ts.p.gridstate == 'hidden'){
|
2239
|
+
$(".ui-jqgrid-hdiv, .ui-jqgrid-bdiv","#gview_"+ts.p.id).slideDown("fast");
|
2240
|
+
if(ts.p.pager) {$(ts.p.pager).slideDown("fast");}
|
2241
|
+
if(ts.p.toppager) {$(ts.p.toppager).slideDown("fast");}
|
2242
|
+
if(ts.p.toolbar[0]===true) {
|
2243
|
+
if( ts.p.toolbar[1]=='both') {
|
2244
|
+
$(grid.ubDiv).slideDown("fast");
|
2245
|
+
}
|
2246
|
+
$(grid.uDiv).slideDown("fast");
|
2247
|
+
}
|
2248
|
+
if(ts.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+ts.p.id).slideDown("fast"); }
|
2249
|
+
$("span",this).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n");
|
2250
|
+
if(hg) {ts.p.datatype = tdt;populate();hg=false;}
|
2251
|
+
ts.p.gridstate = 'visible';
|
2252
|
+
if($("#gbox_"+ts.p.id).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+ts.p.id).show(); }
|
2253
|
+
if(onHdCl) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}
|
2254
|
+
}
|
2255
|
+
return false;
|
2256
|
+
});
|
2257
|
+
if(hg) {ts.p.datatype="local"; $(".ui-jqgrid-titlebar-close",grid.cDiv).trigger("click");}
|
2258
|
+
}
|
2259
|
+
} else {$(grid.cDiv).hide();}
|
2260
|
+
$(grid.hDiv).after(grid.bDiv)
|
2261
|
+
.mousemove(function (e) {
|
2262
|
+
if(grid.resizing){grid.dragMove(e);return false;}
|
2263
|
+
});
|
2264
|
+
$(".ui-jqgrid-labels",grid.hDiv).bind("selectstart", function () { return false; });
|
2265
|
+
$(document).mouseup(function (e) {
|
2266
|
+
if(grid.resizing) { grid.dragEnd(); return false;}
|
2267
|
+
return true;
|
2268
|
+
});
|
2269
|
+
this.updateColumns = function () {
|
2270
|
+
var r = this.rows[0], self =this;
|
2271
|
+
if(r) {
|
2272
|
+
$("td",r).each( function( k ) {
|
2273
|
+
$(this).css("width",self.grid.headers[k].width+"px");
|
2274
|
+
});
|
2275
|
+
this.grid.cols = r.cells;
|
2276
|
+
}
|
2277
|
+
return this;
|
2278
|
+
};
|
2279
|
+
ts.formatCol = formatCol;
|
2280
|
+
ts.sortData = sortData;
|
2281
|
+
ts.updatepager = updatepager;
|
2282
|
+
ts.refreshIndex = refreshIndex;
|
2283
|
+
ts.formatter = function ( rowId, cellval , colpos, rwdat, act){return formatter(rowId, cellval , colpos, rwdat, act);};
|
2284
|
+
$.extend(grid,{populate : populate, emptyRows: emptyRows});
|
2285
|
+
this.grid = grid;
|
2286
|
+
ts.addXmlData = function(d) {addXmlData(d,ts.grid.bDiv);};
|
2287
|
+
ts.addJSONData = function(d) {addJSONData(d,ts.grid.bDiv);};
|
2288
|
+
populate();ts.p.hiddengrid=false;
|
2289
|
+
$(window).unload(function () {
|
2290
|
+
ts = null;
|
2291
|
+
});
|
2292
|
+
});
|
2293
|
+
};
|
2294
|
+
$.jgrid.extend({
|
2295
|
+
getGridParam : function(pName) {
|
2296
|
+
var $t = this[0];
|
2297
|
+
if (!$t || !$t.grid) {return;}
|
2298
|
+
if (!pName) { return $t.p; }
|
2299
|
+
else {return typeof($t.p[pName]) != "undefined" ? $t.p[pName] : null;}
|
2300
|
+
},
|
2301
|
+
setGridParam : function (newParams){
|
2302
|
+
return this.each(function(){
|
2303
|
+
if (this.grid && typeof(newParams) === 'object') {$.extend(true,this.p,newParams);}
|
2304
|
+
});
|
2305
|
+
},
|
2306
|
+
getDataIDs : function () {
|
2307
|
+
var ids=[], i=0, len;
|
2308
|
+
this.each(function(){
|
2309
|
+
len = this.rows.length;
|
2310
|
+
if(len && len>0){
|
2311
|
+
while(i<len) {
|
2312
|
+
ids[i] = this.rows[i].id;
|
2313
|
+
i++;
|
2314
|
+
}
|
2315
|
+
}
|
2316
|
+
});
|
2317
|
+
return ids;
|
2318
|
+
},
|
2319
|
+
setSelection : function(selection,onsr) {
|
2320
|
+
return this.each(function(){
|
2321
|
+
var $t = this, stat,pt, ner, ia, tpsr;
|
2322
|
+
if(selection === undefined) { return; }
|
2323
|
+
onsr = onsr === false ? false : true;
|
2324
|
+
pt=$t.rows.namedItem(selection+"");
|
2325
|
+
if(!pt) { return; }
|
2326
|
+
function scrGrid(iR){
|
2327
|
+
var ch = $($t.grid.bDiv)[0].clientHeight,
|
2328
|
+
st = $($t.grid.bDiv)[0].scrollTop,
|
2329
|
+
rpos = $t.rows[iR].offsetTop,
|
2330
|
+
rh = $t.rows[iR].clientHeight;
|
2331
|
+
if(rpos+rh >= ch+st) { $($t.grid.bDiv)[0].scrollTop = rpos-(ch+st)+rh+st; }
|
2332
|
+
else if(rpos < ch+st) {
|
2333
|
+
if(rpos < st) {
|
2334
|
+
$($t.grid.bDiv)[0].scrollTop = rpos;
|
2335
|
+
}
|
2336
|
+
}
|
2337
|
+
}
|
2338
|
+
if($t.p.scrollrows===true) {
|
2339
|
+
ner = $t.rows.namedItem(selection).rowIndex;
|
2340
|
+
if(ner >=0 ){
|
2341
|
+
scrGrid(ner);
|
2342
|
+
}
|
2343
|
+
}
|
2344
|
+
if(!$t.p.multiselect) {
|
2345
|
+
if(pt.className !== "ui-subgrid") {
|
2346
|
+
if( $t.p.selrow ) { $($t.rows.namedItem($t.p.selrow)).removeClass("ui-state-highlight").attr("aria-selected","false"); }
|
2347
|
+
$t.p.selrow = pt.id;
|
2348
|
+
$(pt).addClass("ui-state-highlight").attr("aria-selected","true");
|
2349
|
+
if( $t.p.onSelectRow && onsr) { $t.p.onSelectRow.call($t,$t.p.selrow, true); }
|
2350
|
+
}
|
2351
|
+
} else {
|
2352
|
+
$t.p.selrow = pt.id;
|
2353
|
+
ia = $.inArray($t.p.selrow,$t.p.selarrrow);
|
2354
|
+
if ( ia === -1 ){
|
2355
|
+
if(pt.className !== "ui-subgrid") { $(pt).addClass("ui-state-highlight").attr("aria-selected","true");}
|
2356
|
+
stat = true;
|
2357
|
+
$("#jqg_"+$.jgrid.jqID($t.p.selrow),$t.rows[pt.rowIndex]).attr("checked",stat);
|
2358
|
+
$t.p.selarrrow.push($t.p.selrow);
|
2359
|
+
if( $t.p.onSelectRow && onsr) { $t.p.onSelectRow.call($t,$t.p.selrow, stat); }
|
2360
|
+
} else {
|
2361
|
+
if(pt.className !== "ui-subgrid") { $(pt).removeClass("ui-state-highlight").attr("aria-selected","false");}
|
2362
|
+
stat = false;
|
2363
|
+
$("#jqg_"+$.jgrid.jqID($t.p.selrow),$t.rows[pt.rowIndex]).attr("checked",stat);
|
2364
|
+
$t.p.selarrrow.splice(ia,1);
|
2365
|
+
if( $t.p.onSelectRow && onsr) { $t.p.onSelectRow.call($t,$t.p.selrow, stat); }
|
2366
|
+
tpsr = $t.p.selarrrow[0];
|
2367
|
+
$t.p.selrow = (tpsr === undefined) ? null : tpsr;
|
2368
|
+
}
|
2369
|
+
}
|
2370
|
+
});
|
2371
|
+
},
|
2372
|
+
resetSelection : function(){
|
2373
|
+
return this.each(function(){
|
2374
|
+
var t = this, ind;
|
2375
|
+
if(!t.p.multiselect) {
|
2376
|
+
if(t.p.selrow) {
|
2377
|
+
$("tr#"+$.jgrid.jqID(t.p.selrow),t.grid.bDiv).removeClass("ui-state-highlight").attr("aria-selected","false");
|
2378
|
+
t.p.selrow = null;
|
2379
|
+
}
|
2380
|
+
} else {
|
2381
|
+
$(t.p.selarrrow).each(function(i,n){
|
2382
|
+
ind = t.rows.namedItem(n);
|
2383
|
+
$(ind).removeClass("ui-state-highlight").attr("aria-selected","false");
|
2384
|
+
$("#jqg_"+$.jgrid.jqID(n),ind).attr("checked",false);
|
2385
|
+
});
|
2386
|
+
$("#cb_"+$.jgrid.jqID(t.p.id),t.grid.hDiv).attr("checked",false);
|
2387
|
+
t.p.selarrrow = [];
|
2388
|
+
}
|
2389
|
+
t.p.savedRow = [];
|
2390
|
+
});
|
2391
|
+
},
|
2392
|
+
getRowData : function( rowid ) {
|
2393
|
+
var res = {}, resall, getall=false, len, j=0;
|
2394
|
+
this.each(function(){
|
2395
|
+
var $t = this,nm,ind;
|
2396
|
+
if(typeof(rowid) == 'undefined') {
|
2397
|
+
getall = true;
|
2398
|
+
resall = [];
|
2399
|
+
len = $t.rows.length;
|
2400
|
+
} else {
|
2401
|
+
ind = $t.rows.namedItem(rowid);
|
2402
|
+
if(!ind) { return res; }
|
2403
|
+
len = 1;
|
2404
|
+
}
|
2405
|
+
while(j<len){
|
2406
|
+
if(getall) { ind = $t.rows[j]; }
|
2407
|
+
$('td',ind).each( function(i) {
|
2408
|
+
nm = $t.p.colModel[i].name;
|
2409
|
+
if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
|
2410
|
+
if($t.p.treeGrid===true && nm == $t.p.ExpandColumn) {
|
2411
|
+
res[nm] = $.jgrid.htmlDecode($("span:first",this).html());
|
2412
|
+
} else {
|
2413
|
+
try {
|
2414
|
+
res[nm] = $.unformat(this,{rowId:ind.id, colModel:$t.p.colModel[i]},i);
|
2415
|
+
} catch (e){
|
2416
|
+
res[nm] = $.jgrid.htmlDecode($(this).html());
|
2417
|
+
}
|
2418
|
+
}
|
2419
|
+
}
|
2420
|
+
});
|
2421
|
+
j++;
|
2422
|
+
if(getall) { resall.push(res); res={}; }
|
2423
|
+
}
|
2424
|
+
});
|
2425
|
+
return resall ? resall: res;
|
2426
|
+
},
|
2427
|
+
delRowData : function(rowid) {
|
2428
|
+
var success = false, rowInd, ia, ri;
|
2429
|
+
this.each(function() {
|
2430
|
+
var $t = this;
|
2431
|
+
rowInd = $t.rows.namedItem(rowid);
|
2432
|
+
if(!rowInd) {return false;}
|
2433
|
+
else {
|
2434
|
+
ri = rowInd.rowIndex;
|
2435
|
+
$(rowInd).remove();
|
2436
|
+
$t.p.records--;
|
2437
|
+
$t.p.reccount--;
|
2438
|
+
$t.updatepager(true,false);
|
2439
|
+
success=true;
|
2440
|
+
if($t.p.multiselect) {
|
2441
|
+
ia = $.inArray(rowid,$t.p.selarrrow);
|
2442
|
+
if(ia != -1) { $t.p.selarrrow.splice(ia,1);}
|
2443
|
+
}
|
2444
|
+
if(rowid == $t.p.selrow) {$t.p.selrow=null;}
|
2445
|
+
}
|
2446
|
+
if($t.p.datatype == 'local') {
|
2447
|
+
var pos = null;
|
2448
|
+
pos = $t.p._index[rowid];
|
2449
|
+
if(pos !== null) {
|
2450
|
+
$t.p.data.splice(pos,1);
|
2451
|
+
$t.refreshIndex();
|
2452
|
+
}
|
2453
|
+
}
|
2454
|
+
if( ri === 0 && success ) {
|
2455
|
+
$t.updateColumns();
|
2456
|
+
}
|
2457
|
+
if( $t.p.altRows === true && success ) {
|
2458
|
+
var cn = $t.p.altclass;
|
2459
|
+
$($t.rows).each(function(i){
|
2460
|
+
if(i % 2 ==1) { $(this).addClass(cn); }
|
2461
|
+
else { $(this).removeClass(cn); }
|
2462
|
+
});
|
2463
|
+
}
|
2464
|
+
});
|
2465
|
+
return success;
|
2466
|
+
},
|
2467
|
+
setRowData : function(rowid, data, cssp) {
|
2468
|
+
var nm, success=true, title;
|
2469
|
+
this.each(function(){
|
2470
|
+
if(!this.grid) {return false;}
|
2471
|
+
var t = this, vl, ind, cp = typeof cssp, lcdata={};
|
2472
|
+
ind = t.rows.namedItem(rowid);
|
2473
|
+
if(!ind) { return false; }
|
2474
|
+
if( data ) {
|
2475
|
+
try {
|
2476
|
+
$(this.p.colModel).each(function(i){
|
2477
|
+
nm = this.name;
|
2478
|
+
if( data[nm] !== undefined) {
|
2479
|
+
// @TODO we must handle propertly the formatter date
|
2480
|
+
lcdata[nm] = this.formatter && typeof(this.formatter) === 'string' && this.formatter == 'date' ? $.unformat.date(data[nm],this) : data[nm];
|
2481
|
+
vl = t.formatter( rowid, data[nm], i, data, 'edit');
|
2482
|
+
title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
|
2483
|
+
if(t.p.treeGrid===true && nm == t.p.ExpandColumn) {
|
2484
|
+
$("td:eq("+i+") > span:first",ind).html(vl).attr(title);
|
2485
|
+
} else {
|
2486
|
+
$("td:eq("+i+")",ind).html(vl).attr(title);
|
2487
|
+
}
|
2488
|
+
}
|
2489
|
+
});
|
2490
|
+
if(t.p.datatype == 'local') {
|
2491
|
+
var pos;
|
2492
|
+
pos = t.p._index[rowid];
|
2493
|
+
if(typeof(pos) != 'undefined') {
|
2494
|
+
t.p.data[pos] = $.extend(true, t.p.data[pos], lcdata);
|
2495
|
+
}
|
2496
|
+
lcdata = null;
|
2497
|
+
}
|
2498
|
+
} catch (e) {
|
2499
|
+
success = false;
|
2500
|
+
}
|
2501
|
+
}
|
2502
|
+
if(success) {
|
2503
|
+
if(cp === 'string') {$(ind).addClass(cssp);} else if(cp === 'object') {$(ind).css(cssp);}
|
2504
|
+
}
|
2505
|
+
});
|
2506
|
+
return success;
|
2507
|
+
},
|
2508
|
+
addRowData : function(rowid,rdata,pos,src) {
|
2509
|
+
if(!pos) {pos = "last";}
|
2510
|
+
var success = false, nm, row, gi, si, ni,sind, i, v, prp="", aradd, cnm, cn, data, cm;
|
2511
|
+
if(rdata) {
|
2512
|
+
if($.isArray(rdata)) {
|
2513
|
+
aradd=true;
|
2514
|
+
pos = "last";
|
2515
|
+
cnm = rowid;
|
2516
|
+
} else {
|
2517
|
+
rdata = [rdata];
|
2518
|
+
aradd = false;
|
2519
|
+
}
|
2520
|
+
this.each(function() {
|
2521
|
+
var t = this, datalen = rdata.length;
|
2522
|
+
ni = t.p.rownumbers===true ? 1 :0;
|
2523
|
+
gi = t.p.multiselect ===true ? 1 :0;
|
2524
|
+
si = t.p.subGrid===true ? 1 :0;
|
2525
|
+
if(!aradd) {
|
2526
|
+
if(typeof(rowid) != 'undefined') { rowid = rowid+"";}
|
2527
|
+
else {
|
2528
|
+
rowid = (t.p.records+1)+"";
|
2529
|
+
if(t.p.keyIndex !== false) {
|
2530
|
+
cnm = t.p.colModel[t.p.keyIndex+gi+si+ni].name;
|
2531
|
+
if(typeof rdata[0][cnm] != "undefined") { rowid = rdata[0][cnm]; }
|
2532
|
+
}
|
2533
|
+
}
|
2534
|
+
}
|
2535
|
+
cn = t.p.altclass;
|
2536
|
+
var k = 0, cna ="", lcdata = {},
|
2537
|
+
air = $.isFunction(t.p.afterInsertRow) ? true : false;
|
2538
|
+
while(k < datalen) {
|
2539
|
+
data = rdata[k];
|
2540
|
+
row="";
|
2541
|
+
if(aradd) {
|
2542
|
+
try {rowid = data[cnm];}
|
2543
|
+
catch (e) {rowid = (t.p.records+1)+"";}
|
2544
|
+
cna = t.p.altRows === true ? (t.rows.length-1)%2 === 0 ? cn : "" : "";
|
2545
|
+
}
|
2546
|
+
if(ni){
|
2547
|
+
prp = t.formatCol(0,1,'');
|
2548
|
+
row += "<td role=\"gridcell\" aria-describedby=\""+t.p.id+"_rn\" class=\"ui-state-default jqgrid-rownum\" "+prp+">0</td>";
|
2549
|
+
}
|
2550
|
+
if(gi) {
|
2551
|
+
v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+rowid+"\" class=\"cbox\"/>";
|
2552
|
+
prp = t.formatCol(ni,1,'');
|
2553
|
+
row += "<td role=\"gridcell\" aria-describedby=\""+t.p.id+"_cb\" "+prp+">"+v+"</td>";
|
2554
|
+
}
|
2555
|
+
if(si) {
|
2556
|
+
row += $(t).jqGrid("addSubGridCell",gi+ni,1);
|
2557
|
+
}
|
2558
|
+
for(i = gi+si+ni; i < t.p.colModel.length;i++){
|
2559
|
+
cm = t.p.colModel[i];
|
2560
|
+
nm = cm.name;
|
2561
|
+
lcdata[nm] = cm.formatter && typeof(cm.formatter) === 'string' && cm.formatter == 'date' ? $.unformat.date(data[nm],cm) : data[nm];
|
2562
|
+
v = t.formatter( rowid, data[nm], i, data, 'edit');
|
2563
|
+
prp = t.formatCol(i,1,v);
|
2564
|
+
row += "<td role=\"gridcell\" aria-describedby=\""+t.p.id+"_"+nm+"\" "+prp+">"+v+"</td>";
|
2565
|
+
}
|
2566
|
+
row = "<tr id=\""+rowid+"\" role=\"row\" class=\"ui-widget-content jqgrow ui-row-"+t.p.direction+" "+cna+"\">" + row+"</tr>";
|
2567
|
+
if(t.p.subGrid===true) {
|
2568
|
+
row = $(row)[0];
|
2569
|
+
$(t).jqGrid("addSubGrid",row,gi+ni);
|
2570
|
+
}
|
2571
|
+
if(t.rows.length === 0){
|
2572
|
+
$("table:first",t.grid.bDiv).append(row);
|
2573
|
+
} else {
|
2574
|
+
switch (pos) {
|
2575
|
+
case 'last':
|
2576
|
+
$(t.rows[t.rows.length-1]).after(row);
|
2577
|
+
break;
|
2578
|
+
case 'first':
|
2579
|
+
$(t.rows[0]).before(row);
|
2580
|
+
break;
|
2581
|
+
case 'after':
|
2582
|
+
sind = t.rows.namedItem(src);
|
2583
|
+
if (sind) {
|
2584
|
+
if($(t.rows[sind.rowIndex+1]).hasClass("ui-subgrid")) { $(t.rows[sind.rowIndex+1]).after(row); }
|
2585
|
+
else { $(sind).after(row); }
|
2586
|
+
}
|
2587
|
+
break;
|
2588
|
+
case 'before':
|
2589
|
+
sind = t.rows.namedItem(src);
|
2590
|
+
if(sind) {$(sind).before(row);sind=sind.rowIndex;}
|
2591
|
+
break;
|
2592
|
+
}
|
2593
|
+
}
|
2594
|
+
t.p.records++;
|
2595
|
+
t.p.reccount++;
|
2596
|
+
if(!t.grid.cols || !t.grid.cols.length) { t.grid.cols = t.rows[0].cells; }
|
2597
|
+
if(pos==='first' || (pos==='before' && sind <= 1) || t.rows.length === 1 ){
|
2598
|
+
t.updateColumns();
|
2599
|
+
}
|
2600
|
+
if(air) { t.p.afterInsertRow.call(t,rowid,data,data); }
|
2601
|
+
k++;
|
2602
|
+
if(t.p.datatype == 'local') {
|
2603
|
+
t.p._index[rowid] = t.p.data.length;
|
2604
|
+
t.p.data.push(lcdata);
|
2605
|
+
lcdata = {};
|
2606
|
+
}
|
2607
|
+
}
|
2608
|
+
if( t.p.altRows === true && !aradd) {
|
2609
|
+
if (pos == "last") {
|
2610
|
+
if ((t.rows.length-1)%2 == 1) {$(t.rows[t.rows.length-1]).addClass(cn);}
|
2611
|
+
} else {
|
2612
|
+
$(t.rows).each(function(i){
|
2613
|
+
if(i % 2 ==1) { $(this).addClass(cn); }
|
2614
|
+
else { $(this).removeClass(cn); }
|
2615
|
+
});
|
2616
|
+
}
|
2617
|
+
}
|
2618
|
+
t.updatepager(true,true);
|
2619
|
+
success = true;
|
2620
|
+
});
|
2621
|
+
}
|
2622
|
+
return success;
|
2623
|
+
},
|
2624
|
+
footerData : function(action,data, format) {
|
2625
|
+
var nm, success=false, res={}, title;
|
2626
|
+
function isEmpty(obj) {
|
2627
|
+
for(var i in obj) {
|
2628
|
+
if (obj.hasOwnProperty(i)) { return false; }
|
2629
|
+
}
|
2630
|
+
return true;
|
2631
|
+
}
|
2632
|
+
if(typeof(action) == "undefined") { action = "get"; }
|
2633
|
+
if(typeof(format) != "boolean") { format = true; }
|
2634
|
+
action = action.toLowerCase();
|
2635
|
+
this.each(function(){
|
2636
|
+
var t = this, vl;
|
2637
|
+
if(!t.grid || !t.p.footerrow) {return false;}
|
2638
|
+
if(action == "set") { if(isEmpty(data)) { return false; } }
|
2639
|
+
success=true;
|
2640
|
+
$(this.p.colModel).each(function(i){
|
2641
|
+
nm = this.name;
|
2642
|
+
if(action == "set") {
|
2643
|
+
if( data[nm] !== undefined) {
|
2644
|
+
vl = format ? t.formatter( "", data[nm], i, data, 'edit') : data[nm];
|
2645
|
+
title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
|
2646
|
+
$("tr.footrow td:eq("+i+")",t.grid.sDiv).html(vl).attr(title);
|
2647
|
+
success = true;
|
2648
|
+
}
|
2649
|
+
} else if(action == "get") {
|
2650
|
+
res[nm] = $("tr.footrow td:eq("+i+")",t.grid.sDiv).html();
|
2651
|
+
}
|
2652
|
+
});
|
2653
|
+
});
|
2654
|
+
return action == "get" ? res : success;
|
2655
|
+
},
|
2656
|
+
ShowHideCol : function(colname,show) {
|
2657
|
+
return this.each(function() {
|
2658
|
+
var $t = this, fndh=false;
|
2659
|
+
if (!$t.grid ) {return;}
|
2660
|
+
if( typeof colname === 'string') {colname=[colname];}
|
2661
|
+
show = show !="none" ? "" : "none";
|
2662
|
+
var sw = show == "" ? true :false;
|
2663
|
+
$(this.p.colModel).each(function(i) {
|
2664
|
+
if ($.inArray(this.name,colname) !== -1 && this.hidden === sw) {
|
2665
|
+
$("tr",$t.grid.hDiv).each(function(){
|
2666
|
+
$("th:eq("+i+")",this).css("display",show);
|
2667
|
+
});
|
2668
|
+
$($t.rows).each(function(j){
|
2669
|
+
$("td:eq("+i+")",$t.rows[j]).css("display",show);
|
2670
|
+
});
|
2671
|
+
if($t.p.footerrow) { $("td:eq("+i+")",$t.grid.sDiv).css("display", show); }
|
2672
|
+
if(show == "none") { $t.p.tblwidth -= this.width;} else {$t.p.tblwidth += this.width;}
|
2673
|
+
this.hidden = !sw;
|
2674
|
+
fndh=true;
|
2675
|
+
}
|
2676
|
+
});
|
2677
|
+
if(fndh===true) {
|
2678
|
+
$("table:first",$t.grid.hDiv).width($t.p.tblwidth);
|
2679
|
+
$("table:first",$t.grid.bDiv).width($t.p.tblwidth);
|
2680
|
+
$t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft;
|
2681
|
+
if($t.p.footerrow) {
|
2682
|
+
$("table:first",$t.grid.sDiv).width($t.p.tblwidth);
|
2683
|
+
$t.grid.sDiv.scrollLeft = $t.grid.bDiv.scrollLeft;
|
2684
|
+
}
|
2685
|
+
}
|
2686
|
+
});
|
2687
|
+
},
|
2688
|
+
hideCol : function (colname) {
|
2689
|
+
return this.each(function(){$(this).jqGrid("ShowHideCol",colname,"none");});
|
2690
|
+
},
|
2691
|
+
showCol : function(colname) {
|
2692
|
+
return this.each(function(){$(this).jqGrid("ShowHideCol",colname,"");});
|
2693
|
+
},
|
2694
|
+
remapColumns : function(permutation, updateCells, keepHeader)
|
2695
|
+
{
|
2696
|
+
function resortArray(a) {
|
2697
|
+
var ac;
|
2698
|
+
if (a.length) {
|
2699
|
+
ac = $.makeArray(a);
|
2700
|
+
} else {
|
2701
|
+
ac = $.extend({}, a);
|
2702
|
+
}
|
2703
|
+
$.each(permutation, function(i) {
|
2704
|
+
a[i] = ac[this];
|
2705
|
+
});
|
2706
|
+
}
|
2707
|
+
var ts = this.get(0);
|
2708
|
+
function resortRows(parent, clobj) {
|
2709
|
+
$(">tr"+(clobj||""), parent).each(function() {
|
2710
|
+
var row = this;
|
2711
|
+
var elems = $.makeArray(row.cells);
|
2712
|
+
$.each(permutation, function() {
|
2713
|
+
var e = elems[this];
|
2714
|
+
if (e) {
|
2715
|
+
row.appendChild(e);
|
2716
|
+
}
|
2717
|
+
});
|
2718
|
+
});
|
2719
|
+
}
|
2720
|
+
resortArray(ts.p.colModel);
|
2721
|
+
resortArray(ts.p.colNames);
|
2722
|
+
resortArray(ts.grid.headers);
|
2723
|
+
resortRows($("thead:first", ts.grid.hDiv), keepHeader && ":not(.ui-jqgrid-labels)");
|
2724
|
+
if (updateCells) {
|
2725
|
+
resortRows($("tbody:first", ts.grid.bDiv), ".jqgrow");
|
2726
|
+
}
|
2727
|
+
if (ts.p.footerrow) {
|
2728
|
+
resortRows($("tbody:first", ts.grid.sDiv));
|
2729
|
+
}
|
2730
|
+
if (ts.p.remapColumns) {
|
2731
|
+
if (!ts.p.remapColumns.length){
|
2732
|
+
ts.p.remapColumns = $.makeArray(permutation);
|
2733
|
+
} else {
|
2734
|
+
resortArray(ts.p.remapColumns);
|
2735
|
+
}
|
2736
|
+
}
|
2737
|
+
ts.p.lastsort = $.inArray(ts.p.lastsort, permutation);
|
2738
|
+
if(ts.p.treeGrid) { ts.p.expColInd = $.inArray(ts.p.expColInd, permutation); }
|
2739
|
+
},
|
2740
|
+
setGridWidth : function(nwidth, shrink) {
|
2741
|
+
return this.each(function(){
|
2742
|
+
if (!this.grid ) {return;}
|
2743
|
+
var $t = this, cw,
|
2744
|
+
initwidth = 0, brd=$t.p.cellLayout, lvc, vc=0, hs=false, scw=$t.p.scrollOffset, aw, gw=0, tw=0,
|
2745
|
+
cl = 0,cr;
|
2746
|
+
if(typeof shrink != 'boolean') {
|
2747
|
+
shrink=$t.p.shrinkToFit;
|
2748
|
+
}
|
2749
|
+
if(isNaN(nwidth)) {return;}
|
2750
|
+
else { nwidth = parseInt(nwidth,10); $t.grid.width = $t.p.width = nwidth;}
|
2751
|
+
$("#gbox_"+$t.p.id).css("width",nwidth+"px");
|
2752
|
+
$("#gview_"+$t.p.id).css("width",nwidth+"px");
|
2753
|
+
$($t.grid.bDiv).css("width",nwidth+"px");
|
2754
|
+
$($t.grid.hDiv).css("width",nwidth+"px");
|
2755
|
+
if($t.p.pager ) {$($t.p.pager).css("width",nwidth+"px");}
|
2756
|
+
if($t.p.toppager ) {$($t.p.toppager).css("width",nwidth+"px");}
|
2757
|
+
if($t.p.toolbar[0] === true){
|
2758
|
+
$($t.grid.uDiv).css("width",nwidth+"px");
|
2759
|
+
if($t.p.toolbar[1]=="both") {$($t.grid.ubDiv).css("width",nwidth+"px");}
|
2760
|
+
}
|
2761
|
+
if($t.p.footerrow) { $($t.grid.sDiv).css("width",nwidth+"px"); }
|
2762
|
+
if(shrink ===false && $t.p.forceFit === true) {$t.p.forceFit=false;}
|
2763
|
+
if(shrink===true) {
|
2764
|
+
if ($.browser.safari) { brd=0;}
|
2765
|
+
$.each($t.p.colModel, function(i) {
|
2766
|
+
if(this.hidden===false){
|
2767
|
+
initwidth += parseInt(this.width,10);
|
2768
|
+
if(this.fixed) {
|
2769
|
+
tw += this.width;
|
2770
|
+
gw += this.width+brd;
|
2771
|
+
} else {
|
2772
|
+
vc++;
|
2773
|
+
}
|
2774
|
+
cl++;
|
2775
|
+
}
|
2776
|
+
});
|
2777
|
+
if(vc === 0) { return; }
|
2778
|
+
$t.p.tblwidth = initwidth;
|
2779
|
+
aw = nwidth-brd*vc-gw;
|
2780
|
+
if(!isNaN($t.p.height)) {
|
2781
|
+
if($($t.grid.bDiv)[0].clientHeight < $($t.grid.bDiv)[0].scrollHeight){
|
2782
|
+
hs = true;
|
2783
|
+
aw -= scw;
|
2784
|
+
}
|
2785
|
+
}
|
2786
|
+
initwidth =0;
|
2787
|
+
var cle = $t.grid.cols.length >0;
|
2788
|
+
$.each($t.p.colModel, function(i) {
|
2789
|
+
if(this.hidden === false && !this.fixed){
|
2790
|
+
cw = Math.round(aw*this.width/($t.p.tblwidth-tw));
|
2791
|
+
if (cw < 0) { return; }
|
2792
|
+
this.width =cw;
|
2793
|
+
initwidth += cw;
|
2794
|
+
$t.grid.headers[i].width=cw;
|
2795
|
+
$t.grid.headers[i].el.style.width=cw+"px";
|
2796
|
+
if($t.p.footerrow) { $t.grid.footers[i].style.width = cw+"px"; }
|
2797
|
+
if(cle) { $t.grid.cols[i].style.width = cw+"px"; }
|
2798
|
+
lvc = i;
|
2799
|
+
}
|
2800
|
+
});
|
2801
|
+
cr =0;
|
2802
|
+
if (hs) {
|
2803
|
+
if(nwidth-gw-(initwidth+brd*vc) !== scw){
|
2804
|
+
cr = nwidth-gw-(initwidth+brd*vc)-scw;
|
2805
|
+
}
|
2806
|
+
} else if( Math.abs(nwidth-gw-(initwidth+brd*vc)) !== 1) {
|
2807
|
+
cr = nwidth-gw-(initwidth+brd*vc);
|
2808
|
+
}
|
2809
|
+
$t.p.colModel[lvc].width += cr;
|
2810
|
+
$t.p.tblwidth = initwidth+cr+tw+brd*cl;
|
2811
|
+
if($t.p.tblwidth > nwidth) {
|
2812
|
+
var delta = $t.p.tblwidth - parseInt(nwidth,10);
|
2813
|
+
$t.p.tblwidth = nwidth;
|
2814
|
+
cw = $t.p.colModel[lvc].width = $t.p.colModel[lvc].width-delta;
|
2815
|
+
} else {
|
2816
|
+
cw= $t.p.colModel[lvc].width;
|
2817
|
+
}
|
2818
|
+
$t.grid.headers[lvc].width = cw;
|
2819
|
+
$t.grid.headers[lvc].el.style.width=cw+"px";
|
2820
|
+
if(cle) { $t.grid.cols[lvc].style.width = cw+"px"; }
|
2821
|
+
$('table:first',$t.grid.bDiv).css("width",$t.p.tblwidth+"px");
|
2822
|
+
$('table:first',$t.grid.hDiv).css("width",$t.p.tblwidth+"px");
|
2823
|
+
$t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft;
|
2824
|
+
if($t.p.footerrow) {
|
2825
|
+
$t.grid.footers[lvc].style.width = cw+"px";
|
2826
|
+
$('table:first',$t.grid.sDiv).css("width",$t.p.tblwidth+"px");
|
2827
|
+
}
|
2828
|
+
}
|
2829
|
+
});
|
2830
|
+
},
|
2831
|
+
setGridHeight : function (nh) {
|
2832
|
+
return this.each(function (){
|
2833
|
+
var $t = this;
|
2834
|
+
if(!$t.grid) {return;}
|
2835
|
+
$($t.grid.bDiv).css({height: nh+(isNaN(nh)?"":"px")});
|
2836
|
+
$t.p.height = nh;
|
2837
|
+
if ($t.p.scroll) { $t.grid.populateVisible(); }
|
2838
|
+
});
|
2839
|
+
},
|
2840
|
+
setCaption : function (newcap){
|
2841
|
+
return this.each(function(){
|
2842
|
+
this.p.caption=newcap;
|
2843
|
+
$("span.ui-jqgrid-title",this.grid.cDiv).html(newcap);
|
2844
|
+
$(this.grid.cDiv).show();
|
2845
|
+
});
|
2846
|
+
},
|
2847
|
+
setLabel : function(colname, nData, prop, attrp ){
|
2848
|
+
return this.each(function(){
|
2849
|
+
var $t = this, pos=-1;
|
2850
|
+
if(!$t.grid) {return;}
|
2851
|
+
if(isNaN(colname)) {
|
2852
|
+
$($t.p.colModel).each(function(i){
|
2853
|
+
if (this.name == colname) {
|
2854
|
+
pos = i;return false;
|
2855
|
+
}
|
2856
|
+
});
|
2857
|
+
} else {pos = parseInt(colname,10);}
|
2858
|
+
if(pos>=0) {
|
2859
|
+
var thecol = $("tr.ui-jqgrid-labels th:eq("+pos+")",$t.grid.hDiv);
|
2860
|
+
if (nData){
|
2861
|
+
var ico = $(".s-ico",thecol);
|
2862
|
+
$("[id^=jqgh_]",thecol).empty().html(nData).append(ico);
|
2863
|
+
$t.p.colNames[pos] = nData;
|
2864
|
+
}
|
2865
|
+
if (prop) {
|
2866
|
+
if(typeof prop === 'string') {$(thecol).addClass(prop);} else {$(thecol).css(prop);}
|
2867
|
+
}
|
2868
|
+
if(typeof attrp === 'object') {$(thecol).attr(attrp);}
|
2869
|
+
}
|
2870
|
+
});
|
2871
|
+
},
|
2872
|
+
setCell : function(rowid,colname,nData,cssp,attrp, forceupd) {
|
2873
|
+
return this.each(function(){
|
2874
|
+
var $t = this, pos =-1,v, title;
|
2875
|
+
if(!$t.grid) {return;}
|
2876
|
+
if(isNaN(colname)) {
|
2877
|
+
$($t.p.colModel).each(function(i){
|
2878
|
+
if (this.name == colname) {
|
2879
|
+
pos = i;return false;
|
2880
|
+
}
|
2881
|
+
});
|
2882
|
+
} else {pos = parseInt(colname,10);}
|
2883
|
+
if(pos>=0) {
|
2884
|
+
var ind = $t.rows.namedItem(rowid);
|
2885
|
+
if (ind){
|
2886
|
+
var tcell = $("td:eq("+pos+")",ind);
|
2887
|
+
if(nData !== "" || forceupd === true) {
|
2888
|
+
v = $t.formatter(rowid, nData, pos,ind,'edit');
|
2889
|
+
title = $t.p.colModel[pos].title ? {"title":$.jgrid.stripHtml(v)} : {};
|
2890
|
+
if($t.p.treeGrid && $(".tree-wrap",$(tcell)).length>0) {
|
2891
|
+
$("span",$(tcell)).html(v).attr(title);
|
2892
|
+
} else {
|
2893
|
+
$(tcell).html(v).attr(title);
|
2894
|
+
}
|
2895
|
+
if($t.p.datatype == "local") {
|
2896
|
+
var cm = $t.p.colModel[pos], index;
|
2897
|
+
nData = cm.formatter && typeof(cm.formatter) === 'string' && cm.formatter == 'date' ? $.unformat.date(nData,cm) : nData;
|
2898
|
+
index = $t.p._index[rowid];
|
2899
|
+
if(parseInt(index,10) >= 0 ) {
|
2900
|
+
$t.p.data[index][cm.name] = nData;
|
2901
|
+
}
|
2902
|
+
}
|
2903
|
+
}
|
2904
|
+
if(typeof cssp === 'string'){
|
2905
|
+
$(tcell).addClass(cssp);
|
2906
|
+
} else if(cssp) {
|
2907
|
+
$(tcell).css(cssp);
|
2908
|
+
}
|
2909
|
+
if(typeof attrp === 'object') {$(tcell).attr(attrp);}
|
2910
|
+
}
|
2911
|
+
}
|
2912
|
+
});
|
2913
|
+
},
|
2914
|
+
getCell : function(rowid,col) {
|
2915
|
+
var ret = false;
|
2916
|
+
this.each(function(){
|
2917
|
+
var $t=this, pos=-1;
|
2918
|
+
if(!$t.grid) {return;}
|
2919
|
+
if(isNaN(col)) {
|
2920
|
+
$($t.p.colModel).each(function(i){
|
2921
|
+
if (this.name === col) {
|
2922
|
+
pos = i;return false;
|
2923
|
+
}
|
2924
|
+
});
|
2925
|
+
} else {pos = parseInt(col,10);}
|
2926
|
+
if(pos>=0) {
|
2927
|
+
var ind = $t.rows.namedItem(rowid);
|
2928
|
+
if(ind) {
|
2929
|
+
try {
|
2930
|
+
ret = $.unformat($("td:eq("+pos+")",ind),{rowId:ind.id, colModel:$t.p.colModel[pos]},pos);
|
2931
|
+
} catch (e){
|
2932
|
+
ret = $.jgrid.htmlDecode($("td:eq("+pos+")",ind).html());
|
2933
|
+
}
|
2934
|
+
}
|
2935
|
+
}
|
2936
|
+
});
|
2937
|
+
return ret;
|
2938
|
+
},
|
2939
|
+
getCol : function (col, obj, mathopr) {
|
2940
|
+
var ret = [], val, sum=0;
|
2941
|
+
obj = typeof (obj) != 'boolean' ? false : obj;
|
2942
|
+
if(typeof mathopr == 'undefined') { mathopr = false; }
|
2943
|
+
this.each(function(){
|
2944
|
+
var $t=this, pos=-1;
|
2945
|
+
if(!$t.grid) {return;}
|
2946
|
+
if(isNaN(col)) {
|
2947
|
+
$($t.p.colModel).each(function(i){
|
2948
|
+
if (this.name === col) {
|
2949
|
+
pos = i;return false;
|
2950
|
+
}
|
2951
|
+
});
|
2952
|
+
} else {pos = parseInt(col,10);}
|
2953
|
+
if(pos>=0) {
|
2954
|
+
var ln = $t.rows.length, i =0;
|
2955
|
+
if (ln && ln>0){
|
2956
|
+
while(i<ln){
|
2957
|
+
try {
|
2958
|
+
val = $.unformat($($t.rows[i].cells[pos]),{rowId:$t.rows[i].id, colModel:$t.p.colModel[pos]},pos);
|
2959
|
+
} catch (e) {
|
2960
|
+
val = $.jgrid.htmlDecode($t.rows[i].cells[pos].innerHTML);
|
2961
|
+
}
|
2962
|
+
if(mathopr) { sum += parseFloat(val); }
|
2963
|
+
else if(obj) { ret.push({id:$t.rows[i].id,value:val}); }
|
2964
|
+
else { ret[i]=val; }
|
2965
|
+
i++;
|
2966
|
+
}
|
2967
|
+
if(mathopr) {
|
2968
|
+
switch(mathopr.toLowerCase()){
|
2969
|
+
case 'sum': ret =sum; break;
|
2970
|
+
case 'avg': ret = sum/ln; break;
|
2971
|
+
case 'count': ret = ln; break;
|
2972
|
+
}
|
2973
|
+
}
|
2974
|
+
}
|
2975
|
+
}
|
2976
|
+
});
|
2977
|
+
return ret;
|
2978
|
+
},
|
2979
|
+
clearGridData : function(clearfooter) {
|
2980
|
+
return this.each(function(){
|
2981
|
+
var $t = this;
|
2982
|
+
if(!$t.grid) {return;}
|
2983
|
+
if(typeof clearfooter != 'boolean') { clearfooter = false; }
|
2984
|
+
$("tbody:first tr", $t.grid.bDiv).remove();
|
2985
|
+
if($t.p.footerrow && clearfooter) { $(".ui-jqgrid-ftable td",$t.grid.sDiv).html(" "); }
|
2986
|
+
$t.p.selrow = null; $t.p.selarrrow= []; $t.p.savedRow = [];
|
2987
|
+
$t.p.records = 0;$t.p.page='0';$t.p.lastpage='0';$t.p.reccount=0;
|
2988
|
+
$t.p.data = []; $t.p_index = {};
|
2989
|
+
$t.updatepager(true,false);
|
2990
|
+
});
|
2991
|
+
},
|
2992
|
+
getInd : function(rowid,rc){
|
2993
|
+
var ret =false,rw;
|
2994
|
+
this.each(function(){
|
2995
|
+
rw = this.rows.namedItem(rowid);
|
2996
|
+
if(rw) {
|
2997
|
+
ret = rc===true ? rw: rw.rowIndex;
|
2998
|
+
}
|
2999
|
+
});
|
3000
|
+
return ret;
|
3001
|
+
}
|
3002
|
+
});
|
3003
|
+
})(jQuery);
|