grid.base.js 135 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014
  1. // ==ClosureCompiler==
  2. // @compilation_level SIMPLE_OPTIMIZATIONS
  3. /**
  4. * @license jqGrid 4.7.0 - jQuery Grid
  5. * Copyright (c) 2008, Tony Tomov, tony@trirand.com
  6. * Dual licensed under the MIT and GPL licenses
  7. * http://www.opensource.org/licenses/mit-license.php
  8. * http://www.gnu.org/licenses/gpl-2.0.html
  9. * Date: 2014-12-08
  10. */
  11. //jsHint options
  12. /*jshint evil:true, eqeqeq:false, eqnull:true, devel:true */
  13. /*global jQuery */
  14. (function ($) {
  15. "use strict";
  16. $.jgrid = $.jgrid || {};
  17. $.extend($.jgrid,{
  18. version : "4.7.0",
  19. htmlDecode : function(value){
  20. if(value && (value===' ' || value===' ' || (value.length===1 && value.charCodeAt(0)===160))) { return "";}
  21. return !value ? value : String(value).replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"').replace(/&amp;/g, "&");
  22. },
  23. htmlEncode : function (value){
  24. return !value ? value : String(value).replace(/&/g, "&amp;").replace(/\"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  25. },
  26. format : function(format){ //jqgformat
  27. var args = $.makeArray(arguments).slice(1);
  28. if(format==null) { format = ""; }
  29. return format.replace(/\{(\d+)\}/g, function(m, i){
  30. return args[i];
  31. });
  32. },
  33. msie : navigator.appName === 'Microsoft Internet Explorer',
  34. msiever : function () {
  35. var rv = -1;
  36. var ua = navigator.userAgent;
  37. var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
  38. if (re.exec(ua) != null) {
  39. rv = parseFloat( RegExp.$1 );
  40. }
  41. return rv;
  42. },
  43. getCellIndex : function (cell) {
  44. var c = $(cell);
  45. if (c.is('tr')) { return -1; }
  46. c = (!c.is('td') && !c.is('th') ? c.closest("td,th") : c)[0];
  47. if ($.jgrid.msie) { return $.inArray(c, c.parentNode.cells); }
  48. return c.cellIndex;
  49. },
  50. stripHtml : function(v) {
  51. v = String(v);
  52. var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
  53. if (v) {
  54. v = v.replace(regexp,"");
  55. return (v && v !== '&nbsp;' && v !== '&#160;') ? v.replace(/\"/g,"'") : "";
  56. }
  57. return v;
  58. },
  59. stripPref : function (pref, id) {
  60. var obj = $.type( pref );
  61. if( obj === "string" || obj === "number") {
  62. pref = String(pref);
  63. id = pref !== "" ? String(id).replace(String(pref), "") : id;
  64. }
  65. return id;
  66. },
  67. parse : function(jsonString) {
  68. var js = jsonString;
  69. if (js.substr(0,9) === "while(1);") { js = js.substr(9); }
  70. if (js.substr(0,2) === "/*") { js = js.substr(2,js.length-4); }
  71. if(!js) { js = "{}"; }
  72. return ($.jgrid.useJSON===true && typeof JSON === 'object' && typeof JSON.parse === 'function') ?
  73. JSON.parse(js) :
  74. eval('(' + js + ')');
  75. },
  76. parseDate : function(format, date, newformat, opts) {
  77. var token = /\\.|[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g,
  78. timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
  79. timezoneClip = /[^-+\dA-Z]/g,
  80. msDateRegExp = new RegExp("^\/Date\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\)\/$"),
  81. msMatch = ((typeof date === 'string') ? date.match(msDateRegExp): null),
  82. pad = function (value, length) {
  83. value = String(value);
  84. length = parseInt(length,10) || 2;
  85. while (value.length < length) { value = '0' + value; }
  86. return value;
  87. },
  88. ts = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0, u:0},
  89. timestamp=0, dM, k,hl,
  90. h12to24 = function(ampm, h){
  91. if (ampm === 0){ if (h === 12) { h = 0;} }
  92. else { if (h !== 12) { h += 12; } }
  93. return h;
  94. },
  95. offset =0;
  96. if(opts === undefined) {
  97. opts = $.jgrid.formatter.date;
  98. }
  99. // old lang files
  100. if(opts.parseRe === undefined ) {
  101. opts.parseRe = /[#%\\\/:_;.,\t\s-]/;
  102. }
  103. if( opts.masks.hasOwnProperty(format) ) { format = opts.masks[format]; }
  104. if(date && date != null) {
  105. if( !isNaN( date - 0 ) && String(format).toLowerCase() === "u") {
  106. //Unix timestamp
  107. timestamp = new Date( parseFloat(date)*1000 );
  108. } else if(date.constructor === Date) {
  109. timestamp = date;
  110. // Microsoft date format support
  111. } else if( msMatch !== null ) {
  112. timestamp = new Date(parseInt(msMatch[1], 10));
  113. if (msMatch[3]) {
  114. offset = Number(msMatch[5]) * 60 + Number(msMatch[6]);
  115. offset *= ((msMatch[4] === '-') ? 1 : -1);
  116. offset -= timestamp.getTimezoneOffset();
  117. timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
  118. }
  119. } else {
  120. //Support ISO8601Long that have Z at the end to indicate UTC timezone
  121. if(opts.srcformat === 'ISO8601Long' && date.charAt(date.length - 1) === 'Z') {
  122. offset -= (new Date()).getTimezoneOffset();
  123. }
  124. date = String(date).replace(/\T/g,"#").replace(/\t/,"%").split(opts.parseRe);
  125. format = format.replace(/\T/g,"#").replace(/\t/,"%").split(opts.parseRe);
  126. // parsing for month names
  127. for(k=0,hl=format.length;k<hl;k++){
  128. if(format[k] === 'M') {
  129. dM = $.inArray(date[k],opts.monthNames);
  130. if(dM !== -1 && dM < 12){date[k] = dM+1; ts.m = date[k];}
  131. }
  132. if(format[k] === 'F') {
  133. dM = $.inArray(date[k],opts.monthNames,12);
  134. if(dM !== -1 && dM > 11){date[k] = dM+1-12; ts.m = date[k];}
  135. }
  136. if(format[k] === 'a') {
  137. dM = $.inArray(date[k],opts.AmPm);
  138. if(dM !== -1 && dM < 2 && date[k] === opts.AmPm[dM]){
  139. date[k] = dM;
  140. ts.h = h12to24(date[k], ts.h);
  141. }
  142. }
  143. if(format[k] === 'A') {
  144. dM = $.inArray(date[k],opts.AmPm);
  145. if(dM !== -1 && dM > 1 && date[k] === opts.AmPm[dM]){
  146. date[k] = dM-2;
  147. ts.h = h12to24(date[k], ts.h);
  148. }
  149. }
  150. if (format[k] === 'g') {
  151. ts.h = parseInt(date[k], 10);
  152. }
  153. if(date[k] !== undefined) {
  154. ts[format[k].toLowerCase()] = parseInt(date[k],10);
  155. }
  156. }
  157. if(ts.f) {ts.m = ts.f;}
  158. if( ts.m === 0 && ts.y === 0 && ts.d === 0) {
  159. return "&#160;" ;
  160. }
  161. ts.m = parseInt(ts.m,10)-1;
  162. var ty = ts.y;
  163. if (ty >= 70 && ty <= 99) {ts.y = 1900+ts.y;}
  164. else if (ty >=0 && ty <=69) {ts.y= 2000+ts.y;}
  165. timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
  166. //Apply offset to show date as local time.
  167. if(offset > 0) {
  168. timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
  169. }
  170. }
  171. } else {
  172. timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
  173. }
  174. if(opts.userLocalTime && offset === 0) {
  175. offset -= (new Date()).getTimezoneOffset();
  176. if( offset > 0 ) {
  177. timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
  178. }
  179. }
  180. if( newformat === undefined ) {
  181. return timestamp;
  182. }
  183. if( opts.masks.hasOwnProperty(newformat) ) {
  184. newformat = opts.masks[newformat];
  185. } else if ( !newformat ) {
  186. newformat = 'Y-m-d';
  187. }
  188. var
  189. G = timestamp.getHours(),
  190. i = timestamp.getMinutes(),
  191. j = timestamp.getDate(),
  192. n = timestamp.getMonth() + 1,
  193. o = timestamp.getTimezoneOffset(),
  194. s = timestamp.getSeconds(),
  195. u = timestamp.getMilliseconds(),
  196. w = timestamp.getDay(),
  197. Y = timestamp.getFullYear(),
  198. N = (w + 6) % 7 + 1,
  199. z = (new Date(Y, n - 1, j) - new Date(Y, 0, 1)) / 86400000,
  200. flags = {
  201. // Day
  202. d: pad(j),
  203. D: opts.dayNames[w],
  204. j: j,
  205. l: opts.dayNames[w + 7],
  206. N: N,
  207. S: opts.S(j),
  208. //j < 11 || j > 13 ? ['st', 'nd', 'rd', 'th'][Math.min((j - 1) % 10, 3)] : 'th',
  209. w: w,
  210. z: z,
  211. // Week
  212. W: N < 5 ? Math.floor((z + N - 1) / 7) + 1 : Math.floor((z + N - 1) / 7) || ((new Date(Y - 1, 0, 1).getDay() + 6) % 7 < 4 ? 53 : 52),
  213. // Month
  214. F: opts.monthNames[n - 1 + 12],
  215. m: pad(n),
  216. M: opts.monthNames[n - 1],
  217. n: n,
  218. t: '?',
  219. // Year
  220. L: '?',
  221. o: '?',
  222. Y: Y,
  223. y: String(Y).substring(2),
  224. // Time
  225. a: G < 12 ? opts.AmPm[0] : opts.AmPm[1],
  226. A: G < 12 ? opts.AmPm[2] : opts.AmPm[3],
  227. B: '?',
  228. g: G % 12 || 12,
  229. G: G,
  230. h: pad(G % 12 || 12),
  231. H: pad(G),
  232. i: pad(i),
  233. s: pad(s),
  234. u: u,
  235. // Timezone
  236. e: '?',
  237. I: '?',
  238. O: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
  239. P: '?',
  240. T: (String(timestamp).match(timezone) || [""]).pop().replace(timezoneClip, ""),
  241. Z: '?',
  242. // Full Date/Time
  243. c: '?',
  244. r: '?',
  245. U: Math.floor(timestamp / 1000)
  246. };
  247. return newformat.replace(token, function ($0) {
  248. return flags.hasOwnProperty($0) ? flags[$0] : $0.substring(1);
  249. });
  250. },
  251. jqID : function(sid){
  252. return String(sid).replace(/[!"#$%&'()*+,.\/:; <=>?@\[\\\]\^`{|}~]/g,"\\$&");
  253. },
  254. guid : 1,
  255. uidPref: 'jqg',
  256. randId : function( prefix ) {
  257. return (prefix || $.jgrid.uidPref) + ($.jgrid.guid++);
  258. },
  259. getAccessor : function(obj, expr) {
  260. var ret,p,prm = [], i;
  261. if( typeof expr === 'function') { return expr(obj); }
  262. ret = obj[expr];
  263. if(ret===undefined) {
  264. try {
  265. if ( typeof expr === 'string' ) {
  266. prm = expr.split('.');
  267. }
  268. i = prm.length;
  269. if( i ) {
  270. ret = obj;
  271. while (ret && i--) {
  272. p = prm.shift();
  273. ret = ret[p];
  274. }
  275. }
  276. } catch (e) {}
  277. }
  278. return ret;
  279. },
  280. getXmlData: function (obj, expr, returnObj) {
  281. var ret, m = typeof expr === 'string' ? expr.match(/^(.*)\[(\w+)\]$/) : null;
  282. if (typeof expr === 'function') { return expr(obj); }
  283. if (m && m[2]) {
  284. // m[2] is the attribute selector
  285. // m[1] is an optional element selector
  286. // examples: "[id]", "rows[page]"
  287. return m[1] ? $(m[1], obj).attr(m[2]) : $(obj).attr(m[2]);
  288. }
  289. ret = $(expr, obj);
  290. if (returnObj) { return ret; }
  291. //$(expr, obj).filter(':last'); // we use ':last' to be more compatible with old version of jqGrid
  292. return ret.length > 0 ? $(ret).text() : undefined;
  293. },
  294. cellWidth : function () {
  295. var $testDiv = $("<div class='ui-jqgrid' style='left:10000px'><table class='ui-jqgrid-btable' style='width:5px;'><tr class='jqgrow'><td style='width:5px;display:block;'></td></tr></table></div>"),
  296. testCell = $testDiv.appendTo("body")
  297. .find("td")
  298. .width();
  299. $testDiv.remove();
  300. return Math.abs(testCell-5) > 0.1;
  301. },
  302. cell_width : true,
  303. ajaxOptions: {},
  304. from : function(source){
  305. // Original Author Hugo Bonacci
  306. // License MIT http://jlinq.codeplex.com/license
  307. var QueryObject=function(d,q){
  308. if(typeof d==="string"){
  309. d=$.data(d);
  310. }
  311. var self=this,
  312. _data=d,
  313. _usecase=true,
  314. _trim=false,
  315. _query=q,
  316. _stripNum = /[\$,%]/g,
  317. _lastCommand=null,
  318. _lastField=null,
  319. _orDepth=0,
  320. _negate=false,
  321. _queuedOperator="",
  322. _sorting=[],
  323. _useProperties=true;
  324. if(typeof d==="object"&&d.push) {
  325. if(d.length>0){
  326. if(typeof d[0]!=="object"){
  327. _useProperties=false;
  328. }else{
  329. _useProperties=true;
  330. }
  331. }
  332. }else{
  333. throw "data provides is not an array";
  334. }
  335. this._hasData=function(){
  336. return _data===null?false:_data.length===0?false:true;
  337. };
  338. this._getStr=function(s){
  339. var phrase=[];
  340. if(_trim){
  341. phrase.push("jQuery.trim(");
  342. }
  343. phrase.push("String("+s+")");
  344. if(_trim){
  345. phrase.push(")");
  346. }
  347. if(!_usecase){
  348. phrase.push(".toLowerCase()");
  349. }
  350. return phrase.join("");
  351. };
  352. this._strComp=function(val){
  353. if(typeof val==="string"){
  354. return".toString()";
  355. }
  356. return"";
  357. };
  358. this._group=function(f,u){
  359. return({field:f.toString(),unique:u,items:[]});
  360. };
  361. this._toStr=function(phrase){
  362. if(_trim){
  363. phrase=$.trim(phrase);
  364. }
  365. phrase=phrase.toString().replace(/\\/g,'\\\\').replace(/\"/g,'\\"');
  366. return _usecase ? phrase : phrase.toLowerCase();
  367. };
  368. this._funcLoop=function(func){
  369. var results=[];
  370. $.each(_data,function(i,v){
  371. results.push(func(v));
  372. });
  373. return results;
  374. };
  375. this._append=function(s){
  376. var i;
  377. if(_query===null){
  378. _query="";
  379. } else {
  380. _query+=_queuedOperator === "" ? " && " :_queuedOperator;
  381. }
  382. for (i=0;i<_orDepth;i++){
  383. _query+="(";
  384. }
  385. if(_negate){
  386. _query+="!";
  387. }
  388. _query+="("+s+")";
  389. _negate=false;
  390. _queuedOperator="";
  391. _orDepth=0;
  392. };
  393. this._setCommand=function(f,c){
  394. _lastCommand=f;
  395. _lastField=c;
  396. };
  397. this._resetNegate=function(){
  398. _negate=false;
  399. };
  400. this._repeatCommand=function(f,v){
  401. if(_lastCommand===null){
  402. return self;
  403. }
  404. if(f!==null&&v!==null){
  405. return _lastCommand(f,v);
  406. }
  407. if(_lastField===null){
  408. return _lastCommand(f);
  409. }
  410. if(!_useProperties){
  411. return _lastCommand(f);
  412. }
  413. return _lastCommand(_lastField,f);
  414. };
  415. this._equals=function(a,b){
  416. return(self._compare(a,b,1)===0);
  417. };
  418. this._compare=function(a,b,d){
  419. var toString = Object.prototype.toString;
  420. if( d === undefined) { d = 1; }
  421. if(a===undefined) { a = null; }
  422. if(b===undefined) { b = null; }
  423. if(a===null && b===null){
  424. return 0;
  425. }
  426. if(a===null&&b!==null){
  427. return 1;
  428. }
  429. if(a!==null&&b===null){
  430. return -1;
  431. }
  432. if (toString.call(a) === '[object Date]' && toString.call(b) === '[object Date]') {
  433. if (a < b) { return -d; }
  434. if (a > b) { return d; }
  435. return 0;
  436. }
  437. if(!_usecase && typeof a !== "number" && typeof b !== "number" ) {
  438. a=String(a);
  439. b=String(b);
  440. }
  441. if(a<b){return -d;}
  442. if(a>b){return d;}
  443. return 0;
  444. };
  445. this._performSort=function(){
  446. if(_sorting.length===0){return;}
  447. _data=self._doSort(_data,0);
  448. };
  449. this._doSort=function(d,q){
  450. var by=_sorting[q].by,
  451. dir=_sorting[q].dir,
  452. type = _sorting[q].type,
  453. dfmt = _sorting[q].datefmt,
  454. sfunc = _sorting[q].sfunc;
  455. if(q===_sorting.length-1){
  456. return self._getOrder(d, by, dir, type, dfmt, sfunc);
  457. }
  458. q++;
  459. var values=self._getGroup(d,by,dir,type,dfmt), results=[], i, j, sorted;
  460. for(i=0;i<values.length;i++){
  461. sorted=self._doSort(values[i].items,q);
  462. for(j=0;j<sorted.length;j++){
  463. results.push(sorted[j]);
  464. }
  465. }
  466. return results;
  467. };
  468. this._getOrder=function(data,by,dir,type, dfmt, sfunc){
  469. var sortData=[],_sortData=[], newDir = dir==="a" ? 1 : -1, i,ab,j,
  470. findSortKey;
  471. if(type === undefined ) { type = "text"; }
  472. if (type === 'float' || type=== 'number' || type=== 'currency' || type=== 'numeric') {
  473. findSortKey = function($cell) {
  474. var key = parseFloat( String($cell).replace(_stripNum, ''));
  475. return isNaN(key) ? Number.NEGATIVE_INFINITY : key;
  476. };
  477. } else if (type==='int' || type==='integer') {
  478. findSortKey = function($cell) {
  479. return $cell ? parseFloat(String($cell).replace(_stripNum, '')) : Number.NEGATIVE_INFINITY;
  480. };
  481. } else if(type === 'date' || type === 'datetime') {
  482. findSortKey = function($cell) {
  483. return $.jgrid.parseDate(dfmt,$cell).getTime();
  484. };
  485. } else if($.isFunction(type)) {
  486. findSortKey = type;
  487. } else {
  488. findSortKey = function($cell) {
  489. $cell = $cell ? $.trim(String($cell)) : "";
  490. return _usecase ? $cell : $cell.toLowerCase();
  491. };
  492. }
  493. $.each(data,function(i,v){
  494. ab = by!=="" ? $.jgrid.getAccessor(v,by) : v;
  495. if(ab === undefined) { ab = ""; }
  496. ab = findSortKey(ab, v);
  497. _sortData.push({ 'vSort': ab,'index':i});
  498. });
  499. if($.isFunction(sfunc)) {
  500. _sortData.sort(function(a,b){
  501. a = a.vSort;
  502. b = b.vSort;
  503. return sfunc.call(this,a,b,newDir);
  504. });
  505. } else {
  506. _sortData.sort(function(a,b){
  507. a = a.vSort;
  508. b = b.vSort;
  509. return self._compare(a,b,newDir);
  510. });
  511. }
  512. j=0;
  513. var nrec= data.length;
  514. // overhead, but we do not change the original data.
  515. while(j<nrec) {
  516. i = _sortData[j].index;
  517. sortData.push(data[i]);
  518. j++;
  519. }
  520. return sortData;
  521. };
  522. this._getGroup=function(data,by,dir,type, dfmt){
  523. var results=[],
  524. group=null,
  525. last=null, val;
  526. $.each(self._getOrder(data,by,dir,type, dfmt),function(i,v){
  527. val = $.jgrid.getAccessor(v, by);
  528. if(val == null) { val = ""; }
  529. if(!self._equals(last,val)){
  530. last=val;
  531. if(group !== null){
  532. results.push(group);
  533. }
  534. group=self._group(by,val);
  535. }
  536. group.items.push(v);
  537. });
  538. if(group !== null){
  539. results.push(group);
  540. }
  541. return results;
  542. };
  543. this.ignoreCase=function(){
  544. _usecase=false;
  545. return self;
  546. };
  547. this.useCase=function(){
  548. _usecase=true;
  549. return self;
  550. };
  551. this.trim=function(){
  552. _trim=true;
  553. return self;
  554. };
  555. this.noTrim=function(){
  556. _trim=false;
  557. return self;
  558. };
  559. this.execute=function(){
  560. var match=_query, results=[];
  561. if(match === null){
  562. return self;
  563. }
  564. $.each(_data,function(){
  565. if(eval(match)){results.push(this);}
  566. });
  567. _data=results;
  568. return self;
  569. };
  570. this.data=function(){
  571. return _data;
  572. };
  573. this.select=function(f){
  574. self._performSort();
  575. if(!self._hasData()){ return[]; }
  576. self.execute();
  577. if($.isFunction(f)){
  578. var results=[];
  579. $.each(_data,function(i,v){
  580. results.push(f(v));
  581. });
  582. return results;
  583. }
  584. return _data;
  585. };
  586. this.hasMatch=function(){
  587. if(!self._hasData()) { return false; }
  588. self.execute();
  589. return _data.length>0;
  590. };
  591. this.andNot=function(f,v,x){
  592. _negate=!_negate;
  593. return self.and(f,v,x);
  594. };
  595. this.orNot=function(f,v,x){
  596. _negate=!_negate;
  597. return self.or(f,v,x);
  598. };
  599. this.not=function(f,v,x){
  600. return self.andNot(f,v,x);
  601. };
  602. this.and=function(f,v,x){
  603. _queuedOperator=" && ";
  604. if(f===undefined){
  605. return self;
  606. }
  607. return self._repeatCommand(f,v,x);
  608. };
  609. this.or=function(f,v,x){
  610. _queuedOperator=" || ";
  611. if(f===undefined) { return self; }
  612. return self._repeatCommand(f,v,x);
  613. };
  614. this.orBegin=function(){
  615. _orDepth++;
  616. return self;
  617. };
  618. this.orEnd=function(){
  619. if (_query !== null){
  620. _query+=")";
  621. }
  622. return self;
  623. };
  624. this.isNot=function(f){
  625. _negate=!_negate;
  626. return self.is(f);
  627. };
  628. this.is=function(f){
  629. self._append('this.'+f);
  630. self._resetNegate();
  631. return self;
  632. };
  633. this._compareValues=function(func,f,v,how,t){
  634. var fld;
  635. if(_useProperties){
  636. fld='jQuery.jgrid.getAccessor(this,\''+f+'\')';
  637. }else{
  638. fld='this';
  639. }
  640. if(v===undefined) { v = null; }
  641. //var val=v===null?f:v,
  642. var val =v,
  643. swst = t.stype === undefined ? "text" : t.stype;
  644. if(v !== null) {
  645. switch(swst) {
  646. case 'int':
  647. case 'integer':
  648. val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
  649. fld = 'parseInt('+fld+',10)';
  650. val = 'parseInt('+val+',10)';
  651. break;
  652. case 'float':
  653. case 'number':
  654. case 'numeric':
  655. val = String(val).replace(_stripNum, '');
  656. val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
  657. fld = 'parseFloat('+fld+')';
  658. val = 'parseFloat('+val+')';
  659. break;
  660. case 'date':
  661. case 'datetime':
  662. val = String($.jgrid.parseDate(t.newfmt || 'Y-m-d',val).getTime());
  663. fld = 'jQuery.jgrid.parseDate("'+t.srcfmt+'",'+fld+').getTime()';
  664. break;
  665. default :
  666. fld=self._getStr(fld);
  667. val=self._getStr('"'+self._toStr(val)+'"');
  668. }
  669. }
  670. self._append(fld+' '+how+' '+val);
  671. self._setCommand(func,f);
  672. self._resetNegate();
  673. return self;
  674. };
  675. this.equals=function(f,v,t){
  676. return self._compareValues(self.equals,f,v,"==",t);
  677. };
  678. this.notEquals=function(f,v,t){
  679. return self._compareValues(self.equals,f,v,"!==",t);
  680. };
  681. this.isNull = function(f,v,t){
  682. return self._compareValues(self.equals,f,null,"===",t);
  683. };
  684. this.greater=function(f,v,t){
  685. return self._compareValues(self.greater,f,v,">",t);
  686. };
  687. this.less=function(f,v,t){
  688. return self._compareValues(self.less,f,v,"<",t);
  689. };
  690. this.greaterOrEquals=function(f,v,t){
  691. return self._compareValues(self.greaterOrEquals,f,v,">=",t);
  692. };
  693. this.lessOrEquals=function(f,v,t){
  694. return self._compareValues(self.lessOrEquals,f,v,"<=",t);
  695. };
  696. this.startsWith=function(f,v){
  697. var val = (v==null) ? f: v,
  698. length=_trim ? $.trim(val.toString()).length : val.toString().length;
  699. if(_useProperties){
  700. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(v)+'"'));
  701. }else{
  702. if (v!=null) { length=_trim?$.trim(v.toString()).length:v.toString().length; }
  703. self._append(self._getStr('this')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(f)+'"'));
  704. }
  705. self._setCommand(self.startsWith,f);
  706. self._resetNegate();
  707. return self;
  708. };
  709. this.endsWith=function(f,v){
  710. var val = (v==null) ? f: v,
  711. length=_trim ? $.trim(val.toString()).length:val.toString().length;
  712. if(_useProperties){
  713. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr('+self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.length-'+length+','+length+') == "'+self._toStr(v)+'"');
  714. } else {
  715. self._append(self._getStr('this')+'.substr('+self._getStr('this')+'.length-"'+self._toStr(f)+'".length,"'+self._toStr(f)+'".length) == "'+self._toStr(f)+'"');
  716. }
  717. self._setCommand(self.endsWith,f);self._resetNegate();
  718. return self;
  719. };
  720. this.contains=function(f,v){
  721. if(_useProperties){
  722. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.indexOf("'+self._toStr(v)+'",0) > -1');
  723. }else{
  724. self._append(self._getStr('this')+'.indexOf("'+self._toStr(f)+'",0) > -1');
  725. }
  726. self._setCommand(self.contains,f);
  727. self._resetNegate();
  728. return self;
  729. };
  730. this.groupBy=function(by,dir,type, datefmt){
  731. if(!self._hasData()){
  732. return null;
  733. }
  734. return self._getGroup(_data,by,dir,type, datefmt);
  735. };
  736. this.orderBy=function(by,dir,stype, dfmt, sfunc){
  737. dir = dir == null ? "a" :$.trim(dir.toString().toLowerCase());
  738. if(stype == null) { stype = "text"; }
  739. if(dfmt == null) { dfmt = "Y-m-d"; }
  740. if(sfunc == null) { sfunc = false; }
  741. if(dir==="desc"||dir==="descending"){dir="d";}
  742. if(dir==="asc"||dir==="ascending"){dir="a";}
  743. _sorting.push({by:by,dir:dir,type:stype, datefmt: dfmt, sfunc: sfunc});
  744. return self;
  745. };
  746. return self;
  747. };
  748. return new QueryObject(source,null);
  749. },
  750. getMethod: function (name) {
  751. return this.getAccessor($.fn.jqGrid, name);
  752. },
  753. extend : function(methods) {
  754. $.extend($.fn.jqGrid,methods);
  755. if (!this.no_legacy_api) {
  756. $.fn.extend(methods);
  757. }
  758. }
  759. });
  760. $.fn.jqGrid = function( pin ) {
  761. if (typeof pin === 'string') {
  762. var fn = $.jgrid.getMethod(pin);
  763. if (!fn) {
  764. throw ("jqGrid - No such method: " + pin);
  765. }
  766. var args = $.makeArray(arguments).slice(1);
  767. return fn.apply(this,args);
  768. }
  769. return this.each( function() {
  770. if(this.grid) {return;}
  771. var localData;
  772. if (pin != null && pin.data !== undefined) {
  773. localData = pin.data;
  774. pin.data = [];
  775. }
  776. var p = $.extend(true,{
  777. url: "",
  778. height: 150,
  779. page: 1,
  780. rowNum: 20,
  781. rowTotal : null,
  782. records: 0,
  783. pager: "",
  784. pgbuttons: true,
  785. pginput: true,
  786. colModel: [],
  787. rowList: [],
  788. colNames: [],
  789. sortorder: "asc",
  790. sortname: "",
  791. datatype: "xml",
  792. mtype: "GET",
  793. altRows: false,
  794. selarrrow: [],
  795. savedRow: [],
  796. shrinkToFit: true,
  797. xmlReader: {},
  798. jsonReader: {},
  799. subGrid: false,
  800. subGridModel :[],
  801. reccount: 0,
  802. lastpage: 0,
  803. lastsort: 0,
  804. selrow: null,
  805. beforeSelectRow: null,
  806. onSelectRow: null,
  807. onSortCol: null,
  808. ondblClickRow: null,
  809. onRightClickRow: null,
  810. onPaging: null,
  811. onSelectAll: null,
  812. onInitGrid : null,
  813. loadComplete: null,
  814. gridComplete: null,
  815. loadError: null,
  816. loadBeforeSend: null,
  817. afterInsertRow: null,
  818. beforeRequest: null,
  819. beforeProcessing : null,
  820. onHeaderClick: null,
  821. viewrecords: false,
  822. loadonce: false,
  823. multiselect: false,
  824. multikey: false,
  825. editurl: null,
  826. search: false,
  827. caption: "",
  828. hidegrid: true,
  829. hiddengrid: false,
  830. postData: {},
  831. userData: {},
  832. treeGrid : false,
  833. treeGridModel : 'nested',
  834. treeReader : {},
  835. treeANode : -1,
  836. ExpandColumn: null,
  837. tree_root_level : 0,
  838. prmNames: {page:"page",rows:"rows", sort: "sidx",order: "sord", search:"_search", nd:"nd", id:"id",oper:"oper",editoper:"edit",addoper:"add",deloper:"del", subgridid:"id", npage: null, totalrows:"totalrows"},
  839. forceFit : false,
  840. gridstate : "visible",
  841. cellEdit: false,
  842. cellsubmit: "remote",
  843. nv:0,
  844. loadui: "enable",
  845. toolbar: [false,""],
  846. scroll: false,
  847. multiboxonly : false,
  848. deselectAfterSort : true,
  849. scrollrows : false,
  850. autowidth: false,
  851. scrollOffset :18,
  852. cellLayout: 5,
  853. subGridWidth: 20,
  854. multiselectWidth: 20,
  855. gridview: false,
  856. rownumWidth: 25,
  857. rownumbers : false,
  858. pagerpos: 'center',
  859. recordpos: 'right',
  860. footerrow : false,
  861. userDataOnFooter : false,
  862. hoverrows : true,
  863. altclass : 'ui-priority-secondary',
  864. viewsortcols : [false,'vertical',true],
  865. resizeclass : '',
  866. autoencode : false,
  867. remapColumns : [],
  868. ajaxGridOptions :{},
  869. direction : "ltr",
  870. toppager: false,
  871. headertitles: false,
  872. scrollTimeout: 40,
  873. data : [],
  874. _index : {},
  875. grouping : false,
  876. groupingView : {groupField:[],groupOrder:[], groupText:[],groupColumnShow:[],groupSummary:[], showSummaryOnHide: false, sortitems:[], sortnames:[], summary:[],summaryval:[], plusicon: 'ui-icon-circlesmall-plus', minusicon: 'ui-icon-circlesmall-minus', displayField: [], groupSummaryPos:[], formatDisplayField : [], _locgr : false},
  877. ignoreCase : false,
  878. cmTemplate : {},
  879. idPrefix : "",
  880. multiSort : false,
  881. minColWidth : 33
  882. }, $.jgrid.defaults, pin || {});
  883. if (localData !== undefined) {
  884. p.data = localData;
  885. pin.data = localData;
  886. }
  887. var ts= this, grid={
  888. headers:[],
  889. cols:[],
  890. footers: [],
  891. dragStart: function(i,x,y) {
  892. var gridLeftPos = $(this.bDiv).offset().left;
  893. this.resizing = { idx: i, startX: x.pageX, sOL : x.pageX - gridLeftPos };
  894. this.hDiv.style.cursor = "col-resize";
  895. this.curGbox = $("#rs_m"+$.jgrid.jqID(p.id),"#gbox_"+$.jgrid.jqID(p.id));
  896. this.curGbox.css({display:"block",left:x.pageX-gridLeftPos,top:y[1],height:y[2]});
  897. $(ts).triggerHandler("jqGridResizeStart", [x, i]);
  898. if($.isFunction(p.resizeStart)) { p.resizeStart.call(ts,x,i); }
  899. document.onselectstart=function(){return false;};
  900. },
  901. dragMove: function(x) {
  902. if(this.resizing) {
  903. var diff = x.pageX-this.resizing.startX,
  904. h = this.headers[this.resizing.idx],
  905. newWidth = p.direction === "ltr" ? h.width + diff : h.width - diff, hn, nWn;
  906. if(newWidth > 33) {
  907. this.curGbox.css({left:this.resizing.sOL+diff});
  908. if(p.forceFit===true ){
  909. hn = this.headers[this.resizing.idx+p.nv];
  910. nWn = p.direction === "ltr" ? hn.width - diff : hn.width + diff;
  911. if(nWn > p.minColWidth ) {
  912. h.newWidth = newWidth;
  913. hn.newWidth = nWn;
  914. }
  915. } else {
  916. this.newWidth = p.direction === "ltr" ? p.tblwidth+diff : p.tblwidth-diff;
  917. h.newWidth = newWidth;
  918. }
  919. }
  920. }
  921. },
  922. dragEnd: function() {
  923. this.hDiv.style.cursor = "default";
  924. if(this.resizing) {
  925. var idx = this.resizing.idx,
  926. nw = this.headers[idx].newWidth || this.headers[idx].width;
  927. nw = parseInt(nw,10);
  928. this.resizing = false;
  929. $("#rs_m"+$.jgrid.jqID(p.id)).css("display","none");
  930. p.colModel[idx].width = nw;
  931. this.headers[idx].width = nw;
  932. this.headers[idx].el.style.width = nw + "px";
  933. this.cols[idx].style.width = nw+"px";
  934. if(this.footers.length>0) {this.footers[idx].style.width = nw+"px";}
  935. if(p.forceFit===true){
  936. nw = this.headers[idx+p.nv].newWidth || this.headers[idx+p.nv].width;
  937. this.headers[idx+p.nv].width = nw;
  938. this.headers[idx+p.nv].el.style.width = nw + "px";
  939. this.cols[idx+p.nv].style.width = nw+"px";
  940. if(this.footers.length>0) {this.footers[idx+p.nv].style.width = nw+"px";}
  941. p.colModel[idx+p.nv].width = nw;
  942. } else {
  943. p.tblwidth = this.newWidth || p.tblwidth;
  944. $('table:first',this.bDiv).css("width",p.tblwidth+"px");
  945. $('table:first',this.hDiv).css("width",p.tblwidth+"px");
  946. this.hDiv.scrollLeft = this.bDiv.scrollLeft;
  947. if(p.footerrow) {
  948. $('table:first',this.sDiv).css("width",p.tblwidth+"px");
  949. this.sDiv.scrollLeft = this.bDiv.scrollLeft;
  950. }
  951. }
  952. $(ts).triggerHandler("jqGridResizeStop", [nw, idx]);
  953. if($.isFunction(p.resizeStop)) { p.resizeStop.call(ts,nw,idx); }
  954. }
  955. this.curGbox = null;
  956. document.onselectstart=function(){return true;};
  957. },
  958. populateVisible: function() {
  959. if (grid.timer) { clearTimeout(grid.timer); }
  960. grid.timer = null;
  961. var dh = $(grid.bDiv).height();
  962. if (!dh) { return; }
  963. var table = $("table:first", grid.bDiv);
  964. var rows, rh;
  965. if(table[0].rows.length) {
  966. try {
  967. rows = table[0].rows[1];
  968. rh = rows ? $(rows).outerHeight() || grid.prevRowHeight : grid.prevRowHeight;
  969. } catch (pv) {
  970. rh = grid.prevRowHeight;
  971. }
  972. }
  973. if (!rh) { return; }
  974. grid.prevRowHeight = rh;
  975. var rn = p.rowNum;
  976. var scrollTop = grid.scrollTop = grid.bDiv.scrollTop;
  977. var ttop = Math.round(table.position().top) - scrollTop;
  978. var tbot = ttop + table.height();
  979. var div = rh * rn;
  980. var page, npage, empty;
  981. if ( tbot < dh && ttop <= 0 &&
  982. (p.lastpage===undefined||(parseInt((tbot + scrollTop + div - 1) / div,10) || 0) <= p.lastpage))
  983. {
  984. npage = parseInt((dh - tbot + div - 1) / div,10) || 1;
  985. if (tbot >= 0 || npage < 2 || p.scroll === true) {
  986. page = ( Math.round((tbot + scrollTop) / div) || 0) + 1;
  987. ttop = -1;
  988. } else {
  989. ttop = 1;
  990. }
  991. }
  992. if (ttop > 0) {
  993. page = ( parseInt(scrollTop / div,10) || 0 ) + 1;
  994. npage = (parseInt((scrollTop + dh) / div,10) || 0) + 2 - page;
  995. empty = true;
  996. }
  997. if (npage) {
  998. if (p.lastpage && (page > p.lastpage || p.lastpage===1 || (page === p.page && page===p.lastpage)) ) {
  999. return;
  1000. }
  1001. if (grid.hDiv.loading) {
  1002. grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
  1003. } else {
  1004. p.page = page;
  1005. if (empty) {
  1006. grid.selectionPreserver(table[0]);
  1007. grid.emptyRows.call(table[0], false, false);
  1008. }
  1009. grid.populate(npage);
  1010. }
  1011. }
  1012. },
  1013. scrollGrid: function( e ) {
  1014. if(p.scroll) {
  1015. var scrollTop = grid.bDiv.scrollTop;
  1016. if(grid.scrollTop === undefined) { grid.scrollTop = 0; }
  1017. if (scrollTop !== grid.scrollTop) {
  1018. grid.scrollTop = scrollTop;
  1019. if (grid.timer) { clearTimeout(grid.timer); }
  1020. grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
  1021. }
  1022. }
  1023. grid.hDiv.scrollLeft = grid.bDiv.scrollLeft;
  1024. if(p.footerrow) {
  1025. grid.sDiv.scrollLeft = grid.bDiv.scrollLeft;
  1026. }
  1027. if( e ) { e.stopPropagation(); }
  1028. },
  1029. selectionPreserver : function(ts) {
  1030. var p = ts.p,
  1031. sr = p.selrow, sra = p.selarrrow ? $.makeArray(p.selarrrow) : null,
  1032. left = ts.grid.bDiv.scrollLeft,
  1033. restoreSelection = function() {
  1034. var i;
  1035. p.selrow = null;
  1036. p.selarrrow = [];
  1037. if(p.multiselect && sra && sra.length>0) {
  1038. for(i=0;i<sra.length;i++){
  1039. if (sra[i] !== sr) {
  1040. $(ts).jqGrid("setSelection",sra[i],false, null);
  1041. }
  1042. }
  1043. }
  1044. if (sr) {
  1045. $(ts).jqGrid("setSelection",sr,false,null);
  1046. }
  1047. ts.grid.bDiv.scrollLeft = left;
  1048. $(ts).unbind('.selectionPreserver', restoreSelection);
  1049. };
  1050. $(ts).bind('jqGridGridComplete.selectionPreserver', restoreSelection);
  1051. }
  1052. };
  1053. if(this.tagName.toUpperCase() !== 'TABLE' || this.id == null) {
  1054. alert("Element is not a table or has no id!");
  1055. return;
  1056. }
  1057. if(document.documentMode !== undefined ) { // IE only
  1058. if(document.documentMode <= 5) {
  1059. alert("Grid can not be used in this ('quirks') mode!");
  1060. return;
  1061. }
  1062. }
  1063. $(this).empty().attr("tabindex","0");
  1064. this.p = p ;
  1065. this.p.useProp = !!$.fn.prop;
  1066. var i, dir;
  1067. if(this.p.colNames.length === 0) {
  1068. for (i=0;i<this.p.colModel.length;i++){
  1069. this.p.colNames[i] = this.p.colModel[i].label || this.p.colModel[i].name;
  1070. }
  1071. }
  1072. if( this.p.colNames.length !== this.p.colModel.length ) {
  1073. alert($.jgrid.errors.model);
  1074. return;
  1075. }
  1076. var gv = $("<div class='ui-jqgrid-view' role='grid'></div>"),
  1077. isMSIE = $.jgrid.msie;
  1078. ts.p.direction = $.trim(ts.p.direction.toLowerCase());
  1079. if($.inArray(ts.p.direction,["ltr","rtl"]) === -1) { ts.p.direction = "ltr"; }
  1080. dir = ts.p.direction;
  1081. $(gv).insertBefore(this);
  1082. $(this).removeClass("scroll").appendTo(gv);
  1083. var eg = $("<div class='ui-jqgrid ui-widget ui-widget-content ui-corner-all'></div>");
  1084. $(eg).attr({"id" : "gbox_"+this.id,"dir":dir}).insertBefore(gv);
  1085. $(gv).attr("id","gview_"+this.id).appendTo(eg);
  1086. $("<div class='ui-widget-overlay jqgrid-overlay' id='lui_"+this.id+"'></div>").insertBefore(gv);
  1087. $("<div class='loading ui-state-default ui-state-active' id='load_"+this.id+"'>"+this.p.loadtext+"</div>").insertBefore(gv);
  1088. $(this).attr({cellspacing:"0",cellpadding:"0",border:"0","role":"presentation","aria-multiselectable":!!this.p.multiselect,"aria-labelledby":"gbox_"+this.id});
  1089. var sortkeys = ["shiftKey","altKey","ctrlKey"],
  1090. intNum = function(val,defval) {
  1091. val = parseInt(val,10);
  1092. if (isNaN(val)) { return defval || 0;}
  1093. return val;
  1094. },
  1095. formatCol = function (pos, rowInd, tv, rawObject, rowId, rdata){
  1096. var cm = ts.p.colModel[pos], cellAttrFunc,
  1097. ral = cm.align, result="style=\"", clas = cm.classes, nm = cm.name, celp, acp=[];
  1098. if(ral) { result += "text-align:"+ral+";"; }
  1099. if(cm.hidden===true) { result += "display:none;"; }
  1100. if(rowInd===0) {
  1101. result += "width: "+grid.headers[pos].width+"px;";
  1102. } else if ($.isFunction(cm.cellattr) || (typeof cm.cellattr === "string" && $.jgrid.cellattr != null && $.isFunction($.jgrid.cellattr[cm.cellattr]))) {
  1103. cellAttrFunc = $.isFunction(cm.cellattr) ? cm.cellattr : $.jgrid.cellattr[cm.cellattr];
  1104. celp = cellAttrFunc.call(ts, rowId, tv, rawObject, cm, rdata);
  1105. if(celp && typeof celp === "string") {
  1106. celp = celp.replace(/style/i,'style').replace(/title/i,'title');
  1107. if(celp.indexOf('title') > -1) { cm.title=false;}
  1108. if(celp.indexOf('class') > -1) { clas = undefined;}
  1109. acp = celp.replace(/\-style/g,'-sti').split(/style/);
  1110. if(acp.length === 2 ) {
  1111. acp[1] = $.trim(acp[1].replace(/\-sti/g,'-style').replace("=",""));
  1112. if(acp[1].indexOf("'") === 0 || acp[1].indexOf('"') === 0) {
  1113. acp[1] = acp[1].substring(1);
  1114. }
  1115. result += acp[1].replace(/'/gi,'"');
  1116. } else {
  1117. result += "\"";
  1118. }
  1119. }
  1120. }
  1121. if(!acp.length) { acp[0] = ""; result += "\"";}
  1122. result += (clas !== undefined ? (" class=\""+clas+"\"") :"") + ((cm.title && tv) ? (" title=\""+$.jgrid.stripHtml(tv)+"\"") :"");
  1123. result += " aria-describedby=\""+ts.p.id+"_"+nm+"\"";
  1124. return result + acp[0];
  1125. },
  1126. cellVal = function (val) {
  1127. return val == null || val === "" ? "&#160;" : (ts.p.autoencode ? $.jgrid.htmlEncode(val) : String(val));
  1128. },
  1129. formatter = function (rowId, cellval , colpos, rwdat, _act){
  1130. var cm = ts.p.colModel[colpos],v;
  1131. if(cm.formatter !== undefined) {
  1132. rowId = String(ts.p.idPrefix) !== "" ? $.jgrid.stripPref(ts.p.idPrefix, rowId) : rowId;
  1133. var opts= {rowId: rowId, colModel:cm, gid:ts.p.id, pos:colpos };
  1134. if($.isFunction( cm.formatter ) ) {
  1135. v = cm.formatter.call(ts,cellval,opts,rwdat,_act);
  1136. } else if($.fmatter){
  1137. v = $.fn.fmatter.call(ts,cm.formatter,cellval,opts,rwdat,_act);
  1138. } else {
  1139. v = cellVal(cellval);
  1140. }
  1141. } else {
  1142. v = cellVal(cellval);
  1143. }
  1144. return v;
  1145. },
  1146. addCell = function(rowId,cell,pos,irow, srvr, rdata) {
  1147. var v,prp;
  1148. v = formatter(rowId,cell,pos,srvr,'add');
  1149. prp = formatCol( pos,irow, v, srvr, rowId, rdata);
  1150. return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  1151. },
  1152. addMulti = function(rowid,pos,irow,checked){
  1153. var v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+ts.p.id+"_"+rowid+"\" class=\"cbox\" name=\"jqg_"+ts.p.id+"_"+rowid+"\"" + (checked ? "checked=\"checked\"" : "")+"/>",
  1154. prp = formatCol( pos,irow,'',null, rowid, true);
  1155. return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  1156. },
  1157. addRowNum = function (pos,irow,pG,rN) {
  1158. var v = (parseInt(pG,10)-1)*parseInt(rN,10)+1+irow,
  1159. prp = formatCol( pos,irow,v, null, irow, true);
  1160. return "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" "+prp+">"+v+"</td>";
  1161. },
  1162. reader = function (datatype) {
  1163. var field, f=[], j=0, i;
  1164. for(i =0; i<ts.p.colModel.length; i++){
  1165. field = ts.p.colModel[i];
  1166. if (field.name !== 'cb' && field.name !=='subgrid' && field.name !=='rn') {
  1167. f[j]= datatype === "local" ?
  1168. field.name :
  1169. ( (datatype==="xml" || datatype === "xmlstring") ? field.xmlmap || field.name : field.jsonmap || field.name );
  1170. if(ts.p.keyName !== false && field.key===true ) {
  1171. ts.p.keyName = f[j];
  1172. }
  1173. j++;
  1174. }
  1175. }
  1176. return f;
  1177. },
  1178. orderedCols = function (offset) {
  1179. var order = ts.p.remapColumns;
  1180. if (!order || !order.length) {
  1181. order = $.map(ts.p.colModel, function(v,i) { return i; });
  1182. }
  1183. if (offset) {
  1184. order = $.map(order, function(v) { return v<offset?null:v-offset; });
  1185. }
  1186. return order;
  1187. },
  1188. emptyRows = function (scroll, locdata) {
  1189. var firstrow;
  1190. if (this.p.deepempty) {
  1191. $(this.rows).slice(1).remove();
  1192. } else {
  1193. firstrow = this.rows.length > 0 ? this.rows[0] : null;
  1194. $(this.firstChild).empty().append(firstrow);
  1195. }
  1196. if (scroll && this.p.scroll) {
  1197. $(this.grid.bDiv.firstChild).css({height: "auto"});
  1198. $(this.grid.bDiv.firstChild.firstChild).css({height: 0, display: "none"});
  1199. if (this.grid.bDiv.scrollTop !== 0) {
  1200. this.grid.bDiv.scrollTop = 0;
  1201. }
  1202. }
  1203. if(locdata === true && this.p.treeGrid) {
  1204. this.p.data = []; this.p._index = {};
  1205. }
  1206. },
  1207. normalizeData = function() {
  1208. var p = ts.p, data = p.data, dataLength = data.length, i, j, cur, idn, idr, ccur, v, rd,
  1209. localReader = p.localReader,
  1210. colModel = p.colModel,
  1211. cellName = localReader.cell,
  1212. iOffset = (p.multiselect === true ? 1 : 0) + (p.subGrid === true ? 1 : 0) + (p.rownumbers === true ? 1 : 0),
  1213. br = p.scroll ? $.jgrid.randId() : 1,
  1214. arrayReader, objectReader, rowReader;
  1215. if (p.datatype !== "local" || localReader.repeatitems !== true) {
  1216. return; // nothing to do
  1217. }
  1218. arrayReader = orderedCols(iOffset);
  1219. objectReader = reader("local");
  1220. // read ALL input items and convert items to be read by
  1221. // $.jgrid.getAccessor with column name as the second parameter
  1222. idn = p.keyIndex === false ?
  1223. ($.isFunction(localReader.id) ? localReader.id.call(ts, data) : localReader.id) :
  1224. p.keyIndex;
  1225. for (i = 0; i < dataLength; i++) {
  1226. cur = data[i];
  1227. // read id in the same way like addJSONData do
  1228. // probably it would be better to start with "if (cellName) {...}"
  1229. // but the goal of the current implementation was just have THE SAME
  1230. // id values like in addJSONData ...
  1231. idr = $.jgrid.getAccessor(cur, idn);
  1232. if (idr === undefined) {
  1233. if (typeof idn === "number" && colModel[idn + iOffset] != null) {
  1234. // reread id by name
  1235. idr = $.jgrid.getAccessor(cur, colModel[idn + iOffset].name);
  1236. }
  1237. if (idr === undefined) {
  1238. idr = br + i;
  1239. if (cellName) {
  1240. ccur = $.jgrid.getAccessor(cur, cellName) || cur;
  1241. idr = ccur != null && ccur[idn] !== undefined ? ccur[idn] : idr;
  1242. ccur = null;
  1243. }
  1244. }
  1245. }
  1246. rd = { };
  1247. rd[localReader.id] = idr;
  1248. if (cellName) {
  1249. cur = $.jgrid.getAccessor(cur, cellName) || cur;
  1250. }
  1251. rowReader = $.isArray(cur) ? arrayReader : objectReader;
  1252. for (j = 0; j < rowReader.length; j++) {
  1253. v = $.jgrid.getAccessor(cur, rowReader[j]);
  1254. rd[colModel[j + iOffset].name] = v;
  1255. }
  1256. $.extend(true, data[i], rd);
  1257. }
  1258. },
  1259. refreshIndex = function() {
  1260. var datalen = ts.p.data.length, idname, i, val;
  1261. if(ts.p.keyName === false || ts.p.loadonce === true) {
  1262. idname = ts.p.localReader.id;
  1263. } else {
  1264. idname = ts.p.keyName;
  1265. }
  1266. ts.p._index = [];
  1267. for(i =0;i < datalen; i++) {
  1268. val = $.jgrid.getAccessor(ts.p.data[i],idname);
  1269. if (val === undefined) { val=String(i+1); }
  1270. ts.p._index[val] = i;
  1271. }
  1272. },
  1273. constructTr = function(id, hide, altClass, rd, cur, selected) {
  1274. var tabindex = '-1', restAttr = '', attrName, style = hide ? 'display:none;' : '',
  1275. classes = 'ui-widget-content jqgrow ui-row-' + ts.p.direction + (altClass ? ' ' + altClass : '') + (selected ? ' ui-state-highlight' : ''),
  1276. rowAttrObj = $(ts).triggerHandler("jqGridRowAttr", [rd, cur, id]);
  1277. if( typeof rowAttrObj !== "object" ) {
  1278. rowAttrObj = $.isFunction(ts.p.rowattr) ? ts.p.rowattr.call(ts, rd, cur, id) :
  1279. (typeof ts.p.rowattr === "string" && $.jgrid.rowattr != null && $.isFunction($.jgrid.rowattr[ts.p.rowattr]) ?
  1280. $.jgrid.rowattr[ts.p.rowattr].call(ts, rd, cur, id) : {});
  1281. }
  1282. if(!$.isEmptyObject( rowAttrObj )) {
  1283. if (rowAttrObj.hasOwnProperty("id")) {
  1284. id = rowAttrObj.id;
  1285. delete rowAttrObj.id;
  1286. }
  1287. if (rowAttrObj.hasOwnProperty("tabindex")) {
  1288. tabindex = rowAttrObj.tabindex;
  1289. delete rowAttrObj.tabindex;
  1290. }
  1291. if (rowAttrObj.hasOwnProperty("style")) {
  1292. style += rowAttrObj.style;
  1293. delete rowAttrObj.style;
  1294. }
  1295. if (rowAttrObj.hasOwnProperty("class")) {
  1296. classes += ' ' + rowAttrObj['class'];
  1297. delete rowAttrObj['class'];
  1298. }
  1299. // dot't allow to change role attribute
  1300. try { delete rowAttrObj.role; } catch(ra){}
  1301. for (attrName in rowAttrObj) {
  1302. if (rowAttrObj.hasOwnProperty(attrName)) {
  1303. restAttr += ' ' + attrName + '=' + rowAttrObj[attrName];
  1304. }
  1305. }
  1306. }
  1307. return '<tr role="row" id="' + id + '" tabindex="' + tabindex + '" class="' + classes + '"' +
  1308. (style === '' ? '' : ' style="' + style + '"') + restAttr + '>';
  1309. },
  1310. addXmlData = function (xml,t, rcnt, more, adjust) {
  1311. var startReq = new Date(),
  1312. locdata = (ts.p.datatype !== "local" && ts.p.loadonce) || ts.p.datatype === "xmlstring",
  1313. xmlid = "_id_", xmlRd = ts.p.xmlReader,
  1314. frd = ts.p.datatype === "local" ? "local" : "xml";
  1315. if(locdata) {
  1316. ts.p.data = [];
  1317. ts.p._index = {};
  1318. ts.p.localReader.id = xmlid;
  1319. }
  1320. ts.p.reccount = 0;
  1321. if($.isXMLDoc(xml)) {
  1322. if(ts.p.treeANode===-1 && !ts.p.scroll) {
  1323. emptyRows.call(ts, false, true);
  1324. rcnt=1;
  1325. } else { rcnt = rcnt > 1 ? rcnt :1; }
  1326. } else { return; }
  1327. var self= $(ts), i,fpos,ir=0,v,gi=ts.p.multiselect===true?1:0,si=0,addSubGridCell,ni=ts.p.rownumbers===true?1:0,idn, getId,f=[],F,rd ={}, xmlr,rid, rowData=[], cn=(ts.p.altRows === true) ? ts.p.altclass:"",cn1;
  1328. if(ts.p.subGrid===true) {
  1329. si = 1;
  1330. addSubGridCell = $.jgrid.getMethod("addSubGridCell");
  1331. }
  1332. if(!xmlRd.repeatitems) {f = reader(frd);}
  1333. if( ts.p.keyName===false) {
  1334. idn = $.isFunction( xmlRd.id ) ? xmlRd.id.call(ts, xml) : xmlRd.id;
  1335. } else {
  1336. idn = ts.p.keyName;
  1337. }
  1338. if( String(idn).indexOf("[") === -1 ) {
  1339. if (f.length) {
  1340. getId = function( trow, k) {return $(idn,trow).text() || k;};
  1341. } else {
  1342. getId = function( trow, k) {return $(xmlRd.cell,trow).eq(idn).text() || k;};
  1343. }
  1344. }
  1345. else {
  1346. getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;};
  1347. }
  1348. ts.p.userData = {};
  1349. ts.p.page = intNum($.jgrid.getXmlData(xml, xmlRd.page), ts.p.page);
  1350. ts.p.lastpage = intNum($.jgrid.getXmlData(xml, xmlRd.total), 1);
  1351. ts.p.records = intNum($.jgrid.getXmlData(xml, xmlRd.records));
  1352. if($.isFunction(xmlRd.userdata)) {
  1353. ts.p.userData = xmlRd.userdata.call(ts, xml) || {};
  1354. } else {
  1355. $.jgrid.getXmlData(xml, xmlRd.userdata, true).each(function() {ts.p.userData[this.getAttribute("name")]= $(this).text();});
  1356. }
  1357. var gxml = $.jgrid.getXmlData( xml, xmlRd.root, true);
  1358. gxml = $.jgrid.getXmlData( gxml, xmlRd.row, true);
  1359. if (!gxml) { gxml = []; }
  1360. var gl = gxml.length, j=0, grpdata=[], rn = parseInt(ts.p.rowNum,10), br=ts.p.scroll?$.jgrid.randId():1, altr;
  1361. if (gl > 0 && ts.p.page <= 0) { ts.p.page = 1; }
  1362. if(gxml && gl){
  1363. if (adjust) { rn *= adjust+1; }
  1364. var afterInsRow = $.isFunction(ts.p.afterInsertRow), hiderow=false, groupingPrepare;
  1365. if(ts.p.grouping) {
  1366. hiderow = ts.p.groupingView.groupCollapse === true;
  1367. groupingPrepare = $.jgrid.getMethod("groupingPrepare");
  1368. }
  1369. while (j<gl) {
  1370. xmlr = gxml[j];
  1371. rid = getId(xmlr,br+j);
  1372. rid = ts.p.idPrefix + rid;
  1373. altr = rcnt === 0 ? 0 : rcnt+1;
  1374. cn1 = (altr+j)%2 === 1 ? cn : '';
  1375. var iStartTrTag = rowData.length;
  1376. rowData.push("");
  1377. if( ni ) {
  1378. rowData.push( addRowNum(0,j,ts.p.page,ts.p.rowNum) );
  1379. }
  1380. if( gi ) {
  1381. rowData.push( addMulti(rid,ni,j, false) );
  1382. }
  1383. if( si ) {
  1384. rowData.push( addSubGridCell.call(self,gi+ni,j+rcnt) );
  1385. }
  1386. if(xmlRd.repeatitems){
  1387. if (!F) { F=orderedCols(gi+si+ni); }
  1388. var cells = $.jgrid.getXmlData( xmlr, xmlRd.cell, true);
  1389. $.each(F, function (k) {
  1390. var cell = cells[this];
  1391. if (!cell) { return false; }
  1392. v = cell.textContent || cell.text;
  1393. rd[ts.p.colModel[k+gi+si+ni].name] = v;
  1394. rowData.push( addCell(rid,v,k+gi+si+ni,j+rcnt,xmlr, rd) );
  1395. });
  1396. } else {
  1397. for(i = 0; i < f.length;i++) {
  1398. v = $.jgrid.getXmlData( xmlr, f[i]);
  1399. rd[ts.p.colModel[i+gi+si+ni].name] = v;
  1400. rowData.push( addCell(rid, v, i+gi+si+ni, j+rcnt, xmlr, rd) );
  1401. }
  1402. }
  1403. rowData[iStartTrTag] = constructTr(rid, hiderow, cn1, rd, xmlr, false);
  1404. rowData.push("</tr>");
  1405. if(ts.p.grouping) {
  1406. grpdata.push( rowData );
  1407. if(!ts.p.groupingView._locgr) {
  1408. groupingPrepare.call(self, rd, j );
  1409. }
  1410. rowData = [];
  1411. }
  1412. if(locdata || ts.p.treeGrid === true) {
  1413. rd[xmlid] = $.jgrid.stripPref(ts.p.idPrefix, rid);
  1414. ts.p.data.push(rd);
  1415. ts.p._index[rd[xmlid]] = ts.p.data.length-1;
  1416. }
  1417. if(ts.p.gridview === false ) {
  1418. $("tbody:first",t).append(rowData.join(''));
  1419. self.triggerHandler("jqGridAfterInsertRow", [rid, rd, xmlr]);
  1420. if(afterInsRow) {ts.p.afterInsertRow.call(ts,rid,rd,xmlr);}
  1421. rowData=[];
  1422. }
  1423. rd={};
  1424. ir++;
  1425. j++;
  1426. if(ir===rn) {break;}
  1427. }
  1428. }
  1429. if(ts.p.gridview === true) {
  1430. fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
  1431. if(ts.p.grouping) {
  1432. if(!locdata) {
  1433. self.jqGrid('groupingRender',grpdata,ts.p.colModel.length, ts.p.page, rn);
  1434. grpdata = null;
  1435. }
  1436. } else if(ts.p.treeGrid === true && fpos > 0) {
  1437. $(ts.rows[fpos]).after(rowData.join(''));
  1438. } else {
  1439. //$("tbody:first",t).append(rowData.join(''));
  1440. ts.firstElementChild.innerHTML += rowData.join(''); // append to innerHTML of tbody which contains the first row (.jqgfirstrow)
  1441. ts.grid.cols = ts.rows[0].cells; // update cached first row
  1442. }
  1443. }
  1444. if(ts.p.subGrid === true ) {
  1445. try {self.jqGrid("addSubGrid",gi+ni);} catch (_){}
  1446. }
  1447. ts.p.totaltime = new Date() - startReq;
  1448. if(ir>0) { if(ts.p.records===0) { ts.p.records=gl;} }
  1449. rowData =null;
  1450. if( ts.p.treeGrid === true) {
  1451. try {self.jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
  1452. }
  1453. //if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
  1454. ts.p.reccount=ir;
  1455. ts.p.treeANode = -1;
  1456. if(ts.p.userDataOnFooter) { self.jqGrid("footerData","set",ts.p.userData,true); }
  1457. if(locdata) {
  1458. ts.p.records = gl;
  1459. ts.p.lastpage = Math.ceil(gl/ rn);
  1460. }
  1461. if (!more) { ts.updatepager(false,true); }
  1462. if(locdata) {
  1463. while (ir<gl) {
  1464. xmlr = gxml[ir];
  1465. rid = getId(xmlr,ir+br);
  1466. rid = ts.p.idPrefix + rid;
  1467. if(xmlRd.repeatitems){
  1468. if (!F) { F=orderedCols(gi+si+ni); }
  1469. var cells2 = $.jgrid.getXmlData( xmlr, xmlRd.cell, true);
  1470. $.each(F, function (k) {
  1471. var cell = cells2[this];
  1472. if (!cell) { return false; }
  1473. v = cell.textContent || cell.text;
  1474. rd[ts.p.colModel[k+gi+si+ni].name] = v;
  1475. });
  1476. } else {
  1477. for(i = 0; i < f.length;i++) {
  1478. v = $.jgrid.getXmlData( xmlr, f[i]);
  1479. rd[ts.p.colModel[i+gi+si+ni].name] = v;
  1480. }
  1481. }
  1482. rd[xmlid] = $.jgrid.stripPref(ts.p.idPrefix, rid);
  1483. if(ts.p.grouping) {
  1484. groupingPrepare.call(self, rd, ir );
  1485. }
  1486. ts.p.data.push(rd);
  1487. ts.p._index[rd[xmlid]] = ts.p.data.length-1;
  1488. rd = {};
  1489. ir++;
  1490. }
  1491. if(ts.p.grouping) {
  1492. ts.p.groupingView._locgr = true;
  1493. self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn);
  1494. grpdata = null;
  1495. }
  1496. }
  1497. },
  1498. addJSONData = function(data,t, rcnt, more, adjust) {
  1499. var startReq = new Date();
  1500. if(data) {
  1501. if(ts.p.treeANode === -1 && !ts.p.scroll) {
  1502. emptyRows.call(ts, false, true);
  1503. rcnt=1;
  1504. } else { rcnt = rcnt > 1 ? rcnt :1; }
  1505. } else { return; }
  1506. var dReader, locid = "_id_", frd,
  1507. locdata = (ts.p.datatype !== "local" && ts.p.loadonce) || ts.p.datatype === "jsonstring";
  1508. if(locdata) { ts.p.data = []; ts.p._index = {}; ts.p.localReader.id = locid;}
  1509. ts.p.reccount = 0;
  1510. if(ts.p.datatype === "local") {
  1511. dReader = ts.p.localReader;
  1512. frd= 'local';
  1513. } else {
  1514. dReader = ts.p.jsonReader;
  1515. frd='json';
  1516. }
  1517. var self = $(ts), ir=0,v,i,j,f=[],cur,gi=ts.p.multiselect?1:0,si=ts.p.subGrid===true?1:0,addSubGridCell,ni=ts.p.rownumbers===true?1:0,arrayReader=orderedCols(gi+si+ni),objectReader=reader(frd),rowReader,len,drows,idn,rd={}, fpos, idr,rowData=[],cn=(ts.p.altRows === true) ? ts.p.altclass:"",cn1;
  1518. ts.p.page = intNum($.jgrid.getAccessor(data,dReader.page), ts.p.page);
  1519. ts.p.lastpage = intNum($.jgrid.getAccessor(data,dReader.total), 1);
  1520. ts.p.records = intNum($.jgrid.getAccessor(data,dReader.records));
  1521. ts.p.userData = $.jgrid.getAccessor(data,dReader.userdata) || {};
  1522. if(si) {
  1523. addSubGridCell = $.jgrid.getMethod("addSubGridCell");
  1524. }
  1525. if( ts.p.keyName===false ) {
  1526. idn = $.isFunction(dReader.id) ? dReader.id.call(ts, data) : dReader.id;
  1527. } else {
  1528. idn = ts.p.keyName;
  1529. }
  1530. drows = $.jgrid.getAccessor(data,dReader.root);
  1531. if (drows == null && $.isArray(data)) { drows = data; }
  1532. if (!drows) { drows = []; }
  1533. len = drows.length; i=0;
  1534. if (len > 0 && ts.p.page <= 0) { ts.p.page = 1; }
  1535. var rn = parseInt(ts.p.rowNum,10),br=ts.p.scroll?$.jgrid.randId():1, altr, selected=false, selr;
  1536. if (adjust) { rn *= adjust+1; }
  1537. if(ts.p.datatype === "local" && !ts.p.deselectAfterSort) {
  1538. selected = true;
  1539. }
  1540. var afterInsRow = $.isFunction(ts.p.afterInsertRow), grpdata=[],hiderow=false, groupingPrepare;
  1541. if(ts.p.grouping) {
  1542. hiderow = ts.p.groupingView.groupCollapse === true;
  1543. groupingPrepare = $.jgrid.getMethod("groupingPrepare");
  1544. }
  1545. while (i<len) {
  1546. cur = drows[i];
  1547. idr = $.jgrid.getAccessor(cur,idn);
  1548. if(idr === undefined) {
  1549. if (typeof idn === "number" && ts.p.colModel[idn+gi+si+ni] != null) {
  1550. // reread id by name
  1551. idr = $.jgrid.getAccessor(cur,ts.p.colModel[idn+gi+si+ni].name);
  1552. }
  1553. if(idr === undefined) {
  1554. idr = br+i;
  1555. if(f.length===0){
  1556. if(dReader.cell){
  1557. var ccur = $.jgrid.getAccessor(cur,dReader.cell) || cur;
  1558. idr = ccur != null && ccur[idn] !== undefined ? ccur[idn] : idr;
  1559. ccur=null;
  1560. }
  1561. }
  1562. }
  1563. }
  1564. idr = ts.p.idPrefix + idr;
  1565. altr = rcnt === 1 ? 0 : rcnt;
  1566. cn1 = (altr+i)%2 === 1 ? cn : '';
  1567. if( selected) {
  1568. if( ts.p.multiselect) {
  1569. selr = ($.inArray(idr, ts.p.selarrrow) !== -1);
  1570. } else {
  1571. selr = (idr === ts.p.selrow);
  1572. }
  1573. }
  1574. var iStartTrTag = rowData.length;
  1575. rowData.push("");
  1576. if( ni ) {
  1577. rowData.push( addRowNum(0,i,ts.p.page,ts.p.rowNum) );
  1578. }
  1579. if( gi ){
  1580. rowData.push( addMulti(idr,ni,i,selr) );
  1581. }
  1582. if( si ) {
  1583. rowData.push( addSubGridCell.call(self,gi+ni,i+rcnt) );
  1584. }
  1585. rowReader=objectReader;
  1586. if (dReader.repeatitems) {
  1587. if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell) || cur;}
  1588. if ($.isArray(cur)) { rowReader=arrayReader; }
  1589. }
  1590. for (j=0;j<rowReader.length;j++) {
  1591. v = $.jgrid.getAccessor(cur,rowReader[j]);
  1592. rd[ts.p.colModel[j+gi+si+ni].name] = v;
  1593. rowData.push( addCell(idr,v,j+gi+si+ni,i+rcnt,cur, rd) );
  1594. }
  1595. rowData[iStartTrTag] = constructTr(idr, hiderow, cn1, rd, cur, selr);
  1596. rowData.push( "</tr>" );
  1597. if(ts.p.grouping) {
  1598. grpdata.push( rowData );
  1599. if(!ts.p.groupingView._locgr) {
  1600. groupingPrepare.call(self, rd, i);
  1601. }
  1602. rowData = [];
  1603. }
  1604. if(locdata || ts.p.treeGrid===true) {
  1605. rd[locid] = $.jgrid.stripPref(ts.p.idPrefix, idr);
  1606. ts.p.data.push(rd);
  1607. ts.p._index[rd[locid]] = ts.p.data.length-1;
  1608. }
  1609. if(ts.p.gridview === false ) {
  1610. $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join(''));
  1611. self.triggerHandler("jqGridAfterInsertRow", [idr, rd, cur]);
  1612. if(afterInsRow) {ts.p.afterInsertRow.call(ts,idr,rd,cur);}
  1613. rowData=[];//ari=0;
  1614. }
  1615. rd={};
  1616. ir++;
  1617. i++;
  1618. if(ir===rn) { break; }
  1619. }
  1620. if(ts.p.gridview === true ) {
  1621. fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
  1622. if(ts.p.grouping) {
  1623. if(!locdata) {
  1624. self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn);
  1625. grpdata = null;
  1626. }
  1627. } else if(ts.p.treeGrid === true && fpos > 0) {
  1628. $(ts.rows[fpos]).after(rowData.join(''));
  1629. } else {
  1630. //$("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join(''));
  1631. ts.firstElementChild.innerHTML += rowData.join(''); // append to innerHTML of tbody which contains the first row (.jqgfirstrow)
  1632. ts.grid.cols = ts.rows[0].cells; // update cached first row
  1633. }
  1634. }
  1635. if(ts.p.subGrid === true ) {
  1636. try { self.jqGrid("addSubGrid",gi+ni);} catch (_){}
  1637. }
  1638. ts.p.totaltime = new Date() - startReq;
  1639. if(ir>0) {
  1640. if(ts.p.records===0) { ts.p.records=len; }
  1641. }
  1642. rowData = null;
  1643. if( ts.p.treeGrid === true) {
  1644. try {self.jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
  1645. }
  1646. //if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
  1647. ts.p.reccount=ir;
  1648. ts.p.treeANode = -1;
  1649. if(ts.p.userDataOnFooter) { self.jqGrid("footerData","set",ts.p.userData,true); }
  1650. if(locdata) {
  1651. ts.p.records = len;
  1652. ts.p.lastpage = Math.ceil(len/ rn);
  1653. }
  1654. if (!more) { ts.updatepager(false,true); }
  1655. if(locdata) {
  1656. while (ir<len && drows[ir]) {
  1657. cur = drows[ir];
  1658. idr = $.jgrid.getAccessor(cur,idn);
  1659. if(idr === undefined) {
  1660. if (typeof idn === "number" && ts.p.colModel[idn+gi+si+ni] != null) {
  1661. // reread id by name
  1662. idr = $.jgrid.getAccessor(cur,ts.p.colModel[idn+gi+si+ni].name);
  1663. }
  1664. if(idr === undefined) {
  1665. idr = br+ir;
  1666. if(f.length===0){
  1667. if(dReader.cell){
  1668. var ccur2 = $.jgrid.getAccessor(cur,dReader.cell) || cur;
  1669. idr = ccur2 != null && ccur2[idn] !== undefined ? ccur2[idn] : idr;
  1670. ccur2=null;
  1671. }
  1672. }
  1673. }
  1674. }
  1675. if(cur) {
  1676. idr = ts.p.idPrefix + idr;
  1677. rowReader=objectReader;
  1678. if (dReader.repeatitems) {
  1679. if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell) || cur;}
  1680. if ($.isArray(cur)) { rowReader=arrayReader; }
  1681. }
  1682. for (j=0;j<rowReader.length;j++) {
  1683. rd[ts.p.colModel[j+gi+si+ni].name] = $.jgrid.getAccessor(cur,rowReader[j]);
  1684. }
  1685. rd[locid] = $.jgrid.stripPref(ts.p.idPrefix, idr);
  1686. if(ts.p.grouping) {
  1687. groupingPrepare.call(self, rd, ir );
  1688. }
  1689. ts.p.data.push(rd);
  1690. ts.p._index[rd[locid]] = ts.p.data.length-1;
  1691. rd = {};
  1692. }
  1693. ir++;
  1694. }
  1695. if(ts.p.grouping) {
  1696. ts.p.groupingView._locgr = true;
  1697. self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn);
  1698. grpdata = null;
  1699. }
  1700. }
  1701. },
  1702. addLocalData = function() {
  1703. var st = ts.p.multiSort ? [] : "", sto=[], fndsort=false, cmtypes={}, grtypes=[], grindexes=[], srcformat, sorttype, newformat;
  1704. if(!$.isArray(ts.p.data)) {
  1705. return;
  1706. }
  1707. var grpview = ts.p.grouping ? ts.p.groupingView : false, lengrp, gin;
  1708. $.each(ts.p.colModel,function(){
  1709. sorttype = this.sorttype || "text";
  1710. if(sorttype === "date" || sorttype === "datetime") {
  1711. if(this.formatter && typeof this.formatter === 'string' && this.formatter === 'date') {
  1712. if(this.formatoptions && this.formatoptions.srcformat) {
  1713. srcformat = this.formatoptions.srcformat;
  1714. } else {
  1715. srcformat = $.jgrid.formatter.date.srcformat;
  1716. }
  1717. if(this.formatoptions && this.formatoptions.newformat) {
  1718. newformat = this.formatoptions.newformat;
  1719. } else {
  1720. newformat = $.jgrid.formatter.date.newformat;
  1721. }
  1722. } else {
  1723. srcformat = newformat = this.datefmt || "Y-m-d";
  1724. }
  1725. cmtypes[this.name] = {"stype": sorttype, "srcfmt": srcformat,"newfmt":newformat, "sfunc": this.sortfunc || null};
  1726. } else {
  1727. cmtypes[this.name] = {"stype": sorttype, "srcfmt":'',"newfmt":'', "sfunc": this.sortfunc || null};
  1728. }
  1729. if(ts.p.grouping ) {
  1730. for(gin =0, lengrp = grpview.groupField.length; gin< lengrp; gin++) {
  1731. if( this.name === grpview.groupField[gin]) {
  1732. var grindex = this.name;
  1733. if (this.index) {
  1734. grindex = this.index;
  1735. }
  1736. grtypes[gin] = cmtypes[grindex];
  1737. grindexes[gin]= grindex;
  1738. }
  1739. }
  1740. }
  1741. if(ts.p.multiSort) {
  1742. if(this.lso) {
  1743. st.push(this.name);
  1744. var tmplso= this.lso.split("-");
  1745. sto.push( tmplso[tmplso.length-1] );
  1746. }
  1747. } else {
  1748. if(!fndsort && (this.index === ts.p.sortname || this.name === ts.p.sortname)){
  1749. st = this.name; // ???
  1750. fndsort = true;
  1751. }
  1752. }
  1753. });
  1754. if(ts.p.treeGrid) {
  1755. $(ts).jqGrid("SortTree", st, ts.p.sortorder, cmtypes[st].stype || 'text', cmtypes[st].srcfmt || '');
  1756. return;
  1757. }
  1758. var compareFnMap = {
  1759. 'eq':function(queryObj) {return queryObj.equals;},
  1760. 'ne':function(queryObj) {return queryObj.notEquals;},
  1761. 'lt':function(queryObj) {return queryObj.less;},
  1762. 'le':function(queryObj) {return queryObj.lessOrEquals;},
  1763. 'gt':function(queryObj) {return queryObj.greater;},
  1764. 'ge':function(queryObj) {return queryObj.greaterOrEquals;},
  1765. 'cn':function(queryObj) {return queryObj.contains;},
  1766. 'nc':function(queryObj,op) {return op === "OR" ? queryObj.orNot().contains : queryObj.andNot().contains;},
  1767. 'bw':function(queryObj) {return queryObj.startsWith;},
  1768. 'bn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().startsWith : queryObj.andNot().startsWith;},
  1769. 'en':function(queryObj,op) {return op === "OR" ? queryObj.orNot().endsWith : queryObj.andNot().endsWith;},
  1770. 'ew':function(queryObj) {return queryObj.endsWith;},
  1771. 'ni':function(queryObj,op) {return op === "OR" ? queryObj.orNot().equals : queryObj.andNot().equals;},
  1772. 'in':function(queryObj) {return queryObj.equals;},
  1773. 'nu':function(queryObj) {return queryObj.isNull;},
  1774. 'nn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().isNull : queryObj.andNot().isNull;}
  1775. },
  1776. query = $.jgrid.from(ts.p.data);
  1777. if (ts.p.ignoreCase) { query = query.ignoreCase(); }
  1778. function tojLinq ( group ) {
  1779. var s = 0, index, gor, ror, opr, rule;
  1780. if (group.groups != null) {
  1781. gor = group.groups.length && group.groupOp.toString().toUpperCase() === "OR";
  1782. if (gor) {
  1783. query.orBegin();
  1784. }
  1785. for (index = 0; index < group.groups.length; index++) {
  1786. if (s > 0 && gor) {
  1787. query.or();
  1788. }
  1789. try {
  1790. tojLinq(group.groups[index]);
  1791. } catch (e) {alert(e);}
  1792. s++;
  1793. }
  1794. if (gor) {
  1795. query.orEnd();
  1796. }
  1797. }
  1798. if (group.rules != null) {
  1799. //if(s>0) {
  1800. // var result = query.select();
  1801. // query = $.jgrid.from( result);
  1802. // if (ts.p.ignoreCase) { query = query.ignoreCase(); }
  1803. //}
  1804. try{
  1805. ror = group.rules.length && group.groupOp.toString().toUpperCase() === "OR";
  1806. if (ror) {
  1807. query.orBegin();
  1808. }
  1809. for (index = 0; index < group.rules.length; index++) {
  1810. rule = group.rules[index];
  1811. opr = group.groupOp.toString().toUpperCase();
  1812. if (compareFnMap[rule.op] && rule.field ) {
  1813. if(s > 0 && opr && opr === "OR") {
  1814. query = query.or();
  1815. }
  1816. query = compareFnMap[rule.op](query, opr)(rule.field, rule.data, cmtypes[rule.field]);
  1817. }
  1818. s++;
  1819. }
  1820. if (ror) {
  1821. query.orEnd();
  1822. }
  1823. } catch (g) {alert(g);}
  1824. }
  1825. }
  1826. if (ts.p.search === true) {
  1827. var srules = ts.p.postData.filters;
  1828. if(srules) {
  1829. if(typeof srules === "string") { srules = $.jgrid.parse(srules);}
  1830. tojLinq( srules );
  1831. } else {
  1832. try {
  1833. query = compareFnMap[ts.p.postData.searchOper](query)(ts.p.postData.searchField, ts.p.postData.searchString,cmtypes[ts.p.postData.searchField]);
  1834. } catch (se){}
  1835. }
  1836. }
  1837. if(ts.p.grouping) {
  1838. for(gin=0; gin<lengrp;gin++) {
  1839. query.orderBy(grindexes[gin],grpview.groupOrder[gin],grtypes[gin].stype, grtypes[gin].srcfmt);
  1840. }
  1841. }
  1842. if(ts.p.multiSort) {
  1843. $.each(st,function(i){
  1844. query.orderBy(this, sto[i], cmtypes[this].stype, cmtypes[this].srcfmt, cmtypes[this].sfunc);
  1845. });
  1846. } else {
  1847. if (st && ts.p.sortorder && fndsort) {
  1848. if(ts.p.sortorder.toUpperCase() === "DESC") {
  1849. query.orderBy(ts.p.sortname, "d", cmtypes[st].stype, cmtypes[st].srcfmt, cmtypes[st].sfunc);
  1850. } else {
  1851. query.orderBy(ts.p.sortname, "a", cmtypes[st].stype, cmtypes[st].srcfmt, cmtypes[st].sfunc);
  1852. }
  1853. }
  1854. }
  1855. var queryResults = query.select(),
  1856. recordsperpage = parseInt(ts.p.rowNum,10),
  1857. total = queryResults.length,
  1858. page = parseInt(ts.p.page,10),
  1859. totalpages = Math.ceil(total / recordsperpage),
  1860. retresult = {};
  1861. if((ts.p.search || ts.p.resetsearch) && ts.p.grouping && ts.p.groupingView._locgr) {
  1862. ts.p.groupingView.groups =[];
  1863. var j, grPrepare = $.jgrid.getMethod("groupingPrepare"), key, udc;
  1864. if(ts.p.footerrow && ts.p.userDataOnFooter) {
  1865. for (key in ts.p.userData) {
  1866. if(ts.p.userData.hasOwnProperty(key)) {
  1867. ts.p.userData[key] = 0;
  1868. }
  1869. }
  1870. udc = true;
  1871. }
  1872. for(j=0; j<total; j++) {
  1873. if(udc) {
  1874. for(key in ts.p.userData){
  1875. ts.p.userData[key] += parseFloat(queryResults[j][key] || 0);
  1876. }
  1877. }
  1878. grPrepare.call($(ts),queryResults[j],j, recordsperpage );
  1879. }
  1880. }
  1881. queryResults = queryResults.slice( (page-1)*recordsperpage , page*recordsperpage );
  1882. query = null;
  1883. cmtypes = null;
  1884. retresult[ts.p.localReader.total] = totalpages;
  1885. retresult[ts.p.localReader.page] = page;
  1886. retresult[ts.p.localReader.records] = total;
  1887. retresult[ts.p.localReader.root] = queryResults;
  1888. retresult[ts.p.localReader.userdata] = ts.p.userData;
  1889. queryResults = null;
  1890. return retresult;
  1891. },
  1892. updatepager = function(rn, dnd) {
  1893. var cp, last, base, from,to,tot,fmt, pgboxes = "", sppg,
  1894. tspg = ts.p.pager ? "_"+$.jgrid.jqID(ts.p.pager.substr(1)) : "",
  1895. tspg_t = ts.p.toppager ? "_"+ts.p.toppager.substr(1) : "";
  1896. base = parseInt(ts.p.page,10)-1;
  1897. if(base < 0) { base = 0; }
  1898. base = base*parseInt(ts.p.rowNum,10);
  1899. to = base + ts.p.reccount;
  1900. if (ts.p.scroll) {
  1901. var rows = $("tbody:first > tr:gt(0)", ts.grid.bDiv);
  1902. base = to - rows.length;
  1903. ts.p.reccount = rows.length;
  1904. var rh = rows.outerHeight() || ts.grid.prevRowHeight;
  1905. if (rh) {
  1906. var top = base * rh;
  1907. var height = parseInt(ts.p.records,10) * rh;
  1908. $(">div:first",ts.grid.bDiv).css({height : height}).children("div:first").css({height:top,display:top?"":"none"});
  1909. if (ts.grid.bDiv.scrollTop == 0 && ts.p.page > 1) {
  1910. ts.grid.bDiv.scrollTop = ts.p.rowNum * (ts.p.page - 1) * rh;
  1911. }
  1912. }
  1913. ts.grid.bDiv.scrollLeft = ts.grid.hDiv.scrollLeft;
  1914. }
  1915. pgboxes = ts.p.pager || "";
  1916. pgboxes += ts.p.toppager ? (pgboxes ? "," + ts.p.toppager : ts.p.toppager) : "";
  1917. if(pgboxes) {
  1918. fmt = $.jgrid.formatter.integer || {};
  1919. cp = intNum(ts.p.page);
  1920. last = intNum(ts.p.lastpage);
  1921. $(".selbox",pgboxes)[ this.p.useProp ? 'prop' : 'attr' ]("disabled",false);
  1922. if(ts.p.pginput===true) {
  1923. $('.ui-pg-input',pgboxes).val(ts.p.page);
  1924. sppg = ts.p.toppager ? '#sp_1'+tspg+",#sp_1"+tspg_t : '#sp_1'+tspg;
  1925. $(sppg).html($.fmatter ? $.fmatter.util.NumberFormat(ts.p.lastpage,fmt):ts.p.lastpage);
  1926. }
  1927. if (ts.p.viewrecords){
  1928. if(ts.p.reccount === 0) {
  1929. $(".ui-paging-info",pgboxes).html(ts.p.emptyrecords);
  1930. } else {
  1931. from = base+1;
  1932. tot=ts.p.records;
  1933. if($.fmatter) {
  1934. from = $.fmatter.util.NumberFormat(from,fmt);
  1935. to = $.fmatter.util.NumberFormat(to,fmt);
  1936. tot = $.fmatter.util.NumberFormat(tot,fmt);
  1937. }
  1938. $(".ui-paging-info",pgboxes).html($.jgrid.format(ts.p.recordtext,from,to,tot));
  1939. }
  1940. }
  1941. if(ts.p.pgbuttons===true) {
  1942. if(cp<=0) {cp = last = 0;}
  1943. if(cp===1 || cp === 0) {
  1944. $("#first"+tspg+", #prev"+tspg).addClass('ui-state-disabled').removeClass('ui-state-hover');
  1945. if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).addClass('ui-state-disabled').removeClass('ui-state-hover'); }
  1946. } else {
  1947. $("#first"+tspg+", #prev"+tspg).removeClass('ui-state-disabled');
  1948. if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).removeClass('ui-state-disabled'); }
  1949. }
  1950. if(cp===last || cp === 0) {
  1951. $("#next"+tspg+", #last"+tspg).addClass('ui-state-disabled').removeClass('ui-state-hover');
  1952. if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).addClass('ui-state-disabled').removeClass('ui-state-hover'); }
  1953. } else {
  1954. $("#next"+tspg+", #last"+tspg).removeClass('ui-state-disabled');
  1955. if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).removeClass('ui-state-disabled'); }
  1956. }
  1957. }
  1958. }
  1959. if(rn===true && ts.p.rownumbers === true) {
  1960. $(">td.jqgrid-rownum",ts.rows).each(function(i){
  1961. $(this).html(base+1+i);
  1962. });
  1963. }
  1964. if(dnd && ts.p.jqgdnd) { $(ts).jqGrid('gridDnD','updateDnD');}
  1965. $(ts).triggerHandler("jqGridGridComplete");
  1966. if($.isFunction(ts.p.gridComplete)) {ts.p.gridComplete.call(ts);}
  1967. $(ts).triggerHandler("jqGridAfterGridComplete");
  1968. },
  1969. beginReq = function() {
  1970. ts.grid.hDiv.loading = true;
  1971. if(ts.p.hiddengrid) { return;}
  1972. $(ts).jqGrid("progressBar", {method:"show", loadtype : ts.p.loadui, htmlcontent: ts.p.loadtext });
  1973. },
  1974. endReq = function() {
  1975. ts.grid.hDiv.loading = false;
  1976. $(ts).jqGrid("progressBar", {method:"hide", loadtype : ts.p.loadui });
  1977. },
  1978. populate = function (npage) {
  1979. if(!ts.grid.hDiv.loading) {
  1980. var pvis = ts.p.scroll && npage === false,
  1981. prm = {}, dt, dstr, pN=ts.p.prmNames;
  1982. if(ts.p.page <=0) { ts.p.page = Math.min(1,ts.p.lastpage); }
  1983. if(pN.search !== null) {prm[pN.search] = ts.p.search;} if(pN.nd !== null) {prm[pN.nd] = new Date().getTime();}
  1984. if(pN.rows !== null) {prm[pN.rows]= ts.p.rowNum;} if(pN.page !== null) {prm[pN.page]= ts.p.page;}
  1985. if(pN.sort !== null) {prm[pN.sort]= ts.p.sortname;} if(pN.order !== null) {prm[pN.order]= ts.p.sortorder;}
  1986. if(ts.p.rowTotal !== null && pN.totalrows !== null) { prm[pN.totalrows]= ts.p.rowTotal; }
  1987. var lcf = $.isFunction(ts.p.loadComplete), lc = lcf ? ts.p.loadComplete : null;
  1988. var adjust = 0;
  1989. npage = npage || 1;
  1990. if (npage > 1) {
  1991. if(pN.npage !== null) {
  1992. prm[pN.npage] = npage;
  1993. adjust = npage - 1;
  1994. npage = 1;
  1995. } else {
  1996. lc = function(req) {
  1997. ts.p.page++;
  1998. ts.grid.hDiv.loading = false;
  1999. if (lcf) {
  2000. ts.p.loadComplete.call(ts,req);
  2001. }
  2002. populate(npage-1);
  2003. };
  2004. }
  2005. } else if (pN.npage !== null) {
  2006. delete ts.p.postData[pN.npage];
  2007. }
  2008. if(ts.p.grouping) {
  2009. $(ts).jqGrid('groupingSetup');
  2010. var grp = ts.p.groupingView, gi, gs="";
  2011. for(gi=0;gi<grp.groupField.length;gi++) {
  2012. var index = grp.groupField[gi];
  2013. $.each(ts.p.colModel, function(cmIndex, cmValue) {
  2014. if (cmValue.name === index && cmValue.index){
  2015. index = cmValue.index;
  2016. }
  2017. } );
  2018. gs += index +" "+grp.groupOrder[gi]+", ";
  2019. }
  2020. prm[pN.sort] = gs + prm[pN.sort];
  2021. }
  2022. $.extend(ts.p.postData,prm);
  2023. var rcnt = !ts.p.scroll ? 1 : ts.rows.length-1;
  2024. var bfr = $(ts).triggerHandler("jqGridBeforeRequest");
  2025. if (bfr === false || bfr === 'stop') { return; }
  2026. if ($.isFunction(ts.p.datatype)) { ts.p.datatype.call(ts,ts.p.postData,"load_"+ts.p.id, rcnt, npage, adjust); return;}
  2027. if ($.isFunction(ts.p.beforeRequest)) {
  2028. bfr = ts.p.beforeRequest.call(ts);
  2029. if(bfr === undefined) { bfr = true; }
  2030. if ( bfr === false ) { return; }
  2031. }
  2032. dt = ts.p.datatype.toLowerCase();
  2033. switch(dt)
  2034. {
  2035. case "json":
  2036. case "jsonp":
  2037. case "xml":
  2038. case "script":
  2039. $.ajax($.extend({
  2040. url:ts.p.url,
  2041. type:ts.p.mtype,
  2042. dataType: dt ,
  2043. data: $.isFunction(ts.p.serializeGridData)? ts.p.serializeGridData.call(ts,ts.p.postData) : ts.p.postData,
  2044. success:function(data,st, xhr) {
  2045. if ($.isFunction(ts.p.beforeProcessing)) {
  2046. if (ts.p.beforeProcessing.call(ts, data, st, xhr) === false) {
  2047. endReq();
  2048. return;
  2049. }
  2050. }
  2051. if(dt === "xml") { addXmlData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
  2052. else { addJSONData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
  2053. $(ts).triggerHandler("jqGridLoadComplete", [data]);
  2054. if(lc) { lc.call(ts,data); }
  2055. $(ts).triggerHandler("jqGridAfterLoadComplete", [data]);
  2056. if (pvis) { ts.grid.populateVisible(); }
  2057. if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";}
  2058. data=null;
  2059. if (npage === 1) { endReq(); }
  2060. },
  2061. error:function(xhr,st,err){
  2062. if($.isFunction(ts.p.loadError)) { ts.p.loadError.call(ts,xhr,st,err); }
  2063. if (npage === 1) { endReq(); }
  2064. xhr=null;
  2065. },
  2066. beforeSend: function(xhr, settings ){
  2067. var gotoreq = true;
  2068. if($.isFunction(ts.p.loadBeforeSend)) {
  2069. gotoreq = ts.p.loadBeforeSend.call(ts,xhr, settings);
  2070. }
  2071. if(gotoreq === undefined) { gotoreq = true; }
  2072. if(gotoreq === false) {
  2073. return false;
  2074. }
  2075. beginReq();
  2076. }
  2077. },$.jgrid.ajaxOptions, ts.p.ajaxGridOptions));
  2078. break;
  2079. case "xmlstring":
  2080. beginReq();
  2081. dstr = typeof ts.p.datastr !== 'string' ? ts.p.datastr : $.parseXML(ts.p.datastr);
  2082. addXmlData(dstr,ts.grid.bDiv);
  2083. $(ts).triggerHandler("jqGridLoadComplete", [dstr]);
  2084. if(lcf) {ts.p.loadComplete.call(ts,dstr);}
  2085. $(ts).triggerHandler("jqGridAfterLoadComplete", [dstr]);
  2086. ts.p.datatype = "local";
  2087. ts.p.datastr = null;
  2088. endReq();
  2089. break;
  2090. case "jsonstring":
  2091. beginReq();
  2092. if(typeof ts.p.datastr === 'string') { dstr = $.jgrid.parse(ts.p.datastr); }
  2093. else { dstr = ts.p.datastr; }
  2094. addJSONData(dstr,ts.grid.bDiv);
  2095. $(ts).triggerHandler("jqGridLoadComplete", [dstr]);
  2096. if(lcf) {ts.p.loadComplete.call(ts,dstr);}
  2097. $(ts).triggerHandler("jqGridAfterLoadComplete", [dstr]);
  2098. ts.p.datatype = "local";
  2099. ts.p.datastr = null;
  2100. endReq();
  2101. break;
  2102. case "local":
  2103. case "clientside":
  2104. beginReq();
  2105. ts.p.datatype = "local";
  2106. var req = addLocalData();
  2107. addJSONData(req,ts.grid.bDiv,rcnt,npage>1,adjust);
  2108. $(ts).triggerHandler("jqGridLoadComplete", [req]);
  2109. if(lc) { lc.call(ts,req); }
  2110. $(ts).triggerHandler("jqGridAfterLoadComplete", [req]);
  2111. if (pvis) { ts.grid.populateVisible(); }
  2112. endReq();
  2113. break;
  2114. }
  2115. }
  2116. },
  2117. setHeadCheckBox = function ( checked ) {
  2118. $('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.hDiv)[ts.p.useProp ? 'prop': 'attr']("checked", checked);
  2119. var fid = ts.p.frozenColumns ? ts.p.id+"_frozen" : "";
  2120. if(fid) {
  2121. $('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.fhDiv)[ts.p.useProp ? 'prop': 'attr']("checked", checked);
  2122. }
  2123. },
  2124. setPager = function (pgid, tp){
  2125. // TBD - consider escaping pgid with pgid = $.jgrid.jqID(pgid);
  2126. var sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='ui-separator'></span></td>",
  2127. pginp = "",
  2128. pgl="<table cellspacing='0' cellpadding='0' border='0' style='table-layout:auto;' class='ui-pg-table'><tbody><tr>",
  2129. str="", pgcnt, lft, cent, rgt, twd, tdw, i,
  2130. clearVals = function(onpaging){
  2131. var ret;
  2132. if ($.isFunction(ts.p.onPaging) ) { ret = ts.p.onPaging.call(ts,onpaging); }
  2133. if(ret==='stop') {return false;}
  2134. ts.p.selrow = null;
  2135. if(ts.p.multiselect) {ts.p.selarrrow =[]; setHeadCheckBox( false );}
  2136. ts.p.savedRow = [];
  2137. return true;
  2138. };
  2139. pgid = pgid.substr(1);
  2140. tp += "_" + pgid;
  2141. pgcnt = "pg_"+pgid;
  2142. lft = pgid+"_left"; cent = pgid+"_center"; rgt = pgid+"_right";
  2143. $("#"+$.jgrid.jqID(pgid) )
  2144. .append("<div id='"+pgcnt+"' class='ui-pager-control' role='group'><table cellspacing='0' cellpadding='0' border='0' class='ui-pg-table' style='width:100%;table-layout:fixed;height:100%;' role='row'><tbody><tr><td id='"+lft+"' align='left'></td><td id='"+cent+"' align='center' style='white-space:pre;'></td><td id='"+rgt+"' align='right'></td></tr></tbody></table></div>")
  2145. .attr("dir","ltr"); //explicit setting
  2146. if(ts.p.rowList.length >0){
  2147. str = "<td dir='"+dir+"'>";
  2148. str +="<select class='ui-pg-selbox' role='listbox' " + (ts.p.pgrecs ? "title='"+ts.p.pgrecs +"'" : "")+ ">";
  2149. var strnm;
  2150. for(i=0;i<ts.p.rowList.length;i++){
  2151. strnm = ts.p.rowList[i].toString().split(":");
  2152. if(strnm.length === 1) {
  2153. strnm[1] = strnm[0];
  2154. }
  2155. str +="<option role=\"option\" value=\""+strnm[0]+"\""+(( intNum(ts.p.rowNum,0) === intNum(strnm[0],0))?" selected=\"selected\"":"")+">"+strnm[1]+"</option>";
  2156. }
  2157. str +="</select></td>";
  2158. }
  2159. if(dir==="rtl") { pgl += str; }
  2160. if(ts.p.pginput===true) { pginp= "<td dir='"+dir+"'>"+$.jgrid.format(ts.p.pgtext || "","<input class='ui-pg-input' type='text' size='2' maxlength='7' value='0' role='textbox'/>","<span id='sp_1_"+$.jgrid.jqID(pgid)+"'></span>")+"</td>";}
  2161. if(ts.p.pgbuttons===true) {
  2162. var po=["first"+tp,"prev"+tp, "next"+tp,"last"+tp]; if(dir==="rtl") { po.reverse(); }
  2163. pgl += "<td id='"+po[0]+"' class='ui-pg-button ui-corner-all' " + (ts.p.pgfirst ? "title='"+ts.p.pgfirst +"'" : "")+"><span class='ui-icon ui-icon-seek-first'></span></td>";
  2164. pgl += "<td id='"+po[1]+"' class='ui-pg-button ui-corner-all' " + (ts.p.pgprev ? "title='"+ts.p.pgprev +"'" : "")+"><span class='ui-icon ui-icon-seek-prev'></span></td>";
  2165. pgl += pginp !== "" ? sep+pginp+sep:"";
  2166. pgl += "<td id='"+po[2]+"' class='ui-pg-button ui-corner-all' " + (ts.p.pgnext ? "title='"+ts.p.pgnext +"'" : "")+"><span class='ui-icon ui-icon-seek-next'></span></td>";
  2167. pgl += "<td id='"+po[3]+"' class='ui-pg-button ui-corner-all' " + (ts.p.pglast ? "title='"+ts.p.pglast +"'" : "")+"><span class='ui-icon ui-icon-seek-end'></span></td>";
  2168. } else if (pginp !== "") { pgl += pginp; }
  2169. if(dir==="ltr") { pgl += str; }
  2170. pgl += "</tr></tbody></table>";
  2171. if(ts.p.viewrecords===true) {$("td#"+pgid+"_"+ts.p.recordpos,"#"+pgcnt).append("<div dir='"+dir+"' style='text-align:"+ts.p.recordpos+"' class='ui-paging-info'></div>");}
  2172. $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).append(pgl);
  2173. tdw = $(".ui-jqgrid").css("font-size") || "11px";
  2174. $(document.body).append("<div id='testpg' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:"+tdw+";visibility:hidden;' ></div>");
  2175. twd = $(pgl).clone().appendTo("#testpg").width();
  2176. $("#testpg").remove();
  2177. if(twd > 0) {
  2178. if(pginp !== "") { twd += 50; } //should be param
  2179. $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).width(twd);
  2180. }
  2181. ts.p._nvtd = [];
  2182. ts.p._nvtd[0] = twd ? Math.floor((ts.p.width - twd)/2) : Math.floor(ts.p.width/3);
  2183. ts.p._nvtd[1] = 0;
  2184. pgl=null;
  2185. $('.ui-pg-selbox',"#"+pgcnt).bind('change',function() {
  2186. if(!clearVals('records')) { return false; }
  2187. ts.p.page = Math.round(ts.p.rowNum*(ts.p.page-1)/this.value-0.5)+1;
  2188. ts.p.rowNum = this.value;
  2189. if(ts.p.pager) { $('.ui-pg-selbox',ts.p.pager).val(this.value); }
  2190. if(ts.p.toppager) { $('.ui-pg-selbox',ts.p.toppager).val(this.value); }
  2191. populate();
  2192. return false;
  2193. });
  2194. if(ts.p.pgbuttons===true) {
  2195. $(".ui-pg-button","#"+pgcnt).hover(function(){
  2196. if($(this).hasClass('ui-state-disabled')) {
  2197. this.style.cursor='default';
  2198. } else {
  2199. $(this).addClass('ui-state-hover');
  2200. this.style.cursor='pointer';
  2201. }
  2202. },function() {
  2203. if(!$(this).hasClass('ui-state-disabled')) {
  2204. $(this).removeClass('ui-state-hover');
  2205. this.style.cursor= "default";
  2206. }
  2207. });
  2208. $("#first"+$.jgrid.jqID(tp)+", #prev"+$.jgrid.jqID(tp)+", #next"+$.jgrid.jqID(tp)+", #last"+$.jgrid.jqID(tp)).click( function() {
  2209. if ($(this).hasClass("ui-state-disabled")) {
  2210. return false;
  2211. }
  2212. var cp = intNum(ts.p.page,1),
  2213. last = intNum(ts.p.lastpage,1), selclick = false,
  2214. fp=true, pp=true, np=true,lp=true;
  2215. if(last ===0 || last===1) {fp=false;pp=false;np=false;lp=false; }
  2216. else if( last>1 && cp >=1) {
  2217. if( cp === 1) { fp=false; pp=false; }
  2218. //else if( cp>1 && cp <last){ }
  2219. else if( cp===last){ np=false;lp=false; }
  2220. } else if( last>1 && cp===0 ) { np=false;lp=false; cp=last-1;}
  2221. if(!clearVals(this.id)) { return false; }
  2222. if( this.id === 'first'+tp && fp ) { ts.p.page=1; selclick=true;}
  2223. if( this.id === 'prev'+tp && pp) { ts.p.page=(cp-1); selclick=true;}
  2224. if( this.id === 'next'+tp && np) { ts.p.page=(cp+1); selclick=true;}
  2225. if( this.id === 'last'+tp && lp) { ts.p.page=last; selclick=true;}
  2226. if(selclick) {
  2227. populate();
  2228. }
  2229. return false;
  2230. });
  2231. }
  2232. if(ts.p.pginput===true) {
  2233. $('input.ui-pg-input',"#"+pgcnt).keypress( function(e) {
  2234. var key = e.charCode || e.keyCode || 0;
  2235. if(key === 13) {
  2236. if(!clearVals('user')) { return false; }
  2237. $(this).val( intNum( $(this).val(), 1));
  2238. ts.p.page = ($(this).val()>0) ? $(this).val():ts.p.page;
  2239. populate();
  2240. return false;
  2241. }
  2242. return this;
  2243. });
  2244. }
  2245. },
  2246. multiSort = function(iCol, obj ) {
  2247. var splas, sort="", cm = ts.p.colModel, fs=false, ls,
  2248. selTh = ts.p.frozenColumns ? obj : ts.grid.headers[iCol].el, so="";
  2249. $("span.ui-grid-ico-sort",selTh).addClass('ui-state-disabled');
  2250. $(selTh).attr("aria-selected","false");
  2251. if(cm[iCol].lso) {
  2252. if(cm[iCol].lso==="asc") {
  2253. cm[iCol].lso += "-desc";
  2254. so = "desc";
  2255. } else if(cm[iCol].lso==="desc") {
  2256. cm[iCol].lso += "-asc";
  2257. so = "asc";
  2258. } else if(cm[iCol].lso==="asc-desc" || cm[iCol].lso==="desc-asc") {
  2259. cm[iCol].lso="";
  2260. }
  2261. } else {
  2262. cm[iCol].lso = so = cm[iCol].firstsortorder || 'asc';
  2263. }
  2264. if( so ) {
  2265. $("span.s-ico",selTh).show();
  2266. $("span.ui-icon-"+so,selTh).removeClass('ui-state-disabled');
  2267. $(selTh).attr("aria-selected","true");
  2268. } else {
  2269. if(!ts.p.viewsortcols[0]) {
  2270. $("span.s-ico",selTh).hide();
  2271. }
  2272. }
  2273. ts.p.sortorder = "";
  2274. $.each(cm, function(i){
  2275. if(this.lso) {
  2276. if(i>0 && fs) {
  2277. sort += ", ";
  2278. }
  2279. splas = this.lso.split("-");
  2280. sort += cm[i].index || cm[i].name;
  2281. sort += " "+splas[splas.length-1];
  2282. fs = true;
  2283. ts.p.sortorder = splas[splas.length-1];
  2284. }
  2285. });
  2286. ls = sort.lastIndexOf(ts.p.sortorder);
  2287. sort = sort.substring(0, ls);
  2288. ts.p.sortname = sort;
  2289. },
  2290. sortData = function (index, idxcol,reload,sor, obj){
  2291. if(!ts.p.colModel[idxcol].sortable) { return; }
  2292. if(ts.p.savedRow.length > 0) {return;}
  2293. if(!reload) {
  2294. if( ts.p.lastsort === idxcol && ts.p.sortname !== "" ) {
  2295. if( ts.p.sortorder === 'asc') {
  2296. ts.p.sortorder = 'desc';
  2297. } else if(ts.p.sortorder === 'desc') { ts.p.sortorder = 'asc';}
  2298. } else { ts.p.sortorder = ts.p.colModel[idxcol].firstsortorder || 'asc'; }
  2299. ts.p.page = 1;
  2300. }
  2301. if(ts.p.multiSort) {
  2302. multiSort( idxcol, obj);
  2303. } else {
  2304. if(sor) {
  2305. if(ts.p.lastsort === idxcol && ts.p.sortorder === sor && !reload) { return; }
  2306. ts.p.sortorder = sor;
  2307. }
  2308. var previousSelectedTh = ts.grid.headers[ts.p.lastsort].el, newSelectedTh = ts.p.frozenColumns ? obj : ts.grid.headers[idxcol].el;
  2309. $("span.ui-grid-ico-sort",previousSelectedTh).addClass('ui-state-disabled');
  2310. $(previousSelectedTh).attr("aria-selected","false");
  2311. if(ts.p.frozenColumns) {
  2312. ts.grid.fhDiv.find("span.ui-grid-ico-sort").addClass('ui-state-disabled');
  2313. ts.grid.fhDiv.find("th").attr("aria-selected","false");
  2314. }
  2315. $("span.ui-icon-"+ts.p.sortorder,newSelectedTh).removeClass('ui-state-disabled');
  2316. $(newSelectedTh).attr("aria-selected","true");
  2317. if(!ts.p.viewsortcols[0]) {
  2318. if(ts.p.lastsort !== idxcol) {
  2319. if(ts.p.frozenColumns){
  2320. ts.grid.fhDiv.find("span.s-ico").hide();
  2321. }
  2322. $("span.s-ico",previousSelectedTh).hide();
  2323. $("span.s-ico",newSelectedTh).show();
  2324. } else if (ts.p.sortname === "") { // if ts.p.lastsort === idxcol but ts.p.sortname === ""
  2325. $("span.s-ico",newSelectedTh).show();
  2326. }
  2327. }
  2328. index = index.substring(5 + ts.p.id.length + 1); // bad to be changed!?!
  2329. ts.p.sortname = ts.p.colModel[idxcol].index || index;
  2330. }
  2331. if ($(ts).triggerHandler("jqGridSortCol", [ts.p.sortname, idxcol, ts.p.sortorder]) === 'stop') {
  2332. ts.p.lastsort = idxcol;
  2333. return;
  2334. }
  2335. if($.isFunction(ts.p.onSortCol)) {if (ts.p.onSortCol.call(ts, ts.p.sortname, idxcol, ts.p.sortorder)==='stop') {ts.p.lastsort = idxcol; return;}}
  2336. if(ts.p.datatype === "local") {
  2337. if(ts.p.deselectAfterSort) {$(ts).jqGrid("resetSelection");}
  2338. } else {
  2339. ts.p.selrow = null;
  2340. if(ts.p.multiselect){setHeadCheckBox( false );}
  2341. ts.p.selarrrow =[];
  2342. ts.p.savedRow =[];
  2343. }
  2344. if(ts.p.scroll) {
  2345. var sscroll = ts.grid.bDiv.scrollLeft;
  2346. emptyRows.call(ts, true, false);
  2347. ts.grid.hDiv.scrollLeft = sscroll;
  2348. }
  2349. if(ts.p.subGrid && ts.p.datatype === 'local') {
  2350. $("td.sgexpanded","#"+$.jgrid.jqID(ts.p.id)).each(function(){
  2351. $(this).trigger("click");
  2352. });
  2353. }
  2354. populate();
  2355. ts.p.lastsort = idxcol;
  2356. if(ts.p.sortname !== index && idxcol) {ts.p.lastsort = idxcol;}
  2357. },
  2358. setColWidth = function () {
  2359. var initwidth = 0, brd=$.jgrid.cell_width? 0: intNum(ts.p.cellLayout,0), vc=0, lvc, scw=intNum(ts.p.scrollOffset,0),cw,hs=false,aw,gw=0,cr;
  2360. $.each(ts.p.colModel, function() {
  2361. if(this.hidden === undefined) {this.hidden=false;}
  2362. if(ts.p.grouping && ts.p.autowidth) {
  2363. var ind = $.inArray(this.name, ts.p.groupingView.groupField);
  2364. if(ind >= 0 && ts.p.groupingView.groupColumnShow.length > ind) {
  2365. this.hidden = !ts.p.groupingView.groupColumnShow[ind];
  2366. }
  2367. }
  2368. this.widthOrg = cw = intNum(this.width,0);
  2369. if(this.hidden===false){
  2370. initwidth += cw+brd;
  2371. if(this.fixed) {
  2372. gw += cw+brd;
  2373. } else {
  2374. vc++;
  2375. }
  2376. }
  2377. });
  2378. if(isNaN(ts.p.width)) {
  2379. ts.p.width = initwidth + ((ts.p.shrinkToFit ===false && !isNaN(ts.p.height)) ? scw : 0);
  2380. }
  2381. grid.width = ts.p.width;
  2382. ts.p.tblwidth = initwidth;
  2383. if(ts.p.shrinkToFit ===false && ts.p.forceFit === true) {ts.p.forceFit=false;}
  2384. if(ts.p.shrinkToFit===true && vc > 0) {
  2385. aw = grid.width-brd*vc-gw;
  2386. if(!isNaN(ts.p.height)) {
  2387. aw -= scw;
  2388. hs = true;
  2389. }
  2390. initwidth =0;
  2391. $.each(ts.p.colModel, function(i) {
  2392. if(this.hidden === false && !this.fixed){
  2393. cw = Math.round(aw*this.width/(ts.p.tblwidth-brd*vc-gw));
  2394. this.width =cw;
  2395. initwidth += cw;
  2396. lvc = i;
  2397. }
  2398. });
  2399. cr =0;
  2400. if (hs) {
  2401. if(grid.width-gw-(initwidth+brd*vc) !== scw){
  2402. cr = grid.width-gw-(initwidth+brd*vc)-scw;
  2403. }
  2404. } else if(!hs && Math.abs(grid.width-gw-(initwidth+brd*vc)) !== 1) {
  2405. cr = grid.width-gw-(initwidth+brd*vc);
  2406. }
  2407. ts.p.colModel[lvc].width += cr;
  2408. ts.p.tblwidth = initwidth+cr+brd*vc+gw;
  2409. if(ts.p.tblwidth > ts.p.width) {
  2410. ts.p.colModel[lvc].width -= (ts.p.tblwidth - parseInt(ts.p.width,10));
  2411. ts.p.tblwidth = ts.p.width;
  2412. }
  2413. }
  2414. },
  2415. nextVisible= function(iCol) {
  2416. var ret = iCol, j=iCol, i;
  2417. for (i = iCol+1;i<ts.p.colModel.length;i++){
  2418. if(ts.p.colModel[i].hidden !== true ) {
  2419. j=i; break;
  2420. }
  2421. }
  2422. return j-ret;
  2423. },
  2424. getOffset = function (iCol) {
  2425. var $th = $(ts.grid.headers[iCol].el), ret = [$th.position().left + $th.outerWidth()];
  2426. if(ts.p.direction==="rtl") { ret[0] = ts.p.width - ret[0]; }
  2427. ret[0] -= ts.grid.bDiv.scrollLeft;
  2428. ret.push($(ts.grid.hDiv).position().top);
  2429. ret.push($(ts.grid.bDiv).offset().top - $(ts.grid.hDiv).offset().top + $(ts.grid.bDiv).height());
  2430. return ret;
  2431. },
  2432. getColumnHeaderIndex = function (th) {
  2433. var i, headers = ts.grid.headers, ci = $.jgrid.getCellIndex(th);
  2434. for (i = 0; i < headers.length; i++) {
  2435. if (th === headers[i].el) {
  2436. ci = i;
  2437. break;
  2438. }
  2439. }
  2440. return ci;
  2441. },
  2442. colTemplate;
  2443. this.p.id = this.id;
  2444. if ($.inArray(ts.p.multikey,sortkeys) === -1 ) {ts.p.multikey = false;}
  2445. ts.p.keyName=false;
  2446. for (i=0; i<ts.p.colModel.length;i++) {
  2447. colTemplate = typeof ts.p.colModel[i].template === "string" ?
  2448. ($.jgrid.cmTemplate != null && typeof $.jgrid.cmTemplate[ts.p.colModel[i].template] === "object" ? $.jgrid.cmTemplate[ts.p.colModel[i].template]: {}) :
  2449. ts.p.colModel[i].template;
  2450. ts.p.colModel[i] = $.extend(true, {}, ts.p.cmTemplate, colTemplate || {}, ts.p.colModel[i]);
  2451. if (ts.p.keyName === false && ts.p.colModel[i].key===true) {
  2452. ts.p.keyName = ts.p.colModel[i].name;
  2453. }
  2454. }
  2455. ts.p.sortorder = ts.p.sortorder.toLowerCase();
  2456. $.jgrid.cell_width = $.jgrid.cellWidth();
  2457. if(ts.p.grouping===true) {
  2458. ts.p.scroll = false;
  2459. ts.p.rownumbers = false;
  2460. //ts.p.subGrid = false; expiremental
  2461. ts.p.treeGrid = false;
  2462. ts.p.gridview = true;
  2463. }
  2464. if(this.p.treeGrid === true) {
  2465. try { $(this).jqGrid("setTreeGrid");} catch (_) {}
  2466. if(ts.p.datatype !== "local") { ts.p.localReader = {id: "_id_"}; }
  2467. }
  2468. if(this.p.subGrid) {
  2469. try { $(ts).jqGrid("setSubGrid");} catch (s){}
  2470. }
  2471. if(this.p.multiselect) {
  2472. this.p.colNames.unshift("<input role='checkbox' id='cb_"+this.p.id+"' class='cbox' type='checkbox'/>");
  2473. this.p.colModel.unshift({name:'cb',width:$.jgrid.cell_width ? ts.p.multiselectWidth+ts.p.cellLayout : ts.p.multiselectWidth,sortable:false,resizable:false,hidedlg:true,search:false,align:'center',fixed:true});
  2474. }
  2475. if(this.p.rownumbers) {
  2476. this.p.colNames.unshift("");
  2477. this.p.colModel.unshift({name:'rn',width:ts.p.rownumWidth,sortable:false,resizable:false,hidedlg:true,search:false,align:'center',fixed:true});
  2478. }
  2479. ts.p.xmlReader = $.extend(true,{
  2480. root: "rows",
  2481. row: "row",
  2482. page: "rows>page",
  2483. total: "rows>total",
  2484. records : "rows>records",
  2485. repeatitems: true,
  2486. cell: "cell",
  2487. id: "[id]",
  2488. userdata: "userdata",
  2489. subgrid: {root:"rows", row: "row", repeatitems: true, cell:"cell"}
  2490. }, ts.p.xmlReader);
  2491. ts.p.jsonReader = $.extend(true,{
  2492. root: "rows",
  2493. page: "page",
  2494. total: "total",
  2495. records: "records",
  2496. repeatitems: true,
  2497. cell: "cell",
  2498. id: "id",
  2499. userdata: "userdata",
  2500. subgrid: {root:"rows", repeatitems: true, cell:"cell"}
  2501. },ts.p.jsonReader);
  2502. ts.p.localReader = $.extend(true,{
  2503. root: "rows",
  2504. page: "page",
  2505. total: "total",
  2506. records: "records",
  2507. repeatitems: false,
  2508. cell: "cell",
  2509. id: "id",
  2510. userdata: "userdata",
  2511. subgrid: {root:"rows", repeatitems: true, cell:"cell"}
  2512. },ts.p.localReader);
  2513. if(ts.p.scroll){
  2514. ts.p.pgbuttons = false; ts.p.pginput=false; ts.p.rowList=[];
  2515. }
  2516. if(ts.p.data.length) { normalizeData(); refreshIndex(); }
  2517. var thead = "<thead><tr class='ui-jqgrid-labels' role='row'>",
  2518. tdc, idn, w, res, sort,
  2519. td, ptr, tbody, imgs,iac="",idc="",sortarr=[], sortord=[], sotmp=[];
  2520. if(ts.p.shrinkToFit===true && ts.p.forceFit===true) {
  2521. for (i=ts.p.colModel.length-1;i>=0;i--){
  2522. if(!ts.p.colModel[i].hidden) {
  2523. ts.p.colModel[i].resizable=false;
  2524. break;
  2525. }
  2526. }
  2527. }
  2528. if(ts.p.viewsortcols[1] === 'horizontal') {iac=" ui-i-asc";idc=" ui-i-desc";}
  2529. tdc = isMSIE ? "class='ui-th-div-ie'" :"";
  2530. imgs = "<span class='s-ico' style='display:none'><span sort='asc' class='ui-grid-ico-sort ui-icon-asc"+iac+" ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-"+dir+"'></span>";
  2531. imgs += "<span sort='desc' class='ui-grid-ico-sort ui-icon-desc"+idc+" ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-"+dir+"'></span></span>";
  2532. if(ts.p.multiSort) {
  2533. sortarr = ts.p.sortname.split(",");
  2534. for (i=0; i<sortarr.length; i++) {
  2535. sotmp = $.trim(sortarr[i]).split(" ");
  2536. sortarr[i] = $.trim(sotmp[0]);
  2537. sortord[i] = sotmp[1] ? $.trim(sotmp[1]) : ts.p.sortorder || "asc";
  2538. }
  2539. }
  2540. for(i=0;i<this.p.colNames.length;i++){
  2541. var tooltip = ts.p.headertitles ? (" title=\""+$.jgrid.stripHtml(ts.p.colNames[i])+"\"") :"";
  2542. thead += "<th id='"+ts.p.id+"_"+ts.p.colModel[i].name+"' role='columnheader' class='ui-state-default ui-th-column ui-th-"+dir+"'"+ tooltip+">";
  2543. idn = ts.p.colModel[i].index || ts.p.colModel[i].name;
  2544. thead += "<div id='jqgh_"+ts.p.id+"_"+ts.p.colModel[i].name+"' "+tdc+">"+ts.p.colNames[i];
  2545. if(!ts.p.colModel[i].width) { ts.p.colModel[i].width = 150; }
  2546. else { ts.p.colModel[i].width = parseInt(ts.p.colModel[i].width,10); }
  2547. if(typeof ts.p.colModel[i].title !== "boolean") { ts.p.colModel[i].title = true; }
  2548. ts.p.colModel[i].lso = "";
  2549. if (idn === ts.p.sortname) {
  2550. ts.p.lastsort = i;
  2551. }
  2552. if(ts.p.multiSort) {
  2553. sotmp = $.inArray(idn,sortarr);
  2554. if( sotmp !== -1 ) {
  2555. ts.p.colModel[i].lso = sortord[sotmp];
  2556. }
  2557. }
  2558. thead += imgs+"</div></th>";
  2559. }
  2560. thead += "</tr></thead>";
  2561. imgs = null;
  2562. $(this).append(thead);
  2563. $("thead tr:first th",this).hover(function(){$(this).addClass('ui-state-hover');},function(){$(this).removeClass('ui-state-hover');});
  2564. if(this.p.multiselect) {
  2565. var emp=[], chk;
  2566. $('#cb_'+$.jgrid.jqID(ts.p.id),this).bind('click',function(){
  2567. ts.p.selarrrow = [];
  2568. var froz = ts.p.frozenColumns === true ? ts.p.id + "_frozen" : "";
  2569. if (this.checked) {
  2570. $(ts.rows).each(function(i) {
  2571. if (i>0) {
  2572. if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass("jqgroup") && !$(this).hasClass('ui-state-disabled') && !$(this).hasClass("jqfoot")){
  2573. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked",true);
  2574. $(this).addClass("ui-state-highlight").attr("aria-selected","true");
  2575. ts.p.selarrrow.push(this.id);
  2576. ts.p.selrow = this.id;
  2577. if(froz) {
  2578. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id), ts.grid.fbDiv )[ts.p.useProp ? 'prop': 'attr']("checked",true);
  2579. $("#"+$.jgrid.jqID(this.id), ts.grid.fbDiv).addClass("ui-state-highlight");
  2580. }
  2581. }
  2582. }
  2583. });
  2584. chk=true;
  2585. emp=[];
  2586. }
  2587. else {
  2588. $(ts.rows).each(function(i) {
  2589. if(i>0) {
  2590. if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass("jqgroup") && !$(this).hasClass('ui-state-disabled') && !$(this).hasClass("jqfoot")){
  2591. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2592. $(this).removeClass("ui-state-highlight").attr("aria-selected","false");
  2593. emp.push(this.id);
  2594. if(froz) {
  2595. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id), ts.grid.fbDiv )[ts.p.useProp ? 'prop': 'attr']("checked",false);
  2596. $("#"+$.jgrid.jqID(this.id), ts.grid.fbDiv).removeClass("ui-state-highlight");
  2597. }
  2598. }
  2599. }
  2600. });
  2601. ts.p.selrow = null;
  2602. chk=false;
  2603. }
  2604. $(ts).triggerHandler("jqGridSelectAll", [chk ? ts.p.selarrrow : emp, chk]);
  2605. if($.isFunction(ts.p.onSelectAll)) {ts.p.onSelectAll.call(ts, chk ? ts.p.selarrrow : emp,chk);}
  2606. });
  2607. }
  2608. if(ts.p.autowidth===true) {
  2609. var pw = $(eg).innerWidth();
  2610. ts.p.width = pw > 0? pw: 'nw';
  2611. }
  2612. setColWidth();
  2613. $(eg).css("width",grid.width+"px").append("<div class='ui-jqgrid-resize-mark' id='rs_m"+ts.p.id+"'>&#160;</div>");
  2614. $(gv).css("width",grid.width+"px");
  2615. thead = $("thead:first",ts).get(0);
  2616. var tfoot = "";
  2617. if(ts.p.footerrow) { tfoot += "<table role='presentation' style='width:"+ts.p.tblwidth+"px' class='ui-jqgrid-ftable' cellspacing='0' cellpadding='0' border='0'><tbody><tr role='row' class='ui-widget-content footrow footrow-"+dir+"'>"; }
  2618. var thr = $("tr:first",thead),
  2619. firstr = "<tr class='jqgfirstrow' role='row' style='height:auto'>";
  2620. ts.p.disableClick=false;
  2621. $("th",thr).each(function ( j ) {
  2622. w = ts.p.colModel[j].width;
  2623. if(ts.p.colModel[j].resizable === undefined) {ts.p.colModel[j].resizable = true;}
  2624. if(ts.p.colModel[j].resizable){
  2625. res = document.createElement("span");
  2626. $(res).html("&#160;").addClass('ui-jqgrid-resize ui-jqgrid-resize-'+dir)
  2627. .css("cursor","col-resize");
  2628. $(this).addClass(ts.p.resizeclass);
  2629. } else {
  2630. res = "";
  2631. }
  2632. $(this).css("width",w+"px").prepend(res);
  2633. res = null;
  2634. var hdcol = "";
  2635. if( ts.p.colModel[j].hidden ) {
  2636. $(this).css("display","none");
  2637. hdcol = "display:none;";
  2638. }
  2639. firstr += "<td role='gridcell' style='height:0px;width:"+w+"px;"+hdcol+"'></td>";
  2640. grid.headers[j] = { width: w, el: this };
  2641. sort = ts.p.colModel[j].sortable;
  2642. if( typeof sort !== 'boolean') {ts.p.colModel[j].sortable = true; sort=true;}
  2643. var nm = ts.p.colModel[j].name;
  2644. if( !(nm === 'cb' || nm==='subgrid' || nm==='rn') ) {
  2645. if(ts.p.viewsortcols[2]){
  2646. $(">div",this).addClass('ui-jqgrid-sortable');
  2647. }
  2648. }
  2649. if(sort) {
  2650. if(ts.p.multiSort) {
  2651. if(ts.p.viewsortcols[0]) {
  2652. $("div span.s-ico",this).show();
  2653. if(ts.p.colModel[j].lso){
  2654. $("div span.ui-icon-"+ts.p.colModel[j].lso,this).removeClass("ui-state-disabled");
  2655. }
  2656. } else if( ts.p.colModel[j].lso) {
  2657. $("div span.s-ico",this).show();
  2658. $("div span.ui-icon-"+ts.p.colModel[j].lso,this).removeClass("ui-state-disabled");
  2659. }
  2660. } else {
  2661. 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");}}
  2662. else if(j === ts.p.lastsort && ts.p.sortname !== "") {$("div span.s-ico",this).show();$("div span.ui-icon-"+ts.p.sortorder,this).removeClass("ui-state-disabled");}
  2663. }
  2664. }
  2665. if(ts.p.footerrow) { tfoot += "<td role='gridcell' "+formatCol(j,0,'', null, '', false)+">&#160;</td>"; }
  2666. }).mousedown(function(e) {
  2667. if ($(e.target).closest("th>span.ui-jqgrid-resize").length !== 1) { return; }
  2668. var ci = getColumnHeaderIndex(this);
  2669. if(ts.p.forceFit===true) {ts.p.nv= nextVisible(ci);}
  2670. grid.dragStart(ci, e, getOffset(ci));
  2671. return false;
  2672. }).click(function(e) {
  2673. if (ts.p.disableClick) {
  2674. ts.p.disableClick = false;
  2675. return false;
  2676. }
  2677. var s = "th>div.ui-jqgrid-sortable",r,d;
  2678. if (!ts.p.viewsortcols[2]) { s = "th>div>span>span.ui-grid-ico-sort"; }
  2679. var t = $(e.target).closest(s);
  2680. if (t.length !== 1) { return; }
  2681. var ci;
  2682. if(ts.p.frozenColumns) {
  2683. var tid = $(this)[0].id.substring( ts.p.id.length + 1 );
  2684. $(ts.p.colModel).each(function(i){
  2685. if (this.name === tid) {
  2686. ci = i;return false;
  2687. }
  2688. });
  2689. } else {
  2690. ci = getColumnHeaderIndex(this);
  2691. }
  2692. if (!ts.p.viewsortcols[2]) { r=true;d=t.attr("sort"); }
  2693. if(ci != null){
  2694. sortData( $('div',this)[0].id, ci, r, d, this);
  2695. }
  2696. return false;
  2697. });
  2698. if (ts.p.sortable && $.fn.sortable) {
  2699. try {
  2700. $(ts).jqGrid("sortableColumns", thr);
  2701. } catch (e){}
  2702. }
  2703. if(ts.p.footerrow) { tfoot += "</tr></tbody></table>"; }
  2704. firstr += "</tr>";
  2705. tbody = document.createElement("tbody");
  2706. this.appendChild(tbody);
  2707. $(this).addClass('ui-jqgrid-btable').append(firstr);
  2708. firstr = null;
  2709. var hTable = $("<table class='ui-jqgrid-htable' style='width:"+ts.p.tblwidth+"px' role='presentation' aria-labelledby='gbox_"+this.id+"' cellspacing='0' cellpadding='0' border='0'></table>").append(thead),
  2710. hg = (ts.p.caption && ts.p.hiddengrid===true) ? true : false,
  2711. hb = $("<div class='ui-jqgrid-hbox" + (dir==="rtl" ? "-rtl" : "" )+"'></div>");
  2712. thead = null;
  2713. grid.hDiv = document.createElement("div");
  2714. $(grid.hDiv)
  2715. .css({ width: grid.width+"px"})
  2716. .addClass("ui-state-default ui-jqgrid-hdiv")
  2717. .append(hb);
  2718. $(hb).append(hTable);
  2719. hTable = null;
  2720. if(hg) { $(grid.hDiv).hide(); }
  2721. if(ts.p.pager){
  2722. // TBD -- escape ts.p.pager here?
  2723. if(typeof ts.p.pager === "string") {if(ts.p.pager.substr(0,1) !== "#") { ts.p.pager = "#"+ts.p.pager;} }
  2724. else { ts.p.pager = "#"+ $(ts.p.pager).attr("id");}
  2725. $(ts.p.pager).css({width: grid.width+"px"}).addClass('ui-state-default ui-jqgrid-pager ui-corner-bottom').appendTo(eg);
  2726. if(hg) {$(ts.p.pager).hide();}
  2727. setPager(ts.p.pager,'');
  2728. }
  2729. if( ts.p.cellEdit === false && ts.p.hoverrows === true) {
  2730. $(ts).bind('mouseover',function(e) {
  2731. ptr = $(e.target).closest("tr.jqgrow");
  2732. if($(ptr).attr("class") !== "ui-subgrid") {
  2733. $(ptr).addClass("ui-state-hover");
  2734. }
  2735. }).bind('mouseout',function(e) {
  2736. ptr = $(e.target).closest("tr.jqgrow");
  2737. $(ptr).removeClass("ui-state-hover");
  2738. });
  2739. }
  2740. var ri,ci, tdHtml;
  2741. $(ts).before(grid.hDiv).click(function(e) {
  2742. td = e.target;
  2743. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2744. if($(ptr).length === 0 || ptr[0].className.indexOf( 'ui-state-disabled' ) > -1 || ($(td,ts).closest("table.ui-jqgrid-btable").attr('id') || '').replace("_frozen","") !== ts.id ) {
  2745. return this;
  2746. }
  2747. var scb = $(td).hasClass("cbox"),
  2748. cSel = $(ts).triggerHandler("jqGridBeforeSelectRow", [ptr[0].id, e]);
  2749. cSel = (cSel === false || cSel === 'stop') ? false : true;
  2750. if ($.isFunction(ts.p.beforeSelectRow)) {
  2751. var allowRowSelect = ts.p.beforeSelectRow.call(ts, ptr[0].id, e);
  2752. if (allowRowSelect === false || allowRowSelect === 'stop') {
  2753. cSel = false;
  2754. }
  2755. }
  2756. if (td.tagName === 'A' || ((td.tagName === 'INPUT' || td.tagName === 'TEXTAREA' || td.tagName === 'OPTION' || td.tagName === 'SELECT' ) && !scb) ) { return; }
  2757. ri = ptr[0].id;
  2758. td = $(td).closest("tr.jqgrow>td");
  2759. if (td.length > 0) {
  2760. ci = $.jgrid.getCellIndex(td);
  2761. tdHtml = $(td).closest("td,th").html();
  2762. $(ts).triggerHandler("jqGridCellSelect", [ri,ci,tdHtml,e]);
  2763. if($.isFunction(ts.p.onCellSelect)) {
  2764. ts.p.onCellSelect.call(ts,ri,ci,tdHtml,e);
  2765. }
  2766. }
  2767. if(ts.p.cellEdit === true) {
  2768. if(ts.p.multiselect && scb && cSel){
  2769. $(ts).jqGrid("setSelection", ri ,true,e);
  2770. } else if (td.length > 0) {
  2771. ri = ptr[0].rowIndex;
  2772. try {$(ts).jqGrid("editCell",ri,ci,true);} catch (_) {}
  2773. }
  2774. }
  2775. if (!cSel) {
  2776. return;
  2777. }
  2778. if ( !ts.p.multikey ) {
  2779. if(ts.p.multiselect && ts.p.multiboxonly) {
  2780. if(scb){$(ts).jqGrid("setSelection",ri,true,e);}
  2781. else {
  2782. var frz = ts.p.frozenColumns ? ts.p.id+"_frozen" : "";
  2783. $(ts.p.selarrrow).each(function(i,n){
  2784. var trid = $(ts).jqGrid('getGridRowById',n);
  2785. if(trid) { $( trid ).removeClass("ui-state-highlight"); }
  2786. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n))[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2787. if(frz) {
  2788. $("#"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(frz)).removeClass("ui-state-highlight");
  2789. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(frz))[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2790. }
  2791. });
  2792. ts.p.selarrrow = [];
  2793. $(ts).jqGrid("setSelection",ri,true,e);
  2794. }
  2795. } else {
  2796. $(ts).jqGrid("setSelection",ri,true,e);
  2797. }
  2798. } else {
  2799. if(e[ts.p.multikey]) {
  2800. $(ts).jqGrid("setSelection",ri,true,e);
  2801. } else if(ts.p.multiselect && scb) {
  2802. scb = $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ri).is(":checked");
  2803. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ri)[ts.p.useProp ? 'prop' : 'attr']("checked", scb);
  2804. }
  2805. }
  2806. }).bind('reloadGrid', function(e,opts) {
  2807. if(ts.p.treeGrid ===true) { ts.p.datatype = ts.p.treedatatype;}
  2808. if (opts && opts.current) {
  2809. ts.grid.selectionPreserver(ts);
  2810. }
  2811. if(ts.p.datatype==="local"){ $(ts).jqGrid("resetSelection"); if(ts.p.data.length) { normalizeData(); refreshIndex();} }
  2812. else if(!ts.p.treeGrid) {
  2813. ts.p.selrow=null;
  2814. if(ts.p.multiselect) {ts.p.selarrrow =[];setHeadCheckBox(false);}
  2815. ts.p.savedRow = [];
  2816. }
  2817. if(ts.p.scroll) {emptyRows.call(ts, true, false);}
  2818. if (opts && opts.page) {
  2819. var page = opts.page;
  2820. if (page > ts.p.lastpage) { page = ts.p.lastpage; }
  2821. if (page < 1) { page = 1; }
  2822. ts.p.page = page;
  2823. if (ts.grid.prevRowHeight) {
  2824. ts.grid.bDiv.scrollTop = (page - 1) * ts.grid.prevRowHeight * ts.p.rowNum;
  2825. } else {
  2826. ts.grid.bDiv.scrollTop = 0;
  2827. }
  2828. }
  2829. if (ts.grid.prevRowHeight && ts.p.scroll) {
  2830. delete ts.p.lastpage;
  2831. ts.grid.populateVisible();
  2832. } else {
  2833. ts.grid.populate();
  2834. }
  2835. if(ts.p._inlinenav===true) {$(ts).jqGrid('showAddEditButtons');}
  2836. return false;
  2837. })
  2838. .dblclick(function(e) {
  2839. td = e.target;
  2840. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2841. if($(ptr).length === 0 ){return;}
  2842. ri = ptr[0].rowIndex;
  2843. ci = $.jgrid.getCellIndex(td);
  2844. var dbcr = $(ts).triggerHandler("jqGridDblClickRow", [$(ptr).attr("id"),ri,ci,e]);
  2845. if( dbcr != null) { return dbcr; }
  2846. if ($.isFunction(ts.p.ondblClickRow)) {
  2847. dbcr = ts.p.ondblClickRow.call(ts,$(ptr).attr("id"),ri,ci, e);
  2848. if( dbcr != null) { return dbcr; }
  2849. }
  2850. })
  2851. .bind('contextmenu', function(e) {
  2852. td = e.target;
  2853. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2854. if($(ptr).length === 0 ){return;}
  2855. if(!ts.p.multiselect) { $(ts).jqGrid("setSelection",ptr[0].id,true,e); }
  2856. ri = ptr[0].rowIndex;
  2857. ci = $.jgrid.getCellIndex(td);
  2858. var rcr = $(ts).triggerHandler("jqGridRightClickRow", [$(ptr).attr("id"),ri,ci,e]);
  2859. if( rcr != null) { return rcr; }
  2860. if ($.isFunction(ts.p.onRightClickRow)) {
  2861. rcr = ts.p.onRightClickRow.call(ts,$(ptr).attr("id"),ri,ci, e);
  2862. if( rcr != null) { return rcr; }
  2863. }
  2864. });
  2865. grid.bDiv = document.createElement("div");
  2866. if(isMSIE) { if(String(ts.p.height).toLowerCase() === "auto") { ts.p.height = "100%"; } }
  2867. $(grid.bDiv)
  2868. .append($('<div style="position:relative;'+(isMSIE && $.jgrid.msiever() < 8 ? "height:0.01%;" : "")+'"></div>').append('<div></div>').append(this))
  2869. .addClass("ui-jqgrid-bdiv")
  2870. .css({ height: ts.p.height+(isNaN(ts.p.height)?"":"px"), width: (grid.width)+"px"})
  2871. .scroll(grid.scrollGrid);
  2872. $("table:first",grid.bDiv).css({width:ts.p.tblwidth+"px"});
  2873. if( !$.support.tbody ) { //IE
  2874. if( $("tbody",this).length === 2 ) { $("tbody:gt(0)",this).remove();}
  2875. }
  2876. if(ts.p.multikey){
  2877. if( $.jgrid.msie) {
  2878. $(grid.bDiv).bind("selectstart",function(){return false;});
  2879. } else {
  2880. $(grid.bDiv).bind("mousedown",function(){return false;});
  2881. }
  2882. }
  2883. if(hg) {$(grid.bDiv).hide();}
  2884. grid.cDiv = document.createElement("div");
  2885. var arf = ts.p.hidegrid===true ? $("<a role='link' class='ui-jqgrid-titlebar-close ui-corner-all HeaderButton' " + (ts.p.showhide ? "title='"+ts.p.showhide+"'" : "")+" />").hover(
  2886. function(){ arf.addClass('ui-state-hover');},
  2887. function() {arf.removeClass('ui-state-hover');})
  2888. .append("<span class='ui-icon ui-icon-circle-triangle-n'></span>").css((dir==="rtl"?"left":"right"),"0px") : "";
  2889. $(grid.cDiv).append(arf).append("<span class='ui-jqgrid-title'>"+ts.p.caption+"</span>")
  2890. .addClass("ui-jqgrid-titlebar ui-jqgrid-caption"+(dir==="rtl" ? "-rtl" :"" )+" ui-widget-header ui-corner-top ui-helper-clearfix");
  2891. $(grid.cDiv).insertBefore(grid.hDiv);
  2892. if( ts.p.toolbar[0] ) {
  2893. grid.uDiv = document.createElement("div");
  2894. if(ts.p.toolbar[1] === "top") {$(grid.uDiv).insertBefore(grid.hDiv);}
  2895. else if (ts.p.toolbar[1]==="bottom" ) {$(grid.uDiv).insertAfter(grid.hDiv);}
  2896. if(ts.p.toolbar[1]==="both") {
  2897. grid.ubDiv = document.createElement("div");
  2898. $(grid.uDiv).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id).insertBefore(grid.hDiv);
  2899. $(grid.ubDiv).addClass("ui-userdata ui-state-default").attr("id","tb_"+this.id).insertAfter(grid.hDiv);
  2900. if(hg) {$(grid.ubDiv).hide();}
  2901. } else {
  2902. $(grid.uDiv).width(grid.width).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id);
  2903. }
  2904. if(hg) {$(grid.uDiv).hide();}
  2905. }
  2906. if(ts.p.toppager) {
  2907. ts.p.toppager = $.jgrid.jqID(ts.p.id)+"_toppager";
  2908. grid.topDiv = $("<div id='"+ts.p.toppager+"'></div>")[0];
  2909. ts.p.toppager = "#"+ts.p.toppager;
  2910. $(grid.topDiv).addClass('ui-state-default ui-jqgrid-toppager').width(grid.width).insertBefore(grid.hDiv);
  2911. setPager(ts.p.toppager,'_t');
  2912. }
  2913. if(ts.p.footerrow) {
  2914. grid.sDiv = $("<div class='ui-jqgrid-sdiv'></div>")[0];
  2915. hb = $("<div class='ui-jqgrid-hbox"+(dir==="rtl"?"-rtl":"")+"'></div>");
  2916. $(grid.sDiv).append(hb).width(grid.width).insertAfter(grid.hDiv);
  2917. $(hb).append(tfoot);
  2918. grid.footers = $(".ui-jqgrid-ftable",grid.sDiv)[0].rows[0].cells;
  2919. if(ts.p.rownumbers) { grid.footers[0].className = 'ui-state-default jqgrid-rownum'; }
  2920. if(hg) {$(grid.sDiv).hide();}
  2921. }
  2922. hb = null;
  2923. if(ts.p.caption) {
  2924. var tdt = ts.p.datatype;
  2925. if(ts.p.hidegrid===true) {
  2926. $(".ui-jqgrid-titlebar-close",grid.cDiv).click( function(e){
  2927. var onHdCl = $.isFunction(ts.p.onHeaderClick),
  2928. elems = ".ui-jqgrid-bdiv, .ui-jqgrid-hdiv, .ui-jqgrid-pager, .ui-jqgrid-sdiv",
  2929. counter, self = this;
  2930. if(ts.p.toolbar[0]===true) {
  2931. if( ts.p.toolbar[1]==='both') {
  2932. elems += ', #' + $(grid.ubDiv).attr('id');
  2933. }
  2934. elems += ', #' + $(grid.uDiv).attr('id');
  2935. }
  2936. counter = $(elems,"#gview_"+$.jgrid.jqID(ts.p.id)).length;
  2937. if(ts.p.gridstate === 'visible') {
  2938. $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideUp("fast", function() {
  2939. counter--;
  2940. if (counter === 0) {
  2941. $("span",self).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s");
  2942. ts.p.gridstate = 'hidden';
  2943. if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).hide(); }
  2944. $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate,e]);
  2945. if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}}
  2946. }
  2947. });
  2948. } else if(ts.p.gridstate === 'hidden'){
  2949. $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideDown("fast", function() {
  2950. counter--;
  2951. if (counter === 0) {
  2952. $("span",self).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n");
  2953. if(hg) {ts.p.datatype = tdt;populate();hg=false;}
  2954. ts.p.gridstate = 'visible';
  2955. if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).show(); }
  2956. $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate,e]);
  2957. if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}}
  2958. }
  2959. });
  2960. }
  2961. return false;
  2962. });
  2963. if(hg) {ts.p.datatype="local"; $(".ui-jqgrid-titlebar-close",grid.cDiv).trigger("click");}
  2964. }
  2965. } else {
  2966. $(grid.cDiv).hide();
  2967. $(grid.hDiv).addClass('ui-corner-top');
  2968. }
  2969. $(grid.hDiv).after(grid.bDiv)
  2970. .mousemove(function (e) {
  2971. if(grid.resizing){grid.dragMove(e);return false;}
  2972. });
  2973. $(".ui-jqgrid-labels",grid.hDiv).bind("selectstart", function () { return false; });
  2974. $(document).bind( "mouseup.jqGrid" + ts.p.id, function () {
  2975. if(grid.resizing) { grid.dragEnd(); return false;}
  2976. return true;
  2977. });
  2978. ts.formatCol = formatCol;
  2979. ts.sortData = sortData;
  2980. ts.updatepager = updatepager;
  2981. ts.refreshIndex = refreshIndex;
  2982. ts.setHeadCheckBox = setHeadCheckBox;
  2983. ts.constructTr = constructTr;
  2984. ts.formatter = function ( rowId, cellval , colpos, rwdat, act){return formatter(rowId, cellval , colpos, rwdat, act);};
  2985. $.extend(grid,{populate : populate, emptyRows: emptyRows, beginReq: beginReq, endReq: endReq});
  2986. this.grid = grid;
  2987. ts.addXmlData = function(d) {addXmlData(d,ts.grid.bDiv);};
  2988. ts.addJSONData = function(d) {addJSONData(d,ts.grid.bDiv);};
  2989. this.grid.cols = this.rows[0].cells;
  2990. $(ts).triggerHandler("jqGridInitGrid");
  2991. if ($.isFunction( ts.p.onInitGrid )) { ts.p.onInitGrid.call(ts); }
  2992. populate();ts.p.hiddengrid=false;
  2993. });
  2994. };
  2995. $.jgrid.extend({
  2996. getGridParam : function(pName) {
  2997. var $t = this[0];
  2998. if (!$t || !$t.grid) {return;}
  2999. if (!pName) { return $t.p; }
  3000. return $t.p[pName] !== undefined ? $t.p[pName] : null;
  3001. },
  3002. setGridParam : function (newParams, overwrite){
  3003. return this.each(function(){
  3004. if(overwrite == null) {
  3005. overwrite = false;
  3006. }
  3007. if (this.grid && typeof newParams === 'object') {
  3008. if(overwrite === true) {
  3009. var params = $.extend({}, this.p, newParams);
  3010. this.p = params;
  3011. } else {
  3012. $.extend(true,this.p,newParams);
  3013. }
  3014. }
  3015. });
  3016. },
  3017. getGridRowById: function ( rowid ) {
  3018. var row;
  3019. this.each( function(){
  3020. try {
  3021. //row = this.rows.namedItem( rowid );
  3022. var i = this.rows.length;
  3023. while(i--) {
  3024. if( rowid.toString() === this.rows[i].id) {
  3025. row = this.rows[i];
  3026. break;
  3027. }
  3028. }
  3029. } catch ( e ) {
  3030. row = $(this.grid.bDiv).find( "#" + $.jgrid.jqID( rowid ));
  3031. }
  3032. });
  3033. return row;
  3034. },
  3035. getDataIDs : function () {
  3036. var ids=[], i=0, len, j=0;
  3037. this.each(function(){
  3038. len = this.rows.length;
  3039. if(len && len>0){
  3040. while(i<len) {
  3041. if($(this.rows[i]).hasClass('jqgrow')) {
  3042. ids[j] = this.rows[i].id;
  3043. j++;
  3044. }
  3045. i++;
  3046. }
  3047. }
  3048. });
  3049. return ids;
  3050. },
  3051. setSelection : function(selection,onsr, e) {
  3052. return this.each(function(){
  3053. var $t = this, stat,pt, ner, ia, tpsr, fid, csr;
  3054. if(selection === undefined) { return; }
  3055. onsr = onsr === false ? false : true;
  3056. pt=$($t).jqGrid('getGridRowById', selection);
  3057. if(!pt || !pt.className || pt.className.indexOf( 'ui-state-disabled' ) > -1 ) { return; }
  3058. function scrGrid(iR){
  3059. var ch = $($t.grid.bDiv)[0].clientHeight,
  3060. st = $($t.grid.bDiv)[0].scrollTop,
  3061. rpos = $($t.rows[iR]).position().top,
  3062. rh = $t.rows[iR].clientHeight;
  3063. if(rpos+rh >= ch+st) { $($t.grid.bDiv)[0].scrollTop = rpos-(ch+st)+rh+st; }
  3064. else if(rpos < ch+st) {
  3065. if(rpos < st) {
  3066. $($t.grid.bDiv)[0].scrollTop = rpos;
  3067. }
  3068. }
  3069. }
  3070. if($t.p.scrollrows===true) {
  3071. ner = $($t).jqGrid('getGridRowById',selection).rowIndex;
  3072. if(ner >=0 ){
  3073. scrGrid(ner);
  3074. }
  3075. }
  3076. if($t.p.frozenColumns === true ) {
  3077. fid = $t.p.id+"_frozen";
  3078. }
  3079. if(!$t.p.multiselect) {
  3080. if(pt.className !== "ui-subgrid") {
  3081. if( $t.p.selrow !== pt.id ) {
  3082. csr = $($t).jqGrid('getGridRowById', $t.p.selrow);
  3083. if( csr ) {
  3084. $( csr ).removeClass("ui-state-highlight").attr({"aria-selected":"false", "tabindex" : "-1"});
  3085. }
  3086. $(pt).addClass("ui-state-highlight").attr({"aria-selected":"true", "tabindex" : "0"});//.focus();
  3087. if(fid) {
  3088. $("#"+$.jgrid.jqID($t.p.selrow), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight");
  3089. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).addClass("ui-state-highlight");
  3090. }
  3091. stat = true;
  3092. } else {
  3093. stat = false;
  3094. }
  3095. $t.p.selrow = pt.id;
  3096. if( onsr ) {
  3097. $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]);
  3098. if( $t.p.onSelectRow) { $t.p.onSelectRow.call($t, pt.id, stat, e); }
  3099. }
  3100. }
  3101. } else {
  3102. //unselect selectall checkbox when deselecting a specific row
  3103. $t.setHeadCheckBox( false );
  3104. $t.p.selrow = pt.id;
  3105. ia = $.inArray($t.p.selrow,$t.p.selarrrow);
  3106. if ( ia === -1 ){
  3107. if(pt.className !== "ui-subgrid") { $(pt).addClass("ui-state-highlight").attr("aria-selected","true");}
  3108. stat = true;
  3109. $t.p.selarrrow.push($t.p.selrow);
  3110. } else {
  3111. if(pt.className !== "ui-subgrid") { $(pt).removeClass("ui-state-highlight").attr("aria-selected","false");}
  3112. stat = false;
  3113. $t.p.selarrrow.splice(ia,1);
  3114. tpsr = $t.p.selarrrow[0];
  3115. $t.p.selrow = (tpsr === undefined) ? null : tpsr;
  3116. }
  3117. $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(pt.id))[$t.p.useProp ? 'prop': 'attr']("checked",stat);
  3118. if(fid) {
  3119. if(ia === -1) {
  3120. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).addClass("ui-state-highlight");
  3121. } else {
  3122. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight");
  3123. }
  3124. $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid))[$t.p.useProp ? 'prop': 'attr']("checked",stat);
  3125. }
  3126. if( onsr ) {
  3127. $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]);
  3128. if( $t.p.onSelectRow) { $t.p.onSelectRow.call($t, pt.id , stat, e); }
  3129. }
  3130. }
  3131. });
  3132. },
  3133. resetSelection : function( rowid ){
  3134. return this.each(function(){
  3135. var t = this, sr, fid;
  3136. if( t.p.frozenColumns === true ) {
  3137. fid = t.p.id+"_frozen";
  3138. }
  3139. if(rowid !== undefined ) {
  3140. sr = rowid === t.p.selrow ? t.p.selrow : rowid;
  3141. $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(sr)).removeClass("ui-state-highlight").attr("aria-selected","false");
  3142. if (fid) { $("#"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); }
  3143. if(t.p.multiselect) {
  3144. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(t.p.id))[t.p.useProp ? 'prop': 'attr']("checked",false);
  3145. if(fid) { $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(fid))[t.p.useProp ? 'prop': 'attr']("checked",false); }
  3146. t.setHeadCheckBox( false);
  3147. var ia = $.inArray($.jgrid.jqID(sr), t.p.selarrrow);
  3148. if ( ia !== -1 ){
  3149. t.p.selarrrow.splice(ia,1);
  3150. }
  3151. }
  3152. sr = null;
  3153. } else if(!t.p.multiselect) {
  3154. if(t.p.selrow) {
  3155. $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(t.p.selrow)).removeClass("ui-state-highlight").attr("aria-selected","false");
  3156. if(fid) { $("#"+$.jgrid.jqID(t.p.selrow), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); }
  3157. t.p.selrow = null;
  3158. }
  3159. } else {
  3160. $(t.p.selarrrow).each(function(i,n){
  3161. $( $(t).jqGrid('getGridRowById',n) ).removeClass("ui-state-highlight").attr("aria-selected","false");
  3162. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n))[t.p.useProp ? 'prop': 'attr']("checked",false);
  3163. if(fid) {
  3164. $("#"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight");
  3165. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(fid))[t.p.useProp ? 'prop': 'attr']("checked",false);
  3166. }
  3167. });
  3168. t.setHeadCheckBox( false );
  3169. t.p.selarrrow = [];
  3170. t.p.selrow = null;
  3171. }
  3172. if(t.p.cellEdit === true) {
  3173. if(parseInt(t.p.iCol,10)>=0 && parseInt(t.p.iRow,10)>=0) {
  3174. $("td:eq("+t.p.iCol+")",t.rows[t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  3175. $(t.rows[t.p.iRow]).removeClass("selected-row ui-state-hover");
  3176. }
  3177. }
  3178. t.p.savedRow = [];
  3179. });
  3180. },
  3181. getRowData : function( rowid ) {
  3182. var res = {}, resall, getall=false, len, j=0;
  3183. this.each(function(){
  3184. var $t = this,nm,ind;
  3185. if(rowid === undefined) {
  3186. getall = true;
  3187. resall = [];
  3188. len = $t.rows.length;
  3189. } else {
  3190. ind = $($t).jqGrid('getGridRowById', rowid);
  3191. if(!ind) { return res; }
  3192. len = 2;
  3193. }
  3194. while(j<len){
  3195. if(getall) { ind = $t.rows[j]; }
  3196. if( $(ind).hasClass('jqgrow') ) {
  3197. $('td[role="gridcell"]',ind).each( function(i) {
  3198. nm = $t.p.colModel[i].name;
  3199. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  3200. if($t.p.treeGrid===true && nm === $t.p.ExpandColumn) {
  3201. res[nm] = $.jgrid.htmlDecode($("span:first",this).html());
  3202. } else {
  3203. try {
  3204. res[nm] = $.unformat.call($t,this,{rowId:ind.id, colModel:$t.p.colModel[i]},i);
  3205. } catch (e){
  3206. res[nm] = $.jgrid.htmlDecode($(this).html());
  3207. }
  3208. }
  3209. }
  3210. });
  3211. if(getall) { resall.push(res); res={}; }
  3212. }
  3213. j++;
  3214. }
  3215. });
  3216. return resall || res;
  3217. },
  3218. delRowData : function(rowid) {
  3219. var success = false, rowInd, ia, nextRow;
  3220. this.each(function() {
  3221. var $t = this;
  3222. rowInd = $($t).jqGrid('getGridRowById', rowid);
  3223. if(!rowInd) {return false;}
  3224. if($t.p.subGrid) {
  3225. nextRow = $(rowInd).next();
  3226. if(nextRow.hasClass('ui-subgrid')) {
  3227. nextRow.remove();
  3228. }
  3229. }
  3230. $(rowInd).remove();
  3231. $t.p.records--;
  3232. $t.p.reccount--;
  3233. $t.updatepager(true,false);
  3234. success=true;
  3235. if($t.p.multiselect) {
  3236. ia = $.inArray(rowid,$t.p.selarrrow);
  3237. if(ia !== -1) { $t.p.selarrrow.splice(ia,1);}
  3238. }
  3239. if ($t.p.multiselect && $t.p.selarrrow.length > 0) {
  3240. $t.p.selrow = $t.p.selarrrow[$t.p.selarrrow.length-1];
  3241. } else {
  3242. $t.p.selrow = null;
  3243. }
  3244. if($t.p.datatype === 'local') {
  3245. var id = $.jgrid.stripPref($t.p.idPrefix, rowid),
  3246. pos = $t.p._index[id];
  3247. if(pos !== undefined) {
  3248. $t.p.data.splice(pos,1);
  3249. $t.refreshIndex();
  3250. }
  3251. }
  3252. if( $t.p.altRows === true && success ) {
  3253. var cn = $t.p.altclass;
  3254. $($t.rows).each(function(i){
  3255. if(i % 2 === 1) { $(this).addClass(cn); }
  3256. else { $(this).removeClass(cn); }
  3257. });
  3258. }
  3259. });
  3260. return success;
  3261. },
  3262. setRowData : function(rowid, data, cssp) {
  3263. var nm, success=true, title;
  3264. this.each(function(){
  3265. if(!this.grid) {return false;}
  3266. var t = this, vl, ind, cp = typeof cssp, lcdata={};
  3267. ind = $(this).jqGrid('getGridRowById', rowid);
  3268. if(!ind) { return false; }
  3269. if( data ) {
  3270. try {
  3271. $(this.p.colModel).each(function(i){
  3272. nm = this.name;
  3273. var dval =$.jgrid.getAccessor(data,nm);
  3274. if( dval !== undefined) {
  3275. lcdata[nm] = this.formatter && typeof this.formatter === 'string' && this.formatter === 'date' ? $.unformat.date.call(t,dval,this) : dval;
  3276. vl = t.formatter( rowid, lcdata[nm], i, data, 'edit');
  3277. title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
  3278. if(t.p.treeGrid===true && nm === t.p.ExpandColumn) {
  3279. $("td[role='gridcell']:eq("+i+") > span:first",ind).html(vl).attr(title);
  3280. } else {
  3281. $("td[role='gridcell']:eq("+i+")",ind).html(vl).attr(title);
  3282. }
  3283. }
  3284. });
  3285. if(t.p.datatype === 'local') {
  3286. var id = $.jgrid.stripPref(t.p.idPrefix, rowid),
  3287. pos = t.p._index[id], key;
  3288. if(t.p.treeGrid) {
  3289. for(key in t.p.treeReader){
  3290. if(t.p.treeReader.hasOwnProperty(key)) {
  3291. delete lcdata[t.p.treeReader[key]];
  3292. }
  3293. }
  3294. }
  3295. if(pos !== undefined) {
  3296. t.p.data[pos] = $.extend(true, t.p.data[pos], lcdata);
  3297. }
  3298. lcdata = null;
  3299. }
  3300. } catch (e) {
  3301. success = false;
  3302. }
  3303. }
  3304. if(success) {
  3305. if(cp === 'string') {$(ind).addClass(cssp);} else if(cssp !== null && cp === 'object') {$(ind).css(cssp);}
  3306. $(t).triggerHandler("jqGridAfterGridComplete");
  3307. }
  3308. });
  3309. return success;
  3310. },
  3311. addRowData : function(rowid,rdata,pos,src) {
  3312. if(["first", "last", "before", "after"].indexOf(pos) == -1) {pos = "last";}
  3313. var success = false, nm, row, gi, si, ni,sind, i, v, prp="", aradd, cnm, cn, data, cm, id;
  3314. if(rdata) {
  3315. if($.isArray(rdata)) {
  3316. aradd=true;
  3317. //pos = "last";
  3318. cnm = rowid;
  3319. } else {
  3320. rdata = [rdata];
  3321. aradd = false;
  3322. }
  3323. this.each(function() {
  3324. var t = this, datalen = rdata.length;
  3325. ni = t.p.rownumbers===true ? 1 :0;
  3326. gi = t.p.multiselect ===true ? 1 :0;
  3327. si = t.p.subGrid===true ? 1 :0;
  3328. if(!aradd) {
  3329. if(rowid !== undefined) { rowid = String(rowid);}
  3330. else {
  3331. rowid = $.jgrid.randId();
  3332. if(t.p.keyName !== false) {
  3333. cnm = t.p.keyName;
  3334. if(rdata[0][cnm] !== undefined) { rowid = rdata[0][cnm]; }
  3335. }
  3336. }
  3337. }
  3338. cn = t.p.altclass;
  3339. var k = 0, cna ="", lcdata = {},
  3340. air = $.isFunction(t.p.afterInsertRow) ? true : false;
  3341. while(k < datalen) {
  3342. data = rdata[k];
  3343. row=[];
  3344. if(aradd) {
  3345. try {
  3346. rowid = data[cnm];
  3347. if(rowid===undefined) {
  3348. rowid = $.jgrid.randId();
  3349. }
  3350. }
  3351. catch (e) {rowid = $.jgrid.randId();}
  3352. cna = t.p.altRows === true ? (t.rows.length-1)%2 === 0 ? cn : "" : "";
  3353. }
  3354. id = rowid;
  3355. rowid = t.p.idPrefix + rowid;
  3356. if(ni){
  3357. prp = t.formatCol(0,1,'',null,rowid, true);
  3358. row[row.length] = "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" "+prp+">0</td>";
  3359. }
  3360. if(gi) {
  3361. v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+t.p.id+"_"+rowid+"\" class=\"cbox\"/>";
  3362. prp = t.formatCol(ni,1,'', null, rowid, true);
  3363. row[row.length] = "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  3364. }
  3365. if(si) {
  3366. row[row.length] = $(t).jqGrid("addSubGridCell",gi+ni,1);
  3367. }
  3368. for(i = gi+si+ni; i < t.p.colModel.length;i++){
  3369. cm = t.p.colModel[i];
  3370. nm = cm.name;
  3371. lcdata[nm] = data[nm];
  3372. v = t.formatter( rowid, $.jgrid.getAccessor(data,nm), i, data );
  3373. prp = t.formatCol(i,1,v, data, rowid, lcdata);
  3374. row[row.length] = "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  3375. }
  3376. row.unshift( t.constructTr(rowid, false, cna, lcdata, data, false ) );
  3377. row[row.length] = "</tr>";
  3378. if(t.rows.length === 0){
  3379. $("table:first",t.grid.bDiv).append(row.join(''));
  3380. } else {
  3381. switch (pos) {
  3382. case 'last':
  3383. $(t.rows[t.rows.length-1]).after(row.join(''));
  3384. sind = t.rows.length-1;
  3385. break;
  3386. case 'first':
  3387. $(t.rows[0]).after(row.join(''));
  3388. sind = 1;
  3389. break;
  3390. case 'after':
  3391. sind = $(t).jqGrid('getGridRowById', src);
  3392. if (sind) {
  3393. if($(t.rows[sind.rowIndex+1]).hasClass("ui-subgrid")) { $(t.rows[sind.rowIndex+1]).after(row); }
  3394. else { $(sind).after(row.join('')); }
  3395. sind=sind.rowIndex + 1;
  3396. }
  3397. break;
  3398. case 'before':
  3399. sind = $(t).jqGrid('getGridRowById', src);
  3400. if(sind) {
  3401. $(sind).before(row.join(''));
  3402. sind=sind.rowIndex - 1;
  3403. }
  3404. break;
  3405. }
  3406. }
  3407. if(t.p.subGrid===true) {
  3408. $(t).jqGrid("addSubGrid",gi+ni, sind);
  3409. }
  3410. t.p.records++;
  3411. t.p.reccount++;
  3412. $(t).triggerHandler("jqGridAfterInsertRow", [rowid,data,data]);
  3413. if(air) { t.p.afterInsertRow.call(t,rowid,data,data); }
  3414. k++;
  3415. if(t.p.datatype === 'local') {
  3416. lcdata[t.p.localReader.id] = id;
  3417. t.p._index[id] = t.p.data.length;
  3418. t.p.data.push(lcdata);
  3419. lcdata = {};
  3420. }
  3421. }
  3422. if( t.p.altRows === true && !aradd) {
  3423. if (pos === "last") {
  3424. if ((t.rows.length-1)%2 === 1) {$(t.rows[t.rows.length-1]).addClass(cn);}
  3425. } else {
  3426. $(t.rows).each(function(i){
  3427. if(i % 2 ===1) { $(this).addClass(cn); }
  3428. else { $(this).removeClass(cn); }
  3429. });
  3430. }
  3431. }
  3432. t.updatepager(true,true);
  3433. success = true;
  3434. });
  3435. }
  3436. return success;
  3437. },
  3438. footerData : function(action,data, format) {
  3439. var nm, success=false, res={}, title;
  3440. function isEmpty(obj) {
  3441. var i;
  3442. for(i in obj) {
  3443. if (obj.hasOwnProperty(i)) { return false; }
  3444. }
  3445. return true;
  3446. }
  3447. if(action == undefined) { action = "get"; }
  3448. if(typeof format !== "boolean") { format = true; }
  3449. action = action.toLowerCase();
  3450. this.each(function(){
  3451. var t = this, vl;
  3452. if(!t.grid || !t.p.footerrow) {return false;}
  3453. if(action === "set") { if(isEmpty(data)) { return false; } }
  3454. success=true;
  3455. $(this.p.colModel).each(function(i){
  3456. nm = this.name;
  3457. if(action === "set") {
  3458. if( data[nm] !== undefined) {
  3459. vl = format ? t.formatter( "", data[nm], i, data, 'edit') : data[nm];
  3460. title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
  3461. $("tr.footrow td:eq("+i+")",t.grid.sDiv).html(vl).attr(title);
  3462. success = true;
  3463. }
  3464. } else if(action === "get") {
  3465. res[nm] = $("tr.footrow td:eq("+i+")",t.grid.sDiv).html();
  3466. }
  3467. });
  3468. });
  3469. return action === "get" ? res : success;
  3470. },
  3471. showHideCol : function(colname,show) {
  3472. return this.each(function() {
  3473. var $t = this, fndh=false, brd=$.jgrid.cell_width ? 0: $t.p.cellLayout, cw;
  3474. if (!$t.grid ) {return;}
  3475. if( typeof colname === 'string') {colname=[colname];}
  3476. show = show !== "none" ? "" : "none";
  3477. var sw = show === "" ? true :false,
  3478. gh = $t.p.groupHeader && (typeof $t.p.groupHeader === 'object' || $.isFunction($t.p.groupHeader) );
  3479. if(gh) { $($t).jqGrid('destroyGroupHeader', false); }
  3480. $(this.p.colModel).each(function(i) {
  3481. if ($.inArray(this.name,colname) !== -1 && this.hidden === sw) {
  3482. if($t.p.frozenColumns === true && this.frozen === true) {
  3483. return true;
  3484. }
  3485. $("tr[role=row]",$t.grid.hDiv).each(function(){
  3486. $(this.cells[i]).css("display", show);
  3487. });
  3488. $($t.rows).each(function(){
  3489. if (!$(this).hasClass("jqgroup")) {
  3490. $(this.cells[i]).css("display", show);
  3491. }
  3492. });
  3493. if($t.p.footerrow) { $("tr.footrow td:eq("+i+")", $t.grid.sDiv).css("display", show); }
  3494. cw = parseInt(this.width,10);
  3495. if(show === "none") {
  3496. $t.p.tblwidth -= cw+brd;
  3497. } else {
  3498. $t.p.tblwidth += cw+brd;
  3499. }
  3500. this.hidden = !sw;
  3501. fndh=true;
  3502. $($t).triggerHandler("jqGridShowHideCol", [sw,this.name,i]);
  3503. }
  3504. });
  3505. if(fndh===true) {
  3506. if($t.p.shrinkToFit === true && !isNaN($t.p.height)) { $t.p.tblwidth += parseInt($t.p.scrollOffset,10);}
  3507. $($t).jqGrid("setGridWidth",$t.p.shrinkToFit === true ? $t.p.tblwidth : $t.p.width );
  3508. }
  3509. if( gh ) {
  3510. $($t).jqGrid('setGroupHeaders',$t.p.groupHeader);
  3511. }
  3512. });
  3513. },
  3514. hideCol : function (colname) {
  3515. return this.each(function(){$(this).jqGrid("showHideCol",colname,"none");});
  3516. },
  3517. showCol : function(colname) {
  3518. return this.each(function(){$(this).jqGrid("showHideCol",colname,"");});
  3519. },
  3520. remapColumns : function(permutation, updateCells, keepHeader)
  3521. {
  3522. function resortArray(a) {
  3523. var ac;
  3524. if (a.length) {
  3525. ac = $.makeArray(a);
  3526. } else {
  3527. ac = $.extend({}, a);
  3528. }
  3529. $.each(permutation, function(i) {
  3530. a[i] = ac[this];
  3531. });
  3532. }
  3533. var ts = this.get(0);
  3534. function resortRows(parent, clobj) {
  3535. $(">tr"+(clobj||""), parent).each(function() {
  3536. var row = this;
  3537. var elems = $.makeArray(row.cells);
  3538. $.each(permutation, function() {
  3539. var e = elems[this];
  3540. if (e) {
  3541. row.appendChild(e);
  3542. }
  3543. });
  3544. });
  3545. }
  3546. resortArray(ts.p.colModel);
  3547. resortArray(ts.p.colNames);
  3548. resortArray(ts.grid.headers);
  3549. resortRows($("thead:first", ts.grid.hDiv), keepHeader && ":not(.ui-jqgrid-labels)");
  3550. if (updateCells) {
  3551. resortRows($("#"+$.jgrid.jqID(ts.p.id)+" tbody:first"), ".jqgfirstrow, tr.jqgrow, tr.jqfoot");
  3552. }
  3553. if (ts.p.footerrow) {
  3554. resortRows($("tbody:first", ts.grid.sDiv));
  3555. }
  3556. if (ts.p.remapColumns) {
  3557. if (!ts.p.remapColumns.length){
  3558. ts.p.remapColumns = $.makeArray(permutation);
  3559. } else {
  3560. resortArray(ts.p.remapColumns);
  3561. }
  3562. }
  3563. ts.p.lastsort = $.inArray(ts.p.lastsort, permutation);
  3564. if(ts.p.treeGrid) { ts.p.expColInd = $.inArray(ts.p.expColInd, permutation); }
  3565. $(ts).triggerHandler("jqGridRemapColumns", [permutation, updateCells, keepHeader]);
  3566. },
  3567. setGridWidth : function(nwidth, shrink) {
  3568. return this.each(function(){
  3569. if (!this.grid ) {return;}
  3570. var $t = this, cw,
  3571. initwidth = 0, brd=$.jgrid.cell_width ? 0: $t.p.cellLayout, lvc, vc=0, hs=false, scw=$t.p.scrollOffset, aw, gw=0, cr;
  3572. if(typeof shrink !== 'boolean') {
  3573. shrink=$t.p.shrinkToFit;
  3574. }
  3575. if(isNaN(nwidth)) {return;}
  3576. nwidth = parseInt(nwidth,10);
  3577. $t.grid.width = $t.p.width = nwidth;
  3578. $("#gbox_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px");
  3579. $("#gview_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px");
  3580. $($t.grid.bDiv).css("width",nwidth+"px");
  3581. $($t.grid.hDiv).css("width",nwidth+"px");
  3582. if($t.p.pager ) {$($t.p.pager).css("width",nwidth+"px");}
  3583. if($t.p.toppager ) {$($t.p.toppager).css("width",nwidth+"px");}
  3584. if($t.p.toolbar[0] === true){
  3585. $($t.grid.uDiv).css("width",nwidth+"px");
  3586. if($t.p.toolbar[1]==="both") {$($t.grid.ubDiv).css("width",nwidth+"px");}
  3587. }
  3588. if($t.p.footerrow) { $($t.grid.sDiv).css("width",nwidth+"px"); }
  3589. if(shrink ===false && $t.p.forceFit === true) {$t.p.forceFit=false;}
  3590. if(shrink===true) {
  3591. $.each($t.p.colModel, function() {
  3592. if(this.hidden===false){
  3593. cw = this.widthOrg;
  3594. initwidth += cw+brd;
  3595. if(this.fixed) {
  3596. gw += cw+brd;
  3597. } else {
  3598. vc++;
  3599. }
  3600. }
  3601. });
  3602. if(vc === 0) { return; }
  3603. $t.p.tblwidth = initwidth;
  3604. aw = nwidth-brd*vc-gw;
  3605. if(!isNaN($t.p.height)) {
  3606. if($($t.grid.bDiv)[0].clientHeight < $($t.grid.bDiv)[0].scrollHeight || $t.rows.length === 1){
  3607. hs = true;
  3608. aw -= scw;
  3609. }
  3610. }
  3611. initwidth =0;
  3612. var cle = $t.grid.cols.length >0;
  3613. $.each($t.p.colModel, function(i) {
  3614. if(this.hidden === false && !this.fixed){
  3615. cw = this.widthOrg;
  3616. cw = Math.round(aw*cw/($t.p.tblwidth-brd*vc-gw));
  3617. if (cw < 0) { return; }
  3618. this.width =cw;
  3619. initwidth += cw;
  3620. $t.grid.headers[i].width=cw;
  3621. $t.grid.headers[i].el.style.width=cw+"px";
  3622. if($t.p.footerrow) { $t.grid.footers[i].style.width = cw+"px"; }
  3623. if(cle) { $t.grid.cols[i].style.width = cw+"px"; }
  3624. lvc = i;
  3625. }
  3626. });
  3627. if (!lvc) { return; }
  3628. cr =0;
  3629. if (hs) {
  3630. if(nwidth-gw-(initwidth+brd*vc) !== scw){
  3631. cr = nwidth-gw-(initwidth+brd*vc)-scw;
  3632. }
  3633. } else if( Math.abs(nwidth-gw-(initwidth+brd*vc)) !== 1) {
  3634. cr = nwidth-gw-(initwidth+brd*vc);
  3635. }
  3636. $t.p.colModel[lvc].width += cr;
  3637. $t.p.tblwidth = initwidth+cr+brd*vc+gw;
  3638. if($t.p.tblwidth > nwidth) {
  3639. var delta = $t.p.tblwidth - parseInt(nwidth,10);
  3640. $t.p.tblwidth = nwidth;
  3641. cw = $t.p.colModel[lvc].width = $t.p.colModel[lvc].width-delta;
  3642. } else {
  3643. cw= $t.p.colModel[lvc].width;
  3644. }
  3645. $t.grid.headers[lvc].width = cw;
  3646. $t.grid.headers[lvc].el.style.width=cw+"px";
  3647. if(cle) { $t.grid.cols[lvc].style.width = cw+"px"; }
  3648. if($t.p.footerrow) {
  3649. $t.grid.footers[lvc].style.width = cw+"px";
  3650. }
  3651. }
  3652. if($t.p.tblwidth) {
  3653. $('table:first',$t.grid.bDiv).css("width",$t.p.tblwidth+"px");
  3654. $('table:first',$t.grid.hDiv).css("width",$t.p.tblwidth+"px");
  3655. $t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft;
  3656. if($t.p.footerrow) {
  3657. $('table:first',$t.grid.sDiv).css("width",$t.p.tblwidth+"px");
  3658. }
  3659. }
  3660. });
  3661. },
  3662. setGridHeight : function (nh) {
  3663. return this.each(function (){
  3664. var $t = this;
  3665. if(!$t.grid) {return;}
  3666. var bDiv = $($t.grid.bDiv);
  3667. bDiv.css({height: nh+(isNaN(nh)?"":"px")});
  3668. if($t.p.frozenColumns === true){
  3669. //follow the original set height to use 16, better scrollbar width detection
  3670. $('#'+$.jgrid.jqID($t.p.id)+"_frozen").parent().height(bDiv.height() - 16);
  3671. }
  3672. $t.p.height = nh;
  3673. if ($t.p.scroll) { $t.grid.populateVisible(); }
  3674. });
  3675. },
  3676. setCaption : function (newcap){
  3677. return this.each(function(){
  3678. this.p.caption=newcap;
  3679. $("span.ui-jqgrid-title, span.ui-jqgrid-title-rtl",this.grid.cDiv).html(newcap);
  3680. $(this.grid.cDiv).show();
  3681. $(this.grid.hDiv).removeClass('ui-corner-top');
  3682. });
  3683. },
  3684. setLabel : function(colname, nData, prop, attrp ){
  3685. return this.each(function(){
  3686. var $t = this, pos=-1;
  3687. if(!$t.grid) {return;}
  3688. if(colname !== undefined) {
  3689. $($t.p.colModel).each(function(i){
  3690. if (this.name === colname) {
  3691. pos = i;return false;
  3692. }
  3693. });
  3694. } else { return; }
  3695. if(pos>=0) {
  3696. var thecol = $("tr.ui-jqgrid-labels th:eq("+pos+")",$t.grid.hDiv);
  3697. if (nData){
  3698. var ico = $(".s-ico",thecol);
  3699. $("[id^=jqgh_]",thecol).empty().html(nData).append(ico);
  3700. $t.p.colNames[pos] = nData;
  3701. }
  3702. if (prop) {
  3703. if(typeof prop === 'string') {$(thecol).addClass(prop);} else {$(thecol).css(prop);}
  3704. }
  3705. if(typeof attrp === 'object') {$(thecol).attr(attrp);}
  3706. }
  3707. });
  3708. },
  3709. setCell : function(rowid,colname,nData,cssp,attrp, forceupd) {
  3710. return this.each(function(){
  3711. var $t = this, pos =-1,v, title;
  3712. if(!$t.grid) {return;}
  3713. if(isNaN(colname)) {
  3714. $($t.p.colModel).each(function(i){
  3715. if (this.name === colname) {
  3716. pos = i;return false;
  3717. }
  3718. });
  3719. } else {pos = parseInt(colname,10);}
  3720. if(pos>=0) {
  3721. var ind = $($t).jqGrid('getGridRowById', rowid);
  3722. if (ind){
  3723. var tcell = $("td:eq("+pos+")",ind), cl=0, rawdat=[];
  3724. if(nData !== "" || forceupd === true) {
  3725. while(cl<ind.cells.length) {
  3726. // slow down speed
  3727. rawdat.push(ind.cells[cl].innerHTML);
  3728. cl++;
  3729. }
  3730. v = $t.formatter(rowid, nData, pos, rawdat, 'edit');
  3731. title = $t.p.colModel[pos].title ? {"title":$.jgrid.stripHtml(v)} : {};
  3732. if($t.p.treeGrid && $(".tree-wrap",$(tcell)).length>0) {
  3733. $("span",$(tcell)).html(v).attr(title);
  3734. } else {
  3735. $(tcell).html(v).attr(title);
  3736. }
  3737. if($t.p.datatype === "local") {
  3738. var cm = $t.p.colModel[pos], index;
  3739. nData = cm.formatter && typeof cm.formatter === 'string' && cm.formatter === 'date' ? $.unformat.date.call($t,nData,cm) : nData;
  3740. index = $t.p._index[$.jgrid.stripPref($t.p.idPrefix, rowid)];
  3741. if(index !== undefined) {
  3742. $t.p.data[index][cm.name] = nData;
  3743. }
  3744. }
  3745. }
  3746. if(typeof cssp === 'string'){
  3747. $(tcell).addClass(cssp);
  3748. } else if(cssp) {
  3749. $(tcell).css(cssp);
  3750. }
  3751. if(typeof attrp === 'object') {$(tcell).attr(attrp);}
  3752. }
  3753. }
  3754. });
  3755. },
  3756. getCell : function(rowid,col) {
  3757. var ret = false;
  3758. this.each(function(){
  3759. var $t=this, pos=-1;
  3760. if(!$t.grid) {return;}
  3761. if(isNaN(col)) {
  3762. $($t.p.colModel).each(function(i){
  3763. if (this.name === col) {
  3764. pos = i;return false;
  3765. }
  3766. });
  3767. } else {pos = parseInt(col,10);}
  3768. if(pos>=0) {
  3769. var ind = $($t).jqGrid('getGridRowById', rowid);
  3770. if(ind) {
  3771. try {
  3772. ret = $.unformat.call($t,$("td:eq("+pos+")",ind),{rowId:ind.id, colModel:$t.p.colModel[pos]},pos);
  3773. } catch (e){
  3774. ret = $.jgrid.htmlDecode($("td:eq("+pos+")",ind).html());
  3775. }
  3776. }
  3777. }
  3778. });
  3779. return ret;
  3780. },
  3781. getCol : function (col, obj, mathopr) {
  3782. var ret = [], val, sum=0, min, max, v;
  3783. obj = typeof obj !== 'boolean' ? false : obj;
  3784. if(mathopr === undefined) { mathopr = false; }
  3785. this.each(function(){
  3786. var $t=this, pos=-1;
  3787. if(!$t.grid) {return;}
  3788. if(isNaN(col)) {
  3789. $($t.p.colModel).each(function(i){
  3790. if (this.name === col) {
  3791. pos = i;return false;
  3792. }
  3793. });
  3794. } else {pos = parseInt(col,10);}
  3795. if(pos>=0) {
  3796. var ln = $t.rows.length, i =0, dlen=0;
  3797. if (ln && ln>0){
  3798. while(i<ln){
  3799. if($($t.rows[i]).hasClass('jqgrow')) {
  3800. try {
  3801. val = $.unformat.call($t,$($t.rows[i].cells[pos]),{rowId:$t.rows[i].id, colModel:$t.p.colModel[pos]},pos);
  3802. } catch (e) {
  3803. val = $.jgrid.htmlDecode($t.rows[i].cells[pos].innerHTML);
  3804. }
  3805. if(mathopr) {
  3806. v = parseFloat(val);
  3807. if(!isNaN(v)) {
  3808. sum += v;
  3809. if (max === undefined) {max = min = v;}
  3810. min = Math.min(min, v);
  3811. max = Math.max(max, v);
  3812. dlen++;
  3813. }
  3814. }
  3815. else if(obj) { ret.push( {id:$t.rows[i].id,value:val} ); }
  3816. else { ret.push( val ); }
  3817. }
  3818. i++;
  3819. }
  3820. if(mathopr) {
  3821. switch(mathopr.toLowerCase()){
  3822. case 'sum': ret =sum; break;
  3823. case 'avg': ret = sum/dlen; break;
  3824. case 'count': ret = (ln-1); break;
  3825. case 'min': ret = min; break;
  3826. case 'max': ret = max; break;
  3827. }
  3828. }
  3829. }
  3830. }
  3831. });
  3832. return ret;
  3833. },
  3834. clearGridData : function(clearfooter) {
  3835. return this.each(function(){
  3836. var $t = this;
  3837. if(!$t.grid) {return;}
  3838. if(typeof clearfooter !== 'boolean') { clearfooter = false; }
  3839. if($t.p.deepempty) {$("#"+$.jgrid.jqID($t.p.id)+" tbody:first tr:gt(0)").remove();}
  3840. else {
  3841. var trf = $("#"+$.jgrid.jqID($t.p.id)+" tbody:first tr:first")[0];
  3842. $("#"+$.jgrid.jqID($t.p.id)+" tbody:first").empty().append(trf);
  3843. }
  3844. if($t.p.footerrow && clearfooter) { $(".ui-jqgrid-ftable td",$t.grid.sDiv).html("&#160;"); }
  3845. $t.p.selrow = null; $t.p.selarrrow= []; $t.p.savedRow = [];
  3846. $t.p.records = 0;$t.p.page=1;$t.p.lastpage=0;$t.p.reccount=0;
  3847. $t.p.data = []; $t.p._index = {};
  3848. $t.updatepager(true,false);
  3849. });
  3850. },
  3851. getInd : function(rowid,rc){
  3852. var ret =false,rw;
  3853. this.each(function(){
  3854. rw = $(this).jqGrid('getGridRowById', rowid);
  3855. if(rw) {
  3856. ret = rc===true ? rw: rw.rowIndex;
  3857. }
  3858. });
  3859. return ret;
  3860. },
  3861. bindKeys : function( settings ){
  3862. var o = $.extend({
  3863. onEnter: null,
  3864. onSpace: null,
  3865. onLeftKey: null,
  3866. onRightKey: null,
  3867. scrollingRows : true
  3868. },settings || {});
  3869. return this.each(function(){
  3870. var $t = this;
  3871. if( !$('body').is('[role]') ){$('body').attr('role','application');}
  3872. $t.p.scrollrows = o.scrollingRows;
  3873. $($t).keydown(function(event){
  3874. var target = $($t).find('tr[tabindex=0]')[0], id, r, mind,
  3875. expanded = $t.p.treeReader.expanded_field;
  3876. //check for arrow keys
  3877. if(target) {
  3878. mind = $t.p._index[$.jgrid.stripPref($t.p.idPrefix, target.id)];
  3879. if(event.keyCode === 37 || event.keyCode === 38 || event.keyCode === 39 || event.keyCode === 40){
  3880. // up key
  3881. if(event.keyCode === 38 ){
  3882. r = target.previousSibling;
  3883. id = "";
  3884. if(r) {
  3885. if($(r).is(":hidden")) {
  3886. while(r) {
  3887. r = r.previousSibling;
  3888. if(!$(r).is(":hidden") && $(r).hasClass('jqgrow')) {id = r.id;break;}
  3889. }
  3890. } else {
  3891. id = r.id;
  3892. }
  3893. }
  3894. $($t).jqGrid('setSelection', id, true, event);
  3895. event.preventDefault();
  3896. }
  3897. //if key is down arrow
  3898. if(event.keyCode === 40){
  3899. r = target.nextSibling;
  3900. id ="";
  3901. if(r) {
  3902. if($(r).is(":hidden")) {
  3903. while(r) {
  3904. r = r.nextSibling;
  3905. if(!$(r).is(":hidden") && $(r).hasClass('jqgrow') ) {id = r.id;break;}
  3906. }
  3907. } else {
  3908. id = r.id;
  3909. }
  3910. }
  3911. $($t).jqGrid('setSelection', id, true, event);
  3912. event.preventDefault();
  3913. }
  3914. // left
  3915. if(event.keyCode === 37 ){
  3916. if($t.p.treeGrid && $t.p.data[mind][expanded]) {
  3917. $(target).find("div.treeclick").trigger('click');
  3918. }
  3919. $($t).triggerHandler("jqGridKeyLeft", [$t.p.selrow]);
  3920. if($.isFunction(o.onLeftKey)) {
  3921. o.onLeftKey.call($t, $t.p.selrow);
  3922. }
  3923. }
  3924. // right
  3925. if(event.keyCode === 39 ){
  3926. if($t.p.treeGrid && !$t.p.data[mind][expanded]) {
  3927. $(target).find("div.treeclick").trigger('click');
  3928. }
  3929. $($t).triggerHandler("jqGridKeyRight", [$t.p.selrow]);
  3930. if($.isFunction(o.onRightKey)) {
  3931. o.onRightKey.call($t, $t.p.selrow);
  3932. }
  3933. }
  3934. }
  3935. //check if enter was pressed on a grid or treegrid node
  3936. else if( event.keyCode === 13 ){
  3937. $($t).triggerHandler("jqGridKeyEnter", [$t.p.selrow]);
  3938. if($.isFunction(o.onEnter)) {
  3939. o.onEnter.call($t, $t.p.selrow);
  3940. }
  3941. } else if(event.keyCode === 32) {
  3942. $($t).triggerHandler("jqGridKeySpace", [$t.p.selrow]);
  3943. if($.isFunction(o.onSpace)) {
  3944. o.onSpace.call($t, $t.p.selrow);
  3945. }
  3946. }
  3947. }
  3948. });
  3949. });
  3950. },
  3951. unbindKeys : function(){
  3952. return this.each(function(){
  3953. $(this).unbind('keydown');
  3954. });
  3955. },
  3956. getLocalRow : function (rowid) {
  3957. var ret = false, ind;
  3958. this.each(function(){
  3959. if(rowid !== undefined) {
  3960. ind = this.p._index[$.jgrid.stripPref(this.p.idPrefix, rowid)];
  3961. if(ind >= 0 ) {
  3962. ret = this.p.data[ind];
  3963. }
  3964. }
  3965. });
  3966. return ret;
  3967. },
  3968. progressBar : function ( p ) {
  3969. p = $.extend({
  3970. htmlcontent : "",
  3971. method : "hide",
  3972. loadtype : "disable"
  3973. }, p || {});
  3974. return this.each(function(){
  3975. var sh = p.method==="show" ? true : false;
  3976. if(p.htmlcontent !== "") {
  3977. $("#load_"+$.jgrid.jqID(this.p.id)).html( p.htmlcontent );
  3978. }
  3979. switch(p.loadtype) {
  3980. case "disable":
  3981. break;
  3982. case "enable":
  3983. $("#load_"+$.jgrid.jqID(this.p.id)).toggle( sh );
  3984. break;
  3985. case "block":
  3986. $("#lui_"+$.jgrid.jqID(this.p.id)).toggle( sh );
  3987. $("#load_"+$.jgrid.jqID(this.p.id)).toggle( sh );
  3988. break;
  3989. }
  3990. });
  3991. }
  3992. });
  3993. })(jQuery);