grid.base.js 315 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490
  1. // ==ClosureCompiler==
  2. // @compilation_level SIMPLE_OPTIMIZATIONS
  3. /**
  4. * @license jqGrid 4.15.6-pre - free jqGrid: https://github.com/free-jqgrid/jqGrid
  5. * Copyright (c) 2008-2014, Tony Tomov, tony@trirand.com
  6. * Copyright (c) 2014-2018, Oleg Kiriljuk, oleg.kiriljuk@ok-soft-gmbh.com
  7. * Dual licensed under the MIT and GPL licenses
  8. * http://www.opensource.org/licenses/mit-license.php
  9. * http://www.gnu.org/licenses/gpl-2.0.html
  10. * Date: 2018-10-08
  11. */
  12. //jsHint options
  13. /*jshint eqnull:true */
  14. /*jslint browser: true, evil: true, devel: true, white: true */
  15. /*global jQuery, define, HTMLElement, HTMLTableRowElement, module, require */
  16. (function (global, factory) {
  17. "use strict";
  18. if (typeof define === "function" && define.amd) {
  19. // AMD. Register as an anonymous module.
  20. //console.log("grid.base AMD");
  21. define([
  22. "jquery"
  23. ], function ($) {
  24. //console.log("grid.base AMD: define callback");
  25. return factory($, global.document);
  26. });
  27. } else if (typeof module === "object" && module.exports) {
  28. // Node/CommonJS
  29. //console.log("grid.base CommonJS");
  30. module.exports = function (root, $) {
  31. //console.log("grid.base CommonJS: in module.exports");
  32. if (!root) {
  33. root = window;
  34. }
  35. //console.log("grid.base CommonJS: before require('jquery')");
  36. if ($ === undefined) {
  37. // require("jquery") returns a factory that requires window to
  38. // build a jQuery instance, we normalize how we use modules
  39. // that require this pattern but the window provided is a noop
  40. // if it's defined (how jquery works)
  41. $ = typeof window !== "undefined" ?
  42. require("jquery") :
  43. require("jquery")(root);
  44. }
  45. //global.jQuery = $;
  46. //root.jQuery = $;
  47. //console.log("grid.base CommonJS: before factory");
  48. factory($, root.document);
  49. return $;
  50. };
  51. } else {
  52. // Browser globals
  53. //console.log("grid.base Browser: before factory");
  54. factory(jQuery, global.document);
  55. }
  56. }(typeof window !== "undefined" ? window : this, function ($, document) {
  57. "use strict";
  58. // begin module grid.base
  59. /** @const */
  60. var englishLanguageDefaults = {
  61. name: "English (United States)",
  62. nameEnglish: "English (United States)",
  63. isRTL: false,
  64. defaults: {
  65. recordtext: "View {0} - {1} of {2}",
  66. emptyrecords: "No records to view",
  67. loadtext: "Loading...",
  68. pgtext: "Page {0} of {1}",
  69. pgfirst: "First Page",
  70. pglast: "Last Page",
  71. pgnext: "Next Page",
  72. pgprev: "Previous Page",
  73. pgrecs: "Records per Page",
  74. showhide: "Toggle Expand Collapse Grid",
  75. savetext: "Saving..."
  76. },
  77. search: {
  78. caption: "Search...",
  79. Find: "Find",
  80. Reset: "Reset",
  81. odata: [
  82. { oper: "eq", text: "equal" },
  83. { oper: "ne", text: "not equal" },
  84. { oper: "lt", text: "less" },
  85. { oper: "le", text: "less or equal" },
  86. { oper: "gt", text: "greater" },
  87. { oper: "ge", text: "greater or equal" },
  88. { oper: "bw", text: "begins with" },
  89. { oper: "bn", text: "does not begin with" },
  90. { oper: "in", text: "is in" },
  91. { oper: "ni", text: "is not in" },
  92. { oper: "ew", text: "ends with" },
  93. { oper: "en", text: "does not end with" },
  94. { oper: "cn", text: "contains" },
  95. { oper: "nc", text: "does not contain" },
  96. { oper: "nu", text: "is null" },
  97. { oper: "nn", text: "is not null" }
  98. ],
  99. groupOps: [
  100. { op: "AND", text: "all" },
  101. { op: "OR", text: "any" }
  102. ],
  103. addGroupTitle: "Add subgroup",
  104. deleteGroupTitle: "Delete group",
  105. addRuleTitle: "Add rule",
  106. deleteRuleTitle: "Delete rule",
  107. operandTitle: "Click to select search operation.",
  108. resetTitle: "Reset Search Value"
  109. },
  110. edit: {
  111. addCaption: "Add Record",
  112. editCaption: "Edit Record",
  113. bSubmit: "Submit",
  114. bCancel: "Cancel",
  115. bClose: "Close",
  116. saveData: "Data has been changed! Save changes?",
  117. bYes: "Yes",
  118. bNo: "No",
  119. bExit: "Cancel",
  120. msg: {
  121. required: "Field is required",
  122. number: "Please, enter valid number",
  123. minValue: "value must be greater than or equal to ",
  124. maxValue: "value must be less than or equal to",
  125. email: "is not a valid e-mail",
  126. integer: "Please, enter valid integer value",
  127. date: "Please, enter valid date value",
  128. url: "is not a valid URL. Prefix required ('http://' or 'https://')",
  129. nodefined: " is not defined!",
  130. novalue: " return value is required!",
  131. customarray: "Custom function should return array!",
  132. customfcheck: "Custom function should be present in case of custom checking!"
  133. }
  134. },
  135. view: {
  136. caption: "View Record",
  137. bClose: "Close"
  138. },
  139. del: {
  140. caption: "Delete",
  141. msg: "Delete selected record(s)?",
  142. bSubmit: "Delete",
  143. bCancel: "Cancel"
  144. },
  145. nav: {
  146. edittext: "",
  147. edittitle: "Edit selected row",
  148. addtext: "",
  149. addtitle: "Add new row",
  150. deltext: "",
  151. deltitle: "Delete selected row",
  152. searchtext: "",
  153. searchtitle: "Find records",
  154. refreshtext: "",
  155. refreshtitle: "Reload Grid",
  156. alertcap: "Warning",
  157. alerttext: "Please, select row",
  158. viewtext: "",
  159. viewtitle: "View selected row",
  160. savetext: "",
  161. savetitle: "Save row",
  162. canceltext: "",
  163. canceltitle: "Cancel row editing"
  164. },
  165. col: {
  166. caption: "Select columns",
  167. bSubmit: "Ok",
  168. bCancel: "Cancel"
  169. },
  170. errors: {
  171. errcap: "Error",
  172. nourl: "No url is set",
  173. norecords: "No records to process",
  174. model: "Length of colNames <> colModel!"
  175. },
  176. formatter: {
  177. integer: {
  178. thousandsSeparator: ",",
  179. defaultValue: "0"
  180. },
  181. number: {
  182. decimalSeparator: ".",
  183. thousandsSeparator: ",",
  184. decimalPlaces: 2,
  185. defaultValue: "0.00"
  186. },
  187. currency: {
  188. decimalSeparator: ".",
  189. thousandsSeparator: ",",
  190. decimalPlaces: 2,
  191. prefix: "",
  192. suffix: "",
  193. defaultValue: "0.00"
  194. },
  195. date: {
  196. dayNames: [
  197. "Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat",
  198. "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
  199. ],
  200. monthNames: [
  201. "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
  202. "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
  203. ],
  204. AmPm: ["am", "pm", "AM", "PM"],
  205. S: function (j) {
  206. var ending = ["st", "nd", "rd", "th"];
  207. return j < 11 || j > 13 ? ending[Math.min((j - 1) % 10, 3)] : "th";
  208. },
  209. srcformat: "Y-m-d",
  210. newformat: "n/j/Y",
  211. masks: {
  212. // see http://php.net/manual/en/function.date.php for PHP format used in jqGrid
  213. // and see http://docs.jquery.com/UI/Datepicker/formatDate
  214. // and https://github.com/jquery/globalize#dates for alternative formats used frequently
  215. // one can find on https://github.com/jquery/globalize/tree/master/lib/cultures many
  216. // information about date, time, numbers and currency formats used in different countries
  217. // one should just convert the information in PHP format
  218. // short date:
  219. // n - Numeric representation of a month, without leading zeros
  220. // j - Day of the month without leading zeros
  221. // Y - A full numeric representation of a year, 4 digits
  222. // example: 3/1/2012 which means 1 March 2012
  223. ShortDate: "n/j/Y", // in jQuery UI Datepicker: "M/d/yyyy"
  224. // long date:
  225. // l - A full textual representation of the day of the week
  226. // F - A full textual representation of a month
  227. // d - Day of the month, 2 digits with leading zeros
  228. // Y - A full numeric representation of a year, 4 digits
  229. LongDate: "l, F d, Y", // in jQuery UI Datepicker: "dddd, MMMM dd, yyyy"
  230. // long date with long time:
  231. // l - A full textual representation of the day of the week
  232. // F - A full textual representation of a month
  233. // d - Day of the month, 2 digits with leading zeros
  234. // Y - A full numeric representation of a year, 4 digits
  235. // g - 12-hour format of an hour without leading zeros
  236. // i - Minutes with leading zeros
  237. // s - Seconds, with leading zeros
  238. // A - Uppercase Ante meridiem and Post meridiem (AM or PM)
  239. FullDateTime: "l, F d, Y g:i:s A", // in jQuery UI Datepicker: "dddd, MMMM dd, yyyy h:mm:ss tt"
  240. // month day:
  241. // F - A full textual representation of a month
  242. // d - Day of the month, 2 digits with leading zeros
  243. MonthDay: "F d", // in jQuery UI Datepicker: "MMMM dd"
  244. // short time (without seconds)
  245. // g - 12-hour format of an hour without leading zeros
  246. // i - Minutes with leading zeros
  247. // A - Uppercase Ante meridiem and Post meridiem (AM or PM)
  248. ShortTime: "g:i A", // in jQuery UI Datepicker: "h:mm tt"
  249. // long time (with seconds)
  250. // g - 12-hour format of an hour without leading zeros
  251. // i - Minutes with leading zeros
  252. // s - Seconds, with leading zeros
  253. // A - Uppercase Ante meridiem and Post meridiem (AM or PM)
  254. LongTime: "g:i:s A", // in jQuery UI Datepicker: "h:mm:ss tt"
  255. // month with year
  256. // Y - A full numeric representation of a year, 4 digits
  257. // F - A full textual representation of a month
  258. YearMonth: "F, Y" // in jQuery UI Datepicker: "MMMM, yyyy"
  259. }
  260. }
  261. }
  262. };
  263. $.jgrid = $.jgrid || {};
  264. var jgrid = $.jgrid;
  265. jgrid.locales = jgrid.locales || {};
  266. var locales = jgrid.locales;
  267. /**
  268. * Enum with different components of jqGrid.
  269. * @enum {number} @const
  270. */
  271. /*var INPUT_NAME_TYPE = {
  272. COL_NAME: 0,
  273. ADDITIONAL_PROPERTY: 1,
  274. ROWID: 2
  275. };*/
  276. /**
  277. * Enum with different components of jqGrid.
  278. * @enum {number} @const
  279. */
  280. var COMPONENT_NAMES = {
  281. // let us this - <table> from which grid is created. Then
  282. // gBox (grid box) - outer div which includes all grid components: $(this).closest(".ui-jqgrid")[0]
  283. // In the same way
  284. GRID_BOX_DIV: 0, // tagName: "div". class: "ui-jqgrid". Id: "gbox_" + gridId
  285. GRID_OVERLAY_DIV: 1, // tagName: "div". class: "jqgrid-overlay". Id: "lui_" + gridId
  286. LOADING_DIV: 2, // tagName: "div". class: "loading". Id: "load_" + gridId
  287. DIALOG_ALERT_DIV: 3, // tagName: "div". class: "ui-jqdialog". Id: "alertmod_" + gridId
  288. DIALOG_SEARCH_DIV: 4, // tagName: "div". class: "ui-jqdialog". Id: "searchmodfbox_" + gridId
  289. DIALOG_VIEW_DIV: 5, // tagName: "div". class: "ui-jqdialog". Id: "viewmod" + gridId
  290. DIALOG_EDIT_DIV: 6, // tagName: "div". class: "ui-jqdialog". Id: "editmod" + gridId
  291. DIALOG_DELETE_DIV: 7, // tagName: "div". class: "ui-jqdialog". Id: "delmod" + gridId
  292. GRID_VIEW_DIV: 8, // tagName: "div". class: "ui-jqgrid-view". Id: "gview_" + gridId
  293. TITLE_BAR_DIV: 9, // tagName: "div". class: "ui-jqgrid-titlebar" and either "ui-jqgrid-caption" or "ui-jqgrid-caption-rtl"
  294. UPPER_TOOLBAR_DIV: 10, // tagName: "div". class: "ui-userdata". Id: "tb_" + gridId
  295. TOP_PAGER_DIV: 11, // tagName: "div". class: "ui-jqgrid-toppager". Id: gridId + "_toppager"
  296. HEADER_DIV: 12, // tagName: "div". class: "ui-jqgrid-hdiv"
  297. HEADER_BOX_DIV: 13, // tagName: "div". class: either "ui-jqgrid-hdiv" or "ui-jqgrid-hbox-rtl"
  298. HEADER_TABLE: 14, // tagName: "table". class: "ui-jqgrid-htable"
  299. HEADER_COLS_ROW: 15, // tagName: "tr". class: "jqgfirstrow" or the row with column headers
  300. HEADER_COLS: 16, // tagName: "th". class: either "ui-first-th-rtl" or "ui-first-th-rtl"
  301. HEADER_ROWS: 47, // tagName: "tr". class: "ui-jqgrid-labels"
  302. HEADER_TH: 48, // tagName: "th". class: "ui-th-column" and either "ui-th-ltr" or "ui-th-rtl"
  303. HEADER_SORTABLE_DIV: 49, // tagName: "div". class: "ui-jqgrid-labels"
  304. HEADER_RESIZABLE_SPAN: 50, // tagName: "span". class: "ui-jqgrid-resize" and either "ui-jqgrid-resize-ltr" or "ui-jqgrid-resize-rtl"
  305. HEADER_SELECT_ALL_ROWS_CHECKBOX: 45, // tagName: "input" (can be changed to "button" in the future). class: "cbox". Id: "cb_" + gridId
  306. SEARCH_TOOLBAR: 17, // tagName: "tr". class: "ui-search-toolbar". Its direct children are th having class "ui-th-column" and optionally "ui-th-rtl"
  307. BODY_DIV: 18, // tagName: "div". class: "ui-jqgrid-bdiv"
  308. BODY_SCROLL_FULL_DIV: 19, // tagName: "div" - It can have height CSS property which simulate the total size of virtual data.
  309. BODY_SCROLL_TOP_DIV: 20, // tagName: "div" - It can have height CSS property which simulate virtual data before the current displayed in btable.
  310. BODY_TABLE: 21, // tagName: "table". class: "ui-jqgrid-btable". Id: gridId
  311. GRID: 21, // tagName: "table". class: "ui-jqgrid-btable". Id: gridId
  312. BODY_COLS_ROW: 22, // tagName: "tr". class: "jqgfirstrow"
  313. BODY_COLS: 23, // tagName: "td"
  314. BODY_DATA_ROWS: 24, // tagName: "tr". class: "jqgrow" and optionally "ui-row-rtl"
  315. FOOTER_DIV: 25, // tagName: "div". class: "ui-jqgrid-sdiv"
  316. FOOTER_BOX_DIV: 26, // tagName: "div". class: either "ui-jqgrid-hdiv" or "ui-jqgrid-hbox-rtl". ??? is it really needed ???
  317. FOOTER_TABLE: 27, // tagName: "table". class: "ui-jqgrid-ftable"
  318. FOOTER_DATA_ROWS: 28, // tagName: "tr". class: "footrow", optionally additionally "footrow-rtl"
  319. BOTTOM_TOOLBAR_DIV: 29, // tagName: "div". class: "ui-userdata". Id: "tb_" + gridId
  320. FROZEN_HEADER_DIV: 30, // tagName: "div". class: "frozen-div" and "ui-jqgrid-hdiv"
  321. // no hBox currently exists
  322. FROZEN_HEADER_TABLE: 31, // tagName: "table". class: "ui-jqgrid-htable"
  323. FROZEN_HEADER_COLS_ROW: 32, // tagName: "tr". class: "jqgfirstrow"
  324. FROZEN_HEADER_COLS: 33, // tagName: "th". class: either "ui-first-th-rtl" or "ui-first-th-rtl"
  325. FROZEN_SEARCH_TOOLBAR: 34, // tagName: "tr". class: "ui-search-toolbar". Its direct children are th having class "ui-th-column" and optionally "ui-th-rtl"
  326. // TODO: fix id of children of .ui-search-input to have no id duplicates with the main grid
  327. FROZEN_FOOTER_DIV: 35, // tagName: "div". class: "frozen-div" and "ui-jqgrid-sdiv"
  328. FROZEN_FOOTER_TABLE: 36, // tagName: "table". class: "ui-jqgrid-ftable"
  329. FROZEN_FOOTER_DATA_ROWS: 37, // tagName: "tr". class: "footrow", optionally additionally "footrow-rtl"
  330. FROZEN_BODY_DIV: 38, // tagName: "div". class: "frozen-div" and "ui-jqgrid-bdiv"
  331. // no full scroll div and top scroll div is currently exist
  332. FROZEN_BODY_TABLE: 39, // tagName: "table". class: "ui-jqgrid-btable". Id: gridId + "_frozen"
  333. FROZEN_BODY_COLS_ROW: 40, // tagName: "tr". class: "jqgfirstrow"
  334. FROZEN_BODY_COLS: 41, // tagName: "td"
  335. FROZEN_BODY_DATA_ROWS: 42, // tagName: "tr". class: "jqgrow" and optionally "ui-row-rtl"
  336. // TODO: fix id of children of .jqgrow to have no id duplicates with the main grid
  337. COLUMN_RESIZER_DIV: 43, // tagName: "div". class: "ui-jqgrid-resize-mark". Id: "rs_m" + gridId
  338. BOTTOM_PAGER_DIV: 44, // tagName: "div". class: "ui-jqgrid-pager"
  339. SEARCH_OPERATION_MENU_UL: 46 // tagName: "ul". class: "ui-search-menu". id="sopt_menu"
  340. };
  341. if (jgrid.defaults == null || $.isEmptyObject(locales) || locales["en-US"] === undefined) {
  342. // set English options only if no grid.locale-XX.js file are included before jquery.jqGrid.min.js or jquery.jqGrid.src.js
  343. // the files included AFTER jquery.jqGrid.min.js or jquery.jqGrid.src.js will just overwrite all the settings which were set previously
  344. // We can set locInfo under $.jgrid additionally to setting under $.jgrid.locales[locale]
  345. // only to have more compatibility with the previous version of jqGrid.
  346. // We don't make this currently.
  347. if (locales["en-US"] === undefined) {
  348. $.extend(true, jgrid, /*englishLanguageDefaults,*/ {
  349. locales: {
  350. "en-US": englishLanguageDefaults // and for English US
  351. }
  352. });
  353. }
  354. jgrid.defaults = jgrid.defaults || {};
  355. if (jgrid.defaults.locale === undefined) {
  356. jgrid.defaults.locale = "en-US";
  357. }
  358. }
  359. jgrid.defaults = jgrid.defaults || {};
  360. var defaults = jgrid.defaults;
  361. //if (jgrid.defaults.locale && locales[jgrid.defaults.locale]) {
  362. // $.extend(true, $.jgrid, locales[jgrid.defaults.locale]); // add to improve compatibility only
  363. //}
  364. $.extend(true, jgrid, {
  365. /** @const */
  366. version: "4.15.6-pre",
  367. /** @const */
  368. productName: "free jqGrid",
  369. defaults: {},
  370. search: {},
  371. edit: {},
  372. view: {},
  373. del: {},
  374. nav: {},
  375. col: {},
  376. errors: {},
  377. formatter: {
  378. unused: "" // used only to detect whether the changes are overwritten because of wrong usage
  379. },
  380. icons: {
  381. jQueryUI: {
  382. common: "ui-icon",
  383. pager: {
  384. first: "ui-icon-seek-first",
  385. prev: "ui-icon-seek-prev",
  386. next: "ui-icon-seek-next",
  387. last: "ui-icon-seek-end"
  388. },
  389. sort: {
  390. asc: "ui-icon-triangle-1-n",
  391. desc: "ui-icon-triangle-1-s"
  392. },
  393. gridMinimize: {
  394. visible: "ui-icon-circle-triangle-n",
  395. hidden: "ui-icon-circle-triangle-s"
  396. },
  397. nav: {
  398. edit: "ui-icon-pencil",
  399. add: "ui-icon-plus",
  400. del: "ui-icon-trash",
  401. search: "ui-icon-search",
  402. refresh: "ui-icon-refresh",
  403. view: "ui-icon-document",
  404. save: "ui-icon-disk",
  405. cancel: "ui-icon-cancel",
  406. newbutton: "ui-icon-newwin"
  407. },
  408. actions: {
  409. edit: "ui-icon-pencil",
  410. del: "ui-icon-trash",
  411. save: "ui-icon-disk",
  412. cancel: "ui-icon-cancel"
  413. },
  414. form: {
  415. close: "ui-icon-closethick",
  416. prev: "ui-icon-triangle-1-w",
  417. next: "ui-icon-triangle-1-e",
  418. save: "ui-icon-disk",
  419. undo: "ui-icon-close",
  420. del: "ui-icon-scissors",
  421. cancel: "ui-icon-cancel",
  422. resizableLtr: "ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se"
  423. },
  424. search: {
  425. search: "ui-icon-search",
  426. reset: "ui-icon-arrowreturnthick-1-w",
  427. query: "ui-icon-comment"
  428. },
  429. subgrid: {
  430. plus: "ui-icon-plus",
  431. minus: "ui-icon-minus",
  432. openLtr: "ui-icon-caret-1-sw",
  433. openRtl: "ui-icon-caret-1-se"
  434. },
  435. grouping: {
  436. plus: "ui-icon-circlesmall-plus",
  437. minus: "ui-icon-circlesmall-minus"
  438. },
  439. treeGrid: {
  440. minus: "ui-icon-triangle-1-s",
  441. leaf: "ui-icon-radio-off",
  442. plusLtr: "ui-icon-triangle-1-e",
  443. plusRtl: "ui-icon-triangle-1-w"
  444. }
  445. },
  446. fontAwesome: {
  447. common: "fa",
  448. pager: {
  449. common: "fa-fw",
  450. first: "fa-step-backward",
  451. prev: "fa-backward",
  452. next: "fa-forward",
  453. last: "fa-step-forward"
  454. },
  455. sort: {
  456. common: "fa-lg", // common: "",
  457. asc: "fa-sort-asc", // asc: "fa-sort-amount-asc",
  458. desc: "fa-sort-desc" // desc: "fa-sort-amount-desc"
  459. },
  460. gridMinimize: {
  461. visible: "fa-chevron-circle-up",
  462. hidden: "fa-chevron-circle-down"
  463. },
  464. nav: {
  465. common: "fa-lg fa-fw",
  466. edit: "fa-pencil",
  467. add: "fa-plus",
  468. del: "fa-trash-o",
  469. search: "fa-search",
  470. refresh: "fa-refresh",
  471. view: "fa-file-o",
  472. save: "fa-floppy-o",
  473. cancel: "fa-ban",
  474. newbutton: "fa-external-link"
  475. },
  476. actions: {
  477. common: "fa-fw",
  478. edit: "fa-pencil",
  479. del: "fa-trash-o",
  480. save: "fa-floppy-o",
  481. cancel: "fa-ban"
  482. },
  483. form: {
  484. close: "fa-times",
  485. prev: "fa-caret-left",
  486. next: "fa-caret-right",
  487. save: "fa-floppy-o",
  488. undo: "fa-undo",
  489. del: "fa-trash-o",
  490. cancel: "fa-ban",
  491. resizableLtr: "fa-rss fa-rotate-270"
  492. },
  493. search: {
  494. search: "fa-search",
  495. reset: "fa-undo",
  496. query: "fa-comments-o"
  497. },
  498. subgrid: {
  499. common: "fa-fw",
  500. plus: "fa-plus",
  501. minus: "fa-minus",
  502. openLtr: "fa-reply fa-rotate-180",
  503. openRtl: "fa-share fa-rotate-180"
  504. },
  505. grouping: {
  506. common: "fa-fw",
  507. plus: "fa-plus-square-o",
  508. minus: "fa-minus-square-o"
  509. },
  510. treeGrid: {
  511. common: "fa-fw",
  512. minus: "fa-lg fa-sort-desc",
  513. leaf: "fa-dot-circle-o",
  514. plusLtr: "fa-lg fa-caret-right",
  515. plusRtl: "fa-lg fa-caret-left"
  516. },
  517. checkbox: {
  518. checkedClasses: "fa-check-square-o",
  519. checked: "fa-check-square-o fa-lg",
  520. unchecked: "fa-square-o fa-lg"
  521. }
  522. },
  523. fontAwesome5: {
  524. //common: "fas", //"fa"
  525. pager: {
  526. common: "fa-fw",
  527. first: "fa-step-backward",
  528. prev: "fa-backward",
  529. next: "fa-forward",
  530. last: "fa-step-forward"
  531. },
  532. sort: {
  533. common: "fa-lg", // common: "",
  534. asc: "fa-sort-up", //"fa-sort-asc", // asc: "fa-sort-amount-asc",
  535. desc: "fa-sort-down" //"fa-sort-desc" // desc: "fa-sort-amount-desc"
  536. },
  537. gridMinimize: {
  538. visible: "fa-chevron-circle-up",
  539. hidden: "fa-chevron-circle-down"
  540. },
  541. nav: {
  542. common: "fa-lg fa-fw",
  543. edit: "fa-pencil-alt",
  544. add: "fa-plus",
  545. del: "fa-trash-alt",
  546. search: "fa-search",
  547. refresh: "fa-sync", //"fa-refresh",
  548. view: "fa-file",
  549. save: "fa-save",
  550. cancel: "fa-ban",
  551. newbutton: "fa-external-link-alt"
  552. },
  553. actions: {
  554. common: "fa-fw",
  555. edit: "fa-pencil-alt",
  556. del: "fa-trash-alt",
  557. save: "fa-save",
  558. cancel: "fa-ban"
  559. },
  560. form: {
  561. close: "fa-times",
  562. prev: "fa-caret-left",
  563. next: "fa-caret-right",
  564. save: "fa-save",
  565. undo: "fa-undo",
  566. del: "fa-trash-alt",
  567. cancel: "fa-ban",
  568. resizableLtr: "fa-rss fa-lg fa-rotate-270"
  569. },
  570. search: {
  571. search: "fa-search",
  572. reset: "fa-undo",
  573. query: "fa-comments"
  574. },
  575. subgrid: {
  576. common: "fa-fw",
  577. plus: "fa-plus",
  578. minus: "fa-minus",
  579. openLtr: "fa-reply fa-rotate-180",
  580. openRtl: "fa-share fa-rotate-180"
  581. },
  582. grouping: {
  583. common: "fa-fw",
  584. plus: "fa-plus-square",
  585. minus: "fa-minus-square"
  586. },
  587. treeGrid: {
  588. common: "fa-fw",
  589. minus: "fa-lg fa-sort-down", //"fa-lg fa-sort-desc",
  590. leaf: "fa-dot-circle",
  591. plusLtr: "fa-lg fa-caret-right",
  592. plusRtl: "fa-lg fa-caret-left"
  593. },
  594. checkbox: {
  595. ignoreParents: true,
  596. checkedClasses: "fa-check-square",
  597. checked: "far fa-check-square fa-lg",
  598. unchecked: "far fa-square fa-lg"
  599. }
  600. },
  601. fontAwesomeBrands: {
  602. baseIconSet: "fontAwesome5",
  603. common: "fab"
  604. },
  605. fontAwesomeLight: {
  606. baseIconSet: "fontAwesome5",
  607. common: "fal"
  608. },
  609. fontAwesomeRegular: {
  610. baseIconSet: "fontAwesome5",
  611. common: "far"
  612. },
  613. fontAwesomeSolid: {
  614. baseIconSet: "fontAwesome5",
  615. common: "fas"
  616. },
  617. fontAwesomeSVG: {
  618. baseIconSet: "fontAwesome5",
  619. common: "fas"
  620. },
  621. glyph: {
  622. common: "glyphicon",
  623. pager: {
  624. common: "",
  625. first: "glyphicon-step-backward",
  626. prev: "glyphicon-backward",
  627. next: "glyphicon-forward",
  628. last: "glyphicon-step-forward"
  629. },
  630. sort: {
  631. common: "",
  632. asc: "glyphicon-triangle-top",
  633. desc: "glyphicon-triangle-bottom"
  634. },
  635. gridMinimize: {
  636. visible: "glyphicon-circle-arrow-up",
  637. hidden: "glyphicon-circle-arrow-down"
  638. },
  639. nav: {
  640. common: "",
  641. edit: "glyphicon-edit",
  642. add: "glyphicon-plus",
  643. del: "glyphicon-trash",
  644. search: "glyphicon-search",
  645. refresh: "glyphicon-refresh",
  646. view: "glyphicon-file", // glyphicon glyphicon-th-list
  647. save: "glyphicon-save",
  648. cancel: "glyphicon-ban-circle",
  649. newbutton: "glyphicon-new-window"
  650. },
  651. actions: {
  652. common: "",
  653. edit: "glyphicon-edit",
  654. del: "glyphicon-trash",
  655. save: "glyphicon-save",
  656. cancel: "glyphicon-ban-circle"
  657. },
  658. form: {
  659. close: "glyphicon-remove-circle",
  660. prev: "glyphicon-step-backward",
  661. next: "glyphicon-step-forward",
  662. save: "glyphicon-save",
  663. undo: "glyphicon-repeat",
  664. del: "glyphicon-trash",
  665. cancel: "glyphicon-ban-circle",
  666. resizableLtr: "glyphicon-import"
  667. },
  668. search: {
  669. search: "glyphicon-search",
  670. reset: "glyphicon-repeat",
  671. query: "glyphicon-cog" //"glyphicon-comment"
  672. },
  673. subgrid: {
  674. common: "",
  675. plus: "glyphicon-zoom-in", //"glyphicon-plus", "glyphicon-th-list",
  676. minus: "glyphicon-zoom-out", // "glyphicon-minus",
  677. openLtr: "glyphicon-indent-left",
  678. openRtl: "glyphicon-indent-left"
  679. },
  680. grouping: {
  681. common: "",
  682. plus: "glyphicon-expand",
  683. minus: "glyphicon-collapse-down"
  684. },
  685. treeGrid: {
  686. common: "",
  687. minus: "glyphicon-triangle-bottom",
  688. leaf: "glyphicon-record", // glyphicon-unchecked
  689. plusLtr: "glyphicon-triangle-right",
  690. plusRtl: "glyphicon-triangle-left"
  691. },
  692. checkbox: {
  693. checkedClasses: "glyphicon-check",
  694. checked: "glyphicon-check",
  695. unchecked: "glyphicon-unchecked"
  696. }
  697. }
  698. },
  699. guiStyles: {
  700. jQueryUI: {
  701. gBox: "ui-jqgrid-jquery-ui ui-widget ui-widget-content ui-corner-all", // ui-widget-content??? for the children of gbox
  702. gView: "",
  703. overlay: "ui-widget-overlay",
  704. loading: "ui-state-default ui-state-active",
  705. hDiv: "ui-state-default ui-corner-top",
  706. hTable: "",
  707. colHeaders: "ui-state-default",
  708. states: {
  709. select: "ui-state-highlight",
  710. disabled: "ui-state-disabled ui-jqgrid-disablePointerEvents",
  711. hover: "ui-state-hover", // can be table-hover on <table> only and style like .table-hover tbody tr:hover td
  712. error: "ui-state-error",
  713. active: "ui-state-active",
  714. textOfClickable: "ui-state-default"
  715. },
  716. dialog: {
  717. header: "ui-widget-header ui-dialog-titlebar ui-corner-all ui-helper-clearfix",
  718. window: "ui-jqgrid-jquery-ui ui-widget ui-widget-content ui-corner-all ui-front",
  719. document: "",
  720. subdocument: "",
  721. body: "",
  722. footer: "",
  723. content: "ui-widget-content",
  724. hr: "ui-widget-content",
  725. closeButton: "ui-corner-all",
  726. fmButton: "ui-state-default",
  727. dataField: "ui-widget-content ui-corner-all",
  728. viewCellLabel: "ui-widget-content",
  729. viewLabel: "",
  730. viewCellData: "ui-widget-content",
  731. viewData: "",
  732. leftCorner: "ui-corner-left",
  733. rightCorner: "ui-corner-right",
  734. defaultCorner: "ui-corner-all"
  735. },
  736. filterToolbar: {
  737. dataField: "ui-widget-content"
  738. },
  739. subgrid: {
  740. thSubgrid: "ui-state-default", // used only with subGridModel
  741. rowSubTable: "ui-widget-content", // used only with subGridModel additionally to ui-subtblcell
  742. row: "ui-widget-content", // class of the subgrid row, additional to ui-subgrid
  743. tdStart: "", // it can be with span over rownumber and multiselect columns
  744. tdWithIcon: "ui-widget-content", // class of cell with +- icon, additional to subgrid-cell
  745. buttonDiv: "",
  746. button: "",
  747. tdData: "ui-widget-content", // class of main td with span over the grid, additional subgrid-data
  748. legacyTable: ""
  749. },
  750. grid: "",
  751. gridRow: "ui-widget-content",
  752. rowNum: "ui-state-default",
  753. gridFooter: "",
  754. rowFooter: "ui-widget-content",
  755. gridTitle: "ui-widget-header ui-corner-top",
  756. gridError: "ui-state-error",
  757. gridErrorText: "",
  758. titleButton: "ui-corner-all",
  759. toolbarUpper: "ui-state-default",
  760. toolbarBottom: "ui-state-default",
  761. actionsDiv: "ui-widget-content",
  762. actionsButton: "ui-corner-all",
  763. pager: {
  764. pager: "ui-state-default",
  765. pagerButton: "ui-corner-all",
  766. pagerInput: "ui-widget-content",
  767. pagerSelect: "ui-widget-content"
  768. },
  769. navButton: "ui-corner-all",
  770. searchDialog: {
  771. operator: "ui-corner-all",
  772. label: "ui-corner-all",
  773. elem: "ui-corner-all",
  774. operationGroup: "",
  775. addRuleButton: "ui-corner-all",
  776. deleteRuleButton: "ui-corner-all",
  777. operationSelect: "ui-corner-all",
  778. addGroupButton: "ui-corner-all",
  779. deleteGroupButton: "ui-corner-all"
  780. },
  781. searchToolbar: {
  782. menu: "ui-menu-jqueryui ui-menu ui-widget ui-widget-content ui-corner-all",
  783. menuItem: "ui-menu-item",
  784. menuItemButton: "ui-corner-all",
  785. operButton: "ui-corner-all",
  786. clearButton: "ui-corner-all"
  787. },
  788. top: "ui-corner-top",
  789. bottom: "ui-corner-bottom",
  790. resizer: "ui-widget-header"
  791. },
  792. bootstrap: {
  793. gBox: "ui-jqgrid-bootstrap",
  794. gView: "panel-info",
  795. overlay: "modal-backdrop",
  796. loading: "alert alert-info",
  797. hDiv: "",
  798. hTable: "table table-hover table-condensed table-bordered",
  799. colHeaders: "",
  800. states: {
  801. select: "success",
  802. disabled: "disabled ui-jqgrid-disablePointerEvents",
  803. hover: "active",
  804. error: "danger",
  805. active: "active",
  806. textOfClickable: ""
  807. },
  808. dialog: {
  809. header: "modal-header",
  810. window: "modal ui-jqgrid-bootstrap",
  811. document: "modal-dialog",
  812. subdocument: "modal-content",
  813. body: "modal-body",
  814. footer: "modal-footer",
  815. content: "modal-content",
  816. hr: "hidden",
  817. closeButton: "btn btn-xs btn-default",
  818. fmButton: "btn btn-default",
  819. dataField: "form-control",
  820. viewCellLabel: "",
  821. viewLabel: "control-label",
  822. viewCellData: "",
  823. viewData: "form-control",
  824. leftCorner: "",
  825. rightCorner: "",
  826. defaultCorner: ""
  827. },
  828. filterToolbar: {
  829. dataField: "form-control"
  830. },
  831. subgrid: {
  832. thSubgrid: "",
  833. rowSubTable: "",
  834. row: "",
  835. tdStart: "",
  836. tdWithIcon: "",
  837. buttonDiv: "",
  838. button: "btn btn-xs",
  839. tdData: "",
  840. legacyTable: "table table-condensed table-hover table-bordered"
  841. },
  842. grid: "table table-condensed table-hover table-bordered",
  843. gridRow: "",
  844. rowNum: "",
  845. gridFooter: "table table-hover table-condensed table-bordered",
  846. rowFooter: "",
  847. gridTitle: "",
  848. gridError: "alert alert-danger",
  849. gridErrorText: "sr-only",
  850. titleButton: "btn btn-xs btn-default",
  851. actionsDiv: "",
  852. actionsButton: "btn btn-xs btn-default",
  853. toolbarUpper: "",
  854. toolbarBottom: "",
  855. pager: {
  856. pager: "panel-footer",
  857. pagerButton: "btn btn-xs",
  858. pagerInput: "form-control",
  859. pagerSelect: "form-control"
  860. },
  861. navButton: "btn btn-xs",
  862. searchDialog: {
  863. operator: "form-control",
  864. label: "form-control",
  865. elem: "form-control",
  866. operationGroup: "form-inline",
  867. addRuleButton: "btn btn-xs btn-default",
  868. deleteRuleButton: "btn btn-xs btn-default",
  869. operationSelect: "form-control",
  870. addGroupButton: "btn btn-xs btn-default",
  871. deleteGroupButton: "btn btn-xs btn-default"
  872. },
  873. searchToolbar: {
  874. menu: "dropdown-menu",
  875. menuItem: "",
  876. menuItemButton: "ui-corner-all",
  877. operButton: "btn btn-xs btn-default",
  878. clearButton: "btn btn-xs btn-default"
  879. },
  880. top: "ui-jqgrid-bootstrap-corner-top",
  881. bottom: "ui-jqgrid-bootstrap-corner-bottom",
  882. resizer: "ui-jqgrid-bootstrap"
  883. },
  884. bootstrapPrimary: {
  885. baseGuiStyle: "bootstrap",
  886. dialog: {
  887. closeButton: "btn btn-xs close",
  888. fmButton: "btn btn-primary"
  889. },
  890. searchDialog: {
  891. addRuleButton: "btn btn-xs btn-primary",
  892. deleteRuleButton: "btn btn-xs btn-primary",
  893. addGroupButton: "btn btn-xs btn-primary",
  894. deleteGroupButton: "btn btn-xs btn-primary"
  895. }
  896. },
  897. bootstrap4: {
  898. gBox: "ui-jqgrid-bootstrap",
  899. gView: "card",
  900. overlay: "modal-backdrop",
  901. loading: "alert alert-info",
  902. hDiv: "",
  903. hTable: "table table-hover table-sm table-bordered",
  904. colHeaders: "",
  905. states: {
  906. select: "table-success",
  907. disabled: "disabled ui-jqgrid-disablePointerEvents",
  908. hover: "active",
  909. hoverTh: "table-active",
  910. error: "danger",
  911. active: "active",
  912. textOfClickable: ""
  913. },
  914. dialog: {
  915. header: "modal-header",
  916. window: "modal ui-jqgrid-bootstrap",
  917. document: "modal-dialog",
  918. subdocument: "modal-content",
  919. body: "modal-body",
  920. footer: "modal-footer",
  921. content: "modal-content",
  922. hr: "d-none",
  923. closeButton: "btn btn-xs btn-outline-primary",
  924. fmButton: "btn btn-outline-secondary",
  925. dataField: "form-control",
  926. viewCellLabel: "",
  927. viewLabel: "control-label",
  928. viewCellData: "",
  929. viewData: "form-control",
  930. leftCorner: "",
  931. rightCorner: "",
  932. defaultCorner: ""
  933. },
  934. filterToolbar: {
  935. dataField: "form-control"
  936. },
  937. subgrid: {
  938. thSubgrid: "",
  939. rowSubTable: "",
  940. row: "",
  941. tdStart: "",
  942. tdWithIcon: "",
  943. buttonDiv: "",
  944. button: "btn btn-xs",
  945. tdData: "",
  946. legacyTable: "table table-condensed table-hover table-bordered"
  947. },
  948. grid: "table table-condensed table-hover table-bordered",
  949. gridRow: "",
  950. rowNum: "",
  951. gridFooter: "table table-hover table-condensed table-bordered",
  952. rowFooter: "",
  953. gridTitle: "",
  954. gridError: "alert alert-danger",
  955. gridErrorText: "sr-only",
  956. titleButton: "btn btn-xs btn-outline-primary",
  957. actionsDiv: "",
  958. actionsButton: "btn btn-xs btn-outline-secondary",
  959. toolbarUpper: "",
  960. toolbarBottom: "",
  961. pager: {
  962. pager: "card-footer",
  963. pagerButton: "btn btn-xs",
  964. pagerInput: "form-control",
  965. pagerSelect: "form-control"
  966. },
  967. navButton: "btn btn-xs",
  968. searchDialog: {
  969. operator: "form-control",
  970. label: "form-control",
  971. elem: "form-control",
  972. operationGroup: "form-inline",
  973. addRuleButton: "btn btn-xs btn-default",
  974. deleteRuleButton: "btn btn-xs btn-default",
  975. operationSelect: "form-control",
  976. addGroupButton: "btn btn-xs btn-default",
  977. deleteGroupButton: "btn btn-xs btn-default"
  978. },
  979. searchToolbar: {
  980. menu: "dropdown-menu",
  981. menuItem: "",
  982. menuItemButton: "dropdown-item",
  983. operButton: "btn btn-xs btn-outline-secondary",
  984. clearButton: "btn btn-xs btn-outline-secondary"
  985. },
  986. top: "ui-jqgrid-bootstrap-corner-top",
  987. bottom: "ui-jqgrid-bootstrap-corner-bottom",
  988. resizer: "ui-jqgrid-bootstrap"
  989. }
  990. },
  991. htmlDecode: function (value) {
  992. if (value && (value === "&nbsp;" ||
  993. value === "&#160;" ||
  994. (value.length === 1 && value.charCodeAt(0) === 160))) {
  995. return "";
  996. }
  997. return !value ?
  998. value :
  999. String(value)
  1000. .replace(/&gt;/g, ">")
  1001. .replace(/&lt;/g, "<")
  1002. .replace(/&#x27;/g, "'")
  1003. .replace(/&#x2F;/g, "\/")
  1004. .replace(/&#39;/g, "'")
  1005. .replace(/&#47;/g, "\/")
  1006. .replace(/&quot;/g, "\"")
  1007. .replace(/&amp;/g, "&");
  1008. },
  1009. htmlEncode: function (value) {
  1010. // see https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.231_-_HTML_Escape_Before_Inserting_Untrusted_Data_into_HTML_Element_Content
  1011. return !value ?
  1012. value :
  1013. String(value)
  1014. .replace(/&/g, "&amp;")
  1015. .replace(/"/g, "&quot;")
  1016. .replace(/'/g, "&#39;")
  1017. .replace(/\//g, "&#47;")
  1018. .replace(/</g, "&lt;")
  1019. .replace(/>/g, "&gt;");
  1020. },
  1021. oldEncodePostedData: function (value) {
  1022. return !value ?
  1023. value :
  1024. String(value)
  1025. .replace(/&/g, "&amp;")
  1026. .replace(/"/g, "&quot;")
  1027. .replace(/</g, "&lt;")
  1028. .replace(/>/g, "&gt;");
  1029. },
  1030. oldDecodePostedData: function (value) {
  1031. if (value && (value === "&nbsp;" ||
  1032. value === "&#160;" ||
  1033. (value.length === 1 && value.charCodeAt(0) === 160))) {
  1034. return "";
  1035. }
  1036. return !value ?
  1037. value :
  1038. String(value)
  1039. .replace(/&gt;/g, ">")
  1040. .replace(/&lt;/g, "<")
  1041. .replace(/&quot;/g, "\"")
  1042. .replace(/&amp;/g, "&");
  1043. },
  1044. clearArray: function (ar) {
  1045. // see http://jsperf.com/empty-javascript-array
  1046. while (ar.length > 0) {
  1047. ar.pop();
  1048. }
  1049. },
  1050. format: function (format) { //jqgformat
  1051. var args = $.makeArray(arguments).slice(1);
  1052. if (format == null) { format = ""; }
  1053. return format.replace(/\{(\d+)\}/g, function (m, i) {
  1054. return args[i];
  1055. });
  1056. },
  1057. template: function (format) { //jqgformat
  1058. var args = $.makeArray(arguments).slice(1), j, al = args.length;
  1059. if (format == null) {
  1060. format = "";
  1061. }
  1062. return format.replace(/\{([\w\-]+)(?:\:([\w\.]*)(?:\((\.*?)?\))?)?\}/g, function (m, i) {
  1063. var nmarr, k;
  1064. if (!isNaN(parseInt(i, 10))) {
  1065. return args[parseInt(i, 10)];
  1066. }
  1067. for (j = 0; j < al; j++) {
  1068. if ($.isArray(args[j])) {
  1069. nmarr = args[j];
  1070. k = nmarr.length;
  1071. while (k--) {
  1072. if (i === nmarr[k].nm) {
  1073. return nmarr[k].v;
  1074. }
  1075. }
  1076. }
  1077. }
  1078. });
  1079. },
  1080. msie: navigator.appName === "Microsoft Internet Explorer",
  1081. msiever: function () {
  1082. // Trident/4.0 - Internet Explorer 8,
  1083. // Trident/5.0 - Internet Explorer 9,
  1084. // Trident/6.0 - Internet Explorer 10
  1085. // Trident/7.0 - IE11
  1086. // Version tokens MSIE might not reflect the actual version of the browser
  1087. // If Compatibility View is enabled for a webpage or the browser mode is set to an earlier version
  1088. var rv = -1, match;
  1089. if (navigator.appName === "Microsoft Internet Explorer") {
  1090. match = /(MSIE) ([0-9]{1,}[.0-9]{0,})/.exec(navigator.userAgent);
  1091. if (match != null && match.length === 3) {
  1092. rv = parseFloat(match[2] || -1);
  1093. }
  1094. } else if (navigator.appName === "Netscape") {
  1095. match = /rv:([0-9]{1,}[.0-9]{0,})/.exec(navigator.userAgent);
  1096. if (match != null && match.length === 2) {
  1097. rv = parseFloat(match[1] || -1);
  1098. }
  1099. }
  1100. return rv;
  1101. },
  1102. fixMaxHeightOfDiv: function (height) {
  1103. // we place the fixing of maximal height in the method to allow easy
  1104. // to overwrite the method and to change the behaviour of jqGrid
  1105. // in case of usage virtual scrolling
  1106. if (navigator.appName === "Microsoft Internet Explorer") {
  1107. return Math.min(height, 1533917); // ??? 1022611
  1108. }
  1109. if (/(Firefox)/.exec(navigator.userAgent) != null) {
  1110. return Math.min(height, 17895696);
  1111. }
  1112. return height;
  1113. },
  1114. getRelativeRect: function (elem) {
  1115. var relativeTo = elem instanceof $ && elem.length > 0 ? elem[0] : elem,
  1116. relativeToOuterHeight = $(relativeTo).outerHeight(),
  1117. gbox = $(this).closest(".ui-jqgrid")[0],
  1118. rectRelativeTo, rectGbox;
  1119. if (!gbox) {
  1120. return { top: 0, left: 0 };
  1121. }
  1122. rectRelativeTo = relativeTo.getBoundingClientRect != null ?
  1123. relativeTo.getBoundingClientRect() :
  1124. $(relativeTo).offset();
  1125. rectGbox = gbox.getBoundingClientRect != null ?
  1126. gbox.getBoundingClientRect() :
  1127. $(gbox).offset();
  1128. return {
  1129. top: rectRelativeTo.top + relativeToOuterHeight - rectGbox.top,
  1130. //right: rectGbox.right - rectRelativeTo.right,
  1131. left: rectRelativeTo.left - rectGbox.left
  1132. };
  1133. },
  1134. getCellIndex: function (cell) {
  1135. var c = $(cell);
  1136. if (c.is("tr")) { return -1; }
  1137. c = (!c.is("td") && !c.is("th") ? c.closest("td,th") : c)[0];
  1138. if (c == null) { return -1; }
  1139. if (jgrid.msie) { return $.inArray(c, c.parentNode.cells); }
  1140. return c.cellIndex;
  1141. },
  1142. stripHtml: function (v) {
  1143. v = String(v);
  1144. if (v) {
  1145. v = v.replace(/<("[^"]*"|'[^']*'|[^'">])*>/gi, "");
  1146. return (v && v !== "&nbsp;" && v !== "&#160;") ? v.replace(/"/g, "'") : "";
  1147. }
  1148. return v;
  1149. },
  1150. stripPref: function (pref, id) {
  1151. var obj = $.type(pref);
  1152. if (obj === "string" || obj === "number") {
  1153. pref = String(pref);
  1154. id = pref !== "" ? String(id).replace(String(pref), "") : id;
  1155. }
  1156. return id;
  1157. },
  1158. getRes: function (basePath, path) {
  1159. var pathParts = path.split("."), n = pathParts.length, i;
  1160. if (basePath == null) {
  1161. return undefined;
  1162. }
  1163. for (i = 0; i < n; i++) {
  1164. if (!pathParts[i]) {
  1165. return null;
  1166. }
  1167. basePath = basePath[pathParts[i]];
  1168. if (basePath === undefined) {
  1169. break;
  1170. }
  1171. if (typeof basePath === "string") {
  1172. return basePath;
  1173. }
  1174. }
  1175. return basePath;
  1176. },
  1177. parseDate: function (format, date, newformat, opts) {
  1178. // It seems that the code was "imported" by Tony from http://blog.stevenlevithan.com/archives/date-time-format
  1179. // Thus I include the reference to original
  1180. // Date Format 1.2.3 (c) 2007-2009 Steven Levithan <stevenlevithan.com> MIT license
  1181. // The code can be found on https://github.com/felixge/node-dateformat/blob/master/lib/dateformat.js
  1182. // It would be probabbly good idea to support original date format additionally to the
  1183. // PHP data format used below.
  1184. var token = /\\.|[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g, dM, k, hl, timestamp = 0, offset = 0,
  1185. timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[\-+]\d{4})?)\b/g,
  1186. timezoneClip = /[^\-+\dA-Z]/g,
  1187. msMatch = ((typeof date === "string") ? date.match(/^\/Date\((([\-+])?[0-9]+)(([\-+])([0-9]{2})([0-9]{2}))?\)\/$/) : null),
  1188. pad = function (value, length) {
  1189. value = String(value);
  1190. length = parseInt(length, 10) || 2;
  1191. while (value.length < length) { value = "0" + value; }
  1192. return value;
  1193. },
  1194. ts = { m: 1, d: 1, y: 1970, h: 0, i: 0, s: 0, u: 0 },
  1195. h12To24 = function (ampm, h) {
  1196. if (ampm === 0) {
  1197. if (h === 12) { h = 0; }
  1198. } else {
  1199. if (h !== 12) { h += 12; }
  1200. }
  1201. return h;
  1202. },
  1203. getDefOptions = function (p, options) {
  1204. // It could be multiple sources for date properties used below.
  1205. // Let us we need to use srcformat. The highest priority have
  1206. // opts.srcformat if it is specified. If the srcformat is not
  1207. // specified of if opts is undefined then one should use
  1208. // $.jgrid.locales.de.formatter.date.srcformat, for example,
  1209. // where "de" part is an example of the locale of the grid
  1210. // ($t.p.locale). There as the third important case existing
  1211. // because of compatibility only. The old place for formatter.date.srcformat
  1212. // was $.jgrid.formatter.date.srcformat (without "locales.de" part
  1213. // in the middle). Now such option should be not used, but
  1214. // because of some code where the old code of jqGrid was customized
  1215. // using $.jgrid.formatter instead of $.jgrid.locales[locale].formatter,
  1216. // one have to take in consideration the case. If such setting exist
  1217. // then one should use it (should use $.jgrid.formatter.date.srcformat)
  1218. // BEFORE the new default $.jgrid.locales.de.formatter.date.srcformat.
  1219. // As the result sue should search for all below properties in 3 sources:
  1220. // first in opts || {}, second in
  1221. // ($.jgrid.formatter || {}).date || {}
  1222. // and finally, if $t.p != null && $t.p.locale != null, under
  1223. // $.jgrid.locales[$t.p.locale].formatter.date
  1224. // oder (it's the same, just rewritten) under
  1225. // ((locales[$t.p.locale] || {}).formatter || {}).date
  1226. var props = ["AmPm", "dayNames", "masks", "monthNames", "userLocalTime", "parseRe", "S", "srcformat"],
  1227. root1 = options || {},
  1228. root2 = (jgrid.formatter || {}).date || {},
  1229. root3 = ((locales[(p || $.jgrid.defaults).locale] || {}).formatter || {}).date,
  1230. iProp, nProps = props.length, result = {}, prop;
  1231. for (iProp = 0; iProp < nProps; iProp++) {
  1232. prop = props[iProp];
  1233. if (root1[prop] !== undefined) { // root1.hasOwnProperty(prop)
  1234. result[prop] = root1[prop];
  1235. } else if (root2[prop] !== undefined) {// root2.hasOwnProperty(prop)
  1236. result[prop] = root2[prop];
  1237. } else if (root3[prop] !== undefined) {// root3.hasOwnProperty(prop)
  1238. result[prop] = root3[prop];
  1239. }
  1240. }
  1241. return result;
  1242. };
  1243. //opts = $.extend({}, (jgrid.formatter || {}).date,
  1244. // $t.p != null ?
  1245. // jgrid.getRes(locales[$t.p.locale], "formatter.date") || {} :
  1246. // {},
  1247. // opts || {});
  1248. opts = getDefOptions(this.p, opts);
  1249. // old lang files
  1250. if (opts.parseRe === undefined) {
  1251. opts.parseRe = /[#%\\\/:_;.,\t\s\-]/;
  1252. }
  1253. if (opts.masks.hasOwnProperty(format)) { format = opts.masks[format]; }
  1254. if (date && date != null) {
  1255. if (!isNaN(date) && String(format).toLowerCase() === "u") {
  1256. //Unix timestamp
  1257. timestamp = new Date(parseFloat(date) * 1000);
  1258. } else if (!isNaN(date) && String(format).toLowerCase() === "u1000") {
  1259. // Milliseconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
  1260. timestamp = new Date(parseFloat(date));
  1261. } else if (date.constructor === Date) {
  1262. timestamp = date;
  1263. // Microsoft date format support
  1264. } else if (msMatch !== null) {
  1265. timestamp = new Date(parseInt(msMatch[1], 10));
  1266. if (msMatch[3]) {
  1267. offset = Number(msMatch[5]) * 60 + Number(msMatch[6]);
  1268. offset *= ((msMatch[4] === "-") ? 1 : -1);
  1269. offset -= timestamp.getTimezoneOffset();
  1270. timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
  1271. }
  1272. } else {
  1273. //Support ISO8601Long that have Z at the end to indicate UTC timezone
  1274. if (opts.srcformat === "ISO8601Long" && date.charAt(date.length - 1) === "Z") {
  1275. offset -= (new Date()).getTimezoneOffset();
  1276. }
  1277. date = String(date).replace(/\T/g, "#").replace(/\t/, "%").split(opts.parseRe);
  1278. format = format.replace(/\T/g, "#").replace(/\t/, "%").split(opts.parseRe);
  1279. // parsing for month names and time
  1280. for (k = 0, hl = Math.min(format.length, date.length); k < hl; k++) {
  1281. switch (format[k]) {
  1282. case "M":
  1283. // A short textual representation of a month, three letters Jan through Dec
  1284. dM = $.inArray(date[k], opts.monthNames);
  1285. if (dM !== -1 && dM < 12) {
  1286. date[k] = dM + 1;
  1287. ts.m = date[k];
  1288. }
  1289. break;
  1290. case "F":
  1291. // A full textual representation of a month, such as January or March
  1292. dM = $.inArray(date[k], opts.monthNames, 12);
  1293. if (dM !== -1 && dM > 11) {
  1294. date[k] = dM + 1 - 12;
  1295. ts.m = date[k];
  1296. }
  1297. break;
  1298. case "n":
  1299. // Numeric representation of a month, without leading zeros 1 through 12
  1300. ts.m = parseInt(date[k], 10);
  1301. break;
  1302. case "j":
  1303. // Day of the month without leading zeros 1 to 31
  1304. ts.d = parseInt(date[k], 10);
  1305. break;
  1306. case "g":
  1307. // 12-hour format of an hour without leading zeros 1 through 12
  1308. ts.h = parseInt(date[k], 10);
  1309. break;
  1310. case "a":
  1311. // Lowercase Ante meridiem and Post meridiem am or pm
  1312. dM = $.inArray(date[k], opts.AmPm);
  1313. if (dM !== -1 && dM < 2 && date[k] === opts.AmPm[dM]) {
  1314. date[k] = dM;
  1315. ts.h = h12To24(date[k], ts.h);
  1316. }
  1317. break;
  1318. case "A":
  1319. // Uppercase Ante meridiem and Post meridiem AM or PM
  1320. dM = $.inArray(date[k], opts.AmPm);
  1321. if (dM !== -1 && dM > 1 && date[k] === opts.AmPm[dM]) {
  1322. date[k] = dM - 2;
  1323. ts.h = h12To24(date[k], ts.h);
  1324. }
  1325. break;
  1326. }
  1327. if (date[k] !== undefined && date[k] !== "" && !isNaN(date[k])) {
  1328. ts[format[k].toLowerCase()] = parseInt(date[k], 10);
  1329. }
  1330. }
  1331. if (ts.f) { ts.m = ts.f; }
  1332. if (ts.m === 0 && ts.y === 0 && ts.d === 0) {
  1333. return "&#160;";
  1334. }
  1335. ts.m = parseInt(ts.m, 10) - 1;
  1336. var ty = ts.y;
  1337. if (ty >= 70 && ty <= 99) {
  1338. ts.y = 1900 + ts.y;
  1339. } else if (ty >= 0 && ty <= 69) {
  1340. ts.y = 2000 + ts.y;
  1341. }
  1342. timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
  1343. //Apply offset to show date as local time.
  1344. if (offset !== 0) {
  1345. timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
  1346. }
  1347. }
  1348. } else {
  1349. timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
  1350. }
  1351. if (opts.userLocalTime && offset === 0) {
  1352. offset -= (new Date()).getTimezoneOffset();
  1353. if (offset !== 0) {
  1354. timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
  1355. }
  1356. }
  1357. if (newformat === undefined) {
  1358. return timestamp;
  1359. }
  1360. if (opts.masks.hasOwnProperty(newformat)) {
  1361. newformat = opts.masks[newformat];
  1362. } else if (!newformat) {
  1363. newformat = "Y-m-d";
  1364. }
  1365. if (newformat.toLowerCase() === "u1000") {
  1366. return timestamp.getTime();
  1367. }
  1368. var hours = timestamp.getHours(), // a Number, from 0 to 23, representing the hour
  1369. i = timestamp.getMinutes(),
  1370. j = timestamp.getDate(),
  1371. n = timestamp.getMonth() + 1,
  1372. o = timestamp.getTimezoneOffset(),
  1373. s = timestamp.getSeconds(),
  1374. u = timestamp.getMilliseconds(),
  1375. w = timestamp.getDay(),
  1376. year = timestamp.getFullYear(), // a Number, representing four digits, representing the year. Examples: 1999 or 2003
  1377. dayOfWeek = (w + 6) % 7 + 1, // numeric representation of the day of the week. 1 (for Monday) through 7 (for Sunday)
  1378. z = (new Date(year, n - 1, j) - new Date(year, 0, 1)) / 86400000,
  1379. weekNumberOfYear = dayOfWeek < 5 ?
  1380. Math.floor((z + dayOfWeek - 1) / 7) + 1 :
  1381. Math.floor((z + dayOfWeek - 1) / 7) || ((new Date(year - 1, 0, 1).getDay() + 6) % 7 < 4 ? 53 : 52),
  1382. flags = {
  1383. // Day
  1384. d: pad(j), // Day of the month, 2 digits with leading zeros 01 to 31
  1385. D: opts.dayNames[w], // A textual representation of a day, three letters. Mon through Sun
  1386. j: j, // Day of the month without leading zeros 1 to 31
  1387. l: opts.dayNames[w + 7], // A full textual representation of the day of the week. Sunday through Saturday
  1388. N: dayOfWeek, // ISO-8601 numeric representation of the day of the week. 1 (for Monday) through 7 (for Sunday)
  1389. S: opts.S(j), // English ordinal suffix for the day of the month, 2 characters. st, nd, rd or th. Works well with j
  1390. w: w, // Numeric representation of the day of the week. 0 (for Sunday) through 6 (for Saturday)
  1391. z: z, // The day of the year (starting from 0). 0 through 365
  1392. // Week.
  1393. W: weekNumberOfYear, // ISO-8601 week number of year, weeks starting on Monday. Example: 42 (the 42nd week in the year)
  1394. // Month
  1395. F: opts.monthNames[n - 1 + 12], // A full textual representation of a month, such as January or March. January through December
  1396. m: pad(n), // Numeric representation of a month, with leading zeros. 01 through 12
  1397. M: opts.monthNames[n - 1], // A short textual representation of a month, three letters. Jan through Dec
  1398. n: n, // Numeric representation of a month, without leading zeros. 1 through 12
  1399. t: "?", // Number of days in the given month. 28 through 31
  1400. // Year
  1401. L: "?", // Whether it's a leap year. 1 if it is a leap year, 0 otherwise.
  1402. o: "?", // SO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. Examples: 1999 or 2003
  1403. Y: year, // A full numeric representation of a year, 4 digits. Examples: 1999 or 2003
  1404. y: String(year).substring(2), // A two digit representation of a year. Examples: 99 or 03
  1405. // Time
  1406. a: hours < 12 ? opts.AmPm[0] : opts.AmPm[1], // Lowercase Ante meridiem and Post meridiem: am or pm
  1407. A: hours < 12 ? opts.AmPm[2] : opts.AmPm[3], // Uppercase Ante meridiem and Post meridiem: AM or PM
  1408. B: "?", // Swatch Internet time 000 through 999
  1409. g: hours % 12 || 12, // 12-hour format of an hour without leading zeros 1 through 12
  1410. G: hours, // 24-hour format of an hour without leading zeros. 0 through 23
  1411. h: pad(hours % 12 || 12), // 12-hour format of an hour with leading zeros: 01 through 12
  1412. H: pad(hours), // 24-hour format of an hour with leading zeros: 00 through 23
  1413. i: pad(i), // Minutes with leading zeros: 00 to 59
  1414. s: pad(s), // Seconds, with leading zeros: 00 through 59
  1415. u: u, // Microseconds. Example: 654321
  1416. // Timezone
  1417. e: "?", // Timezone identifier. Examples: UTC, GMT, Atlantic/Azores
  1418. I: "?", // Whether or not the date is in daylight saving time. 1 if Daylight Saving Time, 0 otherwise.
  1419. O: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4), // Difference to Greenwich time (GMT) in hours. Example: +0200
  1420. P: "?", // Difference to Greenwich time (GMT) with colon between hours and minutes. Example: +02:00
  1421. T: (String(timestamp).match(timezone) || [""]).pop().replace(timezoneClip, ""), // Timezone abbreviation. Examples: EST, MDT
  1422. Z: "?", // Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. -43200 through 50400
  1423. // Full Date/Time
  1424. c: "?", // ISO 8601 date. Example: 2004-02-12T15:19:21+00:00
  1425. r: "?", // RFC 2822 formatted date. Example: Thu, 21 Dec 2000 16:01:07 +0200
  1426. U: Math.floor(timestamp / 1000) // Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
  1427. };
  1428. return newformat.replace(token, function ($0) {
  1429. return flags.hasOwnProperty($0) ? flags[$0] : $0.substring(1);
  1430. });
  1431. },
  1432. parseDateToNumber: function (format, date) {
  1433. var datetime = jgrid.parseDate.call(this, format, date);
  1434. // datetime could be the string "&#160;"
  1435. return datetime instanceof Date ? datetime.getTime() : 0;
  1436. },
  1437. jqID: function (sid) {
  1438. return String(sid).replace(/[!"#$%&'()*+,.\/:; <=>?@\[\\\]\^`{|}~]/g, "\\$&");
  1439. },
  1440. /**
  1441. * @param {COMPONENT_NAMES} componentName
  1442. */
  1443. getGridComponentId: function (componentName) {
  1444. var self = this;
  1445. if (self.p == null || !self.p.id) {
  1446. return ""; // return empty string
  1447. }
  1448. var id = self.p.id;
  1449. switch (componentName) {
  1450. case COMPONENT_NAMES.GRID:
  1451. return id;
  1452. case COMPONENT_NAMES.GRID_BOX_DIV:
  1453. return "gbox_" + id;
  1454. case COMPONENT_NAMES.GRID_VIEW_DIV:
  1455. return "gview_" + id;
  1456. case COMPONENT_NAMES.DIALOG_ALERT_DIV: // footer/summary table
  1457. return "alertmod_" + id;
  1458. case COMPONENT_NAMES.COLUMN_RESIZER_DIV:
  1459. return "rs_m" + id;
  1460. case COMPONENT_NAMES.HEADER_SELECT_ALL_ROWS_CHECKBOX:
  1461. return "cb_" + id;
  1462. case COMPONENT_NAMES.SEARCH_OPERATION_MENU_UL:
  1463. return "sopt_menu";
  1464. default:
  1465. return ""; // return empty string
  1466. }
  1467. },
  1468. /**
  1469. * @param {COMPONENT_NAMES} componentName
  1470. */
  1471. getGridComponentIdSelector: function (componentName) {
  1472. var id = jgrid.getGridComponentId.call(this, componentName);
  1473. return id ? "#" + jgrid.jqID(id) : "";
  1474. },
  1475. isHTMLElement: function (elem) {
  1476. // see http://stackoverflow.com/a/384380/315935
  1477. return (typeof HTMLElement === "object" || typeof HTMLElement === "function") ?
  1478. elem instanceof HTMLElement : //DOM2
  1479. elem != null && typeof elem === "object" && elem.nodeType === 1 && typeof elem.nodeName === "string";
  1480. },
  1481. /**
  1482. * @param {COMPONENT_NAMES} componentName
  1483. */
  1484. getGridComponent: function (componentName, $p) {// , p1
  1485. var p;
  1486. if ($p instanceof $ || $p.length > 0) {
  1487. p = $p[0];
  1488. } else if (jgrid.isHTMLElement($p)) {
  1489. p = $p;
  1490. $p = $(p);
  1491. } else {
  1492. return $(); // return empty jQuery object
  1493. }
  1494. switch (componentName) {
  1495. case COMPONENT_NAMES.BODY_TABLE: // get body table from bDiv
  1496. return $p.hasClass("ui-jqgrid-bdiv") ? $p.children("div").children(".ui-jqgrid-btable") : $();
  1497. case COMPONENT_NAMES.HEADER_TABLE: // header table from bDiv
  1498. return $p.hasClass("ui-jqgrid-hdiv") ? $p.children("div").children(".ui-jqgrid-htable") : $();
  1499. case COMPONENT_NAMES.FOOTER_TABLE: // footer/summary table from sDiv
  1500. return $p.hasClass("ui-jqgrid-sdiv") ? $p.children("div").children(".ui-jqgrid-ftable") : $();
  1501. case COMPONENT_NAMES.FROZEN_HEADER_TABLE: // header table from bDiv
  1502. return $p.hasClass("ui-jqgrid-hdiv") ? $p.children(".ui-jqgrid-htable") : $();
  1503. case COMPONENT_NAMES.FROZEN_FOOTER_TABLE: // footer/summary table from sDiv
  1504. return $p.hasClass("ui-jqgrid-sdiv") ? $p.children(".ui-jqgrid-ftable") : $();
  1505. case COMPONENT_NAMES.BODY_DIV: // get bDiv of grid (bTable)
  1506. return $p.hasClass("ui-jqgrid-btable") && p.grid != null ? $(p.grid.bDiv) : $();
  1507. case COMPONENT_NAMES.HEADER_DIV: // get hDiv of grid (bTable)
  1508. return $p.hasClass("ui-jqgrid-btable") && p.grid != null ? $(p.grid.hDiv) : $();
  1509. case COMPONENT_NAMES.FOOTER_DIV: // get sDiv of grid (bTable)
  1510. return $p.hasClass("ui-jqgrid-btable") && p.grid != null ? $(p.grid.sDiv) : $();
  1511. //case "colHeader": // p should be iCol
  1512. // return !isNaN(p1) && p.grid != null && p.grid.headers != null && p.grid.headers[p1] != null ?
  1513. // $(p.grid.headers[p1].el) : $();
  1514. default:
  1515. return $(); // return empty jQuery object
  1516. }
  1517. },
  1518. fixScrollOffsetAndhBoxPadding: function () {
  1519. var self = this, grid = self.grid;
  1520. if (!grid) {
  1521. return;
  1522. }
  1523. var p = self.p, bDiv = grid.bDiv,
  1524. fixhBox = function (hDiv) {
  1525. var $hDivhBox = $(hDiv).children("div").first();
  1526. $hDivhBox.css($hDivhBox.hasClass("ui-jqgrid-hbox-rtl") ? "padding-left" : "padding-right", p.scrollOffset);
  1527. hDiv.scrollLeft = bDiv.scrollLeft;
  1528. };
  1529. if ($(bDiv).width() > 0) {
  1530. p.scrollOffset = (bDiv.offsetWidth - bDiv.clientWidth); // can be 0 if no scrollbar exist
  1531. // TODO: add detection of the width of vertical scroll bar if the grid is hidden
  1532. // at the moment of executing fixScrollOffsetAndhBoxPadding (for example inside of inactive jQuery UI Tab)
  1533. // one need just create close construction with visible:hidden style, add to body and get its width
  1534. fixhBox(grid.hDiv);
  1535. if (grid.sDiv) {
  1536. fixhBox(grid.sDiv);
  1537. }
  1538. }
  1539. },
  1540. mergeCssClasses: function () {
  1541. var args = $.makeArray(arguments), map = {}, i, j, ar, cssClass, classes = [];
  1542. for (i = 0; i < args.length; i++) {
  1543. ar = String(args[i]).replace(/[\t\r\n\f]/g, " ").split(" ");
  1544. for (j = 0; j < ar.length; j++) {
  1545. cssClass = ar[j];
  1546. if (cssClass !== "" && !map.hasOwnProperty(cssClass)) {
  1547. map[cssClass] = true;
  1548. classes.push(cssClass);
  1549. }
  1550. }
  1551. }
  1552. return classes.join(" ");
  1553. },
  1554. hasOneFromClasses: function (elem, classes) {
  1555. var $elem = $(elem),
  1556. arClasses = String(classes).replace(/[\t\r\n\f]/g, " ").split(" "),
  1557. n = arClasses.length,
  1558. i;
  1559. for (i = 0; i < n; i++) {
  1560. if ($elem.hasClass(arClasses[i])) {
  1561. return true;
  1562. }
  1563. }
  1564. return false;
  1565. },
  1566. hasAllClasses: function (elem, classes) {
  1567. // the current implementation of jQuery.hasClass can work with multiple classes,
  1568. // but the classes HAVE TO BE in exact the same order. jQuery.hasClass just
  1569. // search for classes using indexOf.
  1570. // (see https://github.com/jquery/jquery/blob/1.11.3/src/attributes/classes.js#L143-L154)
  1571. // Thus we cant's use it to test whether an element has the list of all the classes
  1572. // and we introduces the helper method hasAllClasses
  1573. var $elem = $(elem),
  1574. arClasses = String(classes).replace(/[\t\r\n\f]/g, " ").split(" "),
  1575. n = arClasses.length,
  1576. i;
  1577. for (i = 0; i < n; i++) {
  1578. if (!$elem.hasClass(arClasses[i])) {
  1579. return false;
  1580. }
  1581. }
  1582. return true;
  1583. },
  1584. detectRowEditing: function (rowid) {
  1585. //var i, savedRowInfo, tr, self = this, rows = self.rows, p = self.p, isFunction = $.isFunction;
  1586. if (!this.grid || this.p == null || this.p.editingInfo == null || this.p.editingInfo[rowid] == null) {
  1587. return null; // this is not a grid or the row is not editing now
  1588. }
  1589. return this.p.editingInfo[rowid];
  1590. },
  1591. // The method returns jQuery wrapper with the cell (<td>) of the row.
  1592. // It can return jQuery wrapper with two cells in case of usage frozen data:
  1593. // one cell of the main grid and another cell with the corresponding cell from the frozen body table
  1594. getCell: function (tr, iCol) {
  1595. var grid = this.grid, p = this.p, frozenRows, $td;
  1596. if (!grid || !p) { return $(); } // not a grid
  1597. if (tr instanceof $ || tr.length > 0) {
  1598. tr = tr[0]; // unwrap jQuery object to DOM element
  1599. }
  1600. if (!((typeof HTMLTableRowElement === "object" || typeof HTMLTableRowElement === "function") && tr instanceof HTMLTableRowElement) || tr.cells == null) { // the line will be failed in IE7
  1601. return $(); // return empty jQuery object
  1602. }
  1603. $td = $(tr.cells[iCol]);
  1604. frozenRows = grid.fbRows;
  1605. return frozenRows != null && iCol < frozenRows[0].cells.length ?
  1606. $td.add(frozenRows[tr.rowIndex].cells[iCol]) :
  1607. $td;
  1608. },
  1609. getDataFieldOfCell: function (tr, iCol) {
  1610. var p = this.p, $td = jgrid.getCell.call(this, tr, iCol), $dataElement;
  1611. if (p.treeGrid && $td.children("div.tree-wrap").length > 0) {
  1612. $td = $td.children("span.cell-wrapperleaf,span.cell-wrapper");
  1613. }
  1614. if (p.colModel[iCol].autoResizable) {
  1615. $dataElement = $td.children("span." + p.autoResizing.wrapperClassName);
  1616. if ($dataElement.length === 0) { // for example, td is in editing mode
  1617. $dataElement = $td;
  1618. }
  1619. } else {
  1620. $dataElement = $td;
  1621. }
  1622. return $dataElement;
  1623. },
  1624. enumEditableCells: function (tr, mode, callback) {
  1625. var self = this, grid = self.grid, rows = self.rows, p = self.p;
  1626. if (grid == null || rows == null || p == null || tr == null || tr.rowIndex == null || !tr.id || !$.isFunction(callback)) {
  1627. return null; // this is not a grid or tr is not tr
  1628. }
  1629. var iCol, colModel = p.colModel, nCol = colModel.length, cm, nm, options, id, pos, item,
  1630. isEditable, iRow = tr.rowIndex, td, $dataElement, dataWidth,
  1631. frozenRows = grid.fbRows, frozen = frozenRows != null,
  1632. trFrozen = frozen ? frozenRows[iRow] : null;
  1633. // normalize tr if required
  1634. if (frozen/* && !$.contains(self, tr)*/) {
  1635. // The event could be inside of frozen div.
  1636. // Thus tr could be the same as trFrozen
  1637. // We normalize it based on the rowIndex.
  1638. tr = self.rows[iRow];
  1639. }
  1640. for (iCol = 0; iCol < nCol; iCol++) {
  1641. cm = colModel[iCol];
  1642. nm = cm.name;
  1643. if (nm !== "cb" && nm !== "subgrid" && nm !== "rn") {
  1644. if (frozen && !cm.frozen) {
  1645. frozen = false;
  1646. }
  1647. td = (frozen ? trFrozen : tr).cells[iCol];
  1648. $dataElement = $(td);
  1649. if (!$dataElement.hasClass("not-editable-cell")) {
  1650. dataWidth = $dataElement.width();
  1651. if (p.treeGrid === true && nm === p.ExpandColumn) {
  1652. dataWidth -= $dataElement.children("div.tree-wrap").outerWidth();
  1653. $dataElement = $dataElement.children("span.cell-wrapperleaf,span.cell-wrapper").first();
  1654. } else {
  1655. dataWidth = 0; // we can test it in the callback and use width:auto in the case
  1656. }
  1657. id = stripPref(p.idPrefix, tr.id);
  1658. options = {
  1659. rowid: tr.id,
  1660. id: id,
  1661. iCol: iCol,
  1662. iRow: iRow,
  1663. cmName: nm,
  1664. cm: cm,
  1665. mode: mode,
  1666. td: td,
  1667. tr: tr,
  1668. trFrozen: trFrozen,
  1669. dataElement: $dataElement[0],
  1670. dataWidth: dataWidth
  1671. };
  1672. if (p.datatype === "local") {
  1673. pos = p._index[id];
  1674. item = pos != null ? p.data[pos] : undefined;
  1675. if (item) {
  1676. options.item = item;
  1677. }
  1678. }
  1679. if (!cm.edittype) { cm.edittype = "text"; }
  1680. if (((p.editingInfo[tr.id] || {}).editable || {}).hasOwnProperty(nm)) {
  1681. // if the cell in already editing
  1682. isEditable = p.editingInfo[tr.id].editable[nm];
  1683. } else {
  1684. isEditable = cm.editable;
  1685. isEditable = $.isFunction(isEditable) ?
  1686. isEditable.call(self, options) :
  1687. isEditable;
  1688. }
  1689. if (isEditable === true || isEditable === "hidden") {
  1690. options.editable = isEditable;
  1691. if (callback.call(self, options) === false) { break; }
  1692. }
  1693. }
  1694. }
  1695. }
  1696. },
  1697. getEditedValue: function ($dataFiled, cm, valueText, editable) {
  1698. var result, checkBoxValues, newformat, $field, values, texts,
  1699. formatoptions = cm.formatoptions || {}, editoptions = cm.editoptions || {},
  1700. customValue = editoptions.custom_value,
  1701. nameSelector = "[name=" + jgrid.jqID(cm.name) + "]", $t = this, $self = $($t);
  1702. if (editable === "hidden" || editable === "readonly") {
  1703. // the implementation from the next line can be improved
  1704. return $($t).jqGrid("getCell", $dataFiled.closest("tr.jqgrow").attr("id"), cm.name);
  1705. }
  1706. switch (cm.edittype) {
  1707. case "checkbox":
  1708. checkBoxValues = ["Yes", "No"];
  1709. if (typeof editoptions.value === "string") {
  1710. checkBoxValues = editoptions.value.split(":");
  1711. }
  1712. result = $dataFiled.find("input[type=checkbox]").is(":checked") ? checkBoxValues[0] : checkBoxValues[1];
  1713. break;
  1714. case "text":
  1715. case "password":
  1716. case "textarea":
  1717. case "button":
  1718. $field = $dataFiled.find("input" + nameSelector + ",textarea" + nameSelector);
  1719. result = $field.val();
  1720. if ($field.prop("type") === "date" && String(result).split("-").length === 3) {
  1721. newformat = formatoptions.newformat || $self.jqGrid("getGridRes", "formatter.date.newformat");
  1722. result = jgrid.parseDate.call($t, "Y-m-d", result, newformat);
  1723. }
  1724. break;
  1725. case "select":
  1726. $field = $dataFiled.find("select option:selected");
  1727. if (editoptions.multiple) {
  1728. values = [];
  1729. texts = [];
  1730. $field.each(function () {
  1731. values.push($(this).val());
  1732. texts.push($(this).text());
  1733. });
  1734. result = values.join(",");
  1735. valueText.text = texts.join(",");
  1736. } else {
  1737. result = $field.val();
  1738. valueText.text = $field.text();
  1739. }
  1740. valueText.value = result;
  1741. break;
  1742. case "custom":
  1743. try {
  1744. if ($.isFunction(customValue)) {
  1745. result = customValue.call($t, $dataFiled.find(".customelement"), "get");
  1746. if (result === undefined) {
  1747. throw "e2";
  1748. }
  1749. } else {
  1750. throw "e1";
  1751. }
  1752. } catch (e) {
  1753. var errorText, infoDialog = jgrid.info_dialog,
  1754. getRes = function (path) { $self.jqGrid("getGridRes", path); };
  1755. switch (String(e)) {
  1756. case "e1":
  1757. errorText = "function 'custom_value' " + getRes("edit.msg.nodefined");
  1758. break;
  1759. case "e2":
  1760. break;
  1761. default:
  1762. errorText = e.message;
  1763. break;
  1764. }
  1765. if (infoDialog && $.isFunction(infoDialog)) {
  1766. infoDialog.call($t, getRes("errors.errcap"), errorText, getRes("edit.bClose"));
  1767. } else {
  1768. ($.isFunction(defaults.fatalError) ? defaults.fatalError : alert)(errorText);
  1769. }
  1770. }
  1771. break;
  1772. default:
  1773. result = $dataFiled.find("*" + nameSelector).text();
  1774. break;
  1775. }
  1776. return result;
  1777. },
  1778. guid: 1,
  1779. uidPref: "jqg",
  1780. randId: function (prefix) {
  1781. return (prefix || jgrid.uidPref) + (jgrid.guid++);
  1782. },
  1783. getAccessor: function (obj, expr) {
  1784. var ret, p, prm = [], i;
  1785. if ($.isFunction(expr)) { return expr(obj); }
  1786. if (obj != null && obj.hasOwnProperty(expr)) {
  1787. return obj[expr];
  1788. }
  1789. try {
  1790. if (typeof expr === "string") {
  1791. prm = expr.split(".");
  1792. }
  1793. i = prm.length;
  1794. if (i) {
  1795. ret = obj;
  1796. while (ret != null && i--) {
  1797. p = prm.shift();
  1798. if (ret.hasOwnProperty(p)) {
  1799. ret = ret[p];
  1800. } else {
  1801. ret = undefined;
  1802. }
  1803. }
  1804. }
  1805. } catch (ignore) { }
  1806. return ret;
  1807. },
  1808. getXmlData: function (obj, expr, returnObj) {
  1809. var m = typeof expr === "string" ? expr.match(/^(.*)\[(\w+)\]$/) : null;
  1810. if ($.isFunction(expr)) { return expr(obj); }
  1811. if (m && m[2]) {
  1812. // m[2] is the attribute selector
  1813. // m[1] is an optional element selector
  1814. // examples: "[id]", "rows[page]"
  1815. return m[1] ? $(m[1], obj).attr(m[2]) : $(obj).attr(m[2]);
  1816. }
  1817. if (obj === undefined) {
  1818. //alert("expr");
  1819. return undefined;
  1820. }
  1821. // !!! one should never use another form $(expr, obj) if obj could be undefined
  1822. // In the case the $(expr, obj) could be $("someString") and jQuery can
  1823. // parse it as array of characters ($("someString").length will be "someString".length) !!!
  1824. // The problem take place if expr is not string object, but object new String("someString").
  1825. // The problem can exist if one use $.each with array of strings.
  1826. // The "this" inside of $.each is the string converted to object.
  1827. var ret = $(obj).find(expr);
  1828. if (returnObj) { return ret; }
  1829. //$(expr, obj).filter(":last"); // we use ":last" to be more compatible with old version of jqGrid
  1830. return ret.length > 0 ? $(ret).text() : undefined;
  1831. },
  1832. cellWidth: function () {
  1833. // TODO: use all other classes in grid. Probably one should set the visibility explicitly to show (display:block)
  1834. var $testDiv = $("<div class='ui-jqgrid' style='left:10000px'><div class='ui-jqgrid-view'><div class='ui-jqgrid-bdiv'><table class='ui-jqgrid-btable' style='width:5px;'><tr class='jqgrow'><td style='width:5px;display:block;'></td></tr></table></div></div></div>"),
  1835. testCell = $testDiv.appendTo("body")
  1836. .find("td")
  1837. .width();
  1838. $testDiv.remove();
  1839. return Math.abs(testCell - 5) > 0.1;
  1840. },
  1841. isCellClassHidden: function (className) {
  1842. if (className == null || className === "") {
  1843. return false;
  1844. } else {
  1845. var $testDiv = $("<div class='ui-jqgrid' style='left:10000px'><div class='ui-jqgrid-view'><div class='ui-jqgrid-bdiv'><table class='ui-jqgrid-btable' style='width:5px;'><tr class='jqgrow'><td style='width:5px;' class='" + (className || "") + "'></td></tr></table></div></div></div>"),
  1846. isHidden = $testDiv.appendTo("body")
  1847. .find("td")
  1848. .is(":hidden");
  1849. $testDiv.remove();
  1850. return isHidden;
  1851. }
  1852. },
  1853. cell_width: true,
  1854. ajaxOptions: {},
  1855. from: function (source) {
  1856. // Original Author Hugo Bonacci
  1857. // License MIT http://jlinq.codeplex.com/license
  1858. var context = this,
  1859. /**
  1860. * @private
  1861. * @class
  1862. */
  1863. QueryObject = function (d, q) {
  1864. var self = this,
  1865. _data = d,
  1866. _usecase = true,
  1867. _trim = false,
  1868. _query = q,
  1869. _stripNum = /[\$,%]/g,
  1870. _lastCommand = null,
  1871. _lastField = null,
  1872. _orDepth = 0,
  1873. _negate = false,
  1874. _queuedOperator = "",
  1875. _sorting = [],
  1876. toString = Object.prototype.toString;
  1877. if (typeof d === "object" && d.push) {
  1878. if (d.length > 0) {
  1879. if (typeof d[0] !== "object") {
  1880. throw "data items are not objects";
  1881. }
  1882. }
  1883. } else {
  1884. throw "data provides is not an array";
  1885. }
  1886. /**
  1887. * @private
  1888. * @type {function(): boolean}
  1889. */
  1890. this._hasData = function () {
  1891. return _data === null ? false : _data.length === 0 ? false : true;
  1892. };
  1893. /**
  1894. * @private
  1895. * @type {function(string): string}
  1896. */
  1897. this._getStr = function (s) {
  1898. var phrase = [];
  1899. if (_trim) {
  1900. phrase.push("jQuery.trim(");
  1901. }
  1902. phrase.push("String(" + s + " || '')");
  1903. if (_trim) {
  1904. phrase.push(")");
  1905. }
  1906. if (!_usecase) {
  1907. phrase.push(".toUpperCase()");
  1908. }
  1909. return phrase.join("");
  1910. };
  1911. /** @private */
  1912. this._strComp = function (val) {
  1913. if (typeof val === "string") {
  1914. return ".toString()";
  1915. }
  1916. return "";
  1917. };
  1918. /** @private */
  1919. this._group = function (f, u) {
  1920. return ({ field: f.toString(), unique: u, items: [] });
  1921. };
  1922. /** @private */
  1923. this._toStr = function (phrase) {
  1924. if (_trim) {
  1925. phrase = $.trim(phrase);
  1926. }
  1927. phrase = phrase.toString().replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
  1928. return _usecase ? phrase : phrase.toUpperCase();
  1929. };
  1930. /** @private */
  1931. this._funcLoop = function (func) {
  1932. var results = [];
  1933. $.each(_data, function (i, v) {
  1934. results.push(func(v));
  1935. });
  1936. return results;
  1937. };
  1938. /** @private */
  1939. this._append = function (s) {
  1940. var i;
  1941. if (_query === null) {
  1942. _query = "";
  1943. } else {
  1944. _query += _queuedOperator === "" ? " && " : _queuedOperator;
  1945. }
  1946. for (i = 0; i < _orDepth; i++) {
  1947. _query += "(";
  1948. }
  1949. if (_negate) {
  1950. _query += "!";
  1951. }
  1952. _query += "(" + s + ")";
  1953. _negate = false;
  1954. _queuedOperator = "";
  1955. _orDepth = 0;
  1956. };
  1957. /** @private */
  1958. this._setCommand = function (f, c) {
  1959. _lastCommand = f;
  1960. _lastField = c;
  1961. };
  1962. /** @private */
  1963. this._resetNegate = function () {
  1964. _negate = false;
  1965. };
  1966. /** @private */
  1967. this._repeatCommand = function (f, v) {
  1968. if (_lastCommand === null) {
  1969. return self;
  1970. }
  1971. if (f !== null && v !== null) {
  1972. return _lastCommand(f, v);
  1973. }
  1974. if (_lastField === null) {
  1975. return _lastCommand(f);
  1976. }
  1977. return _lastCommand(_lastField, f);
  1978. };
  1979. /** @private */
  1980. this._equals = function (a, b) {
  1981. return (self._compare(a, b, 1) === 0);
  1982. };
  1983. /** @private */
  1984. this._compare = function (a, b, dir) {
  1985. if (dir === undefined) { dir = 1; }
  1986. if (a === undefined) { a = null; }
  1987. if (b === undefined) { b = null; }
  1988. if (a === null && b === null) {
  1989. return 0;
  1990. }
  1991. if (a === null && b !== null) {
  1992. return 1;
  1993. }
  1994. if (a !== null && b === null) {
  1995. return -1;
  1996. }
  1997. if (toString.call(a) === "[object Date]" && toString.call(b) === "[object Date]") {
  1998. if (a < b) { return -dir; }
  1999. if (a > b) { return dir; }
  2000. return 0;
  2001. }
  2002. if (!_usecase && typeof a !== "number" && typeof b !== "number") {
  2003. a = String(a);
  2004. b = String(b);
  2005. }
  2006. if (a < b) { return -dir; }
  2007. if (a > b) { return dir; }
  2008. return 0;
  2009. };
  2010. /** @private */
  2011. this._performSort = function () {
  2012. if (_sorting.length === 0) { return; }
  2013. _data = self._doSort(_data, 0);
  2014. };
  2015. /** @private */
  2016. this._doSort = function (data, iSort) {
  2017. var by = _sorting[iSort].by,
  2018. dir = _sorting[iSort].dir,
  2019. type = _sorting[iSort].type,
  2020. dfmt = _sorting[iSort].datefmt,
  2021. sfunc = _sorting[iSort].sfunc;
  2022. if (iSort === _sorting.length - 1) {
  2023. return self._getOrder(data, by, dir, type, dfmt, sfunc);
  2024. }
  2025. iSort++;
  2026. var values = self._getGroup(data, by, dir, type, dfmt), results = [], i, j, sorted;
  2027. for (i = 0; i < values.length; i++) {
  2028. sorted = self._doSort(values[i].items, iSort);
  2029. for (j = 0; j < sorted.length; j++) {
  2030. results.push(sorted[j]);
  2031. }
  2032. }
  2033. return results;
  2034. };
  2035. /** @private */
  2036. this._getOrder = function (data, by, dir, type, dfmt, sfunc) {
  2037. var sortData = [], _sortData = [], newDir = dir === "a" ? 1 : -1, i, ab, findSortKey;
  2038. if (type === undefined) { type = "text"; }
  2039. if (type === "float" || type === "number" || type === "currency" || type === "numeric") {
  2040. findSortKey = function ($cell) {
  2041. var key = parseFloat(String($cell).replace(_stripNum, ""));
  2042. return isNaN(key) ? Number.NEGATIVE_INFINITY : key;
  2043. };
  2044. } else if (type === "int" || type === "integer") {
  2045. findSortKey = function ($cell) {
  2046. return $cell != null ? parseFloat(String($cell).replace(_stripNum, "")) : Number.NEGATIVE_INFINITY;
  2047. };
  2048. } else if (type === "date" || type === "datetime") {
  2049. findSortKey = function ($cell) {
  2050. return jgrid.parseDateToNumber.call(context, dfmt, $cell);
  2051. };
  2052. } else if ($.isFunction(type)) {
  2053. findSortKey = type;
  2054. } else {
  2055. findSortKey = function ($cell) {
  2056. $cell = $cell != null ? $.trim(String($cell)) : "";
  2057. return _usecase ? $cell : $cell.toUpperCase();
  2058. };
  2059. }
  2060. $.each(data, function (index, v) {
  2061. ab = by !== "" ? jgrid.getAccessor(v, by) : v;
  2062. if (ab === undefined) { ab = ""; }
  2063. ab = findSortKey.call(context, ab, v);
  2064. _sortData.push({ vSort: ab, data: v, index: index });
  2065. });
  2066. if ($.isFunction(sfunc)) {
  2067. _sortData.sort(function (a, b) {
  2068. return sfunc.call(context, a.vSort, b.vSort, newDir, a.data, b.data);
  2069. });
  2070. } else {
  2071. _sortData.sort(function (a, b) {
  2072. return self._compare(a.vSort, b.vSort, newDir);
  2073. });
  2074. }
  2075. var j = 0, nrec = data.length;
  2076. // overhead, but we do not change the original data.
  2077. while (j < nrec) {
  2078. i = _sortData[j].index;
  2079. sortData.push(data[i]);
  2080. j++;
  2081. }
  2082. return sortData;
  2083. };
  2084. /** @private */
  2085. this._getGroup = function (data, by, dir, type, dfmt) {
  2086. var results = [],
  2087. group = null,
  2088. last = null;
  2089. $.each(self._getOrder(data, by, dir, type, dfmt), function (i, v) {
  2090. var val = jgrid.getAccessor(v, by);
  2091. if (val == null) { val = ""; }
  2092. if (!self._equals(last, val)) {
  2093. last = val;
  2094. if (group !== null) {
  2095. results.push(group);
  2096. }
  2097. group = self._group(by, val);
  2098. }
  2099. group.items.push(v);
  2100. });
  2101. if (group !== null) {
  2102. results.push(group);
  2103. }
  2104. return results;
  2105. };
  2106. this.ignoreCase = function () {
  2107. _usecase = false;
  2108. return self;
  2109. };
  2110. this.useCase = function () {
  2111. _usecase = true;
  2112. return self;
  2113. };
  2114. this.trim = function () {
  2115. _trim = true;
  2116. return self;
  2117. };
  2118. this.noTrim = function () {
  2119. _trim = false;
  2120. return self;
  2121. };
  2122. this.execute = function () {
  2123. var match = _query, results = [];
  2124. if (match === null) {
  2125. return self;
  2126. }
  2127. $.each(_data, function () {
  2128. (function () {
  2129. var localMath = "(function (context) {\n" +
  2130. "var yesObject = { 1: 1, x: 1, \"true\": 1, yes: 1, y: 1, on: 1 }," +
  2131. "noObject = { 0: 1, \"false\": 1, no: 1, n: 1, off: 1 }," +
  2132. "normilizeBoolean = function (v) {\n" +
  2133. "if (typeof v === \"string\") {\n" +
  2134. "if (noObject[v.toLowerCase()]) { return false; } " +
  2135. "else if (yesObject[v.toLowerCase()]) { return true; } " +
  2136. "}\n" +
  2137. "return !!v;\n" +
  2138. "}," +
  2139. "intFunc = function (jQuery, self) { return " +
  2140. match +
  2141. "; }; return intFunc.call(context.item, context.jQuery, context.context); }(this))";
  2142. if (eval(localMath)) { results.push(this.item); }
  2143. }.call({
  2144. item: this,
  2145. jQuery: $,
  2146. context: context
  2147. }));
  2148. });
  2149. _data = results;
  2150. return self;
  2151. };
  2152. this.data = function () {
  2153. return _data;
  2154. };
  2155. this.select = function (f) {
  2156. self.execute();
  2157. if ($.isFunction(f)) {
  2158. var results = [];
  2159. $.each(_data, function (i, v) {
  2160. results.push(f(v));
  2161. });
  2162. return results;
  2163. }
  2164. if (!self._hasData()) { return []; }
  2165. self._performSort();
  2166. return _data;
  2167. };
  2168. this.hasMatch = function () {
  2169. if (!self._hasData()) { return false; }
  2170. self.execute();
  2171. return _data.length > 0;
  2172. };
  2173. this.andNot = function (f, v, x) {
  2174. _negate = !_negate;
  2175. return self.and(f, v, x);
  2176. };
  2177. this.orNot = function (f, v, x) {
  2178. _negate = !_negate;
  2179. return self.or(f, v, x);
  2180. };
  2181. this.not = function (f, v, x) {
  2182. return self.andNot(f, v, x);
  2183. };
  2184. this.and = function (f, v, x) {
  2185. _queuedOperator = " && ";
  2186. if (f === undefined) {
  2187. return self;
  2188. }
  2189. return self._repeatCommand(f, v, x);
  2190. };
  2191. this.or = function (f, v, x) {
  2192. _queuedOperator = " || ";
  2193. if (f === undefined) { return self; }
  2194. return self._repeatCommand(f, v, x);
  2195. };
  2196. this.orBegin = function () {
  2197. _orDepth++;
  2198. return self;
  2199. };
  2200. this.orEnd = function () {
  2201. if (_query !== null) {
  2202. _query += ")";
  2203. }
  2204. return self;
  2205. };
  2206. this.isNot = function (f) {
  2207. _negate = !_negate;
  2208. return self.is(f);
  2209. };
  2210. this.is = function (f) {
  2211. self._append("this." + f);
  2212. self._resetNegate();
  2213. return self;
  2214. };
  2215. /** @private */
  2216. this._compareValues = function (func, f, v, how, t) {
  2217. var fld = f;
  2218. if (v === undefined) { v = null; }
  2219. //var val=v===null?f:v,
  2220. var val = v, swst = t.stype === undefined ? "text" : t.stype;
  2221. if (v !== null) {
  2222. switch (swst) {
  2223. case "int":
  2224. case "integer":
  2225. val = String(val).replace(_stripNum, "");
  2226. val = (isNaN(Number(val)) || val === "") ? "0" : Number(val); // To be fixed with more intelligent code
  2227. fld = "parseInt(" + fld + "||0,10)";
  2228. val = String(parseInt(val, 10));
  2229. break;
  2230. case "boolean":
  2231. // use !! operator to convert ruthy/falsy values to boolean and then compare the values
  2232. fld = "normilizeBoolean(" + fld + ")";
  2233. val = "normilizeBoolean(" + String(val) + ")";
  2234. break;
  2235. case "float":
  2236. case "number":
  2237. case "currency":
  2238. case "numeric":
  2239. val = String(val).replace(_stripNum, "");
  2240. val = (isNaN(Number(val)) || val === "") ? "0" : Number(val); // To be fixed with more intelligent code
  2241. fld = "parseFloat(" + fld + "||0)";
  2242. val = String(val);
  2243. break;
  2244. case "date":
  2245. case "datetime":
  2246. val = String(jgrid.parseDateToNumber.call(context, t.newfmt || "Y-m-d", val));
  2247. fld = "jQuery.jgrid.parseDateToNumber.call(self,\"" + t.srcfmt + "\"," + fld + ")";
  2248. break;
  2249. default:
  2250. // TODO: consider to apply formatter at least to process correctly
  2251. // default values. For example is bootean property is not defined
  2252. // if will be displayed by formatter:"checkbox" as false value.
  2253. // If the user search for the value one will process the following
  2254. // jQuery.jgrid.getAccessor(this,'closed')).toUpperCase() == String("FALSE").toUpperCase()
  2255. // which works wrong if the property "closed" is undefined.
  2256. fld = self._getStr(fld);
  2257. val = self._getStr("\"" + self._toStr(val) + "\"");
  2258. }
  2259. }
  2260. self._append(fld + " " + how + " " + val);
  2261. self._setCommand(func, f);
  2262. self._resetNegate();
  2263. return self;
  2264. };
  2265. this.equals = function (f, v, t) {
  2266. return self._compareValues(self.equals, f, v, "==", t);
  2267. };
  2268. this.notEquals = function (f, v, t) {
  2269. return self._compareValues(self.equals, f, v, "!==", t);
  2270. };
  2271. this.isNull = function (f, v, t) {
  2272. return self._compareValues(self.equals, f, null, "===", t);
  2273. };
  2274. this.greater = function (f, v, t) {
  2275. return self._compareValues(self.greater, f, v, ">", t);
  2276. };
  2277. this.less = function (f, v, t) {
  2278. return self._compareValues(self.less, f, v, "<", t);
  2279. };
  2280. this.greaterOrEquals = function (f, v, t) {
  2281. return self._compareValues(self.greaterOrEquals, f, v, ">=", t);
  2282. };
  2283. this.lessOrEquals = function (f, v, t) {
  2284. return self._compareValues(self.lessOrEquals, f, v, "<=", t);
  2285. };
  2286. this.startsWith = function (f, v) {
  2287. var val = (v == null) ? f : v,
  2288. length = _trim ? $.trim(val.toString()).length : val.toString().length;
  2289. self._append(self._getStr(f) + ".substr(0," + length + ") == " + self._getStr("\"" + self._toStr(v) + "\""));
  2290. self._setCommand(self.startsWith, f);
  2291. self._resetNegate();
  2292. return self;
  2293. };
  2294. this.endsWith = function (f, v) {
  2295. var val = (v == null) ? f : v,
  2296. length = _trim ? $.trim(val.toString()).length : val.toString().length;
  2297. self._append(self._getStr(f) + ".substr(" + self._getStr(f) + ".length-" + length + "," + length + ") == \"" + self._toStr(v) + "\"");
  2298. self._setCommand(self.endsWith, f);
  2299. self._resetNegate();
  2300. return self;
  2301. };
  2302. this.contains = function (f, v) {
  2303. self._append(self._getStr(f) + ".indexOf(\"" + self._toStr(v) + "\",0) > -1");
  2304. self._setCommand(self.contains, f);
  2305. self._resetNegate();
  2306. return self;
  2307. };
  2308. this.groupBy = function (by, dir, type, datefmt) {
  2309. if (!self._hasData()) {
  2310. return null;
  2311. }
  2312. return self._getGroup(_data, by, dir, type, datefmt);
  2313. };
  2314. this.orderBy = function (by, dir, stype, dfmt, sfunc) {
  2315. dir = dir == null ? "a" : $.trim(dir.toString().toLowerCase());
  2316. if (stype == null) { stype = "text"; }
  2317. if (dfmt == null) { dfmt = "Y-m-d"; }
  2318. if (sfunc == null) { sfunc = false; }
  2319. if (dir === "desc" || dir === "descending") { dir = "d"; }
  2320. if (dir === "asc" || dir === "ascending") { dir = "a"; }
  2321. _sorting.push({ by: by, dir: dir, type: stype, datefmt: dfmt, sfunc: sfunc });
  2322. return self;
  2323. };
  2324. this.inSet = function (f, v, t) {
  2325. var val = v === undefined ? null : v,
  2326. swst = t.stype === undefined ? "text" : t.stype;
  2327. val = self._getStr("\"" + self._toStr(val) + "\"");
  2328. if (swst !== "text") {
  2329. // NOT yet implemented
  2330. return self._compareValues(self.equals, f, v, "==", t);
  2331. }
  2332. self._append("jQuery.inArray(" + self._getStr(f) + "," + val + ".split('" +
  2333. (context.p.inFilterSeparator || ",") + "')) >= 0");
  2334. self._setCommand(self.inSet, f);
  2335. self._resetNegate();
  2336. return self;
  2337. };
  2338. this.custom = function (ruleOp, field, data) {
  2339. self._append("self.p.customSortOperations." + ruleOp + ".filter.call(self,{item:this,cmName:\"" + field +
  2340. "\",iCol:self.p.iColByName[\"" + field + "\"]>=0 ? self.p.iColByName[\"" + field + "\"] : self.p.iPropByName[\"" + field +
  2341. "\"],isAddProp:self.p.iColByName[\"" + field + "\"]<0" +
  2342. ",searchValue:\"" + data + "\"})");
  2343. self._setCommand(self.custom, field);
  2344. self._resetNegate();
  2345. return self;
  2346. };
  2347. return self;
  2348. };
  2349. return new QueryObject(source, null);
  2350. },
  2351. serializeFeedback: function (callback, eventName, postData) {
  2352. var self = this, eventResult;
  2353. if (self instanceof $ && self.length > 0) {
  2354. self = self[0];
  2355. }
  2356. if (typeof postData === "string") {
  2357. return postData;
  2358. }
  2359. eventResult = $(self).triggerHandler(eventName, postData);
  2360. if (typeof eventResult === "string") {
  2361. return eventResult;
  2362. }
  2363. if (eventResult == null || typeof eventResult !== "object") {
  2364. eventResult = postData; // uses original postData
  2365. }
  2366. return $.isFunction(callback) ? callback.call(self, eventResult) : eventResult;
  2367. },
  2368. fullBoolFeedback: function (callback, eventName) {
  2369. var self = this, args = $.makeArray(arguments).slice(2), result = $(self).triggerHandler(eventName, args);
  2370. result = (result === false || result === "stop") ? false : true;
  2371. if ($.isFunction(callback)) {
  2372. var callbackResult = callback.apply(self, args);
  2373. if (callbackResult === false || callbackResult === "stop") {
  2374. result = false;
  2375. }
  2376. }
  2377. return result;
  2378. },
  2379. feedback: function (p, eventPrefix, callbackSuffix, callbackName) {
  2380. var self = this;
  2381. if (self instanceof $ && self.length > 0) {
  2382. self = self[0];
  2383. }
  2384. if (p == null || typeof callbackName !== "string" || callbackName.length < 2) {
  2385. return null; // incorrect call
  2386. }
  2387. // onSortCol -> jqGridSortCol, onSelectAll -> jqGridSelectAll, ondblClickRow -> jqGridDblClickRow
  2388. // resizeStop -> jqGridResizeStop
  2389. var eventName = callbackName.substring(0, 2) === "on" ?
  2390. "jqGrid" + eventPrefix + callbackName.charAt(2).toUpperCase() + callbackName.substring(3) :
  2391. "jqGrid" + eventPrefix + callbackName.charAt(0).toUpperCase() + callbackName.substring(1),
  2392. args = $.makeArray(arguments).slice(4),
  2393. callback = p[callbackName + callbackSuffix];
  2394. args.unshift(eventName);
  2395. args.unshift(callback);
  2396. return jgrid.fullBoolFeedback.apply(self, args);
  2397. },
  2398. builderSortIcons: function (iCol) {
  2399. // iCol is unused currently, but one can modify the code to set for example different sorting
  2400. // icons for columns based on sorttype option of colModel
  2401. var ts = this, p = ts.p, $self = $(ts),
  2402. disabledStateClasses = $self.jqGrid("getGuiStyles", "states.disabled"),
  2403. getClasses = function (ascOrDesc) {
  2404. var cm = p.colModel[iCol],
  2405. sortIconFunc = cm != null && $.isFunction(cm.sortIconName) ?
  2406. cm.sortIconName :
  2407. p.sortIconName;
  2408. var sortIconName = $.isFunction(sortIconFunc) ?
  2409. sortIconFunc.call(ts, {
  2410. order: ascOrDesc,
  2411. iCol: iCol,
  2412. cm: cm
  2413. }) :
  2414. $self.jqGrid("getIconRes", "sort." + ascOrDesc);
  2415. return jgrid.mergeCssClasses(
  2416. "ui-grid-ico-sort",
  2417. "ui-icon-" + ascOrDesc,
  2418. p.viewsortcols[1] === "horizontal" ? "ui-i-" + ascOrDesc : "",
  2419. disabledStateClasses,
  2420. sortIconName,
  2421. "ui-sort-" + p.direction
  2422. );
  2423. };
  2424. return "<span class='s-ico" + (p.sortIconsBeforeText ? " jqgrid-icons-first" : "") +
  2425. "' style='display:none'><span class='" + getClasses("asc") +
  2426. "'></span><span class='" + getClasses("desc") + "'></span></span>";
  2427. },
  2428. /**
  2429. * @param {String} id
  2430. * @param {String} text
  2431. * @param {String} icon
  2432. * @param {String} iconOnLeftOrRight - string "left", "right" or undefined
  2433. * @param {String} conner - string "left", "right" or undefined.
  2434. */
  2435. builderFmButon: function (id, text, icon, iconOnLeftOrRight, conner) {
  2436. var p = this.p, $self = $(this),
  2437. getDialogGuiStyles = function (name) {
  2438. return $self.jqGrid("getGuiStyles", "dialog." + name);
  2439. };
  2440. if (p == null) { return ""; }
  2441. return "<a id='" + id + "' class='" +
  2442. jgrid.mergeCssClasses("fm-button",
  2443. getDialogGuiStyles("fmButton"),
  2444. getDialogGuiStyles(conner === "right" ? "rightCorner" : (conner === "left" ? "leftCorner" : "defaultCorner")),
  2445. iconOnLeftOrRight === "right" ?
  2446. "fm-button-icon-right" :
  2447. (iconOnLeftOrRight === "left" ? "fm-button-icon-left" : "")
  2448. ) + "' role='button' tabindex='0'>" +
  2449. (icon ? "<span class='fm-button-icon " + ($self.jqGrid("getIconRes", icon) || icon) + "'></span>" : "") +
  2450. (text ? "<span class='fm-button-text'>" + text + "</span>" : "") +
  2451. "</a>";
  2452. },
  2453. convertOnSaveLocally: function (nData, cm, oData, id, item, iCol) {
  2454. var self = this, p = self.p;
  2455. if (p == null) {
  2456. return nData;
  2457. }
  2458. if ($.isFunction(cm.convertOnSave)) {
  2459. return cm.convertOnSave.call(this, { newValue: nData, cm: cm, oldValue: oData, id: id, item: item, iCol: iCol });
  2460. }
  2461. if (typeof oData !== "boolean" && typeof oData !== "number") {
  2462. // we support first of all editing of boolean and numeric data
  2463. // TODO: more data types (like Date) need be implemented
  2464. return nData;
  2465. }
  2466. if (typeof oData === "boolean" && (cm.edittype === "checkbox" || cm.formatter === "checkbox")) {
  2467. // convert nData to boolean if possible
  2468. var lnData = String(nData).toLowerCase(),
  2469. cbv = cm.editoptions != null && typeof cm.editoptions.value === "string" ?
  2470. cm.editoptions.value.split(":") : ["yes", "no"];
  2471. if ($.inArray(lnData, ["1", "true", cbv[0].toLowerCase()]) >= 0) {
  2472. nData = true;
  2473. } else if ($.inArray(lnData, ["0", "false", cbv[1].toLowerCase()]) >= 0) {
  2474. nData = false;
  2475. }
  2476. } else if (typeof oData === "number" && !isNaN(nData)) {
  2477. if (cm.formatter === "number" || cm.formatter === "currency") {
  2478. nData = parseFloat(nData);
  2479. } else if (cm.formatter === "integer") {
  2480. nData = parseInt(nData, 10);
  2481. }
  2482. }
  2483. return nData;
  2484. },
  2485. parseDataToHtml: function (len, ids, items, cellsToDisplay, rcnt, adjust, readAllInputData) {
  2486. var self = this, p = self.p, $self = $(self), i, j, altr, cn1, selr, idr, rd, cells, iStartTrTag,
  2487. selected = false, rowData = [], grpdata = [],
  2488. cn = (p.altRows === true && !$self.jqGrid("isBootstrapGuiStyle")) ? p.altclass : "",
  2489. grp = p.groupingView,
  2490. hiderow = false,
  2491. rn = parseInt(p.rowNum, 10), cmName, $j = $.fn.jqGrid,
  2492. // prepare to build the map rowIndexes, which will simplify us to get rowIndex
  2493. // of any row of table by its rowid.
  2494. // ??? probably rcnt can be used too
  2495. rowIndex = p.treeGrid === true && p.treeANode > -1 ?
  2496. self.rows[p.treeANode].rowIndex + 1 :
  2497. self.rows.length,
  2498. formatCol = self.formatCol,
  2499. addCell = function (rowId, cell, pos, irow, srvr, rdata) {
  2500. var v = self.formatter(rowId, cell, pos, srvr, "add", rdata);
  2501. return "<td role='gridcell' " + formatCol(pos, irow, v, srvr, rowId, rdata) + ">" + v + "</td>";
  2502. },
  2503. addMulti = function (rowid, pos, irow, checked, item) {
  2504. var checkboxHtml = "&nbsp;", hasCbox = true,
  2505. callbackParams = { rowid: rowid, iRow: irow, iCol: pos, data: item, checked: checked };
  2506. if ($.isFunction(p.hasMultiselectCheckBox)) {
  2507. hasCbox = p.hasMultiselectCheckBox.call(self, callbackParams);
  2508. }
  2509. if (hasCbox) {
  2510. checkboxHtml = $.isFunction(p.checkboxHtml) ?
  2511. p.checkboxHtml.call(self, callbackParams) :
  2512. "<input type='checkbox' id='jqg_" + p.id + "_" + rowid +
  2513. "' class='cbox' name='jqg_" + p.id + "_" + rowid + "'" +
  2514. (checked ? " checked='checked' aria-checked='true'" : " aria-checked='false'") + "/>";
  2515. }
  2516. return "<td role='gridcell' " + formatCol(pos, irow, "", null, rowid, true) + ">" +
  2517. checkboxHtml + "</td>";
  2518. },
  2519. addRowNum = function (pos, irow, pG, rN) {
  2520. var v = (parseInt(pG, 10) - 1) * parseInt(rN, 10) + 1 + irow;
  2521. return "<td role='gridcell' class='" + $j.getGuiStyles.call($self, "rowNum", "jqgrid-rownum") + "' " +
  2522. formatCol(pos, irow, v, null, irow, true) + ">" + v + "</td>";
  2523. };
  2524. if (rowIndex <= 1) { p.rowIndexes = {}; }
  2525. if ((p.datatype === "local" && !p.deselectAfterSort) || p.multiPageSelection) { selected = true; }
  2526. if (adjust) { rn *= adjust + 1; }
  2527. for (i = 0; i < Math.min(len, rn); i++) {
  2528. idr = ids[i];
  2529. rd = items[i];
  2530. cells = cellsToDisplay != null ? cellsToDisplay[i] : rd;
  2531. altr = rcnt === 1 ? 0 : rcnt; // probably rowIndex should be used instead
  2532. cn1 = (altr + i) % 2 === 1 ? cn : "";
  2533. if (selected) {
  2534. if (p.multiselect) {
  2535. selr = ($.inArray(idr, p.selarrrow) !== -1);
  2536. if (selr && p.selrow === null) { p.selrow = idr; }
  2537. } else {
  2538. selr = (idr === p.selrow);
  2539. }
  2540. } else {
  2541. selr = false;
  2542. }
  2543. iStartTrTag = rowData.length;
  2544. rowData.push(""); // it will be replaced. See rowData[iStartTrTag] below
  2545. for (j = 0; j < p.colModel.length; j++) {
  2546. cmName = p.colModel[j].name;
  2547. switch (cmName) {
  2548. case "rn":
  2549. rowData.push(addRowNum(j, i, p.page, p.rowNum));
  2550. break;
  2551. case "cb":
  2552. rowData.push(addMulti(idr, j, i, selr, rd));
  2553. break;
  2554. case "subgrid":
  2555. rowData.push($j.addSubGridCell.call($self, j, i + rcnt, idr, rd));
  2556. break;
  2557. default:
  2558. rowData.push(addCell(idr, rd[cmName], j, i + rcnt, cells, rd));
  2559. }
  2560. }
  2561. if (p.grouping) {
  2562. if ($j.groupingPrepare && !grp._locgr) {
  2563. $j.groupingPrepare.call($self, rd, i);
  2564. }
  2565. hiderow = $.isFunction(grp.groupCollapse) ?
  2566. grp.groupCollapse.call(self, {
  2567. group: grp.groups[grp.groups.length - 1],
  2568. rowid: idr,
  2569. data: rd
  2570. }) :
  2571. grp.groupCollapse;
  2572. }
  2573. rowData[iStartTrTag] = self.constructTr(idr, hiderow, cn1, rd, cells, selr);
  2574. rowData.push("</tr>");
  2575. p.rowIndexes[idr] = rowIndex;
  2576. rowIndex++;
  2577. //TODO: fix p.rowIndexes in case of usage grouping.
  2578. if (p.grouping) {
  2579. // we save the rowData in the array grpdata first.
  2580. // grpdata will collect HTML fragments of all rows of data
  2581. // of the current group. Later we call groupingRender, which
  2582. // will insert additional grouping row and concatinate all
  2583. // the HTML fragments of all rows of the group.
  2584. grpdata.push(rowData);
  2585. rowData = []; // the data for rendering are moved in grpdata
  2586. }
  2587. if (rowData.length > p.maxItemsToJoin) {
  2588. rowData = [rowData.join("")];
  2589. }
  2590. }
  2591. if (p.grouping && $j.groupingRender) {
  2592. if (readAllInputData) {
  2593. grp._locgr = true;
  2594. }
  2595. rowData = [$j.groupingRender.call($self, grpdata, rn)];
  2596. jgrid.clearArray(grpdata); //grpdata = null;
  2597. }
  2598. return rowData;
  2599. },
  2600. fillSelectOptions: function (elem, value, sep, delim, isMultiple, valuesToSelect) {
  2601. var i, so, sv, ov, optionInfo, optionInfos = [], isSelected, key, ovm,
  2602. isNoFilterValueExist = false,
  2603. mapFunc = function (n, ii) { if (ii > 0) { return n; } };
  2604. if (!value) { return; }
  2605. if (typeof value === "function") {
  2606. value = value();
  2607. }
  2608. if (typeof value === "string") {
  2609. so = value.split(delim);
  2610. for (i = 0; i < so.length; i++) {
  2611. sv = so[i].split(sep);
  2612. if (sv.length > 2) {
  2613. sv[1] = $.map(sv, mapFunc).join(sep);
  2614. }
  2615. optionInfos.push({
  2616. value: sv[0],
  2617. innerHtml: sv[1],
  2618. selectValue: $.trim(sv[0]),
  2619. selectText: $.trim(sv[1]),
  2620. selected: false
  2621. });
  2622. if (sv[0] === "") {
  2623. isNoFilterValueExist = true;
  2624. }
  2625. }
  2626. } else if (typeof value === "object") {
  2627. for (key in value) {
  2628. if (value.hasOwnProperty(key)) {
  2629. optionInfos.push({
  2630. value: key,
  2631. innerHtml: value[key],
  2632. selectValue: $.trim(key),
  2633. selectText: $.trim(value[key]),
  2634. selected: false
  2635. });
  2636. }
  2637. if (key === "") {
  2638. isNoFilterValueExist = true;
  2639. }
  2640. }
  2641. }
  2642. if (typeof valuesToSelect === "string") {
  2643. ovm = isMultiple ?
  2644. $.map(valuesToSelect.split(","), function (n) { return $.trim(n); }) :
  2645. [$.trim(valuesToSelect)];
  2646. valuesToSelect = $.trim(valuesToSelect);
  2647. // mark selection
  2648. // 1) first by value
  2649. for (i = 0; i < optionInfos.length; i++) {
  2650. optionInfo = optionInfos[i];
  2651. if (!isMultiple && optionInfo.selectValue === valuesToSelect) {
  2652. optionInfo.selected = true;
  2653. isSelected = true;
  2654. }
  2655. if (isMultiple && $.inArray(optionInfo.selectValue, ovm) > -1) {
  2656. optionInfo.selected = true;
  2657. isSelected = true;
  2658. }
  2659. }
  2660. // 2) when no selection by value, then by text
  2661. if (!isSelected) {
  2662. for (i = 0; i < optionInfos.length; i++) {
  2663. optionInfo = optionInfos[i];
  2664. if (!isMultiple && optionInfo.selectText === valuesToSelect) {
  2665. optionInfo.selected = true;
  2666. }
  2667. if (isMultiple && $.inArray(optionInfo.selectText, ovm) > -1) {
  2668. optionInfo.selected = true;
  2669. }
  2670. }
  2671. }
  2672. }
  2673. for (i = 0; i < optionInfos.length; i++) {
  2674. optionInfo = optionInfos[i];
  2675. ov = document.createElement("option");
  2676. ov.value = optionInfo.value;
  2677. ov.innerHTML = optionInfo.innerHtml;
  2678. if (optionInfo.selected) {
  2679. ov.selected = true;
  2680. }
  2681. elem.appendChild(ov);
  2682. }
  2683. return isNoFilterValueExist;
  2684. },
  2685. getMethod: function (name) {
  2686. // this should be $.jgrid object
  2687. return this.getAccessor($.fn.jqGrid, name);
  2688. },
  2689. extend: function (methods) {
  2690. $.extend($.fn.jqGrid, methods);
  2691. if (!this.no_legacy_api) {
  2692. $.fn.extend(methods);
  2693. }
  2694. }
  2695. });
  2696. var clearArray = jgrid.clearArray, jqID = jgrid.jqID,
  2697. getGridComponentIdSelector = jgrid.getGridComponentIdSelector, getGridComponentId = jgrid.getGridComponentId,
  2698. getGridComponent = jgrid.getGridComponent, stripPref = jgrid.stripPref, randId = jgrid.randId,
  2699. getAccessor = jgrid.getAccessor, convertOnSaveLocally = jgrid.convertOnSaveLocally,
  2700. stripHtml = jgrid.stripHtml, htmlEncode = jgrid.htmlEncode, htmlDecode = jgrid.htmlDecode,
  2701. mergeCssClasses = jgrid.mergeCssClasses, hasOneFromClasses = jgrid.hasOneFromClasses,
  2702. feedback = function () {
  2703. // short form of $.jgrid.feedback to save usage this.p as the first parameter
  2704. var args = $.makeArray(arguments);
  2705. args.unshift("");
  2706. args.unshift("");
  2707. args.unshift(this.p);
  2708. return jgrid.feedback.apply(this, args);
  2709. };
  2710. /**
  2711. * @param {(string|Object)} pin
  2712. */
  2713. $.fn.jqGrid = function (pin) {
  2714. var $j = $.fn.jqGrid, fn;
  2715. if (typeof pin === "string") {
  2716. fn = $j[pin];
  2717. if (!fn) {
  2718. throw ("jqGrid - No such method: " + pin);
  2719. }
  2720. return fn.apply(this, $.makeArray(arguments).slice(1));
  2721. }
  2722. return this.each(function () {
  2723. if (this.grid) { return; }
  2724. // TODO: verify that pin.locale exists in locales. If it's not exist then change it to
  2725. // en-US or some other which exist
  2726. var ts = this, localData, localDataStr, $self0 = $(ts),
  2727. isFunction = $.isFunction, isArray = $.isArray, extend = $.extend, inArray = $.inArray,
  2728. trim = $.trim, each = $.each, setSelection = $j.setSelection, getGridRes = $j.getGridRes,
  2729. fatalErrorFunction = isFunction(defaults.fatalError) ? defaults.fatalError : alert,
  2730. locale = pin.locale || defaults.locale || "en-US",
  2731. direction = locales[locale] != null && typeof locales[locale].isRTL === "boolean" ? (locales[locale].isRTL ? "rtl" : "ltr") : "ltr",
  2732. iconSet = pin.iconSet || defaults.iconSet || ((pin.guiStyle || defaults.guiStyle) === "bootstrap" || (pin.guiStyle || defaults.guiStyle) === "bootstrapPrimary" ? "glyph" : "jQueryUI"),
  2733. guiStyle = pin.guiStyle || defaults.guiStyle || "jQueryUI",
  2734. getIcon = function (path) {
  2735. //return jgrid.getIconRes(iconSet, path);
  2736. return $j.getIconRes.call(ts, path);
  2737. },
  2738. getGuiStyles = function (path, jqClasses) {
  2739. return $self0.jqGrid("getGuiStyles", path, jqClasses);
  2740. },
  2741. stdLoadError = function (jqXHR, textStatus, errorThrown) {
  2742. if (textStatus !== "abort" && errorThrown !== "abort") {
  2743. var contentType = jqXHR.getResponseHeader ("Content-Type"),
  2744. message = jqXHR.responseText || "",
  2745. processHtmlError = function (msg) {
  2746. var div = document.createElement("div"), scripts, i, bodyMatch;
  2747. // get body only and strip all scripts
  2748. bodyMatch = /<body[^>]*>([\s\S]*)<\/body\s*>/gim.exec(msg);
  2749. div.innerHTML = bodyMatch != null && bodyMatch.length === 2 ?
  2750. bodyMatch[1] : msg;
  2751. scripts = div.getElementsByTagName("script");
  2752. i = scripts.length;
  2753. while (i--) {
  2754. scripts[i].parentNode.removeChild(scripts[i]);
  2755. }
  2756. // strip html headers and get the body only
  2757. msg = div.innerHTML;
  2758. try {
  2759. // remove HTML, if it has no text
  2760. if ($.trim($(msg).text()) === "") {
  2761. msg = "";
  2762. }
  2763. }
  2764. catch (ignore) {}
  2765. return msg;
  2766. },
  2767. processJsonError = function (msg) {
  2768. try {
  2769. var errorInfo = $.parseJSON(msg), errorMessages = [], errorProp;
  2770. for (errorProp in errorInfo) {
  2771. if (errorInfo.hasOwnProperty(errorProp) && errorProp !== "StackTrace") {
  2772. errorMessages.push(errorProp + ": " + errorInfo[errorProp]);
  2773. }
  2774. }
  2775. msg = errorMessages.join("<br />");
  2776. }
  2777. catch (ignore) {}
  2778. return msg;
  2779. };
  2780. if (contentType === "text/html") {
  2781. message = processHtmlError(message);
  2782. } else if (contentType === "application/json") {
  2783. message = processJsonError(message);
  2784. } else if (contentType === "text/plain") {
  2785. // try to process as JSON
  2786. message = processJsonError(message);
  2787. }
  2788. if (jqXHR.status !== 500 && jqXHR.status !== 0) {
  2789. // add the header
  2790. message = (textStatus || errorThrown) +
  2791. (errorThrown && (errorThrown !== textStatus) ? ": " + errorThrown : "") +
  2792. " " + jqXHR.status + " " + jqXHR.statusText +
  2793. (message !== "" ? "<hr />" : "") +
  2794. message;
  2795. }
  2796. $self0.jqGrid("displayErrorMessage", message || textStatus || errorThrown);
  2797. }
  2798. };
  2799. if (pin == null) {
  2800. pin = { datatype: "local" };
  2801. }
  2802. if (pin.datastr !== undefined && isArray(pin.datastr)) {
  2803. localDataStr = pin.datastr;
  2804. pin.datastr = []; // don't clear the array, just change the value of datastr property
  2805. }
  2806. if (pin.data !== undefined) {
  2807. localData = pin.data;
  2808. pin.data = []; // don't clear the array, just change the value of data property
  2809. }
  2810. if (jgrid.formatter == null || jgrid.formatter.unused == null) {
  2811. // detect old locale file grid.locale-XX.js are included (without DEEP extend).
  2812. fatalErrorFunction("CRITICAL ERROR!!!\n\n\nOne uses probably\n\n\t$.extend($.jgrid.defaults, {...});\n\nto set default settings of jqGrid instead of the usage the DEEP version of jQuery.extend (with true as the first parameter):\n\n\t$.extend(true, $.jgrid.defaults, {...});\n\nOne other possible reason:\n\nyou included some OLD version of language file (grid.locale-en.js for example) AFTER jquery.jqGrid.min.js. For example all language files of jqGrid 4.7.0 uses non-deep call of jQuery.extend.\n\n\nSome options of jqGrid could still work, but another one will be broken.");
  2813. }
  2814. if (pin.datatype === undefined && pin.dataType !== undefined) {
  2815. // fix the bug in the usage of dataType instead of datatype
  2816. pin.datatype = pin.dataType;
  2817. delete pin.dataType;
  2818. }
  2819. if (pin.mtype === undefined && pin.type !== undefined) {
  2820. // fix the bug in the usage of type instead of mtype
  2821. pin.mtype = pin.type;
  2822. delete pin.type;
  2823. }
  2824. ts.p = { iconSet: iconSet }; // minimal initializing to get icons with respect of getIconRes method
  2825. var p = extend(true,
  2826. {
  2827. //url: "",
  2828. height: "auto",
  2829. page: 1,
  2830. rowNum: 20,
  2831. maxRowNum: 10000,
  2832. pagingDuringEditing: "prevent", // "prevent", "cancel" or "save"
  2833. sortingDuringEditing: "prevent", // "prevent", "cancel" or "save"
  2834. reloadingDuringEditing: "prevent", // "prevent", "cancel" or "save"
  2835. autoresizeOnLoad: false,
  2836. columnsToReResizing: [],
  2837. autoResizing: {
  2838. wrapperClassName: "ui-jqgrid-cell-wrapper",
  2839. //widthOfVisiblePartOfSortIcon: pin.iconSet === "fontAwesome" ? 13 : 12,
  2840. minColWidth: 33,
  2841. maxColWidth: 300,
  2842. adjustGridWidth: true, // shrinkToFit and widthOrg (no width option or width:"auto" during jqGrid creation will be detected) will be used additionally with adjustGridWidth
  2843. compact: false,
  2844. fixWidthOnShrink: false
  2845. },
  2846. doubleClickSensitivity: 250,
  2847. minResizingWidth: 10,
  2848. rowTotal: null,
  2849. records: 0,
  2850. pager: "",
  2851. pgbuttons: true,
  2852. pginput: true,
  2853. colModel: [],
  2854. additionalProperties: [],
  2855. arrayReader: [],
  2856. rowList: [],
  2857. colNames: [],
  2858. sortorder: "asc",
  2859. threeStateSort: false,
  2860. //showOneSortIcon: pin.showOneSortIcon !== undefined ? pin.showOneSortIcon :
  2861. // pin.iconSet === "fontAwesome" ? true : false, // hide or set ui-state-disabled class on the other icon
  2862. sortname: "",
  2863. //datatype: pin.datatype !== undefined ? pin.datatype : // datatype parameter are specified - use it
  2864. // localData !== undefined || pin.url == null ? "local" : // data parameter specified or no url are specified
  2865. // pin.jsonReader != null && typeof pin.jsonReader === "object" ? "json" : "xml", // if jsonReader are specified - use "json". In all other cases - use "xml"
  2866. mtype: "GET",
  2867. altRows: false,
  2868. selarrrow: [],
  2869. savedRow: [],
  2870. editingInfo: {},
  2871. shrinkToFit: true,
  2872. xmlReader: {},
  2873. //jsonReader: {},
  2874. subGrid: false,
  2875. subGridModel: [],
  2876. reccount: 0,
  2877. lastpage: 0,
  2878. lastsort: 0,
  2879. selrow: null,
  2880. singleSelectClickMode: "toggle",
  2881. selectOnContextMenu: true,
  2882. beforeSelectRow: null,
  2883. onSelectRow: null,
  2884. onSortCol: null,
  2885. ondblClickRow: null,
  2886. onRightClickRow: null,
  2887. onPaging: null,
  2888. onSelectAll: null,
  2889. onInitGrid: null,
  2890. loadComplete: null,
  2891. gridComplete: null,
  2892. loadError: stdLoadError,
  2893. loadBeforeSend: null,
  2894. afterInsertRow: null,
  2895. beforeRequest: null,
  2896. beforeProcessing: null,
  2897. onHeaderClick: null,
  2898. viewrecords: false,
  2899. loadonce: false,
  2900. forceClientSorting: false,
  2901. multiselect: false,
  2902. multikey: false,
  2903. editurl: "clientArray",
  2904. search: false,
  2905. caption: "",
  2906. hidegrid: true,
  2907. hiddengrid: false,
  2908. useUnformattedDataForCellAttr: true,
  2909. postData: {},
  2910. userData: {},
  2911. treeGrid: false,
  2912. treeGridModel: "nested",
  2913. treeReader: {},
  2914. treeANode: -1,
  2915. ExpandColumn: null,
  2916. tree_root_level: 0,
  2917. prmNames: {
  2918. page: "page",
  2919. rows: "rows",
  2920. sort: "sidx",
  2921. order: "sord",
  2922. search: "_search",
  2923. filters: "filters",
  2924. nd: "nd",
  2925. id: "id",
  2926. idold: "idOld",
  2927. oper: "oper",
  2928. editoper: "edit",
  2929. addoper: "add",
  2930. deloper: "del",
  2931. subgridid: "id",
  2932. npage: null,
  2933. totalrows: "totalrows"
  2934. },
  2935. forceFit: false,
  2936. gridstate: "visible",
  2937. cellEdit: false,
  2938. iCol: -1,
  2939. iRow: -1,
  2940. //cellsubmit: pin.cellurl === undefined ? "clientArray" : "remote",
  2941. nv: 0,
  2942. loadui: "enable",
  2943. toolbar: [false, ""],
  2944. scroll: false,
  2945. multiboxonly: false,
  2946. deselectAfterSort: true,
  2947. resetPageAfterSort: true,
  2948. multiPageSelection: false,
  2949. selectAllMode: "filtered",
  2950. scrollrows: false,
  2951. autowidth: false,
  2952. scrollOffset: 18,
  2953. cellLayout: 5,
  2954. subGridWidth: 16,
  2955. multiselectWidth: 16,
  2956. multiselectPosition: "left",
  2957. gridview: true,
  2958. rownumWidth: 25,
  2959. rownumbers: false,
  2960. pagerpos: "center",
  2961. footerrow: false,
  2962. userDataOnFooter: false,
  2963. hoverrows: true,
  2964. altclass: "ui-priority-secondary",
  2965. viewsortcols: [false, "vertical", true],
  2966. resizeclass: "",
  2967. autoencode: true, // one can use false to have better backwards compatibility, but one have to prevent Cross Site Scripting (XSS) manually
  2968. autoEncodeOnEdit: false,
  2969. remapColumns: [],
  2970. cmNamesInputOrder: [],
  2971. ajaxGridOptions: {},
  2972. direction: direction,
  2973. toppager: false,
  2974. headertitles: false,
  2975. scrollTimeout: 40,
  2976. maxItemsToJoin: 32768,
  2977. data: [],
  2978. lastSelectedData: [],
  2979. quickEmpty: "quickest", // false, true or "quickest"
  2980. /** @dict */
  2981. _index: {},
  2982. indexByColumnData: {},
  2983. dataIndexById: {},
  2984. iColByName: {},
  2985. iPropByName: {},
  2986. reservedColumnNames: ["rn", "cb", "subgrid"],
  2987. grouping: false,
  2988. groupingView: {
  2989. groupField: [],
  2990. groupOrder: [],
  2991. groupText: [],
  2992. groupColumnShow: [],
  2993. groupSummary: [],
  2994. showSummaryOnHide: false,
  2995. useDefaultValuesOnGrouping: true,
  2996. summary: [],
  2997. displayField: [],
  2998. groupSummaryPos: [],
  2999. formatDisplayField: [],
  3000. _locgr: false,
  3001. commonIconClass: getIcon("grouping.common"),
  3002. plusicon: getIcon("grouping.plus"),
  3003. minusicon: getIcon("grouping.minus")
  3004. },
  3005. ignoreCase: true,
  3006. cmTemplate: {},
  3007. idPrefix: "",
  3008. iconSet: iconSet, // "fontAwesome" or "jQueryUI" or some custom value
  3009. guiStyle: guiStyle,
  3010. locale: locale,
  3011. multiSort: false,
  3012. showSortOrder: true,
  3013. sortOrderPosition: "afterSortIcons", // "afterSortIcons", "beforeSortIcons"
  3014. multiSortOrder: "lastClickedFirstSorted", // "lastClickedLastSorted", "lastClickedFirstSorted" or callback reodering function
  3015. maxSortColumns: 3,
  3016. treeIcons: {
  3017. commonIconClass: getIcon("treeGrid.common"),
  3018. plusLtr: getIcon("treeGrid.plusLtr"),
  3019. plusRtl: getIcon("treeGrid.plusRtl"),
  3020. minus: getIcon("treeGrid.minus"),
  3021. leaf: getIcon("treeGrid.leaf")
  3022. }
  3023. },
  3024. //locales[locale].defaults,
  3025. defaults,
  3026. {
  3027. navOptions: extend(true, {
  3028. commonIconClass: getIcon("nav.common"),
  3029. editicon: getIcon("nav.edit"),
  3030. addicon: getIcon("nav.add"),
  3031. delicon: getIcon("nav.del"),
  3032. searchicon: getIcon("nav.search"),
  3033. refreshicon: getIcon("nav.refresh"),
  3034. viewicon: getIcon("nav.view"),
  3035. saveicon: getIcon("nav.save"),
  3036. cancelicon: getIcon("nav.cancel"),
  3037. buttonicon: getIcon("nav.newbutton")
  3038. }, jgrid.nav || {}),
  3039. actionsNavOptions: extend(true, {
  3040. commonIconClass: getIcon("actions.common"),
  3041. editicon: getIcon("actions.edit"),
  3042. delicon: getIcon("actions.del"),
  3043. saveicon: getIcon("actions.save"),
  3044. cancelicon: getIcon("actions.cancel")
  3045. }, jgrid.actionsNav || {}),
  3046. formEditing: extend(true, {
  3047. commonIconClass: getIcon("form.common"),
  3048. prevIcon: getIcon("form.prev"),
  3049. nextIcon: getIcon("form.next"),
  3050. saveicon: [true, "left", getIcon("form.save")],
  3051. closeicon: [true, "left", getIcon("form.undo")]
  3052. }, jgrid.edit || {}),
  3053. searching: extend(true, {
  3054. commonIconClass: getIcon("search.common"),
  3055. findDialogIcon: getIcon("search.search"),
  3056. resetDialogIcon: getIcon("search.reset"),
  3057. queryDialogIcon: getIcon("search.query")
  3058. }, jgrid.search || {}),
  3059. formViewing: extend(true, {
  3060. commonIconClass: getIcon("form.common"),
  3061. prevIcon: getIcon("form.prev"),
  3062. nextIcon: getIcon("form.next"),
  3063. closeicon: [true, "left", getIcon("form.cancel")]
  3064. }, jgrid.view || {}),
  3065. formDeleting: extend(true, {
  3066. commonIconClass: getIcon("form.common"),
  3067. delicon: [true, "left", getIcon("form.del")],
  3068. cancelicon: [true, "left", getIcon("form.cancel")]
  3069. }, jgrid.del || {})
  3070. },
  3071. pin || {}),
  3072. getRes = function (path) {
  3073. return getGridRes.call($self0, path);
  3074. },
  3075. getDef = function (path) {
  3076. var gridParam = jgrid.getRes(p, path);
  3077. return gridParam !== undefined ? gridParam : getGridRes.call($self0, "defaults." + path);
  3078. };
  3079. // set dynamic options
  3080. p.recordpos = p.recordpos || (p.direction === "rtl" ? "left" : "right");
  3081. p.autoResizing.widthOfVisiblePartOfSortIcon =
  3082. p.autoResizing.widthOfVisiblePartOfSortIcon !== undefined ?
  3083. p.autoResizing.widthOfVisiblePartOfSortIcon :
  3084. (p.iconSet === "fontAwesome" ? 13 : 12);
  3085. //p.showOneSortIcon = p.showOneSortIcon !== undefined ? p.showOneSortIcon :
  3086. // (p.iconSet === "fontAwesome" ? true : false);
  3087. p.datatype = p.datatype !== undefined ? p.datatype : // datatype parameter are specified - use it
  3088. localData !== undefined || p.url == null ? "local" : // data parameter specified or no url are specified
  3089. p.jsonReader != null && typeof p.jsonReader === "object" ? "json" : "xml"; // if jsonReader are specified - use "json". In all other cases - use "xml"
  3090. p.jsonReader = p.jsonReader || {};
  3091. p.url = p.url || "";
  3092. p.cellsubmit = p.cellsubmit !== undefined ? p.cellsubmit :
  3093. p.cellurl === undefined ? "clientArray" : "remote";
  3094. p.gridview = p.gridview !== undefined ? p.gridview : (p.afterInsertRow == null);
  3095. if (localData !== undefined) {
  3096. p.data = localData;
  3097. pin.data = localData;
  3098. }
  3099. if (localDataStr !== undefined) {
  3100. p.datastr = localDataStr;
  3101. pin.datastr = localDataStr;
  3102. }
  3103. if (ts.tagName.toUpperCase() !== "TABLE") {
  3104. fatalErrorFunction("Element is not a table!");
  3105. return;
  3106. }
  3107. if (ts.id === "") {
  3108. $self0.attr("id", randId());
  3109. }
  3110. if (document.documentMode !== undefined) { // IE only
  3111. if (document.documentMode <= 5) {
  3112. fatalErrorFunction("Grid can not be used in this ('quirks') mode!");
  3113. return;
  3114. }
  3115. }
  3116. $self0.empty().attr("tabindex", "0");
  3117. ts.p = p;
  3118. p.id = ts.id;
  3119. p.idSel = "#" + jqID(ts.id);
  3120. p.gBoxId = getGridComponentId.call(ts, COMPONENT_NAMES.GRID_BOX_DIV); // gbox id like "gbox_list" or "gbox_my.list"
  3121. p.gBox = getGridComponentIdSelector.call(ts, COMPONENT_NAMES.GRID_BOX_DIV); // gbox selector like "#gbox_list" or "#gbox_my\\.list"
  3122. p.gViewId = getGridComponentId.call(ts, COMPONENT_NAMES.GRID_VIEW_DIV); // gview id like "gview_list" or "gview_my.list"
  3123. p.gView = getGridComponentIdSelector.call(ts, COMPONENT_NAMES.GRID_VIEW_DIV); // gview selector like "#gview_list" or "#gview_my\\.list"
  3124. p.rsId = getGridComponentId.call(ts, COMPONENT_NAMES.COLUMN_RESIZER_DIV); // vertical div inside of gbox which will be seen on resizing of columns
  3125. p.rs = getGridComponentIdSelector.call(ts, COMPONENT_NAMES.COLUMN_RESIZER_DIV); // vertical div inside of gbox which will be seen on resizing of columns
  3126. p.cbId = getGridComponentId.call(ts, COMPONENT_NAMES.HEADER_SELECT_ALL_ROWS_CHECKBOX); // "cb_" +id
  3127. p.cb = getGridComponentIdSelector.call(ts, COMPONENT_NAMES.HEADER_SELECT_ALL_ROWS_CHECKBOX); // "cb_" +id
  3128. var fixScrollOffsetAndhBoxPadding = jgrid.fixScrollOffsetAndhBoxPadding,
  3129. buildColNameMap = function (colModel) {
  3130. var m = {}, i, n = colModel.length;
  3131. for (i = 0; i < n; i++) {
  3132. m[colModel[i].name] = i;
  3133. }
  3134. return m;
  3135. },
  3136. buildEmptyIndexedColumnMap = function () {
  3137. var m = {}, i, colModel = p.colModel, n = colModel.length, cm;
  3138. for (i = 0; i < n; i++) {
  3139. cm = colModel[i];
  3140. if (cm.createColumnIndex ||
  3141. (p.createColumnIndex && cm.createColumnIndex !== false) ||
  3142. (cm.stype === "select" && (cm.searchoptions || {}).generateValue) ||
  3143. (cm.edittype === "select" && (cm.editoptions || {}).generateValue)) {
  3144. m[colModel[i].name] = {};
  3145. }
  3146. }
  3147. return m;
  3148. },
  3149. buildAddPropMap = function (additionalProperties) {
  3150. var m = {}, i, n = additionalProperties.length, addPropInfo;
  3151. for (i = 0; i < n; i++) {
  3152. addPropInfo = additionalProperties[i];
  3153. m[typeof addPropInfo === "string" ? addPropInfo : addPropInfo.name] = i;
  3154. }
  3155. return m;
  3156. },
  3157. rebuildRowIndexes = function () {
  3158. var rowIndexes = {}, row, i;
  3159. this.p.rowIndexes = rowIndexes;
  3160. for (i = 0; i < this.rows.length; i++) {
  3161. row = this.rows[i];
  3162. if ($(row).hasClass("jqgrow")) {
  3163. rowIndexes[row.id] = row.rowIndex;
  3164. }
  3165. }
  3166. },
  3167. buildArrayReader = function () {
  3168. var i, colModel = p.colModel, cmNamesInputOrder = p.cmNamesInputOrder,
  3169. additionalProperties = p.additionalProperties, n = cmNamesInputOrder.length, arrayReaderInfos,
  3170. name, index, order;
  3171. p.arrayReaderInfos = {};
  3172. arrayReaderInfos = p.arrayReaderInfos;
  3173. for (order = 0; order < n; order++) {
  3174. name = cmNamesInputOrder[order];
  3175. if (inArray(name, p.reservedColumnNames) < 0 && !arrayReaderInfos.hasOwnProperty(name)) {
  3176. index = p.iColByName[name];
  3177. if (index !== undefined) {
  3178. arrayReaderInfos[name] = { name: name, index: index, order: order, type: 0 }; // INPUT_NAME_TYPE.COL_NAME
  3179. } else {
  3180. index = p.iPropByName[name];
  3181. if (index !== undefined) {
  3182. arrayReaderInfos[name] = { name: name, index: index, order: order, type: 1 };// INPUT_NAME_TYPE.ADDITIONAL_PROPERTY
  3183. } else if (name === (p.prmNames.rowidName || "rowid")) {
  3184. arrayReaderInfos[name] = { index: index, type: 2 };// INPUT_NAME_TYPE.ROWID
  3185. }
  3186. }
  3187. }
  3188. }
  3189. n = colModel.length;
  3190. for (i = 0; i < n; i++) {
  3191. name = colModel[i].name;
  3192. if (inArray(name, p.reservedColumnNames) < 0 && !arrayReaderInfos.hasOwnProperty(name)) {
  3193. arrayReaderInfos[name] = { name: name, index: i, order: order, type: 0 };// INPUT_NAME_TYPE.COL_NAME
  3194. order++;
  3195. }
  3196. }
  3197. n = additionalProperties.length;
  3198. for (i = 0; i < n; i++) {
  3199. name = additionalProperties[i];
  3200. if (name != null && !arrayReaderInfos.hasOwnProperty(name)) {
  3201. if (typeof name === "object" && $.type(name.name) === "string") {
  3202. name = name.name;
  3203. }
  3204. arrayReaderInfos[name] = { name: name, index: i, order: order, type: 1 };
  3205. order++;
  3206. }
  3207. }
  3208. },
  3209. myResizerClickHandler = function (e) {
  3210. var pageX = $(this).data("pageX");
  3211. if (pageX) {
  3212. pageX = String(pageX).split(";");
  3213. pageX = pageX[pageX.length - 1];
  3214. $(this).data("pageX", pageX + ";" + e.pageX);
  3215. } else {
  3216. $(this).data("pageX", e.pageX);
  3217. }
  3218. },
  3219. intNum = function (val, defval) {
  3220. val = parseInt(val, 10);
  3221. if (isNaN(val)) { return defval || 0; }
  3222. return val;
  3223. },
  3224. grid = {
  3225. headers: [],
  3226. cols: [],
  3227. footers: [],
  3228. // Some properties will be created dynamically on demand
  3229. // cDiv
  3230. // uDiv
  3231. // topDiv
  3232. // hDiv
  3233. // bDiv
  3234. // sDiv
  3235. // ubDiv
  3236. // fhDiv
  3237. // fbDiv
  3238. // fsDiv
  3239. // width
  3240. // newWidth
  3241. // resizing
  3242. // scrollTop
  3243. // timer
  3244. // prevRowHeight
  3245. dragStart: function (i, x, y, $th) {
  3246. var self = this, $bDiv = $(self.bDiv), gridOffset = $bDiv.closest(p.gBox).offset(),
  3247. // it's better to use exact position of the border on the right of the current header
  3248. startX = $th.offset().left + (p.direction === "rtl" ? 0 : self.headers[i].width + (jgrid.cell_width ? 0 : intNum(p.cellLayout, 0)) - 2);
  3249. self.resizing = { idx: i, startX: startX, sOL: startX, moved: false, delta: startX - x.pageX };
  3250. self.curGbox = $(p.rs);
  3251. self.curGbox.prependTo("body"); // change the parent to be able to move over the ranges of the gBox
  3252. self.curGbox.css({ display: "block", left: startX, top: y[1] + gridOffset.top + 1, height: y[2] });
  3253. self.curGbox.css("height", (y[2] - (self.curGbox.outerHeight() - self.curGbox.height())) + "px");
  3254. self.curGbox.data("idx", i);
  3255. self.curGbox.data("delta", startX - x.pageX);
  3256. myResizerClickHandler.call(this.curGbox, x);
  3257. feedback.call(getGridComponent(COMPONENT_NAMES.BODY_TABLE, $bDiv)[0], "resizeStart", x, i);
  3258. document.onselectstart = function () { return false; };
  3259. $(document)
  3260. .on("mousemove.jqGrid", function (e) {
  3261. if (grid.resizing) {
  3262. grid.dragMove(e);
  3263. return false;
  3264. }
  3265. })
  3266. .on("mouseup.jqGrid" + p.id, function () {
  3267. if (grid.resizing) {
  3268. grid.dragEnd();
  3269. return false;
  3270. }
  3271. });
  3272. },
  3273. dragMove: function (x) {
  3274. var self = this, resizing = self.resizing;
  3275. if (resizing) {
  3276. var diff = x.pageX + resizing.delta - resizing.startX, headers = self.headers, h = headers[resizing.idx],
  3277. newWidth = p.direction === "ltr" ? h.width + diff : h.width - diff, hn, nWn,
  3278. minResizingWidth = ((p.colModel[resizing.idx] || {}).autoResizing || {}).minColWidth || p.minResizingWidth;
  3279. resizing.moved = true;
  3280. if (newWidth > minResizingWidth) {
  3281. if (self.curGbox == null) {
  3282. self.curGbox = $(p.rs);
  3283. }
  3284. self.curGbox.css({ left: resizing.sOL + diff });
  3285. if (p.forceFit === true) {
  3286. hn = headers[resizing.idx + p.nv];
  3287. nWn = p.direction === "ltr" ? hn.width - diff : hn.width + diff;
  3288. if (nWn > p.autoResizing.minColWidth) {
  3289. h.newWidth = newWidth;
  3290. hn.newWidth = nWn;
  3291. }
  3292. } else {
  3293. self.newWidth = p.direction === "ltr" ? p.tblwidth + diff : p.tblwidth - diff;
  3294. h.newWidth = newWidth;
  3295. }
  3296. }
  3297. }
  3298. },
  3299. resizeColumn: function (idx, skipCallbacks, skipGridAdjustments) {
  3300. var self = this, headers = self.headers, footers = self.footers, h = headers[idx], hn, nw = h.newWidth || h.width,
  3301. $bTable = getGridComponent(COMPONENT_NAMES.BODY_TABLE, self.bDiv), $hTable = getGridComponent(COMPONENT_NAMES.HEADER_TABLE, self.hDiv),
  3302. hCols = $hTable.children("thead").children("tr").first()[0].cells;
  3303. nw = parseInt(nw, 10);
  3304. p.colModel[idx].width = nw;
  3305. h.width = nw;
  3306. hCols[idx].style.width = nw + "px";
  3307. self.cols[idx].style.width = nw + "px";
  3308. if (self.fbRows) {
  3309. $(self.fbRows[0].cells[idx]).css("width", nw);
  3310. $(getGridComponent(COMPONENT_NAMES.FROZEN_HEADER_TABLE, self.fhDiv)[0].rows[0].cells[idx]).css("width", nw);
  3311. if (p.footerrow) {
  3312. $(getGridComponent(COMPONENT_NAMES.FROZEN_FOOTER_TABLE, self.fsDiv)[0].rows[0].cells[idx]).css("width", nw);
  3313. }
  3314. }
  3315. if (footers.length > 0) { footers[idx].style.width = nw + "px"; }
  3316. if (skipGridAdjustments !== true) {
  3317. fixScrollOffsetAndhBoxPadding.call($bTable[0]);
  3318. }
  3319. if (p.forceFit === true) {
  3320. hn = headers[idx + p.nv]; // next visible th
  3321. nw = hn.newWidth || hn.width;
  3322. hn.width = nw;
  3323. hCols[idx + p.nv].style.width = nw + "px";
  3324. self.cols[idx + p.nv].style.width = nw + "px";
  3325. if (footers.length > 0) { footers[idx + p.nv].style.width = nw + "px"; }
  3326. p.colModel[idx + p.nv].width = nw;
  3327. } else {
  3328. p.tblwidth = self.newWidth || p.tblwidth;
  3329. //$bTable.css("width", p.tblwidth + "px");
  3330. //getGridComponent(COMPONENT_NAMES.HEADER_TABLE, self.hDiv).css("width", p.tblwidth + "px");
  3331. if (skipGridAdjustments !== true) {
  3332. self.hDiv.scrollLeft = self.bDiv.scrollLeft;
  3333. if (p.footerrow) {
  3334. //getGridComponent(COMPONENT_NAMES.FOOTER_TABLE, self.sDiv).css("width", p.tblwidth + "px");
  3335. self.sDiv.scrollLeft = self.bDiv.scrollLeft;
  3336. }
  3337. }
  3338. }
  3339. if (!p.autowidth && (p.widthOrg === undefined || p.widthOrg === "auto" || p.widthOrg === "100%") && skipGridAdjustments !== true) {
  3340. $j.setGridWidth.call($bTable, self.newWidth + p.scrollOffset, false);
  3341. }
  3342. if (!skipCallbacks) {
  3343. feedback.call($bTable[0], "resizeStop", nw, idx);
  3344. }
  3345. },
  3346. dragEnd: function () {
  3347. var self = this;
  3348. self.hDiv.style.cursor = "default";
  3349. if (self.resizing) {
  3350. if (self.resizing !== null && self.resizing.moved === true) {
  3351. $(self.headers[self.resizing.idx].el).removeData("autoResized");
  3352. self.resizeColumn(self.resizing.idx, false);
  3353. }
  3354. $(p.rs).removeData("pageX");
  3355. self.resizing = false;
  3356. setTimeout(function () {
  3357. $(p.rs).css("display", "none")
  3358. .prependTo(p.gBox); // restore the parent
  3359. }, p.doubleClickSensitivity);
  3360. }
  3361. self.curGbox = null;
  3362. document.onselectstart = function () { return true; };
  3363. $(document).off("mousemove.jqGrid mouseup.jqGrid" + p.id);
  3364. },
  3365. populateVisible: function () {
  3366. var self = this, $self = $(self), gridSelf = self.grid, bDiv = gridSelf.bDiv, $bDiv = $(bDiv);
  3367. if (gridSelf.timer) { clearTimeout(gridSelf.timer); }
  3368. gridSelf.timer = null;
  3369. var dh = $bDiv.height();
  3370. if (!dh) { return; }
  3371. var firstDataRow, rh;
  3372. if (self.rows.length) {
  3373. try {
  3374. firstDataRow = self.rows[1]; // self.rows[0] is cols row (the first row (.jqgfirstrow)) used only to set column width
  3375. rh = firstDataRow ? $(firstDataRow).outerHeight() || gridSelf.prevRowHeight : gridSelf.prevRowHeight;
  3376. } catch (pv) {
  3377. rh = gridSelf.prevRowHeight;
  3378. }
  3379. }
  3380. if (!rh) { return; }
  3381. gridSelf.prevRowHeight = rh;
  3382. var rn = p.rowNum;
  3383. gridSelf.scrollTop = bDiv.scrollTop;
  3384. var scrollTop = gridSelf.scrollTop;
  3385. var ttop = Math.round($self.position().top) - scrollTop;
  3386. var tbot = ttop + $self.height();
  3387. var div = rh * rn;
  3388. var page, npage, empty;
  3389. if (tbot < dh && ttop <= 0 &&
  3390. (p.lastpage === undefined || (parseInt((tbot + scrollTop + div - 1) / div, 10) || 0) <= p.lastpage)) {
  3391. npage = parseInt((dh - tbot + div - 1) / div, 10) || 1;
  3392. if (tbot >= 0 || npage < 2 || p.scroll === true) {
  3393. page = (Math.round((tbot + scrollTop) / div) || 0) + 1;
  3394. ttop = -1;
  3395. } else {
  3396. ttop = 1;
  3397. }
  3398. }
  3399. if (ttop > 0) {
  3400. page = (parseInt(scrollTop / div, 10) || 0) + 1;
  3401. npage = (parseInt((scrollTop + dh) / div, 10) || 0) + 2 - page;
  3402. empty = true;
  3403. }
  3404. if (npage) {
  3405. if (p.lastpage && (page > p.lastpage || p.lastpage === 1 || (page === p.page && page === p.lastpage))) {
  3406. return;
  3407. }
  3408. if (gridSelf.hDiv.loading) {
  3409. gridSelf.timer = setTimeout(function () { gridSelf.populateVisible.call(self); }, p.scrollTimeout);
  3410. } else {
  3411. p.page = page;
  3412. if (empty) {
  3413. gridSelf.selectionPreserver.call(self);
  3414. gridSelf.emptyRows.call(self, false, false);
  3415. }
  3416. gridSelf.populate.call(self, npage);
  3417. }
  3418. }
  3419. },
  3420. scrollGrid: function () { // this must be bDiv
  3421. if (p.scroll) {
  3422. var scrollTop = this.scrollTop;
  3423. // save last scrollTop of bDiv as property of grid object
  3424. if (grid.scrollTop === undefined) { grid.scrollTop = 0; }
  3425. if (scrollTop !== grid.scrollTop) {
  3426. grid.scrollTop = scrollTop;
  3427. if (grid.timer) { clearTimeout(grid.timer); }
  3428. grid.timer = setTimeout(function () { grid.populateVisible.call(ts); }, p.scrollTimeout);
  3429. }
  3430. }
  3431. grid.hDiv.scrollLeft = this.scrollLeft;
  3432. if (p.footerrow) {
  3433. grid.sDiv.scrollLeft = this.scrollLeft;
  3434. }
  3435. return false;
  3436. },
  3437. selectionPreserver: function () {
  3438. var self = this, $self = $(self), sr = p.selrow, sra = p.selarrrow ? $.makeArray(p.selarrrow) : null,
  3439. bDiv = self.grid.bDiv, left = bDiv.scrollLeft,
  3440. restoreSelection = function () {
  3441. var i;
  3442. p.selrow = null;
  3443. if (!p.multiPageSelection) {
  3444. clearArray(p.selarrrow); // p.selarrrow = [];
  3445. if (p.multiselect && sra && sra.length > 0) {
  3446. for (i = 0; i < sra.length; i++) {
  3447. if (sra[i] !== sr) {
  3448. setSelection.call($self, sra[i], false, null);
  3449. }
  3450. }
  3451. }
  3452. if (sr) {
  3453. setSelection.call($self, sr, false, null);
  3454. }
  3455. }
  3456. bDiv.scrollLeft = left;
  3457. $self.off(".selectionPreserver", restoreSelection);
  3458. };
  3459. $self.on("jqGridGridComplete.selectionPreserver", restoreSelection);
  3460. }
  3461. };
  3462. ts.grid = grid;
  3463. feedback.call(ts, "beforeInitGrid");
  3464. p.iColByName = buildColNameMap(p.colModel);
  3465. p.iPropByName = buildAddPropMap(p.additionalProperties);
  3466. // TODO: replace altclass : "ui-priority-secondary",
  3467. // set default buttonicon : "ui-icon-newwin" of navButtonAdd: fa-external-link, fa-desktop or other
  3468. // change the order in $.extend to allows to set icons using $.jgrid (for example $.jgrid.nav). It will be ovewritten currently by p.navOptions which we set above.
  3469. jgrid.msie = jgrid.msiever() > 0;
  3470. var gv = $("<div class='" + getGuiStyles("gView", "ui-jqgrid-view") + "' role='grid' aria-multiselectable='" + !!p.multiselect + "'></div>"),
  3471. isMSIE = jgrid.msie, dir;
  3472. p.direction = trim(p.direction.toLowerCase());
  3473. if (inArray(p.direction, ["ltr", "rtl"]) === -1) { p.direction = "ltr"; }
  3474. dir = p.direction;
  3475. $(gv).insertBefore(ts);
  3476. $self0.removeClass("scroll").appendTo(gv);
  3477. var eg = $("<div class='" + getGuiStyles("gBox", "ui-jqgrid") + "'></div>");
  3478. $(eg).attr({ "id": p.gBoxId, "dir": dir }).insertBefore(gv);
  3479. $(gv).attr("id", p.gViewId).appendTo(eg);
  3480. $("<div class='" + getGuiStyles("overlay", "jqgrid-overlay") + "' id='lui_" + p.id + "'></div>").insertBefore(gv);
  3481. $("<div class='" + getGuiStyles("loading", "loading") + "' id='load_" + p.id + "'>" + getDef("loadtext") + "</div>").insertBefore(gv);
  3482. $self0.attr({ "role": "presentation", "aria-labelledby": "gbox_" + ts.id });
  3483. var sortkeys = ["shiftKey", "altKey", "ctrlKey"],
  3484. // for reading of array of items from the input data it's required to know the
  3485. // mapping of input items to the column names (colModel[iCol].name items).
  3486. // The function normalizeRemapColumns converts p.remapColumns to p.cmNamesInputOrder and fills
  3487. // p.cmNamesInputOrder with the names colModel items.
  3488. // The function should be called only if no p.cmNamesInputOrder is specified
  3489. normalizeRemapColumns = function () {
  3490. // offset is the number of columns in colModel which should be skipped in calculation of the mapping
  3491. // offset is the number of columns from the list "rn", "cb", "subgrid".
  3492. // The index 0 in the p.remapColumns means the first column after the "rn", "cb", "subgrid"
  3493. var remapColumns = p.remapColumns, colModel = p.colModel, nCol = colModel.length, cmNames = [], i, remappedCmNames,
  3494. name;
  3495. for (i = 0; i < nCol; i++) {
  3496. name = colModel[i].name;
  3497. if (inArray(name, p.reservedColumnNames) < 0) {
  3498. cmNames.push(name);
  3499. }
  3500. }
  3501. // it's important to remark that the numbers in remapColumns or in
  3502. // jsonReder, localReader, xmlReader are based on the position of column
  3503. // in colModel BEFORE adding columns "rn", "cb", "subgrid"
  3504. if (remapColumns != null) {
  3505. // now we should remap items in cmNames corresponds to the indexes from p.remapColumns array
  3506. remappedCmNames = cmNames.slice(); // make copy of cmNames array
  3507. for (i = 0; i < remapColumns.length; i++) {
  3508. cmNames[i] = remappedCmNames[remapColumns[i]];
  3509. }
  3510. }
  3511. p.cmNamesInputOrder = cmNames;
  3512. },
  3513. stripGridPrefix = function (rowId) {
  3514. return stripPref(p.idPrefix, rowId);
  3515. },
  3516. formatCol = function (pos, rowInd, tv, rawObject, rowId, rdata) {
  3517. var cm = p.colModel[pos], cellAttrFunc,
  3518. rPrefix = cm.autoResizable ? "<span class='" + p.autoResizing.wrapperClassName + "'>" : "",
  3519. // see https://github.com/free-jqgrid/jqGrid/issues/74#issuecomment-107675796
  3520. // we will cut formatted string like "<span class='ui-jqgrid-cell-wrapper'>193,81</span>"
  3521. // to substring "193,81". The formatting (comma, point, dollar and so on) still stay.
  3522. unwrappedCellValue = cm.autoResizable ? tv.substring(rPrefix.length, tv.length - "</span>".length) : tv,
  3523. cellValue = p.useUnformattedDataForCellAttr && rdata != null ?
  3524. rdata[cm.name] :
  3525. (cm.autoResizable ? unwrappedCellValue : tv),
  3526. result, classes = cm.classes,
  3527. styleValue = cm.align ? "text-align:" + cm.align + ";" : "",
  3528. attrStr, matches, value, tilteValue,
  3529. encodeAttr = function (v) {
  3530. return typeof v === "string" ? v.replace(/'/g, "&#39;") : v;
  3531. },
  3532. rest = " aria-describedby='" + p.id + "_" + cm.name + "'";
  3533. if (cm.hidden === true) { styleValue += "display:none;"; }
  3534. if (rowInd === 0) {
  3535. styleValue += "width: " + grid.headers[pos].width + "px;";
  3536. } else if (isFunction(cm.cellattr) || (typeof cm.cellattr === "string" && jgrid.cellattr != null && isFunction(jgrid.cellattr[cm.cellattr]))) {
  3537. cellAttrFunc = isFunction(cm.cellattr) ? cm.cellattr : jgrid.cellattr[cm.cellattr];
  3538. attrStr = cellAttrFunc.call(ts, rowId, cellValue, rawObject, cm, rdata, unwrappedCellValue);
  3539. if (typeof attrStr === "string") {
  3540. // ??? probably one can create object with properties from the attrStr
  3541. // and then to use one common function with constructTr to combine the default
  3542. // properties with the properties used in cellattr and rowattr.
  3543. // Probably one could use $.extend with the most attributes. The exception are
  3544. // only class and style attributes which hold multi-values with " " or ";" as separator
  3545. attrStr = attrStr.replace(/\n/g, "&#xA;");
  3546. while (true) {
  3547. // we have to use ? in the construction ([^\2]*?) to have non-greedy (lazy, minimal) matching
  3548. // so that we will find the FIRST closing quote instead of default the LAST matching.
  3549. // TODO: more common regex for the attribute name.
  3550. // See http://www.w3.org/TR/html-markup/syntax.html#syntax-attributes:
  3551. // Attribute names must consist of one or more characters other than the space
  3552. // characters, U+0000 NULL, """, "'", ">", "/", "=", the control characters,
  3553. // and any characters that are not defined by Unicode.
  3554. // An important example is attribute name with "-" in the middle: "data-sometext"
  3555. matches = /^\s*(\w+[\w|\-]*)\s*=\s*([\"|\'])(.*?)\2(.*)/.exec(attrStr);
  3556. if (matches === null || matches.length < 5) {
  3557. if (!tilteValue && cm.title) {
  3558. tilteValue = cellValue;
  3559. }
  3560. return rest + " style='" + encodeAttr(styleValue) + "'" +
  3561. (classes ? " class='" + encodeAttr(classes) + "'" : "") +
  3562. (tilteValue ? " title='" + encodeAttr(tilteValue) + "'" : "");
  3563. }
  3564. value = matches[3];
  3565. attrStr = matches[4];
  3566. switch (matches[1].toLowerCase()) { // attribute name
  3567. case "class":
  3568. // if some special characters are inside of class value there MUST be escaped
  3569. // so we can use any quote characters (' or ") around the call value.
  3570. // So we don't need to save quote used in class attribute
  3571. if (classes) {
  3572. classes += " " + value;
  3573. } else {
  3574. classes = value;
  3575. }
  3576. break;
  3577. case "title":
  3578. //quotedTilteValue = quote + value + quote;
  3579. tilteValue = value;
  3580. break;
  3581. case "style":
  3582. styleValue += value;
  3583. break;
  3584. default:
  3585. // matches[2] is quote
  3586. rest += " " + matches[1] + "=" + matches[2] + value + matches[2];
  3587. break;
  3588. }
  3589. }
  3590. }
  3591. }
  3592. result = styleValue !== "" ? "style='" + styleValue + "'" : "";
  3593. result += (classes !== undefined ? (" class='" + classes + "'") : "") + ((cm.title && cellValue) ? (" title='" + stripHtml(tv).replace(/'/g, "&apos;") + "'") : "");
  3594. result += rest;
  3595. return result;
  3596. },
  3597. cellVal = function (val) {
  3598. return val == null || val === "" ? "&#160;" : (p.autoencode ? htmlEncode(val) : String(val));
  3599. },
  3600. normalizeTreeGridProperties = function (ldat) {
  3601. var treeReader = p.treeReader,
  3602. loaded = treeReader.loaded,
  3603. isLeaf = treeReader.leaf_field,
  3604. expanded = treeReader.expanded_field,
  3605. getBool = function (val) {
  3606. return val === true || val === "true" || val === "1";
  3607. };
  3608. if (p.treeGridModel === "nested" && !ldat[isLeaf]) {
  3609. var lft = parseInt(ldat[treeReader.left_field], 10),
  3610. rgt = parseInt(ldat[treeReader.right_field], 10);
  3611. ldat[isLeaf] = (rgt === lft + 1) ? true : false;
  3612. }
  3613. if (ldat[loaded] !== undefined) {
  3614. ldat[loaded] = getBool(ldat[loaded]);
  3615. }
  3616. ldat[isLeaf] = getBool(ldat[isLeaf]);
  3617. ldat[expanded] = getBool(ldat[expanded]);
  3618. // the next line is suspected. The local data which missing loaded property
  3619. // can be be changed to have expanded=false
  3620. // we comment it.
  3621. //ldat[expanded] = ldat[expanded] && (ldat[loaded] || ldat[loaded] === undefined);
  3622. },
  3623. formatter = function (rowId, cellval, colpos, rwdat, act, rdata) {
  3624. var cm = p.colModel[colpos], v;
  3625. if (cm.formatter !== undefined) {
  3626. rowId = String(p.idPrefix) !== "" ? stripGridPrefix(rowId) : rowId;
  3627. var opts = { rowId: rowId, colModel: cm, gid: p.id, pos: colpos, rowData: rdata || rwdat };
  3628. if (isFunction(cm.cellBuilder)) {
  3629. v = cm.cellBuilder.call(ts, cellval, opts, rwdat, act);
  3630. } else if (isFunction(cm.formatter)) {
  3631. v = cm.formatter.call(ts, cellval, opts, rwdat, act);
  3632. } else if ($.fmatter) {
  3633. v = $.fn.fmatter.call(ts, cm.formatter, cellval, opts, rwdat, act);
  3634. } else {
  3635. v = cellVal(cellval);
  3636. }
  3637. } else {
  3638. v = cellVal(cellval);
  3639. }
  3640. v = cm.autoResizable && cm.formatter !== "actions" ? "<span class='" + p.autoResizing.wrapperClassName + "'>" + v + "</span>" : v;
  3641. if (p.treeGrid && act !== "edit" && ((p.ExpandColumn == null && colpos === 0) || (p.ExpandColumn === cm.name))) {
  3642. if (rdata == null) { rdata = p.data[p._index[rowId]]; }
  3643. var curLevel = parseInt(rdata[p.treeReader.level_field] || 0, 10), levelOffset = 18,
  3644. rootLevel = parseInt(p.tree_root_level, 10),
  3645. lftpos = rootLevel === 0 ? curLevel : curLevel - 1,
  3646. isLeaf = rdata[p.treeReader.leaf_field],
  3647. isExpanded = rdata[p.treeReader.expanded_field],
  3648. icon = rdata[p.treeReader.icon_field],
  3649. iconClass = isLeaf ?
  3650. ((icon != null && icon !== "") ? icon : p.treeIcons.leaf) + " tree-leaf" :
  3651. (isExpanded ? p.treeIcons.minus + " tree-minus" : p.treeIcons.plus + " tree-plus");
  3652. //normalizeTreeGridProperties(rdata); // ??? don't needed more probably
  3653. if (!isLeaf && icon && typeof icon === "string") {
  3654. var icons = icon.split(",");
  3655. if (icons.length === 2) {
  3656. iconClass = isExpanded ? icons[0] : icons [1];
  3657. }
  3658. }
  3659. v = "<div class='tree-wrap' style='width:" + ((lftpos + 1) * levelOffset) +
  3660. "px;'><div class='" +
  3661. mergeCssClasses(p.treeIcons.commonIconClass, iconClass, "treeclick") +
  3662. "' style='" +
  3663. (p.ExpandColClick === true ? "cursor:pointer;" : "") +
  3664. (p.direction === "rtl" ? "margin-right:" : "margin-left:") +
  3665. (lftpos * levelOffset) + "px;'></div></div>" +
  3666. "<span class='cell-wrapper" + (isLeaf ? "leaf" : "") + "'" +
  3667. (p.ExpandColClick ? " style='cursor:pointer;'" : "") + ">" +
  3668. v + "</span>";
  3669. }
  3670. return v;
  3671. },
  3672. emptyRows = function (scroll, locdata) {
  3673. var self = this, bDiv = grid.bDiv,
  3674. frozenTable = grid.fbDiv != null ?
  3675. grid.fbDiv.children(".ui-jqgrid-btable")[0] : null,
  3676. removeRows = function (table) {
  3677. if (!table) { return; }
  3678. var tableRows = table.rows, firstrow = tableRows[0];
  3679. if (p.deepempty) {
  3680. if (tableRows) { $(tableRows).slice(1).remove(); }
  3681. } else if (p.quickEmpty) {
  3682. if (p.quickEmpty === "quickest") {
  3683. table.replaceChild(document.createElement("tbody"), table.tBodies[0]);
  3684. table.firstChild.appendChild(firstrow);
  3685. } else {
  3686. while (tableRows.length > 1) { // skip deliting of the first row
  3687. table.deleteRow(tableRows.length - 1);
  3688. }
  3689. }
  3690. } else {
  3691. $(table.firstChild).empty().append(firstrow);
  3692. }
  3693. };
  3694. $(self).off(".jqGridFormatter");
  3695. removeRows(self);
  3696. removeRows(frozenTable);
  3697. if (scroll && p.scroll) {
  3698. $(bDiv.firstChild).css({ height: "auto" });
  3699. $(bDiv.firstChild.firstChild).css({ height: 0, display: "none" });
  3700. if (bDiv.scrollTop !== 0) {
  3701. bDiv.scrollTop = 0;
  3702. }
  3703. }
  3704. if (locdata === true && p.treeGrid) {
  3705. clearArray(p.data); //p.data = [];
  3706. clearArray(p.lastSelectedData); //p.lastSelectedData = [];
  3707. p._index = {};
  3708. p.dataIndexById = {};
  3709. p.indexByColumnData = {};
  3710. }
  3711. p.rowIndexes = {};
  3712. p.iRow = -1;
  3713. p.iCol = -1;
  3714. //$(self.grid.headers).each(function () { $(this.el).removeData("autoResized"); });
  3715. },
  3716. addItemDataToColumnIndex = function (rd, id) {
  3717. var cmName, v;
  3718. for (cmName in p.indexByColumnData) {
  3719. if (p.indexByColumnData.hasOwnProperty(cmName)) {
  3720. v = rd[cmName];
  3721. if (rd.hasOwnProperty(cmName) && v !== undefined && v !== "") {
  3722. // rd[cmName] is the value, which need be saved in p.indexByColumnData[cmName]
  3723. if (p.ignoreCase) {
  3724. v = String(v).toLowerCase();
  3725. }
  3726. if (p.indexByColumnData[cmName][v] === undefined) {
  3727. p.indexByColumnData[cmName][v] = {};
  3728. }
  3729. p.indexByColumnData[cmName][v][id] = rd[cmName];
  3730. if (p.dataIndexById[id] === undefined) {
  3731. p.dataIndexById[id] = {};
  3732. }
  3733. if (p.dataIndexById[id][cmName] === undefined) {
  3734. p.dataIndexById[id][cmName] = {};
  3735. }
  3736. p.dataIndexById[id][cmName][v] = p.indexByColumnData[cmName][v];
  3737. }
  3738. }
  3739. }
  3740. },
  3741. removeItemDataFromColumnIndex = function (id) {
  3742. var cmName, columnIndex, v, index = p.dataIndexById[id];
  3743. if (index == null) {
  3744. return;
  3745. }
  3746. for (cmName in index) {
  3747. if (index.hasOwnProperty(cmName)) {
  3748. columnIndex = index[cmName];
  3749. for (v in columnIndex) {
  3750. if (columnIndex.hasOwnProperty(v)) {
  3751. delete p.indexByColumnData[cmName][v][id];
  3752. if ($.isEmptyObject(p.indexByColumnData[cmName][v])) {
  3753. delete p.indexByColumnData[cmName][v];
  3754. }
  3755. }
  3756. }
  3757. }
  3758. }
  3759. delete p.dataIndexById[id];
  3760. },
  3761. normalizeData = function () {
  3762. var data = p.data, dataLength = data.length, i, cur, cells, idName, idIndex, v, rd, id,
  3763. localReader = p.localReader, additionalProperties = p.additionalProperties,
  3764. cellName = localReader.cell, cmName, isArrayCells, addProp, info,
  3765. arrayReaderInfos = p.arrayReaderInfos;
  3766. if (p.datatype !== "local" || localReader.repeatitems !== true) {
  3767. if (p.treeGrid) {
  3768. for (i = 0; i < dataLength; i++) {
  3769. normalizeTreeGridProperties(data[i]);
  3770. }
  3771. }
  3772. return; // nothing to do
  3773. }
  3774. idName = p.keyName === false ?
  3775. (isFunction(localReader.id) ? localReader.id.call(ts, data) : localReader.id) :
  3776. p.keyName;
  3777. if (!isNaN(idName)) {
  3778. idIndex = Number(idName);
  3779. /*for (cmName in arrayReaderInfos) {
  3780. if (arrayReaderInfos.hasOwnProperty(cmName)) {
  3781. info = arrayReaderInfos[cmName];
  3782. if (info.order === idIndex) {
  3783. idName = info.name;
  3784. break;
  3785. }
  3786. }
  3787. }*/
  3788. } else if (!isFunction(idName)) {
  3789. if (p.arrayReaderInfos[idName] != null) {
  3790. idIndex = p.arrayReaderInfos[idName].order;
  3791. }
  3792. }
  3793. for (i = 0; i < dataLength; i++) {
  3794. cur = data[i];
  3795. cells = cellName ? getAccessor(cur, cellName) || cur : cur;
  3796. isArrayCells = isArray(cells);
  3797. rd = {};
  3798. for (cmName in arrayReaderInfos) {
  3799. if (arrayReaderInfos.hasOwnProperty(cmName)) {
  3800. info = arrayReaderInfos[cmName];
  3801. v = getAccessor(cells, isArrayCells ? info.order : info.name);
  3802. if (info.type === 1) { // additional property
  3803. addProp = additionalProperties[info.index];
  3804. if (addProp != null && isFunction(addProp.convert)) {
  3805. v = addProp.convert(v, cells);
  3806. }
  3807. }
  3808. if (v !== undefined) {
  3809. rd[cmName] = v;
  3810. }
  3811. }
  3812. }
  3813. // read id.
  3814. if (rd[idName] !== undefined) {
  3815. // in case of p.keyName or if there exist column with the same id name
  3816. // probably one should test only for rd[p.keyName] !== undefined
  3817. // and get rd[p.keyName] below, but the probability that the user
  3818. // wanted to use the column rd[idName] as the rowid seemd me
  3819. // higher as the opposite case.
  3820. // the id should be already read in p.keyName column.
  3821. // One need generate id only if the input data had no id
  3822. id = rd[idName] !== undefined ? rd[idName] : randId(); //id = br + i;
  3823. } else {
  3824. id = getAccessor(cur, isArray(cur) ? idIndex : idName);
  3825. if (id === undefined) {
  3826. id = getAccessor(cells, isArray(cells) ? idIndex : idName);
  3827. }
  3828. if (id === undefined) {
  3829. id = randId(); //id = br + i;
  3830. }
  3831. }
  3832. id = String(id);
  3833. rd[localReader.id] = id; //p.idPrefix + id;
  3834. // the next two line are the most important!
  3835. // one should consider to remove true parameter to improve the performance !!!
  3836. if (p.treeGrid) { normalizeTreeGridProperties(rd); }
  3837. extend(data[i], rd); // extend(true, data[i], rd);
  3838. }
  3839. },
  3840. refreshIndex = function () {
  3841. var datalen = p.data.length, idname, i, val, item;
  3842. if (p.keyName === false || (p.loadonce && p.dataTypeOrg)) {
  3843. idname = p.localReader.id;
  3844. } else {
  3845. idname = p.keyName;
  3846. }
  3847. p._index = {};
  3848. p.dataIndexById = {};
  3849. p.indexByColumnData = buildEmptyIndexedColumnMap();
  3850. for (i = 0; i < datalen; i++) {
  3851. item = p.data[i];
  3852. val = getAccessor(item, idname);
  3853. if (val === undefined) {
  3854. val = String(randId()); //String(i + 1);
  3855. if (item[idname] === undefined) {
  3856. item[idname] = val;
  3857. }
  3858. }
  3859. p._index[val] = i;
  3860. addItemDataToColumnIndex.call(this, item, val);
  3861. }
  3862. },
  3863. constructTr = function (id, hide, altClass, rd, cur, selected) {
  3864. var tabindex = "-1", restAttr = "", attrName, style = hide ? "display:none;" : "", self = this,
  3865. classes = getGuiStyles("gridRow", "jqgrow ui-row-" + p.direction) + (altClass ? " " + altClass : "") + (selected ? " " + getGuiStyles("states.select") : ""),
  3866. rowAttrObj = $(self).triggerHandler("jqGridRowAttr", [rd, cur, id]);
  3867. if (typeof rowAttrObj !== "object") {
  3868. rowAttrObj = isFunction(p.rowattr) ? p.rowattr.call(self, rd, cur, id) :
  3869. (typeof p.rowattr === "string" && jgrid.rowattr != null && isFunction(jgrid.rowattr[p.rowattr]) ?
  3870. jgrid.rowattr[p.rowattr].call(self, rd, cur, id) : {});
  3871. }
  3872. if (rowAttrObj != null && !$.isEmptyObject(rowAttrObj)) {
  3873. if (rowAttrObj.hasOwnProperty("id")) {
  3874. id = rowAttrObj.id;
  3875. delete rowAttrObj.id;
  3876. }
  3877. if (rowAttrObj.hasOwnProperty("tabindex")) {
  3878. tabindex = rowAttrObj.tabindex;
  3879. delete rowAttrObj.tabindex;
  3880. }
  3881. if (rowAttrObj.hasOwnProperty("style")) {
  3882. style += rowAttrObj.style;
  3883. delete rowAttrObj.style;
  3884. }
  3885. if (rowAttrObj.hasOwnProperty("class")) {
  3886. classes += " " + rowAttrObj["class"];
  3887. delete rowAttrObj["class"];
  3888. }
  3889. // don't allow to change role attribute
  3890. try { delete rowAttrObj.role; } catch (ignore) { }
  3891. for (attrName in rowAttrObj) {
  3892. if (rowAttrObj.hasOwnProperty(attrName)) {
  3893. restAttr += " " + attrName + "=" + rowAttrObj[attrName];
  3894. }
  3895. }
  3896. }
  3897. if (p.treeGrid) {
  3898. if (parseInt(rd[p.treeReader.level_field], 10) !== parseInt(p.tree_root_level, 10)) {
  3899. var pn = $j.getNodeParent.call($(this), rd),
  3900. expan = pn && pn.hasOwnProperty(p.treeReader.expanded_field) ?
  3901. pn[p.treeReader.expanded_field] : true;
  3902. if (!expan && !hide) {
  3903. // TODO: append ";" to style if required
  3904. style += "display:none;";
  3905. }
  3906. }
  3907. }
  3908. return "<tr role='row' id='" + id + "' tabindex='" + tabindex + "' class='" + classes + "'" +
  3909. (style === "" ? "" : " style='" + style + "'") + restAttr + ">";
  3910. },
  3911. finalizationFormatters = function () {
  3912. var i, formatName, fmatter = $.fn.fmatter;
  3913. for (i = 0; i < p.colModel.length; i++) {
  3914. formatName = p.colModel[i].formatter;
  3915. if (typeof formatName === "string" && fmatter != null &&
  3916. isFunction(fmatter[formatName]) && isFunction(fmatter[formatName].pageFinalization)) {
  3917. fmatter[formatName].pageFinalization.call(this, i);
  3918. }
  3919. }
  3920. },
  3921. fillOrClearCellBuilder = function (clear, act) {
  3922. var i, cm, colModel = p.colModel, n = colModel.length, opt,
  3923. autoencodeCellBuilder = function (v) {
  3924. return v == null || v === "" ? "&#160;" : htmlEncode(v);
  3925. },
  3926. simpleCellBuilder = function (v) {
  3927. return v == null || v === "" ? "&#160;" : String(v);
  3928. };
  3929. for (i = 0; i < n; i++) {
  3930. cm = colModel[i];
  3931. cm.cellBuilder = null;
  3932. if (!clear) {
  3933. opt = { colModel: cm, gid: p.id, pos: i };
  3934. if (cm.formatter === undefined) {
  3935. cm.cellBuilder = p.autoencode ? autoencodeCellBuilder : simpleCellBuilder;
  3936. } else if (typeof cm.formatter === "string" && $.fn.fmatter != null && isFunction($.fn.fmatter.getCellBuilder)) {
  3937. cm.cellBuilder = $.fn.fmatter.getCellBuilder.call(ts, cm.formatter, opt, act || "add");
  3938. } else if (isFunction(cm.getCellBuilder)) {
  3939. cm.cellBuilder = cm.getCellBuilder.call(ts, opt, act || "add");
  3940. }
  3941. }
  3942. }
  3943. },
  3944. readInput = function (data, rcnt, more, adjust) {
  3945. var self = this, $self = $(self), startReq = new Date(), datatype = p.datatype,
  3946. // readAllInputData shows that one should read ALL input items, not only the current page of data
  3947. readAllInputData = (datatype !== "local" && p.loadonce) || datatype === "xmlstring" || datatype === "jsonstring",
  3948. isXML = (datatype === "xmlstring" || datatype === "xml") && $.isXMLDoc(data),
  3949. locid = "_id_", dataReader = p.localReader, fieldReader = getAccessor;
  3950. if (data) {
  3951. if (datatype === "xml" && !isXML) {
  3952. return;
  3953. }
  3954. if (p.treeANode === -1 && !p.scroll) {
  3955. grid.emptyRows.call(self, false, true);
  3956. rcnt = 1;
  3957. } else {
  3958. rcnt = rcnt > 1 ? rcnt : 1;
  3959. }
  3960. } else {
  3961. // in case of usage TreeGrid for example
  3962. return;
  3963. }
  3964. if (readAllInputData) {
  3965. clearArray(p.data); //p.data = [];
  3966. clearArray(p.lastSelectedData); //p.lastSelectedData = [];
  3967. p._index = {};
  3968. if (p.grouping && p.groupingView != null) {
  3969. p.groupingView.groups = [];
  3970. p.groupingView._locgr = false;
  3971. }
  3972. p.localReader.id = locid; // consider to place the statement in if (p.treeGrid) {...}
  3973. }
  3974. p.reccount = 0;
  3975. switch (datatype) {
  3976. case "xml":
  3977. case "xmlstring":
  3978. dataReader = p.xmlReader;
  3979. fieldReader = jgrid.getXmlData;
  3980. break;
  3981. case "json":
  3982. case "jsonp":
  3983. case "jsonstring":
  3984. dataReader = p.jsonReader;
  3985. break;
  3986. default:
  3987. break;
  3988. }
  3989. var i, cells, len, drows, idName, idIndex, rd = {}, idr,
  3990. colModel = p.colModel, nCol = colModel.length, cmName,
  3991. iChild, children, nChildren, child,
  3992. // TODO: consider to introduce preloadedAttributes in the same way
  3993. // like we use to preloadedNodes below and to cache .attributes[i]
  3994. // in the same way like one cache .childNodes[i].
  3995. // One should measure the performance, to find out whether
  3996. // such caching will improve the performance.
  3997. arrayReaderInfos = p.arrayReaderInfos, info, preloadedNodes = {},
  3998. attrReader = function (nodeName) {
  3999. return function (obj) {
  4000. var attrValue = obj != null && isFunction(obj.getAttribute) ? obj.getAttribute(nodeName) : null;
  4001. return attrValue !== null ? attrValue : undefined;
  4002. };
  4003. },
  4004. nodeReader = function (nodeName) {
  4005. return function () {
  4006. // commented code which used getElementsByTagName works
  4007. // good in new web browsers (Chrome, Firefox, Safari),
  4008. // but it is slowly in IE10 and especially in IE8.
  4009. // So we use the code which is very good for all web browsers
  4010. /*var elem = obj.getElementsByTagName(nodeName)[0], childNodes;
  4011. if (elem != null) {
  4012. childNodes = elem.childNodes;
  4013. return childNodes.length > 0 ? childNodes[0].nodeValue : undefined;
  4014. }
  4015. return undefined;*/
  4016. var elem = preloadedNodes[nodeName], childNodes;
  4017. if (elem == null) { return undefined; }
  4018. childNodes = elem.childNodes;
  4019. return childNodes.length > 0 ? childNodes[0].nodeValue : undefined;
  4020. };
  4021. };
  4022. p.page = intNum(fieldReader(data, dataReader.page), p.page);
  4023. p.lastpage = intNum(fieldReader(data, dataReader.total), 1);
  4024. p.records = intNum(fieldReader(data, dataReader.records));
  4025. if (isFunction(dataReader.userdata)) {
  4026. p.userData = dataReader.userdata.call(self, data) || {};
  4027. } else if (isXML) {
  4028. fieldReader(data, dataReader.userdata, true)
  4029. .each(function () {
  4030. p.userData[this.getAttribute("name")] = $(this).text();
  4031. });
  4032. } else {
  4033. p.userData = fieldReader(data, dataReader.userdata) || {};
  4034. }
  4035. // fill colReader and
  4036. fillOrClearCellBuilder();
  4037. var colReader = {}, isArrayCells, v, addProp, items,
  4038. additionalProperties = p.additionalProperties,
  4039. setSimpleColReaderIfPossible = function (propName, nameReaderOrAddProp) {
  4040. if (isXML && typeof nameReaderOrAddProp === "string") {
  4041. if (/^\w+$/.test(nameReaderOrAddProp)) {
  4042. colReader[propName] = nodeReader(nameReaderOrAddProp);
  4043. } else if (/^\[\w+\]$/.test(nameReaderOrAddProp)) {
  4044. colReader[propName] = attrReader(nameReaderOrAddProp.substring(1, nameReaderOrAddProp.length - 1));
  4045. }
  4046. }
  4047. },
  4048. colReaderFilling = function (colOrAddProp) {
  4049. var colOrAddPropName = colOrAddProp.name,
  4050. nameReader = isXML ?
  4051. colOrAddProp.xmlmap || colOrAddPropName :
  4052. (datatype === "local" && !p.dataTypeOrg) || datatype === "jsonstring" || datatype === "json" || datatype === "jsonp" ? colOrAddProp.jsonmap || colOrAddPropName : colOrAddPropName;
  4053. if (p.keyName !== false && colOrAddProp.key === true) {
  4054. p.keyName = colOrAddPropName; // TODO: replace nameReader to colOrAddPropName if we don't will read it at the second time
  4055. }
  4056. if (typeof nameReader === "string" || isFunction(nameReader)) {
  4057. colReader[colOrAddPropName] = nameReader;
  4058. }
  4059. if (!isFunction(nameReader)) {
  4060. setSimpleColReaderIfPossible(colOrAddPropName, nameReader);
  4061. }
  4062. };
  4063. for (i = 0; i < nCol; i++) {
  4064. colReaderFilling(colModel[i]);
  4065. }
  4066. nCol = additionalProperties.length;
  4067. for (i = 0; i < nCol; i++) {
  4068. addProp = additionalProperties[i];
  4069. if (typeof addProp === "object" && addProp != null) {
  4070. colReaderFilling(addProp);
  4071. } else {
  4072. setSimpleColReaderIfPossible(addProp, addProp);
  4073. }
  4074. }
  4075. // TODO: Consider to allow to specify key:true property in additionalProperties
  4076. // in the case the item of additionalProperties should looks not like
  4077. // "myProp" and not like {name: "myProp", convert: function (data) {...}} used in TreeGrid,
  4078. // but in more common form {name: "myProp", key:true, convert: function (data) {...}}
  4079. // prepare to read id of data items
  4080. // if p.keyName !== false it contains the name of the column or the nameReader functoin (jsonmap or xmlmap)
  4081. // in the case the reading of id is simple and one DON'T NEED TO READ IT AT ALL
  4082. // because it will be already read during reading of the columns
  4083. idName = p.keyName === false ?
  4084. (isFunction(dataReader.id) ? dataReader.id.call(self, data) : dataReader.id) :
  4085. p.keyName;
  4086. if (!isNaN(idName)) {
  4087. idIndex = Number(idName);
  4088. } else if (!isFunction(idName)) {
  4089. if (arrayReaderInfos[idName]) {
  4090. idIndex = arrayReaderInfos[idName].order;
  4091. }
  4092. if (isXML && p.keyName === false) {
  4093. if (typeof idName === "string" && /^\[\w+\]$/.test(idName)) {
  4094. idName = attrReader(idName.substring(1, idName.length - 1));
  4095. } else if (typeof idName === "string" && /^\w+$/.test(idName)) {
  4096. idName = nodeReader(idName);
  4097. }
  4098. }
  4099. }
  4100. // get array of items from the input data
  4101. drows = fieldReader(data, dataReader.root, true);
  4102. if (dataReader.row) {
  4103. if (drows.length === 1 && typeof dataReader.row === "string" && /^\w+$/.test(dataReader.row)) {
  4104. items = [];
  4105. children = drows[0].childNodes;
  4106. nChildren = children.length;
  4107. for (iChild = 0; iChild < nChildren; iChild++) {
  4108. child = children[iChild];
  4109. if (child.nodeType === 1 && child.nodeName === dataReader.row) {
  4110. items.push(child);
  4111. }
  4112. }
  4113. drows = items;
  4114. } else {
  4115. drows = fieldReader(drows, dataReader.row, true); // || [];
  4116. }
  4117. }
  4118. if (drows == null && isArray(data)) { drows = data; }
  4119. if (!drows) { drows = []; }
  4120. len = drows.length;
  4121. if (len > 0 && p.page <= 0) { p.page = 1; }
  4122. var rn = parseInt(p.rowNum, 10); // br = p.scroll ? randId() : 1
  4123. if (adjust) { rn *= adjust + 1; }
  4124. // The first loop (from 0 till len) read ALL data and saves it in array
  4125. var cellsToDisplay = [], ids = [], id, cur;
  4126. items = [];
  4127. for (i = 0; i < len; i++) {
  4128. cur = drows[i];
  4129. cells = dataReader.repeatitems && dataReader.cell ? fieldReader(cur, dataReader.cell, true) || cur : cur;
  4130. isArrayCells = dataReader.repeatitems && (isXML || isArray(cells));
  4131. // the first step: reading the input data from the current item
  4132. rd = {}; // require to prevent modification of items previously placed in p.data
  4133. preloadedNodes = {};
  4134. if (isXML && !isArrayCells && cells != null) {
  4135. // reading of simple children nodes by name can be relatively slow
  4136. // because one enumerates all children nodes to find the node with
  4137. // specified name
  4138. children = cells.childNodes;
  4139. nChildren = children.length;
  4140. for (iChild = 0; iChild < nChildren; iChild++) {
  4141. child = children[iChild];
  4142. if (child.nodeType === 1) {
  4143. preloadedNodes[child.nodeName] = child;
  4144. }
  4145. }
  4146. // TODO: one can consider to examine cells.attributes and
  4147. // to save all values in preloadedAttributes map.
  4148. }
  4149. for (cmName in arrayReaderInfos) {
  4150. if (arrayReaderInfos.hasOwnProperty(cmName)) {
  4151. info = arrayReaderInfos[cmName];
  4152. if (isArrayCells) {
  4153. v = cells[info.order];
  4154. if (isXML && v != null) {
  4155. v = v.textContent || v.text;
  4156. }
  4157. } else if (colReader[cmName] != null && typeof colReader[cmName] !== "string") { // isFunction(colReader[cmName])
  4158. v = colReader[cmName].call(self, cells, { cmName: cmName, iItem: i });
  4159. } else {
  4160. v = fieldReader(cells, typeof colReader[cmName] === "string" ? colReader[cmName] : info.name);
  4161. }
  4162. if (info.type === 1) { // additional property
  4163. addProp = additionalProperties[info.index];
  4164. if (addProp != null && isFunction(addProp.convert)) {
  4165. v = addProp.convert(v, cells);
  4166. }
  4167. }
  4168. if (v !== undefined) {
  4169. rd[cmName] = v;
  4170. }
  4171. }
  4172. }
  4173. // read id.
  4174. if (rd[idName] !== undefined) {
  4175. // the id should be already read in p.keyName column.
  4176. // One need generate id only if the input data had no id
  4177. id = rd[idName] !== undefined ? rd[idName] : randId(); //id = br + i;
  4178. } else {
  4179. id = fieldReader(cur, isArray(cur) ? idIndex : idName);
  4180. if (id === undefined) {
  4181. id = fieldReader(cells, isArray(cells) ? idIndex : idName);
  4182. }
  4183. if (id === undefined) {
  4184. id = randId(); //id = br + i;
  4185. }
  4186. }
  4187. if (rd[idName] === undefined) {
  4188. rd[idName] = id;
  4189. }
  4190. id = String(id);
  4191. idr = p.idPrefix + id;
  4192. if (p.treeGrid) { normalizeTreeGridProperties(rd); }
  4193. // final steps of reading the row
  4194. if (i < rn) {
  4195. ids.push(idr);
  4196. cellsToDisplay.push(cells);
  4197. items.push(rd);
  4198. } else if (!readAllInputData) {
  4199. break;
  4200. }
  4201. if (readAllInputData || p.treeGrid === true) {
  4202. rd[locid] = id; //stripGridPrefix(idr);
  4203. p.data.push(rd);
  4204. addItemDataToColumnIndex(rd, id);
  4205. p._index[rd[locid]] = p.data.length - 1;
  4206. }
  4207. }
  4208. if (readAllInputData && p.treeGrid !== true) {
  4209. if (p.forceClientSorting) {
  4210. // don't display the data, just read it.
  4211. return;
  4212. }
  4213. // initialize lastSelectedData to simplify the usage of lastSelectedData
  4214. p.lastSelectedData = p.data.slice();
  4215. }
  4216. // of rd items plus array cells items (almost the same as drows).
  4217. // The second loop (from 0 till min(len,rn)) will build rowData from the both arrays
  4218. // Then one place rowData AT ONCE to the body any calls afterInsertRow in the loop
  4219. // for every inserted row.
  4220. // Finally one clean up the both arrays
  4221. var rowData = jgrid.parseDataToHtml.call(self, len, ids, items, cellsToDisplay, rcnt, adjust, readAllInputData);
  4222. fillOrClearCellBuilder(true); // clear cellBuilders
  4223. // place the HTML string fragments collected in rowData in the body of grid
  4224. var fpos = p.treeANode > -1 ? p.treeANode : 0;
  4225. var $tbody = $(self.tBodies[0]);
  4226. if (p.treeGrid === true && fpos > 0) {
  4227. $(self.rows[fpos]).after(rowData.join(""));
  4228. } else if (p.scroll) {
  4229. $tbody.append(rowData.join(""));
  4230. } else if (self.firstElementChild == null || (document.documentMode !== undefined && document.documentMode <= 9)) {
  4231. // for IE8 for example
  4232. $tbody.html($tbody.html() + rowData.join("")); // append to innerHTML of tbody which contains the first row (.jqgfirstrow)
  4233. self.grid.cols = self.rows[0].cells; // update cached first row
  4234. } else {
  4235. self.firstElementChild.innerHTML += rowData.join(""); // append to innerHTML of tbody which contains the first row (.jqgfirstrow)
  4236. self.grid.cols = self.rows[0].cells; // update cached first row
  4237. }
  4238. // refresh rowIndexes cash in case of usage grouping
  4239. if (p.grouping) {
  4240. rebuildRowIndexes.call(self);
  4241. // bind onclick on +/- icon of grouping header to the call of groupingToggle
  4242. var expandOrCollapseGroup = function (e) {
  4243. var groupHeaderId = $(this).closest("tr.jqgroup").attr("id");
  4244. $self.jqGrid("groupingToggle", groupHeaderId, this, e);
  4245. return false;
  4246. },
  4247. $tr;
  4248. for (i = 0; i < self.rows.length; i++) {
  4249. $tr = $(self.rows[i]);
  4250. if ($tr.hasClass("jqgroup")) {
  4251. $tr.children("td")
  4252. .children("span.tree-wrap")
  4253. .click(expandOrCollapseGroup);
  4254. }
  4255. }
  4256. }
  4257. //
  4258. if (p.subGrid === true) {
  4259. // make subgrid specific actions: bind click event handler to "+"
  4260. try { $j.addSubGrid.call($self, p.iColByName.subgrid); } catch (ignore) { }
  4261. }
  4262. if (p.gridview === false || isFunction(p.afterInsertRow)) {
  4263. for (i = 0; i < Math.min(len, rn); i++) {
  4264. feedback.call(self, "afterInsertRow", ids[i], items[i], cellsToDisplay[i]);
  4265. }
  4266. }
  4267. p.totaltime = new Date() - startReq;
  4268. if (i > 0) {
  4269. if (p.records === 0) { p.records = len; }
  4270. }
  4271. clearArray(rowData);
  4272. if (p.treeGrid === true) {
  4273. try { $j.setTreeNode.call($self, fpos + 1, i + fpos + 1); } catch (ignore) { }
  4274. }
  4275. p.reccount = Math.min(len, rn);
  4276. p.treeANode = -1;
  4277. if (p.userDataOnFooter) { $j.footerData.call($self, "set", p.userData, true); }
  4278. if (readAllInputData) {
  4279. p.records = len;
  4280. p.lastpage = Math.ceil(len / rn);
  4281. }
  4282. if (!more) { self.updatepager(false, true); }
  4283. finalizationFormatters.call(self);
  4284. },
  4285. addLocalData = function () {
  4286. var $self = $(this), st = p.multiSort ? [] : "", sto = {}, fndsort = false, cmtypes = {}, grtypes = [], grindexes = [],
  4287. defSrcFormat = getRes("formatter.date.srcformat"),
  4288. defNewFormat = getRes("formatter.date.newformat");
  4289. if (!isArray(p.data)) {
  4290. return {};
  4291. }
  4292. if (p.multiSort) {
  4293. getSortNames(st, sto);
  4294. }
  4295. var grpview = p.grouping ? p.groupingView : false, lengrp, gin,
  4296. processColModel = function (cm, iCol1, isAddProp) {
  4297. var srcformat, newformat,
  4298. grindex = cm.index || cm.name,
  4299. sorttype = cm.sorttype || "text";
  4300. cmtypes[cm.name] = {
  4301. reader: !p.dataTypeOrg ? cm.jsonmap || cm.name : cm.name,
  4302. iCol: iCol1,
  4303. stype: sorttype,
  4304. srcfmt: "",
  4305. newfmt: "",
  4306. sfunc: cm.sortfunc || null,
  4307. isAddProp: isAddProp === true ? true : false
  4308. };
  4309. if (sorttype === "date" || sorttype === "datetime") {
  4310. if (cm.formatter && typeof cm.formatter === "string" && cm.formatter === "date") {
  4311. if (cm.formatoptions && cm.formatoptions.srcformat) {
  4312. srcformat = cm.formatoptions.srcformat;
  4313. } else {
  4314. srcformat = defSrcFormat;
  4315. }
  4316. if (cm.formatoptions && cm.formatoptions.newformat) {
  4317. newformat = cm.formatoptions.newformat;
  4318. } else {
  4319. newformat = defNewFormat;
  4320. }
  4321. } else {
  4322. srcformat = newformat = cm.datefmt || "Y-m-d";
  4323. }
  4324. cmtypes[cm.name].srcfmt = srcformat;
  4325. cmtypes[cm.name].newfmt = newformat;
  4326. }
  4327. if (p.grouping) {
  4328. for (gin = 0, lengrp = grpview.groupField.length; gin < lengrp; gin++) {
  4329. if (cm.name === grpview.groupField[gin]) {
  4330. grtypes[gin] = cmtypes[grindex];
  4331. grindexes[gin] = grindex;
  4332. }
  4333. }
  4334. }
  4335. if (!p.multiSort) {
  4336. if (!fndsort && (cm.index === p.sortname || cm.name === p.sortname)) {
  4337. st = cm.name; // ???
  4338. fndsort = true;
  4339. }
  4340. }
  4341. };
  4342. each(p.colModel, function (iCol1) {
  4343. processColModel(this, iCol1);
  4344. });
  4345. each(p.additionalProperties, function (iCol1) {
  4346. processColModel(
  4347. typeof this === "string" ? { name: this } : this,
  4348. iCol1,
  4349. true
  4350. );
  4351. });
  4352. if (p.treeGrid) {
  4353. $j.SortTree.call($self, st, p.sortorder,
  4354. cmtypes[st] != null && cmtypes[st].stype ? cmtypes[st].stype : "text",
  4355. cmtypes[st] != null && cmtypes[st].srcfmt ? cmtypes[st].srcfmt : "");
  4356. return false;
  4357. }
  4358. var compareFnMap = {
  4359. "eq": function (queryObj) { return queryObj.equals; },
  4360. "ne": function (queryObj) { return queryObj.notEquals; },
  4361. "lt": function (queryObj) { return queryObj.less; },
  4362. "le": function (queryObj) { return queryObj.lessOrEquals; },
  4363. "gt": function (queryObj) { return queryObj.greater; },
  4364. "ge": function (queryObj) { return queryObj.greaterOrEquals; },
  4365. "cn": function (queryObj) { return queryObj.contains; },
  4366. "nc": function (queryObj, op) { return op === "OR" ? queryObj.orNot().contains : queryObj.andNot().contains; },
  4367. "bw": function (queryObj) { return queryObj.startsWith; },
  4368. "bn": function (queryObj, op) { return op === "OR" ? queryObj.orNot().startsWith : queryObj.andNot().startsWith; },
  4369. "en": function (queryObj, op) { return op === "OR" ? queryObj.orNot().endsWith : queryObj.andNot().endsWith; },
  4370. "ew": function (queryObj) { return queryObj.endsWith; },
  4371. "ni": function (queryObj, op) { return op === "OR" ? queryObj.orNot().inSet : queryObj.andNot().inSet; },
  4372. "in": function (queryObj) { return queryObj.inSet; },
  4373. "nu": function (queryObj) { return queryObj.isNull; },
  4374. "nn": function (queryObj, op) { return op === "OR" ? queryObj.orNot().isNull : queryObj.andNot().isNull; }
  4375. },
  4376. query = jgrid.from.call(this, p.data);
  4377. if (p.ignoreCase) { query = query.ignoreCase(); }
  4378. function tojLinq(group) {
  4379. var s = 0, index, gor, ror, opr, rule, r, cmi1;
  4380. if (group.groups != null) {
  4381. gor = group.groups.length && group.groupOp.toString().toUpperCase() === "OR";
  4382. if (gor) {
  4383. query.orBegin();
  4384. }
  4385. for (index = 0; index < group.groups.length; index++) {
  4386. if (s > 0 && gor) {
  4387. query.or();
  4388. }
  4389. try {
  4390. tojLinq(group.groups[index]);
  4391. } catch (e) { fatalErrorFunction(e); }
  4392. s++;
  4393. }
  4394. if (gor) {
  4395. query.orEnd();
  4396. }
  4397. }
  4398. if (group.rules != null) {
  4399. try {
  4400. ror = group.rules.length && group.groupOp.toString().toUpperCase() === "OR";
  4401. if (ror) {
  4402. query.orBegin();
  4403. }
  4404. for (index = 0; index < group.rules.length; index++) {
  4405. rule = group.rules[index];
  4406. opr = group.groupOp.toString().toUpperCase();
  4407. if (compareFnMap[rule.op] && rule.field) {
  4408. if (s > 0 && opr && opr === "OR") {
  4409. query = query.or();
  4410. }
  4411. cmi1 = cmtypes[rule.field];
  4412. if (cmi1 != null) {
  4413. r = cmi1.reader;
  4414. query = compareFnMap[rule.op](query, opr)(
  4415. isFunction(r) ?
  4416. "jQuery.jgrid.getAccessor(this,jQuery(\"" + p.idSel + "\")[0].p.colModel[" + cmi1.iCol + "].jsonmap)" :
  4417. "jQuery.jgrid.getAccessor(this,'" + r + "')",
  4418. rule.data,
  4419. cmtypes[rule.field]
  4420. );
  4421. }
  4422. } else if (p.customSortOperations != null && p.customSortOperations[rule.op] != null && isFunction(p.customSortOperations[rule.op].filter)) {
  4423. query = query.custom(rule.op, rule.field, rule.data);
  4424. }
  4425. s++;
  4426. }
  4427. if (ror) {
  4428. query.orEnd();
  4429. }
  4430. } catch (g) { fatalErrorFunction(g); }
  4431. }
  4432. }
  4433. if (p.search === true) {
  4434. var srules = p.postData[(p.searching || {}).sFilter || p.prmNames.filters];
  4435. if (srules) {
  4436. if (typeof srules === "string") { srules = $.parseJSON(srules); }
  4437. tojLinq(srules);
  4438. } else {
  4439. try {
  4440. var cmtypes1 = cmtypes[p.postData.searchField];
  4441. query = compareFnMap[p.postData.searchOper](query)(
  4442. //p.postData.searchField,
  4443. isFunction(cmtypes1.reader) ?
  4444. "jQuery.jgrid.getAccessor(this,jQuery(\"" + p.idSel + "\")[0].p.colModel[" + cmtypes1.iCol + "].jsonmap)" :
  4445. "jQuery.jgrid.getAccessor(this,'" + cmtypes1.reader + "')",
  4446. p.postData.searchString,
  4447. cmtypes[p.postData.searchField]
  4448. );
  4449. } catch (ignore) { }
  4450. }
  4451. }
  4452. if (p.grouping) {
  4453. for (gin = 0; gin < lengrp && gin < grindexes.length && gin < grtypes.length; gin++) {
  4454. query.orderBy(grindexes[gin], grpview.groupOrder[gin], grtypes[gin].stype, grtypes[gin].srcfmt);
  4455. }
  4456. }
  4457. if (p.multiSort) {
  4458. each(st, function () {
  4459. query.orderBy(this, sto[this], cmtypes[this].stype, cmtypes[this].srcfmt, cmtypes[this].sfunc);
  4460. });
  4461. } else if (st && p.sortorder && fndsort) {
  4462. query.orderBy(p.sortname, p.sortorder.toUpperCase() === "DESC" ? "d" : "a", cmtypes[st].stype, cmtypes[st].srcfmt, cmtypes[st].sfunc);
  4463. }
  4464. p.lastSelectedData = query.select();
  4465. var recordsperpage = parseInt(p.rowNum, 10),
  4466. total = p.lastSelectedData.length,
  4467. page = parseInt(p.page, 10),
  4468. totalpages = Math.ceil(total / recordsperpage),
  4469. retresult = {};
  4470. if (p.grouping && p.groupingView._locgr) {
  4471. p.groupingView.groups = [];
  4472. var j, key, udc;
  4473. if (p.footerrow && p.userDataOnFooter) {
  4474. for (key in p.userData) {
  4475. if (p.userData.hasOwnProperty(key)) {
  4476. p.userData[key] = 0;
  4477. }
  4478. }
  4479. udc = true;
  4480. }
  4481. for (j = 0; j < total; j++) {
  4482. if (udc) {
  4483. for (key in p.userData) {
  4484. if (p.userData.hasOwnProperty(key)) {
  4485. p.userData[key] += parseFloat(p.lastSelectedData[j][key] || 0);
  4486. }
  4487. }
  4488. }
  4489. $j.groupingPrepare.call($self, p.lastSelectedData[j], j, recordsperpage);
  4490. }
  4491. }
  4492. query = null;
  4493. cmtypes = null;
  4494. var localReader = p.localReader;
  4495. retresult[localReader.total] = totalpages;
  4496. retresult[localReader.page] = page;
  4497. retresult[localReader.records] = total;
  4498. retresult[localReader.root] = p.lastSelectedData.slice((page - 1) * recordsperpage, page * recordsperpage);
  4499. retresult[localReader.userdata] = p.userData;
  4500. return retresult;
  4501. },
  4502. setWidthOfPagerTdWithPager = function ($pgTable) {
  4503. var self = this, width = $pgTable.outerWidth(), fontSize;
  4504. if (width <= 0) { // not visible
  4505. fontSize = $(self).closest(".ui-jqgrid>.ui-jqgrid-view").css("font-size") || "11px";
  4506. $(document.body).append("<div id='testpg' class='" + getGuiStyles("gBox", "ui-jqgrid") + "' style='font-size:" +
  4507. fontSize +
  4508. ";visibility:hidden;margin:0;padding:0;' ></div>");
  4509. $($pgTable).clone().appendTo("#testpg");
  4510. width = $("#testpg>.ui-pg-table").width();
  4511. $("#testpg").remove();
  4512. }
  4513. if (width > 0) {
  4514. $pgTable.parent().width(width);
  4515. }
  4516. return width;
  4517. },
  4518. updatepager = function (rn, dnd) {
  4519. var self = this, $self = $(self), gridSelf = self.grid, cp, last, base1, from, to, tot, fmt, pgboxes = p.pager || "", sppg,
  4520. tspg = p.pager ? "_" + p.pager.substr(1) : "", bDiv = gridSelf.bDiv, numberFormat = $.fmatter ? $.fmatter.NumberFormat : null,
  4521. tspgTop = p.toppager ? "_" + p.toppager.substr(1) : "",
  4522. hoverClasses = getGuiStyles("states.hover"), disabledClasses = getGuiStyles("states.disabled");
  4523. base1 = parseInt(p.page, 10) - 1;
  4524. if (base1 < 0) { base1 = 0; }
  4525. base1 = base1 * parseInt(p.rowNum, 10);
  4526. to = base1 + p.reccount;
  4527. if (p.scroll) {
  4528. var rows = $(getGridComponent(COMPONENT_NAMES.BODY_TABLE, bDiv)[0].rows).slice(1);//$("tbody:first > tr:gt(0)", bDiv);
  4529. base1 = to - rows.length;
  4530. p.reccount = rows.length;
  4531. var rh = rows.outerHeight() || gridSelf.prevRowHeight;
  4532. if (rh) {
  4533. var top = base1 * rh;
  4534. var height = jgrid.fixMaxHeightOfDiv.call(self, parseInt(p.records, 10) * rh);
  4535. $(bDiv).children("div").first().css({ height: height + "px" })
  4536. .children("div").first().css({ height: top + "px", display: top + "px" ? "" : "none" });
  4537. if (bDiv.scrollTop === 0 && p.page > 1) {
  4538. bDiv.scrollTop = p.rowNum * (p.page - 1) * rh;
  4539. }
  4540. }
  4541. bDiv.scrollLeft = gridSelf.hDiv.scrollLeft;
  4542. }
  4543. pgboxes += p.toppager ? (pgboxes ? "," : "") + p.toppager : "";
  4544. if (pgboxes) {
  4545. fmt = getRes("formatter.integer") || {};
  4546. cp = intNum(p.page);
  4547. last = intNum(p.lastpage);
  4548. $(".selbox", pgboxes).prop("disabled", false);
  4549. if (p.pginput === true) {
  4550. var $pagerInputs = $(".ui-pg-input", pgboxes),
  4551. numberOfDigitsInPageNumber = String(p.page).length;
  4552. $pagerInputs.val(p.page);
  4553. // verify the value of size attribute of "input.ui-pg-input"
  4554. // and increase it if it's required.
  4555. $pagerInputs.each(function () {
  4556. var size = parseInt($(this).attr("size"), 10);
  4557. if (size > 0 && size < numberOfDigitsInPageNumber) {
  4558. $(this).attr("size", numberOfDigitsInPageNumber);
  4559. }
  4560. });
  4561. sppg = p.toppager ? "#sp_1" + tspg + ",#sp_1" + tspgTop : "#sp_1" + tspg;
  4562. $(sppg).html($.fmatter ? numberFormat(p.lastpage, fmt) : p.lastpage)
  4563. .closest(".ui-pg-table").each(function () {
  4564. setWidthOfPagerTdWithPager.call(self, $(this));
  4565. });
  4566. }
  4567. if (p.viewrecords) {
  4568. if (p.reccount === 0) {
  4569. $(".ui-paging-info", pgboxes).html(getDef("emptyrecords"));
  4570. } else {
  4571. from = base1 + 1;
  4572. tot = p.records;
  4573. if ($.fmatter) {
  4574. from = numberFormat(from, fmt);
  4575. to = numberFormat(to, fmt);
  4576. tot = numberFormat(tot, fmt);
  4577. }
  4578. $(".ui-paging-info", pgboxes).html(jgrid.format(getDef("recordtext"), from, to, tot));
  4579. }
  4580. }
  4581. if (p.pgbuttons === true) {
  4582. if (last <= 0) { cp = 0;}
  4583. if (cp <= 0) { cp = last = 0; }
  4584. if (cp === 1 || cp === 0) {
  4585. $("#first" + tspg + ", #prev" + tspg).addClass(disabledClasses).removeClass(hoverClasses);
  4586. if (p.toppager) { $("#first_t" + tspgTop + ", #prev_t" + tspgTop).addClass(disabledClasses).removeClass(hoverClasses); }
  4587. } else {
  4588. $("#first" + tspg + ", #prev" + tspg).removeClass(disabledClasses);
  4589. if (p.toppager) { $("#first_t" + tspgTop + ", #prev_t" + tspgTop).removeClass(disabledClasses); }
  4590. }
  4591. if (cp === last || cp === 0) {
  4592. $("#next" + tspg + ", #last" + tspg).addClass(disabledClasses).removeClass(hoverClasses);
  4593. if (p.toppager) { $("#next_t" + tspgTop + ", #last_t" + tspgTop).addClass(disabledClasses).removeClass(hoverClasses); }
  4594. } else {
  4595. $("#next" + tspg + ", #last" + tspg).removeClass(disabledClasses);
  4596. if (p.toppager) { $("#next_t" + tspgTop + ", #last_t" + tspgTop).removeClass(disabledClasses); }
  4597. }
  4598. }
  4599. }
  4600. if (rn === true && p.rownumbers === true) {
  4601. $(">td.jqgrid-rownum", self.rows).each(function (i) {
  4602. $(this).html(base1 + 1 + i);
  4603. });
  4604. }
  4605. if (dnd && p.jqgdnd) { $self.jqGrid("gridDnD", "updateDnD"); }
  4606. feedback.call(self, "gridComplete");
  4607. $self.triggerHandler("jqGridAfterGridComplete");
  4608. },
  4609. beginReq = function () {
  4610. var self = this;
  4611. self.grid.hDiv.loading = true;
  4612. if (p.hiddengrid) { return; }
  4613. $j.progressBar.call($(self), { method: "show", loadtype: p.loadui, htmlcontent: getDef("loadtext") });
  4614. },
  4615. endReq = function () {
  4616. var self = this;
  4617. self.grid.hDiv.loading = false;
  4618. $j.progressBar.call($(self), { method: "hide", loadtype: p.loadui });
  4619. },
  4620. populate = function (npage) {
  4621. var self = this, $self = $(self), gridSelf = self.grid;
  4622. if (!gridSelf.hDiv.loading) {
  4623. var pvis = p.scroll && npage === false, prm = {}, dt, dstr, pN = p.prmNames;
  4624. if (p.page <= 0) { p.page = Math.min(1, p.lastpage); }
  4625. if (pN.search !== null) { prm[pN.search] = p.search; }
  4626. if (pN.nd !== null) { prm[pN.nd] = new Date().getTime(); }
  4627. if (isNaN(parseInt(p.rowNum, 10)) || parseInt(p.rowNum, 10) <= 0) { p.rowNum = p.maxRowNum; }
  4628. if (pN.rows !== null) { prm[pN.rows] = p.rowNum; }
  4629. if (pN.page !== null) { prm[pN.page] = p.page; }
  4630. if (pN.sort !== null) { prm[pN.sort] = p.sortname; }
  4631. if (pN.order !== null) { prm[pN.order] = p.sortorder; }
  4632. if (p.rowTotal !== null && pN.totalrows !== null) { prm[pN.totalrows] = p.rowTotal; }
  4633. var lcf = isFunction(p.loadComplete), lc = lcf ? p.loadComplete : null;
  4634. var adjust = 0;
  4635. npage = npage || 1;
  4636. if (npage > 1) {
  4637. if (pN.npage !== null) {
  4638. prm[pN.npage] = npage;
  4639. adjust = npage - 1;
  4640. npage = 1;
  4641. } else {
  4642. lc = function (data) {
  4643. p.page++;
  4644. gridSelf.hDiv.loading = false;
  4645. if (lcf) {
  4646. p.loadComplete.call(self, data);
  4647. }
  4648. populate.call(self, npage - 1);
  4649. };
  4650. }
  4651. } else if (pN.npage !== null) {
  4652. delete p.postData[pN.npage];
  4653. }
  4654. if (p.grouping && $j.groupingSetup) {
  4655. $j.groupingSetup.call($self);
  4656. var grp = p.groupingView, gi, gs = "", index, iColumn, cmValue;
  4657. for (gi = 0; gi < grp.groupField.length; gi++) {
  4658. index = grp.groupField[gi];
  4659. for (iColumn = 0; iColumn < p.colModel.length; iColumn++) {
  4660. cmValue = p.colModel[iColumn];
  4661. if (cmValue.name === index && cmValue.index) {
  4662. index = cmValue.index;
  4663. }
  4664. }
  4665. gs += index + " " + grp.groupOrder[gi] + ", ";
  4666. }
  4667. prm[pN.sort] = gs + prm[pN.sort];
  4668. }
  4669. extend(p.postData, prm);
  4670. var rcnt = !p.scroll ? 1 : self.rows.length - 1,
  4671. fixDisplayingHorizontalScrollbar = function () {
  4672. fixScrollOffsetAndhBoxPadding.call(self);
  4673. // if no items are displayed in the btable, but the column header is too wide
  4674. // the horizontal scrollbar of bDiv will be disabled.
  4675. if (!p.autowidth && (p.widthOrg === undefined || p.widthOrg === "auto" || p.widthOrg === "100%")) {
  4676. $j.setGridWidth.call($self, p.tblwidth + p.scrollOffset, false);
  4677. }
  4678. },
  4679. resort = function () {
  4680. var iRes;
  4681. if (p.autoresizeOnLoad) {
  4682. $j.autoResizeAllColumns.call($self);
  4683. clearArray(p.columnsToReResizing);
  4684. if (p.autowidth) {
  4685. $j.setGridWidth.call($self,
  4686. $self.closest(".ui-jqgrid").parent().width(),
  4687. true);
  4688. }
  4689. } else {
  4690. for (iRes = 0; iRes < p.columnsToReResizing.length; iRes++) {
  4691. $j.autoResizeColumn.call($self, p.columnsToReResizing[iRes]);
  4692. }
  4693. clearArray(p.columnsToReResizing);
  4694. }
  4695. },
  4696. finalReportSteps = function () {
  4697. feedback.call(self, "loadComplete", dstr);
  4698. resort();
  4699. $self.triggerHandler("jqGridAfterLoadComplete", [dstr]);
  4700. endReq.call(self);
  4701. p.datatype = "local";
  4702. p.datastr = null;
  4703. fixDisplayingHorizontalScrollbar();
  4704. },
  4705. finalReportVirtual = function (data) {
  4706. $self.triggerHandler("jqGridLoadComplete", [data]);
  4707. if (lc) { lc.call(self, data); }
  4708. resort();
  4709. $self.triggerHandler("jqGridAfterLoadComplete", [data]);
  4710. if (pvis) { gridSelf.populateVisible.call(self); }
  4711. if (npage === 1) { endReq.call(self); }
  4712. fixDisplayingHorizontalScrollbar();
  4713. },
  4714. readLocal = function () {
  4715. var req = addLocalData.call(self);
  4716. readInput.call(self, req, rcnt, npage > 1, adjust);
  4717. finalReportVirtual(req);
  4718. };
  4719. if (!feedback.call(self, "beforeRequest")) { return; }
  4720. if (isFunction(p.datatype)) { p.datatype.call(self, p.postData, "load_" + p.id, rcnt, npage, adjust); return; }
  4721. dt = p.datatype.toLowerCase();
  4722. $(grid.eDiv).hide();
  4723. switch (dt) {
  4724. case "json":
  4725. case "jsonp":
  4726. case "xml":
  4727. case "script":
  4728. $.ajax(extend({
  4729. url: p.url,
  4730. type: p.mtype,
  4731. dataType: dt,
  4732. //data: $.isFunction(p.serializeGridData)? p.serializeGridData.call(self,p.postData) : p.postData,
  4733. data: jgrid.serializeFeedback.call(ts, p.serializeGridData, "jqGridSerializeGridData", p.postData),
  4734. success: function (data, textStatus, jqXHR) {
  4735. p.jqXhr = null;
  4736. $(grid.eDiv).hide();
  4737. if (isFunction(p.beforeProcessing)) {
  4738. if (p.beforeProcessing.call(self, data, textStatus, jqXHR) === false) {
  4739. endReq.call(self);
  4740. return;
  4741. }
  4742. }
  4743. readInput.call(self, data, rcnt, npage > 1, adjust);
  4744. finalReportVirtual(data);
  4745. if (p.loadonce || p.treeGrid) {
  4746. p.dataTypeOrg = p.datatype;
  4747. p.datatype = "local";
  4748. if (p.forceClientSorting) { readLocal(); }
  4749. }
  4750. },
  4751. error: function (jqXHR, textStatus, errorThrown) {
  4752. p.jqXhr = null;
  4753. if (isFunction(p.loadError)) { p.loadError.call(self, jqXHR, textStatus, errorThrown); }
  4754. if (npage === 1) { endReq.call(self); }
  4755. },
  4756. beforeSend: function (jqXHR, settings) {
  4757. var gotoreq = true;
  4758. if (isFunction(p.loadBeforeSend)) {
  4759. gotoreq = p.loadBeforeSend.call(self, jqXHR, settings);
  4760. }
  4761. if (gotoreq === undefined) { gotoreq = true; }
  4762. if (gotoreq === false) {
  4763. return false;
  4764. }
  4765. p.jqXhr = jqXHR;
  4766. beginReq.call(self);
  4767. }
  4768. }, jgrid.ajaxOptions, p.ajaxGridOptions));
  4769. break;
  4770. case "xmlstring":
  4771. beginReq.call(self);
  4772. dstr = typeof p.datastr === "string" ? $.parseXML(p.datastr) : p.datastr;
  4773. readInput.call(self, dstr);
  4774. finalReportSteps();
  4775. if (p.forceClientSorting) { readLocal(); }
  4776. break;
  4777. case "jsonstring":
  4778. beginReq.call(self);
  4779. dstr = p.datastr && typeof p.datastr === "string" ? $.parseJSON(p.datastr) : p.datastr;
  4780. readInput.call(self, dstr);
  4781. finalReportSteps();
  4782. if (p.forceClientSorting) { readLocal(); }
  4783. break;
  4784. case "local":
  4785. case "clientside":
  4786. beginReq.call(self);
  4787. p.datatype = "local";
  4788. readLocal();
  4789. break;
  4790. }
  4791. }
  4792. },
  4793. setHeadCheckBox = function (checked) {
  4794. var self = this, gridSelf = self.grid;
  4795. $(p.cb, gridSelf.hDiv).prop("checked", checked);
  4796. if (p.frozenColumns) {
  4797. $(p.cb, gridSelf.fhDiv).prop("checked", checked);
  4798. }
  4799. },
  4800. cancelOrSaveEditing = function (mode) {
  4801. // The current code don't take in the consideration errors during
  4802. // remote saving/canceling. The standard behavior in case of
  4803. // remote saving/canceling is wating till the server response and
  4804. // holding inline/cell editing if saving/canceling failed by some
  4805. // server reason. The current code of cancelOrSaveEditing
  4806. // don't wait for the server response
  4807. var iEditing, savedRowInfo;
  4808. for (iEditing = 0; iEditing < p.savedRow.length; iEditing++) {
  4809. savedRowInfo = p.savedRow[iEditing];
  4810. if (mode === "save") {
  4811. if (savedRowInfo.hasOwnProperty("ic")) {
  4812. $self0.jqGrid("saveCell", savedRowInfo.id, savedRowInfo.ic);
  4813. } else {
  4814. $self0.jqGrid("saveRow", savedRowInfo.id);
  4815. }
  4816. } else {
  4817. // mode === "cancel"
  4818. if (savedRowInfo.hasOwnProperty("ic")) {
  4819. $self0.jqGrid("restoreCell", savedRowInfo.id, savedRowInfo.ic);
  4820. } else {
  4821. $self0.jqGrid("restoreRow", savedRowInfo.id);
  4822. }
  4823. }
  4824. }
  4825. //clearArray(p.savedRow); // p.savedRow = [];
  4826. //p.editingInfo = {};
  4827. },
  4828. setPager = function (pgid, tp) {
  4829. var hoverClasses = getGuiStyles("states.hover"), disabledClasses = getGuiStyles("states.disabled"),
  4830. sep = "<td class='ui-pg-button " + disabledClasses + "'><span class='ui-separator'></span></td>",
  4831. pginp = "",
  4832. blockAlign = p.pagerpos === "left" ? "margin-right:auto;" : (p.pagerpos === "right" ? "margin-left:auto;" : "margin-left:auto;margin-right:auto;"),
  4833. pgl = "<table " + "style='table-layout:auto;white-space: pre;" + blockAlign + "' class='ui-pg-table'><tbody><tr>",
  4834. str = "", pgcnt, lft, cent, rgt, twd, i,
  4835. clearVals = function (onpaging, newPage, newRowNum) {
  4836. if (p.savedRow.length > 0 && p.pagingDuringEditing === "prevent") {
  4837. return false;
  4838. }
  4839. if (!feedback.call(ts, "onPaging", onpaging, {
  4840. newPage: newPage,
  4841. currentPage: intNum(p.page, 1),
  4842. lastPage: intNum(p.lastpage, 1),
  4843. currentRowNum: intNum(p.rowNum, 10),
  4844. newRowNum: newRowNum
  4845. })) {
  4846. return false;
  4847. }
  4848. p.selrow = null;
  4849. if (p.multiselect) {
  4850. if (!p.multiPageSelection) {
  4851. clearArray(p.selarrrow); // p.selarrrow = [];
  4852. }
  4853. setHeadCheckBox.call(ts, false);
  4854. }
  4855. cancelOrSaveEditing(p.pagingDuringEditing);
  4856. return true;
  4857. };
  4858. tp += "_" + pgid;
  4859. pgcnt = "pg_" + pgid;
  4860. lft = pgid + "_left";
  4861. cent = pgid + "_center";
  4862. rgt = pgid + "_right";
  4863. $("#" + jqID(pgid))
  4864. .append("<div id='" + pgcnt + "' class='ui-pager-control' role='group'><table class='ui-pg-table' style='width:100%;table-layout:fixed;height:100%;'><tbody><tr>" +
  4865. "<td id='" + lft + "' class='ui-jqgrid-pg-left'" + (p.pagerLeftWidth !== undefined ? " style='width:" + p.pagerLeftWidth + "px;'" : "") + "></td>" +
  4866. "<td id='" + cent + "' class='ui-jqgrid-pg-center'" + (p.pagerCenterWidth !== undefined ? " style='width:" + p.pagerCenterWidth + "px;'" : "") + "></td>" +
  4867. "<td id='" + rgt + "' class='ui-jqgrid-pg-right'" + (p.pagerRightWidth !== undefined ? " style='width:" + p.pagerRightWidth + "px;'" : "") + "></td></tr></tbody></table></div>")
  4868. .attr("dir", "ltr"); //explicit setting
  4869. pgcnt = "#" + jqID(pgcnt); // modify to id selector
  4870. if (p.rowList.length > 0) {
  4871. str = "<td dir='" + dir + "'>";
  4872. var pgrecs = getDef("pgrecs");
  4873. str += "<select class='" + getGuiStyles("pager.pagerSelect", "ui-pg-selbox") + "' " + (pgrecs ? "title='" + pgrecs + "'" : "") + ">";
  4874. var strnm;
  4875. for (i = 0; i < p.rowList.length; i++) {
  4876. strnm = p.rowList[i].toString().split(":");
  4877. if (strnm.length === 1) {
  4878. strnm[1] = strnm[0];
  4879. }
  4880. str += "<option value='" + strnm[0] + "'" + ((intNum(p.rowNum, 0) === intNum(strnm[0], 0)) ? " selected='selected'" : "") + ">" + strnm[1] + "</option>";
  4881. }
  4882. str += "</select></td>";
  4883. }
  4884. if (dir === "rtl") { pgl += str; }
  4885. if (p.pginput === true) { pginp = "<td dir='" + dir + "'>" + jgrid.format(getDef("pgtext") || "", "<input aria-label='Page No.' class='" + getGuiStyles("pager.pagerInput", "ui-pg-input") + "' type='text' size='2' maxlength='7' value='0'/>", "<span id='sp_1_" + pgid + "'>0</span>") + "</td>"; }
  4886. pgid = "#" + jqID(pgid); // modify to id selector
  4887. if (p.pgbuttons === true) {
  4888. var po = ["first", "prev", "next", "last"],
  4889. poIcons = po.slice(),
  4890. buttonClasses = getGuiStyles("pager.pagerButton", "ui-pg-button"),
  4891. buildPagerButton = function (buttonName, iconName) {
  4892. var titleText = getDef("pg" + buttonName);
  4893. return "<td role='button' tabindex='0' id='" + buttonName + tp + "' class='" + buttonClasses + "' " +
  4894. (titleText ? "title='" + titleText + "'" : "") + "><span class='" + getIcon("pager." + iconName) + "'></span></td>";
  4895. };
  4896. if (dir === "rtl") { po.reverse(); }
  4897. for (i = 0; i < po.length; i++) {
  4898. pgl += buildPagerButton(po[i], poIcons[i]);
  4899. if (i === 1) {
  4900. pgl += pginp !== "" ? sep + pginp + sep : "";
  4901. }
  4902. }
  4903. } else if (pginp !== "") { pgl += pginp; }
  4904. if (dir === "ltr") { pgl += str; }
  4905. pgl += "</tr></tbody></table>";
  4906. if (p.viewrecords === true) { $("td" + pgid + "_" + p.recordpos, pgcnt).append("<span dir='" + dir + "' style='text-align:" + p.recordpos + "' class='ui-paging-info'></span>"); }
  4907. var $pagerIn = $("td" + pgid + "_" + p.pagerpos, pgcnt);
  4908. $pagerIn.append(pgl);
  4909. twd = setWidthOfPagerTdWithPager.call(this, $pagerIn.children(".ui-pg-table"));
  4910. p._nvtd = [];
  4911. p._nvtd[0] = twd ? Math.floor((p.width - twd) / 2) : Math.floor(p.width / 3);
  4912. p._nvtd[1] = 0;
  4913. pgl = null;
  4914. $(".ui-pg-selbox", pgcnt).on("change", function () {
  4915. var newRowNum = intNum(this.value, 10),
  4916. newPage = Math.round(p.rowNum * (p.page - 1) / newRowNum - 0.5) + 1;
  4917. if (!clearVals("records", newPage, newRowNum)) { return false; }
  4918. p.page = newPage;
  4919. p.rowNum = newRowNum;
  4920. if (p.pager) { $(".ui-pg-selbox", p.pager).val(newRowNum); }
  4921. if (p.toppager) { $(".ui-pg-selbox", p.toppager).val(newRowNum); }
  4922. populate.call(ts);
  4923. return false;
  4924. });
  4925. if (p.pgbuttons === true) {
  4926. $(".ui-pg-button", pgcnt).hover(function () {
  4927. if (hasOneFromClasses(this, disabledClasses)) {
  4928. this.style.cursor = "default";
  4929. } else {
  4930. $(this).addClass(hoverClasses);
  4931. this.style.cursor = "pointer";
  4932. }
  4933. }, function () {
  4934. if (!hasOneFromClasses(this, disabledClasses)) {
  4935. $(this).removeClass(hoverClasses);
  4936. this.style.cursor = "default";
  4937. }
  4938. });
  4939. $("#first" + jqID(tp) + ", #prev" + jqID(tp) + ", #next" + jqID(tp) + ", #last" + jqID(tp)).click(function () {
  4940. if (hasOneFromClasses(this, disabledClasses)) {
  4941. return false;
  4942. }
  4943. var cp = intNum(p.page, 1), newPage = cp, onpaging = this.id,
  4944. last = intNum(p.lastpage, 1), selclick = false,
  4945. fp = true, pp = true, np = true, lp = true;
  4946. if (last === 0 || last === 1) {
  4947. if (cp <= 1) {
  4948. fp = false;
  4949. pp = false;
  4950. }
  4951. np = false;
  4952. lp = false;
  4953. } else if (last > 1 && cp >= 1) {
  4954. if (cp === 1) {
  4955. fp = false;
  4956. pp = false;
  4957. } else if (cp === last) {
  4958. np = false;
  4959. lp = false;
  4960. }
  4961. } else if (last > 1 && cp === 0) {
  4962. np = false;
  4963. lp = false;
  4964. cp = last - 1;
  4965. }
  4966. if (this.id === "first" + tp && fp) {
  4967. onpaging = "first";
  4968. newPage = 1;
  4969. selclick = true;
  4970. }
  4971. if (this.id === "prev" + tp && pp) {
  4972. onpaging = "prev";
  4973. newPage = (cp - 1);
  4974. selclick = true;
  4975. }
  4976. if (this.id === "next" + tp && np) {
  4977. onpaging = "next";
  4978. newPage = (cp + 1);
  4979. selclick = true;
  4980. }
  4981. if (this.id === "last" + tp && lp) {
  4982. onpaging = "last";
  4983. newPage = last;
  4984. selclick = true;
  4985. }
  4986. if (!clearVals(onpaging, newPage, intNum(p.rowNum, 10))) { return false; }
  4987. p.page = newPage;
  4988. if (selclick) {
  4989. populate.call(ts);
  4990. }
  4991. return false;
  4992. });
  4993. }
  4994. if (p.pginput === true) {
  4995. $("input.ui-pg-input", pgcnt).on("keypress.jqGrid", function (e) {
  4996. var key = e.charCode || e.keyCode || 0, newPage = intNum($(this).val(), 1);
  4997. if (key === 13) {
  4998. if (!clearVals("user", newPage, intNum(p.rowNum, 10))) { return false; }
  4999. $(this).val(newPage);
  5000. p.page = ($(this).val() > 0) ? $(this).val() : p.page;
  5001. populate.call(ts);
  5002. return false;
  5003. }
  5004. return this;
  5005. });
  5006. }
  5007. $pagerIn.children(".ui-pg-table").on("keydown.jqGrid", function (e) {
  5008. var $focused;
  5009. if (e.which === 13) {
  5010. $focused = $pagerIn.find(":focus");
  5011. if ($focused.length > 0) {
  5012. $focused.trigger("click");
  5013. }
  5014. }
  5015. });
  5016. },
  5017. getSortNames = function (sortNames, sortDirs, cm) {
  5018. // sortNames, sortDirs MUST be initialized to [] and {} before
  5019. // process sortname
  5020. each((p.sortname + " " + p.sortorder).split(","), function () {
  5021. var s = $.trim(this).split(" ");
  5022. if (s.length === 2) {
  5023. sortNames.push(s[0]);
  5024. }
  5025. });
  5026. if (cm != null) {
  5027. var i = $.inArray(cm.index || cm.name, sortNames);
  5028. if (cm.lso !== "" && i < 0) {
  5029. // new column is clicked
  5030. sortNames.push(cm.index || cm.name);
  5031. } else if (cm.lso === "" && i >= 0) {
  5032. // remove column
  5033. sortNames.splice(i, 1);
  5034. }
  5035. }
  5036. each(p.colModel, function () {
  5037. var sortName = this.index || this.name, splas;
  5038. if (this.lso) {
  5039. splas = this.lso.split("-");
  5040. if ($.inArray(sortName, sortNames) < 0) {
  5041. sortNames.push(sortName);
  5042. }
  5043. sortDirs[sortName] = splas[splas.length - 1];
  5044. }
  5045. });
  5046. },
  5047. multiSort = function (iCol1, obj) {
  5048. var sort1 = "", cm = p.colModel[iCol1], so,
  5049. disabledClasses = getGuiStyles("states.disabled"),
  5050. $selTh = p.frozenColumns ? $(ts.grid.headers[iCol1].el).add($(obj)) : $(ts.grid.headers[iCol1].el),
  5051. $iconsSpan = $selTh.find("span.s-ico"),
  5052. $iconAsc = $iconsSpan.children("span.ui-icon-asc"),
  5053. $iconDesc = $iconsSpan.children("span.ui-icon-desc"),
  5054. $iconsActive = $iconAsc, $iconsInictive = $iconDesc, sortNames = [], sortDirs = {};
  5055. $selTh.find("span.ui-grid-ico-sort").addClass(disabledClasses); // for both icons
  5056. $selTh.attr("aria-selected", "false");
  5057. if (cm.lso) {
  5058. $iconsSpan.show();
  5059. so = cm.lso.split("-");
  5060. so = so[so.length - 1];
  5061. if (so === "desc") {
  5062. $iconsActive = $iconDesc;
  5063. $iconsInictive = $iconAsc;
  5064. }
  5065. $iconsActive.removeClass(disabledClasses).css("display", ""); // show;
  5066. if (p.showOneSortIcon) {
  5067. $iconsInictive.hide();
  5068. }
  5069. $selTh.attr("aria-selected", "true");
  5070. } else if (!p.viewsortcols[0]) {
  5071. $iconsSpan.hide();
  5072. }
  5073. getSortNames(sortNames, sortDirs, cm);
  5074. if (typeof p.sortname === "string" && p.sortname !== "" && p.sortname.split(",").length < sortNames.length) {
  5075. var removeSorting = function (sortNameToRemove) {
  5076. each(p.colModel, function () {
  5077. var indexInSortNames, thDivIdSelector = "#jqgh_" + jgrid.jqID(p.id + "_" + this.name),
  5078. $thDiv = $(thDivIdSelector);
  5079. if (this.lso && (this.index || this.name) === sortNameToRemove) {
  5080. if (typeof sortNames.indexOf === "function") {
  5081. indexInSortNames = sortNames.indexOf(sortNameToRemove);
  5082. } else {
  5083. // old web browser
  5084. for (indexInSortNames = 0; indexInSortNames < sortNames.length; indexInSortNames++) {
  5085. if (sortNames[indexInSortNames] === sortNameToRemove) {
  5086. break;
  5087. }
  5088. }
  5089. if (indexInSortNames === sortNames.length) {
  5090. indexInSortNames = -1;
  5091. }
  5092. }
  5093. if (indexInSortNames >= 0) {
  5094. sortNames.splice(indexInSortNames, 1);
  5095. this.lso = "";
  5096. }
  5097. }
  5098. if (p.frozenColumns) {
  5099. $thDiv = $thDiv.add($(grid.fhDiv).find(thDivIdSelector));
  5100. }
  5101. $thDiv.children(".s-ico")[this.lso ? "show" : "hide"]();
  5102. });
  5103. };
  5104. if (p.multiSortOrder === "lastClickedFirstSorted" && sortNames.length > 1) {
  5105. sortNames.unshift(sortNames[sortNames.length - 1]);
  5106. sortNames.pop();
  5107. while (sortNames.length > p.maxSortColumns) {
  5108. removeSorting(sortNames[sortNames.length - 1]); //sortNames.pop() and a little more
  5109. }
  5110. } else if (isFunction(p.multiSortOrder)) {
  5111. sortNames = p.multiSortOrder.call(ts, {
  5112. sortNames: sortNames,
  5113. cm: cm,
  5114. sortDirs: sortDirs,
  5115. removeSorting: removeSorting
  5116. }) || sortNames;
  5117. }
  5118. }
  5119. each(sortNames, function () {
  5120. if (sort1.length > 0) { sort1 += ", "; }
  5121. sort1 += this + " " + sortDirs[this];
  5122. p.sortorder = sortDirs[this];
  5123. });
  5124. p.sortname = sort1.substring(0, sort1.length - p.sortorder.length - 1);
  5125. if (p.showSortOrder) {
  5126. // reset multisort indexes
  5127. each(p.colModel, function () {
  5128. if (this.sortable) {
  5129. var sortIndex = inArray(this.name, sortNames),
  5130. thDivIdSelector = "#jqgh_" + jgrid.jqID(p.id + "_" + this.name),
  5131. $thDiv = $(thDivIdSelector);
  5132. if (p.frozenColumns) {
  5133. $thDiv = $thDiv.add($(grid.fhDiv).find(thDivIdSelector));
  5134. }
  5135. $thDiv
  5136. .children(".ui-jqgrid-sort-order")
  5137. .html(sortIndex < 0 ?
  5138. "&nbsp;" :
  5139. isFunction(p.formatSortOrder) ?
  5140. p.formatSortOrder.call(ts, { cm: this, sortIndex: sortIndex }) :
  5141. sortIndex + 1);
  5142. }
  5143. });
  5144. }
  5145. },
  5146. sortData = function (index, idxcol, reload, sor, obj, e) {
  5147. var self = this, mygrid = self.grid, cm = p.colModel[idxcol], disabledClasses = getGuiStyles("states.disabled");
  5148. if (cm == null || !cm.sortable) { return; }
  5149. if (p.savedRow.length > 0 && p.sortingDuringEditing === "prevent") { return; }
  5150. if (p.lastsort === idxcol && p.sortname !== "") {
  5151. if (p.sortorder === "asc") {
  5152. p.sortorder = "desc";
  5153. } else if (p.sortorder === "desc") {
  5154. p.sortorder = "asc";
  5155. } else {
  5156. p.sortorder = cm.firstsortorder || "asc";
  5157. }
  5158. } else {
  5159. p.sortorder = cm.firstsortorder || "asc";
  5160. }
  5161. // first set new value of lso:
  5162. // "asc" -> "asc-desc", new sorting to "desc"
  5163. // "desc" -> "desc-asc", new sorting to "asc"
  5164. // "asc-desc" or "desc-asc" -> "", no new sorting ""
  5165. // "" -> cm.firstsortorder || "asc"
  5166. if (cm.lso) {
  5167. if (cm.lso === "asc") {
  5168. cm.lso += "-desc";
  5169. } else if (cm.lso === "desc") {
  5170. cm.lso += "-asc";
  5171. } else if ((cm.lso === "asc-desc" || cm.lso === "desc-asc") && (p.threeStateSort || p.multiSort)) {
  5172. cm.lso = "";
  5173. }
  5174. } else {
  5175. cm.lso = cm.firstsortorder || "asc";
  5176. }
  5177. if (!reload && p.resetPageAfterSort) {
  5178. p.page = 1;
  5179. }
  5180. if (p.multiSort) {
  5181. multiSort(idxcol, obj);
  5182. } else {
  5183. if (sor) {
  5184. if (p.lastsort === idxcol && p.sortorder === sor && !reload) { return; }
  5185. p.sortorder = sor;
  5186. }
  5187. var headers = mygrid.headers, fhDiv = mygrid.fhDiv,
  5188. $previousSelectedTh = headers[p.lastsort] ? $(headers[p.lastsort].el) : $(),
  5189. $newSelectedTh = p.frozenColumns ? $(obj) : $(headers[idxcol].el),
  5190. $iconsSpan = $newSelectedTh.find("span.s-ico"),
  5191. $iconsActive = $iconsSpan.children(".ui-icon-" + p.sortorder),
  5192. $iconsInictive = $iconsSpan.children(".ui-icon-" + (p.sortorder === "asc" ? "desc" : "asc"));
  5193. cm = p.colModel[p.lastsort];
  5194. $previousSelectedTh.find(".ui-grid-ico-sort").addClass(disabledClasses);
  5195. $previousSelectedTh.attr("aria-selected", "false");
  5196. if (p.frozenColumns) {
  5197. fhDiv.find(".ui-grid-ico-sort").addClass(disabledClasses);
  5198. fhDiv.find("th").attr("aria-selected", "false");
  5199. }
  5200. if (!p.viewsortcols[0]) {
  5201. if (p.lastsort !== idxcol) {
  5202. if (p.frozenColumns) {
  5203. fhDiv.find("span.s-ico").hide();
  5204. }
  5205. $previousSelectedTh.find("span.s-ico").hide();
  5206. $iconsSpan.show();
  5207. } else if (p.sortname === "") { // if p.lastsort === idxcol but p.sortname === ""
  5208. $iconsSpan.show(); // ???
  5209. }
  5210. }
  5211. if (p.lastsort !== idxcol) {
  5212. if ($previousSelectedTh.data("autoResized") === "true" &&
  5213. ((cm != null && cm.autoResizing != null && cm.autoResizing.compact) ||
  5214. p.autoResizing.compact)) {
  5215. // recalculate the width of the column after removing sort icon
  5216. p.columnsToReResizing.push(p.lastsort);
  5217. }
  5218. }
  5219. cm = p.colModel[idxcol];
  5220. $iconsSpan.css("display", ""); // show
  5221. if (cm.lso !== "") {
  5222. $iconsActive.removeClass(disabledClasses).css("display", ""); // show
  5223. if (p.showOneSortIcon) {
  5224. $iconsInictive.removeClass(disabledClasses).hide();
  5225. }
  5226. $newSelectedTh.attr("aria-selected", "true");
  5227. } else {
  5228. $newSelectedTh.attr("aria-selected", "false");
  5229. if (p.threeStateSort) {
  5230. p.sortorder = "";
  5231. if (!p.viewsortcols[0]) {
  5232. $iconsSpan.hide();
  5233. }
  5234. }
  5235. }
  5236. if (p.lastsort !== idxcol && $newSelectedTh.data("autoResized") === "true") {
  5237. if ((cm != null && cm.autoResizing != null && cm.autoResizing.compact) ||
  5238. p.autoResizing.compact) {
  5239. // recalculate the width of the column after removing sort icon
  5240. p.columnsToReResizing.push(idxcol);
  5241. }
  5242. }
  5243. p.sortname = cm.index || index;
  5244. }
  5245. if (!feedback.call(self, "onSortCol", p.sortname, idxcol, p.sortorder, e || {})) {
  5246. p.lastsort = idxcol;
  5247. return;
  5248. }
  5249. if (p.datatype === "local") {
  5250. if (p.deselectAfterSort && !p.multiPageSelection) { $j.resetSelection.call($(self)); }
  5251. } else if (!p.multiPageSelection) {
  5252. p.selrow = null;
  5253. if (p.multiselect) {
  5254. setHeadCheckBox.call(self, false);
  5255. clearArray(p.selarrrow); //p.selarrrow =[];
  5256. }
  5257. }
  5258. cancelOrSaveEditing(p.sortingDuringEditing);
  5259. if (p.scroll) {
  5260. var sscroll = mygrid.bDiv.scrollLeft;
  5261. grid.emptyRows.call(self, true, false);
  5262. mygrid.hDiv.scrollLeft = sscroll;
  5263. }
  5264. if (p.subGrid && p.datatype === "local") {
  5265. $("td.sgexpanded", "#" + jqID(p.id)).each(function () {
  5266. $(this).trigger("click");
  5267. });
  5268. }
  5269. populate.call(self);
  5270. p.lastsort = idxcol;
  5271. if (p.sortname !== index && idxcol) { p.lastsort = idxcol; }
  5272. },
  5273. setInitialColWidth = function () {
  5274. var initialWidth = 0, borderAndPaddingWidth = jgrid.cell_width ? 0 : intNum(p.cellLayout, 0), numberOfVariableColumns = 0, iLastVariableColumn, scrollbarWidth = intNum(p.scrollOffset, 0), columnWidth, hasScrollbar = false, totalVariableWidth, fixedColumnsWidth = 0, correctur,
  5275. isCellClassHidden = jgrid.isCellClassHidden;
  5276. each(p.colModel, function () {
  5277. if (this.hidden === undefined) { this.hidden = false; }
  5278. if (p.grouping && p.autowidth) {
  5279. var ind = inArray(this.name, p.groupingView.groupField);
  5280. if (ind >= 0 && p.groupingView.groupColumnShow.length > ind) {
  5281. this.hidden = !p.groupingView.groupColumnShow[ind];
  5282. }
  5283. }
  5284. this.widthOrg = columnWidth = intNum(this.width, 0);
  5285. if (this.hidden === false && !isCellClassHidden(this.classes)) {
  5286. initialWidth += columnWidth + borderAndPaddingWidth;
  5287. if (this.fixed) {
  5288. fixedColumnsWidth += columnWidth + borderAndPaddingWidth;
  5289. } else {
  5290. numberOfVariableColumns++;
  5291. }
  5292. }
  5293. });
  5294. if (isNaN(p.width)) {
  5295. p.width = initialWidth + ((p.shrinkToFit === false && !isNaN(p.height)) ? scrollbarWidth : 0);
  5296. }
  5297. grid.width = p.width;
  5298. p.tblwidth = initialWidth;
  5299. if (p.shrinkToFit === false && p.forceFit === true) { p.forceFit = false; }
  5300. if (p.shrinkToFit === true && numberOfVariableColumns > 0) {
  5301. totalVariableWidth = grid.width - borderAndPaddingWidth * numberOfVariableColumns - fixedColumnsWidth;
  5302. if (!isNaN(p.height)) {
  5303. totalVariableWidth -= scrollbarWidth;
  5304. hasScrollbar = true;
  5305. }
  5306. initialWidth = 0;
  5307. each(p.colModel, function (i) {
  5308. if (this.hidden === false && !isCellClassHidden(this.classes) && !this.fixed) {
  5309. columnWidth = Math.round(totalVariableWidth * this.width / (p.tblwidth - borderAndPaddingWidth * numberOfVariableColumns - fixedColumnsWidth));
  5310. this.width = columnWidth;
  5311. initialWidth += columnWidth;
  5312. iLastVariableColumn = i;
  5313. }
  5314. });
  5315. correctur = 0;
  5316. if (hasScrollbar) {
  5317. if (grid.width - fixedColumnsWidth - (initialWidth + borderAndPaddingWidth * numberOfVariableColumns) !== scrollbarWidth) {
  5318. correctur = grid.width - fixedColumnsWidth - (initialWidth + borderAndPaddingWidth * numberOfVariableColumns) - scrollbarWidth;
  5319. }
  5320. } else if (!hasScrollbar && Math.abs(grid.width - fixedColumnsWidth - (initialWidth + borderAndPaddingWidth * numberOfVariableColumns)) !== 1) {
  5321. correctur = grid.width - fixedColumnsWidth - (initialWidth + borderAndPaddingWidth * numberOfVariableColumns);
  5322. }
  5323. p.colModel[iLastVariableColumn].width += correctur;
  5324. p.tblwidth = initialWidth + correctur + borderAndPaddingWidth * numberOfVariableColumns + fixedColumnsWidth;
  5325. if (p.tblwidth > p.width) {
  5326. p.colModel[iLastVariableColumn].width -= (p.tblwidth - parseInt(p.width, 10));
  5327. p.tblwidth = p.width;
  5328. }
  5329. }
  5330. },
  5331. nextVisible = function (iCol1) {
  5332. var ret = iCol1, j = iCol1, i;
  5333. for (i = iCol1 + 1; i < p.colModel.length; i++) {
  5334. if (p.colModel[i].hidden !== true) {
  5335. j = i;
  5336. break;
  5337. }
  5338. }
  5339. return j - ret;
  5340. },
  5341. getColumnHeaderIndex = function (th) {
  5342. // TODO: adjust the code after adjust the way which generates
  5343. // ids of frozen columns
  5344. return p.iColByName[(th.id || "").substring(p.id.length + 1)];
  5345. },
  5346. colTemplate;
  5347. if (inArray(p.multikey, sortkeys) === -1) { p.multikey = false; }
  5348. p.keyName = false;
  5349. p.sortorder = p.sortorder.toLowerCase();
  5350. jgrid.cell_width = jgrid.cellWidth();
  5351. var jgridCmTemplate = jgrid.cmTemplate, iCol, cmi;
  5352. for (iCol = 0; iCol < p.colModel.length; iCol++) {
  5353. cmi = p.colModel[iCol];
  5354. colTemplate = typeof cmi.template === "string" ?
  5355. (jgridCmTemplate != null && (typeof jgridCmTemplate[cmi.template] === "object" || isFunction(jgridCmTemplate[cmi.template])) ?
  5356. jgridCmTemplate[cmi.template] : {}) :
  5357. cmi.template;
  5358. if (isFunction(colTemplate)) {
  5359. colTemplate = colTemplate.call(ts, { cm: cmi, iCol: iCol });
  5360. }
  5361. cmi = extend(true, {}, p.cmTemplate, colTemplate || {}, cmi);
  5362. if (p.keyName === false && cmi.key === true) {
  5363. p.keyName = cmi.name;
  5364. }
  5365. p.colModel[iCol] = cmi;
  5366. }
  5367. p.indexByColumnData = buildEmptyIndexedColumnMap();
  5368. for (iCol = 0; iCol < p.additionalProperties.length; iCol++) {
  5369. cmi = p.additionalProperties[iCol];
  5370. if (p.keyName === false && cmi.key === true) {
  5371. p.keyName = cmi.name;
  5372. }
  5373. }
  5374. if (p.colNames.length === 0) {
  5375. for (iCol = 0; iCol < p.colModel.length; iCol++) {
  5376. p.colNames[iCol] = p.colModel[iCol].label !== undefined ? p.colModel[iCol].label : p.colModel[iCol].name;
  5377. }
  5378. }
  5379. if (p.colNames.length !== p.colModel.length) {
  5380. fatalErrorFunction(getRes("errors.model"));
  5381. return;
  5382. }
  5383. if (p.grouping === true) {
  5384. p.scroll = false;
  5385. p.rownumbers = false;
  5386. //p.subGrid = false; expiremental
  5387. p.treeGrid = false;
  5388. p.gridview = true;
  5389. }
  5390. if (p.subGrid && isFunction($j.setSubGrid)) {
  5391. try { $j.setSubGrid.call($self0); } catch (ignore1) { }
  5392. }
  5393. if (p.multiselect && (p.multiselectPosition === "left" || p.multiselectPosition === "right")) {
  5394. var insertMethod = p.multiselectPosition === "left" ? "unshift" : "push";
  5395. p.colNames[insertMethod]("<input id='" + p.cbId + "' class='cbox' type='checkbox' aria-checked='false'/>");
  5396. p.colModel[insertMethod]({ name: "cb", width: jgrid.cell_width ? p.multiselectWidth + p.cellLayout : p.multiselectWidth, labelClasses: "jqgh_cbox", classes: "td_cbox", sortable: false, resizable: false, hidedlg: true, search: false, align: "center", fixed: true, frozen: true });
  5397. }
  5398. if (p.rownumbers) {
  5399. p.colNames.unshift("");
  5400. p.colModel.unshift({ name: "rn", width: jgrid.cell_width ? p.rownumWidth + p.cellLayout : p.rownumWidth, labelClasses: "jqgh_rn", sortable: false, resizable: false, hidedlg: true, search: false, align: "center", fixed: true, frozen: true });
  5401. }
  5402. p.iColByName = buildColNameMap(p.colModel);
  5403. p.xmlReader = extend(true, {
  5404. root: "rows",
  5405. row: "row",
  5406. page: "rows>page",
  5407. total: "rows>total",
  5408. records: "rows>records",
  5409. repeatitems: true,
  5410. cell: "cell",
  5411. id: "[id]",
  5412. userdata: "userdata",
  5413. subgrid: { root: "rows", row: "row", repeatitems: true, cell: "cell" }
  5414. }, p.xmlReader);
  5415. p.jsonReader = extend(true, {
  5416. root: "rows",
  5417. page: "page",
  5418. total: "total",
  5419. records: "records",
  5420. repeatitems: true,
  5421. cell: "cell",
  5422. id: "id",
  5423. userdata: "userdata",
  5424. subgrid: { root: "rows", repeatitems: true, cell: "cell" }
  5425. }, p.jsonReader);
  5426. p.localReader = extend(true, {
  5427. root: "rows",
  5428. page: "page",
  5429. total: "total",
  5430. records: "records",
  5431. repeatitems: false,
  5432. cell: "cell",
  5433. id: "id",
  5434. userdata: "userdata",
  5435. subgrid: { root: "rows", repeatitems: true, cell: "cell" }
  5436. }, p.localReader);
  5437. if (p.scroll) {
  5438. p.pgbuttons = false;
  5439. p.pginput = false;
  5440. p.rowList = [];
  5441. }
  5442. if (p.treeGrid === true) {
  5443. try { $j.setTreeGrid.call($self0); } catch (ignore1) { }
  5444. if (p.datatype !== "local") { p.localReader = { id: "_id_" }; }
  5445. // rebuild p.iPropByName after modification of p.additionalProperties
  5446. p.iPropByName = buildAddPropMap(p.additionalProperties);
  5447. }
  5448. normalizeRemapColumns();
  5449. buildArrayReader();
  5450. if (p.data.length) {
  5451. normalizeData.call(ts);
  5452. refreshIndex.call(ts);
  5453. }
  5454. if (p.shrinkToFit === true && p.forceFit === true) {
  5455. for (iCol = p.colModel.length - 1; iCol >= 0; iCol--) {
  5456. if (p.colModel[iCol].hidden !== true) {
  5457. p.colModel[iCol].resizable = false;
  5458. break;
  5459. }
  5460. }
  5461. }
  5462. var idn, w, res, sort, tooltip, labelStyle, ptr, sortarr = [], sortord = [], sotmp = [],
  5463. thead = "<thead><tr class='ui-jqgrid-labels' role='row'>", headerText,
  5464. tbody = "<tbody><tr style='display:none;'>",
  5465. hoverStateClasses = getGuiStyles("states.hover"),
  5466. hoverThStateClasses = getGuiStyles("states.hoverTh") || hoverStateClasses,
  5467. disabledStateClasses = getGuiStyles("states.disabled");
  5468. if (p.multiSort) {
  5469. sortarr = p.sortname.split(",");
  5470. var iSort;
  5471. for (iSort = 0; iSort < sortarr.length; iSort++) {
  5472. sotmp = trim(sortarr[iSort]).split(" ");
  5473. sortarr[iSort] = trim(sotmp[0]);
  5474. sortord[iSort] = sotmp[1] ? trim(sotmp[1]) : p.sortorder || "asc";
  5475. }
  5476. }
  5477. for (iCol = 0; iCol < p.colNames.length; iCol++) {
  5478. cmi = p.colModel[iCol];
  5479. tooltip = p.headertitles || cmi.headerTitle ? (" title='" + stripHtml(typeof cmi.headerTitle === "string" ? cmi.headerTitle : p.colNames[iCol]) + "'") : "";
  5480. thead += "<th id='" + p.id + "_" + cmi.name + "' class='" + getGuiStyles("colHeaders", "ui-th-column ui-th-" + dir + " " + (cmi.labelClasses || "")) + "'" + tooltip + ">";
  5481. idn = cmi.index || cmi.name;
  5482. switch (cmi.labelAlign) {
  5483. case "left":
  5484. labelStyle = "text-align:left;";
  5485. break;
  5486. case "right":
  5487. labelStyle = "text-align:right;";
  5488. break;
  5489. case "likeData":
  5490. labelStyle = cmi.align === undefined || cmi.align === "left" ?
  5491. "text-align:left;" : (cmi.align === "right" ? "text-align:right;" : "");
  5492. break;
  5493. default:
  5494. labelStyle = "";
  5495. }
  5496. thead += "<div id='jqgh_" + p.id + "_" + cmi.name + "'" +
  5497. (isMSIE ? " class='ui-th-div-ie'" : "") +
  5498. (labelStyle === "" ? "" : " style='" + labelStyle + "'") + " role='columnheader'>";
  5499. headerText = (cmi.autoResizable && cmi.formatter !== "actions") || cmi.rotated ?
  5500. "<span class='" + p.autoResizing.wrapperClassName + "'>" + p.colNames[iCol] + "</span>" :
  5501. p.colNames[iCol];
  5502. if (p.sortIconsBeforeText) {
  5503. thead += (p.builderSortIcons || jgrid.builderSortIcons).call(ts, iCol);
  5504. thead += headerText;
  5505. } else {
  5506. thead += headerText;
  5507. thead += (p.builderSortIcons || jgrid.builderSortIcons).call(ts, iCol);
  5508. }
  5509. thead += "</div></th>";
  5510. tbody += "<td></td>";
  5511. cmi.width = cmi.width ? parseInt(cmi.width, 10) : 150;
  5512. if (typeof cmi.title !== "boolean") { cmi.title = true; }
  5513. cmi.lso = "";
  5514. if (idn === p.sortname) {
  5515. p.lastsort = iCol;
  5516. cmi.lso = p.sortorder || cmi.firstsortorder || "asc";
  5517. }
  5518. if (p.multiSort) {
  5519. sotmp = inArray(idn, sortarr);
  5520. if (sotmp !== -1) {
  5521. cmi.lso = sortord[sotmp];
  5522. }
  5523. }
  5524. }
  5525. thead += "</tr></thead>";
  5526. tbody += "</tr></tbody>";
  5527. var hTable = $("<table class='" + getGuiStyles("hTable", "ui-jqgrid-htable") +
  5528. "' style='width:1px' role='presentation' aria-labelledby='gbox_" + p.id + "'>" +
  5529. thead + tbody + "</table>");
  5530. $(hTable[0].tHead)
  5531. .children("tr")
  5532. .children("th")
  5533. .hover(
  5534. function () { $(this).addClass(hoverThStateClasses); },
  5535. function () { $(this).removeClass(hoverThStateClasses); }
  5536. );
  5537. if (p.multiselect) {
  5538. $(p.cb, hTable).on("click", function () {
  5539. var highlightClass = getGuiStyles("states.select"), toCheck, emp = [],
  5540. iColCb = p.iColByName.cb,
  5541. selectUnselectRow = function (tr, toSelect) {
  5542. $(tr)[toSelect ? "addClass" : "removeClass"](highlightClass)
  5543. .attr(toSelect ?
  5544. { "aria-selected": "true", tabindex: "0" } :
  5545. { "aria-selected": "false", tabindex: "-1" });
  5546. if (iColCb !== undefined) { // p.multiselectCheckboxes
  5547. $(tr.cells[iColCb]).children("input.cbox").prop("checked", toSelect);
  5548. }
  5549. },
  5550. frozenRows = grid.fbRows,
  5551. skipClasses = disabledStateClasses + " ui-subgrid jqgroup jqfoot jqgfirstrow jqgskipselect",
  5552. id, ids = p._index, iSel;
  5553. clearArray(p.selarrrow); // p.selarrrow = [];
  5554. if (this.checked) {
  5555. toCheck = true;
  5556. p.selrow = ts.rows.length > 1 ? ts.rows[ts.rows.length - 1].id : null;
  5557. if (p.multiPageSelection && (p.datatype === "local" || p.treeGrid)) {
  5558. if (p.selectAllMode === "filtered" && p.lastSelectedData != null && p.lastSelectedData.length > 0) {
  5559. p.selarrrow = [];
  5560. for (iSel = 0; iSel < p.lastSelectedData.length; iSel++) {
  5561. if (p.lastSelectedData[iSel].hasOwnProperty(p.localReader.id)) {
  5562. p.selarrrow.push(p.idPrefix + p.lastSelectedData[iSel][p.localReader.id]);
  5563. }
  5564. }
  5565. } else if (p.data != null && p.data.length > 0 && ids != null) {
  5566. // add to selarrrow all
  5567. for (id in ids) {
  5568. if (ids.hasOwnProperty(id)) {
  5569. p.selarrrow.push(p.idPrefix + id);
  5570. }
  5571. }
  5572. }
  5573. }
  5574. } else {
  5575. toCheck = false;
  5576. p.selrow = null;
  5577. }
  5578. var selArr = toCheck ? p.selarrrow : emp;
  5579. $(ts.rows).each(function (i) {
  5580. if (!hasOneFromClasses(this, skipClasses)) {
  5581. selectUnselectRow(this, toCheck);
  5582. if ($.inArray(this.id, selArr) < 0) {
  5583. selArr.push(this.id);
  5584. }
  5585. if (frozenRows) {
  5586. selectUnselectRow(frozenRows[i], toCheck);
  5587. }
  5588. }
  5589. });
  5590. feedback.call(ts, "onSelectAll", toCheck ? p.selarrrow : emp, toCheck);
  5591. // it's important don't use return false in the event handler
  5592. // the usage of return false break checking/unchecking
  5593. });
  5594. }
  5595. if (p.autowidth === true) {
  5596. var pw = Math.floor($(eg).innerWidth());
  5597. p.width = pw > 0 ? pw : "nw";
  5598. }
  5599. if (!isNaN(p.width)) { // process values like "500" instead of the number 500.
  5600. p.width = Number(p.width);
  5601. } else if (!isNaN(parseFloat(p.width))) { // process values like "500px"
  5602. p.width = parseFloat(p.width);
  5603. }
  5604. p.widthOrg = p.width;
  5605. setInitialColWidth();
  5606. $(eg).css("width", grid.width + "px")
  5607. .append("<div class='" + getGuiStyles("resizer", "ui-jqgrid-resize-mark") + "' id='" + p.rsId + "'>&#160;</div>");
  5608. $(p.rs)
  5609. .on("selectstart", function () {
  5610. return false;
  5611. })
  5612. .click(myResizerClickHandler)
  5613. .dblclick(function (e) {
  5614. var iColIndex = $(this).data("idx"),
  5615. pageX = $(this).data("pageX"),
  5616. cm = p.colModel[iColIndex];
  5617. if (pageX == null || cm == null) {
  5618. return false;
  5619. }
  5620. var arPageX = String(pageX).split(";"),
  5621. pageX1 = parseFloat(arPageX[0]),
  5622. pageX2 = parseFloat(arPageX[1]);
  5623. if (arPageX.length === 2 && (Math.abs(pageX1 - pageX2) > 5 || Math.abs(e.pageX - pageX1) > 5 || Math.abs(e.pageX - pageX2) > 5)) {
  5624. return false;
  5625. }
  5626. if (feedback.call(ts, "resizeDblClick", iColIndex, cm, e) && cm.autoResizable) {
  5627. $j.autoResizeColumn.call($self0, iColIndex);
  5628. }
  5629. feedback.call(ts, "afterResizeDblClick", { iCol: iColIndex, cm: cm, cmName: cm.name });
  5630. return false; // stop propagate
  5631. });
  5632. $(gv).css("width", grid.width + "px");
  5633. var tfoot = "";
  5634. if (p.footerrow) {
  5635. tfoot += "<table role='presentation' style='width:1px' class='" +
  5636. getGuiStyles("gridFooter", "ui-jqgrid-ftable") +
  5637. "'><tbody><tr role='row' class='" + getGuiStyles("rowFooter", "footrow footrow-" + dir) + "'>";
  5638. }
  5639. var firstr = "<tr class='" + getGuiStyles("gridRow", "jqgfirstrow ui-row-" + p.direction) + "' role='row' style='height:auto'>";
  5640. p.disableClick = false;
  5641. $("th", hTable[0].tHead.rows[0])
  5642. .each(function (j) {
  5643. var cm = p.colModel[j], nm = cm.name, $th = $(this),
  5644. $sortableDiv = $th.children("div"),
  5645. $iconsSpan = $sortableDiv.children("span.s-ico"),
  5646. showOneSortIcon = p.showOneSortIcon;
  5647. w = cm.width;
  5648. if (cm.resizable === undefined) { cm.resizable = true; }
  5649. if (cm.resizable) {
  5650. res = document.createElement("span");
  5651. $(res).html("&#160;")
  5652. .addClass("ui-jqgrid-resize ui-jqgrid-resize-" + dir)
  5653. //.css("cursor","col-resize")
  5654. .on("selectstart", function () {
  5655. return false;
  5656. });
  5657. $th.addClass(p.resizeclass);
  5658. } else {
  5659. res = "";
  5660. }
  5661. $th.css("width", w + "px")
  5662. .prepend(res);
  5663. res = null;
  5664. var hdcol = "";
  5665. if (cm.hidden === true) {
  5666. $th.css("display", "none");
  5667. hdcol = "display:none;";
  5668. }
  5669. firstr += "<td role='gridcell' " + (cm.classes ? "class='" + cm.classes + "' " : "") +
  5670. "style='height:0;width:" + w + "px;" + hdcol + "'></td>";
  5671. grid.headers[j] = { width: w, el: this };
  5672. sort = cm.sortable;
  5673. if (typeof sort !== "boolean") { cm.sortable = true; sort = true; }
  5674. if (!(nm === "cb" || nm === "subgrid" || nm === "rn") && sort) {
  5675. if (p.viewsortcols[2]) {
  5676. // class ui-jqgrid-sortable changes the cursor in
  5677. $sortableDiv.addClass("ui-jqgrid-sortable");
  5678. }
  5679. }
  5680. if (sort) {
  5681. if (p.multiSort) {
  5682. var notLso = cm.lso === "desc" ? "asc" : "desc";
  5683. if (p.viewsortcols[0]) {
  5684. $iconsSpan.css("display", "");
  5685. if (cm.lso) {
  5686. $iconsSpan.children("span.ui-icon-" + cm.lso).removeClass(disabledStateClasses);
  5687. if (showOneSortIcon) {
  5688. $iconsSpan.children("span.ui-icon-" + notLso).hide();
  5689. }
  5690. }
  5691. } else if (cm.lso) {
  5692. $iconsSpan.css("display", "");
  5693. $iconsSpan.children("span.ui-icon-" + cm.lso).removeClass(disabledStateClasses);
  5694. if (showOneSortIcon) {
  5695. $iconsSpan.children("span.ui-icon-" + notLso).hide();
  5696. }
  5697. }
  5698. if (p.showSortOrder) {
  5699. sotmp = inArray(nm, sortarr);
  5700. $iconsSpan[p.sortOrderPosition === "beforeSortIcons" ? "before" : "after"]("<span class='ui-jqgrid-sort-order'>" +
  5701. (sotmp < 0 ?
  5702. "&nbsp;" :
  5703. isFunction(p.formatSortOrder) ?
  5704. p.formatSortOrder.call(ts, { cm: this, sortIndex: sotmp }) :
  5705. sotmp + 1) +
  5706. "</span>");
  5707. }
  5708. } else {
  5709. var notSortOrder = p.sortorder === "desc" ? "asc" : "desc";
  5710. if (p.viewsortcols[0]) {
  5711. $iconsSpan.css("display", "");
  5712. if (j === p.lastsort) {
  5713. $iconsSpan.children("span.ui-icon-" + p.sortorder).removeClass(disabledStateClasses);
  5714. if (showOneSortIcon) {
  5715. $iconsSpan.children("span.ui-icon-" + notSortOrder).hide();
  5716. }
  5717. }
  5718. } else if (j === p.lastsort && cm.lso !== "") { // p.sortname === (cm.index || nm)
  5719. $iconsSpan.css("display", "");
  5720. $iconsSpan.children("span.ui-icon-" + p.sortorder).removeClass(disabledStateClasses);
  5721. if (showOneSortIcon) {
  5722. $iconsSpan.children("span.ui-icon-" + notSortOrder).hide();
  5723. }
  5724. }
  5725. }
  5726. }
  5727. if (p.footerrow) { tfoot += "<td role='gridcell' " + formatCol(j, 0, "", null, "", false) + ">&#160;</td>"; }
  5728. })
  5729. .mousedown(function (e) {
  5730. var $th = $(this), isFrozen = $th.closest(".ui-jqgrid-hdiv").hasClass("frozen-div"),
  5731. getOffset = function () {
  5732. var ret = [$th.position().left + $th.outerWidth()];
  5733. if (p.direction === "rtl") { ret[0] = p.width - ret[0]; }
  5734. ret[0] -= isFrozen ? 0 : grid.bDiv.scrollLeft;
  5735. ret.push($(grid.hDiv).position().top);
  5736. ret.push($(grid.bDiv).offset().top - $(grid.hDiv).offset().top + $(grid.bDiv).height() +
  5737. (grid.sDiv ? $(grid.sDiv).height() : 0));
  5738. return ret;
  5739. },
  5740. iCol1;
  5741. if ($(e.target).closest("th>span.ui-jqgrid-resize").length !== 1) { return; }
  5742. iCol1 = getColumnHeaderIndex(this);
  5743. if (iCol1 != null) {
  5744. if (p.forceFit === true) { p.nv = nextVisible(iCol1); }
  5745. grid.dragStart(iCol1, e, getOffset(), $th);
  5746. }
  5747. return false;
  5748. })
  5749. .click(function (e) {
  5750. if (p.disableClick) {
  5751. p.disableClick = false;
  5752. return false;
  5753. }
  5754. var s = "th.ui-th-column>div", r, d;
  5755. if (!p.viewsortcols[2]) {
  5756. s += ">span.s-ico>span.ui-grid-ico-sort"; // sort only on click on sorting icon
  5757. } else {
  5758. s += ".ui-jqgrid-sortable";
  5759. }
  5760. var t = $(e.target).closest(s);
  5761. if (t.length !== 1) { return; }
  5762. if (!p.viewsortcols[2]) {
  5763. r = true;
  5764. d = t.hasClass("ui-icon-desc") ? "asc" : "desc";
  5765. }
  5766. var iColByName = getColumnHeaderIndex(this);
  5767. if (iColByName != null) {
  5768. // the $("div", this)[0].id looks like "jqgh_" + p.id + "_" + colIndex (like "jqgh_list_invdate")
  5769. sortData.call(ts, $("div", this)[0].id.substring(5 + p.id.length + 1), iColByName, r, d, this, e);
  5770. }
  5771. return false;
  5772. });
  5773. if (p.sortable && isFunction($j.sortableColumns)) {
  5774. try {
  5775. $j.sortableColumns.call($self0, $(hTable[0].tHead.rows[0]));
  5776. } catch (ignore1) { }
  5777. }
  5778. if (p.footerrow) { tfoot += "</tr></tbody></table>"; }
  5779. firstr += "</tr>";
  5780. $self0.html("<tbody>" + firstr + "</tbody>");
  5781. //firstr = null;
  5782. $self0.addClass(getGuiStyles("grid", "ui-jqgrid-btable" + (p.altRows === true && $self0.jqGrid("isBootstrapGuiStyle") ? " table-striped" : "")));
  5783. var hg = (p.caption && p.hiddengrid === true) ? true : false,
  5784. hb = $("<div class='ui-jqgrid-hbox" + (dir === "rtl" ? "-rtl" : "") + "'></div>"),
  5785. topClasses = getGuiStyles("top"),
  5786. bottomClasses = getGuiStyles("bottom");
  5787. grid.hDiv = document.createElement("div");
  5788. $(grid.hDiv)
  5789. .css({ width: grid.width + "px" })
  5790. .addClass(getGuiStyles("hDiv", "ui-jqgrid-hdiv"))
  5791. .append(hb)
  5792. .scroll(function () {
  5793. // the hDiv can be scrolled because of tab keyboard navigation
  5794. // we have to sync bDiv and hDiv scrollLeft in the case
  5795. var bDiv = $(this).next(".ui-jqgrid-bdiv")[0];
  5796. if (bDiv) {
  5797. bDiv.scrollLeft = this.scrollLeft;
  5798. }
  5799. return false;
  5800. });
  5801. $(hb).append(hTable);
  5802. hTable = null;
  5803. if (hg) { $(grid.hDiv).hide(); }
  5804. p.rowNum = parseInt(p.rowNum, 10);
  5805. if (isNaN(p.rowNum) || p.rowNum <= 0) {
  5806. p.rowNum = p.maxRowNum;
  5807. }
  5808. if (p.pager) {
  5809. // see http://learn.jquery.com/using-jquery-core/faq/how-do-i-select-an-element-by-an-id-that-has-characters-used-in-css-notation/
  5810. // or http://api.jquery.com/id-selector/ or http://api.jquery.com/category/selectors/
  5811. // about the requirement to escape characters like ".", ":" or some other in case.
  5812. var $pager, pagerId;
  5813. if (typeof p.pager === "string" && p.pager.substr(0, 1) !== "#") {
  5814. pagerId = p.pager; // UNESCAPED id of the pager
  5815. $pager = $("#" + jqID(p.pager));
  5816. } else if (p.pager === true) {
  5817. pagerId = randId();
  5818. $pager = $("<div id='" + pagerId + "'></div>");
  5819. $pager.appendTo("body");
  5820. p.pager = "#" + jqID(pagerId);
  5821. } else {
  5822. $pager = $(p.pager); // jQuery wrapper or ESCAPED id selector
  5823. pagerId = $pager.attr("id");
  5824. }
  5825. if ($pager.length > 0) {
  5826. $pager.css({ width: grid.width + "px" }).addClass(getGuiStyles("pager.pager", "ui-jqgrid-pager " + bottomClasses)).appendTo(eg);
  5827. if (hg) { $pager.hide(); }
  5828. setPager.call(ts, pagerId, "");
  5829. p.pager = "#" + jqID(pagerId); // hold ESCAPED id selector in the pager
  5830. } else {
  5831. p.pager = ""; // clear wrong value of the pager option
  5832. }
  5833. }
  5834. if (p.cellEdit === false && p.hoverrows === true) {
  5835. $self0
  5836. .on("mouseover.jqGrid", function (e) {
  5837. ptr = $(e.target).closest("tr.jqgrow");
  5838. if ($(ptr).attr("class") !== "ui-subgrid") {
  5839. $(ptr).addClass(hoverStateClasses);
  5840. }
  5841. })
  5842. .on("mouseout.jqGrid", function (e) {
  5843. ptr = $(e.target).closest("tr.jqgrow");
  5844. $(ptr).removeClass(hoverStateClasses);
  5845. });
  5846. }
  5847. var getTdFromTarget = function (target) {
  5848. var $td, $tr, $table;
  5849. do {
  5850. $td = $(target).closest("td");
  5851. if ($td.length > 0) {
  5852. $tr = $td.parent();
  5853. $table = $tr.parent().parent();
  5854. if ($tr.is(".jqgrow") && ($table[0] === this || ($table.is("table.ui-jqgrid-btable") && ($table[0].id || "").replace("_frozen", "") === this.id))) {
  5855. break;
  5856. }
  5857. target = $td.parent();
  5858. }
  5859. } while ($td.length > 0);
  5860. return $td;
  5861. };
  5862. $self0.before(grid.hDiv)
  5863. .click(function (e) {
  5864. var highlightClass = getGuiStyles("states.select"), target = e.target,
  5865. $td = getTdFromTarget.call(ts, target), $tr = $td.parent();
  5866. // we uses ts.rows context below to be sure that we don't process the clicks in the subgrid
  5867. // probably one can change the rule and to step over the parents till one will have
  5868. // "tr.jqgrow>td" AND the parent of parent (the table element) will be ts.
  5869. // one can use the same processing in click, dblclick and contextmenu
  5870. //ptr = $(td, ts.rows).closest("tr.jqgrow");
  5871. if ($tr.length === 0 || hasOneFromClasses($tr, disabledStateClasses)) {
  5872. return;
  5873. }
  5874. var ri = $tr[0].id, ci = $td[0].cellIndex,
  5875. checkboxClicked = $(target).hasClass("cbox") &&
  5876. $(target).is(":enabled") && !hasOneFromClasses(target, disabledStateClasses),
  5877. selectionAllowed = feedback.call(ts, "beforeSelectRow", ri, e), alreadySelected = false,
  5878. editingInfo = jgrid.detectRowEditing.call(ts, ri),
  5879. locked = editingInfo != null && editingInfo.mode !== "cellEditing"; // editingInfo.savedRow.ic
  5880. if (target.tagName === "A" || (locked && !checkboxClicked)) { return; }
  5881. feedback.call(ts, "onCellSelect", ri, ci, $td.html(), e);
  5882. if (p.cellEdit === true) {
  5883. if (selectionAllowed && p.multiselect && checkboxClicked) {
  5884. setSelection.call($self0, ri, true, e);
  5885. if (checkboxClicked && !p.noCellSelection) {
  5886. return;
  5887. }
  5888. alreadySelected = true;
  5889. }
  5890. try {
  5891. $j.editCell.call($self0, $tr[0].rowIndex, ci, true);
  5892. } catch (ignore) { }
  5893. if (!p.multiselect || !p.noCellSelection || (p.multiboxonly && alreadySelected)) {
  5894. return;
  5895. }
  5896. }
  5897. if (!selectionAllowed) {
  5898. if (checkboxClicked) {
  5899. // selection is not allowed by beforeSelectRow, but the multiselect
  5900. // checkbox is clicked.
  5901. $(target).prop("checked", false);
  5902. }
  5903. return;
  5904. }
  5905. if (!p.multikey) {
  5906. if (p.multiselect && p.multiboxonly) {
  5907. if (checkboxClicked && !alreadySelected) {
  5908. setSelection.call($self0, ri, true, e);
  5909. } else {
  5910. var frz = p.frozenColumns ? p.id + "_frozen" : "";
  5911. $(p.selarrrow).each(function (i, n) {
  5912. var trid = $j.getGridRowById.call($self0, n);
  5913. if (trid) { $(trid).removeClass(highlightClass); }
  5914. $("#jqg_" + jqID(p.id) + "_" + jqID(n)).prop("checked", false);
  5915. if (frz) {
  5916. $("#" + jqID(n), "#" + jqID(frz)).removeClass(highlightClass);
  5917. $("#jqg_" + jqID(p.id) + "_" + jqID(n), "#" + jqID(frz)).prop("checked", false);
  5918. }
  5919. });
  5920. clearArray(p.selarrrow); // p.selarrrow = [];
  5921. if (!alreadySelected) {
  5922. setSelection.call($self0, ri, true, e);
  5923. }
  5924. }
  5925. } else {
  5926. var oldSelRow = p.selrow;
  5927. if (!alreadySelected) {
  5928. setSelection.call($self0, ri, true, e);
  5929. }
  5930. if (p.singleSelectClickMode === "toggle" && !p.multiselect && oldSelRow === ri) {
  5931. if (ts.grid.fbRows) {
  5932. $tr = $tr.add(
  5933. ts.grid.fbRows[$tr[0].rowIndex] === $tr[0] ?
  5934. ts.rows[$tr[0].rowIndex] :
  5935. ts.grid.fbRows[$tr[0].rowIndex]
  5936. );
  5937. }
  5938. $tr.removeClass(highlightClass).attr({ "aria-selected": "false", "tabindex": "-1" });
  5939. p.selrow = null;
  5940. }
  5941. }
  5942. } else {
  5943. if (e[p.multikey] && !alreadySelected) {
  5944. setSelection.call($self0, ri, true, e);
  5945. } else if (p.multiselect && checkboxClicked) {
  5946. checkboxClicked = $("#jqg_" + jqID(p.id) + "_" + ri).is(":checked");
  5947. $("#jqg_" + jqID(p.id) + "_" + ri).prop("checked", !checkboxClicked);
  5948. }
  5949. }
  5950. // it's important don't use return false in the event handler
  5951. // the usage of return false break checking/uchecking
  5952. })
  5953. .on("reloadGrid", function (e, opts) {
  5954. var self = this, gridSelf = self.grid, $self = $(this), p = self.p;
  5955. if (p.savedRow.length > 0 && p.reloadingDuringEditing === "prevent") {
  5956. return false;
  5957. }
  5958. if (p.treeGrid === true) {
  5959. p.datatype = p.treedatatype;
  5960. }
  5961. opts = extend({}, defaults.reloadGridOptions || {}, p.reloadGridOptions || {}, opts || {});
  5962. if (p.datatype === "local" && p.dataTypeOrg && p.loadonce && opts.fromServer) {
  5963. p.datatype = p.dataTypeOrg;
  5964. delete p.dataTypeOrg;
  5965. }
  5966. if (opts.current) {
  5967. gridSelf.selectionPreserver.call(self);
  5968. }
  5969. if (p.datatype === "local") {
  5970. if (!p.multiPageSelection) {
  5971. $j.resetSelection.call($self);
  5972. }
  5973. if (p.data.length) {
  5974. normalizeData.call(self);
  5975. refreshIndex.call(self);
  5976. }
  5977. } else if (!p.treeGrid && !p.multiPageSelection) {
  5978. p.selrow = null;
  5979. if (p.multiselect) {
  5980. clearArray(p.selarrrow); // p.selarrrow = [];
  5981. setHeadCheckBox.call(self, false);
  5982. }
  5983. clearArray(p.savedRow); // p.savedRow = [];
  5984. p.editingInfo = {};
  5985. }
  5986. cancelOrSaveEditing(p.reloadingDuringEditing);
  5987. p.iRow = -1;
  5988. p.iCol = -1;
  5989. if (p.scroll) { grid.emptyRows.call(self, true, false); }
  5990. if (opts.page) {
  5991. var page = parseInt(opts.page, 10);
  5992. if (page > p.lastpage) { page = p.lastpage; }
  5993. if (page < 1) { page = 1; }
  5994. p.page = page;
  5995. if (gridSelf.prevRowHeight) {
  5996. gridSelf.bDiv.scrollTop = (page - 1) * gridSelf.prevRowHeight * p.rowNum;
  5997. } else {
  5998. gridSelf.bDiv.scrollTop = 0;
  5999. }
  6000. }
  6001. if (gridSelf.prevRowHeight && p.scroll && opts.page === undefined) {
  6002. delete p.lastpage;
  6003. gridSelf.populateVisible.call(self);
  6004. } else {
  6005. gridSelf.populate.call(self);
  6006. }
  6007. if (p._inlinenav === true) { $self.jqGrid("showAddEditButtons", false); }
  6008. return false;
  6009. })
  6010. .dblclick(function (e) {
  6011. var $td = getTdFromTarget.call(ts, e.target), $tr = $td.parent();
  6012. // TODO: replace ts below to method which use $(this) in case of click
  6013. // on the grid and the table of the main grid if one click inside the FROZEN column
  6014. if ($td.length > 0 && !feedback.call(ts, "ondblClickRow", $tr.attr("id"), $tr[0].rowIndex, $td[0].cellIndex, e)) {
  6015. return false; // e.preventDefault() and e.stopPropagation() together
  6016. }
  6017. })
  6018. .on("contextmenu", function (e) {
  6019. var $td = getTdFromTarget.call(ts, e.target), $tr = $td.parent(), rowid = $tr.attr("id");
  6020. if ($td.length === 0) { return; }
  6021. if (!p.multiselect && p.selrow !== rowid && p.selectOnContextMenu === true) {
  6022. // TODO: replace $self0 and ts below to method which use $(this) in case of click
  6023. // on the grid and the table of the main grid if one click inside the FROZEN column
  6024. setSelection.call($self0, rowid, true, e);
  6025. }
  6026. if (!feedback.call(ts, "onRightClickRow", rowid, $tr[0].rowIndex, $td[0].cellIndex, e)) {
  6027. return false; // e.preventDefault() and e.stopPropagation() together
  6028. }
  6029. });
  6030. grid.bDiv = document.createElement("div");
  6031. if (isMSIE) { if (String(p.height).toLowerCase() === "auto") { p.height = "100%"; } }
  6032. $(grid.bDiv)
  6033. .append($("<div style='position:relative;'></div>").append("<div></div>").append(ts))
  6034. .addClass("ui-jqgrid-bdiv")
  6035. .css({ height: p.height + (isNaN(p.height) ? "" : "px"), width: (grid.width) + "px" })
  6036. .scroll(grid.scrollGrid);
  6037. if (p.maxHeight) {
  6038. $(grid.bDiv).css("max-height", p.maxHeight + (isNaN(p.maxHeight) ? "" : "px"));
  6039. }
  6040. $self0.css({ width: "1px" });
  6041. if (!$.support.tbody) { //IE
  6042. if ($(">tbody", ts).length === 2) { $(">tbody:gt(0)", ts).remove(); }
  6043. }
  6044. if (p.multikey) {
  6045. $(grid.bDiv).on(jgrid.msie ? "selectstart" : "mousedown", function () { return false; });
  6046. }
  6047. if (hg) { $(grid.bDiv).hide(); }
  6048. grid.cDiv = document.createElement("div");
  6049. var visibleGridIcon = getIcon("gridMinimize.visible"), hiddenGridIcon = getIcon("gridMinimize.hidden"), showhide = getDef("showhide"),
  6050. arf = p.hidegrid === true ?
  6051. $("<a role='link' class='" + getGuiStyles("titleButton", "ui-jqgrid-titlebar-close") + "'" + (showhide ? " title='" + showhide + "'" : "") + "/>")
  6052. .hover(
  6053. function () { arf.addClass(hoverStateClasses); },
  6054. function () { arf.removeClass(hoverStateClasses); }
  6055. )
  6056. .append("<span class='" + visibleGridIcon + "'></span>") :
  6057. "";
  6058. $(grid.cDiv).append("<span class='ui-jqgrid-title'>" + p.caption + "</span>")
  6059. .append(arf)
  6060. .addClass(getGuiStyles("gridTitle", "ui-jqgrid-titlebar ui-jqgrid-caption" + (dir === "rtl" ? "-rtl " : " ") + topClasses));
  6061. $(grid.cDiv).insertBefore(grid.hDiv);
  6062. if (p.toolbar[0]) {
  6063. grid.uDiv = document.createElement("div");
  6064. if (p.toolbar[1] === "top") {
  6065. $(grid.uDiv).insertBefore(grid.hDiv);
  6066. } else if (p.toolbar[1] === "bottom") {
  6067. $(grid.uDiv).insertAfter(grid.hDiv);
  6068. }
  6069. var toolbarUpperClasses = getGuiStyles("toolbarUpper", "ui-userdata");
  6070. if (p.toolbar[1] === "both") {
  6071. grid.ubDiv = document.createElement("div");
  6072. $(grid.uDiv).addClass(toolbarUpperClasses).attr("id", "t_" + p.id).insertBefore(grid.hDiv);
  6073. $(grid.ubDiv).addClass(getGuiStyles("toolbarBottom", "ui-userdata")).attr("id", "tb_" + p.id).insertAfter(grid.hDiv);
  6074. if (hg) { $(grid.ubDiv).hide(); }
  6075. } else {
  6076. $(grid.uDiv).width(grid.width).addClass(toolbarUpperClasses).attr("id", "t_" + p.id);
  6077. }
  6078. if (hg) { $(grid.uDiv).hide(); }
  6079. }
  6080. if (typeof p.datatype === "string") {
  6081. p.datatype = p.datatype.toLowerCase();
  6082. }
  6083. if (p.toppager) {
  6084. p.toppager = p.id + "_toppager";
  6085. grid.topDiv = $("<div id='" + p.toppager + "'></div>")[0];
  6086. $(grid.topDiv)
  6087. .addClass(getGuiStyles("pager.pager", "ui-jqgrid-toppager" + (p.caption ? "" : " " + topClasses)))
  6088. .css({ width: grid.width + "px" })
  6089. .insertBefore(grid.hDiv);
  6090. setPager.call(ts, p.toppager, "_t");
  6091. p.toppager = "#" + jqID(p.toppager); // hold ESCAPED id selector in the toppager option
  6092. } else if (p.pager === "" && !p.scroll) {
  6093. p.rowNum = p.maxRowNum;
  6094. }
  6095. if (p.footerrow) {
  6096. grid.sDiv = $("<div class='ui-jqgrid-sdiv'></div>")[0];
  6097. hb = $("<div class='ui-jqgrid-hbox" + (dir === "rtl" ? "-rtl" : "") + "'></div>");
  6098. $(grid.sDiv).append(hb).width(grid.width).insertAfter(grid.hDiv);
  6099. $(hb).append(tfoot);
  6100. grid.footers = $(".ui-jqgrid-ftable", grid.sDiv)[0].rows[0].cells;
  6101. if (p.rownumbers) { grid.footers[0].className = getGuiStyles("rowNum", "jqgrid-rownum"); }
  6102. if (hg) { $(grid.sDiv).hide(); }
  6103. }
  6104. hb = null;
  6105. if (p.caption) {
  6106. var tdt = p.datatype;
  6107. if (p.hidegrid === true) {
  6108. $(".ui-jqgrid-titlebar-close", grid.cDiv).click(function (e) {
  6109. var elems = ".ui-jqgrid-bdiv,.ui-jqgrid-hdiv,.ui-jqgrid-pager,.ui-jqgrid-sdiv", self = this;
  6110. if (p.toolbar[0] === true) {
  6111. if (p.toolbar[1] === "both") {
  6112. elems += ",#" + jqID($(grid.ubDiv).attr("id"));
  6113. }
  6114. elems += ",#" + jqID($(grid.uDiv).attr("id"));
  6115. }
  6116. var counter = $(elems, p.gView).length;
  6117. if (p.toppager) {
  6118. elems += "," + p.toppager;
  6119. }
  6120. if (p.gridstate === "visible") {
  6121. $(elems, p.gBox).slideUp("fast", function () {
  6122. counter--;
  6123. if (counter === 0) {
  6124. $("span", self).removeClass(visibleGridIcon).addClass(hiddenGridIcon);
  6125. p.gridstate = "hidden";
  6126. if ($(p.gBox).hasClass("ui-resizable")) { $(".ui-resizable-handle", p.gBox).hide(); }
  6127. $(grid.cDiv).addClass(bottomClasses);
  6128. if (!hg) { feedback.call(ts, "onHeaderClick", p.gridstate, e); }
  6129. }
  6130. });
  6131. } else if (p.gridstate === "hidden") {
  6132. $(grid.cDiv).removeClass(bottomClasses);
  6133. $(elems, p.gBox).slideDown("fast", function () {
  6134. counter--;
  6135. if (counter === 0) {
  6136. $("span", self).removeClass(hiddenGridIcon).addClass(visibleGridIcon);
  6137. if (hg) { p.datatype = tdt; populate.call(ts); hg = false; }
  6138. p.gridstate = "visible";
  6139. if ($(p.gBox).hasClass("ui-resizable")) { $(".ui-resizable-handle", p.gBox).show(); }
  6140. if (!hg) { feedback.call(ts, "onHeaderClick", p.gridstate, e); }
  6141. }
  6142. });
  6143. }
  6144. return false;
  6145. });
  6146. if (hg) { p.datatype = "local"; $(".ui-jqgrid-titlebar-close", grid.cDiv).trigger("click"); }
  6147. }
  6148. } else {
  6149. $(grid.cDiv).hide();
  6150. $(grid.cDiv).nextAll("div:visible").first().addClass("ui-corner-top"); // set on top toolbar or toppager or on hDiv
  6151. }
  6152. $(grid.hDiv).after(grid.bDiv);
  6153. grid.eDiv = $("<div class='" + getGuiStyles("gridError", "ui-jqgrid-errorbar ui-jqgrid-errorbar-" + dir) +
  6154. "' style='display:none;'>" +
  6155. //($self0.jqGrid("isBootstrapGuiStyle") ? "<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button>" : "") +
  6156. "<span class='" + getGuiStyles("gridErrorText", "ui-jqgrid-error") + "'></span></div>")[0];
  6157. $(grid.hDiv).after(grid.eDiv);
  6158. $(eg)
  6159. .click(myResizerClickHandler)
  6160. .dblclick(function (e) { // it's still needed for Firefox
  6161. var $resizer = $(p.rs),
  6162. resizerOffset = $resizer.offset(),
  6163. iColIndex = $resizer.data("idx"),
  6164. delta = $resizer.data("delta"),
  6165. cm = p.colModel[iColIndex],
  6166. pageX = $(this).data("pageX") || $resizer.data("pageX");
  6167. if (pageX == null || cm == null) {
  6168. return false;
  6169. }
  6170. var arPageX = String(pageX).split(";"),
  6171. pageX1 = parseFloat(arPageX[0]),
  6172. pageX2 = parseFloat(arPageX[1]);
  6173. if (arPageX.length === 2 && (Math.abs(pageX1 - pageX2) > 5 || Math.abs(e.pageX - pageX1) > 5 || Math.abs(e.pageX - pageX2) > 5)) {
  6174. return false;
  6175. }
  6176. if (feedback.call(ts, "resizeDblClick", iColIndex, cm) &&
  6177. (resizerOffset.left - 1 <= e.pageX + delta && e.pageX + delta <= resizerOffset.left + $resizer.outerWidth() + 1) && cm.autoResizable) {
  6178. $j.autoResizeColumn.call($self0, iColIndex);
  6179. }
  6180. feedback.call(ts, "afterResizeDblClick", { iCol: iColIndex, cm: cm, cmName: cm.name });
  6181. return false;
  6182. });
  6183. if (!p.pager) {
  6184. $(grid.cDiv).nextAll("div:visible").filter(":last").addClass(bottomClasses); // set on bottom toolbar or footer (sDiv) or on bDiv
  6185. }
  6186. $(".ui-jqgrid-labels", grid.hDiv)
  6187. .on("selectstart", function () { return false; });
  6188. ts.formatCol = formatCol;
  6189. ts.sortData = sortData;
  6190. ts.updatepager = updatepager;
  6191. ts.refreshIndex = refreshIndex;
  6192. ts.addItemDataToColumnIndex = addItemDataToColumnIndex;
  6193. ts.removeItemDataFromColumnIndex = removeItemDataFromColumnIndex;
  6194. ts.generateValueFromColumnIndex = function (cmName, separator, delimiter) {
  6195. var uniqueTexts = $(this).jqGrid("getUniqueValueFromColumnIndex", cmName), v = "", i, len;
  6196. if (uniqueTexts != null) {
  6197. // convert to format of editoptions.value or searchoptions.value
  6198. delimiter = delimiter || ";";
  6199. separator = separator || ":";
  6200. for (i = 0, len = uniqueTexts.length; i < len; i++) {
  6201. if (v !== "") {
  6202. v += delimiter || ";";
  6203. }
  6204. v += uniqueTexts[i] + (separator || ":") + uniqueTexts[i];
  6205. }
  6206. }
  6207. return v;
  6208. };
  6209. ts.setHeadCheckBox = setHeadCheckBox;
  6210. ts.fixScrollOffsetAndhBoxPadding = fixScrollOffsetAndhBoxPadding;
  6211. ts.constructTr = constructTr;
  6212. ts.formatter = formatter;
  6213. extend(grid, { populate: populate, emptyRows: emptyRows, beginReq: beginReq, endReq: endReq });
  6214. ts.addXmlData = readInput;
  6215. ts.addJSONData = readInput;
  6216. ts.rebuildRowIndexes = rebuildRowIndexes;
  6217. ts.grid.cols = ts.rows[0].cells;
  6218. feedback.call(ts, "onInitGrid");
  6219. // fix to allow to load TreeGrid using datatype:"local", data:mydata instead of treeGrid: true
  6220. if (p.treeGrid && p.datatype === "local" && p.data != null && p.data.length > 0) {
  6221. p.datatype = "jsonstring";
  6222. p.datastr = p.data;
  6223. p.data = [];
  6224. }
  6225. populate.call(ts);
  6226. p.hiddengrid = false;
  6227. });
  6228. };
  6229. var base = $.fn.jqGrid;
  6230. jgrid.extend({
  6231. getGridRes: function (defaultPropName) {
  6232. // The problem is the following: there are already exist some properties of $.jgrid which can be used
  6233. // to set some defaults of jqGrid. It's: $.jgrid.defaults, $.jgrid.search, $.jgrid.edit, $.jgrid.view, $.jgrid.del, $.jgrid.nav
  6234. // $.jgrid.formatter, $.jgrid.errors, $.jgrid.col
  6235. // Existing programs could use the objects to set either language specific settings (which are now moved under locales part)
  6236. // be language independent. Thus one should combine language specific settings with the user's settings and overwrite the settings
  6237. // with grid specific settings if the settings exist.
  6238. //
  6239. // For example:
  6240. // p.loadtext (grid option) = "..."
  6241. // $.jgrid.defaults.loadtext = "........."
  6242. // p.locales = "en-US",
  6243. // $.jgrid.locales["en-US"].defaults.loadtext = "Loading...";
  6244. //
  6245. // p.edit.addCaption = "Add Invoice"
  6246. // $.jgrid.edit.addCaption = "Add"
  6247. // p.locales = "en-US",
  6248. // $.jgrid.locales["en-US"].edit.addCaption = "Add Record";
  6249. //
  6250. // In the case the grid option p.loadtext = "..." need be used. If p.loadtext is not defined then $.jgrid.defaults.loadtext. If
  6251. // $.jgrid.defaults.loadtext is not defined explicitly by the user, then language settings will be used
  6252. var $t = this[0];
  6253. if (!$t || !$t.grid || !$t.p) { return null; }
  6254. // One need get defaultPropName from $.jgrid root first. If no value exist then one should get it from $.jgrid[reg] root
  6255. var res = jgrid.getRes(locales[$t.p.locale], defaultPropName) || jgrid.getRes(locales["en-US"], defaultPropName),
  6256. resDef = jgrid.getRes(jgrid, defaultPropName);
  6257. return typeof res === "object" && res !== null && !$.isArray(res) ?
  6258. $.extend(true, {}, res, resDef || {}) : // !!! Expensive and can be slow !!!
  6259. resDef !== undefined ? resDef : res;
  6260. },
  6261. getGuiStyles: function (path, jqClasses) {
  6262. var $t = this instanceof $ && this.length > 0 ? this[0] : this;
  6263. if (!$t || !$t.grid || !$t.p) { return ""; }
  6264. var p = $t.p, guiStyle = p.guiStyle || jgrid.defaults.guiStyle || "jQueryUI",
  6265. guiClasses = jgrid.getRes(jgrid.guiStyles[guiStyle], path), baseGuiStyle;
  6266. if (guiClasses === undefined) {
  6267. baseGuiStyle = jgrid.getRes(jgrid.guiStyles[guiStyle], "baseGuiStyle");
  6268. if (typeof baseGuiStyle === "string") {
  6269. guiClasses = jgrid.getRes(jgrid.guiStyles[baseGuiStyle], path);
  6270. }
  6271. }
  6272. return jgrid.mergeCssClasses(guiClasses || "", jqClasses || "");
  6273. },
  6274. isBootstrapGuiStyle: function () {
  6275. return $.inArray("ui-jqgrid-bootstrap", $(this).jqGrid("getGuiStyles", "gBox").split(" ")) >= 0;
  6276. },
  6277. displayErrorMessage: function (message) {
  6278. var $t = this instanceof $ && this.length > 0 ? this[0] : this;
  6279. if (!$t || !$t.grid || !$t.p || !message) { return; }
  6280. var $errorDiv = $($t.grid.eDiv),
  6281. $errorSpan = $errorDiv.children(".ui-jqgrid-error");
  6282. $errorSpan.html(message);
  6283. $errorDiv.show();
  6284. if ($t.p.errorDisplayTimeout) {
  6285. setTimeout(function () {
  6286. $errorSpan.empty();
  6287. $errorDiv.hide();
  6288. }, $t.p.errorDisplayTimeout);
  6289. }
  6290. },
  6291. getIconRes: function (path) {
  6292. var $t = this instanceof $ && this.length > 0 ? this[0] : this;
  6293. if (!$t || !$t.p) { return ""; }
  6294. var p = $t.p, iconSet = jgrid.icons[p.iconSet],
  6295. getIcon = function (basePath, path, alternativeRoot) {
  6296. var pathParts = path.split("."), root, n = pathParts.length, part, i, classes = [];
  6297. basePath = typeof basePath === "string" ? jgrid.icons[basePath] : basePath;
  6298. if (basePath == null) {
  6299. return ""; // error unknown iconSet
  6300. }
  6301. root = basePath;
  6302. if (root.common) {
  6303. classes.push(root.common);
  6304. } else if (alternativeRoot && alternativeRoot.common) {
  6305. classes.push(alternativeRoot.common);
  6306. }
  6307. for (i = 0; i < n; i++) {
  6308. part = pathParts[i];
  6309. if (!part) {
  6310. break;
  6311. }
  6312. if (i + 1 === n && root.ignoreParents) {
  6313. // the final level
  6314. // Verify that ignoreParents mode is set on the level
  6315. classes = []; // reset array of classes
  6316. }
  6317. root = root[part];
  6318. if (root === undefined) {
  6319. if (part === "common") { break; }
  6320. return ""; // error unknown icon path
  6321. }
  6322. if (typeof root === "string") {
  6323. classes.push(root);
  6324. break;
  6325. }
  6326. if (root != null && root.common) {
  6327. classes.push(root.common);
  6328. }
  6329. }
  6330. return jgrid.mergeCssClasses.apply(this, classes);
  6331. };
  6332. if (iconSet == null) {
  6333. return "";
  6334. }
  6335. var classes = getIcon(p.iconSet, path);
  6336. if (classes === "" && iconSet.baseIconSet != null) {
  6337. classes = getIcon(iconSet.baseIconSet, path, jgrid.icons[p.iconSet]);
  6338. }
  6339. return classes || "";
  6340. },
  6341. isInCommonIconClass: function (testClass) {
  6342. var $t = this instanceof $ && this.length > 0 ? this[0] : this;
  6343. if (!$t || !$t.p) { return ""; }
  6344. var p = $t.p, iconSet = jgrid.icons[p.iconSet];
  6345. if (iconSet == null) {
  6346. return false;
  6347. }
  6348. var commonClasses = iconSet.common;
  6349. if (commonClasses === undefined) {
  6350. if (iconSet.baseIconSet == null) {
  6351. return false;
  6352. }
  6353. iconSet = jgrid.icons[iconSet.baseIconSet];
  6354. if (iconSet == null) {
  6355. return false;
  6356. }
  6357. commonClasses = iconSet.common;
  6358. }
  6359. return typeof commonClasses === "string" && $.inArray(testClass, commonClasses.split(" ")) >= 0;
  6360. },
  6361. getUniqueValueFromColumnIndex: function (cmName) {
  6362. var $t = this[0];
  6363. if (!$t || !$t.grid) { return null; }
  6364. var uniqueTexts = [], v = "", id;
  6365. var uniqueValues = $t.p.indexByColumnData[cmName];
  6366. if (uniqueValues != null) {
  6367. for (v in uniqueValues) {
  6368. if (uniqueValues.hasOwnProperty(v)) {
  6369. for (id in uniqueValues[v]) {
  6370. if (uniqueValues[v].hasOwnProperty(id)) {
  6371. v = String(uniqueValues[v][id]); // get the value in the correct case
  6372. break;
  6373. }
  6374. }
  6375. uniqueTexts.push(v);
  6376. }
  6377. }
  6378. // sort the values
  6379. if ($t.p.ignoreCase) {
  6380. if (typeof String.prototype.localeCompare === "undefined") {
  6381. // IE10 and before
  6382. uniqueTexts.sort(function (a, b) {
  6383. var aLowCase = a.toLowerCase(),
  6384. bLowCase = b.toLowerCase();
  6385. return (aLowCase === bLowCase) ? 0 : ((aLowCase > bLowCase) ? 1 : -1);
  6386. });
  6387. } else {
  6388. uniqueTexts.sort(function (a, b) {
  6389. return String(a).toLowerCase().localeCompare(String(b).toLowerCase());
  6390. });
  6391. }
  6392. } else {
  6393. uniqueTexts.sort();
  6394. }
  6395. }
  6396. return uniqueTexts;
  6397. },
  6398. generateDatalistFromColumnIndex: function (cmName) {
  6399. if (!this[0] || !this[0].grid) { return null; }
  6400. var uniqueTexts = this.jqGrid("getUniqueValueFromColumnIndex", cmName), i, len,
  6401. $dataList = $("<datalist></datalist>");
  6402. if (uniqueTexts != null && uniqueTexts.length > 0) {
  6403. // convert to format of editoptions.value or searchoptions.value
  6404. for (i = 0, len = uniqueTexts.length; i < len; i++) {
  6405. $dataList.append($("<option></option>").attr("value", uniqueTexts[i]));
  6406. }
  6407. } else {
  6408. return $(); // return empty jQuery object
  6409. }
  6410. return $dataList;
  6411. },
  6412. getGridParam: function (pName) {
  6413. var $t = this[0];
  6414. if (!$t || !$t.grid) { return null; }
  6415. if (!pName) { return $t.p; }
  6416. return $t.p[pName] !== undefined ? $t.p[pName] : null;
  6417. },
  6418. setGridParam: function (newParams, overwrite) {
  6419. return this.each(function () {
  6420. var self = this;
  6421. if (overwrite == null) {
  6422. overwrite = false;
  6423. }
  6424. if (self.grid && typeof newParams === "object") {
  6425. if (overwrite === true) {
  6426. $.extend(self.p, newParams);
  6427. } else {
  6428. $.extend(true, self.p, newParams);
  6429. }
  6430. }
  6431. });
  6432. },
  6433. abortAjaxRequest: function () {
  6434. return this.each(function () {
  6435. var self = this;
  6436. if (self.p.jqXhr != null) {
  6437. self.p.jqXhr.abort();
  6438. }
  6439. self.grid.endReq.call(self);
  6440. });
  6441. },
  6442. getGridRowById: function (rowid) {
  6443. if (rowid == null) {
  6444. return null;
  6445. }
  6446. var row, rowId = rowid.toString();
  6447. this.each(function () {
  6448. var i, rows = this.rows, tr, rowIndex;
  6449. if (this.p.rowIndexes != null) {
  6450. rowIndex = this.p.rowIndexes[rowId];
  6451. tr = rows[rowIndex];
  6452. if (tr && tr.id === rowId) {
  6453. row = tr;
  6454. }
  6455. }
  6456. if (!row) {
  6457. try {
  6458. //row = this.rows.namedItem( rowid );
  6459. i = rows.length;
  6460. while (i--) {
  6461. tr = rows[i];
  6462. if (rowId === tr.id) {
  6463. row = tr;
  6464. break;
  6465. }
  6466. }
  6467. } catch (e) {
  6468. row = $(this.grid.bDiv).find("#" + jqID(rowid));
  6469. row = row.length > 0 ? row[0] : null;
  6470. }
  6471. }
  6472. });
  6473. return row;
  6474. },
  6475. getDataIDs: function () {
  6476. var ids = [];
  6477. this.each(function () {
  6478. var rows = this.rows, len = rows.length, i, tr;
  6479. if (len && len > 0) {
  6480. for (i = 0; i < len; i++) {
  6481. tr = rows[i];
  6482. if ($(tr).hasClass("jqgrow")) {
  6483. ids.push(tr.id);
  6484. }
  6485. }
  6486. }
  6487. });
  6488. return ids;
  6489. },
  6490. /*selectDeselectRow: function (tr, toSelect, notUpdateParam) {
  6491. return this.each(function () {
  6492. var $t = this, p = $t.p, rowId = tr.id, iSel, getGuiStyles = base.getGuiStyles,
  6493. highlightClass = getGuiStyles.call($($t), "states.select"), frozenRows,
  6494. selectUnselectRow = function (tr1, toSelect) {
  6495. var method = toSelect ? "addClass" : "removeClass", iColCb = p.iColByName.cb,
  6496. attributes = toSelect ?
  6497. { "aria-selected": "true", tabindex: "0" } :
  6498. { "aria-selected": "false", tabindex: "-1" },
  6499. selectUnselectRowInTable = function (tr) {
  6500. $(tr)[method](highlightClass).attr(attributes);
  6501. if (iColCb !== undefined) { // p.multiselect or p.multiselectCheckboxes
  6502. $(tr.cells[iColCb]).children("input.cbox").prop("checked", toSelect);
  6503. }
  6504. };
  6505. selectUnselectRowInTable(tr1);
  6506. if (frozenRows) {
  6507. selectUnselectRowInTable(frozenRows[tr1.rowIndex]);
  6508. }
  6509. };
  6510. if (!$t.grid || !p || rowId === "") { return; }
  6511. frozenRows = $t.grid.fbRows;
  6512. selectUnselectRow(tr, toSelect);
  6513. if (!notUpdateParam) {
  6514. iSel = $.inArray(rowId, p.selarrrow);
  6515. if (iSel < 0 && toSelect) {
  6516. // select
  6517. p.selarrrow.push(rowId);
  6518. p.selrow = rowId;
  6519. } else if (iSel >= 0 && !toSelect) {
  6520. // deselect
  6521. p.selarrrow.splice(iSel, 1); // remove from array
  6522. p.selrow = p.selarrrow.length >= 0 ? p.selarrrow[0] : null;
  6523. }
  6524. }
  6525. });
  6526. },*/
  6527. setSelection: function (selection, onsr, e) {
  6528. return this.each(function () {
  6529. var $t = this, $self = $($t), p = $t.p, stat, pt, ner, ia, tpsr, csr, $tr, editingInfo,
  6530. getGuiStyles = base.getGuiStyles, getGridRowById = base.getGridRowById,
  6531. highlightClass = getGuiStyles.call($self, "states.select"),
  6532. disabledClasses = getGuiStyles.call($self, "states.disabled"),
  6533. frozenRows = $t.grid.fbRows,
  6534. selectUnselectRow = function (tr1, toSelect) {
  6535. var method = toSelect ? "addClass" : "removeClass", iColCb = p.iColByName.cb,
  6536. attributes = toSelect ?
  6537. { "aria-selected": "true", tabindex: "0" } :
  6538. { "aria-selected": "false", tabindex: "-1" },
  6539. selectUnselectRowInTable = function (tr) {
  6540. $(tr)[method](highlightClass).attr(attributes);
  6541. if (iColCb !== undefined) { // p.multiselect or p.multiselectCheckboxes
  6542. $(tr.cells[iColCb]).children("input.cbox").prop("checked", toSelect);
  6543. }
  6544. };
  6545. selectUnselectRowInTable(tr1);
  6546. if (frozenRows) {
  6547. selectUnselectRowInTable(frozenRows[tr1.rowIndex]);
  6548. }
  6549. };
  6550. if (selection === undefined) { return; }
  6551. onsr = onsr === false ? false : true;
  6552. if (e != null) {
  6553. // try to get tr from e.target
  6554. $tr = $(e.target).closest("tr.jqgrow");
  6555. if ($tr.length > 0) {
  6556. pt = $tr[0];
  6557. if (frozenRows/* && !$.contains($t, pt)*/) {
  6558. // The event could be inside of frozen div.
  6559. // Thus tr could be the same as trFrozen (frozenRows[pt.rowIndex])
  6560. // We normalize it based on the rowIndex.
  6561. pt = $t.rows[pt.rowIndex];
  6562. }
  6563. }
  6564. }
  6565. if (pt == null) {
  6566. pt = getGridRowById.call($self, selection);
  6567. }
  6568. if (!pt || !pt.className || pt.className.indexOf(disabledClasses) > -1) { return; }
  6569. function scrGrid(tr, bDiv) {
  6570. var ch = bDiv.clientHeight,
  6571. st = bDiv.scrollTop,
  6572. rpos = $(tr).position().top,
  6573. rh = tr.clientHeight;
  6574. if (rpos + rh >= ch + st) {
  6575. bDiv.scrollTop = rpos - (ch + st) + rh + st;
  6576. } else if (rpos < ch + st) {
  6577. if (rpos < st) {
  6578. bDiv.scrollTop = rpos;
  6579. }
  6580. }
  6581. }
  6582. if (p.scrollrows === true) {
  6583. ner = getGridRowById.call($self, selection);
  6584. if (ner != null) {
  6585. ner = ner.rowIndex;
  6586. if (ner >= 0) {
  6587. scrGrid($t.rows[ner], $t.grid.bDiv);
  6588. }
  6589. }
  6590. }
  6591. if (!p.multiselect) {
  6592. if (pt.className !== "ui-subgrid") {
  6593. if (p.selrow !== pt.id) {
  6594. if (p.selrow !== null) {
  6595. csr = getGridRowById.call($self, p.selrow);
  6596. if (csr) {
  6597. selectUnselectRow(csr, false);
  6598. }
  6599. }
  6600. selectUnselectRow(pt, true);
  6601. stat = true;
  6602. } else {
  6603. stat = false;
  6604. }
  6605. p.selrow = pt.id;
  6606. if (onsr) {
  6607. feedback.call($t, "onSelectRow", pt.id, stat, e || {});
  6608. }
  6609. }
  6610. } else {
  6611. //unselect selectall checkbox when deselecting a specific row
  6612. $t.setHeadCheckBox(false);
  6613. p.selrow = pt.id;
  6614. editingInfo = jgrid.detectRowEditing.call($t, pt.id);
  6615. ia = $.inArray(p.selrow, p.selarrrow);
  6616. if (ia === -1) {
  6617. stat = true;
  6618. p.selarrrow.push(p.selrow);
  6619. } else if (editingInfo !== null && (editingInfo.mode === "inlineEditing" || !$(e.target).hasClass("cbox"))) {
  6620. // the row is editing and selected now. The checkbox is clicked
  6621. stat = true; // set to force the checkbox stay selected
  6622. } else {
  6623. // deselect only if the row is not in editing mode
  6624. stat = false;
  6625. p.selarrrow.splice(ia, 1);
  6626. tpsr = p.selarrrow[0];
  6627. p.selrow = (tpsr === undefined) ? null : tpsr;
  6628. }
  6629. if (pt.className !== "ui-subgrid") {
  6630. selectUnselectRow(pt, stat);
  6631. }
  6632. if (onsr) {
  6633. feedback.call($t, "onSelectRow", pt.id, stat, e || {});
  6634. }
  6635. }
  6636. });
  6637. },
  6638. resetSelection: function (rowid) {
  6639. return this.each(function () {
  6640. var $t = this, $self = $(this), p = $t.p, row,
  6641. getGuiStyles = base.getGuiStyles, getGridRowById = base.getGridRowById,
  6642. highlightClass = getGuiStyles.call($self, "states.select"), //"ui-state-highlight"
  6643. cellEditCellHighlightClasses = "edit-cell " + highlightClass,
  6644. cellEditRowHighlightClasses = "selected-row " + getGuiStyles.call($self, "states.hover"),
  6645. iColCb = p.iColByName.cb,
  6646. multiselectChechboxes = iColCb !== undefined,
  6647. frozenRows = $t.grid.fbRows,
  6648. deselectRow = function (tr) {
  6649. var method = "removeClass", frozenRow,
  6650. attributes = { "aria-selected": "false", tabindex: "-1" };
  6651. $(tr)[method](highlightClass).attr(attributes);
  6652. if (multiselectChechboxes) { // p.multiselect or p.multiselectCheckboxes
  6653. $(tr.cells[iColCb]).children("input.cbox").prop("checked", false);
  6654. }
  6655. if (frozenRows) {
  6656. frozenRow = frozenRows[tr.rowIndex];
  6657. $(frozenRow)[method](highlightClass).attr(attributes);
  6658. if (multiselectChechboxes) { // p.multiselect or p.multiselectCheckboxes
  6659. $(frozenRow.cells[iColCb]).children("input.cbox").prop("checked", false);
  6660. }
  6661. }
  6662. };
  6663. if (rowid !== undefined) {
  6664. row = getGridRowById.call($self, rowid);
  6665. deselectRow(row);
  6666. if (multiselectChechboxes) {
  6667. $t.setHeadCheckBox(false);
  6668. var ia = $.inArray(rowid, p.selarrrow);
  6669. if (ia !== -1) {
  6670. p.selarrrow.splice(ia, 1);
  6671. }
  6672. }
  6673. } else if (!p.multiselect) {
  6674. if (p.selrow) {
  6675. row = getGridRowById.call($self, p.selrow);
  6676. deselectRow(row);
  6677. p.selrow = null;
  6678. }
  6679. } else {
  6680. $($t.rows).each(function () {
  6681. var iSel = $.inArray(this.id, p.selarrrow);
  6682. if (iSel !== -1) {
  6683. deselectRow(this);
  6684. p.selarrrow.splice(iSel, 1);
  6685. }
  6686. });
  6687. $t.setHeadCheckBox(false);
  6688. if (!p.multiPageSelection) {
  6689. clearArray(p.selarrrow); // p.selarrrow = [];
  6690. }
  6691. p.selrow = null;
  6692. }
  6693. if (p.cellEdit === true) {
  6694. if (parseInt(p.iCol, 10) >= 0 && parseInt(p.iRow, 10) >= 0) {
  6695. row = $t.rows[p.iRow];
  6696. if (row != null) {
  6697. $(row.cells[p.iCol]).removeClass(cellEditCellHighlightClasses);
  6698. $(row).removeClass(cellEditRowHighlightClasses);
  6699. }
  6700. if (frozenRows) {
  6701. row = frozenRows[p.iRow];
  6702. if (row != null) {
  6703. $(row.cells[p.iCol]).removeClass(cellEditCellHighlightClasses);
  6704. $(row).removeClass(cellEditRowHighlightClasses);
  6705. }
  6706. }
  6707. }
  6708. }
  6709. //clearArray(p.savedRow); // p.savedRow = [];
  6710. //p.editingInfo = {};
  6711. });
  6712. },
  6713. isCellEditing: function (rowid, iCol, trDom) {
  6714. var $t = this[0], editingInfo = jgrid.detectRowEditing.call($t, rowid);
  6715. if (editingInfo != null &&
  6716. ((editingInfo.mode === "inlineEditing") ||
  6717. (editingInfo.mode === "cellEditing" && editingInfo.savedRow.ic === iCol))) {
  6718. iCol = isNaN(iCol) ? $t.p.iColByName[iCol] : parseInt(iCol, 10);
  6719. var tr = trDom != null && trDom.id === rowid ?
  6720. trDom :
  6721. base.getGridRowById.call($($t), rowid),
  6722. cm = $t.p.colModel[iCol],
  6723. isEditable = cm.editable;
  6724. if ($.isFunction(isEditable)) {
  6725. isEditable = isEditable.call($t, {
  6726. rowid: rowid,
  6727. id: stripPref($t.p.idPrefix, rowid),
  6728. iCol: iCol,
  6729. iRow: tr.rowIndex,
  6730. cmName: cm.name,
  6731. cm: cm,
  6732. mode: editingInfo.mode,
  6733. td: tr.cells[iCol],
  6734. tr: tr,
  6735. dataElement: jgrid.getDataFieldOfCell.call($t, tr, iCol)[0]
  6736. });
  6737. }
  6738. if (isEditable === true) {
  6739. return true;
  6740. }
  6741. }
  6742. return false;
  6743. },
  6744. getRowData: function (rowid, options) {
  6745. // TODO: add additional parameter, which will inform whether the output data need be in formatted or unformatted form
  6746. var res = {}, resall;
  6747. if (typeof rowid === "object") {
  6748. options = rowid;
  6749. rowid = undefined;
  6750. }
  6751. options = options || {};
  6752. this.each(function () {
  6753. var $t = this, p = $t.p, getall = false, tr, len = 1, j, rows = $t.rows, i, $td, cm, nm, td, editingInfo;
  6754. if (rowid === undefined) {
  6755. getall = true;
  6756. resall = [];
  6757. len = rows.length;
  6758. } else {
  6759. tr = base.getGridRowById.call($($t), rowid);
  6760. if (!tr) { return res; }
  6761. }
  6762. for (j = 0; j < len; j++) {
  6763. if (getall) { tr = rows[j]; }
  6764. if ($(tr).hasClass("jqgrow")) {
  6765. editingInfo = jgrid.detectRowEditing.call($t, rowid);
  6766. $td = $(tr).find("td[role=gridcell]");
  6767. for (i = 0; i < $td.length; i++) {
  6768. cm = p.colModel[i];
  6769. nm = cm.name;
  6770. if ($.inArray(nm, p.reservedColumnNames) < 0 && cm.formatter !== "actions" && (!options.skipHidden || !cm.hidden)) {
  6771. td = $td[i];
  6772. if (base.isCellEditing.call($($t), rowid, i, tr)) {
  6773. res[nm] = jgrid.getEditedValue.call($t, jgrid.getDataFieldOfCell.call($t, tr, i), cm, {}, cm.editable);
  6774. } else if (p.treeGrid === true && nm === p.ExpandColumn) {
  6775. res[nm] = htmlDecode($("span", td).first().html());
  6776. } else {
  6777. try {
  6778. res[nm] = $.unformat.call($t, td, { rowId: rowid, colModel: cm }, i);
  6779. } catch (exception) {
  6780. res[nm] = htmlDecode($(td).html());
  6781. }
  6782. }
  6783. }
  6784. }
  6785. if (options.includeId && (p.keyName === false || res[p.keyName] == null)) {
  6786. res[p.prmNames.id] = stripPref(p.idPrefix, tr.id);
  6787. }
  6788. if (getall) {
  6789. resall.push(res);
  6790. res = {};
  6791. }
  6792. }
  6793. }
  6794. });
  6795. return resall || res;
  6796. },
  6797. delRowData: function (rowid) {
  6798. var success = false;
  6799. this.each(function () {
  6800. var $t = this, p = $t.p, editingInfo = $.jgrid.detectRowEditing.call($t, rowid), rowInd, ia, nextRow;
  6801. rowInd = base.getGridRowById.call($($t), rowid);
  6802. if (!rowInd) { return false; }
  6803. if (p.subGrid) {
  6804. nextRow = $(rowInd).next();
  6805. if (nextRow.hasClass("ui-subgrid")) {
  6806. nextRow.remove();
  6807. }
  6808. }
  6809. if (editingInfo != null) {
  6810. try {
  6811. if (editingInfo.mode === "inlineEditing" && base.restoreRow != null) {
  6812. base.restoreRow.call($($t), rowid);
  6813. } else if (editingInfo.mode === "cellEditing" && base.restoreCell != null) {
  6814. base.restoreCell.call($($t), editingInfo.savedRow.id, editingInfo.savedRow.ic);
  6815. }
  6816. } catch (ignore) { }
  6817. }
  6818. if (rowInd.rowIndex === p.iRow) { // delete row with selected/edited cell
  6819. // reset cell editing parameters in case of selected cells, but not editing
  6820. p.iRow = -1;
  6821. p.iCol = -1;
  6822. }
  6823. $(rowInd).remove();
  6824. p.records--;
  6825. p.reccount--;
  6826. $t.updatepager(true, false);
  6827. success = true;
  6828. if (p.multiselect) {
  6829. ia = $.inArray(rowid, p.selarrrow);
  6830. if (ia !== -1) { p.selarrrow.splice(ia, 1); }
  6831. }
  6832. if (p.multiselect && p.selarrrow.length > 0) {
  6833. p.selrow = p.selarrrow[p.selarrrow.length - 1];
  6834. } else if (p.selrow === rowid) {
  6835. p.selrow = null;
  6836. }
  6837. if (p.datatype === "local") {
  6838. var id = stripPref(p.idPrefix, rowid),
  6839. pos = p._index[id];
  6840. if (pos !== undefined) {
  6841. $t.removeItemDataFromColumnIndex(id);
  6842. p.data.splice(pos, 1);
  6843. $t.refreshIndex(); // ??? it could be less expansive
  6844. }
  6845. }
  6846. $t.rebuildRowIndexes();
  6847. if (p.altRows === true && success && !$($t).jqGrid("isBootstrapGuiStyle")) {
  6848. var cn = p.altclass, frozenRows = $t.grid.fbRows;
  6849. $($t.rows).each(function (i) {
  6850. var $row = $(this);
  6851. if (frozenRows) {
  6852. $row = $row.add(frozenRows[this.rowIndex]);
  6853. }
  6854. $row[i % 2 === 0 ? "addClass" : "removeClass"](cn);
  6855. });
  6856. }
  6857. feedback.call($t, "afterDelRow", rowid);
  6858. });
  6859. return success;
  6860. },
  6861. setRowData: function (rowid, data, cssp) {
  6862. // TODO: add additional parameter to setRowData which inform that input data is in formatted or unformatted form
  6863. var success = true;
  6864. this.each(function () {
  6865. var t = this, p = t.p, ind, cp = typeof cssp, lcdata = {};
  6866. if (!t.grid) { return false; }
  6867. ind = base.getGridRowById.call($(t), rowid);
  6868. if (!ind) { return false; }
  6869. if (data) {
  6870. try {
  6871. var id = stripPref(p.idPrefix, rowid), key, pos = p._index[id], newData = {},
  6872. oData = pos != null ? p.data[pos] : undefined;
  6873. $(p.colModel).each(function (i) {
  6874. var cm = this, nm = cm.name, vl = getAccessor(data, nm);
  6875. if (vl !== undefined) {
  6876. if (p.datatype === "local" && oData != null) {
  6877. vl = convertOnSaveLocally.call(t, vl, cm, oData[nm], id, oData, i);
  6878. if ($.isFunction(cm.saveLocally)) {
  6879. cm.saveLocally.call(t, { newValue: vl, newItem: lcdata, oldItem: oData, id: id, cm: cm, cmName: nm, iCol: i });
  6880. } else {
  6881. lcdata[nm] = vl;
  6882. }
  6883. }
  6884. newData[nm] = vl;
  6885. }
  6886. });
  6887. $(p.colModel).each(function (i) {
  6888. var cm = this, nm = cm.name, title, vl = getAccessor(data, nm), $td = $(ind.cells[i]);
  6889. if (vl !== undefined) {
  6890. if (p.datatype === "local" && oData != null) {
  6891. vl = lcdata[nm];
  6892. }
  6893. title = cm.title ? { "title": vl } : {};
  6894. vl = t.formatter(rowid, vl, i, data, "edit", newData);
  6895. if (cm.formatter === "select") {
  6896. title = cm.title ? { "title": stripHtml(vl) } : {};
  6897. }
  6898. var $dataFiled = $td;
  6899. if (p.treeGrid === true && nm === p.ExpandColumn) {
  6900. $dataFiled = $dataFiled.children("span.cell-wrapperleaf,span.cell-wrapper").first();
  6901. }
  6902. $dataFiled.html(vl);
  6903. $td.attr(title);
  6904. if (p.frozenColumns) {
  6905. $dataFiled = $(t.grid.fbRows[ind.rowIndex].cells[i]);
  6906. if (p.treeGrid === true && nm === p.ExpandColumn) {
  6907. $dataFiled = $dataFiled.children("span.cell-wrapperleaf,span.cell-wrapper").first();
  6908. }
  6909. $dataFiled.html(vl).attr(title);
  6910. }
  6911. }
  6912. });
  6913. if (p.datatype === "local") {
  6914. if (p.treeGrid) {
  6915. for (key in p.treeReader) {
  6916. if (p.treeReader.hasOwnProperty(key)) {
  6917. delete lcdata[p.treeReader[key]];
  6918. }
  6919. }
  6920. }
  6921. if (oData !== undefined) {
  6922. // !!!!
  6923. p.data[pos] = $.extend(true, oData, lcdata);
  6924. t.removeItemDataFromColumnIndex(id);
  6925. t.addItemDataToColumnIndex(p.data[pos], id);
  6926. }
  6927. }
  6928. feedback.call(t, "afterSetRow", {
  6929. rowid: rowid,
  6930. inputData: data,
  6931. iData: pos,
  6932. iRow: ind.rowIndex,
  6933. tr: ind,
  6934. localData: lcdata,
  6935. cssProp: cssp
  6936. });
  6937. } catch (exception) {
  6938. success = false;
  6939. }
  6940. }
  6941. if (success) {
  6942. if (cp === "string") { $(ind).addClass(cssp); } else if (cssp !== null && cp === "object") { $(ind).css(cssp); }
  6943. //$(t).triggerHandler("jqGridAfterGridComplete");
  6944. }
  6945. });
  6946. return success;
  6947. },
  6948. changeRowid: function (oldRowId, newRowId) {
  6949. return this.each(function () {
  6950. var ts = this, $self = $(ts), p = ts.p, localData, i, newCboxId, tr, $tr, cm, value;
  6951. if (!ts.grid || !p || oldRowId === newRowId) { return; }
  6952. tr = $self.jqGrid("getGridRowById", oldRowId);
  6953. if (!tr || $self.jqGrid("getGridRowById", newRowId) != null) {
  6954. // consider to throw an exception or displaying an error in some way
  6955. return;
  6956. }
  6957. var oldId = jgrid.stripPref(p.idPrefix, oldRowId),
  6958. newId = jgrid.stripPref(p.idPrefix, newRowId),
  6959. idname = p.keyName === false ? p.prmNames.id : p.keyName,
  6960. fixRowid = function () {
  6961. var id = this.id, lengthDiff = id.length - oldId.length;
  6962. if (lengthDiff > 0 && id.substr(lengthDiff) === oldId) {
  6963. $(this).attr("id", id.substr(0, lengthDiff) + newId);
  6964. }
  6965. };
  6966. if (p.iColByName[idname] >= 0) {
  6967. $self.jqGrid("setCell", oldRowId, idname, newId);
  6968. }
  6969. if (p.datatype === "local" && p._index[oldId] !== undefined) {
  6970. p._index[newId] = p._index[oldId];
  6971. localData = p.data[p._index[oldId]];
  6972. delete p._index[oldId];
  6973. if (localData.hasOwnProperty(idname)) {
  6974. localData[idname] = newId;
  6975. }
  6976. }
  6977. // fix rowIndexes used inside of getGridRowById
  6978. p.rowIndexes[newRowId] = tr.rowIndex;
  6979. delete p.rowIndexes[oldRowId];
  6980. $tr = ts.grid.fbRows == null ?
  6981. $(tr) :
  6982. $(tr).add(ts.grid.fbRows[tr.rowIndex]);
  6983. $tr.attr("id", newRowId);
  6984. if (p.selrow === oldRowId) {
  6985. p.selrow = newRowId;
  6986. }
  6987. if ($.isArray(p.selarrrow)) {
  6988. i = $.inArray(oldRowId, p.selarrrow);
  6989. if (i >= 0) {
  6990. p.selarrrow[i] = newRowId;
  6991. }
  6992. }
  6993. if (p.multiselect) {
  6994. newCboxId = "jqg_" + p.id + "_" + newRowId;
  6995. $tr.find("input.cbox")
  6996. .attr("id", newCboxId)
  6997. .attr("name", newCboxId);
  6998. }
  6999. // fix ids of all column with formatters actions and probably showlink
  7000. for (i = 0; i < p.colModel.length; i++) {
  7001. cm = p.colModel[i];
  7002. if (cm.formatter === "actions") {
  7003. $tr.find(".ui-jqgrid-actions .ui-pg-div")
  7004. .each(fixRowid);
  7005. } else if (cm.formatter === "showlink" || (cm.unformat != null && cm.formatter != null)) {
  7006. // resetting the same value in the cell will reformat the cell
  7007. // with new rowid getCell uses unformat and setCell uses unformat
  7008. value = $self.jqGrid("getCell", newRowId, i);
  7009. $self.jqGrid("setCell", newRowId, i, value, false, false, true);
  7010. }
  7011. }
  7012. feedback.call(ts, "afterChangeRowid", {
  7013. rowid: newRowId,
  7014. oldRowid: oldRowId,
  7015. iRow: tr.rowIndex,
  7016. tr: tr
  7017. });
  7018. });
  7019. },
  7020. addRowData: function (rowid, rdata, pos, src) {
  7021. // TODO: add an additional parameter, which will inform whether the input data rdata is in formatted or unformatted form
  7022. if ($.inArray(pos, ["first", "last", "before", "after", "afterSelected", "beforeSelected"]) < 0) { pos = "last"; }
  7023. var success = false, nm, row, sind, i, v, aradd, cnm, cn, data, cm, id;
  7024. if (rdata) {
  7025. if ($.isArray(rdata)) {
  7026. aradd = true;
  7027. //pos = "last";
  7028. cnm = rowid;
  7029. } else {
  7030. rdata = [rdata];
  7031. aradd = false;
  7032. }
  7033. this.each(function () {
  7034. var t = this, p = t.p, datalen = rdata.length, $self = $(t), rows = t.rows, k = 0,
  7035. getGridRowById = base.getGridRowById, colModel = p.colModel, lcdata,
  7036. additionalProperties = p.additionalProperties, grouping;
  7037. if (!aradd) {
  7038. if (rowid !== undefined) {
  7039. rowid = String(rowid);
  7040. } else {
  7041. rowid = randId();
  7042. if (p.keyName !== false) {
  7043. cnm = p.keyName;
  7044. if (rdata[0][cnm] !== undefined) { rowid = rdata[0][cnm]; }
  7045. }
  7046. }
  7047. }
  7048. cn = p.altclass;
  7049. // TODO: call jgrid.parseDataToHtml once with ALL data,
  7050. // TODO: set correct the altrow classes inside of jgrid.parseDataToHtml (use params)
  7051. while (k < datalen) {
  7052. data = rdata[k];
  7053. row = [];
  7054. if (aradd) {
  7055. try {
  7056. rowid = data[cnm];
  7057. if (rowid === undefined) {
  7058. rowid = randId();
  7059. }
  7060. } catch (exception) { rowid = randId(); }
  7061. //cna = p.altRows === true ? (rows.length - 1) % 2 === 0 ? cn : "" : "";
  7062. }
  7063. id = jgrid.stripPref(p.idPrefix, rowid);
  7064. lcdata = {};
  7065. for (i = 0; i < colModel.length; i++) {
  7066. cm = colModel[i];
  7067. nm = cm.name;
  7068. if (nm !== "rn" && nm !== "cb" && nm !== "subgrid") {
  7069. v = convertOnSaveLocally.call(t, getAccessor(data, nm), cm, undefined, id, {}, i);
  7070. if ($.isFunction(cm.saveLocally)) {
  7071. cm.saveLocally.call(t, { newValue: v, newItem: lcdata, oldItem: {}, id: id, rowid: rowid, cm: cm, cmName: nm, iCol: i });
  7072. } else if (v !== undefined) {
  7073. lcdata[nm] = v;
  7074. }
  7075. }
  7076. }
  7077. for (i = 0; i < additionalProperties.length; i++) {
  7078. nm = additionalProperties[i];
  7079. if (typeof nm === "object" && nm.hasOwnProperty("name")) {
  7080. nm = nm.name;
  7081. }
  7082. v = getAccessor(data, nm);
  7083. if (v !== undefined) {
  7084. lcdata[nm] = v;
  7085. }
  7086. }
  7087. if (p.datatype === "local") {
  7088. lcdata[p.localReader.id] = id;
  7089. p._index[id] = p.data.length;
  7090. p.data.push(lcdata);
  7091. t.addItemDataToColumnIndex(lcdata, id);
  7092. }
  7093. grouping = p.grouping;
  7094. p.grouping = false; // workaround for adding row in the grid with grouping data
  7095. row = jgrid.parseDataToHtml.call(t, 1, [rowid], [lcdata]);
  7096. p.grouping = grouping;
  7097. row = row.join("");
  7098. if (rows.length === 0) {
  7099. $(t.tBodies[0]).append(row);
  7100. } else {
  7101. if (pos === "afterSelected" || pos === "beforeSelected") {
  7102. if (src === undefined && p.selrow !== null) {
  7103. src = p.selrow;
  7104. pos = (pos === "afterSelected") ? "after" : "before";
  7105. } else {
  7106. pos = (pos === "afterSelected") ? "last" : "first";
  7107. }
  7108. }
  7109. switch (pos) {
  7110. case "last":
  7111. $(rows[rows.length - 1]).after(row);
  7112. sind = rows.length - 1;
  7113. break;
  7114. case "first":
  7115. $(rows[0]).after(row);
  7116. sind = 1;
  7117. break;
  7118. case "after":
  7119. sind = getGridRowById.call($self, src);
  7120. if (sind) {
  7121. if ($(rows[sind.rowIndex + 1]).hasClass("ui-subgrid")) {
  7122. $(rows[sind.rowIndex + 1]).after(row);
  7123. sind = sind.rowIndex + 2;
  7124. } else {
  7125. $(sind).after(row);
  7126. sind = sind.rowIndex + 1;
  7127. }
  7128. }
  7129. break;
  7130. case "before":
  7131. sind = getGridRowById.call($self, src);
  7132. if (sind) {
  7133. $(sind).before(row);
  7134. sind = sind.rowIndex - 1;
  7135. }
  7136. break;
  7137. }
  7138. }
  7139. if (p.subGrid === true) {
  7140. base.addSubGrid.call($self, p.iColByName.subgrid, sind);
  7141. }
  7142. p.records++;
  7143. p.reccount++;
  7144. if (p.lastpage === 0) {
  7145. p.lastpage = 1;
  7146. }
  7147. feedback.call(t, "afterAddRow", {
  7148. rowid: rowid,
  7149. inputData: rdata,
  7150. position: pos,
  7151. srcRowid: src,
  7152. iRow: sind,
  7153. tr: rows[sind],
  7154. localData: lcdata,
  7155. iData: p.data.length - 1
  7156. });
  7157. k++;
  7158. }
  7159. if (p.altRows === true && !aradd && !$self.jqGrid("isBootstrapGuiStyle")) {
  7160. // even in case of usage correct parameter for parseDataToHtml
  7161. // one will need to reset the classes if the row will be inserted not at the end of jqGrid
  7162. if (pos === "last") {
  7163. if ((rows.length - 1) % 2 === 0) { $(rows[rows.length - 1]).addClass(cn); }
  7164. } else {
  7165. $(rows).each(function (iRow) {
  7166. if (iRow % 2 === 1) {
  7167. $(this).addClass(cn);
  7168. } else {
  7169. $(this).removeClass(cn);
  7170. }
  7171. });
  7172. }
  7173. }
  7174. t.rebuildRowIndexes(); // we can remove the call later if pos==="last"
  7175. t.updatepager(true, true);
  7176. success = true;
  7177. });
  7178. }
  7179. return success;
  7180. },
  7181. footerData: function (action, data, format) {
  7182. // TODO: add an additional parameter, which will inform whether the input data "data" is in formatted or unformatted form
  7183. var success = false, res = {};
  7184. function isEmpty(obj) {
  7185. var i;
  7186. for (i in obj) {
  7187. if (obj.hasOwnProperty(i)) { return false; }
  7188. }
  7189. return true;
  7190. }
  7191. if (action == null) { action = "get"; }
  7192. if (typeof format !== "boolean") { format = true; }
  7193. action = action.toLowerCase();
  7194. this.each(function () {
  7195. var t = this, p = t.p, vl, $td, nm, iCol;
  7196. if (!t.grid || !p.footerrow) { return false; }
  7197. if (action === "set" && isEmpty(data)) { return false; }
  7198. success = true;
  7199. var ftable = $(t.grid.sDiv)
  7200. .children(".ui-jqgrid-hbox" + (p.direction === "rtl" ? "-rtl" : ""))
  7201. .children(".ui-jqgrid-ftable")[0];
  7202. if (ftable == null || ftable.rows == null) { return false; }
  7203. var cells = ftable.rows[0].cells, colModel = p.colModel,
  7204. fcells = t.grid.fsDiv == null ? {} : t.grid.fsDiv.children(".ui-jqgrid-ftable")[0].rows[0].cells;
  7205. if (action === "get") {
  7206. for (iCol = 0; iCol < colModel.length; iCol++) {
  7207. nm = colModel[iCol].name;
  7208. if ($.inArray(nm, p.reservedColumnNames) < 0) {
  7209. if (data !== false) {
  7210. vl = $(cells[iCol]).text();
  7211. if ($.trim(vl)) {
  7212. res[nm] = vl;
  7213. }
  7214. } else {
  7215. res[nm] = $(cells[iCol]).html();
  7216. }
  7217. }
  7218. }
  7219. } else if (action === "set") {
  7220. for (nm in data) {
  7221. iCol = p.iColByName[nm];
  7222. if (data.hasOwnProperty(nm) && iCol !== undefined) {
  7223. vl = format ? t.formatter("", data[nm], iCol, data, "edit") : data[nm];
  7224. $td = $(cells[iCol]).add(fcells[iCol]);
  7225. $td.html(vl);
  7226. if (colModel[iCol].title) {
  7227. $td.attr({ "title": stripHtml(vl) });
  7228. }
  7229. }
  7230. }
  7231. }
  7232. });
  7233. return action === "get" ? res : success;
  7234. },
  7235. resetColumnResizerHeight: function () {
  7236. return this.each(function () {
  7237. if ($.jgrid.msie) {
  7238. // IE don't calculate height: 100%; in the CSS rule
  7239. // .ui-jqgrid .ui-jqgrid-labels > .ui-th-column > .ui-jqgrid-resize { ... }
  7240. // One have to set the height of the span.ui-jqgrid-resize explicitly
  7241. // to the height of the row/th
  7242. var $th, $resizer, i, headers = this.grid.headers, headerHeight;
  7243. for (i = 0; i < headers.length; i++) {
  7244. $th = $(headers[i].el);
  7245. headerHeight = $th.height();
  7246. if (headerHeight) {
  7247. $resizer = $th.children(".ui-jqgrid-resize");
  7248. if ($resizer.length > 0 && Math.abs(headerHeight - $resizer.height()) > 0.5) {
  7249. $th.children(".ui-jqgrid-resize").height(headerHeight);
  7250. }
  7251. }
  7252. }
  7253. }
  7254. });
  7255. },
  7256. rotateColumnHeaders: function (columnNameOrIndexes, headerHeight) {
  7257. return this.each(function () {
  7258. // TODO: reorder columns via drag&drop
  7259. var $self = $(this), p = this.p, i, iCol, th, $th, thHeight, columnNameOrIndex,
  7260. $thDiv, $inconsDiv, $textWrapper, $sortOrder, widthIcon, widthText,
  7261. thPaddingLeft, thPaddingRight, thPaddingTop, thPaddingBottom,
  7262. nColFrozen = p.frozenColumns && $.isFunction(base.getNumberOfFrozenColumns) ? $self.jqGrid("getNumberOfFrozenColumns") : 0,
  7263. removeInconsDiv = function () {
  7264. $inconsDiv.detach();
  7265. /*$inconsDiv.each(function () {
  7266. this.parentNode.removeChild(this);
  7267. });*/
  7268. $sortOrder.detach();
  7269. /*$sortOrder.each(function () {
  7270. this.parentNode.removeChild(this);
  7271. });*/
  7272. },
  7273. appendInconsDiv = function () {
  7274. $thDiv.each(function (index) {
  7275. if (index < $inconsDiv.length) {
  7276. $(this).append($inconsDiv[index]);
  7277. }
  7278. if (index < $sortOrder.length) {
  7279. $(this).append($sortOrder[index]);
  7280. }
  7281. });
  7282. };
  7283. if (!$.isArray(columnNameOrIndexes)) {
  7284. columnNameOrIndexes = [columnNameOrIndexes];
  7285. }
  7286. for (i = 0; i < columnNameOrIndexes.length; i++) {
  7287. columnNameOrIndex = columnNameOrIndexes[i];
  7288. iCol = isNaN(columnNameOrIndex) ?
  7289. p.iColByName[columnNameOrIndex] :
  7290. parseInt(columnNameOrIndex, 10);
  7291. if (iCol >= 0) {
  7292. th = this.grid.headers[iCol].el;
  7293. $th = iCol < nColFrozen ?
  7294. $(th).add($(this.grid.fhDiv.find("#" + jqID(th.id)))) :
  7295. $(th);
  7296. $thDiv = $th.children("div");
  7297. $inconsDiv = $thDiv.children("span.s-ico");
  7298. $sortOrder = $thDiv.children("span.ui-jqgrid-sort-order");
  7299. $textWrapper = $thDiv.children("span." + p.autoResizing.wrapperClassName);
  7300. if ($textWrapper.length < 1) {
  7301. removeInconsDiv();
  7302. $thDiv.wrapInner("<span class='" + p.autoResizing.wrapperClassName + "'></span>");
  7303. $textWrapper = $thDiv.children("span." + p.autoResizing.wrapperClassName);
  7304. appendInconsDiv();
  7305. }
  7306. widthIcon = $inconsDiv.outerWidth(true);
  7307. widthText = $textWrapper.outerWidth();
  7308. thPaddingTop = parseFloat($th.css("padding-top") || 0);
  7309. thPaddingBottom = parseFloat($th.css("padding-bottom") || 0);
  7310. thPaddingLeft = parseFloat($th.css("padding-left") || 0);
  7311. thPaddingRight = parseFloat($th.css("padding-right") || 0);
  7312. if (p.showSortOrder) {
  7313. widthIcon += widthIcon * 0.5; // one can improve the calculation later !!!
  7314. }
  7315. thHeight = headerHeight === undefined || headerHeight === 0 ?
  7316. widthText + widthIcon + thPaddingLeft + thPaddingRight :
  7317. headerHeight;
  7318. $th.height(thHeight);
  7319. $th.css({
  7320. paddingTop: thPaddingRight + "px",
  7321. paddingBottom: thPaddingLeft + "px",
  7322. paddingLeft: thPaddingTop + "px",
  7323. paddingRight: thPaddingBottom + "px"
  7324. });
  7325. //thHeight = Math.max($th.parent().height(), thHeight);
  7326. // we must set width of column header div BEFOR adding class "ui-jqgrid-rotate" to
  7327. // prevent text cutting based on the current column width
  7328. $thDiv.css("min-width", (thHeight - thPaddingLeft - thPaddingRight) + "px")
  7329. .addClass("ui-jqgrid-rotate")
  7330. .css({ bottom: 0 });
  7331. p.colModel[iCol].rotated = true;
  7332. }
  7333. }
  7334. $self.jqGrid("resetColumnResizerHeight");
  7335. if (p.frozenColumns) {
  7336. setTimeout(function () {
  7337. $self.triggerHandler("jqGridResetFrozenHeights", {
  7338. header: {
  7339. resizeDiv: true,
  7340. resizedRows: {
  7341. iRowStart: 0,
  7342. iRowEnd: -1 // -1 means "till the end"
  7343. }
  7344. },
  7345. resizeFooter: true,
  7346. body: {
  7347. resizeDiv: true,
  7348. resizedRows: {
  7349. iRowStart: -1, // -1 means don't recalculate heights or rows
  7350. iRowEnd: -1
  7351. }
  7352. }
  7353. });
  7354. }, 0);
  7355. }
  7356. });
  7357. },
  7358. showHideCol: function (colname, show, options) {
  7359. return this.each(function () {
  7360. var $t = this, $self = $($t), grid = $t.grid, fndh = false, p = $t.p, brd = jgrid.cell_width ? 0 : p.cellLayout, cw;
  7361. if (!grid) { return; }
  7362. if (typeof colname === "string") { colname = [colname]; }
  7363. show = (show !== "none" && show !== false) ? "" : "none";
  7364. options = options || {};
  7365. var sw = show === "" ? true : false, groupHeader = p.groupHeader,
  7366. gh = groupHeader && (typeof groupHeader === "object" || $.isFunction(groupHeader));
  7367. if (gh && !options.skipSetGroupHeaders) {
  7368. base.destroyGroupHeader.call($self, false);
  7369. }
  7370. $(p.colModel).each(function (iCol) {
  7371. var setDisplayCssOnRows = function (rows) {
  7372. var iRow, nRow, row, cell, $cell, $thDiv, $inconsDiv, $textWrapper, heightText, widthText, heightIcon, widthIcon,
  7373. thHeight, thPaddingTop, thPaddingBottom, thPaddingLeft, thPaddingRight;
  7374. for (iRow = 0, nRow = rows.length; iRow < nRow; iRow++) {
  7375. row = rows[iRow];
  7376. cell = row.cells[iCol];
  7377. if (!$(row).hasClass("jqgroup") || (cell != null && cell.colSpan === 1)) {
  7378. /* workaround for the bug of Microsoft Edge
  7379. /* The following bug: Microsoft Edge "optimize" the changes of styles on elements with "height:0"
  7380. * on the empty grid. In other words, if the grid is empty then the code
  7381. * $(cell).css("display", "");
  7382. * or
  7383. * cell.style.display = "";
  7384. * will NOT change the style of the cell. One can examine cell.outerHTML to see something like
  7385. * <td role="gridcell" style="height:0;width:20px;display:none;"></td>
  7386. * but still see that cell.style.display is changed. As the workaround we first temporary set
  7387. * height of the cell from 0 to 1px, then changes "display" style and finally reset height to 0
  7388. */
  7389. $cell = $(cell);
  7390. if (iRow === 0 && $(row).hasClass("jqgfirstrow")) {
  7391. $cell.css("height", "1px");
  7392. $cell.css("display", show);
  7393. $cell.css("height", "0");
  7394. } else {
  7395. $cell.css("display", show);
  7396. }
  7397. if (sw && cell != null && cell.tagName.toUpperCase() === "TH" && $cell.hasClass("ui-th-column")) {
  7398. $thDiv = $cell.children("div");
  7399. if ($thDiv.hasClass("ui-jqgrid-rotate")) {
  7400. $inconsDiv = $thDiv.children("span.s-ico");
  7401. $textWrapper = $thDiv.children("span." + p.autoResizing.wrapperClassName),
  7402. heightText = $textWrapper.outerHeight(),
  7403. widthText = $textWrapper.outerWidth(),
  7404. heightIcon = $inconsDiv.outerHeight(),
  7405. widthIcon = $inconsDiv.outerWidth(true);
  7406. if ($textWrapper.length > 0) {
  7407. thPaddingTop = parseFloat($cell.css("padding-top") || 0);
  7408. thPaddingBottom = parseFloat($cell.css("padding-bottom") || 0);
  7409. thPaddingLeft = parseFloat($cell.css("padding-left") || 0);
  7410. thPaddingRight = parseFloat($cell.css("padding-right") || 0);
  7411. if (p.showSortOrder) {
  7412. widthIcon += widthIcon * 0.5; // one can improve the calculation later !!!
  7413. }
  7414. thHeight = widthText + widthIcon + thPaddingLeft + thPaddingRight;
  7415. $cell.height(thHeight);
  7416. $cell.css({
  7417. paddingTop: thPaddingRight + "px",
  7418. paddingBottom: thPaddingLeft + "px",
  7419. paddingLeft: thPaddingTop + "px",
  7420. paddingRight: thPaddingBottom + "px"
  7421. });
  7422. //thHeight = Math.max($cell.parent().height(), thHeight);
  7423. // we must set width of column header div BEFOR adding class "ui-jqgrid-rotate" to
  7424. // prevent text cutting based on the current column width
  7425. $thDiv.css("min-width", (thHeight - thPaddingLeft - thPaddingRight) + "px")
  7426. .css({ bottom: 0 });
  7427. }
  7428. }
  7429. }
  7430. }
  7431. // to follow HTML standards exactly one should probably add hidden column in
  7432. // grouping header row if ($(row).hasClass("jqgroup")) and decrement the value of
  7433. // colspan.
  7434. }
  7435. };
  7436. if ($.inArray(this.name, colname) !== -1 && this.hidden === sw) {
  7437. if (p.frozenColumns === true && this.frozen === true && !options.notSkipFrozen) {
  7438. return true;
  7439. }
  7440. setDisplayCssOnRows($(grid.hDiv).find(".ui-jqgrid-htable>thead>tr"));
  7441. if (p.frozenColumns === true && grid.fhDiv != null) {
  7442. setDisplayCssOnRows($(grid.fhDiv).find(".ui-jqgrid-htable>thead>tr"));
  7443. }
  7444. setDisplayCssOnRows($t.rows);
  7445. if (p.frozenColumns === true && grid.fbRows != null) {
  7446. setDisplayCssOnRows($t.rows);
  7447. }
  7448. if (p.footerrow) {
  7449. setDisplayCssOnRows($(grid.sDiv).find("tr.footrow"));
  7450. if (p.frozenColumns === true && grid.fsDiv != null) {
  7451. setDisplayCssOnRows($(grid.fsDiv).find("tr.footrow"));
  7452. }
  7453. }
  7454. cw = parseInt(this.width, 10);
  7455. if (show === "none") {
  7456. p.tblwidth -= cw + brd;
  7457. } else {
  7458. p.tblwidth += cw + brd;
  7459. }
  7460. this.hidden = !sw;
  7461. fndh = true;
  7462. if (!options.skipFeedback) {
  7463. feedback.call($t, "onShowHideCol", sw, this.name, iCol, options);
  7464. } else {
  7465. options.toReport = options.toReport || {};
  7466. options.toReport[this.name] = sw;
  7467. }
  7468. }
  7469. });
  7470. if (fndh === true) {
  7471. var newGridWidth = !p.autowidth && (p.widthOrg === undefined || p.widthOrg === "auto" || p.widthOrg === "100%") ?
  7472. p.tblwidth + parseInt(p.scrollOffset, 10) :
  7473. p.width;
  7474. if (!options.skipSetGridWidth) {
  7475. base.setGridWidth.call($self, newGridWidth);
  7476. } else {
  7477. options.newGridWidth = newGridWidth;
  7478. }
  7479. }
  7480. if (gh && !options.skipSetGroupHeaders) {
  7481. if (p.pivotOptions != null && p.pivotOptions.colHeaders != null && p.pivotOptions.colHeaders.length > 1) {
  7482. var i, gHead = p.pivotOptions.colHeaders;
  7483. for (i = 0; i < gHead.length; i++) {
  7484. // Multiple calls of setGroupHeaders for one grid are wrong,
  7485. // but there are produces good results in case of usage
  7486. // useColSpanStyle: false option. The rowspan values
  7487. // needed be increased in case of usage useColSpanStyle: true
  7488. if (gHead[i] && gHead[i].groupHeaders.length) {
  7489. base.setGroupHeaders.call($self, gHead[i]);
  7490. }
  7491. }
  7492. } else {
  7493. base.setGroupHeaders.call($self, p.groupHeader);
  7494. }
  7495. }
  7496. });
  7497. },
  7498. hideCol: function (colname, options) {
  7499. return this.each(function () { base.showHideCol.call($(this), colname, "none", options); });
  7500. },
  7501. showCol: function (colname, options) {
  7502. return this.each(function () { base.showHideCol.call($(this), colname, "", options); });
  7503. },
  7504. remapColumns: function (permutation, updateCells, keepHeader) {
  7505. var ts = this[0], p = ts.p, grid = ts.grid, iCol, n, makeArray = $.makeArray,
  7506. isFrozenColumns = p.frozenColumns === true, $toResort,
  7507. nFrozenColumns = this.jqGrid("getNumberOfFrozenColumns"),
  7508. permutationNormalized;
  7509. function normalizePermutation() {
  7510. var frozen = [], nonFrozen = [], i, l = permutation.length;
  7511. for (i = 0; i < l; i++) {
  7512. if (isFrozenColumns && permutation[i] < nFrozenColumns) {
  7513. frozen.push(permutation[i]);
  7514. } else {
  7515. nonFrozen.push(permutation[i]);
  7516. }
  7517. }
  7518. return frozen.concat(nonFrozen);
  7519. }
  7520. function resortArray(a) {
  7521. var ac = a.length ? makeArray(a) : $.extend({}, a);
  7522. $.each(permutationNormalized, function (i) {
  7523. a[i] = ac[this];
  7524. });
  7525. }
  7526. function resortRows($parent, selector) {
  7527. var $rows = selector ? $parent.children(selector) : $parent.children();
  7528. $rows.each(function () {
  7529. var row = this, elems = makeArray(row.cells);
  7530. $.each(permutationNormalized, function (i) {
  7531. var e = elems[this], oldElem = row.cells[i];
  7532. if (e != null && oldElem != null && e.cellIndex !== i) {
  7533. e.parentNode.insertBefore(e, oldElem);
  7534. }
  7535. });
  7536. });
  7537. }
  7538. if (grid == null || p == null) { return; }
  7539. // One have to "normalize" permutation array in case of usage frozen columns.
  7540. // The new index of frozen columns have to be less then nFrozenColumns
  7541. // (less then the number of frozen columns). In the same way the new index
  7542. // of non-frozen columns have to stay >=nFrozenColumns (non-frozen columns
  7543. // have to stay non-frozen)
  7544. permutationNormalized = normalizePermutation();
  7545. resortArray(p.colModel);
  7546. resortArray(p.colNames);
  7547. resortArray(grid.headers);
  7548. $toResort = $(grid.hDiv)
  7549. .children("div")
  7550. .children("table.ui-jqgrid-htable")
  7551. .children("thead");
  7552. if (isFrozenColumns && grid.fhDiv != null) {
  7553. $toResort = $toResort.add(
  7554. grid.fhDiv
  7555. .children("table.ui-jqgrid-htable")
  7556. .children("thead")
  7557. );
  7558. }
  7559. resortRows($toResort, keepHeader && ":not(.ui-jqgrid-labels)");
  7560. if (updateCells) {
  7561. $toResort = $(ts.tBodies[0]);
  7562. if (isFrozenColumns && grid.fbDiv != null) {
  7563. $toResort = $toResort.add(
  7564. grid.fbDiv
  7565. .children("table.ui-jqgrid-btable")
  7566. .children("tbody")
  7567. .first()
  7568. );
  7569. }
  7570. resortRows($toResort, "tr.jqgfirstrow,tr.jqgrow,tr.jqfoot");
  7571. }
  7572. if (p.footerrow) {
  7573. $toResort = $(grid.sDiv)
  7574. .children("div")
  7575. .children("table.ui-jqgrid-ftable")
  7576. .children("tbody")
  7577. .first();
  7578. if (isFrozenColumns && grid.fsDiv != null) {
  7579. $toResort = $toResort.add(
  7580. grid.fsDiv
  7581. .children("table.ui-jqgrid-ftable")
  7582. .children("tbody")
  7583. .first()
  7584. );
  7585. }
  7586. resortRows($toResort);
  7587. }
  7588. if (p.remapColumns) {
  7589. if (!p.remapColumns.length) {
  7590. p.remapColumns = makeArray(permutationNormalized);
  7591. } else {
  7592. resortArray(p.remapColumns);
  7593. }
  7594. }
  7595. p.lastsort = $.inArray(p.lastsort, permutationNormalized);
  7596. // rebuild iColByName
  7597. p.iColByName = {};
  7598. for (iCol = 0, n = p.colModel.length; iCol < n; iCol++) {
  7599. p.iColByName[p.colModel[iCol].name] = iCol;
  7600. }
  7601. feedback.call(ts, "onRemapColumns", permutationNormalized, updateCells, keepHeader);
  7602. },
  7603. remapColumnsByName: function (permutationByName, updateCells, keepHeader) {
  7604. var ts = this[0], p = ts.p, permutation = [], i, n, cmNames = permutationByName.slice(), inArray = $.inArray;
  7605. if (p.subGrid && inArray("subgrid", cmNames) < 0) {
  7606. cmNames.unshift("subgrid");
  7607. }
  7608. if (p.multiselect && inArray("cb", cmNames) < 0) {
  7609. cmNames.unshift("cb");
  7610. }
  7611. if (p.rownumbers && inArray("rn", cmNames) < 0) {
  7612. cmNames.unshift("rn");
  7613. }
  7614. for (i = 0, n = cmNames.length; i < n; i++) {
  7615. permutation.push(p.iColByName[cmNames[i]]);
  7616. }
  7617. base.remapColumns.call(this, permutation, updateCells, keepHeader);
  7618. return this;
  7619. },
  7620. setGridWidth: function (newWidth, shrink) {
  7621. return this.each(function () {
  7622. var $t = this, p = $t.p, columnWidth, grid = $t.grid, initialWidth = 0, iLastVariableColumn, numberOfVariableColumns = 0, hasScrollbar = false, totalVariableWidth, fixedColumnsWidth = 0, correctur,
  7623. isCellClassHidden = jgrid.isCellClassHidden, newGridWidth = newWidth;
  7624. if (!grid || p == null) { return; }
  7625. $t.fixScrollOffsetAndhBoxPadding();
  7626. // there are tree categorien of columns important below:
  7627. // 1) hidden - the columns will be not used in calculation of width
  7628. // 2) fixed - we will use the existing width of the columns in the calculation of the total width, but we well not change its width
  7629. // 3) variable columns - all other visible columns which width can be changed in general
  7630. // The width of every column consist from the innerWidth and the with of outer parts which will be 0 or cellLayout depend on boxing model used.
  7631. // The total width of the grid consist of the sum of width of all visible (fixed and variable) columns.
  7632. // There are outer bDiv which could have scroll bars. The p.scrollOffset hold the width or vertical scrollbar if it exists.
  7633. // grid.width and p.width need be set to the width of bDiv. The width of all other divs should be set to the same value.
  7634. //
  7635. // the input parameter newWidth specify new value of outer width (the width of bDiv)
  7636. var colModel = p.colModel, cm, scrollbarWidth = p.scrollOffset, borderAndPaddingWidth = jgrid.cell_width ? 0 : p.cellLayout, thInfo,
  7637. headers = grid.headers, footers = grid.footers, bDiv = grid.bDiv, hDiv = grid.hDiv, sDiv = grid.sDiv,
  7638. cols = grid.cols, delta, colsExist, shrinkFactor,
  7639. hCols = $(hDiv).find(">div>.ui-jqgrid-htable>thead>tr").first()[0].cells,
  7640. setWidthOfAllDivs = function (width) {
  7641. grid.width = p.width = width;
  7642. $(p.gBox).css("width", width + "px");
  7643. $(p.gView).css("width", width + "px");
  7644. $(bDiv).css("width", width + "px");
  7645. $(hDiv).css("width", width + "px");
  7646. if (p.pager) {
  7647. $(p.pager).css("width", width + "px");
  7648. }
  7649. if (p.toppager) {
  7650. $(p.toppager).css("width", width + "px");
  7651. }
  7652. if (p.toolbar[0] === true) {
  7653. $(grid.uDiv).css("width", width + "px");
  7654. if (p.toolbar[1] === "both") {
  7655. $(grid.ubDiv).css("width", width + "px");
  7656. }
  7657. }
  7658. if (p.footerrow) {
  7659. $(sDiv).css("width", width + "px");
  7660. }
  7661. };
  7662. if (typeof shrink !== "boolean") {
  7663. shrink = p.shrinkToFit;
  7664. }
  7665. if (isNaN(newGridWidth)) { return; }
  7666. newGridWidth = parseInt(newGridWidth, 10); // round till integer value of px
  7667. setWidthOfAllDivs(newGridWidth);
  7668. if (shrink === false && p.forceFit === true) { p.forceFit = false; }
  7669. // TODO: ??? recalculate p.tblwidth in case of shrink===false
  7670. if (shrink === true) {
  7671. // calculate initialWidth, fixedColumnsWidth and numberOfVariableColumns
  7672. $.each(colModel, function () {
  7673. // the classes property of colModel will be applied to the first
  7674. // row of the grid (hCols). If the
  7675. if (this.hidden === false && !isCellClassHidden(this.classes)) {
  7676. columnWidth = this.widthOrg;
  7677. initialWidth += columnWidth + borderAndPaddingWidth;
  7678. if (this.fixed) {
  7679. fixedColumnsWidth += this.width + borderAndPaddingWidth;
  7680. } else {
  7681. numberOfVariableColumns++;
  7682. }
  7683. }
  7684. });
  7685. if (numberOfVariableColumns === 0) { return; }
  7686. p.tblwidth = parseInt(initialWidth, 10); // round till integer value of px;
  7687. totalVariableWidth = newGridWidth - borderAndPaddingWidth * numberOfVariableColumns - fixedColumnsWidth;
  7688. if (!isNaN(p.height)) {
  7689. if (bDiv.clientHeight < bDiv.scrollHeight || $t.rows.length === 1) {
  7690. hasScrollbar = true;
  7691. totalVariableWidth -= scrollbarWidth;
  7692. }
  7693. }
  7694. shrinkFactor = totalVariableWidth / (p.tblwidth - borderAndPaddingWidth * numberOfVariableColumns - fixedColumnsWidth);
  7695. if (shrinkFactor < 0) { return; }
  7696. initialWidth = 0;
  7697. colsExist = cols.length > 0;
  7698. $.each(colModel, function (i) {
  7699. if (this.hidden === false && !isCellClassHidden(this.classes) && !this.fixed) {
  7700. columnWidth = Math.round(this.widthOrg * shrinkFactor);
  7701. this.width = columnWidth;
  7702. initialWidth += columnWidth;
  7703. headers[i].width = columnWidth;
  7704. hCols[i].style.width = columnWidth + "px";
  7705. if (p.footerrow) {
  7706. footers[i].style.width = columnWidth + "px";
  7707. }
  7708. if (colsExist) {
  7709. cols[i].style.width = columnWidth + "px";
  7710. }
  7711. iLastVariableColumn = i;
  7712. }
  7713. });
  7714. if (!iLastVariableColumn) { return; }
  7715. correctur = 0;
  7716. if (hasScrollbar) {
  7717. if (newGridWidth - fixedColumnsWidth - (initialWidth + borderAndPaddingWidth * numberOfVariableColumns) !== scrollbarWidth) {
  7718. correctur = newGridWidth - fixedColumnsWidth - (initialWidth + borderAndPaddingWidth * numberOfVariableColumns) - scrollbarWidth;
  7719. }
  7720. } else if (Math.abs(newGridWidth - fixedColumnsWidth - (initialWidth + borderAndPaddingWidth * numberOfVariableColumns)) !== 1) {
  7721. correctur = newGridWidth - fixedColumnsWidth - (initialWidth + borderAndPaddingWidth * numberOfVariableColumns);
  7722. }
  7723. cm = colModel[iLastVariableColumn];
  7724. cm.width += correctur;
  7725. p.tblwidth = parseInt(initialWidth + correctur + borderAndPaddingWidth * numberOfVariableColumns + fixedColumnsWidth, 10); // round till integer value of px;
  7726. if (p.tblwidth > newGridWidth) {
  7727. delta = p.tblwidth - parseInt(newGridWidth, 10);
  7728. p.tblwidth = newGridWidth;
  7729. cm.width = cm.width - delta;
  7730. }
  7731. columnWidth = cm.width;
  7732. thInfo = headers[iLastVariableColumn];
  7733. thInfo.width = columnWidth;
  7734. hCols[iLastVariableColumn].style.width = columnWidth + "px";
  7735. if (colsExist) { cols[iLastVariableColumn].style.width = columnWidth + "px"; }
  7736. if (p.footerrow) {
  7737. footers[iLastVariableColumn].style.width = columnWidth + "px";
  7738. }
  7739. if (p.tblwidth + (hasScrollbar ? scrollbarWidth : 0) < p.width) { // prabably bDiv.offsetWidth - bDiv.clientWidth is better as scw
  7740. // decrease the width if required
  7741. setWidthOfAllDivs(p.tblwidth + (hasScrollbar ? scrollbarWidth : 0));
  7742. }
  7743. if (bDiv.offsetWidth > bDiv.clientWidth) { // the part seems never work
  7744. // horizontal scroll bar exist.
  7745. // we need increase the width of bDiv to fix the problem or to reduce the width of the table
  7746. // currently we just increase the width
  7747. if (!p.autowidth && (p.widthOrg === undefined || p.widthOrg === "auto" || p.widthOrg === "100%")) {
  7748. setWidthOfAllDivs(bDiv.offsetWidth);
  7749. }
  7750. }
  7751. }
  7752. if (p.tblwidth) {
  7753. p.tblwidth = parseInt(p.tblwidth, 10); // round till integer value of px;
  7754. newGridWidth = p.tblwidth;
  7755. //$($t).css("width", newGridWidth + "px");
  7756. //getGridComponent(COMPONENT_NAMES.HEADER_TABLE, hDiv).css("width", newGridWidth + "px");
  7757. hDiv.scrollLeft = bDiv.scrollLeft;
  7758. /*if (p.footerrow) {
  7759. getGridComponent(COMPONENT_NAMES.FOOTER_TABLE, sDiv).css("width", newGridWidth + "px");
  7760. }*/
  7761. // small fix which origin should be examined more exactly
  7762. delta = Math.abs(newGridWidth - p.width);
  7763. if (p.shrinkToFit && !shrink && delta < 3 && delta > 0) {
  7764. if (newGridWidth < p.width) {
  7765. setWidthOfAllDivs(newGridWidth); // decrease the width if required
  7766. }
  7767. if (bDiv.offsetWidth > bDiv.clientWidth) { // the part seems never work
  7768. if (!p.autowidth && (p.widthOrg === undefined || p.widthOrg === "auto" || p.widthOrg === "100%")) {
  7769. setWidthOfAllDivs(bDiv.offsetWidth);
  7770. }
  7771. }
  7772. }
  7773. }
  7774. $t.fixScrollOffsetAndhBoxPadding();
  7775. var whichHeigthToRecalculate = {
  7776. resizeDiv: true,
  7777. resizedRows: {
  7778. iRowStart: (shrink ? 0 : -1), // -1 means don't recalculate heights or rows
  7779. iRowEnd: -1
  7780. }
  7781. };
  7782. $($t).triggerHandler("jqGridResetFrozenHeights", [{
  7783. header: whichHeigthToRecalculate,
  7784. resizeFooter: true,
  7785. body: whichHeigthToRecalculate
  7786. }]);
  7787. });
  7788. },
  7789. setGridHeight: function (nh) {
  7790. return this.each(function () {
  7791. var $t = this, grid = $t.grid, p = $t.p;
  7792. if (!grid) { return; }
  7793. var bDiv = $(grid.bDiv);
  7794. bDiv.css({ height: nh + (isNaN(nh) ? "" : "px") });
  7795. if (p.frozenColumns === true) {
  7796. //follow the original set height to use 16, better scrollbar width detection
  7797. $(p.idSel + "_frozen").parent().height(bDiv.height() - 16);
  7798. }
  7799. p.height = nh;
  7800. if (p.scroll) { grid.populateVisible.call($t); }
  7801. $t.fixScrollOffsetAndhBoxPadding();
  7802. $($t).triggerHandler("jqGridResetFrozenHeights");
  7803. });
  7804. },
  7805. setCaption: function (newcap) {
  7806. return this.each(function () {
  7807. var self = this, cDiv = self.grid.cDiv;
  7808. self.p.caption = newcap;
  7809. $("span.ui-jqgrid-title, span.ui-jqgrid-title-rtl", cDiv).html(newcap);
  7810. $(cDiv).show();
  7811. $(cDiv).nextAll("div").removeClass(base.getGuiStyles.call(self, "top"));
  7812. $(this).triggerHandler("jqGridResetFrozenHeights");
  7813. });
  7814. },
  7815. setLabel: function (colname, nData, prop, attrp) {
  7816. return this.each(function () {
  7817. var $t = this, iCol, p = $t.p, $th;
  7818. if (!$t.grid) { return; }
  7819. if (isNaN(colname)) {
  7820. iCol = p.iColByName[colname];
  7821. if (iCol === undefined) { return; }
  7822. } else { iCol = parseInt(colname, 10); }
  7823. if (iCol >= 0) {
  7824. $th = $($t.grid.headers[iCol].el);
  7825. if (p.frozenColumns) {
  7826. $th = $th.add($t.grid.fhDiv.find("#" + jqID($th)));
  7827. }
  7828. if (nData) {
  7829. $th.each(function () {
  7830. var $div = $("[id^=jqgh_]", this),
  7831. $textWrapper = $div.children("span.ui-jqgrid-cell-wrapper");
  7832. if ($textWrapper.length > 0) {
  7833. $textWrapper.html(nData);
  7834. } else {
  7835. var $ico = $(".s-ico", this);
  7836. $div.empty()
  7837. .html(nData)[p.sortIconsBeforeText ? "prepend" : "append"]($ico);
  7838. }
  7839. });
  7840. p.colNames[iCol] = nData;
  7841. }
  7842. if (prop) {
  7843. if (typeof prop === "string") { $th.addClass(prop); } else { $th.css(prop); }
  7844. }
  7845. if (typeof attrp === "object") { $th.attr(attrp); }
  7846. }
  7847. });
  7848. },
  7849. setCell: function (rowid, colName, nData, cssp, attrp, forceUpdate) {
  7850. // TODO: add an additional parameter, which will inform whether the input data nData is in formatted or unformatted form
  7851. return this.each(function () {
  7852. var $t = this, p = $t.p, iCol = -1, colModel = p.colModel, v, i, cm, item, tr, $td, $tdi, val, rawdat = {}, id, index;
  7853. if (!$t.grid) { return; }
  7854. iCol = isNaN(colName) ? p.iColByName[colName] : parseInt(colName, 10);
  7855. if (iCol >= 0) {
  7856. tr = base.getGridRowById.call($($t), rowid);
  7857. if (tr) {
  7858. $td = jgrid.getCell.call($t, tr, iCol);
  7859. if (nData !== "" || forceUpdate === true) {
  7860. cm = colModel[iCol];
  7861. if (p.datatype === "local") {
  7862. id = stripPref(p.idPrefix, rowid);
  7863. index = p._index[id];
  7864. if (index !== undefined) {
  7865. item = p.data[index];
  7866. }
  7867. }
  7868. // !!! filling of the rawdat for all cells slow down speed
  7869. // probably one should use p.data[index] (see below) instead ???
  7870. if (item == null) {
  7871. for (i = 0; i < tr.cells.length; i++) {
  7872. // !!! BUG the usage of innerHTML is wrong
  7873. // one have to use p.data[index] or unformat the data
  7874. if (i !== iCol) {
  7875. $tdi = jgrid.getDataFieldOfCell.call($t, tr, i);
  7876. if ($tdi.length > 0) {
  7877. try {
  7878. val = $.unformat.call($t, $tdi, { rowId: rowid, colModel: colModel[i] }, i);
  7879. } catch (exception) {
  7880. val = htmlDecode($tdi[0].innerHTML);
  7881. }
  7882. rawdat[colModel[i].name] = val;
  7883. }
  7884. }
  7885. }
  7886. } else {
  7887. rawdat = item;
  7888. }
  7889. rawdat[cm.name] = nData;
  7890. v = $t.formatter(rowid, nData, iCol, rawdat, "edit");
  7891. // update the data in the corresponding part of the cell
  7892. var $dataFiled = $td;
  7893. if (p.treeGrid === true && cm.name === p.ExpandColumn) {
  7894. $dataFiled = $dataFiled.children("span.cell-wrapperleaf,span.cell-wrapper").first();
  7895. }
  7896. $dataFiled.html(v);
  7897. // update the title of the cell if required
  7898. if (cm.title) {
  7899. $td.attr({ "title": nData });
  7900. }
  7901. if (item != null) { // p.datatype === "local"
  7902. v = convertOnSaveLocally.call($t, nData, cm, item[cm.name], id, item, iCol);
  7903. if ($.isFunction(cm.saveLocally)) {
  7904. cm.saveLocally.call($t, { newValue: v, newItem: item, oldItem: item, id: id, cm: cm, cmName: cm.name, iCol: iCol });
  7905. } else {
  7906. item[cm.name] = v;
  7907. // !!!!
  7908. }
  7909. }
  7910. }
  7911. if (cssp || attrp) {
  7912. $td = jgrid.getCell.call($t, tr, iCol);
  7913. if (cssp) {
  7914. $td[typeof cssp === "string" ? "addClass" : "css"](cssp);
  7915. }
  7916. if (typeof attrp === "object") {
  7917. $td.attr(attrp);
  7918. }
  7919. }
  7920. }
  7921. }
  7922. });
  7923. },
  7924. getCell: function (rowid, colName) {
  7925. // TODO: add an additional parameter, which will inform whether the output data should be in formatted or unformatted form
  7926. var ret = false;
  7927. this.each(function () {
  7928. var $t = this, iCol, p = $t.p, tr, $td, cm;
  7929. if (!$t.grid) { return; }
  7930. iCol = isNaN(colName) ? p.iColByName[colName] : parseInt(colName, 10);
  7931. if (iCol >= 0) { //isNaN(iCol)>=0 is false and undefined >= 0 is false
  7932. tr = base.getGridRowById.call($($t), rowid);
  7933. if (tr) {
  7934. $td = jgrid.getDataFieldOfCell.call($t, tr, iCol).first();
  7935. cm = p.colModel[iCol];
  7936. try {
  7937. if (base.isCellEditing.call($($t), rowid, iCol, tr)) {
  7938. ret = jgrid.getEditedValue.call($t, $td, cm, {}, cm.editable);
  7939. } else {
  7940. ret = $.unformat.call($t, $td, { rowId: tr.id, colModel: cm }, iCol);
  7941. }
  7942. } catch (exception) {
  7943. ret = htmlDecode($td.html());
  7944. }
  7945. }
  7946. }
  7947. });
  7948. return ret;
  7949. },
  7950. getCol: function (colName, obj, mathopr) {
  7951. // TODO: add an additional parameter, which will inform whether the output data should be in formatted or unformatted form
  7952. var ret = [], val, sum = 0, min, max, v;
  7953. obj = typeof obj !== "boolean" ? false : obj;
  7954. if (mathopr === undefined) { mathopr = false; }
  7955. this.each(function () {
  7956. var $t = this, iCol, p = $t.p, $td;
  7957. if (!$t.grid) { return; }
  7958. iCol = isNaN(colName) ? p.iColByName[colName] : parseInt(colName, 10);
  7959. if (iCol >= 0) { //isNaN(iCol)>=0 is false and undefined >= 0 is false
  7960. var rows = $t.rows, ln = rows.length, i = 0, dlen = 0, tr, cm = p.colModel[iCol], rowid;
  7961. if (ln && ln > 0) {
  7962. while (i < ln) {
  7963. tr = rows[i];
  7964. if ($(tr).hasClass("jqgrow")) {
  7965. $td = jgrid.getDataFieldOfCell.call($t, tr, iCol).first(); //$(tr.cells[iCol]);
  7966. rowid = tr.id;
  7967. try {
  7968. if (base.isCellEditing.call($($t), rowid, iCol, tr)) {
  7969. val = jgrid.getEditedValue.call($t, $td, cm, {}, cm.editable);
  7970. } else {
  7971. val = $.unformat.call($t, $td, { rowId: rowid, colModel: cm }, iCol);
  7972. }
  7973. } catch (exception) {
  7974. val = htmlDecode($td.html());
  7975. }
  7976. if (mathopr) {
  7977. v = parseFloat(val);
  7978. if (!isNaN(v)) {
  7979. sum += v;
  7980. if (max === undefined) { max = min = v; }
  7981. min = Math.min(min, v);
  7982. max = Math.max(max, v);
  7983. dlen++;
  7984. }
  7985. } else if (obj) {
  7986. ret.push({ id: rowid, value: val });
  7987. } else {
  7988. ret.push(val);
  7989. }
  7990. }
  7991. i++;
  7992. }
  7993. if (mathopr) {
  7994. switch (mathopr.toLowerCase()) {
  7995. case "sum":
  7996. ret = sum;
  7997. break;
  7998. case "avg":
  7999. ret = sum / dlen;
  8000. break;
  8001. case "count":
  8002. ret = (ln - 1);
  8003. break;
  8004. case "min":
  8005. ret = min;
  8006. break;
  8007. case "max":
  8008. ret = max;
  8009. break;
  8010. }
  8011. }
  8012. }
  8013. }
  8014. });
  8015. return ret;
  8016. },
  8017. clearGridData: function (clearfooter) {
  8018. return this.each(function () {
  8019. var $t = this, p = $t.p, rows = $t.rows, grid = $t.grid;
  8020. if (!grid || !p || !rows) { return; }
  8021. if (typeof clearfooter !== "boolean") { clearfooter = false; }
  8022. $($t).off(".jqGridFormatter");
  8023. grid.emptyRows.call($t, false, true);
  8024. if (p.footerrow && clearfooter) { $(".ui-jqgrid-ftable td", grid.sDiv).html("&#160;"); }
  8025. p.selrow = null;
  8026. clearArray(p.selarrrow); // p.selarrrow= [];
  8027. clearArray(p.savedRow); // p.savedRow = [];
  8028. p.editingInfo = {};
  8029. clearArray(p.data); //p.data = [];
  8030. clearArray(p.lastSelectedData); //p.lastSelectedData = [];
  8031. p._index = {};
  8032. p.rowIndexes = {};
  8033. p.dataIndexById = {};
  8034. p.indexByColumnData = {};
  8035. p.records = 0;
  8036. p.page = 1;
  8037. p.lastpage = 0;
  8038. p.reccount = 0;
  8039. $t.updatepager(true, false);
  8040. });
  8041. },
  8042. getInd: function (rowid, rc) {
  8043. var tr = base.getGridRowById.call($(this), rowid);
  8044. return tr ? (rc === true ? tr : tr.rowIndex) : false;
  8045. },
  8046. bindKeys: function (settings) {
  8047. var o = $.extend({
  8048. onEnter: null,
  8049. onSpace: null,
  8050. onLeftKey: null,
  8051. onRightKey: null,
  8052. scrollingRows: true
  8053. }, settings || {});
  8054. return this.each(function () {
  8055. var $t = this, p = $t.p, $self = $($t);
  8056. p.scrollrows = o.scrollingRows;
  8057. $self.on("keydown.jqGrid", function (event) {
  8058. var tr = $(this).find("tr[tabindex=0]")[0],
  8059. editingInfo = jgrid.detectRowEditing.call($t, $(event.target).closest("tr.jqgrow").attr("id")),
  8060. moveVertical = function (siblingProperty) {
  8061. do {
  8062. tr = tr[siblingProperty];
  8063. if (tr === null) { return; }
  8064. } while ($(tr).is(":hidden") || !$(tr).hasClass("jqgrow"));
  8065. base.setSelection.call($self, tr.id, true);
  8066. event.preventDefault();
  8067. },
  8068. feedbackKey = function (name, callbackSuffix) {
  8069. // possible events
  8070. // jqGridKeyLeft
  8071. // jqGridKeyRight
  8072. // jqGridKeyEnter
  8073. // jqGridKeySpace
  8074. // possible callbacks
  8075. // onLeftKey
  8076. // onRightKey
  8077. // onEnter
  8078. // onSpace
  8079. // no onUpKey or onDownKey and the corresponding events
  8080. var callback = o["on" + name + (callbackSuffix || "")];
  8081. $self.triggerHandler("jqGridKey" + name, [p.selrow]);
  8082. if ($.isFunction(callback)) {
  8083. callback.call($t, p.selrow);
  8084. }
  8085. },
  8086. moveHorizontal = function (stringLeftOrRight) {
  8087. if (p.treeGrid) {
  8088. var expanded = p.data[p._index[stripPref(p.idPrefix, tr.id)]][p.treeReader.expanded_field];
  8089. if (stringLeftOrRight === "Right") { expanded = !expanded; }
  8090. if (expanded) {
  8091. $(tr).find("div.treeclick").trigger("click");
  8092. }
  8093. }
  8094. feedbackKey(stringLeftOrRight, "Key");
  8095. };
  8096. //check for arrow keys
  8097. if (tr && editingInfo === null) {
  8098. switch (event.keyCode) {
  8099. case 38: // up key
  8100. moveVertical("previousSibling");
  8101. break;
  8102. case 40: // down key
  8103. moveVertical("nextSibling");
  8104. break;
  8105. case 37: // left key
  8106. moveHorizontal("Left");
  8107. break;
  8108. case 39: // left key
  8109. moveHorizontal("Right");
  8110. break;
  8111. case 13: // enter key
  8112. feedbackKey("Enter");
  8113. break;
  8114. case 32: // space key
  8115. feedbackKey("Space");
  8116. break;
  8117. default:
  8118. break;
  8119. }
  8120. }
  8121. });
  8122. });
  8123. },
  8124. unbindKeys: function () {
  8125. return this.each(function () {
  8126. $(this).off("keydown.jqGrid");
  8127. });
  8128. },
  8129. getLocalRow: function (rowid) {
  8130. var ret = false, ind;
  8131. this.each(function () {
  8132. var p = this.p;
  8133. if (rowid !== undefined && p != null && p._index != null && p.data != null) {
  8134. ind = p._index[stripPref(p.idPrefix, rowid)];
  8135. if (ind >= 0) {
  8136. ret = p.data[ind];
  8137. }
  8138. }
  8139. });
  8140. return ret;
  8141. },
  8142. progressBar: function (p) {
  8143. p = $.extend({
  8144. htmlcontent: "",
  8145. method: "hide",
  8146. loadtype: "disable"
  8147. }, p || {});
  8148. return this.each(function () {
  8149. var sh = p.method === "show" ? true : false, gridIdEscaped = jqID(this.p.id), $loading = $("#load_" + gridIdEscaped);
  8150. if (p.htmlcontent !== "") {
  8151. $loading.html(p.htmlcontent);
  8152. }
  8153. switch (p.loadtype) {
  8154. case "disable":
  8155. break;
  8156. case "enable":
  8157. $loading.toggle(sh);
  8158. break;
  8159. case "block":
  8160. $("#lui_" + gridIdEscaped).toggle(sh);
  8161. $loading.toggle(sh);
  8162. break;
  8163. }
  8164. });
  8165. },
  8166. setColWidth: function (iCol, newWidth, adjustGridWidth, skipGridAdjustments) {
  8167. return this.each(function () {
  8168. var self = this, $self = $(self), grid = self.grid, p = self.p, h;
  8169. if (typeof iCol === "string") {
  8170. // the first parametrer is column name instead of index
  8171. iCol = p.iColByName[iCol];
  8172. if (iCol === undefined) { return; }
  8173. } else if (typeof iCol !== "number") {
  8174. return; // error: wrong parameters
  8175. }
  8176. h = grid.headers[iCol];
  8177. if (h != null) {
  8178. h.newWidth = newWidth;
  8179. grid.newWidth = p.tblwidth + newWidth - h.width;
  8180. grid.resizeColumn(iCol, !p.frozenColumns, skipGridAdjustments);
  8181. if (adjustGridWidth !== false && !skipGridAdjustments) {
  8182. self.fixScrollOffsetAndhBoxPadding();
  8183. base.setGridWidth.call($self, grid.newWidth + p.scrollOffset, false); // adjust grid width too
  8184. }
  8185. }
  8186. });
  8187. },
  8188. getAutoResizableWidth: function (iCol) {
  8189. // The method get the max-width in the column.
  8190. // It get in considerations only VISIBLE elements.
  8191. // For example if some rows with data are hidden (grouping data, tree grid)
  8192. // then the max-width will see 0 as the width of the elements of the rows.
  8193. //
  8194. // The most expensive in below code is getting padding-left.
  8195. var self = this;
  8196. if (self.length === 0) {
  8197. return -1;
  8198. }
  8199. self = self[0];
  8200. var rows = self.rows, row, cell, iRow, $cell, $cellFirstChild,
  8201. p = self.p,
  8202. cm = p.colModel[iCol],
  8203. $th = $(self.grid.headers[iCol].el),
  8204. $thDiv = $th.children("div"),
  8205. thPaddingLeft = parseFloat($th.css((cm.rotated ? "padding-top" : "padding-left")) || 0), // typically 2
  8206. thPaddingRight = parseFloat($th.css((cm.rotated ? "padding-bottom" : "padding-right")) || 0),// typically 2
  8207. $incosDiv = $thDiv.children("span.s-ico"),
  8208. $sortOrder = $thDiv.children(".ui-jqgrid-sort-order"),
  8209. $wrapper = $thDiv.children("." + p.autoResizing.wrapperClassName),
  8210. wrapperOuterWidth = cm.rotated ? $wrapper.outerHeight() : $wrapper.outerWidth(),
  8211. wrapperCssWidth = parseFloat($wrapper.css(cm.rotated ? "height" : "width") || 0),
  8212. widthOuter = 0,
  8213. colWidth = 0,
  8214. compact = (cm.autoResizing != null && cm.autoResizable.compact !== undefined) ? cm.autoResizable.compact : p.autoResizing.compact,
  8215. wrapperClassName = p.autoResizing.wrapperClassName;
  8216. if (cm == null || !cm.autoResizable || $wrapper.length === 0 || cm.hidden || jgrid.isCellClassHidden(cm.classes) || cm.fixed) {
  8217. return -1; // do nothing
  8218. }
  8219. if (!compact || $incosDiv.is(":visible") || ($incosDiv.css("display") !== "none")) { //|| p.viewsortcols[0]
  8220. colWidth = cm.rotated ?
  8221. $incosDiv.outerHeight(true) :
  8222. $incosDiv.outerWidth(true) + ($sortOrder.length > 0 ? $sortOrder.outerWidth(true) : 0);
  8223. if (!p.sortIconsBeforeText) {
  8224. colWidth -= p.direction === "rtl" ?
  8225. parseFloat($incosDiv.css("padding-left") || 0) +
  8226. parseFloat($incosDiv.css("margin-left") || 0) :
  8227. parseFloat($incosDiv.css("padding-right") || 0) +
  8228. parseFloat($incosDiv.css("margin-right") || 0);
  8229. }
  8230. }
  8231. if (cm.rotated) {
  8232. colWidth = Math.max(colWidth, wrapperOuterWidth + thPaddingLeft + thPaddingRight);
  8233. } else {
  8234. colWidth += wrapperOuterWidth + thPaddingLeft +
  8235. (wrapperCssWidth === wrapperOuterWidth ? thPaddingLeft + thPaddingRight : 0) +
  8236. parseFloat($thDiv.css("margin-left") || 0) + parseFloat($thDiv.css("margin-right") || 0);
  8237. }
  8238. for (iRow = 0, rows = self.rows; iRow < rows.length; iRow++) {
  8239. row = rows[iRow];
  8240. cell = row.cells[iCol];
  8241. $cell = $(row.cells[iCol]);
  8242. if (cell != null && ($(row).hasClass("jqgrow") && row.style.display !== "none" && cell.style.display !== "none" || ($(row).hasClass("jqgroup") && cell.colSpan === 1))) {
  8243. $cellFirstChild = $(cell.firstChild);
  8244. if ($cellFirstChild.hasClass(wrapperClassName)) {
  8245. colWidth = Math.max(colWidth, $cellFirstChild.outerWidth() + widthOuter);
  8246. } else if (p.treeGrid && p.ExpandColumn === cm.name) {
  8247. $cellFirstChild = $cell.children(".cell-wrapper,.cell-wrapperleaf");
  8248. colWidth = Math.max(colWidth, $cellFirstChild.outerWidth() + widthOuter + $cell.children(".tree-wrap").outerWidth());
  8249. }
  8250. } else if ($(row).hasClass("jqgfirstrow")) {
  8251. // widthOuter is 4 typically (if jgrid.cell_width is true).
  8252. widthOuter = (jgrid.cell_width ? parseFloat($cell.css("padding-left") || 0) + parseFloat($cell.css("padding-right") || 0) : 0) +
  8253. parseFloat($cell.css("border-right") || 0) +
  8254. parseFloat($cell.css("border-left") || 0);
  8255. }
  8256. }
  8257. colWidth = Math.max(colWidth,
  8258. cm.autoResizing != null && cm.autoResizing.minColWidth !== undefined ?
  8259. cm.autoResizing.minColWidth :
  8260. p.autoResizing.minColWidth);
  8261. return Math.min(
  8262. colWidth,
  8263. cm.autoResizing != null && cm.autoResizing.maxColWidth !== undefined ?
  8264. cm.autoResizing.maxColWidth :
  8265. p.autoResizing.maxColWidth
  8266. );
  8267. },
  8268. autoResizeColumn: function (iCol, skipGridAdjustments) {
  8269. return this.each(function () {
  8270. var self = this, $self = $(this), p = self.p, cm = p.colModel[iCol], widthOrg,
  8271. $th = $(self.grid.headers[iCol].el),
  8272. newWidth = base.getAutoResizableWidth.call($self, iCol),
  8273. resetWidthOrg = (cm.autoResizing || {}).resetWidthOrg;
  8274. if (cm == null || newWidth < 0 || newWidth === cm.width) {
  8275. return;
  8276. }
  8277. base.setColWidth.call($self, iCol, newWidth, p.autoResizing.adjustGridWidth && !p.autoResizing.fixWidthOnShrink && !skipGridAdjustments, skipGridAdjustments);
  8278. if (p.autoResizing.fixWidthOnShrink && p.shrinkToFit && !skipGridAdjustments) {
  8279. cm.fixed = true;
  8280. widthOrg = cm.widthOrg; // save the value in temporary variable
  8281. cm.widthOrg = cm.width; // to force not changing of the column width
  8282. base.setGridWidth.call($self, p.width, true);
  8283. cm.widthOrg = widthOrg;
  8284. cm.fixed = false;
  8285. }
  8286. if (resetWidthOrg || (resetWidthOrg === undefined && p.autoResizing.resetWidthOrg)) {
  8287. cm.widthOrg = cm.width;
  8288. }
  8289. $th.data("autoResized", "true");
  8290. });
  8291. },
  8292. autoResizeAllColumns: function () {
  8293. return this.each(function () {
  8294. var self = this, $self = $(self), p = self.p, colModel = p.colModel, nCol = colModel.length, iCol, cm,
  8295. shrinkToFit = p.shrinkToFit, // save the original shrinkToFit value in the grid
  8296. adjustGridWidth = p.autoResizing.adjustGridWidth,
  8297. fixWidthOnShrink = p.autoResizing.fixWidthOnShrink,
  8298. width = parseInt(p.widthOrg, 10), grid = self.grid,
  8299. autoResizeColumn = base.autoResizeColumn; // cache autoResizeColumn reference
  8300. // autoResizeAllColumns calls multiple times autoResizeColumn
  8301. // which calls setColWidth, which calls resizeColumn, which calls
  8302. // fixScrollOffsetAndhBoxPadding and setGridWidth.
  8303. // The method setGridWidth will be called ADDITIONALLY by autoResizeColumn too
  8304. // As the result the most time spending by autoResizeAllColumns is
  8305. // for multiple calling of setGridWidth and fixScrollOffsetAndhBoxPadding
  8306. //
  8307. // So we skipp internal calls of fixScrollOffsetAndhBoxPadding and setGridWidth
  8308. // and to call the method ONCE after the end of loop below
  8309. // 1) Analyse colModel, colNames properties and sortname parameter to calculate
  8310. // minimal and optimal width of every column and the grid. It could be
  8311. // some important cases which should be
  8312. // a) The current width of the grid is LESS then optimal width and resizable column don't have fixed:true property.
  8313. // 1. save widthOrg of the resizable column in temporary variable
  8314. // 2. set widthOrg property of the resizable column to optimal size and set additionally fixed:true
  8315. // 3. call setGridWidth with the CURRENT grid width to change shrink width of all fixed:false
  8316. p.shrinkToFit = false; // make no shrinking during resizing of any columns
  8317. p.autoResizing.adjustGridWidth = true;
  8318. p.autoResizing.fixWidthOnShrink = false;
  8319. for (iCol = 0; iCol < nCol; iCol++) {
  8320. cm = colModel[iCol];
  8321. if (cm.autoResizable && cm.formatter !== "actions") {
  8322. autoResizeColumn.call($self, iCol, true);
  8323. }
  8324. }
  8325. // finalization
  8326. grid.hDiv.scrollLeft = grid.bDiv.scrollLeft;
  8327. if (p.footerrow) {
  8328. grid.sDiv.scrollLeft = grid.bDiv.scrollLeft;
  8329. }
  8330. self.fixScrollOffsetAndhBoxPadding();
  8331. if (!isNaN(width)) {
  8332. base.setGridWidth.call($self, width, false);
  8333. } else if (adjustGridWidth) {
  8334. base.setGridWidth.call($self, grid.newWidth + p.scrollOffset, false);
  8335. }
  8336. // restore the original shrinkToFit value
  8337. p.autoResizing.fixWidthOnShrink = fixWidthOnShrink;
  8338. p.autoResizing.adjustGridWidth = adjustGridWidth;
  8339. p.shrinkToFit = shrinkToFit;
  8340. });
  8341. }
  8342. });
  8343. // end module grid.base
  8344. }));