/** * * @license Guriddo jqGrid JS - v5.1.0 - 2016-05-12 * 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: "5.1.0", 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, ">"); }, 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; }, useJSON: true, 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 = $("
"), 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; }, isMobile: function () { try { if (/Android|webOS|iPhone|iPad|iPod|pocket|psp|kindle|avantgo|blazer|midori|Tablet|Palm|maemo|plucker|phone|BlackBerry|symbian|IEMobile|mobile|ZuneWP7|Windows Phone|Opera Mini/i.test(navigator.userAgent)) { return true; } return false; } catch (e) { return false; } }, 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 "提供的数据不是数组"; } 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) { return sfunc.call(this, a.vSort, b.vSort, newDir, a, b); }); } else { _sortData.sort(function (a, b) { return self._compare(a.vSort, b.vSort, 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 ui-common-table").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 (_) { } }, styleUI: { jQueryUI: { common: { disabled: "ui-state-disabled", highlight: "ui-state-highlight", hover: "ui-state-hover", cornerall: "ui-corner-all", cornertop: "ui-corner-top", cornerbottom: "ui-corner-bottom", hidden: "ui-helper-hidden", icon_base: "ui-icon", overlay: "ui-widget-overlay", active: "ui-state-active", error: "ui-state-error", button: "ui-state-default ui-corner-all", content: "ui-widget-content" }, base: { entrieBox: "ui-widget ui-widget-content ui-corner-all", // entrie div incl everthing viewBox: "", // view diw headerTable: "", headerBox: "ui-state-default", rowTable: "", rowBox: "ui-widget-content", footerTable: "", footerBox: "ui-widget-content", headerDiv: "ui-state-default", gridtitleBox: "ui-widget-header ui-corner-top ui-helper-clearfix", customtoolbarBox: "ui-state-default", //overlayBox: "ui-widget-overlay", loadingBox: "ui-state-default ui-state-active", rownumBox: "ui-state-default", scrollBox: "ui-widget-content", multiBox: "", pagerBox: "ui-state-default ui-corner-bottom", pagerTable: "", toppagerBox: "ui-state-default", pgInput: "ui-corner-all", pgSelectBox: "ui-widget-content ui-corner-all", pgButtonBox: "ui-corner-all", icon_first: "ui-icon-seek-first", icon_prev: "ui-icon-seek-prev", icon_next: "ui-icon-seek-next", icon_end: "ui-icon-seek-end", icon_asc: "ui-icon-triangle-1-n", icon_desc: "ui-icon-triangle-1-s", icon_caption_open: "ui-icon-circle-triangle-n", icon_caption_close: "ui-icon-circle-triangle-s" }, modal: { modal: "ui-widget ui-widget-content ui-corner-all ui-dialog", header: "ui-widget-header ui-corner-all ui-helper-clearfix", content: "ui-widget-content", resizable: "ui-resizable-handle ui-resizable-se", icon_close: "ui-icon-closethick", icon_resizable: "ui-icon-gripsmall-diagonal-se" }, celledit: { inputClass: "ui-widget-content ui-corner-all" }, inlinedit: { inputClass: "ui-widget-content ui-corner-all", icon_edit_nav: "ui-icon-pencil", icon_add_nav: "ui-icon-plus", icon_save_nav: "ui-icon-disk", icon_cancel_nav: "ui-icon-cancel" }, formedit: { inputClass: "ui-widget-content ui-corner-all", icon_prev: "ui-icon-triangle-1-w", icon_next: "ui-icon-triangle-1-e", icon_save: "ui-icon-disk", icon_close: "ui-icon-close", icon_del: "ui-icon-scissors", icon_cancel: "ui-icon-cancel" }, navigator: { icon_edit_nav: "ui-icon-pencil", icon_add_nav: "ui-icon-plus", icon_del_nav: "ui-icon-trash", icon_search_nav: "ui-icon-search", icon_refresh_nav: "ui-icon-refresh", icon_view_nav: "ui-icon-document", icon_newbutton_nav: "ui-icon-newwin" }, grouping: { icon_plus: 'ui-icon-circlesmall-plus', icon_minus: 'ui-icon-circlesmall-minus' }, filter: { table_widget: 'ui-widget ui-widget-content', srSelect: 'ui-widget-content ui-corner-all', srInput: 'ui-widget-content ui-corner-all', menu_widget: 'ui-widget ui-widget-content ui-corner-all', icon_search: 'ui-icon-search', icon_reset: 'ui-icon-arrowreturnthick-1-w', icon_query: 'ui-icon-comment' }, subgrid: { icon_plus: 'ui-icon-plus', icon_minus: 'ui-icon-minus', icon_open: 'ui-icon-carat-1-sw' }, treegrid: { icon_plus: 'ui-icon-triangle-1-', icon_minus: 'ui-icon-triangle-1-s', icon_leaf: 'ui-icon-radio-off' }, fmatter: { icon_edit: "ui-icon-pencil", icon_add: "ui-icon-plus", icon_save: "ui-icon-disk", icon_cancel: "ui-icon-cancel", icon_del: "ui-icon-trash" }, colmenu: { menu_widget: 'ui-widget ui-widget-content ui-corner-all', input_checkbox: "ui-widget ui-widget-content", filter_select: "ui-widget-content ui-corner-all", filter_input: "ui-widget-content ui-corner-all", icon_menu: "ui-icon-comment", icon_sort_asc: "ui-icon-arrow-1-n", icon_sort_desc: "ui-icon-arrow-1-s", icon_columns: "ui-icon-extlink", icon_filter: "ui-icon-calculator", icon_group: "ui-icon-grip-solid-horizontal", icon_freeze: "ui-icon-grip-solid-vertical", icon_move: "ui-icon-arrow-4" } }, Bootstrap: { common: { disabled: "ui-disabled", highlight: "success", hover: "active", cornerall: "", cornertop: "", cornerbottom: "", hidden: "", icon_base: "glyphicon", overlay: "ui-overlay", active: "active", error: "bg-danger", button: "btn btn-default", content: "" }, base: { entrieBox: "", viewBox: "table-responsive", headerTable: "table table-bordered", headerBox: "", rowTable: "table table-bordered", rowBox: "", footerTable: "table table-bordered", footerBox: "", headerDiv: "", gridtitleBox: "", customtoolbarBox: "", //overlayBox: "ui-overlay", loadingBox: "row", rownumBox: "", scrollBox: "", multiBox: "checkbox", pagerBox: "", pagerTable: "table", toppagerBox: "", pgInput: "form-control", pgSelectBox: "form-control", pgButtonBox: "", icon_first: "glyphicon-step-backward", icon_prev: "glyphicon-backward", icon_next: "glyphicon-forward", icon_end: "glyphicon-step-forward", icon_asc: "glyphicon-triangle-top", icon_desc: "glyphicon-triangle-bottom", icon_caption_open: "glyphicon-circle-arrow-up", icon_caption_close: "glyphicon-circle-arrow-down" }, modal: { modal: "modal-content", header: "modal-header", title: "modal-title", content: "modal-body", resizable: "ui-resizable-handle ui-resizable-se", icon_close: "glyphicon-remove-circle", icon_resizable: "glyphicon-import" }, celledit: { inputClass: 'form-control' }, inlinedit: { inputClass: 'form-control', icon_edit_nav: "glyphicon-edit", icon_add_nav: "glyphicon-plus", icon_save_nav: "glyphicon-save", icon_cancel_nav: "glyphicon-remove-circle" }, formedit: { inputClass: "form-control", icon_prev: "glyphicon-step-backward", icon_next: "glyphicon-step-forward", icon_save: "glyphicon-save", icon_close: "glyphicon-remove-circle", icon_del: "glyphicon-trash", icon_cancel: "glyphicon-remove-circle" }, navigator: { icon_edit_nav: "glyphicon-edit", icon_add_nav: "glyphicon-plus", icon_del_nav: "glyphicon-trash", icon_search_nav: "glyphicon-search", icon_refresh_nav: "glyphicon-refresh", icon_view_nav: "glyphicon-info-sign", icon_newbutton_nav: "glyphicon-new-window" }, grouping: { icon_plus: 'glyphicon-triangle-right', icon_minus: 'glyphicon-triangle-bottom' }, filter: { table_widget: 'table table-condensed', srSelect: 'form-control', srInput: 'form-control', menu_widget: '', icon_search: 'glyphicon-search', icon_reset: 'glyphicon-refresh', icon_query: 'glyphicon-comment' }, subgrid: { icon_plus: 'glyphicon-triangle-right', icon_minus: 'glyphicon-triangle-bottom', icon_open: 'glyphicon-indent-left' }, treegrid: { icon_plus: 'glyphicon-triangle-right', icon_minus: 'glyphicon-triangle-bottom', icon_leaf: 'glyphicon-unchecked' }, fmatter: { icon_edit: "glyphicon-edit", icon_add: "glyphicon-plus", icon_save: "glyphicon-save", icon_cancel: "glyphicon-remove-circle", icon_del: "glyphicon-trash" }, colmenu: { menu_widget: '', input_checkbox: "", filter_select: "form-control", filter_input: "form-control", icon_menu: "glyphicon-menu-hamburger", icon_sort_asc: "glyphicon-sort-by-alphabet", icon_sort_desc: "glyphicon-sort-by-alphabet-alt", icon_columns: "glyphicon-list-alt", icon_filter: "glyphicon-filter", icon_group: "glyphicon-align-left", icon_freeze: "glyphicon-object-align-horizontal", icon_move: "glyphicon-move" } } } }); $.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, { unwritten: true, url: "", height: 150, page: 1, rowNum: 20, rowTotal: null, records: 0, pager: "", pgbuttons: true, pginput: true, colModel: [], rowList: [20,50, 100, 150,200,500,1000], 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: false, 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: 30, gridview: true, rownumWidth: 28, 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: '', minusicon: '', 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", styleUI: "Bootstrap", responsive: false, restoreCellonFail: true, colFilters: {}, colMenu: false }, $.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 (events) { 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 (events) { $(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 (p.frozenColumns) { $(grid.fbDiv).scrollTop(grid.bDiv.scrollTop); } 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("元素不是表或没有id!"); return; } if (document.documentMode !== undefined) { // IE only if (document.documentMode <= 5) { alert("Grid can not be used in this ('quirks') mode!"); return; } } var i = 0, lr, lk, dir; for (lk in $.jgrid.regional) { if ($.jgrid.regional.hasOwnProperty(lk)) { if (i === 0) { lr = lk; } i++; } } if (i === 1 && lr !== p.regional) { p.regional = lr; } $(this).empty().attr("tabindex", "0"); this.p = p; this.p.useProp = !!$.fn.prop; 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 getstyle = $.jgrid.getMethod("getStyleUI"), stylemodule = ts.p.styleUI + ".common", disabled = getstyle(stylemodule, 'disabled', true), highlight = getstyle(stylemodule, 'highlight', true), hover = getstyle(stylemodule, 'hover', true), cornerall = getstyle(stylemodule, 'cornerall', true), iconbase = getstyle(stylemodule, 'icon_base', true), colmenustyle = $.jgrid.styleUI[(ts.p.styleUI || 'jQueryUI')].colmenu, isMSIE = $.jgrid.msie, gv, sortarr = [], sortord = [], sotmp = []; stylemodule = ts.p.styleUI + ".base"; gv = $("
"); 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).appendTo(gv); var eg = $("
"); $(eg).attr({ "id": "gbox_" + this.id, "dir": dir }).insertBefore(gv); $(gv).attr("id", "gview_" + this.id).appendTo(eg); $("
").insertBefore(gv); $("
" + $.jgrid.getRegional(ts, "defaults.loadtext", this.p.loadtext) + "
").insertBefore(gv); $(this).attr({ 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, styleUI: ts.p.styleUI }; 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 "" + v + ""; }, addMulti = function (rowid, pos, irow, checked, uiclass) { var v = "", prp = formatCol(pos, irow, '', null, rowid, true); return "" + v + ""; }, addRowNum = function (pos, irow, pG, rN, uiclass) { var v = (parseInt(pG, 10) - 1) * parseInt(rN, 10) + 1 + irow, prp = formatCol(pos, irow, v, null, irow, true); return "" + v + ""; }, 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: "0px", 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, classes, rd, cur) { var tabindex = '-1', restAttr = '', attrName, style = hide ? 'display:none;' : '', //classes = getstyle(stylemodule, 'rowBox', true) + ts.p.direction + (altClass ? ' ' + altClass : '') + (selected ? ' ' + 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 ''; }, 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 = getstyle(stylemodule, 'rowBox', true, 'jqgrow ui-row-' + ts.p.direction), classes; 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, tablebody = $("#" + $.jgrid.jqID(ts.p.id) + " tbody:first"); 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, rnc = ni ? getstyle(stylemodule, 'rownumBox', false, 'jqgrid-rownum') : "", mlc = gi ? getstyle(stylemodule, 'multiBox', false, 'cbox') : ""; 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; classes = 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, rnc)); } if (gi) { rowData.push(addMulti(rid, ni, j, false, mlc)); } 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, classes, rd, xmlr); rowData.push(""); 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) { tablebody.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:first",t).append(rowData.join('')); tablebody.append(rowData.join('')); ts.grid.cols = ts.rows[0].cells; // update cached first row } } ts.p.totaltime = new Date() - startReq; rowData = null; if (ts.p.subGrid === true) { try { self.jqGrid("addSubGrid", gi + ni); } catch (_) { } } if (ir > 0) { if (ts.p.records === 0) { ts.p.records = gl; } } if (ts.p.treeGrid === true) { try { self.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) { self.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 + br); rid = ts.p.idPrefix + rid; if (xmlRd.repeatitems) { if (!F) { F = orderedCols(gi + si + ni); } var cells2 = $.jgrid.getXmlData(xmlr, xmlRd.cell, true); $.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 = $.jgrid.getXmlData(xmlr, f[i]); rd[ts.p.colModel[i + gi + si + ni].name] = v; } } rd[xmlid] = $.jgrid.stripPref(ts.p.idPrefix, rid); if (ts.p.grouping) { groupingPrepare.call(self, rd, ir); } ts.p.data.push(rd); ts.p._index[rd[xmlid]] = ts.p.data.length - 1; rd = {}; ir++; } if (ts.p.grouping) { ts.p.groupingView._locgr = true; self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn); grpdata = null; } } }, addJSONData = function (data, rcnt, more, adjust) { var startReq = new Date(); if (data) { if (ts.p.treeANode === -1 && !ts.p.scroll) { emptyRows.call(ts, 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 self = $(ts), ir = 0, v, i, j, f = [], cur, gi = ts.p.multiselect ? 1 : 0, si = ts.p.subGrid === true ? 1 : 0, addSubGridCell, ni = ts.p.rownumbers === true ? 1 : 0, arrayReader = orderedCols(gi + si + ni), objectReader = reader(frd), rowReader, len, drows, idn, rd = {}, fpos, idr, rowData = [], cn = (ts.p.altRows === true) ? ts.p.altclass : "", cn1 = getstyle(stylemodule, 'rowBox', true, 'jqgrow ui-row-' + ts.p.direction), classes; ts.p.page = intNum($.jgrid.getAccessor(data, dReader.page), ts.p.page); ts.p.lastpage = intNum($.jgrid.getAccessor(data, dReader.total), 1); ts.p.records = intNum($.jgrid.getAccessor(data, dReader.records)); ts.p.userData = $.jgrid.getAccessor(data, dReader.userdata) || {}; if (si) { addSubGridCell = $.jgrid.getMethod("addSubGridCell"); } if (ts.p.keyName === false) { idn = $.isFunction(dReader.id) ? dReader.id.call(ts, data) : dReader.id; } else { idn = ts.p.keyName; } drows = $.jgrid.getAccessor(data, dReader.root); if (drows == null && $.isArray(data)) { drows = data; } if (!drows) { drows = []; } len = drows.length; i = 0; if (len > 0 && ts.p.page <= 0) { ts.p.page = 1; } var rn = parseInt(ts.p.rowNum, 10), br = ts.p.scroll ? $.jgrid.randId() : 1, altr, selected = false, selr; if (adjust) { rn *= adjust + 1; } if (ts.p.datatype === "local" && !ts.p.deselectAfterSort) { selected = true; } var afterInsRow = $.isFunction(ts.p.afterInsertRow), grpdata = [], hiderow = false, groupingPrepare, tablebody = $("#" + $.jgrid.jqID(ts.p.id) + " tbody:first"), rnc = ni ? getstyle(stylemodule, 'rownumBox', false, 'jqgrid-rownum') : "", mlc = gi ? getstyle(stylemodule, 'multiBox', false, 'cbox') : ""; if (ts.p.grouping) { hiderow = ts.p.groupingView.groupCollapse === true; groupingPrepare = $.jgrid.getMethod("groupingPrepare"); } while (i < len) { cur = drows[i]; idr = $.jgrid.getAccessor(cur, idn); if (idr === undefined) { if (typeof idn === "number" && ts.p.colModel[idn + gi + si + ni] != null) { // reread id by name idr = $.jgrid.getAccessor(cur, ts.p.colModel[idn + gi + si + ni].name); } if (idr === undefined) { idr = br + i; if (f.length === 0) { if (dReader.cell) { var ccur = $.jgrid.getAccessor(cur, dReader.cell) || cur; idr = ccur != null && ccur[idn] !== undefined ? ccur[idn] : idr; ccur = null; } } } } idr = ts.p.idPrefix + idr; altr = rcnt === 1 ? 0 : rcnt; classes = cn1 + ((altr + i) % 2 === 1 ? ' ' + cn : ''); if (selected) { if (ts.p.multiselect) { selr = ($.inArray(idr, ts.p.selarrrow) !== -1); } else { selr = (idr === ts.p.selrow); } } var iStartTrTag = rowData.length; rowData.push(""); if (ni) { rowData.push(addRowNum(0, i, ts.p.page, ts.p.rowNum, rnc)); } if (gi) { rowData.push(addMulti(idr, ni, i, selr, mlc)); } if (si) { rowData.push(addSubGridCell.call(self, gi + ni, i + rcnt)); } rowReader = objectReader; if (dReader.repeatitems) { if (dReader.cell) { cur = $.jgrid.getAccessor(cur, dReader.cell) || cur; } if ($.isArray(cur)) { rowReader = arrayReader; } } for (j = 0; j < rowReader.length; j++) { v = $.jgrid.getAccessor(cur, rowReader[j]); rd[ts.p.colModel[j + gi + si + ni].name] = v; rowData.push(addCell(idr, v, j + gi + si + ni, i + rcnt, cur, rd)); } classes += (selr ? ' ' + highlight : ''); rowData[iStartTrTag] = constructTr(idr, hiderow, classes, rd, cur); rowData.push(""); if (ts.p.grouping) { grpdata.push(rowData); if (!ts.p.groupingView._locgr) { groupingPrepare.call(self, rd, i); } rowData = []; } if (locdata || (ts.p.treeGrid === true && !(ts.p._ald))) { rd[locid] = $.jgrid.stripPref(ts.p.idPrefix, idr); ts.p.data.push(rd); ts.p._index[rd[locid]] = ts.p.data.length - 1; } if (ts.p.gridview === false) { tablebody.append(rowData.join('')); self.triggerHandler("jqGridAfterInsertRow", [idr, rd, cur]); 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) { 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 { tablebody.append(rowData.join('')); ts.grid.cols = ts.rows[0].cells; } } ts.p.totaltime = new Date() - startReq; rowData = null; if (ts.p.subGrid === true) { try { self.jqGrid("addSubGrid", gi + ni); } catch (_) { } } if (ir > 0) { if (ts.p.records === 0) { ts.p.records = len; } } if (ts.p.treeGrid === true) { try { self.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) { self.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) { if (typeof idn === "number" && ts.p.colModel[idn + gi + si + ni] != null) { // reread id by name idr = $.jgrid.getAccessor(cur, ts.p.colModel[idn + gi + si + ni].name); } if (idr === undefined) { idr = br + ir; if (f.length === 0) { if (dReader.cell) { var ccur2 = $.jgrid.getAccessor(cur, dReader.cell) || cur; idr = ccur2 != null && ccur2[idn] !== undefined ? ccur2[idn] : idr; ccur2 = null; } } } } if (cur) { idr = ts.p.idPrefix + idr; rowReader = objectReader; if (dReader.repeatitems) { if (dReader.cell) { cur = $.jgrid.getAccessor(cur, dReader.cell) || cur; } if ($.isArray(cur)) { rowReader = arrayReader; } } for (j = 0; j < rowReader.length; j++) { rd[ts.p.colModel[j + gi + si + ni].name] = $.jgrid.getAccessor(cur, rowReader[j]); } rd[locid] = $.jgrid.stripPref(ts.p.idPrefix, idr); if (ts.p.grouping) { groupingPrepare.call(self, rd, ir); } ts.p.data.push(rd); ts.p._index[rd[locid]] = ts.p.data.length - 1; rd = {}; } ir++; } if (ts.p.grouping) { ts.p.groupingView._locgr = true; self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn); grpdata = null; } } }, addLocalData = function () { var st = ts.p.multiSort ? [] : "", sto = [], fndsort = false, cmtypes = {}, grtypes = [], grindexes = [], srcformat, sorttype, newformat, sfld; if (!$.isArray(ts.p.data)) { return; } var grpview = ts.p.grouping ? ts.p.groupingView : false, lengrp, gin, si; $.each(ts.p.colModel, function () { sorttype = this.sorttype || "text"; si = this.index || this.name; 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.getRegional(ts, "formatter.date.srcformat"); } if (this.formatoptions && this.formatoptions.newformat) { newformat = this.formatoptions.newformat; } else { newformat = $.jgrid.getRegional(ts, "formatter.date.newformat"); } } else { srcformat = newformat = this.datefmt || "Y-m-d"; } cmtypes[si] = { "stype": sorttype, "srcfmt": srcformat, "newfmt": newformat, "sfunc": this.sortfunc || null }; } else { cmtypes[si] = { "stype": sorttype, "srcfmt": '', "newfmt": '', "sfunc": this.sortfunc || null }; } if (ts.p.grouping) { for (gin = 0, lengrp = grpview.groupField.length; gin < lengrp; gin++) { if (this.name === grpview.groupField[gin]) { grtypes[gin] = cmtypes[si]; grindexes[gin] = si; } } } if (!ts.p.multiSort) { if (!fndsort && (si === ts.p.sortname)) { st = si; fndsort = true; } } }); if (ts.p.multiSort) { st = sortarr; sto = sortord; } if (ts.p.treeGrid && ts.p._sort) { $(ts).jqGrid("SortTree", st, ts.p.sortorder, cmtypes[st].stype || 'text', cmtypes[st].srcfmt || ''); return; } var compareFnMap = { 'eq': function (queryObj) { return queryObj.equals; }, 'ne': function (queryObj) { return queryObj.notEquals; }, 'lt': function (queryObj) { return queryObj.less; }, 'le': function (queryObj) { return queryObj.lessOrEquals; }, 'gt': function (queryObj) { return queryObj.greater; }, 'ge': function (queryObj) { return queryObj.greaterOrEquals; }, 'cn': function (queryObj) { return queryObj.contains; }, 'nc': function (queryObj, op) { return op === "OR" ? queryObj.orNot().contains : queryObj.andNot().contains; }, 'bw': function (queryObj) { 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) { return queryObj.endsWith; }, 'ni': function (queryObj, op) { return op === "OR" ? queryObj.orNot().equals : queryObj.andNot().equals; }, 'in': function (queryObj) { return queryObj.equals; }, 'nu': function (queryObj) { return queryObj.isNull; }, 'nn': function (queryObj, op) { return op === "OR" ? queryObj.orNot().isNull : queryObj.andNot().isNull; } }, query = $.jgrid.from.call(ts, ts.p.data); if (ts.p.ignoreCase) { query = query.ignoreCase(); } function tojLinq(group) { var s = 0, index, gor, ror, opr, rule, fld; if (group.groups != null) { 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 != null) { //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(); } fld = cmtypes[rule.field]; if (fld.stype === 'date') { if (fld.srcfmt && fld.newfmt && fld.srcfmt !== fld.newfmt) { rule.data = $.jgrid.parseDate.call(ts, fld.newfmt, rule.data, fld.srcfmt); } } 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 { sfld = cmtypes[ts.p.postData.searchField]; if (sfld.stype === 'date') { if (sfld.srcfmt && sfld.newfmt && sfld.srcfmt !== sfld.newfmt) { ts.p.postData.searchString = $.jgrid.parseDate.call(ts, sfld.newfmt, ts.p.postData.searchString, sfld.srcfmt); } } query = compareFnMap[ts.p.postData.searchOper](query)(ts.p.postData.searchField, ts.p.postData.searchString, cmtypes[ts.p.postData.searchField]); } catch (se) { } } } else { if (ts.p.treeGrid && ts.p.treeGridModel === "nested") { query.orderBy(ts.p.treeReader.left_field, 'asc', 'integer', '', null); } } if (ts.p.treeGrid && ts.p.treeGridModel === "adjacency") { lengrp = 0; st = null; } if (ts.p.grouping) { for (gin = 0; gin < lengrp; gin++) { query.orderBy(grindexes[gin], grpview.groupOrder[gin], grtypes[gin].stype, grtypes[gin].srcfmt); } } if (ts.p.multiSort) { $.each(st, function (i) { query.orderBy(this, sto[i], cmtypes[this].stype, cmtypes[this].srcfmt, cmtypes[this].sfunc); }); } else { if (st && ts.p.sortorder && fndsort) { // to be fixed in case sortname has more than one field if (ts.p.sortorder.toUpperCase() === "DESC") { query.orderBy(ts.p.sortname, "d", cmtypes[st].stype, cmtypes[st].srcfmt, cmtypes[st].sfunc); } else { query.orderBy(ts.p.sortname, "a", cmtypes[st].stype, cmtypes[st].srcfmt, cmtypes[st].sfunc); } } } 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 = {}; if ((ts.p.search || ts.p.resetsearch) && ts.p.grouping && ts.p.groupingView._locgr) { ts.p.groupingView.groups = []; var j, grPrepare = $.jgrid.getMethod("groupingPrepare"), key, udc; if (ts.p.footerrow && ts.p.userDataOnFooter) { for (key in ts.p.userData) { if (ts.p.userData.hasOwnProperty(key)) { ts.p.userData[key] = 0; } } udc = true; } for (j = 0; j < total; j++) { if (udc) { for (key in ts.p.userData) { if (ts.p.userData.hasOwnProperty(key)) { ts.p.userData[key] += parseFloat(queryResults[j][key] || 0); } } } grPrepare.call($(ts), queryResults[j], j, recordsperpage); } } if (ts.p.treeGrid && ts.p.search) { queryResults = $(ts).jqGrid("searchTree", queryResults); } else { 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; queryResults = null; return retresult; }, updatepager = function (rn, dnd) { var cp, last, base, from, to, tot, fmt, pgboxes = "", sppg, pgid = ts.p.pager ? $.jgrid.jqID(ts.p.pager.substr(1)) : "", tspg = pgid ? "_" + pgid : "", tspg_t = ts.p.toppager ? "_" + ts.p.toppager.substr(1) : ""; base = parseInt(ts.p.page, 10) - 1; if (base < 0) { base = 0; } base = base * parseInt(ts.p.rowNum, 10); to = base + ts.p.reccount; if (ts.p.scroll) { var rows = $("tbody:first > tr:gt(0)", ts.grid.bDiv); base = to - rows.length; ts.p.reccount = rows.length; var rh = rows.outerHeight() || ts.grid.prevRowHeight; if (rh) { var top = base * rh; var height = parseInt(ts.p.records, 10) * rh; $(">div:first", ts.grid.bDiv).css({ height: height }).children("div:first").css({ height: top, display: top ? "" : "none" }); if (ts.grid.bDiv.scrollTop === 0 && ts.p.page > 1) { ts.grid.bDiv.scrollTop = ts.p.rowNum * (ts.p.page - 1) * rh; } } ts.grid.bDiv.scrollLeft = ts.grid.hDiv.scrollLeft; } pgboxes = ts.p.pager || ""; pgboxes += ts.p.toppager ? (pgboxes ? "," + ts.p.toppager : ts.p.toppager) : ""; if (pgboxes) { fmt = $.jgrid.getRegional(ts, "formatter.integer"); cp = intNum(ts.p.page); last = intNum(ts.p.lastpage); $(".selbox", pgboxes)[this.p.useProp ? 'prop' : 'attr']("disabled", false); if (ts.p.pginput === true) { $("#input" + tspg).html($.jgrid.template($.jgrid.getRegional(ts, "defaults.pgtext", ts.p.pgtext) || "", "", "")); if (ts.p.toppager) { $("#input_t" + tspg_t).html($.jgrid.template($.jgrid.getRegional(ts, "defaults.pgtext", ts.p.pgtext) || "", "", "")); } $('.ui-pg-input', pgboxes).val(ts.p.page); sppg = ts.p.toppager ? '#sp_1' + tspg + ",#sp_1" + tspg + "_toppager" : '#sp_1' + tspg; $(sppg).html($.fmatter ? $.fmatter.util.NumberFormat(ts.p.lastpage, fmt) : ts.p.lastpage); } if (ts.p.viewrecords) { if (ts.p.reccount === 0) { $(".ui-paging-info", pgboxes).html($.jgrid.getRegional(ts, "defaults.emptyrecords", ts.p.emptyrecords)); } else { from = base + 1; tot = ts.p.records; if ($.fmatter) { from = $.fmatter.util.NumberFormat(from, fmt); to = $.fmatter.util.NumberFormat(to, fmt); tot = $.fmatter.util.NumberFormat(tot, fmt); } var rt = $.jgrid.getRegional(ts, "defaults.recordtext", ts.p.recordtext); $(".ui-paging-info", pgboxes).html($.jgrid.template(rt, from, to, tot)); } } if (ts.p.pgbuttons === true) { if (cp <= 0) { cp = last = 0; } if (cp === 1 || cp === 0) { $("#first" + tspg + ", #prev" + tspg).addClass(disabled).removeClass(hover); if (ts.p.toppager) { $("#first_t" + tspg_t + ", #prev_t" + tspg_t).addClass(disabled).removeClass(hover); } } else { $("#first" + tspg + ", #prev" + tspg).removeClass(disabled); if (ts.p.toppager) { $("#first_t" + tspg_t + ", #prev_t" + tspg_t).removeClass(disabled); } } if (cp === last || cp === 0) { $("#next" + tspg + ", #last" + tspg).addClass(disabled).removeClass(hover); if (ts.p.toppager) { $("#next_t" + tspg_t + ", #last_t" + tspg_t).addClass(disabled).removeClass(hover); } } else { $("#next" + tspg + ", #last" + tspg).removeClass(disabled); if (ts.p.toppager) { $("#next_t" + tspg_t + ", #last_t" + tspg_t).removeClass(disabled); } } } } if (rn === true && ts.p.rownumbers === true) { $(">td.jqgrid-rownum", ts.rows).each(function (i) { $(this).html(base + 1 + i); }); } if (dnd && ts.p.jqgdnd) { $(ts).jqGrid('gridDnD', 'updateDnD'); } $(ts).triggerHandler("jqGridGridComplete"); if ($.isFunction(ts.p.gridComplete)) { ts.p.gridComplete.call(ts); } $(ts).triggerHandler("jqGridAfterGridComplete"); }, beginReq = function () { window.setTimeout(function () { $.loading(true); top.$("#loadingPage").find('.loading-content').attr('isTableLoading', 'true'); }, 0); ts.grid.hDiv.loading = true; if (ts.p.hiddengrid) { return; } }, endReq = function () { window.setTimeout(function () { top.$("#loadingPage").find('.loading-content').removeAttr('isTableLoading'); $.loading(false); }, 0); ts.grid.hDiv.loading = false; if (ts.p.unwritten) { $("#" + ts.p.id).parents('.ui-jqgrid-bdiv').find(".unwritten").remove(); if ($("#" + ts.p.id).find('tbody tr').length == 1) { $("#" + ts.p.id).parents('.ui-jqgrid-bdiv').append('
暂无数据!
') } } }, populate = function (npage) { if (!ts.grid.hDiv.loading) { var pvis = ts.p.scroll && npage === false, prm = {}, dt, dstr, pN = ts.p.prmNames; if (ts.p.page <= 0) { ts.p.page = Math.min(1, ts.p.lastpage); } if (pN.search !== null) { prm[pN.search] = ts.p.search; } if (pN.nd !== null) { prm[pN.nd] = new Date().getTime(); } if (pN.rows !== null) { prm[pN.rows] = ts.p.rowNum; } if (pN.page !== null) { prm[pN.page] = ts.p.page; } if (pN.sort !== null) { prm[pN.sort] = ts.p.sortname; } if (pN.order !== null) { prm[pN.order] = ts.p.sortorder; } if (ts.p.rowTotal !== null && pN.totalrows !== null) { prm[pN.totalrows] = ts.p.rowTotal; } var lcf = $.isFunction(ts.p.loadComplete), lc = lcf ? ts.p.loadComplete : null; var adjust = 0; npage = npage || 1; if (npage > 1) { if (pN.npage !== null) { prm[pN.npage] = npage; adjust = npage - 1; npage = 1; } else { lc = function (req) { ts.p.page++; ts.grid.hDiv.loading = false; if (lcf) { ts.p.loadComplete.call(ts, req); } populate(npage - 1); }; } } else if (pN.npage !== null) { delete ts.p.postData[pN.npage]; } if (ts.p.grouping) { $(ts).jqGrid('groupingSetup'); var grp = ts.p.groupingView, gi, gs = ""; for (gi = 0; gi < grp.groupField.length; gi++) { var index = grp.groupField[gi]; $.each(ts.p.colModel, function (cmIndex, cmValue) { if (cmValue.name === index && cmValue.index) { index = cmValue.index; } }); gs += index + " " + grp.groupOrder[gi] + ", "; } prm[pN.sort] = gs + prm[pN.sort]; } $.extend(ts.p.postData, prm); var rcnt = !ts.p.scroll ? 1 : ts.rows.length - 1; var bfr = $(ts).triggerHandler("jqGridBeforeRequest"); if (bfr === false || bfr === 'stop') { return; } if ($.isFunction(ts.p.datatype)) { ts.p.datatype.call(ts, ts.p.postData, "load_" + ts.p.id, rcnt, npage, adjust); return; } if ($.isFunction(ts.p.beforeRequest)) { bfr = ts.p.beforeRequest.call(ts); if (bfr === undefined) { bfr = true; } if (bfr === false) { return; } } dt = ts.p.datatype.toLowerCase(); switch (dt) { case "json": case "jsonp": case "xml": case "script": $.ajax($.extend({ url: ts.p.url, type: ts.p.mtype, dataType: dt, data: $.isFunction(ts.p.serializeGridData) ? ts.p.serializeGridData.call(ts, ts.p.postData) : ts.p.postData, success: function (data, st, xhr) { if ($.isFunction(ts.p.beforeProcessing)) { if (ts.p.beforeProcessing.call(ts, data, st, xhr) === false) { endReq(); return; } } if (dt === "xml") { addXmlData(data, rcnt, npage > 1, adjust); } else { addJSONData(data, rcnt, npage > 1, adjust); } $(ts).triggerHandler("jqGridLoadComplete", [data]); if (lc) { lc.call(ts, data); } $(ts).triggerHandler("jqGridAfterLoadComplete", [data]); if (pvis) { ts.grid.populateVisible(); } if (ts.p.loadonce || ts.p.treeGrid) { ts.p.datatype = "local"; } data = null; if (npage === 1) { endReq(); } }, error: function (xhr, st, err) { if ($.isFunction(ts.p.loadError)) { ts.p.loadError.call(ts, xhr, st, err); } if (npage === 1) { endReq(); } xhr = null; }, beforeSend: function (xhr, settings) { var gotoreq = true; if ($.isFunction(ts.p.loadBeforeSend)) { gotoreq = ts.p.loadBeforeSend.call(ts, xhr, settings); } if (gotoreq === undefined) { gotoreq = true; } if (gotoreq === false) { return false; } beginReq(); } }, $.jgrid.ajaxOptions, ts.p.ajaxGridOptions)); break; case "xmlstring": beginReq(); dstr = typeof ts.p.datastr !== 'string' ? ts.p.datastr : $.parseXML(ts.p.datastr); addXmlData(dstr); $(ts).triggerHandler("jqGridLoadComplete", [dstr]); if (lcf) { ts.p.loadComplete.call(ts, dstr); } $(ts).triggerHandler("jqGridAfterLoadComplete", [dstr]); ts.p.datatype = "local"; ts.p.datastr = null; endReq(); break; case "jsonstring": beginReq(); if (typeof ts.p.datastr === 'string') { dstr = $.jgrid.parse(ts.p.datastr); } else { dstr = ts.p.datastr; } addJSONData(dstr); $(ts).triggerHandler("jqGridLoadComplete", [dstr]); if (lcf) { ts.p.loadComplete.call(ts, dstr); } $(ts).triggerHandler("jqGridAfterLoadComplete", [dstr]); ts.p.datatype = "local"; ts.p.datastr = null; endReq(); break; case "local": case "clientside": beginReq(); ts.p.datatype = "local"; ts.p._ald = true; var req = addLocalData(); addJSONData(req, rcnt, npage > 1, adjust); $(ts).triggerHandler("jqGridLoadComplete", [req]); if (lc) { lc.call(ts, req); } $(ts).triggerHandler("jqGridAfterLoadComplete", [req]); if (pvis) { ts.grid.populateVisible(); } endReq(); ts.p._ald = false; break; } ts.p._sort = false; } }, setHeadCheckBox = function (checked) { $('#cb_' + $.jgrid.jqID(ts.p.id), ts.grid.hDiv)[ts.p.useProp ? 'prop' : 'attr']("checked", checked); var fid = ts.p.frozenColumns ? ts.p.id + "_frozen" : ""; if (fid) { $('#cb_' + $.jgrid.jqID(ts.p.id), ts.grid.fhDiv)[ts.p.useProp ? 'prop' : 'attr']("checked", checked); } }, setPager = function (pgid, tp) { // TBD - consider escaping pgid with pgid = $.jgrid.jqID(pgid); var sep = "", pginp = "", pgl = "", str = "", pgcnt, lft, cent, rgt, twd, tdw, i, clearVals = function (onpaging, thus) { var ret; if ($.isFunction(ts.p.onPaging)) { ret = ts.p.onPaging.call(ts, onpaging, thus); } if (ret === 'stop') { return false; } ts.p.selrow = null; if (ts.p.multiselect) { ts.p.selarrrow = []; setHeadCheckBox(false); } ts.p.savedRow = []; return true; }; pgid = pgid.substr(1); tp += "_" + pgid; pgcnt = "pg_" + pgid; lft = pgid + "_left"; cent = pgid + "_center"; rgt = pgid + "_right"; $("#" + $.jgrid.jqID(pgid)) .append("
") .attr("dir", "ltr"); //explicit setting if (ts.p.rowList.length > 0) { str = ""; str += ""; } if (dir === "rtl") { pgl += str; } if (ts.p.pginput === true) { pginp = "" + $.jgrid.template($.jgrid.getRegional(ts, "defaults.pgtext", ts.p.pgtext) || "", "", "") + ""; } if (ts.p.pgbuttons === true) { var po = ["first" + tp, "prev" + tp, "next" + tp, "last" + tp], btc = getstyle(stylemodule, 'pgButtonBox', true, 'ui-pg-button'), pot = [($.jgrid.getRegional(ts, "defaults.pgfirst", ts.p.pgfirst) || ""), ($.jgrid.getRegional(ts, "defaults.pgprev", ts.p.pgprev) || ""), ($.jgrid.getRegional(ts, "defaults.pgnext", ts.p.pgnext) || ""), ($.jgrid.getRegional(ts, "defaults.pglast", ts.p.pglast) || "")]; if (dir === "rtl") { po.reverse(); pot.reverse(); } pgl += ""; pgl += ""; pgl += pginp !== "" ? sep + pginp + sep : ""; pgl += ""; pgl += ""; } else if (pginp !== "") { pgl += pginp; } if (dir === "ltr") { pgl += str; } pgl += ""; if (ts.p.viewrecords === true) { $("td#" + pgid + "_" + ts.p.recordpos, "#" + pgcnt).append("
"); } $("td#" + pgid + "_" + ts.p.pagerpos, "#" + pgcnt).append(pgl); tdw = $("#gbox_" + $.jgrid.jqID(ts.p.id)).css("font-size") || "11px"; $("#gbox_" + $.jgrid.jqID(ts.p.id)).append(""); twd = $(pgl).clone().appendTo("#testpg").width(); $("#testpg").remove(); if (twd > 0) { if (pginp !== "") { twd += 50; } //should be param $("td#" + pgid + "_" + ts.p.pagerpos, "#" + pgcnt).width(twd); } ts.p._nvtd = []; ts.p._nvtd[0] = twd ? Math.floor((ts.p.width - twd) / 2) : Math.floor(ts.p.width / 3); ts.p._nvtd[1] = 0; pgl = null; $('.ui-pg-selbox', "#" + pgcnt).bind('change', function () { if (!clearVals('records', this)) { return false; } ts.p.page = Math.round(ts.p.rowNum * (ts.p.page - 1) / this.value - 0.5) + 1; ts.p.rowNum = this.value; if (ts.p.pager) { $('.ui-pg-selbox', ts.p.pager).val(this.value); } if (ts.p.toppager) { $('.ui-pg-selbox', ts.p.toppager).val(this.value); } populate(); return false; }); if (ts.p.pgbuttons === true) { $(".ui-pg-button", "#" + pgcnt).hover(function () { if ($(this).hasClass(disabled)) { this.style.cursor = 'default'; } else { $(this).addClass(hover); this.style.cursor = 'pointer'; } }, function () { if (!$(this).hasClass(disabled)) { $(this).removeClass(hover); this.style.cursor = "default"; } }); $("#first" + $.jgrid.jqID(tp) + ", #prev" + $.jgrid.jqID(tp) + ", #next" + $.jgrid.jqID(tp) + ", #last" + $.jgrid.jqID(tp)).click(function () { if ($(this).hasClass(disabled)) { return false; } var cp = intNum(ts.p.page, 1), last = intNum(ts.p.lastpage, 1), selclick = false, fp = true, pp = true, np = true, lp = true; if (last === 0 || last === 1) { fp = false; pp = false; np = false; lp = false; } else if (last > 1 && cp >= 1) { if (cp === 1) { fp = false; pp = false; } else if (cp === last) { np = false; lp = false; } } else if (last > 1 && cp === 0) { np = false; lp = false; cp = last - 1; } if (!clearVals(this.id.split("_")[0], this)) { return false; } if (this.id === 'first' + tp && fp) { ts.p.page = 1; selclick = true; } if (this.id === 'prev' + tp && pp) { ts.p.page = (cp - 1); selclick = true; } if (this.id === 'next' + tp && np) { ts.p.page = (cp + 1); selclick = true; } if (this.id === 'last' + tp && lp) { ts.p.page = last; selclick = true; } if (selclick) { populate(); } return false; }); } if (ts.p.pginput === true) { $("#" + pgcnt).on('keypress', 'input.ui-pg-input', function (e) { var key = e.charCode || e.keyCode || 0; if (key === 13) { if (!clearVals('user', this)) { return false; } $(this).val(intNum($(this).val(), 1)); ts.p.page = ($(this).val() > 0) ? $(this).val() : ts.p.page; populate(); return false; } return this; }); } }, multiSort = function (iCol, obj, sor) { var cm = ts.p.colModel, selTh = ts.p.frozenColumns ? obj : ts.grid.headers[iCol].el, so = "", sn; $("span.ui-grid-ico-sort", selTh).addClass(disabled); $(selTh).attr("aria-selected", "false"); sn = (cm[iCol].index || cm[iCol].name); if (typeof sor == "undefined") { if (cm[iCol].lso) { if (cm[iCol].lso === "asc") { cm[iCol].lso += "-desc"; so = "desc"; } else if (cm[iCol].lso === "desc") { cm[iCol].lso += "-asc"; so = "asc"; } else if (cm[iCol].lso === "asc-desc" || cm[iCol].lso === "desc-asc") { cm[iCol].lso = ""; } } else { cm[iCol].lso = so = cm[iCol].firstsortorder || 'asc'; } } else { cm[iCol].lso = so = sor; } if (so) { $("span.s-ico", selTh).show(); $("span.ui-icon-" + so, selTh).removeClass(disabled); $(selTh).attr("aria-selected", "true"); } else { if (!ts.p.viewsortcols[0]) { $("span.s-ico", selTh).hide(); } } var isn = sortarr.indexOf(sn); if (isn === -1) { sortarr.push(sn); sortord.push(so); } else { if (so) { sortord[isn] = so; } else { sortord.splice(isn, 1); sortarr.splice(isn, 1); } } ts.p.sortorder = ""; ts.p.sortname = ""; for (var i = 0, len = sortarr.length; i < len ; i++) { if (i > 0) { ts.p.sortname += ", "; } ts.p.sortname += sortarr[i]; if (i !== len - 1) { ts.p.sortname += " " + sortord[i]; } } ts.p.sortorder = sortord[len - 1]; /* $.each(cm, function(i){ if(this.lso) { if(i>0 && fs) { sort += ", "; } splas = this.lso.split("-"); sort += cm[i].index || cm[i].name; sort += " "+splas[splas.length-1]; fs = true; ts.p.sortorder = splas[splas.length-1]; } }); ls = sort.lastIndexOf(ts.p.sortorder); sort = sort.substring(0, ls); ts.p.sortname = sort; */ }, sortData = function (index, idxcol, reload, sor, obj) { if (!ts.p.colModel[idxcol].sortable) { return; } if (ts.p.savedRow.length > 0) { return; } if (!reload) { if (ts.p.lastsort === idxcol && ts.p.sortname !== "") { if (ts.p.sortorder === 'asc') { ts.p.sortorder = 'desc'; } else if (ts.p.sortorder === 'desc') { ts.p.sortorder = 'asc'; } } else { ts.p.sortorder = ts.p.colModel[idxcol].firstsortorder || 'asc'; } ts.p.page = 1; } if (ts.p.multiSort) { multiSort(idxcol, obj, sor); } else { if (sor) { if (ts.p.lastsort === idxcol && ts.p.sortorder === sor && !reload) { return; } ts.p.sortorder = sor; } var previousSelectedTh = ts.grid.headers[ts.p.lastsort] ? ts.grid.headers[ts.p.lastsort].el : null, newSelectedTh = ts.p.frozenColumns ? obj : ts.grid.headers[idxcol].el, //sortrule = $.trim(ts.p.viewsortcols[1] === 'single' ? hidden : disabled); usehide = ts.p.viewsortcols[1] === 'single' ? true : false, tmpicon; tmpicon = $(previousSelectedTh).find("span.ui-grid-ico-sort"); tmpicon.addClass(disabled); if (usehide) { $(tmpicon).css("display", "none"); } $(previousSelectedTh).attr("aria-selected", "false"); if (ts.p.frozenColumns) { tmpicon = ts.grid.fhDiv.find("span.ui-grid-ico-sort"); tmpicon.addClass(disabled); if (usehide) { tmpicon.css("display", "none"); } ts.grid.fhDiv.find("th").attr("aria-selected", "false"); } tmpicon = $(newSelectedTh).find("span.ui-icon-" + ts.p.sortorder); tmpicon.removeClass(disabled); if (usehide) { tmpicon.css("display", ""); } $(newSelectedTh).attr("aria-selected", "true"); if (!ts.p.viewsortcols[0]) { if (ts.p.lastsort !== idxcol) { if (ts.p.frozenColumns) { ts.grid.fhDiv.find("span.s-ico").hide(); } $("span.s-ico", previousSelectedTh).hide(); $("span.s-ico", newSelectedTh).show(); } else if (ts.p.sortname === "") { // if ts.p.lastsort === idxcol but ts.p.sortname === "" $("span.s-ico", newSelectedTh).show(); } } index = index.substring(5 + ts.p.id.length + 1); // bad to be changed!?! ts.p.sortname = ts.p.colModel[idxcol].index || index; } if ($(ts).triggerHandler("jqGridSortCol", [ts.p.sortname, idxcol, ts.p.sortorder]) === 'stop') { ts.p.lastsort = idxcol; return; } if ($.isFunction(ts.p.onSortCol)) { if (ts.p.onSortCol.call(ts, ts.p.sortname, idxcol, ts.p.sortorder) === 'stop') { ts.p.lastsort = idxcol; return; } } if (ts.p.datatype === "local") { if (ts.p.deselectAfterSort) { $(ts).jqGrid("resetSelection"); } } else { ts.p.selrow = null; if (ts.p.multiselect) { setHeadCheckBox(false); } ts.p.selarrrow = []; ts.p.savedRow = []; } if (ts.p.scroll) { var sscroll = ts.grid.bDiv.scrollLeft; emptyRows.call(ts, true, false); ts.grid.hDiv.scrollLeft = sscroll; } if (ts.p.subGrid && ts.p.datatype === 'local') { $("td.sgexpanded", "#" + $.jgrid.jqID(ts.p.id)).each(function () { $(this).trigger("click"); }); } ts.p._sort = true; populate(); ts.p.lastsort = idxcol; if (ts.p.sortname !== index && idxcol) { ts.p.lastsort = idxcol; } }, setColWidth = function () { var initwidth = 0, brd = $.jgrid.cell_width ? 0 : intNum(ts.p.cellLayout, 0), vc = 0, lvc, scw = intNum(ts.p.scrollOffset, 0), cw, hs = false, aw, gw = 0, cr; $.each(ts.p.colModel, function () { if (this.hidden === undefined) { this.hidden = false; } if (ts.p.grouping && ts.p.autowidth) { var ind = $.inArray(this.name, ts.p.groupingView.groupField); if (ind >= 0 && ts.p.groupingView.groupColumnShow.length > ind) { this.hidden = !ts.p.groupingView.groupColumnShow[ind]; } } this.widthOrg = cw = intNum(this.width, 0); if (this.hidden === false) { initwidth += cw + brd; if (this.fixed) { gw += cw + brd; } else { vc++; } } }); if (isNaN(ts.p.width)) { ts.p.width = initwidth + ((ts.p.shrinkToFit === false && !isNaN(ts.p.height)) ? scw : 0); } grid.width = parseInt(ts.p.width, 10); ts.p.tblwidth = initwidth; if (ts.p.shrinkToFit === false && ts.p.forceFit === true) { ts.p.forceFit = false; } if (ts.p.shrinkToFit === true && vc > 0) { aw = grid.width - brd * vc - gw; if (!isNaN(ts.p.height)) { aw -= scw; hs = true; } initwidth = 0; $.each(ts.p.colModel, function (i) { if (this.hidden === false && !this.fixed) { cw = Math.round(aw * this.width / (ts.p.tblwidth - brd * vc - gw)); this.width = cw; initwidth += cw; lvc = i; } }); cr = 0; if (hs) { if (grid.width - gw - (initwidth + brd * vc) !== scw) { cr = grid.width - gw - (initwidth + brd * vc) - scw; } } else if (!hs && Math.abs(grid.width - gw - (initwidth + brd * vc)) !== 1) { cr = grid.width - gw - (initwidth + brd * vc); } ts.p.colModel[lvc].width += cr; ts.p.tblwidth = initwidth + cr + brd * vc + gw; if (ts.p.tblwidth > ts.p.width) { ts.p.colModel[lvc].width -= (ts.p.tblwidth - parseInt(ts.p.width, 10)); ts.p.tblwidth = ts.p.width; } } }, nextVisible = function (iCol) { var ret = iCol, j = iCol, i; for (i = iCol + 1; i < ts.p.colModel.length; i++) { if (ts.p.colModel[i].hidden !== true) { j = i; break; } } return j - ret; }, getOffset = function (iCol) { var $th = $(ts.grid.headers[iCol].el), ret = [$th.position().left + $th.outerWidth()]; if (ts.p.direction === "rtl") { ret[0] = ts.p.width - ret[0]; } ret[0] -= ts.grid.bDiv.scrollLeft; ret.push($(ts.grid.hDiv).position().top); ret.push($(ts.grid.bDiv).offset().top - $(ts.grid.hDiv).offset().top + $(ts.grid.bDiv).height()); return ret; }, getColumnHeaderIndex = function (th) { var i, headers = ts.grid.headers, ci = $.jgrid.getCellIndex(th); for (i = 0; i < headers.length; i++) { if (th === headers[i].el) { ci = i; break; } } return ci; }, buildColItems = function (top, left, parent) { var cm = ts.p.colModel, len = cm.length, i, cols = [], disp, texts = $.jgrid.getRegional(ts, "colmenu"), str1 = '"; $(parent).append(str1); $("#col_menu").addClass("ui-menu " + colmenustyle.menu_widget); if ($.fn.html5sortable()) { $("#col_menu").html5sortable({ handle: 'span', forcePlaceholderSize: true } ).bind('sortupdate', function (e, ui) { cols.splice(ui.startindex, 1); cols.splice(ui.endindex, 0, ui.startindex); $(ts).jqGrid("destroyFrozenColumns"); $(ts).jqGrid("remapColumns", cols, true); $(ts).jqGrid("setFrozenColumns"); for (i = 0; i < len; i++) { cols[i] = i; } }); } // NO jQuery UI $("#col_menu > li > a").on("click", function (e) { var checked; if ($(e.target).hasClass('notclick')) { return; } if ($(e.target).is(":input")) { checked = $(e.target).is(":checked"); } else { checked = !$("input", this).is(":checked"); $("input", this).prop("checked", checked); } if (!checked) { $(ts).jqGrid('hideCol', $("input", this).attr('name')); $(this).parent().attr("draggable", "false"); } else { $(ts).jqGrid('showCol', $("input", this).attr('name')); $(this).parent().attr("draggable", "true"); } }).hover(function () { $(this).addClass(hover); }, function () { $(this).removeClass(hover); }); }, buildSearchBox = function (index, top, left, parent) { var cm = ts.p.colModel[index], rules, o1 = '', v1 = '', r1 = '', o2 = '', v2 = '', so, op, repstr = '', selected, elem, numopts = ['eq', 'ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn', 'in', 'ni'], stropts = ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc', 'nu', 'nn', 'in', 'ni'], texts = $.jgrid.getRegional(ts, "search"), common = $.jgrid.styleUI[(ts.p.styleUI || 'jQueryUI')].common; if (!cm) { return; } rules = ts.p.colFilters && ts.p.colFilters[cm.name] ? ts.p.colFilters[cm.name] : false; if (rules && !$.isEmptyObject(rules)) { o1 = rules.oper1; v1 = rules.value1; r1 = rules.rule; o2 = rules.oper2; v2 = rules.value2; } if (!cm.searchoptions) { cm.searchoptions = {}; } if (cm.searchoptions.sopt) { so = cm.searchoptions.sopt; } else if (cm.sorttype === 'text') { so = stropts; } else { so = numopts; } if (cm.searchoptions.operands) { op = cm.searchoptions.operands; } else { op = texts.groupOps; } //elem = $(''); elem = $('
'); var str1 = '
' + $.jgrid.getRegional(ts, "colmenu.searchTitle") + '
'; str1 += '
'; elem.append(str1); var df = ""; if (cm.searchoptions.defaultValue) { df = $.isFunction(cm.searchoptions.defaultValue) ? cm.searchoptions.defaultValue.call(ts) : cm.searchoptions.defaultValue; } //overwrite default value if restore from filters if (v1) { df = v1; } var soptions = $.extend(cm.searchoptions, { name: cm.index || cm.name, id: "sval1_" + ts.p.idPrefix + cm.name, oper: 'search' }) var input = $.jgrid.createEl.call(ts, cm.stype, soptions, df, false, $.extend({}, $.jgrid.ajaxOptions, ts.p.ajaxSelectOptions || {})); $(input).addClass(colmenustyle.filter_input); str1 = $('
').append(input); elem.append(str1); // and/or str1 = '
'; elem.append(str1); //oper2 repstr = ''; $.each(texts.odata, function (i, n) { selected = n.oper === o2 ? 'selected="selected"' : ''; if ($.inArray(n.oper, so) !== -1) { repstr += ''; } }); str1 = '
'; elem.append(str1); // value2 if (v2) { df = v2; } else { df = ""; } soptions = $.extend(cm.searchoptions, { name: cm.index || cm.name, id: "sval2_" + ts.p.idPrefix + cm.name, oper: 'search' }); input = $.jgrid.createEl.call(ts, cm.stype, soptions, df, false, $.extend({}, $.jgrid.ajaxOptions, ts.p.ajaxSelectOptions || {})); $(input).addClass(colmenustyle.filter_input); str1 = $('
').append(input); elem.append(str1); // buttons str1 = "
"; str1 += "
" + texts.Reset + "
"; str1 += "
" + texts.Find + "
"; str1 += "
"; elem.append(str1); elem = $('').append(elem); elem = $('').append(elem); $(parent).append(elem); $("#search_menu").addClass("ui-menu " + colmenustyle.menu_widget); $("#bs_reset, #bs_search", "#search_menu").hover(function () { $(this).addClass(hover); }, function () { $(this).removeClass(hover); }); $(elem).find("#bs_reset").click(function (e) { ts.p.colFilters[cm.name] = {}; ts.p.postData.filters = buildFilters(); ts.p.search = true; $(ts).trigger("reloadGrid"); $("#column_menu").remove(); return false; }); $(elem).find("#bs_search").click(function (e) { ts.p.colFilters[cm.name] = { oper1: $("#oper1", "#search_menu").val(), value1: $("#sval1_" + ts.p.idPrefix + cm.name, "#search_menu").val(), rule: $("#operand", "#search_menu").val(), oper2: $("#oper2", "#search_menu").val(), value2: $("#sval2_" + ts.p.idPrefix + cm.name, "#search_menu").val() }; ts.p.postData.filters = buildFilters(); ts.p.search = true; $(ts).trigger("reloadGrid"); $("#column_menu").remove(); return false; }); }, buildFilters = function () { var go = "AND", filters = "{\"groupOp\":\"" + go + "\",\"rules\":[], \"groups\" : [", i = 0; for (var item in ts.p.colFilters) { if (ts.p.colFilters.hasOwnProperty(item)) { var si = ts.p.colFilters[item]; if (!$.isEmptyObject(si)) { if (i > 0) { filters += ","; } filters += "{\"groupOp\": \"" + si.rule + "\", \"rules\" : ["; filters += "{\"field\":\"" + item + "\","; filters += "\"op\":\"" + si.oper1 + "\","; si.value1 += ""; filters += "\"data\":\"" + si.value1.replace(/\\/g, '\\\\').replace(/\"/g, '\\"') + "\"}"; if (si.value2) { filters += ",{\"field\":\"" + item + "\","; filters += "\"op\":\"" + si.oper2 + "\","; si.value2 += ""; filters += "\"data\":\"" + si.value2.replace(/\\/g, '\\\\').replace(/\"/g, '\\"') + "\"}"; } filters += "]}"; i++; } else { //console.log('empty object'); } } } filters += "]}"; return filters; }, buildGrouping = function (index, isgroup) { var cm = ts.p.colModel[index], group = ts.p.groupingView; if (isgroup !== -1) { group.groupField.splice(isgroup, 1); } else { group.groupField.push(cm.name); } $(ts).jqGrid('groupingGroupBy', group.groupField); if (ts.p.frozenColumns) { $(ts).jqGrid("destroyFrozenColumns"); $(ts).jqGrid("setFrozenColumns"); } }, buildFreeze = function (index, isfreeze) { var cols = [], i, len = ts.p.colModel.length, lastfrozen = -1, cm = ts.p.colModel;; for (i = 0; i < len; i++) { if (cm[i].frozen) { lastfrozen = i; } cols.push(i); } // from position index to lastfrozen+1 cols.splice(index, 1); cols.splice(lastfrozen + (isfreeze ? 1 : 0), 0, index); cm[index].frozen = isfreeze; $(ts).jqGrid("destroyFrozenColumns"); $(ts).jqGrid("remapColumns", cols, true); $(ts).jqGrid("setFrozenColumns"); }, buildColMenu = function (index, left, top) { //$("#sopt_menu").remove(); left = parseInt(left, 10); top = parseInt(top, 10) + 25; var fs = $('.ui-jqgrid-view').css('font-size') || '11px'; var str = '"; $('body').append(str); $("#column_menu").addClass("ui-menu " + colmenustyle.menu_widget); $("#column_menu > li > a").hover( function () { $("#col_menu").remove(); $("#search_menu").remove(); if ($(this).attr("value") === 'columns') { var left1 = $(this).parent().width() + 18, top1 = $(this).parent().position().top - 5; buildColItems(top1, left1, $(this).parent()); } if ($(this).attr("value") === 'filtering') { var left1 = $(this).parent().width() + 18, top1 = $(this).parent().position().top - 5; buildSearchBox(index, top1, left1, $(this).parent()); } $(this).addClass(hover); }, function () { $(this).removeClass(hover); } ).click(function () { var v = $(this).attr("value"), sobj = ts.grid.headers[index].el; if (v === 'sortasc') { sortData("jqgh_" + ts.p.id + "_" + cm.name, index, true, 'asc', sobj); } else if (v === 'sortdesc') { sortData("jqgh_" + ts.p.id + "_" + cm.name, index, true, 'desc', sobj); } else if (v === 'grouping') { buildGrouping(index, isgroup); } else if (v === 'freeze') { buildFreeze(index, isfreeze); } if (v.indexOf('sort') !== -1 || v === 'grouping' || v === 'freeze') { $(this).remove(); } }); }, colTemplate; if (ts.p.colMenu) { $("body").on('click', function (e) { if (!$(e.target).closest(".column-menu").length) { $("#column_menu").remove(); } }); } this.p.id = this.id; if ($.inArray(ts.p.multikey, sortkeys) === -1) { ts.p.multikey = false; } ts.p.keyName = false; for (i = 0; i < ts.p.colModel.length; i++) { colTemplate = typeof ts.p.colModel[i].template === "string" ? ($.jgrid.cmTemplate != null && typeof $.jgrid.cmTemplate[ts.p.colModel[i].template] === "object" ? $.jgrid.cmTemplate[ts.p.colModel[i].template] : {}) : ts.p.colModel[i].template; ts.p.colModel[i] = $.extend(true, {}, ts.p.cmTemplate, colTemplate || {}, ts.p.colModel[i]); if (ts.p.keyName === false && ts.p.colModel[i].key === true) { ts.p.keyName = ts.p.colModel[i].name; } } ts.p.sortorder = ts.p.sortorder.toLowerCase(); $.jgrid.cell_width = $.jgrid.cellWidth(); if (ts.p.grouping === true) { ts.p.scroll = false; ts.p.rownumbers = false; //ts.p.subGrid = false; expiremental ts.p.treeGrid = false; ts.p.gridview = true; } if (this.p.treeGrid === true) { try { $(this).jqGrid("setTreeGrid"); } catch (_) { } if (ts.p.datatype !== "local") { ts.p.localReader = { id: "_id_" }; } } if (this.p.subGrid) { try { $(ts).jqGrid("setSubGrid"); } catch (s) { } } if (this.p.multiselect) { this.p.colNames.unshift("
"); this.p.colModel.unshift({ name: 'cb', width: $.jgrid.cell_width ? ts.p.multiselectWidth + ts.p.cellLayout : ts.p.multiselectWidth, sortable: false, resizable: false, hidedlg: true, search: false, align: 'center', fixed: true, frozen: true }); } if (this.p.rownumbers) { this.p.colNames.unshift(""); this.p.colModel.unshift({ name: 'rn', width: ts.p.rownumWidth, sortable: false, resizable: false, hidedlg: true, search: false, align: 'center', fixed: true, frozen: true }); } ts.p.xmlReader = $.extend(true, { root: "rows", row: "row", page: "rows>page", total: "rows>total", records: "rows>records", repeatitems: true, cell: "cell", id: "[id]", userdata: "userdata", subgrid: { root: "rows", row: "row", repeatitems: true, cell: "cell" } }, ts.p.xmlReader); ts.p.jsonReader = $.extend(true, { root: "rows", page: "page", total: "total", records: "records", repeatitems: true, cell: "cell", id: "id", userdata: "userdata", subgrid: { root: "rows", repeatitems: true, cell: "cell" } }, ts.p.jsonReader); ts.p.localReader = $.extend(true, { root: "rows", page: "page", total: "total", records: "records", repeatitems: false, cell: "cell", id: "id", userdata: "userdata", subgrid: { root: "rows", repeatitems: true, cell: "cell" } }, ts.p.localReader); if (ts.p.scroll) { ts.p.pgbuttons = false; ts.p.pginput = false; ts.p.rowList = []; } if (ts.p.data.length) { normalizeData(); refreshIndex(); } var thead = "", tdc, idn, w, res, sort = "", td, ptr, tbody, imgs, iac = "", idc = "", tmpcm; if (ts.p.shrinkToFit === true && ts.p.forceFit === true) { for (i = ts.p.colModel.length - 1; i >= 0; i--) { if (!ts.p.colModel[i].hidden) { ts.p.colModel[i].resizable = false; break; } } } if (ts.p.viewsortcols[1] === 'horizontal') { iac = " ui-i-asc"; idc = " ui-i-desc"; } else if (ts.p.viewsortcols[1] === "single") { iac = " ui-single-sort-asc"; idc = " ui-single-sort-desc"; sort = " style='display:none'"; ts.p.viewsortcols[0] = false; } tdc = isMSIE ? "class='ui-th-div-ie'" : ""; imgs = ""; if (ts.p.multiSort) { if (ts.p.sortname) { sortarr = ts.p.sortname.split(","); for (i = 0; i < sortarr.length; i++) { sotmp = $.trim(sortarr[i]).split(" "); sortarr[i] = $.trim(sotmp[0]); sortord[i] = sotmp[1] ? $.trim(sotmp[1]) : ts.p.sortorder || "asc"; } } } //扩展 var _used_width = 0; var _colNo = 0; for (i = 0; i < this.p.colNames.length; i++) { var _hidden = ts.p.colModel[i].hidden; if (ts.p.colModel[i].autowidth == true) { _colNo = i; break; } if (_hidden == undefined) { _colNo = i; } } for (i = 0; i < this.p.colNames.length; i++) { var tooltip = ts.p.headertitles ? (" title=\"" + $.jgrid.stripHtml(ts.p.colNames[i]) + "\"") : ""; tmpcm = ts.p.colModel[i]; //扩展 var _hidden = tmpcm.hidden; var _width = tmpcm.width; if (_hidden != undefined) { _width = 0; } else { _used_width += _width + 8; } if (i == _colNo) { if ($("#gview_" + ts.p.id).width() > _used_width) { if (tmpcm.autowidth == true || tmpcm.autowidth == undefined) { _width = _width + $("#gview_" + ts.p.id).width() - _used_width - 22; } } } if (!tmpcm.hasOwnProperty('colmenu')) { tmpcm.colmenu = (tmpcm.name === "rn" || tmpcm.name === "cb" || tmpcm.name === "subgrid") ? false : true; } thead += ""; idn = tmpcm.index || tmpcm.name; thead += "
" + ts.p.colNames[i]; tmpcm.width = _width ? parseInt(_width, 10) : 150 if (typeof tmpcm.title !== "boolean") { tmpcm.title = true; } tmpcm.lso = ""; if (idn === ts.p.sortname) { ts.p.lastsort = i; } if (ts.p.multiSort) { sotmp = $.inArray(idn, sortarr); if (sotmp !== -1) { tmpcm.lso = sortord[sotmp]; } } thead += imgs; if (ts.p.colMenu && tmpcm.colmenu) { thead += ""; } thead += "
"; } thead += ""; imgs = null; tmpcm = null; $(this).append(thead); $("thead tr:first th", this).hover( function () { $(this).addClass(hover); }, function () { $(this).removeClass(hover); } ); if (this.p.multiselect) { var emp = [], chk; $('#cb_' + $.jgrid.jqID(ts.p.id), this).bind('click', function () { ts.p.selarrrow = []; var froz = ts.p.frozenColumns === true ? ts.p.id + "_frozen" : ""; if (this.checked) { $(ts.rows).each(function (i) { if (i > 0) { if (!$(this).hasClass("ui-subgrid") && !$(this).hasClass("jqgroup") && !$(this).hasClass(disabled) && !$(this).hasClass("jqfoot")) { $("#jqg_" + $.jgrid.jqID(ts.p.id) + "_" + $.jgrid.jqID(this.id))[ts.p.useProp ? 'prop' : 'attr']("checked", true); $(this).addClass(highlight).attr("aria-selected", "true"); ts.p.selarrrow.push(this.id); ts.p.selrow = this.id; if (froz) { $("#jqg_" + $.jgrid.jqID(ts.p.id) + "_" + $.jgrid.jqID(this.id), ts.grid.fbDiv)[ts.p.useProp ? 'prop' : 'attr']("checked", true); $("#" + $.jgrid.jqID(this.id), ts.grid.fbDiv).addClass(highlight); } } } }); chk = true; emp = []; } else { $(ts.rows).each(function (i) { if (i > 0) { if (!$(this).hasClass("ui-subgrid") && !$(this).hasClass("jqgroup") && !$(this).hasClass(disabled) && !$(this).hasClass("jqfoot")) { $("#jqg_" + $.jgrid.jqID(ts.p.id) + "_" + $.jgrid.jqID(this.id))[ts.p.useProp ? 'prop' : 'attr']("checked", false); $(this).removeClass(highlight).attr("aria-selected", "false"); emp.push(this.id); if (froz) { $("#jqg_" + $.jgrid.jqID(ts.p.id) + "_" + $.jgrid.jqID(this.id), ts.grid.fbDiv)[ts.p.useProp ? 'prop' : 'attr']("checked", false); $("#" + $.jgrid.jqID(this.id), ts.grid.fbDiv).removeClass(highlight); } } } }); ts.p.selrow = null; chk = false; } $(ts).triggerHandler("jqGridSelectAll", [chk ? ts.p.selarrrow : emp, chk]); if ($.isFunction(ts.p.onSelectAll)) { ts.p.onSelectAll.call(ts, chk ? ts.p.selarrrow : emp, chk); } }); } if (ts.p.autowidth === true) { var pw = $(eg).innerWidth(); ts.p.width = pw > 0 ? pw : 'nw'; } setColWidth(); $(eg).css("width", grid.width + "px").append("
 
"); if (ts.p.scrollPopUp) { $(eg).append("
"); } $(gv).css("width", grid.width + "px"); thead = $("thead:first", ts).get(0); var tfoot = ""; if (ts.p.footerrow) { tfoot += ""; } var thr = $("tr:first", thead), firstr = ""; ts.p.disableClick = false; $("th", thr).each(function (j) { tmpcm = ts.p.colModel[j]; w = tmpcm.width; if (tmpcm.resizable === undefined) { tmpcm.resizable = true; } if (tmpcm.resizable) { res = document.createElement("span"); $(res).html(" ").addClass('ui-jqgrid-resize ui-jqgrid-resize-' + dir) .css("cursor", "col-resize"); $(this).addClass(ts.p.resizeclass); } else { res = ""; } $(this).css("width", w + "px").prepend(res); res = null; var hdcol = ""; if (tmpcm.hidden) { $(this).css("display", "none"); hdcol = "display:none;"; } firstr += ""; grid.headers[j] = { width: w, el: this }; sort = tmpcm.sortable; if (typeof sort !== 'boolean') { tmpcm.sortable = true; sort = true; } var nm = tmpcm.name; if (!(nm === 'cb' || nm === 'subgrid' || nm === 'rn')) { if (ts.p.viewsortcols[2]) { $(">div", this).addClass('ui-jqgrid-sortable'); } } if (sort) { if (ts.p.multiSort) { if (ts.p.viewsortcols[0]) { $("div span.s-ico", this).show(); if (ts.p.colModel[j].lso) { $("div span.ui-icon-" + tmpcm.lso, this).removeClass(disabled).css("display", ""); } } else if (ts.p.colModel[j].lso) { $("div span.s-ico", this).show(); $("div span.ui-icon-" + tmpcm.lso, this).removeClass(disabled).css("display", ""); } } else { if (ts.p.viewsortcols[0]) { $("div span.s-ico", this).show(); if (j === ts.p.lastsort) { $("div span.ui-icon-" + ts.p.sortorder, this).removeClass(disabled).css("display", ""); } } else if (j === ts.p.lastsort && ts.p.sortname !== "") { $("div span.s-ico", this).show(); $("div span.ui-icon-" + ts.p.sortorder, this).removeClass(disabled).css("display", ""); } } } if (ts.p.footerrow) { tfoot += ""; } }).mousedown(function (e) { if ($(e.target).closest("th>span.ui-jqgrid-resize").length !== 1) { return; } var ci = getColumnHeaderIndex(this); if (ts.p.forceFit === true) { ts.p.nv = nextVisible(ci); } grid.dragStart(ci, e, getOffset(ci)); return false; }).click(function (e) { if (ts.p.disableClick) { ts.p.disableClick = false; return false; } var s = "th>div.ui-jqgrid-sortable", r, d; if (!ts.p.viewsortcols[2]) { s = "th>div>span>span.ui-grid-ico-sort"; } var t = $(e.target).closest(s); if (t.length !== 1) { return; } var ci; if (ts.p.frozenColumns) { var tid = $(this)[0].id.substring(ts.p.id.length + 1); $(ts.p.colModel).each(function (i) { if (this.name === tid) { ci = i; return false; } }); } else { ci = getColumnHeaderIndex(this); } // if ($(e.target).hasClass('colmenuspan')) { if ($("#column_menu")[0] != null) { $("#column_menu").remove(); } var colindex = $.jgrid.getCellIndex(e.target); if (colindex === -1) { return; } var offset = $(this).offset(), left = (offset.left), top = (offset.top); buildColMenu(colindex, left, top, t); e.stopPropagation(); return; } // if (!ts.p.viewsortcols[2]) { r = true; d = t.attr("sort"); } if (ci != null) { sortData($('div', this)[0].id, ci, r, d, this); } return false; }); tmpcm = null; if (ts.p.sortable && $.fn.sortable) { try { $(ts).jqGrid("sortableColumns", thr); } catch (e) { } } if (ts.p.footerrow) { tfoot += "
 
"; } firstr += ""; tbody = document.createElement("tbody"); //$(this).append(firstr); this.appendChild(tbody); $(this).addClass(getstyle(stylemodule, "rowTable", true, 'ui-jqgrid-btable ui-common-table')).append(firstr); //$(firstr).insertAfter(this); firstr = null; var hTable = $("
").append(thead), hg = (ts.p.caption && ts.p.hiddengrid === true) ? true : false, hb = $("
"), bstw = ts.p.styleUI === 'Bootstrap' ? 2 : 0; thead = null; grid.hDiv = document.createElement("div"); grid.hDiv.style.width = (grid.width - bstw) + "px"; grid.hDiv.className = getstyle(stylemodule, 'headerDiv', true, 'ui-jqgrid-hdiv'); $(grid.hDiv).append(hb); $(hb).append(hTable); hTable = null; if (hg) { $(grid.hDiv).hide(); } if (ts.p.pager) { // TBD -- escape ts.p.pager here? if (typeof ts.p.pager === "string") { if (ts.p.pager.substr(0, 1) !== "#") { ts.p.pager = "#" + ts.p.pager; } } else { ts.p.pager = "#" + $(ts.p.pager).attr("id"); } $(ts.p.pager).css({ width: grid.width + "px" }).addClass(getstyle(stylemodule, 'pagerBox', true, 'ui-jqgrid-pager')).appendTo(eg); if (hg) { $(ts.p.pager).hide(); } setPager(ts.p.pager, ''); } if (ts.p.cellEdit === false && ts.p.hoverrows === true) { $(ts).bind('mouseover', function (e) { ptr = $(e.target).closest("tr.jqgrow"); if ($(ptr).attr("class") !== "ui-subgrid") { $(ptr).addClass(hover); } }).bind('mouseout', function (e) { ptr = $(e.target).closest("tr.jqgrow"); $(ptr).removeClass(hover); }); } var ri, ci, tdHtml; $(ts).before(grid.hDiv).click(function (e) { td = e.target; ptr = $(td, ts.rows).closest("tr.jqgrow"); if ($(ptr).length === 0 || ptr[0].className.indexOf(disabled) > -1 || ($(td, ts).closest("table.ui-jqgrid-btable").attr('id') || '').replace("_frozen", "") !== ts.id) { return this; } var scb = $(td).filter(":enabled").hasClass("cbox"), cSel = $(ts).triggerHandler("jqGridBeforeSelectRow", [ptr[0].id, e]); cSel = (cSel === false || cSel === 'stop') ? false : true; if ($.isFunction(ts.p.beforeSelectRow)) { var allowRowSelect = ts.p.beforeSelectRow.call(ts, ptr[0].id, e); if (allowRowSelect === false || allowRowSelect === 'stop') { cSel = false; } } if (td.tagName === 'A' || ((td.tagName === 'INPUT' || td.tagName === 'TEXTAREA' || td.tagName === 'OPTION' || td.tagName === 'SELECT') && !scb)) { return; } ri = ptr[0].id; td = $(td).closest("tr.jqgrow>td"); if (td.length > 0) { ci = $.jgrid.getCellIndex(td); tdHtml = $(td).closest("td,th").html(); $(ts).triggerHandler("jqGridCellSelect", [ri, ci, tdHtml, e]); if ($.isFunction(ts.p.onCellSelect)) { ts.p.onCellSelect.call(ts, ri, ci, tdHtml, e); } } if (ts.p.cellEdit === true) { if (ts.p.multiselect && scb && cSel) { $(ts).jqGrid("setSelection", ri, true, e); } else if (td.length > 0) { try { $(ts).jqGrid("editCell", ptr[0].rowIndex, ci, true); } catch (_) { } } return; } if (!cSel) { return; } if (!ts.p.multikey) { if (ts.p.multiselect && ts.p.multiboxonly) { if (scb) { $(ts).jqGrid("setSelection", ri, true, e); } else { var frz = ts.p.frozenColumns ? ts.p.id + "_frozen" : ""; $(ts.p.selarrrow).each(function (i, n) { var trid = $(ts).jqGrid('getGridRowById', n); if (trid) { $(trid).removeClass(highlight); } $("#jqg_" + $.jgrid.jqID(ts.p.id) + "_" + $.jgrid.jqID(n))[ts.p.useProp ? 'prop' : 'attr']("checked", false); if (frz) { $("#" + $.jgrid.jqID(n), "#" + $.jgrid.jqID(frz)).removeClass(highlight); $("#jqg_" + $.jgrid.jqID(ts.p.id) + "_" + $.jgrid.jqID(n), "#" + $.jgrid.jqID(frz))[ts.p.useProp ? 'prop' : 'attr']("checked", false); } }); ts.p.selarrrow = []; $(ts).jqGrid("setSelection", ri, true, e); } } else { $(ts).jqGrid("setSelection", ri, true, e); } } else { if (e[ts.p.multikey]) { $(ts).jqGrid("setSelection", ri, true, e); } else if (ts.p.multiselect && scb) { scb = $("#jqg_" + $.jgrid.jqID(ts.p.id) + "_" + ri).is(":checked"); $("#jqg_" + $.jgrid.jqID(ts.p.id) + "_" + ri)[ts.p.useProp ? 'prop' : 'attr']("checked", !scb); } } }).bind('reloadGrid', function (e, opts) { if (ts.p.treeGrid === true) { ts.p.datatype = ts.p.treedatatype; } opts = opts || {}; if (opts.current) { ts.grid.selectionPreserver(ts); } if (ts.p.datatype === "local") { $(ts).jqGrid("resetSelection"); if (ts.p.data.length) { normalizeData(); refreshIndex(); } } else if (!ts.p.treeGrid) { ts.p.selrow = null; if (ts.p.multiselect) { ts.p.selarrrow = []; setHeadCheckBox(false); } ts.p.savedRow = []; } if (ts.p.scroll) { emptyRows.call(ts, true, false); } if (opts.page) { var page = opts.page; if (page > ts.p.lastpage) { page = ts.p.lastpage; } if (page < 1) { page = 1; } ts.p.page = page; if (ts.grid.prevRowHeight) { ts.grid.bDiv.scrollTop = (page - 1) * ts.grid.prevRowHeight * ts.p.rowNum; } else { ts.grid.bDiv.scrollTop = 0; } } if (ts.grid.prevRowHeight && ts.p.scroll && opts.page === undefined) { delete ts.p.lastpage; ts.grid.populateVisible(); } else { ts.grid.populate(); } if (ts.p.inlineNav === true) { $(ts).jqGrid('showAddEditButtons'); } return false; }) .dblclick(function (e) { td = e.target; ptr = $(td, ts.rows).closest("tr.jqgrow"); if ($(ptr).length === 0) { return; } ri = ptr[0].rowIndex; ci = $.jgrid.getCellIndex(td); var dbcr = $(ts).triggerHandler("jqGridDblClickRow", [$(ptr).attr("id"), ri, ci, e]); if (dbcr != null) { return dbcr; } if ($.isFunction(ts.p.ondblClickRow)) { dbcr = ts.p.ondblClickRow.call(ts, $(ptr).attr("id"), ri, ci, e); if (dbcr != null) { return dbcr; } } }) .bind('contextmenu', function (e) { td = e.target; ptr = $(td, ts.rows).closest("tr.jqgrow"); if ($(ptr).length === 0) { return; } if (!ts.p.multiselect) { $(ts).jqGrid("setSelection", ptr[0].id, true, e); } ri = ptr[0].rowIndex; ci = $.jgrid.getCellIndex(td); var rcr = $(ts).triggerHandler("jqGridRightClickRow", [$(ptr).attr("id"), ri, ci, e]); if (rcr != null) { return rcr; } if ($.isFunction(ts.p.onRightClickRow)) { rcr = ts.p.onRightClickRow.call(ts, $(ptr).attr("id"), ri, ci, e); if (rcr != null) { return rcr; } } }); grid.bDiv = document.createElement("div"); if (isMSIE) { if (String(ts.p.height).toLowerCase() === "auto") { ts.p.height = "100%"; } } $(grid.bDiv) .append($('
').append('
').append(this)) .addClass("ui-jqgrid-bdiv") .css({ height: ts.p.height + (isNaN(ts.p.height) ? "" : "px"), width: (grid.width - bstw) + "px" }) .scroll(grid.scrollGrid); $("table:first", grid.bDiv).css({ width: ts.p.tblwidth + "px" }); if (!$.support.tbody) { //IE if ($("tbody", this).length === 2) { $("tbody:gt(0)", this).remove(); } } if (ts.p.multikey) { if ($.jgrid.msie) { $(grid.bDiv).bind("selectstart", function () { return false; }); } else { $(grid.bDiv).bind("mousedown", function () { return false; }); } } if (hg) { // hidden grid $(grid.bDiv).hide(); } var icoo = iconbase + " " + getstyle(stylemodule, 'icon_caption_open', true), icoc = iconbase + " " + getstyle(stylemodule, 'icon_caption_close', true); grid.cDiv = document.createElement("div"); var arf = ts.p.hidegrid === true ? $("").hover( function () { arf.addClass(hover); }, function () { arf.removeClass(hover); }) .append("").css((dir === "rtl" ? "left" : "right"), "0px") : ""; $(grid.cDiv).append(arf).append("" + ts.p.caption + "") .addClass("ui-jqgrid-titlebar ui-jqgrid-caption" + (dir === "rtl" ? "-rtl" : "") + " " + getstyle(stylemodule, 'gridtitleBox', true)); $(grid.cDiv).insertBefore(grid.hDiv); if (ts.p.toolbar[0]) { var tbstyle = getstyle(stylemodule, 'customtoolbarBox', true, 'ui-userdata'); grid.uDiv = document.createElement("div"); if (ts.p.toolbar[1] === "top") { $(grid.uDiv).insertBefore(grid.hDiv); } else if (ts.p.toolbar[1] === "bottom") { $(grid.uDiv).insertAfter(grid.hDiv); } if (ts.p.toolbar[1] === "both") { grid.ubDiv = document.createElement("div"); $(grid.uDiv).addClass(tbstyle + " ui-userdata-top").attr("id", "t_" + this.id).insertBefore(grid.hDiv).width(grid.width - bstw); $(grid.ubDiv).addClass(tbstyle + " ui-userdata-bottom").attr("id", "tb_" + this.id).insertAfter(grid.hDiv).width(grid.width - bstw); if (hg) { $(grid.ubDiv).hide(); } } else { $(grid.uDiv).width(grid.width - bstw).addClass(tbstyle + " ui-userdata-top").attr("id", "t_" + this.id); } if (hg) { $(grid.uDiv).hide(); } } if (ts.p.toppager) { ts.p.toppager = $.jgrid.jqID(ts.p.id) + "_toppager"; grid.topDiv = $("
")[0]; ts.p.toppager = "#" + ts.p.toppager; $(grid.topDiv).addClass(getstyle(stylemodule, 'toppagerBox', true, 'ui-jqgrid-toppager')).width(grid.width - bstw).insertBefore(grid.hDiv); setPager(ts.p.toppager, '_t'); } if (ts.p.footerrow) { grid.sDiv = $("
")[0]; hb = $("
"); $(grid.sDiv).append(hb).width(grid.width - bstw).insertAfter(grid.hDiv); $(hb).append(tfoot); grid.footers = $(".ui-jqgrid-ftable", grid.sDiv)[0].rows[0].cells; if (ts.p.rownumbers) { grid.footers[0].className = getstyle(stylemodule, 'rownumBox', true, 'jqgrid-rownum'); } if (hg) { $(grid.sDiv).hide(); } } hb = null; if (ts.p.caption) { var tdt = ts.p.datatype; if (ts.p.hidegrid === true) { $(".ui-jqgrid-titlebar-close", grid.cDiv).click(function (e) { var onHdCl = $.isFunction(ts.p.onHeaderClick), elems = ".ui-jqgrid-bdiv, .ui-jqgrid-hdiv, .ui-jqgrid-toppager, .ui-jqgrid-pager, .ui-jqgrid-sdiv", counter, self = this; if (ts.p.toolbar[0] === true) { if (ts.p.toolbar[1] === 'both') { elems += ', #' + $(grid.ubDiv).attr('id'); } elems += ', #' + $(grid.uDiv).attr('id'); } counter = $(elems, "#gview_" + $.jgrid.jqID(ts.p.id)).length; if (ts.p.gridstate === 'visible') { $(elems, "#gbox_" + $.jgrid.jqID(ts.p.id)).slideUp("fast", function () { counter--; if (counter === 0) { $("span", self).removeClass(icoo).addClass(icoc); ts.p.gridstate = 'hidden'; if ($("#gbox_" + $.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle", "#gbox_" + $.jgrid.jqID(ts.p.id)).hide(); } $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate, e]); if (onHdCl) { if (!hg) { ts.p.onHeaderClick.call(ts, ts.p.gridstate, e); } } } }); } else if (ts.p.gridstate === 'hidden') { $(elems, "#gbox_" + $.jgrid.jqID(ts.p.id)).slideDown("fast", function () { counter--; if (counter === 0) { $("span", self).removeClass(icoc).addClass(icoo); if (hg) { ts.p.datatype = tdt; populate(); hg = false; } ts.p.gridstate = 'visible'; if ($("#gbox_" + $.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle", "#gbox_" + $.jgrid.jqID(ts.p.id)).show(); } $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate, e]); if (onHdCl) { if (!hg) { ts.p.onHeaderClick.call(ts, ts.p.gridstate, e); } } } }); } return false; }); if (hg) { ts.p.datatype = "local"; $(".ui-jqgrid-titlebar-close", grid.cDiv).trigger("click"); } } } else { $(grid.cDiv).hide(); if (!ts.p.toppager) { $(grid.hDiv).addClass(getstyle(ts.p.styleUI + '.common', 'cornertop', true)); } } $(grid.hDiv).after(grid.bDiv) .mousemove(function (e) { if (grid.resizing) { grid.dragMove(e); return false; } }); $(".ui-jqgrid-labels", grid.hDiv).bind("selectstart", function () { return false; }); $(document).bind("mouseup.jqGrid" + ts.p.id, function () { if (grid.resizing) { grid.dragEnd(true); return false; } return true; }); ts.formatCol = formatCol; ts.sortData = sortData; ts.updatepager = updatepager; ts.refreshIndex = refreshIndex; ts.setHeadCheckBox = setHeadCheckBox; ts.constructTr = constructTr; ts.formatter = function (rowId, cellval, colpos, rwdat, act) { return formatter(rowId, cellval, colpos, rwdat, act); }; $.extend(grid, { populate: populate, emptyRows: emptyRows, beginReq: beginReq, endReq: endReq }); this.grid = grid; ts.addXmlData = function (d) { addXmlData(d); }; ts.addJSONData = function (d) { addJSONData(d); }; this.grid.cols = this.rows[0].cells; $(ts).triggerHandler("jqGridInitGrid"); if ($.isFunction(ts.p.onInitGrid)) { ts.p.onInitGrid.call(ts); } populate(); ts.p.hiddengrid = false; if (ts.p.responsive) { var supportsOrientationChange = "onorientationchange" in window, orientationEvent = supportsOrientationChange ? "orientationchange" : "resize"; $(window).on(orientationEvent, function () { $(ts).jqGrid('resizeGrid'); }); } }); }; $.jgrid.extend({ getGridParam: function (name, module) { var $t = this[0], ret; if (!$t || !$t.grid) { return; } if (module === undefined && typeof module !== 'string') { module = 'jqGrid'; //$t.p } ret = $t.p; if (module !== 'jqGrid') { try { ret = $($t).data(module); } catch (e) { ret = $t.p; } } if (!name) { return ret; } return ret[name] !== undefined ? ret[name] : null; }, setGridParam: function (newParams, overwrite) { return this.each(function () { if (overwrite == null) { overwrite = false; } if (this.grid && typeof newParams === 'object') { if (overwrite === true) { var params = $.extend({}, this.p, newParams); this.p = params; } else { $.extend(true, this.p, newParams); } } }); }, getGridRowById: function (rowid) { var row; this.each(function () { try { //row = this.rows.namedItem( rowid ); var i = this.rows.length; while (i--) { if (rowid.toString() === this.rows[i].id) { row = this.rows[i]; break; } } } catch (e) { row = $(this.grid.bDiv).find("#" + $.jgrid.jqID(rowid)); } }); return row; }, getDataIDs: function () { var ids = [], i = 0, len, j = 0; this.each(function () { len = this.rows.length; if (len && len > 0) { while (i < len) { if ($(this.rows[i]).hasClass('jqgrow')) { ids[j] = this.rows[i].id; j++; } i++; } } }); return ids; }, setSelection: function (selection, onsr, e) { return this.each(function () { var $t = this, stat, pt, ner, ia, tpsr, fid, csr, getstyle = $.jgrid.getMethod("getStyleUI"), highlight = getstyle($t.p.styleUI + '.common', 'highlight', true), disabled = getstyle($t.p.styleUI + '.common', 'disabled', true); if (selection === undefined) { return; } onsr = onsr === false ? false : true; pt = $($t).jqGrid('getGridRowById', selection); if (!pt || !pt.className || pt.className.indexOf(disabled) > -1) { return; } function scrGrid(iR) { var ch = $($t.grid.bDiv)[0].clientHeight, st = $($t.grid.bDiv)[0].scrollTop, rpos = $($t.rows[iR]).position().top, rh = $t.rows[iR].clientHeight; if (rpos + rh >= ch + st) { $($t.grid.bDiv)[0].scrollTop = rpos - (ch + st) + rh + st; } else if (rpos < ch + st) { if (rpos < st) { $($t.grid.bDiv)[0].scrollTop = rpos; } } } if ($t.p.scrollrows === true) { ner = $($t).jqGrid('getGridRowById', selection).rowIndex; if (ner >= 0) { scrGrid(ner); } } if ($t.p.frozenColumns === true) { fid = $t.p.id + "_frozen"; } if (!$t.p.multiselect) { if (pt.className !== "ui-subgrid") { if ($t.p.selrow !== pt.id) { csr = $($t).jqGrid('getGridRowById', $t.p.selrow); if (csr) { $(csr).removeClass(highlight).attr({ "aria-selected": "false", "tabindex": "-1" }); } $(pt).addClass(highlight).attr({ "aria-selected": "true", "tabindex": "0" });//.focus(); if (fid) { $("#" + $.jgrid.jqID($t.p.selrow), "#" + $.jgrid.jqID(fid)).removeClass(highlight); $("#" + $.jgrid.jqID(selection), "#" + $.jgrid.jqID(fid)).addClass(highlight); } stat = true; } else { stat = false; } $t.p.selrow = pt.id; if (onsr) { $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]); if ($t.p.onSelectRow) { $t.p.onSelectRow.call($t, pt.id, stat, e); } } } } else { //unselect selectall checkbox when deselecting a specific row $t.setHeadCheckBox(false); $t.p.selrow = pt.id; ia = $.inArray($t.p.selrow, $t.p.selarrrow); if (ia === -1) { if (pt.className !== "ui-subgrid") { $(pt).addClass(highlight).attr("aria-selected", "true"); } stat = true; $t.p.selarrrow.push($t.p.selrow); } else { if (pt.className !== "ui-subgrid") { $(pt).removeClass(highlight).attr("aria-selected", "false"); } stat = false; $t.p.selarrrow.splice(ia, 1); tpsr = $t.p.selarrrow[0]; $t.p.selrow = (tpsr === undefined) ? null : tpsr; } $("#jqg_" + $.jgrid.jqID($t.p.id) + "_" + $.jgrid.jqID(pt.id))[$t.p.useProp ? 'prop' : 'attr']("checked", stat); if (fid) { if (ia === -1) { $("#" + $.jgrid.jqID(selection), "#" + $.jgrid.jqID(fid)).addClass(highlight); } else { $("#" + $.jgrid.jqID(selection), "#" + $.jgrid.jqID(fid)).removeClass(highlight); } $("#jqg_" + $.jgrid.jqID($t.p.id) + "_" + $.jgrid.jqID(selection), "#" + $.jgrid.jqID(fid))[$t.p.useProp ? 'prop' : 'attr']("checked", stat); } if (onsr) { $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]); if ($t.p.onSelectRow) { $t.p.onSelectRow.call($t, pt.id, stat, e); } } } }); }, resetSelection: function (rowid) { return this.each(function () { var t = this, sr, fid, getstyle = $.jgrid.getMethod("getStyleUI"), highlight = getstyle(t.p.styleUI + '.common', 'highlight', true), hover = getstyle(t.p.styleUI + '.common', 'hover', true); if (t.p.frozenColumns === true) { fid = t.p.id + "_frozen"; } if (rowid !== undefined) { sr = rowid === t.p.selrow ? t.p.selrow : rowid; $("#" + $.jgrid.jqID(t.p.id) + " tbody:first tr#" + $.jgrid.jqID(sr)).removeClass(highlight).attr("aria-selected", "false"); if (fid) { $("#" + $.jgrid.jqID(sr), "#" + $.jgrid.jqID(fid)).removeClass(highlight); } if (t.p.multiselect) { $("#jqg_" + $.jgrid.jqID(t.p.id) + "_" + $.jgrid.jqID(sr), "#" + $.jgrid.jqID(t.p.id))[t.p.useProp ? 'prop' : 'attr']("checked", false); if (fid) { $("#jqg_" + $.jgrid.jqID(t.p.id) + "_" + $.jgrid.jqID(sr), "#" + $.jgrid.jqID(fid))[t.p.useProp ? 'prop' : 'attr']("checked", false); } t.setHeadCheckBox(false); var ia = $.inArray($.jgrid.jqID(sr), t.p.selarrrow); if (ia !== -1) { t.p.selarrrow.splice(ia, 1); } } if (t.p.onUnSelectRow) { t.p.onUnSelectRow.call(t, sr); } sr = null; } else if (!t.p.multiselect) { if (t.p.selrow) { $("#" + $.jgrid.jqID(t.p.id) + " tbody:first tr#" + $.jgrid.jqID(t.p.selrow)).removeClass(highlight).attr("aria-selected", "false"); if (fid) { $("#" + $.jgrid.jqID(t.p.selrow), "#" + $.jgrid.jqID(fid)).removeClass(highlight); } if (t.p.onUnSelectRow) { t.p.onUnSelectRow.call(t, t.p.selrow); } t.p.selrow = null; } } else { $(t.p.selarrrow).each(function (i, n) { $($(t).jqGrid('getGridRowById', n)).removeClass(highlight).attr("aria-selected", "false"); $("#jqg_" + $.jgrid.jqID(t.p.id) + "_" + $.jgrid.jqID(n))[t.p.useProp ? 'prop' : 'attr']("checked", false); if (fid) { $("#" + $.jgrid.jqID(n), "#" + $.jgrid.jqID(fid)).removeClass(highlight); $("#jqg_" + $.jgrid.jqID(t.p.id) + "_" + $.jgrid.jqID(n), "#" + $.jgrid.jqID(fid))[t.p.useProp ? 'prop' : 'attr']("checked", false); } if (t.p.onUnSelectRow) { t.p.onUnSelectRow.call(t, n); } }); t.setHeadCheckBox(false); t.p.selarrrow = []; t.p.selrow = null; } if (t.p.cellEdit === true) { if (parseInt(t.p.iCol, 10) >= 0 && parseInt(t.p.iRow, 10) >= 0) { $("td:eq(" + t.p.iCol + ")", t.rows[t.p.iRow]).removeClass("edit-cell " + highlight); $(t.rows[t.p.iRow]).removeClass("selected-row " + hover); } } t.p.savedRow = []; }); }, getRowData: function (rowid, usedata) { var res = {}, resall, getall = false, len, j = 0; this.each(function () { var $t = this, nm, ind; if (rowid == null) { getall = true; resall = []; len = $t.rows.length - 1; } else { ind = $($t).jqGrid('getGridRowById', rowid); if (!ind) { return res; } len = 1; } if (!(usedata && usedata === true && $t.p.data.length > 0)) { usedata = false; } while (j < len) { if (getall) { ind = $t.rows[j]; } if ($(ind).hasClass('jqgrow')) { if (usedata) { res = $t.p.data[$t.p._index[ind.id]]; } else { $('td[role="gridcell"]', ind).each(function (i) { nm = $t.p.colModel[i].name; if (nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') { if ($t.p.treeGrid === true && nm === $t.p.ExpandColumn) { res[nm] = $.jgrid.htmlDecode($("span:first", this).html()); } else { try { res[nm] = $.unformat.call($t, this, { rowId: ind.id, colModel: $t.p.colModel[i] }, i); } catch (e) { res[nm] = $.jgrid.htmlDecode($(this).html()); } } } }); } if (getall) { resall.push(res); res = {}; } } j++; } }); return resall || res; }, delRowData: function (rowid) { var success = false, rowInd, ia, nextRow; this.each(function () { var $t = this; rowInd = $($t).jqGrid('getGridRowById', rowid); if (!rowInd) { return false; } if ($t.p.subGrid) { nextRow = $(rowInd).next(); if (nextRow.hasClass('ui-subgrid')) { nextRow.remove(); } } $(rowInd).remove(); $t.p.records--; $t.p.reccount--; $t.updatepager(true, false); success = true; if ($t.p.multiselect) { ia = $.inArray(rowid, $t.p.selarrrow); if (ia !== -1) { $t.p.selarrrow.splice(ia, 1); } } if ($t.p.multiselect && $t.p.selarrrow.length > 0) { $t.p.selrow = $t.p.selarrrow[$t.p.selarrrow.length - 1]; } else { if ($t.p.selrow === rowid) { $t.p.selrow = null; } } if ($t.p.datatype === 'local') { var id = $.jgrid.stripPref($t.p.idPrefix, rowid), pos = $t.p._index[id]; if (pos !== undefined) { $t.p.data.splice(pos, 1); $t.refreshIndex(); } } if ($t.p.altRows === true && success) { var cn = $t.p.altclass; $($t.rows).each(function (i) { if (i % 2 === 1) { $(this).addClass(cn); } else { $(this).removeClass(cn); } }); } }); return success; }, setRowData: function (rowid, data, cssp) { var nm, success = true, title; this.each(function () { if (!this.grid) { return false; } var t = this, vl, ind, cp = typeof cssp, lcdata = {}; ind = $(this).jqGrid('getGridRowById', rowid); if (!ind) { return false; } if (data) { try { $(this.p.colModel).each(function (i) { nm = this.name; var dval = $.jgrid.getAccessor(data, nm); if (dval !== undefined) { lcdata[nm] = this.formatter && typeof this.formatter === 'string' && this.formatter === 'date' ? $.unformat.date.call(t, dval, this) : dval; vl = t.formatter(rowid, lcdata[nm], i, data, 'edit'); title = this.title ? { "title": $.jgrid.stripHtml(vl) } : {}; if (t.p.treeGrid === true && nm === t.p.ExpandColumn) { $("td[role='gridcell']:eq(" + i + ") > span:first", ind).html(vl).attr(title); } else { $("td[role='gridcell']:eq(" + i + ")", ind).html(vl).attr(title); } } }); if (t.p.datatype === 'local') { var id = $.jgrid.stripPref(t.p.idPrefix, rowid), pos = t.p._index[id], key; if (t.p.treeGrid) { for (key in t.p.treeReader) { if (t.p.treeReader.hasOwnProperty(key)) { delete lcdata[t.p.treeReader[key]]; } } } if (pos !== undefined) { t.p.data[pos] = $.extend(true, t.p.data[pos], lcdata); } lcdata = null; } } catch (e) { success = false; } } if (success) { if (cp === 'string') { $(ind).addClass(cssp); } else if (cssp !== null && cp === 'object') { $(ind).css(cssp); } $(t).triggerHandler("jqGridAfterGridComplete"); } }); return success; }, addRowData: function (rowid, rdata, pos, src) { if ($.inArray(pos, ["first", "last", "before", "after"]) === -1) { pos = "last"; } var success = false, nm, row, rnc = "", msc = "", gi, si, ni, sind, i, v, prp = "", aradd, cnm, cn, data, cm, id; if (rdata) { if ($.isArray(rdata)) { aradd = true; //pos = "last"; cnm = rowid; } else { rdata = [rdata]; aradd = false; } this.each(function () { var t = this, datalen = rdata.length; ni = t.p.rownumbers === true ? 1 : 0; gi = t.p.multiselect === true ? 1 : 0; si = t.p.subGrid === true ? 1 : 0; if (!aradd) { if (rowid !== undefined) { rowid = String(rowid); } else { rowid = $.jgrid.randId(); if (t.p.keyName !== false) { cnm = t.p.keyName; if (rdata[0][cnm] !== undefined) { rowid = rdata[0][cnm]; } } } } cn = t.p.altclass; var k = 0, cna = $(t).jqGrid('getStyleUI', t.p.styleUI + ".base", 'rowBox', true, 'jqgrow ui-row-' + t.p.direction), lcdata = {}, classes, air = $.isFunction(t.p.afterInsertRow) ? true : false; if (ni) { rnc = $(t).jqGrid('getStyleUI', t.p.styleUI + ".base", 'rownumBox', false, 'jqgrid-rownum'); } if (gi) { msc = $(t).jqGrid('getStyleUI', t.p.styleUI + ".base", 'multiBox', false, 'cbox'); } while (k < datalen) { data = rdata[k]; row = []; classes = cna; if (aradd) { try { rowid = data[cnm]; if (rowid === undefined) { rowid = $.jgrid.randId(); } } catch (e) { rowid = $.jgrid.randId(); } classes += (t.p.altRows === true ? (t.rows.length - 1) % 2 === 0 ? " " + cn : "" : ""); } id = rowid; rowid = t.p.idPrefix + rowid; if (ni) { prp = t.formatCol(0, 1, '', null, rowid, true); row[row.length] = "0"; } if (gi) { //v = ""; v = ""; // v = "
"; prp = t.formatCol(ni, 1, '', null, rowid, true); row[row.length] = "" + v + ""; } if (si) { row[row.length] = $(t).jqGrid("addSubGridCell", gi + ni, 1); } for (i = gi + si + ni; i < t.p.colModel.length; i++) { cm = t.p.colModel[i]; nm = cm.name; lcdata[nm] = data[nm]; v = t.formatter(rowid, $.jgrid.getAccessor(data, nm), i, data); prp = t.formatCol(i, 1, v, data, rowid, lcdata); row[row.length] = "" + v + ""; } row.unshift(t.constructTr(rowid, false, classes, lcdata, data)); row[row.length] = ""; if (t.rows.length === 0) { $("table:first", t.grid.bDiv).append(row.join('')); } else { switch (pos) { case 'last': $(t.rows[t.rows.length - 1]).after(row.join('')); sind = t.rows.length - 1; break; case 'first': $(t.rows[0]).after(row.join('')); sind = 1; break; case 'after': sind = $(t).jqGrid('getGridRowById', src); if (sind) { if ($(t.rows[sind.rowIndex + 1]).hasClass("ui-subgrid")) { $(t.rows[sind.rowIndex + 1]).after(row); } else { $(sind).after(row.join('')); } sind = sind.rowIndex + 1; } break; case 'before': sind = $(t).jqGrid('getGridRowById', src); if (sind) { $(sind).before(row.join('')); sind = sind.rowIndex - 1; } break; } } if (t.p.subGrid === true) { $(t).jqGrid("addSubGrid", gi + ni, sind); } t.p.records++; t.p.reccount++; $(t).triggerHandler("jqGridAfterInsertRow", [rowid, data, data]); if (air) { t.p.afterInsertRow.call(t, rowid, data, data); } k++; if (t.p.datatype === 'local') { lcdata[t.p.localReader.id] = id; t.p._index[id] = t.p.data.length; t.p.data.push(lcdata); lcdata = {}; } } if (t.p.altRows === true && !aradd) { if (pos === "last") { if ((t.rows.length - 1) % 2 === 0) { $(t.rows[t.rows.length - 1]).addClass(cn); } } else { $(t.rows).each(function (i) { if (i % 2 === 0) { $(this).addClass(cn); } else { $(this).removeClass(cn); } }); } } t.updatepager(true, true); success = true; }); } return success; }, footerData: function (action, data, format) { var nm, success = false, res = {}, title; function isEmpty(obj) { var i; for (i in obj) { if (obj.hasOwnProperty(i)) { return false; } } return true; } if (action === undefined) { action = "get"; } if (typeof format !== "boolean") { format = true; } action = action.toLowerCase(); this.each(function () { var t = this, vl; if (!t.grid || !t.p.footerrow) { return false; } if (action === "set") { if (isEmpty(data)) { return false; } } success = true; $(this.p.colModel).each(function (i) { nm = this.name; if (action === "set") { if (data[nm] !== undefined) { vl = format ? t.formatter("", data[nm], i, data, 'edit') : data[nm]; title = this.title ? { "title": $.jgrid.stripHtml(vl) } : {}; $("tr.footrow td:eq(" + i + ")", t.grid.sDiv).html(vl).attr(title); success = true; } } else if (action === "get") { res[nm] = $("tr.footrow td:eq(" + i + ")", t.grid.sDiv).html(); } }); }); return action === "get" ? res : success; }, showHideCol: function (colname, show) { return this.each(function () { var $t = this, fndh = false, brd = $.jgrid.cell_width ? 0 : $t.p.cellLayout, cw; if (!$t.grid) { return; } if (typeof colname === 'string') { colname = [colname]; } show = show !== "none" ? "" : "none"; var sw = show === "" ? true : false, gh = $t.p.groupHeader && ($.isArray($t.p.groupHeader) || $.isFunction($t.p.groupHeader)); if (gh) { $($t).jqGrid('destroyGroupHeader', false); } $(this.p.colModel).each(function (i) { if ($.inArray(this.name, colname) !== -1 && this.hidden === sw) { if ($t.p.frozenColumns === true && this.frozen === true) { return true; } $("tr[role=row]", $t.grid.hDiv).each(function () { $(this.cells[i]).css("display", show); }); $($t.rows).each(function () { if (!$(this).hasClass("jqgroup")) { $(this.cells[i]).css("display", show); } }); if ($t.p.footerrow) { $("tr.footrow td:eq(" + i + ")", $t.grid.sDiv).css("display", show); } cw = parseInt(this.width, 10); if (show === "none") { $t.p.tblwidth -= cw + brd; } else { $t.p.tblwidth += cw + brd; } this.hidden = !sw; fndh = true; $($t).triggerHandler("jqGridShowHideCol", [sw, this.name, i]); } }); if (fndh === true) { if ($t.p.shrinkToFit === true && !isNaN($t.p.height)) { $t.p.tblwidth += parseInt($t.p.scrollOffset, 10); } $($t).jqGrid("setGridWidth", $t.p.shrinkToFit === true ? $t.p.tblwidth : $t.p.width); } if (gh) { var gHead = $.extend([], $t.p.groupHeader); $t.p.groupHeader = null; for (var k = 0; k < gHead.length; k++) { $($t).jqGrid('setGroupHeaders', gHead[k]); } } }); }, hideCol: function (colname) { return this.each(function () { $(this).jqGrid("showHideCol", colname, "none"); }); }, showCol: function (colname) { return this.each(function () { $(this).jqGrid("showHideCol", colname, ""); }); }, remapColumns: function (permutation, updateCells, keepHeader) { function resortArray(a) { var ac; if (a.length) { ac = $.makeArray(a); } else { ac = $.extend({}, a); } $.each(permutation, function (i) { a[i] = ac[this]; }); } var ts = this.get(0); function resortRows(parent, clobj) { $(">tr" + (clobj || ""), parent).each(function () { var row = this; var elems = $.makeArray(row.cells); $.each(permutation, function () { var e = elems[this]; if (e) { row.appendChild(e); } }); }); } resortArray(ts.p.colModel); resortArray(ts.p.colNames); resortArray(ts.grid.headers); resortRows($("thead:first", ts.grid.hDiv), keepHeader && ":not(.ui-jqgrid-labels)"); if (updateCells) { resortRows($("#" + $.jgrid.jqID(ts.p.id) + " tbody:first"), ".jqgfirstrow, tr.jqgrow, tr.jqfoot"); } if (ts.p.footerrow) { resortRows($("tbody:first", ts.grid.sDiv)); } if (ts.p.remapColumns) { if (!ts.p.remapColumns.length) { ts.p.remapColumns = $.makeArray(permutation); } else { resortArray(ts.p.remapColumns); } } ts.p.lastsort = $.inArray(ts.p.lastsort, permutation); if (ts.p.treeGrid) { ts.p.expColInd = $.inArray(ts.p.expColInd, permutation); } $(ts).triggerHandler("jqGridRemapColumns", [permutation, updateCells, keepHeader]); }, setGridWidth: function (nwidth, shrink) { return this.each(function () { if (!this.grid) { return; } var $t = this, cw, initwidth = 0, brd = $.jgrid.cell_width ? 0 : $t.p.cellLayout, lvc, vc = 0, hs = false, scw = $t.p.scrollOffset, aw, gw = 0, cr, bstw = $t.p.styleUI === 'Bootstrap' ? 2 : 0; if (typeof shrink !== 'boolean') { shrink = $t.p.shrinkToFit; } if (isNaN(nwidth)) { return; } nwidth = parseInt(nwidth, 10); $t.grid.width = $t.p.width = nwidth; $("#gbox_" + $.jgrid.jqID($t.p.id)).css("width", nwidth + "px"); $("#gview_" + $.jgrid.jqID($t.p.id)).css("width", nwidth + "px"); $($t.grid.bDiv).css("width", (nwidth - bstw) + "px"); $($t.grid.hDiv).css("width", (nwidth - bstw) + "px"); if ($t.p.pager) { $($t.p.pager).css("width", nwidth + "px"); } if ($t.p.toppager) { $($t.p.toppager).css("width", (nwidth - bstw) + "px"); } if ($t.p.toolbar[0] === true) { $($t.grid.uDiv).css("width", (nwidth - bstw) + "px"); if ($t.p.toolbar[1] === "both") { $($t.grid.ubDiv).css("width", (nwidth - bstw) + "px"); } } if ($t.p.footerrow) { $($t.grid.sDiv).css("width", (nwidth - bstw) + "px"); } if (shrink === false && $t.p.forceFit === true) { $t.p.forceFit = false; } if (shrink === true) { $.each($t.p.colModel, function () { if (this.hidden === false) { cw = this.widthOrg; initwidth += cw + brd; if (this.fixed) { gw += cw + brd; } else { vc++; } } }); if (vc === 0) { return; } $t.p.tblwidth = initwidth; aw = nwidth - brd * vc - gw; if (!isNaN($t.p.height)) { if ($($t.grid.bDiv)[0].clientHeight < $($t.grid.bDiv)[0].scrollHeight || $t.rows.length === 1) { hs = true; aw -= scw; } } initwidth = 0; var cle = $t.grid.cols.length > 0; $.each($t.p.colModel, function (i) { if (this.hidden === false && !this.fixed) { cw = this.widthOrg; cw = Math.round(aw * cw / ($t.p.tblwidth - brd * vc - gw)); if (cw < 0) { return; } this.width = cw; initwidth += cw; $t.grid.headers[i].width = cw; $t.grid.headers[i].el.style.width = cw + "px"; if ($t.p.footerrow) { $t.grid.footers[i].style.width = cw + "px"; } if (cle) { $t.grid.cols[i].style.width = cw + "px"; } lvc = i; } }); if (!lvc) { return; } cr = 0; if (hs) { if (nwidth - gw - (initwidth + brd * vc) !== scw) { cr = nwidth - gw - (initwidth + brd * vc) - scw; } } else if (Math.abs(nwidth - gw - (initwidth + brd * vc)) !== 1) { cr = nwidth - gw - (initwidth + brd * vc); } $t.p.colModel[lvc].width += cr; $t.p.tblwidth = initwidth + cr + brd * vc + gw; if ($t.p.tblwidth > nwidth) { var delta = $t.p.tblwidth - parseInt(nwidth, 10); $t.p.tblwidth = nwidth; cw = $t.p.colModel[lvc].width = $t.p.colModel[lvc].width - delta; } else { cw = $t.p.colModel[lvc].width; } $t.grid.headers[lvc].width = cw; $t.grid.headers[lvc].el.style.width = cw + "px"; if (cle) { $t.grid.cols[lvc].style.width = cw + "px"; } if ($t.p.footerrow) { $t.grid.footers[lvc].style.width = cw + "px"; } } if ($t.p.tblwidth) { $('table:first', $t.grid.bDiv).css("width", $t.p.tblwidth + "px"); $('table:first', $t.grid.hDiv).css("width", $t.p.tblwidth + "px"); $t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft; if ($t.p.footerrow) { $('table:first', $t.grid.sDiv).css("width", $t.p.tblwidth + "px"); } } }); }, setGridHeight: function (nh) { return this.each(function () { var $t = this; if (!$t.grid) { return; } var bDiv = $($t.grid.bDiv); bDiv.css({ height: nh + (isNaN(nh) ? "" : "px") }); if ($t.p.frozenColumns === true) { //follow the original set height to use 16, better scrollbar width detection $('#' + $.jgrid.jqID($t.p.id) + "_frozen").parent().height(bDiv.height() - 16); } $t.p.height = nh; if ($t.p.scroll) { $t.grid.populateVisible(); } }); }, setCaption: function (newcap) { return this.each(function () { var ctop = $(this).jqGrid('getStyleUI', this.p.styleUI + ".common", 'cornertop', true); this.p.caption = newcap; $(".ui-jqgrid-title, .ui-jqgrid-title-rtl", this.grid.cDiv).html(newcap); $(this.grid.cDiv).show(); $(this.grid.hDiv).removeClass(ctop); }); }, setLabel: function (colname, nData, prop, attrp) { return this.each(function () { var $t = this, pos = -1; if (!$t.grid) { return; } if (colname != null) { if (isNaN(colname)) { $($t.p.colModel).each(function (i) { if (this.name === colname) { pos = i; return false; } }); } else { pos = parseInt(colname, 10); } } else { return; } if (pos >= 0) { var thecol = $("tr.ui-jqgrid-labels th:eq(" + pos + ")", $t.grid.hDiv); if (nData) { var ico = $(".s-ico", thecol); $("[id^=jqgh_]", thecol).empty().html(nData).append(ico); $t.p.colNames[pos] = nData; } if (prop) { if (typeof prop === 'string') { $(thecol).addClass(prop); } else { $(thecol).css(prop); } } if (typeof attrp === 'object') { $(thecol).attr(attrp); } } }); }, setCell: function (rowid, colname, nData, cssp, attrp, forceupd) { return this.each(function () { var $t = this, pos = -1, v, title; if (!$t.grid) { return; } if (isNaN(colname)) { $($t.p.colModel).each(function (i) { if (this.name === colname) { pos = i; return false; } }); } else { pos = parseInt(colname, 10); } if (pos >= 0) { var ind = $($t).jqGrid('getGridRowById', rowid); if (ind) { var tcell = $("td:eq(" + pos + ")", ind), cl = 0, rawdat = []; if (nData !== "" || forceupd === true) { if (ind.cells !== undefined) { while (cl < ind.cells.length) { // slow down speed rawdat.push(ind.cells[cl].innerHTML); cl++; } } v = $t.formatter(rowid, nData, pos, rawdat, 'edit'); title = $t.p.colModel[pos].title ? { "title": $.jgrid.stripHtml(v) } : {}; if ($t.p.treeGrid && $(".tree-wrap", $(tcell)).length > 0) { $("span", $(tcell)).html(v).attr(title); } else { $(tcell).html(v).attr(title); } if ($t.p.datatype === "local") { var cm = $t.p.colModel[pos], index; nData = cm.formatter && typeof cm.formatter === 'string' && cm.formatter === 'date' ? $.unformat.date.call($t, nData, cm) : nData; index = $t.p._index[$.jgrid.stripPref($t.p.idPrefix, rowid)]; if (index !== undefined) { $t.p.data[index][cm.name] = nData; } } } if (typeof cssp === 'string') { $(tcell).addClass(cssp); } else if (cssp) { $(tcell).css(cssp); } if (typeof attrp === 'object') { $(tcell).attr(attrp); } } } }); }, getCell: function (rowid, col) { var ret = false; this.each(function () { var $t = this, pos = -1; if (!$t.grid) { return; } if (isNaN(col)) { $($t.p.colModel).each(function (i) { if (this.name === col) { pos = i; return false; } }); } else { pos = parseInt(col, 10); } if (pos >= 0) { var ind = $($t).jqGrid('getGridRowById', rowid); if (ind) { try { ret = $.unformat.call($t, $("td:eq(" + pos + ")", ind), { rowId: ind.id, colModel: $t.p.colModel[pos] }, pos); } catch (e) { ret = $.jgrid.htmlDecode($("td:eq(" + pos + ")", ind).html()); } } } }); return ret; }, getCol: function (col, obj, mathopr) { var ret = [], val, sum = 0, min, max, v; obj = typeof obj !== 'boolean' ? false : obj; if (mathopr === undefined) { mathopr = false; } this.each(function () { var $t = this, pos = -1; if (!$t.grid) { return; } if (isNaN(col)) { $($t.p.colModel).each(function (i) { if (this.name === col) { pos = i; return false; } }); } else { pos = parseInt(col, 10); } if (pos >= 0) { var ln = $t.rows.length, i = 0, dlen = 0; if (ln && ln > 0) { while (i < ln) { if ($($t.rows[i]).hasClass('jqgrow')) { try { val = $.unformat.call($t, $($t.rows[i].cells[pos]), { rowId: $t.rows[i].id, colModel: $t.p.colModel[pos] }, pos); } catch (e) { val = $.jgrid.htmlDecode($t.rows[i].cells[pos].innerHTML); } if (mathopr) { v = parseFloat(val); if (!isNaN(v)) { sum += v; if (max === undefined) { max = min = v; } min = Math.min(min, v); max = Math.max(max, v); dlen++; } } else if (obj) { ret.push({ id: $t.rows[i].id, value: val }); } else { ret.push(val); } } i++; } if (mathopr) { switch (mathopr.toLowerCase()) { case 'sum': ret = sum; break; case 'avg': ret = sum / dlen; break; case 'count': ret = (ln - 1); break; case 'min': ret = min; break; case 'max': ret = max; break; } } } } }); return ret; }, clearGridData: function (clearfooter) { return this.each(function () { var $t = this; if (!$t.grid) { return; } if (typeof clearfooter !== 'boolean') { clearfooter = false; } if ($t.p.deepempty) { $("#" + $.jgrid.jqID($t.p.id) + " tbody:first tr:gt(0)").remove(); } else { var trf = $("#" + $.jgrid.jqID($t.p.id) + " tbody:first tr:first")[0]; $("#" + $.jgrid.jqID($t.p.id) + " tbody:first").empty().append(trf); } if ($t.p.footerrow && clearfooter) { $(".ui-jqgrid-ftable td", $t.grid.sDiv).html(" "); } $t.p.selrow = null; $t.p.selarrrow = []; $t.p.savedRow = []; $t.p.records = 0; $t.p.page = 1; $t.p.lastpage = 0; $t.p.reccount = 0; $t.p.data = []; $t.p._index = {}; $t.updatepager(true, false); }); }, getInd: function (rowid, rc) { var ret = false, rw; this.each(function () { rw = $(this).jqGrid('getGridRowById', rowid); if (rw) { ret = rc === true ? rw : rw.rowIndex; } }); return ret; }, bindKeys: function (settings) { var o = $.extend({ onEnter: null, onSpace: null, onLeftKey: null, onRightKey: null, scrollingRows: true }, settings || {}); return this.each(function () { var $t = this; if (!$('body').is('[role]')) { $('body').attr('role', 'application'); } $t.p.scrollrows = o.scrollingRows; $($t).keydown(function (event) { var target = $($t).find('tr[tabindex=0]')[0], id, r, mind, expanded = $t.p.treeReader.expanded_field; //check for arrow keys if (target) { mind = $t.p._index[$.jgrid.stripPref($t.p.idPrefix, target.id)]; if (event.keyCode === 37 || event.keyCode === 38 || event.keyCode === 39 || event.keyCode === 40) { // up key if (event.keyCode === 38) { r = target.previousSibling; id = ""; if (r) { if ($(r).is(":hidden")) { while (r) { r = r.previousSibling; if (!$(r).is(":hidden") && $(r).hasClass('jqgrow')) { id = r.id; break; } } } else { id = r.id; } } $($t).jqGrid('setSelection', id, true, event); event.preventDefault(); } //if key is down arrow if (event.keyCode === 40) { r = target.nextSibling; id = ""; if (r) { if ($(r).is(":hidden")) { while (r) { r = r.nextSibling; if (!$(r).is(":hidden") && $(r).hasClass('jqgrow')) { id = r.id; break; } } } else { id = r.id; } } $($t).jqGrid('setSelection', id, true, event); event.preventDefault(); } // left if (event.keyCode === 37) { if ($t.p.treeGrid && $t.p.data[mind][expanded]) { $(target).find("div.treeclick").trigger('click'); } $($t).triggerHandler("jqGridKeyLeft", [$t.p.selrow]); if ($.isFunction(o.onLeftKey)) { o.onLeftKey.call($t, $t.p.selrow); } } // right if (event.keyCode === 39) { if ($t.p.treeGrid && !$t.p.data[mind][expanded]) { $(target).find("div.treeclick").trigger('click'); } $($t).triggerHandler("jqGridKeyRight", [$t.p.selrow]); if ($.isFunction(o.onRightKey)) { o.onRightKey.call($t, $t.p.selrow); } } } //check if enter was pressed on a grid or treegrid node else if (event.keyCode === 13) { $($t).triggerHandler("jqGridKeyEnter", [$t.p.selrow]); if ($.isFunction(o.onEnter)) { o.onEnter.call($t, $t.p.selrow); } } else if (event.keyCode === 32) { $($t).triggerHandler("jqGridKeySpace", [$t.p.selrow]); if ($.isFunction(o.onSpace)) { o.onSpace.call($t, $t.p.selrow); } } } }); }); }, unbindKeys: function () { return this.each(function () { $(this).unbind('keydown'); }); }, getLocalRow: function (rowid) { var ret = false, ind; this.each(function () { if (rowid !== undefined) { ind = this.p._index[$.jgrid.stripPref(this.p.idPrefix, rowid)]; if (ind >= 0) { ret = this.p.data[ind]; } } }); return ret; }, progressBar: function (p) { p = $.extend({ htmlcontent: "", method: "hide", loadtype: "disable" }, p || {}); return this.each(function () { var sh = p.method === "show" ? true : false, loadDiv = $("#load_" + $.jgrid.jqID(this.p.id)), offsetParent, top, scrollTop = $(window).scrollTop(); if (p.htmlcontent !== "") { loadDiv.html(p.htmlcontent); } switch (p.loadtype) { case "disable": break; case "enable": loadDiv.toggle(sh); break; case "block": $("#lui_" + $.jgrid.jqID(this.p.id)).toggle(sh); loadDiv.toggle(sh); break; } if (loadDiv.is(':visible')) { offsetParent = loadDiv.offsetParent(); loadDiv.css('top', ''); if (loadDiv.offset().top < scrollTop) { top = Math.min( 10 + scrollTop - offsetParent.offset().top, offsetParent.height() - loadDiv.height() ); loadDiv.css('top', top + 'px'); } } }); }, getColProp: function (colname) { var ret = {}, $t = this[0]; if (!$t.grid) { return false; } var cM = $t.p.colModel, i; for (i = 0; i < cM.length; i++) { if (cM[i].name === colname) { ret = cM[i]; break; } } return ret; }, setColProp: function (colname, obj) { //do not set width will not work return this.each(function () { if (this.grid) { if (obj) { var cM = this.p.colModel, i; for (i = 0; i < cM.length; i++) { if (cM[i].name === colname) { $.extend(true, this.p.colModel[i], obj); break; } } } } }); }, sortGrid: function (colname, reload, sor) { return this.each(function () { var $t = this, idx = -1, i, sobj = false; if (!$t.grid) { return; } if (!colname) { colname = $t.p.sortname; } for (i = 0; i < $t.p.colModel.length; i++) { if ($t.p.colModel[i].index === colname || $t.p.colModel[i].name === colname) { idx = i; if ($t.p.frozenColumns === true && $t.p.colModel[i].frozen === true) { sobj = $t.grid.fhDiv.find("#" + $t.p.id + "_" + colname); } break; } } if (idx !== -1) { var sort = $t.p.colModel[idx].sortable; if (!sobj) { sobj = $t.grid.headers[idx].el; } if (typeof sort !== 'boolean') { sort = true; } if (typeof reload !== 'boolean') { reload = false; } if (sort) { $t.sortData("jqgh_" + $t.p.id + "_" + colname, idx, reload, sor, sobj); } } }); }, setGridState: function (state) { return this.each(function () { if (!this.grid) { return; } var $t = this, open = $(this).jqGrid('getStyleUI', this.p.styleUI + ".base", 'icon_caption_open', true), close = $(this).jqGrid('getStyleUI', this.p.styleUI + ".base", 'icon_caption_close', true); if (state === 'hidden') { $(".ui-jqgrid-bdiv, .ui-jqgrid-hdiv", "#gview_" + $.jgrid.jqID($t.p.id)).slideUp("fast"); if ($t.p.pager) { $($t.p.pager).slideUp("fast"); } if ($t.p.toppager) { $($t.p.toppager).slideUp("fast"); } if ($t.p.toolbar[0] === true) { if ($t.p.toolbar[1] === 'both') { $($t.grid.ubDiv).slideUp("fast"); } $($t.grid.uDiv).slideUp("fast"); } if ($t.p.footerrow) { $(".ui-jqgrid-sdiv", "#gbox_" + $.jgrid.jqID($t.p.id)).slideUp("fast"); } $(".ui-jqgrid-headlink", $t.grid.cDiv).removeClass(open).addClass(close); $t.p.gridstate = 'hidden'; } else if (state === 'visible') { $(".ui-jqgrid-hdiv, .ui-jqgrid-bdiv", "#gview_" + $.jgrid.jqID($t.p.id)).slideDown("fast"); if ($t.p.pager) { $($t.p.pager).slideDown("fast"); } if ($t.p.toppager) { $($t.p.toppager).slideDown("fast"); } if ($t.p.toolbar[0] === true) { if ($t.p.toolbar[1] === 'both') { $($t.grid.ubDiv).slideDown("fast"); } $($t.grid.uDiv).slideDown("fast"); } if ($t.p.footerrow) { $(".ui-jqgrid-sdiv", "#gbox_" + $.jgrid.jqID($t.p.id)).slideDown("fast"); } $(".ui-jqgrid-headlink", $t.grid.cDiv).removeClass(close).addClass(open); $t.p.gridstate = 'visible'; } }); }, setFrozenColumns: function () { return this.each(function () { if (!this.grid) { return; } var $t = this, cm = $t.p.colModel, i = 0, len = cm.length, maxfrozen = -1, frozen = false, hd = $($t).jqGrid('getStyleUI', $t.p.styleUI + ".base", 'headerDiv', true, 'ui-jqgrid-hdiv'), hover = $($t).jqGrid('getStyleUI', $t.p.styleUI + ".common", 'hover', true); // TODO treeGrid and grouping Support if ($t.p.subGrid === true || $t.p.treeGrid === true || $t.p.cellEdit === true || $t.p.sortable || $t.p.scroll) { return; } if ($t.p.rownumbers) { i++; } if ($t.p.multiselect) { i++; } // get the max index of frozen col while (i < len) { // from left, no breaking frozen if (cm[i].frozen === true) { frozen = true; maxfrozen = i; } else { break; } i++; } if (maxfrozen >= 0 && frozen) { var top = $t.p.caption ? $($t.grid.cDiv).outerHeight() : 0, hth = $(".ui-jqgrid-htable", "#gview_" + $.jgrid.jqID($t.p.id)).height(); //headers if ($t.p.toppager) { top = top + $($t.grid.topDiv).outerHeight(); } if ($t.p.toolbar[0] === true) { if ($t.p.toolbar[1] !== "bottom") { top = top + $($t.grid.uDiv).outerHeight(); } } $t.grid.fhDiv = $('
'); $t.grid.fbDiv = $('
'); $("#gview_" + $.jgrid.jqID($t.p.id)).append($t.grid.fhDiv); var htbl = $(".ui-jqgrid-htable", "#gview_" + $.jgrid.jqID($t.p.id)).clone(true); // groupheader support - only if useColSpanstyle is false if ($t.p.groupHeader) { $("tr.jqg-first-row-header, tr.jqg-third-row-header", htbl).each(function () { $("th:gt(" + maxfrozen + ")", this).remove(); }); var swapfroz = -1, fdel = -1, cs, rs; $("tr.jqg-second-row-header th", htbl).each(function () { cs = parseInt($(this).attr("colspan"), 10); rs = parseInt($(this).attr("rowspan"), 10); if (rs) { swapfroz++; fdel++; } if (cs) { swapfroz = swapfroz + cs; fdel++; } if (swapfroz === maxfrozen) { fdel = maxfrozen; return false; } }); if (swapfroz !== maxfrozen) { fdel = maxfrozen; } $("tr.jqg-second-row-header", htbl).each(function () { $("th:gt(" + fdel + ")", this).remove(); }); } else { $("tr", htbl).each(function () { $("th:gt(" + maxfrozen + ")", this).remove(); }); } $(htbl).width(1); if (!$.jgrid.msie) { $(htbl).css("height", "100%"); } // resizing stuff $($t.grid.fhDiv).append(htbl) .mousemove(function (e) { if ($t.grid.resizing) { $t.grid.dragMove(e); return false; } }); if ($t.p.footerrow) { var hbd = $(".ui-jqgrid-bdiv", "#gview_" + $.jgrid.jqID($t.p.id)).height(); $t.grid.fsDiv = $('
'); $("#gview_" + $.jgrid.jqID($t.p.id)).append($t.grid.fsDiv); var ftbl = $(".ui-jqgrid-ftable", "#gview_" + $.jgrid.jqID($t.p.id)).clone(true); $("tr", ftbl).each(function () { $("td:gt(" + maxfrozen + ")", this).remove(); }); $(ftbl).width(1); $($t.grid.fsDiv).append(ftbl); } $($t).bind('jqGridResizeStop.setFrozenColumns', function (e, w, index) { var rhth = $(".ui-jqgrid-htable", $t.grid.fhDiv); $("th:eq(" + index + ")", rhth).width(w); var btd = $(".ui-jqgrid-btable", $t.grid.fbDiv); $("tr:first td:eq(" + index + ")", btd).width(w); if ($t.p.footerrow) { var ftd = $(".ui-jqgrid-ftable", $t.grid.fsDiv); $("tr:first td:eq(" + index + ")", ftd).width(w); } }); // data stuff //TODO support for setRowData $("#gview_" + $.jgrid.jqID($t.p.id)).append($t.grid.fbDiv); $($t.grid.fbDiv).bind('mousewheel DOMMouseScroll', function (e) { var st = $($t.grid.bDiv).scrollTop(); if (e.originalEvent.wheelDelta > 0 || e.originalEvent.detail < 0) { //up $($t.grid.bDiv).scrollTop(st - 25); } else { //down $($t.grid.bDiv).scrollTop(st + 25); } e.preventDefault(); }); if ($t.p.hoverrows === true) { $("#" + $.jgrid.jqID($t.p.id)).unbind('mouseover').unbind('mouseout'); } $($t).bind('jqGridAfterGridComplete.setFrozenColumns', function () { $("#" + $.jgrid.jqID($t.p.id) + "_frozen").remove(); $($t.grid.fbDiv).height($($t.grid.bDiv).height() - 16); var btbl = $("#" + $.jgrid.jqID($t.p.id)).clone(true); $("tr[role=row]", btbl).each(function () { $("td[role=gridcell]:gt(" + maxfrozen + ")", this).remove(); }); $(btbl).width(1).attr("id", $t.p.id + "_frozen"); $($t.grid.fbDiv).append(btbl); if ($t.p.hoverrows === true) { $("tr.jqgrow", btbl).hover( function () { $(this).addClass(hover); $("#" + $.jgrid.jqID(this.id), "#" + $.jgrid.jqID($t.p.id)).addClass(hover); }, function () { $(this).removeClass(hover); $("#" + $.jgrid.jqID(this.id), "#" + $.jgrid.jqID($t.p.id)).removeClass(hover); } ); $("tr.jqgrow", "#" + $.jgrid.jqID($t.p.id)).hover( function () { $(this).addClass(hover); $("#" + $.jgrid.jqID(this.id), "#" + $.jgrid.jqID($t.p.id) + "_frozen").addClass(hover); }, function () { $(this).removeClass(hover); $("#" + $.jgrid.jqID(this.id), "#" + $.jgrid.jqID($t.p.id) + "_frozen").removeClass(hover); } ); } btbl = null; }); if (!$t.grid.hDiv.loading) { $($t).triggerHandler("jqGridAfterGridComplete"); } $t.p.frozenColumns = true; } }); }, destroyFrozenColumns: function () { return this.each(function () { if (!this.grid) { return; } if (this.p.frozenColumns === true) { var $t = this, hover = $($t).jqGrid('getStyleUI', $t.p.styleUI + ".common", 'hover', true); $($t.grid.fhDiv).remove(); $($t.grid.fbDiv).remove(); $t.grid.fhDiv = null; $t.grid.fbDiv = null; if ($t.p.footerrow) { $($t.grid.fsDiv).remove(); $t.grid.fsDiv = null; } $(this).unbind('.setFrozenColumns'); if ($t.p.hoverrows === true) { var ptr; $("#" + $.jgrid.jqID($t.p.id)).bind('mouseover', function (e) { ptr = $(e.target).closest("tr.jqgrow"); if ($(ptr).attr("class") !== "ui-subgrid") { $(ptr).addClass(hover); } }).bind('mouseout', function (e) { ptr = $(e.target).closest("tr.jqgrow"); $(ptr).removeClass(hover); }); } this.p.frozenColumns = false; } }); }, resizeColumn: function (iCol, newWidth) { return this.each(function () { var grid = this.grid, p = this.p, cm = p.colModel, i, cmLen = cm.length, diff, diffnv; if (typeof iCol === "string") { for (i = 0; i < cmLen; i++) { if (cm[i].name === iCol) { iCol = i; break; } } } else { iCol = parseInt(iCol, 10); } newWidth = parseInt(newWidth, 10); // filters if (typeof iCol !== "number" || iCol < 0 || iCol > cm.length - 1 || typeof newWidth !== "number") { return; } if (newWidth < p.minColWidth) { return; } if (p.forceFit) { p.nv = 0; for (i = iCol + 1; i < cmLen; i++) { if (cm[i].hidden !== true) { p.nv = i - iCol; break; } } } // use resize stuff grid.resizing = { idx: iCol }; diff = newWidth - grid.headers[iCol].width; if (p.forceFit) { diffnv = grid.headers[iCol + p.nv].width - diff; if (diffnv < p.minColWidth) { return; } grid.headers[iCol + p.nv].newWidth = grid.headers[iCol + p.nv].width - diff; } grid.newWidth = p.tblwidth + diff; grid.headers[iCol].newWidth = newWidth; grid.dragEnd(false); }); }, getStyleUI: function (styleui, classui, notclasstag, gridclass) { try { var ret = "", stylemod = styleui.split("."), q = ""; if (!notclasstag) { ret = "class="; q = "\""; } if (gridclass == null) { gridclass = ""; } switch (stylemod.length) { case 1: ret += q + $.trim(gridclass + " " + $.jgrid.styleUI[stylemod[0]][classui] + q); break; case 2: ret += q + $.trim(gridclass + " " + $.jgrid.styleUI[stylemod[0]][stylemod[1]][classui] + q); } } catch (cls) { ret = ""; } return ret; }, resizeGrid: function (timeout) { return this.each(function () { var $t = this; if (timeout === undefined) { timeout = 500; } setTimeout(function () { try { var winwidth = $(window).width(), parentwidth = $("#gbox_" + $.jgrid.jqID($t.p.id)).parent().width(), ww = $t.p.width; if ((winwidth - parentwidth) > 3) { ww = parentwidth; } else { ww = winwidth; } $("#" + $.jgrid.jqID($t.p.id)).jqGrid('setGridWidth', ww); } catch (e) { } }, timeout); }); } }); //module begin $.jgrid.extend({ editCell: function (iRow, iCol, ed) { return this.each(function () { var $t = this, nm, tmp, cc, cm, highlight = $(this).jqGrid('getStyleUI', $t.p.styleUI + '.common', 'highlight', true), hover = $(this).jqGrid('getStyleUI', $t.p.styleUI + '.common', 'hover', true), inpclass = $(this).jqGrid('getStyleUI', $t.p.styleUI + ".celledit", 'inputClass', true); if (!$t.grid || $t.p.cellEdit !== true) { return; } iCol = parseInt(iCol, 10); // select the row that can be used for other methods $t.p.selrow = $t.rows[iRow].id; if (!$t.p.knv) { $($t).jqGrid("GridNav"); } // check to see if we have already edited cell if ($t.p.savedRow.length > 0) { // prevent second click on that field and enable selects if (ed === true) { if (iRow == $t.p.iRow && iCol == $t.p.iCol) { return; } } // save the cell $($t).jqGrid("saveCell", $t.p.savedRow[0].id, $t.p.savedRow[0].ic); } else { window.setTimeout(function () { $("#" + $.jgrid.jqID($t.p.knv)).attr("tabindex", "-1").focus(); }, 1); } cm = $t.p.colModel[iCol]; nm = cm.name; if (nm === 'subgrid' || nm === 'cb' || nm === 'rn') { return; } cc = $("td:eq(" + iCol + ")", $t.rows[iRow]); if (cm.editable === true && ed === true && !cc.hasClass("not-editable-cell") && (!$.isFunction($t.p.isCellEditable) || $t.p.isCellEditable.call($t, nm, iRow, iCol))) { if (parseInt($t.p.iCol, 10) >= 0 && parseInt($t.p.iRow, 10) >= 0) { //$("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell " + highlight); $($t.rows[$t.p.iRow]).removeClass("selected-row " + hover).find("td:eq(" + $t.p.iCol + ")").removeClass("edit-cell " + highlight); } $(cc).addClass("edit-cell " + highlight); $($t.rows[iRow]).addClass("selected-row " + hover); try { tmp = $.unformat.call($t, cc, { rowId: $t.rows[iRow].id, colModel: cm }, iCol); } catch (_) { tmp = (cm.edittype && cm.edittype === 'textarea') ? $(cc).text() : $(cc).html(); } if ($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); } if (!cm.edittype) { cm.edittype = "text"; } $t.p.savedRow.push({ id: iRow, ic: iCol, name: nm, v: tmp }); if (tmp === " " || tmp === " " || (tmp.length === 1 && tmp.charCodeAt(0) === 160)) { tmp = ''; } if ($.isFunction($t.p.formatCell)) { var tmp2 = $t.p.formatCell.call($t, $t.rows[iRow].id, nm, tmp, iRow, iCol); if (tmp2 !== undefined) { tmp = tmp2; } } $($t).triggerHandler("jqGridBeforeEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]); if ($.isFunction($t.p.beforeEditCell)) { $t.p.beforeEditCell.call($t, $t.rows[iRow].id, nm, tmp, iRow, iCol); } var opt = $.extend({}, cm.editoptions || {}, { id: iRow + "_" + nm, name: nm, rowId: $t.rows[iRow].id, oper: 'edit' }); var elc = $.jgrid.createEl.call($t, cm.edittype, opt, tmp, true, $.extend({}, $.jgrid.ajaxOptions, $t.p.ajaxSelectOptions || {})); if ($.inArray(cm.edittype, ['text', 'textarea', 'password', 'select']) > -1) { $(elc).addClass(inpclass); } $(cc).html("").append(elc).attr("tabindex", "0"); $.jgrid.bindEv.call($t, elc, opt); window.setTimeout(function () { $(elc).focus(); }, 1); $("input, select, textarea", cc).bind("keydown", function (e) { if (e.keyCode === 27) { if ($("input.hasDatepicker", cc).length > 0) { if ($(".ui-datepicker").is(":hidden")) { $($t).jqGrid("restoreCell", iRow, iCol); } else { $("input.hasDatepicker", cc).datepicker('hide'); } } else { $($t).jqGrid("restoreCell", iRow, iCol); } } //ESC if (e.keyCode === 13 && !e.shiftKey) { $($t).jqGrid("saveCell", iRow, iCol); // Prevent default action return false; } //Enter if (e.keyCode === 9) { if (!$t.grid.hDiv.loading) { if (e.shiftKey) { $($t).jqGrid("prevCell", iRow, iCol); } //Shift TAb else { $($t).jqGrid("nextCell", iRow, iCol); } //Tab } else { return false; } } e.stopPropagation(); }); $($t).triggerHandler("jqGridAfterEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]); if ($.isFunction($t.p.afterEditCell)) { $t.p.afterEditCell.call($t, $t.rows[iRow].id, nm, tmp, iRow, iCol); } } else { if (parseInt($t.p.iCol, 10) >= 0 && parseInt($t.p.iRow, 10) >= 0) { //$("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell " + highlight); $($t.rows[$t.p.iRow]).removeClass("selected-row " + hover).find("td:eq(" + $t.p.iCol + ")").removeClass("edit-cell " + highlight); } cc.addClass("edit-cell " + highlight); $($t.rows[iRow]).addClass("selected-row " + hover); tmp = cc.html().replace(/\ \;/ig, ''); $($t).triggerHandler("jqGridSelectCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]); if ($.isFunction($t.p.onSelectCell)) { $t.p.onSelectCell.call($t, $t.rows[iRow].id, nm, tmp, iRow, iCol); } } $t.p.iCol = iCol; $t.p.iRow = iRow; }); }, saveCell: function (iRow, iCol) { return this.each(function () { var $t = this, fr, errors = $.jgrid.getRegional(this, 'errors'), edit = $.jgrid.getRegional(this, 'edit'); if (!$t.grid || $t.p.cellEdit !== true) { return; } if ($t.p.savedRow.length >= 1) { fr = 0; } else { fr = null; } if (fr !== null) { var cc = $("td:eq(" + iCol + ")", $t.rows[iRow]), v, v2, cm = $t.p.colModel[iCol], nm = cm.name, nmjq = $.jgrid.jqID(nm), p = $(cc).offset(); switch (cm.edittype) { case "select": if (!cm.editoptions.multiple) { v = $("#" + iRow + "_" + nmjq + " option:selected", $t.rows[iRow]).val(); v2 = $("#" + iRow + "_" + nmjq + " option:selected", $t.rows[iRow]).text(); } else { var sel = $("#" + iRow + "_" + nmjq, $t.rows[iRow]), selectedText = []; v = $(sel).val(); if (v) { v.join(","); } else { v = ""; } $("option:selected", sel).each( function (i, selected) { selectedText[i] = $(selected).text(); } ); v2 = selectedText.join(","); } if (cm.formatter) { v2 = v; } break; case "checkbox": var cbv = ["Yes", "No"]; if (cm.editoptions) { cbv = cm.editoptions.value.split(":"); } v = $("#" + iRow + "_" + nmjq, $t.rows[iRow]).is(":checked") ? cbv[0] : cbv[1]; v2 = v; break; case "password": case "text": case "textarea": case "button": v = $("#" + iRow + "_" + nmjq, $t.rows[iRow]).val(); v2 = v; break; case 'custom': try { if (cm.editoptions && $.isFunction(cm.editoptions.custom_value)) { v = cm.editoptions.custom_value.call($t, $(".customelement", cc), 'get'); if (v === undefined) { throw "e2"; } else { v2 = v; } } else { throw "e1"; } } catch (e) { if (e === "e1") { $.jgrid.info_dialog(errors.errcap, "function 'custom_value' " + edit.msg.nodefined, edit.bClose, { styleUI: $t.p.styleUI }); } else if (e === "e2") { $.jgrid.info_dialog(errors.errcap, "function 'custom_value' " + edit.msg.novalue, edit.bClose, { styleUI: $t.p.styleUI }); } else { $.jgrid.info_dialog(errors.errcap, e.message, edit.bClose, { styleUI: $t.p.styleUI }); } } break; } // The common approach is if nothing changed do not do anything if (v2 !== $t.p.savedRow[fr].v) { var vvv = $($t).triggerHandler("jqGridBeforeSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]); if (vvv) { v = vvv; v2 = vvv; } if ($.isFunction($t.p.beforeSaveCell)) { var vv = $t.p.beforeSaveCell.call($t, $t.rows[iRow].id, nm, v, iRow, iCol); if (vv) { v = vv; v2 = vv; } } var cv = $.jgrid.checkValues.call($t, v, iCol), nuem = false; if (cv[0] === true) { var addpost = $($t).triggerHandler("jqGridBeforeSubmitCell", [$t.rows[iRow].id, nm, v, iRow, iCol]) || {}; if ($.isFunction($t.p.beforeSubmitCell)) { addpost = $t.p.beforeSubmitCell.call($t, $t.rows[iRow].id, nm, v, iRow, iCol); if (!addpost) { addpost = {}; } } if ($("input.hasDatepicker", cc).length > 0) { $("input.hasDatepicker", cc).datepicker('hide'); } if ($t.p.cellsubmit === 'remote') { if ($t.p.cellurl) { var postdata = {}; if ($t.p.autoencode) { v = $.jgrid.htmlEncode(v); } if (cm.editoptions && cm.editoptions.NullIfEmpty && v === "") { v = 'null'; nuem = true; } postdata[nm] = v; var idname, oper, opers; opers = $t.p.prmNames; idname = opers.id; oper = opers.oper; postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, $t.rows[iRow].id); postdata[oper] = opers.editoper; postdata = $.extend(addpost, postdata); $($t).jqGrid("progressBar", { method: "show", loadtype: $t.p.loadui, htmlcontent: $.jgrid.getRegional($t, 'defaults.savetext') }); $t.grid.hDiv.loading = true; $.ajax($.extend({ url: $t.p.cellurl, data: $.isFunction($t.p.serializeCellData) ? $t.p.serializeCellData.call($t, postdata, nm) : postdata, type: "POST", complete: function (result, stat) { $($t).jqGrid("progressBar", { method: "hide", loadtype: $t.p.loadui }); $t.grid.hDiv.loading = false; if (stat === 'success') { var ret = $($t).triggerHandler("jqGridAfterSubmitCell", [$t, result, postdata.id, nm, v, iRow, iCol]) || [true, '']; if (ret[0] === true && $.isFunction($t.p.afterSubmitCell)) { ret = $t.p.afterSubmitCell.call($t, result, postdata.id, nm, v, iRow, iCol); } if (ret[0] === true) { if (nuem) { v = ""; } $(cc).empty(); $($t).jqGrid("setCell", $t.rows[iRow].id, iCol, v2, false, false, true); $(cc).addClass("dirty-cell"); $($t.rows[iRow]).addClass("edited"); $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]); if ($.isFunction($t.p.afterSaveCell)) { $t.p.afterSaveCell.call($t, $t.rows[iRow].id, nm, v, iRow, iCol); } $t.p.savedRow.splice(0, 1); } else { $.jgrid.info_dialog(errors.errcap, ret[1], edit.bClose, { styleUI: $t.p.styleUI }); if ($t.p.restoreCellonFail) { $($t).jqGrid("restoreCell", iRow, iCol); } } } }, error: function (res, stat, err) { $("#lui_" + $.jgrid.jqID($t.p.id)).hide(); $t.grid.hDiv.loading = false; $($t).triggerHandler("jqGridErrorCell", [res, stat, err]); if ($.isFunction($t.p.errorCell)) { $t.p.errorCell.call($t, res, stat, err); } else { $.jgrid.info_dialog(errors.errcap, res.status + " : " + res.statusText + "
" + stat, edit.bClose, { styleUI: $t.p.styleUI }); } if ($t.p.restoreCellonFail) { $($t).jqGrid("restoreCell", iRow, iCol); } } }, $.jgrid.ajaxOptions, $t.p.ajaxCellOptions || {})); } else { try { $.jgrid.info_dialog(errors.errcap, errors.nourl, edit.bClose, { styleUI: $t.p.styleUI }); if ($t.p.restoreCellonFail) { $($t).jqGrid("restoreCell", iRow, iCol); } } catch (e) { } } } if ($t.p.cellsubmit === 'clientArray') { $(cc).empty(); $($t).jqGrid("setCell", $t.rows[iRow].id, iCol, v2, false, false, true); $(cc).addClass("dirty-cell"); $($t.rows[iRow]).addClass("edited"); $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]); if ($.isFunction($t.p.afterSaveCell)) { $t.p.afterSaveCell.call($t, $t.rows[iRow].id, nm, v, iRow, iCol); } $t.p.savedRow.splice(0, 1); } } else { try { window.setTimeout(function () { $.jgrid.info_dialog(errors.errcap, v + " " + cv[1], edit.bClose, { styleUI: $t.p.styleUI, top: p.top + 40, left: p.left }); }, 100); $($t).jqGrid("restoreCell", iRow, iCol); } catch (e) { } } } else { $($t).jqGrid("restoreCell", iRow, iCol); } } window.setTimeout(function () { $("#" + $.jgrid.jqID($t.p.knv)).attr("tabindex", "-1").focus(); }, 0); }); }, restoreCell: function (iRow, iCol) { return this.each(function () { var $t = this, fr; if (!$t.grid || $t.p.cellEdit !== true) { return; } if ($t.p.savedRow.length >= 1) { fr = 0; } else { fr = null; } if (fr !== null) { var cc = $("td:eq(" + iCol + ")", $t.rows[iRow]); // datepicker fix if ($.isFunction($.fn.datepicker)) { try { $("input.hasDatepicker", cc).datepicker('hide'); } catch (e) { } } $(cc).empty().attr("tabindex", "-1"); $($t).jqGrid("setCell", $t.rows[iRow].id, iCol, $t.p.savedRow[fr].v, false, false, true); $($t).triggerHandler("jqGridAfterRestoreCell", [$t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol]); if ($.isFunction($t.p.afterRestoreCell)) { $t.p.afterRestoreCell.call($t, $t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol); } $t.p.savedRow.splice(0, 1); } window.setTimeout(function () { $("#" + $t.p.knv).attr("tabindex", "-1").focus(); }, 0); }); }, nextCell: function (iRow, iCol) { return this.each(function () { var $t = this, nCol = false, i; if (!$t.grid || $t.p.cellEdit !== true) { return; } // try to find next editable cell for (i = iCol + 1; i < $t.p.colModel.length; i++) { if ($t.p.colModel[i].editable === true && (!$.isFunction($t.p.isCellEditable) || $t.p.isCellEditable.call($t, $t.p.colModel[i].name, iRow, i))) { nCol = i; break; } } if (nCol !== false) { $($t).jqGrid("editCell", iRow, nCol, true); } else { if ($t.p.savedRow.length > 0) { $($t).jqGrid("saveCell", iRow, iCol); } } }); }, prevCell: function (iRow, iCol) { return this.each(function () { var $t = this, nCol = false, i; if (!$t.grid || $t.p.cellEdit !== true) { return; } // try to find next editable cell for (i = iCol - 1; i >= 0; i--) { if ($t.p.colModel[i].editable === true && (!$.isFunction($t.p.isCellEditable) || $t.p.isCellEditable.call($t, $t.p.colModel[i].name, iRow, i))) { nCol = i; break; } } if (nCol !== false) { $($t).jqGrid("editCell", iRow, nCol, true); } else { if ($t.p.savedRow.length > 0) { $($t).jqGrid("saveCell", iRow, iCol); } } }); }, GridNav: function () { return this.each(function () { var $t = this; if (!$t.grid || $t.p.cellEdit !== true) { return; } // trick to process keydown on non input elements $t.p.knv = $t.p.id + "_kn"; var selection = $("
"), i, kdir; function scrollGrid(iR, iC, tp) { if (tp.substr(0, 1) === 'v') { var ch = $($t.grid.bDiv)[0].clientHeight, st = $($t.grid.bDiv)[0].scrollTop, nROT = $t.rows[iR].offsetTop + $t.rows[iR].clientHeight, pROT = $t.rows[iR].offsetTop; if (tp === 'vd') { if (nROT >= ch) { $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop + $t.rows[iR].clientHeight; } } if (tp === 'vu') { if (pROT < st) { $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop - $t.rows[iR].clientHeight; } } } if (tp === 'h') { var cw = $($t.grid.bDiv)[0].clientWidth, sl = $($t.grid.bDiv)[0].scrollLeft, nCOL = $t.rows[iR].cells[iC].offsetLeft + $t.rows[iR].cells[iC].clientWidth, pCOL = $t.rows[iR].cells[iC].offsetLeft; if (nCOL >= cw + parseInt(sl, 10)) { $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft + $t.rows[iR].cells[iC].clientWidth; } else if (pCOL < sl) { $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft - $t.rows[iR].cells[iC].clientWidth; } } } function findNextVisible(iC, act) { var ind, i; if (act === 'lft') { ind = iC + 1; for (i = iC; i >= 0; i--) { if ($t.p.colModel[i].hidden !== true) { ind = i; break; } } } if (act === 'rgt') { ind = iC - 1; for (i = iC; i < $t.p.colModel.length; i++) { if ($t.p.colModel[i].hidden !== true) { ind = i; break; } } } return ind; } $(selection).insertBefore($t.grid.cDiv); $("#" + $t.p.knv) .focus() .keydown(function (e) { kdir = e.keyCode; if ($t.p.direction === "rtl") { if (kdir === 37) { kdir = 39; } else if (kdir === 39) { kdir = 37; } } switch (kdir) { case 38: if ($t.p.iRow - 1 > 0) { scrollGrid($t.p.iRow - 1, $t.p.iCol, 'vu'); $($t).jqGrid("editCell", $t.p.iRow - 1, $t.p.iCol, false); } break; case 40: if ($t.p.iRow + 1 <= $t.rows.length - 1) { scrollGrid($t.p.iRow + 1, $t.p.iCol, 'vd'); $($t).jqGrid("editCell", $t.p.iRow + 1, $t.p.iCol, false); } break; case 37: if ($t.p.iCol - 1 >= 0) { i = findNextVisible($t.p.iCol - 1, 'lft'); scrollGrid($t.p.iRow, i, 'h'); $($t).jqGrid("editCell", $t.p.iRow, i, false); } break; case 39: if ($t.p.iCol + 1 <= $t.p.colModel.length - 1) { i = findNextVisible($t.p.iCol + 1, 'rgt'); scrollGrid($t.p.iRow, i, 'h'); $($t).jqGrid("editCell", $t.p.iRow, i, false); } break; case 13: if (parseInt($t.p.iCol, 10) >= 0 && parseInt($t.p.iRow, 10) >= 0) { $($t).jqGrid("editCell", $t.p.iRow, $t.p.iCol, true); } break; default: return true; } return false; }); }); }, getChangedCells: function (mthd) { var ret = []; if (!mthd) { mthd = 'all'; } this.each(function () { var $t = this, nm; if (!$t.grid || $t.p.cellEdit !== true) { return; } $($t.rows).each(function (j) { var res = {}; if ($(this).hasClass("edited")) { $('td', this).each(function (i) { nm = $t.p.colModel[i].name; if (nm !== 'cb' && nm !== 'subgrid') { if (mthd === 'dirty') { if ($(this).hasClass('dirty-cell')) { try { res[nm] = $.unformat.call($t, this, { rowId: $t.rows[j].id, colModel: $t.p.colModel[i] }, i); } catch (e) { res[nm] = $.jgrid.htmlDecode($(this).html()); } } } else { try { res[nm] = $.unformat.call($t, this, { rowId: $t.rows[j].id, colModel: $t.p.colModel[i] }, i); } catch (e) { res[nm] = $.jgrid.htmlDecode($(this).html()); } } } }); res.id = this.id; ret.push(res); } }); }); return ret; } /// end cell editing }); //module begin $.extend($.jgrid, { // Modal functions showModal: function (h) { h.w.show(); }, closeModal: function (h) { h.w.hide().attr("aria-hidden", "true"); if (h.o) { h.o.remove(); } }, hideModal: function (selector, o) { o = $.extend({ jqm: true, gb: '', removemodal: false, formprop: false, form: '' }, o || {}); var thisgrid = o.gb && typeof o.gb === "string" && o.gb.substr(0, 6) === "#gbox_" ? $("#" + o.gb.substr(6))[0] : false; if (o.onClose) { var oncret = thisgrid ? o.onClose.call(thisgrid, selector) : o.onClose(selector); if (typeof oncret === 'boolean' && !oncret) { return; } } if (o.formprop && thisgrid && o.form) { var fh = $(selector)[0].style.height, fw = $(selector)[0].style.width; if (fh.indexOf("px") > -1) { fh = parseFloat(fh); } if (fw.indexOf("px") > -1) { fw = parseFloat(fw); } var frmgr, frmdata; if (o.form === 'edit') { frmgr = '#' + $.jgrid.jqID("FrmGrid_" + o.gb.substr(6)); frmdata = "formProp"; } else if (o.form === 'view') { frmgr = '#' + $.jgrid.jqID("ViewGrid_" + o.gb.substr(6)); frmdata = "viewProp"; } $(thisgrid).data(frmdata, { top: parseFloat($(selector).css("top")), left: parseFloat($(selector).css("left")), width: fw, height: fh, dataheight: $(frmgr).height(), datawidth: $(frmgr).width() }); } if ($.fn.jqm && o.jqm === true) { $(selector).attr("aria-hidden", "true").jqmHide(); } else { if (o.gb !== '') { try { $(".jqgrid-overlay:first", o.gb).hide(); } catch (e) { } } $(selector).hide().attr("aria-hidden", "true"); } if (o.removemodal) { $(selector).remove(); } }, //Helper functions findPos: function (obj) { var curleft = 0, curtop = 0; if (obj.offsetParent) { do { curleft += obj.offsetLeft; curtop += obj.offsetTop; } while (obj = obj.offsetParent); //do not change obj == obj.offsetParent } return [curleft, curtop]; }, createModal: function (aIDs, content, p, insertSelector, posSelector, appendsel, css) { p = $.extend(true, {}, $.jgrid.jqModal || {}, p); var self = this, rtlsup = $(p.gbox).attr("dir") === "rtl" ? true : false, classes = $.jgrid.styleUI[(p.styleUI || 'jQueryUI')].modal, common = $.jgrid.styleUI[(p.styleUI || 'jQueryUI')].common, mw = document.createElement('div'); css = $.extend({}, css || {}); mw.className = "ui-jqdialog " + classes.modal; mw.id = aIDs.themodal; var mh = document.createElement('div'); mh.className = "ui-jqdialog-titlebar " + classes.header; mh.id = aIDs.modalhead; $(mh).append("" + p.caption + ""); var ahr = $("
") .hover(function () { ahr.addClass(common.hover); }, function () { ahr.removeClass(common.hover); }) .append(""); $(mh).append(ahr); if (rtlsup) { mw.dir = "rtl"; $(".ui-jqdialog-title", mh).css("float", "right"); $(".ui-jqdialog-titlebar-close", mh).css("left", 0.3 + "em"); } else { mw.dir = "ltr"; $(".ui-jqdialog-title", mh).css("float", "left"); $(".ui-jqdialog-titlebar-close", mh).css("right", 0.3 + "em"); } var mc = document.createElement('div'); $(mc).addClass("ui-jqdialog-content " + classes.content).attr("id", aIDs.modalcontent); $(mc).append(content); mw.appendChild(mc); $(mw).prepend(mh); if (appendsel === true) { $('body').append(mw); } //append as first child in body -for alert dialog else if (typeof appendsel === "string") { $(appendsel).append(mw); } else { $(mw).insertBefore(insertSelector); } $(mw).css(css); if (p.jqModal === undefined) { p.jqModal = true; } // internal use var coord = {}; if ($.fn.jqm && p.jqModal === true) { if (p.left === 0 && p.top === 0 && p.overlay) { var pos = []; pos = $.jgrid.findPos(posSelector); p.left = pos[0] + 4; p.top = pos[1] + 4; } coord.top = p.top + "px"; coord.left = p.left; } else if (p.left !== 0 || p.top !== 0) { coord.left = p.left; coord.top = p.top + "px"; } $("a.ui-jqdialog-titlebar-close", mh).click(function () { var oncm = $("#" + $.jgrid.jqID(aIDs.themodal)).data("onClose") || p.onClose; var gboxclose = $("#" + $.jgrid.jqID(aIDs.themodal)).data("gbox") || p.gbox; self.hideModal("#" + $.jgrid.jqID(aIDs.themodal), { gb: gboxclose, jqm: p.jqModal, onClose: oncm, removemodal: p.removemodal || false, formprop: !p.recreateForm || false, form: p.form || '' }); return false; }); if (p.width === 0 || !p.width) { p.width = 300; } if (p.height === 0 || !p.height) { p.height = 200; } if (!p.zIndex) { var parentZ = $(insertSelector).parents("*[role=dialog]").filter(':first').css("z-index"); if (parentZ) { p.zIndex = parseInt(parentZ, 10) + 2; } else { p.zIndex = 950; } } var rtlt = 0; if (rtlsup && coord.left && !appendsel) { rtlt = $(p.gbox).width() - (!isNaN(p.width) ? parseInt(p.width, 10) : 0) - 8; // to do // just in case coord.left = parseInt(coord.left, 10) + parseInt(rtlt, 10); } if (coord.left) { coord.left += "px"; } $(mw).css($.extend({ width: isNaN(p.width) ? "auto" : p.width + "px", height: isNaN(p.height) ? "auto" : p.height + "px", zIndex: p.zIndex, overflow: 'hidden' }, coord)) .attr({ tabIndex: "-1", "role": "dialog", "aria-labelledby": aIDs.modalhead, "aria-hidden": "true" }); if (p.drag === undefined) { p.drag = true; } if (p.resize === undefined) { p.resize = true; } if (p.drag) { $(mh).css('cursor', 'move'); if ($.fn.tinyDraggable) { //$(mw).jqDrag(mh); $(mw).tinyDraggable({ handle: "#" + $.jgrid.jqID(mh.id) }); } else { try { $(mw).draggable({ handle: $("#" + $.jgrid.jqID(mh.id)) }); } catch (e) { } } } if (p.resize) { if ($.fn.jqResize) { $(mw).append("
"); $("#" + $.jgrid.jqID(aIDs.themodal)).jqResize(".jqResize", aIDs.scrollelm ? "#" + $.jgrid.jqID(aIDs.scrollelm) : false); } else { try { $(mw).resizable({ handles: 'se, sw', alsoResize: aIDs.scrollelm ? "#" + $.jgrid.jqID(aIDs.scrollelm) : false }); } catch (r) { } } } if (p.closeOnEscape === true) { $(mw).keydown(function (e) { if (e.which === 27) { var cone = $("#" + $.jgrid.jqID(aIDs.themodal)).data("onClose") || p.onClose; self.hideModal("#" + $.jgrid.jqID(aIDs.themodal), { gb: p.gbox, jqm: p.jqModal, onClose: cone, removemodal: p.removemodal || false, formprop: !p.recreateForm || false, form: p.form || '' }); } }); } }, viewModal: function (selector, o) { o = $.extend({ toTop: true, overlay: 10, modal: false, overlayClass: 'ui-widget-overlay', // to be fixed onShow: $.jgrid.showModal, onHide: $.jgrid.closeModal, gbox: '', jqm: true, jqM: true }, o || {}); if (o.focusField === undefined) { o.focusField = 0; } if (typeof o.focusField === "number" && o.focusField >= 0) { o.focusField = parseInt(o.focusField, 10); } else if (typeof o.focusField === "boolean" && !o.focusField) { o.focusField = false; } else { o.focusField = 0; } if ($.fn.jqm && o.jqm === true) { if (o.jqM) { $(selector).attr("aria-hidden", "false").jqm(o).jqmShow(); } else { $(selector).attr("aria-hidden", "false").jqmShow(); } } else { if (o.gbox !== '') { $(".jqgrid-overlay:first", o.gbox).show(); $(selector).data("gbox", o.gbox); } $(selector).show().attr("aria-hidden", "false"); if (o.focusField >= 0) { try { $(':input:visible', selector)[parseInt(o.focusField, 10)].focus(); } catch (_) { } } } }, info_dialog: function (caption, content, c_b, modalopt) { var mopt = { width: 290, height: 'auto', dataheight: 'auto', drag: true, resize: false, left: 250, top: 170, zIndex: 1000, jqModal: true, modal: false, closeOnEscape: true, align: 'center', buttonalign: 'center', buttons: [] // {text:'textbutt', id:"buttid", onClick : function(){...}} // if the id is not provided we set it like info_button_+ the index in the array - i.e info_button_0,info_button_1... }; $.extend(true, mopt, $.jgrid.jqModal || {}, { caption: "" + caption + "" }, modalopt || {}); var jm = mopt.jqModal, self = this, classes = $.jgrid.styleUI[(mopt.styleUI || 'jQueryUI')].modal, common = $.jgrid.styleUI[(mopt.styleUI || 'jQueryUI')].common; if ($.fn.jqm && !jm) { jm = false; } // in case there is no jqModal var buttstr = "", i; if (mopt.buttons.length > 0) { for (i = 0; i < mopt.buttons.length; i++) { if (mopt.buttons[i].id === undefined) { mopt.buttons[i].id = "info_button_" + i; } buttstr += "" + mopt.buttons[i].text + ""; } } var dh = isNaN(mopt.dataheight) ? mopt.dataheight : mopt.dataheight + "px", cn = "text-align:" + mopt.align + ";"; var cnt = "
"; cnt += "
" + content + "
"; cnt += c_b ? "
" + c_b + "" + buttstr + "
" : buttstr !== "" ? "
" + buttstr + "
" : ""; cnt += "
"; try { if ($("#info_dialog").attr("aria-hidden") === "false") { $.jgrid.hideModal("#info_dialog", { jqm: jm }); } $("#info_dialog").remove(); } catch (e) { } $.jgrid.createModal({ themodal: 'info_dialog', modalhead: 'info_head', modalcontent: 'info_content', scrollelm: 'infocnt' }, cnt, mopt, '', '', true ); // attach onclick after inserting into the dom if (buttstr) { $.each(mopt.buttons, function (i) { $("#" + $.jgrid.jqID(this.id), "#info_id").bind('click', function () { mopt.buttons[i].onClick.call($("#info_dialog")); return false; }); }); } $("#closedialog", "#info_id").click(function () { self.hideModal("#info_dialog", { jqm: jm, onClose: $("#info_dialog").data("onClose") || mopt.onClose, gb: $("#info_dialog").data("gbox") || mopt.gbox }); return false; }); $(".fm-button", "#info_dialog").hover( function () { $(this).addClass(common.hover); }, function () { $(this).removeClass(common.hover); } ); if ($.isFunction(mopt.beforeOpen)) { mopt.beforeOpen(); } $.jgrid.viewModal("#info_dialog", { onHide: function (h) { h.w.hide().remove(); if (h.o) { h.o.remove(); } }, modal: mopt.modal, jqm: jm }); if ($.isFunction(mopt.afterOpen)) { mopt.afterOpen(); } try { $("#info_dialog").focus(); } catch (m) { } }, bindEv: function (el, opt) { var $t = this; if ($.isFunction(opt.dataInit)) { opt.dataInit.call($t, el, opt); } if (opt.dataEvents) { $.each(opt.dataEvents, function () { if (this.data !== undefined) { $(el).bind(this.type, this.data, this.fn); } else { $(el).bind(this.type, this.fn); } }); } }, // Form Functions createEl: function (eltype, options, vl, autowidth, ajaxso) { var elem = "", $t = this; function setAttributes(elm, atr, exl) { var exclude = ['dataInit', 'dataEvents', 'dataUrl', 'buildSelect', 'sopt', 'searchhidden', 'defaultValue', 'attr', 'custom_element', 'custom_value', 'oper']; if (exl !== undefined && $.isArray(exl)) { $.merge(exclude, exl); } $.each(atr, function (key, value) { if ($.inArray(key, exclude) === -1) { $(elm).attr(key, value); } }); if (!atr.hasOwnProperty('id')) { $(elm).attr('id', $.jgrid.randId()); } } switch (eltype) { case "textarea": elem = document.createElement("textarea"); if (autowidth) { if (!options.cols) { $(elem).css({ width: "98%" }); } } else if (!options.cols) { options.cols = 20; } if (!options.rows) { options.rows = 2; } if (vl === ' ' || vl === ' ' || (vl.length === 1 && vl.charCodeAt(0) === 160)) { vl = ""; } elem.value = vl; setAttributes(elem, options); $(elem).attr({ "role": "textbox", "multiline": "true" }); break; case "checkbox": //what code for simple checkbox elem = document.createElement("input"); elem.type = "checkbox"; if (!options.value) { var vl1 = (vl + "").toLowerCase(); if (vl1.search(/(false|f|0|no|n|off|undefined)/i) < 0 && vl1 !== "") { elem.checked = true; elem.defaultChecked = true; elem.value = vl; } else { elem.value = "on"; } $(elem).attr("offval", "off"); } else { var cbval = options.value.split(":"); if (vl === cbval[0]) { elem.checked = true; elem.defaultChecked = true; } elem.value = cbval[0]; $(elem).attr("offval", cbval[1]); } setAttributes(elem, options, ['value']); $(elem).attr("role", "checkbox"); break; case "select": elem = document.createElement("select"); elem.setAttribute("role", "select"); var msl, ovm = []; if (options.multiple === true) { msl = true; elem.multiple = "multiple"; $(elem).attr("aria-multiselectable", "true"); } else { msl = false; } if (options.dataUrl != null) { var rowid = null, postData = options.postData || ajaxso.postData; try { rowid = options.rowId; } catch (e) { } if ($t.p && $t.p.idPrefix) { rowid = $.jgrid.stripPref($t.p.idPrefix, rowid); } $.ajax($.extend({ url: $.isFunction(options.dataUrl) ? options.dataUrl.call($t, rowid, vl, String(options.name)) : options.dataUrl, type: "GET", dataType: "html", data: $.isFunction(postData) ? postData.call($t, rowid, vl, String(options.name)) : postData, context: { elem: elem, options: options, vl: vl }, success: function (data) { var ovm = [], elem = this.elem, vl = this.vl, options = $.extend({}, this.options), msl = options.multiple === true, cU = options.cacheUrlData === true, oV = '', txt, a = $.isFunction(options.buildSelect) ? options.buildSelect.call($t, data) : data; if (typeof a === 'string') { a = $($.trim(a)).html(); } if (a) { $(elem).append(a); setAttributes(elem, options, postData ? ['postData'] : undefined); if (options.size === undefined) { options.size = msl ? 3 : 1; } if (msl) { ovm = vl.split(","); ovm = $.map(ovm, function (n) { return $.trim(n); }); } else { ovm[0] = $.trim(vl); } //$(elem).attr(options); //setTimeout(function(){ $("option", elem).each(function (i) { txt = $(this).text(); vl = $(this).val() || txt; if (cU) { oV += (i !== 0 ? ";" : "") + vl + ":" + txt; } //if(i===0) { this.selected = ""; } // fix IE8/IE7 problem with selecting of the first item on multiple=true if (i === 0 && elem.multiple) { this.selected = false; } $(this).attr("role", "option"); if ($.inArray($.trim(txt), ovm) > -1 || $.inArray($.trim(vl), ovm) > -1) { this.selected = "selected"; } }); if (cU) { if (options.oper === 'edit') { $($t).jqGrid('setColProp', options.name, { editoptions: { buildSelect: null, dataUrl: null, value: oV } }); } else if (options.oper === 'search') { $($t).jqGrid('setColProp', options.name, { searchoptions: { dataUrl: null, value: oV } }); } else if (options.oper === 'filter') { if ($("#fbox_" + $t.p.id)[0].p) { var cols = $("#fbox_" + $t.p.id)[0].p.columns, nm; $.each(cols, function (i) { nm = this.index || this.name; if (options.name === nm) { this.searchoptions.dataUrl = null; this.searchoptions.value = oV; return false; } }); } } } $($t).triggerHandler("jqGridAddEditAfterSelectUrlComplete", [elem]); //},0); } } }, ajaxso || {})); } else if (options.value) { var i; if (options.size === undefined) { options.size = msl ? 3 : 1; } if (msl) { ovm = vl.split(","); ovm = $.map(ovm, function (n) { return $.trim(n); }); } if (typeof options.value === 'function') { options.value = options.value(); } var so, sv, ov, oSv, key, value, sep = options.separator === undefined ? ":" : options.separator, delim = options.delimiter === undefined ? ";" : options.delimiter; if (typeof options.value === 'string') { so = options.value.split(delim); for (i = 0; i < so.length; i++) { sv = so[i].split(sep); if (sv.length > 2) { sv[1] = $.map(sv, function (n, ii) { if (ii > 0) { return n; } }).join(sep); } ov = document.createElement("option"); ov.setAttribute("role", "option"); ov.value = sv[0]; ov.innerHTML = sv[1]; elem.appendChild(ov); if (!msl && ($.trim(sv[0]) === $.trim(vl) || $.trim(sv[1]) === $.trim(vl))) { ov.selected = "selected"; } if (msl && ($.inArray($.trim(sv[1]), ovm) > -1 || $.inArray($.trim(sv[0]), ovm) > -1)) { ov.selected = "selected"; } } } else if (Object.prototype.toString.call(options.value) === "[object Array]") { oSv = options.value; // array of arrays [[Key, Value], [Key, Value], ...] for (i = 0; i < oSv.length; i++) { if (oSv[i].length === 2) { key = oSv[i][0]; value = oSv[i][1]; ov = document.createElement("option"); ov.setAttribute("role", "option"); ov.value = key; ov.innerHTML = value; elem.appendChild(ov); if (!msl && ($.trim(key) === $.trim(vl) || $.trim(value) === $.trim(vl))) { ov.selected = "selected"; } if (msl && ($.inArray($.trim(value), ovm) > -1 || $.inArray($.trim(key), ovm) > -1)) { ov.selected = "selected"; } } } } else if (typeof options.value === 'object') { oSv = options.value; for (key in oSv) { if (oSv.hasOwnProperty(key)) { ov = document.createElement("option"); ov.setAttribute("role", "option"); ov.value = key; ov.innerHTML = oSv[key]; elem.appendChild(ov); if (!msl && ($.trim(key) === $.trim(vl) || $.trim(oSv[key]) === $.trim(vl))) { ov.selected = "selected"; } if (msl && ($.inArray($.trim(oSv[key]), ovm) > -1 || $.inArray($.trim(key), ovm) > -1)) { ov.selected = "selected"; } } } } setAttributes(elem, options, ['value']); } break; case "image": case "file": elem = document.createElement("input"); elem.type = eltype; setAttributes(elem, options); break; case "custom": elem = document.createElement("span"); try { if ($.isFunction(options.custom_element)) { var celm = options.custom_element.call($t, vl, options); if (celm) { celm = $(celm).addClass("customelement").attr({ id: options.id, name: options.name }); $(elem).empty().append(celm); } else { throw "e2"; } } else { throw "e1"; } } catch (e) { var errors = $.jgrid.getRegional($t, 'errors'), edit = $.jgrid.getRegional($t, 'edit'); if (e === "e1") { $.jgrid.info_dialog(errors.errcap, "function 'custom_element' " + edit.msg.nodefined, edit.bClose, { styleUI: $t.p.styleUI }); } else if (e === "e2") { $.jgrid.info_dialog(errors.errcap, "function 'custom_element' " + edit.msg.novalue, edit.bClose, { styleUI: $t.p.styleUI }); } else { $.jgrid.info_dialog(errors.errcap, typeof e === "string" ? e : e.message, edit.bClose, { styleUI: $t.p.styleUI }); } } break; default: var role; if (eltype === "button") { role = "button"; } else { role = "textbox"; } // ??? elem = document.createElement("input"); elem.type = eltype; elem.value = vl; setAttributes(elem, options); if (eltype !== "button") { if (autowidth) { if (!options.size) { $(elem).css({ width: "96%" }); } } else if (!options.size) { options.size = 20; } } $(elem).attr("role", role); } return elem; }, // Date Validation Javascript checkDate: function (format, date) { var daysInFebruary = function (year) { // February has 29 days in any year evenly divisible by four, // EXCEPT for centurial years which are not also divisible by 400. return (((year % 4 === 0) && (year % 100 !== 0 || (year % 400 === 0))) ? 29 : 28); }, tsp = {}, sep; format = format.toLowerCase(); //we search for /,-,. for the date separator if (format.indexOf("/") !== -1) { sep = "/"; } else if (format.indexOf("-") !== -1) { sep = "-"; } else if (format.indexOf(".") !== -1) { sep = "."; } else { sep = "/"; } format = format.split(sep); date = date.split(sep); if (date.length !== 3) { return false; } var j = -1, yln, dln = -1, mln = -1, i; for (i = 0; i < format.length; i++) { var dv = isNaN(date[i]) ? 0 : parseInt(date[i], 10); tsp[format[i]] = dv; yln = format[i]; if (yln.indexOf("y") !== -1) { j = i; } if (yln.indexOf("m") !== -1) { mln = i; } if (yln.indexOf("d") !== -1) { dln = i; } } if (format[j] === "y" || format[j] === "yyyy") { yln = 4; } else if (format[j] === "yy") { yln = 2; } else { yln = -1; } var daysInMonth = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], strDate; if (j === -1) { return false; } strDate = tsp[format[j]].toString(); if (yln === 2 && strDate.length === 1) { yln = 1; } if (strDate.length !== yln || (tsp[format[j]] === 0 && date[j] !== "00")) { return false; } if (mln === -1) { return false; } strDate = tsp[format[mln]].toString(); if (strDate.length < 1 || tsp[format[mln]] < 1 || tsp[format[mln]] > 12) { return false; } if (dln === -1) { return false; } strDate = tsp[format[dln]].toString(); if (strDate.length < 1 || tsp[format[dln]] < 1 || tsp[format[dln]] > 31 || (tsp[format[mln]] === 2 && tsp[format[dln]] > daysInFebruary(tsp[format[j]])) || tsp[format[dln]] > daysInMonth[tsp[format[mln]]]) { return false; } return true; }, isEmpty: function (val) { if (val.match(/^\s+$/) || val === "") { return true; } return false; }, checkTime: function (time) { // checks only hh:ss (and optional am/pm) var re = /^(\d{1,2}):(\d{2})([apAP][Mm])?$/, regs; if (!$.jgrid.isEmpty(time)) { regs = time.match(re); if (regs) { if (regs[3]) { if (regs[1] < 1 || regs[1] > 12) { return false; } } else { if (regs[1] > 23) { return false; } } if (regs[2] > 59) { return false; } } else { return false; } } return true; }, checkValues: function (val, valref, customobject, nam) { var edtrul, i, nm, dft, len, g = this, cm = g.p.colModel, msg = $.jgrid.getRegional(this, 'edit.msg'), fmtdate; if (customobject === undefined) { if (typeof valref === 'string') { for (i = 0, len = cm.length; i < len; i++) { if (cm[i].name === valref) { edtrul = cm[i].editrules; valref = i; if (cm[i].formoptions != null) { nm = cm[i].formoptions.label; } break; } } } else if (valref >= 0) { edtrul = cm[valref].editrules; } } else { edtrul = customobject; nm = nam === undefined ? "_" : nam; } if (edtrul) { if (!nm) { nm = g.p.colNames != null ? g.p.colNames[valref] : cm[valref].label; } if (edtrul.required === true) { if ($.jgrid.isEmpty(val)) { return [false, nm + ": " + msg.required, ""]; } } // force required var rqfield = edtrul.required === false ? false : true; if (edtrul.number === true) { if (!(rqfield === false && $.jgrid.isEmpty(val))) { if (isNaN(val)) { return [false, nm + ": " + msg.number, ""]; } } } if (edtrul.minValue !== undefined && !isNaN(edtrul.minValue)) { if (parseFloat(val) < parseFloat(edtrul.minValue)) { return [false, nm + ": " + msg.minValue + " " + edtrul.minValue, ""]; } } if (edtrul.maxValue !== undefined && !isNaN(edtrul.maxValue)) { if (parseFloat(val) > parseFloat(edtrul.maxValue)) { return [false, nm + ": " + msg.maxValue + " " + edtrul.maxValue, ""]; } } var filter; if (edtrul.email === true) { if (!(rqfield === false && $.jgrid.isEmpty(val))) { // taken from $ Validate plugin filter = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i; if (!filter.test(val)) { return [false, nm + ": " + msg.email, ""]; } } } if (edtrul.integer === true) { if (!(rqfield === false && $.jgrid.isEmpty(val))) { if (isNaN(val)) { return [false, nm + ": " + msg.integer, ""]; } if ((val % 1 !== 0) || (val.indexOf('.') !== -1)) { return [false, nm + ": " + msg.integer, ""]; } } } if (edtrul.date === true) { if (!(rqfield === false && $.jgrid.isEmpty(val))) { if (cm[valref].formatoptions && cm[valref].formatoptions.newformat) { dft = cm[valref].formatoptions.newformat; fmtdate = $.jgrid.getRegional(g, 'formatter.date.masks'); if (fmtdate && fmtdate.hasOwnProperty(dft)) { dft = fmtdate[dft]; } } else { dft = cm[valref].datefmt || "Y-m-d"; } if (!$.jgrid.checkDate(dft, val)) { return [false, nm + ": " + msg.date + " - " + dft, ""]; } } } if (edtrul.time === true) { if (!(rqfield === false && $.jgrid.isEmpty(val))) { if (!$.jgrid.checkTime(val)) { return [false, nm + ": " + msg.date + " - hh:mm (am/pm)", ""]; } } } if (edtrul.url === true) { if (!(rqfield === false && $.jgrid.isEmpty(val))) { filter = /^(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i; if (!filter.test(val)) { return [false, nm + ": " + msg.url, ""]; } } } if (edtrul.custom === true) { if (!(rqfield === false && $.jgrid.isEmpty(val))) { if ($.isFunction(edtrul.custom_func)) { var ret = edtrul.custom_func.call(g, val, nm, valref); return $.isArray(ret) ? ret : [false, msg.customarray, ""]; } return [false, msg.customfcheck, ""]; } } } return [true, "", ""]; } }); //module begin $.fn.jqFilter = function (arg) { if (typeof arg === 'string') { var fn = $.fn.jqFilter[arg]; if (!fn) { throw ("jqFilter - No such method: " + arg); } var args = $.makeArray(arguments).slice(1); return fn.apply(this, args); } var p = $.extend(true, { filter: null, columns: [], sortStrategy: null, onChange: null, afterRedraw: null, checkValues: null, error: false, errmsg: "", errorcheck: true, showQuery: true, sopt: null, ops: [], operands: null, numopts: ['eq', 'ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn', 'in', 'ni'], stropts: ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc', 'nu', 'nn', 'in', 'ni'], strarr: ['text', 'string', 'blob'], groupOps: [{ op: "AND", text: "AND" }, { op: "OR", text: "OR" }], groupButton: true, ruleButtons: true, uniqueSearchFields: false, direction: "ltr" }, $.jgrid.filter, arg || {}); return this.each(function () { if (this.filter) { return; } this.p = p; // setup filter in case if they is not defined if (this.p.filter === null || this.p.filter === undefined) { this.p.filter = { groupOp: this.p.groupOps[0].op, rules: [], groups: [] }; } // Sort the columns if the sort strategy is provided. if (this.p.sortStrategy != null && $.isFunction(this.p.sortStrategy)) { this.p.columns.sort(this.p.sortStrategy); } var i, len = this.p.columns.length, cl, isIE = /msie/i.test(navigator.userAgent) && !window.opera; // translating the options this.p.initFilter = $.extend(true, {}, this.p.filter); // set default values for the columns if they are not set if (!len) { return; } for (i = 0; i < len; i++) { cl = this.p.columns[i]; if (cl.stype) { // grid compatibility cl.inputtype = cl.stype; } else if (!cl.inputtype) { cl.inputtype = 'text'; } if (cl.sorttype) { // grid compatibility cl.searchtype = cl.sorttype; } else if (!cl.searchtype) { cl.searchtype = 'string'; } if (cl.hidden === undefined) { // jqGrid compatibility cl.hidden = false; } if (!cl.label) { cl.label = cl.name; } if (cl.index) { cl.name = cl.index; } if (!cl.hasOwnProperty('searchoptions')) { cl.searchoptions = {}; } if (!cl.hasOwnProperty('searchrules')) { cl.searchrules = {}; } if (cl.search === undefined) { cl.inlist = true; } else { cl.inlist = cl.search; } } var getGrid = function () { return $("#" + $.jgrid.jqID(p.id))[0] || null; }, $tg = getGrid(), classes = $.jgrid.styleUI[($tg.p.styleUI || 'jQueryUI')].filter, common = $.jgrid.styleUI[($tg.p.styleUI || 'jQueryUI')].common; if (this.p.showQuery) { $(this).append("
"); } /* *Perform checking. * */ var checkData = function (val, colModelItem) { var ret = [true, ""], $t = getGrid(); if ($.isFunction(colModelItem.searchrules)) { ret = colModelItem.searchrules.call($t, val, colModelItem); } else if ($.jgrid && $.jgrid.checkValues) { try { ret = $.jgrid.checkValues.call($t, val, -1, colModelItem.searchrules, colModelItem.label); } catch (e) { } } if (ret && ret.length && ret[0] === false) { p.error = !ret[0]; p.errmsg = ret[1]; } }; /* moving to common randId = function() { return Math.floor(Math.random()*10000).toString(); }; */ this.onchange = function () { // clear any error this.p.error = false; this.p.errmsg = ""; return $.isFunction(this.p.onChange) ? this.p.onChange.call(this, this.p) : false; }; /* * Redraw the filter every time when new field is added/deleted * and field is changed */ this.reDraw = function () { $("table.group:first", this).remove(); var t = this.createTableForGroup(p.filter, null); $(this).append(t); if ($.isFunction(this.p.afterRedraw)) { this.p.afterRedraw.call(this, this.p); } }; /* * Creates a grouping data for the filter * @param group - object * @param parentgroup - object */ this.createTableForGroup = function (group, parentgroup) { var that = this, i; // this table will hold all the group (tables) and rules (rows) var table = $("
"), // create error message row align = "left"; if (this.p.direction === "rtl") { align = "right"; table.attr("dir", "rtl"); } if (parentgroup === null) { table.append(""); } var tr = $(""); table.append(tr); // this header will hold the group operator type and group action buttons for // creating subgroup "+ {}", creating rule "+" or deleting the group "-" var th = $(""); tr.append(th); if (this.p.ruleButtons === true) { // dropdown for: choosing group operator type var groupOpSelect = $(""); th.append(groupOpSelect); // populate dropdown with all posible group operators: or, and var str = "", selected; for (i = 0; i < p.groupOps.length; i++) { selected = group.groupOp === that.p.groupOps[i].op ? " selected='selected'" : ""; str += ""; } groupOpSelect .append(str) .bind('change', function () { group.groupOp = $(groupOpSelect).val(); that.onchange(); // signals that the filter has changed }); } // button for adding a new subgroup var inputAddSubgroup = ""; if (this.p.groupButton) { inputAddSubgroup = $(""); inputAddSubgroup.bind('click', function () { if (group.groups === undefined) { group.groups = []; } group.groups.push({ groupOp: p.groupOps[0].op, rules: [], groups: [] }); // adding a new group that.reDraw(); // the html has changed, force reDraw that.onchange(); // signals that the filter has changed return false; }); } th.append(inputAddSubgroup); if (this.p.ruleButtons === true) { // button for adding a new rule var inputAddRule = $(""), cm; inputAddRule.bind('click', function () { //if(!group) { group = {};} if (group.rules === undefined) { group.rules = []; } for (i = 0; i < that.p.columns.length; i++) { // but show only serchable and serchhidden = true fields var searchable = (that.p.columns[i].search === undefined) ? true : that.p.columns[i].search, hidden = (that.p.columns[i].hidden === true), ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true); if ((ignoreHiding && searchable) || (searchable && !hidden)) { cm = that.p.columns[i]; break; } } if (!cm) { return false; } var opr; if (cm.searchoptions.sopt) { opr = cm.searchoptions.sopt; } else if (that.p.sopt) { opr = that.p.sopt; } else if ($.inArray(cm.searchtype, that.p.strarr) !== -1) { opr = that.p.stropts; } else { opr = that.p.numopts; } group.rules.push({ field: cm.name, op: opr[0], data: "" }); // adding a new rule that.reDraw(); // the html has changed, force reDraw // for the moment no change have been made to the rule, so // this will not trigger onchange event return false; }); th.append(inputAddRule); } // button for delete the group if (parentgroup !== null) { // ignore the first group var inputDeleteGroup = $(""); th.append(inputDeleteGroup); inputDeleteGroup.bind('click', function () { // remove group from parent for (i = 0; i < parentgroup.groups.length; i++) { if (parentgroup.groups[i] === group) { parentgroup.groups.splice(i, 1); break; } } that.reDraw(); // the html has changed, force reDraw that.onchange(); // signals that the filter has changed return false; }); } // append subgroup rows if (group.groups !== undefined) { for (i = 0; i < group.groups.length; i++) { var trHolderForSubgroup = $(""); table.append(trHolderForSubgroup); var tdFirstHolderForSubgroup = $(""); trHolderForSubgroup.append(tdFirstHolderForSubgroup); var tdMainHolderForSubgroup = $(""); tdMainHolderForSubgroup.append(this.createTableForGroup(group.groups[i], group)); trHolderForSubgroup.append(tdMainHolderForSubgroup); } } if (group.groupOp === undefined) { group.groupOp = that.p.groupOps[0].op; } // append rules rows var suni = that.p.ruleButtons && that.p.uniqueSearchFields; if (suni) { for (var ii = 0; ii < that.p.columns.length; ii++) { if (that.p.columns[ii].inlist) { that.p.columns[ii].search = true; } } } if (group.rules !== undefined) { for (i = 0; i < group.rules.length; i++) { table.append( this.createTableRowForRule(group.rules[i], group) ); if (suni) { var field = group.rules[i].field; for (var ii = 0; ii < that.p.columns.length; ii++) { if (field === that.p.columns[ii].name) { that.p.columns[ii].search = false; break; } } } } } return table; }; /* * Create the rule data for the filter */ this.createTableRowForRule = function (rule, group) { // save current entity in a variable so that it could // be referenced in anonimous method calls var that = this, $t = getGrid(), tr = $(""), //document.createElement("tr"), // first column used for padding //tdFirstHolderForRule = document.createElement("td"), i, op, trpar, cm, str = "", selected; //tdFirstHolderForRule.setAttribute("class", "first"); tr.append(""); // create field container var ruleFieldTd = $(""); tr.append(ruleFieldTd); // dropdown for: choosing field var ruleFieldSelect = $(""), ina, aoprs = []; ruleFieldTd.append(ruleFieldSelect); ruleFieldSelect.bind('change', function () { rule.field = $(ruleFieldSelect).val(); trpar = $(this).parents("tr:first"); $(".data", trpar).empty(); for (i = 0; i < that.p.columns.length; i++) { if (that.p.columns[i].name === rule.field) { cm = that.p.columns[i]; break; } } if (!cm) { return; } cm.searchoptions.id = $.jgrid.randId(); cm.searchoptions.name = rule.field; cm.searchoptions.oper = 'filter'; if (isIE && cm.inputtype === "text") { if (!cm.searchoptions.size) { cm.searchoptions.size = 10; } } var elm = $.jgrid.createEl.call($t, cm.inputtype, cm.searchoptions, "", true, that.p.ajaxSelectOptions || {}, true); $(elm).addClass("input-elm " + classes.srInput); //that.createElement(rule, ""); if (cm.searchoptions.sopt) { op = cm.searchoptions.sopt; } else if (that.p.sopt) { op = that.p.sopt; } else if ($.inArray(cm.searchtype, that.p.strarr) !== -1) { op = that.p.stropts; } else { op = that.p.numopts; } // operators var s = "", so = 0; aoprs = []; $.each(that.p.ops, function () { aoprs.push(this.oper); }); for (i = 0 ; i < op.length; i++) { ina = $.inArray(op[i], aoprs); if (ina !== -1) { if (so === 0) { rule.op = that.p.ops[ina].oper; } s += ""; so++; } } $(".selectopts", trpar).empty().append(s); $(".selectopts", trpar)[0].selectedIndex = 0; if ($.jgrid.msie && $.jgrid.msiever() < 9) { var sw = parseInt($("select.selectopts", trpar)[0].offsetWidth, 10) + 1; $(".selectopts", trpar).width(sw); $(".selectopts", trpar).css("width", "auto"); } // data $(".data", trpar).append(elm); $.jgrid.bindEv.call($t, elm, cm.searchoptions); $(".input-elm", trpar).bind('change', function (e) { var elem = e.target; rule.data = elem.nodeName.toUpperCase() === "SPAN" && cm.searchoptions && $.isFunction(cm.searchoptions.custom_value) ? cm.searchoptions.custom_value.call($t, $(elem).children(".customelement:first"), 'get') : elem.value; that.onchange(); // signals that the filter has changed }); setTimeout(function () { //IE, Opera, Chrome rule.data = $(elm).val(); that.onchange(); // signals that the filter has changed }, 0); }); // populate drop down with user provided column definitions var j = 0; for (i = 0; i < that.p.columns.length; i++) { // but show only serchable and serchhidden = true fields var searchable = (that.p.columns[i].search === undefined) ? true : that.p.columns[i].search, hidden = (that.p.columns[i].hidden === true), ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true); if ((ignoreHiding && searchable) || (searchable && !hidden)) { selected = ""; if (rule.field === that.p.columns[i].name) { selected = " selected='selected'"; j = i; } str += ""; } } ruleFieldSelect.append(str); // create operator container var ruleOperatorTd = $(""); tr.append(ruleOperatorTd); cm = p.columns[j]; // create it here so it can be referentiated in the onchange event //var RD = that.createElement(rule, rule.data); cm.searchoptions.id = $.jgrid.randId(); if (isIE && cm.inputtype === "text") { if (!cm.searchoptions.size) { cm.searchoptions.size = 10; } } cm.searchoptions.name = rule.field; cm.searchoptions.oper = 'filter'; var ruleDataInput = $.jgrid.createEl.call($t, cm.inputtype, cm.searchoptions, rule.data, true, that.p.ajaxSelectOptions || {}, true); if (rule.op === 'nu' || rule.op === 'nn') { $(ruleDataInput).attr('readonly', 'true'); $(ruleDataInput).attr('disabled', 'true'); } //retain the state of disabled text fields in case of null ops // dropdown for: choosing operator var ruleOperatorSelect = $(""); ruleOperatorTd.append(ruleOperatorSelect); ruleOperatorSelect.bind('change', function () { rule.op = $(ruleOperatorSelect).val(); trpar = $(this).parents("tr:first"); var rd = $(".input-elm", trpar)[0]; if (rule.op === "nu" || rule.op === "nn") { // disable for operator "is null" and "is not null" rule.data = ""; if (rd.tagName.toUpperCase() !== 'SELECT') { rd.value = ""; } rd.setAttribute("readonly", "true"); rd.setAttribute("disabled", "true"); } else { if (rd.tagName.toUpperCase() === 'SELECT') { rule.data = rd.value; } rd.removeAttribute("readonly"); rd.removeAttribute("disabled"); } that.onchange(); // signals that the filter has changed }); // populate drop down with all available operators if (cm.searchoptions.sopt) { op = cm.searchoptions.sopt; } else if (that.p.sopt) { op = that.p.sopt; } else if ($.inArray(cm.searchtype, that.p.strarr) !== -1) { op = that.p.stropts; } else { op = that.p.numopts; } str = ""; $.each(that.p.ops, function () { aoprs.push(this.oper); }); for (i = 0; i < op.length; i++) { ina = $.inArray(op[i], aoprs); if (ina !== -1) { selected = rule.op === that.p.ops[ina].oper ? " selected='selected'" : ""; str += ""; } } ruleOperatorSelect.append(str); // create data container var ruleDataTd = $(""); tr.append(ruleDataTd); // textbox for: data // is created previously //ruleDataInput.setAttribute("type", "text"); ruleDataTd.append(ruleDataInput); $.jgrid.bindEv.call($t, ruleDataInput, cm.searchoptions); $(ruleDataInput) .addClass("input-elm " + classes.srInput) .bind('change', function () { rule.data = cm.inputtype === 'custom' ? cm.searchoptions.custom_value.call($t, $(this).children(".customelement:first"), 'get') : $(this).val(); that.onchange(); // signals that the filter has changed }); // create action container var ruleDeleteTd = $(""); tr.append(ruleDeleteTd); // create button for: delete rule if (this.p.ruleButtons === true) { var ruleDeleteInput = $(""); ruleDeleteTd.append(ruleDeleteInput); //$(ruleDeleteInput).html("").height(20).width(30).button({icons: { primary: "ui-icon-minus", text:false}}); ruleDeleteInput.bind('click', function () { // remove rule from group for (i = 0; i < group.rules.length; i++) { if (group.rules[i] === rule) { group.rules.splice(i, 1); break; } } that.reDraw(); // the html has changed, force reDraw that.onchange(); // signals that the filter has changed return false; }); } return tr; }; this.getStringForGroup = function (group) { var s = "(", index; if (group.groups !== undefined) { for (index = 0; index < group.groups.length; index++) { if (s.length > 1) { s += " " + group.groupOp + " "; } try { s += this.getStringForGroup(group.groups[index]); } catch (eg) { alert(eg); } } } if (group.rules !== undefined) { try { for (index = 0; index < group.rules.length; index++) { if (s.length > 1) { s += " " + group.groupOp + " "; } s += this.getStringForRule(group.rules[index]); } } catch (e) { alert(e); } } s += ")"; if (s === "()") { return ""; // ignore groups that don't have rules } return s; }; this.getStringForRule = function (rule) { var opUF = "", opC = "", i, cm, ret, val, numtypes = ['int', 'integer', 'float', 'number', 'currency']; // jqGrid for (i = 0; i < this.p.ops.length; i++) { if (this.p.ops[i].oper === rule.op) { opUF = this.p.operands.hasOwnProperty(rule.op) ? this.p.operands[rule.op] : ""; opC = this.p.ops[i].oper; break; } } for (i = 0; i < this.p.columns.length; i++) { if (this.p.columns[i].name === rule.field) { cm = this.p.columns[i]; break; } } if (cm === undefined) { return ""; } val = rule.data; if (opC === 'bw' || opC === 'bn') { val = val + "%"; } if (opC === 'ew' || opC === 'en') { val = "%" + val; } if (opC === 'cn' || opC === 'nc') { val = "%" + val + "%"; } if (opC === 'in' || opC === 'ni') { val = " (" + val + ")"; } if (p.errorcheck) { checkData(rule.data, cm); } if ($.inArray(cm.searchtype, numtypes) !== -1 || opC === 'nn' || opC === 'nu') { ret = rule.field + " " + opUF + " " + val; } else { ret = rule.field + " " + opUF + " \"" + val + "\""; } return ret; }; this.resetFilter = function () { this.p.filter = $.extend(true, {}, this.p.initFilter); this.reDraw(); this.onchange(); }; this.hideError = function () { $("th." + common.error, this).html(""); $("tr.error", this).hide(); }; this.showError = function () { $("th." + common.error, this).html(this.p.errmsg); $("tr.error", this).show(); }; this.toUserFriendlyString = function () { return this.getStringForGroup(p.filter); }; this.toString = function () { // this will obtain a string that can be used to match an item. var that = this; function getStringRule(rule) { if (that.p.errorcheck) { var i, cm; for (i = 0; i < that.p.columns.length; i++) { if (that.p.columns[i].name === rule.field) { cm = that.p.columns[i]; break; } } if (cm) { checkData(rule.data, cm); } } return rule.op + "(item." + rule.field + ",'" + rule.data + "')"; } function getStringForGroup(group) { var s = "(", index; if (group.groups !== undefined) { for (index = 0; index < group.groups.length; index++) { if (s.length > 1) { if (group.groupOp === "OR") { s += " || "; } else { s += " && "; } } s += getStringForGroup(group.groups[index]); } } if (group.rules !== undefined) { for (index = 0; index < group.rules.length; index++) { if (s.length > 1) { if (group.groupOp === "OR") { s += " || "; } else { s += " && "; } } s += getStringRule(group.rules[index]); } } s += ")"; if (s === "()") { return ""; // ignore groups that don't have rules } return s; } return getStringForGroup(this.p.filter); }; // Here we init the filter this.reDraw(); if (this.p.showQuery) { this.onchange(); } // mark is as created so that it will not be created twice on this element this.filter = true; }); }; $.extend($.fn.jqFilter, { /* * Return SQL like string. Can be used directly */ toSQLString: function () { var s = ""; this.each(function () { s = this.toUserFriendlyString(); }); return s; }, /* * Return filter data as object. */ filterData: function () { var s; this.each(function () { s = this.p.filter; }); return s; }, getParameter: function (param) { if (param !== undefined) { if (this.p.hasOwnProperty(param)) { return this.p[param]; } } return this.p; }, resetFilter: function () { return this.each(function () { this.resetFilter(); }); }, addFilter: function (pfilter) { if (typeof pfilter === "string") { pfilter = $.jgrid.parse(pfilter); } this.each(function () { this.p.filter = pfilter; this.reDraw(); this.onchange(); }); } }); $.jgrid.extend({ filterToolbar: function (p) { var regional = $.jgrid.getRegional(this[0], 'search'); p = $.extend({ autosearch: true, autosearchDelay: 500, searchOnEnter: true, beforeSearch: null, afterSearch: null, beforeClear: null, afterClear: null, onClearSearchValue: null, searchurl: '', stringResult: false, groupOp: 'AND', defaultSearch: "bw", searchOperators: false, resetIcon: "x", splitSelect: ",", groupOpSelect: "OR", operands: { "eq": "==", "ne": "!", "lt": "<", "le": "<=", "gt": ">", "ge": ">=", "bw": "^", "bn": "!^", "in": "=", "ni": "!=", "ew": "|", "en": "!@", "cn": "~", "nc": "!~", "nu": "#", "nn": "!#", "bt": "..." } }, regional, p || {}); return this.each(function () { var $t = this; if ($t.p.filterToolbar) { return; } if (!$($t).data('filterToolbar')) { $($t).data('filterToolbar', p); } if ($t.p.force_regional) { p = $.extend(p, regional); } var classes = $.jgrid.styleUI[($t.p.styleUI || 'jQueryUI')].filter, common = $.jgrid.styleUI[($t.p.styleUI || 'jQueryUI')].common, base = $.jgrid.styleUI[($t.p.styleUI || 'jQueryUI')].base, triggerToolbar = function () { var sdata = {}, j = 0, v, nm, sopt = {}, so, ms = false, ssfield = [], bbt = false, sop; $.each($t.p.colModel, function () { var $elem = $("#gs_" + $t.p.idPrefix + $.jgrid.jqID(this.name), (this.frozen === true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv); nm = this.index || this.name; sop = this.searchoptions || {}; if (p.searchOperators && sop.searchOperMenu) { so = $elem.parent().prev().children("a").attr("soper") || p.defaultSearch; } else { so = (sop.sopt) ? sop.sopt[0] : this.stype === 'select' ? 'eq' : p.defaultSearch; } v = this.stype === "custom" && $.isFunction(sop.custom_value) && $elem.length > 0 && $elem[0].nodeName.toUpperCase() === "SPAN" ? sop.custom_value.call($t, $elem.children(".customelement:first"), "get") : $elem.val(); // detect multiselect if (this.stype === 'select' && sop.multiple && $.isArray(v) && v.length) { ms = true; ssfield.push(nm); v = v.length === 1 ? v[0] : v; } if (so === "bt") { bbt = true; } if (v || so === "nu" || so === "nn") { sdata[nm] = v; sopt[nm] = so; j++; } else { try { delete $t.p.postData[nm]; } catch (z) { } } }); var sd = j > 0 ? true : false; if (p.stringResult === true || $t.p.datatype === "local" || p.searchOperators === true) { var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":["; var gi = 0; $.each(sdata, function (i, n) { if (gi > 0) { ruleGroup += ","; } ruleGroup += "{\"field\":\"" + i + "\","; ruleGroup += "\"op\":\"" + sopt[i] + "\","; n += ""; ruleGroup += "\"data\":\"" + n.replace(/\\/g, '\\\\').replace(/\"/g, '\\"') + "\"}"; gi++; }); ruleGroup += "]}"; // multiselect var filters, rules, k, str, rule, ssdata, group; if (ms) { filters = $.jgrid.parse(ruleGroup);//, rules, k,str, rule, ssdata, group; if (filters.rules && filters.rules.length) { rules = filters.rules; for (k = 0; k < rules.length; k++) { rule = rules[k]; if ($.inArray(rule.filed, ssfield)) { ssdata = rule.data.split(p.splitSelect); if (ssdata.length > 1) { if (filters.groups === undefined) { filters.groups = []; } group = { groupOp: p.groupOpSelect, groups: [], rules: [] }; filters.groups.push(group); $.each(ssdata, function (l) { str = ssdata[l]; if (str) { group.rules.push({ data: ssdata[l], op: rule.op, field: rule.field }); } }); rules.splice(k, 1); k--; } } } } //ruleGroup = JSON.stringify( filters ); } if (bbt) { if (!$.isPlainObject(filters)) { filters = $.jgrid.parse(ruleGroup); } if (filters.rules && filters.rules.length) { rules = filters.rules; for (k = 0; k < rules.length; k++) { rule = rules[k]; if (rule.op === "bt") { ssdata = rule.data.split("..."); if (ssdata.length > 1) { if (filters.groups === undefined) { filters.groups = []; } group = { groupOp: 'AND', groups: [], rules: [] }; filters.groups.push(group); $.each(ssdata, function (l) { var btop = l === 0 ? 'ge' : 'le'; str = ssdata[l]; if (str) { group.rules.push({ data: ssdata[l], op: btop, field: rule.field }); } }); rules.splice(k, 1); k--; } } } } } if (bbt || ms) { ruleGroup = JSON.stringify(filters); } $.extend($t.p.postData, { filters: ruleGroup }); $.each(['searchField', 'searchString', 'searchOper'], function (i, n) { if ($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n]; } }); } else { $.extend($t.p.postData, sdata); } var saveurl; if ($t.p.searchurl) { saveurl = $t.p.url; $($t).jqGrid("setGridParam", { url: $t.p.searchurl }); } var bsr = $($t).triggerHandler("jqGridToolbarBeforeSearch") === 'stop' ? true : false; if (!bsr && $.isFunction(p.beforeSearch)) { bsr = p.beforeSearch.call($t); } if (!bsr) { $($t).jqGrid("setGridParam", { search: sd }).trigger("reloadGrid", [{ page: 1 }]); } if (saveurl) { $($t).jqGrid("setGridParam", { url: saveurl }); } $($t).triggerHandler("jqGridToolbarAfterSearch"); if ($.isFunction(p.afterSearch)) { p.afterSearch.call($t); } }, clearToolbar = function (trigger) { var sdata = {}, j = 0, nm; trigger = (typeof trigger !== 'boolean') ? true : trigger; $.each($t.p.colModel, function () { var v, $elem = $("#gs_" + $t.p.idPrefix + $.jgrid.jqID(this.name), (this.frozen === true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv); if (this.searchoptions && this.searchoptions.defaultValue !== undefined) { v = this.searchoptions.defaultValue; } nm = this.index || this.name; switch (this.stype) { case 'select': $elem.find("option").each(function (i) { if (i === 0) { this.selected = true; } if ($(this).val() === v) { this.selected = true; return false; } }); if (v !== undefined) { // post the key and not the text sdata[nm] = v; j++; } else { try { delete $t.p.postData[nm]; } catch (e) { } } break; case 'text': $elem.val(v || ""); if (v !== undefined) { sdata[nm] = v; j++; } else { try { delete $t.p.postData[nm]; } catch (y) { } } break; case 'custom': if ($.isFunction(this.searchoptions.custom_value) && $elem.length > 0 && $elem[0].nodeName.toUpperCase() === "SPAN") { this.searchoptions.custom_value.call($t, $elem.children(".customelement:first"), "set", v || ""); } break; } }); var sd = j > 0 ? true : false; $t.p.resetsearch = true; if (p.stringResult === true || $t.p.datatype === "local") { var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":["; var gi = 0; $.each(sdata, function (i, n) { if (gi > 0) { ruleGroup += ","; } ruleGroup += "{\"field\":\"" + i + "\","; ruleGroup += "\"op\":\"" + "eq" + "\","; n += ""; ruleGroup += "\"data\":\"" + n.replace(/\\/g, '\\\\').replace(/\"/g, '\\"') + "\"}"; gi++; }); ruleGroup += "]}"; $.extend($t.p.postData, { filters: ruleGroup }); $.each(['searchField', 'searchString', 'searchOper'], function (i, n) { if ($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n]; } }); } else { $.extend($t.p.postData, sdata); } var saveurl; if ($t.p.searchurl) { saveurl = $t.p.url; $($t).jqGrid("setGridParam", { url: $t.p.searchurl }); } var bcv = $($t).triggerHandler("jqGridToolbarBeforeClear") === 'stop' ? true : false; if (!bcv && $.isFunction(p.beforeClear)) { bcv = p.beforeClear.call($t); } if (!bcv) { if (trigger) { $($t).jqGrid("setGridParam", { search: sd }).trigger("reloadGrid", [{ page: 1 }]); } } if (saveurl) { $($t).jqGrid("setGridParam", { url: saveurl }); } $($t).triggerHandler("jqGridToolbarAfterClear"); if ($.isFunction(p.afterClear)) { p.afterClear(); } }, toggleToolbar = function () { var trow = $("tr.ui-search-toolbar", $t.grid.hDiv), trow2 = $t.p.frozenColumns === true ? $("tr.ui-search-toolbar", $t.grid.fhDiv) : false; if (trow.css("display") === 'none') { trow.show(); if (trow2) { trow2.show(); } } else { trow.hide(); if (trow2) { trow2.hide(); } } }, buildRuleMenu = function (elem, left, top) { $("#sopt_menu").remove(); left = parseInt(left, 10); top = parseInt(top, 10) + 18; var fs = $('.ui-jqgrid-view').css('font-size') || '11px'; var str = '"; $('body').append(str); $("#sopt_menu").addClass("ui-menu " + classes.menu_widget); $("#sopt_menu > li > a").hover( function () { $(this).addClass(common.hover); }, function () { $(this).removeClass(common.hover); } ).click(function () { var v = $(this).attr("value"), oper = $(this).attr("oper"); $($t).triggerHandler("jqGridToolbarSelectOper", [v, oper, elem]); $("#sopt_menu").hide(); $(elem).text(oper).attr("soper", v); if (p.autosearch === true) { var inpelm = $(elem).parent().next().children()[0]; if ($(inpelm).val() || v === "nu" || v === "nn") { triggerToolbar(); } } }); }; // create the row var tr = $(""), timeoutHnd, rules, filterobj; if (p.restoreFromFilters) { filterobj = $t.p.postData.filters; if (filterobj) { if (typeof filterobj === "string") { filterobj = $.jgrid.parse(filterobj); } rules = filterobj.rules.length ? filterobj.rules : false; } } $.each($t.p.colModel, function (ci) { var cm = this, soptions, select = "", sot = "=", so, i, st, csv, df, elem, restores, th = $(""), thd = $("
"), stbl = $("
"); if (this.hidden === true) { $(th).css("display", "none"); } this.search = this.search === false ? false : true; if (this.stype === undefined) { this.stype = 'text'; } this.searchoptions = this.searchoptions || {}; if (this.searchoptions.searchOperMenu === undefined) { this.searchoptions.searchOperMenu = true; } soptions = $.extend({}, this.searchoptions, { name: cm.index || cm.name, id: "gs_" + $t.p.idPrefix + cm.name, oper: 'search' }); if (this.search) { if (p.restoreFromFilters && rules) { restores = false; for (var is = 0; is < rules.length; is++) { if (rules[is].field) { var snm = cm.index || cm.name; if (snm === rules[is].field) { restores = rules[is]; break; } } } } if (p.searchOperators) { so = (soptions.sopt) ? soptions.sopt[0] : cm.stype === 'select' ? 'eq' : p.defaultSearch; // overwrite search operators if (p.restoreFromFilters && restores) { so = restores.op; } for (i = 0; i < p.odata.length; i++) { if (p.odata[i].oper === so) { sot = p.operands[so] || ""; break; } } st = soptions.searchtitle != null ? soptions.searchtitle : p.operandTitle; select = this.searchoptions.searchOperMenu ? "" + sot + "" : ""; } $("td:eq(0)", stbl).attr("colindex", ci).append(select); if (soptions.clearSearch === undefined) { soptions.clearSearch = true; } if (soptions.clearSearch) { csv = p.resetTitle || 'Clear Search Value'; $("td:eq(2)", stbl).append("" + p.resetIcon + ""); } else { $("td:eq(2)", stbl).hide(); } if (this.surl) { soptions.dataUrl = this.surl; } df = ""; if (soptions.defaultValue) { df = $.isFunction(soptions.defaultValue) ? soptions.defaultValue.call($t) : soptions.defaultValue; } //overwrite default value if restore from filters if (p.restoreFromFilters && restores) { df = restores.data; } elem = $.jgrid.createEl.call($t, this.stype, soptions, df, false, $.extend({}, $.jgrid.ajaxOptions, $t.p.ajaxSelectOptions || {})); $(elem).addClass(classes.srInput); $("td:eq(1)", stbl).append(elem); $(thd).append(stbl); if (soptions.dataEvents == null) { soptions.dataEvents = []; } switch (this.stype) { case "select": if (p.autosearch === true) { soptions.dataEvents.push({ type: "change", fn: function () { triggerToolbar(); return false; } }); } break; case "text": if (p.autosearch === true) { if (p.searchOnEnter) { soptions.dataEvents.push({ type: "keypress", fn: function (e) { var key = e.charCode || e.keyCode || 0; if (key === 13) { triggerToolbar(); return false; } return this; } }); } else { soptions.dataEvents.push({ type: "keydown", fn: function (e) { var key = e.which; switch (key) { case 13: return false; case 9: case 16: case 37: case 38: case 39: case 40: case 27: break; default: if (timeoutHnd) { clearTimeout(timeoutHnd); } timeoutHnd = setTimeout(function () { triggerToolbar(); }, p.autosearchDelay); } } }); } } break; } $.jgrid.bindEv.call($t, elem, soptions); } $(th).append(thd); $(tr).append(th); if (!p.searchOperators || select === "") { $("td:eq(0)", stbl).hide(); } }); $("table thead", $t.grid.hDiv).append(tr); if (p.searchOperators) { $(".soptclass", tr).click(function (e) { var offset = $(this).offset(), left = (offset.left), top = (offset.top); buildRuleMenu(this, left, top); e.stopPropagation(); }); $("body").on('click', function (e) { if (e.target.className !== "soptclass") { $("#sopt_menu").remove(); } }); } $(".clearsearchclass", tr).click(function () { var ptr = $(this).parents("tr:first"), coli = parseInt($("td.ui-search-oper", ptr).attr('colindex'), 10), sval = $.extend({}, $t.p.colModel[coli].searchoptions || {}), dval = sval.defaultValue ? sval.defaultValue : "", elem; if ($t.p.colModel[coli].stype === "select") { elem = $("td.ui-search-input select", ptr); if (dval) { elem.val(dval); } else { elem[0].selectedIndex = 0; } } else { elem = $("td.ui-search-input input", ptr); elem.val(dval); } $($t).triggerHandler("jqGridToolbarClearVal", [elem[0], coli, sval, dval]); if ($.isFunction(p.onClearSearchValue)) { p.onClearSearchValue.call($t, elem[0], coli, sval, dval); } // ToDo custom search type if (p.autosearch === true) { triggerToolbar(); } }); this.p.filterToolbar = true; this.triggerToolbar = triggerToolbar; this.clearToolbar = clearToolbar; this.toggleToolbar = toggleToolbar; }); }, destroyFilterToolbar: function () { return this.each(function () { if (!this.p.filterToolbar) { return; } this.triggerToolbar = null; this.clearToolbar = null; this.toggleToolbar = null; this.p.filterToolbar = false; $(this.grid.hDiv).find("table thead tr.ui-search-toolbar").remove(); }); }, refreshFilterToolbar: function (p) { p = $.extend(true, { filters: "", onClearVal: null, onSetVal: null }, p || {}); return this.each(function () { var $t = this, cm = $t.p.colModel, i, l = $t.p.colModel.length, searchitem, filters, rules, rule, ssfield = [], ia; // clear the values on toolbar. // do not call clearToolbar if (!$t.p.filterToolbar) { return; } for (i = 0; i < l; i++) { ssfield.push(cm[i].name); searchitem = $("#gs_" + $t.p.idPrefix + $.jgrid.jqID(cm[i].name)); switch (cm[i].stype) { case 'select': case 'text': searchitem.val(""); break; } if ($.isFunction(p.onClearVal)) { p.onClearVal.call($t, searchitem, cm[i].name); } } function setrules(filter) { if (filter && filter.rules) { // condition to exit rules = filter.rules; l = rules.length; for (i = 0; i < l; i++) { rule = rules[i]; ia = $.inArray(rule.field, ssfield); if (ia !== -1) { searchitem = $("#gs_" + $t.p.idPrefix + $.jgrid.jqID(cm[ia].name)); // problem for between operator if (searchitem.length > 0) { if (cm[ia].stype === "select") { searchitem.find("option[value='" + $.jgrid.jqID(rule.data) + "']").prop('selected', true); } else if (cm[ia].stype === "text") { searchitem.val(rule.data); } if ($.isFunction(p.onSetVal)) { p.onSetVal.call($t, searchitem, cm[ia].name); } } } } if (filter.groups) { for (var k = 0; k < filter.groups.length; k++) { setrules(filter.groups[k]); } } } } if (typeof (p.filters) === "string" && p.filters.length) { filters = $.jgrid.parse(p.filters); // flat filters only } if ($.isPlainObject(filters)) { setrules(filters); } }); }, searchGrid: function (p) { var regional = $.jgrid.getRegional(this[0], 'search'); p = $.extend(true, { recreateFilter: false, drag: true, sField: 'searchField', sValue: 'searchString', sOper: 'searchOper', sFilter: 'filters', loadDefaults: true, // this options activates loading of default filters from grid's postData for Multipe Search only. beforeShowSearch: null, afterShowSearch: null, onInitializeSearch: null, afterRedraw: null, afterChange: null, sortStrategy: null, closeAfterSearch: false, closeAfterReset: false, closeOnEscape: false, searchOnEnter: false, multipleSearch: false, multipleGroup: false, //cloneSearchRowOnAdd: true, top: 0, left: 0, jqModal: true, modal: false, resize: true, width: 450, height: 'auto', dataheight: 'auto', showQuery: false, errorcheck: true, sopt: null, stringResult: undefined, onClose: null, onSearch: null, onReset: null, toTop: true, overlay: 30, columns: [], tmplNames: null, tmplFilters: null, tmplLabel: ' Template: ', showOnLoad: false, layer: null, operands: { "eq": "=", "ne": "<>", "lt": "<", "le": "<=", "gt": ">", "ge": ">=", "bw": "LIKE", "bn": "NOT LIKE", "in": "IN", "ni": "NOT IN", "ew": "LIKE", "en": "NOT LIKE", "cn": "LIKE", "nc": "NOT LIKE", "nu": "IS NULL", "nn": "ISNOT NULL" } }, regional, p || {}); return this.each(function () { var $t = this; if (!$t.grid) { return; } var fid = "fbox_" + $t.p.id, showFrm = true, mustReload = true, IDs = { themodal: 'searchmod' + fid, modalhead: 'searchhd' + fid, modalcontent: 'searchcnt' + fid, scrollelm: fid }, defaultFilters = $t.p.postData[p.sFilter], fl, classes = $.jgrid.styleUI[($t.p.styleUI || 'jQueryUI')].filter, common = $.jgrid.styleUI[($t.p.styleUI || 'jQueryUI')].common; p.styleUI = $t.p.styleUI; if (typeof defaultFilters === "string") { defaultFilters = $.jgrid.parse(defaultFilters); } if (p.recreateFilter === true) { $("#" + $.jgrid.jqID(IDs.themodal)).remove(); } function showFilter(_filter) { showFrm = $($t).triggerHandler("jqGridFilterBeforeShow", [_filter]); if (showFrm === undefined) { showFrm = true; } if (showFrm && $.isFunction(p.beforeShowSearch)) { showFrm = p.beforeShowSearch.call($t, _filter); } if (showFrm) { $.jgrid.viewModal("#" + $.jgrid.jqID(IDs.themodal), { gbox: "#gbox_" + $.jgrid.jqID(fid), jqm: p.jqModal, modal: p.modal, overlay: p.overlay, toTop: p.toTop }); $($t).triggerHandler("jqGridFilterAfterShow", [_filter]); if ($.isFunction(p.afterShowSearch)) { p.afterShowSearch.call($t, _filter); } } } if ($("#" + $.jgrid.jqID(IDs.themodal))[0] !== undefined) { showFilter($("#fbox_" + $.jgrid.jqID($t.p.id))); } else { var fil = $("
").insertBefore("#gview_" + $.jgrid.jqID($t.p.id)), align = "left", butleft = ""; if ($t.p.direction === "rtl") { align = "right"; butleft = " style='text-align:left'"; fil.attr("dir", "rtl"); } var columns = $.extend([], $t.p.colModel), bS = "" + p.Find + "", bC = "" + p.Reset + "", bQ = "", tmpl = "", colnm, found = false, bt, cmi = -1; if (p.showQuery) { bQ = "Query"; } if (!p.columns.length) { $.each(columns, function (i, n) { if (!n.label) { n.label = $t.p.colNames[i]; } // find first searchable column and set it if no default filter if (!found) { var searchable = (n.search === undefined) ? true : n.search, hidden = (n.hidden === true), ignoreHiding = (n.searchoptions && n.searchoptions.searchhidden === true); if ((ignoreHiding && searchable) || (searchable && !hidden)) { found = true; colnm = n.index || n.name; cmi = i; } } }); } else { columns = p.columns; cmi = 0; colnm = columns[0].index || columns[0].name; } // old behaviour if ((!defaultFilters && colnm) || p.multipleSearch === false) { var cmop = "eq"; if (cmi >= 0 && columns[cmi].searchoptions && columns[cmi].searchoptions.sopt) { cmop = columns[cmi].searchoptions.sopt[0]; } else if (p.sopt && p.sopt.length) { cmop = p.sopt[0]; } defaultFilters = { groupOp: "AND", rules: [{ field: colnm, op: cmop, data: "" }] }; } found = false; if (p.tmplNames && p.tmplNames.length) { found = true; tmpl = "" + p.tmplLabel + ""; tmpl += ""; } bt = "" + tmpl + "

" + bC + "" + bQ + bS + "
"; fid = $.jgrid.jqID(fid); $("#" + fid).jqFilter({ columns: columns, sortStrategy: p.sortStrategy, filter: p.loadDefaults ? defaultFilters : null, showQuery: p.showQuery, errorcheck: p.errorcheck, sopt: p.sopt, groupButton: p.multipleGroup, ruleButtons: p.multipleSearch, uniqueSearchFields: p.uniqueSearchFields, afterRedraw: p.afterRedraw, ops: p.odata, operands: p.operands, ajaxSelectOptions: $t.p.ajaxSelectOptions, groupOps: p.groupOps, onChange: function () { if (this.p.showQuery) { $('.query', this).html(this.toUserFriendlyString()); } if ($.isFunction(p.afterChange)) { p.afterChange.call($t, $("#" + fid), p); } }, direction: $t.p.direction, id: $t.p.id }); fil.append(bt); if (found && p.tmplFilters && p.tmplFilters.length) { $(".ui-template", fil).bind('change', function () { var curtempl = $(this).val(); if (curtempl === "default") { $("#" + fid).jqFilter('addFilter', defaultFilters); } else { $("#" + fid).jqFilter('addFilter', p.tmplFilters[parseInt(curtempl, 10)]); } return false; }); } if (p.multipleGroup === true) { p.multipleSearch = true; } $($t).triggerHandler("jqGridFilterInitialize", [$("#" + fid)]); if ($.isFunction(p.onInitializeSearch)) { p.onInitializeSearch.call($t, $("#" + fid)); } p.gbox = "#gbox_" + fid; if (p.layer) { $.jgrid.createModal(IDs, fil, p, "#gview_" + $.jgrid.jqID($t.p.id), $("#gbox_" + $.jgrid.jqID($t.p.id))[0], "#" + $.jgrid.jqID(p.layer), { position: "relative" }); } else { $.jgrid.createModal(IDs, fil, p, "#gview_" + $.jgrid.jqID($t.p.id), $("#gbox_" + $.jgrid.jqID($t.p.id))[0]); } if (p.searchOnEnter || p.closeOnEscape) { $("#" + $.jgrid.jqID(IDs.themodal)).keydown(function (e) { var $target = $(e.target); if (p.searchOnEnter && e.which === 13 && // 13 === $.ui.keyCode.ENTER !$target.hasClass('add-group') && !$target.hasClass('add-rule') && !$target.hasClass('delete-group') && !$target.hasClass('delete-rule') && (!$target.hasClass("fm-button") || !$target.is("[id$=_query]"))) { $("#" + fid + "_search").click(); return false; } if (p.closeOnEscape && e.which === 27) { // 27 === $.ui.keyCode.ESCAPE $("#" + $.jgrid.jqID(IDs.modalhead)).find(".ui-jqdialog-titlebar-close").click(); return false; } }); } if (bQ) { $("#" + fid + "_query").bind('click', function () { $(".queryresult", fil).toggle(); return false; }); } if (p.stringResult === undefined) { // to provide backward compatibility, inferring stringResult value from multipleSearch p.stringResult = p.multipleSearch; } $("#" + fid + "_search").bind('click', function () { var sdata = {}, res, filters; fl = $("#" + fid); fl.find(".input-elm:focus").change(); filters = fl.jqFilter('filterData'); if (p.errorcheck) { fl[0].hideError(); if (!p.showQuery) { fl.jqFilter('toSQLString'); } if (fl[0].p.error) { fl[0].showError(); return false; } } if (p.stringResult) { try { res = JSON.stringify(filters); } catch (e2) { } if (typeof res === "string") { sdata[p.sFilter] = res; $.each([p.sField, p.sValue, p.sOper], function () { sdata[this] = ""; }); } } else { if (p.multipleSearch) { sdata[p.sFilter] = filters; $.each([p.sField, p.sValue, p.sOper], function () { sdata[this] = ""; }); } else { sdata[p.sField] = filters.rules[0].field; sdata[p.sValue] = filters.rules[0].data; sdata[p.sOper] = filters.rules[0].op; sdata[p.sFilter] = ""; } } $t.p.search = true; $.extend($t.p.postData, sdata); mustReload = $($t).triggerHandler("jqGridFilterSearch"); if (mustReload === undefined) { mustReload = true; } if (mustReload && $.isFunction(p.onSearch)) { mustReload = p.onSearch.call($t, $t.p.filters); } if (mustReload !== false) { $($t).trigger("reloadGrid", [{ page: 1 }]); } if (p.closeAfterSearch) { $.jgrid.hideModal("#" + $.jgrid.jqID(IDs.themodal), { gb: "#gbox_" + $.jgrid.jqID($t.p.id), jqm: p.jqModal, onClose: p.onClose }); } return false; }); $("#" + fid + "_reset").bind('click', function () { var sdata = {}, fl = $("#" + fid); $t.p.search = false; $t.p.resetsearch = true; if (p.multipleSearch === false) { sdata[p.sField] = sdata[p.sValue] = sdata[p.sOper] = ""; } else { sdata[p.sFilter] = ""; } fl[0].resetFilter(); if (found) { $(".ui-template", fil).val("default"); } $.extend($t.p.postData, sdata); mustReload = $($t).triggerHandler("jqGridFilterReset"); if (mustReload === undefined) { mustReload = true; } if (mustReload && $.isFunction(p.onReset)) { mustReload = p.onReset.call($t); } if (mustReload !== false) { $($t).trigger("reloadGrid", [{ page: 1 }]); } if (p.closeAfterReset) { $.jgrid.hideModal("#" + $.jgrid.jqID(IDs.themodal), { gb: "#gbox_" + $.jgrid.jqID($t.p.id), jqm: p.jqModal, onClose: p.onClose }); } return false; }); showFilter($("#" + fid)); $(".fm-button:not(." + common.disabled + ")", fil).hover( function () { $(this).addClass(common.hover); }, function () { $(this).removeClass(common.hover); } ); } }); }, filterInput: function (val, p) { p = $.extend(true, { defaultSearch: 'cn', groupOp: 'OR', searchAll: false, beforeSearch: null, afterSearch: null }, p || {}); return this.each(function () { var $t = this; if (!$t.grid) { return; } var nm, sop, ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[", gi = 0, so; val += ""; if (!$t.p.datatype === 'local') { return; } $.each($t.p.colModel, function () { nm = this.index || this.name; sop = this.searchoptions || {}; so = p.defaultSearch ? p.defaultSearch : (sop.sopt) ? sop.sopt[0] : p.defaultSearch; this.search = this.search === false ? false : true; if (this.search || p.searchAll) { if (gi > 0) { ruleGroup += ","; } ruleGroup += "{\"field\":\"" + nm + "\","; ruleGroup += "\"op\":\"" + so + "\","; ruleGroup += "\"data\":\"" + val.replace(/\\/g, '\\\\').replace(/\"/g, '\\"') + "\"}"; gi++; } }); ruleGroup += "]}"; $.extend($t.p.postData, { filters: ruleGroup }); $.each(['searchField', 'searchString', 'searchOper'], function (i, n) { if ($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n]; } }); var bsr = $($t).triggerHandler("jqGridFilterInputBeforeSearch") === 'stop' ? true : false; if (!bsr && $.isFunction(p.beforeSearch)) { bsr = p.beforeSearch.call($t); } if (!bsr) { $($t).jqGrid("setGridParam", { search: true }).trigger("reloadGrid", [{ page: 1 }]); } $($t).triggerHandler("jqGridFilterInputAfterSearch"); if ($.isFunction(p.afterSearch)) { p.afterSearch.call($t); } }); } }); //module begin var rp_ge = {}; $.jgrid.extend({ editGridRow: function (rowid, p) { var regional = $.jgrid.getRegional(this[0], 'edit'), currstyle = this[0].p.styleUI, styles = $.jgrid.styleUI[currstyle].formedit, commonstyle = $.jgrid.styleUI[currstyle].common; p = $.extend(true, { top: 0, left: 0, width: '500', datawidth: 'auto', height: 'auto', dataheight: 'auto', modal: false, overlay: 30, drag: true, resize: true, url: null, mtype: "POST", clearAfterAdd: true, closeAfterEdit: false, reloadAfterSubmit: true, onInitializeForm: null, beforeInitData: null, beforeShowForm: null, afterShowForm: null, beforeSubmit: null, afterSubmit: null, onclickSubmit: null, afterComplete: null, onclickPgButtons: null, afterclickPgButtons: null, editData: {}, recreateForm: false, jqModal: true, closeOnEscape: false, addedrow: "first", topinfo: '', bottominfo: '', saveicon: [], closeicon: [], savekey: [false, 13], navkeys: [false, 38, 40], checkOnSubmit: false, checkOnUpdate: false, processing: false, onClose: null, ajaxEditOptions: {}, serializeEditData: null, viewPagerButtons: true, overlayClass: commonstyle.overlay, removemodal: true, form: 'edit', template: null, focusField: true, editselected: false }, regional, p || {}); rp_ge[$(this)[0].p.id] = p; return this.each(function () { var $t = this; if (!$t.grid || !rowid) { return; } $t.p.savedData = {}; var gID = $t.p.id, frmgr = "FrmGrid_" + gID, frmtborg = "TblGrid_" + gID, frmtb = "#" + $.jgrid.jqID(frmtborg), frmtb2, IDs = { themodal: 'editmod' + gID, modalhead: 'edithd' + gID, modalcontent: 'editcnt' + gID, scrollelm: frmgr }, showFrm = true, maxCols = 1, maxRows = 0, postdata, diff, frmoper, templ = typeof rp_ge[$t.p.id].template === "string" && rp_ge[$t.p.id].template.length > 0, errors = $.jgrid.getRegional(this, 'errors'); rp_ge[$t.p.id].styleUI = $t.p.styleUI || 'jQueryUI'; if ($.jgrid.isMobile()) { rp_ge[$t.p.id].resize = false; } if (rowid === "new") { rowid = "_empty"; frmoper = "add"; p.caption = rp_ge[$t.p.id].addCaption; } else { p.caption = rp_ge[$t.p.id].editCaption; frmoper = "edit"; } if (!p.recreateForm) { if ($($t).data("formProp")) { $.extend(rp_ge[$(this)[0].p.id], $($t).data("formProp")); } } var closeovrl = true; if (p.checkOnUpdate && p.jqModal && !p.modal) { closeovrl = false; } function getFormData() { var a2 = {}, i; $(frmtb).find(".FormElement").each(function () { var celm = $(".customelement", this); if (celm.length) { var elem = celm[0], nm = $(elem).attr('name'); $.each($t.p.colModel, function () { if (this.name === nm && this.editoptions && $.isFunction(this.editoptions.custom_value)) { try { postdata[nm] = this.editoptions.custom_value.call($t, $("#" + $.jgrid.jqID(nm), frmtb), 'get'); if (postdata[nm] === undefined) { throw "e1"; } } catch (e) { if (e === "e1") { $.jgrid.info_dialog(errors.errcap, "function 'custom_value' " + rp_ge[$(this)[0]].p.msg.novalue, rp_ge[$(this)[0]].p.bClose, { styleUI: rp_ge[$(this)[0]].p.styleUI }); } else { $.jgrid.info_dialog(errors.errcap, e.message, rp_ge[$(this)[0]].p.bClose, { styleUI: rp_ge[$(this)[0]].p.styleUI }); } } return true; } }); } else { switch ($(this).get(0).type) { case "checkbox": if ($(this).is(":checked")) { postdata[this.name] = $(this).val(); } else { var ofv = $(this).attr("offval"); postdata[this.name] = ofv; } break; case "select-one": postdata[this.name] = $(this).val(); break; case "select-multiple": postdata[this.name] = $(this).val(); postdata[this.name] = postdata[this.name] ? postdata[this.name].join(",") : ""; break; case "password": case "text": case "textarea": case "button": postdata[this.name] = $(this).val(); break; case "radio": if (a2.hasOwnProperty(this.name)) { return true; } else { a2[this.name] = ($(this).attr("offval") === undefined) ? "off" : $(this).attr("offval"); } break; } if ($t.p.autoencode) { postdata[this.name] = $.jgrid.htmlEncode(postdata[this.name]); } } }); for (i in a2) { if (a2.hasOwnProperty(i)) { var val = $('input[name="' + i + '"]:checked', frmtb).val(); postdata[i] = (val !== undefined) ? val : a2[i]; if ($t.p.autoencode) { postdata[i] = $.jgrid.htmlEncode(postdata[i]); } } } return true; } function createData(rowid, obj, tb, maxcols) { var nm, hc, trdata, cnt = 0, tmp, dc, elc, retpos = [], ind = false, tdtmpl = "  ", tmpl = "", i, ffld; //*2 for (i = 1; i <= maxcols; i++) { tmpl += tdtmpl; } if (rowid !== '_empty') { ind = $(obj).jqGrid("getInd", rowid); } $(obj.p.colModel).each(function (i) { nm = this.name; // hidden fields are included in the form if (this.editrules && this.editrules.edithidden === true) { hc = false; } else { hc = this.hidden === true ? true : false; } dc = hc ? "style='display:none'" : ""; if (nm !== 'cb' && nm !== 'subgrid' && this.editable === true && nm !== 'rn') { if (ind === false) { tmp = ""; } else { if (nm === obj.p.ExpandColumn && obj.p.treeGrid === true) { tmp = $("td[role='gridcell']:eq(" + i + ")", obj.rows[ind]).text(); } else { try { tmp = $.unformat.call(obj, $("td[role='gridcell']:eq(" + i + ")", obj.rows[ind]), { rowId: rowid, colModel: this }, i); } catch (_) { tmp = (this.edittype && this.edittype === "textarea") ? $("td[role='gridcell']:eq(" + i + ")", obj.rows[ind]).text() : $("td[role='gridcell']:eq(" + i + ")", obj.rows[ind]).html(); } if (!tmp || tmp === " " || tmp === " " || (tmp.length === 1 && tmp.charCodeAt(0) === 160)) { tmp = ''; } } } var opt = $.extend({}, this.editoptions || {}, { id: nm, name: nm, rowId: rowid, oper: 'edit' }), frmopt = $.extend({}, { elmprefix: '', elmsuffix: '', rowabove: false, rowcontent: '' }, this.formoptions || {}), rp = parseInt(frmopt.rowpos, 10) || cnt + 1, cp = parseInt((parseInt(frmopt.colpos, 10) || 1) * 2, 10); if (rowid === "_empty" && opt.defaultValue) { tmp = $.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue; } if (!this.edittype) { this.edittype = "text"; } if ($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); } elc = $.jgrid.createEl.call($t, this.edittype, opt, tmp, false, $.extend({}, $.jgrid.ajaxOptions, obj.p.ajaxSelectOptions || {})); //if(tmp === "" && this.edittype == "checkbox") {tmp = $(elc).attr("offval");} //if(tmp === "" && this.edittype == "select") {tmp = $("option:eq(0)",elc).text();} if (this.edittype === "select") { tmp = $(elc).val(); if ($(elc).get(0).type === 'select-multiple' && tmp) { tmp = tmp.join(","); } } if (this.edittype === 'checkbox') { if ($(elc).is(":checked")) { tmp = $(elc).val(); } else { tmp = $(elc).attr("offval"); } } $(elc).addClass("FormElement"); if ($.inArray(this.edittype, ['text', 'textarea', 'password', 'select']) > -1) { $(elc).addClass(styles.inputClass); } ffld = true; if (templ) { var ftmplfld = $(frm).find("#" + nm); if (ftmplfld.length) { ftmplfld.replaceWith(elc); } else { ffld = false; } } else { //-------------------- trdata = $(tb).find("tr[rowpos=" + rp + "]"); if (frmopt.rowabove) { var newdata = $("" + frmopt.rowcontent + ""); $(tb).append(newdata); newdata[0].rp = rp; } if (trdata.length === 0) { trdata = $("").addClass("FormData").attr("id", "tr_" + nm); $(trdata).append(tmpl); $(tb).append(trdata); trdata[0].rp = rp; } $("td:eq(" + (cp - 2) + ")", trdata[0]).html(""); $("td:eq(" + (cp - 1) + ")", trdata[0]).append(frmopt.elmprefix).append(elc).append(frmopt.elmsuffix); //------------------------- } if ((rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) && ffld) { $t.p.savedData[nm] = tmp; } if (this.edittype === 'custom' && $.isFunction(opt.custom_value)) { opt.custom_value.call($t, $("#" + nm, frmgr), 'set', tmp); } $.jgrid.bindEv.call($t, elc, opt); retpos[cnt] = i; cnt++; } }); if (cnt > 0) { var idrow; if (templ) { idrow = "