/script/jquery.jqGrid.src.js
JavaScript | 13540 lines | 7316 code | 173 blank | 6051 comment | 2046 complexity | 0730e1e62e5660f98d075018b7f27c03 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- /**
- *
- * @license Guriddo jqGrid JS - v4.8.2 - 2015-03-24
- * Copyright(c) 2008, Tony Tomov, tony@trirand.com
- *
- * License: http://guriddo.net/?page_id=103334
- */
- (function( factory ) {
- "use strict";
- if ( typeof define === "function" && define.amd ) {
- // AMD. Register as an anonymous module.
- define([
- "jquery"
- ], factory );
- } else {
- // Browser globals
- factory( jQuery );
- }
- }(function( $ ) {
- "use strict";
- //module begin
- $.jgrid = $.jgrid || {};
- if(!$.jgrid.hasOwnProperty("defaults")) {
- $.jgrid.defaults = {};
- }
- $.extend($.jgrid,{
- version : "4.8.2",
- 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, ">");
- },
- template : function(format){ //jqgformat
- var args = $.makeArray(arguments).slice(1), j, al = args.length;
- if(format==null) { format = ""; }
- return format.replace(/\{([\w\-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g, function(m,i){
- if(!isNaN(parseInt(i,10))) {
- return args[parseInt(i,10)];
- }
- for(j=0; j < al;j++) {
- if($.isArray(args[j])) {
- var nmarr = args[ j ],
- k = nmarr.length;
- while(k--) {
- if(i===nmarr[k].nm) {
- return nmarr[k].v;
- }
- }
- }
- }
- });
- },
- msie : navigator.appName === 'Microsoft Internet Explorer',
- msiever : function () {
- var rv = -1;
- var ua = navigator.userAgent;
- var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
- if (re.exec(ua) != null) {
- rv = parseFloat( RegExp.$1 );
- }
- return rv;
- },
- 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 ($.jgrid.msie) { return $.inArray(c, c.parentNode.cells); }
- return c.cellIndex;
- },
- stripHtml : function(v) {
- v = String(v);
- var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
- if (v) {
- v = v.replace(regexp,"");
- return (v && v !== ' ' && v !== ' ') ? v.replace(/\"/g,"'") : "";
- }
- return v;
- },
- stripPref : function (pref, id) {
- var obj = $.type( pref );
- if( obj === "string" || obj === "number") {
- pref = String(pref);
- id = pref !== "" ? String(id).replace(String(pref), "") : id;
- }
- return id;
- },
- 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, newformat, opts) {
- var token = /\\.|[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g,
- timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
- timezoneClip = /[^-+\dA-Z]/g,
- msDateRegExp = new RegExp("^\/Date\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\)\/$"),
- msMatch = ((typeof date === 'string') ? date.match(msDateRegExp): null),
- pad = function (value, length) {
- value = String(value);
- length = parseInt(length,10) || 2;
- while (value.length < length) { value = '0' + value; }
- return value;
- },
- ts = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0, u:0},
- timestamp=0, dM, k,hl,
- h12to24 = function(ampm, h){
- if (ampm === 0){ if (h === 12) { h = 0;} }
- else { if (h !== 12) { h += 12; } }
- return h;
- },
- offset =0;
- if(opts === undefined) {
- opts = $.jgrid.getRegional(this, "formatter.date");//$.jgrid.formatter.date;
- }
- // old lang files
- if(opts.parseRe === undefined ) {
- opts.parseRe = /[#%\\\/:_;.,\t\s-]/;
- }
- if( opts.masks.hasOwnProperty(format) ) { format = opts.masks[format]; }
- if(date && date != null) {
- if( !isNaN( date - 0 ) && String(format).toLowerCase() === "u") {
- //Unix timestamp
- timestamp = new Date( parseFloat(date)*1000 );
- } else if(date.constructor === Date) {
- timestamp = date;
- // Microsoft date format support
- } else if( msMatch !== null ) {
- timestamp = new Date(parseInt(msMatch[1], 10));
- if (msMatch[3]) {
- offset = Number(msMatch[5]) * 60 + Number(msMatch[6]);
- offset *= ((msMatch[4] === '-') ? 1 : -1);
- offset -= timestamp.getTimezoneOffset();
- timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
- }
- } else {
- //Support ISO8601Long that have Z at the end to indicate UTC timezone
- if(opts.srcformat === 'ISO8601Long' && date.charAt(date.length - 1) === 'Z') {
- offset -= (new Date()).getTimezoneOffset();
- }
- date = String(date).replace(/\T/g,"#").replace(/\t/,"%").split(opts.parseRe);
- format = format.replace(/\T/g,"#").replace(/\t/,"%").split(opts.parseRe);
- // parsing for month names
- for(k=0,hl=format.length;k<hl;k++){
- switch ( format[k] ) {
- case 'M':
- dM = $.inArray(date[k],opts.monthNames);
- if(dM !== -1 && dM < 12){date[k] = dM+1; ts.m = date[k];}
- break;
- case 'F':
- dM = $.inArray(date[k],opts.monthNames,12);
- if(dM !== -1 && dM > 11){date[k] = dM+1-12; ts.m = date[k];}
- break;
- case 'n':
- format[k] = 'm';
- break;
- case 'j':
- format[k] = 'd';
- break;
- case 'a':
- dM = $.inArray(date[k],opts.AmPm);
- if(dM !== -1 && dM < 2 && date[k] === opts.AmPm[dM]){
- date[k] = dM;
- ts.h = h12to24(date[k], ts.h);
- }
- break;
- case 'A':
- dM = $.inArray(date[k],opts.AmPm);
- if(dM !== -1 && dM > 1 && date[k] === opts.AmPm[dM]){
- date[k] = dM-2;
- ts.h = h12to24(date[k], ts.h);
- }
- break;
- case 'g':
- ts.h = parseInt(date[k], 10);
- break;
- }
- if(date[k] !== undefined) {
- ts[format[k].toLowerCase()] = parseInt(date[k],10);
- }
- }
- if(ts.f) {ts.m = ts.f;}
- if( ts.m === 0 && ts.y === 0 && ts.d === 0) {
- return " " ;
- }
- ts.m = parseInt(ts.m,10)-1;
- var ty = ts.y;
- if (ty >= 70 && ty <= 99) {ts.y = 1900+ts.y;}
- else if (ty >=0 && ty <=69) {ts.y= 2000+ts.y;}
- timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
- //Apply offset to show date as local time.
- if(offset > 0) {
- timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
- }
- }
- } else {
- timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
- }
- if(opts.userLocalTime && offset === 0) {
- offset -= (new Date()).getTimezoneOffset();
- if( offset > 0 ) {
- timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
- }
- }
- if( newformat === undefined ) {
- return timestamp;
- }
- if( opts.masks.hasOwnProperty(newformat) ) {
- newformat = opts.masks[newformat];
- } else if ( !newformat ) {
- newformat = 'Y-m-d';
- }
- var
- G = timestamp.getHours(),
- i = timestamp.getMinutes(),
- j = timestamp.getDate(),
- n = timestamp.getMonth() + 1,
- o = timestamp.getTimezoneOffset(),
- s = timestamp.getSeconds(),
- u = timestamp.getMilliseconds(),
- w = timestamp.getDay(),
- Y = timestamp.getFullYear(),
- N = (w + 6) % 7 + 1,
- z = (new Date(Y, n - 1, j) - new Date(Y, 0, 1)) / 86400000,
- flags = {
- // Day
- d: pad(j),
- D: opts.dayNames[w],
- j: j,
- l: opts.dayNames[w + 7],
- N: N,
- S: opts.S(j),
- //j < 11 || j > 13 ? ['st', 'nd', 'rd', 'th'][Math.min((j - 1) % 10, 3)] : 'th',
- w: w,
- z: z,
- // Week
- W: N < 5 ? Math.floor((z + N - 1) / 7) + 1 : Math.floor((z + N - 1) / 7) || ((new Date(Y - 1, 0, 1).getDay() + 6) % 7 < 4 ? 53 : 52),
- // Month
- F: opts.monthNames[n - 1 + 12],
- m: pad(n),
- M: opts.monthNames[n - 1],
- n: n,
- t: '?',
- // Year
- L: '?',
- o: '?',
- Y: Y,
- y: String(Y).substring(2),
- // Time
- a: G < 12 ? opts.AmPm[0] : opts.AmPm[1],
- A: G < 12 ? opts.AmPm[2] : opts.AmPm[3],
- B: '?',
- g: G % 12 || 12,
- G: G,
- h: pad(G % 12 || 12),
- H: pad(G),
- i: pad(i),
- s: pad(s),
- u: u,
- // Timezone
- e: '?',
- I: '?',
- O: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
- P: '?',
- T: (String(timestamp).match(timezone) || [""]).pop().replace(timezoneClip, ""),
- Z: '?',
- // Full Date/Time
- c: '?',
- r: '?',
- U: Math.floor(timestamp / 1000)
- };
- return newformat.replace(token, function ($0) {
- return flags.hasOwnProperty($0) ? flags[$0] : $0.substring(1);
- });
- },
- jqID : function(sid){
- return String(sid).replace(/[!"#$%&'()*+,.\/:; <=>?@\[\\\]\^`{|}~]/g,"\\$&");
- },
- guid : 1,
- uidPref: 'jqg',
- randId : function( prefix ) {
- return (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;
- },
- getXmlData: function (obj, expr, returnObj) {
- var ret, m = typeof expr === 'string' ? expr.match(/^(.*)\[(\w+)\]$/) : null;
- if (typeof expr === 'function') { return expr(obj); }
- if (m && m[2]) {
- // m[2] is the attribute selector
- // m[1] is an optional element selector
- // examples: "[id]", "rows[page]"
- return m[1] ? $(m[1], obj).attr(m[2]) : $(obj).attr(m[2]);
- }
- ret = $(expr, obj);
- if (returnObj) { return ret; }
- //$(expr, obj).filter(':last'); // we use ':last' to be more compatible with old version of jqGrid
- return ret.length > 0 ? $(ret).text() : undefined;
- },
- cellWidth : function () {
- var $testDiv = $("<div class='ui-jqgrid' style='left:10000px'><table class='ui-jqgrid-btable' style='width:5px;'><tr class='jqgrow'><td style='width:5px;display:block;'></td></tr></table></div>"),
- testCell = $testDiv.appendTo("body")
- .find("td")
- .width();
- $testDiv.remove();
- return Math.abs(testCell-5) > 0.1;
- },
- isLocalStorage : function () {
- try {
- return 'localStorage' in window && window.localStorage !== null;
- } catch (e) {
- return false;
- }
- },
- getRegional : function(inst, param, def_val) {
- var ret;
- if(def_val !== undefined) {
- return def_val;
- }
- if(inst.p && inst.p.regional && $.jgrid.regional) {
- ret = $.jgrid.getAccessor( $.jgrid.regional[inst.p.regional] || {}, param);
- }
- if(ret === undefined ) {
- ret = $.jgrid.getAccessor( $.jgrid, param);
- }
- return ret;
- },
- cell_width : true,
- ajaxOptions: {},
- from : function(source){
- // Original Author Hugo Bonacci
- // License MIT http://jlinq.codeplex.com/license
- var $t = this,
- 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()";
- }
- return"";
- };
- this._group=function(f,u){
- return({field:f.toString(),unique:u,items:[]});
- };
- this._toStr=function(phrase){
- if(_trim){
- phrase=$.trim(phrase);
- }
- phrase=phrase.toString().replace(/\\/g,'\\\\').replace(/\"/g,'\\"');
- return _usecase ? phrase : phrase.toLowerCase();
- };
- 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){
- var toString = Object.prototype.toString;
- 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 (toString.call(a) === '[object Date]' && toString.call(b) === '[object Date]') {
- if (a < b) { return -d; }
- if (a > b) { return d; }
- return 0;
- }
- if(!_usecase && typeof a !== "number" && typeof b !== "number" ) {
- a=String(a);
- b=String(b);
- }
- 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,
- sfunc = _sorting[q].sfunc;
- if(q===_sorting.length-1){
- return self._getOrder(d, by, dir, type, dfmt, sfunc);
- }
- q++;
- var values=self._getGroup(d,by,dir,type,dfmt), results=[], i, j, sorted;
- for(i=0;i<values.length;i++){
- sorted=self._doSort(values[i].items,q);
- for(j=0;j<sorted.length;j++){
- results.push(sorted[j]);
- }
- }
- return results;
- };
- this._getOrder=function(data,by,dir,type, dfmt, sfunc){
- 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) {
- var key = parseFloat( String($cell).replace(_stripNum, ''));
- return isNaN(key) ? Number.NEGATIVE_INFINITY : key;
- };
- } else if (type==='int' || type==='integer') {
- findSortKey = function($cell) {
- return $cell ? parseFloat(String($cell).replace(_stripNum, '')) : Number.NEGATIVE_INFINITY;
- };
- } else if(type === 'date' || type === 'datetime') {
- findSortKey = function($cell) {
- return $.jgrid.parseDate.call($t, dfmt, $cell).getTime();
- };
- } else if($.isFunction(type)) {
- findSortKey = type;
- } else {
- findSortKey = function($cell) {
- $cell = $cell ? $.trim(String($cell)) : "";
- return _usecase ? $cell : $cell.toLowerCase();
- };
- }
- $.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});
- });
- if($.isFunction(sfunc)) {
- _sortData.sort(function(a,b){
- a = a.vSort;
- b = b.vSort;
- return sfunc.call(this,a,b,newDir);
- });
- } else {
- _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 == null) { 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(){
- 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.call($t, t.srcfmt || 'Y-m-d',val).getTime());
- fld = 'jQuery.jgrid.parseDate.call(jQuery("#'+$.jgrid.jqID($t.p.id)+'")[0],"'+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==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{
- if (v!=null) { 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==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, sfunc){
- dir = dir == null ? "a" :$.trim(dir.toString().toLowerCase());
- if(stype == null) { stype = "text"; }
- if(dfmt == null) { dfmt = "Y-m-d"; }
- if(sfunc == null) { sfunc = false; }
- if(dir==="desc"||dir==="descending"){dir="d";}
- if(dir==="asc"||dir==="ascending"){dir="a";}
- _sorting.push({by:by,dir:dir,type:stype, datefmt: dfmt, sfunc: sfunc});
- return self;
- };
- return self;
- };
- return new QueryObject(source,null);
- },
- getMethod: function (name) {
- return this.getAccessor($.fn.jqGrid, name);
- },
- extend : function(methods) {
- $.extend($.fn.jqGrid,methods);
- if (!this.no_legacy_api) {
- $.fn.extend(methods);
- }
- },
- clearBeforeUnload : function( jqGridId ) {
- var $t = $("#"+$.jgrid.jqID( jqGridId ))[0], grid;
- if(!$t.grid) { return;}
- grid = $t.grid;
- if ($.isFunction(grid.emptyRows)) {
- grid.emptyRows.call($t, true, true); // this work quick enough and reduce the size of memory leaks if we have someone
- }
- $(document).unbind("mouseup.jqGrid" + $t.p.id );
- $(grid.hDiv).unbind("mousemove"); // TODO add namespace
- $($t).unbind();
- var i, l = grid.headers.length,
- removevents = ['formatCol','sortData','updatepager','refreshIndex','setHeadCheckBox','constructTr','formatter','addXmlData','addJSONData','grid','p'];
- for (i = 0; i < l; i++) {
- grid.headers[i].el = null;
- }
- for( i in grid) {
- if( grid.hasOwnProperty(i)) {
- grid[i] = null;
- }
- }
- // experimental
- for( i in $t.p) {
- if($t.p.hasOwnProperty(i)) {
- $t.p[i] = $.isArray($t.p[i]) ? [] : null;
- }
- }
- l = removevents.length;
- for(i = 0; i < l; i++) {
- if($t.hasOwnProperty(removevents[i])) {
- $t[removevents[i]] = null;
- delete($t[removevents[i]]);
- }
- }
- },
- gridUnload : function ( jqGridId ) {
- if(!jqGridId) { return; }
- jqGridId = $.trim(jqGridId);
- if(jqGridId.indexOf("#") === 0) {
- jqGridId = jqGridId.substring(1);
- }
-
- var $t = $("#"+ $.jgrid.jqID(jqGridId))[0];
- if ( !$t.grid ) {return;}
- var defgrid = {id: $($t).attr('id'),cl: $($t).attr('class')};
- if ($t.p.pager) {
- $($t.p.pager).unbind().empty().removeClass("ui-state-default ui-jqgrid-pager ui-corner-bottom");
- }
- var newtable = document.createElement('table');
- newtable.className = defgrid.cl;
- var gid = $.jgrid.jqID($t.id);
- $(newtable).removeClass("ui-jqgrid-btable").insertBefore("#gbox_"+gid);
- if( $($t.p.pager).parents("#gbox_"+gid).length === 1 ) {
- $($t.p.pager).insertBefore("#gbox_"+gid);
- }
- $.jgrid.clearBeforeUnload( jqGridId );
- $("#gbox_"+gid).remove();
- $(newtable).attr({id:defgrid.id});
- $("#alertmod_"+$.jgrid.jqID(jqGridId)).remove();
- },
- gridDestroy : function ( jqGridId ) {
- if(!jqGridId) { return; }
- jqGridId = $.trim(jqGridId);
- if(jqGridId.indexOf("#") === 0) {
- jqGridId = jqGridId.substring(1);
- }
- var $t = $("#"+ $.jgrid.jqID(jqGridId))[0];
- if ( !$t.grid ) {return;}
- if ( $t.p.pager ) { // if not part of grid
- $($t.p.pager).remove();
- }
- try {
- $.jgrid.clearBeforeUnload( jqGridId );
- $("#gbox_"+$.jgrid.jqID(jqGridId)).remove();
- } catch (_) {}
- }
- });
- $.fn.jqGrid = function( pin ) {
- if (typeof pin === 'string') {
- var fn = $.jgrid.getMethod(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 localData;
- if (pin != null && pin.data !== undefined) {
- localData = pin.data;
- pin.data = [];
- }
- 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,
- onInitGrid : 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: true,
- 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:[], summary:[],summaryval:[], plusicon: 'ui-icon-circlesmall-plus', minusicon: 'ui-icon-circlesmall-minus', displayField: [], groupSummaryPos:[], formatDisplayField : [], _locgr : false},
- ignoreCase : true,
- cmTemplate : {},
- idPrefix : "",
- multiSort : false,
- minColWidth : 33,
- scrollPopUp : false,
- scrollTopOffset: 0, // pixel
- scrollLeftOffset : "100%", //percent
- storeNavOptions: false,
- regional : "en"
- }, $.jgrid.defaults , pin );
- if (localData !== undefined) {
- p.data = localData;
- pin.data = localData;
- }
- var ts= this, grid={
- headers:[],
- cols:[],
- footers: [],
- dragStart: function(i,x,y) {
- var gridLeftPos = $(this.bDiv).offset().left;
- this.resizing = { idx: i, startX: x.pageX, sOL : x.pageX - gridLeftPos };
- 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:x.pageX-gridLeftPos,top:y[1],height:y[2]});
- $(ts).triggerHandler("jqGridResizeStart", [x, i]);
- if($.isFunction(p.resizeStart)) { p.resizeStart.call(ts,x,i); }
- document.onselectstart=function(){return false;};
- },
- dragMove: function(x) {
- if(this.resizing) {
- var diff = x.pageX-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 > p.minColWidth ) {
- 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;
- }
- }
- $(ts).triggerHandler("jqGridResizeStop", [nw, idx]);
- if($.isFunction(p.resizeStop)) { p.resizeStop.call(ts,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) || 0) <= p.lastpage))
- {
- npage = parseInt((dh - tbot + div - 1) / div,10) || 1;
- if (tbot >= 0 || npage < 2 || p.scroll === true) {
- page = ( Math.round((tbot + scrollTop) / div) || 0) + 1;
- ttop = -1;
- } else {
- ttop = 1;
- }
- }
- if (ttop > 0) {
- page = ( parseInt(scrollTop / div,10) || 0 ) + 1;
- npage = (parseInt((scrollTop + dh) / div,10) || 0) + 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.call(table[0], false, false);
- }
- grid.populate(npage);
- }
- if(p.scrollPopUp && p.lastpage != null) {
- $("#scroll_g"+p.id).show().html( $.jgrid.template( $.jgrid.getRegional(ts, "defaults.pgtext", p.pgtext) , p.page, p.lastpage)).css({ "top": p.scrollTopOffset+scrollTop*((parseInt(p.height,10) - 45)/ (parseInt(rh,10)*parseInt(p.records,10))) +"px", "left" : p.scrollLeftOffset});
- $(this).mouseout(function(){
- $("#scroll_g"+p.id).hide();
- });
- }
- }
- },
- 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,
- sr = p.selrow, sra = p.selarrrow ? $.makeArray(p.selarrrow) : null,
- left = ts.grid.bDiv.scrollLeft,
- restoreSelection = function() {
- var i;
- p.selrow = null;
- p.selarrrow = [];
- if(p.multiselect && sra && sra.length>0) {
- for(i=0;i<sra.length;i++){
- if (sra[i] !== sr) {
- $(ts).jqGrid("setSelection",sra[i],false, null);
- }
- }
- }
- if (sr) {
- $(ts).jqGrid("setSelection",sr,false,null);
- }
- ts.grid.bDiv.scrollLeft = left;
- $(ts).unbind('.selectionPreserver', restoreSelection);
- };
- $(ts).bind('jqGridGridComplete.selectionPreserver', restoreSelection);
- }
- };
- if(this.tagName.toUpperCase() !== 'TABLE' || this.id == null) {
- alert("Element is not a table or has no id!");
- return;
- }
- if(document.documentMode !== undefined ) { // IE only
- if(document.documentMode <= 5) {
- alert("Grid can not be used in this ('quirks') mode!");
- return;
- }
- }
- $(this).empty().attr("tabindex","0");
- this.p = p ;
- this.p.useProp = !!$.fn.prop;
- var i, dir;
- 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.getRegional(this,"errors.model"));
- return;
- }
- var gv = $("<div class='ui-jqgrid-view' role='grid'></div>"),
- isMSIE = $.jgrid.msie;
- ts.p.direction = $.trim(ts.p.direction.toLowerCase());
- ts.p._ald = false;
- if($.inArray(ts.p.direction,["ltr","rtl"]) === -1) { ts.p.direction = "ltr"; }
- dir = ts.p.direction;
- $(gv).insertBefore(this);
- $(this).removeClass("scroll").appendTo(gv);
- var eg = $("<div class='ui-jqgrid ui-widget ui-widget-content ui-corner-all'></div>");
- $(eg).attr({"id" : "gbox_"+this.id,"dir":dir}).insertBefore(gv);
- $(gv).attr("id","gview_"+this.id).appendTo(eg);
- $("<div class='ui-widget-overlay jqgrid-overlay' id='lui_"+this.id+"'></div>").insertBefore(gv);
- $("<div class='loading ui-state-default ui-state-active' id='load_"+this.id+"'>"+$.jgrid.getRegional(ts, "defaults.loadtext", this.p.loadtext)+"</div>").insertBefore(gv);
- $(this).attr({cellspacing:"0",cellpadding:"0",border:"0","role":"presentation","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 || 0;}
- return val;
- },
- formatCol = function (pos, rowInd, tv, rawObject, rowId, rdata){
- var cm = ts.p.colModel[pos], cellAttrFunc,
- 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 ($.isFunction(cm.cellattr) || (typeof cm.cellattr === "string" && $.jgrid.cellattr != null && $.isFunction($.jgrid.cellattr[cm.cellattr]))) {
- cellAttrFunc = $.isFunction(cm.cellattr) ? cm.cellattr : $.jgrid.cellattr[cm.cellattr];
- celp = cellAttrFunc.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.replace(/\-style/g,'-sti').split(/style/);
- if(acp.length === 2 ) {
- acp[1] = $.trim(acp[1].replace(/\-sti/g,'-style').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 == null || val === "" ? " " : (ts.p.autoencode ? $.jgrid.htmlEncode(val) : String(val));
- },
- formatter = function (rowId, cellval , colpos, rwdat, _act){
- var cm = ts.p.colModel[colpos],v;
- if(cm.formatter !== undefined) {
- rowId = String(ts.p.idPrefix) !== "" ? $.jgrid.stripPref(ts.p.idPrefix, rowId) : rowId;
- 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.call(ts,cm.formatter,cellval,opts,rwdat,_act);
- } else {
- v = cellVal(cellval);
- }
- } else {
- v = cellVal(cellval);
- }
- return v;
- },
- addCell = function(rowId,cell,pos,irow, srvr, rdata) {
- var v,prp;
- v = formatter(rowId,cell,pos,srvr,'add');
- prp = formatCol( pos,irow, v, srvr, rowId, rdata);
- return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
- },
- addMulti = function(rowid,pos,irow,checked){
- var v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+ts.p.id+"_"+rowid+"\" class=\"cbox\" name=\"jqg_"+ts.p.id+"_"+rowid+"\"" + (checked ? "checked=\"checked\"" : "")+"/>",
- 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') {
- f[j]= datatype === "local" ?
- field.name :
- ( (datatype==="xml" || datatype === "xmlstring") ? field.xmlmap || field.name : field.jsonmap || field.name );
- if(ts.p.keyName !== false && field.key===true ) {
- ts.p.keyName = f[j];
- }
- 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 (scroll, locdata) {
- var firstrow;
- if (this.p.deepempty) {
- $(this.rows).slice(1).remove();
- } else {
- firstrow = this.rows.length > 0 ? this.rows[0] : null;
- $(this.firstChild).empty().append(firstrow);
- }
- if (scroll && this.p.scroll) {
- $(this.grid.bDiv.firstChild).css({height: "auto"});
- $(this.grid.bDiv.firstChild.firstChild).css({height: 0, display: "none"});
- if (this.grid.bDiv.scrollTop !== 0) {
- this.grid.bDiv.scrollTop = 0;
- }
- }
- if(locdata === true && this.p.treeGrid && !this.p.loadonce ) {
- this.p.data = []; this.p._index = {};
- }
- },
- normalizeData = function() {
- var p = ts.p, data = p.data, dataLength = data.length, i, j, cur, idn, idr, ccur, v, rd,
- localReader = p.localReader,
- colModel = p.colModel,
- cellName = localReader.cell,
- iOffset = (p.multiselect === true ? 1 : 0) + (p.subGrid === true ? 1 : 0) + (p.rownumbers === true ? 1 : 0),
- br = p.scroll ? $.jgrid.randId() : 1,
- arrayReader, objectReader, rowReader;
- if (p.datatype !== "local" || localReader.repeatitems !== true) {
- return; // nothing to do
- }
- arrayReader = orderedCols(iOffset);
- objectReader = reader("local");
- // read ALL input items and convert items to be read by
- // $.jgrid.getAccessor with column name as the second parameter
- idn = p.keyIndex === false ?
- ($.isFunction(localReader.id) ? localReader.id.call(ts, data) : localReader.id) :
- p.keyIndex;
- for (i = 0; i < dataLength; i++) {
- cur = data[i];
- // read id in the same way like addJSONData do
- // probably it would be better to start with "if (cellName) {...}"
- // but the goal of the current implementation was just have THE SAME
- // id values like in addJSONData ...
- idr = $.jgrid.getAccessor(cur, idn);
- if (idr === undefined) {
- if (typeof idn === "number" && colModel[idn + iOffset] != null) {
- // reread id by name
- idr = $.jgrid.getAccessor(cur, colModel[idn + iOffset].name);
- }
- if (idr === undefined) {
- idr = br + i;
- if (cellName) {
- ccur = $.jgrid.getAccessor(cur, cellName) || cur;
- idr = ccur != null && ccur[idn] !== undefined ? ccur[idn] : idr;
- ccur = null;
- }
- }
- }
- rd = { };
- rd[localReader.id] = idr;
- if (cellName) {
- cur = $.jgrid.getAccessor(cur, cellName) || cur;
- }
- rowReader = $.isArray(cur) ? arrayReader : objectReader;
- for (j = 0; j < rowReader.length; j++) {
- v = $.jgrid.getAccessor(cur, rowReader[j]);
- rd[colModel[j + iOffset].name] = v;
- }
- $.extend(true, data[i], rd);
- }
- },
- refreshIndex = function() {
- var datalen = ts.p.data.length, idname, i, val;
- if(ts.p.keyName === false || ts.p.loadonce === true) {
- idname = ts.p.localReader.id;
- } else {
- idname = ts.p.keyName;
- }
- ts.p._index = [];
- for(i =0;i < datalen; i++) {
- val = $.jgrid.getAccessor(ts.p.data[i],idname);
- if (val === undefined) { val=String(i+1); }
- ts.p._index[val] = i;
- }
- },
- constructTr = function(id, hide, altClass, rd, cur, selected) {
- var tabindex = '-1', restAttr = '', attrName, style = hide ? 'display:none;' : '',
- classes = 'ui-widget-content jqgrow ui-row-' + ts.p.direction + (altClass ? ' ' + altClass : '') + (selected ? ' ui-state-highlight' : ''),
- rowAttrObj = $(ts).triggerHandler("jqGridRowAttr", [rd, cur, id]);
- if( typeof rowAttrObj !== "object" ) {
- rowAttrObj = $.isFunction(ts.p.rowattr) ? ts.p.rowattr.call(ts, rd, cur, id) :
- (typeof ts.p.rowattr === "string" && $.jgrid.rowattr != null && $.isFunction($.jgrid.rowattr[ts.p.rowattr]) ?
- $.jgrid.rowattr[ts.p.rowattr].call(ts, rd, cur, id) : {});
- }
- if(!$.isEmptyObject( rowAttrObj )) {
- if (rowAttrObj.hasOwnProperty("id")) {
- id = rowAttrObj.id;
- delete rowAttrObj.id;
- }
- if (rowAttrObj.hasOwnProperty("tabindex")) {
- tabindex = rowAttrObj.tabindex;
- delete rowAttrObj.tabindex;
- }
- if (rowAttrObj.hasOwnProperty("style")) {
- style += rowAttrObj.style;
- delete rowAttrObj.style;
- }
- if (rowAttrObj.hasOwnProperty("class")) {
- classes += ' ' + rowAttrObj['class'];
- delete rowAttrObj['class'];
- }
- // dot't allow to change role attribute
- try { delete rowAttrObj.role; } catch(ra){}
- for (attrName in rowAttrObj) {
- if (rowAttrObj.hasOwnProperty(attrName)) {
- restAttr += ' ' + attrName + '=' + rowAttrObj[attrName];
- }
- }
- }
- return '<tr role="row" id="' + id + '" tabindex="' + tabindex + '" class="' + classes + '"' +
- (style === '' ? '' : ' style="' + style + '"') + restAttr + '>';
- },
- addXmlData = function (xml, rcnt, more, adjust) {
- var startReq = new Date(),
- locdata = (ts.p.datatype !== "local" && ts.p.loadonce) || ts.p.datatype === "xmlstring",
- xmlid = "_id_", xmlRd = ts.p.xmlReader,
- 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.call(ts, false, true);
- rcnt=1;
- } else { rcnt = rcnt > 1 ? rcnt :1; }
- } else { return; }
- var self= $(ts), i,fpos,ir=0,v,gi=ts.p.multiselect===true?1:0,si=0,addSubGridCell,ni=ts.p.rownumbers===true?1:0,idn, getId,f=[],F,rd ={}, xmlr,rid, rowData=[], cn=(ts.p.altRows === true) ? ts.p.altclass:"",cn1;
- if(ts.p.subGrid===true) {
- si = 1;
- addSubGridCell = $.jgrid.getMethod("addSubGridCell");
- }
- if(!xmlRd.repeatitems) {f = reader(frd);}
- if( ts.p.keyName===false) {
- idn = $.isFunction( xmlRd.id ) ? xmlRd.id.call(ts, xml) : xmlRd.id;
- } else {
- idn = ts.p.keyName;
- }
- if( String(idn).indexOf("[") === -1 ) {
- if (f.length) {
- getId = function( trow, k) {return $(idn,trow).text() || k;};
- } else {
- getId = function( trow, k) {return $(xmlRd.cell,trow).eq(idn).text() || k;};
- }
- }
- else {
- getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;};
- }
- ts.p.userData = {};
- ts.p.page = intNum($.jgrid.getXmlData(xml, xmlRd.page), ts.p.page);
- ts.p.lastpage = intNum($.jgrid.getXmlData(xml, xmlRd.total), 1);
- ts.p.records = intNum($.jgrid.getXmlData(xml, xmlRd.records));
- if($.isFunction(xmlRd.userdata)) {
- ts.p.userData = xmlRd.userdata.call(ts, xml) || {};
- } else {
- $.jgrid.getXmlData(xml, xmlRd.userdata, true).each(function() {ts.p.userData[this.getAttribute("name")]= $(this).text();});
- }
- var gxml = $.jgrid.getXmlData( xml, xmlRd.root, true);
- gxml = $.jgrid.getXmlData( gxml, xmlRd.row, true);
- if (!gxml) { gxml = []; }
- var gl = gxml.length, j=0, grpdata=[], rn = parseInt(ts.p.rowNum,10), br=ts.p.scroll?$.jgrid.randId():1, altr;
- if (gl > 0 && ts.p.page <= 0) { ts.p.page = 1; }
- if(gxml && gl){
- if (adjust) { rn *= adjust+1; }
- var afterInsRow = $.isFunction(ts.p.afterInsertRow), hiderow=false, groupingPrepare;
- if(ts.p.grouping) {
- hiderow = ts.p.groupingView.groupCollapse === true;
- groupingPrepare = $.jgrid.getMethod("groupingPrepare");
- }
- 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 : '';
- var iStartTrTag = rowData.length;
- rowData.push("");
- if( ni ) {
- rowData.push( addRowNum(0,j,ts.p.page,ts.p.rowNum) );
- }
- if( gi ) {
- rowData.push( addMulti(rid,ni,j, false) );
- }
- if( si ) {
- rowData.push( addSubGridCell.call(self, gi+ni, j+rcnt) );
- }
- if(xmlRd.repeatitems){
- if (!F) { F=orderedCols(gi+si+ni); }
- var cells = $.jgrid.getXmlData( xmlr, xmlRd.cell, true);
- $.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, rd) );
- });
- } else {
- for(i = 0; i < f.length;i++) {
- v = $.jgrid.getXmlData( xmlr, f[i]);
- rd[ts.p.colModel[i+gi+si+ni].name] = v;
- rowData.push( addCell(rid, v, i+gi+si+ni, j+rcnt, xmlr, rd) );
- }
- }
- rowData[iStartTrTag] = constructTr(rid, hiderow, cn1, rd, xmlr, false);
- rowData.push("</tr>");
- if(ts.p.grouping) {
- grpdata.push( rowData );
- if(!ts.p.groupingView._locgr) {
- groupingPrepare.call(self , rd, j );
- }
- rowData = [];
- }
- if(locdata || (ts.p.treeGrid === true && !(ts.p._ald)) ) {
- rd[xmlid] = $.jgrid.stripPref(ts.p.idPrefix, rid);
- ts.p.data.push(rd);
- ts.p._index[rd[xmlid]] = ts.p.data.length-1;
- }
- if(ts.p.gridview === false ) {
- $("tbody:first", ts.grid.bDiv).append(rowData.join(''));
- self.triggerHandler("jqGridAfterInsertRow", [rid, rd, xmlr]);
- 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) {
- if(!locdata) {
- self.jqGrid('groupingRender',grpdata,ts.p.colModel.length, ts.p.page, rn);
- grpdata = null;
- }
- } else if(ts.p.treeGrid === true && fpos > 0) {
- $(ts.rows[fpos]).after(rowData.join(''));
- } else {
- //$("tbody:…
Large files files are truncated, but you can click here to view the full file