Built files from Bizgaze WebServer
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

tabulator.es2015.js 581KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381
  1. /* Tabulator v4.8.2 (c) Oliver Folkerd */
  2. 'use strict';
  3. // https://tc39.github.io/ecma262/#sec-array.prototype.findIndex
  4. 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; };
  5. if (!Array.prototype.findIndex) {
  6. Object.defineProperty(Array.prototype, 'findIndex', {
  7. value: function value(predicate) {
  8. // 1. Let O be ? ToObject(this value).
  9. if (this == null) {
  10. throw new TypeError('"this" is null or not defined');
  11. }
  12. var o = Object(this);
  13. // 2. Let len be ? ToLength(? Get(O, "length")).
  14. var len = o.length >>> 0;
  15. // 3. If IsCallable(predicate) is false, throw a TypeError exception.
  16. if (typeof predicate !== 'function') {
  17. throw new TypeError('predicate must be a function');
  18. }
  19. // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
  20. var thisArg = arguments[1];
  21. // 5. Let k be 0.
  22. var k = 0;
  23. // 6. Repeat, while k < len
  24. while (k < len) {
  25. // a. Let Pk be ! ToString(k).
  26. // b. Let kValue be ? Get(O, Pk).
  27. // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
  28. // d. If testResult is true, return k.
  29. var kValue = o[k];
  30. if (predicate.call(thisArg, kValue, k, o)) {
  31. return k;
  32. }
  33. // e. Increase k by 1.
  34. k++;
  35. }
  36. // 7. Return -1.
  37. return -1;
  38. }
  39. });
  40. }
  41. // https://tc39.github.io/ecma262/#sec-array.prototype.find
  42. if (!Array.prototype.find) {
  43. Object.defineProperty(Array.prototype, 'find', {
  44. value: function value(predicate) {
  45. // 1. Let O be ? ToObject(this value).
  46. if (this == null) {
  47. throw new TypeError('"this" is null or not defined');
  48. }
  49. var o = Object(this);
  50. // 2. Let len be ? ToLength(? Get(O, "length")).
  51. var len = o.length >>> 0;
  52. // 3. If IsCallable(predicate) is false, throw a TypeError exception.
  53. if (typeof predicate !== 'function') {
  54. throw new TypeError('predicate must be a function');
  55. }
  56. // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
  57. var thisArg = arguments[1];
  58. // 5. Let k be 0.
  59. var k = 0;
  60. // 6. Repeat, while k < len
  61. while (k < len) {
  62. // a. Let Pk be ! ToString(k).
  63. // b. Let kValue be ? Get(O, Pk).
  64. // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
  65. // d. If testResult is true, return kValue.
  66. var kValue = o[k];
  67. if (predicate.call(thisArg, kValue, k, o)) {
  68. return kValue;
  69. }
  70. // e. Increase k by 1.
  71. k++;
  72. }
  73. // 7. Return undefined.
  74. return undefined;
  75. }
  76. });
  77. }
  78. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes#Polyfill
  79. if (!String.prototype.includes) {
  80. String.prototype.includes = function (search, start) {
  81. 'use strict';
  82. if (search instanceof RegExp) {
  83. throw TypeError('first argument must not be a RegExp');
  84. }
  85. if (start === undefined) {
  86. start = 0;
  87. }
  88. return this.indexOf(search, start) !== -1;
  89. };
  90. }
  91. // https://tc39.github.io/ecma262/#sec-array.prototype.includes
  92. if (!Array.prototype.includes) {
  93. Object.defineProperty(Array.prototype, 'includes', {
  94. value: function value(searchElement, fromIndex) {
  95. if (this == null) {
  96. throw new TypeError('"this" is null or not defined');
  97. }
  98. // 1. Let O be ? ToObject(this value).
  99. var o = Object(this);
  100. // 2. Let len be ? ToLength(? Get(O, "length")).
  101. var len = o.length >>> 0;
  102. // 3. If len is 0, return false.
  103. if (len === 0) {
  104. return false;
  105. }
  106. // 4. Let n be ? ToInteger(fromIndex).
  107. // (If fromIndex is undefined, this step produces the value 0.)
  108. var n = fromIndex | 0;
  109. // 5. If n ≥ 0, then
  110. // a. Let k be n.
  111. // 6. Else n < 0,
  112. // a. Let k be len + n.
  113. // b. If k < 0, let k be 0.
  114. var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
  115. function sameValueZero(x, y) {
  116. return x === y || typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y);
  117. }
  118. // 7. Repeat, while k < len
  119. while (k < len) {
  120. // a. Let elementK be the result of ? Get(O, ! ToString(k)).
  121. // b. If SameValueZero(searchElement, elementK) is true, return true.
  122. if (sameValueZero(o[k], searchElement)) {
  123. return true;
  124. }
  125. // c. Increase k by 1.
  126. k++;
  127. }
  128. // 8. Return false
  129. return false;
  130. }
  131. });
  132. }
  133. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill
  134. if (typeof Object.assign !== 'function') {
  135. // Must be writable: true, enumerable: false, configurable: true
  136. Object.defineProperty(Object, "assign", {
  137. value: function assign(target, varArgs) {
  138. // .length of function is 2
  139. 'use strict';
  140. if (target === null || target === undefined) {
  141. throw new TypeError('Cannot convert undefined or null to object');
  142. }
  143. var to = Object(target);
  144. for (var index = 1; index < arguments.length; index++) {
  145. var nextSource = arguments[index];
  146. if (nextSource !== null && nextSource !== undefined) {
  147. for (var nextKey in nextSource) {
  148. // Avoid bugs when hasOwnProperty is shadowed
  149. if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
  150. to[nextKey] = nextSource[nextKey];
  151. }
  152. }
  153. }
  154. }
  155. return to;
  156. },
  157. writable: true,
  158. configurable: true
  159. });
  160. }
  161. var ColumnManager = function ColumnManager(table) {
  162. this.table = table; //hold parent table
  163. this.blockHozScrollEvent = false;
  164. this.headersElement = this.createHeadersElement();
  165. this.element = this.createHeaderElement(); //containing element
  166. this.rowManager = null; //hold row manager object
  167. this.columns = []; // column definition object
  168. this.columnsByIndex = []; //columns by index
  169. this.columnsByField = {}; //columns by field
  170. this.scrollLeft = 0;
  171. this.element.insertBefore(this.headersElement, this.element.firstChild);
  172. };
  173. ////////////// Setup Functions /////////////////
  174. ColumnManager.prototype.createHeadersElement = function () {
  175. var el = document.createElement("div");
  176. el.classList.add("tabulator-headers");
  177. return el;
  178. };
  179. ColumnManager.prototype.createHeaderElement = function () {
  180. var el = document.createElement("div");
  181. el.classList.add("tabulator-header");
  182. if (!this.table.options.headerVisible) {
  183. el.classList.add("tabulator-header-hidden");
  184. }
  185. return el;
  186. };
  187. ColumnManager.prototype.initialize = function () {
  188. var self = this;
  189. //scroll body along with header
  190. // self.element.addEventListener("scroll", function(e){
  191. // if(!self.blockHozScrollEvent){
  192. // self.table.rowManager.scrollHorizontal(self.element.scrollLeft);
  193. // }
  194. // });
  195. };
  196. //link to row manager
  197. ColumnManager.prototype.setRowManager = function (manager) {
  198. this.rowManager = manager;
  199. };
  200. //return containing element
  201. ColumnManager.prototype.getElement = function () {
  202. return this.element;
  203. };
  204. //return header containing element
  205. ColumnManager.prototype.getHeadersElement = function () {
  206. return this.headersElement;
  207. };
  208. // ColumnManager.prototype.tempScrollBlock = function(){
  209. // clearTimeout(this.blockHozScrollEvent);
  210. // this.blockHozScrollEvent = setTimeout(() => {this.blockHozScrollEvent = false;}, 50);
  211. // }
  212. //scroll horizontally to match table body
  213. ColumnManager.prototype.scrollHorizontal = function (left) {
  214. var hozAdjust = 0,
  215. scrollWidth = this.element.scrollWidth - this.table.element.clientWidth;
  216. // this.tempScrollBlock();
  217. this.element.scrollLeft = left;
  218. //adjust for vertical scrollbar moving table when present
  219. if (left > scrollWidth) {
  220. hozAdjust = left - scrollWidth;
  221. this.element.style.marginLeft = -hozAdjust + "px";
  222. } else {
  223. this.element.style.marginLeft = 0;
  224. }
  225. //keep frozen columns fixed in position
  226. //this._calcFrozenColumnsPos(hozAdjust + 3);
  227. this.scrollLeft = left;
  228. if (this.table.modExists("frozenColumns")) {
  229. this.table.modules.frozenColumns.scrollHorizontal();
  230. }
  231. };
  232. ///////////// Column Setup Functions /////////////
  233. ColumnManager.prototype.generateColumnsFromRowData = function (data) {
  234. var cols = [],
  235. definitions = this.table.options.autoColumnsDefinitions,
  236. row,
  237. sorter;
  238. if (data && data.length) {
  239. row = data[0];
  240. for (var key in row) {
  241. var col = {
  242. field: key,
  243. title: key
  244. };
  245. var value = row[key];
  246. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  247. case "undefined":
  248. sorter = "string";
  249. break;
  250. case "boolean":
  251. sorter = "boolean";
  252. break;
  253. case "object":
  254. if (Array.isArray(value)) {
  255. sorter = "array";
  256. } else {
  257. sorter = "string";
  258. }
  259. break;
  260. default:
  261. if (!isNaN(value) && value !== "") {
  262. sorter = "number";
  263. } else {
  264. if (value.match(/((^[0-9]+[a-z]+)|(^[a-z]+[0-9]+))+$/i)) {
  265. sorter = "alphanum";
  266. } else {
  267. sorter = "string";
  268. }
  269. }
  270. break;
  271. }
  272. col.sorter = sorter;
  273. cols.push(col);
  274. }
  275. if (definitions) {
  276. switch (typeof definitions === 'undefined' ? 'undefined' : _typeof(definitions)) {
  277. case "function":
  278. this.table.options.columns = definitions.call(this.table, cols);
  279. break;
  280. case "object":
  281. if (Array.isArray(definitions)) {
  282. cols.forEach(function (col) {
  283. var match = definitions.find(function (def) {
  284. return def.field === col.field;
  285. });
  286. if (match) {
  287. Object.assign(col, match);
  288. }
  289. });
  290. } else {
  291. cols.forEach(function (col) {
  292. if (definitions[col.field]) {
  293. Object.assign(col, definitions[col.field]);
  294. }
  295. });
  296. }
  297. this.table.options.columns = cols;
  298. break;
  299. }
  300. } else {
  301. this.table.options.columns = cols;
  302. }
  303. this.setColumns(this.table.options.columns);
  304. }
  305. };
  306. ColumnManager.prototype.setColumns = function (cols, row) {
  307. var self = this;
  308. while (self.headersElement.firstChild) {
  309. self.headersElement.removeChild(self.headersElement.firstChild);
  310. }self.columns = [];
  311. self.columnsByIndex = [];
  312. self.columnsByField = {};
  313. //reset frozen columns
  314. if (self.table.modExists("frozenColumns")) {
  315. self.table.modules.frozenColumns.reset();
  316. }
  317. cols.forEach(function (def, i) {
  318. self._addColumn(def);
  319. });
  320. self._reIndexColumns();
  321. if (self.table.options.responsiveLayout && self.table.modExists("responsiveLayout", true)) {
  322. self.table.modules.responsiveLayout.initialize();
  323. }
  324. if (this.table.options.virtualDomHoz) {
  325. this.table.vdomHoz.reinitialize(false, true);
  326. }
  327. self.redraw(true);
  328. };
  329. ColumnManager.prototype._addColumn = function (definition, before, nextToColumn) {
  330. var column = new Column(definition, this),
  331. colEl = column.getElement(),
  332. index = nextToColumn ? this.findColumnIndex(nextToColumn) : nextToColumn;
  333. if (nextToColumn && index > -1) {
  334. var parentIndex = this.columns.indexOf(nextToColumn.getTopColumn());
  335. var nextEl = nextToColumn.getElement();
  336. if (before) {
  337. this.columns.splice(parentIndex, 0, column);
  338. nextEl.parentNode.insertBefore(colEl, nextEl);
  339. } else {
  340. this.columns.splice(parentIndex + 1, 0, column);
  341. nextEl.parentNode.insertBefore(colEl, nextEl.nextSibling);
  342. }
  343. } else {
  344. if (before) {
  345. this.columns.unshift(column);
  346. this.headersElement.insertBefore(column.getElement(), this.headersElement.firstChild);
  347. } else {
  348. this.columns.push(column);
  349. this.headersElement.appendChild(column.getElement());
  350. }
  351. column.columnRendered();
  352. }
  353. return column;
  354. };
  355. ColumnManager.prototype.registerColumnField = function (col) {
  356. if (col.definition.field) {
  357. this.columnsByField[col.definition.field] = col;
  358. }
  359. };
  360. ColumnManager.prototype.registerColumnPosition = function (col) {
  361. this.columnsByIndex.push(col);
  362. };
  363. ColumnManager.prototype._reIndexColumns = function () {
  364. this.columnsByIndex = [];
  365. this.columns.forEach(function (column) {
  366. column.reRegisterPosition();
  367. });
  368. };
  369. //ensure column headers take up the correct amount of space in column groups
  370. ColumnManager.prototype._verticalAlignHeaders = function () {
  371. var self = this,
  372. minHeight = 0;
  373. self.columns.forEach(function (column) {
  374. var height;
  375. column.clearVerticalAlign();
  376. height = column.getHeight();
  377. if (height > minHeight) {
  378. minHeight = height;
  379. }
  380. });
  381. self.columns.forEach(function (column) {
  382. column.verticalAlign(self.table.options.columnHeaderVertAlign, minHeight);
  383. });
  384. self.rowManager.adjustTableSize();
  385. };
  386. //////////////// Column Details /////////////////
  387. ColumnManager.prototype.findColumn = function (subject) {
  388. var self = this;
  389. if ((typeof subject === 'undefined' ? 'undefined' : _typeof(subject)) == "object") {
  390. if (subject instanceof Column) {
  391. //subject is column element
  392. return subject;
  393. } else if (subject instanceof ColumnComponent) {
  394. //subject is public column component
  395. return subject._getSelf() || false;
  396. } else if (typeof HTMLElement !== "undefined" && subject instanceof HTMLElement) {
  397. //subject is a HTML element of the column header
  398. var match = self.columns.find(function (column) {
  399. return column.element === subject;
  400. });
  401. return match || false;
  402. }
  403. } else {
  404. //subject should be treated as the field name of the column
  405. return this.columnsByField[subject] || false;
  406. }
  407. //catch all for any other type of input
  408. return false;
  409. };
  410. ColumnManager.prototype.getColumnByField = function (field) {
  411. return this.columnsByField[field];
  412. };
  413. ColumnManager.prototype.getColumnsByFieldRoot = function (root) {
  414. var _this = this;
  415. var matches = [];
  416. Object.keys(this.columnsByField).forEach(function (field) {
  417. var fieldRoot = field.split(".")[0];
  418. if (fieldRoot === root) {
  419. matches.push(_this.columnsByField[field]);
  420. }
  421. });
  422. return matches;
  423. };
  424. ColumnManager.prototype.getColumnByIndex = function (index) {
  425. return this.columnsByIndex[index];
  426. };
  427. ColumnManager.prototype.getFirstVisibileColumn = function (index) {
  428. var index = this.columnsByIndex.findIndex(function (col) {
  429. return col.visible;
  430. });
  431. return index > -1 ? this.columnsByIndex[index] : false;
  432. };
  433. ColumnManager.prototype.getColumns = function () {
  434. return this.columns;
  435. };
  436. ColumnManager.prototype.findColumnIndex = function (column) {
  437. return this.columnsByIndex.findIndex(function (col) {
  438. return column === col;
  439. });
  440. };
  441. //return all columns that are not groups
  442. ColumnManager.prototype.getRealColumns = function () {
  443. return this.columnsByIndex;
  444. };
  445. //travers across columns and call action
  446. ColumnManager.prototype.traverse = function (callback) {
  447. var self = this;
  448. self.columnsByIndex.forEach(function (column, i) {
  449. callback(column, i);
  450. });
  451. };
  452. //get defintions of actual columns
  453. ColumnManager.prototype.getDefinitions = function (active) {
  454. var self = this,
  455. output = [];
  456. self.columnsByIndex.forEach(function (column) {
  457. if (!active || active && column.visible) {
  458. output.push(column.getDefinition());
  459. }
  460. });
  461. return output;
  462. };
  463. //get full nested definition tree
  464. ColumnManager.prototype.getDefinitionTree = function () {
  465. var self = this,
  466. output = [];
  467. self.columns.forEach(function (column) {
  468. output.push(column.getDefinition(true));
  469. });
  470. return output;
  471. };
  472. ColumnManager.prototype.getComponents = function (structured) {
  473. var self = this,
  474. output = [],
  475. columns = structured ? self.columns : self.columnsByIndex;
  476. columns.forEach(function (column) {
  477. output.push(column.getComponent());
  478. });
  479. return output;
  480. };
  481. ColumnManager.prototype.getWidth = function () {
  482. var width = 0;
  483. this.columnsByIndex.forEach(function (column) {
  484. if (column.visible) {
  485. width += column.getWidth();
  486. }
  487. });
  488. return width;
  489. };
  490. ColumnManager.prototype.moveColumn = function (from, to, after) {
  491. this.moveColumnActual(from, to, after);
  492. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  493. this.table.modules.responsiveLayout.initialize();
  494. }
  495. if (this.table.modExists("columnCalcs")) {
  496. this.table.modules.columnCalcs.recalc(this.table.rowManager.activeRows);
  497. }
  498. to.element.parentNode.insertBefore(from.element, to.element);
  499. if (after) {
  500. to.element.parentNode.insertBefore(to.element, from.element);
  501. }
  502. this._verticalAlignHeaders();
  503. this.table.rowManager.reinitialize();
  504. };
  505. ColumnManager.prototype.moveColumnActual = function (from, to, after) {
  506. if (from.parent.isGroup) {
  507. this._moveColumnInArray(from.parent.columns, from, to, after);
  508. } else {
  509. this._moveColumnInArray(this.columns, from, to, after);
  510. }
  511. this._moveColumnInArray(this.columnsByIndex, from, to, after, true);
  512. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  513. this.table.modules.responsiveLayout.initialize();
  514. }
  515. if (this.table.options.virtualDomHoz) {
  516. this.table.vdomHoz.reinitialize(true);
  517. }
  518. if (this.table.options.columnMoved) {
  519. this.table.options.columnMoved.call(this.table, from.getComponent(), this.table.columnManager.getComponents());
  520. }
  521. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.columns) {
  522. this.table.modules.persistence.save("columns");
  523. }
  524. };
  525. ColumnManager.prototype._moveColumnInArray = function (columns, from, to, after, updateRows) {
  526. var _this2 = this;
  527. var fromIndex = columns.indexOf(from),
  528. toIndex,
  529. rows = [];
  530. if (fromIndex > -1) {
  531. columns.splice(fromIndex, 1);
  532. toIndex = columns.indexOf(to);
  533. if (toIndex > -1) {
  534. if (after) {
  535. toIndex = toIndex + 1;
  536. }
  537. } else {
  538. toIndex = fromIndex;
  539. }
  540. columns.splice(toIndex, 0, from);
  541. if (updateRows) {
  542. if (this.table.options.dataTree && this.table.modExists("dataTree", true)) {
  543. this.table.rowManager.rows.forEach(function (row) {
  544. rows = rows.concat(_this2.table.modules.dataTree.getTreeChildren(row, false, true));
  545. });
  546. }
  547. rows = rows.concat(this.table.rowManager.rows);
  548. rows.forEach(function (row) {
  549. if (row.cells.length) {
  550. var cell = row.cells.splice(fromIndex, 1)[0];
  551. row.cells.splice(toIndex, 0, cell);
  552. }
  553. });
  554. }
  555. }
  556. };
  557. ColumnManager.prototype.scrollToColumn = function (column, position, ifVisible) {
  558. var _this3 = this;
  559. var left = 0,
  560. offset = 0,
  561. adjust = 0,
  562. colEl = column.getElement();
  563. return new Promise(function (resolve, reject) {
  564. if (typeof position === "undefined") {
  565. position = _this3.table.options.scrollToColumnPosition;
  566. }
  567. if (typeof ifVisible === "undefined") {
  568. ifVisible = _this3.table.options.scrollToColumnIfVisible;
  569. }
  570. if (column.visible) {
  571. //align to correct position
  572. switch (position) {
  573. case "middle":
  574. case "center":
  575. adjust = -_this3.element.clientWidth / 2;
  576. break;
  577. case "right":
  578. adjust = colEl.clientWidth - _this3.headersElement.clientWidth;
  579. break;
  580. }
  581. //check column visibility
  582. if (!ifVisible) {
  583. offset = colEl.offsetLeft;
  584. if (offset > 0 && offset + colEl.offsetWidth < _this3.element.clientWidth) {
  585. return false;
  586. }
  587. }
  588. //calculate scroll position
  589. left = colEl.offsetLeft + adjust;
  590. left = Math.max(Math.min(left, _this3.table.rowManager.element.scrollWidth - _this3.table.rowManager.element.clientWidth), 0);
  591. _this3.table.rowManager.scrollHorizontal(left);
  592. _this3.scrollHorizontal(left);
  593. resolve();
  594. } else {
  595. console.warn("Scroll Error - Column not visible");
  596. reject("Scroll Error - Column not visible");
  597. }
  598. });
  599. };
  600. //////////////// Cell Management /////////////////
  601. ColumnManager.prototype.generateCells = function (row) {
  602. var self = this;
  603. var cells = [];
  604. self.columnsByIndex.forEach(function (column) {
  605. cells.push(column.generateCell(row));
  606. });
  607. return cells;
  608. };
  609. //////////////// Column Management /////////////////
  610. ColumnManager.prototype.getFlexBaseWidth = function () {
  611. var self = this,
  612. totalWidth = self.table.element.clientWidth,
  613. //table element width
  614. fixedWidth = 0;
  615. //adjust for vertical scrollbar if present
  616. if (self.rowManager.element.scrollHeight > self.rowManager.element.clientHeight) {
  617. totalWidth -= self.rowManager.element.offsetWidth - self.rowManager.element.clientWidth;
  618. }
  619. this.columnsByIndex.forEach(function (column) {
  620. var width, minWidth, colWidth;
  621. if (column.visible) {
  622. width = column.definition.width || 0;
  623. minWidth = typeof column.minWidth == "undefined" ? self.table.options.columnMinWidth : parseInt(column.minWidth);
  624. if (typeof width == "string") {
  625. if (width.indexOf("%") > -1) {
  626. colWidth = totalWidth / 100 * parseInt(width);
  627. } else {
  628. colWidth = parseInt(width);
  629. }
  630. } else {
  631. colWidth = width;
  632. }
  633. fixedWidth += colWidth > minWidth ? colWidth : minWidth;
  634. }
  635. });
  636. return fixedWidth;
  637. };
  638. ColumnManager.prototype.addColumn = function (definition, before, nextToColumn) {
  639. var _this4 = this;
  640. return new Promise(function (resolve, reject) {
  641. var column = _this4._addColumn(definition, before, nextToColumn);
  642. _this4._reIndexColumns();
  643. if (_this4.table.options.responsiveLayout && _this4.table.modExists("responsiveLayout", true)) {
  644. _this4.table.modules.responsiveLayout.initialize();
  645. }
  646. if (_this4.table.modExists("columnCalcs")) {
  647. _this4.table.modules.columnCalcs.recalc(_this4.table.rowManager.activeRows);
  648. }
  649. _this4.redraw();
  650. if (_this4.table.modules.layout.getMode() != "fitColumns") {
  651. column.reinitializeWidth();
  652. }
  653. _this4._verticalAlignHeaders();
  654. _this4.table.rowManager.reinitialize();
  655. if (_this4.table.options.virtualDomHoz) {
  656. _this4.table.vdomHoz.reinitialize();
  657. }
  658. resolve(column);
  659. });
  660. };
  661. //remove column from system
  662. ColumnManager.prototype.deregisterColumn = function (column) {
  663. var field = column.getField(),
  664. index;
  665. //remove from field list
  666. if (field) {
  667. delete this.columnsByField[field];
  668. }
  669. //remove from index list
  670. index = this.columnsByIndex.indexOf(column);
  671. if (index > -1) {
  672. this.columnsByIndex.splice(index, 1);
  673. }
  674. //remove from column list
  675. index = this.columns.indexOf(column);
  676. if (index > -1) {
  677. this.columns.splice(index, 1);
  678. }
  679. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  680. this.table.modules.responsiveLayout.initialize();
  681. }
  682. this._verticalAlignHeaders();
  683. this.redraw();
  684. };
  685. //redraw columns
  686. ColumnManager.prototype.redraw = function (force) {
  687. if (force) {
  688. if (Tabulator.prototype.helpers.elVisible(this.element)) {
  689. this._verticalAlignHeaders();
  690. }
  691. this.table.rowManager.resetScroll();
  692. this.table.rowManager.reinitialize();
  693. }
  694. if (["fitColumns", "fitDataStretch"].indexOf(this.table.modules.layout.getMode()) > -1) {
  695. this.table.modules.layout.layout();
  696. } else {
  697. if (force) {
  698. this.table.modules.layout.layout();
  699. } else {
  700. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  701. this.table.modules.responsiveLayout.update();
  702. }
  703. }
  704. }
  705. if (this.table.modExists("frozenColumns")) {
  706. this.table.modules.frozenColumns.layout();
  707. }
  708. if (this.table.modExists("columnCalcs")) {
  709. this.table.modules.columnCalcs.recalc(this.table.rowManager.activeRows);
  710. }
  711. if (force) {
  712. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.columns) {
  713. this.table.modules.persistence.save("columns");
  714. }
  715. if (this.table.modExists("columnCalcs")) {
  716. this.table.modules.columnCalcs.redraw();
  717. }
  718. }
  719. this.table.footerManager.redraw();
  720. };
  721. //public column object
  722. var ColumnComponent = function ColumnComponent(column) {
  723. this._column = column;
  724. this.type = "ColumnComponent";
  725. };
  726. ColumnComponent.prototype.getElement = function () {
  727. return this._column.getElement();
  728. };
  729. ColumnComponent.prototype.getDefinition = function () {
  730. return this._column.getDefinition();
  731. };
  732. ColumnComponent.prototype.getField = function () {
  733. return this._column.getField();
  734. };
  735. ColumnComponent.prototype.getCells = function () {
  736. var cells = [];
  737. this._column.cells.forEach(function (cell) {
  738. cells.push(cell.getComponent());
  739. });
  740. return cells;
  741. };
  742. ColumnComponent.prototype.getVisibility = function () {
  743. console.warn("getVisibility function is deprecated, you should now use the isVisible function");
  744. return this._column.visible;
  745. };
  746. ColumnComponent.prototype.isVisible = function () {
  747. return this._column.visible;
  748. };
  749. ColumnComponent.prototype.show = function () {
  750. if (this._column.isGroup) {
  751. this._column.columns.forEach(function (column) {
  752. column.show();
  753. });
  754. } else {
  755. this._column.show();
  756. }
  757. };
  758. ColumnComponent.prototype.hide = function () {
  759. if (this._column.isGroup) {
  760. this._column.columns.forEach(function (column) {
  761. column.hide();
  762. });
  763. } else {
  764. this._column.hide();
  765. }
  766. };
  767. ColumnComponent.prototype.toggle = function () {
  768. if (this._column.visible) {
  769. this.hide();
  770. } else {
  771. this.show();
  772. }
  773. };
  774. ColumnComponent.prototype.delete = function () {
  775. return this._column.delete();
  776. };
  777. ColumnComponent.prototype.getSubColumns = function () {
  778. var output = [];
  779. if (this._column.columns.length) {
  780. this._column.columns.forEach(function (column) {
  781. output.push(column.getComponent());
  782. });
  783. }
  784. return output;
  785. };
  786. ColumnComponent.prototype.getParentColumn = function () {
  787. return this._column.parent instanceof Column ? this._column.parent.getComponent() : false;
  788. };
  789. ColumnComponent.prototype._getSelf = function () {
  790. return this._column;
  791. };
  792. ColumnComponent.prototype.scrollTo = function () {
  793. return this._column.table.columnManager.scrollToColumn(this._column);
  794. };
  795. ColumnComponent.prototype.getTable = function () {
  796. return this._column.table;
  797. };
  798. ColumnComponent.prototype.headerFilterFocus = function () {
  799. if (this._column.table.modExists("filter", true)) {
  800. this._column.table.modules.filter.setHeaderFilterFocus(this._column);
  801. }
  802. };
  803. ColumnComponent.prototype.reloadHeaderFilter = function () {
  804. if (this._column.table.modExists("filter", true)) {
  805. this._column.table.modules.filter.reloadHeaderFilter(this._column);
  806. }
  807. };
  808. ColumnComponent.prototype.getHeaderFilterValue = function () {
  809. if (this._column.table.modExists("filter", true)) {
  810. return this._column.table.modules.filter.getHeaderFilterValue(this._column);
  811. }
  812. };
  813. ColumnComponent.prototype.setHeaderFilterValue = function (value) {
  814. if (this._column.table.modExists("filter", true)) {
  815. this._column.table.modules.filter.setHeaderFilterValue(this._column, value);
  816. }
  817. };
  818. ColumnComponent.prototype.move = function (to, after) {
  819. var toColumn = this._column.table.columnManager.findColumn(to);
  820. if (toColumn) {
  821. this._column.table.columnManager.moveColumn(this._column, toColumn, after);
  822. } else {
  823. console.warn("Move Error - No matching column found:", toColumn);
  824. }
  825. };
  826. ColumnComponent.prototype.getNextColumn = function () {
  827. var nextCol = this._column.nextColumn();
  828. return nextCol ? nextCol.getComponent() : false;
  829. };
  830. ColumnComponent.prototype.getPrevColumn = function () {
  831. var prevCol = this._column.prevColumn();
  832. return prevCol ? prevCol.getComponent() : false;
  833. };
  834. ColumnComponent.prototype.updateDefinition = function (updates) {
  835. return this._column.updateDefinition(updates);
  836. };
  837. ColumnComponent.prototype.getWidth = function () {
  838. return this._column.getWidth();
  839. };
  840. ColumnComponent.prototype.setWidth = function (width) {
  841. var result;
  842. if (width === true) {
  843. result = this._column.reinitializeWidth(true);
  844. } else {
  845. result = this._column.setWidth(width);
  846. }
  847. if (this._column.table.options.virtualDomHoz) {
  848. this._column.table.vdomHoz.reinitialize(true);
  849. }
  850. return result;
  851. };
  852. ColumnComponent.prototype.validate = function () {
  853. return this._column.validate();
  854. };
  855. var Column = function Column(def, parent) {
  856. var self = this;
  857. this.table = parent.table;
  858. this.definition = def; //column definition
  859. this.parent = parent; //hold parent object
  860. this.type = "column"; //type of element
  861. this.columns = []; //child columns
  862. this.cells = []; //cells bound to this column
  863. this.element = this.createElement(); //column header element
  864. this.contentElement = false;
  865. this.titleHolderElement = false;
  866. this.titleElement = false;
  867. this.groupElement = this.createGroupElement(); //column group holder element
  868. this.isGroup = false;
  869. this.tooltip = false; //hold column tooltip
  870. this.hozAlign = ""; //horizontal text alignment
  871. this.vertAlign = ""; //vert text alignment
  872. //multi dimensional filed handling
  873. this.field = "";
  874. this.fieldStructure = "";
  875. this.getFieldValue = "";
  876. this.setFieldValue = "";
  877. this.titleFormatterRendered = false;
  878. this.setField(this.definition.field);
  879. if (this.table.options.invalidOptionWarnings) {
  880. this.checkDefinition();
  881. }
  882. this.modules = {}; //hold module variables;
  883. this.cellEvents = {
  884. cellClick: false,
  885. cellDblClick: false,
  886. cellContext: false,
  887. cellTap: false,
  888. cellDblTap: false,
  889. cellTapHold: false,
  890. cellMouseEnter: false,
  891. cellMouseLeave: false,
  892. cellMouseOver: false,
  893. cellMouseOut: false,
  894. cellMouseMove: false
  895. };
  896. this.width = null; //column width
  897. this.widthStyled = ""; //column width prestyled to improve render efficiency
  898. this.minWidth = null; //column minimum width
  899. this.minWidthStyled = ""; //column minimum prestyled to improve render efficiency
  900. this.widthFixed = false; //user has specified a width for this column
  901. this.visible = true; //default visible state
  902. this.component = null;
  903. this._mapDepricatedFunctionality();
  904. //initialize column
  905. if (def.columns) {
  906. this.isGroup = true;
  907. def.columns.forEach(function (def, i) {
  908. var newCol = new Column(def, self);
  909. self.attachColumn(newCol);
  910. });
  911. self.checkColumnVisibility();
  912. } else {
  913. parent.registerColumnField(this);
  914. }
  915. if (def.rowHandle && this.table.options.movableRows !== false && this.table.modExists("moveRow")) {
  916. this.table.modules.moveRow.setHandle(true);
  917. }
  918. this._buildHeader();
  919. this.bindModuleColumns();
  920. };
  921. Column.prototype.createElement = function () {
  922. var el = document.createElement("div");
  923. el.classList.add("tabulator-col");
  924. el.setAttribute("role", "columnheader");
  925. el.setAttribute("aria-sort", "none");
  926. return el;
  927. };
  928. Column.prototype.createGroupElement = function () {
  929. var el = document.createElement("div");
  930. el.classList.add("tabulator-col-group-cols");
  931. return el;
  932. };
  933. Column.prototype.checkDefinition = function () {
  934. var _this5 = this;
  935. Object.keys(this.definition).forEach(function (key) {
  936. if (_this5.defaultOptionList.indexOf(key) === -1) {
  937. console.warn("Invalid column definition option in '" + (_this5.field || _this5.definition.title) + "' column:", key);
  938. }
  939. });
  940. };
  941. Column.prototype.setField = function (field) {
  942. this.field = field;
  943. this.fieldStructure = field ? this.table.options.nestedFieldSeparator ? field.split(this.table.options.nestedFieldSeparator) : [field] : [];
  944. this.getFieldValue = this.fieldStructure.length > 1 ? this._getNestedData : this._getFlatData;
  945. this.setFieldValue = this.fieldStructure.length > 1 ? this._setNestedData : this._setFlatData;
  946. };
  947. //register column position with column manager
  948. Column.prototype.registerColumnPosition = function (column) {
  949. this.parent.registerColumnPosition(column);
  950. };
  951. //register column position with column manager
  952. Column.prototype.registerColumnField = function (column) {
  953. this.parent.registerColumnField(column);
  954. };
  955. //trigger position registration
  956. Column.prototype.reRegisterPosition = function () {
  957. if (this.isGroup) {
  958. this.columns.forEach(function (column) {
  959. column.reRegisterPosition();
  960. });
  961. } else {
  962. this.registerColumnPosition(this);
  963. }
  964. };
  965. Column.prototype._mapDepricatedFunctionality = function () {
  966. if (typeof this.definition.hideInHtml !== "undefined") {
  967. this.definition.htmlOutput = !this.definition.hideInHtml;
  968. console.warn("hideInHtml column definition property is deprecated, you should now use htmlOutput");
  969. }
  970. if (typeof this.definition.align !== "undefined") {
  971. this.definition.hozAlign = this.definition.align;
  972. console.warn("align column definition property is deprecated, you should now use hozAlign");
  973. }
  974. if (typeof this.definition.downloadTitle !== "undefined") {
  975. this.definition.titleDownload = this.definition.downloadTitle;
  976. console.warn("downloadTitle definition property is deprecated, you should now use titleDownload");
  977. }
  978. };
  979. Column.prototype.setTooltip = function () {
  980. var self = this,
  981. def = self.definition;
  982. //set header tooltips
  983. var tooltip = def.headerTooltip || def.tooltip === false ? def.headerTooltip : self.table.options.tooltipsHeader;
  984. if (tooltip) {
  985. if (tooltip === true) {
  986. if (def.field) {
  987. self.table.modules.localize.bind("columns|" + def.field, function (value) {
  988. self.element.setAttribute("title", value || def.title);
  989. });
  990. } else {
  991. self.element.setAttribute("title", def.title);
  992. }
  993. } else {
  994. if (typeof tooltip == "function") {
  995. tooltip = tooltip(self.getComponent());
  996. if (tooltip === false) {
  997. tooltip = "";
  998. }
  999. }
  1000. self.element.setAttribute("title", tooltip);
  1001. }
  1002. } else {
  1003. self.element.setAttribute("title", "");
  1004. }
  1005. };
  1006. //build header element
  1007. Column.prototype._buildHeader = function () {
  1008. var self = this,
  1009. def = self.definition;
  1010. while (self.element.firstChild) {
  1011. self.element.removeChild(self.element.firstChild);
  1012. }if (def.headerVertical) {
  1013. self.element.classList.add("tabulator-col-vertical");
  1014. if (def.headerVertical === "flip") {
  1015. self.element.classList.add("tabulator-col-vertical-flip");
  1016. }
  1017. }
  1018. self.contentElement = self._bindEvents();
  1019. self.contentElement = self._buildColumnHeaderContent();
  1020. self.element.appendChild(self.contentElement);
  1021. if (self.isGroup) {
  1022. self._buildGroupHeader();
  1023. } else {
  1024. self._buildColumnHeader();
  1025. }
  1026. self.setTooltip();
  1027. //set resizable handles
  1028. if (self.table.options.resizableColumns && self.table.modExists("resizeColumns")) {
  1029. self.table.modules.resizeColumns.initializeColumn("header", self, self.element);
  1030. }
  1031. //set resizable handles
  1032. if (def.headerFilter && self.table.modExists("filter") && self.table.modExists("edit")) {
  1033. if (typeof def.headerFilterPlaceholder !== "undefined" && def.field) {
  1034. self.table.modules.localize.setHeaderFilterColumnPlaceholder(def.field, def.headerFilterPlaceholder);
  1035. }
  1036. self.table.modules.filter.initializeColumn(self);
  1037. }
  1038. //set resizable handles
  1039. if (self.table.modExists("frozenColumns")) {
  1040. self.table.modules.frozenColumns.initializeColumn(self);
  1041. }
  1042. //set movable column
  1043. if (self.table.options.movableColumns && !self.isGroup && self.table.modExists("moveColumn")) {
  1044. self.table.modules.moveColumn.initializeColumn(self);
  1045. }
  1046. //set calcs column
  1047. if ((def.topCalc || def.bottomCalc) && self.table.modExists("columnCalcs")) {
  1048. self.table.modules.columnCalcs.initializeColumn(self);
  1049. }
  1050. //handle persistence
  1051. if (self.table.modExists("persistence") && self.table.modules.persistence.config.columns) {
  1052. self.table.modules.persistence.initializeColumn(self);
  1053. }
  1054. //update header tooltip on mouse enter
  1055. self.element.addEventListener("mouseenter", function (e) {
  1056. self.setTooltip();
  1057. });
  1058. };
  1059. Column.prototype._bindEvents = function () {
  1060. var self = this,
  1061. def = self.definition,
  1062. dblTap,
  1063. tapHold,
  1064. tap;
  1065. //setup header click event bindings
  1066. if (typeof def.headerClick == "function") {
  1067. self.element.addEventListener("click", function (e) {
  1068. def.headerClick(e, self.getComponent());
  1069. });
  1070. }
  1071. if (typeof def.headerDblClick == "function") {
  1072. self.element.addEventListener("dblclick", function (e) {
  1073. def.headerDblClick(e, self.getComponent());
  1074. });
  1075. }
  1076. if (typeof def.headerContext == "function") {
  1077. self.element.addEventListener("contextmenu", function (e) {
  1078. def.headerContext(e, self.getComponent());
  1079. });
  1080. }
  1081. //setup header tap event bindings
  1082. if (typeof def.headerTap == "function") {
  1083. tap = false;
  1084. self.element.addEventListener("touchstart", function (e) {
  1085. tap = true;
  1086. }, { passive: true });
  1087. self.element.addEventListener("touchend", function (e) {
  1088. if (tap) {
  1089. def.headerTap(e, self.getComponent());
  1090. }
  1091. tap = false;
  1092. });
  1093. }
  1094. if (typeof def.headerDblTap == "function") {
  1095. dblTap = null;
  1096. self.element.addEventListener("touchend", function (e) {
  1097. if (dblTap) {
  1098. clearTimeout(dblTap);
  1099. dblTap = null;
  1100. def.headerDblTap(e, self.getComponent());
  1101. } else {
  1102. dblTap = setTimeout(function () {
  1103. clearTimeout(dblTap);
  1104. dblTap = null;
  1105. }, 300);
  1106. }
  1107. });
  1108. }
  1109. if (typeof def.headerTapHold == "function") {
  1110. tapHold = null;
  1111. self.element.addEventListener("touchstart", function (e) {
  1112. clearTimeout(tapHold);
  1113. tapHold = setTimeout(function () {
  1114. clearTimeout(tapHold);
  1115. tapHold = null;
  1116. tap = false;
  1117. def.headerTapHold(e, self.getComponent());
  1118. }, 1000);
  1119. }, { passive: true });
  1120. self.element.addEventListener("touchend", function (e) {
  1121. clearTimeout(tapHold);
  1122. tapHold = null;
  1123. });
  1124. }
  1125. //store column cell click event bindings
  1126. if (typeof def.cellClick == "function") {
  1127. self.cellEvents.cellClick = def.cellClick;
  1128. }
  1129. if (typeof def.cellDblClick == "function") {
  1130. self.cellEvents.cellDblClick = def.cellDblClick;
  1131. }
  1132. if (typeof def.cellContext == "function") {
  1133. self.cellEvents.cellContext = def.cellContext;
  1134. }
  1135. //store column mouse event bindings
  1136. if (typeof def.cellMouseEnter == "function") {
  1137. self.cellEvents.cellMouseEnter = def.cellMouseEnter;
  1138. }
  1139. if (typeof def.cellMouseLeave == "function") {
  1140. self.cellEvents.cellMouseLeave = def.cellMouseLeave;
  1141. }
  1142. if (typeof def.cellMouseOver == "function") {
  1143. self.cellEvents.cellMouseOver = def.cellMouseOver;
  1144. }
  1145. if (typeof def.cellMouseOut == "function") {
  1146. self.cellEvents.cellMouseOut = def.cellMouseOut;
  1147. }
  1148. if (typeof def.cellMouseMove == "function") {
  1149. self.cellEvents.cellMouseMove = def.cellMouseMove;
  1150. }
  1151. //setup column cell tap event bindings
  1152. if (typeof def.cellTap == "function") {
  1153. self.cellEvents.cellTap = def.cellTap;
  1154. }
  1155. if (typeof def.cellDblTap == "function") {
  1156. self.cellEvents.cellDblTap = def.cellDblTap;
  1157. }
  1158. if (typeof def.cellTapHold == "function") {
  1159. self.cellEvents.cellTapHold = def.cellTapHold;
  1160. }
  1161. //setup column cell edit callbacks
  1162. if (typeof def.cellEdited == "function") {
  1163. self.cellEvents.cellEdited = def.cellEdited;
  1164. }
  1165. if (typeof def.cellEditing == "function") {
  1166. self.cellEvents.cellEditing = def.cellEditing;
  1167. }
  1168. if (typeof def.cellEditCancelled == "function") {
  1169. self.cellEvents.cellEditCancelled = def.cellEditCancelled;
  1170. }
  1171. };
  1172. //build header element for header
  1173. Column.prototype._buildColumnHeader = function () {
  1174. var _this6 = this;
  1175. var def = this.definition,
  1176. table = this.table,
  1177. sortable;
  1178. //set column sorter
  1179. if (table.modExists("sort")) {
  1180. table.modules.sort.initializeColumn(this, this.titleHolderElement);
  1181. }
  1182. //set column header context menu
  1183. if ((def.headerContextMenu || def.headerClickMenu || def.headerMenu) && table.modExists("menu")) {
  1184. table.modules.menu.initializeColumnHeader(this);
  1185. }
  1186. //set column formatter
  1187. if (table.modExists("format")) {
  1188. table.modules.format.initializeColumn(this);
  1189. }
  1190. //set column editor
  1191. if (typeof def.editor != "undefined" && table.modExists("edit")) {
  1192. table.modules.edit.initializeColumn(this);
  1193. }
  1194. //set colum validator
  1195. if (typeof def.validator != "undefined" && table.modExists("validate")) {
  1196. table.modules.validate.initializeColumn(this);
  1197. }
  1198. //set column mutator
  1199. if (table.modExists("mutator")) {
  1200. table.modules.mutator.initializeColumn(this);
  1201. }
  1202. //set column accessor
  1203. if (table.modExists("accessor")) {
  1204. table.modules.accessor.initializeColumn(this);
  1205. }
  1206. //set respoviveLayout
  1207. if (_typeof(table.options.responsiveLayout) && table.modExists("responsiveLayout")) {
  1208. table.modules.responsiveLayout.initializeColumn(this);
  1209. }
  1210. //set column visibility
  1211. if (typeof def.visible != "undefined") {
  1212. if (def.visible) {
  1213. this.show(true);
  1214. } else {
  1215. this.hide(true);
  1216. }
  1217. }
  1218. //asign additional css classes to column header
  1219. if (def.cssClass) {
  1220. var classeNames = def.cssClass.split(" ");
  1221. classeNames.forEach(function (className) {
  1222. _this6.element.classList.add(className);
  1223. });
  1224. }
  1225. if (def.field) {
  1226. this.element.setAttribute("tabulator-field", def.field);
  1227. }
  1228. //set min width if present
  1229. this.setMinWidth(typeof def.minWidth == "undefined" ? this.table.options.columnMinWidth : parseInt(def.minWidth));
  1230. this.reinitializeWidth();
  1231. //set tooltip if present
  1232. this.tooltip = this.definition.tooltip || this.definition.tooltip === false ? this.definition.tooltip : this.table.options.tooltips;
  1233. //set orizontal text alignment
  1234. this.hozAlign = typeof this.definition.hozAlign == "undefined" ? this.table.options.cellHozAlign : this.definition.hozAlign;
  1235. this.vertAlign = typeof this.definition.vertAlign == "undefined" ? this.table.options.cellVertAlign : this.definition.vertAlign;
  1236. this.titleElement.style.textAlign = this.definition.headerHozAlign || this.table.options.headerHozAlign;
  1237. };
  1238. Column.prototype._buildColumnHeaderContent = function () {
  1239. var def = this.definition,
  1240. table = this.table;
  1241. var contentElement = document.createElement("div");
  1242. contentElement.classList.add("tabulator-col-content");
  1243. this.titleHolderElement = document.createElement("div");
  1244. this.titleHolderElement.classList.add("tabulator-col-title-holder");
  1245. contentElement.appendChild(this.titleHolderElement);
  1246. this.titleElement = this._buildColumnHeaderTitle();
  1247. this.titleHolderElement.appendChild(this.titleElement);
  1248. return contentElement;
  1249. };
  1250. //build title element of column
  1251. Column.prototype._buildColumnHeaderTitle = function () {
  1252. var self = this,
  1253. def = self.definition,
  1254. table = self.table,
  1255. title;
  1256. var titleHolderElement = document.createElement("div");
  1257. titleHolderElement.classList.add("tabulator-col-title");
  1258. if (def.editableTitle) {
  1259. var titleElement = document.createElement("input");
  1260. titleElement.classList.add("tabulator-title-editor");
  1261. titleElement.addEventListener("click", function (e) {
  1262. e.stopPropagation();
  1263. titleElement.focus();
  1264. });
  1265. titleElement.addEventListener("change", function () {
  1266. def.title = titleElement.value;
  1267. table.options.columnTitleChanged.call(self.table, self.getComponent());
  1268. });
  1269. titleHolderElement.appendChild(titleElement);
  1270. if (def.field) {
  1271. table.modules.localize.bind("columns|" + def.field, function (text) {
  1272. titleElement.value = text || def.title || "&nbsp;";
  1273. });
  1274. } else {
  1275. titleElement.value = def.title || "&nbsp;";
  1276. }
  1277. } else {
  1278. if (def.field) {
  1279. table.modules.localize.bind("columns|" + def.field, function (text) {
  1280. self._formatColumnHeaderTitle(titleHolderElement, text || def.title || "&nbsp;");
  1281. });
  1282. } else {
  1283. self._formatColumnHeaderTitle(titleHolderElement, def.title || "&nbsp;");
  1284. }
  1285. }
  1286. return titleHolderElement;
  1287. };
  1288. Column.prototype._formatColumnHeaderTitle = function (el, title) {
  1289. var _this7 = this;
  1290. var formatter, contents, params, mockCell, onRendered;
  1291. if (this.definition.titleFormatter && this.table.modExists("format")) {
  1292. formatter = this.table.modules.format.getFormatter(this.definition.titleFormatter);
  1293. onRendered = function onRendered(callback) {
  1294. _this7.titleFormatterRendered = callback;
  1295. };
  1296. mockCell = {
  1297. getValue: function getValue() {
  1298. return title;
  1299. },
  1300. getElement: function getElement() {
  1301. return el;
  1302. }
  1303. };
  1304. params = this.definition.titleFormatterParams || {};
  1305. params = typeof params === "function" ? params() : params;
  1306. contents = formatter.call(this.table.modules.format, mockCell, params, onRendered);
  1307. switch (typeof contents === 'undefined' ? 'undefined' : _typeof(contents)) {
  1308. case "object":
  1309. if (contents instanceof Node) {
  1310. el.appendChild(contents);
  1311. } else {
  1312. el.innerHTML = "";
  1313. 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);
  1314. }
  1315. break;
  1316. case "undefined":
  1317. case "null":
  1318. el.innerHTML = "";
  1319. break;
  1320. default:
  1321. el.innerHTML = contents;
  1322. }
  1323. } else {
  1324. el.innerHTML = title;
  1325. }
  1326. };
  1327. //build header element for column group
  1328. Column.prototype._buildGroupHeader = function () {
  1329. var _this8 = this;
  1330. this.element.classList.add("tabulator-col-group");
  1331. this.element.setAttribute("role", "columngroup");
  1332. this.element.setAttribute("aria-title", this.definition.title);
  1333. //asign additional css classes to column header
  1334. if (this.definition.cssClass) {
  1335. var classeNames = this.definition.cssClass.split(" ");
  1336. classeNames.forEach(function (className) {
  1337. _this8.element.classList.add(className);
  1338. });
  1339. }
  1340. //set column header context menu
  1341. if ((this.definition.headerContextMenu || this.definition.headerMenu) && this.table.modExists("menu")) {
  1342. this.table.modules.menu.initializeColumnHeader(this);
  1343. }
  1344. this.element.appendChild(this.groupElement);
  1345. };
  1346. //flat field lookup
  1347. Column.prototype._getFlatData = function (data) {
  1348. return data[this.field];
  1349. };
  1350. //nested field lookup
  1351. Column.prototype._getNestedData = function (data) {
  1352. var dataObj = data,
  1353. structure = this.fieldStructure,
  1354. length = structure.length,
  1355. output;
  1356. for (var _i = 0; _i < length; _i++) {
  1357. dataObj = dataObj[structure[_i]];
  1358. output = dataObj;
  1359. if (!dataObj) {
  1360. break;
  1361. }
  1362. }
  1363. return output;
  1364. };
  1365. //flat field set
  1366. Column.prototype._setFlatData = function (data, value) {
  1367. if (this.field) {
  1368. data[this.field] = value;
  1369. }
  1370. };
  1371. //nested field set
  1372. Column.prototype._setNestedData = function (data, value) {
  1373. var dataObj = data,
  1374. structure = this.fieldStructure,
  1375. length = structure.length;
  1376. for (var _i2 = 0; _i2 < length; _i2++) {
  1377. if (_i2 == length - 1) {
  1378. dataObj[structure[_i2]] = value;
  1379. } else {
  1380. if (!dataObj[structure[_i2]]) {
  1381. if (typeof value !== "undefined") {
  1382. dataObj[structure[_i2]] = {};
  1383. } else {
  1384. break;
  1385. }
  1386. }
  1387. dataObj = dataObj[structure[_i2]];
  1388. }
  1389. }
  1390. };
  1391. //attach column to this group
  1392. Column.prototype.attachColumn = function (column) {
  1393. var self = this;
  1394. if (self.groupElement) {
  1395. self.columns.push(column);
  1396. self.groupElement.appendChild(column.getElement());
  1397. } else {
  1398. console.warn("Column Warning - Column being attached to another column instead of column group");
  1399. }
  1400. };
  1401. //vertically align header in column
  1402. Column.prototype.verticalAlign = function (alignment, height) {
  1403. //calculate height of column header and group holder element
  1404. var parentHeight = this.parent.isGroup ? this.parent.getGroupElement().clientHeight : height || this.parent.getHeadersElement().clientHeight;
  1405. // var parentHeight = this.parent.isGroup ? this.parent.getGroupElement().clientHeight : this.parent.getHeadersElement().clientHeight;
  1406. this.element.style.height = parentHeight + "px";
  1407. if (this.isGroup) {
  1408. this.groupElement.style.minHeight = parentHeight - this.contentElement.offsetHeight + "px";
  1409. }
  1410. //vertically align cell contents
  1411. if (!this.isGroup && alignment !== "top") {
  1412. if (alignment === "bottom") {
  1413. this.element.style.paddingTop = this.element.clientHeight - this.contentElement.offsetHeight + "px";
  1414. } else {
  1415. this.element.style.paddingTop = (this.element.clientHeight - this.contentElement.offsetHeight) / 2 + "px";
  1416. }
  1417. }
  1418. this.columns.forEach(function (column) {
  1419. column.verticalAlign(alignment);
  1420. });
  1421. };
  1422. //clear vertical alignmenet
  1423. Column.prototype.clearVerticalAlign = function () {
  1424. this.element.style.paddingTop = "";
  1425. this.element.style.height = "";
  1426. this.element.style.minHeight = "";
  1427. this.groupElement.style.minHeight = "";
  1428. this.columns.forEach(function (column) {
  1429. column.clearVerticalAlign();
  1430. });
  1431. };
  1432. Column.prototype.bindModuleColumns = function () {
  1433. //check if rownum formatter is being used on a column
  1434. if (this.definition.formatter == "rownum") {
  1435. this.table.rowManager.rowNumColumn = this;
  1436. }
  1437. };
  1438. //// Retreive Column Information ////
  1439. //return column header element
  1440. Column.prototype.getElement = function () {
  1441. return this.element;
  1442. };
  1443. //return colunm group element
  1444. Column.prototype.getGroupElement = function () {
  1445. return this.groupElement;
  1446. };
  1447. //return field name
  1448. Column.prototype.getField = function () {
  1449. return this.field;
  1450. };
  1451. //return the first column in a group
  1452. Column.prototype.getFirstColumn = function () {
  1453. if (!this.isGroup) {
  1454. return this;
  1455. } else {
  1456. if (this.columns.length) {
  1457. return this.columns[0].getFirstColumn();
  1458. } else {
  1459. return false;
  1460. }
  1461. }
  1462. };
  1463. //return the last column in a group
  1464. Column.prototype.getLastColumn = function () {
  1465. if (!this.isGroup) {
  1466. return this;
  1467. } else {
  1468. if (this.columns.length) {
  1469. return this.columns[this.columns.length - 1].getLastColumn();
  1470. } else {
  1471. return false;
  1472. }
  1473. }
  1474. };
  1475. //return all columns in a group
  1476. Column.prototype.getColumns = function () {
  1477. return this.columns;
  1478. };
  1479. //return all columns in a group
  1480. Column.prototype.getCells = function () {
  1481. return this.cells;
  1482. };
  1483. //retreive the top column in a group of columns
  1484. Column.prototype.getTopColumn = function () {
  1485. if (this.parent.isGroup) {
  1486. return this.parent.getTopColumn();
  1487. } else {
  1488. return this;
  1489. }
  1490. };
  1491. //return column definition object
  1492. Column.prototype.getDefinition = function (updateBranches) {
  1493. var colDefs = [];
  1494. if (this.isGroup && updateBranches) {
  1495. this.columns.forEach(function (column) {
  1496. colDefs.push(column.getDefinition(true));
  1497. });
  1498. this.definition.columns = colDefs;
  1499. }
  1500. return this.definition;
  1501. };
  1502. //////////////////// Actions ////////////////////
  1503. Column.prototype.checkColumnVisibility = function () {
  1504. var visible = false;
  1505. this.columns.forEach(function (column) {
  1506. if (column.visible) {
  1507. visible = true;
  1508. }
  1509. });
  1510. if (visible) {
  1511. this.show();
  1512. this.parent.table.options.columnVisibilityChanged.call(this.table, this.getComponent(), false);
  1513. } else {
  1514. this.hide();
  1515. }
  1516. };
  1517. //show column
  1518. Column.prototype.show = function (silent, responsiveToggle) {
  1519. if (!this.visible) {
  1520. this.visible = true;
  1521. this.element.style.display = "";
  1522. if (this.parent.isGroup) {
  1523. this.parent.checkColumnVisibility();
  1524. }
  1525. this.cells.forEach(function (cell) {
  1526. cell.show();
  1527. });
  1528. if (!this.isGroup && this.width === null) {
  1529. this.reinitializeWidth();
  1530. }
  1531. this.table.columnManager._verticalAlignHeaders();
  1532. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.columns) {
  1533. this.table.modules.persistence.save("columns");
  1534. }
  1535. if (!responsiveToggle && this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  1536. this.table.modules.responsiveLayout.updateColumnVisibility(this, this.visible);
  1537. }
  1538. if (!silent) {
  1539. this.table.options.columnVisibilityChanged.call(this.table, this.getComponent(), true);
  1540. }
  1541. if (this.parent.isGroup) {
  1542. this.parent.matchChildWidths();
  1543. }
  1544. }
  1545. };
  1546. //hide column
  1547. Column.prototype.hide = function (silent, responsiveToggle) {
  1548. if (this.visible) {
  1549. this.visible = false;
  1550. this.element.style.display = "none";
  1551. this.table.columnManager._verticalAlignHeaders();
  1552. if (this.parent.isGroup) {
  1553. this.parent.checkColumnVisibility();
  1554. }
  1555. this.cells.forEach(function (cell) {
  1556. cell.hide();
  1557. });
  1558. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.columns) {
  1559. this.table.modules.persistence.save("columns");
  1560. }
  1561. if (!responsiveToggle && this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  1562. this.table.modules.responsiveLayout.updateColumnVisibility(this, this.visible);
  1563. }
  1564. if (!silent) {
  1565. this.table.options.columnVisibilityChanged.call(this.table, this.getComponent(), false);
  1566. }
  1567. if (this.parent.isGroup) {
  1568. this.parent.matchChildWidths();
  1569. }
  1570. }
  1571. };
  1572. Column.prototype.matchChildWidths = function () {
  1573. var childWidth = 0;
  1574. if (this.contentElement && this.columns.length) {
  1575. this.columns.forEach(function (column) {
  1576. if (column.visible) {
  1577. childWidth += column.getWidth();
  1578. }
  1579. });
  1580. this.contentElement.style.maxWidth = childWidth - 1 + "px";
  1581. if (this.parent.isGroup) {
  1582. this.parent.matchChildWidths();
  1583. }
  1584. }
  1585. };
  1586. Column.prototype.setWidth = function (width) {
  1587. this.widthFixed = true;
  1588. this.setWidthActual(width);
  1589. };
  1590. Column.prototype.setWidthActual = function (width) {
  1591. if (isNaN(width)) {
  1592. width = Math.floor(this.table.element.clientWidth / 100 * parseInt(width));
  1593. }
  1594. width = Math.max(this.minWidth, width);
  1595. this.width = width;
  1596. this.widthStyled = width ? width + "px" : "";
  1597. this.element.style.width = this.widthStyled;
  1598. if (!this.isGroup) {
  1599. this.cells.forEach(function (cell) {
  1600. cell.setWidth();
  1601. });
  1602. }
  1603. if (this.parent.isGroup) {
  1604. this.parent.matchChildWidths();
  1605. }
  1606. //set resizable handles
  1607. if (this.table.modExists("frozenColumns")) {
  1608. this.table.modules.frozenColumns.layout();
  1609. }
  1610. };
  1611. Column.prototype.checkCellHeights = function () {
  1612. var rows = [];
  1613. this.cells.forEach(function (cell) {
  1614. if (cell.row.heightInitialized) {
  1615. if (cell.row.getElement().offsetParent !== null) {
  1616. rows.push(cell.row);
  1617. cell.row.clearCellHeight();
  1618. } else {
  1619. cell.row.heightInitialized = false;
  1620. }
  1621. }
  1622. });
  1623. rows.forEach(function (row) {
  1624. row.calcHeight();
  1625. });
  1626. rows.forEach(function (row) {
  1627. row.setCellHeight();
  1628. });
  1629. };
  1630. Column.prototype.getWidth = function () {
  1631. var width = 0;
  1632. if (this.isGroup) {
  1633. this.columns.forEach(function (column) {
  1634. if (column.visible) {
  1635. width += column.getWidth();
  1636. }
  1637. });
  1638. } else {
  1639. width = this.width;
  1640. }
  1641. return width;
  1642. };
  1643. Column.prototype.getHeight = function () {
  1644. return this.element.offsetHeight;
  1645. };
  1646. Column.prototype.setMinWidth = function (minWidth) {
  1647. this.minWidth = minWidth;
  1648. this.minWidthStyled = minWidth ? minWidth + "px" : "";
  1649. this.element.style.minWidth = this.minWidthStyled;
  1650. this.cells.forEach(function (cell) {
  1651. cell.setMinWidth();
  1652. });
  1653. };
  1654. Column.prototype.delete = function () {
  1655. var _this9 = this;
  1656. return new Promise(function (resolve, reject) {
  1657. if (_this9.isGroup) {
  1658. _this9.columns.forEach(function (column) {
  1659. column.delete();
  1660. });
  1661. }
  1662. //cancel edit if column is currently being edited
  1663. if (_this9.table.modExists("edit")) {
  1664. if (_this9.table.modules.edit.currentCell.column === _this9) {
  1665. _this9.table.modules.edit.cancelEdit();
  1666. }
  1667. }
  1668. var cellCount = _this9.cells.length;
  1669. for (var _i3 = 0; _i3 < cellCount; _i3++) {
  1670. _this9.cells[0].delete();
  1671. }
  1672. if (_this9.element.parentNode) {
  1673. _this9.element.parentNode.removeChild(_this9.element);
  1674. }
  1675. _this9.element = false;
  1676. _this9.contentElement = false;
  1677. _this9.titleElement = false;
  1678. _this9.groupElement = false;
  1679. _this9.table.columnManager.deregisterColumn(_this9);
  1680. if (_this9.table.options.virtualDomHoz) {
  1681. _this9.table.vdomHoz.reinitialize(true);
  1682. }
  1683. resolve();
  1684. });
  1685. };
  1686. Column.prototype.columnRendered = function () {
  1687. if (this.titleFormatterRendered) {
  1688. this.titleFormatterRendered();
  1689. }
  1690. };
  1691. Column.prototype.validate = function () {
  1692. var invalid = [];
  1693. this.cells.forEach(function (cell) {
  1694. if (!cell.validate()) {
  1695. invalid.push(cell.getComponent());
  1696. }
  1697. });
  1698. return invalid.length ? invalid : true;
  1699. };
  1700. //////////////// Cell Management /////////////////
  1701. //generate cell for this column
  1702. Column.prototype.generateCell = function (row) {
  1703. var self = this;
  1704. var cell = new Cell(self, row);
  1705. this.cells.push(cell);
  1706. return cell;
  1707. };
  1708. Column.prototype.nextColumn = function () {
  1709. var index = this.table.columnManager.findColumnIndex(this);
  1710. return index > -1 ? this._nextVisibleColumn(index + 1) : false;
  1711. };
  1712. Column.prototype._nextVisibleColumn = function (index) {
  1713. var column = this.table.columnManager.getColumnByIndex(index);
  1714. return !column || column.visible ? column : this._nextVisibleColumn(index + 1);
  1715. };
  1716. Column.prototype.prevColumn = function () {
  1717. var index = this.table.columnManager.findColumnIndex(this);
  1718. return index > -1 ? this._prevVisibleColumn(index - 1) : false;
  1719. };
  1720. Column.prototype._prevVisibleColumn = function (index) {
  1721. var column = this.table.columnManager.getColumnByIndex(index);
  1722. return !column || column.visible ? column : this._prevVisibleColumn(index - 1);
  1723. };
  1724. Column.prototype.reinitializeWidth = function (force) {
  1725. this.widthFixed = false;
  1726. //set width if present
  1727. if (typeof this.definition.width !== "undefined" && !force) {
  1728. this.setWidth(this.definition.width);
  1729. }
  1730. //hide header filters to prevent them altering column width
  1731. if (this.table.modExists("filter")) {
  1732. this.table.modules.filter.hideHeaderFilterElements();
  1733. }
  1734. this.fitToData();
  1735. //show header filters again after layout is complete
  1736. if (this.table.modExists("filter")) {
  1737. this.table.modules.filter.showHeaderFilterElements();
  1738. }
  1739. };
  1740. //set column width to maximum cell width
  1741. Column.prototype.fitToData = function () {
  1742. var self = this;
  1743. if (!this.widthFixed) {
  1744. this.element.style.width = "";
  1745. self.cells.forEach(function (cell) {
  1746. cell.clearWidth();
  1747. });
  1748. }
  1749. var maxWidth = this.element.offsetWidth;
  1750. if (!self.width || !this.widthFixed) {
  1751. self.cells.forEach(function (cell) {
  1752. var width = cell.getWidth();
  1753. if (width > maxWidth) {
  1754. maxWidth = width;
  1755. }
  1756. });
  1757. if (maxWidth) {
  1758. self.setWidthActual(maxWidth + 1);
  1759. }
  1760. }
  1761. };
  1762. Column.prototype.updateDefinition = function (updates) {
  1763. var _this10 = this;
  1764. return new Promise(function (resolve, reject) {
  1765. var definition;
  1766. if (!_this10.isGroup) {
  1767. definition = Object.assign({}, _this10.getDefinition());
  1768. definition = Object.assign(definition, updates);
  1769. _this10.table.columnManager.addColumn(definition, false, _this10).then(function (column) {
  1770. if (definition.field == _this10.field) {
  1771. _this10.field = false; //cleair field name to prevent deletion of duplicate column from arrays
  1772. }
  1773. _this10.delete().then(function () {
  1774. resolve(column.getComponent());
  1775. }).catch(function (err) {
  1776. reject(err);
  1777. });
  1778. }).catch(function (err) {
  1779. reject(err);
  1780. });
  1781. } else {
  1782. console.warn("Column Update Error - The updateDefinition function is only available on columns, not column groups");
  1783. reject("Column Update Error - The updateDefinition function is only available on columns, not column groups");
  1784. }
  1785. });
  1786. };
  1787. Column.prototype.deleteCell = function (cell) {
  1788. var index = this.cells.indexOf(cell);
  1789. if (index > -1) {
  1790. this.cells.splice(index, 1);
  1791. }
  1792. };
  1793. 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", "headerHozAlign", "editableTitle", "titleFormatter", "titleFormatterParams", "headerFilter", "headerFilterPlaceholder", "headerFilterParams", "headerFilterEmptyCheck", "headerFilterFunc", "headerFilterFuncParams", "headerFilterLiveFilter", "print", "headerContextMenu", "headerMenu", "contextMenu",
  1794. // "headerClickMenu",
  1795. "clickMenu", "formatterPrint", "formatterPrintParams", "formatterClipboard", "formatterClipboardParams", "formatterHtmlOutput", "formatterHtmlOutputParams", "titlePrint", "titleClipboard", "titleHtmlOutput", "titleDownload"];
  1796. //////////////// Event Bindings /////////////////
  1797. //////////////// Object Generation /////////////////
  1798. Column.prototype.getComponent = function () {
  1799. if (!this.component) {
  1800. this.component = new ColumnComponent(this);
  1801. }
  1802. return this.component;
  1803. };
  1804. var RowManager = function RowManager(table) {
  1805. this.table = table;
  1806. this.element = this.createHolderElement(); //containing element
  1807. this.tableElement = this.createTableElement(); //table element
  1808. this.heightFixer = this.createTableElement(); //table element
  1809. this.columnManager = null; //hold column manager object
  1810. this.height = 0; //hold height of table element
  1811. this.firstRender = false; //handle first render
  1812. this.renderMode = "virtual"; //current rendering mode
  1813. this.fixedHeight = false; //current rendering mode
  1814. this.rows = []; //hold row data objects
  1815. this.activeRows = []; //rows currently available to on display in the table
  1816. this.activeRowsCount = 0; //count of active rows
  1817. this.displayRows = []; //rows currently on display in the table
  1818. this.displayRowsCount = 0; //count of display rows
  1819. this.scrollTop = 0;
  1820. this.scrollLeft = 0;
  1821. this.vDomRowHeight = 20; //approximation of row heights for padding
  1822. this.vDomTop = 0; //hold position for first rendered row in the virtual DOM
  1823. this.vDomBottom = 0; //hold possition for last rendered row in the virtual DOM
  1824. this.vDomScrollPosTop = 0; //last scroll position of the vDom top;
  1825. this.vDomScrollPosBottom = 0; //last scroll position of the vDom bottom;
  1826. this.vDomTopPad = 0; //hold value of padding for top of virtual DOM
  1827. this.vDomBottomPad = 0; //hold value of padding for bottom of virtual DOM
  1828. this.vDomMaxRenderChain = 90; //the maximum number of dom elements that can be rendered in 1 go
  1829. this.vDomWindowBuffer = 0; //window row buffer before removing elements, to smooth scrolling
  1830. this.vDomWindowMinTotalRows = 20; //minimum number of rows to be generated in virtual dom (prevent buffering issues on tables with tall rows)
  1831. this.vDomWindowMinMarginRows = 5; //minimum number of rows to be generated in virtual dom margin
  1832. this.vDomTopNewRows = []; //rows to normalize after appending to optimize render speed
  1833. this.vDomBottomNewRows = []; //rows to normalize after appending to optimize render speed
  1834. this.rowNumColumn = false; //hold column component for row number column
  1835. this.redrawBlock = false; //prevent redraws to allow multiple data manipulations becore continuing
  1836. this.redrawBlockRestoreConfig = false; //store latest redraw function calls for when redraw is needed
  1837. this.redrawBlockRederInPosition = false; //store latest redraw function calls for when redraw is needed
  1838. };
  1839. //////////////// Setup Functions /////////////////
  1840. RowManager.prototype.createHolderElement = function () {
  1841. var el = document.createElement("div");
  1842. el.classList.add("tabulator-tableHolder");
  1843. el.setAttribute("tabindex", 0);
  1844. return el;
  1845. };
  1846. RowManager.prototype.createTableElement = function () {
  1847. var el = document.createElement("div");
  1848. el.classList.add("tabulator-table");
  1849. return el;
  1850. };
  1851. //return containing element
  1852. RowManager.prototype.getElement = function () {
  1853. return this.element;
  1854. };
  1855. //return table element
  1856. RowManager.prototype.getTableElement = function () {
  1857. return this.tableElement;
  1858. };
  1859. //return position of row in table
  1860. RowManager.prototype.getRowPosition = function (row, active) {
  1861. if (active) {
  1862. return this.activeRows.indexOf(row);
  1863. } else {
  1864. return this.rows.indexOf(row);
  1865. }
  1866. };
  1867. //link to column manager
  1868. RowManager.prototype.setColumnManager = function (manager) {
  1869. this.columnManager = manager;
  1870. };
  1871. RowManager.prototype.initialize = function () {
  1872. var self = this;
  1873. self.setRenderMode();
  1874. //initialize manager
  1875. self.element.appendChild(self.tableElement);
  1876. self.firstRender = true;
  1877. //scroll header along with table body
  1878. self.element.addEventListener("scroll", function () {
  1879. var left = self.element.scrollLeft;
  1880. //handle horizontal scrolling
  1881. if (self.scrollLeft != left) {
  1882. self.columnManager.scrollHorizontal(left);
  1883. if (self.table.options.groupBy) {
  1884. self.table.modules.groupRows.scrollHeaders(left);
  1885. }
  1886. if (self.table.modExists("columnCalcs")) {
  1887. self.table.modules.columnCalcs.scrollHorizontal(left);
  1888. }
  1889. self.table.options.scrollHorizontal(left);
  1890. }
  1891. self.scrollLeft = left;
  1892. });
  1893. //handle virtual dom scrolling
  1894. if (this.renderMode === "virtual") {
  1895. self.element.addEventListener("scroll", function () {
  1896. var top = self.element.scrollTop;
  1897. var dir = self.scrollTop > top;
  1898. //handle verical scrolling
  1899. if (self.scrollTop != top) {
  1900. self.scrollTop = top;
  1901. self.scrollVertical(dir);
  1902. if (self.table.options.ajaxProgressiveLoad == "scroll") {
  1903. self.table.modules.ajax.nextPage(self.element.scrollHeight - self.element.clientHeight - top);
  1904. }
  1905. self.table.options.scrollVertical(top);
  1906. } else {
  1907. self.scrollTop = top;
  1908. }
  1909. });
  1910. }
  1911. };
  1912. ////////////////// Row Manipulation //////////////////
  1913. RowManager.prototype.findRow = function (subject) {
  1914. var self = this;
  1915. if ((typeof subject === 'undefined' ? 'undefined' : _typeof(subject)) == "object") {
  1916. if (subject instanceof Row) {
  1917. //subject is row element
  1918. return subject;
  1919. } else if (subject instanceof RowComponent) {
  1920. //subject is public row component
  1921. return subject._getSelf() || false;
  1922. } else if (typeof HTMLElement !== "undefined" && subject instanceof HTMLElement) {
  1923. //subject is a HTML element of the row
  1924. var match = self.rows.find(function (row) {
  1925. return row.element === subject;
  1926. });
  1927. return match || false;
  1928. }
  1929. } else if (typeof subject == "undefined" || subject === null) {
  1930. return false;
  1931. } else {
  1932. //subject should be treated as the index of the row
  1933. var _match = self.rows.find(function (row) {
  1934. return row.data[self.table.options.index] == subject;
  1935. });
  1936. return _match || false;
  1937. }
  1938. //catch all for any other type of input
  1939. return false;
  1940. };
  1941. RowManager.prototype.getRowFromDataObject = function (data) {
  1942. var match = this.rows.find(function (row) {
  1943. return row.data === data;
  1944. });
  1945. return match || false;
  1946. };
  1947. RowManager.prototype.getRowFromPosition = function (position, active) {
  1948. if (active) {
  1949. return this.activeRows[position];
  1950. } else {
  1951. return this.rows[position];
  1952. }
  1953. };
  1954. RowManager.prototype.scrollToRow = function (row, position, ifVisible) {
  1955. var _this11 = this;
  1956. var rowIndex = this.getDisplayRows().indexOf(row),
  1957. rowEl = row.getElement(),
  1958. rowTop,
  1959. offset = 0;
  1960. return new Promise(function (resolve, reject) {
  1961. if (rowIndex > -1) {
  1962. if (typeof position === "undefined") {
  1963. position = _this11.table.options.scrollToRowPosition;
  1964. }
  1965. if (typeof ifVisible === "undefined") {
  1966. ifVisible = _this11.table.options.scrollToRowIfVisible;
  1967. }
  1968. if (position === "nearest") {
  1969. switch (_this11.renderMode) {
  1970. case "classic":
  1971. rowTop = Tabulator.prototype.helpers.elOffset(rowEl).top;
  1972. position = Math.abs(_this11.element.scrollTop - rowTop) > Math.abs(_this11.element.scrollTop + _this11.element.clientHeight - rowTop) ? "bottom" : "top";
  1973. break;
  1974. case "virtual":
  1975. position = Math.abs(_this11.vDomTop - rowIndex) > Math.abs(_this11.vDomBottom - rowIndex) ? "bottom" : "top";
  1976. break;
  1977. }
  1978. }
  1979. //check row visibility
  1980. if (!ifVisible) {
  1981. if (Tabulator.prototype.helpers.elVisible(rowEl)) {
  1982. offset = Tabulator.prototype.helpers.elOffset(rowEl).top - Tabulator.prototype.helpers.elOffset(_this11.element).top;
  1983. if (offset > 0 && offset < _this11.element.clientHeight - rowEl.offsetHeight) {
  1984. return false;
  1985. }
  1986. }
  1987. }
  1988. //scroll to row
  1989. switch (_this11.renderMode) {
  1990. case "classic":
  1991. _this11.element.scrollTop = Tabulator.prototype.helpers.elOffset(rowEl).top - Tabulator.prototype.helpers.elOffset(_this11.element).top + _this11.element.scrollTop;
  1992. break;
  1993. case "virtual":
  1994. _this11._virtualRenderFill(rowIndex, true);
  1995. break;
  1996. }
  1997. //align to correct position
  1998. switch (position) {
  1999. case "middle":
  2000. case "center":
  2001. if (_this11.element.scrollHeight - _this11.element.scrollTop == _this11.element.clientHeight) {
  2002. _this11.element.scrollTop = _this11.element.scrollTop + (rowEl.offsetTop - _this11.element.scrollTop) - (_this11.element.scrollHeight - rowEl.offsetTop) / 2;
  2003. } else {
  2004. _this11.element.scrollTop = _this11.element.scrollTop - _this11.element.clientHeight / 2;
  2005. }
  2006. break;
  2007. case "bottom":
  2008. if (_this11.element.scrollHeight - _this11.element.scrollTop == _this11.element.clientHeight) {
  2009. _this11.element.scrollTop = _this11.element.scrollTop - (_this11.element.scrollHeight - rowEl.offsetTop) + rowEl.offsetHeight;
  2010. } else {
  2011. _this11.element.scrollTop = _this11.element.scrollTop - _this11.element.clientHeight + rowEl.offsetHeight;
  2012. }
  2013. break;
  2014. }
  2015. resolve();
  2016. } else {
  2017. console.warn("Scroll Error - Row not visible");
  2018. reject("Scroll Error - Row not visible");
  2019. }
  2020. });
  2021. };
  2022. ////////////////// Data Handling //////////////////
  2023. RowManager.prototype.setData = function (data, renderInPosition, columnsChanged) {
  2024. var _this12 = this;
  2025. var self = this;
  2026. return new Promise(function (resolve, reject) {
  2027. if (renderInPosition && _this12.getDisplayRows().length) {
  2028. if (self.table.options.pagination) {
  2029. self._setDataActual(data, true);
  2030. } else {
  2031. _this12.reRenderInPosition(function () {
  2032. self._setDataActual(data);
  2033. });
  2034. }
  2035. } else {
  2036. if (_this12.table.options.autoColumns && columnsChanged) {
  2037. _this12.table.columnManager.generateColumnsFromRowData(data);
  2038. }
  2039. _this12.resetScroll();
  2040. _this12._setDataActual(data);
  2041. }
  2042. resolve();
  2043. });
  2044. };
  2045. RowManager.prototype._setDataActual = function (data, renderInPosition) {
  2046. var self = this;
  2047. self.table.options.dataLoading.call(this.table, data);
  2048. this._wipeElements();
  2049. if (this.table.options.history && this.table.modExists("history")) {
  2050. this.table.modules.history.clear();
  2051. }
  2052. if (Array.isArray(data)) {
  2053. if (this.table.modExists("selectRow")) {
  2054. this.table.modules.selectRow.clearSelectionData();
  2055. }
  2056. if (this.table.options.reactiveData && this.table.modExists("reactiveData", true)) {
  2057. this.table.modules.reactiveData.watchData(data);
  2058. }
  2059. data.forEach(function (def, i) {
  2060. if (def && (typeof def === 'undefined' ? 'undefined' : _typeof(def)) === "object") {
  2061. var row = new Row(def, self);
  2062. self.rows.push(row);
  2063. } else {
  2064. console.warn("Data Loading Warning - Invalid row data detected and ignored, expecting object but received:", def);
  2065. }
  2066. });
  2067. self.refreshActiveData(false, false, renderInPosition);
  2068. self.table.options.dataLoaded.call(this.table, data);
  2069. } else {
  2070. 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);
  2071. }
  2072. };
  2073. RowManager.prototype._wipeElements = function () {
  2074. this.rows.forEach(function (row) {
  2075. row.wipe();
  2076. });
  2077. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  2078. this.table.modules.groupRows.wipe();
  2079. }
  2080. this.rows = [];
  2081. this.activeRows = [];
  2082. this.activeRowsCount = 0;
  2083. this.displayRows = [];
  2084. this.displayRowsCount = 0;
  2085. this.adjustTableSize();
  2086. };
  2087. RowManager.prototype.deleteRow = function (row, blockRedraw) {
  2088. var allIndex = this.rows.indexOf(row),
  2089. activeIndex = this.activeRows.indexOf(row);
  2090. if (activeIndex > -1) {
  2091. this.activeRows.splice(activeIndex, 1);
  2092. }
  2093. if (allIndex > -1) {
  2094. this.rows.splice(allIndex, 1);
  2095. }
  2096. this.setActiveRows(this.activeRows);
  2097. this.displayRowIterator(function (rows) {
  2098. var displayIndex = rows.indexOf(row);
  2099. if (displayIndex > -1) {
  2100. rows.splice(displayIndex, 1);
  2101. }
  2102. });
  2103. if (!blockRedraw) {
  2104. this.reRenderInPosition();
  2105. }
  2106. this.regenerateRowNumbers();
  2107. this.table.options.rowDeleted.call(this.table, row.getComponent());
  2108. if (this.table.options.dataChanged) {
  2109. this.table.options.dataChanged.call(this.table, this.getData());
  2110. }
  2111. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  2112. this.table.modules.groupRows.updateGroupRows(true);
  2113. } else if (this.table.options.pagination && this.table.modExists("page")) {
  2114. this.refreshActiveData(false, false, true);
  2115. } else {
  2116. if (this.table.options.pagination && this.table.modExists("page")) {
  2117. this.refreshActiveData("page");
  2118. }
  2119. }
  2120. };
  2121. RowManager.prototype.addRow = function (data, pos, index, blockRedraw) {
  2122. var row = this.addRowActual(data, pos, index, blockRedraw);
  2123. if (this.table.options.history && this.table.modExists("history")) {
  2124. this.table.modules.history.action("rowAdd", row, { data: data, pos: pos, index: index });
  2125. }
  2126. return row;
  2127. };
  2128. //add multiple rows
  2129. RowManager.prototype.addRows = function (data, pos, index) {
  2130. var _this13 = this;
  2131. var self = this,
  2132. length = 0,
  2133. rows = [];
  2134. return new Promise(function (resolve, reject) {
  2135. pos = _this13.findAddRowPos(pos);
  2136. if (!Array.isArray(data)) {
  2137. data = [data];
  2138. }
  2139. length = data.length - 1;
  2140. if (typeof index == "undefined" && pos || typeof index !== "undefined" && !pos) {
  2141. data.reverse();
  2142. }
  2143. data.forEach(function (item, i) {
  2144. var row = self.addRow(item, pos, index, true);
  2145. rows.push(row);
  2146. });
  2147. if (_this13.table.options.groupBy && _this13.table.modExists("groupRows")) {
  2148. _this13.table.modules.groupRows.updateGroupRows(true);
  2149. } else if (_this13.table.options.pagination && _this13.table.modExists("page")) {
  2150. _this13.refreshActiveData(false, false, true);
  2151. } else {
  2152. _this13.reRenderInPosition();
  2153. }
  2154. //recalc column calculations if present
  2155. if (_this13.table.modExists("columnCalcs")) {
  2156. _this13.table.modules.columnCalcs.recalc(_this13.table.rowManager.activeRows);
  2157. }
  2158. _this13.regenerateRowNumbers();
  2159. resolve(rows);
  2160. });
  2161. };
  2162. RowManager.prototype.findAddRowPos = function (pos) {
  2163. if (typeof pos === "undefined") {
  2164. pos = this.table.options.addRowPos;
  2165. }
  2166. if (pos === "pos") {
  2167. pos = true;
  2168. }
  2169. if (pos === "bottom") {
  2170. pos = false;
  2171. }
  2172. return pos;
  2173. };
  2174. RowManager.prototype.addRowActual = function (data, pos, index, blockRedraw) {
  2175. var row = data instanceof Row ? data : new Row(data || {}, this),
  2176. top = this.findAddRowPos(pos),
  2177. allIndex = -1,
  2178. activeIndex,
  2179. dispRows;
  2180. if (!index && this.table.options.pagination && this.table.options.paginationAddRow == "page") {
  2181. dispRows = this.getDisplayRows();
  2182. if (top) {
  2183. if (dispRows.length) {
  2184. index = dispRows[0];
  2185. } else {
  2186. if (this.activeRows.length) {
  2187. index = this.activeRows[this.activeRows.length - 1];
  2188. top = false;
  2189. }
  2190. }
  2191. } else {
  2192. if (dispRows.length) {
  2193. index = dispRows[dispRows.length - 1];
  2194. top = dispRows.length < this.table.modules.page.getPageSize() ? false : true;
  2195. }
  2196. }
  2197. }
  2198. if (typeof index !== "undefined") {
  2199. index = this.findRow(index);
  2200. }
  2201. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  2202. this.table.modules.groupRows.assignRowToGroup(row);
  2203. var groupRows = row.getGroup().rows;
  2204. if (groupRows.length > 1) {
  2205. if (!index || index && groupRows.indexOf(index) == -1) {
  2206. if (top) {
  2207. if (groupRows[0] !== row) {
  2208. index = groupRows[0];
  2209. this._moveRowInArray(row.getGroup().rows, row, index, !top);
  2210. }
  2211. } else {
  2212. if (groupRows[groupRows.length - 1] !== row) {
  2213. index = groupRows[groupRows.length - 1];
  2214. this._moveRowInArray(row.getGroup().rows, row, index, !top);
  2215. }
  2216. }
  2217. } else {
  2218. this._moveRowInArray(row.getGroup().rows, row, index, !top);
  2219. }
  2220. }
  2221. }
  2222. if (index) {
  2223. allIndex = this.rows.indexOf(index);
  2224. }
  2225. if (index && allIndex > -1) {
  2226. activeIndex = this.activeRows.indexOf(index);
  2227. this.displayRowIterator(function (rows) {
  2228. var displayIndex = rows.indexOf(index);
  2229. if (displayIndex > -1) {
  2230. rows.splice(top ? displayIndex : displayIndex + 1, 0, row);
  2231. }
  2232. });
  2233. if (activeIndex > -1) {
  2234. this.activeRows.splice(top ? activeIndex : activeIndex + 1, 0, row);
  2235. }
  2236. this.rows.splice(top ? allIndex : allIndex + 1, 0, row);
  2237. } else {
  2238. if (top) {
  2239. this.displayRowIterator(function (rows) {
  2240. rows.unshift(row);
  2241. });
  2242. this.activeRows.unshift(row);
  2243. this.rows.unshift(row);
  2244. } else {
  2245. this.displayRowIterator(function (rows) {
  2246. rows.push(row);
  2247. });
  2248. this.activeRows.push(row);
  2249. this.rows.push(row);
  2250. }
  2251. }
  2252. this.setActiveRows(this.activeRows);
  2253. this.table.options.rowAdded.call(this.table, row.getComponent());
  2254. if (this.table.options.dataChanged) {
  2255. this.table.options.dataChanged.call(this.table, this.getData());
  2256. }
  2257. if (!blockRedraw) {
  2258. this.reRenderInPosition();
  2259. }
  2260. return row;
  2261. };
  2262. RowManager.prototype.moveRow = function (from, to, after) {
  2263. if (this.table.options.history && this.table.modExists("history")) {
  2264. this.table.modules.history.action("rowMove", from, { posFrom: this.getRowPosition(from), posTo: this.getRowPosition(to), to: to, after: after });
  2265. }
  2266. this.moveRowActual(from, to, after);
  2267. this.regenerateRowNumbers();
  2268. this.table.options.rowMoved.call(this.table, from.getComponent());
  2269. };
  2270. RowManager.prototype.moveRowActual = function (from, to, after) {
  2271. var _this14 = this;
  2272. this._moveRowInArray(this.rows, from, to, after);
  2273. this._moveRowInArray(this.activeRows, from, to, after);
  2274. this.displayRowIterator(function (rows) {
  2275. _this14._moveRowInArray(rows, from, to, after);
  2276. });
  2277. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  2278. if (!after && to instanceof Group) {
  2279. to = this.table.rowManager.prevDisplayRow(from) || to;
  2280. }
  2281. var toGroup = to.getGroup();
  2282. var fromGroup = from.getGroup();
  2283. if (toGroup === fromGroup) {
  2284. this._moveRowInArray(toGroup.rows, from, to, after);
  2285. } else {
  2286. if (fromGroup) {
  2287. fromGroup.removeRow(from);
  2288. }
  2289. toGroup.insertRow(from, to, after);
  2290. }
  2291. }
  2292. };
  2293. RowManager.prototype._moveRowInArray = function (rows, from, to, after) {
  2294. var fromIndex, toIndex, start, end;
  2295. if (from !== to) {
  2296. fromIndex = rows.indexOf(from);
  2297. if (fromIndex > -1) {
  2298. rows.splice(fromIndex, 1);
  2299. toIndex = rows.indexOf(to);
  2300. if (toIndex > -1) {
  2301. if (after) {
  2302. rows.splice(toIndex + 1, 0, from);
  2303. } else {
  2304. rows.splice(toIndex, 0, from);
  2305. }
  2306. } else {
  2307. rows.splice(fromIndex, 0, from);
  2308. }
  2309. }
  2310. //restyle rows
  2311. if (rows === this.getDisplayRows()) {
  2312. start = fromIndex < toIndex ? fromIndex : toIndex;
  2313. end = toIndex > fromIndex ? toIndex : fromIndex + 1;
  2314. for (var _i4 = start; _i4 <= end; _i4++) {
  2315. if (rows[_i4]) {
  2316. this.styleRow(rows[_i4], _i4);
  2317. }
  2318. }
  2319. }
  2320. }
  2321. };
  2322. RowManager.prototype.clearData = function () {
  2323. this.setData([]);
  2324. };
  2325. RowManager.prototype.getRowIndex = function (row) {
  2326. return this.findRowIndex(row, this.rows);
  2327. };
  2328. RowManager.prototype.getDisplayRowIndex = function (row) {
  2329. var index = this.getDisplayRows().indexOf(row);
  2330. return index > -1 ? index : false;
  2331. };
  2332. RowManager.prototype.nextDisplayRow = function (row, rowOnly) {
  2333. var index = this.getDisplayRowIndex(row),
  2334. nextRow = false;
  2335. if (index !== false && index < this.displayRowsCount - 1) {
  2336. nextRow = this.getDisplayRows()[index + 1];
  2337. }
  2338. if (nextRow && (!(nextRow instanceof Row) || nextRow.type != "row")) {
  2339. return this.nextDisplayRow(nextRow, rowOnly);
  2340. }
  2341. return nextRow;
  2342. };
  2343. RowManager.prototype.prevDisplayRow = function (row, rowOnly) {
  2344. var index = this.getDisplayRowIndex(row),
  2345. prevRow = false;
  2346. if (index) {
  2347. prevRow = this.getDisplayRows()[index - 1];
  2348. }
  2349. if (rowOnly && prevRow && (!(prevRow instanceof Row) || prevRow.type != "row")) {
  2350. return this.prevDisplayRow(prevRow, rowOnly);
  2351. }
  2352. return prevRow;
  2353. };
  2354. RowManager.prototype.findRowIndex = function (row, list) {
  2355. var rowIndex;
  2356. row = this.findRow(row);
  2357. if (row) {
  2358. rowIndex = list.indexOf(row);
  2359. if (rowIndex > -1) {
  2360. return rowIndex;
  2361. }
  2362. }
  2363. return false;
  2364. };
  2365. RowManager.prototype.getData = function (active, transform) {
  2366. var output = [],
  2367. rows = this.getRows(active);
  2368. rows.forEach(function (row) {
  2369. if (row.type == "row") {
  2370. output.push(row.getData(transform || "data"));
  2371. }
  2372. });
  2373. return output;
  2374. };
  2375. RowManager.prototype.getComponents = function (active) {
  2376. var output = [],
  2377. rows = this.getRows(active);
  2378. rows.forEach(function (row) {
  2379. output.push(row.getComponent());
  2380. });
  2381. return output;
  2382. };
  2383. RowManager.prototype.getDataCount = function (active) {
  2384. var rows = this.getRows(active);
  2385. return rows.length;
  2386. };
  2387. RowManager.prototype._genRemoteRequest = function () {
  2388. var _this15 = this;
  2389. var table = this.table,
  2390. options = table.options,
  2391. params = {};
  2392. if (table.modExists("page")) {
  2393. //set sort data if defined
  2394. if (options.ajaxSorting) {
  2395. var sorters = this.table.modules.sort.getSort();
  2396. sorters.forEach(function (item) {
  2397. delete item.column;
  2398. });
  2399. params[this.table.modules.page.paginationDataSentNames.sorters] = sorters;
  2400. }
  2401. //set filter data if defined
  2402. if (options.ajaxFiltering) {
  2403. var filters = this.table.modules.filter.getFilters(true, true);
  2404. params[this.table.modules.page.paginationDataSentNames.filters] = filters;
  2405. }
  2406. this.table.modules.ajax.setParams(params, true);
  2407. }
  2408. table.modules.ajax.sendRequest().then(function (data) {
  2409. _this15._setDataActual(data, true);
  2410. }).catch(function (e) {});
  2411. };
  2412. //choose the path to refresh data after a filter update
  2413. RowManager.prototype.filterRefresh = function () {
  2414. var table = this.table,
  2415. options = table.options,
  2416. left = this.scrollLeft;
  2417. if (options.ajaxFiltering) {
  2418. if (options.pagination == "remote" && table.modExists("page")) {
  2419. table.modules.page.reset(true);
  2420. table.modules.page.setPage(1).then(function () {}).catch(function () {});
  2421. } else if (options.ajaxProgressiveLoad) {
  2422. table.modules.ajax.loadData().then(function () {}).catch(function () {});
  2423. } else {
  2424. //assume data is url, make ajax call to url to get data
  2425. this._genRemoteRequest();
  2426. }
  2427. } else {
  2428. this.refreshActiveData("filter");
  2429. }
  2430. this.scrollHorizontal(left);
  2431. };
  2432. //choose the path to refresh data after a sorter update
  2433. RowManager.prototype.sorterRefresh = function (loadOrignalData) {
  2434. var table = this.table,
  2435. options = this.table.options,
  2436. left = this.scrollLeft;
  2437. if (options.ajaxSorting) {
  2438. if ((options.pagination == "remote" || options.progressiveLoad) && table.modExists("page")) {
  2439. table.modules.page.reset(true);
  2440. table.modules.page.setPage(1).then(function () {}).catch(function () {});
  2441. } else if (options.ajaxProgressiveLoad) {
  2442. table.modules.ajax.loadData().then(function () {}).catch(function () {});
  2443. } else {
  2444. //assume data is url, make ajax call to url to get data
  2445. this._genRemoteRequest();
  2446. }
  2447. } else {
  2448. this.refreshActiveData(loadOrignalData ? "filter" : "sort");
  2449. }
  2450. this.scrollHorizontal(left);
  2451. };
  2452. RowManager.prototype.scrollHorizontal = function (left) {
  2453. this.scrollLeft = left;
  2454. this.element.scrollLeft = left;
  2455. if (this.table.options.groupBy) {
  2456. this.table.modules.groupRows.scrollHeaders(left);
  2457. }
  2458. if (this.table.modExists("columnCalcs")) {
  2459. this.table.modules.columnCalcs.scrollHorizontal(left);
  2460. }
  2461. };
  2462. //set active data set
  2463. RowManager.prototype.refreshActiveData = function (stage, skipStage, renderInPosition) {
  2464. var self = this,
  2465. table = this.table,
  2466. cascadeOrder = ["all", "filter", "sort", "display", "freeze", "group", "tree", "page"],
  2467. displayIndex;
  2468. if (this.redrawBlock) {
  2469. if (!this.redrawBlockRestoreConfig || cascadeOrder.indexOf(stage) < cascadeOrder.indexOf(this.redrawBlockRestoreConfig.stage)) {
  2470. this.redrawBlockRestoreConfig = {
  2471. stage: stage,
  2472. skipStage: skipStage,
  2473. renderInPosition: renderInPosition
  2474. };
  2475. }
  2476. return;
  2477. } else {
  2478. if (self.table.modExists("edit")) {
  2479. self.table.modules.edit.cancelEdit();
  2480. }
  2481. if (!stage) {
  2482. stage = "all";
  2483. }
  2484. if (table.options.selectable && !table.options.selectablePersistence && table.modExists("selectRow")) {
  2485. table.modules.selectRow.deselectRows();
  2486. }
  2487. //cascade through data refresh stages
  2488. switch (stage) {
  2489. case "all":
  2490. case "filter":
  2491. if (!skipStage) {
  2492. if (table.modExists("filter")) {
  2493. self.setActiveRows(table.modules.filter.filter(self.rows));
  2494. } else {
  2495. self.setActiveRows(self.rows.slice(0));
  2496. }
  2497. } else {
  2498. skipStage = false;
  2499. }
  2500. case "sort":
  2501. if (!skipStage) {
  2502. if (table.modExists("sort")) {
  2503. table.modules.sort.sort(this.activeRows);
  2504. }
  2505. } else {
  2506. skipStage = false;
  2507. }
  2508. //regenerate row numbers for row number formatter if in use
  2509. this.regenerateRowNumbers();
  2510. //generic stage to allow for pipeline trigger after the data manipulation stage
  2511. case "display":
  2512. this.resetDisplayRows();
  2513. case "freeze":
  2514. if (!skipStage) {
  2515. if (this.table.modExists("frozenRows")) {
  2516. if (table.modules.frozenRows.isFrozen()) {
  2517. if (!table.modules.frozenRows.getDisplayIndex()) {
  2518. table.modules.frozenRows.setDisplayIndex(this.getNextDisplayIndex());
  2519. }
  2520. displayIndex = table.modules.frozenRows.getDisplayIndex();
  2521. displayIndex = self.setDisplayRows(table.modules.frozenRows.getRows(this.getDisplayRows(displayIndex - 1)), displayIndex);
  2522. if (displayIndex !== true) {
  2523. table.modules.frozenRows.setDisplayIndex(displayIndex);
  2524. }
  2525. }
  2526. }
  2527. } else {
  2528. skipStage = false;
  2529. }
  2530. case "group":
  2531. if (!skipStage) {
  2532. if (table.options.groupBy && table.modExists("groupRows")) {
  2533. if (!table.modules.groupRows.getDisplayIndex()) {
  2534. table.modules.groupRows.setDisplayIndex(this.getNextDisplayIndex());
  2535. }
  2536. displayIndex = table.modules.groupRows.getDisplayIndex();
  2537. displayIndex = self.setDisplayRows(table.modules.groupRows.getRows(this.getDisplayRows(displayIndex - 1)), displayIndex);
  2538. if (displayIndex !== true) {
  2539. table.modules.groupRows.setDisplayIndex(displayIndex);
  2540. }
  2541. }
  2542. } else {
  2543. skipStage = false;
  2544. }
  2545. case "tree":
  2546. if (!skipStage) {
  2547. if (table.options.dataTree && table.modExists("dataTree")) {
  2548. if (!table.modules.dataTree.getDisplayIndex()) {
  2549. table.modules.dataTree.setDisplayIndex(this.getNextDisplayIndex());
  2550. }
  2551. displayIndex = table.modules.dataTree.getDisplayIndex();
  2552. displayIndex = self.setDisplayRows(table.modules.dataTree.getRows(this.getDisplayRows(displayIndex - 1)), displayIndex);
  2553. if (displayIndex !== true) {
  2554. table.modules.dataTree.setDisplayIndex(displayIndex);
  2555. }
  2556. }
  2557. } else {
  2558. skipStage = false;
  2559. }
  2560. if (table.options.pagination && table.modExists("page") && !renderInPosition) {
  2561. if (table.modules.page.getMode() == "local") {
  2562. table.modules.page.reset();
  2563. }
  2564. }
  2565. case "page":
  2566. if (!skipStage) {
  2567. if (table.options.pagination && table.modExists("page")) {
  2568. if (!table.modules.page.getDisplayIndex()) {
  2569. table.modules.page.setDisplayIndex(this.getNextDisplayIndex());
  2570. }
  2571. displayIndex = table.modules.page.getDisplayIndex();
  2572. if (table.modules.page.getMode() == "local") {
  2573. table.modules.page.setMaxRows(this.getDisplayRows(displayIndex - 1).length);
  2574. }
  2575. displayIndex = self.setDisplayRows(table.modules.page.getRows(this.getDisplayRows(displayIndex - 1)), displayIndex);
  2576. if (displayIndex !== true) {
  2577. table.modules.page.setDisplayIndex(displayIndex);
  2578. }
  2579. }
  2580. } else {
  2581. skipStage = false;
  2582. }
  2583. }
  2584. if (Tabulator.prototype.helpers.elVisible(self.element)) {
  2585. if (renderInPosition) {
  2586. self.reRenderInPosition();
  2587. } else {
  2588. if (stage === "all" && this.table.options.virtualDomHoz) {
  2589. this.table.vdomHoz.dataChange();
  2590. }
  2591. self.renderTable();
  2592. if (table.options.layoutColumnsOnNewData) {
  2593. self.table.columnManager.redraw(true);
  2594. }
  2595. }
  2596. }
  2597. if (table.modExists("columnCalcs")) {
  2598. table.modules.columnCalcs.recalc(this.activeRows);
  2599. }
  2600. }
  2601. };
  2602. //regenerate row numbers for row number formatter if in use
  2603. RowManager.prototype.regenerateRowNumbers = function () {
  2604. var _this16 = this;
  2605. if (this.rowNumColumn) {
  2606. this.activeRows.forEach(function (row) {
  2607. var cell = row.getCell(_this16.rowNumColumn);
  2608. if (cell) {
  2609. cell._generateContents();
  2610. }
  2611. });
  2612. }
  2613. };
  2614. RowManager.prototype.setActiveRows = function (activeRows) {
  2615. this.activeRows = activeRows;
  2616. this.activeRowsCount = this.activeRows.length;
  2617. };
  2618. //reset display rows array
  2619. RowManager.prototype.resetDisplayRows = function () {
  2620. this.displayRows = [];
  2621. this.displayRows.push(this.activeRows.slice(0));
  2622. this.displayRowsCount = this.displayRows[0].length;
  2623. if (this.table.modExists("frozenRows")) {
  2624. this.table.modules.frozenRows.setDisplayIndex(0);
  2625. }
  2626. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  2627. this.table.modules.groupRows.setDisplayIndex(0);
  2628. }
  2629. if (this.table.options.pagination && this.table.modExists("page")) {
  2630. this.table.modules.page.setDisplayIndex(0);
  2631. }
  2632. };
  2633. RowManager.prototype.getNextDisplayIndex = function () {
  2634. return this.displayRows.length;
  2635. };
  2636. //set display row pipeline data
  2637. RowManager.prototype.setDisplayRows = function (displayRows, index) {
  2638. var output = true;
  2639. if (index && typeof this.displayRows[index] != "undefined") {
  2640. this.displayRows[index] = displayRows;
  2641. output = true;
  2642. } else {
  2643. this.displayRows.push(displayRows);
  2644. output = index = this.displayRows.length - 1;
  2645. }
  2646. if (index == this.displayRows.length - 1) {
  2647. this.displayRowsCount = this.displayRows[this.displayRows.length - 1].length;
  2648. }
  2649. return output;
  2650. };
  2651. RowManager.prototype.getDisplayRows = function (index) {
  2652. if (typeof index == "undefined") {
  2653. return this.displayRows.length ? this.displayRows[this.displayRows.length - 1] : [];
  2654. } else {
  2655. return this.displayRows[index] || [];
  2656. }
  2657. };
  2658. RowManager.prototype.getVisibleRows = function (viewable) {
  2659. var topEdge = this.element.scrollTop,
  2660. bottomEdge = this.element.clientHeight + topEdge,
  2661. topFound = false,
  2662. topRow = 0,
  2663. bottomRow = 0,
  2664. rows = this.getDisplayRows();
  2665. if (viewable) {
  2666. this.getDisplayRows();
  2667. for (var i = this.vDomTop; i <= this.vDomBottom; i++) {
  2668. if (rows[i]) {
  2669. if (!topFound) {
  2670. if (topEdge - rows[i].getElement().offsetTop >= 0) {
  2671. topRow = i;
  2672. } else {
  2673. topFound = true;
  2674. if (bottomEdge - rows[i].getElement().offsetTop >= 0) {
  2675. bottomRow = i;
  2676. } else {
  2677. break;
  2678. }
  2679. }
  2680. } else {
  2681. if (bottomEdge - rows[i].getElement().offsetTop >= 0) {
  2682. bottomRow = i;
  2683. } else {
  2684. break;
  2685. }
  2686. }
  2687. }
  2688. }
  2689. } else {
  2690. topRow = this.vDomTop;
  2691. bottomRow = this.vDomBottom;
  2692. }
  2693. return rows.slice(topRow, bottomRow + 1);
  2694. };
  2695. //repeat action accross display rows
  2696. RowManager.prototype.displayRowIterator = function (callback) {
  2697. this.displayRows.forEach(callback);
  2698. this.displayRowsCount = this.displayRows[this.displayRows.length - 1].length;
  2699. };
  2700. //return only actual rows (not group headers etc)
  2701. RowManager.prototype.getRows = function (active) {
  2702. var rows;
  2703. switch (active) {
  2704. case "active":
  2705. rows = this.activeRows;
  2706. break;
  2707. case "display":
  2708. rows = this.table.rowManager.getDisplayRows();
  2709. break;
  2710. case "visible":
  2711. rows = this.getVisibleRows(true);
  2712. break;
  2713. case "selected":
  2714. rows = this.table.modules.selectRow.selectedRows;
  2715. break;
  2716. default:
  2717. rows = this.rows;
  2718. }
  2719. return rows;
  2720. };
  2721. ///////////////// Table Rendering /////////////////
  2722. //trigger rerender of table in current position
  2723. RowManager.prototype.reRenderInPosition = function (callback) {
  2724. if (this.getRenderMode() == "virtual") {
  2725. if (this.redrawBlock) {
  2726. if (callback) {
  2727. callback();
  2728. } else {
  2729. this.redrawBlockRederInPosition = true;
  2730. }
  2731. } else {
  2732. var scrollTop = this.element.scrollTop;
  2733. var topRow = false;
  2734. var topOffset = false;
  2735. var left = this.scrollLeft;
  2736. var rows = this.getDisplayRows();
  2737. for (var i = this.vDomTop; i <= this.vDomBottom; i++) {
  2738. if (rows[i]) {
  2739. var diff = scrollTop - rows[i].getElement().offsetTop;
  2740. if (topOffset === false || Math.abs(diff) < topOffset) {
  2741. topOffset = diff;
  2742. topRow = i;
  2743. } else {
  2744. break;
  2745. }
  2746. }
  2747. }
  2748. if (callback) {
  2749. callback();
  2750. }
  2751. this._virtualRenderFill(topRow === false ? this.displayRowsCount - 1 : topRow, true, topOffset || 0);
  2752. this.scrollHorizontal(left);
  2753. }
  2754. } else {
  2755. this.renderTable();
  2756. if (callback) {
  2757. callback();
  2758. }
  2759. }
  2760. };
  2761. RowManager.prototype.setRenderMode = function () {
  2762. if (this.table.options.virtualDom) {
  2763. this.renderMode = "virtual";
  2764. if (this.table.element.clientHeight || this.table.options.height) {
  2765. this.fixedHeight = true;
  2766. } else {
  2767. this.fixedHeight = false;
  2768. }
  2769. } else {
  2770. this.renderMode = "classic";
  2771. }
  2772. };
  2773. RowManager.prototype.getRenderMode = function () {
  2774. return this.renderMode;
  2775. };
  2776. RowManager.prototype.renderTable = function () {
  2777. this.table.options.renderStarted.call(this.table);
  2778. this.element.scrollTop = 0;
  2779. switch (this.renderMode) {
  2780. case "classic":
  2781. this._simpleRender();
  2782. break;
  2783. case "virtual":
  2784. this._virtualRenderFill();
  2785. break;
  2786. }
  2787. if (this.firstRender) {
  2788. if (this.displayRowsCount) {
  2789. this.firstRender = false;
  2790. this.table.modules.layout.layout();
  2791. } else {
  2792. this.renderEmptyScroll();
  2793. }
  2794. }
  2795. if (this.table.modExists("frozenColumns")) {
  2796. this.table.modules.frozenColumns.layout();
  2797. }
  2798. if (!this.displayRowsCount) {
  2799. if (this.table.options.placeholder) {
  2800. this.table.options.placeholder.setAttribute("tabulator-render-mode", this.renderMode);
  2801. this.getElement().appendChild(this.table.options.placeholder);
  2802. this.table.options.placeholder.style.width = this.table.columnManager.getWidth() + "px";
  2803. }
  2804. }
  2805. this.table.options.renderComplete.call(this.table);
  2806. };
  2807. //simple render on heightless table
  2808. RowManager.prototype._simpleRender = function () {
  2809. this._clearVirtualDom();
  2810. if (this.displayRowsCount) {
  2811. this.checkClassicModeGroupHeaderWidth();
  2812. } else {
  2813. this.renderEmptyScroll();
  2814. }
  2815. };
  2816. RowManager.prototype.checkClassicModeGroupHeaderWidth = function () {
  2817. var self = this,
  2818. element = this.tableElement,
  2819. onlyGroupHeaders = true;
  2820. self.getDisplayRows().forEach(function (row, index) {
  2821. self.styleRow(row, index);
  2822. element.appendChild(row.getElement());
  2823. row.initialize(true);
  2824. if (row.type !== "group") {
  2825. onlyGroupHeaders = false;
  2826. }
  2827. });
  2828. if (onlyGroupHeaders) {
  2829. element.style.minWidth = self.table.columnManager.getWidth() + "px";
  2830. } else {
  2831. element.style.minWidth = "";
  2832. }
  2833. };
  2834. //show scrollbars on empty table div
  2835. RowManager.prototype.renderEmptyScroll = function () {
  2836. if (this.table.options.placeholder) {
  2837. this.tableElement.style.display = "none";
  2838. } else {
  2839. this.tableElement.style.minWidth = this.table.columnManager.getWidth() + "px";
  2840. // this.tableElement.style.minHeight = "1px";
  2841. // this.tableElement.style.visibility = "hidden";
  2842. }
  2843. };
  2844. RowManager.prototype._clearVirtualDom = function () {
  2845. var element = this.tableElement;
  2846. if (this.table.options.placeholder && this.table.options.placeholder.parentNode) {
  2847. this.table.options.placeholder.parentNode.removeChild(this.table.options.placeholder);
  2848. }
  2849. // element.children.detach();
  2850. while (element.firstChild) {
  2851. element.removeChild(element.firstChild);
  2852. }element.style.paddingTop = "";
  2853. element.style.paddingBottom = "";
  2854. element.style.minWidth = "";
  2855. element.style.minHeight = "";
  2856. element.style.display = "";
  2857. element.style.visibility = "";
  2858. this.scrollTop = 0;
  2859. this.scrollLeft = 0;
  2860. this.vDomTop = 0;
  2861. this.vDomBottom = 0;
  2862. this.vDomTopPad = 0;
  2863. this.vDomBottomPad = 0;
  2864. };
  2865. RowManager.prototype.styleRow = function (row, index) {
  2866. var rowEl = row.getElement();
  2867. if (index % 2) {
  2868. rowEl.classList.add("tabulator-row-even");
  2869. rowEl.classList.remove("tabulator-row-odd");
  2870. } else {
  2871. rowEl.classList.add("tabulator-row-odd");
  2872. rowEl.classList.remove("tabulator-row-even");
  2873. }
  2874. };
  2875. //full virtual render
  2876. RowManager.prototype._virtualRenderFill = function (position, forceMove, offset) {
  2877. var self = this,
  2878. element = self.tableElement,
  2879. holder = self.element,
  2880. topPad = 0,
  2881. rowsHeight = 0,
  2882. topPadHeight = 0,
  2883. i = 0,
  2884. onlyGroupHeaders = true,
  2885. rows = self.getDisplayRows();
  2886. position = position || 0;
  2887. offset = offset || 0;
  2888. if (!position) {
  2889. self._clearVirtualDom();
  2890. } else {
  2891. while (element.firstChild) {
  2892. element.removeChild(element.firstChild);
  2893. } //check if position is too close to bottom of table
  2894. var heightOccupied = (self.displayRowsCount - position + 1) * self.vDomRowHeight;
  2895. if (heightOccupied < self.height) {
  2896. position -= Math.ceil((self.height - heightOccupied) / self.vDomRowHeight);
  2897. if (position < 0) {
  2898. position = 0;
  2899. }
  2900. }
  2901. //calculate initial pad
  2902. topPad = Math.min(Math.max(Math.floor(self.vDomWindowBuffer / self.vDomRowHeight), self.vDomWindowMinMarginRows), position);
  2903. position -= topPad;
  2904. }
  2905. if (self.displayRowsCount && Tabulator.prototype.helpers.elVisible(self.element)) {
  2906. self.vDomTop = position;
  2907. self.vDomBottom = position - 1;
  2908. while ((rowsHeight <= self.height + self.vDomWindowBuffer || i < self.vDomWindowMinTotalRows) && self.vDomBottom < self.displayRowsCount - 1) {
  2909. var index = self.vDomBottom + 1,
  2910. row = rows[index],
  2911. rowHeight = 0;
  2912. self.styleRow(row, index);
  2913. element.appendChild(row.getElement());
  2914. row.initialize();
  2915. if (!row.heightInitialized) {
  2916. row.normalizeHeight(true);
  2917. }
  2918. // if(!row.initialized){
  2919. // row.initialize(true);
  2920. // }else{
  2921. // if(!row.heightInitialized){
  2922. // row.normalizeHeight(true);
  2923. // }
  2924. // }
  2925. rowHeight = row.getHeight();
  2926. if (i < topPad) {
  2927. topPadHeight += rowHeight;
  2928. } else {
  2929. rowsHeight += rowHeight;
  2930. }
  2931. if (rowHeight > this.vDomWindowBuffer) {
  2932. this.vDomWindowBuffer = rowHeight * 2;
  2933. }
  2934. if (row.type !== "group") {
  2935. onlyGroupHeaders = false;
  2936. }
  2937. self.vDomBottom++;
  2938. i++;
  2939. }
  2940. if (!position) {
  2941. this.vDomTopPad = 0;
  2942. //adjust rowheight to match average of rendered elements
  2943. self.vDomRowHeight = Math.floor((rowsHeight + topPadHeight) / i);
  2944. self.vDomBottomPad = self.vDomRowHeight * (self.displayRowsCount - self.vDomBottom - 1);
  2945. self.vDomScrollHeight = topPadHeight + rowsHeight + self.vDomBottomPad - self.height;
  2946. } else {
  2947. self.vDomTopPad = !forceMove ? self.scrollTop - topPadHeight : self.vDomRowHeight * this.vDomTop + offset;
  2948. self.vDomBottomPad = self.vDomBottom == self.displayRowsCount - 1 ? 0 : Math.max(self.vDomScrollHeight - self.vDomTopPad - rowsHeight - topPadHeight, 0);
  2949. }
  2950. element.style.paddingTop = self.vDomTopPad + "px";
  2951. element.style.paddingBottom = self.vDomBottomPad + "px";
  2952. if (forceMove) {
  2953. this.scrollTop = self.vDomTopPad + topPadHeight + offset - (this.element.scrollWidth > this.element.clientWidth ? this.element.offsetHeight - this.element.clientHeight : 0);
  2954. }
  2955. this.scrollTop = Math.min(this.scrollTop, this.element.scrollHeight - this.height);
  2956. //adjust for horizontal scrollbar if present (and not at top of table)
  2957. if (this.element.scrollWidth > this.element.offsetWidth && forceMove) {
  2958. this.scrollTop += this.element.offsetHeight - this.element.clientHeight;
  2959. }
  2960. this.vDomScrollPosTop = this.scrollTop;
  2961. this.vDomScrollPosBottom = this.scrollTop;
  2962. holder.scrollTop = this.scrollTop;
  2963. element.style.minWidth = onlyGroupHeaders ? self.table.columnManager.getWidth() + "px" : "";
  2964. if (self.table.options.groupBy) {
  2965. if (self.table.modules.layout.getMode() != "fitDataFill" && self.displayRowsCount == self.table.modules.groupRows.countGroups()) {
  2966. self.tableElement.style.minWidth = self.table.columnManager.getWidth();
  2967. }
  2968. }
  2969. } else {
  2970. this.renderEmptyScroll();
  2971. }
  2972. if (!this.fixedHeight) {
  2973. this.adjustTableSize();
  2974. }
  2975. };
  2976. //handle vertical scrolling
  2977. RowManager.prototype.scrollVertical = function (dir) {
  2978. var topDiff = this.scrollTop - this.vDomScrollPosTop;
  2979. var bottomDiff = this.scrollTop - this.vDomScrollPosBottom;
  2980. var margin = this.vDomWindowBuffer * 2;
  2981. if (-topDiff > margin || bottomDiff > margin) {
  2982. //if big scroll redraw table;
  2983. var left = this.scrollLeft;
  2984. this._virtualRenderFill(Math.floor(this.element.scrollTop / this.element.scrollHeight * this.displayRowsCount));
  2985. this.scrollHorizontal(left);
  2986. } else {
  2987. if (dir) {
  2988. //scrolling up
  2989. if (topDiff < 0) {
  2990. this._addTopRow(-topDiff);
  2991. }
  2992. if (bottomDiff < 0) {
  2993. //hide bottom row if needed
  2994. if (this.vDomScrollHeight - this.scrollTop > this.vDomWindowBuffer) {
  2995. this._removeBottomRow(-bottomDiff);
  2996. } else {
  2997. this.vDomScrollPosBottom = this.scrollTop;
  2998. }
  2999. }
  3000. } else {
  3001. //scrolling down
  3002. if (topDiff >= 0) {
  3003. //hide top row if needed
  3004. if (this.scrollTop > this.vDomWindowBuffer) {
  3005. this._removeTopRow(topDiff);
  3006. } else {
  3007. this.vDomScrollPosTop = this.scrollTop;
  3008. }
  3009. }
  3010. if (bottomDiff >= 0) {
  3011. this._addBottomRow(bottomDiff);
  3012. }
  3013. }
  3014. }
  3015. };
  3016. RowManager.prototype._addTopRow = function (topDiff) {
  3017. var i = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  3018. var table = this.tableElement,
  3019. rows = this.getDisplayRows();
  3020. if (this.vDomTop) {
  3021. var index = this.vDomTop - 1,
  3022. topRow = rows[index],
  3023. topRowHeight = topRow.getHeight() || this.vDomRowHeight;
  3024. //hide top row if needed
  3025. if (topDiff >= topRowHeight) {
  3026. this.styleRow(topRow, index);
  3027. table.insertBefore(topRow.getElement(), table.firstChild);
  3028. if (!topRow.initialized || !topRow.heightInitialized) {
  3029. this.vDomTopNewRows.push(topRow);
  3030. if (!topRow.heightInitialized) {
  3031. topRow.clearCellHeight();
  3032. }
  3033. }
  3034. topRow.initialize();
  3035. this.vDomTopPad -= topRowHeight;
  3036. if (this.vDomTopPad < 0) {
  3037. this.vDomTopPad = index * this.vDomRowHeight;
  3038. }
  3039. if (!index) {
  3040. this.vDomTopPad = 0;
  3041. }
  3042. table.style.paddingTop = this.vDomTopPad + "px";
  3043. this.vDomScrollPosTop -= topRowHeight;
  3044. this.vDomTop--;
  3045. }
  3046. topDiff = -(this.scrollTop - this.vDomScrollPosTop);
  3047. if (topRow.getHeight() > this.vDomWindowBuffer) {
  3048. this.vDomWindowBuffer = topRow.getHeight() * 2;
  3049. }
  3050. if (i < this.vDomMaxRenderChain && this.vDomTop && topDiff >= (rows[this.vDomTop - 1].getHeight() || this.vDomRowHeight)) {
  3051. this._addTopRow(topDiff, i + 1);
  3052. } else {
  3053. this._quickNormalizeRowHeight(this.vDomTopNewRows);
  3054. }
  3055. }
  3056. };
  3057. RowManager.prototype._removeTopRow = function (topDiff) {
  3058. var table = this.tableElement,
  3059. topRow = this.getDisplayRows()[this.vDomTop],
  3060. topRowHeight = topRow.getHeight() || this.vDomRowHeight;
  3061. if (topDiff >= topRowHeight) {
  3062. var rowEl = topRow.getElement();
  3063. rowEl.parentNode.removeChild(rowEl);
  3064. this.vDomTopPad += topRowHeight;
  3065. table.style.paddingTop = this.vDomTopPad + "px";
  3066. this.vDomScrollPosTop += this.vDomTop ? topRowHeight : topRowHeight + this.vDomWindowBuffer;
  3067. this.vDomTop++;
  3068. topDiff = this.scrollTop - this.vDomScrollPosTop;
  3069. this._removeTopRow(topDiff);
  3070. }
  3071. };
  3072. RowManager.prototype._addBottomRow = function (bottomDiff) {
  3073. var i = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  3074. var table = this.tableElement,
  3075. rows = this.getDisplayRows();
  3076. if (this.vDomBottom < this.displayRowsCount - 1) {
  3077. var index = this.vDomBottom + 1,
  3078. bottomRow = rows[index],
  3079. bottomRowHeight = bottomRow.getHeight() || this.vDomRowHeight;
  3080. //hide bottom row if needed
  3081. if (bottomDiff >= bottomRowHeight) {
  3082. this.styleRow(bottomRow, index);
  3083. table.appendChild(bottomRow.getElement());
  3084. if (!bottomRow.initialized || !bottomRow.heightInitialized) {
  3085. this.vDomBottomNewRows.push(bottomRow);
  3086. if (!bottomRow.heightInitialized) {
  3087. bottomRow.clearCellHeight();
  3088. }
  3089. }
  3090. bottomRow.initialize();
  3091. this.vDomBottomPad -= bottomRowHeight;
  3092. if (this.vDomBottomPad < 0 || index == this.displayRowsCount - 1) {
  3093. this.vDomBottomPad = 0;
  3094. }
  3095. table.style.paddingBottom = this.vDomBottomPad + "px";
  3096. this.vDomScrollPosBottom += bottomRowHeight;
  3097. this.vDomBottom++;
  3098. }
  3099. bottomDiff = this.scrollTop - this.vDomScrollPosBottom;
  3100. if (bottomRow.getHeight() > this.vDomWindowBuffer) {
  3101. this.vDomWindowBuffer = bottomRow.getHeight() * 2;
  3102. }
  3103. if (i < this.vDomMaxRenderChain && this.vDomBottom < this.displayRowsCount - 1 && bottomDiff >= (rows[this.vDomBottom + 1].getHeight() || this.vDomRowHeight)) {
  3104. this._addBottomRow(bottomDiff, i + 1);
  3105. } else {
  3106. this._quickNormalizeRowHeight(this.vDomBottomNewRows);
  3107. }
  3108. }
  3109. };
  3110. RowManager.prototype._removeBottomRow = function (bottomDiff) {
  3111. var table = this.tableElement,
  3112. bottomRow = this.getDisplayRows()[this.vDomBottom],
  3113. bottomRowHeight = bottomRow.getHeight() || this.vDomRowHeight;
  3114. if (bottomDiff >= bottomRowHeight) {
  3115. var rowEl = bottomRow.getElement();
  3116. if (rowEl.parentNode) {
  3117. rowEl.parentNode.removeChild(rowEl);
  3118. }
  3119. this.vDomBottomPad += bottomRowHeight;
  3120. if (this.vDomBottomPad < 0) {
  3121. this.vDomBottomPad = 0;
  3122. }
  3123. table.style.paddingBottom = this.vDomBottomPad + "px";
  3124. this.vDomScrollPosBottom -= bottomRowHeight;
  3125. this.vDomBottom--;
  3126. bottomDiff = -(this.scrollTop - this.vDomScrollPosBottom);
  3127. this._removeBottomRow(bottomDiff);
  3128. }
  3129. };
  3130. RowManager.prototype._quickNormalizeRowHeight = function (rows) {
  3131. rows.forEach(function (row) {
  3132. row.calcHeight();
  3133. });
  3134. rows.forEach(function (row) {
  3135. row.setCellHeight();
  3136. });
  3137. rows.length = 0;
  3138. };
  3139. //normalize height of active rows
  3140. RowManager.prototype.normalizeHeight = function () {
  3141. this.activeRows.forEach(function (row) {
  3142. row.normalizeHeight();
  3143. });
  3144. };
  3145. //adjust the height of the table holder to fit in the Tabulator element
  3146. RowManager.prototype.adjustTableSize = function () {
  3147. var initialHeight = this.element.clientHeight,
  3148. modExists;
  3149. if (this.renderMode === "virtual") {
  3150. var otherHeight = Math.floor(this.columnManager.getElement().offsetHeight + (this.table.footerManager && !this.table.footerManager.external ? this.table.footerManager.getElement().offsetHeight : 0));
  3151. if (this.fixedHeight) {
  3152. this.element.style.minHeight = "calc(100% - " + otherHeight + "px)";
  3153. this.element.style.height = "calc(100% - " + otherHeight + "px)";
  3154. this.element.style.maxHeight = "calc(100% - " + otherHeight + "px)";
  3155. } else {
  3156. this.element.style.height = "";
  3157. this.element.style.height = Math.floor(this.table.element.clientHeight) - otherHeight + "px";
  3158. this.element.scrollTop = this.scrollTop;
  3159. }
  3160. this.height = this.element.clientHeight;
  3161. this.vDomWindowBuffer = this.table.options.virtualDomBuffer || this.height;
  3162. //check if the table has changed size when dealing with variable height tables
  3163. if (!this.fixedHeight && Math.floor(initialHeight) != Math.floor(this.element.clientHeight)) {
  3164. modExists = this.table.modExists("resizeTable");
  3165. if (modExists && !this.table.modules.resizeTable.autoResize || !modExists) {
  3166. this.redraw();
  3167. }
  3168. }
  3169. }
  3170. };
  3171. //renitialize all rows
  3172. RowManager.prototype.reinitialize = function () {
  3173. this.rows.forEach(function (row) {
  3174. row.reinitialize(true);
  3175. });
  3176. };
  3177. //prevent table from being redrawn
  3178. RowManager.prototype.blockRedraw = function () {
  3179. this.redrawBlock = true;
  3180. this.redrawBlockRestoreConfig = false;
  3181. };
  3182. //restore table redrawing
  3183. RowManager.prototype.restoreRedraw = function () {
  3184. this.redrawBlock = false;
  3185. if (this.redrawBlockRestoreConfig) {
  3186. this.refreshActiveData(this.redrawBlockRestoreConfig.stage, this.redrawBlockRestoreConfig.skipStage, this.redrawBlockRestoreConfig.renderInPosition);
  3187. this.redrawBlockRestoreConfig = false;
  3188. } else {
  3189. if (this.redrawBlockRederInPosition) {
  3190. this.reRenderInPosition();
  3191. }
  3192. }
  3193. this.redrawBlockRederInPosition = false;
  3194. };
  3195. //redraw table
  3196. RowManager.prototype.redraw = function (force) {
  3197. var pos = 0,
  3198. left = this.scrollLeft;
  3199. this.adjustTableSize();
  3200. this.table.tableWidth = this.table.element.clientWidth;
  3201. if (!force) {
  3202. if (this.renderMode == "classic") {
  3203. if (this.table.options.groupBy) {
  3204. this.refreshActiveData("group", false, false);
  3205. } else {
  3206. this._simpleRender();
  3207. }
  3208. } else {
  3209. this.reRenderInPosition();
  3210. this.scrollHorizontal(left);
  3211. }
  3212. if (!this.displayRowsCount) {
  3213. if (this.table.options.placeholder) {
  3214. this.getElement().appendChild(this.table.options.placeholder);
  3215. }
  3216. }
  3217. } else {
  3218. this.renderTable();
  3219. }
  3220. };
  3221. RowManager.prototype.resetScroll = function () {
  3222. this.element.scrollLeft = 0;
  3223. this.element.scrollTop = 0;
  3224. if (this.table.browser === "ie") {
  3225. var event = document.createEvent("Event");
  3226. event.initEvent("scroll", false, true);
  3227. this.element.dispatchEvent(event);
  3228. } else {
  3229. this.element.dispatchEvent(new Event('scroll'));
  3230. }
  3231. };
  3232. var VDomHoz = function VDomHoz(table) {
  3233. this.table = table;
  3234. this.element = this.table.rowManager.tableElement;
  3235. this.holderEl = this.table.rowManager.element;
  3236. this.leftCol = 0;
  3237. this.rightCol = 0;
  3238. this.scrollLeft = 0;
  3239. this.vDomScrollPosLeft = 0;
  3240. this.vDomScrollPosRight = 0;
  3241. this.vDomPadLeft = 0;
  3242. this.vDomPadRight = 0;
  3243. this.fitDataColAvg = 0;
  3244. this.window = 200; //pixel margin to make column visible before it is shown on screen
  3245. this.initialized = false;
  3246. this.columns = [];
  3247. if (this.compatabilityCheck()) {
  3248. this.initialize();
  3249. }
  3250. };
  3251. VDomHoz.prototype.compatabilityCheck = function () {
  3252. var options = this.table.options,
  3253. frozen = false,
  3254. ok = true;
  3255. if (options.layout == "fitDataTable") {
  3256. console.warn("Horizontal Vitrual DOM is not compatible with fitDataTable layout mode");
  3257. ok = false;
  3258. }
  3259. if (options.responsiveLayout) {
  3260. console.warn("Horizontal Vitrual DOM is not compatible with responsive columns");
  3261. ok = false;
  3262. }
  3263. if (this.table.rtl) {
  3264. console.warn("Horizontal Vitrual DOM is not currently compatible with RTL text direction");
  3265. ok = false;
  3266. }
  3267. // if(options.rowFormatter){
  3268. // console.warn("Horizontal Vitrual DOM is not compatible with row formatters");
  3269. // ok = false;
  3270. // }
  3271. if (options.columns) {
  3272. frozen = options.columns.find(function (col) {
  3273. return col.frozen;
  3274. });
  3275. if (frozen) {
  3276. console.warn("Horizontal Vitrual DOM is not compatible with frozen columns");
  3277. ok = false;
  3278. }
  3279. }
  3280. if (!ok) {
  3281. options.virtualDomHoz = false;
  3282. }
  3283. return ok;
  3284. };
  3285. VDomHoz.prototype.initialize = function () {
  3286. var _this17 = this;
  3287. this.holderEl.addEventListener("scroll", function () {
  3288. var left = _this17.holderEl.scrollLeft;
  3289. if (_this17.scrollLeft != left) {
  3290. _this17.scrollLeft = left;
  3291. _this17.scroll(left - (_this17.vDomScrollPosLeft + _this17.window));
  3292. }
  3293. });
  3294. };
  3295. VDomHoz.prototype.deinitialize = function () {
  3296. this.initialized = false;
  3297. };
  3298. VDomHoz.prototype.clear = function () {
  3299. this.columns = [];
  3300. this.leftCol = -1;
  3301. this.rightCol = 0;
  3302. this.vDomScrollPosLeft = 0;
  3303. this.vDomScrollPosRight = 0;
  3304. this.vDomPadLeft = 0;
  3305. this.vDomPadRight = 0;
  3306. };
  3307. VDomHoz.prototype.dataChange = function () {
  3308. var change = false,
  3309. collsWidth = 0,
  3310. colEnd = 0,
  3311. group,
  3312. row,
  3313. rowEl;
  3314. if (this.table.options.layout === "fitData") {
  3315. this.table.columnManager.columnsByIndex.forEach(function (column) {
  3316. if (!column.definition.width && column.visible) {
  3317. change = true;
  3318. }
  3319. });
  3320. if (change) {
  3321. if (change && this.table.rowManager.getDisplayRows().length) {
  3322. // this.table.vdomHoz.deinitialize();
  3323. this.vDomScrollPosRight = this.scrollLeft + this.holderEl.clientWidth + this.window;
  3324. if (this.table.options.groupBy) {
  3325. group = this.table.modules.groupRows.getGroups(false)[0];
  3326. row = group.getRows(false)[0];
  3327. } else {
  3328. row = this.table.rowManager.getDisplayRows()[0];
  3329. }
  3330. if (row) {
  3331. rowEl = row.getElement();
  3332. row.generateCells();
  3333. this.element.appendChild(rowEl);
  3334. for (var colEnd = 0; colEnd < row.cells.length; colEnd++) {
  3335. var cell = row.cells[colEnd];
  3336. rowEl.appendChild(cell.getElement());
  3337. cell.column.reinitializeWidth();
  3338. collsWidth += cell.column.getWidth();
  3339. if (collsWidth > this.vDomScrollPosRight) {
  3340. break;
  3341. }
  3342. }
  3343. rowEl.parentNode.removeChild(rowEl);
  3344. this.fitDataColAvg = Math.floor(collsWidth / (colEnd + 1));
  3345. for (colEnd; colEnd < this.table.columnManager.columnsByIndex.length; colEnd++) {
  3346. this.table.columnManager.columnsByIndex[colEnd].setWidth(this.fitDataColAvg);
  3347. }
  3348. this.reinitialize(false, true);
  3349. }
  3350. }
  3351. }
  3352. } else {
  3353. if (this.table.options.layout === "fitColumns") {
  3354. this.table.modules.layout.layout();
  3355. this.table.vdomHoz.reinitialize(false, true);
  3356. }
  3357. }
  3358. };
  3359. VDomHoz.prototype.fitDataLayoutOverride = function () {
  3360. for (var _i5 = this.leftCol; _i5 <= this.rightCol; _i5++) {
  3361. this.columns[_i5].reinitializeWidth();
  3362. }
  3363. };
  3364. VDomHoz.prototype.reinitialize = function (update, blockRedraw) {
  3365. var _this18 = this;
  3366. var old = {
  3367. cols: this.columns,
  3368. leftCol: this.leftCol,
  3369. rightCol: this.rightCol
  3370. };
  3371. if (update && !this.initialized) {
  3372. return;
  3373. }
  3374. this.clear();
  3375. this.scrollLeft = this.holderEl.scrollLeft;
  3376. this.vDomScrollPosLeft = this.scrollLeft - this.window;
  3377. this.vDomScrollPosRight = this.scrollLeft + this.holderEl.clientWidth + this.window;
  3378. var colPos = 0;
  3379. this.table.columnManager.columnsByIndex.forEach(function (column) {
  3380. var config = {};
  3381. if (column.visible) {
  3382. var width = column.getWidth();
  3383. config.leftPos = colPos;
  3384. config.rightPos = colPos + width;
  3385. if (colPos + width > _this18.vDomScrollPosLeft && colPos < _this18.vDomScrollPosRight) {
  3386. //column is visible
  3387. if (_this18.leftCol == -1) {
  3388. _this18.leftCol = _this18.columns.length;
  3389. _this18.vDomPadLeft = colPos;
  3390. }
  3391. _this18.rightCol = _this18.columns.length;
  3392. } else {
  3393. // column is hidden
  3394. if (_this18.leftCol !== -1) {
  3395. _this18.vDomPadRight += width;
  3396. }
  3397. }
  3398. _this18.columns.push(column);
  3399. column.modules.vdomHoz = config;
  3400. colPos += width;
  3401. }
  3402. });
  3403. this.element.style.paddingLeft = this.vDomPadLeft + "px";
  3404. this.element.style.paddingRight = this.vDomPadRight + "px";
  3405. this.initialized = true;
  3406. if (!blockRedraw) {
  3407. if (!update || this.reinitChanged(old)) {
  3408. this.renitializeRows();
  3409. }
  3410. }
  3411. this.holderEl.scrollLeft = this.scrollLeft;
  3412. };
  3413. VDomHoz.prototype.reinitChanged = function (old) {
  3414. var _this19 = this;
  3415. var match = true;
  3416. if (old.cols.length !== this.columns.length || old.leftCol !== this.leftCol || old.rightCol !== this.rightCol) {
  3417. return true;
  3418. }
  3419. old.cols.forEach(function (col, i) {
  3420. if (col !== _this19.columns[i]) {
  3421. match = false;
  3422. }
  3423. });
  3424. return !match;
  3425. };
  3426. VDomHoz.prototype.renitializeRows = function () {
  3427. var _this20 = this;
  3428. var rows = this.table.rowManager.getVisibleRows();
  3429. rows.forEach(function (row) {
  3430. _this20.reinitializeRow(row, true);
  3431. });
  3432. };
  3433. VDomHoz.prototype.scroll = function (diff) {
  3434. this.vDomScrollPosLeft += diff;
  3435. this.vDomScrollPosRight += diff;
  3436. if (diff > this.holderEl.clientWidth * .8) {
  3437. this.reinitialize();
  3438. } else {
  3439. if (diff > 0) {
  3440. //scroll right
  3441. this.addColRight();
  3442. this.removeColLeft();
  3443. } else {
  3444. //scroll left
  3445. this.addColLeft();
  3446. this.removeColRight();
  3447. }
  3448. }
  3449. };
  3450. VDomHoz.prototype.colPositionAdjust = function (start, end, diff) {
  3451. for (var _i6 = start; _i6 < end; _i6++) {
  3452. var column = this.columns[_i6];
  3453. column.modules.vdomHoz.leftPos -= diff;
  3454. column.modules.vdomHoz.rightPos -= diff;
  3455. }
  3456. };
  3457. VDomHoz.prototype.addColRight = function () {
  3458. var column = this.columns[this.rightCol + 1],
  3459. rows,
  3460. oldWidth,
  3461. widthDiff;
  3462. if (column && column.modules.vdomHoz.leftPos <= this.vDomScrollPosRight) {
  3463. rows = this.table.rowManager.getVisibleRows();
  3464. rows.forEach(function (row) {
  3465. if (row.type !== "group") {
  3466. var cell = row.getCell(column);
  3467. row.getElement().appendChild(cell.getElement());
  3468. cell.cellRendered();
  3469. }
  3470. });
  3471. if (this.fitDataColAvg) {
  3472. oldWidth = column.getWidth();
  3473. if (oldWidth === this.fitDataColAvg) {
  3474. column.reinitializeWidth();
  3475. widthDiff = oldWidth - column.getWidth();
  3476. if (widthDiff) {
  3477. column.modules.vdomHoz.rightPos -= widthDiff;
  3478. this.colPositionAdjust(this.rightCol + 1, this.columns.length, widthDiff);
  3479. }
  3480. }
  3481. }
  3482. this.rightCol++;
  3483. if (this.rightCol >= this.columns.length - 1) {
  3484. this.vDomPadRight = 0;
  3485. } else {
  3486. this.vDomPadRight -= column.getWidth();
  3487. }
  3488. this.element.style.paddingRight = this.vDomPadRight + "px";
  3489. this.addColRight();
  3490. }
  3491. };
  3492. VDomHoz.prototype.addColLeft = function () {
  3493. var column = this.columns[this.leftCol - 1],
  3494. rows;
  3495. if (column && column.modules.vdomHoz.rightPos >= this.vDomScrollPosLeft) {
  3496. var rows = this.table.rowManager.getVisibleRows();
  3497. rows.forEach(function (row) {
  3498. if (row.type !== "group") {
  3499. var cell = row.getCell(column);
  3500. row.getElement().prepend(cell.getElement());
  3501. cell.cellRendered();
  3502. }
  3503. });
  3504. if (!this.leftCol) {
  3505. this.vDomPadLeft = 0;
  3506. } else {
  3507. this.vDomPadLeft -= column.getWidth();
  3508. }
  3509. this.element.style.paddingLeft = this.vDomPadLeft + "px";
  3510. this.leftCol--;
  3511. this.addColLeft();
  3512. }
  3513. };
  3514. VDomHoz.prototype.removeColRight = function (column) {
  3515. var column = this.columns[this.rightCol],
  3516. rows;
  3517. if (column && column.modules.vdomHoz.leftPos > this.vDomScrollPosRight) {
  3518. rows = this.table.rowManager.getVisibleRows();
  3519. column.modules.vdomHoz.visible = false;
  3520. rows.forEach(function (row) {
  3521. if (row.type !== "group") {
  3522. var cell = row.getCell(column);
  3523. row.getElement().removeChild(cell.getElement());
  3524. }
  3525. });
  3526. this.vDomPadRight += column.getWidth();
  3527. this.element.style.paddingRight = this.vDomPadRight + "px";
  3528. this.rightCol--;
  3529. this.removeColRight();
  3530. }
  3531. };
  3532. VDomHoz.prototype.removeColLeft = function () {
  3533. var column = this.columns[this.leftCol],
  3534. rows;
  3535. if (column && column.modules.vdomHoz.rightPos < this.vDomScrollPosLeft) {
  3536. rows = this.table.rowManager.getVisibleRows();
  3537. rows.forEach(function (row) {
  3538. if (row.type !== "group") {
  3539. var cell = row.getCell(column);
  3540. row.getElement().removeChild(cell.getElement());
  3541. }
  3542. });
  3543. this.vDomPadLeft += column.getWidth();
  3544. this.element.style.paddingLeft = this.vDomPadLeft + "px";
  3545. this.leftCol++;
  3546. this.removeColLeft();
  3547. }
  3548. };
  3549. VDomHoz.prototype.initializeRow = function (row) {
  3550. if (row.type !== "group") {
  3551. row.modules.vdomHoz = {
  3552. leftCol: this.leftCol,
  3553. rightCol: this.rightCol
  3554. };
  3555. for (var _i7 = this.leftCol; _i7 <= this.rightCol; _i7++) {
  3556. var column = this.columns[_i7];
  3557. if (column.visible) {
  3558. var cell = row.getCell(column);
  3559. row.element.appendChild(cell.getElement());
  3560. cell.cellRendered();
  3561. }
  3562. }
  3563. }
  3564. };
  3565. VDomHoz.prototype.reinitializeRow = function (row, force) {
  3566. if (row.type !== "group") {
  3567. if (force || !row.modules.vdomHoz || row.modules.vdomHoz.leftCol !== this.leftCol || row.modules.vdomHoz.rightCol !== this.rightCol) {
  3568. while (row.element.firstChild) {
  3569. row.element.removeChild(row.element.firstChild);
  3570. }this.initializeRow(row);
  3571. }
  3572. }
  3573. };
  3574. //public row object
  3575. var RowComponent = function RowComponent(row) {
  3576. this._row = row;
  3577. };
  3578. RowComponent.prototype.getData = function (transform) {
  3579. return this._row.getData(transform);
  3580. };
  3581. RowComponent.prototype.getElement = function () {
  3582. return this._row.getElement();
  3583. };
  3584. RowComponent.prototype.getCells = function () {
  3585. var cells = [];
  3586. this._row.getCells().forEach(function (cell) {
  3587. cells.push(cell.getComponent());
  3588. });
  3589. return cells;
  3590. };
  3591. RowComponent.prototype.getCell = function (column) {
  3592. var cell = this._row.getCell(column);
  3593. return cell ? cell.getComponent() : false;
  3594. };
  3595. RowComponent.prototype.getIndex = function () {
  3596. return this._row.getData("data")[this._row.table.options.index];
  3597. };
  3598. RowComponent.prototype.getPosition = function (active) {
  3599. return this._row.table.rowManager.getRowPosition(this._row, active);
  3600. };
  3601. RowComponent.prototype.delete = function () {
  3602. return this._row.delete();
  3603. };
  3604. RowComponent.prototype.scrollTo = function () {
  3605. return this._row.table.rowManager.scrollToRow(this._row);
  3606. };
  3607. RowComponent.prototype.pageTo = function () {
  3608. if (this._row.table.modExists("page", true)) {
  3609. return this._row.table.modules.page.setPageToRow(this._row);
  3610. }
  3611. };
  3612. RowComponent.prototype.move = function (to, after) {
  3613. this._row.moveToRow(to, after);
  3614. };
  3615. RowComponent.prototype.update = function (data) {
  3616. return this._row.updateData(data);
  3617. };
  3618. RowComponent.prototype.normalizeHeight = function () {
  3619. this._row.normalizeHeight(true);
  3620. };
  3621. RowComponent.prototype.select = function () {
  3622. this._row.table.modules.selectRow.selectRows(this._row);
  3623. };
  3624. RowComponent.prototype.deselect = function () {
  3625. this._row.table.modules.selectRow.deselectRows(this._row);
  3626. };
  3627. RowComponent.prototype.toggleSelect = function () {
  3628. this._row.table.modules.selectRow.toggleRow(this._row);
  3629. };
  3630. RowComponent.prototype.isSelected = function () {
  3631. return this._row.table.modules.selectRow.isRowSelected(this._row);
  3632. };
  3633. RowComponent.prototype._getSelf = function () {
  3634. return this._row;
  3635. };
  3636. RowComponent.prototype.validate = function () {
  3637. return this._row.validate();
  3638. };
  3639. RowComponent.prototype.freeze = function () {
  3640. if (this._row.table.modExists("frozenRows", true)) {
  3641. this._row.table.modules.frozenRows.freezeRow(this._row);
  3642. }
  3643. };
  3644. RowComponent.prototype.unfreeze = function () {
  3645. if (this._row.table.modExists("frozenRows", true)) {
  3646. this._row.table.modules.frozenRows.unfreezeRow(this._row);
  3647. }
  3648. };
  3649. RowComponent.prototype.isFrozen = function () {
  3650. if (this._row.table.modExists("frozenRows", true)) {
  3651. var index = this._row.table.modules.frozenRows.rows.indexOf(this._row);
  3652. return index > -1;
  3653. }
  3654. return false;
  3655. };
  3656. RowComponent.prototype.treeCollapse = function () {
  3657. if (this._row.table.modExists("dataTree", true)) {
  3658. this._row.table.modules.dataTree.collapseRow(this._row);
  3659. }
  3660. };
  3661. RowComponent.prototype.treeExpand = function () {
  3662. if (this._row.table.modExists("dataTree", true)) {
  3663. this._row.table.modules.dataTree.expandRow(this._row);
  3664. }
  3665. };
  3666. RowComponent.prototype.treeToggle = function () {
  3667. if (this._row.table.modExists("dataTree", true)) {
  3668. this._row.table.modules.dataTree.toggleRow(this._row);
  3669. }
  3670. };
  3671. RowComponent.prototype.getTreeParent = function () {
  3672. if (this._row.table.modExists("dataTree", true)) {
  3673. return this._row.table.modules.dataTree.getTreeParent(this._row);
  3674. }
  3675. return false;
  3676. };
  3677. RowComponent.prototype.getTreeChildren = function () {
  3678. if (this._row.table.modExists("dataTree", true)) {
  3679. return this._row.table.modules.dataTree.getTreeChildren(this._row, true);
  3680. }
  3681. return false;
  3682. };
  3683. RowComponent.prototype.addTreeChild = function (data, pos, index) {
  3684. if (this._row.table.modExists("dataTree", true)) {
  3685. return this._row.table.modules.dataTree.addTreeChildRow(this._row, data, pos, index);
  3686. }
  3687. return false;
  3688. };
  3689. RowComponent.prototype.reformat = function () {
  3690. return this._row.reinitialize();
  3691. };
  3692. RowComponent.prototype.getGroup = function () {
  3693. return this._row.getGroup().getComponent();
  3694. };
  3695. RowComponent.prototype.getTable = function () {
  3696. return this._row.table;
  3697. };
  3698. RowComponent.prototype.getNextRow = function () {
  3699. var row = this._row.nextRow();
  3700. return row ? row.getComponent() : row;
  3701. };
  3702. RowComponent.prototype.getPrevRow = function () {
  3703. var row = this._row.prevRow();
  3704. return row ? row.getComponent() : row;
  3705. };
  3706. var Row = function Row(data, parent) {
  3707. var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "row";
  3708. this.table = parent.table;
  3709. this.parent = parent;
  3710. this.data = {};
  3711. this.type = type; //type of element
  3712. this.element = this.createElement();
  3713. this.modules = {}; //hold module variables;
  3714. this.cells = [];
  3715. this.height = 0; //hold element height
  3716. this.heightStyled = ""; //hold element height prestyled to improve render efficiency
  3717. this.manualHeight = false; //user has manually set row height
  3718. this.outerHeight = 0; //holde lements outer height
  3719. this.initialized = false; //element has been rendered
  3720. this.heightInitialized = false; //element has resized cells to fit
  3721. this.component = null;
  3722. this.setData(data);
  3723. this.generateElement();
  3724. };
  3725. Row.prototype.createElement = function () {
  3726. var el = document.createElement("div");
  3727. el.classList.add("tabulator-row");
  3728. el.setAttribute("role", "row");
  3729. return el;
  3730. };
  3731. Row.prototype.getElement = function () {
  3732. return this.element;
  3733. };
  3734. Row.prototype.detachElement = function () {
  3735. if (this.element && this.element.parentNode) {
  3736. this.element.parentNode.removeChild(this.element);
  3737. }
  3738. };
  3739. Row.prototype.generateElement = function () {
  3740. var self = this,
  3741. dblTap,
  3742. tapHold,
  3743. tap;
  3744. //set row selection characteristics
  3745. if (self.table.options.selectable !== false && self.table.modExists("selectRow")) {
  3746. self.table.modules.selectRow.initializeRow(this);
  3747. }
  3748. //setup movable rows
  3749. if (self.table.options.movableRows !== false && self.table.modExists("moveRow")) {
  3750. self.table.modules.moveRow.initializeRow(this);
  3751. }
  3752. //setup data tree
  3753. if (self.table.options.dataTree !== false && self.table.modExists("dataTree")) {
  3754. self.table.modules.dataTree.initializeRow(this);
  3755. }
  3756. //setup column colapse container
  3757. if (self.table.options.responsiveLayout === "collapse" && self.table.modExists("responsiveLayout")) {
  3758. self.table.modules.responsiveLayout.initializeRow(this);
  3759. }
  3760. //set column menu
  3761. if ((self.table.options.rowContextMenu || self.table.options.rowClickMenu) && this.table.modExists("menu")) {
  3762. self.table.modules.menu.initializeRow(this);
  3763. }
  3764. //handle row click events
  3765. if (self.table.options.rowClick) {
  3766. self.element.addEventListener("click", function (e) {
  3767. self.table.options.rowClick(e, self.getComponent());
  3768. });
  3769. }
  3770. if (self.table.options.rowDblClick) {
  3771. self.element.addEventListener("dblclick", function (e) {
  3772. self.table.options.rowDblClick(e, self.getComponent());
  3773. });
  3774. }
  3775. if (self.table.options.rowContext) {
  3776. self.element.addEventListener("contextmenu", function (e) {
  3777. self.table.options.rowContext(e, self.getComponent());
  3778. });
  3779. }
  3780. //handle mouse events
  3781. if (self.table.options.rowMouseEnter) {
  3782. self.element.addEventListener("mouseenter", function (e) {
  3783. self.table.options.rowMouseEnter(e, self.getComponent());
  3784. });
  3785. }
  3786. if (self.table.options.rowMouseLeave) {
  3787. self.element.addEventListener("mouseleave", function (e) {
  3788. self.table.options.rowMouseLeave(e, self.getComponent());
  3789. });
  3790. }
  3791. if (self.table.options.rowMouseOver) {
  3792. self.element.addEventListener("mouseover", function (e) {
  3793. self.table.options.rowMouseOver(e, self.getComponent());
  3794. });
  3795. }
  3796. if (self.table.options.rowMouseOut) {
  3797. self.element.addEventListener("mouseout", function (e) {
  3798. self.table.options.rowMouseOut(e, self.getComponent());
  3799. });
  3800. }
  3801. if (self.table.options.rowMouseMove) {
  3802. self.element.addEventListener("mousemove", function (e) {
  3803. self.table.options.rowMouseMove(e, self.getComponent());
  3804. });
  3805. }
  3806. if (self.table.options.rowTap) {
  3807. tap = false;
  3808. self.element.addEventListener("touchstart", function (e) {
  3809. tap = true;
  3810. }, { passive: true });
  3811. self.element.addEventListener("touchend", function (e) {
  3812. if (tap) {
  3813. self.table.options.rowTap(e, self.getComponent());
  3814. }
  3815. tap = false;
  3816. });
  3817. }
  3818. if (self.table.options.rowDblTap) {
  3819. dblTap = null;
  3820. self.element.addEventListener("touchend", function (e) {
  3821. if (dblTap) {
  3822. clearTimeout(dblTap);
  3823. dblTap = null;
  3824. self.table.options.rowDblTap(e, self.getComponent());
  3825. } else {
  3826. dblTap = setTimeout(function () {
  3827. clearTimeout(dblTap);
  3828. dblTap = null;
  3829. }, 300);
  3830. }
  3831. });
  3832. }
  3833. if (self.table.options.rowTapHold) {
  3834. tapHold = null;
  3835. self.element.addEventListener("touchstart", function (e) {
  3836. clearTimeout(tapHold);
  3837. tapHold = setTimeout(function () {
  3838. clearTimeout(tapHold);
  3839. tapHold = null;
  3840. tap = false;
  3841. self.table.options.rowTapHold(e, self.getComponent());
  3842. }, 1000);
  3843. }, { passive: true });
  3844. self.element.addEventListener("touchend", function (e) {
  3845. clearTimeout(tapHold);
  3846. tapHold = null;
  3847. });
  3848. }
  3849. };
  3850. Row.prototype.generateCells = function () {
  3851. this.cells = this.table.columnManager.generateCells(this);
  3852. };
  3853. //functions to setup on first render
  3854. Row.prototype.initialize = function (force) {
  3855. var _this21 = this;
  3856. if (!this.initialized || force) {
  3857. this.deleteCells();
  3858. while (this.element.firstChild) {
  3859. this.element.removeChild(this.element.firstChild);
  3860. } //handle frozen cells
  3861. if (this.table.modExists("frozenColumns")) {
  3862. this.table.modules.frozenColumns.layoutRow(this);
  3863. }
  3864. this.generateCells();
  3865. if (this.table.options.virtualDomHoz && this.table.vdomHoz.initialized) {
  3866. this.table.vdomHoz.initializeRow(this);
  3867. } else {
  3868. this.cells.forEach(function (cell) {
  3869. _this21.element.appendChild(cell.getElement());
  3870. cell.cellRendered();
  3871. });
  3872. }
  3873. if (force) {
  3874. this.normalizeHeight();
  3875. }
  3876. //setup movable rows
  3877. if (this.table.options.dataTree && this.table.modExists("dataTree")) {
  3878. this.table.modules.dataTree.layoutRow(this);
  3879. }
  3880. //setup column colapse container
  3881. if (this.table.options.responsiveLayout === "collapse" && this.table.modExists("responsiveLayout")) {
  3882. this.table.modules.responsiveLayout.layoutRow(this);
  3883. }
  3884. if (this.table.options.rowFormatter) {
  3885. this.table.options.rowFormatter(this.getComponent());
  3886. }
  3887. //set resizable handles
  3888. if (this.table.options.resizableRows && this.table.modExists("resizeRows")) {
  3889. this.table.modules.resizeRows.initializeRow(this);
  3890. }
  3891. this.initialized = true;
  3892. } else {
  3893. if (this.table.options.virtualDomHoz) {
  3894. this.table.vdomHoz.reinitializeRow(this);
  3895. }
  3896. }
  3897. };
  3898. Row.prototype.reinitializeHeight = function () {
  3899. this.heightInitialized = false;
  3900. if (this.element.offsetParent !== null) {
  3901. this.normalizeHeight(true);
  3902. }
  3903. };
  3904. Row.prototype.reinitialize = function (children) {
  3905. this.initialized = false;
  3906. this.heightInitialized = false;
  3907. if (!this.manualHeight) {
  3908. this.height = 0;
  3909. this.heightStyled = "";
  3910. }
  3911. if (this.element.offsetParent !== null) {
  3912. this.initialize(true);
  3913. }
  3914. if (this.table.options.dataTree && this.table.modExists("dataTree", true)) {
  3915. this.table.modules.dataTree.getTreeChildren(this, false, true).forEach(function (child) {
  3916. child.reinitialize(true);
  3917. });
  3918. }
  3919. };
  3920. //get heights when doing bulk row style calcs in virtual DOM
  3921. Row.prototype.calcHeight = function (force) {
  3922. var maxHeight = 0,
  3923. minHeight = this.table.options.resizableRows ? this.element.clientHeight : 0;
  3924. this.cells.forEach(function (cell) {
  3925. var height = cell.getHeight();
  3926. if (height > maxHeight) {
  3927. maxHeight = height;
  3928. }
  3929. });
  3930. if (force) {
  3931. this.height = Math.max(maxHeight, minHeight);
  3932. } else {
  3933. this.height = this.manualHeight ? this.height : Math.max(maxHeight, minHeight);
  3934. }
  3935. this.heightStyled = this.height ? this.height + "px" : "";
  3936. this.outerHeight = this.element.offsetHeight;
  3937. };
  3938. //set of cells
  3939. Row.prototype.setCellHeight = function () {
  3940. this.cells.forEach(function (cell) {
  3941. cell.setHeight();
  3942. });
  3943. this.heightInitialized = true;
  3944. };
  3945. Row.prototype.clearCellHeight = function () {
  3946. this.cells.forEach(function (cell) {
  3947. cell.clearHeight();
  3948. });
  3949. };
  3950. //normalize the height of elements in the row
  3951. Row.prototype.normalizeHeight = function (force) {
  3952. if (force) {
  3953. this.clearCellHeight();
  3954. }
  3955. this.calcHeight(force);
  3956. this.setCellHeight();
  3957. };
  3958. // Row.prototype.setHeight = function(height){
  3959. // this.height = height;
  3960. // this.setCellHeight();
  3961. // };
  3962. //set height of rows
  3963. Row.prototype.setHeight = function (height, force) {
  3964. if (this.height != height || force) {
  3965. this.manualHeight = true;
  3966. this.height = height;
  3967. this.heightStyled = height ? height + "px" : "";
  3968. this.setCellHeight();
  3969. // this.outerHeight = this.element.outerHeight();
  3970. this.outerHeight = this.element.offsetHeight;
  3971. }
  3972. };
  3973. //return rows outer height
  3974. Row.prototype.getHeight = function () {
  3975. return this.outerHeight;
  3976. };
  3977. //return rows outer Width
  3978. Row.prototype.getWidth = function () {
  3979. return this.element.offsetWidth;
  3980. };
  3981. //////////////// Cell Management /////////////////
  3982. Row.prototype.deleteCell = function (cell) {
  3983. var index = this.cells.indexOf(cell);
  3984. if (index > -1) {
  3985. this.cells.splice(index, 1);
  3986. }
  3987. };
  3988. //////////////// Data Management /////////////////
  3989. Row.prototype.setData = function (data) {
  3990. if (this.table.modExists("mutator")) {
  3991. data = this.table.modules.mutator.transformRow(data, "data");
  3992. }
  3993. this.data = data;
  3994. if (this.table.options.reactiveData && this.table.modExists("reactiveData", true)) {
  3995. this.table.modules.reactiveData.watchRow(this);
  3996. }
  3997. };
  3998. //update the rows data
  3999. Row.prototype.updateData = function (updatedData) {
  4000. var _this22 = this;
  4001. var visible = Tabulator.prototype.helpers.elVisible(this.element),
  4002. tempData = {},
  4003. newRowData;
  4004. return new Promise(function (resolve, reject) {
  4005. if (typeof updatedData === "string") {
  4006. updatedData = JSON.parse(updatedData);
  4007. }
  4008. if (_this22.table.options.reactiveData && _this22.table.modExists("reactiveData", true)) {
  4009. _this22.table.modules.reactiveData.block();
  4010. }
  4011. //mutate incomming data if needed
  4012. if (_this22.table.modExists("mutator")) {
  4013. tempData = Object.assign(tempData, _this22.data);
  4014. tempData = Object.assign(tempData, updatedData);
  4015. newRowData = _this22.table.modules.mutator.transformRow(tempData, "data", updatedData);
  4016. } else {
  4017. newRowData = updatedData;
  4018. }
  4019. //set data
  4020. for (var attrname in newRowData) {
  4021. _this22.data[attrname] = newRowData[attrname];
  4022. }
  4023. if (_this22.table.options.reactiveData && _this22.table.modExists("reactiveData", true)) {
  4024. _this22.table.modules.reactiveData.unblock();
  4025. }
  4026. //update affected cells only
  4027. for (var attrname in updatedData) {
  4028. var columns = _this22.table.columnManager.getColumnsByFieldRoot(attrname);
  4029. columns.forEach(function (column) {
  4030. var cell = _this22.getCell(column.getField());
  4031. if (cell) {
  4032. var value = column.getFieldValue(newRowData);
  4033. if (cell.getValue() != value) {
  4034. cell.setValueProcessData(value);
  4035. if (visible) {
  4036. cell.cellRendered();
  4037. }
  4038. }
  4039. }
  4040. });
  4041. }
  4042. if (_this22.table.options.groupUpdateOnCellEdit && _this22.table.options.groupBy && _this22.table.modExists("groupRows")) {
  4043. _this22.table.modules.groupRows.reassignRowToGroup(_this22.row);
  4044. }
  4045. //Partial reinitialization if visible
  4046. if (visible) {
  4047. _this22.normalizeHeight(true);
  4048. if (_this22.table.options.rowFormatter) {
  4049. _this22.table.options.rowFormatter(_this22.getComponent());
  4050. }
  4051. } else {
  4052. _this22.initialized = false;
  4053. _this22.height = 0;
  4054. _this22.heightStyled = "";
  4055. }
  4056. if (_this22.table.options.dataTree !== false && _this22.table.modExists("dataTree") && _this22.table.modules.dataTree.redrawNeeded(updatedData)) {
  4057. _this22.table.modules.dataTree.initializeRow(_this22);
  4058. _this22.table.modules.dataTree.layoutRow(_this22);
  4059. _this22.table.rowManager.refreshActiveData("tree", false, true);
  4060. }
  4061. //this.reinitialize();
  4062. _this22.table.options.rowUpdated.call(_this22.table, _this22.getComponent());
  4063. if (_this22.table.options.dataChanged) {
  4064. _this22.table.options.dataChanged.call(_this22.table, _this22.table.rowManager.getData());
  4065. }
  4066. resolve();
  4067. });
  4068. };
  4069. Row.prototype.getData = function (transform) {
  4070. if (transform) {
  4071. if (this.table.modExists("accessor")) {
  4072. return this.table.modules.accessor.transformRow(this, transform);
  4073. }
  4074. }
  4075. return this.data;
  4076. };
  4077. Row.prototype.getCell = function (column) {
  4078. var match = false;
  4079. column = this.table.columnManager.findColumn(column);
  4080. match = this.cells.find(function (cell) {
  4081. return cell.column === column;
  4082. });
  4083. return match;
  4084. };
  4085. Row.prototype.getCellIndex = function (findCell) {
  4086. return this.cells.findIndex(function (cell) {
  4087. return cell === findCell;
  4088. });
  4089. };
  4090. Row.prototype.findNextEditableCell = function (index) {
  4091. var nextCell = false;
  4092. if (index < this.cells.length - 1) {
  4093. for (var i = index + 1; i < this.cells.length; i++) {
  4094. var cell = this.cells[i];
  4095. if (cell.column.modules.edit && Tabulator.prototype.helpers.elVisible(cell.getElement())) {
  4096. var allowEdit = true;
  4097. if (typeof cell.column.modules.edit.check == "function") {
  4098. allowEdit = cell.column.modules.edit.check(cell.getComponent());
  4099. }
  4100. if (allowEdit) {
  4101. nextCell = cell;
  4102. break;
  4103. }
  4104. }
  4105. }
  4106. }
  4107. return nextCell;
  4108. };
  4109. Row.prototype.findPrevEditableCell = function (index) {
  4110. var prevCell = false;
  4111. if (index > 0) {
  4112. for (var i = index - 1; i >= 0; i--) {
  4113. var cell = this.cells[i],
  4114. allowEdit = true;
  4115. if (cell.column.modules.edit && Tabulator.prototype.helpers.elVisible(cell.getElement())) {
  4116. if (typeof cell.column.modules.edit.check == "function") {
  4117. allowEdit = cell.column.modules.edit.check(cell.getComponent());
  4118. }
  4119. if (allowEdit) {
  4120. prevCell = cell;
  4121. break;
  4122. }
  4123. }
  4124. }
  4125. }
  4126. return prevCell;
  4127. };
  4128. Row.prototype.getCells = function () {
  4129. return this.cells;
  4130. };
  4131. Row.prototype.nextRow = function () {
  4132. var row = this.table.rowManager.nextDisplayRow(this, true);
  4133. return row || false;
  4134. };
  4135. Row.prototype.prevRow = function () {
  4136. var row = this.table.rowManager.prevDisplayRow(this, true);
  4137. return row || false;
  4138. };
  4139. Row.prototype.moveToRow = function (to, before) {
  4140. var toRow = this.table.rowManager.findRow(to);
  4141. if (toRow) {
  4142. this.table.rowManager.moveRowActual(this, toRow, !before);
  4143. this.table.rowManager.refreshActiveData("display", false, true);
  4144. } else {
  4145. console.warn("Move Error - No matching row found:", to);
  4146. }
  4147. };
  4148. Row.prototype.validate = function () {
  4149. var invalid = [];
  4150. this.cells.forEach(function (cell) {
  4151. if (!cell.validate()) {
  4152. invalid.push(cell.getComponent());
  4153. }
  4154. });
  4155. return invalid.length ? invalid : true;
  4156. };
  4157. ///////////////////// Actions /////////////////////
  4158. Row.prototype.delete = function () {
  4159. var _this23 = this;
  4160. return new Promise(function (resolve, reject) {
  4161. var index, rows;
  4162. if (_this23.table.options.history && _this23.table.modExists("history")) {
  4163. if (_this23.table.options.groupBy && _this23.table.modExists("groupRows")) {
  4164. rows = _this23.getGroup().rows;
  4165. index = rows.indexOf(_this23);
  4166. if (index) {
  4167. index = rows[index - 1];
  4168. }
  4169. } else {
  4170. index = _this23.table.rowManager.getRowIndex(_this23);
  4171. if (index) {
  4172. index = _this23.table.rowManager.rows[index - 1];
  4173. }
  4174. }
  4175. _this23.table.modules.history.action("rowDelete", _this23, { data: _this23.getData(), pos: !index, index: index });
  4176. }
  4177. _this23.deleteActual();
  4178. resolve();
  4179. });
  4180. };
  4181. Row.prototype.deleteActual = function (blockRedraw) {
  4182. var index = this.table.rowManager.getRowIndex(this);
  4183. this.detatchModules();
  4184. // if(this.table.options.dataTree && this.table.modExists("dataTree")){
  4185. // this.table.modules.dataTree.collapseRow(this, true);
  4186. // }
  4187. //remove any reactive data watchers from row object
  4188. if (this.table.options.reactiveData && this.table.modExists("reactiveData", true)) {}
  4189. // this.table.modules.reactiveData.unwatchRow(this);
  4190. //remove from group
  4191. if (this.modules.group) {
  4192. this.modules.group.removeRow(this);
  4193. }
  4194. this.table.rowManager.deleteRow(this, blockRedraw);
  4195. this.deleteCells();
  4196. this.initialized = false;
  4197. this.heightInitialized = false;
  4198. this.element = false;
  4199. if (this.table.options.dataTree && this.table.modExists("dataTree", true)) {
  4200. this.table.modules.dataTree.rowDelete(this);
  4201. }
  4202. //recalc column calculations if present
  4203. if (this.table.modExists("columnCalcs")) {
  4204. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  4205. this.table.modules.columnCalcs.recalcRowGroup(this);
  4206. } else {
  4207. this.table.modules.columnCalcs.recalc(this.table.rowManager.activeRows);
  4208. }
  4209. }
  4210. };
  4211. Row.prototype.detatchModules = function () {
  4212. //deselect row if it is selected
  4213. if (this.table.modExists("selectRow")) {
  4214. this.table.modules.selectRow._deselectRow(this, true);
  4215. }
  4216. //cancel edit if row is currently being edited
  4217. if (this.table.modExists("edit")) {
  4218. if (this.table.modules.edit.currentCell.row === this) {
  4219. this.table.modules.edit.cancelEdit();
  4220. }
  4221. }
  4222. if (this.table.modExists("frozenRows")) {
  4223. this.table.modules.frozenRows.detachRow(this);
  4224. }
  4225. };
  4226. Row.prototype.deleteCells = function () {
  4227. var cellCount = this.cells.length;
  4228. for (var _i8 = 0; _i8 < cellCount; _i8++) {
  4229. this.cells[0].delete();
  4230. }
  4231. };
  4232. Row.prototype.wipe = function () {
  4233. this.detatchModules();
  4234. this.deleteCells();
  4235. while (this.element.firstChild) {
  4236. this.element.removeChild(this.element.firstChild);
  4237. }this.element = false;
  4238. this.modules = {};
  4239. if (this.element.parentNode) {
  4240. this.element.parentNode.removeChild(this.element);
  4241. }
  4242. };
  4243. Row.prototype.getGroup = function () {
  4244. return this.modules.group || false;
  4245. };
  4246. //////////////// Object Generation /////////////////
  4247. Row.prototype.getComponent = function () {
  4248. if (!this.component) {
  4249. this.component = new RowComponent(this);
  4250. }
  4251. return this.component;
  4252. };
  4253. //public row object
  4254. var CellComponent = function CellComponent(cell) {
  4255. this._cell = cell;
  4256. };
  4257. CellComponent.prototype.getValue = function () {
  4258. return this._cell.getValue();
  4259. };
  4260. CellComponent.prototype.getOldValue = function () {
  4261. return this._cell.getOldValue();
  4262. };
  4263. CellComponent.prototype.getInitialValue = function () {
  4264. return this._cell.initialValue;
  4265. };
  4266. CellComponent.prototype.getElement = function () {
  4267. return this._cell.getElement();
  4268. };
  4269. CellComponent.prototype.getRow = function () {
  4270. return this._cell.row.getComponent();
  4271. };
  4272. CellComponent.prototype.getData = function () {
  4273. return this._cell.row.getData();
  4274. };
  4275. CellComponent.prototype.getField = function () {
  4276. return this._cell.column.getField();
  4277. };
  4278. CellComponent.prototype.getColumn = function () {
  4279. return this._cell.column.getComponent();
  4280. };
  4281. CellComponent.prototype.setValue = function (value, mutate) {
  4282. if (typeof mutate == "undefined") {
  4283. mutate = true;
  4284. }
  4285. this._cell.setValue(value, mutate);
  4286. };
  4287. CellComponent.prototype.restoreOldValue = function () {
  4288. this._cell.setValueActual(this._cell.getOldValue());
  4289. };
  4290. CellComponent.prototype.restoreInitialValue = function () {
  4291. this._cell.setValueActual(this._cell.initialValue);
  4292. };
  4293. CellComponent.prototype.edit = function (force) {
  4294. return this._cell.edit(force);
  4295. };
  4296. CellComponent.prototype.cancelEdit = function () {
  4297. this._cell.cancelEdit();
  4298. };
  4299. CellComponent.prototype.isEdited = function () {
  4300. return !!this._cell.modules.edit && this._cell.modules.edit.edited;
  4301. };
  4302. CellComponent.prototype.clearEdited = function () {
  4303. if (self.table.modExists("edit", true)) {
  4304. this._cell.table.modules.edit.clearEdited(this._cell);
  4305. }
  4306. };
  4307. CellComponent.prototype.isValid = function () {
  4308. return this._cell.modules.validate ? !this._cell.modules.validate.invalid : true;
  4309. };
  4310. CellComponent.prototype.validate = function () {
  4311. return this._cell.validate();
  4312. };
  4313. CellComponent.prototype.clearValidation = function () {
  4314. if (this._cell.table.modExists("validate", true)) {
  4315. this._cell.table.modules.validate.clearValidation(this._cell);
  4316. }
  4317. };
  4318. CellComponent.prototype.nav = function () {
  4319. return this._cell.nav();
  4320. };
  4321. CellComponent.prototype.checkHeight = function () {
  4322. this._cell.checkHeight();
  4323. };
  4324. CellComponent.prototype.getTable = function () {
  4325. return this._cell.table;
  4326. };
  4327. CellComponent.prototype._getSelf = function () {
  4328. return this._cell;
  4329. };
  4330. var Cell = function Cell(column, row) {
  4331. this.table = column.table;
  4332. this.column = column;
  4333. this.row = row;
  4334. this.element = null;
  4335. this.value = null;
  4336. this.initialValue;
  4337. this.oldValue = null;
  4338. this.modules = {};
  4339. this.height = null;
  4340. this.width = null;
  4341. this.minWidth = null;
  4342. this.component = null;
  4343. this.loaded = false; //track if the cell has been added to the DOM yet
  4344. this.build();
  4345. };
  4346. //////////////// Setup Functions /////////////////
  4347. //generate element
  4348. Cell.prototype.build = function () {
  4349. this.generateElement();
  4350. this.setWidth();
  4351. this._configureCell();
  4352. this.setValueActual(this.column.getFieldValue(this.row.data));
  4353. this.initialValue = this.value;
  4354. };
  4355. Cell.prototype.generateElement = function () {
  4356. this.element = document.createElement('div');
  4357. this.element.className = "tabulator-cell";
  4358. this.element.setAttribute("role", "gridcell");
  4359. this.element = this.element;
  4360. };
  4361. Cell.prototype._configureCell = function () {
  4362. var self = this,
  4363. cellEvents = self.column.cellEvents,
  4364. element = self.element,
  4365. field = this.column.getField(),
  4366. vertAligns = {
  4367. top: "flex-start",
  4368. bottom: "flex-end",
  4369. middle: "center"
  4370. },
  4371. hozAligns = {
  4372. left: "flex-start",
  4373. right: "flex-end",
  4374. center: "center"
  4375. };
  4376. //set text alignment
  4377. element.style.textAlign = self.column.hozAlign;
  4378. if (self.column.vertAlign) {
  4379. element.style.display = "inline-flex";
  4380. element.style.alignItems = vertAligns[self.column.vertAlign] || "";
  4381. if (self.column.hozAlign) {
  4382. element.style.justifyContent = hozAligns[self.column.hozAlign] || "";
  4383. }
  4384. }
  4385. if (field) {
  4386. element.setAttribute("tabulator-field", field);
  4387. }
  4388. //add class to cell if needed
  4389. if (self.column.definition.cssClass) {
  4390. var classNames = self.column.definition.cssClass.split(" ");
  4391. classNames.forEach(function (className) {
  4392. element.classList.add(className);
  4393. });
  4394. }
  4395. //update tooltip on mouse enter
  4396. if (this.table.options.tooltipGenerationMode === "hover") {
  4397. element.addEventListener("mouseenter", function (e) {
  4398. self._generateTooltip();
  4399. });
  4400. }
  4401. self._bindClickEvents(cellEvents);
  4402. self._bindTouchEvents(cellEvents);
  4403. self._bindMouseEvents(cellEvents);
  4404. if (self.column.modules.edit) {
  4405. self.table.modules.edit.bindEditor(self);
  4406. }
  4407. if (self.column.definition.rowHandle && self.table.options.movableRows !== false && self.table.modExists("moveRow")) {
  4408. self.table.modules.moveRow.initializeCell(self);
  4409. }
  4410. //hide cell if not visible
  4411. if (!self.column.visible) {
  4412. self.hide();
  4413. }
  4414. };
  4415. Cell.prototype._bindClickEvents = function (cellEvents) {
  4416. var self = this,
  4417. element = self.element;
  4418. //set event bindings
  4419. if (cellEvents.cellClick || self.table.options.cellClick) {
  4420. element.addEventListener("click", function (e) {
  4421. var component = self.getComponent();
  4422. if (cellEvents.cellClick) {
  4423. cellEvents.cellClick.call(self.table, e, component);
  4424. }
  4425. if (self.table.options.cellClick) {
  4426. self.table.options.cellClick.call(self.table, e, component);
  4427. }
  4428. });
  4429. }
  4430. if (cellEvents.cellDblClick || this.table.options.cellDblClick) {
  4431. element.addEventListener("dblclick", function (e) {
  4432. var component = self.getComponent();
  4433. if (cellEvents.cellDblClick) {
  4434. cellEvents.cellDblClick.call(self.table, e, component);
  4435. }
  4436. if (self.table.options.cellDblClick) {
  4437. self.table.options.cellDblClick.call(self.table, e, component);
  4438. }
  4439. });
  4440. } else {
  4441. element.addEventListener("dblclick", function (e) {
  4442. if (self.table.modExists("edit")) {
  4443. if (self.table.modules.edit.currentCell === self) {
  4444. return; //prevent instant selection of editor content
  4445. }
  4446. }
  4447. e.preventDefault();
  4448. try {
  4449. if (document.selection) {
  4450. // IE
  4451. var range = document.body.createTextRange();
  4452. range.moveToElementText(self.element);
  4453. range.select();
  4454. } else if (window.getSelection) {
  4455. var range = document.createRange();
  4456. range.selectNode(self.element);
  4457. window.getSelection().removeAllRanges();
  4458. window.getSelection().addRange(range);
  4459. }
  4460. } catch (e) {}
  4461. });
  4462. }
  4463. if (cellEvents.cellContext || this.table.options.cellContext) {
  4464. element.addEventListener("contextmenu", function (e) {
  4465. var component = self.getComponent();
  4466. if (cellEvents.cellContext) {
  4467. cellEvents.cellContext.call(self.table, e, component);
  4468. }
  4469. if (self.table.options.cellContext) {
  4470. self.table.options.cellContext.call(self.table, e, component);
  4471. }
  4472. });
  4473. }
  4474. };
  4475. Cell.prototype._bindMouseEvents = function (cellEvents) {
  4476. var self = this,
  4477. element = self.element;
  4478. if (cellEvents.cellMouseEnter || self.table.options.cellMouseEnter) {
  4479. element.addEventListener("mouseenter", function (e) {
  4480. var component = self.getComponent();
  4481. if (cellEvents.cellMouseEnter) {
  4482. cellEvents.cellMouseEnter.call(self.table, e, component);
  4483. }
  4484. if (self.table.options.cellMouseEnter) {
  4485. self.table.options.cellMouseEnter.call(self.table, e, component);
  4486. }
  4487. });
  4488. }
  4489. if (cellEvents.cellMouseLeave || self.table.options.cellMouseLeave) {
  4490. element.addEventListener("mouseleave", function (e) {
  4491. var component = self.getComponent();
  4492. if (cellEvents.cellMouseLeave) {
  4493. cellEvents.cellMouseLeave.call(self.table, e, component);
  4494. }
  4495. if (self.table.options.cellMouseLeave) {
  4496. self.table.options.cellMouseLeave.call(self.table, e, component);
  4497. }
  4498. });
  4499. }
  4500. if (cellEvents.cellMouseOver || self.table.options.cellMouseOver) {
  4501. element.addEventListener("mouseover", function (e) {
  4502. var component = self.getComponent();
  4503. if (cellEvents.cellMouseOver) {
  4504. cellEvents.cellMouseOver.call(self.table, e, component);
  4505. }
  4506. if (self.table.options.cellMouseOver) {
  4507. self.table.options.cellMouseOver.call(self.table, e, component);
  4508. }
  4509. });
  4510. }
  4511. if (cellEvents.cellMouseOut || self.table.options.cellMouseOut) {
  4512. element.addEventListener("mouseout", function (e) {
  4513. var component = self.getComponent();
  4514. if (cellEvents.cellMouseOut) {
  4515. cellEvents.cellMouseOut.call(self.table, e, component);
  4516. }
  4517. if (self.table.options.cellMouseOut) {
  4518. self.table.options.cellMouseOut.call(self.table, e, component);
  4519. }
  4520. });
  4521. }
  4522. if (cellEvents.cellMouseMove || self.table.options.cellMouseMove) {
  4523. element.addEventListener("mousemove", function (e) {
  4524. var component = self.getComponent();
  4525. if (cellEvents.cellMouseMove) {
  4526. cellEvents.cellMouseMove.call(self.table, e, component);
  4527. }
  4528. if (self.table.options.cellMouseMove) {
  4529. self.table.options.cellMouseMove.call(self.table, e, component);
  4530. }
  4531. });
  4532. }
  4533. };
  4534. Cell.prototype._bindTouchEvents = function (cellEvents) {
  4535. var self = this,
  4536. element = self.element,
  4537. dblTap,
  4538. tapHold,
  4539. tap;
  4540. if (cellEvents.cellTap || this.table.options.cellTap) {
  4541. tap = false;
  4542. element.addEventListener("touchstart", function (e) {
  4543. tap = true;
  4544. }, { passive: true });
  4545. element.addEventListener("touchend", function (e) {
  4546. if (tap) {
  4547. var component = self.getComponent();
  4548. if (cellEvents.cellTap) {
  4549. cellEvents.cellTap.call(self.table, e, component);
  4550. }
  4551. if (self.table.options.cellTap) {
  4552. self.table.options.cellTap.call(self.table, e, component);
  4553. }
  4554. }
  4555. tap = false;
  4556. });
  4557. }
  4558. if (cellEvents.cellDblTap || this.table.options.cellDblTap) {
  4559. dblTap = null;
  4560. element.addEventListener("touchend", function (e) {
  4561. if (dblTap) {
  4562. clearTimeout(dblTap);
  4563. dblTap = null;
  4564. var component = self.getComponent();
  4565. if (cellEvents.cellDblTap) {
  4566. cellEvents.cellDblTap.call(self.table, e, component);
  4567. }
  4568. if (self.table.options.cellDblTap) {
  4569. self.table.options.cellDblTap.call(self.table, e, component);
  4570. }
  4571. } else {
  4572. dblTap = setTimeout(function () {
  4573. clearTimeout(dblTap);
  4574. dblTap = null;
  4575. }, 300);
  4576. }
  4577. });
  4578. }
  4579. if (cellEvents.cellTapHold || this.table.options.cellTapHold) {
  4580. tapHold = null;
  4581. element.addEventListener("touchstart", function (e) {
  4582. clearTimeout(tapHold);
  4583. tapHold = setTimeout(function () {
  4584. clearTimeout(tapHold);
  4585. tapHold = null;
  4586. tap = false;
  4587. var component = self.getComponent();
  4588. if (cellEvents.cellTapHold) {
  4589. cellEvents.cellTapHold.call(self.table, e, component);
  4590. }
  4591. if (self.table.options.cellTapHold) {
  4592. self.table.options.cellTapHold.call(self.table, e, component);
  4593. }
  4594. }, 1000);
  4595. }, { passive: true });
  4596. element.addEventListener("touchend", function (e) {
  4597. clearTimeout(tapHold);
  4598. tapHold = null;
  4599. });
  4600. }
  4601. };
  4602. //generate cell contents
  4603. Cell.prototype._generateContents = function () {
  4604. var val;
  4605. if (this.table.modExists("format")) {
  4606. val = this.table.modules.format.formatValue(this);
  4607. } else {
  4608. val = this.element.innerHTML = this.value;
  4609. }
  4610. switch (typeof val === 'undefined' ? 'undefined' : _typeof(val)) {
  4611. case "object":
  4612. if (val instanceof Node) {
  4613. //clear previous cell contents
  4614. while (this.element.firstChild) {
  4615. this.element.removeChild(this.element.firstChild);
  4616. }this.element.appendChild(val);
  4617. } else {
  4618. this.element.innerHTML = "";
  4619. if (val != null) {
  4620. 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);
  4621. }
  4622. }
  4623. break;
  4624. case "undefined":
  4625. case "null":
  4626. this.element.innerHTML = "";
  4627. break;
  4628. default:
  4629. this.element.innerHTML = val;
  4630. }
  4631. };
  4632. Cell.prototype.cellRendered = function () {
  4633. if (this.table.modExists("format") && this.table.modules.format.cellRendered) {
  4634. this.table.modules.format.cellRendered(this);
  4635. }
  4636. };
  4637. //generate tooltip text
  4638. Cell.prototype._generateTooltip = function () {
  4639. var tooltip = this.column.tooltip;
  4640. if (tooltip) {
  4641. if (tooltip === true) {
  4642. tooltip = this.value;
  4643. } else if (typeof tooltip == "function") {
  4644. tooltip = tooltip(this.getComponent());
  4645. if (tooltip === false) {
  4646. tooltip = "";
  4647. }
  4648. }
  4649. if (typeof tooltip === "undefined") {
  4650. tooltip = "";
  4651. }
  4652. this.element.setAttribute("title", tooltip);
  4653. } else {
  4654. this.element.setAttribute("title", "");
  4655. }
  4656. };
  4657. //////////////////// Getters ////////////////////
  4658. Cell.prototype.getElement = function () {
  4659. if (!this.loaded) {
  4660. this.loaded = true;
  4661. this.layoutElement();
  4662. }
  4663. return this.element;
  4664. };
  4665. Cell.prototype.getValue = function () {
  4666. return this.value;
  4667. };
  4668. Cell.prototype.getOldValue = function () {
  4669. return this.oldValue;
  4670. };
  4671. //////////////////// Actions ////////////////////
  4672. Cell.prototype.setValue = function (value, mutate) {
  4673. var changed = this.setValueProcessData(value, mutate),
  4674. component;
  4675. if (changed) {
  4676. if (this.table.options.history && this.table.modExists("history")) {
  4677. this.table.modules.history.action("cellEdit", this, { oldValue: this.oldValue, newValue: this.value });
  4678. }
  4679. component = this.getComponent();
  4680. if (this.column.cellEvents.cellEdited) {
  4681. this.column.cellEvents.cellEdited.call(this.table, component);
  4682. }
  4683. if (this.table.options.groupUpdateOnCellEdit && this.table.options.groupBy && this.table.modExists("groupRows")) {
  4684. this.table.modules.groupRows.reassignRowToGroup(this.row);
  4685. }
  4686. this.cellRendered();
  4687. this.table.options.cellEdited.call(this.table, component);
  4688. if (this.table.options.dataChanged) {
  4689. this.table.options.dataChanged.call(this.table, this.table.rowManager.getData());
  4690. }
  4691. }
  4692. };
  4693. Cell.prototype.setValueProcessData = function (value, mutate) {
  4694. var changed = false;
  4695. if (this.value != value) {
  4696. changed = true;
  4697. if (mutate) {
  4698. if (this.column.modules.mutate) {
  4699. value = this.table.modules.mutator.transformCell(this, value);
  4700. }
  4701. }
  4702. }
  4703. this.setValueActual(value);
  4704. if (changed && this.table.modExists("columnCalcs")) {
  4705. if (this.column.definition.topCalc || this.column.definition.bottomCalc) {
  4706. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  4707. if (this.table.options.columnCalcs == "table" || this.table.options.columnCalcs == "both") {
  4708. this.table.modules.columnCalcs.recalc(this.table.rowManager.activeRows);
  4709. }
  4710. if (this.table.options.columnCalcs != "table") {
  4711. this.table.modules.columnCalcs.recalcRowGroup(this.row);
  4712. }
  4713. } else {
  4714. this.table.modules.columnCalcs.recalc(this.table.rowManager.activeRows);
  4715. }
  4716. }
  4717. }
  4718. return changed;
  4719. };
  4720. Cell.prototype.setValueActual = function (value) {
  4721. this.oldValue = this.value;
  4722. this.value = value;
  4723. if (this.table.options.reactiveData && this.table.modExists("reactiveData")) {
  4724. this.table.modules.reactiveData.block();
  4725. }
  4726. this.column.setFieldValue(this.row.data, value);
  4727. if (this.table.options.reactiveData && this.table.modExists("reactiveData")) {
  4728. this.table.modules.reactiveData.unblock();
  4729. }
  4730. if (this.loaded) {
  4731. this.layoutElement();
  4732. }
  4733. };
  4734. Cell.prototype.layoutElement = function () {
  4735. this._generateContents();
  4736. this._generateTooltip();
  4737. //set resizable handles
  4738. if (this.table.options.resizableColumns && this.table.modExists("resizeColumns") && this.row.type === "row") {
  4739. this.table.modules.resizeColumns.initializeColumn("cell", this.column, this.element);
  4740. }
  4741. if ((this.column.definition.contextMenu || this.column.definition.clickMenu) && this.table.modExists("menu")) {
  4742. this.table.modules.menu.initializeCell(this);
  4743. }
  4744. //handle frozen cells
  4745. if (this.table.modExists("frozenColumns")) {
  4746. this.table.modules.frozenColumns.layoutElement(this.element, this.column);
  4747. }
  4748. };
  4749. Cell.prototype.setWidth = function () {
  4750. this.width = this.column.width;
  4751. this.element.style.width = this.column.widthStyled;
  4752. };
  4753. Cell.prototype.clearWidth = function () {
  4754. this.width = "";
  4755. this.element.style.width = "";
  4756. };
  4757. Cell.prototype.getWidth = function () {
  4758. return this.width || this.element.offsetWidth;
  4759. };
  4760. Cell.prototype.setMinWidth = function () {
  4761. this.minWidth = this.column.minWidth;
  4762. this.element.style.minWidth = this.column.minWidthStyled;
  4763. };
  4764. Cell.prototype.checkHeight = function () {
  4765. // var height = this.element.css("height");
  4766. this.row.reinitializeHeight();
  4767. };
  4768. Cell.prototype.clearHeight = function () {
  4769. this.element.style.height = "";
  4770. this.height = null;
  4771. };
  4772. Cell.prototype.setHeight = function () {
  4773. this.height = this.row.height;
  4774. this.element.style.height = this.row.heightStyled;
  4775. };
  4776. Cell.prototype.getHeight = function () {
  4777. return this.height || this.element.offsetHeight;
  4778. };
  4779. Cell.prototype.show = function () {
  4780. this.element.style.display = this.column.vertAlign ? "inline-flex" : "";
  4781. };
  4782. Cell.prototype.hide = function () {
  4783. this.element.style.display = "none";
  4784. };
  4785. Cell.prototype.edit = function (force) {
  4786. if (this.table.modExists("edit", true)) {
  4787. return this.table.modules.edit.editCell(this, force);
  4788. }
  4789. };
  4790. Cell.prototype.cancelEdit = function () {
  4791. if (this.table.modExists("edit", true)) {
  4792. var editing = this.table.modules.edit.getCurrentCell();
  4793. if (editing && editing._getSelf() === this) {
  4794. this.table.modules.edit.cancelEdit();
  4795. } else {
  4796. console.warn("Cancel Editor Error - This cell is not currently being edited ");
  4797. }
  4798. }
  4799. };
  4800. Cell.prototype.validate = function () {
  4801. if (this.column.modules.validate && this.table.modExists("validate", true)) {
  4802. var valid = this.table.modules.validate.validate(this.column.modules.validate, this, this.getValue());
  4803. return valid === true;
  4804. } else {
  4805. return true;
  4806. }
  4807. };
  4808. Cell.prototype.delete = function () {
  4809. if (!this.table.rowManager.redrawBlock && this.element.parentNode) {
  4810. this.element.parentNode.removeChild(this.element);
  4811. }
  4812. if (this.modules.validate && this.modules.validate.invalid) {
  4813. this.table.modules.validate.clearValidation(this);
  4814. }
  4815. if (this.modules.edit && this.modules.edit.edited) {
  4816. this.table.modules.edit.clearEdited(this);
  4817. }
  4818. if (this.table.options.history) {
  4819. this.table.modules.history.clearComponentHistory(this);
  4820. }
  4821. this.element = false;
  4822. this.column.deleteCell(this);
  4823. this.row.deleteCell(this);
  4824. this.calcs = {};
  4825. };
  4826. //////////////// Navigation /////////////////
  4827. Cell.prototype.nav = function () {
  4828. var self = this,
  4829. nextCell = false,
  4830. index = this.row.getCellIndex(this);
  4831. return {
  4832. next: function next() {
  4833. var nextCell = this.right(),
  4834. nextRow;
  4835. if (!nextCell) {
  4836. nextRow = self.table.rowManager.nextDisplayRow(self.row, true);
  4837. if (nextRow) {
  4838. nextCell = nextRow.findNextEditableCell(-1);
  4839. if (nextCell) {
  4840. nextCell.edit();
  4841. return true;
  4842. }
  4843. }
  4844. } else {
  4845. return true;
  4846. }
  4847. return false;
  4848. },
  4849. prev: function prev() {
  4850. var nextCell = this.left(),
  4851. prevRow;
  4852. if (!nextCell) {
  4853. prevRow = self.table.rowManager.prevDisplayRow(self.row, true);
  4854. if (prevRow) {
  4855. nextCell = prevRow.findPrevEditableCell(prevRow.cells.length);
  4856. if (nextCell) {
  4857. nextCell.edit();
  4858. return true;
  4859. }
  4860. }
  4861. } else {
  4862. return true;
  4863. }
  4864. return false;
  4865. },
  4866. left: function left() {
  4867. nextCell = self.row.findPrevEditableCell(index);
  4868. if (nextCell) {
  4869. nextCell.edit();
  4870. return true;
  4871. } else {
  4872. return false;
  4873. }
  4874. },
  4875. right: function right() {
  4876. nextCell = self.row.findNextEditableCell(index);
  4877. if (nextCell) {
  4878. nextCell.edit();
  4879. return true;
  4880. } else {
  4881. return false;
  4882. }
  4883. },
  4884. up: function up() {
  4885. var nextRow = self.table.rowManager.prevDisplayRow(self.row, true);
  4886. if (nextRow) {
  4887. nextRow.cells[index].edit();
  4888. }
  4889. },
  4890. down: function down() {
  4891. var nextRow = self.table.rowManager.nextDisplayRow(self.row, true);
  4892. if (nextRow) {
  4893. nextRow.cells[index].edit();
  4894. }
  4895. }
  4896. };
  4897. };
  4898. Cell.prototype.getIndex = function () {
  4899. this.row.getCellIndex(this);
  4900. };
  4901. //////////////// Object Generation /////////////////
  4902. Cell.prototype.getComponent = function () {
  4903. if (!this.component) {
  4904. this.component = new CellComponent(this);
  4905. }
  4906. return this.component;
  4907. };
  4908. var FooterManager = function FooterManager(table) {
  4909. this.table = table;
  4910. this.active = false;
  4911. this.element = this.createElement(); //containing element
  4912. this.external = false;
  4913. this.links = [];
  4914. this._initialize();
  4915. };
  4916. FooterManager.prototype.createElement = function () {
  4917. var el = document.createElement("div");
  4918. el.classList.add("tabulator-footer");
  4919. return el;
  4920. };
  4921. FooterManager.prototype._initialize = function (element) {
  4922. if (this.table.options.footerElement) {
  4923. switch (_typeof(this.table.options.footerElement)) {
  4924. case "string":
  4925. if (this.table.options.footerElement[0] === "<") {
  4926. this.element.innerHTML = this.table.options.footerElement;
  4927. } else {
  4928. this.external = true;
  4929. this.element = document.querySelector(this.table.options.footerElement);
  4930. }
  4931. break;
  4932. default:
  4933. this.element = this.table.options.footerElement;
  4934. break;
  4935. }
  4936. }
  4937. };
  4938. FooterManager.prototype.getElement = function () {
  4939. return this.element;
  4940. };
  4941. FooterManager.prototype.append = function (element, parent) {
  4942. this.activate(parent);
  4943. this.element.appendChild(element);
  4944. this.table.rowManager.adjustTableSize();
  4945. };
  4946. FooterManager.prototype.prepend = function (element, parent) {
  4947. this.activate(parent);
  4948. this.element.insertBefore(element, this.element.firstChild);
  4949. this.table.rowManager.adjustTableSize();
  4950. };
  4951. FooterManager.prototype.remove = function (element) {
  4952. element.parentNode.removeChild(element);
  4953. this.deactivate();
  4954. };
  4955. FooterManager.prototype.deactivate = function (force) {
  4956. if (!this.element.firstChild || force) {
  4957. if (!this.external) {
  4958. this.element.parentNode.removeChild(this.element);
  4959. }
  4960. this.active = false;
  4961. }
  4962. // this.table.rowManager.adjustTableSize();
  4963. };
  4964. FooterManager.prototype.activate = function (parent) {
  4965. if (!this.active) {
  4966. this.active = true;
  4967. if (!this.external) {
  4968. this.table.element.appendChild(this.getElement());
  4969. this.table.element.style.display = '';
  4970. }
  4971. }
  4972. if (parent) {
  4973. this.links.push(parent);
  4974. }
  4975. };
  4976. FooterManager.prototype.redraw = function () {
  4977. this.links.forEach(function (link) {
  4978. link.footerRedraw();
  4979. });
  4980. };
  4981. var Tabulator = function Tabulator(element, options) {
  4982. this.options = {};
  4983. this.columnManager = null; // hold Column Manager
  4984. this.rowManager = null; //hold Row Manager
  4985. this.footerManager = null; //holder Footer Manager
  4986. this.vdomHoz = null; //holder horizontal virtual dom
  4987. this.browser = ""; //hold current browser type
  4988. this.browserSlow = false; //handle reduced functionality for slower browsers
  4989. this.browserMobile = false; //check if running on moble, prevent resize cancelling edit on keyboard appearence
  4990. this.rtl = false; //check if the table is in RTL mode
  4991. this.modules = {}; //hold all modules bound to this table
  4992. if (this.initializeElement(element)) {
  4993. this.initializeOptions(options || {});
  4994. this._create();
  4995. }
  4996. Tabulator.prototype.comms.register(this); //register table for inderdevice communication
  4997. };
  4998. //default setup options
  4999. Tabulator.prototype.defaultOptions = {
  5000. height: false, //height of tabulator
  5001. minHeight: false, //minimum height of tabulator
  5002. maxHeight: false, //maximum height of tabulator
  5003. layout: "fitData", ///layout type "fitColumns" | "fitData"
  5004. layoutColumnsOnNewData: false, //update column widths on setData
  5005. columnMinWidth: 40, //minimum global width for a column
  5006. columnHeaderVertAlign: "top", //vertical alignment of column headers
  5007. columnVertAlign: false, // DEPRECATED - Left to allow warning
  5008. resizableColumns: true, //resizable columns
  5009. resizableRows: false, //resizable rows
  5010. autoResize: true, //auto resize table
  5011. columns: [], //store for colum header info
  5012. cellHozAlign: "", //horizontal align columns
  5013. cellVertAlign: "", //vertical align columns
  5014. headerHozAlign: "", //horizontal header alignment
  5015. data: [], //default starting data
  5016. autoColumns: false, //build columns from data row structure
  5017. autoColumnsDefinitions: false,
  5018. reactiveData: false, //enable data reactivity
  5019. nestedFieldSeparator: ".", //seperatpr for nested data
  5020. tooltips: false, //Tool tip value
  5021. tooltipsHeader: false, //Tool tip for headers
  5022. tooltipGenerationMode: "load", //when to generate tooltips
  5023. initialSort: false, //initial sorting criteria
  5024. initialFilter: false, //initial filtering criteria
  5025. initialHeaderFilter: false, //initial header filtering criteria
  5026. columnHeaderSortMulti: true, //multiple or single column sorting
  5027. sortOrderReverse: false, //reverse internal sort ordering
  5028. headerSort: true, //set default global header sort
  5029. headerSortTristate: false, //set default tristate header sorting
  5030. headerSortElement: "<div class='tabulator-arrow'></div>", //header sort element
  5031. footerElement: false, //hold footer element
  5032. index: "id", //filed for row index
  5033. textDirection: "auto",
  5034. keybindings: [], //array for keybindings
  5035. tabEndNewRow: false, //create new row when tab to end of table
  5036. invalidOptionWarnings: true, //allow toggling of invalid option warnings
  5037. clipboard: false, //enable clipboard
  5038. clipboardCopyStyled: true, //formatted table data
  5039. clipboardCopyConfig: false, //clipboard config
  5040. clipboardCopyFormatter: false, //DEPRICATED - REMOVE in 5.0
  5041. clipboardCopyRowRange: "active", //restrict clipboard to visible rows only
  5042. clipboardPasteParser: "table", //convert pasted clipboard data to rows
  5043. clipboardPasteAction: "insert", //how to insert pasted data into the table
  5044. clipboardCopied: function clipboardCopied() {}, //data has been copied to the clipboard
  5045. clipboardPasted: function clipboardPasted() {}, //data has been pasted into the table
  5046. clipboardPasteError: function clipboardPasteError() {}, //data has not successfully been pasted into the table
  5047. downloadDataFormatter: false, //function to manipulate table data before it is downloaded
  5048. downloadReady: function downloadReady(data, blob) {
  5049. return blob;
  5050. }, //function to manipulate download data
  5051. downloadComplete: false, //function to manipulate download data
  5052. downloadConfig: {}, //download config
  5053. downloadRowRange: "active", //restrict download to active rows only
  5054. dataTree: false, //enable data tree
  5055. dataTreeFilter: true, //filter child rows
  5056. dataTreeSort: true, //sort child rows
  5057. dataTreeElementColumn: false,
  5058. dataTreeBranchElement: true, //show data tree branch element
  5059. dataTreeChildIndent: 9, //data tree child indent in px
  5060. dataTreeChildField: "_children", //data tre column field to look for child rows
  5061. dataTreeCollapseElement: false, //data tree row collapse element
  5062. dataTreeExpandElement: false, //data tree row expand element
  5063. dataTreeStartExpanded: false,
  5064. dataTreeRowExpanded: function dataTreeRowExpanded() {}, //row has been expanded
  5065. dataTreeRowCollapsed: function dataTreeRowCollapsed() {}, //row has been collapsed
  5066. dataTreeChildColumnCalcs: false, //include visible data tree rows in column calculations
  5067. dataTreeSelectPropagate: false, //seleccting a parent row selects its children
  5068. printAsHtml: false, //enable print as html
  5069. printFormatter: false, //printing page formatter
  5070. printHeader: false, //page header contents
  5071. printFooter: false, //page footer contents
  5072. printCopyStyle: true, //DEPRICATED - REMOVE in 5.0
  5073. printStyled: true, //enable print as html styling
  5074. printVisibleRows: true, //DEPRICATED - REMOVE in 5.0
  5075. printRowRange: "visible", //restrict print to visible rows only
  5076. printConfig: {}, //print config options
  5077. addRowPos: "bottom", //position to insert blank rows, top|bottom
  5078. selectable: "highlight", //highlight rows on hover
  5079. selectableRangeMode: "drag", //highlight rows on hover
  5080. selectableRollingSelection: true, //roll selection once maximum number of selectable rows is reached
  5081. selectablePersistence: true, // maintain selection when table view is updated
  5082. selectableCheck: function selectableCheck(data, row) {
  5083. return true;
  5084. }, //check wheather row is selectable
  5085. headerFilterLiveFilterDelay: 300, //delay before updating column after user types in header filter
  5086. headerFilterPlaceholder: false, //placeholder text to display in header filters
  5087. headerVisible: true, //hide header
  5088. history: false, //enable edit history
  5089. locale: false, //current system language
  5090. langs: {},
  5091. virtualDom: true, //enable DOM virtualization
  5092. virtualDomBuffer: 0, // set virtual DOM buffer size
  5093. virtualDomHoz: false, //enable horizontal DOM virtualization
  5094. persistentLayout: false, //DEPRICATED - REMOVE in 5.0
  5095. persistentSort: false, //DEPRICATED - REMOVE in 5.0
  5096. persistentFilter: false, //DEPRICATED - REMOVE in 5.0
  5097. persistenceID: "", //key for persistent storage
  5098. persistenceMode: true, //mode for storing persistence information
  5099. persistenceReaderFunc: false, //function for handling persistence data reading
  5100. persistenceWriterFunc: false, //function for handling persistence data writing
  5101. persistence: false,
  5102. responsiveLayout: false, //responsive layout flags
  5103. responsiveLayoutCollapseStartOpen: true, //start showing collapsed data
  5104. responsiveLayoutCollapseUseFormatters: true, //responsive layout collapse formatter
  5105. responsiveLayoutCollapseFormatter: false, //responsive layout collapse formatter
  5106. pagination: false, //set pagination type
  5107. paginationSize: false, //set number of rows to a page
  5108. paginationInitialPage: 1, //initail page to show on load
  5109. paginationButtonCount: 5, // set count of page button
  5110. paginationSizeSelector: false, //add pagination size selector element
  5111. paginationElement: false, //element to hold pagination numbers
  5112. paginationDataSent: {}, //pagination data sent to the server
  5113. paginationDataReceived: {}, //pagination data received from the server
  5114. paginationAddRow: "page", //add rows on table or page
  5115. ajaxURL: false, //url for ajax loading
  5116. ajaxURLGenerator: false,
  5117. ajaxParams: {}, //params for ajax loading
  5118. ajaxConfig: "get", //ajax request type
  5119. ajaxContentType: "form", //ajax request type
  5120. ajaxRequestFunc: false, //promise function
  5121. ajaxLoader: true, //show loader
  5122. ajaxLoaderLoading: false, //loader element
  5123. ajaxLoaderError: false, //loader element
  5124. ajaxFiltering: false,
  5125. ajaxSorting: false,
  5126. ajaxProgressiveLoad: false, //progressive loading
  5127. ajaxProgressiveLoadDelay: 0, //delay between requests
  5128. ajaxProgressiveLoadScrollMargin: 0, //margin before scroll begins
  5129. groupBy: false, //enable table grouping and set field to group by
  5130. groupStartOpen: true, //starting state of group
  5131. groupValues: false,
  5132. groupUpdateOnCellEdit: false,
  5133. groupHeader: false, //header generation function
  5134. groupHeaderPrint: null,
  5135. groupHeaderClipboard: null,
  5136. groupHeaderHtmlOutput: null,
  5137. groupHeaderDownload: null,
  5138. htmlOutputConfig: false, //html outypu config
  5139. movableColumns: false, //enable movable columns
  5140. movableRows: false, //enable movable rows
  5141. movableRowsConnectedTables: false, //tables for movable rows to be connected to
  5142. movableRowsConnectedElements: false, //other elements for movable rows to be connected to
  5143. movableRowsSender: false,
  5144. movableRowsReceiver: "insert",
  5145. movableRowsSendingStart: function movableRowsSendingStart() {},
  5146. movableRowsSent: function movableRowsSent() {},
  5147. movableRowsSentFailed: function movableRowsSentFailed() {},
  5148. movableRowsSendingStop: function movableRowsSendingStop() {},
  5149. movableRowsReceivingStart: function movableRowsReceivingStart() {},
  5150. movableRowsReceived: function movableRowsReceived() {},
  5151. movableRowsReceivedFailed: function movableRowsReceivedFailed() {},
  5152. movableRowsReceivingStop: function movableRowsReceivingStop() {},
  5153. movableRowsElementDrop: function movableRowsElementDrop() {},
  5154. scrollToRowPosition: "top",
  5155. scrollToRowIfVisible: true,
  5156. scrollToColumnPosition: "left",
  5157. scrollToColumnIfVisible: true,
  5158. rowFormatter: false,
  5159. rowFormatterPrint: null,
  5160. rowFormatterClipboard: null,
  5161. rowFormatterHtmlOutput: null,
  5162. placeholder: false,
  5163. //table building callbacks
  5164. tableBuilding: function tableBuilding() {},
  5165. tableBuilt: function tableBuilt() {},
  5166. //render callbacks
  5167. renderStarted: function renderStarted() {},
  5168. renderComplete: function renderComplete() {},
  5169. //row callbacks
  5170. rowClick: false,
  5171. rowDblClick: false,
  5172. rowContext: false,
  5173. rowTap: false,
  5174. rowDblTap: false,
  5175. rowTapHold: false,
  5176. rowMouseEnter: false,
  5177. rowMouseLeave: false,
  5178. rowMouseOver: false,
  5179. rowMouseOut: false,
  5180. rowMouseMove: false,
  5181. rowContextMenu: false,
  5182. rowClickMenu: false,
  5183. rowAdded: function rowAdded() {},
  5184. rowDeleted: function rowDeleted() {},
  5185. rowMoved: function rowMoved() {},
  5186. rowUpdated: function rowUpdated() {},
  5187. rowSelectionChanged: function rowSelectionChanged() {},
  5188. rowSelected: function rowSelected() {},
  5189. rowDeselected: function rowDeselected() {},
  5190. rowResized: function rowResized() {},
  5191. //cell callbacks
  5192. //row callbacks
  5193. cellClick: false,
  5194. cellDblClick: false,
  5195. cellContext: false,
  5196. cellTap: false,
  5197. cellDblTap: false,
  5198. cellTapHold: false,
  5199. cellMouseEnter: false,
  5200. cellMouseLeave: false,
  5201. cellMouseOver: false,
  5202. cellMouseOut: false,
  5203. cellMouseMove: false,
  5204. cellEditing: function cellEditing() {},
  5205. cellEdited: function cellEdited() {},
  5206. cellEditCancelled: function cellEditCancelled() {},
  5207. //column callbacks
  5208. columnMoved: false,
  5209. columnResized: function columnResized() {},
  5210. columnTitleChanged: function columnTitleChanged() {},
  5211. columnVisibilityChanged: function columnVisibilityChanged() {},
  5212. //HTML iport callbacks
  5213. htmlImporting: function htmlImporting() {},
  5214. htmlImported: function htmlImported() {},
  5215. //data callbacks
  5216. dataLoading: function dataLoading() {},
  5217. dataLoaded: function dataLoaded() {},
  5218. dataEdited: false, //DEPRECATED
  5219. dataChanged: false,
  5220. //ajax callbacks
  5221. ajaxRequesting: function ajaxRequesting() {},
  5222. ajaxResponse: false,
  5223. ajaxError: function ajaxError() {},
  5224. //filtering callbacks
  5225. dataFiltering: false,
  5226. dataFiltered: false,
  5227. //sorting callbacks
  5228. dataSorting: function dataSorting() {},
  5229. dataSorted: function dataSorted() {},
  5230. //grouping callbacks
  5231. groupToggleElement: "arrow",
  5232. groupClosedShowCalcs: false,
  5233. dataGrouping: function dataGrouping() {},
  5234. dataGrouped: false,
  5235. groupVisibilityChanged: function groupVisibilityChanged() {},
  5236. groupClick: false,
  5237. groupDblClick: false,
  5238. groupContext: false,
  5239. groupContextMenu: false,
  5240. groupClickMenu: false,
  5241. groupTap: false,
  5242. groupDblTap: false,
  5243. groupTapHold: false,
  5244. columnCalcs: true,
  5245. //pagination callbacks
  5246. pageLoaded: function pageLoaded() {},
  5247. //localization callbacks
  5248. localized: function localized() {},
  5249. //validation callbacks
  5250. validationMode: "blocking",
  5251. validationFailed: function validationFailed() {},
  5252. //history callbacks
  5253. historyUndo: function historyUndo() {},
  5254. historyRedo: function historyRedo() {},
  5255. //scroll callbacks
  5256. scrollHorizontal: function scrollHorizontal() {},
  5257. scrollVertical: function scrollVertical() {}
  5258. };
  5259. Tabulator.prototype.initializeOptions = function (options) {
  5260. //warn user if option is not available
  5261. if (options.invalidOptionWarnings !== false) {
  5262. for (var key in options) {
  5263. if (typeof this.defaultOptions[key] === "undefined") {
  5264. console.warn("Invalid table constructor option:", key);
  5265. }
  5266. }
  5267. }
  5268. //assign options to table
  5269. for (var key in this.defaultOptions) {
  5270. if (key in options) {
  5271. this.options[key] = options[key];
  5272. } else {
  5273. if (Array.isArray(this.defaultOptions[key])) {
  5274. this.options[key] = [];
  5275. } else if (_typeof(this.defaultOptions[key]) === "object" && this.defaultOptions[key] !== null) {
  5276. this.options[key] = {};
  5277. } else {
  5278. this.options[key] = this.defaultOptions[key];
  5279. }
  5280. }
  5281. }
  5282. };
  5283. Tabulator.prototype.initializeElement = function (element) {
  5284. if (typeof HTMLElement !== "undefined" && element instanceof HTMLElement) {
  5285. this.element = element;
  5286. return true;
  5287. } else if (typeof element === "string") {
  5288. this.element = document.querySelector(element);
  5289. if (this.element) {
  5290. return true;
  5291. } else {
  5292. console.error("Tabulator Creation Error - no element found matching selector: ", element);
  5293. return false;
  5294. }
  5295. } else {
  5296. console.error("Tabulator Creation Error - Invalid element provided:", element);
  5297. return false;
  5298. }
  5299. };
  5300. Tabulator.prototype.rtlCheck = function () {
  5301. var style = window.getComputedStyle(this.element);
  5302. switch (this.options.textDirection) {
  5303. case "auto":
  5304. if (style.direction !== "rtl") {
  5305. break;
  5306. };
  5307. case "rtl":
  5308. this.element.classList.add("tabulator-rtl");
  5309. this.rtl = true;
  5310. break;
  5311. case "ltr":
  5312. this.element.classList.add("tabulator-ltr");
  5313. default:
  5314. this.rtl = false;
  5315. }
  5316. };
  5317. //convert depricated functionality to new functions
  5318. Tabulator.prototype._mapDepricatedFunctionality = function () {
  5319. //map depricated persistance setup options
  5320. if (this.options.persistentLayout || this.options.persistentSort || this.options.persistentFilter) {
  5321. if (!this.options.persistence) {
  5322. this.options.persistence = {};
  5323. }
  5324. }
  5325. if (this.options.dataEdited) {
  5326. console.warn("DEPRECATION WARNING - dataEdited option has been deprecated, please use the dataChanged option instead");
  5327. this.options.dataChanged = this.options.dataEdited;
  5328. }
  5329. if (this.options.downloadDataFormatter) {
  5330. console.warn("DEPRECATION WARNING - downloadDataFormatter option has been deprecated");
  5331. }
  5332. if (typeof this.options.clipboardCopyHeader !== "undefined") {
  5333. this.options.columnHeaders = this.options.clipboardCopyHeader;
  5334. console.warn("DEPRECATION WARNING - clipboardCopyHeader option has been deprecated, please use the columnHeaders property on the clipboardCopyConfig option");
  5335. }
  5336. if (this.options.printVisibleRows !== true) {
  5337. console.warn("printVisibleRows option is deprecated, you should now use the printRowRange option");
  5338. this.options.persistence.printRowRange = "active";
  5339. }
  5340. if (this.options.printCopyStyle !== true) {
  5341. console.warn("printCopyStyle option is deprecated, you should now use the printStyled option");
  5342. this.options.persistence.printStyled = this.options.printCopyStyle;
  5343. }
  5344. if (this.options.persistentLayout) {
  5345. console.warn("persistentLayout option is deprecated, you should now use the persistence option");
  5346. if (this.options.persistence !== true && typeof this.options.persistence.columns === "undefined") {
  5347. this.options.persistence.columns = true;
  5348. }
  5349. }
  5350. if (this.options.persistentSort) {
  5351. console.warn("persistentSort option is deprecated, you should now use the persistence option");
  5352. if (this.options.persistence !== true && typeof this.options.persistence.sort === "undefined") {
  5353. this.options.persistence.sort = true;
  5354. }
  5355. }
  5356. if (this.options.persistentFilter) {
  5357. console.warn("persistentFilter option is deprecated, you should now use the persistence option");
  5358. if (this.options.persistence !== true && typeof this.options.persistence.filter === "undefined") {
  5359. this.options.persistence.filter = true;
  5360. }
  5361. }
  5362. if (this.options.columnVertAlign) {
  5363. console.warn("columnVertAlign option is deprecated, you should now use the columnHeaderVertAlign option");
  5364. this.options.columnHeaderVertAlign = this.options.columnVertAlign;
  5365. }
  5366. };
  5367. Tabulator.prototype._clearSelection = function () {
  5368. this.element.classList.add("tabulator-block-select");
  5369. if (window.getSelection) {
  5370. if (window.getSelection().empty) {
  5371. // Chrome
  5372. window.getSelection().empty();
  5373. } else if (window.getSelection().removeAllRanges) {
  5374. // Firefox
  5375. window.getSelection().removeAllRanges();
  5376. }
  5377. } else if (document.selection) {
  5378. // IE?
  5379. document.selection.empty();
  5380. }
  5381. this.element.classList.remove("tabulator-block-select");
  5382. };
  5383. //concreate table
  5384. Tabulator.prototype._create = function () {
  5385. this._clearObjectPointers();
  5386. this._mapDepricatedFunctionality();
  5387. this.bindModules();
  5388. this.rtlCheck();
  5389. if (this.element.tagName === "TABLE") {
  5390. if (this.modExists("htmlTableImport", true)) {
  5391. this.modules.htmlTableImport.parseTable();
  5392. }
  5393. }
  5394. this.columnManager = new ColumnManager(this);
  5395. this.rowManager = new RowManager(this);
  5396. this.footerManager = new FooterManager(this);
  5397. this.columnManager.setRowManager(this.rowManager);
  5398. this.rowManager.setColumnManager(this.columnManager);
  5399. if (this.options.virtualDomHoz) {
  5400. this.vdomHoz = new VDomHoz(this);
  5401. }
  5402. this._buildElement();
  5403. this._loadInitialData();
  5404. };
  5405. //clear pointers to objects in default config object
  5406. Tabulator.prototype._clearObjectPointers = function () {
  5407. this.options.columns = this.options.columns.slice(0);
  5408. if (!this.options.reactiveData) {
  5409. this.options.data = this.options.data.slice(0);
  5410. }
  5411. };
  5412. //build tabulator element
  5413. Tabulator.prototype._buildElement = function () {
  5414. var _this24 = this;
  5415. var element = this.element,
  5416. mod = this.modules,
  5417. options = this.options;
  5418. options.tableBuilding.call(this);
  5419. element.classList.add("tabulator");
  5420. element.setAttribute("role", "grid");
  5421. //empty element
  5422. while (element.firstChild) {
  5423. element.removeChild(element.firstChild);
  5424. } //set table height
  5425. if (options.height) {
  5426. options.height = isNaN(options.height) ? options.height : options.height + "px";
  5427. element.style.height = options.height;
  5428. }
  5429. //set table min height
  5430. if (options.minHeight !== false) {
  5431. options.minHeight = isNaN(options.minHeight) ? options.minHeight : options.minHeight + "px";
  5432. element.style.minHeight = options.minHeight;
  5433. }
  5434. //set table maxHeight
  5435. if (options.maxHeight !== false) {
  5436. options.maxHeight = isNaN(options.maxHeight) ? options.maxHeight : options.maxHeight + "px";
  5437. element.style.maxHeight = options.maxHeight;
  5438. }
  5439. this.columnManager.initialize();
  5440. this.rowManager.initialize();
  5441. this._detectBrowser();
  5442. if (this.modExists("layout", true)) {
  5443. mod.layout.initialize(options.layout);
  5444. }
  5445. //set localization
  5446. mod.localize.initialize();
  5447. if (options.headerFilterPlaceholder !== false) {
  5448. mod.localize.setHeaderFilterPlaceholder(options.headerFilterPlaceholder);
  5449. }
  5450. for (var locale in options.langs) {
  5451. mod.localize.installLang(locale, options.langs[locale]);
  5452. }
  5453. mod.localize.setLocale(options.locale);
  5454. //configure placeholder element
  5455. if (typeof options.placeholder == "string") {
  5456. var el = document.createElement("div");
  5457. el.classList.add("tabulator-placeholder");
  5458. var span = document.createElement("span");
  5459. span.innerHTML = options.placeholder;
  5460. el.appendChild(span);
  5461. options.placeholder = el;
  5462. }
  5463. //build table elements
  5464. element.appendChild(this.columnManager.getElement());
  5465. element.appendChild(this.rowManager.getElement());
  5466. if (options.footerElement) {
  5467. this.footerManager.activate();
  5468. }
  5469. if (options.persistence && this.modExists("persistence", true)) {
  5470. mod.persistence.initialize();
  5471. }
  5472. if (options.persistence && this.modExists("persistence", true) && mod.persistence.config.columns) {
  5473. options.columns = mod.persistence.load("columns", options.columns);
  5474. }
  5475. if (options.movableRows && this.modExists("moveRow")) {
  5476. mod.moveRow.initialize();
  5477. }
  5478. if (options.autoColumns && this.options.data) {
  5479. this.columnManager.generateColumnsFromRowData(this.options.data);
  5480. }
  5481. if (this.modExists("columnCalcs")) {
  5482. mod.columnCalcs.initialize();
  5483. }
  5484. this.columnManager.setColumns(options.columns);
  5485. if (options.dataTree && this.modExists("dataTree", true)) {
  5486. mod.dataTree.initialize();
  5487. }
  5488. if (this.modExists("frozenRows")) {
  5489. this.modules.frozenRows.initialize();
  5490. }
  5491. if ((options.persistence && this.modExists("persistence", true) && mod.persistence.config.sort || options.initialSort) && this.modExists("sort", true)) {
  5492. var sorters = [];
  5493. if (options.persistence && this.modExists("persistence", true) && mod.persistence.config.sort) {
  5494. sorters = mod.persistence.load("sort");
  5495. if (sorters === false && options.initialSort) {
  5496. sorters = options.initialSort;
  5497. }
  5498. } else if (options.initialSort) {
  5499. sorters = options.initialSort;
  5500. }
  5501. mod.sort.setSort(sorters);
  5502. }
  5503. if ((options.persistence && this.modExists("persistence", true) && mod.persistence.config.filter || options.initialFilter) && this.modExists("filter", true)) {
  5504. var filters = [];
  5505. if (options.persistence && this.modExists("persistence", true) && mod.persistence.config.filter) {
  5506. filters = mod.persistence.load("filter");
  5507. if (filters === false && options.initialFilter) {
  5508. filters = options.initialFilter;
  5509. }
  5510. } else if (options.initialFilter) {
  5511. filters = options.initialFilter;
  5512. }
  5513. mod.filter.setFilter(filters);
  5514. }
  5515. if (options.initialHeaderFilter && this.modExists("filter", true)) {
  5516. options.initialHeaderFilter.forEach(function (item) {
  5517. var column = _this24.columnManager.findColumn(item.field);
  5518. if (column) {
  5519. mod.filter.setHeaderFilterValue(column, item.value);
  5520. } else {
  5521. console.warn("Column Filter Error - No matching column found:", item.field);
  5522. return false;
  5523. }
  5524. });
  5525. }
  5526. if (this.modExists("ajax")) {
  5527. mod.ajax.initialize();
  5528. }
  5529. if (options.pagination && this.modExists("page", true)) {
  5530. mod.page.initialize();
  5531. }
  5532. if (options.groupBy && this.modExists("groupRows", true)) {
  5533. mod.groupRows.initialize();
  5534. }
  5535. if (this.modExists("keybindings")) {
  5536. mod.keybindings.initialize();
  5537. }
  5538. if (this.modExists("selectRow")) {
  5539. mod.selectRow.clearSelectionData(true);
  5540. }
  5541. if (options.autoResize && this.modExists("resizeTable")) {
  5542. mod.resizeTable.initialize();
  5543. }
  5544. if (this.modExists("clipboard")) {
  5545. mod.clipboard.initialize();
  5546. }
  5547. if (options.printAsHtml && this.modExists("print")) {
  5548. mod.print.initialize();
  5549. }
  5550. options.tableBuilt.call(this);
  5551. };
  5552. Tabulator.prototype._loadInitialData = function () {
  5553. var self = this;
  5554. if (self.options.pagination && self.modExists("page")) {
  5555. self.modules.page.reset(true, true);
  5556. if (self.options.pagination == "local") {
  5557. if (self.options.data.length) {
  5558. self.rowManager.setData(self.options.data, false, true);
  5559. } else {
  5560. if ((self.options.ajaxURL || self.options.ajaxURLGenerator) && self.modExists("ajax")) {
  5561. self.modules.ajax.loadData(false, true).then(function () {}).catch(function () {
  5562. if (self.options.paginationInitialPage) {
  5563. self.modules.page.setPage(self.options.paginationInitialPage);
  5564. }
  5565. });
  5566. return;
  5567. } else {
  5568. self.rowManager.setData(self.options.data, false, true);
  5569. }
  5570. }
  5571. if (self.options.paginationInitialPage) {
  5572. self.modules.page.setPage(self.options.paginationInitialPage);
  5573. }
  5574. } else {
  5575. if (self.options.ajaxURL) {
  5576. self.modules.page.setPage(self.options.paginationInitialPage).then(function () {}).catch(function () {});
  5577. } else {
  5578. self.rowManager.setData([], false, true);
  5579. }
  5580. }
  5581. } else {
  5582. if (self.options.data.length) {
  5583. self.rowManager.setData(self.options.data);
  5584. } else {
  5585. if ((self.options.ajaxURL || self.options.ajaxURLGenerator) && self.modExists("ajax")) {
  5586. self.modules.ajax.loadData(false, true).then(function () {}).catch(function () {});
  5587. } else {
  5588. self.rowManager.setData(self.options.data, false, true);
  5589. }
  5590. }
  5591. }
  5592. };
  5593. //deconstructor
  5594. Tabulator.prototype.destroy = function () {
  5595. var element = this.element;
  5596. Tabulator.prototype.comms.deregister(this); //deregister table from inderdevice communication
  5597. if (this.options.reactiveData && this.modExists("reactiveData", true)) {
  5598. this.modules.reactiveData.unwatchData();
  5599. }
  5600. //clear row data
  5601. this.rowManager.rows.forEach(function (row) {
  5602. row.wipe();
  5603. });
  5604. this.rowManager.rows = [];
  5605. this.rowManager.activeRows = [];
  5606. this.rowManager.displayRows = [];
  5607. //clear event bindings
  5608. if (this.options.autoResize && this.modExists("resizeTable")) {
  5609. this.modules.resizeTable.clearBindings();
  5610. }
  5611. if (this.modExists("keybindings")) {
  5612. this.modules.keybindings.clearBindings();
  5613. }
  5614. //clear DOM
  5615. while (element.firstChild) {
  5616. element.removeChild(element.firstChild);
  5617. }element.classList.remove("tabulator");
  5618. };
  5619. Tabulator.prototype._detectBrowser = function () {
  5620. var ua = navigator.userAgent || navigator.vendor || window.opera;
  5621. if (ua.indexOf("Trident") > -1) {
  5622. this.browser = "ie";
  5623. this.browserSlow = true;
  5624. } else if (ua.indexOf("Edge") > -1) {
  5625. this.browser = "edge";
  5626. this.browserSlow = true;
  5627. } else if (ua.indexOf("Firefox") > -1) {
  5628. this.browser = "firefox";
  5629. this.browserSlow = false;
  5630. } else {
  5631. this.browser = "other";
  5632. this.browserSlow = false;
  5633. }
  5634. 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));
  5635. };
  5636. ////////////////// Data Handling //////////////////
  5637. //block table redrawing
  5638. Tabulator.prototype.blockRedraw = function () {
  5639. return this.rowManager.blockRedraw();
  5640. };
  5641. //restore table redrawing
  5642. Tabulator.prototype.restoreRedraw = function () {
  5643. return this.rowManager.restoreRedraw();
  5644. };
  5645. //local data from local file
  5646. Tabulator.prototype.setDataFromLocalFile = function (extensions) {
  5647. var _this25 = this;
  5648. return new Promise(function (resolve, reject) {
  5649. var input = document.createElement("input");
  5650. input.type = "file";
  5651. input.accept = extensions || ".json,application/json";
  5652. input.addEventListener("change", function (e) {
  5653. var file = input.files[0],
  5654. reader = new FileReader(),
  5655. data;
  5656. reader.readAsText(file);
  5657. reader.onload = function (e) {
  5658. try {
  5659. data = JSON.parse(reader.result);
  5660. } catch (e) {
  5661. console.warn("File Load Error - File contents is invalid JSON", e);
  5662. reject(e);
  5663. return;
  5664. }
  5665. _this25.setData(data).then(function (data) {
  5666. resolve(data);
  5667. }).catch(function (err) {
  5668. resolve(err);
  5669. });
  5670. };
  5671. reader.onerror = function (e) {
  5672. console.warn("File Load Error - Unable to read file");
  5673. reject();
  5674. };
  5675. });
  5676. input.click();
  5677. });
  5678. };
  5679. //load data
  5680. Tabulator.prototype.setData = function (data, params, config) {
  5681. if (this.modExists("ajax")) {
  5682. this.modules.ajax.blockActiveRequest();
  5683. }
  5684. return this._setData(data, params, config, false, true);
  5685. };
  5686. Tabulator.prototype._setData = function (data, params, config, inPosition, columnsChanged) {
  5687. var self = this;
  5688. if (typeof data === "string") {
  5689. if (data.indexOf("{") == 0 || data.indexOf("[") == 0) {
  5690. //data is a json encoded string
  5691. return self.rowManager.setData(JSON.parse(data), inPosition, columnsChanged);
  5692. } else {
  5693. if (self.modExists("ajax", true)) {
  5694. if (params) {
  5695. self.modules.ajax.setParams(params);
  5696. }
  5697. if (config) {
  5698. self.modules.ajax.setConfig(config);
  5699. }
  5700. self.modules.ajax.setUrl(data);
  5701. if (self.options.pagination == "remote" && self.modExists("page", true)) {
  5702. self.modules.page.reset(true, true);
  5703. return self.modules.page.setPage(1);
  5704. } else {
  5705. //assume data is url, make ajax call to url to get data
  5706. return self.modules.ajax.loadData(inPosition, columnsChanged);
  5707. }
  5708. }
  5709. }
  5710. } else {
  5711. if (data) {
  5712. //asume data is already an object
  5713. return self.rowManager.setData(data, inPosition, columnsChanged);
  5714. } else {
  5715. //no data provided, check if ajaxURL is present;
  5716. if (self.modExists("ajax") && (self.modules.ajax.getUrl || self.options.ajaxURLGenerator)) {
  5717. if (self.options.pagination == "remote" && self.modExists("page", true)) {
  5718. self.modules.page.reset(true, true);
  5719. return self.modules.page.setPage(1);
  5720. } else {
  5721. return self.modules.ajax.loadData(inPosition, columnsChanged);
  5722. }
  5723. } else {
  5724. //empty data
  5725. return self.rowManager.setData([], inPosition, columnsChanged);
  5726. }
  5727. }
  5728. }
  5729. };
  5730. //clear data
  5731. Tabulator.prototype.clearData = function () {
  5732. if (this.modExists("ajax")) {
  5733. this.modules.ajax.blockActiveRequest();
  5734. }
  5735. this.rowManager.clearData();
  5736. };
  5737. //get table data array
  5738. Tabulator.prototype.getData = function (active) {
  5739. if (active === true) {
  5740. console.warn("passing a boolean to the getData function is deprecated, you should now pass the string 'active'");
  5741. active = "active";
  5742. }
  5743. return this.rowManager.getData(active);
  5744. };
  5745. //get table data array count
  5746. Tabulator.prototype.getDataCount = function (active) {
  5747. if (active === true) {
  5748. console.warn("passing a boolean to the getDataCount function is deprecated, you should now pass the string 'active'");
  5749. active = "active";
  5750. }
  5751. return this.rowManager.getDataCount(active);
  5752. };
  5753. //search for specific row components
  5754. Tabulator.prototype.searchRows = function (field, type, value) {
  5755. if (this.modExists("filter", true)) {
  5756. return this.modules.filter.search("rows", field, type, value);
  5757. }
  5758. };
  5759. //search for specific data
  5760. Tabulator.prototype.searchData = function (field, type, value) {
  5761. if (this.modExists("filter", true)) {
  5762. return this.modules.filter.search("data", field, type, value);
  5763. }
  5764. };
  5765. //get table html
  5766. Tabulator.prototype.getHtml = function (visible, style, config) {
  5767. if (this.modExists("export", true)) {
  5768. return this.modules.export.getHtml(visible, style, config);
  5769. }
  5770. };
  5771. //get print html
  5772. Tabulator.prototype.print = function (visible, style, config) {
  5773. if (this.modExists("print", true)) {
  5774. return this.modules.print.printFullscreen(visible, style, config);
  5775. }
  5776. };
  5777. //retrieve Ajax URL
  5778. Tabulator.prototype.getAjaxUrl = function () {
  5779. if (this.modExists("ajax", true)) {
  5780. return this.modules.ajax.getUrl();
  5781. }
  5782. };
  5783. //replace data, keeping table in position with same sort
  5784. Tabulator.prototype.replaceData = function (data, params, config) {
  5785. if (this.modExists("ajax")) {
  5786. this.modules.ajax.blockActiveRequest();
  5787. }
  5788. return this._setData(data, params, config, true);
  5789. };
  5790. //update table data
  5791. Tabulator.prototype.updateData = function (data) {
  5792. var _this26 = this;
  5793. var self = this;
  5794. var responses = 0;
  5795. return new Promise(function (resolve, reject) {
  5796. if (_this26.modExists("ajax")) {
  5797. _this26.modules.ajax.blockActiveRequest();
  5798. }
  5799. if (typeof data === "string") {
  5800. data = JSON.parse(data);
  5801. }
  5802. if (data) {
  5803. data.forEach(function (item) {
  5804. var row = self.rowManager.findRow(item[self.options.index]);
  5805. if (row) {
  5806. responses++;
  5807. row.updateData(item).then(function () {
  5808. responses--;
  5809. if (!responses) {
  5810. resolve();
  5811. }
  5812. });
  5813. }
  5814. });
  5815. } else {
  5816. console.warn("Update Error - No data provided");
  5817. reject("Update Error - No data provided");
  5818. }
  5819. });
  5820. };
  5821. Tabulator.prototype.addData = function (data, pos, index) {
  5822. var _this27 = this;
  5823. return new Promise(function (resolve, reject) {
  5824. if (_this27.modExists("ajax")) {
  5825. _this27.modules.ajax.blockActiveRequest();
  5826. }
  5827. if (typeof data === "string") {
  5828. data = JSON.parse(data);
  5829. }
  5830. if (data) {
  5831. _this27.rowManager.addRows(data, pos, index).then(function (rows) {
  5832. var output = [];
  5833. rows.forEach(function (row) {
  5834. output.push(row.getComponent());
  5835. });
  5836. resolve(output);
  5837. });
  5838. } else {
  5839. console.warn("Update Error - No data provided");
  5840. reject("Update Error - No data provided");
  5841. }
  5842. });
  5843. };
  5844. //update table data
  5845. Tabulator.prototype.updateOrAddData = function (data) {
  5846. var _this28 = this;
  5847. var self = this,
  5848. rows = [],
  5849. responses = 0;
  5850. return new Promise(function (resolve, reject) {
  5851. if (_this28.modExists("ajax")) {
  5852. _this28.modules.ajax.blockActiveRequest();
  5853. }
  5854. if (typeof data === "string") {
  5855. data = JSON.parse(data);
  5856. }
  5857. if (data) {
  5858. data.forEach(function (item) {
  5859. var row = self.rowManager.findRow(item[self.options.index]);
  5860. responses++;
  5861. if (row) {
  5862. row.updateData(item).then(function () {
  5863. responses--;
  5864. rows.push(row.getComponent());
  5865. if (!responses) {
  5866. resolve(rows);
  5867. }
  5868. });
  5869. } else {
  5870. self.rowManager.addRows(item).then(function (newRows) {
  5871. responses--;
  5872. rows.push(newRows[0].getComponent());
  5873. if (!responses) {
  5874. resolve(rows);
  5875. }
  5876. });
  5877. }
  5878. });
  5879. } else {
  5880. console.warn("Update Error - No data provided");
  5881. reject("Update Error - No data provided");
  5882. }
  5883. });
  5884. };
  5885. //get row object
  5886. Tabulator.prototype.getRow = function (index) {
  5887. var row = this.rowManager.findRow(index);
  5888. if (row) {
  5889. return row.getComponent();
  5890. } else {
  5891. console.warn("Find Error - No matching row found:", index);
  5892. return false;
  5893. }
  5894. };
  5895. //get row object
  5896. Tabulator.prototype.getRowFromPosition = function (position, active) {
  5897. var row = this.rowManager.getRowFromPosition(position, active);
  5898. if (row) {
  5899. return row.getComponent();
  5900. } else {
  5901. console.warn("Find Error - No matching row found:", position);
  5902. return false;
  5903. }
  5904. };
  5905. //delete row from table
  5906. Tabulator.prototype.deleteRow = function (index) {
  5907. var _this29 = this;
  5908. return new Promise(function (resolve, reject) {
  5909. var self = _this29,
  5910. count = 0,
  5911. successCount = 0,
  5912. foundRows = [];
  5913. function doneCheck() {
  5914. count++;
  5915. if (count == index.length) {
  5916. if (successCount) {
  5917. self.rowManager.reRenderInPosition();
  5918. resolve();
  5919. }
  5920. }
  5921. }
  5922. if (!Array.isArray(index)) {
  5923. index = [index];
  5924. }
  5925. //find matching rows
  5926. index.forEach(function (item) {
  5927. var row = _this29.rowManager.findRow(item, true);
  5928. if (row) {
  5929. foundRows.push(row);
  5930. } else {
  5931. console.warn("Delete Error - No matching row found:", item);
  5932. reject("Delete Error - No matching row found");
  5933. doneCheck();
  5934. }
  5935. });
  5936. //sort rows into correct order to ensure smooth delete from table
  5937. foundRows.sort(function (a, b) {
  5938. return _this29.rowManager.rows.indexOf(a) > _this29.rowManager.rows.indexOf(b) ? 1 : -1;
  5939. });
  5940. foundRows.forEach(function (row) {
  5941. row.delete().then(function () {
  5942. successCount++;
  5943. doneCheck();
  5944. }).catch(function (err) {
  5945. doneCheck();
  5946. reject(err);
  5947. });
  5948. });
  5949. });
  5950. };
  5951. //add row to table
  5952. Tabulator.prototype.addRow = function (data, pos, index) {
  5953. var _this30 = this;
  5954. return new Promise(function (resolve, reject) {
  5955. if (typeof data === "string") {
  5956. data = JSON.parse(data);
  5957. }
  5958. _this30.rowManager.addRows(data, pos, index).then(function (rows) {
  5959. //recalc column calculations if present
  5960. if (_this30.modExists("columnCalcs")) {
  5961. _this30.modules.columnCalcs.recalc(_this30.rowManager.activeRows);
  5962. }
  5963. resolve(rows[0].getComponent());
  5964. });
  5965. });
  5966. };
  5967. //update a row if it exitsts otherwise create it
  5968. Tabulator.prototype.updateOrAddRow = function (index, data) {
  5969. var _this31 = this;
  5970. return new Promise(function (resolve, reject) {
  5971. var row = _this31.rowManager.findRow(index);
  5972. if (typeof data === "string") {
  5973. data = JSON.parse(data);
  5974. }
  5975. if (row) {
  5976. row.updateData(data).then(function () {
  5977. //recalc column calculations if present
  5978. if (_this31.modExists("columnCalcs")) {
  5979. _this31.modules.columnCalcs.recalc(_this31.rowManager.activeRows);
  5980. }
  5981. resolve(row.getComponent());
  5982. }).catch(function (err) {
  5983. reject(err);
  5984. });
  5985. } else {
  5986. row = _this31.rowManager.addRows(data).then(function (rows) {
  5987. //recalc column calculations if present
  5988. if (_this31.modExists("columnCalcs")) {
  5989. _this31.modules.columnCalcs.recalc(_this31.rowManager.activeRows);
  5990. }
  5991. resolve(rows[0].getComponent());
  5992. }).catch(function (err) {
  5993. reject(err);
  5994. });
  5995. }
  5996. });
  5997. };
  5998. //update row data
  5999. Tabulator.prototype.updateRow = function (index, data) {
  6000. var _this32 = this;
  6001. return new Promise(function (resolve, reject) {
  6002. var row = _this32.rowManager.findRow(index);
  6003. if (typeof data === "string") {
  6004. data = JSON.parse(data);
  6005. }
  6006. if (row) {
  6007. row.updateData(data).then(function () {
  6008. resolve(row.getComponent());
  6009. }).catch(function (err) {
  6010. reject(err);
  6011. });
  6012. } else {
  6013. console.warn("Update Error - No matching row found:", index);
  6014. reject("Update Error - No matching row found");
  6015. }
  6016. });
  6017. };
  6018. //scroll to row in DOM
  6019. Tabulator.prototype.scrollToRow = function (index, position, ifVisible) {
  6020. var _this33 = this;
  6021. return new Promise(function (resolve, reject) {
  6022. var row = _this33.rowManager.findRow(index);
  6023. if (row) {
  6024. _this33.rowManager.scrollToRow(row, position, ifVisible).then(function () {
  6025. resolve();
  6026. }).catch(function (err) {
  6027. reject(err);
  6028. });
  6029. } else {
  6030. console.warn("Scroll Error - No matching row found:", index);
  6031. reject("Scroll Error - No matching row found");
  6032. }
  6033. });
  6034. };
  6035. Tabulator.prototype.moveRow = function (from, to, after) {
  6036. var fromRow = this.rowManager.findRow(from);
  6037. if (fromRow) {
  6038. fromRow.moveToRow(to, after);
  6039. } else {
  6040. console.warn("Move Error - No matching row found:", from);
  6041. }
  6042. };
  6043. Tabulator.prototype.getRows = function (active) {
  6044. if (active === true) {
  6045. console.warn("passing a boolean to the getRows function is deprecated, you should now pass the string 'active'");
  6046. active = "active";
  6047. }
  6048. return this.rowManager.getComponents(active);
  6049. };
  6050. //get position of row in table
  6051. Tabulator.prototype.getRowPosition = function (index, active) {
  6052. var row = this.rowManager.findRow(index);
  6053. if (row) {
  6054. return this.rowManager.getRowPosition(row, active);
  6055. } else {
  6056. console.warn("Position Error - No matching row found:", index);
  6057. return false;
  6058. }
  6059. };
  6060. //copy table data to clipboard
  6061. Tabulator.prototype.copyToClipboard = function (selector) {
  6062. if (this.modExists("clipboard", true)) {
  6063. this.modules.clipboard.copy(selector);
  6064. }
  6065. };
  6066. /////////////// Column Functions ///////////////
  6067. Tabulator.prototype.setColumns = function (definition) {
  6068. this.columnManager.setColumns(definition);
  6069. };
  6070. Tabulator.prototype.getColumns = function (structured) {
  6071. return this.columnManager.getComponents(structured);
  6072. };
  6073. Tabulator.prototype.getColumn = function (field) {
  6074. var col = this.columnManager.findColumn(field);
  6075. if (col) {
  6076. return col.getComponent();
  6077. } else {
  6078. console.warn("Find Error - No matching column found:", field);
  6079. return false;
  6080. }
  6081. };
  6082. Tabulator.prototype.getColumnDefinitions = function () {
  6083. return this.columnManager.getDefinitionTree();
  6084. };
  6085. Tabulator.prototype.getColumnLayout = function () {
  6086. if (this.modExists("persistence", true)) {
  6087. return this.modules.persistence.parseColumns(this.columnManager.getColumns());
  6088. }
  6089. };
  6090. Tabulator.prototype.setColumnLayout = function (layout) {
  6091. if (this.modExists("persistence", true)) {
  6092. this.columnManager.setColumns(this.modules.persistence.mergeDefinition(this.options.columns, layout));
  6093. return true;
  6094. }
  6095. return false;
  6096. };
  6097. Tabulator.prototype.showColumn = function (field) {
  6098. var column = this.columnManager.findColumn(field);
  6099. if (column) {
  6100. column.show();
  6101. if (this.options.responsiveLayout && this.modExists("responsiveLayout", true)) {
  6102. this.modules.responsiveLayout.update();
  6103. }
  6104. } else {
  6105. console.warn("Column Show Error - No matching column found:", field);
  6106. return false;
  6107. }
  6108. };
  6109. Tabulator.prototype.hideColumn = function (field) {
  6110. var column = this.columnManager.findColumn(field);
  6111. if (column) {
  6112. column.hide();
  6113. if (this.options.responsiveLayout && this.modExists("responsiveLayout", true)) {
  6114. this.modules.responsiveLayout.update();
  6115. }
  6116. } else {
  6117. console.warn("Column Hide Error - No matching column found:", field);
  6118. return false;
  6119. }
  6120. };
  6121. Tabulator.prototype.toggleColumn = function (field) {
  6122. var column = this.columnManager.findColumn(field);
  6123. if (column) {
  6124. if (column.visible) {
  6125. column.hide();
  6126. } else {
  6127. column.show();
  6128. }
  6129. } else {
  6130. console.warn("Column Visibility Toggle Error - No matching column found:", field);
  6131. return false;
  6132. }
  6133. };
  6134. Tabulator.prototype.addColumn = function (definition, before, field) {
  6135. var _this34 = this;
  6136. return new Promise(function (resolve, reject) {
  6137. var column = _this34.columnManager.findColumn(field);
  6138. _this34.columnManager.addColumn(definition, before, column).then(function (column) {
  6139. resolve(column.getComponent());
  6140. }).catch(function (err) {
  6141. reject(err);
  6142. });
  6143. });
  6144. };
  6145. Tabulator.prototype.deleteColumn = function (field) {
  6146. var _this35 = this;
  6147. return new Promise(function (resolve, reject) {
  6148. var column = _this35.columnManager.findColumn(field);
  6149. if (column) {
  6150. column.delete().then(function () {
  6151. resolve();
  6152. }).catch(function (err) {
  6153. reject(err);
  6154. });
  6155. } else {
  6156. console.warn("Column Delete Error - No matching column found:", field);
  6157. reject();
  6158. }
  6159. });
  6160. };
  6161. Tabulator.prototype.updateColumnDefinition = function (field, definition) {
  6162. var _this36 = this;
  6163. return new Promise(function (resolve, reject) {
  6164. var column = _this36.columnManager.findColumn(field);
  6165. if (column) {
  6166. column.updateDefinition(definition).then(function (col) {
  6167. resolve(col);
  6168. }).catch(function (err) {
  6169. reject(err);
  6170. });
  6171. } else {
  6172. console.warn("Column Update Error - No matching column found:", field);
  6173. reject();
  6174. }
  6175. });
  6176. };
  6177. Tabulator.prototype.moveColumn = function (from, to, after) {
  6178. var fromColumn = this.columnManager.findColumn(from);
  6179. var toColumn = this.columnManager.findColumn(to);
  6180. if (fromColumn) {
  6181. if (toColumn) {
  6182. this.columnManager.moveColumn(fromColumn, toColumn, after);
  6183. } else {
  6184. console.warn("Move Error - No matching column found:", toColumn);
  6185. }
  6186. } else {
  6187. console.warn("Move Error - No matching column found:", from);
  6188. }
  6189. };
  6190. //scroll to column in DOM
  6191. Tabulator.prototype.scrollToColumn = function (field, position, ifVisible) {
  6192. var _this37 = this;
  6193. return new Promise(function (resolve, reject) {
  6194. var column = _this37.columnManager.findColumn(field);
  6195. if (column) {
  6196. _this37.columnManager.scrollToColumn(column, position, ifVisible).then(function () {
  6197. resolve();
  6198. }).catch(function (err) {
  6199. reject(err);
  6200. });
  6201. } else {
  6202. console.warn("Scroll Error - No matching column found:", field);
  6203. reject("Scroll Error - No matching column found");
  6204. }
  6205. });
  6206. };
  6207. //////////// Localization Functions ////////////
  6208. Tabulator.prototype.setLocale = function (locale) {
  6209. this.modules.localize.setLocale(locale);
  6210. };
  6211. Tabulator.prototype.getLocale = function () {
  6212. return this.modules.localize.getLocale();
  6213. };
  6214. Tabulator.prototype.getLang = function (locale) {
  6215. return this.modules.localize.getLang(locale);
  6216. };
  6217. //////////// General Public Functions ////////////
  6218. //redraw list without updating data
  6219. Tabulator.prototype.redraw = function (force) {
  6220. this.columnManager.redraw(force);
  6221. this.rowManager.redraw(force);
  6222. };
  6223. Tabulator.prototype.setHeight = function (height) {
  6224. if (this.rowManager.renderMode !== "classic") {
  6225. this.options.height = isNaN(height) ? height : height + "px";
  6226. this.element.style.height = this.options.height;
  6227. this.rowManager.setRenderMode();
  6228. this.rowManager.redraw();
  6229. } else {
  6230. console.warn("setHeight function is not available in classic render mode");
  6231. }
  6232. };
  6233. ///////////////////// Sorting ////////////////////
  6234. //trigger sort
  6235. Tabulator.prototype.setSort = function (sortList, dir) {
  6236. if (this.modExists("sort", true)) {
  6237. this.modules.sort.setSort(sortList, dir);
  6238. this.rowManager.sorterRefresh();
  6239. }
  6240. };
  6241. Tabulator.prototype.getSorters = function () {
  6242. if (this.modExists("sort", true)) {
  6243. return this.modules.sort.getSort();
  6244. }
  6245. };
  6246. Tabulator.prototype.clearSort = function () {
  6247. if (this.modExists("sort", true)) {
  6248. this.modules.sort.clear();
  6249. this.rowManager.sorterRefresh();
  6250. }
  6251. };
  6252. ///////////////////// Filtering ////////////////////
  6253. //set standard filters
  6254. Tabulator.prototype.setFilter = function (field, type, value, params) {
  6255. if (this.modExists("filter", true)) {
  6256. this.modules.filter.setFilter(field, type, value, params);
  6257. this.rowManager.filterRefresh();
  6258. }
  6259. };
  6260. //add filter to array
  6261. Tabulator.prototype.addFilter = function (field, type, value, params) {
  6262. if (this.modExists("filter", true)) {
  6263. this.modules.filter.addFilter(field, type, value, params);
  6264. this.rowManager.filterRefresh();
  6265. }
  6266. };
  6267. //get all filters
  6268. Tabulator.prototype.getFilters = function (all) {
  6269. if (this.modExists("filter", true)) {
  6270. return this.modules.filter.getFilters(all);
  6271. }
  6272. };
  6273. Tabulator.prototype.setHeaderFilterFocus = function (field) {
  6274. if (this.modExists("filter", true)) {
  6275. var column = this.columnManager.findColumn(field);
  6276. if (column) {
  6277. this.modules.filter.setHeaderFilterFocus(column);
  6278. } else {
  6279. console.warn("Column Filter Focus Error - No matching column found:", field);
  6280. return false;
  6281. }
  6282. }
  6283. };
  6284. Tabulator.prototype.getHeaderFilterValue = function (field) {
  6285. if (this.modExists("filter", true)) {
  6286. var column = this.columnManager.findColumn(field);
  6287. if (column) {
  6288. return this.modules.filter.getHeaderFilterValue(column);
  6289. } else {
  6290. console.warn("Column Filter Error - No matching column found:", field);
  6291. }
  6292. }
  6293. };
  6294. Tabulator.prototype.setHeaderFilterValue = function (field, value) {
  6295. if (this.modExists("filter", true)) {
  6296. var column = this.columnManager.findColumn(field);
  6297. if (column) {
  6298. this.modules.filter.setHeaderFilterValue(column, value);
  6299. } else {
  6300. console.warn("Column Filter Error - No matching column found:", field);
  6301. return false;
  6302. }
  6303. }
  6304. };
  6305. Tabulator.prototype.getHeaderFilters = function () {
  6306. if (this.modExists("filter", true)) {
  6307. return this.modules.filter.getHeaderFilters();
  6308. }
  6309. };
  6310. //remove filter from array
  6311. Tabulator.prototype.removeFilter = function (field, type, value) {
  6312. if (this.modExists("filter", true)) {
  6313. this.modules.filter.removeFilter(field, type, value);
  6314. this.rowManager.filterRefresh();
  6315. }
  6316. };
  6317. //clear filters
  6318. Tabulator.prototype.clearFilter = function (all) {
  6319. if (this.modExists("filter", true)) {
  6320. this.modules.filter.clearFilter(all);
  6321. this.rowManager.filterRefresh();
  6322. }
  6323. };
  6324. //clear header filters
  6325. Tabulator.prototype.clearHeaderFilter = function () {
  6326. if (this.modExists("filter", true)) {
  6327. this.modules.filter.clearHeaderFilter();
  6328. this.rowManager.filterRefresh();
  6329. }
  6330. };
  6331. ///////////////////// select ////////////////////
  6332. Tabulator.prototype.selectRow = function (rows) {
  6333. if (this.modExists("selectRow", true)) {
  6334. if (rows === true) {
  6335. console.warn("passing a boolean to the selectRowselectRow function is deprecated, you should now pass the string 'active'");
  6336. rows = "active";
  6337. }
  6338. this.modules.selectRow.selectRows(rows);
  6339. }
  6340. };
  6341. Tabulator.prototype.deselectRow = function (rows) {
  6342. if (this.modExists("selectRow", true)) {
  6343. this.modules.selectRow.deselectRows(rows);
  6344. }
  6345. };
  6346. Tabulator.prototype.toggleSelectRow = function (row) {
  6347. if (this.modExists("selectRow", true)) {
  6348. this.modules.selectRow.toggleRow(row);
  6349. }
  6350. };
  6351. Tabulator.prototype.getSelectedRows = function () {
  6352. if (this.modExists("selectRow", true)) {
  6353. return this.modules.selectRow.getSelectedRows();
  6354. }
  6355. };
  6356. Tabulator.prototype.getSelectedData = function () {
  6357. if (this.modExists("selectRow", true)) {
  6358. return this.modules.selectRow.getSelectedData();
  6359. }
  6360. };
  6361. ///////////////////// validation ////////////////////
  6362. Tabulator.prototype.getInvalidCells = function () {
  6363. if (this.modExists("validate", true)) {
  6364. return this.modules.validate.getInvalidCells();
  6365. }
  6366. };
  6367. Tabulator.prototype.clearCellValidation = function (cells) {
  6368. var _this38 = this;
  6369. if (this.modExists("validate", true)) {
  6370. if (!cells) {
  6371. cells = this.modules.validate.getInvalidCells();
  6372. }
  6373. if (!Array.isArray(cells)) {
  6374. cells = [cells];
  6375. }
  6376. cells.forEach(function (cell) {
  6377. _this38.modules.validate.clearValidation(cell._getSelf());
  6378. });
  6379. }
  6380. };
  6381. Tabulator.prototype.validate = function (cells) {
  6382. var output = [];
  6383. //clear row data
  6384. this.rowManager.rows.forEach(function (row) {
  6385. var valid = row.validate();
  6386. if (valid !== true) {
  6387. output = output.concat(valid);
  6388. }
  6389. });
  6390. return output.length ? output : true;
  6391. };
  6392. //////////// Pagination Functions ////////////
  6393. Tabulator.prototype.setMaxPage = function (max) {
  6394. if (this.options.pagination && this.modExists("page")) {
  6395. this.modules.page.setMaxPage(max);
  6396. } else {
  6397. return false;
  6398. }
  6399. };
  6400. Tabulator.prototype.setPage = function (page) {
  6401. if (this.options.pagination && this.modExists("page")) {
  6402. return this.modules.page.setPage(page);
  6403. } else {
  6404. return new Promise(function (resolve, reject) {
  6405. reject();
  6406. });
  6407. }
  6408. };
  6409. Tabulator.prototype.setPageToRow = function (row) {
  6410. var _this39 = this;
  6411. return new Promise(function (resolve, reject) {
  6412. if (_this39.options.pagination && _this39.modExists("page")) {
  6413. row = _this39.rowManager.findRow(row);
  6414. if (row) {
  6415. _this39.modules.page.setPageToRow(row).then(function () {
  6416. resolve();
  6417. }).catch(function () {
  6418. reject();
  6419. });
  6420. } else {
  6421. reject();
  6422. }
  6423. } else {
  6424. reject();
  6425. }
  6426. });
  6427. };
  6428. Tabulator.prototype.setPageSize = function (size) {
  6429. if (this.options.pagination && this.modExists("page")) {
  6430. this.modules.page.setPageSize(size);
  6431. this.modules.page.setPage(1).then(function () {}).catch(function () {});
  6432. } else {
  6433. return false;
  6434. }
  6435. };
  6436. Tabulator.prototype.getPageSize = function () {
  6437. if (this.options.pagination && this.modExists("page", true)) {
  6438. return this.modules.page.getPageSize();
  6439. }
  6440. };
  6441. Tabulator.prototype.previousPage = function () {
  6442. if (this.options.pagination && this.modExists("page")) {
  6443. this.modules.page.previousPage();
  6444. } else {
  6445. return false;
  6446. }
  6447. };
  6448. Tabulator.prototype.nextPage = function () {
  6449. if (this.options.pagination && this.modExists("page")) {
  6450. this.modules.page.nextPage();
  6451. } else {
  6452. return false;
  6453. }
  6454. };
  6455. Tabulator.prototype.getPage = function () {
  6456. if (this.options.pagination && this.modExists("page")) {
  6457. return this.modules.page.getPage();
  6458. } else {
  6459. return false;
  6460. }
  6461. };
  6462. Tabulator.prototype.getPageMax = function () {
  6463. if (this.options.pagination && this.modExists("page")) {
  6464. return this.modules.page.getPageMax();
  6465. } else {
  6466. return false;
  6467. }
  6468. };
  6469. ///////////////// Grouping Functions ///////////////
  6470. Tabulator.prototype.setGroupBy = function (groups) {
  6471. if (this.modExists("groupRows", true)) {
  6472. this.options.groupBy = groups;
  6473. this.modules.groupRows.initialize();
  6474. this.rowManager.refreshActiveData("display");
  6475. if (this.options.persistence && this.modExists("persistence", true) && this.modules.persistence.config.group) {
  6476. this.modules.persistence.save("group");
  6477. }
  6478. } else {
  6479. return false;
  6480. }
  6481. };
  6482. Tabulator.prototype.setGroupValues = function (groupValues) {
  6483. if (this.modExists("groupRows", true)) {
  6484. this.options.groupValues = groupValues;
  6485. this.modules.groupRows.initialize();
  6486. this.rowManager.refreshActiveData("display");
  6487. if (this.options.persistence && this.modExists("persistence", true) && this.modules.persistence.config.group) {
  6488. this.modules.persistence.save("group");
  6489. }
  6490. } else {
  6491. return false;
  6492. }
  6493. };
  6494. Tabulator.prototype.setGroupStartOpen = function (values) {
  6495. if (this.modExists("groupRows", true)) {
  6496. this.options.groupStartOpen = values;
  6497. this.modules.groupRows.initialize();
  6498. if (this.options.groupBy) {
  6499. this.rowManager.refreshActiveData("group");
  6500. if (this.options.persistence && this.modExists("persistence", true) && this.modules.persistence.config.group) {
  6501. this.modules.persistence.save("group");
  6502. }
  6503. } else {
  6504. console.warn("Grouping Update - cant refresh view, no groups have been set");
  6505. }
  6506. } else {
  6507. return false;
  6508. }
  6509. };
  6510. Tabulator.prototype.setGroupHeader = function (values) {
  6511. if (this.modExists("groupRows", true)) {
  6512. this.options.groupHeader = values;
  6513. this.modules.groupRows.initialize();
  6514. if (this.options.groupBy) {
  6515. this.rowManager.refreshActiveData("group");
  6516. if (this.options.persistence && this.modExists("persistence", true) && this.modules.persistence.config.group) {
  6517. this.modules.persistence.save("group");
  6518. }
  6519. } else {
  6520. console.warn("Grouping Update - cant refresh view, no groups have been set");
  6521. }
  6522. } else {
  6523. return false;
  6524. }
  6525. };
  6526. Tabulator.prototype.getGroups = function (values) {
  6527. if (this.modExists("groupRows", true)) {
  6528. return this.modules.groupRows.getGroups(true);
  6529. } else {
  6530. return false;
  6531. }
  6532. };
  6533. // get grouped table data in the same format as getData()
  6534. Tabulator.prototype.getGroupedData = function () {
  6535. if (this.modExists("groupRows", true)) {
  6536. return this.options.groupBy ? this.modules.groupRows.getGroupedData() : this.getData();
  6537. }
  6538. };
  6539. Tabulator.prototype.getEditedCells = function () {
  6540. if (this.modExists("edit", true)) {
  6541. return this.modules.edit.getEditedCells();
  6542. }
  6543. };
  6544. Tabulator.prototype.clearCellEdited = function (cells) {
  6545. var _this40 = this;
  6546. if (this.modExists("edit", true)) {
  6547. if (!cells) {
  6548. cells = this.modules.edit.getEditedCells();
  6549. }
  6550. if (!Array.isArray(cells)) {
  6551. cells = [cells];
  6552. }
  6553. cells.forEach(function (cell) {
  6554. _this40.modules.edit.clearEdited(cell._getSelf());
  6555. });
  6556. }
  6557. };
  6558. ///////////////// Column Calculation Functions ///////////////
  6559. Tabulator.prototype.getCalcResults = function () {
  6560. if (this.modExists("columnCalcs", true)) {
  6561. return this.modules.columnCalcs.getResults();
  6562. } else {
  6563. return false;
  6564. }
  6565. };
  6566. Tabulator.prototype.recalc = function () {
  6567. if (this.modExists("columnCalcs", true)) {
  6568. this.modules.columnCalcs.recalcAll(this.rowManager.activeRows);
  6569. }
  6570. };
  6571. /////////////// Navigation Management //////////////
  6572. Tabulator.prototype.navigatePrev = function () {
  6573. var cell = false;
  6574. if (this.modExists("edit", true)) {
  6575. cell = this.modules.edit.currentCell;
  6576. if (cell) {
  6577. return cell.nav().prev();
  6578. }
  6579. }
  6580. return false;
  6581. };
  6582. Tabulator.prototype.navigateNext = function () {
  6583. var cell = false;
  6584. if (this.modExists("edit", true)) {
  6585. cell = this.modules.edit.currentCell;
  6586. if (cell) {
  6587. return cell.nav().next();
  6588. }
  6589. }
  6590. return false;
  6591. };
  6592. Tabulator.prototype.navigateLeft = function () {
  6593. var cell = false;
  6594. if (this.modExists("edit", true)) {
  6595. cell = this.modules.edit.currentCell;
  6596. if (cell) {
  6597. e.preventDefault();
  6598. return cell.nav().left();
  6599. }
  6600. }
  6601. return false;
  6602. };
  6603. Tabulator.prototype.navigateRight = function () {
  6604. var cell = false;
  6605. if (this.modExists("edit", true)) {
  6606. cell = this.modules.edit.currentCell;
  6607. if (cell) {
  6608. e.preventDefault();
  6609. return cell.nav().right();
  6610. }
  6611. }
  6612. return false;
  6613. };
  6614. Tabulator.prototype.navigateUp = function () {
  6615. var cell = false;
  6616. if (this.modExists("edit", true)) {
  6617. cell = this.modules.edit.currentCell;
  6618. if (cell) {
  6619. e.preventDefault();
  6620. return cell.nav().up();
  6621. }
  6622. }
  6623. return false;
  6624. };
  6625. Tabulator.prototype.navigateDown = function () {
  6626. var cell = false;
  6627. if (this.modExists("edit", true)) {
  6628. cell = this.modules.edit.currentCell;
  6629. if (cell) {
  6630. e.preventDefault();
  6631. return cell.nav().down();
  6632. }
  6633. }
  6634. return false;
  6635. };
  6636. /////////////// History Management //////////////
  6637. Tabulator.prototype.undo = function () {
  6638. if (this.options.history && this.modExists("history", true)) {
  6639. return this.modules.history.undo();
  6640. } else {
  6641. return false;
  6642. }
  6643. };
  6644. Tabulator.prototype.redo = function () {
  6645. if (this.options.history && this.modExists("history", true)) {
  6646. return this.modules.history.redo();
  6647. } else {
  6648. return false;
  6649. }
  6650. };
  6651. Tabulator.prototype.getHistoryUndoSize = function () {
  6652. if (this.options.history && this.modExists("history", true)) {
  6653. return this.modules.history.getHistoryUndoSize();
  6654. } else {
  6655. return false;
  6656. }
  6657. };
  6658. Tabulator.prototype.getHistoryRedoSize = function () {
  6659. if (this.options.history && this.modExists("history", true)) {
  6660. return this.modules.history.getHistoryRedoSize();
  6661. } else {
  6662. return false;
  6663. }
  6664. };
  6665. /////////////// Download Management //////////////
  6666. Tabulator.prototype.download = function (type, filename, options, active) {
  6667. if (this.modExists("download", true)) {
  6668. this.modules.download.download(type, filename, options, active);
  6669. }
  6670. };
  6671. Tabulator.prototype.downloadToTab = function (type, filename, options, active) {
  6672. if (this.modExists("download", true)) {
  6673. this.modules.download.download(type, filename, options, active, true);
  6674. }
  6675. };
  6676. /////////// Inter Table Communications ///////////
  6677. Tabulator.prototype.tableComms = function (table, module, action, data) {
  6678. this.modules.comms.receive(table, module, action, data);
  6679. };
  6680. ////////////// Extension Management //////////////
  6681. //object to hold module
  6682. Tabulator.prototype.moduleBindings = {};
  6683. //extend module
  6684. Tabulator.prototype.extendModule = function (name, property, values) {
  6685. if (Tabulator.prototype.moduleBindings[name]) {
  6686. var source = Tabulator.prototype.moduleBindings[name].prototype[property];
  6687. if (source) {
  6688. if ((typeof values === 'undefined' ? 'undefined' : _typeof(values)) == "object") {
  6689. for (var key in values) {
  6690. source[key] = values[key];
  6691. }
  6692. } else {
  6693. console.warn("Module Error - Invalid value type, it must be an object");
  6694. }
  6695. } else {
  6696. console.warn("Module Error - property does not exist:", property);
  6697. }
  6698. } else {
  6699. console.warn("Module Error - module does not exist:", name);
  6700. }
  6701. };
  6702. //add module to tabulator
  6703. Tabulator.prototype.registerModule = function (name, module) {
  6704. var self = this;
  6705. Tabulator.prototype.moduleBindings[name] = module;
  6706. };
  6707. //ensure that module are bound to instantiated function
  6708. Tabulator.prototype.bindModules = function () {
  6709. this.modules = {};
  6710. for (var name in Tabulator.prototype.moduleBindings) {
  6711. this.modules[name] = new Tabulator.prototype.moduleBindings[name](this);
  6712. }
  6713. };
  6714. //Check for module
  6715. Tabulator.prototype.modExists = function (plugin, required) {
  6716. if (this.modules[plugin]) {
  6717. return true;
  6718. } else {
  6719. if (required) {
  6720. console.error("Tabulator Module Not Installed: " + plugin);
  6721. }
  6722. return false;
  6723. }
  6724. };
  6725. Tabulator.prototype.helpers = {
  6726. elVisible: function elVisible(el) {
  6727. return !(el.offsetWidth <= 0 && el.offsetHeight <= 0);
  6728. },
  6729. elOffset: function elOffset(el) {
  6730. var box = el.getBoundingClientRect();
  6731. return {
  6732. top: box.top + window.pageYOffset - document.documentElement.clientTop,
  6733. left: box.left + window.pageXOffset - document.documentElement.clientLeft
  6734. };
  6735. },
  6736. deepClone: function deepClone(obj) {
  6737. var clone = Object.assign(Array.isArray(obj) ? [] : {}, obj);
  6738. for (var i in obj) {
  6739. if (obj[i] != null && _typeof(obj[i]) === "object") {
  6740. if (obj[i] instanceof Date) {
  6741. clone[i] = new Date(obj[i]);
  6742. } else {
  6743. clone[i] = this.deepClone(obj[i]);
  6744. }
  6745. }
  6746. }
  6747. return clone;
  6748. }
  6749. };
  6750. Tabulator.prototype.comms = {
  6751. tables: [],
  6752. register: function register(table) {
  6753. Tabulator.prototype.comms.tables.push(table);
  6754. },
  6755. deregister: function deregister(table) {
  6756. var index = Tabulator.prototype.comms.tables.indexOf(table);
  6757. if (index > -1) {
  6758. Tabulator.prototype.comms.tables.splice(index, 1);
  6759. }
  6760. },
  6761. lookupTable: function lookupTable(query, silent) {
  6762. var results = [],
  6763. matches,
  6764. match;
  6765. if (typeof query === "string") {
  6766. matches = document.querySelectorAll(query);
  6767. if (matches.length) {
  6768. for (var i = 0; i < matches.length; i++) {
  6769. match = Tabulator.prototype.comms.matchElement(matches[i]);
  6770. if (match) {
  6771. results.push(match);
  6772. }
  6773. }
  6774. }
  6775. } else if (typeof HTMLElement !== "undefined" && query instanceof HTMLElement || query instanceof Tabulator) {
  6776. match = Tabulator.prototype.comms.matchElement(query);
  6777. if (match) {
  6778. results.push(match);
  6779. }
  6780. } else if (Array.isArray(query)) {
  6781. query.forEach(function (item) {
  6782. results = results.concat(Tabulator.prototype.comms.lookupTable(item));
  6783. });
  6784. } else {
  6785. if (!silent) {
  6786. console.warn("Table Connection Error - Invalid Selector", query);
  6787. }
  6788. }
  6789. return results;
  6790. },
  6791. matchElement: function matchElement(element) {
  6792. return Tabulator.prototype.comms.tables.find(function (table) {
  6793. return element instanceof Tabulator ? table === element : table.element === element;
  6794. });
  6795. }
  6796. };
  6797. Tabulator.prototype.findTable = function (query) {
  6798. var results = Tabulator.prototype.comms.lookupTable(query, true);
  6799. return Array.isArray(results) && !results.length ? false : results;
  6800. };
  6801. var Layout = function Layout(table) {
  6802. this.table = table;
  6803. this.mode = null;
  6804. };
  6805. //initialize layout system
  6806. Layout.prototype.initialize = function (layout) {
  6807. if (this.modes[layout]) {
  6808. this.mode = layout;
  6809. } else {
  6810. console.warn("Layout Error - invalid mode set, defaulting to 'fitData' : " + layout);
  6811. this.mode = 'fitData';
  6812. }
  6813. this.table.element.setAttribute("tabulator-layout", this.mode);
  6814. };
  6815. Layout.prototype.getMode = function () {
  6816. return this.mode;
  6817. };
  6818. //trigger table layout
  6819. Layout.prototype.layout = function () {
  6820. this.modes[this.mode].call(this, this.table.columnManager.columnsByIndex);
  6821. };
  6822. //layout render functions
  6823. Layout.prototype.modes = {
  6824. //resize columns to fit data they contain
  6825. "fitData": function fitData(columns) {
  6826. if (this.table.options.virtualDomHoz) {
  6827. this.table.vdomHoz.fitDataLayoutOverride();
  6828. } else {
  6829. columns.forEach(function (column) {
  6830. column.reinitializeWidth();
  6831. });
  6832. }
  6833. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  6834. this.table.modules.responsiveLayout.update();
  6835. }
  6836. },
  6837. //resize columns to fit data they contain and stretch row to fill table
  6838. "fitDataFill": function fitDataFill(columns) {
  6839. columns.forEach(function (column) {
  6840. column.reinitializeWidth();
  6841. });
  6842. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  6843. this.table.modules.responsiveLayout.update();
  6844. }
  6845. },
  6846. //resize columns to fit data they contain
  6847. "fitDataTable": function fitDataTable(columns) {
  6848. columns.forEach(function (column) {
  6849. column.reinitializeWidth();
  6850. });
  6851. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  6852. this.table.modules.responsiveLayout.update();
  6853. }
  6854. },
  6855. //resize columns to fit data the contain and stretch last column to fill table
  6856. "fitDataStretch": function fitDataStretch(columns) {
  6857. var _this41 = this;
  6858. var colsWidth = 0,
  6859. tableWidth = this.table.rowManager.element.clientWidth,
  6860. gap = 0,
  6861. lastCol = false;
  6862. columns.forEach(function (column, i) {
  6863. if (!column.widthFixed) {
  6864. column.reinitializeWidth();
  6865. }
  6866. if (_this41.table.options.responsiveLayout ? column.modules.responsive.visible : column.visible) {
  6867. lastCol = column;
  6868. }
  6869. if (column.visible) {
  6870. colsWidth += column.getWidth();
  6871. }
  6872. });
  6873. if (lastCol) {
  6874. gap = tableWidth - colsWidth + lastCol.getWidth();
  6875. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  6876. lastCol.setWidth(0);
  6877. this.table.modules.responsiveLayout.update();
  6878. }
  6879. if (gap > 0) {
  6880. lastCol.setWidth(gap);
  6881. } else {
  6882. lastCol.reinitializeWidth();
  6883. }
  6884. } else {
  6885. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  6886. this.table.modules.responsiveLayout.update();
  6887. }
  6888. }
  6889. },
  6890. //resize columns to fit
  6891. "fitColumns": function fitColumns(columns) {
  6892. var self = this;
  6893. var totalWidth = self.table.element.clientWidth; //table element width
  6894. var fixedWidth = 0; //total width of columns with a defined width
  6895. var flexWidth = 0; //total width available to flexible columns
  6896. var flexGrowUnits = 0; //total number of widthGrow blocks accross all columns
  6897. var flexColWidth = 0; //desired width of flexible columns
  6898. var flexColumns = []; //array of flexible width columns
  6899. var fixedShrinkColumns = []; //array of fixed width columns that can shrink
  6900. var flexShrinkUnits = 0; //total number of widthShrink blocks accross all columns
  6901. var overflowWidth = 0; //horizontal overflow width
  6902. var gapFill = 0; //number of pixels to be added to final column to close and half pixel gaps
  6903. function calcWidth(width) {
  6904. var colWidth;
  6905. if (typeof width == "string") {
  6906. if (width.indexOf("%") > -1) {
  6907. colWidth = totalWidth / 100 * parseInt(width);
  6908. } else {
  6909. colWidth = parseInt(width);
  6910. }
  6911. } else {
  6912. colWidth = width;
  6913. }
  6914. return colWidth;
  6915. }
  6916. //ensure columns resize to take up the correct amount of space
  6917. function scaleColumns(columns, freeSpace, colWidth, shrinkCols) {
  6918. var oversizeCols = [],
  6919. oversizeSpace = 0,
  6920. remainingSpace = 0,
  6921. nextColWidth = 0,
  6922. gap = 0,
  6923. changeUnits = 0,
  6924. undersizeCols = [];
  6925. function calcGrow(col) {
  6926. return colWidth * (col.column.definition.widthGrow || 1);
  6927. }
  6928. function calcShrink(col) {
  6929. return calcWidth(col.width) - colWidth * (col.column.definition.widthShrink || 0);
  6930. }
  6931. columns.forEach(function (col, i) {
  6932. var width = shrinkCols ? calcShrink(col) : calcGrow(col);
  6933. if (col.column.minWidth >= width) {
  6934. oversizeCols.push(col);
  6935. } else {
  6936. undersizeCols.push(col);
  6937. changeUnits += shrinkCols ? col.column.definition.widthShrink || 1 : col.column.definition.widthGrow || 1;
  6938. }
  6939. });
  6940. if (oversizeCols.length) {
  6941. oversizeCols.forEach(function (col) {
  6942. oversizeSpace += shrinkCols ? col.width - col.column.minWidth : col.column.minWidth;
  6943. col.width = col.column.minWidth;
  6944. });
  6945. remainingSpace = freeSpace - oversizeSpace;
  6946. nextColWidth = changeUnits ? Math.floor(remainingSpace / changeUnits) : remainingSpace;
  6947. gap = remainingSpace - nextColWidth * changeUnits;
  6948. gap += scaleColumns(undersizeCols, remainingSpace, nextColWidth, shrinkCols);
  6949. } else {
  6950. gap = changeUnits ? freeSpace - Math.floor(freeSpace / changeUnits) * changeUnits : freeSpace;
  6951. undersizeCols.forEach(function (column) {
  6952. column.width = shrinkCols ? calcShrink(column) : calcGrow(column);
  6953. });
  6954. }
  6955. return gap;
  6956. }
  6957. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  6958. this.table.modules.responsiveLayout.update();
  6959. }
  6960. //adjust for vertical scrollbar if present
  6961. if (this.table.rowManager.element.scrollHeight > this.table.rowManager.element.clientHeight) {
  6962. totalWidth -= this.table.rowManager.element.offsetWidth - this.table.rowManager.element.clientWidth;
  6963. }
  6964. columns.forEach(function (column) {
  6965. var width, minWidth, colWidth;
  6966. if (column.visible) {
  6967. width = column.definition.width;
  6968. minWidth = parseInt(column.minWidth);
  6969. if (width) {
  6970. colWidth = calcWidth(width);
  6971. fixedWidth += colWidth > minWidth ? colWidth : minWidth;
  6972. if (column.definition.widthShrink) {
  6973. fixedShrinkColumns.push({
  6974. column: column,
  6975. width: colWidth > minWidth ? colWidth : minWidth
  6976. });
  6977. flexShrinkUnits += column.definition.widthShrink;
  6978. }
  6979. } else {
  6980. flexColumns.push({
  6981. column: column,
  6982. width: 0
  6983. });
  6984. flexGrowUnits += column.definition.widthGrow || 1;
  6985. }
  6986. }
  6987. });
  6988. //calculate available space
  6989. flexWidth = totalWidth - fixedWidth;
  6990. //calculate correct column size
  6991. flexColWidth = Math.floor(flexWidth / flexGrowUnits);
  6992. //generate column widths
  6993. var gapFill = scaleColumns(flexColumns, flexWidth, flexColWidth, false);
  6994. //increase width of last column to account for rounding errors
  6995. if (flexColumns.length && gapFill > 0) {
  6996. flexColumns[flexColumns.length - 1].width += +gapFill;
  6997. }
  6998. //caculate space for columns to be shrunk into
  6999. flexColumns.forEach(function (col) {
  7000. flexWidth -= col.width;
  7001. });
  7002. overflowWidth = Math.abs(gapFill) + flexWidth;
  7003. //shrink oversize columns if there is no available space
  7004. if (overflowWidth > 0 && flexShrinkUnits) {
  7005. gapFill = scaleColumns(fixedShrinkColumns, overflowWidth, Math.floor(overflowWidth / flexShrinkUnits), true);
  7006. }
  7007. //decrease width of last column to account for rounding errors
  7008. if (fixedShrinkColumns.length) {
  7009. fixedShrinkColumns[fixedShrinkColumns.length - 1].width -= gapFill;
  7010. }
  7011. flexColumns.forEach(function (col) {
  7012. col.column.setWidth(col.width);
  7013. });
  7014. fixedShrinkColumns.forEach(function (col) {
  7015. col.column.setWidth(col.width);
  7016. });
  7017. }
  7018. };
  7019. Tabulator.prototype.registerModule("layout", Layout);
  7020. var Localize = function Localize(table) {
  7021. this.table = table; //hold Tabulator object
  7022. this.locale = "default"; //current locale
  7023. this.lang = false; //current language
  7024. this.bindings = {}; //update events to call when locale is changed
  7025. this.langList = {};
  7026. };
  7027. Localize.prototype.initialize = function () {
  7028. this.langList = Tabulator.prototype.helpers.deepClone(this.langs);
  7029. };
  7030. //set header placehoder
  7031. Localize.prototype.setHeaderFilterPlaceholder = function (placeholder) {
  7032. this.langList.default.headerFilters.default = placeholder;
  7033. };
  7034. //set header filter placeholder by column
  7035. Localize.prototype.setHeaderFilterColumnPlaceholder = function (column, placeholder) {
  7036. this.langList.default.headerFilters.columns[column] = placeholder;
  7037. if (this.lang && !this.lang.headerFilters.columns[column]) {
  7038. this.lang.headerFilters.columns[column] = placeholder;
  7039. }
  7040. };
  7041. //setup a lang description object
  7042. Localize.prototype.installLang = function (locale, lang) {
  7043. if (this.langList[locale]) {
  7044. this._setLangProp(this.langList[locale], lang);
  7045. } else {
  7046. this.langList[locale] = lang;
  7047. }
  7048. };
  7049. Localize.prototype._setLangProp = function (lang, values) {
  7050. for (var key in values) {
  7051. if (lang[key] && _typeof(lang[key]) == "object") {
  7052. this._setLangProp(lang[key], values[key]);
  7053. } else {
  7054. lang[key] = values[key];
  7055. }
  7056. }
  7057. };
  7058. //set current locale
  7059. Localize.prototype.setLocale = function (desiredLocale) {
  7060. var self = this;
  7061. desiredLocale = desiredLocale || "default";
  7062. //fill in any matching languge values
  7063. function traverseLang(trans, path) {
  7064. for (var prop in trans) {
  7065. if (_typeof(trans[prop]) == "object") {
  7066. if (!path[prop]) {
  7067. path[prop] = {};
  7068. }
  7069. traverseLang(trans[prop], path[prop]);
  7070. } else {
  7071. path[prop] = trans[prop];
  7072. }
  7073. }
  7074. }
  7075. //determing correct locale to load
  7076. if (desiredLocale === true && navigator.language) {
  7077. //get local from system
  7078. desiredLocale = navigator.language.toLowerCase();
  7079. }
  7080. if (desiredLocale) {
  7081. //if locale is not set, check for matching top level locale else use default
  7082. if (!self.langList[desiredLocale]) {
  7083. var prefix = desiredLocale.split("-")[0];
  7084. if (self.langList[prefix]) {
  7085. console.warn("Localization Error - Exact matching locale not found, using closest match: ", desiredLocale, prefix);
  7086. desiredLocale = prefix;
  7087. } else {
  7088. console.warn("Localization Error - Matching locale not found, using default: ", desiredLocale);
  7089. desiredLocale = "default";
  7090. }
  7091. }
  7092. }
  7093. self.locale = desiredLocale;
  7094. //load default lang template
  7095. self.lang = Tabulator.prototype.helpers.deepClone(self.langList.default || {});
  7096. if (desiredLocale != "default") {
  7097. traverseLang(self.langList[desiredLocale], self.lang);
  7098. }
  7099. self.table.options.localized.call(self.table, self.locale, self.lang);
  7100. self._executeBindings();
  7101. };
  7102. //get current locale
  7103. Localize.prototype.getLocale = function (locale) {
  7104. return self.locale;
  7105. };
  7106. //get lang object for given local or current if none provided
  7107. Localize.prototype.getLang = function (locale) {
  7108. return locale ? this.langList[locale] : this.lang;
  7109. };
  7110. //get text for current locale
  7111. Localize.prototype.getText = function (path, value) {
  7112. var path = value ? path + "|" + value : path,
  7113. pathArray = path.split("|"),
  7114. text = this._getLangElement(pathArray, this.locale);
  7115. // if(text === false){
  7116. // console.warn("Localization Error - Matching localized text not found for given path: ", path);
  7117. // }
  7118. return text || "";
  7119. };
  7120. //traverse langs object and find localized copy
  7121. Localize.prototype._getLangElement = function (path, locale) {
  7122. var self = this;
  7123. var root = self.lang;
  7124. path.forEach(function (level) {
  7125. var rootPath;
  7126. if (root) {
  7127. rootPath = root[level];
  7128. if (typeof rootPath != "undefined") {
  7129. root = rootPath;
  7130. } else {
  7131. root = false;
  7132. }
  7133. }
  7134. });
  7135. return root;
  7136. };
  7137. //set update binding
  7138. Localize.prototype.bind = function (path, callback) {
  7139. if (!this.bindings[path]) {
  7140. this.bindings[path] = [];
  7141. }
  7142. this.bindings[path].push(callback);
  7143. callback(this.getText(path), this.lang);
  7144. };
  7145. //itterate through bindings and trigger updates
  7146. Localize.prototype._executeBindings = function () {
  7147. var self = this;
  7148. var _loop = function _loop(path) {
  7149. self.bindings[path].forEach(function (binding) {
  7150. binding(self.getText(path), self.lang);
  7151. });
  7152. };
  7153. for (var path in self.bindings) {
  7154. _loop(path);
  7155. }
  7156. };
  7157. //Localized text listings
  7158. Localize.prototype.langs = {
  7159. "default": { //hold default locale text
  7160. "groups": {
  7161. "item": "item",
  7162. "items": "items"
  7163. },
  7164. "columns": {},
  7165. "ajax": {
  7166. "loading": "Loading",
  7167. "error": "Error"
  7168. },
  7169. "pagination": {
  7170. "page_size": "Page Size",
  7171. "page_title": "Show Page",
  7172. "first": "First",
  7173. "first_title": "First Page",
  7174. "last": "Last",
  7175. "last_title": "Last Page",
  7176. "prev": "Prev",
  7177. "prev_title": "Prev Page",
  7178. "next": "Next",
  7179. "next_title": "Next Page",
  7180. "all": "All"
  7181. },
  7182. "headerFilters": {
  7183. "default": "filter column...",
  7184. "columns": {}
  7185. }
  7186. }
  7187. };
  7188. Tabulator.prototype.registerModule("localize", Localize);
  7189. var Comms = function Comms(table) {
  7190. this.table = table;
  7191. };
  7192. Comms.prototype.getConnections = function (selectors) {
  7193. var self = this,
  7194. connections = [],
  7195. connection;
  7196. connection = Tabulator.prototype.comms.lookupTable(selectors);
  7197. connection.forEach(function (con) {
  7198. if (self.table !== con) {
  7199. connections.push(con);
  7200. }
  7201. });
  7202. return connections;
  7203. };
  7204. Comms.prototype.send = function (selectors, module, action, data) {
  7205. var self = this,
  7206. connections = this.getConnections(selectors);
  7207. connections.forEach(function (connection) {
  7208. connection.tableComms(self.table.element, module, action, data);
  7209. });
  7210. if (!connections.length && selectors) {
  7211. console.warn("Table Connection Error - No tables matching selector found", selectors);
  7212. }
  7213. };
  7214. Comms.prototype.receive = function (table, module, action, data) {
  7215. if (this.table.modExists(module)) {
  7216. return this.table.modules[module].commsReceived(table, action, data);
  7217. } else {
  7218. console.warn("Inter-table Comms Error - no such module:", module);
  7219. }
  7220. };
  7221. Tabulator.prototype.registerModule("comms", Comms);
  7222. var Accessor = function Accessor(table) {
  7223. this.table = table; //hold Tabulator object
  7224. this.allowedTypes = ["", "data", "download", "clipboard", "print", "htmlOutput"]; //list of accessor types
  7225. };
  7226. //initialize column accessor
  7227. Accessor.prototype.initializeColumn = function (column) {
  7228. var self = this,
  7229. match = false,
  7230. config = {};
  7231. this.allowedTypes.forEach(function (type) {
  7232. var key = "accessor" + (type.charAt(0).toUpperCase() + type.slice(1)),
  7233. accessor;
  7234. if (column.definition[key]) {
  7235. accessor = self.lookupAccessor(column.definition[key]);
  7236. if (accessor) {
  7237. match = true;
  7238. config[key] = {
  7239. accessor: accessor,
  7240. params: column.definition[key + "Params"] || {}
  7241. };
  7242. }
  7243. }
  7244. });
  7245. if (match) {
  7246. column.modules.accessor = config;
  7247. }
  7248. };
  7249. Accessor.prototype.lookupAccessor = function (value) {
  7250. var accessor = false;
  7251. //set column accessor
  7252. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  7253. case "string":
  7254. if (this.accessors[value]) {
  7255. accessor = this.accessors[value];
  7256. } else {
  7257. console.warn("Accessor Error - No such accessor found, ignoring: ", value);
  7258. }
  7259. break;
  7260. case "function":
  7261. accessor = value;
  7262. break;
  7263. }
  7264. return accessor;
  7265. };
  7266. //apply accessor to row
  7267. Accessor.prototype.transformRow = function (row, type) {
  7268. var key = "accessor" + (type.charAt(0).toUpperCase() + type.slice(1)),
  7269. rowComponent = row.getComponent();
  7270. //clone data object with deep copy to isolate internal data from returned result
  7271. var data = Tabulator.prototype.helpers.deepClone(row.data || {});
  7272. this.table.columnManager.traverse(function (column) {
  7273. var value, accessor, params, colCompnent;
  7274. if (column.modules.accessor) {
  7275. accessor = column.modules.accessor[key] || column.modules.accessor.accessor || false;
  7276. if (accessor) {
  7277. value = column.getFieldValue(data);
  7278. if (value != "undefined") {
  7279. colCompnent = column.getComponent();
  7280. params = typeof accessor.params === "function" ? accessor.params(value, data, type, colCompnent, rowComponent) : accessor.params;
  7281. column.setFieldValue(data, accessor.accessor(value, data, type, params, colCompnent, rowComponent));
  7282. }
  7283. }
  7284. }
  7285. });
  7286. return data;
  7287. },
  7288. //default accessors
  7289. Accessor.prototype.accessors = {};
  7290. Tabulator.prototype.registerModule("accessor", Accessor);
  7291. var Ajax = function Ajax(table) {
  7292. this.table = table; //hold Tabulator object
  7293. this.config = false; //hold config object for ajax request
  7294. this.url = ""; //request URL
  7295. this.urlGenerator = false;
  7296. this.params = false; //request parameters
  7297. this.loaderElement = this.createLoaderElement(); //loader message div
  7298. this.msgElement = this.createMsgElement(); //message element
  7299. this.loadingElement = false;
  7300. this.errorElement = false;
  7301. this.loaderPromise = false;
  7302. this.progressiveLoad = false;
  7303. this.loading = false;
  7304. this.requestOrder = 0; //prevent requests comming out of sequence if overridden by another load request
  7305. };
  7306. //initialize setup options
  7307. Ajax.prototype.initialize = function () {
  7308. var template;
  7309. this.loaderElement.appendChild(this.msgElement);
  7310. if (this.table.options.ajaxLoaderLoading) {
  7311. if (typeof this.table.options.ajaxLoaderLoading == "string") {
  7312. template = document.createElement('template');
  7313. template.innerHTML = this.table.options.ajaxLoaderLoading.trim();
  7314. this.loadingElement = template.content.firstChild;
  7315. } else {
  7316. this.loadingElement = this.table.options.ajaxLoaderLoading;
  7317. }
  7318. }
  7319. this.loaderPromise = this.table.options.ajaxRequestFunc || this.defaultLoaderPromise;
  7320. this.urlGenerator = this.table.options.ajaxURLGenerator || this.defaultURLGenerator;
  7321. if (this.table.options.ajaxLoaderError) {
  7322. if (typeof this.table.options.ajaxLoaderError == "string") {
  7323. template = document.createElement('template');
  7324. template.innerHTML = this.table.options.ajaxLoaderError.trim();
  7325. this.errorElement = template.content.firstChild;
  7326. } else {
  7327. this.errorElement = this.table.options.ajaxLoaderError;
  7328. }
  7329. }
  7330. if (this.table.options.ajaxParams) {
  7331. this.setParams(this.table.options.ajaxParams);
  7332. }
  7333. if (this.table.options.ajaxConfig) {
  7334. this.setConfig(this.table.options.ajaxConfig);
  7335. }
  7336. if (this.table.options.ajaxURL) {
  7337. this.setUrl(this.table.options.ajaxURL);
  7338. }
  7339. if (this.table.options.ajaxProgressiveLoad) {
  7340. if (this.table.options.pagination) {
  7341. this.progressiveLoad = false;
  7342. console.error("Progressive Load Error - Pagination and progressive load cannot be used at the same time");
  7343. } else {
  7344. if (this.table.modExists("page")) {
  7345. this.progressiveLoad = this.table.options.ajaxProgressiveLoad;
  7346. this.table.modules.page.initializeProgressive(this.progressiveLoad);
  7347. } else {
  7348. console.error("Pagination plugin is required for progressive ajax loading");
  7349. }
  7350. }
  7351. }
  7352. };
  7353. Ajax.prototype.createLoaderElement = function () {
  7354. var el = document.createElement("div");
  7355. el.classList.add("tabulator-loader");
  7356. return el;
  7357. };
  7358. Ajax.prototype.createMsgElement = function () {
  7359. var el = document.createElement("div");
  7360. el.classList.add("tabulator-loader-msg");
  7361. el.setAttribute("role", "alert");
  7362. return el;
  7363. };
  7364. //set ajax params
  7365. Ajax.prototype.setParams = function (params, update) {
  7366. if (update) {
  7367. this.params = this.params || {};
  7368. for (var key in params) {
  7369. this.params[key] = params[key];
  7370. }
  7371. } else {
  7372. this.params = params;
  7373. }
  7374. };
  7375. Ajax.prototype.getParams = function () {
  7376. return this.params || {};
  7377. };
  7378. //load config object
  7379. Ajax.prototype.setConfig = function (config) {
  7380. this._loadDefaultConfig();
  7381. if (typeof config == "string") {
  7382. this.config.method = config;
  7383. } else {
  7384. for (var key in config) {
  7385. this.config[key] = config[key];
  7386. }
  7387. }
  7388. };
  7389. //create config object from default
  7390. Ajax.prototype._loadDefaultConfig = function (force) {
  7391. var self = this;
  7392. if (!self.config || force) {
  7393. self.config = {};
  7394. //load base config from defaults
  7395. for (var key in self.defaultConfig) {
  7396. self.config[key] = self.defaultConfig[key];
  7397. }
  7398. }
  7399. };
  7400. //set request url
  7401. Ajax.prototype.setUrl = function (url) {
  7402. this.url = url;
  7403. };
  7404. //get request url
  7405. Ajax.prototype.getUrl = function () {
  7406. return this.url;
  7407. };
  7408. //lstandard loading function
  7409. Ajax.prototype.loadData = function (inPosition, columnsChanged) {
  7410. var self = this;
  7411. if (this.progressiveLoad) {
  7412. return this._loadDataProgressive();
  7413. } else {
  7414. return this._loadDataStandard(inPosition, columnsChanged);
  7415. }
  7416. };
  7417. Ajax.prototype.nextPage = function (diff) {
  7418. var margin;
  7419. if (!this.loading) {
  7420. margin = this.table.options.ajaxProgressiveLoadScrollMargin || this.table.rowManager.getElement().clientHeight * 2;
  7421. if (diff < margin) {
  7422. this.table.modules.page.nextPage().then(function () {}).catch(function () {});
  7423. }
  7424. }
  7425. };
  7426. Ajax.prototype.blockActiveRequest = function () {
  7427. this.requestOrder++;
  7428. };
  7429. Ajax.prototype._loadDataProgressive = function () {
  7430. this.table.rowManager.setData([]);
  7431. return this.table.modules.page.setPage(1);
  7432. };
  7433. Ajax.prototype._loadDataStandard = function (inPosition, columnsChanged) {
  7434. var _this42 = this;
  7435. return new Promise(function (resolve, reject) {
  7436. _this42.sendRequest(inPosition).then(function (data) {
  7437. _this42.table.rowManager.setData(data, inPosition, columnsChanged).then(function () {
  7438. resolve();
  7439. }).catch(function (e) {
  7440. reject(e);
  7441. });
  7442. }).catch(function (e) {
  7443. reject(e);
  7444. });
  7445. });
  7446. };
  7447. Ajax.prototype.generateParamsList = function (data, prefix) {
  7448. var self = this,
  7449. output = [];
  7450. prefix = prefix || "";
  7451. if (Array.isArray(data)) {
  7452. data.forEach(function (item, i) {
  7453. output = output.concat(self.generateParamsList(item, prefix ? prefix + "[" + i + "]" : i));
  7454. });
  7455. } else if ((typeof data === 'undefined' ? 'undefined' : _typeof(data)) === "object") {
  7456. for (var key in data) {
  7457. output = output.concat(self.generateParamsList(data[key], prefix ? prefix + "[" + key + "]" : key));
  7458. }
  7459. } else {
  7460. output.push({ key: prefix, value: data });
  7461. }
  7462. return output;
  7463. };
  7464. Ajax.prototype.serializeParams = function (params) {
  7465. var output = this.generateParamsList(params),
  7466. encoded = [];
  7467. output.forEach(function (item) {
  7468. encoded.push(encodeURIComponent(item.key) + "=" + encodeURIComponent(item.value));
  7469. });
  7470. return encoded.join("&");
  7471. };
  7472. //send ajax request
  7473. Ajax.prototype.sendRequest = function (silent) {
  7474. var _this43 = this;
  7475. var self = this,
  7476. url = self.url,
  7477. requestNo,
  7478. esc,
  7479. query;
  7480. self.requestOrder++;
  7481. requestNo = self.requestOrder;
  7482. self._loadDefaultConfig();
  7483. return new Promise(function (resolve, reject) {
  7484. if (self.table.options.ajaxRequesting.call(_this43.table, self.url, self.params) !== false) {
  7485. self.loading = true;
  7486. if (!silent) {
  7487. self.showLoader();
  7488. }
  7489. _this43.loaderPromise(url, self.config, self.params).then(function (data) {
  7490. if (requestNo === self.requestOrder) {
  7491. if (self.table.options.ajaxResponse) {
  7492. data = self.table.options.ajaxResponse.call(self.table, self.url, self.params, data);
  7493. }
  7494. resolve(data);
  7495. self.hideLoader();
  7496. self.loading = false;
  7497. } else {
  7498. console.warn("Ajax Response Blocked - An active ajax request was blocked by an attempt to change table data while the request was being made");
  7499. }
  7500. }).catch(function (error) {
  7501. console.error("Ajax Load Error: ", error);
  7502. self.table.options.ajaxError.call(self.table, error);
  7503. self.showError();
  7504. setTimeout(function () {
  7505. self.hideLoader();
  7506. }, 3000);
  7507. self.loading = false;
  7508. reject();
  7509. });
  7510. } else {
  7511. reject();
  7512. }
  7513. });
  7514. };
  7515. Ajax.prototype.showLoader = function () {
  7516. var shouldLoad = typeof this.table.options.ajaxLoader === "function" ? this.table.options.ajaxLoader() : this.table.options.ajaxLoader;
  7517. if (shouldLoad) {
  7518. this.hideLoader();
  7519. while (this.msgElement.firstChild) {
  7520. this.msgElement.removeChild(this.msgElement.firstChild);
  7521. }this.msgElement.classList.remove("tabulator-error");
  7522. this.msgElement.classList.add("tabulator-loading");
  7523. if (this.loadingElement) {
  7524. this.msgElement.appendChild(this.loadingElement);
  7525. } else {
  7526. this.msgElement.innerHTML = this.table.modules.localize.getText("ajax|loading");
  7527. }
  7528. this.table.element.appendChild(this.loaderElement);
  7529. }
  7530. };
  7531. Ajax.prototype.showError = function () {
  7532. this.hideLoader();
  7533. while (this.msgElement.firstChild) {
  7534. this.msgElement.removeChild(this.msgElement.firstChild);
  7535. }this.msgElement.classList.remove("tabulator-loading");
  7536. this.msgElement.classList.add("tabulator-error");
  7537. if (this.errorElement) {
  7538. this.msgElement.appendChild(this.errorElement);
  7539. } else {
  7540. this.msgElement.innerHTML = this.table.modules.localize.getText("ajax|error");
  7541. }
  7542. this.table.element.appendChild(this.loaderElement);
  7543. };
  7544. Ajax.prototype.hideLoader = function () {
  7545. if (this.loaderElement.parentNode) {
  7546. this.loaderElement.parentNode.removeChild(this.loaderElement);
  7547. }
  7548. };
  7549. //default ajax config object
  7550. Ajax.prototype.defaultConfig = {
  7551. method: "GET"
  7552. };
  7553. Ajax.prototype.defaultURLGenerator = function (url, config, params) {
  7554. if (url) {
  7555. if (params && Object.keys(params).length) {
  7556. if (!config.method || config.method.toLowerCase() == "get") {
  7557. config.method = "get";
  7558. url += (url.includes("?") ? "&" : "?") + this.serializeParams(params);
  7559. }
  7560. }
  7561. }
  7562. return url;
  7563. };
  7564. Ajax.prototype.defaultLoaderPromise = function (url, config, params) {
  7565. var self = this,
  7566. contentType;
  7567. return new Promise(function (resolve, reject) {
  7568. //set url
  7569. url = self.urlGenerator(url, config, params);
  7570. //set body content if not GET request
  7571. if (config.method.toUpperCase() != "GET") {
  7572. contentType = _typeof(self.table.options.ajaxContentType) === "object" ? self.table.options.ajaxContentType : self.contentTypeFormatters[self.table.options.ajaxContentType];
  7573. if (contentType) {
  7574. for (var key in contentType.headers) {
  7575. if (!config.headers) {
  7576. config.headers = {};
  7577. }
  7578. if (typeof config.headers[key] === "undefined") {
  7579. config.headers[key] = contentType.headers[key];
  7580. }
  7581. }
  7582. config.body = contentType.body.call(self, url, config, params);
  7583. } else {
  7584. console.warn("Ajax Error - Invalid ajaxContentType value:", self.table.options.ajaxContentType);
  7585. }
  7586. }
  7587. if (url) {
  7588. //configure headers
  7589. if (typeof config.headers === "undefined") {
  7590. config.headers = {};
  7591. }
  7592. if (typeof config.headers.Accept === "undefined") {
  7593. config.headers.Accept = "application/json";
  7594. }
  7595. if (typeof config.headers["X-Requested-With"] === "undefined") {
  7596. config.headers["X-Requested-With"] = "XMLHttpRequest";
  7597. }
  7598. if (typeof config.mode === "undefined") {
  7599. config.mode = "cors";
  7600. }
  7601. if (config.mode == "cors") {
  7602. if (typeof config.headers["Access-Control-Allow-Origin"] === "undefined") {
  7603. config.headers["Access-Control-Allow-Origin"] = window.location.origin;
  7604. }
  7605. if (typeof config.credentials === "undefined") {
  7606. config.credentials = 'same-origin';
  7607. }
  7608. } else {
  7609. if (typeof config.credentials === "undefined") {
  7610. config.credentials = 'include';
  7611. }
  7612. }
  7613. //send request
  7614. fetch(url, config).then(function (response) {
  7615. if (response.ok) {
  7616. response.json().then(function (data) {
  7617. resolve(data);
  7618. }).catch(function (error) {
  7619. reject(error);
  7620. console.warn("Ajax Load Error - Invalid JSON returned", error);
  7621. });
  7622. } else {
  7623. console.error("Ajax Load Error - Connection Error: " + response.status, response.statusText);
  7624. reject(response);
  7625. }
  7626. }).catch(function (error) {
  7627. console.error("Ajax Load Error - Connection Error: ", error);
  7628. reject(error);
  7629. });
  7630. } else {
  7631. console.warn("Ajax Load Error - No URL Set");
  7632. resolve([]);
  7633. }
  7634. });
  7635. };
  7636. Ajax.prototype.contentTypeFormatters = {
  7637. "json": {
  7638. headers: {
  7639. 'Content-Type': 'application/json'
  7640. },
  7641. body: function body(url, config, params) {
  7642. return JSON.stringify(params);
  7643. }
  7644. },
  7645. "form": {
  7646. headers: {},
  7647. body: function body(url, config, params) {
  7648. var output = this.generateParamsList(params),
  7649. form = new FormData();
  7650. output.forEach(function (item) {
  7651. form.append(item.key, item.value);
  7652. });
  7653. return form;
  7654. }
  7655. }
  7656. };
  7657. Tabulator.prototype.registerModule("ajax", Ajax);
  7658. //public calc object
  7659. var CalcComponent = function CalcComponent(row) {
  7660. this._row = row;
  7661. };
  7662. CalcComponent.prototype.getData = function (transform) {
  7663. return this._row.getData(transform);
  7664. };
  7665. CalcComponent.prototype.getElement = function () {
  7666. return this._row.getElement();
  7667. };
  7668. CalcComponent.prototype.getTable = function () {
  7669. return this._row.table;
  7670. };
  7671. CalcComponent.prototype.getCells = function () {
  7672. var cells = [];
  7673. this._row.getCells().forEach(function (cell) {
  7674. cells.push(cell.getComponent());
  7675. });
  7676. return cells;
  7677. };
  7678. CalcComponent.prototype.getCell = function (column) {
  7679. var cell = this._row.getCell(column);
  7680. return cell ? cell.getComponent() : false;
  7681. };
  7682. CalcComponent.prototype._getSelf = function () {
  7683. return this._row;
  7684. };
  7685. var ColumnCalcs = function ColumnCalcs(table) {
  7686. this.table = table; //hold Tabulator object
  7687. this.topCalcs = [];
  7688. this.botCalcs = [];
  7689. this.genColumn = false;
  7690. this.topElement = this.createElement();
  7691. this.botElement = this.createElement();
  7692. this.topRow = false;
  7693. this.botRow = false;
  7694. this.topInitialized = false;
  7695. this.botInitialized = false;
  7696. this.initialize();
  7697. };
  7698. ColumnCalcs.prototype.createElement = function () {
  7699. var el = document.createElement("div");
  7700. el.classList.add("tabulator-calcs-holder");
  7701. return el;
  7702. };
  7703. ColumnCalcs.prototype.initialize = function () {
  7704. this.genColumn = new Column({ field: "value" }, this);
  7705. };
  7706. //dummy functions to handle being mock column manager
  7707. ColumnCalcs.prototype.registerColumnField = function () {};
  7708. //initialize column calcs
  7709. ColumnCalcs.prototype.initializeColumn = function (column) {
  7710. var def = column.definition;
  7711. var config = {
  7712. topCalcParams: def.topCalcParams || {},
  7713. botCalcParams: def.bottomCalcParams || {}
  7714. };
  7715. if (def.topCalc) {
  7716. switch (_typeof(def.topCalc)) {
  7717. case "string":
  7718. if (this.calculations[def.topCalc]) {
  7719. config.topCalc = this.calculations[def.topCalc];
  7720. } else {
  7721. console.warn("Column Calc Error - No such calculation found, ignoring: ", def.topCalc);
  7722. }
  7723. break;
  7724. case "function":
  7725. config.topCalc = def.topCalc;
  7726. break;
  7727. }
  7728. if (config.topCalc) {
  7729. column.modules.columnCalcs = config;
  7730. this.topCalcs.push(column);
  7731. if (this.table.options.columnCalcs != "group") {
  7732. this.initializeTopRow();
  7733. }
  7734. }
  7735. }
  7736. if (def.bottomCalc) {
  7737. switch (_typeof(def.bottomCalc)) {
  7738. case "string":
  7739. if (this.calculations[def.bottomCalc]) {
  7740. config.botCalc = this.calculations[def.bottomCalc];
  7741. } else {
  7742. console.warn("Column Calc Error - No such calculation found, ignoring: ", def.bottomCalc);
  7743. }
  7744. break;
  7745. case "function":
  7746. config.botCalc = def.bottomCalc;
  7747. break;
  7748. }
  7749. if (config.botCalc) {
  7750. column.modules.columnCalcs = config;
  7751. this.botCalcs.push(column);
  7752. if (this.table.options.columnCalcs != "group") {
  7753. this.initializeBottomRow();
  7754. }
  7755. }
  7756. }
  7757. };
  7758. ColumnCalcs.prototype.removeCalcs = function () {
  7759. var changed = false;
  7760. if (this.topInitialized) {
  7761. this.topInitialized = false;
  7762. this.topElement.parentNode.removeChild(this.topElement);
  7763. changed = true;
  7764. }
  7765. if (this.botInitialized) {
  7766. this.botInitialized = false;
  7767. this.table.footerManager.remove(this.botElement);
  7768. changed = true;
  7769. }
  7770. if (changed) {
  7771. this.table.rowManager.adjustTableSize();
  7772. }
  7773. };
  7774. ColumnCalcs.prototype.initializeTopRow = function () {
  7775. if (!this.topInitialized) {
  7776. // this.table.columnManager.headersElement.after(this.topElement);
  7777. this.table.columnManager.getElement().insertBefore(this.topElement, this.table.columnManager.headersElement.nextSibling);
  7778. this.topInitialized = true;
  7779. }
  7780. };
  7781. ColumnCalcs.prototype.initializeBottomRow = function () {
  7782. if (!this.botInitialized) {
  7783. this.table.footerManager.prepend(this.botElement);
  7784. this.botInitialized = true;
  7785. }
  7786. };
  7787. ColumnCalcs.prototype.scrollHorizontal = function (left) {
  7788. var hozAdjust = 0,
  7789. scrollWidth = this.table.columnManager.getElement().scrollWidth - this.table.element.clientWidth;
  7790. if (this.botInitialized && this.botRow) {
  7791. this.botRow.getElement().style.marginLeft = -left + "px";
  7792. }
  7793. };
  7794. ColumnCalcs.prototype.recalc = function (rows) {
  7795. var data, row;
  7796. if (this.topInitialized || this.botInitialized) {
  7797. data = this.rowsToData(rows);
  7798. if (this.topInitialized) {
  7799. if (this.topRow) {
  7800. this.topRow.deleteCells();
  7801. }
  7802. row = this.generateRow("top", this.rowsToData(rows));
  7803. this.topRow = row;
  7804. while (this.topElement.firstChild) {
  7805. this.topElement.removeChild(this.topElement.firstChild);
  7806. }this.topElement.appendChild(row.getElement());
  7807. row.initialize(true);
  7808. }
  7809. if (this.botInitialized) {
  7810. if (this.botRow) {
  7811. this.botRow.deleteCells();
  7812. }
  7813. row = this.generateRow("bottom", this.rowsToData(rows));
  7814. this.botRow = row;
  7815. while (this.botElement.firstChild) {
  7816. this.botElement.removeChild(this.botElement.firstChild);
  7817. }this.botElement.appendChild(row.getElement());
  7818. row.initialize(true);
  7819. }
  7820. this.table.rowManager.adjustTableSize();
  7821. //set resizable handles
  7822. if (this.table.modExists("frozenColumns")) {
  7823. this.table.modules.frozenColumns.layout();
  7824. }
  7825. }
  7826. };
  7827. ColumnCalcs.prototype.recalcRowGroup = function (row) {
  7828. this.recalcGroup(this.table.modules.groupRows.getRowGroup(row));
  7829. };
  7830. ColumnCalcs.prototype.recalcAll = function () {
  7831. var _this44 = this;
  7832. if (this.topCalcs.length || this.botCalcs.length) {
  7833. if (this.table.options.columnCalcs !== "group") {
  7834. this.recalc(this.table.rowManager.activeRows);
  7835. }
  7836. if (this.table.options.groupBy && this.table.options.columnCalcs !== "table") {
  7837. var groups = table.modules.groupRows.getChildGroups();
  7838. groups.forEach(function (group) {
  7839. _this44.recalcGroup(group);
  7840. });
  7841. }
  7842. }
  7843. };
  7844. ColumnCalcs.prototype.recalcGroup = function (group) {
  7845. var data, rowData;
  7846. if (group) {
  7847. if (group.calcs) {
  7848. if (group.calcs.bottom) {
  7849. data = this.rowsToData(group.rows);
  7850. rowData = this.generateRowData("bottom", data);
  7851. group.calcs.bottom.updateData(rowData);
  7852. group.calcs.bottom.reinitialize();
  7853. }
  7854. if (group.calcs.top) {
  7855. data = this.rowsToData(group.rows);
  7856. rowData = this.generateRowData("top", data);
  7857. group.calcs.top.updateData(rowData);
  7858. group.calcs.top.reinitialize();
  7859. }
  7860. }
  7861. }
  7862. };
  7863. //generate top stats row
  7864. ColumnCalcs.prototype.generateTopRow = function (rows) {
  7865. return this.generateRow("top", this.rowsToData(rows));
  7866. };
  7867. //generate bottom stats row
  7868. ColumnCalcs.prototype.generateBottomRow = function (rows) {
  7869. return this.generateRow("bottom", this.rowsToData(rows));
  7870. };
  7871. ColumnCalcs.prototype.rowsToData = function (rows) {
  7872. var _this45 = this;
  7873. var data = [];
  7874. rows.forEach(function (row) {
  7875. data.push(row.getData());
  7876. if (_this45.table.options.dataTree && _this45.table.options.dataTreeChildColumnCalcs) {
  7877. if (row.modules.dataTree.open) {
  7878. var children = _this45.rowsToData(_this45.table.modules.dataTree.getFilteredTreeChildren(row));
  7879. data = data.concat(children);
  7880. }
  7881. }
  7882. });
  7883. return data;
  7884. };
  7885. //generate stats row
  7886. ColumnCalcs.prototype.generateRow = function (pos, data) {
  7887. var self = this,
  7888. rowData = this.generateRowData(pos, data),
  7889. row;
  7890. if (self.table.modExists("mutator")) {
  7891. self.table.modules.mutator.disable();
  7892. }
  7893. row = new Row(rowData, this, "calc");
  7894. if (self.table.modExists("mutator")) {
  7895. self.table.modules.mutator.enable();
  7896. }
  7897. row.getElement().classList.add("tabulator-calcs", "tabulator-calcs-" + pos);
  7898. row.component = false;
  7899. row.getComponent = function () {
  7900. if (!this.component) {
  7901. this.component = new CalcComponent(this);
  7902. }
  7903. return this.component;
  7904. };
  7905. row.generateCells = function () {
  7906. var cells = [];
  7907. self.table.columnManager.columnsByIndex.forEach(function (column) {
  7908. //set field name of mock column
  7909. self.genColumn.setField(column.getField());
  7910. self.genColumn.hozAlign = column.hozAlign;
  7911. if (column.definition[pos + "CalcFormatter"] && self.table.modExists("format")) {
  7912. self.genColumn.modules.format = {
  7913. formatter: self.table.modules.format.getFormatter(column.definition[pos + "CalcFormatter"]),
  7914. params: column.definition[pos + "CalcFormatterParams"] || {}
  7915. };
  7916. } else {
  7917. self.genColumn.modules.format = {
  7918. formatter: self.table.modules.format.getFormatter("plaintext"),
  7919. params: {}
  7920. };
  7921. }
  7922. //ensure css class defintion is replicated to calculation cell
  7923. self.genColumn.definition.cssClass = column.definition.cssClass;
  7924. //generate cell and assign to correct column
  7925. var cell = new Cell(self.genColumn, row);
  7926. cell.getElement();
  7927. cell.column = column;
  7928. cell.setWidth();
  7929. column.cells.push(cell);
  7930. cells.push(cell);
  7931. if (!column.visible) {
  7932. cell.hide();
  7933. }
  7934. });
  7935. this.cells = cells;
  7936. };
  7937. return row;
  7938. };
  7939. //generate stats row
  7940. ColumnCalcs.prototype.generateRowData = function (pos, data) {
  7941. var rowData = {},
  7942. calcs = pos == "top" ? this.topCalcs : this.botCalcs,
  7943. type = pos == "top" ? "topCalc" : "botCalc",
  7944. params,
  7945. paramKey;
  7946. calcs.forEach(function (column) {
  7947. var values = [];
  7948. if (column.modules.columnCalcs && column.modules.columnCalcs[type]) {
  7949. data.forEach(function (item) {
  7950. values.push(column.getFieldValue(item));
  7951. });
  7952. paramKey = type + "Params";
  7953. params = typeof column.modules.columnCalcs[paramKey] === "function" ? column.modules.columnCalcs[paramKey](values, data) : column.modules.columnCalcs[paramKey];
  7954. column.setFieldValue(rowData, column.modules.columnCalcs[type](values, data, params));
  7955. }
  7956. });
  7957. return rowData;
  7958. };
  7959. ColumnCalcs.prototype.hasTopCalcs = function () {
  7960. return !!this.topCalcs.length;
  7961. };
  7962. ColumnCalcs.prototype.hasBottomCalcs = function () {
  7963. return !!this.botCalcs.length;
  7964. };
  7965. //handle table redraw
  7966. ColumnCalcs.prototype.redraw = function () {
  7967. if (this.topRow) {
  7968. this.topRow.normalizeHeight(true);
  7969. }
  7970. if (this.botRow) {
  7971. this.botRow.normalizeHeight(true);
  7972. }
  7973. };
  7974. //return the calculated
  7975. ColumnCalcs.prototype.getResults = function () {
  7976. var self = this,
  7977. results = {},
  7978. groups;
  7979. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  7980. groups = this.table.modules.groupRows.getGroups(true);
  7981. groups.forEach(function (group) {
  7982. results[group.getKey()] = self.getGroupResults(group);
  7983. });
  7984. } else {
  7985. results = {
  7986. top: this.topRow ? this.topRow.getData() : {},
  7987. bottom: this.botRow ? this.botRow.getData() : {}
  7988. };
  7989. }
  7990. return results;
  7991. };
  7992. //get results from a group
  7993. ColumnCalcs.prototype.getGroupResults = function (group) {
  7994. var self = this,
  7995. groupObj = group._getSelf(),
  7996. subGroups = group.getSubGroups(),
  7997. subGroupResults = {},
  7998. results = {};
  7999. subGroups.forEach(function (subgroup) {
  8000. subGroupResults[subgroup.getKey()] = self.getGroupResults(subgroup);
  8001. });
  8002. results = {
  8003. top: groupObj.calcs.top ? groupObj.calcs.top.getData() : {},
  8004. bottom: groupObj.calcs.bottom ? groupObj.calcs.bottom.getData() : {},
  8005. groups: subGroupResults
  8006. };
  8007. return results;
  8008. };
  8009. //default calculations
  8010. ColumnCalcs.prototype.calculations = {
  8011. "avg": function avg(values, data, calcParams) {
  8012. var output = 0,
  8013. precision = typeof calcParams.precision !== "undefined" ? calcParams.precision : 2;
  8014. if (values.length) {
  8015. output = values.reduce(function (sum, value) {
  8016. value = Number(value);
  8017. return sum + value;
  8018. });
  8019. output = output / values.length;
  8020. output = precision !== false ? output.toFixed(precision) : output;
  8021. }
  8022. return parseFloat(output).toString();
  8023. },
  8024. "max": function max(values, data, calcParams) {
  8025. var output = null,
  8026. precision = typeof calcParams.precision !== "undefined" ? calcParams.precision : false;
  8027. values.forEach(function (value) {
  8028. value = Number(value);
  8029. if (value > output || output === null) {
  8030. output = value;
  8031. }
  8032. });
  8033. return output !== null ? precision !== false ? output.toFixed(precision) : output : "";
  8034. },
  8035. "min": function min(values, data, calcParams) {
  8036. var output = null,
  8037. precision = typeof calcParams.precision !== "undefined" ? calcParams.precision : false;
  8038. values.forEach(function (value) {
  8039. value = Number(value);
  8040. if (value < output || output === null) {
  8041. output = value;
  8042. }
  8043. });
  8044. return output !== null ? precision !== false ? output.toFixed(precision) : output : "";
  8045. },
  8046. "sum": function sum(values, data, calcParams) {
  8047. var output = 0,
  8048. precision = typeof calcParams.precision !== "undefined" ? calcParams.precision : false;
  8049. if (values.length) {
  8050. values.forEach(function (value) {
  8051. value = Number(value);
  8052. output += !isNaN(value) ? Number(value) : 0;
  8053. });
  8054. }
  8055. return precision !== false ? output.toFixed(precision) : output;
  8056. },
  8057. "concat": function concat(values, data, calcParams) {
  8058. var output = 0;
  8059. if (values.length) {
  8060. output = values.reduce(function (sum, value) {
  8061. return String(sum) + String(value);
  8062. });
  8063. }
  8064. return output;
  8065. },
  8066. "count": function count(values, data, calcParams) {
  8067. var output = 0;
  8068. if (values.length) {
  8069. values.forEach(function (value) {
  8070. if (value) {
  8071. output++;
  8072. }
  8073. });
  8074. }
  8075. return output;
  8076. }
  8077. };
  8078. Tabulator.prototype.registerModule("columnCalcs", ColumnCalcs);
  8079. var Clipboard = function Clipboard(table) {
  8080. this.table = table;
  8081. this.mode = true;
  8082. this.pasteParser = function () {};
  8083. this.pasteAction = function () {};
  8084. this.customSelection = false;
  8085. this.rowRange = false;
  8086. this.blocked = true; //block copy actions not originating from this command
  8087. };
  8088. Clipboard.prototype.initialize = function () {
  8089. var _this46 = this;
  8090. this.mode = this.table.options.clipboard;
  8091. this.rowRange = this.table.options.clipboardCopyRowRange;
  8092. if (this.mode === true || this.mode === "copy") {
  8093. this.table.element.addEventListener("copy", function (e) {
  8094. var plain, html, list;
  8095. if (!_this46.blocked) {
  8096. e.preventDefault();
  8097. if (_this46.customSelection) {
  8098. plain = _this46.customSelection;
  8099. if (_this46.table.options.clipboardCopyFormatter) {
  8100. plain = _this46.table.options.clipboardCopyFormatter("plain", plain);
  8101. }
  8102. } else {
  8103. var list = _this46.table.modules.export.generateExportList(_this46.rowRange, _this46.table.options.clipboardCopyStyled, _this46.table.options.clipboardCopyConfig, "clipboard");
  8104. html = _this46.table.modules.export.genereateHTMLTable(list);
  8105. plain = html ? _this46.generatePlainContent(list) : "";
  8106. if (_this46.table.options.clipboardCopyFormatter) {
  8107. plain = _this46.table.options.clipboardCopyFormatter("plain", plain);
  8108. html = _this46.table.options.clipboardCopyFormatter("html", html);
  8109. }
  8110. }
  8111. if (window.clipboardData && window.clipboardData.setData) {
  8112. window.clipboardData.setData('Text', plain);
  8113. } else if (e.clipboardData && e.clipboardData.setData) {
  8114. e.clipboardData.setData('text/plain', plain);
  8115. if (html) {
  8116. e.clipboardData.setData('text/html', html);
  8117. }
  8118. } else if (e.originalEvent && e.originalEvent.clipboardData.setData) {
  8119. e.originalEvent.clipboardData.setData('text/plain', plain);
  8120. if (html) {
  8121. e.originalEvent.clipboardData.setData('text/html', html);
  8122. }
  8123. }
  8124. _this46.table.options.clipboardCopied.call(_this46.table, plain, html);
  8125. _this46.reset();
  8126. }
  8127. });
  8128. }
  8129. if (this.mode === true || this.mode === "paste") {
  8130. this.table.element.addEventListener("paste", function (e) {
  8131. _this46.paste(e);
  8132. });
  8133. }
  8134. this.setPasteParser(this.table.options.clipboardPasteParser);
  8135. this.setPasteAction(this.table.options.clipboardPasteAction);
  8136. };
  8137. Clipboard.prototype.reset = function () {
  8138. this.blocked = false;
  8139. this.originalSelectionText = "";
  8140. };
  8141. Clipboard.prototype.generatePlainContent = function (list) {
  8142. var output = [];
  8143. list.forEach(function (row) {
  8144. var rowData = [];
  8145. row.columns.forEach(function (col) {
  8146. var value = "";
  8147. if (col) {
  8148. if (row.type === "group") {
  8149. col.value = col.component.getKey();
  8150. }
  8151. if (col.value === null) {
  8152. value = "";
  8153. } else {
  8154. switch (_typeof(col.value)) {
  8155. case "object":
  8156. value = JSON.stringify(col.value);
  8157. break;
  8158. case "undefined":
  8159. value = "";
  8160. break;
  8161. default:
  8162. value = col.value;
  8163. }
  8164. }
  8165. }
  8166. rowData.push(value);
  8167. });
  8168. output.push(rowData.join("\t"));
  8169. });
  8170. return output.join("\n");
  8171. };
  8172. Clipboard.prototype.copy = function (range, internal) {
  8173. var range, sel, textRange;
  8174. this.blocked = false;
  8175. this.customSelection = false;
  8176. if (this.mode === true || this.mode === "copy") {
  8177. this.rowRange = range || this.table.options.clipboardCopyRowRange;
  8178. if (typeof window.getSelection != "undefined" && typeof document.createRange != "undefined") {
  8179. range = document.createRange();
  8180. range.selectNodeContents(this.table.element);
  8181. sel = window.getSelection();
  8182. if (sel.toString() && internal) {
  8183. this.customSelection = sel.toString();
  8184. }
  8185. sel.removeAllRanges();
  8186. sel.addRange(range);
  8187. } else if (typeof document.selection != "undefined" && typeof document.body.createTextRange != "undefined") {
  8188. textRange = document.body.createTextRange();
  8189. textRange.moveToElementText(this.table.element);
  8190. textRange.select();
  8191. }
  8192. document.execCommand('copy');
  8193. if (sel) {
  8194. sel.removeAllRanges();
  8195. }
  8196. }
  8197. };
  8198. //PASTE EVENT HANDLING
  8199. Clipboard.prototype.setPasteAction = function (action) {
  8200. switch (typeof action === 'undefined' ? 'undefined' : _typeof(action)) {
  8201. case "string":
  8202. this.pasteAction = this.pasteActions[action];
  8203. if (!this.pasteAction) {
  8204. console.warn("Clipboard Error - No such paste action found:", action);
  8205. }
  8206. break;
  8207. case "function":
  8208. this.pasteAction = action;
  8209. break;
  8210. }
  8211. };
  8212. Clipboard.prototype.setPasteParser = function (parser) {
  8213. switch (typeof parser === 'undefined' ? 'undefined' : _typeof(parser)) {
  8214. case "string":
  8215. this.pasteParser = this.pasteParsers[parser];
  8216. if (!this.pasteParser) {
  8217. console.warn("Clipboard Error - No such paste parser found:", parser);
  8218. }
  8219. break;
  8220. case "function":
  8221. this.pasteParser = parser;
  8222. break;
  8223. }
  8224. };
  8225. Clipboard.prototype.paste = function (e) {
  8226. var data, rowData, rows;
  8227. if (this.checkPaseOrigin(e)) {
  8228. data = this.getPasteData(e);
  8229. rowData = this.pasteParser.call(this, data);
  8230. if (rowData) {
  8231. e.preventDefault();
  8232. if (this.table.modExists("mutator")) {
  8233. rowData = this.mutateData(rowData);
  8234. }
  8235. rows = this.pasteAction.call(this, rowData);
  8236. this.table.options.clipboardPasted.call(this.table, data, rowData, rows);
  8237. } else {
  8238. this.table.options.clipboardPasteError.call(this.table, data);
  8239. }
  8240. }
  8241. };
  8242. Clipboard.prototype.mutateData = function (data) {
  8243. var self = this,
  8244. output = [];
  8245. if (Array.isArray(data)) {
  8246. data.forEach(function (row) {
  8247. output.push(self.table.modules.mutator.transformRow(row, "clipboard"));
  8248. });
  8249. } else {
  8250. output = data;
  8251. }
  8252. return output;
  8253. };
  8254. Clipboard.prototype.checkPaseOrigin = function (e) {
  8255. var valid = true;
  8256. if (e.target.tagName != "DIV" || this.table.modules.edit.currentCell) {
  8257. valid = false;
  8258. }
  8259. return valid;
  8260. };
  8261. Clipboard.prototype.getPasteData = function (e) {
  8262. var data;
  8263. if (window.clipboardData && window.clipboardData.getData) {
  8264. data = window.clipboardData.getData('Text');
  8265. } else if (e.clipboardData && e.clipboardData.getData) {
  8266. data = e.clipboardData.getData('text/plain');
  8267. } else if (e.originalEvent && e.originalEvent.clipboardData.getData) {
  8268. data = e.originalEvent.clipboardData.getData('text/plain');
  8269. }
  8270. return data;
  8271. };
  8272. Clipboard.prototype.pasteParsers = {
  8273. table: function table(clipboard) {
  8274. var data = [],
  8275. success = false,
  8276. headerFindSuccess = true,
  8277. columns = this.table.columnManager.columns,
  8278. columnMap = [],
  8279. rows = [];
  8280. //get data from clipboard into array of columns and rows.
  8281. clipboard = clipboard.split("\n");
  8282. clipboard.forEach(function (row) {
  8283. data.push(row.split("\t"));
  8284. });
  8285. if (data.length && !(data.length === 1 && data[0].length < 2)) {
  8286. success = true;
  8287. //check if headers are present by title
  8288. data[0].forEach(function (value) {
  8289. var column = columns.find(function (column) {
  8290. return value && column.definition.title && value.trim() && column.definition.title.trim() === value.trim();
  8291. });
  8292. if (column) {
  8293. columnMap.push(column);
  8294. } else {
  8295. headerFindSuccess = false;
  8296. }
  8297. });
  8298. //check if column headers are present by field
  8299. if (!headerFindSuccess) {
  8300. headerFindSuccess = true;
  8301. columnMap = [];
  8302. data[0].forEach(function (value) {
  8303. var column = columns.find(function (column) {
  8304. return value && column.field && value.trim() && column.field.trim() === value.trim();
  8305. });
  8306. if (column) {
  8307. columnMap.push(column);
  8308. } else {
  8309. headerFindSuccess = false;
  8310. }
  8311. });
  8312. if (!headerFindSuccess) {
  8313. columnMap = this.table.columnManager.columnsByIndex;
  8314. }
  8315. }
  8316. //remove header row if found
  8317. if (headerFindSuccess) {
  8318. data.shift();
  8319. }
  8320. data.forEach(function (item) {
  8321. var row = {};
  8322. item.forEach(function (value, i) {
  8323. if (columnMap[i]) {
  8324. row[columnMap[i].field] = value;
  8325. }
  8326. });
  8327. rows.push(row);
  8328. });
  8329. return rows;
  8330. } else {
  8331. return false;
  8332. }
  8333. }
  8334. };
  8335. Clipboard.prototype.pasteActions = {
  8336. replace: function replace(rows) {
  8337. return this.table.setData(rows);
  8338. },
  8339. update: function update(rows) {
  8340. return this.table.updateOrAddData(rows);
  8341. },
  8342. insert: function insert(rows) {
  8343. return this.table.addData(rows);
  8344. }
  8345. };
  8346. Tabulator.prototype.registerModule("clipboard", Clipboard);
  8347. var DataTree = function DataTree(table) {
  8348. this.table = table;
  8349. this.indent = 10;
  8350. this.field = "";
  8351. this.collapseEl = null;
  8352. this.expandEl = null;
  8353. this.branchEl = null;
  8354. this.elementField = false;
  8355. this.startOpen = function () {};
  8356. this.displayIndex = 0;
  8357. };
  8358. DataTree.prototype.initialize = function () {
  8359. var dummyEl = null,
  8360. firstCol = this.table.columnManager.getFirstVisibileColumn(),
  8361. options = this.table.options;
  8362. this.field = options.dataTreeChildField;
  8363. this.indent = options.dataTreeChildIndent;
  8364. this.elementField = options.dataTreeElementColumn || (firstCol ? firstCol.field : false);
  8365. if (options.dataTreeBranchElement) {
  8366. if (options.dataTreeBranchElement === true) {
  8367. this.branchEl = document.createElement("div");
  8368. this.branchEl.classList.add("tabulator-data-tree-branch");
  8369. } else {
  8370. if (typeof options.dataTreeBranchElement === "string") {
  8371. dummyEl = document.createElement("div");
  8372. dummyEl.innerHTML = options.dataTreeBranchElement;
  8373. this.branchEl = dummyEl.firstChild;
  8374. } else {
  8375. this.branchEl = options.dataTreeBranchElement;
  8376. }
  8377. }
  8378. }
  8379. if (options.dataTreeCollapseElement) {
  8380. if (typeof options.dataTreeCollapseElement === "string") {
  8381. dummyEl = document.createElement("div");
  8382. dummyEl.innerHTML = options.dataTreeCollapseElement;
  8383. this.collapseEl = dummyEl.firstChild;
  8384. } else {
  8385. this.collapseEl = options.dataTreeCollapseElement;
  8386. }
  8387. } else {
  8388. this.collapseEl = document.createElement("div");
  8389. this.collapseEl.classList.add("tabulator-data-tree-control");
  8390. this.collapseEl.tabIndex = 0;
  8391. this.collapseEl.innerHTML = "<div class='tabulator-data-tree-control-collapse'></div>";
  8392. }
  8393. if (options.dataTreeExpandElement) {
  8394. if (typeof options.dataTreeExpandElement === "string") {
  8395. dummyEl = document.createElement("div");
  8396. dummyEl.innerHTML = options.dataTreeExpandElement;
  8397. this.expandEl = dummyEl.firstChild;
  8398. } else {
  8399. this.expandEl = options.dataTreeExpandElement;
  8400. }
  8401. } else {
  8402. this.expandEl = document.createElement("div");
  8403. this.expandEl.classList.add("tabulator-data-tree-control");
  8404. this.expandEl.tabIndex = 0;
  8405. this.expandEl.innerHTML = "<div class='tabulator-data-tree-control-expand'></div>";
  8406. }
  8407. switch (_typeof(options.dataTreeStartExpanded)) {
  8408. case "boolean":
  8409. this.startOpen = function (row, index) {
  8410. return options.dataTreeStartExpanded;
  8411. };
  8412. break;
  8413. case "function":
  8414. this.startOpen = options.dataTreeStartExpanded;
  8415. break;
  8416. default:
  8417. this.startOpen = function (row, index) {
  8418. return options.dataTreeStartExpanded[index];
  8419. };
  8420. break;
  8421. }
  8422. };
  8423. DataTree.prototype.initializeRow = function (row) {
  8424. var childArray = row.getData()[this.field];
  8425. var isArray = Array.isArray(childArray);
  8426. var children = isArray || !isArray && (typeof childArray === 'undefined' ? 'undefined' : _typeof(childArray)) === "object" && childArray !== null;
  8427. if (!children && row.modules.dataTree && row.modules.dataTree.branchEl) {
  8428. row.modules.dataTree.branchEl.parentNode.removeChild(row.modules.dataTree.branchEl);
  8429. }
  8430. if (!children && row.modules.dataTree && row.modules.dataTree.controlEl) {
  8431. row.modules.dataTree.controlEl.parentNode.removeChild(row.modules.dataTree.controlEl);
  8432. }
  8433. row.modules.dataTree = {
  8434. index: row.modules.dataTree ? row.modules.dataTree.index : 0,
  8435. open: children ? row.modules.dataTree ? row.modules.dataTree.open : this.startOpen(row.getComponent(), 0) : false,
  8436. controlEl: row.modules.dataTree && children ? row.modules.dataTree.controlEl : false,
  8437. branchEl: row.modules.dataTree && children ? row.modules.dataTree.branchEl : false,
  8438. parent: row.modules.dataTree ? row.modules.dataTree.parent : false,
  8439. children: children
  8440. };
  8441. };
  8442. DataTree.prototype.layoutRow = function (row) {
  8443. var cell = this.elementField ? row.getCell(this.elementField) : row.getCells()[0],
  8444. el = cell.getElement(),
  8445. config = row.modules.dataTree;
  8446. if (config.branchEl) {
  8447. if (config.branchEl.parentNode) {
  8448. config.branchEl.parentNode.removeChild(config.branchEl);
  8449. }
  8450. config.branchEl = false;
  8451. }
  8452. if (config.controlEl) {
  8453. if (config.controlEl.parentNode) {
  8454. config.controlEl.parentNode.removeChild(config.controlEl);
  8455. }
  8456. config.controlEl = false;
  8457. }
  8458. this.generateControlElement(row, el);
  8459. row.element.classList.add("tabulator-tree-level-" + config.index);
  8460. if (config.index) {
  8461. if (this.branchEl) {
  8462. config.branchEl = this.branchEl.cloneNode(true);
  8463. el.insertBefore(config.branchEl, el.firstChild);
  8464. if (this.table.rtl) {
  8465. config.branchEl.style.marginRight = (config.branchEl.offsetWidth + config.branchEl.style.marginLeft) * (config.index - 1) + config.index * this.indent + "px";
  8466. } else {
  8467. config.branchEl.style.marginLeft = (config.branchEl.offsetWidth + config.branchEl.style.marginRight) * (config.index - 1) + config.index * this.indent + "px";
  8468. }
  8469. } else {
  8470. if (this.table.rtl) {
  8471. el.style.paddingRight = parseInt(window.getComputedStyle(el, null).getPropertyValue('padding-right')) + config.index * this.indent + "px";
  8472. } else {
  8473. el.style.paddingLeft = parseInt(window.getComputedStyle(el, null).getPropertyValue('padding-left')) + config.index * this.indent + "px";
  8474. }
  8475. }
  8476. }
  8477. };
  8478. DataTree.prototype.generateControlElement = function (row, el) {
  8479. var _this47 = this;
  8480. var config = row.modules.dataTree,
  8481. el = el || row.getCells()[0].getElement(),
  8482. oldControl = config.controlEl;
  8483. if (config.children !== false) {
  8484. if (config.open) {
  8485. config.controlEl = this.collapseEl.cloneNode(true);
  8486. config.controlEl.addEventListener("click", function (e) {
  8487. e.stopPropagation();
  8488. _this47.collapseRow(row);
  8489. });
  8490. } else {
  8491. config.controlEl = this.expandEl.cloneNode(true);
  8492. config.controlEl.addEventListener("click", function (e) {
  8493. e.stopPropagation();
  8494. _this47.expandRow(row);
  8495. });
  8496. }
  8497. config.controlEl.addEventListener("mousedown", function (e) {
  8498. e.stopPropagation();
  8499. });
  8500. if (oldControl && oldControl.parentNode === el) {
  8501. oldControl.parentNode.replaceChild(config.controlEl, oldControl);
  8502. } else {
  8503. el.insertBefore(config.controlEl, el.firstChild);
  8504. }
  8505. }
  8506. };
  8507. DataTree.prototype.setDisplayIndex = function (index) {
  8508. this.displayIndex = index;
  8509. };
  8510. DataTree.prototype.getDisplayIndex = function () {
  8511. return this.displayIndex;
  8512. };
  8513. DataTree.prototype.getRows = function (rows) {
  8514. var _this48 = this;
  8515. var output = [];
  8516. rows.forEach(function (row, i) {
  8517. var config, children;
  8518. output.push(row);
  8519. if (row instanceof Row) {
  8520. config = row.modules.dataTree.children;
  8521. if (!config.index && config.children !== false) {
  8522. children = _this48.getChildren(row);
  8523. children.forEach(function (child) {
  8524. output.push(child);
  8525. });
  8526. }
  8527. }
  8528. });
  8529. return output;
  8530. };
  8531. DataTree.prototype.getChildren = function (row) {
  8532. var _this49 = this;
  8533. var config = row.modules.dataTree,
  8534. children = [],
  8535. output = [];
  8536. if (config.children !== false && config.open) {
  8537. if (!Array.isArray(config.children)) {
  8538. config.children = this.generateChildren(row);
  8539. }
  8540. if (this.table.modExists("filter") && this.table.options.dataTreeFilter) {
  8541. children = this.table.modules.filter.filter(config.children);
  8542. } else {
  8543. children = config.children;
  8544. }
  8545. if (this.table.modExists("sort") && this.table.options.dataTreeSort) {
  8546. this.table.modules.sort.sort(children);
  8547. }
  8548. children.forEach(function (child) {
  8549. output.push(child);
  8550. var subChildren = _this49.getChildren(child);
  8551. subChildren.forEach(function (sub) {
  8552. output.push(sub);
  8553. });
  8554. });
  8555. }
  8556. return output;
  8557. };
  8558. DataTree.prototype.generateChildren = function (row) {
  8559. var _this50 = this;
  8560. var children = [];
  8561. var childArray = row.getData()[this.field];
  8562. if (!Array.isArray(childArray)) {
  8563. childArray = [childArray];
  8564. }
  8565. childArray.forEach(function (childData) {
  8566. var childRow = new Row(childData || {}, _this50.table.rowManager);
  8567. childRow.modules.dataTree.index = row.modules.dataTree.index + 1;
  8568. childRow.modules.dataTree.parent = row;
  8569. if (childRow.modules.dataTree.children) {
  8570. childRow.modules.dataTree.open = _this50.startOpen(childRow.getComponent(), childRow.modules.dataTree.index);
  8571. }
  8572. children.push(childRow);
  8573. });
  8574. return children;
  8575. };
  8576. DataTree.prototype.expandRow = function (row, silent) {
  8577. var config = row.modules.dataTree;
  8578. if (config.children !== false) {
  8579. config.open = true;
  8580. row.reinitialize();
  8581. this.table.rowManager.refreshActiveData("tree", false, true);
  8582. this.table.options.dataTreeRowExpanded(row.getComponent(), row.modules.dataTree.index);
  8583. }
  8584. };
  8585. DataTree.prototype.collapseRow = function (row) {
  8586. var config = row.modules.dataTree;
  8587. if (config.children !== false) {
  8588. config.open = false;
  8589. row.reinitialize();
  8590. this.table.rowManager.refreshActiveData("tree", false, true);
  8591. this.table.options.dataTreeRowCollapsed(row.getComponent(), row.modules.dataTree.index);
  8592. }
  8593. };
  8594. DataTree.prototype.toggleRow = function (row) {
  8595. var config = row.modules.dataTree;
  8596. if (config.children !== false) {
  8597. if (config.open) {
  8598. this.collapseRow(row);
  8599. } else {
  8600. this.expandRow(row);
  8601. }
  8602. }
  8603. };
  8604. DataTree.prototype.getTreeParent = function (row) {
  8605. return row.modules.dataTree.parent ? row.modules.dataTree.parent.getComponent() : false;
  8606. };
  8607. DataTree.prototype.getFilteredTreeChildren = function (row) {
  8608. var config = row.modules.dataTree,
  8609. output = [],
  8610. children;
  8611. if (config.children) {
  8612. if (!Array.isArray(config.children)) {
  8613. config.children = this.generateChildren(row);
  8614. }
  8615. if (this.table.modExists("filter") && this.table.options.dataTreeFilter) {
  8616. children = this.table.modules.filter.filter(config.children);
  8617. } else {
  8618. children = config.children;
  8619. }
  8620. children.forEach(function (childRow) {
  8621. if (childRow instanceof Row) {
  8622. output.push(childRow);
  8623. }
  8624. });
  8625. }
  8626. return output;
  8627. };
  8628. DataTree.prototype.rowDelete = function (row) {
  8629. var parent = row.modules.dataTree.parent,
  8630. childIndex;
  8631. if (parent) {
  8632. childIndex = this.findChildIndex(row, parent);
  8633. if (childIndex !== false) {
  8634. parent.data[this.field].splice(childIndex, 1);
  8635. }
  8636. if (!parent.data[this.field].length) {
  8637. delete parent.data[this.field];
  8638. }
  8639. this.initializeRow(parent);
  8640. this.layoutRow(parent);
  8641. }
  8642. this.table.rowManager.refreshActiveData("tree", false, true);
  8643. };
  8644. DataTree.prototype.addTreeChildRow = function (row, data, top, index) {
  8645. var childIndex = false;
  8646. if (typeof data === "string") {
  8647. data = JSON.parse(data);
  8648. }
  8649. if (!Array.isArray(row.data[this.field])) {
  8650. row.data[this.field] = [];
  8651. row.modules.dataTree.open = this.startOpen(row.getComponent(), row.modules.dataTree.index);
  8652. }
  8653. if (typeof index !== "undefined") {
  8654. childIndex = this.findChildIndex(index, row);
  8655. if (childIndex !== false) {
  8656. row.data[this.field].splice(top ? childIndex : childIndex + 1, 0, data);
  8657. }
  8658. }
  8659. if (childIndex === false) {
  8660. if (top) {
  8661. row.data[this.field].unshift(data);
  8662. } else {
  8663. row.data[this.field].push(data);
  8664. }
  8665. }
  8666. this.initializeRow(row);
  8667. this.layoutRow(row);
  8668. this.table.rowManager.refreshActiveData("tree", false, true);
  8669. };
  8670. DataTree.prototype.findChildIndex = function (subject, parent) {
  8671. var _this51 = this;
  8672. var match = false;
  8673. if ((typeof subject === 'undefined' ? 'undefined' : _typeof(subject)) == "object") {
  8674. if (subject instanceof Row) {
  8675. //subject is row element
  8676. match = subject.data;
  8677. } else if (subject instanceof RowComponent) {
  8678. //subject is public row component
  8679. match = subject._getSelf().data;
  8680. } else if (typeof HTMLElement !== "undefined" && subject instanceof HTMLElement) {
  8681. if (parent.modules.dataTree) {
  8682. match = parent.modules.dataTree.children.find(function (childRow) {
  8683. return childRow instanceof Row ? childRow.element === subject : false;
  8684. });
  8685. if (match) {
  8686. match = match.data;
  8687. }
  8688. }
  8689. }
  8690. } else if (typeof subject == "undefined" || subject === null) {
  8691. match = false;
  8692. } else {
  8693. //subject should be treated as the index of the row
  8694. match = parent.data[this.field].find(function (row) {
  8695. return row.data[_this51.table.options.index] == subject;
  8696. });
  8697. }
  8698. if (match) {
  8699. if (Array.isArray(parent.data[this.field])) {
  8700. match = parent.data[this.field].indexOf(match);
  8701. }
  8702. if (match == -1) {
  8703. match = false;
  8704. }
  8705. }
  8706. //catch all for any other type of input
  8707. return match;
  8708. };
  8709. DataTree.prototype.getTreeChildren = function (row, component, recurse) {
  8710. var _this52 = this;
  8711. var config = row.modules.dataTree,
  8712. output = [];
  8713. if (config.children) {
  8714. if (!Array.isArray(config.children)) {
  8715. config.children = this.generateChildren(row);
  8716. }
  8717. config.children.forEach(function (childRow) {
  8718. if (childRow instanceof Row) {
  8719. output.push(component ? childRow.getComponent() : childRow);
  8720. if (recurse) {
  8721. output = output.concat(_this52.getTreeChildren(childRow, component, recurse));
  8722. }
  8723. }
  8724. });
  8725. }
  8726. return output;
  8727. };
  8728. DataTree.prototype.checkForRestyle = function (cell) {
  8729. if (!cell.row.cells.indexOf(cell)) {
  8730. cell.row.reinitialize();
  8731. }
  8732. };
  8733. DataTree.prototype.getChildField = function () {
  8734. return this.field;
  8735. };
  8736. DataTree.prototype.redrawNeeded = function (data) {
  8737. return (this.field ? typeof data[this.field] !== "undefined" : false) || (this.elementField ? typeof data[this.elementField] !== "undefined" : false);
  8738. };
  8739. Tabulator.prototype.registerModule("dataTree", DataTree);
  8740. var Download = function Download(table) {
  8741. this.table = table; //hold Tabulator object
  8742. };
  8743. //trigger file download
  8744. Download.prototype.download = function (type, filename, options, range, interceptCallback) {
  8745. var self = this,
  8746. downloadFunc = false;
  8747. function buildLink(data, mime) {
  8748. if (interceptCallback) {
  8749. if (interceptCallback === true) {
  8750. self.triggerDownload(data, mime, type, filename, true);
  8751. } else {
  8752. interceptCallback(data);
  8753. }
  8754. } else {
  8755. self.triggerDownload(data, mime, type, filename);
  8756. }
  8757. }
  8758. if (typeof type == "function") {
  8759. downloadFunc = type;
  8760. } else {
  8761. if (self.downloaders[type]) {
  8762. downloadFunc = self.downloaders[type];
  8763. } else {
  8764. console.warn("Download Error - No such download type found: ", type);
  8765. }
  8766. }
  8767. if (downloadFunc) {
  8768. var list = this.generateExportList(range);
  8769. downloadFunc.call(this.table, list, options || {}, buildLink);
  8770. }
  8771. };
  8772. Download.prototype.generateExportList = function (range) {
  8773. var list = this.table.modules.export.generateExportList(this.table.options.downloadConfig, false, range || this.table.options.downloadRowRange, "download");
  8774. //assign group header formatter
  8775. var groupHeader = this.table.options.groupHeaderDownload;
  8776. if (groupHeader && !Array.isArray(groupHeader)) {
  8777. groupHeader = [groupHeader];
  8778. }
  8779. list.forEach(function (row) {
  8780. var group;
  8781. if (row.type === "group") {
  8782. group = row.columns[0];
  8783. if (groupHeader && groupHeader[row.indent]) {
  8784. group.value = groupHeader[row.indent](group.value, row.component._group.getRowCount(), row.component._group.getData(), row.component);
  8785. }
  8786. }
  8787. });
  8788. return list;
  8789. };
  8790. Download.prototype.triggerDownload = function (data, mime, type, filename, newTab) {
  8791. var element = document.createElement('a'),
  8792. blob = new Blob([data], { type: mime }),
  8793. filename = filename || "Tabulator." + (typeof type === "function" ? "txt" : type);
  8794. blob = this.table.options.downloadReady.call(this.table, data, blob);
  8795. if (blob) {
  8796. if (newTab) {
  8797. window.open(window.URL.createObjectURL(blob));
  8798. } else {
  8799. if (navigator.msSaveOrOpenBlob) {
  8800. navigator.msSaveOrOpenBlob(blob, filename);
  8801. } else {
  8802. element.setAttribute('href', window.URL.createObjectURL(blob));
  8803. //set file title
  8804. element.setAttribute('download', filename);
  8805. //trigger download
  8806. element.style.display = 'none';
  8807. document.body.appendChild(element);
  8808. element.click();
  8809. //remove temporary link element
  8810. document.body.removeChild(element);
  8811. }
  8812. }
  8813. if (this.table.options.downloadComplete) {
  8814. this.table.options.downloadComplete();
  8815. }
  8816. }
  8817. };
  8818. Download.prototype.commsReceived = function (table, action, data) {
  8819. switch (action) {
  8820. case "intercept":
  8821. this.download(data.type, "", data.options, data.active, data.intercept);
  8822. break;
  8823. }
  8824. };
  8825. //downloaders
  8826. Download.prototype.downloaders = {
  8827. csv: function csv(list, options, setFileContents) {
  8828. var delimiter = options && options.delimiter ? options.delimiter : ",",
  8829. fileContents = [],
  8830. headers = [];
  8831. list.forEach(function (row) {
  8832. var item = [];
  8833. switch (row.type) {
  8834. case "group":
  8835. console.warn("Download Warning - CSV downloader cannot process row groups");
  8836. break;
  8837. case "calc":
  8838. console.warn("Download Warning - CSV downloader cannot process column calculations");
  8839. break;
  8840. case "header":
  8841. row.columns.forEach(function (col, i) {
  8842. if (col && col.depth === 1) {
  8843. headers[i] = typeof col.value == "undefined" || col.value === null ? "" : '"' + String(col.value).split('"').join('""') + '"';
  8844. }
  8845. });
  8846. break;
  8847. case "row":
  8848. row.columns.forEach(function (col) {
  8849. if (col) {
  8850. switch (_typeof(col.value)) {
  8851. case "object":
  8852. col.value = JSON.stringify(col.value);
  8853. break;
  8854. case "undefined":
  8855. case "null":
  8856. col.value = "";
  8857. break;
  8858. }
  8859. item.push('"' + String(col.value).split('"').join('""') + '"');
  8860. }
  8861. });
  8862. fileContents.push(item.join(delimiter));
  8863. break;
  8864. }
  8865. });
  8866. if (headers.length) {
  8867. fileContents.unshift(headers.join(delimiter));
  8868. }
  8869. fileContents = fileContents.join("\n");
  8870. if (options.bom) {
  8871. fileContents = '\uFEFF' + fileContents;
  8872. }
  8873. setFileContents(fileContents, "text/csv");
  8874. },
  8875. json: function json(list, options, setFileContents) {
  8876. var fileContents = [];
  8877. list.forEach(function (row) {
  8878. var item = {};
  8879. switch (row.type) {
  8880. case "header":
  8881. break;
  8882. case "group":
  8883. console.warn("Download Warning - JSON downloader cannot process row groups");
  8884. break;
  8885. case "calc":
  8886. console.warn("Download Warning - JSON downloader cannot process column calculations");
  8887. break;
  8888. case "row":
  8889. row.columns.forEach(function (col) {
  8890. if (col) {
  8891. item[col.component.getField()] = col.value;
  8892. }
  8893. });
  8894. fileContents.push(item);
  8895. break;
  8896. }
  8897. });
  8898. fileContents = JSON.stringify(fileContents, null, '\t');
  8899. setFileContents(fileContents, "application/json");
  8900. },
  8901. pdf: function pdf(list, options, setFileContents) {
  8902. var header = [],
  8903. body = [],
  8904. autoTableParams = {},
  8905. rowGroupStyles = options.rowGroupStyles || {
  8906. fontStyle: "bold",
  8907. fontSize: 12,
  8908. cellPadding: 6,
  8909. fillColor: 220
  8910. },
  8911. rowCalcStyles = options.rowCalcStyles || {
  8912. fontStyle: "bold",
  8913. fontSize: 10,
  8914. cellPadding: 4,
  8915. fillColor: 232
  8916. },
  8917. jsPDFParams = options.jsPDF || {},
  8918. title = options && options.title ? options.title : "";
  8919. if (!jsPDFParams.orientation) {
  8920. jsPDFParams.orientation = options.orientation || "landscape";
  8921. }
  8922. if (!jsPDFParams.unit) {
  8923. jsPDFParams.unit = "pt";
  8924. }
  8925. //parse row list
  8926. list.forEach(function (row) {
  8927. var item = {};
  8928. switch (row.type) {
  8929. case "header":
  8930. header.push(parseRow(row));
  8931. break;
  8932. case "group":
  8933. body.push(parseRow(row, rowGroupStyles));
  8934. break;
  8935. case "calc":
  8936. body.push(parseRow(row, rowCalcStyles));
  8937. break;
  8938. case "row":
  8939. body.push(parseRow(row));
  8940. break;
  8941. }
  8942. });
  8943. function parseRow(row, styles) {
  8944. var rowData = [];
  8945. row.columns.forEach(function (col) {
  8946. var cell;
  8947. if (col) {
  8948. switch (_typeof(col.value)) {
  8949. case "object":
  8950. col.value = JSON.stringify(col.value);
  8951. break;
  8952. case "undefined":
  8953. case "null":
  8954. col.value = "";
  8955. break;
  8956. }
  8957. cell = {
  8958. content: col.value,
  8959. colSpan: col.width,
  8960. rowSpan: col.height
  8961. };
  8962. if (styles) {
  8963. cell.styles = styles;
  8964. }
  8965. rowData.push(cell);
  8966. } else {
  8967. rowData.push("");
  8968. }
  8969. });
  8970. return rowData;
  8971. }
  8972. //configure PDF
  8973. var doc = new jsPDF(jsPDFParams); //set document to landscape, better for most tables
  8974. if (options && options.autoTable) {
  8975. if (typeof options.autoTable === "function") {
  8976. autoTableParams = options.autoTable(doc) || {};
  8977. } else {
  8978. autoTableParams = options.autoTable;
  8979. }
  8980. }
  8981. if (title) {
  8982. autoTableParams.addPageContent = function (data) {
  8983. doc.text(title, 40, 30);
  8984. };
  8985. }
  8986. autoTableParams.head = header;
  8987. autoTableParams.body = body;
  8988. doc.autoTable(autoTableParams);
  8989. if (options && options.documentProcessing) {
  8990. options.documentProcessing(doc);
  8991. }
  8992. setFileContents(doc.output("arraybuffer"), "application/pdf");
  8993. },
  8994. xlsx: function xlsx(list, options, setFileContents) {
  8995. var self = this,
  8996. sheetName = options.sheetName || "Sheet1",
  8997. workbook = XLSX.utils.book_new(),
  8998. output;
  8999. workbook.SheetNames = [];
  9000. workbook.Sheets = {};
  9001. function generateSheet() {
  9002. var rows = [],
  9003. merges = [],
  9004. worksheet = {},
  9005. range = { s: { c: 0, r: 0 }, e: { c: list[0] ? list[0].columns.reduce(function (a, b) {
  9006. return a + (b && b.width ? b.width : 1);
  9007. }, 0) : 0, r: list.length } };
  9008. //parse row list
  9009. list.forEach(function (row, i) {
  9010. var rowData = [];
  9011. row.columns.forEach(function (col, j) {
  9012. if (col) {
  9013. rowData.push(!(col.value instanceof Date) && _typeof(col.value) === "object" ? JSON.stringify(col.value) : col.value);
  9014. if (col.width > 1 || col.height > -1) {
  9015. merges.push({ s: { r: i, c: j }, e: { r: i + col.height - 1, c: j + col.width - 1 } });
  9016. }
  9017. } else {
  9018. rowData.push("");
  9019. }
  9020. });
  9021. rows.push(rowData);
  9022. });
  9023. //convert rows to worksheet
  9024. XLSX.utils.sheet_add_aoa(worksheet, rows);
  9025. worksheet['!ref'] = XLSX.utils.encode_range(range);
  9026. if (merges.length) {
  9027. worksheet["!merges"] = merges;
  9028. }
  9029. return worksheet;
  9030. }
  9031. if (options.sheetOnly) {
  9032. setFileContents(generateSheet());
  9033. return;
  9034. }
  9035. if (options.sheets) {
  9036. for (var sheet in options.sheets) {
  9037. if (options.sheets[sheet] === true) {
  9038. workbook.SheetNames.push(sheet);
  9039. workbook.Sheets[sheet] = generateSheet();
  9040. } else {
  9041. workbook.SheetNames.push(sheet);
  9042. this.modules.comms.send(options.sheets[sheet], "download", "intercept", {
  9043. type: "xlsx",
  9044. options: { sheetOnly: true },
  9045. active: self.active,
  9046. intercept: function intercept(data) {
  9047. workbook.Sheets[sheet] = data;
  9048. }
  9049. });
  9050. }
  9051. }
  9052. } else {
  9053. workbook.SheetNames.push(sheetName);
  9054. workbook.Sheets[sheetName] = generateSheet();
  9055. }
  9056. if (options.documentProcessing) {
  9057. workbook = options.documentProcessing(workbook);
  9058. }
  9059. //convert workbook to binary array
  9060. function s2ab(s) {
  9061. var buf = new ArrayBuffer(s.length);
  9062. var view = new Uint8Array(buf);
  9063. for (var i = 0; i != s.length; ++i) {
  9064. view[i] = s.charCodeAt(i) & 0xFF;
  9065. }return buf;
  9066. }
  9067. output = XLSX.write(workbook, { bookType: 'xlsx', bookSST: true, type: 'binary' });
  9068. setFileContents(s2ab(output), "application/octet-stream");
  9069. },
  9070. html: function html(list, options, setFileContents) {
  9071. if (this.modExists("export", true)) {
  9072. setFileContents(this.modules.export.genereateHTMLTable(list), "text/html");
  9073. }
  9074. }
  9075. };
  9076. Tabulator.prototype.registerModule("download", Download);
  9077. var Edit = function Edit(table) {
  9078. this.table = table; //hold Tabulator object
  9079. this.currentCell = false; //hold currently editing cell
  9080. this.mouseClick = false; //hold mousedown state to prevent click binding being overriden by editor opening
  9081. this.recursionBlock = false; //prevent focus recursion
  9082. this.invalidEdit = false;
  9083. this.editedCells = [];
  9084. };
  9085. //initialize column editor
  9086. Edit.prototype.initializeColumn = function (column) {
  9087. var self = this,
  9088. config = {
  9089. editor: false,
  9090. blocked: false,
  9091. check: column.definition.editable,
  9092. params: column.definition.editorParams || {}
  9093. };
  9094. //set column editor
  9095. switch (_typeof(column.definition.editor)) {
  9096. case "string":
  9097. if (column.definition.editor === "tick") {
  9098. column.definition.editor = "tickCross";
  9099. console.warn("DEPRECATION WARNING - the tick editor has been deprecated, please use the tickCross editor");
  9100. }
  9101. if (self.editors[column.definition.editor]) {
  9102. config.editor = self.editors[column.definition.editor];
  9103. } else {
  9104. console.warn("Editor Error - No such editor found: ", column.definition.editor);
  9105. }
  9106. break;
  9107. case "function":
  9108. config.editor = column.definition.editor;
  9109. break;
  9110. case "boolean":
  9111. if (column.definition.editor === true) {
  9112. if (typeof column.definition.formatter !== "function") {
  9113. if (column.definition.formatter === "tick") {
  9114. column.definition.formatter = "tickCross";
  9115. console.warn("DEPRECATION WARNING - the tick editor has been deprecated, please use the tickCross editor");
  9116. }
  9117. if (self.editors[column.definition.formatter]) {
  9118. config.editor = self.editors[column.definition.formatter];
  9119. } else {
  9120. config.editor = self.editors["input"];
  9121. }
  9122. } else {
  9123. console.warn("Editor Error - Cannot auto lookup editor for a custom formatter: ", column.definition.formatter);
  9124. }
  9125. }
  9126. break;
  9127. }
  9128. if (config.editor) {
  9129. column.modules.edit = config;
  9130. }
  9131. };
  9132. Edit.prototype.getCurrentCell = function () {
  9133. return this.currentCell ? this.currentCell.getComponent() : false;
  9134. };
  9135. Edit.prototype.clearEditor = function (cancel) {
  9136. var cell = this.currentCell,
  9137. cellEl;
  9138. this.invalidEdit = false;
  9139. if (cell) {
  9140. this.currentCell = false;
  9141. cellEl = cell.getElement();
  9142. if (cancel) {
  9143. cell.validate();
  9144. } else {
  9145. cellEl.classList.remove("tabulator-validation-fail");
  9146. }
  9147. cellEl.classList.remove("tabulator-editing");
  9148. while (cellEl.firstChild) {
  9149. cellEl.removeChild(cellEl.firstChild);
  9150. }cell.row.getElement().classList.remove("tabulator-row-editing");
  9151. }
  9152. };
  9153. Edit.prototype.cancelEdit = function () {
  9154. if (this.currentCell) {
  9155. var cell = this.currentCell;
  9156. var component = this.currentCell.getComponent();
  9157. this.clearEditor(true);
  9158. cell.setValueActual(cell.getValue());
  9159. cell.cellRendered();
  9160. if (cell.column.definition.editor == "textarea" || cell.column.definition.variableHeight) {
  9161. cell.row.normalizeHeight(true);
  9162. }
  9163. if (cell.column.cellEvents.cellEditCancelled) {
  9164. cell.column.cellEvents.cellEditCancelled.call(this.table, component);
  9165. }
  9166. this.table.options.cellEditCancelled.call(this.table, component);
  9167. }
  9168. };
  9169. //return a formatted value for a cell
  9170. Edit.prototype.bindEditor = function (cell) {
  9171. var self = this,
  9172. element = cell.getElement();
  9173. element.setAttribute("tabindex", 0);
  9174. element.addEventListener("click", function (e) {
  9175. if (!element.classList.contains("tabulator-editing")) {
  9176. element.focus({ preventScroll: true });
  9177. }
  9178. });
  9179. element.addEventListener("mousedown", function (e) {
  9180. if (e.button === 2) {
  9181. e.preventDefault();
  9182. } else {
  9183. self.mouseClick = true;
  9184. }
  9185. });
  9186. element.addEventListener("focus", function (e) {
  9187. if (!self.recursionBlock) {
  9188. self.edit(cell, e, false);
  9189. }
  9190. });
  9191. };
  9192. Edit.prototype.focusCellNoEvent = function (cell, block) {
  9193. this.recursionBlock = true;
  9194. if (!(block && this.table.browser === "ie")) {
  9195. cell.getElement().focus({ preventScroll: true });
  9196. }
  9197. this.recursionBlock = false;
  9198. };
  9199. Edit.prototype.editCell = function (cell, forceEdit) {
  9200. this.focusCellNoEvent(cell);
  9201. this.edit(cell, false, forceEdit);
  9202. };
  9203. Edit.prototype.focusScrollAdjust = function (cell) {
  9204. if (this.table.rowManager.getRenderMode() == "virtual") {
  9205. var topEdge = this.table.rowManager.element.scrollTop,
  9206. bottomEdge = this.table.rowManager.element.clientHeight + this.table.rowManager.element.scrollTop,
  9207. rowEl = cell.row.getElement(),
  9208. offset = rowEl.offsetTop;
  9209. if (rowEl.offsetTop < topEdge) {
  9210. this.table.rowManager.element.scrollTop -= topEdge - rowEl.offsetTop;
  9211. } else {
  9212. if (rowEl.offsetTop + rowEl.offsetHeight > bottomEdge) {
  9213. this.table.rowManager.element.scrollTop += rowEl.offsetTop + rowEl.offsetHeight - bottomEdge;
  9214. }
  9215. }
  9216. var leftEdge = this.table.rowManager.element.scrollLeft,
  9217. rightEdge = this.table.rowManager.element.clientWidth + this.table.rowManager.element.scrollLeft,
  9218. cellEl = cell.getElement(),
  9219. offset = cellEl.offsetLeft;
  9220. if (this.table.modExists("frozenColumns")) {
  9221. leftEdge += parseInt(this.table.modules.frozenColumns.leftMargin);
  9222. rightEdge -= parseInt(this.table.modules.frozenColumns.rightMargin);
  9223. }
  9224. if (cellEl.offsetLeft < leftEdge) {
  9225. this.table.rowManager.element.scrollLeft -= leftEdge - cellEl.offsetLeft;
  9226. } else {
  9227. if (cellEl.offsetLeft + cellEl.offsetWidth > rightEdge) {
  9228. this.table.rowManager.element.scrollLeft += cellEl.offsetLeft + cellEl.offsetWidth - rightEdge;
  9229. }
  9230. }
  9231. }
  9232. };
  9233. Edit.prototype.edit = function (cell, e, forceEdit) {
  9234. var self = this,
  9235. allowEdit = true,
  9236. rendered = function rendered() {},
  9237. element = cell.getElement(),
  9238. cellEditor,
  9239. component,
  9240. params;
  9241. //prevent editing if another cell is refusing to leave focus (eg. validation fail)
  9242. if (this.currentCell) {
  9243. if (!this.invalidEdit) {
  9244. this.cancelEdit();
  9245. }
  9246. return;
  9247. }
  9248. //handle successfull value change
  9249. function success(value) {
  9250. if (self.currentCell === cell) {
  9251. var valid = true;
  9252. if (cell.column.modules.validate && self.table.modExists("validate") && self.table.options.validationMode != "manual") {
  9253. valid = self.table.modules.validate.validate(cell.column.modules.validate, cell, value);
  9254. }
  9255. if (valid === true || self.table.options.validationMode === "highlight") {
  9256. self.clearEditor();
  9257. if (!cell.modules.edit) {
  9258. cell.modules.edit = {};
  9259. }
  9260. cell.modules.edit.edited = true;
  9261. if (self.editedCells.indexOf(cell) == -1) {
  9262. self.editedCells.push(cell);
  9263. }
  9264. cell.setValue(value, true);
  9265. if (self.table.options.dataTree && self.table.modExists("dataTree")) {
  9266. self.table.modules.dataTree.checkForRestyle(cell);
  9267. }
  9268. if (valid !== true) {
  9269. element.classList.add("tabulator-validation-fail");
  9270. self.table.options.validationFailed.call(self.table, cell.getComponent(), value, valid);
  9271. return false;
  9272. }
  9273. return true;
  9274. } else {
  9275. self.invalidEdit = true;
  9276. element.classList.add("tabulator-validation-fail");
  9277. self.focusCellNoEvent(cell, true);
  9278. rendered();
  9279. self.table.options.validationFailed.call(self.table, cell.getComponent(), value, valid);
  9280. return false;
  9281. }
  9282. } else {
  9283. // console.warn("Edit Success Error - cannot call success on a cell that is no longer being edited");
  9284. }
  9285. }
  9286. //handle aborted edit
  9287. function cancel() {
  9288. if (self.currentCell === cell) {
  9289. self.cancelEdit();
  9290. if (self.table.options.dataTree && self.table.modExists("dataTree")) {
  9291. self.table.modules.dataTree.checkForRestyle(cell);
  9292. }
  9293. } else {
  9294. // console.warn("Edit Success Error - cannot call cancel on a cell that is no longer being edited");
  9295. }
  9296. }
  9297. function onRendered(callback) {
  9298. rendered = callback;
  9299. }
  9300. if (!cell.column.modules.edit.blocked) {
  9301. if (e) {
  9302. e.stopPropagation();
  9303. }
  9304. switch (_typeof(cell.column.modules.edit.check)) {
  9305. case "function":
  9306. allowEdit = cell.column.modules.edit.check(cell.getComponent());
  9307. break;
  9308. case "boolean":
  9309. allowEdit = cell.column.modules.edit.check;
  9310. break;
  9311. }
  9312. if (allowEdit || forceEdit) {
  9313. self.cancelEdit();
  9314. self.currentCell = cell;
  9315. this.focusScrollAdjust(cell);
  9316. component = cell.getComponent();
  9317. if (this.mouseClick) {
  9318. this.mouseClick = false;
  9319. if (cell.column.cellEvents.cellClick) {
  9320. cell.column.cellEvents.cellClick.call(this.table, e, component);
  9321. }
  9322. }
  9323. if (cell.column.cellEvents.cellEditing) {
  9324. cell.column.cellEvents.cellEditing.call(this.table, component);
  9325. }
  9326. self.table.options.cellEditing.call(this.table, component);
  9327. params = typeof cell.column.modules.edit.params === "function" ? cell.column.modules.edit.params(component) : cell.column.modules.edit.params;
  9328. cellEditor = cell.column.modules.edit.editor.call(self, component, onRendered, success, cancel, params);
  9329. //if editor returned, add to DOM, if false, abort edit
  9330. if (cellEditor !== false) {
  9331. if (cellEditor instanceof Node) {
  9332. element.classList.add("tabulator-editing");
  9333. cell.row.getElement().classList.add("tabulator-row-editing");
  9334. while (element.firstChild) {
  9335. element.removeChild(element.firstChild);
  9336. }element.appendChild(cellEditor);
  9337. //trigger onRendered Callback
  9338. rendered();
  9339. //prevent editing from triggering rowClick event
  9340. var children = element.children;
  9341. for (var i = 0; i < children.length; i++) {
  9342. children[i].addEventListener("click", function (e) {
  9343. e.stopPropagation();
  9344. });
  9345. }
  9346. } else {
  9347. console.warn("Edit Error - Editor should return an instance of Node, the editor returned:", cellEditor);
  9348. element.blur();
  9349. return false;
  9350. }
  9351. } else {
  9352. element.blur();
  9353. return false;
  9354. }
  9355. return true;
  9356. } else {
  9357. this.mouseClick = false;
  9358. element.blur();
  9359. return false;
  9360. }
  9361. } else {
  9362. this.mouseClick = false;
  9363. element.blur();
  9364. return false;
  9365. }
  9366. };
  9367. Edit.prototype.maskInput = function (el, options) {
  9368. var mask = options.mask,
  9369. maskLetter = typeof options.maskLetterChar !== "undefined" ? options.maskLetterChar : "A",
  9370. maskNumber = typeof options.maskNumberChar !== "undefined" ? options.maskNumberChar : "9",
  9371. maskWildcard = typeof options.maskWildcardChar !== "undefined" ? options.maskWildcardChar : "*",
  9372. success = false;
  9373. function fillSymbols(index) {
  9374. var symbol = mask[index];
  9375. if (typeof symbol !== "undefined" && symbol !== maskWildcard && symbol !== maskLetter && symbol !== maskNumber) {
  9376. el.value = el.value + "" + symbol;
  9377. fillSymbols(index + 1);
  9378. }
  9379. }
  9380. el.addEventListener("keydown", function (e) {
  9381. var index = el.value.length,
  9382. char = e.key;
  9383. if (e.keyCode > 46) {
  9384. if (index >= mask.length) {
  9385. e.preventDefault();
  9386. e.stopPropagation();
  9387. success = false;
  9388. return false;
  9389. } else {
  9390. switch (mask[index]) {
  9391. case maskLetter:
  9392. if (char.toUpperCase() == char.toLowerCase()) {
  9393. e.preventDefault();
  9394. e.stopPropagation();
  9395. success = false;
  9396. return false;
  9397. }
  9398. break;
  9399. case maskNumber:
  9400. if (isNaN(char)) {
  9401. e.preventDefault();
  9402. e.stopPropagation();
  9403. success = false;
  9404. return false;
  9405. }
  9406. break;
  9407. case maskWildcard:
  9408. break;
  9409. default:
  9410. if (char !== mask[index]) {
  9411. e.preventDefault();
  9412. e.stopPropagation();
  9413. success = false;
  9414. return false;
  9415. }
  9416. }
  9417. }
  9418. success = true;
  9419. }
  9420. return;
  9421. });
  9422. el.addEventListener("keyup", function (e) {
  9423. if (e.keyCode > 46) {
  9424. if (options.maskAutoFill) {
  9425. fillSymbols(el.value.length);
  9426. }
  9427. }
  9428. });
  9429. if (!el.placeholder) {
  9430. el.placeholder = mask;
  9431. }
  9432. if (options.maskAutoFill) {
  9433. fillSymbols(el.value.length);
  9434. }
  9435. };
  9436. Edit.prototype.getEditedCells = function () {
  9437. var output = [];
  9438. this.editedCells.forEach(function (cell) {
  9439. output.push(cell.getComponent());
  9440. });
  9441. return output;
  9442. };
  9443. Edit.prototype.clearEdited = function (cell) {
  9444. var editIndex;
  9445. if (cell.modules.validate && cell.modules.edit && cell.modules.edit.edited) {
  9446. cell.modules.validate.invalid = false;
  9447. editIndex = this.editedCells.indexOf(cell);
  9448. if (editIndex > -1) {
  9449. this.editedCells.splice(editIndex, 1);
  9450. }
  9451. }
  9452. };
  9453. //default data editors
  9454. Edit.prototype.editors = {
  9455. //input element
  9456. input: function input(cell, onRendered, success, cancel, editorParams) {
  9457. //create and style input
  9458. var cellValue = cell.getValue(),
  9459. input = document.createElement("input");
  9460. input.setAttribute("type", editorParams.search ? "search" : "text");
  9461. input.style.padding = "4px";
  9462. input.style.width = "100%";
  9463. input.style.boxSizing = "border-box";
  9464. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  9465. for (var key in editorParams.elementAttributes) {
  9466. if (key.charAt(0) == "+") {
  9467. key = key.slice(1);
  9468. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  9469. } else {
  9470. input.setAttribute(key, editorParams.elementAttributes[key]);
  9471. }
  9472. }
  9473. }
  9474. input.value = typeof cellValue !== "undefined" ? cellValue : "";
  9475. onRendered(function () {
  9476. input.focus({ preventScroll: true });
  9477. input.style.height = "100%";
  9478. });
  9479. function onChange(e) {
  9480. if ((cellValue === null || typeof cellValue === "undefined") && input.value !== "" || input.value !== cellValue) {
  9481. if (success(input.value)) {
  9482. cellValue = input.value; //persist value if successfully validated incase editor is used as header filter
  9483. }
  9484. } else {
  9485. cancel();
  9486. }
  9487. }
  9488. //submit new value on blur or change
  9489. input.addEventListener("change", onChange);
  9490. input.addEventListener("blur", onChange);
  9491. //submit new value on enter
  9492. input.addEventListener("keydown", function (e) {
  9493. switch (e.keyCode) {
  9494. // case 9:
  9495. case 13:
  9496. onChange(e);
  9497. break;
  9498. case 27:
  9499. cancel();
  9500. break;
  9501. case 35:
  9502. case 36:
  9503. e.stopPropagation();
  9504. break;
  9505. }
  9506. });
  9507. if (editorParams.mask) {
  9508. this.table.modules.edit.maskInput(input, editorParams);
  9509. }
  9510. return input;
  9511. },
  9512. //resizable text area element
  9513. textarea: function textarea(cell, onRendered, success, cancel, editorParams) {
  9514. var self = this,
  9515. cellValue = cell.getValue(),
  9516. vertNav = editorParams.verticalNavigation || "hybrid",
  9517. value = String(cellValue !== null && typeof cellValue !== "undefined" ? cellValue : ""),
  9518. count = (value.match(/(?:\r\n|\r|\n)/g) || []).length + 1,
  9519. input = document.createElement("textarea"),
  9520. scrollHeight = 0;
  9521. //create and style input
  9522. input.style.display = "block";
  9523. input.style.padding = "2px";
  9524. input.style.height = "100%";
  9525. input.style.width = "100%";
  9526. input.style.boxSizing = "border-box";
  9527. input.style.whiteSpace = "pre-wrap";
  9528. input.style.resize = "none";
  9529. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  9530. for (var key in editorParams.elementAttributes) {
  9531. if (key.charAt(0) == "+") {
  9532. key = key.slice(1);
  9533. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  9534. } else {
  9535. input.setAttribute(key, editorParams.elementAttributes[key]);
  9536. }
  9537. }
  9538. }
  9539. input.value = value;
  9540. onRendered(function () {
  9541. input.focus({ preventScroll: true });
  9542. input.style.height = "100%";
  9543. input.scrollHeight;
  9544. input.style.height = input.scrollHeight + "px";
  9545. cell.getRow().normalizeHeight();
  9546. });
  9547. function onChange(e) {
  9548. if ((cellValue === null || typeof cellValue === "undefined") && input.value !== "" || input.value !== cellValue) {
  9549. if (success(input.value)) {
  9550. cellValue = input.value; //persist value if successfully validated incase editor is used as header filter
  9551. }
  9552. setTimeout(function () {
  9553. cell.getRow().normalizeHeight();
  9554. }, 300);
  9555. } else {
  9556. cancel();
  9557. }
  9558. }
  9559. //submit new value on blur or change
  9560. input.addEventListener("change", onChange);
  9561. input.addEventListener("blur", onChange);
  9562. input.addEventListener("keyup", function () {
  9563. input.style.height = "";
  9564. var heightNow = input.scrollHeight;
  9565. input.style.height = heightNow + "px";
  9566. if (heightNow != scrollHeight) {
  9567. scrollHeight = heightNow;
  9568. cell.getRow().normalizeHeight();
  9569. }
  9570. });
  9571. input.addEventListener("keydown", function (e) {
  9572. switch (e.keyCode) {
  9573. case 27:
  9574. cancel();
  9575. break;
  9576. case 38:
  9577. //up arrow
  9578. if (vertNav == "editor" || vertNav == "hybrid" && input.selectionStart) {
  9579. e.stopImmediatePropagation();
  9580. e.stopPropagation();
  9581. }
  9582. break;
  9583. case 40:
  9584. //down arrow
  9585. if (vertNav == "editor" || vertNav == "hybrid" && input.selectionStart !== input.value.length) {
  9586. e.stopImmediatePropagation();
  9587. e.stopPropagation();
  9588. }
  9589. break;
  9590. case 35:
  9591. case 36:
  9592. e.stopPropagation();
  9593. break;
  9594. }
  9595. });
  9596. if (editorParams.mask) {
  9597. this.table.modules.edit.maskInput(input, editorParams);
  9598. }
  9599. return input;
  9600. },
  9601. //input element with type of number
  9602. number: function number(cell, onRendered, success, cancel, editorParams) {
  9603. var cellValue = cell.getValue(),
  9604. vertNav = editorParams.verticalNavigation || "editor",
  9605. input = document.createElement("input");
  9606. input.setAttribute("type", "number");
  9607. if (typeof editorParams.max != "undefined") {
  9608. input.setAttribute("max", editorParams.max);
  9609. }
  9610. if (typeof editorParams.min != "undefined") {
  9611. input.setAttribute("min", editorParams.min);
  9612. }
  9613. if (typeof editorParams.step != "undefined") {
  9614. input.setAttribute("step", editorParams.step);
  9615. }
  9616. //create and style input
  9617. input.style.padding = "4px";
  9618. input.style.width = "100%";
  9619. input.style.boxSizing = "border-box";
  9620. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  9621. for (var key in editorParams.elementAttributes) {
  9622. if (key.charAt(0) == "+") {
  9623. key = key.slice(1);
  9624. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  9625. } else {
  9626. input.setAttribute(key, editorParams.elementAttributes[key]);
  9627. }
  9628. }
  9629. }
  9630. input.value = cellValue;
  9631. var blurFunc = function blurFunc(e) {
  9632. onChange();
  9633. };
  9634. onRendered(function () {
  9635. //submit new value on blur
  9636. input.removeEventListener("blur", blurFunc);
  9637. input.focus({ preventScroll: true });
  9638. input.style.height = "100%";
  9639. //submit new value on blur
  9640. input.addEventListener("blur", blurFunc);
  9641. });
  9642. function onChange() {
  9643. var value = input.value;
  9644. if (!isNaN(value) && value !== "") {
  9645. value = Number(value);
  9646. }
  9647. if (value !== cellValue) {
  9648. if (success(value)) {
  9649. cellValue = value; //persist value if successfully validated incase editor is used as header filter
  9650. }
  9651. } else {
  9652. cancel();
  9653. }
  9654. }
  9655. //submit new value on enter
  9656. input.addEventListener("keydown", function (e) {
  9657. switch (e.keyCode) {
  9658. case 13:
  9659. // case 9:
  9660. onChange();
  9661. break;
  9662. case 27:
  9663. cancel();
  9664. break;
  9665. case 38: //up arrow
  9666. case 40:
  9667. //down arrow
  9668. if (vertNav == "editor") {
  9669. e.stopImmediatePropagation();
  9670. e.stopPropagation();
  9671. }
  9672. break;
  9673. case 35:
  9674. case 36:
  9675. e.stopPropagation();
  9676. break;
  9677. }
  9678. });
  9679. if (editorParams.mask) {
  9680. this.table.modules.edit.maskInput(input, editorParams);
  9681. }
  9682. return input;
  9683. },
  9684. //input element with type of number
  9685. range: function range(cell, onRendered, success, cancel, editorParams) {
  9686. var cellValue = cell.getValue(),
  9687. input = document.createElement("input");
  9688. input.setAttribute("type", "range");
  9689. if (typeof editorParams.max != "undefined") {
  9690. input.setAttribute("max", editorParams.max);
  9691. }
  9692. if (typeof editorParams.min != "undefined") {
  9693. input.setAttribute("min", editorParams.min);
  9694. }
  9695. if (typeof editorParams.step != "undefined") {
  9696. input.setAttribute("step", editorParams.step);
  9697. }
  9698. //create and style input
  9699. input.style.padding = "4px";
  9700. input.style.width = "100%";
  9701. input.style.boxSizing = "border-box";
  9702. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  9703. for (var key in editorParams.elementAttributes) {
  9704. if (key.charAt(0) == "+") {
  9705. key = key.slice(1);
  9706. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  9707. } else {
  9708. input.setAttribute(key, editorParams.elementAttributes[key]);
  9709. }
  9710. }
  9711. }
  9712. input.value = cellValue;
  9713. onRendered(function () {
  9714. input.focus({ preventScroll: true });
  9715. input.style.height = "100%";
  9716. });
  9717. function onChange() {
  9718. var value = input.value;
  9719. if (!isNaN(value) && value !== "") {
  9720. value = Number(value);
  9721. }
  9722. if (value != cellValue) {
  9723. if (success(value)) {
  9724. cellValue = value; //persist value if successfully validated incase editor is used as header filter
  9725. }
  9726. } else {
  9727. cancel();
  9728. }
  9729. }
  9730. //submit new value on blur
  9731. input.addEventListener("blur", function (e) {
  9732. onChange();
  9733. });
  9734. //submit new value on enter
  9735. input.addEventListener("keydown", function (e) {
  9736. switch (e.keyCode) {
  9737. case 13:
  9738. // case 9:
  9739. onChange();
  9740. break;
  9741. case 27:
  9742. cancel();
  9743. break;
  9744. }
  9745. });
  9746. return input;
  9747. },
  9748. //select
  9749. select: function select(cell, onRendered, success, cancel, editorParams) {
  9750. var _this53 = this;
  9751. var self = this,
  9752. cellEl = cell.getElement(),
  9753. initialValue = cell.getValue(),
  9754. vertNav = editorParams.verticalNavigation || "editor",
  9755. initialDisplayValue = typeof initialValue !== "undefined" || initialValue === null ? Array.isArray(initialValue) ? initialValue : [initialValue] : typeof editorParams.defaultValue !== "undefined" ? editorParams.defaultValue : [],
  9756. input = document.createElement("input"),
  9757. listEl = document.createElement("div"),
  9758. multiselect = editorParams.multiselect,
  9759. dataItems = [],
  9760. currentItem = {},
  9761. displayItems = [],
  9762. currentItems = [],
  9763. blurable = true,
  9764. blockListShow = false;
  9765. if (Array.isArray(editorParams) || !Array.isArray(editorParams) && (typeof editorParams === 'undefined' ? 'undefined' : _typeof(editorParams)) === "object" && !editorParams.values) {
  9766. 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");
  9767. editorParams = { values: editorParams };
  9768. }
  9769. function getUniqueColumnValues(field) {
  9770. var output = {},
  9771. data = self.table.getData(),
  9772. column;
  9773. if (field) {
  9774. column = self.table.columnManager.getColumnByField(field);
  9775. } else {
  9776. column = cell.getColumn()._getSelf();
  9777. }
  9778. if (column) {
  9779. data.forEach(function (row) {
  9780. var val = column.getFieldValue(row);
  9781. if (val !== null && typeof val !== "undefined" && val !== "") {
  9782. output[val] = true;
  9783. }
  9784. });
  9785. if (editorParams.sortValuesList) {
  9786. if (editorParams.sortValuesList == "asc") {
  9787. output = Object.keys(output).sort();
  9788. } else {
  9789. output = Object.keys(output).sort().reverse();
  9790. }
  9791. } else {
  9792. output = Object.keys(output);
  9793. }
  9794. } else {
  9795. console.warn("unable to find matching column to create select lookup list:", field);
  9796. }
  9797. return output;
  9798. }
  9799. function parseItems(inputValues, curentValues) {
  9800. var dataList = [];
  9801. var displayList = [];
  9802. function processComplexListItem(item) {
  9803. var item = {
  9804. label: item.label,
  9805. value: item.value,
  9806. itemParams: item.itemParams,
  9807. elementAttributes: item.elementAttributes,
  9808. element: false
  9809. };
  9810. // if(item.value === curentValue || (!isNaN(parseFloat(item.value)) && !isNaN(parseFloat(item.value)) && parseFloat(item.value) === parseFloat(curentValue))){
  9811. // setCurrentItem(item);
  9812. // }
  9813. if (curentValues.indexOf(item.value) > -1) {
  9814. setItem(item);
  9815. }
  9816. dataList.push(item);
  9817. displayList.push(item);
  9818. return item;
  9819. }
  9820. if (typeof inputValues == "function") {
  9821. inputValues = inputValues(cell);
  9822. }
  9823. if (Array.isArray(inputValues)) {
  9824. inputValues.forEach(function (value) {
  9825. var item;
  9826. if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === "object") {
  9827. if (value.options) {
  9828. item = {
  9829. label: value.label,
  9830. group: true,
  9831. itemParams: value.itemParams,
  9832. elementAttributes: value.elementAttributes,
  9833. element: false
  9834. };
  9835. displayList.push(item);
  9836. value.options.forEach(function (item) {
  9837. processComplexListItem(item);
  9838. });
  9839. } else {
  9840. processComplexListItem(value);
  9841. }
  9842. } else {
  9843. item = {
  9844. label: value,
  9845. value: value,
  9846. element: false
  9847. };
  9848. // if(item.value === curentValue || (!isNaN(parseFloat(item.value)) && !isNaN(parseFloat(item.value)) && parseFloat(item.value) === parseFloat(curentValue))){
  9849. // setCurrentItem(item);
  9850. // }
  9851. if (curentValues.indexOf(item.value) > -1) {
  9852. setItem(item);
  9853. }
  9854. dataList.push(item);
  9855. displayList.push(item);
  9856. }
  9857. });
  9858. } else {
  9859. for (var key in inputValues) {
  9860. var item = {
  9861. label: inputValues[key],
  9862. value: key,
  9863. element: false
  9864. };
  9865. // if(item.value === curentValue || (!isNaN(parseFloat(item.value)) && !isNaN(parseFloat(item.value)) && parseFloat(item.value) === parseFloat(curentValue))){
  9866. // setCurrentItem(item);
  9867. // }
  9868. if (curentValues.indexOf(item.value) > -1) {
  9869. setItem(item);
  9870. }
  9871. dataList.push(item);
  9872. displayList.push(item);
  9873. }
  9874. }
  9875. dataItems = dataList;
  9876. displayItems = displayList;
  9877. fillList();
  9878. }
  9879. function fillList() {
  9880. while (listEl.firstChild) {
  9881. listEl.removeChild(listEl.firstChild);
  9882. }displayItems.forEach(function (item) {
  9883. var el = item.element;
  9884. if (!el) {
  9885. el = document.createElement("div");
  9886. item.label = editorParams.listItemFormatter ? editorParams.listItemFormatter(item.value, item.label, cell, el, item.itemParams) : item.label;
  9887. if (item.group) {
  9888. el.classList.add("tabulator-edit-select-list-group");
  9889. el.tabIndex = 0;
  9890. el.innerHTML = item.label === "" ? "&nbsp;" : item.label;
  9891. } else {
  9892. el.classList.add("tabulator-edit-select-list-item");
  9893. el.tabIndex = 0;
  9894. el.innerHTML = item.label === "" ? "&nbsp;" : item.label;
  9895. el.addEventListener("click", function () {
  9896. blockListShow = true;
  9897. setTimeout(function () {
  9898. blockListShow = false;
  9899. }, 10);
  9900. // setCurrentItem(item);
  9901. // chooseItem();
  9902. if (multiselect) {
  9903. toggleItem(item);
  9904. input.focus();
  9905. } else {
  9906. chooseItem(item);
  9907. }
  9908. });
  9909. // if(item === currentItem){
  9910. // el.classList.add("active");
  9911. // }
  9912. if (currentItems.indexOf(item) > -1) {
  9913. el.classList.add("active");
  9914. }
  9915. }
  9916. if (item.elementAttributes && _typeof(item.elementAttributes) == "object") {
  9917. for (var key in item.elementAttributes) {
  9918. if (key.charAt(0) == "+") {
  9919. key = key.slice(1);
  9920. el.setAttribute(key, input.getAttribute(key) + item.elementAttributes["+" + key]);
  9921. } else {
  9922. el.setAttribute(key, item.elementAttributes[key]);
  9923. }
  9924. }
  9925. }
  9926. el.addEventListener("mousedown", function () {
  9927. blurable = false;
  9928. setTimeout(function () {
  9929. blurable = true;
  9930. }, 10);
  9931. });
  9932. item.element = el;
  9933. }
  9934. listEl.appendChild(el);
  9935. });
  9936. }
  9937. function setCurrentItem(item, active) {
  9938. if (!multiselect && currentItem && currentItem.element) {
  9939. currentItem.element.classList.remove("active");
  9940. }
  9941. if (currentItem && currentItem.element) {
  9942. currentItem.element.classList.remove("focused");
  9943. }
  9944. currentItem = item;
  9945. if (item.element) {
  9946. item.element.classList.add("focused");
  9947. if (active) {
  9948. item.element.classList.add("active");
  9949. }
  9950. }
  9951. }
  9952. // function chooseItem(){
  9953. // hideList();
  9954. // if(initialValue !== currentItem.value){
  9955. // initialValue = currentItem.value;
  9956. // success(currentItem.value);
  9957. // }else{
  9958. // cancel();
  9959. // }
  9960. // }
  9961. function setItem(item) {
  9962. var index = currentItems.indexOf(item);
  9963. if (index == -1) {
  9964. currentItems.push(item);
  9965. setCurrentItem(item, true);
  9966. }
  9967. fillInput();
  9968. }
  9969. function unsetItem(index) {
  9970. var item = currentItems[index];
  9971. if (index > -1) {
  9972. currentItems.splice(index, 1);
  9973. if (item.element) {
  9974. item.element.classList.remove("active");
  9975. }
  9976. }
  9977. }
  9978. function toggleItem(item) {
  9979. if (!item) {
  9980. item = currentItem;
  9981. }
  9982. var index = currentItems.indexOf(item);
  9983. if (index > -1) {
  9984. unsetItem(index);
  9985. } else {
  9986. if (multiselect !== true && currentItems.length >= multiselect) {
  9987. unsetItem(0);
  9988. }
  9989. setItem(item);
  9990. }
  9991. fillInput();
  9992. }
  9993. function chooseItem(item) {
  9994. hideList();
  9995. if (!item) {
  9996. item = currentItem;
  9997. }
  9998. if (item) {
  9999. input.value = item.label;
  10000. success(item.value);
  10001. }
  10002. initialDisplayValue = input.value;
  10003. }
  10004. function chooseItems(silent) {
  10005. if (!silent) {
  10006. hideList();
  10007. }
  10008. var output = [];
  10009. currentItems.forEach(function (item) {
  10010. output.push(item.value);
  10011. });
  10012. initialDisplayValue = input.value;
  10013. success(output);
  10014. }
  10015. function fillInput() {
  10016. var output = [];
  10017. currentItems.forEach(function (item) {
  10018. output.push(item.label);
  10019. });
  10020. input.value = output.join(", ");
  10021. if (self.currentCell === false) {
  10022. chooseItems(true);
  10023. }
  10024. }
  10025. function unsetItems() {
  10026. var len = currentItems.length;
  10027. for (var _i9 = 0; _i9 < len; _i9++) {
  10028. unsetItem(0);
  10029. }
  10030. }
  10031. function cancelItem() {
  10032. hideList();
  10033. cancel();
  10034. }
  10035. function showList() {
  10036. currentItems = [];
  10037. if (!listEl.parentNode) {
  10038. if (editorParams.values === true) {
  10039. parseItems(getUniqueColumnValues(), initialDisplayValue);
  10040. } else if (typeof editorParams.values === "string") {
  10041. parseItems(getUniqueColumnValues(editorParams.values), initialDisplayValue);
  10042. } else {
  10043. parseItems(editorParams.values || [], initialDisplayValue);
  10044. }
  10045. var offset = Tabulator.prototype.helpers.elOffset(cellEl);
  10046. listEl.style.minWidth = cellEl.offsetWidth + "px";
  10047. listEl.style.top = offset.top + cellEl.offsetHeight + "px";
  10048. listEl.style.left = offset.left + "px";
  10049. listEl.addEventListener("mousedown", function (e) {
  10050. blurable = false;
  10051. setTimeout(function () {
  10052. blurable = true;
  10053. }, 10);
  10054. });
  10055. document.body.appendChild(listEl);
  10056. }
  10057. }
  10058. function hideList() {
  10059. if (listEl.parentNode) {
  10060. listEl.parentNode.removeChild(listEl);
  10061. }
  10062. removeScrollListener();
  10063. }
  10064. function removeScrollListener() {
  10065. self.table.rowManager.element.removeEventListener("scroll", cancelItem);
  10066. }
  10067. //style input
  10068. input.setAttribute("type", "text");
  10069. input.style.padding = "4px";
  10070. input.style.width = "100%";
  10071. input.style.boxSizing = "border-box";
  10072. input.style.cursor = "default";
  10073. input.readOnly = this.currentCell != false;
  10074. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  10075. for (var key in editorParams.elementAttributes) {
  10076. if (key.charAt(0) == "+") {
  10077. key = key.slice(1);
  10078. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  10079. } else {
  10080. input.setAttribute(key, editorParams.elementAttributes[key]);
  10081. }
  10082. }
  10083. }
  10084. input.value = typeof initialValue !== "undefined" || initialValue === null ? initialValue : "";
  10085. // if(editorParams.values === true){
  10086. // parseItems(getUniqueColumnValues(), initialValue);
  10087. // }else if(typeof editorParams.values === "string"){
  10088. // parseItems(getUniqueColumnValues(editorParams.values), initialValue);
  10089. // }else{
  10090. // parseItems(editorParams.values || [], initialValue);
  10091. // }
  10092. input.addEventListener("search", function (e) {
  10093. if (!input.value) {
  10094. unsetItems();
  10095. chooseItems();
  10096. }
  10097. });
  10098. //allow key based navigation
  10099. input.addEventListener("keydown", function (e) {
  10100. var index;
  10101. switch (e.keyCode) {
  10102. case 38:
  10103. //up arrow
  10104. index = dataItems.indexOf(currentItem);
  10105. if (vertNav == "editor" || vertNav == "hybrid" && index) {
  10106. e.stopImmediatePropagation();
  10107. e.stopPropagation();
  10108. e.preventDefault();
  10109. if (index > 0) {
  10110. setCurrentItem(dataItems[index - 1], !multiselect);
  10111. }
  10112. }
  10113. break;
  10114. case 40:
  10115. //down arrow
  10116. index = dataItems.indexOf(currentItem);
  10117. if (vertNav == "editor" || vertNav == "hybrid" && index < dataItems.length - 1) {
  10118. e.stopImmediatePropagation();
  10119. e.stopPropagation();
  10120. e.preventDefault();
  10121. if (index < dataItems.length - 1) {
  10122. if (index == -1) {
  10123. setCurrentItem(dataItems[0], !multiselect);
  10124. } else {
  10125. setCurrentItem(dataItems[index + 1], !multiselect);
  10126. }
  10127. }
  10128. }
  10129. break;
  10130. case 37: //left arrow
  10131. case 39:
  10132. //right arrow
  10133. e.stopImmediatePropagation();
  10134. e.stopPropagation();
  10135. e.preventDefault();
  10136. break;
  10137. case 13:
  10138. //enter
  10139. // chooseItem();
  10140. if (multiselect) {
  10141. toggleItem();
  10142. } else {
  10143. chooseItem();
  10144. }
  10145. break;
  10146. case 27:
  10147. //escape
  10148. cancelItem();
  10149. break;
  10150. case 9:
  10151. //tab
  10152. break;
  10153. default:
  10154. if (self.currentCell === false) {
  10155. e.preventDefault();
  10156. }
  10157. }
  10158. });
  10159. input.addEventListener("blur", function (e) {
  10160. if (blurable) {
  10161. if (multiselect) {
  10162. chooseItems();
  10163. } else {
  10164. cancelItem();
  10165. }
  10166. }
  10167. });
  10168. input.addEventListener("focus", function (e) {
  10169. if (!blockListShow) {
  10170. showList();
  10171. }
  10172. });
  10173. //style list element
  10174. listEl = document.createElement("div");
  10175. listEl.classList.add("tabulator-edit-select-list");
  10176. onRendered(function () {
  10177. input.style.height = "100%";
  10178. input.focus({ preventScroll: true });
  10179. });
  10180. setTimeout(function () {
  10181. _this53.table.rowManager.element.addEventListener("scroll", cancelItem);
  10182. }, 10);
  10183. return input;
  10184. },
  10185. //autocomplete
  10186. autocomplete: function autocomplete(cell, onRendered, success, cancel, editorParams) {
  10187. var _this54 = this;
  10188. var self = this,
  10189. cellEl = cell.getElement(),
  10190. initialValue = cell.getValue(),
  10191. vertNav = editorParams.verticalNavigation || "editor",
  10192. initialDisplayValue = typeof initialValue !== "undefined" || initialValue === null ? initialValue : typeof editorParams.defaultValue !== "undefined" ? editorParams.defaultValue : "",
  10193. input = document.createElement("input"),
  10194. listEl = document.createElement("div"),
  10195. allItems = [],
  10196. displayItems = [],
  10197. values = [],
  10198. currentItem = false,
  10199. blurable = true,
  10200. uniqueColumnValues = false;
  10201. //style input
  10202. input.setAttribute("type", "search");
  10203. input.style.padding = "4px";
  10204. input.style.width = "100%";
  10205. input.style.boxSizing = "border-box";
  10206. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  10207. for (var key in editorParams.elementAttributes) {
  10208. if (key.charAt(0) == "+") {
  10209. key = key.slice(1);
  10210. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  10211. } else {
  10212. input.setAttribute(key, editorParams.elementAttributes[key]);
  10213. }
  10214. }
  10215. }
  10216. //style list element
  10217. listEl.classList.add("tabulator-edit-select-list");
  10218. listEl.addEventListener("mousedown", function (e) {
  10219. blurable = false;
  10220. setTimeout(function () {
  10221. blurable = true;
  10222. }, 10);
  10223. });
  10224. function genUniqueColumnValues() {
  10225. if (editorParams.values === true) {
  10226. uniqueColumnValues = getUniqueColumnValues();
  10227. } else if (typeof editorParams.values === "string") {
  10228. uniqueColumnValues = getUniqueColumnValues(editorParams.values);
  10229. }
  10230. }
  10231. function getUniqueColumnValues(field) {
  10232. var output = {},
  10233. data = self.table.getData(),
  10234. column;
  10235. if (field) {
  10236. column = self.table.columnManager.getColumnByField(field);
  10237. } else {
  10238. column = cell.getColumn()._getSelf();
  10239. }
  10240. if (column) {
  10241. data.forEach(function (row) {
  10242. var val = column.getFieldValue(row);
  10243. if (val !== null && typeof val !== "undefined" && val !== "") {
  10244. output[val] = true;
  10245. }
  10246. });
  10247. if (editorParams.sortValuesList) {
  10248. if (editorParams.sortValuesList == "asc") {
  10249. output = Object.keys(output).sort();
  10250. } else {
  10251. output = Object.keys(output).sort().reverse();
  10252. }
  10253. } else {
  10254. output = Object.keys(output);
  10255. }
  10256. } else {
  10257. console.warn("unable to find matching column to create autocomplete lookup list:", field);
  10258. }
  10259. return output;
  10260. }
  10261. function filterList(term, intialLoad) {
  10262. var matches = [],
  10263. values,
  10264. items,
  10265. searchEl;
  10266. //lookup base values list
  10267. if (uniqueColumnValues) {
  10268. values = uniqueColumnValues;
  10269. } else {
  10270. values = editorParams.values || [];
  10271. }
  10272. if (editorParams.searchFunc) {
  10273. matches = editorParams.searchFunc(term, values);
  10274. if (matches instanceof Promise) {
  10275. addNotice(typeof editorParams.searchingPlaceholder !== "undefined" ? editorParams.searchingPlaceholder : "Searching...");
  10276. matches.then(function (result) {
  10277. fillListIfNotEmpty(parseItems(result), intialLoad);
  10278. }).catch(function (err) {
  10279. console.err("error in autocomplete search promise:", err);
  10280. });
  10281. } else {
  10282. fillListIfNotEmpty(parseItems(matches), intialLoad);
  10283. }
  10284. } else {
  10285. items = parseItems(values);
  10286. if (term === "") {
  10287. if (editorParams.showListOnEmpty) {
  10288. matches = items;
  10289. }
  10290. } else {
  10291. items.forEach(function (item) {
  10292. if (item.value !== null || typeof item.value !== "undefined") {
  10293. if (String(item.value).toLowerCase().indexOf(String(term).toLowerCase()) > -1 || String(item.title).toLowerCase().indexOf(String(term).toLowerCase()) > -1) {
  10294. matches.push(item);
  10295. }
  10296. }
  10297. });
  10298. }
  10299. fillListIfNotEmpty(matches, intialLoad);
  10300. }
  10301. }
  10302. function addNotice(notice) {
  10303. var searchEl = document.createElement("div");
  10304. clearList();
  10305. if (notice !== false) {
  10306. searchEl.classList.add("tabulator-edit-select-list-notice");
  10307. searchEl.tabIndex = 0;
  10308. if (notice instanceof Node) {
  10309. searchEl.appendChild(notice);
  10310. } else {
  10311. searchEl.innerHTML = notice;
  10312. }
  10313. listEl.appendChild(searchEl);
  10314. }
  10315. }
  10316. function parseItems(inputValues) {
  10317. var itemList = [];
  10318. if (Array.isArray(inputValues)) {
  10319. inputValues.forEach(function (value) {
  10320. var item = {};
  10321. if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === "object") {
  10322. item.title = editorParams.listItemFormatter ? editorParams.listItemFormatter(value.value, value.label) : value.label;
  10323. item.value = value.value;
  10324. } else {
  10325. item.title = editorParams.listItemFormatter ? editorParams.listItemFormatter(value, value) : value;
  10326. item.value = value;
  10327. }
  10328. itemList.push(item);
  10329. });
  10330. } else {
  10331. for (var key in inputValues) {
  10332. var item = {
  10333. title: editorParams.listItemFormatter ? editorParams.listItemFormatter(key, inputValues[key]) : inputValues[key],
  10334. value: key
  10335. };
  10336. itemList.push(item);
  10337. }
  10338. }
  10339. return itemList;
  10340. }
  10341. function clearList() {
  10342. while (listEl.firstChild) {
  10343. listEl.removeChild(listEl.firstChild);
  10344. }
  10345. }
  10346. function fillListIfNotEmpty(items, intialLoad) {
  10347. if (items.length) {
  10348. fillList(items, intialLoad);
  10349. } else {
  10350. if (editorParams.emptyPlaceholder) {
  10351. addNotice(editorParams.emptyPlaceholder);
  10352. }
  10353. }
  10354. }
  10355. function fillList(items, intialLoad) {
  10356. var current = false;
  10357. clearList();
  10358. displayItems = items;
  10359. displayItems.forEach(function (item) {
  10360. var el = item.element;
  10361. if (!el) {
  10362. el = document.createElement("div");
  10363. el.classList.add("tabulator-edit-select-list-item");
  10364. el.tabIndex = 0;
  10365. el.innerHTML = item.title;
  10366. el.addEventListener("click", function (e) {
  10367. setCurrentItem(item);
  10368. chooseItem();
  10369. });
  10370. el.addEventListener("mousedown", function (e) {
  10371. blurable = false;
  10372. setTimeout(function () {
  10373. blurable = true;
  10374. }, 10);
  10375. });
  10376. item.element = el;
  10377. if (intialLoad && item.value == initialValue) {
  10378. input.value = item.title;
  10379. item.element.classList.add("active");
  10380. current = true;
  10381. }
  10382. if (item === currentItem) {
  10383. item.element.classList.add("active");
  10384. current = true;
  10385. }
  10386. }
  10387. listEl.appendChild(el);
  10388. });
  10389. if (!current) {
  10390. setCurrentItem(false);
  10391. }
  10392. }
  10393. function chooseItem() {
  10394. hideList();
  10395. if (currentItem) {
  10396. if (initialValue !== currentItem.value) {
  10397. initialValue = currentItem.value;
  10398. input.value = currentItem.title;
  10399. success(currentItem.value);
  10400. } else {
  10401. cancel();
  10402. }
  10403. } else {
  10404. if (editorParams.freetext) {
  10405. initialValue = input.value;
  10406. success(input.value);
  10407. } else {
  10408. if (editorParams.allowEmpty && input.value === "") {
  10409. initialValue = input.value;
  10410. success(input.value);
  10411. } else {
  10412. cancel();
  10413. }
  10414. }
  10415. }
  10416. }
  10417. function showList() {
  10418. if (!listEl.parentNode) {
  10419. while (listEl.firstChild) {
  10420. listEl.removeChild(listEl.firstChild);
  10421. }var offset = Tabulator.prototype.helpers.elOffset(cellEl);
  10422. listEl.style.minWidth = cellEl.offsetWidth + "px";
  10423. listEl.style.top = offset.top + cellEl.offsetHeight + "px";
  10424. listEl.style.left = offset.left + "px";
  10425. document.body.appendChild(listEl);
  10426. }
  10427. }
  10428. function setCurrentItem(item, showInputValue) {
  10429. if (currentItem && currentItem.element) {
  10430. currentItem.element.classList.remove("active");
  10431. }
  10432. currentItem = item;
  10433. if (item && item.element) {
  10434. item.element.classList.add("active");
  10435. }
  10436. }
  10437. function hideList() {
  10438. if (listEl.parentNode) {
  10439. listEl.parentNode.removeChild(listEl);
  10440. }
  10441. removeScrollListener();
  10442. }
  10443. function cancelItem() {
  10444. hideList();
  10445. cancel();
  10446. }
  10447. function removeScrollListener() {
  10448. self.table.rowManager.element.removeEventListener("scroll", cancelItem);
  10449. }
  10450. //allow key based navigation
  10451. input.addEventListener("keydown", function (e) {
  10452. var index;
  10453. switch (e.keyCode) {
  10454. case 38:
  10455. //up arrow
  10456. index = displayItems.indexOf(currentItem);
  10457. if (vertNav == "editor" || vertNav == "hybrid" && index) {
  10458. e.stopImmediatePropagation();
  10459. e.stopPropagation();
  10460. e.preventDefault();
  10461. if (index > 0) {
  10462. setCurrentItem(displayItems[index - 1]);
  10463. } else {
  10464. setCurrentItem(false);
  10465. }
  10466. }
  10467. break;
  10468. case 40:
  10469. //down arrow
  10470. index = displayItems.indexOf(currentItem);
  10471. if (vertNav == "editor" || vertNav == "hybrid" && index < displayItems.length - 1) {
  10472. e.stopImmediatePropagation();
  10473. e.stopPropagation();
  10474. e.preventDefault();
  10475. if (index < displayItems.length - 1) {
  10476. if (index == -1) {
  10477. setCurrentItem(displayItems[0]);
  10478. } else {
  10479. setCurrentItem(displayItems[index + 1]);
  10480. }
  10481. }
  10482. }
  10483. break;
  10484. case 37: //left arrow
  10485. case 39:
  10486. //right arrow
  10487. e.stopImmediatePropagation();
  10488. e.stopPropagation();
  10489. // e.preventDefault();
  10490. break;
  10491. case 13:
  10492. //enter
  10493. chooseItem();
  10494. break;
  10495. case 27:
  10496. //escape
  10497. cancelItem();
  10498. break;
  10499. case 36: //home
  10500. case 35:
  10501. //end
  10502. //prevent table navigation while using input element
  10503. e.stopImmediatePropagation();
  10504. break;
  10505. }
  10506. });
  10507. input.addEventListener("keyup", function (e) {
  10508. switch (e.keyCode) {
  10509. case 38: //up arrow
  10510. case 37: //left arrow
  10511. case 39: //up arrow
  10512. case 40: //right arrow
  10513. case 13: //enter
  10514. case 27:
  10515. //escape
  10516. break;
  10517. default:
  10518. filterList(input.value);
  10519. }
  10520. });
  10521. input.addEventListener("search", function (e) {
  10522. filterList(input.value);
  10523. });
  10524. input.addEventListener("blur", function (e) {
  10525. if (blurable) {
  10526. chooseItem();
  10527. }
  10528. });
  10529. input.addEventListener("focus", function (e) {
  10530. var value = initialDisplayValue;
  10531. genUniqueColumnValues();
  10532. showList();
  10533. input.value = value;
  10534. filterList(value, true);
  10535. });
  10536. onRendered(function () {
  10537. input.style.height = "100%";
  10538. input.focus({ preventScroll: true });
  10539. });
  10540. if (editorParams.mask) {
  10541. this.table.modules.edit.maskInput(input, editorParams);
  10542. }
  10543. setTimeout(function () {
  10544. _this54.table.rowManager.element.addEventListener("scroll", cancelItem);
  10545. }, 10);
  10546. genUniqueColumnValues();
  10547. input.value = initialDisplayValue;
  10548. filterList(initialDisplayValue, true);
  10549. return input;
  10550. },
  10551. //star rating
  10552. star: function star(cell, onRendered, success, cancel, editorParams) {
  10553. var self = this,
  10554. element = cell.getElement(),
  10555. value = cell.getValue(),
  10556. maxStars = element.getElementsByTagName("svg").length || 5,
  10557. size = element.getElementsByTagName("svg")[0] ? element.getElementsByTagName("svg")[0].getAttribute("width") : 14,
  10558. stars = [],
  10559. starsHolder = document.createElement("div"),
  10560. star = document.createElementNS('http://www.w3.org/2000/svg', "svg");
  10561. //change star type
  10562. function starChange(val) {
  10563. stars.forEach(function (star, i) {
  10564. if (i < val) {
  10565. if (self.table.browser == "ie") {
  10566. star.setAttribute("class", "tabulator-star-active");
  10567. } else {
  10568. star.classList.replace("tabulator-star-inactive", "tabulator-star-active");
  10569. }
  10570. 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 "/>';
  10571. } else {
  10572. if (self.table.browser == "ie") {
  10573. star.setAttribute("class", "tabulator-star-inactive");
  10574. } else {
  10575. star.classList.replace("tabulator-star-active", "tabulator-star-inactive");
  10576. }
  10577. 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 "/>';
  10578. }
  10579. });
  10580. }
  10581. //build stars
  10582. function buildStar(i) {
  10583. var starHolder = document.createElement("span");
  10584. var nextStar = star.cloneNode(true);
  10585. stars.push(nextStar);
  10586. starHolder.addEventListener("mouseenter", function (e) {
  10587. e.stopPropagation();
  10588. e.stopImmediatePropagation();
  10589. starChange(i);
  10590. });
  10591. starHolder.addEventListener("mousemove", function (e) {
  10592. e.stopPropagation();
  10593. e.stopImmediatePropagation();
  10594. });
  10595. starHolder.addEventListener("click", function (e) {
  10596. e.stopPropagation();
  10597. e.stopImmediatePropagation();
  10598. success(i);
  10599. element.blur();
  10600. });
  10601. starHolder.appendChild(nextStar);
  10602. starsHolder.appendChild(starHolder);
  10603. }
  10604. //handle keyboard navigation value change
  10605. function changeValue(val) {
  10606. value = val;
  10607. starChange(val);
  10608. }
  10609. //style cell
  10610. element.style.whiteSpace = "nowrap";
  10611. element.style.overflow = "hidden";
  10612. element.style.textOverflow = "ellipsis";
  10613. //style holding element
  10614. starsHolder.style.verticalAlign = "middle";
  10615. starsHolder.style.display = "inline-block";
  10616. starsHolder.style.padding = "4px";
  10617. //style star
  10618. star.setAttribute("width", size);
  10619. star.setAttribute("height", size);
  10620. star.setAttribute("viewBox", "0 0 512 512");
  10621. star.setAttribute("xml:space", "preserve");
  10622. star.style.padding = "0 1px";
  10623. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  10624. for (var key in editorParams.elementAttributes) {
  10625. if (key.charAt(0) == "+") {
  10626. key = key.slice(1);
  10627. starsHolder.setAttribute(key, starsHolder.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  10628. } else {
  10629. starsHolder.setAttribute(key, editorParams.elementAttributes[key]);
  10630. }
  10631. }
  10632. }
  10633. //create correct number of stars
  10634. for (var i = 1; i <= maxStars; i++) {
  10635. buildStar(i);
  10636. }
  10637. //ensure value does not exceed number of stars
  10638. value = Math.min(parseInt(value), maxStars);
  10639. // set initial styling of stars
  10640. starChange(value);
  10641. starsHolder.addEventListener("mousemove", function (e) {
  10642. starChange(0);
  10643. });
  10644. starsHolder.addEventListener("click", function (e) {
  10645. success(0);
  10646. });
  10647. element.addEventListener("blur", function (e) {
  10648. cancel();
  10649. });
  10650. //allow key based navigation
  10651. element.addEventListener("keydown", function (e) {
  10652. switch (e.keyCode) {
  10653. case 39:
  10654. //right arrow
  10655. changeValue(value + 1);
  10656. break;
  10657. case 37:
  10658. //left arrow
  10659. changeValue(value - 1);
  10660. break;
  10661. case 13:
  10662. //enter
  10663. success(value);
  10664. break;
  10665. case 27:
  10666. //escape
  10667. cancel();
  10668. break;
  10669. }
  10670. });
  10671. return starsHolder;
  10672. },
  10673. //draggable progress bar
  10674. progress: function progress(cell, onRendered, success, cancel, editorParams) {
  10675. var element = cell.getElement(),
  10676. max = typeof editorParams.max === "undefined" ? element.getElementsByTagName("div")[0].getAttribute("max") || 100 : editorParams.max,
  10677. min = typeof editorParams.min === "undefined" ? element.getElementsByTagName("div")[0].getAttribute("min") || 0 : editorParams.min,
  10678. percent = (max - min) / 100,
  10679. value = cell.getValue() || 0,
  10680. handle = document.createElement("div"),
  10681. bar = document.createElement("div"),
  10682. mouseDrag,
  10683. mouseDragWidth;
  10684. //set new value
  10685. function updateValue() {
  10686. var calcVal = percent * Math.round(bar.offsetWidth / (element.clientWidth / 100)) + min;
  10687. success(calcVal);
  10688. element.setAttribute("aria-valuenow", calcVal);
  10689. element.setAttribute("aria-label", value);
  10690. }
  10691. //style handle
  10692. handle.style.position = "absolute";
  10693. handle.style.right = "0";
  10694. handle.style.top = "0";
  10695. handle.style.bottom = "0";
  10696. handle.style.width = "5px";
  10697. handle.classList.add("tabulator-progress-handle");
  10698. //style bar
  10699. bar.style.display = "inline-block";
  10700. bar.style.position = "relative";
  10701. // bar.style.top = "8px";
  10702. // bar.style.bottom = "8px";
  10703. // bar.style.left = "4px";
  10704. // bar.style.marginRight = "4px";
  10705. bar.style.height = "100%";
  10706. bar.style.backgroundColor = "#488CE9";
  10707. bar.style.maxWidth = "100%";
  10708. bar.style.minWidth = "0%";
  10709. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  10710. for (var key in editorParams.elementAttributes) {
  10711. if (key.charAt(0) == "+") {
  10712. key = key.slice(1);
  10713. bar.setAttribute(key, bar.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  10714. } else {
  10715. bar.setAttribute(key, editorParams.elementAttributes[key]);
  10716. }
  10717. }
  10718. }
  10719. //style cell
  10720. element.style.padding = "4px 4px";
  10721. //make sure value is in range
  10722. value = Math.min(parseFloat(value), max);
  10723. value = Math.max(parseFloat(value), min);
  10724. //workout percentage
  10725. value = Math.round((value - min) / percent);
  10726. // bar.style.right = value + "%";
  10727. bar.style.width = value + "%";
  10728. element.setAttribute("aria-valuemin", min);
  10729. element.setAttribute("aria-valuemax", max);
  10730. bar.appendChild(handle);
  10731. handle.addEventListener("mousedown", function (e) {
  10732. mouseDrag = e.screenX;
  10733. mouseDragWidth = bar.offsetWidth;
  10734. });
  10735. handle.addEventListener("mouseover", function () {
  10736. handle.style.cursor = "ew-resize";
  10737. });
  10738. element.addEventListener("mousemove", function (e) {
  10739. if (mouseDrag) {
  10740. bar.style.width = mouseDragWidth + e.screenX - mouseDrag + "px";
  10741. }
  10742. });
  10743. element.addEventListener("mouseup", function (e) {
  10744. if (mouseDrag) {
  10745. e.stopPropagation();
  10746. e.stopImmediatePropagation();
  10747. mouseDrag = false;
  10748. mouseDragWidth = false;
  10749. updateValue();
  10750. }
  10751. });
  10752. //allow key based navigation
  10753. element.addEventListener("keydown", function (e) {
  10754. switch (e.keyCode) {
  10755. case 39:
  10756. //right arrow
  10757. e.preventDefault();
  10758. bar.style.width = bar.clientWidth + element.clientWidth / 100 + "px";
  10759. break;
  10760. case 37:
  10761. //left arrow
  10762. e.preventDefault();
  10763. bar.style.width = bar.clientWidth - element.clientWidth / 100 + "px";
  10764. break;
  10765. case 9: //tab
  10766. case 13:
  10767. //enter
  10768. updateValue();
  10769. break;
  10770. case 27:
  10771. //escape
  10772. cancel();
  10773. break;
  10774. }
  10775. });
  10776. element.addEventListener("blur", function () {
  10777. cancel();
  10778. });
  10779. return bar;
  10780. },
  10781. //checkbox
  10782. tickCross: function tickCross(cell, onRendered, success, cancel, editorParams) {
  10783. var value = cell.getValue(),
  10784. input = document.createElement("input"),
  10785. tristate = editorParams.tristate,
  10786. indetermValue = typeof editorParams.indeterminateValue === "undefined" ? null : editorParams.indeterminateValue,
  10787. indetermState = false;
  10788. input.setAttribute("type", "checkbox");
  10789. input.style.marginTop = "5px";
  10790. input.style.boxSizing = "border-box";
  10791. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  10792. for (var key in editorParams.elementAttributes) {
  10793. if (key.charAt(0) == "+") {
  10794. key = key.slice(1);
  10795. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  10796. } else {
  10797. input.setAttribute(key, editorParams.elementAttributes[key]);
  10798. }
  10799. }
  10800. }
  10801. input.value = value;
  10802. if (tristate && (typeof value === "undefined" || value === indetermValue || value === "")) {
  10803. indetermState = true;
  10804. input.indeterminate = true;
  10805. }
  10806. if (this.table.browser != "firefox") {
  10807. //prevent blur issue on mac firefox
  10808. onRendered(function () {
  10809. input.focus({ preventScroll: true });
  10810. });
  10811. }
  10812. input.checked = value === true || value === "true" || value === "True" || value === 1;
  10813. onRendered(function () {
  10814. input.focus();
  10815. });
  10816. function setValue(blur) {
  10817. if (tristate) {
  10818. if (!blur) {
  10819. if (input.checked && !indetermState) {
  10820. input.checked = false;
  10821. input.indeterminate = true;
  10822. indetermState = true;
  10823. return indetermValue;
  10824. } else {
  10825. indetermState = false;
  10826. return input.checked;
  10827. }
  10828. } else {
  10829. if (indetermState) {
  10830. return indetermValue;
  10831. } else {
  10832. return input.checked;
  10833. }
  10834. }
  10835. } else {
  10836. return input.checked;
  10837. }
  10838. }
  10839. //submit new value on blur
  10840. input.addEventListener("change", function (e) {
  10841. success(setValue());
  10842. });
  10843. input.addEventListener("blur", function (e) {
  10844. success(setValue(true));
  10845. });
  10846. //submit new value on enter
  10847. input.addEventListener("keydown", function (e) {
  10848. if (e.keyCode == 13) {
  10849. success(setValue());
  10850. }
  10851. if (e.keyCode == 27) {
  10852. cancel();
  10853. }
  10854. });
  10855. return input;
  10856. }
  10857. };
  10858. Tabulator.prototype.registerModule("edit", Edit);
  10859. var ExportRow = function ExportRow(type, columns, component, indent) {
  10860. this.type = type;
  10861. this.columns = columns;
  10862. this.component = component || false;
  10863. this.indent = indent || 0;
  10864. };
  10865. var ExportColumn = function ExportColumn(value, component, width, height, depth) {
  10866. this.value = value;
  10867. this.component = component || false;
  10868. this.width = width;
  10869. this.height = height;
  10870. this.depth = depth;
  10871. };
  10872. var Export = function Export(table) {
  10873. this.table = table; //hold Tabulator object
  10874. this.config = {};
  10875. this.cloneTableStyle = true;
  10876. this.colVisProp = "";
  10877. };
  10878. Export.prototype.generateExportList = function (config, style, range, colVisProp) {
  10879. this.cloneTableStyle = style;
  10880. this.config = config || {};
  10881. this.colVisProp = colVisProp;
  10882. var headers = this.config.columnHeaders !== false ? this.headersToExportRows(this.generateColumnGroupHeaders()) : [];
  10883. var body = this.bodyToExportRows(this.rowLookup(range));
  10884. return headers.concat(body);
  10885. };
  10886. Export.prototype.genereateTable = function (config, style, range, colVisProp) {
  10887. var list = this.generateExportList(config, style, range, colVisProp);
  10888. return this.genereateTableElement(list);
  10889. };
  10890. Export.prototype.rowLookup = function (range) {
  10891. var _this55 = this;
  10892. var rows = [];
  10893. if (typeof range == "function") {
  10894. range.call(this.table).forEach(function (row) {
  10895. row = _this55.table.rowManager.findRow(row);
  10896. if (row) {
  10897. rows.push(row);
  10898. }
  10899. });
  10900. } else {
  10901. switch (range) {
  10902. case true:
  10903. case "visible":
  10904. rows = this.table.rowManager.getVisibleRows(true);
  10905. break;
  10906. case "all":
  10907. rows = this.table.rowManager.rows;
  10908. break;
  10909. case "selected":
  10910. rows = this.table.modules.selectRow.selectedRows;
  10911. break;
  10912. case "active":
  10913. default:
  10914. if (this.table.options.pagination) {
  10915. rows = this.table.rowManager.getDisplayRows(this.table.rowManager.displayRows.length - 2);
  10916. } else {
  10917. rows = this.table.rowManager.getDisplayRows();
  10918. }
  10919. }
  10920. }
  10921. return Object.assign([], rows);
  10922. };
  10923. Export.prototype.generateColumnGroupHeaders = function () {
  10924. var _this56 = this;
  10925. var output = [];
  10926. var columns = this.config.columnGroups !== false ? this.table.columnManager.columns : this.table.columnManager.columnsByIndex;
  10927. columns.forEach(function (column) {
  10928. var colData = _this56.processColumnGroup(column);
  10929. if (colData) {
  10930. output.push(colData);
  10931. }
  10932. });
  10933. return output;
  10934. };
  10935. Export.prototype.processColumnGroup = function (column) {
  10936. var _this57 = this;
  10937. var subGroups = column.columns,
  10938. maxDepth = 0,
  10939. title = column.definition["title" + (this.colVisProp.charAt(0).toUpperCase() + this.colVisProp.slice(1))] || column.definition.title;
  10940. var groupData = {
  10941. title: title,
  10942. column: column,
  10943. depth: 1
  10944. };
  10945. if (subGroups.length) {
  10946. groupData.subGroups = [];
  10947. groupData.width = 0;
  10948. subGroups.forEach(function (subGroup) {
  10949. var subGroupData = _this57.processColumnGroup(subGroup);
  10950. if (subGroupData) {
  10951. groupData.width += subGroupData.width;
  10952. groupData.subGroups.push(subGroupData);
  10953. if (subGroupData.depth > maxDepth) {
  10954. maxDepth = subGroupData.depth;
  10955. }
  10956. }
  10957. });
  10958. groupData.depth += maxDepth;
  10959. if (!groupData.width) {
  10960. return false;
  10961. }
  10962. } else {
  10963. if (this.columnVisCheck(column)) {
  10964. groupData.width = 1;
  10965. } else {
  10966. return false;
  10967. }
  10968. }
  10969. return groupData;
  10970. };
  10971. Export.prototype.columnVisCheck = function (column) {
  10972. return column.definition[this.colVisProp] !== false && (column.visible || !column.visible && column.definition[this.colVisProp]);
  10973. };
  10974. Export.prototype.headersToExportRows = function (columns) {
  10975. var headers = [],
  10976. headerDepth = 0,
  10977. exportRows = [];
  10978. function parseColumnGroup(column, level) {
  10979. var depth = headerDepth - level;
  10980. if (typeof headers[level] === "undefined") {
  10981. headers[level] = [];
  10982. }
  10983. column.height = column.subGroups ? 1 : depth - column.depth + 1;
  10984. headers[level].push(column);
  10985. if (column.height > 1) {
  10986. for (var _i10 = 1; _i10 < column.height; _i10++) {
  10987. if (typeof headers[level + _i10] === "undefined") {
  10988. headers[level + _i10] = [];
  10989. }
  10990. headers[level + _i10].push(false);
  10991. }
  10992. }
  10993. if (column.width > 1) {
  10994. for (var _i11 = 1; _i11 < column.width; _i11++) {
  10995. headers[level].push(false);
  10996. }
  10997. }
  10998. if (column.subGroups) {
  10999. column.subGroups.forEach(function (subGroup) {
  11000. parseColumnGroup(subGroup, level + 1);
  11001. });
  11002. }
  11003. }
  11004. //calculate maximum header debth
  11005. columns.forEach(function (column) {
  11006. if (column.depth > headerDepth) {
  11007. headerDepth = column.depth;
  11008. }
  11009. });
  11010. columns.forEach(function (column) {
  11011. parseColumnGroup(column, 0);
  11012. });
  11013. headers.forEach(function (header) {
  11014. var columns = [];
  11015. header.forEach(function (col) {
  11016. if (col) {
  11017. columns.push(new ExportColumn(col.title, col.column.getComponent(), col.width, col.height, col.depth));
  11018. } else {
  11019. columns.push(null);
  11020. }
  11021. });
  11022. exportRows.push(new ExportRow("header", columns));
  11023. });
  11024. return exportRows;
  11025. };
  11026. Export.prototype.bodyToExportRows = function (rows) {
  11027. var _this58 = this;
  11028. var columns = [];
  11029. var exportRows = [];
  11030. this.table.columnManager.columnsByIndex.forEach(function (column) {
  11031. if (_this58.columnVisCheck(column)) {
  11032. columns.push(column.getComponent());
  11033. }
  11034. });
  11035. if (this.config.columnCalcs !== false && this.table.modExists("columnCalcs")) {
  11036. if (this.table.modules.columnCalcs.topInitialized) {
  11037. rows.unshift(this.table.modules.columnCalcs.topRow);
  11038. }
  11039. if (this.table.modules.columnCalcs.botInitialized) {
  11040. rows.push(this.table.modules.columnCalcs.botRow);
  11041. }
  11042. }
  11043. rows = rows.filter(function (row) {
  11044. switch (row.type) {
  11045. case "group":
  11046. return _this58.config.rowGroups !== false;
  11047. break;
  11048. case "calc":
  11049. return _this58.config.columnCalcs !== false;
  11050. break;
  11051. case "row":
  11052. return !(_this58.table.options.dataTree && _this58.config.dataTree === false && row.modules.dataTree.parent);
  11053. break;
  11054. }
  11055. return true;
  11056. });
  11057. rows.forEach(function (row, i) {
  11058. var rowData = row.getData(_this58.colVisProp);
  11059. var exportCols = [];
  11060. var indent = 0;
  11061. switch (row.type) {
  11062. case "group":
  11063. indent = row.level;
  11064. exportCols.push(new ExportColumn(row.key, row.getComponent(), columns.length, 1));
  11065. break;
  11066. case "calc":
  11067. case "row":
  11068. columns.forEach(function (col) {
  11069. exportCols.push(new ExportColumn(col._column.getFieldValue(rowData), col, 1, 1));
  11070. });
  11071. if (_this58.table.options.dataTree && _this58.config.dataTree !== false) {
  11072. indent = row.modules.dataTree.index;
  11073. }
  11074. break;
  11075. }
  11076. exportRows.push(new ExportRow(row.type, exportCols, row.getComponent(), indent));
  11077. });
  11078. return exportRows;
  11079. };
  11080. Export.prototype.genereateTableElement = function (list) {
  11081. var _this59 = this;
  11082. var table = document.createElement("table"),
  11083. headerEl = document.createElement("thead"),
  11084. bodyEl = document.createElement("tbody"),
  11085. styles = this.lookupTableStyles(),
  11086. rowFormatter = this.table.options["rowFormatter" + (this.colVisProp.charAt(0).toUpperCase() + this.colVisProp.slice(1))],
  11087. setup = {};
  11088. setup.rowFormatter = rowFormatter !== null ? rowFormatter : this.table.options.rowFormatter;
  11089. if (this.table.options.dataTree && this.config.dataTree !== false && this.table.modExists("columnCalcs")) {
  11090. setup.treeElementField = this.table.modules.dataTree.elementField;
  11091. }
  11092. //assign group header formatter
  11093. setup.groupHeader = this.table.options["groupHeader" + (this.colVisProp.charAt(0).toUpperCase() + this.colVisProp.slice(1))];
  11094. if (setup.groupHeader && !Array.isArray(setup.groupHeader)) {
  11095. setup.groupHeader = [setup.groupHeader];
  11096. }
  11097. table.classList.add("tabulator-print-table");
  11098. this.mapElementStyles(this.table.columnManager.getHeadersElement(), headerEl, ["border-top", "border-left", "border-right", "border-bottom", "background-color", "color", "font-weight", "font-family", "font-size"]);
  11099. if (list.length > 1000) {
  11100. console.warn("It may take a long time to render an HTML table with more than 1000 rows");
  11101. }
  11102. list.forEach(function (row, i) {
  11103. switch (row.type) {
  11104. case "header":
  11105. headerEl.appendChild(_this59.genereateHeaderElement(row, setup, styles));
  11106. break;
  11107. case "group":
  11108. bodyEl.appendChild(_this59.genereateGroupElement(row, setup, styles));
  11109. break;
  11110. case "calc":
  11111. bodyEl.appendChild(_this59.genereateCalcElement(row, setup, styles));
  11112. break;
  11113. case "row":
  11114. var rowEl = _this59.genereateRowElement(row, setup, styles);
  11115. _this59.mapElementStyles(i % 2 && styles.evenRow ? styles.evenRow : styles.oddRow, rowEl, ["border-top", "border-left", "border-right", "border-bottom", "color", "font-weight", "font-family", "font-size", "background-color"]);
  11116. bodyEl.appendChild(rowEl);
  11117. break;
  11118. }
  11119. });
  11120. if (headerEl.innerHTML) {
  11121. table.appendChild(headerEl);
  11122. }
  11123. table.appendChild(bodyEl);
  11124. this.mapElementStyles(this.table.element, table, ["border-top", "border-left", "border-right", "border-bottom"]);
  11125. return table;
  11126. };
  11127. Export.prototype.lookupTableStyles = function () {
  11128. var styles = {};
  11129. //lookup row styles
  11130. if (this.cloneTableStyle && window.getComputedStyle) {
  11131. styles.oddRow = this.table.element.querySelector(".tabulator-row-odd:not(.tabulator-group):not(.tabulator-calcs)");
  11132. styles.evenRow = this.table.element.querySelector(".tabulator-row-even:not(.tabulator-group):not(.tabulator-calcs)");
  11133. styles.calcRow = this.table.element.querySelector(".tabulator-row.tabulator-calcs");
  11134. styles.firstRow = this.table.element.querySelector(".tabulator-row:not(.tabulator-group):not(.tabulator-calcs)");
  11135. styles.firstGroup = this.table.element.getElementsByClassName("tabulator-group")[0];
  11136. if (styles.firstRow) {
  11137. styles.styleCells = styles.firstRow.getElementsByClassName("tabulator-cell");
  11138. styles.firstCell = styles.styleCells[0];
  11139. styles.lastCell = styles.styleCells[styles.styleCells.length - 1];
  11140. }
  11141. }
  11142. return styles;
  11143. };
  11144. Export.prototype.genereateHeaderElement = function (row, setup, styles) {
  11145. var _this60 = this;
  11146. var rowEl = document.createElement("tr");
  11147. row.columns.forEach(function (column) {
  11148. if (column) {
  11149. var cellEl = document.createElement("th");
  11150. var classNames = column.component._column.definition.cssClass ? column.component._column.definition.cssClass.split(" ") : [];
  11151. cellEl.colSpan = column.width;
  11152. cellEl.rowSpan = column.height;
  11153. cellEl.innerHTML = column.value;
  11154. if (_this60.cloneTableStyle) {
  11155. cellEl.style.boxSizing = "border-box";
  11156. }
  11157. classNames.forEach(function (className) {
  11158. cellEl.classList.add(className);
  11159. });
  11160. _this60.mapElementStyles(column.component.getElement(), cellEl, ["text-align", "border-top", "border-left", "border-right", "border-bottom", "background-color", "color", "font-weight", "font-family", "font-size"]);
  11161. _this60.mapElementStyles(column.component._column.contentElement, cellEl, ["padding-top", "padding-left", "padding-right", "padding-bottom"]);
  11162. if (column.component._column.visible) {
  11163. _this60.mapElementStyles(column.component.getElement(), cellEl, ["width"]);
  11164. } else {
  11165. if (column.component._column.definition.width) {
  11166. cellEl.style.width = column.component._column.definition.width + "px";
  11167. }
  11168. }
  11169. if (column.component._column.parent) {
  11170. _this60.mapElementStyles(column.component._column.parent.groupElement, cellEl, ["border-top"]);
  11171. }
  11172. rowEl.appendChild(cellEl);
  11173. }
  11174. });
  11175. return rowEl;
  11176. };
  11177. Export.prototype.genereateGroupElement = function (row, setup, styles) {
  11178. var rowEl = document.createElement("tr"),
  11179. cellEl = document.createElement("td"),
  11180. group = row.columns[0];
  11181. rowEl.classList.add("tabulator-print-table-row");
  11182. if (setup.groupHeader && setup.groupHeader[row.indent]) {
  11183. group.value = setup.groupHeader[row.indent](group.value, row.component._group.getRowCount(), row.component._group.getData(), row.component);
  11184. } else {
  11185. if (setup.groupHeader === false) {
  11186. group.value = group.value;
  11187. } else {
  11188. group.value = row.component._group.generator(group.value, row.component._group.getRowCount(), row.component._group.getData(), row.component);
  11189. }
  11190. }
  11191. cellEl.colSpan = group.width;
  11192. cellEl.innerHTML = group.value;
  11193. rowEl.classList.add("tabulator-print-table-group");
  11194. rowEl.classList.add("tabulator-group-level-" + row.indent);
  11195. if (group.component.isVisible()) {
  11196. rowEl.classList.add("tabulator-group-visible");
  11197. }
  11198. this.mapElementStyles(styles.firstGroup, rowEl, ["border-top", "border-left", "border-right", "border-bottom", "color", "font-weight", "font-family", "font-size", "background-color"]);
  11199. this.mapElementStyles(styles.firstGroup, cellEl, ["padding-top", "padding-left", "padding-right", "padding-bottom"]);
  11200. rowEl.appendChild(cellEl);
  11201. return rowEl;
  11202. };
  11203. Export.prototype.genereateCalcElement = function (row, setup, styles) {
  11204. var rowEl = this.genereateRowElement(row, setup, styles);
  11205. rowEl.classList.add("tabulator-print-table-calcs");
  11206. this.mapElementStyles(styles.calcRow, rowEl, ["border-top", "border-left", "border-right", "border-bottom", "color", "font-weight", "font-family", "font-size", "background-color"]);
  11207. return rowEl;
  11208. };
  11209. Export.prototype.genereateRowElement = function (row, setup, styles) {
  11210. var _this61 = this;
  11211. var rowEl = document.createElement("tr");
  11212. rowEl.classList.add("tabulator-print-table-row");
  11213. row.columns.forEach(function (col) {
  11214. if (col) {
  11215. var cellEl = document.createElement("td"),
  11216. column = col.component._column,
  11217. value = col.value;
  11218. var cellWrapper = {
  11219. modules: {},
  11220. getValue: function getValue() {
  11221. return value;
  11222. },
  11223. getField: function getField() {
  11224. return column.definition.field;
  11225. },
  11226. getElement: function getElement() {
  11227. return cellEl;
  11228. },
  11229. getColumn: function getColumn() {
  11230. return column.getComponent();
  11231. },
  11232. getData: function getData() {
  11233. return row.component.getData();
  11234. },
  11235. getRow: function getRow() {
  11236. return row.component;
  11237. },
  11238. getComponent: function getComponent() {
  11239. return cellWrapper;
  11240. },
  11241. column: column
  11242. };
  11243. var classNames = column.definition.cssClass ? column.definition.cssClass.split(" ") : [];
  11244. classNames.forEach(function (className) {
  11245. cellEl.classList.add(className);
  11246. });
  11247. if (_this61.table.modExists("format") && _this61.config.formatCells !== false) {
  11248. value = _this61.table.modules.format.formatExportValue(cellWrapper, _this61.colVisProp);
  11249. } else {
  11250. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  11251. case "object":
  11252. value = JSON.stringify(value);
  11253. break;
  11254. case "undefined":
  11255. case "null":
  11256. value = "";
  11257. break;
  11258. default:
  11259. value = value;
  11260. }
  11261. }
  11262. if (value instanceof Node) {
  11263. cellEl.appendChild(value);
  11264. } else {
  11265. cellEl.innerHTML = value;
  11266. }
  11267. if (styles.firstCell) {
  11268. _this61.mapElementStyles(styles.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"]);
  11269. if (column.definition.align) {
  11270. cellEl.style.textAlign = column.definition.align;
  11271. }
  11272. }
  11273. if (_this61.table.options.dataTree && _this61.config.dataTree !== false) {
  11274. if (setup.treeElementField && setup.treeElementField == column.field || !setup.treeElementField && i == 0) {
  11275. if (row.component._row.modules.dataTree.controlEl) {
  11276. cellEl.insertBefore(row.component._row.modules.dataTree.controlEl.cloneNode(true), cellEl.firstChild);
  11277. }
  11278. if (row.component._row.modules.dataTree.branchEl) {
  11279. cellEl.insertBefore(row.component._row.modules.dataTree.branchEl.cloneNode(true), cellEl.firstChild);
  11280. }
  11281. }
  11282. }
  11283. rowEl.appendChild(cellEl);
  11284. if (cellWrapper.modules.format && cellWrapper.modules.format.renderedCallback) {
  11285. cellWrapper.modules.format.renderedCallback();
  11286. }
  11287. if (setup.rowFormatter && _this61.config.formatCells !== false) {
  11288. setup.rowFormatter(row.component);
  11289. }
  11290. }
  11291. });
  11292. return rowEl;
  11293. };
  11294. Export.prototype.genereateHTMLTable = function (list) {
  11295. var holder = document.createElement("div");
  11296. holder.appendChild(this.genereateTableElement(list));
  11297. return holder.innerHTML;
  11298. };
  11299. Export.prototype.getHtml = function (visible, style, config, colVisProp) {
  11300. var list = this.generateExportList(config || this.table.options.htmlOutputConfig, style, visible, colVisProp || "htmlOutput");
  11301. return this.genereateHTMLTable(list);
  11302. };
  11303. Export.prototype.mapElementStyles = function (from, to, props) {
  11304. if (this.cloneTableStyle && from && to) {
  11305. var lookup = {
  11306. "background-color": "backgroundColor",
  11307. "color": "fontColor",
  11308. "width": "width",
  11309. "font-weight": "fontWeight",
  11310. "font-family": "fontFamily",
  11311. "font-size": "fontSize",
  11312. "text-align": "textAlign",
  11313. "border-top": "borderTop",
  11314. "border-left": "borderLeft",
  11315. "border-right": "borderRight",
  11316. "border-bottom": "borderBottom",
  11317. "padding-top": "paddingTop",
  11318. "padding-left": "paddingLeft",
  11319. "padding-right": "paddingRight",
  11320. "padding-bottom": "paddingBottom"
  11321. };
  11322. if (window.getComputedStyle) {
  11323. var fromStyle = window.getComputedStyle(from);
  11324. props.forEach(function (prop) {
  11325. to.style[lookup[prop]] = fromStyle.getPropertyValue(prop);
  11326. });
  11327. }
  11328. }
  11329. };
  11330. Tabulator.prototype.registerModule("export", Export);
  11331. var Filter = function Filter(table) {
  11332. this.table = table; //hold Tabulator object
  11333. this.filterList = []; //hold filter list
  11334. this.headerFilters = {}; //hold column filters
  11335. this.headerFilterColumns = []; //hold columns that use header filters
  11336. this.prevHeaderFilterChangeCheck = "";
  11337. this.prevHeaderFilterChangeCheck = "{}";
  11338. this.changed = false; //has filtering changed since last render
  11339. };
  11340. //initialize column header filter
  11341. Filter.prototype.initializeColumn = function (column, value) {
  11342. var self = this,
  11343. field = column.getField(),
  11344. params;
  11345. //handle successfull value change
  11346. function success(value) {
  11347. var filterType = column.modules.filter.tagType == "input" && column.modules.filter.attrType == "text" || column.modules.filter.tagType == "textarea" ? "partial" : "match",
  11348. type = "",
  11349. filterChangeCheck = "",
  11350. filterFunc;
  11351. if (typeof column.modules.filter.prevSuccess === "undefined" || column.modules.filter.prevSuccess !== value) {
  11352. column.modules.filter.prevSuccess = value;
  11353. if (!column.modules.filter.emptyFunc(value)) {
  11354. column.modules.filter.value = value;
  11355. switch (_typeof(column.definition.headerFilterFunc)) {
  11356. case "string":
  11357. if (self.filters[column.definition.headerFilterFunc]) {
  11358. type = column.definition.headerFilterFunc;
  11359. filterFunc = function filterFunc(data) {
  11360. var params = column.definition.headerFilterFuncParams || {};
  11361. var fieldVal = column.getFieldValue(data);
  11362. params = typeof params === "function" ? params(value, fieldVal, data) : params;
  11363. return self.filters[column.definition.headerFilterFunc](value, fieldVal, data, params);
  11364. };
  11365. } else {
  11366. console.warn("Header Filter Error - Matching filter function not found: ", column.definition.headerFilterFunc);
  11367. }
  11368. break;
  11369. case "function":
  11370. filterFunc = function filterFunc(data) {
  11371. var params = column.definition.headerFilterFuncParams || {};
  11372. var fieldVal = column.getFieldValue(data);
  11373. params = typeof params === "function" ? params(value, fieldVal, data) : params;
  11374. return column.definition.headerFilterFunc(value, fieldVal, data, params);
  11375. };
  11376. type = filterFunc;
  11377. break;
  11378. }
  11379. if (!filterFunc) {
  11380. switch (filterType) {
  11381. case "partial":
  11382. filterFunc = function filterFunc(data) {
  11383. var colVal = column.getFieldValue(data);
  11384. if (typeof colVal !== 'undefined' && colVal !== null) {
  11385. return String(colVal).toLowerCase().indexOf(String(value).toLowerCase()) > -1;
  11386. } else {
  11387. return false;
  11388. }
  11389. };
  11390. type = "like";
  11391. break;
  11392. default:
  11393. filterFunc = function filterFunc(data) {
  11394. return column.getFieldValue(data) == value;
  11395. };
  11396. type = "=";
  11397. }
  11398. }
  11399. self.headerFilters[field] = { value: value, func: filterFunc, type: type, params: params || {} };
  11400. } else {
  11401. delete self.headerFilters[field];
  11402. }
  11403. filterChangeCheck = JSON.stringify(self.headerFilters);
  11404. if (self.prevHeaderFilterChangeCheck !== filterChangeCheck) {
  11405. self.prevHeaderFilterChangeCheck = filterChangeCheck;
  11406. self.changed = true;
  11407. self.table.rowManager.filterRefresh();
  11408. }
  11409. }
  11410. return true;
  11411. }
  11412. column.modules.filter = {
  11413. success: success,
  11414. attrType: false,
  11415. tagType: false,
  11416. emptyFunc: false
  11417. };
  11418. this.generateHeaderFilterElement(column);
  11419. };
  11420. Filter.prototype.generateHeaderFilterElement = function (column, initialValue, reinitialize) {
  11421. var _this62 = this;
  11422. var self = this,
  11423. success = column.modules.filter.success,
  11424. field = column.getField(),
  11425. filterElement,
  11426. editor,
  11427. editorElement,
  11428. cellWrapper,
  11429. typingTimer,
  11430. searchTrigger,
  11431. params;
  11432. //handle aborted edit
  11433. function cancel() {}
  11434. if (column.modules.filter.headerElement && column.modules.filter.headerElement.parentNode) {
  11435. column.contentElement.removeChild(column.modules.filter.headerElement.parentNode);
  11436. }
  11437. if (field) {
  11438. //set empty value function
  11439. column.modules.filter.emptyFunc = column.definition.headerFilterEmptyCheck || function (value) {
  11440. return !value && value !== "0";
  11441. };
  11442. filterElement = document.createElement("div");
  11443. filterElement.classList.add("tabulator-header-filter");
  11444. //set column editor
  11445. switch (_typeof(column.definition.headerFilter)) {
  11446. case "string":
  11447. if (self.table.modules.edit.editors[column.definition.headerFilter]) {
  11448. editor = self.table.modules.edit.editors[column.definition.headerFilter];
  11449. if ((column.definition.headerFilter === "tick" || column.definition.headerFilter === "tickCross") && !column.definition.headerFilterEmptyCheck) {
  11450. column.modules.filter.emptyFunc = function (value) {
  11451. return value !== true && value !== false;
  11452. };
  11453. }
  11454. } else {
  11455. console.warn("Filter Error - Cannot build header filter, No such editor found: ", column.definition.editor);
  11456. }
  11457. break;
  11458. case "function":
  11459. editor = column.definition.headerFilter;
  11460. break;
  11461. case "boolean":
  11462. if (column.modules.edit && column.modules.edit.editor) {
  11463. editor = column.modules.edit.editor;
  11464. } else {
  11465. if (column.definition.formatter && self.table.modules.edit.editors[column.definition.formatter]) {
  11466. editor = self.table.modules.edit.editors[column.definition.formatter];
  11467. if ((column.definition.formatter === "tick" || column.definition.formatter === "tickCross") && !column.definition.headerFilterEmptyCheck) {
  11468. column.modules.filter.emptyFunc = function (value) {
  11469. return value !== true && value !== false;
  11470. };
  11471. }
  11472. } else {
  11473. editor = self.table.modules.edit.editors["input"];
  11474. }
  11475. }
  11476. break;
  11477. }
  11478. if (editor) {
  11479. cellWrapper = {
  11480. getValue: function getValue() {
  11481. return typeof initialValue !== "undefined" ? initialValue : "";
  11482. },
  11483. getField: function getField() {
  11484. return column.definition.field;
  11485. },
  11486. getElement: function getElement() {
  11487. return filterElement;
  11488. },
  11489. getColumn: function getColumn() {
  11490. return column.getComponent();
  11491. },
  11492. getRow: function getRow() {
  11493. return {
  11494. normalizeHeight: function normalizeHeight() {}
  11495. };
  11496. }
  11497. };
  11498. params = column.definition.headerFilterParams || {};
  11499. params = typeof params === "function" ? params.call(self.table) : params;
  11500. editorElement = editor.call(this.table.modules.edit, cellWrapper, function () {}, success, cancel, params);
  11501. if (!editorElement) {
  11502. console.warn("Filter Error - Cannot add filter to " + field + " column, editor returned a value of false");
  11503. return;
  11504. }
  11505. if (!(editorElement instanceof Node)) {
  11506. console.warn("Filter Error - Cannot add filter to " + field + " column, editor should return an instance of Node, the editor returned:", editorElement);
  11507. return;
  11508. }
  11509. //set Placeholder Text
  11510. if (field) {
  11511. self.table.modules.localize.bind("headerFilters|columns|" + column.definition.field, function (value) {
  11512. editorElement.setAttribute("placeholder", typeof value !== "undefined" && value ? value : self.table.modules.localize.getText("headerFilters|default"));
  11513. });
  11514. } else {
  11515. self.table.modules.localize.bind("headerFilters|default", function (value) {
  11516. editorElement.setAttribute("placeholder", typeof self.column.definition.headerFilterPlaceholder !== "undefined" && self.column.definition.headerFilterPlaceholder ? self.column.definition.headerFilterPlaceholder : value);
  11517. });
  11518. }
  11519. //focus on element on click
  11520. editorElement.addEventListener("click", function (e) {
  11521. e.stopPropagation();
  11522. editorElement.focus();
  11523. });
  11524. editorElement.addEventListener("focus", function (e) {
  11525. var left = _this62.table.columnManager.element.scrollLeft;
  11526. if (left !== _this62.table.rowManager.element.scrollLeft) {
  11527. _this62.table.rowManager.scrollHorizontal(left);
  11528. _this62.table.columnManager.scrollHorizontal(left);
  11529. }
  11530. });
  11531. //live update filters as user types
  11532. typingTimer = false;
  11533. searchTrigger = function searchTrigger(e) {
  11534. if (typingTimer) {
  11535. clearTimeout(typingTimer);
  11536. }
  11537. typingTimer = setTimeout(function () {
  11538. success(editorElement.value);
  11539. }, self.table.options.headerFilterLiveFilterDelay);
  11540. };
  11541. column.modules.filter.headerElement = editorElement;
  11542. column.modules.filter.attrType = editorElement.hasAttribute("type") ? editorElement.getAttribute("type").toLowerCase() : "";
  11543. column.modules.filter.tagType = editorElement.tagName.toLowerCase();
  11544. if (column.definition.headerFilterLiveFilter !== false) {
  11545. if (!(column.definition.headerFilter === 'autocomplete' || column.definition.headerFilter === 'tickCross' || (column.definition.editor === 'autocomplete' || column.definition.editor === 'tickCross') && column.definition.headerFilter === true)) {
  11546. editorElement.addEventListener("keyup", searchTrigger);
  11547. editorElement.addEventListener("search", searchTrigger);
  11548. //update number filtered columns on change
  11549. if (column.modules.filter.attrType == "number") {
  11550. editorElement.addEventListener("change", function (e) {
  11551. success(editorElement.value);
  11552. });
  11553. }
  11554. //change text inputs to search inputs to allow for clearing of field
  11555. if (column.modules.filter.attrType == "text" && this.table.browser !== "ie") {
  11556. editorElement.setAttribute("type", "search");
  11557. // editorElement.off("change blur"); //prevent blur from triggering filter and preventing selection click
  11558. }
  11559. }
  11560. //prevent input and select elements from propegating click to column sorters etc
  11561. if (column.modules.filter.tagType == "input" || column.modules.filter.tagType == "select" || column.modules.filter.tagType == "textarea") {
  11562. editorElement.addEventListener("mousedown", function (e) {
  11563. e.stopPropagation();
  11564. });
  11565. }
  11566. }
  11567. filterElement.appendChild(editorElement);
  11568. column.contentElement.appendChild(filterElement);
  11569. if (!reinitialize) {
  11570. self.headerFilterColumns.push(column);
  11571. }
  11572. }
  11573. } else {
  11574. console.warn("Filter Error - Cannot add header filter, column has no field set:", column.definition.title);
  11575. }
  11576. };
  11577. //hide all header filter elements (used to ensure correct column widths in "fitData" layout mode)
  11578. Filter.prototype.hideHeaderFilterElements = function () {
  11579. this.headerFilterColumns.forEach(function (column) {
  11580. if (column.modules.filter && column.modules.filter.headerElement) {
  11581. column.modules.filter.headerElement.style.display = 'none';
  11582. }
  11583. });
  11584. };
  11585. //show all header filter elements (used to ensure correct column widths in "fitData" layout mode)
  11586. Filter.prototype.showHeaderFilterElements = function () {
  11587. this.headerFilterColumns.forEach(function (column) {
  11588. if (column.modules.filter && column.modules.filter.headerElement) {
  11589. column.modules.filter.headerElement.style.display = '';
  11590. }
  11591. });
  11592. };
  11593. //programatically set focus of header filter
  11594. Filter.prototype.setHeaderFilterFocus = function (column) {
  11595. if (column.modules.filter && column.modules.filter.headerElement) {
  11596. column.modules.filter.headerElement.focus();
  11597. } else {
  11598. console.warn("Column Filter Focus Error - No header filter set on column:", column.getField());
  11599. }
  11600. };
  11601. //programmatically get value of header filter
  11602. Filter.prototype.getHeaderFilterValue = function (column) {
  11603. if (column.modules.filter && column.modules.filter.headerElement) {
  11604. return column.modules.filter.headerElement.value;
  11605. } else {
  11606. console.warn("Column Filter Error - No header filter set on column:", column.getField());
  11607. }
  11608. };
  11609. //programatically set value of header filter
  11610. Filter.prototype.setHeaderFilterValue = function (column, value) {
  11611. if (column) {
  11612. if (column.modules.filter && column.modules.filter.headerElement) {
  11613. this.generateHeaderFilterElement(column, value, true);
  11614. column.modules.filter.success(value);
  11615. } else {
  11616. console.warn("Column Filter Error - No header filter set on column:", column.getField());
  11617. }
  11618. }
  11619. };
  11620. Filter.prototype.reloadHeaderFilter = function (column) {
  11621. if (column) {
  11622. if (column.modules.filter && column.modules.filter.headerElement) {
  11623. this.generateHeaderFilterElement(column, column.modules.filter.value, true);
  11624. } else {
  11625. console.warn("Column Filter Error - No header filter set on column:", column.getField());
  11626. }
  11627. }
  11628. };
  11629. //check if the filters has changed since last use
  11630. Filter.prototype.hasChanged = function () {
  11631. var changed = this.changed;
  11632. this.changed = false;
  11633. return changed;
  11634. };
  11635. //set standard filters
  11636. Filter.prototype.setFilter = function (field, type, value, params) {
  11637. var self = this;
  11638. self.filterList = [];
  11639. if (!Array.isArray(field)) {
  11640. field = [{ field: field, type: type, value: value, params: params }];
  11641. }
  11642. self.addFilter(field);
  11643. };
  11644. //add filter to array
  11645. Filter.prototype.addFilter = function (field, type, value, params) {
  11646. var self = this;
  11647. if (!Array.isArray(field)) {
  11648. field = [{ field: field, type: type, value: value, params: params }];
  11649. }
  11650. field.forEach(function (filter) {
  11651. filter = self.findFilter(filter);
  11652. if (filter) {
  11653. self.filterList.push(filter);
  11654. self.changed = true;
  11655. }
  11656. });
  11657. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.filter) {
  11658. this.table.modules.persistence.save("filter");
  11659. }
  11660. };
  11661. Filter.prototype.findFilter = function (filter) {
  11662. var self = this,
  11663. column;
  11664. if (Array.isArray(filter)) {
  11665. return this.findSubFilters(filter);
  11666. }
  11667. var filterFunc = false;
  11668. if (typeof filter.field == "function") {
  11669. filterFunc = function filterFunc(data) {
  11670. return filter.field(data, filter.type || {}); // pass params to custom filter function
  11671. };
  11672. } else {
  11673. if (self.filters[filter.type]) {
  11674. column = self.table.columnManager.getColumnByField(filter.field);
  11675. if (column) {
  11676. filterFunc = function filterFunc(data) {
  11677. return self.filters[filter.type](filter.value, column.getFieldValue(data), data, filter.params || {});
  11678. };
  11679. } else {
  11680. filterFunc = function filterFunc(data) {
  11681. return self.filters[filter.type](filter.value, data[filter.field], data, filter.params || {});
  11682. };
  11683. }
  11684. } else {
  11685. console.warn("Filter Error - No such filter type found, ignoring: ", filter.type);
  11686. }
  11687. }
  11688. filter.func = filterFunc;
  11689. return filter.func ? filter : false;
  11690. };
  11691. Filter.prototype.findSubFilters = function (filters) {
  11692. var self = this,
  11693. output = [];
  11694. filters.forEach(function (filter) {
  11695. filter = self.findFilter(filter);
  11696. if (filter) {
  11697. output.push(filter);
  11698. }
  11699. });
  11700. return output.length ? output : false;
  11701. };
  11702. //get all filters
  11703. Filter.prototype.getFilters = function (all, ajax) {
  11704. var output = [];
  11705. if (all) {
  11706. output = this.getHeaderFilters();
  11707. }
  11708. if (ajax) {
  11709. output.forEach(function (item) {
  11710. if (typeof item.type == "function") {
  11711. item.type = "function";
  11712. }
  11713. });
  11714. }
  11715. output = output.concat(this.filtersToArray(this.filterList, ajax));
  11716. return output;
  11717. };
  11718. //filter to Object
  11719. Filter.prototype.filtersToArray = function (filterList, ajax) {
  11720. var _this63 = this;
  11721. var output = [];
  11722. filterList.forEach(function (filter) {
  11723. var item;
  11724. if (Array.isArray(filter)) {
  11725. output.push(_this63.filtersToArray(filter, ajax));
  11726. } else {
  11727. item = { field: filter.field, type: filter.type, value: filter.value };
  11728. if (ajax) {
  11729. if (typeof item.type == "function") {
  11730. item.type = "function";
  11731. }
  11732. }
  11733. output.push(item);
  11734. }
  11735. });
  11736. return output;
  11737. };
  11738. //get all filters
  11739. Filter.prototype.getHeaderFilters = function () {
  11740. var self = this,
  11741. output = [];
  11742. for (var key in this.headerFilters) {
  11743. output.push({ field: key, type: this.headerFilters[key].type, value: this.headerFilters[key].value });
  11744. }
  11745. return output;
  11746. };
  11747. //remove filter from array
  11748. Filter.prototype.removeFilter = function (field, type, value) {
  11749. var self = this;
  11750. if (!Array.isArray(field)) {
  11751. field = [{ field: field, type: type, value: value }];
  11752. }
  11753. field.forEach(function (filter) {
  11754. var index = -1;
  11755. if (_typeof(filter.field) == "object") {
  11756. index = self.filterList.findIndex(function (element) {
  11757. return filter === element;
  11758. });
  11759. } else {
  11760. index = self.filterList.findIndex(function (element) {
  11761. return filter.field === element.field && filter.type === element.type && filter.value === element.value;
  11762. });
  11763. }
  11764. if (index > -1) {
  11765. self.filterList.splice(index, 1);
  11766. self.changed = true;
  11767. } else {
  11768. console.warn("Filter Error - No matching filter type found, ignoring: ", filter.type);
  11769. }
  11770. });
  11771. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.filter) {
  11772. this.table.modules.persistence.save("filter");
  11773. }
  11774. };
  11775. //clear filters
  11776. Filter.prototype.clearFilter = function (all) {
  11777. this.filterList = [];
  11778. if (all) {
  11779. this.clearHeaderFilter();
  11780. }
  11781. this.changed = true;
  11782. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.filter) {
  11783. this.table.modules.persistence.save("filter");
  11784. }
  11785. };
  11786. //clear header filters
  11787. Filter.prototype.clearHeaderFilter = function () {
  11788. var self = this;
  11789. this.headerFilters = {};
  11790. self.prevHeaderFilterChangeCheck = "{}";
  11791. this.headerFilterColumns.forEach(function (column) {
  11792. column.modules.filter.value = null;
  11793. column.modules.filter.prevSuccess = undefined;
  11794. self.reloadHeaderFilter(column);
  11795. });
  11796. this.changed = true;
  11797. };
  11798. //search data and return matching rows
  11799. Filter.prototype.search = function (searchType, field, type, value) {
  11800. var self = this,
  11801. activeRows = [],
  11802. filterList = [];
  11803. if (!Array.isArray(field)) {
  11804. field = [{ field: field, type: type, value: value }];
  11805. }
  11806. field.forEach(function (filter) {
  11807. filter = self.findFilter(filter);
  11808. if (filter) {
  11809. filterList.push(filter);
  11810. }
  11811. });
  11812. this.table.rowManager.rows.forEach(function (row) {
  11813. var match = true;
  11814. filterList.forEach(function (filter) {
  11815. if (!self.filterRecurse(filter, row.getData())) {
  11816. match = false;
  11817. }
  11818. });
  11819. if (match) {
  11820. activeRows.push(searchType === "data" ? row.getData("data") : row.getComponent());
  11821. }
  11822. });
  11823. return activeRows;
  11824. };
  11825. //filter row array
  11826. Filter.prototype.filter = function (rowList, filters) {
  11827. var self = this,
  11828. activeRows = [],
  11829. activeRowComponents = [];
  11830. if (self.table.options.dataFiltering) {
  11831. self.table.options.dataFiltering.call(self.table, self.getFilters());
  11832. }
  11833. if (!self.table.options.ajaxFiltering && (self.filterList.length || Object.keys(self.headerFilters).length)) {
  11834. rowList.forEach(function (row) {
  11835. if (self.filterRow(row)) {
  11836. activeRows.push(row);
  11837. }
  11838. });
  11839. } else {
  11840. activeRows = rowList.slice(0);
  11841. }
  11842. if (self.table.options.dataFiltered) {
  11843. activeRows.forEach(function (row) {
  11844. activeRowComponents.push(row.getComponent());
  11845. });
  11846. self.table.options.dataFiltered.call(self.table, self.getFilters(), activeRowComponents);
  11847. }
  11848. return activeRows;
  11849. };
  11850. //filter individual row
  11851. Filter.prototype.filterRow = function (row, filters) {
  11852. var self = this,
  11853. match = true,
  11854. data = row.getData();
  11855. self.filterList.forEach(function (filter) {
  11856. if (!self.filterRecurse(filter, data)) {
  11857. match = false;
  11858. }
  11859. });
  11860. for (var field in self.headerFilters) {
  11861. if (!self.headerFilters[field].func(data)) {
  11862. match = false;
  11863. }
  11864. }
  11865. return match;
  11866. };
  11867. Filter.prototype.filterRecurse = function (filter, data) {
  11868. var self = this,
  11869. match = false;
  11870. if (Array.isArray(filter)) {
  11871. filter.forEach(function (subFilter) {
  11872. if (self.filterRecurse(subFilter, data)) {
  11873. match = true;
  11874. }
  11875. });
  11876. } else {
  11877. match = filter.func(data);
  11878. }
  11879. return match;
  11880. };
  11881. //list of available filters
  11882. Filter.prototype.filters = {
  11883. //equal to
  11884. "=": function _(filterVal, rowVal, rowData, filterParams) {
  11885. return rowVal == filterVal ? true : false;
  11886. },
  11887. //less than
  11888. "<": function _(filterVal, rowVal, rowData, filterParams) {
  11889. return rowVal < filterVal ? true : false;
  11890. },
  11891. //less than or equal to
  11892. "<=": function _(filterVal, rowVal, rowData, filterParams) {
  11893. return rowVal <= filterVal ? true : false;
  11894. },
  11895. //greater than
  11896. ">": function _(filterVal, rowVal, rowData, filterParams) {
  11897. return rowVal > filterVal ? true : false;
  11898. },
  11899. //greater than or equal to
  11900. ">=": function _(filterVal, rowVal, rowData, filterParams) {
  11901. return rowVal >= filterVal ? true : false;
  11902. },
  11903. //not equal to
  11904. "!=": function _(filterVal, rowVal, rowData, filterParams) {
  11905. return rowVal != filterVal ? true : false;
  11906. },
  11907. "regex": function regex(filterVal, rowVal, rowData, filterParams) {
  11908. if (typeof filterVal == "string") {
  11909. filterVal = new RegExp(filterVal);
  11910. }
  11911. return filterVal.test(rowVal);
  11912. },
  11913. //contains the string
  11914. "like": function like(filterVal, rowVal, rowData, filterParams) {
  11915. if (filterVal === null || typeof filterVal === "undefined") {
  11916. return rowVal === filterVal ? true : false;
  11917. } else {
  11918. if (typeof rowVal !== 'undefined' && rowVal !== null) {
  11919. return String(rowVal).toLowerCase().indexOf(filterVal.toLowerCase()) > -1;
  11920. } else {
  11921. return false;
  11922. }
  11923. }
  11924. },
  11925. //contains the keywords
  11926. "keywords": function keywords(filterVal, rowVal, rowData, filterParams) {
  11927. var keywords = filterVal.toLowerCase().split(typeof filterParams.separator === "undefined" ? " " : filterParams.separator),
  11928. value = String(rowVal === null || typeof rowVal === "undefined" ? "" : rowVal).toLowerCase(),
  11929. matches = [];
  11930. keywords.forEach(function (keyword) {
  11931. if (value.includes(keyword)) {
  11932. matches.push(true);
  11933. }
  11934. });
  11935. return filterParams.matchAll ? matches.length === keywords.length : !!matches.length;
  11936. },
  11937. //starts with the string
  11938. "starts": function starts(filterVal, rowVal, rowData, filterParams) {
  11939. if (filterVal === null || typeof filterVal === "undefined") {
  11940. return rowVal === filterVal ? true : false;
  11941. } else {
  11942. if (typeof rowVal !== 'undefined' && rowVal !== null) {
  11943. return String(rowVal).toLowerCase().startsWith(filterVal.toLowerCase());
  11944. } else {
  11945. return false;
  11946. }
  11947. }
  11948. },
  11949. //ends with the string
  11950. "ends": function ends(filterVal, rowVal, rowData, filterParams) {
  11951. if (filterVal === null || typeof filterVal === "undefined") {
  11952. return rowVal === filterVal ? true : false;
  11953. } else {
  11954. if (typeof rowVal !== 'undefined' && rowVal !== null) {
  11955. return String(rowVal).toLowerCase().endsWith(filterVal.toLowerCase());
  11956. } else {
  11957. return false;
  11958. }
  11959. }
  11960. },
  11961. //in array
  11962. "in": function _in(filterVal, rowVal, rowData, filterParams) {
  11963. if (Array.isArray(filterVal)) {
  11964. return filterVal.length ? filterVal.indexOf(rowVal) > -1 : true;
  11965. } else {
  11966. console.warn("Filter Error - filter value is not an array:", filterVal);
  11967. return false;
  11968. }
  11969. }
  11970. };
  11971. Tabulator.prototype.registerModule("filter", Filter);
  11972. var Format = function Format(table) {
  11973. this.table = table; //hold Tabulator object
  11974. };
  11975. //initialize column formatter
  11976. Format.prototype.initializeColumn = function (column) {
  11977. column.modules.format = this.lookupFormatter(column, "");
  11978. if (typeof column.definition.formatterPrint !== "undefined") {
  11979. column.modules.format.print = this.lookupFormatter(column, "Print");
  11980. }
  11981. if (typeof column.definition.formatterClipboard !== "undefined") {
  11982. column.modules.format.clipboard = this.lookupFormatter(column, "Clipboard");
  11983. }
  11984. if (typeof column.definition.formatterHtmlOutput !== "undefined") {
  11985. column.modules.format.htmlOutput = this.lookupFormatter(column, "HtmlOutput");
  11986. }
  11987. };
  11988. Format.prototype.lookupFormatter = function (column, type) {
  11989. var config = { params: column.definition["formatter" + type + "Params"] || {} },
  11990. formatter = column.definition["formatter" + type];
  11991. //set column formatter
  11992. switch (typeof formatter === 'undefined' ? 'undefined' : _typeof(formatter)) {
  11993. case "string":
  11994. if (formatter === "tick") {
  11995. formatter = "tickCross";
  11996. if (typeof config.params.crossElement == "undefined") {
  11997. config.params.crossElement = false;
  11998. }
  11999. console.warn("DEPRECATION WARNING - the tick formatter has been deprecated, please use the tickCross formatter with the crossElement param set to false");
  12000. }
  12001. if (this.formatters[formatter]) {
  12002. config.formatter = this.formatters[formatter];
  12003. } else {
  12004. console.warn("Formatter Error - No such formatter found: ", formatter);
  12005. config.formatter = this.formatters.plaintext;
  12006. }
  12007. break;
  12008. case "function":
  12009. config.formatter = formatter;
  12010. break;
  12011. default:
  12012. config.formatter = this.formatters.plaintext;
  12013. break;
  12014. }
  12015. return config;
  12016. };
  12017. Format.prototype.cellRendered = function (cell) {
  12018. if (cell.modules.format && cell.modules.format.renderedCallback && !cell.modules.format.rendered) {
  12019. cell.modules.format.renderedCallback();
  12020. cell.modules.format.rendered = true;
  12021. }
  12022. };
  12023. //return a formatted value for a cell
  12024. Format.prototype.formatValue = function (cell) {
  12025. var component = cell.getComponent(),
  12026. params = typeof cell.column.modules.format.params === "function" ? cell.column.modules.format.params(component) : cell.column.modules.format.params;
  12027. function onRendered(callback) {
  12028. if (!cell.modules.format) {
  12029. cell.modules.format = {};
  12030. }
  12031. cell.modules.format.renderedCallback = callback;
  12032. cell.modules.format.rendered = false;
  12033. }
  12034. return cell.column.modules.format.formatter.call(this, component, params, onRendered);
  12035. };
  12036. Format.prototype.formatExportValue = function (cell, type) {
  12037. var formatter = cell.column.modules.format[type],
  12038. params;
  12039. if (formatter) {
  12040. var onRendered = function onRendered(callback) {
  12041. if (!cell.modules.format) {
  12042. cell.modules.format = {};
  12043. }
  12044. cell.modules.format.renderedCallback = callback;
  12045. cell.modules.format.rendered = false;
  12046. };
  12047. params = typeof formatter.params === "function" ? formatter.params(component) : formatter.params;
  12048. return formatter.formatter.call(this, cell.getComponent(), params, onRendered);
  12049. } else {
  12050. return this.formatValue(cell);
  12051. }
  12052. };
  12053. Format.prototype.sanitizeHTML = function (value) {
  12054. if (value) {
  12055. var entityMap = {
  12056. '&': '&amp;',
  12057. '<': '&lt;',
  12058. '>': '&gt;',
  12059. '"': '&quot;',
  12060. "'": '&#39;',
  12061. '/': '&#x2F;',
  12062. '`': '&#x60;',
  12063. '=': '&#x3D;'
  12064. };
  12065. return String(value).replace(/[&<>"'`=\/]/g, function (s) {
  12066. return entityMap[s];
  12067. });
  12068. } else {
  12069. return value;
  12070. }
  12071. };
  12072. Format.prototype.emptyToSpace = function (value) {
  12073. return value === null || typeof value === "undefined" || value === "" ? "&nbsp;" : value;
  12074. };
  12075. //get formatter for cell
  12076. Format.prototype.getFormatter = function (formatter) {
  12077. var formatter;
  12078. switch (typeof formatter === 'undefined' ? 'undefined' : _typeof(formatter)) {
  12079. case "string":
  12080. if (this.formatters[formatter]) {
  12081. formatter = this.formatters[formatter];
  12082. } else {
  12083. console.warn("Formatter Error - No such formatter found: ", formatter);
  12084. formatter = this.formatters.plaintext;
  12085. }
  12086. break;
  12087. case "function":
  12088. formatter = formatter;
  12089. break;
  12090. default:
  12091. formatter = this.formatters.plaintext;
  12092. break;
  12093. }
  12094. return formatter;
  12095. };
  12096. //default data formatters
  12097. Format.prototype.formatters = {
  12098. //plain text value
  12099. plaintext: function plaintext(cell, formatterParams, onRendered) {
  12100. return this.emptyToSpace(this.sanitizeHTML(cell.getValue()));
  12101. },
  12102. //html text value
  12103. html: function html(cell, formatterParams, onRendered) {
  12104. return cell.getValue();
  12105. },
  12106. //multiline text area
  12107. textarea: function textarea(cell, formatterParams, onRendered) {
  12108. cell.getElement().style.whiteSpace = "pre-wrap";
  12109. return this.emptyToSpace(this.sanitizeHTML(cell.getValue()));
  12110. },
  12111. //currency formatting
  12112. money: function money(cell, formatterParams, onRendered) {
  12113. var floatVal = parseFloat(cell.getValue()),
  12114. number,
  12115. integer,
  12116. decimal,
  12117. rgx;
  12118. var decimalSym = formatterParams.decimal || ".";
  12119. var thousandSym = formatterParams.thousand || ",";
  12120. var symbol = formatterParams.symbol || "";
  12121. var after = !!formatterParams.symbolAfter;
  12122. var precision = typeof formatterParams.precision !== "undefined" ? formatterParams.precision : 2;
  12123. if (isNaN(floatVal)) {
  12124. return this.emptyToSpace(this.sanitizeHTML(cell.getValue()));
  12125. }
  12126. number = precision !== false ? floatVal.toFixed(precision) : floatVal;
  12127. number = String(number).split(".");
  12128. integer = number[0];
  12129. decimal = number.length > 1 ? decimalSym + number[1] : "";
  12130. rgx = /(\d+)(\d{3})/;
  12131. while (rgx.test(integer)) {
  12132. integer = integer.replace(rgx, "$1" + thousandSym + "$2");
  12133. }
  12134. return after ? integer + decimal + symbol : symbol + integer + decimal;
  12135. },
  12136. //clickable anchor tag
  12137. link: function link(cell, formatterParams, onRendered) {
  12138. var value = cell.getValue(),
  12139. urlPrefix = formatterParams.urlPrefix || "",
  12140. download = formatterParams.download,
  12141. label = value,
  12142. el = document.createElement("a"),
  12143. data;
  12144. if (formatterParams.labelField) {
  12145. data = cell.getData();
  12146. label = data[formatterParams.labelField];
  12147. }
  12148. if (formatterParams.label) {
  12149. switch (_typeof(formatterParams.label)) {
  12150. case "string":
  12151. label = formatterParams.label;
  12152. break;
  12153. case "function":
  12154. label = formatterParams.label(cell);
  12155. break;
  12156. }
  12157. }
  12158. if (label) {
  12159. if (formatterParams.urlField) {
  12160. data = cell.getData();
  12161. value = data[formatterParams.urlField];
  12162. }
  12163. if (formatterParams.url) {
  12164. switch (_typeof(formatterParams.url)) {
  12165. case "string":
  12166. value = formatterParams.url;
  12167. break;
  12168. case "function":
  12169. value = formatterParams.url(cell);
  12170. break;
  12171. }
  12172. }
  12173. el.setAttribute("href", urlPrefix + value);
  12174. if (formatterParams.target) {
  12175. el.setAttribute("target", formatterParams.target);
  12176. }
  12177. if (formatterParams.download) {
  12178. if (typeof download == "function") {
  12179. download = download(cell);
  12180. } else {
  12181. download = download === true ? "" : download;
  12182. }
  12183. el.setAttribute("download", download);
  12184. }
  12185. el.innerHTML = this.emptyToSpace(this.sanitizeHTML(label));
  12186. return el;
  12187. } else {
  12188. return "&nbsp;";
  12189. }
  12190. },
  12191. //image element
  12192. image: function image(cell, formatterParams, onRendered) {
  12193. var el = document.createElement("img");
  12194. el.setAttribute("src", cell.getValue());
  12195. switch (_typeof(formatterParams.height)) {
  12196. case "number":
  12197. el.style.height = formatterParams.height + "px";
  12198. break;
  12199. case "string":
  12200. el.style.height = formatterParams.height;
  12201. break;
  12202. }
  12203. switch (_typeof(formatterParams.width)) {
  12204. case "number":
  12205. el.style.width = formatterParams.width + "px";
  12206. break;
  12207. case "string":
  12208. el.style.width = formatterParams.width;
  12209. break;
  12210. }
  12211. el.addEventListener("load", function () {
  12212. cell.getRow().normalizeHeight();
  12213. });
  12214. return el;
  12215. },
  12216. //tick or cross
  12217. tickCross: function tickCross(cell, formatterParams, onRendered) {
  12218. var value = cell.getValue(),
  12219. element = cell.getElement(),
  12220. empty = formatterParams.allowEmpty,
  12221. truthy = formatterParams.allowTruthy,
  12222. 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>',
  12223. 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>';
  12224. if (truthy && value || value === true || value === "true" || value === "True" || value === 1 || value === "1") {
  12225. element.setAttribute("aria-checked", true);
  12226. return tick || "";
  12227. } else {
  12228. if (empty && (value === "null" || value === "" || value === null || typeof value === "undefined")) {
  12229. element.setAttribute("aria-checked", "mixed");
  12230. return "";
  12231. } else {
  12232. element.setAttribute("aria-checked", false);
  12233. return cross || "";
  12234. }
  12235. }
  12236. },
  12237. datetime: function datetime(cell, formatterParams, onRendered) {
  12238. var inputFormat = formatterParams.inputFormat || "YYYY-MM-DD hh:mm:ss";
  12239. var outputFormat = formatterParams.outputFormat || "DD/MM/YYYY hh:mm:ss";
  12240. var invalid = typeof formatterParams.invalidPlaceholder !== "undefined" ? formatterParams.invalidPlaceholder : "";
  12241. var value = cell.getValue();
  12242. var newDatetime = moment(value, inputFormat);
  12243. if (newDatetime.isValid()) {
  12244. return formatterParams.timezone ? newDatetime.tz(formatterParams.timezone).format(outputFormat) : newDatetime.format(outputFormat);
  12245. } else {
  12246. if (invalid === true) {
  12247. return value;
  12248. } else if (typeof invalid === "function") {
  12249. return invalid(value);
  12250. } else {
  12251. return invalid;
  12252. }
  12253. }
  12254. },
  12255. datetimediff: function datetime(cell, formatterParams, onRendered) {
  12256. var inputFormat = formatterParams.inputFormat || "YYYY-MM-DD hh:mm:ss";
  12257. var invalid = typeof formatterParams.invalidPlaceholder !== "undefined" ? formatterParams.invalidPlaceholder : "";
  12258. var suffix = typeof formatterParams.suffix !== "undefined" ? formatterParams.suffix : false;
  12259. var unit = typeof formatterParams.unit !== "undefined" ? formatterParams.unit : undefined;
  12260. var humanize = typeof formatterParams.humanize !== "undefined" ? formatterParams.humanize : false;
  12261. var date = typeof formatterParams.date !== "undefined" ? formatterParams.date : moment();
  12262. var value = cell.getValue();
  12263. var newDatetime = moment(value, inputFormat);
  12264. if (newDatetime.isValid()) {
  12265. if (humanize) {
  12266. return moment.duration(newDatetime.diff(date)).humanize(suffix);
  12267. } else {
  12268. return newDatetime.diff(date, unit) + (suffix ? " " + suffix : "");
  12269. }
  12270. } else {
  12271. if (invalid === true) {
  12272. return value;
  12273. } else if (typeof invalid === "function") {
  12274. return invalid(value);
  12275. } else {
  12276. return invalid;
  12277. }
  12278. }
  12279. },
  12280. //select
  12281. lookup: function lookup(cell, formatterParams, onRendered) {
  12282. var value = cell.getValue();
  12283. if (typeof formatterParams[value] === "undefined") {
  12284. console.warn('Missing display value for ' + value);
  12285. return value;
  12286. }
  12287. return formatterParams[value];
  12288. },
  12289. //star rating
  12290. star: function star(cell, formatterParams, onRendered) {
  12291. var value = cell.getValue(),
  12292. element = cell.getElement(),
  12293. maxStars = formatterParams && formatterParams.stars ? formatterParams.stars : 5,
  12294. stars = document.createElement("span"),
  12295. star = document.createElementNS('http://www.w3.org/2000/svg', "svg"),
  12296. 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 "/>',
  12297. 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 "/>';
  12298. //style stars holder
  12299. stars.style.verticalAlign = "middle";
  12300. //style star
  12301. star.setAttribute("width", "14");
  12302. star.setAttribute("height", "14");
  12303. star.setAttribute("viewBox", "0 0 512 512");
  12304. star.setAttribute("xml:space", "preserve");
  12305. star.style.padding = "0 1px";
  12306. value = value && !isNaN(value) ? parseInt(value) : 0;
  12307. value = Math.max(0, Math.min(value, maxStars));
  12308. for (var i = 1; i <= maxStars; i++) {
  12309. var nextStar = star.cloneNode(true);
  12310. nextStar.innerHTML = i <= value ? starActive : starInactive;
  12311. stars.appendChild(nextStar);
  12312. }
  12313. element.style.whiteSpace = "nowrap";
  12314. element.style.overflow = "hidden";
  12315. element.style.textOverflow = "ellipsis";
  12316. element.setAttribute("aria-label", value);
  12317. return stars;
  12318. },
  12319. traffic: function traffic(cell, formatterParams, onRendered) {
  12320. var value = this.sanitizeHTML(cell.getValue()) || 0,
  12321. el = document.createElement("span"),
  12322. max = formatterParams && formatterParams.max ? formatterParams.max : 100,
  12323. min = formatterParams && formatterParams.min ? formatterParams.min : 0,
  12324. colors = formatterParams && typeof formatterParams.color !== "undefined" ? formatterParams.color : ["red", "orange", "green"],
  12325. color = "#666666",
  12326. percent,
  12327. percentValue;
  12328. if (isNaN(value) || typeof cell.getValue() === "undefined") {
  12329. return;
  12330. }
  12331. el.classList.add("tabulator-traffic-light");
  12332. //make sure value is in range
  12333. percentValue = parseFloat(value) <= max ? parseFloat(value) : max;
  12334. percentValue = parseFloat(percentValue) >= min ? parseFloat(percentValue) : min;
  12335. //workout percentage
  12336. percent = (max - min) / 100;
  12337. percentValue = Math.round((percentValue - min) / percent);
  12338. //set color
  12339. switch (typeof colors === 'undefined' ? 'undefined' : _typeof(colors)) {
  12340. case "string":
  12341. color = colors;
  12342. break;
  12343. case "function":
  12344. color = colors(value);
  12345. break;
  12346. case "object":
  12347. if (Array.isArray(colors)) {
  12348. var unit = 100 / colors.length;
  12349. var index = Math.floor(percentValue / unit);
  12350. index = Math.min(index, colors.length - 1);
  12351. index = Math.max(index, 0);
  12352. color = colors[index];
  12353. break;
  12354. }
  12355. }
  12356. el.style.backgroundColor = color;
  12357. return el;
  12358. },
  12359. //progress bar
  12360. progress: function progress(cell, formatterParams, onRendered) {
  12361. //progress bar
  12362. var value = this.sanitizeHTML(cell.getValue()) || 0,
  12363. element = cell.getElement(),
  12364. max = formatterParams && formatterParams.max ? formatterParams.max : 100,
  12365. min = formatterParams && formatterParams.min ? formatterParams.min : 0,
  12366. legendAlign = formatterParams && formatterParams.legendAlign ? formatterParams.legendAlign : "center",
  12367. percent,
  12368. percentValue,
  12369. color,
  12370. legend,
  12371. legendColor,
  12372. top,
  12373. left,
  12374. right,
  12375. bottom;
  12376. //make sure value is in range
  12377. percentValue = parseFloat(value) <= max ? parseFloat(value) : max;
  12378. percentValue = parseFloat(percentValue) >= min ? parseFloat(percentValue) : min;
  12379. //workout percentage
  12380. percent = (max - min) / 100;
  12381. percentValue = Math.round((percentValue - min) / percent);
  12382. //set bar color
  12383. switch (_typeof(formatterParams.color)) {
  12384. case "string":
  12385. color = formatterParams.color;
  12386. break;
  12387. case "function":
  12388. color = formatterParams.color(value);
  12389. break;
  12390. case "object":
  12391. if (Array.isArray(formatterParams.color)) {
  12392. var unit = 100 / formatterParams.color.length;
  12393. var index = Math.floor(percentValue / unit);
  12394. index = Math.min(index, formatterParams.color.length - 1);
  12395. index = Math.max(index, 0);
  12396. color = formatterParams.color[index];
  12397. break;
  12398. }
  12399. default:
  12400. color = "#2DC214";
  12401. }
  12402. //generate legend
  12403. switch (_typeof(formatterParams.legend)) {
  12404. case "string":
  12405. legend = formatterParams.legend;
  12406. break;
  12407. case "function":
  12408. legend = formatterParams.legend(value);
  12409. break;
  12410. case "boolean":
  12411. legend = value;
  12412. break;
  12413. default:
  12414. legend = false;
  12415. }
  12416. //set legend color
  12417. switch (_typeof(formatterParams.legendColor)) {
  12418. case "string":
  12419. legendColor = formatterParams.legendColor;
  12420. break;
  12421. case "function":
  12422. legendColor = formatterParams.legendColor(value);
  12423. break;
  12424. case "object":
  12425. if (Array.isArray(formatterParams.legendColor)) {
  12426. var unit = 100 / formatterParams.legendColor.length;
  12427. var index = Math.floor(percentValue / unit);
  12428. index = Math.min(index, formatterParams.legendColor.length - 1);
  12429. index = Math.max(index, 0);
  12430. legendColor = formatterParams.legendColor[index];
  12431. }
  12432. break;
  12433. default:
  12434. legendColor = "#000";
  12435. }
  12436. element.style.minWidth = "30px";
  12437. element.style.position = "relative";
  12438. element.setAttribute("aria-label", percentValue);
  12439. var barEl = document.createElement("div");
  12440. barEl.style.display = "inline-block";
  12441. barEl.style.position = "relative";
  12442. barEl.style.width = percentValue + "%";
  12443. barEl.style.backgroundColor = color;
  12444. barEl.style.height = "100%";
  12445. barEl.setAttribute('data-max', max);
  12446. barEl.setAttribute('data-min', min);
  12447. if (legend) {
  12448. var legendEl = document.createElement("div");
  12449. legendEl.style.position = "absolute";
  12450. legendEl.style.top = "4px";
  12451. legendEl.style.left = 0;
  12452. legendEl.style.textAlign = legendAlign;
  12453. legendEl.style.width = "100%";
  12454. legendEl.style.color = legendColor;
  12455. legendEl.innerHTML = legend;
  12456. }
  12457. onRendered(function () {
  12458. //handle custom element needed if formatter is to be included in printed/downloaded output
  12459. if (!(cell instanceof CellComponent)) {
  12460. var holderEl = document.createElement("div");
  12461. holderEl.style.position = "absolute";
  12462. holderEl.style.top = "4px";
  12463. holderEl.style.bottom = "4px";
  12464. holderEl.style.left = "4px";
  12465. holderEl.style.right = "4px";
  12466. element.appendChild(holderEl);
  12467. element = holderEl;
  12468. }
  12469. element.appendChild(barEl);
  12470. if (legend) {
  12471. element.appendChild(legendEl);
  12472. }
  12473. });
  12474. return "";
  12475. },
  12476. //background color
  12477. color: function color(cell, formatterParams, onRendered) {
  12478. cell.getElement().style.backgroundColor = this.sanitizeHTML(cell.getValue());
  12479. return "";
  12480. },
  12481. //tick icon
  12482. buttonTick: function buttonTick(cell, formatterParams, onRendered) {
  12483. 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>';
  12484. },
  12485. //cross icon
  12486. buttonCross: function buttonCross(cell, formatterParams, onRendered) {
  12487. 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>';
  12488. },
  12489. //current row number
  12490. rownum: function rownum(cell, formatterParams, onRendered) {
  12491. return this.table.rowManager.activeRows.indexOf(cell.getRow()._getSelf()) + 1;
  12492. },
  12493. //row handle
  12494. handle: function handle(cell, formatterParams, onRendered) {
  12495. cell.getElement().classList.add("tabulator-row-handle");
  12496. 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>";
  12497. },
  12498. responsiveCollapse: function responsiveCollapse(cell, formatterParams, onRendered) {
  12499. var self = this,
  12500. open = false,
  12501. el = document.createElement("div"),
  12502. config = cell.getRow()._row.modules.responsiveLayout;
  12503. el.classList.add("tabulator-responsive-collapse-toggle");
  12504. el.innerHTML = "<span class='tabulator-responsive-collapse-toggle-open'>+</span><span class='tabulator-responsive-collapse-toggle-close'>-</span>";
  12505. cell.getElement().classList.add("tabulator-row-handle");
  12506. function toggleList(isOpen) {
  12507. var collapseEl = config.element;
  12508. config.open = isOpen;
  12509. if (collapseEl) {
  12510. if (config.open) {
  12511. el.classList.add("open");
  12512. collapseEl.style.display = '';
  12513. } else {
  12514. el.classList.remove("open");
  12515. collapseEl.style.display = 'none';
  12516. }
  12517. }
  12518. }
  12519. el.addEventListener("click", function (e) {
  12520. e.stopImmediatePropagation();
  12521. toggleList(!config.open);
  12522. });
  12523. toggleList(config.open);
  12524. return el;
  12525. },
  12526. rowSelection: function rowSelection(cell, formatterParams, onRendered) {
  12527. var _this64 = this;
  12528. var checkbox = document.createElement("input");
  12529. checkbox.type = 'checkbox';
  12530. if (this.table.modExists("selectRow", true)) {
  12531. checkbox.addEventListener("click", function (e) {
  12532. e.stopPropagation();
  12533. });
  12534. if (typeof cell.getRow == 'function') {
  12535. var row = cell.getRow();
  12536. if (row instanceof RowComponent) {
  12537. checkbox.addEventListener("change", function (e) {
  12538. row.toggleSelect();
  12539. });
  12540. checkbox.checked = row.isSelected && row.isSelected();
  12541. this.table.modules.selectRow.registerRowSelectCheckbox(row, checkbox);
  12542. } else {
  12543. checkbox = "";
  12544. }
  12545. } else {
  12546. checkbox.addEventListener("change", function (e) {
  12547. if (_this64.table.modules.selectRow.selectedRows.length) {
  12548. _this64.table.deselectRow();
  12549. } else {
  12550. _this64.table.selectRow(formatterParams.rowRange);
  12551. }
  12552. });
  12553. this.table.modules.selectRow.registerHeaderSelectCheckbox(checkbox);
  12554. }
  12555. }
  12556. return checkbox;
  12557. }
  12558. };
  12559. Tabulator.prototype.registerModule("format", Format);
  12560. var FrozenColumns = function FrozenColumns(table) {
  12561. this.table = table; //hold Tabulator object
  12562. this.leftColumns = [];
  12563. this.rightColumns = [];
  12564. this.leftMargin = 0;
  12565. this.rightMargin = 0;
  12566. this.rightPadding = 0;
  12567. this.initializationMode = "left";
  12568. this.active = false;
  12569. this.scrollEndTimer = false;
  12570. };
  12571. //reset initial state
  12572. FrozenColumns.prototype.reset = function () {
  12573. this.initializationMode = "left";
  12574. this.leftColumns = [];
  12575. this.rightColumns = [];
  12576. this.leftMargin = 0;
  12577. this.rightMargin = 0;
  12578. this.rightMargin = 0;
  12579. this.active = false;
  12580. this.table.columnManager.headersElement.style.marginLeft = 0;
  12581. this.table.columnManager.element.style.paddingRight = 0;
  12582. };
  12583. //initialize specific column
  12584. FrozenColumns.prototype.initializeColumn = function (column) {
  12585. var config = { margin: 0, edge: false };
  12586. if (!column.isGroup) {
  12587. if (this.frozenCheck(column)) {
  12588. config.position = this.initializationMode;
  12589. if (this.initializationMode == "left") {
  12590. this.leftColumns.push(column);
  12591. } else {
  12592. this.rightColumns.unshift(column);
  12593. }
  12594. this.active = true;
  12595. column.modules.frozen = config;
  12596. } else {
  12597. this.initializationMode = "right";
  12598. }
  12599. }
  12600. };
  12601. FrozenColumns.prototype.frozenCheck = function (column) {
  12602. var frozen = false;
  12603. if (column.parent.isGroup && column.definition.frozen) {
  12604. console.warn("Frozen Column Error - Parent column group must be frozen, not individual columns or sub column groups");
  12605. }
  12606. if (column.parent.isGroup) {
  12607. return this.frozenCheck(column.parent);
  12608. } else {
  12609. return column.definition.frozen;
  12610. }
  12611. return frozen;
  12612. };
  12613. //quick layout to smooth horizontal scrolling
  12614. FrozenColumns.prototype.scrollHorizontal = function () {
  12615. var _this65 = this;
  12616. var rows;
  12617. if (this.active) {
  12618. clearTimeout(this.scrollEndTimer);
  12619. //layout all rows after scroll is complete
  12620. this.scrollEndTimer = setTimeout(function () {
  12621. _this65.layout();
  12622. }, 100);
  12623. rows = this.table.rowManager.getVisibleRows();
  12624. this.calcMargins();
  12625. this.layoutColumnPosition();
  12626. this.layoutCalcRows();
  12627. rows.forEach(function (row) {
  12628. if (row.type === "row") {
  12629. _this65.layoutRow(row);
  12630. }
  12631. });
  12632. this.table.rowManager.tableElement.style.marginRight = this.rightMargin;
  12633. }
  12634. };
  12635. //calculate margins for rows
  12636. FrozenColumns.prototype.calcMargins = function () {
  12637. this.leftMargin = this._calcSpace(this.leftColumns, this.leftColumns.length) + "px";
  12638. this.table.columnManager.headersElement.style.marginLeft = this.leftMargin;
  12639. this.rightMargin = this._calcSpace(this.rightColumns, this.rightColumns.length) + "px";
  12640. this.table.columnManager.element.style.paddingRight = this.rightMargin;
  12641. //calculate right frozen columns
  12642. this.rightPadding = this.table.rowManager.element.clientWidth + this.table.columnManager.scrollLeft;
  12643. };
  12644. //layout calculation rows
  12645. FrozenColumns.prototype.layoutCalcRows = function () {
  12646. if (this.table.modExists("columnCalcs")) {
  12647. if (this.table.modules.columnCalcs.topInitialized && this.table.modules.columnCalcs.topRow) {
  12648. this.layoutRow(this.table.modules.columnCalcs.topRow);
  12649. }
  12650. if (this.table.modules.columnCalcs.botInitialized && this.table.modules.columnCalcs.botRow) {
  12651. this.layoutRow(this.table.modules.columnCalcs.botRow);
  12652. }
  12653. }
  12654. };
  12655. //calculate column positions and layout headers
  12656. FrozenColumns.prototype.layoutColumnPosition = function (allCells) {
  12657. var _this66 = this;
  12658. var leftParents = [];
  12659. this.leftColumns.forEach(function (column, i) {
  12660. column.modules.frozen.margin = _this66._calcSpace(_this66.leftColumns, i) + _this66.table.columnManager.scrollLeft + "px";
  12661. if (i == _this66.leftColumns.length - 1) {
  12662. column.modules.frozen.edge = true;
  12663. } else {
  12664. column.modules.frozen.edge = false;
  12665. }
  12666. if (column.parent.isGroup) {
  12667. var parentEl = _this66.getColGroupParentElement(column);
  12668. if (!leftParents.includes(parentEl)) {
  12669. _this66.layoutElement(parentEl, column);
  12670. leftParents.push(parentEl);
  12671. }
  12672. if (column.modules.frozen.edge) {
  12673. parentEl.classList.add("tabulator-frozen-" + column.modules.frozen.position);
  12674. }
  12675. } else {
  12676. _this66.layoutElement(column.getElement(), column);
  12677. }
  12678. if (allCells) {
  12679. column.cells.forEach(function (cell) {
  12680. _this66.layoutElement(cell.getElement(), column);
  12681. });
  12682. }
  12683. });
  12684. this.rightColumns.forEach(function (column, i) {
  12685. column.modules.frozen.margin = _this66.rightPadding - _this66._calcSpace(_this66.rightColumns, i + 1) + "px";
  12686. if (i == _this66.rightColumns.length - 1) {
  12687. column.modules.frozen.edge = true;
  12688. } else {
  12689. column.modules.frozen.edge = false;
  12690. }
  12691. if (column.parent.isGroup) {
  12692. _this66.layoutElement(_this66.getColGroupParentElement(column), column);
  12693. } else {
  12694. _this66.layoutElement(column.getElement(), column);
  12695. }
  12696. if (allCells) {
  12697. column.cells.forEach(function (cell) {
  12698. _this66.layoutElement(cell.getElement(), column);
  12699. });
  12700. }
  12701. });
  12702. };
  12703. FrozenColumns.prototype.getColGroupParentElement = function (column) {
  12704. return column.parent.isGroup ? this.getColGroupParentElement(column.parent) : column.getElement();
  12705. };
  12706. //layout columns appropropriatly
  12707. FrozenColumns.prototype.layout = function () {
  12708. var self = this,
  12709. rightMargin = 0;
  12710. if (self.active) {
  12711. //calculate row padding
  12712. this.calcMargins();
  12713. // self.table.rowManager.activeRows.forEach(function(row){
  12714. // self.layoutRow(row);
  12715. // });
  12716. // if(self.table.options.dataTree){
  12717. self.table.rowManager.getDisplayRows().forEach(function (row) {
  12718. if (row.type === "row") {
  12719. self.layoutRow(row);
  12720. }
  12721. });
  12722. // }
  12723. this.layoutCalcRows();
  12724. //calculate left columns
  12725. this.layoutColumnPosition(true);
  12726. // if(tableHolder.scrollHeight > tableHolder.clientHeight){
  12727. // rightMargin -= tableHolder.offsetWidth - tableHolder.clientWidth;
  12728. // }
  12729. this.table.rowManager.tableElement.style.marginRight = this.rightMargin;
  12730. }
  12731. };
  12732. FrozenColumns.prototype.layoutRow = function (row) {
  12733. var _this67 = this;
  12734. var rowEl = row.getElement();
  12735. rowEl.style.paddingLeft = this.leftMargin;
  12736. // rowEl.style.paddingRight = this.rightMargin + "px";
  12737. this.leftColumns.forEach(function (column) {
  12738. var cell = row.getCell(column);
  12739. if (cell) {
  12740. _this67.layoutElement(cell.getElement(), column);
  12741. }
  12742. });
  12743. this.rightColumns.forEach(function (column) {
  12744. var cell = row.getCell(column);
  12745. if (cell) {
  12746. _this67.layoutElement(cell.getElement(), column);
  12747. }
  12748. });
  12749. };
  12750. FrozenColumns.prototype.layoutElement = function (element, column) {
  12751. if (column.modules.frozen) {
  12752. element.style.position = "absolute";
  12753. element.style.left = column.modules.frozen.margin;
  12754. element.classList.add("tabulator-frozen");
  12755. if (column.modules.frozen.edge) {
  12756. element.classList.add("tabulator-frozen-" + column.modules.frozen.position);
  12757. }
  12758. }
  12759. };
  12760. FrozenColumns.prototype._calcSpace = function (columns, index) {
  12761. var width = 0;
  12762. for (var _i12 = 0; _i12 < index; _i12++) {
  12763. if (columns[_i12].visible) {
  12764. width += columns[_i12].getWidth();
  12765. }
  12766. }
  12767. return width;
  12768. };
  12769. Tabulator.prototype.registerModule("frozenColumns", FrozenColumns);
  12770. var FrozenRows = function FrozenRows(table) {
  12771. this.table = table; //hold Tabulator object
  12772. this.topElement = document.createElement("div");
  12773. this.rows = [];
  12774. this.displayIndex = 0; //index in display pipeline
  12775. };
  12776. FrozenRows.prototype.initialize = function () {
  12777. this.rows = [];
  12778. this.topElement.classList.add("tabulator-frozen-rows-holder");
  12779. // this.table.columnManager.element.append(this.topElement);
  12780. this.table.columnManager.getElement().insertBefore(this.topElement, this.table.columnManager.headersElement.nextSibling);
  12781. };
  12782. FrozenRows.prototype.setDisplayIndex = function (index) {
  12783. this.displayIndex = index;
  12784. };
  12785. FrozenRows.prototype.getDisplayIndex = function () {
  12786. return this.displayIndex;
  12787. };
  12788. FrozenRows.prototype.isFrozen = function () {
  12789. return !!this.rows.length;
  12790. };
  12791. //filter frozen rows out of display data
  12792. FrozenRows.prototype.getRows = function (rows) {
  12793. var self = this,
  12794. frozen = [],
  12795. output = rows.slice(0);
  12796. this.rows.forEach(function (row) {
  12797. var index = output.indexOf(row);
  12798. if (index > -1) {
  12799. output.splice(index, 1);
  12800. }
  12801. });
  12802. return output;
  12803. };
  12804. FrozenRows.prototype.freezeRow = function (row) {
  12805. if (!row.modules.frozen) {
  12806. row.modules.frozen = true;
  12807. this.topElement.appendChild(row.getElement());
  12808. row.initialize();
  12809. row.normalizeHeight();
  12810. this.table.rowManager.adjustTableSize();
  12811. this.rows.push(row);
  12812. this.table.rowManager.refreshActiveData("display");
  12813. this.styleRows();
  12814. } else {
  12815. console.warn("Freeze Error - Row is already frozen");
  12816. }
  12817. };
  12818. FrozenRows.prototype.unfreezeRow = function (row) {
  12819. var index = this.rows.indexOf(row);
  12820. if (row.modules.frozen) {
  12821. row.modules.frozen = false;
  12822. this.detachRow(row);
  12823. this.table.rowManager.adjustTableSize();
  12824. this.table.rowManager.refreshActiveData("display");
  12825. if (this.rows.length) {
  12826. this.styleRows();
  12827. }
  12828. } else {
  12829. console.warn("Freeze Error - Row is already unfrozen");
  12830. }
  12831. };
  12832. FrozenRows.prototype.detachRow = function (row) {
  12833. var index = this.rows.indexOf(row);
  12834. if (index > -1) {
  12835. var rowEl = row.getElement();
  12836. rowEl.parentNode.removeChild(rowEl);
  12837. this.rows.splice(index, 1);
  12838. }
  12839. };
  12840. FrozenRows.prototype.styleRows = function (row) {
  12841. var self = this;
  12842. this.rows.forEach(function (row, i) {
  12843. self.table.rowManager.styleRow(row, i);
  12844. });
  12845. };
  12846. Tabulator.prototype.registerModule("frozenRows", FrozenRows);
  12847. //public group object
  12848. var GroupComponent = function GroupComponent(group) {
  12849. this._group = group;
  12850. this.type = "GroupComponent";
  12851. };
  12852. GroupComponent.prototype.getKey = function () {
  12853. return this._group.key;
  12854. };
  12855. GroupComponent.prototype.getField = function () {
  12856. return this._group.field;
  12857. };
  12858. GroupComponent.prototype.getElement = function () {
  12859. return this._group.element;
  12860. };
  12861. GroupComponent.prototype.getRows = function () {
  12862. return this._group.getRows(true);
  12863. };
  12864. GroupComponent.prototype.getSubGroups = function () {
  12865. return this._group.getSubGroups(true);
  12866. };
  12867. GroupComponent.prototype.getParentGroup = function () {
  12868. return this._group.parent ? this._group.parent.getComponent() : false;
  12869. };
  12870. GroupComponent.prototype.getVisibility = function () {
  12871. console.warn("getVisibility function is deprecated, you should now use the isVisible function");
  12872. return this._group.visible;
  12873. };
  12874. GroupComponent.prototype.isVisible = function () {
  12875. return this._group.visible;
  12876. };
  12877. GroupComponent.prototype.show = function () {
  12878. this._group.show();
  12879. };
  12880. GroupComponent.prototype.hide = function () {
  12881. this._group.hide();
  12882. };
  12883. GroupComponent.prototype.toggle = function () {
  12884. this._group.toggleVisibility();
  12885. };
  12886. GroupComponent.prototype._getSelf = function () {
  12887. return this._group;
  12888. };
  12889. GroupComponent.prototype.getTable = function () {
  12890. return this._group.groupManager.table;
  12891. };
  12892. //////////////////////////////////////////////////
  12893. //////////////// Group Functions /////////////////
  12894. //////////////////////////////////////////////////
  12895. var Group = function Group(groupManager, parent, level, key, field, generator, oldGroup) {
  12896. this.groupManager = groupManager;
  12897. this.parent = parent;
  12898. this.key = key;
  12899. this.level = level;
  12900. this.field = field;
  12901. this.hasSubGroups = level < groupManager.groupIDLookups.length - 1;
  12902. this.addRow = this.hasSubGroups ? this._addRowToGroup : this._addRow;
  12903. this.type = "group"; //type of element
  12904. this.old = oldGroup;
  12905. this.rows = [];
  12906. this.groups = [];
  12907. this.groupList = [];
  12908. this.generator = generator;
  12909. this.elementContents = false;
  12910. this.height = 0;
  12911. this.outerHeight = 0;
  12912. this.initialized = false;
  12913. this.calcs = {};
  12914. this.initialized = false;
  12915. this.modules = {};
  12916. this.arrowElement = false;
  12917. this.visible = oldGroup ? oldGroup.visible : typeof groupManager.startOpen[level] !== "undefined" ? groupManager.startOpen[level] : groupManager.startOpen[0];
  12918. this.component = null;
  12919. this.createElements();
  12920. this.addBindings();
  12921. this.createValueGroups();
  12922. };
  12923. Group.prototype.wipe = function () {
  12924. if (this.groupList.length) {
  12925. this.groupList.forEach(function (group) {
  12926. group.wipe();
  12927. });
  12928. } else {
  12929. this.element = false;
  12930. this.arrowElement = false;
  12931. this.elementContents = false;
  12932. }
  12933. };
  12934. Group.prototype.createElements = function () {
  12935. var arrow = document.createElement("div");
  12936. arrow.classList.add("tabulator-arrow");
  12937. this.element = document.createElement("div");
  12938. this.element.classList.add("tabulator-row");
  12939. this.element.classList.add("tabulator-group");
  12940. this.element.classList.add("tabulator-group-level-" + this.level);
  12941. this.element.setAttribute("role", "rowgroup");
  12942. this.arrowElement = document.createElement("div");
  12943. this.arrowElement.classList.add("tabulator-group-toggle");
  12944. this.arrowElement.appendChild(arrow);
  12945. //setup movable rows
  12946. if (this.groupManager.table.options.movableRows !== false && this.groupManager.table.modExists("moveRow")) {
  12947. this.groupManager.table.modules.moveRow.initializeGroupHeader(this);
  12948. }
  12949. };
  12950. Group.prototype.createValueGroups = function () {
  12951. var _this68 = this;
  12952. var level = this.level + 1;
  12953. if (this.groupManager.allowedValues && this.groupManager.allowedValues[level]) {
  12954. this.groupManager.allowedValues[level].forEach(function (value) {
  12955. _this68._createGroup(value, level);
  12956. });
  12957. }
  12958. };
  12959. Group.prototype.addBindings = function () {
  12960. var self = this,
  12961. dblTap,
  12962. tapHold,
  12963. tap,
  12964. toggleElement;
  12965. //handle group click events
  12966. if (self.groupManager.table.options.groupClick) {
  12967. self.element.addEventListener("click", function (e) {
  12968. self.groupManager.table.options.groupClick.call(self.groupManager.table, e, self.getComponent());
  12969. });
  12970. }
  12971. if (self.groupManager.table.options.groupDblClick) {
  12972. self.element.addEventListener("dblclick", function (e) {
  12973. self.groupManager.table.options.groupDblClick.call(self.groupManager.table, e, self.getComponent());
  12974. });
  12975. }
  12976. if (self.groupManager.table.options.groupContext) {
  12977. self.element.addEventListener("contextmenu", function (e) {
  12978. self.groupManager.table.options.groupContext.call(self.groupManager.table, e, self.getComponent());
  12979. });
  12980. }
  12981. if ((self.groupManager.table.options.groupContextMenu || self.groupManager.table.options.groupClickMenu) && self.groupManager.table.modExists("menu")) {
  12982. self.groupManager.table.modules.menu.initializeGroup.call(self.groupManager.table.modules.menu, self);
  12983. }
  12984. if (self.groupManager.table.options.groupTap) {
  12985. tap = false;
  12986. self.element.addEventListener("touchstart", function (e) {
  12987. tap = true;
  12988. }, { passive: true });
  12989. self.element.addEventListener("touchend", function (e) {
  12990. if (tap) {
  12991. self.groupManager.table.options.groupTap(e, self.getComponent());
  12992. }
  12993. tap = false;
  12994. });
  12995. }
  12996. if (self.groupManager.table.options.groupDblTap) {
  12997. dblTap = null;
  12998. self.element.addEventListener("touchend", function (e) {
  12999. if (dblTap) {
  13000. clearTimeout(dblTap);
  13001. dblTap = null;
  13002. self.groupManager.table.options.groupDblTap(e, self.getComponent());
  13003. } else {
  13004. dblTap = setTimeout(function () {
  13005. clearTimeout(dblTap);
  13006. dblTap = null;
  13007. }, 300);
  13008. }
  13009. });
  13010. }
  13011. if (self.groupManager.table.options.groupTapHold) {
  13012. tapHold = null;
  13013. self.element.addEventListener("touchstart", function (e) {
  13014. clearTimeout(tapHold);
  13015. tapHold = setTimeout(function () {
  13016. clearTimeout(tapHold);
  13017. tapHold = null;
  13018. tap = false;
  13019. self.groupManager.table.options.groupTapHold(e, self.getComponent());
  13020. }, 1000);
  13021. }, { passive: true });
  13022. self.element.addEventListener("touchend", function (e) {
  13023. clearTimeout(tapHold);
  13024. tapHold = null;
  13025. });
  13026. }
  13027. if (self.groupManager.table.options.groupToggleElement) {
  13028. toggleElement = self.groupManager.table.options.groupToggleElement == "arrow" ? self.arrowElement : self.element;
  13029. toggleElement.addEventListener("click", function (e) {
  13030. e.stopPropagation();
  13031. e.stopImmediatePropagation();
  13032. self.toggleVisibility();
  13033. });
  13034. }
  13035. };
  13036. Group.prototype._createGroup = function (groupID, level) {
  13037. var groupKey = level + "_" + groupID;
  13038. 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);
  13039. this.groups[groupKey] = group;
  13040. this.groupList.push(group);
  13041. };
  13042. Group.prototype._addRowToGroup = function (row) {
  13043. var level = this.level + 1;
  13044. if (this.hasSubGroups) {
  13045. var groupID = this.groupManager.groupIDLookups[level].func(row.getData()),
  13046. groupKey = level + "_" + groupID;
  13047. if (this.groupManager.allowedValues && this.groupManager.allowedValues[level]) {
  13048. if (this.groups[groupKey]) {
  13049. this.groups[groupKey].addRow(row);
  13050. }
  13051. } else {
  13052. if (!this.groups[groupKey]) {
  13053. this._createGroup(groupID, level);
  13054. }
  13055. this.groups[groupKey].addRow(row);
  13056. }
  13057. }
  13058. };
  13059. Group.prototype._addRow = function (row) {
  13060. this.rows.push(row);
  13061. row.modules.group = this;
  13062. };
  13063. Group.prototype.insertRow = function (row, to, after) {
  13064. var data = this.conformRowData({});
  13065. row.updateData(data);
  13066. var toIndex = this.rows.indexOf(to);
  13067. if (toIndex > -1) {
  13068. if (after) {
  13069. this.rows.splice(toIndex + 1, 0, row);
  13070. } else {
  13071. this.rows.splice(toIndex, 0, row);
  13072. }
  13073. } else {
  13074. if (after) {
  13075. this.rows.push(row);
  13076. } else {
  13077. this.rows.unshift(row);
  13078. }
  13079. }
  13080. row.modules.group = this;
  13081. this.generateGroupHeaderContents();
  13082. if (this.groupManager.table.modExists("columnCalcs") && this.groupManager.table.options.columnCalcs != "table") {
  13083. this.groupManager.table.modules.columnCalcs.recalcGroup(this);
  13084. }
  13085. this.groupManager.updateGroupRows(true);
  13086. };
  13087. Group.prototype.scrollHeader = function (left) {
  13088. this.arrowElement.style.marginLeft = left;
  13089. this.groupList.forEach(function (child) {
  13090. child.scrollHeader(left);
  13091. });
  13092. };
  13093. Group.prototype.getRowIndex = function (row) {};
  13094. //update row data to match grouping contraints
  13095. Group.prototype.conformRowData = function (data) {
  13096. if (this.field) {
  13097. data[this.field] = this.key;
  13098. } else {
  13099. console.warn("Data Conforming Error - Cannot conform row data to match new group as groupBy is a function");
  13100. }
  13101. if (this.parent) {
  13102. data = this.parent.conformRowData(data);
  13103. }
  13104. return data;
  13105. };
  13106. Group.prototype.removeRow = function (row) {
  13107. var index = this.rows.indexOf(row);
  13108. var el = row.getElement();
  13109. if (index > -1) {
  13110. this.rows.splice(index, 1);
  13111. }
  13112. if (!this.groupManager.table.options.groupValues && !this.rows.length) {
  13113. if (this.parent) {
  13114. this.parent.removeGroup(this);
  13115. } else {
  13116. this.groupManager.removeGroup(this);
  13117. }
  13118. this.groupManager.updateGroupRows(true);
  13119. } else {
  13120. if (el.parentNode) {
  13121. el.parentNode.removeChild(el);
  13122. }
  13123. this.generateGroupHeaderContents();
  13124. if (this.groupManager.table.modExists("columnCalcs") && this.groupManager.table.options.columnCalcs != "table") {
  13125. this.groupManager.table.modules.columnCalcs.recalcGroup(this);
  13126. }
  13127. }
  13128. };
  13129. Group.prototype.removeGroup = function (group) {
  13130. var groupKey = group.level + "_" + group.key,
  13131. index;
  13132. if (this.groups[groupKey]) {
  13133. delete this.groups[groupKey];
  13134. index = this.groupList.indexOf(group);
  13135. if (index > -1) {
  13136. this.groupList.splice(index, 1);
  13137. }
  13138. if (!this.groupList.length) {
  13139. if (this.parent) {
  13140. this.parent.removeGroup(this);
  13141. } else {
  13142. this.groupManager.removeGroup(this);
  13143. }
  13144. }
  13145. }
  13146. };
  13147. Group.prototype.getHeadersAndRows = function (noCalc) {
  13148. var output = [];
  13149. output.push(this);
  13150. this._visSet();
  13151. if (this.visible) {
  13152. if (this.groupList.length) {
  13153. this.groupList.forEach(function (group) {
  13154. output = output.concat(group.getHeadersAndRows(noCalc));
  13155. });
  13156. } else {
  13157. if (!noCalc && this.groupManager.table.options.columnCalcs != "table" && this.groupManager.table.modExists("columnCalcs") && this.groupManager.table.modules.columnCalcs.hasTopCalcs()) {
  13158. if (this.calcs.top) {
  13159. this.calcs.top.detachElement();
  13160. this.calcs.top.deleteCells();
  13161. }
  13162. this.calcs.top = this.groupManager.table.modules.columnCalcs.generateTopRow(this.rows);
  13163. output.push(this.calcs.top);
  13164. }
  13165. output = output.concat(this.rows);
  13166. if (!noCalc && this.groupManager.table.options.columnCalcs != "table" && this.groupManager.table.modExists("columnCalcs") && this.groupManager.table.modules.columnCalcs.hasBottomCalcs()) {
  13167. if (this.calcs.bottom) {
  13168. this.calcs.bottom.detachElement();
  13169. this.calcs.bottom.deleteCells();
  13170. }
  13171. this.calcs.bottom = this.groupManager.table.modules.columnCalcs.generateBottomRow(this.rows);
  13172. output.push(this.calcs.bottom);
  13173. }
  13174. }
  13175. } else {
  13176. if (!this.groupList.length && this.groupManager.table.options.columnCalcs != "table") {
  13177. if (this.groupManager.table.modExists("columnCalcs")) {
  13178. if (!noCalc && this.groupManager.table.modules.columnCalcs.hasTopCalcs()) {
  13179. if (this.calcs.top) {
  13180. this.calcs.top.detachElement();
  13181. this.calcs.top.deleteCells();
  13182. }
  13183. if (this.groupManager.table.options.groupClosedShowCalcs) {
  13184. this.calcs.top = this.groupManager.table.modules.columnCalcs.generateTopRow(this.rows);
  13185. output.push(this.calcs.top);
  13186. }
  13187. }
  13188. if (!noCalc && this.groupManager.table.modules.columnCalcs.hasBottomCalcs()) {
  13189. if (this.calcs.bottom) {
  13190. this.calcs.bottom.detachElement();
  13191. this.calcs.bottom.deleteCells();
  13192. }
  13193. if (this.groupManager.table.options.groupClosedShowCalcs) {
  13194. this.calcs.bottom = this.groupManager.table.modules.columnCalcs.generateBottomRow(this.rows);
  13195. output.push(this.calcs.bottom);
  13196. }
  13197. }
  13198. }
  13199. }
  13200. }
  13201. return output;
  13202. };
  13203. Group.prototype.getData = function (visible, transform) {
  13204. var self = this,
  13205. output = [];
  13206. this._visSet();
  13207. if (!visible || visible && this.visible) {
  13208. this.rows.forEach(function (row) {
  13209. output.push(row.getData(transform || "data"));
  13210. });
  13211. }
  13212. return output;
  13213. };
  13214. // Group.prototype.getRows = function(){
  13215. // this._visSet();
  13216. // return this.visible ? this.rows : [];
  13217. // };
  13218. Group.prototype.getRowCount = function () {
  13219. var count = 0;
  13220. if (this.groupList.length) {
  13221. this.groupList.forEach(function (group) {
  13222. count += group.getRowCount();
  13223. });
  13224. } else {
  13225. count = this.rows.length;
  13226. }
  13227. return count;
  13228. };
  13229. Group.prototype.toggleVisibility = function () {
  13230. if (this.visible) {
  13231. this.hide();
  13232. } else {
  13233. this.show();
  13234. }
  13235. };
  13236. Group.prototype.hide = function () {
  13237. this.visible = false;
  13238. if (this.groupManager.table.rowManager.getRenderMode() == "classic" && !this.groupManager.table.options.pagination) {
  13239. this.element.classList.remove("tabulator-group-visible");
  13240. if (this.groupList.length) {
  13241. this.groupList.forEach(function (group) {
  13242. var rows = group.getHeadersAndRows();
  13243. rows.forEach(function (row) {
  13244. row.detachElement();
  13245. });
  13246. });
  13247. } else {
  13248. this.rows.forEach(function (row) {
  13249. var rowEl = row.getElement();
  13250. rowEl.parentNode.removeChild(rowEl);
  13251. });
  13252. }
  13253. this.groupManager.table.rowManager.setDisplayRows(this.groupManager.updateGroupRows(), this.groupManager.getDisplayIndex());
  13254. this.groupManager.table.rowManager.checkClassicModeGroupHeaderWidth();
  13255. } else {
  13256. this.groupManager.updateGroupRows(true);
  13257. }
  13258. this.groupManager.table.options.groupVisibilityChanged.call(this.table, this.getComponent(), false);
  13259. };
  13260. Group.prototype.show = function () {
  13261. var self = this;
  13262. self.visible = true;
  13263. if (this.groupManager.table.rowManager.getRenderMode() == "classic" && !this.groupManager.table.options.pagination) {
  13264. this.element.classList.add("tabulator-group-visible");
  13265. var prev = self.getElement();
  13266. if (this.groupList.length) {
  13267. this.groupList.forEach(function (group) {
  13268. var rows = group.getHeadersAndRows();
  13269. rows.forEach(function (row) {
  13270. var rowEl = row.getElement();
  13271. prev.parentNode.insertBefore(rowEl, prev.nextSibling);
  13272. row.initialize();
  13273. prev = rowEl;
  13274. });
  13275. });
  13276. } else {
  13277. self.rows.forEach(function (row) {
  13278. var rowEl = row.getElement();
  13279. prev.parentNode.insertBefore(rowEl, prev.nextSibling);
  13280. row.initialize();
  13281. prev = rowEl;
  13282. });
  13283. }
  13284. this.groupManager.table.rowManager.setDisplayRows(this.groupManager.updateGroupRows(), this.groupManager.getDisplayIndex());
  13285. this.groupManager.table.rowManager.checkClassicModeGroupHeaderWidth();
  13286. } else {
  13287. this.groupManager.updateGroupRows(true);
  13288. }
  13289. this.groupManager.table.options.groupVisibilityChanged.call(this.table, this.getComponent(), true);
  13290. };
  13291. Group.prototype._visSet = function () {
  13292. var data = [];
  13293. if (typeof this.visible == "function") {
  13294. this.rows.forEach(function (row) {
  13295. data.push(row.getData());
  13296. });
  13297. this.visible = this.visible(this.key, this.getRowCount(), data, this.getComponent());
  13298. }
  13299. };
  13300. Group.prototype.getRowGroup = function (row) {
  13301. var match = false;
  13302. if (this.groupList.length) {
  13303. this.groupList.forEach(function (group) {
  13304. var result = group.getRowGroup(row);
  13305. if (result) {
  13306. match = result;
  13307. }
  13308. });
  13309. } else {
  13310. if (this.rows.find(function (item) {
  13311. return item === row;
  13312. })) {
  13313. match = this;
  13314. }
  13315. }
  13316. return match;
  13317. };
  13318. Group.prototype.getSubGroups = function (component) {
  13319. var output = [];
  13320. this.groupList.forEach(function (child) {
  13321. output.push(component ? child.getComponent() : child);
  13322. });
  13323. return output;
  13324. };
  13325. Group.prototype.getRows = function (compoment) {
  13326. var output = [];
  13327. this.rows.forEach(function (row) {
  13328. output.push(compoment ? row.getComponent() : row);
  13329. });
  13330. return output;
  13331. };
  13332. Group.prototype.generateGroupHeaderContents = function () {
  13333. var data = [];
  13334. this.rows.forEach(function (row) {
  13335. data.push(row.getData());
  13336. });
  13337. this.elementContents = this.generator(this.key, this.getRowCount(), data, this.getComponent());
  13338. while (this.element.firstChild) {
  13339. this.element.removeChild(this.element.firstChild);
  13340. }if (typeof this.elementContents === "string") {
  13341. this.element.innerHTML = this.elementContents;
  13342. } else {
  13343. this.element.appendChild(this.elementContents);
  13344. }
  13345. this.element.insertBefore(this.arrowElement, this.element.firstChild);
  13346. };
  13347. Group.prototype.getPath = function () {
  13348. var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  13349. path.unshift(this.key);
  13350. if (this.parent) {
  13351. this.parent.getPath(path);
  13352. }
  13353. return path;
  13354. };
  13355. ////////////// Standard Row Functions //////////////
  13356. Group.prototype.getElement = function () {
  13357. this.addBindingsd = false;
  13358. this._visSet();
  13359. if (this.visible) {
  13360. this.element.classList.add("tabulator-group-visible");
  13361. } else {
  13362. this.element.classList.remove("tabulator-group-visible");
  13363. }
  13364. for (var i = 0; i < this.element.childNodes.length; ++i) {
  13365. this.element.childNodes[i].parentNode.removeChild(this.element.childNodes[i]);
  13366. }
  13367. this.generateGroupHeaderContents();
  13368. // this.addBindings();
  13369. return this.element;
  13370. };
  13371. Group.prototype.detachElement = function () {
  13372. if (this.element && this.element.parentNode) {
  13373. this.element.parentNode.removeChild(this.element);
  13374. }
  13375. };
  13376. //normalize the height of elements in the row
  13377. Group.prototype.normalizeHeight = function () {
  13378. this.setHeight(this.element.clientHeight);
  13379. };
  13380. Group.prototype.initialize = function (force) {
  13381. if (!this.initialized || force) {
  13382. this.normalizeHeight();
  13383. this.initialized = true;
  13384. }
  13385. };
  13386. Group.prototype.reinitialize = function () {
  13387. this.initialized = false;
  13388. this.height = 0;
  13389. if (Tabulator.prototype.helpers.elVisible(this.element)) {
  13390. this.initialize(true);
  13391. }
  13392. };
  13393. Group.prototype.setHeight = function (height) {
  13394. if (this.height != height) {
  13395. this.height = height;
  13396. this.outerHeight = this.element.offsetHeight;
  13397. }
  13398. };
  13399. //return rows outer height
  13400. Group.prototype.getHeight = function () {
  13401. return this.outerHeight;
  13402. };
  13403. Group.prototype.getGroup = function () {
  13404. return this;
  13405. };
  13406. Group.prototype.reinitializeHeight = function () {};
  13407. Group.prototype.calcHeight = function () {};
  13408. Group.prototype.setCellHeight = function () {};
  13409. Group.prototype.clearCellHeight = function () {};
  13410. //////////////// Object Generation /////////////////
  13411. Group.prototype.getComponent = function () {
  13412. if (!this.component) {
  13413. this.component = new GroupComponent(this);
  13414. }
  13415. return this.component;
  13416. };
  13417. //////////////////////////////////////////////////
  13418. ////////////// Group Row Extension ///////////////
  13419. //////////////////////////////////////////////////
  13420. var GroupRows = function GroupRows(table) {
  13421. this.table = table; //hold Tabulator object
  13422. this.groupIDLookups = false; //enable table grouping and set field to group by
  13423. this.startOpen = [function () {
  13424. return false;
  13425. }]; //starting state of group
  13426. this.headerGenerator = [function () {
  13427. return "";
  13428. }];
  13429. this.groupList = []; //ordered list of groups
  13430. this.allowedValues = false;
  13431. this.groups = {}; //hold row groups
  13432. this.displayIndex = 0; //index in display pipeline
  13433. };
  13434. //initialize group configuration
  13435. GroupRows.prototype.initialize = function () {
  13436. var self = this,
  13437. groupBy = self.table.options.groupBy,
  13438. startOpen = self.table.options.groupStartOpen,
  13439. groupHeader = self.table.options.groupHeader;
  13440. this.allowedValues = self.table.options.groupValues;
  13441. if (Array.isArray(groupBy) && Array.isArray(groupHeader) && groupBy.length > groupHeader.length) {
  13442. console.warn("Error creating group headers, groupHeader array is shorter than groupBy array");
  13443. }
  13444. self.headerGenerator = [function () {
  13445. return "";
  13446. }];
  13447. this.startOpen = [function () {
  13448. return false;
  13449. }]; //starting state of group
  13450. self.table.modules.localize.bind("groups|item", function (langValue, lang) {
  13451. self.headerGenerator[0] = function (value, count, data) {
  13452. //header layout function
  13453. return (typeof value === "undefined" ? "" : value) + "<span>(" + count + " " + (count === 1 ? langValue : lang.groups.items) + ")</span>";
  13454. };
  13455. });
  13456. this.groupIDLookups = [];
  13457. if (Array.isArray(groupBy) || groupBy) {
  13458. if (this.table.modExists("columnCalcs") && this.table.options.columnCalcs != "table" && this.table.options.columnCalcs != "both") {
  13459. this.table.modules.columnCalcs.removeCalcs();
  13460. }
  13461. } else {
  13462. if (this.table.modExists("columnCalcs") && this.table.options.columnCalcs != "group") {
  13463. var cols = this.table.columnManager.getRealColumns();
  13464. cols.forEach(function (col) {
  13465. if (col.definition.topCalc) {
  13466. self.table.modules.columnCalcs.initializeTopRow();
  13467. }
  13468. if (col.definition.bottomCalc) {
  13469. self.table.modules.columnCalcs.initializeBottomRow();
  13470. }
  13471. });
  13472. }
  13473. }
  13474. if (!Array.isArray(groupBy)) {
  13475. groupBy = [groupBy];
  13476. }
  13477. groupBy.forEach(function (group, i) {
  13478. var lookupFunc, column;
  13479. if (typeof group == "function") {
  13480. lookupFunc = group;
  13481. } else {
  13482. column = self.table.columnManager.getColumnByField(group);
  13483. if (column) {
  13484. lookupFunc = function lookupFunc(data) {
  13485. return column.getFieldValue(data);
  13486. };
  13487. } else {
  13488. lookupFunc = function lookupFunc(data) {
  13489. return data[group];
  13490. };
  13491. }
  13492. }
  13493. self.groupIDLookups.push({
  13494. field: typeof group === "function" ? false : group,
  13495. func: lookupFunc,
  13496. values: self.allowedValues ? self.allowedValues[i] : false
  13497. });
  13498. });
  13499. if (startOpen) {
  13500. if (!Array.isArray(startOpen)) {
  13501. startOpen = [startOpen];
  13502. }
  13503. startOpen.forEach(function (level) {
  13504. level = typeof level == "function" ? level : function () {
  13505. return true;
  13506. };
  13507. });
  13508. self.startOpen = startOpen;
  13509. }
  13510. if (groupHeader) {
  13511. self.headerGenerator = Array.isArray(groupHeader) ? groupHeader : [groupHeader];
  13512. }
  13513. this.initialized = true;
  13514. };
  13515. GroupRows.prototype.setDisplayIndex = function (index) {
  13516. this.displayIndex = index;
  13517. };
  13518. GroupRows.prototype.getDisplayIndex = function () {
  13519. return this.displayIndex;
  13520. };
  13521. //return appropriate rows with group headers
  13522. GroupRows.prototype.getRows = function (rows) {
  13523. if (this.groupIDLookups.length) {
  13524. this.table.options.dataGrouping.call(this.table);
  13525. this.generateGroups(rows);
  13526. if (this.table.options.dataGrouped) {
  13527. this.table.options.dataGrouped.call(this.table, this.getGroups(true));
  13528. }
  13529. return this.updateGroupRows();
  13530. } else {
  13531. return rows.slice(0);
  13532. }
  13533. };
  13534. GroupRows.prototype.getGroups = function (compoment) {
  13535. var groupComponents = [];
  13536. this.groupList.forEach(function (group) {
  13537. groupComponents.push(compoment ? group.getComponent() : group);
  13538. });
  13539. return groupComponents;
  13540. };
  13541. GroupRows.prototype.getChildGroups = function (group) {
  13542. var _this69 = this;
  13543. var groupComponents = [];
  13544. if (!group) {
  13545. group = this;
  13546. }
  13547. group.groupList.forEach(function (child) {
  13548. if (child.groupList.length) {
  13549. groupComponents = groupComponents.concat(_this69.getChildGroups(child));
  13550. } else {
  13551. groupComponents.push(child);
  13552. }
  13553. });
  13554. return groupComponents;
  13555. };
  13556. GroupRows.prototype.wipe = function () {
  13557. this.groupList.forEach(function (group) {
  13558. group.wipe();
  13559. });
  13560. };
  13561. GroupRows.prototype.pullGroupListData = function (groupList) {
  13562. var self = this;
  13563. var groupListData = [];
  13564. groupList.forEach(function (group) {
  13565. var groupHeader = {};
  13566. groupHeader.level = 0;
  13567. groupHeader.rowCount = 0;
  13568. groupHeader.headerContent = "";
  13569. var childData = [];
  13570. if (group.hasSubGroups) {
  13571. childData = self.pullGroupListData(group.groupList);
  13572. groupHeader.level = group.level;
  13573. groupHeader.rowCount = childData.length - group.groupList.length; // data length minus number of sub-headers
  13574. groupHeader.headerContent = group.generator(group.key, groupHeader.rowCount, group.rows, group);
  13575. groupListData.push(groupHeader);
  13576. groupListData = groupListData.concat(childData);
  13577. } else {
  13578. groupHeader.level = group.level;
  13579. groupHeader.headerContent = group.generator(group.key, group.rows.length, group.rows, group);
  13580. groupHeader.rowCount = group.getRows().length;
  13581. groupListData.push(groupHeader);
  13582. group.getRows().forEach(function (row) {
  13583. groupListData.push(row.getData("data"));
  13584. });
  13585. }
  13586. });
  13587. return groupListData;
  13588. };
  13589. GroupRows.prototype.getGroupedData = function () {
  13590. return this.pullGroupListData(this.groupList);
  13591. };
  13592. GroupRows.prototype.getRowGroup = function (row) {
  13593. var match = false;
  13594. this.groupList.forEach(function (group) {
  13595. var result = group.getRowGroup(row);
  13596. if (result) {
  13597. match = result;
  13598. }
  13599. });
  13600. return match;
  13601. };
  13602. GroupRows.prototype.countGroups = function () {
  13603. return this.groupList.length;
  13604. };
  13605. GroupRows.prototype.generateGroups = function (rows) {
  13606. var self = this,
  13607. oldGroups = self.groups;
  13608. self.groups = {};
  13609. self.groupList = [];
  13610. if (this.allowedValues && this.allowedValues[0]) {
  13611. this.allowedValues[0].forEach(function (value) {
  13612. self.createGroup(value, 0, oldGroups);
  13613. });
  13614. rows.forEach(function (row) {
  13615. self.assignRowToExistingGroup(row, oldGroups);
  13616. });
  13617. } else {
  13618. rows.forEach(function (row) {
  13619. self.assignRowToGroup(row, oldGroups);
  13620. });
  13621. }
  13622. };
  13623. GroupRows.prototype.createGroup = function (groupID, level, oldGroups) {
  13624. var groupKey = level + "_" + groupID,
  13625. group;
  13626. oldGroups = oldGroups || [];
  13627. group = new Group(this, false, level, groupID, this.groupIDLookups[0].field, this.headerGenerator[0], oldGroups[groupKey]);
  13628. this.groups[groupKey] = group;
  13629. this.groupList.push(group);
  13630. };
  13631. // GroupRows.prototype.assignRowToGroup = function(row, oldGroups){
  13632. // var groupID = this.groupIDLookups[0].func(row.getData()),
  13633. // groupKey = "0_" + groupID;
  13634. // if(!this.groups[groupKey]){
  13635. // this.createGroup(groupID, 0, oldGroups);
  13636. // }
  13637. // this.groups[groupKey].addRow(row);
  13638. // };
  13639. GroupRows.prototype.assignRowToExistingGroup = function (row, oldGroups) {
  13640. var groupID = this.groupIDLookups[0].func(row.getData()),
  13641. groupKey = "0_" + groupID;
  13642. if (this.groups[groupKey]) {
  13643. this.groups[groupKey].addRow(row);
  13644. }
  13645. };
  13646. GroupRows.prototype.assignRowToGroup = function (row, oldGroups) {
  13647. var groupID = this.groupIDLookups[0].func(row.getData()),
  13648. newGroupNeeded = !this.groups["0_" + groupID];
  13649. if (newGroupNeeded) {
  13650. this.createGroup(groupID, 0, oldGroups);
  13651. }
  13652. this.groups["0_" + groupID].addRow(row);
  13653. return !newGroupNeeded;
  13654. };
  13655. GroupRows.prototype.reassignRowToGroup = function (row) {
  13656. var oldRowGroup = row.getGroup(),
  13657. oldGroupPath = oldRowGroup.getPath(),
  13658. newGroupPath = this.getExpectedPath(row),
  13659. samePath = true;
  13660. // figure out if new group path is the same as old group path
  13661. var samePath = oldGroupPath.length == newGroupPath.length && oldGroupPath.every(function (element, index) {
  13662. return element === newGroupPath[index];
  13663. });
  13664. // refresh if they new path and old path aren't the same (aka the row's groupings have changed)
  13665. if (!samePath) {
  13666. oldRowGroup.removeRow(row);
  13667. this.assignRowToGroup(row, self.groups);
  13668. this.table.rowManager.refreshActiveData("group", false, true);
  13669. }
  13670. };
  13671. GroupRows.prototype.getExpectedPath = function (row) {
  13672. var groupPath = [],
  13673. rowData = row.getData();
  13674. this.groupIDLookups.forEach(function (groupId) {
  13675. groupPath.push(groupId.func(rowData));
  13676. });
  13677. return groupPath;
  13678. };
  13679. GroupRows.prototype.updateGroupRows = function (force) {
  13680. var self = this,
  13681. output = [],
  13682. oldRowCount;
  13683. self.groupList.forEach(function (group) {
  13684. output = output.concat(group.getHeadersAndRows());
  13685. });
  13686. //force update of table display
  13687. if (force) {
  13688. var displayIndex = self.table.rowManager.setDisplayRows(output, this.getDisplayIndex());
  13689. if (displayIndex !== true) {
  13690. this.setDisplayIndex(displayIndex);
  13691. }
  13692. self.table.rowManager.refreshActiveData("group", true, true);
  13693. }
  13694. return output;
  13695. };
  13696. GroupRows.prototype.scrollHeaders = function (left) {
  13697. if (this.table.options.virtualDomHoz) {
  13698. left -= this.table.vdomHoz.vDomPadLeft;
  13699. }
  13700. left = left + "px";
  13701. this.groupList.forEach(function (group) {
  13702. group.scrollHeader(left);
  13703. });
  13704. };
  13705. GroupRows.prototype.removeGroup = function (group) {
  13706. var groupKey = group.level + "_" + group.key,
  13707. index;
  13708. if (this.groups[groupKey]) {
  13709. delete this.groups[groupKey];
  13710. index = this.groupList.indexOf(group);
  13711. if (index > -1) {
  13712. this.groupList.splice(index, 1);
  13713. }
  13714. }
  13715. };
  13716. Tabulator.prototype.registerModule("groupRows", GroupRows);
  13717. var History = function History(table) {
  13718. this.table = table; //hold Tabulator object
  13719. this.history = [];
  13720. this.index = -1;
  13721. };
  13722. History.prototype.clear = function () {
  13723. this.history = [];
  13724. this.index = -1;
  13725. };
  13726. History.prototype.action = function (type, component, data) {
  13727. this.history = this.history.slice(0, this.index + 1);
  13728. this.history.push({
  13729. type: type,
  13730. component: component,
  13731. data: data
  13732. });
  13733. this.index++;
  13734. };
  13735. History.prototype.getHistoryUndoSize = function () {
  13736. return this.index + 1;
  13737. };
  13738. History.prototype.getHistoryRedoSize = function () {
  13739. return this.history.length - (this.index + 1);
  13740. };
  13741. History.prototype.clearComponentHistory = function (component) {
  13742. var index = this.history.findIndex(function (item) {
  13743. return item.component === component;
  13744. });
  13745. if (index > -1) {
  13746. this.history.splice(index, 1);
  13747. if (index <= this.index) {
  13748. this.index--;
  13749. }
  13750. this.clearComponentHistory(component);
  13751. }
  13752. };
  13753. History.prototype.undo = function () {
  13754. if (this.index > -1) {
  13755. var action = this.history[this.index];
  13756. this.undoers[action.type].call(this, action);
  13757. this.index--;
  13758. this.table.options.historyUndo.call(this.table, action.type, action.component.getComponent(), action.data);
  13759. return true;
  13760. } else {
  13761. console.warn("History Undo Error - No more history to undo");
  13762. return false;
  13763. }
  13764. };
  13765. History.prototype.redo = function () {
  13766. if (this.history.length - 1 > this.index) {
  13767. this.index++;
  13768. var action = this.history[this.index];
  13769. this.redoers[action.type].call(this, action);
  13770. this.table.options.historyRedo.call(this.table, action.type, action.component.getComponent(), action.data);
  13771. return true;
  13772. } else {
  13773. console.warn("History Redo Error - No more history to redo");
  13774. return false;
  13775. }
  13776. };
  13777. History.prototype.undoers = {
  13778. cellEdit: function cellEdit(action) {
  13779. action.component.setValueProcessData(action.data.oldValue);
  13780. },
  13781. rowAdd: function rowAdd(action) {
  13782. action.component.deleteActual();
  13783. },
  13784. rowDelete: function rowDelete(action) {
  13785. var newRow = this.table.rowManager.addRowActual(action.data.data, action.data.pos, action.data.index);
  13786. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  13787. this.table.modules.groupRows.updateGroupRows(true);
  13788. }
  13789. this._rebindRow(action.component, newRow);
  13790. },
  13791. rowMove: function rowMove(action) {
  13792. this.table.rowManager.moveRowActual(action.component, this.table.rowManager.rows[action.data.posFrom], !action.data.after);
  13793. this.table.rowManager.redraw();
  13794. }
  13795. };
  13796. History.prototype.redoers = {
  13797. cellEdit: function cellEdit(action) {
  13798. action.component.setValueProcessData(action.data.newValue);
  13799. },
  13800. rowAdd: function rowAdd(action) {
  13801. var newRow = this.table.rowManager.addRowActual(action.data.data, action.data.pos, action.data.index);
  13802. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  13803. this.table.modules.groupRows.updateGroupRows(true);
  13804. }
  13805. this._rebindRow(action.component, newRow);
  13806. },
  13807. rowDelete: function rowDelete(action) {
  13808. action.component.deleteActual();
  13809. },
  13810. rowMove: function rowMove(action) {
  13811. this.table.rowManager.moveRowActual(action.component, this.table.rowManager.rows[action.data.posTo], action.data.after);
  13812. this.table.rowManager.redraw();
  13813. }
  13814. };
  13815. //rebind rows to new element after deletion
  13816. History.prototype._rebindRow = function (oldRow, newRow) {
  13817. this.history.forEach(function (action) {
  13818. if (action.component instanceof Row) {
  13819. if (action.component === oldRow) {
  13820. action.component = newRow;
  13821. }
  13822. } else if (action.component instanceof Cell) {
  13823. if (action.component.row === oldRow) {
  13824. var field = action.component.column.getField();
  13825. if (field) {
  13826. action.component = newRow.getCell(field);
  13827. }
  13828. }
  13829. }
  13830. });
  13831. };
  13832. Tabulator.prototype.registerModule("history", History);
  13833. var HtmlTableImport = function HtmlTableImport(table) {
  13834. this.table = table; //hold Tabulator object
  13835. this.fieldIndex = [];
  13836. this.hasIndex = false;
  13837. };
  13838. HtmlTableImport.prototype.parseTable = function () {
  13839. var self = this,
  13840. element = self.table.element,
  13841. options = self.table.options,
  13842. columns = options.columns,
  13843. headers = element.getElementsByTagName("th"),
  13844. rows = element.getElementsByTagName("tbody")[0],
  13845. data = [],
  13846. newTable;
  13847. self.hasIndex = false;
  13848. self.table.options.htmlImporting.call(this.table);
  13849. rows = rows ? rows.getElementsByTagName("tr") : [];
  13850. //check for tablator inline options
  13851. self._extractOptions(element, options);
  13852. if (headers.length) {
  13853. self._extractHeaders(headers, rows);
  13854. } else {
  13855. self._generateBlankHeaders(headers, rows);
  13856. }
  13857. //iterate through table rows and build data set
  13858. for (var index = 0; index < rows.length; index++) {
  13859. var row = rows[index],
  13860. cells = row.getElementsByTagName("td"),
  13861. item = {};
  13862. //create index if the dont exist in table
  13863. if (!self.hasIndex) {
  13864. item[options.index] = index;
  13865. }
  13866. for (var i = 0; i < cells.length; i++) {
  13867. var cell = cells[i];
  13868. if (typeof this.fieldIndex[i] !== "undefined") {
  13869. item[this.fieldIndex[i]] = cell.innerHTML;
  13870. }
  13871. }
  13872. //add row data to item
  13873. data.push(item);
  13874. }
  13875. //create new element
  13876. var newElement = document.createElement("div");
  13877. //transfer attributes to new element
  13878. var attributes = element.attributes;
  13879. // loop through attributes and apply them on div
  13880. for (var i in attributes) {
  13881. if (_typeof(attributes[i]) == "object") {
  13882. newElement.setAttribute(attributes[i].name, attributes[i].value);
  13883. }
  13884. }
  13885. // replace table with div element
  13886. element.parentNode.replaceChild(newElement, element);
  13887. options.data = data;
  13888. self.table.options.htmlImported.call(this.table);
  13889. // // newElement.tabulator(options);
  13890. this.table.element = newElement;
  13891. };
  13892. //extract tabulator attribute options
  13893. HtmlTableImport.prototype._extractOptions = function (element, options, defaultOptions) {
  13894. var attributes = element.attributes;
  13895. var optionsArr = defaultOptions ? Object.assign([], defaultOptions) : Object.keys(options);
  13896. var optionsList = {};
  13897. optionsArr.forEach(function (item) {
  13898. optionsList[item.toLowerCase()] = item;
  13899. });
  13900. for (var index in attributes) {
  13901. var attrib = attributes[index];
  13902. var name;
  13903. if (attrib && (typeof attrib === 'undefined' ? 'undefined' : _typeof(attrib)) == "object" && attrib.name && attrib.name.indexOf("tabulator-") === 0) {
  13904. name = attrib.name.replace("tabulator-", "");
  13905. if (typeof optionsList[name] !== "undefined") {
  13906. options[optionsList[name]] = this._attribValue(attrib.value);
  13907. }
  13908. }
  13909. }
  13910. };
  13911. //get value of attribute
  13912. HtmlTableImport.prototype._attribValue = function (value) {
  13913. if (value === "true") {
  13914. return true;
  13915. }
  13916. if (value === "false") {
  13917. return false;
  13918. }
  13919. return value;
  13920. };
  13921. //find column if it has already been defined
  13922. HtmlTableImport.prototype._findCol = function (title) {
  13923. var match = this.table.options.columns.find(function (column) {
  13924. return column.title === title;
  13925. });
  13926. return match || false;
  13927. };
  13928. //extract column from headers
  13929. HtmlTableImport.prototype._extractHeaders = function (headers, rows) {
  13930. for (var index = 0; index < headers.length; index++) {
  13931. var header = headers[index],
  13932. exists = false,
  13933. col = this._findCol(header.textContent),
  13934. width,
  13935. attributes;
  13936. if (col) {
  13937. exists = true;
  13938. } else {
  13939. col = { title: header.textContent.trim() };
  13940. }
  13941. if (!col.field) {
  13942. col.field = header.textContent.trim().toLowerCase().replace(" ", "_");
  13943. }
  13944. width = header.getAttribute("width");
  13945. if (width && !col.width) {
  13946. col.width = width;
  13947. }
  13948. //check for tablator inline options
  13949. attributes = header.attributes;
  13950. // //check for tablator inline options
  13951. this._extractOptions(header, col, Column.prototype.defaultOptionList);
  13952. this.fieldIndex[index] = col.field;
  13953. if (col.field == this.table.options.index) {
  13954. this.hasIndex = true;
  13955. }
  13956. if (!exists) {
  13957. this.table.options.columns.push(col);
  13958. }
  13959. }
  13960. };
  13961. //generate blank headers
  13962. HtmlTableImport.prototype._generateBlankHeaders = function (headers, rows) {
  13963. for (var index = 0; index < headers.length; index++) {
  13964. var header = headers[index],
  13965. col = { title: "", field: "col" + index };
  13966. this.fieldIndex[index] = col.field;
  13967. var width = header.getAttribute("width");
  13968. if (width) {
  13969. col.width = width;
  13970. }
  13971. this.table.options.columns.push(col);
  13972. }
  13973. };
  13974. Tabulator.prototype.registerModule("htmlTableImport", HtmlTableImport);
  13975. var Keybindings = function Keybindings(table) {
  13976. this.table = table; //hold Tabulator object
  13977. this.watchKeys = null;
  13978. this.pressedKeys = null;
  13979. this.keyupBinding = false;
  13980. this.keydownBinding = false;
  13981. };
  13982. Keybindings.prototype.initialize = function () {
  13983. var bindings = this.table.options.keybindings,
  13984. mergedBindings = {};
  13985. this.watchKeys = {};
  13986. this.pressedKeys = [];
  13987. if (bindings !== false) {
  13988. for (var key in this.bindings) {
  13989. mergedBindings[key] = this.bindings[key];
  13990. }
  13991. if (Object.keys(bindings).length) {
  13992. for (var _key in bindings) {
  13993. mergedBindings[_key] = bindings[_key];
  13994. }
  13995. }
  13996. this.mapBindings(mergedBindings);
  13997. this.bindEvents();
  13998. }
  13999. };
  14000. Keybindings.prototype.mapBindings = function (bindings) {
  14001. var _this70 = this;
  14002. var self = this;
  14003. var _loop2 = function _loop2(key) {
  14004. if (_this70.actions[key]) {
  14005. if (bindings[key]) {
  14006. if (_typeof(bindings[key]) !== "object") {
  14007. bindings[key] = [bindings[key]];
  14008. }
  14009. bindings[key].forEach(function (binding) {
  14010. self.mapBinding(key, binding);
  14011. });
  14012. }
  14013. } else {
  14014. console.warn("Key Binding Error - no such action:", key);
  14015. }
  14016. };
  14017. for (var key in bindings) {
  14018. _loop2(key);
  14019. }
  14020. };
  14021. Keybindings.prototype.mapBinding = function (action, symbolsList) {
  14022. var self = this;
  14023. var binding = {
  14024. action: this.actions[action],
  14025. keys: [],
  14026. ctrl: false,
  14027. shift: false,
  14028. meta: false
  14029. };
  14030. var symbols = symbolsList.toString().toLowerCase().split(" ").join("").split("+");
  14031. symbols.forEach(function (symbol) {
  14032. switch (symbol) {
  14033. case "ctrl":
  14034. binding.ctrl = true;
  14035. break;
  14036. case "shift":
  14037. binding.shift = true;
  14038. break;
  14039. case "meta":
  14040. binding.meta = true;
  14041. break;
  14042. default:
  14043. symbol = parseInt(symbol);
  14044. binding.keys.push(symbol);
  14045. if (!self.watchKeys[symbol]) {
  14046. self.watchKeys[symbol] = [];
  14047. }
  14048. self.watchKeys[symbol].push(binding);
  14049. }
  14050. });
  14051. };
  14052. Keybindings.prototype.bindEvents = function () {
  14053. var self = this;
  14054. this.keyupBinding = function (e) {
  14055. var code = e.keyCode;
  14056. var bindings = self.watchKeys[code];
  14057. if (bindings) {
  14058. self.pressedKeys.push(code);
  14059. bindings.forEach(function (binding) {
  14060. self.checkBinding(e, binding);
  14061. });
  14062. }
  14063. };
  14064. this.keydownBinding = function (e) {
  14065. var code = e.keyCode;
  14066. var bindings = self.watchKeys[code];
  14067. if (bindings) {
  14068. var index = self.pressedKeys.indexOf(code);
  14069. if (index > -1) {
  14070. self.pressedKeys.splice(index, 1);
  14071. }
  14072. }
  14073. };
  14074. this.table.element.addEventListener("keydown", this.keyupBinding);
  14075. this.table.element.addEventListener("keyup", this.keydownBinding);
  14076. };
  14077. Keybindings.prototype.clearBindings = function () {
  14078. if (this.keyupBinding) {
  14079. this.table.element.removeEventListener("keydown", this.keyupBinding);
  14080. }
  14081. if (this.keydownBinding) {
  14082. this.table.element.removeEventListener("keyup", this.keydownBinding);
  14083. }
  14084. };
  14085. Keybindings.prototype.checkBinding = function (e, binding) {
  14086. var self = this,
  14087. match = true;
  14088. if (e.ctrlKey == binding.ctrl && e.shiftKey == binding.shift && e.metaKey == binding.meta) {
  14089. binding.keys.forEach(function (key) {
  14090. var index = self.pressedKeys.indexOf(key);
  14091. if (index == -1) {
  14092. match = false;
  14093. }
  14094. });
  14095. if (match) {
  14096. binding.action.call(self, e);
  14097. }
  14098. return true;
  14099. }
  14100. return false;
  14101. };
  14102. //default bindings
  14103. Keybindings.prototype.bindings = {
  14104. navPrev: "shift + 9",
  14105. navNext: 9,
  14106. navUp: 38,
  14107. navDown: 40,
  14108. scrollPageUp: 33,
  14109. scrollPageDown: 34,
  14110. scrollToStart: 36,
  14111. scrollToEnd: 35,
  14112. undo: "ctrl + 90",
  14113. redo: "ctrl + 89",
  14114. copyToClipboard: "ctrl + 67"
  14115. };
  14116. //default actions
  14117. Keybindings.prototype.actions = {
  14118. keyBlock: function keyBlock(e) {
  14119. e.stopPropagation();
  14120. e.preventDefault();
  14121. },
  14122. scrollPageUp: function scrollPageUp(e) {
  14123. var rowManager = this.table.rowManager,
  14124. newPos = rowManager.scrollTop - rowManager.height,
  14125. scrollMax = rowManager.element.scrollHeight;
  14126. e.preventDefault();
  14127. if (rowManager.displayRowsCount) {
  14128. if (newPos >= 0) {
  14129. rowManager.element.scrollTop = newPos;
  14130. } else {
  14131. rowManager.scrollToRow(rowManager.getDisplayRows()[0]);
  14132. }
  14133. }
  14134. this.table.element.focus();
  14135. },
  14136. scrollPageDown: function scrollPageDown(e) {
  14137. var rowManager = this.table.rowManager,
  14138. newPos = rowManager.scrollTop + rowManager.height,
  14139. scrollMax = rowManager.element.scrollHeight;
  14140. e.preventDefault();
  14141. if (rowManager.displayRowsCount) {
  14142. if (newPos <= scrollMax) {
  14143. rowManager.element.scrollTop = newPos;
  14144. } else {
  14145. rowManager.scrollToRow(rowManager.getDisplayRows()[rowManager.displayRowsCount - 1]);
  14146. }
  14147. }
  14148. this.table.element.focus();
  14149. },
  14150. scrollToStart: function scrollToStart(e) {
  14151. var rowManager = this.table.rowManager;
  14152. e.preventDefault();
  14153. if (rowManager.displayRowsCount) {
  14154. rowManager.scrollToRow(rowManager.getDisplayRows()[0]);
  14155. }
  14156. this.table.element.focus();
  14157. },
  14158. scrollToEnd: function scrollToEnd(e) {
  14159. var rowManager = this.table.rowManager;
  14160. e.preventDefault();
  14161. if (rowManager.displayRowsCount) {
  14162. rowManager.scrollToRow(rowManager.getDisplayRows()[rowManager.displayRowsCount - 1]);
  14163. }
  14164. this.table.element.focus();
  14165. },
  14166. navPrev: function navPrev(e) {
  14167. var cell = false;
  14168. if (this.table.modExists("edit")) {
  14169. cell = this.table.modules.edit.currentCell;
  14170. if (cell) {
  14171. e.preventDefault();
  14172. cell.nav().prev();
  14173. }
  14174. }
  14175. },
  14176. navNext: function navNext(e) {
  14177. var cell = false;
  14178. var newRow = this.table.options.tabEndNewRow;
  14179. var nav;
  14180. if (this.table.modExists("edit")) {
  14181. cell = this.table.modules.edit.currentCell;
  14182. if (cell) {
  14183. e.preventDefault();
  14184. nav = cell.nav();
  14185. if (!nav.next()) {
  14186. if (newRow) {
  14187. cell.getElement().firstChild.blur();
  14188. if (newRow === true) {
  14189. newRow = this.table.addRow({});
  14190. } else {
  14191. if (typeof newRow == "function") {
  14192. newRow = this.table.addRow(newRow(cell.row.getComponent()));
  14193. } else {
  14194. newRow = this.table.addRow(Object.assign({}, newRow));
  14195. }
  14196. }
  14197. newRow.then(function () {
  14198. setTimeout(function () {
  14199. nav.next();
  14200. });
  14201. });
  14202. }
  14203. }
  14204. }
  14205. }
  14206. },
  14207. navLeft: function navLeft(e) {
  14208. var cell = false;
  14209. if (this.table.modExists("edit")) {
  14210. cell = this.table.modules.edit.currentCell;
  14211. if (cell) {
  14212. e.preventDefault();
  14213. cell.nav().left();
  14214. }
  14215. }
  14216. },
  14217. navRight: function navRight(e) {
  14218. var cell = false;
  14219. if (this.table.modExists("edit")) {
  14220. cell = this.table.modules.edit.currentCell;
  14221. if (cell) {
  14222. e.preventDefault();
  14223. cell.nav().right();
  14224. }
  14225. }
  14226. },
  14227. navUp: function navUp(e) {
  14228. var cell = false;
  14229. if (this.table.modExists("edit")) {
  14230. cell = this.table.modules.edit.currentCell;
  14231. if (cell) {
  14232. e.preventDefault();
  14233. cell.nav().up();
  14234. }
  14235. }
  14236. },
  14237. navDown: function navDown(e) {
  14238. var cell = false;
  14239. if (this.table.modExists("edit")) {
  14240. cell = this.table.modules.edit.currentCell;
  14241. if (cell) {
  14242. e.preventDefault();
  14243. cell.nav().down();
  14244. }
  14245. }
  14246. },
  14247. undo: function undo(e) {
  14248. var cell = false;
  14249. if (this.table.options.history && this.table.modExists("history") && this.table.modExists("edit")) {
  14250. cell = this.table.modules.edit.currentCell;
  14251. if (!cell) {
  14252. e.preventDefault();
  14253. this.table.modules.history.undo();
  14254. }
  14255. }
  14256. },
  14257. redo: function redo(e) {
  14258. var cell = false;
  14259. if (this.table.options.history && this.table.modExists("history") && this.table.modExists("edit")) {
  14260. cell = this.table.modules.edit.currentCell;
  14261. if (!cell) {
  14262. e.preventDefault();
  14263. this.table.modules.history.redo();
  14264. }
  14265. }
  14266. },
  14267. copyToClipboard: function copyToClipboard(e) {
  14268. if (!this.table.modules.edit.currentCell) {
  14269. if (this.table.modExists("clipboard", true)) {
  14270. this.table.modules.clipboard.copy(false, true);
  14271. }
  14272. }
  14273. }
  14274. };
  14275. Tabulator.prototype.registerModule("keybindings", Keybindings);
  14276. var Menu = function Menu(table) {
  14277. this.table = table; //hold Tabulator object
  14278. this.menuEl = false;
  14279. this.blurEvent = this.hideMenu.bind(this);
  14280. this.escEvent = this.escMenu.bind(this);
  14281. this.nestedMenuBlock = false;
  14282. };
  14283. Menu.prototype.initializeColumnHeader = function (column) {
  14284. var _this71 = this;
  14285. var headerMenuEl;
  14286. if (column.definition.headerContextMenu) {
  14287. column.getElement().addEventListener("contextmenu", this.LoadMenuEvent.bind(this, column, column.definition.headerContextMenu));
  14288. this.tapHold(column, column.definition.headerContextMenu);
  14289. }
  14290. // if(column.definition.headerClickMenu){
  14291. // column.getElement().addEventListener("click", this.LoadMenuEvent.bind(this, column, column.definition.headerClickMenu));
  14292. // }
  14293. if (column.definition.headerMenu) {
  14294. headerMenuEl = document.createElement("span");
  14295. headerMenuEl.classList.add("tabulator-header-menu-button");
  14296. headerMenuEl.innerHTML = "&vellip;";
  14297. headerMenuEl.addEventListener("click", function (e) {
  14298. var menu = typeof column.definition.headerMenu == "function" ? column.definition.headerMenu(column.getComponent(), e) : column.definition.headerMenu;
  14299. e.stopPropagation();
  14300. e.preventDefault();
  14301. _this71.loadMenu(e, column, menu);
  14302. });
  14303. column.titleElement.insertBefore(headerMenuEl, column.titleElement.firstChild);
  14304. }
  14305. };
  14306. Menu.prototype.LoadMenuEvent = function (component, menu, e) {
  14307. menu = typeof menu == "function" ? menu(component.getComponent(), e) : menu;
  14308. // if(component instanceof Cell){
  14309. // e.stopImmediatePropagation();
  14310. // }
  14311. this.loadMenu(e, component, menu);
  14312. };
  14313. Menu.prototype.tapHold = function (component, menu) {
  14314. var _this72 = this;
  14315. var element = component.getElement(),
  14316. tapHold = null,
  14317. loaded = false;
  14318. element.addEventListener("touchstart", function (e) {
  14319. clearTimeout(tapHold);
  14320. loaded = false;
  14321. tapHold = setTimeout(function () {
  14322. clearTimeout(tapHold);
  14323. tapHold = null;
  14324. loaded = true;
  14325. _this72.LoadMenuEvent(component, menu, e);
  14326. }, 1000);
  14327. }, { passive: true });
  14328. element.addEventListener("touchend", function (e) {
  14329. clearTimeout(tapHold);
  14330. tapHold = null;
  14331. if (loaded) {
  14332. e.preventDefault();
  14333. }
  14334. });
  14335. };
  14336. Menu.prototype.initializeCell = function (cell) {
  14337. if (cell.column.definition.contextMenu) {
  14338. cell.getElement().addEventListener("contextmenu", this.LoadMenuEvent.bind(this, cell, cell.column.definition.contextMenu));
  14339. this.tapHold(cell, cell.column.definition.contextMenu);
  14340. }
  14341. if (cell.column.definition.clickMenu) {
  14342. cell.getElement().addEventListener("click", this.LoadMenuEvent.bind(this, cell, cell.column.definition.clickMenu));
  14343. }
  14344. };
  14345. Menu.prototype.initializeRow = function (row) {
  14346. if (this.table.options.rowContextMenu) {
  14347. row.getElement().addEventListener("contextmenu", this.LoadMenuEvent.bind(this, row, this.table.options.rowContextMenu));
  14348. this.tapHold(row, this.table.options.rowContextMenu);
  14349. }
  14350. if (this.table.options.rowClickMenu) {
  14351. row.getElement().addEventListener("click", this.LoadMenuEvent.bind(this, row, this.table.options.rowClickMenu));
  14352. }
  14353. };
  14354. Menu.prototype.initializeGroup = function (group) {
  14355. if (this.table.options.groupContextMenu) {
  14356. group.getElement().addEventListener("contextmenu", this.LoadMenuEvent.bind(this, group, this.table.options.groupContextMenu));
  14357. this.tapHold(group, this.table.options.groupContextMenu);
  14358. }
  14359. if (this.table.options.groupClickMenu) {
  14360. group.getElement().addEventListener("click", this.LoadMenuEvent.bind(this, group, this.table.options.groupClickMenu));
  14361. }
  14362. };
  14363. Menu.prototype.loadMenu = function (e, component, menu) {
  14364. var _this73 = this;
  14365. var docHeight = Math.max(document.body.offsetHeight, window.innerHeight),
  14366. touch = !(e instanceof MouseEvent);
  14367. if (!touch) {
  14368. e.preventDefault();
  14369. }
  14370. //abort if no menu set
  14371. if (!menu || !menu.length) {
  14372. return;
  14373. }
  14374. if (this.nestedMenuBlock) {
  14375. //abort if child menu already open
  14376. if (this.isOpen()) {
  14377. return;
  14378. }
  14379. } else {
  14380. this.nestedMenuBlock = setTimeout(function () {
  14381. _this73.nestedMenuBlock = false;
  14382. }, 100);
  14383. }
  14384. this.hideMenu();
  14385. this.menuEl = document.createElement("div");
  14386. this.menuEl.classList.add("tabulator-menu");
  14387. menu.forEach(function (item) {
  14388. var itemEl = document.createElement("div");
  14389. var label = item.label;
  14390. var disabled = item.disabled;
  14391. if (item.separator) {
  14392. itemEl.classList.add("tabulator-menu-separator");
  14393. } else {
  14394. itemEl.classList.add("tabulator-menu-item");
  14395. if (typeof label == "function") {
  14396. label = label(component.getComponent());
  14397. }
  14398. if (label instanceof Node) {
  14399. itemEl.appendChild(label);
  14400. } else {
  14401. itemEl.innerHTML = label;
  14402. }
  14403. if (typeof disabled == "function") {
  14404. disabled = disabled(component.getComponent());
  14405. }
  14406. if (disabled) {
  14407. itemEl.classList.add("tabulator-menu-item-disabled");
  14408. itemEl.addEventListener("click", function (e) {
  14409. e.stopPropagation();
  14410. });
  14411. } else {
  14412. itemEl.addEventListener("click", function (e) {
  14413. _this73.hideMenu();
  14414. item.action(e, component.getComponent());
  14415. });
  14416. }
  14417. }
  14418. _this73.menuEl.appendChild(itemEl);
  14419. });
  14420. this.menuEl.style.top = (touch ? e.touches[0].pageY : e.pageY) + "px";
  14421. this.menuEl.style.left = (touch ? e.touches[0].pageX : e.pageX) + "px";
  14422. setTimeout(function () {
  14423. _this73.table.rowManager.element.addEventListener("scroll", _this73.blurEvent);
  14424. document.body.addEventListener("click", _this73.blurEvent);
  14425. document.body.addEventListener("contextmenu", _this73.blurEvent);
  14426. document.body.addEventListener("keydown", _this73.escEvent);
  14427. }, 100);
  14428. document.body.appendChild(this.menuEl);
  14429. //move menu to start on right edge if it is too close to the edge of the screen
  14430. if (e.pageX + this.menuEl.offsetWidth >= document.body.offsetWidth) {
  14431. this.menuEl.style.left = "";
  14432. this.menuEl.style.right = document.body.offsetWidth - e.pageX + "px";
  14433. }
  14434. //move menu to start on bottom edge if it is too close to the edge of the screen
  14435. if (e.pageY + this.menuEl.offsetHeight >= docHeight) {
  14436. this.menuEl.style.top = "";
  14437. this.menuEl.style.bottom = docHeight - e.pageY + "px";
  14438. }
  14439. };
  14440. Menu.prototype.isOpen = function () {
  14441. return !!this.menuEl.parentNode;
  14442. };
  14443. Menu.prototype.escMenu = function (e) {
  14444. if (e.keyCode == 27) {
  14445. this.hideMenu();
  14446. }
  14447. };
  14448. Menu.prototype.hideMenu = function () {
  14449. if (this.menuEl.parentNode) {
  14450. this.menuEl.parentNode.removeChild(this.menuEl);
  14451. }
  14452. if (this.escEvent) {
  14453. document.body.removeEventListener("keydown", this.escEvent);
  14454. }
  14455. if (this.blurEvent) {
  14456. document.body.removeEventListener("click", this.blurEvent);
  14457. document.body.removeEventListener("contextmenu", this.blurEvent);
  14458. this.table.rowManager.element.removeEventListener("scroll", this.blurEvent);
  14459. }
  14460. };
  14461. //default accessors
  14462. Menu.prototype.menus = {};
  14463. Tabulator.prototype.registerModule("menu", Menu);
  14464. var MoveColumns = function MoveColumns(table) {
  14465. this.table = table; //hold Tabulator object
  14466. this.placeholderElement = this.createPlaceholderElement();
  14467. this.hoverElement = false; //floating column header element
  14468. this.checkTimeout = false; //click check timeout holder
  14469. this.checkPeriod = 250; //period to wait on mousedown to consider this a move and not a click
  14470. this.moving = false; //currently moving column
  14471. this.toCol = false; //destination column
  14472. this.toColAfter = false; //position of moving column relative to the desitnation column
  14473. this.startX = 0; //starting position within header element
  14474. this.autoScrollMargin = 40; //auto scroll on edge when within margin
  14475. this.autoScrollStep = 5; //auto scroll distance in pixels
  14476. this.autoScrollTimeout = false; //auto scroll timeout
  14477. this.touchMove = false;
  14478. this.moveHover = this.moveHover.bind(this);
  14479. this.endMove = this.endMove.bind(this);
  14480. };
  14481. MoveColumns.prototype.createPlaceholderElement = function () {
  14482. var el = document.createElement("div");
  14483. el.classList.add("tabulator-col");
  14484. el.classList.add("tabulator-col-placeholder");
  14485. return el;
  14486. };
  14487. MoveColumns.prototype.initializeColumn = function (column) {
  14488. var self = this,
  14489. config = {},
  14490. colEl;
  14491. if (!column.modules.frozen) {
  14492. colEl = column.getElement();
  14493. config.mousemove = function (e) {
  14494. if (column.parent === self.moving.parent) {
  14495. if ((self.touchMove ? e.touches[0].pageX : e.pageX) - Tabulator.prototype.helpers.elOffset(colEl).left + self.table.columnManager.element.scrollLeft > column.getWidth() / 2) {
  14496. if (self.toCol !== column || !self.toColAfter) {
  14497. colEl.parentNode.insertBefore(self.placeholderElement, colEl.nextSibling);
  14498. self.moveColumn(column, true);
  14499. }
  14500. } else {
  14501. if (self.toCol !== column || self.toColAfter) {
  14502. colEl.parentNode.insertBefore(self.placeholderElement, colEl);
  14503. self.moveColumn(column, false);
  14504. }
  14505. }
  14506. }
  14507. }.bind(self);
  14508. colEl.addEventListener("mousedown", function (e) {
  14509. self.touchMove = false;
  14510. if (e.which === 1) {
  14511. self.checkTimeout = setTimeout(function () {
  14512. self.startMove(e, column);
  14513. }, self.checkPeriod);
  14514. }
  14515. });
  14516. colEl.addEventListener("mouseup", function (e) {
  14517. if (e.which === 1) {
  14518. if (self.checkTimeout) {
  14519. clearTimeout(self.checkTimeout);
  14520. }
  14521. }
  14522. });
  14523. self.bindTouchEvents(column);
  14524. }
  14525. column.modules.moveColumn = config;
  14526. };
  14527. MoveColumns.prototype.bindTouchEvents = function (column) {
  14528. var self = this,
  14529. colEl = column.getElement(),
  14530. startXMove = false,
  14531. //shifting center position of the cell
  14532. dir = false,
  14533. currentCol,
  14534. nextCol,
  14535. prevCol,
  14536. nextColWidth,
  14537. prevColWidth,
  14538. nextColWidthLast,
  14539. prevColWidthLast;
  14540. colEl.addEventListener("touchstart", function (e) {
  14541. self.checkTimeout = setTimeout(function () {
  14542. self.touchMove = true;
  14543. currentCol = column;
  14544. nextCol = column.nextColumn();
  14545. nextColWidth = nextCol ? nextCol.getWidth() / 2 : 0;
  14546. prevCol = column.prevColumn();
  14547. prevColWidth = prevCol ? prevCol.getWidth() / 2 : 0;
  14548. nextColWidthLast = 0;
  14549. prevColWidthLast = 0;
  14550. startXMove = false;
  14551. self.startMove(e, column);
  14552. }, self.checkPeriod);
  14553. }, { passive: true });
  14554. colEl.addEventListener("touchmove", function (e) {
  14555. var halfCol, diff, moveToCol;
  14556. if (self.moving) {
  14557. self.moveHover(e);
  14558. if (!startXMove) {
  14559. startXMove = e.touches[0].pageX;
  14560. }
  14561. diff = e.touches[0].pageX - startXMove;
  14562. if (diff > 0) {
  14563. if (nextCol && diff - nextColWidthLast > nextColWidth) {
  14564. moveToCol = nextCol;
  14565. if (moveToCol !== column) {
  14566. startXMove = e.touches[0].pageX;
  14567. moveToCol.getElement().parentNode.insertBefore(self.placeholderElement, moveToCol.getElement().nextSibling);
  14568. self.moveColumn(moveToCol, true);
  14569. }
  14570. }
  14571. } else {
  14572. if (prevCol && -diff - prevColWidthLast > prevColWidth) {
  14573. moveToCol = prevCol;
  14574. if (moveToCol !== column) {
  14575. startXMove = e.touches[0].pageX;
  14576. moveToCol.getElement().parentNode.insertBefore(self.placeholderElement, moveToCol.getElement());
  14577. self.moveColumn(moveToCol, false);
  14578. }
  14579. }
  14580. }
  14581. if (moveToCol) {
  14582. currentCol = moveToCol;
  14583. nextCol = moveToCol.nextColumn();
  14584. nextColWidthLast = nextColWidth;
  14585. nextColWidth = nextCol ? nextCol.getWidth() / 2 : 0;
  14586. prevCol = moveToCol.prevColumn();
  14587. prevColWidthLast = prevColWidth;
  14588. prevColWidth = prevCol ? prevCol.getWidth() / 2 : 0;
  14589. }
  14590. }
  14591. }, { passive: true });
  14592. colEl.addEventListener("touchend", function (e) {
  14593. if (self.checkTimeout) {
  14594. clearTimeout(self.checkTimeout);
  14595. }
  14596. if (self.moving) {
  14597. self.endMove(e);
  14598. }
  14599. });
  14600. };
  14601. MoveColumns.prototype.startMove = function (e, column) {
  14602. var element = column.getElement();
  14603. this.moving = column;
  14604. this.startX = (this.touchMove ? e.touches[0].pageX : e.pageX) - Tabulator.prototype.helpers.elOffset(element).left;
  14605. this.table.element.classList.add("tabulator-block-select");
  14606. //create placeholder
  14607. this.placeholderElement.style.width = column.getWidth() + "px";
  14608. this.placeholderElement.style.height = column.getHeight() + "px";
  14609. element.parentNode.insertBefore(this.placeholderElement, element);
  14610. element.parentNode.removeChild(element);
  14611. //create hover element
  14612. this.hoverElement = element.cloneNode(true);
  14613. this.hoverElement.classList.add("tabulator-moving");
  14614. this.table.columnManager.getElement().appendChild(this.hoverElement);
  14615. this.hoverElement.style.left = "0";
  14616. this.hoverElement.style.bottom = "0";
  14617. if (!this.touchMove) {
  14618. this._bindMouseMove();
  14619. document.body.addEventListener("mousemove", this.moveHover);
  14620. document.body.addEventListener("mouseup", this.endMove);
  14621. }
  14622. this.moveHover(e);
  14623. };
  14624. MoveColumns.prototype._bindMouseMove = function () {
  14625. this.table.columnManager.columnsByIndex.forEach(function (column) {
  14626. if (column.modules.moveColumn.mousemove) {
  14627. column.getElement().addEventListener("mousemove", column.modules.moveColumn.mousemove);
  14628. }
  14629. });
  14630. };
  14631. MoveColumns.prototype._unbindMouseMove = function () {
  14632. this.table.columnManager.columnsByIndex.forEach(function (column) {
  14633. if (column.modules.moveColumn.mousemove) {
  14634. column.getElement().removeEventListener("mousemove", column.modules.moveColumn.mousemove);
  14635. }
  14636. });
  14637. };
  14638. MoveColumns.prototype.moveColumn = function (column, after) {
  14639. var movingCells = this.moving.getCells();
  14640. this.toCol = column;
  14641. this.toColAfter = after;
  14642. if (after) {
  14643. column.getCells().forEach(function (cell, i) {
  14644. var cellEl = cell.getElement();
  14645. cellEl.parentNode.insertBefore(movingCells[i].getElement(), cellEl.nextSibling);
  14646. });
  14647. } else {
  14648. column.getCells().forEach(function (cell, i) {
  14649. var cellEl = cell.getElement();
  14650. cellEl.parentNode.insertBefore(movingCells[i].getElement(), cellEl);
  14651. });
  14652. }
  14653. };
  14654. MoveColumns.prototype.endMove = function (e) {
  14655. if (e.which === 1 || this.touchMove) {
  14656. this._unbindMouseMove();
  14657. this.placeholderElement.parentNode.insertBefore(this.moving.getElement(), this.placeholderElement.nextSibling);
  14658. this.placeholderElement.parentNode.removeChild(this.placeholderElement);
  14659. this.hoverElement.parentNode.removeChild(this.hoverElement);
  14660. this.table.element.classList.remove("tabulator-block-select");
  14661. if (this.toCol) {
  14662. this.table.columnManager.moveColumnActual(this.moving, this.toCol, this.toColAfter);
  14663. }
  14664. this.moving = false;
  14665. this.toCol = false;
  14666. this.toColAfter = false;
  14667. if (!this.touchMove) {
  14668. document.body.removeEventListener("mousemove", this.moveHover);
  14669. document.body.removeEventListener("mouseup", this.endMove);
  14670. }
  14671. }
  14672. };
  14673. MoveColumns.prototype.moveHover = function (e) {
  14674. var self = this,
  14675. columnHolder = self.table.columnManager.getElement(),
  14676. scrollLeft = columnHolder.scrollLeft,
  14677. xPos = (self.touchMove ? e.touches[0].pageX : e.pageX) - Tabulator.prototype.helpers.elOffset(columnHolder).left + scrollLeft,
  14678. scrollPos;
  14679. self.hoverElement.style.left = xPos - self.startX + "px";
  14680. if (xPos - scrollLeft < self.autoScrollMargin) {
  14681. if (!self.autoScrollTimeout) {
  14682. self.autoScrollTimeout = setTimeout(function () {
  14683. scrollPos = Math.max(0, scrollLeft - 5);
  14684. self.table.rowManager.getElement().scrollLeft = scrollPos;
  14685. self.autoScrollTimeout = false;
  14686. }, 1);
  14687. }
  14688. }
  14689. if (scrollLeft + columnHolder.clientWidth - xPos < self.autoScrollMargin) {
  14690. if (!self.autoScrollTimeout) {
  14691. self.autoScrollTimeout = setTimeout(function () {
  14692. scrollPos = Math.min(columnHolder.clientWidth, scrollLeft + 5);
  14693. self.table.rowManager.getElement().scrollLeft = scrollPos;
  14694. self.autoScrollTimeout = false;
  14695. }, 1);
  14696. }
  14697. }
  14698. };
  14699. Tabulator.prototype.registerModule("moveColumn", MoveColumns);
  14700. var MoveRows = function MoveRows(table) {
  14701. this.table = table; //hold Tabulator object
  14702. this.placeholderElement = this.createPlaceholderElement();
  14703. this.hoverElement = false; //floating row header element
  14704. this.checkTimeout = false; //click check timeout holder
  14705. this.checkPeriod = 150; //period to wait on mousedown to consider this a move and not a click
  14706. this.moving = false; //currently moving row
  14707. this.toRow = false; //destination row
  14708. this.toRowAfter = false; //position of moving row relative to the desitnation row
  14709. this.hasHandle = false; //row has handle instead of fully movable row
  14710. this.startY = 0; //starting Y position within header element
  14711. this.startX = 0; //starting X position within header element
  14712. this.moveHover = this.moveHover.bind(this);
  14713. this.endMove = this.endMove.bind(this);
  14714. this.tableRowDropEvent = false;
  14715. this.touchMove = false;
  14716. this.connection = false;
  14717. this.connectionSelectorsTables = false;
  14718. this.connectionSelectorsElements = false;
  14719. this.connectionElements = [];
  14720. this.connections = [];
  14721. this.connectedTable = false;
  14722. this.connectedRow = false;
  14723. };
  14724. MoveRows.prototype.createPlaceholderElement = function () {
  14725. var el = document.createElement("div");
  14726. el.classList.add("tabulator-row");
  14727. el.classList.add("tabulator-row-placeholder");
  14728. return el;
  14729. };
  14730. MoveRows.prototype.initialize = function (handle) {
  14731. this.connectionSelectorsTables = this.table.options.movableRowsConnectedTables;
  14732. this.connectionSelectorsElements = this.table.options.movableRowsConnectedElements;
  14733. this.connection = this.connectionSelectorsTables || this.connectionSelectorsElements;
  14734. };
  14735. MoveRows.prototype.setHandle = function (handle) {
  14736. this.hasHandle = handle;
  14737. };
  14738. MoveRows.prototype.initializeGroupHeader = function (group) {
  14739. var self = this,
  14740. config = {},
  14741. rowEl;
  14742. //inter table drag drop
  14743. config.mouseup = function (e) {
  14744. self.tableRowDrop(e, row);
  14745. }.bind(self);
  14746. //same table drag drop
  14747. config.mousemove = function (e) {
  14748. if (e.pageY - Tabulator.prototype.helpers.elOffset(group.element).top + self.table.rowManager.element.scrollTop > group.getHeight() / 2) {
  14749. if (self.toRow !== group || !self.toRowAfter) {
  14750. var rowEl = group.getElement();
  14751. rowEl.parentNode.insertBefore(self.placeholderElement, rowEl.nextSibling);
  14752. self.moveRow(group, true);
  14753. }
  14754. } else {
  14755. if (self.toRow !== group || self.toRowAfter) {
  14756. var rowEl = group.getElement();
  14757. if (rowEl.previousSibling) {
  14758. rowEl.parentNode.insertBefore(self.placeholderElement, rowEl);
  14759. self.moveRow(group, false);
  14760. }
  14761. }
  14762. }
  14763. }.bind(self);
  14764. group.modules.moveRow = config;
  14765. };
  14766. MoveRows.prototype.initializeRow = function (row) {
  14767. var self = this,
  14768. config = {},
  14769. rowEl;
  14770. //inter table drag drop
  14771. config.mouseup = function (e) {
  14772. self.tableRowDrop(e, row);
  14773. }.bind(self);
  14774. //same table drag drop
  14775. config.mousemove = function (e) {
  14776. if (e.pageY - Tabulator.prototype.helpers.elOffset(row.element).top + self.table.rowManager.element.scrollTop > row.getHeight() / 2) {
  14777. if (self.toRow !== row || !self.toRowAfter) {
  14778. var rowEl = row.getElement();
  14779. rowEl.parentNode.insertBefore(self.placeholderElement, rowEl.nextSibling);
  14780. self.moveRow(row, true);
  14781. }
  14782. } else {
  14783. if (self.toRow !== row || self.toRowAfter) {
  14784. var rowEl = row.getElement();
  14785. rowEl.parentNode.insertBefore(self.placeholderElement, rowEl);
  14786. self.moveRow(row, false);
  14787. }
  14788. }
  14789. }.bind(self);
  14790. if (!this.hasHandle) {
  14791. rowEl = row.getElement();
  14792. rowEl.addEventListener("mousedown", function (e) {
  14793. if (e.which === 1) {
  14794. self.checkTimeout = setTimeout(function () {
  14795. self.startMove(e, row);
  14796. }, self.checkPeriod);
  14797. }
  14798. });
  14799. rowEl.addEventListener("mouseup", function (e) {
  14800. if (e.which === 1) {
  14801. if (self.checkTimeout) {
  14802. clearTimeout(self.checkTimeout);
  14803. }
  14804. }
  14805. });
  14806. this.bindTouchEvents(row, row.getElement());
  14807. }
  14808. row.modules.moveRow = config;
  14809. };
  14810. MoveRows.prototype.initializeCell = function (cell) {
  14811. var self = this,
  14812. cellEl = cell.getElement();
  14813. cellEl.addEventListener("mousedown", function (e) {
  14814. if (e.which === 1) {
  14815. self.checkTimeout = setTimeout(function () {
  14816. self.startMove(e, cell.row);
  14817. }, self.checkPeriod);
  14818. }
  14819. });
  14820. cellEl.addEventListener("mouseup", function (e) {
  14821. if (e.which === 1) {
  14822. if (self.checkTimeout) {
  14823. clearTimeout(self.checkTimeout);
  14824. }
  14825. }
  14826. });
  14827. this.bindTouchEvents(cell.row, cell.getElement());
  14828. };
  14829. MoveRows.prototype.bindTouchEvents = function (row, element) {
  14830. var self = this,
  14831. startYMove = false,
  14832. //shifting center position of the cell
  14833. dir = false,
  14834. currentRow,
  14835. nextRow,
  14836. prevRow,
  14837. nextRowHeight,
  14838. prevRowHeight,
  14839. nextRowHeightLast,
  14840. prevRowHeightLast;
  14841. element.addEventListener("touchstart", function (e) {
  14842. self.checkTimeout = setTimeout(function () {
  14843. self.touchMove = true;
  14844. currentRow = row;
  14845. nextRow = row.nextRow();
  14846. nextRowHeight = nextRow ? nextRow.getHeight() / 2 : 0;
  14847. prevRow = row.prevRow();
  14848. prevRowHeight = prevRow ? prevRow.getHeight() / 2 : 0;
  14849. nextRowHeightLast = 0;
  14850. prevRowHeightLast = 0;
  14851. startYMove = false;
  14852. self.startMove(e, row);
  14853. }, self.checkPeriod);
  14854. }, { passive: true });
  14855. this.moving, this.toRow, this.toRowAfter;
  14856. element.addEventListener("touchmove", function (e) {
  14857. var halfCol, diff, moveToRow;
  14858. if (self.moving) {
  14859. e.preventDefault();
  14860. self.moveHover(e);
  14861. if (!startYMove) {
  14862. startYMove = e.touches[0].pageY;
  14863. }
  14864. diff = e.touches[0].pageY - startYMove;
  14865. if (diff > 0) {
  14866. if (nextRow && diff - nextRowHeightLast > nextRowHeight) {
  14867. moveToRow = nextRow;
  14868. if (moveToRow !== row) {
  14869. startYMove = e.touches[0].pageY;
  14870. moveToRow.getElement().parentNode.insertBefore(self.placeholderElement, moveToRow.getElement().nextSibling);
  14871. self.moveRow(moveToRow, true);
  14872. }
  14873. }
  14874. } else {
  14875. if (prevRow && -diff - prevRowHeightLast > prevRowHeight) {
  14876. moveToRow = prevRow;
  14877. if (moveToRow !== row) {
  14878. startYMove = e.touches[0].pageY;
  14879. moveToRow.getElement().parentNode.insertBefore(self.placeholderElement, moveToRow.getElement());
  14880. self.moveRow(moveToRow, false);
  14881. }
  14882. }
  14883. }
  14884. if (moveToRow) {
  14885. currentRow = moveToRow;
  14886. nextRow = moveToRow.nextRow();
  14887. nextRowHeightLast = nextRowHeight;
  14888. nextRowHeight = nextRow ? nextRow.getHeight() / 2 : 0;
  14889. prevRow = moveToRow.prevRow();
  14890. prevRowHeightLast = prevRowHeight;
  14891. prevRowHeight = prevRow ? prevRow.getHeight() / 2 : 0;
  14892. }
  14893. }
  14894. });
  14895. element.addEventListener("touchend", function (e) {
  14896. if (self.checkTimeout) {
  14897. clearTimeout(self.checkTimeout);
  14898. }
  14899. if (self.moving) {
  14900. self.endMove(e);
  14901. self.touchMove = false;
  14902. }
  14903. });
  14904. };
  14905. MoveRows.prototype._bindMouseMove = function () {
  14906. var self = this;
  14907. self.table.rowManager.getDisplayRows().forEach(function (row) {
  14908. if ((row.type === "row" || row.type === "group") && row.modules.moveRow.mousemove) {
  14909. row.getElement().addEventListener("mousemove", row.modules.moveRow.mousemove);
  14910. }
  14911. });
  14912. };
  14913. MoveRows.prototype._unbindMouseMove = function () {
  14914. var self = this;
  14915. self.table.rowManager.getDisplayRows().forEach(function (row) {
  14916. if ((row.type === "row" || row.type === "group") && row.modules.moveRow.mousemove) {
  14917. row.getElement().removeEventListener("mousemove", row.modules.moveRow.mousemove);
  14918. }
  14919. });
  14920. };
  14921. MoveRows.prototype.startMove = function (e, row) {
  14922. var element = row.getElement();
  14923. this.setStartPosition(e, row);
  14924. this.moving = row;
  14925. this.table.element.classList.add("tabulator-block-select");
  14926. //create placeholder
  14927. this.placeholderElement.style.width = row.getWidth() + "px";
  14928. this.placeholderElement.style.height = row.getHeight() + "px";
  14929. if (!this.connection) {
  14930. element.parentNode.insertBefore(this.placeholderElement, element);
  14931. element.parentNode.removeChild(element);
  14932. } else {
  14933. this.table.element.classList.add("tabulator-movingrow-sending");
  14934. this.connectToTables(row);
  14935. }
  14936. //create hover element
  14937. this.hoverElement = element.cloneNode(true);
  14938. this.hoverElement.classList.add("tabulator-moving");
  14939. if (this.connection) {
  14940. document.body.appendChild(this.hoverElement);
  14941. this.hoverElement.style.left = "0";
  14942. this.hoverElement.style.top = "0";
  14943. this.hoverElement.style.width = this.table.element.clientWidth + "px";
  14944. this.hoverElement.style.whiteSpace = "nowrap";
  14945. this.hoverElement.style.overflow = "hidden";
  14946. this.hoverElement.style.pointerEvents = "none";
  14947. } else {
  14948. this.table.rowManager.getTableElement().appendChild(this.hoverElement);
  14949. this.hoverElement.style.left = "0";
  14950. this.hoverElement.style.top = "0";
  14951. this._bindMouseMove();
  14952. }
  14953. document.body.addEventListener("mousemove", this.moveHover);
  14954. document.body.addEventListener("mouseup", this.endMove);
  14955. this.moveHover(e);
  14956. };
  14957. MoveRows.prototype.setStartPosition = function (e, row) {
  14958. var pageX = this.touchMove ? e.touches[0].pageX : e.pageX,
  14959. pageY = this.touchMove ? e.touches[0].pageY : e.pageY,
  14960. element,
  14961. position;
  14962. element = row.getElement();
  14963. if (this.connection) {
  14964. position = element.getBoundingClientRect();
  14965. this.startX = position.left - pageX + window.pageXOffset;
  14966. this.startY = position.top - pageY + window.pageYOffset;
  14967. } else {
  14968. this.startY = pageY - element.getBoundingClientRect().top;
  14969. }
  14970. };
  14971. MoveRows.prototype.endMove = function (e) {
  14972. if (!e || e.which === 1 || this.touchMove) {
  14973. this._unbindMouseMove();
  14974. if (!this.connection) {
  14975. this.placeholderElement.parentNode.insertBefore(this.moving.getElement(), this.placeholderElement.nextSibling);
  14976. this.placeholderElement.parentNode.removeChild(this.placeholderElement);
  14977. }
  14978. this.hoverElement.parentNode.removeChild(this.hoverElement);
  14979. this.table.element.classList.remove("tabulator-block-select");
  14980. if (this.toRow) {
  14981. this.table.rowManager.moveRow(this.moving, this.toRow, this.toRowAfter);
  14982. }
  14983. this.moving = false;
  14984. this.toRow = false;
  14985. this.toRowAfter = false;
  14986. document.body.removeEventListener("mousemove", this.moveHover);
  14987. document.body.removeEventListener("mouseup", this.endMove);
  14988. if (this.connection) {
  14989. this.table.element.classList.remove("tabulator-movingrow-sending");
  14990. this.disconnectFromTables();
  14991. }
  14992. }
  14993. };
  14994. MoveRows.prototype.moveRow = function (row, after) {
  14995. this.toRow = row;
  14996. this.toRowAfter = after;
  14997. };
  14998. MoveRows.prototype.moveHover = function (e) {
  14999. if (this.connection) {
  15000. this.moveHoverConnections.call(this, e);
  15001. } else {
  15002. this.moveHoverTable.call(this, e);
  15003. }
  15004. };
  15005. MoveRows.prototype.moveHoverTable = function (e) {
  15006. var rowHolder = this.table.rowManager.getElement(),
  15007. scrollTop = rowHolder.scrollTop,
  15008. yPos = (this.touchMove ? e.touches[0].pageY : e.pageY) - rowHolder.getBoundingClientRect().top + scrollTop,
  15009. scrollPos;
  15010. this.hoverElement.style.top = yPos - this.startY + "px";
  15011. };
  15012. MoveRows.prototype.moveHoverConnections = function (e) {
  15013. this.hoverElement.style.left = this.startX + (this.touchMove ? e.touches[0].pageX : e.pageX) + "px";
  15014. this.hoverElement.style.top = this.startY + (this.touchMove ? e.touches[0].pageY : e.pageY) + "px";
  15015. };
  15016. MoveRows.prototype.elementRowDrop = function (e, element, row) {
  15017. if (this.table.options.movableRowsElementDrop) {
  15018. this.table.options.movableRowsElementDrop(e, element, row ? row.getComponent() : false);
  15019. }
  15020. };
  15021. //establish connection with other tables
  15022. MoveRows.prototype.connectToTables = function (row) {
  15023. var _this74 = this;
  15024. var connectionTables;
  15025. if (this.connectionSelectorsTables) {
  15026. connectionTables = this.table.modules.comms.getConnections(this.connectionSelectorsTables);
  15027. this.table.options.movableRowsSendingStart.call(this.table, connectionTables);
  15028. this.table.modules.comms.send(this.connectionSelectorsTables, "moveRow", "connect", {
  15029. row: row
  15030. });
  15031. }
  15032. if (this.connectionSelectorsElements) {
  15033. this.connectionElements = [];
  15034. if (!Array.isArray(this.connectionSelectorsElements)) {
  15035. this.connectionSelectorsElements = [this.connectionSelectorsElements];
  15036. }
  15037. this.connectionSelectorsElements.forEach(function (query) {
  15038. if (typeof query === "string") {
  15039. _this74.connectionElements = _this74.connectionElements.concat(Array.prototype.slice.call(document.querySelectorAll(query)));
  15040. } else {
  15041. _this74.connectionElements.push(query);
  15042. }
  15043. });
  15044. this.connectionElements.forEach(function (element) {
  15045. var dropEvent = function dropEvent(e) {
  15046. _this74.elementRowDrop(e, element, _this74.moving);
  15047. };
  15048. element.addEventListener("mouseup", dropEvent);
  15049. element.tabulatorElementDropEvent = dropEvent;
  15050. element.classList.add("tabulator-movingrow-receiving");
  15051. });
  15052. }
  15053. };
  15054. //disconnect from other tables
  15055. MoveRows.prototype.disconnectFromTables = function () {
  15056. var connectionTables;
  15057. if (this.connectionSelectorsTables) {
  15058. connectionTables = this.table.modules.comms.getConnections(this.connectionSelectorsTables);
  15059. this.table.options.movableRowsSendingStop.call(this.table, connectionTables);
  15060. this.table.modules.comms.send(this.connectionSelectorsTables, "moveRow", "disconnect");
  15061. }
  15062. this.connectionElements.forEach(function (element) {
  15063. element.classList.remove("tabulator-movingrow-receiving");
  15064. element.removeEventListener("mouseup", element.tabulatorElementDropEvent);
  15065. delete element.tabulatorElementDropEvent;
  15066. });
  15067. };
  15068. //accept incomming connection
  15069. MoveRows.prototype.connect = function (table, row) {
  15070. var self = this;
  15071. if (!this.connectedTable) {
  15072. this.connectedTable = table;
  15073. this.connectedRow = row;
  15074. this.table.element.classList.add("tabulator-movingrow-receiving");
  15075. self.table.rowManager.getDisplayRows().forEach(function (row) {
  15076. if (row.type === "row" && row.modules.moveRow && row.modules.moveRow.mouseup) {
  15077. row.getElement().addEventListener("mouseup", row.modules.moveRow.mouseup);
  15078. }
  15079. });
  15080. self.tableRowDropEvent = self.tableRowDrop.bind(self);
  15081. self.table.element.addEventListener("mouseup", self.tableRowDropEvent);
  15082. this.table.options.movableRowsReceivingStart.call(this.table, row, table);
  15083. return true;
  15084. } else {
  15085. console.warn("Move Row Error - Table cannot accept connection, already connected to table:", this.connectedTable);
  15086. return false;
  15087. }
  15088. };
  15089. //close incomming connection
  15090. MoveRows.prototype.disconnect = function (table) {
  15091. var self = this;
  15092. if (table === this.connectedTable) {
  15093. this.connectedTable = false;
  15094. this.connectedRow = false;
  15095. this.table.element.classList.remove("tabulator-movingrow-receiving");
  15096. self.table.rowManager.getDisplayRows().forEach(function (row) {
  15097. if (row.type === "row" && row.modules.moveRow && row.modules.moveRow.mouseup) {
  15098. row.getElement().removeEventListener("mouseup", row.modules.moveRow.mouseup);
  15099. }
  15100. });
  15101. self.table.element.removeEventListener("mouseup", self.tableRowDropEvent);
  15102. this.table.options.movableRowsReceivingStop.call(this.table, table);
  15103. } else {
  15104. console.warn("Move Row Error - trying to disconnect from non connected table");
  15105. }
  15106. };
  15107. MoveRows.prototype.dropComplete = function (table, row, success) {
  15108. var sender = false;
  15109. if (success) {
  15110. switch (_typeof(this.table.options.movableRowsSender)) {
  15111. case "string":
  15112. sender = this.senders[this.table.options.movableRowsSender];
  15113. break;
  15114. case "function":
  15115. sender = this.table.options.movableRowsSender;
  15116. break;
  15117. }
  15118. if (sender) {
  15119. sender.call(this, this.moving.getComponent(), row ? row.getComponent() : undefined, table);
  15120. } else {
  15121. if (this.table.options.movableRowsSender) {
  15122. console.warn("Mover Row Error - no matching sender found:", this.table.options.movableRowsSender);
  15123. }
  15124. }
  15125. this.table.options.movableRowsSent.call(this.table, this.moving.getComponent(), row ? row.getComponent() : undefined, table);
  15126. } else {
  15127. this.table.options.movableRowsSentFailed.call(this.table, this.moving.getComponent(), row ? row.getComponent() : undefined, table);
  15128. }
  15129. this.endMove();
  15130. };
  15131. MoveRows.prototype.tableRowDrop = function (e, row) {
  15132. var receiver = false,
  15133. success = false;
  15134. console.trace("drop");
  15135. e.stopImmediatePropagation();
  15136. switch (_typeof(this.table.options.movableRowsReceiver)) {
  15137. case "string":
  15138. receiver = this.receivers[this.table.options.movableRowsReceiver];
  15139. break;
  15140. case "function":
  15141. receiver = this.table.options.movableRowsReceiver;
  15142. break;
  15143. }
  15144. if (receiver) {
  15145. success = receiver.call(this, this.connectedRow.getComponent(), row ? row.getComponent() : undefined, this.connectedTable);
  15146. } else {
  15147. console.warn("Mover Row Error - no matching receiver found:", this.table.options.movableRowsReceiver);
  15148. }
  15149. if (success) {
  15150. this.table.options.movableRowsReceived.call(this.table, this.connectedRow.getComponent(), row ? row.getComponent() : undefined, this.connectedTable);
  15151. } else {
  15152. this.table.options.movableRowsReceivedFailed.call(this.table, this.connectedRow.getComponent(), row ? row.getComponent() : undefined, this.connectedTable);
  15153. }
  15154. this.table.modules.comms.send(this.connectedTable, "moveRow", "dropcomplete", {
  15155. row: row,
  15156. success: success
  15157. });
  15158. };
  15159. MoveRows.prototype.receivers = {
  15160. insert: function insert(fromRow, toRow, fromTable) {
  15161. this.table.addRow(fromRow.getData(), undefined, toRow);
  15162. return true;
  15163. },
  15164. add: function add(fromRow, toRow, fromTable) {
  15165. this.table.addRow(fromRow.getData());
  15166. return true;
  15167. },
  15168. update: function update(fromRow, toRow, fromTable) {
  15169. if (toRow) {
  15170. toRow.update(fromRow.getData());
  15171. return true;
  15172. }
  15173. return false;
  15174. },
  15175. replace: function replace(fromRow, toRow, fromTable) {
  15176. if (toRow) {
  15177. this.table.addRow(fromRow.getData(), undefined, toRow);
  15178. toRow.delete();
  15179. return true;
  15180. }
  15181. return false;
  15182. }
  15183. };
  15184. MoveRows.prototype.senders = {
  15185. delete: function _delete(fromRow, toRow, toTable) {
  15186. fromRow.delete();
  15187. }
  15188. };
  15189. MoveRows.prototype.commsReceived = function (table, action, data) {
  15190. switch (action) {
  15191. case "connect":
  15192. return this.connect(table, data.row);
  15193. break;
  15194. case "disconnect":
  15195. return this.disconnect(table);
  15196. break;
  15197. case "dropcomplete":
  15198. return this.dropComplete(table, data.row, data.success);
  15199. break;
  15200. }
  15201. };
  15202. Tabulator.prototype.registerModule("moveRow", MoveRows);
  15203. var Mutator = function Mutator(table) {
  15204. this.table = table; //hold Tabulator object
  15205. this.allowedTypes = ["", "data", "edit", "clipboard"]; //list of muatation types
  15206. this.enabled = true;
  15207. };
  15208. //initialize column mutator
  15209. Mutator.prototype.initializeColumn = function (column) {
  15210. var self = this,
  15211. match = false,
  15212. config = {};
  15213. this.allowedTypes.forEach(function (type) {
  15214. var key = "mutator" + (type.charAt(0).toUpperCase() + type.slice(1)),
  15215. mutator;
  15216. if (column.definition[key]) {
  15217. mutator = self.lookupMutator(column.definition[key]);
  15218. if (mutator) {
  15219. match = true;
  15220. config[key] = {
  15221. mutator: mutator,
  15222. params: column.definition[key + "Params"] || {}
  15223. };
  15224. }
  15225. }
  15226. });
  15227. if (match) {
  15228. column.modules.mutate = config;
  15229. }
  15230. };
  15231. Mutator.prototype.lookupMutator = function (value) {
  15232. var mutator = false;
  15233. //set column mutator
  15234. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  15235. case "string":
  15236. if (this.mutators[value]) {
  15237. mutator = this.mutators[value];
  15238. } else {
  15239. console.warn("Mutator Error - No such mutator found, ignoring: ", value);
  15240. }
  15241. break;
  15242. case "function":
  15243. mutator = value;
  15244. break;
  15245. }
  15246. return mutator;
  15247. };
  15248. //apply mutator to row
  15249. Mutator.prototype.transformRow = function (data, type, updatedData) {
  15250. var self = this,
  15251. key = "mutator" + (type.charAt(0).toUpperCase() + type.slice(1)),
  15252. value;
  15253. if (this.enabled) {
  15254. self.table.columnManager.traverse(function (column) {
  15255. var mutator, params, component;
  15256. if (column.modules.mutate) {
  15257. mutator = column.modules.mutate[key] || column.modules.mutate.mutator || false;
  15258. if (mutator) {
  15259. value = column.getFieldValue(typeof updatedData !== "undefined" ? updatedData : data);
  15260. if (type == "data" || typeof value !== "undefined") {
  15261. component = column.getComponent();
  15262. params = typeof mutator.params === "function" ? mutator.params(value, data, type, component) : mutator.params;
  15263. column.setFieldValue(data, mutator.mutator(value, data, type, params, component));
  15264. }
  15265. }
  15266. }
  15267. });
  15268. }
  15269. return data;
  15270. };
  15271. //apply mutator to new cell value
  15272. Mutator.prototype.transformCell = function (cell, value) {
  15273. var mutator = cell.column.modules.mutate.mutatorEdit || cell.column.modules.mutate.mutator || false,
  15274. tempData = {};
  15275. if (mutator) {
  15276. tempData = Object.assign(tempData, cell.row.getData());
  15277. cell.column.setFieldValue(tempData, value);
  15278. return mutator.mutator(value, tempData, "edit", mutator.params, cell.getComponent());
  15279. } else {
  15280. return value;
  15281. }
  15282. };
  15283. Mutator.prototype.enable = function () {
  15284. this.enabled = true;
  15285. };
  15286. Mutator.prototype.disable = function () {
  15287. this.enabled = false;
  15288. };
  15289. //default mutators
  15290. Mutator.prototype.mutators = {};
  15291. Tabulator.prototype.registerModule("mutator", Mutator);
  15292. var Page = function Page(table) {
  15293. this.table = table; //hold Tabulator object
  15294. this.mode = "local";
  15295. this.progressiveLoad = false;
  15296. this.size = 0;
  15297. this.page = 1;
  15298. this.count = 5;
  15299. this.max = 1;
  15300. this.displayIndex = 0; //index in display pipeline
  15301. this.initialLoad = true;
  15302. this.pageSizes = [];
  15303. this.dataReceivedNames = {};
  15304. this.dataSentNames = {};
  15305. this.createElements();
  15306. };
  15307. Page.prototype.createElements = function () {
  15308. var button;
  15309. this.element = document.createElement("span");
  15310. this.element.classList.add("tabulator-paginator");
  15311. this.pagesElement = document.createElement("span");
  15312. this.pagesElement.classList.add("tabulator-pages");
  15313. button = document.createElement("button");
  15314. button.classList.add("tabulator-page");
  15315. button.setAttribute("type", "button");
  15316. button.setAttribute("role", "button");
  15317. button.setAttribute("aria-label", "");
  15318. button.setAttribute("title", "");
  15319. this.firstBut = button.cloneNode(true);
  15320. this.firstBut.setAttribute("data-page", "first");
  15321. this.prevBut = button.cloneNode(true);
  15322. this.prevBut.setAttribute("data-page", "prev");
  15323. this.nextBut = button.cloneNode(true);
  15324. this.nextBut.setAttribute("data-page", "next");
  15325. this.lastBut = button.cloneNode(true);
  15326. this.lastBut.setAttribute("data-page", "last");
  15327. if (this.table.options.paginationSizeSelector) {
  15328. this.pageSizeSelect = document.createElement("select");
  15329. this.pageSizeSelect.classList.add("tabulator-page-size");
  15330. }
  15331. };
  15332. Page.prototype.generatePageSizeSelectList = function () {
  15333. var _this75 = this;
  15334. var pageSizes = [];
  15335. if (this.pageSizeSelect) {
  15336. if (Array.isArray(this.table.options.paginationSizeSelector)) {
  15337. pageSizes = this.table.options.paginationSizeSelector;
  15338. this.pageSizes = pageSizes;
  15339. if (this.pageSizes.indexOf(this.size) == -1) {
  15340. pageSizes.unshift(this.size);
  15341. }
  15342. } else {
  15343. if (this.pageSizes.indexOf(this.size) == -1) {
  15344. pageSizes = [];
  15345. for (var _i13 = 1; _i13 < 5; _i13++) {
  15346. pageSizes.push(this.size * _i13);
  15347. }
  15348. this.pageSizes = pageSizes;
  15349. } else {
  15350. pageSizes = this.pageSizes;
  15351. }
  15352. }
  15353. while (this.pageSizeSelect.firstChild) {
  15354. this.pageSizeSelect.removeChild(this.pageSizeSelect.firstChild);
  15355. }pageSizes.forEach(function (item) {
  15356. var itemEl = document.createElement("option");
  15357. itemEl.value = item;
  15358. if (item === true) {
  15359. _this75.table.modules.localize.bind("pagination|all", function (value) {
  15360. itemEl.innerHTML = value;
  15361. });
  15362. } else {
  15363. itemEl.innerHTML = item;
  15364. }
  15365. _this75.pageSizeSelect.appendChild(itemEl);
  15366. });
  15367. this.pageSizeSelect.value = this.size;
  15368. }
  15369. };
  15370. //setup pageination
  15371. Page.prototype.initialize = function (hidden) {
  15372. var self = this,
  15373. pageSelectLabel,
  15374. testElRow,
  15375. testElCell;
  15376. //update param names
  15377. this.dataSentNames = Object.assign({}, this.paginationDataSentNames);
  15378. this.dataSentNames = Object.assign(this.dataSentNames, this.table.options.paginationDataSent);
  15379. this.dataReceivedNames = Object.assign({}, this.paginationDataReceivedNames);
  15380. this.dataReceivedNames = Object.assign(this.dataReceivedNames, this.table.options.paginationDataReceived);
  15381. //build pagination element
  15382. //bind localizations
  15383. self.table.modules.localize.bind("pagination|first", function (value) {
  15384. self.firstBut.innerHTML = value;
  15385. });
  15386. self.table.modules.localize.bind("pagination|first_title", function (value) {
  15387. self.firstBut.setAttribute("aria-label", value);
  15388. self.firstBut.setAttribute("title", value);
  15389. });
  15390. self.table.modules.localize.bind("pagination|prev", function (value) {
  15391. self.prevBut.innerHTML = value;
  15392. });
  15393. self.table.modules.localize.bind("pagination|prev_title", function (value) {
  15394. self.prevBut.setAttribute("aria-label", value);
  15395. self.prevBut.setAttribute("title", value);
  15396. });
  15397. self.table.modules.localize.bind("pagination|next", function (value) {
  15398. self.nextBut.innerHTML = value;
  15399. });
  15400. self.table.modules.localize.bind("pagination|next_title", function (value) {
  15401. self.nextBut.setAttribute("aria-label", value);
  15402. self.nextBut.setAttribute("title", value);
  15403. });
  15404. self.table.modules.localize.bind("pagination|last", function (value) {
  15405. self.lastBut.innerHTML = value;
  15406. });
  15407. self.table.modules.localize.bind("pagination|last_title", function (value) {
  15408. self.lastBut.setAttribute("aria-label", value);
  15409. self.lastBut.setAttribute("title", value);
  15410. });
  15411. //click bindings
  15412. self.firstBut.addEventListener("click", function () {
  15413. self.setPage(1).then(function () {}).catch(function () {});
  15414. });
  15415. self.prevBut.addEventListener("click", function () {
  15416. self.previousPage().then(function () {}).catch(function () {});
  15417. });
  15418. self.nextBut.addEventListener("click", function () {
  15419. self.nextPage().then(function () {}).catch(function () {});
  15420. });
  15421. self.lastBut.addEventListener("click", function () {
  15422. self.setPage(self.max).then(function () {}).catch(function () {});
  15423. });
  15424. if (self.table.options.paginationElement) {
  15425. self.element = self.table.options.paginationElement;
  15426. }
  15427. if (this.pageSizeSelect) {
  15428. pageSelectLabel = document.createElement("label");
  15429. self.table.modules.localize.bind("pagination|page_size", function (value) {
  15430. self.pageSizeSelect.setAttribute("aria-label", value);
  15431. self.pageSizeSelect.setAttribute("title", value);
  15432. pageSelectLabel.innerHTML = value;
  15433. });
  15434. self.element.appendChild(pageSelectLabel);
  15435. self.element.appendChild(self.pageSizeSelect);
  15436. self.pageSizeSelect.addEventListener("change", function (e) {
  15437. self.setPageSize(self.pageSizeSelect.value == "true" ? true : self.pageSizeSelect.value);
  15438. self.setPage(1).then(function () {}).catch(function () {});
  15439. });
  15440. }
  15441. //append to DOM
  15442. self.element.appendChild(self.firstBut);
  15443. self.element.appendChild(self.prevBut);
  15444. self.element.appendChild(self.pagesElement);
  15445. self.element.appendChild(self.nextBut);
  15446. self.element.appendChild(self.lastBut);
  15447. if (!self.table.options.paginationElement && !hidden) {
  15448. self.table.footerManager.append(self.element, self);
  15449. }
  15450. //set default values
  15451. self.mode = self.table.options.pagination;
  15452. if (self.table.options.paginationSize) {
  15453. self.size = self.table.options.paginationSize;
  15454. } else {
  15455. testElRow = document.createElement("div");
  15456. testElRow.classList.add("tabulator-row");
  15457. testElRow.style.visibility = hidden;
  15458. testElCell = document.createElement("div");
  15459. testElCell.classList.add("tabulator-cell");
  15460. testElCell.innerHTML = "Page Row Test";
  15461. testElRow.appendChild(testElCell);
  15462. self.table.rowManager.getTableElement().appendChild(testElRow);
  15463. self.size = Math.floor(self.table.rowManager.getElement().clientHeight / testElRow.offsetHeight);
  15464. self.table.rowManager.getTableElement().removeChild(testElRow);
  15465. }
  15466. // self.page = self.table.options.paginationInitialPage || 1;
  15467. self.count = self.table.options.paginationButtonCount;
  15468. self.generatePageSizeSelectList();
  15469. };
  15470. Page.prototype.initializeProgressive = function (mode) {
  15471. this.initialize(true);
  15472. this.mode = "progressive_" + mode;
  15473. this.progressiveLoad = true;
  15474. };
  15475. Page.prototype.setDisplayIndex = function (index) {
  15476. this.displayIndex = index;
  15477. };
  15478. Page.prototype.getDisplayIndex = function () {
  15479. return this.displayIndex;
  15480. };
  15481. //calculate maximum page from number of rows
  15482. Page.prototype.setMaxRows = function (rowCount) {
  15483. if (!rowCount) {
  15484. this.max = 1;
  15485. } else {
  15486. this.max = this.size === true ? 1 : Math.ceil(rowCount / this.size);
  15487. }
  15488. if (this.page > this.max) {
  15489. this.page = this.max;
  15490. }
  15491. };
  15492. //reset to first page without triggering action
  15493. Page.prototype.reset = function (force, columnsChanged) {
  15494. if (this.mode == "local" || force) {
  15495. this.page = 1;
  15496. }
  15497. if (columnsChanged) {
  15498. this.initialLoad = true;
  15499. }
  15500. return true;
  15501. };
  15502. //set the maxmum page
  15503. Page.prototype.setMaxPage = function (max) {
  15504. max = parseInt(max);
  15505. this.max = max || 1;
  15506. if (this.page > this.max) {
  15507. this.page = this.max;
  15508. this.trigger();
  15509. }
  15510. };
  15511. //set current page number
  15512. Page.prototype.setPage = function (page) {
  15513. var _this76 = this;
  15514. var self = this;
  15515. switch (page) {
  15516. case "first":
  15517. return this.setPage(1);
  15518. break;
  15519. case "prev":
  15520. return this.previousPage();
  15521. break;
  15522. case "next":
  15523. return this.nextPage();
  15524. break;
  15525. case "last":
  15526. return this.setPage(this.max);
  15527. break;
  15528. }
  15529. return new Promise(function (resolve, reject) {
  15530. page = parseInt(page);
  15531. if (page > 0 && page <= _this76.max) {
  15532. _this76.page = page;
  15533. _this76.trigger().then(function () {
  15534. resolve();
  15535. }).catch(function () {
  15536. reject();
  15537. });
  15538. if (self.table.options.persistence && self.table.modExists("persistence", true) && self.table.modules.persistence.config.page) {
  15539. self.table.modules.persistence.save("page");
  15540. }
  15541. } else {
  15542. console.warn("Pagination Error - Requested page is out of range of 1 - " + _this76.max + ":", page);
  15543. reject();
  15544. }
  15545. });
  15546. };
  15547. Page.prototype.setPageToRow = function (row) {
  15548. var _this77 = this;
  15549. return new Promise(function (resolve, reject) {
  15550. var rows = _this77.table.rowManager.getDisplayRows(_this77.displayIndex - 1);
  15551. var index = rows.indexOf(row);
  15552. if (index > -1) {
  15553. var page = _this77.size === true ? 1 : Math.ceil((index + 1) / _this77.size);
  15554. _this77.setPage(page).then(function () {
  15555. resolve();
  15556. }).catch(function () {
  15557. reject();
  15558. });
  15559. } else {
  15560. console.warn("Pagination Error - Requested row is not visible");
  15561. reject();
  15562. }
  15563. });
  15564. };
  15565. Page.prototype.setPageSize = function (size) {
  15566. if (size !== true) {
  15567. size = parseInt(size);
  15568. }
  15569. if (size > 0) {
  15570. this.size = size;
  15571. }
  15572. if (this.pageSizeSelect) {
  15573. // this.pageSizeSelect.value = size;
  15574. this.generatePageSizeSelectList();
  15575. }
  15576. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.page) {
  15577. this.table.modules.persistence.save("page");
  15578. }
  15579. };
  15580. //setup the pagination buttons
  15581. Page.prototype._setPageButtons = function () {
  15582. var self = this;
  15583. var leftSize = Math.floor((this.count - 1) / 2);
  15584. var rightSize = Math.ceil((this.count - 1) / 2);
  15585. var min = this.max - this.page + leftSize + 1 < this.count ? this.max - this.count + 1 : Math.max(this.page - leftSize, 1);
  15586. var max = this.page <= rightSize ? Math.min(this.count, this.max) : Math.min(this.page + rightSize, this.max);
  15587. while (self.pagesElement.firstChild) {
  15588. self.pagesElement.removeChild(self.pagesElement.firstChild);
  15589. }if (self.page == 1) {
  15590. self.firstBut.disabled = true;
  15591. self.prevBut.disabled = true;
  15592. } else {
  15593. self.firstBut.disabled = false;
  15594. self.prevBut.disabled = false;
  15595. }
  15596. if (self.page == self.max) {
  15597. self.lastBut.disabled = true;
  15598. self.nextBut.disabled = true;
  15599. } else {
  15600. self.lastBut.disabled = false;
  15601. self.nextBut.disabled = false;
  15602. }
  15603. for (var _i14 = min; _i14 <= max; _i14++) {
  15604. if (_i14 > 0 && _i14 <= self.max) {
  15605. self.pagesElement.appendChild(self._generatePageButton(_i14));
  15606. }
  15607. }
  15608. this.footerRedraw();
  15609. };
  15610. Page.prototype._generatePageButton = function (page) {
  15611. var self = this,
  15612. button = document.createElement("button");
  15613. button.classList.add("tabulator-page");
  15614. if (page == self.page) {
  15615. button.classList.add("active");
  15616. }
  15617. button.setAttribute("type", "button");
  15618. button.setAttribute("role", "button");
  15619. self.table.modules.localize.bind("pagination|page_title", function (value) {
  15620. button.setAttribute("aria-label", value + " " + page);
  15621. button.setAttribute("title", value + " " + page);
  15622. });
  15623. button.setAttribute("data-page", page);
  15624. button.textContent = page;
  15625. button.addEventListener("click", function (e) {
  15626. self.setPage(page).then(function () {}).catch(function () {});
  15627. });
  15628. return button;
  15629. };
  15630. //previous page
  15631. Page.prototype.previousPage = function () {
  15632. var _this78 = this;
  15633. return new Promise(function (resolve, reject) {
  15634. if (_this78.page > 1) {
  15635. _this78.page--;
  15636. _this78.trigger().then(function () {
  15637. resolve();
  15638. }).catch(function () {
  15639. reject();
  15640. });
  15641. if (_this78.table.options.persistence && _this78.table.modExists("persistence", true) && _this78.table.modules.persistence.config.page) {
  15642. _this78.table.modules.persistence.save("page");
  15643. }
  15644. } else {
  15645. console.warn("Pagination Error - Previous page would be less than page 1:", 0);
  15646. reject();
  15647. }
  15648. });
  15649. };
  15650. //next page
  15651. Page.prototype.nextPage = function () {
  15652. var _this79 = this;
  15653. return new Promise(function (resolve, reject) {
  15654. if (_this79.page < _this79.max) {
  15655. _this79.page++;
  15656. _this79.trigger().then(function () {
  15657. resolve();
  15658. }).catch(function () {
  15659. reject();
  15660. });
  15661. if (_this79.table.options.persistence && _this79.table.modExists("persistence", true) && _this79.table.modules.persistence.config.page) {
  15662. _this79.table.modules.persistence.save("page");
  15663. }
  15664. } else {
  15665. if (!_this79.progressiveLoad) {
  15666. console.warn("Pagination Error - Next page would be greater than maximum page of " + _this79.max + ":", _this79.max + 1);
  15667. }
  15668. reject();
  15669. }
  15670. });
  15671. };
  15672. //return current page number
  15673. Page.prototype.getPage = function () {
  15674. return this.page;
  15675. };
  15676. //return max page number
  15677. Page.prototype.getPageMax = function () {
  15678. return this.max;
  15679. };
  15680. Page.prototype.getPageSize = function (size) {
  15681. return this.size;
  15682. };
  15683. Page.prototype.getMode = function () {
  15684. return this.mode;
  15685. };
  15686. //return appropriate rows for current page
  15687. Page.prototype.getRows = function (data) {
  15688. var output, start, end;
  15689. if (this.mode == "local") {
  15690. output = [];
  15691. if (this.size === true) {
  15692. start = 0;
  15693. end = data.length;
  15694. } else {
  15695. start = this.size * (this.page - 1);
  15696. end = start + parseInt(this.size);
  15697. }
  15698. this._setPageButtons();
  15699. for (var _i15 = start; _i15 < end; _i15++) {
  15700. if (data[_i15]) {
  15701. output.push(data[_i15]);
  15702. }
  15703. }
  15704. return output;
  15705. } else {
  15706. this._setPageButtons();
  15707. return data.slice(0);
  15708. }
  15709. };
  15710. Page.prototype.trigger = function () {
  15711. var _this80 = this;
  15712. var left;
  15713. return new Promise(function (resolve, reject) {
  15714. switch (_this80.mode) {
  15715. case "local":
  15716. left = _this80.table.rowManager.scrollLeft;
  15717. _this80.table.rowManager.refreshActiveData("page");
  15718. _this80.table.rowManager.scrollHorizontal(left);
  15719. _this80.table.options.pageLoaded.call(_this80.table, _this80.getPage());
  15720. resolve();
  15721. break;
  15722. case "remote":
  15723. case "progressive_load":
  15724. case "progressive_scroll":
  15725. _this80.table.modules.ajax.blockActiveRequest();
  15726. _this80._getRemotePage().then(function () {
  15727. resolve();
  15728. }).catch(function () {
  15729. reject();
  15730. });
  15731. break;
  15732. default:
  15733. console.warn("Pagination Error - no such pagination mode:", _this80.mode);
  15734. reject();
  15735. }
  15736. });
  15737. };
  15738. Page.prototype._getRemotePage = function () {
  15739. var _this81 = this;
  15740. var self = this,
  15741. oldParams,
  15742. pageParams;
  15743. return new Promise(function (resolve, reject) {
  15744. if (!self.table.modExists("ajax", true)) {
  15745. reject();
  15746. }
  15747. //record old params and restore after request has been made
  15748. oldParams = Tabulator.prototype.helpers.deepClone(self.table.modules.ajax.getParams() || {});
  15749. pageParams = self.table.modules.ajax.getParams();
  15750. //configure request params
  15751. pageParams[_this81.dataSentNames.page] = self.page;
  15752. //set page size if defined
  15753. if (_this81.size) {
  15754. pageParams[_this81.dataSentNames.size] = _this81.size;
  15755. }
  15756. //set sort data if defined
  15757. if (_this81.table.options.ajaxSorting && _this81.table.modExists("sort")) {
  15758. var sorters = self.table.modules.sort.getSort();
  15759. sorters.forEach(function (item) {
  15760. delete item.column;
  15761. });
  15762. pageParams[_this81.dataSentNames.sorters] = sorters;
  15763. }
  15764. //set filter data if defined
  15765. if (_this81.table.options.ajaxFiltering && _this81.table.modExists("filter")) {
  15766. var filters = self.table.modules.filter.getFilters(true, true);
  15767. pageParams[_this81.dataSentNames.filters] = filters;
  15768. }
  15769. self.table.modules.ajax.setParams(pageParams);
  15770. self.table.modules.ajax.sendRequest(_this81.progressiveLoad).then(function (data) {
  15771. self._parseRemoteData(data);
  15772. resolve();
  15773. }).catch(function (e) {
  15774. reject();
  15775. });
  15776. self.table.modules.ajax.setParams(oldParams);
  15777. });
  15778. };
  15779. Page.prototype._parseRemoteData = function (data) {
  15780. var self = this,
  15781. left,
  15782. data,
  15783. margin;
  15784. if (typeof data[this.dataReceivedNames.last_page] === "undefined") {
  15785. console.warn("Remote Pagination Error - Server response missing '" + this.dataReceivedNames.last_page + "' property");
  15786. }
  15787. if (data[this.dataReceivedNames.data]) {
  15788. this.max = parseInt(data[this.dataReceivedNames.last_page]) || 1;
  15789. if (this.progressiveLoad) {
  15790. switch (this.mode) {
  15791. case "progressive_load":
  15792. if (this.page == 1) {
  15793. this.table.rowManager.setData(data[this.dataReceivedNames.data], false, this.initialLoad && this.page == 1);
  15794. } else {
  15795. this.table.rowManager.addRows(data[this.dataReceivedNames.data]);
  15796. }
  15797. if (this.page < this.max) {
  15798. setTimeout(function () {
  15799. self.nextPage().then(function () {}).catch(function () {});
  15800. }, self.table.options.ajaxProgressiveLoadDelay);
  15801. }
  15802. break;
  15803. case "progressive_scroll":
  15804. data = this.table.rowManager.getData().concat(data[this.dataReceivedNames.data]);
  15805. this.table.rowManager.setData(data, true, this.initialLoad && this.page == 1);
  15806. margin = this.table.options.ajaxProgressiveLoadScrollMargin || this.table.rowManager.element.clientHeight * 2;
  15807. if (self.table.rowManager.element.scrollHeight <= self.table.rowManager.element.clientHeight + margin) {
  15808. self.nextPage().then(function () {}).catch(function () {});
  15809. }
  15810. break;
  15811. }
  15812. } else {
  15813. left = this.table.rowManager.scrollLeft;
  15814. this.table.rowManager.setData(data[this.dataReceivedNames.data], false, this.initialLoad && this.page == 1);
  15815. this.table.rowManager.scrollHorizontal(left);
  15816. this.table.columnManager.scrollHorizontal(left);
  15817. this.table.options.pageLoaded.call(this.table, this.getPage());
  15818. }
  15819. this.initialLoad = false;
  15820. } else {
  15821. console.warn("Remote Pagination Error - Server response missing '" + this.dataReceivedNames.data + "' property");
  15822. }
  15823. };
  15824. //handle the footer element being redrawn
  15825. Page.prototype.footerRedraw = function () {
  15826. var footer = this.table.footerManager.element;
  15827. if (Math.ceil(footer.clientWidth) - footer.scrollWidth < 0) {
  15828. this.pagesElement.style.display = 'none';
  15829. } else {
  15830. this.pagesElement.style.display = '';
  15831. if (Math.ceil(footer.clientWidth) - footer.scrollWidth < 0) {
  15832. this.pagesElement.style.display = 'none';
  15833. }
  15834. }
  15835. };
  15836. //set the paramter names for pagination requests
  15837. Page.prototype.paginationDataSentNames = {
  15838. "page": "page",
  15839. "size": "size",
  15840. "sorters": "sorters",
  15841. // "sort_dir":"sort_dir",
  15842. "filters": "filters"
  15843. // "filter_value":"filter_value",
  15844. // "filter_type":"filter_type",
  15845. };
  15846. //set the property names for pagination responses
  15847. Page.prototype.paginationDataReceivedNames = {
  15848. "current_page": "current_page",
  15849. "last_page": "last_page",
  15850. "data": "data"
  15851. };
  15852. Tabulator.prototype.registerModule("page", Page);
  15853. var Persistence = function Persistence(table) {
  15854. this.table = table; //hold Tabulator object
  15855. this.mode = "";
  15856. this.id = "";
  15857. // this.persistProps = ["field", "width", "visible"];
  15858. this.defWatcherBlock = false;
  15859. this.config = {};
  15860. this.readFunc = false;
  15861. this.writeFunc = false;
  15862. };
  15863. // Test for whether localStorage is available for use.
  15864. Persistence.prototype.localStorageTest = function () {
  15865. var testKey = "_tabulator_test";
  15866. try {
  15867. window.localStorage.setItem(testKey, testKey);
  15868. window.localStorage.removeItem(testKey);
  15869. return true;
  15870. } catch (e) {
  15871. return false;
  15872. }
  15873. };
  15874. //setup parameters
  15875. Persistence.prototype.initialize = function () {
  15876. //determine persistent layout storage type
  15877. var mode = this.table.options.persistenceMode,
  15878. id = this.table.options.persistenceID,
  15879. retreivedData;
  15880. this.mode = mode !== true ? mode : this.localStorageTest() ? "local" : "cookie";
  15881. if (this.table.options.persistenceReaderFunc) {
  15882. if (typeof this.table.options.persistenceReaderFunc === "function") {
  15883. this.readFunc = this.table.options.persistenceReaderFunc;
  15884. } else {
  15885. if (this.readers[this.table.options.persistenceReaderFunc]) {
  15886. this.readFunc = this.readers[this.table.options.persistenceReaderFunc];
  15887. } else {
  15888. console.warn("Persistence Read Error - invalid reader set", this.table.options.persistenceReaderFunc);
  15889. }
  15890. }
  15891. } else {
  15892. if (this.readers[this.mode]) {
  15893. this.readFunc = this.readers[this.mode];
  15894. } else {
  15895. console.warn("Persistence Read Error - invalid reader set", this.mode);
  15896. }
  15897. }
  15898. if (this.table.options.persistenceWriterFunc) {
  15899. if (typeof this.table.options.persistenceWriterFunc === "function") {
  15900. this.writeFunc = this.table.options.persistenceWriterFunc;
  15901. } else {
  15902. if (this.readers[this.table.options.persistenceWriterFunc]) {
  15903. this.writeFunc = this.readers[this.table.options.persistenceWriterFunc];
  15904. } else {
  15905. console.warn("Persistence Write Error - invalid reader set", this.table.options.persistenceWriterFunc);
  15906. }
  15907. }
  15908. } else {
  15909. if (this.writers[this.mode]) {
  15910. this.writeFunc = this.writers[this.mode];
  15911. } else {
  15912. console.warn("Persistence Write Error - invalid writer set", this.mode);
  15913. }
  15914. }
  15915. //set storage tag
  15916. this.id = "tabulator-" + (id || this.table.element.getAttribute("id") || "");
  15917. this.config = {
  15918. sort: this.table.options.persistence === true || this.table.options.persistence.sort,
  15919. filter: this.table.options.persistence === true || this.table.options.persistence.filter,
  15920. group: this.table.options.persistence === true || this.table.options.persistence.group,
  15921. page: this.table.options.persistence === true || this.table.options.persistence.page,
  15922. columns: this.table.options.persistence === true ? ["title", "width", "visible"] : this.table.options.persistence.columns
  15923. };
  15924. //load pagination data if needed
  15925. if (this.config.page) {
  15926. retreivedData = this.retreiveData("page");
  15927. if (retreivedData) {
  15928. if (typeof retreivedData.paginationSize !== "undefined" && (this.config.page === true || this.config.page.size)) {
  15929. this.table.options.paginationSize = retreivedData.paginationSize;
  15930. }
  15931. if (typeof retreivedData.paginationInitialPage !== "undefined" && (this.config.page === true || this.config.page.page)) {
  15932. this.table.options.paginationInitialPage = retreivedData.paginationInitialPage;
  15933. }
  15934. }
  15935. }
  15936. //load group data if needed
  15937. if (this.config.group) {
  15938. retreivedData = this.retreiveData("group");
  15939. if (retreivedData) {
  15940. if (typeof retreivedData.groupBy !== "undefined" && (this.config.group === true || this.config.group.groupBy)) {
  15941. this.table.options.groupBy = retreivedData.groupBy;
  15942. }
  15943. if (typeof retreivedData.groupStartOpen !== "undefined" && (this.config.group === true || this.config.group.groupStartOpen)) {
  15944. this.table.options.groupStartOpen = retreivedData.groupStartOpen;
  15945. }
  15946. if (typeof retreivedData.groupHeader !== "undefined" && (this.config.group === true || this.config.group.groupHeader)) {
  15947. this.table.options.groupHeader = retreivedData.groupHeader;
  15948. }
  15949. }
  15950. }
  15951. };
  15952. Persistence.prototype.initializeColumn = function (column) {
  15953. var self = this,
  15954. def,
  15955. keys;
  15956. if (this.config.columns) {
  15957. this.defWatcherBlock = true;
  15958. def = column.getDefinition();
  15959. keys = this.config.columns === true ? Object.keys(def) : this.config.columns;
  15960. keys.forEach(function (key) {
  15961. var props = Object.getOwnPropertyDescriptor(def, key);
  15962. var value = def[key];
  15963. if (props) {
  15964. Object.defineProperty(def, key, {
  15965. set: function set(newValue) {
  15966. value = newValue;
  15967. if (!self.defWatcherBlock) {
  15968. self.save("columns");
  15969. }
  15970. if (props.set) {
  15971. props.set(newValue);
  15972. }
  15973. },
  15974. get: function get() {
  15975. if (props.get) {
  15976. props.get();
  15977. }
  15978. return value;
  15979. }
  15980. });
  15981. }
  15982. });
  15983. this.defWatcherBlock = false;
  15984. }
  15985. };
  15986. //load saved definitions
  15987. Persistence.prototype.load = function (type, current) {
  15988. var data = this.retreiveData(type);
  15989. if (current) {
  15990. data = data ? this.mergeDefinition(current, data) : current;
  15991. }
  15992. return data;
  15993. };
  15994. //retreive data from memory
  15995. Persistence.prototype.retreiveData = function (type) {
  15996. return this.readFunc ? this.readFunc(this.id, type) : false;
  15997. };
  15998. //merge old and new column definitions
  15999. Persistence.prototype.mergeDefinition = function (oldCols, newCols) {
  16000. var self = this,
  16001. output = [];
  16002. // oldCols = oldCols || [];
  16003. newCols = newCols || [];
  16004. newCols.forEach(function (column, to) {
  16005. var from = self._findColumn(oldCols, column),
  16006. keys;
  16007. if (from) {
  16008. if (self.config.columns === true || self.config.columns == undefined) {
  16009. keys = Object.keys(from);
  16010. keys.push("width");
  16011. } else {
  16012. keys = self.config.columns;
  16013. }
  16014. keys.forEach(function (key) {
  16015. if (typeof column[key] !== "undefined") {
  16016. from[key] = column[key];
  16017. }
  16018. });
  16019. if (from.columns) {
  16020. from.columns = self.mergeDefinition(from.columns, column.columns);
  16021. }
  16022. output.push(from);
  16023. }
  16024. });
  16025. oldCols.forEach(function (column, i) {
  16026. var from = self._findColumn(newCols, column);
  16027. if (!from) {
  16028. if (output.length > i) {
  16029. output.splice(i, 0, column);
  16030. } else {
  16031. output.push(column);
  16032. }
  16033. }
  16034. });
  16035. return output;
  16036. };
  16037. //find matching columns
  16038. Persistence.prototype._findColumn = function (columns, subject) {
  16039. var type = subject.columns ? "group" : subject.field ? "field" : "object";
  16040. return columns.find(function (col) {
  16041. switch (type) {
  16042. case "group":
  16043. return col.title === subject.title && col.columns.length === subject.columns.length;
  16044. break;
  16045. case "field":
  16046. return col.field === subject.field;
  16047. break;
  16048. case "object":
  16049. return col === subject;
  16050. break;
  16051. }
  16052. });
  16053. };
  16054. //save data
  16055. Persistence.prototype.save = function (type) {
  16056. var data = {};
  16057. switch (type) {
  16058. case "columns":
  16059. data = this.parseColumns(this.table.columnManager.getColumns());
  16060. break;
  16061. case "filter":
  16062. data = this.table.modules.filter.getFilters();
  16063. break;
  16064. case "sort":
  16065. data = this.validateSorters(this.table.modules.sort.getSort());
  16066. break;
  16067. case "group":
  16068. data = this.getGroupConfig();
  16069. break;
  16070. case "page":
  16071. data = this.getPageConfig();
  16072. break;
  16073. }
  16074. if (this.writeFunc) {
  16075. this.writeFunc(this.id, type, data);
  16076. }
  16077. };
  16078. //ensure sorters contain no function data
  16079. Persistence.prototype.validateSorters = function (data) {
  16080. data.forEach(function (item) {
  16081. item.column = item.field;
  16082. delete item.field;
  16083. });
  16084. return data;
  16085. };
  16086. Persistence.prototype.getGroupConfig = function () {
  16087. var data = {};
  16088. if (this.config.group) {
  16089. if (this.config.group === true || this.config.group.groupBy) {
  16090. data.groupBy = this.table.options.groupBy;
  16091. }
  16092. if (this.config.group === true || this.config.group.groupStartOpen) {
  16093. data.groupStartOpen = this.table.options.groupStartOpen;
  16094. }
  16095. if (this.config.group === true || this.config.group.groupHeader) {
  16096. data.groupHeader = this.table.options.groupHeader;
  16097. }
  16098. }
  16099. return data;
  16100. };
  16101. Persistence.prototype.getPageConfig = function () {
  16102. var data = {};
  16103. if (this.config.page) {
  16104. if (this.config.page === true || this.config.page.size) {
  16105. data.paginationSize = this.table.modules.page.getPageSize();
  16106. }
  16107. if (this.config.page === true || this.config.page.page) {
  16108. data.paginationInitialPage = this.table.modules.page.getPage();
  16109. }
  16110. }
  16111. return data;
  16112. };
  16113. //parse columns for data to store
  16114. Persistence.prototype.parseColumns = function (columns) {
  16115. var self = this,
  16116. definitions = [],
  16117. excludedKeys = ["headerContextMenu", "headerMenu", "contextMenu", "clickMenu"];
  16118. columns.forEach(function (column) {
  16119. var defStore = {},
  16120. colDef = column.getDefinition(),
  16121. keys;
  16122. if (column.isGroup) {
  16123. defStore.title = colDef.title;
  16124. defStore.columns = self.parseColumns(column.getColumns());
  16125. } else {
  16126. defStore.field = column.getField();
  16127. if (self.config.columns === true || self.config.columns == undefined) {
  16128. keys = Object.keys(colDef);
  16129. keys.push("width");
  16130. } else {
  16131. keys = self.config.columns;
  16132. }
  16133. keys.forEach(function (key) {
  16134. switch (key) {
  16135. case "width":
  16136. defStore.width = column.getWidth();
  16137. break;
  16138. case "visible":
  16139. defStore.visible = column.visible;
  16140. break;
  16141. default:
  16142. if (typeof colDef[key] !== "function" && excludedKeys.indexOf(key) === -1) {
  16143. defStore[key] = colDef[key];
  16144. }
  16145. }
  16146. });
  16147. }
  16148. definitions.push(defStore);
  16149. });
  16150. return definitions;
  16151. };
  16152. // read peristence information from storage
  16153. Persistence.prototype.readers = {
  16154. local: function local(id, type) {
  16155. var data = localStorage.getItem(id + "-" + type);
  16156. return data ? JSON.parse(data) : false;
  16157. },
  16158. cookie: function cookie(id, type) {
  16159. var cookie = document.cookie,
  16160. key = id + "-" + type,
  16161. cookiePos = cookie.indexOf(key + "="),
  16162. end,
  16163. data;
  16164. //if cookie exists, decode and load column data into tabulator
  16165. if (cookiePos > -1) {
  16166. cookie = cookie.substr(cookiePos);
  16167. end = cookie.indexOf(";");
  16168. if (end > -1) {
  16169. cookie = cookie.substr(0, end);
  16170. }
  16171. data = cookie.replace(key + "=", "");
  16172. }
  16173. return data ? JSON.parse(data) : false;
  16174. }
  16175. };
  16176. //write persistence information to storage
  16177. Persistence.prototype.writers = {
  16178. local: function local(id, type, data) {
  16179. localStorage.setItem(id + "-" + type, JSON.stringify(data));
  16180. },
  16181. cookie: function cookie(id, type, data) {
  16182. var expireDate = new Date();
  16183. expireDate.setDate(expireDate.getDate() + 10000);
  16184. document.cookie = id + "-" + type + "=" + JSON.stringify(data) + "; expires=" + expireDate.toUTCString();
  16185. }
  16186. };
  16187. Tabulator.prototype.registerModule("persistence", Persistence);
  16188. var Print = function Print(table) {
  16189. this.table = table; //hold Tabulator object
  16190. this.element = false;
  16191. this.manualBlock = false;
  16192. };
  16193. Print.prototype.initialize = function () {
  16194. window.addEventListener("beforeprint", this.replaceTable.bind(this));
  16195. window.addEventListener("afterprint", this.cleanup.bind(this));
  16196. };
  16197. Print.prototype.replaceTable = function () {
  16198. if (!this.manualBlock) {
  16199. this.element = document.createElement("div");
  16200. this.element.classList.add("tabulator-print-table");
  16201. this.element.appendChild(this.table.modules.export.genereateTable(this.table.options.printConfig, this.table.options.printStyled, this.table.options.printRowRange, "print"));
  16202. this.table.element.style.display = "none";
  16203. this.table.element.parentNode.insertBefore(this.element, this.table.element);
  16204. }
  16205. };
  16206. Print.prototype.cleanup = function () {
  16207. document.body.classList.remove("tabulator-print-fullscreen-hide");
  16208. if (this.element && this.element.parentNode) {
  16209. this.element.parentNode.removeChild(this.element);
  16210. this.table.element.style.display = "";
  16211. }
  16212. };
  16213. Print.prototype.printFullscreen = function (visible, style, config) {
  16214. var scrollX = window.scrollX,
  16215. scrollY = window.scrollY,
  16216. headerEl = document.createElement("div"),
  16217. footerEl = document.createElement("div"),
  16218. tableEl = this.table.modules.export.genereateTable(typeof config != "undefined" ? config : this.table.options.printConfig, typeof style != "undefined" ? style : this.table.options.printStyled, visible, "print"),
  16219. headerContent,
  16220. footerContent;
  16221. this.manualBlock = true;
  16222. this.element = document.createElement("div");
  16223. this.element.classList.add("tabulator-print-fullscreen");
  16224. if (this.table.options.printHeader) {
  16225. headerEl.classList.add("tabulator-print-header");
  16226. headerContent = typeof this.table.options.printHeader == "function" ? this.table.options.printHeader.call(this.table) : this.table.options.printHeader;
  16227. if (typeof headerContent == "string") {
  16228. headerEl.innerHTML = headerContent;
  16229. } else {
  16230. headerEl.appendChild(headerContent);
  16231. }
  16232. this.element.appendChild(headerEl);
  16233. }
  16234. this.element.appendChild(tableEl);
  16235. if (this.table.options.printFooter) {
  16236. footerEl.classList.add("tabulator-print-footer");
  16237. footerContent = typeof this.table.options.printFooter == "function" ? this.table.options.printFooter.call(this.table) : this.table.options.printFooter;
  16238. if (typeof footerContent == "string") {
  16239. footerEl.innerHTML = footerContent;
  16240. } else {
  16241. footerEl.appendChild(footerContent);
  16242. }
  16243. this.element.appendChild(footerEl);
  16244. }
  16245. document.body.classList.add("tabulator-print-fullscreen-hide");
  16246. document.body.appendChild(this.element);
  16247. if (this.table.options.printFormatter) {
  16248. this.table.options.printFormatter(this.element, tableEl);
  16249. }
  16250. window.print();
  16251. this.cleanup();
  16252. window.scrollTo(scrollX, scrollY);
  16253. this.manualBlock = false;
  16254. };
  16255. Tabulator.prototype.registerModule("print", Print);
  16256. var ReactiveData = function ReactiveData(table) {
  16257. this.table = table; //hold Tabulator object
  16258. this.data = false;
  16259. this.blocked = false; //block reactivity while performing update
  16260. this.origFuncs = {}; // hold original data array functions to allow replacement after data is done with
  16261. this.currentVersion = 0;
  16262. };
  16263. ReactiveData.prototype.watchData = function (data) {
  16264. var self = this,
  16265. pushFunc,
  16266. version;
  16267. this.currentVersion++;
  16268. version = this.currentVersion;
  16269. self.unwatchData();
  16270. self.data = data;
  16271. //override array push function
  16272. self.origFuncs.push = data.push;
  16273. Object.defineProperty(self.data, "push", {
  16274. enumerable: false,
  16275. configurable: true,
  16276. value: function value() {
  16277. var args = Array.from(arguments);
  16278. if (!self.blocked && version === self.currentVersion) {
  16279. args.forEach(function (arg) {
  16280. self.table.rowManager.addRowActual(arg, false);
  16281. });
  16282. }
  16283. return self.origFuncs.push.apply(data, arguments);
  16284. }
  16285. });
  16286. //override array unshift function
  16287. self.origFuncs.unshift = data.unshift;
  16288. Object.defineProperty(self.data, "unshift", {
  16289. enumerable: false,
  16290. configurable: true,
  16291. value: function value() {
  16292. var args = Array.from(arguments);
  16293. if (!self.blocked && version === self.currentVersion) {
  16294. args.forEach(function (arg) {
  16295. self.table.rowManager.addRowActual(arg, true);
  16296. });
  16297. }
  16298. return self.origFuncs.unshift.apply(data, arguments);
  16299. }
  16300. });
  16301. //override array shift function
  16302. self.origFuncs.shift = data.shift;
  16303. Object.defineProperty(self.data, "shift", {
  16304. enumerable: false,
  16305. configurable: true,
  16306. value: function value() {
  16307. var row;
  16308. if (!self.blocked && version === self.currentVersion) {
  16309. if (self.data.length) {
  16310. row = self.table.rowManager.getRowFromDataObject(self.data[0]);
  16311. if (row) {
  16312. row.deleteActual();
  16313. }
  16314. }
  16315. }
  16316. return self.origFuncs.shift.call(data);
  16317. }
  16318. });
  16319. //override array pop function
  16320. self.origFuncs.pop = data.pop;
  16321. Object.defineProperty(self.data, "pop", {
  16322. enumerable: false,
  16323. configurable: true,
  16324. value: function value() {
  16325. var row;
  16326. if (!self.blocked && version === self.currentVersion) {
  16327. if (self.data.length) {
  16328. row = self.table.rowManager.getRowFromDataObject(self.data[self.data.length - 1]);
  16329. if (row) {
  16330. row.deleteActual();
  16331. }
  16332. }
  16333. }
  16334. return self.origFuncs.pop.call(data);
  16335. }
  16336. });
  16337. //override array splice function
  16338. self.origFuncs.splice = data.splice;
  16339. Object.defineProperty(self.data, "splice", {
  16340. enumerable: false,
  16341. configurable: true,
  16342. value: function value() {
  16343. var args = Array.from(arguments),
  16344. start = args[0] < 0 ? data.length + args[0] : args[0],
  16345. end = args[1],
  16346. newRows = args[2] ? args.slice(2) : false,
  16347. startRow;
  16348. if (!self.blocked && version === self.currentVersion) {
  16349. //add new rows
  16350. if (newRows) {
  16351. startRow = data[start] ? self.table.rowManager.getRowFromDataObject(data[start]) : false;
  16352. if (startRow) {
  16353. newRows.forEach(function (rowData) {
  16354. self.table.rowManager.addRowActual(rowData, true, startRow, true);
  16355. });
  16356. } else {
  16357. newRows = newRows.slice().reverse();
  16358. newRows.forEach(function (rowData) {
  16359. self.table.rowManager.addRowActual(rowData, true, false, true);
  16360. });
  16361. }
  16362. }
  16363. //delete removed rows
  16364. if (end !== 0) {
  16365. var oldRows = data.slice(start, typeof args[1] === "undefined" ? args[1] : start + end);
  16366. oldRows.forEach(function (rowData, i) {
  16367. var row = self.table.rowManager.getRowFromDataObject(rowData);
  16368. if (row) {
  16369. row.deleteActual(i !== oldRows.length - 1);
  16370. }
  16371. });
  16372. }
  16373. if (newRows || end !== 0) {
  16374. self.table.rowManager.reRenderInPosition();
  16375. }
  16376. }
  16377. return self.origFuncs.splice.apply(data, arguments);
  16378. }
  16379. });
  16380. };
  16381. ReactiveData.prototype.unwatchData = function () {
  16382. if (this.data !== false) {
  16383. for (var key in this.origFuncs) {
  16384. Object.defineProperty(this.data, key, {
  16385. enumerable: true,
  16386. configurable: true,
  16387. writable: true,
  16388. value: this.origFuncs.key
  16389. });
  16390. }
  16391. }
  16392. };
  16393. ReactiveData.prototype.watchRow = function (row) {
  16394. var data = row.getData();
  16395. this.blocked = true;
  16396. for (var key in data) {
  16397. this.watchKey(row, data, key);
  16398. }
  16399. if (this.table.options.dataTree) {
  16400. this.watchTreeChildren(row);
  16401. }
  16402. this.blocked = false;
  16403. };
  16404. ReactiveData.prototype.watchTreeChildren = function (row) {
  16405. var self = this,
  16406. childField = row.getData()[this.table.options.dataTreeChildField],
  16407. origFuncs = {};
  16408. function rebuildTree() {
  16409. self.table.modules.dataTree.initializeRow(row);
  16410. self.table.modules.dataTree.layoutRow(row);
  16411. self.table.rowManager.refreshActiveData("tree", false, true);
  16412. }
  16413. if (childField) {
  16414. origFuncs.push = childField.push;
  16415. Object.defineProperty(childField, "push", {
  16416. enumerable: false,
  16417. configurable: true,
  16418. value: function value() {
  16419. var result = origFuncs.push.apply(childField, arguments);
  16420. rebuildTree();
  16421. return result;
  16422. }
  16423. });
  16424. origFuncs.unshift = childField.unshift;
  16425. Object.defineProperty(childField, "unshift", {
  16426. enumerable: false,
  16427. configurable: true,
  16428. value: function value() {
  16429. var result = origFuncs.unshift.apply(childField, arguments);
  16430. rebuildTree();
  16431. return result;
  16432. }
  16433. });
  16434. origFuncs.shift = childField.shift;
  16435. Object.defineProperty(childField, "shift", {
  16436. enumerable: false,
  16437. configurable: true,
  16438. value: function value() {
  16439. var result = origFuncs.shift.call(childField);
  16440. rebuildTree();
  16441. return result;
  16442. }
  16443. });
  16444. origFuncs.pop = childField.pop;
  16445. Object.defineProperty(childField, "pop", {
  16446. enumerable: false,
  16447. configurable: true,
  16448. value: function value() {
  16449. var result = origFuncs.pop.call(childField);
  16450. rebuildTree();
  16451. return result;
  16452. }
  16453. });
  16454. origFuncs.splice = childField.splice;
  16455. Object.defineProperty(childField, "splice", {
  16456. enumerable: false,
  16457. configurable: true,
  16458. value: function value() {
  16459. var result = origFuncs.splice.apply(childField, arguments);
  16460. rebuildTree();
  16461. return result;
  16462. }
  16463. });
  16464. }
  16465. };
  16466. ReactiveData.prototype.watchKey = function (row, data, key) {
  16467. var self = this,
  16468. props = Object.getOwnPropertyDescriptor(data, key),
  16469. value = data[key],
  16470. version = this.currentVersion;
  16471. Object.defineProperty(data, key, {
  16472. set: function set(newValue) {
  16473. value = newValue;
  16474. if (!self.blocked && version === self.currentVersion) {
  16475. var update = {};
  16476. update[key] = newValue;
  16477. row.updateData(update);
  16478. }
  16479. if (props.set) {
  16480. props.set(newValue);
  16481. }
  16482. },
  16483. get: function get() {
  16484. if (props.get) {
  16485. props.get();
  16486. }
  16487. return value;
  16488. }
  16489. });
  16490. };
  16491. ReactiveData.prototype.unwatchRow = function (row) {
  16492. var data = row.getData();
  16493. for (var key in data) {
  16494. Object.defineProperty(data, key, {
  16495. value: data[key]
  16496. });
  16497. }
  16498. };
  16499. ReactiveData.prototype.block = function () {
  16500. this.blocked = true;
  16501. };
  16502. ReactiveData.prototype.unblock = function () {
  16503. this.blocked = false;
  16504. };
  16505. Tabulator.prototype.registerModule("reactiveData", ReactiveData);
  16506. var ResizeColumns = function ResizeColumns(table) {
  16507. this.table = table; //hold Tabulator object
  16508. this.startColumn = false;
  16509. this.startX = false;
  16510. this.startWidth = false;
  16511. this.handle = null;
  16512. this.prevHandle = null;
  16513. };
  16514. ResizeColumns.prototype.initializeColumn = function (type, column, element) {
  16515. var self = this,
  16516. variableHeight = false,
  16517. mode = this.table.options.resizableColumns;
  16518. //set column resize mode
  16519. if (type === "header") {
  16520. variableHeight = column.definition.formatter == "textarea" || column.definition.variableHeight;
  16521. column.modules.resize = { variableHeight: variableHeight };
  16522. }
  16523. if (mode === true || mode == type) {
  16524. var handle = document.createElement('div');
  16525. handle.className = "tabulator-col-resize-handle";
  16526. var prevHandle = document.createElement('div');
  16527. prevHandle.className = "tabulator-col-resize-handle prev";
  16528. handle.addEventListener("click", function (e) {
  16529. e.stopPropagation();
  16530. });
  16531. var handleDown = function handleDown(e) {
  16532. var nearestColumn = column.getLastColumn();
  16533. if (nearestColumn && self._checkResizability(nearestColumn)) {
  16534. self.startColumn = column;
  16535. self._mouseDown(e, nearestColumn, handle);
  16536. }
  16537. };
  16538. handle.addEventListener("mousedown", handleDown);
  16539. handle.addEventListener("touchstart", handleDown, { passive: true });
  16540. //reszie column on double click
  16541. handle.addEventListener("dblclick", function (e) {
  16542. var col = column.getLastColumn();
  16543. if (col && self._checkResizability(col)) {
  16544. e.stopPropagation();
  16545. col.reinitializeWidth(true);
  16546. }
  16547. });
  16548. prevHandle.addEventListener("click", function (e) {
  16549. e.stopPropagation();
  16550. });
  16551. var prevHandleDown = function prevHandleDown(e) {
  16552. var nearestColumn, colIndex, prevColumn;
  16553. nearestColumn = column.getFirstColumn();
  16554. if (nearestColumn) {
  16555. colIndex = self.table.columnManager.findColumnIndex(nearestColumn);
  16556. prevColumn = colIndex > 0 ? self.table.columnManager.getColumnByIndex(colIndex - 1) : false;
  16557. if (prevColumn && self._checkResizability(prevColumn)) {
  16558. self.startColumn = column;
  16559. self._mouseDown(e, prevColumn, prevHandle);
  16560. }
  16561. }
  16562. };
  16563. prevHandle.addEventListener("mousedown", prevHandleDown);
  16564. prevHandle.addEventListener("touchstart", prevHandleDown, { passive: true });
  16565. //resize column on double click
  16566. prevHandle.addEventListener("dblclick", function (e) {
  16567. var nearestColumn, colIndex, prevColumn;
  16568. nearestColumn = column.getFirstColumn();
  16569. if (nearestColumn) {
  16570. colIndex = self.table.columnManager.findColumnIndex(nearestColumn);
  16571. prevColumn = colIndex > 0 ? self.table.columnManager.getColumnByIndex(colIndex - 1) : false;
  16572. if (prevColumn && self._checkResizability(prevColumn)) {
  16573. e.stopPropagation();
  16574. prevColumn.reinitializeWidth(true);
  16575. }
  16576. }
  16577. });
  16578. element.appendChild(handle);
  16579. element.appendChild(prevHandle);
  16580. }
  16581. };
  16582. ResizeColumns.prototype._checkResizability = function (column) {
  16583. return typeof column.definition.resizable != "undefined" ? column.definition.resizable : this.table.options.resizableColumns;
  16584. };
  16585. ResizeColumns.prototype._mouseDown = function (e, column, handle) {
  16586. var self = this;
  16587. self.table.element.classList.add("tabulator-block-select");
  16588. function mouseMove(e) {
  16589. // self.table.columnManager.tempScrollBlock();
  16590. if (self.table.rtl) {
  16591. column.setWidth(self.startWidth - ((typeof e.screenX === "undefined" ? e.touches[0].screenX : e.screenX) - self.startX));
  16592. } else {
  16593. column.setWidth(self.startWidth + ((typeof e.screenX === "undefined" ? e.touches[0].screenX : e.screenX) - self.startX));
  16594. }
  16595. if (self.table.options.virtualDomHoz) {
  16596. self.table.vdomHoz.reinitialize(true);
  16597. }
  16598. if (!self.table.browserSlow && column.modules.resize && column.modules.resize.variableHeight) {
  16599. column.checkCellHeights();
  16600. }
  16601. }
  16602. function mouseUp(e) {
  16603. //block editor from taking action while resizing is taking place
  16604. if (self.startColumn.modules.edit) {
  16605. self.startColumn.modules.edit.blocked = false;
  16606. }
  16607. if (self.table.browserSlow && column.modules.resize && column.modules.resize.variableHeight) {
  16608. column.checkCellHeights();
  16609. }
  16610. document.body.removeEventListener("mouseup", mouseUp);
  16611. document.body.removeEventListener("mousemove", mouseMove);
  16612. handle.removeEventListener("touchmove", mouseMove);
  16613. handle.removeEventListener("touchend", mouseUp);
  16614. self.table.element.classList.remove("tabulator-block-select");
  16615. if (self.table.options.persistence && self.table.modExists("persistence", true) && self.table.modules.persistence.config.columns) {
  16616. self.table.modules.persistence.save("columns");
  16617. }
  16618. self.table.options.columnResized.call(self.table, column.getComponent());
  16619. }
  16620. e.stopPropagation(); //prevent resize from interfereing with movable columns
  16621. //block editor from taking action while resizing is taking place
  16622. if (self.startColumn.modules.edit) {
  16623. self.startColumn.modules.edit.blocked = true;
  16624. }
  16625. self.startX = typeof e.screenX === "undefined" ? e.touches[0].screenX : e.screenX;
  16626. self.startWidth = column.getWidth();
  16627. document.body.addEventListener("mousemove", mouseMove);
  16628. document.body.addEventListener("mouseup", mouseUp);
  16629. handle.addEventListener("touchmove", mouseMove, { passive: true });
  16630. handle.addEventListener("touchend", mouseUp);
  16631. };
  16632. Tabulator.prototype.registerModule("resizeColumns", ResizeColumns);
  16633. var ResizeRows = function ResizeRows(table) {
  16634. this.table = table; //hold Tabulator object
  16635. this.startColumn = false;
  16636. this.startY = false;
  16637. this.startHeight = false;
  16638. this.handle = null;
  16639. this.prevHandle = null;
  16640. };
  16641. ResizeRows.prototype.initializeRow = function (row) {
  16642. var self = this,
  16643. rowEl = row.getElement();
  16644. var handle = document.createElement('div');
  16645. handle.className = "tabulator-row-resize-handle";
  16646. var prevHandle = document.createElement('div');
  16647. prevHandle.className = "tabulator-row-resize-handle prev";
  16648. handle.addEventListener("click", function (e) {
  16649. e.stopPropagation();
  16650. });
  16651. var handleDown = function handleDown(e) {
  16652. self.startRow = row;
  16653. self._mouseDown(e, row, handle);
  16654. };
  16655. handle.addEventListener("mousedown", handleDown);
  16656. handle.addEventListener("touchstart", handleDown, { passive: true });
  16657. prevHandle.addEventListener("click", function (e) {
  16658. e.stopPropagation();
  16659. });
  16660. var prevHandleDown = function prevHandleDown(e) {
  16661. var prevRow = self.table.rowManager.prevDisplayRow(row);
  16662. if (prevRow) {
  16663. self.startRow = prevRow;
  16664. self._mouseDown(e, prevRow, prevHandle);
  16665. }
  16666. };
  16667. prevHandle.addEventListener("mousedown", prevHandleDown);
  16668. prevHandle.addEventListener("touchstart", prevHandleDown, { passive: true });
  16669. rowEl.appendChild(handle);
  16670. rowEl.appendChild(prevHandle);
  16671. };
  16672. ResizeRows.prototype._mouseDown = function (e, row, handle) {
  16673. var self = this;
  16674. self.table.element.classList.add("tabulator-block-select");
  16675. function mouseMove(e) {
  16676. row.setHeight(self.startHeight + ((typeof e.screenY === "undefined" ? e.touches[0].screenY : e.screenY) - self.startY));
  16677. }
  16678. function mouseUp(e) {
  16679. // //block editor from taking action while resizing is taking place
  16680. // if(self.startColumn.modules.edit){
  16681. // self.startColumn.modules.edit.blocked = false;
  16682. // }
  16683. document.body.removeEventListener("mouseup", mouseMove);
  16684. document.body.removeEventListener("mousemove", mouseMove);
  16685. handle.removeEventListener("touchmove", mouseMove);
  16686. handle.removeEventListener("touchend", mouseUp);
  16687. self.table.element.classList.remove("tabulator-block-select");
  16688. self.table.options.rowResized.call(this.table, row.getComponent());
  16689. }
  16690. e.stopPropagation(); //prevent resize from interfereing with movable columns
  16691. //block editor from taking action while resizing is taking place
  16692. // if(self.startColumn.modules.edit){
  16693. // self.startColumn.modules.edit.blocked = true;
  16694. // }
  16695. self.startY = typeof e.screenY === "undefined" ? e.touches[0].screenY : e.screenY;
  16696. self.startHeight = row.getHeight();
  16697. document.body.addEventListener("mousemove", mouseMove);
  16698. document.body.addEventListener("mouseup", mouseUp);
  16699. handle.addEventListener("touchmove", mouseMove, { passive: true });
  16700. handle.addEventListener("touchend", mouseUp);
  16701. };
  16702. Tabulator.prototype.registerModule("resizeRows", ResizeRows);
  16703. var ResizeTable = function ResizeTable(table) {
  16704. this.table = table; //hold Tabulator object
  16705. this.binding = false;
  16706. this.observer = false;
  16707. this.containerObserver = false;
  16708. this.tableHeight = 0;
  16709. this.tableWidth = 0;
  16710. this.containerHeight = 0;
  16711. this.containerWidth = 0;
  16712. this.autoResize = false;
  16713. };
  16714. ResizeTable.prototype.initialize = function (row) {
  16715. var _this82 = this;
  16716. var table = this.table,
  16717. tableStyle;
  16718. this.tableHeight = table.element.clientHeight;
  16719. this.tableWidth = table.element.clientWidth;
  16720. if (table.element.parentNode) {
  16721. this.containerHeight = table.element.parentNode.clientHeight;
  16722. this.containerWidth = table.element.parentNode.clientWidth;
  16723. }
  16724. if (typeof ResizeObserver !== "undefined" && table.rowManager.getRenderMode() === "virtual") {
  16725. this.autoResize = true;
  16726. this.observer = new ResizeObserver(function (entry) {
  16727. if (!table.browserMobile || table.browserMobile && !table.modules.edit.currentCell) {
  16728. var nodeHeight = Math.floor(entry[0].contentRect.height);
  16729. var nodeWidth = Math.floor(entry[0].contentRect.width);
  16730. if (_this82.tableHeight != nodeHeight || _this82.tableWidth != nodeWidth) {
  16731. _this82.tableHeight = nodeHeight;
  16732. _this82.tableWidth = nodeWidth;
  16733. if (table.element.parentNode) {
  16734. _this82.containerHeight = table.element.parentNode.clientHeight;
  16735. _this82.containerWidth = table.element.parentNode.clientWidth;
  16736. }
  16737. if (table.options.virtualDomHoz) {
  16738. table.vdomHoz.reinitialize(true);
  16739. }
  16740. table.redraw();
  16741. }
  16742. }
  16743. });
  16744. this.observer.observe(table.element);
  16745. tableStyle = window.getComputedStyle(table.element);
  16746. if (this.table.element.parentNode && !this.table.rowManager.fixedHeight && (tableStyle.getPropertyValue("max-height") || tableStyle.getPropertyValue("min-height"))) {
  16747. this.containerObserver = new ResizeObserver(function (entry) {
  16748. if (!table.browserMobile || table.browserMobile && !table.modules.edit.currentCell) {
  16749. var nodeHeight = Math.floor(entry[0].contentRect.height);
  16750. var nodeWidth = Math.floor(entry[0].contentRect.width);
  16751. if (_this82.containerHeight != nodeHeight || _this82.containerWidth != nodeWidth) {
  16752. _this82.containerHeight = nodeHeight;
  16753. _this82.containerWidth = nodeWidth;
  16754. _this82.tableHeight = table.element.clientHeight;
  16755. _this82.tableWidth = table.element.clientWidth;
  16756. }
  16757. if (table.options.virtualDomHoz) {
  16758. table.vdomHoz.reinitialize(true);
  16759. }
  16760. table.redraw();
  16761. }
  16762. });
  16763. this.containerObserver.observe(this.table.element.parentNode);
  16764. }
  16765. } else {
  16766. this.binding = function () {
  16767. if (!table.browserMobile || table.browserMobile && !table.modules.edit.currentCell) {
  16768. if (table.options.virtualDomHoz) {
  16769. table.vdomHoz.reinitialize(true);
  16770. }
  16771. table.redraw();
  16772. }
  16773. };
  16774. window.addEventListener("resize", this.binding);
  16775. }
  16776. };
  16777. ResizeTable.prototype.clearBindings = function (row) {
  16778. if (this.binding) {
  16779. window.removeEventListener("resize", this.binding);
  16780. }
  16781. if (this.observer) {
  16782. this.observer.unobserve(this.table.element);
  16783. }
  16784. if (this.containerObserver) {
  16785. this.containerObserver.unobserve(this.table.element.parentNode);
  16786. }
  16787. };
  16788. Tabulator.prototype.registerModule("resizeTable", ResizeTable);
  16789. var ResponsiveLayout = function ResponsiveLayout(table) {
  16790. this.table = table; //hold Tabulator object
  16791. this.columns = [];
  16792. this.hiddenColumns = [];
  16793. this.mode = "";
  16794. this.index = 0;
  16795. this.collapseFormatter = [];
  16796. this.collapseStartOpen = true;
  16797. this.collapseHandleColumn = false;
  16798. };
  16799. //generate resposive columns list
  16800. ResponsiveLayout.prototype.initialize = function () {
  16801. var self = this,
  16802. columns = [];
  16803. this.mode = this.table.options.responsiveLayout;
  16804. this.collapseFormatter = this.table.options.responsiveLayoutCollapseFormatter || this.formatCollapsedData;
  16805. this.collapseStartOpen = this.table.options.responsiveLayoutCollapseStartOpen;
  16806. this.hiddenColumns = [];
  16807. //detemine level of responsivity for each column
  16808. this.table.columnManager.columnsByIndex.forEach(function (column, i) {
  16809. if (column.modules.responsive) {
  16810. if (column.modules.responsive.order && column.modules.responsive.visible) {
  16811. column.modules.responsive.index = i;
  16812. columns.push(column);
  16813. if (!column.visible && self.mode === "collapse") {
  16814. self.hiddenColumns.push(column);
  16815. }
  16816. }
  16817. }
  16818. });
  16819. //sort list by responsivity
  16820. columns = columns.reverse();
  16821. columns = columns.sort(function (a, b) {
  16822. var diff = b.modules.responsive.order - a.modules.responsive.order;
  16823. return diff || b.modules.responsive.index - a.modules.responsive.index;
  16824. });
  16825. this.columns = columns;
  16826. if (this.mode === "collapse") {
  16827. this.generateCollapsedContent();
  16828. }
  16829. //assign collapse column
  16830. for (var _iterator = this.table.columnManager.columnsByIndex, _isArray = Array.isArray(_iterator), _i16 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
  16831. var _ref;
  16832. if (_isArray) {
  16833. if (_i16 >= _iterator.length) break;
  16834. _ref = _iterator[_i16++];
  16835. } else {
  16836. _i16 = _iterator.next();
  16837. if (_i16.done) break;
  16838. _ref = _i16.value;
  16839. }
  16840. var col = _ref;
  16841. if (col.definition.formatter == "responsiveCollapse") {
  16842. this.collapseHandleColumn = col;
  16843. break;
  16844. }
  16845. }
  16846. if (this.collapseHandleColumn) {
  16847. if (this.hiddenColumns.length) {
  16848. this.collapseHandleColumn.show();
  16849. } else {
  16850. this.collapseHandleColumn.hide();
  16851. }
  16852. }
  16853. };
  16854. //define layout information
  16855. ResponsiveLayout.prototype.initializeColumn = function (column) {
  16856. var def = column.getDefinition();
  16857. column.modules.responsive = { order: typeof def.responsive === "undefined" ? 1 : def.responsive, visible: def.visible === false ? false : true };
  16858. };
  16859. ResponsiveLayout.prototype.initializeRow = function (row) {
  16860. var el;
  16861. if (row.type !== "calc") {
  16862. el = document.createElement("div");
  16863. el.classList.add("tabulator-responsive-collapse");
  16864. row.modules.responsiveLayout = {
  16865. element: el,
  16866. open: this.collapseStartOpen
  16867. };
  16868. if (!this.collapseStartOpen) {
  16869. el.style.display = 'none';
  16870. }
  16871. }
  16872. };
  16873. ResponsiveLayout.prototype.layoutRow = function (row) {
  16874. var rowEl = row.getElement();
  16875. if (row.modules.responsiveLayout) {
  16876. rowEl.appendChild(row.modules.responsiveLayout.element);
  16877. this.generateCollapsedRowContent(row);
  16878. }
  16879. };
  16880. //update column visibility
  16881. ResponsiveLayout.prototype.updateColumnVisibility = function (column, visible) {
  16882. var index;
  16883. if (column.modules.responsive) {
  16884. column.modules.responsive.visible = visible;
  16885. this.initialize();
  16886. }
  16887. };
  16888. ResponsiveLayout.prototype.hideColumn = function (column) {
  16889. var colCount = this.hiddenColumns.length;
  16890. column.hide(false, true);
  16891. if (this.mode === "collapse") {
  16892. this.hiddenColumns.unshift(column);
  16893. this.generateCollapsedContent();
  16894. if (this.collapseHandleColumn && !colCount) {
  16895. this.collapseHandleColumn.show();
  16896. }
  16897. }
  16898. };
  16899. ResponsiveLayout.prototype.showColumn = function (column) {
  16900. var index;
  16901. column.show(false, true);
  16902. //set column width to prevent calculation loops on uninitialized columns
  16903. column.setWidth(column.getWidth());
  16904. if (this.mode === "collapse") {
  16905. index = this.hiddenColumns.indexOf(column);
  16906. if (index > -1) {
  16907. this.hiddenColumns.splice(index, 1);
  16908. }
  16909. this.generateCollapsedContent();
  16910. if (this.collapseHandleColumn && !this.hiddenColumns.length) {
  16911. this.collapseHandleColumn.hide();
  16912. }
  16913. }
  16914. };
  16915. //redraw columns to fit space
  16916. ResponsiveLayout.prototype.update = function () {
  16917. var self = this,
  16918. working = true;
  16919. while (working) {
  16920. var width = self.table.modules.layout.getMode() == "fitColumns" ? self.table.columnManager.getFlexBaseWidth() : self.table.columnManager.getWidth();
  16921. var diff = (self.table.options.headerVisible ? self.table.columnManager.element.clientWidth : self.table.element.clientWidth) - width;
  16922. if (diff < 0) {
  16923. //table is too wide
  16924. var column = self.columns[self.index];
  16925. if (column) {
  16926. self.hideColumn(column);
  16927. self.index++;
  16928. } else {
  16929. working = false;
  16930. }
  16931. } else {
  16932. //table has spare space
  16933. var _column = self.columns[self.index - 1];
  16934. if (_column) {
  16935. if (diff > 0) {
  16936. if (diff >= _column.getWidth()) {
  16937. self.showColumn(_column);
  16938. self.index--;
  16939. } else {
  16940. working = false;
  16941. }
  16942. } else {
  16943. working = false;
  16944. }
  16945. } else {
  16946. working = false;
  16947. }
  16948. }
  16949. if (!self.table.rowManager.activeRowsCount) {
  16950. self.table.rowManager.renderEmptyScroll();
  16951. }
  16952. }
  16953. };
  16954. ResponsiveLayout.prototype.generateCollapsedContent = function () {
  16955. var self = this,
  16956. rows = this.table.rowManager.getDisplayRows();
  16957. rows.forEach(function (row) {
  16958. self.generateCollapsedRowContent(row);
  16959. });
  16960. };
  16961. ResponsiveLayout.prototype.generateCollapsedRowContent = function (row) {
  16962. var el, contents;
  16963. if (row.modules.responsiveLayout) {
  16964. el = row.modules.responsiveLayout.element;
  16965. while (el.firstChild) {
  16966. el.removeChild(el.firstChild);
  16967. }contents = this.collapseFormatter(this.generateCollapsedRowData(row));
  16968. if (contents) {
  16969. el.appendChild(contents);
  16970. }
  16971. }
  16972. };
  16973. ResponsiveLayout.prototype.generateCollapsedRowData = function (row) {
  16974. var self = this,
  16975. data = row.getData(),
  16976. output = [],
  16977. mockCellComponent;
  16978. this.hiddenColumns.forEach(function (column) {
  16979. var value = column.getFieldValue(data);
  16980. if (column.definition.title && column.field) {
  16981. if (column.modules.format && self.table.options.responsiveLayoutCollapseUseFormatters) {
  16982. mockCellComponent = {
  16983. value: false,
  16984. data: {},
  16985. getValue: function getValue() {
  16986. return value;
  16987. },
  16988. getData: function getData() {
  16989. return data;
  16990. },
  16991. getElement: function getElement() {
  16992. return document.createElement("div");
  16993. },
  16994. getRow: function getRow() {
  16995. return row.getComponent();
  16996. },
  16997. getColumn: function getColumn() {
  16998. return column.getComponent();
  16999. }
  17000. };
  17001. output.push({
  17002. title: column.definition.title,
  17003. value: column.modules.format.formatter.call(self.table.modules.format, mockCellComponent, column.modules.format.params)
  17004. });
  17005. } else {
  17006. output.push({
  17007. title: column.definition.title,
  17008. value: value
  17009. });
  17010. }
  17011. }
  17012. });
  17013. return output;
  17014. };
  17015. ResponsiveLayout.prototype.formatCollapsedData = function (data) {
  17016. var list = document.createElement("table"),
  17017. listContents = "";
  17018. data.forEach(function (item) {
  17019. var div = document.createElement("div");
  17020. if (item.value instanceof Node) {
  17021. div.appendChild(item.value);
  17022. item.value = div.innerHTML;
  17023. }
  17024. listContents += "<tr><td><strong>" + item.title + "</strong></td><td>" + item.value + "</td></tr>";
  17025. });
  17026. list.innerHTML = listContents;
  17027. return Object.keys(data).length ? list : "";
  17028. };
  17029. Tabulator.prototype.registerModule("responsiveLayout", ResponsiveLayout);
  17030. var SelectRow = function SelectRow(table) {
  17031. this.table = table; //hold Tabulator object
  17032. this.selecting = false; //flag selecting in progress
  17033. this.lastClickedRow = false; //last clicked row
  17034. this.selectPrev = []; //hold previously selected element for drag drop selection
  17035. this.selectedRows = []; //hold selected rows
  17036. this.headerCheckboxElement = null; // hold header select element
  17037. };
  17038. SelectRow.prototype.clearSelectionData = function (silent) {
  17039. this.selecting = false;
  17040. this.lastClickedRow = false;
  17041. this.selectPrev = [];
  17042. this.selectedRows = [];
  17043. if (!silent) {
  17044. this._rowSelectionChanged();
  17045. }
  17046. };
  17047. SelectRow.prototype.initializeRow = function (row) {
  17048. var self = this,
  17049. element = row.getElement();
  17050. // trigger end of row selection
  17051. var endSelect = function endSelect() {
  17052. setTimeout(function () {
  17053. self.selecting = false;
  17054. }, 50);
  17055. document.body.removeEventListener("mouseup", endSelect);
  17056. };
  17057. row.modules.select = { selected: false };
  17058. //set row selection class
  17059. if (self.table.options.selectableCheck.call(this.table, row.getComponent())) {
  17060. element.classList.add("tabulator-selectable");
  17061. element.classList.remove("tabulator-unselectable");
  17062. if (self.table.options.selectable && self.table.options.selectable != "highlight") {
  17063. if (self.table.options.selectableRangeMode === "click") {
  17064. element.addEventListener("click", function (e) {
  17065. if (e.shiftKey) {
  17066. self.table._clearSelection();
  17067. self.lastClickedRow = self.lastClickedRow || row;
  17068. var lastClickedRowIdx = self.table.rowManager.getDisplayRowIndex(self.lastClickedRow);
  17069. var rowIdx = self.table.rowManager.getDisplayRowIndex(row);
  17070. var fromRowIdx = lastClickedRowIdx <= rowIdx ? lastClickedRowIdx : rowIdx;
  17071. var toRowIdx = lastClickedRowIdx >= rowIdx ? lastClickedRowIdx : rowIdx;
  17072. var rows = self.table.rowManager.getDisplayRows().slice(0);
  17073. var toggledRows = rows.splice(fromRowIdx, toRowIdx - fromRowIdx + 1);
  17074. if (e.ctrlKey || e.metaKey) {
  17075. toggledRows.forEach(function (toggledRow) {
  17076. if (toggledRow !== self.lastClickedRow) {
  17077. if (self.table.options.selectable !== true && !self.isRowSelected(row)) {
  17078. if (self.selectedRows.length < self.table.options.selectable) {
  17079. self.toggleRow(toggledRow);
  17080. }
  17081. } else {
  17082. self.toggleRow(toggledRow);
  17083. }
  17084. }
  17085. });
  17086. self.lastClickedRow = row;
  17087. } else {
  17088. self.deselectRows(undefined, true);
  17089. if (self.table.options.selectable !== true) {
  17090. if (toggledRows.length > self.table.options.selectable) {
  17091. toggledRows = toggledRows.slice(0, self.table.options.selectable);
  17092. }
  17093. }
  17094. self.selectRows(toggledRows);
  17095. }
  17096. self.table._clearSelection();
  17097. } else if (e.ctrlKey || e.metaKey) {
  17098. self.toggleRow(row);
  17099. self.lastClickedRow = row;
  17100. } else {
  17101. self.deselectRows(undefined, true);
  17102. self.selectRows(row);
  17103. self.lastClickedRow = row;
  17104. }
  17105. });
  17106. } else {
  17107. element.addEventListener("click", function (e) {
  17108. if (!self.table.modExists("edit") || !self.table.modules.edit.getCurrentCell()) {
  17109. self.table._clearSelection();
  17110. }
  17111. if (!self.selecting) {
  17112. self.toggleRow(row);
  17113. }
  17114. });
  17115. element.addEventListener("mousedown", function (e) {
  17116. if (e.shiftKey) {
  17117. self.table._clearSelection();
  17118. self.selecting = true;
  17119. self.selectPrev = [];
  17120. document.body.addEventListener("mouseup", endSelect);
  17121. document.body.addEventListener("keyup", endSelect);
  17122. self.toggleRow(row);
  17123. return false;
  17124. }
  17125. });
  17126. element.addEventListener("mouseenter", function (e) {
  17127. if (self.selecting) {
  17128. self.table._clearSelection();
  17129. self.toggleRow(row);
  17130. if (self.selectPrev[1] == row) {
  17131. self.toggleRow(self.selectPrev[0]);
  17132. }
  17133. }
  17134. });
  17135. element.addEventListener("mouseout", function (e) {
  17136. if (self.selecting) {
  17137. self.table._clearSelection();
  17138. self.selectPrev.unshift(row);
  17139. }
  17140. });
  17141. }
  17142. }
  17143. } else {
  17144. element.classList.add("tabulator-unselectable");
  17145. element.classList.remove("tabulator-selectable");
  17146. }
  17147. };
  17148. //toggle row selection
  17149. SelectRow.prototype.toggleRow = function (row) {
  17150. if (this.table.options.selectableCheck.call(this.table, row.getComponent())) {
  17151. if (row.modules.select && row.modules.select.selected) {
  17152. this._deselectRow(row);
  17153. } else {
  17154. this._selectRow(row);
  17155. }
  17156. }
  17157. };
  17158. //select a number of rows
  17159. SelectRow.prototype.selectRows = function (rows) {
  17160. var _this83 = this;
  17161. var rowMatch;
  17162. switch (typeof rows === 'undefined' ? 'undefined' : _typeof(rows)) {
  17163. case "undefined":
  17164. this.table.rowManager.rows.forEach(function (row) {
  17165. _this83._selectRow(row, true, true);
  17166. });
  17167. this._rowSelectionChanged();
  17168. break;
  17169. case "string":
  17170. rowMatch = this.table.rowManager.findRow(rows);
  17171. if (rowMatch) {
  17172. this._selectRow(rowMatch, true, true);
  17173. } else {
  17174. this.table.rowManager.getRows(rows).forEach(function (row) {
  17175. _this83._selectRow(row, true, true);
  17176. });
  17177. }
  17178. this._rowSelectionChanged();
  17179. break;
  17180. default:
  17181. if (Array.isArray(rows)) {
  17182. rows.forEach(function (row) {
  17183. _this83._selectRow(row, true, true);
  17184. });
  17185. this._rowSelectionChanged();
  17186. } else {
  17187. this._selectRow(rows, false, true);
  17188. }
  17189. break;
  17190. }
  17191. };
  17192. //select an individual row
  17193. SelectRow.prototype._selectRow = function (rowInfo, silent, force) {
  17194. var index;
  17195. //handle max row count
  17196. if (!isNaN(this.table.options.selectable) && this.table.options.selectable !== true && !force) {
  17197. if (this.selectedRows.length >= this.table.options.selectable) {
  17198. if (this.table.options.selectableRollingSelection) {
  17199. this._deselectRow(this.selectedRows[0]);
  17200. } else {
  17201. return false;
  17202. }
  17203. }
  17204. }
  17205. var row = this.table.rowManager.findRow(rowInfo);
  17206. if (row) {
  17207. if (this.selectedRows.indexOf(row) == -1) {
  17208. if (!row.modules.select) {
  17209. row.modules.select = {};
  17210. }
  17211. row.modules.select.selected = true;
  17212. if (row.modules.select.checkboxEl) {
  17213. row.modules.select.checkboxEl.checked = true;
  17214. }
  17215. row.getElement().classList.add("tabulator-selected");
  17216. this.selectedRows.push(row);
  17217. if (this.table.options.dataTreeSelectPropagate) {
  17218. this.childRowSelection(row, true);
  17219. }
  17220. if (!silent) {
  17221. this.table.options.rowSelected.call(this.table, row.getComponent());
  17222. }
  17223. this._rowSelectionChanged(silent);
  17224. }
  17225. } else {
  17226. if (!silent) {
  17227. console.warn("Selection Error - No such row found, ignoring selection:" + rowInfo);
  17228. }
  17229. }
  17230. };
  17231. SelectRow.prototype.isRowSelected = function (row) {
  17232. return this.selectedRows.indexOf(row) !== -1;
  17233. };
  17234. //deselect a number of rows
  17235. SelectRow.prototype.deselectRows = function (rows, silent) {
  17236. var self = this,
  17237. rowCount;
  17238. if (typeof rows == "undefined") {
  17239. rowCount = self.selectedRows.length;
  17240. for (var _i17 = 0; _i17 < rowCount; _i17++) {
  17241. self._deselectRow(self.selectedRows[0], true);
  17242. }
  17243. self._rowSelectionChanged(silent);
  17244. } else {
  17245. if (Array.isArray(rows)) {
  17246. rows.forEach(function (row) {
  17247. self._deselectRow(row, true);
  17248. });
  17249. self._rowSelectionChanged(silent);
  17250. } else {
  17251. self._deselectRow(rows, silent);
  17252. }
  17253. }
  17254. };
  17255. //deselect an individual row
  17256. SelectRow.prototype._deselectRow = function (rowInfo, silent) {
  17257. var self = this,
  17258. row = self.table.rowManager.findRow(rowInfo),
  17259. index;
  17260. if (row) {
  17261. index = self.selectedRows.findIndex(function (selectedRow) {
  17262. return selectedRow == row;
  17263. });
  17264. if (index > -1) {
  17265. if (!row.modules.select) {
  17266. row.modules.select = {};
  17267. }
  17268. row.modules.select.selected = false;
  17269. if (row.modules.select.checkboxEl) {
  17270. row.modules.select.checkboxEl.checked = false;
  17271. }
  17272. row.getElement().classList.remove("tabulator-selected");
  17273. self.selectedRows.splice(index, 1);
  17274. if (this.table.options.dataTreeSelectPropagate) {
  17275. this.childRowSelection(row, false);
  17276. }
  17277. if (!silent) {
  17278. self.table.options.rowDeselected.call(this.table, row.getComponent());
  17279. }
  17280. self._rowSelectionChanged(silent);
  17281. }
  17282. } else {
  17283. if (!silent) {
  17284. console.warn("Deselection Error - No such row found, ignoring selection:" + rowInfo);
  17285. }
  17286. }
  17287. };
  17288. SelectRow.prototype.getSelectedData = function () {
  17289. var data = [];
  17290. this.selectedRows.forEach(function (row) {
  17291. data.push(row.getData());
  17292. });
  17293. return data;
  17294. };
  17295. SelectRow.prototype.getSelectedRows = function () {
  17296. var rows = [];
  17297. this.selectedRows.forEach(function (row) {
  17298. rows.push(row.getComponent());
  17299. });
  17300. return rows;
  17301. };
  17302. SelectRow.prototype._rowSelectionChanged = function (silent) {
  17303. if (this.headerCheckboxElement) {
  17304. if (this.selectedRows.length === 0) {
  17305. this.headerCheckboxElement.checked = false;
  17306. this.headerCheckboxElement.indeterminate = false;
  17307. } else if (this.table.rowManager.rows.length === this.selectedRows.length) {
  17308. this.headerCheckboxElement.checked = true;
  17309. this.headerCheckboxElement.indeterminate = false;
  17310. } else {
  17311. this.headerCheckboxElement.indeterminate = true;
  17312. this.headerCheckboxElement.checked = false;
  17313. }
  17314. }
  17315. if (!silent) {
  17316. this.table.options.rowSelectionChanged.call(this.table, this.getSelectedData(), this.getSelectedRows());
  17317. }
  17318. };
  17319. SelectRow.prototype.registerRowSelectCheckbox = function (row, element) {
  17320. if (!row._row.modules.select) {
  17321. row._row.modules.select = {};
  17322. }
  17323. row._row.modules.select.checkboxEl = element;
  17324. };
  17325. SelectRow.prototype.registerHeaderSelectCheckbox = function (element) {
  17326. this.headerCheckboxElement = element;
  17327. };
  17328. SelectRow.prototype.childRowSelection = function (row, select) {
  17329. var children = this.table.modules.dataTree.getChildren(row);
  17330. if (select) {
  17331. for (var _iterator2 = children, _isArray2 = Array.isArray(_iterator2), _i18 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
  17332. var _ref2;
  17333. if (_isArray2) {
  17334. if (_i18 >= _iterator2.length) break;
  17335. _ref2 = _iterator2[_i18++];
  17336. } else {
  17337. _i18 = _iterator2.next();
  17338. if (_i18.done) break;
  17339. _ref2 = _i18.value;
  17340. }
  17341. var child = _ref2;
  17342. this._selectRow(child, true);
  17343. }
  17344. } else {
  17345. for (var _iterator3 = children, _isArray3 = Array.isArray(_iterator3), _i19 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
  17346. var _ref3;
  17347. if (_isArray3) {
  17348. if (_i19 >= _iterator3.length) break;
  17349. _ref3 = _iterator3[_i19++];
  17350. } else {
  17351. _i19 = _iterator3.next();
  17352. if (_i19.done) break;
  17353. _ref3 = _i19.value;
  17354. }
  17355. var _child = _ref3;
  17356. this._deselectRow(_child, true);
  17357. }
  17358. }
  17359. };
  17360. Tabulator.prototype.registerModule("selectRow", SelectRow);
  17361. var Sort = function Sort(table) {
  17362. this.table = table; //hold Tabulator object
  17363. this.sortList = []; //holder current sort
  17364. this.changed = false; //has the sort changed since last render
  17365. };
  17366. //initialize column header for sorting
  17367. Sort.prototype.initializeColumn = function (column, content) {
  17368. var self = this,
  17369. sorter = false,
  17370. colEl,
  17371. arrowEl;
  17372. switch (_typeof(column.definition.sorter)) {
  17373. case "string":
  17374. if (self.sorters[column.definition.sorter]) {
  17375. sorter = self.sorters[column.definition.sorter];
  17376. } else {
  17377. console.warn("Sort Error - No such sorter found: ", column.definition.sorter);
  17378. }
  17379. break;
  17380. case "function":
  17381. sorter = column.definition.sorter;
  17382. break;
  17383. }
  17384. column.modules.sort = {
  17385. sorter: sorter, dir: "none",
  17386. params: column.definition.sorterParams || {},
  17387. startingDir: column.definition.headerSortStartingDir || "asc",
  17388. tristate: typeof column.definition.headerSortTristate !== "undefined" ? column.definition.headerSortTristate : this.table.options.headerSortTristate
  17389. };
  17390. if (typeof column.definition.headerSort === "undefined" ? this.table.options.headerSort !== false : column.definition.headerSort !== false) {
  17391. colEl = column.getElement();
  17392. colEl.classList.add("tabulator-sortable");
  17393. arrowEl = document.createElement("div");
  17394. arrowEl.classList.add("tabulator-col-sorter");
  17395. if (_typeof(this.table.options.headerSortElement) == "object") {
  17396. arrowEl.appendChild(this.table.options.headerSortElement);
  17397. } else {
  17398. arrowEl.innerHTML = this.table.options.headerSortElement;
  17399. }
  17400. //create sorter arrow
  17401. content.appendChild(arrowEl);
  17402. column.modules.sort.element = arrowEl;
  17403. //sort on click
  17404. colEl.addEventListener("click", function (e) {
  17405. var dir = "",
  17406. sorters = [],
  17407. match = false;
  17408. if (column.modules.sort) {
  17409. if (column.modules.sort.tristate) {
  17410. if (column.modules.sort.dir == "none") {
  17411. dir = column.modules.sort.startingDir;
  17412. } else {
  17413. if (column.modules.sort.dir == column.modules.sort.startingDir) {
  17414. dir = column.modules.sort.dir == "asc" ? "desc" : "asc";
  17415. } else {
  17416. dir = "none";
  17417. }
  17418. }
  17419. } else {
  17420. switch (column.modules.sort.dir) {
  17421. case "asc":
  17422. dir = "desc";
  17423. break;
  17424. case "desc":
  17425. dir = "asc";
  17426. break;
  17427. default:
  17428. dir = column.modules.sort.startingDir;
  17429. }
  17430. }
  17431. if (self.table.options.columnHeaderSortMulti && (e.shiftKey || e.ctrlKey)) {
  17432. sorters = self.getSort();
  17433. match = sorters.findIndex(function (sorter) {
  17434. return sorter.field === column.getField();
  17435. });
  17436. if (match > -1) {
  17437. sorters[match].dir = dir;
  17438. if (match != sorters.length - 1) {
  17439. match = sorters.splice(match, 1)[0];
  17440. if (dir != "none") {
  17441. sorters.push(match);
  17442. }
  17443. }
  17444. } else {
  17445. if (dir != "none") {
  17446. sorters.push({ column: column, dir: dir });
  17447. }
  17448. }
  17449. //add to existing sort
  17450. self.setSort(sorters);
  17451. } else {
  17452. if (dir == "none") {
  17453. self.clear();
  17454. } else {
  17455. //sort by column only
  17456. self.setSort(column, dir);
  17457. }
  17458. }
  17459. self.table.rowManager.sorterRefresh(!self.sortList.length);
  17460. }
  17461. });
  17462. }
  17463. };
  17464. //check if the sorters have changed since last use
  17465. Sort.prototype.hasChanged = function () {
  17466. var changed = this.changed;
  17467. this.changed = false;
  17468. return changed;
  17469. };
  17470. //return current sorters
  17471. Sort.prototype.getSort = function () {
  17472. var self = this,
  17473. sorters = [];
  17474. self.sortList.forEach(function (item) {
  17475. if (item.column) {
  17476. sorters.push({ column: item.column.getComponent(), field: item.column.getField(), dir: item.dir });
  17477. }
  17478. });
  17479. return sorters;
  17480. };
  17481. //change sort list and trigger sort
  17482. Sort.prototype.setSort = function (sortList, dir) {
  17483. var self = this,
  17484. newSortList = [];
  17485. if (!Array.isArray(sortList)) {
  17486. sortList = [{ column: sortList, dir: dir }];
  17487. }
  17488. sortList.forEach(function (item) {
  17489. var column;
  17490. column = self.table.columnManager.findColumn(item.column);
  17491. if (column) {
  17492. item.column = column;
  17493. newSortList.push(item);
  17494. self.changed = true;
  17495. } else {
  17496. console.warn("Sort Warning - Sort field does not exist and is being ignored: ", item.column);
  17497. }
  17498. });
  17499. self.sortList = newSortList;
  17500. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.sort) {
  17501. this.table.modules.persistence.save("sort");
  17502. }
  17503. };
  17504. //clear sorters
  17505. Sort.prototype.clear = function () {
  17506. this.setSort([]);
  17507. };
  17508. //find appropriate sorter for column
  17509. Sort.prototype.findSorter = function (column) {
  17510. var row = this.table.rowManager.activeRows[0],
  17511. sorter = "string",
  17512. field,
  17513. value;
  17514. if (row) {
  17515. row = row.getData();
  17516. field = column.getField();
  17517. if (field) {
  17518. value = column.getFieldValue(row);
  17519. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  17520. case "undefined":
  17521. sorter = "string";
  17522. break;
  17523. case "boolean":
  17524. sorter = "boolean";
  17525. break;
  17526. default:
  17527. if (!isNaN(value) && value !== "") {
  17528. sorter = "number";
  17529. } else {
  17530. if (value.match(/((^[0-9]+[a-z]+)|(^[a-z]+[0-9]+))+$/i)) {
  17531. sorter = "alphanum";
  17532. }
  17533. }
  17534. break;
  17535. }
  17536. }
  17537. }
  17538. return this.sorters[sorter];
  17539. };
  17540. //work through sort list sorting data
  17541. Sort.prototype.sort = function (data) {
  17542. var self = this,
  17543. sortList = this.table.options.sortOrderReverse ? self.sortList.slice().reverse() : self.sortList,
  17544. sortListActual = [],
  17545. rowComponents = [],
  17546. lastSort;
  17547. if (self.table.options.dataSorting) {
  17548. self.table.options.dataSorting.call(self.table, self.getSort());
  17549. }
  17550. self.clearColumnHeaders();
  17551. if (!self.table.options.ajaxSorting) {
  17552. //build list of valid sorters and trigger column specific callbacks before sort begins
  17553. sortList.forEach(function (item, i) {
  17554. var sortObj = item.column.modules.sort;
  17555. if (item.column && sortObj) {
  17556. //if no sorter has been defined, take a guess
  17557. if (!sortObj.sorter) {
  17558. sortObj.sorter = self.findSorter(item.column);
  17559. }
  17560. item.params = typeof sortObj.params === "function" ? sortObj.params(item.column.getComponent(), item.dir) : sortObj.params;
  17561. sortListActual.push(item);
  17562. }
  17563. self.setColumnHeader(item.column, item.dir);
  17564. });
  17565. //sort data
  17566. if (sortListActual.length) {
  17567. self._sortItems(data, sortListActual);
  17568. }
  17569. } else {
  17570. sortList.forEach(function (item, i) {
  17571. self.setColumnHeader(item.column, item.dir);
  17572. });
  17573. }
  17574. if (self.table.options.dataSorted) {
  17575. data.forEach(function (row) {
  17576. rowComponents.push(row.getComponent());
  17577. });
  17578. self.table.options.dataSorted.call(self.table, self.getSort(), rowComponents);
  17579. }
  17580. };
  17581. //clear sort arrows on columns
  17582. Sort.prototype.clearColumnHeaders = function () {
  17583. this.table.columnManager.getRealColumns().forEach(function (column) {
  17584. if (column.modules.sort) {
  17585. column.modules.sort.dir = "none";
  17586. column.getElement().setAttribute("aria-sort", "none");
  17587. }
  17588. });
  17589. };
  17590. //set the column header sort direction
  17591. Sort.prototype.setColumnHeader = function (column, dir) {
  17592. column.modules.sort.dir = dir;
  17593. column.getElement().setAttribute("aria-sort", dir);
  17594. };
  17595. //sort each item in sort list
  17596. Sort.prototype._sortItems = function (data, sortList) {
  17597. var _this84 = this;
  17598. var sorterCount = sortList.length - 1;
  17599. data.sort(function (a, b) {
  17600. var result;
  17601. for (var i = sorterCount; i >= 0; i--) {
  17602. var sortItem = sortList[i];
  17603. result = _this84._sortRow(a, b, sortItem.column, sortItem.dir, sortItem.params);
  17604. if (result !== 0) {
  17605. break;
  17606. }
  17607. }
  17608. return result;
  17609. });
  17610. };
  17611. //process individual rows for a sort function on active data
  17612. Sort.prototype._sortRow = function (a, b, column, dir, params) {
  17613. var el1Comp, el2Comp, colComp;
  17614. //switch elements depending on search direction
  17615. var el1 = dir == "asc" ? a : b;
  17616. var el2 = dir == "asc" ? b : a;
  17617. a = column.getFieldValue(el1.getData());
  17618. b = column.getFieldValue(el2.getData());
  17619. a = typeof a !== "undefined" ? a : "";
  17620. b = typeof b !== "undefined" ? b : "";
  17621. el1Comp = el1.getComponent();
  17622. el2Comp = el2.getComponent();
  17623. return column.modules.sort.sorter.call(this, a, b, el1Comp, el2Comp, column.getComponent(), dir, params);
  17624. };
  17625. //default data sorters
  17626. Sort.prototype.sorters = {
  17627. //sort numbers
  17628. number: function number(a, b, aRow, bRow, column, dir, params) {
  17629. var alignEmptyValues = params.alignEmptyValues;
  17630. var decimal = params.decimalSeparator || ".";
  17631. var thousand = params.thousandSeparator || ",";
  17632. var emptyAlign = 0;
  17633. a = parseFloat(String(a).split(thousand).join("").split(decimal).join("."));
  17634. b = parseFloat(String(b).split(thousand).join("").split(decimal).join("."));
  17635. //handle non numeric values
  17636. if (isNaN(a)) {
  17637. emptyAlign = isNaN(b) ? 0 : -1;
  17638. } else if (isNaN(b)) {
  17639. emptyAlign = 1;
  17640. } else {
  17641. //compare valid values
  17642. return a - b;
  17643. }
  17644. //fix empty values in position
  17645. if (alignEmptyValues === "top" && dir === "desc" || alignEmptyValues === "bottom" && dir === "asc") {
  17646. emptyAlign *= -1;
  17647. }
  17648. return emptyAlign;
  17649. },
  17650. //sort strings
  17651. string: function string(a, b, aRow, bRow, column, dir, params) {
  17652. var alignEmptyValues = params.alignEmptyValues;
  17653. var emptyAlign = 0;
  17654. var locale;
  17655. //handle empty values
  17656. if (!a) {
  17657. emptyAlign = !b ? 0 : -1;
  17658. } else if (!b) {
  17659. emptyAlign = 1;
  17660. } else {
  17661. //compare valid values
  17662. switch (_typeof(params.locale)) {
  17663. case "boolean":
  17664. if (params.locale) {
  17665. locale = this.table.modules.localize.getLocale();
  17666. }
  17667. break;
  17668. case "string":
  17669. locale = params.locale;
  17670. break;
  17671. }
  17672. return String(a).toLowerCase().localeCompare(String(b).toLowerCase(), locale);
  17673. }
  17674. //fix empty values in position
  17675. if (alignEmptyValues === "top" && dir === "desc" || alignEmptyValues === "bottom" && dir === "asc") {
  17676. emptyAlign *= -1;
  17677. }
  17678. return emptyAlign;
  17679. },
  17680. //sort date
  17681. date: function date(a, b, aRow, bRow, column, dir, params) {
  17682. if (!params.format) {
  17683. params.format = "DD/MM/YYYY";
  17684. }
  17685. return this.sorters.datetime.call(this, a, b, aRow, bRow, column, dir, params);
  17686. },
  17687. //sort HH:mm formatted times
  17688. time: function time(a, b, aRow, bRow, column, dir, params) {
  17689. if (!params.format) {
  17690. params.format = "HH:mm";
  17691. }
  17692. return this.sorters.datetime.call(this, a, b, aRow, bRow, column, dir, params);
  17693. },
  17694. //sort datetime
  17695. datetime: function datetime(a, b, aRow, bRow, column, dir, params) {
  17696. var format = params.format || "DD/MM/YYYY HH:mm:ss",
  17697. alignEmptyValues = params.alignEmptyValues,
  17698. emptyAlign = 0;
  17699. if (typeof moment != "undefined") {
  17700. a = moment(a, format);
  17701. b = moment(b, format);
  17702. if (!a.isValid()) {
  17703. emptyAlign = !b.isValid() ? 0 : -1;
  17704. } else if (!b.isValid()) {
  17705. emptyAlign = 1;
  17706. } else {
  17707. //compare valid values
  17708. return a - b;
  17709. }
  17710. //fix empty values in position
  17711. if (alignEmptyValues === "top" && dir === "desc" || alignEmptyValues === "bottom" && dir === "asc") {
  17712. emptyAlign *= -1;
  17713. }
  17714. return emptyAlign;
  17715. } else {
  17716. console.error("Sort Error - 'datetime' sorter is dependant on moment.js");
  17717. }
  17718. },
  17719. //sort booleans
  17720. boolean: function boolean(a, b, aRow, bRow, column, dir, params) {
  17721. var el1 = a === true || a === "true" || a === "True" || a === 1 ? 1 : 0;
  17722. var el2 = b === true || b === "true" || b === "True" || b === 1 ? 1 : 0;
  17723. return el1 - el2;
  17724. },
  17725. //sort if element contains any data
  17726. array: function array(a, b, aRow, bRow, column, dir, params) {
  17727. var el1 = 0;
  17728. var el2 = 0;
  17729. var type = params.type || "length";
  17730. var alignEmptyValues = params.alignEmptyValues;
  17731. var emptyAlign = 0;
  17732. function calc(value) {
  17733. switch (type) {
  17734. case "length":
  17735. return value.length;
  17736. break;
  17737. case "sum":
  17738. return value.reduce(function (c, d) {
  17739. return c + d;
  17740. });
  17741. break;
  17742. case "max":
  17743. return Math.max.apply(null, value);
  17744. break;
  17745. case "min":
  17746. return Math.min.apply(null, value);
  17747. break;
  17748. case "avg":
  17749. return value.reduce(function (c, d) {
  17750. return c + d;
  17751. }) / value.length;
  17752. break;
  17753. }
  17754. }
  17755. //handle non array values
  17756. if (!Array.isArray(a)) {
  17757. alignEmptyValues = !Array.isArray(b) ? 0 : -1;
  17758. } else if (!Array.isArray(b)) {
  17759. alignEmptyValues = 1;
  17760. } else {
  17761. //compare valid values
  17762. el1 = a ? calc(a) : 0;
  17763. el2 = b ? calc(b) : 0;
  17764. return el1 - el2;
  17765. }
  17766. //fix empty values in position
  17767. if (alignEmptyValues === "top" && dir === "desc" || alignEmptyValues === "bottom" && dir === "asc") {
  17768. emptyAlign *= -1;
  17769. }
  17770. return emptyAlign;
  17771. },
  17772. //sort if element contains any data
  17773. exists: function exists(a, b, aRow, bRow, column, dir, params) {
  17774. var el1 = typeof a == "undefined" ? 0 : 1;
  17775. var el2 = typeof b == "undefined" ? 0 : 1;
  17776. return el1 - el2;
  17777. },
  17778. //sort alpha numeric strings
  17779. alphanum: function alphanum(as, bs, aRow, bRow, column, dir, params) {
  17780. var a,
  17781. b,
  17782. a1,
  17783. b1,
  17784. i = 0,
  17785. L,
  17786. rx = /(\d+)|(\D+)/g,
  17787. rd = /\d/;
  17788. var alignEmptyValues = params.alignEmptyValues;
  17789. var emptyAlign = 0;
  17790. //handle empty values
  17791. if (!as && as !== 0) {
  17792. emptyAlign = !bs && bs !== 0 ? 0 : -1;
  17793. } else if (!bs && bs !== 0) {
  17794. emptyAlign = 1;
  17795. } else {
  17796. if (isFinite(as) && isFinite(bs)) return as - bs;
  17797. a = String(as).toLowerCase();
  17798. b = String(bs).toLowerCase();
  17799. if (a === b) return 0;
  17800. if (!(rd.test(a) && rd.test(b))) return a > b ? 1 : -1;
  17801. a = a.match(rx);
  17802. b = b.match(rx);
  17803. L = a.length > b.length ? b.length : a.length;
  17804. while (i < L) {
  17805. a1 = a[i];
  17806. b1 = b[i++];
  17807. if (a1 !== b1) {
  17808. if (isFinite(a1) && isFinite(b1)) {
  17809. if (a1.charAt(0) === "0") a1 = "." + a1;
  17810. if (b1.charAt(0) === "0") b1 = "." + b1;
  17811. return a1 - b1;
  17812. } else return a1 > b1 ? 1 : -1;
  17813. }
  17814. }
  17815. return a.length > b.length;
  17816. }
  17817. //fix empty values in position
  17818. if (alignEmptyValues === "top" && dir === "desc" || alignEmptyValues === "bottom" && dir === "asc") {
  17819. emptyAlign *= -1;
  17820. }
  17821. return emptyAlign;
  17822. }
  17823. };
  17824. Tabulator.prototype.registerModule("sort", Sort);
  17825. var Validate = function Validate(table) {
  17826. this.table = table;
  17827. this.invalidCells = [];
  17828. };
  17829. //validate
  17830. Validate.prototype.initializeColumn = function (column) {
  17831. var self = this,
  17832. config = [],
  17833. validator;
  17834. if (column.definition.validator) {
  17835. if (Array.isArray(column.definition.validator)) {
  17836. column.definition.validator.forEach(function (item) {
  17837. validator = self._extractValidator(item);
  17838. if (validator) {
  17839. config.push(validator);
  17840. }
  17841. });
  17842. } else {
  17843. validator = this._extractValidator(column.definition.validator);
  17844. if (validator) {
  17845. config.push(validator);
  17846. }
  17847. }
  17848. column.modules.validate = config.length ? config : false;
  17849. }
  17850. };
  17851. Validate.prototype._extractValidator = function (value) {
  17852. var type, params, pos;
  17853. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  17854. case "string":
  17855. pos = value.indexOf(':');
  17856. if (pos > -1) {
  17857. type = value.substring(0, pos);
  17858. params = value.substring(pos + 1);
  17859. } else {
  17860. type = value;
  17861. }
  17862. return this._buildValidator(type, params);
  17863. break;
  17864. case "function":
  17865. return this._buildValidator(value);
  17866. break;
  17867. case "object":
  17868. return this._buildValidator(value.type, value.parameters);
  17869. break;
  17870. }
  17871. };
  17872. Validate.prototype._buildValidator = function (type, params) {
  17873. var func = typeof type == "function" ? type : this.validators[type];
  17874. if (!func) {
  17875. console.warn("Validator Setup Error - No matching validator found:", type);
  17876. return false;
  17877. } else {
  17878. return {
  17879. type: typeof type == "function" ? "function" : type,
  17880. func: func,
  17881. params: params
  17882. };
  17883. }
  17884. };
  17885. Validate.prototype.validate = function (validators, cell, value) {
  17886. var self = this,
  17887. valid = [],
  17888. invalidIndex = this.invalidCells.indexOf(cell);
  17889. if (validators) {
  17890. validators.forEach(function (item) {
  17891. if (!item.func.call(self, cell.getComponent(), value, item.params)) {
  17892. valid.push({
  17893. type: item.type,
  17894. parameters: item.params
  17895. });
  17896. }
  17897. });
  17898. }
  17899. valid = valid.length ? valid : true;
  17900. if (!cell.modules.validate) {
  17901. cell.modules.validate = {};
  17902. }
  17903. if (valid === true) {
  17904. cell.modules.validate.invalid = false;
  17905. cell.getElement().classList.remove("tabulator-validation-fail");
  17906. if (invalidIndex > -1) {
  17907. this.invalidCells.splice(invalidIndex, 1);
  17908. }
  17909. } else {
  17910. cell.modules.validate.invalid = true;
  17911. if (this.table.options.validationMode !== "manual") {
  17912. cell.getElement().classList.add("tabulator-validation-fail");
  17913. }
  17914. if (invalidIndex == -1) {
  17915. this.invalidCells.push(cell);
  17916. }
  17917. }
  17918. return valid;
  17919. };
  17920. Validate.prototype.getInvalidCells = function () {
  17921. var output = [];
  17922. this.invalidCells.forEach(function (cell) {
  17923. output.push(cell.getComponent());
  17924. });
  17925. return output;
  17926. };
  17927. Validate.prototype.clearValidation = function (cell) {
  17928. var invalidIndex;
  17929. if (cell.modules.validate && cell.modules.validate.invalid) {
  17930. cell.getElement().classList.remove("tabulator-validation-fail");
  17931. cell.modules.validate.invalid = false;
  17932. invalidIndex = this.invalidCells.indexOf(cell);
  17933. if (invalidIndex > -1) {
  17934. this.invalidCells.splice(invalidIndex, 1);
  17935. }
  17936. }
  17937. };
  17938. Validate.prototype.validators = {
  17939. //is integer
  17940. integer: function integer(cell, value, parameters) {
  17941. if (value === "" || value === null || typeof value === "undefined") {
  17942. return true;
  17943. }
  17944. value = Number(value);
  17945. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  17946. },
  17947. //is float
  17948. float: function float(cell, value, parameters) {
  17949. if (value === "" || value === null || typeof value === "undefined") {
  17950. return true;
  17951. }
  17952. value = Number(value);
  17953. return typeof value === 'number' && isFinite(value) && value % 1 !== 0;
  17954. },
  17955. //must be a number
  17956. numeric: function numeric(cell, value, parameters) {
  17957. if (value === "" || value === null || typeof value === "undefined") {
  17958. return true;
  17959. }
  17960. return !isNaN(value);
  17961. },
  17962. //must be a string
  17963. string: function string(cell, value, parameters) {
  17964. if (value === "" || value === null || typeof value === "undefined") {
  17965. return true;
  17966. }
  17967. return isNaN(value);
  17968. },
  17969. //maximum value
  17970. max: function max(cell, value, parameters) {
  17971. if (value === "" || value === null || typeof value === "undefined") {
  17972. return true;
  17973. }
  17974. return parseFloat(value) <= parameters;
  17975. },
  17976. //minimum value
  17977. min: function min(cell, value, parameters) {
  17978. if (value === "" || value === null || typeof value === "undefined") {
  17979. return true;
  17980. }
  17981. return parseFloat(value) >= parameters;
  17982. },
  17983. //starts with value
  17984. starts: function starts(cell, value, parameters) {
  17985. if (value === "" || value === null || typeof value === "undefined") {
  17986. return true;
  17987. }
  17988. return String(value).toLowerCase().startsWith(String(parameters).toLowerCase());
  17989. },
  17990. //ends with value
  17991. ends: function ends(cell, value, parameters) {
  17992. if (value === "" || value === null || typeof value === "undefined") {
  17993. return true;
  17994. }
  17995. return String(value).toLowerCase().endsWith(String(parameters).toLowerCase());
  17996. },
  17997. //minimum string length
  17998. minLength: function minLength(cell, value, parameters) {
  17999. if (value === "" || value === null || typeof value === "undefined") {
  18000. return true;
  18001. }
  18002. return String(value).length >= parameters;
  18003. },
  18004. //maximum string length
  18005. maxLength: function maxLength(cell, value, parameters) {
  18006. if (value === "" || value === null || typeof value === "undefined") {
  18007. return true;
  18008. }
  18009. return String(value).length <= parameters;
  18010. },
  18011. //in provided value list
  18012. in: function _in(cell, value, parameters) {
  18013. if (value === "" || value === null || typeof value === "undefined") {
  18014. return true;
  18015. }
  18016. if (typeof parameters == "string") {
  18017. parameters = parameters.split("|");
  18018. }
  18019. return value === "" || parameters.indexOf(value) > -1;
  18020. },
  18021. //must match provided regex
  18022. regex: function regex(cell, value, parameters) {
  18023. if (value === "" || value === null || typeof value === "undefined") {
  18024. return true;
  18025. }
  18026. var reg = new RegExp(parameters);
  18027. return reg.test(value);
  18028. },
  18029. //value must be unique in this column
  18030. unique: function unique(cell, value, parameters) {
  18031. if (value === "" || value === null || typeof value === "undefined") {
  18032. return true;
  18033. }
  18034. var unique = true;
  18035. var cellData = cell.getData();
  18036. var column = cell.getColumn()._getSelf();
  18037. this.table.rowManager.rows.forEach(function (row) {
  18038. var data = row.getData();
  18039. if (data !== cellData) {
  18040. if (value == column.getFieldValue(data)) {
  18041. unique = false;
  18042. }
  18043. }
  18044. });
  18045. return unique;
  18046. },
  18047. //must have a value
  18048. required: function required(cell, value, parameters) {
  18049. return value !== "" && value !== null && typeof value !== "undefined";
  18050. }
  18051. };
  18052. Tabulator.prototype.registerModule("validate", Validate);
  18053. export default Tabulator;