;(function ($) { /* * jqGrid 3.6 - jQuery Grid * Copyright (c) 2008, Tony Tomov, tony@trirand.com * Dual licensed under the MIT and GPL licenses * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * Date: 2009-11-08 */ $.jgrid = $.jgrid || {}; $.extend($.jgrid,{ htmlDecode : function(value){ if(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(/])*>/gi; if(v) { return v.replace(regexp,"");} else {return v;} }, stringToDoc : function (xmlString) { var xmlDoc; if(typeof xmlString !== 'string') return xmlString; try { var parser = new DOMParser(); xmlDoc = parser.parseFromString(xmlString,"text/xml"); } catch(e) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc["loadXM"+"L"](xmlString); } return (xmlDoc && xmlDoc.documentElement && xmlDoc.documentElement.tagName != 'parsererror') ? xmlDoc : null; }, parse : function(jsonString) { var js = jsonString, msg; 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 = "{}"; } ($.jgrid.useJSON===true && typeof (JSON) === 'object' && typeof (JSON.parse) === 'function') ? msg = JSON.parse(js) : msg = eval('(' + js + ')'); return msg.hasOwnProperty('d') ? msg.d : msg; }, empty : function () { while ( this.firstChild ) this.removeChild( this.firstChild ); }, jqID : function(sid){ sid = sid + ""; return sid.replace(/([\.\:\[\]])/g,"\\$1"); }, ajaxOptions: {}, extend : function(methods) { $.extend($.fn.jqGrid,methods); if (!this.no_legacy_api) { $.fn.extend(methods); } } }); $.fn.jqGrid = function( pin ) { if (typeof pin == 'string') { var fn = $.fn.jqGrid[pin]; if (!fn) { throw ("jqGrid - No such method: " + pin); } var args = $.makeArray(arguments).slice(1); return fn.apply(this,args); } return this.each( function() { if(this.grid) {return;} var p = $.extend(true,{ url: "", height: 150, page: 1, rowNum: 20, records: 0, pager: "", pgbuttons: true, pginput: true, colModel: [], rowList: [], colNames: [], sortorder: "asc", sortname: "", datatype: "xml", mtype: "GET", altRows: false, selarrrow: [], savedRow: [], shrinkToFit: true, xmlReader: {}, jsonReader: {}, subGrid: false, subGridModel :[], reccount: 0, lastpage: 0, lastsort: 0, selrow: null, beforeSelectRow: null, onSelectRow: null, onSortCol: null, ondblClickRow: null, onRightClickRow: null, onPaging: null, onSelectAll: null, loadComplete: null, gridComplete: null, loadError: null, loadBeforeSend: null, afterInsertRow: null, beforeRequest: null, onHeaderClick: null, viewrecords: false, loadonce: false, multiselect: false, multikey: false, editurl: null, search: false, caption: "", hidegrid: true, hiddengrid: false, postData: {}, userData: {}, treeGrid : false, treeGridModel : 'nested', treeReader : {}, treeANode : -1, ExpandColumn: null, tree_root_level : 0, prmNames: {page:"page",rows:"rows", sort: "sidx",order: "sord", search:"_search", nd:"nd"}, forceFit : false, gridstate : "visible", cellEdit: false, cellsubmit: "remote", nv:0, loadui: "enable", toolbar: [false,""], scroll: false, multiboxonly : false, deselectAfterSort : true, scrollrows : false, autowidth: false, scrollOffset :18, cellLayout: 5, subGridWidth: 20, multiselectWidth: 20, gridview: false, rownumWidth: 25, rownumbers : false, pagerpos: 'center', recordpos: 'right', footerrow : false, userDataOnFooter : false, hoverrows : true, altclass : 'ui-priority-secondary', viewsortcols : [false,'vertical',true], resizeclass : '', autoencode : false, remapColumns : [], ajaxGridOptions :{}, direction : "ltr" }, $.jgrid.defaults, pin || {}); var grid={ headers:[], cols:[], footers: [], dragStart: function(i,x,y) { this.resizing = { idx: i, startX: x.clientX, sOL : y[0]}; this.hDiv.style.cursor = "col-resize"; this.curGbox = $("#rs_m"+p.id,"#gbox_"+p.id); this.curGbox.css({display:"block",left:y[0],top:y[1],height:y[2]}); if($.isFunction(p.resizeStart)) p.resizeStart.call(this,x,i); document.onselectstart=new Function ("return false"); }, dragMove: function(x) { if(this.resizing) { var diff = x.clientX-this.resizing.startX, h = this.headers[this.resizing.idx], newWidth = p.direction === "ltr" ? h.width + diff : h.width - diff, hn, nWn; if(newWidth > 33) { this.curGbox.css({left:this.resizing.sOL+diff}); if(p.forceFit===true ){ hn = this.headers[this.resizing.idx+p.nv]; nWn = p.direction === "ltr" ? hn.width - diff : hn.width + diff; if(nWn >33) { h.newWidth = newWidth; hn.newWidth = nWn; } } else { this.newWidth = p.direction === "ltr" ? p.tblwidth+diff : p.tblwidth-diff; h.newWidth = newWidth; } } } }, dragEnd: function() { this.hDiv.style.cursor = "default"; if(this.resizing) { var idx = this.resizing.idx, nw = this.headers[idx].newWidth || this.headers[idx].width; nw = parseInt(nw); this.resizing = false; $("#rs_m"+p.id).css("display","none"); p.colModel[idx].width = nw; this.headers[idx].width = nw; this.headers[idx].el.style.width = nw + "px"; if(this.cols.length>0) {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"; if(this.cols.length>0) this.cols[idx+p.nv].style.width = nw+"px"; if(this.footers.length>0) {this.footers[idx+p.nv].style.width = nw+"px";} p.colModel[idx+p.nv].width = nw; } else { p.tblwidth = this.newWidth || p.tblwidth; $('table:first',this.bDiv).css("width",p.tblwidth+"px"); $('table:first',this.hDiv).css("width",p.tblwidth+"px"); this.hDiv.scrollLeft = this.bDiv.scrollLeft; if(p.footerrow) { $('table:first',this.sDiv).css("width",p.tblwidth+"px"); this.sDiv.scrollLeft = this.bDiv.scrollLeft; } } if($.isFunction(p.resizeStop)) p.resizeStop.call(this,nw,idx); } this.curGbox=null; document.onselectstart=new 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 = $("> tbody > tr:visible:first", table); var rh = rows.outerHeight() || grid.prevRowHeight; if (!rh) return; grid.prevRowHeight = rh; var rn = p.rowNum; if (rn < 10) { rn = parseInt(dh / rh) + 1 << 1; if (rn < 10) rn = 10; p.rowNum = rn; } var scrollTop = grid.scrollTop = grid.bDiv.scrollTop; var ttop = table.position().top - scrollTop; var tbot = ttop + table.height(); var div = rh * rn; var page, npage, empty; if (ttop <= 0 && tbot < dh && parseInt((tbot + scrollTop + div - 1) / div) < p.lastpage) { npage = parseInt((dh - tbot + div - 1) / div); if (tbot >= 0 || npage < 2 || p.scroll === true) { page = parseInt((tbot + scrollTop) / div) + 1; ttop = -1; } else { ttop = 1; } } if (ttop > 0) { page = parseInt(scrollTop / div) + 1; npage = parseInt((scrollTop + dh) / div) + 2 - page; empty = true; } if (npage) { if (page > p.lastpage) { return; } if (grid.hDiv.loading) { grid.timer = setTimeout(grid.populateVisible, 200); } else { p.page = page; if (empty) { grid.selectionPreserver(table[0]); grid.emptyRows(grid.bDiv); } grid.populate(npage); } } }, scrollGrid: function() { if(p.scroll) { var scrollTop = grid.bDiv.scrollTop; if (scrollTop != grid.scrollTop) { grid.scrollTop = scrollTop; if (grid.timer) clearTimeout(grid.timer); grid.timer = setTimeout(grid.populateVisible, 200); } } grid.hDiv.scrollLeft = grid.bDiv.scrollLeft; if(p.footerrow) { grid.sDiv.scrollLeft = grid.bDiv.scrollLeft; } }, selectionPreserver : function(ts) { var p = ts.p; var sr = p.selrow, sra = p.selarrrow ? $.makeArray(p.selarrrow) : null; var left = ts.grid.bDiv.scrollLeft; var complete = p.gridComplete; p.gridComplete = function() { p.selrow = null; p.selarrrow = []; if(p.multiselect && sra && sra.length>0) { for(var i=0;i"), ii, isMSIE = $.browser.msie ? true:false, isSafari = $.browser.safari ? true : false; ts = this; ts.p.direction = $.trim(ts.p.direction.toLowerCase()); if($.inArray(ts.p.direction,["ltr","rtl"]) == -1) ts.p.direction = "ltr"; dir = ts.p.direction; $(gv).insertBefore(this); $(this).appendTo(gv).removeClass("scroll"); var eg = $("
"); $(eg).insertBefore(gv).attr({"id" : "gbox_"+this.id,"dir":dir}); $(gv).appendTo(eg).attr("id","gview_"+this.id); if (isMSIE && $.browser.version <= 6) { ii = ''; } else { ii="";} $("
").append(ii).insertBefore(gv); $("
"+this.p.loadtext+"
").insertBefore(gv); $(this).attr({cellSpacing:"0",cellPadding:"0",border:"0","role":"grid","aria-multiselectable":this.p.multiselect,"aria-labelledby":"gbox_"+this.id}); var sortkeys = ["shiftKey","altKey","ctrlKey"], IntNum = function(val,defval) { val = parseInt(val,10); if (isNaN(val)) { return defval ? defval : 0;} else {return val;} }, formatCol = function (pos, rowInd){ var ral = ts.p.colModel[pos].align, result="style=\"", clas = ts.p.colModel[pos].classes; if(ral) result += "text-align:"+ral+";"; if(ts.p.colModel[pos].hidden===true) result += "display:none;"; if(rowInd===0) { result += "width: "+grid.headers[pos].width+"px;" } return result+"\"" + (clas !== undefined ? (" class=\""+clas+"\"") :""); }, addCell = function(rowId,cell,pos,irow, srvr) { var v,prp; v = formatter(rowId,cell,pos,srvr,'add'); prp = formatCol( pos,irow); return ""+v+""; }, formatter = function (rowId, cellval , colpos, rwdat, _act){ var cm = ts.p.colModel[colpos],v; if(typeof cm.formatter !== 'undefined') { var opts= {rowId: rowId, colModel:cm }; if($.isFunction( cm.formatter ) ) { v = cm.formatter(cellval,opts,rwdat,_act); } else if($.fmatter){ v = $.fn.fmatter(cm.formatter, cellval,opts, rwdat, _act); } else { v = cellVal(cellval); } } else { v = cellVal(cellval); } return v; }, cellVal = function (val) { return val === undefined || val === null || val === "" ? " " : ts.p.autoencode ? $.jgrid.htmlEncode(val+"") : val+""; }, addMulti = function(rowid,pos,irow){ var v = "", prp = formatCol(pos,irow); return ""+v+""; }, addRowNum = function (pos,irow,pG,rN) { var v = (parseInt(pG)-1)*parseInt(rN)+1+irow, prp = formatCol(pos,irow); return ""+v+""; }, reader = function (datatype) { var field, f=[], j=0, i; for(i =0; idiv:first", parent).css({height:"auto"}).children("div:first").css({height:0,display:"none"}); parent.scrollTop = 0; } tBody = null; }, addXmlData = function (xml,t, rcnt, more, adjust) { var startReq = new Date(); ts.p.reccount = 0; if($.isXMLDoc(xml)) { if(ts.p.treeANode===-1 && !ts.p.scroll) { emptyRows(t); rcnt=0; } else { rcnt = rcnt > 0 ? rcnt :0; } } else { return; } var i,fpos,ir=0,v,row,gi=0,si=0,ni=0,idn, getId,f=[],F,rd ={}, rl= ts.rows.length, xmlr,rid, rowData=[],ari=0, cn=(ts.p.altRows === true) ? " "+ts.p.altclass:"",cn1; if(!ts.p.xmlReader.repeatitems) {f = reader("xml");} if( ts.p.keyIndex===false) { idn = ts.p.xmlReader.id; } else { idn = ts.p.keyIndex; } if(f.length>0 && !isNaN(idn)) { if (ts.p.remapColumns && ts.p.remapColumns.length) { idn = $.inArray(idn, ts.p.remapColumns); } idn=f[idn]; } if( (idn+"").indexOf("[") === -1 ) { if (f.length) { getId = function( trow, k) {return $(idn,trow).text() || k;}; } else { getId = function( trow, k) {return $(ts.p.xmlReader.cell,trow).eq(idn).text() || k;}; } } else { getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;}; } $(ts.p.xmlReader.page,xml).each(function() {ts.p.page = this.textContent || this.text || 1; }); $(ts.p.xmlReader.total,xml).each(function() {ts.p.lastpage = this.textContent || this.text || 1; } ); $(ts.p.xmlReader.records,xml).each(function() {ts.p.records = this.textContent || this.text || 0; } ); $(ts.p.xmlReader.userdata,xml).each(function() {ts.p.userData[this.getAttribute("name")]=this.textContent || this.text;}); var gxml = $(ts.p.xmlReader.root+" "+ts.p.xmlReader.row,xml),gl = gxml.length, j=0; if(gxml && gl){ var rn = parseInt(ts.p.rowNum),br=ts.p.scroll?(parseInt(ts.p.page)-1)*rn+1:1; if (adjust) rn *= adjust+1; var afterInsRow = $.isFunction(ts.p.afterInsertRow); while (j"; if(ts.p.rownumbers===true) { rowData[ari++] = addRowNum(0,j,ts.p.page,ts.p.rowNum); ni=1; } if(ts.p.multiselect===true) { rowData[ari++] = addMulti(rid,ni,j); gi=1; } if (ts.p.subGrid===true) { rowData[ari++]= $(ts).jqGrid("addSubGridCell",gi+ni,j+rcnt); si= 1; } if(ts.p.xmlReader.repeatitems){ if (!F) F=orderedCols(gi+si+ni); var cells = $(ts.p.xmlReader.cell,xmlr); $.each(F, function (k) { var cell = cells[this]; if (!cell) return false; v = cell.textContent || cell.text; rd[ts.p.colModel[k+gi+si+ni].name] = v; rowData[ari++] = addCell(rid,v,k+gi+si+ni,j+rcnt,xmlr); }); } else { for(i = 0; i < f.length;i++) { v = $(f[i],xmlr).text(); rd[ts.p.colModel[i+gi+si+ni].name] = v; rowData[ari++] = addCell(rid, v, i+gi+si+ni, j+rcnt, xmlr); } } rowData[ari++] = ""; if(ts.p.gridview === false ) { if( ts.p.treeGrid === true) { fpos = ts.p.treeANode >= -1 ? ts.p.treeANode: 0; row = $(rowData.join(''))[0]; // speed overhead try {$(ts).jqGrid("setTreeNode",rd,row);} catch (e) {} rl === 0 ? $("tbody:first",t).append(row) : $(ts.rows[j+fpos+rcnt]).after(row); } else { $("tbody:first",t).append(rowData.join('')); } if (ts.p.subGrid===true) { try {$(ts).jqGrid("addSubGrid",ts.rows[ts.rows.length-1],gi+ni);} catch (e){} } if(afterInsRow) {ts.p.afterInsertRow.call(ts,rid,rd,xmlr);} rowData=[];ari=0; } rd={}; ir++; j++; if(ir==rn) {break;} } } if(ts.p.gridview === true) { $("tbody:first",t).append(rowData.join('')); } ts.p.totaltime = new Date() - startReq; if(ir>0) {ts.grid.cols = ts.rows[0].cells;if(ts.p.records===0)ts.p.records=gl;} rowData =null; if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;} ts.p.reccount=ir; ts.p.treeANode = -1; if(ts.p.userDataOnFooter) $(ts).jqGrid("footerData","set",ts.p.userData,true); if (!more) updatepager(false,true); }, addJSONData = function(data,t, rcnt, more, adjust) { var startReq = new Date(); ts.p.reccount = 0; if(data) { if(ts.p.treeANode === -1 && !ts.p.scroll) { emptyRows(t); rcnt=0; } else { rcnt = rcnt > 0 ? rcnt :0; } } else { return; } var ir=0,v,i,j,row,f=[],F,cur,gi=0,si=0,ni=0,len,drows,idn,rd={}, fpos,rl = ts.rows.length,idr,rowData=[],ari=0,cn=(ts.p.altRows === true) ? " "+ts.p.altclass:"",cn1; ts.p.page = data[ts.p.jsonReader.page] || 1; ts.p.lastpage= data[ts.p.jsonReader.total] || 1; ts.p.records= data[ts.p.jsonReader.records] || 0; ts.p.userData = data[ts.p.jsonReader.userdata] || {}; if(!ts.p.jsonReader.repeatitems) { F = f = reader("json"); } if( ts.p.keyIndex===false ) { idn = ts.p.jsonReader.id; } else { idn = ts.p.keyIndex; } if(f.length>0 && !isNaN(idn)) { if (ts.p.remapColumns && ts.p.remapColumns.length) { idn = $.inArray(idn, ts.p.remapColumns); } idn=f[idn]; } drows = data[ts.p.jsonReader.root]; if (drows) { len = drows.length, i=0; var rn = parseInt(ts.p.rowNum),br=ts.p.scroll?(parseInt(ts.p.page)-1)*rn+1:1; if (adjust) rn *= adjust+1; var afterInsRow = $.isFunction(ts.p.afterInsertRow); while (i"; if(ts.p.rownumbers===true) { rowData[ari++] = addRowNum(0,i,ts.p.page,ts.p.rowNum); ni=1; } if(ts.p.multiselect){ rowData[ari++] = addMulti(idr,ni,i); gi = 1; } if (ts.p.subGrid) { rowData[ari++]= $(ts).jqGrid("addSubGridCell",gi+ni,i+rcnt); si= 1; } if (ts.p.jsonReader.repeatitems) { if(ts.p.jsonReader.cell) {cur = cur[ts.p.jsonReader.cell];} if (!F) F=orderedCols(gi+si+ni); } for (j=0;j= -1 ? ts.p.treeANode: 0; row = $(rowData.join(''))[0]; try {$(ts).jqGrid("setTreeNode",rd,row);} catch (e) {} rl === 0 ? $("tbody:first",t).append(row) : $(ts.rows[i+fpos+rcnt]).after(row); } else { $("tbody:first",t).append(rowData.join('')); } if(ts.p.subGrid === true ) { try { $(ts).jqGrid("addSubGrid",ts.rows[ts.rows.length-1],gi+ni);} catch (e){} } if(afterInsRow) {ts.p.afterInsertRow(idr,rd,cur);} rowData=[];ari=0; } rd={}; ir++; i++; if(ir==rn) break; } if(ts.p.gridview === true ) { $("tbody:first",t).append(rowData.join('')); } ts.p.totaltime = new Date() - startReq; if(ir>0) {ts.grid.cols = ts.rows[0].cells;if(ts.p.records===0)ts.p.records=len;} } if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;} ts.p.reccount=ir; ts.p.treeANode = -1; if(ts.p.userDataOnFooter) $(ts).jqGrid("footerData","set",ts.p.userData,true); if (!more) updatepager(false,true); }, updatepager = function(rn, dnd) { var cp, last, base,bs, from,to,tot,fmt; base = (parseInt(ts.p.page)-1)*parseInt(ts.p.rowNum); to = base + ts.p.reccount; if (ts.p.scroll) { var rows = $("tbody:first > tr", ts.grid.bDiv); base = to - rows.length var rh = rows.outerHeight(); 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.p.pager) { fmt = $.jgrid.formatter.integer || {}; if (ts.p.loadonce) { cp = last = 1; ts.p.lastpage = ts.page =1; $(".selbox",ts.p.pager).attr("disabled",true); } else { cp = IntNum(ts.p.page); last = IntNum(ts.p.lastpage); $(".selbox",ts.p.pager).attr("disabled",false); } if(ts.p.pginput===true) { $('.ui-pg-input',ts.p.pager).val(ts.p.page); $('#sp_1',ts.p.pager).html($.fmatter ? $.fmatter.util.NumberFormat(ts.p.lastpage,fmt):ts.p.lastpage).width(); } if (ts.p.viewrecords){ if(ts.p.reccount === 0) $(".ui-paging-info",ts.p.pager).html(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); } $(".ui-paging-info",ts.p.pager).html($.jgrid.format(ts.p.recordtext,from,to,tot)); } } if(ts.p.pgbuttons===true) { if(cp<=0) {cp = last = 1;} if(cp==1) {$("#first, #prev",ts.p.pager).addClass('ui-state-disabled').removeClass('ui-state-hover');} else {$("#first, #prev",ts.p.pager).removeClass('ui-state-disabled');} if(cp==last) {$("#next, #last",ts.p.pager).addClass('ui-state-disabled').removeClass('ui-state-hover');} else {$("#next, #last",ts.p.pager).removeClass('ui-state-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');} if($.isFunction(ts.p.gridComplete)) {ts.p.gridComplete();} }, populate = function (npage) { if(!ts.grid.hDiv.loading) { var pvis = ts.p.scroll && npage == false; var prm = {}, dt, dstr, pN=ts.p.prmNames;; 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; var lc = ts.p.loadComplete; var lcf = $.isFunction(lc); if (!lcf) lc = 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) { if (lcf) { ts.p.loadComplete.call(ts,req); } ts.grid.hDiv.loading = false; ts.p.page++; populate(npage-1); } } } else if (pN.npage != null) { delete ts.p.postData[pN.npage]; } $.extend(ts.p.postData,prm); var rcnt = !ts.p.scroll ? 0 : ts.rows.length-1; if ($.isFunction(ts.p.datatype)) { ts.p.datatype(ts.p.postData,"load_"+ts.p.id); return;} else if($.isFunction(ts.p.beforeRequest)) {ts.p.beforeRequest.call(ts);} 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(ts.p.postData) : ts.p.postData, complete:function(req,st) { if(st=="success" || (req.statusText == "OK" && req.status == "200")) { if(dt === "xml") addXmlData(req.responseXML,ts.grid.bDiv,rcnt,npage>1,adjust); else addJSONData($.jgrid.parse(req.responseText),ts.grid.bDiv,rcnt,npage>1,adjust); if(lc) lc.call(ts,req); if (pvis) ts.grid.populateVisible(); } req=null; endReq(); }, error:function(xhr,st,err){ if($.isFunction(ts.p.loadError)) ts.p.loadError.call(ts,xhr,st,err); endReq(); xhr=null; }, beforeSend: function(xhr){ beginReq(); if($.isFunction(ts.p.loadBeforeSend)) ts.p.loadBeforeSend.call(this,xhr); } },$.jgrid.ajaxOptions, ts.p.ajaxGridOptions)); if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";} break; case "xmlstring": beginReq(); addXmlData(dstr = $.jgrid.stringToDoc(ts.p.datastr),ts.grid.bDiv); ts.p.datatype = "local"; if(lcf) {ts.p.loadComplete.call(ts,dstr);} 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.grid.bDiv); ts.p.datatype = "local"; if(lcf) {ts.p.loadComplete.call(ts,dstr);} ts.p.datastr = null; endReq(); break; case "local": case "clientside": beginReq(); ts.p.datatype = "local"; sortArrayData(); endReq(); break; } } }, beginReq = function() { ts.grid.hDiv.loading = true; if(ts.p.hiddengrid) { return;} switch(ts.p.loadui) { case "disable": break; case "enable": $("#load_"+ts.p.id).show(); break; case "block": $("#lui_"+ts.p.id).show(); $("#load_"+ts.p.id).show(); break; } }, endReq = function() { ts.grid.hDiv.loading = false; switch(ts.p.loadui) { case "disable": break; case "enable": $("#load_"+ts.p.id).hide(); break; case "block": $("#lui_"+ts.p.id).hide(); $("#load_"+ts.p.id).hide(); break; } }, sortArrayData = function() { var stripNum = /[\$,%]/g; var rows=[], col=0, st, sv, findSortKey,newDir = (ts.p.sortorder == "asc") ? 1 :-1; $.each(ts.p.colModel,function(i,v){ if(this.index == ts.p.sortname || this.name == ts.p.sortname){ col = ts.p.lastsort= i; st = this.sorttype; return false; } }); if (st == 'float' || st== 'number' || st== 'currency') { findSortKey = function($cell) { var key = parseFloat($cell.replace(stripNum, '')); return isNaN(key) ? 0 : key; }; } else if (st=='int' || st=='integer') { findSortKey = function($cell) { return IntNum($cell.replace(stripNum, '')); }; } else if(st == 'date') { findSortKey = function($cell) { var fd = ts.p.colModel[col].datefmt || "Y-m-d"; return parseDate(fd,$cell).getTime(); }; } else { findSortKey = function($cell) { return $.trim($cell.toUpperCase()); }; } $.each(ts.rows, function(index, row) { try { sv = $.unformat($(row).children('td').eq(col),{colModel:ts.p.colModel[col]},col,true);} catch (_) { sv = $(row).children('td').eq(col).text(); } row.sortKey = findSortKey(sv); rows[index] = this; }); if(ts.p.treeGrid) { $(ts).jqGrid("SortTree",newDir); } else { rows.sort(function(a, b) { if (a.sortKey < b.sortKey) {return -newDir;} if (a.sortKey > b.sortKey) {return newDir;} return 0; }); if(rows[0]){ $("td",rows[0]).each( function( k ) { $(this).css("width",grid.headers[k].width+"px"); }); ts.grid.cols = rows[0].cells; } var cn = ""; if(ts.p.altRows) cn = ts.p.altclass; $.each(rows, function(i, row) { if(cn) { if(i%2 ==1) $(row).addClass(cn); else $(row).removeClass(cn); } $('tbody',ts.grid.bDiv).append(row); row.sortKey = null; }); } ts.grid.bDiv.scrollTop = 0; }, parseDate = function(format, date) { var tsp = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0},k,hl,dM; date = date.split(/[\\\/:_;.\t\T\s-]/); format = format.split(/[\\\/:_;.\t\T\s-]/); var dfmt = $.jgrid.formatter.date.monthNames; for(k=0,hl=format.length;k 11){date[k] = dM+1-12;} } tsp[format[k].toLowerCase()] = parseInt(date[k],10); } tsp.m = parseInt(tsp.m,10)-1; var ty = tsp.y; if (ty >= 70 && ty <= 99) {tsp.y = 1900+tsp.y;} else if (ty >=0 && ty <=69) {tsp.y= 2000+tsp.y;} return new Date(tsp.y, tsp.m, tsp.d, tsp.h, tsp.i, tsp.s,0); }, setPager = function (){ var sep = "", pgid= $(ts.p.pager).attr("id") || 'pager',pginp = "", pgl="", str="", pgcnt, lft, cent, rgt, twd, tdw, i, clearVals = function(onpaging){ if ($.isFunction(ts.p.onPaging) ) {ts.p.onPaging(onpaging);} ts.p.selrow = null; if(ts.p.multiselect) {ts.p.selarrrow =[];$('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.hDiv).attr("checked",false);} ts.p.savedRow = []; }; pgcnt = "pg_"+pgid; lft = pgid+"_left"; cent = pgid+"_center"; rgt = pgid+"_right"; $(ts.p.pager).addClass('ui-jqgrid-pager corner-bottom') .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.format(ts.p.pgtext || "","","")+""; if(ts.p.pgbuttons===true) { var po=["first","prev", "next","last"]; if(dir=="rtl") po.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 = $(".ui-jqgrid").css("font-size") || "11px"; $('body').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() { ts.p.page = Math.round(ts.p.rowNum*(ts.p.page-1)/this.value-0.5)+1; ts.p.rowNum = this.value; clearVals('records'); populate(); return false; }); if(ts.p.pgbuttons===true) { $(".ui-pg-button","#"+pgcnt).hover(function(e){ if($(this).hasClass('ui-state-disabled')) { this.style.cursor='default'; } else { $(this).addClass('ui-state-hover'); this.style.cursor='pointer'; } },function(e) { if($(this).hasClass('ui-state-disabled')) { } else { $(this).removeClass('ui-state-hover'); this.style.cursor= "default"; } }); $("#first, #prev, #next, #last",ts.p.pager).click( function(e) { var cp = IntNum(ts.p.page), last = IntNum(ts.p.lastpage), 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>1 && cp 1 && cp===0 ) { np=false;lp=false; cp=last-1;} if( this.id === 'first' && fp ) { ts.p.page=1; selclick=true;} if( this.id === 'prev' && pp) { ts.p.page=(cp-1); selclick=true;} if( this.id === 'next' && np) { ts.p.page=(cp+1); selclick=true;} if( this.id === 'last' && lp) { ts.p.page=last; selclick=true;} if(selclick) { clearVals(this.id); populate(); } return false; }); } if(ts.p.pginput===true) { $('input.ui-pg-input',"#"+pgcnt).keypress( function(e) { var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0; if(key == 13) { ts.p.page = ($(this).val()>0) ? $(this).val():ts.p.page; clearVals('user'); populate(); return false; } return this; }); } }, sortData = function (index, idxcol,reload,sor){ if(!ts.p.colModel[idxcol].sortable) return; var imgs, so; if(ts.p.savedRow.length > 0) {return;} if(!reload) { if( ts.p.lastsort == idxcol ) { if( ts.p.sortorder == 'asc') { ts.p.sortorder = 'desc'; } else if(ts.p.sortorder == 'desc') { ts.p.sortorder = 'asc';} } else { ts.p.sortorder = 'asc';} ts.p.page = 1; } if(sor) { if(ts.p.lastsort == idxcol && ts.p.sortorder == sor) return; else ts.p.sortorder = sor; } var thd= $("thead:first",ts.grid.hDiv).get(0); $("tr th:eq("+ts.p.lastsort+") span.ui-grid-ico-sort",thd).addClass('ui-state-disabled'); $("tr th:eq("+ts.p.lastsort+")",thd).attr("aria-selected","false"); $("tr th:eq("+idxcol+") span.ui-icon-"+ts.p.sortorder,thd).removeClass('ui-state-disabled'); $("tr th:eq("+idxcol+")",thd).attr("aria-selected","true"); if(!ts.p.viewsortcols[0]) { if(ts.p.lastsort != idxcol) { $("tr th:eq("+ts.p.lastsort+") span.s-ico",thd).hide(); $("tr th:eq("+idxcol+") span.s-ico",thd).show(); } } ts.p.lastsort = idxcol; index = index.substring(5); ts.p.sortname = ts.p.colModel[idxcol].index || index; so = ts.p.sortorder; if($.isFunction(ts.p.onSortCol)) {ts.p.onSortCol.call(ts,index,idxcol,so);} if(ts.p.datatype == "local") { if(ts.p.deselectAfterSort) {$(ts).jqGrid("resetSelection");} } else { ts.p.selrow = null; if(ts.p.multiselect){$("#cb_"+$.jgrid.jqID(ts.p.id),ts.grid.hDiv).attr("checked",false);} ts.p.selarrrow =[]; ts.p.savedRow =[]; if(ts.p.scroll) {emptyRows(ts.grid.bDiv,true);} } if(ts.p.subGrid && ts.p.datatype=='local') { $("td.sgexpanded","#"+ts.p.id).each(function(){ $(this).trigger("click"); }); } populate(); if(ts.p.sortname != index && idxcol) {ts.p.lastsort = idxcol;} }, setColWidth = function () { var initwidth = 0, brd=ts.p.cellLayout, vc=0, lvc, scw=ts.p.scrollOffset,cw,hs=false,aw,tw=0,gw=0, cl = 0, cr; if (isSafari) { brd=0; } $.each(ts.p.colModel, function(i) { if(typeof this.hidden === 'undefined') {this.hidden=false;} if(this.hidden===false){ initwidth += IntNum(this.width); if(this.fixed) { tw += this.width; gw += this.width+brd; } else { vc++; } cl++; } }); if(isNaN(ts.p.width)) {ts.p.width = grid.width = initwidth;} else { grid.width = ts.p.width} 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)) { } else { aw -= scw; hs = true; } initwidth =0; $.each(ts.p.colModel, function(i) { if(this.hidden === false && !this.fixed){ cw = Math.floor(aw/(ts.p.tblwidth-tw)*this.width); 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+tw+cl*brd; } }, nextVisible= function(iCol) { var ret = iCol, j=iCol, i; for (i = iCol+1;i"); this.p.colModel.unshift({name:'cb',width:isSafari ? ts.p.multiselectWidth+ts.p.cellLayout : ts.p.multiselectWidth,sortable:false,resizable:false,hidedlg:true,search:false,align:'center',fixed:true}); } 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}); } ts.p.xmlReader = $.extend({ 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({ 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); if(ts.p.scroll){ ts.p.pgbuttons = false; ts.p.pginput=false; ts.p.rowList=[]; } var thead = "", tdc, idn, w, res, sort, td, ptr, tbody, imgs,iac="",idc=""; 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";} tdc = isMSIE ? "class='ui-th-div-ie'" :""; imgs = ""; for(i=0;i"; idn = ts.p.colModel[i].index || ts.p.colModel[i].name; thead += "
"+ts.p.colNames[i]; if (idn == ts.p.sortname) { ts.p.lastsort = i; } thead += imgs+"
"; } thead += ""; $(this).append(thead); $("thead tr:first th",this).hover(function(){$(this).addClass('ui-state-hover');},function(){$(this).removeClass('ui-state-hover');}); if(this.p.multiselect) { var onSA = true, emp=[], chk; if(typeof ts.p.onSelectAll !== 'function') {onSA=false;} $('#cb_'+$.jgrid.jqID(ts.p.id),this).bind('click',function(){ if (this.checked) { $("[id^=jqg_]",ts.rows).attr("checked",true); $(ts.rows).each(function(i) { if(!$(this).hasClass("subgrid")){ $(this).addClass("ui-state-highlight").attr("aria-selected","true"); ts.p.selarrrow[i]= ts.p.selrow = this.id; } }); chk=true; emp=[]; } else { $("[id^=jqg_]",ts.rows).attr("checked",false); $(ts.rows).each(function(i) { if(!$(this).hasClass("subgrid")){ $(this).removeClass("ui-state-highlight").attr("aria-selected","false"); emp[i] = this.id; } }); ts.p.selarrrow = []; ts.p.selrow = null; chk=false; } if(onSA) {ts.p.onSelectAll(chk ? ts.p.selarrrow : emp,chk);} }); } $.each(ts.p.colModel, function(i){if(!this.width) {this.width=150;} this.width = parseInt(this.width);}); if(ts.p.autowidth===true) { var pw = $(eg).innerWidth(); ts.p.width = pw > 0? pw: 'nw'; } setColWidth(); $(eg).css("width",grid.width+"px").append("
 
"); $(gv).css("width",grid.width+"px"); thead = $("thead:first",ts).get(0); var tfoot = ""; var thr = $("tr:first",thead); ts.p.disableClick=false; $("th",thr).each(function ( j ) { var ht = $('div',this)[0]; w = ts.p.colModel[j].width; if(typeof ts.p.colModel[j].resizable === 'undefined') {ts.p.colModel[j].resizable = true;} if(ts.p.colModel[j].resizable){ res = document.createElement("span"); $(res).html(" ").addClass('ui-jqgrid-resize ui-jqgrid-resize-'+dir); !$.browser.opera ? $(res).css("cursor","col-resize") : ""; $(this).addClass(ts.p.resizeclass); } else { res = ""; } $(this).css("width",w+"px").prepend(res); if( ts.p.colModel[j].hidden ) $(this).css("display","none"); grid.headers[j] = { width: w, el: this }; sort = ts.p.colModel[j].sortable; if( typeof sort !== 'boolean') {ts.p.colModel[j].sortable = true; sort=true;} var nm = ts.p.colModel[j].name; if( !(nm == 'cb' || nm=='subgrid' || nm=='rn') ) { if(ts.p.viewsortcols[2]) $("div",this).addClass('ui-jqgrid-sortable'); } if(sort) { if(ts.p.viewsortcols[0]) {$("div span.s-ico",this).show(); if(j==ts.p.lastsort){ $("div span.ui-icon-"+ts.p.sortorder,this).removeClass("ui-state-disabled");}} else if( j == ts.p.lastsort) {$("div span.s-ico",this).show();$("div span.ui-icon-"+ts.p.sortorder,this).removeClass("ui-state-disabled");} } tfoot += ""; }).mousedown(function(e) { if ($(e.target).closest("th>span.ui-jqgrid-resize").length != 1) return; var ci = $.jgrid.getCellIndex(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 = $.jgrid.getCellIndex(this); if (!ts.p.viewsortcols[2]) { r=true,d=t.attr("sort") } sortData($('div',this)[0].id,ci,r,d); return false; }); if (ts.p.sortable && $.fn.sortable) { try { $(ts).jqGrid("sortableColumns", thr); } catch (e){} } tfoot += "
 
"; tbody = document.createElement("tbody"); this.appendChild(tbody); $(this).addClass('ui-jqgrid-btable'); var hTable = $("
").append(thead), hg = (ts.p.caption && ts.p.hiddengrid===true) ? true : false, hb = $("
"); grid.hDiv = document.createElement("div"); $(grid.hDiv) .css({ width: grid.width+"px"}) .addClass("ui-state-default ui-jqgrid-hdiv") .append(hb); $(hb).append(hTable); if(hg) $(grid.hDiv).hide(); ts.p._height =0; if(ts.p.pager){ if(typeof ts.p.pager == "string") {if(ts.p.pager.substr(0,1) !="#") ts.p.pager = "#"+ts.p.pager;} $(ts.p.pager).css({width: grid.width+"px"}).appendTo(eg).addClass('ui-state-default ui-jqgrid-pager'); ts.p._height += parseInt($(ts.p.pager).height(),10); if(hg) {$(ts.p.pager).hide();} setPager(); } if( ts.p.cellEdit === false && ts.p.hoverrows === true) { $(ts).bind('mouseover',function(e) { ptr = $(e.target).closest("tr.jqgrow"); if($(ptr).attr("class") !== "subgrid") { $(ptr).addClass("ui-state-hover"); } return false; }).bind('mouseout',function(e) { ptr = $(e.target).closest("tr.jqgrow"); $(ptr).removeClass("ui-state-hover"); return false; }); } var ri,ci; $(ts).before(grid.hDiv).click(function(e) { td = e.target; var scb = $(td).hasClass("cbox"); ptr = $(td,ts.rows).closest("tr.jqgrow"); if($(ptr).length === 0 ) { return this; } var cSel = true; if($.isFunction(ts.p.beforeSelectRow)) cSel = ts.p.beforeSelectRow.call(ts,ptr[0].id, e); if (td.tagName == 'A' || ((td.tagName == 'INPUT' || td.tagName == 'TEXTAREA' || td.tagName == 'OPTION' || td.tagName == 'SELECT' ) && !scb) ) { return true; } if(cSel === true) { if(ts.p.cellEdit === true) { if(ts.p.multiselect && scb){ $(ts).jqGrid("setSelection",ptr[0].id,true); } else { ri = ptr[0].rowIndex; ci = $.jgrid.getCellIndex(td); try {$(ts).jqGrid("editCell",ri,ci,true);} catch (_) {} } } else if ( !ts.p.multikey ) { if(ts.p.multiselect && ts.p.multiboxonly) { if(scb){$(ts).jqGrid("setSelection",ptr[0].id,true);} else { $(ts.p.selarrrow).each(function(i,n){ var ind = ts.rows.namedItem(n); $(ind).removeClass("ui-state-highlight"); $("#jqg_"+$.jgrid.jqID(n),ind).attr("checked",false); }); ts.p.selarrrow = []; $("#cb_"+$.jgrid.jqID(ts.p.id),ts.grid.hDiv).attr("checked",false); $(ts).jqGrid("setSelection",ptr[0].id,true); } } else { $(ts).jqGrid("setSelection",ptr[0].id,true); } } else { if(e[ts.p.multikey]) { $(ts).jqGrid("setSelection",ptr[0].id,true); } else if(ts.p.multiselect && scb) { scb = $("[id^=jqg_]",ptr).attr("checked"); $("[id^=jqg_]",ptr).attr("checked",!scb); } } if($.isFunction(ts.p.onCellSelect)) { ri = ptr[0].id; ci = $.jgrid.getCellIndex(td); ts.p.onCellSelect.call(ts,ri,ci,$(td).html(),e); } } e.stopPropagation(); }).bind('reloadGrid', function(e,opts) { if(ts.p.treeGrid ===true) { ts.p.datatype = ts.p.treedatatype;} if (opts && opts.current) { ts.grid.selectionPreserver(ts); } if(ts.p.datatype=="local" && !sr){ $(ts).jqGrid("resetSelection");} else if(!ts.p.treeGrid) { ts.p.selrow=null; if(ts.p.multiselect) {ts.p.selarrrow =[];$('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.hDiv).attr("checked",false);} ts.p.savedRow = []; if(ts.p.scroll) {emptyRows(ts.grid.bDiv);} } if (opts && 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) ts.grid.populateVisible(); else ts.grid.populate(); return false; }); if( $.isFunction(this.p.ondblClickRow) ) { $(this).dblclick(function(e) { td = e.target; ptr = $(td,ts.rows).closest("tr.jqgrow"); if($(ptr).length === 0 ){return false;} ri = ptr[0].rowIndex; ci = $.jgrid.getCellIndex(td); ts.p.ondblClickRow.call(ts,$(ptr).attr("id"),ri,ci, e); return false; }); } if ($.isFunction(this.p.onRightClickRow)) { $(this).bind('contextmenu', function(e) { td = e.target; ptr = $(td,ts.rows).closest("tr.jqgrow"); if($(ptr).length === 0 ){return false;} if(!ts.p.multiselect) { $(ts).jqGrid("setSelection",ptr[0].id,true); } ri = ptr[0].rowIndex; ci = $.jgrid.getCellIndex(td); ts.p.onRightClickRow.call(ts,$(ptr).attr("id"),ri,ci, e); return false; }); } grid.bDiv = document.createElement("div"); $(grid.bDiv) .append($('
').append('
').append(this)) .addClass("ui-jqgrid-bdiv") .css({ height: ts.p.height+(isNaN(ts.p.height)?"":"px"), width: (grid.width)+"px"}) .scroll(grid.scrollGrid); $("table:first",grid.bDiv).css({width:ts.p.tblwidth+"px"}); if( isMSIE ) { if( $("tbody",this).size() == 2 ) { $("tbody:first",this).remove();} if( ts.p.multikey) {$(grid.bDiv).bind("selectstart",function(){return false;});} } else { if( ts.p.multikey) {$(grid.bDiv).bind("mousedown",function(){return false;});} } if(hg) {$(grid.bDiv).hide();} grid.cDiv = document.createElement("div"); var arf = ts.p.hidegrid===true ? $("").addClass('ui-jqgrid-titlebar-close HeaderButton').hover( function(){ arf.addClass('ui-state-hover');}, function() {arf.removeClass('ui-state-hover');}) .append("").css((dir=="rtl"?"left":"right"),"0px") : ""; $(grid.cDiv).append(arf).append(""+ts.p.caption+"") .addClass("ui-jqgrid-titlebar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix"); $(grid.cDiv).insertBefore(grid.hDiv); if( ts.p.toolbar[0] ) { 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).insertBefore(grid.hDiv).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id); $(grid.ubDiv).insertAfter(grid.hDiv).addClass("ui-userdata ui-state-default").attr("id","tb_"+this.id); ts.p._height += IntNum($(grid.ubDiv).height()); if(hg) {$(grid.ubDiv).hide();} } else { $(grid.uDiv).width(grid.width).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id); } ts.p._height += IntNum($(grid.uDiv).height()); if(hg) {$(grid.uDiv).hide();} } if(ts.p.footerrow) { grid.sDiv = $("
")[0]; hb = $("
"); $(grid.sDiv).append(hb).insertAfter(grid.hDiv).width(grid.width); $(hb).append(tfoot); grid.footers = $(".ui-jqgrid-ftable",grid.sDiv)[0].rows[0].cells; if(ts.p.rownumbers) grid.footers[0].className = 'ui-state-default jqgrid-rownum'; if(hg) {$(grid.sDiv).hide();} } if(ts.p.caption) { ts.p._height += parseInt($(grid.cDiv,ts).height(),10); 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); if(ts.p.gridstate == 'visible') { $(".ui-jqgrid-bdiv, .ui-jqgrid-hdiv","#gview_"+ts.p.id).slideUp("fast"); if(ts.p.pager) {$(ts.p.pager).slideUp("fast");} if(ts.p.toolbar[0]===true) { if( ts.p.toolbar[1]=='both') { $(grid.ubDiv).slideUp("fast"); } $(grid.uDiv).slideUp("fast"); } if(ts.p.footerrow) $(".ui-jqgrid-sdiv","#gbox_"+ts.p.id).slideUp("fast"); $("span",this).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s"); ts.p.gridstate = 'hidden'; if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}} } else if(ts.p.gridstate == 'hidden'){ $(".ui-jqgrid-hdiv, .ui-jqgrid-bdiv","#gview_"+ts.p.id).slideDown("fast"); if(ts.p.pager) {$(ts.p.pager).slideDown("fast");} if(ts.p.toolbar[0]===true) { if( ts.p.toolbar[1]=='both') { $(grid.ubDiv).slideDown("fast"); } $(grid.uDiv).slideDown("fast"); } if(ts.p.footerrow) $(".ui-jqgrid-sdiv","#gbox_"+ts.p.id).slideDown("fast"); $("span",this).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n"); if(hg) {ts.p.datatype = tdt;populate();hg=false;} ts.p.gridstate = 'visible'; if(onHdCl) {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();} $(grid.hDiv).after(grid.bDiv); $(".ui-jqgrid-labels",grid.hDiv).bind("selectstart", function () { return false; }) .mousemove(function (e) { if(grid.resizing){grid.dragMove(e);return false;} }); ts.p._height += parseInt($(grid.hDiv).height(),10); $(document).mouseup(function (e) { if(grid.resizing) { grid.dragEnd(); return false;} return true; }); this.updateColumns = function () { var r = this.rows[0], self =this; if(r) { $("td",r).each( function( k ) { $(this).css("width",self.grid.headers[k].width+"px"); }); this.grid.cols = r.cells; } return this; } ts.formatCol = formatCol; ts.sortData = sortData; ts.updatepager = updatepager; ts.formatter = function ( rowId, cellval , colpos, rwdat, act){return formatter(rowId, cellval , colpos, rwdat, act);}; $.extend(grid,{populate : populate, emptyRows: emptyRows}); this.grid = grid; ts.addXmlData = function(d) {addXmlData(d,ts.grid.bDiv);}; ts.addJSONData = function(d) {addJSONData(d,ts.grid.bDiv);}; populate();ts.p.hiddengrid=false; $(window).unload(function () { $(this).empty(); this.grid = null; this.p = null; }); }); }; $.jgrid.extend({ getGridParam : function(pName) { var $t = this[0]; if (!$t.grid) {return;} if (!pName) { return $t.p; } else {return typeof($t.p[pName]) != "undefined" ? $t.p[pName] : null;} }, setGridParam : function (newParams){ return this.each(function(){ if (this.grid && typeof(newParams) === 'object') {$.extend(true,this.p,newParams);} }); }, getDataIDs : function () { var ids=[], i=0, len; this.each(function(){ len = this.rows.length; if(len && len>0){ while(i=0 ){ if(ner > olr ) { scrGrid(ner,'d'); } else { scrGrid(ner,'u'); } } } if(!$t.p.multiselect) { if($(pt).attr("class") !== "subgrid") { if( $t.p.selrow ) {$("tr#"+$.jgrid.jqID($t.p.selrow),$t.grid.bDiv).removeClass("ui-state-highlight").attr("aria-selected","false") ;} $t.p.selrow = pt.id; $(pt).addClass("ui-state-highlight").attr("aria-selected","true"); if( $t.p.onSelectRow && onsr) { $t.p.onSelectRow($t.p.selrow, true); } } } else { $t.p.selrow = pt.id; ia = $.inArray($t.p.selrow,$t.p.selarrrow); if ( ia === -1 ){ if($(pt).attr("class") !== "subgrid") { $(pt).addClass("ui-state-highlight").attr("aria-selected","true");} stat = true; $("#jqg_"+$.jgrid.jqID($t.p.selrow),$t.rows).attr("checked",stat); $t.p.selarrrow.push($t.p.selrow); if( $t.p.onSelectRow && onsr) { $t.p.onSelectRow($t.p.selrow, stat); } } else { if($(pt).attr("class") !== "subgrid") { $(pt).removeClass("ui-state-highlight").attr("aria-selected","false");} stat = false; $("#jqg_"+$.jgrid.jqID($t.p.selrow),$t.rows).attr("checked",stat); $t.p.selarrrow.splice(ia,1); if( $t.p.onSelectRow && onsr) { $t.p.onSelectRow($t.p.selrow, stat); } tpsr = $t.p.selarrrow[0]; $t.p.selrow = (tpsr === undefined) ? null : tpsr; } } function scrGrid(iR,tp){ 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 == 'd') { if(nROT >= ch) { $($t.grid.bDiv)[0].scrollTop = st + nROT-pROT; } } if(tp == 'u'){ if (pROT < st) { $($t.grid.bDiv)[0].scrollTop = st - nROT+pROT; } } } }); }, resetSelection : function(){ return this.each(function(){ var t = this, ind; if(!t.p.multiselect) { if(t.p.selrow) { $("tr#"+$.jgrid.jqID(t.p.selrow),t.grid.bDiv).removeClass("ui-state-highlight").attr("aria-selected","false"); t.p.selrow = null; } } else { $(t.p.selarrrow).each(function(i,n){ ind = t.rows.namedItem(n); $(ind).removeClass("ui-state-highlight").attr("aria-selected","false"); $("#jqg_"+$.jgrid.jqID(n),ind).attr("checked",false); }); $("#cb_"+$.jgrid.jqID(t.p.id),t.grid.hDiv).attr("checked",false); t.p.selarrrow = []; } t.p.savedRow = []; }); }, getRowData : function( rowid ) { var res = {}, resall, getall=false, len, j=0; this.each(function(){ var $t = this,nm,ind; if(typeof(rowid) == 'undefined') { getall = true; resall = []; len = $t.rows.length; } else { ind = $t.rows.namedItem(rowid); if(!ind) return res; len = 1; } while(j span:first",ind).html(vl).attr("title",$.jgrid.stripHtml(vl)); } else { $("td:eq("+i+")",ind).html(vl).attr("title",$.jgrid.stripHtml(vl)); } success = true; } }); } if(cp === 'string') {$(ind).addClass(cssp);} else if(cp === 'object') {$(ind).css(cssp);} }); return success; }, addRowData : function(rowid,data,pos,src) { if(!pos) {pos = "last";} var success = false, nm, row="", gi=0, si=0, ni=0,sind, i, v, prp=""; if(data) { this.each(function() { var t = this; if(t.p.rownumbers===true){ prp = t.formatCol(ni,1); row += "0"; ni=1; } if(t.p.multiselect) { v = ""; prp = t.formatCol(ni,1); row += ""+v+""; gi = 1; } if(t.p.subGrid===true) { row += $(t).jqGrid("addSubGridCell",gi+ni,1); si=1; } if(typeof(rowid) != 'undefined') rowid = rowid+""; else { rowid = (t.p.records+1)+""; if(t.p.keyIndex !== false) { var cmn = t.p.colModel[t.p.keyIndex+gi+si+ni].name; if(typeof data[cmn] != "undefined") rowid = data[cmn]; } } for(i = gi+si+ni; i < this.p.colModel.length;i++){ nm = this.p.colModel[i].name; v = t.formatter( rowid, data[nm], i, data, 'add'); prp = t.formatCol(i,1); row += ""+v+""; } row = "" + row+""; if(t.p.subGrid===true) { row = $(row)[0]; $(t).jqGrid("addSubGrid",row,gi+ni); } if(t.rows.length === 0){ $("table:first",t.grid.bDiv).append(row); } else { switch (pos) { case 'last': $(t.rows[t.rows.length-1]).after(row); break; case 'first': $(t.rows[0]).before(row); break; case 'after': sind = t.rows.namedItem(src); if (sind) {$(t.rows[sind.rowIndex+1]).hasClass("ui-subgrid") ? $(t.rows[sind.rowIndex+1]).after(row) : $(sind).after(row);} break; case 'before': sind = t.rows.namedItem(src); if(sind) {$(sind).before(row);sind=sind.rowIndex;} break; } } t.p.records++; t.p.reccount++; if(!t.grid.cols || !t.grid.cols.length) t.grid.cols = t.rows[0].cells; if(pos==='first' || (pos==='before' && sind <= 1) || t.rows.length === 1 ){ t.updateColumns(); } if( t.p.altRows === true ) { var cn = t.p.altclass; if (pos == "last") { if ((t.rows.length-1)%2 == 1) {$(t.rows[t.rows.length-1]).addClass(cn);} } else { $(t.rows).each(function(i){ if(i % 2 ==1) $(this).addClass(cn); else $(this).removeClass(cn); }); } } try {t.p.afterInsertRow(rowid,data); } catch(e){} t.updatepager(true,true); success = true; }); } return success; }, footerData : function(action,data, format) { var nm, success=false, res={}; function isEmpty(obj) { for(var i in obj) { return false; } return true; } if(typeof(action) == "undefined") action = "get"; if(typeof(format) != "boolean") format = true; action = action.toLowerCase(); this.each(function(){ var t = this, vl, ind; 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]; $("tr.footrow td:eq("+i+")",t.grid.sDiv).html(vl).attr("title",$.jgrid.stripHtml(vl)); 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; if (!$t.grid ) {return;} if( typeof colname === 'string') {colname=[colname];} show = show !="none" ? "" : "none"; var sw = show == "" ? true :false; $(this.p.colModel).each(function(i) { if ($.inArray(this.name,colname) !== -1 && this.hidden === sw) { $("tr",$t.grid.hDiv).each(function(){ $("th:eq("+i+")",this).css("display",show); }); $($t.rows).each(function(j){ $("td:eq("+i+")",$t.rows[j]).css("display",show); }); if($t.p.footerrow) $("td:eq("+i+")",$t.grid.sDiv).css("display", show); if(show == "none") $t.p.tblwidth -= this.width; else $t.p.tblwidth += this.width; this.hidden = !sw; fndh=true; } }); if(fndh===true) { $("table:first",$t.grid.hDiv).width($t.p.tblwidth); $("table:first",$t.grid.bDiv).width($t.p.tblwidth); $t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft; if($t.p.footerrow) { $("table:first",$t.grid.sDiv).width($t.p.tblwidth); $t.grid.sDiv.scrollLeft = $t.grid.bDiv.scrollLeft; } } }); }, 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($("tbody:first", ts.grid.bDiv), ".jqgrow"); } 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); }, setGridWidth : function(nwidth, shrink) { return this.each(function(){ var $t = this, cw, initwidth = 0, brd=$t.p.cellLayout, lvc, vc=0, hs=false, scw=$t.p.scrollOffset, aw, gw=0, tw=0, cl = 0,cr; if (!$t.grid ) {return;} if(typeof shrink != 'boolean') { shrink=$t.p.shrinkToFit; } if(isNaN(nwidth)) {return;} else { nwidth = parseInt(nwidth); $t.grid.width = $t.p.width = nwidth;} $("#gbox_"+$t.p.id).css("width",nwidth+"px"); $("#gview_"+$t.p.id).css("width",nwidth+"px"); $($t.grid.bDiv).css("width",nwidth+"px"); $($t.grid.hDiv).css("width",nwidth+"px"); if($t.p.pager ) {$($t.p.pager).css("width",nwidth+"px");} if($t.p.toolbar[0] === true){ $($t.grid.uDiv).css("width",nwidth+"px"); if($t.p.toolbar[1]=="both") {$($t.grid.ubDiv).css("width",nwidth+"px");} } if($t.p.footerrow) $($t.grid.sDiv).css("width",nwidth+"px"); if(shrink ===false && $t.p.forceFit == true) {$t.p.forceFit=false;} if(shrink===true) { if ($.browser.safari) { brd=0;} $.each($t.p.colModel, function(i) { if(this.hidden===false){ initwidth += parseInt(this.width,10); if(this.fixed) { tw += this.width; gw += this.width+brd; } else { vc++; } cl++; } }); 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){ hs = true; aw -= scw; } } initwidth =0; var cle = $t.grid.cols.length >0; $.each($t.p.colModel, function(i) { var tn = this.name; if(this.hidden === false && !this.fixed){ cw = Math.floor((aw)/($t.p.tblwidth-tw)*this.width); 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; } }); 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; 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"; $t.p.tblwidth = initwidth+cr+tw+brd*cl; $('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) { $t.grid.footers[lvc].style.width = cw+"px"; $('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;} $($t.grid.bDiv).css({height: nh+(isNaN(nh)?"":"px")}); $t.p.height = nh; if ($t.p.scroll) $t.grid.populateVisible(); }); }, setCaption : function (newcap){ return this.each(function(){ this.p.caption=newcap; $("span.ui-jqgrid-title",this.grid.cDiv).html(newcap); $(this.grid.cDiv).show(); }); }, setLabel : function(colname, nData, prop, attrp ){ return this.each(function(){ var $t = this, pos=-1; 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 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) { return this.each(function(){ var $t = this, pos =-1,v; 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.rows.namedItem(rowid); if (ind){ var tcell = $("td:eq("+pos+")",ind); if(nData !== "") { v = $t.formatter(rowid, nData, pos,ind,'edit'); $(tcell).html(v).attr("title",$.jgrid.stripHtml(v)); } if (cssp){ if(typeof cssp === 'string') {$(tcell).addClass(cssp);} else {$(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.rows.namedItem(rowid); if(ind) { try { ret = $.unformat($("td:eq("+pos+")",ind),{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; obj = typeof (obj) != 'boolean' ? false : obj; if(typeof 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; if (ln && ln>0){ while(i0) { // prevent second click on that field and enable selects if (ed===true ) { if(iRow == $t.p.iRow && iCol == $t.p.iCol){ return; } } // if so check to see if the content is changed var vl = $("td:eq("+$t.p.savedRow[0].ic+")>#"+$t.p.savedRow[0].id+"_"+$.jgrid.jqID($t.p.savedRow[0].name),$t.rows[$t.p.savedRow[0].id]).val(); if ($t.p.savedRow[0].v != vl) { // save it $($t).jqGrid("saveCell",$t.p.savedRow[0].id,$t.p.savedRow[0].ic) } else { // restore it $($t).jqGrid("restoreCell",$t.p.savedRow[0].id,$t.p.savedRow[0].ic); } } else { window.setTimeout(function () { $("#"+$t.p.knv).attr("tabindex","-1").focus();},0); } nm = $t.p.colModel[iCol].name; if (nm=='subgrid' || nm=='cb' || nm=='rn') {return;} cc = $("td:eq("+iCol+")",$t.rows[iRow]); if ($t.p.colModel[iCol].editable===true && ed===true && !cc.hasClass("not-editable-cell")) { if(parseInt($t.p.iCol)>=0 && parseInt($t.p.iRow)>=0) { $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight"); $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover"); } $(cc).addClass("edit-cell ui-state-highlight"); $($t.rows[iRow]).addClass("selected-row ui-state-hover"); try { tmp = $.unformat(cc,{colModel:$t.p.colModel[iCol]},iCol); } catch (_) { tmp = $(cc).html(); } if (!$t.p.colModel[iCol].edittype) {$t.p.colModel[iCol].edittype = "text";} $t.p.savedRow.push({id:iRow,ic:iCol,name:nm,v:tmp}); if($.isFunction($t.p.formatCell)) { var tmp2 = $t.p.formatCell($t.rows[iRow].id,nm,tmp,iRow,iCol); if(tmp2 != undefined ) {tmp = tmp2;} } var opt = $.extend({}, $t.p.colModel[iCol].editoptions || {} ,{id:iRow+"_"+nm,name:nm}); var elc = createEl($t.p.colModel[iCol].edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {})); if ($.isFunction($t.p.beforeEditCell)) { $t.p.beforeEditCell($t.rows[iRow].id,nm,tmp,iRow,iCol); } $(cc).html("").append(elc).attr("tabindex","0"); window.setTimeout(function () { $(elc).focus();},0); $("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) {$($t).jqGrid("saveCell",iRow,iCol);}//Enter if (e.keyCode == 9) { if (e.shiftKey) {$($t).jqGrid("prevCell",iRow,iCol);} //Shift TAb else {$($t).jqGrid("nextCell",iRow,iCol);} //Tab } e.stopPropagation(); }); if ($.isFunction($t.p.afterEditCell)) { $t.p.afterEditCell($t.rows[iRow].id,nm,tmp,iRow,iCol); } } else { if (parseInt($t.p.iCol)>=0 && parseInt($t.p.iRow)>=0) { $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight"); $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover"); } cc.addClass("edit-cell ui-state-highlight"); $($t.rows[iRow]).addClass("selected-row ui-state-hover"); if ($.isFunction($t.p.onSelectCell)) { tmp = cc.html().replace(/\ \;/ig,''); $t.p.onSelectCell($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; 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) ; 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]).attr("checked") ? cbv[0] : cbv[1]; v2=v; break; case "password": case "text": case "textarea": case "button" : v = !$t.p.autoencode ? $("#"+iRow+"_"+nmjq,$t.rows[iRow]).val() : $.jgrid.htmlEncode($("#"+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($(".customelement",cc)); if (v===undefined) throw "e2"; else v2=v; } else throw "e1"; } catch (e) { if (e=="e1") info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,jQuery.jgrid.edit.bClose); if (e=="e2") info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,jQuery.jgrid.edit.bClose); else info_dialog(jQuery.jgrid.errors.errcap,e.message,jQuery.jgrid.edit.bClose); } break; } // The common approach is if nothing changed do not do anything if (v2 != $t.p.savedRow[fr].v){ if ($.isFunction($t.p.beforeSaveCell)) { var vv = $t.p.beforeSaveCell($t.rows[iRow].id,nm, v, iRow,iCol); if (vv) {v = vv;} } var cv = checkValues(v,iCol,$t); if(cv[0] === true) { var addpost = {}; if ($.isFunction($t.p.beforeSubmitCell)) { addpost = $t.p.beforeSubmitCell($t.rows[iRow].id,nm, v, iRow,iCol); if (!addpost) {addpost={};} } if(v2=="") v2=" "; if( $("input.hasDatepicker",cc).length >0) $("input.hasDatepicker",cc).datepicker('hide'); if ($t.p.cellsubmit == 'remote') { if ($t.p.cellurl) { var postdata = {}; postdata[nm] = v; postdata["id"] = $t.rows[iRow].id; postdata = $.extend(addpost,postdata); $.ajax( $.extend( { url: $t.p.cellurl, data :$.isFunction($t.p.serializeCellData) ? $t.p.serializeCellData(postdata) : postdata, type: "POST", complete: function (result, stat) { if (stat == 'success') { if ($.isFunction($t.p.afterSubmitCell)) { var ret = $t.p.afterSubmitCell(result,postdata.id,nm,v,iRow,iCol); if(ret[0] === true) { $(cc).empty(); $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, v2); $(cc).addClass("dirty-cell"); $($t.rows[iRow]).addClass("edited"); if ($.isFunction($t.p.afterSaveCell)) { $t.p.afterSaveCell($t.rows[iRow].id,nm, v, iRow,iCol); } $t.p.savedRow.splice(0,1); } else { info_dialog($.jgrid.errors.errcap,ret[1],$.jgrid.edit.bClose); $($t).jqGrid("restoreCell",iRow,iCol); } } else { $(cc).empty(); $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, v2); $(cc).addClass("dirty-cell"); $($t.rows[iRow]).addClass("edited"); if ($.isFunction($t.p.afterSaveCell)) { $t.p.afterSaveCell($t.rows[iRow].id,nm, v, iRow,iCol); } $t.p.savedRow.splice(0,1); } } }, error:function(res,stat){ if ($.isFunction($t.p.errorCell)) { $t.p.errorCell(res,stat); $($t).jqGrid("restoreCell",iRow,iCol); } else { info_dialog($.jgrid.errors.errcap,res.status+" : "+res.statusText+"
"+stat,$.jgrid.edit.bClose); $($t).jqGrid("restoreCell",iRow,iCol); } } }, $.jgrid.ajaxOptions, $t.p.ajaxCellOptions || {})); } else { try { info_dialog($.jgrid.errors.errcap,$.jgrid.errors.nourl,$.jgrid.edit.bClose); $($t).jqGrid("restoreCell",iRow,iCol); } catch (e) {} } } if ($t.p.cellsubmit == 'clientArray') { $(cc).empty(); $($t).jqGrid("setCell",$t.rows[iRow].id,iCol, v2); $(cc).addClass("dirty-cell"); $($t.rows[iRow]).addClass("edited"); if ($.isFunction($t.p.afterSaveCell)) { $t.p.afterSaveCell($t.rows[iRow].id,nm, v, iRow,iCol); } $t.p.savedRow.splice(0,1); } } else { try { window.setTimeout(function(){info_dialog($.jgrid.errors.errcap,v+" "+cv[1],$.jgrid.edit.bClose)},100); $($t).jqGrid("restoreCell",iRow,iCol); } catch (e) {} } } else { $($t).jqGrid("restoreCell",iRow,iCol); } } if ($.browser.opera) { $("#"+$t.p.knv).attr("tabindex","-1").focus(); } else { window.setTimeout(function () { $("#"+$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); $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; if (!$t.grid || $t.p.cellEdit !== true) {return;} // try to find next editable cell for (var i=iCol+1; i<$t.p.colModel.length; i++) { if ( $t.p.colModel[i].editable ===true) { 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; if (!$t.grid || $t.p.cellEdit !== true) {return;} // try to find next editable cell for (var i=iCol-1; i>=0; i--) { if ( $t.p.colModel[i].editable ===true) { 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; $(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; } return false; }); 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)) { $($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; }; }); }, 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(this,{colModel:$t.p.colModel[i]},i); } catch (e){ res[nm] = $.jgrid.htmlDecode($(this).html()); } } } else { try { res[nm] = $.unformat(this,{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 }); })(jQuery); /* * jqGrid common function * Tony Tomov tony@trirand.com * http://trirand.com/blog/ * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html */ // Modal functions var showModal = function(h) { h.w.show(); }; var closeModal = function(h) { h.w.hide().attr("aria-hidden","true"); if(h.o) { h.o.remove(); } }; var createModal = function(aIDs, content, p, insertSelector, posSelector, appendsel) { var mw = document.createElement('div'), rtlsup; rtlsup = jQuery(p.gbox).attr("dir") == "rtl" ? true : false; mw.className= "ui-widget ui-widget-content ui-corner-all ui-jqdialog"; mw.id = aIDs.themodal; var mh = document.createElement('div'); mh.className = "ui-jqdialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"; mh.id = aIDs.modalhead; jQuery(mh).append(""+p.caption+""); var ahr= jQuery("
") .hover(function(){ahr.addClass('ui-state-hover');}, function(){ahr.removeClass('ui-state-hover');}) .append(""); jQuery(mh).append(ahr); if(rtlsup) { mw.dir = "rtl"; jQuery(".ui-jqdialog-title",mh).css("float","right"); jQuery(".ui-jqdialog-titlebar-close",mh).css("left",0.3+"em"); } else { mw.dir = "ltr"; jQuery(".ui-jqdialog-title",mh).css("float","left"); jQuery(".ui-jqdialog-titlebar-close",mh).css("right",0.3+"em"); } var mc = document.createElement('div'); jQuery(mc).addClass("ui-jqdialog-content ui-widget-content").attr("id",aIDs.modalcontent); jQuery(mc).append(content); mw.appendChild(mc); jQuery(mw).prepend(mh); if(appendsel===true) { jQuery('body').append(mw); } //append as first child in body -for alert dialog else {jQuery(mw).insertBefore(insertSelector);} if(typeof p.jqModal === 'undefined') {p.jqModal = true;} // internal use var coord = {}; if ( jQuery.fn.jqm && p.jqModal === true) { if(p.left ==0 && p.top==0) { var pos = []; pos = 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"; } jQuery("a.ui-jqdialog-titlebar-close",mh).click(function(e){ var oncm = jQuery("#"+aIDs.themodal).data("onClose") || p.onClose; var gboxclose = jQuery("#"+aIDs.themodal).data("gbox") || p.gbox; hideModal("#"+aIDs.themodal,{gb:gboxclose,jqm:p.jqModal,onClose:oncm}); return false; }); if (p.width == 0 || !p.width) {p.width = 300;} if(p.height==0 || !p.height) {p.height =200;} if(!p.zIndex) {p.zIndex = 950;} var rtlt = 0; if( rtlsup && coord.left && !appendsel) { rtlt = jQuery(p.gbox).width()- (!isNaN(p.width) ? parseInt(p.width) :0) - 8; // to do // just in case coord.left = parseInt(coord.left) + parseInt(rtlt); } if(coord.left) coord.left += "px"; jQuery(mw).css(jQuery.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(typeof p.drag == 'undefined') { p.drag=true;} if(typeof p.resize == 'undefined') {p.resize=true;} if (p.drag) { jQuery(mh).css('cursor','move'); if(jQuery.fn.jqDrag) { jQuery(mw).jqDrag(mh); } else { try { jQuery(mw).draggable({handle: jQuery("#"+mh.id)}); } catch (e) {} } } if(p.resize) { if(jQuery.fn.jqResize) { jQuery(mw).append("
"); jQuery("#"+aIDs.themodal).jqResize(".jqResize",aIDs.scrollelm ? "#"+aIDs.scrollelm : false); } else { try { jQuery(mw).resizable({handles: 'se, sw',alsoResize: aIDs.scrollelm ? "#"+aIDs.scrollelm : false}); } catch (e) {} } } if(p.closeOnEscape === true){ jQuery(mw).keydown( function( e ) { if( e.which == 27 ) { var cone = jQuery("#"+aIDs.themodal).data("onClose") || p.onClose; hideModal(this,{gb:p.gbox,jqm:p.jqModal,onClose: cone}); } }); } }; var viewModal = function (selector,o){ o = jQuery.extend({ toTop: true, overlay: 10, modal: false, onShow: showModal, onHide: closeModal, gbox: '', jqm : true, jqM : true }, o || {}); if (jQuery.fn.jqm && o.jqm == true) { if(o.jqM) jQuery(selector).attr("aria-hidden","false").jqm(o).jqmShow(); else jQuery(selector).attr("aria-hidden","false").jqmShow(); } else { if(o.gbox != '') { jQuery(".jqgrid-overlay:first",o.gbox).show(); jQuery(selector).data("gbox",o.gbox); } jQuery(selector).show().attr("aria-hidden","false"); try{jQuery(':input:visible',selector)[0].focus();}catch(_){} } }; var hideModal = function (selector,o) { o = jQuery.extend({jqm : true, gb :''}, o || {}); if(o.onClose) { var oncret = o.onClose(selector); if (typeof oncret == 'boolean' && !oncret ) return; } if (jQuery.fn.jqm && o.jqm === true) { jQuery(selector).attr("aria-hidden","true").jqmHide(); } else { if(o.gb != '') { try {jQuery(".jqgrid-overlay:first",o.gb).hide();} catch (e){} } jQuery(selector).hide().attr("aria-hidden","true"); } }; function info_dialog(caption, content,c_b, modalopt) { var mopt = { width:290, height:'auto', dataheight: 'auto', drag: true, resize: false, caption:""+caption+"", left:250, top:170, zIndex : 1000, jqModal : true, 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... }; jQuery.extend(mopt,modalopt || {}); var jm = mopt.jqModal; if(jQuery.fn.jqm && !jm) jm = false; // in case there is no jqModal var buttstr =""; if(mopt.buttons.length > 0) { for(var i=0;i"+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+"
" : ""; cnt += "
"; try { if(jQuery("#info_dialog").attr("aria-hidden") == "false") hideModal("#info_dialog",{jqm:jm}); jQuery("#info_dialog").remove(); } catch (e){} createModal({ themodal:'info_dialog', modalhead:'info_head', modalcontent:'info_content', scrollelm: 'infocnt'}, cnt, mopt, '','',true ); // attach onclick after inserting into the dom if(buttstr) { jQuery.each(mopt.buttons,function(i){ jQuery("#"+this.id,"#info_id").bind('click',function(){mopt.buttons[i].onClick.call(jQuery("#info_dialog")); return false;}); }); } jQuery("#closedialog", "#info_id").click(function(e){ hideModal("#info_dialog",{jqm:jm}); return false; }); jQuery(".fm-button","#info_dialog").hover( function(){jQuery(this).addClass('ui-state-hover');}, function(){jQuery(this).removeClass('ui-state-hover');} ); viewModal("#info_dialog",{ onHide: function(h) { h.w.hide().remove(); if(h.o) { h.o.remove(); } }, modal :true, jqm:jm }); } //Helper functions function findPos(obj) { var curleft = 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]; } function isArray(obj) { if (obj.constructor.toString().indexOf("Array") == -1) { return false; } else { return true; } } // Form Functions function createEl(eltype,options,vl,autowidth, ajaxso) { var elem = ""; if(options.defaultValue) delete options['defaultValue']; function bindEv (el, opt) { if(jQuery.isFunction(opt.dataInit)) { // datepicker fix el.id = opt.id; opt.dataInit(el); delete opt['id']; delete opt['dataInit']; } if(opt.dataEvents) { jQuery.each(opt.dataEvents, function() { if (this.data != null) jQuery(el).bind(this.type, this.data, this.fn); else jQuery(el).bind(this.type, this.fn); }); delete opt['dataEvents']; } return opt; } switch (eltype) { case "textarea" : elem = document.createElement("textarea"); if(autowidth) { if(!options.cols) jQuery(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; options = bindEv(elem,options); jQuery(elem).attr(options); 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|0|no|off|undefined)/i)<0 && vl1!=="") { elem.checked=true; elem.defaultChecked=true; elem.value = vl; } else { elem.value = "on"; } jQuery(elem).attr("offval","off"); } else { var cbval = options.value.split(":"); if(vl === cbval[0]) { elem.checked=true; elem.defaultChecked=true; } elem.value = cbval[0]; jQuery(elem).attr("offval",cbval[1]); try {delete options['value'];} catch (e){} } options = bindEv(elem,options); jQuery(elem).attr(options); break; case "select" : elem = document.createElement("select"); var msl, ovm = []; if(options.multiple===true) { msl = true; elem.multiple="multiple"; } else msl = false; if(options.dataUrl != null) { jQuery.ajax(jQuery.extend({ url: options.dataUrl, type : "GET", complete: function(data,status){ try {delete options['dataUrl'];delete options['value'];} catch (e){} var a; if(options.buildSelect != null) { var b = options.buildSelect(data); a = jQuery(b).html(); delete options['buildSelect']; } else a = jQuery(data.responseText).html(); if(a) { jQuery(elem).append(a); options = bindEv(elem,options); if(typeof options.size === 'undefined') { options.size = msl ? 3 : 1;} if(msl) { ovm = vl.split(","); ovm = jQuery.map(ovm,function(n){return jQuery.trim(n)}); } else { ovm[0] = vl; } jQuery(elem).attr(options); setTimeout(function(){ jQuery("option",elem).each(function(i){ if(i==0) this.selected = ""; if(jQuery.inArray(jQuery(this).text(),ovm) > -1 || jQuery.inArray(jQuery(this).val(),ovm)>-1) { this.selected= "selected"; if(!msl) return false; } }); },0); } } },ajaxso || {})); } else if(options.value) { var i; if(msl) { ovm = vl.split(","); ovm = jQuery.map(ovm,function(n){return jQuery.trim(n)}); if(typeof options.size === 'undefined') {options.size = 3;} } else { options.size = 1; } if(typeof options.value === 'function') options.value = options.value(); if(typeof options.value === 'string') { var so = options.value.split(";"),sv, ov; for(i=0; i-1 || jQuery.inArray(sv[0], ovm)>-1)) {ov.selected ="selected";} elem.appendChild(ov); } } else if (typeof options.value === 'object') { var oSv = options.value; for ( var key in oSv) { ov = document.createElement("option"); ov.value = key; ov.innerHTML = oSv[key]; if (!msl && (key == vl ||oSv[key]==vl) ) ov.selected ="selected"; if (msl && (jQuery.inArray(oSv[key],ovm)>-1 || jQuery.inArray(key,ovm)>-1)) ov.selected ="selected"; elem.appendChild(ov); } } options = bindEv(elem,options); try {delete options['value'];} catch (e){} jQuery(elem).attr(options); } break; case "text" : case "password" : case "button" : elem = document.createElement("input"); elem.type = eltype; elem.value = jQuery.jgrid.htmlDecode(vl); options = bindEv(elem,options); if(eltype != "button"){ if(autowidth) { if(!options.size) jQuery(elem).css({width:"98%"}); } else if (!options.size) options.size = 20; } jQuery(elem).attr(options); break; case "image" : case "file" : elem = document.createElement("input"); elem.type = eltype; options = bindEv(elem,options); jQuery(elem).attr(options); break; case "custom" : elem = document.createElement("span"); try { if(jQuery.isFunction(options.custom_element)) { var celm = options.custom_element.call(this,vl,options); if(celm) { celm = jQuery(celm).addClass("customelement").attr({id:options.id,name:options.name}); jQuery(elem).empty().append(celm); } else throw "e2"; } else throw "e1"; } catch (e) { if (e=="e1") info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_element' "+jQuery.jgrid.edit.msg.nodefined, jQuery.jgrid.edit.bClose); if (e=="e2") info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_element' "+jQuery.jgrid.edit.msg.novalue,jQuery.jgrid.edit.bClose); else info_dialog(jQuery.jgrid.errors.errcap,e.message,jQuery.jgrid.edit.bClose); } break; } return elem; } function checkValues(val, valref,g) { var edtrul,i, nm; if(typeof(valref)=='string'){ for( i =0, len=g.p.colModel.length;i=0) { edtrul = g.p.colModel[valref].editrules; } if(edtrul) { if(!nm) nm = g.p.colNames[valref]; if(edtrul.required === true) { if( val.match(/^s+$/) || val == "" ) return [false,nm+": "+jQuery.jgrid.edit.msg.required,""]; } // force required var rqfield = edtrul.required === false ? false : true; if(edtrul.number === true) { if( !(rqfield === false && isEmpty(val)) ) { if(isNaN(val)) return [false,nm+": "+jQuery.jgrid.edit.msg.number,""]; } } if(typeof edtrul.minValue != 'undefined' && !isNaN(edtrul.minValue)) { if (parseFloat(val) < parseFloat(edtrul.minValue) ) return [false,nm+": "+jQuery.jgrid.edit.msg.minValue+" "+edtrul.minValue,""]; } if(typeof edtrul.maxValue != 'undefined' && !isNaN(edtrul.maxValue)) { if (parseFloat(val) > parseFloat(edtrul.maxValue) ) return [false,nm+": "+jQuery.jgrid.edit.msg.maxValue+" "+edtrul.maxValue,""]; } var filter; if(edtrul.email === true) { if( !(rqfield === false && isEmpty(val)) ) { // taken from jquery 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+": "+jQuery.jgrid.edit.msg.email,""];} } } if(edtrul.integer === true) { if( !(rqfield === false && isEmpty(val)) ) { if(isNaN(val)) return [false,nm+": "+jQuery.jgrid.edit.msg.integer,""]; if ((val % 1 != 0) || (val.indexOf('.') != -1)) return [false,nm+": "+jQuery.jgrid.edit.msg.integer,""]; } } if(edtrul.date === true) { if( !(rqfield === false && isEmpty(val)) ) { var dft = g.p.colModel[valref].datefmt || "Y-m-d"; if(!checkDate (dft, val)) return [false,nm+": "+jQuery.jgrid.edit.msg.date+" - "+dft,""]; } } if(edtrul.time === true) { if( !(rqfield === false && isEmpty(val)) ) { if(!checkTime (val)) return [false,nm+": "+jQuery.jgrid.edit.msg.date+" - hh:mm (am/pm)",""]; } } if(edtrul.url === true) { if( !(rqfield === false && isEmpty(val)) ) { filter = /^(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i; if(!filter.test(val)) {return [false,nm+": "+jQuery.jgrid.edit.msg.url,""];} } } if(edtrul.custom === true) { if( !(rqfield === false && isEmpty(val)) ) { if(jQuery.isFunction(edtrul.custom_func)) { var ret = edtrul.custom_func.call(g,val,nm); if(jQuery.isArray(ret)) { return ret; } else { return [false,jQuery.jgrid.edit.msg.customarray,""]; } } else { return [false,jQuery.jgrid.edit.msg.customfcheck,""]; } } } } return [true,"",""]; } // Date Validation Javascript function checkDate (format, date) { var 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; for(var i=0;i12){ return false; } } if(dln === -1) { return false; } else { 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; } function daysInFebruary (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 ); } function DaysArray(n) { for (var i = 1; i <= n; i++) { this[i] = 31; if (i==4 || i==6 || i==9 || i==11) {this[i] = 30;} if (i==2) {this[i] = 29;} } return this; } function isEmpty(val) { if (val.match(/^s+$/) || val == "") { return true; } else { return false; } } function checkTime(time){ // checks only hh:ss (and optional am/pm) var re = /^(\d{1,2}):(\d{2})([ap]m)?$/,regs; if(!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; } ;(function($){ /** * jqGrid extension for custom methods * Tony Tomov tony@trirand.com * http://trirand.com/blog/ * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html **/ $.jgrid.extend({ getColProp : function(colname){ var ret ={}, $t = this[0]; if ( !$t.grid ) { return; } var cM = $t.p.colModel; for ( var i =0;i0 ) { $(data).each(function(j){ srow = this; ind = t.rows.namedItem(srow[rowidname]); if(ind) { sid = srow[rowidname]; if(jsonreader === true){ if(t.p.jsonReader.repeatitems === true) { if(t.p.jsonReader.cell) {srow = srow[t.p.jsonReader.cell];} for (var k=0;k span:first",ind).html(vl).attr("title",$.jgrid.stripHtml(vl)); } else { $("td:eq("+k+")",ind).html(vl).attr("title",$.jgrid.stripHtml(vl)); } } success = true; return true; } } $(t.p.colModel).each(function(i){ nm = jsonreader===true ? this.jsonmap || this.name :this.name; if( srow[nm] != undefined) { vl = t.formatter( sid, srow[nm], i, srow, 'edit'); if(t.p.treeGrid===true && nm == t.p.ExpandColumn) { $("td:eq("+i+") > span:first",ind).html(vl).attr("title",$.jgrid.stripHtml(vl)); } else { $("td:eq("+i+")",ind).html(vl).attr("title",$.jgrid.stripHtml(vl)); } success = true; } }); } }); } }); return success; }, filterGrid : function(gridid,p){ p = $.extend({ gridModel : false, gridNames : false, gridToolbar : false, filterModel: [], // label/name/stype/defval/surl/sopt formtype : "horizontal", // horizontal/vertical autosearch: true, // if set to false a serch button should be enabled. formclass: "filterform", tableclass: "filtertable", buttonclass: "filterbutton", searchButton: "Search", clearButton: "Clear", enableSearch : false, enableClear: false, beforeSearch: null, afterSearch: null, beforeClear: null, afterClear: null, url : '', marksearched: true },p || {}); return this.each(function(){ var self = this; this.p = p; if(this.p.filterModel.length == 0 && this.p.gridModel===false) { alert("No filter is set"); return;} if( !gridid) {alert("No target grid is set!"); return;} this.p.gridid = gridid.indexOf("#") != -1 ? gridid : "#"+gridid; var gcolMod = $(this.p.gridid).jqGrid("getGridParam",'colModel'); if(gcolMod) { if( this.p.gridModel === true) { var thegrid = $(this.p.gridid)[0]; var sh; // we should use the options search, edittype, editoptions // additionally surl and defval can be added in grid colModel $.each(gcolMod, function (i,n) { var tmpFil = []; this.search = this.search === false ? false : true; if(this.editrules && this.editrules.searchhidden === true) { sh = true; } else { if(this.hidden === true ) { sh = false; } else { sh = true; } } if( this.search === true && sh === true) { if(self.p.gridNames===true) { tmpFil.label = thegrid.p.colNames[i]; } else { tmpFil.label = ''; } tmpFil.name = this.name; tmpFil.index = this.index || this.name; // we support only text and selects, so all other to text tmpFil.stype = this.edittype || 'text'; if(tmpFil.stype != 'select' ) { tmpFil.stype = 'text'; } tmpFil.defval = this.defval || ''; tmpFil.surl = this.surl || ''; tmpFil.sopt = this.editoptions || {}; tmpFil.width = this.width; self.p.filterModel.push(tmpFil); } }); } else { $.each(self.p.filterModel,function(i,n) { for(var j=0;j0 ? true : false; $.extend(gr.p.postData,sdata); var saveurl; if(self.p.url) { saveurl = $(gr).jqGrid("getGridParam",'url'); $(gr).jqGrid("setGridParam",{url:self.p.url}); } $(gr).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]); if(saveurl) {$(gr).jqGrid("setGridParam",{url:saveurl});} if($.isFunction(self.p.afterSearch)){self.p.afterSearch();} }; var clearSearch = function(){ var sdata={}, v, j=0; var gr = $(self.p.gridid)[0], nm; if($.isFunction(self.p.beforeClear)){self.p.beforeClear();} $.each(self.p.filterModel,function(i,n){ nm = this.index; v = (this.defval) ? this.defval : ""; if(!this.stype){this.stype=='text';} switch (this.stype) { case 'select' : var v1; $("select[name="+nm+"] option",self).each(function (i){ if(i==0) this.selected = true; if ($(this).text() == v) { this.selected = true; v1 = $(this).val(); return false; } }); if(v1) { // post the key and not the text sdata[nm] = v1; if(self.p.marksearched){ $("#jqgh_"+this.name,gr.grid.hDiv).addClass("dirty-cell"); } j++; } else { if(self.p.marksearched){ $("#jqgh_"+this.name,gr.grid.hDiv).removeClass("dirty-cell"); } try { delete gr.p.postData[this.index]; } catch (e) {} } break; case 'text': $("input[name="+nm+"]",self).val(v); if(v) { sdata[nm] = v; if(self.p.marksearched){ $("#jqgh_"+this.name,gr.grid.hDiv).addClass("dirty-cell"); } j++; } else { if(self.p.marksearched){ $("#jqgh_"+this.name,gr.grid.hDiv).removeClass("dirty-cell"); } try { delete gr.p.postData[this.index]; } catch (e) {} } break; } }); var sd = j>0 ? true : false; $.extend(gr.p.postData,sdata); var saveurl; if(self.p.url) { saveurl = $(gr).jqGrid("getGridParam",'url'); $(gr).jqGrid("setGridParam",{url:self.p.url}); } $(gr).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]); if(saveurl) {$(gr).jqGrid("setGridParam",{url:saveurl});} if($.isFunction(self.p.afterClear)){self.p.afterClear();} }; var formFill = function(){ var tr = document.createElement("tr"); var tr1, sb, cb,tl,td, td1; if(self.p.formtype=='horizontal'){ $(tbl).append(tr); } $.each(self.p.filterModel,function(i,n){ tl = document.createElement("td"); $(tl).append(""); td = document.createElement("td"); var $t=this; if(!this.stype) { this.stype='text';} switch (this.stype) { case "select": if(this.surl) { // data returned should have already constructed html select $(td).load(this.surl,function(){ if($t.defval) $("select",this).val($t.defval); $("select",this).attr({name:$t.index || $t.name, id: "sg_"+$t.name}); if($t.sopt) $("select",this).attr($t.sopt); if(self.p.gridToolbar===true && $t.width) { $("select",this).width($t.width); } if(self.p.autosearch===true){ $("select",this).change(function(e){ triggerSearch(); return false; }); } }); } else { // sopt to construct the values if($t.sopt.value) { var oSv = $t.sopt.value; var elem = document.createElement("select"); $(elem).attr({name:$t.index || $t.name, id: "sg_"+$t.name}).attr($t.sopt); if(typeof oSv === "string") { var so = oSv.split(";"), sv, ov; for(var k=0; k"); if($t.sopt) $("input",td).attr($t.sopt); if(self.p.gridToolbar===true && $t.width) { if($.browser.msie) { $("input",td).width($t.width-4); } else { $("input",td).width($t.width-2); } } if(self.p.autosearch===true){ $("input",td).keypress(function(e){ var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0; if(key == 13){ triggerSearch(); return false; } return this; }); } break; } if(self.p.formtype=='horizontal'){ if(self.p.gridToolbar===true && self.p.gridNames===false) { $(tr).append(td); } else { $(tr).append(tl).append(td); } $(tr).append(td); } else { tr1 = document.createElement("tr"); $(tr1).append(tl).append(td); $(tbl).append(tr1); } }); td = document.createElement("td"); if(self.p.enableSearch === true){ sb = ""; $(td).append(sb); $("input#sButton",td).click(function(){ triggerSearch(); return false; }); } if(self.p.enableClear === true) { cb = ""; $(td).append(cb); $("input#cButton",td).click(function(){ clearSearch(); return false; }); } if(self.p.enableClear === true || self.p.enableSearch === true) { if(self.p.formtype=='horizontal') { $(tr).append(td); } else { tr1 = document.createElement("tr"); $(tr1).append(" ").append(td); $(tbl).append(tr1); } } }; var frm = $("
"); var tbl =$("
"); $(frm).append(tbl); formFill(); $(this).append(frm); this.triggerSearch = triggerSearch; this.clearSearch = clearSearch; }); }, filterToolbar : function(p){ p = $.extend({ autosearch: true, beforeSearch: null, afterSearch: null, beforeClear: null, afterClear: null, searchurl : '' },p || {}); return this.each(function(){ var $t = this; var triggerToolbar = function() { var sdata={}, j=0, v, nm; $t.p.searchdata = {}; $.each($t.p.colModel,function(i,n){ nm = this.index || this.name; switch (this.stype) { case 'select' : v = $("select[name="+nm+"]",$t.grid.hDiv).val(); if(v) { sdata[nm] = v; j++; } else { try { delete $t.p.postData[nm]; } catch (e) {} } break; case 'text': v = $("input[name="+nm+"]",$t.grid.hDiv).val(); if(v) { sdata[nm] = v; j++; } else { try { delete $t.p.postData[nm]; } catch (e) {} } break; } }); var sd = j>0 ? true : false; $.extend($t.p.postData,sdata); var saveurl; if($t.p.searchurl) { saveurl = $t.p.url; $($t).jqGrid("setGridParam",{url:$t.p.searchurl}); } var bsr = false; if($.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});} if($.isFunction(p.afterSearch)){p.afterSearch();} }; var clearToolbar = function(){ var sdata={}, v, j=0, nm; $.each($t.p.colModel,function(i,n){ v = (this.searchoptions && this.searchoptions.defaultValue) ? this.searchoptions.defaultValue : ""; nm = this.index || this.name; switch (this.stype) { case 'select' : var v1; $("select[name="+nm+"] option",$t.grid.hDiv).each(function (i){ if(i==0) this.selected = true; if ($(this).text() == v) { this.selected = true; v1 = $(this).val(); return false; } }); if (v1) { // post the key and not the text sdata[nm] = v1; j++; } else { try { delete $t.p.postData[nm]; } catch(e) {} } break; case 'text': $("input[name="+nm+"]",$t.grid.hDiv).val(v); if(v) { sdata[nm] = v; j++; } else { try { delete $t.p.postData[nm]; } catch (e){} } break; } }); var sd = j>0 ? true : false; $.extend($t.p.postData,sdata); var saveurl; if($t.p.searchurl) { saveurl = $t.p.url; $($t).jqGrid("setGridParam",{url:$t.p.searchurl}); } var bcv = false; if($.isFunction(p.beforeClear)){bcv = p.beforeClear.call($t);} if(!bcv) $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]); if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});} if($.isFunction(p.afterClear)){p.afterClear();} }; var toggleToolbar = function(){ var trow = $("tr.ui-search-toolbar",$t.grid.hDiv); if(trow.css("display")=='none') trow.show(); else trow.hide(); }; // create the row function bindEvents(selector, events) { var jElem = $(selector); if (jElem[0] != null) { jQuery.each(events, function() { if (this.data != null) jElem.bind(this.type, this.data, this.fn); else jElem.bind(this.type, this.fn); }); } } var tr = $(""), th,thd, soptions; $.each($t.p.colModel,function(i,n){ var cm=this; th = $(""); thd = $("
"); if(this.hidden===true) { $(th).css("display","none");} this.search = this.search === false ? false : true; if(typeof this.stype == 'undefined' ) {this.stype='text';} soptions = $.extend({},this.searchoptions || {}); if(this.search){ switch (this.stype) { case "select": var surl = this.surl || soptions.dataUrl; if(surl) { // data returned should have already constructed html select // primitive jQuery load var self = thd; $.ajax($.extend({ url: surl, dataType: "html", complete: function(res,status) { if(soptions.buildSelect != null) { var d = soptions.buildSelect(res); if (d) $(self).append(d); } else $(self).append(res.responseText); if(soptions.defaultValue) $("select",self).val(soptions.defaultValue); $("select",self).attr({name:cm.index || cm.name, id: "gs_"+cm.name}); if(soptions.attr) {$("select",self).attr(soptions.attr);} $("select",self).css({width: "100%"}); // preserve autoserch if(soptions.dataInit != null) soptions.dataInit($("select",self)[0]); if(soptions.dataEvents != null) bindEvents($("select",self)[0],soptions.dataEvents); if(p.autosearch===true){ $("select",self).change(function(e){ triggerToolbar(); return false; }); } } }, $.jgrid.ajaxOptions, $t.p.ajaxSelectOptions || {} )); } else { var oSv; if(cm.searchoptions && cm.searchoptions.value) oSv = cm.searchoptions.value; else if(cm.editoptions && cm.editoptions.value) { oSv = cm.editoptions.value; } if (oSv) { var elem = document.createElement("select"); elem.style.width = "100%"; $(elem).attr({name:cm.index || cm.name, id: "gs_"+cm.name}); if(typeof oSv === "string") { var so = oSv.split(";"), sv, ov; for(var k=0; k"); if(soptions.attr) {$("input",thd).attr(soptions.attr);} if(soptions.dataInit != null) soptions.dataInit($("input",thd)[0]); if(soptions.dataEvents != null) bindEvents($("input",thd)[0], soptions.dataEvents); if(p.autosearch===true){ $("input",thd).keypress(function(e){ var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0; if(key == 13){ triggerToolbar(); return false; } return this; }); } break; } } $(th).append(thd); $(tr).append(th); }); $("table thead",$t.grid.hDiv).append(tr); this.triggerToolbar = triggerToolbar; this.clearToolbar = clearToolbar; this.toggleToolbar = toggleToolbar; }); } }); })(jQuery); ;(function($){ /** * jqGrid extension for form editing Grid Data * Tony Tomov tony@trirand.com * http://trirand.com/blog/ * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html **/ var rp_ge = null; $.jgrid.extend({ searchGrid : function (p) { p = $.extend({ recreateFilter: false, drag: true, sField:'searchField', sValue:'searchString', sOper: 'searchOper', sFilter: 'filters', beforeShowSearch: null, afterShowSearch : null, onInitializeSearch: null, closeAfterSearch : false, closeOnEscape : false, multipleSearch : false, // translation // if you want to change or remove the order change it in sopt // ['bw','eq','ne','lt','le','gt','ge','ew','cn'] sopt: null, onClose : null // these are common options }, $.jgrid.search, p || {}); return this.each(function() { var $t = this; if(!$t.grid) {return;} if($.fn.searchFilter) { var fid = "fbox_"+$t.p.id; if(p.recreateFilter===true) {$("#"+fid).remove();} if( $("#"+fid).html() != null ) { if ( $.isFunction(p.beforeShowSearch) ) { p.beforeShowSearch($("#"+fid)); }; showFilter(); if( $.isFunction(p.afterShowSearch) ) { p.afterShowSearch($("#"+fid)); } } else { var fields = [], colNames = $("#"+$t.p.id).jqGrid("getGridParam","colNames"), colModel = $("#"+$t.p.id).jqGrid("getGridParam","colModel"), stempl = ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc'], j,pos,k,oprtr; oprtr = jQuery.fn.searchFilter.defaults.operators; if (p.sopt !=null) { oprtr = []; k=0; for(j=0;j