Built files from Bizgaze WebServer
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

tabulator.js 558KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238
  1. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  2. /* Tabulator v4.6.3 (c) Oliver Folkerd */
  3. ;(function (global, factory) {
  4. if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object' && typeof module !== 'undefined') {
  5. module.exports = factory();
  6. } else if (typeof define === 'function' && define.amd) {
  7. define(factory);
  8. } else {
  9. global.Tabulator = factory();
  10. }
  11. })(this, function () {
  12. 'use strict';
  13. // https://tc39.github.io/ecma262/#sec-array.prototype.findIndex
  14. if (!Array.prototype.findIndex) {
  15. Object.defineProperty(Array.prototype, 'findIndex', {
  16. value: function value(predicate) {
  17. // 1. Let O be ? ToObject(this value).
  18. if (this == null) {
  19. throw new TypeError('"this" is null or not defined');
  20. }
  21. var o = Object(this);
  22. // 2. Let len be ? ToLength(? Get(O, "length")).
  23. var len = o.length >>> 0;
  24. // 3. If IsCallable(predicate) is false, throw a TypeError exception.
  25. if (typeof predicate !== 'function') {
  26. throw new TypeError('predicate must be a function');
  27. }
  28. // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
  29. var thisArg = arguments[1];
  30. // 5. Let k be 0.
  31. var k = 0;
  32. // 6. Repeat, while k < len
  33. while (k < len) {
  34. // a. Let Pk be ! ToString(k).
  35. // b. Let kValue be ? Get(O, Pk).
  36. // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
  37. // d. If testResult is true, return k.
  38. var kValue = o[k];
  39. if (predicate.call(thisArg, kValue, k, o)) {
  40. return k;
  41. }
  42. // e. Increase k by 1.
  43. k++;
  44. }
  45. // 7. Return -1.
  46. return -1;
  47. }
  48. });
  49. }
  50. // https://tc39.github.io/ecma262/#sec-array.prototype.find
  51. if (!Array.prototype.find) {
  52. Object.defineProperty(Array.prototype, 'find', {
  53. value: function value(predicate) {
  54. // 1. Let O be ? ToObject(this value).
  55. if (this == null) {
  56. throw new TypeError('"this" is null or not defined');
  57. }
  58. var o = Object(this);
  59. // 2. Let len be ? ToLength(? Get(O, "length")).
  60. var len = o.length >>> 0;
  61. // 3. If IsCallable(predicate) is false, throw a TypeError exception.
  62. if (typeof predicate !== 'function') {
  63. throw new TypeError('predicate must be a function');
  64. }
  65. // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
  66. var thisArg = arguments[1];
  67. // 5. Let k be 0.
  68. var k = 0;
  69. // 6. Repeat, while k < len
  70. while (k < len) {
  71. // a. Let Pk be ! ToString(k).
  72. // b. Let kValue be ? Get(O, Pk).
  73. // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
  74. // d. If testResult is true, return kValue.
  75. var kValue = o[k];
  76. if (predicate.call(thisArg, kValue, k, o)) {
  77. return kValue;
  78. }
  79. // e. Increase k by 1.
  80. k++;
  81. }
  82. // 7. Return undefined.
  83. return undefined;
  84. }
  85. });
  86. }
  87. var ColumnManager = function ColumnManager(table) {
  88. this.table = table; //hold parent table
  89. this.blockHozScrollEvent = false;
  90. this.headersElement = this.createHeadersElement();
  91. this.element = this.createHeaderElement(); //containing element
  92. this.rowManager = null; //hold row manager object
  93. this.columns = []; // column definition object
  94. this.columnsByIndex = []; //columns by index
  95. this.columnsByField = {}; //columns by field
  96. this.scrollLeft = 0;
  97. this.element.insertBefore(this.headersElement, this.element.firstChild);
  98. };
  99. ////////////// Setup Functions /////////////////
  100. ColumnManager.prototype.createHeadersElement = function () {
  101. var el = document.createElement("div");
  102. el.classList.add("tabulator-headers");
  103. return el;
  104. };
  105. ColumnManager.prototype.createHeaderElement = function () {
  106. var el = document.createElement("div");
  107. el.classList.add("tabulator-header");
  108. if (!this.table.options.headerVisible) {
  109. el.classList.add("tabulator-header-hidden");
  110. }
  111. return el;
  112. };
  113. ColumnManager.prototype.initialize = function () {
  114. var self = this;
  115. //scroll body along with header
  116. // self.element.addEventListener("scroll", function(e){
  117. // if(!self.blockHozScrollEvent){
  118. // self.table.rowManager.scrollHorizontal(self.element.scrollLeft);
  119. // }
  120. // });
  121. };
  122. //link to row manager
  123. ColumnManager.prototype.setRowManager = function (manager) {
  124. this.rowManager = manager;
  125. };
  126. //return containing element
  127. ColumnManager.prototype.getElement = function () {
  128. return this.element;
  129. };
  130. //return header containing element
  131. ColumnManager.prototype.getHeadersElement = function () {
  132. return this.headersElement;
  133. };
  134. // ColumnManager.prototype.tempScrollBlock = function(){
  135. // clearTimeout(this.blockHozScrollEvent);
  136. // this.blockHozScrollEvent = setTimeout(() => {this.blockHozScrollEvent = false;}, 50);
  137. // }
  138. //scroll horizontally to match table body
  139. ColumnManager.prototype.scrollHorizontal = function (left) {
  140. var hozAdjust = 0,
  141. scrollWidth = this.element.scrollWidth - this.table.element.clientWidth;
  142. // this.tempScrollBlock();
  143. this.element.scrollLeft = left;
  144. //adjust for vertical scrollbar moving table when present
  145. if (left > scrollWidth) {
  146. hozAdjust = left - scrollWidth;
  147. this.element.style.marginLeft = -hozAdjust + "px";
  148. } else {
  149. this.element.style.marginLeft = 0;
  150. }
  151. //keep frozen columns fixed in position
  152. //this._calcFrozenColumnsPos(hozAdjust + 3);
  153. this.scrollLeft = left;
  154. if (this.table.modExists("frozenColumns")) {
  155. this.table.modules.frozenColumns.scrollHorizontal();
  156. }
  157. };
  158. ///////////// Column Setup Functions /////////////
  159. ColumnManager.prototype.generateColumnsFromRowData = function (data) {
  160. var cols = [],
  161. row,
  162. sorter;
  163. if (data && data.length) {
  164. row = data[0];
  165. for (var key in row) {
  166. var col = {
  167. field: key,
  168. title: key
  169. };
  170. var value = row[key];
  171. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  172. case "undefined":
  173. sorter = "string";
  174. break;
  175. case "boolean":
  176. sorter = "boolean";
  177. break;
  178. case "object":
  179. if (Array.isArray(value)) {
  180. sorter = "array";
  181. } else {
  182. sorter = "string";
  183. }
  184. break;
  185. default:
  186. if (!isNaN(value) && value !== "") {
  187. sorter = "number";
  188. } else {
  189. if (value.match(/((^[0-9]+[a-z]+)|(^[a-z]+[0-9]+))+$/i)) {
  190. sorter = "alphanum";
  191. } else {
  192. sorter = "string";
  193. }
  194. }
  195. break;
  196. }
  197. col.sorter = sorter;
  198. cols.push(col);
  199. }
  200. this.table.options.columns = cols;
  201. this.setColumns(this.table.options.columns);
  202. }
  203. };
  204. ColumnManager.prototype.setColumns = function (cols, row) {
  205. var self = this;
  206. while (self.headersElement.firstChild) {
  207. self.headersElement.removeChild(self.headersElement.firstChild);
  208. }self.columns = [];
  209. self.columnsByIndex = [];
  210. self.columnsByField = {};
  211. //reset frozen columns
  212. if (self.table.modExists("frozenColumns")) {
  213. self.table.modules.frozenColumns.reset();
  214. }
  215. cols.forEach(function (def, i) {
  216. self._addColumn(def);
  217. });
  218. self._reIndexColumns();
  219. if (self.table.options.responsiveLayout && self.table.modExists("responsiveLayout", true)) {
  220. self.table.modules.responsiveLayout.initialize();
  221. }
  222. self.redraw(true);
  223. };
  224. ColumnManager.prototype._addColumn = function (definition, before, nextToColumn) {
  225. var column = new Column(definition, this),
  226. colEl = column.getElement(),
  227. index = nextToColumn ? this.findColumnIndex(nextToColumn) : nextToColumn;
  228. if (nextToColumn && index > -1) {
  229. var parentIndex = this.columns.indexOf(nextToColumn.getTopColumn());
  230. var nextEl = nextToColumn.getElement();
  231. if (before) {
  232. this.columns.splice(parentIndex, 0, column);
  233. nextEl.parentNode.insertBefore(colEl, nextEl);
  234. } else {
  235. this.columns.splice(parentIndex + 1, 0, column);
  236. nextEl.parentNode.insertBefore(colEl, nextEl.nextSibling);
  237. }
  238. } else {
  239. if (before) {
  240. this.columns.unshift(column);
  241. this.headersElement.insertBefore(column.getElement(), this.headersElement.firstChild);
  242. } else {
  243. this.columns.push(column);
  244. this.headersElement.appendChild(column.getElement());
  245. }
  246. column.columnRendered();
  247. }
  248. return column;
  249. };
  250. ColumnManager.prototype.registerColumnField = function (col) {
  251. if (col.definition.field) {
  252. this.columnsByField[col.definition.field] = col;
  253. }
  254. };
  255. ColumnManager.prototype.registerColumnPosition = function (col) {
  256. this.columnsByIndex.push(col);
  257. };
  258. ColumnManager.prototype._reIndexColumns = function () {
  259. this.columnsByIndex = [];
  260. this.columns.forEach(function (column) {
  261. column.reRegisterPosition();
  262. });
  263. };
  264. //ensure column headers take up the correct amount of space in column groups
  265. ColumnManager.prototype._verticalAlignHeaders = function () {
  266. var self = this,
  267. minHeight = 0;
  268. self.columns.forEach(function (column) {
  269. var height;
  270. column.clearVerticalAlign();
  271. height = column.getHeight();
  272. if (height > minHeight) {
  273. minHeight = height;
  274. }
  275. });
  276. self.columns.forEach(function (column) {
  277. column.verticalAlign(self.table.options.columnHeaderVertAlign, minHeight);
  278. });
  279. self.rowManager.adjustTableSize();
  280. };
  281. //////////////// Column Details /////////////////
  282. ColumnManager.prototype.findColumn = function (subject) {
  283. var self = this;
  284. if ((typeof subject === 'undefined' ? 'undefined' : _typeof(subject)) == "object") {
  285. if (subject instanceof Column) {
  286. //subject is column element
  287. return subject;
  288. } else if (subject instanceof ColumnComponent) {
  289. //subject is public column component
  290. return subject._getSelf() || false;
  291. } else if (typeof HTMLElement !== "undefined" && subject instanceof HTMLElement) {
  292. //subject is a HTML element of the column header
  293. var match = self.columns.find(function (column) {
  294. return column.element === subject;
  295. });
  296. return match || false;
  297. }
  298. } else {
  299. //subject should be treated as the field name of the column
  300. return this.columnsByField[subject] || false;
  301. }
  302. //catch all for any other type of input
  303. return false;
  304. };
  305. ColumnManager.prototype.getColumnByField = function (field) {
  306. return this.columnsByField[field];
  307. };
  308. ColumnManager.prototype.getColumnsByFieldRoot = function (root) {
  309. var _this = this;
  310. var matches = [];
  311. Object.keys(this.columnsByField).forEach(function (field) {
  312. var fieldRoot = field.split(".")[0];
  313. if (fieldRoot === root) {
  314. matches.push(_this.columnsByField[field]);
  315. }
  316. });
  317. return matches;
  318. };
  319. ColumnManager.prototype.getColumnByIndex = function (index) {
  320. return this.columnsByIndex[index];
  321. };
  322. ColumnManager.prototype.getFirstVisibileColumn = function (index) {
  323. var index = this.columnsByIndex.findIndex(function (col) {
  324. return col.visible;
  325. });
  326. return index > -1 ? this.columnsByIndex[index] : false;
  327. };
  328. ColumnManager.prototype.getColumns = function () {
  329. return this.columns;
  330. };
  331. ColumnManager.prototype.findColumnIndex = function (column) {
  332. return this.columnsByIndex.findIndex(function (col) {
  333. return column === col;
  334. });
  335. };
  336. //return all columns that are not groups
  337. ColumnManager.prototype.getRealColumns = function () {
  338. return this.columnsByIndex;
  339. };
  340. //travers across columns and call action
  341. ColumnManager.prototype.traverse = function (callback) {
  342. var self = this;
  343. self.columnsByIndex.forEach(function (column, i) {
  344. callback(column, i);
  345. });
  346. };
  347. //get defintions of actual columns
  348. ColumnManager.prototype.getDefinitions = function (active) {
  349. var self = this,
  350. output = [];
  351. self.columnsByIndex.forEach(function (column) {
  352. if (!active || active && column.visible) {
  353. output.push(column.getDefinition());
  354. }
  355. });
  356. return output;
  357. };
  358. //get full nested definition tree
  359. ColumnManager.prototype.getDefinitionTree = function () {
  360. var self = this,
  361. output = [];
  362. self.columns.forEach(function (column) {
  363. output.push(column.getDefinition(true));
  364. });
  365. return output;
  366. };
  367. ColumnManager.prototype.getComponents = function (structured) {
  368. var self = this,
  369. output = [],
  370. columns = structured ? self.columns : self.columnsByIndex;
  371. columns.forEach(function (column) {
  372. output.push(column.getComponent());
  373. });
  374. return output;
  375. };
  376. ColumnManager.prototype.getWidth = function () {
  377. var width = 0;
  378. this.columnsByIndex.forEach(function (column) {
  379. if (column.visible) {
  380. width += column.getWidth();
  381. }
  382. });
  383. return width;
  384. };
  385. ColumnManager.prototype.moveColumn = function (from, to, after) {
  386. this.moveColumnActual(from, to, after);
  387. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  388. this.table.modules.responsiveLayout.initialize();
  389. }
  390. if (this.table.modExists("columnCalcs")) {
  391. this.table.modules.columnCalcs.recalc(this.table.rowManager.activeRows);
  392. }
  393. to.element.parentNode.insertBefore(from.element, to.element);
  394. if (after) {
  395. to.element.parentNode.insertBefore(to.element, from.element);
  396. }
  397. this._verticalAlignHeaders();
  398. this.table.rowManager.reinitialize();
  399. };
  400. ColumnManager.prototype.moveColumnActual = function (from, to, after) {
  401. if (from.parent.isGroup) {
  402. this._moveColumnInArray(from.parent.columns, from, to, after);
  403. } else {
  404. this._moveColumnInArray(this.columns, from, to, after);
  405. }
  406. this._moveColumnInArray(this.columnsByIndex, from, to, after, true);
  407. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  408. this.table.modules.responsiveLayout.initialize();
  409. }
  410. if (this.table.options.columnMoved) {
  411. this.table.options.columnMoved.call(this.table, from.getComponent(), this.table.columnManager.getComponents());
  412. }
  413. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.columns) {
  414. this.table.modules.persistence.save("columns");
  415. }
  416. };
  417. ColumnManager.prototype._moveColumnInArray = function (columns, from, to, after, updateRows) {
  418. var fromIndex = columns.indexOf(from),
  419. toIndex;
  420. if (fromIndex > -1) {
  421. columns.splice(fromIndex, 1);
  422. toIndex = columns.indexOf(to);
  423. if (toIndex > -1) {
  424. if (after) {
  425. toIndex = toIndex + 1;
  426. }
  427. } else {
  428. toIndex = fromIndex;
  429. }
  430. columns.splice(toIndex, 0, from);
  431. if (updateRows) {
  432. this.table.rowManager.rows.forEach(function (row) {
  433. if (row.cells.length) {
  434. var cell = row.cells.splice(fromIndex, 1)[0];
  435. row.cells.splice(toIndex, 0, cell);
  436. }
  437. });
  438. }
  439. }
  440. };
  441. ColumnManager.prototype.scrollToColumn = function (column, position, ifVisible) {
  442. var _this2 = this;
  443. var left = 0,
  444. offset = 0,
  445. adjust = 0,
  446. colEl = column.getElement();
  447. return new Promise(function (resolve, reject) {
  448. if (typeof position === "undefined") {
  449. position = _this2.table.options.scrollToColumnPosition;
  450. }
  451. if (typeof ifVisible === "undefined") {
  452. ifVisible = _this2.table.options.scrollToColumnIfVisible;
  453. }
  454. if (column.visible) {
  455. //align to correct position
  456. switch (position) {
  457. case "middle":
  458. case "center":
  459. adjust = -_this2.element.clientWidth / 2;
  460. break;
  461. case "right":
  462. adjust = colEl.clientWidth - _this2.headersElement.clientWidth;
  463. break;
  464. }
  465. //check column visibility
  466. if (!ifVisible) {
  467. offset = colEl.offsetLeft;
  468. if (offset > 0 && offset + colEl.offsetWidth < _this2.element.clientWidth) {
  469. return false;
  470. }
  471. }
  472. //calculate scroll position
  473. left = colEl.offsetLeft + _this2.element.scrollLeft + adjust;
  474. left = Math.max(Math.min(left, _this2.table.rowManager.element.scrollWidth - _this2.table.rowManager.element.clientWidth), 0);
  475. _this2.table.rowManager.scrollHorizontal(left);
  476. _this2.scrollHorizontal(left);
  477. resolve();
  478. } else {
  479. console.warn("Scroll Error - Column not visible");
  480. reject("Scroll Error - Column not visible");
  481. }
  482. });
  483. };
  484. //////////////// Cell Management /////////////////
  485. ColumnManager.prototype.generateCells = function (row) {
  486. var self = this;
  487. var cells = [];
  488. self.columnsByIndex.forEach(function (column) {
  489. cells.push(column.generateCell(row));
  490. });
  491. return cells;
  492. };
  493. //////////////// Column Management /////////////////
  494. ColumnManager.prototype.getFlexBaseWidth = function () {
  495. var self = this,
  496. totalWidth = self.table.element.clientWidth,
  497. //table element width
  498. fixedWidth = 0;
  499. //adjust for vertical scrollbar if present
  500. if (self.rowManager.element.scrollHeight > self.rowManager.element.clientHeight) {
  501. totalWidth -= self.rowManager.element.offsetWidth - self.rowManager.element.clientWidth;
  502. }
  503. this.columnsByIndex.forEach(function (column) {
  504. var width, minWidth, colWidth;
  505. if (column.visible) {
  506. width = column.definition.width || 0;
  507. minWidth = typeof column.minWidth == "undefined" ? self.table.options.columnMinWidth : parseInt(column.minWidth);
  508. if (typeof width == "string") {
  509. if (width.indexOf("%") > -1) {
  510. colWidth = totalWidth / 100 * parseInt(width);
  511. } else {
  512. colWidth = parseInt(width);
  513. }
  514. } else {
  515. colWidth = width;
  516. }
  517. fixedWidth += colWidth > minWidth ? colWidth : minWidth;
  518. }
  519. });
  520. return fixedWidth;
  521. };
  522. ColumnManager.prototype.addColumn = function (definition, before, nextToColumn) {
  523. var _this3 = this;
  524. return new Promise(function (resolve, reject) {
  525. var column = _this3._addColumn(definition, before, nextToColumn);
  526. _this3._reIndexColumns();
  527. if (_this3.table.options.responsiveLayout && _this3.table.modExists("responsiveLayout", true)) {
  528. _this3.table.modules.responsiveLayout.initialize();
  529. }
  530. if (_this3.table.modExists("columnCalcs")) {
  531. _this3.table.modules.columnCalcs.recalc(_this3.table.rowManager.activeRows);
  532. }
  533. _this3.redraw();
  534. if (_this3.table.modules.layout.getMode() != "fitColumns") {
  535. column.reinitializeWidth();
  536. }
  537. _this3._verticalAlignHeaders();
  538. _this3.table.rowManager.reinitialize();
  539. resolve(column);
  540. });
  541. };
  542. //remove column from system
  543. ColumnManager.prototype.deregisterColumn = function (column) {
  544. var field = column.getField(),
  545. index;
  546. //remove from field list
  547. if (field) {
  548. delete this.columnsByField[field];
  549. }
  550. //remove from index list
  551. index = this.columnsByIndex.indexOf(column);
  552. if (index > -1) {
  553. this.columnsByIndex.splice(index, 1);
  554. }
  555. //remove from column list
  556. index = this.columns.indexOf(column);
  557. if (index > -1) {
  558. this.columns.splice(index, 1);
  559. }
  560. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  561. this.table.modules.responsiveLayout.initialize();
  562. }
  563. this.redraw();
  564. };
  565. //redraw columns
  566. ColumnManager.prototype.redraw = function (force) {
  567. if (force) {
  568. if (Tabulator.prototype.helpers.elVisible(this.element)) {
  569. this._verticalAlignHeaders();
  570. }
  571. this.table.rowManager.resetScroll();
  572. this.table.rowManager.reinitialize();
  573. }
  574. if (["fitColumns", "fitDataStretch"].indexOf(this.table.modules.layout.getMode()) > -1) {
  575. this.table.modules.layout.layout();
  576. } else {
  577. if (force) {
  578. this.table.modules.layout.layout();
  579. } else {
  580. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  581. this.table.modules.responsiveLayout.update();
  582. }
  583. }
  584. }
  585. if (this.table.modExists("frozenColumns")) {
  586. this.table.modules.frozenColumns.layout();
  587. }
  588. if (this.table.modExists("columnCalcs")) {
  589. this.table.modules.columnCalcs.recalc(this.table.rowManager.activeRows);
  590. }
  591. if (force) {
  592. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.columns) {
  593. this.table.modules.persistence.save("columns");
  594. }
  595. if (this.table.modExists("columnCalcs")) {
  596. this.table.modules.columnCalcs.redraw();
  597. }
  598. }
  599. this.table.footerManager.redraw();
  600. };
  601. //public column object
  602. var ColumnComponent = function ColumnComponent(column) {
  603. this._column = column;
  604. this.type = "ColumnComponent";
  605. };
  606. ColumnComponent.prototype.getElement = function () {
  607. return this._column.getElement();
  608. };
  609. ColumnComponent.prototype.getDefinition = function () {
  610. return this._column.getDefinition();
  611. };
  612. ColumnComponent.prototype.getField = function () {
  613. return this._column.getField();
  614. };
  615. ColumnComponent.prototype.getCells = function () {
  616. var cells = [];
  617. this._column.cells.forEach(function (cell) {
  618. cells.push(cell.getComponent());
  619. });
  620. return cells;
  621. };
  622. ColumnComponent.prototype.getVisibility = function () {
  623. return this._column.visible;
  624. };
  625. ColumnComponent.prototype.show = function () {
  626. if (this._column.isGroup) {
  627. this._column.columns.forEach(function (column) {
  628. column.show();
  629. });
  630. } else {
  631. this._column.show();
  632. }
  633. };
  634. ColumnComponent.prototype.hide = function () {
  635. if (this._column.isGroup) {
  636. this._column.columns.forEach(function (column) {
  637. column.hide();
  638. });
  639. } else {
  640. this._column.hide();
  641. }
  642. };
  643. ColumnComponent.prototype.toggle = function () {
  644. if (this._column.visible) {
  645. this.hide();
  646. } else {
  647. this.show();
  648. }
  649. };
  650. ColumnComponent.prototype.delete = function () {
  651. return this._column.delete();
  652. };
  653. ColumnComponent.prototype.getSubColumns = function () {
  654. var output = [];
  655. if (this._column.columns.length) {
  656. this._column.columns.forEach(function (column) {
  657. output.push(column.getComponent());
  658. });
  659. }
  660. return output;
  661. };
  662. ColumnComponent.prototype.getParentColumn = function () {
  663. return this._column.parent instanceof Column ? this._column.parent.getComponent() : false;
  664. };
  665. ColumnComponent.prototype._getSelf = function () {
  666. return this._column;
  667. };
  668. ColumnComponent.prototype.scrollTo = function () {
  669. return this._column.table.columnManager.scrollToColumn(this._column);
  670. };
  671. ColumnComponent.prototype.getTable = function () {
  672. return this._column.table;
  673. };
  674. ColumnComponent.prototype.headerFilterFocus = function () {
  675. if (this._column.table.modExists("filter", true)) {
  676. this._column.table.modules.filter.setHeaderFilterFocus(this._column);
  677. }
  678. };
  679. ColumnComponent.prototype.reloadHeaderFilter = function () {
  680. if (this._column.table.modExists("filter", true)) {
  681. this._column.table.modules.filter.reloadHeaderFilter(this._column);
  682. }
  683. };
  684. ColumnComponent.prototype.getHeaderFilterValue = function () {
  685. if (this._column.table.modExists("filter", true)) {
  686. return this._column.table.modules.filter.getHeaderFilterValue(this._column);
  687. }
  688. };
  689. ColumnComponent.prototype.setHeaderFilterValue = function (value) {
  690. if (this._column.table.modExists("filter", true)) {
  691. this._column.table.modules.filter.setHeaderFilterValue(this._column, value);
  692. }
  693. };
  694. ColumnComponent.prototype.move = function (to, after) {
  695. var toColumn = this._column.table.columnManager.findColumn(to);
  696. if (toColumn) {
  697. this._column.table.columnManager.moveColumn(this._column, toColumn, after);
  698. } else {
  699. console.warn("Move Error - No matching column found:", toColumn);
  700. }
  701. };
  702. ColumnComponent.prototype.getNextColumn = function () {
  703. var nextCol = this._column.nextColumn();
  704. return nextCol ? nextCol.getComponent() : false;
  705. };
  706. ColumnComponent.prototype.getPrevColumn = function () {
  707. var prevCol = this._column.prevColumn();
  708. return prevCol ? prevCol.getComponent() : false;
  709. };
  710. ColumnComponent.prototype.updateDefinition = function (updates) {
  711. return this._column.updateDefinition(updates);
  712. };
  713. var Column = function Column(def, parent) {
  714. var self = this;
  715. this.table = parent.table;
  716. this.definition = def; //column definition
  717. this.parent = parent; //hold parent object
  718. this.type = "column"; //type of element
  719. this.columns = []; //child columns
  720. this.cells = []; //cells bound to this column
  721. this.element = this.createElement(); //column header element
  722. this.contentElement = false;
  723. this.titleElement = false;
  724. this.groupElement = this.createGroupElement(); //column group holder element
  725. this.isGroup = false;
  726. this.tooltip = false; //hold column tooltip
  727. this.hozAlign = ""; //horizontal text alignment
  728. this.vertAlign = ""; //vert text alignment
  729. //multi dimensional filed handling
  730. this.field = "";
  731. this.fieldStructure = "";
  732. this.getFieldValue = "";
  733. this.setFieldValue = "";
  734. this.titleFormatterRendered = false;
  735. this.setField(this.definition.field);
  736. if (this.table.options.invalidOptionWarnings) {
  737. this.checkDefinition();
  738. }
  739. this.modules = {}; //hold module variables;
  740. this.cellEvents = {
  741. cellClick: false,
  742. cellDblClick: false,
  743. cellContext: false,
  744. cellTap: false,
  745. cellDblTap: false,
  746. cellTapHold: false,
  747. cellMouseEnter: false,
  748. cellMouseLeave: false,
  749. cellMouseOver: false,
  750. cellMouseOut: false,
  751. cellMouseMove: false
  752. };
  753. this.width = null; //column width
  754. this.widthStyled = ""; //column width prestyled to improve render efficiency
  755. this.minWidth = null; //column minimum width
  756. this.minWidthStyled = ""; //column minimum prestyled to improve render efficiency
  757. this.widthFixed = false; //user has specified a width for this column
  758. this.visible = true; //default visible state
  759. this._mapDepricatedFunctionality();
  760. //initialize column
  761. if (def.columns) {
  762. this.isGroup = true;
  763. def.columns.forEach(function (def, i) {
  764. var newCol = new Column(def, self);
  765. self.attachColumn(newCol);
  766. });
  767. self.checkColumnVisibility();
  768. } else {
  769. parent.registerColumnField(this);
  770. }
  771. if (def.rowHandle && this.table.options.movableRows !== false && this.table.modExists("moveRow")) {
  772. this.table.modules.moveRow.setHandle(true);
  773. }
  774. this._buildHeader();
  775. this.bindModuleColumns();
  776. };
  777. Column.prototype.createElement = function () {
  778. var el = document.createElement("div");
  779. el.classList.add("tabulator-col");
  780. el.setAttribute("role", "columnheader");
  781. el.setAttribute("aria-sort", "none");
  782. return el;
  783. };
  784. Column.prototype.createGroupElement = function () {
  785. var el = document.createElement("div");
  786. el.classList.add("tabulator-col-group-cols");
  787. return el;
  788. };
  789. Column.prototype.checkDefinition = function () {
  790. var _this4 = this;
  791. Object.keys(this.definition).forEach(function (key) {
  792. if (_this4.defaultOptionList.indexOf(key) === -1) {
  793. console.warn("Invalid column definition option in '" + (_this4.field || _this4.definition.title) + "' column:", key);
  794. }
  795. });
  796. };
  797. Column.prototype.setField = function (field) {
  798. this.field = field;
  799. this.fieldStructure = field ? this.table.options.nestedFieldSeparator ? field.split(this.table.options.nestedFieldSeparator) : [field] : [];
  800. this.getFieldValue = this.fieldStructure.length > 1 ? this._getNestedData : this._getFlatData;
  801. this.setFieldValue = this.fieldStructure.length > 1 ? this._setNestedData : this._setFlatData;
  802. };
  803. //register column position with column manager
  804. Column.prototype.registerColumnPosition = function (column) {
  805. this.parent.registerColumnPosition(column);
  806. };
  807. //register column position with column manager
  808. Column.prototype.registerColumnField = function (column) {
  809. this.parent.registerColumnField(column);
  810. };
  811. //trigger position registration
  812. Column.prototype.reRegisterPosition = function () {
  813. if (this.isGroup) {
  814. this.columns.forEach(function (column) {
  815. column.reRegisterPosition();
  816. });
  817. } else {
  818. this.registerColumnPosition(this);
  819. }
  820. };
  821. Column.prototype._mapDepricatedFunctionality = function () {
  822. if (typeof this.definition.hideInHtml !== "undefined") {
  823. this.definition.htmlOutput = !this.definition.hideInHtml;
  824. console.warn("hideInHtml column definition property is deprecated, you should now use htmlOutput");
  825. }
  826. if (typeof this.definition.align !== "undefined") {
  827. this.definition.hozAlign = this.definition.align;
  828. console.warn("align column definition property is deprecated, you should now use hozAlign");
  829. }
  830. };
  831. Column.prototype.setTooltip = function () {
  832. var self = this,
  833. def = self.definition;
  834. //set header tooltips
  835. var tooltip = def.headerTooltip || def.tooltip === false ? def.headerTooltip : self.table.options.tooltipsHeader;
  836. if (tooltip) {
  837. if (tooltip === true) {
  838. if (def.field) {
  839. self.table.modules.localize.bind("columns|" + def.field, function (value) {
  840. self.element.setAttribute("title", value || def.title);
  841. });
  842. } else {
  843. self.element.setAttribute("title", def.title);
  844. }
  845. } else {
  846. if (typeof tooltip == "function") {
  847. tooltip = tooltip(self.getComponent());
  848. if (tooltip === false) {
  849. tooltip = "";
  850. }
  851. }
  852. self.element.setAttribute("title", tooltip);
  853. }
  854. } else {
  855. self.element.setAttribute("title", "");
  856. }
  857. };
  858. //build header element
  859. Column.prototype._buildHeader = function () {
  860. var self = this,
  861. def = self.definition;
  862. while (self.element.firstChild) {
  863. self.element.removeChild(self.element.firstChild);
  864. }if (def.headerVertical) {
  865. self.element.classList.add("tabulator-col-vertical");
  866. if (def.headerVertical === "flip") {
  867. self.element.classList.add("tabulator-col-vertical-flip");
  868. }
  869. }
  870. self.contentElement = self._bindEvents();
  871. self.contentElement = self._buildColumnHeaderContent();
  872. self.element.appendChild(self.contentElement);
  873. if (self.isGroup) {
  874. self._buildGroupHeader();
  875. } else {
  876. self._buildColumnHeader();
  877. }
  878. self.setTooltip();
  879. //set resizable handles
  880. if (self.table.options.resizableColumns && self.table.modExists("resizeColumns")) {
  881. self.table.modules.resizeColumns.initializeColumn("header", self, self.element);
  882. }
  883. //set resizable handles
  884. if (def.headerFilter && self.table.modExists("filter") && self.table.modExists("edit")) {
  885. if (typeof def.headerFilterPlaceholder !== "undefined" && def.field) {
  886. self.table.modules.localize.setHeaderFilterColumnPlaceholder(def.field, def.headerFilterPlaceholder);
  887. }
  888. self.table.modules.filter.initializeColumn(self);
  889. }
  890. //set resizable handles
  891. if (self.table.modExists("frozenColumns")) {
  892. self.table.modules.frozenColumns.initializeColumn(self);
  893. }
  894. //set movable column
  895. if (self.table.options.movableColumns && !self.isGroup && self.table.modExists("moveColumn")) {
  896. self.table.modules.moveColumn.initializeColumn(self);
  897. }
  898. //set calcs column
  899. if ((def.topCalc || def.bottomCalc) && self.table.modExists("columnCalcs")) {
  900. self.table.modules.columnCalcs.initializeColumn(self);
  901. }
  902. //handle persistence
  903. if (self.table.modExists("persistence") && self.table.modules.persistence.config.columns) {
  904. self.table.modules.persistence.initializeColumn(self);
  905. }
  906. //update header tooltip on mouse enter
  907. self.element.addEventListener("mouseenter", function (e) {
  908. self.setTooltip();
  909. });
  910. };
  911. Column.prototype._bindEvents = function () {
  912. var self = this,
  913. def = self.definition,
  914. dblTap,
  915. tapHold,
  916. tap;
  917. //setup header click event bindings
  918. if (typeof def.headerClick == "function") {
  919. self.element.addEventListener("click", function (e) {
  920. def.headerClick(e, self.getComponent());
  921. });
  922. }
  923. if (typeof def.headerDblClick == "function") {
  924. self.element.addEventListener("dblclick", function (e) {
  925. def.headerDblClick(e, self.getComponent());
  926. });
  927. }
  928. if (typeof def.headerContext == "function") {
  929. self.element.addEventListener("contextmenu", function (e) {
  930. def.headerContext(e, self.getComponent());
  931. });
  932. }
  933. //setup header tap event bindings
  934. if (typeof def.headerTap == "function") {
  935. tap = false;
  936. self.element.addEventListener("touchstart", function (e) {
  937. tap = true;
  938. }, { passive: true });
  939. self.element.addEventListener("touchend", function (e) {
  940. if (tap) {
  941. def.headerTap(e, self.getComponent());
  942. }
  943. tap = false;
  944. });
  945. }
  946. if (typeof def.headerDblTap == "function") {
  947. dblTap = null;
  948. self.element.addEventListener("touchend", function (e) {
  949. if (dblTap) {
  950. clearTimeout(dblTap);
  951. dblTap = null;
  952. def.headerDblTap(e, self.getComponent());
  953. } else {
  954. dblTap = setTimeout(function () {
  955. clearTimeout(dblTap);
  956. dblTap = null;
  957. }, 300);
  958. }
  959. });
  960. }
  961. if (typeof def.headerTapHold == "function") {
  962. tapHold = null;
  963. self.element.addEventListener("touchstart", function (e) {
  964. clearTimeout(tapHold);
  965. tapHold = setTimeout(function () {
  966. clearTimeout(tapHold);
  967. tapHold = null;
  968. tap = false;
  969. def.headerTapHold(e, self.getComponent());
  970. }, 1000);
  971. }, { passive: true });
  972. self.element.addEventListener("touchend", function (e) {
  973. clearTimeout(tapHold);
  974. tapHold = null;
  975. });
  976. }
  977. //store column cell click event bindings
  978. if (typeof def.cellClick == "function") {
  979. self.cellEvents.cellClick = def.cellClick;
  980. }
  981. if (typeof def.cellDblClick == "function") {
  982. self.cellEvents.cellDblClick = def.cellDblClick;
  983. }
  984. if (typeof def.cellContext == "function") {
  985. self.cellEvents.cellContext = def.cellContext;
  986. }
  987. //store column mouse event bindings
  988. if (typeof def.cellMouseEnter == "function") {
  989. self.cellEvents.cellMouseEnter = def.cellMouseEnter;
  990. }
  991. if (typeof def.cellMouseLeave == "function") {
  992. self.cellEvents.cellMouseLeave = def.cellMouseLeave;
  993. }
  994. if (typeof def.cellMouseOver == "function") {
  995. self.cellEvents.cellMouseOver = def.cellMouseOver;
  996. }
  997. if (typeof def.cellMouseOut == "function") {
  998. self.cellEvents.cellMouseOut = def.cellMouseOut;
  999. }
  1000. if (typeof def.cellMouseMove == "function") {
  1001. self.cellEvents.cellMouseMove = def.cellMouseMove;
  1002. }
  1003. //setup column cell tap event bindings
  1004. if (typeof def.cellTap == "function") {
  1005. self.cellEvents.cellTap = def.cellTap;
  1006. }
  1007. if (typeof def.cellDblTap == "function") {
  1008. self.cellEvents.cellDblTap = def.cellDblTap;
  1009. }
  1010. if (typeof def.cellTapHold == "function") {
  1011. self.cellEvents.cellTapHold = def.cellTapHold;
  1012. }
  1013. //setup column cell edit callbacks
  1014. if (typeof def.cellEdited == "function") {
  1015. self.cellEvents.cellEdited = def.cellEdited;
  1016. }
  1017. if (typeof def.cellEditing == "function") {
  1018. self.cellEvents.cellEditing = def.cellEditing;
  1019. }
  1020. if (typeof def.cellEditCancelled == "function") {
  1021. self.cellEvents.cellEditCancelled = def.cellEditCancelled;
  1022. }
  1023. };
  1024. //build header element for header
  1025. Column.prototype._buildColumnHeader = function () {
  1026. var self = this,
  1027. def = self.definition,
  1028. table = self.table,
  1029. sortable;
  1030. //set column sorter
  1031. if (table.modExists("sort")) {
  1032. table.modules.sort.initializeColumn(self, self.contentElement);
  1033. }
  1034. //set column header context menu
  1035. if ((def.headerContextMenu || def.headerMenu) && table.modExists("menu")) {
  1036. table.modules.menu.initializeColumnHeader(self);
  1037. }
  1038. //set column formatter
  1039. if (table.modExists("format")) {
  1040. table.modules.format.initializeColumn(self);
  1041. }
  1042. //set column editor
  1043. if (typeof def.editor != "undefined" && table.modExists("edit")) {
  1044. table.modules.edit.initializeColumn(self);
  1045. }
  1046. //set colum validator
  1047. if (typeof def.validator != "undefined" && table.modExists("validate")) {
  1048. table.modules.validate.initializeColumn(self);
  1049. }
  1050. //set column mutator
  1051. if (table.modExists("mutator")) {
  1052. table.modules.mutator.initializeColumn(self);
  1053. }
  1054. //set column accessor
  1055. if (table.modExists("accessor")) {
  1056. table.modules.accessor.initializeColumn(self);
  1057. }
  1058. //set respoviveLayout
  1059. if (_typeof(table.options.responsiveLayout) && table.modExists("responsiveLayout")) {
  1060. table.modules.responsiveLayout.initializeColumn(self);
  1061. }
  1062. //set column visibility
  1063. if (typeof def.visible != "undefined") {
  1064. if (def.visible) {
  1065. self.show(true);
  1066. } else {
  1067. self.hide(true);
  1068. }
  1069. }
  1070. //asign additional css classes to column header
  1071. if (def.cssClass) {
  1072. var classeNames = def.cssClass.split(" ");
  1073. classeNames.forEach(function (className) {
  1074. self.element.classList.add(className);
  1075. });
  1076. }
  1077. if (def.field) {
  1078. this.element.setAttribute("tabulator-field", def.field);
  1079. }
  1080. //set min width if present
  1081. self.setMinWidth(typeof def.minWidth == "undefined" ? self.table.options.columnMinWidth : parseInt(def.minWidth));
  1082. self.reinitializeWidth();
  1083. //set tooltip if present
  1084. self.tooltip = self.definition.tooltip || self.definition.tooltip === false ? self.definition.tooltip : self.table.options.tooltips;
  1085. //set orizontal text alignment
  1086. self.hozAlign = typeof self.definition.hozAlign == "undefined" ? self.table.options.cellHozAlign : self.definition.hozAlign;
  1087. self.vertAlign = typeof self.definition.vertAlign == "undefined" ? self.table.options.cellVertAlign : self.definition.vertAlign;
  1088. };
  1089. Column.prototype._buildColumnHeaderContent = function () {
  1090. var def = this.definition,
  1091. table = this.table;
  1092. var contentElement = document.createElement("div");
  1093. contentElement.classList.add("tabulator-col-content");
  1094. this.titleElement = this._buildColumnHeaderTitle();
  1095. contentElement.appendChild(this.titleElement);
  1096. return contentElement;
  1097. };
  1098. //build title element of column
  1099. Column.prototype._buildColumnHeaderTitle = function () {
  1100. var self = this,
  1101. def = self.definition,
  1102. table = self.table,
  1103. title;
  1104. var titleHolderElement = document.createElement("div");
  1105. titleHolderElement.classList.add("tabulator-col-title");
  1106. if (def.editableTitle) {
  1107. var titleElement = document.createElement("input");
  1108. titleElement.classList.add("tabulator-title-editor");
  1109. titleElement.addEventListener("click", function (e) {
  1110. e.stopPropagation();
  1111. titleElement.focus();
  1112. });
  1113. titleElement.addEventListener("change", function () {
  1114. def.title = titleElement.value;
  1115. table.options.columnTitleChanged.call(self.table, self.getComponent());
  1116. });
  1117. titleHolderElement.appendChild(titleElement);
  1118. if (def.field) {
  1119. table.modules.localize.bind("columns|" + def.field, function (text) {
  1120. titleElement.value = text || def.title || "&nbsp;";
  1121. });
  1122. } else {
  1123. titleElement.value = def.title || "&nbsp;";
  1124. }
  1125. } else {
  1126. if (def.field) {
  1127. table.modules.localize.bind("columns|" + def.field, function (text) {
  1128. self._formatColumnHeaderTitle(titleHolderElement, text || def.title || "&nbsp;");
  1129. });
  1130. } else {
  1131. self._formatColumnHeaderTitle(titleHolderElement, def.title || "&nbsp;");
  1132. }
  1133. }
  1134. return titleHolderElement;
  1135. };
  1136. Column.prototype._formatColumnHeaderTitle = function (el, title) {
  1137. var _this5 = this;
  1138. var formatter, contents, params, mockCell, onRendered;
  1139. if (this.definition.titleFormatter && this.table.modExists("format")) {
  1140. formatter = this.table.modules.format.getFormatter(this.definition.titleFormatter);
  1141. onRendered = function onRendered(callback) {
  1142. _this5.titleFormatterRendered = callback;
  1143. };
  1144. mockCell = {
  1145. getValue: function getValue() {
  1146. return title;
  1147. },
  1148. getElement: function getElement() {
  1149. return el;
  1150. }
  1151. };
  1152. params = this.definition.titleFormatterParams || {};
  1153. params = typeof params === "function" ? params() : params;
  1154. contents = formatter.call(this.table.modules.format, mockCell, params, onRendered);
  1155. switch (typeof contents === 'undefined' ? 'undefined' : _typeof(contents)) {
  1156. case "object":
  1157. if (contents instanceof Node) {
  1158. el.appendChild(contents);
  1159. } else {
  1160. el.innerHTML = "";
  1161. console.warn("Format Error - Title formatter has returned a type of object, the only valid formatter object return is an instance of Node, the formatter returned:", contents);
  1162. }
  1163. break;
  1164. case "undefined":
  1165. case "null":
  1166. el.innerHTML = "";
  1167. break;
  1168. default:
  1169. el.innerHTML = contents;
  1170. }
  1171. } else {
  1172. el.innerHTML = title;
  1173. }
  1174. };
  1175. //build header element for column group
  1176. Column.prototype._buildGroupHeader = function () {
  1177. var _this6 = this;
  1178. this.element.classList.add("tabulator-col-group");
  1179. this.element.setAttribute("role", "columngroup");
  1180. this.element.setAttribute("aria-title", this.definition.title);
  1181. //asign additional css classes to column header
  1182. if (this.definition.cssClass) {
  1183. var classeNames = this.definition.cssClass.split(" ");
  1184. classeNames.forEach(function (className) {
  1185. _this6.element.classList.add(className);
  1186. });
  1187. }
  1188. this.element.appendChild(this.groupElement);
  1189. };
  1190. //flat field lookup
  1191. Column.prototype._getFlatData = function (data) {
  1192. return data[this.field];
  1193. };
  1194. //nested field lookup
  1195. Column.prototype._getNestedData = function (data) {
  1196. var dataObj = data,
  1197. structure = this.fieldStructure,
  1198. length = structure.length,
  1199. output;
  1200. for (var i = 0; i < length; i++) {
  1201. dataObj = dataObj[structure[i]];
  1202. output = dataObj;
  1203. if (!dataObj) {
  1204. break;
  1205. }
  1206. }
  1207. return output;
  1208. };
  1209. //flat field set
  1210. Column.prototype._setFlatData = function (data, value) {
  1211. if (this.field) {
  1212. data[this.field] = value;
  1213. }
  1214. };
  1215. //nested field set
  1216. Column.prototype._setNestedData = function (data, value) {
  1217. var dataObj = data,
  1218. structure = this.fieldStructure,
  1219. length = structure.length;
  1220. for (var i = 0; i < length; i++) {
  1221. if (i == length - 1) {
  1222. dataObj[structure[i]] = value;
  1223. } else {
  1224. if (!dataObj[structure[i]]) {
  1225. if (typeof value !== "undefined") {
  1226. dataObj[structure[i]] = {};
  1227. } else {
  1228. break;
  1229. }
  1230. }
  1231. dataObj = dataObj[structure[i]];
  1232. }
  1233. }
  1234. };
  1235. //attach column to this group
  1236. Column.prototype.attachColumn = function (column) {
  1237. var self = this;
  1238. if (self.groupElement) {
  1239. self.columns.push(column);
  1240. self.groupElement.appendChild(column.getElement());
  1241. } else {
  1242. console.warn("Column Warning - Column being attached to another column instead of column group");
  1243. }
  1244. };
  1245. //vertically align header in column
  1246. Column.prototype.verticalAlign = function (alignment, height) {
  1247. //calculate height of column header and group holder element
  1248. var parentHeight = this.parent.isGroup ? this.parent.getGroupElement().clientHeight : height || this.parent.getHeadersElement().clientHeight;
  1249. // var parentHeight = this.parent.isGroup ? this.parent.getGroupElement().clientHeight : this.parent.getHeadersElement().clientHeight;
  1250. this.element.style.height = parentHeight + "px";
  1251. if (this.isGroup) {
  1252. this.groupElement.style.minHeight = parentHeight - this.contentElement.offsetHeight + "px";
  1253. }
  1254. //vertically align cell contents
  1255. if (!this.isGroup && alignment !== "top") {
  1256. if (alignment === "bottom") {
  1257. this.element.style.paddingTop = this.element.clientHeight - this.contentElement.offsetHeight + "px";
  1258. } else {
  1259. this.element.style.paddingTop = (this.element.clientHeight - this.contentElement.offsetHeight) / 2 + "px";
  1260. }
  1261. }
  1262. this.columns.forEach(function (column) {
  1263. column.verticalAlign(alignment);
  1264. });
  1265. };
  1266. //clear vertical alignmenet
  1267. Column.prototype.clearVerticalAlign = function () {
  1268. this.element.style.paddingTop = "";
  1269. this.element.style.height = "";
  1270. this.element.style.minHeight = "";
  1271. this.groupElement.style.minHeight = "";
  1272. this.columns.forEach(function (column) {
  1273. column.clearVerticalAlign();
  1274. });
  1275. };
  1276. Column.prototype.bindModuleColumns = function () {
  1277. //check if rownum formatter is being used on a column
  1278. if (this.definition.formatter == "rownum") {
  1279. this.table.rowManager.rowNumColumn = this;
  1280. }
  1281. };
  1282. //// Retreive Column Information ////
  1283. //return column header element
  1284. Column.prototype.getElement = function () {
  1285. return this.element;
  1286. };
  1287. //return colunm group element
  1288. Column.prototype.getGroupElement = function () {
  1289. return this.groupElement;
  1290. };
  1291. //return field name
  1292. Column.prototype.getField = function () {
  1293. return this.field;
  1294. };
  1295. //return the first column in a group
  1296. Column.prototype.getFirstColumn = function () {
  1297. if (!this.isGroup) {
  1298. return this;
  1299. } else {
  1300. if (this.columns.length) {
  1301. return this.columns[0].getFirstColumn();
  1302. } else {
  1303. return false;
  1304. }
  1305. }
  1306. };
  1307. //return the last column in a group
  1308. Column.prototype.getLastColumn = function () {
  1309. if (!this.isGroup) {
  1310. return this;
  1311. } else {
  1312. if (this.columns.length) {
  1313. return this.columns[this.columns.length - 1].getLastColumn();
  1314. } else {
  1315. return false;
  1316. }
  1317. }
  1318. };
  1319. //return all columns in a group
  1320. Column.prototype.getColumns = function () {
  1321. return this.columns;
  1322. };
  1323. //return all columns in a group
  1324. Column.prototype.getCells = function () {
  1325. return this.cells;
  1326. };
  1327. //retreive the top column in a group of columns
  1328. Column.prototype.getTopColumn = function () {
  1329. if (this.parent.isGroup) {
  1330. return this.parent.getTopColumn();
  1331. } else {
  1332. return this;
  1333. }
  1334. };
  1335. //return column definition object
  1336. Column.prototype.getDefinition = function (updateBranches) {
  1337. var colDefs = [];
  1338. if (this.isGroup && updateBranches) {
  1339. this.columns.forEach(function (column) {
  1340. colDefs.push(column.getDefinition(true));
  1341. });
  1342. this.definition.columns = colDefs;
  1343. }
  1344. return this.definition;
  1345. };
  1346. //////////////////// Actions ////////////////////
  1347. Column.prototype.checkColumnVisibility = function () {
  1348. var visible = false;
  1349. this.columns.forEach(function (column) {
  1350. if (column.visible) {
  1351. visible = true;
  1352. }
  1353. });
  1354. if (visible) {
  1355. this.show();
  1356. this.parent.table.options.columnVisibilityChanged.call(this.table, this.getComponent(), false);
  1357. } else {
  1358. this.hide();
  1359. }
  1360. };
  1361. //show column
  1362. Column.prototype.show = function (silent, responsiveToggle) {
  1363. if (!this.visible) {
  1364. this.visible = true;
  1365. this.element.style.display = "";
  1366. if (this.parent.isGroup) {
  1367. this.parent.checkColumnVisibility();
  1368. }
  1369. this.cells.forEach(function (cell) {
  1370. cell.show();
  1371. });
  1372. if (!this.isGroup && this.width === null) {
  1373. this.reinitializeWidth();
  1374. }
  1375. this.table.columnManager._verticalAlignHeaders();
  1376. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.columns) {
  1377. this.table.modules.persistence.save("columns");
  1378. }
  1379. if (!responsiveToggle && this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  1380. this.table.modules.responsiveLayout.updateColumnVisibility(this, this.visible);
  1381. }
  1382. if (!silent) {
  1383. this.table.options.columnVisibilityChanged.call(this.table, this.getComponent(), true);
  1384. }
  1385. if (this.parent.isGroup) {
  1386. this.parent.matchChildWidths();
  1387. }
  1388. }
  1389. };
  1390. //hide column
  1391. Column.prototype.hide = function (silent, responsiveToggle) {
  1392. if (this.visible) {
  1393. this.visible = false;
  1394. this.element.style.display = "none";
  1395. this.table.columnManager._verticalAlignHeaders();
  1396. if (this.parent.isGroup) {
  1397. this.parent.checkColumnVisibility();
  1398. }
  1399. this.cells.forEach(function (cell) {
  1400. cell.hide();
  1401. });
  1402. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.columns) {
  1403. this.table.modules.persistence.save("columns");
  1404. }
  1405. if (!responsiveToggle && this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  1406. this.table.modules.responsiveLayout.updateColumnVisibility(this, this.visible);
  1407. }
  1408. if (!silent) {
  1409. this.table.options.columnVisibilityChanged.call(this.table, this.getComponent(), false);
  1410. }
  1411. if (this.parent.isGroup) {
  1412. this.parent.matchChildWidths();
  1413. }
  1414. }
  1415. };
  1416. Column.prototype.matchChildWidths = function () {
  1417. var childWidth = 0;
  1418. if (this.contentElement && this.columns.length) {
  1419. this.columns.forEach(function (column) {
  1420. if (column.visible) {
  1421. childWidth += column.getWidth();
  1422. }
  1423. });
  1424. this.contentElement.style.maxWidth = childWidth - 1 + "px";
  1425. if (this.parent.isGroup) {
  1426. this.parent.matchChildWidths();
  1427. }
  1428. }
  1429. };
  1430. Column.prototype.setWidth = function (width) {
  1431. this.widthFixed = true;
  1432. this.setWidthActual(width);
  1433. };
  1434. Column.prototype.setWidthActual = function (width) {
  1435. if (isNaN(width)) {
  1436. width = Math.floor(this.table.element.clientWidth / 100 * parseInt(width));
  1437. }
  1438. width = Math.max(this.minWidth, width);
  1439. this.width = width;
  1440. this.widthStyled = width ? width + "px" : "";
  1441. this.element.style.width = this.widthStyled;
  1442. if (!this.isGroup) {
  1443. this.cells.forEach(function (cell) {
  1444. cell.setWidth();
  1445. });
  1446. }
  1447. if (this.parent.isGroup) {
  1448. this.parent.matchChildWidths();
  1449. }
  1450. //set resizable handles
  1451. if (this.table.modExists("frozenColumns")) {
  1452. this.table.modules.frozenColumns.layout();
  1453. }
  1454. };
  1455. Column.prototype.checkCellHeights = function () {
  1456. var rows = [];
  1457. this.cells.forEach(function (cell) {
  1458. if (cell.row.heightInitialized) {
  1459. if (cell.row.getElement().offsetParent !== null) {
  1460. rows.push(cell.row);
  1461. cell.row.clearCellHeight();
  1462. } else {
  1463. cell.row.heightInitialized = false;
  1464. }
  1465. }
  1466. });
  1467. rows.forEach(function (row) {
  1468. row.calcHeight();
  1469. });
  1470. rows.forEach(function (row) {
  1471. row.setCellHeight();
  1472. });
  1473. };
  1474. Column.prototype.getWidth = function () {
  1475. var width = 0;
  1476. if (this.isGroup) {
  1477. this.columns.forEach(function (column) {
  1478. if (column.visible) {
  1479. width += column.getWidth();
  1480. }
  1481. });
  1482. } else {
  1483. width = this.width;
  1484. }
  1485. return width;
  1486. };
  1487. Column.prototype.getHeight = function () {
  1488. return this.element.offsetHeight;
  1489. };
  1490. Column.prototype.setMinWidth = function (minWidth) {
  1491. this.minWidth = minWidth;
  1492. this.minWidthStyled = minWidth ? minWidth + "px" : "";
  1493. this.element.style.minWidth = this.minWidthStyled;
  1494. this.cells.forEach(function (cell) {
  1495. cell.setMinWidth();
  1496. });
  1497. };
  1498. Column.prototype.delete = function () {
  1499. var _this7 = this;
  1500. return new Promise(function (resolve, reject) {
  1501. if (_this7.isGroup) {
  1502. _this7.columns.forEach(function (column) {
  1503. column.delete();
  1504. });
  1505. }
  1506. //cancel edit if column is currently being edited
  1507. if (_this7.table.modExists("edit")) {
  1508. if (_this7.table.modules.edit.currentCell.column === _this7) {
  1509. _this7.table.modules.edit.cancelEdit();
  1510. }
  1511. }
  1512. var cellCount = _this7.cells.length;
  1513. for (var i = 0; i < cellCount; i++) {
  1514. _this7.cells[0].delete();
  1515. }
  1516. _this7.element.parentNode.removeChild(_this7.element);
  1517. _this7.table.columnManager.deregisterColumn(_this7);
  1518. resolve();
  1519. });
  1520. };
  1521. Column.prototype.columnRendered = function () {
  1522. if (this.titleFormatterRendered) {
  1523. this.titleFormatterRendered();
  1524. }
  1525. };
  1526. //////////////// Cell Management /////////////////
  1527. //generate cell for this column
  1528. Column.prototype.generateCell = function (row) {
  1529. var self = this;
  1530. var cell = new Cell(self, row);
  1531. this.cells.push(cell);
  1532. return cell;
  1533. };
  1534. Column.prototype.nextColumn = function () {
  1535. var index = this.table.columnManager.findColumnIndex(this);
  1536. return index > -1 ? this._nextVisibleColumn(index + 1) : false;
  1537. };
  1538. Column.prototype._nextVisibleColumn = function (index) {
  1539. var column = this.table.columnManager.getColumnByIndex(index);
  1540. return !column || column.visible ? column : this._nextVisibleColumn(index + 1);
  1541. };
  1542. Column.prototype.prevColumn = function () {
  1543. var index = this.table.columnManager.findColumnIndex(this);
  1544. return index > -1 ? this._prevVisibleColumn(index - 1) : false;
  1545. };
  1546. Column.prototype._prevVisibleColumn = function (index) {
  1547. var column = this.table.columnManager.getColumnByIndex(index);
  1548. return !column || column.visible ? column : this._prevVisibleColumn(index - 1);
  1549. };
  1550. Column.prototype.reinitializeWidth = function (force) {
  1551. this.widthFixed = false;
  1552. //set width if present
  1553. if (typeof this.definition.width !== "undefined" && !force) {
  1554. this.setWidth(this.definition.width);
  1555. }
  1556. //hide header filters to prevent them altering column width
  1557. if (this.table.modExists("filter")) {
  1558. this.table.modules.filter.hideHeaderFilterElements();
  1559. }
  1560. this.fitToData();
  1561. //show header filters again after layout is complete
  1562. if (this.table.modExists("filter")) {
  1563. this.table.modules.filter.showHeaderFilterElements();
  1564. }
  1565. };
  1566. //set column width to maximum cell width
  1567. Column.prototype.fitToData = function () {
  1568. var self = this;
  1569. if (!this.widthFixed) {
  1570. this.element.style.width = "";
  1571. self.cells.forEach(function (cell) {
  1572. cell.clearWidth();
  1573. });
  1574. }
  1575. var maxWidth = this.element.offsetWidth;
  1576. if (!self.width || !this.widthFixed) {
  1577. self.cells.forEach(function (cell) {
  1578. var width = cell.getWidth();
  1579. if (width > maxWidth) {
  1580. maxWidth = width;
  1581. }
  1582. });
  1583. if (maxWidth) {
  1584. self.setWidthActual(maxWidth + 1);
  1585. }
  1586. }
  1587. };
  1588. Column.prototype.updateDefinition = function (updates) {
  1589. var _this8 = this;
  1590. return new Promise(function (resolve, reject) {
  1591. var definition;
  1592. if (!_this8.isGroup) {
  1593. definition = Object.assign({}, _this8.getDefinition());
  1594. definition = Object.assign(definition, updates);
  1595. _this8.table.columnManager.addColumn(definition, false, _this8).then(function (column) {
  1596. if (definition.field == _this8.field) {
  1597. _this8.field = false; //cleair field name to prevent deletion of duplicate column from arrays
  1598. }
  1599. _this8.delete().then(function () {
  1600. resolve(column.getComponent());
  1601. }).catch(function (err) {
  1602. reject(err);
  1603. });
  1604. }).catch(function (err) {
  1605. reject(err);
  1606. });
  1607. } else {
  1608. console.warn("Column Update Error - The updateDefintion function is only available on columns, not column groups");
  1609. reject("Column Update Error - The updateDefintion function is only available on columns, not column groups");
  1610. }
  1611. });
  1612. };
  1613. Column.prototype.deleteCell = function (cell) {
  1614. var index = this.cells.indexOf(cell);
  1615. if (index > -1) {
  1616. this.cells.splice(index, 1);
  1617. }
  1618. };
  1619. Column.prototype.defaultOptionList = ["title", "field", "columns", "visible", "align", "hozAlign", "vertAlign", "width", "minWidth", "widthGrow", "widthShrink", "resizable", "frozen", "responsive", "tooltip", "cssClass", "rowHandle", "hideInHtml", "print", "htmlOutput", "sorter", "sorterParams", "formatter", "formatterParams", "variableHeight", "editable", "editor", "editorParams", "validator", "mutator", "mutatorParams", "mutatorData", "mutatorDataParams", "mutatorEdit", "mutatorEditParams", "mutatorClipboard", "mutatorClipboardParams", "accessor", "accessorParams", "accessorData", "accessorDataParams", "accessorDownload", "accessorDownloadParams", "accessorClipboard", "accessorClipboardParams", "accessorPrint", "accessorPrintParams", "accessorHtmlOutput", "accessorHtmlOutputParams", "clipboard", "download", "downloadTitle", "topCalc", "topCalcParams", "topCalcFormatter", "topCalcFormatterParams", "bottomCalc", "bottomCalcParams", "bottomCalcFormatter", "bottomCalcFormatterParams", "cellClick", "cellDblClick", "cellContext", "cellTap", "cellDblTap", "cellTapHold", "cellMouseEnter", "cellMouseLeave", "cellMouseOver", "cellMouseOut", "cellMouseMove", "cellEditing", "cellEdited", "cellEditCancelled", "headerSort", "headerSortStartingDir", "headerSortTristate", "headerClick", "headerDblClick", "headerContext", "headerTap", "headerDblTap", "headerTapHold", "headerTooltip", "headerVertical", "editableTitle", "titleFormatter", "titleFormatterParams", "headerFilter", "headerFilterPlaceholder", "headerFilterParams", "headerFilterEmptyCheck", "headerFilterFunc", "headerFilterFuncParams", "headerFilterLiveFilter", "print", "headerContextMenu", "headerMenu", "contextMenu", "formatterPrint", "formatterPrintParams", "formatterClipboard", "formatterClipboardParams", "formatterHtmlOutput", "formatterHtmlOutputParams"];
  1620. //////////////// Event Bindings /////////////////
  1621. //////////////// Object Generation /////////////////
  1622. Column.prototype.getComponent = function () {
  1623. return new ColumnComponent(this);
  1624. };
  1625. var RowManager = function RowManager(table) {
  1626. this.table = table;
  1627. this.element = this.createHolderElement(); //containing element
  1628. this.tableElement = this.createTableElement(); //table element
  1629. this.heightFixer = this.createTableElement(); //table element
  1630. this.columnManager = null; //hold column manager object
  1631. this.height = 0; //hold height of table element
  1632. this.firstRender = false; //handle first render
  1633. this.renderMode = "virtual"; //current rendering mode
  1634. this.fixedHeight = false; //current rendering mode
  1635. this.rows = []; //hold row data objects
  1636. this.activeRows = []; //rows currently available to on display in the table
  1637. this.activeRowsCount = 0; //count of active rows
  1638. this.displayRows = []; //rows currently on display in the table
  1639. this.displayRowsCount = 0; //count of display rows
  1640. this.scrollTop = 0;
  1641. this.scrollLeft = 0;
  1642. this.vDomRowHeight = 20; //approximation of row heights for padding
  1643. this.vDomTop = 0; //hold position for first rendered row in the virtual DOM
  1644. this.vDomBottom = 0; //hold possition for last rendered row in the virtual DOM
  1645. this.vDomScrollPosTop = 0; //last scroll position of the vDom top;
  1646. this.vDomScrollPosBottom = 0; //last scroll position of the vDom bottom;
  1647. this.vDomTopPad = 0; //hold value of padding for top of virtual DOM
  1648. this.vDomBottomPad = 0; //hold value of padding for bottom of virtual DOM
  1649. this.vDomMaxRenderChain = 90; //the maximum number of dom elements that can be rendered in 1 go
  1650. this.vDomWindowBuffer = 0; //window row buffer before removing elements, to smooth scrolling
  1651. this.vDomWindowMinTotalRows = 20; //minimum number of rows to be generated in virtual dom (prevent buffering issues on tables with tall rows)
  1652. this.vDomWindowMinMarginRows = 5; //minimum number of rows to be generated in virtual dom margin
  1653. this.vDomTopNewRows = []; //rows to normalize after appending to optimize render speed
  1654. this.vDomBottomNewRows = []; //rows to normalize after appending to optimize render speed
  1655. this.rowNumColumn = false; //hold column component for row number column
  1656. this.redrawBlock = false; //prevent redraws to allow multiple data manipulations becore continuing
  1657. this.redrawBlockRestoreConfig = false; //store latest redraw function calls for when redraw is needed
  1658. this.redrawBlockRederInPosition = false; //store latest redraw function calls for when redraw is needed
  1659. };
  1660. //////////////// Setup Functions /////////////////
  1661. RowManager.prototype.createHolderElement = function () {
  1662. var el = document.createElement("div");
  1663. el.classList.add("tabulator-tableHolder");
  1664. el.setAttribute("tabindex", 0);
  1665. return el;
  1666. };
  1667. RowManager.prototype.createTableElement = function () {
  1668. var el = document.createElement("div");
  1669. el.classList.add("tabulator-table");
  1670. return el;
  1671. };
  1672. //return containing element
  1673. RowManager.prototype.getElement = function () {
  1674. return this.element;
  1675. };
  1676. //return table element
  1677. RowManager.prototype.getTableElement = function () {
  1678. return this.tableElement;
  1679. };
  1680. //return position of row in table
  1681. RowManager.prototype.getRowPosition = function (row, active) {
  1682. if (active) {
  1683. return this.activeRows.indexOf(row);
  1684. } else {
  1685. return this.rows.indexOf(row);
  1686. }
  1687. };
  1688. //link to column manager
  1689. RowManager.prototype.setColumnManager = function (manager) {
  1690. this.columnManager = manager;
  1691. };
  1692. RowManager.prototype.initialize = function () {
  1693. var self = this;
  1694. self.setRenderMode();
  1695. //initialize manager
  1696. self.element.appendChild(self.tableElement);
  1697. self.firstRender = true;
  1698. //scroll header along with table body
  1699. self.element.addEventListener("scroll", function () {
  1700. var left = self.element.scrollLeft;
  1701. //handle horizontal scrolling
  1702. if (self.scrollLeft != left) {
  1703. self.columnManager.scrollHorizontal(left);
  1704. if (self.table.options.groupBy) {
  1705. self.table.modules.groupRows.scrollHeaders(left);
  1706. }
  1707. if (self.table.modExists("columnCalcs")) {
  1708. self.table.modules.columnCalcs.scrollHorizontal(left);
  1709. }
  1710. self.table.options.scrollHorizontal(left);
  1711. }
  1712. self.scrollLeft = left;
  1713. });
  1714. //handle virtual dom scrolling
  1715. if (this.renderMode === "virtual") {
  1716. self.element.addEventListener("scroll", function () {
  1717. var top = self.element.scrollTop;
  1718. var dir = self.scrollTop > top;
  1719. //handle verical scrolling
  1720. if (self.scrollTop != top) {
  1721. self.scrollTop = top;
  1722. self.scrollVertical(dir);
  1723. if (self.table.options.ajaxProgressiveLoad == "scroll") {
  1724. self.table.modules.ajax.nextPage(self.element.scrollHeight - self.element.clientHeight - top);
  1725. }
  1726. self.table.options.scrollVertical(top);
  1727. } else {
  1728. self.scrollTop = top;
  1729. }
  1730. });
  1731. }
  1732. };
  1733. ////////////////// Row Manipulation //////////////////
  1734. RowManager.prototype.findRow = function (subject) {
  1735. var self = this;
  1736. if ((typeof subject === 'undefined' ? 'undefined' : _typeof(subject)) == "object") {
  1737. if (subject instanceof Row) {
  1738. //subject is row element
  1739. return subject;
  1740. } else if (subject instanceof RowComponent) {
  1741. //subject is public row component
  1742. return subject._getSelf() || false;
  1743. } else if (typeof HTMLElement !== "undefined" && subject instanceof HTMLElement) {
  1744. //subject is a HTML element of the row
  1745. var match = self.rows.find(function (row) {
  1746. return row.element === subject;
  1747. });
  1748. return match || false;
  1749. }
  1750. } else if (typeof subject == "undefined" || subject === null) {
  1751. return false;
  1752. } else {
  1753. //subject should be treated as the index of the row
  1754. var _match = self.rows.find(function (row) {
  1755. return row.data[self.table.options.index] == subject;
  1756. });
  1757. return _match || false;
  1758. }
  1759. //catch all for any other type of input
  1760. return false;
  1761. };
  1762. RowManager.prototype.getRowFromDataObject = function (data) {
  1763. var match = this.rows.find(function (row) {
  1764. return row.data === data;
  1765. });
  1766. return match || false;
  1767. };
  1768. RowManager.prototype.getRowFromPosition = function (position, active) {
  1769. if (active) {
  1770. return this.activeRows[position];
  1771. } else {
  1772. return this.rows[position];
  1773. }
  1774. };
  1775. RowManager.prototype.scrollToRow = function (row, position, ifVisible) {
  1776. var _this9 = this;
  1777. var rowIndex = this.getDisplayRows().indexOf(row),
  1778. rowEl = row.getElement(),
  1779. rowTop,
  1780. offset = 0;
  1781. return new Promise(function (resolve, reject) {
  1782. if (rowIndex > -1) {
  1783. if (typeof position === "undefined") {
  1784. position = _this9.table.options.scrollToRowPosition;
  1785. }
  1786. if (typeof ifVisible === "undefined") {
  1787. ifVisible = _this9.table.options.scrollToRowIfVisible;
  1788. }
  1789. if (position === "nearest") {
  1790. switch (_this9.renderMode) {
  1791. case "classic":
  1792. rowTop = Tabulator.prototype.helpers.elOffset(rowEl).top;
  1793. position = Math.abs(_this9.element.scrollTop - rowTop) > Math.abs(_this9.element.scrollTop + _this9.element.clientHeight - rowTop) ? "bottom" : "top";
  1794. break;
  1795. case "virtual":
  1796. position = Math.abs(_this9.vDomTop - rowIndex) > Math.abs(_this9.vDomBottom - rowIndex) ? "bottom" : "top";
  1797. break;
  1798. }
  1799. }
  1800. //check row visibility
  1801. if (!ifVisible) {
  1802. if (Tabulator.prototype.helpers.elVisible(rowEl)) {
  1803. offset = Tabulator.prototype.helpers.elOffset(rowEl).top - Tabulator.prototype.helpers.elOffset(_this9.element).top;
  1804. if (offset > 0 && offset < _this9.element.clientHeight - rowEl.offsetHeight) {
  1805. return false;
  1806. }
  1807. }
  1808. }
  1809. //scroll to row
  1810. switch (_this9.renderMode) {
  1811. case "classic":
  1812. _this9.element.scrollTop = Tabulator.prototype.helpers.elOffset(rowEl).top - Tabulator.prototype.helpers.elOffset(_this9.element).top + _this9.element.scrollTop;
  1813. break;
  1814. case "virtual":
  1815. _this9._virtualRenderFill(rowIndex, true);
  1816. break;
  1817. }
  1818. //align to correct position
  1819. switch (position) {
  1820. case "middle":
  1821. case "center":
  1822. if (_this9.element.scrollHeight - _this9.element.scrollTop == _this9.element.clientHeight) {
  1823. _this9.element.scrollTop = _this9.element.scrollTop + (rowEl.offsetTop - _this9.element.scrollTop) - (_this9.element.scrollHeight - rowEl.offsetTop) / 2;
  1824. } else {
  1825. _this9.element.scrollTop = _this9.element.scrollTop - _this9.element.clientHeight / 2;
  1826. }
  1827. break;
  1828. case "bottom":
  1829. if (_this9.element.scrollHeight - _this9.element.scrollTop == _this9.element.clientHeight) {
  1830. _this9.element.scrollTop = _this9.element.scrollTop - (_this9.element.scrollHeight - rowEl.offsetTop) + rowEl.offsetHeight;
  1831. } else {
  1832. _this9.element.scrollTop = _this9.element.scrollTop - _this9.element.clientHeight + rowEl.offsetHeight;
  1833. }
  1834. break;
  1835. }
  1836. resolve();
  1837. } else {
  1838. console.warn("Scroll Error - Row not visible");
  1839. reject("Scroll Error - Row not visible");
  1840. }
  1841. });
  1842. };
  1843. ////////////////// Data Handling //////////////////
  1844. RowManager.prototype.setData = function (data, renderInPosition, columnsChanged) {
  1845. var _this10 = this;
  1846. var self = this;
  1847. return new Promise(function (resolve, reject) {
  1848. if (renderInPosition && _this10.getDisplayRows().length) {
  1849. if (self.table.options.pagination) {
  1850. self._setDataActual(data, true);
  1851. } else {
  1852. _this10.reRenderInPosition(function () {
  1853. self._setDataActual(data);
  1854. });
  1855. }
  1856. } else {
  1857. if (_this10.table.options.autoColumns && columnsChanged) {
  1858. _this10.table.columnManager.generateColumnsFromRowData(data);
  1859. }
  1860. _this10.resetScroll();
  1861. _this10._setDataActual(data);
  1862. }
  1863. resolve();
  1864. });
  1865. };
  1866. RowManager.prototype._setDataActual = function (data, renderInPosition) {
  1867. var self = this;
  1868. self.table.options.dataLoading.call(this.table, data);
  1869. this._wipeElements();
  1870. if (this.table.options.history && this.table.modExists("history")) {
  1871. this.table.modules.history.clear();
  1872. }
  1873. if (Array.isArray(data)) {
  1874. if (this.table.modExists("selectRow")) {
  1875. this.table.modules.selectRow.clearSelectionData();
  1876. }
  1877. if (this.table.options.reactiveData && this.table.modExists("reactiveData", true)) {
  1878. this.table.modules.reactiveData.watchData(data);
  1879. }
  1880. data.forEach(function (def, i) {
  1881. if (def && (typeof def === 'undefined' ? 'undefined' : _typeof(def)) === "object") {
  1882. var row = new Row(def, self);
  1883. self.rows.push(row);
  1884. } else {
  1885. console.warn("Data Loading Warning - Invalid row data detected and ignored, expecting object but received:", def);
  1886. }
  1887. });
  1888. self.table.options.dataLoaded.call(this.table, data);
  1889. self.refreshActiveData(false, false, renderInPosition);
  1890. } else {
  1891. console.error("Data Loading Error - Unable to process data due to invalid data type \nExpecting: array \nReceived: ", typeof data === 'undefined' ? 'undefined' : _typeof(data), "\nData: ", data);
  1892. }
  1893. };
  1894. RowManager.prototype._wipeElements = function () {
  1895. this.rows.forEach(function (row) {
  1896. row.wipe();
  1897. });
  1898. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  1899. this.table.modules.groupRows.wipe();
  1900. }
  1901. this.rows = [];
  1902. };
  1903. RowManager.prototype.deleteRow = function (row, blockRedraw) {
  1904. var allIndex = this.rows.indexOf(row),
  1905. activeIndex = this.activeRows.indexOf(row);
  1906. if (activeIndex > -1) {
  1907. this.activeRows.splice(activeIndex, 1);
  1908. }
  1909. if (allIndex > -1) {
  1910. this.rows.splice(allIndex, 1);
  1911. }
  1912. this.setActiveRows(this.activeRows);
  1913. this.displayRowIterator(function (rows) {
  1914. var displayIndex = rows.indexOf(row);
  1915. if (displayIndex > -1) {
  1916. rows.splice(displayIndex, 1);
  1917. }
  1918. });
  1919. if (!blockRedraw) {
  1920. this.reRenderInPosition();
  1921. }
  1922. this.regenerateRowNumbers();
  1923. this.table.options.rowDeleted.call(this.table, row.getComponent());
  1924. this.table.options.dataEdited.call(this.table, this.getData());
  1925. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  1926. this.table.modules.groupRows.updateGroupRows(true);
  1927. } else if (this.table.options.pagination && this.table.modExists("page")) {
  1928. this.refreshActiveData(false, false, true);
  1929. } else {
  1930. if (this.table.options.pagination && this.table.modExists("page")) {
  1931. this.refreshActiveData("page");
  1932. }
  1933. }
  1934. };
  1935. RowManager.prototype.addRow = function (data, pos, index, blockRedraw) {
  1936. var row = this.addRowActual(data, pos, index, blockRedraw);
  1937. if (this.table.options.history && this.table.modExists("history")) {
  1938. this.table.modules.history.action("rowAdd", row, { data: data, pos: pos, index: index });
  1939. }
  1940. return row;
  1941. };
  1942. //add multiple rows
  1943. RowManager.prototype.addRows = function (data, pos, index) {
  1944. var _this11 = this;
  1945. var self = this,
  1946. length = 0,
  1947. rows = [];
  1948. return new Promise(function (resolve, reject) {
  1949. pos = _this11.findAddRowPos(pos);
  1950. if (!Array.isArray(data)) {
  1951. data = [data];
  1952. }
  1953. length = data.length - 1;
  1954. if (typeof index == "undefined" && pos || typeof index !== "undefined" && !pos) {
  1955. data.reverse();
  1956. }
  1957. data.forEach(function (item, i) {
  1958. var row = self.addRow(item, pos, index, true);
  1959. rows.push(row);
  1960. });
  1961. if (_this11.table.options.groupBy && _this11.table.modExists("groupRows")) {
  1962. _this11.table.modules.groupRows.updateGroupRows(true);
  1963. } else if (_this11.table.options.pagination && _this11.table.modExists("page")) {
  1964. _this11.refreshActiveData(false, false, true);
  1965. } else {
  1966. _this11.reRenderInPosition();
  1967. }
  1968. //recalc column calculations if present
  1969. if (_this11.table.modExists("columnCalcs")) {
  1970. _this11.table.modules.columnCalcs.recalc(_this11.table.rowManager.activeRows);
  1971. }
  1972. _this11.regenerateRowNumbers();
  1973. resolve(rows);
  1974. });
  1975. };
  1976. RowManager.prototype.findAddRowPos = function (pos) {
  1977. if (typeof pos === "undefined") {
  1978. pos = this.table.options.addRowPos;
  1979. }
  1980. if (pos === "pos") {
  1981. pos = true;
  1982. }
  1983. if (pos === "bottom") {
  1984. pos = false;
  1985. }
  1986. return pos;
  1987. };
  1988. RowManager.prototype.addRowActual = function (data, pos, index, blockRedraw) {
  1989. var row = data instanceof Row ? data : new Row(data || {}, this),
  1990. top = this.findAddRowPos(pos),
  1991. allIndex = -1,
  1992. activeIndex,
  1993. dispRows;
  1994. if (!index && this.table.options.pagination && this.table.options.paginationAddRow == "page") {
  1995. dispRows = this.getDisplayRows();
  1996. if (top) {
  1997. if (dispRows.length) {
  1998. index = dispRows[0];
  1999. } else {
  2000. if (this.activeRows.length) {
  2001. index = this.activeRows[this.activeRows.length - 1];
  2002. top = false;
  2003. }
  2004. }
  2005. } else {
  2006. if (dispRows.length) {
  2007. index = dispRows[dispRows.length - 1];
  2008. top = dispRows.length < this.table.modules.page.getPageSize() ? false : true;
  2009. }
  2010. }
  2011. }
  2012. if (typeof index !== "undefined") {
  2013. index = this.findRow(index);
  2014. }
  2015. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  2016. this.table.modules.groupRows.assignRowToGroup(row);
  2017. var groupRows = row.getGroup().rows;
  2018. if (groupRows.length > 1) {
  2019. if (!index || index && groupRows.indexOf(index) == -1) {
  2020. if (top) {
  2021. if (groupRows[0] !== row) {
  2022. index = groupRows[0];
  2023. this._moveRowInArray(row.getGroup().rows, row, index, !top);
  2024. }
  2025. } else {
  2026. if (groupRows[groupRows.length - 1] !== row) {
  2027. index = groupRows[groupRows.length - 1];
  2028. this._moveRowInArray(row.getGroup().rows, row, index, !top);
  2029. }
  2030. }
  2031. } else {
  2032. this._moveRowInArray(row.getGroup().rows, row, index, !top);
  2033. }
  2034. }
  2035. }
  2036. if (index) {
  2037. allIndex = this.rows.indexOf(index);
  2038. }
  2039. if (index && allIndex > -1) {
  2040. activeIndex = this.activeRows.indexOf(index);
  2041. this.displayRowIterator(function (rows) {
  2042. var displayIndex = rows.indexOf(index);
  2043. if (displayIndex > -1) {
  2044. rows.splice(top ? displayIndex : displayIndex + 1, 0, row);
  2045. }
  2046. });
  2047. if (activeIndex > -1) {
  2048. this.activeRows.splice(top ? activeIndex : activeIndex + 1, 0, row);
  2049. }
  2050. this.rows.splice(top ? allIndex : allIndex + 1, 0, row);
  2051. } else {
  2052. if (top) {
  2053. this.displayRowIterator(function (rows) {
  2054. rows.unshift(row);
  2055. });
  2056. this.activeRows.unshift(row);
  2057. this.rows.unshift(row);
  2058. } else {
  2059. this.displayRowIterator(function (rows) {
  2060. rows.push(row);
  2061. });
  2062. this.activeRows.push(row);
  2063. this.rows.push(row);
  2064. }
  2065. }
  2066. this.setActiveRows(this.activeRows);
  2067. this.table.options.rowAdded.call(this.table, row.getComponent());
  2068. this.table.options.dataEdited.call(this.table, this.getData());
  2069. if (!blockRedraw) {
  2070. this.reRenderInPosition();
  2071. }
  2072. return row;
  2073. };
  2074. RowManager.prototype.moveRow = function (from, to, after) {
  2075. if (this.table.options.history && this.table.modExists("history")) {
  2076. this.table.modules.history.action("rowMove", from, { posFrom: this.getRowPosition(from), posTo: this.getRowPosition(to), to: to, after: after });
  2077. }
  2078. this.moveRowActual(from, to, after);
  2079. this.regenerateRowNumbers();
  2080. this.table.options.rowMoved.call(this.table, from.getComponent());
  2081. };
  2082. RowManager.prototype.moveRowActual = function (from, to, after) {
  2083. var _this12 = this;
  2084. this._moveRowInArray(this.rows, from, to, after);
  2085. this._moveRowInArray(this.activeRows, from, to, after);
  2086. this.displayRowIterator(function (rows) {
  2087. _this12._moveRowInArray(rows, from, to, after);
  2088. });
  2089. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  2090. if (!after && to instanceof Group) {
  2091. to = this.table.rowManager.prevDisplayRow(from) || to;
  2092. }
  2093. var toGroup = to.getGroup();
  2094. var fromGroup = from.getGroup();
  2095. if (toGroup === fromGroup) {
  2096. this._moveRowInArray(toGroup.rows, from, to, after);
  2097. } else {
  2098. if (fromGroup) {
  2099. fromGroup.removeRow(from);
  2100. }
  2101. toGroup.insertRow(from, to, after);
  2102. }
  2103. }
  2104. };
  2105. RowManager.prototype._moveRowInArray = function (rows, from, to, after) {
  2106. var fromIndex, toIndex, start, end;
  2107. if (from !== to) {
  2108. fromIndex = rows.indexOf(from);
  2109. if (fromIndex > -1) {
  2110. rows.splice(fromIndex, 1);
  2111. toIndex = rows.indexOf(to);
  2112. if (toIndex > -1) {
  2113. if (after) {
  2114. rows.splice(toIndex + 1, 0, from);
  2115. } else {
  2116. rows.splice(toIndex, 0, from);
  2117. }
  2118. } else {
  2119. rows.splice(fromIndex, 0, from);
  2120. }
  2121. }
  2122. //restyle rows
  2123. if (rows === this.getDisplayRows()) {
  2124. start = fromIndex < toIndex ? fromIndex : toIndex;
  2125. end = toIndex > fromIndex ? toIndex : fromIndex + 1;
  2126. for (var i = start; i <= end; i++) {
  2127. if (rows[i]) {
  2128. this.styleRow(rows[i], i);
  2129. }
  2130. }
  2131. }
  2132. }
  2133. };
  2134. RowManager.prototype.clearData = function () {
  2135. this.setData([]);
  2136. };
  2137. RowManager.prototype.getRowIndex = function (row) {
  2138. return this.findRowIndex(row, this.rows);
  2139. };
  2140. RowManager.prototype.getDisplayRowIndex = function (row) {
  2141. var index = this.getDisplayRows().indexOf(row);
  2142. return index > -1 ? index : false;
  2143. };
  2144. RowManager.prototype.nextDisplayRow = function (row, rowOnly) {
  2145. var index = this.getDisplayRowIndex(row),
  2146. nextRow = false;
  2147. if (index !== false && index < this.displayRowsCount - 1) {
  2148. nextRow = this.getDisplayRows()[index + 1];
  2149. }
  2150. if (nextRow && (!(nextRow instanceof Row) || nextRow.type != "row")) {
  2151. return this.nextDisplayRow(nextRow, rowOnly);
  2152. }
  2153. return nextRow;
  2154. };
  2155. RowManager.prototype.prevDisplayRow = function (row, rowOnly) {
  2156. var index = this.getDisplayRowIndex(row),
  2157. prevRow = false;
  2158. if (index) {
  2159. prevRow = this.getDisplayRows()[index - 1];
  2160. }
  2161. if (rowOnly && prevRow && (!(prevRow instanceof Row) || prevRow.type != "row")) {
  2162. return this.prevDisplayRow(prevRow, rowOnly);
  2163. }
  2164. return prevRow;
  2165. };
  2166. RowManager.prototype.findRowIndex = function (row, list) {
  2167. var rowIndex;
  2168. row = this.findRow(row);
  2169. if (row) {
  2170. rowIndex = list.indexOf(row);
  2171. if (rowIndex > -1) {
  2172. return rowIndex;
  2173. }
  2174. }
  2175. return false;
  2176. };
  2177. RowManager.prototype.getData = function (active, transform) {
  2178. var output = [],
  2179. rows = this.getRows(active);
  2180. rows.forEach(function (row) {
  2181. if (row.type == "row") {
  2182. output.push(row.getData(transform || "data"));
  2183. }
  2184. });
  2185. return output;
  2186. };
  2187. RowManager.prototype.getComponents = function (active) {
  2188. var output = [],
  2189. rows = this.getRows(active);
  2190. rows.forEach(function (row) {
  2191. output.push(row.getComponent());
  2192. });
  2193. return output;
  2194. };
  2195. RowManager.prototype.getDataCount = function (active) {
  2196. var rows = this.getRows(active);
  2197. return rows.length;
  2198. };
  2199. RowManager.prototype._genRemoteRequest = function () {
  2200. var _this13 = this;
  2201. var table = this.table,
  2202. options = table.options,
  2203. params = {};
  2204. if (table.modExists("page")) {
  2205. //set sort data if defined
  2206. if (options.ajaxSorting) {
  2207. var sorters = this.table.modules.sort.getSort();
  2208. sorters.forEach(function (item) {
  2209. delete item.column;
  2210. });
  2211. params[this.table.modules.page.paginationDataSentNames.sorters] = sorters;
  2212. }
  2213. //set filter data if defined
  2214. if (options.ajaxFiltering) {
  2215. var filters = this.table.modules.filter.getFilters(true, true);
  2216. params[this.table.modules.page.paginationDataSentNames.filters] = filters;
  2217. }
  2218. this.table.modules.ajax.setParams(params, true);
  2219. }
  2220. table.modules.ajax.sendRequest().then(function (data) {
  2221. _this13._setDataActual(data, true);
  2222. }).catch(function (e) {});
  2223. };
  2224. //choose the path to refresh data after a filter update
  2225. RowManager.prototype.filterRefresh = function () {
  2226. var table = this.table,
  2227. options = table.options,
  2228. left = this.scrollLeft;
  2229. if (options.ajaxFiltering) {
  2230. if (options.pagination == "remote" && table.modExists("page")) {
  2231. table.modules.page.reset(true);
  2232. table.modules.page.setPage(1).then(function () {}).catch(function () {});
  2233. } else if (options.ajaxProgressiveLoad) {
  2234. table.modules.ajax.loadData().then(function () {}).catch(function () {});
  2235. } else {
  2236. //assume data is url, make ajax call to url to get data
  2237. this._genRemoteRequest();
  2238. }
  2239. } else {
  2240. this.refreshActiveData("filter");
  2241. }
  2242. this.scrollHorizontal(left);
  2243. };
  2244. //choose the path to refresh data after a sorter update
  2245. RowManager.prototype.sorterRefresh = function (loadOrignalData) {
  2246. var table = this.table,
  2247. options = this.table.options,
  2248. left = this.scrollLeft;
  2249. if (options.ajaxSorting) {
  2250. if ((options.pagination == "remote" || options.progressiveLoad) && table.modExists("page")) {
  2251. table.modules.page.reset(true);
  2252. table.modules.page.setPage(1).then(function () {}).catch(function () {});
  2253. } else if (options.ajaxProgressiveLoad) {
  2254. table.modules.ajax.loadData().then(function () {}).catch(function () {});
  2255. } else {
  2256. //assume data is url, make ajax call to url to get data
  2257. this._genRemoteRequest();
  2258. }
  2259. } else {
  2260. this.refreshActiveData(loadOrignalData ? "filter" : "sort");
  2261. }
  2262. this.scrollHorizontal(left);
  2263. };
  2264. RowManager.prototype.scrollHorizontal = function (left) {
  2265. this.scrollLeft = left;
  2266. this.element.scrollLeft = left;
  2267. if (this.table.options.groupBy) {
  2268. this.table.modules.groupRows.scrollHeaders(left);
  2269. }
  2270. if (this.table.modExists("columnCalcs")) {
  2271. this.table.modules.columnCalcs.scrollHorizontal(left);
  2272. }
  2273. };
  2274. //set active data set
  2275. RowManager.prototype.refreshActiveData = function (stage, skipStage, renderInPosition) {
  2276. var self = this,
  2277. table = this.table,
  2278. cascadeOrder = ["all", "filter", "sort", "display", "freeze", "group", "tree", "page"],
  2279. displayIndex;
  2280. if (this.redrawBlock) {
  2281. if (!this.redrawBlockRestoreConfig || cascadeOrder.indexOf(stage) < cascadeOrder.indexOf(this.redrawBlockRestoreConfig.stage)) {
  2282. this.redrawBlockRestoreConfig = {
  2283. stage: stage,
  2284. skipStage: skipStage,
  2285. renderInPosition: renderInPosition
  2286. };
  2287. }
  2288. return;
  2289. } else {
  2290. if (self.table.modExists("edit")) {
  2291. self.table.modules.edit.cancelEdit();
  2292. }
  2293. if (!stage) {
  2294. stage = "all";
  2295. }
  2296. if (table.options.selectable && !table.options.selectablePersistence && table.modExists("selectRow")) {
  2297. table.modules.selectRow.deselectRows();
  2298. }
  2299. //cascade through data refresh stages
  2300. switch (stage) {
  2301. case "all":
  2302. case "filter":
  2303. if (!skipStage) {
  2304. if (table.modExists("filter")) {
  2305. self.setActiveRows(table.modules.filter.filter(self.rows));
  2306. } else {
  2307. self.setActiveRows(self.rows.slice(0));
  2308. }
  2309. } else {
  2310. skipStage = false;
  2311. }
  2312. case "sort":
  2313. if (!skipStage) {
  2314. if (table.modExists("sort")) {
  2315. table.modules.sort.sort(this.activeRows);
  2316. }
  2317. } else {
  2318. skipStage = false;
  2319. }
  2320. //regenerate row numbers for row number formatter if in use
  2321. this.regenerateRowNumbers();
  2322. //generic stage to allow for pipeline trigger after the data manipulation stage
  2323. case "display":
  2324. this.resetDisplayRows();
  2325. case "freeze":
  2326. if (!skipStage) {
  2327. if (this.table.modExists("frozenRows")) {
  2328. if (table.modules.frozenRows.isFrozen()) {
  2329. if (!table.modules.frozenRows.getDisplayIndex()) {
  2330. table.modules.frozenRows.setDisplayIndex(this.getNextDisplayIndex());
  2331. }
  2332. displayIndex = table.modules.frozenRows.getDisplayIndex();
  2333. displayIndex = self.setDisplayRows(table.modules.frozenRows.getRows(this.getDisplayRows(displayIndex - 1)), displayIndex);
  2334. if (displayIndex !== true) {
  2335. table.modules.frozenRows.setDisplayIndex(displayIndex);
  2336. }
  2337. }
  2338. }
  2339. } else {
  2340. skipStage = false;
  2341. }
  2342. case "group":
  2343. if (!skipStage) {
  2344. if (table.options.groupBy && table.modExists("groupRows")) {
  2345. if (!table.modules.groupRows.getDisplayIndex()) {
  2346. table.modules.groupRows.setDisplayIndex(this.getNextDisplayIndex());
  2347. }
  2348. displayIndex = table.modules.groupRows.getDisplayIndex();
  2349. displayIndex = self.setDisplayRows(table.modules.groupRows.getRows(this.getDisplayRows(displayIndex - 1)), displayIndex);
  2350. if (displayIndex !== true) {
  2351. table.modules.groupRows.setDisplayIndex(displayIndex);
  2352. }
  2353. }
  2354. } else {
  2355. skipStage = false;
  2356. }
  2357. case "tree":
  2358. if (!skipStage) {
  2359. if (table.options.dataTree && table.modExists("dataTree")) {
  2360. if (!table.modules.dataTree.getDisplayIndex()) {
  2361. table.modules.dataTree.setDisplayIndex(this.getNextDisplayIndex());
  2362. }
  2363. displayIndex = table.modules.dataTree.getDisplayIndex();
  2364. displayIndex = self.setDisplayRows(table.modules.dataTree.getRows(this.getDisplayRows(displayIndex - 1)), displayIndex);
  2365. if (displayIndex !== true) {
  2366. table.modules.dataTree.setDisplayIndex(displayIndex);
  2367. }
  2368. }
  2369. } else {
  2370. skipStage = false;
  2371. }
  2372. if (table.options.pagination && table.modExists("page") && !renderInPosition) {
  2373. if (table.modules.page.getMode() == "local") {
  2374. table.modules.page.reset();
  2375. }
  2376. }
  2377. case "page":
  2378. if (!skipStage) {
  2379. if (table.options.pagination && table.modExists("page")) {
  2380. if (!table.modules.page.getDisplayIndex()) {
  2381. table.modules.page.setDisplayIndex(this.getNextDisplayIndex());
  2382. }
  2383. displayIndex = table.modules.page.getDisplayIndex();
  2384. if (table.modules.page.getMode() == "local") {
  2385. table.modules.page.setMaxRows(this.getDisplayRows(displayIndex - 1).length);
  2386. }
  2387. displayIndex = self.setDisplayRows(table.modules.page.getRows(this.getDisplayRows(displayIndex - 1)), displayIndex);
  2388. if (displayIndex !== true) {
  2389. table.modules.page.setDisplayIndex(displayIndex);
  2390. }
  2391. }
  2392. } else {
  2393. skipStage = false;
  2394. }
  2395. }
  2396. if (Tabulator.prototype.helpers.elVisible(self.element)) {
  2397. if (renderInPosition) {
  2398. self.reRenderInPosition();
  2399. } else {
  2400. self.renderTable();
  2401. if (table.options.layoutColumnsOnNewData) {
  2402. self.table.columnManager.redraw(true);
  2403. }
  2404. }
  2405. }
  2406. if (table.modExists("columnCalcs")) {
  2407. table.modules.columnCalcs.recalc(this.activeRows);
  2408. }
  2409. }
  2410. };
  2411. //regenerate row numbers for row number formatter if in use
  2412. RowManager.prototype.regenerateRowNumbers = function () {
  2413. var _this14 = this;
  2414. if (this.rowNumColumn) {
  2415. this.activeRows.forEach(function (row) {
  2416. var cell = row.getCell(_this14.rowNumColumn);
  2417. if (cell) {
  2418. cell._generateContents();
  2419. }
  2420. });
  2421. }
  2422. };
  2423. RowManager.prototype.setActiveRows = function (activeRows) {
  2424. this.activeRows = activeRows;
  2425. this.activeRowsCount = this.activeRows.length;
  2426. };
  2427. //reset display rows array
  2428. RowManager.prototype.resetDisplayRows = function () {
  2429. this.displayRows = [];
  2430. this.displayRows.push(this.activeRows.slice(0));
  2431. this.displayRowsCount = this.displayRows[0].length;
  2432. if (this.table.modExists("frozenRows")) {
  2433. this.table.modules.frozenRows.setDisplayIndex(0);
  2434. }
  2435. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  2436. this.table.modules.groupRows.setDisplayIndex(0);
  2437. }
  2438. if (this.table.options.pagination && this.table.modExists("page")) {
  2439. this.table.modules.page.setDisplayIndex(0);
  2440. }
  2441. };
  2442. RowManager.prototype.getNextDisplayIndex = function () {
  2443. return this.displayRows.length;
  2444. };
  2445. //set display row pipeline data
  2446. RowManager.prototype.setDisplayRows = function (displayRows, index) {
  2447. var output = true;
  2448. if (index && typeof this.displayRows[index] != "undefined") {
  2449. this.displayRows[index] = displayRows;
  2450. output = true;
  2451. } else {
  2452. this.displayRows.push(displayRows);
  2453. output = index = this.displayRows.length - 1;
  2454. }
  2455. if (index == this.displayRows.length - 1) {
  2456. this.displayRowsCount = this.displayRows[this.displayRows.length - 1].length;
  2457. }
  2458. return output;
  2459. };
  2460. RowManager.prototype.getDisplayRows = function (index) {
  2461. if (typeof index == "undefined") {
  2462. return this.displayRows.length ? this.displayRows[this.displayRows.length - 1] : [];
  2463. } else {
  2464. return this.displayRows[index] || [];
  2465. }
  2466. };
  2467. RowManager.prototype.getVisibleRows = function (viewable) {
  2468. var topEdge = this.element.scrollTop,
  2469. bottomEdge = this.element.clientHeight + topEdge,
  2470. topFound = false,
  2471. topRow = 0,
  2472. bottomRow = 0,
  2473. rows = this.getDisplayRows();
  2474. if (viewable) {
  2475. this.getDisplayRows();
  2476. for (var i = this.vDomTop; i <= this.vDomBottom; i++) {
  2477. if (rows[i]) {
  2478. if (!topFound) {
  2479. if (topEdge - rows[i].getElement().offsetTop >= 0) {
  2480. topRow = i;
  2481. } else {
  2482. topFound = true;
  2483. if (bottomEdge - rows[i].getElement().offsetTop >= 0) {
  2484. bottomRow = i;
  2485. } else {
  2486. break;
  2487. }
  2488. }
  2489. } else {
  2490. if (bottomEdge - rows[i].getElement().offsetTop >= 0) {
  2491. bottomRow = i;
  2492. } else {
  2493. break;
  2494. }
  2495. }
  2496. }
  2497. }
  2498. } else {
  2499. topRow = this.vDomTop;
  2500. bottomRow = this.vDomBottom;
  2501. }
  2502. return rows.slice(topRow, bottomRow + 1);
  2503. };
  2504. //repeat action accross display rows
  2505. RowManager.prototype.displayRowIterator = function (callback) {
  2506. this.displayRows.forEach(callback);
  2507. this.displayRowsCount = this.displayRows[this.displayRows.length - 1].length;
  2508. };
  2509. //return only actual rows (not group headers etc)
  2510. RowManager.prototype.getRows = function (active) {
  2511. var rows;
  2512. switch (active) {
  2513. case "active":
  2514. rows = this.activeRows;
  2515. break;
  2516. case "display":
  2517. rows = this.table.rowManager.getDisplayRows();
  2518. break;
  2519. case "visible":
  2520. rows = this.getVisibleRows(true);
  2521. break;
  2522. default:
  2523. rows = this.rows;
  2524. }
  2525. return rows;
  2526. };
  2527. ///////////////// Table Rendering /////////////////
  2528. //trigger rerender of table in current position
  2529. RowManager.prototype.reRenderInPosition = function (callback) {
  2530. if (this.getRenderMode() == "virtual") {
  2531. if (this.redrawBlock) {
  2532. if (callback) {
  2533. callback();
  2534. } else {
  2535. this.redrawBlockRederInPosition = true;
  2536. }
  2537. } else {
  2538. var scrollTop = this.element.scrollTop;
  2539. var topRow = false;
  2540. var topOffset = false;
  2541. var left = this.scrollLeft;
  2542. var rows = this.getDisplayRows();
  2543. for (var i = this.vDomTop; i <= this.vDomBottom; i++) {
  2544. if (rows[i]) {
  2545. var diff = scrollTop - rows[i].getElement().offsetTop;
  2546. if (topOffset === false || Math.abs(diff) < topOffset) {
  2547. topOffset = diff;
  2548. topRow = i;
  2549. } else {
  2550. break;
  2551. }
  2552. }
  2553. }
  2554. if (callback) {
  2555. callback();
  2556. }
  2557. this._virtualRenderFill(topRow === false ? this.displayRowsCount - 1 : topRow, true, topOffset || 0);
  2558. this.scrollHorizontal(left);
  2559. }
  2560. } else {
  2561. this.renderTable();
  2562. if (callback) {
  2563. callback();
  2564. }
  2565. }
  2566. };
  2567. RowManager.prototype.setRenderMode = function () {
  2568. if (this.table.options.virtualDom) {
  2569. this.renderMode = "virtual";
  2570. if (this.table.element.clientHeight || this.table.options.height) {
  2571. this.fixedHeight = true;
  2572. } else {
  2573. this.fixedHeight = false;
  2574. }
  2575. } else {
  2576. this.renderMode = "classic";
  2577. }
  2578. };
  2579. RowManager.prototype.getRenderMode = function () {
  2580. return this.renderMode;
  2581. };
  2582. RowManager.prototype.renderTable = function () {
  2583. this.table.options.renderStarted.call(this.table);
  2584. this.element.scrollTop = 0;
  2585. switch (this.renderMode) {
  2586. case "classic":
  2587. this._simpleRender();
  2588. break;
  2589. case "virtual":
  2590. this._virtualRenderFill();
  2591. break;
  2592. }
  2593. if (this.firstRender) {
  2594. if (this.displayRowsCount) {
  2595. this.firstRender = false;
  2596. this.table.modules.layout.layout();
  2597. } else {
  2598. this.renderEmptyScroll();
  2599. }
  2600. }
  2601. if (this.table.modExists("frozenColumns")) {
  2602. this.table.modules.frozenColumns.layout();
  2603. }
  2604. if (!this.displayRowsCount) {
  2605. if (this.table.options.placeholder) {
  2606. this.table.options.placeholder.setAttribute("tabulator-render-mode", this.renderMode);
  2607. this.getElement().appendChild(this.table.options.placeholder);
  2608. this.table.options.placeholder.style.width = this.table.columnManager.getWidth() + "px";
  2609. }
  2610. }
  2611. this.table.options.renderComplete.call(this.table);
  2612. };
  2613. //simple render on heightless table
  2614. RowManager.prototype._simpleRender = function () {
  2615. this._clearVirtualDom();
  2616. if (this.displayRowsCount) {
  2617. this.checkClassicModeGroupHeaderWidth();
  2618. } else {
  2619. this.renderEmptyScroll();
  2620. }
  2621. };
  2622. RowManager.prototype.checkClassicModeGroupHeaderWidth = function () {
  2623. var self = this,
  2624. element = this.tableElement,
  2625. onlyGroupHeaders = true;
  2626. self.getDisplayRows().forEach(function (row, index) {
  2627. self.styleRow(row, index);
  2628. element.appendChild(row.getElement());
  2629. row.initialize(true);
  2630. if (row.type !== "group") {
  2631. onlyGroupHeaders = false;
  2632. }
  2633. });
  2634. if (onlyGroupHeaders) {
  2635. element.style.minWidth = self.table.columnManager.getWidth() + "px";
  2636. } else {
  2637. element.style.minWidth = "";
  2638. }
  2639. };
  2640. //show scrollbars on empty table div
  2641. RowManager.prototype.renderEmptyScroll = function () {
  2642. if (this.table.options.placeholder) {
  2643. this.tableElement.style.display = "none";
  2644. } else {
  2645. this.tableElement.style.minWidth = this.table.columnManager.getWidth() + "px";
  2646. this.tableElement.style.minHeight = "1px";
  2647. this.tableElement.style.visibility = "hidden";
  2648. }
  2649. };
  2650. RowManager.prototype._clearVirtualDom = function () {
  2651. var element = this.tableElement;
  2652. if (this.table.options.placeholder && this.table.options.placeholder.parentNode) {
  2653. this.table.options.placeholder.parentNode.removeChild(this.table.options.placeholder);
  2654. }
  2655. // element.children.detach();
  2656. while (element.firstChild) {
  2657. element.removeChild(element.firstChild);
  2658. }element.style.paddingTop = "";
  2659. element.style.paddingBottom = "";
  2660. element.style.minWidth = "";
  2661. element.style.minHeight = "";
  2662. element.style.display = "";
  2663. element.style.visibility = "";
  2664. this.scrollTop = 0;
  2665. this.scrollLeft = 0;
  2666. this.vDomTop = 0;
  2667. this.vDomBottom = 0;
  2668. this.vDomTopPad = 0;
  2669. this.vDomBottomPad = 0;
  2670. };
  2671. RowManager.prototype.styleRow = function (row, index) {
  2672. var rowEl = row.getElement();
  2673. if (index % 2) {
  2674. rowEl.classList.add("tabulator-row-even");
  2675. rowEl.classList.remove("tabulator-row-odd");
  2676. } else {
  2677. rowEl.classList.add("tabulator-row-odd");
  2678. rowEl.classList.remove("tabulator-row-even");
  2679. }
  2680. };
  2681. //full virtual render
  2682. RowManager.prototype._virtualRenderFill = function (position, forceMove, offset) {
  2683. var self = this,
  2684. element = self.tableElement,
  2685. holder = self.element,
  2686. topPad = 0,
  2687. rowsHeight = 0,
  2688. topPadHeight = 0,
  2689. i = 0,
  2690. onlyGroupHeaders = true,
  2691. rows = self.getDisplayRows();
  2692. position = position || 0;
  2693. offset = offset || 0;
  2694. if (!position) {
  2695. self._clearVirtualDom();
  2696. } else {
  2697. while (element.firstChild) {
  2698. element.removeChild(element.firstChild);
  2699. } //check if position is too close to bottom of table
  2700. var heightOccupied = (self.displayRowsCount - position + 1) * self.vDomRowHeight;
  2701. if (heightOccupied < self.height) {
  2702. position -= Math.ceil((self.height - heightOccupied) / self.vDomRowHeight);
  2703. if (position < 0) {
  2704. position = 0;
  2705. }
  2706. }
  2707. //calculate initial pad
  2708. topPad = Math.min(Math.max(Math.floor(self.vDomWindowBuffer / self.vDomRowHeight), self.vDomWindowMinMarginRows), position);
  2709. position -= topPad;
  2710. }
  2711. if (self.displayRowsCount && Tabulator.prototype.helpers.elVisible(self.element)) {
  2712. self.vDomTop = position;
  2713. self.vDomBottom = position - 1;
  2714. while ((rowsHeight <= self.height + self.vDomWindowBuffer || i < self.vDomWindowMinTotalRows) && self.vDomBottom < self.displayRowsCount - 1) {
  2715. var index = self.vDomBottom + 1,
  2716. row = rows[index],
  2717. rowHeight = 0;
  2718. self.styleRow(row, index);
  2719. element.appendChild(row.getElement());
  2720. if (!row.initialized) {
  2721. row.initialize(true);
  2722. } else {
  2723. if (!row.heightInitialized) {
  2724. row.normalizeHeight(true);
  2725. }
  2726. }
  2727. rowHeight = row.getHeight();
  2728. if (i < topPad) {
  2729. topPadHeight += rowHeight;
  2730. } else {
  2731. rowsHeight += rowHeight;
  2732. }
  2733. if (rowHeight > this.vDomWindowBuffer) {
  2734. this.vDomWindowBuffer = rowHeight * 2;
  2735. }
  2736. if (row.type !== "group") {
  2737. onlyGroupHeaders = false;
  2738. }
  2739. self.vDomBottom++;
  2740. i++;
  2741. }
  2742. if (!position) {
  2743. this.vDomTopPad = 0;
  2744. //adjust rowheight to match average of rendered elements
  2745. self.vDomRowHeight = Math.floor((rowsHeight + topPadHeight) / i);
  2746. self.vDomBottomPad = self.vDomRowHeight * (self.displayRowsCount - self.vDomBottom - 1);
  2747. self.vDomScrollHeight = topPadHeight + rowsHeight + self.vDomBottomPad - self.height;
  2748. } else {
  2749. self.vDomTopPad = !forceMove ? self.scrollTop - topPadHeight : self.vDomRowHeight * this.vDomTop + offset;
  2750. self.vDomBottomPad = self.vDomBottom == self.displayRowsCount - 1 ? 0 : Math.max(self.vDomScrollHeight - self.vDomTopPad - rowsHeight - topPadHeight, 0);
  2751. }
  2752. element.style.paddingTop = self.vDomTopPad + "px";
  2753. element.style.paddingBottom = self.vDomBottomPad + "px";
  2754. if (forceMove) {
  2755. this.scrollTop = self.vDomTopPad + topPadHeight + offset - (this.element.scrollWidth > this.element.clientWidth ? this.element.offsetHeight - this.element.clientHeight : 0);
  2756. }
  2757. this.scrollTop = Math.min(this.scrollTop, this.element.scrollHeight - this.height);
  2758. //adjust for horizontal scrollbar if present (and not at top of table)
  2759. if (this.element.scrollWidth > this.element.offsetWidth && forceMove) {
  2760. this.scrollTop += this.element.offsetHeight - this.element.clientHeight;
  2761. }
  2762. this.vDomScrollPosTop = this.scrollTop;
  2763. this.vDomScrollPosBottom = this.scrollTop;
  2764. holder.scrollTop = this.scrollTop;
  2765. element.style.minWidth = onlyGroupHeaders ? self.table.columnManager.getWidth() + "px" : "";
  2766. if (self.table.options.groupBy) {
  2767. if (self.table.modules.layout.getMode() != "fitDataFill" && self.displayRowsCount == self.table.modules.groupRows.countGroups()) {
  2768. self.tableElement.style.minWidth = self.table.columnManager.getWidth();
  2769. }
  2770. }
  2771. } else {
  2772. this.renderEmptyScroll();
  2773. }
  2774. if (!this.fixedHeight) {
  2775. this.adjustTableSize();
  2776. }
  2777. };
  2778. //handle vertical scrolling
  2779. RowManager.prototype.scrollVertical = function (dir) {
  2780. var topDiff = this.scrollTop - this.vDomScrollPosTop;
  2781. var bottomDiff = this.scrollTop - this.vDomScrollPosBottom;
  2782. var margin = this.vDomWindowBuffer * 2;
  2783. if (-topDiff > margin || bottomDiff > margin) {
  2784. //if big scroll redraw table;
  2785. var left = this.scrollLeft;
  2786. this._virtualRenderFill(Math.floor(this.element.scrollTop / this.element.scrollHeight * this.displayRowsCount));
  2787. this.scrollHorizontal(left);
  2788. } else {
  2789. if (dir) {
  2790. //scrolling up
  2791. if (topDiff < 0) {
  2792. this._addTopRow(-topDiff);
  2793. }
  2794. if (bottomDiff < 0) {
  2795. //hide bottom row if needed
  2796. if (this.vDomScrollHeight - this.scrollTop > this.vDomWindowBuffer) {
  2797. this._removeBottomRow(-bottomDiff);
  2798. } else {
  2799. this.vDomScrollPosBottom = this.scrollTop;
  2800. }
  2801. }
  2802. } else {
  2803. //scrolling down
  2804. if (topDiff >= 0) {
  2805. //hide top row if needed
  2806. if (this.scrollTop > this.vDomWindowBuffer) {
  2807. this._removeTopRow(topDiff);
  2808. } else {
  2809. this.vDomScrollPosTop = this.scrollTop;
  2810. }
  2811. }
  2812. if (bottomDiff >= 0) {
  2813. this._addBottomRow(bottomDiff);
  2814. }
  2815. }
  2816. }
  2817. };
  2818. RowManager.prototype._addTopRow = function (topDiff) {
  2819. var i = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  2820. var table = this.tableElement,
  2821. rows = this.getDisplayRows();
  2822. if (this.vDomTop) {
  2823. var index = this.vDomTop - 1,
  2824. topRow = rows[index],
  2825. topRowHeight = topRow.getHeight() || this.vDomRowHeight;
  2826. //hide top row if needed
  2827. if (topDiff >= topRowHeight) {
  2828. this.styleRow(topRow, index);
  2829. table.insertBefore(topRow.getElement(), table.firstChild);
  2830. if (!topRow.initialized || !topRow.heightInitialized) {
  2831. this.vDomTopNewRows.push(topRow);
  2832. if (!topRow.heightInitialized) {
  2833. topRow.clearCellHeight();
  2834. }
  2835. }
  2836. topRow.initialize();
  2837. this.vDomTopPad -= topRowHeight;
  2838. if (this.vDomTopPad < 0) {
  2839. this.vDomTopPad = index * this.vDomRowHeight;
  2840. }
  2841. if (!index) {
  2842. this.vDomTopPad = 0;
  2843. }
  2844. table.style.paddingTop = this.vDomTopPad + "px";
  2845. this.vDomScrollPosTop -= topRowHeight;
  2846. this.vDomTop--;
  2847. }
  2848. topDiff = -(this.scrollTop - this.vDomScrollPosTop);
  2849. if (topRow.getHeight() > this.vDomWindowBuffer) {
  2850. this.vDomWindowBuffer = topRow.getHeight() * 2;
  2851. }
  2852. if (i < this.vDomMaxRenderChain && this.vDomTop && topDiff >= (rows[this.vDomTop - 1].getHeight() || this.vDomRowHeight)) {
  2853. this._addTopRow(topDiff, i + 1);
  2854. } else {
  2855. this._quickNormalizeRowHeight(this.vDomTopNewRows);
  2856. }
  2857. }
  2858. };
  2859. RowManager.prototype._removeTopRow = function (topDiff) {
  2860. var table = this.tableElement,
  2861. topRow = this.getDisplayRows()[this.vDomTop],
  2862. topRowHeight = topRow.getHeight() || this.vDomRowHeight;
  2863. if (topDiff >= topRowHeight) {
  2864. var rowEl = topRow.getElement();
  2865. rowEl.parentNode.removeChild(rowEl);
  2866. this.vDomTopPad += topRowHeight;
  2867. table.style.paddingTop = this.vDomTopPad + "px";
  2868. this.vDomScrollPosTop += this.vDomTop ? topRowHeight : topRowHeight + this.vDomWindowBuffer;
  2869. this.vDomTop++;
  2870. topDiff = this.scrollTop - this.vDomScrollPosTop;
  2871. this._removeTopRow(topDiff);
  2872. }
  2873. };
  2874. RowManager.prototype._addBottomRow = function (bottomDiff) {
  2875. var i = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  2876. var table = this.tableElement,
  2877. rows = this.getDisplayRows();
  2878. if (this.vDomBottom < this.displayRowsCount - 1) {
  2879. var index = this.vDomBottom + 1,
  2880. bottomRow = rows[index],
  2881. bottomRowHeight = bottomRow.getHeight() || this.vDomRowHeight;
  2882. //hide bottom row if needed
  2883. if (bottomDiff >= bottomRowHeight) {
  2884. this.styleRow(bottomRow, index);
  2885. table.appendChild(bottomRow.getElement());
  2886. if (!bottomRow.initialized || !bottomRow.heightInitialized) {
  2887. this.vDomBottomNewRows.push(bottomRow);
  2888. if (!bottomRow.heightInitialized) {
  2889. bottomRow.clearCellHeight();
  2890. }
  2891. }
  2892. bottomRow.initialize();
  2893. this.vDomBottomPad -= bottomRowHeight;
  2894. if (this.vDomBottomPad < 0 || index == this.displayRowsCount - 1) {
  2895. this.vDomBottomPad = 0;
  2896. }
  2897. table.style.paddingBottom = this.vDomBottomPad + "px";
  2898. this.vDomScrollPosBottom += bottomRowHeight;
  2899. this.vDomBottom++;
  2900. }
  2901. bottomDiff = this.scrollTop - this.vDomScrollPosBottom;
  2902. if (bottomRow.getHeight() > this.vDomWindowBuffer) {
  2903. this.vDomWindowBuffer = bottomRow.getHeight() * 2;
  2904. }
  2905. if (i < this.vDomMaxRenderChain && this.vDomBottom < this.displayRowsCount - 1 && bottomDiff >= (rows[this.vDomBottom + 1].getHeight() || this.vDomRowHeight)) {
  2906. this._addBottomRow(bottomDiff, i + 1);
  2907. } else {
  2908. this._quickNormalizeRowHeight(this.vDomBottomNewRows);
  2909. }
  2910. }
  2911. };
  2912. RowManager.prototype._removeBottomRow = function (bottomDiff) {
  2913. var table = this.tableElement,
  2914. bottomRow = this.getDisplayRows()[this.vDomBottom],
  2915. bottomRowHeight = bottomRow.getHeight() || this.vDomRowHeight;
  2916. if (bottomDiff >= bottomRowHeight) {
  2917. var rowEl = bottomRow.getElement();
  2918. if (rowEl.parentNode) {
  2919. rowEl.parentNode.removeChild(rowEl);
  2920. }
  2921. this.vDomBottomPad += bottomRowHeight;
  2922. if (this.vDomBottomPad < 0) {
  2923. this.vDomBottomPad = 0;
  2924. }
  2925. table.style.paddingBottom = this.vDomBottomPad + "px";
  2926. this.vDomScrollPosBottom -= bottomRowHeight;
  2927. this.vDomBottom--;
  2928. bottomDiff = -(this.scrollTop - this.vDomScrollPosBottom);
  2929. this._removeBottomRow(bottomDiff);
  2930. }
  2931. };
  2932. RowManager.prototype._quickNormalizeRowHeight = function (rows) {
  2933. rows.forEach(function (row) {
  2934. row.calcHeight();
  2935. });
  2936. rows.forEach(function (row) {
  2937. row.setCellHeight();
  2938. });
  2939. rows.length = 0;
  2940. };
  2941. //normalize height of active rows
  2942. RowManager.prototype.normalizeHeight = function () {
  2943. this.activeRows.forEach(function (row) {
  2944. row.normalizeHeight();
  2945. });
  2946. };
  2947. //adjust the height of the table holder to fit in the Tabulator element
  2948. RowManager.prototype.adjustTableSize = function () {
  2949. var initialHeight = this.element.clientHeight,
  2950. modExists;
  2951. if (this.renderMode === "virtual") {
  2952. var otherHeight = this.columnManager.getElement().offsetHeight + (this.table.footerManager && !this.table.footerManager.external ? this.table.footerManager.getElement().offsetHeight : 0);
  2953. if (this.fixedHeight) {
  2954. this.element.style.minHeight = "calc(100% - " + otherHeight + "px)";
  2955. this.element.style.height = "calc(100% - " + otherHeight + "px)";
  2956. this.element.style.maxHeight = "calc(100% - " + otherHeight + "px)";
  2957. } else {
  2958. this.element.style.height = "";
  2959. this.element.style.height = this.table.element.clientHeight - otherHeight + "px";
  2960. this.element.scrollTop = this.scrollTop;
  2961. }
  2962. this.height = this.element.clientHeight;
  2963. this.vDomWindowBuffer = this.table.options.virtualDomBuffer || this.height;
  2964. //check if the table has changed size when dealing with variable height tables
  2965. if (!this.fixedHeight && initialHeight != this.element.clientHeight) {
  2966. modExists = this.table.modExists("resizeTable");
  2967. if (modExists && !this.table.modules.resizeTable.autoResize || !modExists) {
  2968. this.redraw();
  2969. }
  2970. }
  2971. }
  2972. };
  2973. //renitialize all rows
  2974. RowManager.prototype.reinitialize = function () {
  2975. this.rows.forEach(function (row) {
  2976. row.reinitialize();
  2977. });
  2978. };
  2979. //prevent table from being redrawn
  2980. RowManager.prototype.blockRedraw = function () {
  2981. this.redrawBlock = true;
  2982. this.redrawBlockRestoreConfig = false;
  2983. };
  2984. //restore table redrawing
  2985. RowManager.prototype.restoreRedraw = function () {
  2986. this.redrawBlock = false;
  2987. if (this.redrawBlockRestoreConfig) {
  2988. this.refreshActiveData(this.redrawBlockRestoreConfig.stage, this.redrawBlockRestoreConfig.skipStage, this.redrawBlockRestoreConfig.renderInPosition);
  2989. this.redrawBlockRestoreConfig = false;
  2990. } else {
  2991. if (this.redrawBlockRederInPosition) {
  2992. this.reRenderInPosition();
  2993. }
  2994. }
  2995. this.redrawBlockRederInPosition = false;
  2996. };
  2997. //redraw table
  2998. RowManager.prototype.redraw = function (force) {
  2999. var pos = 0,
  3000. left = this.scrollLeft;
  3001. this.adjustTableSize();
  3002. this.table.tableWidth = this.table.element.clientWidth;
  3003. if (!force) {
  3004. if (this.renderMode == "classic") {
  3005. if (this.table.options.groupBy) {
  3006. this.refreshActiveData("group", false, false);
  3007. } else {
  3008. this._simpleRender();
  3009. }
  3010. } else {
  3011. this.reRenderInPosition();
  3012. this.scrollHorizontal(left);
  3013. }
  3014. if (!this.displayRowsCount) {
  3015. if (this.table.options.placeholder) {
  3016. this.getElement().appendChild(this.table.options.placeholder);
  3017. }
  3018. }
  3019. } else {
  3020. this.renderTable();
  3021. }
  3022. };
  3023. RowManager.prototype.resetScroll = function () {
  3024. this.element.scrollLeft = 0;
  3025. this.element.scrollTop = 0;
  3026. if (this.table.browser === "ie") {
  3027. var event = document.createEvent("Event");
  3028. event.initEvent("scroll", false, true);
  3029. this.element.dispatchEvent(event);
  3030. } else {
  3031. this.element.dispatchEvent(new Event('scroll'));
  3032. }
  3033. };
  3034. //public row object
  3035. var RowComponent = function RowComponent(row) {
  3036. this._row = row;
  3037. };
  3038. RowComponent.prototype.getData = function (transform) {
  3039. return this._row.getData(transform);
  3040. };
  3041. RowComponent.prototype.getElement = function () {
  3042. return this._row.getElement();
  3043. };
  3044. RowComponent.prototype.getCells = function () {
  3045. var cells = [];
  3046. this._row.getCells().forEach(function (cell) {
  3047. cells.push(cell.getComponent());
  3048. });
  3049. return cells;
  3050. };
  3051. RowComponent.prototype.getCell = function (column) {
  3052. var cell = this._row.getCell(column);
  3053. return cell ? cell.getComponent() : false;
  3054. };
  3055. RowComponent.prototype.getIndex = function () {
  3056. return this._row.getData("data")[this._row.table.options.index];
  3057. };
  3058. RowComponent.prototype.getPosition = function (active) {
  3059. return this._row.table.rowManager.getRowPosition(this._row, active);
  3060. };
  3061. RowComponent.prototype.delete = function () {
  3062. return this._row.delete();
  3063. };
  3064. RowComponent.prototype.scrollTo = function () {
  3065. return this._row.table.rowManager.scrollToRow(this._row);
  3066. };
  3067. RowComponent.prototype.pageTo = function () {
  3068. if (this._row.table.modExists("page", true)) {
  3069. return this._row.table.modules.page.setPageToRow(this._row);
  3070. }
  3071. };
  3072. RowComponent.prototype.move = function (to, after) {
  3073. this._row.moveToRow(to, after);
  3074. };
  3075. RowComponent.prototype.update = function (data) {
  3076. return this._row.updateData(data);
  3077. };
  3078. RowComponent.prototype.normalizeHeight = function () {
  3079. this._row.normalizeHeight(true);
  3080. };
  3081. RowComponent.prototype.select = function () {
  3082. this._row.table.modules.selectRow.selectRows(this._row);
  3083. };
  3084. RowComponent.prototype.deselect = function () {
  3085. this._row.table.modules.selectRow.deselectRows(this._row);
  3086. };
  3087. RowComponent.prototype.toggleSelect = function () {
  3088. this._row.table.modules.selectRow.toggleRow(this._row);
  3089. };
  3090. RowComponent.prototype.isSelected = function () {
  3091. return this._row.table.modules.selectRow.isRowSelected(this._row);
  3092. };
  3093. RowComponent.prototype._getSelf = function () {
  3094. return this._row;
  3095. };
  3096. RowComponent.prototype.freeze = function () {
  3097. if (this._row.table.modExists("frozenRows", true)) {
  3098. this._row.table.modules.frozenRows.freezeRow(this._row);
  3099. }
  3100. };
  3101. RowComponent.prototype.unfreeze = function () {
  3102. if (this._row.table.modExists("frozenRows", true)) {
  3103. this._row.table.modules.frozenRows.unfreezeRow(this._row);
  3104. }
  3105. };
  3106. RowComponent.prototype.treeCollapse = function () {
  3107. if (this._row.table.modExists("dataTree", true)) {
  3108. this._row.table.modules.dataTree.collapseRow(this._row);
  3109. }
  3110. };
  3111. RowComponent.prototype.treeExpand = function () {
  3112. if (this._row.table.modExists("dataTree", true)) {
  3113. this._row.table.modules.dataTree.expandRow(this._row);
  3114. }
  3115. };
  3116. RowComponent.prototype.treeToggle = function () {
  3117. if (this._row.table.modExists("dataTree", true)) {
  3118. this._row.table.modules.dataTree.toggleRow(this._row);
  3119. }
  3120. };
  3121. RowComponent.prototype.getTreeParent = function () {
  3122. if (this._row.table.modExists("dataTree", true)) {
  3123. return this._row.table.modules.dataTree.getTreeParent(this._row);
  3124. }
  3125. return false;
  3126. };
  3127. RowComponent.prototype.getTreeChildren = function () {
  3128. if (this._row.table.modExists("dataTree", true)) {
  3129. return this._row.table.modules.dataTree.getTreeChildren(this._row);
  3130. }
  3131. return false;
  3132. };
  3133. RowComponent.prototype.reformat = function () {
  3134. return this._row.reinitialize();
  3135. };
  3136. RowComponent.prototype.getGroup = function () {
  3137. return this._row.getGroup().getComponent();
  3138. };
  3139. RowComponent.prototype.getTable = function () {
  3140. return this._row.table;
  3141. };
  3142. RowComponent.prototype.getNextRow = function () {
  3143. var row = this._row.nextRow();
  3144. return row ? row.getComponent() : row;
  3145. };
  3146. RowComponent.prototype.getPrevRow = function () {
  3147. var row = this._row.prevRow();
  3148. return row ? row.getComponent() : row;
  3149. };
  3150. var Row = function Row(data, parent) {
  3151. var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "row";
  3152. this.table = parent.table;
  3153. this.parent = parent;
  3154. this.data = {};
  3155. this.type = type; //type of element
  3156. this.element = this.createElement();
  3157. this.modules = {}; //hold module variables;
  3158. this.cells = [];
  3159. this.height = 0; //hold element height
  3160. this.heightStyled = ""; //hold element height prestyled to improve render efficiency
  3161. this.manualHeight = false; //user has manually set row height
  3162. this.outerHeight = 0; //holde lements outer height
  3163. this.initialized = false; //element has been rendered
  3164. this.heightInitialized = false; //element has resized cells to fit
  3165. this.setData(data);
  3166. this.generateElement();
  3167. };
  3168. Row.prototype.createElement = function () {
  3169. var el = document.createElement("div");
  3170. el.classList.add("tabulator-row");
  3171. el.setAttribute("role", "row");
  3172. return el;
  3173. };
  3174. Row.prototype.getElement = function () {
  3175. return this.element;
  3176. };
  3177. Row.prototype.detachElement = function () {
  3178. if (this.element && this.element.parentNode) {
  3179. this.element.parentNode.removeChild(this.element);
  3180. }
  3181. };
  3182. Row.prototype.generateElement = function () {
  3183. var self = this,
  3184. dblTap,
  3185. tapHold,
  3186. tap;
  3187. //set row selection characteristics
  3188. if (self.table.options.selectable !== false && self.table.modExists("selectRow")) {
  3189. self.table.modules.selectRow.initializeRow(this);
  3190. }
  3191. //setup movable rows
  3192. if (self.table.options.movableRows !== false && self.table.modExists("moveRow")) {
  3193. self.table.modules.moveRow.initializeRow(this);
  3194. }
  3195. //setup data tree
  3196. if (self.table.options.dataTree !== false && self.table.modExists("dataTree")) {
  3197. self.table.modules.dataTree.initializeRow(this);
  3198. }
  3199. //setup column colapse container
  3200. if (self.table.options.responsiveLayout === "collapse" && self.table.modExists("responsiveLayout")) {
  3201. self.table.modules.responsiveLayout.initializeRow(this);
  3202. }
  3203. //set column menu
  3204. if (self.table.options.rowContextMenu && this.table.modExists("menu")) {
  3205. self.table.modules.menu.initializeRow(this);
  3206. }
  3207. //handle row click events
  3208. if (self.table.options.rowClick) {
  3209. self.element.addEventListener("click", function (e) {
  3210. self.table.options.rowClick(e, self.getComponent());
  3211. });
  3212. }
  3213. if (self.table.options.rowDblClick) {
  3214. self.element.addEventListener("dblclick", function (e) {
  3215. self.table.options.rowDblClick(e, self.getComponent());
  3216. });
  3217. }
  3218. if (self.table.options.rowContext) {
  3219. self.element.addEventListener("contextmenu", function (e) {
  3220. self.table.options.rowContext(e, self.getComponent());
  3221. });
  3222. }
  3223. //handle mouse events
  3224. if (self.table.options.rowMouseEnter) {
  3225. self.element.addEventListener("mouseenter", function (e) {
  3226. self.table.options.rowMouseEnter(e, self.getComponent());
  3227. });
  3228. }
  3229. if (self.table.options.rowMouseLeave) {
  3230. self.element.addEventListener("mouseleave", function (e) {
  3231. self.table.options.rowMouseLeave(e, self.getComponent());
  3232. });
  3233. }
  3234. if (self.table.options.rowMouseOver) {
  3235. self.element.addEventListener("mouseover", function (e) {
  3236. self.table.options.rowMouseOver(e, self.getComponent());
  3237. });
  3238. }
  3239. if (self.table.options.rowMouseOut) {
  3240. self.element.addEventListener("mouseout", function (e) {
  3241. self.table.options.rowMouseOut(e, self.getComponent());
  3242. });
  3243. }
  3244. if (self.table.options.rowMouseMove) {
  3245. self.element.addEventListener("mousemove", function (e) {
  3246. self.table.options.rowMouseMove(e, self.getComponent());
  3247. });
  3248. }
  3249. if (self.table.options.rowTap) {
  3250. tap = false;
  3251. self.element.addEventListener("touchstart", function (e) {
  3252. tap = true;
  3253. }, { passive: true });
  3254. self.element.addEventListener("touchend", function (e) {
  3255. if (tap) {
  3256. self.table.options.rowTap(e, self.getComponent());
  3257. }
  3258. tap = false;
  3259. });
  3260. }
  3261. if (self.table.options.rowDblTap) {
  3262. dblTap = null;
  3263. self.element.addEventListener("touchend", function (e) {
  3264. if (dblTap) {
  3265. clearTimeout(dblTap);
  3266. dblTap = null;
  3267. self.table.options.rowDblTap(e, self.getComponent());
  3268. } else {
  3269. dblTap = setTimeout(function () {
  3270. clearTimeout(dblTap);
  3271. dblTap = null;
  3272. }, 300);
  3273. }
  3274. });
  3275. }
  3276. if (self.table.options.rowTapHold) {
  3277. tapHold = null;
  3278. self.element.addEventListener("touchstart", function (e) {
  3279. clearTimeout(tapHold);
  3280. tapHold = setTimeout(function () {
  3281. clearTimeout(tapHold);
  3282. tapHold = null;
  3283. tap = false;
  3284. self.table.options.rowTapHold(e, self.getComponent());
  3285. }, 1000);
  3286. }, { passive: true });
  3287. self.element.addEventListener("touchend", function (e) {
  3288. clearTimeout(tapHold);
  3289. tapHold = null;
  3290. });
  3291. }
  3292. };
  3293. Row.prototype.generateCells = function () {
  3294. this.cells = this.table.columnManager.generateCells(this);
  3295. };
  3296. //functions to setup on first render
  3297. Row.prototype.initialize = function (force) {
  3298. var self = this;
  3299. if (!self.initialized || force) {
  3300. self.deleteCells();
  3301. while (self.element.firstChild) {
  3302. self.element.removeChild(self.element.firstChild);
  3303. } //handle frozen cells
  3304. if (this.table.modExists("frozenColumns")) {
  3305. this.table.modules.frozenColumns.layoutRow(this);
  3306. }
  3307. this.generateCells();
  3308. self.cells.forEach(function (cell) {
  3309. self.element.appendChild(cell.getElement());
  3310. cell.cellRendered();
  3311. });
  3312. if (force) {
  3313. self.normalizeHeight();
  3314. }
  3315. //setup movable rows
  3316. if (self.table.options.dataTree && self.table.modExists("dataTree")) {
  3317. self.table.modules.dataTree.layoutRow(this);
  3318. }
  3319. //setup column colapse container
  3320. if (self.table.options.responsiveLayout === "collapse" && self.table.modExists("responsiveLayout")) {
  3321. self.table.modules.responsiveLayout.layoutRow(this);
  3322. }
  3323. if (self.table.options.rowFormatter) {
  3324. self.table.options.rowFormatter(self.getComponent());
  3325. }
  3326. //set resizable handles
  3327. if (self.table.options.resizableRows && self.table.modExists("resizeRows")) {
  3328. self.table.modules.resizeRows.initializeRow(self);
  3329. }
  3330. self.initialized = true;
  3331. }
  3332. };
  3333. Row.prototype.reinitializeHeight = function () {
  3334. this.heightInitialized = false;
  3335. if (this.element.offsetParent !== null) {
  3336. this.normalizeHeight(true);
  3337. }
  3338. };
  3339. Row.prototype.reinitialize = function () {
  3340. this.initialized = false;
  3341. this.heightInitialized = false;
  3342. if (!this.manualHeight) {
  3343. this.height = 0;
  3344. this.heightStyled = "";
  3345. }
  3346. if (this.element.offsetParent !== null) {
  3347. this.initialize(true);
  3348. }
  3349. };
  3350. //get heights when doing bulk row style calcs in virtual DOM
  3351. Row.prototype.calcHeight = function (force) {
  3352. var maxHeight = 0,
  3353. minHeight = this.table.options.resizableRows ? this.element.clientHeight : 0;
  3354. this.cells.forEach(function (cell) {
  3355. var height = cell.getHeight();
  3356. if (height > maxHeight) {
  3357. maxHeight = height;
  3358. }
  3359. });
  3360. if (force) {
  3361. this.height = Math.max(maxHeight, minHeight);
  3362. } else {
  3363. this.height = this.manualHeight ? this.height : Math.max(maxHeight, minHeight);
  3364. }
  3365. this.heightStyled = this.height ? this.height + "px" : "";
  3366. this.outerHeight = this.element.offsetHeight;
  3367. };
  3368. //set of cells
  3369. Row.prototype.setCellHeight = function () {
  3370. this.cells.forEach(function (cell) {
  3371. cell.setHeight();
  3372. });
  3373. this.heightInitialized = true;
  3374. };
  3375. Row.prototype.clearCellHeight = function () {
  3376. this.cells.forEach(function (cell) {
  3377. cell.clearHeight();
  3378. });
  3379. };
  3380. //normalize the height of elements in the row
  3381. Row.prototype.normalizeHeight = function (force) {
  3382. if (force) {
  3383. this.clearCellHeight();
  3384. }
  3385. this.calcHeight(force);
  3386. this.setCellHeight();
  3387. };
  3388. // Row.prototype.setHeight = function(height){
  3389. // this.height = height;
  3390. // this.setCellHeight();
  3391. // };
  3392. //set height of rows
  3393. Row.prototype.setHeight = function (height, force) {
  3394. if (this.height != height || force) {
  3395. this.manualHeight = true;
  3396. this.height = height;
  3397. this.heightStyled = height ? height + "px" : "";
  3398. this.setCellHeight();
  3399. // this.outerHeight = this.element.outerHeight();
  3400. this.outerHeight = this.element.offsetHeight;
  3401. }
  3402. };
  3403. //return rows outer height
  3404. Row.prototype.getHeight = function () {
  3405. return this.outerHeight;
  3406. };
  3407. //return rows outer Width
  3408. Row.prototype.getWidth = function () {
  3409. return this.element.offsetWidth;
  3410. };
  3411. //////////////// Cell Management /////////////////
  3412. Row.prototype.deleteCell = function (cell) {
  3413. var index = this.cells.indexOf(cell);
  3414. if (index > -1) {
  3415. this.cells.splice(index, 1);
  3416. }
  3417. };
  3418. //////////////// Data Management /////////////////
  3419. Row.prototype.setData = function (data) {
  3420. if (this.table.modExists("mutator")) {
  3421. data = this.table.modules.mutator.transformRow(data, "data");
  3422. }
  3423. this.data = data;
  3424. if (this.table.options.reactiveData && this.table.modExists("reactiveData", true)) {
  3425. this.table.modules.reactiveData.watchRow(this);
  3426. }
  3427. };
  3428. //update the rows data
  3429. Row.prototype.updateData = function (updatedData) {
  3430. var _this15 = this;
  3431. var visible = Tabulator.prototype.helpers.elVisible(this.element),
  3432. tempData = {},
  3433. newRowData;
  3434. return new Promise(function (resolve, reject) {
  3435. if (typeof updatedData === "string") {
  3436. updatedData = JSON.parse(updatedData);
  3437. }
  3438. if (_this15.table.options.reactiveData && _this15.table.modExists("reactiveData", true)) {
  3439. _this15.table.modules.reactiveData.block();
  3440. }
  3441. //mutate incomming data if needed
  3442. if (_this15.table.modExists("mutator")) {
  3443. tempData = Object.assign(tempData, _this15.data);
  3444. tempData = Object.assign(tempData, updatedData);
  3445. newRowData = _this15.table.modules.mutator.transformRow(tempData, "data", updatedData);
  3446. } else {
  3447. newRowData = updatedData;
  3448. }
  3449. //set data
  3450. for (var attrname in newRowData) {
  3451. _this15.data[attrname] = newRowData[attrname];
  3452. }
  3453. if (_this15.table.options.reactiveData && _this15.table.modExists("reactiveData", true)) {
  3454. _this15.table.modules.reactiveData.unblock();
  3455. }
  3456. //update affected cells only
  3457. for (var attrname in updatedData) {
  3458. var columns = _this15.table.columnManager.getColumnsByFieldRoot(attrname);
  3459. columns.forEach(function (column) {
  3460. var cell = _this15.getCell(column.getField());
  3461. if (cell) {
  3462. var value = column.getFieldValue(newRowData);
  3463. if (cell.getValue() != value) {
  3464. cell.setValueProcessData(value);
  3465. if (visible) {
  3466. cell.cellRendered();
  3467. }
  3468. }
  3469. }
  3470. });
  3471. }
  3472. //Partial reinitialization if visible
  3473. if (visible) {
  3474. _this15.normalizeHeight(true);
  3475. if (_this15.table.options.rowFormatter) {
  3476. _this15.table.options.rowFormatter(_this15.getComponent());
  3477. }
  3478. } else {
  3479. _this15.initialized = false;
  3480. _this15.height = 0;
  3481. _this15.heightStyled = "";
  3482. }
  3483. if (_this15.table.options.dataTree !== false && _this15.table.modExists("dataTree") && _this15.table.modules.dataTree.redrawNeeded(updatedData)) {
  3484. _this15.table.modules.dataTree.initializeRow(_this15);
  3485. _this15.table.modules.dataTree.layoutRow(_this15);
  3486. _this15.table.rowManager.refreshActiveData("tree", false, true);
  3487. }
  3488. //this.reinitialize();
  3489. _this15.table.options.rowUpdated.call(_this15.table, _this15.getComponent());
  3490. resolve();
  3491. });
  3492. };
  3493. Row.prototype.getData = function (transform) {
  3494. var self = this;
  3495. if (transform) {
  3496. if (self.table.modExists("accessor")) {
  3497. return self.table.modules.accessor.transformRow(self.data, transform);
  3498. }
  3499. } else {
  3500. return this.data;
  3501. }
  3502. };
  3503. Row.prototype.getCell = function (column) {
  3504. var match = false;
  3505. column = this.table.columnManager.findColumn(column);
  3506. match = this.cells.find(function (cell) {
  3507. return cell.column === column;
  3508. });
  3509. return match;
  3510. };
  3511. Row.prototype.getCellIndex = function (findCell) {
  3512. return this.cells.findIndex(function (cell) {
  3513. return cell === findCell;
  3514. });
  3515. };
  3516. Row.prototype.findNextEditableCell = function (index) {
  3517. var nextCell = false;
  3518. if (index < this.cells.length - 1) {
  3519. for (var i = index + 1; i < this.cells.length; i++) {
  3520. var cell = this.cells[i];
  3521. if (cell.column.modules.edit && Tabulator.prototype.helpers.elVisible(cell.getElement())) {
  3522. var allowEdit = true;
  3523. if (typeof cell.column.modules.edit.check == "function") {
  3524. allowEdit = cell.column.modules.edit.check(cell.getComponent());
  3525. }
  3526. if (allowEdit) {
  3527. nextCell = cell;
  3528. break;
  3529. }
  3530. }
  3531. }
  3532. }
  3533. return nextCell;
  3534. };
  3535. Row.prototype.findPrevEditableCell = function (index) {
  3536. var prevCell = false;
  3537. if (index > 0) {
  3538. for (var i = index - 1; i >= 0; i--) {
  3539. var cell = this.cells[i],
  3540. allowEdit = true;
  3541. if (cell.column.modules.edit && Tabulator.prototype.helpers.elVisible(cell.getElement())) {
  3542. if (typeof cell.column.modules.edit.check == "function") {
  3543. allowEdit = cell.column.modules.edit.check(cell.getComponent());
  3544. }
  3545. if (allowEdit) {
  3546. prevCell = cell;
  3547. break;
  3548. }
  3549. }
  3550. }
  3551. }
  3552. return prevCell;
  3553. };
  3554. Row.prototype.getCells = function () {
  3555. return this.cells;
  3556. };
  3557. Row.prototype.nextRow = function () {
  3558. var row = this.table.rowManager.nextDisplayRow(this, true);
  3559. return row || false;
  3560. };
  3561. Row.prototype.prevRow = function () {
  3562. var row = this.table.rowManager.prevDisplayRow(this, true);
  3563. return row || false;
  3564. };
  3565. Row.prototype.moveToRow = function (to, before) {
  3566. var toRow = this.table.rowManager.findRow(to);
  3567. if (toRow) {
  3568. this.table.rowManager.moveRowActual(this, toRow, !before);
  3569. this.table.rowManager.refreshActiveData("display", false, true);
  3570. } else {
  3571. console.warn("Move Error - No matching row found:", to);
  3572. }
  3573. };
  3574. ///////////////////// Actions /////////////////////
  3575. Row.prototype.delete = function () {
  3576. var _this16 = this;
  3577. return new Promise(function (resolve, reject) {
  3578. var index, rows;
  3579. if (_this16.table.options.history && _this16.table.modExists("history")) {
  3580. if (_this16.table.options.groupBy && _this16.table.modExists("groupRows")) {
  3581. rows = _this16.getGroup().rows;
  3582. index = rows.indexOf(_this16);
  3583. if (index) {
  3584. index = rows[index - 1];
  3585. }
  3586. } else {
  3587. index = _this16.table.rowManager.getRowIndex(_this16);
  3588. if (index) {
  3589. index = _this16.table.rowManager.rows[index - 1];
  3590. }
  3591. }
  3592. _this16.table.modules.history.action("rowDelete", _this16, { data: _this16.getData(), pos: !index, index: index });
  3593. }
  3594. _this16.deleteActual();
  3595. resolve();
  3596. });
  3597. };
  3598. Row.prototype.deleteActual = function (blockRedraw) {
  3599. var index = this.table.rowManager.getRowIndex(this);
  3600. //deselect row if it is selected
  3601. if (this.table.modExists("selectRow")) {
  3602. this.table.modules.selectRow._deselectRow(this, true);
  3603. }
  3604. //cancel edit if row is currently being edited
  3605. if (this.table.modExists("edit")) {
  3606. if (this.table.modules.edit.currentCell.row === this) {
  3607. this.table.modules.edit.cancelEdit();
  3608. }
  3609. }
  3610. // if(this.table.options.dataTree && this.table.modExists("dataTree")){
  3611. // this.table.modules.dataTree.collapseRow(this, true);
  3612. // }
  3613. //remove any reactive data watchers from row object
  3614. if (this.table.options.reactiveData && this.table.modExists("reactiveData", true)) {}
  3615. // this.table.modules.reactiveData.unwatchRow(this);
  3616. //remove from group
  3617. if (this.modules.group) {
  3618. this.modules.group.removeRow(this);
  3619. }
  3620. this.table.rowManager.deleteRow(this, blockRedraw);
  3621. this.deleteCells();
  3622. this.initialized = false;
  3623. this.heightInitialized = false;
  3624. //recalc column calculations if present
  3625. if (this.table.modExists("columnCalcs")) {
  3626. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  3627. this.table.modules.columnCalcs.recalcRowGroup(this);
  3628. } else {
  3629. this.table.modules.columnCalcs.recalc(this.table.rowManager.activeRows);
  3630. }
  3631. }
  3632. };
  3633. Row.prototype.deleteCells = function () {
  3634. var cellCount = this.cells.length;
  3635. for (var i = 0; i < cellCount; i++) {
  3636. this.cells[0].delete();
  3637. }
  3638. };
  3639. Row.prototype.wipe = function () {
  3640. this.deleteCells();
  3641. while (this.element.firstChild) {
  3642. this.element.removeChild(this.element.firstChild);
  3643. }this.element = false;
  3644. this.modules = {};
  3645. if (this.element.parentNode) {
  3646. this.element.parentNode.removeChild(this.element);
  3647. }
  3648. };
  3649. Row.prototype.getGroup = function () {
  3650. return this.modules.group || false;
  3651. };
  3652. //////////////// Object Generation /////////////////
  3653. Row.prototype.getComponent = function () {
  3654. return new RowComponent(this);
  3655. };
  3656. //public row object
  3657. var CellComponent = function CellComponent(cell) {
  3658. this._cell = cell;
  3659. };
  3660. CellComponent.prototype.getValue = function () {
  3661. return this._cell.getValue();
  3662. };
  3663. CellComponent.prototype.getOldValue = function () {
  3664. return this._cell.getOldValue();
  3665. };
  3666. CellComponent.prototype.getElement = function () {
  3667. return this._cell.getElement();
  3668. };
  3669. CellComponent.prototype.getRow = function () {
  3670. return this._cell.row.getComponent();
  3671. };
  3672. CellComponent.prototype.getData = function () {
  3673. return this._cell.row.getData();
  3674. };
  3675. CellComponent.prototype.getField = function () {
  3676. return this._cell.column.getField();
  3677. };
  3678. CellComponent.prototype.getColumn = function () {
  3679. return this._cell.column.getComponent();
  3680. };
  3681. CellComponent.prototype.setValue = function (value, mutate) {
  3682. if (typeof mutate == "undefined") {
  3683. mutate = true;
  3684. }
  3685. this._cell.setValue(value, mutate);
  3686. };
  3687. CellComponent.prototype.restoreOldValue = function () {
  3688. this._cell.setValueActual(this._cell.getOldValue());
  3689. };
  3690. CellComponent.prototype.edit = function (force) {
  3691. return this._cell.edit(force);
  3692. };
  3693. CellComponent.prototype.cancelEdit = function () {
  3694. this._cell.cancelEdit();
  3695. };
  3696. CellComponent.prototype.nav = function () {
  3697. return this._cell.nav();
  3698. };
  3699. CellComponent.prototype.checkHeight = function () {
  3700. this._cell.checkHeight();
  3701. };
  3702. CellComponent.prototype.getTable = function () {
  3703. return this._cell.table;
  3704. };
  3705. CellComponent.prototype._getSelf = function () {
  3706. return this._cell;
  3707. };
  3708. var Cell = function Cell(column, row) {
  3709. this.table = column.table;
  3710. this.column = column;
  3711. this.row = row;
  3712. this.element = null;
  3713. this.value = null;
  3714. this.oldValue = null;
  3715. this.modules = {};
  3716. this.height = null;
  3717. this.width = null;
  3718. this.minWidth = null;
  3719. this.build();
  3720. };
  3721. //////////////// Setup Functions /////////////////
  3722. //generate element
  3723. Cell.prototype.build = function () {
  3724. this.generateElement();
  3725. this.setWidth();
  3726. this._configureCell();
  3727. this.setValueActual(this.column.getFieldValue(this.row.data));
  3728. };
  3729. Cell.prototype.generateElement = function () {
  3730. this.element = document.createElement('div');
  3731. this.element.className = "tabulator-cell";
  3732. this.element.setAttribute("role", "gridcell");
  3733. this.element = this.element;
  3734. };
  3735. Cell.prototype._configureCell = function () {
  3736. var self = this,
  3737. cellEvents = self.column.cellEvents,
  3738. element = self.element,
  3739. field = this.column.getField(),
  3740. vertAligns = {
  3741. top: "flex-start",
  3742. bottom: "flex-end",
  3743. middle: "center"
  3744. },
  3745. hozAligns = {
  3746. left: "flex-start",
  3747. right: "flex-end",
  3748. center: "center"
  3749. };
  3750. //set text alignment
  3751. element.style.textAlign = self.column.hozAlign;
  3752. if (self.column.vertAlign) {
  3753. element.style.display = "inline-flex";
  3754. element.style.alignItems = vertAligns[self.column.vertAlign] || "";
  3755. if (self.column.hozAlign) {
  3756. element.style.justifyContent = hozAligns[self.column.hozAlign] || "";
  3757. }
  3758. }
  3759. if (field) {
  3760. element.setAttribute("tabulator-field", field);
  3761. }
  3762. //add class to cell if needed
  3763. if (self.column.definition.cssClass) {
  3764. var classNames = self.column.definition.cssClass.split(" ");
  3765. classNames.forEach(function (className) {
  3766. element.classList.add(className);
  3767. });
  3768. }
  3769. //update tooltip on mouse enter
  3770. if (this.table.options.tooltipGenerationMode === "hover") {
  3771. element.addEventListener("mouseenter", function (e) {
  3772. self._generateTooltip();
  3773. });
  3774. }
  3775. self._bindClickEvents(cellEvents);
  3776. self._bindTouchEvents(cellEvents);
  3777. self._bindMouseEvents(cellEvents);
  3778. if (self.column.modules.edit) {
  3779. self.table.modules.edit.bindEditor(self);
  3780. }
  3781. if (self.column.definition.rowHandle && self.table.options.movableRows !== false && self.table.modExists("moveRow")) {
  3782. self.table.modules.moveRow.initializeCell(self);
  3783. }
  3784. //hide cell if not visible
  3785. if (!self.column.visible) {
  3786. self.hide();
  3787. }
  3788. };
  3789. Cell.prototype._bindClickEvents = function (cellEvents) {
  3790. var self = this,
  3791. element = self.element;
  3792. //set event bindings
  3793. if (cellEvents.cellClick || self.table.options.cellClick) {
  3794. element.addEventListener("click", function (e) {
  3795. var component = self.getComponent();
  3796. if (cellEvents.cellClick) {
  3797. cellEvents.cellClick.call(self.table, e, component);
  3798. }
  3799. if (self.table.options.cellClick) {
  3800. self.table.options.cellClick.call(self.table, e, component);
  3801. }
  3802. });
  3803. }
  3804. if (cellEvents.cellDblClick || this.table.options.cellDblClick) {
  3805. element.addEventListener("dblclick", function (e) {
  3806. var component = self.getComponent();
  3807. if (cellEvents.cellDblClick) {
  3808. cellEvents.cellDblClick.call(self.table, e, component);
  3809. }
  3810. if (self.table.options.cellDblClick) {
  3811. self.table.options.cellDblClick.call(self.table, e, component);
  3812. }
  3813. });
  3814. } else {
  3815. element.addEventListener("dblclick", function (e) {
  3816. if (self.table.modExists("edit")) {
  3817. if (self.table.modules.edit.currentCell === self) {
  3818. return; //prevent instant selection of editor content
  3819. }
  3820. }
  3821. e.preventDefault();
  3822. try {
  3823. if (document.selection) {
  3824. // IE
  3825. var range = document.body.createTextRange();
  3826. range.moveToElementText(self.element);
  3827. range.select();
  3828. } else if (window.getSelection) {
  3829. var range = document.createRange();
  3830. range.selectNode(self.element);
  3831. window.getSelection().removeAllRanges();
  3832. window.getSelection().addRange(range);
  3833. }
  3834. } catch (e) {}
  3835. });
  3836. }
  3837. if (cellEvents.cellContext || this.table.options.cellContext) {
  3838. element.addEventListener("contextmenu", function (e) {
  3839. var component = self.getComponent();
  3840. if (cellEvents.cellContext) {
  3841. cellEvents.cellContext.call(self.table, e, component);
  3842. }
  3843. if (self.table.options.cellContext) {
  3844. self.table.options.cellContext.call(self.table, e, component);
  3845. }
  3846. });
  3847. }
  3848. };
  3849. Cell.prototype._bindMouseEvents = function (cellEvents) {
  3850. var self = this,
  3851. element = self.element;
  3852. if (cellEvents.cellMouseEnter || self.table.options.cellMouseEnter) {
  3853. element.addEventListener("mouseenter", function (e) {
  3854. var component = self.getComponent();
  3855. if (cellEvents.cellMouseEnter) {
  3856. cellEvents.cellMouseEnter.call(self.table, e, component);
  3857. }
  3858. if (self.table.options.cellMouseEnter) {
  3859. self.table.options.cellMouseEnter.call(self.table, e, component);
  3860. }
  3861. });
  3862. }
  3863. if (cellEvents.cellMouseLeave || self.table.options.cellMouseLeave) {
  3864. element.addEventListener("mouseleave", function (e) {
  3865. var component = self.getComponent();
  3866. if (cellEvents.cellMouseLeave) {
  3867. cellEvents.cellMouseLeave.call(self.table, e, component);
  3868. }
  3869. if (self.table.options.cellMouseLeave) {
  3870. self.table.options.cellMouseLeave.call(self.table, e, component);
  3871. }
  3872. });
  3873. }
  3874. if (cellEvents.cellMouseOver || self.table.options.cellMouseOver) {
  3875. element.addEventListener("mouseover", function (e) {
  3876. var component = self.getComponent();
  3877. if (cellEvents.cellMouseOver) {
  3878. cellEvents.cellMouseOver.call(self.table, e, component);
  3879. }
  3880. if (self.table.options.cellMouseOver) {
  3881. self.table.options.cellMouseOver.call(self.table, e, component);
  3882. }
  3883. });
  3884. }
  3885. if (cellEvents.cellMouseOut || self.table.options.cellMouseOut) {
  3886. element.addEventListener("mouseout", function (e) {
  3887. var component = self.getComponent();
  3888. if (cellEvents.cellMouseOut) {
  3889. cellEvents.cellMouseOut.call(self.table, e, component);
  3890. }
  3891. if (self.table.options.cellMouseOut) {
  3892. self.table.options.cellMouseOut.call(self.table, e, component);
  3893. }
  3894. });
  3895. }
  3896. if (cellEvents.cellMouseMove || self.table.options.cellMouseMove) {
  3897. element.addEventListener("mousemove", function (e) {
  3898. var component = self.getComponent();
  3899. if (cellEvents.cellMouseMove) {
  3900. cellEvents.cellMouseMove.call(self.table, e, component);
  3901. }
  3902. if (self.table.options.cellMouseMove) {
  3903. self.table.options.cellMouseMove.call(self.table, e, component);
  3904. }
  3905. });
  3906. }
  3907. };
  3908. Cell.prototype._bindTouchEvents = function (cellEvents) {
  3909. var self = this,
  3910. element = self.element,
  3911. dblTap,
  3912. tapHold,
  3913. tap;
  3914. if (cellEvents.cellTap || this.table.options.cellTap) {
  3915. tap = false;
  3916. element.addEventListener("touchstart", function (e) {
  3917. tap = true;
  3918. }, { passive: true });
  3919. element.addEventListener("touchend", function (e) {
  3920. if (tap) {
  3921. var component = self.getComponent();
  3922. if (cellEvents.cellTap) {
  3923. cellEvents.cellTap.call(self.table, e, component);
  3924. }
  3925. if (self.table.options.cellTap) {
  3926. self.table.options.cellTap.call(self.table, e, component);
  3927. }
  3928. }
  3929. tap = false;
  3930. });
  3931. }
  3932. if (cellEvents.cellDblTap || this.table.options.cellDblTap) {
  3933. dblTap = null;
  3934. element.addEventListener("touchend", function (e) {
  3935. if (dblTap) {
  3936. clearTimeout(dblTap);
  3937. dblTap = null;
  3938. var component = self.getComponent();
  3939. if (cellEvents.cellDblTap) {
  3940. cellEvents.cellDblTap.call(self.table, e, component);
  3941. }
  3942. if (self.table.options.cellDblTap) {
  3943. self.table.options.cellDblTap.call(self.table, e, component);
  3944. }
  3945. } else {
  3946. dblTap = setTimeout(function () {
  3947. clearTimeout(dblTap);
  3948. dblTap = null;
  3949. }, 300);
  3950. }
  3951. });
  3952. }
  3953. if (cellEvents.cellTapHold || this.table.options.cellTapHold) {
  3954. tapHold = null;
  3955. element.addEventListener("touchstart", function (e) {
  3956. clearTimeout(tapHold);
  3957. tapHold = setTimeout(function () {
  3958. clearTimeout(tapHold);
  3959. tapHold = null;
  3960. tap = false;
  3961. var component = self.getComponent();
  3962. if (cellEvents.cellTapHold) {
  3963. cellEvents.cellTapHold.call(self.table, e, component);
  3964. }
  3965. if (self.table.options.cellTapHold) {
  3966. self.table.options.cellTapHold.call(self.table, e, component);
  3967. }
  3968. }, 1000);
  3969. }, { passive: true });
  3970. element.addEventListener("touchend", function (e) {
  3971. clearTimeout(tapHold);
  3972. tapHold = null;
  3973. });
  3974. }
  3975. };
  3976. //generate cell contents
  3977. Cell.prototype._generateContents = function () {
  3978. var val;
  3979. if (this.table.modExists("format")) {
  3980. val = this.table.modules.format.formatValue(this);
  3981. } else {
  3982. val = this.element.innerHTML = this.value;
  3983. }
  3984. switch (typeof val === 'undefined' ? 'undefined' : _typeof(val)) {
  3985. case "object":
  3986. if (val instanceof Node) {
  3987. //clear previous cell contents
  3988. while (this.element.firstChild) {
  3989. this.element.removeChild(this.element.firstChild);
  3990. }this.element.appendChild(val);
  3991. } else {
  3992. this.element.innerHTML = "";
  3993. if (val != null) {
  3994. console.warn("Format Error - Formatter has returned a type of object, the only valid formatter object return is an instance of Node, the formatter returned:", val);
  3995. }
  3996. }
  3997. break;
  3998. case "undefined":
  3999. case "null":
  4000. this.element.innerHTML = "";
  4001. break;
  4002. default:
  4003. this.element.innerHTML = val;
  4004. }
  4005. };
  4006. Cell.prototype.cellRendered = function () {
  4007. if (this.table.modExists("format") && this.table.modules.format.cellRendered) {
  4008. this.table.modules.format.cellRendered(this);
  4009. }
  4010. };
  4011. //generate tooltip text
  4012. Cell.prototype._generateTooltip = function () {
  4013. var tooltip = this.column.tooltip;
  4014. if (tooltip) {
  4015. if (tooltip === true) {
  4016. tooltip = this.value;
  4017. } else if (typeof tooltip == "function") {
  4018. tooltip = tooltip(this.getComponent());
  4019. if (tooltip === false) {
  4020. tooltip = "";
  4021. }
  4022. }
  4023. if (typeof tooltip === "undefined") {
  4024. tooltip = "";
  4025. }
  4026. this.element.setAttribute("title", tooltip);
  4027. } else {
  4028. this.element.setAttribute("title", "");
  4029. }
  4030. };
  4031. //////////////////// Getters ////////////////////
  4032. Cell.prototype.getElement = function () {
  4033. return this.element;
  4034. };
  4035. Cell.prototype.getValue = function () {
  4036. return this.value;
  4037. };
  4038. Cell.prototype.getOldValue = function () {
  4039. return this.oldValue;
  4040. };
  4041. //////////////////// Actions ////////////////////
  4042. Cell.prototype.setValue = function (value, mutate) {
  4043. var changed = this.setValueProcessData(value, mutate),
  4044. component;
  4045. if (changed) {
  4046. if (this.table.options.history && this.table.modExists("history")) {
  4047. this.table.modules.history.action("cellEdit", this, { oldValue: this.oldValue, newValue: this.value });
  4048. }
  4049. component = this.getComponent();
  4050. if (this.column.cellEvents.cellEdited) {
  4051. this.column.cellEvents.cellEdited.call(this.table, component);
  4052. }
  4053. this.cellRendered();
  4054. this.table.options.cellEdited.call(this.table, component);
  4055. this.table.options.dataEdited.call(this.table, this.table.rowManager.getData());
  4056. }
  4057. };
  4058. Cell.prototype.setValueProcessData = function (value, mutate) {
  4059. var changed = false;
  4060. if (this.value != value) {
  4061. changed = true;
  4062. if (mutate) {
  4063. if (this.column.modules.mutate) {
  4064. value = this.table.modules.mutator.transformCell(this, value);
  4065. }
  4066. }
  4067. }
  4068. this.setValueActual(value);
  4069. if (changed && this.table.modExists("columnCalcs")) {
  4070. if (this.column.definition.topCalc || this.column.definition.bottomCalc) {
  4071. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  4072. if (this.table.options.columnCalcs == "table" || this.table.options.columnCalcs == "both") {
  4073. this.table.modules.columnCalcs.recalc(this.table.rowManager.activeRows);
  4074. }
  4075. if (this.table.options.columnCalcs != "table") {
  4076. this.table.modules.columnCalcs.recalcRowGroup(this.row);
  4077. }
  4078. } else {
  4079. this.table.modules.columnCalcs.recalc(this.table.rowManager.activeRows);
  4080. }
  4081. }
  4082. }
  4083. return changed;
  4084. };
  4085. Cell.prototype.setValueActual = function (value) {
  4086. this.oldValue = this.value;
  4087. this.value = value;
  4088. if (this.table.options.reactiveData && this.table.modExists("reactiveData")) {
  4089. this.table.modules.reactiveData.block();
  4090. }
  4091. this.column.setFieldValue(this.row.data, value);
  4092. if (this.table.options.reactiveData && this.table.modExists("reactiveData")) {
  4093. this.table.modules.reactiveData.unblock();
  4094. }
  4095. this._generateContents();
  4096. this._generateTooltip();
  4097. //set resizable handles
  4098. if (this.table.options.resizableColumns && this.table.modExists("resizeColumns")) {
  4099. this.table.modules.resizeColumns.initializeColumn("cell", this.column, this.element);
  4100. }
  4101. //set column menu
  4102. if (this.column.definition.contextMenu && this.table.modExists("menu")) {
  4103. this.table.modules.menu.initializeCell(this);
  4104. }
  4105. //handle frozen cells
  4106. if (this.table.modExists("frozenColumns")) {
  4107. this.table.modules.frozenColumns.layoutElement(this.element, this.column);
  4108. }
  4109. };
  4110. Cell.prototype.setWidth = function () {
  4111. this.width = this.column.width;
  4112. this.element.style.width = this.column.widthStyled;
  4113. };
  4114. Cell.prototype.clearWidth = function () {
  4115. this.width = "";
  4116. this.element.style.width = "";
  4117. };
  4118. Cell.prototype.getWidth = function () {
  4119. return this.width || this.element.offsetWidth;
  4120. };
  4121. Cell.prototype.setMinWidth = function () {
  4122. this.minWidth = this.column.minWidth;
  4123. this.element.style.minWidth = this.column.minWidthStyled;
  4124. };
  4125. Cell.prototype.checkHeight = function () {
  4126. // var height = this.element.css("height");
  4127. this.row.reinitializeHeight();
  4128. };
  4129. Cell.prototype.clearHeight = function () {
  4130. this.element.style.height = "";
  4131. this.height = null;
  4132. };
  4133. Cell.prototype.setHeight = function () {
  4134. this.height = this.row.height;
  4135. this.element.style.height = this.row.heightStyled;
  4136. };
  4137. Cell.prototype.getHeight = function () {
  4138. return this.height || this.element.offsetHeight;
  4139. };
  4140. Cell.prototype.show = function () {
  4141. this.element.style.display = "";
  4142. };
  4143. Cell.prototype.hide = function () {
  4144. this.element.style.display = "none";
  4145. };
  4146. Cell.prototype.edit = function (force) {
  4147. if (this.table.modExists("edit", true)) {
  4148. return this.table.modules.edit.editCell(this, force);
  4149. }
  4150. };
  4151. Cell.prototype.cancelEdit = function () {
  4152. if (this.table.modExists("edit", true)) {
  4153. var editing = this.table.modules.edit.getCurrentCell();
  4154. if (editing && editing._getSelf() === this) {
  4155. this.table.modules.edit.cancelEdit();
  4156. } else {
  4157. console.warn("Cancel Editor Error - This cell is not currently being edited ");
  4158. }
  4159. }
  4160. };
  4161. Cell.prototype.delete = function () {
  4162. if (!this.table.rowManager.redrawBlock) {
  4163. this.element.parentNode.removeChild(this.element);
  4164. }
  4165. this.element = false;
  4166. this.column.deleteCell(this);
  4167. this.row.deleteCell(this);
  4168. this.calcs = {};
  4169. };
  4170. //////////////// Navigation /////////////////
  4171. Cell.prototype.nav = function () {
  4172. var self = this,
  4173. nextCell = false,
  4174. index = this.row.getCellIndex(this);
  4175. return {
  4176. next: function next() {
  4177. var nextCell = this.right(),
  4178. nextRow;
  4179. if (!nextCell) {
  4180. nextRow = self.table.rowManager.nextDisplayRow(self.row, true);
  4181. if (nextRow) {
  4182. nextCell = nextRow.findNextEditableCell(-1);
  4183. if (nextCell) {
  4184. nextCell.edit();
  4185. return true;
  4186. }
  4187. }
  4188. } else {
  4189. return true;
  4190. }
  4191. return false;
  4192. },
  4193. prev: function prev() {
  4194. var nextCell = this.left(),
  4195. prevRow;
  4196. if (!nextCell) {
  4197. prevRow = self.table.rowManager.prevDisplayRow(self.row, true);
  4198. if (prevRow) {
  4199. nextCell = prevRow.findPrevEditableCell(prevRow.cells.length);
  4200. if (nextCell) {
  4201. nextCell.edit();
  4202. return true;
  4203. }
  4204. }
  4205. } else {
  4206. return true;
  4207. }
  4208. return false;
  4209. },
  4210. left: function left() {
  4211. nextCell = self.row.findPrevEditableCell(index);
  4212. if (nextCell) {
  4213. nextCell.edit();
  4214. return true;
  4215. } else {
  4216. return false;
  4217. }
  4218. },
  4219. right: function right() {
  4220. nextCell = self.row.findNextEditableCell(index);
  4221. if (nextCell) {
  4222. nextCell.edit();
  4223. return true;
  4224. } else {
  4225. return false;
  4226. }
  4227. },
  4228. up: function up() {
  4229. var nextRow = self.table.rowManager.prevDisplayRow(self.row, true);
  4230. if (nextRow) {
  4231. nextRow.cells[index].edit();
  4232. }
  4233. },
  4234. down: function down() {
  4235. var nextRow = self.table.rowManager.nextDisplayRow(self.row, true);
  4236. if (nextRow) {
  4237. nextRow.cells[index].edit();
  4238. }
  4239. }
  4240. };
  4241. };
  4242. Cell.prototype.getIndex = function () {
  4243. this.row.getCellIndex(this);
  4244. };
  4245. //////////////// Object Generation /////////////////
  4246. Cell.prototype.getComponent = function () {
  4247. return new CellComponent(this);
  4248. };
  4249. var FooterManager = function FooterManager(table) {
  4250. this.table = table;
  4251. this.active = false;
  4252. this.element = this.createElement(); //containing element
  4253. this.external = false;
  4254. this.links = [];
  4255. this._initialize();
  4256. };
  4257. FooterManager.prototype.createElement = function () {
  4258. var el = document.createElement("div");
  4259. el.classList.add("tabulator-footer");
  4260. return el;
  4261. };
  4262. FooterManager.prototype._initialize = function (element) {
  4263. if (this.table.options.footerElement) {
  4264. switch (_typeof(this.table.options.footerElement)) {
  4265. case "string":
  4266. if (this.table.options.footerElement[0] === "<") {
  4267. this.element.innerHTML = this.table.options.footerElement;
  4268. } else {
  4269. this.external = true;
  4270. this.element = document.querySelector(this.table.options.footerElement);
  4271. }
  4272. break;
  4273. default:
  4274. this.element = this.table.options.footerElement;
  4275. break;
  4276. }
  4277. }
  4278. };
  4279. FooterManager.prototype.getElement = function () {
  4280. return this.element;
  4281. };
  4282. FooterManager.prototype.append = function (element, parent) {
  4283. this.activate(parent);
  4284. this.element.appendChild(element);
  4285. this.table.rowManager.adjustTableSize();
  4286. };
  4287. FooterManager.prototype.prepend = function (element, parent) {
  4288. this.activate(parent);
  4289. this.element.insertBefore(element, this.element.firstChild);
  4290. this.table.rowManager.adjustTableSize();
  4291. };
  4292. FooterManager.prototype.remove = function (element) {
  4293. element.parentNode.removeChild(element);
  4294. this.deactivate();
  4295. };
  4296. FooterManager.prototype.deactivate = function (force) {
  4297. if (!this.element.firstChild || force) {
  4298. if (!this.external) {
  4299. this.element.parentNode.removeChild(this.element);
  4300. }
  4301. this.active = false;
  4302. }
  4303. // this.table.rowManager.adjustTableSize();
  4304. };
  4305. FooterManager.prototype.activate = function (parent) {
  4306. if (!this.active) {
  4307. this.active = true;
  4308. if (!this.external) {
  4309. this.table.element.appendChild(this.getElement());
  4310. this.table.element.style.display = '';
  4311. }
  4312. }
  4313. if (parent) {
  4314. this.links.push(parent);
  4315. }
  4316. };
  4317. FooterManager.prototype.redraw = function () {
  4318. this.links.forEach(function (link) {
  4319. link.footerRedraw();
  4320. });
  4321. };
  4322. var Tabulator = function Tabulator(element, options) {
  4323. this.options = {};
  4324. this.columnManager = null; // hold Column Manager
  4325. this.rowManager = null; //hold Row Manager
  4326. this.footerManager = null; //holder Footer Manager
  4327. this.browser = ""; //hold current browser type
  4328. this.browserSlow = false; //handle reduced functionality for slower browsers
  4329. this.browserMobile = false; //check if running on moble, prevent resize cancelling edit on keyboard appearence
  4330. this.modules = {}; //hold all modules bound to this table
  4331. this.initializeElement(element);
  4332. this.initializeOptions(options || {});
  4333. this._create();
  4334. Tabulator.prototype.comms.register(this); //register table for inderdevice communication
  4335. };
  4336. //default setup options
  4337. Tabulator.prototype.defaultOptions = {
  4338. height: false, //height of tabulator
  4339. minHeight: false, //minimum height of tabulator
  4340. maxHeight: false, //maximum height of tabulator
  4341. layout: "fitData", ///layout type "fitColumns" | "fitData"
  4342. layoutColumnsOnNewData: false, //update column widths on setData
  4343. columnMinWidth: 40, //minimum global width for a column
  4344. columnHeaderVertAlign: "top", //vertical alignment of column headers
  4345. columnVertAlign: false, // DEPRECATED - Left to allow warning
  4346. resizableColumns: true, //resizable columns
  4347. resizableRows: false, //resizable rows
  4348. autoResize: true, //auto resize table
  4349. columns: [], //store for colum header info
  4350. cellHozAlign: "", //horizontal align columns
  4351. cellVertAlign: "", //certical align columns
  4352. data: [], //default starting data
  4353. autoColumns: false, //build columns from data row structure
  4354. reactiveData: false, //enable data reactivity
  4355. nestedFieldSeparator: ".", //seperatpr for nested data
  4356. tooltips: false, //Tool tip value
  4357. tooltipsHeader: false, //Tool tip for headers
  4358. tooltipGenerationMode: "load", //when to generate tooltips
  4359. initialSort: false, //initial sorting criteria
  4360. initialFilter: false, //initial filtering criteria
  4361. initialHeaderFilter: false, //initial header filtering criteria
  4362. columnHeaderSortMulti: true, //multiple or single column sorting
  4363. sortOrderReverse: false, //reverse internal sort ordering
  4364. headerSort: true, //set default global header sort
  4365. headerSortTristate: false, //set default tristate header sorting
  4366. footerElement: false, //hold footer element
  4367. index: "id", //filed for row index
  4368. keybindings: [], //array for keybindings
  4369. tabEndNewRow: false, //create new row when tab to end of table
  4370. invalidOptionWarnings: true, //allow toggling of invalid option warnings
  4371. clipboard: false, //enable clipboard
  4372. clipboardCopyStyled: true, //formatted table data
  4373. clipboardCopyConfig: false, //clipboard config
  4374. clipboardCopyFormatter: false, //DEPRICATED - REMOVE in 5.0
  4375. clipboardCopyRowRange: "active", //restrict clipboard to visible rows only
  4376. clipboardPasteParser: "table", //convert pasted clipboard data to rows
  4377. clipboardPasteAction: "insert", //how to insert pasted data into the table
  4378. clipboardCopied: function clipboardCopied() {}, //data has been copied to the clipboard
  4379. clipboardPasted: function clipboardPasted() {}, //data has been pasted into the table
  4380. clipboardPasteError: function clipboardPasteError() {}, //data has not successfully been pasted into the table
  4381. downloadDataFormatter: false, //function to manipulate table data before it is downloaded
  4382. downloadReady: function downloadReady(data, blob) {
  4383. return blob;
  4384. }, //function to manipulate download data
  4385. downloadComplete: false, //function to manipulate download data
  4386. downloadConfig: false, //download config
  4387. dataTree: false, //enable data tree
  4388. dataTreeElementColumn: false,
  4389. dataTreeBranchElement: true, //show data tree branch element
  4390. dataTreeChildIndent: 9, //data tree child indent in px
  4391. dataTreeChildField: "_children", //data tre column field to look for child rows
  4392. dataTreeCollapseElement: false, //data tree row collapse element
  4393. dataTreeExpandElement: false, //data tree row expand element
  4394. dataTreeStartExpanded: false,
  4395. dataTreeRowExpanded: function dataTreeRowExpanded() {}, //row has been expanded
  4396. dataTreeRowCollapsed: function dataTreeRowCollapsed() {}, //row has been collapsed
  4397. dataTreeChildColumnCalcs: false, //include visible data tree rows in column calculations
  4398. dataTreeSelectPropagate: false, //seleccting a parent row selects its children
  4399. printAsHtml: false, //enable print as html
  4400. printFormatter: false, //printing page formatter
  4401. printHeader: false, //page header contents
  4402. printFooter: false, //page footer contents
  4403. printCopyStyle: true, //DEPRICATED - REMOVE in 5.0
  4404. printStyled: true, //enable print as html styling
  4405. printVisibleRows: true, //DEPRICATED - REMOVE in 5.0
  4406. printRowRange: "visible", //restrict print to visible rows only
  4407. printConfig: {}, //print config options
  4408. addRowPos: "bottom", //position to insert blank rows, top|bottom
  4409. selectable: "highlight", //highlight rows on hover
  4410. selectableRangeMode: "drag", //highlight rows on hover
  4411. selectableRollingSelection: true, //roll selection once maximum number of selectable rows is reached
  4412. selectablePersistence: true, // maintain selection when table view is updated
  4413. selectableCheck: function selectableCheck(data, row) {
  4414. return true;
  4415. }, //check wheather row is selectable
  4416. headerFilterLiveFilterDelay: 300, //delay before updating column after user types in header filter
  4417. headerFilterPlaceholder: false, //placeholder text to display in header filters
  4418. headerVisible: true, //hide header
  4419. history: false, //enable edit history
  4420. locale: false, //current system language
  4421. langs: {},
  4422. virtualDom: true, //enable DOM virtualization
  4423. virtualDomBuffer: 0, // set virtual DOM buffer size
  4424. persistentLayout: false, //DEPRICATED - REMOVE in 5.0
  4425. persistentSort: false, //DEPRICATED - REMOVE in 5.0
  4426. persistentFilter: false, //DEPRICATED - REMOVE in 5.0
  4427. persistenceID: "", //key for persistent storage
  4428. persistenceMode: true, //mode for storing persistence information
  4429. persistenceReaderFunc: false, //function for handling persistence data reading
  4430. persistenceWriterFunc: false, //function for handling persistence data writing
  4431. persistence: false,
  4432. responsiveLayout: false, //responsive layout flags
  4433. responsiveLayoutCollapseStartOpen: true, //start showing collapsed data
  4434. responsiveLayoutCollapseUseFormatters: true, //responsive layout collapse formatter
  4435. responsiveLayoutCollapseFormatter: false, //responsive layout collapse formatter
  4436. pagination: false, //set pagination type
  4437. paginationSize: false, //set number of rows to a page
  4438. paginationInitialPage: 1, //initail page to show on load
  4439. paginationButtonCount: 5, // set count of page button
  4440. paginationSizeSelector: false, //add pagination size selector element
  4441. paginationElement: false, //element to hold pagination numbers
  4442. paginationDataSent: {}, //pagination data sent to the server
  4443. paginationDataReceived: {}, //pagination data received from the server
  4444. paginationAddRow: "page", //add rows on table or page
  4445. ajaxURL: false, //url for ajax loading
  4446. ajaxURLGenerator: false,
  4447. ajaxParams: {}, //params for ajax loading
  4448. ajaxConfig: "get", //ajax request type
  4449. ajaxContentType: "form", //ajax request type
  4450. ajaxRequestFunc: false, //promise function
  4451. ajaxLoader: true, //show loader
  4452. ajaxLoaderLoading: false, //loader element
  4453. ajaxLoaderError: false, //loader element
  4454. ajaxFiltering: false,
  4455. ajaxSorting: false,
  4456. ajaxProgressiveLoad: false, //progressive loading
  4457. ajaxProgressiveLoadDelay: 0, //delay between requests
  4458. ajaxProgressiveLoadScrollMargin: 0, //margin before scroll begins
  4459. groupBy: false, //enable table grouping and set field to group by
  4460. groupStartOpen: true, //starting state of group
  4461. groupValues: false,
  4462. groupHeader: false, //header generation function
  4463. htmlOutputConfig: false, //html outypu config
  4464. movableColumns: false, //enable movable columns
  4465. movableRows: false, //enable movable rows
  4466. movableRowsConnectedTables: false, //tables for movable rows to be connected to
  4467. movableRowsSender: false,
  4468. movableRowsReceiver: "insert",
  4469. movableRowsSendingStart: function movableRowsSendingStart() {},
  4470. movableRowsSent: function movableRowsSent() {},
  4471. movableRowsSentFailed: function movableRowsSentFailed() {},
  4472. movableRowsSendingStop: function movableRowsSendingStop() {},
  4473. movableRowsReceivingStart: function movableRowsReceivingStart() {},
  4474. movableRowsReceived: function movableRowsReceived() {},
  4475. movableRowsReceivedFailed: function movableRowsReceivedFailed() {},
  4476. movableRowsReceivingStop: function movableRowsReceivingStop() {},
  4477. scrollToRowPosition: "top",
  4478. scrollToRowIfVisible: true,
  4479. scrollToColumnPosition: "left",
  4480. scrollToColumnIfVisible: true,
  4481. rowFormatter: false,
  4482. rowFormatterPrint: null,
  4483. rowFormatterClipboard: null,
  4484. rowFormatterHtmlOutput: null,
  4485. placeholder: false,
  4486. //table building callbacks
  4487. tableBuilding: function tableBuilding() {},
  4488. tableBuilt: function tableBuilt() {},
  4489. //render callbacks
  4490. renderStarted: function renderStarted() {},
  4491. renderComplete: function renderComplete() {},
  4492. //row callbacks
  4493. rowClick: false,
  4494. rowDblClick: false,
  4495. rowContext: false,
  4496. rowTap: false,
  4497. rowDblTap: false,
  4498. rowTapHold: false,
  4499. rowMouseEnter: false,
  4500. rowMouseLeave: false,
  4501. rowMouseOver: false,
  4502. rowMouseOut: false,
  4503. rowMouseMove: false,
  4504. rowContextMenu: false,
  4505. rowAdded: function rowAdded() {},
  4506. rowDeleted: function rowDeleted() {},
  4507. rowMoved: function rowMoved() {},
  4508. rowUpdated: function rowUpdated() {},
  4509. rowSelectionChanged: function rowSelectionChanged() {},
  4510. rowSelected: function rowSelected() {},
  4511. rowDeselected: function rowDeselected() {},
  4512. rowResized: function rowResized() {},
  4513. //cell callbacks
  4514. //row callbacks
  4515. cellClick: false,
  4516. cellDblClick: false,
  4517. cellContext: false,
  4518. cellTap: false,
  4519. cellDblTap: false,
  4520. cellTapHold: false,
  4521. cellMouseEnter: false,
  4522. cellMouseLeave: false,
  4523. cellMouseOver: false,
  4524. cellMouseOut: false,
  4525. cellMouseMove: false,
  4526. cellEditing: function cellEditing() {},
  4527. cellEdited: function cellEdited() {},
  4528. cellEditCancelled: function cellEditCancelled() {},
  4529. //column callbacks
  4530. columnMoved: false,
  4531. columnResized: function columnResized() {},
  4532. columnTitleChanged: function columnTitleChanged() {},
  4533. columnVisibilityChanged: function columnVisibilityChanged() {},
  4534. //HTML iport callbacks
  4535. htmlImporting: function htmlImporting() {},
  4536. htmlImported: function htmlImported() {},
  4537. //data callbacks
  4538. dataLoading: function dataLoading() {},
  4539. dataLoaded: function dataLoaded() {},
  4540. dataEdited: function dataEdited() {},
  4541. //ajax callbacks
  4542. ajaxRequesting: function ajaxRequesting() {},
  4543. ajaxResponse: false,
  4544. ajaxError: function ajaxError() {},
  4545. //filtering callbacks
  4546. dataFiltering: false,
  4547. dataFiltered: false,
  4548. //sorting callbacks
  4549. dataSorting: function dataSorting() {},
  4550. dataSorted: function dataSorted() {},
  4551. //grouping callbacks
  4552. groupToggleElement: "arrow",
  4553. groupClosedShowCalcs: false,
  4554. dataGrouping: function dataGrouping() {},
  4555. dataGrouped: false,
  4556. groupVisibilityChanged: function groupVisibilityChanged() {},
  4557. groupClick: false,
  4558. groupDblClick: false,
  4559. groupContext: false,
  4560. groupTap: false,
  4561. groupDblTap: false,
  4562. groupTapHold: false,
  4563. columnCalcs: true,
  4564. //pagination callbacks
  4565. pageLoaded: function pageLoaded() {},
  4566. //localization callbacks
  4567. localized: function localized() {},
  4568. //validation has failed
  4569. validationFailed: function validationFailed() {},
  4570. //history callbacks
  4571. historyUndo: function historyUndo() {},
  4572. historyRedo: function historyRedo() {},
  4573. //scroll callbacks
  4574. scrollHorizontal: function scrollHorizontal() {},
  4575. scrollVertical: function scrollVertical() {}
  4576. };
  4577. Tabulator.prototype.initializeOptions = function (options) {
  4578. //warn user if option is not available
  4579. if (options.invalidOptionWarnings !== false) {
  4580. for (var key in options) {
  4581. if (typeof this.defaultOptions[key] === "undefined") {
  4582. console.warn("Invalid table constructor option:", key);
  4583. }
  4584. }
  4585. }
  4586. //assign options to table
  4587. for (var key in this.defaultOptions) {
  4588. if (key in options) {
  4589. this.options[key] = options[key];
  4590. } else {
  4591. if (Array.isArray(this.defaultOptions[key])) {
  4592. this.options[key] = [];
  4593. } else if (_typeof(this.defaultOptions[key]) === "object" && this.defaultOptions[key] !== null) {
  4594. this.options[key] = {};
  4595. } else {
  4596. this.options[key] = this.defaultOptions[key];
  4597. }
  4598. }
  4599. }
  4600. };
  4601. Tabulator.prototype.initializeElement = function (element) {
  4602. if (typeof HTMLElement !== "undefined" && element instanceof HTMLElement) {
  4603. this.element = element;
  4604. return true;
  4605. } else if (typeof element === "string") {
  4606. this.element = document.querySelector(element);
  4607. if (this.element) {
  4608. return true;
  4609. } else {
  4610. console.error("Tabulator Creation Error - no element found matching selector: ", element);
  4611. return false;
  4612. }
  4613. } else {
  4614. console.error("Tabulator Creation Error - Invalid element provided:", element);
  4615. return false;
  4616. }
  4617. };
  4618. //convert depricated functionality to new functions
  4619. Tabulator.prototype._mapDepricatedFunctionality = function () {
  4620. //map depricated persistance setup options
  4621. if (this.options.persistentLayout || this.options.persistentSort || this.options.persistentFilter) {
  4622. if (!this.options.persistence) {
  4623. this.options.persistence = {};
  4624. }
  4625. }
  4626. if (typeof this.options.clipboardCopyHeader !== "undefined") {
  4627. this.options.columnHeaders = this.options.clipboardCopyHeader;
  4628. console.warn("DEPRECATION WARNING - clipboardCopyHeader option has been deprecated, please use the columnHeaders property on the clipboardCopyConfig option");
  4629. }
  4630. if (this.options.printVisibleRows !== true) {
  4631. console.warn("printVisibleRows option is deprecated, you should now use the printRowRange option");
  4632. this.options.persistence.printRowRange = "active";
  4633. }
  4634. if (this.options.printCopyStyle !== true) {
  4635. console.warn("printCopyStyle option is deprecated, you should now use the printStyled option");
  4636. this.options.persistence.printStyled = this.options.printCopyStyle;
  4637. }
  4638. if (this.options.persistentLayout) {
  4639. console.warn("persistentLayout option is deprecated, you should now use the persistence option");
  4640. if (this.options.persistence !== true && typeof this.options.persistence.columns === "undefined") {
  4641. this.options.persistence.columns = true;
  4642. }
  4643. }
  4644. if (this.options.persistentSort) {
  4645. console.warn("persistentSort option is deprecated, you should now use the persistence option");
  4646. if (this.options.persistence !== true && typeof this.options.persistence.sort === "undefined") {
  4647. this.options.persistence.sort = true;
  4648. }
  4649. }
  4650. if (this.options.persistentFilter) {
  4651. console.warn("persistentFilter option is deprecated, you should now use the persistence option");
  4652. if (this.options.persistence !== true && typeof this.options.persistence.filter === "undefined") {
  4653. this.options.persistence.filter = true;
  4654. }
  4655. }
  4656. if (this.options.columnVertAlign) {
  4657. console.warn("columnVertAlign option is deprecated, you should now use the columnHeaderVertAlign option");
  4658. this.options.columnHeaderVertAlign = this.options.columnVertAlign;
  4659. }
  4660. };
  4661. Tabulator.prototype._clearSelection = function () {
  4662. this.element.classList.add("tabulator-block-select");
  4663. if (window.getSelection) {
  4664. if (window.getSelection().empty) {
  4665. // Chrome
  4666. window.getSelection().empty();
  4667. } else if (window.getSelection().removeAllRanges) {
  4668. // Firefox
  4669. window.getSelection().removeAllRanges();
  4670. }
  4671. } else if (document.selection) {
  4672. // IE?
  4673. document.selection.empty();
  4674. }
  4675. this.element.classList.remove("tabulator-block-select");
  4676. };
  4677. //concreate table
  4678. Tabulator.prototype._create = function () {
  4679. this._clearObjectPointers();
  4680. this._mapDepricatedFunctionality();
  4681. this.bindModules();
  4682. if (this.element.tagName === "TABLE") {
  4683. if (this.modExists("htmlTableImport", true)) {
  4684. this.modules.htmlTableImport.parseTable();
  4685. }
  4686. }
  4687. this.columnManager = new ColumnManager(this);
  4688. this.rowManager = new RowManager(this);
  4689. this.footerManager = new FooterManager(this);
  4690. this.columnManager.setRowManager(this.rowManager);
  4691. this.rowManager.setColumnManager(this.columnManager);
  4692. this._buildElement();
  4693. this._loadInitialData();
  4694. };
  4695. //clear pointers to objects in default config object
  4696. Tabulator.prototype._clearObjectPointers = function () {
  4697. this.options.columns = this.options.columns.slice(0);
  4698. if (!this.options.reactiveData) {
  4699. this.options.data = this.options.data.slice(0);
  4700. }
  4701. };
  4702. //build tabulator element
  4703. Tabulator.prototype._buildElement = function () {
  4704. var _this17 = this;
  4705. var element = this.element,
  4706. mod = this.modules,
  4707. options = this.options;
  4708. options.tableBuilding.call(this);
  4709. element.classList.add("tabulator");
  4710. element.setAttribute("role", "grid");
  4711. //empty element
  4712. while (element.firstChild) {
  4713. element.removeChild(element.firstChild);
  4714. } //set table height
  4715. if (options.height) {
  4716. options.height = isNaN(options.height) ? options.height : options.height + "px";
  4717. element.style.height = options.height;
  4718. }
  4719. //set table min height
  4720. if (options.minHeight !== false) {
  4721. options.minHeight = isNaN(options.minHeight) ? options.minHeight : options.minHeight + "px";
  4722. element.style.minHeight = options.minHeight;
  4723. }
  4724. //set table maxHeight
  4725. if (options.maxHeight !== false) {
  4726. options.maxHeight = isNaN(options.maxHeight) ? options.maxHeight : options.maxHeight + "px";
  4727. element.style.maxHeight = options.maxHeight;
  4728. }
  4729. this.columnManager.initialize();
  4730. this.rowManager.initialize();
  4731. this._detectBrowser();
  4732. if (this.modExists("layout", true)) {
  4733. mod.layout.initialize(options.layout);
  4734. }
  4735. //set localization
  4736. if (options.headerFilterPlaceholder !== false) {
  4737. mod.localize.setHeaderFilterPlaceholder(options.headerFilterPlaceholder);
  4738. }
  4739. for (var locale in options.langs) {
  4740. mod.localize.installLang(locale, options.langs[locale]);
  4741. }
  4742. mod.localize.setLocale(options.locale);
  4743. //configure placeholder element
  4744. if (typeof options.placeholder == "string") {
  4745. var el = document.createElement("div");
  4746. el.classList.add("tabulator-placeholder");
  4747. var span = document.createElement("span");
  4748. span.innerHTML = options.placeholder;
  4749. el.appendChild(span);
  4750. options.placeholder = el;
  4751. }
  4752. //build table elements
  4753. element.appendChild(this.columnManager.getElement());
  4754. element.appendChild(this.rowManager.getElement());
  4755. if (options.footerElement) {
  4756. this.footerManager.activate();
  4757. }
  4758. if (options.persistence && this.modExists("persistence", true)) {
  4759. mod.persistence.initialize();
  4760. }
  4761. if (options.persistence && this.modExists("persistence", true) && mod.persistence.config.columns) {
  4762. options.columns = mod.persistence.load("columns", options.columns);
  4763. }
  4764. if (options.movableRows && this.modExists("moveRow")) {
  4765. mod.moveRow.initialize();
  4766. }
  4767. if (options.autoColumns && this.options.data) {
  4768. this.columnManager.generateColumnsFromRowData(this.options.data);
  4769. }
  4770. if (this.modExists("columnCalcs")) {
  4771. mod.columnCalcs.initialize();
  4772. }
  4773. this.columnManager.setColumns(options.columns);
  4774. if (options.dataTree && this.modExists("dataTree", true)) {
  4775. mod.dataTree.initialize();
  4776. }
  4777. if (this.modExists("frozenRows")) {
  4778. this.modules.frozenRows.initialize();
  4779. }
  4780. if ((options.persistence && this.modExists("persistence", true) && mod.persistence.config.sort || options.initialSort) && this.modExists("sort", true)) {
  4781. var sorters = [];
  4782. if (options.persistence && this.modExists("persistence", true) && mod.persistence.config.sort) {
  4783. sorters = mod.persistence.load("sort");
  4784. if (sorters === false && options.initialSort) {
  4785. sorters = options.initialSort;
  4786. }
  4787. } else if (options.initialSort) {
  4788. sorters = options.initialSort;
  4789. }
  4790. mod.sort.setSort(sorters);
  4791. }
  4792. if ((options.persistence && this.modExists("persistence", true) && mod.persistence.config.filter || options.initialFilter) && this.modExists("filter", true)) {
  4793. var filters = [];
  4794. if (options.persistence && this.modExists("persistence", true) && mod.persistence.config.filter) {
  4795. filters = mod.persistence.load("filter");
  4796. if (filters === false && options.initialFilter) {
  4797. filters = options.initialFilter;
  4798. }
  4799. } else if (options.initialFilter) {
  4800. filters = options.initialFilter;
  4801. }
  4802. mod.filter.setFilter(filters);
  4803. }
  4804. if (options.initialHeaderFilter && this.modExists("filter", true)) {
  4805. options.initialHeaderFilter.forEach(function (item) {
  4806. var column = _this17.columnManager.findColumn(item.field);
  4807. if (column) {
  4808. mod.filter.setHeaderFilterValue(column, item.value);
  4809. } else {
  4810. console.warn("Column Filter Error - No matching column found:", item.field);
  4811. return false;
  4812. }
  4813. });
  4814. }
  4815. if (this.modExists("ajax")) {
  4816. mod.ajax.initialize();
  4817. }
  4818. if (options.pagination && this.modExists("page", true)) {
  4819. mod.page.initialize();
  4820. }
  4821. if (options.groupBy && this.modExists("groupRows", true)) {
  4822. mod.groupRows.initialize();
  4823. }
  4824. if (this.modExists("keybindings")) {
  4825. mod.keybindings.initialize();
  4826. }
  4827. if (this.modExists("selectRow")) {
  4828. mod.selectRow.clearSelectionData(true);
  4829. }
  4830. if (options.autoResize && this.modExists("resizeTable")) {
  4831. mod.resizeTable.initialize();
  4832. }
  4833. if (this.modExists("clipboard")) {
  4834. mod.clipboard.initialize();
  4835. }
  4836. if (options.printAsHtml && this.modExists("print")) {
  4837. mod.print.initialize();
  4838. }
  4839. options.tableBuilt.call(this);
  4840. };
  4841. Tabulator.prototype._loadInitialData = function () {
  4842. var self = this;
  4843. if (self.options.pagination && self.modExists("page")) {
  4844. self.modules.page.reset(true, true);
  4845. if (self.options.pagination == "local") {
  4846. if (self.options.data.length) {
  4847. self.rowManager.setData(self.options.data, false, true);
  4848. } else {
  4849. if ((self.options.ajaxURL || self.options.ajaxURLGenerator) && self.modExists("ajax")) {
  4850. self.modules.ajax.loadData(false, true).then(function () {}).catch(function () {
  4851. if (self.options.paginationInitialPage) {
  4852. self.modules.page.setPage(self.options.paginationInitialPage);
  4853. }
  4854. });
  4855. return;
  4856. } else {
  4857. self.rowManager.setData(self.options.data, false, true);
  4858. }
  4859. }
  4860. if (self.options.paginationInitialPage) {
  4861. self.modules.page.setPage(self.options.paginationInitialPage);
  4862. }
  4863. } else {
  4864. if (self.options.ajaxURL) {
  4865. self.modules.page.setPage(self.options.paginationInitialPage).then(function () {}).catch(function () {});
  4866. } else {
  4867. self.rowManager.setData([], false, true);
  4868. }
  4869. }
  4870. } else {
  4871. if (self.options.data.length) {
  4872. self.rowManager.setData(self.options.data);
  4873. } else {
  4874. if ((self.options.ajaxURL || self.options.ajaxURLGenerator) && self.modExists("ajax")) {
  4875. self.modules.ajax.loadData(false, true).then(function () {}).catch(function () {});
  4876. } else {
  4877. self.rowManager.setData(self.options.data, false, true);
  4878. }
  4879. }
  4880. }
  4881. };
  4882. //deconstructor
  4883. Tabulator.prototype.destroy = function () {
  4884. var element = this.element;
  4885. Tabulator.prototype.comms.deregister(this); //deregister table from inderdevice communication
  4886. if (this.options.reactiveData && this.modExists("reactiveData", true)) {
  4887. this.modules.reactiveData.unwatchData();
  4888. }
  4889. //clear row data
  4890. this.rowManager.rows.forEach(function (row) {
  4891. row.wipe();
  4892. });
  4893. this.rowManager.rows = [];
  4894. this.rowManager.activeRows = [];
  4895. this.rowManager.displayRows = [];
  4896. //clear event bindings
  4897. if (this.options.autoResize && this.modExists("resizeTable")) {
  4898. this.modules.resizeTable.clearBindings();
  4899. }
  4900. if (this.modExists("keybindings")) {
  4901. this.modules.keybindings.clearBindings();
  4902. }
  4903. //clear DOM
  4904. while (element.firstChild) {
  4905. element.removeChild(element.firstChild);
  4906. }element.classList.remove("tabulator");
  4907. };
  4908. Tabulator.prototype._detectBrowser = function () {
  4909. var ua = navigator.userAgent || navigator.vendor || window.opera;
  4910. if (ua.indexOf("Trident") > -1) {
  4911. this.browser = "ie";
  4912. this.browserSlow = true;
  4913. } else if (ua.indexOf("Edge") > -1) {
  4914. this.browser = "edge";
  4915. this.browserSlow = true;
  4916. } else if (ua.indexOf("Firefox") > -1) {
  4917. this.browser = "firefox";
  4918. this.browserSlow = false;
  4919. } else {
  4920. this.browser = "other";
  4921. this.browserSlow = false;
  4922. }
  4923. this.browserMobile = /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(ua) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(ua.substr(0, 4));
  4924. };
  4925. ////////////////// Data Handling //////////////////
  4926. //block table redrawing
  4927. Tabulator.prototype.blockRedraw = function () {
  4928. return this.rowManager.blockRedraw();
  4929. };
  4930. //restore table redrawing
  4931. Tabulator.prototype.restoreRedraw = function () {
  4932. return this.rowManager.restoreRedraw();
  4933. };
  4934. //local data from local file
  4935. Tabulator.prototype.setDataFromLocalFile = function (extensions) {
  4936. var _this18 = this;
  4937. return new Promise(function (resolve, reject) {
  4938. var input = document.createElement("input");
  4939. input.type = "file";
  4940. input.accept = extensions || ".json,application/json";
  4941. input.addEventListener("change", function (e) {
  4942. var file = input.files[0],
  4943. reader = new FileReader(),
  4944. data;
  4945. reader.readAsText(file);
  4946. reader.onload = function (e) {
  4947. try {
  4948. data = JSON.parse(reader.result);
  4949. } catch (e) {
  4950. console.warn("File Load Error - File contents is invalid JSON", e);
  4951. reject(e);
  4952. return;
  4953. }
  4954. _this18._setData(data).then(function (data) {
  4955. resolve(data);
  4956. }).catch(function (err) {
  4957. resolve(err);
  4958. });
  4959. };
  4960. reader.onerror = function (e) {
  4961. console.warn("File Load Error - Unable to read file");
  4962. reject();
  4963. };
  4964. });
  4965. input.click();
  4966. });
  4967. };
  4968. //load data
  4969. Tabulator.prototype.setData = function (data, params, config) {
  4970. if (this.modExists("ajax")) {
  4971. this.modules.ajax.blockActiveRequest();
  4972. }
  4973. return this._setData(data, params, config, false, true);
  4974. };
  4975. Tabulator.prototype._setData = function (data, params, config, inPosition, columnsChanged) {
  4976. var self = this;
  4977. if (typeof data === "string") {
  4978. if (data.indexOf("{") == 0 || data.indexOf("[") == 0) {
  4979. //data is a json encoded string
  4980. return self.rowManager.setData(JSON.parse(data), inPosition, columnsChanged);
  4981. } else {
  4982. if (self.modExists("ajax", true)) {
  4983. if (params) {
  4984. self.modules.ajax.setParams(params);
  4985. }
  4986. if (config) {
  4987. self.modules.ajax.setConfig(config);
  4988. }
  4989. self.modules.ajax.setUrl(data);
  4990. if (self.options.pagination == "remote" && self.modExists("page", true)) {
  4991. self.modules.page.reset(true, true);
  4992. return self.modules.page.setPage(1);
  4993. } else {
  4994. //assume data is url, make ajax call to url to get data
  4995. return self.modules.ajax.loadData(inPosition, columnsChanged);
  4996. }
  4997. }
  4998. }
  4999. } else {
  5000. if (data) {
  5001. //asume data is already an object
  5002. return self.rowManager.setData(data, inPosition, columnsChanged);
  5003. } else {
  5004. //no data provided, check if ajaxURL is present;
  5005. if (self.modExists("ajax") && (self.modules.ajax.getUrl || self.options.ajaxURLGenerator)) {
  5006. if (self.options.pagination == "remote" && self.modExists("page", true)) {
  5007. self.modules.page.reset(true, true);
  5008. return self.modules.page.setPage(1);
  5009. } else {
  5010. return self.modules.ajax.loadData(inPosition, columnsChanged);
  5011. }
  5012. } else {
  5013. //empty data
  5014. return self.rowManager.setData([], inPosition, columnsChanged);
  5015. }
  5016. }
  5017. }
  5018. };
  5019. //clear data
  5020. Tabulator.prototype.clearData = function () {
  5021. if (this.modExists("ajax")) {
  5022. this.modules.ajax.blockActiveRequest();
  5023. }
  5024. this.rowManager.clearData();
  5025. };
  5026. //get table data array
  5027. Tabulator.prototype.getData = function (active) {
  5028. if (active === true) {
  5029. console.warn("passing a boolean to the getData function is deprecated, you should now pass the string 'active'");
  5030. active = "active";
  5031. }
  5032. return this.rowManager.getData(active);
  5033. };
  5034. //get table data array count
  5035. Tabulator.prototype.getDataCount = function (active) {
  5036. if (active === true) {
  5037. console.warn("passing a boolean to the getDataCount function is deprecated, you should now pass the string 'active'");
  5038. active = "active";
  5039. }
  5040. return this.rowManager.getDataCount(active);
  5041. };
  5042. //search for specific row components
  5043. Tabulator.prototype.searchRows = function (field, type, value) {
  5044. if (this.modExists("filter", true)) {
  5045. return this.modules.filter.search("rows", field, type, value);
  5046. }
  5047. };
  5048. //search for specific data
  5049. Tabulator.prototype.searchData = function (field, type, value) {
  5050. if (this.modExists("filter", true)) {
  5051. return this.modules.filter.search("data", field, type, value);
  5052. }
  5053. };
  5054. //get table html
  5055. Tabulator.prototype.getHtml = function (visible, style, config) {
  5056. if (this.modExists("export", true)) {
  5057. return this.modules.export.getHtml(visible, style, config);
  5058. }
  5059. };
  5060. //get print html
  5061. Tabulator.prototype.print = function (visible, style, config) {
  5062. if (this.modExists("print", true)) {
  5063. return this.modules.print.printFullscreen(visible, style, config);
  5064. }
  5065. };
  5066. //retrieve Ajax URL
  5067. Tabulator.prototype.getAjaxUrl = function () {
  5068. if (this.modExists("ajax", true)) {
  5069. return this.modules.ajax.getUrl();
  5070. }
  5071. };
  5072. //replace data, keeping table in position with same sort
  5073. Tabulator.prototype.replaceData = function (data, params, config) {
  5074. if (this.modExists("ajax")) {
  5075. this.modules.ajax.blockActiveRequest();
  5076. }
  5077. return this._setData(data, params, config, true);
  5078. };
  5079. //update table data
  5080. Tabulator.prototype.updateData = function (data) {
  5081. var _this19 = this;
  5082. var self = this;
  5083. var responses = 0;
  5084. return new Promise(function (resolve, reject) {
  5085. if (_this19.modExists("ajax")) {
  5086. _this19.modules.ajax.blockActiveRequest();
  5087. }
  5088. if (typeof data === "string") {
  5089. data = JSON.parse(data);
  5090. }
  5091. if (data) {
  5092. data.forEach(function (item) {
  5093. var row = self.rowManager.findRow(item[self.options.index]);
  5094. if (row) {
  5095. responses++;
  5096. row.updateData(item).then(function () {
  5097. responses--;
  5098. if (!responses) {
  5099. resolve();
  5100. }
  5101. });
  5102. }
  5103. });
  5104. } else {
  5105. console.warn("Update Error - No data provided");
  5106. reject("Update Error - No data provided");
  5107. }
  5108. });
  5109. };
  5110. Tabulator.prototype.addData = function (data, pos, index) {
  5111. var _this20 = this;
  5112. return new Promise(function (resolve, reject) {
  5113. if (_this20.modExists("ajax")) {
  5114. _this20.modules.ajax.blockActiveRequest();
  5115. }
  5116. if (typeof data === "string") {
  5117. data = JSON.parse(data);
  5118. }
  5119. if (data) {
  5120. _this20.rowManager.addRows(data, pos, index).then(function (rows) {
  5121. var output = [];
  5122. rows.forEach(function (row) {
  5123. output.push(row.getComponent());
  5124. });
  5125. resolve(output);
  5126. });
  5127. } else {
  5128. console.warn("Update Error - No data provided");
  5129. reject("Update Error - No data provided");
  5130. }
  5131. });
  5132. };
  5133. //update table data
  5134. Tabulator.prototype.updateOrAddData = function (data) {
  5135. var _this21 = this;
  5136. var self = this,
  5137. rows = [],
  5138. responses = 0;
  5139. return new Promise(function (resolve, reject) {
  5140. if (_this21.modExists("ajax")) {
  5141. _this21.modules.ajax.blockActiveRequest();
  5142. }
  5143. if (typeof data === "string") {
  5144. data = JSON.parse(data);
  5145. }
  5146. if (data) {
  5147. data.forEach(function (item) {
  5148. var row = self.rowManager.findRow(item[self.options.index]);
  5149. responses++;
  5150. if (row) {
  5151. row.updateData(item).then(function () {
  5152. responses--;
  5153. rows.push(row.getComponent());
  5154. if (!responses) {
  5155. resolve(rows);
  5156. }
  5157. });
  5158. } else {
  5159. self.rowManager.addRows(item).then(function (newRows) {
  5160. responses--;
  5161. rows.push(newRows[0].getComponent());
  5162. if (!responses) {
  5163. resolve(rows);
  5164. }
  5165. });
  5166. }
  5167. });
  5168. } else {
  5169. console.warn("Update Error - No data provided");
  5170. reject("Update Error - No data provided");
  5171. }
  5172. });
  5173. };
  5174. //get row object
  5175. Tabulator.prototype.getRow = function (index) {
  5176. var row = this.rowManager.findRow(index);
  5177. if (row) {
  5178. return row.getComponent();
  5179. } else {
  5180. console.warn("Find Error - No matching row found:", index);
  5181. return false;
  5182. }
  5183. };
  5184. //get row object
  5185. Tabulator.prototype.getRowFromPosition = function (position, active) {
  5186. var row = this.rowManager.getRowFromPosition(position, active);
  5187. if (row) {
  5188. return row.getComponent();
  5189. } else {
  5190. console.warn("Find Error - No matching row found:", position);
  5191. return false;
  5192. }
  5193. };
  5194. //delete row from table
  5195. Tabulator.prototype.deleteRow = function (index) {
  5196. var _this22 = this;
  5197. return new Promise(function (resolve, reject) {
  5198. var self = _this22,
  5199. count = 0,
  5200. successCount = 0,
  5201. foundRows = [];
  5202. function doneCheck() {
  5203. count++;
  5204. if (count == index.length) {
  5205. if (successCount) {
  5206. self.rowManager.reRenderInPosition();
  5207. resolve();
  5208. }
  5209. }
  5210. }
  5211. if (!Array.isArray(index)) {
  5212. index = [index];
  5213. }
  5214. //find matching rows
  5215. index.forEach(function (item) {
  5216. var row = _this22.rowManager.findRow(item, true);
  5217. if (row) {
  5218. foundRows.push(row);
  5219. } else {
  5220. console.warn("Delete Error - No matching row found:", item);
  5221. reject("Delete Error - No matching row found");
  5222. doneCheck();
  5223. }
  5224. });
  5225. //sort rows into correct order to ensure smooth delete from table
  5226. foundRows.sort(function (a, b) {
  5227. return _this22.rowManager.rows.indexOf(a) > _this22.rowManager.rows.indexOf(b) ? 1 : -1;
  5228. });
  5229. foundRows.forEach(function (row) {
  5230. row.delete().then(function () {
  5231. successCount++;
  5232. doneCheck();
  5233. }).catch(function (err) {
  5234. doneCheck();
  5235. reject(err);
  5236. });
  5237. });
  5238. });
  5239. };
  5240. //add row to table
  5241. Tabulator.prototype.addRow = function (data, pos, index) {
  5242. var _this23 = this;
  5243. return new Promise(function (resolve, reject) {
  5244. if (typeof data === "string") {
  5245. data = JSON.parse(data);
  5246. }
  5247. _this23.rowManager.addRows(data, pos, index).then(function (rows) {
  5248. //recalc column calculations if present
  5249. if (_this23.modExists("columnCalcs")) {
  5250. _this23.modules.columnCalcs.recalc(_this23.rowManager.activeRows);
  5251. }
  5252. resolve(rows[0].getComponent());
  5253. });
  5254. });
  5255. };
  5256. //update a row if it exitsts otherwise create it
  5257. Tabulator.prototype.updateOrAddRow = function (index, data) {
  5258. var _this24 = this;
  5259. return new Promise(function (resolve, reject) {
  5260. var row = _this24.rowManager.findRow(index);
  5261. if (typeof data === "string") {
  5262. data = JSON.parse(data);
  5263. }
  5264. if (row) {
  5265. row.updateData(data).then(function () {
  5266. //recalc column calculations if present
  5267. if (_this24.modExists("columnCalcs")) {
  5268. _this24.modules.columnCalcs.recalc(_this24.rowManager.activeRows);
  5269. }
  5270. resolve(row.getComponent());
  5271. }).catch(function (err) {
  5272. reject(err);
  5273. });
  5274. } else {
  5275. row = _this24.rowManager.addRows(data).then(function (rows) {
  5276. //recalc column calculations if present
  5277. if (_this24.modExists("columnCalcs")) {
  5278. _this24.modules.columnCalcs.recalc(_this24.rowManager.activeRows);
  5279. }
  5280. resolve(rows[0].getComponent());
  5281. }).catch(function (err) {
  5282. reject(err);
  5283. });
  5284. }
  5285. });
  5286. };
  5287. //update row data
  5288. Tabulator.prototype.updateRow = function (index, data) {
  5289. var _this25 = this;
  5290. return new Promise(function (resolve, reject) {
  5291. var row = _this25.rowManager.findRow(index);
  5292. if (typeof data === "string") {
  5293. data = JSON.parse(data);
  5294. }
  5295. if (row) {
  5296. row.updateData(data).then(function () {
  5297. resolve(row.getComponent());
  5298. }).catch(function (err) {
  5299. reject(err);
  5300. });
  5301. } else {
  5302. console.warn("Update Error - No matching row found:", index);
  5303. reject("Update Error - No matching row found");
  5304. }
  5305. });
  5306. };
  5307. //scroll to row in DOM
  5308. Tabulator.prototype.scrollToRow = function (index, position, ifVisible) {
  5309. var _this26 = this;
  5310. return new Promise(function (resolve, reject) {
  5311. var row = _this26.rowManager.findRow(index);
  5312. if (row) {
  5313. _this26.rowManager.scrollToRow(row, position, ifVisible).then(function () {
  5314. resolve();
  5315. }).catch(function (err) {
  5316. reject(err);
  5317. });
  5318. } else {
  5319. console.warn("Scroll Error - No matching row found:", index);
  5320. reject("Scroll Error - No matching row found");
  5321. }
  5322. });
  5323. };
  5324. Tabulator.prototype.moveRow = function (from, to, after) {
  5325. var fromRow = this.rowManager.findRow(from);
  5326. if (fromRow) {
  5327. fromRow.moveToRow(to, after);
  5328. } else {
  5329. console.warn("Move Error - No matching row found:", from);
  5330. }
  5331. };
  5332. Tabulator.prototype.getRows = function (active) {
  5333. if (active === true) {
  5334. console.warn("passing a boolean to the getRows function is deprecated, you should now pass the string 'active'");
  5335. active = "active";
  5336. }
  5337. return this.rowManager.getComponents(active);
  5338. };
  5339. //get position of row in table
  5340. Tabulator.prototype.getRowPosition = function (index, active) {
  5341. var row = this.rowManager.findRow(index);
  5342. if (row) {
  5343. return this.rowManager.getRowPosition(row, active);
  5344. } else {
  5345. console.warn("Position Error - No matching row found:", index);
  5346. return false;
  5347. }
  5348. };
  5349. //copy table data to clipboard
  5350. Tabulator.prototype.copyToClipboard = function (selector) {
  5351. if (this.modExists("clipboard", true)) {
  5352. this.modules.clipboard.copy(selector);
  5353. }
  5354. };
  5355. /////////////// Column Functions ///////////////
  5356. Tabulator.prototype.setColumns = function (definition) {
  5357. this.columnManager.setColumns(definition);
  5358. };
  5359. Tabulator.prototype.getColumns = function (structured) {
  5360. return this.columnManager.getComponents(structured);
  5361. };
  5362. Tabulator.prototype.getColumn = function (field) {
  5363. var col = this.columnManager.findColumn(field);
  5364. if (col) {
  5365. return col.getComponent();
  5366. } else {
  5367. console.warn("Find Error - No matching column found:", field);
  5368. return false;
  5369. }
  5370. };
  5371. Tabulator.prototype.getColumnDefinitions = function () {
  5372. return this.columnManager.getDefinitionTree();
  5373. };
  5374. Tabulator.prototype.getColumnLayout = function () {
  5375. if (this.modExists("persistence", true)) {
  5376. return this.modules.persistence.parseColumns(this.columnManager.getColumns());
  5377. }
  5378. };
  5379. Tabulator.prototype.setColumnLayout = function (layout) {
  5380. if (this.modExists("persistence", true)) {
  5381. this.columnManager.setColumns(this.modules.persistence.mergeDefinition(this.options.columns, layout));
  5382. return true;
  5383. }
  5384. return false;
  5385. };
  5386. Tabulator.prototype.showColumn = function (field) {
  5387. var column = this.columnManager.findColumn(field);
  5388. if (column) {
  5389. column.show();
  5390. if (this.options.responsiveLayout && this.modExists("responsiveLayout", true)) {
  5391. this.modules.responsiveLayout.update();
  5392. }
  5393. } else {
  5394. console.warn("Column Show Error - No matching column found:", field);
  5395. return false;
  5396. }
  5397. };
  5398. Tabulator.prototype.hideColumn = function (field) {
  5399. var column = this.columnManager.findColumn(field);
  5400. if (column) {
  5401. column.hide();
  5402. if (this.options.responsiveLayout && this.modExists("responsiveLayout", true)) {
  5403. this.modules.responsiveLayout.update();
  5404. }
  5405. } else {
  5406. console.warn("Column Hide Error - No matching column found:", field);
  5407. return false;
  5408. }
  5409. };
  5410. Tabulator.prototype.toggleColumn = function (field) {
  5411. var column = this.columnManager.findColumn(field);
  5412. if (column) {
  5413. if (column.visible) {
  5414. column.hide();
  5415. } else {
  5416. column.show();
  5417. }
  5418. } else {
  5419. console.warn("Column Visibility Toggle Error - No matching column found:", field);
  5420. return false;
  5421. }
  5422. };
  5423. Tabulator.prototype.addColumn = function (definition, before, field) {
  5424. var _this27 = this;
  5425. return new Promise(function (resolve, reject) {
  5426. var column = _this27.columnManager.findColumn(field);
  5427. _this27.columnManager.addColumn(definition, before, column).then(function (column) {
  5428. resolve(column.getComponent());
  5429. }).catch(function (err) {
  5430. reject(err);
  5431. });
  5432. });
  5433. };
  5434. Tabulator.prototype.deleteColumn = function (field) {
  5435. var _this28 = this;
  5436. return new Promise(function (resolve, reject) {
  5437. var column = _this28.columnManager.findColumn(field);
  5438. if (column) {
  5439. column.delete().then(function () {
  5440. resolve();
  5441. }).catch(function (err) {
  5442. reject(err);
  5443. });
  5444. } else {
  5445. console.warn("Column Delete Error - No matching column found:", field);
  5446. reject();
  5447. }
  5448. });
  5449. };
  5450. Tabulator.prototype.updateColumnDefinition = function (field, definition) {
  5451. var _this29 = this;
  5452. return new Promise(function (resolve, reject) {
  5453. var column = _this29.columnManager.findColumn(field);
  5454. if (column) {
  5455. column.updateDefinition(definition).then(function (col) {
  5456. resolve(col);
  5457. }).catch(function (err) {
  5458. reject(err);
  5459. });
  5460. } else {
  5461. console.warn("Column Update Error - No matching column found:", field);
  5462. reject();
  5463. }
  5464. });
  5465. };
  5466. Tabulator.prototype.moveColumn = function (from, to, after) {
  5467. var fromColumn = this.columnManager.findColumn(from);
  5468. var toColumn = this.columnManager.findColumn(to);
  5469. if (fromColumn) {
  5470. if (toColumn) {
  5471. this.columnManager.moveColumn(fromColumn, toColumn, after);
  5472. } else {
  5473. console.warn("Move Error - No matching column found:", toColumn);
  5474. }
  5475. } else {
  5476. console.warn("Move Error - No matching column found:", from);
  5477. }
  5478. };
  5479. //scroll to column in DOM
  5480. Tabulator.prototype.scrollToColumn = function (field, position, ifVisible) {
  5481. var _this30 = this;
  5482. return new Promise(function (resolve, reject) {
  5483. var column = _this30.columnManager.findColumn(field);
  5484. if (column) {
  5485. _this30.columnManager.scrollToColumn(column, position, ifVisible).then(function () {
  5486. resolve();
  5487. }).catch(function (err) {
  5488. reject(err);
  5489. });
  5490. } else {
  5491. console.warn("Scroll Error - No matching column found:", field);
  5492. reject("Scroll Error - No matching column found");
  5493. }
  5494. });
  5495. };
  5496. //////////// Localization Functions ////////////
  5497. Tabulator.prototype.setLocale = function (locale) {
  5498. this.modules.localize.setLocale(locale);
  5499. };
  5500. Tabulator.prototype.getLocale = function () {
  5501. return this.modules.localize.getLocale();
  5502. };
  5503. Tabulator.prototype.getLang = function (locale) {
  5504. return this.modules.localize.getLang(locale);
  5505. };
  5506. //////////// General Public Functions ////////////
  5507. //redraw list without updating data
  5508. Tabulator.prototype.redraw = function (force) {
  5509. this.columnManager.redraw(force);
  5510. this.rowManager.redraw(force);
  5511. };
  5512. Tabulator.prototype.setHeight = function (height) {
  5513. if (this.rowManager.renderMode !== "classic") {
  5514. this.options.height = isNaN(height) ? height : height + "px";
  5515. this.element.style.height = this.options.height;
  5516. this.rowManager.setRenderMode();
  5517. this.rowManager.redraw();
  5518. } else {
  5519. console.warn("setHeight function is not available in classic render mode");
  5520. }
  5521. };
  5522. ///////////////////// Sorting ////////////////////
  5523. //trigger sort
  5524. Tabulator.prototype.setSort = function (sortList, dir) {
  5525. if (this.modExists("sort", true)) {
  5526. this.modules.sort.setSort(sortList, dir);
  5527. this.rowManager.sorterRefresh();
  5528. }
  5529. };
  5530. Tabulator.prototype.getSorters = function () {
  5531. if (this.modExists("sort", true)) {
  5532. return this.modules.sort.getSort();
  5533. }
  5534. };
  5535. Tabulator.prototype.clearSort = function () {
  5536. if (this.modExists("sort", true)) {
  5537. this.modules.sort.clear();
  5538. this.rowManager.sorterRefresh();
  5539. }
  5540. };
  5541. ///////////////////// Filtering ////////////////////
  5542. //set standard filters
  5543. Tabulator.prototype.setFilter = function (field, type, value) {
  5544. if (this.modExists("filter", true)) {
  5545. this.modules.filter.setFilter(field, type, value);
  5546. this.rowManager.filterRefresh();
  5547. }
  5548. };
  5549. //add filter to array
  5550. Tabulator.prototype.addFilter = function (field, type, value) {
  5551. if (this.modExists("filter", true)) {
  5552. this.modules.filter.addFilter(field, type, value);
  5553. this.rowManager.filterRefresh();
  5554. }
  5555. };
  5556. //get all filters
  5557. Tabulator.prototype.getFilters = function (all) {
  5558. if (this.modExists("filter", true)) {
  5559. return this.modules.filter.getFilters(all);
  5560. }
  5561. };
  5562. Tabulator.prototype.setHeaderFilterFocus = function (field) {
  5563. if (this.modExists("filter", true)) {
  5564. var column = this.columnManager.findColumn(field);
  5565. if (column) {
  5566. this.modules.filter.setHeaderFilterFocus(column);
  5567. } else {
  5568. console.warn("Column Filter Focus Error - No matching column found:", field);
  5569. return false;
  5570. }
  5571. }
  5572. };
  5573. Tabulator.prototype.getHeaderFilterValue = function (field) {
  5574. if (this.modExists("filter", true)) {
  5575. var column = this.columnManager.findColumn(field);
  5576. if (column) {
  5577. return this.modules.filter.getHeaderFilterValue(column);
  5578. } else {
  5579. console.warn("Column Filter Error - No matching column found:", field);
  5580. }
  5581. }
  5582. };
  5583. Tabulator.prototype.setHeaderFilterValue = function (field, value) {
  5584. if (this.modExists("filter", true)) {
  5585. var column = this.columnManager.findColumn(field);
  5586. if (column) {
  5587. this.modules.filter.setHeaderFilterValue(column, value);
  5588. } else {
  5589. console.warn("Column Filter Error - No matching column found:", field);
  5590. return false;
  5591. }
  5592. }
  5593. };
  5594. Tabulator.prototype.getHeaderFilters = function () {
  5595. if (this.modExists("filter", true)) {
  5596. return this.modules.filter.getHeaderFilters();
  5597. }
  5598. };
  5599. //remove filter from array
  5600. Tabulator.prototype.removeFilter = function (field, type, value) {
  5601. if (this.modExists("filter", true)) {
  5602. this.modules.filter.removeFilter(field, type, value);
  5603. this.rowManager.filterRefresh();
  5604. }
  5605. };
  5606. //clear filters
  5607. Tabulator.prototype.clearFilter = function (all) {
  5608. if (this.modExists("filter", true)) {
  5609. this.modules.filter.clearFilter(all);
  5610. this.rowManager.filterRefresh();
  5611. }
  5612. };
  5613. //clear header filters
  5614. Tabulator.prototype.clearHeaderFilter = function () {
  5615. if (this.modExists("filter", true)) {
  5616. this.modules.filter.clearHeaderFilter();
  5617. this.rowManager.filterRefresh();
  5618. }
  5619. };
  5620. ///////////////////// Filtering ////////////////////
  5621. Tabulator.prototype.selectRow = function (rows) {
  5622. if (this.modExists("selectRow", true)) {
  5623. if (rows === true) {
  5624. console.warn("passing a boolean to the selectRowselectRow function is deprecated, you should now pass the string 'active'");
  5625. rows = "active";
  5626. }
  5627. this.modules.selectRow.selectRows(rows);
  5628. }
  5629. };
  5630. Tabulator.prototype.deselectRow = function (rows) {
  5631. if (this.modExists("selectRow", true)) {
  5632. this.modules.selectRow.deselectRows(rows);
  5633. }
  5634. };
  5635. Tabulator.prototype.toggleSelectRow = function (row) {
  5636. if (this.modExists("selectRow", true)) {
  5637. this.modules.selectRow.toggleRow(row);
  5638. }
  5639. };
  5640. Tabulator.prototype.getSelectedRows = function () {
  5641. if (this.modExists("selectRow", true)) {
  5642. return this.modules.selectRow.getSelectedRows();
  5643. }
  5644. };
  5645. Tabulator.prototype.getSelectedData = function () {
  5646. if (this.modExists("selectRow", true)) {
  5647. return this.modules.selectRow.getSelectedData();
  5648. }
  5649. };
  5650. //////////// Pagination Functions ////////////
  5651. Tabulator.prototype.setMaxPage = function (max) {
  5652. if (this.options.pagination && this.modExists("page")) {
  5653. this.modules.page.setMaxPage(max);
  5654. } else {
  5655. return false;
  5656. }
  5657. };
  5658. Tabulator.prototype.setPage = function (page) {
  5659. if (this.options.pagination && this.modExists("page")) {
  5660. return this.modules.page.setPage(page);
  5661. } else {
  5662. return new Promise(function (resolve, reject) {
  5663. reject();
  5664. });
  5665. }
  5666. };
  5667. Tabulator.prototype.setPageToRow = function (row) {
  5668. var _this31 = this;
  5669. return new Promise(function (resolve, reject) {
  5670. if (_this31.options.pagination && _this31.modExists("page")) {
  5671. row = _this31.rowManager.findRow(row);
  5672. if (row) {
  5673. _this31.modules.page.setPageToRow(row).then(function () {
  5674. resolve();
  5675. }).catch(function () {
  5676. reject();
  5677. });
  5678. } else {
  5679. reject();
  5680. }
  5681. } else {
  5682. reject();
  5683. }
  5684. });
  5685. };
  5686. Tabulator.prototype.setPageSize = function (size) {
  5687. if (this.options.pagination && this.modExists("page")) {
  5688. this.modules.page.setPageSize(size);
  5689. this.modules.page.setPage(1).then(function () {}).catch(function () {});
  5690. } else {
  5691. return false;
  5692. }
  5693. };
  5694. Tabulator.prototype.getPageSize = function () {
  5695. if (this.options.pagination && this.modExists("page", true)) {
  5696. return this.modules.page.getPageSize();
  5697. }
  5698. };
  5699. Tabulator.prototype.previousPage = function () {
  5700. if (this.options.pagination && this.modExists("page")) {
  5701. this.modules.page.previousPage();
  5702. } else {
  5703. return false;
  5704. }
  5705. };
  5706. Tabulator.prototype.nextPage = function () {
  5707. if (this.options.pagination && this.modExists("page")) {
  5708. this.modules.page.nextPage();
  5709. } else {
  5710. return false;
  5711. }
  5712. };
  5713. Tabulator.prototype.getPage = function () {
  5714. if (this.options.pagination && this.modExists("page")) {
  5715. return this.modules.page.getPage();
  5716. } else {
  5717. return false;
  5718. }
  5719. };
  5720. Tabulator.prototype.getPageMax = function () {
  5721. if (this.options.pagination && this.modExists("page")) {
  5722. return this.modules.page.getPageMax();
  5723. } else {
  5724. return false;
  5725. }
  5726. };
  5727. ///////////////// Grouping Functions ///////////////
  5728. Tabulator.prototype.setGroupBy = function (groups) {
  5729. if (this.modExists("groupRows", true)) {
  5730. this.options.groupBy = groups;
  5731. this.modules.groupRows.initialize();
  5732. this.rowManager.refreshActiveData("display");
  5733. if (this.options.persistence && this.modExists("persistence", true) && this.modules.persistence.config.group) {
  5734. this.modules.persistence.save("group");
  5735. }
  5736. } else {
  5737. return false;
  5738. }
  5739. };
  5740. Tabulator.prototype.setGroupStartOpen = function (values) {
  5741. if (this.modExists("groupRows", true)) {
  5742. this.options.groupStartOpen = values;
  5743. this.modules.groupRows.initialize();
  5744. if (this.options.groupBy) {
  5745. this.rowManager.refreshActiveData("group");
  5746. if (this.options.persistence && this.modExists("persistence", true) && this.modules.persistence.config.group) {
  5747. this.modules.persistence.save("group");
  5748. }
  5749. } else {
  5750. console.warn("Grouping Update - cant refresh view, no groups have been set");
  5751. }
  5752. } else {
  5753. return false;
  5754. }
  5755. };
  5756. Tabulator.prototype.setGroupHeader = function (values) {
  5757. if (this.modExists("groupRows", true)) {
  5758. this.options.groupHeader = values;
  5759. this.modules.groupRows.initialize();
  5760. if (this.options.groupBy) {
  5761. this.rowManager.refreshActiveData("group");
  5762. if (this.options.persistence && this.modExists("persistence", true) && this.modules.persistence.config.group) {
  5763. this.modules.persistence.save("group");
  5764. }
  5765. } else {
  5766. console.warn("Grouping Update - cant refresh view, no groups have been set");
  5767. }
  5768. } else {
  5769. return false;
  5770. }
  5771. };
  5772. Tabulator.prototype.getGroups = function (values) {
  5773. if (this.modExists("groupRows", true)) {
  5774. return this.modules.groupRows.getGroups(true);
  5775. } else {
  5776. return false;
  5777. }
  5778. };
  5779. // get grouped table data in the same format as getData()
  5780. Tabulator.prototype.getGroupedData = function () {
  5781. if (this.modExists("groupRows", true)) {
  5782. return this.options.groupBy ? this.modules.groupRows.getGroupedData() : this.getData();
  5783. }
  5784. };
  5785. ///////////////// Column Calculation Functions ///////////////
  5786. Tabulator.prototype.getCalcResults = function () {
  5787. if (this.modExists("columnCalcs", true)) {
  5788. return this.modules.columnCalcs.getResults();
  5789. } else {
  5790. return false;
  5791. }
  5792. };
  5793. Tabulator.prototype.recalc = function () {
  5794. if (this.modExists("columnCalcs", true)) {
  5795. this.modules.columnCalcs.recalcAll(this.rowManager.activeRows);
  5796. }
  5797. };
  5798. /////////////// Navigation Management //////////////
  5799. Tabulator.prototype.navigatePrev = function () {
  5800. var cell = false;
  5801. if (this.modExists("edit", true)) {
  5802. cell = this.modules.edit.currentCell;
  5803. if (cell) {
  5804. return cell.nav().prev();
  5805. }
  5806. }
  5807. return false;
  5808. };
  5809. Tabulator.prototype.navigateNext = function () {
  5810. var cell = false;
  5811. if (this.modExists("edit", true)) {
  5812. cell = this.modules.edit.currentCell;
  5813. if (cell) {
  5814. return cell.nav().next();
  5815. }
  5816. }
  5817. return false;
  5818. };
  5819. Tabulator.prototype.navigateLeft = function () {
  5820. var cell = false;
  5821. if (this.modExists("edit", true)) {
  5822. cell = this.modules.edit.currentCell;
  5823. if (cell) {
  5824. e.preventDefault();
  5825. return cell.nav().left();
  5826. }
  5827. }
  5828. return false;
  5829. };
  5830. Tabulator.prototype.navigateRight = function () {
  5831. var cell = false;
  5832. if (this.modExists("edit", true)) {
  5833. cell = this.modules.edit.currentCell;
  5834. if (cell) {
  5835. e.preventDefault();
  5836. return cell.nav().right();
  5837. }
  5838. }
  5839. return false;
  5840. };
  5841. Tabulator.prototype.navigateUp = function () {
  5842. var cell = false;
  5843. if (this.modExists("edit", true)) {
  5844. cell = this.modules.edit.currentCell;
  5845. if (cell) {
  5846. e.preventDefault();
  5847. return cell.nav().up();
  5848. }
  5849. }
  5850. return false;
  5851. };
  5852. Tabulator.prototype.navigateDown = function () {
  5853. var cell = false;
  5854. if (this.modExists("edit", true)) {
  5855. cell = this.modules.edit.currentCell;
  5856. if (cell) {
  5857. e.preventDefault();
  5858. return cell.nav().down();
  5859. }
  5860. }
  5861. return false;
  5862. };
  5863. /////////////// History Management //////////////
  5864. Tabulator.prototype.undo = function () {
  5865. if (this.options.history && this.modExists("history", true)) {
  5866. return this.modules.history.undo();
  5867. } else {
  5868. return false;
  5869. }
  5870. };
  5871. Tabulator.prototype.redo = function () {
  5872. if (this.options.history && this.modExists("history", true)) {
  5873. return this.modules.history.redo();
  5874. } else {
  5875. return false;
  5876. }
  5877. };
  5878. Tabulator.prototype.getHistoryUndoSize = function () {
  5879. if (this.options.history && this.modExists("history", true)) {
  5880. return this.modules.history.getHistoryUndoSize();
  5881. } else {
  5882. return false;
  5883. }
  5884. };
  5885. Tabulator.prototype.getHistoryRedoSize = function () {
  5886. if (this.options.history && this.modExists("history", true)) {
  5887. return this.modules.history.getHistoryRedoSize();
  5888. } else {
  5889. return false;
  5890. }
  5891. };
  5892. /////////////// Download Management //////////////
  5893. Tabulator.prototype.download = function (type, filename, options, active) {
  5894. if (this.modExists("download", true)) {
  5895. this.modules.download.download(type, filename, options, active);
  5896. }
  5897. };
  5898. Tabulator.prototype.downloadToTab = function (type, filename, options, active) {
  5899. if (this.modExists("download", true)) {
  5900. this.modules.download.download(type, filename, options, active, true);
  5901. }
  5902. };
  5903. /////////// Inter Table Communications ///////////
  5904. Tabulator.prototype.tableComms = function (table, module, action, data) {
  5905. this.modules.comms.receive(table, module, action, data);
  5906. };
  5907. ////////////// Extension Management //////////////
  5908. //object to hold module
  5909. Tabulator.prototype.moduleBindings = {};
  5910. //extend module
  5911. Tabulator.prototype.extendModule = function (name, property, values) {
  5912. if (Tabulator.prototype.moduleBindings[name]) {
  5913. var source = Tabulator.prototype.moduleBindings[name].prototype[property];
  5914. if (source) {
  5915. if ((typeof values === 'undefined' ? 'undefined' : _typeof(values)) == "object") {
  5916. for (var key in values) {
  5917. source[key] = values[key];
  5918. }
  5919. } else {
  5920. console.warn("Module Error - Invalid value type, it must be an object");
  5921. }
  5922. } else {
  5923. console.warn("Module Error - property does not exist:", property);
  5924. }
  5925. } else {
  5926. console.warn("Module Error - module does not exist:", name);
  5927. }
  5928. };
  5929. //add module to tabulator
  5930. Tabulator.prototype.registerModule = function (name, module) {
  5931. var self = this;
  5932. Tabulator.prototype.moduleBindings[name] = module;
  5933. };
  5934. //ensure that module are bound to instantiated function
  5935. Tabulator.prototype.bindModules = function () {
  5936. this.modules = {};
  5937. for (var name in Tabulator.prototype.moduleBindings) {
  5938. this.modules[name] = new Tabulator.prototype.moduleBindings[name](this);
  5939. }
  5940. };
  5941. //Check for module
  5942. Tabulator.prototype.modExists = function (plugin, required) {
  5943. if (this.modules[plugin]) {
  5944. return true;
  5945. } else {
  5946. if (required) {
  5947. console.error("Tabulator Module Not Installed: " + plugin);
  5948. }
  5949. return false;
  5950. }
  5951. };
  5952. Tabulator.prototype.helpers = {
  5953. elVisible: function elVisible(el) {
  5954. return !(el.offsetWidth <= 0 && el.offsetHeight <= 0);
  5955. },
  5956. elOffset: function elOffset(el) {
  5957. var box = el.getBoundingClientRect();
  5958. return {
  5959. top: box.top + window.pageYOffset - document.documentElement.clientTop,
  5960. left: box.left + window.pageXOffset - document.documentElement.clientLeft
  5961. };
  5962. },
  5963. deepClone: function deepClone(obj) {
  5964. var clone = Array.isArray(obj) ? [] : {};
  5965. for (var i in obj) {
  5966. if (obj[i] != null && _typeof(obj[i]) === "object") {
  5967. if (obj[i] instanceof Date) {
  5968. clone[i] = new Date(obj[i]);
  5969. } else {
  5970. clone[i] = this.deepClone(obj[i]);
  5971. }
  5972. } else {
  5973. clone[i] = obj[i];
  5974. }
  5975. }
  5976. return clone;
  5977. }
  5978. };
  5979. Tabulator.prototype.comms = {
  5980. tables: [],
  5981. register: function register(table) {
  5982. Tabulator.prototype.comms.tables.push(table);
  5983. },
  5984. deregister: function deregister(table) {
  5985. var index = Tabulator.prototype.comms.tables.indexOf(table);
  5986. if (index > -1) {
  5987. Tabulator.prototype.comms.tables.splice(index, 1);
  5988. }
  5989. },
  5990. lookupTable: function lookupTable(query, silent) {
  5991. var results = [],
  5992. matches,
  5993. match;
  5994. if (typeof query === "string") {
  5995. matches = document.querySelectorAll(query);
  5996. if (matches.length) {
  5997. for (var i = 0; i < matches.length; i++) {
  5998. match = Tabulator.prototype.comms.matchElement(matches[i]);
  5999. if (match) {
  6000. results.push(match);
  6001. }
  6002. }
  6003. }
  6004. } else if (typeof HTMLElement !== "undefined" && query instanceof HTMLElement || query instanceof Tabulator) {
  6005. match = Tabulator.prototype.comms.matchElement(query);
  6006. if (match) {
  6007. results.push(match);
  6008. }
  6009. } else if (Array.isArray(query)) {
  6010. query.forEach(function (item) {
  6011. results = results.concat(Tabulator.prototype.comms.lookupTable(item));
  6012. });
  6013. } else {
  6014. if (!silent) {
  6015. console.warn("Table Connection Error - Invalid Selector", query);
  6016. }
  6017. }
  6018. return results;
  6019. },
  6020. matchElement: function matchElement(element) {
  6021. return Tabulator.prototype.comms.tables.find(function (table) {
  6022. return element instanceof Tabulator ? table === element : table.element === element;
  6023. });
  6024. }
  6025. };
  6026. Tabulator.prototype.findTable = function (query) {
  6027. var results = Tabulator.prototype.comms.lookupTable(query, true);
  6028. return Array.isArray(results) && !results.length ? false : results;
  6029. };
  6030. var Layout = function Layout(table) {
  6031. this.table = table;
  6032. this.mode = null;
  6033. };
  6034. //initialize layout system
  6035. Layout.prototype.initialize = function (layout) {
  6036. if (this.modes[layout]) {
  6037. this.mode = layout;
  6038. } else {
  6039. console.warn("Layout Error - invalid mode set, defaulting to 'fitData' : " + layout);
  6040. this.mode = 'fitData';
  6041. }
  6042. this.table.element.setAttribute("tabulator-layout", this.mode);
  6043. };
  6044. Layout.prototype.getMode = function () {
  6045. return this.mode;
  6046. };
  6047. //trigger table layout
  6048. Layout.prototype.layout = function () {
  6049. this.modes[this.mode].call(this, this.table.columnManager.columnsByIndex);
  6050. };
  6051. //layout render functions
  6052. Layout.prototype.modes = {
  6053. //resize columns to fit data the contain
  6054. "fitData": function fitData(columns) {
  6055. columns.forEach(function (column) {
  6056. column.reinitializeWidth();
  6057. });
  6058. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  6059. this.table.modules.responsiveLayout.update();
  6060. }
  6061. },
  6062. //resize columns to fit data the contain and stretch row to fill table
  6063. "fitDataFill": function fitDataFill(columns) {
  6064. columns.forEach(function (column) {
  6065. column.reinitializeWidth();
  6066. });
  6067. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  6068. this.table.modules.responsiveLayout.update();
  6069. }
  6070. },
  6071. //resize columns to fit data the contain and stretch last column to fill table
  6072. "fitDataStretch": function fitDataStretch(columns) {
  6073. var _this32 = this;
  6074. var colsWidth = 0,
  6075. tableWidth = this.table.rowManager.element.clientWidth,
  6076. gap = 0,
  6077. lastCol = false;
  6078. columns.forEach(function (column, i) {
  6079. if (!column.widthFixed) {
  6080. column.reinitializeWidth();
  6081. }
  6082. if (_this32.table.options.responsiveLayout ? column.modules.responsive.visible : column.visible) {
  6083. lastCol = column;
  6084. }
  6085. if (column.visible) {
  6086. colsWidth += column.getWidth();
  6087. }
  6088. });
  6089. if (lastCol) {
  6090. gap = tableWidth - colsWidth + lastCol.getWidth();
  6091. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  6092. lastCol.setWidth(0);
  6093. this.table.modules.responsiveLayout.update();
  6094. }
  6095. if (gap > 0) {
  6096. lastCol.setWidth(gap);
  6097. } else {
  6098. lastCol.reinitializeWidth();
  6099. }
  6100. } else {
  6101. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  6102. this.table.modules.responsiveLayout.update();
  6103. }
  6104. }
  6105. },
  6106. //resize columns to fit
  6107. "fitColumns": function fitColumns(columns) {
  6108. var self = this;
  6109. var totalWidth = self.table.element.clientWidth; //table element width
  6110. var fixedWidth = 0; //total width of columns with a defined width
  6111. var flexWidth = 0; //total width available to flexible columns
  6112. var flexGrowUnits = 0; //total number of widthGrow blocks accross all columns
  6113. var flexColWidth = 0; //desired width of flexible columns
  6114. var flexColumns = []; //array of flexible width columns
  6115. var fixedShrinkColumns = []; //array of fixed width columns that can shrink
  6116. var flexShrinkUnits = 0; //total number of widthShrink blocks accross all columns
  6117. var overflowWidth = 0; //horizontal overflow width
  6118. var gapFill = 0; //number of pixels to be added to final column to close and half pixel gaps
  6119. function calcWidth(width) {
  6120. var colWidth;
  6121. if (typeof width == "string") {
  6122. if (width.indexOf("%") > -1) {
  6123. colWidth = totalWidth / 100 * parseInt(width);
  6124. } else {
  6125. colWidth = parseInt(width);
  6126. }
  6127. } else {
  6128. colWidth = width;
  6129. }
  6130. return colWidth;
  6131. }
  6132. //ensure columns resize to take up the correct amount of space
  6133. function scaleColumns(columns, freeSpace, colWidth, shrinkCols) {
  6134. var oversizeCols = [],
  6135. oversizeSpace = 0,
  6136. remainingSpace = 0,
  6137. nextColWidth = 0,
  6138. gap = 0,
  6139. changeUnits = 0,
  6140. undersizeCols = [];
  6141. function calcGrow(col) {
  6142. return colWidth * (col.column.definition.widthGrow || 1);
  6143. }
  6144. function calcShrink(col) {
  6145. return calcWidth(col.width) - colWidth * (col.column.definition.widthShrink || 0);
  6146. }
  6147. columns.forEach(function (col, i) {
  6148. var width = shrinkCols ? calcShrink(col) : calcGrow(col);
  6149. if (col.column.minWidth >= width) {
  6150. oversizeCols.push(col);
  6151. } else {
  6152. undersizeCols.push(col);
  6153. changeUnits += shrinkCols ? col.column.definition.widthShrink || 1 : col.column.definition.widthGrow || 1;
  6154. }
  6155. });
  6156. if (oversizeCols.length) {
  6157. oversizeCols.forEach(function (col) {
  6158. oversizeSpace += shrinkCols ? col.width - col.column.minWidth : col.column.minWidth;
  6159. col.width = col.column.minWidth;
  6160. });
  6161. remainingSpace = freeSpace - oversizeSpace;
  6162. nextColWidth = changeUnits ? Math.floor(remainingSpace / changeUnits) : remainingSpace;
  6163. gap = remainingSpace - nextColWidth * changeUnits;
  6164. gap += scaleColumns(undersizeCols, remainingSpace, nextColWidth, shrinkCols);
  6165. } else {
  6166. gap = changeUnits ? freeSpace - Math.floor(freeSpace / changeUnits) * changeUnits : freeSpace;
  6167. undersizeCols.forEach(function (column) {
  6168. column.width = shrinkCols ? calcShrink(column) : calcGrow(column);
  6169. });
  6170. }
  6171. return gap;
  6172. }
  6173. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  6174. this.table.modules.responsiveLayout.update();
  6175. }
  6176. //adjust for vertical scrollbar if present
  6177. if (this.table.rowManager.element.scrollHeight > this.table.rowManager.element.clientHeight) {
  6178. totalWidth -= this.table.rowManager.element.offsetWidth - this.table.rowManager.element.clientWidth;
  6179. }
  6180. columns.forEach(function (column) {
  6181. var width, minWidth, colWidth;
  6182. if (column.visible) {
  6183. width = column.definition.width;
  6184. minWidth = parseInt(column.minWidth);
  6185. if (width) {
  6186. colWidth = calcWidth(width);
  6187. fixedWidth += colWidth > minWidth ? colWidth : minWidth;
  6188. if (column.definition.widthShrink) {
  6189. fixedShrinkColumns.push({
  6190. column: column,
  6191. width: colWidth > minWidth ? colWidth : minWidth
  6192. });
  6193. flexShrinkUnits += column.definition.widthShrink;
  6194. }
  6195. } else {
  6196. flexColumns.push({
  6197. column: column,
  6198. width: 0
  6199. });
  6200. flexGrowUnits += column.definition.widthGrow || 1;
  6201. }
  6202. }
  6203. });
  6204. //calculate available space
  6205. flexWidth = totalWidth - fixedWidth;
  6206. //calculate correct column size
  6207. flexColWidth = Math.floor(flexWidth / flexGrowUnits);
  6208. //generate column widths
  6209. var gapFill = scaleColumns(flexColumns, flexWidth, flexColWidth, false);
  6210. //increase width of last column to account for rounding errors
  6211. if (flexColumns.length && gapFill > 0) {
  6212. flexColumns[flexColumns.length - 1].width += +gapFill;
  6213. }
  6214. //caculate space for columns to be shrunk into
  6215. flexColumns.forEach(function (col) {
  6216. flexWidth -= col.width;
  6217. });
  6218. overflowWidth = Math.abs(gapFill) + flexWidth;
  6219. //shrink oversize columns if there is no available space
  6220. if (overflowWidth > 0 && flexShrinkUnits) {
  6221. gapFill = scaleColumns(fixedShrinkColumns, overflowWidth, Math.floor(overflowWidth / flexShrinkUnits), true);
  6222. }
  6223. //decrease width of last column to account for rounding errors
  6224. if (fixedShrinkColumns.length) {
  6225. fixedShrinkColumns[fixedShrinkColumns.length - 1].width -= gapFill;
  6226. }
  6227. flexColumns.forEach(function (col) {
  6228. col.column.setWidth(col.width);
  6229. });
  6230. fixedShrinkColumns.forEach(function (col) {
  6231. col.column.setWidth(col.width);
  6232. });
  6233. }
  6234. };
  6235. Tabulator.prototype.registerModule("layout", Layout);
  6236. var Localize = function Localize(table) {
  6237. this.table = table; //hold Tabulator object
  6238. this.locale = "default"; //current locale
  6239. this.lang = false; //current language
  6240. this.bindings = {}; //update events to call when locale is changed
  6241. };
  6242. //set header placehoder
  6243. Localize.prototype.setHeaderFilterPlaceholder = function (placeholder) {
  6244. this.langs.default.headerFilters.default = placeholder;
  6245. };
  6246. //set header filter placeholder by column
  6247. Localize.prototype.setHeaderFilterColumnPlaceholder = function (column, placeholder) {
  6248. this.langs.default.headerFilters.columns[column] = placeholder;
  6249. if (this.lang && !this.lang.headerFilters.columns[column]) {
  6250. this.lang.headerFilters.columns[column] = placeholder;
  6251. }
  6252. };
  6253. //setup a lang description object
  6254. Localize.prototype.installLang = function (locale, lang) {
  6255. if (this.langs[locale]) {
  6256. this._setLangProp(this.langs[locale], lang);
  6257. } else {
  6258. this.langs[locale] = lang;
  6259. }
  6260. };
  6261. Localize.prototype._setLangProp = function (lang, values) {
  6262. for (var key in values) {
  6263. if (lang[key] && _typeof(lang[key]) == "object") {
  6264. this._setLangProp(lang[key], values[key]);
  6265. } else {
  6266. lang[key] = values[key];
  6267. }
  6268. }
  6269. };
  6270. //set current locale
  6271. Localize.prototype.setLocale = function (desiredLocale) {
  6272. var self = this;
  6273. desiredLocale = desiredLocale || "default";
  6274. //fill in any matching languge values
  6275. function traverseLang(trans, path) {
  6276. for (var prop in trans) {
  6277. if (_typeof(trans[prop]) == "object") {
  6278. if (!path[prop]) {
  6279. path[prop] = {};
  6280. }
  6281. traverseLang(trans[prop], path[prop]);
  6282. } else {
  6283. path[prop] = trans[prop];
  6284. }
  6285. }
  6286. }
  6287. //determing correct locale to load
  6288. if (desiredLocale === true && navigator.language) {
  6289. //get local from system
  6290. desiredLocale = navigator.language.toLowerCase();
  6291. }
  6292. if (desiredLocale) {
  6293. //if locale is not set, check for matching top level locale else use default
  6294. if (!self.langs[desiredLocale]) {
  6295. var prefix = desiredLocale.split("-")[0];
  6296. if (self.langs[prefix]) {
  6297. console.warn("Localization Error - Exact matching locale not found, using closest match: ", desiredLocale, prefix);
  6298. desiredLocale = prefix;
  6299. } else {
  6300. console.warn("Localization Error - Matching locale not found, using default: ", desiredLocale);
  6301. desiredLocale = "default";
  6302. }
  6303. }
  6304. }
  6305. self.locale = desiredLocale;
  6306. //load default lang template
  6307. self.lang = Tabulator.prototype.helpers.deepClone(self.langs.default || {});
  6308. if (desiredLocale != "default") {
  6309. traverseLang(self.langs[desiredLocale], self.lang);
  6310. }
  6311. self.table.options.localized.call(self.table, self.locale, self.lang);
  6312. self._executeBindings();
  6313. };
  6314. //get current locale
  6315. Localize.prototype.getLocale = function (locale) {
  6316. return self.locale;
  6317. };
  6318. //get lang object for given local or current if none provided
  6319. Localize.prototype.getLang = function (locale) {
  6320. return locale ? this.langs[locale] : this.lang;
  6321. };
  6322. //get text for current locale
  6323. Localize.prototype.getText = function (path, value) {
  6324. var path = value ? path + "|" + value : path,
  6325. pathArray = path.split("|"),
  6326. text = this._getLangElement(pathArray, this.locale);
  6327. // if(text === false){
  6328. // console.warn("Localization Error - Matching localized text not found for given path: ", path);
  6329. // }
  6330. return text || "";
  6331. };
  6332. //traverse langs object and find localized copy
  6333. Localize.prototype._getLangElement = function (path, locale) {
  6334. var self = this;
  6335. var root = self.lang;
  6336. path.forEach(function (level) {
  6337. var rootPath;
  6338. if (root) {
  6339. rootPath = root[level];
  6340. if (typeof rootPath != "undefined") {
  6341. root = rootPath;
  6342. } else {
  6343. root = false;
  6344. }
  6345. }
  6346. });
  6347. return root;
  6348. };
  6349. //set update binding
  6350. Localize.prototype.bind = function (path, callback) {
  6351. if (!this.bindings[path]) {
  6352. this.bindings[path] = [];
  6353. }
  6354. this.bindings[path].push(callback);
  6355. callback(this.getText(path), this.lang);
  6356. };
  6357. //itterate through bindings and trigger updates
  6358. Localize.prototype._executeBindings = function () {
  6359. var self = this;
  6360. var _loop = function _loop(path) {
  6361. self.bindings[path].forEach(function (binding) {
  6362. binding(self.getText(path), self.lang);
  6363. });
  6364. };
  6365. for (var path in self.bindings) {
  6366. _loop(path);
  6367. }
  6368. };
  6369. //Localized text listings
  6370. Localize.prototype.langs = {
  6371. "default": { //hold default locale text
  6372. "groups": {
  6373. "item": "item",
  6374. "items": "items"
  6375. },
  6376. "columns": {},
  6377. "ajax": {
  6378. "loading": "Loading",
  6379. "error": "Error"
  6380. },
  6381. "pagination": {
  6382. "page_size": "Page Size",
  6383. "first": "First",
  6384. "first_title": "First Page",
  6385. "last": "Last",
  6386. "last_title": "Last Page",
  6387. "prev": "Prev",
  6388. "prev_title": "Prev Page",
  6389. "next": "Next",
  6390. "next_title": "Next Page"
  6391. },
  6392. "headerFilters": {
  6393. "default": "filter column...",
  6394. "columns": {}
  6395. }
  6396. }
  6397. };
  6398. Tabulator.prototype.registerModule("localize", Localize);
  6399. var Comms = function Comms(table) {
  6400. this.table = table;
  6401. };
  6402. Comms.prototype.getConnections = function (selectors) {
  6403. var self = this,
  6404. connections = [],
  6405. connection;
  6406. connection = Tabulator.prototype.comms.lookupTable(selectors);
  6407. connection.forEach(function (con) {
  6408. if (self.table !== con) {
  6409. connections.push(con);
  6410. }
  6411. });
  6412. return connections;
  6413. };
  6414. Comms.prototype.send = function (selectors, module, action, data) {
  6415. var self = this,
  6416. connections = this.getConnections(selectors);
  6417. connections.forEach(function (connection) {
  6418. connection.tableComms(self.table.element, module, action, data);
  6419. });
  6420. if (!connections.length && selectors) {
  6421. console.warn("Table Connection Error - No tables matching selector found", selectors);
  6422. }
  6423. };
  6424. Comms.prototype.receive = function (table, module, action, data) {
  6425. if (this.table.modExists(module)) {
  6426. return this.table.modules[module].commsReceived(table, action, data);
  6427. } else {
  6428. console.warn("Inter-table Comms Error - no such module:", module);
  6429. }
  6430. };
  6431. Tabulator.prototype.registerModule("comms", Comms);
  6432. var Accessor = function Accessor(table) {
  6433. this.table = table; //hold Tabulator object
  6434. this.allowedTypes = ["", "data", "download", "clipboard", "print", "htmlOutput"]; //list of accessor types
  6435. };
  6436. //initialize column accessor
  6437. Accessor.prototype.initializeColumn = function (column) {
  6438. var self = this,
  6439. match = false,
  6440. config = {};
  6441. this.allowedTypes.forEach(function (type) {
  6442. var key = "accessor" + (type.charAt(0).toUpperCase() + type.slice(1)),
  6443. accessor;
  6444. if (column.definition[key]) {
  6445. accessor = self.lookupAccessor(column.definition[key]);
  6446. if (accessor) {
  6447. match = true;
  6448. config[key] = {
  6449. accessor: accessor,
  6450. params: column.definition[key + "Params"] || {}
  6451. };
  6452. }
  6453. }
  6454. });
  6455. if (match) {
  6456. column.modules.accessor = config;
  6457. }
  6458. };
  6459. Accessor.prototype.lookupAccessor = function (value) {
  6460. var accessor = false;
  6461. //set column accessor
  6462. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  6463. case "string":
  6464. if (this.accessors[value]) {
  6465. accessor = this.accessors[value];
  6466. } else {
  6467. console.warn("Accessor Error - No such accessor found, ignoring: ", value);
  6468. }
  6469. break;
  6470. case "function":
  6471. accessor = value;
  6472. break;
  6473. }
  6474. return accessor;
  6475. };
  6476. //apply accessor to row
  6477. Accessor.prototype.transformRow = function (dataIn, type) {
  6478. var self = this,
  6479. key = "accessor" + (type.charAt(0).toUpperCase() + type.slice(1));
  6480. //clone data object with deep copy to isolate internal data from returned result
  6481. var data = Tabulator.prototype.helpers.deepClone(dataIn || {});
  6482. self.table.columnManager.traverse(function (column) {
  6483. var value, accessor, params, component;
  6484. if (column.modules.accessor) {
  6485. accessor = column.modules.accessor[key] || column.modules.accessor.accessor || false;
  6486. if (accessor) {
  6487. value = column.getFieldValue(data);
  6488. if (value != "undefined") {
  6489. component = column.getComponent();
  6490. params = typeof accessor.params === "function" ? accessor.params(value, data, type, component) : accessor.params;
  6491. column.setFieldValue(data, accessor.accessor(value, data, type, params, component));
  6492. }
  6493. }
  6494. }
  6495. });
  6496. return data;
  6497. },
  6498. //default accessors
  6499. Accessor.prototype.accessors = {};
  6500. Tabulator.prototype.registerModule("accessor", Accessor);
  6501. var Ajax = function Ajax(table) {
  6502. this.table = table; //hold Tabulator object
  6503. this.config = false; //hold config object for ajax request
  6504. this.url = ""; //request URL
  6505. this.urlGenerator = false;
  6506. this.params = false; //request parameters
  6507. this.loaderElement = this.createLoaderElement(); //loader message div
  6508. this.msgElement = this.createMsgElement(); //message element
  6509. this.loadingElement = false;
  6510. this.errorElement = false;
  6511. this.loaderPromise = false;
  6512. this.progressiveLoad = false;
  6513. this.loading = false;
  6514. this.requestOrder = 0; //prevent requests comming out of sequence if overridden by another load request
  6515. };
  6516. //initialize setup options
  6517. Ajax.prototype.initialize = function () {
  6518. var template;
  6519. this.loaderElement.appendChild(this.msgElement);
  6520. if (this.table.options.ajaxLoaderLoading) {
  6521. if (typeof this.table.options.ajaxLoaderLoading == "string") {
  6522. template = document.createElement('template');
  6523. template.innerHTML = this.table.options.ajaxLoaderLoading.trim();
  6524. this.loadingElement = template.content.firstChild;
  6525. } else {
  6526. this.loadingElement = this.table.options.ajaxLoaderLoading;
  6527. }
  6528. }
  6529. this.loaderPromise = this.table.options.ajaxRequestFunc || this.defaultLoaderPromise;
  6530. this.urlGenerator = this.table.options.ajaxURLGenerator || this.defaultURLGenerator;
  6531. if (this.table.options.ajaxLoaderError) {
  6532. if (typeof this.table.options.ajaxLoaderError == "string") {
  6533. template = document.createElement('template');
  6534. template.innerHTML = this.table.options.ajaxLoaderError.trim();
  6535. this.errorElement = template.content.firstChild;
  6536. } else {
  6537. this.errorElement = this.table.options.ajaxLoaderError;
  6538. }
  6539. }
  6540. if (this.table.options.ajaxParams) {
  6541. this.setParams(this.table.options.ajaxParams);
  6542. }
  6543. if (this.table.options.ajaxConfig) {
  6544. this.setConfig(this.table.options.ajaxConfig);
  6545. }
  6546. if (this.table.options.ajaxURL) {
  6547. this.setUrl(this.table.options.ajaxURL);
  6548. }
  6549. if (this.table.options.ajaxProgressiveLoad) {
  6550. if (this.table.options.pagination) {
  6551. this.progressiveLoad = false;
  6552. console.error("Progressive Load Error - Pagination and progressive load cannot be used at the same time");
  6553. } else {
  6554. if (this.table.modExists("page")) {
  6555. this.progressiveLoad = this.table.options.ajaxProgressiveLoad;
  6556. this.table.modules.page.initializeProgressive(this.progressiveLoad);
  6557. } else {
  6558. console.error("Pagination plugin is required for progressive ajax loading");
  6559. }
  6560. }
  6561. }
  6562. };
  6563. Ajax.prototype.createLoaderElement = function () {
  6564. var el = document.createElement("div");
  6565. el.classList.add("tabulator-loader");
  6566. return el;
  6567. };
  6568. Ajax.prototype.createMsgElement = function () {
  6569. var el = document.createElement("div");
  6570. el.classList.add("tabulator-loader-msg");
  6571. el.setAttribute("role", "alert");
  6572. return el;
  6573. };
  6574. //set ajax params
  6575. Ajax.prototype.setParams = function (params, update) {
  6576. if (update) {
  6577. this.params = this.params || {};
  6578. for (var key in params) {
  6579. this.params[key] = params[key];
  6580. }
  6581. } else {
  6582. this.params = params;
  6583. }
  6584. };
  6585. Ajax.prototype.getParams = function () {
  6586. return this.params || {};
  6587. };
  6588. //load config object
  6589. Ajax.prototype.setConfig = function (config) {
  6590. this._loadDefaultConfig();
  6591. if (typeof config == "string") {
  6592. this.config.method = config;
  6593. } else {
  6594. for (var key in config) {
  6595. this.config[key] = config[key];
  6596. }
  6597. }
  6598. };
  6599. //create config object from default
  6600. Ajax.prototype._loadDefaultConfig = function (force) {
  6601. var self = this;
  6602. if (!self.config || force) {
  6603. self.config = {};
  6604. //load base config from defaults
  6605. for (var key in self.defaultConfig) {
  6606. self.config[key] = self.defaultConfig[key];
  6607. }
  6608. }
  6609. };
  6610. //set request url
  6611. Ajax.prototype.setUrl = function (url) {
  6612. this.url = url;
  6613. };
  6614. //get request url
  6615. Ajax.prototype.getUrl = function () {
  6616. return this.url;
  6617. };
  6618. //lstandard loading function
  6619. Ajax.prototype.loadData = function (inPosition, columnsChanged) {
  6620. var self = this;
  6621. if (this.progressiveLoad) {
  6622. return this._loadDataProgressive();
  6623. } else {
  6624. return this._loadDataStandard(inPosition, columnsChanged);
  6625. }
  6626. };
  6627. Ajax.prototype.nextPage = function (diff) {
  6628. var margin;
  6629. if (!this.loading) {
  6630. margin = this.table.options.ajaxProgressiveLoadScrollMargin || this.table.rowManager.getElement().clientHeight * 2;
  6631. if (diff < margin) {
  6632. this.table.modules.page.nextPage().then(function () {}).catch(function () {});
  6633. }
  6634. }
  6635. };
  6636. Ajax.prototype.blockActiveRequest = function () {
  6637. this.requestOrder++;
  6638. };
  6639. Ajax.prototype._loadDataProgressive = function () {
  6640. this.table.rowManager.setData([]);
  6641. return this.table.modules.page.setPage(1);
  6642. };
  6643. Ajax.prototype._loadDataStandard = function (inPosition, columnsChanged) {
  6644. var _this33 = this;
  6645. return new Promise(function (resolve, reject) {
  6646. _this33.sendRequest(inPosition).then(function (data) {
  6647. _this33.table.rowManager.setData(data, inPosition, columnsChanged).then(function () {
  6648. resolve();
  6649. }).catch(function (e) {
  6650. reject(e);
  6651. });
  6652. }).catch(function (e) {
  6653. reject(e);
  6654. });
  6655. });
  6656. };
  6657. Ajax.prototype.generateParamsList = function (data, prefix) {
  6658. var self = this,
  6659. output = [];
  6660. prefix = prefix || "";
  6661. if (Array.isArray(data)) {
  6662. data.forEach(function (item, i) {
  6663. output = output.concat(self.generateParamsList(item, prefix ? prefix + "[" + i + "]" : i));
  6664. });
  6665. } else if ((typeof data === 'undefined' ? 'undefined' : _typeof(data)) === "object") {
  6666. for (var key in data) {
  6667. output = output.concat(self.generateParamsList(data[key], prefix ? prefix + "[" + key + "]" : key));
  6668. }
  6669. } else {
  6670. output.push({ key: prefix, value: data });
  6671. }
  6672. return output;
  6673. };
  6674. Ajax.prototype.serializeParams = function (params) {
  6675. var output = this.generateParamsList(params),
  6676. encoded = [];
  6677. output.forEach(function (item) {
  6678. encoded.push(encodeURIComponent(item.key) + "=" + encodeURIComponent(item.value));
  6679. });
  6680. return encoded.join("&");
  6681. };
  6682. //send ajax request
  6683. Ajax.prototype.sendRequest = function (silent) {
  6684. var _this34 = this;
  6685. var self = this,
  6686. url = self.url,
  6687. requestNo,
  6688. esc,
  6689. query;
  6690. self.requestOrder++;
  6691. requestNo = self.requestOrder;
  6692. self._loadDefaultConfig();
  6693. return new Promise(function (resolve, reject) {
  6694. if (self.table.options.ajaxRequesting.call(_this34.table, self.url, self.params) !== false) {
  6695. self.loading = true;
  6696. if (!silent) {
  6697. self.showLoader();
  6698. }
  6699. _this34.loaderPromise(url, self.config, self.params).then(function (data) {
  6700. if (requestNo === self.requestOrder) {
  6701. if (self.table.options.ajaxResponse) {
  6702. data = self.table.options.ajaxResponse.call(self.table, self.url, self.params, data);
  6703. }
  6704. resolve(data);
  6705. self.hideLoader();
  6706. self.loading = false;
  6707. } else {
  6708. console.warn("Ajax Response Blocked - An active ajax request was blocked by an attempt to change table data while the request was being made");
  6709. }
  6710. }).catch(function (error) {
  6711. console.error("Ajax Load Error: ", error);
  6712. self.table.options.ajaxError.call(self.table, error);
  6713. self.showError();
  6714. setTimeout(function () {
  6715. self.hideLoader();
  6716. }, 3000);
  6717. self.loading = false;
  6718. reject();
  6719. });
  6720. } else {
  6721. reject();
  6722. }
  6723. });
  6724. };
  6725. Ajax.prototype.showLoader = function () {
  6726. var shouldLoad = typeof this.table.options.ajaxLoader === "function" ? this.table.options.ajaxLoader() : this.table.options.ajaxLoader;
  6727. if (shouldLoad) {
  6728. this.hideLoader();
  6729. while (this.msgElement.firstChild) {
  6730. this.msgElement.removeChild(this.msgElement.firstChild);
  6731. }this.msgElement.classList.remove("tabulator-error");
  6732. this.msgElement.classList.add("tabulator-loading");
  6733. if (this.loadingElement) {
  6734. this.msgElement.appendChild(this.loadingElement);
  6735. } else {
  6736. this.msgElement.innerHTML = this.table.modules.localize.getText("ajax|loading");
  6737. }
  6738. this.table.element.appendChild(this.loaderElement);
  6739. }
  6740. };
  6741. Ajax.prototype.showError = function () {
  6742. this.hideLoader();
  6743. while (this.msgElement.firstChild) {
  6744. this.msgElement.removeChild(this.msgElement.firstChild);
  6745. }this.msgElement.classList.remove("tabulator-loading");
  6746. this.msgElement.classList.add("tabulator-error");
  6747. if (this.errorElement) {
  6748. this.msgElement.appendChild(this.errorElement);
  6749. } else {
  6750. this.msgElement.innerHTML = this.table.modules.localize.getText("ajax|error");
  6751. }
  6752. this.table.element.appendChild(this.loaderElement);
  6753. };
  6754. Ajax.prototype.hideLoader = function () {
  6755. if (this.loaderElement.parentNode) {
  6756. this.loaderElement.parentNode.removeChild(this.loaderElement);
  6757. }
  6758. };
  6759. //default ajax config object
  6760. Ajax.prototype.defaultConfig = {
  6761. method: "GET"
  6762. };
  6763. Ajax.prototype.defaultURLGenerator = function (url, config, params) {
  6764. if (url) {
  6765. if (params && Object.keys(params).length) {
  6766. if (!config.method || config.method.toLowerCase() == "get") {
  6767. config.method = "get";
  6768. url += (url.includes("?") ? "&" : "?") + this.serializeParams(params);
  6769. }
  6770. }
  6771. }
  6772. return url;
  6773. };
  6774. Ajax.prototype.defaultLoaderPromise = function (url, config, params) {
  6775. var self = this,
  6776. contentType;
  6777. return new Promise(function (resolve, reject) {
  6778. //set url
  6779. url = self.urlGenerator(url, config, params);
  6780. //set body content if not GET request
  6781. if (config.method.toUpperCase() != "GET") {
  6782. contentType = _typeof(self.table.options.ajaxContentType) === "object" ? self.table.options.ajaxContentType : self.contentTypeFormatters[self.table.options.ajaxContentType];
  6783. if (contentType) {
  6784. for (var key in contentType.headers) {
  6785. if (!config.headers) {
  6786. config.headers = {};
  6787. }
  6788. if (typeof config.headers[key] === "undefined") {
  6789. config.headers[key] = contentType.headers[key];
  6790. }
  6791. }
  6792. config.body = contentType.body.call(self, url, config, params);
  6793. } else {
  6794. console.warn("Ajax Error - Invalid ajaxContentType value:", self.table.options.ajaxContentType);
  6795. }
  6796. }
  6797. if (url) {
  6798. //configure headers
  6799. if (typeof config.headers === "undefined") {
  6800. config.headers = {};
  6801. }
  6802. if (typeof config.headers.Accept === "undefined") {
  6803. config.headers.Accept = "application/json";
  6804. }
  6805. if (typeof config.headers["X-Requested-With"] === "undefined") {
  6806. config.headers["X-Requested-With"] = "XMLHttpRequest";
  6807. }
  6808. if (typeof config.mode === "undefined") {
  6809. config.mode = "cors";
  6810. }
  6811. if (config.mode == "cors") {
  6812. if (typeof config.headers["Access-Control-Allow-Origin"] === "undefined") {
  6813. config.headers["Access-Control-Allow-Origin"] = window.location.origin;
  6814. }
  6815. if (typeof config.credentials === "undefined") {
  6816. config.credentials = 'same-origin';
  6817. }
  6818. } else {
  6819. if (typeof config.credentials === "undefined") {
  6820. config.credentials = 'include';
  6821. }
  6822. }
  6823. //send request
  6824. fetch(url, config).then(function (response) {
  6825. if (response.ok) {
  6826. response.json().then(function (data) {
  6827. resolve(data);
  6828. }).catch(function (error) {
  6829. reject(error);
  6830. console.warn("Ajax Load Error - Invalid JSON returned", error);
  6831. });
  6832. } else {
  6833. console.error("Ajax Load Error - Connection Error: " + response.status, response.statusText);
  6834. reject(response);
  6835. }
  6836. }).catch(function (error) {
  6837. console.error("Ajax Load Error - Connection Error: ", error);
  6838. reject(error);
  6839. });
  6840. } else {
  6841. console.warn("Ajax Load Error - No URL Set");
  6842. resolve([]);
  6843. }
  6844. });
  6845. };
  6846. Ajax.prototype.contentTypeFormatters = {
  6847. "json": {
  6848. headers: {
  6849. 'Content-Type': 'application/json'
  6850. },
  6851. body: function body(url, config, params) {
  6852. return JSON.stringify(params);
  6853. }
  6854. },
  6855. "form": {
  6856. headers: {},
  6857. body: function body(url, config, params) {
  6858. var output = this.generateParamsList(params),
  6859. form = new FormData();
  6860. output.forEach(function (item) {
  6861. form.append(item.key, item.value);
  6862. });
  6863. return form;
  6864. }
  6865. }
  6866. };
  6867. Tabulator.prototype.registerModule("ajax", Ajax);
  6868. var ColumnCalcs = function ColumnCalcs(table) {
  6869. this.table = table; //hold Tabulator object
  6870. this.topCalcs = [];
  6871. this.botCalcs = [];
  6872. this.genColumn = false;
  6873. this.topElement = this.createElement();
  6874. this.botElement = this.createElement();
  6875. this.topRow = false;
  6876. this.botRow = false;
  6877. this.topInitialized = false;
  6878. this.botInitialized = false;
  6879. this.initialize();
  6880. };
  6881. ColumnCalcs.prototype.createElement = function () {
  6882. var el = document.createElement("div");
  6883. el.classList.add("tabulator-calcs-holder");
  6884. return el;
  6885. };
  6886. ColumnCalcs.prototype.initialize = function () {
  6887. this.genColumn = new Column({ field: "value" }, this);
  6888. };
  6889. //dummy functions to handle being mock column manager
  6890. ColumnCalcs.prototype.registerColumnField = function () {};
  6891. //initialize column calcs
  6892. ColumnCalcs.prototype.initializeColumn = function (column) {
  6893. var def = column.definition;
  6894. var config = {
  6895. topCalcParams: def.topCalcParams || {},
  6896. botCalcParams: def.bottomCalcParams || {}
  6897. };
  6898. if (def.topCalc) {
  6899. switch (_typeof(def.topCalc)) {
  6900. case "string":
  6901. if (this.calculations[def.topCalc]) {
  6902. config.topCalc = this.calculations[def.topCalc];
  6903. } else {
  6904. console.warn("Column Calc Error - No such calculation found, ignoring: ", def.topCalc);
  6905. }
  6906. break;
  6907. case "function":
  6908. config.topCalc = def.topCalc;
  6909. break;
  6910. }
  6911. if (config.topCalc) {
  6912. column.modules.columnCalcs = config;
  6913. this.topCalcs.push(column);
  6914. if (this.table.options.columnCalcs != "group") {
  6915. this.initializeTopRow();
  6916. }
  6917. }
  6918. }
  6919. if (def.bottomCalc) {
  6920. switch (_typeof(def.bottomCalc)) {
  6921. case "string":
  6922. if (this.calculations[def.bottomCalc]) {
  6923. config.botCalc = this.calculations[def.bottomCalc];
  6924. } else {
  6925. console.warn("Column Calc Error - No such calculation found, ignoring: ", def.bottomCalc);
  6926. }
  6927. break;
  6928. case "function":
  6929. config.botCalc = def.bottomCalc;
  6930. break;
  6931. }
  6932. if (config.botCalc) {
  6933. column.modules.columnCalcs = config;
  6934. this.botCalcs.push(column);
  6935. if (this.table.options.columnCalcs != "group") {
  6936. this.initializeBottomRow();
  6937. }
  6938. }
  6939. }
  6940. };
  6941. ColumnCalcs.prototype.removeCalcs = function () {
  6942. var changed = false;
  6943. if (this.topInitialized) {
  6944. this.topInitialized = false;
  6945. this.topElement.parentNode.removeChild(this.topElement);
  6946. changed = true;
  6947. }
  6948. if (this.botInitialized) {
  6949. this.botInitialized = false;
  6950. this.table.footerManager.remove(this.botElement);
  6951. changed = true;
  6952. }
  6953. if (changed) {
  6954. this.table.rowManager.adjustTableSize();
  6955. }
  6956. };
  6957. ColumnCalcs.prototype.initializeTopRow = function () {
  6958. if (!this.topInitialized) {
  6959. // this.table.columnManager.headersElement.after(this.topElement);
  6960. this.table.columnManager.getElement().insertBefore(this.topElement, this.table.columnManager.headersElement.nextSibling);
  6961. this.topInitialized = true;
  6962. }
  6963. };
  6964. ColumnCalcs.prototype.initializeBottomRow = function () {
  6965. if (!this.botInitialized) {
  6966. this.table.footerManager.prepend(this.botElement);
  6967. this.botInitialized = true;
  6968. }
  6969. };
  6970. ColumnCalcs.prototype.scrollHorizontal = function (left) {
  6971. var hozAdjust = 0,
  6972. scrollWidth = this.table.columnManager.getElement().scrollWidth - this.table.element.clientWidth;
  6973. if (this.botInitialized) {
  6974. this.botRow.getElement().style.marginLeft = -left + "px";
  6975. }
  6976. };
  6977. ColumnCalcs.prototype.recalc = function (rows) {
  6978. var data, row;
  6979. if (this.topInitialized || this.botInitialized) {
  6980. data = this.rowsToData(rows);
  6981. if (this.topInitialized) {
  6982. if (this.topRow) {
  6983. this.topRow.deleteCells();
  6984. }
  6985. row = this.generateRow("top", this.rowsToData(rows));
  6986. this.topRow = row;
  6987. while (this.topElement.firstChild) {
  6988. this.topElement.removeChild(this.topElement.firstChild);
  6989. }this.topElement.appendChild(row.getElement());
  6990. row.initialize(true);
  6991. }
  6992. if (this.botInitialized) {
  6993. if (this.botRow) {
  6994. this.botRow.deleteCells();
  6995. }
  6996. row = this.generateRow("bottom", this.rowsToData(rows));
  6997. this.botRow = row;
  6998. while (this.botElement.firstChild) {
  6999. this.botElement.removeChild(this.botElement.firstChild);
  7000. }this.botElement.appendChild(row.getElement());
  7001. row.initialize(true);
  7002. }
  7003. this.table.rowManager.adjustTableSize();
  7004. //set resizable handles
  7005. if (this.table.modExists("frozenColumns")) {
  7006. this.table.modules.frozenColumns.layout();
  7007. }
  7008. }
  7009. };
  7010. ColumnCalcs.prototype.recalcRowGroup = function (row) {
  7011. this.recalcGroup(this.table.modules.groupRows.getRowGroup(row));
  7012. };
  7013. ColumnCalcs.prototype.recalcAll = function () {
  7014. var _this35 = this;
  7015. if (this.topCalcs.length || this.botCalcs.length) {
  7016. if (this.table.options.columnCalcs !== "group") {
  7017. this.recalc(this.table.rowManager.activeRows);
  7018. }
  7019. if (this.table.options.groupBy && this.table.options.columnCalcs !== "table") {
  7020. var groups = table.modules.groupRows.getChildGroups();
  7021. groups.forEach(function (group) {
  7022. _this35.recalcGroup(group);
  7023. });
  7024. }
  7025. }
  7026. };
  7027. ColumnCalcs.prototype.recalcGroup = function (group) {
  7028. var data, rowData;
  7029. if (group) {
  7030. if (group.calcs) {
  7031. if (group.calcs.bottom) {
  7032. data = this.rowsToData(group.rows);
  7033. rowData = this.generateRowData("bottom", data);
  7034. group.calcs.bottom.updateData(rowData);
  7035. group.calcs.bottom.reinitialize();
  7036. }
  7037. if (group.calcs.top) {
  7038. data = this.rowsToData(group.rows);
  7039. rowData = this.generateRowData("top", data);
  7040. group.calcs.top.updateData(rowData);
  7041. group.calcs.top.reinitialize();
  7042. }
  7043. }
  7044. }
  7045. };
  7046. //generate top stats row
  7047. ColumnCalcs.prototype.generateTopRow = function (rows) {
  7048. return this.generateRow("top", this.rowsToData(rows));
  7049. };
  7050. //generate bottom stats row
  7051. ColumnCalcs.prototype.generateBottomRow = function (rows) {
  7052. return this.generateRow("bottom", this.rowsToData(rows));
  7053. };
  7054. ColumnCalcs.prototype.rowsToData = function (rows) {
  7055. var _this36 = this;
  7056. var data = [];
  7057. rows.forEach(function (row) {
  7058. data.push(row.getData());
  7059. if (_this36.table.options.dataTree && _this36.table.options.dataTreeChildColumnCalcs) {
  7060. if (row.modules.dataTree.open) {
  7061. var children = _this36.rowsToData(_this36.table.modules.dataTree.getFilteredTreeChildren(row));
  7062. data = data.concat(children);
  7063. }
  7064. }
  7065. });
  7066. return data;
  7067. };
  7068. //generate stats row
  7069. ColumnCalcs.prototype.generateRow = function (pos, data) {
  7070. var self = this,
  7071. rowData = this.generateRowData(pos, data),
  7072. row;
  7073. if (self.table.modExists("mutator")) {
  7074. self.table.modules.mutator.disable();
  7075. }
  7076. row = new Row(rowData, this, "calc");
  7077. if (self.table.modExists("mutator")) {
  7078. self.table.modules.mutator.enable();
  7079. }
  7080. row.getElement().classList.add("tabulator-calcs", "tabulator-calcs-" + pos);
  7081. row.generateCells = function () {
  7082. var cells = [];
  7083. self.table.columnManager.columnsByIndex.forEach(function (column) {
  7084. //set field name of mock column
  7085. self.genColumn.setField(column.getField());
  7086. self.genColumn.hozAlign = column.hozAlign;
  7087. if (column.definition[pos + "CalcFormatter"] && self.table.modExists("format")) {
  7088. self.genColumn.modules.format = {
  7089. formatter: self.table.modules.format.getFormatter(column.definition[pos + "CalcFormatter"]),
  7090. params: column.definition[pos + "CalcFormatterParams"]
  7091. };
  7092. } else {
  7093. self.genColumn.modules.format = {
  7094. formatter: self.table.modules.format.getFormatter("plaintext"),
  7095. params: {}
  7096. };
  7097. }
  7098. //ensure css class defintion is replicated to calculation cell
  7099. self.genColumn.definition.cssClass = column.definition.cssClass;
  7100. //generate cell and assign to correct column
  7101. var cell = new Cell(self.genColumn, row);
  7102. cell.column = column;
  7103. cell.setWidth();
  7104. column.cells.push(cell);
  7105. cells.push(cell);
  7106. if (!column.visible) {
  7107. cell.hide();
  7108. }
  7109. });
  7110. this.cells = cells;
  7111. };
  7112. return row;
  7113. };
  7114. //generate stats row
  7115. ColumnCalcs.prototype.generateRowData = function (pos, data) {
  7116. var rowData = {},
  7117. calcs = pos == "top" ? this.topCalcs : this.botCalcs,
  7118. type = pos == "top" ? "topCalc" : "botCalc",
  7119. params,
  7120. paramKey;
  7121. calcs.forEach(function (column) {
  7122. var values = [];
  7123. if (column.modules.columnCalcs && column.modules.columnCalcs[type]) {
  7124. data.forEach(function (item) {
  7125. values.push(column.getFieldValue(item));
  7126. });
  7127. paramKey = type + "Params";
  7128. params = typeof column.modules.columnCalcs[paramKey] === "function" ? column.modules.columnCalcs[paramKey](values, data) : column.modules.columnCalcs[paramKey];
  7129. column.setFieldValue(rowData, column.modules.columnCalcs[type](values, data, params));
  7130. }
  7131. });
  7132. return rowData;
  7133. };
  7134. ColumnCalcs.prototype.hasTopCalcs = function () {
  7135. return !!this.topCalcs.length;
  7136. };
  7137. ColumnCalcs.prototype.hasBottomCalcs = function () {
  7138. return !!this.botCalcs.length;
  7139. };
  7140. //handle table redraw
  7141. ColumnCalcs.prototype.redraw = function () {
  7142. if (this.topRow) {
  7143. this.topRow.normalizeHeight(true);
  7144. }
  7145. if (this.botRow) {
  7146. this.botRow.normalizeHeight(true);
  7147. }
  7148. };
  7149. //return the calculated
  7150. ColumnCalcs.prototype.getResults = function () {
  7151. var self = this,
  7152. results = {},
  7153. groups;
  7154. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  7155. groups = this.table.modules.groupRows.getGroups(true);
  7156. groups.forEach(function (group) {
  7157. results[group.getKey()] = self.getGroupResults(group);
  7158. });
  7159. } else {
  7160. results = {
  7161. top: this.topRow ? this.topRow.getData() : {},
  7162. bottom: this.botRow ? this.botRow.getData() : {}
  7163. };
  7164. }
  7165. return results;
  7166. };
  7167. //get results from a group
  7168. ColumnCalcs.prototype.getGroupResults = function (group) {
  7169. var self = this,
  7170. groupObj = group._getSelf(),
  7171. subGroups = group.getSubGroups(),
  7172. subGroupResults = {},
  7173. results = {};
  7174. subGroups.forEach(function (subgroup) {
  7175. subGroupResults[subgroup.getKey()] = self.getGroupResults(subgroup);
  7176. });
  7177. results = {
  7178. top: groupObj.calcs.top ? groupObj.calcs.top.getData() : {},
  7179. bottom: groupObj.calcs.bottom ? groupObj.calcs.bottom.getData() : {},
  7180. groups: subGroupResults
  7181. };
  7182. return results;
  7183. };
  7184. //default calculations
  7185. ColumnCalcs.prototype.calculations = {
  7186. "avg": function avg(values, data, calcParams) {
  7187. var output = 0,
  7188. precision = typeof calcParams.precision !== "undefined" ? calcParams.precision : 2;
  7189. if (values.length) {
  7190. output = values.reduce(function (sum, value) {
  7191. value = Number(value);
  7192. return sum + value;
  7193. });
  7194. output = output / values.length;
  7195. output = precision !== false ? output.toFixed(precision) : output;
  7196. }
  7197. return parseFloat(output).toString();
  7198. },
  7199. "max": function max(values, data, calcParams) {
  7200. var output = null,
  7201. precision = typeof calcParams.precision !== "undefined" ? calcParams.precision : false;
  7202. values.forEach(function (value) {
  7203. value = Number(value);
  7204. if (value > output || output === null) {
  7205. output = value;
  7206. }
  7207. });
  7208. return output !== null ? precision !== false ? output.toFixed(precision) : output : "";
  7209. },
  7210. "min": function min(values, data, calcParams) {
  7211. var output = null,
  7212. precision = typeof calcParams.precision !== "undefined" ? calcParams.precision : false;
  7213. values.forEach(function (value) {
  7214. value = Number(value);
  7215. if (value < output || output === null) {
  7216. output = value;
  7217. }
  7218. });
  7219. return output !== null ? precision !== false ? output.toFixed(precision) : output : "";
  7220. },
  7221. "sum": function sum(values, data, calcParams) {
  7222. var output = 0,
  7223. precision = typeof calcParams.precision !== "undefined" ? calcParams.precision : false;
  7224. if (values.length) {
  7225. values.forEach(function (value) {
  7226. value = Number(value);
  7227. output += !isNaN(value) ? Number(value) : 0;
  7228. });
  7229. }
  7230. return precision !== false ? output.toFixed(precision) : output;
  7231. },
  7232. "concat": function concat(values, data, calcParams) {
  7233. var output = 0;
  7234. if (values.length) {
  7235. output = values.reduce(function (sum, value) {
  7236. return String(sum) + String(value);
  7237. });
  7238. }
  7239. return output;
  7240. },
  7241. "count": function count(values, data, calcParams) {
  7242. var output = 0;
  7243. if (values.length) {
  7244. values.forEach(function (value) {
  7245. if (value) {
  7246. output++;
  7247. }
  7248. });
  7249. }
  7250. return output;
  7251. }
  7252. };
  7253. Tabulator.prototype.registerModule("columnCalcs", ColumnCalcs);
  7254. var Clipboard = function Clipboard(table) {
  7255. this.table = table;
  7256. this.mode = true;
  7257. this.pasteParser = function () {};
  7258. this.pasteAction = function () {};
  7259. this.customSelection = false;
  7260. this.rowRange = false;
  7261. this.blocked = true; //block copy actions not originating from this command
  7262. };
  7263. Clipboard.prototype.initialize = function () {
  7264. var _this37 = this;
  7265. this.mode = this.table.options.clipboard;
  7266. this.rowRange = this.table.options.clipboardCopyRowRange;
  7267. if (this.mode === true || this.mode === "copy") {
  7268. this.table.element.addEventListener("copy", function (e) {
  7269. var plain, html;
  7270. if (!_this37.blocked) {
  7271. e.preventDefault();
  7272. if (_this37.customSelection) {
  7273. plain = _this37.customSelection;
  7274. if (_this37.table.options.clipboardCopyFormatter) {
  7275. plain = _this37.table.options.clipboardCopyFormatter("plain", plain);
  7276. }
  7277. } else {
  7278. html = _this37.table.modules.export.getHtml(_this37.rowRange, _this37.table.options.clipboardCopyStyled, _this37.table.options.clipboardCopyConfig, "clipboard");
  7279. plain = html ? _this37.generatePlainContent(html) : "";
  7280. if (_this37.table.options.clipboardCopyFormatter) {
  7281. plain = _this37.table.options.clipboardCopyFormatter("plain", plain);
  7282. html = _this37.table.options.clipboardCopyFormatter("html", html);
  7283. }
  7284. }
  7285. if (window.clipboardData && window.clipboardData.setData) {
  7286. window.clipboardData.setData('Text', plain);
  7287. } else if (e.clipboardData && e.clipboardData.setData) {
  7288. e.clipboardData.setData('text/plain', plain);
  7289. if (html) {
  7290. e.clipboardData.setData('text/html', html);
  7291. }
  7292. } else if (e.originalEvent && e.originalEvent.clipboardData.setData) {
  7293. e.originalEvent.clipboardData.setData('text/plain', plain);
  7294. if (html) {
  7295. e.originalEvent.clipboardData.setData('text/html', html);
  7296. }
  7297. }
  7298. _this37.table.options.clipboardCopied.call(_this37.table, plain, html);
  7299. _this37.reset();
  7300. }
  7301. });
  7302. }
  7303. if (this.mode === true || this.mode === "paste") {
  7304. this.table.element.addEventListener("paste", function (e) {
  7305. _this37.paste(e);
  7306. });
  7307. }
  7308. this.setPasteParser(this.table.options.clipboardPasteParser);
  7309. this.setPasteAction(this.table.options.clipboardPasteAction);
  7310. };
  7311. Clipboard.prototype.reset = function () {
  7312. this.blocked = false;
  7313. this.originalSelectionText = "";
  7314. };
  7315. Clipboard.prototype.generatePlainContent = function (html) {
  7316. var output = [];
  7317. var holder = document.createElement("div");
  7318. holder.innerHTML = html;
  7319. var table = holder.getElementsByTagName("table")[0];
  7320. var rows = Array.prototype.slice.call(table.getElementsByTagName("tr"));
  7321. rows.forEach(function (row) {
  7322. var rowData = [];
  7323. var headers = Array.prototype.slice.call(row.getElementsByTagName("th"));
  7324. var cells = Array.prototype.slice.call(row.getElementsByTagName("td"));
  7325. cells = cells.concat(headers);
  7326. cells.forEach(function (cell) {
  7327. var val = cell.innerHTML;
  7328. val = val == "&nbsp;" ? "" : val;
  7329. rowData.push(val);
  7330. });
  7331. output.push(rowData.join("\t"));
  7332. });
  7333. return output.join("\n");
  7334. };
  7335. Clipboard.prototype.copy = function (range, internal) {
  7336. var range, sel, textRange;
  7337. this.blocked = false;
  7338. this.customSelection = false;
  7339. if (this.mode === true || this.mode === "copy") {
  7340. this.rowRange = range || this.table.options.clipboardCopyRowRange;
  7341. if (typeof window.getSelection != "undefined" && typeof document.createRange != "undefined") {
  7342. range = document.createRange();
  7343. range.selectNodeContents(this.table.element);
  7344. sel = window.getSelection();
  7345. if (sel.toString() && internal) {
  7346. this.customSelection = sel.toString();
  7347. }
  7348. sel.removeAllRanges();
  7349. sel.addRange(range);
  7350. } else if (typeof document.selection != "undefined" && typeof document.body.createTextRange != "undefined") {
  7351. textRange = document.body.createTextRange();
  7352. textRange.moveToElementText(this.table.element);
  7353. textRange.select();
  7354. }
  7355. document.execCommand('copy');
  7356. if (sel) {
  7357. sel.removeAllRanges();
  7358. }
  7359. }
  7360. };
  7361. //PASTE EVENT HANDLING
  7362. Clipboard.prototype.setPasteAction = function (action) {
  7363. switch (typeof action === 'undefined' ? 'undefined' : _typeof(action)) {
  7364. case "string":
  7365. this.pasteAction = this.pasteActions[action];
  7366. if (!this.pasteAction) {
  7367. console.warn("Clipboard Error - No such paste action found:", action);
  7368. }
  7369. break;
  7370. case "function":
  7371. this.pasteAction = action;
  7372. break;
  7373. }
  7374. };
  7375. Clipboard.prototype.setPasteParser = function (parser) {
  7376. switch (typeof parser === 'undefined' ? 'undefined' : _typeof(parser)) {
  7377. case "string":
  7378. this.pasteParser = this.pasteParsers[parser];
  7379. if (!this.pasteParser) {
  7380. console.warn("Clipboard Error - No such paste parser found:", parser);
  7381. }
  7382. break;
  7383. case "function":
  7384. this.pasteParser = parser;
  7385. break;
  7386. }
  7387. };
  7388. Clipboard.prototype.paste = function (e) {
  7389. var data, rowData, rows;
  7390. if (this.checkPaseOrigin(e)) {
  7391. data = this.getPasteData(e);
  7392. rowData = this.pasteParser.call(this, data);
  7393. if (rowData) {
  7394. e.preventDefault();
  7395. if (this.table.modExists("mutator")) {
  7396. rowData = this.mutateData(rowData);
  7397. }
  7398. rows = this.pasteAction.call(this, rowData);
  7399. this.table.options.clipboardPasted.call(this.table, data, rowData, rows);
  7400. } else {
  7401. this.table.options.clipboardPasteError.call(this.table, data);
  7402. }
  7403. }
  7404. };
  7405. Clipboard.prototype.mutateData = function (data) {
  7406. var self = this,
  7407. output = [];
  7408. if (Array.isArray(data)) {
  7409. data.forEach(function (row) {
  7410. output.push(self.table.modules.mutator.transformRow(row, "clipboard"));
  7411. });
  7412. } else {
  7413. output = data;
  7414. }
  7415. return output;
  7416. };
  7417. Clipboard.prototype.checkPaseOrigin = function (e) {
  7418. var valid = true;
  7419. if (e.target.tagName != "DIV" || this.table.modules.edit.currentCell) {
  7420. valid = false;
  7421. }
  7422. return valid;
  7423. };
  7424. Clipboard.prototype.getPasteData = function (e) {
  7425. var data;
  7426. if (window.clipboardData && window.clipboardData.getData) {
  7427. data = window.clipboardData.getData('Text');
  7428. } else if (e.clipboardData && e.clipboardData.getData) {
  7429. data = e.clipboardData.getData('text/plain');
  7430. } else if (e.originalEvent && e.originalEvent.clipboardData.getData) {
  7431. data = e.originalEvent.clipboardData.getData('text/plain');
  7432. }
  7433. return data;
  7434. };
  7435. Clipboard.prototype.pasteParsers = {
  7436. table: function table(clipboard) {
  7437. var data = [],
  7438. success = false,
  7439. headerFindSuccess = true,
  7440. columns = this.table.columnManager.columns,
  7441. columnMap = [],
  7442. rows = [];
  7443. //get data from clipboard into array of columns and rows.
  7444. clipboard = clipboard.split("\n");
  7445. clipboard.forEach(function (row) {
  7446. data.push(row.split("\t"));
  7447. });
  7448. if (data.length && !(data.length === 1 && data[0].length < 2)) {
  7449. success = true;
  7450. //check if headers are present by title
  7451. data[0].forEach(function (value) {
  7452. var column = columns.find(function (column) {
  7453. return value && column.definition.title && value.trim() && column.definition.title.trim() === value.trim();
  7454. });
  7455. if (column) {
  7456. columnMap.push(column);
  7457. } else {
  7458. headerFindSuccess = false;
  7459. }
  7460. });
  7461. //check if column headers are present by field
  7462. if (!headerFindSuccess) {
  7463. headerFindSuccess = true;
  7464. columnMap = [];
  7465. data[0].forEach(function (value) {
  7466. var column = columns.find(function (column) {
  7467. return value && column.field && value.trim() && column.field.trim() === value.trim();
  7468. });
  7469. if (column) {
  7470. columnMap.push(column);
  7471. } else {
  7472. headerFindSuccess = false;
  7473. }
  7474. });
  7475. if (!headerFindSuccess) {
  7476. columnMap = this.table.columnManager.columnsByIndex;
  7477. }
  7478. }
  7479. //remove header row if found
  7480. if (headerFindSuccess) {
  7481. data.shift();
  7482. }
  7483. data.forEach(function (item) {
  7484. var row = {};
  7485. item.forEach(function (value, i) {
  7486. if (columnMap[i]) {
  7487. row[columnMap[i].field] = value;
  7488. }
  7489. });
  7490. rows.push(row);
  7491. });
  7492. return rows;
  7493. } else {
  7494. return false;
  7495. }
  7496. }
  7497. };
  7498. Clipboard.prototype.pasteActions = {
  7499. replace: function replace(rows) {
  7500. return this.table.setData(rows);
  7501. },
  7502. update: function update(rows) {
  7503. return this.table.updateOrAddData(rows);
  7504. },
  7505. insert: function insert(rows) {
  7506. return this.table.addData(rows);
  7507. }
  7508. };
  7509. Tabulator.prototype.registerModule("clipboard", Clipboard);
  7510. var DataTree = function DataTree(table) {
  7511. this.table = table;
  7512. this.indent = 10;
  7513. this.field = "";
  7514. this.collapseEl = null;
  7515. this.expandEl = null;
  7516. this.branchEl = null;
  7517. this.elementField = false;
  7518. this.startOpen = function () {};
  7519. this.displayIndex = 0;
  7520. };
  7521. DataTree.prototype.initialize = function () {
  7522. var dummyEl = null,
  7523. firstCol = this.table.columnManager.getFirstVisibileColumn(),
  7524. options = this.table.options;
  7525. this.field = options.dataTreeChildField;
  7526. this.indent = options.dataTreeChildIndent;
  7527. this.elementField = options.dataTreeElementColumn || (firstCol ? firstCol.field : false);
  7528. if (options.dataTreeBranchElement) {
  7529. if (options.dataTreeBranchElement === true) {
  7530. this.branchEl = document.createElement("div");
  7531. this.branchEl.classList.add("tabulator-data-tree-branch");
  7532. } else {
  7533. if (typeof options.dataTreeBranchElement === "string") {
  7534. dummyEl = document.createElement("div");
  7535. dummyEl.innerHTML = options.dataTreeBranchElement;
  7536. this.branchEl = dummyEl.firstChild;
  7537. } else {
  7538. this.branchEl = options.dataTreeBranchElement;
  7539. }
  7540. }
  7541. }
  7542. if (options.dataTreeCollapseElement) {
  7543. if (typeof options.dataTreeCollapseElement === "string") {
  7544. dummyEl = document.createElement("div");
  7545. dummyEl.innerHTML = options.dataTreeCollapseElement;
  7546. this.collapseEl = dummyEl.firstChild;
  7547. } else {
  7548. this.collapseEl = options.dataTreeCollapseElement;
  7549. }
  7550. } else {
  7551. this.collapseEl = document.createElement("div");
  7552. this.collapseEl.classList.add("tabulator-data-tree-control");
  7553. this.collapseEl.tabIndex = 0;
  7554. this.collapseEl.innerHTML = "<div class='tabulator-data-tree-control-collapse'></div>";
  7555. }
  7556. if (options.dataTreeExpandElement) {
  7557. if (typeof options.dataTreeExpandElement === "string") {
  7558. dummyEl = document.createElement("div");
  7559. dummyEl.innerHTML = options.dataTreeExpandElement;
  7560. this.expandEl = dummyEl.firstChild;
  7561. } else {
  7562. this.expandEl = options.dataTreeExpandElement;
  7563. }
  7564. } else {
  7565. this.expandEl = document.createElement("div");
  7566. this.expandEl.classList.add("tabulator-data-tree-control");
  7567. this.expandEl.tabIndex = 0;
  7568. this.expandEl.innerHTML = "<div class='tabulator-data-tree-control-expand'></div>";
  7569. }
  7570. switch (_typeof(options.dataTreeStartExpanded)) {
  7571. case "boolean":
  7572. this.startOpen = function (row, index) {
  7573. return options.dataTreeStartExpanded;
  7574. };
  7575. break;
  7576. case "function":
  7577. this.startOpen = options.dataTreeStartExpanded;
  7578. break;
  7579. default:
  7580. this.startOpen = function (row, index) {
  7581. return options.dataTreeStartExpanded[index];
  7582. };
  7583. break;
  7584. }
  7585. };
  7586. DataTree.prototype.initializeRow = function (row) {
  7587. var childArray = row.getData()[this.field];
  7588. var isArray = Array.isArray(childArray);
  7589. var children = isArray || !isArray && (typeof childArray === 'undefined' ? 'undefined' : _typeof(childArray)) === "object" && childArray !== null;
  7590. if (!children && row.modules.dataTree && row.modules.dataTree.branchEl) {
  7591. row.modules.dataTree.branchEl.parentNode.removeChild(row.modules.dataTree.branchEl);
  7592. }
  7593. if (!children && row.modules.dataTree && row.modules.dataTree.controlEl) {
  7594. row.modules.dataTree.controlEl.parentNode.removeChild(row.modules.dataTree.controlEl);
  7595. }
  7596. row.modules.dataTree = {
  7597. index: row.modules.dataTree ? row.modules.dataTree.index : 0,
  7598. open: children ? row.modules.dataTree ? row.modules.dataTree.open : this.startOpen(row.getComponent(), 0) : false,
  7599. controlEl: row.modules.dataTree && children ? row.modules.dataTree.controlEl : false,
  7600. branchEl: row.modules.dataTree && children ? row.modules.dataTree.branchEl : false,
  7601. parent: row.modules.dataTree ? row.modules.dataTree.parent : false,
  7602. children: children
  7603. };
  7604. };
  7605. DataTree.prototype.layoutRow = function (row) {
  7606. var cell = this.elementField ? row.getCell(this.elementField) : row.getCells()[0],
  7607. el = cell.getElement(),
  7608. config = row.modules.dataTree;
  7609. if (config.branchEl) {
  7610. if (config.branchEl.parentNode) {
  7611. config.branchEl.parentNode.removeChild(config.branchEl);
  7612. }
  7613. config.branchEl = false;
  7614. }
  7615. if (config.controlEl) {
  7616. if (config.controlEl.parentNode) {
  7617. config.controlEl.parentNode.removeChild(config.controlEl);
  7618. }
  7619. config.controlEl = false;
  7620. }
  7621. this.generateControlElement(row, el);
  7622. row.element.classList.add("tabulator-tree-level-" + config.index);
  7623. if (config.index) {
  7624. if (this.branchEl) {
  7625. config.branchEl = this.branchEl.cloneNode(true);
  7626. el.insertBefore(config.branchEl, el.firstChild);
  7627. config.branchEl.style.marginLeft = (config.branchEl.offsetWidth + config.branchEl.style.marginRight) * (config.index - 1) + config.index * this.indent + "px";
  7628. } else {
  7629. el.style.paddingLeft = parseInt(window.getComputedStyle(el, null).getPropertyValue('padding-left')) + config.index * this.indent + "px";
  7630. }
  7631. }
  7632. };
  7633. DataTree.prototype.generateControlElement = function (row, el) {
  7634. var _this38 = this;
  7635. var config = row.modules.dataTree,
  7636. el = el || row.getCells()[0].getElement(),
  7637. oldControl = config.controlEl;
  7638. if (config.children !== false) {
  7639. if (config.open) {
  7640. config.controlEl = this.collapseEl.cloneNode(true);
  7641. config.controlEl.addEventListener("click", function (e) {
  7642. e.stopPropagation();
  7643. _this38.collapseRow(row);
  7644. });
  7645. } else {
  7646. config.controlEl = this.expandEl.cloneNode(true);
  7647. config.controlEl.addEventListener("click", function (e) {
  7648. e.stopPropagation();
  7649. _this38.expandRow(row);
  7650. });
  7651. }
  7652. config.controlEl.addEventListener("mousedown", function (e) {
  7653. e.stopPropagation();
  7654. });
  7655. if (oldControl && oldControl.parentNode === el) {
  7656. oldControl.parentNode.replaceChild(config.controlEl, oldControl);
  7657. } else {
  7658. el.insertBefore(config.controlEl, el.firstChild);
  7659. }
  7660. }
  7661. };
  7662. DataTree.prototype.setDisplayIndex = function (index) {
  7663. this.displayIndex = index;
  7664. };
  7665. DataTree.prototype.getDisplayIndex = function () {
  7666. return this.displayIndex;
  7667. };
  7668. DataTree.prototype.getRows = function (rows) {
  7669. var _this39 = this;
  7670. var output = [];
  7671. rows.forEach(function (row, i) {
  7672. var config, children;
  7673. output.push(row);
  7674. if (row instanceof Row) {
  7675. config = row.modules.dataTree.children;
  7676. if (!config.index && config.children !== false) {
  7677. children = _this39.getChildren(row);
  7678. children.forEach(function (child) {
  7679. output.push(child);
  7680. });
  7681. }
  7682. }
  7683. });
  7684. return output;
  7685. };
  7686. DataTree.prototype.getChildren = function (row) {
  7687. var _this40 = this;
  7688. var config = row.modules.dataTree,
  7689. children = [],
  7690. output = [];
  7691. if (config.children !== false && config.open) {
  7692. if (!Array.isArray(config.children)) {
  7693. config.children = this.generateChildren(row);
  7694. }
  7695. if (this.table.modExists("filter")) {
  7696. children = this.table.modules.filter.filter(config.children);
  7697. } else {
  7698. children = config.children;
  7699. }
  7700. if (this.table.modExists("sort")) {
  7701. this.table.modules.sort.sort(children);
  7702. }
  7703. children.forEach(function (child) {
  7704. output.push(child);
  7705. var subChildren = _this40.getChildren(child);
  7706. subChildren.forEach(function (sub) {
  7707. output.push(sub);
  7708. });
  7709. });
  7710. }
  7711. return output;
  7712. };
  7713. DataTree.prototype.generateChildren = function (row) {
  7714. var _this41 = this;
  7715. var children = [];
  7716. var childArray = row.getData()[this.field];
  7717. if (!Array.isArray(childArray)) {
  7718. childArray = [childArray];
  7719. }
  7720. childArray.forEach(function (childData) {
  7721. var childRow = new Row(childData || {}, _this41.table.rowManager);
  7722. childRow.modules.dataTree.index = row.modules.dataTree.index + 1;
  7723. childRow.modules.dataTree.parent = row;
  7724. if (childRow.modules.dataTree.children) {
  7725. childRow.modules.dataTree.open = _this41.startOpen(childRow.getComponent(), childRow.modules.dataTree.index);
  7726. }
  7727. children.push(childRow);
  7728. });
  7729. return children;
  7730. };
  7731. DataTree.prototype.expandRow = function (row, silent) {
  7732. var config = row.modules.dataTree;
  7733. if (config.children !== false) {
  7734. config.open = true;
  7735. row.reinitialize();
  7736. this.table.rowManager.refreshActiveData("tree", false, true);
  7737. this.table.options.dataTreeRowExpanded(row.getComponent(), row.modules.dataTree.index);
  7738. }
  7739. };
  7740. DataTree.prototype.collapseRow = function (row) {
  7741. var config = row.modules.dataTree;
  7742. if (config.children !== false) {
  7743. config.open = false;
  7744. row.reinitialize();
  7745. this.table.rowManager.refreshActiveData("tree", false, true);
  7746. this.table.options.dataTreeRowCollapsed(row.getComponent(), row.modules.dataTree.index);
  7747. }
  7748. };
  7749. DataTree.prototype.toggleRow = function (row) {
  7750. var config = row.modules.dataTree;
  7751. if (config.children !== false) {
  7752. if (config.open) {
  7753. this.collapseRow(row);
  7754. } else {
  7755. this.expandRow(row);
  7756. }
  7757. }
  7758. };
  7759. DataTree.prototype.getTreeParent = function (row) {
  7760. return row.modules.dataTree.parent ? row.modules.dataTree.parent.getComponent() : false;
  7761. };
  7762. DataTree.prototype.getFilteredTreeChildren = function (row) {
  7763. var config = row.modules.dataTree,
  7764. output = [],
  7765. children;
  7766. if (config.children) {
  7767. if (!Array.isArray(config.children)) {
  7768. config.children = this.generateChildren(row);
  7769. }
  7770. if (this.table.modExists("filter")) {
  7771. children = this.table.modules.filter.filter(config.children);
  7772. } else {
  7773. children = config.children;
  7774. }
  7775. children.forEach(function (childRow) {
  7776. if (childRow instanceof Row) {
  7777. output.push(childRow);
  7778. }
  7779. });
  7780. }
  7781. return output;
  7782. };
  7783. DataTree.prototype.getTreeChildren = function (row) {
  7784. var config = row.modules.dataTree,
  7785. output = [];
  7786. if (config.children) {
  7787. if (!Array.isArray(config.children)) {
  7788. config.children = this.generateChildren(row);
  7789. }
  7790. config.children.forEach(function (childRow) {
  7791. if (childRow instanceof Row) {
  7792. output.push(childRow.getComponent());
  7793. }
  7794. });
  7795. }
  7796. return output;
  7797. };
  7798. DataTree.prototype.checkForRestyle = function (cell) {
  7799. if (!cell.row.cells.indexOf(cell)) {
  7800. cell.row.reinitialize();
  7801. }
  7802. };
  7803. DataTree.prototype.getChildField = function () {
  7804. return this.field;
  7805. };
  7806. DataTree.prototype.redrawNeeded = function (data) {
  7807. return (this.field ? typeof data[this.field] !== "undefined" : false) || (this.elementField ? typeof data[this.elementField] !== "undefined" : false);
  7808. };
  7809. Tabulator.prototype.registerModule("dataTree", DataTree);
  7810. var Download = function Download(table) {
  7811. this.table = table; //hold Tabulator object
  7812. this.fields = {}; //hold filed multi dimension arrays
  7813. this.columnsByIndex = []; //hold columns in their order in the table
  7814. this.columnsByField = {}; //hold columns with lookup by field name
  7815. this.config = {};
  7816. this.active = false;
  7817. };
  7818. //trigger file download
  7819. Download.prototype.download = function (type, filename, options, active, interceptCallback) {
  7820. var self = this,
  7821. downloadFunc = false;
  7822. this.processConfig();
  7823. this.active = active;
  7824. function buildLink(data, mime) {
  7825. if (interceptCallback) {
  7826. if (interceptCallback === true) {
  7827. self.triggerDownload(data, mime, type, filename, true);
  7828. } else {
  7829. interceptCallback(data);
  7830. }
  7831. } else {
  7832. self.triggerDownload(data, mime, type, filename);
  7833. }
  7834. }
  7835. if (typeof type == "function") {
  7836. downloadFunc = type;
  7837. } else {
  7838. if (self.downloaders[type]) {
  7839. downloadFunc = self.downloaders[type];
  7840. } else {
  7841. console.warn("Download Error - No such download type found: ", type);
  7842. }
  7843. }
  7844. this.processColumns();
  7845. if (downloadFunc) {
  7846. downloadFunc.call(this, self.processDefinitions(), self.processData(active || "active"), options || {}, buildLink, this.config);
  7847. }
  7848. };
  7849. Download.prototype.processConfig = function () {
  7850. var config = { //download config
  7851. columnGroups: true,
  7852. rowGroups: true,
  7853. columnCalcs: true,
  7854. dataTree: true
  7855. };
  7856. if (this.table.options.downloadConfig) {
  7857. for (var key in this.table.options.downloadConfig) {
  7858. config[key] = this.table.options.downloadConfig[key];
  7859. }
  7860. }
  7861. this.config.rowGroups = config.rowGroups && this.table.options.groupBy && this.table.modExists("groupRows");
  7862. if (config.columnGroups && this.table.columnManager.columns.length != this.table.columnManager.columnsByIndex.length) {
  7863. this.config.columnGroups = true;
  7864. }
  7865. if (config.columnCalcs && this.table.modExists("columnCalcs")) {
  7866. this.config.columnCalcs = true;
  7867. }
  7868. if (config.dataTree && this.table.options.dataTree && this.table.modExists("dataTree")) {
  7869. this.config.dataTree = true;
  7870. }
  7871. };
  7872. Download.prototype.processColumns = function () {
  7873. var self = this;
  7874. self.columnsByIndex = [];
  7875. self.columnsByField = {};
  7876. self.table.columnManager.columnsByIndex.forEach(function (column) {
  7877. if (column.field && column.definition.download !== false && (column.visible || !column.visible && column.definition.download)) {
  7878. self.columnsByIndex.push(column);
  7879. self.columnsByField[column.field] = column;
  7880. }
  7881. });
  7882. };
  7883. Download.prototype.processDefinitions = function () {
  7884. var self = this,
  7885. processedDefinitions = [];
  7886. if (this.config.columnGroups) {
  7887. self.table.columnManager.columns.forEach(function (column) {
  7888. var colData = self.processColumnGroup(column);
  7889. if (colData) {
  7890. processedDefinitions.push(colData);
  7891. }
  7892. });
  7893. } else {
  7894. self.columnsByIndex.forEach(function (column) {
  7895. if (column.download !== false) {
  7896. //isolate definiton from defintion object
  7897. processedDefinitions.push(self.processDefinition(column));
  7898. }
  7899. });
  7900. }
  7901. return processedDefinitions;
  7902. };
  7903. Download.prototype.processColumnGroup = function (column) {
  7904. var _this42 = this;
  7905. var subGroups = column.columns,
  7906. maxDepth = 0;
  7907. var processedColumn = this.processDefinition(column);
  7908. var groupData = {
  7909. type: "group",
  7910. title: processedColumn.title,
  7911. depth: 1
  7912. };
  7913. if (subGroups.length) {
  7914. groupData.subGroups = [];
  7915. groupData.width = 0;
  7916. subGroups.forEach(function (subGroup) {
  7917. var subGroupData = _this42.processColumnGroup(subGroup);
  7918. if (subGroupData.depth > maxDepth) {
  7919. maxDepth = subGroupData.depth;
  7920. }
  7921. if (subGroupData) {
  7922. groupData.width += subGroupData.width;
  7923. groupData.subGroups.push(subGroupData);
  7924. }
  7925. });
  7926. groupData.depth += maxDepth;
  7927. if (!groupData.width) {
  7928. return false;
  7929. }
  7930. } else {
  7931. if (column.field && column.definition.download !== false && (column.visible || !column.visible && column.definition.download)) {
  7932. groupData.width = 1;
  7933. groupData.definition = processedColumn;
  7934. } else {
  7935. return false;
  7936. }
  7937. }
  7938. return groupData;
  7939. };
  7940. Download.prototype.processDefinition = function (column) {
  7941. var def = {};
  7942. for (var key in column.definition) {
  7943. def[key] = column.definition[key];
  7944. }
  7945. if (typeof column.definition.downloadTitle != "undefined") {
  7946. def.title = column.definition.downloadTitle;
  7947. }
  7948. return def;
  7949. };
  7950. Download.prototype.processData = function (active) {
  7951. var _this43 = this;
  7952. var self = this,
  7953. data = [],
  7954. groups = [],
  7955. rows = false,
  7956. calcs = {};
  7957. if (this.config.rowGroups) {
  7958. if (active == "visible") {
  7959. rows = self.table.rowManager.getRows(active);
  7960. rows.forEach(function (row) {
  7961. if (row.type == "row") {
  7962. var group = row.getGroup();
  7963. if (groups.indexOf(group) === -1) {
  7964. groups.push(group);
  7965. }
  7966. }
  7967. });
  7968. } else {
  7969. groups = this.table.modules.groupRows.getGroups();
  7970. }
  7971. groups.forEach(function (group) {
  7972. data.push(_this43.processGroupData(group, rows));
  7973. });
  7974. } else {
  7975. if (this.config.dataTree) {
  7976. active = active = "active" ? "display" : active;
  7977. }
  7978. data = self.table.rowManager.getData(active, "download");
  7979. }
  7980. if (this.config.columnCalcs) {
  7981. calcs = this.table.getCalcResults();
  7982. data = {
  7983. calcs: calcs,
  7984. data: data
  7985. };
  7986. }
  7987. //bulk data processing
  7988. if (typeof self.table.options.downloadDataFormatter == "function") {
  7989. data = self.table.options.downloadDataFormatter(data);
  7990. }
  7991. return data;
  7992. };
  7993. Download.prototype.processGroupData = function (group, visRows) {
  7994. var _this44 = this;
  7995. var subGroups = group.getSubGroups();
  7996. var groupData = {
  7997. type: "group",
  7998. key: group.key
  7999. };
  8000. if (subGroups.length) {
  8001. groupData.subGroups = [];
  8002. subGroups.forEach(function (subGroup) {
  8003. groupData.subGroups.push(_this44.processGroupData(subGroup, visRows));
  8004. });
  8005. } else {
  8006. if (visRows) {
  8007. groupData.rows = [];
  8008. group.rows.forEach(function (row) {
  8009. if (visRows.indexOf(row) > -1) {
  8010. groupData.rows.push(row.getData("download"));
  8011. }
  8012. });
  8013. } else {
  8014. groupData.rows = group.getData(true, "download");
  8015. }
  8016. }
  8017. return groupData;
  8018. };
  8019. Download.prototype.triggerDownload = function (data, mime, type, filename, newTab) {
  8020. var element = document.createElement('a'),
  8021. blob = new Blob([data], { type: mime }),
  8022. filename = filename || "Tabulator." + (typeof type === "function" ? "txt" : type);
  8023. blob = this.table.options.downloadReady.call(this.table, data, blob);
  8024. if (blob) {
  8025. if (newTab) {
  8026. window.open(window.URL.createObjectURL(blob));
  8027. } else {
  8028. if (navigator.msSaveOrOpenBlob) {
  8029. navigator.msSaveOrOpenBlob(blob, filename);
  8030. } else {
  8031. element.setAttribute('href', window.URL.createObjectURL(blob));
  8032. //set file title
  8033. element.setAttribute('download', filename);
  8034. //trigger download
  8035. element.style.display = 'none';
  8036. document.body.appendChild(element);
  8037. element.click();
  8038. //remove temporary link element
  8039. document.body.removeChild(element);
  8040. }
  8041. }
  8042. if (this.table.options.downloadComplete) {
  8043. this.table.options.downloadComplete();
  8044. }
  8045. }
  8046. };
  8047. //nested field lookup
  8048. Download.prototype.getFieldValue = function (field, data) {
  8049. var column = this.columnsByField[field];
  8050. if (column) {
  8051. return column.getFieldValue(data);
  8052. }
  8053. return false;
  8054. };
  8055. Download.prototype.commsReceived = function (table, action, data) {
  8056. switch (action) {
  8057. case "intercept":
  8058. this.download(data.type, "", data.options, data.active, data.intercept);
  8059. break;
  8060. }
  8061. };
  8062. //downloaders
  8063. Download.prototype.downloaders = {
  8064. csv: function csv(columns, data, options, setFileContents, config) {
  8065. var self = this,
  8066. titles = [],
  8067. fields = [],
  8068. delimiter = options && options.delimiter ? options.delimiter : ",",
  8069. fileContents,
  8070. output;
  8071. //build column headers
  8072. function parseSimpleTitles() {
  8073. columns.forEach(function (column) {
  8074. titles.push('"' + String(column.title).split('"').join('""') + '"');
  8075. fields.push(column.field);
  8076. });
  8077. }
  8078. function parseColumnGroup(column, level) {
  8079. if (column.subGroups) {
  8080. column.subGroups.forEach(function (subGroup) {
  8081. parseColumnGroup(subGroup, level + 1);
  8082. });
  8083. } else {
  8084. titles.push('"' + String(column.title).split('"').join('""') + '"');
  8085. fields.push(column.definition.field);
  8086. }
  8087. }
  8088. if (config.columnGroups) {
  8089. console.warn("Download Warning - CSV downloader cannot process column groups");
  8090. columns.forEach(function (column) {
  8091. parseColumnGroup(column, 0);
  8092. });
  8093. } else {
  8094. parseSimpleTitles();
  8095. }
  8096. //generate header row
  8097. fileContents = [titles.join(delimiter)];
  8098. function parseRows(data) {
  8099. //generate each row of the table
  8100. data.forEach(function (row) {
  8101. var rowData = [];
  8102. fields.forEach(function (field) {
  8103. var value = self.getFieldValue(field, row);
  8104. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  8105. case "object":
  8106. value = JSON.stringify(value);
  8107. break;
  8108. case "undefined":
  8109. case "null":
  8110. value = "";
  8111. break;
  8112. default:
  8113. value = value;
  8114. }
  8115. //escape quotation marks
  8116. rowData.push('"' + String(value).split('"').join('""') + '"');
  8117. });
  8118. fileContents.push(rowData.join(delimiter));
  8119. });
  8120. }
  8121. function parseGroup(group) {
  8122. if (group.subGroups) {
  8123. group.subGroups.forEach(function (subGroup) {
  8124. parseGroup(subGroup);
  8125. });
  8126. } else {
  8127. parseRows(group.rows);
  8128. }
  8129. }
  8130. if (config.columnCalcs) {
  8131. console.warn("Download Warning - CSV downloader cannot process column calculations");
  8132. data = data.data;
  8133. }
  8134. if (config.rowGroups) {
  8135. console.warn("Download Warning - CSV downloader cannot process row groups");
  8136. data.forEach(function (group) {
  8137. parseGroup(group);
  8138. });
  8139. } else {
  8140. parseRows(data);
  8141. }
  8142. output = fileContents.join("\n");
  8143. if (options.bom) {
  8144. output = '\uFEFF' + output;
  8145. }
  8146. setFileContents(output, "text/csv");
  8147. },
  8148. json: function json(columns, data, options, setFileContents, config) {
  8149. var fileContents;
  8150. if (config.columnCalcs) {
  8151. console.warn("Download Warning - CSV downloader cannot process column calculations");
  8152. data = data.data;
  8153. }
  8154. fileContents = JSON.stringify(data, null, '\t');
  8155. setFileContents(fileContents, "application/json");
  8156. },
  8157. pdf: function pdf(columns, data, options, setFileContents, config) {
  8158. var self = this,
  8159. fields = [],
  8160. header = [],
  8161. body = [],
  8162. calcs = {},
  8163. headerDepth = 1,
  8164. table = "",
  8165. autoTableParams = {},
  8166. rowGroupStyles = options.rowGroupStyles || {
  8167. fontStyle: "bold",
  8168. fontSize: 12,
  8169. cellPadding: 6,
  8170. fillColor: 220
  8171. },
  8172. rowCalcStyles = options.rowCalcStyles || {
  8173. fontStyle: "bold",
  8174. fontSize: 10,
  8175. cellPadding: 4,
  8176. fillColor: 232
  8177. },
  8178. jsPDFParams = options.jsPDF || {},
  8179. title = options && options.title ? options.title : "";
  8180. if (config.columnCalcs) {
  8181. calcs = data.calcs;
  8182. data = data.data;
  8183. }
  8184. if (!jsPDFParams.orientation) {
  8185. jsPDFParams.orientation = options.orientation || "landscape";
  8186. }
  8187. if (!jsPDFParams.unit) {
  8188. jsPDFParams.unit = "pt";
  8189. }
  8190. //build column headers
  8191. function parseSimpleTitles() {
  8192. columns.forEach(function (column) {
  8193. if (column.field) {
  8194. header.push(column.title || "");
  8195. fields.push(column.field);
  8196. }
  8197. });
  8198. header = [header];
  8199. }
  8200. function parseColumnGroup(column, level) {
  8201. var colSpan = column.width,
  8202. rowSpan = 1,
  8203. col = {
  8204. content: column.title || ""
  8205. };
  8206. if (column.subGroups) {
  8207. column.subGroups.forEach(function (subGroup) {
  8208. parseColumnGroup(subGroup, level + 1);
  8209. });
  8210. rowSpan = 1;
  8211. } else {
  8212. fields.push(column.definition.field);
  8213. rowSpan = headerDepth - level;
  8214. }
  8215. col.rowSpan = rowSpan;
  8216. // col.colSpan = colSpan;
  8217. header[level].push(col);
  8218. colSpan--;
  8219. if (rowSpan > 1) {
  8220. for (var i = level + 1; i < headerDepth; i++) {
  8221. header[i].push("");
  8222. }
  8223. }
  8224. for (var i = 0; i < colSpan; i++) {
  8225. header[level].push("");
  8226. }
  8227. }
  8228. if (config.columnGroups) {
  8229. columns.forEach(function (column) {
  8230. if (column.depth > headerDepth) {
  8231. headerDepth = column.depth;
  8232. }
  8233. });
  8234. for (var i = 0; i < headerDepth; i++) {
  8235. header.push([]);
  8236. }
  8237. columns.forEach(function (column) {
  8238. parseColumnGroup(column, 0);
  8239. });
  8240. } else {
  8241. parseSimpleTitles();
  8242. }
  8243. function parseValue(value) {
  8244. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  8245. case "object":
  8246. value = JSON.stringify(value);
  8247. break;
  8248. case "undefined":
  8249. case "null":
  8250. value = "";
  8251. break;
  8252. default:
  8253. value = value;
  8254. }
  8255. return value;
  8256. }
  8257. function parseRows(data) {
  8258. //build table rows
  8259. data.forEach(function (row) {
  8260. body.push(parseRow(row));
  8261. });
  8262. }
  8263. function parseRow(row, styles) {
  8264. var rowData = [];
  8265. fields.forEach(function (field) {
  8266. var value = self.getFieldValue(field, row);
  8267. value = parseValue(value);
  8268. if (styles) {
  8269. rowData.push({
  8270. content: value,
  8271. styles: styles
  8272. });
  8273. } else {
  8274. rowData.push(value);
  8275. }
  8276. });
  8277. return rowData;
  8278. }
  8279. function parseGroup(group, calcObj) {
  8280. var groupData = [];
  8281. groupData.push({ content: parseValue(group.key), colSpan: fields.length, styles: rowGroupStyles });
  8282. body.push(groupData);
  8283. if (group.subGroups) {
  8284. group.subGroups.forEach(function (subGroup) {
  8285. parseGroup(subGroup, calcObj[group.key] ? calcObj[group.key].groups || {} : {});
  8286. });
  8287. } else {
  8288. if (config.columnCalcs) {
  8289. addCalcRow(calcObj, group.key, "top");
  8290. }
  8291. parseRows(group.rows);
  8292. if (config.columnCalcs) {
  8293. addCalcRow(calcObj, group.key, "bottom");
  8294. }
  8295. }
  8296. }
  8297. function addCalcRow(calcs, selector, pos) {
  8298. var calcData = calcs[selector];
  8299. if (calcData) {
  8300. if (pos) {
  8301. calcData = calcData[pos];
  8302. }
  8303. if (Object.keys(calcData).length) {
  8304. body.push(parseRow(calcData, rowCalcStyles));
  8305. }
  8306. }
  8307. }
  8308. if (config.rowGroups) {
  8309. data.forEach(function (group) {
  8310. parseGroup(group, calcs);
  8311. });
  8312. } else {
  8313. if (config.columnCalcs) {
  8314. addCalcRow(calcs, "top");
  8315. }
  8316. parseRows(data);
  8317. if (config.columnCalcs) {
  8318. addCalcRow(calcs, "bottom");
  8319. }
  8320. }
  8321. var doc = new jsPDF(jsPDFParams); //set document to landscape, better for most tables
  8322. if (options && options.autoTable) {
  8323. if (typeof options.autoTable === "function") {
  8324. autoTableParams = options.autoTable(doc) || {};
  8325. } else {
  8326. autoTableParams = options.autoTable;
  8327. }
  8328. }
  8329. if (title) {
  8330. autoTableParams.addPageContent = function (data) {
  8331. doc.text(title, 40, 30);
  8332. };
  8333. }
  8334. autoTableParams.head = header;
  8335. autoTableParams.body = body;
  8336. doc.autoTable(autoTableParams);
  8337. if (options && options.documentProcessing) {
  8338. options.documentProcessing(doc);
  8339. }
  8340. setFileContents(doc.output("arraybuffer"), "application/pdf");
  8341. },
  8342. xlsx: function xlsx(columns, data, options, setFileContents, config) {
  8343. var self = this,
  8344. sheetName = options.sheetName || "Sheet1",
  8345. workbook = XLSX.utils.book_new(),
  8346. calcs = {},
  8347. groupRowIndexs = [],
  8348. groupColumnIndexs = [],
  8349. calcRowIndexs = [],
  8350. output;
  8351. workbook.SheetNames = [];
  8352. workbook.Sheets = {};
  8353. if (config.columnCalcs) {
  8354. calcs = data.calcs;
  8355. data = data.data;
  8356. }
  8357. function generateSheet() {
  8358. var titles = [],
  8359. fields = [],
  8360. rows = [],
  8361. worksheet;
  8362. //convert rows to worksheet
  8363. function rowsToSheet() {
  8364. var sheet = {};
  8365. var range = { s: { c: 0, r: 0 }, e: { c: fields.length, r: rows.length } };
  8366. XLSX.utils.sheet_add_aoa(sheet, rows);
  8367. sheet['!ref'] = XLSX.utils.encode_range(range);
  8368. var merges = generateMerges();
  8369. if (merges.length) {
  8370. sheet["!merges"] = merges;
  8371. }
  8372. return sheet;
  8373. }
  8374. function parseSimpleTitles() {
  8375. //get field lists
  8376. columns.forEach(function (column) {
  8377. titles.push(column.title);
  8378. fields.push(column.field);
  8379. });
  8380. rows.push(titles);
  8381. }
  8382. function parseColumnGroup(column, level) {
  8383. if (typeof titles[level] === "undefined") {
  8384. titles[level] = [];
  8385. }
  8386. if (typeof groupColumnIndexs[level] === "undefined") {
  8387. groupColumnIndexs[level] = [];
  8388. }
  8389. if (column.width > 1) {
  8390. groupColumnIndexs[level].push({
  8391. type: "hoz",
  8392. start: titles[level].length,
  8393. end: titles[level].length + column.width - 1
  8394. });
  8395. }
  8396. titles[level].push(column.title);
  8397. if (column.subGroups) {
  8398. column.subGroups.forEach(function (subGroup) {
  8399. parseColumnGroup(subGroup, level + 1);
  8400. });
  8401. } else {
  8402. fields.push(column.definition.field);
  8403. padColumnTitles(fields.length - 1, level);
  8404. groupColumnIndexs[level].push({
  8405. type: "vert",
  8406. start: fields.length - 1
  8407. });
  8408. }
  8409. }
  8410. function padColumnTitles() {
  8411. var max = 0;
  8412. titles.forEach(function (title) {
  8413. var len = title.length;
  8414. if (len > max) {
  8415. max = len;
  8416. }
  8417. });
  8418. titles.forEach(function (title) {
  8419. var len = title.length;
  8420. if (len < max) {
  8421. for (var i = len; i < max; i++) {
  8422. title.push("");
  8423. }
  8424. }
  8425. });
  8426. }
  8427. if (config.columnGroups) {
  8428. columns.forEach(function (column) {
  8429. parseColumnGroup(column, 0);
  8430. });
  8431. titles.forEach(function (title) {
  8432. rows.push(title);
  8433. });
  8434. } else {
  8435. parseSimpleTitles();
  8436. }
  8437. function generateMerges() {
  8438. var output = [];
  8439. groupRowIndexs.forEach(function (index) {
  8440. output.push({ s: { r: index, c: 0 }, e: { r: index, c: fields.length - 1 } });
  8441. });
  8442. groupColumnIndexs.forEach(function (merges, level) {
  8443. merges.forEach(function (merge) {
  8444. if (merge.type === "hoz") {
  8445. output.push({ s: { r: level, c: merge.start }, e: { r: level, c: merge.end } });
  8446. } else {
  8447. if (level != titles.length - 1) {
  8448. output.push({ s: { r: level, c: merge.start }, e: { r: titles.length - 1, c: merge.start } });
  8449. }
  8450. }
  8451. });
  8452. });
  8453. return output;
  8454. }
  8455. //generate each row of the table
  8456. function parseRows(data) {
  8457. data.forEach(function (row) {
  8458. rows.push(parseRow(row));
  8459. });
  8460. }
  8461. function parseRow(row) {
  8462. var rowData = [];
  8463. fields.forEach(function (field) {
  8464. var value = self.getFieldValue(field, row);
  8465. rowData.push(!(value instanceof Date) && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === "object" ? JSON.stringify(value) : value);
  8466. });
  8467. return rowData;
  8468. }
  8469. function addCalcRow(calcs, selector, pos) {
  8470. var calcData = calcs[selector];
  8471. if (calcData) {
  8472. if (pos) {
  8473. calcData = calcData[pos];
  8474. }
  8475. if (Object.keys(calcData).length) {
  8476. calcRowIndexs.push(rows.length);
  8477. rows.push(parseRow(calcData));
  8478. }
  8479. }
  8480. }
  8481. function parseGroup(group, calcObj) {
  8482. var groupData = [];
  8483. groupData.push(group.key);
  8484. groupRowIndexs.push(rows.length);
  8485. rows.push(groupData);
  8486. if (group.subGroups) {
  8487. group.subGroups.forEach(function (subGroup) {
  8488. parseGroup(subGroup, calcObj[group.key] ? calcObj[group.key].groups || {} : {});
  8489. });
  8490. } else {
  8491. if (config.columnCalcs) {
  8492. addCalcRow(calcObj, group.key, "top");
  8493. }
  8494. parseRows(group.rows);
  8495. if (config.columnCalcs) {
  8496. addCalcRow(calcObj, group.key, "bottom");
  8497. }
  8498. }
  8499. }
  8500. if (config.rowGroups) {
  8501. data.forEach(function (group) {
  8502. parseGroup(group, calcs);
  8503. });
  8504. } else {
  8505. if (config.columnCalcs) {
  8506. addCalcRow(calcs, "top");
  8507. }
  8508. parseRows(data);
  8509. if (config.columnCalcs) {
  8510. addCalcRow(calcs, "bottom");
  8511. }
  8512. }
  8513. worksheet = rowsToSheet();
  8514. return worksheet;
  8515. }
  8516. if (options.sheetOnly) {
  8517. setFileContents(generateSheet());
  8518. return;
  8519. }
  8520. if (options.sheets) {
  8521. for (var sheet in options.sheets) {
  8522. if (options.sheets[sheet] === true) {
  8523. workbook.SheetNames.push(sheet);
  8524. workbook.Sheets[sheet] = generateSheet();
  8525. } else {
  8526. workbook.SheetNames.push(sheet);
  8527. this.table.modules.comms.send(options.sheets[sheet], "download", "intercept", {
  8528. type: "xlsx",
  8529. options: { sheetOnly: true },
  8530. active: self.active,
  8531. intercept: function intercept(data) {
  8532. workbook.Sheets[sheet] = data;
  8533. }
  8534. });
  8535. }
  8536. }
  8537. } else {
  8538. workbook.SheetNames.push(sheetName);
  8539. workbook.Sheets[sheetName] = generateSheet();
  8540. }
  8541. if (options.documentProcessing) {
  8542. workbook = options.documentProcessing(workbook);
  8543. }
  8544. //convert workbook to binary array
  8545. function s2ab(s) {
  8546. var buf = new ArrayBuffer(s.length);
  8547. var view = new Uint8Array(buf);
  8548. for (var i = 0; i != s.length; ++i) {
  8549. view[i] = s.charCodeAt(i) & 0xFF;
  8550. }return buf;
  8551. }
  8552. output = XLSX.write(workbook, { bookType: 'xlsx', bookSST: true, type: 'binary' });
  8553. setFileContents(s2ab(output), "application/octet-stream");
  8554. },
  8555. html: function html(columns, data, options, setFileContents, config) {
  8556. if (this.table.modExists("export", true)) {
  8557. setFileContents(this.table.modules.export.getHtml(true, options.style, config), "text/html");
  8558. }
  8559. }
  8560. };
  8561. Tabulator.prototype.registerModule("download", Download);
  8562. var Edit = function Edit(table) {
  8563. this.table = table; //hold Tabulator object
  8564. this.currentCell = false; //hold currently editing cell
  8565. this.mouseClick = false; //hold mousedown state to prevent click binding being overriden by editor opening
  8566. this.recursionBlock = false; //prevent focus recursion
  8567. this.invalidEdit = false;
  8568. };
  8569. //initialize column editor
  8570. Edit.prototype.initializeColumn = function (column) {
  8571. var self = this,
  8572. config = {
  8573. editor: false,
  8574. blocked: false,
  8575. check: column.definition.editable,
  8576. params: column.definition.editorParams || {}
  8577. };
  8578. //set column editor
  8579. switch (_typeof(column.definition.editor)) {
  8580. case "string":
  8581. if (column.definition.editor === "tick") {
  8582. column.definition.editor = "tickCross";
  8583. console.warn("DEPRECATION WARNING - the tick editor has been deprecated, please use the tickCross editor");
  8584. }
  8585. if (self.editors[column.definition.editor]) {
  8586. config.editor = self.editors[column.definition.editor];
  8587. } else {
  8588. console.warn("Editor Error - No such editor found: ", column.definition.editor);
  8589. }
  8590. break;
  8591. case "function":
  8592. config.editor = column.definition.editor;
  8593. break;
  8594. case "boolean":
  8595. if (column.definition.editor === true) {
  8596. if (typeof column.definition.formatter !== "function") {
  8597. if (column.definition.formatter === "tick") {
  8598. column.definition.formatter = "tickCross";
  8599. console.warn("DEPRECATION WARNING - the tick editor has been deprecated, please use the tickCross editor");
  8600. }
  8601. if (self.editors[column.definition.formatter]) {
  8602. config.editor = self.editors[column.definition.formatter];
  8603. } else {
  8604. config.editor = self.editors["input"];
  8605. }
  8606. } else {
  8607. console.warn("Editor Error - Cannot auto lookup editor for a custom formatter: ", column.definition.formatter);
  8608. }
  8609. }
  8610. break;
  8611. }
  8612. if (config.editor) {
  8613. column.modules.edit = config;
  8614. }
  8615. };
  8616. Edit.prototype.getCurrentCell = function () {
  8617. return this.currentCell ? this.currentCell.getComponent() : false;
  8618. };
  8619. Edit.prototype.clearEditor = function () {
  8620. var cell = this.currentCell,
  8621. cellEl;
  8622. this.invalidEdit = false;
  8623. if (cell) {
  8624. this.currentCell = false;
  8625. cellEl = cell.getElement();
  8626. cellEl.classList.remove("tabulator-validation-fail");
  8627. cellEl.classList.remove("tabulator-editing");
  8628. while (cellEl.firstChild) {
  8629. cellEl.removeChild(cellEl.firstChild);
  8630. }cell.row.getElement().classList.remove("tabulator-row-editing");
  8631. }
  8632. };
  8633. Edit.prototype.cancelEdit = function () {
  8634. if (this.currentCell) {
  8635. var cell = this.currentCell;
  8636. var component = this.currentCell.getComponent();
  8637. this.clearEditor();
  8638. cell.setValueActual(cell.getValue());
  8639. cell.cellRendered();
  8640. if (cell.column.cellEvents.cellEditCancelled) {
  8641. cell.column.cellEvents.cellEditCancelled.call(this.table, component);
  8642. }
  8643. this.table.options.cellEditCancelled.call(this.table, component);
  8644. }
  8645. };
  8646. //return a formatted value for a cell
  8647. Edit.prototype.bindEditor = function (cell) {
  8648. var self = this,
  8649. element = cell.getElement();
  8650. element.setAttribute("tabindex", 0);
  8651. element.addEventListener("click", function (e) {
  8652. if (!element.classList.contains("tabulator-editing")) {
  8653. element.focus({ preventScroll: true });
  8654. }
  8655. });
  8656. element.addEventListener("mousedown", function (e) {
  8657. self.mouseClick = true;
  8658. });
  8659. element.addEventListener("focus", function (e) {
  8660. if (!self.recursionBlock) {
  8661. self.edit(cell, e, false);
  8662. }
  8663. });
  8664. };
  8665. Edit.prototype.focusCellNoEvent = function (cell, block) {
  8666. this.recursionBlock = true;
  8667. if (!(block && this.table.browser === "ie")) {
  8668. cell.getElement().focus({ preventScroll: true });
  8669. }
  8670. this.recursionBlock = false;
  8671. };
  8672. Edit.prototype.editCell = function (cell, forceEdit) {
  8673. this.focusCellNoEvent(cell);
  8674. this.edit(cell, false, forceEdit);
  8675. };
  8676. Edit.prototype.focusScrollAdjust = function (cell) {
  8677. if (this.table.rowManager.getRenderMode() == "virtual") {
  8678. var topEdge = this.table.rowManager.element.scrollTop,
  8679. bottomEdge = this.table.rowManager.element.clientHeight + this.table.rowManager.element.scrollTop,
  8680. rowEl = cell.row.getElement(),
  8681. offset = rowEl.offsetTop;
  8682. if (rowEl.offsetTop < topEdge) {
  8683. this.table.rowManager.element.scrollTop -= topEdge - rowEl.offsetTop;
  8684. } else {
  8685. if (rowEl.offsetTop + rowEl.offsetHeight > bottomEdge) {
  8686. this.table.rowManager.element.scrollTop += rowEl.offsetTop + rowEl.offsetHeight - bottomEdge;
  8687. }
  8688. }
  8689. }
  8690. };
  8691. Edit.prototype.edit = function (cell, e, forceEdit) {
  8692. var self = this,
  8693. allowEdit = true,
  8694. rendered = function rendered() {},
  8695. element = cell.getElement(),
  8696. cellEditor,
  8697. component,
  8698. params;
  8699. //prevent editing if another cell is refusing to leave focus (eg. validation fail)
  8700. if (this.currentCell) {
  8701. if (!this.invalidEdit) {
  8702. this.cancelEdit();
  8703. }
  8704. return;
  8705. }
  8706. //handle successfull value change
  8707. function success(value) {
  8708. if (self.currentCell === cell) {
  8709. var valid = true;
  8710. if (cell.column.modules.validate && self.table.modExists("validate")) {
  8711. valid = self.table.modules.validate.validate(cell.column.modules.validate, cell.getComponent(), value);
  8712. }
  8713. if (valid === true) {
  8714. self.clearEditor();
  8715. cell.setValue(value, true);
  8716. if (self.table.options.dataTree && self.table.modExists("dataTree")) {
  8717. self.table.modules.dataTree.checkForRestyle(cell);
  8718. }
  8719. return true;
  8720. } else {
  8721. self.invalidEdit = true;
  8722. element.classList.add("tabulator-validation-fail");
  8723. self.focusCellNoEvent(cell, true);
  8724. rendered();
  8725. self.table.options.validationFailed.call(self.table, cell.getComponent(), value, valid);
  8726. return false;
  8727. }
  8728. } else {
  8729. // console.warn("Edit Success Error - cannot call success on a cell that is no longer being edited");
  8730. }
  8731. }
  8732. //handle aborted edit
  8733. function cancel() {
  8734. if (self.currentCell === cell) {
  8735. self.cancelEdit();
  8736. if (self.table.options.dataTree && self.table.modExists("dataTree")) {
  8737. self.table.modules.dataTree.checkForRestyle(cell);
  8738. }
  8739. } else {
  8740. // console.warn("Edit Success Error - cannot call cancel on a cell that is no longer being edited");
  8741. }
  8742. }
  8743. function onRendered(callback) {
  8744. rendered = callback;
  8745. }
  8746. if (!cell.column.modules.edit.blocked) {
  8747. if (e) {
  8748. e.stopPropagation();
  8749. }
  8750. switch (_typeof(cell.column.modules.edit.check)) {
  8751. case "function":
  8752. allowEdit = cell.column.modules.edit.check(cell.getComponent());
  8753. break;
  8754. case "boolean":
  8755. allowEdit = cell.column.modules.edit.check;
  8756. break;
  8757. }
  8758. if (allowEdit || forceEdit) {
  8759. self.cancelEdit();
  8760. self.currentCell = cell;
  8761. this.focusScrollAdjust(cell);
  8762. component = cell.getComponent();
  8763. if (this.mouseClick) {
  8764. this.mouseClick = false;
  8765. if (cell.column.cellEvents.cellClick) {
  8766. cell.column.cellEvents.cellClick.call(this.table, e, component);
  8767. }
  8768. }
  8769. if (cell.column.cellEvents.cellEditing) {
  8770. cell.column.cellEvents.cellEditing.call(this.table, component);
  8771. }
  8772. self.table.options.cellEditing.call(this.table, component);
  8773. params = typeof cell.column.modules.edit.params === "function" ? cell.column.modules.edit.params(component) : cell.column.modules.edit.params;
  8774. cellEditor = cell.column.modules.edit.editor.call(self, component, onRendered, success, cancel, params);
  8775. //if editor returned, add to DOM, if false, abort edit
  8776. if (cellEditor !== false) {
  8777. if (cellEditor instanceof Node) {
  8778. element.classList.add("tabulator-editing");
  8779. cell.row.getElement().classList.add("tabulator-row-editing");
  8780. while (element.firstChild) {
  8781. element.removeChild(element.firstChild);
  8782. }element.appendChild(cellEditor);
  8783. //trigger onRendered Callback
  8784. rendered();
  8785. //prevent editing from triggering rowClick event
  8786. var children = element.children;
  8787. for (var i = 0; i < children.length; i++) {
  8788. children[i].addEventListener("click", function (e) {
  8789. e.stopPropagation();
  8790. });
  8791. }
  8792. } else {
  8793. console.warn("Edit Error - Editor should return an instance of Node, the editor returned:", cellEditor);
  8794. element.blur();
  8795. return false;
  8796. }
  8797. } else {
  8798. element.blur();
  8799. return false;
  8800. }
  8801. return true;
  8802. } else {
  8803. this.mouseClick = false;
  8804. element.blur();
  8805. return false;
  8806. }
  8807. } else {
  8808. this.mouseClick = false;
  8809. element.blur();
  8810. return false;
  8811. }
  8812. };
  8813. Edit.prototype.maskInput = function (el, options) {
  8814. var mask = options.mask,
  8815. maskLetter = typeof options.maskLetterChar !== "undefined" ? options.maskLetterChar : "A",
  8816. maskNumber = typeof options.maskNumberChar !== "undefined" ? options.maskNumberChar : "9",
  8817. maskWildcard = typeof options.maskWildcardChar !== "undefined" ? options.maskWildcardChar : "*",
  8818. success = false;
  8819. function fillSymbols(index) {
  8820. var symbol = mask[index];
  8821. if (typeof symbol !== "undefined" && symbol !== maskWildcard && symbol !== maskLetter && symbol !== maskNumber) {
  8822. el.value = el.value + "" + symbol;
  8823. fillSymbols(index + 1);
  8824. }
  8825. }
  8826. el.addEventListener("keydown", function (e) {
  8827. var index = el.value.length,
  8828. char = e.key;
  8829. if (e.keyCode > 46) {
  8830. if (index >= mask.length) {
  8831. e.preventDefault();
  8832. e.stopPropagation();
  8833. success = false;
  8834. return false;
  8835. } else {
  8836. switch (mask[index]) {
  8837. case maskLetter:
  8838. if (char.toUpperCase() == char.toLowerCase()) {
  8839. e.preventDefault();
  8840. e.stopPropagation();
  8841. success = false;
  8842. return false;
  8843. }
  8844. break;
  8845. case maskNumber:
  8846. if (isNaN(char)) {
  8847. e.preventDefault();
  8848. e.stopPropagation();
  8849. success = false;
  8850. return false;
  8851. }
  8852. break;
  8853. case maskWildcard:
  8854. break;
  8855. default:
  8856. if (char !== mask[index]) {
  8857. e.preventDefault();
  8858. e.stopPropagation();
  8859. success = false;
  8860. return false;
  8861. }
  8862. }
  8863. }
  8864. success = true;
  8865. }
  8866. return;
  8867. });
  8868. el.addEventListener("keyup", function (e) {
  8869. if (e.keyCode > 46) {
  8870. if (options.maskAutoFill) {
  8871. fillSymbols(el.value.length);
  8872. }
  8873. }
  8874. });
  8875. if (!el.placeholder) {
  8876. el.placeholder = mask;
  8877. }
  8878. if (options.maskAutoFill) {
  8879. fillSymbols(el.value.length);
  8880. }
  8881. };
  8882. //default data editors
  8883. Edit.prototype.editors = {
  8884. //input element
  8885. input: function input(cell, onRendered, success, cancel, editorParams) {
  8886. //create and style input
  8887. var cellValue = cell.getValue(),
  8888. input = document.createElement("input");
  8889. input.setAttribute("type", editorParams.search ? "search" : "text");
  8890. input.style.padding = "4px";
  8891. input.style.width = "100%";
  8892. input.style.boxSizing = "border-box";
  8893. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  8894. for (var key in editorParams.elementAttributes) {
  8895. if (key.charAt(0) == "+") {
  8896. key = key.slice(1);
  8897. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  8898. } else {
  8899. input.setAttribute(key, editorParams.elementAttributes[key]);
  8900. }
  8901. }
  8902. }
  8903. input.value = typeof cellValue !== "undefined" ? cellValue : "";
  8904. onRendered(function () {
  8905. input.focus({ preventScroll: true });
  8906. input.style.height = "100%";
  8907. });
  8908. function onChange(e) {
  8909. if ((cellValue === null || typeof cellValue === "undefined") && input.value !== "" || input.value !== cellValue) {
  8910. if (success(input.value)) {
  8911. cellValue = input.value; //persist value if successfully validated incase editor is used as header filter
  8912. }
  8913. } else {
  8914. cancel();
  8915. }
  8916. }
  8917. //submit new value on blur or change
  8918. input.addEventListener("change", onChange);
  8919. input.addEventListener("blur", onChange);
  8920. //submit new value on enter
  8921. input.addEventListener("keydown", function (e) {
  8922. switch (e.keyCode) {
  8923. // case 9:
  8924. case 13:
  8925. onChange(e);
  8926. break;
  8927. case 27:
  8928. cancel();
  8929. break;
  8930. }
  8931. });
  8932. if (editorParams.mask) {
  8933. this.table.modules.edit.maskInput(input, editorParams);
  8934. }
  8935. return input;
  8936. },
  8937. //resizable text area element
  8938. textarea: function textarea(cell, onRendered, success, cancel, editorParams) {
  8939. var self = this,
  8940. cellValue = cell.getValue(),
  8941. vertNav = editorParams.verticalNavigation || "hybrid",
  8942. value = String(cellValue !== null && typeof cellValue !== "undefined" ? cellValue : ""),
  8943. count = (value.match(/(?:\r\n|\r|\n)/g) || []).length + 1,
  8944. input = document.createElement("textarea"),
  8945. scrollHeight = 0;
  8946. //create and style input
  8947. input.style.display = "block";
  8948. input.style.padding = "2px";
  8949. input.style.height = "100%";
  8950. input.style.width = "100%";
  8951. input.style.boxSizing = "border-box";
  8952. input.style.whiteSpace = "pre-wrap";
  8953. input.style.resize = "none";
  8954. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  8955. for (var key in editorParams.elementAttributes) {
  8956. if (key.charAt(0) == "+") {
  8957. key = key.slice(1);
  8958. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  8959. } else {
  8960. input.setAttribute(key, editorParams.elementAttributes[key]);
  8961. }
  8962. }
  8963. }
  8964. input.value = value;
  8965. onRendered(function () {
  8966. input.focus({ preventScroll: true });
  8967. input.style.height = "100%";
  8968. });
  8969. function onChange(e) {
  8970. if ((cellValue === null || typeof cellValue === "undefined") && input.value !== "" || input.value !== cellValue) {
  8971. if (success(input.value)) {
  8972. cellValue = input.value; //persist value if successfully validated incase editor is used as header filter
  8973. }
  8974. setTimeout(function () {
  8975. cell.getRow().normalizeHeight();
  8976. }, 300);
  8977. } else {
  8978. cancel();
  8979. }
  8980. }
  8981. //submit new value on blur or change
  8982. input.addEventListener("change", onChange);
  8983. input.addEventListener("blur", onChange);
  8984. input.addEventListener("keyup", function () {
  8985. input.style.height = "";
  8986. var heightNow = input.scrollHeight;
  8987. input.style.height = heightNow + "px";
  8988. if (heightNow != scrollHeight) {
  8989. scrollHeight = heightNow;
  8990. cell.getRow().normalizeHeight();
  8991. }
  8992. });
  8993. input.addEventListener("keydown", function (e) {
  8994. switch (e.keyCode) {
  8995. case 27:
  8996. cancel();
  8997. break;
  8998. case 38:
  8999. //up arrow
  9000. if (vertNav == "editor" || vertNav == "hybrid" && input.selectionStart) {
  9001. e.stopImmediatePropagation();
  9002. e.stopPropagation();
  9003. }
  9004. break;
  9005. case 40:
  9006. //down arrow
  9007. if (vertNav == "editor" || vertNav == "hybrid" && input.selectionStart !== input.value.length) {
  9008. e.stopImmediatePropagation();
  9009. e.stopPropagation();
  9010. }
  9011. break;
  9012. }
  9013. });
  9014. if (editorParams.mask) {
  9015. this.table.modules.edit.maskInput(input, editorParams);
  9016. }
  9017. return input;
  9018. },
  9019. //input element with type of number
  9020. number: function number(cell, onRendered, success, cancel, editorParams) {
  9021. var cellValue = cell.getValue(),
  9022. vertNav = editorParams.verticalNavigation || "editor",
  9023. input = document.createElement("input");
  9024. input.setAttribute("type", "number");
  9025. if (typeof editorParams.max != "undefined") {
  9026. input.setAttribute("max", editorParams.max);
  9027. }
  9028. if (typeof editorParams.min != "undefined") {
  9029. input.setAttribute("min", editorParams.min);
  9030. }
  9031. if (typeof editorParams.step != "undefined") {
  9032. input.setAttribute("step", editorParams.step);
  9033. }
  9034. //create and style input
  9035. input.style.padding = "4px";
  9036. input.style.width = "100%";
  9037. input.style.boxSizing = "border-box";
  9038. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  9039. for (var key in editorParams.elementAttributes) {
  9040. if (key.charAt(0) == "+") {
  9041. key = key.slice(1);
  9042. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  9043. } else {
  9044. input.setAttribute(key, editorParams.elementAttributes[key]);
  9045. }
  9046. }
  9047. }
  9048. input.value = cellValue;
  9049. var blurFunc = function blurFunc(e) {
  9050. onChange();
  9051. };
  9052. onRendered(function () {
  9053. //submit new value on blur
  9054. input.removeEventListener("blur", blurFunc);
  9055. input.focus({ preventScroll: true });
  9056. input.style.height = "100%";
  9057. //submit new value on blur
  9058. input.addEventListener("blur", blurFunc);
  9059. });
  9060. function onChange() {
  9061. var value = input.value;
  9062. if (!isNaN(value) && value !== "") {
  9063. value = Number(value);
  9064. }
  9065. if (value !== cellValue) {
  9066. if (success(value)) {
  9067. cellValue = value; //persist value if successfully validated incase editor is used as header filter
  9068. }
  9069. } else {
  9070. cancel();
  9071. }
  9072. }
  9073. //submit new value on enter
  9074. input.addEventListener("keydown", function (e) {
  9075. switch (e.keyCode) {
  9076. case 13:
  9077. // case 9:
  9078. onChange();
  9079. break;
  9080. case 27:
  9081. cancel();
  9082. break;
  9083. case 38: //up arrow
  9084. case 40:
  9085. //down arrow
  9086. if (vertNav == "editor") {
  9087. e.stopImmediatePropagation();
  9088. e.stopPropagation();
  9089. }
  9090. break;
  9091. }
  9092. });
  9093. if (editorParams.mask) {
  9094. this.table.modules.edit.maskInput(input, editorParams);
  9095. }
  9096. return input;
  9097. },
  9098. //input element with type of number
  9099. range: function range(cell, onRendered, success, cancel, editorParams) {
  9100. var cellValue = cell.getValue(),
  9101. input = document.createElement("input");
  9102. input.setAttribute("type", "range");
  9103. if (typeof editorParams.max != "undefined") {
  9104. input.setAttribute("max", editorParams.max);
  9105. }
  9106. if (typeof editorParams.min != "undefined") {
  9107. input.setAttribute("min", editorParams.min);
  9108. }
  9109. if (typeof editorParams.step != "undefined") {
  9110. input.setAttribute("step", editorParams.step);
  9111. }
  9112. //create and style input
  9113. input.style.padding = "4px";
  9114. input.style.width = "100%";
  9115. input.style.boxSizing = "border-box";
  9116. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  9117. for (var key in editorParams.elementAttributes) {
  9118. if (key.charAt(0) == "+") {
  9119. key = key.slice(1);
  9120. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  9121. } else {
  9122. input.setAttribute(key, editorParams.elementAttributes[key]);
  9123. }
  9124. }
  9125. }
  9126. input.value = cellValue;
  9127. onRendered(function () {
  9128. input.focus({ preventScroll: true });
  9129. input.style.height = "100%";
  9130. });
  9131. function onChange() {
  9132. var value = input.value;
  9133. if (!isNaN(value) && value !== "") {
  9134. value = Number(value);
  9135. }
  9136. if (value != cellValue) {
  9137. if (success(value)) {
  9138. cellValue = value; //persist value if successfully validated incase editor is used as header filter
  9139. }
  9140. } else {
  9141. cancel();
  9142. }
  9143. }
  9144. //submit new value on blur
  9145. input.addEventListener("blur", function (e) {
  9146. onChange();
  9147. });
  9148. //submit new value on enter
  9149. input.addEventListener("keydown", function (e) {
  9150. switch (e.keyCode) {
  9151. case 13:
  9152. case 9:
  9153. onChange();
  9154. break;
  9155. case 27:
  9156. cancel();
  9157. break;
  9158. }
  9159. });
  9160. return input;
  9161. },
  9162. //select
  9163. select: function select(cell, onRendered, success, cancel, editorParams) {
  9164. var self = this,
  9165. cellEl = cell.getElement(),
  9166. initialValue = cell.getValue(),
  9167. vertNav = editorParams.verticalNavigation || "editor",
  9168. initialDisplayValue = typeof initialValue !== "undefined" || initialValue === null ? initialValue : typeof editorParams.defaultValue !== "undefined" ? editorParams.defaultValue : "",
  9169. input = document.createElement("input"),
  9170. listEl = document.createElement("div"),
  9171. dataItems = [],
  9172. displayItems = [],
  9173. currentItem = {},
  9174. blurable = true;
  9175. this.table.rowManager.element.addEventListener("scroll", cancelItem);
  9176. if (Array.isArray(editorParams) || !Array.isArray(editorParams) && (typeof editorParams === 'undefined' ? 'undefined' : _typeof(editorParams)) === "object" && !editorParams.values) {
  9177. console.warn("DEPRECATION WARNING - values for the select editor must now be passed into the values property of the editorParams object, not as the editorParams object");
  9178. editorParams = { values: editorParams };
  9179. }
  9180. function getUniqueColumnValues(field) {
  9181. var output = {},
  9182. data = self.table.getData(),
  9183. column;
  9184. if (field) {
  9185. column = self.table.columnManager.getColumnByField(field);
  9186. } else {
  9187. column = cell.getColumn()._getSelf();
  9188. }
  9189. if (column) {
  9190. data.forEach(function (row) {
  9191. var val = column.getFieldValue(row);
  9192. if (val !== null && typeof val !== "undefined" && val !== "") {
  9193. output[val] = true;
  9194. }
  9195. });
  9196. if (editorParams.sortValuesList) {
  9197. if (editorParams.sortValuesList == "asc") {
  9198. output = Object.keys(output).sort();
  9199. } else {
  9200. output = Object.keys(output).sort().reverse();
  9201. }
  9202. } else {
  9203. output = Object.keys(output);
  9204. }
  9205. } else {
  9206. console.warn("unable to find matching column to create select lookup list:", field);
  9207. }
  9208. return output;
  9209. }
  9210. function parseItems(inputValues, curentValue) {
  9211. var dataList = [];
  9212. var displayList = [];
  9213. function processComplexListItem(item) {
  9214. var item = {
  9215. label: editorParams.listItemFormatter ? editorParams.listItemFormatter(item.value, item.label) : item.label,
  9216. value: item.value,
  9217. element: false
  9218. };
  9219. if (item.value === curentValue || !isNaN(parseFloat(item.value)) && !isNaN(parseFloat(item.value)) && parseFloat(item.value) === parseFloat(curentValue)) {
  9220. setCurrentItem(item);
  9221. }
  9222. dataList.push(item);
  9223. displayList.push(item);
  9224. return item;
  9225. }
  9226. if (typeof inputValues == "function") {
  9227. inputValues = inputValues(cell);
  9228. }
  9229. if (Array.isArray(inputValues)) {
  9230. inputValues.forEach(function (value) {
  9231. var item;
  9232. if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === "object") {
  9233. if (value.options) {
  9234. item = {
  9235. label: value.label,
  9236. group: true,
  9237. element: false
  9238. };
  9239. displayList.push(item);
  9240. value.options.forEach(function (item) {
  9241. processComplexListItem(item);
  9242. });
  9243. } else {
  9244. processComplexListItem(value);
  9245. }
  9246. } else {
  9247. item = {
  9248. label: editorParams.listItemFormatter ? editorParams.listItemFormatter(value, value) : value,
  9249. value: value,
  9250. element: false
  9251. };
  9252. if (item.value === curentValue || !isNaN(parseFloat(item.value)) && !isNaN(parseFloat(item.value)) && parseFloat(item.value) === parseFloat(curentValue)) {
  9253. setCurrentItem(item);
  9254. }
  9255. dataList.push(item);
  9256. displayList.push(item);
  9257. }
  9258. });
  9259. } else {
  9260. for (var key in inputValues) {
  9261. var item = {
  9262. label: editorParams.listItemFormatter ? editorParams.listItemFormatter(key, inputValues[key]) : inputValues[key],
  9263. value: key,
  9264. element: false
  9265. };
  9266. if (item.value === curentValue || !isNaN(parseFloat(item.value)) && !isNaN(parseFloat(item.value)) && parseFloat(item.value) === parseFloat(curentValue)) {
  9267. setCurrentItem(item);
  9268. }
  9269. dataList.push(item);
  9270. displayList.push(item);
  9271. }
  9272. }
  9273. dataItems = dataList;
  9274. displayItems = displayList;
  9275. fillList();
  9276. }
  9277. function fillList() {
  9278. while (listEl.firstChild) {
  9279. listEl.removeChild(listEl.firstChild);
  9280. }displayItems.forEach(function (item) {
  9281. var el = item.element;
  9282. if (!el) {
  9283. if (item.group) {
  9284. el = document.createElement("div");
  9285. el.classList.add("tabulator-edit-select-list-group");
  9286. el.tabIndex = 0;
  9287. el.innerHTML = item.label === "" ? "&nbsp;" : item.label;
  9288. } else {
  9289. el = document.createElement("div");
  9290. el.classList.add("tabulator-edit-select-list-item");
  9291. el.tabIndex = 0;
  9292. el.innerHTML = item.label === "" ? "&nbsp;" : item.label;
  9293. el.addEventListener("click", function () {
  9294. setCurrentItem(item);
  9295. chooseItem();
  9296. });
  9297. if (item === currentItem) {
  9298. el.classList.add("active");
  9299. }
  9300. }
  9301. el.addEventListener("mousedown", function () {
  9302. blurable = false;
  9303. setTimeout(function () {
  9304. blurable = true;
  9305. }, 10);
  9306. });
  9307. item.element = el;
  9308. }
  9309. listEl.appendChild(el);
  9310. });
  9311. }
  9312. function setCurrentItem(item) {
  9313. if (currentItem && currentItem.element) {
  9314. currentItem.element.classList.remove("active");
  9315. }
  9316. currentItem = item;
  9317. input.value = item.label === "&nbsp;" ? "" : item.label;
  9318. if (item.element) {
  9319. item.element.classList.add("active");
  9320. }
  9321. }
  9322. function chooseItem() {
  9323. hideList();
  9324. if (initialValue !== currentItem.value) {
  9325. initialValue = currentItem.value;
  9326. success(currentItem.value);
  9327. } else {
  9328. cancel();
  9329. }
  9330. }
  9331. function cancelItem() {
  9332. hideList();
  9333. cancel();
  9334. }
  9335. function showList() {
  9336. if (!listEl.parentNode) {
  9337. if (editorParams.values === true) {
  9338. parseItems(getUniqueColumnValues(), initialDisplayValue);
  9339. } else if (typeof editorParams.values === "string") {
  9340. parseItems(getUniqueColumnValues(editorParams.values), initialDisplayValue);
  9341. } else {
  9342. parseItems(editorParams.values || [], initialDisplayValue);
  9343. }
  9344. var offset = Tabulator.prototype.helpers.elOffset(cellEl);
  9345. listEl.style.minWidth = cellEl.offsetWidth + "px";
  9346. listEl.style.top = offset.top + cellEl.offsetHeight + "px";
  9347. listEl.style.left = offset.left + "px";
  9348. listEl.addEventListener("mousedown", function (e) {
  9349. blurable = false;
  9350. setTimeout(function () {
  9351. blurable = true;
  9352. }, 10);
  9353. });
  9354. document.body.appendChild(listEl);
  9355. }
  9356. }
  9357. function hideList() {
  9358. if (listEl.parentNode) {
  9359. listEl.parentNode.removeChild(listEl);
  9360. }
  9361. removeScrollListener();
  9362. }
  9363. function removeScrollListener() {
  9364. self.table.rowManager.element.removeEventListener("scroll", cancelItem);
  9365. }
  9366. //style input
  9367. input.setAttribute("type", "text");
  9368. input.style.padding = "4px";
  9369. input.style.width = "100%";
  9370. input.style.boxSizing = "border-box";
  9371. input.style.cursor = "default";
  9372. input.readOnly = this.currentCell != false;
  9373. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  9374. for (var key in editorParams.elementAttributes) {
  9375. if (key.charAt(0) == "+") {
  9376. key = key.slice(1);
  9377. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  9378. } else {
  9379. input.setAttribute(key, editorParams.elementAttributes[key]);
  9380. }
  9381. }
  9382. }
  9383. input.value = typeof initialValue !== "undefined" || initialValue === null ? initialValue : "";
  9384. // if(editorParams.values === true){
  9385. // parseItems(getUniqueColumnValues(), initialValue);
  9386. // }else if(typeof editorParams.values === "string"){
  9387. // parseItems(getUniqueColumnValues(editorParams.values), initialValue);
  9388. // }else{
  9389. // parseItems(editorParams.values || [], initialValue);
  9390. // }
  9391. //allow key based navigation
  9392. input.addEventListener("keydown", function (e) {
  9393. var index;
  9394. switch (e.keyCode) {
  9395. case 38:
  9396. //up arrow
  9397. index = dataItems.indexOf(currentItem);
  9398. if (vertNav == "editor" || vertNav == "hybrid" && index) {
  9399. e.stopImmediatePropagation();
  9400. e.stopPropagation();
  9401. e.preventDefault();
  9402. if (index > 0) {
  9403. setCurrentItem(dataItems[index - 1]);
  9404. }
  9405. }
  9406. break;
  9407. case 40:
  9408. //down arrow
  9409. index = dataItems.indexOf(currentItem);
  9410. if (vertNav == "editor" || vertNav == "hybrid" && index < dataItems.length - 1) {
  9411. e.stopImmediatePropagation();
  9412. e.stopPropagation();
  9413. e.preventDefault();
  9414. if (index < dataItems.length - 1) {
  9415. if (index == -1) {
  9416. setCurrentItem(dataItems[0]);
  9417. } else {
  9418. setCurrentItem(dataItems[index + 1]);
  9419. }
  9420. }
  9421. }
  9422. break;
  9423. case 37: //left arrow
  9424. case 39:
  9425. //right arrow
  9426. e.stopImmediatePropagation();
  9427. e.stopPropagation();
  9428. e.preventDefault();
  9429. break;
  9430. case 13:
  9431. //enter
  9432. chooseItem();
  9433. break;
  9434. case 27:
  9435. //escape
  9436. cancelItem();
  9437. break;
  9438. }
  9439. });
  9440. input.addEventListener("blur", function (e) {
  9441. if (blurable) {
  9442. cancelItem();
  9443. }
  9444. });
  9445. input.addEventListener("focus", function (e) {
  9446. showList();
  9447. });
  9448. //style list element
  9449. listEl = document.createElement("div");
  9450. listEl.classList.add("tabulator-edit-select-list");
  9451. onRendered(function () {
  9452. input.style.height = "100%";
  9453. input.focus({ preventScroll: true });
  9454. });
  9455. return input;
  9456. },
  9457. //autocomplete
  9458. autocomplete: function autocomplete(cell, onRendered, success, cancel, editorParams) {
  9459. var self = this,
  9460. cellEl = cell.getElement(),
  9461. initialValue = cell.getValue(),
  9462. vertNav = editorParams.verticalNavigation || "editor",
  9463. initialDisplayValue = typeof initialValue !== "undefined" || initialValue === null ? initialValue : typeof editorParams.defaultValue !== "undefined" ? editorParams.defaultValue : "",
  9464. input = document.createElement("input"),
  9465. listEl = document.createElement("div"),
  9466. allItems = [],
  9467. displayItems = [],
  9468. values = [],
  9469. currentItem = false,
  9470. blurable = true;
  9471. this.table.rowManager.element.addEventListener("scroll", cancelItem);
  9472. //style input
  9473. input.setAttribute("type", "search");
  9474. input.style.padding = "4px";
  9475. input.style.width = "100%";
  9476. input.style.boxSizing = "border-box";
  9477. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  9478. for (var key in editorParams.elementAttributes) {
  9479. if (key.charAt(0) == "+") {
  9480. key = key.slice(1);
  9481. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  9482. } else {
  9483. input.setAttribute(key, editorParams.elementAttributes[key]);
  9484. }
  9485. }
  9486. }
  9487. //style list element
  9488. listEl.classList.add("tabulator-edit-select-list");
  9489. listEl.addEventListener("mousedown", function (e) {
  9490. blurable = false;
  9491. setTimeout(function () {
  9492. blurable = true;
  9493. }, 10);
  9494. });
  9495. function getUniqueColumnValues(field) {
  9496. var output = {},
  9497. data = self.table.getData(),
  9498. column;
  9499. if (field) {
  9500. column = self.table.columnManager.getColumnByField(field);
  9501. } else {
  9502. column = cell.getColumn()._getSelf();
  9503. }
  9504. if (column) {
  9505. data.forEach(function (row) {
  9506. var val = column.getFieldValue(row);
  9507. if (val !== null && typeof val !== "undefined" && val !== "") {
  9508. output[val] = true;
  9509. }
  9510. });
  9511. if (editorParams.sortValuesList) {
  9512. if (editorParams.sortValuesList == "asc") {
  9513. output = Object.keys(output).sort();
  9514. } else {
  9515. output = Object.keys(output).sort().reverse();
  9516. }
  9517. } else {
  9518. output = Object.keys(output);
  9519. }
  9520. } else {
  9521. console.warn("unable to find matching column to create autocomplete lookup list:", field);
  9522. }
  9523. return output;
  9524. }
  9525. function filterList(term, intialLoad) {
  9526. var matches = [],
  9527. values,
  9528. items,
  9529. searchEl;
  9530. //lookup base values list
  9531. if (editorParams.values === true) {
  9532. values = getUniqueColumnValues();
  9533. } else if (typeof editorParams.values === "string") {
  9534. values = getUniqueColumnValues(editorParams.values);
  9535. } else {
  9536. values = editorParams.values || [];
  9537. }
  9538. if (editorParams.searchFunc) {
  9539. matches = editorParams.searchFunc(term, values);
  9540. if (matches instanceof Promise) {
  9541. addNotice(typeof editorParams.searchingPlaceholder !== "undefined" ? editorParams.searchingPlaceholder : "Searching...");
  9542. matches.then(function (result) {
  9543. fillListIfNotEmpty(parseItems(result), intialLoad);
  9544. }).catch(function (err) {
  9545. console.err("error in autocomplete search promise:", err);
  9546. });
  9547. } else {
  9548. fillListIfNotEmpty(parseItems(matches), intialLoad);
  9549. }
  9550. } else {
  9551. items = parseItems(values);
  9552. if (term === "") {
  9553. if (editorParams.showListOnEmpty) {
  9554. matches = items;
  9555. }
  9556. } else {
  9557. items.forEach(function (item) {
  9558. if (item.value !== null || typeof item.value !== "undefined") {
  9559. if (String(item.value).toLowerCase().indexOf(String(term).toLowerCase()) > -1 || String(item.title).toLowerCase().indexOf(String(term).toLowerCase()) > -1) {
  9560. matches.push(item);
  9561. }
  9562. }
  9563. });
  9564. }
  9565. fillListIfNotEmpty(matches, intialLoad);
  9566. }
  9567. }
  9568. function addNotice(notice) {
  9569. var searchEl = document.createElement("div");
  9570. clearList();
  9571. if (notice !== false) {
  9572. searchEl.classList.add("tabulator-edit-select-list-notice");
  9573. searchEl.tabIndex = 0;
  9574. if (notice instanceof Node) {
  9575. searchEl.appendChild(notice);
  9576. } else {
  9577. searchEl.innerHTML = notice;
  9578. }
  9579. listEl.appendChild(searchEl);
  9580. }
  9581. }
  9582. function parseItems(inputValues) {
  9583. var itemList = [];
  9584. if (Array.isArray(inputValues)) {
  9585. inputValues.forEach(function (value) {
  9586. var item = {
  9587. title: editorParams.listItemFormatter ? editorParams.listItemFormatter(value, value) : value,
  9588. value: value
  9589. };
  9590. itemList.push(item);
  9591. });
  9592. } else {
  9593. for (var key in inputValues) {
  9594. var item = {
  9595. title: editorParams.listItemFormatter ? editorParams.listItemFormatter(key, inputValues[key]) : inputValues[key],
  9596. value: key
  9597. };
  9598. itemList.push(item);
  9599. }
  9600. }
  9601. return itemList;
  9602. }
  9603. function clearList() {
  9604. while (listEl.firstChild) {
  9605. listEl.removeChild(listEl.firstChild);
  9606. }
  9607. }
  9608. function fillListIfNotEmpty(items, intialLoad) {
  9609. if (items.length) {
  9610. fillList(items, intialLoad);
  9611. } else {
  9612. if (editorParams.emptyPlaceholder) {
  9613. addNotice(editorParams.emptyPlaceholder);
  9614. }
  9615. }
  9616. }
  9617. function fillList(items, intialLoad) {
  9618. var current = false;
  9619. clearList();
  9620. displayItems = items;
  9621. displayItems.forEach(function (item) {
  9622. var el = item.element;
  9623. if (!el) {
  9624. el = document.createElement("div");
  9625. el.classList.add("tabulator-edit-select-list-item");
  9626. el.tabIndex = 0;
  9627. el.innerHTML = item.title;
  9628. el.addEventListener("click", function (e) {
  9629. setCurrentItem(item);
  9630. chooseItem();
  9631. });
  9632. el.addEventListener("mousedown", function (e) {
  9633. blurable = false;
  9634. setTimeout(function () {
  9635. blurable = true;
  9636. }, 10);
  9637. });
  9638. item.element = el;
  9639. if (intialLoad && item.value == initialValue) {
  9640. input.value = item.title;
  9641. item.element.classList.add("active");
  9642. current = true;
  9643. }
  9644. if (item === currentItem) {
  9645. item.element.classList.add("active");
  9646. current = true;
  9647. }
  9648. }
  9649. listEl.appendChild(el);
  9650. });
  9651. if (!current) {
  9652. setCurrentItem(false);
  9653. }
  9654. }
  9655. function chooseItem() {
  9656. hideList();
  9657. if (currentItem) {
  9658. if (initialValue !== currentItem.value) {
  9659. initialValue = currentItem.value;
  9660. input.value = currentItem.title;
  9661. success(currentItem.value);
  9662. } else {
  9663. cancel();
  9664. }
  9665. } else {
  9666. if (editorParams.freetext) {
  9667. initialValue = input.value;
  9668. success(input.value);
  9669. } else {
  9670. if (editorParams.allowEmpty && input.value === "") {
  9671. initialValue = input.value;
  9672. success(input.value);
  9673. } else {
  9674. cancel();
  9675. }
  9676. }
  9677. }
  9678. }
  9679. function showList() {
  9680. if (!listEl.parentNode) {
  9681. while (listEl.firstChild) {
  9682. listEl.removeChild(listEl.firstChild);
  9683. }var offset = Tabulator.prototype.helpers.elOffset(cellEl);
  9684. listEl.style.minWidth = cellEl.offsetWidth + "px";
  9685. listEl.style.top = offset.top + cellEl.offsetHeight + "px";
  9686. listEl.style.left = offset.left + "px";
  9687. document.body.appendChild(listEl);
  9688. }
  9689. }
  9690. function setCurrentItem(item, showInputValue) {
  9691. if (currentItem && currentItem.element) {
  9692. currentItem.element.classList.remove("active");
  9693. }
  9694. currentItem = item;
  9695. if (item && item.element) {
  9696. item.element.classList.add("active");
  9697. }
  9698. }
  9699. function hideList() {
  9700. if (listEl.parentNode) {
  9701. listEl.parentNode.removeChild(listEl);
  9702. }
  9703. removeScrollListener();
  9704. }
  9705. function cancelItem() {
  9706. hideList();
  9707. cancel();
  9708. }
  9709. function removeScrollListener() {
  9710. self.table.rowManager.element.removeEventListener("scroll", cancelItem);
  9711. }
  9712. //allow key based navigation
  9713. input.addEventListener("keydown", function (e) {
  9714. var index;
  9715. switch (e.keyCode) {
  9716. case 38:
  9717. //up arrow
  9718. index = displayItems.indexOf(currentItem);
  9719. if (vertNav == "editor" || vertNav == "hybrid" && index) {
  9720. e.stopImmediatePropagation();
  9721. e.stopPropagation();
  9722. e.preventDefault();
  9723. if (index > 0) {
  9724. setCurrentItem(displayItems[index - 1]);
  9725. } else {
  9726. setCurrentItem(false);
  9727. }
  9728. }
  9729. break;
  9730. case 40:
  9731. //down arrow
  9732. index = displayItems.indexOf(currentItem);
  9733. if (vertNav == "editor" || vertNav == "hybrid" && index < displayItems.length - 1) {
  9734. e.stopImmediatePropagation();
  9735. e.stopPropagation();
  9736. e.preventDefault();
  9737. if (index < displayItems.length - 1) {
  9738. if (index == -1) {
  9739. setCurrentItem(displayItems[0]);
  9740. } else {
  9741. setCurrentItem(displayItems[index + 1]);
  9742. }
  9743. }
  9744. }
  9745. break;
  9746. case 37: //left arrow
  9747. case 39:
  9748. //right arrow
  9749. e.stopImmediatePropagation();
  9750. e.stopPropagation();
  9751. e.preventDefault();
  9752. break;
  9753. case 13:
  9754. //enter
  9755. chooseItem();
  9756. break;
  9757. case 27:
  9758. //escape
  9759. cancelItem();
  9760. break;
  9761. case 36: //home
  9762. case 35:
  9763. //end
  9764. //prevent table navigation while using input element
  9765. e.stopImmediatePropagation();
  9766. break;
  9767. }
  9768. });
  9769. input.addEventListener("keyup", function (e) {
  9770. switch (e.keyCode) {
  9771. case 38: //up arrow
  9772. case 37: //left arrow
  9773. case 39: //up arrow
  9774. case 40: //right arrow
  9775. case 13: //enter
  9776. case 27:
  9777. //escape
  9778. break;
  9779. default:
  9780. filterList(input.value);
  9781. }
  9782. });
  9783. input.addEventListener("search", function (e) {
  9784. filterList(input.value);
  9785. });
  9786. input.addEventListener("blur", function (e) {
  9787. if (blurable) {
  9788. chooseItem();
  9789. }
  9790. });
  9791. input.addEventListener("focus", function (e) {
  9792. var value = initialDisplayValue;
  9793. showList();
  9794. input.value = value;
  9795. filterList(value, true);
  9796. });
  9797. onRendered(function () {
  9798. input.style.height = "100%";
  9799. input.focus({ preventScroll: true });
  9800. });
  9801. if (editorParams.mask) {
  9802. this.table.modules.edit.maskInput(input, editorParams);
  9803. }
  9804. return input;
  9805. },
  9806. //start rating
  9807. star: function star(cell, onRendered, success, cancel, editorParams) {
  9808. var self = this,
  9809. element = cell.getElement(),
  9810. value = cell.getValue(),
  9811. maxStars = element.getElementsByTagName("svg").length || 5,
  9812. size = element.getElementsByTagName("svg")[0] ? element.getElementsByTagName("svg")[0].getAttribute("width") : 14,
  9813. stars = [],
  9814. starsHolder = document.createElement("div"),
  9815. star = document.createElementNS('http://www.w3.org/2000/svg', "svg");
  9816. //change star type
  9817. function starChange(val) {
  9818. stars.forEach(function (star, i) {
  9819. if (i < val) {
  9820. if (self.table.browser == "ie") {
  9821. star.setAttribute("class", "tabulator-star-active");
  9822. } else {
  9823. star.classList.replace("tabulator-star-inactive", "tabulator-star-active");
  9824. }
  9825. star.innerHTML = '<polygon fill="#488CE9" stroke="#014AAE" stroke-width="37.6152" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="259.216,29.942 330.27,173.919 489.16,197.007 374.185,309.08 401.33,467.31 259.216,392.612 117.104,467.31 144.25,309.08 29.274,197.007 188.165,173.919 "/>';
  9826. } else {
  9827. if (self.table.browser == "ie") {
  9828. star.setAttribute("class", "tabulator-star-inactive");
  9829. } else {
  9830. star.classList.replace("tabulator-star-active", "tabulator-star-inactive");
  9831. }
  9832. star.innerHTML = '<polygon fill="#010155" stroke="#686868" stroke-width="37.6152" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="259.216,29.942 330.27,173.919 489.16,197.007 374.185,309.08 401.33,467.31 259.216,392.612 117.104,467.31 144.25,309.08 29.274,197.007 188.165,173.919 "/>';
  9833. }
  9834. });
  9835. }
  9836. //build stars
  9837. function buildStar(i) {
  9838. var starHolder = document.createElement("span");
  9839. var nextStar = star.cloneNode(true);
  9840. stars.push(nextStar);
  9841. starHolder.addEventListener("mouseenter", function (e) {
  9842. e.stopPropagation();
  9843. e.stopImmediatePropagation();
  9844. starChange(i);
  9845. });
  9846. starHolder.addEventListener("mousemove", function (e) {
  9847. e.stopPropagation();
  9848. e.stopImmediatePropagation();
  9849. });
  9850. starHolder.addEventListener("click", function (e) {
  9851. e.stopPropagation();
  9852. e.stopImmediatePropagation();
  9853. success(i);
  9854. });
  9855. starHolder.appendChild(nextStar);
  9856. starsHolder.appendChild(starHolder);
  9857. }
  9858. //handle keyboard navigation value change
  9859. function changeValue(val) {
  9860. value = val;
  9861. starChange(val);
  9862. }
  9863. //style cell
  9864. element.style.whiteSpace = "nowrap";
  9865. element.style.overflow = "hidden";
  9866. element.style.textOverflow = "ellipsis";
  9867. //style holding element
  9868. starsHolder.style.verticalAlign = "middle";
  9869. starsHolder.style.display = "inline-block";
  9870. starsHolder.style.padding = "4px";
  9871. //style star
  9872. star.setAttribute("width", size);
  9873. star.setAttribute("height", size);
  9874. star.setAttribute("viewBox", "0 0 512 512");
  9875. star.setAttribute("xml:space", "preserve");
  9876. star.style.padding = "0 1px";
  9877. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  9878. for (var key in editorParams.elementAttributes) {
  9879. if (key.charAt(0) == "+") {
  9880. key = key.slice(1);
  9881. starsHolder.setAttribute(key, starsHolder.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  9882. } else {
  9883. starsHolder.setAttribute(key, editorParams.elementAttributes[key]);
  9884. }
  9885. }
  9886. }
  9887. //create correct number of stars
  9888. for (var i = 1; i <= maxStars; i++) {
  9889. buildStar(i);
  9890. }
  9891. //ensure value does not exceed number of stars
  9892. value = Math.min(parseInt(value), maxStars);
  9893. // set initial styling of stars
  9894. starChange(value);
  9895. starsHolder.addEventListener("mousemove", function (e) {
  9896. starChange(0);
  9897. });
  9898. starsHolder.addEventListener("click", function (e) {
  9899. success(0);
  9900. });
  9901. element.addEventListener("blur", function (e) {
  9902. cancel();
  9903. });
  9904. //allow key based navigation
  9905. element.addEventListener("keydown", function (e) {
  9906. switch (e.keyCode) {
  9907. case 39:
  9908. //right arrow
  9909. changeValue(value + 1);
  9910. break;
  9911. case 37:
  9912. //left arrow
  9913. changeValue(value - 1);
  9914. break;
  9915. case 13:
  9916. //enter
  9917. success(value);
  9918. break;
  9919. case 27:
  9920. //escape
  9921. cancel();
  9922. break;
  9923. }
  9924. });
  9925. return starsHolder;
  9926. },
  9927. //draggable progress bar
  9928. progress: function progress(cell, onRendered, success, cancel, editorParams) {
  9929. var element = cell.getElement(),
  9930. max = typeof editorParams.max === "undefined" ? element.getElementsByTagName("div")[0].getAttribute("max") || 100 : editorParams.max,
  9931. min = typeof editorParams.min === "undefined" ? element.getElementsByTagName("div")[0].getAttribute("min") || 0 : editorParams.min,
  9932. percent = (max - min) / 100,
  9933. value = cell.getValue() || 0,
  9934. handle = document.createElement("div"),
  9935. bar = document.createElement("div"),
  9936. mouseDrag,
  9937. mouseDragWidth;
  9938. //set new value
  9939. function updateValue() {
  9940. var calcVal = percent * Math.round(bar.offsetWidth / (element.clientWidth / 100)) + min;
  9941. success(calcVal);
  9942. element.setAttribute("aria-valuenow", calcVal);
  9943. element.setAttribute("aria-label", value);
  9944. }
  9945. //style handle
  9946. handle.style.position = "absolute";
  9947. handle.style.right = "0";
  9948. handle.style.top = "0";
  9949. handle.style.bottom = "0";
  9950. handle.style.width = "5px";
  9951. handle.classList.add("tabulator-progress-handle");
  9952. //style bar
  9953. bar.style.display = "inline-block";
  9954. bar.style.position = "relative";
  9955. // bar.style.top = "8px";
  9956. // bar.style.bottom = "8px";
  9957. // bar.style.left = "4px";
  9958. // bar.style.marginRight = "4px";
  9959. bar.style.height = "100%";
  9960. bar.style.backgroundColor = "#488CE9";
  9961. bar.style.maxWidth = "100%";
  9962. bar.style.minWidth = "0%";
  9963. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  9964. for (var key in editorParams.elementAttributes) {
  9965. if (key.charAt(0) == "+") {
  9966. key = key.slice(1);
  9967. bar.setAttribute(key, bar.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  9968. } else {
  9969. bar.setAttribute(key, editorParams.elementAttributes[key]);
  9970. }
  9971. }
  9972. }
  9973. //style cell
  9974. element.style.padding = "4px 4px";
  9975. //make sure value is in range
  9976. value = Math.min(parseFloat(value), max);
  9977. value = Math.max(parseFloat(value), min);
  9978. //workout percentage
  9979. value = Math.round((value - min) / percent);
  9980. // bar.style.right = value + "%";
  9981. bar.style.width = value + "%";
  9982. element.setAttribute("aria-valuemin", min);
  9983. element.setAttribute("aria-valuemax", max);
  9984. bar.appendChild(handle);
  9985. handle.addEventListener("mousedown", function (e) {
  9986. mouseDrag = e.screenX;
  9987. mouseDragWidth = bar.offsetWidth;
  9988. });
  9989. handle.addEventListener("mouseover", function () {
  9990. handle.style.cursor = "ew-resize";
  9991. });
  9992. element.addEventListener("mousemove", function (e) {
  9993. if (mouseDrag) {
  9994. bar.style.width = mouseDragWidth + e.screenX - mouseDrag + "px";
  9995. }
  9996. });
  9997. element.addEventListener("mouseup", function (e) {
  9998. if (mouseDrag) {
  9999. e.stopPropagation();
  10000. e.stopImmediatePropagation();
  10001. mouseDrag = false;
  10002. mouseDragWidth = false;
  10003. updateValue();
  10004. }
  10005. });
  10006. //allow key based navigation
  10007. element.addEventListener("keydown", function (e) {
  10008. switch (e.keyCode) {
  10009. case 39:
  10010. //right arrow
  10011. e.preventDefault();
  10012. bar.style.width = bar.clientWidth + element.clientWidth / 100 + "px";
  10013. break;
  10014. case 37:
  10015. //left arrow
  10016. e.preventDefault();
  10017. bar.style.width = bar.clientWidth - element.clientWidth / 100 + "px";
  10018. break;
  10019. case 9: //tab
  10020. case 13:
  10021. //enter
  10022. updateValue();
  10023. break;
  10024. case 27:
  10025. //escape
  10026. cancel();
  10027. break;
  10028. }
  10029. });
  10030. element.addEventListener("blur", function () {
  10031. cancel();
  10032. });
  10033. return bar;
  10034. },
  10035. //checkbox
  10036. tickCross: function tickCross(cell, onRendered, success, cancel, editorParams) {
  10037. var value = cell.getValue(),
  10038. input = document.createElement("input"),
  10039. tristate = editorParams.tristate,
  10040. indetermValue = typeof editorParams.indeterminateValue === "undefined" ? null : editorParams.indeterminateValue,
  10041. indetermState = false;
  10042. input.setAttribute("type", "checkbox");
  10043. input.style.marginTop = "5px";
  10044. input.style.boxSizing = "border-box";
  10045. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  10046. for (var key in editorParams.elementAttributes) {
  10047. if (key.charAt(0) == "+") {
  10048. key = key.slice(1);
  10049. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  10050. } else {
  10051. input.setAttribute(key, editorParams.elementAttributes[key]);
  10052. }
  10053. }
  10054. }
  10055. input.value = value;
  10056. if (tristate && (typeof value === "undefined" || value === indetermValue || value === "")) {
  10057. indetermState = true;
  10058. input.indeterminate = true;
  10059. }
  10060. if (this.table.browser != "firefox") {
  10061. //prevent blur issue on mac firefox
  10062. onRendered(function () {
  10063. input.focus({ preventScroll: true });
  10064. });
  10065. }
  10066. input.checked = value === true || value === "true" || value === "True" || value === 1;
  10067. function setValue(blur) {
  10068. if (tristate) {
  10069. if (!blur) {
  10070. if (input.checked && !indetermState) {
  10071. input.checked = false;
  10072. input.indeterminate = true;
  10073. indetermState = true;
  10074. return indetermValue;
  10075. } else {
  10076. indetermState = false;
  10077. return input.checked;
  10078. }
  10079. } else {
  10080. if (indetermState) {
  10081. return indetermValue;
  10082. } else {
  10083. return input.checked;
  10084. }
  10085. }
  10086. } else {
  10087. return input.checked;
  10088. }
  10089. }
  10090. //submit new value on blur
  10091. input.addEventListener("change", function (e) {
  10092. success(setValue());
  10093. });
  10094. input.addEventListener("blur", function (e) {
  10095. success(setValue(true));
  10096. });
  10097. //submit new value on enter
  10098. input.addEventListener("keydown", function (e) {
  10099. if (e.keyCode == 13) {
  10100. success(setValue());
  10101. }
  10102. if (e.keyCode == 27) {
  10103. cancel();
  10104. }
  10105. });
  10106. return input;
  10107. }
  10108. };
  10109. Tabulator.prototype.registerModule("edit", Edit);
  10110. var Export = function Export(table) {
  10111. this.table = table; //hold Tabulator object
  10112. this.config = {};
  10113. this.cloneTableStyle = true;
  10114. this.colVisProp = "";
  10115. };
  10116. Export.prototype.genereateTable = function (config, style, range, colVisProp) {
  10117. this.cloneTableStyle = style;
  10118. this.config = config || {};
  10119. this.colVisProp = colVisProp;
  10120. var table = document.createElement("table");
  10121. table.classList.add("tabulator-print-table");
  10122. if (this.config.columnHeaders !== false) {
  10123. table.appendChild(this.generateHeaderElements());
  10124. }
  10125. table.appendChild(this.generateBodyElements(this.rowLookup(range)));
  10126. this.mapElementStyles(this.table.element, table, ["border-top", "border-left", "border-right", "border-bottom"]);
  10127. return table;
  10128. };
  10129. Export.prototype.rowLookup = function (range) {
  10130. var _this45 = this;
  10131. var rows = [];
  10132. if (typeof range == "function") {
  10133. range.call(this.table).forEach(function (row) {
  10134. row = _this45.table.rowManager.findRow(row);
  10135. if (row) {
  10136. rows.push(row);
  10137. }
  10138. });
  10139. } else {
  10140. switch (range) {
  10141. case true:
  10142. case "visible":
  10143. rows = this.table.rowManager.getVisibleRows(true);
  10144. break;
  10145. case "all":
  10146. rows = this.table.rowManager.rows;
  10147. break;
  10148. case "selected":
  10149. rows = this.table.modules.selectRow.selectedRows;
  10150. break;
  10151. case "active":
  10152. default:
  10153. rows = this.table.rowManager.getDisplayRows();
  10154. }
  10155. }
  10156. return Object.assign([], rows);
  10157. };
  10158. Export.prototype.generateColumnGroupHeaders = function () {
  10159. var _this46 = this;
  10160. var output = [];
  10161. var columns = this.config.columnGroups !== false ? this.table.columnManager.columns : this.table.columnManager.columnsByIndex;
  10162. columns.forEach(function (column) {
  10163. var colData = _this46.processColumnGroup(column);
  10164. if (colData) {
  10165. output.push(colData);
  10166. }
  10167. });
  10168. return output;
  10169. };
  10170. Export.prototype.processColumnGroup = function (column) {
  10171. var _this47 = this;
  10172. var subGroups = column.columns,
  10173. maxDepth = 0;
  10174. var groupData = {
  10175. title: column.definition.title,
  10176. column: column,
  10177. depth: 1
  10178. };
  10179. if (subGroups.length) {
  10180. groupData.subGroups = [];
  10181. groupData.width = 0;
  10182. subGroups.forEach(function (subGroup) {
  10183. var subGroupData = _this47.processColumnGroup(subGroup);
  10184. if (subGroupData) {
  10185. groupData.width += subGroupData.width;
  10186. groupData.subGroups.push(subGroupData);
  10187. if (subGroupData.depth > maxDepth) {
  10188. maxDepth = subGroupData.depth;
  10189. }
  10190. }
  10191. });
  10192. groupData.depth += maxDepth;
  10193. if (!groupData.width) {
  10194. return false;
  10195. }
  10196. } else {
  10197. if (this.columnVisCheck(column)) {
  10198. groupData.width = 1;
  10199. } else {
  10200. return false;
  10201. }
  10202. }
  10203. return groupData;
  10204. };
  10205. Export.prototype.groupHeadersToRows = function (columns) {
  10206. var headers = [],
  10207. headerDepth = 0;
  10208. function parseColumnGroup(column, level) {
  10209. var depth = headerDepth - level;
  10210. if (typeof headers[level] === "undefined") {
  10211. headers[level] = [];
  10212. }
  10213. column.height = column.subGroups ? 1 : depth - column.depth + 1;
  10214. headers[level].push(column);
  10215. if (column.subGroups) {
  10216. column.subGroups.forEach(function (subGroup) {
  10217. parseColumnGroup(subGroup, level + 1);
  10218. });
  10219. }
  10220. }
  10221. //calculate maximum header debth
  10222. columns.forEach(function (column) {
  10223. if (column.depth > headerDepth) {
  10224. headerDepth = column.depth;
  10225. }
  10226. });
  10227. columns.forEach(function (column) {
  10228. parseColumnGroup(column, 0);
  10229. });
  10230. return headers;
  10231. };
  10232. Export.prototype.generateHeaderElements = function () {
  10233. var _this48 = this;
  10234. var headerEl = document.createElement("thead");
  10235. var rows = this.groupHeadersToRows(this.generateColumnGroupHeaders());
  10236. rows.forEach(function (row) {
  10237. var rowEl = document.createElement("tr");
  10238. _this48.mapElementStyles(_this48.table.columnManager.getHeadersElement(), headerEl, ["border-top", "border-left", "border-right", "border-bottom", "background-color", "color", "font-weight", "font-family", "font-size"]);
  10239. row.forEach(function (column) {
  10240. var cellEl = document.createElement("th");
  10241. var classNames = column.column.definition.cssClass ? column.column.definition.cssClass.split(" ") : [];
  10242. cellEl.colSpan = column.width;
  10243. cellEl.rowSpan = column.height;
  10244. cellEl.innerHTML = column.column.definition.title;
  10245. if (_this48.cloneTableStyle) {
  10246. cellEl.style.boxSizing = "border-box";
  10247. }
  10248. classNames.forEach(function (className) {
  10249. cellEl.classList.add(className);
  10250. });
  10251. _this48.mapElementStyles(column.column.getElement(), cellEl, ["text-align", "border-top", "border-left", "border-right", "border-bottom", "background-color", "color", "font-weight", "font-family", "font-size"]);
  10252. _this48.mapElementStyles(column.column.contentElement, cellEl, ["padding-top", "padding-left", "padding-right", "padding-bottom"]);
  10253. if (column.column.visible) {
  10254. _this48.mapElementStyles(column.column.getElement(), cellEl, ["width"]);
  10255. } else {
  10256. if (column.column.definition.width) {
  10257. cellEl.style.width = column.column.definition.width + "px";
  10258. }
  10259. }
  10260. if (column.column.parent) {
  10261. _this48.mapElementStyles(column.column.parent.groupElement, cellEl, ["border-top"]);
  10262. }
  10263. rowEl.appendChild(cellEl);
  10264. });
  10265. headerEl.appendChild(rowEl);
  10266. });
  10267. return headerEl;
  10268. };
  10269. Export.prototype.generateBodyElements = function (rows) {};
  10270. Export.prototype.generateBodyElements = function (rows) {
  10271. var _this49 = this;
  10272. var oddRow, evenRow, calcRow, firstRow, firstCell, firstGroup, lastCell, styleCells, styleRow, treeElementField, rowFormatter;
  10273. //assign row formatter
  10274. rowFormatter = this.table.options["rowFormatter" + (this.colVisProp.charAt(0).toUpperCase() + this.colVisProp.slice(1))];
  10275. rowFormatter = rowFormatter !== null ? rowFormatter : this.table.options.rowFormatter;
  10276. //lookup row styles
  10277. if (this.cloneTableStyle && window.getComputedStyle) {
  10278. oddRow = this.table.element.querySelector(".tabulator-row-odd:not(.tabulator-group):not(.tabulator-calcs)");
  10279. evenRow = this.table.element.querySelector(".tabulator-row-even:not(.tabulator-group):not(.tabulator-calcs)");
  10280. calcRow = this.table.element.querySelector(".tabulator-row.tabulator-calcs");
  10281. firstRow = this.table.element.querySelector(".tabulator-row:not(.tabulator-group):not(.tabulator-calcs)");
  10282. firstGroup = this.table.element.getElementsByClassName("tabulator-group")[0];
  10283. if (firstRow) {
  10284. styleCells = firstRow.getElementsByClassName("tabulator-cell");
  10285. firstCell = styleCells[0];
  10286. lastCell = styleCells[styleCells.length - 1];
  10287. }
  10288. }
  10289. var bodyEl = document.createElement("tbody");
  10290. var columns = [];
  10291. if (this.config.columnCalcs !== false && this.table.modExists("columnCalcs")) {
  10292. if (this.table.modules.columnCalcs.topInitialized) {
  10293. rows.unshift(this.table.modules.columnCalcs.topRow);
  10294. }
  10295. if (this.table.modules.columnCalcs.botInitialized) {
  10296. rows.push(this.table.modules.columnCalcs.botRow);
  10297. }
  10298. }
  10299. this.table.columnManager.columnsByIndex.forEach(function (column) {
  10300. if (_this49.columnVisCheck(column)) {
  10301. columns.push(column);
  10302. }
  10303. });
  10304. if (this.table.options.dataTree && this.config.dataTree !== false && this.table.modExists("columnCalcs")) {
  10305. treeElementField = this.table.modules.dataTree.elementField;
  10306. }
  10307. rows = rows.filter(function (row) {
  10308. switch (row.type) {
  10309. case "group":
  10310. return _this49.config.rowGroups !== false;
  10311. break;
  10312. case "calc":
  10313. return _this49.config.columnCalcs !== false;
  10314. break;
  10315. }
  10316. return true;
  10317. });
  10318. if (rows.length > 1000) {
  10319. console.warn("It may take a long time to render an HTML table with more than 1000 rows");
  10320. }
  10321. rows.forEach(function (row, i) {
  10322. var rowData = row.getData(_this49.colVisProp);
  10323. var rowEl = document.createElement("tr");
  10324. rowEl.classList.add("tabulator-print-table-row");
  10325. switch (row.type) {
  10326. case "group":
  10327. var cellEl = document.createElement("td");
  10328. cellEl.colSpan = columns.length;
  10329. cellEl.innerHTML = row.key;
  10330. rowEl.classList.add("tabulator-print-table-group");
  10331. _this49.mapElementStyles(firstGroup, rowEl, ["border-top", "border-left", "border-right", "border-bottom", "color", "font-weight", "font-family", "font-size", "background-color"]);
  10332. _this49.mapElementStyles(firstGroup, cellEl, ["padding-top", "padding-left", "padding-right", "padding-bottom"]);
  10333. rowEl.appendChild(cellEl);
  10334. break;
  10335. case "calc":
  10336. rowEl.classList.add("tabulator-print-table-calcs");
  10337. case "row":
  10338. if (_this49.table.options.dataTree && _this49.config.dataTree === false && row.modules.dataTree.parent) {
  10339. return;
  10340. }
  10341. columns.forEach(function (column, i) {
  10342. var cellEl = document.createElement("td");
  10343. var value = column.getFieldValue(rowData);
  10344. var cellWrapper = {
  10345. modules: {},
  10346. getValue: function getValue() {
  10347. return value;
  10348. },
  10349. getField: function getField() {
  10350. return column.definition.field;
  10351. },
  10352. getElement: function getElement() {
  10353. return cellEl;
  10354. },
  10355. getColumn: function getColumn() {
  10356. return column.getComponent();
  10357. },
  10358. getData: function getData() {
  10359. return rowData;
  10360. },
  10361. getRow: function getRow() {
  10362. return row.getComponent();
  10363. },
  10364. getComponent: function getComponent() {
  10365. return cellWrapper;
  10366. },
  10367. column: column
  10368. };
  10369. var classNames = column.definition.cssClass ? column.definition.cssClass.split(" ") : [];
  10370. classNames.forEach(function (className) {
  10371. cellEl.classList.add(className);
  10372. });
  10373. if (_this49.table.modExists("format") && _this49.config.formatCells !== false) {
  10374. value = _this49.table.modules.format.formatExportValue(cellWrapper, _this49.colVisProp);
  10375. } else {
  10376. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  10377. case "object":
  10378. value = JSON.stringify(value);
  10379. break;
  10380. case "undefined":
  10381. case "null":
  10382. value = "";
  10383. break;
  10384. default:
  10385. value = value;
  10386. }
  10387. }
  10388. if (value instanceof Node) {
  10389. cellEl.appendChild(value);
  10390. } else {
  10391. cellEl.innerHTML = value;
  10392. }
  10393. if (firstCell) {
  10394. _this49.mapElementStyles(firstCell, cellEl, ["padding-top", "padding-left", "padding-right", "padding-bottom", "border-top", "border-left", "border-right", "border-bottom", "color", "font-weight", "font-family", "font-size"]);
  10395. if (column.definition.align) {
  10396. cellEl.style.textAlign = column.definition.align;
  10397. }
  10398. }
  10399. if (_this49.table.options.dataTree && _this49.config.dataTree !== false) {
  10400. if (treeElementField && treeElementField == column.field || !treeElementField && i == 0) {
  10401. if (row.modules.dataTree.controlEl) {
  10402. cellEl.insertBefore(row.modules.dataTree.controlEl.cloneNode(true), cellEl.firstChild);
  10403. }
  10404. if (row.modules.dataTree.branchEl) {
  10405. cellEl.insertBefore(row.modules.dataTree.branchEl.cloneNode(true), cellEl.firstChild);
  10406. }
  10407. }
  10408. }
  10409. rowEl.appendChild(cellEl);
  10410. if (cellWrapper.modules.format && cellWrapper.modules.format.renderedCallback) {
  10411. cellWrapper.modules.format.renderedCallback();
  10412. }
  10413. });
  10414. styleRow = row.type == "calc" ? calcRow : i % 2 && evenRow ? evenRow : oddRow;
  10415. _this49.mapElementStyles(styleRow, rowEl, ["border-top", "border-left", "border-right", "border-bottom", "color", "font-weight", "font-family", "font-size", "background-color"]);
  10416. if (rowFormatter && _this49.config.formatCells !== false) {
  10417. var rowComponent = row.getComponent();
  10418. rowComponent.getElement = function () {
  10419. return rowEl;
  10420. };
  10421. rowFormatter(rowComponent);
  10422. }
  10423. break;
  10424. }
  10425. bodyEl.appendChild(rowEl);
  10426. });
  10427. return bodyEl;
  10428. };
  10429. Export.prototype.columnVisCheck = function (column) {
  10430. return column.definition[this.colVisProp] !== false && (column.visible || !column.visible && column.definition[this.colVisProp]);
  10431. };
  10432. Export.prototype.getHtml = function (visible, style, config, colVisProp) {
  10433. var holder = document.createElement("div");
  10434. holder.appendChild(this.genereateTable(config || this.table.options.htmlOutputConfig, style, visible, colVisProp || "htmlOutput"));
  10435. return holder.innerHTML;
  10436. };
  10437. Export.prototype.mapElementStyles = function (from, to, props) {
  10438. if (this.cloneTableStyle && from && to) {
  10439. var lookup = {
  10440. "background-color": "backgroundColor",
  10441. "color": "fontColor",
  10442. "width": "width",
  10443. "font-weight": "fontWeight",
  10444. "font-family": "fontFamily",
  10445. "font-size": "fontSize",
  10446. "text-align": "textAlign",
  10447. "border-top": "borderTop",
  10448. "border-left": "borderLeft",
  10449. "border-right": "borderRight",
  10450. "border-bottom": "borderBottom",
  10451. "padding-top": "paddingTop",
  10452. "padding-left": "paddingLeft",
  10453. "padding-right": "paddingRight",
  10454. "padding-bottom": "paddingBottom"
  10455. };
  10456. if (window.getComputedStyle) {
  10457. var fromStyle = window.getComputedStyle(from);
  10458. props.forEach(function (prop) {
  10459. to.style[lookup[prop]] = fromStyle.getPropertyValue(prop);
  10460. });
  10461. }
  10462. }
  10463. };
  10464. Tabulator.prototype.registerModule("export", Export);
  10465. var Filter = function Filter(table) {
  10466. this.table = table; //hold Tabulator object
  10467. this.filterList = []; //hold filter list
  10468. this.headerFilters = {}; //hold column filters
  10469. this.headerFilterColumns = []; //hold columns that use header filters
  10470. this.prevHeaderFilterChangeCheck = "";
  10471. this.prevHeaderFilterChangeCheck = "{}";
  10472. this.changed = false; //has filtering changed since last render
  10473. };
  10474. //initialize column header filter
  10475. Filter.prototype.initializeColumn = function (column, value) {
  10476. var self = this,
  10477. field = column.getField(),
  10478. params;
  10479. //handle successfull value change
  10480. function success(value) {
  10481. var filterType = column.modules.filter.tagType == "input" && column.modules.filter.attrType == "text" || column.modules.filter.tagType == "textarea" ? "partial" : "match",
  10482. type = "",
  10483. filterChangeCheck = "",
  10484. filterFunc;
  10485. if (typeof column.modules.filter.prevSuccess === "undefined" || column.modules.filter.prevSuccess !== value) {
  10486. column.modules.filter.prevSuccess = value;
  10487. if (!column.modules.filter.emptyFunc(value)) {
  10488. column.modules.filter.value = value;
  10489. switch (_typeof(column.definition.headerFilterFunc)) {
  10490. case "string":
  10491. if (self.filters[column.definition.headerFilterFunc]) {
  10492. type = column.definition.headerFilterFunc;
  10493. filterFunc = function filterFunc(data) {
  10494. var params = column.definition.headerFilterFuncParams || {};
  10495. var fieldVal = column.getFieldValue(data);
  10496. params = typeof params === "function" ? params(value, fieldVal, data) : params;
  10497. return self.filters[column.definition.headerFilterFunc](value, fieldVal, data, params);
  10498. };
  10499. } else {
  10500. console.warn("Header Filter Error - Matching filter function not found: ", column.definition.headerFilterFunc);
  10501. }
  10502. break;
  10503. case "function":
  10504. filterFunc = function filterFunc(data) {
  10505. var params = column.definition.headerFilterFuncParams || {};
  10506. var fieldVal = column.getFieldValue(data);
  10507. params = typeof params === "function" ? params(value, fieldVal, data) : params;
  10508. return column.definition.headerFilterFunc(value, fieldVal, data, params);
  10509. };
  10510. type = filterFunc;
  10511. break;
  10512. }
  10513. if (!filterFunc) {
  10514. switch (filterType) {
  10515. case "partial":
  10516. filterFunc = function filterFunc(data) {
  10517. var colVal = column.getFieldValue(data);
  10518. if (typeof colVal !== 'undefined' && colVal !== null) {
  10519. return String(colVal).toLowerCase().indexOf(String(value).toLowerCase()) > -1;
  10520. } else {
  10521. return false;
  10522. }
  10523. };
  10524. type = "like";
  10525. break;
  10526. default:
  10527. filterFunc = function filterFunc(data) {
  10528. return column.getFieldValue(data) == value;
  10529. };
  10530. type = "=";
  10531. }
  10532. }
  10533. self.headerFilters[field] = { value: value, func: filterFunc, type: type };
  10534. } else {
  10535. delete self.headerFilters[field];
  10536. }
  10537. filterChangeCheck = JSON.stringify(self.headerFilters);
  10538. if (self.prevHeaderFilterChangeCheck !== filterChangeCheck) {
  10539. self.prevHeaderFilterChangeCheck = filterChangeCheck;
  10540. self.changed = true;
  10541. self.table.rowManager.filterRefresh();
  10542. }
  10543. }
  10544. return true;
  10545. }
  10546. column.modules.filter = {
  10547. success: success,
  10548. attrType: false,
  10549. tagType: false,
  10550. emptyFunc: false
  10551. };
  10552. this.generateHeaderFilterElement(column);
  10553. };
  10554. Filter.prototype.generateHeaderFilterElement = function (column, initialValue, reinitialize) {
  10555. var _this50 = this;
  10556. var self = this,
  10557. success = column.modules.filter.success,
  10558. field = column.getField(),
  10559. filterElement,
  10560. editor,
  10561. editorElement,
  10562. cellWrapper,
  10563. typingTimer,
  10564. searchTrigger,
  10565. params;
  10566. //handle aborted edit
  10567. function cancel() {}
  10568. if (column.modules.filter.headerElement && column.modules.filter.headerElement.parentNode) {
  10569. column.contentElement.removeChild(column.modules.filter.headerElement.parentNode);
  10570. }
  10571. if (field) {
  10572. //set empty value function
  10573. column.modules.filter.emptyFunc = column.definition.headerFilterEmptyCheck || function (value) {
  10574. return !value && value !== "0";
  10575. };
  10576. filterElement = document.createElement("div");
  10577. filterElement.classList.add("tabulator-header-filter");
  10578. //set column editor
  10579. switch (_typeof(column.definition.headerFilter)) {
  10580. case "string":
  10581. if (self.table.modules.edit.editors[column.definition.headerFilter]) {
  10582. editor = self.table.modules.edit.editors[column.definition.headerFilter];
  10583. if ((column.definition.headerFilter === "tick" || column.definition.headerFilter === "tickCross") && !column.definition.headerFilterEmptyCheck) {
  10584. column.modules.filter.emptyFunc = function (value) {
  10585. return value !== true && value !== false;
  10586. };
  10587. }
  10588. } else {
  10589. console.warn("Filter Error - Cannot build header filter, No such editor found: ", column.definition.editor);
  10590. }
  10591. break;
  10592. case "function":
  10593. editor = column.definition.headerFilter;
  10594. break;
  10595. case "boolean":
  10596. if (column.modules.edit && column.modules.edit.editor) {
  10597. editor = column.modules.edit.editor;
  10598. } else {
  10599. if (column.definition.formatter && self.table.modules.edit.editors[column.definition.formatter]) {
  10600. editor = self.table.modules.edit.editors[column.definition.formatter];
  10601. if ((column.definition.formatter === "tick" || column.definition.formatter === "tickCross") && !column.definition.headerFilterEmptyCheck) {
  10602. column.modules.filter.emptyFunc = function (value) {
  10603. return value !== true && value !== false;
  10604. };
  10605. }
  10606. } else {
  10607. editor = self.table.modules.edit.editors["input"];
  10608. }
  10609. }
  10610. break;
  10611. }
  10612. if (editor) {
  10613. cellWrapper = {
  10614. getValue: function getValue() {
  10615. return typeof initialValue !== "undefined" ? initialValue : "";
  10616. },
  10617. getField: function getField() {
  10618. return column.definition.field;
  10619. },
  10620. getElement: function getElement() {
  10621. return filterElement;
  10622. },
  10623. getColumn: function getColumn() {
  10624. return column.getComponent();
  10625. },
  10626. getRow: function getRow() {
  10627. return {
  10628. normalizeHeight: function normalizeHeight() {}
  10629. };
  10630. }
  10631. };
  10632. params = column.definition.headerFilterParams || {};
  10633. params = typeof params === "function" ? params.call(self.table) : params;
  10634. editorElement = editor.call(this.table.modules.edit, cellWrapper, function () {}, success, cancel, params);
  10635. if (!editorElement) {
  10636. console.warn("Filter Error - Cannot add filter to " + field + " column, editor returned a value of false");
  10637. return;
  10638. }
  10639. if (!(editorElement instanceof Node)) {
  10640. console.warn("Filter Error - Cannot add filter to " + field + " column, editor should return an instance of Node, the editor returned:", editorElement);
  10641. return;
  10642. }
  10643. //set Placeholder Text
  10644. if (field) {
  10645. self.table.modules.localize.bind("headerFilters|columns|" + column.definition.field, function (value) {
  10646. editorElement.setAttribute("placeholder", typeof value !== "undefined" && value ? value : self.table.modules.localize.getText("headerFilters|default"));
  10647. });
  10648. } else {
  10649. self.table.modules.localize.bind("headerFilters|default", function (value) {
  10650. editorElement.setAttribute("placeholder", typeof self.column.definition.headerFilterPlaceholder !== "undefined" && self.column.definition.headerFilterPlaceholder ? self.column.definition.headerFilterPlaceholder : value);
  10651. });
  10652. }
  10653. //focus on element on click
  10654. editorElement.addEventListener("click", function (e) {
  10655. e.stopPropagation();
  10656. editorElement.focus();
  10657. });
  10658. editorElement.addEventListener("focus", function (e) {
  10659. var left = _this50.table.columnManager.element.scrollLeft;
  10660. if (left !== _this50.table.rowManager.element.scrollLeft) {
  10661. _this50.table.rowManager.scrollHorizontal(left);
  10662. _this50.table.columnManager.scrollHorizontal(left);
  10663. }
  10664. });
  10665. //live update filters as user types
  10666. typingTimer = false;
  10667. searchTrigger = function searchTrigger(e) {
  10668. if (typingTimer) {
  10669. clearTimeout(typingTimer);
  10670. }
  10671. typingTimer = setTimeout(function () {
  10672. success(editorElement.value);
  10673. }, self.table.options.headerFilterLiveFilterDelay);
  10674. };
  10675. column.modules.filter.headerElement = editorElement;
  10676. column.modules.filter.attrType = editorElement.hasAttribute("type") ? editorElement.getAttribute("type").toLowerCase() : "";
  10677. column.modules.filter.tagType = editorElement.tagName.toLowerCase();
  10678. if (column.definition.headerFilterLiveFilter !== false) {
  10679. if (!(column.definition.headerFilter === 'autocomplete' || column.definition.headerFilter === 'tickCross' || (column.definition.editor === 'autocomplete' || column.definition.editor === 'tickCross') && column.definition.headerFilter === true)) {
  10680. editorElement.addEventListener("keyup", searchTrigger);
  10681. editorElement.addEventListener("search", searchTrigger);
  10682. //update number filtered columns on change
  10683. if (column.modules.filter.attrType == "number") {
  10684. editorElement.addEventListener("change", function (e) {
  10685. success(editorElement.value);
  10686. });
  10687. }
  10688. //change text inputs to search inputs to allow for clearing of field
  10689. if (column.modules.filter.attrType == "text" && this.table.browser !== "ie") {
  10690. editorElement.setAttribute("type", "search");
  10691. // editorElement.off("change blur"); //prevent blur from triggering filter and preventing selection click
  10692. }
  10693. }
  10694. //prevent input and select elements from propegating click to column sorters etc
  10695. if (column.modules.filter.tagType == "input" || column.modules.filter.tagType == "select" || column.modules.filter.tagType == "textarea") {
  10696. editorElement.addEventListener("mousedown", function (e) {
  10697. e.stopPropagation();
  10698. });
  10699. }
  10700. }
  10701. filterElement.appendChild(editorElement);
  10702. column.contentElement.appendChild(filterElement);
  10703. if (!reinitialize) {
  10704. self.headerFilterColumns.push(column);
  10705. }
  10706. }
  10707. } else {
  10708. console.warn("Filter Error - Cannot add header filter, column has no field set:", column.definition.title);
  10709. }
  10710. };
  10711. //hide all header filter elements (used to ensure correct column widths in "fitData" layout mode)
  10712. Filter.prototype.hideHeaderFilterElements = function () {
  10713. this.headerFilterColumns.forEach(function (column) {
  10714. if (column.modules.filter && column.modules.filter.headerElement) {
  10715. column.modules.filter.headerElement.style.display = 'none';
  10716. }
  10717. });
  10718. };
  10719. //show all header filter elements (used to ensure correct column widths in "fitData" layout mode)
  10720. Filter.prototype.showHeaderFilterElements = function () {
  10721. this.headerFilterColumns.forEach(function (column) {
  10722. if (column.modules.filter && column.modules.filter.headerElement) {
  10723. column.modules.filter.headerElement.style.display = '';
  10724. }
  10725. });
  10726. };
  10727. //programatically set focus of header filter
  10728. Filter.prototype.setHeaderFilterFocus = function (column) {
  10729. if (column.modules.filter && column.modules.filter.headerElement) {
  10730. column.modules.filter.headerElement.focus();
  10731. } else {
  10732. console.warn("Column Filter Focus Error - No header filter set on column:", column.getField());
  10733. }
  10734. };
  10735. //programmatically get value of header filter
  10736. Filter.prototype.getHeaderFilterValue = function (column) {
  10737. if (column.modules.filter && column.modules.filter.headerElement) {
  10738. return column.modules.filter.headerElement.value;
  10739. } else {
  10740. console.warn("Column Filter Error - No header filter set on column:", column.getField());
  10741. }
  10742. };
  10743. //programatically set value of header filter
  10744. Filter.prototype.setHeaderFilterValue = function (column, value) {
  10745. if (column) {
  10746. if (column.modules.filter && column.modules.filter.headerElement) {
  10747. this.generateHeaderFilterElement(column, value, true);
  10748. column.modules.filter.success(value);
  10749. } else {
  10750. console.warn("Column Filter Error - No header filter set on column:", column.getField());
  10751. }
  10752. }
  10753. };
  10754. Filter.prototype.reloadHeaderFilter = function (column) {
  10755. if (column) {
  10756. if (column.modules.filter && column.modules.filter.headerElement) {
  10757. this.generateHeaderFilterElement(column, column.modules.filter.value, true);
  10758. } else {
  10759. console.warn("Column Filter Error - No header filter set on column:", column.getField());
  10760. }
  10761. }
  10762. };
  10763. //check if the filters has changed since last use
  10764. Filter.prototype.hasChanged = function () {
  10765. var changed = this.changed;
  10766. this.changed = false;
  10767. return changed;
  10768. };
  10769. //set standard filters
  10770. Filter.prototype.setFilter = function (field, type, value) {
  10771. var self = this;
  10772. self.filterList = [];
  10773. if (!Array.isArray(field)) {
  10774. field = [{ field: field, type: type, value: value }];
  10775. }
  10776. self.addFilter(field);
  10777. };
  10778. //add filter to array
  10779. Filter.prototype.addFilter = function (field, type, value) {
  10780. var self = this;
  10781. if (!Array.isArray(field)) {
  10782. field = [{ field: field, type: type, value: value }];
  10783. }
  10784. field.forEach(function (filter) {
  10785. filter = self.findFilter(filter);
  10786. if (filter) {
  10787. self.filterList.push(filter);
  10788. self.changed = true;
  10789. }
  10790. });
  10791. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.filter) {
  10792. this.table.modules.persistence.save("filter");
  10793. }
  10794. };
  10795. Filter.prototype.findFilter = function (filter) {
  10796. var self = this,
  10797. column;
  10798. if (Array.isArray(filter)) {
  10799. return this.findSubFilters(filter);
  10800. }
  10801. var filterFunc = false;
  10802. if (typeof filter.field == "function") {
  10803. filterFunc = function filterFunc(data) {
  10804. return filter.field(data, filter.type || {}); // pass params to custom filter function
  10805. };
  10806. } else {
  10807. if (self.filters[filter.type]) {
  10808. column = self.table.columnManager.getColumnByField(filter.field);
  10809. if (column) {
  10810. filterFunc = function filterFunc(data) {
  10811. return self.filters[filter.type](filter.value, column.getFieldValue(data));
  10812. };
  10813. } else {
  10814. filterFunc = function filterFunc(data) {
  10815. return self.filters[filter.type](filter.value, data[filter.field]);
  10816. };
  10817. }
  10818. } else {
  10819. console.warn("Filter Error - No such filter type found, ignoring: ", filter.type);
  10820. }
  10821. }
  10822. filter.func = filterFunc;
  10823. return filter.func ? filter : false;
  10824. };
  10825. Filter.prototype.findSubFilters = function (filters) {
  10826. var self = this,
  10827. output = [];
  10828. filters.forEach(function (filter) {
  10829. filter = self.findFilter(filter);
  10830. if (filter) {
  10831. output.push(filter);
  10832. }
  10833. });
  10834. return output.length ? output : false;
  10835. };
  10836. //get all filters
  10837. Filter.prototype.getFilters = function (all, ajax) {
  10838. var output = [];
  10839. if (all) {
  10840. output = this.getHeaderFilters();
  10841. }
  10842. if (ajax) {
  10843. output.forEach(function (item) {
  10844. if (typeof item.type == "function") {
  10845. item.type = "function";
  10846. }
  10847. });
  10848. }
  10849. output = output.concat(this.filtersToArray(this.filterList, ajax));
  10850. return output;
  10851. };
  10852. //filter to Object
  10853. Filter.prototype.filtersToArray = function (filterList, ajax) {
  10854. var _this51 = this;
  10855. var output = [];
  10856. filterList.forEach(function (filter) {
  10857. var item;
  10858. if (Array.isArray(filter)) {
  10859. output.push(_this51.filtersToArray(filter, ajax));
  10860. } else {
  10861. item = { field: filter.field, type: filter.type, value: filter.value };
  10862. if (ajax) {
  10863. if (typeof item.type == "function") {
  10864. item.type = "function";
  10865. }
  10866. }
  10867. output.push(item);
  10868. }
  10869. });
  10870. return output;
  10871. };
  10872. //get all filters
  10873. Filter.prototype.getHeaderFilters = function () {
  10874. var self = this,
  10875. output = [];
  10876. for (var key in this.headerFilters) {
  10877. output.push({ field: key, type: this.headerFilters[key].type, value: this.headerFilters[key].value });
  10878. }
  10879. return output;
  10880. };
  10881. //remove filter from array
  10882. Filter.prototype.removeFilter = function (field, type, value) {
  10883. var self = this;
  10884. if (!Array.isArray(field)) {
  10885. field = [{ field: field, type: type, value: value }];
  10886. }
  10887. field.forEach(function (filter) {
  10888. var index = -1;
  10889. if (_typeof(filter.field) == "object") {
  10890. index = self.filterList.findIndex(function (element) {
  10891. return filter === element;
  10892. });
  10893. } else {
  10894. index = self.filterList.findIndex(function (element) {
  10895. return filter.field === element.field && filter.type === element.type && filter.value === element.value;
  10896. });
  10897. }
  10898. if (index > -1) {
  10899. self.filterList.splice(index, 1);
  10900. self.changed = true;
  10901. } else {
  10902. console.warn("Filter Error - No matching filter type found, ignoring: ", filter.type);
  10903. }
  10904. });
  10905. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.filter) {
  10906. this.table.modules.persistence.save("filter");
  10907. }
  10908. };
  10909. //clear filters
  10910. Filter.prototype.clearFilter = function (all) {
  10911. this.filterList = [];
  10912. if (all) {
  10913. this.clearHeaderFilter();
  10914. }
  10915. this.changed = true;
  10916. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.filter) {
  10917. this.table.modules.persistence.save("filter");
  10918. }
  10919. };
  10920. //clear header filters
  10921. Filter.prototype.clearHeaderFilter = function () {
  10922. var self = this;
  10923. this.headerFilters = {};
  10924. self.prevHeaderFilterChangeCheck = "{}";
  10925. this.headerFilterColumns.forEach(function (column) {
  10926. column.modules.filter.value = null;
  10927. column.modules.filter.prevSuccess = undefined;
  10928. self.reloadHeaderFilter(column);
  10929. });
  10930. this.changed = true;
  10931. };
  10932. //search data and return matching rows
  10933. Filter.prototype.search = function (searchType, field, type, value) {
  10934. var self = this,
  10935. activeRows = [],
  10936. filterList = [];
  10937. if (!Array.isArray(field)) {
  10938. field = [{ field: field, type: type, value: value }];
  10939. }
  10940. field.forEach(function (filter) {
  10941. filter = self.findFilter(filter);
  10942. if (filter) {
  10943. filterList.push(filter);
  10944. }
  10945. });
  10946. this.table.rowManager.rows.forEach(function (row) {
  10947. var match = true;
  10948. filterList.forEach(function (filter) {
  10949. if (!self.filterRecurse(filter, row.getData())) {
  10950. match = false;
  10951. }
  10952. });
  10953. if (match) {
  10954. activeRows.push(searchType === "data" ? row.getData("data") : row.getComponent());
  10955. }
  10956. });
  10957. return activeRows;
  10958. };
  10959. //filter row array
  10960. Filter.prototype.filter = function (rowList, filters) {
  10961. var self = this,
  10962. activeRows = [],
  10963. activeRowComponents = [];
  10964. if (self.table.options.dataFiltering) {
  10965. self.table.options.dataFiltering.call(self.table, self.getFilters());
  10966. }
  10967. if (!self.table.options.ajaxFiltering && (self.filterList.length || Object.keys(self.headerFilters).length)) {
  10968. rowList.forEach(function (row) {
  10969. if (self.filterRow(row)) {
  10970. activeRows.push(row);
  10971. }
  10972. });
  10973. } else {
  10974. activeRows = rowList.slice(0);
  10975. }
  10976. if (self.table.options.dataFiltered) {
  10977. activeRows.forEach(function (row) {
  10978. activeRowComponents.push(row.getComponent());
  10979. });
  10980. self.table.options.dataFiltered.call(self.table, self.getFilters(), activeRowComponents);
  10981. }
  10982. return activeRows;
  10983. };
  10984. //filter individual row
  10985. Filter.prototype.filterRow = function (row, filters) {
  10986. var self = this,
  10987. match = true,
  10988. data = row.getData();
  10989. self.filterList.forEach(function (filter) {
  10990. if (!self.filterRecurse(filter, data)) {
  10991. match = false;
  10992. }
  10993. });
  10994. for (var field in self.headerFilters) {
  10995. if (!self.headerFilters[field].func(data)) {
  10996. match = false;
  10997. }
  10998. }
  10999. return match;
  11000. };
  11001. Filter.prototype.filterRecurse = function (filter, data) {
  11002. var self = this,
  11003. match = false;
  11004. if (Array.isArray(filter)) {
  11005. filter.forEach(function (subFilter) {
  11006. if (self.filterRecurse(subFilter, data)) {
  11007. match = true;
  11008. }
  11009. });
  11010. } else {
  11011. match = filter.func(data);
  11012. }
  11013. return match;
  11014. };
  11015. //list of available filters
  11016. Filter.prototype.filters = {
  11017. //equal to
  11018. "=": function _(filterVal, rowVal, rowData, filterParams) {
  11019. return rowVal == filterVal ? true : false;
  11020. },
  11021. //less than
  11022. "<": function _(filterVal, rowVal, rowData, filterParams) {
  11023. return rowVal < filterVal ? true : false;
  11024. },
  11025. //less than or equal to
  11026. "<=": function _(filterVal, rowVal, rowData, filterParams) {
  11027. return rowVal <= filterVal ? true : false;
  11028. },
  11029. //greater than
  11030. ">": function _(filterVal, rowVal, rowData, filterParams) {
  11031. return rowVal > filterVal ? true : false;
  11032. },
  11033. //greater than or equal to
  11034. ">=": function _(filterVal, rowVal, rowData, filterParams) {
  11035. return rowVal >= filterVal ? true : false;
  11036. },
  11037. //not equal to
  11038. "!=": function _(filterVal, rowVal, rowData, filterParams) {
  11039. return rowVal != filterVal ? true : false;
  11040. },
  11041. "regex": function regex(filterVal, rowVal, rowData, filterParams) {
  11042. if (typeof filterVal == "string") {
  11043. filterVal = new RegExp(filterVal);
  11044. }
  11045. return filterVal.test(rowVal);
  11046. },
  11047. //contains the string
  11048. "like": function like(filterVal, rowVal, rowData, filterParams) {
  11049. if (filterVal === null || typeof filterVal === "undefined") {
  11050. return rowVal === filterVal ? true : false;
  11051. } else {
  11052. if (typeof rowVal !== 'undefined' && rowVal !== null) {
  11053. return String(rowVal).toLowerCase().indexOf(filterVal.toLowerCase()) > -1;
  11054. } else {
  11055. return false;
  11056. }
  11057. }
  11058. },
  11059. //in array
  11060. "in": function _in(filterVal, rowVal, rowData, filterParams) {
  11061. if (Array.isArray(filterVal)) {
  11062. return filterVal.indexOf(rowVal) > -1;
  11063. } else {
  11064. console.warn("Filter Error - filter value is not an array:", filterVal);
  11065. return false;
  11066. }
  11067. }
  11068. };
  11069. Tabulator.prototype.registerModule("filter", Filter);
  11070. var Format = function Format(table) {
  11071. this.table = table; //hold Tabulator object
  11072. };
  11073. //initialize column formatter
  11074. Format.prototype.initializeColumn = function (column) {
  11075. column.modules.format = this.lookupFormatter(column, "");
  11076. if (typeof column.definition.formatterPrint !== "undefined") {
  11077. column.modules.format.print = this.lookupFormatter(column, "Print");
  11078. }
  11079. if (typeof column.definition.formatterClipboard !== "undefined") {
  11080. column.modules.format.clipboard = this.lookupFormatter(column, "Clipboard");
  11081. }
  11082. if (typeof column.definition.formatterHtmlOutput !== "undefined") {
  11083. column.modules.format.htmlOutput = this.lookupFormatter(column, "HtmlOutput");
  11084. }
  11085. };
  11086. Format.prototype.lookupFormatter = function (column, type) {
  11087. var config = { params: column.definition["formatter" + type + "Params"] || {} },
  11088. formatter = column.definition["formatter" + type];
  11089. //set column formatter
  11090. switch (typeof formatter === 'undefined' ? 'undefined' : _typeof(formatter)) {
  11091. case "string":
  11092. if (formatter === "tick") {
  11093. formatter = "tickCross";
  11094. if (typeof config.params.crossElement == "undefined") {
  11095. config.params.crossElement = false;
  11096. }
  11097. console.warn("DEPRECATION WARNING - the tick formatter has been deprecated, please use the tickCross formatter with the crossElement param set to false");
  11098. }
  11099. if (this.formatters[formatter]) {
  11100. config.formatter = this.formatters[formatter];
  11101. } else {
  11102. console.warn("Formatter Error - No such formatter found: ", formatter);
  11103. config.formatter = this.formatters.plaintext;
  11104. }
  11105. break;
  11106. case "function":
  11107. config.formatter = formatter;
  11108. break;
  11109. default:
  11110. config.formatter = this.formatters.plaintext;
  11111. break;
  11112. }
  11113. return config;
  11114. };
  11115. Format.prototype.cellRendered = function (cell) {
  11116. if (cell.modules.format && cell.modules.format.renderedCallback) {
  11117. cell.modules.format.renderedCallback();
  11118. }
  11119. };
  11120. //return a formatted value for a cell
  11121. Format.prototype.formatValue = function (cell) {
  11122. var component = cell.getComponent(),
  11123. params = typeof cell.column.modules.format.params === "function" ? cell.column.modules.format.params(component) : cell.column.modules.format.params;
  11124. function onRendered(callback) {
  11125. if (!cell.modules.format) {
  11126. cell.modules.format = {};
  11127. }
  11128. cell.modules.format.renderedCallback = callback;
  11129. }
  11130. return cell.column.modules.format.formatter.call(this, component, params, onRendered);
  11131. };
  11132. Format.prototype.formatExportValue = function (cell, type) {
  11133. var formatter = cell.column.modules.format[type],
  11134. params;
  11135. if (formatter) {
  11136. var onRendered = function onRendered(callback) {
  11137. if (!cell.modules.format) {
  11138. cell.modules.format = {};
  11139. }
  11140. cell.modules.format.renderedCallback = callback;
  11141. };
  11142. params = typeof formatter.params === "function" ? formatter.params(component) : formatter.params;
  11143. return formatter.formatter.call(this, cell.getComponent(), params, onRendered);
  11144. } else {
  11145. return this.formatValue(cell);
  11146. }
  11147. };
  11148. Format.prototype.sanitizeHTML = function (value) {
  11149. if (value) {
  11150. var entityMap = {
  11151. '&': '&amp;',
  11152. '<': '&lt;',
  11153. '>': '&gt;',
  11154. '"': '&quot;',
  11155. "'": '&#39;',
  11156. '/': '&#x2F;',
  11157. '`': '&#x60;',
  11158. '=': '&#x3D;'
  11159. };
  11160. return String(value).replace(/[&<>"'`=\/]/g, function (s) {
  11161. return entityMap[s];
  11162. });
  11163. } else {
  11164. return value;
  11165. }
  11166. };
  11167. Format.prototype.emptyToSpace = function (value) {
  11168. return value === null || typeof value === "undefined" || value === "" ? "&nbsp;" : value;
  11169. };
  11170. //get formatter for cell
  11171. Format.prototype.getFormatter = function (formatter) {
  11172. var formatter;
  11173. switch (typeof formatter === 'undefined' ? 'undefined' : _typeof(formatter)) {
  11174. case "string":
  11175. if (this.formatters[formatter]) {
  11176. formatter = this.formatters[formatter];
  11177. } else {
  11178. console.warn("Formatter Error - No such formatter found: ", formatter);
  11179. formatter = this.formatters.plaintext;
  11180. }
  11181. break;
  11182. case "function":
  11183. formatter = formatter;
  11184. break;
  11185. default:
  11186. formatter = this.formatters.plaintext;
  11187. break;
  11188. }
  11189. return formatter;
  11190. };
  11191. //default data formatters
  11192. Format.prototype.formatters = {
  11193. //plain text value
  11194. plaintext: function plaintext(cell, formatterParams, onRendered) {
  11195. return this.emptyToSpace(this.sanitizeHTML(cell.getValue()));
  11196. },
  11197. //html text value
  11198. html: function html(cell, formatterParams, onRendered) {
  11199. return cell.getValue();
  11200. },
  11201. //multiline text area
  11202. textarea: function textarea(cell, formatterParams, onRendered) {
  11203. cell.getElement().style.whiteSpace = "pre-wrap";
  11204. return this.emptyToSpace(this.sanitizeHTML(cell.getValue()));
  11205. },
  11206. //currency formatting
  11207. money: function money(cell, formatterParams, onRendered) {
  11208. var floatVal = parseFloat(cell.getValue()),
  11209. number,
  11210. integer,
  11211. decimal,
  11212. rgx;
  11213. var decimalSym = formatterParams.decimal || ".";
  11214. var thousandSym = formatterParams.thousand || ",";
  11215. var symbol = formatterParams.symbol || "";
  11216. var after = !!formatterParams.symbolAfter;
  11217. var precision = typeof formatterParams.precision !== "undefined" ? formatterParams.precision : 2;
  11218. if (isNaN(floatVal)) {
  11219. return this.emptyToSpace(this.sanitizeHTML(cell.getValue()));
  11220. }
  11221. number = precision !== false ? floatVal.toFixed(precision) : floatVal;
  11222. number = String(number).split(".");
  11223. integer = number[0];
  11224. decimal = number.length > 1 ? decimalSym + number[1] : "";
  11225. rgx = /(\d+)(\d{3})/;
  11226. while (rgx.test(integer)) {
  11227. integer = integer.replace(rgx, "$1" + thousandSym + "$2");
  11228. }
  11229. return after ? integer + decimal + symbol : symbol + integer + decimal;
  11230. },
  11231. //clickable anchor tag
  11232. link: function link(cell, formatterParams, onRendered) {
  11233. var value = cell.getValue(),
  11234. urlPrefix = formatterParams.urlPrefix || "",
  11235. download = formatterParams.download,
  11236. label = value,
  11237. el = document.createElement("a"),
  11238. data;
  11239. if (formatterParams.labelField) {
  11240. data = cell.getData();
  11241. label = data[formatterParams.labelField];
  11242. }
  11243. if (formatterParams.label) {
  11244. switch (_typeof(formatterParams.label)) {
  11245. case "string":
  11246. label = formatterParams.label;
  11247. break;
  11248. case "function":
  11249. label = formatterParams.label(cell);
  11250. break;
  11251. }
  11252. }
  11253. if (label) {
  11254. if (formatterParams.urlField) {
  11255. data = cell.getData();
  11256. value = data[formatterParams.urlField];
  11257. }
  11258. if (formatterParams.url) {
  11259. switch (_typeof(formatterParams.url)) {
  11260. case "string":
  11261. value = formatterParams.url;
  11262. break;
  11263. case "function":
  11264. value = formatterParams.url(cell);
  11265. break;
  11266. }
  11267. }
  11268. el.setAttribute("href", urlPrefix + value);
  11269. if (formatterParams.target) {
  11270. el.setAttribute("target", formatterParams.target);
  11271. }
  11272. if (formatterParams.download) {
  11273. if (typeof download == "function") {
  11274. download = download(cell);
  11275. } else {
  11276. download = download === true ? "" : download;
  11277. }
  11278. el.setAttribute("download", download);
  11279. }
  11280. el.innerHTML = this.emptyToSpace(this.sanitizeHTML(label));
  11281. return el;
  11282. } else {
  11283. return "&nbsp;";
  11284. }
  11285. },
  11286. //image element
  11287. image: function image(cell, formatterParams, onRendered) {
  11288. var el = document.createElement("img");
  11289. el.setAttribute("src", cell.getValue());
  11290. switch (_typeof(formatterParams.height)) {
  11291. case "number":
  11292. el.style.height = formatterParams.height + "px";
  11293. break;
  11294. case "string":
  11295. el.style.height = formatterParams.height;
  11296. break;
  11297. }
  11298. switch (_typeof(formatterParams.width)) {
  11299. case "number":
  11300. el.style.width = formatterParams.width + "px";
  11301. break;
  11302. case "string":
  11303. el.style.width = formatterParams.width;
  11304. break;
  11305. }
  11306. el.addEventListener("load", function () {
  11307. cell.getRow().normalizeHeight();
  11308. });
  11309. return el;
  11310. },
  11311. //tick or cross
  11312. tickCross: function tickCross(cell, formatterParams, onRendered) {
  11313. var value = cell.getValue(),
  11314. element = cell.getElement(),
  11315. empty = formatterParams.allowEmpty,
  11316. truthy = formatterParams.allowTruthy,
  11317. tick = typeof formatterParams.tickElement !== "undefined" ? formatterParams.tickElement : '<svg enable-background="new 0 0 24 24" height="14" width="14" viewBox="0 0 24 24" xml:space="preserve" ><path fill="#2DC214" clip-rule="evenodd" d="M21.652,3.211c-0.293-0.295-0.77-0.295-1.061,0L9.41,14.34 c-0.293,0.297-0.771,0.297-1.062,0L3.449,9.351C3.304,9.203,3.114,9.13,2.923,9.129C2.73,9.128,2.534,9.201,2.387,9.351 l-2.165,1.946C0.078,11.445,0,11.63,0,11.823c0,0.194,0.078,0.397,0.223,0.544l4.94,5.184c0.292,0.296,0.771,0.776,1.062,1.07 l2.124,2.141c0.292,0.293,0.769,0.293,1.062,0l14.366-14.34c0.293-0.294,0.293-0.777,0-1.071L21.652,3.211z" fill-rule="evenodd"/></svg>',
  11318. cross = typeof formatterParams.crossElement !== "undefined" ? formatterParams.crossElement : '<svg enable-background="new 0 0 24 24" height="14" width="14" viewBox="0 0 24 24" xml:space="preserve" ><path fill="#CE1515" d="M22.245,4.015c0.313,0.313,0.313,0.826,0,1.139l-6.276,6.27c-0.313,0.312-0.313,0.826,0,1.14l6.273,6.272 c0.313,0.313,0.313,0.826,0,1.14l-2.285,2.277c-0.314,0.312-0.828,0.312-1.142,0l-6.271-6.271c-0.313-0.313-0.828-0.313-1.141,0 l-6.276,6.267c-0.313,0.313-0.828,0.313-1.141,0l-2.282-2.28c-0.313-0.313-0.313-0.826,0-1.14l6.278-6.269 c0.313-0.312,0.313-0.826,0-1.14L1.709,5.147c-0.314-0.313-0.314-0.827,0-1.14l2.284-2.278C4.308,1.417,4.821,1.417,5.135,1.73 L11.405,8c0.314,0.314,0.828,0.314,1.141,0.001l6.276-6.267c0.312-0.312,0.826-0.312,1.141,0L22.245,4.015z"/></svg>';
  11319. if (truthy && value || value === true || value === "true" || value === "True" || value === 1 || value === "1") {
  11320. element.setAttribute("aria-checked", true);
  11321. return tick || "";
  11322. } else {
  11323. if (empty && (value === "null" || value === "" || value === null || typeof value === "undefined")) {
  11324. element.setAttribute("aria-checked", "mixed");
  11325. return "";
  11326. } else {
  11327. element.setAttribute("aria-checked", false);
  11328. return cross || "";
  11329. }
  11330. }
  11331. },
  11332. datetime: function datetime(cell, formatterParams, onRendered) {
  11333. var inputFormat = formatterParams.inputFormat || "YYYY-MM-DD hh:mm:ss";
  11334. var outputFormat = formatterParams.outputFormat || "DD/MM/YYYY hh:mm:ss";
  11335. var invalid = typeof formatterParams.invalidPlaceholder !== "undefined" ? formatterParams.invalidPlaceholder : "";
  11336. var value = cell.getValue();
  11337. var newDatetime = moment(value, inputFormat);
  11338. if (newDatetime.isValid()) {
  11339. return newDatetime.format(outputFormat);
  11340. } else {
  11341. if (invalid === true) {
  11342. return value;
  11343. } else if (typeof invalid === "function") {
  11344. return invalid(value);
  11345. } else {
  11346. return invalid;
  11347. }
  11348. }
  11349. },
  11350. datetimediff: function datetime(cell, formatterParams, onRendered) {
  11351. var inputFormat = formatterParams.inputFormat || "YYYY-MM-DD hh:mm:ss";
  11352. var invalid = typeof formatterParams.invalidPlaceholder !== "undefined" ? formatterParams.invalidPlaceholder : "";
  11353. var suffix = typeof formatterParams.suffix !== "undefined" ? formatterParams.suffix : false;
  11354. var unit = typeof formatterParams.unit !== "undefined" ? formatterParams.unit : undefined;
  11355. var humanize = typeof formatterParams.humanize !== "undefined" ? formatterParams.humanize : false;
  11356. var date = typeof formatterParams.date !== "undefined" ? formatterParams.date : moment();
  11357. var value = cell.getValue();
  11358. var newDatetime = moment(value, inputFormat);
  11359. if (newDatetime.isValid()) {
  11360. if (humanize) {
  11361. return moment.duration(newDatetime.diff(date)).humanize(suffix);
  11362. } else {
  11363. return newDatetime.diff(date, unit) + (suffix ? " " + suffix : "");
  11364. }
  11365. } else {
  11366. if (invalid === true) {
  11367. return value;
  11368. } else if (typeof invalid === "function") {
  11369. return invalid(value);
  11370. } else {
  11371. return invalid;
  11372. }
  11373. }
  11374. },
  11375. //select
  11376. lookup: function lookup(cell, formatterParams, onRendered) {
  11377. var value = cell.getValue();
  11378. if (typeof formatterParams[value] === "undefined") {
  11379. console.warn('Missing display value for ' + value);
  11380. return value;
  11381. }
  11382. return formatterParams[value];
  11383. },
  11384. //star rating
  11385. star: function star(cell, formatterParams, onRendered) {
  11386. var value = cell.getValue(),
  11387. element = cell.getElement(),
  11388. maxStars = formatterParams && formatterParams.stars ? formatterParams.stars : 5,
  11389. stars = document.createElement("span"),
  11390. star = document.createElementNS('http://www.w3.org/2000/svg', "svg"),
  11391. starActive = '<polygon fill="#FFEA00" stroke="#C1AB60" stroke-width="37.6152" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="259.216,29.942 330.27,173.919 489.16,197.007 374.185,309.08 401.33,467.31 259.216,392.612 117.104,467.31 144.25,309.08 29.274,197.007 188.165,173.919 "/>',
  11392. starInactive = '<polygon fill="#D2D2D2" stroke="#686868" stroke-width="37.6152" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="259.216,29.942 330.27,173.919 489.16,197.007 374.185,309.08 401.33,467.31 259.216,392.612 117.104,467.31 144.25,309.08 29.274,197.007 188.165,173.919 "/>';
  11393. //style stars holder
  11394. stars.style.verticalAlign = "middle";
  11395. //style star
  11396. star.setAttribute("width", "14");
  11397. star.setAttribute("height", "14");
  11398. star.setAttribute("viewBox", "0 0 512 512");
  11399. star.setAttribute("xml:space", "preserve");
  11400. star.style.padding = "0 1px";
  11401. value = value && !isNaN(value) ? parseInt(value) : 0;
  11402. value = Math.max(0, Math.min(value, maxStars));
  11403. for (var i = 1; i <= maxStars; i++) {
  11404. var nextStar = star.cloneNode(true);
  11405. nextStar.innerHTML = i <= value ? starActive : starInactive;
  11406. stars.appendChild(nextStar);
  11407. }
  11408. element.style.whiteSpace = "nowrap";
  11409. element.style.overflow = "hidden";
  11410. element.style.textOverflow = "ellipsis";
  11411. element.setAttribute("aria-label", value);
  11412. return stars;
  11413. },
  11414. traffic: function traffic(cell, formatterParams, onRendered) {
  11415. var value = this.sanitizeHTML(cell.getValue()) || 0,
  11416. el = document.createElement("span"),
  11417. max = formatterParams && formatterParams.max ? formatterParams.max : 100,
  11418. min = formatterParams && formatterParams.min ? formatterParams.min : 0,
  11419. colors = formatterParams && typeof formatterParams.color !== "undefined" ? formatterParams.color : ["red", "orange", "green"],
  11420. color = "#666666",
  11421. percent,
  11422. percentValue;
  11423. if (isNaN(value) || typeof cell.getValue() === "undefined") {
  11424. return;
  11425. }
  11426. el.classList.add("tabulator-traffic-light");
  11427. //make sure value is in range
  11428. percentValue = parseFloat(value) <= max ? parseFloat(value) : max;
  11429. percentValue = parseFloat(percentValue) >= min ? parseFloat(percentValue) : min;
  11430. //workout percentage
  11431. percent = (max - min) / 100;
  11432. percentValue = Math.round((percentValue - min) / percent);
  11433. //set color
  11434. switch (typeof colors === 'undefined' ? 'undefined' : _typeof(colors)) {
  11435. case "string":
  11436. color = colors;
  11437. break;
  11438. case "function":
  11439. color = colors(value);
  11440. break;
  11441. case "object":
  11442. if (Array.isArray(colors)) {
  11443. var unit = 100 / colors.length;
  11444. var index = Math.floor(percentValue / unit);
  11445. index = Math.min(index, colors.length - 1);
  11446. index = Math.max(index, 0);
  11447. color = colors[index];
  11448. break;
  11449. }
  11450. }
  11451. el.style.backgroundColor = color;
  11452. return el;
  11453. },
  11454. //progress bar
  11455. progress: function progress(cell, formatterParams, onRendered) {
  11456. //progress bar
  11457. var value = this.sanitizeHTML(cell.getValue()) || 0,
  11458. element = cell.getElement(),
  11459. max = formatterParams && formatterParams.max ? formatterParams.max : 100,
  11460. min = formatterParams && formatterParams.min ? formatterParams.min : 0,
  11461. legendAlign = formatterParams && formatterParams.legendAlign ? formatterParams.legendAlign : "center",
  11462. percent,
  11463. percentValue,
  11464. color,
  11465. legend,
  11466. legendColor,
  11467. top,
  11468. left,
  11469. right,
  11470. bottom;
  11471. //make sure value is in range
  11472. percentValue = parseFloat(value) <= max ? parseFloat(value) : max;
  11473. percentValue = parseFloat(percentValue) >= min ? parseFloat(percentValue) : min;
  11474. //workout percentage
  11475. percent = (max - min) / 100;
  11476. percentValue = Math.round((percentValue - min) / percent);
  11477. //set bar color
  11478. switch (_typeof(formatterParams.color)) {
  11479. case "string":
  11480. color = formatterParams.color;
  11481. break;
  11482. case "function":
  11483. color = formatterParams.color(value);
  11484. break;
  11485. case "object":
  11486. if (Array.isArray(formatterParams.color)) {
  11487. var unit = 100 / formatterParams.color.length;
  11488. var index = Math.floor(percentValue / unit);
  11489. index = Math.min(index, formatterParams.color.length - 1);
  11490. index = Math.max(index, 0);
  11491. color = formatterParams.color[index];
  11492. break;
  11493. }
  11494. default:
  11495. color = "#2DC214";
  11496. }
  11497. //generate legend
  11498. switch (_typeof(formatterParams.legend)) {
  11499. case "string":
  11500. legend = formatterParams.legend;
  11501. break;
  11502. case "function":
  11503. legend = formatterParams.legend(value);
  11504. break;
  11505. case "boolean":
  11506. legend = value;
  11507. break;
  11508. default:
  11509. legend = false;
  11510. }
  11511. //set legend color
  11512. switch (_typeof(formatterParams.legendColor)) {
  11513. case "string":
  11514. legendColor = formatterParams.legendColor;
  11515. break;
  11516. case "function":
  11517. legendColor = formatterParams.legendColor(value);
  11518. break;
  11519. case "object":
  11520. if (Array.isArray(formatterParams.legendColor)) {
  11521. var unit = 100 / formatterParams.legendColor.length;
  11522. var index = Math.floor(percentValue / unit);
  11523. index = Math.min(index, formatterParams.legendColor.length - 1);
  11524. index = Math.max(index, 0);
  11525. legendColor = formatterParams.legendColor[index];
  11526. }
  11527. break;
  11528. default:
  11529. legendColor = "#000";
  11530. }
  11531. element.style.minWidth = "30px";
  11532. element.style.position = "relative";
  11533. element.setAttribute("aria-label", percentValue);
  11534. var barEl = document.createElement("div");
  11535. barEl.style.display = "inline-block";
  11536. barEl.style.position = "relative";
  11537. barEl.style.width = percentValue + "%";
  11538. barEl.style.backgroundColor = color;
  11539. barEl.style.height = "100%";
  11540. barEl.setAttribute('data-max', max);
  11541. barEl.setAttribute('data-min', min);
  11542. if (legend) {
  11543. var legendEl = document.createElement("div");
  11544. legendEl.style.position = "absolute";
  11545. legendEl.style.top = "4px";
  11546. legendEl.style.left = 0;
  11547. legendEl.style.textAlign = legendAlign;
  11548. legendEl.style.width = "100%";
  11549. legendEl.style.color = legendColor;
  11550. legendEl.innerHTML = legend;
  11551. }
  11552. onRendered(function () {
  11553. //handle custom element needed if formatter is to be included in printed/downloaded output
  11554. if (!(cell instanceof CellComponent)) {
  11555. var holderEl = document.createElement("div");
  11556. holderEl.style.position = "absolute";
  11557. holderEl.style.top = "4px";
  11558. holderEl.style.bottom = "4px";
  11559. holderEl.style.left = "4px";
  11560. holderEl.style.right = "4px";
  11561. element.appendChild(holderEl);
  11562. element = holderEl;
  11563. }
  11564. element.appendChild(barEl);
  11565. if (legend) {
  11566. element.appendChild(legendEl);
  11567. }
  11568. });
  11569. return "";
  11570. },
  11571. //background color
  11572. color: function color(cell, formatterParams, onRendered) {
  11573. cell.getElement().style.backgroundColor = this.sanitizeHTML(cell.getValue());
  11574. return "";
  11575. },
  11576. //tick icon
  11577. buttonTick: function buttonTick(cell, formatterParams, onRendered) {
  11578. return '<svg enable-background="new 0 0 24 24" height="14" width="14" viewBox="0 0 24 24" xml:space="preserve" ><path fill="#2DC214" clip-rule="evenodd" d="M21.652,3.211c-0.293-0.295-0.77-0.295-1.061,0L9.41,14.34 c-0.293,0.297-0.771,0.297-1.062,0L3.449,9.351C3.304,9.203,3.114,9.13,2.923,9.129C2.73,9.128,2.534,9.201,2.387,9.351 l-2.165,1.946C0.078,11.445,0,11.63,0,11.823c0,0.194,0.078,0.397,0.223,0.544l4.94,5.184c0.292,0.296,0.771,0.776,1.062,1.07 l2.124,2.141c0.292,0.293,0.769,0.293,1.062,0l14.366-14.34c0.293-0.294,0.293-0.777,0-1.071L21.652,3.211z" fill-rule="evenodd"/></svg>';
  11579. },
  11580. //cross icon
  11581. buttonCross: function buttonCross(cell, formatterParams, onRendered) {
  11582. return '<svg enable-background="new 0 0 24 24" height="14" width="14" viewBox="0 0 24 24" xml:space="preserve" ><path fill="#CE1515" d="M22.245,4.015c0.313,0.313,0.313,0.826,0,1.139l-6.276,6.27c-0.313,0.312-0.313,0.826,0,1.14l6.273,6.272 c0.313,0.313,0.313,0.826,0,1.14l-2.285,2.277c-0.314,0.312-0.828,0.312-1.142,0l-6.271-6.271c-0.313-0.313-0.828-0.313-1.141,0 l-6.276,6.267c-0.313,0.313-0.828,0.313-1.141,0l-2.282-2.28c-0.313-0.313-0.313-0.826,0-1.14l6.278-6.269 c0.313-0.312,0.313-0.826,0-1.14L1.709,5.147c-0.314-0.313-0.314-0.827,0-1.14l2.284-2.278C4.308,1.417,4.821,1.417,5.135,1.73 L11.405,8c0.314,0.314,0.828,0.314,1.141,0.001l6.276-6.267c0.312-0.312,0.826-0.312,1.141,0L22.245,4.015z"/></svg>';
  11583. },
  11584. //current row number
  11585. rownum: function rownum(cell, formatterParams, onRendered) {
  11586. return this.table.rowManager.activeRows.indexOf(cell.getRow()._getSelf()) + 1;
  11587. },
  11588. //row handle
  11589. handle: function handle(cell, formatterParams, onRendered) {
  11590. cell.getElement().classList.add("tabulator-row-handle");
  11591. return "<div class='tabulator-row-handle-box'><div class='tabulator-row-handle-bar'></div><div class='tabulator-row-handle-bar'></div><div class='tabulator-row-handle-bar'></div></div>";
  11592. },
  11593. responsiveCollapse: function responsiveCollapse(cell, formatterParams, onRendered) {
  11594. var self = this,
  11595. open = false,
  11596. el = document.createElement("div"),
  11597. config = cell.getRow()._row.modules.responsiveLayout;
  11598. el.classList.add("tabulator-responsive-collapse-toggle");
  11599. el.innerHTML = "<span class='tabulator-responsive-collapse-toggle-open'>+</span><span class='tabulator-responsive-collapse-toggle-close'>-</span>";
  11600. cell.getElement().classList.add("tabulator-row-handle");
  11601. function toggleList(isOpen) {
  11602. var collapseEl = config.element;
  11603. config.open = isOpen;
  11604. if (collapseEl) {
  11605. if (config.open) {
  11606. el.classList.add("open");
  11607. collapseEl.style.display = '';
  11608. } else {
  11609. el.classList.remove("open");
  11610. collapseEl.style.display = 'none';
  11611. }
  11612. }
  11613. }
  11614. el.addEventListener("click", function (e) {
  11615. e.stopImmediatePropagation();
  11616. toggleList(!config.open);
  11617. });
  11618. toggleList(config.open);
  11619. return el;
  11620. },
  11621. rowSelection: function rowSelection(cell) {
  11622. var _this52 = this;
  11623. var checkbox = document.createElement("input");
  11624. checkbox.type = 'checkbox';
  11625. if (this.table.modExists("selectRow", true)) {
  11626. checkbox.addEventListener("click", function (e) {
  11627. e.stopPropagation();
  11628. });
  11629. if (typeof cell.getRow == 'function') {
  11630. var row = cell.getRow();
  11631. checkbox.addEventListener("change", function (e) {
  11632. row.toggleSelect();
  11633. });
  11634. checkbox.checked = row.isSelected();
  11635. this.table.modules.selectRow.registerRowSelectCheckbox(row, checkbox);
  11636. } else {
  11637. checkbox.addEventListener("change", function (e) {
  11638. if (_this52.table.modules.selectRow.selectedRows.length) {
  11639. _this52.table.deselectRow();
  11640. } else {
  11641. _this52.table.selectRow();
  11642. }
  11643. });
  11644. this.table.modules.selectRow.registerHeaderSelectCheckbox(checkbox);
  11645. }
  11646. }
  11647. return checkbox;
  11648. }
  11649. };
  11650. Tabulator.prototype.registerModule("format", Format);
  11651. var FrozenColumns = function FrozenColumns(table) {
  11652. this.table = table; //hold Tabulator object
  11653. this.leftColumns = [];
  11654. this.rightColumns = [];
  11655. this.leftMargin = 0;
  11656. this.rightMargin = 0;
  11657. this.rightPadding = 0;
  11658. this.initializationMode = "left";
  11659. this.active = false;
  11660. this.scrollEndTimer = false;
  11661. };
  11662. //reset initial state
  11663. FrozenColumns.prototype.reset = function () {
  11664. this.initializationMode = "left";
  11665. this.leftColumns = [];
  11666. this.rightColumns = [];
  11667. this.leftMargin = 0;
  11668. this.rightMargin = 0;
  11669. this.rightMargin = 0;
  11670. this.active = false;
  11671. this.table.columnManager.headersElement.style.marginLeft = 0;
  11672. this.table.columnManager.element.style.paddingRight = 0;
  11673. };
  11674. //initialize specific column
  11675. FrozenColumns.prototype.initializeColumn = function (column) {
  11676. var config = { margin: 0, edge: false };
  11677. if (!column.isGroup) {
  11678. if (this.frozenCheck(column)) {
  11679. config.position = this.initializationMode;
  11680. if (this.initializationMode == "left") {
  11681. this.leftColumns.push(column);
  11682. } else {
  11683. this.rightColumns.unshift(column);
  11684. }
  11685. this.active = true;
  11686. column.modules.frozen = config;
  11687. } else {
  11688. this.initializationMode = "right";
  11689. }
  11690. }
  11691. };
  11692. FrozenColumns.prototype.frozenCheck = function (column) {
  11693. var frozen = false;
  11694. if (column.parent.isGroup && column.definition.frozen) {
  11695. console.warn("Frozen Column Error - Parent column group must be frozen, not individual columns or sub column groups");
  11696. }
  11697. if (column.parent.isGroup) {
  11698. return this.frozenCheck(column.parent);
  11699. } else {
  11700. return column.definition.frozen;
  11701. }
  11702. return frozen;
  11703. };
  11704. //quick layout to smooth horizontal scrolling
  11705. FrozenColumns.prototype.scrollHorizontal = function () {
  11706. var _this53 = this;
  11707. var rows;
  11708. if (this.active) {
  11709. clearTimeout(this.scrollEndTimer);
  11710. //layout all rows after scroll is complete
  11711. this.scrollEndTimer = setTimeout(function () {
  11712. _this53.layout();
  11713. }, 100);
  11714. rows = this.table.rowManager.getVisibleRows();
  11715. this.calcMargins();
  11716. this.layoutColumnPosition();
  11717. this.layoutCalcRows();
  11718. rows.forEach(function (row) {
  11719. if (row.type === "row") {
  11720. _this53.layoutRow(row);
  11721. }
  11722. });
  11723. this.table.rowManager.tableElement.style.marginRight = this.rightMargin;
  11724. }
  11725. };
  11726. //calculate margins for rows
  11727. FrozenColumns.prototype.calcMargins = function () {
  11728. this.leftMargin = this._calcSpace(this.leftColumns, this.leftColumns.length) + "px";
  11729. this.table.columnManager.headersElement.style.marginLeft = this.leftMargin;
  11730. this.rightMargin = this._calcSpace(this.rightColumns, this.rightColumns.length) + "px";
  11731. this.table.columnManager.element.style.paddingRight = this.rightMargin;
  11732. //calculate right frozen columns
  11733. this.rightPadding = this.table.rowManager.element.clientWidth + this.table.columnManager.scrollLeft;
  11734. };
  11735. //layout calculation rows
  11736. FrozenColumns.prototype.layoutCalcRows = function () {
  11737. if (this.table.modExists("columnCalcs")) {
  11738. if (this.table.modules.columnCalcs.topInitialized && this.table.modules.columnCalcs.topRow) {
  11739. this.layoutRow(this.table.modules.columnCalcs.topRow);
  11740. }
  11741. if (this.table.modules.columnCalcs.botInitialized && this.table.modules.columnCalcs.botRow) {
  11742. this.layoutRow(this.table.modules.columnCalcs.botRow);
  11743. }
  11744. }
  11745. };
  11746. //calculate column positions and layout headers
  11747. FrozenColumns.prototype.layoutColumnPosition = function (allCells) {
  11748. var _this54 = this;
  11749. var leftParents = [];
  11750. this.leftColumns.forEach(function (column, i) {
  11751. column.modules.frozen.margin = _this54._calcSpace(_this54.leftColumns, i) + _this54.table.columnManager.scrollLeft + "px";
  11752. if (i == _this54.leftColumns.length - 1) {
  11753. column.modules.frozen.edge = true;
  11754. } else {
  11755. column.modules.frozen.edge = false;
  11756. }
  11757. if (column.parent.isGroup) {
  11758. var parentEl = _this54.getColGroupParentElement(column);
  11759. if (!leftParents.includes(parentEl)) {
  11760. _this54.layoutElement(parentEl, column);
  11761. leftParents.push(parentEl);
  11762. }
  11763. if (column.modules.frozen.edge) {
  11764. parentEl.classList.add("tabulator-frozen-" + column.modules.frozen.position);
  11765. }
  11766. } else {
  11767. _this54.layoutElement(column.getElement(), column);
  11768. }
  11769. if (allCells) {
  11770. column.cells.forEach(function (cell) {
  11771. _this54.layoutElement(cell.getElement(), column);
  11772. });
  11773. }
  11774. });
  11775. this.rightColumns.forEach(function (column, i) {
  11776. column.modules.frozen.margin = _this54.rightPadding - _this54._calcSpace(_this54.rightColumns, i + 1) + "px";
  11777. if (i == _this54.rightColumns.length - 1) {
  11778. column.modules.frozen.edge = true;
  11779. } else {
  11780. column.modules.frozen.edge = false;
  11781. }
  11782. if (column.parent.isGroup) {
  11783. _this54.layoutElement(_this54.getColGroupParentElement(column), column);
  11784. } else {
  11785. _this54.layoutElement(column.getElement(), column);
  11786. }
  11787. if (allCells) {
  11788. column.cells.forEach(function (cell) {
  11789. _this54.layoutElement(cell.getElement(), column);
  11790. });
  11791. }
  11792. });
  11793. };
  11794. FrozenColumns.prototype.getColGroupParentElement = function (column) {
  11795. return column.parent.isGroup ? this.getColGroupParentElement(column.parent) : column.getElement();
  11796. };
  11797. //layout columns appropropriatly
  11798. FrozenColumns.prototype.layout = function () {
  11799. var self = this,
  11800. rightMargin = 0;
  11801. if (self.active) {
  11802. //calculate row padding
  11803. this.calcMargins();
  11804. // self.table.rowManager.activeRows.forEach(function(row){
  11805. // self.layoutRow(row);
  11806. // });
  11807. // if(self.table.options.dataTree){
  11808. self.table.rowManager.getDisplayRows().forEach(function (row) {
  11809. if (row.type === "row") {
  11810. self.layoutRow(row);
  11811. }
  11812. });
  11813. // }
  11814. this.layoutCalcRows();
  11815. //calculate left columns
  11816. this.layoutColumnPosition(true);
  11817. // if(tableHolder.scrollHeight > tableHolder.clientHeight){
  11818. // rightMargin -= tableHolder.offsetWidth - tableHolder.clientWidth;
  11819. // }
  11820. this.table.rowManager.tableElement.style.marginRight = this.rightMargin;
  11821. }
  11822. };
  11823. FrozenColumns.prototype.layoutRow = function (row) {
  11824. var _this55 = this;
  11825. var rowEl = row.getElement();
  11826. rowEl.style.paddingLeft = this.leftMargin;
  11827. // rowEl.style.paddingRight = this.rightMargin + "px";
  11828. this.leftColumns.forEach(function (column) {
  11829. var cell = row.getCell(column);
  11830. if (cell) {
  11831. _this55.layoutElement(cell.getElement(), column);
  11832. }
  11833. });
  11834. this.rightColumns.forEach(function (column) {
  11835. var cell = row.getCell(column);
  11836. if (cell) {
  11837. _this55.layoutElement(cell.getElement(), column);
  11838. }
  11839. });
  11840. };
  11841. FrozenColumns.prototype.layoutElement = function (element, column) {
  11842. if (column.modules.frozen) {
  11843. element.style.position = "absolute";
  11844. element.style.left = column.modules.frozen.margin;
  11845. element.classList.add("tabulator-frozen");
  11846. if (column.modules.frozen.edge) {
  11847. element.classList.add("tabulator-frozen-" + column.modules.frozen.position);
  11848. }
  11849. }
  11850. };
  11851. FrozenColumns.prototype._calcSpace = function (columns, index) {
  11852. var width = 0;
  11853. for (var i = 0; i < index; i++) {
  11854. if (columns[i].visible) {
  11855. width += columns[i].getWidth();
  11856. }
  11857. }
  11858. return width;
  11859. };
  11860. Tabulator.prototype.registerModule("frozenColumns", FrozenColumns);
  11861. var FrozenRows = function FrozenRows(table) {
  11862. this.table = table; //hold Tabulator object
  11863. this.topElement = document.createElement("div");
  11864. this.rows = [];
  11865. this.displayIndex = 0; //index in display pipeline
  11866. };
  11867. FrozenRows.prototype.initialize = function () {
  11868. this.rows = [];
  11869. this.topElement.classList.add("tabulator-frozen-rows-holder");
  11870. // this.table.columnManager.element.append(this.topElement);
  11871. this.table.columnManager.getElement().insertBefore(this.topElement, this.table.columnManager.headersElement.nextSibling);
  11872. };
  11873. FrozenRows.prototype.setDisplayIndex = function (index) {
  11874. this.displayIndex = index;
  11875. };
  11876. FrozenRows.prototype.getDisplayIndex = function () {
  11877. return this.displayIndex;
  11878. };
  11879. FrozenRows.prototype.isFrozen = function () {
  11880. return !!this.rows.length;
  11881. };
  11882. //filter frozen rows out of display data
  11883. FrozenRows.prototype.getRows = function (rows) {
  11884. var self = this,
  11885. frozen = [],
  11886. output = rows.slice(0);
  11887. this.rows.forEach(function (row) {
  11888. var index = output.indexOf(row);
  11889. if (index > -1) {
  11890. output.splice(index, 1);
  11891. }
  11892. });
  11893. return output;
  11894. };
  11895. FrozenRows.prototype.freezeRow = function (row) {
  11896. if (!row.modules.frozen) {
  11897. row.modules.frozen = true;
  11898. this.topElement.appendChild(row.getElement());
  11899. row.initialize();
  11900. row.normalizeHeight();
  11901. this.table.rowManager.adjustTableSize();
  11902. this.rows.push(row);
  11903. this.table.rowManager.refreshActiveData("display");
  11904. this.styleRows();
  11905. } else {
  11906. console.warn("Freeze Error - Row is already frozen");
  11907. }
  11908. };
  11909. FrozenRows.prototype.unfreezeRow = function (row) {
  11910. var index = this.rows.indexOf(row);
  11911. if (row.modules.frozen) {
  11912. row.modules.frozen = false;
  11913. var rowEl = row.getElement();
  11914. rowEl.parentNode.removeChild(rowEl);
  11915. this.table.rowManager.adjustTableSize();
  11916. this.rows.splice(index, 1);
  11917. this.table.rowManager.refreshActiveData("display");
  11918. if (this.rows.length) {
  11919. this.styleRows();
  11920. }
  11921. } else {
  11922. console.warn("Freeze Error - Row is already unfrozen");
  11923. }
  11924. };
  11925. FrozenRows.prototype.styleRows = function (row) {
  11926. var self = this;
  11927. this.rows.forEach(function (row, i) {
  11928. self.table.rowManager.styleRow(row, i);
  11929. });
  11930. };
  11931. Tabulator.prototype.registerModule("frozenRows", FrozenRows);
  11932. //public group object
  11933. var GroupComponent = function GroupComponent(group) {
  11934. this._group = group;
  11935. this.type = "GroupComponent";
  11936. };
  11937. GroupComponent.prototype.getKey = function () {
  11938. return this._group.key;
  11939. };
  11940. GroupComponent.prototype.getField = function () {
  11941. return this._group.field;
  11942. };
  11943. GroupComponent.prototype.getElement = function () {
  11944. return this._group.element;
  11945. };
  11946. GroupComponent.prototype.getRows = function () {
  11947. return this._group.getRows(true);
  11948. };
  11949. GroupComponent.prototype.getSubGroups = function () {
  11950. return this._group.getSubGroups(true);
  11951. };
  11952. GroupComponent.prototype.getParentGroup = function () {
  11953. return this._group.parent ? this._group.parent.getComponent() : false;
  11954. };
  11955. GroupComponent.prototype.getVisibility = function () {
  11956. return this._group.visible;
  11957. };
  11958. GroupComponent.prototype.show = function () {
  11959. this._group.show();
  11960. };
  11961. GroupComponent.prototype.hide = function () {
  11962. this._group.hide();
  11963. };
  11964. GroupComponent.prototype.toggle = function () {
  11965. this._group.toggleVisibility();
  11966. };
  11967. GroupComponent.prototype._getSelf = function () {
  11968. return this._group;
  11969. };
  11970. GroupComponent.prototype.getTable = function () {
  11971. return this._group.groupManager.table;
  11972. };
  11973. //////////////////////////////////////////////////
  11974. //////////////// Group Functions /////////////////
  11975. //////////////////////////////////////////////////
  11976. var Group = function Group(groupManager, parent, level, key, field, generator, oldGroup) {
  11977. this.groupManager = groupManager;
  11978. this.parent = parent;
  11979. this.key = key;
  11980. this.level = level;
  11981. this.field = field;
  11982. this.hasSubGroups = level < groupManager.groupIDLookups.length - 1;
  11983. this.addRow = this.hasSubGroups ? this._addRowToGroup : this._addRow;
  11984. this.type = "group"; //type of element
  11985. this.old = oldGroup;
  11986. this.rows = [];
  11987. this.groups = [];
  11988. this.groupList = [];
  11989. this.generator = generator;
  11990. this.elementContents = false;
  11991. this.height = 0;
  11992. this.outerHeight = 0;
  11993. this.initialized = false;
  11994. this.calcs = {};
  11995. this.initialized = false;
  11996. this.modules = {};
  11997. this.arrowElement = false;
  11998. this.visible = oldGroup ? oldGroup.visible : typeof groupManager.startOpen[level] !== "undefined" ? groupManager.startOpen[level] : groupManager.startOpen[0];
  11999. this.createElements();
  12000. this.addBindings();
  12001. this.createValueGroups();
  12002. };
  12003. Group.prototype.wipe = function () {
  12004. if (this.groupList.length) {
  12005. this.groupList.forEach(function (group) {
  12006. group.wipe();
  12007. });
  12008. } else {
  12009. this.element = false;
  12010. this.arrowElement = false;
  12011. this.elementContents = false;
  12012. }
  12013. };
  12014. Group.prototype.createElements = function () {
  12015. var arrow = document.createElement("div");
  12016. arrow.classList.add("tabulator-arrow");
  12017. this.element = document.createElement("div");
  12018. this.element.classList.add("tabulator-row");
  12019. this.element.classList.add("tabulator-group");
  12020. this.element.classList.add("tabulator-group-level-" + this.level);
  12021. this.element.setAttribute("role", "rowgroup");
  12022. this.arrowElement = document.createElement("div");
  12023. this.arrowElement.classList.add("tabulator-group-toggle");
  12024. this.arrowElement.appendChild(arrow);
  12025. //setup movable rows
  12026. if (this.groupManager.table.options.movableRows !== false && this.groupManager.table.modExists("moveRow")) {
  12027. this.groupManager.table.modules.moveRow.initializeGroupHeader(this);
  12028. }
  12029. };
  12030. Group.prototype.createValueGroups = function () {
  12031. var _this56 = this;
  12032. var level = this.level + 1;
  12033. if (this.groupManager.allowedValues && this.groupManager.allowedValues[level]) {
  12034. this.groupManager.allowedValues[level].forEach(function (value) {
  12035. _this56._createGroup(value, level);
  12036. });
  12037. }
  12038. };
  12039. Group.prototype.addBindings = function () {
  12040. var self = this,
  12041. dblTap,
  12042. tapHold,
  12043. tap,
  12044. toggleElement;
  12045. //handle group click events
  12046. if (self.groupManager.table.options.groupClick) {
  12047. self.element.addEventListener("click", function (e) {
  12048. self.groupManager.table.options.groupClick.call(self.groupManager.table, e, self.getComponent());
  12049. });
  12050. }
  12051. if (self.groupManager.table.options.groupDblClick) {
  12052. self.element.addEventListener("dblclick", function (e) {
  12053. self.groupManager.table.options.groupDblClick.call(self.groupManager.table, e, self.getComponent());
  12054. });
  12055. }
  12056. if (self.groupManager.table.options.groupContext) {
  12057. self.element.addEventListener("contextmenu", function (e) {
  12058. self.groupManager.table.options.groupContext.call(self.groupManager.table, e, self.getComponent());
  12059. });
  12060. }
  12061. if (self.groupManager.table.options.groupTap) {
  12062. tap = false;
  12063. self.element.addEventListener("touchstart", function (e) {
  12064. tap = true;
  12065. }, { passive: true });
  12066. self.element.addEventListener("touchend", function (e) {
  12067. if (tap) {
  12068. self.groupManager.table.options.groupTap(e, self.getComponent());
  12069. }
  12070. tap = false;
  12071. });
  12072. }
  12073. if (self.groupManager.table.options.groupDblTap) {
  12074. dblTap = null;
  12075. self.element.addEventListener("touchend", function (e) {
  12076. if (dblTap) {
  12077. clearTimeout(dblTap);
  12078. dblTap = null;
  12079. self.groupManager.table.options.groupDblTap(e, self.getComponent());
  12080. } else {
  12081. dblTap = setTimeout(function () {
  12082. clearTimeout(dblTap);
  12083. dblTap = null;
  12084. }, 300);
  12085. }
  12086. });
  12087. }
  12088. if (self.groupManager.table.options.groupTapHold) {
  12089. tapHold = null;
  12090. self.element.addEventListener("touchstart", function (e) {
  12091. clearTimeout(tapHold);
  12092. tapHold = setTimeout(function () {
  12093. clearTimeout(tapHold);
  12094. tapHold = null;
  12095. tap = false;
  12096. self.groupManager.table.options.groupTapHold(e, self.getComponent());
  12097. }, 1000);
  12098. }, { passive: true });
  12099. self.element.addEventListener("touchend", function (e) {
  12100. clearTimeout(tapHold);
  12101. tapHold = null;
  12102. });
  12103. }
  12104. if (self.groupManager.table.options.groupToggleElement) {
  12105. toggleElement = self.groupManager.table.options.groupToggleElement == "arrow" ? self.arrowElement : self.element;
  12106. toggleElement.addEventListener("click", function (e) {
  12107. e.stopPropagation();
  12108. e.stopImmediatePropagation();
  12109. self.toggleVisibility();
  12110. });
  12111. }
  12112. };
  12113. Group.prototype._createGroup = function (groupID, level) {
  12114. var groupKey = level + "_" + groupID;
  12115. var group = new Group(this.groupManager, this, level, groupID, this.groupManager.groupIDLookups[level].field, this.groupManager.headerGenerator[level] || this.groupManager.headerGenerator[0], this.old ? this.old.groups[groupKey] : false);
  12116. this.groups[groupKey] = group;
  12117. this.groupList.push(group);
  12118. };
  12119. Group.prototype._addRowToGroup = function (row) {
  12120. var level = this.level + 1;
  12121. if (this.hasSubGroups) {
  12122. var groupID = this.groupManager.groupIDLookups[level].func(row.getData()),
  12123. groupKey = level + "_" + groupID;
  12124. if (this.groupManager.allowedValues && this.groupManager.allowedValues[level]) {
  12125. if (this.groups[groupKey]) {
  12126. this.groups[groupKey].addRow(row);
  12127. }
  12128. } else {
  12129. if (!this.groups[groupKey]) {
  12130. this._createGroup(groupID, level);
  12131. }
  12132. this.groups[groupKey].addRow(row);
  12133. }
  12134. }
  12135. };
  12136. Group.prototype._addRow = function (row) {
  12137. this.rows.push(row);
  12138. row.modules.group = this;
  12139. };
  12140. Group.prototype.insertRow = function (row, to, after) {
  12141. var data = this.conformRowData({});
  12142. row.updateData(data);
  12143. var toIndex = this.rows.indexOf(to);
  12144. if (toIndex > -1) {
  12145. if (after) {
  12146. this.rows.splice(toIndex + 1, 0, row);
  12147. } else {
  12148. this.rows.splice(toIndex, 0, row);
  12149. }
  12150. } else {
  12151. if (after) {
  12152. this.rows.push(row);
  12153. } else {
  12154. this.rows.unshift(row);
  12155. }
  12156. }
  12157. row.modules.group = this;
  12158. this.generateGroupHeaderContents();
  12159. if (this.groupManager.table.modExists("columnCalcs") && this.groupManager.table.options.columnCalcs != "table") {
  12160. this.groupManager.table.modules.columnCalcs.recalcGroup(this);
  12161. }
  12162. this.groupManager.updateGroupRows(true);
  12163. };
  12164. Group.prototype.scrollHeader = function (left) {
  12165. this.arrowElement.style.marginLeft = left;
  12166. this.groupList.forEach(function (child) {
  12167. child.scrollHeader(left);
  12168. });
  12169. };
  12170. Group.prototype.getRowIndex = function (row) {};
  12171. //update row data to match grouping contraints
  12172. Group.prototype.conformRowData = function (data) {
  12173. if (this.field) {
  12174. data[this.field] = this.key;
  12175. } else {
  12176. console.warn("Data Conforming Error - Cannot conform row data to match new group as groupBy is a function");
  12177. }
  12178. if (this.parent) {
  12179. data = this.parent.conformRowData(data);
  12180. }
  12181. return data;
  12182. };
  12183. Group.prototype.removeRow = function (row) {
  12184. var index = this.rows.indexOf(row);
  12185. var el = row.getElement();
  12186. if (index > -1) {
  12187. this.rows.splice(index, 1);
  12188. }
  12189. if (!this.groupManager.table.options.groupValues && !this.rows.length) {
  12190. if (this.parent) {
  12191. this.parent.removeGroup(this);
  12192. } else {
  12193. this.groupManager.removeGroup(this);
  12194. }
  12195. this.groupManager.updateGroupRows(true);
  12196. } else {
  12197. if (el.parentNode) {
  12198. el.parentNode.removeChild(el);
  12199. }
  12200. this.generateGroupHeaderContents();
  12201. if (this.groupManager.table.modExists("columnCalcs") && this.groupManager.table.options.columnCalcs != "table") {
  12202. this.groupManager.table.modules.columnCalcs.recalcGroup(this);
  12203. }
  12204. }
  12205. };
  12206. Group.prototype.removeGroup = function (group) {
  12207. var groupKey = group.level + "_" + group.key,
  12208. index;
  12209. if (this.groups[groupKey]) {
  12210. delete this.groups[groupKey];
  12211. index = this.groupList.indexOf(group);
  12212. if (index > -1) {
  12213. this.groupList.splice(index, 1);
  12214. }
  12215. if (!this.groupList.length) {
  12216. if (this.parent) {
  12217. this.parent.removeGroup(this);
  12218. } else {
  12219. this.groupManager.removeGroup(this);
  12220. }
  12221. }
  12222. }
  12223. };
  12224. Group.prototype.getHeadersAndRows = function (noCalc) {
  12225. var output = [];
  12226. output.push(this);
  12227. this._visSet();
  12228. if (this.visible) {
  12229. if (this.groupList.length) {
  12230. this.groupList.forEach(function (group) {
  12231. output = output.concat(group.getHeadersAndRows(noCalc));
  12232. });
  12233. } else {
  12234. if (!noCalc && this.groupManager.table.options.columnCalcs != "table" && this.groupManager.table.modExists("columnCalcs") && this.groupManager.table.modules.columnCalcs.hasTopCalcs()) {
  12235. if (this.calcs.top) {
  12236. this.calcs.top.detachElement();
  12237. this.calcs.top.deleteCells();
  12238. }
  12239. this.calcs.top = this.groupManager.table.modules.columnCalcs.generateTopRow(this.rows);
  12240. output.push(this.calcs.top);
  12241. }
  12242. output = output.concat(this.rows);
  12243. if (!noCalc && this.groupManager.table.options.columnCalcs != "table" && this.groupManager.table.modExists("columnCalcs") && this.groupManager.table.modules.columnCalcs.hasBottomCalcs()) {
  12244. if (this.calcs.bottom) {
  12245. this.calcs.bottom.detachElement();
  12246. this.calcs.bottom.deleteCells();
  12247. }
  12248. this.calcs.bottom = this.groupManager.table.modules.columnCalcs.generateBottomRow(this.rows);
  12249. output.push(this.calcs.bottom);
  12250. }
  12251. }
  12252. } else {
  12253. if (!this.groupList.length && this.groupManager.table.options.columnCalcs != "table") {
  12254. if (this.groupManager.table.modExists("columnCalcs")) {
  12255. if (!noCalc && this.groupManager.table.modules.columnCalcs.hasTopCalcs()) {
  12256. if (this.calcs.top) {
  12257. this.calcs.top.detachElement();
  12258. this.calcs.top.deleteCells();
  12259. }
  12260. if (this.groupManager.table.options.groupClosedShowCalcs) {
  12261. this.calcs.top = this.groupManager.table.modules.columnCalcs.generateTopRow(this.rows);
  12262. output.push(this.calcs.top);
  12263. }
  12264. }
  12265. if (!noCalc && this.groupManager.table.modules.columnCalcs.hasBottomCalcs()) {
  12266. if (this.calcs.bottom) {
  12267. this.calcs.bottom.detachElement();
  12268. this.calcs.bottom.deleteCells();
  12269. }
  12270. if (this.groupManager.table.options.groupClosedShowCalcs) {
  12271. this.calcs.bottom = this.groupManager.table.modules.columnCalcs.generateBottomRow(this.rows);
  12272. output.push(this.calcs.bottom);
  12273. }
  12274. }
  12275. }
  12276. }
  12277. }
  12278. return output;
  12279. };
  12280. Group.prototype.getData = function (visible, transform) {
  12281. var self = this,
  12282. output = [];
  12283. this._visSet();
  12284. if (!visible || visible && this.visible) {
  12285. this.rows.forEach(function (row) {
  12286. output.push(row.getData(transform || "data"));
  12287. });
  12288. }
  12289. return output;
  12290. };
  12291. // Group.prototype.getRows = function(){
  12292. // this._visSet();
  12293. // return this.visible ? this.rows : [];
  12294. // };
  12295. Group.prototype.getRowCount = function () {
  12296. var count = 0;
  12297. if (this.groupList.length) {
  12298. this.groupList.forEach(function (group) {
  12299. count += group.getRowCount();
  12300. });
  12301. } else {
  12302. count = this.rows.length;
  12303. }
  12304. return count;
  12305. };
  12306. Group.prototype.toggleVisibility = function () {
  12307. if (this.visible) {
  12308. this.hide();
  12309. } else {
  12310. this.show();
  12311. }
  12312. };
  12313. Group.prototype.hide = function () {
  12314. this.visible = false;
  12315. if (this.groupManager.table.rowManager.getRenderMode() == "classic" && !this.groupManager.table.options.pagination) {
  12316. this.element.classList.remove("tabulator-group-visible");
  12317. if (this.groupList.length) {
  12318. this.groupList.forEach(function (group) {
  12319. var rows = group.getHeadersAndRows();
  12320. rows.forEach(function (row) {
  12321. row.detachElement();
  12322. });
  12323. });
  12324. } else {
  12325. this.rows.forEach(function (row) {
  12326. var rowEl = row.getElement();
  12327. rowEl.parentNode.removeChild(rowEl);
  12328. });
  12329. }
  12330. this.groupManager.table.rowManager.setDisplayRows(this.groupManager.updateGroupRows(), this.groupManager.getDisplayIndex());
  12331. this.groupManager.table.rowManager.checkClassicModeGroupHeaderWidth();
  12332. } else {
  12333. this.groupManager.updateGroupRows(true);
  12334. }
  12335. this.groupManager.table.options.groupVisibilityChanged.call(this.table, this.getComponent(), false);
  12336. };
  12337. Group.prototype.show = function () {
  12338. var self = this;
  12339. self.visible = true;
  12340. if (this.groupManager.table.rowManager.getRenderMode() == "classic" && !this.groupManager.table.options.pagination) {
  12341. this.element.classList.add("tabulator-group-visible");
  12342. var prev = self.getElement();
  12343. if (this.groupList.length) {
  12344. this.groupList.forEach(function (group) {
  12345. var rows = group.getHeadersAndRows();
  12346. rows.forEach(function (row) {
  12347. var rowEl = row.getElement();
  12348. prev.parentNode.insertBefore(rowEl, prev.nextSibling);
  12349. row.initialize();
  12350. prev = rowEl;
  12351. });
  12352. });
  12353. } else {
  12354. self.rows.forEach(function (row) {
  12355. var rowEl = row.getElement();
  12356. prev.parentNode.insertBefore(rowEl, prev.nextSibling);
  12357. row.initialize();
  12358. prev = rowEl;
  12359. });
  12360. }
  12361. this.groupManager.table.rowManager.setDisplayRows(this.groupManager.updateGroupRows(), this.groupManager.getDisplayIndex());
  12362. this.groupManager.table.rowManager.checkClassicModeGroupHeaderWidth();
  12363. } else {
  12364. this.groupManager.updateGroupRows(true);
  12365. }
  12366. this.groupManager.table.options.groupVisibilityChanged.call(this.table, this.getComponent(), true);
  12367. };
  12368. Group.prototype._visSet = function () {
  12369. var data = [];
  12370. if (typeof this.visible == "function") {
  12371. this.rows.forEach(function (row) {
  12372. data.push(row.getData());
  12373. });
  12374. this.visible = this.visible(this.key, this.getRowCount(), data, this.getComponent());
  12375. }
  12376. };
  12377. Group.prototype.getRowGroup = function (row) {
  12378. var match = false;
  12379. if (this.groupList.length) {
  12380. this.groupList.forEach(function (group) {
  12381. var result = group.getRowGroup(row);
  12382. if (result) {
  12383. match = result;
  12384. }
  12385. });
  12386. } else {
  12387. if (this.rows.find(function (item) {
  12388. return item === row;
  12389. })) {
  12390. match = this;
  12391. }
  12392. }
  12393. return match;
  12394. };
  12395. Group.prototype.getSubGroups = function (component) {
  12396. var output = [];
  12397. this.groupList.forEach(function (child) {
  12398. output.push(component ? child.getComponent() : child);
  12399. });
  12400. return output;
  12401. };
  12402. Group.prototype.getRows = function (compoment) {
  12403. var output = [];
  12404. this.rows.forEach(function (row) {
  12405. output.push(compoment ? row.getComponent() : row);
  12406. });
  12407. return output;
  12408. };
  12409. Group.prototype.generateGroupHeaderContents = function () {
  12410. var data = [];
  12411. this.rows.forEach(function (row) {
  12412. data.push(row.getData());
  12413. });
  12414. this.elementContents = this.generator(this.key, this.getRowCount(), data, this.getComponent());
  12415. while (this.element.firstChild) {
  12416. this.element.removeChild(this.element.firstChild);
  12417. }if (typeof this.elementContents === "string") {
  12418. this.element.innerHTML = this.elementContents;
  12419. } else {
  12420. this.element.appendChild(this.elementContents);
  12421. }
  12422. this.element.insertBefore(this.arrowElement, this.element.firstChild);
  12423. };
  12424. ////////////// Standard Row Functions //////////////
  12425. Group.prototype.getElement = function () {
  12426. this.addBindingsd = false;
  12427. this._visSet();
  12428. if (this.visible) {
  12429. this.element.classList.add("tabulator-group-visible");
  12430. } else {
  12431. this.element.classList.remove("tabulator-group-visible");
  12432. }
  12433. for (var i = 0; i < this.element.childNodes.length; ++i) {
  12434. this.element.childNodes[i].parentNode.removeChild(this.element.childNodes[i]);
  12435. }
  12436. this.generateGroupHeaderContents();
  12437. // this.addBindings();
  12438. return this.element;
  12439. };
  12440. Group.prototype.detachElement = function () {
  12441. if (this.element && this.element.parentNode) {
  12442. this.element.parentNode.removeChild(this.element);
  12443. }
  12444. };
  12445. //normalize the height of elements in the row
  12446. Group.prototype.normalizeHeight = function () {
  12447. this.setHeight(this.element.clientHeight);
  12448. };
  12449. Group.prototype.initialize = function (force) {
  12450. if (!this.initialized || force) {
  12451. this.normalizeHeight();
  12452. this.initialized = true;
  12453. }
  12454. };
  12455. Group.prototype.reinitialize = function () {
  12456. this.initialized = false;
  12457. this.height = 0;
  12458. if (Tabulator.prototype.helpers.elVisible(this.element)) {
  12459. this.initialize(true);
  12460. }
  12461. };
  12462. Group.prototype.setHeight = function (height) {
  12463. if (this.height != height) {
  12464. this.height = height;
  12465. this.outerHeight = this.element.offsetHeight;
  12466. }
  12467. };
  12468. //return rows outer height
  12469. Group.prototype.getHeight = function () {
  12470. return this.outerHeight;
  12471. };
  12472. Group.prototype.getGroup = function () {
  12473. return this;
  12474. };
  12475. Group.prototype.reinitializeHeight = function () {};
  12476. Group.prototype.calcHeight = function () {};
  12477. Group.prototype.setCellHeight = function () {};
  12478. Group.prototype.clearCellHeight = function () {};
  12479. //////////////// Object Generation /////////////////
  12480. Group.prototype.getComponent = function () {
  12481. return new GroupComponent(this);
  12482. };
  12483. //////////////////////////////////////////////////
  12484. ////////////// Group Row Extension ///////////////
  12485. //////////////////////////////////////////////////
  12486. var GroupRows = function GroupRows(table) {
  12487. this.table = table; //hold Tabulator object
  12488. this.groupIDLookups = false; //enable table grouping and set field to group by
  12489. this.startOpen = [function () {
  12490. return false;
  12491. }]; //starting state of group
  12492. this.headerGenerator = [function () {
  12493. return "";
  12494. }];
  12495. this.groupList = []; //ordered list of groups
  12496. this.allowedValues = false;
  12497. this.groups = {}; //hold row groups
  12498. this.displayIndex = 0; //index in display pipeline
  12499. };
  12500. //initialize group configuration
  12501. GroupRows.prototype.initialize = function () {
  12502. var self = this,
  12503. groupBy = self.table.options.groupBy,
  12504. startOpen = self.table.options.groupStartOpen,
  12505. groupHeader = self.table.options.groupHeader;
  12506. this.allowedValues = self.table.options.groupValues;
  12507. if (Array.isArray(groupBy) && Array.isArray(groupHeader) && groupBy.length > groupHeader.length) {
  12508. console.warn("Error creating group headers, groupHeader array is shorter than groupBy array");
  12509. }
  12510. self.headerGenerator = [function () {
  12511. return "";
  12512. }];
  12513. this.startOpen = [function () {
  12514. return false;
  12515. }]; //starting state of group
  12516. self.table.modules.localize.bind("groups|item", function (langValue, lang) {
  12517. self.headerGenerator[0] = function (value, count, data) {
  12518. //header layout function
  12519. return (typeof value === "undefined" ? "" : value) + "<span>(" + count + " " + (count === 1 ? langValue : lang.groups.items) + ")</span>";
  12520. };
  12521. });
  12522. this.groupIDLookups = [];
  12523. if (Array.isArray(groupBy) || groupBy) {
  12524. if (this.table.modExists("columnCalcs") && this.table.options.columnCalcs != "table" && this.table.options.columnCalcs != "both") {
  12525. this.table.modules.columnCalcs.removeCalcs();
  12526. }
  12527. } else {
  12528. if (this.table.modExists("columnCalcs") && this.table.options.columnCalcs != "group") {
  12529. var cols = this.table.columnManager.getRealColumns();
  12530. cols.forEach(function (col) {
  12531. if (col.definition.topCalc) {
  12532. self.table.modules.columnCalcs.initializeTopRow();
  12533. }
  12534. if (col.definition.bottomCalc) {
  12535. self.table.modules.columnCalcs.initializeBottomRow();
  12536. }
  12537. });
  12538. }
  12539. }
  12540. if (!Array.isArray(groupBy)) {
  12541. groupBy = [groupBy];
  12542. }
  12543. groupBy.forEach(function (group, i) {
  12544. var lookupFunc, column;
  12545. if (typeof group == "function") {
  12546. lookupFunc = group;
  12547. } else {
  12548. column = self.table.columnManager.getColumnByField(group);
  12549. if (column) {
  12550. lookupFunc = function lookupFunc(data) {
  12551. return column.getFieldValue(data);
  12552. };
  12553. } else {
  12554. lookupFunc = function lookupFunc(data) {
  12555. return data[group];
  12556. };
  12557. }
  12558. }
  12559. self.groupIDLookups.push({
  12560. field: typeof group === "function" ? false : group,
  12561. func: lookupFunc,
  12562. values: self.allowedValues ? self.allowedValues[i] : false
  12563. });
  12564. });
  12565. if (startOpen) {
  12566. if (!Array.isArray(startOpen)) {
  12567. startOpen = [startOpen];
  12568. }
  12569. startOpen.forEach(function (level) {
  12570. level = typeof level == "function" ? level : function () {
  12571. return true;
  12572. };
  12573. });
  12574. self.startOpen = startOpen;
  12575. }
  12576. if (groupHeader) {
  12577. self.headerGenerator = Array.isArray(groupHeader) ? groupHeader : [groupHeader];
  12578. }
  12579. this.initialized = true;
  12580. };
  12581. GroupRows.prototype.setDisplayIndex = function (index) {
  12582. this.displayIndex = index;
  12583. };
  12584. GroupRows.prototype.getDisplayIndex = function () {
  12585. return this.displayIndex;
  12586. };
  12587. //return appropriate rows with group headers
  12588. GroupRows.prototype.getRows = function (rows) {
  12589. if (this.groupIDLookups.length) {
  12590. this.table.options.dataGrouping.call(this.table);
  12591. this.generateGroups(rows);
  12592. if (this.table.options.dataGrouped) {
  12593. this.table.options.dataGrouped.call(this.table, this.getGroups(true));
  12594. }
  12595. return this.updateGroupRows();
  12596. } else {
  12597. return rows.slice(0);
  12598. }
  12599. };
  12600. GroupRows.prototype.getGroups = function (compoment) {
  12601. var groupComponents = [];
  12602. this.groupList.forEach(function (group) {
  12603. groupComponents.push(compoment ? group.getComponent() : group);
  12604. });
  12605. return groupComponents;
  12606. };
  12607. GroupRows.prototype.getChildGroups = function (group) {
  12608. var _this57 = this;
  12609. var groupComponents = [];
  12610. if (!group) {
  12611. group = this;
  12612. }
  12613. group.groupList.forEach(function (child) {
  12614. if (child.groupList.length) {
  12615. groupComponents = groupComponents.concat(_this57.getChildGroups(child));
  12616. } else {
  12617. groupComponents.push(child);
  12618. }
  12619. });
  12620. return groupComponents;
  12621. };
  12622. GroupRows.prototype.wipe = function () {
  12623. this.groupList.forEach(function (group) {
  12624. group.wipe();
  12625. });
  12626. };
  12627. GroupRows.prototype.pullGroupListData = function (groupList) {
  12628. var self = this;
  12629. var groupListData = [];
  12630. groupList.forEach(function (group) {
  12631. var groupHeader = {};
  12632. groupHeader.level = 0;
  12633. groupHeader.rowCount = 0;
  12634. groupHeader.headerContent = "";
  12635. var childData = [];
  12636. if (group.hasSubGroups) {
  12637. childData = self.pullGroupListData(group.groupList);
  12638. groupHeader.level = group.level;
  12639. groupHeader.rowCount = childData.length - group.groupList.length; // data length minus number of sub-headers
  12640. groupHeader.headerContent = group.generator(group.key, groupHeader.rowCount, group.rows, group);
  12641. groupListData.push(groupHeader);
  12642. groupListData = groupListData.concat(childData);
  12643. } else {
  12644. groupHeader.level = group.level;
  12645. groupHeader.headerContent = group.generator(group.key, group.rows.length, group.rows, group);
  12646. groupHeader.rowCount = group.getRows().length;
  12647. groupListData.push(groupHeader);
  12648. group.getRows().forEach(function (row) {
  12649. groupListData.push(row.getData("data"));
  12650. });
  12651. }
  12652. });
  12653. return groupListData;
  12654. };
  12655. GroupRows.prototype.getGroupedData = function () {
  12656. return this.pullGroupListData(this.groupList);
  12657. };
  12658. GroupRows.prototype.getRowGroup = function (row) {
  12659. var match = false;
  12660. this.groupList.forEach(function (group) {
  12661. var result = group.getRowGroup(row);
  12662. if (result) {
  12663. match = result;
  12664. }
  12665. });
  12666. return match;
  12667. };
  12668. GroupRows.prototype.countGroups = function () {
  12669. return this.groupList.length;
  12670. };
  12671. GroupRows.prototype.generateGroups = function (rows) {
  12672. var self = this,
  12673. oldGroups = self.groups;
  12674. self.groups = {};
  12675. self.groupList = [];
  12676. if (this.allowedValues && this.allowedValues[0]) {
  12677. this.allowedValues[0].forEach(function (value) {
  12678. self.createGroup(value, 0, oldGroups);
  12679. });
  12680. rows.forEach(function (row) {
  12681. self.assignRowToExistingGroup(row, oldGroups);
  12682. });
  12683. } else {
  12684. rows.forEach(function (row) {
  12685. self.assignRowToGroup(row, oldGroups);
  12686. });
  12687. }
  12688. };
  12689. GroupRows.prototype.createGroup = function (groupID, level, oldGroups) {
  12690. var groupKey = level + "_" + groupID,
  12691. group;
  12692. oldGroups = oldGroups || [];
  12693. group = new Group(this, false, level, groupID, this.groupIDLookups[0].field, this.headerGenerator[0], oldGroups[groupKey]);
  12694. this.groups[groupKey] = group;
  12695. this.groupList.push(group);
  12696. };
  12697. // GroupRows.prototype.assignRowToGroup = function(row, oldGroups){
  12698. // var groupID = this.groupIDLookups[0].func(row.getData()),
  12699. // groupKey = "0_" + groupID;
  12700. // if(!this.groups[groupKey]){
  12701. // this.createGroup(groupID, 0, oldGroups);
  12702. // }
  12703. // this.groups[groupKey].addRow(row);
  12704. // };
  12705. GroupRows.prototype.assignRowToExistingGroup = function (row, oldGroups) {
  12706. var groupID = this.groupIDLookups[0].func(row.getData()),
  12707. groupKey = "0_" + groupID;
  12708. if (this.groups[groupKey]) {
  12709. this.groups[groupKey].addRow(row);
  12710. }
  12711. };
  12712. GroupRows.prototype.assignRowToGroup = function (row, oldGroups) {
  12713. var groupID = this.groupIDLookups[0].func(row.getData()),
  12714. newGroupNeeded = !this.groups["0_" + groupID];
  12715. if (newGroupNeeded) {
  12716. this.createGroup(groupID, 0, oldGroups);
  12717. }
  12718. this.groups["0_" + groupID].addRow(row);
  12719. return !newGroupNeeded;
  12720. };
  12721. GroupRows.prototype.updateGroupRows = function (force) {
  12722. var self = this,
  12723. output = [],
  12724. oldRowCount;
  12725. self.groupList.forEach(function (group) {
  12726. output = output.concat(group.getHeadersAndRows());
  12727. });
  12728. //force update of table display
  12729. if (force) {
  12730. var displayIndex = self.table.rowManager.setDisplayRows(output, this.getDisplayIndex());
  12731. if (displayIndex !== true) {
  12732. this.setDisplayIndex(displayIndex);
  12733. }
  12734. self.table.rowManager.refreshActiveData("group", true, true);
  12735. }
  12736. return output;
  12737. };
  12738. GroupRows.prototype.scrollHeaders = function (left) {
  12739. left = left + "px";
  12740. this.groupList.forEach(function (group) {
  12741. group.scrollHeader(left);
  12742. });
  12743. };
  12744. GroupRows.prototype.removeGroup = function (group) {
  12745. var groupKey = group.level + "_" + group.key,
  12746. index;
  12747. if (this.groups[groupKey]) {
  12748. delete this.groups[groupKey];
  12749. index = this.groupList.indexOf(group);
  12750. if (index > -1) {
  12751. this.groupList.splice(index, 1);
  12752. }
  12753. }
  12754. };
  12755. Tabulator.prototype.registerModule("groupRows", GroupRows);
  12756. var History = function History(table) {
  12757. this.table = table; //hold Tabulator object
  12758. this.history = [];
  12759. this.index = -1;
  12760. };
  12761. History.prototype.clear = function () {
  12762. this.history = [];
  12763. this.index = -1;
  12764. };
  12765. History.prototype.action = function (type, component, data) {
  12766. this.history = this.history.slice(0, this.index + 1);
  12767. this.history.push({
  12768. type: type,
  12769. component: component,
  12770. data: data
  12771. });
  12772. this.index++;
  12773. };
  12774. History.prototype.getHistoryUndoSize = function () {
  12775. return this.index + 1;
  12776. };
  12777. History.prototype.getHistoryRedoSize = function () {
  12778. return this.history.length - (this.index + 1);
  12779. };
  12780. History.prototype.undo = function () {
  12781. if (this.index > -1) {
  12782. var action = this.history[this.index];
  12783. this.undoers[action.type].call(this, action);
  12784. this.index--;
  12785. this.table.options.historyUndo.call(this.table, action.type, action.component.getComponent(), action.data);
  12786. return true;
  12787. } else {
  12788. console.warn("History Undo Error - No more history to undo");
  12789. return false;
  12790. }
  12791. };
  12792. History.prototype.redo = function () {
  12793. if (this.history.length - 1 > this.index) {
  12794. this.index++;
  12795. var action = this.history[this.index];
  12796. this.redoers[action.type].call(this, action);
  12797. this.table.options.historyRedo.call(this.table, action.type, action.component.getComponent(), action.data);
  12798. return true;
  12799. } else {
  12800. console.warn("History Redo Error - No more history to redo");
  12801. return false;
  12802. }
  12803. };
  12804. History.prototype.undoers = {
  12805. cellEdit: function cellEdit(action) {
  12806. action.component.setValueProcessData(action.data.oldValue);
  12807. },
  12808. rowAdd: function rowAdd(action) {
  12809. action.component.deleteActual();
  12810. },
  12811. rowDelete: function rowDelete(action) {
  12812. var newRow = this.table.rowManager.addRowActual(action.data.data, action.data.pos, action.data.index);
  12813. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  12814. this.table.modules.groupRows.updateGroupRows(true);
  12815. }
  12816. this._rebindRow(action.component, newRow);
  12817. },
  12818. rowMove: function rowMove(action) {
  12819. this.table.rowManager.moveRowActual(action.component, this.table.rowManager.rows[action.data.posFrom], !action.data.after);
  12820. this.table.rowManager.redraw();
  12821. }
  12822. };
  12823. History.prototype.redoers = {
  12824. cellEdit: function cellEdit(action) {
  12825. action.component.setValueProcessData(action.data.newValue);
  12826. },
  12827. rowAdd: function rowAdd(action) {
  12828. var newRow = this.table.rowManager.addRowActual(action.data.data, action.data.pos, action.data.index);
  12829. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  12830. this.table.modules.groupRows.updateGroupRows(true);
  12831. }
  12832. this._rebindRow(action.component, newRow);
  12833. },
  12834. rowDelete: function rowDelete(action) {
  12835. action.component.deleteActual();
  12836. },
  12837. rowMove: function rowMove(action) {
  12838. this.table.rowManager.moveRowActual(action.component, this.table.rowManager.rows[action.data.posTo], action.data.after);
  12839. this.table.rowManager.redraw();
  12840. }
  12841. };
  12842. //rebind rows to new element after deletion
  12843. History.prototype._rebindRow = function (oldRow, newRow) {
  12844. this.history.forEach(function (action) {
  12845. if (action.component instanceof Row) {
  12846. if (action.component === oldRow) {
  12847. action.component = newRow;
  12848. }
  12849. } else if (action.component instanceof Cell) {
  12850. if (action.component.row === oldRow) {
  12851. var field = action.component.column.getField();
  12852. if (field) {
  12853. action.component = newRow.getCell(field);
  12854. }
  12855. }
  12856. }
  12857. });
  12858. };
  12859. Tabulator.prototype.registerModule("history", History);
  12860. var HtmlTableImport = function HtmlTableImport(table) {
  12861. this.table = table; //hold Tabulator object
  12862. this.fieldIndex = [];
  12863. this.hasIndex = false;
  12864. };
  12865. HtmlTableImport.prototype.parseTable = function () {
  12866. var self = this,
  12867. element = self.table.element,
  12868. options = self.table.options,
  12869. columns = options.columns,
  12870. headers = element.getElementsByTagName("th"),
  12871. rows = element.getElementsByTagName("tbody")[0],
  12872. data = [],
  12873. newTable;
  12874. self.hasIndex = false;
  12875. self.table.options.htmlImporting.call(this.table);
  12876. rows = rows ? rows.getElementsByTagName("tr") : [];
  12877. //check for tablator inline options
  12878. self._extractOptions(element, options);
  12879. if (headers.length) {
  12880. self._extractHeaders(headers, rows);
  12881. } else {
  12882. self._generateBlankHeaders(headers, rows);
  12883. }
  12884. //iterate through table rows and build data set
  12885. for (var index = 0; index < rows.length; index++) {
  12886. var row = rows[index],
  12887. cells = row.getElementsByTagName("td"),
  12888. item = {};
  12889. //create index if the dont exist in table
  12890. if (!self.hasIndex) {
  12891. item[options.index] = index;
  12892. }
  12893. for (var i = 0; i < cells.length; i++) {
  12894. var cell = cells[i];
  12895. if (typeof this.fieldIndex[i] !== "undefined") {
  12896. item[this.fieldIndex[i]] = cell.innerHTML;
  12897. }
  12898. }
  12899. //add row data to item
  12900. data.push(item);
  12901. }
  12902. //create new element
  12903. var newElement = document.createElement("div");
  12904. //transfer attributes to new element
  12905. var attributes = element.attributes;
  12906. // loop through attributes and apply them on div
  12907. for (var i in attributes) {
  12908. if (_typeof(attributes[i]) == "object") {
  12909. newElement.setAttribute(attributes[i].name, attributes[i].value);
  12910. }
  12911. }
  12912. // replace table with div element
  12913. element.parentNode.replaceChild(newElement, element);
  12914. options.data = data;
  12915. self.table.options.htmlImported.call(this.table);
  12916. // // newElement.tabulator(options);
  12917. this.table.element = newElement;
  12918. };
  12919. //extract tabulator attribute options
  12920. HtmlTableImport.prototype._extractOptions = function (element, options, defaultOptions) {
  12921. var attributes = element.attributes;
  12922. var optionsArr = defaultOptions ? Object.assign([], defaultOptions) : Object.keys(options);
  12923. var optionsList = {};
  12924. optionsArr.forEach(function (item) {
  12925. optionsList[item.toLowerCase()] = item;
  12926. });
  12927. for (var index in attributes) {
  12928. var attrib = attributes[index];
  12929. var name;
  12930. if (attrib && (typeof attrib === 'undefined' ? 'undefined' : _typeof(attrib)) == "object" && attrib.name && attrib.name.indexOf("tabulator-") === 0) {
  12931. name = attrib.name.replace("tabulator-", "");
  12932. if (typeof optionsList[name] !== "undefined") {
  12933. options[optionsList[name]] = this._attribValue(attrib.value);
  12934. }
  12935. }
  12936. }
  12937. };
  12938. //get value of attribute
  12939. HtmlTableImport.prototype._attribValue = function (value) {
  12940. if (value === "true") {
  12941. return true;
  12942. }
  12943. if (value === "false") {
  12944. return false;
  12945. }
  12946. return value;
  12947. };
  12948. //find column if it has already been defined
  12949. HtmlTableImport.prototype._findCol = function (title) {
  12950. var match = this.table.options.columns.find(function (column) {
  12951. return column.title === title;
  12952. });
  12953. return match || false;
  12954. };
  12955. //extract column from headers
  12956. HtmlTableImport.prototype._extractHeaders = function (headers, rows) {
  12957. for (var index = 0; index < headers.length; index++) {
  12958. var header = headers[index],
  12959. exists = false,
  12960. col = this._findCol(header.textContent),
  12961. width,
  12962. attributes;
  12963. if (col) {
  12964. exists = true;
  12965. } else {
  12966. col = { title: header.textContent.trim() };
  12967. }
  12968. if (!col.field) {
  12969. col.field = header.textContent.trim().toLowerCase().replace(" ", "_");
  12970. }
  12971. width = header.getAttribute("width");
  12972. if (width && !col.width) {
  12973. col.width = width;
  12974. }
  12975. //check for tablator inline options
  12976. attributes = header.attributes;
  12977. // //check for tablator inline options
  12978. this._extractOptions(header, col, Column.prototype.defaultOptionList);
  12979. this.fieldIndex[index] = col.field;
  12980. if (col.field == this.table.options.index) {
  12981. this.hasIndex = true;
  12982. }
  12983. if (!exists) {
  12984. this.table.options.columns.push(col);
  12985. }
  12986. }
  12987. };
  12988. //generate blank headers
  12989. HtmlTableImport.prototype._generateBlankHeaders = function (headers, rows) {
  12990. for (var index = 0; index < headers.length; index++) {
  12991. var header = headers[index],
  12992. col = { title: "", field: "col" + index };
  12993. this.fieldIndex[index] = col.field;
  12994. var width = header.getAttribute("width");
  12995. if (width) {
  12996. col.width = width;
  12997. }
  12998. this.table.options.columns.push(col);
  12999. }
  13000. };
  13001. Tabulator.prototype.registerModule("htmlTableImport", HtmlTableImport);
  13002. var Keybindings = function Keybindings(table) {
  13003. this.table = table; //hold Tabulator object
  13004. this.watchKeys = null;
  13005. this.pressedKeys = null;
  13006. this.keyupBinding = false;
  13007. this.keydownBinding = false;
  13008. };
  13009. Keybindings.prototype.initialize = function () {
  13010. var bindings = this.table.options.keybindings,
  13011. mergedBindings = {};
  13012. this.watchKeys = {};
  13013. this.pressedKeys = [];
  13014. if (bindings !== false) {
  13015. for (var key in this.bindings) {
  13016. mergedBindings[key] = this.bindings[key];
  13017. }
  13018. if (Object.keys(bindings).length) {
  13019. for (var _key in bindings) {
  13020. mergedBindings[_key] = bindings[_key];
  13021. }
  13022. }
  13023. this.mapBindings(mergedBindings);
  13024. this.bindEvents();
  13025. }
  13026. };
  13027. Keybindings.prototype.mapBindings = function (bindings) {
  13028. var _this58 = this;
  13029. var self = this;
  13030. var _loop2 = function _loop2(key) {
  13031. if (_this58.actions[key]) {
  13032. if (bindings[key]) {
  13033. if (_typeof(bindings[key]) !== "object") {
  13034. bindings[key] = [bindings[key]];
  13035. }
  13036. bindings[key].forEach(function (binding) {
  13037. self.mapBinding(key, binding);
  13038. });
  13039. }
  13040. } else {
  13041. console.warn("Key Binding Error - no such action:", key);
  13042. }
  13043. };
  13044. for (var key in bindings) {
  13045. _loop2(key);
  13046. }
  13047. };
  13048. Keybindings.prototype.mapBinding = function (action, symbolsList) {
  13049. var self = this;
  13050. var binding = {
  13051. action: this.actions[action],
  13052. keys: [],
  13053. ctrl: false,
  13054. shift: false,
  13055. meta: false
  13056. };
  13057. var symbols = symbolsList.toString().toLowerCase().split(" ").join("").split("+");
  13058. symbols.forEach(function (symbol) {
  13059. switch (symbol) {
  13060. case "ctrl":
  13061. binding.ctrl = true;
  13062. break;
  13063. case "shift":
  13064. binding.shift = true;
  13065. break;
  13066. case "meta":
  13067. binding.meta = true;
  13068. break;
  13069. default:
  13070. symbol = parseInt(symbol);
  13071. binding.keys.push(symbol);
  13072. if (!self.watchKeys[symbol]) {
  13073. self.watchKeys[symbol] = [];
  13074. }
  13075. self.watchKeys[symbol].push(binding);
  13076. }
  13077. });
  13078. };
  13079. Keybindings.prototype.bindEvents = function () {
  13080. var self = this;
  13081. this.keyupBinding = function (e) {
  13082. var code = e.keyCode;
  13083. var bindings = self.watchKeys[code];
  13084. if (bindings) {
  13085. self.pressedKeys.push(code);
  13086. bindings.forEach(function (binding) {
  13087. self.checkBinding(e, binding);
  13088. });
  13089. }
  13090. };
  13091. this.keydownBinding = function (e) {
  13092. var code = e.keyCode;
  13093. var bindings = self.watchKeys[code];
  13094. if (bindings) {
  13095. var index = self.pressedKeys.indexOf(code);
  13096. if (index > -1) {
  13097. self.pressedKeys.splice(index, 1);
  13098. }
  13099. }
  13100. };
  13101. this.table.element.addEventListener("keydown", this.keyupBinding);
  13102. this.table.element.addEventListener("keyup", this.keydownBinding);
  13103. };
  13104. Keybindings.prototype.clearBindings = function () {
  13105. if (this.keyupBinding) {
  13106. this.table.element.removeEventListener("keydown", this.keyupBinding);
  13107. }
  13108. if (this.keydownBinding) {
  13109. this.table.element.removeEventListener("keyup", this.keydownBinding);
  13110. }
  13111. };
  13112. Keybindings.prototype.checkBinding = function (e, binding) {
  13113. var self = this,
  13114. match = true;
  13115. if (e.ctrlKey == binding.ctrl && e.shiftKey == binding.shift && e.metaKey == binding.meta) {
  13116. binding.keys.forEach(function (key) {
  13117. var index = self.pressedKeys.indexOf(key);
  13118. if (index == -1) {
  13119. match = false;
  13120. }
  13121. });
  13122. if (match) {
  13123. binding.action.call(self, e);
  13124. }
  13125. return true;
  13126. }
  13127. return false;
  13128. };
  13129. //default bindings
  13130. Keybindings.prototype.bindings = {
  13131. navPrev: "shift + 9",
  13132. navNext: 9,
  13133. navUp: 38,
  13134. navDown: 40,
  13135. scrollPageUp: 33,
  13136. scrollPageDown: 34,
  13137. scrollToStart: 36,
  13138. scrollToEnd: 35,
  13139. undo: "ctrl + 90",
  13140. redo: "ctrl + 89",
  13141. copyToClipboard: "ctrl + 67"
  13142. };
  13143. //default actions
  13144. Keybindings.prototype.actions = {
  13145. keyBlock: function keyBlock(e) {
  13146. e.stopPropagation();
  13147. e.preventDefault();
  13148. },
  13149. scrollPageUp: function scrollPageUp(e) {
  13150. var rowManager = this.table.rowManager,
  13151. newPos = rowManager.scrollTop - rowManager.height,
  13152. scrollMax = rowManager.element.scrollHeight;
  13153. e.preventDefault();
  13154. if (rowManager.displayRowsCount) {
  13155. if (newPos >= 0) {
  13156. rowManager.element.scrollTop = newPos;
  13157. } else {
  13158. rowManager.scrollToRow(rowManager.getDisplayRows()[0]);
  13159. }
  13160. }
  13161. this.table.element.focus();
  13162. },
  13163. scrollPageDown: function scrollPageDown(e) {
  13164. var rowManager = this.table.rowManager,
  13165. newPos = rowManager.scrollTop + rowManager.height,
  13166. scrollMax = rowManager.element.scrollHeight;
  13167. e.preventDefault();
  13168. if (rowManager.displayRowsCount) {
  13169. if (newPos <= scrollMax) {
  13170. rowManager.element.scrollTop = newPos;
  13171. } else {
  13172. rowManager.scrollToRow(rowManager.getDisplayRows()[rowManager.displayRowsCount - 1]);
  13173. }
  13174. }
  13175. this.table.element.focus();
  13176. },
  13177. scrollToStart: function scrollToStart(e) {
  13178. var rowManager = this.table.rowManager;
  13179. e.preventDefault();
  13180. if (rowManager.displayRowsCount) {
  13181. rowManager.scrollToRow(rowManager.getDisplayRows()[0]);
  13182. }
  13183. this.table.element.focus();
  13184. },
  13185. scrollToEnd: function scrollToEnd(e) {
  13186. var rowManager = this.table.rowManager;
  13187. e.preventDefault();
  13188. if (rowManager.displayRowsCount) {
  13189. rowManager.scrollToRow(rowManager.getDisplayRows()[rowManager.displayRowsCount - 1]);
  13190. }
  13191. this.table.element.focus();
  13192. },
  13193. navPrev: function navPrev(e) {
  13194. var cell = false;
  13195. if (this.table.modExists("edit")) {
  13196. cell = this.table.modules.edit.currentCell;
  13197. if (cell) {
  13198. e.preventDefault();
  13199. cell.nav().prev();
  13200. }
  13201. }
  13202. },
  13203. navNext: function navNext(e) {
  13204. var cell = false;
  13205. var newRow = this.table.options.tabEndNewRow;
  13206. var nav;
  13207. if (this.table.modExists("edit")) {
  13208. cell = this.table.modules.edit.currentCell;
  13209. if (cell) {
  13210. e.preventDefault();
  13211. nav = cell.nav();
  13212. if (!nav.next()) {
  13213. if (newRow) {
  13214. cell.getElement().firstChild.blur();
  13215. if (newRow === true) {
  13216. newRow = this.table.addRow({});
  13217. } else {
  13218. if (typeof newRow == "function") {
  13219. newRow = this.table.addRow(newRow(cell.row.getComponent()));
  13220. } else {
  13221. newRow = this.table.addRow(newRow);
  13222. }
  13223. }
  13224. newRow.then(function () {
  13225. setTimeout(function () {
  13226. nav.next();
  13227. });
  13228. });
  13229. }
  13230. }
  13231. }
  13232. }
  13233. },
  13234. navLeft: function navLeft(e) {
  13235. var cell = false;
  13236. if (this.table.modExists("edit")) {
  13237. cell = this.table.modules.edit.currentCell;
  13238. if (cell) {
  13239. e.preventDefault();
  13240. cell.nav().left();
  13241. }
  13242. }
  13243. },
  13244. navRight: function navRight(e) {
  13245. var cell = false;
  13246. if (this.table.modExists("edit")) {
  13247. cell = this.table.modules.edit.currentCell;
  13248. if (cell) {
  13249. e.preventDefault();
  13250. cell.nav().right();
  13251. }
  13252. }
  13253. },
  13254. navUp: function navUp(e) {
  13255. var cell = false;
  13256. if (this.table.modExists("edit")) {
  13257. cell = this.table.modules.edit.currentCell;
  13258. if (cell) {
  13259. e.preventDefault();
  13260. cell.nav().up();
  13261. }
  13262. }
  13263. },
  13264. navDown: function navDown(e) {
  13265. var cell = false;
  13266. if (this.table.modExists("edit")) {
  13267. cell = this.table.modules.edit.currentCell;
  13268. if (cell) {
  13269. e.preventDefault();
  13270. cell.nav().down();
  13271. }
  13272. }
  13273. },
  13274. undo: function undo(e) {
  13275. var cell = false;
  13276. if (this.table.options.history && this.table.modExists("history") && this.table.modExists("edit")) {
  13277. cell = this.table.modules.edit.currentCell;
  13278. if (!cell) {
  13279. e.preventDefault();
  13280. this.table.modules.history.undo();
  13281. }
  13282. }
  13283. },
  13284. redo: function redo(e) {
  13285. var cell = false;
  13286. if (this.table.options.history && this.table.modExists("history") && this.table.modExists("edit")) {
  13287. cell = this.table.modules.edit.currentCell;
  13288. if (!cell) {
  13289. e.preventDefault();
  13290. this.table.modules.history.redo();
  13291. }
  13292. }
  13293. },
  13294. copyToClipboard: function copyToClipboard(e) {
  13295. if (!this.table.modules.edit.currentCell) {
  13296. if (this.table.modExists("clipboard", true)) {
  13297. this.table.modules.clipboard.copy(false, true);
  13298. }
  13299. }
  13300. }
  13301. };
  13302. Tabulator.prototype.registerModule("keybindings", Keybindings);
  13303. var Menu = function Menu(table) {
  13304. this.table = table; //hold Tabulator object
  13305. this.menuEl = false;
  13306. this.blurEvent = this.hideMenu.bind(this);
  13307. };
  13308. Menu.prototype.initializeColumnHeader = function (column) {
  13309. var _this59 = this;
  13310. var headerMenuEl;
  13311. if (column.definition.headerContextMenu) {
  13312. column.getElement().addEventListener("contextmenu", function (e) {
  13313. var menu = typeof column.definition.headerContextMenu == "function" ? column.definition.headerContextMenu(column.getComponent()) : column.definition.headerContextMenu;
  13314. e.preventDefault();
  13315. _this59.loadMenu(e, column, menu);
  13316. });
  13317. }
  13318. if (column.definition.headerMenu) {
  13319. headerMenuEl = document.createElement("span");
  13320. headerMenuEl.classList.add("tabulator-header-menu-button");
  13321. headerMenuEl.innerHTML = "&vellip;";
  13322. headerMenuEl.addEventListener("click", function (e) {
  13323. var menu = typeof column.definition.headerMenu == "function" ? column.definition.headerMenu(column.getComponent()) : column.definition.headerMenu;
  13324. e.stopPropagation();
  13325. e.preventDefault();
  13326. _this59.loadMenu(e, column, menu);
  13327. });
  13328. column.titleElement.insertBefore(headerMenuEl, column.titleElement.firstChild);
  13329. }
  13330. };
  13331. Menu.prototype.initializeCell = function (cell) {
  13332. var _this60 = this;
  13333. cell.getElement().addEventListener("contextmenu", function (e) {
  13334. var menu = typeof cell.column.definition.contextMenu == "function" ? cell.column.definition.contextMenu(cell.getComponent()) : cell.column.definition.contextMenu;
  13335. e.preventDefault();
  13336. _this60.loadMenu(e, cell, menu);
  13337. });
  13338. };
  13339. Menu.prototype.initializeRow = function (row) {
  13340. var _this61 = this;
  13341. row.getElement().addEventListener("contextmenu", function (e) {
  13342. var menu = typeof _this61.table.options.rowContextMenu == "function" ? _this61.table.options.rowContextMenu(row.getComponent()) : _this61.table.options.rowContextMenu;
  13343. e.preventDefault();
  13344. _this61.loadMenu(e, row, menu);
  13345. });
  13346. };
  13347. Menu.prototype.loadMenu = function (e, component, menu) {
  13348. var _this62 = this;
  13349. var docHeight = Math.max(document.body.offsetHeight, window.innerHeight);
  13350. //abort if no menu set
  13351. if (!menu || !menu.length) {
  13352. return;
  13353. }
  13354. this.hideMenu();
  13355. this.menuEl = document.createElement("div");
  13356. this.menuEl.classList.add("tabulator-menu");
  13357. menu.forEach(function (item) {
  13358. var itemEl = document.createElement("div");
  13359. var label = item.label;
  13360. var disabled = item.disabled;
  13361. if (item.separator) {
  13362. itemEl.classList.add("tabulator-menu-separator");
  13363. } else {
  13364. itemEl.classList.add("tabulator-menu-item");
  13365. if (typeof label == "function") {
  13366. label = label(component.getComponent());
  13367. }
  13368. if (label instanceof Node) {
  13369. itemEl.appendChild(label);
  13370. } else {
  13371. itemEl.innerHTML = label;
  13372. }
  13373. if (typeof disabled == "function") {
  13374. disabled = disabled(component.getComponent());
  13375. }
  13376. if (disabled) {
  13377. itemEl.classList.add("tabulator-menu-item-disabled");
  13378. itemEl.addEventListener("click", function (e) {
  13379. e.stopPropagation();
  13380. });
  13381. } else {
  13382. itemEl.addEventListener("click", function (e) {
  13383. _this62.hideMenu();
  13384. item.action(e, component.getComponent());
  13385. });
  13386. }
  13387. }
  13388. _this62.menuEl.appendChild(itemEl);
  13389. });
  13390. this.menuEl.style.top = e.pageY + "px";
  13391. this.menuEl.style.left = e.pageX + "px";
  13392. document.body.addEventListener("click", this.blurEvent);
  13393. this.table.rowManager.element.addEventListener("scroll", this.blurEvent);
  13394. setTimeout(function () {
  13395. document.body.addEventListener("contextmenu", _this62.blurEvent);
  13396. }, 100);
  13397. document.body.appendChild(this.menuEl);
  13398. //move menu to start on right edge if it is too close to the edge of the screen
  13399. if (e.pageX + this.menuEl.offsetWidth >= document.body.offsetWidth) {
  13400. this.menuEl.style.left = "";
  13401. this.menuEl.style.right = document.body.offsetWidth - e.pageX + "px";
  13402. }
  13403. //move menu to start on bottom edge if it is too close to the edge of the screen
  13404. if (e.pageY + this.menuEl.offsetHeight >= docHeight) {
  13405. this.menuEl.style.top = "";
  13406. this.menuEl.style.bottom = docHeight - e.pageY + "px";
  13407. }
  13408. };
  13409. Menu.prototype.hideMenu = function () {
  13410. if (this.menuEl.parentNode) {
  13411. this.menuEl.parentNode.removeChild(this.menuEl);
  13412. }
  13413. if (this.blurEvent) {
  13414. document.body.removeEventListener("click", this.blurEvent);
  13415. document.body.removeEventListener("contextmenu", this.blurEvent);
  13416. this.table.rowManager.element.removeEventListener("scroll", this.blurEvent);
  13417. }
  13418. };
  13419. //default accessors
  13420. Menu.prototype.menus = {};
  13421. Tabulator.prototype.registerModule("menu", Menu);
  13422. var MoveColumns = function MoveColumns(table) {
  13423. this.table = table; //hold Tabulator object
  13424. this.placeholderElement = this.createPlaceholderElement();
  13425. this.hoverElement = false; //floating column header element
  13426. this.checkTimeout = false; //click check timeout holder
  13427. this.checkPeriod = 250; //period to wait on mousedown to consider this a move and not a click
  13428. this.moving = false; //currently moving column
  13429. this.toCol = false; //destination column
  13430. this.toColAfter = false; //position of moving column relative to the desitnation column
  13431. this.startX = 0; //starting position within header element
  13432. this.autoScrollMargin = 40; //auto scroll on edge when within margin
  13433. this.autoScrollStep = 5; //auto scroll distance in pixels
  13434. this.autoScrollTimeout = false; //auto scroll timeout
  13435. this.touchMove = false;
  13436. this.moveHover = this.moveHover.bind(this);
  13437. this.endMove = this.endMove.bind(this);
  13438. };
  13439. MoveColumns.prototype.createPlaceholderElement = function () {
  13440. var el = document.createElement("div");
  13441. el.classList.add("tabulator-col");
  13442. el.classList.add("tabulator-col-placeholder");
  13443. return el;
  13444. };
  13445. MoveColumns.prototype.initializeColumn = function (column) {
  13446. var self = this,
  13447. config = {},
  13448. colEl;
  13449. if (!column.modules.frozen) {
  13450. colEl = column.getElement();
  13451. config.mousemove = function (e) {
  13452. if (column.parent === self.moving.parent) {
  13453. if ((self.touchMove ? e.touches[0].pageX : e.pageX) - Tabulator.prototype.helpers.elOffset(colEl).left + self.table.columnManager.element.scrollLeft > column.getWidth() / 2) {
  13454. if (self.toCol !== column || !self.toColAfter) {
  13455. colEl.parentNode.insertBefore(self.placeholderElement, colEl.nextSibling);
  13456. self.moveColumn(column, true);
  13457. }
  13458. } else {
  13459. if (self.toCol !== column || self.toColAfter) {
  13460. colEl.parentNode.insertBefore(self.placeholderElement, colEl);
  13461. self.moveColumn(column, false);
  13462. }
  13463. }
  13464. }
  13465. }.bind(self);
  13466. colEl.addEventListener("mousedown", function (e) {
  13467. self.touchMove = false;
  13468. if (e.which === 1) {
  13469. self.checkTimeout = setTimeout(function () {
  13470. self.startMove(e, column);
  13471. }, self.checkPeriod);
  13472. }
  13473. });
  13474. colEl.addEventListener("mouseup", function (e) {
  13475. if (e.which === 1) {
  13476. if (self.checkTimeout) {
  13477. clearTimeout(self.checkTimeout);
  13478. }
  13479. }
  13480. });
  13481. self.bindTouchEvents(column);
  13482. }
  13483. column.modules.moveColumn = config;
  13484. };
  13485. MoveColumns.prototype.bindTouchEvents = function (column) {
  13486. var self = this,
  13487. colEl = column.getElement(),
  13488. startXMove = false,
  13489. //shifting center position of the cell
  13490. dir = false,
  13491. currentCol,
  13492. nextCol,
  13493. prevCol,
  13494. nextColWidth,
  13495. prevColWidth,
  13496. nextColWidthLast,
  13497. prevColWidthLast;
  13498. colEl.addEventListener("touchstart", function (e) {
  13499. self.checkTimeout = setTimeout(function () {
  13500. self.touchMove = true;
  13501. currentCol = column;
  13502. nextCol = column.nextColumn();
  13503. nextColWidth = nextCol ? nextCol.getWidth() / 2 : 0;
  13504. prevCol = column.prevColumn();
  13505. prevColWidth = prevCol ? prevCol.getWidth() / 2 : 0;
  13506. nextColWidthLast = 0;
  13507. prevColWidthLast = 0;
  13508. startXMove = false;
  13509. self.startMove(e, column);
  13510. }, self.checkPeriod);
  13511. }, { passive: true });
  13512. colEl.addEventListener("touchmove", function (e) {
  13513. var halfCol, diff, moveToCol;
  13514. if (self.moving) {
  13515. self.moveHover(e);
  13516. if (!startXMove) {
  13517. startXMove = e.touches[0].pageX;
  13518. }
  13519. diff = e.touches[0].pageX - startXMove;
  13520. if (diff > 0) {
  13521. if (nextCol && diff - nextColWidthLast > nextColWidth) {
  13522. moveToCol = nextCol;
  13523. if (moveToCol !== column) {
  13524. startXMove = e.touches[0].pageX;
  13525. moveToCol.getElement().parentNode.insertBefore(self.placeholderElement, moveToCol.getElement().nextSibling);
  13526. self.moveColumn(moveToCol, true);
  13527. }
  13528. }
  13529. } else {
  13530. if (prevCol && -diff - prevColWidthLast > prevColWidth) {
  13531. moveToCol = prevCol;
  13532. if (moveToCol !== column) {
  13533. startXMove = e.touches[0].pageX;
  13534. moveToCol.getElement().parentNode.insertBefore(self.placeholderElement, moveToCol.getElement());
  13535. self.moveColumn(moveToCol, false);
  13536. }
  13537. }
  13538. }
  13539. if (moveToCol) {
  13540. currentCol = moveToCol;
  13541. nextCol = moveToCol.nextColumn();
  13542. nextColWidthLast = nextColWidth;
  13543. nextColWidth = nextCol ? nextCol.getWidth() / 2 : 0;
  13544. prevCol = moveToCol.prevColumn();
  13545. prevColWidthLast = prevColWidth;
  13546. prevColWidth = prevCol ? prevCol.getWidth() / 2 : 0;
  13547. }
  13548. }
  13549. }, { passive: true });
  13550. colEl.addEventListener("touchend", function (e) {
  13551. if (self.checkTimeout) {
  13552. clearTimeout(self.checkTimeout);
  13553. }
  13554. if (self.moving) {
  13555. self.endMove(e);
  13556. }
  13557. });
  13558. };
  13559. MoveColumns.prototype.startMove = function (e, column) {
  13560. var element = column.getElement();
  13561. this.moving = column;
  13562. this.startX = (this.touchMove ? e.touches[0].pageX : e.pageX) - Tabulator.prototype.helpers.elOffset(element).left;
  13563. this.table.element.classList.add("tabulator-block-select");
  13564. //create placeholder
  13565. this.placeholderElement.style.width = column.getWidth() + "px";
  13566. this.placeholderElement.style.height = column.getHeight() + "px";
  13567. element.parentNode.insertBefore(this.placeholderElement, element);
  13568. element.parentNode.removeChild(element);
  13569. //create hover element
  13570. this.hoverElement = element.cloneNode(true);
  13571. this.hoverElement.classList.add("tabulator-moving");
  13572. this.table.columnManager.getElement().appendChild(this.hoverElement);
  13573. this.hoverElement.style.left = "0";
  13574. this.hoverElement.style.bottom = "0";
  13575. if (!this.touchMove) {
  13576. this._bindMouseMove();
  13577. document.body.addEventListener("mousemove", this.moveHover);
  13578. document.body.addEventListener("mouseup", this.endMove);
  13579. }
  13580. this.moveHover(e);
  13581. };
  13582. MoveColumns.prototype._bindMouseMove = function () {
  13583. this.table.columnManager.columnsByIndex.forEach(function (column) {
  13584. if (column.modules.moveColumn.mousemove) {
  13585. column.getElement().addEventListener("mousemove", column.modules.moveColumn.mousemove);
  13586. }
  13587. });
  13588. };
  13589. MoveColumns.prototype._unbindMouseMove = function () {
  13590. this.table.columnManager.columnsByIndex.forEach(function (column) {
  13591. if (column.modules.moveColumn.mousemove) {
  13592. column.getElement().removeEventListener("mousemove", column.modules.moveColumn.mousemove);
  13593. }
  13594. });
  13595. };
  13596. MoveColumns.prototype.moveColumn = function (column, after) {
  13597. var movingCells = this.moving.getCells();
  13598. this.toCol = column;
  13599. this.toColAfter = after;
  13600. if (after) {
  13601. column.getCells().forEach(function (cell, i) {
  13602. var cellEl = cell.getElement();
  13603. cellEl.parentNode.insertBefore(movingCells[i].getElement(), cellEl.nextSibling);
  13604. });
  13605. } else {
  13606. column.getCells().forEach(function (cell, i) {
  13607. var cellEl = cell.getElement();
  13608. cellEl.parentNode.insertBefore(movingCells[i].getElement(), cellEl);
  13609. });
  13610. }
  13611. };
  13612. MoveColumns.prototype.endMove = function (e) {
  13613. if (e.which === 1 || this.touchMove) {
  13614. this._unbindMouseMove();
  13615. this.placeholderElement.parentNode.insertBefore(this.moving.getElement(), this.placeholderElement.nextSibling);
  13616. this.placeholderElement.parentNode.removeChild(this.placeholderElement);
  13617. this.hoverElement.parentNode.removeChild(this.hoverElement);
  13618. this.table.element.classList.remove("tabulator-block-select");
  13619. if (this.toCol) {
  13620. this.table.columnManager.moveColumnActual(this.moving, this.toCol, this.toColAfter);
  13621. }
  13622. this.moving = false;
  13623. this.toCol = false;
  13624. this.toColAfter = false;
  13625. if (!this.touchMove) {
  13626. document.body.removeEventListener("mousemove", this.moveHover);
  13627. document.body.removeEventListener("mouseup", this.endMove);
  13628. }
  13629. }
  13630. };
  13631. MoveColumns.prototype.moveHover = function (e) {
  13632. var self = this,
  13633. columnHolder = self.table.columnManager.getElement(),
  13634. scrollLeft = columnHolder.scrollLeft,
  13635. xPos = (self.touchMove ? e.touches[0].pageX : e.pageX) - Tabulator.prototype.helpers.elOffset(columnHolder).left + scrollLeft,
  13636. scrollPos;
  13637. self.hoverElement.style.left = xPos - self.startX + "px";
  13638. if (xPos - scrollLeft < self.autoScrollMargin) {
  13639. if (!self.autoScrollTimeout) {
  13640. self.autoScrollTimeout = setTimeout(function () {
  13641. scrollPos = Math.max(0, scrollLeft - 5);
  13642. self.table.rowManager.getElement().scrollLeft = scrollPos;
  13643. self.autoScrollTimeout = false;
  13644. }, 1);
  13645. }
  13646. }
  13647. if (scrollLeft + columnHolder.clientWidth - xPos < self.autoScrollMargin) {
  13648. if (!self.autoScrollTimeout) {
  13649. self.autoScrollTimeout = setTimeout(function () {
  13650. scrollPos = Math.min(columnHolder.clientWidth, scrollLeft + 5);
  13651. self.table.rowManager.getElement().scrollLeft = scrollPos;
  13652. self.autoScrollTimeout = false;
  13653. }, 1);
  13654. }
  13655. }
  13656. };
  13657. Tabulator.prototype.registerModule("moveColumn", MoveColumns);
  13658. var MoveRows = function MoveRows(table) {
  13659. this.table = table; //hold Tabulator object
  13660. this.placeholderElement = this.createPlaceholderElement();
  13661. this.hoverElement = false; //floating row header element
  13662. this.checkTimeout = false; //click check timeout holder
  13663. this.checkPeriod = 150; //period to wait on mousedown to consider this a move and not a click
  13664. this.moving = false; //currently moving row
  13665. this.toRow = false; //destination row
  13666. this.toRowAfter = false; //position of moving row relative to the desitnation row
  13667. this.hasHandle = false; //row has handle instead of fully movable row
  13668. this.startY = 0; //starting Y position within header element
  13669. this.startX = 0; //starting X position within header element
  13670. this.moveHover = this.moveHover.bind(this);
  13671. this.endMove = this.endMove.bind(this);
  13672. this.tableRowDropEvent = false;
  13673. this.touchMove = false;
  13674. this.connection = false;
  13675. this.connections = [];
  13676. this.connectedTable = false;
  13677. this.connectedRow = false;
  13678. };
  13679. MoveRows.prototype.createPlaceholderElement = function () {
  13680. var el = document.createElement("div");
  13681. el.classList.add("tabulator-row");
  13682. el.classList.add("tabulator-row-placeholder");
  13683. return el;
  13684. };
  13685. MoveRows.prototype.initialize = function (handle) {
  13686. this.connection = this.table.options.movableRowsConnectedTables;
  13687. };
  13688. MoveRows.prototype.setHandle = function (handle) {
  13689. this.hasHandle = handle;
  13690. };
  13691. MoveRows.prototype.initializeGroupHeader = function (group) {
  13692. var self = this,
  13693. config = {},
  13694. rowEl;
  13695. //inter table drag drop
  13696. config.mouseup = function (e) {
  13697. self.tableRowDrop(e, row);
  13698. }.bind(self);
  13699. //same table drag drop
  13700. config.mousemove = function (e) {
  13701. if (e.pageY - Tabulator.prototype.helpers.elOffset(group.element).top + self.table.rowManager.element.scrollTop > group.getHeight() / 2) {
  13702. if (self.toRow !== group || !self.toRowAfter) {
  13703. var rowEl = group.getElement();
  13704. rowEl.parentNode.insertBefore(self.placeholderElement, rowEl.nextSibling);
  13705. self.moveRow(group, true);
  13706. }
  13707. } else {
  13708. if (self.toRow !== group || self.toRowAfter) {
  13709. var rowEl = group.getElement();
  13710. if (rowEl.previousSibling) {
  13711. rowEl.parentNode.insertBefore(self.placeholderElement, rowEl);
  13712. self.moveRow(group, false);
  13713. }
  13714. }
  13715. }
  13716. }.bind(self);
  13717. group.modules.moveRow = config;
  13718. };
  13719. MoveRows.prototype.initializeRow = function (row) {
  13720. var self = this,
  13721. config = {},
  13722. rowEl;
  13723. //inter table drag drop
  13724. config.mouseup = function (e) {
  13725. self.tableRowDrop(e, row);
  13726. }.bind(self);
  13727. //same table drag drop
  13728. config.mousemove = function (e) {
  13729. if (e.pageY - Tabulator.prototype.helpers.elOffset(row.element).top + self.table.rowManager.element.scrollTop > row.getHeight() / 2) {
  13730. if (self.toRow !== row || !self.toRowAfter) {
  13731. var rowEl = row.getElement();
  13732. rowEl.parentNode.insertBefore(self.placeholderElement, rowEl.nextSibling);
  13733. self.moveRow(row, true);
  13734. }
  13735. } else {
  13736. if (self.toRow !== row || self.toRowAfter) {
  13737. var rowEl = row.getElement();
  13738. rowEl.parentNode.insertBefore(self.placeholderElement, rowEl);
  13739. self.moveRow(row, false);
  13740. }
  13741. }
  13742. }.bind(self);
  13743. if (!this.hasHandle) {
  13744. rowEl = row.getElement();
  13745. rowEl.addEventListener("mousedown", function (e) {
  13746. if (e.which === 1) {
  13747. self.checkTimeout = setTimeout(function () {
  13748. self.startMove(e, row);
  13749. }, self.checkPeriod);
  13750. }
  13751. });
  13752. rowEl.addEventListener("mouseup", function (e) {
  13753. if (e.which === 1) {
  13754. if (self.checkTimeout) {
  13755. clearTimeout(self.checkTimeout);
  13756. }
  13757. }
  13758. });
  13759. this.bindTouchEvents(row, row.getElement());
  13760. }
  13761. row.modules.moveRow = config;
  13762. };
  13763. MoveRows.prototype.initializeCell = function (cell) {
  13764. var self = this,
  13765. cellEl = cell.getElement();
  13766. cellEl.addEventListener("mousedown", function (e) {
  13767. if (e.which === 1) {
  13768. self.checkTimeout = setTimeout(function () {
  13769. self.startMove(e, cell.row);
  13770. }, self.checkPeriod);
  13771. }
  13772. });
  13773. cellEl.addEventListener("mouseup", function (e) {
  13774. if (e.which === 1) {
  13775. if (self.checkTimeout) {
  13776. clearTimeout(self.checkTimeout);
  13777. }
  13778. }
  13779. });
  13780. this.bindTouchEvents(cell.row, cell.getElement());
  13781. };
  13782. MoveRows.prototype.bindTouchEvents = function (row, element) {
  13783. var self = this,
  13784. startYMove = false,
  13785. //shifting center position of the cell
  13786. dir = false,
  13787. currentRow,
  13788. nextRow,
  13789. prevRow,
  13790. nextRowHeight,
  13791. prevRowHeight,
  13792. nextRowHeightLast,
  13793. prevRowHeightLast;
  13794. element.addEventListener("touchstart", function (e) {
  13795. self.checkTimeout = setTimeout(function () {
  13796. self.touchMove = true;
  13797. currentRow = row;
  13798. nextRow = row.nextRow();
  13799. nextRowHeight = nextRow ? nextRow.getHeight() / 2 : 0;
  13800. prevRow = row.prevRow();
  13801. prevRowHeight = prevRow ? prevRow.getHeight() / 2 : 0;
  13802. nextRowHeightLast = 0;
  13803. prevRowHeightLast = 0;
  13804. startYMove = false;
  13805. self.startMove(e, row);
  13806. }, self.checkPeriod);
  13807. }, { passive: true });
  13808. this.moving, this.toRow, this.toRowAfter;
  13809. element.addEventListener("touchmove", function (e) {
  13810. var halfCol, diff, moveToRow;
  13811. if (self.moving) {
  13812. e.preventDefault();
  13813. self.moveHover(e);
  13814. if (!startYMove) {
  13815. startYMove = e.touches[0].pageY;
  13816. }
  13817. diff = e.touches[0].pageY - startYMove;
  13818. if (diff > 0) {
  13819. if (nextRow && diff - nextRowHeightLast > nextRowHeight) {
  13820. moveToRow = nextRow;
  13821. if (moveToRow !== row) {
  13822. startYMove = e.touches[0].pageY;
  13823. moveToRow.getElement().parentNode.insertBefore(self.placeholderElement, moveToRow.getElement().nextSibling);
  13824. self.moveRow(moveToRow, true);
  13825. }
  13826. }
  13827. } else {
  13828. if (prevRow && -diff - prevRowHeightLast > prevRowHeight) {
  13829. moveToRow = prevRow;
  13830. if (moveToRow !== row) {
  13831. startYMove = e.touches[0].pageY;
  13832. moveToRow.getElement().parentNode.insertBefore(self.placeholderElement, moveToRow.getElement());
  13833. self.moveRow(moveToRow, false);
  13834. }
  13835. }
  13836. }
  13837. if (moveToRow) {
  13838. currentRow = moveToRow;
  13839. nextRow = moveToRow.nextRow();
  13840. nextRowHeightLast = nextRowHeight;
  13841. nextRowHeight = nextRow ? nextRow.getHeight() / 2 : 0;
  13842. prevRow = moveToRow.prevRow();
  13843. prevRowHeightLast = prevRowHeight;
  13844. prevRowHeight = prevRow ? prevRow.getHeight() / 2 : 0;
  13845. }
  13846. }
  13847. });
  13848. element.addEventListener("touchend", function (e) {
  13849. if (self.checkTimeout) {
  13850. clearTimeout(self.checkTimeout);
  13851. }
  13852. if (self.moving) {
  13853. self.endMove(e);
  13854. self.touchMove = false;
  13855. }
  13856. });
  13857. };
  13858. MoveRows.prototype._bindMouseMove = function () {
  13859. var self = this;
  13860. self.table.rowManager.getDisplayRows().forEach(function (row) {
  13861. if ((row.type === "row" || row.type === "group") && row.modules.moveRow.mousemove) {
  13862. row.getElement().addEventListener("mousemove", row.modules.moveRow.mousemove);
  13863. }
  13864. });
  13865. };
  13866. MoveRows.prototype._unbindMouseMove = function () {
  13867. var self = this;
  13868. self.table.rowManager.getDisplayRows().forEach(function (row) {
  13869. if ((row.type === "row" || row.type === "group") && row.modules.moveRow.mousemove) {
  13870. row.getElement().removeEventListener("mousemove", row.modules.moveRow.mousemove);
  13871. }
  13872. });
  13873. };
  13874. MoveRows.prototype.startMove = function (e, row) {
  13875. var element = row.getElement();
  13876. this.setStartPosition(e, row);
  13877. this.moving = row;
  13878. this.table.element.classList.add("tabulator-block-select");
  13879. //create placeholder
  13880. this.placeholderElement.style.width = row.getWidth() + "px";
  13881. this.placeholderElement.style.height = row.getHeight() + "px";
  13882. if (!this.connection) {
  13883. element.parentNode.insertBefore(this.placeholderElement, element);
  13884. element.parentNode.removeChild(element);
  13885. } else {
  13886. this.table.element.classList.add("tabulator-movingrow-sending");
  13887. this.connectToTables(row);
  13888. }
  13889. //create hover element
  13890. this.hoverElement = element.cloneNode(true);
  13891. this.hoverElement.classList.add("tabulator-moving");
  13892. if (this.connection) {
  13893. document.body.appendChild(this.hoverElement);
  13894. this.hoverElement.style.left = "0";
  13895. this.hoverElement.style.top = "0";
  13896. this.hoverElement.style.width = this.table.element.clientWidth + "px";
  13897. this.hoverElement.style.whiteSpace = "nowrap";
  13898. this.hoverElement.style.overflow = "hidden";
  13899. this.hoverElement.style.pointerEvents = "none";
  13900. } else {
  13901. this.table.rowManager.getTableElement().appendChild(this.hoverElement);
  13902. this.hoverElement.style.left = "0";
  13903. this.hoverElement.style.top = "0";
  13904. this._bindMouseMove();
  13905. }
  13906. document.body.addEventListener("mousemove", this.moveHover);
  13907. document.body.addEventListener("mouseup", this.endMove);
  13908. this.moveHover(e);
  13909. };
  13910. MoveRows.prototype.setStartPosition = function (e, row) {
  13911. var pageX = this.touchMove ? e.touches[0].pageX : e.pageX,
  13912. pageY = this.touchMove ? e.touches[0].pageY : e.pageY,
  13913. element,
  13914. position;
  13915. element = row.getElement();
  13916. if (this.connection) {
  13917. position = element.getBoundingClientRect();
  13918. this.startX = position.left - pageX + window.pageXOffset;
  13919. this.startY = position.top - pageY + window.pageYOffset;
  13920. } else {
  13921. this.startY = pageY - element.getBoundingClientRect().top;
  13922. }
  13923. };
  13924. MoveRows.prototype.endMove = function (e) {
  13925. if (!e || e.which === 1 || this.touchMove) {
  13926. this._unbindMouseMove();
  13927. if (!this.connection) {
  13928. this.placeholderElement.parentNode.insertBefore(this.moving.getElement(), this.placeholderElement.nextSibling);
  13929. this.placeholderElement.parentNode.removeChild(this.placeholderElement);
  13930. }
  13931. this.hoverElement.parentNode.removeChild(this.hoverElement);
  13932. this.table.element.classList.remove("tabulator-block-select");
  13933. if (this.toRow) {
  13934. this.table.rowManager.moveRow(this.moving, this.toRow, this.toRowAfter);
  13935. }
  13936. this.moving = false;
  13937. this.toRow = false;
  13938. this.toRowAfter = false;
  13939. document.body.removeEventListener("mousemove", this.moveHover);
  13940. document.body.removeEventListener("mouseup", this.endMove);
  13941. if (this.connection) {
  13942. this.table.element.classList.remove("tabulator-movingrow-sending");
  13943. this.disconnectFromTables();
  13944. }
  13945. }
  13946. };
  13947. MoveRows.prototype.moveRow = function (row, after) {
  13948. this.toRow = row;
  13949. this.toRowAfter = after;
  13950. };
  13951. MoveRows.prototype.moveHover = function (e) {
  13952. if (this.connection) {
  13953. this.moveHoverConnections.call(this, e);
  13954. } else {
  13955. this.moveHoverTable.call(this, e);
  13956. }
  13957. };
  13958. MoveRows.prototype.moveHoverTable = function (e) {
  13959. var rowHolder = this.table.rowManager.getElement(),
  13960. scrollTop = rowHolder.scrollTop,
  13961. yPos = (this.touchMove ? e.touches[0].pageY : e.pageY) - rowHolder.getBoundingClientRect().top + scrollTop,
  13962. scrollPos;
  13963. this.hoverElement.style.top = yPos - this.startY + "px";
  13964. };
  13965. MoveRows.prototype.moveHoverConnections = function (e) {
  13966. this.hoverElement.style.left = this.startX + (this.touchMove ? e.touches[0].pageX : e.pageX) + "px";
  13967. this.hoverElement.style.top = this.startY + (this.touchMove ? e.touches[0].pageY : e.pageY) + "px";
  13968. };
  13969. //establish connection with other tables
  13970. MoveRows.prototype.connectToTables = function (row) {
  13971. var self = this,
  13972. connections = this.table.modules.comms.getConnections(this.connection);
  13973. this.table.options.movableRowsSendingStart.call(this.table, connections);
  13974. this.table.modules.comms.send(this.connection, "moveRow", "connect", {
  13975. row: row
  13976. });
  13977. };
  13978. //disconnect from other tables
  13979. MoveRows.prototype.disconnectFromTables = function () {
  13980. var self = this,
  13981. connections = this.table.modules.comms.getConnections(this.connection);
  13982. this.table.options.movableRowsSendingStop.call(this.table, connections);
  13983. this.table.modules.comms.send(this.connection, "moveRow", "disconnect");
  13984. };
  13985. //accept incomming connection
  13986. MoveRows.prototype.connect = function (table, row) {
  13987. var self = this;
  13988. if (!this.connectedTable) {
  13989. this.connectedTable = table;
  13990. this.connectedRow = row;
  13991. this.table.element.classList.add("tabulator-movingrow-receiving");
  13992. self.table.rowManager.getDisplayRows().forEach(function (row) {
  13993. if (row.type === "row" && row.modules.moveRow && row.modules.moveRow.mouseup) {
  13994. row.getElement().addEventListener("mouseup", row.modules.moveRow.mouseup);
  13995. }
  13996. });
  13997. self.tableRowDropEvent = self.tableRowDrop.bind(self);
  13998. self.table.element.addEventListener("mouseup", self.tableRowDropEvent);
  13999. this.table.options.movableRowsReceivingStart.call(this.table, row, table);
  14000. return true;
  14001. } else {
  14002. console.warn("Move Row Error - Table cannot accept connection, already connected to table:", this.connectedTable);
  14003. return false;
  14004. }
  14005. };
  14006. //close incomming connection
  14007. MoveRows.prototype.disconnect = function (table) {
  14008. var self = this;
  14009. if (table === this.connectedTable) {
  14010. this.connectedTable = false;
  14011. this.connectedRow = false;
  14012. this.table.element.classList.remove("tabulator-movingrow-receiving");
  14013. self.table.rowManager.getDisplayRows().forEach(function (row) {
  14014. if (row.type === "row" && row.modules.moveRow && row.modules.moveRow.mouseup) {
  14015. row.getElement().removeEventListener("mouseup", row.modules.moveRow.mouseup);
  14016. }
  14017. });
  14018. self.table.element.removeEventListener("mouseup", self.tableRowDropEvent);
  14019. this.table.options.movableRowsReceivingStop.call(this.table, table);
  14020. } else {
  14021. console.warn("Move Row Error - trying to disconnect from non connected table");
  14022. }
  14023. };
  14024. MoveRows.prototype.dropComplete = function (table, row, success) {
  14025. var sender = false;
  14026. if (success) {
  14027. switch (_typeof(this.table.options.movableRowsSender)) {
  14028. case "string":
  14029. sender = this.senders[this.table.options.movableRowsSender];
  14030. break;
  14031. case "function":
  14032. sender = this.table.options.movableRowsSender;
  14033. break;
  14034. }
  14035. if (sender) {
  14036. sender.call(this, this.moving.getComponent(), row ? row.getComponent() : undefined, table);
  14037. } else {
  14038. if (this.table.options.movableRowsSender) {
  14039. console.warn("Mover Row Error - no matching sender found:", this.table.options.movableRowsSender);
  14040. }
  14041. }
  14042. this.table.options.movableRowsSent.call(this.table, this.moving.getComponent(), row ? row.getComponent() : undefined, table);
  14043. } else {
  14044. this.table.options.movableRowsSentFailed.call(this.table, this.moving.getComponent(), row ? row.getComponent() : undefined, table);
  14045. }
  14046. this.endMove();
  14047. };
  14048. MoveRows.prototype.tableRowDrop = function (e, row) {
  14049. var receiver = false,
  14050. success = false;
  14051. e.stopImmediatePropagation();
  14052. switch (_typeof(this.table.options.movableRowsReceiver)) {
  14053. case "string":
  14054. receiver = this.receivers[this.table.options.movableRowsReceiver];
  14055. break;
  14056. case "function":
  14057. receiver = this.table.options.movableRowsReceiver;
  14058. break;
  14059. }
  14060. if (receiver) {
  14061. success = receiver.call(this, this.connectedRow.getComponent(), row ? row.getComponent() : undefined, this.connectedTable);
  14062. } else {
  14063. console.warn("Mover Row Error - no matching receiver found:", this.table.options.movableRowsReceiver);
  14064. }
  14065. if (success) {
  14066. this.table.options.movableRowsReceived.call(this.table, this.connectedRow.getComponent(), row ? row.getComponent() : undefined, this.connectedTable);
  14067. } else {
  14068. this.table.options.movableRowsReceivedFailed.call(this.table, this.connectedRow.getComponent(), row ? row.getComponent() : undefined, this.connectedTable);
  14069. }
  14070. this.table.modules.comms.send(this.connectedTable, "moveRow", "dropcomplete", {
  14071. row: row,
  14072. success: success
  14073. });
  14074. };
  14075. MoveRows.prototype.receivers = {
  14076. insert: function insert(fromRow, toRow, fromTable) {
  14077. this.table.addRow(fromRow.getData(), undefined, toRow);
  14078. return true;
  14079. },
  14080. add: function add(fromRow, toRow, fromTable) {
  14081. this.table.addRow(fromRow.getData());
  14082. return true;
  14083. },
  14084. update: function update(fromRow, toRow, fromTable) {
  14085. if (toRow) {
  14086. toRow.update(fromRow.getData());
  14087. return true;
  14088. }
  14089. return false;
  14090. },
  14091. replace: function replace(fromRow, toRow, fromTable) {
  14092. if (toRow) {
  14093. this.table.addRow(fromRow.getData(), undefined, toRow);
  14094. toRow.delete();
  14095. return true;
  14096. }
  14097. return false;
  14098. }
  14099. };
  14100. MoveRows.prototype.senders = {
  14101. delete: function _delete(fromRow, toRow, toTable) {
  14102. fromRow.delete();
  14103. }
  14104. };
  14105. MoveRows.prototype.commsReceived = function (table, action, data) {
  14106. switch (action) {
  14107. case "connect":
  14108. return this.connect(table, data.row);
  14109. break;
  14110. case "disconnect":
  14111. return this.disconnect(table);
  14112. break;
  14113. case "dropcomplete":
  14114. return this.dropComplete(table, data.row, data.success);
  14115. break;
  14116. }
  14117. };
  14118. Tabulator.prototype.registerModule("moveRow", MoveRows);
  14119. var Mutator = function Mutator(table) {
  14120. this.table = table; //hold Tabulator object
  14121. this.allowedTypes = ["", "data", "edit", "clipboard"]; //list of muatation types
  14122. this.enabled = true;
  14123. };
  14124. //initialize column mutator
  14125. Mutator.prototype.initializeColumn = function (column) {
  14126. var self = this,
  14127. match = false,
  14128. config = {};
  14129. this.allowedTypes.forEach(function (type) {
  14130. var key = "mutator" + (type.charAt(0).toUpperCase() + type.slice(1)),
  14131. mutator;
  14132. if (column.definition[key]) {
  14133. mutator = self.lookupMutator(column.definition[key]);
  14134. if (mutator) {
  14135. match = true;
  14136. config[key] = {
  14137. mutator: mutator,
  14138. params: column.definition[key + "Params"] || {}
  14139. };
  14140. }
  14141. }
  14142. });
  14143. if (match) {
  14144. column.modules.mutate = config;
  14145. }
  14146. };
  14147. Mutator.prototype.lookupMutator = function (value) {
  14148. var mutator = false;
  14149. //set column mutator
  14150. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  14151. case "string":
  14152. if (this.mutators[value]) {
  14153. mutator = this.mutators[value];
  14154. } else {
  14155. console.warn("Mutator Error - No such mutator found, ignoring: ", value);
  14156. }
  14157. break;
  14158. case "function":
  14159. mutator = value;
  14160. break;
  14161. }
  14162. return mutator;
  14163. };
  14164. //apply mutator to row
  14165. Mutator.prototype.transformRow = function (data, type, updatedData) {
  14166. var self = this,
  14167. key = "mutator" + (type.charAt(0).toUpperCase() + type.slice(1)),
  14168. value;
  14169. if (this.enabled) {
  14170. self.table.columnManager.traverse(function (column) {
  14171. var mutator, params, component;
  14172. if (column.modules.mutate) {
  14173. mutator = column.modules.mutate[key] || column.modules.mutate.mutator || false;
  14174. if (mutator) {
  14175. value = column.getFieldValue(typeof updatedData !== "undefined" ? updatedData : data);
  14176. if (type == "data" || typeof value !== "undefined") {
  14177. component = column.getComponent();
  14178. params = typeof mutator.params === "function" ? mutator.params(value, data, type, component) : mutator.params;
  14179. column.setFieldValue(data, mutator.mutator(value, data, type, params, component));
  14180. }
  14181. }
  14182. }
  14183. });
  14184. }
  14185. return data;
  14186. };
  14187. //apply mutator to new cell value
  14188. Mutator.prototype.transformCell = function (cell, value) {
  14189. var mutator = cell.column.modules.mutate.mutatorEdit || cell.column.modules.mutate.mutator || false,
  14190. tempData = {};
  14191. if (mutator) {
  14192. tempData = Object.assign(tempData, cell.row.getData());
  14193. cell.column.setFieldValue(tempData, value);
  14194. return mutator.mutator(value, tempData, "edit", mutator.params, cell.getComponent());
  14195. } else {
  14196. return value;
  14197. }
  14198. };
  14199. Mutator.prototype.enable = function () {
  14200. this.enabled = true;
  14201. };
  14202. Mutator.prototype.disable = function () {
  14203. this.enabled = false;
  14204. };
  14205. //default mutators
  14206. Mutator.prototype.mutators = {};
  14207. Tabulator.prototype.registerModule("mutator", Mutator);
  14208. var Page = function Page(table) {
  14209. this.table = table; //hold Tabulator object
  14210. this.mode = "local";
  14211. this.progressiveLoad = false;
  14212. this.size = 0;
  14213. this.page = 1;
  14214. this.count = 5;
  14215. this.max = 1;
  14216. this.displayIndex = 0; //index in display pipeline
  14217. this.initialLoad = true;
  14218. this.pageSizes = [];
  14219. this.dataReceivedNames = {};
  14220. this.dataSentNames = {};
  14221. this.createElements();
  14222. };
  14223. Page.prototype.createElements = function () {
  14224. var button;
  14225. this.element = document.createElement("span");
  14226. this.element.classList.add("tabulator-paginator");
  14227. this.pagesElement = document.createElement("span");
  14228. this.pagesElement.classList.add("tabulator-pages");
  14229. button = document.createElement("button");
  14230. button.classList.add("tabulator-page");
  14231. button.setAttribute("type", "button");
  14232. button.setAttribute("role", "button");
  14233. button.setAttribute("aria-label", "");
  14234. button.setAttribute("title", "");
  14235. this.firstBut = button.cloneNode(true);
  14236. this.firstBut.setAttribute("data-page", "first");
  14237. this.prevBut = button.cloneNode(true);
  14238. this.prevBut.setAttribute("data-page", "prev");
  14239. this.nextBut = button.cloneNode(true);
  14240. this.nextBut.setAttribute("data-page", "next");
  14241. this.lastBut = button.cloneNode(true);
  14242. this.lastBut.setAttribute("data-page", "last");
  14243. if (this.table.options.paginationSizeSelector) {
  14244. this.pageSizeSelect = document.createElement("select");
  14245. this.pageSizeSelect.classList.add("tabulator-page-size");
  14246. }
  14247. };
  14248. Page.prototype.generatePageSizeSelectList = function () {
  14249. var _this63 = this;
  14250. var pageSizes = [];
  14251. if (this.pageSizeSelect) {
  14252. if (Array.isArray(this.table.options.paginationSizeSelector)) {
  14253. pageSizes = this.table.options.paginationSizeSelector;
  14254. this.pageSizes = pageSizes;
  14255. if (this.pageSizes.indexOf(this.size) == -1) {
  14256. pageSizes.unshift(this.size);
  14257. }
  14258. } else {
  14259. if (this.pageSizes.indexOf(this.size) == -1) {
  14260. pageSizes = [];
  14261. for (var i = 1; i < 5; i++) {
  14262. pageSizes.push(this.size * i);
  14263. }
  14264. this.pageSizes = pageSizes;
  14265. } else {
  14266. pageSizes = this.pageSizes;
  14267. }
  14268. }
  14269. while (this.pageSizeSelect.firstChild) {
  14270. this.pageSizeSelect.removeChild(this.pageSizeSelect.firstChild);
  14271. }pageSizes.forEach(function (item) {
  14272. var itemEl = document.createElement("option");
  14273. itemEl.value = item;
  14274. itemEl.innerHTML = item;
  14275. _this63.pageSizeSelect.appendChild(itemEl);
  14276. });
  14277. this.pageSizeSelect.value = this.size;
  14278. }
  14279. };
  14280. //setup pageination
  14281. Page.prototype.initialize = function (hidden) {
  14282. var self = this,
  14283. pageSelectLabel,
  14284. testElRow,
  14285. testElCell;
  14286. //update param names
  14287. this.dataSentNames = Object.assign({}, this.paginationDataSentNames);
  14288. this.dataSentNames = Object.assign(this.dataSentNames, this.table.options.paginationDataSent);
  14289. this.dataReceivedNames = Object.assign({}, this.paginationDataReceivedNames);
  14290. this.dataReceivedNames = Object.assign(this.dataReceivedNames, this.table.options.paginationDataReceived);
  14291. //build pagination element
  14292. //bind localizations
  14293. self.table.modules.localize.bind("pagination|first", function (value) {
  14294. self.firstBut.innerHTML = value;
  14295. });
  14296. self.table.modules.localize.bind("pagination|first_title", function (value) {
  14297. self.firstBut.setAttribute("aria-label", value);
  14298. self.firstBut.setAttribute("title", value);
  14299. });
  14300. self.table.modules.localize.bind("pagination|prev", function (value) {
  14301. self.prevBut.innerHTML = value;
  14302. });
  14303. self.table.modules.localize.bind("pagination|prev_title", function (value) {
  14304. self.prevBut.setAttribute("aria-label", value);
  14305. self.prevBut.setAttribute("title", value);
  14306. });
  14307. self.table.modules.localize.bind("pagination|next", function (value) {
  14308. self.nextBut.innerHTML = value;
  14309. });
  14310. self.table.modules.localize.bind("pagination|next_title", function (value) {
  14311. self.nextBut.setAttribute("aria-label", value);
  14312. self.nextBut.setAttribute("title", value);
  14313. });
  14314. self.table.modules.localize.bind("pagination|last", function (value) {
  14315. self.lastBut.innerHTML = value;
  14316. });
  14317. self.table.modules.localize.bind("pagination|last_title", function (value) {
  14318. self.lastBut.setAttribute("aria-label", value);
  14319. self.lastBut.setAttribute("title", value);
  14320. });
  14321. //click bindings
  14322. self.firstBut.addEventListener("click", function () {
  14323. self.setPage(1);
  14324. });
  14325. self.prevBut.addEventListener("click", function () {
  14326. self.previousPage();
  14327. });
  14328. self.nextBut.addEventListener("click", function () {
  14329. self.nextPage().then(function () {}).catch(function () {});
  14330. });
  14331. self.lastBut.addEventListener("click", function () {
  14332. self.setPage(self.max);
  14333. });
  14334. if (self.table.options.paginationElement) {
  14335. self.element = self.table.options.paginationElement;
  14336. }
  14337. if (this.pageSizeSelect) {
  14338. pageSelectLabel = document.createElement("label");
  14339. self.table.modules.localize.bind("pagination|page_size", function (value) {
  14340. self.pageSizeSelect.setAttribute("aria-label", value);
  14341. self.pageSizeSelect.setAttribute("title", value);
  14342. pageSelectLabel.innerHTML = value;
  14343. });
  14344. self.element.appendChild(pageSelectLabel);
  14345. self.element.appendChild(self.pageSizeSelect);
  14346. self.pageSizeSelect.addEventListener("change", function (e) {
  14347. self.setPageSize(self.pageSizeSelect.value);
  14348. self.setPage(1).then(function () {}).catch(function () {});
  14349. });
  14350. }
  14351. //append to DOM
  14352. self.element.appendChild(self.firstBut);
  14353. self.element.appendChild(self.prevBut);
  14354. self.element.appendChild(self.pagesElement);
  14355. self.element.appendChild(self.nextBut);
  14356. self.element.appendChild(self.lastBut);
  14357. if (!self.table.options.paginationElement && !hidden) {
  14358. self.table.footerManager.append(self.element, self);
  14359. }
  14360. //set default values
  14361. self.mode = self.table.options.pagination;
  14362. if (self.table.options.paginationSize) {
  14363. self.size = self.table.options.paginationSize;
  14364. } else {
  14365. testElRow = document.createElement("div");
  14366. testElRow.classList.add("tabulator-row");
  14367. testElRow.style.visibility = hidden;
  14368. testElCell = document.createElement("div");
  14369. testElCell.classList.add("tabulator-cell");
  14370. testElCell.innerHTML = "Page Row Test";
  14371. testElRow.appendChild(testElCell);
  14372. self.table.rowManager.getTableElement().appendChild(testElRow);
  14373. self.size = Math.floor(self.table.rowManager.getElement().clientHeight / testElRow.offsetHeight);
  14374. self.table.rowManager.getTableElement().removeChild(testElRow);
  14375. }
  14376. // self.page = self.table.options.paginationInitialPage || 1;
  14377. self.count = self.table.options.paginationButtonCount;
  14378. self.generatePageSizeSelectList();
  14379. };
  14380. Page.prototype.initializeProgressive = function (mode) {
  14381. this.initialize(true);
  14382. this.mode = "progressive_" + mode;
  14383. this.progressiveLoad = true;
  14384. };
  14385. Page.prototype.setDisplayIndex = function (index) {
  14386. this.displayIndex = index;
  14387. };
  14388. Page.prototype.getDisplayIndex = function () {
  14389. return this.displayIndex;
  14390. };
  14391. //calculate maximum page from number of rows
  14392. Page.prototype.setMaxRows = function (rowCount) {
  14393. if (!rowCount) {
  14394. this.max = 1;
  14395. } else {
  14396. this.max = Math.ceil(rowCount / this.size);
  14397. }
  14398. if (this.page > this.max) {
  14399. this.page = this.max;
  14400. }
  14401. };
  14402. //reset to first page without triggering action
  14403. Page.prototype.reset = function (force, columnsChanged) {
  14404. if (this.mode == "local" || force) {
  14405. this.page = 1;
  14406. }
  14407. if (columnsChanged) {
  14408. this.initialLoad = true;
  14409. }
  14410. return true;
  14411. };
  14412. //set the maxmum page
  14413. Page.prototype.setMaxPage = function (max) {
  14414. max = parseInt(max);
  14415. this.max = max || 1;
  14416. if (this.page > this.max) {
  14417. this.page = this.max;
  14418. this.trigger();
  14419. }
  14420. };
  14421. //set current page number
  14422. Page.prototype.setPage = function (page) {
  14423. var _this64 = this;
  14424. var self = this;
  14425. return new Promise(function (resolve, reject) {
  14426. page = parseInt(page);
  14427. if (page > 0 && page <= _this64.max) {
  14428. _this64.page = page;
  14429. _this64.trigger().then(function () {
  14430. resolve();
  14431. }).catch(function () {
  14432. reject();
  14433. });
  14434. if (self.table.options.persistence && self.table.modExists("persistence", true) && self.table.modules.persistence.config.page) {
  14435. self.table.modules.persistence.save("page");
  14436. }
  14437. } else {
  14438. console.warn("Pagination Error - Requested page is out of range of 1 - " + _this64.max + ":", page);
  14439. reject();
  14440. }
  14441. });
  14442. };
  14443. Page.prototype.setPageToRow = function (row) {
  14444. var _this65 = this;
  14445. return new Promise(function (resolve, reject) {
  14446. var rows = _this65.table.rowManager.getDisplayRows(_this65.displayIndex - 1);
  14447. var index = rows.indexOf(row);
  14448. if (index > -1) {
  14449. var page = Math.ceil((index + 1) / _this65.size);
  14450. _this65.setPage(page).then(function () {
  14451. resolve();
  14452. }).catch(function () {
  14453. reject();
  14454. });
  14455. } else {
  14456. console.warn("Pagination Error - Requested row is not visible");
  14457. reject();
  14458. }
  14459. });
  14460. };
  14461. Page.prototype.setPageSize = function (size) {
  14462. size = parseInt(size);
  14463. if (size > 0) {
  14464. this.size = size;
  14465. }
  14466. if (this.pageSizeSelect) {
  14467. // this.pageSizeSelect.value = size;
  14468. this.generatePageSizeSelectList();
  14469. }
  14470. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.page) {
  14471. this.table.modules.persistence.save("page");
  14472. }
  14473. };
  14474. //setup the pagination buttons
  14475. Page.prototype._setPageButtons = function () {
  14476. var self = this;
  14477. var leftSize = Math.floor((this.count - 1) / 2);
  14478. var rightSize = Math.ceil((this.count - 1) / 2);
  14479. var min = this.max - this.page + leftSize + 1 < this.count ? this.max - this.count + 1 : Math.max(this.page - leftSize, 1);
  14480. var max = this.page <= rightSize ? Math.min(this.count, this.max) : Math.min(this.page + rightSize, this.max);
  14481. while (self.pagesElement.firstChild) {
  14482. self.pagesElement.removeChild(self.pagesElement.firstChild);
  14483. }if (self.page == 1) {
  14484. self.firstBut.disabled = true;
  14485. self.prevBut.disabled = true;
  14486. } else {
  14487. self.firstBut.disabled = false;
  14488. self.prevBut.disabled = false;
  14489. }
  14490. if (self.page == self.max) {
  14491. self.lastBut.disabled = true;
  14492. self.nextBut.disabled = true;
  14493. } else {
  14494. self.lastBut.disabled = false;
  14495. self.nextBut.disabled = false;
  14496. }
  14497. for (var i = min; i <= max; i++) {
  14498. if (i > 0 && i <= self.max) {
  14499. self.pagesElement.appendChild(self._generatePageButton(i));
  14500. }
  14501. }
  14502. this.footerRedraw();
  14503. };
  14504. Page.prototype._generatePageButton = function (page) {
  14505. var self = this,
  14506. button = document.createElement("button");
  14507. button.classList.add("tabulator-page");
  14508. if (page == self.page) {
  14509. button.classList.add("active");
  14510. }
  14511. button.setAttribute("type", "button");
  14512. button.setAttribute("role", "button");
  14513. button.setAttribute("aria-label", "Show Page " + page);
  14514. button.setAttribute("title", "Show Page " + page);
  14515. button.setAttribute("data-page", page);
  14516. button.textContent = page;
  14517. button.addEventListener("click", function (e) {
  14518. self.setPage(page);
  14519. });
  14520. return button;
  14521. };
  14522. //previous page
  14523. Page.prototype.previousPage = function () {
  14524. var _this66 = this;
  14525. return new Promise(function (resolve, reject) {
  14526. if (_this66.page > 1) {
  14527. _this66.page--;
  14528. _this66.trigger().then(function () {
  14529. resolve();
  14530. }).catch(function () {
  14531. reject();
  14532. });
  14533. if (_this66.table.options.persistence && _this66.table.modExists("persistence", true) && _this66.table.modules.persistence.config.page) {
  14534. _this66.table.modules.persistence.save("page");
  14535. }
  14536. } else {
  14537. console.warn("Pagination Error - Previous page would be less than page 1:", 0);
  14538. reject();
  14539. }
  14540. });
  14541. };
  14542. //next page
  14543. Page.prototype.nextPage = function () {
  14544. var _this67 = this;
  14545. return new Promise(function (resolve, reject) {
  14546. if (_this67.page < _this67.max) {
  14547. _this67.page++;
  14548. _this67.trigger().then(function () {
  14549. resolve();
  14550. }).catch(function () {
  14551. reject();
  14552. });
  14553. if (_this67.table.options.persistence && _this67.table.modExists("persistence", true) && _this67.table.modules.persistence.config.page) {
  14554. _this67.table.modules.persistence.save("page");
  14555. }
  14556. } else {
  14557. if (!_this67.progressiveLoad) {
  14558. console.warn("Pagination Error - Next page would be greater than maximum page of " + _this67.max + ":", _this67.max + 1);
  14559. }
  14560. reject();
  14561. }
  14562. });
  14563. };
  14564. //return current page number
  14565. Page.prototype.getPage = function () {
  14566. return this.page;
  14567. };
  14568. //return max page number
  14569. Page.prototype.getPageMax = function () {
  14570. return this.max;
  14571. };
  14572. Page.prototype.getPageSize = function (size) {
  14573. return this.size;
  14574. };
  14575. Page.prototype.getMode = function () {
  14576. return this.mode;
  14577. };
  14578. //return appropriate rows for current page
  14579. Page.prototype.getRows = function (data) {
  14580. var output, start, end;
  14581. if (this.mode == "local") {
  14582. output = [];
  14583. start = this.size * (this.page - 1);
  14584. end = start + parseInt(this.size);
  14585. this._setPageButtons();
  14586. for (var i = start; i < end; i++) {
  14587. if (data[i]) {
  14588. output.push(data[i]);
  14589. }
  14590. }
  14591. return output;
  14592. } else {
  14593. this._setPageButtons();
  14594. return data.slice(0);
  14595. }
  14596. };
  14597. Page.prototype.trigger = function () {
  14598. var _this68 = this;
  14599. var left;
  14600. return new Promise(function (resolve, reject) {
  14601. switch (_this68.mode) {
  14602. case "local":
  14603. left = _this68.table.rowManager.scrollLeft;
  14604. _this68.table.rowManager.refreshActiveData("page");
  14605. _this68.table.rowManager.scrollHorizontal(left);
  14606. _this68.table.options.pageLoaded.call(_this68.table, _this68.getPage());
  14607. resolve();
  14608. break;
  14609. case "remote":
  14610. case "progressive_load":
  14611. case "progressive_scroll":
  14612. _this68.table.modules.ajax.blockActiveRequest();
  14613. _this68._getRemotePage().then(function () {
  14614. resolve();
  14615. }).catch(function () {
  14616. reject();
  14617. });
  14618. break;
  14619. default:
  14620. console.warn("Pagination Error - no such pagination mode:", _this68.mode);
  14621. reject();
  14622. }
  14623. });
  14624. };
  14625. Page.prototype._getRemotePage = function () {
  14626. var _this69 = this;
  14627. var self = this,
  14628. oldParams,
  14629. pageParams;
  14630. return new Promise(function (resolve, reject) {
  14631. if (!self.table.modExists("ajax", true)) {
  14632. reject();
  14633. }
  14634. //record old params and restore after request has been made
  14635. oldParams = Tabulator.prototype.helpers.deepClone(self.table.modules.ajax.getParams() || {});
  14636. pageParams = self.table.modules.ajax.getParams();
  14637. //configure request params
  14638. pageParams[_this69.dataSentNames.page] = self.page;
  14639. //set page size if defined
  14640. if (_this69.size) {
  14641. pageParams[_this69.dataSentNames.size] = _this69.size;
  14642. }
  14643. //set sort data if defined
  14644. if (_this69.table.options.ajaxSorting && _this69.table.modExists("sort")) {
  14645. var sorters = self.table.modules.sort.getSort();
  14646. sorters.forEach(function (item) {
  14647. delete item.column;
  14648. });
  14649. pageParams[_this69.dataSentNames.sorters] = sorters;
  14650. }
  14651. //set filter data if defined
  14652. if (_this69.table.options.ajaxFiltering && _this69.table.modExists("filter")) {
  14653. var filters = self.table.modules.filter.getFilters(true, true);
  14654. pageParams[_this69.dataSentNames.filters] = filters;
  14655. }
  14656. self.table.modules.ajax.setParams(pageParams);
  14657. self.table.modules.ajax.sendRequest(_this69.progressiveLoad).then(function (data) {
  14658. self._parseRemoteData(data);
  14659. resolve();
  14660. }).catch(function (e) {
  14661. reject();
  14662. });
  14663. self.table.modules.ajax.setParams(oldParams);
  14664. });
  14665. };
  14666. Page.prototype._parseRemoteData = function (data) {
  14667. var self = this,
  14668. left,
  14669. data,
  14670. margin;
  14671. if (typeof data[this.dataReceivedNames.last_page] === "undefined") {
  14672. console.warn("Remote Pagination Error - Server response missing '" + this.dataReceivedNames.last_page + "' property");
  14673. }
  14674. if (data[this.dataReceivedNames.data]) {
  14675. this.max = parseInt(data[this.dataReceivedNames.last_page]) || 1;
  14676. if (this.progressiveLoad) {
  14677. switch (this.mode) {
  14678. case "progressive_load":
  14679. if (this.page == 1) {
  14680. this.table.rowManager.setData(data[this.dataReceivedNames.data], false, this.initialLoad && this.page == 1);
  14681. } else {
  14682. this.table.rowManager.addRows(data[this.dataReceivedNames.data]);
  14683. }
  14684. if (this.page < this.max) {
  14685. setTimeout(function () {
  14686. self.nextPage().then(function () {}).catch(function () {});
  14687. }, self.table.options.ajaxProgressiveLoadDelay);
  14688. }
  14689. break;
  14690. case "progressive_scroll":
  14691. data = this.table.rowManager.getData().concat(data[this.dataReceivedNames.data]);
  14692. this.table.rowManager.setData(data, true, this.initialLoad && this.page == 1);
  14693. margin = this.table.options.ajaxProgressiveLoadScrollMargin || this.table.rowManager.element.clientHeight * 2;
  14694. if (self.table.rowManager.element.scrollHeight <= self.table.rowManager.element.clientHeight + margin) {
  14695. self.nextPage().then(function () {}).catch(function () {});
  14696. }
  14697. break;
  14698. }
  14699. } else {
  14700. left = this.table.rowManager.scrollLeft;
  14701. this.table.rowManager.setData(data[this.dataReceivedNames.data], false, this.initialLoad && this.page == 1);
  14702. this.table.rowManager.scrollHorizontal(left);
  14703. this.table.columnManager.scrollHorizontal(left);
  14704. this.table.options.pageLoaded.call(this.table, this.getPage());
  14705. }
  14706. this.initialLoad = false;
  14707. } else {
  14708. console.warn("Remote Pagination Error - Server response missing '" + this.dataReceivedNames.data + "' property");
  14709. }
  14710. };
  14711. //handle the footer element being redrawn
  14712. Page.prototype.footerRedraw = function () {
  14713. var footer = this.table.footerManager.element;
  14714. if (Math.ceil(footer.clientWidth) - footer.scrollWidth < 0) {
  14715. this.pagesElement.style.display = 'none';
  14716. } else {
  14717. this.pagesElement.style.display = '';
  14718. if (Math.ceil(footer.clientWidth) - footer.scrollWidth < 0) {
  14719. this.pagesElement.style.display = 'none';
  14720. }
  14721. }
  14722. };
  14723. //set the paramter names for pagination requests
  14724. Page.prototype.paginationDataSentNames = {
  14725. "page": "page",
  14726. "size": "size",
  14727. "sorters": "sorters",
  14728. // "sort_dir":"sort_dir",
  14729. "filters": "filters"
  14730. // "filter_value":"filter_value",
  14731. // "filter_type":"filter_type",
  14732. };
  14733. //set the property names for pagination responses
  14734. Page.prototype.paginationDataReceivedNames = {
  14735. "current_page": "current_page",
  14736. "last_page": "last_page",
  14737. "data": "data"
  14738. };
  14739. Tabulator.prototype.registerModule("page", Page);
  14740. var Persistence = function Persistence(table) {
  14741. this.table = table; //hold Tabulator object
  14742. this.mode = "";
  14743. this.id = "";
  14744. // this.persistProps = ["field", "width", "visible"];
  14745. this.defWatcherBlock = false;
  14746. this.config = {};
  14747. this.readFunc = false;
  14748. this.writeFunc = false;
  14749. };
  14750. // Test for whether localStorage is available for use.
  14751. Persistence.prototype.localStorageTest = function () {
  14752. var testKey = "_tabulator_test";
  14753. try {
  14754. window.localStorage.setItem(testKey, testKey);
  14755. window.localStorage.removeItem(testKey);
  14756. return true;
  14757. } catch (e) {
  14758. return false;
  14759. }
  14760. };
  14761. //setup parameters
  14762. Persistence.prototype.initialize = function () {
  14763. //determine persistent layout storage type
  14764. var mode = this.table.options.persistenceMode,
  14765. id = this.table.options.persistenceID,
  14766. retreivedData;
  14767. this.mode = mode !== true ? mode : this.localStorageTest() ? "local" : "cookie";
  14768. if (this.table.options.persistenceReaderFunc) {
  14769. if (typeof this.table.options.persistenceReaderFunc === "function") {
  14770. this.readFunc = this.table.options.persistenceReaderFunc;
  14771. } else {
  14772. if (this.readers[this.table.options.persistenceReaderFunc]) {
  14773. this.readFunc = this.readers[this.table.options.persistenceReaderFunc];
  14774. } else {
  14775. console.warn("Persistence Read Error - invalid reader set", this.table.options.persistenceReaderFunc);
  14776. }
  14777. }
  14778. } else {
  14779. if (this.readers[this.mode]) {
  14780. this.readFunc = this.readers[this.mode];
  14781. } else {
  14782. console.warn("Persistence Read Error - invalid reader set", this.mode);
  14783. }
  14784. }
  14785. if (this.table.options.persistenceWriterFunc) {
  14786. if (typeof this.table.options.persistenceWriterFunc === "function") {
  14787. this.writeFunc = this.table.options.persistenceWriterFunc;
  14788. } else {
  14789. if (this.readers[this.table.options.persistenceWriterFunc]) {
  14790. this.writeFunc = this.readers[this.table.options.persistenceWriterFunc];
  14791. } else {
  14792. console.warn("Persistence Write Error - invalid reader set", this.table.options.persistenceWriterFunc);
  14793. }
  14794. }
  14795. } else {
  14796. if (this.writers[this.mode]) {
  14797. this.writeFunc = this.writers[this.mode];
  14798. } else {
  14799. console.warn("Persistence Write Error - invalid writer set", this.mode);
  14800. }
  14801. }
  14802. //set storage tag
  14803. this.id = "tabulator-" + (id || this.table.element.getAttribute("id") || "");
  14804. this.config = {
  14805. sort: this.table.options.persistence === true || this.table.options.persistence.sort,
  14806. filter: this.table.options.persistence === true || this.table.options.persistence.filter,
  14807. group: this.table.options.persistence === true || this.table.options.persistence.group,
  14808. page: this.table.options.persistence === true || this.table.options.persistence.page,
  14809. columns: this.table.options.persistence === true ? ["title", "width", "visible"] : this.table.options.persistence.columns
  14810. };
  14811. //load pagination data if needed
  14812. if (this.config.page) {
  14813. retreivedData = this.retreiveData("page");
  14814. if (retreivedData) {
  14815. if (typeof retreivedData.paginationSize !== "undefined" && (this.config.page === true || this.config.page.size)) {
  14816. this.table.options.paginationSize = retreivedData.paginationSize;
  14817. }
  14818. if (typeof retreivedData.paginationInitialPage !== "undefined" && (this.config.page === true || this.config.page.page)) {
  14819. this.table.options.paginationInitialPage = retreivedData.paginationInitialPage;
  14820. }
  14821. }
  14822. }
  14823. //load group data if needed
  14824. if (this.config.group) {
  14825. retreivedData = this.retreiveData("group");
  14826. if (retreivedData) {
  14827. if (typeof retreivedData.groupBy !== "undefined" && (this.config.group === true || this.config.group.groupBy)) {
  14828. this.table.options.groupBy = retreivedData.groupBy;
  14829. }
  14830. if (typeof retreivedData.groupStartOpen !== "undefined" && (this.config.group === true || this.config.group.groupStartOpen)) {
  14831. this.table.options.groupStartOpen = retreivedData.groupStartOpen;
  14832. }
  14833. if (typeof retreivedData.groupHeader !== "undefined" && (this.config.group === true || this.config.group.groupHeader)) {
  14834. this.table.options.groupHeader = retreivedData.groupHeader;
  14835. }
  14836. }
  14837. }
  14838. };
  14839. Persistence.prototype.initializeColumn = function (column) {
  14840. var self = this,
  14841. def,
  14842. keys;
  14843. if (this.config.columns) {
  14844. this.defWatcherBlock = true;
  14845. def = column.getDefinition();
  14846. keys = this.config.columns === true ? Object.keys(def) : this.config.columns;
  14847. keys.forEach(function (key) {
  14848. var props = Object.getOwnPropertyDescriptor(def, key);
  14849. var value = def[key];
  14850. if (props) {
  14851. Object.defineProperty(def, key, {
  14852. set: function set(newValue) {
  14853. value = newValue;
  14854. if (!self.defWatcherBlock) {
  14855. self.save("columns");
  14856. }
  14857. if (props.set) {
  14858. props.set(newValue);
  14859. }
  14860. },
  14861. get: function get() {
  14862. if (props.get) {
  14863. props.get();
  14864. }
  14865. return value;
  14866. }
  14867. });
  14868. }
  14869. });
  14870. this.defWatcherBlock = false;
  14871. }
  14872. };
  14873. //load saved definitions
  14874. Persistence.prototype.load = function (type, current) {
  14875. var data = this.retreiveData(type);
  14876. if (current) {
  14877. data = data ? this.mergeDefinition(current, data) : current;
  14878. }
  14879. return data;
  14880. };
  14881. //retreive data from memory
  14882. Persistence.prototype.retreiveData = function (type) {
  14883. return this.readFunc ? this.readFunc(this.id, type) : false;
  14884. };
  14885. //merge old and new column definitions
  14886. Persistence.prototype.mergeDefinition = function (oldCols, newCols) {
  14887. var self = this,
  14888. output = [];
  14889. // oldCols = oldCols || [];
  14890. newCols = newCols || [];
  14891. newCols.forEach(function (column, to) {
  14892. var from = self._findColumn(oldCols, column),
  14893. keys;
  14894. if (from) {
  14895. if (self.config.columns === true || self.config.columns == undefined) {
  14896. keys = Object.keys(from);
  14897. keys.push("width");
  14898. } else {
  14899. keys = self.config.columns;
  14900. }
  14901. keys.forEach(function (key) {
  14902. if (typeof column[key] !== "undefined") {
  14903. from[key] = column[key];
  14904. }
  14905. });
  14906. if (from.columns) {
  14907. from.columns = self.mergeDefinition(from.columns, column.columns);
  14908. }
  14909. output.push(from);
  14910. }
  14911. });
  14912. oldCols.forEach(function (column, i) {
  14913. var from = self._findColumn(newCols, column);
  14914. if (!from) {
  14915. if (output.length > i) {
  14916. output.splice(i, 0, column);
  14917. } else {
  14918. output.push(column);
  14919. }
  14920. }
  14921. });
  14922. return output;
  14923. };
  14924. //find matching columns
  14925. Persistence.prototype._findColumn = function (columns, subject) {
  14926. var type = subject.columns ? "group" : subject.field ? "field" : "object";
  14927. return columns.find(function (col) {
  14928. switch (type) {
  14929. case "group":
  14930. return col.title === subject.title && col.columns.length === subject.columns.length;
  14931. break;
  14932. case "field":
  14933. return col.field === subject.field;
  14934. break;
  14935. case "object":
  14936. return col === subject;
  14937. break;
  14938. }
  14939. });
  14940. };
  14941. //save data
  14942. Persistence.prototype.save = function (type) {
  14943. var data = {};
  14944. switch (type) {
  14945. case "columns":
  14946. data = this.parseColumns(this.table.columnManager.getColumns());
  14947. break;
  14948. case "filter":
  14949. data = this.table.modules.filter.getFilters();
  14950. break;
  14951. case "sort":
  14952. data = this.validateSorters(this.table.modules.sort.getSort());
  14953. break;
  14954. case "group":
  14955. data = this.getGroupConfig();
  14956. break;
  14957. case "page":
  14958. data = this.getPageConfig();
  14959. break;
  14960. }
  14961. if (this.writeFunc) {
  14962. this.writeFunc(this.id, type, data);
  14963. }
  14964. };
  14965. //ensure sorters contain no function data
  14966. Persistence.prototype.validateSorters = function (data) {
  14967. data.forEach(function (item) {
  14968. item.column = item.field;
  14969. delete item.field;
  14970. });
  14971. return data;
  14972. };
  14973. Persistence.prototype.getGroupConfig = function () {
  14974. if (this.config.group) {
  14975. if (this.config.group === true || this.config.group.groupBy) {
  14976. data.groupBy = this.table.options.groupBy;
  14977. }
  14978. if (this.config.group === true || this.config.group.groupStartOpen) {
  14979. data.groupStartOpen = this.table.options.groupStartOpen;
  14980. }
  14981. if (this.config.group === true || this.config.group.groupHeader) {
  14982. data.groupHeader = this.table.options.groupHeader;
  14983. }
  14984. }
  14985. return data;
  14986. };
  14987. Persistence.prototype.getPageConfig = function () {
  14988. var data = {};
  14989. if (this.config.page) {
  14990. if (this.config.page === true || this.config.page.size) {
  14991. data.paginationSize = this.table.modules.page.getPageSize();
  14992. }
  14993. if (this.config.page === true || this.config.page.page) {
  14994. data.paginationInitialPage = this.table.modules.page.getPage();
  14995. }
  14996. }
  14997. return data;
  14998. };
  14999. //parse columns for data to store
  15000. Persistence.prototype.parseColumns = function (columns) {
  15001. var self = this,
  15002. definitions = [];
  15003. columns.forEach(function (column) {
  15004. var defStore = {},
  15005. colDef = column.getDefinition(),
  15006. keys;
  15007. if (column.isGroup) {
  15008. defStore.title = colDef.title;
  15009. defStore.columns = self.parseColumns(column.getColumns());
  15010. } else {
  15011. defStore.field = column.getField();
  15012. if (self.config.columns === true || self.config.columns == undefined) {
  15013. keys = Object.keys(colDef);
  15014. keys.push("width");
  15015. } else {
  15016. keys = self.config.columns;
  15017. }
  15018. keys.forEach(function (key) {
  15019. switch (key) {
  15020. case "width":
  15021. defStore.width = column.getWidth();
  15022. break;
  15023. case "visible":
  15024. defStore.visible = column.visible;
  15025. break;
  15026. default:
  15027. defStore[key] = colDef[key];
  15028. }
  15029. });
  15030. }
  15031. definitions.push(defStore);
  15032. });
  15033. return definitions;
  15034. };
  15035. // read peristence information from storage
  15036. Persistence.prototype.readers = {
  15037. local: function local(id, type) {
  15038. var data = localStorage.getItem(id + "-" + type);
  15039. return data ? JSON.parse(data) : false;
  15040. },
  15041. cookie: function cookie(id, type) {
  15042. var cookie = document.cookie,
  15043. key = id + "-" + type,
  15044. cookiePos = cookie.indexOf(key + "="),
  15045. end,
  15046. data;
  15047. //if cookie exists, decode and load column data into tabulator
  15048. if (cookiePos > -1) {
  15049. cookie = cookie.substr(cookiePos);
  15050. end = cookie.indexOf(";");
  15051. if (end > -1) {
  15052. cookie = cookie.substr(0, end);
  15053. }
  15054. data = cookie.replace(key + "=", "");
  15055. }
  15056. return data ? JSON.parse(data) : false;
  15057. }
  15058. };
  15059. //write persistence information to storage
  15060. Persistence.prototype.writers = {
  15061. local: function local(id, type, data) {
  15062. localStorage.setItem(id + "-" + type, JSON.stringify(data));
  15063. },
  15064. cookie: function cookie(id, type, data) {
  15065. var expireDate = new Date();
  15066. expireDate.setDate(expireDate.getDate() + 10000);
  15067. document.cookie = id + "-" + type + "=" + JSON.stringify(data) + "; expires=" + expireDate.toUTCString();
  15068. }
  15069. };
  15070. Tabulator.prototype.registerModule("persistence", Persistence);
  15071. var Print = function Print(table) {
  15072. this.table = table; //hold Tabulator object
  15073. this.element = false;
  15074. this.manualBlock = false;
  15075. };
  15076. Print.prototype.initialize = function () {
  15077. window.addEventListener("beforeprint", this.replaceTable.bind(this));
  15078. window.addEventListener("afterprint", this.cleanup.bind(this));
  15079. };
  15080. Print.prototype.replaceTable = function () {
  15081. if (!this.manualBlock) {
  15082. this.element = document.createElement("div");
  15083. this.element.classList.add("tabulator-print-table");
  15084. this.element.appendChild(this.table.modules.export.genereateTable(this.table.options.printConfig, this.table.options.printStyled, this.table.options.printRowRange, "print"));
  15085. this.table.element.style.display = "none";
  15086. this.table.element.parentNode.insertBefore(this.element, this.table.element);
  15087. }
  15088. };
  15089. Print.prototype.cleanup = function () {
  15090. document.body.classList.remove("tabulator-print-fullscreen-hide");
  15091. if (this.element && this.element.parentNode) {
  15092. this.element.parentNode.removeChild(this.element);
  15093. this.table.element.style.display = "";
  15094. }
  15095. };
  15096. Print.prototype.printFullscreen = function (visible, style, config) {
  15097. var scrollX = window.scrollX,
  15098. scrollY = window.scrollY,
  15099. headerEl = document.createElement("div"),
  15100. footerEl = document.createElement("div"),
  15101. tableEl = this.table.modules.export.genereateTable(typeof config != "undefined" ? config : this.table.options.printConfig, typeof style != "undefined" ? style : this.table.options.printStyled, visible, "print"),
  15102. headerContent,
  15103. footerContent;
  15104. this.manualBlock = true;
  15105. this.element = document.createElement("div");
  15106. this.element.classList.add("tabulator-print-fullscreen");
  15107. if (this.table.options.printHeader) {
  15108. headerEl.classList.add("tabulator-print-header");
  15109. headerContent = typeof this.table.options.printHeader == "function" ? this.table.options.printHeader.call(this.table) : this.table.options.printHeader;
  15110. if (typeof headerContent == "string") {
  15111. headerEl.innerHTML = headerContent;
  15112. } else {
  15113. headerEl.appendChild(headerContent);
  15114. }
  15115. this.element.appendChild(headerEl);
  15116. }
  15117. this.element.appendChild(tableEl);
  15118. if (this.table.options.printFooter) {
  15119. footerEl.classList.add("tabulator-print-footer");
  15120. footerContent = typeof this.table.options.printFooter == "function" ? this.table.options.printFooter.call(this.table) : this.table.options.printFooter;
  15121. if (typeof footerContent == "string") {
  15122. footerEl.innerHTML = footerContent;
  15123. } else {
  15124. footerEl.appendChild(footerContent);
  15125. }
  15126. this.element.appendChild(footerEl);
  15127. }
  15128. document.body.classList.add("tabulator-print-fullscreen-hide");
  15129. document.body.appendChild(this.element);
  15130. if (this.table.options.printFormatter) {
  15131. this.table.options.printFormatter(this.element, tableEl);
  15132. }
  15133. window.print();
  15134. this.cleanup();
  15135. window.scrollTo(scrollX, scrollY);
  15136. this.manualBlock = false;
  15137. };
  15138. Tabulator.prototype.registerModule("print", Print);
  15139. var ReactiveData = function ReactiveData(table) {
  15140. this.table = table; //hold Tabulator object
  15141. this.data = false;
  15142. this.blocked = false; //block reactivity while performing update
  15143. this.origFuncs = {}; // hold original data array functions to allow replacement after data is done with
  15144. this.currentVersion = 0;
  15145. };
  15146. ReactiveData.prototype.watchData = function (data) {
  15147. var self = this,
  15148. pushFunc,
  15149. version;
  15150. this.currentVersion++;
  15151. version = this.currentVersion;
  15152. self.unwatchData();
  15153. self.data = data;
  15154. //override array push function
  15155. self.origFuncs.push = data.push;
  15156. Object.defineProperty(self.data, "push", {
  15157. enumerable: false,
  15158. configurable: true,
  15159. value: function value() {
  15160. var args = Array.from(arguments);
  15161. if (!self.blocked && version === self.currentVersion) {
  15162. args.forEach(function (arg) {
  15163. self.table.rowManager.addRowActual(arg, false);
  15164. });
  15165. }
  15166. return self.origFuncs.push.apply(data, arguments);
  15167. }
  15168. });
  15169. //override array unshift function
  15170. self.origFuncs.unshift = data.unshift;
  15171. Object.defineProperty(self.data, "unshift", {
  15172. enumerable: false,
  15173. configurable: true,
  15174. value: function value() {
  15175. var args = Array.from(arguments);
  15176. if (!self.blocked && version === self.currentVersion) {
  15177. args.forEach(function (arg) {
  15178. self.table.rowManager.addRowActual(arg, true);
  15179. });
  15180. }
  15181. return self.origFuncs.unshift.apply(data, arguments);
  15182. }
  15183. });
  15184. //override array shift function
  15185. self.origFuncs.shift = data.shift;
  15186. Object.defineProperty(self.data, "shift", {
  15187. enumerable: false,
  15188. configurable: true,
  15189. value: function value() {
  15190. var row;
  15191. if (!self.blocked && version === self.currentVersion) {
  15192. if (self.data.length) {
  15193. row = self.table.rowManager.getRowFromDataObject(self.data[0]);
  15194. if (row) {
  15195. row.deleteActual();
  15196. }
  15197. }
  15198. }
  15199. return self.origFuncs.shift.call(data);
  15200. }
  15201. });
  15202. //override array pop function
  15203. self.origFuncs.pop = data.pop;
  15204. Object.defineProperty(self.data, "pop", {
  15205. enumerable: false,
  15206. configurable: true,
  15207. value: function value() {
  15208. var row;
  15209. if (!self.blocked && version === self.currentVersion) {
  15210. if (self.data.length) {
  15211. row = self.table.rowManager.getRowFromDataObject(self.data[self.data.length - 1]);
  15212. if (row) {
  15213. row.deleteActual();
  15214. }
  15215. }
  15216. }
  15217. return self.origFuncs.pop.call(data);
  15218. }
  15219. });
  15220. //override array splice function
  15221. self.origFuncs.splice = data.splice;
  15222. Object.defineProperty(self.data, "splice", {
  15223. enumerable: false,
  15224. configurable: true,
  15225. value: function value() {
  15226. var args = Array.from(arguments),
  15227. start = args[0] < 0 ? data.length + args[0] : args[0],
  15228. end = args[1],
  15229. newRows = args[2] ? args.slice(2) : false,
  15230. startRow;
  15231. if (!self.blocked && version === self.currentVersion) {
  15232. //add new rows
  15233. if (newRows) {
  15234. startRow = data[start] ? self.table.rowManager.getRowFromDataObject(data[start]) : false;
  15235. if (startRow) {
  15236. newRows.forEach(function (rowData) {
  15237. self.table.rowManager.addRowActual(rowData, true, startRow, true);
  15238. });
  15239. } else {
  15240. newRows = newRows.slice().reverse();
  15241. newRows.forEach(function (rowData) {
  15242. self.table.rowManager.addRowActual(rowData, true, false, true);
  15243. });
  15244. }
  15245. }
  15246. //delete removed rows
  15247. if (end !== 0) {
  15248. var oldRows = data.slice(start, typeof args[1] === "undefined" ? args[1] : start + end);
  15249. oldRows.forEach(function (rowData, i) {
  15250. var row = self.table.rowManager.getRowFromDataObject(rowData);
  15251. if (row) {
  15252. row.deleteActual(i !== oldRows.length - 1);
  15253. }
  15254. });
  15255. }
  15256. if (newRows || end !== 0) {
  15257. self.table.rowManager.reRenderInPosition();
  15258. }
  15259. }
  15260. return self.origFuncs.splice.apply(data, arguments);
  15261. }
  15262. });
  15263. };
  15264. ReactiveData.prototype.unwatchData = function () {
  15265. if (this.data !== false) {
  15266. for (var key in this.origFuncs) {
  15267. Object.defineProperty(this.data, key, {
  15268. enumerable: true,
  15269. configurable: true,
  15270. writable: true,
  15271. value: this.origFuncs.key
  15272. });
  15273. }
  15274. }
  15275. };
  15276. ReactiveData.prototype.watchRow = function (row) {
  15277. var self = this,
  15278. data = row.getData();
  15279. this.blocked = true;
  15280. for (var key in data) {
  15281. this.watchKey(row, data, key);
  15282. }
  15283. this.blocked = false;
  15284. };
  15285. ReactiveData.prototype.watchKey = function (row, data, key) {
  15286. var self = this,
  15287. props = Object.getOwnPropertyDescriptor(data, key),
  15288. value = data[key],
  15289. version = this.currentVersion;
  15290. Object.defineProperty(data, key, {
  15291. set: function set(newValue) {
  15292. value = newValue;
  15293. if (!self.blocked && version === self.currentVersion) {
  15294. var update = {};
  15295. update[key] = newValue;
  15296. row.updateData(update);
  15297. }
  15298. if (props.set) {
  15299. props.set(newValue);
  15300. }
  15301. },
  15302. get: function get() {
  15303. if (props.get) {
  15304. props.get();
  15305. }
  15306. return value;
  15307. }
  15308. });
  15309. };
  15310. ReactiveData.prototype.unwatchRow = function (row) {
  15311. var data = row.getData();
  15312. for (var key in data) {
  15313. Object.defineProperty(data, key, {
  15314. value: data[key]
  15315. });
  15316. }
  15317. };
  15318. ReactiveData.prototype.block = function () {
  15319. this.blocked = true;
  15320. };
  15321. ReactiveData.prototype.unblock = function () {
  15322. this.blocked = false;
  15323. };
  15324. Tabulator.prototype.registerModule("reactiveData", ReactiveData);
  15325. var ResizeColumns = function ResizeColumns(table) {
  15326. this.table = table; //hold Tabulator object
  15327. this.startColumn = false;
  15328. this.startX = false;
  15329. this.startWidth = false;
  15330. this.handle = null;
  15331. this.prevHandle = null;
  15332. };
  15333. ResizeColumns.prototype.initializeColumn = function (type, column, element) {
  15334. var self = this,
  15335. variableHeight = false,
  15336. mode = this.table.options.resizableColumns;
  15337. //set column resize mode
  15338. if (type === "header") {
  15339. variableHeight = column.definition.formatter == "textarea" || column.definition.variableHeight;
  15340. column.modules.resize = { variableHeight: variableHeight };
  15341. }
  15342. if (mode === true || mode == type) {
  15343. var handle = document.createElement('div');
  15344. handle.className = "tabulator-col-resize-handle";
  15345. var prevHandle = document.createElement('div');
  15346. prevHandle.className = "tabulator-col-resize-handle prev";
  15347. handle.addEventListener("click", function (e) {
  15348. e.stopPropagation();
  15349. });
  15350. var handleDown = function handleDown(e) {
  15351. var nearestColumn = column.getLastColumn();
  15352. if (nearestColumn && self._checkResizability(nearestColumn)) {
  15353. self.startColumn = column;
  15354. self._mouseDown(e, nearestColumn, handle);
  15355. }
  15356. };
  15357. handle.addEventListener("mousedown", handleDown);
  15358. handle.addEventListener("touchstart", handleDown, { passive: true });
  15359. //reszie column on double click
  15360. handle.addEventListener("dblclick", function (e) {
  15361. var col = column.getLastColumn();
  15362. if (col && self._checkResizability(col)) {
  15363. e.stopPropagation();
  15364. col.reinitializeWidth(true);
  15365. }
  15366. });
  15367. prevHandle.addEventListener("click", function (e) {
  15368. e.stopPropagation();
  15369. });
  15370. var prevHandleDown = function prevHandleDown(e) {
  15371. var nearestColumn, colIndex, prevColumn;
  15372. nearestColumn = column.getFirstColumn();
  15373. if (nearestColumn) {
  15374. colIndex = self.table.columnManager.findColumnIndex(nearestColumn);
  15375. prevColumn = colIndex > 0 ? self.table.columnManager.getColumnByIndex(colIndex - 1) : false;
  15376. if (prevColumn && self._checkResizability(prevColumn)) {
  15377. self.startColumn = column;
  15378. self._mouseDown(e, prevColumn, prevHandle);
  15379. }
  15380. }
  15381. };
  15382. prevHandle.addEventListener("mousedown", prevHandleDown);
  15383. prevHandle.addEventListener("touchstart", prevHandleDown, { passive: true });
  15384. //resize column on double click
  15385. prevHandle.addEventListener("dblclick", function (e) {
  15386. var nearestColumn, colIndex, prevColumn;
  15387. nearestColumn = column.getFirstColumn();
  15388. if (nearestColumn) {
  15389. colIndex = self.table.columnManager.findColumnIndex(nearestColumn);
  15390. prevColumn = colIndex > 0 ? self.table.columnManager.getColumnByIndex(colIndex - 1) : false;
  15391. if (prevColumn && self._checkResizability(prevColumn)) {
  15392. e.stopPropagation();
  15393. prevColumn.reinitializeWidth(true);
  15394. }
  15395. }
  15396. });
  15397. element.appendChild(handle);
  15398. element.appendChild(prevHandle);
  15399. }
  15400. };
  15401. ResizeColumns.prototype._checkResizability = function (column) {
  15402. return typeof column.definition.resizable != "undefined" ? column.definition.resizable : this.table.options.resizableColumns;
  15403. };
  15404. ResizeColumns.prototype._mouseDown = function (e, column, handle) {
  15405. var self = this;
  15406. self.table.element.classList.add("tabulator-block-select");
  15407. function mouseMove(e) {
  15408. // self.table.columnManager.tempScrollBlock();
  15409. column.setWidth(self.startWidth + ((typeof e.screenX === "undefined" ? e.touches[0].screenX : e.screenX) - self.startX));
  15410. if (!self.table.browserSlow && column.modules.resize && column.modules.resize.variableHeight) {
  15411. column.checkCellHeights();
  15412. }
  15413. }
  15414. function mouseUp(e) {
  15415. //block editor from taking action while resizing is taking place
  15416. if (self.startColumn.modules.edit) {
  15417. self.startColumn.modules.edit.blocked = false;
  15418. }
  15419. if (self.table.browserSlow && column.modules.resize && column.modules.resize.variableHeight) {
  15420. column.checkCellHeights();
  15421. }
  15422. document.body.removeEventListener("mouseup", mouseUp);
  15423. document.body.removeEventListener("mousemove", mouseMove);
  15424. handle.removeEventListener("touchmove", mouseMove);
  15425. handle.removeEventListener("touchend", mouseUp);
  15426. self.table.element.classList.remove("tabulator-block-select");
  15427. if (self.table.options.persistence && self.table.modExists("persistence", true) && self.table.modules.persistence.config.columns) {
  15428. self.table.modules.persistence.save("columns");
  15429. }
  15430. self.table.options.columnResized.call(self.table, column.getComponent());
  15431. }
  15432. e.stopPropagation(); //prevent resize from interfereing with movable columns
  15433. //block editor from taking action while resizing is taking place
  15434. if (self.startColumn.modules.edit) {
  15435. self.startColumn.modules.edit.blocked = true;
  15436. }
  15437. self.startX = typeof e.screenX === "undefined" ? e.touches[0].screenX : e.screenX;
  15438. self.startWidth = column.getWidth();
  15439. document.body.addEventListener("mousemove", mouseMove);
  15440. document.body.addEventListener("mouseup", mouseUp);
  15441. handle.addEventListener("touchmove", mouseMove, { passive: true });
  15442. handle.addEventListener("touchend", mouseUp);
  15443. };
  15444. Tabulator.prototype.registerModule("resizeColumns", ResizeColumns);
  15445. var ResizeRows = function ResizeRows(table) {
  15446. this.table = table; //hold Tabulator object
  15447. this.startColumn = false;
  15448. this.startY = false;
  15449. this.startHeight = false;
  15450. this.handle = null;
  15451. this.prevHandle = null;
  15452. };
  15453. ResizeRows.prototype.initializeRow = function (row) {
  15454. var self = this,
  15455. rowEl = row.getElement();
  15456. var handle = document.createElement('div');
  15457. handle.className = "tabulator-row-resize-handle";
  15458. var prevHandle = document.createElement('div');
  15459. prevHandle.className = "tabulator-row-resize-handle prev";
  15460. handle.addEventListener("click", function (e) {
  15461. e.stopPropagation();
  15462. });
  15463. var handleDown = function handleDown(e) {
  15464. self.startRow = row;
  15465. self._mouseDown(e, row, handle);
  15466. };
  15467. handle.addEventListener("mousedown", handleDown);
  15468. handle.addEventListener("touchstart", handleDown, { passive: true });
  15469. prevHandle.addEventListener("click", function (e) {
  15470. e.stopPropagation();
  15471. });
  15472. var prevHandleDown = function prevHandleDown(e) {
  15473. var prevRow = self.table.rowManager.prevDisplayRow(row);
  15474. if (prevRow) {
  15475. self.startRow = prevRow;
  15476. self._mouseDown(e, prevRow, prevHandle);
  15477. }
  15478. };
  15479. prevHandle.addEventListener("mousedown", prevHandleDown);
  15480. prevHandle.addEventListener("touchstart", prevHandleDown, { passive: true });
  15481. rowEl.appendChild(handle);
  15482. rowEl.appendChild(prevHandle);
  15483. };
  15484. ResizeRows.prototype._mouseDown = function (e, row, handle) {
  15485. var self = this;
  15486. self.table.element.classList.add("tabulator-block-select");
  15487. function mouseMove(e) {
  15488. row.setHeight(self.startHeight + ((typeof e.screenY === "undefined" ? e.touches[0].screenY : e.screenY) - self.startY));
  15489. }
  15490. function mouseUp(e) {
  15491. // //block editor from taking action while resizing is taking place
  15492. // if(self.startColumn.modules.edit){
  15493. // self.startColumn.modules.edit.blocked = false;
  15494. // }
  15495. document.body.removeEventListener("mouseup", mouseMove);
  15496. document.body.removeEventListener("mousemove", mouseMove);
  15497. handle.removeEventListener("touchmove", mouseMove);
  15498. handle.removeEventListener("touchend", mouseUp);
  15499. self.table.element.classList.remove("tabulator-block-select");
  15500. self.table.options.rowResized.call(this.table, row.getComponent());
  15501. }
  15502. e.stopPropagation(); //prevent resize from interfereing with movable columns
  15503. //block editor from taking action while resizing is taking place
  15504. // if(self.startColumn.modules.edit){
  15505. // self.startColumn.modules.edit.blocked = true;
  15506. // }
  15507. self.startY = typeof e.screenY === "undefined" ? e.touches[0].screenY : e.screenY;
  15508. self.startHeight = row.getHeight();
  15509. document.body.addEventListener("mousemove", mouseMove);
  15510. document.body.addEventListener("mouseup", mouseUp);
  15511. handle.addEventListener("touchmove", mouseMove, { passive: true });
  15512. handle.addEventListener("touchend", mouseUp);
  15513. };
  15514. Tabulator.prototype.registerModule("resizeRows", ResizeRows);
  15515. var ResizeTable = function ResizeTable(table) {
  15516. this.table = table; //hold Tabulator object
  15517. this.binding = false;
  15518. this.observer = false;
  15519. this.containerObserver = false;
  15520. this.tableHeight = 0;
  15521. this.tableWidth = 0;
  15522. this.containerHeight = 0;
  15523. this.containerWidth = 0;
  15524. this.autoResize = false;
  15525. };
  15526. ResizeTable.prototype.initialize = function (row) {
  15527. var _this70 = this;
  15528. var table = this.table,
  15529. tableStyle;
  15530. this.tableHeight = table.element.clientHeight;
  15531. this.tableWidth = table.element.clientWidth;
  15532. if (table.element.parentNode) {
  15533. this.containerHeight = table.element.parentNode.clientHeight;
  15534. this.containerWidth = table.element.parentNode.clientWidth;
  15535. }
  15536. if (typeof ResizeObserver !== "undefined" && table.rowManager.getRenderMode() === "virtual") {
  15537. this.autoResize = true;
  15538. this.observer = new ResizeObserver(function (entry) {
  15539. if (!table.browserMobile || table.browserMobile && !table.modules.edit.currentCell) {
  15540. var nodeHeight = Math.floor(entry[0].contentRect.height);
  15541. var nodeWidth = Math.floor(entry[0].contentRect.width);
  15542. if (_this70.tableHeight != nodeHeight || _this70.tableWidth != nodeWidth) {
  15543. _this70.tableHeight = nodeHeight;
  15544. _this70.tableWidth = nodeWidth;
  15545. if (table.element.parentNode) {
  15546. _this70.containerHeight = table.element.parentNode.clientHeight;
  15547. _this70.containerWidth = table.element.parentNode.clientWidth;
  15548. }
  15549. table.redraw();
  15550. }
  15551. }
  15552. });
  15553. this.observer.observe(table.element);
  15554. tableStyle = window.getComputedStyle(table.element);
  15555. if (this.table.element.parentNode && !this.table.rowManager.fixedHeight && (tableStyle.getPropertyValue("max-height") || tableStyle.getPropertyValue("min-height"))) {
  15556. this.containerObserver = new ResizeObserver(function (entry) {
  15557. if (!table.browserMobile || table.browserMobile && !table.modules.edit.currentCell) {
  15558. var nodeHeight = Math.floor(entry[0].contentRect.height);
  15559. var nodeWidth = Math.floor(entry[0].contentRect.width);
  15560. if (_this70.containerHeight != nodeHeight || _this70.containerWidth != nodeWidth) {
  15561. _this70.containerHeight = nodeHeight;
  15562. _this70.containerWidth = nodeWidth;
  15563. _this70.tableHeight = table.element.clientHeight;
  15564. _this70.tableWidth = table.element.clientWidth;
  15565. table.redraw();
  15566. }
  15567. table.redraw();
  15568. }
  15569. });
  15570. this.containerObserver.observe(this.table.element.parentNode);
  15571. }
  15572. } else {
  15573. this.binding = function () {
  15574. if (!table.browserMobile || table.browserMobile && !table.modules.edit.currentCell) {
  15575. table.redraw();
  15576. }
  15577. };
  15578. window.addEventListener("resize", this.binding);
  15579. }
  15580. };
  15581. ResizeTable.prototype.clearBindings = function (row) {
  15582. if (this.binding) {
  15583. window.removeEventListener("resize", this.binding);
  15584. }
  15585. if (this.observer) {
  15586. this.observer.unobserve(this.table.element);
  15587. }
  15588. if (this.containerObserver) {
  15589. this.containerObserver.unobserve(this.table.element.parentNode);
  15590. }
  15591. };
  15592. Tabulator.prototype.registerModule("resizeTable", ResizeTable);
  15593. var ResponsiveLayout = function ResponsiveLayout(table) {
  15594. this.table = table; //hold Tabulator object
  15595. this.columns = [];
  15596. this.hiddenColumns = [];
  15597. this.mode = "";
  15598. this.index = 0;
  15599. this.collapseFormatter = [];
  15600. this.collapseStartOpen = true;
  15601. this.collapseHandleColumn = false;
  15602. };
  15603. //generate resposive columns list
  15604. ResponsiveLayout.prototype.initialize = function () {
  15605. var self = this,
  15606. columns = [];
  15607. this.mode = this.table.options.responsiveLayout;
  15608. this.collapseFormatter = this.table.options.responsiveLayoutCollapseFormatter || this.formatCollapsedData;
  15609. this.collapseStartOpen = this.table.options.responsiveLayoutCollapseStartOpen;
  15610. this.hiddenColumns = [];
  15611. //detemine level of responsivity for each column
  15612. this.table.columnManager.columnsByIndex.forEach(function (column, i) {
  15613. if (column.modules.responsive) {
  15614. if (column.modules.responsive.order && column.modules.responsive.visible) {
  15615. column.modules.responsive.index = i;
  15616. columns.push(column);
  15617. if (!column.visible && self.mode === "collapse") {
  15618. self.hiddenColumns.push(column);
  15619. }
  15620. }
  15621. }
  15622. });
  15623. //sort list by responsivity
  15624. columns = columns.reverse();
  15625. columns = columns.sort(function (a, b) {
  15626. var diff = b.modules.responsive.order - a.modules.responsive.order;
  15627. return diff || b.modules.responsive.index - a.modules.responsive.index;
  15628. });
  15629. this.columns = columns;
  15630. if (this.mode === "collapse") {
  15631. this.generateCollapsedContent();
  15632. }
  15633. //assign collapse column
  15634. for (var _iterator = this.table.columnManager.columnsByIndex, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
  15635. var _ref;
  15636. if (_isArray) {
  15637. if (_i >= _iterator.length) break;
  15638. _ref = _iterator[_i++];
  15639. } else {
  15640. _i = _iterator.next();
  15641. if (_i.done) break;
  15642. _ref = _i.value;
  15643. }
  15644. var col = _ref;
  15645. if (col.definition.formatter == "responsiveCollapse") {
  15646. this.collapseHandleColumn = col;
  15647. break;
  15648. }
  15649. }
  15650. if (this.collapseHandleColumn) {
  15651. if (this.hiddenColumns.length) {
  15652. this.collapseHandleColumn.show();
  15653. } else {
  15654. this.collapseHandleColumn.hide();
  15655. }
  15656. }
  15657. };
  15658. //define layout information
  15659. ResponsiveLayout.prototype.initializeColumn = function (column) {
  15660. var def = column.getDefinition();
  15661. column.modules.responsive = { order: typeof def.responsive === "undefined" ? 1 : def.responsive, visible: def.visible === false ? false : true };
  15662. };
  15663. ResponsiveLayout.prototype.initializeRow = function (row) {
  15664. var el;
  15665. if (row.type !== "calc") {
  15666. el = document.createElement("div");
  15667. el.classList.add("tabulator-responsive-collapse");
  15668. row.modules.responsiveLayout = {
  15669. element: el,
  15670. open: this.collapseStartOpen
  15671. };
  15672. if (!this.collapseStartOpen) {
  15673. el.style.display = 'none';
  15674. }
  15675. }
  15676. };
  15677. ResponsiveLayout.prototype.layoutRow = function (row) {
  15678. var rowEl = row.getElement();
  15679. if (row.modules.responsiveLayout) {
  15680. rowEl.appendChild(row.modules.responsiveLayout.element);
  15681. this.generateCollapsedRowContent(row);
  15682. }
  15683. };
  15684. //update column visibility
  15685. ResponsiveLayout.prototype.updateColumnVisibility = function (column, visible) {
  15686. var index;
  15687. if (column.modules.responsive) {
  15688. column.modules.responsive.visible = visible;
  15689. this.initialize();
  15690. }
  15691. };
  15692. ResponsiveLayout.prototype.hideColumn = function (column) {
  15693. var colCount = this.hiddenColumns.length;
  15694. column.hide(false, true);
  15695. if (this.mode === "collapse") {
  15696. this.hiddenColumns.unshift(column);
  15697. this.generateCollapsedContent();
  15698. if (this.collapseHandleColumn && !colCount) {
  15699. this.collapseHandleColumn.show();
  15700. }
  15701. }
  15702. };
  15703. ResponsiveLayout.prototype.showColumn = function (column) {
  15704. var index;
  15705. column.show(false, true);
  15706. //set column width to prevent calculation loops on uninitialized columns
  15707. column.setWidth(column.getWidth());
  15708. if (this.mode === "collapse") {
  15709. index = this.hiddenColumns.indexOf(column);
  15710. if (index > -1) {
  15711. this.hiddenColumns.splice(index, 1);
  15712. }
  15713. this.generateCollapsedContent();
  15714. if (this.collapseHandleColumn && !this.hiddenColumns.length) {
  15715. this.collapseHandleColumn.hide();
  15716. }
  15717. }
  15718. };
  15719. //redraw columns to fit space
  15720. ResponsiveLayout.prototype.update = function () {
  15721. var self = this,
  15722. working = true;
  15723. while (working) {
  15724. var width = self.table.modules.layout.getMode() == "fitColumns" ? self.table.columnManager.getFlexBaseWidth() : self.table.columnManager.getWidth();
  15725. var diff = (self.table.options.headerVisible ? self.table.columnManager.element.clientWidth : self.table.element.clientWidth) - width;
  15726. if (diff < 0) {
  15727. //table is too wide
  15728. var column = self.columns[self.index];
  15729. if (column) {
  15730. self.hideColumn(column);
  15731. self.index++;
  15732. } else {
  15733. working = false;
  15734. }
  15735. } else {
  15736. //table has spare space
  15737. var _column = self.columns[self.index - 1];
  15738. if (_column) {
  15739. if (diff > 0) {
  15740. if (diff >= _column.getWidth()) {
  15741. self.showColumn(_column);
  15742. self.index--;
  15743. } else {
  15744. working = false;
  15745. }
  15746. } else {
  15747. working = false;
  15748. }
  15749. } else {
  15750. working = false;
  15751. }
  15752. }
  15753. if (!self.table.rowManager.activeRowsCount) {
  15754. self.table.rowManager.renderEmptyScroll();
  15755. }
  15756. }
  15757. };
  15758. ResponsiveLayout.prototype.generateCollapsedContent = function () {
  15759. var self = this,
  15760. rows = this.table.rowManager.getDisplayRows();
  15761. rows.forEach(function (row) {
  15762. self.generateCollapsedRowContent(row);
  15763. });
  15764. };
  15765. ResponsiveLayout.prototype.generateCollapsedRowContent = function (row) {
  15766. var el, contents;
  15767. if (row.modules.responsiveLayout) {
  15768. el = row.modules.responsiveLayout.element;
  15769. while (el.firstChild) {
  15770. el.removeChild(el.firstChild);
  15771. }contents = this.collapseFormatter(this.generateCollapsedRowData(row));
  15772. if (contents) {
  15773. el.appendChild(contents);
  15774. }
  15775. }
  15776. };
  15777. ResponsiveLayout.prototype.generateCollapsedRowData = function (row) {
  15778. var self = this,
  15779. data = row.getData(),
  15780. output = [],
  15781. mockCellComponent;
  15782. this.hiddenColumns.forEach(function (column) {
  15783. var value = column.getFieldValue(data);
  15784. if (column.definition.title && column.field) {
  15785. if (column.modules.format && self.table.options.responsiveLayoutCollapseUseFormatters) {
  15786. mockCellComponent = {
  15787. value: false,
  15788. data: {},
  15789. getValue: function getValue() {
  15790. return value;
  15791. },
  15792. getData: function getData() {
  15793. return data;
  15794. },
  15795. getElement: function getElement() {
  15796. return document.createElement("div");
  15797. },
  15798. getRow: function getRow() {
  15799. return row.getComponent();
  15800. },
  15801. getColumn: function getColumn() {
  15802. return column.getComponent();
  15803. }
  15804. };
  15805. output.push({
  15806. title: column.definition.title,
  15807. value: column.modules.format.formatter.call(self.table.modules.format, mockCellComponent, column.modules.format.params)
  15808. });
  15809. } else {
  15810. output.push({
  15811. title: column.definition.title,
  15812. value: value
  15813. });
  15814. }
  15815. }
  15816. });
  15817. return output;
  15818. };
  15819. ResponsiveLayout.prototype.formatCollapsedData = function (data) {
  15820. var list = document.createElement("table"),
  15821. listContents = "";
  15822. data.forEach(function (item) {
  15823. var div = document.createElement("div");
  15824. if (item.value instanceof Node) {
  15825. div.appendChild(item.value);
  15826. item.value = div.innerHTML;
  15827. }
  15828. listContents += "<tr><td><strong>" + item.title + "</strong></td><td>" + item.value + "</td></tr>";
  15829. });
  15830. list.innerHTML = listContents;
  15831. return Object.keys(data).length ? list : "";
  15832. };
  15833. Tabulator.prototype.registerModule("responsiveLayout", ResponsiveLayout);
  15834. var SelectRow = function SelectRow(table) {
  15835. this.table = table; //hold Tabulator object
  15836. this.selecting = false; //flag selecting in progress
  15837. this.lastClickedRow = false; //last clicked row
  15838. this.selectPrev = []; //hold previously selected element for drag drop selection
  15839. this.selectedRows = []; //hold selected rows
  15840. this.headerCheckboxElement = null; // hold header select element
  15841. };
  15842. SelectRow.prototype.clearSelectionData = function (silent) {
  15843. this.selecting = false;
  15844. this.lastClickedRow = false;
  15845. this.selectPrev = [];
  15846. this.selectedRows = [];
  15847. if (!silent) {
  15848. this._rowSelectionChanged();
  15849. }
  15850. };
  15851. SelectRow.prototype.initializeRow = function (row) {
  15852. var self = this,
  15853. element = row.getElement();
  15854. // trigger end of row selection
  15855. var endSelect = function endSelect() {
  15856. setTimeout(function () {
  15857. self.selecting = false;
  15858. }, 50);
  15859. document.body.removeEventListener("mouseup", endSelect);
  15860. };
  15861. row.modules.select = { selected: false };
  15862. //set row selection class
  15863. if (self.table.options.selectableCheck.call(this.table, row.getComponent())) {
  15864. element.classList.add("tabulator-selectable");
  15865. element.classList.remove("tabulator-unselectable");
  15866. if (self.table.options.selectable && self.table.options.selectable != "highlight") {
  15867. if (self.table.options.selectableRangeMode === "click") {
  15868. element.addEventListener("click", function (e) {
  15869. if (e.shiftKey) {
  15870. self.table._clearSelection();
  15871. self.lastClickedRow = self.lastClickedRow || row;
  15872. var lastClickedRowIdx = self.table.rowManager.getDisplayRowIndex(self.lastClickedRow);
  15873. var rowIdx = self.table.rowManager.getDisplayRowIndex(row);
  15874. var fromRowIdx = lastClickedRowIdx <= rowIdx ? lastClickedRowIdx : rowIdx;
  15875. var toRowIdx = lastClickedRowIdx >= rowIdx ? lastClickedRowIdx : rowIdx;
  15876. var rows = self.table.rowManager.getDisplayRows().slice(0);
  15877. var toggledRows = rows.splice(fromRowIdx, toRowIdx - fromRowIdx + 1);
  15878. if (e.ctrlKey || e.metaKey) {
  15879. toggledRows.forEach(function (toggledRow) {
  15880. if (toggledRow !== self.lastClickedRow) {
  15881. if (self.table.options.selectable !== true && !self.isRowSelected(row)) {
  15882. if (self.selectedRows.length < self.table.options.selectable) {
  15883. self.toggleRow(toggledRow);
  15884. }
  15885. } else {
  15886. self.toggleRow(toggledRow);
  15887. }
  15888. }
  15889. });
  15890. self.lastClickedRow = row;
  15891. } else {
  15892. self.deselectRows(undefined, true);
  15893. if (self.table.options.selectable !== true) {
  15894. if (toggledRows.length > self.table.options.selectable) {
  15895. toggledRows = toggledRows.slice(0, self.table.options.selectable);
  15896. }
  15897. }
  15898. self.selectRows(toggledRows);
  15899. }
  15900. self.table._clearSelection();
  15901. } else if (e.ctrlKey || e.metaKey) {
  15902. self.toggleRow(row);
  15903. self.lastClickedRow = row;
  15904. } else {
  15905. self.deselectRows(undefined, true);
  15906. self.selectRows(row);
  15907. self.lastClickedRow = row;
  15908. }
  15909. });
  15910. } else {
  15911. element.addEventListener("click", function (e) {
  15912. if (!self.table.modExists("edit") || !self.table.modules.edit.getCurrentCell()) {
  15913. self.table._clearSelection();
  15914. }
  15915. if (!self.selecting) {
  15916. self.toggleRow(row);
  15917. }
  15918. });
  15919. element.addEventListener("mousedown", function (e) {
  15920. if (e.shiftKey) {
  15921. self.table._clearSelection();
  15922. self.selecting = true;
  15923. self.selectPrev = [];
  15924. document.body.addEventListener("mouseup", endSelect);
  15925. document.body.addEventListener("keyup", endSelect);
  15926. self.toggleRow(row);
  15927. return false;
  15928. }
  15929. });
  15930. element.addEventListener("mouseenter", function (e) {
  15931. if (self.selecting) {
  15932. self.table._clearSelection();
  15933. self.toggleRow(row);
  15934. if (self.selectPrev[1] == row) {
  15935. self.toggleRow(self.selectPrev[0]);
  15936. }
  15937. }
  15938. });
  15939. element.addEventListener("mouseout", function (e) {
  15940. if (self.selecting) {
  15941. self.table._clearSelection();
  15942. self.selectPrev.unshift(row);
  15943. }
  15944. });
  15945. }
  15946. }
  15947. } else {
  15948. element.classList.add("tabulator-unselectable");
  15949. element.classList.remove("tabulator-selectable");
  15950. }
  15951. };
  15952. //toggle row selection
  15953. SelectRow.prototype.toggleRow = function (row) {
  15954. if (this.table.options.selectableCheck.call(this.table, row.getComponent())) {
  15955. if (row.modules.select && row.modules.select.selected) {
  15956. this._deselectRow(row);
  15957. } else {
  15958. this._selectRow(row);
  15959. }
  15960. }
  15961. };
  15962. //select a number of rows
  15963. SelectRow.prototype.selectRows = function (rows) {
  15964. var _this71 = this;
  15965. var rowMatch;
  15966. switch (typeof rows === 'undefined' ? 'undefined' : _typeof(rows)) {
  15967. case "undefined":
  15968. this.table.rowManager.rows.forEach(function (row) {
  15969. _this71._selectRow(row, true, true);
  15970. });
  15971. this._rowSelectionChanged();
  15972. break;
  15973. case "string":
  15974. rowMatch = this.table.rowManager.findRow(rows);
  15975. if (rowMatch) {
  15976. this._selectRow(rowMatch, true, true);
  15977. } else {
  15978. this.table.rowManager.getRows(rows).forEach(function (row) {
  15979. _this71._selectRow(row, true, true);
  15980. });
  15981. }
  15982. this._rowSelectionChanged();
  15983. break;
  15984. default:
  15985. if (Array.isArray(rows)) {
  15986. rows.forEach(function (row) {
  15987. _this71._selectRow(row, true, true);
  15988. });
  15989. this._rowSelectionChanged();
  15990. } else {
  15991. this._selectRow(rows, false, true);
  15992. }
  15993. break;
  15994. }
  15995. };
  15996. //select an individual row
  15997. SelectRow.prototype._selectRow = function (rowInfo, silent, force) {
  15998. var index;
  15999. //handle max row count
  16000. if (!isNaN(this.table.options.selectable) && this.table.options.selectable !== true && !force) {
  16001. if (this.selectedRows.length >= this.table.options.selectable) {
  16002. if (this.table.options.selectableRollingSelection) {
  16003. this._deselectRow(this.selectedRows[0]);
  16004. } else {
  16005. return false;
  16006. }
  16007. }
  16008. }
  16009. var row = this.table.rowManager.findRow(rowInfo);
  16010. if (row) {
  16011. if (this.selectedRows.indexOf(row) == -1) {
  16012. if (!row.modules.select) {
  16013. row.modules.select = {};
  16014. }
  16015. row.modules.select.selected = true;
  16016. if (row.modules.select.checkboxEl) {
  16017. row.modules.select.checkboxEl.checked = true;
  16018. }
  16019. row.getElement().classList.add("tabulator-selected");
  16020. this.selectedRows.push(row);
  16021. if (this.table.options.dataTreeSelectPropagate) {
  16022. this.childRowSelection(row, true);
  16023. }
  16024. if (!silent) {
  16025. this.table.options.rowSelected.call(this.table, row.getComponent());
  16026. }
  16027. this._rowSelectionChanged(silent);
  16028. }
  16029. } else {
  16030. if (!silent) {
  16031. console.warn("Selection Error - No such row found, ignoring selection:" + rowInfo);
  16032. }
  16033. }
  16034. };
  16035. SelectRow.prototype.isRowSelected = function (row) {
  16036. return this.selectedRows.indexOf(row) !== -1;
  16037. };
  16038. //deselect a number of rows
  16039. SelectRow.prototype.deselectRows = function (rows, silent) {
  16040. var self = this,
  16041. rowCount;
  16042. if (typeof rows == "undefined") {
  16043. rowCount = self.selectedRows.length;
  16044. for (var i = 0; i < rowCount; i++) {
  16045. self._deselectRow(self.selectedRows[0], true);
  16046. }
  16047. self._rowSelectionChanged(silent);
  16048. } else {
  16049. if (Array.isArray(rows)) {
  16050. rows.forEach(function (row) {
  16051. self._deselectRow(row, true);
  16052. });
  16053. self._rowSelectionChanged(silent);
  16054. } else {
  16055. self._deselectRow(rows, silent);
  16056. }
  16057. }
  16058. };
  16059. //deselect an individual row
  16060. SelectRow.prototype._deselectRow = function (rowInfo, silent) {
  16061. var self = this,
  16062. row = self.table.rowManager.findRow(rowInfo),
  16063. index;
  16064. if (row) {
  16065. index = self.selectedRows.findIndex(function (selectedRow) {
  16066. return selectedRow == row;
  16067. });
  16068. if (index > -1) {
  16069. if (!row.modules.select) {
  16070. row.modules.select = {};
  16071. }
  16072. row.modules.select.selected = false;
  16073. if (row.modules.select.checkboxEl) {
  16074. row.modules.select.checkboxEl.checked = false;
  16075. }
  16076. row.getElement().classList.remove("tabulator-selected");
  16077. self.selectedRows.splice(index, 1);
  16078. if (this.table.options.dataTreeSelectPropagate) {
  16079. this.childRowSelection(row, false);
  16080. }
  16081. if (!silent) {
  16082. self.table.options.rowDeselected.call(this.table, row.getComponent());
  16083. }
  16084. self._rowSelectionChanged(silent);
  16085. }
  16086. } else {
  16087. if (!silent) {
  16088. console.warn("Deselection Error - No such row found, ignoring selection:" + rowInfo);
  16089. }
  16090. }
  16091. };
  16092. SelectRow.prototype.getSelectedData = function () {
  16093. var data = [];
  16094. this.selectedRows.forEach(function (row) {
  16095. data.push(row.getData());
  16096. });
  16097. return data;
  16098. };
  16099. SelectRow.prototype.getSelectedRows = function () {
  16100. var rows = [];
  16101. this.selectedRows.forEach(function (row) {
  16102. rows.push(row.getComponent());
  16103. });
  16104. return rows;
  16105. };
  16106. SelectRow.prototype._rowSelectionChanged = function (silent) {
  16107. if (this.headerCheckboxElement) {
  16108. if (this.selectedRows.length === 0) {
  16109. this.headerCheckboxElement.checked = false;
  16110. this.headerCheckboxElement.indeterminate = false;
  16111. } else if (this.table.rowManager.rows.length === this.selectedRows.length) {
  16112. this.headerCheckboxElement.checked = true;
  16113. this.headerCheckboxElement.indeterminate = false;
  16114. } else {
  16115. this.headerCheckboxElement.indeterminate = true;
  16116. this.headerCheckboxElement.checked = false;
  16117. }
  16118. }
  16119. if (!silent) {
  16120. this.table.options.rowSelectionChanged.call(this.table, this.getSelectedData(), this.getSelectedRows());
  16121. }
  16122. };
  16123. SelectRow.prototype.registerRowSelectCheckbox = function (row, element) {
  16124. if (!row._row.modules.select) {
  16125. row._row.modules.select = {};
  16126. }
  16127. row._row.modules.select.checkboxEl = element;
  16128. };
  16129. SelectRow.prototype.registerHeaderSelectCheckbox = function (element) {
  16130. this.headerCheckboxElement = element;
  16131. };
  16132. SelectRow.prototype.childRowSelection = function (row, select) {
  16133. var children = this.table.modules.dataTree.getChildren(row);
  16134. if (select) {
  16135. for (var _iterator2 = children, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
  16136. var _ref2;
  16137. if (_isArray2) {
  16138. if (_i2 >= _iterator2.length) break;
  16139. _ref2 = _iterator2[_i2++];
  16140. } else {
  16141. _i2 = _iterator2.next();
  16142. if (_i2.done) break;
  16143. _ref2 = _i2.value;
  16144. }
  16145. var child = _ref2;
  16146. this._selectRow(child, true);
  16147. }
  16148. } else {
  16149. for (var _iterator3 = children, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
  16150. var _ref3;
  16151. if (_isArray3) {
  16152. if (_i3 >= _iterator3.length) break;
  16153. _ref3 = _iterator3[_i3++];
  16154. } else {
  16155. _i3 = _iterator3.next();
  16156. if (_i3.done) break;
  16157. _ref3 = _i3.value;
  16158. }
  16159. var _child = _ref3;
  16160. this._deselectRow(_child, true);
  16161. }
  16162. }
  16163. };
  16164. Tabulator.prototype.registerModule("selectRow", SelectRow);
  16165. var Sort = function Sort(table) {
  16166. this.table = table; //hold Tabulator object
  16167. this.sortList = []; //holder current sort
  16168. this.changed = false; //has the sort changed since last render
  16169. };
  16170. //initialize column header for sorting
  16171. Sort.prototype.initializeColumn = function (column, content) {
  16172. var self = this,
  16173. sorter = false,
  16174. colEl,
  16175. arrowEl;
  16176. switch (_typeof(column.definition.sorter)) {
  16177. case "string":
  16178. if (self.sorters[column.definition.sorter]) {
  16179. sorter = self.sorters[column.definition.sorter];
  16180. } else {
  16181. console.warn("Sort Error - No such sorter found: ", column.definition.sorter);
  16182. }
  16183. break;
  16184. case "function":
  16185. sorter = column.definition.sorter;
  16186. break;
  16187. }
  16188. column.modules.sort = {
  16189. sorter: sorter, dir: "none",
  16190. params: column.definition.sorterParams || {},
  16191. startingDir: column.definition.headerSortStartingDir || "asc",
  16192. tristate: typeof column.definition.headerSortTristate !== "undefined" ? column.definition.headerSortTristate : this.table.options.headerSortTristate
  16193. };
  16194. if (typeof column.definition.headerSort === "undefined" ? this.table.options.headerSort !== false : column.definition.headerSort !== false) {
  16195. colEl = column.getElement();
  16196. colEl.classList.add("tabulator-sortable");
  16197. arrowEl = document.createElement("div");
  16198. arrowEl.classList.add("tabulator-arrow");
  16199. //create sorter arrow
  16200. content.appendChild(arrowEl);
  16201. //sort on click
  16202. colEl.addEventListener("click", function (e) {
  16203. var dir = "",
  16204. sorters = [],
  16205. match = false;
  16206. if (column.modules.sort) {
  16207. if (column.modules.sort.tristate) {
  16208. if (column.modules.sort.dir == "none") {
  16209. dir = column.modules.sort.startingDir;
  16210. } else {
  16211. if (column.modules.sort.dir == column.modules.sort.startingDir) {
  16212. dir = column.modules.sort.dir == "asc" ? "desc" : "asc";
  16213. } else {
  16214. dir = "none";
  16215. }
  16216. }
  16217. } else {
  16218. switch (column.modules.sort.dir) {
  16219. case "asc":
  16220. dir = "desc";
  16221. break;
  16222. case "desc":
  16223. dir = "asc";
  16224. break;
  16225. default:
  16226. dir = column.modules.sort.startingDir;
  16227. }
  16228. }
  16229. if (self.table.options.columnHeaderSortMulti && (e.shiftKey || e.ctrlKey)) {
  16230. sorters = self.getSort();
  16231. match = sorters.findIndex(function (sorter) {
  16232. return sorter.field === column.getField();
  16233. });
  16234. if (match > -1) {
  16235. sorters[match].dir = dir;
  16236. if (match != sorters.length - 1) {
  16237. match = sorters.splice(match, 1)[0];
  16238. if (dir != "none") {
  16239. sorters.push(match);
  16240. }
  16241. }
  16242. } else {
  16243. if (dir != "none") {
  16244. sorters.push({ column: column, dir: dir });
  16245. }
  16246. }
  16247. //add to existing sort
  16248. self.setSort(sorters);
  16249. } else {
  16250. if (dir == "none") {
  16251. self.clear();
  16252. } else {
  16253. //sort by column only
  16254. self.setSort(column, dir);
  16255. }
  16256. }
  16257. self.table.rowManager.sorterRefresh(!self.sortList.length);
  16258. }
  16259. });
  16260. }
  16261. };
  16262. //check if the sorters have changed since last use
  16263. Sort.prototype.hasChanged = function () {
  16264. var changed = this.changed;
  16265. this.changed = false;
  16266. return changed;
  16267. };
  16268. //return current sorters
  16269. Sort.prototype.getSort = function () {
  16270. var self = this,
  16271. sorters = [];
  16272. self.sortList.forEach(function (item) {
  16273. if (item.column) {
  16274. sorters.push({ column: item.column.getComponent(), field: item.column.getField(), dir: item.dir });
  16275. }
  16276. });
  16277. return sorters;
  16278. };
  16279. //change sort list and trigger sort
  16280. Sort.prototype.setSort = function (sortList, dir) {
  16281. var self = this,
  16282. newSortList = [];
  16283. if (!Array.isArray(sortList)) {
  16284. sortList = [{ column: sortList, dir: dir }];
  16285. }
  16286. sortList.forEach(function (item) {
  16287. var column;
  16288. column = self.table.columnManager.findColumn(item.column);
  16289. if (column) {
  16290. item.column = column;
  16291. newSortList.push(item);
  16292. self.changed = true;
  16293. } else {
  16294. console.warn("Sort Warning - Sort field does not exist and is being ignored: ", item.column);
  16295. }
  16296. });
  16297. self.sortList = newSortList;
  16298. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.sort) {
  16299. this.table.modules.persistence.save("sort");
  16300. }
  16301. };
  16302. //clear sorters
  16303. Sort.prototype.clear = function () {
  16304. this.setSort([]);
  16305. };
  16306. //find appropriate sorter for column
  16307. Sort.prototype.findSorter = function (column) {
  16308. var row = this.table.rowManager.activeRows[0],
  16309. sorter = "string",
  16310. field,
  16311. value;
  16312. if (row) {
  16313. row = row.getData();
  16314. field = column.getField();
  16315. if (field) {
  16316. value = column.getFieldValue(row);
  16317. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  16318. case "undefined":
  16319. sorter = "string";
  16320. break;
  16321. case "boolean":
  16322. sorter = "boolean";
  16323. break;
  16324. default:
  16325. if (!isNaN(value) && value !== "") {
  16326. sorter = "number";
  16327. } else {
  16328. if (value.match(/((^[0-9]+[a-z]+)|(^[a-z]+[0-9]+))+$/i)) {
  16329. sorter = "alphanum";
  16330. }
  16331. }
  16332. break;
  16333. }
  16334. }
  16335. }
  16336. return this.sorters[sorter];
  16337. };
  16338. //work through sort list sorting data
  16339. Sort.prototype.sort = function (data) {
  16340. var self = this,
  16341. sortList = this.table.options.sortOrderReverse ? self.sortList.slice().reverse() : self.sortList,
  16342. sortListActual = [],
  16343. lastSort;
  16344. if (self.table.options.dataSorting) {
  16345. self.table.options.dataSorting.call(self.table, self.getSort());
  16346. }
  16347. self.clearColumnHeaders();
  16348. if (!self.table.options.ajaxSorting) {
  16349. //build list of valid sorters and trigger column specific callbacks before sort begins
  16350. sortList.forEach(function (item, i) {
  16351. var sortObj = item.column.modules.sort;
  16352. if (item.column && sortObj) {
  16353. //if no sorter has been defined, take a guess
  16354. if (!sortObj.sorter) {
  16355. sortObj.sorter = self.findSorter(item.column);
  16356. }
  16357. item.params = typeof sortObj.params === "function" ? sortObj.params(item.column.getComponent(), item.dir) : sortObj.params;
  16358. sortListActual.push(item);
  16359. }
  16360. self.setColumnHeader(item.column, item.dir);
  16361. });
  16362. //sort data
  16363. if (sortListActual.length) {
  16364. self._sortItems(data, sortListActual);
  16365. }
  16366. } else {
  16367. sortList.forEach(function (item, i) {
  16368. self.setColumnHeader(item.column, item.dir);
  16369. });
  16370. }
  16371. if (self.table.options.dataSorted) {
  16372. self.table.options.dataSorted.call(self.table, self.getSort(), self.table.rowManager.getComponents("active"));
  16373. }
  16374. };
  16375. //clear sort arrows on columns
  16376. Sort.prototype.clearColumnHeaders = function () {
  16377. this.table.columnManager.getRealColumns().forEach(function (column) {
  16378. if (column.modules.sort) {
  16379. column.modules.sort.dir = "none";
  16380. column.getElement().setAttribute("aria-sort", "none");
  16381. }
  16382. });
  16383. };
  16384. //set the column header sort direction
  16385. Sort.prototype.setColumnHeader = function (column, dir) {
  16386. column.modules.sort.dir = dir;
  16387. column.getElement().setAttribute("aria-sort", dir);
  16388. };
  16389. //sort each item in sort list
  16390. Sort.prototype._sortItems = function (data, sortList) {
  16391. var _this72 = this;
  16392. var sorterCount = sortList.length - 1;
  16393. data.sort(function (a, b) {
  16394. var result;
  16395. for (var i = sorterCount; i >= 0; i--) {
  16396. var sortItem = sortList[i];
  16397. result = _this72._sortRow(a, b, sortItem.column, sortItem.dir, sortItem.params);
  16398. if (result !== 0) {
  16399. break;
  16400. }
  16401. }
  16402. return result;
  16403. });
  16404. };
  16405. //process individual rows for a sort function on active data
  16406. Sort.prototype._sortRow = function (a, b, column, dir, params) {
  16407. var el1Comp, el2Comp, colComp;
  16408. //switch elements depending on search direction
  16409. var el1 = dir == "asc" ? a : b;
  16410. var el2 = dir == "asc" ? b : a;
  16411. a = column.getFieldValue(el1.getData());
  16412. b = column.getFieldValue(el2.getData());
  16413. a = typeof a !== "undefined" ? a : "";
  16414. b = typeof b !== "undefined" ? b : "";
  16415. el1Comp = el1.getComponent();
  16416. el2Comp = el2.getComponent();
  16417. return column.modules.sort.sorter.call(this, a, b, el1Comp, el2Comp, column.getComponent(), dir, params);
  16418. };
  16419. //default data sorters
  16420. Sort.prototype.sorters = {
  16421. //sort numbers
  16422. number: function number(a, b, aRow, bRow, column, dir, params) {
  16423. var alignEmptyValues = params.alignEmptyValues;
  16424. var decimal = params.decimalSeparator || ".";
  16425. var thousand = params.thousandSeparator || ",";
  16426. var emptyAlign = 0;
  16427. a = parseFloat(String(a).split(thousand).join("").split(decimal).join("."));
  16428. b = parseFloat(String(b).split(thousand).join("").split(decimal).join("."));
  16429. //handle non numeric values
  16430. if (isNaN(a)) {
  16431. emptyAlign = isNaN(b) ? 0 : -1;
  16432. } else if (isNaN(b)) {
  16433. emptyAlign = 1;
  16434. } else {
  16435. //compare valid values
  16436. return a - b;
  16437. }
  16438. //fix empty values in position
  16439. if (alignEmptyValues === "top" && dir === "desc" || alignEmptyValues === "bottom" && dir === "asc") {
  16440. emptyAlign *= -1;
  16441. }
  16442. return emptyAlign;
  16443. },
  16444. //sort strings
  16445. string: function string(a, b, aRow, bRow, column, dir, params) {
  16446. var alignEmptyValues = params.alignEmptyValues;
  16447. var emptyAlign = 0;
  16448. var locale;
  16449. //handle empty values
  16450. if (!a) {
  16451. emptyAlign = !b ? 0 : -1;
  16452. } else if (!b) {
  16453. emptyAlign = 1;
  16454. } else {
  16455. //compare valid values
  16456. switch (_typeof(params.locale)) {
  16457. case "boolean":
  16458. if (params.locale) {
  16459. locale = this.table.modules.localize.getLocale();
  16460. }
  16461. break;
  16462. case "string":
  16463. locale = params.locale;
  16464. break;
  16465. }
  16466. return String(a).toLowerCase().localeCompare(String(b).toLowerCase(), locale);
  16467. }
  16468. //fix empty values in position
  16469. if (alignEmptyValues === "top" && dir === "desc" || alignEmptyValues === "bottom" && dir === "asc") {
  16470. emptyAlign *= -1;
  16471. }
  16472. return emptyAlign;
  16473. },
  16474. //sort date
  16475. date: function date(a, b, aRow, bRow, column, dir, params) {
  16476. if (!params.format) {
  16477. params.format = "DD/MM/YYYY";
  16478. }
  16479. return this.sorters.datetime.call(this, a, b, aRow, bRow, column, dir, params);
  16480. },
  16481. //sort hh:mm formatted times
  16482. time: function time(a, b, aRow, bRow, column, dir, params) {
  16483. if (!params.format) {
  16484. params.format = "hh:mm";
  16485. }
  16486. return this.sorters.datetime.call(this, a, b, aRow, bRow, column, dir, params);
  16487. },
  16488. //sort datetime
  16489. datetime: function datetime(a, b, aRow, bRow, column, dir, params) {
  16490. var format = params.format || "DD/MM/YYYY hh:mm:ss",
  16491. alignEmptyValues = params.alignEmptyValues,
  16492. emptyAlign = 0;
  16493. if (typeof moment != "undefined") {
  16494. a = moment(a, format);
  16495. b = moment(b, format);
  16496. if (!a.isValid()) {
  16497. emptyAlign = !b.isValid() ? 0 : -1;
  16498. } else if (!b.isValid()) {
  16499. emptyAlign = 1;
  16500. } else {
  16501. //compare valid values
  16502. return a - b;
  16503. }
  16504. //fix empty values in position
  16505. if (alignEmptyValues === "top" && dir === "desc" || alignEmptyValues === "bottom" && dir === "asc") {
  16506. emptyAlign *= -1;
  16507. }
  16508. return emptyAlign;
  16509. } else {
  16510. console.error("Sort Error - 'datetime' sorter is dependant on moment.js");
  16511. }
  16512. },
  16513. //sort booleans
  16514. boolean: function boolean(a, b, aRow, bRow, column, dir, params) {
  16515. var el1 = a === true || a === "true" || a === "True" || a === 1 ? 1 : 0;
  16516. var el2 = b === true || b === "true" || b === "True" || b === 1 ? 1 : 0;
  16517. return el1 - el2;
  16518. },
  16519. //sort if element contains any data
  16520. array: function array(a, b, aRow, bRow, column, dir, params) {
  16521. var el1 = 0;
  16522. var el2 = 0;
  16523. var type = params.type || "length";
  16524. var alignEmptyValues = params.alignEmptyValues;
  16525. var emptyAlign = 0;
  16526. function calc(value) {
  16527. switch (type) {
  16528. case "length":
  16529. return value.length;
  16530. break;
  16531. case "sum":
  16532. return value.reduce(function (c, d) {
  16533. return c + d;
  16534. });
  16535. break;
  16536. case "max":
  16537. return Math.max.apply(null, value);
  16538. break;
  16539. case "min":
  16540. return Math.min.apply(null, value);
  16541. break;
  16542. case "avg":
  16543. return value.reduce(function (c, d) {
  16544. return c + d;
  16545. }) / value.length;
  16546. break;
  16547. }
  16548. }
  16549. //handle non array values
  16550. if (!Array.isArray(a)) {
  16551. alignEmptyValues = !Array.isArray(b) ? 0 : -1;
  16552. } else if (!Array.isArray(b)) {
  16553. alignEmptyValues = 1;
  16554. } else {
  16555. //compare valid values
  16556. el1 = a ? calc(a) : 0;
  16557. el2 = b ? calc(b) : 0;
  16558. return el1 - el2;
  16559. }
  16560. //fix empty values in position
  16561. if (alignEmptyValues === "top" && dir === "desc" || alignEmptyValues === "bottom" && dir === "asc") {
  16562. emptyAlign *= -1;
  16563. }
  16564. return emptyAlign;
  16565. },
  16566. //sort if element contains any data
  16567. exists: function exists(a, b, aRow, bRow, column, dir, params) {
  16568. var el1 = typeof a == "undefined" ? 0 : 1;
  16569. var el2 = typeof b == "undefined" ? 0 : 1;
  16570. return el1 - el2;
  16571. },
  16572. //sort alpha numeric strings
  16573. alphanum: function alphanum(as, bs, aRow, bRow, column, dir, params) {
  16574. var a,
  16575. b,
  16576. a1,
  16577. b1,
  16578. i = 0,
  16579. L,
  16580. rx = /(\d+)|(\D+)/g,
  16581. rd = /\d/;
  16582. var alignEmptyValues = params.alignEmptyValues;
  16583. var emptyAlign = 0;
  16584. //handle empty values
  16585. if (!as && as !== 0) {
  16586. emptyAlign = !bs && bs !== 0 ? 0 : -1;
  16587. } else if (!bs && bs !== 0) {
  16588. emptyAlign = 1;
  16589. } else {
  16590. if (isFinite(as) && isFinite(bs)) return as - bs;
  16591. a = String(as).toLowerCase();
  16592. b = String(bs).toLowerCase();
  16593. if (a === b) return 0;
  16594. if (!(rd.test(a) && rd.test(b))) return a > b ? 1 : -1;
  16595. a = a.match(rx);
  16596. b = b.match(rx);
  16597. L = a.length > b.length ? b.length : a.length;
  16598. while (i < L) {
  16599. a1 = a[i];
  16600. b1 = b[i++];
  16601. if (a1 !== b1) {
  16602. if (isFinite(a1) && isFinite(b1)) {
  16603. if (a1.charAt(0) === "0") a1 = "." + a1;
  16604. if (b1.charAt(0) === "0") b1 = "." + b1;
  16605. return a1 - b1;
  16606. } else return a1 > b1 ? 1 : -1;
  16607. }
  16608. }
  16609. return a.length > b.length;
  16610. }
  16611. //fix empty values in position
  16612. if (alignEmptyValues === "top" && dir === "desc" || alignEmptyValues === "bottom" && dir === "asc") {
  16613. emptyAlign *= -1;
  16614. }
  16615. return emptyAlign;
  16616. }
  16617. };
  16618. Tabulator.prototype.registerModule("sort", Sort);
  16619. var Validate = function Validate(table) {
  16620. this.table = table;
  16621. };
  16622. //validate
  16623. Validate.prototype.initializeColumn = function (column) {
  16624. var self = this,
  16625. config = [],
  16626. validator;
  16627. if (column.definition.validator) {
  16628. if (Array.isArray(column.definition.validator)) {
  16629. column.definition.validator.forEach(function (item) {
  16630. validator = self._extractValidator(item);
  16631. if (validator) {
  16632. config.push(validator);
  16633. }
  16634. });
  16635. } else {
  16636. validator = this._extractValidator(column.definition.validator);
  16637. if (validator) {
  16638. config.push(validator);
  16639. }
  16640. }
  16641. column.modules.validate = config.length ? config : false;
  16642. }
  16643. };
  16644. Validate.prototype._extractValidator = function (value) {
  16645. var type, params, pos;
  16646. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  16647. case "string":
  16648. pos = value.indexOf(':');
  16649. if (pos > -1) {
  16650. type = value.substring(0, pos);
  16651. params = value.substring(pos + 1);
  16652. } else {
  16653. type = value;
  16654. }
  16655. return this._buildValidator(type, params);
  16656. break;
  16657. case "function":
  16658. return this._buildValidator(value);
  16659. break;
  16660. case "object":
  16661. return this._buildValidator(value.type, value.parameters);
  16662. break;
  16663. }
  16664. };
  16665. Validate.prototype._buildValidator = function (type, params) {
  16666. var func = typeof type == "function" ? type : this.validators[type];
  16667. if (!func) {
  16668. console.warn("Validator Setup Error - No matching validator found:", type);
  16669. return false;
  16670. } else {
  16671. return {
  16672. type: typeof type == "function" ? "function" : type,
  16673. func: func,
  16674. params: params
  16675. };
  16676. }
  16677. };
  16678. Validate.prototype.validate = function (validators, cell, value) {
  16679. var self = this,
  16680. valid = [];
  16681. if (validators) {
  16682. validators.forEach(function (item) {
  16683. if (!item.func.call(self, cell, value, item.params)) {
  16684. valid.push({
  16685. type: item.type,
  16686. parameters: item.params
  16687. });
  16688. }
  16689. });
  16690. }
  16691. return valid.length ? valid : true;
  16692. };
  16693. Validate.prototype.validators = {
  16694. //is integer
  16695. integer: function integer(cell, value, parameters) {
  16696. if (value === "" || value === null || typeof value === "undefined") {
  16697. return true;
  16698. }
  16699. value = Number(value);
  16700. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  16701. },
  16702. //is float
  16703. float: function float(cell, value, parameters) {
  16704. if (value === "" || value === null || typeof value === "undefined") {
  16705. return true;
  16706. }
  16707. value = Number(value);
  16708. return typeof value === 'number' && isFinite(value) && value % 1 !== 0;
  16709. },
  16710. //must be a number
  16711. numeric: function numeric(cell, value, parameters) {
  16712. if (value === "" || value === null || typeof value === "undefined") {
  16713. return true;
  16714. }
  16715. return !isNaN(value);
  16716. },
  16717. //must be a string
  16718. string: function string(cell, value, parameters) {
  16719. if (value === "" || value === null || typeof value === "undefined") {
  16720. return true;
  16721. }
  16722. return isNaN(value);
  16723. },
  16724. //maximum value
  16725. max: function max(cell, value, parameters) {
  16726. if (value === "" || value === null || typeof value === "undefined") {
  16727. return true;
  16728. }
  16729. return parseFloat(value) <= parameters;
  16730. },
  16731. //minimum value
  16732. min: function min(cell, value, parameters) {
  16733. if (value === "" || value === null || typeof value === "undefined") {
  16734. return true;
  16735. }
  16736. return parseFloat(value) >= parameters;
  16737. },
  16738. //minimum string length
  16739. minLength: function minLength(cell, value, parameters) {
  16740. if (value === "" || value === null || typeof value === "undefined") {
  16741. return true;
  16742. }
  16743. return String(value).length >= parameters;
  16744. },
  16745. //maximum string length
  16746. maxLength: function maxLength(cell, value, parameters) {
  16747. if (value === "" || value === null || typeof value === "undefined") {
  16748. return true;
  16749. }
  16750. return String(value).length <= parameters;
  16751. },
  16752. //in provided value list
  16753. in: function _in(cell, value, parameters) {
  16754. if (value === "" || value === null || typeof value === "undefined") {
  16755. return true;
  16756. }
  16757. if (typeof parameters == "string") {
  16758. parameters = parameters.split("|");
  16759. }
  16760. return value === "" || parameters.indexOf(value) > -1;
  16761. },
  16762. //must match provided regex
  16763. regex: function regex(cell, value, parameters) {
  16764. if (value === "" || value === null || typeof value === "undefined") {
  16765. return true;
  16766. }
  16767. var reg = new RegExp(parameters);
  16768. return reg.test(value);
  16769. },
  16770. //value must be unique in this column
  16771. unique: function unique(cell, value, parameters) {
  16772. if (value === "" || value === null || typeof value === "undefined") {
  16773. return true;
  16774. }
  16775. var unique = true;
  16776. var cellData = cell.getData();
  16777. var column = cell.getColumn()._getSelf();
  16778. this.table.rowManager.rows.forEach(function (row) {
  16779. var data = row.getData();
  16780. if (data !== cellData) {
  16781. if (value == column.getFieldValue(data)) {
  16782. unique = false;
  16783. }
  16784. }
  16785. });
  16786. return unique;
  16787. },
  16788. //must have a value
  16789. required: function required(cell, value, parameters) {
  16790. return value !== "" && value !== null && typeof value !== "undefined";
  16791. }
  16792. };
  16793. Tabulator.prototype.registerModule("validate", Validate);
  16794. return Tabulator;
  16795. });