/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
- // ==ClosureCompiler==
- // @compilation_level SIMPLE_OPTIMIZATIONS
-
- /**
- * @license jqGrid 4.2.0 - jQuery Grid
- * Copyright (c) 2008, Tony Tomov, tony@trirand.com
- * Dual licensed under the MIT and GPL licenses
- * http://www.opensource.org/licenses/mit-license.php
- * http://www.gnu.org/licenses/gpl-2.0.html
- * Date: 2011-10-11
- */
- //jsHint options
- /*global document, window, jQuery, DOMParser, ActiveXObject $ */
-
- (function ($) {
-
- $.jgrid = $.jgrid || {};
- $.extend($.jgrid,{
- htmlDecode : function(value){
- if(value && (value==' ' || value==' ' || (value.length==1 && value.charCodeAt(0)==160))) { return "";}
- return !value ? value : String(value).replace(/>/g, ">").replace(/</g, "<").replace(/"/g, '"').replace(/&/g, "&");
- },
- htmlEncode : function (value){
- return !value ? value : String(value).replace(/&/g, "&").replace(/\"/g, """).replace(/</g, "<").replace(/>/g, ">");
- },
- format : function(format){ //jqgformat
- var args = $.makeArray(arguments).slice(1);
- if(format===undefined) { format = ""; }
- return format.replace(/\{(\d+)\}/g, function(m, i){
- return args[i];
- });
- },
- getCellIndex : function (cell) {
- var c = $(cell);
- if (c.is('tr')) { return -1; }
- c = (!c.is('td') && !c.is('th') ? c.closest("td,th") : c)[0];
- if ($.browser.msie) { return $.inArray(c, c.parentNode.cells); }
- return c.cellIndex;
- },
- stripHtml : function(v) {
- v = v+"";
- var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
- if (v) {
- v = v.replace(regexp,"");
- return (v && v !== ' ' && v !== ' ') ? v.replace(/\"/g,"'") : "";
- } else {
- return v;
- }
- },
- stripPref : function (pref, id) {
- var obj = Object.prototype.toString.call(pref).slice(8, -1);
- if( obj == "String" || obj =="Number") {
- pref = String(pref);
- id = pref != "" ? String(id).replace(String(pref), "") : id;
- }
- return id;
- },
- stringToDoc : function (xmlString) {
- var xmlDoc;
- if(typeof xmlString !== 'string') { return xmlString; }
- try {
- var parser = new DOMParser();
- xmlDoc = parser.parseFromString(xmlString,"text/xml");
- }
- catch(e) {
- xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
- xmlDoc.async=false;
- xmlDoc.loadXML(xmlString);
- }
- return (xmlDoc && xmlDoc.documentElement && xmlDoc.documentElement.tagName != 'parsererror') ? xmlDoc : null;
- },
- parse : function(jsonString) {
- var js = jsonString;
- if (js.substr(0,9) == "while(1);") { js = js.substr(9); }
- if (js.substr(0,2) == "/*") { js = js.substr(2,js.length-4); }
- if(!js) { js = "{}"; }
- return ($.jgrid.useJSON===true && typeof (JSON) === 'object' && typeof (JSON.parse) === 'function') ?
- JSON.parse(js) :
- eval('(' + js + ')');
- },
- parseDate : function(format, date) {
- var tsp = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0},k,hl,dM, regdate = /[\\\/:_;.,\t\T\s-]/;
- if(date && date !== null && date !== undefined){
- date = $.trim(date);
- date = date.split(regdate);
- format = format.split(regdate);
- var dfmt = $.jgrid.formatter.date.monthNames;
- var afmt = $.jgrid.formatter.date.AmPm;
- var h12to24 = function(ampm, h){
- if (ampm === 0){ if (h == 12) { h = 0;} }
- else { if (h != 12) { h += 12; } }
- return h;
- };
- for(k=0,hl=format.length;k<hl;k++){
- if(format[k] == 'M') {
- dM = $.inArray(date[k],dfmt);
- if(dM !== -1 && dM < 12){date[k] = dM+1;}
- }
- if(format[k] == 'F') {
- dM = $.inArray(date[k],dfmt);
- if(dM !== -1 && dM > 11){date[k] = dM+1-12;}
- }
- if(format[k] == 'a') {
- dM = $.inArray(date[k],afmt);
- if(dM !== -1 && dM < 2 && date[k] == afmt[dM]){
- date[k] = dM;
- tsp.h = h12to24(date[k], tsp.h);
- }
- }
- if(format[k] == 'A') {
- dM = $.inArray(date[k],afmt);
- if(dM !== -1 && dM > 1 && date[k] == afmt[dM]){
- date[k] = dM-2;
- tsp.h = h12to24(date[k], tsp.h);
- }
- }
- if(date[k] !== undefined) {
- tsp[format[k].toLowerCase()] = parseInt(date[k],10);
- }
- }
- tsp.m = parseInt(tsp.m,10)-1;
- var ty = tsp.y;
- if (ty >= 70 && ty <= 99) {tsp.y = 1900+tsp.y;}
- else if (ty >=0 && ty <=69) {tsp.y= 2000+tsp.y;}
- }
- return new Date(tsp.y, tsp.m, tsp.d, tsp.h, tsp.i, tsp.s,0);
- },
- jqID : function(sid){
- return String(sid).replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g,"\\$&");
- },
- guid : 1,
- uidPref: 'jqg',
- randId : function( prefix ) {
- return (prefix? prefix: $.jgrid.uidPref) + ($.jgrid.guid++);
- },
- getAccessor : function(obj, expr) {
- var ret,p,prm = [], i;
- if( typeof expr === 'function') { return expr(obj); }
- ret = obj[expr];
- if(ret===undefined) {
- try {
- if ( typeof expr === 'string' ) {
- prm = expr.split('.');
- }
- i = prm.length;
- if( i ) {
- ret = obj;
- while (ret && i--) {
- p = prm.shift();
- ret = ret[p];
- }
- }
- } catch (e) {}
- }
- return ret;
- },
- ajaxOptions: {},
- from : function(source,initalQuery){
- // Original Author Hugo Bonacci
- // License MIT http://jlinq.codeplex.com/license
- var queryObject=function(d,q){
- if(typeof(d)=="string"){
- d=$.data(d);
- }
- var self=this,
- _data=d,
- _usecase=true,
- _trim=false,
- _query=q,
- _stripNum = /[\$,%]/g,
- _lastCommand=null,
- _lastField=null,
- _orDepth=0,
- _negate=false,
- _queuedOperator="",
- _sorting=[],
- _useProperties=true;
- if(typeof(d)=="object"&&d.push) {
- if(d.length>0){
- if(typeof(d[0])!="object"){
- _useProperties=false;
- }else{
- _useProperties=true;
- }
- }
- }else{
- throw "data provides is not an array";
- }
- this._hasData=function(){
- return _data===null?false:_data.length===0?false:true;
- };
- this._getStr=function(s){
- var phrase=[];
- if(_trim){
- phrase.push("jQuery.trim(");
- }
- phrase.push("String("+s+")");
- if(_trim){
- phrase.push(")");
- }
- if(!_usecase){
- phrase.push(".toLowerCase()");
- }
- return phrase.join("");
- };
- this._strComp=function(val){
- if(typeof(val)=="string"){
- return".toString()";
- }else{
- return"";
- }
- };
- this._group=function(f,u){
- return({field:f.toString(),unique:u,items:[]});
- };
- this._toStr=function(phrase){
- if(_trim){
- phrase=$.trim(phrase);
- }
- if(!_usecase){
- phrase=phrase.toLowerCase();
- }
- phrase=phrase.toString().replace(/\\/g,'\\\\').replace(/\"/g,'\\"');
- return phrase;
- };
- this._funcLoop=function(func){
- var results=[];
- $.each(_data,function(i,v){
- results.push(func(v));
- });
- return results;
- };
- this._append=function(s){
- var i;
- if(_query===null){
- _query="";
- } else {
- _query+=_queuedOperator === "" ? " && " :_queuedOperator;
- }
- for (i=0;i<_orDepth;i++){
- _query+="(";
- }
- if(_negate){
- _query+="!";
- }
- _query+="("+s+")";
- _negate=false;
- _queuedOperator="";
- _orDepth=0;
- };
- this._setCommand=function(f,c){
- _lastCommand=f;
- _lastField=c;
- };
- this._resetNegate=function(){
- _negate=false;
- };
- this._repeatCommand=function(f,v){
- if(_lastCommand===null){
- return self;
- }
- if(f!==null&&v!==null){
- return _lastCommand(f,v);
- }
- if(_lastField===null){
- return _lastCommand(f);
- }
- if(!_useProperties){
- return _lastCommand(f);
- }
- return _lastCommand(_lastField,f);
- };
- this._equals=function(a,b){
- return(self._compare(a,b,1)===0);
- };
- this._compare=function(a,b,d){
- if( d === undefined) { d = 1; }
- if(a===undefined) { a = null; }
- if(b===undefined) { b = null; }
- if(a===null && b===null){
- return 0;
- }
- if(a===null&&b!==null){
- return 1;
- }
- if(a!==null&&b===null){
- return -1;
- }
- if(!_usecase && typeof(a) !== "number" && typeof(b) !== "number" ) {
- a=String(a).toLowerCase();
- b=String(b).toLowerCase();
- }
- if(a<b){return -d;}
- if(a>b){return d;}
- return 0;
- };
- this._performSort=function(){
- if(_sorting.length===0){return;}
- _data=self._doSort(_data,0);
- };
- this._doSort=function(d,q){
- var by=_sorting[q].by,
- dir=_sorting[q].dir,
- type = _sorting[q].type,
- dfmt = _sorting[q].datefmt;
- if(q==_sorting.length-1){
- return self._getOrder(d, by, dir, type, dfmt);
- }
- q++;
- var values=self._getGroup(d,by,dir,type,dfmt);
- var results=[];
- for(var i=0;i<values.length;i++){
- var sorted=self._doSort(values[i].items,q);
- for(var j=0;j<sorted.length;j++){
- results.push(sorted[j]);
- }
- }
- return results;
- };
- this._getOrder=function(data,by,dir,type, dfmt){
- var sortData=[],_sortData=[], newDir = dir=="a" ? 1 : -1, i,ab,j,
- findSortKey;
-
- if(type === undefined ) { type = "text"; }
- if (type == 'float' || type== 'number' || type== 'currency' || type== 'numeric') {
- findSortKey = function($cell, a) {
- var key = parseFloat( String($cell).replace(_stripNum, ''));
- return isNaN(key) ? 0.00 : key;
- };
- } else if (type=='int' || type=='integer') {
- findSortKey = function($cell, a) {
- return $cell ? parseFloat(String($cell).replace(_stripNum, '')) : 0;
- };
- } else if(type == 'date' || type == 'datetime') {
- findSortKey = function($cell, a) {
- return $.jgrid.parseDate(dfmt,$cell).getTime();
- };
- } else if($.isFunction(type)) {
- findSortKey = type;
- } else {
- findSortKey = function($cell, a) {
- if(!$cell) {$cell ="";}
- return $.trim(String($cell).toUpperCase());
- };
- }
- $.each(data,function(i,v){
- ab = by!=="" ? $.jgrid.getAccessor(v,by) : v;
- if(ab === undefined) { ab = ""; }
- ab = findSortKey(ab, v);
- _sortData.push({ 'vSort': ab,'index':i});
- });
-
- _sortData.sort(function(a,b){
- a = a.vSort;
- b = b.vSort;
- return self._compare(a,b,newDir);
- });
- j=0;
- var nrec= data.length;
- // overhead, but we do not change the original data.
- while(j<nrec) {
- i = _sortData[j].index;
- sortData.push(data[i]);
- j++;
- }
- return sortData;
- };
- this._getGroup=function(data,by,dir,type, dfmt){
- var results=[],
- group=null,
- last=null, val;
- $.each(self._getOrder(data,by,dir,type, dfmt),function(i,v){
- val = $.jgrid.getAccessor(v, by);
- if(val === undefined) { val = ""; }
- if(!self._equals(last,val)){
- last=val;
- if(group !== null){
- results.push(group);
- }
- group=self._group(by,val);
- }
- group.items.push(v);
- });
- if(group !== null){
- results.push(group);
- }
- return results;
- };
- this.ignoreCase=function(){
- _usecase=false;
- return self;
- };
- this.useCase=function(){
- _usecase=true;
- return self;
- };
- this.trim=function(){
- _trim=true;
- return self;
- };
- this.noTrim=function(){
- _trim=false;
- return self;
- };
- this.execute=function(){
- var match=_query, results=[];
- if(match === null){
- return self;
- }
- $.each(_data,function(){
- if(eval(match)){results.push(this);}
- });
- _data=results;
- return self;
- };
- this.data=function(){
- return _data;
- };
- this.select=function(f){
- self._performSort();
- if(!self._hasData()){ return[]; }
- self.execute();
- if($.isFunction(f)){
- var results=[];
- $.each(_data,function(i,v){
- results.push(f(v));
- });
- return results;
- }
- return _data;
- };
- this.hasMatch=function(f){
- if(!self._hasData()) { return false; }
- self.execute();
- return _data.length>0;
- };
- this.andNot=function(f,v,x){
- _negate=!_negate;
- return self.and(f,v,x);
- };
- this.orNot=function(f,v,x){
- _negate=!_negate;
- return self.or(f,v,x);
- };
- this.not=function(f,v,x){
- return self.andNot(f,v,x);
- };
- this.and=function(f,v,x){
- _queuedOperator=" && ";
- if(f===undefined){
- return self;
- }
- return self._repeatCommand(f,v,x);
- };
- this.or=function(f,v,x){
- _queuedOperator=" || ";
- if(f===undefined) { return self; }
- return self._repeatCommand(f,v,x);
- };
- this.orBegin=function(){
- _orDepth++;
- return self;
- };
- this.orEnd=function(){
- if (_query !== null){
- _query+=")";
- }
- return self;
- };
- this.isNot=function(f){
- _negate=!_negate;
- return self.is(f);
- };
- this.is=function(f){
- self._append('this.'+f);
- self._resetNegate();
- return self;
- };
- this._compareValues=function(func,f,v,how,t){
- var fld;
- if(_useProperties){
- fld='jQuery.jgrid.getAccessor(this,\''+f+'\')';
- }else{
- fld='this';
- }
- if(v===undefined) { v = null; }
- //var val=v===null?f:v,
- var val =v,
- swst = t.stype === undefined ? "text" : t.stype;
- if(v !== null) {
- switch(swst) {
- case 'int':
- case 'integer':
- val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
- fld = 'parseInt('+fld+',10)';
- val = 'parseInt('+val+',10)';
- break;
- case 'float':
- case 'number':
- case 'numeric':
- val = String(val).replace(_stripNum, '');
- val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
- fld = 'parseFloat('+fld+')';
- val = 'parseFloat('+val+')';
- break;
- case 'date':
- case 'datetime':
- val = String($.jgrid.parseDate(t.newfmt || 'Y-m-d',val).getTime());
- fld = 'jQuery.jgrid.parseDate("'+t.srcfmt+'",'+fld+').getTime()';
- break;
- default :
- fld=self._getStr(fld);
- val=self._getStr('"'+self._toStr(val)+'"');
- }
- }
- self._append(fld+' '+how+' '+val);
- self._setCommand(func,f);
- self._resetNegate();
- return self;
- };
- this.equals=function(f,v,t){
- return self._compareValues(self.equals,f,v,"==",t);
- };
- this.notEquals=function(f,v,t){
- return self._compareValues(self.equals,f,v,"!==",t);
- };
- this.isNull = function(f,v,t){
- return self._compareValues(self.equals,f,null,"===",t);
- };
- this.greater=function(f,v,t){
- return self._compareValues(self.greater,f,v,">",t);
- };
- this.less=function(f,v,t){
- return self._compareValues(self.less,f,v,"<",t);
- };
- this.greaterOrEquals=function(f,v,t){
- return self._compareValues(self.greaterOrEquals,f,v,">=",t);
- };
- this.lessOrEquals=function(f,v,t){
- return self._compareValues(self.lessOrEquals,f,v,"<=",t);
- };
- this.startsWith=function(f,v){
- var val = (v===undefined || v===null) ? f: v,
- length=_trim ? $.trim(val.toString()).length : val.toString().length;
- if(_useProperties){
- self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(v)+'"'));
- }else{
- length=_trim?$.trim(v.toString()).length:v.toString().length;
- self._append(self._getStr('this')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(f)+'"'));
- }
- self._setCommand(self.startsWith,f);
- self._resetNegate();
- return self;
- };
- this.endsWith=function(f,v){
- var val = (v===undefined || v===null) ? f: v,
- length=_trim ? $.trim(val.toString()).length:val.toString().length;
- if(_useProperties){
- self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr('+self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.length-'+length+','+length+') == "'+self._toStr(v)+'"');
- } else {
- self._append(self._getStr('this')+'.substr('+self._getStr('this')+'.length-"'+self._toStr(f)+'".length,"'+self._toStr(f)+'".length) == "'+self._toStr(f)+'"');
- }
- self._setCommand(self.endsWith,f);self._resetNegate();
- return self;
- };
- this.contains=function(f,v){
- if(_useProperties){
- self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.indexOf("'+self._toStr(v)+'",0) > -1');
- }else{
- self._append(self._getStr('this')+'.indexOf("'+self._toStr(f)+'",0) > -1');
- }
- self._setCommand(self.contains,f);
- self._resetNegate();
- return self;
- };
- this.groupBy=function(by,dir,type, datefmt){
- if(!self._hasData()){
- return null;
- }
- return self._getGroup(_data,by,dir,type, datefmt);
- };
- this.orderBy=function(by,dir,stype, dfmt){
- dir = dir === undefined || dir === null ? "a" :$.trim(dir.toString().toLowerCase());
- if(stype === null || stype === undefined) { stype = "text"; }
- if(dfmt === null || dfmt === undefined) { dfmt = "Y-m-d"; }
- if(dir=="desc"||dir=="descending"){dir="d";}
- if(dir=="asc"||dir=="ascending"){dir="a";}
- _sorting.push({by:by,dir:dir,type:stype, datefmt: dfmt});
- return self;
- };
- return self;
- };
- return new queryObject(source,null);
- },
- extend : function(methods) {
- $.extend($.fn.jqGrid,methods);
- if (!this.no_legacy_api) {
- $.fn.extend(methods);
- }
- }
- });
-
- $.fn.jqGrid = function( pin ) {
- if (typeof pin == 'string') {
- //var fn = $.fn.jqGrid[pin];
- var fn = $.jgrid.getAccessor($.fn.jqGrid,pin);
- if (!fn) {
- throw ("jqGrid - No such method: " + pin);
- }
- var args = $.makeArray(arguments).slice(1);
- return fn.apply(this,args);
- }
- return this.each( function() {
- if(this.grid) {return;}
-
- var p = $.extend(true,{
- url: "",
- height: 150,
- page: 1,
- rowNum: 20,
- rowTotal : null,
- records: 0,
- pager: "",
- pgbuttons: true,
- pginput: true,
- colModel: [],
- rowList: [],
- colNames: [],
- sortorder: "asc",
- sortname: "",
- datatype: "xml",
- mtype: "GET",
- altRows: false,
- selarrrow: [],
- savedRow: [],
- shrinkToFit: true,
- xmlReader: {},
- jsonReader: {},
- subGrid: false,
- subGridModel :[],
- reccount: 0,
- lastpage: 0,
- lastsort: 0,
- selrow: null,
- beforeSelectRow: null,
- onSelectRow: null,
- onSortCol: null,
- ondblClickRow: null,
- onRightClickRow: null,
- onPaging: null,
- onSelectAll: null,
- loadComplete: null,
- gridComplete: null,
- loadError: null,
- loadBeforeSend: null,
- afterInsertRow: null,
- beforeRequest: null,
- beforeProcessing : null,
- onHeaderClick: null,
- viewrecords: false,
- loadonce: false,
- multiselect: false,
- multikey: false,
- editurl: null,
- search: false,
- caption: "",
- hidegrid: true,
- hiddengrid: false,
- postData: {},
- userData: {},
- treeGrid : false,
- treeGridModel : 'nested',
- treeReader : {},
- treeANode : -1,
- ExpandColumn: null,
- tree_root_level : 0,
- 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"},
- forceFit : false,
- gridstate : "visible",
- cellEdit: false,
- cellsubmit: "remote",
- nv:0,
- loadui: "enable",
- toolbar: [false,""],
- scroll: false,
- multiboxonly : false,
- deselectAfterSort : true,
- scrollrows : false,
- autowidth: false,
- scrollOffset :18,
- cellLayout: 5,
- subGridWidth: 20,
- multiselectWidth: 20,
- gridview: false,
- rownumWidth: 25,
- rownumbers : false,
- pagerpos: 'center',
- recordpos: 'right',
- footerrow : false,
- userDataOnFooter : false,
- hoverrows : true,
- altclass : 'ui-priority-secondary',
- viewsortcols : [false,'vertical',true],
- resizeclass : '',
- autoencode : false,
- remapColumns : [],
- ajaxGridOptions :{},
- direction : "ltr",
- toppager: false,
- headertitles: false,
- scrollTimeout: 40,
- data : [],
- _index : {},
- grouping : false,
- groupingView : {groupField:[],groupOrder:[], groupText:[],groupColumnShow:[],groupSummary:[], showSummaryOnHide: false, sortitems:[], sortnames:[], groupDataSorted : false, summary:[],summaryval:[], plusicon: 'ui-icon-circlesmall-plus', minusicon: 'ui-icon-circlesmall-minus'},
- ignoreCase : false,
- cmTemplate : {},
- idPrefix : ""
- }, $.jgrid.defaults, pin || {});
- var grid={
- headers:[],
- cols:[],
- footers: [],
- dragStart: function(i,x,y) {
- this.resizing = { idx: i, startX: x.clientX, sOL : y[0]};
- this.hDiv.style.cursor = "col-resize";
- this.curGbox = $("#rs_m"+$.jgrid.jqID(p.id),"#gbox_"+$.jgrid.jqID(p.id));
- this.curGbox.css({display:"block",left:y[0],top:y[1],height:y[2]});
- if($.isFunction(p.resizeStart)) { p.resizeStart.call(this,x,i); }
- document.onselectstart=function(){return false;};
- },
- dragMove: function(x) {
- if(this.resizing) {
- var diff = x.clientX-this.resizing.startX,
- h = this.headers[this.resizing.idx],
- newWidth = p.direction === "ltr" ? h.width + diff : h.width - diff, hn, nWn;
- if(newWidth > 33) {
- this.curGbox.css({left:this.resizing.sOL+diff});
- if(p.forceFit===true ){
- hn = this.headers[this.resizing.idx+p.nv];
- nWn = p.direction === "ltr" ? hn.width - diff : hn.width + diff;
- if(nWn >33) {
- h.newWidth = newWidth;
- hn.newWidth = nWn;
- }
- } else {
- this.newWidth = p.direction === "ltr" ? p.tblwidth+diff : p.tblwidth-diff;
- h.newWidth = newWidth;
- }
- }
- }
- },
- dragEnd: function() {
- this.hDiv.style.cursor = "default";
- if(this.resizing) {
- var idx = this.resizing.idx,
- nw = this.headers[idx].newWidth || this.headers[idx].width;
- nw = parseInt(nw,10);
- this.resizing = false;
- $("#rs_m"+$.jgrid.jqID(p.id)).css("display","none");
- p.colModel[idx].width = nw;
- this.headers[idx].width = nw;
- this.headers[idx].el.style.width = nw + "px";
- this.cols[idx].style.width = nw+"px";
- if(this.footers.length>0) {this.footers[idx].style.width = nw+"px";}
- if(p.forceFit===true){
- nw = this.headers[idx+p.nv].newWidth || this.headers[idx+p.nv].width;
- this.headers[idx+p.nv].width = nw;
- this.headers[idx+p.nv].el.style.width = nw + "px";
- this.cols[idx+p.nv].style.width = nw+"px";
- if(this.footers.length>0) {this.footers[idx+p.nv].style.width = nw+"px";}
- p.colModel[idx+p.nv].width = nw;
- } else {
- p.tblwidth = this.newWidth || p.tblwidth;
- $('table:first',this.bDiv).css("width",p.tblwidth+"px");
- $('table:first',this.hDiv).css("width",p.tblwidth+"px");
- this.hDiv.scrollLeft = this.bDiv.scrollLeft;
- if(p.footerrow) {
- $('table:first',this.sDiv).css("width",p.tblwidth+"px");
- this.sDiv.scrollLeft = this.bDiv.scrollLeft;
- }
- }
- if($.isFunction(p.resizeStop)) { p.resizeStop.call(this,nw,idx); }
- }
- this.curGbox = null;
- document.onselectstart=function(){return true;};
- },
- populateVisible: function() {
- if (grid.timer) { clearTimeout(grid.timer); }
- grid.timer = null;
- var dh = $(grid.bDiv).height();
- if (!dh) { return; }
- var table = $("table:first", grid.bDiv);
- var rows, rh;
- if(table[0].rows.length) {
- try {
- rows = table[0].rows[1];
- rh = rows ? $(rows).outerHeight() || grid.prevRowHeight : grid.prevRowHeight;
- } catch (pv) {
- rh = grid.prevRowHeight;
- }
- }
- if (!rh) { return; }
- grid.prevRowHeight = rh;
- var rn = p.rowNum;
- var scrollTop = grid.scrollTop = grid.bDiv.scrollTop;
- var ttop = Math.round(table.position().top) - scrollTop;
- var tbot = ttop + table.height();
- var div = rh * rn;
- var page, npage, empty;
- if ( tbot < dh && ttop <= 0 &&
- (p.lastpage===undefined||parseInt((tbot + scrollTop + div - 1) / div,10) <= p.lastpage))
- {
- npage = parseInt((dh - tbot + div - 1) / div,10);
- if (tbot >= 0 || npage < 2 || p.scroll === true) {
- page = Math.round((tbot + scrollTop) / div) + 1;
- ttop = -1;
- } else {
- ttop = 1;
- }
- }
- if (ttop > 0) {
- page = parseInt(scrollTop / div,10) + 1;
- npage = parseInt((scrollTop + dh) / div,10) + 2 - page;
- empty = true;
- }
- if (npage) {
- if (p.lastpage && page > p.lastpage || p.lastpage==1 || (page === p.page && page===p.lastpage) ) {
- return;
- }
- if (grid.hDiv.loading) {
- grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
- } else {
- p.page = page;
- if (empty) {
- grid.selectionPreserver(table[0]);
- grid.emptyRows(grid.bDiv,false, false);
- }
- grid.populate(npage);
- }
- }
- },
- scrollGrid: function( e ) {
- if(p.scroll) {
- var scrollTop = grid.bDiv.scrollTop;
- if(grid.scrollTop === undefined) { grid.scrollTop = 0; }
- if (scrollTop != grid.scrollTop) {
- grid.scrollTop = scrollTop;
- if (grid.timer) { clearTimeout(grid.timer); }
- grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
- }
- }
- grid.hDiv.scrollLeft = grid.bDiv.scrollLeft;
- if(p.footerrow) {
- grid.sDiv.scrollLeft = grid.bDiv.scrollLeft;
- }
- if( e ) { e.stopPropagation(); }
- },
- selectionPreserver : function(ts) {
- var p = ts.p;
- var sr = p.selrow, sra = p.selarrrow ? $.makeArray(p.selarrrow) : null;
- var left = ts.grid.bDiv.scrollLeft;
- var complete = p.gridComplete;
- p.gridComplete = function() {
- p.selrow = null;
- p.selarrrow = [];
- if(p.multiselect && sra && sra.length>0) {
- for(var i=0;i<sra.length;i++){
- if (sra[i] != sr) {
- $(ts).jqGrid("setSelection",sra[i],false);
- }
- }
- }
- if (sr) {
- $(ts).jqGrid("setSelection",sr,false);
- }
- ts.grid.bDiv.scrollLeft = left;
- p.gridComplete = complete;
- if (p.gridComplete) {
- complete();
- }
- };
- }
- };
- if(this.tagName.toUpperCase()!='TABLE') {
- alert("Element is not a table");
- return;
- }
- $(this).empty().attr("tabindex","1");
- this.p = p ;
- this.p.useProp = !!$.fn.prop;
- var i, dir,ts;
- if(this.p.colNames.length === 0) {
- for (i=0;i<this.p.colModel.length;i++){
- this.p.colNames[i] = this.p.colModel[i].label || this.p.colModel[i].name;
- }
- }
- if( this.p.colNames.length !== this.p.colModel.length ) {
- alert($.jgrid.errors.model);
- return;
- }
- var gv = $("<div class='ui-jqgrid-view'></div>"), ii,
- isMSIE = $.browser.msie ? true:false,
- isSafari = $.browser.webkit || $.browser.safari ? true : false;
- ts = this;
- ts.p.direction = $.trim(ts.p.direction.toLowerCase());
- if($.inArray(ts.p.direction,["ltr","rtl"]) == -1) { ts.p.direction = "ltr"; }
- dir = ts.p.direction;
-
- $(gv).insertBefore(this);
- $(this).appendTo(gv).removeClass("scroll");
- var eg = $("<div class='ui-jqgrid ui-widget ui-widget-content ui-corner-all'></div>");
- $(eg).insertBefore(gv).attr({"id" : "gbox_"+this.id,"dir":dir});
- $(gv).appendTo(eg).attr("id","gview_"+this.id);
- if (isMSIE && $.browser.version <= 6) {
- ii = '<iframe style="display:block;position:absolute;z-index:-1;filter:Alpha(Opacity=\'0\');" src="javascript:false;"></iframe>';
- } else { ii="";}
- $("<div class='ui-widget-overlay jqgrid-overlay' id='lui_"+this.id+"'></div>").append(ii).insertBefore(gv);
- $("<div class='loading ui-state-default ui-state-active' id='load_"+this.id+"'>"+this.p.loadtext+"</div>").insertBefore(gv);
- $(this).attr({cellspacing:"0",cellpadding:"0",border:"0","role":"grid","aria-multiselectable":!!this.p.multiselect,"aria-labelledby":"gbox_"+this.id});
- var sortkeys = ["shiftKey","altKey","ctrlKey"],
- intNum = function(val,defval) {
- val = parseInt(val,10);
- if (isNaN(val)) { return defval ? defval : 0;}
- else {return val;}
- },
- formatCol = function (pos, rowInd, tv, rawObject, rowId, rdata){
- var cm = ts.p.colModel[pos],
- ral = cm.align, result="style=\"", clas = cm.classes, nm = cm.name, celp, acp=[];
- if(ral) { result += "text-align:"+ral+";"; }
- if(cm.hidden===true) { result += "display:none;"; }
- if(rowInd===0) {
- result += "width: "+grid.headers[pos].width+"px;";
- } else if (cm.cellattr && $.isFunction(cm.cellattr))
- {
- celp = cm.cellattr.call(ts, rowId, tv, rawObject, cm, rdata);
- if(celp && typeof(celp) === "string") {
- celp = celp.replace(/style/i,'style').replace(/title/i,'title');
- if(celp.indexOf('title') > -1) { cm.title=false;}
- if(celp.indexOf('class') > -1) { clas = undefined;}
- acp = celp.split("style");
- if(acp.length === 2 ) {
- acp[1] = $.trim(acp[1].replace("=",""));
- if(acp[1].indexOf("'") === 0 || acp[1].indexOf('"') === 0) {
- acp[1] = acp[1].substring(1);
- }
- result += acp[1].replace(/'/gi,'"');
- } else {
- result += "\"";
- }
- }
- }
- if(!acp.length) { acp[0] = ""; result += "\"";}
- result += (clas !== undefined ? (" class=\""+clas+"\"") :"") + ((cm.title && tv) ? (" title=\""+$.jgrid.stripHtml(tv)+"\"") :"");
- result += " aria-describedby=\""+ts.p.id+"_"+nm+"\"";
- return result + acp[0];
- },
- cellVal = function (val) {
- return val === undefined || val === null || val === "" ? " " : (ts.p.autoencode ? $.jgrid.htmlEncode(val) : val+"");
- },
- formatter = function (rowId, cellval , colpos, rwdat, _act){
- var cm = ts.p.colModel[colpos],v;
- if(typeof cm.formatter !== 'undefined') {
- var opts= {rowId: rowId, colModel:cm, gid:ts.p.id, pos:colpos };
- if($.isFunction( cm.formatter ) ) {
- v = cm.formatter.call(ts,cellval,opts,rwdat,_act);
- } else if($.fmatter){
- v = $.fn.fmatter(cm.formatter, cellval,opts, rwdat, _act);
- } else {
- v = cellVal(cellval);
- }
- } else {
- v = cellVal(cellval);
- }
- return v;
- },
- addCell = function(rowId,cell,pos,irow, srvr) {
- var v,prp;
- v = formatter(rowId,cell,pos,srvr,'add');
- prp = formatCol( pos,irow, v, srvr, rowId, true);
- return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
- },
- addMulti = function(rowid,pos,irow){
- var v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+ts.p.id+"_"+rowid+"\" class=\"cbox\" name=\"jqg_"+ts.p.id+"_"+rowid+"\"/>",
- prp = formatCol( pos,irow,'',null, rowid, true);
- return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
- },
- addRowNum = function (pos,irow,pG,rN) {
- var v = (parseInt(pG,10)-1)*parseInt(rN,10)+1+irow,
- prp = formatCol( pos,irow,v, null, irow, true);
- return "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" "+prp+">"+v+"</td>";
- },
- reader = function (datatype) {
- var field, f=[], j=0, i;
- for(i =0; i<ts.p.colModel.length; i++){
- field = ts.p.colModel[i];
- if (field.name !== 'cb' && field.name !=='subgrid' && field.name !=='rn') {
- if(datatype == "local") {
- f[j] = field.name;
- } else {
- f[j] = (datatype=="xml") ? field.xmlmap || field.name : field.jsonmap || field.name;
- }
- j++;
- }
- }
- return f;
- },
- orderedCols = function (offset) {
- var order = ts.p.remapColumns;
- if (!order || !order.length) {
- order = $.map(ts.p.colModel, function(v,i) { return i; });
- }
- if (offset) {
- order = $.map(order, function(v) { return v<offset?null:v-offset; });
- }
- return order;
- },
- emptyRows = function (parent, scroll, locdata) {
- if(ts.p.deepempty) {$("#"+$.jgrid.jqID(ts.p.id)+" tbody:first tr:gt(0)").remove();}
- else {
- var trf = $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first tr:first")[0];
- $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").empty().append(trf);
- }
- if (scroll && ts.p.scroll) {
- $(">div:first", parent).css({height:"auto"}).children("div:first").css({height:0,display:"none"});
- parent.scrollTop = 0;
- }
- if(locdata === true) {
- if(ts.p.treeGrid === true ) {
- ts.p.data = []; ts.p._index = {};
- }
- }
- },
- refreshIndex = function() {
- var datalen = ts.p.data.length, idname, i, val,
- ni = ts.p.rownumbers===true ? 1 :0,
- gi = ts.p.multiselect ===true ? 1 :0,
- si = ts.p.subGrid===true ? 1 :0;
-
- if(ts.p.keyIndex === false || ts.p.loadonce === true) {
- idname = ts.p.localReader.id;
- } else {
- idname = ts.p.colModel[ts.p.keyIndex+gi+si+ni].name;
- }
- for(i =0;i < datalen; i++) {
- val = $.jgrid.getAccessor(ts.p.data[i],idname);
- ts.p._index[val] = i;
- }
- },
- addXmlData = function (xml,t, rcnt, more, adjust) {
- var startReq = new Date(),
- locdata = (ts.p.datatype != "local" && ts.p.loadonce) || ts.p.datatype == "xmlstring",
- xmlid = "_id_",
- frd = ts.p.datatype == "local" ? "local" : "xml";
- if(locdata) {
- ts.p.data = [];
- ts.p._index = {};
- ts.p.localReader.id = xmlid;
- }
- ts.p.reccount = 0;
- if($.isXMLDoc(xml)) {
- if(ts.p.treeANode===-1 && !ts.p.scroll) {
- emptyRows(t,false, true);
- rcnt=1;
- } else { rcnt = rcnt > 1 ? rcnt :1; }
- } else { return; }
- 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;
- if(!ts.p.xmlReader.repeatitems) {f = reader(frd);}
- if( ts.p.keyIndex===false) {
- idn = ts.p.xmlReader.id;
- } else {
- idn = ts.p.keyIndex;
- }
- if(f.length>0 && !isNaN(idn)) {
- if (ts.p.remapColumns && ts.p.remapColumns.length) {
- idn = $.inArray(idn, ts.p.remapColumns);
- }
- idn=f[idn];
- }
- if( (idn+"").indexOf("[") === -1 ) {
- if (f.length) {
- getId = function( trow, k) {return $(idn,trow).text() || k;};
- } else {
- getId = function( trow, k) {return $(ts.p.xmlReader.cell,trow).eq(idn).text() || k;};
- }
- }
- else {
- getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;};
- }
- ts.p.userData = {};
- $(ts.p.xmlReader.page,xml).each(function() {ts.p.page = this.textContent || this.text || 0; });
- $(ts.p.xmlReader.total,xml).each(function() {ts.p.lastpage = this.textContent || this.text; if(ts.p.lastpage===undefined) { ts.p.lastpage=1; } } );
- $(ts.p.xmlReader.records,xml).each(function() {ts.p.records = this.textContent || this.text || 0; } );
- $(ts.p.xmlReader.userdata,xml).each(function() {ts.p.userData[this.getAttribute("name")]= $(this).text();});
- var gxml = $(ts.p.xmlReader.root+" "+ts.p.xmlReader.row,xml);
- if (!gxml) { gxml = []; }
- var gl = gxml.length, j=0, grpdata={}, rn;
- if(gxml && gl){
- rn = parseInt(ts.p.rowNum,10);
- var br=ts.p.scroll?$.jgrid.randId():1,altr;
- if (adjust) { rn *= adjust+1; }
- var afterInsRow = $.isFunction(ts.p.afterInsertRow), hiderow="";
- if(ts.p.grouping && ts.p.groupingView.groupCollapse === true) {
- hiderow = " style=\"display:none;\"";
- }
- while (j<gl) {
- xmlr = gxml[j];
- rid = getId(xmlr,br+j);
- rid = ts.p.idPrefix + rid;
- altr = rcnt === 0 ? 0 : rcnt+1;
- cn1 = (altr+j)%2 == 1 ? cn : '';
- rowData.push( "<tr"+hiderow+" id=\""+rid+"\" tabindex=\"-1\" role=\"row\" class =\"ui-widget-content jqgrow ui-row-"+ts.p.direction+""+cn1+"\">" );
- if(ts.p.rownumbers===true) {
- rowData.push( addRowNum(0,j,ts.p.page,ts.p.rowNum) );
- ni=1;
- }
- if(ts.p.multiselect===true) {
- rowData.push( addMulti(rid,ni,j) );
- gi=1;
- }
- if (ts.p.subGrid===true) {
- rowData.push( $(ts).jqGrid("addSubGridCell",gi+ni,j+rcnt) );
- si= 1;
- }
- if(ts.p.xmlReader.repeatitems){
- if (!F) { F=orderedCols(gi+si+ni); }
- var cells = $(ts.p.xmlReader.cell,xmlr);
- $.each(F, function (k) {
- var cell = cells[this];
- if (!cell) { return false; }
- v = cell.textContent || cell.text;
- rd[ts.p.colModel[k+gi+si+ni].name] = v;
- rowData.push( addCell(rid,v,k+gi+si+ni,j+rcnt,xmlr) );
- });
- } else {
- for(i = 0; i < f.length;i++) {
- v = $(f[i],xmlr).text();
- rd[ts.p.colModel[i+gi+si+ni].name] = v;
- rowData.push( addCell(rid, v, i+gi+si+ni, j+rcnt, xmlr) );
- }
- }
- rowData.push("</tr>");
- if(ts.p.grouping) {
- var grlen = ts.p.groupingView.groupField.length, grpitem = [];
- for(var z=0;z<grlen;z++) {
- grpitem.push(rd[ts.p.groupingView.groupField[z]]);
- }
- grpdata = $(ts).jqGrid('groupingPrepare',rowData, grpitem, grpdata, rd);
- rowData = [];
- }
- if(locdata || ts.p.treeGrid === true) {
- rd[xmlid] = rid;
- ts.p.data.push(rd);
- ts.p._index[rid] = ts.p.data.length-1;
- }
- if(ts.p.gridview === false ) {
- $("tbody:first",t).append(rowData.join(''));
- if(afterInsRow) {ts.p.afterInsertRow.call(ts,rid,rd,xmlr);}
- rowData=[];
- }
- rd={};
- ir++;
- j++;
- if(ir==rn) {break;}
- }
- }
- if(ts.p.gridview === true) {
- fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
- if(ts.p.grouping) {
- $(ts).jqGrid('groupingRender',grpdata,ts.p.colModel.length);
- grpdata = null;
- } else if(ts.p.treeGrid === true && fpos > 0) {
- $(ts.rows[fpos]).after(rowData.join(''));
- } else {
- $("tbody:first",t).append(rowData.join(''));
- }
- }
- if(ts.p.subGrid === true ) {
- try {$(ts).jqGrid("addSubGrid",gi+ni);} catch (_){}
- }
- ts.p.totaltime = new Date() - startReq;
- if(ir>0) { if(ts.p.records===0) { ts.p.records=gl;} }
- rowData =null;
- if( ts.p.treeGrid === true) {
- try {$(ts).jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
- }
- if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
- ts.p.reccount=ir;
- ts.p.treeANode = -1;
- if(ts.p.userDataOnFooter) { $(ts).jqGrid("footerData","set",ts.p.userData,true); }
- if(locdata) {
- ts.p.records = gl;
- ts.p.lastpage = Math.ceil(gl/ rn);
- }
- if (!more) { ts.updatepager(false,true); }
- if(locdata) {
- while (ir<gl) {
- xmlr = gxml[ir];
- rid = getId(xmlr,ir);
- rid = ts.p.idPrefix + rid;
- if(ts.p.xmlReader.repeatitems){
- if (!F) { F=orderedCols(gi+si+ni); }
- var cells2 = $(ts.p.xmlReader.cell,xmlr);
- $.each(F, function (k) {
- var cell = cells2[this];
- if (!cell) { return false; }
- v = cell.textContent || cell.text;
- rd[ts.p.colModel[k+gi+si+ni].name] = v;
- });
- } else {
- for(i = 0; i < f.length;i++) {
- v = $(f[i],xmlr).text();
- rd[ts.p.colModel[i+gi+si+ni].name] = v;
- }
- }
- rd[xmlid] = rid;
- ts.p.data.push(rd);
- ts.p._index[rid] = ts.p.data.length-1;
- rd = {};
- ir++;
- }
- }
- },
- addJSONData = function(data,t, rcnt, more, adjust) {
- var startReq = new Date();
- if(data) {
- if(ts.p.treeANode === -1 && !ts.p.scroll) {
- emptyRows(t,false, true);
- rcnt=1;
- } else { rcnt = rcnt > 1 ? rcnt :1; }
- } else { return; }
-
- var dReader, locid = "_id_", frd,
- locdata = (ts.p.datatype != "local" && ts.p.loadonce) || ts.p.datatype == "jsonstring";
- if(locdata) { ts.p.data = []; ts.p._index = {}; ts.p.localReader.id = locid;}
- ts.p.reccount = 0;
- if(ts.p.datatype == "local") {
- dReader = ts.p.localReader;
- frd= 'local';
- } else {
- dReader = ts.p.jsonReader;
- frd='json';
- }
- 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;
- ts.p.page = $.jgrid.getAccessor(data,dReader.page) || 0;
- lp = $.jgrid.getAccessor(data,dReader.total);
- ts.p.lastpage = lp === undefined ? 1 : lp;
- ts.p.records = $.jgrid.getAccessor(data,dReader.records) || 0;
- ts.p.userData = $.jgrid.getAccessor(data,dReader.userdata) || {};
- if(!dReader.repeatitems) {
- F = f = reader(frd);
- }
- if( ts.p.keyIndex===false ) {
- idn = dReader.id;
- } else {
- idn = ts.p.keyIndex;
- }
- if(f.length>0 && !isNaN(idn)) {
- if (ts.p.remapColumns && ts.p.remapColumns.length) {
- idn = $.inArray(idn, ts.p.remapColumns);
- }
- idn=f[idn];
- }
- drows = $.jgrid.getAccessor(data,dReader.root);
- if (!drows) { drows = []; }
- len = drows.length; i=0;
- var rn = parseInt(ts.p.rowNum,10),br=ts.p.scroll?$.jgrid.randId():1, altr;
- if (adjust) { rn *= adjust+1; }
- var afterInsRow = $.isFunction(ts.p.afterInsertRow), grpdata={}, hiderow="";
- if(ts.p.grouping && ts.p.groupingView.groupCollapse === true) {
- hiderow = " style=\"display:none;\"";
- }
- while (i<len) {
- cur = drows[i];
- idr = $.jgrid.getAccessor(cur,idn);
- if(idr === undefined) {
- idr = br+i;
- if(f.length===0){
- if(dReader.cell){
- var ccur = $.jgrid.getAccessor(cur,dReader.cell);
- idr = ccur[idn] || idr;
- ccur=null;
- }
- }
- }
- idr = ts.p.idPrefix + idr;
- altr = rcnt === 1 ? 0 : rcnt;
- cn1 = (altr+i)%2 == 1 ? cn : '';
- rowData.push("<tr"+hiderow+" id=\""+ idr +"\" tabindex=\"-1\" role=\"row\" class= \"ui-widget-content jqgrow ui-row-"+ts.p.direction+""+cn1+"\">");
- if(ts.p.rownumbers===true) {
- rowData.push( addRowNum(0,i,ts.p.page,ts.p.rowNum) );
- ni=1;
- }
- if(ts.p.multiselect){
- rowData.push( addMulti(idr,ni,i) );
- gi = 1;
- }
- if (ts.p.subGrid) {
- rowData.push( $(ts).jqGrid("addSubGridCell",gi+ni,i+rcnt) );
- si= 1;
- }
- if (dReader.repeatitems) {
- if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell);}
- if (!F) { F=orderedCols(gi+si+ni); }
- }
- for (j=0;j<F.length;j++) {
- v = $.jgrid.getAccessor(cur,F[j]);
- rowData.push( addCell(idr,v,j+gi+si+ni,i+rcnt,cur) );
- rd[ts.p.colModel[j+gi+si+ni].name] = v;
- }
- rowData.push( "</tr>" );
- if(ts.p.grouping) {
- var grlen = ts.p.groupingView.groupField.length, grpitem = [];
- for(var z=0;z<grlen;z++) {
- grpitem.push(rd[ts.p.groupingView.groupField[z]]);
- }
- grpdata = $(ts).jqGrid('groupingPrepare',rowData, grpitem, grpdata, rd);
- rowData = [];
- }
- if(locdata || ts.p.treeGrid===true) {
- rd[locid] = idr;
- ts.p.data.push(rd);
- ts.p._index[idr] = ts.p.data.length-1;
- }
- if(ts.p.gridview === false ) {
- $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join(''));
- if(afterInsRow) {ts.p.afterInsertRow.call(ts,idr,rd,cur);}
- rowData=[];//ari=0;
- }
- rd={};
- ir++;
- i++;
- if(ir==rn) { break; }
- }
- if(ts.p.gridview === true ) {
- fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
- if(ts.p.grouping) {
- $(ts).jqGrid('groupingRender',grpdata,ts.p.colModel.length);
- grpdata = null;
- } else if(ts.p.treeGrid === true && fpos > 0) {
- $(ts.rows[fpos]).after(rowData.join(''));
- } else {
- $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join(''));
- }
- }
- if(ts.p.subGrid === true ) {
- try { $(ts).jqGrid("addSubGrid",gi+ni);} catch (_){}
- }
- ts.p.totaltime = new Date() - startReq;
- if(ir>0) {
- if(ts.p.records===0) { ts.p.records=len; }
- }
- rowData = null;
- if( ts.p.treeGrid === true) {
- try {$(ts).jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
- }
- if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
- ts.p.reccount=ir;
- ts.p.treeANode = -1;
- if(ts.p.userDataOnFooter) { $(ts).jqGrid("footerData","set",ts.p.userData,true); }
- if(locdata) {
- ts.p.records = len;
- ts.p.lastpage = Math.ceil(len/ rn);
- }
- if (!more) { ts.updatepager(false,true); }
- if(locdata) {
- while (ir<len && drows[ir]) {
- cur = drows[ir];
- idr = $.jgrid.getAccessor(cur,idn);
- if(idr === undefined) {
- idr = br+ir;
- if(f.length===0){
- if(dReader.cell){
- var ccur2 = $.jgrid.getAccessor(cur,dReader.cell);
- idr = ccur2[idn] || idr;
- ccur2=null;
- }
- }
- }
- if(cur) {
- idr = ts.p.idPrefix + idr;
- if (dReader.repeatitems) {
- if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell);}
- if (!F) { F=orderedCols(gi+si+ni); }
- }
-
- for (j=0;j<F.length;j++) {
- v = $.jgrid.getAccessor(cur,F[j]);
- rd[ts.p.colModel[j+gi+si+ni].name] = v;
- }
- rd[locid] = idr;
- ts.p.data.push(rd);
- ts.p._index[idr] = ts.p.data.length-1;
- rd = {};
- }
- ir++;
- }
- }
- },
- addLocalData = function() {
- var st, fndsort=false, cmtypes={}, grtypes=[], grindexes=[], srcformat, sorttype, newformat;
- if(!$.isArray(ts.p.data)) {
- return;
- }
- var grpview = ts.p.grouping ? ts.p.groupingView : false;
- $.each(ts.p.colModel,function(i,v){
- sorttype = this.sorttype || "text";
- if(sorttype == "date" || sorttype == "datetime") {
- if(this.formatter && typeof(this.formatter) === 'string' && this.formatter == 'date') {
- if(this.formatoptions && this.formatoptions.srcformat) {
- srcformat = this.formatoptions.srcformat;
- } else {
- srcformat = $.jgrid.formatter.date.srcformat;
- }
- if(this.formatoptions && this.formatoptions.newformat) {
- newformat = this.formatoptions.newformat;
- } else {
- newformat = $.jgrid.formatter.date.newformat;
- }
- } else {
- srcformat = newformat = this.datefmt || "Y-m-d";
- }
- cmtypes[this.name] = {"stype": sorttype, "srcfmt": srcformat,"newfmt":newformat};
- } else {
- cmtypes[this.name] = {"stype": sorttype, "srcfmt":'',"newfmt":''};
- }
- if(ts.p.grouping && this.name == grpview.groupField[0]) {
- var grindex = this.name;
- if (typeof this.index != 'undefined') {
- grindex = this.index;
- }
- grtypes[0] = cmtypes[grindex];
- grindexes.push(grindex);
- }
- if(!fndsort && (this.index == ts.p.sortname || this.name == ts.p.sortname)){
- st = this.name; // ???
- fndsort = true;
- }
- });
- if(ts.p.treeGrid) {
- $(ts).jqGrid("SortTree", st, ts.p.sortorder, cmtypes[st].stype, cmtypes[st].srcfmt);
- return;
- }
- var compareFnMap = {
- 'eq':function(queryObj, op) {return queryObj.equals;},
- 'ne':function(queryObj,op) {return queryObj.notEquals;},
- 'lt':function(queryObj,op) {return queryObj.less;},
- 'le':function(queryObj,op) {return queryObj.lessOrEquals;},
- 'gt':function(queryObj,op) {return queryObj.greater;},
- 'ge':function(queryObj,op) {return queryObj.greaterOrEquals;},
- 'cn':function(queryObj,op) {return queryObj.contains;},
- 'nc':function(queryObj,op) {return op === "OR" ? queryObj.orNot().contains : queryObj.andNot().contains;},
- 'bw':function(queryObj,op) {return queryObj.startsWith;},
- 'bn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().startsWith : queryObj.andNot().startsWith;},
- 'en':function(queryObj,op) {return op === "OR" ? queryObj.orNot().endsWith : queryObj.andNot().endsWith;},
- 'ew':function(queryObj,op) {return queryObj.endsWith;},
- 'ni':function(queryObj,op) {return op === "OR" ? queryObj.orNot().equals : queryObj.andNot().equals;},
- 'in':function(queryObj,op) {return queryObj.equals;},
- 'nu':function(queryObj,op) {return queryObj.isNull;},
- 'nn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().isNull : queryObj.andNot().isNull;}
-
- },
- query = $.jgrid.from(ts.p.data);
- if (ts.p.ignoreCase) { query = query.ignoreCase(); }
- function tojLinq ( group ) {
- var s = 0, index, gor, ror, opr, rule;
- if (group.groups !== undefined) {
- gor = group.groups.length && group.groupOp.toString().toUpperCase() === "OR";
- if (gor) {
- query.orBegin();
- }
- for (index = 0; index < group.groups.length; index++) {
- if (s > 0 && gor) {
- query.or();
- }
- try {
- tojLinq(group.groups[index]);
- } catch (e) {alert(e);}
- s++;
- }
- if (gor) {
- query.orEnd();
- }
- }
- if (group.rules !== undefined) {
- if(s>0) {
- var result = query.select();
- query = $.jgrid.from( result);
- if (ts.p.ignoreCase) { query = query.ignoreCase(); }
- }
- try{
- ror = group.rules.length && group.groupOp.toString().toUpperCase() === "OR";
- if (ror) {
- query.orBegin();
- }
- for (index = 0; index < group.rules.length; index++) {
- rule = group.rules[index];
- opr = group.groupOp.toString().toUpperCase();
- if (compareFnMap[rule.op] && rule.field ) {
- if(s > 0 && opr && opr === "OR") {
- query = query.or();
- }
- query = compareFnMap[rule.op](query, opr)(rule.field, rule.data, cmtypes[rule.field]);
- }
- s++;
- }
- if (ror) {
- query.orEnd();
- }
- } catch (g) {alert(g);}
- }
- }
-
- if (ts.p.search === true) {
- var srules = ts.p.postData.filters;
- if(srules) {
- if(typeof srules == "string") { srules = $.jgrid.parse(srules);}
- tojLinq( srules );
- } else {
- try {
- query = compareFnMap[ts.p.postData.searchOper](query)(ts.p.postData.searchField, ts.p.postData.searchString,cmtypes[ts.p.postData.searchField]);
- } catch (se){}
- }
- }
- if(ts.p.grouping) {
- query.orderBy(grindexes,grpview.groupOrder[0],grtypes[0].stype, grtypes[0].srcfmt);
- grpview.groupDataSorted = true;
- }
- if (st && ts.p.sortorder && fndsort) {
- if(ts.p.sortorder.toUpperCase() == "DESC") {
- query.orderBy(ts.p.sortname, "d", cmtypes[st].stype, cmtypes[st].srcfmt);
- } else {
- query.orderBy(ts.p.sortname, "a", cmtypes[st].stype, cmtypes[st].srcfmt);
- }
- }
- var queryResults = query.select(),
- recordsperpage = parseInt(ts.p.rowNum,10),
- total = queryResults.length,
- page = parseInt(ts.p.page,10),
- totalpages = Math.ceil(total / recordsperpage),
- retresult = {};
- queryResults = queryResults.slice( (page-1)*recordsperpage , page*recordsperpage );
- query = null;
- cmtypes = null;
- retresult[ts.p.localReader.total] = totalpages;
- retresult[ts.p.localReader.page] = page;
- retresult[ts.p.localReader.records] = total;
- retresult[ts.p.localReader.root] = queryResults;
- retresult[ts.p.localReader.userdata] = ts.p.userData;
- queryResul…
Large files files are truncated, but you can click here to view the full file