ui-grid.core.js 472 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881
  1. /*!
  2. * ui-grid - v4.4.6 - 2018-04-06
  3. * Copyright (c) 2018 ; License: MIT
  4. */
  5. (function () {
  6. 'use strict';
  7. angular.module('ui.grid.i18n', []);
  8. angular.module('ui.grid', ['ui.grid.i18n']);
  9. })();
  10. (function () {
  11. 'use strict';
  12. /**
  13. * @ngdoc object
  14. * @name ui.grid.service:uiGridConstants
  15. * @description Constants for use across many grid features
  16. *
  17. */
  18. angular.module('ui.grid').constant('uiGridConstants', {
  19. LOG_DEBUG_MESSAGES: true,
  20. LOG_WARN_MESSAGES: true,
  21. LOG_ERROR_MESSAGES: true,
  22. CUSTOM_FILTERS: /CUSTOM_FILTERS/g,
  23. COL_FIELD: /COL_FIELD/g,
  24. MODEL_COL_FIELD: /MODEL_COL_FIELD/g,
  25. TOOLTIP: /title=\"TOOLTIP\"/g,
  26. DISPLAY_CELL_TEMPLATE: /DISPLAY_CELL_TEMPLATE/g,
  27. TEMPLATE_REGEXP: /<.+>/,
  28. FUNC_REGEXP: /(\([^)]*\))?$/,
  29. DOT_REGEXP: /\./g,
  30. APOS_REGEXP: /'/g,
  31. BRACKET_REGEXP: /^(.*)((?:\s*\[\s*\d+\s*\]\s*)|(?:\s*\[\s*"(?:[^"\\]|\\.)*"\s*\]\s*)|(?:\s*\[\s*'(?:[^'\\]|\\.)*'\s*\]\s*))(.*)$/,
  32. COL_CLASS_PREFIX: 'ui-grid-col',
  33. ENTITY_BINDING: '$$this',
  34. events: {
  35. GRID_SCROLL: 'uiGridScroll',
  36. COLUMN_MENU_SHOWN: 'uiGridColMenuShown',
  37. ITEM_DRAGGING: 'uiGridItemDragStart', // For any item being dragged
  38. COLUMN_HEADER_CLICK: 'uiGridColumnHeaderClick'
  39. },
  40. // copied from http://www.lsauer.com/2011/08/javascript-keymap-keycodes-in-json.html
  41. keymap: {
  42. TAB: 9,
  43. STRG: 17,
  44. CAPSLOCK: 20,
  45. CTRL: 17,
  46. CTRLRIGHT: 18,
  47. CTRLR: 18,
  48. SHIFT: 16,
  49. RETURN: 13,
  50. ENTER: 13,
  51. BACKSPACE: 8,
  52. BCKSP: 8,
  53. ALT: 18,
  54. ALTR: 17,
  55. ALTRIGHT: 17,
  56. SPACE: 32,
  57. WIN: 91,
  58. MAC: 91,
  59. FN: null,
  60. PG_UP: 33,
  61. PG_DOWN: 34,
  62. UP: 38,
  63. DOWN: 40,
  64. LEFT: 37,
  65. RIGHT: 39,
  66. ESC: 27,
  67. DEL: 46,
  68. F1: 112,
  69. F2: 113,
  70. F3: 114,
  71. F4: 115,
  72. F5: 116,
  73. F6: 117,
  74. F7: 118,
  75. F8: 119,
  76. F9: 120,
  77. F10: 121,
  78. F11: 122,
  79. F12: 123
  80. },
  81. /**
  82. * @ngdoc object
  83. * @name ASC
  84. * @propertyOf ui.grid.service:uiGridConstants
  85. * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_sort columnDef.sort} and
  86. * {@link ui.grid.class:GridOptions.columnDef#properties_sortDirectionCycle columnDef.sortDirectionCycle}
  87. * to configure the sorting direction of the column
  88. */
  89. ASC: 'asc',
  90. /**
  91. * @ngdoc object
  92. * @name DESC
  93. * @propertyOf ui.grid.service:uiGridConstants
  94. * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_sort columnDef.sort} and
  95. * {@link ui.grid.class:GridOptions.columnDef#properties_sortDirectionCycle columnDef.sortDirectionCycle}
  96. * to configure the sorting direction of the column
  97. */
  98. DESC: 'desc',
  99. /**
  100. * @ngdoc object
  101. * @name filter
  102. * @propertyOf ui.grid.service:uiGridConstants
  103. * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_filter columnDef.filter}
  104. * to configure filtering on the column
  105. *
  106. * `SELECT` and `INPUT` are used with the `type` property of the filter, the rest are used to specify
  107. * one of the built-in conditions.
  108. *
  109. * Available `condition` options are:
  110. * - `uiGridConstants.filter.STARTS_WITH`
  111. * - `uiGridConstants.filter.ENDS_WITH`
  112. * - `uiGridConstants.filter.CONTAINS`
  113. * - `uiGridConstants.filter.GREATER_THAN`
  114. * - `uiGridConstants.filter.GREATER_THAN_OR_EQUAL`
  115. * - `uiGridConstants.filter.LESS_THAN`
  116. * - `uiGridConstants.filter.LESS_THAN_OR_EQUAL`
  117. * - `uiGridConstants.filter.NOT_EQUAL`
  118. *
  119. *
  120. * Available `type` options are:
  121. * - `uiGridConstants.filter.SELECT` - use a dropdown box for the cell header filter field
  122. * - `uiGridConstants.filter.INPUT` - use a text box for the cell header filter field
  123. */
  124. filter: {
  125. STARTS_WITH: 2,
  126. ENDS_WITH: 4,
  127. EXACT: 8,
  128. CONTAINS: 16,
  129. GREATER_THAN: 32,
  130. GREATER_THAN_OR_EQUAL: 64,
  131. LESS_THAN: 128,
  132. LESS_THAN_OR_EQUAL: 256,
  133. NOT_EQUAL: 512,
  134. SELECT: 'select',
  135. INPUT: 'input'
  136. },
  137. /**
  138. * @ngdoc object
  139. * @name aggregationTypes
  140. * @propertyOf ui.grid.service:uiGridConstants
  141. * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_aggregationType columnDef.aggregationType}
  142. * to specify the type of built-in aggregation the column should use.
  143. *
  144. * Available options are:
  145. * - `uiGridConstants.aggregationTypes.sum` - add the values in this column to produce the aggregated value
  146. * - `uiGridConstants.aggregationTypes.count` - count the number of rows to produce the aggregated value
  147. * - `uiGridConstants.aggregationTypes.avg` - average the values in this column to produce the aggregated value
  148. * - `uiGridConstants.aggregationTypes.min` - use the minimum value in this column as the aggregated value
  149. * - `uiGridConstants.aggregationTypes.max` - use the maximum value in this column as the aggregated value
  150. */
  151. aggregationTypes: {
  152. sum: 2,
  153. count: 4,
  154. avg: 8,
  155. min: 16,
  156. max: 32
  157. },
  158. /**
  159. * @ngdoc array
  160. * @name CURRENCY_SYMBOLS
  161. * @propertyOf ui.grid.service:uiGridConstants
  162. * @description A list of all presently circulating currency symbols that was copied from
  163. * https://en.wikipedia.org/wiki/Currency_symbol#List_of_presently-circulating_currency_symbols
  164. *
  165. * Can be used on {@link ui.grid.class:rowSorter} to create a number string regex that ignores currency symbols.
  166. */
  167. CURRENCY_SYMBOLS: ['¤', '؋', 'Ar', 'Ƀ', '฿', 'B/.', 'Br', 'Bs.', 'Bs.F.', 'GH₵', '¢', 'c', 'Ch.', '₡', 'C$', 'D', 'ден',
  168. 'دج', '.د.ب', 'د.ع', 'JD', 'د.ك', 'ل.د', 'дин', 'د.ت', 'د.م.', 'د.إ', 'Db', '$', '₫', 'Esc', '€', 'ƒ', 'Ft', 'FBu',
  169. 'FCFA', 'CFA', 'Fr', 'FRw', 'G', 'gr', '₲', 'h', '₴', '₭', 'Kč', 'kr', 'kn', 'MK', 'ZK', 'Kz', 'K', 'L', 'Le', 'лв',
  170. 'E', 'lp', 'M', 'KM', 'MT', '₥', 'Nfk', '₦', 'Nu.', 'UM', 'T$', 'MOP$', '₱', 'Pt.', '£', 'ج.م.', 'LL', 'LS', 'P', 'Q',
  171. 'q', 'R', 'R$', 'ر.ع.', 'ر.ق', 'ر.س', '៛', 'RM', 'p', 'Rf.', '₹', '₨', 'SRe', 'Rp', '₪', 'Ksh', 'Sh.So.', 'USh', 'S/',
  172. 'SDR', 'сом', '৳ ', 'WS$', '₮', 'VT', '₩', '¥', 'zł'],
  173. /**
  174. * @ngdoc object
  175. * @name scrollDirection
  176. * @propertyOf ui.grid.service:uiGridConstants
  177. * @description Set on {@link ui.grid.class:Grid#properties_scrollDirection Grid.scrollDirection},
  178. * to indicate the direction the grid is currently scrolling in
  179. *
  180. * Available options are:
  181. * - `uiGridConstants.scrollDirection.UP` - set when the grid is scrolling up
  182. * - `uiGridConstants.scrollDirection.DOWN` - set when the grid is scrolling down
  183. * - `uiGridConstants.scrollDirection.LEFT` - set when the grid is scrolling left
  184. * - `uiGridConstants.scrollDirection.RIGHT` - set when the grid is scrolling right
  185. * - `uiGridConstants.scrollDirection.NONE` - set when the grid is not scrolling, this is the default
  186. */
  187. scrollDirection: {
  188. UP: 'up',
  189. DOWN: 'down',
  190. LEFT: 'left',
  191. RIGHT: 'right',
  192. NONE: 'none'
  193. },
  194. /**
  195. * @ngdoc object
  196. * @name dataChange
  197. * @propertyOf ui.grid.service:uiGridConstants
  198. * @description Used with {@link ui.grid.core.api:PublicApi#methods_notifyDataChange PublicApi.notifyDataChange},
  199. * {@link ui.grid.class:Grid#methods_callDataChangeCallbacks Grid.callDataChangeCallbacks},
  200. * and {@link ui.grid.class:Grid#methods_registerDataChangeCallback Grid.registerDataChangeCallback}
  201. * to specify the type of the event(s).
  202. *
  203. * Available options are:
  204. * - `uiGridConstants.dataChange.ALL` - listeners fired on any of these events, fires listeners on all events.
  205. * - `uiGridConstants.dataChange.EDIT` - fired when the data in a cell is edited
  206. * - `uiGridConstants.dataChange.ROW` - fired when a row is added or removed
  207. * - `uiGridConstants.dataChange.COLUMN` - fired when the column definitions are modified
  208. * - `uiGridConstants.dataChange.OPTIONS` - fired when the grid options are modified
  209. */
  210. dataChange: {
  211. ALL: 'all',
  212. EDIT: 'edit',
  213. ROW: 'row',
  214. COLUMN: 'column',
  215. OPTIONS: 'options'
  216. },
  217. /**
  218. * @ngdoc object
  219. * @name scrollbars
  220. * @propertyOf ui.grid.service:uiGridConstants
  221. * @description Used with {@link ui.grid.class:GridOptions#properties_enableHorizontalScrollbar GridOptions.enableHorizontalScrollbar}
  222. * and {@link ui.grid.class:GridOptions#properties_enableVerticalScrollbar GridOptions.enableVerticalScrollbar}
  223. * to specify the scrollbar policy for that direction.
  224. *
  225. * Available options are:
  226. * - `uiGridConstants.scrollbars.NEVER` - never show scrollbars in this direction
  227. * - `uiGridConstants.scrollbars.ALWAYS` - always show scrollbars in this direction
  228. * - `uiGridConstants.scrollbars.WHEN_NEEDED` - shows scrollbars in this direction when needed
  229. */
  230. scrollbars: {
  231. NEVER: 0,
  232. ALWAYS: 1,
  233. WHEN_NEEDED: 2
  234. }
  235. });
  236. })();
  237. angular.module('ui.grid').directive('uiGridCell', ['$compile', '$parse', 'gridUtil', 'uiGridConstants', function ($compile, $parse, gridUtil, uiGridConstants) {
  238. var uiGridCell = {
  239. priority: 0,
  240. scope: false,
  241. require: '?^uiGrid',
  242. compile: function() {
  243. return {
  244. pre: function($scope, $elm, $attrs, uiGridCtrl) {
  245. function compileTemplate() {
  246. var compiledElementFn = $scope.col.compiledElementFn;
  247. compiledElementFn($scope, function(clonedElement, scope) {
  248. $elm.append(clonedElement);
  249. });
  250. }
  251. // If the grid controller is present, use it to get the compiled cell template function
  252. if (uiGridCtrl && $scope.col.compiledElementFn) {
  253. compileTemplate();
  254. }
  255. // No controller, compile the element manually (for unit tests)
  256. else {
  257. if ( uiGridCtrl && !$scope.col.compiledElementFn ){
  258. // gridUtil.logError('Render has been called before precompile. Please log a ui-grid issue');
  259. $scope.col.getCompiledElementFn()
  260. .then(function (compiledElementFn) {
  261. compiledElementFn($scope, function(clonedElement, scope) {
  262. $elm.append(clonedElement);
  263. });
  264. }).catch(angular.noop);
  265. }
  266. else {
  267. var html = $scope.col.cellTemplate
  268. .replace(uiGridConstants.MODEL_COL_FIELD, 'row.entity.' + gridUtil.preEval($scope.col.field))
  269. .replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)');
  270. var cellElement = $compile(html)($scope);
  271. $elm.append(cellElement);
  272. }
  273. }
  274. },
  275. post: function($scope, $elm, $attrs, uiGridCtrl) {
  276. var initColClass = $scope.col.getColClass(false);
  277. $elm.addClass(initColClass);
  278. var classAdded;
  279. var updateClass = function( grid ){
  280. var contents = $elm;
  281. if ( classAdded ){
  282. contents.removeClass( classAdded );
  283. classAdded = null;
  284. }
  285. if (angular.isFunction($scope.col.cellClass)) {
  286. classAdded = $scope.col.cellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex);
  287. }
  288. else {
  289. classAdded = $scope.col.cellClass;
  290. }
  291. contents.addClass(classAdded);
  292. };
  293. if ($scope.col.cellClass) {
  294. updateClass();
  295. }
  296. // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs
  297. var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateClass, [uiGridConstants.dataChange.COLUMN, uiGridConstants.dataChange.EDIT]);
  298. // watch the col and row to see if they change - which would indicate that we've scrolled or sorted or otherwise
  299. // changed the row/col that this cell relates to, and we need to re-evaluate cell classes and maybe other things
  300. var cellChangeFunction = function( n, o ){
  301. if ( n !== o ) {
  302. if ( classAdded || $scope.col.cellClass ){
  303. updateClass();
  304. }
  305. // See if the column's internal class has changed
  306. var newColClass = $scope.col.getColClass(false);
  307. if (newColClass !== initColClass) {
  308. $elm.removeClass(initColClass);
  309. $elm.addClass(newColClass);
  310. initColClass = newColClass;
  311. }
  312. }
  313. };
  314. // TODO(c0bra): Turn this into a deep array watch
  315. /* shouldn't be needed any more given track by col.name
  316. var colWatchDereg = $scope.$watch( 'col', cellChangeFunction );
  317. */
  318. var rowWatchDereg = $scope.$watch( 'row', cellChangeFunction );
  319. var deregisterFunction = function() {
  320. dataChangeDereg();
  321. // colWatchDereg();
  322. rowWatchDereg();
  323. };
  324. $scope.$on( '$destroy', deregisterFunction );
  325. $elm.on( '$destroy', deregisterFunction );
  326. }
  327. };
  328. }
  329. };
  330. return uiGridCell;
  331. }]);
  332. (function(){
  333. angular.module('ui.grid')
  334. .service('uiGridColumnMenuService', [ 'i18nService', 'uiGridConstants', 'gridUtil',
  335. function ( i18nService, uiGridConstants, gridUtil ) {
  336. /**
  337. * @ngdoc service
  338. * @name ui.grid.service:uiGridColumnMenuService
  339. *
  340. * @description Services for working with column menus, factored out
  341. * to make the code easier to understand
  342. */
  343. var service = {
  344. /**
  345. * @ngdoc method
  346. * @methodOf ui.grid.service:uiGridColumnMenuService
  347. * @name initialize
  348. * @description Sets defaults, puts a reference to the $scope on
  349. * the uiGridController
  350. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  351. * @param {controller} uiGridCtrl the uiGridController for the grid
  352. * we're on
  353. *
  354. */
  355. initialize: function( $scope, uiGridCtrl ){
  356. $scope.grid = uiGridCtrl.grid;
  357. // Store a reference to this link/controller in the main uiGrid controller
  358. // to allow showMenu later
  359. uiGridCtrl.columnMenuScope = $scope;
  360. // Save whether we're shown or not so the columns can check
  361. $scope.menuShown = false;
  362. },
  363. /**
  364. * @ngdoc method
  365. * @methodOf ui.grid.service:uiGridColumnMenuService
  366. * @name setColMenuItemWatch
  367. * @description Setup a watch on $scope.col.menuItems, and update
  368. * menuItems based on this. $scope.col needs to be set by the column
  369. * before calling the menu.
  370. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  371. * @param {controller} uiGridCtrl the uiGridController for the grid
  372. * we're on
  373. *
  374. */
  375. setColMenuItemWatch: function ( $scope ){
  376. var deregFunction = $scope.$watch('col.menuItems', function (n) {
  377. if (typeof(n) !== 'undefined' && n && angular.isArray(n)) {
  378. n.forEach(function (item) {
  379. if (typeof(item.context) === 'undefined' || !item.context) {
  380. item.context = {};
  381. }
  382. item.context.col = $scope.col;
  383. });
  384. $scope.menuItems = $scope.defaultMenuItems.concat(n);
  385. }
  386. else {
  387. $scope.menuItems = $scope.defaultMenuItems;
  388. }
  389. });
  390. $scope.$on( '$destroy', deregFunction );
  391. },
  392. /**
  393. * @ngdoc boolean
  394. * @name enableSorting
  395. * @propertyOf ui.grid.class:GridOptions.columnDef
  396. * @description (optional) True by default. When enabled, this setting adds sort
  397. * widgets to the column header, allowing sorting of the data in the individual column.
  398. */
  399. /**
  400. * @ngdoc method
  401. * @methodOf ui.grid.service:uiGridColumnMenuService
  402. * @name sortable
  403. * @description determines whether this column is sortable
  404. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  405. *
  406. */
  407. sortable: function( $scope ) {
  408. if ( $scope.grid.options.enableSorting && typeof($scope.col) !== 'undefined' && $scope.col && $scope.col.enableSorting) {
  409. return true;
  410. }
  411. else {
  412. return false;
  413. }
  414. },
  415. /**
  416. * @ngdoc method
  417. * @methodOf ui.grid.service:uiGridColumnMenuService
  418. * @name isActiveSort
  419. * @description determines whether the requested sort direction is current active, to
  420. * allow highlighting in the menu
  421. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  422. * @param {string} direction the direction that we'd have selected for us to be active
  423. *
  424. */
  425. isActiveSort: function( $scope, direction ){
  426. return (typeof($scope.col) !== 'undefined' && typeof($scope.col.sort) !== 'undefined' &&
  427. typeof($scope.col.sort.direction) !== 'undefined' && $scope.col.sort.direction === direction);
  428. },
  429. /**
  430. * @ngdoc method
  431. * @methodOf ui.grid.service:uiGridColumnMenuService
  432. * @name suppressRemoveSort
  433. * @description determines whether we should suppress the removeSort option
  434. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  435. *
  436. */
  437. suppressRemoveSort: function( $scope ) {
  438. if ($scope.col && $scope.col.suppressRemoveSort) {
  439. return true;
  440. }
  441. else {
  442. return false;
  443. }
  444. },
  445. /**
  446. * @ngdoc boolean
  447. * @name enableHiding
  448. * @propertyOf ui.grid.class:GridOptions.columnDef
  449. * @description (optional) True by default. When set to false, this setting prevents a user from hiding the column
  450. * using the column menu or the grid menu.
  451. */
  452. /**
  453. * @ngdoc method
  454. * @methodOf ui.grid.service:uiGridColumnMenuService
  455. * @name hideable
  456. * @description determines whether a column can be hidden, by checking the enableHiding columnDef option
  457. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  458. *
  459. */
  460. hideable: function( $scope ) {
  461. if (typeof($scope.col) !== 'undefined' && $scope.col && $scope.col.colDef && $scope.col.colDef.enableHiding === false ) {
  462. return false;
  463. }
  464. else {
  465. return true;
  466. }
  467. },
  468. /**
  469. * @ngdoc method
  470. * @methodOf ui.grid.service:uiGridColumnMenuService
  471. * @name getDefaultMenuItems
  472. * @description returns the default menu items for a column menu
  473. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  474. *
  475. */
  476. getDefaultMenuItems: function( $scope ){
  477. return [
  478. {
  479. title: function(){return i18nService.getSafeText('sort.ascending');},
  480. icon: 'ui-grid-icon-sort-alt-up',
  481. action: function($event) {
  482. $event.stopPropagation();
  483. $scope.sortColumn($event, uiGridConstants.ASC);
  484. },
  485. shown: function () {
  486. return service.sortable( $scope );
  487. },
  488. active: function() {
  489. return service.isActiveSort( $scope, uiGridConstants.ASC);
  490. }
  491. },
  492. {
  493. title: function(){return i18nService.getSafeText('sort.descending');},
  494. icon: 'ui-grid-icon-sort-alt-down',
  495. action: function($event) {
  496. $event.stopPropagation();
  497. $scope.sortColumn($event, uiGridConstants.DESC);
  498. },
  499. shown: function() {
  500. return service.sortable( $scope );
  501. },
  502. active: function() {
  503. return service.isActiveSort( $scope, uiGridConstants.DESC);
  504. }
  505. },
  506. {
  507. title: function(){return i18nService.getSafeText('sort.remove');},
  508. icon: 'ui-grid-icon-cancel',
  509. action: function ($event) {
  510. $event.stopPropagation();
  511. $scope.unsortColumn();
  512. },
  513. shown: function() {
  514. return service.sortable( $scope ) &&
  515. typeof($scope.col) !== 'undefined' && (typeof($scope.col.sort) !== 'undefined' &&
  516. typeof($scope.col.sort.direction) !== 'undefined') && $scope.col.sort.direction !== null &&
  517. !service.suppressRemoveSort( $scope );
  518. }
  519. },
  520. {
  521. title: function(){return i18nService.getSafeText('column.hide');},
  522. icon: 'ui-grid-icon-cancel',
  523. shown: function() {
  524. return service.hideable( $scope );
  525. },
  526. action: function ($event) {
  527. $event.stopPropagation();
  528. $scope.hideColumn();
  529. }
  530. }
  531. ];
  532. },
  533. /**
  534. * @ngdoc method
  535. * @methodOf ui.grid.service:uiGridColumnMenuService
  536. * @name getColumnElementPosition
  537. * @description gets the position information needed to place the column
  538. * menu below the column header
  539. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  540. * @param {GridCol} column the column we want to position below
  541. * @param {element} $columnElement the column element we want to position below
  542. * @returns {hash} containing left, top, offset, height, width
  543. *
  544. */
  545. getColumnElementPosition: function( $scope, column, $columnElement ){
  546. var positionData = {};
  547. positionData.left = $columnElement[0].offsetLeft;
  548. positionData.top = $columnElement[0].offsetTop;
  549. positionData.parentLeft = $columnElement[0].offsetParent.offsetLeft;
  550. // Get the grid scrollLeft
  551. positionData.offset = 0;
  552. if (column.grid.options.offsetLeft) {
  553. positionData.offset = column.grid.options.offsetLeft;
  554. }
  555. positionData.height = gridUtil.elementHeight($columnElement, true);
  556. positionData.width = gridUtil.elementWidth($columnElement, true);
  557. return positionData;
  558. },
  559. /**
  560. * @ngdoc method
  561. * @methodOf ui.grid.service:uiGridColumnMenuService
  562. * @name repositionMenu
  563. * @description Reposition the menu below the new column. If the menu has no child nodes
  564. * (i.e. it's not currently visible) then we guess it's width at 100, we'll be called again
  565. * later to fix it
  566. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  567. * @param {GridCol} column the column we want to position below
  568. * @param {hash} positionData a hash containing left, top, offset, height, width
  569. * @param {element} $elm the column menu element that we want to reposition
  570. * @param {element} $columnElement the column element that we want to reposition underneath
  571. *
  572. */
  573. repositionMenu: function( $scope, column, positionData, $elm, $columnElement ) {
  574. var menu = $elm[0].querySelectorAll('.ui-grid-menu');
  575. // It's possible that the render container of the column we're attaching to is
  576. // offset from the grid (i.e. pinned containers), we need to get the difference in the offsetLeft
  577. // between the render container and the grid
  578. var renderContainerElm = gridUtil.closestElm($columnElement, '.ui-grid-render-container');
  579. var renderContainerOffset = renderContainerElm.getBoundingClientRect().left - $scope.grid.element[0].getBoundingClientRect().left;
  580. var containerScrollLeft = renderContainerElm.querySelectorAll('.ui-grid-viewport')[0].scrollLeft;
  581. // repositionMenu is now always called after it's visible in the DOM,
  582. // allowing us to simply get the width every time the menu is opened
  583. var myWidth = gridUtil.elementWidth(menu, true);
  584. var paddingRight = column.lastMenuPaddingRight ? column.lastMenuPaddingRight : ( $scope.lastMenuPaddingRight ? $scope.lastMenuPaddingRight : 10);
  585. if ( menu.length !== 0 ){
  586. var mid = menu[0].querySelectorAll('.ui-grid-menu-mid');
  587. if ( mid.length !== 0 ) {
  588. // TODO(c0bra): use padding-left/padding-right based on document direction (ltr/rtl), place menu on proper side
  589. // Get the column menu right padding
  590. paddingRight = parseInt(gridUtil.getStyles(angular.element(menu)[0])['paddingRight'], 10);
  591. $scope.lastMenuPaddingRight = paddingRight;
  592. column.lastMenuPaddingRight = paddingRight;
  593. }
  594. }
  595. var left = positionData.left + renderContainerOffset - containerScrollLeft + positionData.parentLeft + positionData.width + paddingRight;
  596. if (left < positionData.offset + myWidth) {
  597. left = Math.max(positionData.left - containerScrollLeft + positionData.parentLeft - paddingRight + myWidth, positionData.offset + myWidth);
  598. }
  599. $elm.css('left', left + 'px');
  600. $elm.css('top', (positionData.top + positionData.height) + 'px');
  601. }
  602. };
  603. return service;
  604. }])
  605. .directive('uiGridColumnMenu', ['$timeout', 'gridUtil', 'uiGridConstants', 'uiGridColumnMenuService', '$document',
  606. function ($timeout, gridUtil, uiGridConstants, uiGridColumnMenuService, $document) {
  607. /**
  608. * @ngdoc directive
  609. * @name ui.grid.directive:uiGridColumnMenu
  610. * @description Provides the column menu framework, leverages uiGridMenu underneath
  611. *
  612. */
  613. var uiGridColumnMenu = {
  614. priority: 0,
  615. scope: true,
  616. require: '^uiGrid',
  617. templateUrl: 'ui-grid/uiGridColumnMenu',
  618. replace: true,
  619. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  620. uiGridColumnMenuService.initialize( $scope, uiGridCtrl );
  621. $scope.defaultMenuItems = uiGridColumnMenuService.getDefaultMenuItems( $scope );
  622. // Set the menu items for use with the column menu. The user can later add additional items via the watch
  623. $scope.menuItems = $scope.defaultMenuItems;
  624. uiGridColumnMenuService.setColMenuItemWatch( $scope );
  625. /**
  626. * @ngdoc method
  627. * @methodOf ui.grid.directive:uiGridColumnMenu
  628. * @name showMenu
  629. * @description Shows the column menu. If the menu is already displayed it
  630. * calls the menu to ask it to hide (it will animate), then it repositions the menu
  631. * to the right place whilst hidden (it will make an assumption on menu width),
  632. * then it asks the menu to show (it will animate), then it repositions the menu again
  633. * once we can calculate it's size.
  634. * @param {GridCol} column the column we want to position below
  635. * @param {element} $columnElement the column element we want to position below
  636. */
  637. $scope.showMenu = function(column, $columnElement, event) {
  638. // Swap to this column
  639. $scope.col = column;
  640. // Get the position information for the column element
  641. var colElementPosition = uiGridColumnMenuService.getColumnElementPosition( $scope, column, $columnElement );
  642. if ($scope.menuShown) {
  643. // we want to hide, then reposition, then show, but we want to wait for animations
  644. // we set a variable, and then rely on the menu-hidden event to call the reposition and show
  645. $scope.colElement = $columnElement;
  646. $scope.colElementPosition = colElementPosition;
  647. $scope.hideThenShow = true;
  648. $scope.$broadcast('hide-menu', { originalEvent: event });
  649. } else {
  650. $scope.menuShown = true;
  651. $scope.colElement = $columnElement;
  652. $scope.colElementPosition = colElementPosition;
  653. $scope.$broadcast('show-menu', { originalEvent: event });
  654. }
  655. };
  656. /**
  657. * @ngdoc method
  658. * @methodOf ui.grid.directive:uiGridColumnMenu
  659. * @name hideMenu
  660. * @description Hides the column menu.
  661. * @param {boolean} broadcastTrigger true if we were triggered by a broadcast
  662. * from the menu itself - in which case don't broadcast again as we'll get
  663. * an infinite loop
  664. */
  665. $scope.hideMenu = function( broadcastTrigger ) {
  666. $scope.menuShown = false;
  667. if ( !broadcastTrigger ){
  668. $scope.$broadcast('hide-menu');
  669. }
  670. };
  671. $scope.$on('menu-hidden', function() {
  672. var menuItems = angular.element($elm[0].querySelector('.ui-grid-menu-items'))[0];
  673. $elm[0].removeAttribute('style');
  674. if ( $scope.hideThenShow ){
  675. delete $scope.hideThenShow;
  676. $scope.$broadcast('show-menu');
  677. $scope.menuShown = true;
  678. } else {
  679. $scope.hideMenu( true );
  680. if ($scope.col) {
  681. //Focus on the menu button
  682. gridUtil.focus.bySelector($document, '.ui-grid-header-cell.' + $scope.col.getColClass()+ ' .ui-grid-column-menu-button', $scope.col.grid, false);
  683. }
  684. }
  685. if (menuItems) {
  686. menuItems.onkeydown = null;
  687. angular.forEach(menuItems.children, function removeHandlers(item) {
  688. item.onkeydown = null;
  689. });
  690. }
  691. });
  692. $scope.$on('menu-shown', function() {
  693. $timeout( function() {
  694. uiGridColumnMenuService.repositionMenu( $scope, $scope.col, $scope.colElementPosition, $elm, $scope.colElement );
  695. //automatically set the focus to the first button element in the now open menu.
  696. gridUtil.focus.bySelector($document, '.ui-grid-menu-items .ui-grid-menu-item:not(.ng-hide)', true);
  697. delete $scope.colElementPosition;
  698. delete $scope.columnElement;
  699. addKeydownHandlersToMenu();
  700. });
  701. });
  702. /* Column methods */
  703. $scope.sortColumn = function (event, dir) {
  704. event.stopPropagation();
  705. $scope.grid.sortColumn($scope.col, dir, true)
  706. .then(function () {
  707. $scope.grid.refresh();
  708. $scope.hideMenu();
  709. }).catch(angular.noop);
  710. };
  711. $scope.unsortColumn = function () {
  712. $scope.col.unsort();
  713. $scope.grid.refresh();
  714. $scope.hideMenu();
  715. };
  716. function addKeydownHandlersToMenu() {
  717. var menu = angular.element($elm[0].querySelector('.ui-grid-menu-items'))[0],
  718. menuItems,
  719. visibleMenuItems = [];
  720. if (menu) {
  721. menu.onkeydown = function closeMenu(event) {
  722. if (event.keyCode === uiGridConstants.keymap.ESC) {
  723. event.preventDefault();
  724. $scope.hideMenu();
  725. }
  726. };
  727. menuItems = menu.querySelectorAll('.ui-grid-menu-item:not(.ng-hide)');
  728. angular.forEach(menuItems, function filterVisibleItems(item) {
  729. if (item.offsetParent !== null) {
  730. this.push(item);
  731. }
  732. }, visibleMenuItems);
  733. if (visibleMenuItems.length) {
  734. if (visibleMenuItems.length === 1) {
  735. visibleMenuItems[0].onkeydown = function singleItemHandler(event) {
  736. circularFocusHandler(event, true);
  737. };
  738. } else {
  739. visibleMenuItems[0].onkeydown = function firstItemHandler(event) {
  740. circularFocusHandler(event, false, event.shiftKey, visibleMenuItems.length - 1);
  741. };
  742. visibleMenuItems[visibleMenuItems.length - 1].onkeydown = function lastItemHandler(event) {
  743. circularFocusHandler(event, false, !event.shiftKey, 0);
  744. };
  745. }
  746. }
  747. }
  748. function circularFocusHandler(event, isSingleItem, shiftKeyStatus, index) {
  749. if (event.keyCode === uiGridConstants.keymap.TAB) {
  750. if (isSingleItem) {
  751. event.preventDefault();
  752. } else if (shiftKeyStatus) {
  753. event.preventDefault();
  754. visibleMenuItems[index].focus();
  755. }
  756. }
  757. }
  758. }
  759. // Since we are hiding this column the default hide action will fail so we need to focus somewhere else.
  760. var setFocusOnHideColumn = function(){
  761. $timeout(function() {
  762. // Get the UID of the first
  763. var focusToGridMenu = function(){
  764. return gridUtil.focus.byId('grid-menu', $scope.grid);
  765. };
  766. var thisIndex;
  767. $scope.grid.columns.some(function(element, index){
  768. if (angular.equals(element, $scope.col)) {
  769. thisIndex = index;
  770. return true;
  771. }
  772. });
  773. var previousVisibleCol;
  774. // Try and find the next lower or nearest column to focus on
  775. $scope.grid.columns.some(function(element, index){
  776. if (!element.visible){
  777. return false;
  778. } // This columns index is below the current column index
  779. else if ( index < thisIndex){
  780. previousVisibleCol = element;
  781. } // This elements index is above this column index and we haven't found one that is lower
  782. else if ( index > thisIndex && !previousVisibleCol) {
  783. // This is the next best thing
  784. previousVisibleCol = element;
  785. // We've found one so use it.
  786. return true;
  787. } // We've reached an element with an index above this column and the previousVisibleCol variable has been set
  788. else if (index > thisIndex && previousVisibleCol) {
  789. // We are done.
  790. return true;
  791. }
  792. });
  793. // If found then focus on it
  794. if (previousVisibleCol){
  795. var colClass = previousVisibleCol.getColClass();
  796. gridUtil.focus.bySelector($document, '.ui-grid-header-cell.' + colClass+ ' .ui-grid-header-cell-primary-focus', true).then(angular.noop, function(reason){
  797. if (reason !== 'canceled'){ // If this is canceled then don't perform the action
  798. //The fallback action is to focus on the grid menu
  799. return focusToGridMenu();
  800. }
  801. }).catch(angular.noop);
  802. } else {
  803. // Fallback action to focus on the grid menu
  804. focusToGridMenu();
  805. }
  806. });
  807. };
  808. $scope.hideColumn = function () {
  809. $scope.col.colDef.visible = false;
  810. $scope.col.visible = false;
  811. $scope.grid.queueGridRefresh();
  812. $scope.hideMenu();
  813. $scope.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN );
  814. $scope.grid.api.core.raise.columnVisibilityChanged( $scope.col );
  815. // We are hiding so the default action of focusing on the button that opened this menu will fail.
  816. setFocusOnHideColumn();
  817. };
  818. },
  819. controller: ['$scope', function ($scope) {
  820. var self = this;
  821. $scope.$watch('menuItems', function (n) {
  822. self.menuItems = n;
  823. });
  824. }]
  825. };
  826. return uiGridColumnMenu;
  827. }]);
  828. })();
  829. (function(){
  830. 'use strict';
  831. angular.module('ui.grid').directive('uiGridFilter', ['$compile', '$templateCache', 'i18nService', 'gridUtil', function ($compile, $templateCache, i18nService, gridUtil) {
  832. return {
  833. compile: function() {
  834. return {
  835. pre: function ($scope, $elm, $attrs, controllers) {
  836. $scope.col.updateFilters = function( filterable ){
  837. $elm.children().remove();
  838. if ( filterable ) {
  839. var template = $scope.col.filterHeaderTemplate;
  840. if (template === undefined && $scope.col.providedFilterHeaderTemplate !== '') {
  841. if ($scope.col.filterHeaderTemplatePromise) {
  842. $scope.col.filterHeaderTemplatePromise.then(function () {
  843. template = $scope.col.filterHeaderTemplate;
  844. $elm.append($compile(template)($scope));
  845. });
  846. }
  847. }
  848. else {
  849. $elm.append($compile(template)($scope));
  850. }
  851. }
  852. };
  853. $scope.$on( '$destroy', function() {
  854. delete $scope.col.updateFilters;
  855. });
  856. },
  857. post: function ($scope, $elm, $attrs, controllers){
  858. $scope.aria = i18nService.getSafeText('headerCell.aria');
  859. $scope.removeFilter = function(colFilter, index){
  860. colFilter.term = null;
  861. //Set the focus to the filter input after the action disables the button
  862. gridUtil.focus.bySelector($elm, '.ui-grid-filter-input-' + index);
  863. };
  864. }
  865. };
  866. }
  867. };
  868. }]);
  869. })();
  870. (function () {
  871. 'use strict';
  872. angular.module('ui.grid').directive('uiGridFooterCell', ['$timeout', 'gridUtil', 'uiGridConstants', '$compile',
  873. function ($timeout, gridUtil, uiGridConstants, $compile) {
  874. var uiGridFooterCell = {
  875. priority: 0,
  876. scope: {
  877. col: '=',
  878. row: '=',
  879. renderIndex: '='
  880. },
  881. replace: true,
  882. require: '^uiGrid',
  883. compile: function compile(tElement, tAttrs, transclude) {
  884. return {
  885. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  886. var template = $scope.col.footerCellTemplate;
  887. if (template === undefined && $scope.col.providedFooterCellTemplate !== '') {
  888. if ($scope.col.footerCellTemplatePromise) {
  889. $scope.col.footerCellTemplatePromise.then(function () {
  890. template = $scope.col.footerCellTemplate;
  891. $elm.append($compile(template)($scope));
  892. });
  893. }
  894. }
  895. else {
  896. $elm.append($compile(template)($scope));
  897. }
  898. },
  899. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  900. //$elm.addClass($scope.col.getColClass(false));
  901. $scope.grid = uiGridCtrl.grid;
  902. var initColClass = $scope.col.getColClass(false);
  903. $elm.addClass(initColClass);
  904. // apply any footerCellClass
  905. var classAdded;
  906. var updateClass = function( grid ){
  907. var contents = $elm;
  908. if ( classAdded ){
  909. contents.removeClass( classAdded );
  910. classAdded = null;
  911. }
  912. if (angular.isFunction($scope.col.footerCellClass)) {
  913. classAdded = $scope.col.footerCellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex);
  914. }
  915. else {
  916. classAdded = $scope.col.footerCellClass;
  917. }
  918. contents.addClass(classAdded);
  919. };
  920. if ($scope.col.footerCellClass) {
  921. updateClass();
  922. }
  923. $scope.col.updateAggregationValue();
  924. // Watch for column changes so we can alter the col cell class properly
  925. /* shouldn't be needed any more, given track by col.name
  926. $scope.$watch('col', function (n, o) {
  927. if (n !== o) {
  928. // See if the column's internal class has changed
  929. var newColClass = $scope.col.getColClass(false);
  930. if (newColClass !== initColClass) {
  931. $elm.removeClass(initColClass);
  932. $elm.addClass(newColClass);
  933. initColClass = newColClass;
  934. }
  935. }
  936. });
  937. */
  938. // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs
  939. var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateClass, [uiGridConstants.dataChange.COLUMN]);
  940. // listen for visible rows change and update aggregation values
  941. $scope.grid.api.core.on.rowsRendered( $scope, $scope.col.updateAggregationValue );
  942. $scope.grid.api.core.on.rowsRendered( $scope, updateClass );
  943. $scope.$on( '$destroy', dataChangeDereg );
  944. }
  945. };
  946. }
  947. };
  948. return uiGridFooterCell;
  949. }]);
  950. })();
  951. (function () {
  952. 'use strict';
  953. angular.module('ui.grid').directive('uiGridFooter', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', '$timeout', function ($templateCache, $compile, uiGridConstants, gridUtil, $timeout) {
  954. return {
  955. restrict: 'EA',
  956. replace: true,
  957. // priority: 1000,
  958. require: ['^uiGrid', '^uiGridRenderContainer'],
  959. scope: true,
  960. compile: function ($elm, $attrs) {
  961. return {
  962. pre: function ($scope, $elm, $attrs, controllers) {
  963. var uiGridCtrl = controllers[0];
  964. var containerCtrl = controllers[1];
  965. $scope.grid = uiGridCtrl.grid;
  966. $scope.colContainer = containerCtrl.colContainer;
  967. containerCtrl.footer = $elm;
  968. var footerTemplate = $scope.grid.options.footerTemplate;
  969. gridUtil.getTemplate(footerTemplate)
  970. .then(function (contents) {
  971. var template = angular.element(contents);
  972. var newElm = $compile(template)($scope);
  973. $elm.append(newElm);
  974. if (containerCtrl) {
  975. // Inject a reference to the footer viewport (if it exists) into the grid controller for use in the horizontal scroll handler below
  976. var footerViewport = $elm[0].getElementsByClassName('ui-grid-footer-viewport')[0];
  977. if (footerViewport) {
  978. containerCtrl.footerViewport = footerViewport;
  979. }
  980. }
  981. }).catch(angular.noop);
  982. },
  983. post: function ($scope, $elm, $attrs, controllers) {
  984. var uiGridCtrl = controllers[0];
  985. var containerCtrl = controllers[1];
  986. // gridUtil.logDebug('ui-grid-footer link');
  987. var grid = uiGridCtrl.grid;
  988. // Don't animate footer cells
  989. gridUtil.disableAnimations($elm);
  990. containerCtrl.footer = $elm;
  991. var footerViewport = $elm[0].getElementsByClassName('ui-grid-footer-viewport')[0];
  992. if (footerViewport) {
  993. containerCtrl.footerViewport = footerViewport;
  994. }
  995. }
  996. };
  997. }
  998. };
  999. }]);
  1000. })();
  1001. (function () {
  1002. 'use strict';
  1003. angular.module('ui.grid').directive('uiGridGridFooter', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', '$timeout', function ($templateCache, $compile, uiGridConstants, gridUtil, $timeout) {
  1004. return {
  1005. restrict: 'EA',
  1006. replace: true,
  1007. // priority: 1000,
  1008. require: '^uiGrid',
  1009. scope: true,
  1010. compile: function ($elm, $attrs) {
  1011. return {
  1012. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  1013. $scope.grid = uiGridCtrl.grid;
  1014. var footerTemplate = $scope.grid.options.gridFooterTemplate;
  1015. gridUtil.getTemplate(footerTemplate)
  1016. .then(function (contents) {
  1017. var template = angular.element(contents);
  1018. var newElm = $compile(template)($scope);
  1019. $elm.append(newElm);
  1020. }).catch(angular.noop);
  1021. },
  1022. post: function ($scope, $elm, $attrs, controllers) {
  1023. }
  1024. };
  1025. }
  1026. };
  1027. }]);
  1028. })();
  1029. (function(){
  1030. 'use strict';
  1031. angular.module('ui.grid').directive('uiGridHeaderCell', ['$compile', '$timeout', '$window', '$document', 'gridUtil', 'uiGridConstants', 'ScrollEvent', 'i18nService',
  1032. function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, ScrollEvent, i18nService) {
  1033. // Do stuff after mouse has been down this many ms on the header cell
  1034. var mousedownTimeout = 500;
  1035. var changeModeTimeout = 500; // length of time between a touch event and a mouse event being recognised again, and vice versa
  1036. var uiGridHeaderCell = {
  1037. priority: 0,
  1038. scope: {
  1039. col: '=',
  1040. row: '=',
  1041. renderIndex: '='
  1042. },
  1043. require: ['^uiGrid', '^uiGridRenderContainer'],
  1044. replace: true,
  1045. compile: function() {
  1046. return {
  1047. pre: function ($scope, $elm, $attrs) {
  1048. var template = $scope.col.headerCellTemplate;
  1049. if (template === undefined && $scope.col.providedHeaderCellTemplate !== '') {
  1050. if ($scope.col.headerCellTemplatePromise) {
  1051. $scope.col.headerCellTemplatePromise.then(function () {
  1052. template = $scope.col.headerCellTemplate;
  1053. $elm.append($compile(template)($scope));
  1054. });
  1055. }
  1056. }
  1057. else {
  1058. $elm.append($compile(template)($scope));
  1059. }
  1060. },
  1061. post: function ($scope, $elm, $attrs, controllers) {
  1062. var uiGridCtrl = controllers[0];
  1063. var renderContainerCtrl = controllers[1];
  1064. $scope.i18n = {
  1065. headerCell: i18nService.getSafeText('headerCell'),
  1066. sort: i18nService.getSafeText('sort')
  1067. };
  1068. $scope.isSortPriorityVisible = function() {
  1069. //show sort priority if column is sorted and there is at least one other sorted column
  1070. return angular.isNumber($scope.col.sort.priority) && $scope.grid.columns.some(function(element, index){
  1071. return angular.isNumber(element.sort.priority) && element !== $scope.col;
  1072. });
  1073. };
  1074. $scope.getSortDirectionAriaLabel = function(){
  1075. var col = $scope.col;
  1076. //Trying to recreate this sort of thing but it was getting messy having it in the template.
  1077. //Sort direction {{col.sort.direction == asc ? 'ascending' : ( col.sort.direction == desc ? 'descending':'none')}}. {{col.sort.priority ? {{columnPriorityText}} {{col.sort.priority}} : ''}
  1078. var sortDirectionText = col.sort.direction === uiGridConstants.ASC ? $scope.i18n.sort.ascending : ( col.sort.direction === uiGridConstants.DESC ? $scope.i18n.sort.descending : $scope.i18n.sort.none);
  1079. var label = sortDirectionText;
  1080. if ($scope.isSortPriorityVisible()) {
  1081. label = label + '. ' + $scope.i18n.headerCell.priority + ' ' + (col.sort.priority + 1);
  1082. }
  1083. return label;
  1084. };
  1085. $scope.grid = uiGridCtrl.grid;
  1086. $scope.renderContainer = uiGridCtrl.grid.renderContainers[renderContainerCtrl.containerId];
  1087. var initColClass = $scope.col.getColClass(false);
  1088. $elm.addClass(initColClass);
  1089. // Hide the menu by default
  1090. $scope.menuShown = false;
  1091. // Put asc and desc sort directions in scope
  1092. $scope.asc = uiGridConstants.ASC;
  1093. $scope.desc = uiGridConstants.DESC;
  1094. // Store a reference to menu element
  1095. var $colMenu = angular.element( $elm[0].querySelectorAll('.ui-grid-header-cell-menu') );
  1096. var $contentsElm = angular.element( $elm[0].querySelectorAll('.ui-grid-cell-contents') );
  1097. // apply any headerCellClass
  1098. var classAdded;
  1099. var previousMouseX;
  1100. // filter watchers
  1101. var filterDeregisters = [];
  1102. /*
  1103. * Our basic approach here for event handlers is that we listen for a down event (mousedown or touchstart).
  1104. * Once we have a down event, we need to work out whether we have a click, a drag, or a
  1105. * hold. A click would sort the grid (if sortable). A drag would be used by moveable, so
  1106. * we ignore it. A hold would open the menu.
  1107. *
  1108. * So, on down event, we put in place handlers for move and up events, and a timer. If the
  1109. * timer expires before we see a move or up, then we have a long press and hence a column menu open.
  1110. * If the up happens before the timer, then we have a click, and we sort if the column is sortable.
  1111. * If a move happens before the timer, then we are doing column move, so we do nothing, the moveable feature
  1112. * will handle it.
  1113. *
  1114. * To deal with touch enabled devices that also have mice, we only create our handlers when
  1115. * we get the down event, and we create the corresponding handlers - if we're touchstart then
  1116. * we get touchmove and touchend, if we're mousedown then we get mousemove and mouseup.
  1117. *
  1118. * We also suppress the click action whilst this is happening - otherwise after the mouseup there
  1119. * will be a click event and that can cause the column menu to close
  1120. *
  1121. */
  1122. $scope.downFn = function( event ){
  1123. event.stopPropagation();
  1124. if (typeof(event.originalEvent) !== 'undefined' && event.originalEvent !== undefined) {
  1125. event = event.originalEvent;
  1126. }
  1127. // Don't show the menu if it's not the left button
  1128. if (event.button && event.button !== 0) {
  1129. return;
  1130. }
  1131. previousMouseX = event.pageX;
  1132. $scope.mousedownStartTime = (new Date()).getTime();
  1133. $scope.mousedownTimeout = $timeout(function() { }, mousedownTimeout);
  1134. $scope.mousedownTimeout.then(function () {
  1135. if ( $scope.colMenu ) {
  1136. uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm, event);
  1137. }
  1138. }).catch(angular.noop);
  1139. uiGridCtrl.fireEvent(uiGridConstants.events.COLUMN_HEADER_CLICK, {event: event, columnName: $scope.col.colDef.name});
  1140. $scope.offAllEvents();
  1141. if ( event.type === 'touchstart'){
  1142. $document.on('touchend', $scope.upFn);
  1143. $document.on('touchmove', $scope.moveFn);
  1144. } else if ( event.type === 'mousedown' ){
  1145. $document.on('mouseup', $scope.upFn);
  1146. $document.on('mousemove', $scope.moveFn);
  1147. }
  1148. };
  1149. $scope.upFn = function( event ){
  1150. event.stopPropagation();
  1151. $timeout.cancel($scope.mousedownTimeout);
  1152. $scope.offAllEvents();
  1153. $scope.onDownEvents(event.type);
  1154. var mousedownEndTime = (new Date()).getTime();
  1155. var mousedownTime = mousedownEndTime - $scope.mousedownStartTime;
  1156. if (mousedownTime > mousedownTimeout) {
  1157. // long click, handled above with mousedown
  1158. }
  1159. else {
  1160. // short click
  1161. if ( $scope.sortable ){
  1162. $scope.handleClick(event);
  1163. }
  1164. }
  1165. };
  1166. $scope.handleKeyDown = function(event) {
  1167. if (event.keyCode === 32) {
  1168. event.preventDefault();
  1169. }
  1170. };
  1171. $scope.moveFn = function( event ){
  1172. // Chrome is known to fire some bogus move events.
  1173. var changeValue = event.pageX - previousMouseX;
  1174. if ( changeValue === 0 ){ return; }
  1175. // we're a move, so do nothing and leave for column move (if enabled) to take over
  1176. $timeout.cancel($scope.mousedownTimeout);
  1177. $scope.offAllEvents();
  1178. $scope.onDownEvents(event.type);
  1179. };
  1180. $scope.clickFn = function ( event ){
  1181. event.stopPropagation();
  1182. $contentsElm.off('click', $scope.clickFn);
  1183. };
  1184. $scope.offAllEvents = function(){
  1185. $contentsElm.off('touchstart', $scope.downFn);
  1186. $contentsElm.off('mousedown', $scope.downFn);
  1187. $document.off('touchend', $scope.upFn);
  1188. $document.off('mouseup', $scope.upFn);
  1189. $document.off('touchmove', $scope.moveFn);
  1190. $document.off('mousemove', $scope.moveFn);
  1191. $contentsElm.off('click', $scope.clickFn);
  1192. };
  1193. $scope.onDownEvents = function( type ){
  1194. // If there is a previous event, then wait a while before
  1195. // activating the other mode - i.e. if the last event was a touch event then
  1196. // don't enable mouse events for a wee while (500ms or so)
  1197. // Avoids problems with devices that emulate mouse events when you have touch events
  1198. switch (type){
  1199. case 'touchmove':
  1200. case 'touchend':
  1201. $contentsElm.on('click', $scope.clickFn);
  1202. $contentsElm.on('touchstart', $scope.downFn);
  1203. $timeout(function(){
  1204. $contentsElm.on('mousedown', $scope.downFn);
  1205. }, changeModeTimeout);
  1206. break;
  1207. case 'mousemove':
  1208. case 'mouseup':
  1209. $contentsElm.on('click', $scope.clickFn);
  1210. $contentsElm.on('mousedown', $scope.downFn);
  1211. $timeout(function(){
  1212. $contentsElm.on('touchstart', $scope.downFn);
  1213. }, changeModeTimeout);
  1214. break;
  1215. default:
  1216. $contentsElm.on('click', $scope.clickFn);
  1217. $contentsElm.on('touchstart', $scope.downFn);
  1218. $contentsElm.on('mousedown', $scope.downFn);
  1219. }
  1220. };
  1221. var updateHeaderOptions = function( grid ){
  1222. var contents = $elm;
  1223. if ( classAdded ){
  1224. contents.removeClass( classAdded );
  1225. classAdded = null;
  1226. }
  1227. if (angular.isFunction($scope.col.headerCellClass)) {
  1228. classAdded = $scope.col.headerCellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex);
  1229. }
  1230. else {
  1231. classAdded = $scope.col.headerCellClass;
  1232. }
  1233. contents.addClass(classAdded);
  1234. $scope.$applyAsync(function() {
  1235. var rightMostContainer = $scope.grid.renderContainers['right'] && $scope.grid.renderContainers['right'].visibleColumnCache.length ?
  1236. $scope.grid.renderContainers['right'] : $scope.grid.renderContainers['body'];
  1237. $scope.isLastCol = uiGridCtrl.grid.options && uiGridCtrl.grid.options.enableGridMenu &&
  1238. $scope.col === rightMostContainer.visibleColumnCache[ rightMostContainer.visibleColumnCache.length - 1 ];
  1239. });
  1240. // Figure out whether this column is sortable or not
  1241. $scope.sortable = Boolean($scope.col.enableSorting);
  1242. // Figure out whether this column is filterable or not
  1243. var oldFilterable = $scope.filterable;
  1244. $scope.filterable = Boolean(uiGridCtrl.grid.options.enableFiltering && $scope.col.enableFiltering);
  1245. if ( oldFilterable !== $scope.filterable){
  1246. if ( typeof($scope.col.updateFilters) !== 'undefined' ){
  1247. $scope.col.updateFilters($scope.filterable);
  1248. }
  1249. // if column is filterable add a filter watcher
  1250. if ($scope.filterable) {
  1251. $scope.col.filters.forEach( function(filter, i) {
  1252. filterDeregisters.push($scope.$watch('col.filters[' + i + '].term', function(n, o) {
  1253. if (n !== o) {
  1254. uiGridCtrl.grid.api.core.raise.filterChanged();
  1255. uiGridCtrl.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN );
  1256. uiGridCtrl.grid.queueGridRefresh();
  1257. }
  1258. }));
  1259. });
  1260. $scope.$on('$destroy', function() {
  1261. filterDeregisters.forEach( function(filterDeregister) {
  1262. filterDeregister();
  1263. });
  1264. });
  1265. } else {
  1266. filterDeregisters.forEach( function(filterDeregister) {
  1267. filterDeregister();
  1268. });
  1269. }
  1270. }
  1271. // figure out whether we support column menus
  1272. if ($scope.col.grid.options && $scope.col.grid.options.enableColumnMenus !== false &&
  1273. $scope.col.colDef && $scope.col.colDef.enableColumnMenu !== false){
  1274. $scope.colMenu = true;
  1275. } else {
  1276. $scope.colMenu = false;
  1277. }
  1278. /**
  1279. * @ngdoc property
  1280. * @name enableColumnMenu
  1281. * @propertyOf ui.grid.class:GridOptions.columnDef
  1282. * @description if column menus are enabled, controls the column menus for this specific
  1283. * column (i.e. if gridOptions.enableColumnMenus, then you can control column menus
  1284. * using this option. If gridOptions.enableColumnMenus === false then you get no column
  1285. * menus irrespective of the value of this option ). Defaults to true.
  1286. *
  1287. * By default column menu's trigger is hidden before mouse over, but you can always force it to be visible with CSS:
  1288. *
  1289. * <pre>
  1290. * .ui-grid-column-menu-button {
  1291. * display: block;
  1292. * }
  1293. * </pre>
  1294. */
  1295. /**
  1296. * @ngdoc property
  1297. * @name enableColumnMenus
  1298. * @propertyOf ui.grid.class:GridOptions.columnDef
  1299. * @description Override for column menus everywhere - if set to false then you get no
  1300. * column menus. Defaults to true.
  1301. *
  1302. */
  1303. $scope.offAllEvents();
  1304. if ($scope.sortable || $scope.colMenu) {
  1305. $scope.onDownEvents();
  1306. $scope.$on('$destroy', function () {
  1307. $scope.offAllEvents();
  1308. });
  1309. }
  1310. };
  1311. /*
  1312. $scope.$watch('col', function (n, o) {
  1313. if (n !== o) {
  1314. // See if the column's internal class has changed
  1315. var newColClass = $scope.col.getColClass(false);
  1316. if (newColClass !== initColClass) {
  1317. $elm.removeClass(initColClass);
  1318. $elm.addClass(newColClass);
  1319. initColClass = newColClass;
  1320. }
  1321. }
  1322. });
  1323. */
  1324. updateHeaderOptions();
  1325. // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs
  1326. var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateHeaderOptions, [uiGridConstants.dataChange.COLUMN]);
  1327. $scope.$on( '$destroy', dataChangeDereg );
  1328. $scope.handleClick = function(event) {
  1329. // If the shift key is being held down, add this column to the sort
  1330. var add = false;
  1331. if (event.shiftKey) {
  1332. add = true;
  1333. }
  1334. // Sort this column then rebuild the grid's rows
  1335. uiGridCtrl.grid.sortColumn($scope.col, add)
  1336. .then(function () {
  1337. if (uiGridCtrl.columnMenuScope) { uiGridCtrl.columnMenuScope.hideMenu(); }
  1338. uiGridCtrl.grid.refresh();
  1339. }).catch(angular.noop);
  1340. };
  1341. $scope.headerCellArrowKeyDown = function(event) {
  1342. if (event.keyCode === 32 || event.keyCode === 13) {
  1343. event.preventDefault();
  1344. $scope.toggleMenu(event);
  1345. }
  1346. };
  1347. $scope.toggleMenu = function(event) {
  1348. event.stopPropagation();
  1349. // If the menu is already showing...
  1350. if (uiGridCtrl.columnMenuScope.menuShown) {
  1351. // ... and we're the column the menu is on...
  1352. if (uiGridCtrl.columnMenuScope.col === $scope.col) {
  1353. // ... hide it
  1354. uiGridCtrl.columnMenuScope.hideMenu();
  1355. }
  1356. // ... and we're NOT the column the menu is on
  1357. else {
  1358. // ... move the menu to our column
  1359. uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm);
  1360. }
  1361. }
  1362. // If the menu is NOT showing
  1363. else {
  1364. // ... show it on our column
  1365. uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm);
  1366. }
  1367. };
  1368. }
  1369. };
  1370. }
  1371. };
  1372. return uiGridHeaderCell;
  1373. }]);
  1374. })();
  1375. (function(){
  1376. 'use strict';
  1377. angular.module('ui.grid').directive('uiGridHeader', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', '$timeout', 'ScrollEvent',
  1378. function($templateCache, $compile, uiGridConstants, gridUtil, $timeout, ScrollEvent) {
  1379. var defaultTemplate = 'ui-grid/ui-grid-header';
  1380. var emptyTemplate = 'ui-grid/ui-grid-no-header';
  1381. return {
  1382. restrict: 'EA',
  1383. // templateUrl: 'ui-grid/ui-grid-header',
  1384. replace: true,
  1385. // priority: 1000,
  1386. require: ['^uiGrid', '^uiGridRenderContainer'],
  1387. scope: true,
  1388. compile: function($elm, $attrs) {
  1389. return {
  1390. pre: function ($scope, $elm, $attrs, controllers) {
  1391. var uiGridCtrl = controllers[0];
  1392. var containerCtrl = controllers[1];
  1393. $scope.grid = uiGridCtrl.grid;
  1394. $scope.colContainer = containerCtrl.colContainer;
  1395. updateHeaderReferences();
  1396. var headerTemplate;
  1397. if (!$scope.grid.options.showHeader) {
  1398. headerTemplate = emptyTemplate;
  1399. }
  1400. else {
  1401. headerTemplate = ($scope.grid.options.headerTemplate) ? $scope.grid.options.headerTemplate : defaultTemplate;
  1402. }
  1403. gridUtil.getTemplate(headerTemplate)
  1404. .then(function (contents) {
  1405. var template = angular.element(contents);
  1406. var newElm = $compile(template)($scope);
  1407. $elm.replaceWith(newElm);
  1408. // And update $elm to be the new element
  1409. $elm = newElm;
  1410. updateHeaderReferences();
  1411. if (containerCtrl) {
  1412. // Inject a reference to the header viewport (if it exists) into the grid controller for use in the horizontal scroll handler below
  1413. var headerViewport = $elm[0].getElementsByClassName('ui-grid-header-viewport')[0];
  1414. if (headerViewport) {
  1415. containerCtrl.headerViewport = headerViewport;
  1416. angular.element(headerViewport).on('scroll', scrollHandler);
  1417. $scope.$on('$destroy', function () {
  1418. angular.element(headerViewport).off('scroll', scrollHandler);
  1419. });
  1420. }
  1421. }
  1422. $scope.grid.queueRefresh();
  1423. }).catch(angular.noop);
  1424. function updateHeaderReferences() {
  1425. containerCtrl.header = containerCtrl.colContainer.header = $elm;
  1426. var headerCanvases = $elm[0].getElementsByClassName('ui-grid-header-canvas');
  1427. if (headerCanvases.length > 0) {
  1428. containerCtrl.headerCanvas = containerCtrl.colContainer.headerCanvas = headerCanvases[0];
  1429. }
  1430. else {
  1431. containerCtrl.headerCanvas = null;
  1432. }
  1433. }
  1434. function scrollHandler(evt) {
  1435. if (uiGridCtrl.grid.isScrollingHorizontally) {
  1436. return;
  1437. }
  1438. var newScrollLeft = gridUtil.normalizeScrollLeft(containerCtrl.headerViewport, uiGridCtrl.grid);
  1439. var horizScrollPercentage = containerCtrl.colContainer.scrollHorizontal(newScrollLeft);
  1440. var scrollEvent = new ScrollEvent(uiGridCtrl.grid, null, containerCtrl.colContainer, ScrollEvent.Sources.ViewPortScroll);
  1441. scrollEvent.newScrollLeft = newScrollLeft;
  1442. if ( horizScrollPercentage > -1 ){
  1443. scrollEvent.x = { percentage: horizScrollPercentage };
  1444. }
  1445. uiGridCtrl.grid.scrollContainers(null, scrollEvent);
  1446. }
  1447. },
  1448. post: function ($scope, $elm, $attrs, controllers) {
  1449. var uiGridCtrl = controllers[0];
  1450. var containerCtrl = controllers[1];
  1451. // gridUtil.logDebug('ui-grid-header link');
  1452. var grid = uiGridCtrl.grid;
  1453. // Don't animate header cells
  1454. gridUtil.disableAnimations($elm);
  1455. function updateColumnWidths() {
  1456. // this styleBuilder always runs after the renderContainer, so we can rely on the column widths
  1457. // already being populated correctly
  1458. var columnCache = containerCtrl.colContainer.visibleColumnCache;
  1459. // Build the CSS
  1460. // uiGridCtrl.grid.columns.forEach(function (column) {
  1461. var ret = '';
  1462. var canvasWidth = 0;
  1463. columnCache.forEach(function (column) {
  1464. ret = ret + column.getColClassDefinition();
  1465. canvasWidth += column.drawnWidth;
  1466. });
  1467. containerCtrl.colContainer.canvasWidth = canvasWidth;
  1468. // Return the styles back to buildStyles which pops them into the `customStyles` scope variable
  1469. return ret;
  1470. }
  1471. containerCtrl.header = $elm;
  1472. var headerViewport = $elm[0].getElementsByClassName('ui-grid-header-viewport')[0];
  1473. if (headerViewport) {
  1474. containerCtrl.headerViewport = headerViewport;
  1475. }
  1476. //todo: remove this if by injecting gridCtrl into unit tests
  1477. if (uiGridCtrl) {
  1478. uiGridCtrl.grid.registerStyleComputation({
  1479. priority: 15,
  1480. func: updateColumnWidths
  1481. });
  1482. }
  1483. }
  1484. };
  1485. }
  1486. };
  1487. }]);
  1488. })();
  1489. (function(){
  1490. angular.module('ui.grid')
  1491. .service('uiGridGridMenuService', [ 'gridUtil', 'i18nService', 'uiGridConstants', function( gridUtil, i18nService, uiGridConstants ) {
  1492. /**
  1493. * @ngdoc service
  1494. * @name ui.grid.uiGridGridMenuService
  1495. *
  1496. * @description Methods for working with the grid menu
  1497. */
  1498. var service = {
  1499. /**
  1500. * @ngdoc method
  1501. * @methodOf ui.grid.uiGridGridMenuService
  1502. * @name initialize
  1503. * @description Sets up the gridMenu. Most importantly, sets our
  1504. * scope onto the grid object as grid.gridMenuScope, allowing us
  1505. * to operate when passed only the grid. Second most importantly,
  1506. * we register the 'addToGridMenu' and 'removeFromGridMenu' methods
  1507. * on the core api.
  1508. * @param {$scope} $scope the scope of this gridMenu
  1509. * @param {Grid} grid the grid to which this gridMenu is associated
  1510. */
  1511. initialize: function( $scope, grid ){
  1512. grid.gridMenuScope = $scope;
  1513. $scope.grid = grid;
  1514. $scope.registeredMenuItems = [];
  1515. // not certain this is needed, but would be bad to create a memory leak
  1516. $scope.$on('$destroy', function() {
  1517. if ( $scope.grid && $scope.grid.gridMenuScope ){
  1518. $scope.grid.gridMenuScope = null;
  1519. }
  1520. if ( $scope.grid ){
  1521. $scope.grid = null;
  1522. }
  1523. if ( $scope.registeredMenuItems ){
  1524. $scope.registeredMenuItems = null;
  1525. }
  1526. });
  1527. $scope.registeredMenuItems = [];
  1528. /**
  1529. * @ngdoc function
  1530. * @name addToGridMenu
  1531. * @methodOf ui.grid.core.api:PublicApi
  1532. * @description add items to the grid menu. Used by features
  1533. * to add their menu items if they are enabled, can also be used by
  1534. * end users to add menu items. This method has the advantage of allowing
  1535. * remove again, which can simplify management of which items are included
  1536. * in the menu when. (Noting that in most cases the shown and active functions
  1537. * provide a better way to handle visibility of menu items)
  1538. * @param {Grid} grid the grid on which we are acting
  1539. * @param {array} items menu items in the format as described in the tutorial, with
  1540. * the added note that if you want to use remove you must also specify an `id` field,
  1541. * which is provided when you want to remove an item. The id should be unique.
  1542. *
  1543. */
  1544. grid.api.registerMethod( 'core', 'addToGridMenu', service.addToGridMenu );
  1545. /**
  1546. * @ngdoc function
  1547. * @name removeFromGridMenu
  1548. * @methodOf ui.grid.core.api:PublicApi
  1549. * @description Remove an item from the grid menu based on a provided id. Assumes
  1550. * that the id is unique, removes only the last instance of that id. Does nothing if
  1551. * the specified id is not found
  1552. * @param {Grid} grid the grid on which we are acting
  1553. * @param {string} id the id we'd like to remove from the menu
  1554. *
  1555. */
  1556. grid.api.registerMethod( 'core', 'removeFromGridMenu', service.removeFromGridMenu );
  1557. },
  1558. /**
  1559. * @ngdoc function
  1560. * @name addToGridMenu
  1561. * @propertyOf ui.grid.uiGridGridMenuService
  1562. * @description add items to the grid menu. Used by features
  1563. * to add their menu items if they are enabled, can also be used by
  1564. * end users to add menu items. This method has the advantage of allowing
  1565. * remove again, which can simplify management of which items are included
  1566. * in the menu when. (Noting that in most cases the shown and active functions
  1567. * provide a better way to handle visibility of menu items)
  1568. * @param {Grid} grid the grid on which we are acting
  1569. * @param {array} menuItems menu items in the format as described in the tutorial, with
  1570. * the added note that if you want to use remove you must also specify an `id` field,
  1571. * which is provided when you want to remove an item. The id should be unique.
  1572. *
  1573. */
  1574. addToGridMenu: function( grid, menuItems ) {
  1575. if ( !angular.isArray( menuItems ) ) {
  1576. gridUtil.logError( 'addToGridMenu: menuItems must be an array, and is not, not adding any items');
  1577. } else {
  1578. if ( grid.gridMenuScope ){
  1579. grid.gridMenuScope.registeredMenuItems = grid.gridMenuScope.registeredMenuItems ? grid.gridMenuScope.registeredMenuItems : [];
  1580. grid.gridMenuScope.registeredMenuItems = grid.gridMenuScope.registeredMenuItems.concat( menuItems );
  1581. } else {
  1582. gridUtil.logError( 'Asked to addToGridMenu, but gridMenuScope not present. Timing issue? Please log issue with ui-grid');
  1583. }
  1584. }
  1585. },
  1586. /**
  1587. * @ngdoc function
  1588. * @name removeFromGridMenu
  1589. * @methodOf ui.grid.uiGridGridMenuService
  1590. * @description Remove an item from the grid menu based on a provided id. Assumes
  1591. * that the id is unique, removes only the last instance of that id. Does nothing if
  1592. * the specified id is not found. If there is no gridMenuScope or registeredMenuItems
  1593. * then do nothing silently - the desired result is those menu items not be present and they
  1594. * aren't.
  1595. * @param {Grid} grid the grid on which we are acting
  1596. * @param {string} id the id we'd like to remove from the menu
  1597. *
  1598. */
  1599. removeFromGridMenu: function( grid, id ){
  1600. var foundIndex = -1;
  1601. if ( grid && grid.gridMenuScope ){
  1602. grid.gridMenuScope.registeredMenuItems.forEach( function( value, index ) {
  1603. if ( value.id === id ){
  1604. if (foundIndex > -1) {
  1605. gridUtil.logError( 'removeFromGridMenu: found multiple items with the same id, removing only the last' );
  1606. } else {
  1607. foundIndex = index;
  1608. }
  1609. }
  1610. });
  1611. }
  1612. if ( foundIndex > -1 ){
  1613. grid.gridMenuScope.registeredMenuItems.splice( foundIndex, 1 );
  1614. }
  1615. },
  1616. /**
  1617. * @ngdoc array
  1618. * @name gridMenuCustomItems
  1619. * @propertyOf ui.grid.class:GridOptions
  1620. * @description (optional) An array of menu items that should be added to
  1621. * the gridMenu. Follow the format documented in the tutorial for column
  1622. * menu customisation. The context provided to the action function will
  1623. * include context.grid. An alternative if working with dynamic menus is to use the
  1624. * provided api - core.addToGridMenu and core.removeFromGridMenu, which handles
  1625. * some of the management of items for you.
  1626. *
  1627. */
  1628. /**
  1629. * @ngdoc boolean
  1630. * @name gridMenuShowHideColumns
  1631. * @propertyOf ui.grid.class:GridOptions
  1632. * @description true by default, whether the grid menu should allow hide/show
  1633. * of columns
  1634. *
  1635. */
  1636. /**
  1637. * @ngdoc method
  1638. * @methodOf ui.grid.uiGridGridMenuService
  1639. * @name getMenuItems
  1640. * @description Decides the menu items to show in the menu. This is a
  1641. * combination of:
  1642. *
  1643. * - the default menu items that are always included,
  1644. * - any menu items that have been provided through the addMenuItem api. These
  1645. * are typically added by features within the grid
  1646. * - any menu items included in grid.options.gridMenuCustomItems. These can be
  1647. * changed dynamically, as they're always recalculated whenever we show the
  1648. * menu
  1649. * @param {$scope} $scope the scope of this gridMenu, from which we can find all
  1650. * the information that we need
  1651. * @returns {Array} an array of menu items that can be shown
  1652. */
  1653. getMenuItems: function( $scope ) {
  1654. var menuItems = [
  1655. // this is where we add any menu items we want to always include
  1656. ];
  1657. if ( $scope.grid.options.gridMenuCustomItems ){
  1658. if ( !angular.isArray( $scope.grid.options.gridMenuCustomItems ) ){
  1659. gridUtil.logError( 'gridOptions.gridMenuCustomItems must be an array, and is not');
  1660. } else {
  1661. menuItems = menuItems.concat( $scope.grid.options.gridMenuCustomItems );
  1662. }
  1663. }
  1664. var clearFilters = [{
  1665. title: i18nService.getSafeText('gridMenu.clearAllFilters'),
  1666. action: function ($event) {
  1667. $scope.grid.clearAllFilters();
  1668. },
  1669. shown: function() {
  1670. return $scope.grid.options.enableFiltering;
  1671. },
  1672. order: 100
  1673. }];
  1674. menuItems = menuItems.concat( clearFilters );
  1675. menuItems = menuItems.concat( $scope.registeredMenuItems );
  1676. if ( $scope.grid.options.gridMenuShowHideColumns !== false ){
  1677. menuItems = menuItems.concat( service.showHideColumns( $scope ) );
  1678. }
  1679. menuItems.sort(function(a, b){
  1680. return a.order - b.order;
  1681. });
  1682. return menuItems;
  1683. },
  1684. /**
  1685. * @ngdoc array
  1686. * @name gridMenuTitleFilter
  1687. * @propertyOf ui.grid.class:GridOptions
  1688. * @description (optional) A function that takes a title string
  1689. * (usually the col.displayName), and converts it into a display value. The function
  1690. * must return either a string or a promise.
  1691. *
  1692. * Used for internationalization of the grid menu column names - for angular-translate
  1693. * you can pass $translate as the function, for i18nService you can pass getSafeText as the
  1694. * function
  1695. * @example
  1696. * <pre>
  1697. * gridOptions = {
  1698. * gridMenuTitleFilter: $translate
  1699. * }
  1700. * </pre>
  1701. */
  1702. /**
  1703. * @ngdoc method
  1704. * @methodOf ui.grid.uiGridGridMenuService
  1705. * @name showHideColumns
  1706. * @description Adds two menu items for each of the columns in columnDefs. One
  1707. * menu item for hide, one menu item for show. Each is visible when appropriate
  1708. * (show when column is not visible, hide when column is visible). Each toggles
  1709. * the visible property on the columnDef using toggleColumnVisibility
  1710. * @param {$scope} $scope of a gridMenu, which contains a reference to the grid
  1711. */
  1712. showHideColumns: function( $scope ){
  1713. var showHideColumns = [];
  1714. if ( !$scope.grid.options.columnDefs || $scope.grid.options.columnDefs.length === 0 || $scope.grid.columns.length === 0 ) {
  1715. return showHideColumns;
  1716. }
  1717. function isColumnVisible(colDef) {
  1718. return colDef.visible === true || colDef.visible === undefined;
  1719. }
  1720. // add header for columns
  1721. showHideColumns.push({
  1722. title: i18nService.getSafeText('gridMenu.columns'),
  1723. order: 300
  1724. });
  1725. $scope.grid.options.gridMenuTitleFilter = $scope.grid.options.gridMenuTitleFilter ? $scope.grid.options.gridMenuTitleFilter : function( title ) { return title; };
  1726. $scope.grid.options.columnDefs.forEach( function( colDef, index ){
  1727. if ( colDef.enableHiding !== false ){
  1728. // add hide menu item - shows an OK icon as we only show when column is already visible
  1729. var menuItem = {
  1730. icon: isColumnVisible(colDef) ? 'ui-grid-icon-ok' : 'ui-grid-icon-cancel',
  1731. action: function($event) {
  1732. $event.stopPropagation();
  1733. service.toggleColumnVisibility( this.context.gridCol );
  1734. if ($event.target && $event.target.firstChild) {
  1735. $event.target.firstChild.className = isColumnVisible(this.context.gridCol.colDef) ?
  1736. 'ui-grid-icon-ok' : 'ui-grid-icon-cancel';
  1737. }
  1738. },
  1739. shown: function() {
  1740. return this.context.gridCol.colDef.enableHiding !== false;
  1741. },
  1742. context: { gridCol: $scope.grid.getColumn(colDef.name || colDef.field) },
  1743. leaveOpen: true,
  1744. order: 301 + index
  1745. };
  1746. service.setMenuItemTitle( menuItem, colDef, $scope.grid );
  1747. showHideColumns.push( menuItem );
  1748. }
  1749. });
  1750. return showHideColumns;
  1751. },
  1752. /**
  1753. * @ngdoc method
  1754. * @methodOf ui.grid.uiGridGridMenuService
  1755. * @name setMenuItemTitle
  1756. * @description Handles the response from gridMenuTitleFilter, adding it directly to the menu
  1757. * item if it returns a string, otherwise waiting for the promise to resolve or reject then
  1758. * putting the result into the title
  1759. * @param {object} menuItem the menuItem we want to put the title on
  1760. * @param {object} colDef the colDef from which we can get displayName, name or field
  1761. * @param {Grid} grid the grid, from which we can get the options.gridMenuTitleFilter
  1762. *
  1763. */
  1764. setMenuItemTitle: function( menuItem, colDef, grid ){
  1765. var title = grid.options.gridMenuTitleFilter( colDef.displayName || gridUtil.readableColumnName(colDef.name) || colDef.field );
  1766. if ( typeof(title) === 'string' ){
  1767. menuItem.title = title;
  1768. } else if ( title.then ){
  1769. // must be a promise
  1770. menuItem.title = "";
  1771. title.then( function( successValue ) {
  1772. menuItem.title = successValue;
  1773. }, function( errorValue ) {
  1774. menuItem.title = errorValue;
  1775. }).catch(angular.noop);
  1776. } else {
  1777. gridUtil.logError('Expected gridMenuTitleFilter to return a string or a promise, it has returned neither, bad config');
  1778. menuItem.title = 'badconfig';
  1779. }
  1780. },
  1781. /**
  1782. * @ngdoc method
  1783. * @methodOf ui.grid.uiGridGridMenuService
  1784. * @name toggleColumnVisibility
  1785. * @description Toggles the visibility of an individual column. Expects to be
  1786. * provided a context that has on it a gridColumn, which is the column that
  1787. * we'll operate upon. We change the visibility, and refresh the grid as appropriate
  1788. * @param {GridColumn} gridCol the column that we want to toggle
  1789. *
  1790. */
  1791. toggleColumnVisibility: function( gridCol ) {
  1792. gridCol.colDef.visible = !( gridCol.colDef.visible === true || gridCol.colDef.visible === undefined );
  1793. gridCol.grid.refresh();
  1794. gridCol.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN );
  1795. gridCol.grid.api.core.raise.columnVisibilityChanged( gridCol );
  1796. }
  1797. };
  1798. return service;
  1799. }])
  1800. .directive('uiGridMenuButton', ['gridUtil', 'uiGridConstants', 'uiGridGridMenuService', 'i18nService',
  1801. function (gridUtil, uiGridConstants, uiGridGridMenuService, i18nService) {
  1802. return {
  1803. priority: 0,
  1804. scope: true,
  1805. require: ['^uiGrid'],
  1806. templateUrl: 'ui-grid/ui-grid-menu-button',
  1807. replace: true,
  1808. link: function ($scope, $elm, $attrs, controllers) {
  1809. var uiGridCtrl = controllers[0];
  1810. // For the aria label
  1811. $scope.i18n = {
  1812. aria: i18nService.getSafeText('gridMenu.aria')
  1813. };
  1814. uiGridGridMenuService.initialize($scope, uiGridCtrl.grid);
  1815. $scope.shown = false;
  1816. $scope.toggleMenu = function () {
  1817. if ( $scope.shown ){
  1818. $scope.$broadcast('hide-menu');
  1819. $scope.shown = false;
  1820. } else {
  1821. $scope.menuItems = uiGridGridMenuService.getMenuItems( $scope );
  1822. $scope.$broadcast('show-menu');
  1823. $scope.shown = true;
  1824. }
  1825. };
  1826. $scope.$on('menu-hidden', function() {
  1827. $scope.shown = false;
  1828. gridUtil.focus.bySelector($elm, '.ui-grid-icon-container');
  1829. });
  1830. }
  1831. };
  1832. }]);
  1833. })();
  1834. (function(){
  1835. /**
  1836. * @ngdoc directive
  1837. * @name ui.grid.directive:uiGridMenu
  1838. * @element style
  1839. * @restrict A
  1840. *
  1841. * @description
  1842. * Allows us to interpolate expressions in `<style>` elements. Angular doesn't do this by default as it can/will/might? break in IE8.
  1843. *
  1844. * @example
  1845. <doc:example module="app">
  1846. <doc:source>
  1847. <script>
  1848. var app = angular.module('app', ['ui.grid']);
  1849. app.controller('MainCtrl', ['$scope', function ($scope) {
  1850. }]);
  1851. </script>
  1852. <div ng-controller="MainCtrl">
  1853. <div ui-grid-menu shown="true" ></div>
  1854. </div>
  1855. </doc:source>
  1856. <doc:scenario>
  1857. </doc:scenario>
  1858. </doc:example>
  1859. */
  1860. angular.module('ui.grid')
  1861. .directive('uiGridMenu', ['$compile', '$timeout', '$window', '$document', 'gridUtil', 'uiGridConstants', 'i18nService',
  1862. function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18nService) {
  1863. var uiGridMenu = {
  1864. priority: 0,
  1865. scope: {
  1866. // shown: '&',
  1867. menuItems: '=',
  1868. autoHide: '=?'
  1869. },
  1870. require: '?^uiGrid',
  1871. templateUrl: 'ui-grid/uiGridMenu',
  1872. replace: false,
  1873. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  1874. $scope.dynamicStyles = '';
  1875. if (uiGridCtrl && uiGridCtrl.grid && uiGridCtrl.grid.options && uiGridCtrl.grid.options.gridMenuTemplate) {
  1876. var gridMenuTemplate = uiGridCtrl.grid.options.gridMenuTemplate;
  1877. gridUtil.getTemplate(gridMenuTemplate).then(function (contents) {
  1878. var template = angular.element(contents);
  1879. var newElm = $compile(template)($scope);
  1880. $elm.replaceWith(newElm);
  1881. }).catch(angular.noop);
  1882. }
  1883. var setupHeightStyle = function(gridHeight) {
  1884. //menu appears under header row, so substract that height from it's total
  1885. // additional 20px for general padding
  1886. var gridMenuMaxHeight = gridHeight - uiGridCtrl.grid.headerHeight - 20;
  1887. $scope.dynamicStyles = [
  1888. '.grid' + uiGridCtrl.grid.id + ' .ui-grid-menu-mid {',
  1889. 'max-height: ' + gridMenuMaxHeight + 'px;',
  1890. '}'
  1891. ].join(' ');
  1892. };
  1893. if (uiGridCtrl) {
  1894. setupHeightStyle(uiGridCtrl.grid.gridHeight);
  1895. uiGridCtrl.grid.api.core.on.gridDimensionChanged($scope, function(oldGridHeight, oldGridWidth, newGridHeight, newGridWidth) {
  1896. setupHeightStyle(newGridHeight);
  1897. });
  1898. }
  1899. $scope.i18n = {
  1900. close: i18nService.getSafeText('columnMenu.close')
  1901. };
  1902. // *** Show/Hide functions ******
  1903. $scope.showMenu = function(event, args) {
  1904. if ( !$scope.shown ){
  1905. /*
  1906. * In order to animate cleanly we remove the ng-if, wait a digest cycle, then
  1907. * animate the removal of the ng-hide. We can't successfully (so far as I can tell)
  1908. * animate removal of the ng-if, as the menu items aren't there yet. And we don't want
  1909. * to rely on ng-show only, as that leaves elements in the DOM that are needlessly evaluated
  1910. * on scroll events.
  1911. *
  1912. * Note when testing animation that animations don't run on the tutorials. When debugging it looks
  1913. * like they do, but angular has a default $animate provider that is just a stub, and that's what's
  1914. * being called. ALso don't be fooled by the fact that your browser has actually loaded the
  1915. * angular-translate.js, it's not using it. You need to test animations in an external application.
  1916. */
  1917. $scope.shown = true;
  1918. // Must be a timeout in order to work properly in Firefox. Issue #6533
  1919. $timeout(function() {
  1920. $scope.shownMid = true;
  1921. $scope.$emit('menu-shown');
  1922. });
  1923. } else if ( !$scope.shownMid ) {
  1924. // we're probably doing a hide then show, so we don't need to wait for ng-if
  1925. $scope.shownMid = true;
  1926. $scope.$emit('menu-shown');
  1927. }
  1928. var docEventType = 'click';
  1929. if (args && args.originalEvent && args.originalEvent.type && args.originalEvent.type === 'touchstart') {
  1930. docEventType = args.originalEvent.type;
  1931. }
  1932. // Turn off an existing document click handler
  1933. angular.element(document).off('click touchstart', applyHideMenu);
  1934. $elm.off('keyup', checkKeyUp);
  1935. $elm.off('keydown', checkKeyDown);
  1936. // Turn on the document click handler, but in a timeout so it doesn't apply to THIS click if there is one
  1937. $timeout(function() {
  1938. angular.element(document).on(docEventType, applyHideMenu);
  1939. $elm.on('keyup', checkKeyUp);
  1940. $elm.on('keydown', checkKeyDown);
  1941. });
  1942. };
  1943. $scope.hideMenu = function(event) {
  1944. if ( $scope.shown ){
  1945. /*
  1946. * In order to animate cleanly we animate the addition of ng-hide, then use a $timeout to
  1947. * set the ng-if (shown = false) after the animation runs. In theory we can cascade off the
  1948. * callback on the addClass method, but it is very unreliable with unit tests for no discernable reason.
  1949. *
  1950. * The user may have clicked on the menu again whilst
  1951. * we're waiting, so we check that the mid isn't shown before applying the ng-if.
  1952. */
  1953. $scope.shownMid = false;
  1954. $timeout( function() {
  1955. if ( !$scope.shownMid ){
  1956. $scope.shown = false;
  1957. $scope.$emit('menu-hidden');
  1958. }
  1959. }, 40);
  1960. }
  1961. angular.element(document).off('click touchstart', applyHideMenu);
  1962. $elm.off('keyup', checkKeyUp);
  1963. $elm.off('keydown', checkKeyDown);
  1964. };
  1965. $scope.$on('hide-menu', function (event, args) {
  1966. $scope.hideMenu(event, args);
  1967. });
  1968. $scope.$on('show-menu', function (event, args) {
  1969. $scope.showMenu(event, args);
  1970. });
  1971. // *** Auto hide when click elsewhere ******
  1972. var applyHideMenu = function(){
  1973. if ($scope.shown) {
  1974. $scope.$apply(function () {
  1975. $scope.hideMenu();
  1976. });
  1977. }
  1978. };
  1979. // close menu on ESC and keep tab cyclical
  1980. var checkKeyUp = function(event) {
  1981. if (event.keyCode === 27) {
  1982. $scope.hideMenu();
  1983. }
  1984. };
  1985. var checkKeyDown = function(event) {
  1986. var setFocus = function(elm) {
  1987. elm.focus();
  1988. event.preventDefault();
  1989. return false;
  1990. };
  1991. if (event.keyCode === 9) {
  1992. var firstMenuItem, lastMenuItem;
  1993. var menuItemButtons = $elm[0].querySelectorAll('button:not(.ng-hide)');
  1994. if (menuItemButtons.length > 0) {
  1995. firstMenuItem = menuItemButtons[0];
  1996. lastMenuItem = menuItemButtons[menuItemButtons.length - 1];
  1997. if (event.target === lastMenuItem && !event.shiftKey) {
  1998. setFocus(firstMenuItem);
  1999. } else if (event.target === firstMenuItem && event.shiftKey) {
  2000. setFocus(lastMenuItem);
  2001. }
  2002. }
  2003. }
  2004. };
  2005. if (typeof($scope.autoHide) === 'undefined' || $scope.autoHide === undefined) {
  2006. $scope.autoHide = true;
  2007. }
  2008. if ($scope.autoHide) {
  2009. angular.element($window).on('resize', applyHideMenu);
  2010. }
  2011. $scope.$on('$destroy', function unbindEvents() {
  2012. angular.element($window).off('resize', applyHideMenu);
  2013. angular.element(document).off('click touchstart', applyHideMenu);
  2014. $elm.off('keyup', checkKeyUp);
  2015. $elm.off('keydown', checkKeyDown);
  2016. });
  2017. if (uiGridCtrl) {
  2018. $scope.$on('$destroy', uiGridCtrl.grid.api.core.on.scrollBegin($scope, applyHideMenu ));
  2019. }
  2020. $scope.$on('$destroy', $scope.$on(uiGridConstants.events.ITEM_DRAGGING, applyHideMenu ));
  2021. }
  2022. };
  2023. return uiGridMenu;
  2024. }])
  2025. .directive('uiGridMenuItem', ['gridUtil', '$compile', 'i18nService', function (gridUtil, $compile, i18nService) {
  2026. var uiGridMenuItem = {
  2027. priority: 0,
  2028. scope: {
  2029. name: '=',
  2030. active: '=',
  2031. action: '=',
  2032. icon: '=',
  2033. shown: '=',
  2034. context: '=',
  2035. templateUrl: '=',
  2036. leaveOpen: '=',
  2037. screenReaderOnly: '='
  2038. },
  2039. require: ['?^uiGrid'],
  2040. templateUrl: 'ui-grid/uiGridMenuItem',
  2041. replace: false,
  2042. compile: function() {
  2043. return {
  2044. pre: function ($scope, $elm) {
  2045. if ($scope.templateUrl) {
  2046. gridUtil.getTemplate($scope.templateUrl)
  2047. .then(function (contents) {
  2048. var template = angular.element(contents);
  2049. var newElm = $compile(template)($scope);
  2050. $elm.replaceWith(newElm);
  2051. }).catch(angular.noop);
  2052. }
  2053. },
  2054. post: function ($scope, $elm, $attrs, controllers) {
  2055. var uiGridCtrl = controllers[0];
  2056. // TODO(c0bra): validate that shown and active are functions if they're defined. An exception is already thrown above this though
  2057. // if (typeof($scope.shown) !== 'undefined' && $scope.shown && typeof($scope.shown) !== 'function') {
  2058. // throw new TypeError("$scope.shown is defined but not a function");
  2059. // }
  2060. if (typeof($scope.shown) === 'undefined' || $scope.shown === null) {
  2061. $scope.shown = function() { return true; };
  2062. }
  2063. $scope.itemShown = function () {
  2064. var context = {};
  2065. if ($scope.context) {
  2066. context.context = $scope.context;
  2067. }
  2068. if (typeof(uiGridCtrl) !== 'undefined' && uiGridCtrl) {
  2069. context.grid = uiGridCtrl.grid;
  2070. }
  2071. return $scope.shown.call(context);
  2072. };
  2073. $scope.itemAction = function($event,title) {
  2074. $event.stopPropagation();
  2075. if (typeof($scope.action) === 'function') {
  2076. var context = {};
  2077. if ($scope.context) {
  2078. context.context = $scope.context;
  2079. }
  2080. // Add the grid to the function call context if the uiGrid controller is present
  2081. if (typeof(uiGridCtrl) !== 'undefined' && uiGridCtrl) {
  2082. context.grid = uiGridCtrl.grid;
  2083. }
  2084. $scope.action.call(context, $event, title);
  2085. if ( !$scope.leaveOpen ){
  2086. $scope.$emit('hide-menu');
  2087. } else {
  2088. // Maintain focus on the selected item
  2089. var correctParent = $event.target.parentElement;
  2090. // nodeName of 'I' means target is i element, need the next parent
  2091. if (angular.element($event.target)[0].nodeName === 'I') {
  2092. correctParent = correctParent.parentElement;
  2093. }
  2094. gridUtil.focus.bySelector(correctParent, 'button[type=button]', true);
  2095. }
  2096. }
  2097. };
  2098. $scope.label = function(){
  2099. var toBeDisplayed = $scope.name;
  2100. if (typeof($scope.name) === 'function'){
  2101. toBeDisplayed = $scope.name.call();
  2102. }
  2103. return toBeDisplayed;
  2104. };
  2105. $scope.i18n = i18nService.get();
  2106. }
  2107. };
  2108. }
  2109. };
  2110. return uiGridMenuItem;
  2111. }]);
  2112. })();
  2113. (function(){
  2114. 'use strict';
  2115. /**
  2116. * @ngdoc overview
  2117. * @name ui.grid.directive:uiGridOneBind
  2118. * @summary A group of directives that provide a one time bind to a dom element.
  2119. * @description A group of directives that provide a one time bind to a dom element.
  2120. * As one time bindings are not supported in Angular 1.2.* this directive provdes this capability.
  2121. * This is done to reduce the number of watchers on the dom.
  2122. * <br/>
  2123. * <h2>Short Example ({@link ui.grid.directive:uiGridOneBindSrc ui-grid-one-bind-src})</h2>
  2124. * <pre>
  2125. <div ng-init="imageName = 'myImageDir.jpg'">
  2126. <img ui-grid-one-bind-src="imageName"></img>
  2127. </div>
  2128. </pre>
  2129. * Will become:
  2130. * <pre>
  2131. <div ng-init="imageName = 'myImageDir.jpg'">
  2132. <img ui-grid-one-bind-src="imageName" src="myImageDir.jpg"></img>
  2133. </div>
  2134. </pre>
  2135. </br>
  2136. <h2>Short Example ({@link ui.grid.directive:uiGridOneBindText ui-grid-one-bind-text})</h2>
  2137. * <pre>
  2138. <div ng-init="text='Add this text'" ui-grid-one-bind-text="text"></div>
  2139. </pre>
  2140. * Will become:
  2141. * <pre>
  2142. <div ng-init="text='Add this text'" ui-grid-one-bind-text="text">Add this text</div>
  2143. </pre>
  2144. </br>
  2145. * <b>Note:</b> This behavior is slightly different for the {@link ui.grid.directive:uiGridOneBindIdGrid uiGridOneBindIdGrid}
  2146. * and {@link ui.grid.directive:uiGridOneBindAriaLabelledbyGrid uiGridOneBindAriaLabelledbyGrid} directives.
  2147. *
  2148. */
  2149. //https://github.com/joshkurz/Black-Belt-AngularJS-Directives/blob/master/directives/Optimization/oneBind.js
  2150. var oneBinders = angular.module('ui.grid');
  2151. angular.forEach([
  2152. /**
  2153. * @ngdoc directive
  2154. * @name ui.grid.directive:uiGridOneBindSrc
  2155. * @memberof ui.grid.directive:uiGridOneBind
  2156. * @element img
  2157. * @restrict A
  2158. * @param {String} uiGridOneBindSrc The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2159. * @description One time binding for the src dom tag.
  2160. *
  2161. */
  2162. {tag: 'Src', method: 'attr'},
  2163. /**
  2164. * @ngdoc directive
  2165. * @name ui.grid.directive:uiGridOneBindText
  2166. * @element div
  2167. * @restrict A
  2168. * @param {String} uiGridOneBindText The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2169. * @description One time binding for the text dom tag.
  2170. */
  2171. {tag: 'Text', method: 'text'},
  2172. /**
  2173. * @ngdoc directive
  2174. * @name ui.grid.directive:uiGridOneBindHref
  2175. * @element div
  2176. * @restrict A
  2177. * @param {String} uiGridOneBindHref The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2178. * @description One time binding for the href dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2179. */
  2180. {tag: 'Href', method: 'attr'},
  2181. /**
  2182. * @ngdoc directive
  2183. * @name ui.grid.directive:uiGridOneBindClass
  2184. * @element div
  2185. * @restrict A
  2186. * @param {String} uiGridOneBindClass The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2187. * @param {Object} uiGridOneBindClass The object that you want to bind. At least one of the values in the object must be something other than null or undefined for the watcher to be removed.
  2188. * this is to prevent the watcher from being removed before the scope is initialized.
  2189. * @param {Array} uiGridOneBindClass An array of classes to bind to this element.
  2190. * @description One time binding for the class dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2191. */
  2192. {tag: 'Class', method: 'addClass'},
  2193. /**
  2194. * @ngdoc directive
  2195. * @name ui.grid.directive:uiGridOneBindHtml
  2196. * @element div
  2197. * @restrict A
  2198. * @param {String} uiGridOneBindHtml The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2199. * @description One time binding for the html method on a dom element. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2200. */
  2201. {tag: 'Html', method: 'html'},
  2202. /**
  2203. * @ngdoc directive
  2204. * @name ui.grid.directive:uiGridOneBindAlt
  2205. * @element div
  2206. * @restrict A
  2207. * @param {String} uiGridOneBindAlt The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2208. * @description One time binding for the alt dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2209. */
  2210. {tag: 'Alt', method: 'attr'},
  2211. /**
  2212. * @ngdoc directive
  2213. * @name ui.grid.directive:uiGridOneBindStyle
  2214. * @element div
  2215. * @restrict A
  2216. * @param {String} uiGridOneBindStyle The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2217. * @description One time binding for the style dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2218. */
  2219. {tag: 'Style', method: 'css'},
  2220. /**
  2221. * @ngdoc directive
  2222. * @name ui.grid.directive:uiGridOneBindValue
  2223. * @element div
  2224. * @restrict A
  2225. * @param {String} uiGridOneBindValue The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2226. * @description One time binding for the value dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2227. */
  2228. {tag: 'Value', method: 'attr'},
  2229. /**
  2230. * @ngdoc directive
  2231. * @name ui.grid.directive:uiGridOneBindId
  2232. * @element div
  2233. * @restrict A
  2234. * @param {String} uiGridOneBindId The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2235. * @description One time binding for the value dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2236. */
  2237. {tag: 'Id', method: 'attr'},
  2238. /**
  2239. * @ngdoc directive
  2240. * @name ui.grid.directive:uiGridOneBindIdGrid
  2241. * @element div
  2242. * @restrict A
  2243. * @param {String} uiGridOneBindIdGrid The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2244. * @description One time binding for the id dom tag.
  2245. * <h1>Important Note!</h1>
  2246. * If the id tag passed as a parameter does <b>not</b> contain the grid id as a substring
  2247. * then the directive will search the scope and the parent controller (if it is a uiGridController) for the grid.id value.
  2248. * If this value is found then it is appended to the begining of the id tag. If the grid is not found then the directive throws an error.
  2249. * This is done in order to ensure uniqueness of id tags across the grid.
  2250. * This is to prevent two grids in the same document having duplicate id tags.
  2251. */
  2252. {tag: 'Id', directiveName:'IdGrid', method: 'attr', appendGridId: true},
  2253. /**
  2254. * @ngdoc directive
  2255. * @name ui.grid.directive:uiGridOneBindTitle
  2256. * @element div
  2257. * @restrict A
  2258. * @param {String} uiGridOneBindTitle The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2259. * @description One time binding for the title dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2260. */
  2261. {tag: 'Title', method: 'attr'},
  2262. /**
  2263. * @ngdoc directive
  2264. * @name ui.grid.directive:uiGridOneBindAriaLabel
  2265. * @element div
  2266. * @restrict A
  2267. * @param {String} uiGridOneBindAriaLabel The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2268. * @description One time binding for the aria-label dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2269. *<br/>
  2270. * <pre>
  2271. <div ng-init="text='Add this text'" ui-grid-one-bind-aria-label="text"></div>
  2272. </pre>
  2273. * Will become:
  2274. * <pre>
  2275. <div ng-init="text='Add this text'" ui-grid-one-bind-aria-label="text" aria-label="Add this text"></div>
  2276. </pre>
  2277. */
  2278. {tag: 'Label', method: 'attr', aria:true},
  2279. /**
  2280. * @ngdoc directive
  2281. * @name ui.grid.directive:uiGridOneBindAriaLabelledby
  2282. * @element div
  2283. * @restrict A
  2284. * @param {String} uiGridOneBindAriaLabelledby The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2285. * @description One time binding for the aria-labelledby dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2286. *<br/>
  2287. * <pre>
  2288. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-labelledby="anId"></div>
  2289. </pre>
  2290. * Will become:
  2291. * <pre>
  2292. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-labelledby="anId" aria-labelledby="gridID32"></div>
  2293. </pre>
  2294. */
  2295. {tag: 'Labelledby', method: 'attr', aria:true},
  2296. /**
  2297. * @ngdoc directive
  2298. * @name ui.grid.directive:uiGridOneBindAriaLabelledbyGrid
  2299. * @element div
  2300. * @restrict A
  2301. * @param {String} uiGridOneBindAriaLabelledbyGrid The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2302. * @description One time binding for the aria-labelledby dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2303. * Works somewhat like {@link ui.grid.directive:uiGridOneBindIdGrid} however this one supports a list of ids (seperated by a space) and will dynamically add the
  2304. * grid id to each one.
  2305. *<br/>
  2306. * <pre>
  2307. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-labelledby-grid="anId"></div>
  2308. </pre>
  2309. * Will become ([grid.id] will be replaced by the actual grid id):
  2310. * <pre>
  2311. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-labelledby-grid="anId" aria-labelledby-Grid="[grid.id]-gridID32"></div>
  2312. </pre>
  2313. */
  2314. {tag: 'Labelledby', directiveName:'LabelledbyGrid', appendGridId:true, method: 'attr', aria:true},
  2315. /**
  2316. * @ngdoc directive
  2317. * @name ui.grid.directive:uiGridOneBindAriaDescribedby
  2318. * @element ANY
  2319. * @restrict A
  2320. * @param {String} uiGridOneBindAriaDescribedby The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2321. * @description One time binding for the aria-describedby dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2322. *<br/>
  2323. * <pre>
  2324. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-describedby="anId"></div>
  2325. </pre>
  2326. * Will become:
  2327. * <pre>
  2328. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-describedby="anId" aria-describedby="gridID32"></div>
  2329. </pre>
  2330. */
  2331. {tag: 'Describedby', method: 'attr', aria:true},
  2332. /**
  2333. * @ngdoc directive
  2334. * @name ui.grid.directive:uiGridOneBindAriaDescribedbyGrid
  2335. * @element ANY
  2336. * @restrict A
  2337. * @param {String} uiGridOneBindAriaDescribedbyGrid The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2338. * @description One time binding for the aria-labelledby dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2339. * Works somewhat like {@link ui.grid.directive:uiGridOneBindIdGrid} however this one supports a list of ids (seperated by a space) and will dynamically add the
  2340. * grid id to each one.
  2341. *<br/>
  2342. * <pre>
  2343. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-describedby-grid="anId"></div>
  2344. </pre>
  2345. * Will become ([grid.id] will be replaced by the actual grid id):
  2346. * <pre>
  2347. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-describedby-grid="anId" aria-describedby="[grid.id]-gridID32"></div>
  2348. </pre>
  2349. */
  2350. {tag: 'Describedby', directiveName:'DescribedbyGrid', appendGridId:true, method: 'attr', aria:true}],
  2351. function(v){
  2352. var baseDirectiveName = 'uiGridOneBind';
  2353. //If it is an aria tag then append the aria label seperately
  2354. //This is done because the aria tags are formatted aria-* and the directive name can't have a '-' character in it.
  2355. //If the diretiveName has to be overridden then it does so here. This is because the tag being modified and the directive sometimes don't match up.
  2356. var directiveName = (v.aria ? baseDirectiveName + 'Aria' : baseDirectiveName) + (v.directiveName ? v.directiveName : v.tag);
  2357. oneBinders.directive(directiveName, ['gridUtil', function(gridUtil){
  2358. return {
  2359. restrict: 'A',
  2360. require: ['?uiGrid','?^uiGrid'],
  2361. link: function(scope, iElement, iAttrs, controllers){
  2362. /* Appends the grid id to the beginnig of the value. */
  2363. var appendGridId = function(val){
  2364. var grid; //Get an instance of the grid if its available
  2365. //If its available in the scope then we don't need to try to find it elsewhere
  2366. if (scope.grid) {
  2367. grid = scope.grid;
  2368. }
  2369. //Another possible location to try to find the grid
  2370. else if (scope.col && scope.col.grid){
  2371. grid = scope.col.grid;
  2372. }
  2373. //Last ditch effort: Search through the provided controllers.
  2374. else if (!controllers.some( //Go through the controllers till one has the element we need
  2375. function(controller){
  2376. if (controller && controller.grid) {
  2377. grid = controller.grid;
  2378. return true; //We've found the grid
  2379. }
  2380. })){
  2381. //We tried our best to find it for you
  2382. gridUtil.logError("["+directiveName+"] A valid grid could not be found to bind id. Are you using this directive " +
  2383. "within the correct scope? Trying to generate id: [gridID]-" + val);
  2384. throw new Error("No valid grid could be found");
  2385. }
  2386. if (grid){
  2387. var idRegex = new RegExp(grid.id.toString());
  2388. //If the grid id hasn't been appended already in the template declaration
  2389. if (!idRegex.test(val)){
  2390. val = grid.id.toString() + '-' + val;
  2391. }
  2392. }
  2393. return val;
  2394. };
  2395. // The watch returns a function to remove itself.
  2396. var rmWatcher = scope.$watch(iAttrs[directiveName], function(newV){
  2397. if (newV){
  2398. //If we are trying to add an id element then we also apply the grid id if it isn't already there
  2399. if (v.appendGridId) {
  2400. var newIdString = null;
  2401. //Append the id to all of the new ids.
  2402. angular.forEach( newV.split(' '), function(s){
  2403. newIdString = (newIdString ? (newIdString + ' ') : '') + appendGridId(s);
  2404. });
  2405. newV = newIdString;
  2406. }
  2407. // Append this newValue to the dom element.
  2408. switch (v.method) {
  2409. case 'attr': //The attr method takes two paraams the tag and the value
  2410. if (v.aria) {
  2411. //If it is an aria element then append the aria prefix
  2412. iElement[v.method]('aria-' + v.tag.toLowerCase(),newV);
  2413. } else {
  2414. iElement[v.method](v.tag.toLowerCase(),newV);
  2415. }
  2416. break;
  2417. case 'addClass':
  2418. //Pulled from https://github.com/Pasvaz/bindonce/blob/master/bindonce.js
  2419. if (angular.isObject(newV) && !angular.isArray(newV)) {
  2420. var results = [];
  2421. var nonNullFound = false; //We don't want to remove the binding unless the key is actually defined
  2422. angular.forEach(newV, function (value, index) {
  2423. if (value !== null && typeof(value) !== "undefined"){
  2424. nonNullFound = true; //A non null value for a key was found so the object must have been initialized
  2425. if (value) {results.push(index);}
  2426. }
  2427. });
  2428. //A non null value for a key wasn't found so assume that the scope values haven't been fully initialized
  2429. if (!nonNullFound){
  2430. return; // If not initialized then the watcher should not be removed yet.
  2431. }
  2432. newV = results;
  2433. }
  2434. if (newV) {
  2435. iElement.addClass(angular.isArray(newV) ? newV.join(' ') : newV);
  2436. } else {
  2437. return;
  2438. }
  2439. break;
  2440. default:
  2441. iElement[v.method](newV);
  2442. break;
  2443. }
  2444. //Removes the watcher on itself after the bind
  2445. rmWatcher();
  2446. }
  2447. // True ensures that equality is determined using angular.equals instead of ===
  2448. }, true); //End rm watchers
  2449. } //End compile function
  2450. }; //End directive return
  2451. } // End directive function
  2452. ]); //End directive
  2453. }); // End angular foreach
  2454. })();
  2455. (function () {
  2456. 'use strict';
  2457. var module = angular.module('ui.grid');
  2458. module.directive('uiGridRenderContainer', ['$timeout', '$document', 'uiGridConstants', 'gridUtil', 'ScrollEvent',
  2459. function($timeout, $document, uiGridConstants, gridUtil, ScrollEvent) {
  2460. return {
  2461. replace: true,
  2462. transclude: true,
  2463. templateUrl: 'ui-grid/uiGridRenderContainer',
  2464. require: ['^uiGrid', 'uiGridRenderContainer'],
  2465. scope: {
  2466. containerId: '=',
  2467. rowContainerName: '=',
  2468. colContainerName: '=',
  2469. bindScrollHorizontal: '=',
  2470. bindScrollVertical: '=',
  2471. enableVerticalScrollbar: '=',
  2472. enableHorizontalScrollbar: '='
  2473. },
  2474. controller: 'uiGridRenderContainer as RenderContainer',
  2475. compile: function () {
  2476. return {
  2477. pre: function prelink($scope, $elm, $attrs, controllers) {
  2478. var uiGridCtrl = controllers[0];
  2479. var containerCtrl = controllers[1];
  2480. var grid = $scope.grid = uiGridCtrl.grid;
  2481. // Verify that the render container for this element exists
  2482. if (!$scope.rowContainerName) {
  2483. throw new Error("No row render container name specified");
  2484. }
  2485. if (!$scope.colContainerName) {
  2486. throw new Error("No column render container name specified");
  2487. }
  2488. if (!grid.renderContainers[$scope.rowContainerName]) {
  2489. throw new Error("Row render container '" + $scope.rowContainerName + "' is not registered.");
  2490. }
  2491. if (!grid.renderContainers[$scope.colContainerName]) {
  2492. throw new Error("Column render container '" + $scope.colContainerName + "' is not registered.");
  2493. }
  2494. var rowContainer = $scope.rowContainer = grid.renderContainers[$scope.rowContainerName];
  2495. var colContainer = $scope.colContainer = grid.renderContainers[$scope.colContainerName];
  2496. containerCtrl.containerId = $scope.containerId;
  2497. containerCtrl.rowContainer = rowContainer;
  2498. containerCtrl.colContainer = colContainer;
  2499. },
  2500. post: function postlink($scope, $elm, $attrs, controllers) {
  2501. var uiGridCtrl = controllers[0];
  2502. var containerCtrl = controllers[1];
  2503. var grid = uiGridCtrl.grid;
  2504. var rowContainer = containerCtrl.rowContainer;
  2505. var colContainer = containerCtrl.colContainer;
  2506. var scrollTop = null;
  2507. var scrollLeft = null;
  2508. var renderContainer = grid.renderContainers[$scope.containerId];
  2509. // Put the container name on this element as a class
  2510. $elm.addClass('ui-grid-render-container-' + $scope.containerId);
  2511. // Scroll the render container viewport when the mousewheel is used
  2512. gridUtil.on.mousewheel($elm, function (event) {
  2513. var scrollEvent = new ScrollEvent(grid, rowContainer, colContainer, ScrollEvent.Sources.RenderContainerMouseWheel);
  2514. if (event.deltaY !== 0) {
  2515. var scrollYAmount = event.deltaY * -1 * event.deltaFactor;
  2516. scrollTop = containerCtrl.viewport[0].scrollTop;
  2517. // Get the scroll percentage
  2518. scrollEvent.verticalScrollLength = rowContainer.getVerticalScrollLength();
  2519. var scrollYPercentage = (scrollTop + scrollYAmount) / scrollEvent.verticalScrollLength;
  2520. // If we should be scrolled 100%, make sure the scrollTop matches the maximum scroll length
  2521. // Viewports that have "overflow: hidden" don't let the mousewheel scroll all the way to the bottom without this check
  2522. if (scrollYPercentage >= 1 && scrollTop < scrollEvent.verticalScrollLength) {
  2523. containerCtrl.viewport[0].scrollTop = scrollEvent.verticalScrollLength;
  2524. }
  2525. // Keep scrollPercentage within the range 0-1.
  2526. if (scrollYPercentage < 0) { scrollYPercentage = 0; }
  2527. else if (scrollYPercentage > 1) { scrollYPercentage = 1; }
  2528. scrollEvent.y = { percentage: scrollYPercentage, pixels: scrollYAmount };
  2529. }
  2530. if (event.deltaX !== 0) {
  2531. var scrollXAmount = event.deltaX * event.deltaFactor;
  2532. // Get the scroll percentage
  2533. scrollLeft = gridUtil.normalizeScrollLeft(containerCtrl.viewport, grid);
  2534. scrollEvent.horizontalScrollLength = (colContainer.getCanvasWidth() - colContainer.getViewportWidth());
  2535. var scrollXPercentage = (scrollLeft + scrollXAmount) / scrollEvent.horizontalScrollLength;
  2536. // Keep scrollPercentage within the range 0-1.
  2537. if (scrollXPercentage < 0) { scrollXPercentage = 0; }
  2538. else if (scrollXPercentage > 1) { scrollXPercentage = 1; }
  2539. scrollEvent.x = { percentage: scrollXPercentage, pixels: scrollXAmount };
  2540. }
  2541. // Let the parent container scroll if the grid is already at the top/bottom
  2542. if ((event.deltaY !== 0 && (scrollEvent.atTop(scrollTop) || scrollEvent.atBottom(scrollTop))) ||
  2543. (event.deltaX !== 0 && (scrollEvent.atLeft(scrollLeft) || scrollEvent.atRight(scrollLeft)))) {
  2544. //parent controller scrolls
  2545. }
  2546. else {
  2547. event.preventDefault();
  2548. event.stopPropagation();
  2549. scrollEvent.fireThrottledScrollingEvent('', scrollEvent);
  2550. }
  2551. });
  2552. $elm.bind('$destroy', function() {
  2553. $elm.unbind('keydown');
  2554. ['touchstart', 'touchmove', 'touchend','keydown', 'wheel', 'mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'].forEach(function (eventName) {
  2555. $elm.unbind(eventName);
  2556. });
  2557. });
  2558. // TODO(c0bra): Handle resizing the inner canvas based on the number of elements
  2559. function update() {
  2560. var ret = '';
  2561. var canvasWidth = colContainer.canvasWidth;
  2562. var viewportWidth = colContainer.getViewportWidth();
  2563. var canvasHeight = rowContainer.getCanvasHeight();
  2564. //add additional height for scrollbar on left and right container
  2565. //if ($scope.containerId !== 'body') {
  2566. // canvasHeight -= grid.scrollbarHeight;
  2567. //}
  2568. var viewportHeight = rowContainer.getViewportHeight();
  2569. //shorten the height to make room for a scrollbar placeholder
  2570. if (colContainer.needsHScrollbarPlaceholder()) {
  2571. viewportHeight -= grid.scrollbarHeight;
  2572. }
  2573. var headerViewportWidth,
  2574. footerViewportWidth;
  2575. headerViewportWidth = footerViewportWidth = colContainer.getHeaderViewportWidth();
  2576. // Set canvas dimensions
  2577. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId + ' .ui-grid-canvas { width: ' + canvasWidth + 'px; height: ' + canvasHeight + 'px; }';
  2578. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId + ' .ui-grid-header-canvas { width: ' + (canvasWidth + grid.scrollbarWidth) + 'px; }';
  2579. if (renderContainer.explicitHeaderCanvasHeight) {
  2580. // get height from body container
  2581. var reHCHeight = document.querySelector(
  2582. '.grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-body .ui-grid-header-canvas');
  2583. if (reHCHeight) {
  2584. renderContainer.explicitHeaderCanvasHeight = reHCHeight.offsetHeight;
  2585. }
  2586. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId +
  2587. ' .ui-grid-header-canvas { height: ' + renderContainer.explicitHeaderCanvasHeight + 'px; }';
  2588. }
  2589. else {
  2590. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId + ' .ui-grid-header-canvas { height: inherit; }';
  2591. }
  2592. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId +
  2593. ' .ui-grid-viewport { width: ' + viewportWidth + 'px; height: ' + viewportHeight + 'px; }';
  2594. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId +
  2595. ' .ui-grid-header-viewport { width: ' + headerViewportWidth + 'px; }';
  2596. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId +
  2597. ' .ui-grid-footer-canvas { width: ' + (canvasWidth + grid.scrollbarWidth) + 'px; }';
  2598. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId +
  2599. ' .ui-grid-footer-viewport { width: ' + footerViewportWidth + 'px; }';
  2600. return ret;
  2601. }
  2602. uiGridCtrl.grid.registerStyleComputation({
  2603. priority: 6,
  2604. func: update
  2605. });
  2606. }
  2607. };
  2608. }
  2609. };
  2610. }]);
  2611. module.controller('uiGridRenderContainer', ['$scope', 'gridUtil', function ($scope, gridUtil) {
  2612. }]);
  2613. })();
  2614. (function(){
  2615. 'use strict';
  2616. angular.module('ui.grid').directive('uiGridRow', ['gridUtil', function(gridUtil) {
  2617. return {
  2618. replace: true,
  2619. // priority: 2001,
  2620. // templateUrl: 'ui-grid/ui-grid-row',
  2621. require: ['^uiGrid', '^uiGridRenderContainer'],
  2622. scope: {
  2623. row: '=uiGridRow',
  2624. //rowRenderIndex is added to scope to give the true visual index of the row to any directives that need it
  2625. rowRenderIndex: '='
  2626. },
  2627. compile: function() {
  2628. return {
  2629. pre: function($scope, $elm, $attrs, controllers) {
  2630. var uiGridCtrl = controllers[0];
  2631. var containerCtrl = controllers[1];
  2632. var grid = uiGridCtrl.grid;
  2633. $scope.grid = uiGridCtrl.grid;
  2634. $scope.colContainer = containerCtrl.colContainer;
  2635. // Function for attaching the template to this scope
  2636. var clonedElement, cloneScope;
  2637. function compileTemplate() {
  2638. $scope.row.getRowTemplateFn.then(function (compiledElementFn) {
  2639. // var compiledElementFn = $scope.row.compiledElementFn;
  2640. // Create a new scope for the contents of this row, so we can destroy it later if need be
  2641. var newScope = $scope.$new();
  2642. compiledElementFn(newScope, function (newElm, scope) {
  2643. // If we already have a cloned element, we need to remove it and destroy its scope
  2644. if (clonedElement) {
  2645. clonedElement.remove();
  2646. cloneScope.$destroy();
  2647. }
  2648. // Empty the row and append the new element
  2649. $elm.empty().append(newElm);
  2650. // Save the new cloned element and scope
  2651. clonedElement = newElm;
  2652. cloneScope = newScope;
  2653. });
  2654. }).catch(angular.noop);
  2655. }
  2656. // Initially attach the compiled template to this scope
  2657. compileTemplate();
  2658. // If the row's compiled element function changes, we need to replace this element's contents with the new compiled template
  2659. $scope.$watch('row.getRowTemplateFn', function (newFunc, oldFunc) {
  2660. if (newFunc !== oldFunc) {
  2661. compileTemplate();
  2662. }
  2663. });
  2664. },
  2665. post: function($scope, $elm, $attrs, controllers) {
  2666. }
  2667. };
  2668. }
  2669. };
  2670. }]);
  2671. })();
  2672. (function(){
  2673. // 'use strict';
  2674. /**
  2675. * @ngdoc directive
  2676. * @name ui.grid.directive:uiGridStyle
  2677. * @element style
  2678. * @restrict A
  2679. *
  2680. * @description
  2681. * Allows us to interpolate expressions in `<style>` elements. Angular doesn't do this by default as it can/will/might? break in IE8.
  2682. *
  2683. * @example
  2684. <doc:example module="app">
  2685. <doc:source>
  2686. <script>
  2687. var app = angular.module('app', ['ui.grid']);
  2688. app.controller('MainCtrl', ['$scope', function ($scope) {
  2689. $scope.myStyle = '.blah { border: 1px solid }';
  2690. }]);
  2691. </script>
  2692. <div ng-controller="MainCtrl">
  2693. <style ui-grid-style>{{ myStyle }}</style>
  2694. <span class="blah">I am in a box.</span>
  2695. </div>
  2696. </doc:source>
  2697. <doc:scenario>
  2698. it('should apply the right class to the element', function () {
  2699. element(by.css('.blah')).getCssValue('border-top-width')
  2700. .then(function(c) {
  2701. expect(c).toContain('1px');
  2702. });
  2703. });
  2704. </doc:scenario>
  2705. </doc:example>
  2706. */
  2707. angular.module('ui.grid').directive('uiGridStyle', ['gridUtil', '$interpolate', function(gridUtil, $interpolate) {
  2708. return {
  2709. // restrict: 'A',
  2710. // priority: 1000,
  2711. // require: '?^uiGrid',
  2712. link: function($scope, $elm, $attrs, uiGridCtrl) {
  2713. // gridUtil.logDebug('ui-grid-style link');
  2714. // if (uiGridCtrl === undefined) {
  2715. // gridUtil.logWarn('[ui-grid-style link] uiGridCtrl is undefined!');
  2716. // }
  2717. var interpolateFn = $interpolate($elm.text(), true);
  2718. if (interpolateFn) {
  2719. $scope.$watch(interpolateFn, function(value) {
  2720. $elm.text(value);
  2721. });
  2722. }
  2723. // uiGridCtrl.recalcRowStyles = function() {
  2724. // var offset = (scope.options.offsetTop || 0) - (scope.options.excessRows * scope.options.rowHeight);
  2725. // var rowHeight = scope.options.rowHeight;
  2726. // var ret = '';
  2727. // var rowStyleCount = uiGridCtrl.minRowsToRender() + (scope.options.excessRows * 2);
  2728. // for (var i = 1; i <= rowStyleCount; i++) {
  2729. // ret = ret + ' .grid' + scope.gridId + ' .ui-grid-row:nth-child(' + i + ') { top: ' + offset + 'px; }';
  2730. // offset = offset + rowHeight;
  2731. // }
  2732. // scope.rowStyles = ret;
  2733. // };
  2734. // uiGridCtrl.styleComputions.push(uiGridCtrl.recalcRowStyles);
  2735. }
  2736. };
  2737. }]);
  2738. })();
  2739. (function(){
  2740. 'use strict';
  2741. angular.module('ui.grid').directive('uiGridViewport', ['gridUtil','ScrollEvent','uiGridConstants', '$log',
  2742. function(gridUtil, ScrollEvent, uiGridConstants, $log) {
  2743. return {
  2744. replace: true,
  2745. scope: {},
  2746. controllerAs: 'Viewport',
  2747. templateUrl: 'ui-grid/uiGridViewport',
  2748. require: ['^uiGrid', '^uiGridRenderContainer'],
  2749. link: function($scope, $elm, $attrs, controllers) {
  2750. // gridUtil.logDebug('viewport post-link');
  2751. var uiGridCtrl = controllers[0];
  2752. var containerCtrl = controllers[1];
  2753. $scope.containerCtrl = containerCtrl;
  2754. var rowContainer = containerCtrl.rowContainer;
  2755. var colContainer = containerCtrl.colContainer;
  2756. var grid = uiGridCtrl.grid;
  2757. $scope.grid = uiGridCtrl.grid;
  2758. // Put the containers in scope so we can get rows and columns from them
  2759. $scope.rowContainer = containerCtrl.rowContainer;
  2760. $scope.colContainer = containerCtrl.colContainer;
  2761. // Register this viewport with its container
  2762. containerCtrl.viewport = $elm;
  2763. /**
  2764. * @ngdoc function
  2765. * @name customScroller
  2766. * @methodOf ui.grid.class:GridOptions
  2767. * @description (optional) uiGridViewport.on('scroll', scrollHandler) by default.
  2768. * A function that allows you to provide your own scroller function. It is particularly helpful if you want to use third party scrollers
  2769. * as this allows you to do that.
  2770. *
  2771. * <div class="alert alert-info" role="alert"> <strong>NOTE:</strong> It is important to remember to always pass in an event object to
  2772. * the scrollHandler as the grid scrolling behavior will break without it.</div>
  2773. * <h5>Example</h5>
  2774. * <pre>
  2775. * $scope.gridOptions = {
  2776. * customScroller: function myScrolling(uiGridViewport, scrollHandler) {
  2777. * uiGridViewport.on('scroll', function myScrollingOverride(event) {
  2778. * // Do something here
  2779. *
  2780. * scrollHandler(event);
  2781. * });
  2782. * }
  2783. * };
  2784. * </pre>
  2785. * @param {object} uiGridViewport Element being scrolled. (this gets passed in by the grid).
  2786. * @param {function} scrollHandler Function that needs to be called when scrolling happens. (this gets passed in by the grid).
  2787. */
  2788. if (grid && grid.options && grid.options.customScroller) {
  2789. grid.options.customScroller($elm, scrollHandler);
  2790. } else {
  2791. $elm.on('scroll', scrollHandler);
  2792. }
  2793. var ignoreScroll = false;
  2794. function scrollHandler(evt) {
  2795. //Leaving in this commented code in case it can someday be used
  2796. //It does improve performance, but because the horizontal scroll is normalized,
  2797. // using this code will lead to the column header getting slightly out of line with columns
  2798. //
  2799. //if (ignoreScroll && (grid.isScrollingHorizontally || grid.isScrollingHorizontally)) {
  2800. // //don't ask for scrollTop if we just set it
  2801. // ignoreScroll = false;
  2802. // return;
  2803. //}
  2804. //ignoreScroll = true;
  2805. var newScrollTop = $elm[0].scrollTop;
  2806. var newScrollLeft = gridUtil.normalizeScrollLeft($elm, grid);
  2807. var vertScrollPercentage = rowContainer.scrollVertical(newScrollTop);
  2808. var horizScrollPercentage = colContainer.scrollHorizontal(newScrollLeft);
  2809. var scrollEvent = new ScrollEvent(grid, rowContainer, colContainer, ScrollEvent.Sources.ViewPortScroll);
  2810. scrollEvent.newScrollLeft = newScrollLeft;
  2811. scrollEvent.newScrollTop = newScrollTop;
  2812. if ( horizScrollPercentage > -1 ){
  2813. scrollEvent.x = { percentage: horizScrollPercentage };
  2814. }
  2815. if ( vertScrollPercentage > -1 ){
  2816. scrollEvent.y = { percentage: vertScrollPercentage };
  2817. }
  2818. grid.scrollContainers($scope.$parent.containerId, scrollEvent);
  2819. }
  2820. if ($scope.$parent.bindScrollVertical) {
  2821. grid.addVerticalScrollSync($scope.$parent.containerId, syncVerticalScroll);
  2822. }
  2823. if ($scope.$parent.bindScrollHorizontal) {
  2824. grid.addHorizontalScrollSync($scope.$parent.containerId, syncHorizontalScroll);
  2825. grid.addHorizontalScrollSync($scope.$parent.containerId + 'header', syncHorizontalHeader);
  2826. grid.addHorizontalScrollSync($scope.$parent.containerId + 'footer', syncHorizontalFooter);
  2827. }
  2828. function syncVerticalScroll(scrollEvent){
  2829. containerCtrl.prevScrollArgs = scrollEvent;
  2830. var newScrollTop = scrollEvent.getNewScrollTop(rowContainer,containerCtrl.viewport);
  2831. $elm[0].scrollTop = newScrollTop;
  2832. }
  2833. function syncHorizontalScroll(scrollEvent){
  2834. containerCtrl.prevScrollArgs = scrollEvent;
  2835. var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport);
  2836. $elm[0].scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid);
  2837. }
  2838. function syncHorizontalHeader(scrollEvent){
  2839. var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport);
  2840. if (containerCtrl.headerViewport) {
  2841. containerCtrl.headerViewport.scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid);
  2842. }
  2843. }
  2844. function syncHorizontalFooter(scrollEvent){
  2845. var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport);
  2846. if (containerCtrl.footerViewport) {
  2847. containerCtrl.footerViewport.scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid);
  2848. }
  2849. }
  2850. $scope.$on('$destroy', function unbindEvents() {
  2851. $elm.off();
  2852. });
  2853. },
  2854. controller: ['$scope', function ($scope) {
  2855. this.rowStyle = function (index) {
  2856. var rowContainer = $scope.rowContainer;
  2857. var colContainer = $scope.colContainer;
  2858. var styles = {};
  2859. if (rowContainer.currentTopRow !== 0){
  2860. //top offset based on hidden rows count
  2861. var translateY = "translateY("+ (rowContainer.currentTopRow * rowContainer.grid.options.rowHeight) +"px)";
  2862. styles['transform'] = translateY;
  2863. styles['-webkit-transform'] = translateY;
  2864. styles['-ms-transform'] = translateY;
  2865. }
  2866. if (colContainer.currentFirstColumn !== 0) {
  2867. if (colContainer.grid.isRTL()) {
  2868. styles['margin-right'] = colContainer.columnOffset + 'px';
  2869. }
  2870. else {
  2871. styles['margin-left'] = colContainer.columnOffset + 'px';
  2872. }
  2873. }
  2874. return styles;
  2875. };
  2876. }]
  2877. };
  2878. }
  2879. ]);
  2880. })();
  2881. (function() {
  2882. angular.module('ui.grid')
  2883. .directive('uiGridVisible', function uiGridVisibleAction() {
  2884. return function ($scope, $elm, $attr) {
  2885. $scope.$watch($attr.uiGridVisible, function (visible) {
  2886. // $elm.css('visibility', visible ? 'visible' : 'hidden');
  2887. $elm[visible ? 'removeClass' : 'addClass']('ui-grid-invisible');
  2888. });
  2889. };
  2890. });
  2891. })();
  2892. (function () {
  2893. 'use strict';
  2894. angular.module('ui.grid').controller('uiGridController', ['$scope', '$element', '$attrs', 'gridUtil', '$q', 'uiGridConstants',
  2895. 'gridClassFactory', '$parse', '$compile',
  2896. function ($scope, $elm, $attrs, gridUtil, $q, uiGridConstants,
  2897. gridClassFactory, $parse, $compile) {
  2898. // gridUtil.logDebug('ui-grid controller');
  2899. var self = this;
  2900. var deregFunctions = [];
  2901. self.grid = gridClassFactory.createGrid($scope.uiGrid);
  2902. //assign $scope.$parent if appScope not already assigned
  2903. self.grid.appScope = self.grid.appScope || $scope.$parent;
  2904. $elm.addClass('grid' + self.grid.id);
  2905. self.grid.rtl = gridUtil.getStyles($elm[0])['direction'] === 'rtl';
  2906. // angular.extend(self.grid.options, );
  2907. //all properties of grid are available on scope
  2908. $scope.grid = self.grid;
  2909. if ($attrs.uiGridColumns) {
  2910. deregFunctions.push( $attrs.$observe('uiGridColumns', function(value) {
  2911. self.grid.options.columnDefs = angular.isString(value) ? angular.fromJson(value) : value;
  2912. self.grid.buildColumns()
  2913. .then(function(){
  2914. self.grid.preCompileCellTemplates();
  2915. self.grid.refreshCanvas(true);
  2916. }).catch(angular.noop);
  2917. }) );
  2918. }
  2919. // prevents an error from being thrown when the array is not defined yet and fastWatch is on
  2920. function getSize(array) {
  2921. return array ? array.length : 0;
  2922. }
  2923. // if fastWatch is set we watch only the length and the reference, not every individual object
  2924. if (self.grid.options.fastWatch) {
  2925. self.uiGrid = $scope.uiGrid;
  2926. if (angular.isString($scope.uiGrid.data)) {
  2927. deregFunctions.push( $scope.$parent.$watch($scope.uiGrid.data, dataWatchFunction) );
  2928. deregFunctions.push( $scope.$parent.$watch(function() {
  2929. if ( self.grid.appScope[$scope.uiGrid.data] ){
  2930. return self.grid.appScope[$scope.uiGrid.data].length;
  2931. } else {
  2932. return undefined;
  2933. }
  2934. }, dataWatchFunction) );
  2935. } else {
  2936. deregFunctions.push( $scope.$parent.$watch(function() { return $scope.uiGrid.data; }, dataWatchFunction) );
  2937. deregFunctions.push( $scope.$parent.$watch(function() { return getSize($scope.uiGrid.data); }, function(){ dataWatchFunction($scope.uiGrid.data); }) );
  2938. }
  2939. deregFunctions.push( $scope.$parent.$watch(function() { return $scope.uiGrid.columnDefs; }, columnDefsWatchFunction) );
  2940. deregFunctions.push( $scope.$parent.$watch(function() { return getSize($scope.uiGrid.columnDefs); }, function(){ columnDefsWatchFunction($scope.uiGrid.columnDefs); }) );
  2941. } else {
  2942. if (angular.isString($scope.uiGrid.data)) {
  2943. deregFunctions.push( $scope.$parent.$watchCollection($scope.uiGrid.data, dataWatchFunction) );
  2944. } else {
  2945. deregFunctions.push( $scope.$parent.$watchCollection(function() { return $scope.uiGrid.data; }, dataWatchFunction) );
  2946. }
  2947. deregFunctions.push( $scope.$parent.$watchCollection(function() { return $scope.uiGrid.columnDefs; }, columnDefsWatchFunction) );
  2948. }
  2949. function columnDefsWatchFunction(n, o) {
  2950. if (n && n !== o) {
  2951. self.grid.options.columnDefs = $scope.uiGrid.columnDefs;
  2952. self.grid.callDataChangeCallbacks(uiGridConstants.dataChange.COLUMN, {
  2953. orderByColumnDefs: true,
  2954. preCompileCellTemplates: true
  2955. });
  2956. }
  2957. }
  2958. var mostRecentData;
  2959. function dataWatchFunction(newData) {
  2960. // gridUtil.logDebug('dataWatch fired');
  2961. var promises = [];
  2962. if ( self.grid.options.fastWatch ) {
  2963. if (angular.isString($scope.uiGrid.data)) {
  2964. newData = self.grid.appScope.$eval($scope.uiGrid.data);
  2965. } else {
  2966. newData = $scope.uiGrid.data;
  2967. }
  2968. }
  2969. mostRecentData = newData;
  2970. if (newData) {
  2971. // columns length is greater than the number of row header columns, which don't count because they're created automatically
  2972. var hasColumns = self.grid.columns.length > (self.grid.rowHeaderColumns ? self.grid.rowHeaderColumns.length : 0);
  2973. if (
  2974. // If we have no columns
  2975. !hasColumns &&
  2976. // ... and we don't have a ui-grid-columns attribute, which would define columns for us
  2977. !$attrs.uiGridColumns &&
  2978. // ... and we have no pre-defined columns
  2979. self.grid.options.columnDefs.length === 0 &&
  2980. // ... but we DO have data
  2981. newData.length > 0
  2982. ) {
  2983. // ... then build the column definitions from the data that we have
  2984. self.grid.buildColumnDefsFromData(newData);
  2985. }
  2986. // If we haven't built columns before and either have some columns defined or some data defined
  2987. if (!hasColumns && (self.grid.options.columnDefs.length > 0 || newData.length > 0)) {
  2988. // Build the column set, then pre-compile the column cell templates
  2989. promises.push(self.grid.buildColumns()
  2990. .then(function() {
  2991. self.grid.preCompileCellTemplates();
  2992. }).catch(angular.noop));
  2993. }
  2994. $q.all(promises).then(function() {
  2995. // use most recent data, rather than the potentially outdated data passed into watcher handler
  2996. self.grid.modifyRows(mostRecentData)
  2997. .then(function () {
  2998. // if (self.viewport) {
  2999. self.grid.redrawInPlace(true);
  3000. // }
  3001. $scope.$evalAsync(function() {
  3002. self.grid.refreshCanvas(true);
  3003. self.grid.callDataChangeCallbacks(uiGridConstants.dataChange.ROW);
  3004. });
  3005. }).catch(angular.noop);
  3006. }).catch(angular.noop);
  3007. }
  3008. }
  3009. var styleWatchDereg = $scope.$watch(function () { return self.grid.styleComputations; }, function() {
  3010. self.grid.refreshCanvas(true);
  3011. });
  3012. $scope.$on('$destroy', function() {
  3013. deregFunctions.forEach( function( deregFn ){ deregFn(); });
  3014. styleWatchDereg();
  3015. });
  3016. self.fireEvent = function(eventName, args) {
  3017. args = args || {};
  3018. // Add the grid to the event arguments if it's not there
  3019. if (angular.isUndefined(args.grid)) {
  3020. args.grid = self.grid;
  3021. }
  3022. $scope.$broadcast(eventName, args);
  3023. };
  3024. self.innerCompile = function innerCompile(elm) {
  3025. $compile(elm)($scope);
  3026. };
  3027. }]);
  3028. /**
  3029. * @ngdoc directive
  3030. * @name ui.grid.directive:uiGrid
  3031. * @element div
  3032. * @restrict EA
  3033. * @param {Object} uiGrid Options for the grid to use
  3034. *
  3035. * @description Create a very basic grid.
  3036. *
  3037. * @example
  3038. <example module="app">
  3039. <file name="app.js">
  3040. var app = angular.module('app', ['ui.grid']);
  3041. app.controller('MainCtrl', ['$scope', function ($scope) {
  3042. $scope.data = [
  3043. { name: 'Bob', title: 'CEO' },
  3044. { name: 'Frank', title: 'Lowly Developer' }
  3045. ];
  3046. }]);
  3047. </file>
  3048. <file name="index.html">
  3049. <div ng-controller="MainCtrl">
  3050. <div ui-grid="{ data: data }"></div>
  3051. </div>
  3052. </file>
  3053. </example>
  3054. */
  3055. angular.module('ui.grid').directive('uiGrid', uiGridDirective);
  3056. uiGridDirective.$inject = ['$window', 'gridUtil', 'uiGridConstants'];
  3057. function uiGridDirective($window, gridUtil, uiGridConstants) {
  3058. return {
  3059. templateUrl: 'ui-grid/ui-grid',
  3060. scope: {
  3061. uiGrid: '='
  3062. },
  3063. replace: true,
  3064. transclude: true,
  3065. controller: 'uiGridController',
  3066. compile: function () {
  3067. return {
  3068. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  3069. var grid = uiGridCtrl.grid;
  3070. // Initialize scrollbars (TODO: move to controller??)
  3071. uiGridCtrl.scrollbars = [];
  3072. grid.element = $elm;
  3073. // See if the grid has a rendered width, if not, wait a bit and try again
  3074. var sizeCheckInterval = 100; // ms
  3075. var maxSizeChecks = 20; // 2 seconds total
  3076. var sizeChecks = 0;
  3077. // Setup (event listeners) the grid
  3078. setup();
  3079. // And initialize it
  3080. init();
  3081. // Mark rendering complete so API events can happen
  3082. grid.renderingComplete();
  3083. // If the grid doesn't have size currently, wait for a bit to see if it gets size
  3084. checkSize();
  3085. /*-- Methods --*/
  3086. function checkSize() {
  3087. // If the grid has no width and we haven't checked more than <maxSizeChecks> times, check again in <sizeCheckInterval> milliseconds
  3088. if ($elm[0].offsetWidth <= 0 && sizeChecks < maxSizeChecks) {
  3089. setTimeout(checkSize, sizeCheckInterval);
  3090. sizeChecks++;
  3091. } else {
  3092. $scope.$applyAsync(init);
  3093. }
  3094. }
  3095. // Setup event listeners and watchers
  3096. function setup() {
  3097. var deregisterLeftWatcher, deregisterRightWatcher;
  3098. // Bind to window resize events
  3099. angular.element($window).on('resize', gridResize);
  3100. // Unbind from window resize events when the grid is destroyed
  3101. $elm.on('$destroy', function () {
  3102. angular.element($window).off('resize', gridResize);
  3103. deregisterLeftWatcher();
  3104. deregisterRightWatcher();
  3105. });
  3106. // If we add a left container after render, we need to watch and react
  3107. deregisterLeftWatcher = $scope.$watch(function () { return grid.hasLeftContainer();}, function (newValue, oldValue) {
  3108. if (newValue === oldValue) {
  3109. return;
  3110. }
  3111. grid.refreshCanvas(true);
  3112. });
  3113. // If we add a right container after render, we need to watch and react
  3114. deregisterRightWatcher = $scope.$watch(function () { return grid.hasRightContainer();}, function (newValue, oldValue) {
  3115. if (newValue === oldValue) {
  3116. return;
  3117. }
  3118. grid.refreshCanvas(true);
  3119. });
  3120. }
  3121. // Initialize the directive
  3122. function init() {
  3123. grid.gridWidth = $scope.gridWidth = gridUtil.elementWidth($elm);
  3124. // Default canvasWidth to the grid width, in case we don't get any column definitions to calculate it from
  3125. grid.canvasWidth = uiGridCtrl.grid.gridWidth;
  3126. grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm);
  3127. // If the grid isn't tall enough to fit a single row, it's kind of useless. Resize it to fit a minimum number of rows
  3128. if (grid.gridHeight - grid.scrollbarHeight <= grid.options.rowHeight && grid.options.enableMinHeightCheck) {
  3129. autoAdjustHeight();
  3130. }
  3131. // Run initial canvas refresh
  3132. grid.refreshCanvas(true);
  3133. }
  3134. // Set the grid's height ourselves in the case that its height would be unusably small
  3135. function autoAdjustHeight() {
  3136. // Figure out the new height
  3137. var contentHeight = grid.options.minRowsToShow * grid.options.rowHeight;
  3138. var headerHeight = grid.options.showHeader ? grid.options.headerRowHeight : 0;
  3139. var footerHeight = grid.calcFooterHeight();
  3140. var scrollbarHeight = 0;
  3141. if (grid.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.ALWAYS) {
  3142. scrollbarHeight = gridUtil.getScrollbarWidth();
  3143. }
  3144. var maxNumberOfFilters = 0;
  3145. // Calculates the maximum number of filters in the columns
  3146. angular.forEach(grid.options.columnDefs, function(col) {
  3147. if (col.hasOwnProperty('filter')) {
  3148. if (maxNumberOfFilters < 1) {
  3149. maxNumberOfFilters = 1;
  3150. }
  3151. }
  3152. else if (col.hasOwnProperty('filters')) {
  3153. if (maxNumberOfFilters < col.filters.length) {
  3154. maxNumberOfFilters = col.filters.length;
  3155. }
  3156. }
  3157. });
  3158. if (grid.options.enableFiltering && !maxNumberOfFilters) {
  3159. var allColumnsHaveFilteringTurnedOff = grid.options.columnDefs.length && grid.options.columnDefs.every(function(col) {
  3160. return col.enableFiltering === false;
  3161. });
  3162. if (!allColumnsHaveFilteringTurnedOff) {
  3163. maxNumberOfFilters = 1;
  3164. }
  3165. }
  3166. var filterHeight = maxNumberOfFilters * headerHeight;
  3167. var newHeight = headerHeight + contentHeight + footerHeight + scrollbarHeight + filterHeight;
  3168. $elm.css('height', newHeight + 'px');
  3169. grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm);
  3170. }
  3171. // Resize the grid on window resize events
  3172. function gridResize() {
  3173. grid.gridWidth = $scope.gridWidth = gridUtil.elementWidth($elm);
  3174. grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm);
  3175. grid.refreshCanvas(true);
  3176. }
  3177. }
  3178. };
  3179. }
  3180. };
  3181. }
  3182. })();
  3183. (function(){
  3184. 'use strict';
  3185. // TODO: rename this file to ui-grid-pinned-container.js
  3186. angular.module('ui.grid').directive('uiGridPinnedContainer', ['gridUtil', function (gridUtil) {
  3187. return {
  3188. restrict: 'EA',
  3189. replace: true,
  3190. template: '<div class="ui-grid-pinned-container"><div ui-grid-render-container container-id="side" row-container-name="\'body\'" col-container-name="side" bind-scroll-vertical="true" class="{{ side }} ui-grid-render-container-{{ side }}"></div></div>',
  3191. scope: {
  3192. side: '=uiGridPinnedContainer'
  3193. },
  3194. require: '^uiGrid',
  3195. compile: function compile() {
  3196. return {
  3197. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  3198. // gridUtil.logDebug('ui-grid-pinned-container ' + $scope.side + ' link');
  3199. var grid = uiGridCtrl.grid;
  3200. var myWidth = 0;
  3201. $elm.addClass('ui-grid-pinned-container-' + $scope.side);
  3202. // Monkey-patch the viewport width function
  3203. if ($scope.side === 'left' || $scope.side === 'right') {
  3204. grid.renderContainers[$scope.side].getViewportWidth = monkeyPatchedGetViewportWidth;
  3205. }
  3206. function monkeyPatchedGetViewportWidth() {
  3207. /*jshint validthis: true */
  3208. var self = this;
  3209. var viewportWidth = 0;
  3210. self.visibleColumnCache.forEach(function (column) {
  3211. viewportWidth += column.drawnWidth;
  3212. });
  3213. var adjustment = self.getViewportAdjustment();
  3214. viewportWidth = viewportWidth + adjustment.width;
  3215. return viewportWidth;
  3216. }
  3217. function updateContainerWidth() {
  3218. if ($scope.side === 'left' || $scope.side === 'right') {
  3219. var cols = grid.renderContainers[$scope.side].visibleColumnCache;
  3220. var width = 0;
  3221. for (var i = 0; i < cols.length; i++) {
  3222. var col = cols[i];
  3223. width += col.drawnWidth || col.width || 0;
  3224. }
  3225. return width;
  3226. }
  3227. }
  3228. function updateContainerDimensions() {
  3229. var ret = '';
  3230. // Column containers
  3231. if ($scope.side === 'left' || $scope.side === 'right') {
  3232. myWidth = updateContainerWidth();
  3233. // gridUtil.logDebug('myWidth', myWidth);
  3234. // TODO(c0bra): Subtract sum of col widths from grid viewport width and update it
  3235. $elm.attr('style', null);
  3236. // var myHeight = grid.renderContainers.body.getViewportHeight(); // + grid.horizontalScrollbarHeight;
  3237. ret += '.grid' + grid.id + ' .ui-grid-pinned-container-' + $scope.side + ', .grid' + grid.id + ' .ui-grid-pinned-container-' + $scope.side + ' .ui-grid-render-container-' + $scope.side + ' .ui-grid-viewport { width: ' + myWidth + 'px; } ';
  3238. }
  3239. return ret;
  3240. }
  3241. grid.renderContainers.body.registerViewportAdjuster(function (adjustment) {
  3242. myWidth = updateContainerWidth();
  3243. // Subtract our own width
  3244. adjustment.width -= myWidth;
  3245. adjustment.side = $scope.side;
  3246. return adjustment;
  3247. });
  3248. // Register style computation to adjust for columns in `side`'s render container
  3249. grid.registerStyleComputation({
  3250. priority: 15,
  3251. func: updateContainerDimensions
  3252. });
  3253. }
  3254. };
  3255. }
  3256. };
  3257. }]);
  3258. })();
  3259. (function(){
  3260. angular.module('ui.grid')
  3261. .factory('Grid', ['$q', '$compile', '$parse', 'gridUtil', 'uiGridConstants', 'GridOptions', 'GridColumn', 'GridRow', 'GridApi', 'rowSorter', 'rowSearcher', 'GridRenderContainer', '$timeout','ScrollEvent',
  3262. function($q, $compile, $parse, gridUtil, uiGridConstants, GridOptions, GridColumn, GridRow, GridApi, rowSorter, rowSearcher, GridRenderContainer, $timeout, ScrollEvent) {
  3263. /**
  3264. * @ngdoc object
  3265. * @name ui.grid.core.api:PublicApi
  3266. * @description Public Api for the core grid features
  3267. *
  3268. */
  3269. /**
  3270. * @ngdoc function
  3271. * @name ui.grid.class:Grid
  3272. * @description Grid is the main viewModel. Any properties or methods needed to maintain state are defined in
  3273. * this prototype. One instance of Grid is created per Grid directive instance.
  3274. * @param {object} options Object map of options to pass into the grid. An 'id' property is expected.
  3275. */
  3276. var Grid = function Grid(options) {
  3277. var self = this;
  3278. // Get the id out of the options, then remove it
  3279. if (options !== undefined && typeof(options.id) !== 'undefined' && options.id) {
  3280. if (!/^[_a-zA-Z0-9-]+$/.test(options.id)) {
  3281. throw new Error("Grid id '" + options.id + '" is invalid. It must follow CSS selector syntax rules.');
  3282. }
  3283. }
  3284. else {
  3285. throw new Error('No ID provided. An ID must be given when creating a grid.');
  3286. }
  3287. self.id = options.id;
  3288. delete options.id;
  3289. // Get default options
  3290. self.options = GridOptions.initialize( options );
  3291. /**
  3292. * @ngdoc object
  3293. * @name appScope
  3294. * @propertyOf ui.grid.class:Grid
  3295. * @description reference to the application scope (the parent scope of the ui-grid element). Assigned in ui-grid controller
  3296. * <br/>
  3297. * use gridOptions.appScopeProvider to override the default assignment of $scope.$parent with any reference
  3298. */
  3299. self.appScope = self.options.appScopeProvider;
  3300. self.headerHeight = self.options.headerRowHeight;
  3301. /**
  3302. * @ngdoc object
  3303. * @name footerHeight
  3304. * @propertyOf ui.grid.class:Grid
  3305. * @description returns the total footer height gridFooter + columnFooter
  3306. */
  3307. self.footerHeight = self.calcFooterHeight();
  3308. /**
  3309. * @ngdoc object
  3310. * @name columnFooterHeight
  3311. * @propertyOf ui.grid.class:Grid
  3312. * @description returns the total column footer height
  3313. */
  3314. self.columnFooterHeight = self.calcColumnFooterHeight();
  3315. self.rtl = false;
  3316. self.gridHeight = 0;
  3317. self.gridWidth = 0;
  3318. self.columnBuilders = [];
  3319. self.rowBuilders = [];
  3320. self.rowsProcessors = [];
  3321. self.columnsProcessors = [];
  3322. self.styleComputations = [];
  3323. self.viewportAdjusters = [];
  3324. self.rowHeaderColumns = [];
  3325. self.dataChangeCallbacks = {};
  3326. self.verticalScrollSyncCallBackFns = {};
  3327. self.horizontalScrollSyncCallBackFns = {};
  3328. // self.visibleRowCache = [];
  3329. // Set of 'render' containers for self grid, which can render sets of rows
  3330. self.renderContainers = {};
  3331. // Create a
  3332. self.renderContainers.body = new GridRenderContainer('body', self);
  3333. self.cellValueGetterCache = {};
  3334. // Cached function to use with custom row templates
  3335. self.getRowTemplateFn = null;
  3336. //representation of the rows on the grid.
  3337. //these are wrapped references to the actual data rows (options.data)
  3338. self.rows = [];
  3339. //represents the columns on the grid
  3340. self.columns = [];
  3341. /**
  3342. * @ngdoc boolean
  3343. * @name isScrollingVertically
  3344. * @propertyOf ui.grid.class:Grid
  3345. * @description set to true when Grid is scrolling vertically. Set to false via debounced method
  3346. */
  3347. self.isScrollingVertically = false;
  3348. /**
  3349. * @ngdoc boolean
  3350. * @name isScrollingHorizontally
  3351. * @propertyOf ui.grid.class:Grid
  3352. * @description set to true when Grid is scrolling horizontally. Set to false via debounced method
  3353. */
  3354. self.isScrollingHorizontally = false;
  3355. /**
  3356. * @ngdoc property
  3357. * @name scrollDirection
  3358. * @propertyOf ui.grid.class:Grid
  3359. * @description set one of the {@link ui.grid.service:uiGridConstants#properties_scrollDirection uiGridConstants.scrollDirection}
  3360. * values (UP, DOWN, LEFT, RIGHT, NONE), which tells us which direction we are scrolling.
  3361. * Set to NONE via debounced method
  3362. */
  3363. self.scrollDirection = uiGridConstants.scrollDirection.NONE;
  3364. //if true, grid will not respond to any scroll events
  3365. self.disableScrolling = false;
  3366. function vertical (scrollEvent) {
  3367. self.isScrollingVertically = false;
  3368. self.api.core.raise.scrollEnd(scrollEvent);
  3369. self.scrollDirection = uiGridConstants.scrollDirection.NONE;
  3370. }
  3371. var debouncedVertical = gridUtil.debounce(vertical, self.options.scrollDebounce);
  3372. var debouncedVerticalMinDelay = gridUtil.debounce(vertical, 0);
  3373. function horizontal (scrollEvent) {
  3374. self.isScrollingHorizontally = false;
  3375. self.api.core.raise.scrollEnd(scrollEvent);
  3376. self.scrollDirection = uiGridConstants.scrollDirection.NONE;
  3377. }
  3378. var debouncedHorizontal = gridUtil.debounce(horizontal, self.options.scrollDebounce);
  3379. var debouncedHorizontalMinDelay = gridUtil.debounce(horizontal, 0);
  3380. /**
  3381. * @ngdoc function
  3382. * @name flagScrollingVertically
  3383. * @methodOf ui.grid.class:Grid
  3384. * @description sets isScrollingVertically to true and sets it to false in a debounced function
  3385. */
  3386. self.flagScrollingVertically = function(scrollEvent) {
  3387. if (!self.isScrollingVertically && !self.isScrollingHorizontally) {
  3388. self.api.core.raise.scrollBegin(scrollEvent);
  3389. }
  3390. self.isScrollingVertically = true;
  3391. if (self.options.scrollDebounce === 0 || !scrollEvent.withDelay) {
  3392. debouncedVerticalMinDelay(scrollEvent);
  3393. }
  3394. else {
  3395. debouncedVertical(scrollEvent);
  3396. }
  3397. };
  3398. /**
  3399. * @ngdoc function
  3400. * @name flagScrollingHorizontally
  3401. * @methodOf ui.grid.class:Grid
  3402. * @description sets isScrollingHorizontally to true and sets it to false in a debounced function
  3403. */
  3404. self.flagScrollingHorizontally = function(scrollEvent) {
  3405. if (!self.isScrollingVertically && !self.isScrollingHorizontally) {
  3406. self.api.core.raise.scrollBegin(scrollEvent);
  3407. }
  3408. self.isScrollingHorizontally = true;
  3409. if (self.options.scrollDebounce === 0 || !scrollEvent.withDelay) {
  3410. debouncedHorizontalMinDelay(scrollEvent);
  3411. }
  3412. else {
  3413. debouncedHorizontal(scrollEvent);
  3414. }
  3415. };
  3416. self.scrollbarHeight = 0;
  3417. self.scrollbarWidth = 0;
  3418. if (self.options.enableHorizontalScrollbar !== uiGridConstants.scrollbars.NEVER) {
  3419. self.scrollbarHeight = gridUtil.getScrollbarWidth();
  3420. }
  3421. if (self.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER) {
  3422. self.scrollbarWidth = gridUtil.getScrollbarWidth();
  3423. }
  3424. self.api = new GridApi(self);
  3425. /**
  3426. * @ngdoc function
  3427. * @name refresh
  3428. * @methodOf ui.grid.core.api:PublicApi
  3429. * @description Refresh the rendered grid on screen.
  3430. * The refresh method re-runs both the columnProcessors and the
  3431. * rowProcessors, as well as calling refreshCanvas to update all
  3432. * the grid sizing. In general you should prefer to use queueGridRefresh
  3433. * instead, which is basically a debounced version of refresh.
  3434. *
  3435. * If you only want to resize the grid, not regenerate all the rows
  3436. * and columns, you should consider directly calling refreshCanvas instead.
  3437. *
  3438. * @param {boolean} [rowsAltered] Optional flag for refreshing when the number of rows has changed
  3439. */
  3440. self.api.registerMethod( 'core', 'refresh', this.refresh );
  3441. /**
  3442. * @ngdoc function
  3443. * @name queueGridRefresh
  3444. * @methodOf ui.grid.core.api:PublicApi
  3445. * @description Request a refresh of the rendered grid on screen, if multiple
  3446. * calls to queueGridRefresh are made within a digest cycle only one will execute.
  3447. * The refresh method re-runs both the columnProcessors and the
  3448. * rowProcessors, as well as calling refreshCanvas to update all
  3449. * the grid sizing. In general you should prefer to use queueGridRefresh
  3450. * instead, which is basically a debounced version of refresh.
  3451. *
  3452. */
  3453. self.api.registerMethod( 'core', 'queueGridRefresh', this.queueGridRefresh );
  3454. /**
  3455. * @ngdoc function
  3456. * @name refreshRows
  3457. * @methodOf ui.grid.core.api:PublicApi
  3458. * @description Runs only the rowProcessors, columns remain as they were.
  3459. * It then calls redrawInPlace and refreshCanvas, which adjust the grid sizing.
  3460. * @returns {promise} promise that is resolved when render completes?
  3461. *
  3462. */
  3463. self.api.registerMethod( 'core', 'refreshRows', this.refreshRows );
  3464. /**
  3465. * @ngdoc function
  3466. * @name queueRefresh
  3467. * @methodOf ui.grid.core.api:PublicApi
  3468. * @description Requests execution of refreshCanvas, if multiple requests are made
  3469. * during a digest cycle only one will run. RefreshCanvas updates the grid sizing.
  3470. * @returns {promise} promise that is resolved when render completes?
  3471. *
  3472. */
  3473. self.api.registerMethod( 'core', 'queueRefresh', this.queueRefresh );
  3474. /**
  3475. * @ngdoc function
  3476. * @name handleWindowResize
  3477. * @methodOf ui.grid.core.api:PublicApi
  3478. * @description Trigger a grid resize, normally this would be picked
  3479. * up by a watch on window size, but in some circumstances it is necessary
  3480. * to call this manually
  3481. * @returns {promise} promise that is resolved when render completes?
  3482. *
  3483. */
  3484. self.api.registerMethod( 'core', 'handleWindowResize', this.handleWindowResize );
  3485. /**
  3486. * @ngdoc function
  3487. * @name addRowHeaderColumn
  3488. * @methodOf ui.grid.core.api:PublicApi
  3489. * @description adds a row header column to the grid
  3490. * @param {object} column def
  3491. * @param {number} order Determines order of header column on grid. Lower order means header
  3492. * is positioned to the left of higher order headers
  3493. *
  3494. */
  3495. self.api.registerMethod( 'core', 'addRowHeaderColumn', this.addRowHeaderColumn );
  3496. /**
  3497. * @ngdoc function
  3498. * @name scrollToIfNecessary
  3499. * @methodOf ui.grid.core.api:PublicApi
  3500. * @description Scrolls the grid to make a certain row and column combo visible,
  3501. * in the case that it is not completely visible on the screen already.
  3502. * @param {GridRow} gridRow row to make visible
  3503. * @param {GridColumn} gridCol column to make visible
  3504. * @returns {promise} a promise that is resolved when scrolling is complete
  3505. *
  3506. */
  3507. self.api.registerMethod( 'core', 'scrollToIfNecessary', function(gridRow, gridCol) { return self.scrollToIfNecessary(gridRow, gridCol);} );
  3508. /**
  3509. * @ngdoc function
  3510. * @name scrollTo
  3511. * @methodOf ui.grid.core.api:PublicApi
  3512. * @description Scroll the grid such that the specified
  3513. * row and column is in view
  3514. * @param {object} rowEntity gridOptions.data[] array instance to make visible
  3515. * @param {object} colDef to make visible
  3516. * @returns {promise} a promise that is resolved after any scrolling is finished
  3517. */
  3518. self.api.registerMethod( 'core', 'scrollTo', function (rowEntity, colDef) { return self.scrollTo(rowEntity, colDef);} );
  3519. /**
  3520. * @ngdoc function
  3521. * @name registerRowsProcessor
  3522. * @methodOf ui.grid.core.api:PublicApi
  3523. * @description
  3524. * Register a "rows processor" function. When the rows are updated,
  3525. * the grid calls each registered "rows processor", which has a chance
  3526. * to alter the set of rows (sorting, etc) as long as the count is not
  3527. * modified.
  3528. *
  3529. * @param {function(renderedRowsToProcess, columns )} processorFunction rows processor function, which
  3530. * is run in the context of the grid (i.e. this for the function will be the grid), and must
  3531. * return the updated rows list, which is passed to the next processor in the chain
  3532. * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room
  3533. * for other people to inject rows processors at intermediate priorities. Lower priority rowsProcessors run earlier.
  3534. *
  3535. * At present allRowsVisible is running at 50, sort manipulations running at 60-65, filter is running at 100,
  3536. * sort is at 200, grouping and treeview at 400-410, selectable rows at 500, pagination at 900 (pagination will generally want to be last)
  3537. */
  3538. self.api.registerMethod( 'core', 'registerRowsProcessor', this.registerRowsProcessor );
  3539. /**
  3540. * @ngdoc function
  3541. * @name registerColumnsProcessor
  3542. * @methodOf ui.grid.core.api:PublicApi
  3543. * @description
  3544. * Register a "columns processor" function. When the columns are updated,
  3545. * the grid calls each registered "columns processor", which has a chance
  3546. * to alter the set of columns as long as the count is not
  3547. * modified.
  3548. *
  3549. * @param {function(renderedColumnsToProcess, rows )} processorFunction columns processor function, which
  3550. * is run in the context of the grid (i.e. this for the function will be the grid), and must
  3551. * return the updated columns list, which is passed to the next processor in the chain
  3552. * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room
  3553. * for other people to inject columns processors at intermediate priorities. Lower priority columnsProcessors run earlier.
  3554. *
  3555. * At present allRowsVisible is running at 50, filter is running at 100, sort is at 200, grouping at 400, selectable rows at 500, pagination at 900 (pagination will generally want to be last)
  3556. */
  3557. self.api.registerMethod( 'core', 'registerColumnsProcessor', this.registerColumnsProcessor );
  3558. /**
  3559. * @ngdoc function
  3560. * @name sortHandleNulls
  3561. * @methodOf ui.grid.core.api:PublicApi
  3562. * @description A null handling method that can be used when building custom sort
  3563. * functions
  3564. * @example
  3565. * <pre>
  3566. * mySortFn = function(a, b) {
  3567. * var nulls = $scope.gridApi.core.sortHandleNulls(a, b);
  3568. * if ( nulls !== null ){
  3569. * return nulls;
  3570. * } else {
  3571. * // your code for sorting here
  3572. * };
  3573. * </pre>
  3574. * @param {object} a sort value a
  3575. * @param {object} b sort value b
  3576. * @returns {number} null if there were no nulls/undefineds, otherwise returns
  3577. * a sort value that should be passed back from the sort function
  3578. *
  3579. */
  3580. self.api.registerMethod( 'core', 'sortHandleNulls', rowSorter.handleNulls );
  3581. /**
  3582. * @ngdoc function
  3583. * @name sortChanged
  3584. * @methodOf ui.grid.core.api:PublicApi
  3585. * @description The sort criteria on one or more columns has
  3586. * changed. Provides as parameters the grid and the output of
  3587. * getColumnSorting, which is an array of gridColumns
  3588. * that have sorting on them, sorted in priority order.
  3589. *
  3590. * @param {$scope} scope The scope of the controller. This is used to deregister this event when the scope is destroyed.
  3591. * @param {Function} callBack Will be called when the event is emited. The function passes back the grid and an array of
  3592. * columns with sorts on them, in priority order.
  3593. *
  3594. * @example
  3595. * <pre>
  3596. * gridApi.core.on.sortChanged( $scope, function(grid, sortColumns){
  3597. * // do something
  3598. * });
  3599. * </pre>
  3600. */
  3601. self.api.registerEvent( 'core', 'sortChanged' );
  3602. /**
  3603. * @ngdoc function
  3604. * @name columnVisibilityChanged
  3605. * @methodOf ui.grid.core.api:PublicApi
  3606. * @description The visibility of a column has changed,
  3607. * the column itself is passed out as a parameter of the event.
  3608. *
  3609. * @param {$scope} scope The scope of the controller. This is used to deregister this event when the scope is destroyed.
  3610. * @param {Function} callBack Will be called when the event is emited. The function passes back the GridCol that has changed.
  3611. *
  3612. * @example
  3613. * <pre>
  3614. * gridApi.core.on.columnVisibilityChanged( $scope, function (column) {
  3615. * // do something
  3616. * } );
  3617. * </pre>
  3618. */
  3619. self.api.registerEvent( 'core', 'columnVisibilityChanged' );
  3620. /**
  3621. * @ngdoc method
  3622. * @name notifyDataChange
  3623. * @methodOf ui.grid.core.api:PublicApi
  3624. * @description Notify the grid that a data or config change has occurred,
  3625. * where that change isn't something the grid was otherwise noticing. This
  3626. * might be particularly relevant where you've changed values within the data
  3627. * and you'd like cell classes to be re-evaluated, or changed config within
  3628. * the columnDef and you'd like headerCellClasses to be re-evaluated.
  3629. * @param {string} type one of the
  3630. * {@link ui.grid.service:uiGridConstants#properties_dataChange uiGridConstants.dataChange}
  3631. * values (ALL, ROW, EDIT, COLUMN, OPTIONS), which tells us which refreshes to fire.
  3632. *
  3633. * - ALL: listeners fired on any of these events, fires listeners on all events.
  3634. * - ROW: fired when a row is added or removed.
  3635. * - EDIT: fired when the data in a cell is edited.
  3636. * - COLUMN: fired when the column definitions are modified.
  3637. * - OPTIONS: fired when the grid options are modified.
  3638. */
  3639. self.api.registerMethod( 'core', 'notifyDataChange', this.notifyDataChange );
  3640. /**
  3641. * @ngdoc method
  3642. * @name clearAllFilters
  3643. * @methodOf ui.grid.core.api:PublicApi
  3644. * @description Clears all filters and optionally refreshes the visible rows.
  3645. * @param {object} refreshRows Defaults to true.
  3646. * @param {object} clearConditions Defaults to false.
  3647. * @param {object} clearFlags Defaults to false.
  3648. * @returns {promise} If `refreshRows` is true, returns a promise of the rows refreshing.
  3649. */
  3650. self.api.registerMethod('core', 'clearAllFilters', this.clearAllFilters);
  3651. self.registerDataChangeCallback( self.columnRefreshCallback, [uiGridConstants.dataChange.COLUMN]);
  3652. self.registerDataChangeCallback( self.processRowsCallback, [uiGridConstants.dataChange.EDIT]);
  3653. self.registerDataChangeCallback( self.updateFooterHeightCallback, [uiGridConstants.dataChange.OPTIONS]);
  3654. self.registerStyleComputation({
  3655. priority: 10,
  3656. func: self.getFooterStyles
  3657. });
  3658. };
  3659. Grid.prototype.calcFooterHeight = function () {
  3660. if (!this.hasFooter()) {
  3661. return 0;
  3662. }
  3663. var height = 0;
  3664. if (this.options.showGridFooter) {
  3665. height += this.options.gridFooterHeight;
  3666. }
  3667. height += this.calcColumnFooterHeight();
  3668. return height;
  3669. };
  3670. Grid.prototype.calcColumnFooterHeight = function () {
  3671. var height = 0;
  3672. if (this.options.showColumnFooter) {
  3673. height += this.options.columnFooterHeight;
  3674. }
  3675. return height;
  3676. };
  3677. Grid.prototype.getFooterStyles = function () {
  3678. var style = '.grid' + this.id + ' .ui-grid-footer-aggregates-row { height: ' + this.options.columnFooterHeight + 'px; }';
  3679. style += ' .grid' + this.id + ' .ui-grid-footer-info { height: ' + this.options.gridFooterHeight + 'px; }';
  3680. return style;
  3681. };
  3682. Grid.prototype.hasFooter = function () {
  3683. return this.options.showGridFooter || this.options.showColumnFooter;
  3684. };
  3685. /**
  3686. * @ngdoc function
  3687. * @name isRTL
  3688. * @methodOf ui.grid.class:Grid
  3689. * @description Returns true if grid is RightToLeft
  3690. */
  3691. Grid.prototype.isRTL = function () {
  3692. return this.rtl;
  3693. };
  3694. /**
  3695. * @ngdoc function
  3696. * @name registerColumnBuilder
  3697. * @methodOf ui.grid.class:Grid
  3698. * @description When the build creates columns from column definitions, the columnbuilders will be called to add
  3699. * additional properties to the column.
  3700. * @param {function(colDef, col, gridOptions)} columnBuilder function to be called
  3701. */
  3702. Grid.prototype.registerColumnBuilder = function registerColumnBuilder(columnBuilder) {
  3703. this.columnBuilders.push(columnBuilder);
  3704. };
  3705. /**
  3706. * @ngdoc function
  3707. * @name buildColumnDefsFromData
  3708. * @methodOf ui.grid.class:Grid
  3709. * @description Populates columnDefs from the provided data
  3710. * @param {function(colDef, col, gridOptions)} rowBuilder function to be called
  3711. */
  3712. Grid.prototype.buildColumnDefsFromData = function (dataRows){
  3713. this.options.columnDefs = gridUtil.getColumnsFromData(dataRows, this.options.excludeProperties);
  3714. };
  3715. /**
  3716. * @ngdoc function
  3717. * @name registerRowBuilder
  3718. * @methodOf ui.grid.class:Grid
  3719. * @description When the build creates rows from gridOptions.data, the rowBuilders will be called to add
  3720. * additional properties to the row.
  3721. * @param {function(row, gridOptions)} rowBuilder function to be called
  3722. */
  3723. Grid.prototype.registerRowBuilder = function registerRowBuilder(rowBuilder) {
  3724. this.rowBuilders.push(rowBuilder);
  3725. };
  3726. /**
  3727. * @ngdoc function
  3728. * @name registerDataChangeCallback
  3729. * @methodOf ui.grid.class:Grid
  3730. * @description When a data change occurs, the data change callbacks of the specified type
  3731. * will be called. The rules are:
  3732. *
  3733. * - when the data watch fires, that is considered a ROW change (the data watch only notices
  3734. * added or removed rows)
  3735. * - when the api is called to inform us of a change, the declared type of that change is used
  3736. * - when a cell edit completes, the EDIT callbacks are triggered
  3737. * - when the columnDef watch fires, the COLUMN callbacks are triggered
  3738. * - when the options watch fires, the OPTIONS callbacks are triggered
  3739. *
  3740. * For a given event:
  3741. * - ALL calls ROW, EDIT, COLUMN, OPTIONS and ALL callbacks
  3742. * - ROW calls ROW and ALL callbacks
  3743. * - EDIT calls EDIT and ALL callbacks
  3744. * - COLUMN calls COLUMN and ALL callbacks
  3745. * - OPTIONS calls OPTIONS and ALL callbacks
  3746. *
  3747. * @param {function(grid)} callback function to be called
  3748. * @param {array} types the types of data change you want to be informed of. Values from
  3749. * the {@link ui.grid.service:uiGridConstants#properties_dataChange uiGridConstants.dataChange}
  3750. * values ( ALL, EDIT, ROW, COLUMN, OPTIONS ). Optional and defaults to ALL
  3751. * @returns {function} deregister function - a function that can be called to deregister this callback
  3752. */
  3753. Grid.prototype.registerDataChangeCallback = function registerDataChangeCallback(callback, types, _this) {
  3754. var uid = gridUtil.nextUid();
  3755. if ( !types ){
  3756. types = [uiGridConstants.dataChange.ALL];
  3757. }
  3758. if ( !Array.isArray(types)){
  3759. gridUtil.logError("Expected types to be an array or null in registerDataChangeCallback, value passed was: " + types );
  3760. }
  3761. this.dataChangeCallbacks[uid] = { callback: callback, types: types, _this:_this };
  3762. var self = this;
  3763. var deregisterFunction = function() {
  3764. delete self.dataChangeCallbacks[uid];
  3765. };
  3766. return deregisterFunction;
  3767. };
  3768. /**
  3769. * @ngdoc function
  3770. * @name callDataChangeCallbacks
  3771. * @methodOf ui.grid.class:Grid
  3772. * @description Calls the callbacks based on the type of data change that
  3773. * has occurred. Always calls the ALL callbacks, calls the ROW, EDIT, COLUMN and OPTIONS callbacks if the
  3774. * event type is matching, or if the type is ALL.
  3775. * @param {string} type the type of event that occurred - one of the
  3776. * {@link ui.grid.service:uiGridConstants#properties_dataChange uiGridConstants.dataChange}
  3777. * values (ALL, ROW, EDIT, COLUMN, OPTIONS)
  3778. */
  3779. Grid.prototype.callDataChangeCallbacks = function callDataChangeCallbacks(type, options) {
  3780. angular.forEach( this.dataChangeCallbacks, function( callback, uid ){
  3781. if ( callback.types.indexOf( uiGridConstants.dataChange.ALL ) !== -1 ||
  3782. callback.types.indexOf( type ) !== -1 ||
  3783. type === uiGridConstants.dataChange.ALL ) {
  3784. if (callback._this) {
  3785. callback.callback.apply(callback._this, this, options);
  3786. }
  3787. else {
  3788. callback.callback(this, options);
  3789. }
  3790. }
  3791. }, this);
  3792. };
  3793. /**
  3794. * @ngdoc function
  3795. * @name notifyDataChange
  3796. * @methodOf ui.grid.class:Grid
  3797. * @description Notifies us that a data change has occurred, used in the public
  3798. * api for users to tell us when they've changed data or some other event that
  3799. * our watches cannot pick up
  3800. * @param {string} type the type of event that occurred - one of the
  3801. * uiGridConstants.dataChange values (ALL, ROW, EDIT, COLUMN, OPTIONS)
  3802. *
  3803. * - ALL: listeners fired on any of these events, fires listeners on all events.
  3804. * - ROW: fired when a row is added or removed.
  3805. * - EDIT: fired when the data in a cell is edited.
  3806. * - COLUMN: fired when the column definitions are modified.
  3807. * - OPTIONS: fired when the grid options are modified.
  3808. */
  3809. Grid.prototype.notifyDataChange = function notifyDataChange(type) {
  3810. var constants = uiGridConstants.dataChange;
  3811. if ( type === constants.ALL ||
  3812. type === constants.COLUMN ||
  3813. type === constants.EDIT ||
  3814. type === constants.ROW ||
  3815. type === constants.OPTIONS ){
  3816. this.callDataChangeCallbacks( type );
  3817. } else {
  3818. gridUtil.logError("Notified of a data change, but the type was not recognised, so no action taken, type was: " + type);
  3819. }
  3820. };
  3821. /**
  3822. * @ngdoc function
  3823. * @name columnRefreshCallback
  3824. * @methodOf ui.grid.class:Grid
  3825. * @description refreshes the grid when a column refresh
  3826. * is notified, which triggers handling of the visible flag.
  3827. * This is called on uiGridConstants.dataChange.COLUMN, and is
  3828. * registered as a dataChangeCallback in grid.js
  3829. * @param {object} grid The grid object.
  3830. * @param {object} options Any options passed into the callback.
  3831. */
  3832. Grid.prototype.columnRefreshCallback = function columnRefreshCallback(grid, options){
  3833. grid.buildColumns(options);
  3834. grid.queueGridRefresh();
  3835. };
  3836. /**
  3837. * @ngdoc function
  3838. * @name processRowsCallback
  3839. * @methodOf ui.grid.class:Grid
  3840. * @description calls the row processors, specifically
  3841. * intended to reset the sorting when an edit is called,
  3842. * registered as a dataChangeCallback on uiGridConstants.dataChange.EDIT
  3843. * @param {string} name column name
  3844. */
  3845. Grid.prototype.processRowsCallback = function processRowsCallback( grid ){
  3846. grid.queueGridRefresh();
  3847. };
  3848. /**
  3849. * @ngdoc function
  3850. * @name updateFooterHeightCallback
  3851. * @methodOf ui.grid.class:Grid
  3852. * @description recalculates the footer height,
  3853. * registered as a dataChangeCallback on uiGridConstants.dataChange.OPTIONS
  3854. * @param {string} name column name
  3855. */
  3856. Grid.prototype.updateFooterHeightCallback = function updateFooterHeightCallback( grid ){
  3857. grid.footerHeight = grid.calcFooterHeight();
  3858. grid.columnFooterHeight = grid.calcColumnFooterHeight();
  3859. };
  3860. /**
  3861. * @ngdoc function
  3862. * @name getColumn
  3863. * @methodOf ui.grid.class:Grid
  3864. * @description returns a grid column for the column name
  3865. * @param {string} name column name
  3866. */
  3867. Grid.prototype.getColumn = function getColumn(name) {
  3868. var columns = this.columns.filter(function (column) {
  3869. return column.colDef.name === name;
  3870. });
  3871. return columns.length > 0 ? columns[0] : null;
  3872. };
  3873. /**
  3874. * @ngdoc function
  3875. * @name getColDef
  3876. * @methodOf ui.grid.class:Grid
  3877. * @description returns a grid colDef for the column name
  3878. * @param {string} name column.field
  3879. */
  3880. Grid.prototype.getColDef = function getColDef(name) {
  3881. var colDefs = this.options.columnDefs.filter(function (colDef) {
  3882. return colDef.name === name;
  3883. });
  3884. return colDefs.length > 0 ? colDefs[0] : null;
  3885. };
  3886. /**
  3887. * @ngdoc function
  3888. * @name assignTypes
  3889. * @methodOf ui.grid.class:Grid
  3890. * @description uses the first row of data to assign colDef.type for any types not defined.
  3891. */
  3892. /**
  3893. * @ngdoc property
  3894. * @name type
  3895. * @propertyOf ui.grid.class:GridOptions.columnDef
  3896. * @description the type of the column, used in sorting. If not provided then the
  3897. * grid will guess the type. Add this only if the grid guessing is not to your
  3898. * satisfaction. One of:
  3899. * - 'string'
  3900. * - 'boolean'
  3901. * - 'number'
  3902. * - 'date'
  3903. * - 'object'
  3904. * - 'numberStr'
  3905. * Note that if you choose date, your dates should be in a javascript date type
  3906. *
  3907. */
  3908. Grid.prototype.assignTypes = function(){
  3909. var self = this;
  3910. self.options.columnDefs.forEach(function (colDef, index) {
  3911. //Assign colDef type if not specified
  3912. if (!colDef.type) {
  3913. var col = new GridColumn(colDef, index, self);
  3914. var firstRow = self.rows.length > 0 ? self.rows[0] : null;
  3915. if (firstRow) {
  3916. colDef.type = gridUtil.guessType(self.getCellValue(firstRow, col));
  3917. }
  3918. else {
  3919. colDef.type = 'string';
  3920. }
  3921. }
  3922. });
  3923. };
  3924. /**
  3925. * @ngdoc function
  3926. * @name isRowHeaderColumn
  3927. * @methodOf ui.grid.class:Grid
  3928. * @description returns true if the column is a row Header
  3929. * @param {object} column column
  3930. */
  3931. Grid.prototype.isRowHeaderColumn = function isRowHeaderColumn(column) {
  3932. return this.rowHeaderColumns.indexOf(column) !== -1;
  3933. };
  3934. /**
  3935. * @ngdoc function
  3936. * @name addRowHeaderColumn
  3937. * @methodOf ui.grid.class:Grid
  3938. * @description adds a row header column to the grid
  3939. * @param {object} colDef Column definition object.
  3940. * @param {float} order Number that indicates where the column should be placed in the grid.
  3941. * @param {boolean} stopColumnBuild Prevents the buildColumn callback from being triggered. This is useful to improve
  3942. * performance of the grid during initial load.
  3943. */
  3944. Grid.prototype.addRowHeaderColumn = function addRowHeaderColumn(colDef, order, stopColumnBuild) {
  3945. var self = this;
  3946. //default order
  3947. if (order === undefined) {
  3948. order = 0;
  3949. }
  3950. var rowHeaderCol = new GridColumn(colDef, gridUtil.nextUid(), self);
  3951. rowHeaderCol.isRowHeader = true;
  3952. if (self.isRTL()) {
  3953. self.createRightContainer();
  3954. rowHeaderCol.renderContainer = 'right';
  3955. }
  3956. else {
  3957. self.createLeftContainer();
  3958. rowHeaderCol.renderContainer = 'left';
  3959. }
  3960. // relies on the default column builder being first in array, as it is instantiated
  3961. // as part of grid creation
  3962. self.columnBuilders[0](colDef,rowHeaderCol,self.options)
  3963. .then(function(){
  3964. rowHeaderCol.enableFiltering = false;
  3965. rowHeaderCol.enableSorting = false;
  3966. rowHeaderCol.enableHiding = false;
  3967. rowHeaderCol.headerPriority = order;
  3968. self.rowHeaderColumns.push(rowHeaderCol);
  3969. self.rowHeaderColumns = self.rowHeaderColumns.sort(function (a, b) {
  3970. return a.headerPriority - b.headerPriority;
  3971. });
  3972. if (!stopColumnBuild) {
  3973. self.buildColumns()
  3974. .then(function() {
  3975. self.preCompileCellTemplates();
  3976. self.queueGridRefresh();
  3977. }).catch(angular.noop);
  3978. }
  3979. }).catch(angular.noop);
  3980. };
  3981. /**
  3982. * @ngdoc function
  3983. * @name getOnlyDataColumns
  3984. * @methodOf ui.grid.class:Grid
  3985. * @description returns all columns except for rowHeader columns
  3986. */
  3987. Grid.prototype.getOnlyDataColumns = function getOnlyDataColumns() {
  3988. var self = this;
  3989. var cols = [];
  3990. self.columns.forEach(function (col) {
  3991. if (self.rowHeaderColumns.indexOf(col) === -1) {
  3992. cols.push(col);
  3993. }
  3994. });
  3995. return cols;
  3996. };
  3997. /**
  3998. * @ngdoc function
  3999. * @name buildColumns
  4000. * @methodOf ui.grid.class:Grid
  4001. * @description creates GridColumn objects from the columnDefinition. Calls each registered
  4002. * columnBuilder to further process the column
  4003. * @param {object} options An object contains options to use when building columns
  4004. *
  4005. * * **orderByColumnDefs**: defaults to **false**. When true, `buildColumns` will reorder existing columns according to the order within the column definitions.
  4006. *
  4007. * @returns {Promise} a promise to load any needed column resources
  4008. */
  4009. Grid.prototype.buildColumns = function buildColumns(opts) {
  4010. var options = {
  4011. orderByColumnDefs: false
  4012. };
  4013. angular.extend(options, opts);
  4014. // gridUtil.logDebug('buildColumns');
  4015. var self = this;
  4016. var builderPromises = [];
  4017. var headerOffset = self.rowHeaderColumns.length;
  4018. var i;
  4019. // Remove any columns for which a columnDef cannot be found
  4020. // Deliberately don't use forEach, as it doesn't like splice being called in the middle
  4021. // Also don't cache columns.length, as it will change during this operation
  4022. for (i = 0; i < self.columns.length; i++){
  4023. if (!self.getColDef(self.columns[i].name)) {
  4024. self.columns.splice(i, 1);
  4025. i--;
  4026. }
  4027. }
  4028. //add row header columns to the grid columns array _after_ columns without columnDefs have been removed
  4029. //rowHeaderColumns is ordered by priority so insert in reverse
  4030. for (var j = self.rowHeaderColumns.length - 1; j >= 0; j--) {
  4031. self.columns.unshift(self.rowHeaderColumns[j]);
  4032. }
  4033. // look at each column def, and update column properties to match. If the column def
  4034. // doesn't have a column, then splice in a new gridCol
  4035. self.options.columnDefs.forEach(function (colDef, index) {
  4036. self.preprocessColDef(colDef);
  4037. var col = self.getColumn(colDef.name);
  4038. if (!col) {
  4039. col = new GridColumn(colDef, gridUtil.nextUid(), self);
  4040. self.columns.splice(index + headerOffset, 0, col);
  4041. }
  4042. else {
  4043. // tell updateColumnDef that the column was pre-existing
  4044. col.updateColumnDef(colDef, false);
  4045. }
  4046. self.columnBuilders.forEach(function (builder) {
  4047. builderPromises.push(builder.call(self, colDef, col, self.options));
  4048. });
  4049. });
  4050. /*** Reorder columns if necessary ***/
  4051. if (!!options.orderByColumnDefs) {
  4052. // Create a shallow copy of the columns as a cache
  4053. var columnCache = self.columns.slice(0);
  4054. // We need to allow for the "row headers" when mapping from the column defs array to the columns array
  4055. // If we have a row header in columns[0] and don't account for it we'll overwrite it with the column in columnDefs[0]
  4056. // Go through all the column defs, use the shorter of columns length and colDefs.length because if a user has given two columns the same name then
  4057. // columns will be shorter than columnDefs. In this situation we'll avoid an error, but the user will still get an unexpected result
  4058. var len = Math.min(self.options.columnDefs.length, self.columns.length);
  4059. for (i = 0; i < len; i++) {
  4060. // If the column at this index has a different name than the column at the same index in the column defs...
  4061. if (self.columns[i + headerOffset].name !== self.options.columnDefs[i].name) {
  4062. // Replace the one in the cache with the appropriate column
  4063. columnCache[i + headerOffset] = self.getColumn(self.options.columnDefs[i].name);
  4064. }
  4065. else {
  4066. // Otherwise just copy over the one from the initial columns
  4067. columnCache[i + headerOffset] = self.columns[i + headerOffset];
  4068. }
  4069. }
  4070. // Empty out the columns array, non-destructively
  4071. self.columns.length = 0;
  4072. // And splice in the updated, ordered columns from the cache
  4073. Array.prototype.splice.apply(self.columns, [0, 0].concat(columnCache));
  4074. }
  4075. return $q.all(builderPromises).then(function(){
  4076. if (self.rows.length > 0){
  4077. self.assignTypes();
  4078. }
  4079. if (options.preCompileCellTemplates) {
  4080. self.preCompileCellTemplates();
  4081. }
  4082. }).catch(angular.noop);
  4083. };
  4084. Grid.prototype.preCompileCellTemplate = function(col) {
  4085. var self = this;
  4086. var html = col.cellTemplate.replace(uiGridConstants.MODEL_COL_FIELD, self.getQualifiedColField(col));
  4087. html = html.replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)');
  4088. col.compiledElementFn = $compile(html);
  4089. if (col.compiledElementFnDefer) {
  4090. col.compiledElementFnDefer.resolve(col.compiledElementFn);
  4091. }
  4092. };
  4093. /**
  4094. * @ngdoc function
  4095. * @name preCompileCellTemplates
  4096. * @methodOf ui.grid.class:Grid
  4097. * @description precompiles all cell templates
  4098. */
  4099. Grid.prototype.preCompileCellTemplates = function() {
  4100. var self = this;
  4101. self.columns.forEach(function (col) {
  4102. if ( col.cellTemplate ){
  4103. self.preCompileCellTemplate( col );
  4104. } else if ( col.cellTemplatePromise ){
  4105. col.cellTemplatePromise.then( function() {
  4106. self.preCompileCellTemplate( col );
  4107. }).catch(angular.noop);
  4108. }
  4109. });
  4110. };
  4111. /**
  4112. * @ngdoc function
  4113. * @name getGridQualifiedColField
  4114. * @methodOf ui.grid.class:Grid
  4115. * @description Returns the $parse-able accessor for a column within its $scope
  4116. * @param {GridColumn} col col object
  4117. */
  4118. Grid.prototype.getQualifiedColField = function (col) {
  4119. var base = 'row.entity';
  4120. if ( col.field === uiGridConstants.ENTITY_BINDING ) {
  4121. return base;
  4122. }
  4123. return gridUtil.preEval(base + '.' + col.field);
  4124. };
  4125. /**
  4126. * @ngdoc function
  4127. * @name createLeftContainer
  4128. * @methodOf ui.grid.class:Grid
  4129. * @description creates the left render container if it doesn't already exist
  4130. */
  4131. Grid.prototype.createLeftContainer = function() {
  4132. if (!this.hasLeftContainer()) {
  4133. this.renderContainers.left = new GridRenderContainer('left', this, { disableColumnOffset: true });
  4134. }
  4135. };
  4136. /**
  4137. * @ngdoc function
  4138. * @name createRightContainer
  4139. * @methodOf ui.grid.class:Grid
  4140. * @description creates the right render container if it doesn't already exist
  4141. */
  4142. Grid.prototype.createRightContainer = function() {
  4143. if (!this.hasRightContainer()) {
  4144. this.renderContainers.right = new GridRenderContainer('right', this, { disableColumnOffset: true });
  4145. }
  4146. };
  4147. /**
  4148. * @ngdoc function
  4149. * @name hasLeftContainer
  4150. * @methodOf ui.grid.class:Grid
  4151. * @description returns true if leftContainer exists
  4152. */
  4153. Grid.prototype.hasLeftContainer = function() {
  4154. return this.renderContainers.left !== undefined;
  4155. };
  4156. /**
  4157. * @ngdoc function
  4158. * @name hasRightContainer
  4159. * @methodOf ui.grid.class:Grid
  4160. * @description returns true if rightContainer exists
  4161. */
  4162. Grid.prototype.hasRightContainer = function() {
  4163. return this.renderContainers.right !== undefined;
  4164. };
  4165. /**
  4166. * undocumented function
  4167. * @name preprocessColDef
  4168. * @methodOf ui.grid.class:Grid
  4169. * @description defaults the name property from field to maintain backwards compatibility with 2.x
  4170. * validates that name or field is present
  4171. */
  4172. Grid.prototype.preprocessColDef = function preprocessColDef(colDef) {
  4173. var self = this;
  4174. if (!colDef.field && !colDef.name) {
  4175. throw new Error('colDef.name or colDef.field property is required');
  4176. }
  4177. //maintain backwards compatibility with 2.x
  4178. //field was required in 2.x. now name is required
  4179. if (colDef.name === undefined && colDef.field !== undefined) {
  4180. // See if the column name already exists:
  4181. var newName = colDef.field,
  4182. counter = 2;
  4183. while (self.getColumn(newName)) {
  4184. newName = colDef.field + counter.toString();
  4185. counter++;
  4186. }
  4187. colDef.name = newName;
  4188. }
  4189. };
  4190. // Return a list of items that exist in the `n` array but not the `o` array. Uses optional property accessors passed as third & fourth parameters
  4191. Grid.prototype.newInN = function newInN(o, n, oAccessor, nAccessor) {
  4192. var self = this;
  4193. var t = [];
  4194. for (var i = 0; i < n.length; i++) {
  4195. var nV = nAccessor ? n[i][nAccessor] : n[i];
  4196. var found = false;
  4197. for (var j = 0; j < o.length; j++) {
  4198. var oV = oAccessor ? o[j][oAccessor] : o[j];
  4199. if (self.options.rowEquality(nV, oV)) {
  4200. found = true;
  4201. break;
  4202. }
  4203. }
  4204. if (!found) {
  4205. t.push(nV);
  4206. }
  4207. }
  4208. return t;
  4209. };
  4210. /**
  4211. * @ngdoc function
  4212. * @name getRow
  4213. * @methodOf ui.grid.class:Grid
  4214. * @description returns the GridRow that contains the rowEntity
  4215. * @param {object} rowEntity the gridOptions.data array element instance
  4216. * @param {array} lookInRows [optional] the rows to look in - if not provided then
  4217. * looks in grid.rows
  4218. */
  4219. Grid.prototype.getRow = function getRow(rowEntity, lookInRows) {
  4220. var self = this;
  4221. lookInRows = typeof(lookInRows) === 'undefined' ? self.rows : lookInRows;
  4222. var rows = lookInRows.filter(function (row) {
  4223. return self.options.rowEquality(row.entity, rowEntity);
  4224. });
  4225. return rows.length > 0 ? rows[0] : null;
  4226. };
  4227. /**
  4228. * @ngdoc function
  4229. * @name modifyRows
  4230. * @methodOf ui.grid.class:Grid
  4231. * @description creates or removes GridRow objects from the newRawData array. Calls each registered
  4232. * rowBuilder to further process the row
  4233. * @param {array} newRawData Modified set of data
  4234. *
  4235. * This method aims to achieve three things:
  4236. * 1. the resulting rows array is in the same order as the newRawData, we'll call
  4237. * rowsProcessors immediately after to sort the data anyway
  4238. * 2. if we have row hashing available, we try to use the rowHash to find the row
  4239. * 3. no memory leaks - rows that are no longer in newRawData need to be garbage collected
  4240. *
  4241. * The basic logic flow makes use of the newRawData, oldRows and oldHash, and creates
  4242. * the newRows and newHash
  4243. *
  4244. * ```
  4245. * newRawData.forEach newEntity
  4246. * if (hashing enabled)
  4247. * check oldHash for newEntity
  4248. * else
  4249. * look for old row directly in oldRows
  4250. * if !oldRowFound // must be a new row
  4251. * create newRow
  4252. * append to the newRows and add to newHash
  4253. * run the processors
  4254. * ```
  4255. *
  4256. * Rows are identified using the hashKey if configured. If not configured, then rows
  4257. * are identified using the gridOptions.rowEquality function
  4258. *
  4259. * This method is useful when trying to select rows immediately after loading data without
  4260. * using a $timeout/$interval, e.g.:
  4261. *
  4262. * $scope.gridOptions.data = someData;
  4263. * $scope.gridApi.grid.modifyRows($scope.gridOptions.data);
  4264. * $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]);
  4265. *
  4266. * OR to persist row selection after data update (e.g. rows selected, new data loaded, want
  4267. * originally selected rows to be re-selected))
  4268. */
  4269. Grid.prototype.modifyRows = function modifyRows(newRawData) {
  4270. var self = this;
  4271. var oldRows = self.rows.slice(0);
  4272. var oldRowHash = self.rowHashMap || self.createRowHashMap();
  4273. var allRowsSelected = true;
  4274. self.rowHashMap = self.createRowHashMap();
  4275. self.rows.length = 0;
  4276. newRawData.forEach( function( newEntity, i ) {
  4277. var newRow, oldRow;
  4278. if ( self.options.enableRowHashing ){
  4279. // if hashing is enabled, then this row will be in the hash if we already know about it
  4280. oldRow = oldRowHash.get( newEntity );
  4281. } else {
  4282. // otherwise, manually search the oldRows to see if we can find this row
  4283. oldRow = self.getRow(newEntity, oldRows);
  4284. }
  4285. // update newRow to have an entity
  4286. if ( oldRow ) {
  4287. newRow = oldRow;
  4288. newRow.entity = newEntity;
  4289. }
  4290. // if we didn't find the row, it must be new, so create it
  4291. if ( !newRow ){
  4292. newRow = self.processRowBuilders(new GridRow(newEntity, i, self));
  4293. }
  4294. self.rows.push( newRow );
  4295. self.rowHashMap.put( newEntity, newRow );
  4296. if (!newRow.isSelected) {
  4297. allRowsSelected = false;
  4298. }
  4299. });
  4300. if (self.selection && self.rows.length) {
  4301. self.selection.selectAll = allRowsSelected;
  4302. }
  4303. self.assignTypes();
  4304. var p1 = $q.when(self.processRowsProcessors(self.rows))
  4305. .then(function (renderableRows) {
  4306. return self.setVisibleRows(renderableRows);
  4307. }).catch(angular.noop);
  4308. var p2 = $q.when(self.processColumnsProcessors(self.columns))
  4309. .then(function (renderableColumns) {
  4310. return self.setVisibleColumns(renderableColumns);
  4311. }).catch(angular.noop);
  4312. return $q.all([p1, p2]);
  4313. };
  4314. /**
  4315. * Private Undocumented Method
  4316. * @name addRows
  4317. * @methodOf ui.grid.class:Grid
  4318. * @description adds the newRawData array of rows to the grid and calls all registered
  4319. * rowBuilders. this keyword will reference the grid
  4320. */
  4321. Grid.prototype.addRows = function addRows(newRawData) {
  4322. var self = this;
  4323. var existingRowCount = self.rows.length;
  4324. for (var i = 0; i < newRawData.length; i++) {
  4325. var newRow = self.processRowBuilders(new GridRow(newRawData[i], i + existingRowCount, self));
  4326. if (self.options.enableRowHashing) {
  4327. var found = self.rowHashMap.get(newRow.entity);
  4328. if (found) {
  4329. found.row = newRow;
  4330. }
  4331. }
  4332. self.rows.push(newRow);
  4333. }
  4334. };
  4335. /**
  4336. * @ngdoc function
  4337. * @name processRowBuilders
  4338. * @methodOf ui.grid.class:Grid
  4339. * @description processes all RowBuilders for the gridRow
  4340. * @param {GridRow} gridRow reference to gridRow
  4341. * @returns {GridRow} the gridRow with all additional behavior added
  4342. */
  4343. Grid.prototype.processRowBuilders = function processRowBuilders(gridRow) {
  4344. var self = this;
  4345. self.rowBuilders.forEach(function (builder) {
  4346. builder.call(self, gridRow, self.options);
  4347. });
  4348. return gridRow;
  4349. };
  4350. /**
  4351. * @ngdoc function
  4352. * @name registerStyleComputation
  4353. * @methodOf ui.grid.class:Grid
  4354. * @description registered a styleComputation function
  4355. *
  4356. * If the function returns a value it will be appended into the grid's `<style>` block
  4357. * @param {function($scope)} styleComputationInfo function
  4358. */
  4359. Grid.prototype.registerStyleComputation = function registerStyleComputation(styleComputationInfo) {
  4360. this.styleComputations.push(styleComputationInfo);
  4361. };
  4362. // NOTE (c0bra): We already have rowBuilders. I think these do exactly the same thing...
  4363. // Grid.prototype.registerRowFilter = function(filter) {
  4364. // // TODO(c0bra): validate filter?
  4365. // this.rowFilters.push(filter);
  4366. // };
  4367. // Grid.prototype.removeRowFilter = function(filter) {
  4368. // var idx = this.rowFilters.indexOf(filter);
  4369. // if (typeof(idx) !== 'undefined' && idx !== undefined) {
  4370. // this.rowFilters.slice(idx, 1);
  4371. // }
  4372. // };
  4373. // Grid.prototype.processRowFilters = function(rows) {
  4374. // var self = this;
  4375. // self.rowFilters.forEach(function (filter) {
  4376. // filter.call(self, rows);
  4377. // });
  4378. // };
  4379. /**
  4380. * @ngdoc function
  4381. * @name registerRowsProcessor
  4382. * @methodOf ui.grid.class:Grid
  4383. * @description
  4384. *
  4385. * Register a "rows processor" function. When the rows are updated,
  4386. * the grid calls each registered "rows processor", which has a chance
  4387. * to alter the set of rows (sorting, etc) as long as the count is not
  4388. * modified.
  4389. *
  4390. * @param {function(renderedRowsToProcess, columns )} processor rows processor function, which
  4391. * is run in the context of the grid (i.e. this for the function will be the grid), and must
  4392. * return the updated rows list, which is passed to the next processor in the chain
  4393. * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room
  4394. * for other people to inject rows processors at intermediate priorities. Lower priority rowsProcessors run earlier.
  4395. *
  4396. * At present all rows visible is running at 50, filter is running at 100, sort is at 200, grouping at 400, selectable rows at 500, pagination at 900 (pagination will generally want to be last)
  4397. *
  4398. */
  4399. Grid.prototype.registerRowsProcessor = function registerRowsProcessor(processor, priority) {
  4400. if (!angular.isFunction(processor)) {
  4401. throw 'Attempt to register non-function rows processor: ' + processor;
  4402. }
  4403. this.rowsProcessors.push({processor: processor, priority: priority});
  4404. this.rowsProcessors.sort(function sortByPriority( a, b ){
  4405. return a.priority - b.priority;
  4406. });
  4407. };
  4408. /**
  4409. * @ngdoc function
  4410. * @name removeRowsProcessor
  4411. * @methodOf ui.grid.class:Grid
  4412. * @param {function(renderableRows)} processor processor function
  4413. * @description Remove a registered rows processor
  4414. */
  4415. Grid.prototype.removeRowsProcessor = function removeRowsProcessor(processor) {
  4416. var idx = -1;
  4417. this.rowsProcessors.forEach(function(rowsProcessor, index){
  4418. if ( rowsProcessor.processor === processor ){
  4419. idx = index;
  4420. }
  4421. });
  4422. if ( idx !== -1 ) {
  4423. this.rowsProcessors.splice(idx, 1);
  4424. }
  4425. };
  4426. /**
  4427. * Private Undocumented Method
  4428. * @name processRowsProcessors
  4429. * @methodOf ui.grid.class:Grid
  4430. * @param {Array[GridRow]} renderableRows The array of "renderable" rows
  4431. * @description Run all the registered rows processors on the array of renderable rows
  4432. */
  4433. Grid.prototype.processRowsProcessors = function processRowsProcessors(renderableRows) {
  4434. var self = this;
  4435. // Create a shallow copy of the rows so that we can safely sort them without altering the original grid.rows sort order
  4436. var myRenderableRows = renderableRows.slice(0);
  4437. // Return myRenderableRows with no processing if we have no rows processors
  4438. if (self.rowsProcessors.length === 0) {
  4439. return $q.when(myRenderableRows);
  4440. }
  4441. // Counter for iterating through rows processors
  4442. var i = 0;
  4443. // Promise for when we're done with all the processors
  4444. var finished = $q.defer();
  4445. // This function will call the processor in self.rowsProcessors at index 'i', and then
  4446. // when done will call the next processor in the list, using the output from the processor
  4447. // at i as the argument for 'renderedRowsToProcess' on the next iteration.
  4448. //
  4449. // If we're at the end of the list of processors, we resolve our 'finished' callback with
  4450. // the result.
  4451. function startProcessor(i, renderedRowsToProcess) {
  4452. // Get the processor at 'i'
  4453. var processor = self.rowsProcessors[i].processor;
  4454. // Call the processor, passing in the rows to process and the current columns
  4455. // (note: it's wrapped in $q.when() in case the processor does not return a promise)
  4456. return $q.when( processor.call(self, renderedRowsToProcess, self.columns) )
  4457. .then(function handleProcessedRows(processedRows) {
  4458. // Check for errors
  4459. if (!processedRows) {
  4460. throw "Processor at index " + i + " did not return a set of renderable rows";
  4461. }
  4462. if (!angular.isArray(processedRows)) {
  4463. throw "Processor at index " + i + " did not return an array";
  4464. }
  4465. // Processor is done, increment the counter
  4466. i++;
  4467. // If we're not done with the processors, call the next one
  4468. if (i <= self.rowsProcessors.length - 1) {
  4469. return startProcessor(i, processedRows);
  4470. }
  4471. // We're done! Resolve the 'finished' promise
  4472. else {
  4473. finished.resolve(processedRows);
  4474. }
  4475. }).catch(function(error) {
  4476. throw error;
  4477. });
  4478. }
  4479. // Start on the first processor
  4480. startProcessor(0, myRenderableRows);
  4481. return finished.promise;
  4482. };
  4483. Grid.prototype.setVisibleRows = function setVisibleRows(rows) {
  4484. var self = this;
  4485. // Reset all the render container row caches
  4486. for (var i in self.renderContainers) {
  4487. var container = self.renderContainers[i];
  4488. container.canvasHeightShouldUpdate = true;
  4489. if ( typeof(container.visibleRowCache) === 'undefined' ){
  4490. container.visibleRowCache = [];
  4491. } else {
  4492. container.visibleRowCache.length = 0;
  4493. }
  4494. }
  4495. // rows.forEach(function (row) {
  4496. for (var ri = 0; ri < rows.length; ri++) {
  4497. var row = rows[ri];
  4498. var targetContainer = (typeof(row.renderContainer) !== 'undefined' && row.renderContainer) ? row.renderContainer : 'body';
  4499. // If the row is visible
  4500. if (row.visible) {
  4501. self.renderContainers[targetContainer].visibleRowCache.push(row);
  4502. }
  4503. }
  4504. self.api.core.raise.rowsVisibleChanged(this.api);
  4505. self.api.core.raise.rowsRendered(this.api);
  4506. };
  4507. /**
  4508. * @ngdoc function
  4509. * @name registerColumnsProcessor
  4510. * @methodOf ui.grid.class:Grid
  4511. * @param {function(renderedColumnsToProcess, rows)} processor column processor function, which
  4512. * is run in the context of the grid (i.e. this for the function will be the grid), and
  4513. * which must return an updated renderedColumnsToProcess which can be passed to the next processor
  4514. * in the chain
  4515. * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room
  4516. * for other people to inject columns processors at intermediate priorities. Lower priority columnsProcessors run earlier.
  4517. *
  4518. * At present all rows visible is running at 50, filter is running at 100, sort is at 200, grouping at 400, selectable rows at 500, pagination at 900 (pagination will generally want to be last)
  4519. * @description
  4520. Register a "columns processor" function. When the columns are updated,
  4521. the grid calls each registered "columns processor", which has a chance
  4522. to alter the set of columns, as long as the count is not modified.
  4523. */
  4524. Grid.prototype.registerColumnsProcessor = function registerColumnsProcessor(processor, priority) {
  4525. if (!angular.isFunction(processor)) {
  4526. throw 'Attempt to register non-function rows processor: ' + processor;
  4527. }
  4528. this.columnsProcessors.push({processor: processor, priority: priority});
  4529. this.columnsProcessors.sort(function sortByPriority( a, b ){
  4530. return a.priority - b.priority;
  4531. });
  4532. };
  4533. Grid.prototype.removeColumnsProcessor = function removeColumnsProcessor(processor) {
  4534. var idx = this.columnsProcessors.indexOf(processor);
  4535. if (typeof(idx) !== 'undefined' && idx !== undefined) {
  4536. this.columnsProcessors.splice(idx, 1);
  4537. }
  4538. };
  4539. Grid.prototype.processColumnsProcessors = function processColumnsProcessors(renderableColumns) {
  4540. var self = this;
  4541. // Create a shallow copy of the rows so that we can safely sort them without altering the original grid.rows sort order
  4542. var myRenderableColumns = renderableColumns.slice(0);
  4543. // Return myRenderableRows with no processing if we have no rows processors
  4544. if (self.columnsProcessors.length === 0) {
  4545. return $q.when(myRenderableColumns);
  4546. }
  4547. // Counter for iterating through rows processors
  4548. var i = 0;
  4549. // Promise for when we're done with all the processors
  4550. var finished = $q.defer();
  4551. // This function will call the processor in self.rowsProcessors at index 'i', and then
  4552. // when done will call the next processor in the list, using the output from the processor
  4553. // at i as the argument for 'renderedRowsToProcess' on the next iteration.
  4554. //
  4555. // If we're at the end of the list of processors, we resolve our 'finished' callback with
  4556. // the result.
  4557. function startProcessor(i, renderedColumnsToProcess) {
  4558. // Get the processor at 'i'
  4559. var processor = self.columnsProcessors[i].processor;
  4560. // Call the processor, passing in the rows to process and the current columns
  4561. // (note: it's wrapped in $q.when() in case the processor does not return a promise)
  4562. return $q.when( processor.call(self, renderedColumnsToProcess, self.rows) )
  4563. .then(function handleProcessedRows(processedColumns) {
  4564. // Check for errors
  4565. if (!processedColumns) {
  4566. throw "Processor at index " + i + " did not return a set of renderable rows";
  4567. }
  4568. if (!angular.isArray(processedColumns)) {
  4569. throw "Processor at index " + i + " did not return an array";
  4570. }
  4571. // Processor is done, increment the counter
  4572. i++;
  4573. // If we're not done with the processors, call the next one
  4574. if (i <= self.columnsProcessors.length - 1) {
  4575. return startProcessor(i, myRenderableColumns);
  4576. }
  4577. // We're done! Resolve the 'finished' promise
  4578. else {
  4579. finished.resolve(myRenderableColumns);
  4580. }
  4581. }).catch(angular.noop);
  4582. }
  4583. // Start on the first processor
  4584. startProcessor(0, myRenderableColumns);
  4585. return finished.promise;
  4586. };
  4587. Grid.prototype.setVisibleColumns = function setVisibleColumns(columns) {
  4588. // gridUtil.logDebug('setVisibleColumns');
  4589. var self = this;
  4590. // Reset all the render container row caches
  4591. for (var i in self.renderContainers) {
  4592. var container = self.renderContainers[i];
  4593. container.visibleColumnCache.length = 0;
  4594. }
  4595. for (var ci = 0; ci < columns.length; ci++) {
  4596. var column = columns[ci];
  4597. // If the column is visible
  4598. if (column.visible) {
  4599. // If the column has a container specified
  4600. if (typeof(column.renderContainer) !== 'undefined' && column.renderContainer) {
  4601. self.renderContainers[column.renderContainer].visibleColumnCache.push(column);
  4602. }
  4603. // If not, put it into the body container
  4604. else {
  4605. self.renderContainers.body.visibleColumnCache.push(column);
  4606. }
  4607. }
  4608. }
  4609. };
  4610. /**
  4611. * @ngdoc function
  4612. * @name handleWindowResize
  4613. * @methodOf ui.grid.class:Grid
  4614. * @description Triggered when the browser window resizes; automatically resizes the grid
  4615. * @returns {Promise} A resolved promise once the window resize has completed.
  4616. */
  4617. Grid.prototype.handleWindowResize = function handleWindowResize($event) {
  4618. var self = this;
  4619. self.gridWidth = gridUtil.elementWidth(self.element);
  4620. self.gridHeight = gridUtil.elementHeight(self.element);
  4621. return self.queueRefresh();
  4622. };
  4623. /**
  4624. * @ngdoc function
  4625. * @name queueRefresh
  4626. * @methodOf ui.grid.class:Grid
  4627. * @description queues a grid refreshCanvas, a way of debouncing all the refreshes we might otherwise issue
  4628. */
  4629. Grid.prototype.queueRefresh = function queueRefresh() {
  4630. var self = this;
  4631. if (self.refreshCanceller) {
  4632. $timeout.cancel(self.refreshCanceller);
  4633. }
  4634. self.refreshCanceller = $timeout(function () {
  4635. self.refreshCanvas(true);
  4636. });
  4637. self.refreshCanceller.then(function () {
  4638. self.refreshCanceller = null;
  4639. }).catch(angular.noop);
  4640. return self.refreshCanceller;
  4641. };
  4642. /**
  4643. * @ngdoc function
  4644. * @name queueGridRefresh
  4645. * @methodOf ui.grid.class:Grid
  4646. * @description queues a grid refresh, a way of debouncing all the refreshes we might otherwise issue
  4647. */
  4648. Grid.prototype.queueGridRefresh = function queueGridRefresh() {
  4649. var self = this;
  4650. if (self.gridRefreshCanceller) {
  4651. $timeout.cancel(self.gridRefreshCanceller);
  4652. }
  4653. self.gridRefreshCanceller = $timeout(function () {
  4654. self.refresh(true);
  4655. });
  4656. self.gridRefreshCanceller.then(function () {
  4657. self.gridRefreshCanceller = null;
  4658. }).catch(angular.noop);
  4659. return self.gridRefreshCanceller;
  4660. };
  4661. /**
  4662. * @ngdoc function
  4663. * @name updateCanvasHeight
  4664. * @methodOf ui.grid.class:Grid
  4665. * @description flags all render containers to update their canvas height
  4666. */
  4667. Grid.prototype.updateCanvasHeight = function updateCanvasHeight() {
  4668. var self = this;
  4669. for (var containerId in self.renderContainers) {
  4670. if (self.renderContainers.hasOwnProperty(containerId)) {
  4671. var container = self.renderContainers[containerId];
  4672. container.canvasHeightShouldUpdate = true;
  4673. }
  4674. }
  4675. };
  4676. /**
  4677. * @ngdoc function
  4678. * @name buildStyles
  4679. * @methodOf ui.grid.class:Grid
  4680. * @description calls each styleComputation function
  4681. */
  4682. Grid.prototype.buildStyles = function buildStyles() {
  4683. var self = this;
  4684. // gridUtil.logDebug('buildStyles');
  4685. self.customStyles = '';
  4686. self.styleComputations
  4687. .sort(function(a, b) {
  4688. if (a.priority === null) { return 1; }
  4689. if (b.priority === null) { return -1; }
  4690. if (a.priority === null && b.priority === null) { return 0; }
  4691. return a.priority - b.priority;
  4692. })
  4693. .forEach(function (compInfo) {
  4694. // this used to provide $scope as a second parameter, but I couldn't find any
  4695. // style builders that used it, so removed it as part of moving to grid from controller
  4696. var ret = compInfo.func.call(self);
  4697. if (angular.isString(ret)) {
  4698. self.customStyles += '\n' + ret;
  4699. }
  4700. });
  4701. };
  4702. Grid.prototype.minColumnsToRender = function minColumnsToRender() {
  4703. var self = this;
  4704. var viewport = this.getViewportWidth();
  4705. var min = 0;
  4706. var totalWidth = 0;
  4707. self.columns.forEach(function(col, i) {
  4708. if (totalWidth < viewport) {
  4709. totalWidth += col.drawnWidth;
  4710. min++;
  4711. }
  4712. else {
  4713. var currWidth = 0;
  4714. for (var j = i; j >= i - min; j--) {
  4715. currWidth += self.columns[j].drawnWidth;
  4716. }
  4717. if (currWidth < viewport) {
  4718. min++;
  4719. }
  4720. }
  4721. });
  4722. return min;
  4723. };
  4724. Grid.prototype.getBodyHeight = function getBodyHeight() {
  4725. // Start with the viewportHeight
  4726. var bodyHeight = this.getViewportHeight();
  4727. // Add the horizontal scrollbar height if there is one
  4728. //if (typeof(this.horizontalScrollbarHeight) !== 'undefined' && this.horizontalScrollbarHeight !== undefined && this.horizontalScrollbarHeight > 0) {
  4729. // bodyHeight = bodyHeight + this.horizontalScrollbarHeight;
  4730. //}
  4731. return bodyHeight;
  4732. };
  4733. // NOTE: viewport drawable height is the height of the grid minus the header row height (including any border)
  4734. // TODO(c0bra): account for footer height
  4735. Grid.prototype.getViewportHeight = function getViewportHeight() {
  4736. var self = this;
  4737. var viewPortHeight = this.gridHeight - this.headerHeight - this.footerHeight;
  4738. // Account for native horizontal scrollbar, if present
  4739. //if (typeof(this.horizontalScrollbarHeight) !== 'undefined' && this.horizontalScrollbarHeight !== undefined && this.horizontalScrollbarHeight > 0) {
  4740. // viewPortHeight = viewPortHeight - this.horizontalScrollbarHeight;
  4741. //}
  4742. var adjustment = self.getViewportAdjustment();
  4743. viewPortHeight = viewPortHeight + adjustment.height;
  4744. //gridUtil.logDebug('viewPortHeight', viewPortHeight);
  4745. return viewPortHeight;
  4746. };
  4747. Grid.prototype.getViewportWidth = function getViewportWidth() {
  4748. var self = this;
  4749. var viewPortWidth = this.gridWidth;
  4750. //if (typeof(this.verticalScrollbarWidth) !== 'undefined' && this.verticalScrollbarWidth !== undefined && this.verticalScrollbarWidth > 0) {
  4751. // viewPortWidth = viewPortWidth - this.verticalScrollbarWidth;
  4752. //}
  4753. var adjustment = self.getViewportAdjustment();
  4754. viewPortWidth = viewPortWidth + adjustment.width;
  4755. //gridUtil.logDebug('getviewPortWidth', viewPortWidth);
  4756. return viewPortWidth;
  4757. };
  4758. Grid.prototype.getHeaderViewportWidth = function getHeaderViewportWidth() {
  4759. var viewPortWidth = this.getViewportWidth();
  4760. //if (typeof(this.verticalScrollbarWidth) !== 'undefined' && this.verticalScrollbarWidth !== undefined && this.verticalScrollbarWidth > 0) {
  4761. // viewPortWidth = viewPortWidth + this.verticalScrollbarWidth;
  4762. //}
  4763. return viewPortWidth;
  4764. };
  4765. Grid.prototype.addVerticalScrollSync = function (containerId, callBackFn) {
  4766. this.verticalScrollSyncCallBackFns[containerId] = callBackFn;
  4767. };
  4768. Grid.prototype.addHorizontalScrollSync = function (containerId, callBackFn) {
  4769. this.horizontalScrollSyncCallBackFns[containerId] = callBackFn;
  4770. };
  4771. /**
  4772. * Scroll needed containers by calling their ScrollSyncs
  4773. * @param sourceContainerId the containerId that has already set it's top/left.
  4774. * can be empty string which means all containers need to set top/left
  4775. * @param scrollEvent
  4776. */
  4777. Grid.prototype.scrollContainers = function (sourceContainerId, scrollEvent) {
  4778. if (scrollEvent.y) {
  4779. //default for no container Id (ex. mousewheel means that all containers must set scrollTop/Left)
  4780. var verts = ['body','left', 'right'];
  4781. this.flagScrollingVertically(scrollEvent);
  4782. if (sourceContainerId === 'body') {
  4783. verts = ['left', 'right'];
  4784. }
  4785. else if (sourceContainerId === 'left') {
  4786. verts = ['body', 'right'];
  4787. }
  4788. else if (sourceContainerId === 'right') {
  4789. verts = ['body', 'left'];
  4790. }
  4791. for (var i = 0; i < verts.length; i++) {
  4792. var id = verts[i];
  4793. if (this.verticalScrollSyncCallBackFns[id]) {
  4794. this.verticalScrollSyncCallBackFns[id](scrollEvent);
  4795. }
  4796. }
  4797. }
  4798. if (scrollEvent.x) {
  4799. //default for no container Id (ex. mousewheel means that all containers must set scrollTop/Left)
  4800. var horizs = ['body','bodyheader', 'bodyfooter'];
  4801. this.flagScrollingHorizontally(scrollEvent);
  4802. if (sourceContainerId === 'body') {
  4803. horizs = ['bodyheader', 'bodyfooter'];
  4804. }
  4805. for (var j = 0; j < horizs.length; j++) {
  4806. var idh = horizs[j];
  4807. if (this.horizontalScrollSyncCallBackFns[idh]) {
  4808. this.horizontalScrollSyncCallBackFns[idh](scrollEvent);
  4809. }
  4810. }
  4811. }
  4812. };
  4813. Grid.prototype.registerViewportAdjuster = function registerViewportAdjuster(func) {
  4814. this.viewportAdjusters.push(func);
  4815. };
  4816. Grid.prototype.removeViewportAdjuster = function registerViewportAdjuster(func) {
  4817. var idx = this.viewportAdjusters.indexOf(func);
  4818. if (typeof(idx) !== 'undefined' && idx !== undefined) {
  4819. this.viewportAdjusters.splice(idx, 1);
  4820. }
  4821. };
  4822. Grid.prototype.getViewportAdjustment = function getViewportAdjustment() {
  4823. var self = this;
  4824. var adjustment = { height: 0, width: 0 };
  4825. self.viewportAdjusters.forEach(function (func) {
  4826. adjustment = func.call(this, adjustment);
  4827. });
  4828. return adjustment;
  4829. };
  4830. Grid.prototype.getVisibleRowCount = function getVisibleRowCount() {
  4831. // var count = 0;
  4832. // this.rows.forEach(function (row) {
  4833. // if (row.visible) {
  4834. // count++;
  4835. // }
  4836. // });
  4837. // return this.visibleRowCache.length;
  4838. return this.renderContainers.body.visibleRowCache.length;
  4839. };
  4840. Grid.prototype.getVisibleRows = function getVisibleRows() {
  4841. return this.renderContainers.body.visibleRowCache;
  4842. };
  4843. Grid.prototype.getVisibleColumnCount = function getVisibleColumnCount() {
  4844. // var count = 0;
  4845. // this.rows.forEach(function (row) {
  4846. // if (row.visible) {
  4847. // count++;
  4848. // }
  4849. // });
  4850. // return this.visibleRowCache.length;
  4851. return this.renderContainers.body.visibleColumnCache.length;
  4852. };
  4853. Grid.prototype.searchRows = function searchRows(renderableRows) {
  4854. return rowSearcher.search(this, renderableRows, this.columns);
  4855. };
  4856. Grid.prototype.sortByColumn = function sortByColumn(renderableRows) {
  4857. return rowSorter.sort(this, renderableRows, this.columns);
  4858. };
  4859. /**
  4860. * @ngdoc function
  4861. * @name getCellValue
  4862. * @methodOf ui.grid.class:Grid
  4863. * @description Gets the value of a cell for a particular row and column
  4864. * @param {GridRow} row Row to access
  4865. * @param {GridColumn} col Column to access
  4866. */
  4867. Grid.prototype.getCellValue = function getCellValue(row, col){
  4868. if ( typeof(row.entity[ '$$' + col.uid ]) !== 'undefined' ) {
  4869. return row.entity[ '$$' + col.uid].rendered;
  4870. } else if (this.options.flatEntityAccess && typeof(col.field) !== 'undefined' ){
  4871. return row.entity[col.field];
  4872. } else {
  4873. if (!col.cellValueGetterCache) {
  4874. col.cellValueGetterCache = $parse(row.getEntityQualifiedColField(col));
  4875. }
  4876. return col.cellValueGetterCache(row);
  4877. }
  4878. };
  4879. /**
  4880. * @ngdoc function
  4881. * @name getCellDisplayValue
  4882. * @methodOf ui.grid.class:Grid
  4883. * @description Gets the displayed value of a cell after applying any the `cellFilter`
  4884. * @param {GridRow} row Row to access
  4885. * @param {GridColumn} col Column to access
  4886. */
  4887. Grid.prototype.getCellDisplayValue = function getCellDisplayValue(row, col) {
  4888. if ( !col.cellDisplayGetterCache ) {
  4889. var custom_filter = col.cellFilter ? " | " + col.cellFilter : "";
  4890. if (typeof(row.entity['$$' + col.uid]) !== 'undefined') {
  4891. col.cellDisplayGetterCache = $parse(row.entity['$$' + col.uid].rendered + custom_filter);
  4892. } else if (this.options.flatEntityAccess && typeof(col.field) !== 'undefined') {
  4893. var colField = col.field.replace(/(')|(\\)/g, "\\$&");
  4894. col.cellDisplayGetterCache = $parse('entity[\'' + colField + '\']' + custom_filter);
  4895. } else {
  4896. col.cellDisplayGetterCache = $parse(row.getEntityQualifiedColField(col) + custom_filter);
  4897. }
  4898. }
  4899. var rowWithCol = angular.extend({}, row, {col: col});
  4900. return col.cellDisplayGetterCache(rowWithCol);
  4901. };
  4902. Grid.prototype.getNextColumnSortPriority = function getNextColumnSortPriority() {
  4903. var self = this,
  4904. p = 0;
  4905. self.columns.forEach(function (col) {
  4906. if (col.sort && col.sort.priority !== undefined && col.sort.priority >= p) {
  4907. p = col.sort.priority + 1;
  4908. }
  4909. });
  4910. return p;
  4911. };
  4912. /**
  4913. * @ngdoc function
  4914. * @name resetColumnSorting
  4915. * @methodOf ui.grid.class:Grid
  4916. * @description Return the columns that the grid is currently being sorted by
  4917. * @param {GridColumn} [excludedColumn] Optional GridColumn to exclude from having its sorting reset
  4918. */
  4919. Grid.prototype.resetColumnSorting = function resetColumnSorting(excludeCol) {
  4920. var self = this;
  4921. self.columns.forEach(function (col) {
  4922. if (col !== excludeCol && !col.suppressRemoveSort) {
  4923. col.sort = {};
  4924. }
  4925. });
  4926. };
  4927. /**
  4928. * @ngdoc function
  4929. * @name getColumnSorting
  4930. * @methodOf ui.grid.class:Grid
  4931. * @description Return the columns that the grid is currently being sorted by
  4932. * @returns {Array[GridColumn]} An array of GridColumn objects
  4933. */
  4934. Grid.prototype.getColumnSorting = function getColumnSorting() {
  4935. var self = this;
  4936. var sortedCols = [], myCols;
  4937. // Iterate through all the columns, sorted by priority
  4938. // Make local copy of column list, because sorting is in-place and we do not want to
  4939. // change the original sequence of columns
  4940. myCols = self.columns.slice(0);
  4941. myCols.sort(rowSorter.prioritySort).forEach(function (col) {
  4942. if (col.sort && typeof(col.sort.direction) !== 'undefined' && col.sort.direction && (col.sort.direction === uiGridConstants.ASC || col.sort.direction === uiGridConstants.DESC)) {
  4943. sortedCols.push(col);
  4944. }
  4945. });
  4946. return sortedCols;
  4947. };
  4948. /**
  4949. * @ngdoc function
  4950. * @name sortColumn
  4951. * @methodOf ui.grid.class:Grid
  4952. * @description Set the sorting on a given column, optionally resetting any existing sorting on the Grid.
  4953. * Emits the sortChanged event whenever the sort criteria are changed.
  4954. * @param {GridColumn} column Column to set the sorting on
  4955. * @param {uiGridConstants.ASC|uiGridConstants.DESC} [direction] Direction to sort by, either descending or ascending.
  4956. * If not provided, the column will iterate through the sort directions
  4957. * specified in the {@link ui.grid.class:GridOptions.columnDef#sortDirectionCycle sortDirectionCycle} attribute.
  4958. * @param {boolean} [add] Add this column to the sorting. If not provided or set to `false`, the Grid will reset any existing sorting and sort
  4959. * by this column only
  4960. * @returns {Promise} A resolved promise that supplies the column.
  4961. */
  4962. Grid.prototype.sortColumn = function sortColumn(column, directionOrAdd, add) {
  4963. var self = this,
  4964. direction = null;
  4965. if (typeof(column) === 'undefined' || !column) {
  4966. throw new Error('No column parameter provided');
  4967. }
  4968. // Second argument can either be a direction or whether to add this column to the existing sort.
  4969. // If it's a boolean, it's an add, otherwise, it's a direction
  4970. if (typeof(directionOrAdd) === 'boolean') {
  4971. add = directionOrAdd;
  4972. }
  4973. else {
  4974. direction = directionOrAdd;
  4975. }
  4976. if (!add) {
  4977. self.resetColumnSorting(column);
  4978. column.sort.priority = undefined;
  4979. // Get the actual priority since there may be columns which have suppressRemoveSort set
  4980. column.sort.priority = self.getNextColumnSortPriority();
  4981. }
  4982. else if (column.sort.priority === undefined){
  4983. column.sort.priority = self.getNextColumnSortPriority();
  4984. }
  4985. if (!direction) {
  4986. // Find the current position in the cycle (or -1).
  4987. var i = column.sortDirectionCycle.indexOf(column.sort.direction ? column.sort.direction : null);
  4988. // Proceed to the next position in the cycle (or start at the beginning).
  4989. i = (i+1) % column.sortDirectionCycle.length;
  4990. // If suppressRemoveSort is set, and the next position in the cycle would
  4991. // remove the sort, skip it.
  4992. if (column.colDef && column.suppressRemoveSort && !column.sortDirectionCycle[i]) {
  4993. i = (i+1) % column.sortDirectionCycle.length;
  4994. }
  4995. if (column.sortDirectionCycle[i]) {
  4996. column.sort.direction = column.sortDirectionCycle[i];
  4997. } else {
  4998. removeSortOfColumn(column, self);
  4999. }
  5000. }
  5001. else {
  5002. column.sort.direction = direction;
  5003. }
  5004. self.api.core.raise.sortChanged( self, self.getColumnSorting() );
  5005. return $q.when(column);
  5006. };
  5007. var removeSortOfColumn = function removeSortOfColumn(column, grid) {
  5008. //Decrease priority for every col where priority is higher than the removed sort's priority.
  5009. grid.columns.forEach(function (col) {
  5010. if (col.sort && col.sort.priority !== undefined && col.sort.priority > column.sort.priority) {
  5011. col.sort.priority -= 1;
  5012. }
  5013. });
  5014. //Remove sort
  5015. column.sort = {};
  5016. };
  5017. /**
  5018. * communicate to outside world that we are done with initial rendering
  5019. */
  5020. Grid.prototype.renderingComplete = function(){
  5021. if (angular.isFunction(this.options.onRegisterApi)) {
  5022. this.options.onRegisterApi(this.api);
  5023. }
  5024. this.api.core.raise.renderingComplete( this.api );
  5025. };
  5026. Grid.prototype.createRowHashMap = function createRowHashMap() {
  5027. var self = this;
  5028. var hashMap = new RowHashMap();
  5029. hashMap.grid = self;
  5030. return hashMap;
  5031. };
  5032. /**
  5033. * @ngdoc function
  5034. * @name refresh
  5035. * @methodOf ui.grid.class:Grid
  5036. * @description Refresh the rendered grid on screen.
  5037. * @param {boolean} [rowsAltered] Optional flag for refreshing when the number of rows has changed.
  5038. */
  5039. Grid.prototype.refresh = function refresh(rowsAltered) {
  5040. var self = this;
  5041. var p1 = self.processRowsProcessors(self.rows).then(function (renderableRows) {
  5042. self.setVisibleRows(renderableRows);
  5043. }).catch(angular.noop);
  5044. var p2 = self.processColumnsProcessors(self.columns).then(function (renderableColumns) {
  5045. self.setVisibleColumns(renderableColumns);
  5046. }).catch(angular.noop);
  5047. return $q.all([p1, p2]).then(function () {
  5048. self.refreshCanvas(true);
  5049. self.redrawInPlace(rowsAltered);
  5050. }).catch(angular.noop);
  5051. };
  5052. /**
  5053. * @ngdoc function
  5054. * @name refreshRows
  5055. * @methodOf ui.grid.class:Grid
  5056. * @description Refresh the rendered rows on screen? Note: not functional at present
  5057. * @returns {promise} promise that is resolved when render completes?
  5058. *
  5059. */
  5060. Grid.prototype.refreshRows = function refreshRows() {
  5061. var self = this;
  5062. return self.processRowsProcessors(self.rows)
  5063. .then(function (renderableRows) {
  5064. self.setVisibleRows(renderableRows);
  5065. self.redrawInPlace();
  5066. self.refreshCanvas( true );
  5067. }).catch(angular.noop);
  5068. };
  5069. /**
  5070. * @ngdoc function
  5071. * @name refreshCanvas
  5072. * @methodOf ui.grid.class:Grid
  5073. * @description Builds all styles and recalculates much of the grid sizing
  5074. * @param {object} buildStyles optional parameter. Use TBD
  5075. * @returns {promise} promise that is resolved when the canvas
  5076. * has been refreshed
  5077. *
  5078. */
  5079. Grid.prototype.refreshCanvas = function(buildStyles) {
  5080. var self = this;
  5081. // gridUtil.logDebug('refreshCanvas');
  5082. var p = $q.defer();
  5083. // Get all the header heights
  5084. var containerHeadersToRecalc = [];
  5085. for (var containerId in self.renderContainers) {
  5086. if (self.renderContainers.hasOwnProperty(containerId)) {
  5087. var container = self.renderContainers[containerId];
  5088. // Skip containers that have no canvasWidth set yet
  5089. if (container.canvasWidth === null || isNaN(container.canvasWidth)) {
  5090. continue;
  5091. }
  5092. if (container.header || container.headerCanvas) {
  5093. container.explicitHeaderHeight = container.explicitHeaderHeight || null;
  5094. container.explicitHeaderCanvasHeight = container.explicitHeaderCanvasHeight || null;
  5095. containerHeadersToRecalc.push(container);
  5096. }
  5097. }
  5098. }
  5099. // Build the styles without the explicit header heights
  5100. if (buildStyles) {
  5101. self.buildStyles();
  5102. }
  5103. /*
  5104. *
  5105. * Here we loop through the headers, measuring each element as well as any header "canvas" it has within it.
  5106. *
  5107. * If any header is less than the largest header height, it will be resized to that so that we don't have headers
  5108. * with different heights, which looks like a rendering problem
  5109. *
  5110. * We'll do the same thing with the header canvases, and give the header CELLS an explicit height if their canvas
  5111. * is smaller than the largest canvas height. That was header cells without extra controls like filtering don't
  5112. * appear shorter than other cells.
  5113. *
  5114. */
  5115. if (containerHeadersToRecalc.length > 0) {
  5116. // Putting in a timeout as it's not calculating after the grid element is rendered and filled out
  5117. $timeout(function() {
  5118. // var oldHeaderHeight = self.grid.headerHeight;
  5119. // self.grid.headerHeight = gridUtil.outerElementHeight(self.header);
  5120. var rebuildStyles = false;
  5121. // Get all the header heights
  5122. var maxHeaderHeight = 0;
  5123. var maxHeaderCanvasHeight = 0;
  5124. var i, container;
  5125. var getHeight = function(oldVal, newVal){
  5126. if ( oldVal !== newVal){
  5127. rebuildStyles = true;
  5128. }
  5129. return newVal;
  5130. };
  5131. for (i = 0; i < containerHeadersToRecalc.length; i++) {
  5132. container = containerHeadersToRecalc[i];
  5133. // Skip containers that have no canvasWidth set yet
  5134. if (container.canvasWidth === null || isNaN(container.canvasWidth)) {
  5135. continue;
  5136. }
  5137. if (container.header) {
  5138. var headerHeight = container.headerHeight = getHeight(container.headerHeight, gridUtil.outerElementHeight(container.header));
  5139. // Get the "inner" header height, that is the height minus the top and bottom borders, if present. We'll use it to make sure all the headers have a consistent height
  5140. var topBorder = gridUtil.getBorderSize(container.header, 'top');
  5141. var bottomBorder = gridUtil.getBorderSize(container.header, 'bottom');
  5142. var innerHeaderHeight = parseInt(headerHeight - topBorder - bottomBorder, 10);
  5143. innerHeaderHeight = innerHeaderHeight < 0 ? 0 : innerHeaderHeight;
  5144. container.innerHeaderHeight = innerHeaderHeight;
  5145. // If the header doesn't have an explicit height set, save the largest header height for use later
  5146. // Explicit header heights are based off of the max we are calculating here. We never want to base the max on something we're setting explicitly
  5147. if (!container.explicitHeaderHeight && innerHeaderHeight > maxHeaderHeight) {
  5148. maxHeaderHeight = innerHeaderHeight;
  5149. }
  5150. }
  5151. if (container.headerCanvas) {
  5152. var headerCanvasHeight = container.headerCanvasHeight = getHeight(container.headerCanvasHeight, parseInt(gridUtil.outerElementHeight(container.headerCanvas), 10));
  5153. // If the header doesn't have an explicit canvas height, save the largest header canvas height for use later
  5154. // Explicit header heights are based off of the max we are calculating here. We never want to base the max on something we're setting explicitly
  5155. if (!container.explicitHeaderCanvasHeight && headerCanvasHeight > maxHeaderCanvasHeight) {
  5156. maxHeaderCanvasHeight = headerCanvasHeight;
  5157. }
  5158. }
  5159. }
  5160. // Go through all the headers
  5161. for (i = 0; i < containerHeadersToRecalc.length; i++) {
  5162. container = containerHeadersToRecalc[i];
  5163. /* If:
  5164. 1. We have a max header height
  5165. 2. This container has a header height defined
  5166. 3. And either this container has an explicit header height set, OR its header height is less than the max
  5167. then:
  5168. Give this container's header an explicit height so it will line up with the tallest header
  5169. */
  5170. if (
  5171. maxHeaderHeight > 0 && typeof(container.headerHeight) !== 'undefined' && container.headerHeight !== null &&
  5172. (container.explicitHeaderHeight || container.headerHeight < maxHeaderHeight)
  5173. ) {
  5174. container.explicitHeaderHeight = getHeight(container.explicitHeaderHeight, maxHeaderHeight);
  5175. }
  5176. // Do the same as above except for the header canvas
  5177. if (
  5178. maxHeaderCanvasHeight > 0 && typeof(container.headerCanvasHeight) !== 'undefined' && container.headerCanvasHeight !== null &&
  5179. (container.explicitHeaderCanvasHeight || container.headerCanvasHeight < maxHeaderCanvasHeight)
  5180. ) {
  5181. container.explicitHeaderCanvasHeight = getHeight(container.explicitHeaderCanvasHeight, maxHeaderCanvasHeight);
  5182. }
  5183. }
  5184. // Rebuild styles if the header height has changed
  5185. // The header height is used in body/viewport calculations and those are then used in other styles so we need it to be available
  5186. if (buildStyles && rebuildStyles) {
  5187. self.buildStyles();
  5188. }
  5189. p.resolve();
  5190. });
  5191. }
  5192. else {
  5193. // Timeout still needs to be here to trigger digest after styles have been rebuilt
  5194. $timeout(function() {
  5195. p.resolve();
  5196. });
  5197. }
  5198. return p.promise;
  5199. };
  5200. /**
  5201. * @ngdoc function
  5202. * @name redrawInPlace
  5203. * @methodOf ui.grid.class:Grid
  5204. * @description Redraw the rows and columns based on our current scroll position
  5205. * @param {boolean} [rowsAdded] Optional to indicate rows are added and the scroll percentage must be recalculated
  5206. *
  5207. */
  5208. Grid.prototype.redrawInPlace = function redrawInPlace(rowsAdded) {
  5209. // gridUtil.logDebug('redrawInPlace');
  5210. var self = this;
  5211. for (var i in self.renderContainers) {
  5212. var container = self.renderContainers[i];
  5213. // gridUtil.logDebug('redrawing container', i);
  5214. if (rowsAdded) {
  5215. container.adjustRows(container.prevScrollTop, null);
  5216. container.adjustColumns(container.prevScrollLeft, null);
  5217. }
  5218. else {
  5219. container.adjustRows(null, container.prevScrolltopPercentage);
  5220. container.adjustColumns(null, container.prevScrollleftPercentage);
  5221. }
  5222. }
  5223. };
  5224. /**
  5225. * @ngdoc function
  5226. * @name hasLeftContainerColumns
  5227. * @methodOf ui.grid.class:Grid
  5228. * @description returns true if leftContainer has columns
  5229. */
  5230. Grid.prototype.hasLeftContainerColumns = function () {
  5231. return this.hasLeftContainer() && this.renderContainers.left.renderedColumns.length > 0;
  5232. };
  5233. /**
  5234. * @ngdoc function
  5235. * @name hasRightContainerColumns
  5236. * @methodOf ui.grid.class:Grid
  5237. * @description returns true if rightContainer has columns
  5238. */
  5239. Grid.prototype.hasRightContainerColumns = function () {
  5240. return this.hasRightContainer() && this.renderContainers.right.renderedColumns.length > 0;
  5241. };
  5242. // Turn the scroll position into a percentage and make it an argument for a scroll event
  5243. function getScrollPercentage(scrollPixels, scrollLength) {
  5244. var percentage = scrollPixels / scrollLength;
  5245. // if the percentage is greater than 1, set it to 1
  5246. return percentage <= 1 ? percentage : 1;
  5247. }
  5248. // Only returns the scroll Y position if the percentage is different from the previous
  5249. function getScrollY(scrollPixels, scrollLength, prevScrolltopPercentage) {
  5250. var scrollPercentage = getScrollPercentage(scrollPixels, scrollLength);
  5251. if (scrollPercentage !== prevScrolltopPercentage) {
  5252. return { percentage: getScrollPercentage(scrollPixels, scrollLength) };
  5253. }
  5254. return undefined;
  5255. }
  5256. // Only returns the scroll X position if the percentage is different from the previous
  5257. function getScrollX(horizScrollPixels, horizScrollLength, prevScrollleftPercentage) {
  5258. var horizPercentage = horizScrollPixels / horizScrollLength;
  5259. horizPercentage = (horizPercentage > 1) ? 1 : horizPercentage;
  5260. if (horizPercentage !== prevScrollleftPercentage) {
  5261. return { percentage: horizPercentage };
  5262. }
  5263. return undefined;
  5264. }
  5265. /**
  5266. * @ngdoc method
  5267. * @methodOf ui.grid.class:Grid
  5268. * @name scrollToIfNecessary
  5269. * @description Scrolls the grid to make a certain row and column combo visible,
  5270. * in the case that it is not completely visible on the screen already.
  5271. * @param {GridRow} gridRow row to make visible
  5272. * @param {GridColumn} gridCol column to make visible
  5273. * @returns {promise} a promise that is resolved when scrolling is complete
  5274. */
  5275. Grid.prototype.scrollToIfNecessary = function (gridRow, gridCol) {
  5276. var self = this;
  5277. var scrollEvent = new ScrollEvent(self, 'uiGrid.scrollToIfNecessary');
  5278. // Alias the visible row and column caches
  5279. var visRowCache = self.renderContainers.body.visibleRowCache;
  5280. var visColCache = self.renderContainers.body.visibleColumnCache;
  5281. /*-- Get the top, left, right, and bottom "scrolled" edges of the grid --*/
  5282. // The top boundary is the current Y scroll position PLUS the header height, because the header can obscure rows when the grid is scrolled downwards
  5283. var topBound = self.renderContainers.body.prevScrollTop + self.headerHeight;
  5284. // Don't the let top boundary be less than 0
  5285. topBound = (topBound < 0) ? 0 : topBound;
  5286. // The left boundary is the current X scroll position
  5287. var leftBound = self.renderContainers.body.prevScrollLeft;
  5288. // The bottom boundary is the current Y scroll position, plus the height of the grid, but minus the header height.
  5289. // Basically this is the viewport height added on to the scroll position
  5290. var bottomBound = self.renderContainers.body.prevScrollTop + self.gridHeight - self.renderContainers.body.headerHeight - self.footerHeight - self.scrollbarWidth;
  5291. // If there's a horizontal scrollbar, remove its height from the bottom boundary, otherwise we'll be letting it obscure rows
  5292. //if (self.horizontalScrollbarHeight) {
  5293. // bottomBound = bottomBound - self.horizontalScrollbarHeight;
  5294. //}
  5295. // The right position is the current X scroll position minus the grid width
  5296. var rightBound = self.renderContainers.body.prevScrollLeft + Math.ceil(self.renderContainers.body.getViewportWidth());
  5297. // If there's a vertical scrollbar, subtract it from the right boundary or we'll allow it to obscure cells
  5298. //if (self.verticalScrollbarWidth) {
  5299. // rightBound = rightBound - self.verticalScrollbarWidth;
  5300. //}
  5301. // We were given a row to scroll to
  5302. if (gridRow !== null) {
  5303. // This is the index of the row we want to scroll to, within the list of rows that can be visible
  5304. var seekRowIndex = visRowCache.indexOf(gridRow);
  5305. // Total vertical scroll length of the grid
  5306. var scrollLength = (self.renderContainers.body.getCanvasHeight() - self.renderContainers.body.getViewportHeight());
  5307. // Add the height of the native horizontal scrollbar to the scroll length, if it's there. Otherwise it will mask over the final row
  5308. //if (self.horizontalScrollbarHeight && self.horizontalScrollbarHeight > 0) {
  5309. // scrollLength = scrollLength + self.horizontalScrollbarHeight;
  5310. //}
  5311. // This is the minimum amount of pixels we need to scroll vertical in order to see this row.
  5312. var pixelsToSeeRow = (seekRowIndex * self.options.rowHeight + self.headerHeight);
  5313. // Don't let the pixels required to see the row be less than zero
  5314. pixelsToSeeRow = (pixelsToSeeRow < 0) ? 0 : pixelsToSeeRow;
  5315. var scrollPixels;
  5316. // If the scroll position we need to see the row is LESS than the top boundary, i.e. obscured above the top of the self...
  5317. if (pixelsToSeeRow < topBound) {
  5318. // Get the different between the top boundary and the required scroll position and subtract it from the current scroll position\
  5319. // to get the full position we need
  5320. scrollPixels = self.renderContainers.body.prevScrollTop - (topBound - pixelsToSeeRow);
  5321. scrollEvent.y = getScrollY(scrollPixels, scrollLength, self.renderContainers.body.prevScrolltopPercentage);
  5322. }
  5323. // Otherwise if the scroll position we need to see the row is MORE than the bottom boundary, i.e. obscured below the bottom of the self...
  5324. else if (pixelsToSeeRow > bottomBound) {
  5325. // Get the different between the bottom boundary and the required scroll position and add it to the current scroll position
  5326. // to get the full position we need
  5327. scrollPixels = pixelsToSeeRow - bottomBound + self.renderContainers.body.prevScrollTop;
  5328. scrollEvent.y = getScrollY(scrollPixels, scrollLength,self.renderContainers.body.prevScrolltopPercentage);
  5329. }
  5330. }
  5331. // We were given a column to scroll to
  5332. if (gridCol !== null) {
  5333. // This is the index of the column we want to scroll to, within the list of columns that can be visible
  5334. var seekColumnIndex = visColCache.indexOf(gridCol);
  5335. // Total horizontal scroll length of the grid
  5336. var horizScrollLength = (self.renderContainers.body.getCanvasWidth() - self.renderContainers.body.getViewportWidth());
  5337. // This is the minimum amount of pixels we need to scroll horizontal in order to see this column
  5338. var columnLeftEdge = 0;
  5339. for (var i = 0; i < seekColumnIndex; i++) {
  5340. var col = visColCache[i];
  5341. columnLeftEdge += col.drawnWidth;
  5342. }
  5343. columnLeftEdge = (columnLeftEdge < 0) ? 0 : columnLeftEdge;
  5344. var columnRightEdge = columnLeftEdge + gridCol.drawnWidth;
  5345. // Don't let the pixels required to see the column be less than zero
  5346. columnRightEdge = (columnRightEdge < 0) ? 0 : columnRightEdge;
  5347. var horizScrollPixels;
  5348. // If the scroll position we need to see the column is LESS than the left boundary, i.e. obscured before the left of the self...
  5349. if (columnLeftEdge < leftBound) {
  5350. // Get the different between the left boundary and the required scroll position and subtract it from the current scroll position\
  5351. // to get the full position we need
  5352. horizScrollPixels = self.renderContainers.body.prevScrollLeft - (leftBound - columnLeftEdge);
  5353. // Turn the scroll position into a percentage and make it an argument for a scroll event
  5354. scrollEvent.x = getScrollX(horizScrollPixels, horizScrollLength, self.renderContainers.body.prevScrollleftPercentage);
  5355. }
  5356. // Otherwise if the scroll position we need to see the column is MORE than the right boundary, i.e. obscured after the right of the self...
  5357. else if (columnRightEdge > rightBound) {
  5358. // Get the different between the right boundary and the required scroll position and add it to the current scroll position
  5359. // to get the full position we need
  5360. horizScrollPixels = columnRightEdge - rightBound + self.renderContainers.body.prevScrollLeft;
  5361. // Turn the scroll position into a percentage and make it an argument for a scroll event
  5362. scrollEvent.x = getScrollX(horizScrollPixels, horizScrollLength, self.renderContainers.body.prevScrollleftPercentage);
  5363. }
  5364. }
  5365. var deferred = $q.defer();
  5366. // If we need to scroll on either the x or y axes, fire a scroll event
  5367. if (scrollEvent.y || scrollEvent.x) {
  5368. scrollEvent.withDelay = false;
  5369. self.scrollContainers('',scrollEvent);
  5370. var dereg = self.api.core.on.scrollEnd(null,function() {
  5371. deferred.resolve(scrollEvent);
  5372. dereg();
  5373. });
  5374. }
  5375. else {
  5376. deferred.resolve();
  5377. }
  5378. return deferred.promise;
  5379. };
  5380. /**
  5381. * @ngdoc method
  5382. * @methodOf ui.grid.class:Grid
  5383. * @name scrollTo
  5384. * @description Scroll the grid such that the specified
  5385. * row and column is in view
  5386. * @param {object} rowEntity gridOptions.data[] array instance to make visible
  5387. * @param {object} colDef to make visible
  5388. * @returns {promise} a promise that is resolved after any scrolling is finished
  5389. */
  5390. Grid.prototype.scrollTo = function (rowEntity, colDef) {
  5391. var gridRow = null, gridCol = null;
  5392. if (rowEntity !== null && typeof(rowEntity) !== 'undefined' ) {
  5393. gridRow = this.getRow(rowEntity);
  5394. }
  5395. if (colDef !== null && typeof(colDef) !== 'undefined' ) {
  5396. gridCol = this.getColumn(colDef.name ? colDef.name : colDef.field);
  5397. }
  5398. return this.scrollToIfNecessary(gridRow, gridCol);
  5399. };
  5400. /**
  5401. * @ngdoc function
  5402. * @name clearAllFilters
  5403. * @methodOf ui.grid.class:Grid
  5404. * @description Clears all filters and optionally refreshes the visible rows.
  5405. * @param {object} refreshRows Defaults to true.
  5406. * @param {object} clearConditions Defaults to false.
  5407. * @param {object} clearFlags Defaults to false.
  5408. * @returns {promise} If `refreshRows` is true, returns a promise of the rows refreshing.
  5409. */
  5410. Grid.prototype.clearAllFilters = function clearAllFilters(refreshRows, clearConditions, clearFlags) {
  5411. // Default `refreshRows` to true because it will be the most commonly desired behaviour.
  5412. if (refreshRows === undefined) {
  5413. refreshRows = true;
  5414. }
  5415. if (clearConditions === undefined) {
  5416. clearConditions = false;
  5417. }
  5418. if (clearFlags === undefined) {
  5419. clearFlags = false;
  5420. }
  5421. this.columns.forEach(function(column) {
  5422. column.filters.forEach(function(filter) {
  5423. filter.term = undefined;
  5424. if (clearConditions) {
  5425. filter.condition = undefined;
  5426. }
  5427. if (clearFlags) {
  5428. filter.flags = undefined;
  5429. }
  5430. });
  5431. });
  5432. if (refreshRows) {
  5433. return this.refreshRows();
  5434. }
  5435. };
  5436. // Blatantly stolen from Angular as it isn't exposed (yet? 2.0?)
  5437. function RowHashMap() {}
  5438. RowHashMap.prototype = {
  5439. /**
  5440. * Store key value pair
  5441. * @param key key to store can be any type
  5442. * @param value value to store can be any type
  5443. */
  5444. put: function(key, value) {
  5445. this[this.grid.options.rowIdentity(key)] = value;
  5446. },
  5447. /**
  5448. * @param key
  5449. * @returns {Object} the value for the key
  5450. */
  5451. get: function(key) {
  5452. return this[this.grid.options.rowIdentity(key)];
  5453. },
  5454. /**
  5455. * Remove the key/value pair
  5456. * @param key
  5457. */
  5458. remove: function(key) {
  5459. var value = this[key = this.grid.options.rowIdentity(key)];
  5460. delete this[key];
  5461. return value;
  5462. }
  5463. };
  5464. return Grid;
  5465. }]);
  5466. })();
  5467. (function () {
  5468. angular.module('ui.grid')
  5469. .factory('GridApi', ['$q', '$rootScope', 'gridUtil', 'uiGridConstants', 'GridRow', 'uiGridGridMenuService',
  5470. function ($q, $rootScope, gridUtil, uiGridConstants, GridRow, uiGridGridMenuService) {
  5471. /**
  5472. * @ngdoc function
  5473. * @name ui.grid.class:GridApi
  5474. * @description GridApi provides the ability to register public methods events inside the grid and allow
  5475. * for other components to use the api via featureName.raise.methodName and featureName.on.eventName(function(args){}.
  5476. * <br/>
  5477. * To listen to events, you must add a callback to gridOptions.onRegisterApi
  5478. * <pre>
  5479. * $scope.gridOptions.onRegisterApi = function(gridApi){
  5480. * gridApi.cellNav.on.navigate($scope,function(newRowCol, oldRowCol){
  5481. * $log.log('navigation event');
  5482. * });
  5483. * };
  5484. * </pre>
  5485. * @param {object} grid grid that owns api
  5486. */
  5487. var GridApi = function GridApi(grid) {
  5488. this.grid = grid;
  5489. this.listeners = [];
  5490. /**
  5491. * @ngdoc function
  5492. * @name renderingComplete
  5493. * @methodOf ui.grid.core.api:PublicApi
  5494. * @description Rendering is complete, called at the same
  5495. * time as `onRegisterApi`, but provides a way to obtain
  5496. * that same event within features without stopping end
  5497. * users from getting at the onRegisterApi method.
  5498. *
  5499. * Included in gridApi so that it's always there - otherwise
  5500. * there is still a timing problem with when a feature can
  5501. * call this.
  5502. *
  5503. * @param {GridApi} gridApi the grid api, as normally
  5504. * returned in the onRegisterApi method
  5505. *
  5506. * @example
  5507. * <pre>
  5508. * gridApi.core.on.renderingComplete( grid );
  5509. * </pre>
  5510. */
  5511. this.registerEvent( 'core', 'renderingComplete' );
  5512. /**
  5513. * @ngdoc event
  5514. * @name filterChanged
  5515. * @eventOf ui.grid.core.api:PublicApi
  5516. * @description is raised after the filter is changed. The nature
  5517. * of the watch expression doesn't allow notification of what changed,
  5518. * so the receiver of this event will need to re-extract the filter
  5519. * conditions from the columns.
  5520. *
  5521. */
  5522. this.registerEvent( 'core', 'filterChanged' );
  5523. /**
  5524. * @ngdoc function
  5525. * @name setRowInvisible
  5526. * @methodOf ui.grid.core.api:PublicApi
  5527. * @description Sets an override on the row to make it always invisible,
  5528. * which will override any filtering or other visibility calculations.
  5529. * If the row is currently visible then sets it to invisible and calls
  5530. * both grid refresh and emits the rowsVisibleChanged event
  5531. * @param {GridRow} row the row we want to make invisible
  5532. */
  5533. this.registerMethod( 'core', 'setRowInvisible', GridRow.prototype.setRowInvisible );
  5534. /**
  5535. * @ngdoc function
  5536. * @name clearRowInvisible
  5537. * @methodOf ui.grid.core.api:PublicApi
  5538. * @description Clears any override on visibility for the row so that it returns to
  5539. * using normal filtering and other visibility calculations.
  5540. * If the row is currently invisible then sets it to visible and calls
  5541. * both grid refresh and emits the rowsVisibleChanged event
  5542. * TODO: if a filter is active then we can't just set it to visible?
  5543. * @param {GridRow} row the row we want to make visible
  5544. */
  5545. this.registerMethod( 'core', 'clearRowInvisible', GridRow.prototype.clearRowInvisible );
  5546. /**
  5547. * @ngdoc function
  5548. * @name getVisibleRows
  5549. * @methodOf ui.grid.core.api:PublicApi
  5550. * @description Returns all visible rows
  5551. * @param {Grid} grid the grid you want to get visible rows from
  5552. * @returns {array} an array of gridRow
  5553. */
  5554. this.registerMethod( 'core', 'getVisibleRows', this.grid.getVisibleRows );
  5555. /**
  5556. * @ngdoc event
  5557. * @name rowsVisibleChanged
  5558. * @eventOf ui.grid.core.api:PublicApi
  5559. * @description is raised after the rows that are visible
  5560. * change. The filtering is zero-based, so it isn't possible
  5561. * to say which rows changed (unlike in the selection feature).
  5562. * We can plausibly know which row was changed when setRowInvisible
  5563. * is called, but in that situation the user already knows which row
  5564. * they changed. When a filter runs we don't know what changed,
  5565. * and that is the one that would have been useful.
  5566. *
  5567. */
  5568. this.registerEvent( 'core', 'rowsVisibleChanged' );
  5569. /**
  5570. * @ngdoc event
  5571. * @name rowsRendered
  5572. * @eventOf ui.grid.core.api:PublicApi
  5573. * @description is raised after the cache of visible rows is changed.
  5574. */
  5575. this.registerEvent( 'core', 'rowsRendered' );
  5576. /**
  5577. * @ngdoc event
  5578. * @name scrollBegin
  5579. * @eventOf ui.grid.core.api:PublicApi
  5580. * @description is raised when scroll begins. Is throttled, so won't be raised too frequently
  5581. */
  5582. this.registerEvent( 'core', 'scrollBegin' );
  5583. /**
  5584. * @ngdoc event
  5585. * @name scrollEnd
  5586. * @eventOf ui.grid.core.api:PublicApi
  5587. * @description is raised when scroll has finished. Is throttled, so won't be raised too frequently
  5588. */
  5589. this.registerEvent( 'core', 'scrollEnd' );
  5590. /**
  5591. * @ngdoc event
  5592. * @name canvasHeightChanged
  5593. * @eventOf ui.grid.core.api:PublicApi
  5594. * @description is raised when the canvas height has changed
  5595. * <br/>
  5596. * arguments: oldHeight, newHeight
  5597. */
  5598. this.registerEvent( 'core', 'canvasHeightChanged');
  5599. /**
  5600. * @ngdoc event
  5601. * @name gridDimensionChanged
  5602. * @eventOf ui.grid.core.api:PublicApi
  5603. * @description is raised when the grid dimensions have changed (when autoResize is on)
  5604. * <br/>
  5605. * arguments: oldGridHeight, oldGridWidth, newGridHeight, newGridWidth
  5606. */
  5607. this.registerEvent( 'core', 'gridDimensionChanged');
  5608. };
  5609. /**
  5610. * @ngdoc function
  5611. * @name ui.grid.class:suppressEvents
  5612. * @methodOf ui.grid.class:GridApi
  5613. * @description Used to execute a function while disabling the specified event listeners.
  5614. * Disables the listenerFunctions, executes the callbackFn, and then enables
  5615. * the listenerFunctions again
  5616. * @param {object} listenerFuncs listenerFunc or array of listenerFuncs to suppress. These must be the same
  5617. * functions that were used in the .on.eventName method
  5618. * @param {object} callBackFn function to execute
  5619. * @example
  5620. * <pre>
  5621. * var navigate = function (newRowCol, oldRowCol){
  5622. * //do something on navigate
  5623. * }
  5624. *
  5625. * gridApi.cellNav.on.navigate(scope,navigate);
  5626. *
  5627. *
  5628. * //call the scrollTo event and suppress our navigate listener
  5629. * //scrollTo will still raise the event for other listeners
  5630. * gridApi.suppressEvents(navigate, function(){
  5631. * gridApi.cellNav.scrollTo(aRow, aCol);
  5632. * });
  5633. *
  5634. * </pre>
  5635. */
  5636. GridApi.prototype.suppressEvents = function (listenerFuncs, callBackFn) {
  5637. var self = this;
  5638. var listeners = angular.isArray(listenerFuncs) ? listenerFuncs : [listenerFuncs];
  5639. //find all registered listeners
  5640. var foundListeners = self.listeners.filter(function(listener) {
  5641. return listeners.some(function(l) {
  5642. return listener.handler === l;
  5643. });
  5644. });
  5645. //deregister all the listeners
  5646. foundListeners.forEach(function(l){
  5647. l.dereg();
  5648. });
  5649. callBackFn();
  5650. //reregister all the listeners
  5651. foundListeners.forEach(function(l){
  5652. l.dereg = registerEventWithAngular(l.eventId, l.handler, self.grid, l._this);
  5653. });
  5654. };
  5655. /**
  5656. * @ngdoc function
  5657. * @name registerEvent
  5658. * @methodOf ui.grid.class:GridApi
  5659. * @description Registers a new event for the given feature. The event will get a
  5660. * .raise and .on prepended to it
  5661. * <br>
  5662. * .raise.eventName() - takes no arguments
  5663. * <br/>
  5664. * <br/>
  5665. * .on.eventName(scope, callBackFn, _this)
  5666. * <br/>
  5667. * scope - a scope reference to add a deregister call to the scopes .$on('destroy'). Scope is optional and can be a null value,
  5668. * but in this case you must deregister it yourself via the returned deregister function
  5669. * <br/>
  5670. * callBackFn - The function to call
  5671. * <br/>
  5672. * _this - optional this context variable for callbackFn. If omitted, grid.api will be used for the context
  5673. * <br/>
  5674. * .on.eventName returns a dereg funtion that will remove the listener. It's not necessary to use it as the listener
  5675. * will be removed when the scope is destroyed.
  5676. * @param {string} featureName name of the feature that raises the event
  5677. * @param {string} eventName name of the event
  5678. */
  5679. GridApi.prototype.registerEvent = function (featureName, eventName) {
  5680. var self = this;
  5681. if (!self[featureName]) {
  5682. self[featureName] = {};
  5683. }
  5684. var feature = self[featureName];
  5685. if (!feature.on) {
  5686. feature.on = {};
  5687. feature.raise = {};
  5688. }
  5689. var eventId = self.grid.id + featureName + eventName;
  5690. // gridUtil.logDebug('Creating raise event method ' + featureName + '.raise.' + eventName);
  5691. feature.raise[eventName] = function () {
  5692. $rootScope.$emit.apply($rootScope, [eventId].concat(Array.prototype.slice.call(arguments)));
  5693. };
  5694. // gridUtil.logDebug('Creating on event method ' + featureName + '.on.' + eventName);
  5695. feature.on[eventName] = function (scope, handler, _this) {
  5696. if ( scope !== null && typeof(scope.$on) === 'undefined' ){
  5697. gridUtil.logError('asked to listen on ' + featureName + '.on.' + eventName + ' but scope wasn\'t passed in the input parameters. It is legitimate to pass null, but you\'ve passed something else, so you probably forgot to provide scope rather than did it deliberately, not registering');
  5698. return;
  5699. }
  5700. var deregAngularOn = registerEventWithAngular(eventId, handler, self.grid, _this);
  5701. //track our listener so we can turn off and on
  5702. var listener = {handler: handler, dereg: deregAngularOn, eventId: eventId, scope: scope, _this:_this};
  5703. self.listeners.push(listener);
  5704. var removeListener = function(){
  5705. listener.dereg();
  5706. var index = self.listeners.indexOf(listener);
  5707. self.listeners.splice(index,1);
  5708. };
  5709. //destroy tracking when scope is destroyed
  5710. if (scope) {
  5711. scope.$on('$destroy', function() {
  5712. removeListener();
  5713. });
  5714. }
  5715. return removeListener;
  5716. };
  5717. };
  5718. function registerEventWithAngular(eventId, handler, grid, _this) {
  5719. return $rootScope.$on(eventId, function (event) {
  5720. var args = Array.prototype.slice.call(arguments);
  5721. args.splice(0, 1); //remove evt argument
  5722. handler.apply(_this ? _this : grid.api, args);
  5723. });
  5724. }
  5725. /**
  5726. * @ngdoc function
  5727. * @name registerEventsFromObject
  5728. * @methodOf ui.grid.class:GridApi
  5729. * @description Registers features and events from a simple objectMap.
  5730. * eventObjectMap must be in this format (multiple features allowed)
  5731. * <pre>
  5732. * {featureName:
  5733. * {
  5734. * eventNameOne:function(args){},
  5735. * eventNameTwo:function(args){}
  5736. * }
  5737. * }
  5738. * </pre>
  5739. * @param {object} eventObjectMap map of feature/event names
  5740. */
  5741. GridApi.prototype.registerEventsFromObject = function (eventObjectMap) {
  5742. var self = this;
  5743. var features = [];
  5744. angular.forEach(eventObjectMap, function (featProp, featPropName) {
  5745. var feature = {name: featPropName, events: []};
  5746. angular.forEach(featProp, function (prop, propName) {
  5747. feature.events.push(propName);
  5748. });
  5749. features.push(feature);
  5750. });
  5751. features.forEach(function (feature) {
  5752. feature.events.forEach(function (event) {
  5753. self.registerEvent(feature.name, event);
  5754. });
  5755. });
  5756. };
  5757. /**
  5758. * @ngdoc function
  5759. * @name registerMethod
  5760. * @methodOf ui.grid.class:GridApi
  5761. * @description Registers a new event for the given feature
  5762. * @param {string} featureName name of the feature
  5763. * @param {string} methodName name of the method
  5764. * @param {object} callBackFn function to execute
  5765. * @param {object} _this binds callBackFn 'this' to _this. Defaults to gridApi.grid
  5766. */
  5767. GridApi.prototype.registerMethod = function (featureName, methodName, callBackFn, _this) {
  5768. if (!this[featureName]) {
  5769. this[featureName] = {};
  5770. }
  5771. var feature = this[featureName];
  5772. feature[methodName] = gridUtil.createBoundedWrapper(_this || this.grid, callBackFn);
  5773. };
  5774. /**
  5775. * @ngdoc function
  5776. * @name registerMethodsFromObject
  5777. * @methodOf ui.grid.class:GridApi
  5778. * @description Registers features and methods from a simple objectMap.
  5779. * eventObjectMap must be in this format (multiple features allowed)
  5780. * <br>
  5781. * {featureName:
  5782. * {
  5783. * methodNameOne:function(args){},
  5784. * methodNameTwo:function(args){}
  5785. * }
  5786. * @param {object} eventObjectMap map of feature/event names
  5787. * @param {object} _this binds this to _this for all functions. Defaults to gridApi.grid
  5788. */
  5789. GridApi.prototype.registerMethodsFromObject = function (methodMap, _this) {
  5790. var self = this;
  5791. var features = [];
  5792. angular.forEach(methodMap, function (featProp, featPropName) {
  5793. var feature = {name: featPropName, methods: []};
  5794. angular.forEach(featProp, function (prop, propName) {
  5795. feature.methods.push({name: propName, fn: prop});
  5796. });
  5797. features.push(feature);
  5798. });
  5799. features.forEach(function (feature) {
  5800. feature.methods.forEach(function (method) {
  5801. self.registerMethod(feature.name, method.name, method.fn, _this);
  5802. });
  5803. });
  5804. };
  5805. return GridApi;
  5806. }]);
  5807. })();
  5808. (function(){
  5809. angular.module('ui.grid')
  5810. .factory('GridColumn', ['gridUtil', 'uiGridConstants', 'i18nService', function(gridUtil, uiGridConstants, i18nService) {
  5811. /**
  5812. * ******************************************************************************************
  5813. * PaulL1: Ugly hack here in documentation. These properties are clearly properties of GridColumn,
  5814. * and need to be noted as such for those extending and building ui-grid itself.
  5815. * However, from an end-developer perspective, they interact with all these through columnDefs,
  5816. * and they really need to be documented there. I feel like they're relatively static, and
  5817. * I can't find an elegant way for ngDoc to reference to both....so I've duplicated each
  5818. * comment block. Ugh.
  5819. *
  5820. */
  5821. /**
  5822. * @ngdoc property
  5823. * @name name
  5824. * @propertyOf ui.grid.class:GridColumn
  5825. * @description (mandatory) Each column should have a name, although for backward
  5826. * compatibility with 2.x name can be omitted if field is present.
  5827. *
  5828. * Important - This must be unique to each column on a web page since it can
  5829. * be used as a key for retrieving information such as custom sort algorithms.
  5830. *
  5831. */
  5832. /**
  5833. * @ngdoc property
  5834. * @name name
  5835. * @propertyOf ui.grid.class:GridOptions.columnDef
  5836. * @description (mandatory) Each column should have a name, although for backward
  5837. * compatibility with 2.x name can be omitted if field is present.
  5838. *
  5839. * Important - This must be unique to each column on a web page since it can
  5840. * be used as a key for retrieving information such as custom sort algorithms.
  5841. *
  5842. */
  5843. /**
  5844. * @ngdoc property
  5845. * @name displayName
  5846. * @propertyOf ui.grid.class:GridColumn
  5847. * @description Column name that will be shown in the header. If displayName is not
  5848. * provided then one is generated using the name.
  5849. *
  5850. */
  5851. /**
  5852. * @ngdoc property
  5853. * @name displayName
  5854. * @propertyOf ui.grid.class:GridOptions.columnDef
  5855. * @description Column name that will be shown in the header. If displayName is not
  5856. * provided then one is generated using the name.
  5857. *
  5858. */
  5859. /**
  5860. * @ngdoc property
  5861. * @name field
  5862. * @propertyOf ui.grid.class:GridColumn
  5863. * @description field must be provided if you wish to bind to a
  5864. * property in the data source. Should be an angular expression that evaluates against grid.options.data
  5865. * array element. Can be a complex expression: <code>employee.address.city</code>, or can be a function: <code>employee.getFullAddress()</code>.
  5866. * See the angular docs on binding expressions.
  5867. *
  5868. */
  5869. /**
  5870. * @ngdoc property
  5871. * @name field
  5872. * @propertyOf ui.grid.class:GridOptions.columnDef
  5873. * @description field must be provided if you wish to bind to a
  5874. * property in the data source. Should be an angular expression that evaluates against grid.options.data
  5875. * array element. Can be a complex expression: <code>employee.address.city</code>, or can be a function: <code>employee.getFullAddress()</code>. * See the angular docs on binding expressions. *
  5876. */
  5877. /**
  5878. * @ngdoc property
  5879. * @name filter
  5880. * @propertyOf ui.grid.class:GridColumn
  5881. * @description Filter on this column.
  5882. *
  5883. * Available built-in conditions and types are listed under {@link jui.grid.service:uiGridConstants#properties_filter uiGridOptions.filter}
  5884. * @example
  5885. * <pre>{ term: 'text', condition: uiGridConstants.filter.STARTS_WITH, placeholder: 'type to filter...', ariaLabel: 'Filter for text', flags: { caseSensitive: false }, type: uiGridConstants.filter.SELECT, [ { value: 1, label: 'male' }, { value: 2, label: 'female' } ] }</pre>
  5886. *
  5887. */
  5888. /**
  5889. * @ngdoc property
  5890. * @name extraStyle
  5891. * @propertyOf ui.grid.class:GridColumn
  5892. * @description additional on this column.
  5893. * @example
  5894. * <pre>{extraStyle: {display:'table-cell'}}</pre>
  5895. *
  5896. */
  5897. /**
  5898. * @ngdoc object
  5899. * @name ui.grid.class:GridColumn
  5900. * @description Represents the viewModel for each column. Any state or methods needed for a Grid Column
  5901. * are defined on this prototype
  5902. * @param {ColumnDef} colDef the column def to associate with this column
  5903. * @param {number} uid the unique and immutable uid we'd like to allocate to this column
  5904. * @param {Grid} grid the grid we'd like to create this column in
  5905. */
  5906. function GridColumn(colDef, uid, grid) {
  5907. var self = this;
  5908. self.grid = grid;
  5909. self.uid = uid;
  5910. self.updateColumnDef(colDef, true);
  5911. self.aggregationValue = undefined;
  5912. // The footer cell registers to listen for the rowsRendered event, and calls this. Needed to be
  5913. // in something with a scope so that the dereg would get called
  5914. self.updateAggregationValue = function() {
  5915. // gridUtil.logDebug('getAggregationValue for Column ' + self.colDef.name);
  5916. /**
  5917. * @ngdoc property
  5918. * @name aggregationType
  5919. * @propertyOf ui.grid.class:GridOptions.columnDef
  5920. * @description The aggregation that you'd like to show in the columnFooter for this
  5921. * column. Valid values are in
  5922. * {@link ui.grid.service:uiGridConstants#properties_aggregationTypes uiGridConstants.aggregationTypes},
  5923. * and currently include `uiGridConstants.aggregationTypes.count`,
  5924. * `uiGridConstants.aggregationTypes.sum`, `uiGridConstants.aggregationTypes.avg`, `uiGridConstants.aggregationTypes.min`,
  5925. * `uiGridConstants.aggregationTypes.max`.
  5926. *
  5927. * You can also provide a function as the aggregation type, in this case your function needs to accept the full
  5928. * set of visible rows, and return a value that should be shown
  5929. */
  5930. if (!self.aggregationType) {
  5931. self.aggregationValue = undefined;
  5932. return;
  5933. }
  5934. var result = 0;
  5935. var visibleRows = self.grid.getVisibleRows();
  5936. var cellValues = function(){
  5937. var values = [];
  5938. visibleRows.forEach(function (row) {
  5939. var cellValue = self.grid.getCellValue(row, self);
  5940. var cellNumber = Number(cellValue);
  5941. if (!isNaN(cellNumber)) {
  5942. values.push(cellNumber);
  5943. }
  5944. });
  5945. return values;
  5946. };
  5947. if (angular.isFunction(self.aggregationType)) {
  5948. self.aggregationValue = self.aggregationType(visibleRows, self);
  5949. }
  5950. else if (self.aggregationType === uiGridConstants.aggregationTypes.count) {
  5951. self.aggregationValue = self.grid.getVisibleRowCount();
  5952. }
  5953. else if (self.aggregationType === uiGridConstants.aggregationTypes.sum) {
  5954. cellValues().forEach(function (value) {
  5955. result += value;
  5956. });
  5957. self.aggregationValue = result;
  5958. }
  5959. else if (self.aggregationType === uiGridConstants.aggregationTypes.avg) {
  5960. cellValues().forEach(function (value) {
  5961. result += value;
  5962. });
  5963. result = result / cellValues().length;
  5964. self.aggregationValue = result;
  5965. }
  5966. else if (self.aggregationType === uiGridConstants.aggregationTypes.min) {
  5967. self.aggregationValue = Math.min.apply(null, cellValues());
  5968. }
  5969. else if (self.aggregationType === uiGridConstants.aggregationTypes.max) {
  5970. self.aggregationValue = Math.max.apply(null, cellValues());
  5971. }
  5972. else {
  5973. self.aggregationValue = '\u00A0';
  5974. }
  5975. };
  5976. // var throttledUpdateAggregationValue = gridUtil.throttle(updateAggregationValue, self.grid.options.aggregationCalcThrottle, { trailing: true, context: self.name });
  5977. /**
  5978. * @ngdoc function
  5979. * @name getAggregationValue
  5980. * @methodOf ui.grid.class:GridColumn
  5981. * @description gets the aggregation value based on the aggregation type for this column.
  5982. * Debounced using scrollDebounce option setting
  5983. */
  5984. this.getAggregationValue = function() {
  5985. // if (!self.grid.isScrollingVertically && !self.grid.isScrollingHorizontally) {
  5986. // throttledUpdateAggregationValue();
  5987. // }
  5988. return self.aggregationValue;
  5989. };
  5990. }
  5991. /**
  5992. * @ngdoc function
  5993. * @name hideColumn
  5994. * @methodOf ui.grid.class:GridColumn
  5995. * @description Hides the column by setting colDef.visible = false
  5996. */
  5997. GridColumn.prototype.hideColumn = function() {
  5998. this.colDef.visible = false;
  5999. };
  6000. /**
  6001. * @ngdoc method
  6002. * @methodOf ui.grid.class:GridColumn
  6003. * @name setPropertyOrDefault
  6004. * @description Sets a property on the column using the passed in columnDef, and
  6005. * setting the defaultValue if the value cannot be found on the colDef
  6006. * @param {ColumnDef} colDef the column def to look in for the property value
  6007. * @param {string} propName the property name we'd like to set
  6008. * @param {object} defaultValue the value to use if the colDef doesn't provide the setting
  6009. */
  6010. GridColumn.prototype.setPropertyOrDefault = function (colDef, propName, defaultValue) {
  6011. var self = this;
  6012. // Use the column definition filter if we were passed it
  6013. if (typeof(colDef[propName]) !== 'undefined' && colDef[propName]) {
  6014. self[propName] = colDef[propName];
  6015. }
  6016. // Otherwise use our own if it's set
  6017. else if (typeof(self[propName]) !== 'undefined') {
  6018. self[propName] = self[propName];
  6019. }
  6020. // Default to empty object for the filter
  6021. else {
  6022. self[propName] = defaultValue ? defaultValue : {};
  6023. }
  6024. };
  6025. /**
  6026. * @ngdoc property
  6027. * @name width
  6028. * @propertyOf ui.grid.class:GridOptions.columnDef
  6029. * @description sets the column width. Can be either
  6030. * a number or a percentage, or an * for auto.
  6031. * @example
  6032. * <pre> $scope.gridOptions.columnDefs = [ { field: 'field1', width: 100},
  6033. * { field: 'field2', width: '20%'},
  6034. * { field: 'field3', width: '*' }]; </pre>
  6035. *
  6036. */
  6037. /**
  6038. * @ngdoc property
  6039. * @name minWidth
  6040. * @propertyOf ui.grid.class:GridOptions.columnDef
  6041. * @description Sets the minimum column width. Should be a number.
  6042. * Defaults to gridOptions.minimumColumnSize if minWidth is not provided.
  6043. * @example
  6044. * <pre> $scope.gridOptions.columnDefs = [ { field: 'field1', minWidth: 100}]; </pre>
  6045. *
  6046. */
  6047. /**
  6048. * @ngdoc property
  6049. * @name maxWidth
  6050. * @propertyOf ui.grid.class:GridOptions.columnDef
  6051. * @description sets the maximum column width. Should be a number.
  6052. * @example
  6053. * <pre> $scope.gridOptions.columnDefs = [ { field: 'field1', maxWidth: 100}]; </pre>
  6054. *
  6055. */
  6056. /**
  6057. * @ngdoc property
  6058. * @name visible
  6059. * @propertyOf ui.grid.class:GridOptions.columnDef
  6060. * @description sets whether or not the column is visible
  6061. * </br>Default is true
  6062. * @example
  6063. * <pre> $scope.gridOptions.columnDefs = [
  6064. * { field: 'field1', visible: true},
  6065. * { field: 'field2', visible: false }
  6066. * ]; </pre>
  6067. *
  6068. */
  6069. /**
  6070. * @ngdoc property
  6071. * @name sort
  6072. * @propertyOf ui.grid.class:GridOptions.columnDef
  6073. * @description An object of sort information, attributes are:
  6074. *
  6075. * - direction: values are {@link ui.grid.service:uiGridConstants#properties_ASC uiGridConstants.ASC}
  6076. * or {@link ui.grid.service:uiGridConstants#properties_DESC uiGridConstants.DESC}
  6077. * - ignoreSort: if set to true this sort is ignored (used by tree to manipulate the sort functionality)
  6078. * - priority: says what order to sort the columns in (lower priority gets sorted first).
  6079. * @example
  6080. * <pre>
  6081. * $scope.gridOptions.columnDefs = [{
  6082. * field: 'field1',
  6083. * sort: {
  6084. * direction: uiGridConstants.ASC,
  6085. * ignoreSort: true,
  6086. * priority: 0
  6087. * }
  6088. * }];
  6089. * </pre>
  6090. */
  6091. /**
  6092. * @ngdoc property
  6093. * @name sortingAlgorithm
  6094. * @propertyOf ui.grid.class:GridOptions.columnDef
  6095. * @description Algorithm to use for sorting this column. Takes 'a' and 'b' parameters
  6096. * like any normal sorting function with additional 'rowA', 'rowB', and 'direction' parameters
  6097. * that are the row objects and the current direction of the sort respectively.
  6098. *
  6099. */
  6100. /**
  6101. * @ngdoc property
  6102. * @name defaultSort
  6103. * @propertyOf ui.grid.class:GridOptions.columnDef
  6104. * @description An object of sort information, provides a hidden default ordering of the data
  6105. * when no user sorts are applied, or when a user-provided sort deems two rows to be equal.
  6106. *
  6107. * May be combined with a regular {@link ui.grid.class:GridOptions.columnDef#properties_sort columnDef.sort}
  6108. * to explicitly sort by that column by default.
  6109. *
  6110. * Shares the same object format as {@link ui.grid.class:GridOptions.columnDef#properties_sort columnDef.sort}.
  6111. *
  6112. * Note that a defaultSort can never take priority over an explicit sort.
  6113. * @example
  6114. * <pre>
  6115. * $scope.gridOptions.columnDefs = [{
  6116. * field: 'field1',
  6117. * defaultSort: {
  6118. * direction: uiGridConstants.ASC,
  6119. * priority: 0
  6120. * }
  6121. * }];
  6122. * </pre>
  6123. */
  6124. /**
  6125. * @ngdoc array
  6126. * @name filters
  6127. * @propertyOf ui.grid.class:GridOptions.columnDef
  6128. * @description Specify multiple filter fields.
  6129. * @example
  6130. * <pre>$scope.gridOptions.columnDefs = [
  6131. * {
  6132. * field: 'field1', filters: [
  6133. * {
  6134. * term: 'aa',
  6135. * condition: uiGridConstants.filter.STARTS_WITH,
  6136. * placeholder: 'starts with...',
  6137. * ariaLabel: 'Filter for field1',
  6138. * flags: { caseSensitive: false },
  6139. * type: uiGridConstants.filter.SELECT,
  6140. * selectOptions: [ { value: 1, label: 'male' }, { value: 2, label: 'female' } ]
  6141. * },
  6142. * {
  6143. * condition: uiGridConstants.filter.ENDS_WITH,
  6144. * placeholder: 'ends with...'
  6145. * }
  6146. * ]
  6147. * }
  6148. * ]; </pre>
  6149. *
  6150. *
  6151. */
  6152. /**
  6153. * @ngdoc array
  6154. * @name filters
  6155. * @propertyOf ui.grid.class:GridColumn
  6156. * @description Filters for this column. Includes 'term' property bound to filter input elements.
  6157. * @example
  6158. * <pre>[
  6159. * {
  6160. * term: 'foo', // ngModel for <input>
  6161. * condition: uiGridConstants.filter.STARTS_WITH,
  6162. * placeholder: 'starts with...',
  6163. * ariaLabel: 'Filter for foo',
  6164. * flags: { caseSensitive: false },
  6165. * type: uiGridConstants.filter.SELECT,
  6166. * selectOptions: [ { value: 1, label: 'male' }, { value: 2, label: 'female' } ]
  6167. * },
  6168. * {
  6169. * term: 'baz',
  6170. * condition: uiGridConstants.filter.ENDS_WITH,
  6171. * placeholder: 'ends with...'
  6172. * }
  6173. * ] </pre>
  6174. *
  6175. *
  6176. */
  6177. /**
  6178. * @ngdoc array
  6179. * @name menuItems
  6180. * @propertyOf ui.grid.class:GridOptions.columnDef
  6181. * @description used to add menu items to a column. Refer to the tutorial on this
  6182. * functionality. A number of settings are supported:
  6183. *
  6184. * - title: controls the title that is displayed in the menu
  6185. * - icon: the icon shown alongside that title
  6186. * - action: the method to call when the menu is clicked
  6187. * - shown: a function to evaluate to determine whether or not to show the item
  6188. * - active: a function to evaluate to determine whether or not the item is currently selected
  6189. * - context: context to pass to the action function, available in this.context in your handler
  6190. * - leaveOpen: if set to true, the menu should stay open after the action, defaults to false
  6191. * @example
  6192. * <pre> $scope.gridOptions.columnDefs = [
  6193. * { field: 'field1', menuItems: [
  6194. * {
  6195. * title: 'Outer Scope Alert',
  6196. * icon: 'ui-grid-icon-info-circled',
  6197. * action: function($event) {
  6198. * this.context.blargh(); // $scope.blargh() would work too, this is just an example
  6199. * },
  6200. * shown: function() { return true; },
  6201. * active: function() { return true; },
  6202. * context: $scope
  6203. * },
  6204. * {
  6205. * title: 'Grid ID',
  6206. * action: function() {
  6207. * alert('Grid ID: ' + this.grid.id);
  6208. * }
  6209. * }
  6210. * ] }]; </pre>
  6211. *
  6212. */
  6213. /**
  6214. * @ngdoc method
  6215. * @methodOf ui.grid.class:GridColumn
  6216. * @name updateColumnDef
  6217. * @description Moves settings from the columnDef down onto the column,
  6218. * and sets properties as appropriate
  6219. * @param {ColumnDef} colDef the column def to look in for the property value
  6220. * @param {boolean} isNew whether the column is being newly created, if not
  6221. * we're updating an existing column, and some items such as the sort shouldn't
  6222. * be copied down
  6223. */
  6224. GridColumn.prototype.updateColumnDef = function(colDef, isNew) {
  6225. var self = this;
  6226. self.colDef = colDef;
  6227. if (colDef.name === undefined) {
  6228. throw new Error('colDef.name is required for column at index ' + self.grid.options.columnDefs.indexOf(colDef));
  6229. }
  6230. self.displayName = (colDef.displayName === undefined) ? gridUtil.readableColumnName(colDef.name) : colDef.displayName;
  6231. if (!angular.isNumber(self.width) || !self.hasCustomWidth || colDef.allowCustomWidthOverride) {
  6232. var colDefWidth = colDef.width;
  6233. var parseErrorMsg = "Cannot parse column width '" + colDefWidth + "' for column named '" + colDef.name + "'";
  6234. self.hasCustomWidth = false;
  6235. if (!angular.isString(colDefWidth) && !angular.isNumber(colDefWidth)) {
  6236. self.width = '*';
  6237. } else if (angular.isString(colDefWidth)) {
  6238. // See if it ends with a percent
  6239. if (gridUtil.endsWith(colDefWidth, '%')) {
  6240. // If so we should be able to parse the non-percent-sign part to a number
  6241. var percentStr = colDefWidth.replace(/%/g, '');
  6242. var percent = parseInt(percentStr, 10);
  6243. if (isNaN(percent)) {
  6244. throw new Error(parseErrorMsg);
  6245. }
  6246. self.width = colDefWidth;
  6247. }
  6248. // And see if it's a number string
  6249. else if (colDefWidth.match(/^(\d+)$/)) {
  6250. self.width = parseInt(colDefWidth.match(/^(\d+)$/)[1], 10);
  6251. }
  6252. // Otherwise it should be a string of asterisks
  6253. else if (colDefWidth.match(/^\*+$/)) {
  6254. self.width = colDefWidth;
  6255. }
  6256. // No idea, throw an Error
  6257. else {
  6258. throw new Error(parseErrorMsg);
  6259. }
  6260. }
  6261. // Is a number, use it as the width
  6262. else {
  6263. self.width = colDefWidth;
  6264. }
  6265. }
  6266. function isValidWidthValue(value) {
  6267. return angular.isString(value) || angular.isNumber(value);
  6268. }
  6269. ['minWidth', 'maxWidth'].forEach(function (name) {
  6270. var minOrMaxWidth = colDef[name];
  6271. var parseErrorMsg = "Cannot parse column " + name + " '" + minOrMaxWidth + "' for column named '" + colDef.name + "'";
  6272. // default minWidth to the minimumColumnSize
  6273. if (name === 'minWidth' && !isValidWidthValue(minOrMaxWidth) && angular.isDefined(self.grid.options.minimumColumnSize)) {
  6274. minOrMaxWidth = self.grid.options.minimumColumnSize;
  6275. }
  6276. if (!isValidWidthValue(minOrMaxWidth)) {
  6277. // Sets default minWidth and maxWidth values
  6278. self[name] = ((name === 'minWidth') ? 30 : 9000);
  6279. } else if (angular.isString(minOrMaxWidth)) {
  6280. if (minOrMaxWidth.match(/^(\d+)$/)) {
  6281. self[name] = parseInt(minOrMaxWidth.match(/^(\d+)$/)[1], 10);
  6282. } else {
  6283. throw new Error(parseErrorMsg);
  6284. }
  6285. } else {
  6286. self[name] = minOrMaxWidth;
  6287. }
  6288. });
  6289. //use field if it is defined; name if it is not
  6290. self.field = (colDef.field === undefined) ? colDef.name : colDef.field;
  6291. if ( typeof( self.field ) !== 'string' ){
  6292. gridUtil.logError( 'Field is not a string, this is likely to break the code, Field is: ' + self.field );
  6293. }
  6294. self.name = colDef.name;
  6295. // Use colDef.displayName as long as it's not undefined, otherwise default to the field name
  6296. self.displayName = (colDef.displayName === undefined) ? gridUtil.readableColumnName(colDef.name) : colDef.displayName;
  6297. //self.originalIndex = index;
  6298. self.aggregationType = angular.isDefined(colDef.aggregationType) ? colDef.aggregationType : null;
  6299. self.footerCellTemplate = angular.isDefined(colDef.footerCellTemplate) ? colDef.footerCellTemplate : null;
  6300. /**
  6301. * @ngdoc property
  6302. * @name cellTooltip
  6303. * @propertyOf ui.grid.class:GridOptions.columnDef
  6304. * @description Whether or not to show a tooltip when a user hovers over the cell.
  6305. * If set to false, no tooltip. If true, the cell value is shown in the tooltip (useful
  6306. * if you have long values in your cells), if a function then that function is called
  6307. * passing in the row and the col `cellTooltip( row, col )`, and the return value is shown in the tooltip,
  6308. * if it is a static string then displays that static string.
  6309. *
  6310. * Defaults to false
  6311. *
  6312. */
  6313. if ( typeof(colDef.cellTooltip) === 'undefined' || colDef.cellTooltip === false ) {
  6314. self.cellTooltip = false;
  6315. } else if ( colDef.cellTooltip === true ){
  6316. self.cellTooltip = function(row, col) {
  6317. return self.grid.getCellValue( row, col );
  6318. };
  6319. } else if (typeof(colDef.cellTooltip) === 'function' ){
  6320. self.cellTooltip = colDef.cellTooltip;
  6321. } else {
  6322. self.cellTooltip = function ( row, col ){
  6323. return col.colDef.cellTooltip;
  6324. };
  6325. }
  6326. /**
  6327. * @ngdoc property
  6328. * @name headerTooltip
  6329. * @propertyOf ui.grid.class:GridOptions.columnDef
  6330. * @description Whether or not to show a tooltip when a user hovers over the header cell.
  6331. * If set to false, no tooltip. If true, the displayName is shown in the tooltip (useful
  6332. * if you have long values in your headers), if a function then that function is called
  6333. * passing in the row and the col `headerTooltip( col )`, and the return value is shown in the tooltip,
  6334. * if a static string then shows that static string.
  6335. *
  6336. * Defaults to false
  6337. *
  6338. */
  6339. if ( typeof(colDef.headerTooltip) === 'undefined' || colDef.headerTooltip === false ) {
  6340. self.headerTooltip = false;
  6341. } else if ( colDef.headerTooltip === true ){
  6342. self.headerTooltip = function(col) {
  6343. return col.displayName;
  6344. };
  6345. } else if (typeof(colDef.headerTooltip) === 'function' ){
  6346. self.headerTooltip = colDef.headerTooltip;
  6347. } else {
  6348. self.headerTooltip = function ( col ) {
  6349. return col.colDef.headerTooltip;
  6350. };
  6351. }
  6352. /**
  6353. * @ngdoc property
  6354. * @name footerCellClass
  6355. * @propertyOf ui.grid.class:GridOptions.columnDef
  6356. * @description footerCellClass can be a string specifying the class to append to a cell
  6357. * or it can be a function(grid, row, col, rowRenderIndex, colRenderIndex) that returns a class name
  6358. *
  6359. */
  6360. self.footerCellClass = colDef.footerCellClass;
  6361. /**
  6362. * @ngdoc property
  6363. * @name cellClass
  6364. * @propertyOf ui.grid.class:GridOptions.columnDef
  6365. * @description cellClass can be a string specifying the class to append to a cell
  6366. * or it can be a function(grid, row, col, rowRenderIndex, colRenderIndex) that returns a class name
  6367. *
  6368. */
  6369. self.cellClass = colDef.cellClass;
  6370. /**
  6371. * @ngdoc property
  6372. * @name headerCellClass
  6373. * @propertyOf ui.grid.class:GridOptions.columnDef
  6374. * @description headerCellClass can be a string specifying the class to append to a cell
  6375. * or it can be a function(grid, row, col, rowRenderIndex, colRenderIndex) that returns a class name
  6376. *
  6377. */
  6378. self.headerCellClass = colDef.headerCellClass;
  6379. /**
  6380. * @ngdoc property
  6381. * @name cellFilter
  6382. * @propertyOf ui.grid.class:GridOptions.columnDef
  6383. * @description cellFilter is a filter to apply to the content of each cell
  6384. * @example
  6385. * <pre>
  6386. * gridOptions.columnDefs[0].cellFilter = 'date'
  6387. *
  6388. */
  6389. self.cellFilter = colDef.cellFilter ? colDef.cellFilter : "";
  6390. /**
  6391. * @ngdoc boolean
  6392. * @name sortCellFiltered
  6393. * @propertyOf ui.grid.class:GridOptions.columnDef
  6394. * @description (optional) False by default. When `true` uiGrid will apply the cellFilter before
  6395. * sorting the data. Note that when using this option uiGrid will assume that the displayed value is
  6396. * a string, and use the {@link ui.grid.class:RowSorter#sortAlpha sortAlpha} `sortFn`. It is possible
  6397. * to return a non-string value from an angularjs filter, in which case you should define a {@link ui.grid.class:GridOptions.columnDef#sortingAlgorithm sortingAlgorithm}
  6398. * for the column which hanldes the returned type. You may specify one of the `sortingAlgorithms`
  6399. * found in the {@link ui.grid.RowSorter rowSorter} service.
  6400. */
  6401. self.sortCellFiltered = colDef.sortCellFiltered ? true : false;
  6402. /**
  6403. * @ngdoc boolean
  6404. * @name filterCellFiltered
  6405. * @propertyOf ui.grid.class:GridOptions.columnDef
  6406. * @description (optional) False by default. When `true` uiGrid will apply the cellFilter before
  6407. * applying "search" `filters`.
  6408. */
  6409. self.filterCellFiltered = colDef.filterCellFiltered ? true : false;
  6410. /**
  6411. * @ngdoc property
  6412. * @name headerCellFilter
  6413. * @propertyOf ui.grid.class:GridOptions.columnDef
  6414. * @description headerCellFilter is a filter to apply to the content of the column header
  6415. * @example
  6416. * <pre>
  6417. * gridOptions.columnDefs[0].headerCellFilter = 'translate'
  6418. *
  6419. */
  6420. self.headerCellFilter = colDef.headerCellFilter ? colDef.headerCellFilter : "";
  6421. /**
  6422. * @ngdoc property
  6423. * @name footerCellFilter
  6424. * @propertyOf ui.grid.class:GridOptions.columnDef
  6425. * @description footerCellFilter is a filter to apply to the content of the column footer
  6426. * @example
  6427. * <pre>
  6428. * gridOptions.columnDefs[0].footerCellFilter = 'date'
  6429. *
  6430. */
  6431. self.footerCellFilter = colDef.footerCellFilter ? colDef.footerCellFilter : "";
  6432. self.visible = gridUtil.isNullOrUndefined(colDef.visible) || colDef.visible;
  6433. self.headerClass = colDef.headerClass;
  6434. //self.cursor = self.sortable ? 'pointer' : 'default';
  6435. // Turn on sorting by default
  6436. self.enableSorting = typeof(colDef.enableSorting) !== 'undefined' ? colDef.enableSorting : self.grid.options.enableSorting;
  6437. self.sortingAlgorithm = colDef.sortingAlgorithm;
  6438. /**
  6439. * @ngdoc property
  6440. * @name sortDirectionCycle
  6441. * @propertyOf ui.grid.class:GridOptions.columnDef
  6442. * @description (optional) An array of {@link ui.grid.service:uiGridConstants#properties_ASC sort directions},
  6443. * specifying the order that they should cycle through as the user repeatedly clicks on the column heading.
  6444. * The default is `[null, uiGridConstants.ASC, uiGridConstants.DESC]`. Null
  6445. * refers to the unsorted state. This does not affect the initial sort
  6446. * direction; use the {@link ui.grid.class:GridOptions.columnDef#sort sort}
  6447. * property for that. If
  6448. * {@link ui.grid.class:GridOptions.columnDef#suppressRemoveSort suppressRemoveSort}
  6449. * is also set, the unsorted state will be skipped even if it is listed here.
  6450. * Each direction may not appear in the list more than once (e.g. `[ASC,
  6451. * DESC, DESC]` is not allowed), and the list may not be empty.
  6452. */
  6453. self.sortDirectionCycle = typeof(colDef.sortDirectionCycle) !== 'undefined' ?
  6454. colDef.sortDirectionCycle :
  6455. [null, uiGridConstants.ASC, uiGridConstants.DESC];
  6456. /**
  6457. * @ngdoc boolean
  6458. * @name suppressRemoveSort
  6459. * @propertyOf ui.grid.class:GridOptions.columnDef
  6460. * @description (optional) False by default. When enabled, this setting hides the removeSort option
  6461. * in the menu, and prevents users from manually removing the sort
  6462. */
  6463. if ( typeof(self.suppressRemoveSort) === 'undefined'){
  6464. self.suppressRemoveSort = typeof(colDef.suppressRemoveSort) !== 'undefined' ? colDef.suppressRemoveSort : false;
  6465. }
  6466. /**
  6467. * @ngdoc property
  6468. * @name enableFiltering
  6469. * @propertyOf ui.grid.class:GridOptions.columnDef
  6470. * @description turn off filtering for an individual column, where
  6471. * you've turned on filtering for the overall grid
  6472. * @example
  6473. * <pre>
  6474. * gridOptions.columnDefs[0].enableFiltering = false;
  6475. *
  6476. */
  6477. // Turn on filtering by default (it's disabled by default at the Grid level)
  6478. self.enableFiltering = typeof(colDef.enableFiltering) !== 'undefined' ? colDef.enableFiltering : true;
  6479. // self.menuItems = colDef.menuItems;
  6480. self.setPropertyOrDefault(colDef, 'menuItems', []);
  6481. // Use the column definition sort if we were passed it, but only if this is a newly added column
  6482. if ( isNew ){
  6483. self.setPropertyOrDefault(colDef, 'sort');
  6484. }
  6485. // Use the column definition defaultSort always, unlike normal sort
  6486. self.setPropertyOrDefault(colDef, 'defaultSort');
  6487. // Set up default filters array for when one is not provided.
  6488. // In other words, this (in column def):
  6489. //
  6490. // filter: { term: 'something', flags: {}, condition: [CONDITION] }
  6491. //
  6492. // is just shorthand for this:
  6493. //
  6494. // filters: [{ term: 'something', flags: {}, condition: [CONDITION] }]
  6495. //
  6496. var defaultFilters = [];
  6497. if (colDef.filter) {
  6498. defaultFilters.push(colDef.filter);
  6499. }
  6500. else if ( colDef.filters ){
  6501. defaultFilters = colDef.filters;
  6502. } else {
  6503. // Add an empty filter definition object, which will
  6504. // translate to a guessed condition and no pre-populated
  6505. // value for the filter <input>.
  6506. defaultFilters.push({});
  6507. }
  6508. /**
  6509. * @ngdoc property
  6510. * @name filter
  6511. * @propertyOf ui.grid.class:GridOptions.columnDef
  6512. * @description Specify a single filter field on this column.
  6513. *
  6514. * A filter consists of a condition, a term, and a placeholder:
  6515. *
  6516. * - condition defines how rows are chosen as matching the filter term. This can be set to
  6517. * one of the constants in {@link ui.grid.service:uiGridConstants#properties_filter uiGridConstants.filter},
  6518. * or you can supply a custom filter function
  6519. * that gets passed the following arguments: [searchTerm, cellValue, row, column].
  6520. * - term: If set, the filter field will be pre-populated
  6521. * with this value.
  6522. * - placeholder: String that will be set to the `<input>.placeholder` attribute.
  6523. * - ariaLabel: String that will be set to the `<input>.ariaLabel` attribute. This is what is read as a label to screen reader users.
  6524. * - noTerm: set this to true if you have defined a custom function in condition, and
  6525. * your custom function doesn't require a term (so it can run even when the term is null)
  6526. * - rawTerm: set this to true if you have defined a custom function in condition, and
  6527. * your custom function requires access to the raw unmodified search term that was entered
  6528. * - flags: only flag currently available is `caseSensitive`, set to false if you don't want
  6529. * case sensitive matching
  6530. * - type: defaults to {@link ui.grid.service:uiGridConstants#properties_filter uiGridConstants.filter.INPUT},
  6531. * which gives a text box. If set to {@link ui.grid.service:uiGridConstants#properties_filter uiGridConstants.filter.SELECT}
  6532. * then a select box will be shown with options selectOptions
  6533. * - selectOptions: options in the format `[ { value: 1, label: 'male' }]`. No i18n filter is provided, you need
  6534. * to perform the i18n on the values before you provide them
  6535. * - disableCancelFilterButton: defaults to false. If set to true then the 'x' button that cancels/clears the filter
  6536. * will not be shown.
  6537. * @example
  6538. * <pre>$scope.gridOptions.columnDefs = [
  6539. * {
  6540. * field: 'field1',
  6541. * filter: {
  6542. * term: 'xx',
  6543. * condition: uiGridConstants.filter.STARTS_WITH,
  6544. * placeholder: 'starts with...',
  6545. * ariaLabel: 'Starts with filter for field1',
  6546. * flags: { caseSensitive: false },
  6547. * type: uiGridConstants.filter.SELECT,
  6548. * selectOptions: [ { value: 1, label: 'male' }, { value: 2, label: 'female' } ],
  6549. * disableCancelFilterButton: true
  6550. * }
  6551. * }
  6552. * ]; </pre>
  6553. *
  6554. */
  6555. /*
  6556. /*
  6557. self.filters = [
  6558. {
  6559. term: 'search term'
  6560. condition: uiGridConstants.filter.CONTAINS,
  6561. placeholder: 'my placeholder',
  6562. ariaLabel: 'Starts with filter for field1',
  6563. flags: {
  6564. caseSensitive: true
  6565. }
  6566. }
  6567. ]
  6568. */
  6569. // Only set filter if this is a newly added column, if we're updating an existing
  6570. // column then we don't want to put the default filter back if the user may have already
  6571. // removed it.
  6572. // However, we do want to keep the settings if they change, just not the term
  6573. if ( isNew ) {
  6574. self.setPropertyOrDefault(colDef, 'filter');
  6575. self.setPropertyOrDefault(colDef, 'extraStyle');
  6576. self.setPropertyOrDefault(colDef, 'filters', defaultFilters);
  6577. } else if ( self.filters.length === defaultFilters.length ) {
  6578. self.filters.forEach( function( filter, index ){
  6579. if (typeof(defaultFilters[index].placeholder) !== 'undefined') {
  6580. filter.placeholder = defaultFilters[index].placeholder;
  6581. }
  6582. if (typeof(defaultFilters[index].ariaLabel) !== 'undefined') {
  6583. filter.ariaLabel = defaultFilters[index].ariaLabel;
  6584. }
  6585. if (typeof(defaultFilters[index].flags) !== 'undefined') {
  6586. filter.flags = defaultFilters[index].flags;
  6587. }
  6588. if (typeof(defaultFilters[index].type) !== 'undefined') {
  6589. filter.type = defaultFilters[index].type;
  6590. }
  6591. if (typeof(defaultFilters[index].selectOptions) !== 'undefined') {
  6592. filter.selectOptions = defaultFilters[index].selectOptions;
  6593. }
  6594. });
  6595. }
  6596. };
  6597. /**
  6598. * @ngdoc function
  6599. * @name unsort
  6600. * @methodOf ui.grid.class:GridColumn
  6601. * @description Removes column from the grid sorting
  6602. */
  6603. GridColumn.prototype.unsort = function () {
  6604. //Decrease priority for every col where priority is higher than the removed sort's priority.
  6605. var thisPriority = this.sort.priority;
  6606. this.grid.columns.forEach(function (col) {
  6607. if (col.sort && col.sort.priority !== undefined && col.sort.priority > thisPriority) {
  6608. col.sort.priority -= 1;
  6609. }
  6610. });
  6611. this.sort = {};
  6612. this.grid.api.core.raise.sortChanged( this.grid, this.grid.getColumnSorting() );
  6613. };
  6614. /**
  6615. * @ngdoc function
  6616. * @name getColClass
  6617. * @methodOf ui.grid.class:GridColumn
  6618. * @description Returns the class name for the column
  6619. * @param {bool} prefixDot if true, will return .className instead of className
  6620. */
  6621. GridColumn.prototype.getColClass = function (prefixDot) {
  6622. var cls = uiGridConstants.COL_CLASS_PREFIX + this.uid;
  6623. return prefixDot ? '.' + cls : cls;
  6624. };
  6625. /**
  6626. * @ngdoc function
  6627. * @name isPinnedLeft
  6628. * @methodOf ui.grid.class:GridColumn
  6629. * @description Returns true if column is in the left render container
  6630. */
  6631. GridColumn.prototype.isPinnedLeft = function () {
  6632. return this.renderContainer === 'left';
  6633. };
  6634. /**
  6635. * @ngdoc function
  6636. * @name isPinnedRight
  6637. * @methodOf ui.grid.class:GridColumn
  6638. * @description Returns true if column is in the right render container
  6639. */
  6640. GridColumn.prototype.isPinnedRight = function () {
  6641. return this.renderContainer === 'right';
  6642. };
  6643. /**
  6644. * @ngdoc function
  6645. * @name getColClassDefinition
  6646. * @methodOf ui.grid.class:GridColumn
  6647. * @description Returns the class definition for th column
  6648. */
  6649. GridColumn.prototype.getColClassDefinition = function () {
  6650. return ' .grid' + this.grid.id + ' ' + this.getColClass(true) + ' { min-width: ' + this.drawnWidth + 'px; max-width: ' + this.drawnWidth + 'px; }';
  6651. };
  6652. /**
  6653. * @ngdoc function
  6654. * @name getRenderContainer
  6655. * @methodOf ui.grid.class:GridColumn
  6656. * @description Returns the render container object that this column belongs to.
  6657. *
  6658. * Columns will be default be in the `body` render container if they aren't allocated to one specifically.
  6659. */
  6660. GridColumn.prototype.getRenderContainer = function getRenderContainer() {
  6661. var self = this;
  6662. var containerId = self.renderContainer;
  6663. if (containerId === null || containerId === '' || containerId === undefined) {
  6664. containerId = 'body';
  6665. }
  6666. return self.grid.renderContainers[containerId];
  6667. };
  6668. /**
  6669. * @ngdoc function
  6670. * @name showColumn
  6671. * @methodOf ui.grid.class:GridColumn
  6672. * @description Makes the column visible by setting colDef.visible = true
  6673. */
  6674. GridColumn.prototype.showColumn = function() {
  6675. this.colDef.visible = true;
  6676. };
  6677. /**
  6678. * @ngdoc property
  6679. * @name aggregationHideLabel
  6680. * @propertyOf ui.grid.class:GridOptions.columnDef
  6681. * @description defaults to false, if set to true hides the label text
  6682. * in the aggregation footer, so only the value is displayed.
  6683. *
  6684. */
  6685. /**
  6686. * @ngdoc function
  6687. * @name getAggregationText
  6688. * @methodOf ui.grid.class:GridColumn
  6689. * @description Gets the aggregation label from colDef.aggregationLabel if
  6690. * specified or by using i18n, including deciding whether or not to display
  6691. * based on colDef.aggregationHideLabel.
  6692. *
  6693. * @param {string} label the i18n lookup value to use for the column label
  6694. *
  6695. */
  6696. GridColumn.prototype.getAggregationText = function () {
  6697. var self = this;
  6698. if ( self.colDef.aggregationHideLabel ){
  6699. return '';
  6700. }
  6701. else if ( self.colDef.aggregationLabel ) {
  6702. return self.colDef.aggregationLabel;
  6703. }
  6704. else {
  6705. switch ( self.colDef.aggregationType ){
  6706. case uiGridConstants.aggregationTypes.count:
  6707. return i18nService.getSafeText('aggregation.count');
  6708. case uiGridConstants.aggregationTypes.sum:
  6709. return i18nService.getSafeText('aggregation.sum');
  6710. case uiGridConstants.aggregationTypes.avg:
  6711. return i18nService.getSafeText('aggregation.avg');
  6712. case uiGridConstants.aggregationTypes.min:
  6713. return i18nService.getSafeText('aggregation.min');
  6714. case uiGridConstants.aggregationTypes.max:
  6715. return i18nService.getSafeText('aggregation.max');
  6716. default:
  6717. return '';
  6718. }
  6719. }
  6720. };
  6721. GridColumn.prototype.getCellTemplate = function () {
  6722. var self = this;
  6723. return self.cellTemplatePromise;
  6724. };
  6725. GridColumn.prototype.getCompiledElementFn = function () {
  6726. var self = this;
  6727. return self.compiledElementFnDefer.promise;
  6728. };
  6729. return GridColumn;
  6730. }]);
  6731. })();
  6732. (function(){
  6733. angular.module('ui.grid')
  6734. .factory('GridOptions', ['gridUtil','uiGridConstants', function(gridUtil,uiGridConstants) {
  6735. /**
  6736. * @ngdoc function
  6737. * @name ui.grid.class:GridOptions
  6738. * @description Default GridOptions class. GridOptions are defined by the application developer and overlaid
  6739. * over this object. Setting gridOptions within your controller is the most common method for an application
  6740. * developer to configure the behaviour of their ui-grid
  6741. *
  6742. * @example To define your gridOptions within your controller:
  6743. * <pre>$scope.gridOptions = {
  6744. * data: $scope.myData,
  6745. * columnDefs: [
  6746. * { name: 'field1', displayName: 'pretty display name' },
  6747. * { name: 'field2', visible: false }
  6748. * ]
  6749. * };</pre>
  6750. *
  6751. * You can then use this within your html template, when you define your grid:
  6752. * <pre>&lt;div ui-grid="gridOptions"&gt;&lt;/div&gt;</pre>
  6753. *
  6754. * To provide default options for all of the grids within your application, use an angular
  6755. * decorator to modify the GridOptions factory.
  6756. * <pre>
  6757. * app.config(function($provide){
  6758. * $provide.decorator('GridOptions',function($delegate){
  6759. * var gridOptions;
  6760. * gridOptions = angular.copy($delegate);
  6761. * gridOptions.initialize = function(options) {
  6762. * var initOptions;
  6763. * initOptions = $delegate.initialize(options);
  6764. * initOptions.enableColumnMenus = false;
  6765. * return initOptions;
  6766. * };
  6767. * return gridOptions;
  6768. * });
  6769. * });
  6770. * </pre>
  6771. */
  6772. return {
  6773. initialize: function( baseOptions ){
  6774. /**
  6775. * @ngdoc function
  6776. * @name onRegisterApi
  6777. * @propertyOf ui.grid.class:GridOptions
  6778. * @description A callback that returns the gridApi once the grid is instantiated, which is
  6779. * then used to interact with the grid programatically.
  6780. *
  6781. * Note that the gridApi.core.renderingComplete event is identical to this
  6782. * callback, but has the advantage that it can be called from multiple places
  6783. * if needed
  6784. *
  6785. * @example
  6786. * <pre>
  6787. * $scope.gridOptions.onRegisterApi = function ( gridApi ) {
  6788. * $scope.gridApi = gridApi;
  6789. * $scope.gridApi.selection.selectAllRows( $scope.gridApi.grid );
  6790. * };
  6791. * </pre>
  6792. *
  6793. */
  6794. baseOptions.onRegisterApi = baseOptions.onRegisterApi || angular.noop();
  6795. /**
  6796. * @ngdoc object
  6797. * @name data
  6798. * @propertyOf ui.grid.class:GridOptions
  6799. * @description (mandatory) Array of data to be rendered into the grid, providing the data source or data binding for
  6800. * the grid.
  6801. *
  6802. * Most commonly the data is an array of objects, where each object has a number of attributes.
  6803. * Each attribute automatically becomes a column in your grid. This array could, for example, be sourced from
  6804. * an angularJS $resource query request. The array can also contain complex objects, refer the binding tutorial
  6805. * for examples of that.
  6806. *
  6807. * The most flexible usage is to set your data on $scope:
  6808. *
  6809. * `$scope.data = data;`
  6810. *
  6811. * And then direct the grid to resolve whatever is in $scope.data:
  6812. *
  6813. * `$scope.gridOptions.data = 'data';`
  6814. *
  6815. * This is the most flexible approach as it allows you to replace $scope.data whenever you feel like it without
  6816. * getting pointer issues.
  6817. *
  6818. * Alternatively you can directly set the data array:
  6819. *
  6820. * `$scope.gridOptions.data = [ ];`
  6821. * or
  6822. *
  6823. * `$http.get('/data/100.json')
  6824. * .success(function(data) {
  6825. * $scope.myData = data;
  6826. * $scope.gridOptions.data = $scope.myData;
  6827. * });`
  6828. *
  6829. * Where you do this, you need to take care in updating the data - you can't just update `$scope.myData` to some other
  6830. * array, you need to update $scope.gridOptions.data to point to that new array as well.
  6831. *
  6832. */
  6833. baseOptions.data = baseOptions.data || [];
  6834. /**
  6835. * @ngdoc array
  6836. * @name columnDefs
  6837. * @propertyOf ui.grid.class:GridOptions
  6838. * @description Array of columnDef objects. Only required property is name.
  6839. * The individual options available in columnDefs are documented in the
  6840. * {@link ui.grid.class:GridOptions.columnDef columnDef} section
  6841. * </br>_field property can be used in place of name for backwards compatibility with 2.x_
  6842. * @example
  6843. *
  6844. * <pre>var columnDefs = [{name:'field1'}, {name:'field2'}];</pre>
  6845. *
  6846. */
  6847. baseOptions.columnDefs = baseOptions.columnDefs || [];
  6848. /**
  6849. * @ngdoc object
  6850. * @name ui.grid.class:GridOptions.columnDef
  6851. * @description Definition / configuration of an individual column, which would typically be
  6852. * one of many column definitions within the gridOptions.columnDefs array
  6853. * @example
  6854. * <pre>{name:'field1', field: 'field1', filter: { term: 'xxx' }}</pre>
  6855. *
  6856. */
  6857. /**
  6858. * @ngdoc object
  6859. * @name enableGridMenu
  6860. * @propertyOf ui.grid.class:GridOptions
  6861. * @description Takes a boolean that adds a settings icon in the top right of the grid, which floats above
  6862. * the column header, when true. The menu by default gives access to show/hide columns, but can be
  6863. * customised to show additional actions.
  6864. *
  6865. * See the {@link #!/tutorial/121_grid_menu Grid Menu tutorial} for more detailed information.
  6866. */
  6867. /**
  6868. * @ngdoc array
  6869. * @name excludeProperties
  6870. * @propertyOf ui.grid.class:GridOptions
  6871. * @description Array of property names in data to ignore when auto-generating column names. Provides the
  6872. * inverse of columnDefs - columnDefs is a list of columns to include, excludeProperties is a list of columns
  6873. * to exclude.
  6874. *
  6875. * If columnDefs is defined, this will be ignored.
  6876. *
  6877. * Defaults to ['$$hashKey']
  6878. */
  6879. baseOptions.excludeProperties = baseOptions.excludeProperties || ['$$hashKey'];
  6880. /**
  6881. * @ngdoc boolean
  6882. * @name enableRowHashing
  6883. * @propertyOf ui.grid.class:GridOptions
  6884. * @description True by default. When enabled, this setting allows uiGrid to add
  6885. * `$$hashKey`-type properties (similar to Angular) to elements in the `data` array. This allows
  6886. * the grid to maintain state while vastly speeding up the process of altering `data` by adding/moving/removing rows.
  6887. *
  6888. * Note that this DOES add properties to your data that you may not want, but they are stripped out when using `angular.toJson()`. IF
  6889. * you do not want this at all you can disable this setting but you will take a performance hit if you are using large numbers of rows
  6890. * and are altering the data set often.
  6891. */
  6892. baseOptions.enableRowHashing = baseOptions.enableRowHashing !== false;
  6893. /**
  6894. * @ngdoc function
  6895. * @name rowIdentity
  6896. * @methodOf ui.grid.class:GridOptions
  6897. * @description This function is used to get and, if necessary, set the value uniquely identifying this row (i.e. if an identity is not present it will set one).
  6898. *
  6899. * By default it returns the `$$hashKey` property if it exists. If it doesn't it uses gridUtil.nextUid() to generate one
  6900. */
  6901. baseOptions.rowIdentity = baseOptions.rowIdentity || function rowIdentity(row) {
  6902. return gridUtil.hashKey(row);
  6903. };
  6904. /**
  6905. * @ngdoc function
  6906. * @name getRowIdentity
  6907. * @methodOf ui.grid.class:GridOptions
  6908. * @description This function returns the identity value uniquely identifying this row, if one is not present it does not set it.
  6909. *
  6910. * By default it returns the `$$hashKey` property but can be overridden to use any property or set of properties you want.
  6911. */
  6912. baseOptions.getRowIdentity = baseOptions.getRowIdentity || function getRowIdentity(row) {
  6913. return row.$$hashKey;
  6914. };
  6915. /**
  6916. * @ngdoc property
  6917. * @name flatEntityAccess
  6918. * @propertyOf ui.grid.class:GridOptions
  6919. * @description Set to true if your columns are all related directly to fields in a flat object structure - i.e.
  6920. * each of your columns associate directly with a property on each of the entities in your data array.
  6921. *
  6922. * In that situation we can avoid all the logic associated with complex binding to functions or to properties of sub-objects,
  6923. * which can provide a significant speed improvement with large data sets when filtering or sorting.
  6924. *
  6925. * By default false
  6926. */
  6927. baseOptions.flatEntityAccess = baseOptions.flatEntityAccess === true;
  6928. /**
  6929. * @ngdoc property
  6930. * @name showHeader
  6931. * @propertyOf ui.grid.class:GridOptions
  6932. * @description True by default. When set to false, this setting will replace the
  6933. * standard header template with '<div></div>', resulting in no header being shown.
  6934. */
  6935. baseOptions.showHeader = typeof(baseOptions.showHeader) !== "undefined" ? baseOptions.showHeader : true;
  6936. /* (NOTE): Don't show this in the docs. We only use it internally
  6937. * @ngdoc property
  6938. * @name headerRowHeight
  6939. * @propertyOf ui.grid.class:GridOptions
  6940. * @description The height of the header in pixels, defaults to 30
  6941. *
  6942. */
  6943. if (!baseOptions.showHeader) {
  6944. baseOptions.headerRowHeight = 0;
  6945. }
  6946. else {
  6947. baseOptions.headerRowHeight = typeof(baseOptions.headerRowHeight) !== "undefined" ? baseOptions.headerRowHeight : 30;
  6948. }
  6949. /**
  6950. * @ngdoc property
  6951. * @name rowHeight
  6952. * @propertyOf ui.grid.class:GridOptions
  6953. * @description The height of the row in pixels, Can be passed as integer or string. defaults to 30.
  6954. *
  6955. */
  6956. if (typeof baseOptions.rowHeight === "string") {
  6957. baseOptions.rowHeight = parseInt(baseOptions.rowHeight) || 30;
  6958. }
  6959. else {
  6960. baseOptions.rowHeight = baseOptions.rowHeight || 30;
  6961. }
  6962. /**
  6963. * @ngdoc integer
  6964. * @name minRowsToShow
  6965. * @propertyOf ui.grid.class:GridOptions
  6966. * @description Minimum number of rows to show when the grid doesn't have a defined height. Defaults to "10".
  6967. */
  6968. baseOptions.minRowsToShow = typeof(baseOptions.minRowsToShow) !== "undefined" ? baseOptions.minRowsToShow : 10;
  6969. /**
  6970. * @ngdoc property
  6971. * @name showGridFooter
  6972. * @propertyOf ui.grid.class:GridOptions
  6973. * @description Whether or not to show the footer, defaults to false
  6974. * The footer display Total Rows and Visible Rows (filtered rows)
  6975. */
  6976. baseOptions.showGridFooter = baseOptions.showGridFooter === true;
  6977. /**
  6978. * @ngdoc property
  6979. * @name showColumnFooter
  6980. * @propertyOf ui.grid.class:GridOptions
  6981. * @description Whether or not to show the column footer, defaults to false
  6982. * The column footer displays column aggregates
  6983. */
  6984. baseOptions.showColumnFooter = baseOptions.showColumnFooter === true;
  6985. /**
  6986. * @ngdoc property
  6987. * @name columnFooterHeight
  6988. * @propertyOf ui.grid.class:GridOptions
  6989. * @description The height of the footer rows (column footer and grid footer) in pixels
  6990. *
  6991. */
  6992. baseOptions.columnFooterHeight = typeof(baseOptions.columnFooterHeight) !== "undefined" ? baseOptions.columnFooterHeight : 30;
  6993. baseOptions.gridFooterHeight = typeof(baseOptions.gridFooterHeight) !== "undefined" ? baseOptions.gridFooterHeight : 30;
  6994. baseOptions.columnWidth = typeof(baseOptions.columnWidth) !== "undefined" ? baseOptions.columnWidth : 50;
  6995. /**
  6996. * @ngdoc property
  6997. * @name maxVisibleColumnCount
  6998. * @propertyOf ui.grid.class:GridOptions
  6999. * @description Defaults to 200
  7000. *
  7001. */
  7002. baseOptions.maxVisibleColumnCount = typeof(baseOptions.maxVisibleColumnCount) !== "undefined" ? baseOptions.maxVisibleColumnCount : 200;
  7003. /**
  7004. * @ngdoc property
  7005. * @name virtualizationThreshold
  7006. * @propertyOf ui.grid.class:GridOptions
  7007. * @description Turn virtualization on when number of data elements goes over this number, defaults to 20
  7008. */
  7009. baseOptions.virtualizationThreshold = typeof(baseOptions.virtualizationThreshold) !== "undefined" ? baseOptions.virtualizationThreshold : 20;
  7010. /**
  7011. * @ngdoc property
  7012. * @name columnVirtualizationThreshold
  7013. * @propertyOf ui.grid.class:GridOptions
  7014. * @description Turn virtualization on when number of columns goes over this number, defaults to 10
  7015. */
  7016. baseOptions.columnVirtualizationThreshold = typeof(baseOptions.columnVirtualizationThreshold) !== "undefined" ? baseOptions.columnVirtualizationThreshold : 10;
  7017. /**
  7018. * @ngdoc property
  7019. * @name excessRows
  7020. * @propertyOf ui.grid.class:GridOptions
  7021. * @description Extra rows to to render outside of the viewport, which helps with smoothness of scrolling.
  7022. * Defaults to 4
  7023. */
  7024. baseOptions.excessRows = typeof(baseOptions.excessRows) !== "undefined" ? baseOptions.excessRows : 4;
  7025. /**
  7026. * @ngdoc property
  7027. * @name scrollThreshold
  7028. * @propertyOf ui.grid.class:GridOptions
  7029. * @description Defaults to 4
  7030. */
  7031. baseOptions.scrollThreshold = typeof(baseOptions.scrollThreshold) !== "undefined" ? baseOptions.scrollThreshold : 4;
  7032. /**
  7033. * @ngdoc property
  7034. * @name excessColumns
  7035. * @propertyOf ui.grid.class:GridOptions
  7036. * @description Extra columns to to render outside of the viewport, which helps with smoothness of scrolling.
  7037. * Defaults to 4
  7038. */
  7039. baseOptions.excessColumns = typeof(baseOptions.excessColumns) !== "undefined" ? baseOptions.excessColumns : 4;
  7040. /**
  7041. * @ngdoc property
  7042. * @name horizontalScrollThreshold
  7043. * @propertyOf ui.grid.class:GridOptions
  7044. * @description Defaults to 4
  7045. */
  7046. baseOptions.horizontalScrollThreshold = typeof(baseOptions.horizontalScrollThreshold) !== "undefined" ? baseOptions.horizontalScrollThreshold : 2;
  7047. /**
  7048. * @ngdoc property
  7049. * @name aggregationCalcThrottle
  7050. * @propertyOf ui.grid.class:GridOptions
  7051. * @description Default time in milliseconds to throttle aggregation calcuations, defaults to 500ms
  7052. */
  7053. baseOptions.aggregationCalcThrottle = typeof(baseOptions.aggregationCalcThrottle) !== "undefined" ? baseOptions.aggregationCalcThrottle : 500;
  7054. /**
  7055. * @ngdoc property
  7056. * @name wheelScrollThrottle
  7057. * @propertyOf ui.grid.class:GridOptions
  7058. * @description Default time in milliseconds to throttle scroll events to, defaults to 70ms
  7059. */
  7060. baseOptions.wheelScrollThrottle = typeof(baseOptions.wheelScrollThrottle) !== "undefined" ? baseOptions.wheelScrollThrottle : 70;
  7061. /**
  7062. * @ngdoc property
  7063. * @name scrollDebounce
  7064. * @propertyOf ui.grid.class:GridOptions
  7065. * @description Default time in milliseconds to debounce scroll events, defaults to 300ms
  7066. */
  7067. baseOptions.scrollDebounce = typeof(baseOptions.scrollDebounce) !== "undefined" ? baseOptions.scrollDebounce : 300;
  7068. /**
  7069. * @ngdoc boolean
  7070. * @name enableSorting
  7071. * @propertyOf ui.grid.class:GridOptions
  7072. * @description True by default. When enabled, this setting adds sort
  7073. * widgets to the column headers, allowing sorting of the data for the entire grid.
  7074. * Sorting can then be disabled / enabled on individual columns using the columnDefs,
  7075. * if it set, it will override GridOptions enableSorting setting.
  7076. */
  7077. baseOptions.enableSorting = baseOptions.enableSorting !== false;
  7078. /**
  7079. * @ngdoc boolean
  7080. * @name enableFiltering
  7081. * @propertyOf ui.grid.class:GridOptions
  7082. * @description False by default. When enabled, this setting adds filter
  7083. * boxes to each column header, allowing filtering within the column for the entire grid.
  7084. * Filtering can then be disabled on individual columns using the columnDefs.
  7085. */
  7086. baseOptions.enableFiltering = baseOptions.enableFiltering === true;
  7087. /**
  7088. * @ngdoc boolean
  7089. * @name enableColumnMenus
  7090. * @propertyOf ui.grid.class:GridOptions
  7091. * @description True by default. When enabled, this setting displays a column
  7092. * menu within each column.
  7093. * By default column menu's trigger is hidden before mouse over, but you can always force it to be visible with CSS:
  7094. *
  7095. * <pre>
  7096. * .ui-grid-column-menu-button {
  7097. * display: block;
  7098. * }
  7099. * </pre>
  7100. */
  7101. baseOptions.enableColumnMenus = baseOptions.enableColumnMenus !== false;
  7102. /**
  7103. * @ngdoc boolean
  7104. * @name enableVerticalScrollbar
  7105. * @propertyOf ui.grid.class:GridOptions
  7106. * @description {@link ui.grid.service:uiGridConstants#properties_scrollbars uiGridConstants.scrollbars.ALWAYS} by default.
  7107. * This settings controls the vertical scrollbar for the grid.
  7108. * Supported values: uiGridConstants.scrollbars.ALWAYS, uiGridConstants.scrollbars.NEVER, uiGridConstants.scrollbars.WHEN_NEEDED
  7109. */
  7110. baseOptions.enableVerticalScrollbar = typeof(baseOptions.enableVerticalScrollbar) !== "undefined" ? baseOptions.enableVerticalScrollbar : uiGridConstants.scrollbars.ALWAYS;
  7111. /**
  7112. * @ngdoc boolean
  7113. * @name enableHorizontalScrollbar
  7114. * @propertyOf ui.grid.class:GridOptions
  7115. * @description {@link ui.grid.service:uiGridConstants#properties_scrollbars uiGridConstants.scrollbars.ALWAYS} by default.
  7116. * This settings controls the horizontal scrollbar for the grid.
  7117. * Supported values: uiGridConstants.scrollbars.ALWAYS, uiGridConstants.scrollbars.NEVER, uiGridConstants.scrollbars.WHEN_NEEDED
  7118. */
  7119. baseOptions.enableHorizontalScrollbar = typeof(baseOptions.enableHorizontalScrollbar) !== "undefined" ? baseOptions.enableHorizontalScrollbar : uiGridConstants.scrollbars.ALWAYS;
  7120. /**
  7121. * @ngdoc boolean
  7122. * @name enableMinHeightCheck
  7123. * @propertyOf ui.grid.class:GridOptions
  7124. * @description True by default. When enabled, a newly initialized grid will check to see if it is tall enough to display
  7125. * at least one row of data. If the grid is not tall enough, it will resize the DOM element to display minRowsToShow number
  7126. * of rows.
  7127. */
  7128. baseOptions.enableMinHeightCheck = baseOptions.enableMinHeightCheck !== false;
  7129. /**
  7130. * @ngdoc boolean
  7131. * @name minimumColumnSize
  7132. * @propertyOf ui.grid.class:GridOptions
  7133. * @description Sets the default minimum column width, in other words,
  7134. * it defines the default value for a column minWidth attribute if that is not otherwise specified.
  7135. * Should be a number. Defaults to 30 pixels.
  7136. */
  7137. baseOptions.minimumColumnSize = typeof(baseOptions.minimumColumnSize) !== "undefined" ? baseOptions.minimumColumnSize : 30;
  7138. /**
  7139. * @ngdoc function
  7140. * @name rowEquality
  7141. * @methodOf ui.grid.class:GridOptions
  7142. * @description By default, rows are compared using object equality. This option can be overridden
  7143. * to compare on any data item property or function
  7144. * @param {object} entityA First Data Item to compare
  7145. * @param {object} entityB Second Data Item to compare
  7146. */
  7147. baseOptions.rowEquality = baseOptions.rowEquality || function(entityA, entityB) {
  7148. return entityA === entityB;
  7149. };
  7150. /**
  7151. * @ngdoc string
  7152. * @name headerTemplate
  7153. * @propertyOf ui.grid.class:GridOptions
  7154. * @description Null by default. When provided, this setting uses a custom header
  7155. * template, rather than the default template. Can be set to either the name of a template file:
  7156. * <pre> $scope.gridOptions.headerTemplate = 'header_template.html';</pre>
  7157. * inline html
  7158. * <pre> $scope.gridOptions.headerTemplate = '<div class="ui-grid-top-panel" style="text-align: center">I am a Custom Grid Header</div>'</pre>
  7159. * or the id of a precompiled template (TBD how to use this).
  7160. * </br>Refer to the custom header tutorial for more information.
  7161. * If you want no header at all, you can set to an empty div:
  7162. * <pre> $scope.gridOptions.headerTemplate = '<div></div>';</pre>
  7163. *
  7164. * If you want to only have a static header, then you can set to static content. If
  7165. * you want to tailor the existing column headers, then you should look at the
  7166. * current 'ui-grid-header.html' template in github as your starting point.
  7167. *
  7168. */
  7169. baseOptions.headerTemplate = baseOptions.headerTemplate || null;
  7170. /**
  7171. * @ngdoc string
  7172. * @name footerTemplate
  7173. * @propertyOf ui.grid.class:GridOptions
  7174. * @description (optional) ui-grid/ui-grid-footer by default. This footer shows the per-column
  7175. * aggregation totals.
  7176. * When provided, this setting uses a custom footer template. Can be set to either the name of a template file 'footer_template.html', inline html
  7177. * <pre>'<div class="ui-grid-bottom-panel" style="text-align: center">I am a Custom Grid Footer</div>'</pre>, or the id
  7178. * of a precompiled template (TBD how to use this). Refer to the custom footer tutorial for more information.
  7179. */
  7180. baseOptions.footerTemplate = baseOptions.footerTemplate || 'ui-grid/ui-grid-footer';
  7181. /**
  7182. * @ngdoc string
  7183. * @name gridFooterTemplate
  7184. * @propertyOf ui.grid.class:GridOptions
  7185. * @description (optional) ui-grid/ui-grid-grid-footer by default. This template by default shows the
  7186. * total items at the bottom of the grid, and the selected items if selection is enabled.
  7187. */
  7188. baseOptions.gridFooterTemplate = baseOptions.gridFooterTemplate || 'ui-grid/ui-grid-grid-footer';
  7189. /**
  7190. * @ngdoc string
  7191. * @name rowTemplate
  7192. * @propertyOf ui.grid.class:GridOptions
  7193. * @description 'ui-grid/ui-grid-row' by default. When provided, this setting uses a
  7194. * custom row template. Can be set to either the name of a template file:
  7195. * <pre> $scope.gridOptions.rowTemplate = 'row_template.html';</pre>
  7196. * inline html
  7197. * <pre> $scope.gridOptions.rowTemplate = '<div style="background-color: aquamarine" ng-click="grid.appScope.fnOne(row)" ng-repeat="col in colContainer.renderedColumns track by col.colDef.name" class="ui-grid-cell" ui-grid-cell></div>';</pre>
  7198. * or the id of a precompiled template (TBD how to use this) can be provided.
  7199. * </br>Refer to the custom row template tutorial for more information.
  7200. */
  7201. baseOptions.rowTemplate = baseOptions.rowTemplate || 'ui-grid/ui-grid-row';
  7202. /**
  7203. * @ngdoc string
  7204. * @name gridMenuTemplate
  7205. * @propertyOf ui.grid.class:GridOptions
  7206. * @description 'ui-grid/uiGridMenu' by default. When provided, this setting uses a
  7207. * custom grid menu template.
  7208. */
  7209. baseOptions.gridMenuTemplate = baseOptions.gridMenuTemplate || 'ui-grid/uiGridMenu';
  7210. /**
  7211. * @ngdoc object
  7212. * @name appScopeProvider
  7213. * @propertyOf ui.grid.class:GridOptions
  7214. * @description by default, the parent scope of the ui-grid element will be assigned to grid.appScope
  7215. * this property allows you to assign any reference you want to grid.appScope
  7216. */
  7217. baseOptions.appScopeProvider = baseOptions.appScopeProvider || null;
  7218. return baseOptions;
  7219. }
  7220. };
  7221. }]);
  7222. })();
  7223. (function(){
  7224. angular.module('ui.grid')
  7225. /**
  7226. * @ngdoc function
  7227. * @name ui.grid.class:GridRenderContainer
  7228. * @description The grid has render containers, allowing the ability to have pinned columns. If the grid
  7229. * is right-to-left then there may be a right render container, if left-to-right then there may
  7230. * be a left render container. There is always a body render container.
  7231. * @param {string} name The name of the render container ('body', 'left', or 'right')
  7232. * @param {Grid} grid the grid the render container is in
  7233. * @param {object} options the render container options
  7234. */
  7235. .factory('GridRenderContainer', ['gridUtil', 'uiGridConstants', function(gridUtil, uiGridConstants) {
  7236. function GridRenderContainer(name, grid, options) {
  7237. var self = this;
  7238. // if (gridUtil.type(grid) !== 'Grid') {
  7239. // throw new Error('Grid argument is not a Grid object');
  7240. // }
  7241. self.name = name;
  7242. self.grid = grid;
  7243. // self.rowCache = [];
  7244. // self.columnCache = [];
  7245. self.visibleRowCache = [];
  7246. self.visibleColumnCache = [];
  7247. self.renderedRows = [];
  7248. self.renderedColumns = [];
  7249. self.prevScrollTop = 0;
  7250. self.prevScrolltopPercentage = 0;
  7251. self.prevRowScrollIndex = 0;
  7252. self.prevScrollLeft = 0;
  7253. self.prevScrollleftPercentage = 0;
  7254. self.prevColumnScrollIndex = 0;
  7255. self.columnStyles = '';
  7256. self.viewportAdjusters = [];
  7257. /**
  7258. * @ngdoc boolean
  7259. * @name hasHScrollbar
  7260. * @propertyOf ui.grid.class:GridRenderContainer
  7261. * @description flag to signal that container has a horizontal scrollbar
  7262. */
  7263. self.hasHScrollbar = false;
  7264. /**
  7265. * @ngdoc boolean
  7266. * @name hasVScrollbar
  7267. * @propertyOf ui.grid.class:GridRenderContainer
  7268. * @description flag to signal that container has a vertical scrollbar
  7269. */
  7270. self.hasVScrollbar = false;
  7271. /**
  7272. * @ngdoc boolean
  7273. * @name canvasHeightShouldUpdate
  7274. * @propertyOf ui.grid.class:GridRenderContainer
  7275. * @description flag to signal that container should recalculate the canvas size
  7276. */
  7277. self.canvasHeightShouldUpdate = true;
  7278. /**
  7279. * @ngdoc boolean
  7280. * @name canvasHeight
  7281. * @propertyOf ui.grid.class:GridRenderContainer
  7282. * @description last calculated canvas height value
  7283. */
  7284. self.$$canvasHeight = 0;
  7285. if (options && angular.isObject(options)) {
  7286. angular.extend(self, options);
  7287. }
  7288. grid.registerStyleComputation({
  7289. priority: 5,
  7290. func: function () {
  7291. self.updateColumnWidths();
  7292. return self.columnStyles;
  7293. }
  7294. });
  7295. }
  7296. GridRenderContainer.prototype.reset = function reset() {
  7297. // this.rowCache.length = 0;
  7298. // this.columnCache.length = 0;
  7299. this.visibleColumnCache.length = 0;
  7300. this.visibleRowCache.length = 0;
  7301. this.renderedRows.length = 0;
  7302. this.renderedColumns.length = 0;
  7303. };
  7304. // TODO(c0bra): calculate size?? Should this be in a stackable directive?
  7305. GridRenderContainer.prototype.containsColumn = function (col) {
  7306. return this.visibleColumnCache.indexOf(col) !== -1;
  7307. };
  7308. GridRenderContainer.prototype.minRowsToRender = function minRowsToRender() {
  7309. var self = this;
  7310. var minRows = 0;
  7311. var rowAddedHeight = 0;
  7312. var viewPortHeight = self.getViewportHeight();
  7313. for (var i = self.visibleRowCache.length - 1; rowAddedHeight < viewPortHeight && i >= 0; i--) {
  7314. rowAddedHeight += self.visibleRowCache[i].height;
  7315. minRows++;
  7316. }
  7317. return minRows;
  7318. };
  7319. GridRenderContainer.prototype.minColumnsToRender = function minColumnsToRender() {
  7320. var self = this;
  7321. var viewportWidth = this.getViewportWidth();
  7322. var min = 0;
  7323. var totalWidth = 0;
  7324. for (var i = 0; i < self.visibleColumnCache.length; i++) {
  7325. var col = self.visibleColumnCache[i];
  7326. if (totalWidth < viewportWidth) {
  7327. totalWidth += col.drawnWidth ? col.drawnWidth : 0;
  7328. min++;
  7329. }
  7330. else {
  7331. var currWidth = 0;
  7332. for (var j = i; j >= i - min; j--) {
  7333. currWidth += self.visibleColumnCache[j].drawnWidth ? self.visibleColumnCache[j].drawnWidth : 0;
  7334. }
  7335. if (currWidth < viewportWidth) {
  7336. min++;
  7337. }
  7338. }
  7339. }
  7340. return min;
  7341. };
  7342. GridRenderContainer.prototype.getVisibleRowCount = function getVisibleRowCount() {
  7343. return this.visibleRowCache.length;
  7344. };
  7345. /**
  7346. * @ngdoc function
  7347. * @name registerViewportAdjuster
  7348. * @methodOf ui.grid.class:GridRenderContainer
  7349. * @description Registers an adjuster to the render container's available width or height. Adjusters are used
  7350. * to tell the render container that there is something else consuming space, and to adjust it's size
  7351. * appropriately.
  7352. * @param {function} func the adjuster function we want to register
  7353. */
  7354. GridRenderContainer.prototype.registerViewportAdjuster = function registerViewportAdjuster(func) {
  7355. this.viewportAdjusters.push(func);
  7356. };
  7357. /**
  7358. * @ngdoc function
  7359. * @name removeViewportAdjuster
  7360. * @methodOf ui.grid.class:GridRenderContainer
  7361. * @description Removes an adjuster, should be used when your element is destroyed
  7362. * @param {function} func the adjuster function we want to remove
  7363. */
  7364. GridRenderContainer.prototype.removeViewportAdjuster = function removeViewportAdjuster(func) {
  7365. var idx = this.viewportAdjusters.indexOf(func);
  7366. if (idx > -1) {
  7367. this.viewportAdjusters.splice(idx, 1);
  7368. }
  7369. };
  7370. /**
  7371. * @ngdoc function
  7372. * @name getViewportAdjustment
  7373. * @methodOf ui.grid.class:GridRenderContainer
  7374. * @description Gets the adjustment based on the viewportAdjusters.
  7375. * @returns {object} a hash of { height: x, width: y }. Usually the values will be negative
  7376. */
  7377. GridRenderContainer.prototype.getViewportAdjustment = function getViewportAdjustment() {
  7378. var self = this;
  7379. var adjustment = { height: 0, width: 0 };
  7380. self.viewportAdjusters.forEach(function (func) {
  7381. adjustment = func.call(this, adjustment);
  7382. });
  7383. return adjustment;
  7384. };
  7385. GridRenderContainer.prototype.getMargin = function getMargin(side) {
  7386. var self = this;
  7387. var amount = 0;
  7388. self.viewportAdjusters.forEach(function (func) {
  7389. var adjustment = func.call(this, { height: 0, width: 0 });
  7390. if (adjustment.side && adjustment.side === side) {
  7391. amount += adjustment.width * -1;
  7392. }
  7393. });
  7394. return amount;
  7395. };
  7396. GridRenderContainer.prototype.getViewportHeight = function getViewportHeight() {
  7397. var self = this;
  7398. var headerHeight = (self.headerHeight) ? self.headerHeight : self.grid.headerHeight;
  7399. var viewPortHeight = self.grid.gridHeight - headerHeight - self.grid.footerHeight;
  7400. var adjustment = self.getViewportAdjustment();
  7401. viewPortHeight = viewPortHeight + adjustment.height;
  7402. return viewPortHeight;
  7403. };
  7404. GridRenderContainer.prototype.getViewportWidth = function getViewportWidth() {
  7405. var self = this;
  7406. var viewportWidth = self.grid.gridWidth;
  7407. //if (typeof(self.grid.verticalScrollbarWidth) !== 'undefined' && self.grid.verticalScrollbarWidth !== undefined && self.grid.verticalScrollbarWidth > 0) {
  7408. // viewPortWidth = viewPortWidth - self.grid.verticalScrollbarWidth;
  7409. //}
  7410. // var viewportWidth = 0;\
  7411. // self.visibleColumnCache.forEach(function (column) {
  7412. // viewportWidth += column.drawnWidth;
  7413. // });
  7414. var adjustment = self.getViewportAdjustment();
  7415. viewportWidth = viewportWidth + adjustment.width;
  7416. return viewportWidth;
  7417. };
  7418. GridRenderContainer.prototype.getHeaderViewportWidth = function getHeaderViewportWidth() {
  7419. var self = this;
  7420. var viewportWidth = this.getViewportWidth();
  7421. //if (typeof(self.grid.verticalScrollbarWidth) !== 'undefined' && self.grid.verticalScrollbarWidth !== undefined && self.grid.verticalScrollbarWidth > 0) {
  7422. // viewPortWidth = viewPortWidth + self.grid.verticalScrollbarWidth;
  7423. //}
  7424. // var adjustment = self.getViewportAdjustment();
  7425. // viewPortWidth = viewPortWidth + adjustment.width;
  7426. return viewportWidth;
  7427. };
  7428. /**
  7429. * @ngdoc function
  7430. * @name getCanvasHeight
  7431. * @methodOf ui.grid.class:GridRenderContainer
  7432. * @description Returns the total canvas height. Only recalculates if canvasHeightShouldUpdate = false
  7433. * @returns {number} total height of all the visible rows in the container
  7434. */
  7435. GridRenderContainer.prototype.getCanvasHeight = function getCanvasHeight() {
  7436. var self = this;
  7437. if (!self.canvasHeightShouldUpdate) {
  7438. return self.$$canvasHeight;
  7439. }
  7440. var oldCanvasHeight = self.$$canvasHeight;
  7441. self.$$canvasHeight = 0;
  7442. self.visibleRowCache.forEach(function(row){
  7443. self.$$canvasHeight += row.height;
  7444. });
  7445. self.canvasHeightShouldUpdate = false;
  7446. self.grid.api.core.raise.canvasHeightChanged(oldCanvasHeight, self.$$canvasHeight);
  7447. return self.$$canvasHeight;
  7448. };
  7449. GridRenderContainer.prototype.getVerticalScrollLength = function getVerticalScrollLength() {
  7450. return this.getCanvasHeight() - this.getViewportHeight() + this.grid.scrollbarHeight !== 0 ? this.getCanvasHeight() - this.getViewportHeight() + this.grid.scrollbarHeight : -1;
  7451. };
  7452. GridRenderContainer.prototype.getHorizontalScrollLength = function getHorizontalScrollLength() {
  7453. return this.getCanvasWidth() - this.getViewportWidth() + this.grid.scrollbarWidth !== 0 ? this.getCanvasWidth() - this.getViewportWidth() + this.grid.scrollbarWidth : -1;
  7454. };
  7455. GridRenderContainer.prototype.getCanvasWidth = function getCanvasWidth() {
  7456. var self = this;
  7457. return self.canvasWidth;
  7458. };
  7459. GridRenderContainer.prototype.setRenderedRows = function setRenderedRows(newRows) {
  7460. this.renderedRows.length = newRows.length;
  7461. for (var i = 0; i < newRows.length; i++) {
  7462. this.renderedRows[i] = newRows[i];
  7463. }
  7464. };
  7465. GridRenderContainer.prototype.setRenderedColumns = function setRenderedColumns(newColumns) {
  7466. var self = this;
  7467. // OLD:
  7468. this.renderedColumns.length = newColumns.length;
  7469. for (var i = 0; i < newColumns.length; i++) {
  7470. this.renderedColumns[i] = newColumns[i];
  7471. }
  7472. this.updateColumnOffset();
  7473. };
  7474. GridRenderContainer.prototype.updateColumnOffset = function updateColumnOffset() {
  7475. // Calculate the width of the columns on the left side that are no longer rendered.
  7476. // That will be the offset for the columns as we scroll horizontally.
  7477. var hiddenColumnsWidth = 0;
  7478. for (var i = 0; i < this.currentFirstColumn; i++) {
  7479. hiddenColumnsWidth += this.visibleColumnCache[i].drawnWidth;
  7480. }
  7481. this.columnOffset = hiddenColumnsWidth;
  7482. };
  7483. GridRenderContainer.prototype.scrollVertical = function (newScrollTop) {
  7484. var vertScrollPercentage = -1;
  7485. if (newScrollTop !== this.prevScrollTop) {
  7486. var yDiff = newScrollTop - this.prevScrollTop;
  7487. if (yDiff > 0 ) { this.grid.scrollDirection = uiGridConstants.scrollDirection.DOWN; }
  7488. if (yDiff < 0 ) { this.grid.scrollDirection = uiGridConstants.scrollDirection.UP; }
  7489. var vertScrollLength = this.getVerticalScrollLength();
  7490. vertScrollPercentage = newScrollTop / vertScrollLength;
  7491. // console.log('vert', vertScrollPercentage, newScrollTop, vertScrollLength);
  7492. if (vertScrollPercentage > 1) { vertScrollPercentage = 1; }
  7493. if (vertScrollPercentage < 0) { vertScrollPercentage = 0; }
  7494. this.adjustScrollVertical(newScrollTop, vertScrollPercentage);
  7495. return vertScrollPercentage;
  7496. }
  7497. };
  7498. GridRenderContainer.prototype.scrollHorizontal = function(newScrollLeft){
  7499. var horizScrollPercentage = -1;
  7500. // Handle RTL here
  7501. if (newScrollLeft !== this.prevScrollLeft) {
  7502. var xDiff = newScrollLeft - this.prevScrollLeft;
  7503. if (xDiff > 0) { this.grid.scrollDirection = uiGridConstants.scrollDirection.RIGHT; }
  7504. if (xDiff < 0) { this.grid.scrollDirection = uiGridConstants.scrollDirection.LEFT; }
  7505. var horizScrollLength = this.getHorizontalScrollLength();
  7506. if (horizScrollLength !== 0) {
  7507. horizScrollPercentage = newScrollLeft / horizScrollLength;
  7508. }
  7509. else {
  7510. horizScrollPercentage = 0;
  7511. }
  7512. this.adjustScrollHorizontal(newScrollLeft, horizScrollPercentage);
  7513. return horizScrollPercentage;
  7514. }
  7515. };
  7516. GridRenderContainer.prototype.adjustScrollVertical = function adjustScrollVertical(scrollTop, scrollPercentage, force) {
  7517. if (this.prevScrollTop === scrollTop && !force) {
  7518. return;
  7519. }
  7520. if (typeof(scrollTop) === 'undefined' || scrollTop === undefined || scrollTop === null) {
  7521. scrollTop = (this.getCanvasHeight() - this.getViewportHeight()) * scrollPercentage;
  7522. }
  7523. this.adjustRows(scrollTop, scrollPercentage, false);
  7524. this.prevScrollTop = scrollTop;
  7525. this.prevScrolltopPercentage = scrollPercentage;
  7526. this.grid.queueRefresh();
  7527. };
  7528. GridRenderContainer.prototype.adjustScrollHorizontal = function adjustScrollHorizontal(scrollLeft, scrollPercentage, force) {
  7529. if (this.prevScrollLeft === scrollLeft && !force) {
  7530. return;
  7531. }
  7532. if (typeof(scrollLeft) === 'undefined' || scrollLeft === undefined || scrollLeft === null) {
  7533. scrollLeft = (this.getCanvasWidth() - this.getViewportWidth()) * scrollPercentage;
  7534. }
  7535. this.adjustColumns(scrollLeft, scrollPercentage);
  7536. this.prevScrollLeft = scrollLeft;
  7537. this.prevScrollleftPercentage = scrollPercentage;
  7538. this.grid.queueRefresh();
  7539. };
  7540. GridRenderContainer.prototype.adjustRows = function adjustRows(scrollTop, scrollPercentage, postDataLoaded) {
  7541. var self = this;
  7542. var minRows = self.minRowsToRender();
  7543. var rowCache = self.visibleRowCache;
  7544. var maxRowIndex = rowCache.length - minRows;
  7545. // console.log('scroll%1', scrollPercentage);
  7546. // Calculate the scroll percentage according to the scrollTop location, if no percentage was provided
  7547. if ((typeof(scrollPercentage) === 'undefined' || scrollPercentage === null) && scrollTop) {
  7548. scrollPercentage = scrollTop / self.getVerticalScrollLength();
  7549. }
  7550. var rowIndex = Math.ceil(Math.min(maxRowIndex, maxRowIndex * scrollPercentage));
  7551. // console.log('maxRowIndex / scroll%', maxRowIndex, scrollPercentage, rowIndex);
  7552. // Define a max row index that we can't scroll past
  7553. if (rowIndex > maxRowIndex) {
  7554. rowIndex = maxRowIndex;
  7555. }
  7556. var newRange = [];
  7557. if (rowCache.length > self.grid.options.virtualizationThreshold) {
  7558. if (!(typeof(scrollTop) === 'undefined' || scrollTop === null)) {
  7559. // Have we hit the threshold going down?
  7560. if ( !self.grid.suppressParentScrollDown && self.prevScrollTop < scrollTop && rowIndex < self.prevRowScrollIndex + self.grid.options.scrollThreshold && rowIndex < maxRowIndex) {
  7561. return;
  7562. }
  7563. //Have we hit the threshold going up?
  7564. if ( !self.grid.suppressParentScrollUp && self.prevScrollTop > scrollTop && rowIndex > self.prevRowScrollIndex - self.grid.options.scrollThreshold && rowIndex < maxRowIndex) {
  7565. return;
  7566. }
  7567. }
  7568. var rangeStart = Math.max(0, rowIndex - self.grid.options.excessRows);
  7569. var rangeEnd = Math.min(rowCache.length, rowIndex + minRows + self.grid.options.excessRows);
  7570. newRange = [rangeStart, rangeEnd];
  7571. }
  7572. else {
  7573. var maxLen = self.visibleRowCache.length;
  7574. newRange = [0, Math.max(maxLen, minRows + self.grid.options.excessRows)];
  7575. }
  7576. self.updateViewableRowRange(newRange);
  7577. self.prevRowScrollIndex = rowIndex;
  7578. };
  7579. GridRenderContainer.prototype.adjustColumns = function adjustColumns(scrollLeft, scrollPercentage) {
  7580. var self = this;
  7581. var minCols = self.minColumnsToRender();
  7582. var columnCache = self.visibleColumnCache;
  7583. var maxColumnIndex = columnCache.length - minCols;
  7584. // Calculate the scroll percentage according to the scrollLeft location, if no percentage was provided
  7585. if ((typeof(scrollPercentage) === 'undefined' || scrollPercentage === null) && scrollLeft) {
  7586. scrollPercentage = scrollLeft / self.getHorizontalScrollLength();
  7587. }
  7588. var colIndex = Math.ceil(Math.min(maxColumnIndex, maxColumnIndex * scrollPercentage));
  7589. // Define a max row index that we can't scroll past
  7590. if (colIndex > maxColumnIndex) {
  7591. colIndex = maxColumnIndex;
  7592. }
  7593. var newRange = [];
  7594. if (columnCache.length > self.grid.options.columnVirtualizationThreshold && self.getCanvasWidth() > self.getViewportWidth()) {
  7595. /* Commented the following lines because otherwise the moved column wasn't visible immediately on the new position
  7596. * in the case of many columns with horizontal scroll, one had to scroll left or right and then return in order to see it
  7597. // Have we hit the threshold going down?
  7598. if (self.prevScrollLeft < scrollLeft && colIndex < self.prevColumnScrollIndex + self.grid.options.horizontalScrollThreshold && colIndex < maxColumnIndex) {
  7599. return;
  7600. }
  7601. //Have we hit the threshold going up?
  7602. if (self.prevScrollLeft > scrollLeft && colIndex > self.prevColumnScrollIndex - self.grid.options.horizontalScrollThreshold && colIndex < maxColumnIndex) {
  7603. return;
  7604. }*/
  7605. var rangeStart = Math.max(0, colIndex - self.grid.options.excessColumns);
  7606. var rangeEnd = Math.min(columnCache.length, colIndex + minCols + self.grid.options.excessColumns);
  7607. newRange = [rangeStart, rangeEnd];
  7608. }
  7609. else {
  7610. var maxLen = self.visibleColumnCache.length;
  7611. newRange = [0, Math.max(maxLen, minCols + self.grid.options.excessColumns)];
  7612. }
  7613. self.updateViewableColumnRange(newRange);
  7614. self.prevColumnScrollIndex = colIndex;
  7615. };
  7616. // Method for updating the visible rows
  7617. GridRenderContainer.prototype.updateViewableRowRange = function updateViewableRowRange(renderedRange) {
  7618. // Slice out the range of rows from the data
  7619. // var rowArr = uiGridCtrl.grid.rows.slice(renderedRange[0], renderedRange[1]);
  7620. var rowArr = this.visibleRowCache.slice(renderedRange[0], renderedRange[1]);
  7621. // Define the top-most rendered row
  7622. this.currentTopRow = renderedRange[0];
  7623. this.setRenderedRows(rowArr);
  7624. };
  7625. // Method for updating the visible columns
  7626. GridRenderContainer.prototype.updateViewableColumnRange = function updateViewableColumnRange(renderedRange) {
  7627. // Slice out the range of rows from the data
  7628. // var columnArr = uiGridCtrl.grid.columns.slice(renderedRange[0], renderedRange[1]);
  7629. var columnArr = this.visibleColumnCache.slice(renderedRange[0], renderedRange[1]);
  7630. // Define the left-most rendered columns
  7631. this.currentFirstColumn = renderedRange[0];
  7632. this.setRenderedColumns(columnArr);
  7633. };
  7634. GridRenderContainer.prototype.headerCellWrapperStyle = function () {
  7635. var self = this;
  7636. if (self.currentFirstColumn !== 0) {
  7637. var offset = self.columnOffset;
  7638. if (self.grid.isRTL()) {
  7639. return { 'margin-right': offset + 'px' };
  7640. }
  7641. else {
  7642. return { 'margin-left': offset + 'px' };
  7643. }
  7644. }
  7645. return null;
  7646. };
  7647. /**
  7648. * @ngdoc boolean
  7649. * @name updateColumnWidths
  7650. * @propertyOf ui.grid.class:GridRenderContainer
  7651. * @description Determine the appropriate column width of each column across all render containers.
  7652. *
  7653. * Column width is easy when each column has a specified width. When columns are variable width (i.e.
  7654. * have an * or % of the viewport) then we try to calculate so that things fit in. The problem is that
  7655. * we have multiple render containers, and we don't want one render container to just take the whole viewport
  7656. * when it doesn't need to - we want things to balance out across the render containers.
  7657. *
  7658. * To do this, we use this method to calculate all the renderContainers, recognising that in a given render
  7659. * cycle it'll get called once per render container, so it needs to return the same values each time.
  7660. *
  7661. * The constraints on this method are therefore:
  7662. * - must return the same value when called multiple times, to do this it needs to rely on properties of the
  7663. * columns, but not properties that change when this is called (so it shouldn't rely on drawnWidth)
  7664. *
  7665. * The general logic of this method is:
  7666. * - calculate our total available width
  7667. * - look at all the columns across all render containers, and work out which have widths and which have
  7668. * constraints such as % or * or something else
  7669. * - for those with *, count the total number of * we see and add it onto a running total, add this column to an * array
  7670. * - for those with a %, allocate the % as a percentage of the viewport, having consideration of min and max
  7671. * - for those with manual width (in pixels) we set the drawnWidth to the specified width
  7672. * - we end up with an asterisks array still to process
  7673. * - we look at our remaining width. If it's greater than zero, we divide it up among the asterisk columns, then process
  7674. * them for min and max width constraints
  7675. * - if it's zero or less, we set the asterisk columns to their minimum widths
  7676. * - we use parseInt quite a bit, as we try to make all our column widths integers
  7677. */
  7678. GridRenderContainer.prototype.updateColumnWidths = function () {
  7679. var self = this;
  7680. var asterisksArray = [],
  7681. asteriskNum = 0,
  7682. usedWidthSum = 0,
  7683. ret = '',
  7684. pinRightColumn = false,
  7685. fixedNumberArray = [],
  7686. percentageArray = [],
  7687. totalPercentage = 0;
  7688. // Get the width of the viewport
  7689. var availableWidth = self.grid.getViewportWidth() - self.grid.scrollbarWidth;
  7690. // get all the columns across all render containers, we have to calculate them all or one render container
  7691. // could consume the whole viewport
  7692. var columnCache = [];
  7693. angular.forEach(self.grid.renderContainers, function (container) {
  7694. columnCache = columnCache.concat(container.visibleColumnCache);
  7695. });
  7696. // look at each column, process any manual values or %, put the * into an array to look at later
  7697. columnCache.forEach(function (column) {
  7698. var width = 0;
  7699. // Skip hidden columns
  7700. if (!column.visible) { return; }
  7701. if (pinRightColumn) {
  7702. availableWidth += self.grid.scrollbarWidth;
  7703. }
  7704. if (!pinRightColumn && column.colDef.pinnedRight) {
  7705. pinRightColumn = true;
  7706. }
  7707. if (angular.isNumber(column.width)) {
  7708. // pixel width, set to this value
  7709. width = parseInt(column.width, 10);
  7710. usedWidthSum = usedWidthSum + width;
  7711. column.drawnWidth = width;
  7712. fixedNumberArray.push(column);
  7713. } else if (gridUtil.endsWith(column.width, '%')) {
  7714. // percentage width, set to percentage of the viewport
  7715. // round down to int - some browsers don't play nice with float maxWidth
  7716. var percentageIntegerValue = parseInt(column.width.replace(/%/g, ''), 10);
  7717. width = parseInt(percentageIntegerValue / 100 * availableWidth);
  7718. if (width > column.maxWidth) {
  7719. width = column.maxWidth;
  7720. }
  7721. if (width < column.minWidth) {
  7722. width = column.minWidth;
  7723. }
  7724. usedWidthSum = usedWidthSum + width;
  7725. column.drawnWidth = width;
  7726. totalPercentage = totalPercentage + percentageIntegerValue;
  7727. percentageArray.push(column);
  7728. } else if (angular.isString(column.width) && column.width.indexOf('*') !== -1) {
  7729. // is an asterisk column, the gridColumn already checked the string consists only of '****'
  7730. asteriskNum = asteriskNum + column.width.length;
  7731. asterisksArray.push(column);
  7732. }
  7733. });
  7734. // Get the remaining width (available width subtracted by the used widths sum)
  7735. var remainingWidth = availableWidth - usedWidthSum;
  7736. if (asterisksArray.length > 0) {
  7737. // the width that each asterisk value would be assigned (this can be negative)
  7738. var asteriskVal = remainingWidth / asteriskNum;
  7739. asterisksArray.forEach(function (column) {
  7740. var width = parseInt(column.width.length * asteriskVal, 10);
  7741. if (width > column.maxWidth) {
  7742. width = column.maxWidth;
  7743. }
  7744. if (width < column.minWidth) {
  7745. width = column.minWidth;
  7746. }
  7747. usedWidthSum = usedWidthSum + width;
  7748. column.drawnWidth = width;
  7749. });
  7750. }
  7751. // If there are no columns with asterisk widths then check if there are any with % widths and
  7752. // use them as a fallback for adjusting column widths up or down if we have remaining grid width
  7753. // or need to claw some width back
  7754. var variableWidthColumnArray;
  7755. if (asterisksArray.length > 0) {
  7756. variableWidthColumnArray = asterisksArray;
  7757. } else if (percentageArray.length > 0 && fixedNumberArray.length === 0 && totalPercentage === 100) {
  7758. variableWidthColumnArray = percentageArray;
  7759. }
  7760. if (!angular.isUndefined(variableWidthColumnArray)) {
  7761. // If the grid width didn't divide evenly into the column widths and we have pixels left over, or our
  7762. // calculated widths would have the grid narrower than the available space,
  7763. // dole the remainder out one by one to make everything fit
  7764. var processColumnUpwards = function (column) {
  7765. if (column.drawnWidth < column.maxWidth && leftoverWidth > 0) {
  7766. column.drawnWidth++;
  7767. usedWidthSum++;
  7768. leftoverWidth--;
  7769. columnsToChange = true;
  7770. }
  7771. };
  7772. var leftoverWidth = availableWidth - usedWidthSum;
  7773. var columnsToChange = true;
  7774. while (leftoverWidth > 0 && columnsToChange) {
  7775. columnsToChange = false;
  7776. variableWidthColumnArray.forEach(processColumnUpwards);
  7777. }
  7778. // We can end up with too much width even though some columns aren't at their max width, in this situation
  7779. // we can trim the columns a little
  7780. var processColumnDownwards = function (column) {
  7781. if (column.drawnWidth > column.minWidth && excessWidth > 0) {
  7782. column.drawnWidth--;
  7783. usedWidthSum--;
  7784. excessWidth--;
  7785. columnsToChange = true;
  7786. }
  7787. };
  7788. var excessWidth = usedWidthSum - availableWidth;
  7789. columnsToChange = true;
  7790. while (excessWidth > 0 && columnsToChange) {
  7791. columnsToChange = false;
  7792. variableWidthColumnArray.forEach(processColumnDownwards);
  7793. }
  7794. }
  7795. // all that was across all the renderContainers, now we need to work out what that calculation decided for
  7796. // our renderContainer
  7797. var canvasWidth = 0;
  7798. self.visibleColumnCache.forEach(function(column){
  7799. if ( column.visible ){
  7800. canvasWidth = canvasWidth + column.drawnWidth;
  7801. }
  7802. });
  7803. // Build the CSS
  7804. columnCache.forEach(function (column) {
  7805. ret = ret + column.getColClassDefinition();
  7806. });
  7807. self.canvasWidth = canvasWidth;
  7808. // Return the styles back to buildStyles which pops them into the `customStyles` scope variable
  7809. // return ret;
  7810. // Set this render container's column styles so they can be used in style computation
  7811. this.columnStyles = ret;
  7812. };
  7813. GridRenderContainer.prototype.needsHScrollbarPlaceholder = function () {
  7814. var self = this,
  7815. containerBody;
  7816. if (self.name === 'left' || self.name === 'right' && !this.hasHScrollbar && !this.grid.disableScrolling) {
  7817. if (self.grid.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.ALWAYS) {
  7818. return true;
  7819. }
  7820. containerBody = this.grid.element[0].querySelector('.ui-grid-render-container-body .ui-grid-viewport');
  7821. return containerBody.scrollWidth > containerBody.offsetWidth;
  7822. }
  7823. return false;
  7824. };
  7825. GridRenderContainer.prototype.getViewportStyle = function () {
  7826. var self = this;
  7827. var styles = {};
  7828. var scrollbarVisibility = {};
  7829. scrollbarVisibility[uiGridConstants.scrollbars.ALWAYS] = 'scroll';
  7830. scrollbarVisibility[uiGridConstants.scrollbars.WHEN_NEEDED] = 'auto';
  7831. self.hasHScrollbar = false;
  7832. self.hasVScrollbar = false;
  7833. if (self.grid.disableScrolling) {
  7834. styles['overflow-x'] = 'hidden';
  7835. styles['overflow-y'] = 'hidden';
  7836. return styles;
  7837. }
  7838. if (self.name === 'body') {
  7839. self.hasHScrollbar = self.grid.options.enableHorizontalScrollbar !== uiGridConstants.scrollbars.NEVER;
  7840. if (!self.grid.isRTL()) {
  7841. if (!self.grid.hasRightContainerColumns()) {
  7842. self.hasVScrollbar = self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER;
  7843. }
  7844. }
  7845. else {
  7846. if (!self.grid.hasLeftContainerColumns()) {
  7847. self.hasVScrollbar = self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER;
  7848. }
  7849. }
  7850. }
  7851. else if (self.name === 'left') {
  7852. self.hasVScrollbar = self.grid.isRTL() ? self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER : false;
  7853. }
  7854. else {
  7855. self.hasVScrollbar = !self.grid.isRTL() ? self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER : false;
  7856. }
  7857. styles['overflow-x'] = self.hasHScrollbar ? scrollbarVisibility[self.grid.options.enableHorizontalScrollbar] : 'hidden';
  7858. styles['overflow-y'] = self.hasVScrollbar ? scrollbarVisibility[self.grid.options.enableVerticalScrollbar] : 'hidden';
  7859. return styles;
  7860. };
  7861. return GridRenderContainer;
  7862. }]);
  7863. })();
  7864. (function(){
  7865. angular.module('ui.grid')
  7866. .factory('GridRow', ['gridUtil', 'uiGridConstants', function(gridUtil, uiGridConstants) {
  7867. /**
  7868. * @class GridRow
  7869. * @ngdoc function
  7870. * @name ui.grid.class:GridRow
  7871. * @description GridRow is the viewModel for one logical row on the grid. A grid Row is not necessarily a one-to-one
  7872. * relation to gridOptions.data.
  7873. * @param {object} entity the array item from GridOptions.data
  7874. * @param {number} index the current position of the row in the array
  7875. * @param {Grid} grid reference to the parent grid
  7876. */
  7877. function GridRow(entity, index, grid) {
  7878. /**
  7879. * @ngdoc object
  7880. * @name grid
  7881. * @propertyOf ui.grid.class:GridRow
  7882. * @description A reference back to the grid
  7883. */
  7884. this.grid = grid;
  7885. /**
  7886. * @ngdoc object
  7887. * @name entity
  7888. * @propertyOf ui.grid.class:GridRow
  7889. * @description A reference to an item in gridOptions.data[]
  7890. */
  7891. this.entity = entity;
  7892. /**
  7893. * @ngdoc object
  7894. * @name uid
  7895. * @propertyOf ui.grid.class:GridRow
  7896. * @description UniqueId of row
  7897. */
  7898. this.uid = gridUtil.nextUid();
  7899. /**
  7900. * @ngdoc object
  7901. * @name visible
  7902. * @propertyOf ui.grid.class:GridRow
  7903. * @description If true, the row will be rendered
  7904. */
  7905. // Default to true
  7906. this.visible = true;
  7907. /**
  7908. * @ngdoc object
  7909. * @name isSelected
  7910. * @propertyOf ui.grid.class:GridRow
  7911. * @description Marks if the row has been selected
  7912. */
  7913. // Default to false
  7914. this.isSelected = false;
  7915. this.$$height = grid.options.rowHeight;
  7916. }
  7917. /**
  7918. * @ngdoc object
  7919. * @name height
  7920. * @propertyOf ui.grid.class:GridRow
  7921. * @description height of each individual row. changing the height will flag all
  7922. * row renderContainers to recalculate their canvas height
  7923. */
  7924. Object.defineProperty(GridRow.prototype, 'height', {
  7925. get: function() {
  7926. return this.$$height;
  7927. },
  7928. set: function(height) {
  7929. if (height !== this.$$height) {
  7930. this.grid.updateCanvasHeight();
  7931. this.$$height = height;
  7932. }
  7933. }
  7934. });
  7935. /**
  7936. * @ngdoc function
  7937. * @name getQualifiedColField
  7938. * @methodOf ui.grid.class:GridRow
  7939. * @description returns the qualified field name as it exists on scope
  7940. * ie: row.entity.fieldA
  7941. * @param {GridColumn} col column instance
  7942. * @returns {string} resulting name that can be evaluated on scope
  7943. */
  7944. GridRow.prototype.getQualifiedColField = function(col) {
  7945. return 'row.' + this.getEntityQualifiedColField(col);
  7946. };
  7947. /**
  7948. * @ngdoc function
  7949. * @name getEntityQualifiedColField
  7950. * @methodOf ui.grid.class:GridRow
  7951. * @description returns the qualified field name minus the row path
  7952. * ie: entity.fieldA
  7953. * @param {GridColumn} col column instance
  7954. * @returns {string} resulting name that can be evaluated against a row
  7955. */
  7956. GridRow.prototype.getEntityQualifiedColField = function(col) {
  7957. var base = 'entity';
  7958. if ( col.field === uiGridConstants.ENTITY_BINDING ) {
  7959. return base;
  7960. }
  7961. return gridUtil.preEval(base + '.' + col.field);
  7962. };
  7963. /**
  7964. * @ngdoc function
  7965. * @name setRowInvisible
  7966. * @methodOf ui.grid.class:GridRow
  7967. * @description Sets an override on the row that forces it to always
  7968. * be invisible. Emits the rowsVisibleChanged event if it changed the row visibility.
  7969. *
  7970. * This method can be called from the api, passing in the gridRow we want
  7971. * altered. It should really work by calling gridRow.setRowInvisible, but that's
  7972. * not the way I coded it, and too late to change now. Changed to just call
  7973. * the internal function row.setThisRowInvisible().
  7974. *
  7975. * @param {GridRow} row the row we want to set to invisible
  7976. *
  7977. */
  7978. GridRow.prototype.setRowInvisible = function ( row ) {
  7979. if (row && row.setThisRowInvisible){
  7980. row.setThisRowInvisible( 'user' );
  7981. }
  7982. };
  7983. /**
  7984. * @ngdoc function
  7985. * @name clearRowInvisible
  7986. * @methodOf ui.grid.class:GridRow
  7987. * @description Clears an override on the row that forces it to always
  7988. * be invisible. Emits the rowsVisibleChanged event if it changed the row visibility.
  7989. *
  7990. * This method can be called from the api, passing in the gridRow we want
  7991. * altered. It should really work by calling gridRow.clearRowInvisible, but that's
  7992. * not the way I coded it, and too late to change now. Changed to just call
  7993. * the internal function row.clearThisRowInvisible().
  7994. *
  7995. * @param {GridRow} row the row we want to clear the invisible flag
  7996. *
  7997. */
  7998. GridRow.prototype.clearRowInvisible = function ( row ) {
  7999. if (row && row.clearThisRowInvisible){
  8000. row.clearThisRowInvisible( 'user' );
  8001. }
  8002. };
  8003. /**
  8004. * @ngdoc function
  8005. * @name setThisRowInvisible
  8006. * @methodOf ui.grid.class:GridRow
  8007. * @description Sets an override on the row that forces it to always
  8008. * be invisible. Emits the rowsVisibleChanged event if it changed the row visibility
  8009. *
  8010. * @param {string} reason the reason (usually the module) for the row to be invisible.
  8011. * E.g. grouping, user, filter
  8012. * @param {boolean} fromRowsProcessor whether we were called from a rowsProcessor, passed through to evaluateRowVisibility
  8013. */
  8014. GridRow.prototype.setThisRowInvisible = function ( reason, fromRowsProcessor ) {
  8015. if ( !this.invisibleReason ){
  8016. this.invisibleReason = {};
  8017. }
  8018. this.invisibleReason[reason] = true;
  8019. this.evaluateRowVisibility( fromRowsProcessor);
  8020. };
  8021. /**
  8022. * @ngdoc function
  8023. * @name clearRowInvisible
  8024. * @methodOf ui.grid.class:GridRow
  8025. * @description Clears any override on the row visibility, returning it
  8026. * to normal visibility calculations. Emits the rowsVisibleChanged
  8027. * event
  8028. *
  8029. * @param {string} reason the reason (usually the module) for the row to be invisible.
  8030. * E.g. grouping, user, filter
  8031. * @param {boolean} fromRowsProcessor whether we were called from a rowsProcessor, passed through to evaluateRowVisibility
  8032. */
  8033. GridRow.prototype.clearThisRowInvisible = function ( reason, fromRowsProcessor ) {
  8034. if (typeof(this.invisibleReason) !== 'undefined' ) {
  8035. delete this.invisibleReason[reason];
  8036. }
  8037. this.evaluateRowVisibility( fromRowsProcessor );
  8038. };
  8039. /**
  8040. * @ngdoc function
  8041. * @name evaluateRowVisibility
  8042. * @methodOf ui.grid.class:GridRow
  8043. * @description Determines whether the row should be visible based on invisibleReason,
  8044. * and if it changes the row visibility, then emits the rowsVisibleChanged event.
  8045. *
  8046. * Queues a grid refresh, but doesn't call it directly to avoid hitting lots of grid refreshes.
  8047. * @param {boolean} fromRowProcessor if true, then it won't raise events or queue the refresh, the
  8048. * row processor does that already
  8049. */
  8050. GridRow.prototype.evaluateRowVisibility = function ( fromRowProcessor ) {
  8051. var newVisibility = true;
  8052. if ( typeof(this.invisibleReason) !== 'undefined' ){
  8053. angular.forEach(this.invisibleReason, function( value, key ){
  8054. if ( value ){
  8055. newVisibility = false;
  8056. }
  8057. });
  8058. }
  8059. if ( typeof(this.visible) === 'undefined' || this.visible !== newVisibility ){
  8060. this.visible = newVisibility;
  8061. if ( !fromRowProcessor ){
  8062. this.grid.queueGridRefresh();
  8063. this.grid.api.core.raise.rowsVisibleChanged(this);
  8064. }
  8065. }
  8066. };
  8067. return GridRow;
  8068. }]);
  8069. })();
  8070. (function(){
  8071. 'use strict';
  8072. /**
  8073. * @ngdoc object
  8074. * @name ui.grid.class:GridRowColumn
  8075. * @param {GridRow} row The row for this pair
  8076. * @param {GridColumn} column The column for this pair
  8077. * @description A row and column pair that represents the intersection of these two entities.
  8078. * Must be instantiated as a constructor using the `new` keyword.
  8079. */
  8080. angular.module('ui.grid')
  8081. .factory('GridRowColumn', ['$parse', '$filter',
  8082. function GridRowColumnFactory($parse, $filter){
  8083. var GridRowColumn = function GridRowColumn(row, col) {
  8084. if ( !(this instanceof GridRowColumn)){
  8085. throw "Using GridRowColumn as a function insead of as a constructor. Must be called with `new` keyword";
  8086. }
  8087. /**
  8088. * @ngdoc object
  8089. * @name row
  8090. * @propertyOf ui.grid.class:GridRowColumn
  8091. * @description {@link ui.grid.class:GridRow }
  8092. */
  8093. this.row = row;
  8094. /**
  8095. * @ngdoc object
  8096. * @name col
  8097. * @propertyOf ui.grid.class:GridRowColumn
  8098. * @description {@link ui.grid.class:GridColumn }
  8099. */
  8100. this.col = col;
  8101. };
  8102. /**
  8103. * @ngdoc function
  8104. * @name getIntersectionValueRaw
  8105. * @methodOf ui.grid.class:GridRowColumn
  8106. * @description Gets the intersection of where the row and column meet.
  8107. * @returns {String|Number|Object} The value from the grid data that this GridRowColumn points too.
  8108. * If the column has a cellFilter this will NOT return the filtered value.
  8109. */
  8110. GridRowColumn.prototype.getIntersectionValueRaw = function(){
  8111. var getter = $parse(this.row.getEntityQualifiedColField(this.col));
  8112. var context = this.row;
  8113. return getter(context);
  8114. };
  8115. return GridRowColumn;
  8116. }
  8117. ]);
  8118. })();
  8119. (function () {
  8120. angular.module('ui.grid')
  8121. .factory('ScrollEvent', ['gridUtil', function (gridUtil) {
  8122. /**
  8123. * @ngdoc function
  8124. * @name ui.grid.class:ScrollEvent
  8125. * @description Model for all scrollEvents
  8126. * @param {Grid} grid that owns the scroll event
  8127. * @param {GridRenderContainer} sourceRowContainer that owns the scroll event. Can be null
  8128. * @param {GridRenderContainer} sourceColContainer that owns the scroll event. Can be null
  8129. * @param {string} source the source of the event - from uiGridConstants.scrollEventSources or a string value of directive/service/factory.functionName
  8130. */
  8131. function ScrollEvent(grid, sourceRowContainer, sourceColContainer, source) {
  8132. var self = this;
  8133. if (!grid) {
  8134. throw new Error("grid argument is required");
  8135. }
  8136. /**
  8137. * @ngdoc object
  8138. * @name grid
  8139. * @propertyOf ui.grid.class:ScrollEvent
  8140. * @description A reference back to the grid
  8141. */
  8142. self.grid = grid;
  8143. /**
  8144. * @ngdoc object
  8145. * @name source
  8146. * @propertyOf ui.grid.class:ScrollEvent
  8147. * @description the source of the scroll event. limited to values from uiGridConstants.scrollEventSources
  8148. */
  8149. self.source = source;
  8150. /**
  8151. * @ngdoc object
  8152. * @name noDelay
  8153. * @propertyOf ui.grid.class:ScrollEvent
  8154. * @description most scroll events from the mouse or trackpad require delay to operate properly
  8155. * set to false to eliminate delay. Useful for scroll events that the grid causes, such as scrolling to make a row visible.
  8156. */
  8157. self.withDelay = true;
  8158. self.sourceRowContainer = sourceRowContainer;
  8159. self.sourceColContainer = sourceColContainer;
  8160. self.newScrollLeft = null;
  8161. self.newScrollTop = null;
  8162. self.x = null;
  8163. self.y = null;
  8164. self.verticalScrollLength = -9999999;
  8165. self.horizontalScrollLength = -999999;
  8166. /**
  8167. * @ngdoc function
  8168. * @name fireThrottledScrollingEvent
  8169. * @methodOf ui.grid.class:ScrollEvent
  8170. * @description fires a throttled event using grid.api.core.raise.scrollEvent
  8171. */
  8172. self.fireThrottledScrollingEvent = gridUtil.throttle(function(sourceContainerId) {
  8173. self.grid.scrollContainers(sourceContainerId, self);
  8174. }, self.grid.options.wheelScrollThrottle, {trailing: true});
  8175. }
  8176. /**
  8177. * @ngdoc function
  8178. * @name getNewScrollLeft
  8179. * @methodOf ui.grid.class:ScrollEvent
  8180. * @description returns newScrollLeft property if available; calculates a new value if it isn't
  8181. */
  8182. ScrollEvent.prototype.getNewScrollLeft = function(colContainer, viewport){
  8183. var self = this;
  8184. if (!self.newScrollLeft){
  8185. var scrollWidth = (colContainer.getCanvasWidth() - colContainer.getViewportWidth());
  8186. var oldScrollLeft = gridUtil.normalizeScrollLeft(viewport, self.grid);
  8187. var scrollXPercentage;
  8188. if (typeof(self.x.percentage) !== 'undefined' && self.x.percentage !== undefined) {
  8189. scrollXPercentage = self.x.percentage;
  8190. }
  8191. else if (typeof(self.x.pixels) !== 'undefined' && self.x.pixels !== undefined) {
  8192. scrollXPercentage = self.x.percentage = (oldScrollLeft + self.x.pixels) / scrollWidth;
  8193. }
  8194. else {
  8195. throw new Error("No percentage or pixel value provided for scroll event X axis");
  8196. }
  8197. return Math.max(0, scrollXPercentage * scrollWidth);
  8198. }
  8199. return self.newScrollLeft;
  8200. };
  8201. /**
  8202. * @ngdoc function
  8203. * @name getNewScrollTop
  8204. * @methodOf ui.grid.class:ScrollEvent
  8205. * @description returns newScrollTop property if available; calculates a new value if it isn't
  8206. */
  8207. ScrollEvent.prototype.getNewScrollTop = function(rowContainer, viewport){
  8208. var self = this;
  8209. if (!self.newScrollTop){
  8210. var scrollLength = rowContainer.getVerticalScrollLength();
  8211. var oldScrollTop = viewport[0].scrollTop;
  8212. var scrollYPercentage;
  8213. if (typeof(self.y.percentage) !== 'undefined' && self.y.percentage !== undefined) {
  8214. scrollYPercentage = self.y.percentage;
  8215. }
  8216. else if (typeof(self.y.pixels) !== 'undefined' && self.y.pixels !== undefined) {
  8217. scrollYPercentage = self.y.percentage = (oldScrollTop + self.y.pixels) / scrollLength;
  8218. }
  8219. else {
  8220. throw new Error("No percentage or pixel value provided for scroll event Y axis");
  8221. }
  8222. return Math.max(0, scrollYPercentage * scrollLength);
  8223. }
  8224. return self.newScrollTop;
  8225. };
  8226. ScrollEvent.prototype.atTop = function(scrollTop) {
  8227. return (this.y && (this.y.percentage === 0 || this.verticalScrollLength < 0) && scrollTop === 0);
  8228. };
  8229. ScrollEvent.prototype.atBottom = function(scrollTop) {
  8230. return (this.y && (this.y.percentage === 1 || this.verticalScrollLength === 0) && scrollTop > 0);
  8231. };
  8232. ScrollEvent.prototype.atLeft = function(scrollLeft) {
  8233. return (this.x && (this.x.percentage === 0 || this.horizontalScrollLength < 0) && scrollLeft === 0);
  8234. };
  8235. ScrollEvent.prototype.atRight = function(scrollLeft) {
  8236. return (this.x && (this.x.percentage === 1 || this.horizontalScrollLength ===0) && scrollLeft > 0);
  8237. };
  8238. ScrollEvent.Sources = {
  8239. ViewPortScroll: 'ViewPortScroll',
  8240. RenderContainerMouseWheel: 'RenderContainerMouseWheel',
  8241. RenderContainerTouchMove: 'RenderContainerTouchMove',
  8242. Other: 99
  8243. };
  8244. return ScrollEvent;
  8245. }]);
  8246. })();
  8247. (function () {
  8248. 'use strict';
  8249. /**
  8250. * @ngdoc object
  8251. * @name ui.grid.service:gridClassFactory
  8252. *
  8253. * @description factory to return dom specific instances of a grid
  8254. *
  8255. */
  8256. angular.module('ui.grid').service('gridClassFactory', ['gridUtil', '$q', '$compile', '$templateCache', 'uiGridConstants', 'Grid', 'GridColumn', 'GridRow',
  8257. function (gridUtil, $q, $compile, $templateCache, uiGridConstants, Grid, GridColumn, GridRow) {
  8258. var service = {
  8259. /**
  8260. * @ngdoc method
  8261. * @name createGrid
  8262. * @methodOf ui.grid.service:gridClassFactory
  8263. * @description Creates a new grid instance. Each instance will have a unique id
  8264. * @param {object} options An object map of options to pass into the created grid instance.
  8265. * @returns {Grid} grid
  8266. */
  8267. createGrid : function(options) {
  8268. options = (typeof(options) !== 'undefined') ? options : {};
  8269. options.id = gridUtil.newId();
  8270. var grid = new Grid(options);
  8271. // NOTE/TODO: rowTemplate should always be defined...
  8272. if (grid.options.rowTemplate) {
  8273. var rowTemplateFnPromise = $q.defer();
  8274. grid.getRowTemplateFn = rowTemplateFnPromise.promise;
  8275. gridUtil.getTemplate(grid.options.rowTemplate)
  8276. .then(
  8277. function (template) {
  8278. var rowTemplateFn = $compile(template);
  8279. rowTemplateFnPromise.resolve(rowTemplateFn);
  8280. },
  8281. function (res) {
  8282. // Todo handle response error here?
  8283. throw new Error("Couldn't fetch/use row template '" + grid.options.rowTemplate + "'");
  8284. }).catch(angular.noop);
  8285. }
  8286. grid.registerColumnBuilder(service.defaultColumnBuilder);
  8287. // Row builder for custom row templates
  8288. grid.registerRowBuilder(service.rowTemplateAssigner);
  8289. // Reset all rows to visible initially
  8290. grid.registerRowsProcessor(function allRowsVisible(rows) {
  8291. rows.forEach(function (row) {
  8292. row.evaluateRowVisibility( true );
  8293. });
  8294. return rows;
  8295. }, 50);
  8296. grid.registerColumnsProcessor(function applyColumnVisibility(columns) {
  8297. columns.forEach(function (column) {
  8298. column.visible = angular.isDefined(column.colDef.visible) ? column.colDef.visible : true;
  8299. });
  8300. return columns;
  8301. }, 50);
  8302. grid.registerRowsProcessor(grid.searchRows, 100);
  8303. // Register the default row processor, it sorts rows by selected columns
  8304. if (grid.options.externalSort && angular.isFunction(grid.options.externalSort)) {
  8305. grid.registerRowsProcessor(grid.options.externalSort, 200);
  8306. }
  8307. else {
  8308. grid.registerRowsProcessor(grid.sortByColumn, 200);
  8309. }
  8310. return grid;
  8311. },
  8312. /**
  8313. * @ngdoc function
  8314. * @name defaultColumnBuilder
  8315. * @methodOf ui.grid.service:gridClassFactory
  8316. * @description Processes designTime column definitions and applies them to col for the
  8317. * core grid features
  8318. * @param {object} colDef reference to column definition
  8319. * @param {GridColumn} col reference to gridCol
  8320. * @param {object} gridOptions reference to grid options
  8321. */
  8322. defaultColumnBuilder: function (colDef, col, gridOptions) {
  8323. var templateGetPromises = [];
  8324. // Abstracts the standard template processing we do for every template type.
  8325. var processTemplate = function( templateType, providedType, defaultTemplate, filterType, tooltipType ) {
  8326. if ( !colDef[templateType] ){
  8327. col[providedType] = defaultTemplate;
  8328. } else {
  8329. col[providedType] = colDef[templateType];
  8330. }
  8331. var templatePromise = gridUtil.getTemplate(col[providedType])
  8332. .then(
  8333. function (template) {
  8334. if ( angular.isFunction(template) ) { template = template(); }
  8335. var tooltipCall = ( tooltipType === 'cellTooltip' ) ? 'col.cellTooltip(row,col)' : 'col.headerTooltip(col)';
  8336. if ( tooltipType && col[tooltipType] === false ){
  8337. template = template.replace(uiGridConstants.TOOLTIP, '');
  8338. } else if ( tooltipType && col[tooltipType] ){
  8339. template = template.replace(uiGridConstants.TOOLTIP, 'title="{{' + tooltipCall + ' CUSTOM_FILTERS }}"');
  8340. }
  8341. if ( filterType ){
  8342. col[templateType] = template.replace(uiGridConstants.CUSTOM_FILTERS, function() {
  8343. return col[filterType] ? "|" + col[filterType] : "";
  8344. });
  8345. } else {
  8346. col[templateType] = template;
  8347. }
  8348. },
  8349. function (res) {
  8350. throw new Error("Couldn't fetch/use colDef." + templateType + " '" + colDef[templateType] + "'");
  8351. }).catch(angular.noop);
  8352. templateGetPromises.push(templatePromise);
  8353. return templatePromise;
  8354. };
  8355. /**
  8356. * @ngdoc property
  8357. * @name cellTemplate
  8358. * @propertyOf ui.grid.class:GridOptions.columnDef
  8359. * @description a custom template for each cell in this column. The default
  8360. * is ui-grid/uiGridCell. If you are using the cellNav feature, this template
  8361. * must contain a div that can receive focus.
  8362. *
  8363. */
  8364. col.cellTemplatePromise = processTemplate( 'cellTemplate', 'providedCellTemplate', 'ui-grid/uiGridCell', 'cellFilter', 'cellTooltip' );
  8365. /**
  8366. * @ngdoc property
  8367. * @name headerCellTemplate
  8368. * @propertyOf ui.grid.class:GridOptions.columnDef
  8369. * @description a custom template for the header for this column. The default
  8370. * is ui-grid/uiGridHeaderCell
  8371. *
  8372. */
  8373. col.headerCellTemplatePromise = processTemplate( 'headerCellTemplate', 'providedHeaderCellTemplate', 'ui-grid/uiGridHeaderCell', 'headerCellFilter', 'headerTooltip' );
  8374. /**
  8375. * @ngdoc property
  8376. * @name footerCellTemplate
  8377. * @propertyOf ui.grid.class:GridOptions.columnDef
  8378. * @description a custom template for the footer for this column. The default
  8379. * is ui-grid/uiGridFooterCell
  8380. *
  8381. */
  8382. col.footerCellTemplatePromise = processTemplate( 'footerCellTemplate', 'providedFooterCellTemplate', 'ui-grid/uiGridFooterCell', 'footerCellFilter' );
  8383. /**
  8384. * @ngdoc property
  8385. * @name filterHeaderTemplate
  8386. * @propertyOf ui.grid.class:GridOptions.columnDef
  8387. * @description a custom template for the filter input. The default is ui-grid/ui-grid-filter
  8388. *
  8389. */
  8390. col.filterHeaderTemplatePromise = processTemplate( 'filterHeaderTemplate', 'providedFilterHeaderTemplate', 'ui-grid/ui-grid-filter' );
  8391. // Create a promise for the compiled element function
  8392. col.compiledElementFnDefer = $q.defer();
  8393. return $q.all(templateGetPromises);
  8394. },
  8395. rowTemplateAssigner: function rowTemplateAssigner(row) {
  8396. var grid = this;
  8397. // Row has no template assigned to it
  8398. if (!row.rowTemplate) {
  8399. // Use the default row template from the grid
  8400. row.rowTemplate = grid.options.rowTemplate;
  8401. // Use the grid's function for fetching the compiled row template function
  8402. row.getRowTemplateFn = grid.getRowTemplateFn;
  8403. }
  8404. // Row has its own template assigned
  8405. else {
  8406. // Create a promise for the compiled row template function
  8407. var perRowTemplateFnPromise = $q.defer();
  8408. row.getRowTemplateFn = perRowTemplateFnPromise.promise;
  8409. // Get the row template
  8410. gridUtil.getTemplate(row.rowTemplate)
  8411. .then(function (template) {
  8412. // Compile the template
  8413. var rowTemplateFn = $compile(template);
  8414. // Resolve the compiled template function promise
  8415. perRowTemplateFnPromise.resolve(rowTemplateFn);
  8416. },
  8417. function (res) {
  8418. // Todo handle response error here?
  8419. throw new Error("Couldn't fetch/use row template '" + row.rowTemplate + "'");
  8420. });
  8421. }
  8422. return row.getRowTemplateFn;
  8423. }
  8424. };
  8425. //class definitions (moved to separate factories)
  8426. return service;
  8427. }]);
  8428. })();
  8429. (function() {
  8430. var module = angular.module('ui.grid');
  8431. function escapeRegExp(str) {
  8432. return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
  8433. }
  8434. /**
  8435. * @ngdoc service
  8436. * @name ui.grid.service:rowSearcher
  8437. *
  8438. * @description Service for searching/filtering rows based on column value conditions.
  8439. */
  8440. module.service('rowSearcher', ['gridUtil', 'uiGridConstants', function (gridUtil, uiGridConstants) {
  8441. var defaultCondition = uiGridConstants.filter.CONTAINS;
  8442. var rowSearcher = {};
  8443. /**
  8444. * @ngdoc function
  8445. * @name getTerm
  8446. * @methodOf ui.grid.service:rowSearcher
  8447. * @description Get the term from a filter
  8448. * Trims leading and trailing whitespace
  8449. * @param {object} filter object to use
  8450. * @returns {object} Parsed term
  8451. */
  8452. rowSearcher.getTerm = function getTerm(filter) {
  8453. if (typeof(filter.term) === 'undefined') { return filter.term; }
  8454. var term = filter.term;
  8455. // Strip leading and trailing whitespace if the term is a string
  8456. if (typeof(term) === 'string') {
  8457. term = term.trim();
  8458. }
  8459. return term;
  8460. };
  8461. /**
  8462. * @ngdoc function
  8463. * @name stripTerm
  8464. * @methodOf ui.grid.service:rowSearcher
  8465. * @description Remove leading and trailing asterisk (*) from the filter's term
  8466. * @param {object} filter object to use
  8467. * @returns {uiGridConstants.filter<int>} Value representing the condition constant value
  8468. */
  8469. rowSearcher.stripTerm = function stripTerm(filter) {
  8470. var term = rowSearcher.getTerm(filter);
  8471. if (typeof(term) === 'string') {
  8472. return escapeRegExp(term.replace(/(^\*|\*$)/g, ''));
  8473. }
  8474. else {
  8475. return term;
  8476. }
  8477. };
  8478. /**
  8479. * @ngdoc function
  8480. * @name guessCondition
  8481. * @methodOf ui.grid.service:rowSearcher
  8482. * @description Guess the condition for a filter based on its term
  8483. * <br>
  8484. * Defaults to STARTS_WITH. Uses CONTAINS for strings beginning and ending with *s (*bob*).
  8485. * Uses STARTS_WITH for strings ending with * (bo*). Uses ENDS_WITH for strings starting with * (*ob).
  8486. * @param {object} filter object to use
  8487. * @returns {uiGridConstants.filter<int>} Value representing the condition constant value
  8488. */
  8489. rowSearcher.guessCondition = function guessCondition(filter) {
  8490. if (typeof(filter.term) === 'undefined' || !filter.term) {
  8491. return defaultCondition;
  8492. }
  8493. var term = rowSearcher.getTerm(filter);
  8494. if (/\*/.test(term)) {
  8495. var regexpFlags = '';
  8496. if (!filter.flags || !filter.flags.caseSensitive) {
  8497. regexpFlags += 'i';
  8498. }
  8499. var reText = term.replace(/(\\)?\*/g, function ($0, $1) { return $1 ? $0 : '[\\s\\S]*?'; });
  8500. return new RegExp('^' + reText + '$', regexpFlags);
  8501. }
  8502. // Otherwise default to default condition
  8503. else {
  8504. return defaultCondition;
  8505. }
  8506. };
  8507. /**
  8508. * @ngdoc function
  8509. * @name setupFilters
  8510. * @methodOf ui.grid.service:rowSearcher
  8511. * @description For a given columns filters (either col.filters, or [col.filter] can be passed in),
  8512. * do all the parsing and pre-processing and store that data into a new filters object. The object
  8513. * has the condition, the flags, the stripped term, and a parsed reg exp if there was one.
  8514. *
  8515. * We could use a forEach in here, since it's much less performance sensitive, but since we're using
  8516. * for loops everywhere else in this module...
  8517. *
  8518. * @param {array} filters the filters from the column (col.filters or [col.filter])
  8519. * @returns {array} An array of parsed/preprocessed filters
  8520. */
  8521. rowSearcher.setupFilters = function setupFilters( filters ){
  8522. var newFilters = [];
  8523. var filtersLength = filters.length;
  8524. for ( var i = 0; i < filtersLength; i++ ){
  8525. var filter = filters[i];
  8526. if ( filter.noTerm || !gridUtil.isNullOrUndefined(filter.term) ){
  8527. var newFilter = {};
  8528. var regexpFlags = '';
  8529. if (!filter.flags || !filter.flags.caseSensitive) {
  8530. regexpFlags += 'i';
  8531. }
  8532. if ( !gridUtil.isNullOrUndefined(filter.term) ){
  8533. // it is possible to have noTerm.
  8534. if ( filter.rawTerm ){
  8535. newFilter.term = filter.term;
  8536. } else {
  8537. newFilter.term = rowSearcher.stripTerm(filter);
  8538. }
  8539. }
  8540. newFilter.noTerm = filter.noTerm;
  8541. if ( filter.condition ){
  8542. newFilter.condition = filter.condition;
  8543. } else {
  8544. newFilter.condition = rowSearcher.guessCondition(filter);
  8545. }
  8546. newFilter.flags = angular.extend( { caseSensitive: false, date: false }, filter.flags );
  8547. if (newFilter.condition === uiGridConstants.filter.STARTS_WITH) {
  8548. newFilter.startswithRE = new RegExp('^' + newFilter.term, regexpFlags);
  8549. }
  8550. if (newFilter.condition === uiGridConstants.filter.ENDS_WITH) {
  8551. newFilter.endswithRE = new RegExp(newFilter.term + '$', regexpFlags);
  8552. }
  8553. if (newFilter.condition === uiGridConstants.filter.CONTAINS) {
  8554. newFilter.containsRE = new RegExp(newFilter.term, regexpFlags);
  8555. }
  8556. if (newFilter.condition === uiGridConstants.filter.EXACT) {
  8557. newFilter.exactRE = new RegExp('^' + newFilter.term + '$', regexpFlags);
  8558. }
  8559. newFilters.push(newFilter);
  8560. }
  8561. }
  8562. return newFilters;
  8563. };
  8564. /**
  8565. * @ngdoc function
  8566. * @name runColumnFilter
  8567. * @methodOf ui.grid.service:rowSearcher
  8568. * @description Runs a single pre-parsed filter against a cell, returning true
  8569. * if the cell matches that one filter.
  8570. *
  8571. * @param {Grid} grid the grid we're working against
  8572. * @param {GridRow} row the row we're matching against
  8573. * @param {GridColumn} column the column that we're working against
  8574. * @param {object} filter the specific, preparsed, filter that we want to test
  8575. * @returns {boolean} true if we match (row stays visible)
  8576. */
  8577. rowSearcher.runColumnFilter = function runColumnFilter(grid, row, column, filter) {
  8578. // Cache typeof condition
  8579. var conditionType = typeof(filter.condition);
  8580. // Term to search for.
  8581. var term = filter.term;
  8582. // Get the column value for this row
  8583. var value;
  8584. if ( column.filterCellFiltered ){
  8585. value = grid.getCellDisplayValue(row, column);
  8586. } else {
  8587. value = grid.getCellValue(row, column);
  8588. }
  8589. // If the filter's condition is a RegExp, then use it
  8590. if (filter.condition instanceof RegExp) {
  8591. return filter.condition.test(value);
  8592. }
  8593. // If the filter's condition is a function, run it
  8594. if (conditionType === 'function') {
  8595. return filter.condition(term, value, row, column);
  8596. }
  8597. if (filter.startswithRE) {
  8598. return filter.startswithRE.test(value);
  8599. }
  8600. if (filter.endswithRE) {
  8601. return filter.endswithRE.test(value);
  8602. }
  8603. if (filter.containsRE) {
  8604. return filter.containsRE.test(value);
  8605. }
  8606. if (filter.exactRE) {
  8607. return filter.exactRE.test(value);
  8608. }
  8609. if (filter.condition === uiGridConstants.filter.NOT_EQUAL) {
  8610. var regex = new RegExp('^' + term + '$');
  8611. return !regex.exec(value);
  8612. }
  8613. if (typeof(value) === 'number' && typeof(term) === 'string' ){
  8614. // if the term has a decimal in it, it comes through as '9\.4', we need to take out the \
  8615. // the same for negative numbers
  8616. // TODO: I suspect the right answer is to look at escapeRegExp at the top of this code file, maybe it's not needed?
  8617. var tempFloat = parseFloat(term.replace(/\\\./,'.').replace(/\\\-/,'-'));
  8618. if (!isNaN(tempFloat)) {
  8619. term = tempFloat;
  8620. }
  8621. }
  8622. if (filter.flags.date === true) {
  8623. value = new Date(value);
  8624. // If the term has a dash in it, it comes through as '\-' -- we need to take out the '\'.
  8625. term = new Date(term.replace(/\\/g, ''));
  8626. }
  8627. if (filter.condition === uiGridConstants.filter.GREATER_THAN) {
  8628. return (value > term);
  8629. }
  8630. if (filter.condition === uiGridConstants.filter.GREATER_THAN_OR_EQUAL) {
  8631. return (value >= term);
  8632. }
  8633. if (filter.condition === uiGridConstants.filter.LESS_THAN) {
  8634. return (value < term);
  8635. }
  8636. if (filter.condition === uiGridConstants.filter.LESS_THAN_OR_EQUAL) {
  8637. return (value <= term);
  8638. }
  8639. return true;
  8640. };
  8641. /**
  8642. * @ngdoc boolean
  8643. * @name useExternalFiltering
  8644. * @propertyOf ui.grid.class:GridOptions
  8645. * @description False by default. When enabled, this setting suppresses the internal filtering.
  8646. * All UI logic will still operate, allowing filter conditions to be set and modified.
  8647. *
  8648. * The external filter logic can listen for the `filterChange` event, which fires whenever
  8649. * a filter has been adjusted.
  8650. */
  8651. /**
  8652. * @ngdoc function
  8653. * @name searchColumn
  8654. * @methodOf ui.grid.service:rowSearcher
  8655. * @description Process provided filters on provided column against a given row. If the row meets
  8656. * the conditions on all the filters, return true.
  8657. * @param {Grid} grid Grid to search in
  8658. * @param {GridRow} row Row to search on
  8659. * @param {GridColumn} column Column with the filters to use
  8660. * @param {array} filters array of pre-parsed/preprocessed filters to apply
  8661. * @returns {boolean} Whether the column matches or not.
  8662. */
  8663. rowSearcher.searchColumn = function searchColumn(grid, row, column, filters) {
  8664. if (grid.options.useExternalFiltering) {
  8665. return true;
  8666. }
  8667. var filtersLength = filters.length;
  8668. for (var i = 0; i < filtersLength; i++) {
  8669. var filter = filters[i];
  8670. if ( !gridUtil.isNullOrUndefined(filter.term) && filter.term !== '' || filter.noTerm ){
  8671. var ret = rowSearcher.runColumnFilter(grid, row, column, filter);
  8672. if (!ret) {
  8673. return false;
  8674. }
  8675. }
  8676. }
  8677. return true;
  8678. };
  8679. /**
  8680. * @ngdoc function
  8681. * @name search
  8682. * @methodOf ui.grid.service:rowSearcher
  8683. * @description Run a search across the given rows and columns, marking any rows that don't
  8684. * match the stored col.filters or col.filter as invisible.
  8685. * @param {Grid} grid Grid instance to search inside
  8686. * @param {Array[GridRow]} rows GridRows to filter
  8687. * @param {Array[GridColumn]} columns GridColumns with filters to process
  8688. */
  8689. rowSearcher.search = function search(grid, rows, columns) {
  8690. /*
  8691. * Added performance optimisations into this code base, as this logic creates deeply nested
  8692. * loops and is therefore very performance sensitive. In particular, avoiding forEach as
  8693. * this impacts some browser optimisers (particularly Chrome), using iterators instead
  8694. */
  8695. // Don't do anything if we weren't passed any rows
  8696. if (!rows) {
  8697. return;
  8698. }
  8699. // don't filter if filtering currently disabled
  8700. if (!grid.options.enableFiltering){
  8701. return rows;
  8702. }
  8703. // Build list of filters to apply
  8704. var filterData = [];
  8705. var colsLength = columns.length;
  8706. var hasTerm = function( filters ) {
  8707. var hasTerm = false;
  8708. filters.forEach( function (filter) {
  8709. if ( !gridUtil.isNullOrUndefined(filter.term) && filter.term !== '' || filter.noTerm ){
  8710. hasTerm = true;
  8711. }
  8712. });
  8713. return hasTerm;
  8714. };
  8715. for (var i = 0; i < colsLength; i++) {
  8716. var col = columns[i];
  8717. if (typeof(col.filters) !== 'undefined' && hasTerm(col.filters) ) {
  8718. filterData.push( { col: col, filters: rowSearcher.setupFilters(col.filters) } );
  8719. }
  8720. }
  8721. if (filterData.length > 0) {
  8722. // define functions outside the loop, performance optimisation
  8723. var foreachRow = function(grid, row, col, filters){
  8724. if ( row.visible && !rowSearcher.searchColumn(grid, row, col, filters) ) {
  8725. row.visible = false;
  8726. }
  8727. };
  8728. var foreachFilterCol = function(grid, filterData){
  8729. var rowsLength = rows.length;
  8730. for ( var i = 0; i < rowsLength; i++){
  8731. foreachRow(grid, rows[i], filterData.col, filterData.filters);
  8732. }
  8733. };
  8734. // nested loop itself - foreachFilterCol, which in turn calls foreachRow
  8735. var filterDataLength = filterData.length;
  8736. for ( var j = 0; j < filterDataLength; j++){
  8737. foreachFilterCol( grid, filterData[j] );
  8738. }
  8739. if (grid.api.core.raise.rowsVisibleChanged) {
  8740. grid.api.core.raise.rowsVisibleChanged();
  8741. }
  8742. // drop any invisible rows
  8743. // keeping these, as needed with filtering for trees - we have to come back and make parent nodes visible if child nodes are selected in the filter
  8744. // rows = rows.filter(function(row){ return row.visible; });
  8745. }
  8746. return rows;
  8747. };
  8748. return rowSearcher;
  8749. }]);
  8750. })();
  8751. (function() {
  8752. var module = angular.module('ui.grid');
  8753. /**
  8754. * @ngdoc object
  8755. * @name ui.grid.class:rowSorter
  8756. * @description rowSorter provides the default sorting mechanisms,
  8757. * including guessing column types and applying appropriate sort
  8758. * algorithms
  8759. *
  8760. */
  8761. module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGridConstants) {
  8762. var currencyRegexStr =
  8763. '(' +
  8764. uiGridConstants.CURRENCY_SYMBOLS
  8765. .map(function (a) { return '\\' + a; }) // Escape all the currency symbols ($ at least will jack up this regex)
  8766. .join('|') + // Join all the symbols together with |s
  8767. ')?';
  8768. // /^[-+]?[£$¤¥]?[\d,.]+%?$/
  8769. var numberStrRegex = new RegExp('^[-+]?' + currencyRegexStr + '[\\d,.]+' + currencyRegexStr + '%?$');
  8770. var rowSorter = {
  8771. // Cache of sorting functions. Once we create them, we don't want to keep re-doing it
  8772. // this takes a piece of data from the cell and tries to determine its type and what sorting
  8773. // function to use for it
  8774. colSortFnCache: {}
  8775. };
  8776. /**
  8777. * @ngdoc method
  8778. * @methodOf ui.grid.class:rowSorter
  8779. * @name guessSortFn
  8780. * @description Assigns a sort function to use based on the itemType in the column
  8781. * @param {string} itemType one of 'number', 'boolean', 'string', 'date', 'object'. And
  8782. * error will be thrown for any other type.
  8783. * @returns {function} a sort function that will sort that type
  8784. */
  8785. rowSorter.guessSortFn = function guessSortFn(itemType) {
  8786. switch (itemType) {
  8787. case "number":
  8788. return rowSorter.sortNumber;
  8789. case "numberStr":
  8790. return rowSorter.sortNumberStr;
  8791. case "boolean":
  8792. return rowSorter.sortBool;
  8793. case "string":
  8794. return rowSorter.sortAlpha;
  8795. case "date":
  8796. return rowSorter.sortDate;
  8797. case "object":
  8798. return rowSorter.basicSort;
  8799. default:
  8800. throw new Error('No sorting function found for type:' + itemType);
  8801. }
  8802. };
  8803. /**
  8804. * @ngdoc method
  8805. * @methodOf ui.grid.class:rowSorter
  8806. * @name handleNulls
  8807. * @description Sorts nulls and undefined to the bottom (top when
  8808. * descending). Called by each of the internal sorters before
  8809. * attempting to sort. Note that this method is available on the core api
  8810. * via gridApi.core.sortHandleNulls
  8811. * @param {object} a sort value a
  8812. * @param {object} b sort value b
  8813. * @returns {number} null if there were no nulls/undefineds, otherwise returns
  8814. * a sort value that should be passed back from the sort function
  8815. */
  8816. rowSorter.handleNulls = function handleNulls(a, b) {
  8817. // We want to allow zero values and false values to be evaluated in the sort function
  8818. if ((!a && a !== 0 && a !== false) || (!b && b !== 0 && b !== false)) {
  8819. // We want to force nulls and such to the bottom when we sort... which effectively is "greater than"
  8820. if ((!a && a !== 0 && a !== false) && (!b && b !== 0 && b !== false)) {
  8821. return 0;
  8822. }
  8823. else if (!a && a !== 0 && a !== false) {
  8824. return 1;
  8825. }
  8826. else if (!b && b !== 0 && b !== false) {
  8827. return -1;
  8828. }
  8829. }
  8830. return null;
  8831. };
  8832. /**
  8833. * @ngdoc method
  8834. * @methodOf ui.grid.class:rowSorter
  8835. * @name basicSort
  8836. * @description Sorts any values that provide the < method, including strings
  8837. * or numbers. Handles nulls and undefined through calling handleNulls
  8838. * @param {object} a sort value a
  8839. * @param {object} b sort value b
  8840. * @returns {number} normal sort function, returns -ve, 0, +ve
  8841. */
  8842. rowSorter.basicSort = function basicSort(a, b) {
  8843. var nulls = rowSorter.handleNulls(a, b);
  8844. if ( nulls !== null ){
  8845. return nulls;
  8846. } else {
  8847. if (a === b) {
  8848. return 0;
  8849. }
  8850. if (a < b) {
  8851. return -1;
  8852. }
  8853. return 1;
  8854. }
  8855. };
  8856. /**
  8857. * @ngdoc method
  8858. * @methodOf ui.grid.class:rowSorter
  8859. * @name sortNumber
  8860. * @description Sorts numerical values. Handles nulls and undefined through calling handleNulls
  8861. * @param {object} a sort value a
  8862. * @param {object} b sort value b
  8863. * @returns {number} normal sort function, returns -ve, 0, +ve
  8864. */
  8865. rowSorter.sortNumber = function sortNumber(a, b) {
  8866. var nulls = rowSorter.handleNulls(a, b);
  8867. if ( nulls !== null ){
  8868. return nulls;
  8869. } else {
  8870. return a - b;
  8871. }
  8872. };
  8873. /**
  8874. * @ngdoc method
  8875. * @methodOf ui.grid.class:rowSorter
  8876. * @name sortNumberStr
  8877. * @description Sorts numerical values that are stored in a string (i.e. parses them to numbers first).
  8878. * Handles nulls and undefined through calling handleNulls
  8879. * @param {object} a sort value a
  8880. * @param {object} b sort value b
  8881. * @returns {number} normal sort function, returns -ve, 0, +ve
  8882. */
  8883. rowSorter.sortNumberStr = function sortNumberStr(a, b) {
  8884. var nulls = rowSorter.handleNulls(a, b);
  8885. if ( nulls !== null ){
  8886. return nulls;
  8887. } else {
  8888. var numA, // The parsed number form of 'a'
  8889. numB, // The parsed number form of 'b'
  8890. badA = false,
  8891. badB = false;
  8892. // Try to parse 'a' to a float
  8893. numA = parseFloat(a.replace(/[^0-9.-]/g, ''));
  8894. // If 'a' couldn't be parsed to float, flag it as bad
  8895. if (isNaN(numA)) {
  8896. badA = true;
  8897. }
  8898. // Try to parse 'b' to a float
  8899. numB = parseFloat(b.replace(/[^0-9.-]/g, ''));
  8900. // If 'b' couldn't be parsed to float, flag it as bad
  8901. if (isNaN(numB)) {
  8902. badB = true;
  8903. }
  8904. // We want bad ones to get pushed to the bottom... which effectively is "greater than"
  8905. if (badA && badB) {
  8906. return 0;
  8907. }
  8908. if (badA) {
  8909. return 1;
  8910. }
  8911. if (badB) {
  8912. return -1;
  8913. }
  8914. return numA - numB;
  8915. }
  8916. };
  8917. /**
  8918. * @ngdoc method
  8919. * @methodOf ui.grid.class:rowSorter
  8920. * @name sortAlpha
  8921. * @description Sorts string values. Handles nulls and undefined through calling handleNulls
  8922. * @param {object} a sort value a
  8923. * @param {object} b sort value b
  8924. * @returns {number} normal sort function, returns -ve, 0, +ve
  8925. */
  8926. rowSorter.sortAlpha = function sortAlpha(a, b) {
  8927. var nulls = rowSorter.handleNulls(a, b);
  8928. if ( nulls !== null ){
  8929. return nulls;
  8930. } else {
  8931. var strA = a.toString().toLowerCase(),
  8932. strB = b.toString().toLowerCase();
  8933. return strA === strB ? 0 : strA.localeCompare(strB);
  8934. }
  8935. };
  8936. /**
  8937. * @ngdoc method
  8938. * @methodOf ui.grid.class:rowSorter
  8939. * @name sortDate
  8940. * @description Sorts date values. Handles nulls and undefined through calling handleNulls.
  8941. * Handles date strings by converting to Date object if not already an instance of Date
  8942. * @param {object} a sort value a
  8943. * @param {object} b sort value b
  8944. * @returns {number} normal sort function, returns -ve, 0, +ve
  8945. */
  8946. rowSorter.sortDate = function sortDate(a, b) {
  8947. var nulls = rowSorter.handleNulls(a, b);
  8948. if ( nulls !== null ){
  8949. return nulls;
  8950. } else {
  8951. if (!(a instanceof Date)) {
  8952. a = new Date(a);
  8953. }
  8954. if (!(b instanceof Date)){
  8955. b = new Date(b);
  8956. }
  8957. var timeA = a.getTime(),
  8958. timeB = b.getTime();
  8959. return timeA === timeB ? 0 : (timeA < timeB ? -1 : 1);
  8960. }
  8961. };
  8962. /**
  8963. * @ngdoc method
  8964. * @methodOf ui.grid.class:rowSorter
  8965. * @name sortBool
  8966. * @description Sorts boolean values, true is considered larger than false.
  8967. * Handles nulls and undefined through calling handleNulls
  8968. * @param {object} a sort value a
  8969. * @param {object} b sort value b
  8970. * @returns {number} normal sort function, returns -ve, 0, +ve
  8971. */
  8972. rowSorter.sortBool = function sortBool(a, b) {
  8973. var nulls = rowSorter.handleNulls(a, b);
  8974. if ( nulls !== null ){
  8975. return nulls;
  8976. } else {
  8977. if (a && b) {
  8978. return 0;
  8979. }
  8980. if (!a && !b) {
  8981. return 0;
  8982. }
  8983. else {
  8984. return a ? 1 : -1;
  8985. }
  8986. }
  8987. };
  8988. /**
  8989. * @ngdoc method
  8990. * @methodOf ui.grid.class:rowSorter
  8991. * @name getSortFn
  8992. * @description Get the sort function for the column. Looks first in
  8993. * rowSorter.colSortFnCache using the column name, failing that it
  8994. * looks at col.sortingAlgorithm (and puts it in the cache), failing that
  8995. * it guesses the sort algorithm based on the data type.
  8996. *
  8997. * The cache currently seems a bit pointless, as none of the work we do is
  8998. * processor intensive enough to need caching. Presumably in future we might
  8999. * inspect the row data itself to guess the sort function, and in that case
  9000. * it would make sense to have a cache, the infrastructure is in place to allow
  9001. * that.
  9002. *
  9003. * @param {Grid} grid the grid to consider
  9004. * @param {GridColumn} col the column to find a function for
  9005. * @param {array} rows an array of grid rows. Currently unused, but presumably in future
  9006. * we might inspect the rows themselves to decide what sort of data might be there
  9007. * @returns {function} the sort function chosen for the column
  9008. */
  9009. rowSorter.getSortFn = function getSortFn(grid, col, rows) {
  9010. var sortFn, item;
  9011. // See if we already figured out what to use to sort the column and have it in the cache
  9012. if (rowSorter.colSortFnCache[col.colDef.name]) {
  9013. sortFn = rowSorter.colSortFnCache[col.colDef.name];
  9014. }
  9015. // If the column has its OWN sorting algorithm, use that
  9016. else if (col.sortingAlgorithm !== undefined) {
  9017. sortFn = col.sortingAlgorithm;
  9018. rowSorter.colSortFnCache[col.colDef.name] = col.sortingAlgorithm;
  9019. }
  9020. // Always default to sortAlpha when sorting after a cellFilter
  9021. else if ( col.sortCellFiltered && col.cellFilter ){
  9022. sortFn = rowSorter.sortAlpha;
  9023. rowSorter.colSortFnCache[col.colDef.name] = sortFn;
  9024. }
  9025. // Try and guess what sort function to use
  9026. else {
  9027. // Guess the sort function
  9028. sortFn = rowSorter.guessSortFn(col.colDef.type);
  9029. // If we found a sort function, cache it
  9030. if (sortFn) {
  9031. rowSorter.colSortFnCache[col.colDef.name] = sortFn;
  9032. }
  9033. else {
  9034. // We assign the alpha sort because anything that is null/undefined will never get passed to
  9035. // the actual sorting function. It will get caught in our null check and returned to be sorted
  9036. // down to the bottom
  9037. sortFn = rowSorter.sortAlpha;
  9038. }
  9039. }
  9040. return sortFn;
  9041. };
  9042. /**
  9043. * @ngdoc method
  9044. * @methodOf ui.grid.class:rowSorter
  9045. * @name prioritySort
  9046. * @description Used where multiple columns are present in the sort criteria,
  9047. * we determine which column should take precedence in the sort by sorting
  9048. * the columns based on their sort.priority
  9049. *
  9050. * @param {gridColumn} a column a
  9051. * @param {gridColumn} b column b
  9052. * @returns {number} normal sort function, returns -ve, 0, +ve
  9053. */
  9054. rowSorter.prioritySort = function (a, b) {
  9055. // Both columns have a sort priority
  9056. if (a.sort.priority !== undefined && b.sort.priority !== undefined) {
  9057. // A is higher priority
  9058. if (a.sort.priority < b.sort.priority) {
  9059. return -1;
  9060. }
  9061. // Equal
  9062. else if (a.sort.priority === b.sort.priority) {
  9063. return 0;
  9064. }
  9065. // B is higher
  9066. else {
  9067. return 1;
  9068. }
  9069. }
  9070. // Only A has a priority
  9071. else if (a.sort.priority !== undefined) {
  9072. return -1;
  9073. }
  9074. // Only B has a priority
  9075. else if (b.sort.priority !== undefined) {
  9076. return 1;
  9077. }
  9078. // Neither has a priority
  9079. else {
  9080. return 0;
  9081. }
  9082. };
  9083. /**
  9084. * @ngdoc object
  9085. * @name useExternalSorting
  9086. * @propertyOf ui.grid.class:GridOptions
  9087. * @description Prevents the internal sorting from executing. Events will
  9088. * still be fired when the sort changes, and the sort information on
  9089. * the columns will be updated, allowing an external sorter (for example,
  9090. * server sorting) to be implemented. Defaults to false.
  9091. *
  9092. */
  9093. /**
  9094. * @ngdoc method
  9095. * @methodOf ui.grid.class:rowSorter
  9096. * @name sort
  9097. * @description sorts the grid
  9098. * @param {Object} grid the grid itself
  9099. * @param {array} rows the rows to be sorted
  9100. * @param {array} columns the columns in which to look
  9101. * for sort criteria
  9102. * @returns {array} sorted rows
  9103. */
  9104. rowSorter.sort = function rowSorterSort(grid, rows, columns) {
  9105. // first make sure we are even supposed to do work
  9106. if (!rows) {
  9107. return;
  9108. }
  9109. if (grid.options.useExternalSorting){
  9110. return rows;
  9111. }
  9112. // Build the list of columns to sort by
  9113. var sortCols = [];
  9114. var defaultSortCols = [];
  9115. columns.forEach(function (col) {
  9116. if (col.sort && !col.sort.ignoreSort && col.sort.direction && (col.sort.direction === uiGridConstants.ASC || col.sort.direction === uiGridConstants.DESC)) {
  9117. sortCols.push({
  9118. col: col,
  9119. sort: col.sort
  9120. });
  9121. } else if ( col.defaultSort && col.defaultSort.direction && (col.defaultSort.direction === uiGridConstants.ASC || col.defaultSort.direction === uiGridConstants.DESC) ) {
  9122. defaultSortCols.push({
  9123. col: col,
  9124. sort: col.defaultSort
  9125. });
  9126. }
  9127. });
  9128. // Sort the "sort columns" by their sort priority
  9129. sortCols = sortCols.sort(rowSorter.prioritySort);
  9130. defaultSortCols = defaultSortCols.sort(rowSorter.prioritySort);
  9131. sortCols = sortCols.concat(defaultSortCols);
  9132. // Now rows to sort by, maintain original order
  9133. if (sortCols.length === 0) {
  9134. return rows;
  9135. }
  9136. // Re-usable variables
  9137. var col, direction;
  9138. // put a custom index field on each row, used to make a stable sort out of unstable sorts (e.g. Chrome)
  9139. var setIndex = function( row, idx ){
  9140. row.entity.$$uiGridIndex = idx;
  9141. };
  9142. rows.forEach(setIndex);
  9143. // IE9-11 HACK.... the 'rows' variable would be empty where we call rowSorter.getSortFn(...) below. We have to use a separate reference
  9144. // var d = data.slice(0);
  9145. var r = rows.slice(0);
  9146. // Now actually sort the data
  9147. var rowSortFn = function (rowA, rowB) {
  9148. var tem = 0,
  9149. idx = 0,
  9150. sortFn;
  9151. while (tem === 0 && idx < sortCols.length) {
  9152. // grab the metadata for the rest of the logic
  9153. col = sortCols[idx].col;
  9154. direction = sortCols[idx].sort.direction;
  9155. sortFn = rowSorter.getSortFn(grid, col, r);
  9156. var propA, propB;
  9157. if ( col.sortCellFiltered ){
  9158. propA = grid.getCellDisplayValue(rowA, col);
  9159. propB = grid.getCellDisplayValue(rowB, col);
  9160. } else {
  9161. propA = grid.getCellValue(rowA, col);
  9162. propB = grid.getCellValue(rowB, col);
  9163. }
  9164. tem = sortFn(propA, propB, rowA, rowB, direction, col);
  9165. idx++;
  9166. }
  9167. // Chrome doesn't implement a stable sort function. If our sort returns 0
  9168. // (i.e. the items are equal), and we're at the last sort column in the list,
  9169. // then return the previous order using our custom
  9170. // index variable
  9171. if (tem === 0 ) {
  9172. return rowA.entity.$$uiGridIndex - rowB.entity.$$uiGridIndex;
  9173. }
  9174. // Made it this far, we don't have to worry about null & undefined
  9175. if (direction === uiGridConstants.ASC) {
  9176. return tem;
  9177. } else {
  9178. return 0 - tem;
  9179. }
  9180. };
  9181. var newRows = rows.sort(rowSortFn);
  9182. // remove the custom index field on each row, used to make a stable sort out of unstable sorts (e.g. Chrome)
  9183. var clearIndex = function( row, idx ){
  9184. delete row.entity.$$uiGridIndex;
  9185. };
  9186. rows.forEach(clearIndex);
  9187. return newRows;
  9188. };
  9189. return rowSorter;
  9190. }]);
  9191. })();
  9192. (function() {
  9193. var module = angular.module('ui.grid');
  9194. var bindPolyfill;
  9195. if (typeof Function.prototype.bind !== "function") {
  9196. bindPolyfill = function() {
  9197. var slice = Array.prototype.slice;
  9198. return function(context) {
  9199. var fn = this,
  9200. args = slice.call(arguments, 1);
  9201. if (args.length) {
  9202. return function() {
  9203. return arguments.length ? fn.apply(context, args.concat(slice.call(arguments))) : fn.apply(context, args);
  9204. };
  9205. }
  9206. return function() {
  9207. return arguments.length ? fn.apply(context, arguments) : fn.call(context);
  9208. };
  9209. };
  9210. };
  9211. }
  9212. function getStyles (elem) {
  9213. var e = elem;
  9214. if (typeof(e.length) !== 'undefined' && e.length) {
  9215. e = elem[0];
  9216. }
  9217. return e.ownerDocument.defaultView.getComputedStyle(e, null);
  9218. }
  9219. var rnumnonpx = new RegExp( "^(" + (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source + ")(?!px)[a-z%]+$", "i" ),
  9220. // swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
  9221. // see here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
  9222. rdisplayswap = /^(block|none|table(?!-c[ea]).+)/,
  9223. cssShow = { position: "absolute", visibility: "hidden", display: "block" };
  9224. function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
  9225. var i = extra === ( isBorderBox ? 'border' : 'content' ) ?
  9226. // If we already have the right measurement, avoid augmentation
  9227. 4 :
  9228. // Otherwise initialize for horizontal or vertical properties
  9229. name === 'width' ? 1 : 0,
  9230. val = 0;
  9231. var sides = ['Top', 'Right', 'Bottom', 'Left'];
  9232. for ( ; i < 4; i += 2 ) {
  9233. var side = sides[i];
  9234. // dump('side', side);
  9235. // both box models exclude margin, so add it if we want it
  9236. if ( extra === 'margin' ) {
  9237. var marg = parseFloat(styles[extra + side]);
  9238. if (!isNaN(marg)) {
  9239. val += marg;
  9240. }
  9241. }
  9242. // dump('val1', val);
  9243. if ( isBorderBox ) {
  9244. // border-box includes padding, so remove it if we want content
  9245. if ( extra === 'content' ) {
  9246. var padd = parseFloat(styles['padding' + side]);
  9247. if (!isNaN(padd)) {
  9248. val -= padd;
  9249. // dump('val2', val);
  9250. }
  9251. }
  9252. // at this point, extra isn't border nor margin, so remove border
  9253. if ( extra !== 'margin' ) {
  9254. var bordermarg = parseFloat(styles['border' + side + 'Width']);
  9255. if (!isNaN(bordermarg)) {
  9256. val -= bordermarg;
  9257. // dump('val3', val);
  9258. }
  9259. }
  9260. }
  9261. else {
  9262. // at this point, extra isn't content, so add padding
  9263. var nocontentPad = parseFloat(styles['padding' + side]);
  9264. if (!isNaN(nocontentPad)) {
  9265. val += nocontentPad;
  9266. // dump('val4', val);
  9267. }
  9268. // at this point, extra isn't content nor padding, so add border
  9269. if ( extra !== 'padding') {
  9270. var nocontentnopad = parseFloat(styles['border' + side + 'Width']);
  9271. if (!isNaN(nocontentnopad)) {
  9272. val += nocontentnopad;
  9273. // dump('val5', val);
  9274. }
  9275. }
  9276. }
  9277. }
  9278. // dump('augVal', val);
  9279. return val;
  9280. }
  9281. function getWidthOrHeight( elem, name, extra ) {
  9282. // Start with offset property, which is equivalent to the border-box value
  9283. var valueIsBorderBox = true,
  9284. val, // = name === 'width' ? elem.offsetWidth : elem.offsetHeight,
  9285. styles = getStyles(elem),
  9286. isBorderBox = styles['boxSizing'] === 'border-box';
  9287. // some non-html elements return undefined for offsetWidth, so check for null/undefined
  9288. // svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
  9289. // MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
  9290. if ( val <= 0 || val == null ) {
  9291. // Fall back to computed then uncomputed css if necessary
  9292. val = styles[name];
  9293. if ( val < 0 || val == null ) {
  9294. val = elem.style[ name ];
  9295. }
  9296. // Computed unit is not pixels. Stop here and return.
  9297. if ( rnumnonpx.test(val) ) {
  9298. return val;
  9299. }
  9300. // we need the check for style in case a browser which returns unreliable values
  9301. // for getComputedStyle silently falls back to the reliable elem.style
  9302. valueIsBorderBox = isBorderBox &&
  9303. ( true || val === elem.style[ name ] ); // use 'true' instead of 'support.boxSizingReliable()'
  9304. // Normalize "", auto, and prepare for extra
  9305. val = parseFloat( val ) || 0;
  9306. }
  9307. // use the active box-sizing model to add/subtract irrelevant styles
  9308. var ret = ( val +
  9309. augmentWidthOrHeight(
  9310. elem,
  9311. name,
  9312. extra || ( isBorderBox ? "border" : "content" ),
  9313. valueIsBorderBox,
  9314. styles
  9315. )
  9316. );
  9317. // dump('ret', ret, val);
  9318. return ret;
  9319. }
  9320. function getLineHeight(elm) {
  9321. elm = angular.element(elm)[0];
  9322. var parent = elm.parentElement;
  9323. if (!parent) {
  9324. parent = document.getElementsByTagName('body')[0];
  9325. }
  9326. return parseInt( getStyles(parent).fontSize ) || parseInt( getStyles(elm).fontSize ) || 16;
  9327. }
  9328. var uid = ['0', '0', '0', '0'];
  9329. var uidPrefix = 'uiGrid-';
  9330. /**
  9331. * @ngdoc service
  9332. * @name ui.grid.service:GridUtil
  9333. *
  9334. * @description Grid utility functions
  9335. */
  9336. module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateCache', '$timeout', '$interval', '$injector', '$q', '$interpolate', 'uiGridConstants',
  9337. function ($log, $window, $document, $http, $templateCache, $timeout, $interval, $injector, $q, $interpolate, uiGridConstants) {
  9338. var s = {
  9339. augmentWidthOrHeight: augmentWidthOrHeight,
  9340. getStyles: getStyles,
  9341. /**
  9342. * @ngdoc method
  9343. * @name createBoundedWrapper
  9344. * @methodOf ui.grid.service:GridUtil
  9345. *
  9346. * @param {object} Object to bind 'this' to
  9347. * @param {method} Method to bind
  9348. * @returns {Function} The wrapper that performs the binding
  9349. *
  9350. * @description
  9351. * Binds given method to given object.
  9352. *
  9353. * By means of a wrapper, ensures that ``method`` is always bound to
  9354. * ``object`` regardless of its calling environment.
  9355. * Iow, inside ``method``, ``this`` always points to ``object``.
  9356. *
  9357. * See http://alistapart.com/article/getoutbindingsituations
  9358. *
  9359. */
  9360. createBoundedWrapper: function(object, method) {
  9361. return function() {
  9362. return method.apply(object, arguments);
  9363. };
  9364. },
  9365. /**
  9366. * @ngdoc method
  9367. * @name readableColumnName
  9368. * @methodOf ui.grid.service:GridUtil
  9369. *
  9370. * @param {string} columnName Column name as a string
  9371. * @returns {string} Column name appropriately capitalized and split apart
  9372. *
  9373. @example
  9374. <example module="app">
  9375. <file name="app.js">
  9376. var app = angular.module('app', ['ui.grid']);
  9377. app.controller('MainCtrl', ['$scope', 'gridUtil', function ($scope, gridUtil) {
  9378. $scope.name = 'firstName';
  9379. $scope.columnName = function(name) {
  9380. return gridUtil.readableColumnName(name);
  9381. };
  9382. }]);
  9383. </file>
  9384. <file name="index.html">
  9385. <div ng-controller="MainCtrl">
  9386. <strong>Column name:</strong> <input ng-model="name" />
  9387. <br>
  9388. <strong>Output:</strong> <span ng-bind="columnName(name)"></span>
  9389. </div>
  9390. </file>
  9391. </example>
  9392. */
  9393. readableColumnName: function (columnName) {
  9394. // Convert underscores to spaces
  9395. if (typeof(columnName) === 'undefined' || columnName === undefined || columnName === null) { return columnName; }
  9396. if (typeof(columnName) !== 'string') {
  9397. columnName = String(columnName);
  9398. }
  9399. return columnName.replace(/_+/g, ' ')
  9400. // Replace a completely all-capsed word with a first-letter-capitalized version
  9401. .replace(/^[A-Z]+$/, function (match) {
  9402. return angular.lowercase(angular.uppercase(match.charAt(0)) + match.slice(1));
  9403. })
  9404. // Capitalize the first letter of words
  9405. .replace(/([\w\u00C0-\u017F]+)/g, function (match) {
  9406. return angular.uppercase(match.charAt(0)) + match.slice(1);
  9407. })
  9408. // Put a space in between words that have partial capilizations (i.e. 'firstName' becomes 'First Name')
  9409. // .replace(/([A-Z]|[A-Z]\w+)([A-Z])/g, "$1 $2");
  9410. // .replace(/(\w+?|\w)([A-Z])/g, "$1 $2");
  9411. .replace(/(\w+?(?=[A-Z]))/g, '$1 ');
  9412. },
  9413. /**
  9414. * @ngdoc method
  9415. * @name getColumnsFromData
  9416. * @methodOf ui.grid.service:GridUtil
  9417. * @description Return a list of column names, given a data set
  9418. *
  9419. * @param {string} data Data array for grid
  9420. * @returns {Object} Column definitions with field accessor and column name
  9421. *
  9422. * @example
  9423. <pre>
  9424. var data = [
  9425. { firstName: 'Bob', lastName: 'Jones' },
  9426. { firstName: 'Frank', lastName: 'Smith' }
  9427. ];
  9428. var columnDefs = GridUtil.getColumnsFromData(data, excludeProperties);
  9429. columnDefs == [
  9430. {
  9431. field: 'firstName',
  9432. name: 'First Name'
  9433. },
  9434. {
  9435. field: 'lastName',
  9436. name: 'Last Name'
  9437. }
  9438. ];
  9439. </pre>
  9440. */
  9441. getColumnsFromData: function (data, excludeProperties) {
  9442. var columnDefs = [];
  9443. if (!data || typeof(data[0]) === 'undefined' || data[0] === undefined) { return []; }
  9444. if (angular.isUndefined(excludeProperties)) { excludeProperties = []; }
  9445. var item = data[0];
  9446. angular.forEach(item,function (prop, propName) {
  9447. if ( excludeProperties.indexOf(propName) === -1){
  9448. columnDefs.push({
  9449. name: propName
  9450. });
  9451. }
  9452. });
  9453. return columnDefs;
  9454. },
  9455. /**
  9456. * @ngdoc method
  9457. * @name newId
  9458. * @methodOf ui.grid.service:GridUtil
  9459. * @description Return a unique ID string
  9460. *
  9461. * @returns {string} Unique string
  9462. *
  9463. * @example
  9464. <pre>
  9465. var id = GridUtil.newId();
  9466. # 1387305700482;
  9467. </pre>
  9468. */
  9469. newId: (function() {
  9470. var seedId = new Date().getTime();
  9471. return function() {
  9472. return seedId += 1;
  9473. };
  9474. })(),
  9475. /**
  9476. * @ngdoc method
  9477. * @name getTemplate
  9478. * @methodOf ui.grid.service:GridUtil
  9479. * @description Get's template from cache / element / url
  9480. *
  9481. * @param {string|element|promise} Either a string representing the template id, a string representing the template url,
  9482. * an jQuery/Angualr element, or a promise that returns the template contents to use.
  9483. * @returns {object} a promise resolving to template contents
  9484. *
  9485. * @example
  9486. <pre>
  9487. GridUtil.getTemplate(url).then(function (contents) {
  9488. alert(contents);
  9489. })
  9490. </pre>
  9491. */
  9492. getTemplate: function (template) {
  9493. // Try to fetch the template out of the templateCache
  9494. if ($templateCache.get(template)) {
  9495. return s.postProcessTemplate($templateCache.get(template));
  9496. }
  9497. // See if the template is itself a promise
  9498. if (angular.isFunction(template.then)) {
  9499. return template.then(s.postProcessTemplate).catch(angular.noop);
  9500. }
  9501. // If the template is an element, return the element
  9502. try {
  9503. if (angular.element(template).length > 0) {
  9504. return $q.when(template).then(s.postProcessTemplate).catch(angular.noop);
  9505. }
  9506. }
  9507. catch (err){
  9508. //do nothing; not valid html
  9509. }
  9510. // s.logDebug('fetching url', template);
  9511. // Default to trying to fetch the template as a url with $http
  9512. return $http({ method: 'GET', url: template})
  9513. .then(
  9514. function (result) {
  9515. var templateHtml = result.data.trim();
  9516. //put in templateCache for next call
  9517. $templateCache.put(template, templateHtml);
  9518. return templateHtml;
  9519. },
  9520. function (err) {
  9521. throw new Error("Could not get template " + template + ": " + err);
  9522. }
  9523. )
  9524. .then(s.postProcessTemplate).catch(angular.noop);
  9525. },
  9526. //
  9527. postProcessTemplate: function (template) {
  9528. var startSym = $interpolate.startSymbol(),
  9529. endSym = $interpolate.endSymbol();
  9530. // If either of the interpolation symbols have been changed, we need to alter this template
  9531. if (startSym !== '{{' || endSym !== '}}') {
  9532. template = template.replace(/\{\{/g, startSym);
  9533. template = template.replace(/\}\}/g, endSym);
  9534. }
  9535. return $q.when(template);
  9536. },
  9537. /**
  9538. * @ngdoc method
  9539. * @name guessType
  9540. * @methodOf ui.grid.service:GridUtil
  9541. * @description guesses the type of an argument
  9542. *
  9543. * @param {string/number/bool/object} item variable to examine
  9544. * @returns {string} one of the following
  9545. * - 'string'
  9546. * - 'boolean'
  9547. * - 'number'
  9548. * - 'date'
  9549. * - 'object'
  9550. */
  9551. guessType : function (item) {
  9552. var itemType = typeof(item);
  9553. // Check for numbers and booleans
  9554. switch (itemType) {
  9555. case "number":
  9556. case "boolean":
  9557. case "string":
  9558. return itemType;
  9559. default:
  9560. if (angular.isDate(item)) {
  9561. return "date";
  9562. }
  9563. return "object";
  9564. }
  9565. },
  9566. /**
  9567. * @ngdoc method
  9568. * @name elementWidth
  9569. * @methodOf ui.grid.service:GridUtil
  9570. *
  9571. * @param {element} element DOM element
  9572. * @param {string} [extra] Optional modifier for calculation. Use 'margin' to account for margins on element
  9573. *
  9574. * @returns {number} Element width in pixels, accounting for any borders, etc.
  9575. */
  9576. elementWidth: function (elem) {
  9577. },
  9578. /**
  9579. * @ngdoc method
  9580. * @name elementHeight
  9581. * @methodOf ui.grid.service:GridUtil
  9582. *
  9583. * @param {element} element DOM element
  9584. * @param {string} [extra] Optional modifier for calculation. Use 'margin' to account for margins on element
  9585. *
  9586. * @returns {number} Element height in pixels, accounting for any borders, etc.
  9587. */
  9588. elementHeight: function (elem) {
  9589. },
  9590. // Thanks to http://stackoverflow.com/a/13382873/888165
  9591. getScrollbarWidth: function() {
  9592. var outer = document.createElement("div");
  9593. outer.style.visibility = "hidden";
  9594. outer.style.width = "100px";
  9595. outer.style.msOverflowStyle = "scrollbar"; // needed for WinJS apps
  9596. document.body.appendChild(outer);
  9597. var widthNoScroll = outer.offsetWidth;
  9598. // force scrollbars
  9599. outer.style.overflow = "scroll";
  9600. // add innerdiv
  9601. var inner = document.createElement("div");
  9602. inner.style.width = "100%";
  9603. outer.appendChild(inner);
  9604. var widthWithScroll = inner.offsetWidth;
  9605. // remove divs
  9606. outer.parentNode.removeChild(outer);
  9607. return widthNoScroll - widthWithScroll;
  9608. },
  9609. swap: function( elem, options, callback, args ) {
  9610. var ret, name,
  9611. old = {};
  9612. // Remember the old values, and insert the new ones
  9613. for ( name in options ) {
  9614. old[ name ] = elem.style[ name ];
  9615. elem.style[ name ] = options[ name ];
  9616. }
  9617. ret = callback.apply( elem, args || [] );
  9618. // Revert the old values
  9619. for ( name in options ) {
  9620. elem.style[ name ] = old[ name ];
  9621. }
  9622. return ret;
  9623. },
  9624. fakeElement: function( elem, options, callback, args ) {
  9625. var ret, name,
  9626. newElement = angular.element(elem).clone()[0];
  9627. for ( name in options ) {
  9628. newElement.style[ name ] = options[ name ];
  9629. }
  9630. angular.element(document.body).append(newElement);
  9631. ret = callback.call( newElement, newElement );
  9632. angular.element(newElement).remove();
  9633. return ret;
  9634. },
  9635. /**
  9636. * @ngdoc method
  9637. * @name normalizeWheelEvent
  9638. * @methodOf ui.grid.service:GridUtil
  9639. *
  9640. * @param {event} event A mouse wheel event
  9641. *
  9642. * @returns {event} A normalized event
  9643. *
  9644. * @description
  9645. * Given an event from this list:
  9646. *
  9647. * `wheel, mousewheel, DomMouseScroll, MozMousePixelScroll`
  9648. *
  9649. * "normalize" it
  9650. * so that it stays consistent no matter what browser it comes from (i.e. scale it correctly and make sure the direction is right.)
  9651. */
  9652. normalizeWheelEvent: function (event) {
  9653. // var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'];
  9654. // var toBind = 'onwheel' in document || document.documentMode >= 9 ? ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'];
  9655. var lowestDelta, lowestDeltaXY;
  9656. var orgEvent = event || window.event,
  9657. args = [].slice.call(arguments, 1),
  9658. delta = 0,
  9659. deltaX = 0,
  9660. deltaY = 0,
  9661. absDelta = 0,
  9662. absDeltaXY = 0,
  9663. fn;
  9664. // event = $.event.fix(orgEvent);
  9665. // event.type = 'mousewheel';
  9666. // NOTE: jQuery masks the event and stores it in the event as originalEvent
  9667. if (orgEvent.originalEvent) {
  9668. orgEvent = orgEvent.originalEvent;
  9669. }
  9670. // Old school scrollwheel delta
  9671. if ( orgEvent.wheelDelta ) { delta = orgEvent.wheelDelta; }
  9672. if ( orgEvent.detail ) { delta = orgEvent.detail * -1; }
  9673. // At a minimum, setup the deltaY to be delta
  9674. deltaY = delta;
  9675. // Firefox < 17 related to DOMMouseScroll event
  9676. if ( orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
  9677. deltaY = 0;
  9678. deltaX = delta * -1;
  9679. }
  9680. // New school wheel delta (wheel event)
  9681. if ( orgEvent.deltaY ) {
  9682. deltaY = orgEvent.deltaY * -1;
  9683. delta = deltaY;
  9684. }
  9685. if ( orgEvent.deltaX ) {
  9686. deltaX = orgEvent.deltaX;
  9687. delta = deltaX * -1;
  9688. }
  9689. // Webkit
  9690. if ( orgEvent.wheelDeltaY !== undefined ) { deltaY = orgEvent.wheelDeltaY; }
  9691. if ( orgEvent.wheelDeltaX !== undefined ) { deltaX = orgEvent.wheelDeltaX; }
  9692. // Look for lowest delta to normalize the delta values
  9693. absDelta = Math.abs(delta);
  9694. if ( !lowestDelta || absDelta < lowestDelta ) { lowestDelta = absDelta; }
  9695. absDeltaXY = Math.max(Math.abs(deltaY), Math.abs(deltaX));
  9696. if ( !lowestDeltaXY || absDeltaXY < lowestDeltaXY ) { lowestDeltaXY = absDeltaXY; }
  9697. // Get a whole value for the deltas
  9698. fn = delta > 0 ? 'floor' : 'ceil';
  9699. delta = Math[fn](delta / lowestDelta);
  9700. deltaX = Math[fn](deltaX / lowestDeltaXY);
  9701. deltaY = Math[fn](deltaY / lowestDeltaXY);
  9702. return {
  9703. delta: delta,
  9704. deltaX: deltaX,
  9705. deltaY: deltaY
  9706. };
  9707. },
  9708. // Stolen from Modernizr
  9709. // TODO: make this, and everythign that flows from it, robust
  9710. //http://www.stucox.com/blog/you-cant-detect-a-touchscreen/
  9711. isTouchEnabled: function() {
  9712. var bool;
  9713. if (('ontouchstart' in $window) || $window.DocumentTouch && $document instanceof DocumentTouch) {
  9714. bool = true;
  9715. }
  9716. return bool;
  9717. },
  9718. isNullOrUndefined: function(obj) {
  9719. return (obj === undefined || obj === null);
  9720. },
  9721. endsWith: function(str, suffix) {
  9722. if (!str || !suffix || typeof str !== "string") {
  9723. return false;
  9724. }
  9725. return str.indexOf(suffix, str.length - suffix.length) !== -1;
  9726. },
  9727. arrayContainsObjectWithProperty: function(array, propertyName, propertyValue) {
  9728. var found = false;
  9729. angular.forEach(array, function (object) {
  9730. if (object[propertyName] === propertyValue) {
  9731. found = true;
  9732. }
  9733. });
  9734. return found;
  9735. },
  9736. //// Shim requestAnimationFrame
  9737. //requestAnimationFrame: $window.requestAnimationFrame && $window.requestAnimationFrame.bind($window) ||
  9738. // $window.webkitRequestAnimationFrame && $window.webkitRequestAnimationFrame.bind($window) ||
  9739. // function(fn) {
  9740. // return $timeout(fn, 10, false);
  9741. // },
  9742. numericAndNullSort: function (a, b) {
  9743. if (a === null) { return 1; }
  9744. if (b === null) { return -1; }
  9745. if (a === null && b === null) { return 0; }
  9746. return a - b;
  9747. },
  9748. // Disable ngAnimate animations on an element
  9749. disableAnimations: function (element) {
  9750. var $animate;
  9751. try {
  9752. $animate = $injector.get('$animate');
  9753. // See: http://brianhann.com/angular-1-4-breaking-changes-to-be-aware-of/#animate
  9754. if (angular.version.major > 1 || (angular.version.major === 1 && angular.version.minor >= 4)) {
  9755. $animate.enabled(element, false);
  9756. } else {
  9757. $animate.enabled(false, element);
  9758. }
  9759. }
  9760. catch (e) {}
  9761. },
  9762. enableAnimations: function (element) {
  9763. var $animate;
  9764. try {
  9765. $animate = $injector.get('$animate');
  9766. // See: http://brianhann.com/angular-1-4-breaking-changes-to-be-aware-of/#animate
  9767. if (angular.version.major > 1 || (angular.version.major === 1 && angular.version.minor >= 4)) {
  9768. $animate.enabled(element, true);
  9769. } else {
  9770. $animate.enabled(true, element);
  9771. }
  9772. return $animate;
  9773. }
  9774. catch (e) {}
  9775. },
  9776. // Blatantly stolen from Angular as it isn't exposed (yet)
  9777. nextUid: function nextUid() {
  9778. var index = uid.length;
  9779. var digit;
  9780. while (index) {
  9781. index--;
  9782. digit = uid[index].charCodeAt(0);
  9783. if (digit === 57 /*'9'*/) {
  9784. uid[index] = 'A';
  9785. return uidPrefix + uid.join('');
  9786. }
  9787. if (digit === 90 /*'Z'*/) {
  9788. uid[index] = '0';
  9789. } else {
  9790. uid[index] = String.fromCharCode(digit + 1);
  9791. return uidPrefix + uid.join('');
  9792. }
  9793. }
  9794. uid.unshift('0');
  9795. return uidPrefix + uid.join('');
  9796. },
  9797. // Blatantly stolen from Angular as it isn't exposed (yet)
  9798. hashKey: function hashKey(obj) {
  9799. var objType = typeof obj,
  9800. key;
  9801. if (objType === 'object' && obj !== null) {
  9802. if (typeof (key = obj.$$hashKey) === 'function') {
  9803. // must invoke on object to keep the right this
  9804. key = obj.$$hashKey();
  9805. }
  9806. else if (typeof(obj.$$hashKey) !== 'undefined' && obj.$$hashKey) {
  9807. key = obj.$$hashKey;
  9808. }
  9809. else if (key === undefined) {
  9810. key = obj.$$hashKey = s.nextUid();
  9811. }
  9812. }
  9813. else {
  9814. key = obj;
  9815. }
  9816. return objType + ':' + key;
  9817. },
  9818. resetUids: function () {
  9819. uid = ['0', '0', '0'];
  9820. },
  9821. /**
  9822. * @ngdoc method
  9823. * @methodOf ui.grid.service:GridUtil
  9824. * @name logError
  9825. * @description wraps the $log method, allowing us to choose different
  9826. * treatment within ui-grid if we so desired. At present we only log
  9827. * error messages if uiGridConstants.LOG_ERROR_MESSAGES is set to true
  9828. * @param {string} logMessage message to be logged to the console
  9829. *
  9830. */
  9831. logError: function( logMessage ){
  9832. if ( uiGridConstants.LOG_ERROR_MESSAGES ){
  9833. $log.error( logMessage );
  9834. }
  9835. },
  9836. /**
  9837. * @ngdoc method
  9838. * @methodOf ui.grid.service:GridUtil
  9839. * @name logWarn
  9840. * @description wraps the $log method, allowing us to choose different
  9841. * treatment within ui-grid if we so desired. At present we only log
  9842. * warning messages if uiGridConstants.LOG_WARN_MESSAGES is set to true
  9843. * @param {string} logMessage message to be logged to the console
  9844. *
  9845. */
  9846. logWarn: function( logMessage ){
  9847. if ( uiGridConstants.LOG_WARN_MESSAGES ){
  9848. $log.warn( logMessage );
  9849. }
  9850. },
  9851. /**
  9852. * @ngdoc method
  9853. * @methodOf ui.grid.service:GridUtil
  9854. * @name logDebug
  9855. * @description wraps the $log method, allowing us to choose different
  9856. * treatment within ui-grid if we so desired. At present we only log
  9857. * debug messages if uiGridConstants.LOG_DEBUG_MESSAGES is set to true
  9858. *
  9859. */
  9860. logDebug: function() {
  9861. if ( uiGridConstants.LOG_DEBUG_MESSAGES ){
  9862. $log.debug.apply($log, arguments);
  9863. }
  9864. }
  9865. };
  9866. /**
  9867. * @ngdoc object
  9868. * @name focus
  9869. * @propertyOf ui.grid.service:GridUtil
  9870. * @description Provies a set of methods to set the document focus inside the grid.
  9871. * See {@link ui.grid.service:GridUtil.focus} for more information.
  9872. */
  9873. /**
  9874. * @ngdoc object
  9875. * @name ui.grid.service:GridUtil.focus
  9876. * @description Provies a set of methods to set the document focus inside the grid.
  9877. * Timeouts are utilized to ensure that the focus is invoked after any other event has been triggered.
  9878. * e.g. click events that need to run before the focus or
  9879. * inputs elements that are in a disabled state but are enabled when those events
  9880. * are triggered.
  9881. */
  9882. s.focus = {
  9883. queue: [],
  9884. //http://stackoverflow.com/questions/25596399/set-element-focus-in-angular-way
  9885. /**
  9886. * @ngdoc method
  9887. * @methodOf ui.grid.service:GridUtil.focus
  9888. * @name byId
  9889. * @description Sets the focus of the document to the given id value.
  9890. * If provided with the grid object it will automatically append the grid id.
  9891. * This is done to encourage unique dom id's as it allows for multiple grids on a
  9892. * page.
  9893. * @param {String} id the id of the dom element to set the focus on
  9894. * @param {Object=} Grid the grid object for this grid instance. See: {@link ui.grid.class:Grid}
  9895. * @param {Number} Grid.id the unique id for this grid. Already set on an initialized grid object.
  9896. * @returns {Promise} The `$timeout` promise that will be resolved once focus is set. If another focus is requested before this request is evaluated.
  9897. * then the promise will fail with the `'canceled'` reason.
  9898. */
  9899. byId: function (id, Grid) {
  9900. this._purgeQueue();
  9901. var promise = $timeout(function() {
  9902. var elementID = (Grid && Grid.id ? Grid.id + '-' : '') + id;
  9903. var element = $window.document.getElementById(elementID);
  9904. if (element) {
  9905. element.focus();
  9906. } else {
  9907. s.logWarn('[focus.byId] Element id ' + elementID + ' was not found.');
  9908. }
  9909. }, 0, false);
  9910. this.queue.push(promise);
  9911. return promise;
  9912. },
  9913. /**
  9914. * @ngdoc method
  9915. * @methodOf ui.grid.service:GridUtil.focus
  9916. * @name byElement
  9917. * @description Sets the focus of the document to the given dom element.
  9918. * @param {(element|angular.element)} element the DOM element to set the focus on
  9919. * @returns {Promise} The `$timeout` promise that will be resolved once focus is set. If another focus is requested before this request is evaluated.
  9920. * then the promise will fail with the `'canceled'` reason.
  9921. */
  9922. byElement: function(element){
  9923. if (!angular.isElement(element)){
  9924. s.logWarn("Trying to focus on an element that isn\'t an element.");
  9925. return $q.reject('not-element');
  9926. }
  9927. element = angular.element(element);
  9928. this._purgeQueue();
  9929. var promise = $timeout(function(){
  9930. if (element){
  9931. element[0].focus();
  9932. }
  9933. }, 0, false);
  9934. this.queue.push(promise);
  9935. return promise;
  9936. },
  9937. /**
  9938. * @ngdoc method
  9939. * @methodOf ui.grid.service:GridUtil.focus
  9940. * @name bySelector
  9941. * @description Sets the focus of the document to the given dom element.
  9942. * @param {(element|angular.element)} parentElement the parent/ancestor of the dom element that you are selecting using the query selector
  9943. * @param {String} querySelector finds the dom element using the {@link http://www.w3schools.com/jsref/met_document_queryselector.asp querySelector}
  9944. * @param {boolean} [aSync=false] If true then the selector will be querried inside of a timeout. Otherwise the selector will be querried imidately
  9945. * then the focus will be called.
  9946. * @returns {Promise} The `$timeout` promise that will be resolved once focus is set. If another focus is requested before this request is evaluated.
  9947. * then the promise will fail with the `'canceled'` reason.
  9948. */
  9949. bySelector: function(parentElement, querySelector, aSync){
  9950. var self = this;
  9951. if (!angular.isElement(parentElement)){
  9952. throw new Error("The parent element is not an element.");
  9953. }
  9954. // Ensure that this is an angular element.
  9955. // It is fine if this is already an angular element.
  9956. parentElement = angular.element(parentElement);
  9957. var focusBySelector = function(){
  9958. var element = parentElement[0].querySelector(querySelector);
  9959. return self.byElement(element);
  9960. };
  9961. this._purgeQueue();
  9962. if (aSync){ //Do this asynchronysly
  9963. var promise = $timeout(focusBySelector, 0, false);
  9964. this.queue.push(promise);
  9965. return promise;
  9966. } else {
  9967. return focusBySelector();
  9968. }
  9969. },
  9970. _purgeQueue: function(){
  9971. this.queue.forEach(function(element){
  9972. $timeout.cancel(element);
  9973. });
  9974. this.queue = [];
  9975. }
  9976. };
  9977. ['width', 'height'].forEach(function (name) {
  9978. var capsName = angular.uppercase(name.charAt(0)) + name.substr(1);
  9979. s['element' + capsName] = function (elem, extra) {
  9980. var e = elem;
  9981. if (e && typeof(e.length) !== 'undefined' && e.length) {
  9982. e = elem[0];
  9983. }
  9984. if (e && e !== null) {
  9985. var styles = getStyles(e);
  9986. return e.offsetWidth === 0 && rdisplayswap.test(styles.display) ?
  9987. s.swap(e, cssShow, function() {
  9988. return getWidthOrHeight(e, name, extra );
  9989. }) :
  9990. getWidthOrHeight( e, name, extra );
  9991. }
  9992. else {
  9993. return null;
  9994. }
  9995. };
  9996. s['outerElement' + capsName] = function (elem, margin) {
  9997. return elem ? s['element' + capsName].call(this, elem, margin ? 'margin' : 'border') : null;
  9998. };
  9999. });
  10000. // http://stackoverflow.com/a/24107550/888165
  10001. s.closestElm = function closestElm(el, selector) {
  10002. if (typeof(el.length) !== 'undefined' && el.length) {
  10003. el = el[0];
  10004. }
  10005. var matchesFn;
  10006. // find vendor prefix
  10007. ['matches','webkitMatchesSelector','mozMatchesSelector','msMatchesSelector','oMatchesSelector'].some(function(fn) {
  10008. if (typeof document.body[fn] === 'function') {
  10009. matchesFn = fn;
  10010. return true;
  10011. }
  10012. return false;
  10013. });
  10014. // traverse parents
  10015. var parent;
  10016. while (el !== null) {
  10017. parent = el.parentElement;
  10018. if (parent !== null && parent[matchesFn](selector)) {
  10019. return parent;
  10020. }
  10021. el = parent;
  10022. }
  10023. return null;
  10024. };
  10025. s.type = function (obj) {
  10026. var text = Function.prototype.toString.call(obj.constructor);
  10027. return text.match(/function (.*?)\(/)[1];
  10028. };
  10029. s.getBorderSize = function getBorderSize(elem, borderType) {
  10030. if (typeof(elem.length) !== 'undefined' && elem.length) {
  10031. elem = elem[0];
  10032. }
  10033. var styles = getStyles(elem);
  10034. // If a specific border is supplied, like 'top', read the 'borderTop' style property
  10035. if (borderType) {
  10036. borderType = 'border' + borderType.charAt(0).toUpperCase() + borderType.slice(1);
  10037. }
  10038. else {
  10039. borderType = 'border';
  10040. }
  10041. borderType += 'Width';
  10042. var val = parseInt(styles[borderType], 10);
  10043. if (isNaN(val)) {
  10044. return 0;
  10045. }
  10046. else {
  10047. return val;
  10048. }
  10049. };
  10050. // http://stackoverflow.com/a/22948274/888165
  10051. // TODO: Opera? Mobile?
  10052. s.detectBrowser = function detectBrowser() {
  10053. var userAgent = $window.navigator.userAgent;
  10054. var browsers = {chrome: /chrome/i, safari: /safari/i, firefox: /firefox/i, ie: /internet explorer|trident\//i};
  10055. for (var key in browsers) {
  10056. if (browsers[key].test(userAgent)) {
  10057. return key;
  10058. }
  10059. }
  10060. return 'unknown';
  10061. };
  10062. // Borrowed from https://github.com/othree/jquery.rtl-scroll-type
  10063. // Determine the scroll "type" this browser is using for RTL
  10064. s.rtlScrollType = function rtlScrollType() {
  10065. if (rtlScrollType.type) {
  10066. return rtlScrollType.type;
  10067. }
  10068. var definer = angular.element('<div dir="rtl" style="font-size: 14px; width: 1px; height: 1px; position: absolute; top: -1000px; overflow: scroll">A</div>')[0],
  10069. type = 'reverse';
  10070. document.body.appendChild(definer);
  10071. if (definer.scrollLeft > 0) {
  10072. type = 'default';
  10073. }
  10074. else {
  10075. definer.scrollLeft = 1;
  10076. if (definer.scrollLeft === 0) {
  10077. type = 'negative';
  10078. }
  10079. }
  10080. angular.element(definer).remove();
  10081. rtlScrollType.type = type;
  10082. return type;
  10083. };
  10084. /**
  10085. * @ngdoc method
  10086. * @name normalizeScrollLeft
  10087. * @methodOf ui.grid.service:GridUtil
  10088. *
  10089. * @param {element} element The element to get the `scrollLeft` from.
  10090. * @param {grid} grid - grid used to normalize (uses the rtl property)
  10091. *
  10092. * @returns {number} A normalized scrollLeft value for the current browser.
  10093. *
  10094. * @description
  10095. * Browsers currently handle RTL in different ways, resulting in inconsistent scrollLeft values. This method normalizes them
  10096. */
  10097. s.normalizeScrollLeft = function normalizeScrollLeft(element, grid) {
  10098. if (typeof(element.length) !== 'undefined' && element.length) {
  10099. element = element[0];
  10100. }
  10101. var scrollLeft = element.scrollLeft;
  10102. if (grid.isRTL()) {
  10103. switch (s.rtlScrollType()) {
  10104. case 'default':
  10105. return element.scrollWidth - scrollLeft - element.clientWidth;
  10106. case 'negative':
  10107. return Math.abs(scrollLeft);
  10108. case 'reverse':
  10109. return scrollLeft;
  10110. }
  10111. }
  10112. return scrollLeft;
  10113. };
  10114. /**
  10115. * @ngdoc method
  10116. * @name denormalizeScrollLeft
  10117. * @methodOf ui.grid.service:GridUtil
  10118. *
  10119. * @param {element} element The element to normalize the `scrollLeft` value for
  10120. * @param {number} scrollLeft The `scrollLeft` value to denormalize.
  10121. * @param {grid} grid The grid that owns the scroll event.
  10122. *
  10123. * @returns {number} A normalized scrollLeft value for the current browser.
  10124. *
  10125. * @description
  10126. * Browsers currently handle RTL in different ways, resulting in inconsistent scrollLeft values. This method denormalizes a value for the current browser.
  10127. */
  10128. s.denormalizeScrollLeft = function denormalizeScrollLeft(element, scrollLeft, grid) {
  10129. if (typeof(element.length) !== 'undefined' && element.length) {
  10130. element = element[0];
  10131. }
  10132. if (grid.isRTL()) {
  10133. switch (s.rtlScrollType()) {
  10134. case 'default':
  10135. // Get the max scroll for the element
  10136. var maxScrollLeft = element.scrollWidth - element.clientWidth;
  10137. // Subtract the current scroll amount from the max scroll
  10138. return maxScrollLeft - scrollLeft;
  10139. case 'negative':
  10140. return scrollLeft * -1;
  10141. case 'reverse':
  10142. return scrollLeft;
  10143. }
  10144. }
  10145. return scrollLeft;
  10146. };
  10147. /**
  10148. * @ngdoc method
  10149. * @name preEval
  10150. * @methodOf ui.grid.service:GridUtil
  10151. *
  10152. * @param {string} path Path to evaluate
  10153. *
  10154. * @returns {string} A path that is normalized.
  10155. *
  10156. * @description
  10157. * Takes a field path and converts it to bracket notation to allow for special characters in path
  10158. * @example
  10159. * <pre>
  10160. * gridUtil.preEval('property') == 'property'
  10161. * gridUtil.preEval('nested.deep.prop-erty') = "nested['deep']['prop-erty']"
  10162. * </pre>
  10163. */
  10164. s.preEval = function (path) {
  10165. var m = uiGridConstants.BRACKET_REGEXP.exec(path);
  10166. if (m) {
  10167. return (m[1] ? s.preEval(m[1]) : m[1]) + m[2] + (m[3] ? s.preEval(m[3]) : m[3]);
  10168. } else {
  10169. path = path.replace(uiGridConstants.APOS_REGEXP, '\\\'');
  10170. var parts = path.split(uiGridConstants.DOT_REGEXP);
  10171. var preparsed = [parts.shift()]; // first item must be var notation, thus skip
  10172. angular.forEach(parts, function (part) {
  10173. preparsed.push(part.replace(uiGridConstants.FUNC_REGEXP, '\']$1'));
  10174. });
  10175. return preparsed.join('[\'');
  10176. }
  10177. };
  10178. /**
  10179. * @ngdoc method
  10180. * @name debounce
  10181. * @methodOf ui.grid.service:GridUtil
  10182. *
  10183. * @param {function} func function to debounce
  10184. * @param {number} wait milliseconds to delay
  10185. * @param {boolean} immediate execute before delay
  10186. *
  10187. * @returns {function} A function that can be executed as debounced function
  10188. *
  10189. * @description
  10190. * Copied from https://github.com/shahata/angular-debounce
  10191. * Takes a function, decorates it to execute only 1 time after multiple calls, and returns the decorated function
  10192. * @example
  10193. * <pre>
  10194. * var debouncedFunc = gridUtil.debounce(function(){alert('debounced');}, 500);
  10195. * debouncedFunc();
  10196. * debouncedFunc();
  10197. * debouncedFunc();
  10198. * </pre>
  10199. */
  10200. s.debounce = function (func, wait, immediate) {
  10201. var timeout, args, context, result;
  10202. function debounce() {
  10203. /* jshint validthis:true */
  10204. context = this;
  10205. args = arguments;
  10206. var later = function () {
  10207. timeout = null;
  10208. if (!immediate) {
  10209. result = func.apply(context, args);
  10210. }
  10211. };
  10212. var callNow = immediate && !timeout;
  10213. if (timeout) {
  10214. $timeout.cancel(timeout);
  10215. }
  10216. timeout = $timeout(later, wait, false);
  10217. if (callNow) {
  10218. result = func.apply(context, args);
  10219. }
  10220. return result;
  10221. }
  10222. debounce.cancel = function () {
  10223. $timeout.cancel(timeout);
  10224. timeout = null;
  10225. };
  10226. return debounce;
  10227. };
  10228. /**
  10229. * @ngdoc method
  10230. * @name throttle
  10231. * @methodOf ui.grid.service:GridUtil
  10232. *
  10233. * @param {function} func function to throttle
  10234. * @param {number} wait milliseconds to delay after first trigger
  10235. * @param {Object} params to use in throttle.
  10236. *
  10237. * @returns {function} A function that can be executed as throttled function
  10238. *
  10239. * @description
  10240. * Adapted from debounce function (above)
  10241. * Potential keys for Params Object are:
  10242. * trailing (bool) - whether to trigger after throttle time ends if called multiple times
  10243. * Updated to use $interval rather than $timeout, as protractor (e2e tests) is able to work with $interval,
  10244. * but not with $timeout
  10245. *
  10246. * Note that when using throttle, you need to use throttle to create a new function upfront, then use the function
  10247. * return from that call each time you need to call throttle. If you call throttle itself repeatedly, the lastCall
  10248. * variable will get overwritten and the throttling won't work
  10249. *
  10250. * @example
  10251. * <pre>
  10252. * var throttledFunc = gridUtil.throttle(function(){console.log('throttled');}, 500, {trailing: true});
  10253. * throttledFunc(); //=> logs throttled
  10254. * throttledFunc(); //=> queues attempt to log throttled for ~500ms (since trailing param is truthy)
  10255. * throttledFunc(); //=> updates arguments to keep most-recent request, but does not do anything else.
  10256. * </pre>
  10257. */
  10258. s.throttle = function(func, wait, options){
  10259. options = options || {};
  10260. var lastCall = 0, queued = null, context, args;
  10261. function runFunc(endDate){
  10262. lastCall = +new Date();
  10263. func.apply(context, args);
  10264. $interval(function(){queued = null; }, 0, 1, false);
  10265. }
  10266. return function(){
  10267. /* jshint validthis:true */
  10268. context = this;
  10269. args = arguments;
  10270. if (queued === null){
  10271. var sinceLast = +new Date() - lastCall;
  10272. if (sinceLast > wait){
  10273. runFunc();
  10274. }
  10275. else if (options.trailing){
  10276. queued = $interval(runFunc, wait - sinceLast, 1, false);
  10277. }
  10278. }
  10279. };
  10280. };
  10281. s.on = {};
  10282. s.off = {};
  10283. s._events = {};
  10284. s.addOff = function (eventName) {
  10285. s.off[eventName] = function (elm, fn) {
  10286. var idx = s._events[eventName].indexOf(fn);
  10287. if (idx > 0) {
  10288. s._events[eventName].removeAt(idx);
  10289. }
  10290. };
  10291. };
  10292. var mouseWheeltoBind = ( 'onwheel' in document || document.documentMode >= 9 ) ? ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'],
  10293. nullLowestDeltaTimeout,
  10294. lowestDelta;
  10295. s.on.mousewheel = function (elm, fn) {
  10296. if (!elm || !fn) { return; }
  10297. var $elm = angular.element(elm);
  10298. // Store the line height and page height for this particular element
  10299. $elm.data('mousewheel-line-height', getLineHeight($elm));
  10300. $elm.data('mousewheel-page-height', s.elementHeight($elm));
  10301. if (!$elm.data('mousewheel-callbacks')) { $elm.data('mousewheel-callbacks', {}); }
  10302. var cbs = $elm.data('mousewheel-callbacks');
  10303. cbs[fn] = (Function.prototype.bind || bindPolyfill).call(mousewheelHandler, $elm[0], fn);
  10304. // Bind all the mousew heel events
  10305. for ( var i = mouseWheeltoBind.length; i; ) {
  10306. $elm.on(mouseWheeltoBind[--i], cbs[fn]);
  10307. }
  10308. $elm.on('$destroy', function unbindEvents() {
  10309. for ( var i = mouseWheeltoBind.length; i; ) {
  10310. $elm.off(mouseWheeltoBind[--i], cbs[fn]);
  10311. }
  10312. });
  10313. };
  10314. s.off.mousewheel = function (elm, fn) {
  10315. var $elm = angular.element(elm);
  10316. var cbs = $elm.data('mousewheel-callbacks');
  10317. var handler = cbs[fn];
  10318. if (handler) {
  10319. for ( var i = mouseWheeltoBind.length; i; ) {
  10320. $elm.off(mouseWheeltoBind[--i], handler);
  10321. }
  10322. }
  10323. delete cbs[fn];
  10324. if (Object.keys(cbs).length === 0) {
  10325. $elm.removeData('mousewheel-line-height');
  10326. $elm.removeData('mousewheel-page-height');
  10327. $elm.removeData('mousewheel-callbacks');
  10328. }
  10329. };
  10330. function mousewheelHandler(fn, event) {
  10331. var $elm = angular.element(this);
  10332. var delta = 0,
  10333. deltaX = 0,
  10334. deltaY = 0,
  10335. absDelta = 0,
  10336. offsetX = 0,
  10337. offsetY = 0;
  10338. // jQuery masks events
  10339. if (event.originalEvent) { event = event.originalEvent; }
  10340. if ( 'detail' in event ) { deltaY = event.detail * -1; }
  10341. if ( 'wheelDelta' in event ) { deltaY = event.wheelDelta; }
  10342. if ( 'wheelDeltaY' in event ) { deltaY = event.wheelDeltaY; }
  10343. if ( 'wheelDeltaX' in event ) { deltaX = event.wheelDeltaX * -1; }
  10344. // Firefox < 17 horizontal scrolling related to DOMMouseScroll event
  10345. if ( 'axis' in event && event.axis === event.HORIZONTAL_AXIS ) {
  10346. deltaX = deltaY * -1;
  10347. deltaY = 0;
  10348. }
  10349. // Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy
  10350. delta = deltaY === 0 ? deltaX : deltaY;
  10351. // New school wheel delta (wheel event)
  10352. if ( 'deltaY' in event ) {
  10353. deltaY = event.deltaY * -1;
  10354. delta = deltaY;
  10355. }
  10356. if ( 'deltaX' in event ) {
  10357. deltaX = event.deltaX;
  10358. if ( deltaY === 0 ) { delta = deltaX * -1; }
  10359. }
  10360. // No change actually happened, no reason to go any further
  10361. if ( deltaY === 0 && deltaX === 0 ) { return; }
  10362. // Need to convert lines and pages to pixels if we aren't already in pixels
  10363. // There are three delta modes:
  10364. // * deltaMode 0 is by pixels, nothing to do
  10365. // * deltaMode 1 is by lines
  10366. // * deltaMode 2 is by pages
  10367. if ( event.deltaMode === 1 ) {
  10368. var lineHeight = $elm.data('mousewheel-line-height');
  10369. delta *= lineHeight;
  10370. deltaY *= lineHeight;
  10371. deltaX *= lineHeight;
  10372. }
  10373. else if ( event.deltaMode === 2 ) {
  10374. var pageHeight = $elm.data('mousewheel-page-height');
  10375. delta *= pageHeight;
  10376. deltaY *= pageHeight;
  10377. deltaX *= pageHeight;
  10378. }
  10379. // Store lowest absolute delta to normalize the delta values
  10380. absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) );
  10381. if ( !lowestDelta || absDelta < lowestDelta ) {
  10382. lowestDelta = absDelta;
  10383. // Adjust older deltas if necessary
  10384. if ( shouldAdjustOldDeltas(event, absDelta) ) {
  10385. lowestDelta /= 40;
  10386. }
  10387. }
  10388. // Get a whole, normalized value for the deltas
  10389. delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta);
  10390. deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta);
  10391. deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta);
  10392. // Normalise offsetX and offsetY properties
  10393. // if ($elm[0].getBoundingClientRect ) {
  10394. // var boundingRect = $(elm)[0].getBoundingClientRect();
  10395. // offsetX = event.clientX - boundingRect.left;
  10396. // offsetY = event.clientY - boundingRect.top;
  10397. // }
  10398. // event.deltaX = deltaX;
  10399. // event.deltaY = deltaY;
  10400. // event.deltaFactor = lowestDelta;
  10401. var newEvent = {
  10402. originalEvent: event,
  10403. deltaX: deltaX,
  10404. deltaY: deltaY,
  10405. deltaFactor: lowestDelta,
  10406. preventDefault: function () { event.preventDefault(); },
  10407. stopPropagation: function () { event.stopPropagation(); }
  10408. };
  10409. // Clearout lowestDelta after sometime to better
  10410. // handle multiple device types that give
  10411. // a different lowestDelta
  10412. // Ex: trackpad = 3 and mouse wheel = 120
  10413. if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); }
  10414. nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200);
  10415. fn.call($elm[0], newEvent);
  10416. }
  10417. function nullLowestDelta() {
  10418. lowestDelta = null;
  10419. }
  10420. function shouldAdjustOldDeltas(orgEvent, absDelta) {
  10421. // If this is an older event and the delta is divisable by 120,
  10422. // then we are assuming that the browser is treating this as an
  10423. // older mouse wheel event and that we should divide the deltas
  10424. // by 40 to try and get a more usable deltaFactor.
  10425. // Side note, this actually impacts the reported scroll distance
  10426. // in older browsers and can cause scrolling to be slower than native.
  10427. // Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false.
  10428. return orgEvent.type === 'mousewheel' && absDelta % 120 === 0;
  10429. }
  10430. return s;
  10431. }]);
  10432. // Add 'px' to the end of a number string if it doesn't have it already
  10433. module.filter('px', function() {
  10434. return function(str) {
  10435. if (str.match(/^[\d\.]+$/)) {
  10436. return str + 'px';
  10437. }
  10438. else {
  10439. return str;
  10440. }
  10441. };
  10442. });
  10443. })();
  10444. /**
  10445. * @ngdoc overview
  10446. * @name ui.grid.i18n
  10447. * @description
  10448. *
  10449. * # ui.grid.i18n
  10450. * This module provides i18n functions to ui.grid and any application that wants to use it
  10451. *
  10452. * <div doc-module-components="ui.grid.i18n"></div>
  10453. */
  10454. (function () {
  10455. var DIRECTIVE_ALIASES = ['uiT', 'uiTranslate'];
  10456. var FILTER_ALIASES = ['t', 'uiTranslate'];
  10457. var module = angular.module('ui.grid.i18n');
  10458. /**
  10459. * @ngdoc object
  10460. * @name ui.grid.i18n.constant:i18nConstants
  10461. *
  10462. * @description constants available in i18n module
  10463. */
  10464. module.constant('i18nConstants', {
  10465. MISSING: '[MISSING]',
  10466. UPDATE_EVENT: '$uiI18n',
  10467. LOCALE_DIRECTIVE_ALIAS: 'uiI18n',
  10468. // default to english
  10469. DEFAULT_LANG: 'en'
  10470. });
  10471. // module.config(['$provide', function($provide) {
  10472. // $provide.decorator('i18nService', ['$delegate', function($delegate) {}])}]);
  10473. /**
  10474. * @ngdoc service
  10475. * @name ui.grid.i18n.service:i18nService
  10476. *
  10477. * @description Services for i18n
  10478. */
  10479. module.service('i18nService', ['$log', 'i18nConstants', '$rootScope',
  10480. function ($log, i18nConstants, $rootScope) {
  10481. var langCache = {
  10482. _langs: {},
  10483. current: null,
  10484. get: function (lang) {
  10485. return this._langs[lang.toLowerCase()];
  10486. },
  10487. add: function (lang, strings) {
  10488. var lower = lang.toLowerCase();
  10489. if (!this._langs[lower]) {
  10490. this._langs[lower] = {};
  10491. }
  10492. angular.extend(this._langs[lower], strings);
  10493. },
  10494. getAllLangs: function () {
  10495. var langs = [];
  10496. if (!this._langs) {
  10497. return langs;
  10498. }
  10499. for (var key in this._langs) {
  10500. langs.push(key);
  10501. }
  10502. return langs;
  10503. },
  10504. setCurrent: function (lang) {
  10505. this.current = lang.toLowerCase();
  10506. },
  10507. getCurrentLang: function () {
  10508. return this.current;
  10509. }
  10510. };
  10511. var service = {
  10512. /**
  10513. * @ngdoc service
  10514. * @name add
  10515. * @methodOf ui.grid.i18n.service:i18nService
  10516. * @description Adds the languages and strings to the cache. Decorate this service to
  10517. * add more translation strings
  10518. * @param {string} lang language to add
  10519. * @param {object} stringMaps of strings to add grouped by property names
  10520. * @example
  10521. * <pre>
  10522. * i18nService.add('en', {
  10523. * aggregate: {
  10524. * label1: 'items',
  10525. * label2: 'some more items'
  10526. * }
  10527. * },
  10528. * groupPanel: {
  10529. * description: 'Drag a column header here and drop it to group by that column.'
  10530. * }
  10531. * }
  10532. * </pre>
  10533. */
  10534. add: function (langs, stringMaps) {
  10535. if (typeof(langs) === 'object') {
  10536. angular.forEach(langs, function (lang) {
  10537. if (lang) {
  10538. langCache.add(lang, stringMaps);
  10539. }
  10540. });
  10541. } else {
  10542. langCache.add(langs, stringMaps);
  10543. }
  10544. },
  10545. /**
  10546. * @ngdoc service
  10547. * @name getAllLangs
  10548. * @methodOf ui.grid.i18n.service:i18nService
  10549. * @description return all currently loaded languages
  10550. * @returns {array} string
  10551. */
  10552. getAllLangs: function () {
  10553. return langCache.getAllLangs();
  10554. },
  10555. /**
  10556. * @ngdoc service
  10557. * @name get
  10558. * @methodOf ui.grid.i18n.service:i18nService
  10559. * @description return all currently loaded languages
  10560. * @param {string} lang to return. If not specified, returns current language
  10561. * @returns {object} the translation string maps for the language
  10562. */
  10563. get: function (lang) {
  10564. var language = lang ? lang : service.getCurrentLang();
  10565. return langCache.get(language);
  10566. },
  10567. /**
  10568. * @ngdoc service
  10569. * @name getSafeText
  10570. * @methodOf ui.grid.i18n.service:i18nService
  10571. * @description returns the text specified in the path or a Missing text if text is not found
  10572. * @param {String} path property path to use for retrieving text from string map
  10573. * @param {String} [lang] to return. If not specified, returns current language
  10574. * @returns {object} the translation for the path
  10575. * @example
  10576. * <pre>
  10577. * i18nService.getSafeText('sort.ascending')
  10578. * </pre>
  10579. */
  10580. getSafeText: function (path, lang) {
  10581. var language = lang || service.getCurrentLang();
  10582. var trans = langCache.get(language);
  10583. if (!trans) {
  10584. return i18nConstants.MISSING;
  10585. }
  10586. var paths = path.split('.');
  10587. var current = trans;
  10588. for (var i = 0; i < paths.length; ++i) {
  10589. if (current[paths[i]] === undefined || current[paths[i]] === null) {
  10590. return i18nConstants.MISSING;
  10591. } else {
  10592. current = current[paths[i]];
  10593. }
  10594. }
  10595. return current;
  10596. },
  10597. /**
  10598. * @ngdoc service
  10599. * @name setCurrentLang
  10600. * @methodOf ui.grid.i18n.service:i18nService
  10601. * @description sets the current language to use in the application
  10602. * $broadcasts the i18nConstants.UPDATE_EVENT on the $rootScope
  10603. * @param {string} lang to set
  10604. * @example
  10605. * <pre>
  10606. * i18nService.setCurrentLang('fr');
  10607. * </pre>
  10608. */
  10609. setCurrentLang: function (lang) {
  10610. if (lang) {
  10611. langCache.setCurrent(lang);
  10612. $rootScope.$broadcast(i18nConstants.UPDATE_EVENT);
  10613. }
  10614. },
  10615. /**
  10616. * @ngdoc service
  10617. * @name getCurrentLang
  10618. * @methodOf ui.grid.i18n.service:i18nService
  10619. * @description returns the current language used in the application
  10620. */
  10621. getCurrentLang: function () {
  10622. var lang = langCache.getCurrentLang();
  10623. if (!lang) {
  10624. lang = i18nConstants.DEFAULT_LANG;
  10625. langCache.setCurrent(lang);
  10626. }
  10627. return lang;
  10628. }
  10629. };
  10630. return service;
  10631. }]);
  10632. var localeDirective = function (i18nService, i18nConstants) {
  10633. return {
  10634. compile: function () {
  10635. return {
  10636. pre: function ($scope, $elm, $attrs) {
  10637. var alias = i18nConstants.LOCALE_DIRECTIVE_ALIAS;
  10638. // check for watchable property
  10639. var lang = $scope.$eval($attrs[alias]);
  10640. if (lang) {
  10641. $scope.$watch($attrs[alias], function () {
  10642. i18nService.setCurrentLang(lang);
  10643. });
  10644. } else if ($attrs.$$observers) {
  10645. $attrs.$observe(alias, function () {
  10646. i18nService.setCurrentLang($attrs[alias] || i18nConstants.DEFAULT_LANG);
  10647. });
  10648. }
  10649. }
  10650. };
  10651. }
  10652. };
  10653. };
  10654. module.directive('uiI18n', ['i18nService', 'i18nConstants', localeDirective]);
  10655. // directive syntax
  10656. var uitDirective = function ($parse, i18nService, i18nConstants) {
  10657. return {
  10658. restrict: 'EA',
  10659. compile: function () {
  10660. return {
  10661. pre: function ($scope, $elm, $attrs) {
  10662. var alias1 = DIRECTIVE_ALIASES[0],
  10663. alias2 = DIRECTIVE_ALIASES[1];
  10664. var token = $attrs[alias1] || $attrs[alias2] || $elm.html();
  10665. var missing = i18nConstants.MISSING + token;
  10666. var observer;
  10667. if ($attrs.$$observers) {
  10668. var prop = $attrs[alias1] ? alias1 : alias2;
  10669. observer = $attrs.$observe(prop, function (result) {
  10670. if (result) {
  10671. $elm.html($parse(result)(i18nService.getCurrentLang()) || missing);
  10672. }
  10673. });
  10674. }
  10675. var getter = $parse(token);
  10676. var listener = $scope.$on(i18nConstants.UPDATE_EVENT, function (evt) {
  10677. if (observer) {
  10678. observer($attrs[alias1] || $attrs[alias2]);
  10679. } else {
  10680. // set text based on i18n current language
  10681. $elm.html(getter(i18nService.get()) || missing);
  10682. }
  10683. });
  10684. $scope.$on('$destroy', listener);
  10685. $elm.html(getter(i18nService.get()) || missing);
  10686. }
  10687. };
  10688. }
  10689. };
  10690. };
  10691. angular.forEach( DIRECTIVE_ALIASES, function ( alias ) {
  10692. module.directive( alias, ['$parse', 'i18nService', 'i18nConstants', uitDirective] );
  10693. } );
  10694. // optional filter syntax
  10695. var uitFilter = function ($parse, i18nService, i18nConstants) {
  10696. return function (data) {
  10697. var getter = $parse(data);
  10698. // set text based on i18n current language
  10699. return getter(i18nService.get()) || i18nConstants.MISSING + data;
  10700. };
  10701. };
  10702. angular.forEach( FILTER_ALIASES, function ( alias ) {
  10703. module.filter( alias, ['$parse', 'i18nService', 'i18nConstants', uitFilter] );
  10704. } );
  10705. })();
  10706. (function () {
  10707. angular.module('ui.grid').config(['$provide', function($provide) {
  10708. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  10709. $delegate.add('en', {
  10710. headerCell: {
  10711. aria: {
  10712. defaultFilterLabel: 'Filter for column',
  10713. removeFilter: 'Remove Filter',
  10714. columnMenuButtonLabel: 'Column Menu',
  10715. column: 'Column'
  10716. },
  10717. priority: 'Priority:',
  10718. filterLabel: "Filter for column: "
  10719. },
  10720. aggregate: {
  10721. label: 'items'
  10722. },
  10723. groupPanel: {
  10724. description: 'Drag a column header here and drop it to group by that column.'
  10725. },
  10726. search: {
  10727. aria: {
  10728. selected: 'Row selected',
  10729. notSelected: 'Row not selected'
  10730. },
  10731. placeholder: 'Search...',
  10732. showingItems: 'Showing Items:',
  10733. selectedItems: 'Selected Items:',
  10734. totalItems: 'Total Items:',
  10735. size: 'Page Size:',
  10736. first: 'First Page',
  10737. next: 'Next Page',
  10738. previous: 'Previous Page',
  10739. last: 'Last Page'
  10740. },
  10741. menu: {
  10742. text: 'Choose Columns:'
  10743. },
  10744. sort: {
  10745. ascending: 'Sort Ascending',
  10746. descending: 'Sort Descending',
  10747. none: 'Sort None',
  10748. remove: 'Remove Sort'
  10749. },
  10750. column: {
  10751. hide: 'Hide Column'
  10752. },
  10753. aggregation: {
  10754. count: 'total rows: ',
  10755. sum: 'total: ',
  10756. avg: 'avg: ',
  10757. min: 'min: ',
  10758. max: 'max: '
  10759. },
  10760. pinning: {
  10761. pinLeft: 'Pin Left',
  10762. pinRight: 'Pin Right',
  10763. unpin: 'Unpin'
  10764. },
  10765. columnMenu: {
  10766. close: 'Close'
  10767. },
  10768. gridMenu: {
  10769. aria: {
  10770. buttonLabel: 'Grid Menu'
  10771. },
  10772. columns: 'Columns:',
  10773. importerTitle: 'Import file',
  10774. exporterAllAsCsv: 'Export all data as csv',
  10775. exporterVisibleAsCsv: 'Export visible data as csv',
  10776. exporterSelectedAsCsv: 'Export selected data as csv',
  10777. exporterAllAsPdf: 'Export all data as pdf',
  10778. exporterVisibleAsPdf: 'Export visible data as pdf',
  10779. exporterSelectedAsPdf: 'Export selected data as pdf',
  10780. exporterAllAsExcel: 'Export all data as excel',
  10781. exporterVisibleAsExcel: 'Export visible data as excel',
  10782. exporterSelectedAsExcel: 'Export selected data as excel',
  10783. clearAllFilters: 'Clear all filters'
  10784. },
  10785. importer: {
  10786. noHeaders: 'Column names were unable to be derived, does the file have a header?',
  10787. noObjects: 'Objects were not able to be derived, was there data in the file other than headers?',
  10788. invalidCsv: 'File was unable to be processed, is it valid CSV?',
  10789. invalidJson: 'File was unable to be processed, is it valid Json?',
  10790. jsonNotArray: 'Imported json file must contain an array, aborting.'
  10791. },
  10792. pagination: {
  10793. aria: {
  10794. pageToFirst: 'Page to first',
  10795. pageBack: 'Page back',
  10796. pageSelected: 'Selected page',
  10797. pageForward: 'Page forward',
  10798. pageToLast: 'Page to last'
  10799. },
  10800. sizes: 'items per page',
  10801. totalItems: 'items',
  10802. through: 'through',
  10803. of: 'of'
  10804. },
  10805. grouping: {
  10806. group: 'Group',
  10807. ungroup: 'Ungroup',
  10808. aggregate_count: 'Agg: Count',
  10809. aggregate_sum: 'Agg: Sum',
  10810. aggregate_max: 'Agg: Max',
  10811. aggregate_min: 'Agg: Min',
  10812. aggregate_avg: 'Agg: Avg',
  10813. aggregate_remove: 'Agg: Remove'
  10814. },
  10815. validate: {
  10816. error: 'Error:',
  10817. minLength: 'Value should be at least THRESHOLD characters long.',
  10818. maxLength: 'Value should be at most THRESHOLD characters long.',
  10819. required: 'A value is needed.'
  10820. }
  10821. });
  10822. return $delegate;
  10823. }]);
  10824. }]);
  10825. })();
  10826. angular.module('ui.grid').run(['$templateCache', function($templateCache) {
  10827. 'use strict';
  10828. $templateCache.put('ui-grid/ui-grid-filter',
  10829. "<div class=\"ui-grid-filter-container\" ng-style=\"col.extraStyle\" ng-repeat=\"colFilter in col.filters\" ng-class=\"{'ui-grid-filter-cancel-button-hidden' : colFilter.disableCancelFilterButton === true }\"><div ng-if=\"colFilter.type !== 'select'\"><input type=\"text\" class=\"ui-grid-filter-input ui-grid-filter-input-{{$index}}\" ng-model=\"colFilter.term\" ng-attr-placeholder=\"{{colFilter.placeholder || ''}}\" aria-label=\"{{colFilter.ariaLabel || aria.defaultFilterLabel}}\"><div role=\"button\" class=\"ui-grid-filter-button\" ng-click=\"removeFilter(colFilter, $index)\" ng-if=\"!colFilter.disableCancelFilterButton\" ng-disabled=\"colFilter.term === undefined || colFilter.term === null || colFilter.term === ''\" ng-show=\"colFilter.term !== undefined && colFilter.term !== null && colFilter.term !== ''\"><i class=\"ui-grid-icon-cancel\" ui-grid-one-bind-aria-label=\"aria.removeFilter\">&nbsp;</i></div></div><div ng-if=\"colFilter.type === 'select'\"><select class=\"ui-grid-filter-select ui-grid-filter-input-{{$index}}\" ng-model=\"colFilter.term\" ng-show=\"colFilter.selectOptions.length > 0\" ng-attr-placeholder=\"{{colFilter.placeholder || aria.defaultFilterLabel}}\" aria-label=\"{{colFilter.ariaLabel || ''}}\" ng-options=\"option.value as option.label for option in colFilter.selectOptions\"><option value=\"\"></option></select><div role=\"button\" class=\"ui-grid-filter-button-select\" ng-click=\"removeFilter(colFilter, $index)\" ng-if=\"!colFilter.disableCancelFilterButton\" ng-disabled=\"colFilter.term === undefined || colFilter.term === null || colFilter.term === ''\" ng-show=\"colFilter.term !== undefined && colFilter.term != null\"><i class=\"ui-grid-icon-cancel\" ui-grid-one-bind-aria-label=\"aria.removeFilter\">&nbsp;</i></div></div></div>"
  10830. );
  10831. $templateCache.put('ui-grid/ui-grid-footer',
  10832. "<div class=\"ui-grid-footer-panel ui-grid-footer-aggregates-row\"><!-- tfooter --><div class=\"ui-grid-footer ui-grid-footer-viewport\"><div class=\"ui-grid-footer-canvas\"><div class=\"ui-grid-footer-cell-wrapper\" ng-style=\"colContainer.headerCellWrapperStyle()\"><div role=\"row\" class=\"ui-grid-footer-cell-row\"><div ui-grid-footer-cell role=\"gridcell\" ng-repeat=\"col in colContainer.renderedColumns track by col.uid\" col=\"col\" render-index=\"$index\" class=\"ui-grid-footer-cell ui-grid-clearfix\"></div></div></div></div></div></div>"
  10833. );
  10834. $templateCache.put('ui-grid/ui-grid-grid-footer',
  10835. "<div class=\"ui-grid-footer-info ui-grid-grid-footer\"><span>{{'search.totalItems' | t}} {{grid.rows.length}}</span> <span ng-if=\"grid.renderContainers.body.visibleRowCache.length !== grid.rows.length\" class=\"ngLabel\">({{\"search.showingItems\" | t}} {{grid.renderContainers.body.visibleRowCache.length}})</span></div>"
  10836. );
  10837. $templateCache.put('ui-grid/ui-grid-header',
  10838. "<div role=\"rowgroup\" class=\"ui-grid-header\"><!-- theader --><div class=\"ui-grid-top-panel\"><div class=\"ui-grid-header-viewport\"><div class=\"ui-grid-header-canvas\"><div class=\"ui-grid-header-cell-wrapper\" ng-style=\"colContainer.headerCellWrapperStyle()\"><div role=\"row\" class=\"ui-grid-header-cell-row\"><div class=\"ui-grid-header-cell ui-grid-clearfix\" ng-repeat=\"col in colContainer.renderedColumns track by col.uid\" ui-grid-header-cell col=\"col\" render-index=\"$index\"></div></div></div></div></div></div></div>"
  10839. );
  10840. $templateCache.put('ui-grid/ui-grid-menu-button',
  10841. "<div class=\"ui-grid-menu-button\"><div role=\"button\" ui-grid-one-bind-id-grid=\"'grid-menu'\" class=\"ui-grid-icon-container\" ng-click=\"toggleMenu()\" aria-haspopup=\"true\"><i class=\"ui-grid-icon-menu\" ui-grid-one-bind-aria-label=\"i18n.aria.buttonLabel\">&nbsp;</i></div><div ui-grid-menu menu-items=\"menuItems\"></div></div>"
  10842. );
  10843. $templateCache.put('ui-grid/ui-grid-no-header',
  10844. "<div class=\"ui-grid-top-panel\"></div>"
  10845. );
  10846. $templateCache.put('ui-grid/ui-grid-row',
  10847. "<div ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.uid\" ui-grid-one-bind-id-grid=\"rowRenderIndex + '-' + col.uid + '-cell'\" class=\"ui-grid-cell\" ng-class=\"{ 'ui-grid-row-header-cell': col.isRowHeader }\" role=\"{{col.isRowHeader ? 'rowheader' : 'gridcell'}}\" ui-grid-cell></div>"
  10848. );
  10849. $templateCache.put('ui-grid/ui-grid',
  10850. "<div ui-i18n=\"en\" class=\"ui-grid\"><!-- TODO (c0bra): add \"scoped\" attr here, eventually? --><style ui-grid-style>.grid{{ grid.id }} {\n" +
  10851. " /* Styles for the grid */\n" +
  10852. " }\n" +
  10853. "\n" +
  10854. " .grid{{ grid.id }} .ui-grid-row, .grid{{ grid.id }} .ui-grid-cell, .grid{{ grid.id }} .ui-grid-cell .ui-grid-vertical-bar {\n" +
  10855. " height: {{ grid.options.rowHeight }}px;\n" +
  10856. " }\n" +
  10857. "\n" +
  10858. " .grid{{ grid.id }} .ui-grid-row:last-child .ui-grid-cell {\n" +
  10859. " border-bottom-width: {{ (((grid.getVisibleRowCount() * grid.options.rowHeight) < grid.getViewportHeight()) && '1') || '0' }}px;\n" +
  10860. " }\n" +
  10861. "\n" +
  10862. " {{ grid.verticalScrollbarStyles }}\n" +
  10863. " {{ grid.horizontalScrollbarStyles }}\n" +
  10864. "\n" +
  10865. " /*\n" +
  10866. " .ui-grid[dir=rtl] .ui-grid-viewport {\n" +
  10867. " padding-left: {{ grid.verticalScrollbarWidth }}px;\n" +
  10868. " }\n" +
  10869. " */\n" +
  10870. "\n" +
  10871. " {{ grid.customStyles }}</style><div class=\"ui-grid-contents-wrapper\" role=\"grid\"><div ui-grid-menu-button ng-if=\"grid.options.enableGridMenu\"></div><div ng-if=\"grid.hasLeftContainer()\" style=\"width: 0\" ui-grid-pinned-container=\"'left'\"></div><div ui-grid-render-container container-id=\"'body'\" col-container-name=\"'body'\" row-container-name=\"'body'\" bind-scroll-horizontal=\"true\" bind-scroll-vertical=\"true\" enable-horizontal-scrollbar=\"grid.options.enableHorizontalScrollbar\" enable-vertical-scrollbar=\"grid.options.enableVerticalScrollbar\"></div><div ng-if=\"grid.hasRightContainer()\" style=\"width: 0\" ui-grid-pinned-container=\"'right'\"></div><div ui-grid-grid-footer ng-if=\"grid.options.showGridFooter\"></div><div ui-grid-column-menu ng-if=\"grid.options.enableColumnMenus\"></div><div ng-transclude></div></div></div>"
  10872. );
  10873. $templateCache.put('ui-grid/uiGridCell',
  10874. "<div class=\"ui-grid-cell-contents\" title=\"TOOLTIP\">{{COL_FIELD CUSTOM_FILTERS}}</div>"
  10875. );
  10876. $templateCache.put('ui-grid/uiGridColumnMenu',
  10877. "<div class=\"ui-grid-column-menu\"><div ui-grid-menu menu-items=\"menuItems\"><!-- <div class=\"ui-grid-column-menu\">\n" +
  10878. " <div class=\"inner\" ng-show=\"menuShown\">\n" +
  10879. " <ul>\n" +
  10880. " <div ng-show=\"grid.options.enableSorting\">\n" +
  10881. " <li ng-click=\"sortColumn($event, asc)\" ng-class=\"{ 'selected' : col.sort.direction == asc }\"><i class=\"ui-grid-icon-sort-alt-up\"></i> Sort Ascending</li>\n" +
  10882. " <li ng-click=\"sortColumn($event, desc)\" ng-class=\"{ 'selected' : col.sort.direction == desc }\"><i class=\"ui-grid-icon-sort-alt-down\"></i> Sort Descending</li>\n" +
  10883. " <li ng-show=\"col.sort.direction\" ng-click=\"unsortColumn()\"><i class=\"ui-grid-icon-cancel\"></i> Remove Sort</li>\n" +
  10884. " </div>\n" +
  10885. " </ul>\n" +
  10886. " </div>\n" +
  10887. " </div> --></div></div>"
  10888. );
  10889. $templateCache.put('ui-grid/uiGridFooterCell',
  10890. "<div class=\"ui-grid-cell-contents\" col-index=\"renderIndex\"><div>{{ col.getAggregationText() + ( col.getAggregationValue() CUSTOM_FILTERS ) }}</div></div>"
  10891. );
  10892. $templateCache.put('ui-grid/uiGridHeaderCell',
  10893. "<div role=\"columnheader\" ng-class=\"{ 'sortable': sortable, 'ui-grid-header-cell-last-col': isLastCol }\" ui-grid-one-bind-aria-labelledby-grid=\"col.uid + '-header-text ' + col.uid + '-sortdir-text'\" aria-sort=\"{{col.sort.direction == asc ? 'ascending' : ( col.sort.direction == desc ? 'descending' : (!col.sort.direction ? 'none' : 'other'))}}\"><div role=\"button\" tabindex=\"0\" ng-keydown=\"handleKeyDown($event)\" class=\"ui-grid-cell-contents ui-grid-header-cell-primary-focus\" col-index=\"renderIndex\" title=\"TOOLTIP\"><span class=\"ui-grid-header-cell-label\" ui-grid-one-bind-id-grid=\"col.uid + '-header-text'\">{{ col.displayName CUSTOM_FILTERS }}</span> <span ui-grid-one-bind-id-grid=\"col.uid + '-sortdir-text'\" ui-grid-visible=\"col.sort.direction\" aria-label=\"{{getSortDirectionAriaLabel()}}\"><i ng-class=\"{ 'ui-grid-icon-up-dir': col.sort.direction == asc, 'ui-grid-icon-down-dir': col.sort.direction == desc, 'ui-grid-icon-blank': !col.sort.direction }\" title=\"{{isSortPriorityVisible() ? i18n.headerCell.priority + ' ' + ( col.sort.priority + 1 ) : null}}\" aria-hidden=\"true\"></i> <sub ui-grid-visible=\"isSortPriorityVisible()\" class=\"ui-grid-sort-priority-number\">{{col.sort.priority + 1}}</sub></span></div><div role=\"button\" tabindex=\"0\" ui-grid-one-bind-id-grid=\"col.uid + '-menu-button'\" class=\"ui-grid-column-menu-button\" ng-if=\"grid.options.enableColumnMenus && !col.isRowHeader && col.colDef.enableColumnMenu !== false\" ng-click=\"toggleMenu($event)\" ng-keydown=\"headerCellArrowKeyDown($event)\" ui-grid-one-bind-aria-label=\"i18n.headerCell.aria.columnMenuButtonLabel\" aria-haspopup=\"true\"><i class=\"ui-grid-icon-angle-down\" aria-hidden=\"true\">&nbsp;</i></div><div ui-grid-filter></div></div>"
  10894. );
  10895. $templateCache.put('ui-grid/uiGridMenu',
  10896. "<div class=\"ui-grid-menu\" ng-show=\"shown\"><style ui-grid-style>{{dynamicStyles}}</style><div class=\"ui-grid-menu-mid\" ng-show=\"shownMid\"><div class=\"ui-grid-menu-inner\" ng-if=\"shown\"><ul role=\"menu\" class=\"ui-grid-menu-items\"><li ng-repeat=\"item in menuItems\" role=\"menuitem\" ui-grid-menu-item ui-grid-one-bind-id=\"'menuitem-'+$index\" action=\"item.action\" name=\"item.title\" active=\"item.active\" icon=\"item.icon\" shown=\"item.shown\" context=\"item.context\" template-url=\"item.templateUrl\" leave-open=\"item.leaveOpen\" screen-reader-only=\"item.screenReaderOnly\"></li></ul></div></div></div>"
  10897. );
  10898. $templateCache.put('ui-grid/uiGridMenuItem',
  10899. "<button type=\"button\" class=\"ui-grid-menu-item\" ng-click=\"itemAction($event, title)\" ng-show=\"itemShown()\" ng-class=\"{ 'ui-grid-menu-item-active': active(), 'ui-grid-sr-only': (!focus && screenReaderOnly) }\" aria-pressed=\"{{active()}}\" tabindex=\"0\" ng-focus=\"focus=true\" ng-blur=\"focus=false\"><i ng-class=\"icon\" aria-hidden=\"true\">&nbsp;</i> {{ label() }}</button>"
  10900. );
  10901. $templateCache.put('ui-grid/uiGridRenderContainer',
  10902. "<div role=\"presentation\" ui-grid-one-bind-id-grid=\"'grid-container'\" class=\"ui-grid-render-container\" ng-style=\"{ 'margin-left': colContainer.getMargin('left') + 'px', 'margin-right': colContainer.getMargin('right') + 'px' }\"><!-- All of these dom elements are replaced in place --><div ui-grid-header></div><div ui-grid-viewport></div><div ng-if=\"colContainer.needsHScrollbarPlaceholder()\" class=\"ui-grid-scrollbar-placeholder\" ng-style=\"{height:colContainer.grid.scrollbarHeight + 'px'}\"></div><ui-grid-footer ng-if=\"grid.options.showColumnFooter\"></ui-grid-footer></div>"
  10903. );
  10904. $templateCache.put('ui-grid/uiGridViewport',
  10905. "<div role=\"rowgroup\" class=\"ui-grid-viewport\" ng-style=\"colContainer.getViewportStyle()\"><!-- tbody --><div class=\"ui-grid-canvas\"><div ng-repeat=\"(rowRenderIndex, row) in rowContainer.renderedRows track by $index\" class=\"ui-grid-row\" ng-style=\"Viewport.rowStyle(rowRenderIndex)\"><div role=\"row\" ui-grid-row=\"row\" row-render-index=\"rowRenderIndex\"></div></div></div></div>"
  10906. );
  10907. $templateCache.put('ui-grid/cellEditor',
  10908. "<div><form name=\"inputForm\"><input type=\"INPUT_TYPE\" ng-class=\"'colt' + col.uid\" ui-grid-editor ng-model=\"MODEL_COL_FIELD\"></form></div>"
  10909. );
  10910. $templateCache.put('ui-grid/dropdownEditor',
  10911. "<div><form name=\"inputForm\"><select ng-class=\"'colt' + col.uid\" ui-grid-edit-dropdown ng-model=\"MODEL_COL_FIELD\" ng-options=\"field[editDropdownIdLabel] as field[editDropdownValueLabel] CUSTOM_FILTERS for field in editDropdownOptionsArray\"></select></form></div>"
  10912. );
  10913. $templateCache.put('ui-grid/fileChooserEditor',
  10914. "<div><form name=\"inputForm\"><input ng-class=\"'colt' + col.uid\" ui-grid-edit-file-chooser type=\"file\" id=\"files\" name=\"files[]\" ng-model=\"MODEL_COL_FIELD\"></form></div>"
  10915. );
  10916. $templateCache.put('ui-grid/emptyBaseLayerContainer',
  10917. "<div class=\"ui-grid-empty-base-layer-container ui-grid-canvas\"><div class=\"ui-grid-row\" ng-repeat=\"(rowRenderIndex, row) in grid.baseLayer.emptyRows track by $index\" ng-style=\"Viewport.rowStyle(rowRenderIndex)\"><div><div><div ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name\" class=\"ui-grid-cell {{ col.getColClass(false) }}\"></div></div></div></div></div>"
  10918. );
  10919. $templateCache.put('ui-grid/expandableRow',
  10920. "<div ui-grid-expandable-row ng-if=\"expandableRow.shouldRenderExpand()\" class=\"expandableRow\" style=\"float:left; margin-top: 1px; margin-bottom: 1px\" ng-style=\"{width: (grid.renderContainers.body.getCanvasWidth()) + 'px', height: row.expandedRowHeight + 'px'}\"></div>"
  10921. );
  10922. $templateCache.put('ui-grid/expandableRowHeader',
  10923. "<div class=\"ui-grid-row-header-cell ui-grid-expandable-buttons-cell\"><div class=\"ui-grid-cell-contents\"><i ng-if=\"!(row.groupHeader==true || row.entity.subGridOptions.disableRowExpandable)\" ng-class=\"{ 'ui-grid-icon-plus-squared' : !row.isExpanded, 'ui-grid-icon-minus-squared' : row.isExpanded }\" ng-click=\"grid.api.expandable.toggleRowExpansion(row.entity)\"></i></div></div>"
  10924. );
  10925. $templateCache.put('ui-grid/expandableScrollFiller',
  10926. "<div ng-if=\"expandableRow.shouldRenderFiller()\" ng-class=\"{scrollFiller:true, scrollFillerClass:(colContainer.name === 'body')}\" ng-style=\"{ width: (grid.getViewportWidth()) + 'px', height: row.expandedRowHeight + 2 + 'px', 'margin-left': grid.options.rowHeader.rowHeaderWidth + 'px' }\"><i class=\"ui-grid-icon-spin5 ui-grid-animate-spin\" ng-style=\"{'margin-top': ( row.expandedRowHeight/2 - 5) + 'px', 'margin-left' : ((grid.getViewportWidth() - grid.options.rowHeader.rowHeaderWidth)/2 - 5) + 'px'}\"></i></div>"
  10927. );
  10928. $templateCache.put('ui-grid/expandableTopRowHeader',
  10929. "<div class=\"ui-grid-row-header-cell ui-grid-expandable-buttons-cell\"><div class=\"ui-grid-cell-contents\"><span class=\"ui-grid-cell-empty\" ng-if=\"!grid.options.showExpandAllButton\"></span> <button type=\"button\" class=\"ui-grid-icon-button\" ng-if=\"grid.options.showExpandAllButton\" ng-class=\"{ 'ui-grid-icon-plus-squared' : !grid.expandable.expandedAll, 'ui-grid-icon-minus-squared' : grid.expandable.expandedAll }\" ng-click=\"grid.api.expandable.toggleAllRows()\"></button></div></div>"
  10930. );
  10931. $templateCache.put('ui-grid/csvLink',
  10932. "<span class=\"ui-grid-exporter-csv-link-span\"><a href=\"data:text/csv;charset=UTF-8,CSV_CONTENT\" download=\"FILE_NAME\">LINK_LABEL</a></span>"
  10933. );
  10934. $templateCache.put('ui-grid/importerMenuItem',
  10935. "<li class=\"ui-grid-menu-item\"><form><input class=\"ui-grid-importer-file-chooser\" type=\"file\" id=\"files\" name=\"files[]\"></form></li>"
  10936. );
  10937. $templateCache.put('ui-grid/importerMenuItemContainer',
  10938. "<div ui-grid-importer-menu-item></div>"
  10939. );
  10940. $templateCache.put('ui-grid/pagination',
  10941. "<div class=\"ui-grid-pager-panel\" ui-grid-pager ng-show=\"grid.options.enablePaginationControls\"><div role=\"navigation\" class=\"ui-grid-pager-container\"><div class=\"ui-grid-pager-control\"><button type=\"button\" class=\"ui-grid-pager-first\" ui-grid-one-bind-title=\"aria.pageToFirst\" ui-grid-one-bind-aria-label=\"aria.pageToFirst\" ng-click=\"pageFirstPageClick()\" ng-disabled=\"cantPageBackward()\"><div ng-class=\"grid.isRTL() ? 'last-triangle' : 'first-triangle'\"><div ng-class=\"grid.isRTL() ? 'last-bar-rtl' : 'first-bar'\"></div></div></button> <button type=\"button\" class=\"ui-grid-pager-previous\" ui-grid-one-bind-title=\"aria.pageBack\" ui-grid-one-bind-aria-label=\"aria.pageBack\" ng-click=\"pagePreviousPageClick()\" ng-disabled=\"cantPageBackward()\"><div ng-class=\"grid.isRTL() ? 'last-triangle prev-triangle' : 'first-triangle prev-triangle'\"></div></button> <input type=\"number\" ui-grid-one-bind-title=\"aria.pageSelected\" ui-grid-one-bind-aria-label=\"aria.pageSelected\" class=\"ui-grid-pager-control-input\" ng-model=\"grid.options.paginationCurrentPage\" min=\"1\" max=\"{{ paginationApi.getTotalPages() }}\" step=\"1\" required> <span class=\"ui-grid-pager-max-pages-number\" ng-show=\"paginationApi.getTotalPages() > 0\"><abbr ui-grid-one-bind-title=\"paginationOf\">/</abbr> {{ paginationApi.getTotalPages() }}</span> <button type=\"button\" class=\"ui-grid-pager-next\" ui-grid-one-bind-title=\"aria.pageForward\" ui-grid-one-bind-aria-label=\"aria.pageForward\" ng-click=\"pageNextPageClick()\" ng-disabled=\"cantPageForward()\"><div ng-class=\"grid.isRTL() ? 'first-triangle next-triangle' : 'last-triangle next-triangle'\"></div></button> <button type=\"button\" class=\"ui-grid-pager-last\" ui-grid-one-bind-title=\"aria.pageToLast\" ui-grid-one-bind-aria-label=\"aria.pageToLast\" ng-click=\"pageLastPageClick()\" ng-disabled=\"cantPageToLast()\"><div ng-class=\"grid.isRTL() ? 'first-triangle' : 'last-triangle'\"><div ng-class=\"grid.isRTL() ? 'first-bar-rtl' : 'last-bar'\"></div></div></button></div><div class=\"ui-grid-pager-row-count-picker\" ng-if=\"grid.options.paginationPageSizes.length > 1 && !grid.options.useCustomPagination\"><select ui-grid-one-bind-aria-labelledby-grid=\"'items-per-page-label'\" ng-model=\"grid.options.paginationPageSize\" ng-options=\"o as o for o in grid.options.paginationPageSizes\"></select><span ui-grid-one-bind-id-grid=\"'items-per-page-label'\" class=\"ui-grid-pager-row-count-label\">&nbsp;{{sizesLabel}}</span></div><span ng-if=\"grid.options.paginationPageSizes.length <= 1\" class=\"ui-grid-pager-row-count-label\">{{grid.options.paginationPageSize}}&nbsp;{{sizesLabel}}</span></div><div class=\"ui-grid-pager-count-container\"><div class=\"ui-grid-pager-count\"><span ng-show=\"grid.options.totalItems > 0\">{{ 1 + paginationApi.getFirstRowIndex() }} <abbr ui-grid-one-bind-title=\"paginationThrough\">-</abbr> {{ 1 + paginationApi.getLastRowIndex() }} {{paginationOf}} {{grid.options.totalItems}} {{totalItemsLabel}}</span></div></div></div>"
  10942. );
  10943. $templateCache.put('ui-grid/columnResizer',
  10944. "<div ui-grid-column-resizer ng-if=\"grid.options.enableColumnResizing\" class=\"ui-grid-column-resizer\" col=\"col\" position=\"right\" render-index=\"renderIndex\" unselectable=\"on\"></div>"
  10945. );
  10946. $templateCache.put('ui-grid/gridFooterSelectedItems',
  10947. "<span ng-if=\"grid.selection.selectedCount !== 0 && grid.options.enableFooterTotalSelected\">({{\"search.selectedItems\" | t}} {{grid.selection.selectedCount}})</span>"
  10948. );
  10949. $templateCache.put('ui-grid/selectionHeaderCell',
  10950. "<div><!-- <div class=\"ui-grid-vertical-bar\">&nbsp;</div> --><div class=\"ui-grid-cell-contents\" col-index=\"renderIndex\"><ui-grid-selection-select-all-buttons ng-if=\"grid.options.enableSelectAll\" role=\"checkbox\" ng-model=\"grid.selection.selectAll\"></ui-grid-selection-select-all-buttons></div></div>"
  10951. );
  10952. $templateCache.put('ui-grid/selectionRowHeader',
  10953. "<div class=\"ui-grid-cell-contents ui-grid-disable-selection\"><ui-grid-selection-row-header-buttons></ui-grid-selection-row-header-buttons></div>"
  10954. );
  10955. $templateCache.put('ui-grid/selectionRowHeaderButtons',
  10956. "<div class=\"ui-grid-selection-row-header-buttons ui-grid-icon-ok\" ng-class=\"{'ui-grid-row-selected': row.isSelected}\" ng-click=\"selectButtonClick(row, $event)\" ng-keydown=\"selectButtonKeyDown(row, $event)\" role=\"checkbox\" ng-model=\"row.isSelected\">&nbsp;</div>"
  10957. );
  10958. $templateCache.put('ui-grid/selectionSelectAllButtons',
  10959. "<div role=\"button\" class=\"ui-grid-selection-row-header-buttons ui-grid-icon-ok\" ng-class=\"{'ui-grid-all-selected': grid.selection.selectAll}\" ng-click=\"headerButtonClick($event)\" ng-keydown=\"headerButtonKeyDown($event)\"></div>"
  10960. );
  10961. $templateCache.put('ui-grid/treeBaseExpandAllButtons',
  10962. "<div class=\"ui-grid-tree-base-row-header-buttons\" ng-class=\"{'ui-grid-icon-minus-squared': grid.treeBase.numberLevels > 0 && grid.treeBase.expandAll, 'ui-grid-icon-plus-squared': grid.treeBase.numberLevels > 0 && !grid.treeBase.expandAll}\" ng-click=\"headerButtonClick($event)\"></div>"
  10963. );
  10964. $templateCache.put('ui-grid/treeBaseHeaderCell',
  10965. "<div><div class=\"ui-grid-cell-contents\" col-index=\"renderIndex\"><ui-grid-tree-base-expand-all-buttons ng-if=\"grid.options.enableExpandAll\"></ui-grid-tree-base-expand-all-buttons></div></div>"
  10966. );
  10967. $templateCache.put('ui-grid/treeBaseRowHeader',
  10968. "<div class=\"ui-grid-cell-contents\"><ui-grid-tree-base-row-header-buttons></ui-grid-tree-base-row-header-buttons></div>"
  10969. );
  10970. $templateCache.put('ui-grid/treeBaseRowHeaderButtons',
  10971. "<div class=\"ui-grid-tree-base-row-header-buttons\" ng-class=\"{'ui-grid-tree-base-header': row.treeLevel > -1 }\" ng-click=\"treeButtonClick(row, $event)\"><i ng-class=\"{'ui-grid-icon-minus-squared': ( ( grid.options.showTreeExpandNoChildren && row.treeLevel > -1 ) || ( row.treeNode.children && row.treeNode.children.length > 0 ) ) && row.treeNode.state === 'expanded', 'ui-grid-icon-plus-squared': ( ( grid.options.showTreeExpandNoChildren && row.treeLevel > -1 ) || ( row.treeNode.children && row.treeNode.children.length > 0 ) ) && row.treeNode.state === 'collapsed'}\" ng-style=\"{'padding-left': grid.options.treeIndent * row.treeLevel + 'px'}\"></i> &nbsp;</div>"
  10972. );
  10973. $templateCache.put('ui-grid/cellTitleValidator',
  10974. "<div class=\"ui-grid-cell-contents\" ng-class=\"{invalid:grid.validate.isInvalid(row.entity,col.colDef)}\" title=\"{{grid.validate.getTitleFormattedErrors(row.entity,col.colDef)}}\">{{COL_FIELD CUSTOM_FILTERS}}</div>"
  10975. );
  10976. $templateCache.put('ui-grid/cellTooltipValidator',
  10977. "<div class=\"ui-grid-cell-contents\" ng-class=\"{invalid:grid.validate.isInvalid(row.entity,col.colDef)}\" tooltip-html-unsafe=\"{{grid.validate.getFormattedErrors(row.entity,col.colDef)}}\" tooltip-enable=\"grid.validate.isInvalid(row.entity,col.colDef)\" tooltip-append-to-body=\"true\" tooltip-placement=\"top\" title=\"TOOLTIP\">{{COL_FIELD CUSTOM_FILTERS}}</div>"
  10978. );
  10979. }]);