PageRenderTime 75ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/JqGridMvc/JqGridMvc/Scripts/js/jquery.jqGrid.src.js

#
JavaScript | 11317 lines | 7874 code | 28 blank | 3415 comment | 311 complexity | 22eb8dd1f96cb897f38797c15444ff71 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. // ==ClosureCompiler==
  2. // @compilation_level SIMPLE_OPTIMIZATIONS
  3. /**
  4. * @license jqGrid 4.2.0 - jQuery Grid
  5. * Copyright (c) 2008, Tony Tomov, tony@trirand.com
  6. * Dual licensed under the MIT and GPL licenses
  7. * http://www.opensource.org/licenses/mit-license.php
  8. * http://www.gnu.org/licenses/gpl-2.0.html
  9. * Date: 2011-10-11
  10. */
  11. //jsHint options
  12. /*global document, window, jQuery, DOMParser, ActiveXObject $ */
  13. (function ($) {
  14. $.jgrid = $.jgrid || {};
  15. $.extend($.jgrid,{
  16. htmlDecode : function(value){
  17. if(value && (value==' ' || value==' ' || (value.length==1 && value.charCodeAt(0)==160))) { return "";}
  18. return !value ? value : String(value).replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"').replace(/&amp;/g, "&");
  19. },
  20. htmlEncode : function (value){
  21. return !value ? value : String(value).replace(/&/g, "&amp;").replace(/\"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  22. },
  23. format : function(format){ //jqgformat
  24. var args = $.makeArray(arguments).slice(1);
  25. if(format===undefined) { format = ""; }
  26. return format.replace(/\{(\d+)\}/g, function(m, i){
  27. return args[i];
  28. });
  29. },
  30. getCellIndex : function (cell) {
  31. var c = $(cell);
  32. if (c.is('tr')) { return -1; }
  33. c = (!c.is('td') && !c.is('th') ? c.closest("td,th") : c)[0];
  34. if ($.browser.msie) { return $.inArray(c, c.parentNode.cells); }
  35. return c.cellIndex;
  36. },
  37. stripHtml : function(v) {
  38. v = v+"";
  39. var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
  40. if (v) {
  41. v = v.replace(regexp,"");
  42. return (v && v !== '&nbsp;' && v !== '&#160;') ? v.replace(/\"/g,"'") : "";
  43. } else {
  44. return v;
  45. }
  46. },
  47. stripPref : function (pref, id) {
  48. var obj = Object.prototype.toString.call(pref).slice(8, -1);
  49. if( obj == "String" || obj =="Number") {
  50. pref = String(pref);
  51. id = pref != "" ? String(id).replace(String(pref), "") : id;
  52. }
  53. return id;
  54. },
  55. stringToDoc : function (xmlString) {
  56. var xmlDoc;
  57. if(typeof xmlString !== 'string') { return xmlString; }
  58. try {
  59. var parser = new DOMParser();
  60. xmlDoc = parser.parseFromString(xmlString,"text/xml");
  61. }
  62. catch(e) {
  63. xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  64. xmlDoc.async=false;
  65. xmlDoc.loadXML(xmlString);
  66. }
  67. return (xmlDoc && xmlDoc.documentElement && xmlDoc.documentElement.tagName != 'parsererror') ? xmlDoc : null;
  68. },
  69. parse : function(jsonString) {
  70. var js = jsonString;
  71. if (js.substr(0,9) == "while(1);") { js = js.substr(9); }
  72. if (js.substr(0,2) == "/*") { js = js.substr(2,js.length-4); }
  73. if(!js) { js = "{}"; }
  74. return ($.jgrid.useJSON===true && typeof (JSON) === 'object' && typeof (JSON.parse) === 'function') ?
  75. JSON.parse(js) :
  76. eval('(' + js + ')');
  77. },
  78. parseDate : function(format, date) {
  79. var tsp = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0},k,hl,dM, regdate = /[\\\/:_;.,\t\T\s-]/;
  80. if(date && date !== null && date !== undefined){
  81. date = $.trim(date);
  82. date = date.split(regdate);
  83. format = format.split(regdate);
  84. var dfmt = $.jgrid.formatter.date.monthNames;
  85. var afmt = $.jgrid.formatter.date.AmPm;
  86. var h12to24 = function(ampm, h){
  87. if (ampm === 0){ if (h == 12) { h = 0;} }
  88. else { if (h != 12) { h += 12; } }
  89. return h;
  90. };
  91. for(k=0,hl=format.length;k<hl;k++){
  92. if(format[k] == 'M') {
  93. dM = $.inArray(date[k],dfmt);
  94. if(dM !== -1 && dM < 12){date[k] = dM+1;}
  95. }
  96. if(format[k] == 'F') {
  97. dM = $.inArray(date[k],dfmt);
  98. if(dM !== -1 && dM > 11){date[k] = dM+1-12;}
  99. }
  100. if(format[k] == 'a') {
  101. dM = $.inArray(date[k],afmt);
  102. if(dM !== -1 && dM < 2 && date[k] == afmt[dM]){
  103. date[k] = dM;
  104. tsp.h = h12to24(date[k], tsp.h);
  105. }
  106. }
  107. if(format[k] == 'A') {
  108. dM = $.inArray(date[k],afmt);
  109. if(dM !== -1 && dM > 1 && date[k] == afmt[dM]){
  110. date[k] = dM-2;
  111. tsp.h = h12to24(date[k], tsp.h);
  112. }
  113. }
  114. if(date[k] !== undefined) {
  115. tsp[format[k].toLowerCase()] = parseInt(date[k],10);
  116. }
  117. }
  118. tsp.m = parseInt(tsp.m,10)-1;
  119. var ty = tsp.y;
  120. if (ty >= 70 && ty <= 99) {tsp.y = 1900+tsp.y;}
  121. else if (ty >=0 && ty <=69) {tsp.y= 2000+tsp.y;}
  122. }
  123. return new Date(tsp.y, tsp.m, tsp.d, tsp.h, tsp.i, tsp.s,0);
  124. },
  125. jqID : function(sid){
  126. return String(sid).replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g,"\\$&");
  127. },
  128. guid : 1,
  129. uidPref: 'jqg',
  130. randId : function( prefix ) {
  131. return (prefix? prefix: $.jgrid.uidPref) + ($.jgrid.guid++);
  132. },
  133. getAccessor : function(obj, expr) {
  134. var ret,p,prm = [], i;
  135. if( typeof expr === 'function') { return expr(obj); }
  136. ret = obj[expr];
  137. if(ret===undefined) {
  138. try {
  139. if ( typeof expr === 'string' ) {
  140. prm = expr.split('.');
  141. }
  142. i = prm.length;
  143. if( i ) {
  144. ret = obj;
  145. while (ret && i--) {
  146. p = prm.shift();
  147. ret = ret[p];
  148. }
  149. }
  150. } catch (e) {}
  151. }
  152. return ret;
  153. },
  154. ajaxOptions: {},
  155. from : function(source,initalQuery){
  156. // Original Author Hugo Bonacci
  157. // License MIT http://jlinq.codeplex.com/license
  158. var queryObject=function(d,q){
  159. if(typeof(d)=="string"){
  160. d=$.data(d);
  161. }
  162. var self=this,
  163. _data=d,
  164. _usecase=true,
  165. _trim=false,
  166. _query=q,
  167. _stripNum = /[\$,%]/g,
  168. _lastCommand=null,
  169. _lastField=null,
  170. _orDepth=0,
  171. _negate=false,
  172. _queuedOperator="",
  173. _sorting=[],
  174. _useProperties=true;
  175. if(typeof(d)=="object"&&d.push) {
  176. if(d.length>0){
  177. if(typeof(d[0])!="object"){
  178. _useProperties=false;
  179. }else{
  180. _useProperties=true;
  181. }
  182. }
  183. }else{
  184. throw "data provides is not an array";
  185. }
  186. this._hasData=function(){
  187. return _data===null?false:_data.length===0?false:true;
  188. };
  189. this._getStr=function(s){
  190. var phrase=[];
  191. if(_trim){
  192. phrase.push("jQuery.trim(");
  193. }
  194. phrase.push("String("+s+")");
  195. if(_trim){
  196. phrase.push(")");
  197. }
  198. if(!_usecase){
  199. phrase.push(".toLowerCase()");
  200. }
  201. return phrase.join("");
  202. };
  203. this._strComp=function(val){
  204. if(typeof(val)=="string"){
  205. return".toString()";
  206. }else{
  207. return"";
  208. }
  209. };
  210. this._group=function(f,u){
  211. return({field:f.toString(),unique:u,items:[]});
  212. };
  213. this._toStr=function(phrase){
  214. if(_trim){
  215. phrase=$.trim(phrase);
  216. }
  217. if(!_usecase){
  218. phrase=phrase.toLowerCase();
  219. }
  220. phrase=phrase.toString().replace(/\\/g,'\\\\').replace(/\"/g,'\\"');
  221. return phrase;
  222. };
  223. this._funcLoop=function(func){
  224. var results=[];
  225. $.each(_data,function(i,v){
  226. results.push(func(v));
  227. });
  228. return results;
  229. };
  230. this._append=function(s){
  231. var i;
  232. if(_query===null){
  233. _query="";
  234. } else {
  235. _query+=_queuedOperator === "" ? " && " :_queuedOperator;
  236. }
  237. for (i=0;i<_orDepth;i++){
  238. _query+="(";
  239. }
  240. if(_negate){
  241. _query+="!";
  242. }
  243. _query+="("+s+")";
  244. _negate=false;
  245. _queuedOperator="";
  246. _orDepth=0;
  247. };
  248. this._setCommand=function(f,c){
  249. _lastCommand=f;
  250. _lastField=c;
  251. };
  252. this._resetNegate=function(){
  253. _negate=false;
  254. };
  255. this._repeatCommand=function(f,v){
  256. if(_lastCommand===null){
  257. return self;
  258. }
  259. if(f!==null&&v!==null){
  260. return _lastCommand(f,v);
  261. }
  262. if(_lastField===null){
  263. return _lastCommand(f);
  264. }
  265. if(!_useProperties){
  266. return _lastCommand(f);
  267. }
  268. return _lastCommand(_lastField,f);
  269. };
  270. this._equals=function(a,b){
  271. return(self._compare(a,b,1)===0);
  272. };
  273. this._compare=function(a,b,d){
  274. if( d === undefined) { d = 1; }
  275. if(a===undefined) { a = null; }
  276. if(b===undefined) { b = null; }
  277. if(a===null && b===null){
  278. return 0;
  279. }
  280. if(a===null&&b!==null){
  281. return 1;
  282. }
  283. if(a!==null&&b===null){
  284. return -1;
  285. }
  286. if(!_usecase && typeof(a) !== "number" && typeof(b) !== "number" ) {
  287. a=String(a).toLowerCase();
  288. b=String(b).toLowerCase();
  289. }
  290. if(a<b){return -d;}
  291. if(a>b){return d;}
  292. return 0;
  293. };
  294. this._performSort=function(){
  295. if(_sorting.length===0){return;}
  296. _data=self._doSort(_data,0);
  297. };
  298. this._doSort=function(d,q){
  299. var by=_sorting[q].by,
  300. dir=_sorting[q].dir,
  301. type = _sorting[q].type,
  302. dfmt = _sorting[q].datefmt;
  303. if(q==_sorting.length-1){
  304. return self._getOrder(d, by, dir, type, dfmt);
  305. }
  306. q++;
  307. var values=self._getGroup(d,by,dir,type,dfmt);
  308. var results=[];
  309. for(var i=0;i<values.length;i++){
  310. var sorted=self._doSort(values[i].items,q);
  311. for(var j=0;j<sorted.length;j++){
  312. results.push(sorted[j]);
  313. }
  314. }
  315. return results;
  316. };
  317. this._getOrder=function(data,by,dir,type, dfmt){
  318. var sortData=[],_sortData=[], newDir = dir=="a" ? 1 : -1, i,ab,j,
  319. findSortKey;
  320. if(type === undefined ) { type = "text"; }
  321. if (type == 'float' || type== 'number' || type== 'currency' || type== 'numeric') {
  322. findSortKey = function($cell, a) {
  323. var key = parseFloat( String($cell).replace(_stripNum, ''));
  324. return isNaN(key) ? 0.00 : key;
  325. };
  326. } else if (type=='int' || type=='integer') {
  327. findSortKey = function($cell, a) {
  328. return $cell ? parseFloat(String($cell).replace(_stripNum, '')) : 0;
  329. };
  330. } else if(type == 'date' || type == 'datetime') {
  331. findSortKey = function($cell, a) {
  332. return $.jgrid.parseDate(dfmt,$cell).getTime();
  333. };
  334. } else if($.isFunction(type)) {
  335. findSortKey = type;
  336. } else {
  337. findSortKey = function($cell, a) {
  338. if(!$cell) {$cell ="";}
  339. return $.trim(String($cell).toUpperCase());
  340. };
  341. }
  342. $.each(data,function(i,v){
  343. ab = by!=="" ? $.jgrid.getAccessor(v,by) : v;
  344. if(ab === undefined) { ab = ""; }
  345. ab = findSortKey(ab, v);
  346. _sortData.push({ 'vSort': ab,'index':i});
  347. });
  348. _sortData.sort(function(a,b){
  349. a = a.vSort;
  350. b = b.vSort;
  351. return self._compare(a,b,newDir);
  352. });
  353. j=0;
  354. var nrec= data.length;
  355. // overhead, but we do not change the original data.
  356. while(j<nrec) {
  357. i = _sortData[j].index;
  358. sortData.push(data[i]);
  359. j++;
  360. }
  361. return sortData;
  362. };
  363. this._getGroup=function(data,by,dir,type, dfmt){
  364. var results=[],
  365. group=null,
  366. last=null, val;
  367. $.each(self._getOrder(data,by,dir,type, dfmt),function(i,v){
  368. val = $.jgrid.getAccessor(v, by);
  369. if(val === undefined) { val = ""; }
  370. if(!self._equals(last,val)){
  371. last=val;
  372. if(group !== null){
  373. results.push(group);
  374. }
  375. group=self._group(by,val);
  376. }
  377. group.items.push(v);
  378. });
  379. if(group !== null){
  380. results.push(group);
  381. }
  382. return results;
  383. };
  384. this.ignoreCase=function(){
  385. _usecase=false;
  386. return self;
  387. };
  388. this.useCase=function(){
  389. _usecase=true;
  390. return self;
  391. };
  392. this.trim=function(){
  393. _trim=true;
  394. return self;
  395. };
  396. this.noTrim=function(){
  397. _trim=false;
  398. return self;
  399. };
  400. this.execute=function(){
  401. var match=_query, results=[];
  402. if(match === null){
  403. return self;
  404. }
  405. $.each(_data,function(){
  406. if(eval(match)){results.push(this);}
  407. });
  408. _data=results;
  409. return self;
  410. };
  411. this.data=function(){
  412. return _data;
  413. };
  414. this.select=function(f){
  415. self._performSort();
  416. if(!self._hasData()){ return[]; }
  417. self.execute();
  418. if($.isFunction(f)){
  419. var results=[];
  420. $.each(_data,function(i,v){
  421. results.push(f(v));
  422. });
  423. return results;
  424. }
  425. return _data;
  426. };
  427. this.hasMatch=function(f){
  428. if(!self._hasData()) { return false; }
  429. self.execute();
  430. return _data.length>0;
  431. };
  432. this.andNot=function(f,v,x){
  433. _negate=!_negate;
  434. return self.and(f,v,x);
  435. };
  436. this.orNot=function(f,v,x){
  437. _negate=!_negate;
  438. return self.or(f,v,x);
  439. };
  440. this.not=function(f,v,x){
  441. return self.andNot(f,v,x);
  442. };
  443. this.and=function(f,v,x){
  444. _queuedOperator=" && ";
  445. if(f===undefined){
  446. return self;
  447. }
  448. return self._repeatCommand(f,v,x);
  449. };
  450. this.or=function(f,v,x){
  451. _queuedOperator=" || ";
  452. if(f===undefined) { return self; }
  453. return self._repeatCommand(f,v,x);
  454. };
  455. this.orBegin=function(){
  456. _orDepth++;
  457. return self;
  458. };
  459. this.orEnd=function(){
  460. if (_query !== null){
  461. _query+=")";
  462. }
  463. return self;
  464. };
  465. this.isNot=function(f){
  466. _negate=!_negate;
  467. return self.is(f);
  468. };
  469. this.is=function(f){
  470. self._append('this.'+f);
  471. self._resetNegate();
  472. return self;
  473. };
  474. this._compareValues=function(func,f,v,how,t){
  475. var fld;
  476. if(_useProperties){
  477. fld='jQuery.jgrid.getAccessor(this,\''+f+'\')';
  478. }else{
  479. fld='this';
  480. }
  481. if(v===undefined) { v = null; }
  482. //var val=v===null?f:v,
  483. var val =v,
  484. swst = t.stype === undefined ? "text" : t.stype;
  485. if(v !== null) {
  486. switch(swst) {
  487. case 'int':
  488. case 'integer':
  489. val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
  490. fld = 'parseInt('+fld+',10)';
  491. val = 'parseInt('+val+',10)';
  492. break;
  493. case 'float':
  494. case 'number':
  495. case 'numeric':
  496. val = String(val).replace(_stripNum, '');
  497. val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
  498. fld = 'parseFloat('+fld+')';
  499. val = 'parseFloat('+val+')';
  500. break;
  501. case 'date':
  502. case 'datetime':
  503. val = String($.jgrid.parseDate(t.newfmt || 'Y-m-d',val).getTime());
  504. fld = 'jQuery.jgrid.parseDate("'+t.srcfmt+'",'+fld+').getTime()';
  505. break;
  506. default :
  507. fld=self._getStr(fld);
  508. val=self._getStr('"'+self._toStr(val)+'"');
  509. }
  510. }
  511. self._append(fld+' '+how+' '+val);
  512. self._setCommand(func,f);
  513. self._resetNegate();
  514. return self;
  515. };
  516. this.equals=function(f,v,t){
  517. return self._compareValues(self.equals,f,v,"==",t);
  518. };
  519. this.notEquals=function(f,v,t){
  520. return self._compareValues(self.equals,f,v,"!==",t);
  521. };
  522. this.isNull = function(f,v,t){
  523. return self._compareValues(self.equals,f,null,"===",t);
  524. };
  525. this.greater=function(f,v,t){
  526. return self._compareValues(self.greater,f,v,">",t);
  527. };
  528. this.less=function(f,v,t){
  529. return self._compareValues(self.less,f,v,"<",t);
  530. };
  531. this.greaterOrEquals=function(f,v,t){
  532. return self._compareValues(self.greaterOrEquals,f,v,">=",t);
  533. };
  534. this.lessOrEquals=function(f,v,t){
  535. return self._compareValues(self.lessOrEquals,f,v,"<=",t);
  536. };
  537. this.startsWith=function(f,v){
  538. var val = (v===undefined || v===null) ? f: v,
  539. length=_trim ? $.trim(val.toString()).length : val.toString().length;
  540. if(_useProperties){
  541. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(v)+'"'));
  542. }else{
  543. length=_trim?$.trim(v.toString()).length:v.toString().length;
  544. self._append(self._getStr('this')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(f)+'"'));
  545. }
  546. self._setCommand(self.startsWith,f);
  547. self._resetNegate();
  548. return self;
  549. };
  550. this.endsWith=function(f,v){
  551. var val = (v===undefined || v===null) ? f: v,
  552. length=_trim ? $.trim(val.toString()).length:val.toString().length;
  553. if(_useProperties){
  554. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr('+self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.length-'+length+','+length+') == "'+self._toStr(v)+'"');
  555. } else {
  556. self._append(self._getStr('this')+'.substr('+self._getStr('this')+'.length-"'+self._toStr(f)+'".length,"'+self._toStr(f)+'".length) == "'+self._toStr(f)+'"');
  557. }
  558. self._setCommand(self.endsWith,f);self._resetNegate();
  559. return self;
  560. };
  561. this.contains=function(f,v){
  562. if(_useProperties){
  563. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.indexOf("'+self._toStr(v)+'",0) > -1');
  564. }else{
  565. self._append(self._getStr('this')+'.indexOf("'+self._toStr(f)+'",0) > -1');
  566. }
  567. self._setCommand(self.contains,f);
  568. self._resetNegate();
  569. return self;
  570. };
  571. this.groupBy=function(by,dir,type, datefmt){
  572. if(!self._hasData()){
  573. return null;
  574. }
  575. return self._getGroup(_data,by,dir,type, datefmt);
  576. };
  577. this.orderBy=function(by,dir,stype, dfmt){
  578. dir = dir === undefined || dir === null ? "a" :$.trim(dir.toString().toLowerCase());
  579. if(stype === null || stype === undefined) { stype = "text"; }
  580. if(dfmt === null || dfmt === undefined) { dfmt = "Y-m-d"; }
  581. if(dir=="desc"||dir=="descending"){dir="d";}
  582. if(dir=="asc"||dir=="ascending"){dir="a";}
  583. _sorting.push({by:by,dir:dir,type:stype, datefmt: dfmt});
  584. return self;
  585. };
  586. return self;
  587. };
  588. return new queryObject(source,null);
  589. },
  590. extend : function(methods) {
  591. $.extend($.fn.jqGrid,methods);
  592. if (!this.no_legacy_api) {
  593. $.fn.extend(methods);
  594. }
  595. }
  596. });
  597. $.fn.jqGrid = function( pin ) {
  598. if (typeof pin == 'string') {
  599. //var fn = $.fn.jqGrid[pin];
  600. var fn = $.jgrid.getAccessor($.fn.jqGrid,pin);
  601. if (!fn) {
  602. throw ("jqGrid - No such method: " + pin);
  603. }
  604. var args = $.makeArray(arguments).slice(1);
  605. return fn.apply(this,args);
  606. }
  607. return this.each( function() {
  608. if(this.grid) {return;}
  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. beforeProcessing : null,
  652. onHeaderClick: null,
  653. viewrecords: false,
  654. loadonce: false,
  655. multiselect: false,
  656. multikey: false,
  657. editurl: null,
  658. search: false,
  659. caption: "",
  660. hidegrid: true,
  661. hiddengrid: false,
  662. postData: {},
  663. userData: {},
  664. treeGrid : false,
  665. treeGridModel : 'nested',
  666. treeReader : {},
  667. treeANode : -1,
  668. ExpandColumn: null,
  669. tree_root_level : 0,
  670. 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"},
  671. forceFit : false,
  672. gridstate : "visible",
  673. cellEdit: false,
  674. cellsubmit: "remote",
  675. nv:0,
  676. loadui: "enable",
  677. toolbar: [false,""],
  678. scroll: false,
  679. multiboxonly : false,
  680. deselectAfterSort : true,
  681. scrollrows : false,
  682. autowidth: false,
  683. scrollOffset :18,
  684. cellLayout: 5,
  685. subGridWidth: 20,
  686. multiselectWidth: 20,
  687. gridview: false,
  688. rownumWidth: 25,
  689. rownumbers : false,
  690. pagerpos: 'center',
  691. recordpos: 'right',
  692. footerrow : false,
  693. userDataOnFooter : false,
  694. hoverrows : true,
  695. altclass : 'ui-priority-secondary',
  696. viewsortcols : [false,'vertical',true],
  697. resizeclass : '',
  698. autoencode : false,
  699. remapColumns : [],
  700. ajaxGridOptions :{},
  701. direction : "ltr",
  702. toppager: false,
  703. headertitles: false,
  704. scrollTimeout: 40,
  705. data : [],
  706. _index : {},
  707. grouping : false,
  708. groupingView : {groupField:[],groupOrder:[], groupText:[],groupColumnShow:[],groupSummary:[], showSummaryOnHide: false, sortitems:[], sortnames:[], groupDataSorted : false, summary:[],summaryval:[], plusicon: 'ui-icon-circlesmall-plus', minusicon: 'ui-icon-circlesmall-minus'},
  709. ignoreCase : false,
  710. cmTemplate : {},
  711. idPrefix : ""
  712. }, $.jgrid.defaults, pin || {});
  713. var grid={
  714. headers:[],
  715. cols:[],
  716. footers: [],
  717. dragStart: function(i,x,y) {
  718. this.resizing = { idx: i, startX: x.clientX, sOL : y[0]};
  719. this.hDiv.style.cursor = "col-resize";
  720. this.curGbox = $("#rs_m"+$.jgrid.jqID(p.id),"#gbox_"+$.jgrid.jqID(p.id));
  721. this.curGbox.css({display:"block",left:y[0],top:y[1],height:y[2]});
  722. if($.isFunction(p.resizeStart)) { p.resizeStart.call(this,x,i); }
  723. document.onselectstart=function(){return false;};
  724. },
  725. dragMove: function(x) {
  726. if(this.resizing) {
  727. var diff = x.clientX-this.resizing.startX,
  728. h = this.headers[this.resizing.idx],
  729. newWidth = p.direction === "ltr" ? h.width + diff : h.width - diff, hn, nWn;
  730. if(newWidth > 33) {
  731. this.curGbox.css({left:this.resizing.sOL+diff});
  732. if(p.forceFit===true ){
  733. hn = this.headers[this.resizing.idx+p.nv];
  734. nWn = p.direction === "ltr" ? hn.width - diff : hn.width + diff;
  735. if(nWn >33) {
  736. h.newWidth = newWidth;
  737. hn.newWidth = nWn;
  738. }
  739. } else {
  740. this.newWidth = p.direction === "ltr" ? p.tblwidth+diff : p.tblwidth-diff;
  741. h.newWidth = newWidth;
  742. }
  743. }
  744. }
  745. },
  746. dragEnd: function() {
  747. this.hDiv.style.cursor = "default";
  748. if(this.resizing) {
  749. var idx = this.resizing.idx,
  750. nw = this.headers[idx].newWidth || this.headers[idx].width;
  751. nw = parseInt(nw,10);
  752. this.resizing = false;
  753. $("#rs_m"+$.jgrid.jqID(p.id)).css("display","none");
  754. p.colModel[idx].width = nw;
  755. this.headers[idx].width = nw;
  756. this.headers[idx].el.style.width = nw + "px";
  757. this.cols[idx].style.width = nw+"px";
  758. if(this.footers.length>0) {this.footers[idx].style.width = nw+"px";}
  759. if(p.forceFit===true){
  760. nw = this.headers[idx+p.nv].newWidth || this.headers[idx+p.nv].width;
  761. this.headers[idx+p.nv].width = nw;
  762. this.headers[idx+p.nv].el.style.width = nw + "px";
  763. this.cols[idx+p.nv].style.width = nw+"px";
  764. if(this.footers.length>0) {this.footers[idx+p.nv].style.width = nw+"px";}
  765. p.colModel[idx+p.nv].width = nw;
  766. } else {
  767. p.tblwidth = this.newWidth || p.tblwidth;
  768. $('table:first',this.bDiv).css("width",p.tblwidth+"px");
  769. $('table:first',this.hDiv).css("width",p.tblwidth+"px");
  770. this.hDiv.scrollLeft = this.bDiv.scrollLeft;
  771. if(p.footerrow) {
  772. $('table:first',this.sDiv).css("width",p.tblwidth+"px");
  773. this.sDiv.scrollLeft = this.bDiv.scrollLeft;
  774. }
  775. }
  776. if($.isFunction(p.resizeStop)) { p.resizeStop.call(this,nw,idx); }
  777. }
  778. this.curGbox = null;
  779. document.onselectstart=function(){return true;};
  780. },
  781. populateVisible: function() {
  782. if (grid.timer) { clearTimeout(grid.timer); }
  783. grid.timer = null;
  784. var dh = $(grid.bDiv).height();
  785. if (!dh) { return; }
  786. var table = $("table:first", grid.bDiv);
  787. var rows, rh;
  788. if(table[0].rows.length) {
  789. try {
  790. rows = table[0].rows[1];
  791. rh = rows ? $(rows).outerHeight() || grid.prevRowHeight : grid.prevRowHeight;
  792. } catch (pv) {
  793. rh = grid.prevRowHeight;
  794. }
  795. }
  796. if (!rh) { return; }
  797. grid.prevRowHeight = rh;
  798. var rn = p.rowNum;
  799. var scrollTop = grid.scrollTop = grid.bDiv.scrollTop;
  800. var ttop = Math.round(table.position().top) - scrollTop;
  801. var tbot = ttop + table.height();
  802. var div = rh * rn;
  803. var page, npage, empty;
  804. if ( tbot < dh && ttop <= 0 &&
  805. (p.lastpage===undefined||parseInt((tbot + scrollTop + div - 1) / div,10) <= p.lastpage))
  806. {
  807. npage = parseInt((dh - tbot + div - 1) / div,10);
  808. if (tbot >= 0 || npage < 2 || p.scroll === true) {
  809. page = Math.round((tbot + scrollTop) / div) + 1;
  810. ttop = -1;
  811. } else {
  812. ttop = 1;
  813. }
  814. }
  815. if (ttop > 0) {
  816. page = parseInt(scrollTop / div,10) + 1;
  817. npage = parseInt((scrollTop + dh) / div,10) + 2 - page;
  818. empty = true;
  819. }
  820. if (npage) {
  821. if (p.lastpage && page > p.lastpage || p.lastpage==1 || (page === p.page && page===p.lastpage) ) {
  822. return;
  823. }
  824. if (grid.hDiv.loading) {
  825. grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
  826. } else {
  827. p.page = page;
  828. if (empty) {
  829. grid.selectionPreserver(table[0]);
  830. grid.emptyRows(grid.bDiv,false, false);
  831. }
  832. grid.populate(npage);
  833. }
  834. }
  835. },
  836. scrollGrid: function( e ) {
  837. if(p.scroll) {
  838. var scrollTop = grid.bDiv.scrollTop;
  839. if(grid.scrollTop === undefined) { grid.scrollTop = 0; }
  840. if (scrollTop != grid.scrollTop) {
  841. grid.scrollTop = scrollTop;
  842. if (grid.timer) { clearTimeout(grid.timer); }
  843. grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
  844. }
  845. }
  846. grid.hDiv.scrollLeft = grid.bDiv.scrollLeft;
  847. if(p.footerrow) {
  848. grid.sDiv.scrollLeft = grid.bDiv.scrollLeft;
  849. }
  850. if( e ) { e.stopPropagation(); }
  851. },
  852. selectionPreserver : function(ts) {
  853. var p = ts.p;
  854. var sr = p.selrow, sra = p.selarrrow ? $.makeArray(p.selarrrow) : null;
  855. var left = ts.grid.bDiv.scrollLeft;
  856. var complete = p.gridComplete;
  857. p.gridComplete = function() {
  858. p.selrow = null;
  859. p.selarrrow = [];
  860. if(p.multiselect && sra && sra.length>0) {
  861. for(var i=0;i<sra.length;i++){
  862. if (sra[i] != sr) {
  863. $(ts).jqGrid("setSelection",sra[i],false);
  864. }
  865. }
  866. }
  867. if (sr) {
  868. $(ts).jqGrid("setSelection",sr,false);
  869. }
  870. ts.grid.bDiv.scrollLeft = left;
  871. p.gridComplete = complete;
  872. if (p.gridComplete) {
  873. complete();
  874. }
  875. };
  876. }
  877. };
  878. if(this.tagName.toUpperCase()!='TABLE') {
  879. alert("Element is not a table");
  880. return;
  881. }
  882. $(this).empty().attr("tabindex","1");
  883. this.p = p ;
  884. this.p.useProp = !!$.fn.prop;
  885. var i, dir,ts;
  886. if(this.p.colNames.length === 0) {
  887. for (i=0;i<this.p.colModel.length;i++){
  888. this.p.colNames[i] = this.p.colModel[i].label || this.p.colModel[i].name;
  889. }
  890. }
  891. if( this.p.colNames.length !== this.p.colModel.length ) {
  892. alert($.jgrid.errors.model);
  893. return;
  894. }
  895. var gv = $("<div class='ui-jqgrid-view'></div>"), ii,
  896. isMSIE = $.browser.msie ? true:false,
  897. isSafari = $.browser.webkit || $.browser.safari ? true : false;
  898. ts = this;
  899. ts.p.direction = $.trim(ts.p.direction.toLowerCase());
  900. if($.inArray(ts.p.direction,["ltr","rtl"]) == -1) { ts.p.direction = "ltr"; }
  901. dir = ts.p.direction;
  902. $(gv).insertBefore(this);
  903. $(this).appendTo(gv).removeClass("scroll");
  904. var eg = $("<div class='ui-jqgrid ui-widget ui-widget-content ui-corner-all'></div>");
  905. $(eg).insertBefore(gv).attr({"id" : "gbox_"+this.id,"dir":dir});
  906. $(gv).appendTo(eg).attr("id","gview_"+this.id);
  907. if (isMSIE && $.browser.version <= 6) {
  908. ii = '<iframe style="display:block;position:absolute;z-index:-1;filter:Alpha(Opacity=\'0\');" src="javascript:false;"></iframe>';
  909. } else { ii="";}
  910. $("<div class='ui-widget-overlay jqgrid-overlay' id='lui_"+this.id+"'></div>").append(ii).insertBefore(gv);
  911. $("<div class='loading ui-state-default ui-state-active' id='load_"+this.id+"'>"+this.p.loadtext+"</div>").insertBefore(gv);
  912. $(this).attr({cellspacing:"0",cellpadding:"0",border:"0","role":"grid","aria-multiselectable":!!this.p.multiselect,"aria-labelledby":"gbox_"+this.id});
  913. var sortkeys = ["shiftKey","altKey","ctrlKey"],
  914. intNum = function(val,defval) {
  915. val = parseInt(val,10);
  916. if (isNaN(val)) { return defval ? defval : 0;}
  917. else {return val;}
  918. },
  919. formatCol = function (pos, rowInd, tv, rawObject, rowId, rdata){
  920. var cm = ts.p.colModel[pos],
  921. ral = cm.align, result="style=\"", clas = cm.classes, nm = cm.name, celp, acp=[];
  922. if(ral) { result += "text-align:"+ral+";"; }
  923. if(cm.hidden===true) { result += "display:none;"; }
  924. if(rowInd===0) {
  925. result += "width: "+grid.headers[pos].width+"px;";
  926. } else if (cm.cellattr && $.isFunction(cm.cellattr))
  927. {
  928. celp = cm.cellattr.call(ts, rowId, tv, rawObject, cm, rdata);
  929. if(celp && typeof(celp) === "string") {
  930. celp = celp.replace(/style/i,'style').replace(/title/i,'title');
  931. if(celp.indexOf('title') > -1) { cm.title=false;}
  932. if(celp.indexOf('class') > -1) { clas = undefined;}
  933. acp = celp.split("style");
  934. if(acp.length === 2 ) {
  935. acp[1] = $.trim(acp[1].replace("=",""));
  936. if(acp[1].indexOf("'") === 0 || acp[1].indexOf('"') === 0) {
  937. acp[1] = acp[1].substring(1);
  938. }
  939. result += acp[1].replace(/'/gi,'"');
  940. } else {
  941. result += "\"";
  942. }
  943. }
  944. }
  945. if(!acp.length) { acp[0] = ""; result += "\"";}
  946. result += (clas !== undefined ? (" class=\""+clas+"\"") :"") + ((cm.title && tv) ? (" title=\""+$.jgrid.stripHtml(tv)+"\"") :"");
  947. result += " aria-describedby=\""+ts.p.id+"_"+nm+"\"";
  948. return result + acp[0];
  949. },
  950. cellVal = function (val) {
  951. return val === undefined || val === null || val === "" ? "&#160;" : (ts.p.autoencode ? $.jgrid.htmlEncode(val) : val+"");
  952. },
  953. formatter = function (rowId, cellval , colpos, rwdat, _act){
  954. var cm = ts.p.colModel[colpos],v;
  955. if(typeof cm.formatter !== 'undefined') {
  956. var opts= {rowId: rowId, colModel:cm, gid:ts.p.id, pos:colpos };
  957. if($.isFunction( cm.formatter ) ) {
  958. v = cm.formatter.call(ts,cellval,opts,rwdat,_act);
  959. } else if($.fmatter){
  960. v = $.fn.fmatter(cm.formatter, cellval,opts, rwdat, _act);
  961. } else {
  962. v = cellVal(cellval);
  963. }
  964. } else {
  965. v = cellVal(cellval);
  966. }
  967. return v;
  968. },
  969. addCell = function(rowId,cell,pos,irow, srvr) {
  970. var v,prp;
  971. v = formatter(rowId,cell,pos,srvr,'add');
  972. prp = formatCol( pos,irow, v, srvr, rowId, true);
  973. return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  974. },
  975. addMulti = function(rowid,pos,irow){
  976. var v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+ts.p.id+"_"+rowid+"\" class=\"cbox\" name=\"jqg_"+ts.p.id+"_"+rowid+"\"/>",
  977. prp = formatCol( pos,irow,'',null, rowid, true);
  978. return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  979. },
  980. addRowNum = function (pos,irow,pG,rN) {
  981. var v = (parseInt(pG,10)-1)*parseInt(rN,10)+1+irow,
  982. prp = formatCol( pos,irow,v, null, irow, true);
  983. return "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" "+prp+">"+v+"</td>";
  984. },
  985. reader = function (datatype) {
  986. var field, f=[], j=0, i;
  987. for(i =0; i<ts.p.colModel.length; i++){
  988. field = ts.p.colModel[i];
  989. if (field.name !== 'cb' && field.name !=='subgrid' && field.name !=='rn') {
  990. if(datatype == "local") {
  991. f[j] = field.name;
  992. } else {
  993. f[j] = (datatype=="xml") ? field.xmlmap || field.name : field.jsonmap || field.name;
  994. }
  995. j++;
  996. }
  997. }
  998. return f;
  999. },
  1000. orderedCols = function (offset) {
  1001. var order = ts.p.remapColumns;
  1002. if (!order || !order.length) {
  1003. order = $.map(ts.p.colModel, function(v,i) { return i; });
  1004. }
  1005. if (offset) {
  1006. order = $.map(order, function(v) { return v<offset?null:v-offset; });
  1007. }
  1008. return order;
  1009. },
  1010. emptyRows = function (parent, scroll, locdata) {
  1011. if(ts.p.deepempty) {$("#"+$.jgrid.jqID(ts.p.id)+" tbody:first tr:gt(0)").remove();}
  1012. else {
  1013. var trf = $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first tr:first")[0];
  1014. $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").empty().append(trf);
  1015. }
  1016. if (scroll && ts.p.scroll) {
  1017. $(">div:first", parent).css({height:"auto"}).children("div:first").css({height:0,display:"none"});
  1018. parent.scrollTop = 0;
  1019. }
  1020. if(locdata === true) {
  1021. if(ts.p.treeGrid === true ) {
  1022. ts.p.data = []; ts.p._index = {};
  1023. }
  1024. }
  1025. },
  1026. refreshIndex = function() {
  1027. var datalen = ts.p.data.length, idname, i, val,
  1028. ni = ts.p.rownumbers===true ? 1 :0,
  1029. gi = ts.p.multiselect ===true ? 1 :0,
  1030. si = ts.p.subGrid===true ? 1 :0;
  1031. if(ts.p.keyIndex === false || ts.p.loadonce === true) {
  1032. idname = ts.p.localReader.id;
  1033. } else {
  1034. idname = ts.p.colModel[ts.p.keyIndex+gi+si+ni].name;
  1035. }
  1036. for(i =0;i < datalen; i++) {
  1037. val = $.jgrid.getAccessor(ts.p.data[i],idname);
  1038. ts.p._index[val] = i;
  1039. }
  1040. },
  1041. addXmlData = function (xml,t, rcnt, more, adjust) {
  1042. var startReq = new Date(),
  1043. locdata = (ts.p.datatype != "local" && ts.p.loadonce) || ts.p.datatype == "xmlstring",
  1044. xmlid = "_id_",
  1045. frd = ts.p.datatype == "local" ? "local" : "xml";
  1046. if(locdata) {
  1047. ts.p.data = [];
  1048. ts.p._index = {};
  1049. ts.p.localReader.id = xmlid;
  1050. }
  1051. ts.p.reccount = 0;
  1052. if($.isXMLDoc(xml)) {
  1053. if(ts.p.treeANode===-1 && !ts.p.scroll) {
  1054. emptyRows(t,false, true);
  1055. rcnt=1;
  1056. } else { rcnt = rcnt > 1 ? rcnt :1; }
  1057. } else { return; }
  1058. var i,fpos,ir=0,v,row,gi=0,si=0,ni=0,idn, getId,f=[],F,rd ={}, xmlr,rid, rowData=[], cn=(ts.p.altRows === true) ? " "+ts.p.altclass:"",cn1;
  1059. if(!ts.p.xmlReader.repeatitems) {f = reader(frd);}
  1060. if( ts.p.keyIndex===false) {
  1061. idn = ts.p.xmlReader.id;
  1062. } else {
  1063. idn = ts.p.keyIndex;
  1064. }
  1065. if(f.length>0 && !isNaN(idn)) {
  1066. if (ts.p.remapColumns && ts.p.remapColumns.length) {
  1067. idn = $.inArray(idn, ts.p.remapColumns);
  1068. }
  1069. idn=f[idn];
  1070. }
  1071. if( (idn+"").indexOf("[") === -1 ) {
  1072. if (f.length) {
  1073. getId = function( trow, k) {return $(idn,trow).text() || k;};
  1074. } else {
  1075. getId = function( trow, k) {return $(ts.p.xmlReader.cell,trow).eq(idn).text() || k;};
  1076. }
  1077. }
  1078. else {
  1079. getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;};
  1080. }
  1081. ts.p.userData = {};
  1082. $(ts.p.xmlReader.page,xml).each(function() {ts.p.page = this.textContent || this.text || 0; });
  1083. $(ts.p.xmlReader.total,xml).each(function() {ts.p.lastpage = this.textContent || this.text; if(ts.p.lastpage===undefined) { ts.p.lastpage=1; } } );
  1084. $(ts.p.xmlReader.records,xml).each(function() {ts.p.records = this.textContent || this.text || 0; } );
  1085. $(ts.p.xmlReader.userdata,xml).each(function() {ts.p.userData[this.getAttribute("name")]= $(this).text();});
  1086. var gxml = $(ts.p.xmlReader.root+" "+ts.p.xmlReader.row,xml);
  1087. if (!gxml) { gxml = []; }
  1088. var gl = gxml.length, j=0, grpdata={}, rn;
  1089. if(gxml && gl){
  1090. rn = parseInt(ts.p.rowNum,10);
  1091. var br=ts.p.scroll?$.jgrid.randId():1,altr;
  1092. if (adjust) { rn *= adjust+1; }
  1093. var afterInsRow = $.isFunction(ts.p.afterInsertRow), hiderow="";
  1094. if(ts.p.grouping && ts.p.groupingView.groupCollapse === true) {
  1095. hiderow = " style=\"display:none;\"";
  1096. }
  1097. while (j<gl) {
  1098. xmlr = gxml[j];
  1099. rid = getId(xmlr,br+j);
  1100. rid = ts.p.idPrefix + rid;
  1101. altr = rcnt === 0 ? 0 : rcnt+1;
  1102. cn1 = (altr+j)%2 == 1 ? cn : '';
  1103. rowData.push( "<tr"+hiderow+" id=\""+rid+"\" tabindex=\"-1\" role=\"row\" class =\"ui-widget-content jqgrow ui-row-"+ts.p.direction+""+cn1+"\">" );
  1104. if(ts.p.rownumbers===true) {
  1105. rowData.push( addRowNum(0,j,ts.p.page,ts.p.rowNum) );
  1106. ni=1;
  1107. }
  1108. if(ts.p.multiselect===true) {
  1109. rowData.push( addMulti(rid,ni,j) );
  1110. gi=1;
  1111. }
  1112. if (ts.p.subGrid===true) {
  1113. rowData.push( $(ts).jqGrid("addSubGridCell",gi+ni,j+rcnt) );
  1114. si= 1;
  1115. }
  1116. if(ts.p.xmlReader.repeatitems){
  1117. if (!F) { F=orderedCols(gi+si+ni); }
  1118. var cells = $(ts.p.xmlReader.cell,xmlr);
  1119. $.each(F, function (k) {
  1120. var cell = cells[this];
  1121. if (!cell) { return false; }
  1122. v = cell.textContent || cell.text;
  1123. rd[ts.p.colModel[k+gi+si+ni].name] = v;
  1124. rowData.push( addCell(rid,v,k+gi+si+ni,j+rcnt,xmlr) );
  1125. });
  1126. } else {
  1127. for(i = 0; i < f.length;i++) {
  1128. v = $(f[i],xmlr).text();
  1129. rd[ts.p.colModel[i+gi+si+ni].name] = v;
  1130. rowData.push( addCell(rid, v, i+gi+si+ni, j+rcnt, xmlr) );
  1131. }
  1132. }
  1133. rowData.push("</tr>");
  1134. if(ts.p.grouping) {
  1135. var grlen = ts.p.groupingView.groupField.length, grpitem = [];
  1136. for(var z=0;z<grlen;z++) {
  1137. grpitem.push(rd[ts.p.groupingView.groupField[z]]);
  1138. }
  1139. grpdata = $(ts).jqGrid('groupingPrepare',rowData, grpitem, grpdata, rd);
  1140. rowData = [];
  1141. }
  1142. if(locdata || ts.p.treeGrid === true) {
  1143. rd[xmlid] = rid;
  1144. ts.p.data.push(rd);
  1145. ts.p._index[rid] = ts.p.data.length-1;
  1146. }
  1147. if(ts.p.gridview === false ) {
  1148. $("tbody:first",t).append(rowData.join(''));
  1149. if(afterInsRow) {ts.p.afterInsertRow.call(ts,rid,rd,xmlr);}
  1150. rowData=[];
  1151. }
  1152. rd={};
  1153. ir++;
  1154. j++;
  1155. if(ir==rn) {break;}
  1156. }
  1157. }
  1158. if(ts.p.gridview === true) {
  1159. fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
  1160. if(ts.p.grouping) {
  1161. $(ts).jqGrid('groupingRender',grpdata,ts.p.colModel.length);
  1162. grpdata = null;
  1163. } else if(ts.p.treeGrid === true && fpos > 0) {
  1164. $(ts.rows[fpos]).after(rowData.join(''));
  1165. } else {
  1166. $("tbody:first",t).append(rowData.join(''));
  1167. }
  1168. }
  1169. if(ts.p.subGrid === true ) {
  1170. try {$(ts).jqGrid("addSubGrid",gi+ni);} catch (_){}
  1171. }
  1172. ts.p.totaltime = new Date() - startReq;
  1173. if(ir>0) { if(ts.p.records===0) { ts.p.records=gl;} }
  1174. rowData =null;
  1175. if( ts.p.treeGrid === true) {
  1176. try {$(ts).jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
  1177. }
  1178. if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
  1179. ts.p.reccount=ir;
  1180. ts.p.treeANode = -1;
  1181. if(ts.p.userDataOnFooter) { $(ts).jqGrid("footerData","set",ts.p.userData,true); }
  1182. if(locdata) {
  1183. ts.p.records = gl;
  1184. ts.p.lastpage = Math.ceil(gl/ rn);
  1185. }
  1186. if (!more) { ts.updatepager(false,true); }
  1187. if(locdata) {
  1188. while (ir<gl) {
  1189. xmlr = gxml[ir];
  1190. rid = getId(xmlr,ir);
  1191. rid = ts.p.idPrefix + rid;
  1192. if(ts.p.xmlReader.repeatitems){
  1193. if (!F) { F=orderedCols(gi+si+ni); }
  1194. var cells2 = $(ts.p.xmlReader.cell,xmlr);
  1195. $.each(F, function (k) {
  1196. var cell = cells2[this];
  1197. if (!cell) { return false; }
  1198. v = cell.textContent || cell.text;
  1199. rd[ts.p.colModel[k+gi+si+ni].name] = v;
  1200. });
  1201. } else {
  1202. for(i = 0; i < f.length;i++) {
  1203. v = $(f[i],xmlr).text();
  1204. rd[ts.p.colModel[i+gi+si+ni].name] = v;
  1205. }
  1206. }
  1207. rd[xmlid] = rid;
  1208. ts.p.data.push(rd);
  1209. ts.p._index[rid] = ts.p.data.length-1;
  1210. rd = {};
  1211. ir++;
  1212. }
  1213. }
  1214. },
  1215. addJSONData = function(data,t, rcnt, more, adjust) {
  1216. var startReq = new Date();
  1217. if(data) {
  1218. if(ts.p.treeANode === -1 && !ts.p.scroll) {
  1219. emptyRows(t,false, true);
  1220. rcnt=1;
  1221. } else { rcnt = rcnt > 1 ? rcnt :1; }
  1222. } else { return; }
  1223. var dReader, locid = "_id_", frd,
  1224. locdata = (ts.p.datatype != "local" && ts.p.loadonce) || ts.p.datatype == "jsonstring";
  1225. if(locdata) { ts.p.data = []; ts.p._index = {}; ts.p.localReader.id = locid;}
  1226. ts.p.reccount = 0;
  1227. if(ts.p.datatype == "local") {
  1228. dReader = ts.p.localReader;
  1229. frd= 'local';
  1230. } else {
  1231. dReader = ts.p.jsonReader;
  1232. frd='json';
  1233. }
  1234. var ir=0,v,i,j,f=[],F,cur,gi=0,si=0,ni=0,len,drows,idn,rd={}, fpos, idr,rowData=[],cn=(ts.p.altRows === true) ? " "+ts.p.altclass:"",cn1,lp;
  1235. ts.p.page = $.jgrid.getAccessor(data,dReader.page) || 0;
  1236. lp = $.jgrid.getAccessor(data,dReader.total);
  1237. ts.p.lastpage = lp === undefined ? 1 : lp;
  1238. ts.p.records = $.jgrid.getAccessor(data,dReader.records) || 0;
  1239. ts.p.userData = $.jgrid.getAccessor(data,dReader.userdata) || {};
  1240. if(!dReader.repeatitems) {
  1241. F = f = reader(frd);
  1242. }
  1243. if( ts.p.keyIndex===false ) {
  1244. idn = dReader.id;
  1245. } else {
  1246. idn = ts.p.keyIndex;
  1247. }
  1248. if(f.length>0 && !isNaN(idn)) {
  1249. if (ts.p.remapColumns && ts.p.remapColumns.length) {
  1250. idn = $.inArray(idn, ts.p.remapColumns);
  1251. }
  1252. idn=f[idn];
  1253. }
  1254. drows = $.jgrid.getAccessor(data,dReader.root);
  1255. if (!drows) { drows = []; }
  1256. len = drows.length; i=0;
  1257. var rn = parseInt(ts.p.rowNum,10),br=ts.p.scroll?$.jgrid.randId():1, altr;
  1258. if (adjust) { rn *= adjust+1; }
  1259. var afterInsRow = $.isFunction(ts.p.afterInsertRow), grpdata={}, hiderow="";
  1260. if(ts.p.grouping && ts.p.groupingView.groupCollapse === true) {
  1261. hiderow = " style=\"display:none;\"";
  1262. }
  1263. while (i<len) {
  1264. cur = drows[i];
  1265. idr = $.jgrid.getAccessor(cur,idn);
  1266. if(idr === undefined) {
  1267. idr = br+i;
  1268. if(f.length===0){
  1269. if(dReader.cell){
  1270. var ccur = $.jgrid.getAccessor(cur,dReader.cell);
  1271. idr = ccur[idn] || idr;
  1272. ccur=null;
  1273. }
  1274. }
  1275. }
  1276. idr = ts.p.idPrefix + idr;
  1277. altr = rcnt === 1 ? 0 : rcnt;
  1278. cn1 = (altr+i)%2 == 1 ? cn : '';
  1279. rowData.push("<tr"+hiderow+" id=\""+ idr +"\" tabindex=\"-1\" role=\"row\" class= \"ui-widget-content jqgrow ui-row-"+ts.p.direction+""+cn1+"\">");
  1280. if(ts.p.rownumbers===true) {
  1281. rowData.push( addRowNum(0,i,ts.p.page,ts.p.rowNum) );
  1282. ni=1;
  1283. }
  1284. if(ts.p.multiselect){
  1285. rowData.push( addMulti(idr,ni,i) );
  1286. gi = 1;
  1287. }
  1288. if (ts.p.subGrid) {
  1289. rowData.push( $(ts).jqGrid("addSubGridCell",gi+ni,i+rcnt) );
  1290. si= 1;
  1291. }
  1292. if (dReader.repeatitems) {
  1293. if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell);}
  1294. if (!F) { F=orderedCols(gi+si+ni); }
  1295. }
  1296. for (j=0;j<F.length;j++) {
  1297. v = $.jgrid.getAccessor(cur,F[j]);
  1298. rowData.push( addCell(idr,v,j+gi+si+ni,i+rcnt,cur) );
  1299. rd[ts.p.colModel[j+gi+si+ni].name] = v;
  1300. }
  1301. rowData.push( "</tr>" );
  1302. if(ts.p.grouping) {
  1303. var grlen = ts.p.groupingView.groupField.length, grpitem = [];
  1304. for(var z=0;z<grlen;z++) {
  1305. grpitem.push(rd[ts.p.groupingView.groupField[z]]);
  1306. }
  1307. grpdata = $(ts).jqGrid('groupingPrepare',rowData, grpitem, grpdata, rd);
  1308. rowData = [];
  1309. }
  1310. if(locdata || ts.p.treeGrid===true) {
  1311. rd[locid] = idr;
  1312. ts.p.data.push(rd);
  1313. ts.p._index[idr] = ts.p.data.length-1;
  1314. }
  1315. if(ts.p.gridview === false ) {
  1316. $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join(''));
  1317. if(afterInsRow) {ts.p.afterInsertRow.call(ts,idr,rd,cur);}
  1318. rowData=[];//ari=0;
  1319. }
  1320. rd={};
  1321. ir++;
  1322. i++;
  1323. if(ir==rn) { break; }
  1324. }
  1325. if(ts.p.gridview === true ) {
  1326. fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
  1327. if(ts.p.grouping) {
  1328. $(ts).jqGrid('groupingRender',grpdata,ts.p.colModel.length);
  1329. grpdata = null;
  1330. } else if(ts.p.treeGrid === true && fpos > 0) {
  1331. $(ts.rows[fpos]).after(rowData.join(''));
  1332. } else {
  1333. $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join(''));
  1334. }
  1335. }
  1336. if(ts.p.subGrid === true ) {
  1337. try { $(ts).jqGrid("addSubGrid",gi+ni);} catch (_){}
  1338. }
  1339. ts.p.totaltime = new Date() - startReq;
  1340. if(ir>0) {
  1341. if(ts.p.records===0) { ts.p.records=len; }
  1342. }
  1343. rowData = null;
  1344. if( ts.p.treeGrid === true) {
  1345. try {$(ts).jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
  1346. }
  1347. if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
  1348. ts.p.reccount=ir;
  1349. ts.p.treeANode = -1;
  1350. if(ts.p.userDataOnFooter) { $(ts).jqGrid("footerData","set",ts.p.userData,true); }
  1351. if(locdata) {
  1352. ts.p.records = len;
  1353. ts.p.lastpage = Math.ceil(len/ rn);
  1354. }
  1355. if (!more) { ts.updatepager(false,true); }
  1356. if(locdata) {
  1357. while (ir<len && drows[ir]) {
  1358. cur = drows[ir];
  1359. idr = $.jgrid.getAccessor(cur,idn);
  1360. if(idr === undefined) {
  1361. idr = br+ir;
  1362. if(f.length===0){
  1363. if(dReader.cell){
  1364. var ccur2 = $.jgrid.getAccessor(cur,dReader.cell);
  1365. idr = ccur2[idn] || idr;
  1366. ccur2=null;
  1367. }
  1368. }
  1369. }
  1370. if(cur) {
  1371. idr = ts.p.idPrefix + idr;
  1372. if (dReader.repeatitems) {
  1373. if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell);}
  1374. if (!F) { F=orderedCols(gi+si+ni); }
  1375. }
  1376. for (j=0;j<F.length;j++) {
  1377. v = $.jgrid.getAccessor(cur,F[j]);
  1378. rd[ts.p.colModel[j+gi+si+ni].name] = v;
  1379. }
  1380. rd[locid] = idr;
  1381. ts.p.data.push(rd);
  1382. ts.p._index[idr] = ts.p.data.length-1;
  1383. rd = {};
  1384. }
  1385. ir++;
  1386. }
  1387. }
  1388. },
  1389. addLocalData = function() {
  1390. var st, fndsort=false, cmtypes={}, grtypes=[], grindexes=[], srcformat, sorttype, newformat;
  1391. if(!$.isArray(ts.p.data)) {
  1392. return;
  1393. }
  1394. var grpview = ts.p.grouping ? ts.p.groupingView : false;
  1395. $.each(ts.p.colModel,function(i,v){
  1396. sorttype = this.sorttype || "text";
  1397. if(sorttype == "date" || sorttype == "datetime") {
  1398. if(this.formatter && typeof(this.formatter) === 'string' && this.formatter == 'date') {
  1399. if(this.formatoptions && this.formatoptions.srcformat) {
  1400. srcformat = this.formatoptions.srcformat;
  1401. } else {
  1402. srcformat = $.jgrid.formatter.date.srcformat;
  1403. }
  1404. if(this.formatoptions && this.formatoptions.newformat) {
  1405. newformat = this.formatoptions.newformat;
  1406. } else {
  1407. newformat = $.jgrid.formatter.date.newformat;
  1408. }
  1409. } else {
  1410. srcformat = newformat = this.datefmt || "Y-m-d";
  1411. }
  1412. cmtypes[this.name] = {"stype": sorttype, "srcfmt": srcformat,"newfmt":newformat};
  1413. } else {
  1414. cmtypes[this.name] = {"stype": sorttype, "srcfmt":'',"newfmt":''};
  1415. }
  1416. if(ts.p.grouping && this.name == grpview.groupField[0]) {
  1417. var grindex = this.name;
  1418. if (typeof this.index != 'undefined') {
  1419. grindex = this.index;
  1420. }
  1421. grtypes[0] = cmtypes[grindex];
  1422. grindexes.push(grindex);
  1423. }
  1424. if(!fndsort && (this.index == ts.p.sortname || this.name == ts.p.sortname)){
  1425. st = this.name; // ???
  1426. fndsort = true;
  1427. }
  1428. });
  1429. if(ts.p.treeGrid) {
  1430. $(ts).jqGrid("SortTree", st, ts.p.sortorder, cmtypes[st].stype, cmtypes[st].srcfmt);
  1431. return;
  1432. }
  1433. var compareFnMap = {
  1434. 'eq':function(queryObj, op) {return queryObj.equals;},
  1435. 'ne':function(queryObj,op) {return queryObj.notEquals;},
  1436. 'lt':function(queryObj,op) {return queryObj.less;},
  1437. 'le':function(queryObj,op) {return queryObj.lessOrEquals;},
  1438. 'gt':function(queryObj,op) {return queryObj.greater;},
  1439. 'ge':function(queryObj,op) {return queryObj.greaterOrEquals;},
  1440. 'cn':function(queryObj,op) {return queryObj.contains;},
  1441. 'nc':function(queryObj,op) {return op === "OR" ? queryObj.orNot().contains : queryObj.andNot().contains;},
  1442. 'bw':function(queryObj,op) {return queryObj.startsWith;},
  1443. 'bn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().startsWith : queryObj.andNot().startsWith;},
  1444. 'en':function(queryObj,op) {return op === "OR" ? queryObj.orNot().endsWith : queryObj.andNot().endsWith;},
  1445. 'ew':function(queryObj,op) {return queryObj.endsWith;},
  1446. 'ni':function(queryObj,op) {return op === "OR" ? queryObj.orNot().equals : queryObj.andNot().equals;},
  1447. 'in':function(queryObj,op) {return queryObj.equals;},
  1448. 'nu':function(queryObj,op) {return queryObj.isNull;},
  1449. 'nn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().isNull : queryObj.andNot().isNull;}
  1450. },
  1451. query = $.jgrid.from(ts.p.data);
  1452. if (ts.p.ignoreCase) { query = query.ignoreCase(); }
  1453. function tojLinq ( group ) {
  1454. var s = 0, index, gor, ror, opr, rule;
  1455. if (group.groups !== undefined) {
  1456. gor = group.groups.length && group.groupOp.toString().toUpperCase() === "OR";
  1457. if (gor) {
  1458. query.orBegin();
  1459. }
  1460. for (index = 0; index < group.groups.length; index++) {
  1461. if (s > 0 && gor) {
  1462. query.or();
  1463. }
  1464. try {
  1465. tojLinq(group.groups[index]);
  1466. } catch (e) {alert(e);}
  1467. s++;
  1468. }
  1469. if (gor) {
  1470. query.orEnd();
  1471. }
  1472. }
  1473. if (group.rules !== undefined) {
  1474. if(s>0) {
  1475. var result = query.select();
  1476. query = $.jgrid.from( result);
  1477. if (ts.p.ignoreCase) { query = query.ignoreCase(); }
  1478. }
  1479. try{
  1480. ror = group.rules.length && group.groupOp.toString().toUpperCase() === "OR";
  1481. if (ror) {
  1482. query.orBegin();
  1483. }
  1484. for (index = 0; index < group.rules.length; index++) {
  1485. rule = group.rules[index];
  1486. opr = group.groupOp.toString().toUpperCase();
  1487. if (compareFnMap[rule.op] && rule.field ) {
  1488. if(s > 0 && opr && opr === "OR") {
  1489. query = query.or();
  1490. }
  1491. query = compareFnMap[rule.op](query, opr)(rule.field, rule.data, cmtypes[rule.field]);
  1492. }
  1493. s++;
  1494. }
  1495. if (ror) {
  1496. query.orEnd();
  1497. }
  1498. } catch (g) {alert(g);}
  1499. }
  1500. }
  1501. if (ts.p.search === true) {
  1502. var srules = ts.p.postData.filters;
  1503. if(srules) {
  1504. if(typeof srules == "string") { srules = $.jgrid.parse(srules);}
  1505. tojLinq( srules );
  1506. } else {
  1507. try {
  1508. query = compareFnMap[ts.p.postData.searchOper](query)(ts.p.postData.searchField, ts.p.postData.searchString,cmtypes[ts.p.postData.searchField]);
  1509. } catch (se){}
  1510. }
  1511. }
  1512. if(ts.p.grouping) {
  1513. query.orderBy(grindexes,grpview.groupOrder[0],grtypes[0].stype, grtypes[0].srcfmt);
  1514. grpview.groupDataSorted = true;
  1515. }
  1516. if (st && ts.p.sortorder && fndsort) {
  1517. if(ts.p.sortorder.toUpperCase() == "DESC") {
  1518. query.orderBy(ts.p.sortname, "d", cmtypes[st].stype, cmtypes[st].srcfmt);
  1519. } else {
  1520. query.orderBy(ts.p.sortname, "a", cmtypes[st].stype, cmtypes[st].srcfmt);
  1521. }
  1522. }
  1523. var queryResults = query.select(),
  1524. recordsperpage = parseInt(ts.p.rowNum,10),
  1525. total = queryResults.length,
  1526. page = parseInt(ts.p.page,10),
  1527. totalpages = Math.ceil(total / recordsperpage),
  1528. retresult = {};
  1529. queryResults = queryResults.slice( (page-1)*recordsperpage , page*recordsperpage );
  1530. query = null;
  1531. cmtypes = null;
  1532. retresult[ts.p.localReader.total] = totalpages;
  1533. retresult[ts.p.localReader.page] = page;
  1534. retresult[ts.p.localReader.records] = total;
  1535. retresult[ts.p.localReader.root] = queryResults;
  1536. retresult[ts.p.localReader.userdata] = ts.p.userData;
  1537. queryResul

Large files files are truncated, but you can click here to view the full file