Built files from Bizgaze WebServer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tabulator.js 602KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236
  1. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  2. /* Tabulator v4.8.2 (c) Oliver Folkerd */
  3. ;(function (global, factory) {
  4. if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object' && typeof module !== 'undefined') {
  5. module.exports = factory();
  6. } else if (typeof define === 'function' && define.amd) {
  7. define(factory);
  8. } else {
  9. global.Tabulator = factory();
  10. }
  11. })(this, function () {
  12. 'use strict';
  13. // https://tc39.github.io/ecma262/#sec-array.prototype.findIndex
  14. if (!Array.prototype.findIndex) {
  15. Object.defineProperty(Array.prototype, 'findIndex', {
  16. value: function value(predicate) {
  17. // 1. Let O be ? ToObject(this value).
  18. if (this == null) {
  19. throw new TypeError('"this" is null or not defined');
  20. }
  21. var o = Object(this);
  22. // 2. Let len be ? ToLength(? Get(O, "length")).
  23. var len = o.length >>> 0;
  24. // 3. If IsCallable(predicate) is false, throw a TypeError exception.
  25. if (typeof predicate !== 'function') {
  26. throw new TypeError('predicate must be a function');
  27. }
  28. // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
  29. var thisArg = arguments[1];
  30. // 5. Let k be 0.
  31. var k = 0;
  32. // 6. Repeat, while k < len
  33. while (k < len) {
  34. // a. Let Pk be ! ToString(k).
  35. // b. Let kValue be ? Get(O, Pk).
  36. // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
  37. // d. If testResult is true, return k.
  38. var kValue = o[k];
  39. if (predicate.call(thisArg, kValue, k, o)) {
  40. return k;
  41. }
  42. // e. Increase k by 1.
  43. k++;
  44. }
  45. // 7. Return -1.
  46. return -1;
  47. }
  48. });
  49. }
  50. // https://tc39.github.io/ecma262/#sec-array.prototype.find
  51. if (!Array.prototype.find) {
  52. Object.defineProperty(Array.prototype, 'find', {
  53. value: function value(predicate) {
  54. // 1. Let O be ? ToObject(this value).
  55. if (this == null) {
  56. throw new TypeError('"this" is null or not defined');
  57. }
  58. var o = Object(this);
  59. // 2. Let len be ? ToLength(? Get(O, "length")).
  60. var len = o.length >>> 0;
  61. // 3. If IsCallable(predicate) is false, throw a TypeError exception.
  62. if (typeof predicate !== 'function') {
  63. throw new TypeError('predicate must be a function');
  64. }
  65. // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
  66. var thisArg = arguments[1];
  67. // 5. Let k be 0.
  68. var k = 0;
  69. // 6. Repeat, while k < len
  70. while (k < len) {
  71. // a. Let Pk be ! ToString(k).
  72. // b. Let kValue be ? Get(O, Pk).
  73. // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
  74. // d. If testResult is true, return kValue.
  75. var kValue = o[k];
  76. if (predicate.call(thisArg, kValue, k, o)) {
  77. return kValue;
  78. }
  79. // e. Increase k by 1.
  80. k++;
  81. }
  82. // 7. Return undefined.
  83. return undefined;
  84. }
  85. });
  86. }
  87. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes#Polyfill
  88. if (!String.prototype.includes) {
  89. String.prototype.includes = function (search, start) {
  90. 'use strict';
  91. if (search instanceof RegExp) {
  92. throw TypeError('first argument must not be a RegExp');
  93. }
  94. if (start === undefined) {
  95. start = 0;
  96. }
  97. return this.indexOf(search, start) !== -1;
  98. };
  99. }
  100. // https://tc39.github.io/ecma262/#sec-array.prototype.includes
  101. if (!Array.prototype.includes) {
  102. Object.defineProperty(Array.prototype, 'includes', {
  103. value: function value(searchElement, fromIndex) {
  104. if (this == null) {
  105. throw new TypeError('"this" is null or not defined');
  106. }
  107. // 1. Let O be ? ToObject(this value).
  108. var o = Object(this);
  109. // 2. Let len be ? ToLength(? Get(O, "length")).
  110. var len = o.length >>> 0;
  111. // 3. If len is 0, return false.
  112. if (len === 0) {
  113. return false;
  114. }
  115. // 4. Let n be ? ToInteger(fromIndex).
  116. // (If fromIndex is undefined, this step produces the value 0.)
  117. var n = fromIndex | 0;
  118. // 5. If n ≥ 0, then
  119. // a. Let k be n.
  120. // 6. Else n < 0,
  121. // a. Let k be len + n.
  122. // b. If k < 0, let k be 0.
  123. var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
  124. function sameValueZero(x, y) {
  125. return x === y || typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y);
  126. }
  127. // 7. Repeat, while k < len
  128. while (k < len) {
  129. // a. Let elementK be the result of ? Get(O, ! ToString(k)).
  130. // b. If SameValueZero(searchElement, elementK) is true, return true.
  131. if (sameValueZero(o[k], searchElement)) {
  132. return true;
  133. }
  134. // c. Increase k by 1.
  135. k++;
  136. }
  137. // 8. Return false
  138. return false;
  139. }
  140. });
  141. }
  142. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill
  143. if (typeof Object.assign !== 'function') {
  144. // Must be writable: true, enumerable: false, configurable: true
  145. Object.defineProperty(Object, "assign", {
  146. value: function assign(target, varArgs) {
  147. // .length of function is 2
  148. 'use strict';
  149. if (target === null || target === undefined) {
  150. throw new TypeError('Cannot convert undefined or null to object');
  151. }
  152. var to = Object(target);
  153. for (var index = 1; index < arguments.length; index++) {
  154. var nextSource = arguments[index];
  155. if (nextSource !== null && nextSource !== undefined) {
  156. for (var nextKey in nextSource) {
  157. // Avoid bugs when hasOwnProperty is shadowed
  158. if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
  159. to[nextKey] = nextSource[nextKey];
  160. }
  161. }
  162. }
  163. }
  164. return to;
  165. },
  166. writable: true,
  167. configurable: true
  168. });
  169. }
  170. var ColumnManager = function ColumnManager(table) {
  171. this.table = table; //hold parent table
  172. this.blockHozScrollEvent = false;
  173. this.headersElement = this.createHeadersElement();
  174. this.element = this.createHeaderElement(); //containing element
  175. this.rowManager = null; //hold row manager object
  176. this.columns = []; // column definition object
  177. this.columnsByIndex = []; //columns by index
  178. this.columnsByField = {}; //columns by field
  179. this.scrollLeft = 0;
  180. this.element.insertBefore(this.headersElement, this.element.firstChild);
  181. };
  182. ////////////// Setup Functions /////////////////
  183. ColumnManager.prototype.createHeadersElement = function () {
  184. var el = document.createElement("div");
  185. el.classList.add("tabulator-headers");
  186. return el;
  187. };
  188. ColumnManager.prototype.createHeaderElement = function () {
  189. var el = document.createElement("div");
  190. el.classList.add("tabulator-header");
  191. if (!this.table.options.headerVisible) {
  192. el.classList.add("tabulator-header-hidden");
  193. }
  194. return el;
  195. };
  196. ColumnManager.prototype.initialize = function () {
  197. var self = this;
  198. //scroll body along with header
  199. // self.element.addEventListener("scroll", function(e){
  200. // if(!self.blockHozScrollEvent){
  201. // self.table.rowManager.scrollHorizontal(self.element.scrollLeft);
  202. // }
  203. // });
  204. };
  205. //link to row manager
  206. ColumnManager.prototype.setRowManager = function (manager) {
  207. this.rowManager = manager;
  208. };
  209. //return containing element
  210. ColumnManager.prototype.getElement = function () {
  211. return this.element;
  212. };
  213. //return header containing element
  214. ColumnManager.prototype.getHeadersElement = function () {
  215. return this.headersElement;
  216. };
  217. // ColumnManager.prototype.tempScrollBlock = function(){
  218. // clearTimeout(this.blockHozScrollEvent);
  219. // this.blockHozScrollEvent = setTimeout(() => {this.blockHozScrollEvent = false;}, 50);
  220. // }
  221. //scroll horizontally to match table body
  222. ColumnManager.prototype.scrollHorizontal = function (left) {
  223. var hozAdjust = 0,
  224. scrollWidth = this.element.scrollWidth - this.table.element.clientWidth;
  225. // this.tempScrollBlock();
  226. this.element.scrollLeft = left;
  227. //adjust for vertical scrollbar moving table when present
  228. if (left > scrollWidth) {
  229. hozAdjust = left - scrollWidth;
  230. this.element.style.marginLeft = -hozAdjust + "px";
  231. } else {
  232. this.element.style.marginLeft = 0;
  233. }
  234. //keep frozen columns fixed in position
  235. //this._calcFrozenColumnsPos(hozAdjust + 3);
  236. this.scrollLeft = left;
  237. if (this.table.modExists("frozenColumns")) {
  238. this.table.modules.frozenColumns.scrollHorizontal();
  239. }
  240. };
  241. ///////////// Column Setup Functions /////////////
  242. ColumnManager.prototype.generateColumnsFromRowData = function (data) {
  243. var cols = [],
  244. definitions = this.table.options.autoColumnsDefinitions,
  245. row,
  246. sorter;
  247. if (data && data.length) {
  248. row = data[0];
  249. for (var key in row) {
  250. var col = {
  251. field: key,
  252. title: key
  253. };
  254. var value = row[key];
  255. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  256. case "undefined":
  257. sorter = "string";
  258. break;
  259. case "boolean":
  260. sorter = "boolean";
  261. break;
  262. case "object":
  263. if (Array.isArray(value)) {
  264. sorter = "array";
  265. } else {
  266. sorter = "string";
  267. }
  268. break;
  269. default:
  270. if (!isNaN(value) && value !== "") {
  271. sorter = "number";
  272. } else {
  273. if (value.match(/((^[0-9]+[a-z]+)|(^[a-z]+[0-9]+))+$/i)) {
  274. sorter = "alphanum";
  275. } else {
  276. sorter = "string";
  277. }
  278. }
  279. break;
  280. }
  281. col.sorter = sorter;
  282. cols.push(col);
  283. }
  284. if (definitions) {
  285. switch (typeof definitions === 'undefined' ? 'undefined' : _typeof(definitions)) {
  286. case "function":
  287. this.table.options.columns = definitions.call(this.table, cols);
  288. break;
  289. case "object":
  290. if (Array.isArray(definitions)) {
  291. cols.forEach(function (col) {
  292. var match = definitions.find(function (def) {
  293. return def.field === col.field;
  294. });
  295. if (match) {
  296. Object.assign(col, match);
  297. }
  298. });
  299. } else {
  300. cols.forEach(function (col) {
  301. if (definitions[col.field]) {
  302. Object.assign(col, definitions[col.field]);
  303. }
  304. });
  305. }
  306. this.table.options.columns = cols;
  307. break;
  308. }
  309. } else {
  310. this.table.options.columns = cols;
  311. }
  312. this.setColumns(this.table.options.columns);
  313. }
  314. };
  315. ColumnManager.prototype.setColumns = function (cols, row) {
  316. var self = this;
  317. while (self.headersElement.firstChild) {
  318. self.headersElement.removeChild(self.headersElement.firstChild);
  319. }self.columns = [];
  320. self.columnsByIndex = [];
  321. self.columnsByField = {};
  322. //reset frozen columns
  323. if (self.table.modExists("frozenColumns")) {
  324. self.table.modules.frozenColumns.reset();
  325. }
  326. cols.forEach(function (def, i) {
  327. self._addColumn(def);
  328. });
  329. self._reIndexColumns();
  330. if (self.table.options.responsiveLayout && self.table.modExists("responsiveLayout", true)) {
  331. self.table.modules.responsiveLayout.initialize();
  332. }
  333. if (this.table.options.virtualDomHoz) {
  334. this.table.vdomHoz.reinitialize(false, true);
  335. }
  336. self.redraw(true);
  337. };
  338. ColumnManager.prototype._addColumn = function (definition, before, nextToColumn) {
  339. var column = new Column(definition, this),
  340. colEl = column.getElement(),
  341. index = nextToColumn ? this.findColumnIndex(nextToColumn) : nextToColumn;
  342. if (nextToColumn && index > -1) {
  343. var parentIndex = this.columns.indexOf(nextToColumn.getTopColumn());
  344. var nextEl = nextToColumn.getElement();
  345. if (before) {
  346. this.columns.splice(parentIndex, 0, column);
  347. nextEl.parentNode.insertBefore(colEl, nextEl);
  348. } else {
  349. this.columns.splice(parentIndex + 1, 0, column);
  350. nextEl.parentNode.insertBefore(colEl, nextEl.nextSibling);
  351. }
  352. } else {
  353. if (before) {
  354. this.columns.unshift(column);
  355. this.headersElement.insertBefore(column.getElement(), this.headersElement.firstChild);
  356. } else {
  357. this.columns.push(column);
  358. this.headersElement.appendChild(column.getElement());
  359. }
  360. column.columnRendered();
  361. }
  362. return column;
  363. };
  364. ColumnManager.prototype.registerColumnField = function (col) {
  365. if (col.definition.field) {
  366. this.columnsByField[col.definition.field] = col;
  367. }
  368. };
  369. ColumnManager.prototype.registerColumnPosition = function (col) {
  370. this.columnsByIndex.push(col);
  371. };
  372. ColumnManager.prototype._reIndexColumns = function () {
  373. this.columnsByIndex = [];
  374. this.columns.forEach(function (column) {
  375. column.reRegisterPosition();
  376. });
  377. };
  378. //ensure column headers take up the correct amount of space in column groups
  379. ColumnManager.prototype._verticalAlignHeaders = function () {
  380. var self = this,
  381. minHeight = 0;
  382. self.columns.forEach(function (column) {
  383. var height;
  384. column.clearVerticalAlign();
  385. height = column.getHeight();
  386. if (height > minHeight) {
  387. minHeight = height;
  388. }
  389. });
  390. self.columns.forEach(function (column) {
  391. column.verticalAlign(self.table.options.columnHeaderVertAlign, minHeight);
  392. });
  393. self.rowManager.adjustTableSize();
  394. };
  395. //////////////// Column Details /////////////////
  396. ColumnManager.prototype.findColumn = function (subject) {
  397. var self = this;
  398. if ((typeof subject === 'undefined' ? 'undefined' : _typeof(subject)) == "object") {
  399. if (subject instanceof Column) {
  400. //subject is column element
  401. return subject;
  402. } else if (subject instanceof ColumnComponent) {
  403. //subject is public column component
  404. return subject._getSelf() || false;
  405. } else if (typeof HTMLElement !== "undefined" && subject instanceof HTMLElement) {
  406. //subject is a HTML element of the column header
  407. var match = self.columns.find(function (column) {
  408. return column.element === subject;
  409. });
  410. return match || false;
  411. }
  412. } else {
  413. //subject should be treated as the field name of the column
  414. return this.columnsByField[subject] || false;
  415. }
  416. //catch all for any other type of input
  417. return false;
  418. };
  419. ColumnManager.prototype.getColumnByField = function (field) {
  420. return this.columnsByField[field];
  421. };
  422. ColumnManager.prototype.getColumnsByFieldRoot = function (root) {
  423. var _this = this;
  424. var matches = [];
  425. Object.keys(this.columnsByField).forEach(function (field) {
  426. var fieldRoot = field.split(".")[0];
  427. if (fieldRoot === root) {
  428. matches.push(_this.columnsByField[field]);
  429. }
  430. });
  431. return matches;
  432. };
  433. ColumnManager.prototype.getColumnByIndex = function (index) {
  434. return this.columnsByIndex[index];
  435. };
  436. ColumnManager.prototype.getFirstVisibileColumn = function (index) {
  437. var index = this.columnsByIndex.findIndex(function (col) {
  438. return col.visible;
  439. });
  440. return index > -1 ? this.columnsByIndex[index] : false;
  441. };
  442. ColumnManager.prototype.getColumns = function () {
  443. return this.columns;
  444. };
  445. ColumnManager.prototype.findColumnIndex = function (column) {
  446. return this.columnsByIndex.findIndex(function (col) {
  447. return column === col;
  448. });
  449. };
  450. //return all columns that are not groups
  451. ColumnManager.prototype.getRealColumns = function () {
  452. return this.columnsByIndex;
  453. };
  454. //travers across columns and call action
  455. ColumnManager.prototype.traverse = function (callback) {
  456. var self = this;
  457. self.columnsByIndex.forEach(function (column, i) {
  458. callback(column, i);
  459. });
  460. };
  461. //get defintions of actual columns
  462. ColumnManager.prototype.getDefinitions = function (active) {
  463. var self = this,
  464. output = [];
  465. self.columnsByIndex.forEach(function (column) {
  466. if (!active || active && column.visible) {
  467. output.push(column.getDefinition());
  468. }
  469. });
  470. return output;
  471. };
  472. //get full nested definition tree
  473. ColumnManager.prototype.getDefinitionTree = function () {
  474. var self = this,
  475. output = [];
  476. self.columns.forEach(function (column) {
  477. output.push(column.getDefinition(true));
  478. });
  479. return output;
  480. };
  481. ColumnManager.prototype.getComponents = function (structured) {
  482. var self = this,
  483. output = [],
  484. columns = structured ? self.columns : self.columnsByIndex;
  485. columns.forEach(function (column) {
  486. output.push(column.getComponent());
  487. });
  488. return output;
  489. };
  490. ColumnManager.prototype.getWidth = function () {
  491. var width = 0;
  492. this.columnsByIndex.forEach(function (column) {
  493. if (column.visible) {
  494. width += column.getWidth();
  495. }
  496. });
  497. return width;
  498. };
  499. ColumnManager.prototype.moveColumn = function (from, to, after) {
  500. this.moveColumnActual(from, to, after);
  501. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  502. this.table.modules.responsiveLayout.initialize();
  503. }
  504. if (this.table.modExists("columnCalcs")) {
  505. this.table.modules.columnCalcs.recalc(this.table.rowManager.activeRows);
  506. }
  507. to.element.parentNode.insertBefore(from.element, to.element);
  508. if (after) {
  509. to.element.parentNode.insertBefore(to.element, from.element);
  510. }
  511. this._verticalAlignHeaders();
  512. this.table.rowManager.reinitialize();
  513. };
  514. ColumnManager.prototype.moveColumnActual = function (from, to, after) {
  515. if (from.parent.isGroup) {
  516. this._moveColumnInArray(from.parent.columns, from, to, after);
  517. } else {
  518. this._moveColumnInArray(this.columns, from, to, after);
  519. }
  520. this._moveColumnInArray(this.columnsByIndex, from, to, after, true);
  521. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  522. this.table.modules.responsiveLayout.initialize();
  523. }
  524. if (this.table.options.virtualDomHoz) {
  525. this.table.vdomHoz.reinitialize(true);
  526. }
  527. if (this.table.options.columnMoved) {
  528. this.table.options.columnMoved.call(this.table, from.getComponent(), this.table.columnManager.getComponents());
  529. }
  530. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.columns) {
  531. this.table.modules.persistence.save("columns");
  532. }
  533. };
  534. ColumnManager.prototype._moveColumnInArray = function (columns, from, to, after, updateRows) {
  535. var _this2 = this;
  536. var fromIndex = columns.indexOf(from),
  537. toIndex,
  538. rows = [];
  539. if (fromIndex > -1) {
  540. columns.splice(fromIndex, 1);
  541. toIndex = columns.indexOf(to);
  542. if (toIndex > -1) {
  543. if (after) {
  544. toIndex = toIndex + 1;
  545. }
  546. } else {
  547. toIndex = fromIndex;
  548. }
  549. columns.splice(toIndex, 0, from);
  550. if (updateRows) {
  551. if (this.table.options.dataTree && this.table.modExists("dataTree", true)) {
  552. this.table.rowManager.rows.forEach(function (row) {
  553. rows = rows.concat(_this2.table.modules.dataTree.getTreeChildren(row, false, true));
  554. });
  555. }
  556. rows = rows.concat(this.table.rowManager.rows);
  557. rows.forEach(function (row) {
  558. if (row.cells.length) {
  559. var cell = row.cells.splice(fromIndex, 1)[0];
  560. row.cells.splice(toIndex, 0, cell);
  561. }
  562. });
  563. }
  564. }
  565. };
  566. ColumnManager.prototype.scrollToColumn = function (column, position, ifVisible) {
  567. var _this3 = this;
  568. var left = 0,
  569. offset = 0,
  570. adjust = 0,
  571. colEl = column.getElement();
  572. return new Promise(function (resolve, reject) {
  573. if (typeof position === "undefined") {
  574. position = _this3.table.options.scrollToColumnPosition;
  575. }
  576. if (typeof ifVisible === "undefined") {
  577. ifVisible = _this3.table.options.scrollToColumnIfVisible;
  578. }
  579. if (column.visible) {
  580. //align to correct position
  581. switch (position) {
  582. case "middle":
  583. case "center":
  584. adjust = -_this3.element.clientWidth / 2;
  585. break;
  586. case "right":
  587. adjust = colEl.clientWidth - _this3.headersElement.clientWidth;
  588. break;
  589. }
  590. //check column visibility
  591. if (!ifVisible) {
  592. offset = colEl.offsetLeft;
  593. if (offset > 0 && offset + colEl.offsetWidth < _this3.element.clientWidth) {
  594. return false;
  595. }
  596. }
  597. //calculate scroll position
  598. left = colEl.offsetLeft + adjust;
  599. left = Math.max(Math.min(left, _this3.table.rowManager.element.scrollWidth - _this3.table.rowManager.element.clientWidth), 0);
  600. _this3.table.rowManager.scrollHorizontal(left);
  601. _this3.scrollHorizontal(left);
  602. resolve();
  603. } else {
  604. console.warn("Scroll Error - Column not visible");
  605. reject("Scroll Error - Column not visible");
  606. }
  607. });
  608. };
  609. //////////////// Cell Management /////////////////
  610. ColumnManager.prototype.generateCells = function (row) {
  611. var self = this;
  612. var cells = [];
  613. self.columnsByIndex.forEach(function (column) {
  614. cells.push(column.generateCell(row));
  615. });
  616. return cells;
  617. };
  618. //////////////// Column Management /////////////////
  619. ColumnManager.prototype.getFlexBaseWidth = function () {
  620. var self = this,
  621. totalWidth = self.table.element.clientWidth,
  622. //table element width
  623. fixedWidth = 0;
  624. //adjust for vertical scrollbar if present
  625. if (self.rowManager.element.scrollHeight > self.rowManager.element.clientHeight) {
  626. totalWidth -= self.rowManager.element.offsetWidth - self.rowManager.element.clientWidth;
  627. }
  628. this.columnsByIndex.forEach(function (column) {
  629. var width, minWidth, colWidth;
  630. if (column.visible) {
  631. width = column.definition.width || 0;
  632. minWidth = typeof column.minWidth == "undefined" ? self.table.options.columnMinWidth : parseInt(column.minWidth);
  633. if (typeof width == "string") {
  634. if (width.indexOf("%") > -1) {
  635. colWidth = totalWidth / 100 * parseInt(width);
  636. } else {
  637. colWidth = parseInt(width);
  638. }
  639. } else {
  640. colWidth = width;
  641. }
  642. fixedWidth += colWidth > minWidth ? colWidth : minWidth;
  643. }
  644. });
  645. return fixedWidth;
  646. };
  647. ColumnManager.prototype.addColumn = function (definition, before, nextToColumn) {
  648. var _this4 = this;
  649. return new Promise(function (resolve, reject) {
  650. var column = _this4._addColumn(definition, before, nextToColumn);
  651. _this4._reIndexColumns();
  652. if (_this4.table.options.responsiveLayout && _this4.table.modExists("responsiveLayout", true)) {
  653. _this4.table.modules.responsiveLayout.initialize();
  654. }
  655. if (_this4.table.modExists("columnCalcs")) {
  656. _this4.table.modules.columnCalcs.recalc(_this4.table.rowManager.activeRows);
  657. }
  658. _this4.redraw();
  659. if (_this4.table.modules.layout.getMode() != "fitColumns") {
  660. column.reinitializeWidth();
  661. }
  662. _this4._verticalAlignHeaders();
  663. _this4.table.rowManager.reinitialize();
  664. if (_this4.table.options.virtualDomHoz) {
  665. _this4.table.vdomHoz.reinitialize();
  666. }
  667. resolve(column);
  668. });
  669. };
  670. //remove column from system
  671. ColumnManager.prototype.deregisterColumn = function (column) {
  672. var field = column.getField(),
  673. index;
  674. //remove from field list
  675. if (field) {
  676. delete this.columnsByField[field];
  677. }
  678. //remove from index list
  679. index = this.columnsByIndex.indexOf(column);
  680. if (index > -1) {
  681. this.columnsByIndex.splice(index, 1);
  682. }
  683. //remove from column list
  684. index = this.columns.indexOf(column);
  685. if (index > -1) {
  686. this.columns.splice(index, 1);
  687. }
  688. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  689. this.table.modules.responsiveLayout.initialize();
  690. }
  691. this._verticalAlignHeaders();
  692. this.redraw();
  693. };
  694. //redraw columns
  695. ColumnManager.prototype.redraw = function (force) {
  696. if (force) {
  697. if (Tabulator.prototype.helpers.elVisible(this.element)) {
  698. this._verticalAlignHeaders();
  699. }
  700. this.table.rowManager.resetScroll();
  701. this.table.rowManager.reinitialize();
  702. }
  703. if (["fitColumns", "fitDataStretch"].indexOf(this.table.modules.layout.getMode()) > -1) {
  704. this.table.modules.layout.layout();
  705. } else {
  706. if (force) {
  707. this.table.modules.layout.layout();
  708. } else {
  709. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  710. this.table.modules.responsiveLayout.update();
  711. }
  712. }
  713. }
  714. if (this.table.modExists("frozenColumns")) {
  715. this.table.modules.frozenColumns.layout();
  716. }
  717. if (this.table.modExists("columnCalcs")) {
  718. this.table.modules.columnCalcs.recalc(this.table.rowManager.activeRows);
  719. }
  720. if (force) {
  721. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.columns) {
  722. this.table.modules.persistence.save("columns");
  723. }
  724. if (this.table.modExists("columnCalcs")) {
  725. this.table.modules.columnCalcs.redraw();
  726. }
  727. }
  728. this.table.footerManager.redraw();
  729. };
  730. //public column object
  731. var ColumnComponent = function ColumnComponent(column) {
  732. this._column = column;
  733. this.type = "ColumnComponent";
  734. };
  735. ColumnComponent.prototype.getElement = function () {
  736. return this._column.getElement();
  737. };
  738. ColumnComponent.prototype.getDefinition = function () {
  739. return this._column.getDefinition();
  740. };
  741. ColumnComponent.prototype.getField = function () {
  742. return this._column.getField();
  743. };
  744. ColumnComponent.prototype.getCells = function () {
  745. var cells = [];
  746. this._column.cells.forEach(function (cell) {
  747. cells.push(cell.getComponent());
  748. });
  749. return cells;
  750. };
  751. ColumnComponent.prototype.getVisibility = function () {
  752. console.warn("getVisibility function is deprecated, you should now use the isVisible function");
  753. return this._column.visible;
  754. };
  755. ColumnComponent.prototype.isVisible = function () {
  756. return this._column.visible;
  757. };
  758. ColumnComponent.prototype.show = function () {
  759. if (this._column.isGroup) {
  760. this._column.columns.forEach(function (column) {
  761. column.show();
  762. });
  763. } else {
  764. this._column.show();
  765. }
  766. };
  767. ColumnComponent.prototype.hide = function () {
  768. if (this._column.isGroup) {
  769. this._column.columns.forEach(function (column) {
  770. column.hide();
  771. });
  772. } else {
  773. this._column.hide();
  774. }
  775. };
  776. ColumnComponent.prototype.toggle = function () {
  777. if (this._column.visible) {
  778. this.hide();
  779. } else {
  780. this.show();
  781. }
  782. };
  783. ColumnComponent.prototype.delete = function () {
  784. return this._column.delete();
  785. };
  786. ColumnComponent.prototype.getSubColumns = function () {
  787. var output = [];
  788. if (this._column.columns.length) {
  789. this._column.columns.forEach(function (column) {
  790. output.push(column.getComponent());
  791. });
  792. }
  793. return output;
  794. };
  795. ColumnComponent.prototype.getParentColumn = function () {
  796. return this._column.parent instanceof Column ? this._column.parent.getComponent() : false;
  797. };
  798. ColumnComponent.prototype._getSelf = function () {
  799. return this._column;
  800. };
  801. ColumnComponent.prototype.scrollTo = function () {
  802. return this._column.table.columnManager.scrollToColumn(this._column);
  803. };
  804. ColumnComponent.prototype.getTable = function () {
  805. return this._column.table;
  806. };
  807. ColumnComponent.prototype.headerFilterFocus = function () {
  808. if (this._column.table.modExists("filter", true)) {
  809. this._column.table.modules.filter.setHeaderFilterFocus(this._column);
  810. }
  811. };
  812. ColumnComponent.prototype.reloadHeaderFilter = function () {
  813. if (this._column.table.modExists("filter", true)) {
  814. this._column.table.modules.filter.reloadHeaderFilter(this._column);
  815. }
  816. };
  817. ColumnComponent.prototype.getHeaderFilterValue = function () {
  818. if (this._column.table.modExists("filter", true)) {
  819. return this._column.table.modules.filter.getHeaderFilterValue(this._column);
  820. }
  821. };
  822. ColumnComponent.prototype.setHeaderFilterValue = function (value) {
  823. if (this._column.table.modExists("filter", true)) {
  824. this._column.table.modules.filter.setHeaderFilterValue(this._column, value);
  825. }
  826. };
  827. ColumnComponent.prototype.move = function (to, after) {
  828. var toColumn = this._column.table.columnManager.findColumn(to);
  829. if (toColumn) {
  830. this._column.table.columnManager.moveColumn(this._column, toColumn, after);
  831. } else {
  832. console.warn("Move Error - No matching column found:", toColumn);
  833. }
  834. };
  835. ColumnComponent.prototype.getNextColumn = function () {
  836. var nextCol = this._column.nextColumn();
  837. return nextCol ? nextCol.getComponent() : false;
  838. };
  839. ColumnComponent.prototype.getPrevColumn = function () {
  840. var prevCol = this._column.prevColumn();
  841. return prevCol ? prevCol.getComponent() : false;
  842. };
  843. ColumnComponent.prototype.updateDefinition = function (updates) {
  844. return this._column.updateDefinition(updates);
  845. };
  846. ColumnComponent.prototype.getWidth = function () {
  847. return this._column.getWidth();
  848. };
  849. ColumnComponent.prototype.setWidth = function (width) {
  850. var result;
  851. if (width === true) {
  852. result = this._column.reinitializeWidth(true);
  853. } else {
  854. result = this._column.setWidth(width);
  855. }
  856. if (this._column.table.options.virtualDomHoz) {
  857. this._column.table.vdomHoz.reinitialize(true);
  858. }
  859. return result;
  860. };
  861. ColumnComponent.prototype.validate = function () {
  862. return this._column.validate();
  863. };
  864. var Column = function Column(def, parent) {
  865. var self = this;
  866. this.table = parent.table;
  867. this.definition = def; //column definition
  868. this.parent = parent; //hold parent object
  869. this.type = "column"; //type of element
  870. this.columns = []; //child columns
  871. this.cells = []; //cells bound to this column
  872. this.element = this.createElement(); //column header element
  873. this.contentElement = false;
  874. this.titleHolderElement = false;
  875. this.titleElement = false;
  876. this.groupElement = this.createGroupElement(); //column group holder element
  877. this.isGroup = false;
  878. this.tooltip = false; //hold column tooltip
  879. this.hozAlign = ""; //horizontal text alignment
  880. this.vertAlign = ""; //vert text alignment
  881. //multi dimensional filed handling
  882. this.field = "";
  883. this.fieldStructure = "";
  884. this.getFieldValue = "";
  885. this.setFieldValue = "";
  886. this.titleFormatterRendered = false;
  887. this.setField(this.definition.field);
  888. if (this.table.options.invalidOptionWarnings) {
  889. this.checkDefinition();
  890. }
  891. this.modules = {}; //hold module variables;
  892. this.cellEvents = {
  893. cellClick: false,
  894. cellDblClick: false,
  895. cellContext: false,
  896. cellTap: false,
  897. cellDblTap: false,
  898. cellTapHold: false,
  899. cellMouseEnter: false,
  900. cellMouseLeave: false,
  901. cellMouseOver: false,
  902. cellMouseOut: false,
  903. cellMouseMove: false
  904. };
  905. this.width = null; //column width
  906. this.widthStyled = ""; //column width prestyled to improve render efficiency
  907. this.minWidth = null; //column minimum width
  908. this.minWidthStyled = ""; //column minimum prestyled to improve render efficiency
  909. this.widthFixed = false; //user has specified a width for this column
  910. this.visible = true; //default visible state
  911. this.component = null;
  912. this._mapDepricatedFunctionality();
  913. //initialize column
  914. if (def.columns) {
  915. this.isGroup = true;
  916. def.columns.forEach(function (def, i) {
  917. var newCol = new Column(def, self);
  918. self.attachColumn(newCol);
  919. });
  920. self.checkColumnVisibility();
  921. } else {
  922. parent.registerColumnField(this);
  923. }
  924. if (def.rowHandle && this.table.options.movableRows !== false && this.table.modExists("moveRow")) {
  925. this.table.modules.moveRow.setHandle(true);
  926. }
  927. this._buildHeader();
  928. this.bindModuleColumns();
  929. };
  930. Column.prototype.createElement = function () {
  931. var el = document.createElement("div");
  932. el.classList.add("tabulator-col");
  933. el.setAttribute("role", "columnheader");
  934. el.setAttribute("aria-sort", "none");
  935. return el;
  936. };
  937. Column.prototype.createGroupElement = function () {
  938. var el = document.createElement("div");
  939. el.classList.add("tabulator-col-group-cols");
  940. return el;
  941. };
  942. Column.prototype.checkDefinition = function () {
  943. var _this5 = this;
  944. Object.keys(this.definition).forEach(function (key) {
  945. if (_this5.defaultOptionList.indexOf(key) === -1) {
  946. console.warn("Invalid column definition option in '" + (_this5.field || _this5.definition.title) + "' column:", key);
  947. }
  948. });
  949. };
  950. Column.prototype.setField = function (field) {
  951. this.field = field;
  952. this.fieldStructure = field ? this.table.options.nestedFieldSeparator ? field.split(this.table.options.nestedFieldSeparator) : [field] : [];
  953. this.getFieldValue = this.fieldStructure.length > 1 ? this._getNestedData : this._getFlatData;
  954. this.setFieldValue = this.fieldStructure.length > 1 ? this._setNestedData : this._setFlatData;
  955. };
  956. //register column position with column manager
  957. Column.prototype.registerColumnPosition = function (column) {
  958. this.parent.registerColumnPosition(column);
  959. };
  960. //register column position with column manager
  961. Column.prototype.registerColumnField = function (column) {
  962. this.parent.registerColumnField(column);
  963. };
  964. //trigger position registration
  965. Column.prototype.reRegisterPosition = function () {
  966. if (this.isGroup) {
  967. this.columns.forEach(function (column) {
  968. column.reRegisterPosition();
  969. });
  970. } else {
  971. this.registerColumnPosition(this);
  972. }
  973. };
  974. Column.prototype._mapDepricatedFunctionality = function () {
  975. if (typeof this.definition.hideInHtml !== "undefined") {
  976. this.definition.htmlOutput = !this.definition.hideInHtml;
  977. console.warn("hideInHtml column definition property is deprecated, you should now use htmlOutput");
  978. }
  979. if (typeof this.definition.align !== "undefined") {
  980. this.definition.hozAlign = this.definition.align;
  981. console.warn("align column definition property is deprecated, you should now use hozAlign");
  982. }
  983. if (typeof this.definition.downloadTitle !== "undefined") {
  984. this.definition.titleDownload = this.definition.downloadTitle;
  985. console.warn("downloadTitle definition property is deprecated, you should now use titleDownload");
  986. }
  987. };
  988. Column.prototype.setTooltip = function () {
  989. var self = this,
  990. def = self.definition;
  991. //set header tooltips
  992. var tooltip = def.headerTooltip || def.tooltip === false ? def.headerTooltip : self.table.options.tooltipsHeader;
  993. if (tooltip) {
  994. if (tooltip === true) {
  995. if (def.field) {
  996. self.table.modules.localize.bind("columns|" + def.field, function (value) {
  997. self.element.setAttribute("title", value || def.title);
  998. });
  999. } else {
  1000. self.element.setAttribute("title", def.title);
  1001. }
  1002. } else {
  1003. if (typeof tooltip == "function") {
  1004. tooltip = tooltip(self.getComponent());
  1005. if (tooltip === false) {
  1006. tooltip = "";
  1007. }
  1008. }
  1009. self.element.setAttribute("title", tooltip);
  1010. }
  1011. } else {
  1012. self.element.setAttribute("title", "");
  1013. }
  1014. };
  1015. //build header element
  1016. Column.prototype._buildHeader = function () {
  1017. var self = this,
  1018. def = self.definition;
  1019. while (self.element.firstChild) {
  1020. self.element.removeChild(self.element.firstChild);
  1021. }if (def.headerVertical) {
  1022. self.element.classList.add("tabulator-col-vertical");
  1023. if (def.headerVertical === "flip") {
  1024. self.element.classList.add("tabulator-col-vertical-flip");
  1025. }
  1026. }
  1027. self.contentElement = self._bindEvents();
  1028. self.contentElement = self._buildColumnHeaderContent();
  1029. self.element.appendChild(self.contentElement);
  1030. if (self.isGroup) {
  1031. self._buildGroupHeader();
  1032. } else {
  1033. self._buildColumnHeader();
  1034. }
  1035. self.setTooltip();
  1036. //set resizable handles
  1037. if (self.table.options.resizableColumns && self.table.modExists("resizeColumns")) {
  1038. self.table.modules.resizeColumns.initializeColumn("header", self, self.element);
  1039. }
  1040. //set resizable handles
  1041. if (def.headerFilter && self.table.modExists("filter") && self.table.modExists("edit")) {
  1042. if (typeof def.headerFilterPlaceholder !== "undefined" && def.field) {
  1043. self.table.modules.localize.setHeaderFilterColumnPlaceholder(def.field, def.headerFilterPlaceholder);
  1044. }
  1045. self.table.modules.filter.initializeColumn(self);
  1046. }
  1047. //set resizable handles
  1048. if (self.table.modExists("frozenColumns")) {
  1049. self.table.modules.frozenColumns.initializeColumn(self);
  1050. }
  1051. //set movable column
  1052. if (self.table.options.movableColumns && !self.isGroup && self.table.modExists("moveColumn")) {
  1053. self.table.modules.moveColumn.initializeColumn(self);
  1054. }
  1055. //set calcs column
  1056. if ((def.topCalc || def.bottomCalc) && self.table.modExists("columnCalcs")) {
  1057. self.table.modules.columnCalcs.initializeColumn(self);
  1058. }
  1059. //handle persistence
  1060. if (self.table.modExists("persistence") && self.table.modules.persistence.config.columns) {
  1061. self.table.modules.persistence.initializeColumn(self);
  1062. }
  1063. //update header tooltip on mouse enter
  1064. self.element.addEventListener("mouseenter", function (e) {
  1065. self.setTooltip();
  1066. });
  1067. };
  1068. Column.prototype._bindEvents = function () {
  1069. var self = this,
  1070. def = self.definition,
  1071. dblTap,
  1072. tapHold,
  1073. tap;
  1074. //setup header click event bindings
  1075. if (typeof def.headerClick == "function") {
  1076. self.element.addEventListener("click", function (e) {
  1077. def.headerClick(e, self.getComponent());
  1078. });
  1079. }
  1080. if (typeof def.headerDblClick == "function") {
  1081. self.element.addEventListener("dblclick", function (e) {
  1082. def.headerDblClick(e, self.getComponent());
  1083. });
  1084. }
  1085. if (typeof def.headerContext == "function") {
  1086. self.element.addEventListener("contextmenu", function (e) {
  1087. def.headerContext(e, self.getComponent());
  1088. });
  1089. }
  1090. //setup header tap event bindings
  1091. if (typeof def.headerTap == "function") {
  1092. tap = false;
  1093. self.element.addEventListener("touchstart", function (e) {
  1094. tap = true;
  1095. }, { passive: true });
  1096. self.element.addEventListener("touchend", function (e) {
  1097. if (tap) {
  1098. def.headerTap(e, self.getComponent());
  1099. }
  1100. tap = false;
  1101. });
  1102. }
  1103. if (typeof def.headerDblTap == "function") {
  1104. dblTap = null;
  1105. self.element.addEventListener("touchend", function (e) {
  1106. if (dblTap) {
  1107. clearTimeout(dblTap);
  1108. dblTap = null;
  1109. def.headerDblTap(e, self.getComponent());
  1110. } else {
  1111. dblTap = setTimeout(function () {
  1112. clearTimeout(dblTap);
  1113. dblTap = null;
  1114. }, 300);
  1115. }
  1116. });
  1117. }
  1118. if (typeof def.headerTapHold == "function") {
  1119. tapHold = null;
  1120. self.element.addEventListener("touchstart", function (e) {
  1121. clearTimeout(tapHold);
  1122. tapHold = setTimeout(function () {
  1123. clearTimeout(tapHold);
  1124. tapHold = null;
  1125. tap = false;
  1126. def.headerTapHold(e, self.getComponent());
  1127. }, 1000);
  1128. }, { passive: true });
  1129. self.element.addEventListener("touchend", function (e) {
  1130. clearTimeout(tapHold);
  1131. tapHold = null;
  1132. });
  1133. }
  1134. //store column cell click event bindings
  1135. if (typeof def.cellClick == "function") {
  1136. self.cellEvents.cellClick = def.cellClick;
  1137. }
  1138. if (typeof def.cellDblClick == "function") {
  1139. self.cellEvents.cellDblClick = def.cellDblClick;
  1140. }
  1141. if (typeof def.cellContext == "function") {
  1142. self.cellEvents.cellContext = def.cellContext;
  1143. }
  1144. //store column mouse event bindings
  1145. if (typeof def.cellMouseEnter == "function") {
  1146. self.cellEvents.cellMouseEnter = def.cellMouseEnter;
  1147. }
  1148. if (typeof def.cellMouseLeave == "function") {
  1149. self.cellEvents.cellMouseLeave = def.cellMouseLeave;
  1150. }
  1151. if (typeof def.cellMouseOver == "function") {
  1152. self.cellEvents.cellMouseOver = def.cellMouseOver;
  1153. }
  1154. if (typeof def.cellMouseOut == "function") {
  1155. self.cellEvents.cellMouseOut = def.cellMouseOut;
  1156. }
  1157. if (typeof def.cellMouseMove == "function") {
  1158. self.cellEvents.cellMouseMove = def.cellMouseMove;
  1159. }
  1160. //setup column cell tap event bindings
  1161. if (typeof def.cellTap == "function") {
  1162. self.cellEvents.cellTap = def.cellTap;
  1163. }
  1164. if (typeof def.cellDblTap == "function") {
  1165. self.cellEvents.cellDblTap = def.cellDblTap;
  1166. }
  1167. if (typeof def.cellTapHold == "function") {
  1168. self.cellEvents.cellTapHold = def.cellTapHold;
  1169. }
  1170. //setup column cell edit callbacks
  1171. if (typeof def.cellEdited == "function") {
  1172. self.cellEvents.cellEdited = def.cellEdited;
  1173. }
  1174. if (typeof def.cellEditing == "function") {
  1175. self.cellEvents.cellEditing = def.cellEditing;
  1176. }
  1177. if (typeof def.cellEditCancelled == "function") {
  1178. self.cellEvents.cellEditCancelled = def.cellEditCancelled;
  1179. }
  1180. };
  1181. //build header element for header
  1182. Column.prototype._buildColumnHeader = function () {
  1183. var _this6 = this;
  1184. var def = this.definition,
  1185. table = this.table,
  1186. sortable;
  1187. //set column sorter
  1188. if (table.modExists("sort")) {
  1189. table.modules.sort.initializeColumn(this, this.titleHolderElement);
  1190. }
  1191. //set column header context menu
  1192. if ((def.headerContextMenu || def.headerClickMenu || def.headerMenu) && table.modExists("menu")) {
  1193. table.modules.menu.initializeColumnHeader(this);
  1194. }
  1195. //set column formatter
  1196. if (table.modExists("format")) {
  1197. table.modules.format.initializeColumn(this);
  1198. }
  1199. //set column editor
  1200. if (typeof def.editor != "undefined" && table.modExists("edit")) {
  1201. table.modules.edit.initializeColumn(this);
  1202. }
  1203. //set colum validator
  1204. if (typeof def.validator != "undefined" && table.modExists("validate")) {
  1205. table.modules.validate.initializeColumn(this);
  1206. }
  1207. //set column mutator
  1208. if (table.modExists("mutator")) {
  1209. table.modules.mutator.initializeColumn(this);
  1210. }
  1211. //set column accessor
  1212. if (table.modExists("accessor")) {
  1213. table.modules.accessor.initializeColumn(this);
  1214. }
  1215. //set respoviveLayout
  1216. if (_typeof(table.options.responsiveLayout) && table.modExists("responsiveLayout")) {
  1217. table.modules.responsiveLayout.initializeColumn(this);
  1218. }
  1219. //set column visibility
  1220. if (typeof def.visible != "undefined") {
  1221. if (def.visible) {
  1222. this.show(true);
  1223. } else {
  1224. this.hide(true);
  1225. }
  1226. }
  1227. //asign additional css classes to column header
  1228. if (def.cssClass) {
  1229. var classeNames = def.cssClass.split(" ");
  1230. classeNames.forEach(function (className) {
  1231. _this6.element.classList.add(className);
  1232. });
  1233. }
  1234. if (def.field) {
  1235. this.element.setAttribute("tabulator-field", def.field);
  1236. }
  1237. //set min width if present
  1238. this.setMinWidth(typeof def.minWidth == "undefined" ? this.table.options.columnMinWidth : parseInt(def.minWidth));
  1239. this.reinitializeWidth();
  1240. //set tooltip if present
  1241. this.tooltip = this.definition.tooltip || this.definition.tooltip === false ? this.definition.tooltip : this.table.options.tooltips;
  1242. //set orizontal text alignment
  1243. this.hozAlign = typeof this.definition.hozAlign == "undefined" ? this.table.options.cellHozAlign : this.definition.hozAlign;
  1244. this.vertAlign = typeof this.definition.vertAlign == "undefined" ? this.table.options.cellVertAlign : this.definition.vertAlign;
  1245. this.titleElement.style.textAlign = this.definition.headerHozAlign || this.table.options.headerHozAlign;
  1246. };
  1247. Column.prototype._buildColumnHeaderContent = function () {
  1248. var def = this.definition,
  1249. table = this.table;
  1250. var contentElement = document.createElement("div");
  1251. contentElement.classList.add("tabulator-col-content");
  1252. this.titleHolderElement = document.createElement("div");
  1253. this.titleHolderElement.classList.add("tabulator-col-title-holder");
  1254. contentElement.appendChild(this.titleHolderElement);
  1255. this.titleElement = this._buildColumnHeaderTitle();
  1256. this.titleHolderElement.appendChild(this.titleElement);
  1257. return contentElement;
  1258. };
  1259. //build title element of column
  1260. Column.prototype._buildColumnHeaderTitle = function () {
  1261. var self = this,
  1262. def = self.definition,
  1263. table = self.table,
  1264. title;
  1265. var titleHolderElement = document.createElement("div");
  1266. titleHolderElement.classList.add("tabulator-col-title");
  1267. if (def.editableTitle) {
  1268. var titleElement = document.createElement("input");
  1269. titleElement.classList.add("tabulator-title-editor");
  1270. titleElement.addEventListener("click", function (e) {
  1271. e.stopPropagation();
  1272. titleElement.focus();
  1273. });
  1274. titleElement.addEventListener("change", function () {
  1275. def.title = titleElement.value;
  1276. table.options.columnTitleChanged.call(self.table, self.getComponent());
  1277. });
  1278. titleHolderElement.appendChild(titleElement);
  1279. if (def.field) {
  1280. table.modules.localize.bind("columns|" + def.field, function (text) {
  1281. titleElement.value = text || def.title || "&nbsp;";
  1282. });
  1283. } else {
  1284. titleElement.value = def.title || "&nbsp;";
  1285. }
  1286. } else {
  1287. if (def.field) {
  1288. table.modules.localize.bind("columns|" + def.field, function (text) {
  1289. self._formatColumnHeaderTitle(titleHolderElement, text || def.title || "&nbsp;");
  1290. });
  1291. } else {
  1292. self._formatColumnHeaderTitle(titleHolderElement, def.title || "&nbsp;");
  1293. }
  1294. }
  1295. return titleHolderElement;
  1296. };
  1297. Column.prototype._formatColumnHeaderTitle = function (el, title) {
  1298. var _this7 = this;
  1299. var formatter, contents, params, mockCell, onRendered;
  1300. if (this.definition.titleFormatter && this.table.modExists("format")) {
  1301. formatter = this.table.modules.format.getFormatter(this.definition.titleFormatter);
  1302. onRendered = function onRendered(callback) {
  1303. _this7.titleFormatterRendered = callback;
  1304. };
  1305. mockCell = {
  1306. getValue: function getValue() {
  1307. return title;
  1308. },
  1309. getElement: function getElement() {
  1310. return el;
  1311. }
  1312. };
  1313. params = this.definition.titleFormatterParams || {};
  1314. params = typeof params === "function" ? params() : params;
  1315. contents = formatter.call(this.table.modules.format, mockCell, params, onRendered);
  1316. switch (typeof contents === 'undefined' ? 'undefined' : _typeof(contents)) {
  1317. case "object":
  1318. if (contents instanceof Node) {
  1319. el.appendChild(contents);
  1320. } else {
  1321. el.innerHTML = "";
  1322. 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);
  1323. }
  1324. break;
  1325. case "undefined":
  1326. case "null":
  1327. el.innerHTML = "";
  1328. break;
  1329. default:
  1330. el.innerHTML = contents;
  1331. }
  1332. } else {
  1333. el.innerHTML = title;
  1334. }
  1335. };
  1336. //build header element for column group
  1337. Column.prototype._buildGroupHeader = function () {
  1338. var _this8 = this;
  1339. this.element.classList.add("tabulator-col-group");
  1340. this.element.setAttribute("role", "columngroup");
  1341. this.element.setAttribute("aria-title", this.definition.title);
  1342. //asign additional css classes to column header
  1343. if (this.definition.cssClass) {
  1344. var classeNames = this.definition.cssClass.split(" ");
  1345. classeNames.forEach(function (className) {
  1346. _this8.element.classList.add(className);
  1347. });
  1348. }
  1349. //set column header context menu
  1350. if ((this.definition.headerContextMenu || this.definition.headerMenu) && this.table.modExists("menu")) {
  1351. this.table.modules.menu.initializeColumnHeader(this);
  1352. }
  1353. this.element.appendChild(this.groupElement);
  1354. };
  1355. //flat field lookup
  1356. Column.prototype._getFlatData = function (data) {
  1357. return data[this.field];
  1358. };
  1359. //nested field lookup
  1360. Column.prototype._getNestedData = function (data) {
  1361. var dataObj = data,
  1362. structure = this.fieldStructure,
  1363. length = structure.length,
  1364. output;
  1365. for (var _i = 0; _i < length; _i++) {
  1366. dataObj = dataObj[structure[_i]];
  1367. output = dataObj;
  1368. if (!dataObj) {
  1369. break;
  1370. }
  1371. }
  1372. return output;
  1373. };
  1374. //flat field set
  1375. Column.prototype._setFlatData = function (data, value) {
  1376. if (this.field) {
  1377. data[this.field] = value;
  1378. }
  1379. };
  1380. //nested field set
  1381. Column.prototype._setNestedData = function (data, value) {
  1382. var dataObj = data,
  1383. structure = this.fieldStructure,
  1384. length = structure.length;
  1385. for (var _i2 = 0; _i2 < length; _i2++) {
  1386. if (_i2 == length - 1) {
  1387. dataObj[structure[_i2]] = value;
  1388. } else {
  1389. if (!dataObj[structure[_i2]]) {
  1390. if (typeof value !== "undefined") {
  1391. dataObj[structure[_i2]] = {};
  1392. } else {
  1393. break;
  1394. }
  1395. }
  1396. dataObj = dataObj[structure[_i2]];
  1397. }
  1398. }
  1399. };
  1400. //attach column to this group
  1401. Column.prototype.attachColumn = function (column) {
  1402. var self = this;
  1403. if (self.groupElement) {
  1404. self.columns.push(column);
  1405. self.groupElement.appendChild(column.getElement());
  1406. } else {
  1407. console.warn("Column Warning - Column being attached to another column instead of column group");
  1408. }
  1409. };
  1410. //vertically align header in column
  1411. Column.prototype.verticalAlign = function (alignment, height) {
  1412. //calculate height of column header and group holder element
  1413. var parentHeight = this.parent.isGroup ? this.parent.getGroupElement().clientHeight : height || this.parent.getHeadersElement().clientHeight;
  1414. // var parentHeight = this.parent.isGroup ? this.parent.getGroupElement().clientHeight : this.parent.getHeadersElement().clientHeight;
  1415. this.element.style.height = parentHeight + "px";
  1416. if (this.isGroup) {
  1417. this.groupElement.style.minHeight = parentHeight - this.contentElement.offsetHeight + "px";
  1418. }
  1419. //vertically align cell contents
  1420. if (!this.isGroup && alignment !== "top") {
  1421. if (alignment === "bottom") {
  1422. this.element.style.paddingTop = this.element.clientHeight - this.contentElement.offsetHeight + "px";
  1423. } else {
  1424. this.element.style.paddingTop = (this.element.clientHeight - this.contentElement.offsetHeight) / 2 + "px";
  1425. }
  1426. }
  1427. this.columns.forEach(function (column) {
  1428. column.verticalAlign(alignment);
  1429. });
  1430. };
  1431. //clear vertical alignmenet
  1432. Column.prototype.clearVerticalAlign = function () {
  1433. this.element.style.paddingTop = "";
  1434. this.element.style.height = "";
  1435. this.element.style.minHeight = "";
  1436. this.groupElement.style.minHeight = "";
  1437. this.columns.forEach(function (column) {
  1438. column.clearVerticalAlign();
  1439. });
  1440. };
  1441. Column.prototype.bindModuleColumns = function () {
  1442. //check if rownum formatter is being used on a column
  1443. if (this.definition.formatter == "rownum") {
  1444. this.table.rowManager.rowNumColumn = this;
  1445. }
  1446. };
  1447. //// Retreive Column Information ////
  1448. //return column header element
  1449. Column.prototype.getElement = function () {
  1450. return this.element;
  1451. };
  1452. //return colunm group element
  1453. Column.prototype.getGroupElement = function () {
  1454. return this.groupElement;
  1455. };
  1456. //return field name
  1457. Column.prototype.getField = function () {
  1458. return this.field;
  1459. };
  1460. //return the first column in a group
  1461. Column.prototype.getFirstColumn = function () {
  1462. if (!this.isGroup) {
  1463. return this;
  1464. } else {
  1465. if (this.columns.length) {
  1466. return this.columns[0].getFirstColumn();
  1467. } else {
  1468. return false;
  1469. }
  1470. }
  1471. };
  1472. //return the last column in a group
  1473. Column.prototype.getLastColumn = function () {
  1474. if (!this.isGroup) {
  1475. return this;
  1476. } else {
  1477. if (this.columns.length) {
  1478. return this.columns[this.columns.length - 1].getLastColumn();
  1479. } else {
  1480. return false;
  1481. }
  1482. }
  1483. };
  1484. //return all columns in a group
  1485. Column.prototype.getColumns = function () {
  1486. return this.columns;
  1487. };
  1488. //return all columns in a group
  1489. Column.prototype.getCells = function () {
  1490. return this.cells;
  1491. };
  1492. //retreive the top column in a group of columns
  1493. Column.prototype.getTopColumn = function () {
  1494. if (this.parent.isGroup) {
  1495. return this.parent.getTopColumn();
  1496. } else {
  1497. return this;
  1498. }
  1499. };
  1500. //return column definition object
  1501. Column.prototype.getDefinition = function (updateBranches) {
  1502. var colDefs = [];
  1503. if (this.isGroup && updateBranches) {
  1504. this.columns.forEach(function (column) {
  1505. colDefs.push(column.getDefinition(true));
  1506. });
  1507. this.definition.columns = colDefs;
  1508. }
  1509. return this.definition;
  1510. };
  1511. //////////////////// Actions ////////////////////
  1512. Column.prototype.checkColumnVisibility = function () {
  1513. var visible = false;
  1514. this.columns.forEach(function (column) {
  1515. if (column.visible) {
  1516. visible = true;
  1517. }
  1518. });
  1519. if (visible) {
  1520. this.show();
  1521. this.parent.table.options.columnVisibilityChanged.call(this.table, this.getComponent(), false);
  1522. } else {
  1523. this.hide();
  1524. }
  1525. };
  1526. //show column
  1527. Column.prototype.show = function (silent, responsiveToggle) {
  1528. if (!this.visible) {
  1529. this.visible = true;
  1530. this.element.style.display = "";
  1531. if (this.parent.isGroup) {
  1532. this.parent.checkColumnVisibility();
  1533. }
  1534. this.cells.forEach(function (cell) {
  1535. cell.show();
  1536. });
  1537. if (!this.isGroup && this.width === null) {
  1538. this.reinitializeWidth();
  1539. }
  1540. this.table.columnManager._verticalAlignHeaders();
  1541. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.columns) {
  1542. this.table.modules.persistence.save("columns");
  1543. }
  1544. if (!responsiveToggle && this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  1545. this.table.modules.responsiveLayout.updateColumnVisibility(this, this.visible);
  1546. }
  1547. if (!silent) {
  1548. this.table.options.columnVisibilityChanged.call(this.table, this.getComponent(), true);
  1549. }
  1550. if (this.parent.isGroup) {
  1551. this.parent.matchChildWidths();
  1552. }
  1553. }
  1554. };
  1555. //hide column
  1556. Column.prototype.hide = function (silent, responsiveToggle) {
  1557. if (this.visible) {
  1558. this.visible = false;
  1559. this.element.style.display = "none";
  1560. this.table.columnManager._verticalAlignHeaders();
  1561. if (this.parent.isGroup) {
  1562. this.parent.checkColumnVisibility();
  1563. }
  1564. this.cells.forEach(function (cell) {
  1565. cell.hide();
  1566. });
  1567. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.columns) {
  1568. this.table.modules.persistence.save("columns");
  1569. }
  1570. if (!responsiveToggle && this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  1571. this.table.modules.responsiveLayout.updateColumnVisibility(this, this.visible);
  1572. }
  1573. if (!silent) {
  1574. this.table.options.columnVisibilityChanged.call(this.table, this.getComponent(), false);
  1575. }
  1576. if (this.parent.isGroup) {
  1577. this.parent.matchChildWidths();
  1578. }
  1579. }
  1580. };
  1581. Column.prototype.matchChildWidths = function () {
  1582. var childWidth = 0;
  1583. if (this.contentElement && this.columns.length) {
  1584. this.columns.forEach(function (column) {
  1585. if (column.visible) {
  1586. childWidth += column.getWidth();
  1587. }
  1588. });
  1589. this.contentElement.style.maxWidth = childWidth - 1 + "px";
  1590. if (this.parent.isGroup) {
  1591. this.parent.matchChildWidths();
  1592. }
  1593. }
  1594. };
  1595. Column.prototype.setWidth = function (width) {
  1596. this.widthFixed = true;
  1597. this.setWidthActual(width);
  1598. };
  1599. Column.prototype.setWidthActual = function (width) {
  1600. if (isNaN(width)) {
  1601. width = Math.floor(this.table.element.clientWidth / 100 * parseInt(width));
  1602. }
  1603. width = Math.max(this.minWidth, width);
  1604. this.width = width;
  1605. this.widthStyled = width ? width + "px" : "";
  1606. this.element.style.width = this.widthStyled;
  1607. if (!this.isGroup) {
  1608. this.cells.forEach(function (cell) {
  1609. cell.setWidth();
  1610. });
  1611. }
  1612. if (this.parent.isGroup) {
  1613. this.parent.matchChildWidths();
  1614. }
  1615. //set resizable handles
  1616. if (this.table.modExists("frozenColumns")) {
  1617. this.table.modules.frozenColumns.layout();
  1618. }
  1619. };
  1620. Column.prototype.checkCellHeights = function () {
  1621. var rows = [];
  1622. this.cells.forEach(function (cell) {
  1623. if (cell.row.heightInitialized) {
  1624. if (cell.row.getElement().offsetParent !== null) {
  1625. rows.push(cell.row);
  1626. cell.row.clearCellHeight();
  1627. } else {
  1628. cell.row.heightInitialized = false;
  1629. }
  1630. }
  1631. });
  1632. rows.forEach(function (row) {
  1633. row.calcHeight();
  1634. });
  1635. rows.forEach(function (row) {
  1636. row.setCellHeight();
  1637. });
  1638. };
  1639. Column.prototype.getWidth = function () {
  1640. var width = 0;
  1641. if (this.isGroup) {
  1642. this.columns.forEach(function (column) {
  1643. if (column.visible) {
  1644. width += column.getWidth();
  1645. }
  1646. });
  1647. } else {
  1648. width = this.width;
  1649. }
  1650. return width;
  1651. };
  1652. Column.prototype.getHeight = function () {
  1653. return this.element.offsetHeight;
  1654. };
  1655. Column.prototype.setMinWidth = function (minWidth) {
  1656. this.minWidth = minWidth;
  1657. this.minWidthStyled = minWidth ? minWidth + "px" : "";
  1658. this.element.style.minWidth = this.minWidthStyled;
  1659. this.cells.forEach(function (cell) {
  1660. cell.setMinWidth();
  1661. });
  1662. };
  1663. Column.prototype.delete = function () {
  1664. var _this9 = this;
  1665. return new Promise(function (resolve, reject) {
  1666. if (_this9.isGroup) {
  1667. _this9.columns.forEach(function (column) {
  1668. column.delete();
  1669. });
  1670. }
  1671. //cancel edit if column is currently being edited
  1672. if (_this9.table.modExists("edit")) {
  1673. if (_this9.table.modules.edit.currentCell.column === _this9) {
  1674. _this9.table.modules.edit.cancelEdit();
  1675. }
  1676. }
  1677. var cellCount = _this9.cells.length;
  1678. for (var _i3 = 0; _i3 < cellCount; _i3++) {
  1679. _this9.cells[0].delete();
  1680. }
  1681. if (_this9.element.parentNode) {
  1682. _this9.element.parentNode.removeChild(_this9.element);
  1683. }
  1684. _this9.element = false;
  1685. _this9.contentElement = false;
  1686. _this9.titleElement = false;
  1687. _this9.groupElement = false;
  1688. _this9.table.columnManager.deregisterColumn(_this9);
  1689. if (_this9.table.options.virtualDomHoz) {
  1690. _this9.table.vdomHoz.reinitialize(true);
  1691. }
  1692. resolve();
  1693. });
  1694. };
  1695. Column.prototype.columnRendered = function () {
  1696. if (this.titleFormatterRendered) {
  1697. this.titleFormatterRendered();
  1698. }
  1699. };
  1700. Column.prototype.validate = function () {
  1701. var invalid = [];
  1702. this.cells.forEach(function (cell) {
  1703. if (!cell.validate()) {
  1704. invalid.push(cell.getComponent());
  1705. }
  1706. });
  1707. return invalid.length ? invalid : true;
  1708. };
  1709. //////////////// Cell Management /////////////////
  1710. //generate cell for this column
  1711. Column.prototype.generateCell = function (row) {
  1712. var self = this;
  1713. var cell = new Cell(self, row);
  1714. this.cells.push(cell);
  1715. return cell;
  1716. };
  1717. Column.prototype.nextColumn = function () {
  1718. var index = this.table.columnManager.findColumnIndex(this);
  1719. return index > -1 ? this._nextVisibleColumn(index + 1) : false;
  1720. };
  1721. Column.prototype._nextVisibleColumn = function (index) {
  1722. var column = this.table.columnManager.getColumnByIndex(index);
  1723. return !column || column.visible ? column : this._nextVisibleColumn(index + 1);
  1724. };
  1725. Column.prototype.prevColumn = function () {
  1726. var index = this.table.columnManager.findColumnIndex(this);
  1727. return index > -1 ? this._prevVisibleColumn(index - 1) : false;
  1728. };
  1729. Column.prototype._prevVisibleColumn = function (index) {
  1730. var column = this.table.columnManager.getColumnByIndex(index);
  1731. return !column || column.visible ? column : this._prevVisibleColumn(index - 1);
  1732. };
  1733. Column.prototype.reinitializeWidth = function (force) {
  1734. this.widthFixed = false;
  1735. //set width if present
  1736. if (typeof this.definition.width !== "undefined" && !force) {
  1737. this.setWidth(this.definition.width);
  1738. }
  1739. //hide header filters to prevent them altering column width
  1740. if (this.table.modExists("filter")) {
  1741. this.table.modules.filter.hideHeaderFilterElements();
  1742. }
  1743. this.fitToData();
  1744. //show header filters again after layout is complete
  1745. if (this.table.modExists("filter")) {
  1746. this.table.modules.filter.showHeaderFilterElements();
  1747. }
  1748. };
  1749. //set column width to maximum cell width
  1750. Column.prototype.fitToData = function () {
  1751. var self = this;
  1752. if (!this.widthFixed) {
  1753. this.element.style.width = "";
  1754. self.cells.forEach(function (cell) {
  1755. cell.clearWidth();
  1756. });
  1757. }
  1758. var maxWidth = this.element.offsetWidth;
  1759. if (!self.width || !this.widthFixed) {
  1760. self.cells.forEach(function (cell) {
  1761. var width = cell.getWidth();
  1762. if (width > maxWidth) {
  1763. maxWidth = width;
  1764. }
  1765. });
  1766. if (maxWidth) {
  1767. self.setWidthActual(maxWidth + 1);
  1768. }
  1769. }
  1770. };
  1771. Column.prototype.updateDefinition = function (updates) {
  1772. var _this10 = this;
  1773. return new Promise(function (resolve, reject) {
  1774. var definition;
  1775. if (!_this10.isGroup) {
  1776. definition = Object.assign({}, _this10.getDefinition());
  1777. definition = Object.assign(definition, updates);
  1778. _this10.table.columnManager.addColumn(definition, false, _this10).then(function (column) {
  1779. if (definition.field == _this10.field) {
  1780. _this10.field = false; //cleair field name to prevent deletion of duplicate column from arrays
  1781. }
  1782. _this10.delete().then(function () {
  1783. resolve(column.getComponent());
  1784. }).catch(function (err) {
  1785. reject(err);
  1786. });
  1787. }).catch(function (err) {
  1788. reject(err);
  1789. });
  1790. } else {
  1791. console.warn("Column Update Error - The updateDefinition function is only available on columns, not column groups");
  1792. reject("Column Update Error - The updateDefinition function is only available on columns, not column groups");
  1793. }
  1794. });
  1795. };
  1796. Column.prototype.deleteCell = function (cell) {
  1797. var index = this.cells.indexOf(cell);
  1798. if (index > -1) {
  1799. this.cells.splice(index, 1);
  1800. }
  1801. };
  1802. 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",
  1803. // "headerClickMenu",
  1804. "clickMenu", "formatterPrint", "formatterPrintParams", "formatterClipboard", "formatterClipboardParams", "formatterHtmlOutput", "formatterHtmlOutputParams", "titlePrint", "titleClipboard", "titleHtmlOutput", "titleDownload"];
  1805. //////////////// Event Bindings /////////////////
  1806. //////////////// Object Generation /////////////////
  1807. Column.prototype.getComponent = function () {
  1808. if (!this.component) {
  1809. this.component = new ColumnComponent(this);
  1810. }
  1811. return this.component;
  1812. };
  1813. var RowManager = function RowManager(table) {
  1814. this.table = table;
  1815. this.element = this.createHolderElement(); //containing element
  1816. this.tableElement = this.createTableElement(); //table element
  1817. this.heightFixer = this.createTableElement(); //table element
  1818. this.columnManager = null; //hold column manager object
  1819. this.height = 0; //hold height of table element
  1820. this.firstRender = false; //handle first render
  1821. this.renderMode = "virtual"; //current rendering mode
  1822. this.fixedHeight = false; //current rendering mode
  1823. this.rows = []; //hold row data objects
  1824. this.activeRows = []; //rows currently available to on display in the table
  1825. this.activeRowsCount = 0; //count of active rows
  1826. this.displayRows = []; //rows currently on display in the table
  1827. this.displayRowsCount = 0; //count of display rows
  1828. this.scrollTop = 0;
  1829. this.scrollLeft = 0;
  1830. this.vDomRowHeight = 20; //approximation of row heights for padding
  1831. this.vDomTop = 0; //hold position for first rendered row in the virtual DOM
  1832. this.vDomBottom = 0; //hold possition for last rendered row in the virtual DOM
  1833. this.vDomScrollPosTop = 0; //last scroll position of the vDom top;
  1834. this.vDomScrollPosBottom = 0; //last scroll position of the vDom bottom;
  1835. this.vDomTopPad = 0; //hold value of padding for top of virtual DOM
  1836. this.vDomBottomPad = 0; //hold value of padding for bottom of virtual DOM
  1837. this.vDomMaxRenderChain = 90; //the maximum number of dom elements that can be rendered in 1 go
  1838. this.vDomWindowBuffer = 0; //window row buffer before removing elements, to smooth scrolling
  1839. this.vDomWindowMinTotalRows = 20; //minimum number of rows to be generated in virtual dom (prevent buffering issues on tables with tall rows)
  1840. this.vDomWindowMinMarginRows = 5; //minimum number of rows to be generated in virtual dom margin
  1841. this.vDomTopNewRows = []; //rows to normalize after appending to optimize render speed
  1842. this.vDomBottomNewRows = []; //rows to normalize after appending to optimize render speed
  1843. this.rowNumColumn = false; //hold column component for row number column
  1844. this.redrawBlock = false; //prevent redraws to allow multiple data manipulations becore continuing
  1845. this.redrawBlockRestoreConfig = false; //store latest redraw function calls for when redraw is needed
  1846. this.redrawBlockRederInPosition = false; //store latest redraw function calls for when redraw is needed
  1847. };
  1848. //////////////// Setup Functions /////////////////
  1849. RowManager.prototype.createHolderElement = function () {
  1850. var el = document.createElement("div");
  1851. el.classList.add("tabulator-tableHolder");
  1852. el.setAttribute("tabindex", 0);
  1853. return el;
  1854. };
  1855. RowManager.prototype.createTableElement = function () {
  1856. var el = document.createElement("div");
  1857. el.classList.add("tabulator-table");
  1858. return el;
  1859. };
  1860. //return containing element
  1861. RowManager.prototype.getElement = function () {
  1862. return this.element;
  1863. };
  1864. //return table element
  1865. RowManager.prototype.getTableElement = function () {
  1866. return this.tableElement;
  1867. };
  1868. //return position of row in table
  1869. RowManager.prototype.getRowPosition = function (row, active) {
  1870. if (active) {
  1871. return this.activeRows.indexOf(row);
  1872. } else {
  1873. return this.rows.indexOf(row);
  1874. }
  1875. };
  1876. //link to column manager
  1877. RowManager.prototype.setColumnManager = function (manager) {
  1878. this.columnManager = manager;
  1879. };
  1880. RowManager.prototype.initialize = function () {
  1881. var self = this;
  1882. self.setRenderMode();
  1883. //initialize manager
  1884. self.element.appendChild(self.tableElement);
  1885. self.firstRender = true;
  1886. //scroll header along with table body
  1887. self.element.addEventListener("scroll", function () {
  1888. var left = self.element.scrollLeft;
  1889. //handle horizontal scrolling
  1890. if (self.scrollLeft != left) {
  1891. self.columnManager.scrollHorizontal(left);
  1892. if (self.table.options.groupBy) {
  1893. self.table.modules.groupRows.scrollHeaders(left);
  1894. }
  1895. if (self.table.modExists("columnCalcs")) {
  1896. self.table.modules.columnCalcs.scrollHorizontal(left);
  1897. }
  1898. self.table.options.scrollHorizontal(left);
  1899. }
  1900. self.scrollLeft = left;
  1901. });
  1902. //handle virtual dom scrolling
  1903. if (this.renderMode === "virtual") {
  1904. self.element.addEventListener("scroll", function () {
  1905. var top = self.element.scrollTop;
  1906. var dir = self.scrollTop > top;
  1907. //handle verical scrolling
  1908. if (self.scrollTop != top) {
  1909. self.scrollTop = top;
  1910. self.scrollVertical(dir);
  1911. if (self.table.options.ajaxProgressiveLoad == "scroll") {
  1912. self.table.modules.ajax.nextPage(self.element.scrollHeight - self.element.clientHeight - top);
  1913. }
  1914. self.table.options.scrollVertical(top);
  1915. } else {
  1916. self.scrollTop = top;
  1917. }
  1918. });
  1919. }
  1920. };
  1921. ////////////////// Row Manipulation //////////////////
  1922. RowManager.prototype.findRow = function (subject) {
  1923. var self = this;
  1924. if ((typeof subject === 'undefined' ? 'undefined' : _typeof(subject)) == "object") {
  1925. if (subject instanceof Row) {
  1926. //subject is row element
  1927. return subject;
  1928. } else if (subject instanceof RowComponent) {
  1929. //subject is public row component
  1930. return subject._getSelf() || false;
  1931. } else if (typeof HTMLElement !== "undefined" && subject instanceof HTMLElement) {
  1932. //subject is a HTML element of the row
  1933. var match = self.rows.find(function (row) {
  1934. return row.element === subject;
  1935. });
  1936. return match || false;
  1937. }
  1938. } else if (typeof subject == "undefined" || subject === null) {
  1939. return false;
  1940. } else {
  1941. //subject should be treated as the index of the row
  1942. var _match = self.rows.find(function (row) {
  1943. return row.data[self.table.options.index] == subject;
  1944. });
  1945. return _match || false;
  1946. }
  1947. //catch all for any other type of input
  1948. return false;
  1949. };
  1950. RowManager.prototype.getRowFromDataObject = function (data) {
  1951. var match = this.rows.find(function (row) {
  1952. return row.data === data;
  1953. });
  1954. return match || false;
  1955. };
  1956. RowManager.prototype.getRowFromPosition = function (position, active) {
  1957. if (active) {
  1958. return this.activeRows[position];
  1959. } else {
  1960. return this.rows[position];
  1961. }
  1962. };
  1963. RowManager.prototype.scrollToRow = function (row, position, ifVisible) {
  1964. var _this11 = this;
  1965. var rowIndex = this.getDisplayRows().indexOf(row),
  1966. rowEl = row.getElement(),
  1967. rowTop,
  1968. offset = 0;
  1969. return new Promise(function (resolve, reject) {
  1970. if (rowIndex > -1) {
  1971. if (typeof position === "undefined") {
  1972. position = _this11.table.options.scrollToRowPosition;
  1973. }
  1974. if (typeof ifVisible === "undefined") {
  1975. ifVisible = _this11.table.options.scrollToRowIfVisible;
  1976. }
  1977. if (position === "nearest") {
  1978. switch (_this11.renderMode) {
  1979. case "classic":
  1980. rowTop = Tabulator.prototype.helpers.elOffset(rowEl).top;
  1981. position = Math.abs(_this11.element.scrollTop - rowTop) > Math.abs(_this11.element.scrollTop + _this11.element.clientHeight - rowTop) ? "bottom" : "top";
  1982. break;
  1983. case "virtual":
  1984. position = Math.abs(_this11.vDomTop - rowIndex) > Math.abs(_this11.vDomBottom - rowIndex) ? "bottom" : "top";
  1985. break;
  1986. }
  1987. }
  1988. //check row visibility
  1989. if (!ifVisible) {
  1990. if (Tabulator.prototype.helpers.elVisible(rowEl)) {
  1991. offset = Tabulator.prototype.helpers.elOffset(rowEl).top - Tabulator.prototype.helpers.elOffset(_this11.element).top;
  1992. if (offset > 0 && offset < _this11.element.clientHeight - rowEl.offsetHeight) {
  1993. return false;
  1994. }
  1995. }
  1996. }
  1997. //scroll to row
  1998. switch (_this11.renderMode) {
  1999. case "classic":
  2000. _this11.element.scrollTop = Tabulator.prototype.helpers.elOffset(rowEl).top - Tabulator.prototype.helpers.elOffset(_this11.element).top + _this11.element.scrollTop;
  2001. break;
  2002. case "virtual":
  2003. _this11._virtualRenderFill(rowIndex, true);
  2004. break;
  2005. }
  2006. //align to correct position
  2007. switch (position) {
  2008. case "middle":
  2009. case "center":
  2010. if (_this11.element.scrollHeight - _this11.element.scrollTop == _this11.element.clientHeight) {
  2011. _this11.element.scrollTop = _this11.element.scrollTop + (rowEl.offsetTop - _this11.element.scrollTop) - (_this11.element.scrollHeight - rowEl.offsetTop) / 2;
  2012. } else {
  2013. _this11.element.scrollTop = _this11.element.scrollTop - _this11.element.clientHeight / 2;
  2014. }
  2015. break;
  2016. case "bottom":
  2017. if (_this11.element.scrollHeight - _this11.element.scrollTop == _this11.element.clientHeight) {
  2018. _this11.element.scrollTop = _this11.element.scrollTop - (_this11.element.scrollHeight - rowEl.offsetTop) + rowEl.offsetHeight;
  2019. } else {
  2020. _this11.element.scrollTop = _this11.element.scrollTop - _this11.element.clientHeight + rowEl.offsetHeight;
  2021. }
  2022. break;
  2023. }
  2024. resolve();
  2025. } else {
  2026. console.warn("Scroll Error - Row not visible");
  2027. reject("Scroll Error - Row not visible");
  2028. }
  2029. });
  2030. };
  2031. ////////////////// Data Handling //////////////////
  2032. RowManager.prototype.setData = function (data, renderInPosition, columnsChanged) {
  2033. var _this12 = this;
  2034. var self = this;
  2035. return new Promise(function (resolve, reject) {
  2036. if (renderInPosition && _this12.getDisplayRows().length) {
  2037. if (self.table.options.pagination) {
  2038. self._setDataActual(data, true);
  2039. } else {
  2040. _this12.reRenderInPosition(function () {
  2041. self._setDataActual(data);
  2042. });
  2043. }
  2044. } else {
  2045. if (_this12.table.options.autoColumns && columnsChanged) {
  2046. _this12.table.columnManager.generateColumnsFromRowData(data);
  2047. }
  2048. _this12.resetScroll();
  2049. _this12._setDataActual(data);
  2050. }
  2051. resolve();
  2052. });
  2053. };
  2054. RowManager.prototype._setDataActual = function (data, renderInPosition) {
  2055. var self = this;
  2056. self.table.options.dataLoading.call(this.table, data);
  2057. this._wipeElements();
  2058. if (this.table.options.history && this.table.modExists("history")) {
  2059. this.table.modules.history.clear();
  2060. }
  2061. if (Array.isArray(data)) {
  2062. if (this.table.modExists("selectRow")) {
  2063. this.table.modules.selectRow.clearSelectionData();
  2064. }
  2065. if (this.table.options.reactiveData && this.table.modExists("reactiveData", true)) {
  2066. this.table.modules.reactiveData.watchData(data);
  2067. }
  2068. data.forEach(function (def, i) {
  2069. if (def && (typeof def === 'undefined' ? 'undefined' : _typeof(def)) === "object") {
  2070. var row = new Row(def, self);
  2071. self.rows.push(row);
  2072. } else {
  2073. console.warn("Data Loading Warning - Invalid row data detected and ignored, expecting object but received:", def);
  2074. }
  2075. });
  2076. self.refreshActiveData(false, false, renderInPosition);
  2077. self.table.options.dataLoaded.call(this.table, data);
  2078. } else {
  2079. 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);
  2080. }
  2081. };
  2082. RowManager.prototype._wipeElements = function () {
  2083. this.rows.forEach(function (row) {
  2084. row.wipe();
  2085. });
  2086. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  2087. this.table.modules.groupRows.wipe();
  2088. }
  2089. this.rows = [];
  2090. this.activeRows = [];
  2091. this.activeRowsCount = 0;
  2092. this.displayRows = [];
  2093. this.displayRowsCount = 0;
  2094. this.adjustTableSize();
  2095. };
  2096. RowManager.prototype.deleteRow = function (row, blockRedraw) {
  2097. var allIndex = this.rows.indexOf(row),
  2098. activeIndex = this.activeRows.indexOf(row);
  2099. if (activeIndex > -1) {
  2100. this.activeRows.splice(activeIndex, 1);
  2101. }
  2102. if (allIndex > -1) {
  2103. this.rows.splice(allIndex, 1);
  2104. }
  2105. this.setActiveRows(this.activeRows);
  2106. this.displayRowIterator(function (rows) {
  2107. var displayIndex = rows.indexOf(row);
  2108. if (displayIndex > -1) {
  2109. rows.splice(displayIndex, 1);
  2110. }
  2111. });
  2112. if (!blockRedraw) {
  2113. this.reRenderInPosition();
  2114. }
  2115. this.regenerateRowNumbers();
  2116. this.table.options.rowDeleted.call(this.table, row.getComponent());
  2117. if (this.table.options.dataChanged) {
  2118. this.table.options.dataChanged.call(this.table, this.getData());
  2119. }
  2120. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  2121. this.table.modules.groupRows.updateGroupRows(true);
  2122. } else if (this.table.options.pagination && this.table.modExists("page")) {
  2123. this.refreshActiveData(false, false, true);
  2124. } else {
  2125. if (this.table.options.pagination && this.table.modExists("page")) {
  2126. this.refreshActiveData("page");
  2127. }
  2128. }
  2129. };
  2130. RowManager.prototype.addRow = function (data, pos, index, blockRedraw) {
  2131. var row = this.addRowActual(data, pos, index, blockRedraw);
  2132. if (this.table.options.history && this.table.modExists("history")) {
  2133. this.table.modules.history.action("rowAdd", row, { data: data, pos: pos, index: index });
  2134. }
  2135. return row;
  2136. };
  2137. //add multiple rows
  2138. RowManager.prototype.addRows = function (data, pos, index) {
  2139. var _this13 = this;
  2140. var self = this,
  2141. length = 0,
  2142. rows = [];
  2143. return new Promise(function (resolve, reject) {
  2144. pos = _this13.findAddRowPos(pos);
  2145. if (!Array.isArray(data)) {
  2146. data = [data];
  2147. }
  2148. length = data.length - 1;
  2149. if (typeof index == "undefined" && pos || typeof index !== "undefined" && !pos) {
  2150. data.reverse();
  2151. }
  2152. data.forEach(function (item, i) {
  2153. var row = self.addRow(item, pos, index, true);
  2154. rows.push(row);
  2155. });
  2156. if (_this13.table.options.groupBy && _this13.table.modExists("groupRows")) {
  2157. _this13.table.modules.groupRows.updateGroupRows(true);
  2158. } else if (_this13.table.options.pagination && _this13.table.modExists("page")) {
  2159. _this13.refreshActiveData(false, false, true);
  2160. } else {
  2161. _this13.reRenderInPosition();
  2162. }
  2163. //recalc column calculations if present
  2164. if (_this13.table.modExists("columnCalcs")) {
  2165. _this13.table.modules.columnCalcs.recalc(_this13.table.rowManager.activeRows);
  2166. }
  2167. _this13.regenerateRowNumbers();
  2168. resolve(rows);
  2169. });
  2170. };
  2171. RowManager.prototype.findAddRowPos = function (pos) {
  2172. if (typeof pos === "undefined") {
  2173. pos = this.table.options.addRowPos;
  2174. }
  2175. if (pos === "pos") {
  2176. pos = true;
  2177. }
  2178. if (pos === "bottom") {
  2179. pos = false;
  2180. }
  2181. return pos;
  2182. };
  2183. RowManager.prototype.addRowActual = function (data, pos, index, blockRedraw) {
  2184. var row = data instanceof Row ? data : new Row(data || {}, this),
  2185. top = this.findAddRowPos(pos),
  2186. allIndex = -1,
  2187. activeIndex,
  2188. dispRows;
  2189. if (!index && this.table.options.pagination && this.table.options.paginationAddRow == "page") {
  2190. dispRows = this.getDisplayRows();
  2191. if (top) {
  2192. if (dispRows.length) {
  2193. index = dispRows[0];
  2194. } else {
  2195. if (this.activeRows.length) {
  2196. index = this.activeRows[this.activeRows.length - 1];
  2197. top = false;
  2198. }
  2199. }
  2200. } else {
  2201. if (dispRows.length) {
  2202. index = dispRows[dispRows.length - 1];
  2203. top = dispRows.length < this.table.modules.page.getPageSize() ? false : true;
  2204. }
  2205. }
  2206. }
  2207. if (typeof index !== "undefined") {
  2208. index = this.findRow(index);
  2209. }
  2210. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  2211. this.table.modules.groupRows.assignRowToGroup(row);
  2212. var groupRows = row.getGroup().rows;
  2213. if (groupRows.length > 1) {
  2214. if (!index || index && groupRows.indexOf(index) == -1) {
  2215. if (top) {
  2216. if (groupRows[0] !== row) {
  2217. index = groupRows[0];
  2218. this._moveRowInArray(row.getGroup().rows, row, index, !top);
  2219. }
  2220. } else {
  2221. if (groupRows[groupRows.length - 1] !== row) {
  2222. index = groupRows[groupRows.length - 1];
  2223. this._moveRowInArray(row.getGroup().rows, row, index, !top);
  2224. }
  2225. }
  2226. } else {
  2227. this._moveRowInArray(row.getGroup().rows, row, index, !top);
  2228. }
  2229. }
  2230. }
  2231. if (index) {
  2232. allIndex = this.rows.indexOf(index);
  2233. }
  2234. if (index && allIndex > -1) {
  2235. activeIndex = this.activeRows.indexOf(index);
  2236. this.displayRowIterator(function (rows) {
  2237. var displayIndex = rows.indexOf(index);
  2238. if (displayIndex > -1) {
  2239. rows.splice(top ? displayIndex : displayIndex + 1, 0, row);
  2240. }
  2241. });
  2242. if (activeIndex > -1) {
  2243. this.activeRows.splice(top ? activeIndex : activeIndex + 1, 0, row);
  2244. }
  2245. this.rows.splice(top ? allIndex : allIndex + 1, 0, row);
  2246. } else {
  2247. if (top) {
  2248. this.displayRowIterator(function (rows) {
  2249. rows.unshift(row);
  2250. });
  2251. this.activeRows.unshift(row);
  2252. this.rows.unshift(row);
  2253. } else {
  2254. this.displayRowIterator(function (rows) {
  2255. rows.push(row);
  2256. });
  2257. this.activeRows.push(row);
  2258. this.rows.push(row);
  2259. }
  2260. }
  2261. this.setActiveRows(this.activeRows);
  2262. this.table.options.rowAdded.call(this.table, row.getComponent());
  2263. if (this.table.options.dataChanged) {
  2264. this.table.options.dataChanged.call(this.table, this.getData());
  2265. }
  2266. if (!blockRedraw) {
  2267. this.reRenderInPosition();
  2268. }
  2269. return row;
  2270. };
  2271. RowManager.prototype.moveRow = function (from, to, after) {
  2272. if (this.table.options.history && this.table.modExists("history")) {
  2273. this.table.modules.history.action("rowMove", from, { posFrom: this.getRowPosition(from), posTo: this.getRowPosition(to), to: to, after: after });
  2274. }
  2275. this.moveRowActual(from, to, after);
  2276. this.regenerateRowNumbers();
  2277. this.table.options.rowMoved.call(this.table, from.getComponent());
  2278. };
  2279. RowManager.prototype.moveRowActual = function (from, to, after) {
  2280. var _this14 = this;
  2281. this._moveRowInArray(this.rows, from, to, after);
  2282. this._moveRowInArray(this.activeRows, from, to, after);
  2283. this.displayRowIterator(function (rows) {
  2284. _this14._moveRowInArray(rows, from, to, after);
  2285. });
  2286. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  2287. if (!after && to instanceof Group) {
  2288. to = this.table.rowManager.prevDisplayRow(from) || to;
  2289. }
  2290. var toGroup = to.getGroup();
  2291. var fromGroup = from.getGroup();
  2292. if (toGroup === fromGroup) {
  2293. this._moveRowInArray(toGroup.rows, from, to, after);
  2294. } else {
  2295. if (fromGroup) {
  2296. fromGroup.removeRow(from);
  2297. }
  2298. toGroup.insertRow(from, to, after);
  2299. }
  2300. }
  2301. };
  2302. RowManager.prototype._moveRowInArray = function (rows, from, to, after) {
  2303. var fromIndex, toIndex, start, end;
  2304. if (from !== to) {
  2305. fromIndex = rows.indexOf(from);
  2306. if (fromIndex > -1) {
  2307. rows.splice(fromIndex, 1);
  2308. toIndex = rows.indexOf(to);
  2309. if (toIndex > -1) {
  2310. if (after) {
  2311. rows.splice(toIndex + 1, 0, from);
  2312. } else {
  2313. rows.splice(toIndex, 0, from);
  2314. }
  2315. } else {
  2316. rows.splice(fromIndex, 0, from);
  2317. }
  2318. }
  2319. //restyle rows
  2320. if (rows === this.getDisplayRows()) {
  2321. start = fromIndex < toIndex ? fromIndex : toIndex;
  2322. end = toIndex > fromIndex ? toIndex : fromIndex + 1;
  2323. for (var _i4 = start; _i4 <= end; _i4++) {
  2324. if (rows[_i4]) {
  2325. this.styleRow(rows[_i4], _i4);
  2326. }
  2327. }
  2328. }
  2329. }
  2330. };
  2331. RowManager.prototype.clearData = function () {
  2332. this.setData([]);
  2333. };
  2334. RowManager.prototype.getRowIndex = function (row) {
  2335. return this.findRowIndex(row, this.rows);
  2336. };
  2337. RowManager.prototype.getDisplayRowIndex = function (row) {
  2338. var index = this.getDisplayRows().indexOf(row);
  2339. return index > -1 ? index : false;
  2340. };
  2341. RowManager.prototype.nextDisplayRow = function (row, rowOnly) {
  2342. var index = this.getDisplayRowIndex(row),
  2343. nextRow = false;
  2344. if (index !== false && index < this.displayRowsCount - 1) {
  2345. nextRow = this.getDisplayRows()[index + 1];
  2346. }
  2347. if (nextRow && (!(nextRow instanceof Row) || nextRow.type != "row")) {
  2348. return this.nextDisplayRow(nextRow, rowOnly);
  2349. }
  2350. return nextRow;
  2351. };
  2352. RowManager.prototype.prevDisplayRow = function (row, rowOnly) {
  2353. var index = this.getDisplayRowIndex(row),
  2354. prevRow = false;
  2355. if (index) {
  2356. prevRow = this.getDisplayRows()[index - 1];
  2357. }
  2358. if (rowOnly && prevRow && (!(prevRow instanceof Row) || prevRow.type != "row")) {
  2359. return this.prevDisplayRow(prevRow, rowOnly);
  2360. }
  2361. return prevRow;
  2362. };
  2363. RowManager.prototype.findRowIndex = function (row, list) {
  2364. var rowIndex;
  2365. row = this.findRow(row);
  2366. if (row) {
  2367. rowIndex = list.indexOf(row);
  2368. if (rowIndex > -1) {
  2369. return rowIndex;
  2370. }
  2371. }
  2372. return false;
  2373. };
  2374. RowManager.prototype.getData = function (active, transform) {
  2375. var output = [],
  2376. rows = this.getRows(active);
  2377. rows.forEach(function (row) {
  2378. if (row.type == "row") {
  2379. output.push(row.getData(transform || "data"));
  2380. }
  2381. });
  2382. return output;
  2383. };
  2384. RowManager.prototype.getComponents = function (active) {
  2385. var output = [],
  2386. rows = this.getRows(active);
  2387. rows.forEach(function (row) {
  2388. output.push(row.getComponent());
  2389. });
  2390. return output;
  2391. };
  2392. RowManager.prototype.getDataCount = function (active) {
  2393. var rows = this.getRows(active);
  2394. return rows.length;
  2395. };
  2396. RowManager.prototype._genRemoteRequest = function () {
  2397. var _this15 = this;
  2398. var table = this.table,
  2399. options = table.options,
  2400. params = {};
  2401. if (table.modExists("page")) {
  2402. //set sort data if defined
  2403. if (options.ajaxSorting) {
  2404. var sorters = this.table.modules.sort.getSort();
  2405. sorters.forEach(function (item) {
  2406. delete item.column;
  2407. });
  2408. params[this.table.modules.page.paginationDataSentNames.sorters] = sorters;
  2409. }
  2410. //set filter data if defined
  2411. if (options.ajaxFiltering) {
  2412. var filters = this.table.modules.filter.getFilters(true, true);
  2413. params[this.table.modules.page.paginationDataSentNames.filters] = filters;
  2414. }
  2415. this.table.modules.ajax.setParams(params, true);
  2416. }
  2417. table.modules.ajax.sendRequest().then(function (data) {
  2418. _this15._setDataActual(data, true);
  2419. }).catch(function (e) {});
  2420. };
  2421. //choose the path to refresh data after a filter update
  2422. RowManager.prototype.filterRefresh = function () {
  2423. var table = this.table,
  2424. options = table.options,
  2425. left = this.scrollLeft;
  2426. if (options.ajaxFiltering) {
  2427. if (options.pagination == "remote" && table.modExists("page")) {
  2428. table.modules.page.reset(true);
  2429. table.modules.page.setPage(1).then(function () {}).catch(function () {});
  2430. } else if (options.ajaxProgressiveLoad) {
  2431. table.modules.ajax.loadData().then(function () {}).catch(function () {});
  2432. } else {
  2433. //assume data is url, make ajax call to url to get data
  2434. this._genRemoteRequest();
  2435. }
  2436. } else {
  2437. this.refreshActiveData("filter");
  2438. }
  2439. this.scrollHorizontal(left);
  2440. };
  2441. //choose the path to refresh data after a sorter update
  2442. RowManager.prototype.sorterRefresh = function (loadOrignalData) {
  2443. var table = this.table,
  2444. options = this.table.options,
  2445. left = this.scrollLeft;
  2446. if (options.ajaxSorting) {
  2447. if ((options.pagination == "remote" || options.progressiveLoad) && table.modExists("page")) {
  2448. table.modules.page.reset(true);
  2449. table.modules.page.setPage(1).then(function () {}).catch(function () {});
  2450. } else if (options.ajaxProgressiveLoad) {
  2451. table.modules.ajax.loadData().then(function () {}).catch(function () {});
  2452. } else {
  2453. //assume data is url, make ajax call to url to get data
  2454. this._genRemoteRequest();
  2455. }
  2456. } else {
  2457. this.refreshActiveData(loadOrignalData ? "filter" : "sort");
  2458. }
  2459. this.scrollHorizontal(left);
  2460. };
  2461. RowManager.prototype.scrollHorizontal = function (left) {
  2462. this.scrollLeft = left;
  2463. this.element.scrollLeft = left;
  2464. if (this.table.options.groupBy) {
  2465. this.table.modules.groupRows.scrollHeaders(left);
  2466. }
  2467. if (this.table.modExists("columnCalcs")) {
  2468. this.table.modules.columnCalcs.scrollHorizontal(left);
  2469. }
  2470. };
  2471. //set active data set
  2472. RowManager.prototype.refreshActiveData = function (stage, skipStage, renderInPosition) {
  2473. var self = this,
  2474. table = this.table,
  2475. cascadeOrder = ["all", "filter", "sort", "display", "freeze", "group", "tree", "page"],
  2476. displayIndex;
  2477. if (this.redrawBlock) {
  2478. if (!this.redrawBlockRestoreConfig || cascadeOrder.indexOf(stage) < cascadeOrder.indexOf(this.redrawBlockRestoreConfig.stage)) {
  2479. this.redrawBlockRestoreConfig = {
  2480. stage: stage,
  2481. skipStage: skipStage,
  2482. renderInPosition: renderInPosition
  2483. };
  2484. }
  2485. return;
  2486. } else {
  2487. if (self.table.modExists("edit")) {
  2488. self.table.modules.edit.cancelEdit();
  2489. }
  2490. if (!stage) {
  2491. stage = "all";
  2492. }
  2493. if (table.options.selectable && !table.options.selectablePersistence && table.modExists("selectRow")) {
  2494. table.modules.selectRow.deselectRows();
  2495. }
  2496. //cascade through data refresh stages
  2497. switch (stage) {
  2498. case "all":
  2499. case "filter":
  2500. if (!skipStage) {
  2501. if (table.modExists("filter")) {
  2502. self.setActiveRows(table.modules.filter.filter(self.rows));
  2503. } else {
  2504. self.setActiveRows(self.rows.slice(0));
  2505. }
  2506. } else {
  2507. skipStage = false;
  2508. }
  2509. case "sort":
  2510. if (!skipStage) {
  2511. if (table.modExists("sort")) {
  2512. table.modules.sort.sort(this.activeRows);
  2513. }
  2514. } else {
  2515. skipStage = false;
  2516. }
  2517. //regenerate row numbers for row number formatter if in use
  2518. this.regenerateRowNumbers();
  2519. //generic stage to allow for pipeline trigger after the data manipulation stage
  2520. case "display":
  2521. this.resetDisplayRows();
  2522. case "freeze":
  2523. if (!skipStage) {
  2524. if (this.table.modExists("frozenRows")) {
  2525. if (table.modules.frozenRows.isFrozen()) {
  2526. if (!table.modules.frozenRows.getDisplayIndex()) {
  2527. table.modules.frozenRows.setDisplayIndex(this.getNextDisplayIndex());
  2528. }
  2529. displayIndex = table.modules.frozenRows.getDisplayIndex();
  2530. displayIndex = self.setDisplayRows(table.modules.frozenRows.getRows(this.getDisplayRows(displayIndex - 1)), displayIndex);
  2531. if (displayIndex !== true) {
  2532. table.modules.frozenRows.setDisplayIndex(displayIndex);
  2533. }
  2534. }
  2535. }
  2536. } else {
  2537. skipStage = false;
  2538. }
  2539. case "group":
  2540. if (!skipStage) {
  2541. if (table.options.groupBy && table.modExists("groupRows")) {
  2542. if (!table.modules.groupRows.getDisplayIndex()) {
  2543. table.modules.groupRows.setDisplayIndex(this.getNextDisplayIndex());
  2544. }
  2545. displayIndex = table.modules.groupRows.getDisplayIndex();
  2546. displayIndex = self.setDisplayRows(table.modules.groupRows.getRows(this.getDisplayRows(displayIndex - 1)), displayIndex);
  2547. if (displayIndex !== true) {
  2548. table.modules.groupRows.setDisplayIndex(displayIndex);
  2549. }
  2550. }
  2551. } else {
  2552. skipStage = false;
  2553. }
  2554. case "tree":
  2555. if (!skipStage) {
  2556. if (table.options.dataTree && table.modExists("dataTree")) {
  2557. if (!table.modules.dataTree.getDisplayIndex()) {
  2558. table.modules.dataTree.setDisplayIndex(this.getNextDisplayIndex());
  2559. }
  2560. displayIndex = table.modules.dataTree.getDisplayIndex();
  2561. displayIndex = self.setDisplayRows(table.modules.dataTree.getRows(this.getDisplayRows(displayIndex - 1)), displayIndex);
  2562. if (displayIndex !== true) {
  2563. table.modules.dataTree.setDisplayIndex(displayIndex);
  2564. }
  2565. }
  2566. } else {
  2567. skipStage = false;
  2568. }
  2569. if (table.options.pagination && table.modExists("page") && !renderInPosition) {
  2570. if (table.modules.page.getMode() == "local") {
  2571. table.modules.page.reset();
  2572. }
  2573. }
  2574. case "page":
  2575. if (!skipStage) {
  2576. if (table.options.pagination && table.modExists("page")) {
  2577. if (!table.modules.page.getDisplayIndex()) {
  2578. table.modules.page.setDisplayIndex(this.getNextDisplayIndex());
  2579. }
  2580. displayIndex = table.modules.page.getDisplayIndex();
  2581. if (table.modules.page.getMode() == "local") {
  2582. table.modules.page.setMaxRows(this.getDisplayRows(displayIndex - 1).length);
  2583. }
  2584. displayIndex = self.setDisplayRows(table.modules.page.getRows(this.getDisplayRows(displayIndex - 1)), displayIndex);
  2585. if (displayIndex !== true) {
  2586. table.modules.page.setDisplayIndex(displayIndex);
  2587. }
  2588. }
  2589. } else {
  2590. skipStage = false;
  2591. }
  2592. }
  2593. if (Tabulator.prototype.helpers.elVisible(self.element)) {
  2594. if (renderInPosition) {
  2595. self.reRenderInPosition();
  2596. } else {
  2597. if (stage === "all" && this.table.options.virtualDomHoz) {
  2598. this.table.vdomHoz.dataChange();
  2599. }
  2600. self.renderTable();
  2601. if (table.options.layoutColumnsOnNewData) {
  2602. self.table.columnManager.redraw(true);
  2603. }
  2604. }
  2605. }
  2606. if (table.modExists("columnCalcs")) {
  2607. table.modules.columnCalcs.recalc(this.activeRows);
  2608. }
  2609. }
  2610. };
  2611. //regenerate row numbers for row number formatter if in use
  2612. RowManager.prototype.regenerateRowNumbers = function () {
  2613. var _this16 = this;
  2614. if (this.rowNumColumn) {
  2615. this.activeRows.forEach(function (row) {
  2616. var cell = row.getCell(_this16.rowNumColumn);
  2617. if (cell) {
  2618. cell._generateContents();
  2619. }
  2620. });
  2621. }
  2622. };
  2623. RowManager.prototype.setActiveRows = function (activeRows) {
  2624. this.activeRows = activeRows;
  2625. this.activeRowsCount = this.activeRows.length;
  2626. };
  2627. //reset display rows array
  2628. RowManager.prototype.resetDisplayRows = function () {
  2629. this.displayRows = [];
  2630. this.displayRows.push(this.activeRows.slice(0));
  2631. this.displayRowsCount = this.displayRows[0].length;
  2632. if (this.table.modExists("frozenRows")) {
  2633. this.table.modules.frozenRows.setDisplayIndex(0);
  2634. }
  2635. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  2636. this.table.modules.groupRows.setDisplayIndex(0);
  2637. }
  2638. if (this.table.options.pagination && this.table.modExists("page")) {
  2639. this.table.modules.page.setDisplayIndex(0);
  2640. }
  2641. };
  2642. RowManager.prototype.getNextDisplayIndex = function () {
  2643. return this.displayRows.length;
  2644. };
  2645. //set display row pipeline data
  2646. RowManager.prototype.setDisplayRows = function (displayRows, index) {
  2647. var output = true;
  2648. if (index && typeof this.displayRows[index] != "undefined") {
  2649. this.displayRows[index] = displayRows;
  2650. output = true;
  2651. } else {
  2652. this.displayRows.push(displayRows);
  2653. output = index = this.displayRows.length - 1;
  2654. }
  2655. if (index == this.displayRows.length - 1) {
  2656. this.displayRowsCount = this.displayRows[this.displayRows.length - 1].length;
  2657. }
  2658. return output;
  2659. };
  2660. RowManager.prototype.getDisplayRows = function (index) {
  2661. if (typeof index == "undefined") {
  2662. return this.displayRows.length ? this.displayRows[this.displayRows.length - 1] : [];
  2663. } else {
  2664. return this.displayRows[index] || [];
  2665. }
  2666. };
  2667. RowManager.prototype.getVisibleRows = function (viewable) {
  2668. var topEdge = this.element.scrollTop,
  2669. bottomEdge = this.element.clientHeight + topEdge,
  2670. topFound = false,
  2671. topRow = 0,
  2672. bottomRow = 0,
  2673. rows = this.getDisplayRows();
  2674. if (viewable) {
  2675. this.getDisplayRows();
  2676. for (var i = this.vDomTop; i <= this.vDomBottom; i++) {
  2677. if (rows[i]) {
  2678. if (!topFound) {
  2679. if (topEdge - rows[i].getElement().offsetTop >= 0) {
  2680. topRow = i;
  2681. } else {
  2682. topFound = true;
  2683. if (bottomEdge - rows[i].getElement().offsetTop >= 0) {
  2684. bottomRow = i;
  2685. } else {
  2686. break;
  2687. }
  2688. }
  2689. } else {
  2690. if (bottomEdge - rows[i].getElement().offsetTop >= 0) {
  2691. bottomRow = i;
  2692. } else {
  2693. break;
  2694. }
  2695. }
  2696. }
  2697. }
  2698. } else {
  2699. topRow = this.vDomTop;
  2700. bottomRow = this.vDomBottom;
  2701. }
  2702. return rows.slice(topRow, bottomRow + 1);
  2703. };
  2704. //repeat action accross display rows
  2705. RowManager.prototype.displayRowIterator = function (callback) {
  2706. this.displayRows.forEach(callback);
  2707. this.displayRowsCount = this.displayRows[this.displayRows.length - 1].length;
  2708. };
  2709. //return only actual rows (not group headers etc)
  2710. RowManager.prototype.getRows = function (active) {
  2711. var rows;
  2712. switch (active) {
  2713. case "active":
  2714. rows = this.activeRows;
  2715. break;
  2716. case "display":
  2717. rows = this.table.rowManager.getDisplayRows();
  2718. break;
  2719. case "visible":
  2720. rows = this.getVisibleRows(true);
  2721. break;
  2722. case "selected":
  2723. rows = this.table.modules.selectRow.selectedRows;
  2724. break;
  2725. default:
  2726. rows = this.rows;
  2727. }
  2728. return rows;
  2729. };
  2730. ///////////////// Table Rendering /////////////////
  2731. //trigger rerender of table in current position
  2732. RowManager.prototype.reRenderInPosition = function (callback) {
  2733. if (this.getRenderMode() == "virtual") {
  2734. if (this.redrawBlock) {
  2735. if (callback) {
  2736. callback();
  2737. } else {
  2738. this.redrawBlockRederInPosition = true;
  2739. }
  2740. } else {
  2741. var scrollTop = this.element.scrollTop;
  2742. var topRow = false;
  2743. var topOffset = false;
  2744. var left = this.scrollLeft;
  2745. var rows = this.getDisplayRows();
  2746. for (var i = this.vDomTop; i <= this.vDomBottom; i++) {
  2747. if (rows[i]) {
  2748. var diff = scrollTop - rows[i].getElement().offsetTop;
  2749. if (topOffset === false || Math.abs(diff) < topOffset) {
  2750. topOffset = diff;
  2751. topRow = i;
  2752. } else {
  2753. break;
  2754. }
  2755. }
  2756. }
  2757. if (callback) {
  2758. callback();
  2759. }
  2760. this._virtualRenderFill(topRow === false ? this.displayRowsCount - 1 : topRow, true, topOffset || 0);
  2761. this.scrollHorizontal(left);
  2762. }
  2763. } else {
  2764. this.renderTable();
  2765. if (callback) {
  2766. callback();
  2767. }
  2768. }
  2769. };
  2770. RowManager.prototype.setRenderMode = function () {
  2771. if (this.table.options.virtualDom) {
  2772. this.renderMode = "virtual";
  2773. if (this.table.element.clientHeight || this.table.options.height) {
  2774. this.fixedHeight = true;
  2775. } else {
  2776. this.fixedHeight = false;
  2777. }
  2778. } else {
  2779. this.renderMode = "classic";
  2780. }
  2781. };
  2782. RowManager.prototype.getRenderMode = function () {
  2783. return this.renderMode;
  2784. };
  2785. RowManager.prototype.renderTable = function () {
  2786. this.table.options.renderStarted.call(this.table);
  2787. this.element.scrollTop = 0;
  2788. switch (this.renderMode) {
  2789. case "classic":
  2790. this._simpleRender();
  2791. break;
  2792. case "virtual":
  2793. this._virtualRenderFill();
  2794. break;
  2795. }
  2796. if (this.firstRender) {
  2797. if (this.displayRowsCount) {
  2798. this.firstRender = false;
  2799. this.table.modules.layout.layout();
  2800. } else {
  2801. this.renderEmptyScroll();
  2802. }
  2803. }
  2804. if (this.table.modExists("frozenColumns")) {
  2805. this.table.modules.frozenColumns.layout();
  2806. }
  2807. if (!this.displayRowsCount) {
  2808. if (this.table.options.placeholder) {
  2809. this.table.options.placeholder.setAttribute("tabulator-render-mode", this.renderMode);
  2810. this.getElement().appendChild(this.table.options.placeholder);
  2811. this.table.options.placeholder.style.width = this.table.columnManager.getWidth() + "px";
  2812. }
  2813. }
  2814. this.table.options.renderComplete.call(this.table);
  2815. };
  2816. //simple render on heightless table
  2817. RowManager.prototype._simpleRender = function () {
  2818. this._clearVirtualDom();
  2819. if (this.displayRowsCount) {
  2820. this.checkClassicModeGroupHeaderWidth();
  2821. } else {
  2822. this.renderEmptyScroll();
  2823. }
  2824. };
  2825. RowManager.prototype.checkClassicModeGroupHeaderWidth = function () {
  2826. var self = this,
  2827. element = this.tableElement,
  2828. onlyGroupHeaders = true;
  2829. self.getDisplayRows().forEach(function (row, index) {
  2830. self.styleRow(row, index);
  2831. element.appendChild(row.getElement());
  2832. row.initialize(true);
  2833. if (row.type !== "group") {
  2834. onlyGroupHeaders = false;
  2835. }
  2836. });
  2837. if (onlyGroupHeaders) {
  2838. element.style.minWidth = self.table.columnManager.getWidth() + "px";
  2839. } else {
  2840. element.style.minWidth = "";
  2841. }
  2842. };
  2843. //show scrollbars on empty table div
  2844. RowManager.prototype.renderEmptyScroll = function () {
  2845. if (this.table.options.placeholder) {
  2846. this.tableElement.style.display = "none";
  2847. } else {
  2848. this.tableElement.style.minWidth = this.table.columnManager.getWidth() + "px";
  2849. // this.tableElement.style.minHeight = "1px";
  2850. // this.tableElement.style.visibility = "hidden";
  2851. }
  2852. };
  2853. RowManager.prototype._clearVirtualDom = function () {
  2854. var element = this.tableElement;
  2855. if (this.table.options.placeholder && this.table.options.placeholder.parentNode) {
  2856. this.table.options.placeholder.parentNode.removeChild(this.table.options.placeholder);
  2857. }
  2858. // element.children.detach();
  2859. while (element.firstChild) {
  2860. element.removeChild(element.firstChild);
  2861. }element.style.paddingTop = "";
  2862. element.style.paddingBottom = "";
  2863. element.style.minWidth = "";
  2864. element.style.minHeight = "";
  2865. element.style.display = "";
  2866. element.style.visibility = "";
  2867. this.scrollTop = 0;
  2868. this.scrollLeft = 0;
  2869. this.vDomTop = 0;
  2870. this.vDomBottom = 0;
  2871. this.vDomTopPad = 0;
  2872. this.vDomBottomPad = 0;
  2873. };
  2874. RowManager.prototype.styleRow = function (row, index) {
  2875. var rowEl = row.getElement();
  2876. if (index % 2) {
  2877. rowEl.classList.add("tabulator-row-even");
  2878. rowEl.classList.remove("tabulator-row-odd");
  2879. } else {
  2880. rowEl.classList.add("tabulator-row-odd");
  2881. rowEl.classList.remove("tabulator-row-even");
  2882. }
  2883. };
  2884. //full virtual render
  2885. RowManager.prototype._virtualRenderFill = function (position, forceMove, offset) {
  2886. var self = this,
  2887. element = self.tableElement,
  2888. holder = self.element,
  2889. topPad = 0,
  2890. rowsHeight = 0,
  2891. topPadHeight = 0,
  2892. i = 0,
  2893. onlyGroupHeaders = true,
  2894. rows = self.getDisplayRows();
  2895. position = position || 0;
  2896. offset = offset || 0;
  2897. if (!position) {
  2898. self._clearVirtualDom();
  2899. } else {
  2900. while (element.firstChild) {
  2901. element.removeChild(element.firstChild);
  2902. } //check if position is too close to bottom of table
  2903. var heightOccupied = (self.displayRowsCount - position + 1) * self.vDomRowHeight;
  2904. if (heightOccupied < self.height) {
  2905. position -= Math.ceil((self.height - heightOccupied) / self.vDomRowHeight);
  2906. if (position < 0) {
  2907. position = 0;
  2908. }
  2909. }
  2910. //calculate initial pad
  2911. topPad = Math.min(Math.max(Math.floor(self.vDomWindowBuffer / self.vDomRowHeight), self.vDomWindowMinMarginRows), position);
  2912. position -= topPad;
  2913. }
  2914. if (self.displayRowsCount && Tabulator.prototype.helpers.elVisible(self.element)) {
  2915. self.vDomTop = position;
  2916. self.vDomBottom = position - 1;
  2917. while ((rowsHeight <= self.height + self.vDomWindowBuffer || i < self.vDomWindowMinTotalRows) && self.vDomBottom < self.displayRowsCount - 1) {
  2918. var index = self.vDomBottom + 1,
  2919. row = rows[index],
  2920. rowHeight = 0;
  2921. self.styleRow(row, index);
  2922. element.appendChild(row.getElement());
  2923. row.initialize();
  2924. if (!row.heightInitialized) {
  2925. row.normalizeHeight(true);
  2926. }
  2927. // if(!row.initialized){
  2928. // row.initialize(true);
  2929. // }else{
  2930. // if(!row.heightInitialized){
  2931. // row.normalizeHeight(true);
  2932. // }
  2933. // }
  2934. rowHeight = row.getHeight();
  2935. if (i < topPad) {
  2936. topPadHeight += rowHeight;
  2937. } else {
  2938. rowsHeight += rowHeight;
  2939. }
  2940. if (rowHeight > this.vDomWindowBuffer) {
  2941. this.vDomWindowBuffer = rowHeight * 2;
  2942. }
  2943. if (row.type !== "group") {
  2944. onlyGroupHeaders = false;
  2945. }
  2946. self.vDomBottom++;
  2947. i++;
  2948. }
  2949. if (!position) {
  2950. this.vDomTopPad = 0;
  2951. //adjust rowheight to match average of rendered elements
  2952. self.vDomRowHeight = Math.floor((rowsHeight + topPadHeight) / i);
  2953. self.vDomBottomPad = self.vDomRowHeight * (self.displayRowsCount - self.vDomBottom - 1);
  2954. self.vDomScrollHeight = topPadHeight + rowsHeight + self.vDomBottomPad - self.height;
  2955. } else {
  2956. self.vDomTopPad = !forceMove ? self.scrollTop - topPadHeight : self.vDomRowHeight * this.vDomTop + offset;
  2957. self.vDomBottomPad = self.vDomBottom == self.displayRowsCount - 1 ? 0 : Math.max(self.vDomScrollHeight - self.vDomTopPad - rowsHeight - topPadHeight, 0);
  2958. }
  2959. element.style.paddingTop = self.vDomTopPad + "px";
  2960. element.style.paddingBottom = self.vDomBottomPad + "px";
  2961. if (forceMove) {
  2962. this.scrollTop = self.vDomTopPad + topPadHeight + offset - (this.element.scrollWidth > this.element.clientWidth ? this.element.offsetHeight - this.element.clientHeight : 0);
  2963. }
  2964. this.scrollTop = Math.min(this.scrollTop, this.element.scrollHeight - this.height);
  2965. //adjust for horizontal scrollbar if present (and not at top of table)
  2966. if (this.element.scrollWidth > this.element.offsetWidth && forceMove) {
  2967. this.scrollTop += this.element.offsetHeight - this.element.clientHeight;
  2968. }
  2969. this.vDomScrollPosTop = this.scrollTop;
  2970. this.vDomScrollPosBottom = this.scrollTop;
  2971. holder.scrollTop = this.scrollTop;
  2972. element.style.minWidth = onlyGroupHeaders ? self.table.columnManager.getWidth() + "px" : "";
  2973. if (self.table.options.groupBy) {
  2974. if (self.table.modules.layout.getMode() != "fitDataFill" && self.displayRowsCount == self.table.modules.groupRows.countGroups()) {
  2975. self.tableElement.style.minWidth = self.table.columnManager.getWidth();
  2976. }
  2977. }
  2978. } else {
  2979. this.renderEmptyScroll();
  2980. }
  2981. if (!this.fixedHeight) {
  2982. this.adjustTableSize();
  2983. }
  2984. };
  2985. //handle vertical scrolling
  2986. RowManager.prototype.scrollVertical = function (dir) {
  2987. var topDiff = this.scrollTop - this.vDomScrollPosTop;
  2988. var bottomDiff = this.scrollTop - this.vDomScrollPosBottom;
  2989. var margin = this.vDomWindowBuffer * 2;
  2990. if (-topDiff > margin || bottomDiff > margin) {
  2991. //if big scroll redraw table;
  2992. var left = this.scrollLeft;
  2993. this._virtualRenderFill(Math.floor(this.element.scrollTop / this.element.scrollHeight * this.displayRowsCount));
  2994. this.scrollHorizontal(left);
  2995. } else {
  2996. if (dir) {
  2997. //scrolling up
  2998. if (topDiff < 0) {
  2999. this._addTopRow(-topDiff);
  3000. }
  3001. if (bottomDiff < 0) {
  3002. //hide bottom row if needed
  3003. if (this.vDomScrollHeight - this.scrollTop > this.vDomWindowBuffer) {
  3004. this._removeBottomRow(-bottomDiff);
  3005. } else {
  3006. this.vDomScrollPosBottom = this.scrollTop;
  3007. }
  3008. }
  3009. } else {
  3010. //scrolling down
  3011. if (topDiff >= 0) {
  3012. //hide top row if needed
  3013. if (this.scrollTop > this.vDomWindowBuffer) {
  3014. this._removeTopRow(topDiff);
  3015. } else {
  3016. this.vDomScrollPosTop = this.scrollTop;
  3017. }
  3018. }
  3019. if (bottomDiff >= 0) {
  3020. this._addBottomRow(bottomDiff);
  3021. }
  3022. }
  3023. }
  3024. };
  3025. RowManager.prototype._addTopRow = function (topDiff) {
  3026. var i = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  3027. var table = this.tableElement,
  3028. rows = this.getDisplayRows();
  3029. if (this.vDomTop) {
  3030. var index = this.vDomTop - 1,
  3031. topRow = rows[index],
  3032. topRowHeight = topRow.getHeight() || this.vDomRowHeight;
  3033. //hide top row if needed
  3034. if (topDiff >= topRowHeight) {
  3035. this.styleRow(topRow, index);
  3036. table.insertBefore(topRow.getElement(), table.firstChild);
  3037. if (!topRow.initialized || !topRow.heightInitialized) {
  3038. this.vDomTopNewRows.push(topRow);
  3039. if (!topRow.heightInitialized) {
  3040. topRow.clearCellHeight();
  3041. }
  3042. }
  3043. topRow.initialize();
  3044. this.vDomTopPad -= topRowHeight;
  3045. if (this.vDomTopPad < 0) {
  3046. this.vDomTopPad = index * this.vDomRowHeight;
  3047. }
  3048. if (!index) {
  3049. this.vDomTopPad = 0;
  3050. }
  3051. table.style.paddingTop = this.vDomTopPad + "px";
  3052. this.vDomScrollPosTop -= topRowHeight;
  3053. this.vDomTop--;
  3054. }
  3055. topDiff = -(this.scrollTop - this.vDomScrollPosTop);
  3056. if (topRow.getHeight() > this.vDomWindowBuffer) {
  3057. this.vDomWindowBuffer = topRow.getHeight() * 2;
  3058. }
  3059. if (i < this.vDomMaxRenderChain && this.vDomTop && topDiff >= (rows[this.vDomTop - 1].getHeight() || this.vDomRowHeight)) {
  3060. this._addTopRow(topDiff, i + 1);
  3061. } else {
  3062. this._quickNormalizeRowHeight(this.vDomTopNewRows);
  3063. }
  3064. }
  3065. };
  3066. RowManager.prototype._removeTopRow = function (topDiff) {
  3067. var table = this.tableElement,
  3068. topRow = this.getDisplayRows()[this.vDomTop],
  3069. topRowHeight = topRow.getHeight() || this.vDomRowHeight;
  3070. if (topDiff >= topRowHeight) {
  3071. var rowEl = topRow.getElement();
  3072. rowEl.parentNode.removeChild(rowEl);
  3073. this.vDomTopPad += topRowHeight;
  3074. table.style.paddingTop = this.vDomTopPad + "px";
  3075. this.vDomScrollPosTop += this.vDomTop ? topRowHeight : topRowHeight + this.vDomWindowBuffer;
  3076. this.vDomTop++;
  3077. topDiff = this.scrollTop - this.vDomScrollPosTop;
  3078. this._removeTopRow(topDiff);
  3079. }
  3080. };
  3081. RowManager.prototype._addBottomRow = function (bottomDiff) {
  3082. var i = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  3083. var table = this.tableElement,
  3084. rows = this.getDisplayRows();
  3085. if (this.vDomBottom < this.displayRowsCount - 1) {
  3086. var index = this.vDomBottom + 1,
  3087. bottomRow = rows[index],
  3088. bottomRowHeight = bottomRow.getHeight() || this.vDomRowHeight;
  3089. //hide bottom row if needed
  3090. if (bottomDiff >= bottomRowHeight) {
  3091. this.styleRow(bottomRow, index);
  3092. table.appendChild(bottomRow.getElement());
  3093. if (!bottomRow.initialized || !bottomRow.heightInitialized) {
  3094. this.vDomBottomNewRows.push(bottomRow);
  3095. if (!bottomRow.heightInitialized) {
  3096. bottomRow.clearCellHeight();
  3097. }
  3098. }
  3099. bottomRow.initialize();
  3100. this.vDomBottomPad -= bottomRowHeight;
  3101. if (this.vDomBottomPad < 0 || index == this.displayRowsCount - 1) {
  3102. this.vDomBottomPad = 0;
  3103. }
  3104. table.style.paddingBottom = this.vDomBottomPad + "px";
  3105. this.vDomScrollPosBottom += bottomRowHeight;
  3106. this.vDomBottom++;
  3107. }
  3108. bottomDiff = this.scrollTop - this.vDomScrollPosBottom;
  3109. if (bottomRow.getHeight() > this.vDomWindowBuffer) {
  3110. this.vDomWindowBuffer = bottomRow.getHeight() * 2;
  3111. }
  3112. if (i < this.vDomMaxRenderChain && this.vDomBottom < this.displayRowsCount - 1 && bottomDiff >= (rows[this.vDomBottom + 1].getHeight() || this.vDomRowHeight)) {
  3113. this._addBottomRow(bottomDiff, i + 1);
  3114. } else {
  3115. this._quickNormalizeRowHeight(this.vDomBottomNewRows);
  3116. }
  3117. }
  3118. };
  3119. RowManager.prototype._removeBottomRow = function (bottomDiff) {
  3120. var table = this.tableElement,
  3121. bottomRow = this.getDisplayRows()[this.vDomBottom],
  3122. bottomRowHeight = bottomRow.getHeight() || this.vDomRowHeight;
  3123. if (bottomDiff >= bottomRowHeight) {
  3124. var rowEl = bottomRow.getElement();
  3125. if (rowEl.parentNode) {
  3126. rowEl.parentNode.removeChild(rowEl);
  3127. }
  3128. this.vDomBottomPad += bottomRowHeight;
  3129. if (this.vDomBottomPad < 0) {
  3130. this.vDomBottomPad = 0;
  3131. }
  3132. table.style.paddingBottom = this.vDomBottomPad + "px";
  3133. this.vDomScrollPosBottom -= bottomRowHeight;
  3134. this.vDomBottom--;
  3135. bottomDiff = -(this.scrollTop - this.vDomScrollPosBottom);
  3136. this._removeBottomRow(bottomDiff);
  3137. }
  3138. };
  3139. RowManager.prototype._quickNormalizeRowHeight = function (rows) {
  3140. rows.forEach(function (row) {
  3141. row.calcHeight();
  3142. });
  3143. rows.forEach(function (row) {
  3144. row.setCellHeight();
  3145. });
  3146. rows.length = 0;
  3147. };
  3148. //normalize height of active rows
  3149. RowManager.prototype.normalizeHeight = function () {
  3150. this.activeRows.forEach(function (row) {
  3151. row.normalizeHeight();
  3152. });
  3153. };
  3154. //adjust the height of the table holder to fit in the Tabulator element
  3155. RowManager.prototype.adjustTableSize = function () {
  3156. var initialHeight = this.element.clientHeight,
  3157. modExists;
  3158. if (this.renderMode === "virtual") {
  3159. var otherHeight = Math.floor(this.columnManager.getElement().offsetHeight + (this.table.footerManager && !this.table.footerManager.external ? this.table.footerManager.getElement().offsetHeight : 0));
  3160. if (this.fixedHeight) {
  3161. this.element.style.minHeight = "calc(100% - " + otherHeight + "px)";
  3162. this.element.style.height = "calc(100% - " + otherHeight + "px)";
  3163. this.element.style.maxHeight = "calc(100% - " + otherHeight + "px)";
  3164. } else {
  3165. this.element.style.height = "";
  3166. this.element.style.height = Math.floor(this.table.element.clientHeight) - otherHeight + "px";
  3167. this.element.scrollTop = this.scrollTop;
  3168. }
  3169. this.height = this.element.clientHeight;
  3170. this.vDomWindowBuffer = this.table.options.virtualDomBuffer || this.height;
  3171. //check if the table has changed size when dealing with variable height tables
  3172. if (!this.fixedHeight && Math.floor(initialHeight) != Math.floor(this.element.clientHeight)) {
  3173. modExists = this.table.modExists("resizeTable");
  3174. if (modExists && !this.table.modules.resizeTable.autoResize || !modExists) {
  3175. this.redraw();
  3176. }
  3177. }
  3178. }
  3179. };
  3180. //renitialize all rows
  3181. RowManager.prototype.reinitialize = function () {
  3182. this.rows.forEach(function (row) {
  3183. row.reinitialize(true);
  3184. });
  3185. };
  3186. //prevent table from being redrawn
  3187. RowManager.prototype.blockRedraw = function () {
  3188. this.redrawBlock = true;
  3189. this.redrawBlockRestoreConfig = false;
  3190. };
  3191. //restore table redrawing
  3192. RowManager.prototype.restoreRedraw = function () {
  3193. this.redrawBlock = false;
  3194. if (this.redrawBlockRestoreConfig) {
  3195. this.refreshActiveData(this.redrawBlockRestoreConfig.stage, this.redrawBlockRestoreConfig.skipStage, this.redrawBlockRestoreConfig.renderInPosition);
  3196. this.redrawBlockRestoreConfig = false;
  3197. } else {
  3198. if (this.redrawBlockRederInPosition) {
  3199. this.reRenderInPosition();
  3200. }
  3201. }
  3202. this.redrawBlockRederInPosition = false;
  3203. };
  3204. //redraw table
  3205. RowManager.prototype.redraw = function (force) {
  3206. var pos = 0,
  3207. left = this.scrollLeft;
  3208. this.adjustTableSize();
  3209. this.table.tableWidth = this.table.element.clientWidth;
  3210. if (!force) {
  3211. if (this.renderMode == "classic") {
  3212. if (this.table.options.groupBy) {
  3213. this.refreshActiveData("group", false, false);
  3214. } else {
  3215. this._simpleRender();
  3216. }
  3217. } else {
  3218. this.reRenderInPosition();
  3219. this.scrollHorizontal(left);
  3220. }
  3221. if (!this.displayRowsCount) {
  3222. if (this.table.options.placeholder) {
  3223. this.getElement().appendChild(this.table.options.placeholder);
  3224. }
  3225. }
  3226. } else {
  3227. this.renderTable();
  3228. }
  3229. };
  3230. RowManager.prototype.resetScroll = function () {
  3231. this.element.scrollLeft = 0;
  3232. this.element.scrollTop = 0;
  3233. if (this.table.browser === "ie") {
  3234. var event = document.createEvent("Event");
  3235. event.initEvent("scroll", false, true);
  3236. this.element.dispatchEvent(event);
  3237. } else {
  3238. this.element.dispatchEvent(new Event('scroll'));
  3239. }
  3240. };
  3241. var VDomHoz = function VDomHoz(table) {
  3242. this.table = table;
  3243. this.element = this.table.rowManager.tableElement;
  3244. this.holderEl = this.table.rowManager.element;
  3245. this.leftCol = 0;
  3246. this.rightCol = 0;
  3247. this.scrollLeft = 0;
  3248. this.vDomScrollPosLeft = 0;
  3249. this.vDomScrollPosRight = 0;
  3250. this.vDomPadLeft = 0;
  3251. this.vDomPadRight = 0;
  3252. this.fitDataColAvg = 0;
  3253. this.window = 200; //pixel margin to make column visible before it is shown on screen
  3254. this.initialized = false;
  3255. this.columns = [];
  3256. if (this.compatabilityCheck()) {
  3257. this.initialize();
  3258. }
  3259. };
  3260. VDomHoz.prototype.compatabilityCheck = function () {
  3261. var options = this.table.options,
  3262. frozen = false,
  3263. ok = true;
  3264. if (options.layout == "fitDataTable") {
  3265. console.warn("Horizontal Vitrual DOM is not compatible with fitDataTable layout mode");
  3266. ok = false;
  3267. }
  3268. if (options.responsiveLayout) {
  3269. console.warn("Horizontal Vitrual DOM is not compatible with responsive columns");
  3270. ok = false;
  3271. }
  3272. if (this.table.rtl) {
  3273. console.warn("Horizontal Vitrual DOM is not currently compatible with RTL text direction");
  3274. ok = false;
  3275. }
  3276. // if(options.rowFormatter){
  3277. // console.warn("Horizontal Vitrual DOM is not compatible with row formatters");
  3278. // ok = false;
  3279. // }
  3280. if (options.columns) {
  3281. frozen = options.columns.find(function (col) {
  3282. return col.frozen;
  3283. });
  3284. if (frozen) {
  3285. console.warn("Horizontal Vitrual DOM is not compatible with frozen columns");
  3286. ok = false;
  3287. }
  3288. }
  3289. if (!ok) {
  3290. options.virtualDomHoz = false;
  3291. }
  3292. return ok;
  3293. };
  3294. VDomHoz.prototype.initialize = function () {
  3295. var _this17 = this;
  3296. this.holderEl.addEventListener("scroll", function () {
  3297. var left = _this17.holderEl.scrollLeft;
  3298. if (_this17.scrollLeft != left) {
  3299. _this17.scrollLeft = left;
  3300. _this17.scroll(left - (_this17.vDomScrollPosLeft + _this17.window));
  3301. }
  3302. });
  3303. };
  3304. VDomHoz.prototype.deinitialize = function () {
  3305. this.initialized = false;
  3306. };
  3307. VDomHoz.prototype.clear = function () {
  3308. this.columns = [];
  3309. this.leftCol = -1;
  3310. this.rightCol = 0;
  3311. this.vDomScrollPosLeft = 0;
  3312. this.vDomScrollPosRight = 0;
  3313. this.vDomPadLeft = 0;
  3314. this.vDomPadRight = 0;
  3315. };
  3316. VDomHoz.prototype.dataChange = function () {
  3317. var change = false,
  3318. collsWidth = 0,
  3319. colEnd = 0,
  3320. group,
  3321. row,
  3322. rowEl;
  3323. if (this.table.options.layout === "fitData") {
  3324. this.table.columnManager.columnsByIndex.forEach(function (column) {
  3325. if (!column.definition.width && column.visible) {
  3326. change = true;
  3327. }
  3328. });
  3329. if (change) {
  3330. if (change && this.table.rowManager.getDisplayRows().length) {
  3331. // this.table.vdomHoz.deinitialize();
  3332. this.vDomScrollPosRight = this.scrollLeft + this.holderEl.clientWidth + this.window;
  3333. if (this.table.options.groupBy) {
  3334. group = this.table.modules.groupRows.getGroups(false)[0];
  3335. row = group.getRows(false)[0];
  3336. } else {
  3337. row = this.table.rowManager.getDisplayRows()[0];
  3338. }
  3339. if (row) {
  3340. rowEl = row.getElement();
  3341. row.generateCells();
  3342. this.element.appendChild(rowEl);
  3343. for (var colEnd = 0; colEnd < row.cells.length; colEnd++) {
  3344. var cell = row.cells[colEnd];
  3345. rowEl.appendChild(cell.getElement());
  3346. cell.column.reinitializeWidth();
  3347. collsWidth += cell.column.getWidth();
  3348. if (collsWidth > this.vDomScrollPosRight) {
  3349. break;
  3350. }
  3351. }
  3352. rowEl.parentNode.removeChild(rowEl);
  3353. this.fitDataColAvg = Math.floor(collsWidth / (colEnd + 1));
  3354. for (colEnd; colEnd < this.table.columnManager.columnsByIndex.length; colEnd++) {
  3355. this.table.columnManager.columnsByIndex[colEnd].setWidth(this.fitDataColAvg);
  3356. }
  3357. this.reinitialize(false, true);
  3358. }
  3359. }
  3360. }
  3361. } else {
  3362. if (this.table.options.layout === "fitColumns") {
  3363. this.table.modules.layout.layout();
  3364. this.table.vdomHoz.reinitialize(false, true);
  3365. }
  3366. }
  3367. };
  3368. VDomHoz.prototype.fitDataLayoutOverride = function () {
  3369. for (var _i5 = this.leftCol; _i5 <= this.rightCol; _i5++) {
  3370. this.columns[_i5].reinitializeWidth();
  3371. }
  3372. };
  3373. VDomHoz.prototype.reinitialize = function (update, blockRedraw) {
  3374. var _this18 = this;
  3375. var old = {
  3376. cols: this.columns,
  3377. leftCol: this.leftCol,
  3378. rightCol: this.rightCol
  3379. };
  3380. if (update && !this.initialized) {
  3381. return;
  3382. }
  3383. this.clear();
  3384. this.scrollLeft = this.holderEl.scrollLeft;
  3385. this.vDomScrollPosLeft = this.scrollLeft - this.window;
  3386. this.vDomScrollPosRight = this.scrollLeft + this.holderEl.clientWidth + this.window;
  3387. var colPos = 0;
  3388. this.table.columnManager.columnsByIndex.forEach(function (column) {
  3389. var config = {};
  3390. if (column.visible) {
  3391. var width = column.getWidth();
  3392. config.leftPos = colPos;
  3393. config.rightPos = colPos + width;
  3394. if (colPos + width > _this18.vDomScrollPosLeft && colPos < _this18.vDomScrollPosRight) {
  3395. //column is visible
  3396. if (_this18.leftCol == -1) {
  3397. _this18.leftCol = _this18.columns.length;
  3398. _this18.vDomPadLeft = colPos;
  3399. }
  3400. _this18.rightCol = _this18.columns.length;
  3401. } else {
  3402. // column is hidden
  3403. if (_this18.leftCol !== -1) {
  3404. _this18.vDomPadRight += width;
  3405. }
  3406. }
  3407. _this18.columns.push(column);
  3408. column.modules.vdomHoz = config;
  3409. colPos += width;
  3410. }
  3411. });
  3412. this.element.style.paddingLeft = this.vDomPadLeft + "px";
  3413. this.element.style.paddingRight = this.vDomPadRight + "px";
  3414. this.initialized = true;
  3415. if (!blockRedraw) {
  3416. if (!update || this.reinitChanged(old)) {
  3417. this.renitializeRows();
  3418. }
  3419. }
  3420. this.holderEl.scrollLeft = this.scrollLeft;
  3421. };
  3422. VDomHoz.prototype.reinitChanged = function (old) {
  3423. var _this19 = this;
  3424. var match = true;
  3425. if (old.cols.length !== this.columns.length || old.leftCol !== this.leftCol || old.rightCol !== this.rightCol) {
  3426. return true;
  3427. }
  3428. old.cols.forEach(function (col, i) {
  3429. if (col !== _this19.columns[i]) {
  3430. match = false;
  3431. }
  3432. });
  3433. return !match;
  3434. };
  3435. VDomHoz.prototype.renitializeRows = function () {
  3436. var _this20 = this;
  3437. var rows = this.table.rowManager.getVisibleRows();
  3438. rows.forEach(function (row) {
  3439. _this20.reinitializeRow(row, true);
  3440. });
  3441. };
  3442. VDomHoz.prototype.scroll = function (diff) {
  3443. this.vDomScrollPosLeft += diff;
  3444. this.vDomScrollPosRight += diff;
  3445. if (diff > this.holderEl.clientWidth * .8) {
  3446. this.reinitialize();
  3447. } else {
  3448. if (diff > 0) {
  3449. //scroll right
  3450. this.addColRight();
  3451. this.removeColLeft();
  3452. } else {
  3453. //scroll left
  3454. this.addColLeft();
  3455. this.removeColRight();
  3456. }
  3457. }
  3458. };
  3459. VDomHoz.prototype.colPositionAdjust = function (start, end, diff) {
  3460. for (var _i6 = start; _i6 < end; _i6++) {
  3461. var column = this.columns[_i6];
  3462. column.modules.vdomHoz.leftPos -= diff;
  3463. column.modules.vdomHoz.rightPos -= diff;
  3464. }
  3465. };
  3466. VDomHoz.prototype.addColRight = function () {
  3467. var column = this.columns[this.rightCol + 1],
  3468. rows,
  3469. oldWidth,
  3470. widthDiff;
  3471. if (column && column.modules.vdomHoz.leftPos <= this.vDomScrollPosRight) {
  3472. rows = this.table.rowManager.getVisibleRows();
  3473. rows.forEach(function (row) {
  3474. if (row.type !== "group") {
  3475. var cell = row.getCell(column);
  3476. row.getElement().appendChild(cell.getElement());
  3477. cell.cellRendered();
  3478. }
  3479. });
  3480. if (this.fitDataColAvg) {
  3481. oldWidth = column.getWidth();
  3482. if (oldWidth === this.fitDataColAvg) {
  3483. column.reinitializeWidth();
  3484. widthDiff = oldWidth - column.getWidth();
  3485. if (widthDiff) {
  3486. column.modules.vdomHoz.rightPos -= widthDiff;
  3487. this.colPositionAdjust(this.rightCol + 1, this.columns.length, widthDiff);
  3488. }
  3489. }
  3490. }
  3491. this.rightCol++;
  3492. if (this.rightCol >= this.columns.length - 1) {
  3493. this.vDomPadRight = 0;
  3494. } else {
  3495. this.vDomPadRight -= column.getWidth();
  3496. }
  3497. this.element.style.paddingRight = this.vDomPadRight + "px";
  3498. this.addColRight();
  3499. }
  3500. };
  3501. VDomHoz.prototype.addColLeft = function () {
  3502. var column = this.columns[this.leftCol - 1],
  3503. rows;
  3504. if (column && column.modules.vdomHoz.rightPos >= this.vDomScrollPosLeft) {
  3505. var rows = this.table.rowManager.getVisibleRows();
  3506. rows.forEach(function (row) {
  3507. if (row.type !== "group") {
  3508. var cell = row.getCell(column);
  3509. row.getElement().prepend(cell.getElement());
  3510. cell.cellRendered();
  3511. }
  3512. });
  3513. if (!this.leftCol) {
  3514. this.vDomPadLeft = 0;
  3515. } else {
  3516. this.vDomPadLeft -= column.getWidth();
  3517. }
  3518. this.element.style.paddingLeft = this.vDomPadLeft + "px";
  3519. this.leftCol--;
  3520. this.addColLeft();
  3521. }
  3522. };
  3523. VDomHoz.prototype.removeColRight = function (column) {
  3524. var column = this.columns[this.rightCol],
  3525. rows;
  3526. if (column && column.modules.vdomHoz.leftPos > this.vDomScrollPosRight) {
  3527. rows = this.table.rowManager.getVisibleRows();
  3528. column.modules.vdomHoz.visible = false;
  3529. rows.forEach(function (row) {
  3530. if (row.type !== "group") {
  3531. var cell = row.getCell(column);
  3532. row.getElement().removeChild(cell.getElement());
  3533. }
  3534. });
  3535. this.vDomPadRight += column.getWidth();
  3536. this.element.style.paddingRight = this.vDomPadRight + "px";
  3537. this.rightCol--;
  3538. this.removeColRight();
  3539. }
  3540. };
  3541. VDomHoz.prototype.removeColLeft = function () {
  3542. var column = this.columns[this.leftCol],
  3543. rows;
  3544. if (column && column.modules.vdomHoz.rightPos < this.vDomScrollPosLeft) {
  3545. rows = this.table.rowManager.getVisibleRows();
  3546. rows.forEach(function (row) {
  3547. if (row.type !== "group") {
  3548. var cell = row.getCell(column);
  3549. row.getElement().removeChild(cell.getElement());
  3550. }
  3551. });
  3552. this.vDomPadLeft += column.getWidth();
  3553. this.element.style.paddingLeft = this.vDomPadLeft + "px";
  3554. this.leftCol++;
  3555. this.removeColLeft();
  3556. }
  3557. };
  3558. VDomHoz.prototype.initializeRow = function (row) {
  3559. if (row.type !== "group") {
  3560. row.modules.vdomHoz = {
  3561. leftCol: this.leftCol,
  3562. rightCol: this.rightCol
  3563. };
  3564. for (var _i7 = this.leftCol; _i7 <= this.rightCol; _i7++) {
  3565. var column = this.columns[_i7];
  3566. if (column.visible) {
  3567. var cell = row.getCell(column);
  3568. row.element.appendChild(cell.getElement());
  3569. cell.cellRendered();
  3570. }
  3571. }
  3572. }
  3573. };
  3574. VDomHoz.prototype.reinitializeRow = function (row, force) {
  3575. if (row.type !== "group") {
  3576. if (force || !row.modules.vdomHoz || row.modules.vdomHoz.leftCol !== this.leftCol || row.modules.vdomHoz.rightCol !== this.rightCol) {
  3577. while (row.element.firstChild) {
  3578. row.element.removeChild(row.element.firstChild);
  3579. }this.initializeRow(row);
  3580. }
  3581. }
  3582. };
  3583. //public row object
  3584. var RowComponent = function RowComponent(row) {
  3585. this._row = row;
  3586. };
  3587. RowComponent.prototype.getData = function (transform) {
  3588. return this._row.getData(transform);
  3589. };
  3590. RowComponent.prototype.getElement = function () {
  3591. return this._row.getElement();
  3592. };
  3593. RowComponent.prototype.getCells = function () {
  3594. var cells = [];
  3595. this._row.getCells().forEach(function (cell) {
  3596. cells.push(cell.getComponent());
  3597. });
  3598. return cells;
  3599. };
  3600. RowComponent.prototype.getCell = function (column) {
  3601. var cell = this._row.getCell(column);
  3602. return cell ? cell.getComponent() : false;
  3603. };
  3604. RowComponent.prototype.getIndex = function () {
  3605. return this._row.getData("data")[this._row.table.options.index];
  3606. };
  3607. RowComponent.prototype.getPosition = function (active) {
  3608. return this._row.table.rowManager.getRowPosition(this._row, active);
  3609. };
  3610. RowComponent.prototype.delete = function () {
  3611. return this._row.delete();
  3612. };
  3613. RowComponent.prototype.scrollTo = function () {
  3614. return this._row.table.rowManager.scrollToRow(this._row);
  3615. };
  3616. RowComponent.prototype.pageTo = function () {
  3617. if (this._row.table.modExists("page", true)) {
  3618. return this._row.table.modules.page.setPageToRow(this._row);
  3619. }
  3620. };
  3621. RowComponent.prototype.move = function (to, after) {
  3622. this._row.moveToRow(to, after);
  3623. };
  3624. RowComponent.prototype.update = function (data) {
  3625. return this._row.updateData(data);
  3626. };
  3627. RowComponent.prototype.normalizeHeight = function () {
  3628. this._row.normalizeHeight(true);
  3629. };
  3630. RowComponent.prototype.select = function () {
  3631. this._row.table.modules.selectRow.selectRows(this._row);
  3632. };
  3633. RowComponent.prototype.deselect = function () {
  3634. this._row.table.modules.selectRow.deselectRows(this._row);
  3635. };
  3636. RowComponent.prototype.toggleSelect = function () {
  3637. this._row.table.modules.selectRow.toggleRow(this._row);
  3638. };
  3639. RowComponent.prototype.isSelected = function () {
  3640. return this._row.table.modules.selectRow.isRowSelected(this._row);
  3641. };
  3642. RowComponent.prototype._getSelf = function () {
  3643. return this._row;
  3644. };
  3645. RowComponent.prototype.validate = function () {
  3646. return this._row.validate();
  3647. };
  3648. RowComponent.prototype.freeze = function () {
  3649. if (this._row.table.modExists("frozenRows", true)) {
  3650. this._row.table.modules.frozenRows.freezeRow(this._row);
  3651. }
  3652. };
  3653. RowComponent.prototype.unfreeze = function () {
  3654. if (this._row.table.modExists("frozenRows", true)) {
  3655. this._row.table.modules.frozenRows.unfreezeRow(this._row);
  3656. }
  3657. };
  3658. RowComponent.prototype.isFrozen = function () {
  3659. if (this._row.table.modExists("frozenRows", true)) {
  3660. var index = this._row.table.modules.frozenRows.rows.indexOf(this._row);
  3661. return index > -1;
  3662. }
  3663. return false;
  3664. };
  3665. RowComponent.prototype.treeCollapse = function () {
  3666. if (this._row.table.modExists("dataTree", true)) {
  3667. this._row.table.modules.dataTree.collapseRow(this._row);
  3668. }
  3669. };
  3670. RowComponent.prototype.treeExpand = function () {
  3671. if (this._row.table.modExists("dataTree", true)) {
  3672. this._row.table.modules.dataTree.expandRow(this._row);
  3673. }
  3674. };
  3675. RowComponent.prototype.treeToggle = function () {
  3676. if (this._row.table.modExists("dataTree", true)) {
  3677. this._row.table.modules.dataTree.toggleRow(this._row);
  3678. }
  3679. };
  3680. RowComponent.prototype.getTreeParent = function () {
  3681. if (this._row.table.modExists("dataTree", true)) {
  3682. return this._row.table.modules.dataTree.getTreeParent(this._row);
  3683. }
  3684. return false;
  3685. };
  3686. RowComponent.prototype.getTreeChildren = function () {
  3687. if (this._row.table.modExists("dataTree", true)) {
  3688. return this._row.table.modules.dataTree.getTreeChildren(this._row, true);
  3689. }
  3690. return false;
  3691. };
  3692. RowComponent.prototype.addTreeChild = function (data, pos, index) {
  3693. if (this._row.table.modExists("dataTree", true)) {
  3694. return this._row.table.modules.dataTree.addTreeChildRow(this._row, data, pos, index);
  3695. }
  3696. return false;
  3697. };
  3698. RowComponent.prototype.reformat = function () {
  3699. return this._row.reinitialize();
  3700. };
  3701. RowComponent.prototype.getGroup = function () {
  3702. return this._row.getGroup().getComponent();
  3703. };
  3704. RowComponent.prototype.getTable = function () {
  3705. return this._row.table;
  3706. };
  3707. RowComponent.prototype.getNextRow = function () {
  3708. var row = this._row.nextRow();
  3709. return row ? row.getComponent() : row;
  3710. };
  3711. RowComponent.prototype.getPrevRow = function () {
  3712. var row = this._row.prevRow();
  3713. return row ? row.getComponent() : row;
  3714. };
  3715. var Row = function Row(data, parent) {
  3716. var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "row";
  3717. this.table = parent.table;
  3718. this.parent = parent;
  3719. this.data = {};
  3720. this.type = type; //type of element
  3721. this.element = this.createElement();
  3722. this.modules = {}; //hold module variables;
  3723. this.cells = [];
  3724. this.height = 0; //hold element height
  3725. this.heightStyled = ""; //hold element height prestyled to improve render efficiency
  3726. this.manualHeight = false; //user has manually set row height
  3727. this.outerHeight = 0; //holde lements outer height
  3728. this.initialized = false; //element has been rendered
  3729. this.heightInitialized = false; //element has resized cells to fit
  3730. this.component = null;
  3731. this.setData(data);
  3732. this.generateElement();
  3733. };
  3734. Row.prototype.createElement = function () {
  3735. var el = document.createElement("div");
  3736. el.classList.add("tabulator-row");
  3737. el.setAttribute("role", "row");
  3738. return el;
  3739. };
  3740. Row.prototype.getElement = function () {
  3741. return this.element;
  3742. };
  3743. Row.prototype.detachElement = function () {
  3744. if (this.element && this.element.parentNode) {
  3745. this.element.parentNode.removeChild(this.element);
  3746. }
  3747. };
  3748. Row.prototype.generateElement = function () {
  3749. var self = this,
  3750. dblTap,
  3751. tapHold,
  3752. tap;
  3753. //set row selection characteristics
  3754. if (self.table.options.selectable !== false && self.table.modExists("selectRow")) {
  3755. self.table.modules.selectRow.initializeRow(this);
  3756. }
  3757. //setup movable rows
  3758. if (self.table.options.movableRows !== false && self.table.modExists("moveRow")) {
  3759. self.table.modules.moveRow.initializeRow(this);
  3760. }
  3761. //setup data tree
  3762. if (self.table.options.dataTree !== false && self.table.modExists("dataTree")) {
  3763. self.table.modules.dataTree.initializeRow(this);
  3764. }
  3765. //setup column colapse container
  3766. if (self.table.options.responsiveLayout === "collapse" && self.table.modExists("responsiveLayout")) {
  3767. self.table.modules.responsiveLayout.initializeRow(this);
  3768. }
  3769. //set column menu
  3770. if ((self.table.options.rowContextMenu || self.table.options.rowClickMenu) && this.table.modExists("menu")) {
  3771. self.table.modules.menu.initializeRow(this);
  3772. }
  3773. //handle row click events
  3774. if (self.table.options.rowClick) {
  3775. self.element.addEventListener("click", function (e) {
  3776. self.table.options.rowClick(e, self.getComponent());
  3777. });
  3778. }
  3779. if (self.table.options.rowDblClick) {
  3780. self.element.addEventListener("dblclick", function (e) {
  3781. self.table.options.rowDblClick(e, self.getComponent());
  3782. });
  3783. }
  3784. if (self.table.options.rowContext) {
  3785. self.element.addEventListener("contextmenu", function (e) {
  3786. self.table.options.rowContext(e, self.getComponent());
  3787. });
  3788. }
  3789. //handle mouse events
  3790. if (self.table.options.rowMouseEnter) {
  3791. self.element.addEventListener("mouseenter", function (e) {
  3792. self.table.options.rowMouseEnter(e, self.getComponent());
  3793. });
  3794. }
  3795. if (self.table.options.rowMouseLeave) {
  3796. self.element.addEventListener("mouseleave", function (e) {
  3797. self.table.options.rowMouseLeave(e, self.getComponent());
  3798. });
  3799. }
  3800. if (self.table.options.rowMouseOver) {
  3801. self.element.addEventListener("mouseover", function (e) {
  3802. self.table.options.rowMouseOver(e, self.getComponent());
  3803. });
  3804. }
  3805. if (self.table.options.rowMouseOut) {
  3806. self.element.addEventListener("mouseout", function (e) {
  3807. self.table.options.rowMouseOut(e, self.getComponent());
  3808. });
  3809. }
  3810. if (self.table.options.rowMouseMove) {
  3811. self.element.addEventListener("mousemove", function (e) {
  3812. self.table.options.rowMouseMove(e, self.getComponent());
  3813. });
  3814. }
  3815. if (self.table.options.rowTap) {
  3816. tap = false;
  3817. self.element.addEventListener("touchstart", function (e) {
  3818. tap = true;
  3819. }, { passive: true });
  3820. self.element.addEventListener("touchend", function (e) {
  3821. if (tap) {
  3822. self.table.options.rowTap(e, self.getComponent());
  3823. }
  3824. tap = false;
  3825. });
  3826. }
  3827. if (self.table.options.rowDblTap) {
  3828. dblTap = null;
  3829. self.element.addEventListener("touchend", function (e) {
  3830. if (dblTap) {
  3831. clearTimeout(dblTap);
  3832. dblTap = null;
  3833. self.table.options.rowDblTap(e, self.getComponent());
  3834. } else {
  3835. dblTap = setTimeout(function () {
  3836. clearTimeout(dblTap);
  3837. dblTap = null;
  3838. }, 300);
  3839. }
  3840. });
  3841. }
  3842. if (self.table.options.rowTapHold) {
  3843. tapHold = null;
  3844. self.element.addEventListener("touchstart", function (e) {
  3845. clearTimeout(tapHold);
  3846. tapHold = setTimeout(function () {
  3847. clearTimeout(tapHold);
  3848. tapHold = null;
  3849. tap = false;
  3850. self.table.options.rowTapHold(e, self.getComponent());
  3851. }, 1000);
  3852. }, { passive: true });
  3853. self.element.addEventListener("touchend", function (e) {
  3854. clearTimeout(tapHold);
  3855. tapHold = null;
  3856. });
  3857. }
  3858. };
  3859. Row.prototype.generateCells = function () {
  3860. this.cells = this.table.columnManager.generateCells(this);
  3861. };
  3862. //functions to setup on first render
  3863. Row.prototype.initialize = function (force) {
  3864. var _this21 = this;
  3865. if (!this.initialized || force) {
  3866. this.deleteCells();
  3867. while (this.element.firstChild) {
  3868. this.element.removeChild(this.element.firstChild);
  3869. } //handle frozen cells
  3870. if (this.table.modExists("frozenColumns")) {
  3871. this.table.modules.frozenColumns.layoutRow(this);
  3872. }
  3873. this.generateCells();
  3874. if (this.table.options.virtualDomHoz && this.table.vdomHoz.initialized) {
  3875. this.table.vdomHoz.initializeRow(this);
  3876. } else {
  3877. this.cells.forEach(function (cell) {
  3878. _this21.element.appendChild(cell.getElement());
  3879. cell.cellRendered();
  3880. });
  3881. }
  3882. if (force) {
  3883. this.normalizeHeight();
  3884. }
  3885. //setup movable rows
  3886. if (this.table.options.dataTree && this.table.modExists("dataTree")) {
  3887. this.table.modules.dataTree.layoutRow(this);
  3888. }
  3889. //setup column colapse container
  3890. if (this.table.options.responsiveLayout === "collapse" && this.table.modExists("responsiveLayout")) {
  3891. this.table.modules.responsiveLayout.layoutRow(this);
  3892. }
  3893. if (this.table.options.rowFormatter) {
  3894. this.table.options.rowFormatter(this.getComponent());
  3895. }
  3896. //set resizable handles
  3897. if (this.table.options.resizableRows && this.table.modExists("resizeRows")) {
  3898. this.table.modules.resizeRows.initializeRow(this);
  3899. }
  3900. this.initialized = true;
  3901. } else {
  3902. if (this.table.options.virtualDomHoz) {
  3903. this.table.vdomHoz.reinitializeRow(this);
  3904. }
  3905. }
  3906. };
  3907. Row.prototype.reinitializeHeight = function () {
  3908. this.heightInitialized = false;
  3909. if (this.element.offsetParent !== null) {
  3910. this.normalizeHeight(true);
  3911. }
  3912. };
  3913. Row.prototype.reinitialize = function (children) {
  3914. this.initialized = false;
  3915. this.heightInitialized = false;
  3916. if (!this.manualHeight) {
  3917. this.height = 0;
  3918. this.heightStyled = "";
  3919. }
  3920. if (this.element.offsetParent !== null) {
  3921. this.initialize(true);
  3922. }
  3923. if (this.table.options.dataTree && this.table.modExists("dataTree", true)) {
  3924. this.table.modules.dataTree.getTreeChildren(this, false, true).forEach(function (child) {
  3925. child.reinitialize(true);
  3926. });
  3927. }
  3928. };
  3929. //get heights when doing bulk row style calcs in virtual DOM
  3930. Row.prototype.calcHeight = function (force) {
  3931. var maxHeight = 0,
  3932. minHeight = this.table.options.resizableRows ? this.element.clientHeight : 0;
  3933. this.cells.forEach(function (cell) {
  3934. var height = cell.getHeight();
  3935. if (height > maxHeight) {
  3936. maxHeight = height;
  3937. }
  3938. });
  3939. if (force) {
  3940. this.height = Math.max(maxHeight, minHeight);
  3941. } else {
  3942. this.height = this.manualHeight ? this.height : Math.max(maxHeight, minHeight);
  3943. }
  3944. this.heightStyled = this.height ? this.height + "px" : "";
  3945. this.outerHeight = this.element.offsetHeight;
  3946. };
  3947. //set of cells
  3948. Row.prototype.setCellHeight = function () {
  3949. this.cells.forEach(function (cell) {
  3950. cell.setHeight();
  3951. });
  3952. this.heightInitialized = true;
  3953. };
  3954. Row.prototype.clearCellHeight = function () {
  3955. this.cells.forEach(function (cell) {
  3956. cell.clearHeight();
  3957. });
  3958. };
  3959. //normalize the height of elements in the row
  3960. Row.prototype.normalizeHeight = function (force) {
  3961. if (force) {
  3962. this.clearCellHeight();
  3963. }
  3964. this.calcHeight(force);
  3965. this.setCellHeight();
  3966. };
  3967. // Row.prototype.setHeight = function(height){
  3968. // this.height = height;
  3969. // this.setCellHeight();
  3970. // };
  3971. //set height of rows
  3972. Row.prototype.setHeight = function (height, force) {
  3973. if (this.height != height || force) {
  3974. this.manualHeight = true;
  3975. this.height = height;
  3976. this.heightStyled = height ? height + "px" : "";
  3977. this.setCellHeight();
  3978. // this.outerHeight = this.element.outerHeight();
  3979. this.outerHeight = this.element.offsetHeight;
  3980. }
  3981. };
  3982. //return rows outer height
  3983. Row.prototype.getHeight = function () {
  3984. return this.outerHeight;
  3985. };
  3986. //return rows outer Width
  3987. Row.prototype.getWidth = function () {
  3988. return this.element.offsetWidth;
  3989. };
  3990. //////////////// Cell Management /////////////////
  3991. Row.prototype.deleteCell = function (cell) {
  3992. var index = this.cells.indexOf(cell);
  3993. if (index > -1) {
  3994. this.cells.splice(index, 1);
  3995. }
  3996. };
  3997. //////////////// Data Management /////////////////
  3998. Row.prototype.setData = function (data) {
  3999. if (this.table.modExists("mutator")) {
  4000. data = this.table.modules.mutator.transformRow(data, "data");
  4001. }
  4002. this.data = data;
  4003. if (this.table.options.reactiveData && this.table.modExists("reactiveData", true)) {
  4004. this.table.modules.reactiveData.watchRow(this);
  4005. }
  4006. };
  4007. //update the rows data
  4008. Row.prototype.updateData = function (updatedData) {
  4009. var _this22 = this;
  4010. var visible = Tabulator.prototype.helpers.elVisible(this.element),
  4011. tempData = {},
  4012. newRowData;
  4013. return new Promise(function (resolve, reject) {
  4014. if (typeof updatedData === "string") {
  4015. updatedData = JSON.parse(updatedData);
  4016. }
  4017. if (_this22.table.options.reactiveData && _this22.table.modExists("reactiveData", true)) {
  4018. _this22.table.modules.reactiveData.block();
  4019. }
  4020. //mutate incomming data if needed
  4021. if (_this22.table.modExists("mutator")) {
  4022. tempData = Object.assign(tempData, _this22.data);
  4023. tempData = Object.assign(tempData, updatedData);
  4024. newRowData = _this22.table.modules.mutator.transformRow(tempData, "data", updatedData);
  4025. } else {
  4026. newRowData = updatedData;
  4027. }
  4028. //set data
  4029. for (var attrname in newRowData) {
  4030. _this22.data[attrname] = newRowData[attrname];
  4031. }
  4032. if (_this22.table.options.reactiveData && _this22.table.modExists("reactiveData", true)) {
  4033. _this22.table.modules.reactiveData.unblock();
  4034. }
  4035. //update affected cells only
  4036. for (var attrname in updatedData) {
  4037. var columns = _this22.table.columnManager.getColumnsByFieldRoot(attrname);
  4038. columns.forEach(function (column) {
  4039. var cell = _this22.getCell(column.getField());
  4040. if (cell) {
  4041. var value = column.getFieldValue(newRowData);
  4042. if (cell.getValue() != value) {
  4043. cell.setValueProcessData(value);
  4044. if (visible) {
  4045. cell.cellRendered();
  4046. }
  4047. }
  4048. }
  4049. });
  4050. }
  4051. if (_this22.table.options.groupUpdateOnCellEdit && _this22.table.options.groupBy && _this22.table.modExists("groupRows")) {
  4052. _this22.table.modules.groupRows.reassignRowToGroup(_this22.row);
  4053. }
  4054. //Partial reinitialization if visible
  4055. if (visible) {
  4056. _this22.normalizeHeight(true);
  4057. if (_this22.table.options.rowFormatter) {
  4058. _this22.table.options.rowFormatter(_this22.getComponent());
  4059. }
  4060. } else {
  4061. _this22.initialized = false;
  4062. _this22.height = 0;
  4063. _this22.heightStyled = "";
  4064. }
  4065. if (_this22.table.options.dataTree !== false && _this22.table.modExists("dataTree") && _this22.table.modules.dataTree.redrawNeeded(updatedData)) {
  4066. _this22.table.modules.dataTree.initializeRow(_this22);
  4067. _this22.table.modules.dataTree.layoutRow(_this22);
  4068. _this22.table.rowManager.refreshActiveData("tree", false, true);
  4069. }
  4070. //this.reinitialize();
  4071. _this22.table.options.rowUpdated.call(_this22.table, _this22.getComponent());
  4072. if (_this22.table.options.dataChanged) {
  4073. _this22.table.options.dataChanged.call(_this22.table, _this22.table.rowManager.getData());
  4074. }
  4075. resolve();
  4076. });
  4077. };
  4078. Row.prototype.getData = function (transform) {
  4079. if (transform) {
  4080. if (this.table.modExists("accessor")) {
  4081. return this.table.modules.accessor.transformRow(this, transform);
  4082. }
  4083. }
  4084. return this.data;
  4085. };
  4086. Row.prototype.getCell = function (column) {
  4087. var match = false;
  4088. column = this.table.columnManager.findColumn(column);
  4089. match = this.cells.find(function (cell) {
  4090. return cell.column === column;
  4091. });
  4092. return match;
  4093. };
  4094. Row.prototype.getCellIndex = function (findCell) {
  4095. return this.cells.findIndex(function (cell) {
  4096. return cell === findCell;
  4097. });
  4098. };
  4099. Row.prototype.findNextEditableCell = function (index) {
  4100. var nextCell = false;
  4101. if (index < this.cells.length - 1) {
  4102. for (var i = index + 1; i < this.cells.length; i++) {
  4103. var cell = this.cells[i];
  4104. if (cell.column.modules.edit && Tabulator.prototype.helpers.elVisible(cell.getElement())) {
  4105. var allowEdit = true;
  4106. if (typeof cell.column.modules.edit.check == "function") {
  4107. allowEdit = cell.column.modules.edit.check(cell.getComponent());
  4108. }
  4109. if (allowEdit) {
  4110. nextCell = cell;
  4111. break;
  4112. }
  4113. }
  4114. }
  4115. }
  4116. return nextCell;
  4117. };
  4118. Row.prototype.findPrevEditableCell = function (index) {
  4119. var prevCell = false;
  4120. if (index > 0) {
  4121. for (var i = index - 1; i >= 0; i--) {
  4122. var cell = this.cells[i],
  4123. allowEdit = true;
  4124. if (cell.column.modules.edit && Tabulator.prototype.helpers.elVisible(cell.getElement())) {
  4125. if (typeof cell.column.modules.edit.check == "function") {
  4126. allowEdit = cell.column.modules.edit.check(cell.getComponent());
  4127. }
  4128. if (allowEdit) {
  4129. prevCell = cell;
  4130. break;
  4131. }
  4132. }
  4133. }
  4134. }
  4135. return prevCell;
  4136. };
  4137. Row.prototype.getCells = function () {
  4138. return this.cells;
  4139. };
  4140. Row.prototype.nextRow = function () {
  4141. var row = this.table.rowManager.nextDisplayRow(this, true);
  4142. return row || false;
  4143. };
  4144. Row.prototype.prevRow = function () {
  4145. var row = this.table.rowManager.prevDisplayRow(this, true);
  4146. return row || false;
  4147. };
  4148. Row.prototype.moveToRow = function (to, before) {
  4149. var toRow = this.table.rowManager.findRow(to);
  4150. if (toRow) {
  4151. this.table.rowManager.moveRowActual(this, toRow, !before);
  4152. this.table.rowManager.refreshActiveData("display", false, true);
  4153. } else {
  4154. console.warn("Move Error - No matching row found:", to);
  4155. }
  4156. };
  4157. Row.prototype.validate = function () {
  4158. var invalid = [];
  4159. this.cells.forEach(function (cell) {
  4160. if (!cell.validate()) {
  4161. invalid.push(cell.getComponent());
  4162. }
  4163. });
  4164. return invalid.length ? invalid : true;
  4165. };
  4166. ///////////////////// Actions /////////////////////
  4167. Row.prototype.delete = function () {
  4168. var _this23 = this;
  4169. return new Promise(function (resolve, reject) {
  4170. var index, rows;
  4171. if (_this23.table.options.history && _this23.table.modExists("history")) {
  4172. if (_this23.table.options.groupBy && _this23.table.modExists("groupRows")) {
  4173. rows = _this23.getGroup().rows;
  4174. index = rows.indexOf(_this23);
  4175. if (index) {
  4176. index = rows[index - 1];
  4177. }
  4178. } else {
  4179. index = _this23.table.rowManager.getRowIndex(_this23);
  4180. if (index) {
  4181. index = _this23.table.rowManager.rows[index - 1];
  4182. }
  4183. }
  4184. _this23.table.modules.history.action("rowDelete", _this23, { data: _this23.getData(), pos: !index, index: index });
  4185. }
  4186. _this23.deleteActual();
  4187. resolve();
  4188. });
  4189. };
  4190. Row.prototype.deleteActual = function (blockRedraw) {
  4191. var index = this.table.rowManager.getRowIndex(this);
  4192. this.detatchModules();
  4193. // if(this.table.options.dataTree && this.table.modExists("dataTree")){
  4194. // this.table.modules.dataTree.collapseRow(this, true);
  4195. // }
  4196. //remove any reactive data watchers from row object
  4197. if (this.table.options.reactiveData && this.table.modExists("reactiveData", true)) {}
  4198. // this.table.modules.reactiveData.unwatchRow(this);
  4199. //remove from group
  4200. if (this.modules.group) {
  4201. this.modules.group.removeRow(this);
  4202. }
  4203. this.table.rowManager.deleteRow(this, blockRedraw);
  4204. this.deleteCells();
  4205. this.initialized = false;
  4206. this.heightInitialized = false;
  4207. this.element = false;
  4208. if (this.table.options.dataTree && this.table.modExists("dataTree", true)) {
  4209. this.table.modules.dataTree.rowDelete(this);
  4210. }
  4211. //recalc column calculations if present
  4212. if (this.table.modExists("columnCalcs")) {
  4213. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  4214. this.table.modules.columnCalcs.recalcRowGroup(this);
  4215. } else {
  4216. this.table.modules.columnCalcs.recalc(this.table.rowManager.activeRows);
  4217. }
  4218. }
  4219. };
  4220. Row.prototype.detatchModules = function () {
  4221. //deselect row if it is selected
  4222. if (this.table.modExists("selectRow")) {
  4223. this.table.modules.selectRow._deselectRow(this, true);
  4224. }
  4225. //cancel edit if row is currently being edited
  4226. if (this.table.modExists("edit")) {
  4227. if (this.table.modules.edit.currentCell.row === this) {
  4228. this.table.modules.edit.cancelEdit();
  4229. }
  4230. }
  4231. if (this.table.modExists("frozenRows")) {
  4232. this.table.modules.frozenRows.detachRow(this);
  4233. }
  4234. };
  4235. Row.prototype.deleteCells = function () {
  4236. var cellCount = this.cells.length;
  4237. for (var _i8 = 0; _i8 < cellCount; _i8++) {
  4238. this.cells[0].delete();
  4239. }
  4240. };
  4241. Row.prototype.wipe = function () {
  4242. this.detatchModules();
  4243. this.deleteCells();
  4244. while (this.element.firstChild) {
  4245. this.element.removeChild(this.element.firstChild);
  4246. }this.element = false;
  4247. this.modules = {};
  4248. if (this.element.parentNode) {
  4249. this.element.parentNode.removeChild(this.element);
  4250. }
  4251. };
  4252. Row.prototype.getGroup = function () {
  4253. return this.modules.group || false;
  4254. };
  4255. //////////////// Object Generation /////////////////
  4256. Row.prototype.getComponent = function () {
  4257. if (!this.component) {
  4258. this.component = new RowComponent(this);
  4259. }
  4260. return this.component;
  4261. };
  4262. //public row object
  4263. var CellComponent = function CellComponent(cell) {
  4264. this._cell = cell;
  4265. };
  4266. CellComponent.prototype.getValue = function () {
  4267. return this._cell.getValue();
  4268. };
  4269. CellComponent.prototype.getOldValue = function () {
  4270. return this._cell.getOldValue();
  4271. };
  4272. CellComponent.prototype.getInitialValue = function () {
  4273. return this._cell.initialValue;
  4274. };
  4275. CellComponent.prototype.getElement = function () {
  4276. return this._cell.getElement();
  4277. };
  4278. CellComponent.prototype.getRow = function () {
  4279. return this._cell.row.getComponent();
  4280. };
  4281. CellComponent.prototype.getData = function () {
  4282. return this._cell.row.getData();
  4283. };
  4284. CellComponent.prototype.getField = function () {
  4285. return this._cell.column.getField();
  4286. };
  4287. CellComponent.prototype.getColumn = function () {
  4288. return this._cell.column.getComponent();
  4289. };
  4290. CellComponent.prototype.setValue = function (value, mutate) {
  4291. if (typeof mutate == "undefined") {
  4292. mutate = true;
  4293. }
  4294. this._cell.setValue(value, mutate);
  4295. };
  4296. CellComponent.prototype.restoreOldValue = function () {
  4297. this._cell.setValueActual(this._cell.getOldValue());
  4298. };
  4299. CellComponent.prototype.restoreInitialValue = function () {
  4300. this._cell.setValueActual(this._cell.initialValue);
  4301. };
  4302. CellComponent.prototype.edit = function (force) {
  4303. return this._cell.edit(force);
  4304. };
  4305. CellComponent.prototype.cancelEdit = function () {
  4306. this._cell.cancelEdit();
  4307. };
  4308. CellComponent.prototype.isEdited = function () {
  4309. return !!this._cell.modules.edit && this._cell.modules.edit.edited;
  4310. };
  4311. CellComponent.prototype.clearEdited = function () {
  4312. if (self.table.modExists("edit", true)) {
  4313. this._cell.table.modules.edit.clearEdited(this._cell);
  4314. }
  4315. };
  4316. CellComponent.prototype.isValid = function () {
  4317. return this._cell.modules.validate ? !this._cell.modules.validate.invalid : true;
  4318. };
  4319. CellComponent.prototype.validate = function () {
  4320. return this._cell.validate();
  4321. };
  4322. CellComponent.prototype.clearValidation = function () {
  4323. if (this._cell.table.modExists("validate", true)) {
  4324. this._cell.table.modules.validate.clearValidation(this._cell);
  4325. }
  4326. };
  4327. CellComponent.prototype.nav = function () {
  4328. return this._cell.nav();
  4329. };
  4330. CellComponent.prototype.checkHeight = function () {
  4331. this._cell.checkHeight();
  4332. };
  4333. CellComponent.prototype.getTable = function () {
  4334. return this._cell.table;
  4335. };
  4336. CellComponent.prototype._getSelf = function () {
  4337. return this._cell;
  4338. };
  4339. var Cell = function Cell(column, row) {
  4340. this.table = column.table;
  4341. this.column = column;
  4342. this.row = row;
  4343. this.element = null;
  4344. this.value = null;
  4345. this.initialValue;
  4346. this.oldValue = null;
  4347. this.modules = {};
  4348. this.height = null;
  4349. this.width = null;
  4350. this.minWidth = null;
  4351. this.component = null;
  4352. this.loaded = false; //track if the cell has been added to the DOM yet
  4353. this.build();
  4354. };
  4355. //////////////// Setup Functions /////////////////
  4356. //generate element
  4357. Cell.prototype.build = function () {
  4358. this.generateElement();
  4359. this.setWidth();
  4360. this._configureCell();
  4361. this.setValueActual(this.column.getFieldValue(this.row.data));
  4362. this.initialValue = this.value;
  4363. };
  4364. Cell.prototype.generateElement = function () {
  4365. this.element = document.createElement('div');
  4366. this.element.className = "tabulator-cell";
  4367. this.element.setAttribute("role", "gridcell");
  4368. this.element = this.element;
  4369. };
  4370. Cell.prototype._configureCell = function () {
  4371. var self = this,
  4372. cellEvents = self.column.cellEvents,
  4373. element = self.element,
  4374. field = this.column.getField(),
  4375. vertAligns = {
  4376. top: "flex-start",
  4377. bottom: "flex-end",
  4378. middle: "center"
  4379. },
  4380. hozAligns = {
  4381. left: "flex-start",
  4382. right: "flex-end",
  4383. center: "center"
  4384. };
  4385. //set text alignment
  4386. element.style.textAlign = self.column.hozAlign;
  4387. if (self.column.vertAlign) {
  4388. element.style.display = "inline-flex";
  4389. element.style.alignItems = vertAligns[self.column.vertAlign] || "";
  4390. if (self.column.hozAlign) {
  4391. element.style.justifyContent = hozAligns[self.column.hozAlign] || "";
  4392. }
  4393. }
  4394. if (field) {
  4395. element.setAttribute("tabulator-field", field);
  4396. }
  4397. //add class to cell if needed
  4398. if (self.column.definition.cssClass) {
  4399. var classNames = self.column.definition.cssClass.split(" ");
  4400. classNames.forEach(function (className) {
  4401. element.classList.add(className);
  4402. });
  4403. }
  4404. //update tooltip on mouse enter
  4405. if (this.table.options.tooltipGenerationMode === "hover") {
  4406. element.addEventListener("mouseenter", function (e) {
  4407. self._generateTooltip();
  4408. });
  4409. }
  4410. self._bindClickEvents(cellEvents);
  4411. self._bindTouchEvents(cellEvents);
  4412. self._bindMouseEvents(cellEvents);
  4413. if (self.column.modules.edit) {
  4414. self.table.modules.edit.bindEditor(self);
  4415. }
  4416. if (self.column.definition.rowHandle && self.table.options.movableRows !== false && self.table.modExists("moveRow")) {
  4417. self.table.modules.moveRow.initializeCell(self);
  4418. }
  4419. //hide cell if not visible
  4420. if (!self.column.visible) {
  4421. self.hide();
  4422. }
  4423. };
  4424. Cell.prototype._bindClickEvents = function (cellEvents) {
  4425. var self = this,
  4426. element = self.element;
  4427. //set event bindings
  4428. if (cellEvents.cellClick || self.table.options.cellClick) {
  4429. element.addEventListener("click", function (e) {
  4430. var component = self.getComponent();
  4431. if (cellEvents.cellClick) {
  4432. cellEvents.cellClick.call(self.table, e, component);
  4433. }
  4434. if (self.table.options.cellClick) {
  4435. self.table.options.cellClick.call(self.table, e, component);
  4436. }
  4437. });
  4438. }
  4439. if (cellEvents.cellDblClick || this.table.options.cellDblClick) {
  4440. element.addEventListener("dblclick", function (e) {
  4441. var component = self.getComponent();
  4442. if (cellEvents.cellDblClick) {
  4443. cellEvents.cellDblClick.call(self.table, e, component);
  4444. }
  4445. if (self.table.options.cellDblClick) {
  4446. self.table.options.cellDblClick.call(self.table, e, component);
  4447. }
  4448. });
  4449. } else {
  4450. element.addEventListener("dblclick", function (e) {
  4451. if (self.table.modExists("edit")) {
  4452. if (self.table.modules.edit.currentCell === self) {
  4453. return; //prevent instant selection of editor content
  4454. }
  4455. }
  4456. e.preventDefault();
  4457. try {
  4458. if (document.selection) {
  4459. // IE
  4460. var range = document.body.createTextRange();
  4461. range.moveToElementText(self.element);
  4462. range.select();
  4463. } else if (window.getSelection) {
  4464. var range = document.createRange();
  4465. range.selectNode(self.element);
  4466. window.getSelection().removeAllRanges();
  4467. window.getSelection().addRange(range);
  4468. }
  4469. } catch (e) {}
  4470. });
  4471. }
  4472. if (cellEvents.cellContext || this.table.options.cellContext) {
  4473. element.addEventListener("contextmenu", function (e) {
  4474. var component = self.getComponent();
  4475. if (cellEvents.cellContext) {
  4476. cellEvents.cellContext.call(self.table, e, component);
  4477. }
  4478. if (self.table.options.cellContext) {
  4479. self.table.options.cellContext.call(self.table, e, component);
  4480. }
  4481. });
  4482. }
  4483. };
  4484. Cell.prototype._bindMouseEvents = function (cellEvents) {
  4485. var self = this,
  4486. element = self.element;
  4487. if (cellEvents.cellMouseEnter || self.table.options.cellMouseEnter) {
  4488. element.addEventListener("mouseenter", function (e) {
  4489. var component = self.getComponent();
  4490. if (cellEvents.cellMouseEnter) {
  4491. cellEvents.cellMouseEnter.call(self.table, e, component);
  4492. }
  4493. if (self.table.options.cellMouseEnter) {
  4494. self.table.options.cellMouseEnter.call(self.table, e, component);
  4495. }
  4496. });
  4497. }
  4498. if (cellEvents.cellMouseLeave || self.table.options.cellMouseLeave) {
  4499. element.addEventListener("mouseleave", function (e) {
  4500. var component = self.getComponent();
  4501. if (cellEvents.cellMouseLeave) {
  4502. cellEvents.cellMouseLeave.call(self.table, e, component);
  4503. }
  4504. if (self.table.options.cellMouseLeave) {
  4505. self.table.options.cellMouseLeave.call(self.table, e, component);
  4506. }
  4507. });
  4508. }
  4509. if (cellEvents.cellMouseOver || self.table.options.cellMouseOver) {
  4510. element.addEventListener("mouseover", function (e) {
  4511. var component = self.getComponent();
  4512. if (cellEvents.cellMouseOver) {
  4513. cellEvents.cellMouseOver.call(self.table, e, component);
  4514. }
  4515. if (self.table.options.cellMouseOver) {
  4516. self.table.options.cellMouseOver.call(self.table, e, component);
  4517. }
  4518. });
  4519. }
  4520. if (cellEvents.cellMouseOut || self.table.options.cellMouseOut) {
  4521. element.addEventListener("mouseout", function (e) {
  4522. var component = self.getComponent();
  4523. if (cellEvents.cellMouseOut) {
  4524. cellEvents.cellMouseOut.call(self.table, e, component);
  4525. }
  4526. if (self.table.options.cellMouseOut) {
  4527. self.table.options.cellMouseOut.call(self.table, e, component);
  4528. }
  4529. });
  4530. }
  4531. if (cellEvents.cellMouseMove || self.table.options.cellMouseMove) {
  4532. element.addEventListener("mousemove", function (e) {
  4533. var component = self.getComponent();
  4534. if (cellEvents.cellMouseMove) {
  4535. cellEvents.cellMouseMove.call(self.table, e, component);
  4536. }
  4537. if (self.table.options.cellMouseMove) {
  4538. self.table.options.cellMouseMove.call(self.table, e, component);
  4539. }
  4540. });
  4541. }
  4542. };
  4543. Cell.prototype._bindTouchEvents = function (cellEvents) {
  4544. var self = this,
  4545. element = self.element,
  4546. dblTap,
  4547. tapHold,
  4548. tap;
  4549. if (cellEvents.cellTap || this.table.options.cellTap) {
  4550. tap = false;
  4551. element.addEventListener("touchstart", function (e) {
  4552. tap = true;
  4553. }, { passive: true });
  4554. element.addEventListener("touchend", function (e) {
  4555. if (tap) {
  4556. var component = self.getComponent();
  4557. if (cellEvents.cellTap) {
  4558. cellEvents.cellTap.call(self.table, e, component);
  4559. }
  4560. if (self.table.options.cellTap) {
  4561. self.table.options.cellTap.call(self.table, e, component);
  4562. }
  4563. }
  4564. tap = false;
  4565. });
  4566. }
  4567. if (cellEvents.cellDblTap || this.table.options.cellDblTap) {
  4568. dblTap = null;
  4569. element.addEventListener("touchend", function (e) {
  4570. if (dblTap) {
  4571. clearTimeout(dblTap);
  4572. dblTap = null;
  4573. var component = self.getComponent();
  4574. if (cellEvents.cellDblTap) {
  4575. cellEvents.cellDblTap.call(self.table, e, component);
  4576. }
  4577. if (self.table.options.cellDblTap) {
  4578. self.table.options.cellDblTap.call(self.table, e, component);
  4579. }
  4580. } else {
  4581. dblTap = setTimeout(function () {
  4582. clearTimeout(dblTap);
  4583. dblTap = null;
  4584. }, 300);
  4585. }
  4586. });
  4587. }
  4588. if (cellEvents.cellTapHold || this.table.options.cellTapHold) {
  4589. tapHold = null;
  4590. element.addEventListener("touchstart", function (e) {
  4591. clearTimeout(tapHold);
  4592. tapHold = setTimeout(function () {
  4593. clearTimeout(tapHold);
  4594. tapHold = null;
  4595. tap = false;
  4596. var component = self.getComponent();
  4597. if (cellEvents.cellTapHold) {
  4598. cellEvents.cellTapHold.call(self.table, e, component);
  4599. }
  4600. if (self.table.options.cellTapHold) {
  4601. self.table.options.cellTapHold.call(self.table, e, component);
  4602. }
  4603. }, 1000);
  4604. }, { passive: true });
  4605. element.addEventListener("touchend", function (e) {
  4606. clearTimeout(tapHold);
  4607. tapHold = null;
  4608. });
  4609. }
  4610. };
  4611. //generate cell contents
  4612. Cell.prototype._generateContents = function () {
  4613. var val;
  4614. if (this.table.modExists("format")) {
  4615. val = this.table.modules.format.formatValue(this);
  4616. } else {
  4617. val = this.element.innerHTML = this.value;
  4618. }
  4619. switch (typeof val === 'undefined' ? 'undefined' : _typeof(val)) {
  4620. case "object":
  4621. if (val instanceof Node) {
  4622. //clear previous cell contents
  4623. while (this.element.firstChild) {
  4624. this.element.removeChild(this.element.firstChild);
  4625. }this.element.appendChild(val);
  4626. } else {
  4627. this.element.innerHTML = "";
  4628. if (val != null) {
  4629. 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);
  4630. }
  4631. }
  4632. break;
  4633. case "undefined":
  4634. case "null":
  4635. this.element.innerHTML = "";
  4636. break;
  4637. default:
  4638. this.element.innerHTML = val;
  4639. }
  4640. };
  4641. Cell.prototype.cellRendered = function () {
  4642. if (this.table.modExists("format") && this.table.modules.format.cellRendered) {
  4643. this.table.modules.format.cellRendered(this);
  4644. }
  4645. };
  4646. //generate tooltip text
  4647. Cell.prototype._generateTooltip = function () {
  4648. var tooltip = this.column.tooltip;
  4649. if (tooltip) {
  4650. if (tooltip === true) {
  4651. tooltip = this.value;
  4652. } else if (typeof tooltip == "function") {
  4653. tooltip = tooltip(this.getComponent());
  4654. if (tooltip === false) {
  4655. tooltip = "";
  4656. }
  4657. }
  4658. if (typeof tooltip === "undefined") {
  4659. tooltip = "";
  4660. }
  4661. this.element.setAttribute("title", tooltip);
  4662. } else {
  4663. this.element.setAttribute("title", "");
  4664. }
  4665. };
  4666. //////////////////// Getters ////////////////////
  4667. Cell.prototype.getElement = function () {
  4668. if (!this.loaded) {
  4669. this.loaded = true;
  4670. this.layoutElement();
  4671. }
  4672. return this.element;
  4673. };
  4674. Cell.prototype.getValue = function () {
  4675. return this.value;
  4676. };
  4677. Cell.prototype.getOldValue = function () {
  4678. return this.oldValue;
  4679. };
  4680. //////////////////// Actions ////////////////////
  4681. Cell.prototype.setValue = function (value, mutate) {
  4682. var changed = this.setValueProcessData(value, mutate),
  4683. component;
  4684. if (changed) {
  4685. if (this.table.options.history && this.table.modExists("history")) {
  4686. this.table.modules.history.action("cellEdit", this, { oldValue: this.oldValue, newValue: this.value });
  4687. }
  4688. component = this.getComponent();
  4689. if (this.column.cellEvents.cellEdited) {
  4690. this.column.cellEvents.cellEdited.call(this.table, component);
  4691. }
  4692. if (this.table.options.groupUpdateOnCellEdit && this.table.options.groupBy && this.table.modExists("groupRows")) {
  4693. this.table.modules.groupRows.reassignRowToGroup(this.row);
  4694. }
  4695. this.cellRendered();
  4696. this.table.options.cellEdited.call(this.table, component);
  4697. if (this.table.options.dataChanged) {
  4698. this.table.options.dataChanged.call(this.table, this.table.rowManager.getData());
  4699. }
  4700. }
  4701. };
  4702. Cell.prototype.setValueProcessData = function (value, mutate) {
  4703. var changed = false;
  4704. if (this.value != value) {
  4705. changed = true;
  4706. if (mutate) {
  4707. if (this.column.modules.mutate) {
  4708. value = this.table.modules.mutator.transformCell(this, value);
  4709. }
  4710. }
  4711. }
  4712. this.setValueActual(value);
  4713. if (changed && this.table.modExists("columnCalcs")) {
  4714. if (this.column.definition.topCalc || this.column.definition.bottomCalc) {
  4715. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  4716. if (this.table.options.columnCalcs == "table" || this.table.options.columnCalcs == "both") {
  4717. this.table.modules.columnCalcs.recalc(this.table.rowManager.activeRows);
  4718. }
  4719. if (this.table.options.columnCalcs != "table") {
  4720. this.table.modules.columnCalcs.recalcRowGroup(this.row);
  4721. }
  4722. } else {
  4723. this.table.modules.columnCalcs.recalc(this.table.rowManager.activeRows);
  4724. }
  4725. }
  4726. }
  4727. return changed;
  4728. };
  4729. Cell.prototype.setValueActual = function (value) {
  4730. this.oldValue = this.value;
  4731. this.value = value;
  4732. if (this.table.options.reactiveData && this.table.modExists("reactiveData")) {
  4733. this.table.modules.reactiveData.block();
  4734. }
  4735. this.column.setFieldValue(this.row.data, value);
  4736. if (this.table.options.reactiveData && this.table.modExists("reactiveData")) {
  4737. this.table.modules.reactiveData.unblock();
  4738. }
  4739. if (this.loaded) {
  4740. this.layoutElement();
  4741. }
  4742. };
  4743. Cell.prototype.layoutElement = function () {
  4744. this._generateContents();
  4745. this._generateTooltip();
  4746. //set resizable handles
  4747. if (this.table.options.resizableColumns && this.table.modExists("resizeColumns") && this.row.type === "row") {
  4748. this.table.modules.resizeColumns.initializeColumn("cell", this.column, this.element);
  4749. }
  4750. if ((this.column.definition.contextMenu || this.column.definition.clickMenu) && this.table.modExists("menu")) {
  4751. this.table.modules.menu.initializeCell(this);
  4752. }
  4753. //handle frozen cells
  4754. if (this.table.modExists("frozenColumns")) {
  4755. this.table.modules.frozenColumns.layoutElement(this.element, this.column);
  4756. }
  4757. };
  4758. Cell.prototype.setWidth = function () {
  4759. this.width = this.column.width;
  4760. this.element.style.width = this.column.widthStyled;
  4761. };
  4762. Cell.prototype.clearWidth = function () {
  4763. this.width = "";
  4764. this.element.style.width = "";
  4765. };
  4766. Cell.prototype.getWidth = function () {
  4767. return this.width || this.element.offsetWidth;
  4768. };
  4769. Cell.prototype.setMinWidth = function () {
  4770. this.minWidth = this.column.minWidth;
  4771. this.element.style.minWidth = this.column.minWidthStyled;
  4772. };
  4773. Cell.prototype.checkHeight = function () {
  4774. // var height = this.element.css("height");
  4775. this.row.reinitializeHeight();
  4776. };
  4777. Cell.prototype.clearHeight = function () {
  4778. this.element.style.height = "";
  4779. this.height = null;
  4780. };
  4781. Cell.prototype.setHeight = function () {
  4782. this.height = this.row.height;
  4783. this.element.style.height = this.row.heightStyled;
  4784. };
  4785. Cell.prototype.getHeight = function () {
  4786. return this.height || this.element.offsetHeight;
  4787. };
  4788. Cell.prototype.show = function () {
  4789. this.element.style.display = this.column.vertAlign ? "inline-flex" : "";
  4790. };
  4791. Cell.prototype.hide = function () {
  4792. this.element.style.display = "none";
  4793. };
  4794. Cell.prototype.edit = function (force) {
  4795. if (this.table.modExists("edit", true)) {
  4796. return this.table.modules.edit.editCell(this, force);
  4797. }
  4798. };
  4799. Cell.prototype.cancelEdit = function () {
  4800. if (this.table.modExists("edit", true)) {
  4801. var editing = this.table.modules.edit.getCurrentCell();
  4802. if (editing && editing._getSelf() === this) {
  4803. this.table.modules.edit.cancelEdit();
  4804. } else {
  4805. console.warn("Cancel Editor Error - This cell is not currently being edited ");
  4806. }
  4807. }
  4808. };
  4809. Cell.prototype.validate = function () {
  4810. if (this.column.modules.validate && this.table.modExists("validate", true)) {
  4811. var valid = this.table.modules.validate.validate(this.column.modules.validate, this, this.getValue());
  4812. return valid === true;
  4813. } else {
  4814. return true;
  4815. }
  4816. };
  4817. Cell.prototype.delete = function () {
  4818. if (!this.table.rowManager.redrawBlock && this.element.parentNode) {
  4819. this.element.parentNode.removeChild(this.element);
  4820. }
  4821. if (this.modules.validate && this.modules.validate.invalid) {
  4822. this.table.modules.validate.clearValidation(this);
  4823. }
  4824. if (this.modules.edit && this.modules.edit.edited) {
  4825. this.table.modules.edit.clearEdited(this);
  4826. }
  4827. if (this.table.options.history) {
  4828. this.table.modules.history.clearComponentHistory(this);
  4829. }
  4830. this.element = false;
  4831. this.column.deleteCell(this);
  4832. this.row.deleteCell(this);
  4833. this.calcs = {};
  4834. };
  4835. //////////////// Navigation /////////////////
  4836. Cell.prototype.nav = function () {
  4837. var self = this,
  4838. nextCell = false,
  4839. index = this.row.getCellIndex(this);
  4840. return {
  4841. next: function next() {
  4842. var nextCell = this.right(),
  4843. nextRow;
  4844. if (!nextCell) {
  4845. nextRow = self.table.rowManager.nextDisplayRow(self.row, true);
  4846. if (nextRow) {
  4847. nextCell = nextRow.findNextEditableCell(-1);
  4848. if (nextCell) {
  4849. nextCell.edit();
  4850. return true;
  4851. }
  4852. }
  4853. } else {
  4854. return true;
  4855. }
  4856. return false;
  4857. },
  4858. prev: function prev() {
  4859. var nextCell = this.left(),
  4860. prevRow;
  4861. if (!nextCell) {
  4862. prevRow = self.table.rowManager.prevDisplayRow(self.row, true);
  4863. if (prevRow) {
  4864. nextCell = prevRow.findPrevEditableCell(prevRow.cells.length);
  4865. if (nextCell) {
  4866. nextCell.edit();
  4867. return true;
  4868. }
  4869. }
  4870. } else {
  4871. return true;
  4872. }
  4873. return false;
  4874. },
  4875. left: function left() {
  4876. nextCell = self.row.findPrevEditableCell(index);
  4877. if (nextCell) {
  4878. nextCell.edit();
  4879. return true;
  4880. } else {
  4881. return false;
  4882. }
  4883. },
  4884. right: function right() {
  4885. nextCell = self.row.findNextEditableCell(index);
  4886. if (nextCell) {
  4887. nextCell.edit();
  4888. return true;
  4889. } else {
  4890. return false;
  4891. }
  4892. },
  4893. up: function up() {
  4894. var nextRow = self.table.rowManager.prevDisplayRow(self.row, true);
  4895. if (nextRow) {
  4896. nextRow.cells[index].edit();
  4897. }
  4898. },
  4899. down: function down() {
  4900. var nextRow = self.table.rowManager.nextDisplayRow(self.row, true);
  4901. if (nextRow) {
  4902. nextRow.cells[index].edit();
  4903. }
  4904. }
  4905. };
  4906. };
  4907. Cell.prototype.getIndex = function () {
  4908. this.row.getCellIndex(this);
  4909. };
  4910. //////////////// Object Generation /////////////////
  4911. Cell.prototype.getComponent = function () {
  4912. if (!this.component) {
  4913. this.component = new CellComponent(this);
  4914. }
  4915. return this.component;
  4916. };
  4917. var FooterManager = function FooterManager(table) {
  4918. this.table = table;
  4919. this.active = false;
  4920. this.element = this.createElement(); //containing element
  4921. this.external = false;
  4922. this.links = [];
  4923. this._initialize();
  4924. };
  4925. FooterManager.prototype.createElement = function () {
  4926. var el = document.createElement("div");
  4927. el.classList.add("tabulator-footer");
  4928. return el;
  4929. };
  4930. FooterManager.prototype._initialize = function (element) {
  4931. if (this.table.options.footerElement) {
  4932. switch (_typeof(this.table.options.footerElement)) {
  4933. case "string":
  4934. if (this.table.options.footerElement[0] === "<") {
  4935. this.element.innerHTML = this.table.options.footerElement;
  4936. } else {
  4937. this.external = true;
  4938. this.element = document.querySelector(this.table.options.footerElement);
  4939. }
  4940. break;
  4941. default:
  4942. this.element = this.table.options.footerElement;
  4943. break;
  4944. }
  4945. }
  4946. };
  4947. FooterManager.prototype.getElement = function () {
  4948. return this.element;
  4949. };
  4950. FooterManager.prototype.append = function (element, parent) {
  4951. this.activate(parent);
  4952. this.element.appendChild(element);
  4953. this.table.rowManager.adjustTableSize();
  4954. };
  4955. FooterManager.prototype.prepend = function (element, parent) {
  4956. this.activate(parent);
  4957. this.element.insertBefore(element, this.element.firstChild);
  4958. this.table.rowManager.adjustTableSize();
  4959. };
  4960. FooterManager.prototype.remove = function (element) {
  4961. element.parentNode.removeChild(element);
  4962. this.deactivate();
  4963. };
  4964. FooterManager.prototype.deactivate = function (force) {
  4965. if (!this.element.firstChild || force) {
  4966. if (!this.external) {
  4967. this.element.parentNode.removeChild(this.element);
  4968. }
  4969. this.active = false;
  4970. }
  4971. // this.table.rowManager.adjustTableSize();
  4972. };
  4973. FooterManager.prototype.activate = function (parent) {
  4974. if (!this.active) {
  4975. this.active = true;
  4976. if (!this.external) {
  4977. this.table.element.appendChild(this.getElement());
  4978. this.table.element.style.display = '';
  4979. }
  4980. }
  4981. if (parent) {
  4982. this.links.push(parent);
  4983. }
  4984. };
  4985. FooterManager.prototype.redraw = function () {
  4986. this.links.forEach(function (link) {
  4987. link.footerRedraw();
  4988. });
  4989. };
  4990. var Tabulator = function Tabulator(element, options) {
  4991. this.options = {};
  4992. this.columnManager = null; // hold Column Manager
  4993. this.rowManager = null; //hold Row Manager
  4994. this.footerManager = null; //holder Footer Manager
  4995. this.vdomHoz = null; //holder horizontal virtual dom
  4996. this.browser = ""; //hold current browser type
  4997. this.browserSlow = false; //handle reduced functionality for slower browsers
  4998. this.browserMobile = false; //check if running on moble, prevent resize cancelling edit on keyboard appearence
  4999. this.rtl = false; //check if the table is in RTL mode
  5000. this.modules = {}; //hold all modules bound to this table
  5001. if (this.initializeElement(element)) {
  5002. this.initializeOptions(options || {});
  5003. this._create();
  5004. }
  5005. Tabulator.prototype.comms.register(this); //register table for inderdevice communication
  5006. };
  5007. //default setup options
  5008. Tabulator.prototype.defaultOptions = {
  5009. height: false, //height of tabulator
  5010. minHeight: false, //minimum height of tabulator
  5011. maxHeight: false, //maximum height of tabulator
  5012. layout: "fitData", ///layout type "fitColumns" | "fitData"
  5013. layoutColumnsOnNewData: false, //update column widths on setData
  5014. columnMinWidth: 40, //minimum global width for a column
  5015. columnHeaderVertAlign: "top", //vertical alignment of column headers
  5016. columnVertAlign: false, // DEPRECATED - Left to allow warning
  5017. resizableColumns: true, //resizable columns
  5018. resizableRows: false, //resizable rows
  5019. autoResize: true, //auto resize table
  5020. columns: [], //store for colum header info
  5021. cellHozAlign: "", //horizontal align columns
  5022. cellVertAlign: "", //vertical align columns
  5023. headerHozAlign: "", //horizontal header alignment
  5024. data: [], //default starting data
  5025. autoColumns: false, //build columns from data row structure
  5026. autoColumnsDefinitions: false,
  5027. reactiveData: false, //enable data reactivity
  5028. nestedFieldSeparator: ".", //seperatpr for nested data
  5029. tooltips: false, //Tool tip value
  5030. tooltipsHeader: false, //Tool tip for headers
  5031. tooltipGenerationMode: "load", //when to generate tooltips
  5032. initialSort: false, //initial sorting criteria
  5033. initialFilter: false, //initial filtering criteria
  5034. initialHeaderFilter: false, //initial header filtering criteria
  5035. columnHeaderSortMulti: true, //multiple or single column sorting
  5036. sortOrderReverse: false, //reverse internal sort ordering
  5037. headerSort: true, //set default global header sort
  5038. headerSortTristate: false, //set default tristate header sorting
  5039. headerSortElement: "<div class='tabulator-arrow'></div>", //header sort element
  5040. footerElement: false, //hold footer element
  5041. index: "id", //filed for row index
  5042. textDirection: "auto",
  5043. keybindings: [], //array for keybindings
  5044. tabEndNewRow: false, //create new row when tab to end of table
  5045. invalidOptionWarnings: true, //allow toggling of invalid option warnings
  5046. clipboard: false, //enable clipboard
  5047. clipboardCopyStyled: true, //formatted table data
  5048. clipboardCopyConfig: false, //clipboard config
  5049. clipboardCopyFormatter: false, //DEPRICATED - REMOVE in 5.0
  5050. clipboardCopyRowRange: "active", //restrict clipboard to visible rows only
  5051. clipboardPasteParser: "table", //convert pasted clipboard data to rows
  5052. clipboardPasteAction: "insert", //how to insert pasted data into the table
  5053. clipboardCopied: function clipboardCopied() {}, //data has been copied to the clipboard
  5054. clipboardPasted: function clipboardPasted() {}, //data has been pasted into the table
  5055. clipboardPasteError: function clipboardPasteError() {}, //data has not successfully been pasted into the table
  5056. downloadDataFormatter: false, //function to manipulate table data before it is downloaded
  5057. downloadReady: function downloadReady(data, blob) {
  5058. return blob;
  5059. }, //function to manipulate download data
  5060. downloadComplete: false, //function to manipulate download data
  5061. downloadConfig: {}, //download config
  5062. downloadRowRange: "active", //restrict download to active rows only
  5063. dataTree: false, //enable data tree
  5064. dataTreeFilter: true, //filter child rows
  5065. dataTreeSort: true, //sort child rows
  5066. dataTreeElementColumn: false,
  5067. dataTreeBranchElement: true, //show data tree branch element
  5068. dataTreeChildIndent: 9, //data tree child indent in px
  5069. dataTreeChildField: "_children", //data tre column field to look for child rows
  5070. dataTreeCollapseElement: false, //data tree row collapse element
  5071. dataTreeExpandElement: false, //data tree row expand element
  5072. dataTreeStartExpanded: false,
  5073. dataTreeRowExpanded: function dataTreeRowExpanded() {}, //row has been expanded
  5074. dataTreeRowCollapsed: function dataTreeRowCollapsed() {}, //row has been collapsed
  5075. dataTreeChildColumnCalcs: false, //include visible data tree rows in column calculations
  5076. dataTreeSelectPropagate: false, //seleccting a parent row selects its children
  5077. printAsHtml: false, //enable print as html
  5078. printFormatter: false, //printing page formatter
  5079. printHeader: false, //page header contents
  5080. printFooter: false, //page footer contents
  5081. printCopyStyle: true, //DEPRICATED - REMOVE in 5.0
  5082. printStyled: true, //enable print as html styling
  5083. printVisibleRows: true, //DEPRICATED - REMOVE in 5.0
  5084. printRowRange: "visible", //restrict print to visible rows only
  5085. printConfig: {}, //print config options
  5086. addRowPos: "bottom", //position to insert blank rows, top|bottom
  5087. selectable: "highlight", //highlight rows on hover
  5088. selectableRangeMode: "drag", //highlight rows on hover
  5089. selectableRollingSelection: true, //roll selection once maximum number of selectable rows is reached
  5090. selectablePersistence: true, // maintain selection when table view is updated
  5091. selectableCheck: function selectableCheck(data, row) {
  5092. return true;
  5093. }, //check wheather row is selectable
  5094. headerFilterLiveFilterDelay: 300, //delay before updating column after user types in header filter
  5095. headerFilterPlaceholder: false, //placeholder text to display in header filters
  5096. headerVisible: true, //hide header
  5097. history: false, //enable edit history
  5098. locale: false, //current system language
  5099. langs: {},
  5100. virtualDom: true, //enable DOM virtualization
  5101. virtualDomBuffer: 0, // set virtual DOM buffer size
  5102. virtualDomHoz: false, //enable horizontal DOM virtualization
  5103. persistentLayout: false, //DEPRICATED - REMOVE in 5.0
  5104. persistentSort: false, //DEPRICATED - REMOVE in 5.0
  5105. persistentFilter: false, //DEPRICATED - REMOVE in 5.0
  5106. persistenceID: "", //key for persistent storage
  5107. persistenceMode: true, //mode for storing persistence information
  5108. persistenceReaderFunc: false, //function for handling persistence data reading
  5109. persistenceWriterFunc: false, //function for handling persistence data writing
  5110. persistence: false,
  5111. responsiveLayout: false, //responsive layout flags
  5112. responsiveLayoutCollapseStartOpen: true, //start showing collapsed data
  5113. responsiveLayoutCollapseUseFormatters: true, //responsive layout collapse formatter
  5114. responsiveLayoutCollapseFormatter: false, //responsive layout collapse formatter
  5115. pagination: false, //set pagination type
  5116. paginationSize: false, //set number of rows to a page
  5117. paginationInitialPage: 1, //initail page to show on load
  5118. paginationButtonCount: 5, // set count of page button
  5119. paginationSizeSelector: false, //add pagination size selector element
  5120. paginationElement: false, //element to hold pagination numbers
  5121. paginationDataSent: {}, //pagination data sent to the server
  5122. paginationDataReceived: {}, //pagination data received from the server
  5123. paginationAddRow: "page", //add rows on table or page
  5124. ajaxURL: false, //url for ajax loading
  5125. ajaxURLGenerator: false,
  5126. ajaxParams: {}, //params for ajax loading
  5127. ajaxConfig: "get", //ajax request type
  5128. ajaxContentType: "form", //ajax request type
  5129. ajaxRequestFunc: false, //promise function
  5130. ajaxLoader: true, //show loader
  5131. ajaxLoaderLoading: false, //loader element
  5132. ajaxLoaderError: false, //loader element
  5133. ajaxFiltering: false,
  5134. ajaxSorting: false,
  5135. ajaxProgressiveLoad: false, //progressive loading
  5136. ajaxProgressiveLoadDelay: 0, //delay between requests
  5137. ajaxProgressiveLoadScrollMargin: 0, //margin before scroll begins
  5138. groupBy: false, //enable table grouping and set field to group by
  5139. groupStartOpen: true, //starting state of group
  5140. groupValues: false,
  5141. groupUpdateOnCellEdit: false,
  5142. groupHeader: false, //header generation function
  5143. groupHeaderPrint: null,
  5144. groupHeaderClipboard: null,
  5145. groupHeaderHtmlOutput: null,
  5146. groupHeaderDownload: null,
  5147. htmlOutputConfig: false, //html outypu config
  5148. movableColumns: false, //enable movable columns
  5149. movableRows: false, //enable movable rows
  5150. movableRowsConnectedTables: false, //tables for movable rows to be connected to
  5151. movableRowsConnectedElements: false, //other elements for movable rows to be connected to
  5152. movableRowsSender: false,
  5153. movableRowsReceiver: "insert",
  5154. movableRowsSendingStart: function movableRowsSendingStart() {},
  5155. movableRowsSent: function movableRowsSent() {},
  5156. movableRowsSentFailed: function movableRowsSentFailed() {},
  5157. movableRowsSendingStop: function movableRowsSendingStop() {},
  5158. movableRowsReceivingStart: function movableRowsReceivingStart() {},
  5159. movableRowsReceived: function movableRowsReceived() {},
  5160. movableRowsReceivedFailed: function movableRowsReceivedFailed() {},
  5161. movableRowsReceivingStop: function movableRowsReceivingStop() {},
  5162. movableRowsElementDrop: function movableRowsElementDrop() {},
  5163. scrollToRowPosition: "top",
  5164. scrollToRowIfVisible: true,
  5165. scrollToColumnPosition: "left",
  5166. scrollToColumnIfVisible: true,
  5167. rowFormatter: false,
  5168. rowFormatterPrint: null,
  5169. rowFormatterClipboard: null,
  5170. rowFormatterHtmlOutput: null,
  5171. placeholder: false,
  5172. //table building callbacks
  5173. tableBuilding: function tableBuilding() {},
  5174. tableBuilt: function tableBuilt() {},
  5175. //render callbacks
  5176. renderStarted: function renderStarted() {},
  5177. renderComplete: function renderComplete() {},
  5178. //row callbacks
  5179. rowClick: false,
  5180. rowDblClick: false,
  5181. rowContext: false,
  5182. rowTap: false,
  5183. rowDblTap: false,
  5184. rowTapHold: false,
  5185. rowMouseEnter: false,
  5186. rowMouseLeave: false,
  5187. rowMouseOver: false,
  5188. rowMouseOut: false,
  5189. rowMouseMove: false,
  5190. rowContextMenu: false,
  5191. rowClickMenu: false,
  5192. rowAdded: function rowAdded() {},
  5193. rowDeleted: function rowDeleted() {},
  5194. rowMoved: function rowMoved() {},
  5195. rowUpdated: function rowUpdated() {},
  5196. rowSelectionChanged: function rowSelectionChanged() {},
  5197. rowSelected: function rowSelected() {},
  5198. rowDeselected: function rowDeselected() {},
  5199. rowResized: function rowResized() {},
  5200. //cell callbacks
  5201. //row callbacks
  5202. cellClick: false,
  5203. cellDblClick: false,
  5204. cellContext: false,
  5205. cellTap: false,
  5206. cellDblTap: false,
  5207. cellTapHold: false,
  5208. cellMouseEnter: false,
  5209. cellMouseLeave: false,
  5210. cellMouseOver: false,
  5211. cellMouseOut: false,
  5212. cellMouseMove: false,
  5213. cellEditing: function cellEditing() {},
  5214. cellEdited: function cellEdited() {},
  5215. cellEditCancelled: function cellEditCancelled() {},
  5216. //column callbacks
  5217. columnMoved: false,
  5218. columnResized: function columnResized() {},
  5219. columnTitleChanged: function columnTitleChanged() {},
  5220. columnVisibilityChanged: function columnVisibilityChanged() {},
  5221. //HTML iport callbacks
  5222. htmlImporting: function htmlImporting() {},
  5223. htmlImported: function htmlImported() {},
  5224. //data callbacks
  5225. dataLoading: function dataLoading() {},
  5226. dataLoaded: function dataLoaded() {},
  5227. dataEdited: false, //DEPRECATED
  5228. dataChanged: false,
  5229. //ajax callbacks
  5230. ajaxRequesting: function ajaxRequesting() {},
  5231. ajaxResponse: false,
  5232. ajaxError: function ajaxError() {},
  5233. //filtering callbacks
  5234. dataFiltering: false,
  5235. dataFiltered: false,
  5236. //sorting callbacks
  5237. dataSorting: function dataSorting() {},
  5238. dataSorted: function dataSorted() {},
  5239. //grouping callbacks
  5240. groupToggleElement: "arrow",
  5241. groupClosedShowCalcs: false,
  5242. dataGrouping: function dataGrouping() {},
  5243. dataGrouped: false,
  5244. groupVisibilityChanged: function groupVisibilityChanged() {},
  5245. groupClick: false,
  5246. groupDblClick: false,
  5247. groupContext: false,
  5248. groupContextMenu: false,
  5249. groupClickMenu: false,
  5250. groupTap: false,
  5251. groupDblTap: false,
  5252. groupTapHold: false,
  5253. columnCalcs: true,
  5254. //pagination callbacks
  5255. pageLoaded: function pageLoaded() {},
  5256. //localization callbacks
  5257. localized: function localized() {},
  5258. //validation callbacks
  5259. validationMode: "blocking",
  5260. validationFailed: function validationFailed() {},
  5261. //history callbacks
  5262. historyUndo: function historyUndo() {},
  5263. historyRedo: function historyRedo() {},
  5264. //scroll callbacks
  5265. scrollHorizontal: function scrollHorizontal() {},
  5266. scrollVertical: function scrollVertical() {}
  5267. };
  5268. Tabulator.prototype.initializeOptions = function (options) {
  5269. //warn user if option is not available
  5270. if (options.invalidOptionWarnings !== false) {
  5271. for (var key in options) {
  5272. if (typeof this.defaultOptions[key] === "undefined") {
  5273. console.warn("Invalid table constructor option:", key);
  5274. }
  5275. }
  5276. }
  5277. //assign options to table
  5278. for (var key in this.defaultOptions) {
  5279. if (key in options) {
  5280. this.options[key] = options[key];
  5281. } else {
  5282. if (Array.isArray(this.defaultOptions[key])) {
  5283. this.options[key] = [];
  5284. } else if (_typeof(this.defaultOptions[key]) === "object" && this.defaultOptions[key] !== null) {
  5285. this.options[key] = {};
  5286. } else {
  5287. this.options[key] = this.defaultOptions[key];
  5288. }
  5289. }
  5290. }
  5291. };
  5292. Tabulator.prototype.initializeElement = function (element) {
  5293. if (typeof HTMLElement !== "undefined" && element instanceof HTMLElement) {
  5294. this.element = element;
  5295. return true;
  5296. } else if (typeof element === "string") {
  5297. this.element = document.querySelector(element);
  5298. if (this.element) {
  5299. return true;
  5300. } else {
  5301. console.error("Tabulator Creation Error - no element found matching selector: ", element);
  5302. return false;
  5303. }
  5304. } else {
  5305. console.error("Tabulator Creation Error - Invalid element provided:", element);
  5306. return false;
  5307. }
  5308. };
  5309. Tabulator.prototype.rtlCheck = function () {
  5310. var style = window.getComputedStyle(this.element);
  5311. switch (this.options.textDirection) {
  5312. case "auto":
  5313. if (style.direction !== "rtl") {
  5314. break;
  5315. };
  5316. case "rtl":
  5317. this.element.classList.add("tabulator-rtl");
  5318. this.rtl = true;
  5319. break;
  5320. case "ltr":
  5321. this.element.classList.add("tabulator-ltr");
  5322. default:
  5323. this.rtl = false;
  5324. }
  5325. };
  5326. //convert depricated functionality to new functions
  5327. Tabulator.prototype._mapDepricatedFunctionality = function () {
  5328. //map depricated persistance setup options
  5329. if (this.options.persistentLayout || this.options.persistentSort || this.options.persistentFilter) {
  5330. if (!this.options.persistence) {
  5331. this.options.persistence = {};
  5332. }
  5333. }
  5334. if (this.options.dataEdited) {
  5335. console.warn("DEPRECATION WARNING - dataEdited option has been deprecated, please use the dataChanged option instead");
  5336. this.options.dataChanged = this.options.dataEdited;
  5337. }
  5338. if (this.options.downloadDataFormatter) {
  5339. console.warn("DEPRECATION WARNING - downloadDataFormatter option has been deprecated");
  5340. }
  5341. if (typeof this.options.clipboardCopyHeader !== "undefined") {
  5342. this.options.columnHeaders = this.options.clipboardCopyHeader;
  5343. console.warn("DEPRECATION WARNING - clipboardCopyHeader option has been deprecated, please use the columnHeaders property on the clipboardCopyConfig option");
  5344. }
  5345. if (this.options.printVisibleRows !== true) {
  5346. console.warn("printVisibleRows option is deprecated, you should now use the printRowRange option");
  5347. this.options.persistence.printRowRange = "active";
  5348. }
  5349. if (this.options.printCopyStyle !== true) {
  5350. console.warn("printCopyStyle option is deprecated, you should now use the printStyled option");
  5351. this.options.persistence.printStyled = this.options.printCopyStyle;
  5352. }
  5353. if (this.options.persistentLayout) {
  5354. console.warn("persistentLayout option is deprecated, you should now use the persistence option");
  5355. if (this.options.persistence !== true && typeof this.options.persistence.columns === "undefined") {
  5356. this.options.persistence.columns = true;
  5357. }
  5358. }
  5359. if (this.options.persistentSort) {
  5360. console.warn("persistentSort option is deprecated, you should now use the persistence option");
  5361. if (this.options.persistence !== true && typeof this.options.persistence.sort === "undefined") {
  5362. this.options.persistence.sort = true;
  5363. }
  5364. }
  5365. if (this.options.persistentFilter) {
  5366. console.warn("persistentFilter option is deprecated, you should now use the persistence option");
  5367. if (this.options.persistence !== true && typeof this.options.persistence.filter === "undefined") {
  5368. this.options.persistence.filter = true;
  5369. }
  5370. }
  5371. if (this.options.columnVertAlign) {
  5372. console.warn("columnVertAlign option is deprecated, you should now use the columnHeaderVertAlign option");
  5373. this.options.columnHeaderVertAlign = this.options.columnVertAlign;
  5374. }
  5375. };
  5376. Tabulator.prototype._clearSelection = function () {
  5377. this.element.classList.add("tabulator-block-select");
  5378. if (window.getSelection) {
  5379. if (window.getSelection().empty) {
  5380. // Chrome
  5381. window.getSelection().empty();
  5382. } else if (window.getSelection().removeAllRanges) {
  5383. // Firefox
  5384. window.getSelection().removeAllRanges();
  5385. }
  5386. } else if (document.selection) {
  5387. // IE?
  5388. document.selection.empty();
  5389. }
  5390. this.element.classList.remove("tabulator-block-select");
  5391. };
  5392. //concreate table
  5393. Tabulator.prototype._create = function () {
  5394. this._clearObjectPointers();
  5395. this._mapDepricatedFunctionality();
  5396. this.bindModules();
  5397. this.rtlCheck();
  5398. if (this.element.tagName === "TABLE") {
  5399. if (this.modExists("htmlTableImport", true)) {
  5400. this.modules.htmlTableImport.parseTable();
  5401. }
  5402. }
  5403. this.columnManager = new ColumnManager(this);
  5404. this.rowManager = new RowManager(this);
  5405. this.footerManager = new FooterManager(this);
  5406. this.columnManager.setRowManager(this.rowManager);
  5407. this.rowManager.setColumnManager(this.columnManager);
  5408. if (this.options.virtualDomHoz) {
  5409. this.vdomHoz = new VDomHoz(this);
  5410. }
  5411. this._buildElement();
  5412. this._loadInitialData();
  5413. };
  5414. //clear pointers to objects in default config object
  5415. Tabulator.prototype._clearObjectPointers = function () {
  5416. this.options.columns = this.options.columns.slice(0);
  5417. if (!this.options.reactiveData) {
  5418. this.options.data = this.options.data.slice(0);
  5419. }
  5420. };
  5421. //build tabulator element
  5422. Tabulator.prototype._buildElement = function () {
  5423. var _this24 = this;
  5424. var element = this.element,
  5425. mod = this.modules,
  5426. options = this.options;
  5427. options.tableBuilding.call(this);
  5428. element.classList.add("tabulator");
  5429. element.setAttribute("role", "grid");
  5430. //empty element
  5431. while (element.firstChild) {
  5432. element.removeChild(element.firstChild);
  5433. } //set table height
  5434. if (options.height) {
  5435. options.height = isNaN(options.height) ? options.height : options.height + "px";
  5436. element.style.height = options.height;
  5437. }
  5438. //set table min height
  5439. if (options.minHeight !== false) {
  5440. options.minHeight = isNaN(options.minHeight) ? options.minHeight : options.minHeight + "px";
  5441. element.style.minHeight = options.minHeight;
  5442. }
  5443. //set table maxHeight
  5444. if (options.maxHeight !== false) {
  5445. options.maxHeight = isNaN(options.maxHeight) ? options.maxHeight : options.maxHeight + "px";
  5446. element.style.maxHeight = options.maxHeight;
  5447. }
  5448. this.columnManager.initialize();
  5449. this.rowManager.initialize();
  5450. this._detectBrowser();
  5451. if (this.modExists("layout", true)) {
  5452. mod.layout.initialize(options.layout);
  5453. }
  5454. //set localization
  5455. mod.localize.initialize();
  5456. if (options.headerFilterPlaceholder !== false) {
  5457. mod.localize.setHeaderFilterPlaceholder(options.headerFilterPlaceholder);
  5458. }
  5459. for (var locale in options.langs) {
  5460. mod.localize.installLang(locale, options.langs[locale]);
  5461. }
  5462. mod.localize.setLocale(options.locale);
  5463. //configure placeholder element
  5464. if (typeof options.placeholder == "string") {
  5465. var el = document.createElement("div");
  5466. el.classList.add("tabulator-placeholder");
  5467. var span = document.createElement("span");
  5468. span.innerHTML = options.placeholder;
  5469. el.appendChild(span);
  5470. options.placeholder = el;
  5471. }
  5472. //build table elements
  5473. element.appendChild(this.columnManager.getElement());
  5474. element.appendChild(this.rowManager.getElement());
  5475. if (options.footerElement) {
  5476. this.footerManager.activate();
  5477. }
  5478. if (options.persistence && this.modExists("persistence", true)) {
  5479. mod.persistence.initialize();
  5480. }
  5481. if (options.persistence && this.modExists("persistence", true) && mod.persistence.config.columns) {
  5482. options.columns = mod.persistence.load("columns", options.columns);
  5483. }
  5484. if (options.movableRows && this.modExists("moveRow")) {
  5485. mod.moveRow.initialize();
  5486. }
  5487. if (options.autoColumns && this.options.data) {
  5488. this.columnManager.generateColumnsFromRowData(this.options.data);
  5489. }
  5490. if (this.modExists("columnCalcs")) {
  5491. mod.columnCalcs.initialize();
  5492. }
  5493. this.columnManager.setColumns(options.columns);
  5494. if (options.dataTree && this.modExists("dataTree", true)) {
  5495. mod.dataTree.initialize();
  5496. }
  5497. if (this.modExists("frozenRows")) {
  5498. this.modules.frozenRows.initialize();
  5499. }
  5500. if ((options.persistence && this.modExists("persistence", true) && mod.persistence.config.sort || options.initialSort) && this.modExists("sort", true)) {
  5501. var sorters = [];
  5502. if (options.persistence && this.modExists("persistence", true) && mod.persistence.config.sort) {
  5503. sorters = mod.persistence.load("sort");
  5504. if (sorters === false && options.initialSort) {
  5505. sorters = options.initialSort;
  5506. }
  5507. } else if (options.initialSort) {
  5508. sorters = options.initialSort;
  5509. }
  5510. mod.sort.setSort(sorters);
  5511. }
  5512. if ((options.persistence && this.modExists("persistence", true) && mod.persistence.config.filter || options.initialFilter) && this.modExists("filter", true)) {
  5513. var filters = [];
  5514. if (options.persistence && this.modExists("persistence", true) && mod.persistence.config.filter) {
  5515. filters = mod.persistence.load("filter");
  5516. if (filters === false && options.initialFilter) {
  5517. filters = options.initialFilter;
  5518. }
  5519. } else if (options.initialFilter) {
  5520. filters = options.initialFilter;
  5521. }
  5522. mod.filter.setFilter(filters);
  5523. }
  5524. if (options.initialHeaderFilter && this.modExists("filter", true)) {
  5525. options.initialHeaderFilter.forEach(function (item) {
  5526. var column = _this24.columnManager.findColumn(item.field);
  5527. if (column) {
  5528. mod.filter.setHeaderFilterValue(column, item.value);
  5529. } else {
  5530. console.warn("Column Filter Error - No matching column found:", item.field);
  5531. return false;
  5532. }
  5533. });
  5534. }
  5535. if (this.modExists("ajax")) {
  5536. mod.ajax.initialize();
  5537. }
  5538. if (options.pagination && this.modExists("page", true)) {
  5539. mod.page.initialize();
  5540. }
  5541. if (options.groupBy && this.modExists("groupRows", true)) {
  5542. mod.groupRows.initialize();
  5543. }
  5544. if (this.modExists("keybindings")) {
  5545. mod.keybindings.initialize();
  5546. }
  5547. if (this.modExists("selectRow")) {
  5548. mod.selectRow.clearSelectionData(true);
  5549. }
  5550. if (options.autoResize && this.modExists("resizeTable")) {
  5551. mod.resizeTable.initialize();
  5552. }
  5553. if (this.modExists("clipboard")) {
  5554. mod.clipboard.initialize();
  5555. }
  5556. if (options.printAsHtml && this.modExists("print")) {
  5557. mod.print.initialize();
  5558. }
  5559. options.tableBuilt.call(this);
  5560. };
  5561. Tabulator.prototype._loadInitialData = function () {
  5562. var self = this;
  5563. if (self.options.pagination && self.modExists("page")) {
  5564. self.modules.page.reset(true, true);
  5565. if (self.options.pagination == "local") {
  5566. if (self.options.data.length) {
  5567. self.rowManager.setData(self.options.data, false, true);
  5568. } else {
  5569. if ((self.options.ajaxURL || self.options.ajaxURLGenerator) && self.modExists("ajax")) {
  5570. self.modules.ajax.loadData(false, true).then(function () {}).catch(function () {
  5571. if (self.options.paginationInitialPage) {
  5572. self.modules.page.setPage(self.options.paginationInitialPage);
  5573. }
  5574. });
  5575. return;
  5576. } else {
  5577. self.rowManager.setData(self.options.data, false, true);
  5578. }
  5579. }
  5580. if (self.options.paginationInitialPage) {
  5581. self.modules.page.setPage(self.options.paginationInitialPage);
  5582. }
  5583. } else {
  5584. if (self.options.ajaxURL) {
  5585. self.modules.page.setPage(self.options.paginationInitialPage).then(function () {}).catch(function () {});
  5586. } else {
  5587. self.rowManager.setData([], false, true);
  5588. }
  5589. }
  5590. } else {
  5591. if (self.options.data.length) {
  5592. self.rowManager.setData(self.options.data);
  5593. } else {
  5594. if ((self.options.ajaxURL || self.options.ajaxURLGenerator) && self.modExists("ajax")) {
  5595. self.modules.ajax.loadData(false, true).then(function () {}).catch(function () {});
  5596. } else {
  5597. self.rowManager.setData(self.options.data, false, true);
  5598. }
  5599. }
  5600. }
  5601. };
  5602. //deconstructor
  5603. Tabulator.prototype.destroy = function () {
  5604. var element = this.element;
  5605. Tabulator.prototype.comms.deregister(this); //deregister table from inderdevice communication
  5606. if (this.options.reactiveData && this.modExists("reactiveData", true)) {
  5607. this.modules.reactiveData.unwatchData();
  5608. }
  5609. //clear row data
  5610. this.rowManager.rows.forEach(function (row) {
  5611. row.wipe();
  5612. });
  5613. this.rowManager.rows = [];
  5614. this.rowManager.activeRows = [];
  5615. this.rowManager.displayRows = [];
  5616. //clear event bindings
  5617. if (this.options.autoResize && this.modExists("resizeTable")) {
  5618. this.modules.resizeTable.clearBindings();
  5619. }
  5620. if (this.modExists("keybindings")) {
  5621. this.modules.keybindings.clearBindings();
  5622. }
  5623. //clear DOM
  5624. while (element.firstChild) {
  5625. element.removeChild(element.firstChild);
  5626. }element.classList.remove("tabulator");
  5627. };
  5628. Tabulator.prototype._detectBrowser = function () {
  5629. var ua = navigator.userAgent || navigator.vendor || window.opera;
  5630. if (ua.indexOf("Trident") > -1) {
  5631. this.browser = "ie";
  5632. this.browserSlow = true;
  5633. } else if (ua.indexOf("Edge") > -1) {
  5634. this.browser = "edge";
  5635. this.browserSlow = true;
  5636. } else if (ua.indexOf("Firefox") > -1) {
  5637. this.browser = "firefox";
  5638. this.browserSlow = false;
  5639. } else {
  5640. this.browser = "other";
  5641. this.browserSlow = false;
  5642. }
  5643. 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));
  5644. };
  5645. ////////////////// Data Handling //////////////////
  5646. //block table redrawing
  5647. Tabulator.prototype.blockRedraw = function () {
  5648. return this.rowManager.blockRedraw();
  5649. };
  5650. //restore table redrawing
  5651. Tabulator.prototype.restoreRedraw = function () {
  5652. return this.rowManager.restoreRedraw();
  5653. };
  5654. //local data from local file
  5655. Tabulator.prototype.setDataFromLocalFile = function (extensions) {
  5656. var _this25 = this;
  5657. return new Promise(function (resolve, reject) {
  5658. var input = document.createElement("input");
  5659. input.type = "file";
  5660. input.accept = extensions || ".json,application/json";
  5661. input.addEventListener("change", function (e) {
  5662. var file = input.files[0],
  5663. reader = new FileReader(),
  5664. data;
  5665. reader.readAsText(file);
  5666. reader.onload = function (e) {
  5667. try {
  5668. data = JSON.parse(reader.result);
  5669. } catch (e) {
  5670. console.warn("File Load Error - File contents is invalid JSON", e);
  5671. reject(e);
  5672. return;
  5673. }
  5674. _this25.setData(data).then(function (data) {
  5675. resolve(data);
  5676. }).catch(function (err) {
  5677. resolve(err);
  5678. });
  5679. };
  5680. reader.onerror = function (e) {
  5681. console.warn("File Load Error - Unable to read file");
  5682. reject();
  5683. };
  5684. });
  5685. input.click();
  5686. });
  5687. };
  5688. //load data
  5689. Tabulator.prototype.setData = function (data, params, config) {
  5690. if (this.modExists("ajax")) {
  5691. this.modules.ajax.blockActiveRequest();
  5692. }
  5693. return this._setData(data, params, config, false, true);
  5694. };
  5695. Tabulator.prototype._setData = function (data, params, config, inPosition, columnsChanged) {
  5696. var self = this;
  5697. if (typeof data === "string") {
  5698. if (data.indexOf("{") == 0 || data.indexOf("[") == 0) {
  5699. //data is a json encoded string
  5700. return self.rowManager.setData(JSON.parse(data), inPosition, columnsChanged);
  5701. } else {
  5702. if (self.modExists("ajax", true)) {
  5703. if (params) {
  5704. self.modules.ajax.setParams(params);
  5705. }
  5706. if (config) {
  5707. self.modules.ajax.setConfig(config);
  5708. }
  5709. self.modules.ajax.setUrl(data);
  5710. if (self.options.pagination == "remote" && self.modExists("page", true)) {
  5711. self.modules.page.reset(true, true);
  5712. return self.modules.page.setPage(1);
  5713. } else {
  5714. //assume data is url, make ajax call to url to get data
  5715. return self.modules.ajax.loadData(inPosition, columnsChanged);
  5716. }
  5717. }
  5718. }
  5719. } else {
  5720. if (data) {
  5721. //asume data is already an object
  5722. return self.rowManager.setData(data, inPosition, columnsChanged);
  5723. } else {
  5724. //no data provided, check if ajaxURL is present;
  5725. if (self.modExists("ajax") && (self.modules.ajax.getUrl || self.options.ajaxURLGenerator)) {
  5726. if (self.options.pagination == "remote" && self.modExists("page", true)) {
  5727. self.modules.page.reset(true, true);
  5728. return self.modules.page.setPage(1);
  5729. } else {
  5730. return self.modules.ajax.loadData(inPosition, columnsChanged);
  5731. }
  5732. } else {
  5733. //empty data
  5734. return self.rowManager.setData([], inPosition, columnsChanged);
  5735. }
  5736. }
  5737. }
  5738. };
  5739. //clear data
  5740. Tabulator.prototype.clearData = function () {
  5741. if (this.modExists("ajax")) {
  5742. this.modules.ajax.blockActiveRequest();
  5743. }
  5744. this.rowManager.clearData();
  5745. };
  5746. //get table data array
  5747. Tabulator.prototype.getData = function (active) {
  5748. if (active === true) {
  5749. console.warn("passing a boolean to the getData function is deprecated, you should now pass the string 'active'");
  5750. active = "active";
  5751. }
  5752. return this.rowManager.getData(active);
  5753. };
  5754. //get table data array count
  5755. Tabulator.prototype.getDataCount = function (active) {
  5756. if (active === true) {
  5757. console.warn("passing a boolean to the getDataCount function is deprecated, you should now pass the string 'active'");
  5758. active = "active";
  5759. }
  5760. return this.rowManager.getDataCount(active);
  5761. };
  5762. //search for specific row components
  5763. Tabulator.prototype.searchRows = function (field, type, value) {
  5764. if (this.modExists("filter", true)) {
  5765. return this.modules.filter.search("rows", field, type, value);
  5766. }
  5767. };
  5768. //search for specific data
  5769. Tabulator.prototype.searchData = function (field, type, value) {
  5770. if (this.modExists("filter", true)) {
  5771. return this.modules.filter.search("data", field, type, value);
  5772. }
  5773. };
  5774. //get table html
  5775. Tabulator.prototype.getHtml = function (visible, style, config) {
  5776. if (this.modExists("export", true)) {
  5777. return this.modules.export.getHtml(visible, style, config);
  5778. }
  5779. };
  5780. //get print html
  5781. Tabulator.prototype.print = function (visible, style, config) {
  5782. if (this.modExists("print", true)) {
  5783. return this.modules.print.printFullscreen(visible, style, config);
  5784. }
  5785. };
  5786. //retrieve Ajax URL
  5787. Tabulator.prototype.getAjaxUrl = function () {
  5788. if (this.modExists("ajax", true)) {
  5789. return this.modules.ajax.getUrl();
  5790. }
  5791. };
  5792. //replace data, keeping table in position with same sort
  5793. Tabulator.prototype.replaceData = function (data, params, config) {
  5794. if (this.modExists("ajax")) {
  5795. this.modules.ajax.blockActiveRequest();
  5796. }
  5797. return this._setData(data, params, config, true);
  5798. };
  5799. //update table data
  5800. Tabulator.prototype.updateData = function (data) {
  5801. var _this26 = this;
  5802. var self = this;
  5803. var responses = 0;
  5804. return new Promise(function (resolve, reject) {
  5805. if (_this26.modExists("ajax")) {
  5806. _this26.modules.ajax.blockActiveRequest();
  5807. }
  5808. if (typeof data === "string") {
  5809. data = JSON.parse(data);
  5810. }
  5811. if (data) {
  5812. data.forEach(function (item) {
  5813. var row = self.rowManager.findRow(item[self.options.index]);
  5814. if (row) {
  5815. responses++;
  5816. row.updateData(item).then(function () {
  5817. responses--;
  5818. if (!responses) {
  5819. resolve();
  5820. }
  5821. });
  5822. }
  5823. });
  5824. } else {
  5825. console.warn("Update Error - No data provided");
  5826. reject("Update Error - No data provided");
  5827. }
  5828. });
  5829. };
  5830. Tabulator.prototype.addData = function (data, pos, index) {
  5831. var _this27 = this;
  5832. return new Promise(function (resolve, reject) {
  5833. if (_this27.modExists("ajax")) {
  5834. _this27.modules.ajax.blockActiveRequest();
  5835. }
  5836. if (typeof data === "string") {
  5837. data = JSON.parse(data);
  5838. }
  5839. if (data) {
  5840. _this27.rowManager.addRows(data, pos, index).then(function (rows) {
  5841. var output = [];
  5842. rows.forEach(function (row) {
  5843. output.push(row.getComponent());
  5844. });
  5845. resolve(output);
  5846. });
  5847. } else {
  5848. console.warn("Update Error - No data provided");
  5849. reject("Update Error - No data provided");
  5850. }
  5851. });
  5852. };
  5853. //update table data
  5854. Tabulator.prototype.updateOrAddData = function (data) {
  5855. var _this28 = this;
  5856. var self = this,
  5857. rows = [],
  5858. responses = 0;
  5859. return new Promise(function (resolve, reject) {
  5860. if (_this28.modExists("ajax")) {
  5861. _this28.modules.ajax.blockActiveRequest();
  5862. }
  5863. if (typeof data === "string") {
  5864. data = JSON.parse(data);
  5865. }
  5866. if (data) {
  5867. data.forEach(function (item) {
  5868. var row = self.rowManager.findRow(item[self.options.index]);
  5869. responses++;
  5870. if (row) {
  5871. row.updateData(item).then(function () {
  5872. responses--;
  5873. rows.push(row.getComponent());
  5874. if (!responses) {
  5875. resolve(rows);
  5876. }
  5877. });
  5878. } else {
  5879. self.rowManager.addRows(item).then(function (newRows) {
  5880. responses--;
  5881. rows.push(newRows[0].getComponent());
  5882. if (!responses) {
  5883. resolve(rows);
  5884. }
  5885. });
  5886. }
  5887. });
  5888. } else {
  5889. console.warn("Update Error - No data provided");
  5890. reject("Update Error - No data provided");
  5891. }
  5892. });
  5893. };
  5894. //get row object
  5895. Tabulator.prototype.getRow = function (index) {
  5896. var row = this.rowManager.findRow(index);
  5897. if (row) {
  5898. return row.getComponent();
  5899. } else {
  5900. console.warn("Find Error - No matching row found:", index);
  5901. return false;
  5902. }
  5903. };
  5904. //get row object
  5905. Tabulator.prototype.getRowFromPosition = function (position, active) {
  5906. var row = this.rowManager.getRowFromPosition(position, active);
  5907. if (row) {
  5908. return row.getComponent();
  5909. } else {
  5910. console.warn("Find Error - No matching row found:", position);
  5911. return false;
  5912. }
  5913. };
  5914. //delete row from table
  5915. Tabulator.prototype.deleteRow = function (index) {
  5916. var _this29 = this;
  5917. return new Promise(function (resolve, reject) {
  5918. var self = _this29,
  5919. count = 0,
  5920. successCount = 0,
  5921. foundRows = [];
  5922. function doneCheck() {
  5923. count++;
  5924. if (count == index.length) {
  5925. if (successCount) {
  5926. self.rowManager.reRenderInPosition();
  5927. resolve();
  5928. }
  5929. }
  5930. }
  5931. if (!Array.isArray(index)) {
  5932. index = [index];
  5933. }
  5934. //find matching rows
  5935. index.forEach(function (item) {
  5936. var row = _this29.rowManager.findRow(item, true);
  5937. if (row) {
  5938. foundRows.push(row);
  5939. } else {
  5940. console.warn("Delete Error - No matching row found:", item);
  5941. reject("Delete Error - No matching row found");
  5942. doneCheck();
  5943. }
  5944. });
  5945. //sort rows into correct order to ensure smooth delete from table
  5946. foundRows.sort(function (a, b) {
  5947. return _this29.rowManager.rows.indexOf(a) > _this29.rowManager.rows.indexOf(b) ? 1 : -1;
  5948. });
  5949. foundRows.forEach(function (row) {
  5950. row.delete().then(function () {
  5951. successCount++;
  5952. doneCheck();
  5953. }).catch(function (err) {
  5954. doneCheck();
  5955. reject(err);
  5956. });
  5957. });
  5958. });
  5959. };
  5960. //add row to table
  5961. Tabulator.prototype.addRow = function (data, pos, index) {
  5962. var _this30 = this;
  5963. return new Promise(function (resolve, reject) {
  5964. if (typeof data === "string") {
  5965. data = JSON.parse(data);
  5966. }
  5967. _this30.rowManager.addRows(data, pos, index).then(function (rows) {
  5968. //recalc column calculations if present
  5969. if (_this30.modExists("columnCalcs")) {
  5970. _this30.modules.columnCalcs.recalc(_this30.rowManager.activeRows);
  5971. }
  5972. resolve(rows[0].getComponent());
  5973. });
  5974. });
  5975. };
  5976. //update a row if it exitsts otherwise create it
  5977. Tabulator.prototype.updateOrAddRow = function (index, data) {
  5978. var _this31 = this;
  5979. return new Promise(function (resolve, reject) {
  5980. var row = _this31.rowManager.findRow(index);
  5981. if (typeof data === "string") {
  5982. data = JSON.parse(data);
  5983. }
  5984. if (row) {
  5985. row.updateData(data).then(function () {
  5986. //recalc column calculations if present
  5987. if (_this31.modExists("columnCalcs")) {
  5988. _this31.modules.columnCalcs.recalc(_this31.rowManager.activeRows);
  5989. }
  5990. resolve(row.getComponent());
  5991. }).catch(function (err) {
  5992. reject(err);
  5993. });
  5994. } else {
  5995. row = _this31.rowManager.addRows(data).then(function (rows) {
  5996. //recalc column calculations if present
  5997. if (_this31.modExists("columnCalcs")) {
  5998. _this31.modules.columnCalcs.recalc(_this31.rowManager.activeRows);
  5999. }
  6000. resolve(rows[0].getComponent());
  6001. }).catch(function (err) {
  6002. reject(err);
  6003. });
  6004. }
  6005. });
  6006. };
  6007. //update row data
  6008. Tabulator.prototype.updateRow = function (index, data) {
  6009. var _this32 = this;
  6010. return new Promise(function (resolve, reject) {
  6011. var row = _this32.rowManager.findRow(index);
  6012. if (typeof data === "string") {
  6013. data = JSON.parse(data);
  6014. }
  6015. if (row) {
  6016. row.updateData(data).then(function () {
  6017. resolve(row.getComponent());
  6018. }).catch(function (err) {
  6019. reject(err);
  6020. });
  6021. } else {
  6022. console.warn("Update Error - No matching row found:", index);
  6023. reject("Update Error - No matching row found");
  6024. }
  6025. });
  6026. };
  6027. //scroll to row in DOM
  6028. Tabulator.prototype.scrollToRow = function (index, position, ifVisible) {
  6029. var _this33 = this;
  6030. return new Promise(function (resolve, reject) {
  6031. var row = _this33.rowManager.findRow(index);
  6032. if (row) {
  6033. _this33.rowManager.scrollToRow(row, position, ifVisible).then(function () {
  6034. resolve();
  6035. }).catch(function (err) {
  6036. reject(err);
  6037. });
  6038. } else {
  6039. console.warn("Scroll Error - No matching row found:", index);
  6040. reject("Scroll Error - No matching row found");
  6041. }
  6042. });
  6043. };
  6044. Tabulator.prototype.moveRow = function (from, to, after) {
  6045. var fromRow = this.rowManager.findRow(from);
  6046. if (fromRow) {
  6047. fromRow.moveToRow(to, after);
  6048. } else {
  6049. console.warn("Move Error - No matching row found:", from);
  6050. }
  6051. };
  6052. Tabulator.prototype.getRows = function (active) {
  6053. if (active === true) {
  6054. console.warn("passing a boolean to the getRows function is deprecated, you should now pass the string 'active'");
  6055. active = "active";
  6056. }
  6057. return this.rowManager.getComponents(active);
  6058. };
  6059. //get position of row in table
  6060. Tabulator.prototype.getRowPosition = function (index, active) {
  6061. var row = this.rowManager.findRow(index);
  6062. if (row) {
  6063. return this.rowManager.getRowPosition(row, active);
  6064. } else {
  6065. console.warn("Position Error - No matching row found:", index);
  6066. return false;
  6067. }
  6068. };
  6069. //copy table data to clipboard
  6070. Tabulator.prototype.copyToClipboard = function (selector) {
  6071. if (this.modExists("clipboard", true)) {
  6072. this.modules.clipboard.copy(selector);
  6073. }
  6074. };
  6075. /////////////// Column Functions ///////////////
  6076. Tabulator.prototype.setColumns = function (definition) {
  6077. this.columnManager.setColumns(definition);
  6078. };
  6079. Tabulator.prototype.getColumns = function (structured) {
  6080. return this.columnManager.getComponents(structured);
  6081. };
  6082. Tabulator.prototype.getColumn = function (field) {
  6083. var col = this.columnManager.findColumn(field);
  6084. if (col) {
  6085. return col.getComponent();
  6086. } else {
  6087. console.warn("Find Error - No matching column found:", field);
  6088. return false;
  6089. }
  6090. };
  6091. Tabulator.prototype.getColumnDefinitions = function () {
  6092. return this.columnManager.getDefinitionTree();
  6093. };
  6094. Tabulator.prototype.getColumnLayout = function () {
  6095. if (this.modExists("persistence", true)) {
  6096. return this.modules.persistence.parseColumns(this.columnManager.getColumns());
  6097. }
  6098. };
  6099. Tabulator.prototype.setColumnLayout = function (layout) {
  6100. if (this.modExists("persistence", true)) {
  6101. this.columnManager.setColumns(this.modules.persistence.mergeDefinition(this.options.columns, layout));
  6102. return true;
  6103. }
  6104. return false;
  6105. };
  6106. Tabulator.prototype.showColumn = function (field) {
  6107. var column = this.columnManager.findColumn(field);
  6108. if (column) {
  6109. column.show();
  6110. if (this.options.responsiveLayout && this.modExists("responsiveLayout", true)) {
  6111. this.modules.responsiveLayout.update();
  6112. }
  6113. } else {
  6114. console.warn("Column Show Error - No matching column found:", field);
  6115. return false;
  6116. }
  6117. };
  6118. Tabulator.prototype.hideColumn = function (field) {
  6119. var column = this.columnManager.findColumn(field);
  6120. if (column) {
  6121. column.hide();
  6122. if (this.options.responsiveLayout && this.modExists("responsiveLayout", true)) {
  6123. this.modules.responsiveLayout.update();
  6124. }
  6125. } else {
  6126. console.warn("Column Hide Error - No matching column found:", field);
  6127. return false;
  6128. }
  6129. };
  6130. Tabulator.prototype.toggleColumn = function (field) {
  6131. var column = this.columnManager.findColumn(field);
  6132. if (column) {
  6133. if (column.visible) {
  6134. column.hide();
  6135. } else {
  6136. column.show();
  6137. }
  6138. } else {
  6139. console.warn("Column Visibility Toggle Error - No matching column found:", field);
  6140. return false;
  6141. }
  6142. };
  6143. Tabulator.prototype.addColumn = function (definition, before, field) {
  6144. var _this34 = this;
  6145. return new Promise(function (resolve, reject) {
  6146. var column = _this34.columnManager.findColumn(field);
  6147. _this34.columnManager.addColumn(definition, before, column).then(function (column) {
  6148. resolve(column.getComponent());
  6149. }).catch(function (err) {
  6150. reject(err);
  6151. });
  6152. });
  6153. };
  6154. Tabulator.prototype.deleteColumn = function (field) {
  6155. var _this35 = this;
  6156. return new Promise(function (resolve, reject) {
  6157. var column = _this35.columnManager.findColumn(field);
  6158. if (column) {
  6159. column.delete().then(function () {
  6160. resolve();
  6161. }).catch(function (err) {
  6162. reject(err);
  6163. });
  6164. } else {
  6165. console.warn("Column Delete Error - No matching column found:", field);
  6166. reject();
  6167. }
  6168. });
  6169. };
  6170. Tabulator.prototype.updateColumnDefinition = function (field, definition) {
  6171. var _this36 = this;
  6172. return new Promise(function (resolve, reject) {
  6173. var column = _this36.columnManager.findColumn(field);
  6174. if (column) {
  6175. column.updateDefinition(definition).then(function (col) {
  6176. resolve(col);
  6177. }).catch(function (err) {
  6178. reject(err);
  6179. });
  6180. } else {
  6181. console.warn("Column Update Error - No matching column found:", field);
  6182. reject();
  6183. }
  6184. });
  6185. };
  6186. Tabulator.prototype.moveColumn = function (from, to, after) {
  6187. var fromColumn = this.columnManager.findColumn(from);
  6188. var toColumn = this.columnManager.findColumn(to);
  6189. if (fromColumn) {
  6190. if (toColumn) {
  6191. this.columnManager.moveColumn(fromColumn, toColumn, after);
  6192. } else {
  6193. console.warn("Move Error - No matching column found:", toColumn);
  6194. }
  6195. } else {
  6196. console.warn("Move Error - No matching column found:", from);
  6197. }
  6198. };
  6199. //scroll to column in DOM
  6200. Tabulator.prototype.scrollToColumn = function (field, position, ifVisible) {
  6201. var _this37 = this;
  6202. return new Promise(function (resolve, reject) {
  6203. var column = _this37.columnManager.findColumn(field);
  6204. if (column) {
  6205. _this37.columnManager.scrollToColumn(column, position, ifVisible).then(function () {
  6206. resolve();
  6207. }).catch(function (err) {
  6208. reject(err);
  6209. });
  6210. } else {
  6211. console.warn("Scroll Error - No matching column found:", field);
  6212. reject("Scroll Error - No matching column found");
  6213. }
  6214. });
  6215. };
  6216. //////////// Localization Functions ////////////
  6217. Tabulator.prototype.setLocale = function (locale) {
  6218. this.modules.localize.setLocale(locale);
  6219. };
  6220. Tabulator.prototype.getLocale = function () {
  6221. return this.modules.localize.getLocale();
  6222. };
  6223. Tabulator.prototype.getLang = function (locale) {
  6224. return this.modules.localize.getLang(locale);
  6225. };
  6226. //////////// General Public Functions ////////////
  6227. //redraw list without updating data
  6228. Tabulator.prototype.redraw = function (force) {
  6229. this.columnManager.redraw(force);
  6230. this.rowManager.redraw(force);
  6231. };
  6232. Tabulator.prototype.setHeight = function (height) {
  6233. if (this.rowManager.renderMode !== "classic") {
  6234. this.options.height = isNaN(height) ? height : height + "px";
  6235. this.element.style.height = this.options.height;
  6236. this.rowManager.setRenderMode();
  6237. this.rowManager.redraw();
  6238. } else {
  6239. console.warn("setHeight function is not available in classic render mode");
  6240. }
  6241. };
  6242. ///////////////////// Sorting ////////////////////
  6243. //trigger sort
  6244. Tabulator.prototype.setSort = function (sortList, dir) {
  6245. if (this.modExists("sort", true)) {
  6246. this.modules.sort.setSort(sortList, dir);
  6247. this.rowManager.sorterRefresh();
  6248. }
  6249. };
  6250. Tabulator.prototype.getSorters = function () {
  6251. if (this.modExists("sort", true)) {
  6252. return this.modules.sort.getSort();
  6253. }
  6254. };
  6255. Tabulator.prototype.clearSort = function () {
  6256. if (this.modExists("sort", true)) {
  6257. this.modules.sort.clear();
  6258. this.rowManager.sorterRefresh();
  6259. }
  6260. };
  6261. ///////////////////// Filtering ////////////////////
  6262. //set standard filters
  6263. Tabulator.prototype.setFilter = function (field, type, value, params) {
  6264. if (this.modExists("filter", true)) {
  6265. this.modules.filter.setFilter(field, type, value, params);
  6266. this.rowManager.filterRefresh();
  6267. }
  6268. };
  6269. //add filter to array
  6270. Tabulator.prototype.addFilter = function (field, type, value, params) {
  6271. if (this.modExists("filter", true)) {
  6272. this.modules.filter.addFilter(field, type, value, params);
  6273. this.rowManager.filterRefresh();
  6274. }
  6275. };
  6276. //get all filters
  6277. Tabulator.prototype.getFilters = function (all) {
  6278. if (this.modExists("filter", true)) {
  6279. return this.modules.filter.getFilters(all);
  6280. }
  6281. };
  6282. Tabulator.prototype.setHeaderFilterFocus = function (field) {
  6283. if (this.modExists("filter", true)) {
  6284. var column = this.columnManager.findColumn(field);
  6285. if (column) {
  6286. this.modules.filter.setHeaderFilterFocus(column);
  6287. } else {
  6288. console.warn("Column Filter Focus Error - No matching column found:", field);
  6289. return false;
  6290. }
  6291. }
  6292. };
  6293. Tabulator.prototype.getHeaderFilterValue = function (field) {
  6294. if (this.modExists("filter", true)) {
  6295. var column = this.columnManager.findColumn(field);
  6296. if (column) {
  6297. return this.modules.filter.getHeaderFilterValue(column);
  6298. } else {
  6299. console.warn("Column Filter Error - No matching column found:", field);
  6300. }
  6301. }
  6302. };
  6303. Tabulator.prototype.setHeaderFilterValue = function (field, value) {
  6304. if (this.modExists("filter", true)) {
  6305. var column = this.columnManager.findColumn(field);
  6306. if (column) {
  6307. this.modules.filter.setHeaderFilterValue(column, value);
  6308. } else {
  6309. console.warn("Column Filter Error - No matching column found:", field);
  6310. return false;
  6311. }
  6312. }
  6313. };
  6314. Tabulator.prototype.getHeaderFilters = function () {
  6315. if (this.modExists("filter", true)) {
  6316. return this.modules.filter.getHeaderFilters();
  6317. }
  6318. };
  6319. //remove filter from array
  6320. Tabulator.prototype.removeFilter = function (field, type, value) {
  6321. if (this.modExists("filter", true)) {
  6322. this.modules.filter.removeFilter(field, type, value);
  6323. this.rowManager.filterRefresh();
  6324. }
  6325. };
  6326. //clear filters
  6327. Tabulator.prototype.clearFilter = function (all) {
  6328. if (this.modExists("filter", true)) {
  6329. this.modules.filter.clearFilter(all);
  6330. this.rowManager.filterRefresh();
  6331. }
  6332. };
  6333. //clear header filters
  6334. Tabulator.prototype.clearHeaderFilter = function () {
  6335. if (this.modExists("filter", true)) {
  6336. this.modules.filter.clearHeaderFilter();
  6337. this.rowManager.filterRefresh();
  6338. }
  6339. };
  6340. ///////////////////// select ////////////////////
  6341. Tabulator.prototype.selectRow = function (rows) {
  6342. if (this.modExists("selectRow", true)) {
  6343. if (rows === true) {
  6344. console.warn("passing a boolean to the selectRowselectRow function is deprecated, you should now pass the string 'active'");
  6345. rows = "active";
  6346. }
  6347. this.modules.selectRow.selectRows(rows);
  6348. }
  6349. };
  6350. Tabulator.prototype.deselectRow = function (rows) {
  6351. if (this.modExists("selectRow", true)) {
  6352. this.modules.selectRow.deselectRows(rows);
  6353. }
  6354. };
  6355. Tabulator.prototype.toggleSelectRow = function (row) {
  6356. if (this.modExists("selectRow", true)) {
  6357. this.modules.selectRow.toggleRow(row);
  6358. }
  6359. };
  6360. Tabulator.prototype.getSelectedRows = function () {
  6361. if (this.modExists("selectRow", true)) {
  6362. return this.modules.selectRow.getSelectedRows();
  6363. }
  6364. };
  6365. Tabulator.prototype.getSelectedData = function () {
  6366. if (this.modExists("selectRow", true)) {
  6367. return this.modules.selectRow.getSelectedData();
  6368. }
  6369. };
  6370. ///////////////////// validation ////////////////////
  6371. Tabulator.prototype.getInvalidCells = function () {
  6372. if (this.modExists("validate", true)) {
  6373. return this.modules.validate.getInvalidCells();
  6374. }
  6375. };
  6376. Tabulator.prototype.clearCellValidation = function (cells) {
  6377. var _this38 = this;
  6378. if (this.modExists("validate", true)) {
  6379. if (!cells) {
  6380. cells = this.modules.validate.getInvalidCells();
  6381. }
  6382. if (!Array.isArray(cells)) {
  6383. cells = [cells];
  6384. }
  6385. cells.forEach(function (cell) {
  6386. _this38.modules.validate.clearValidation(cell._getSelf());
  6387. });
  6388. }
  6389. };
  6390. Tabulator.prototype.validate = function (cells) {
  6391. var output = [];
  6392. //clear row data
  6393. this.rowManager.rows.forEach(function (row) {
  6394. var valid = row.validate();
  6395. if (valid !== true) {
  6396. output = output.concat(valid);
  6397. }
  6398. });
  6399. return output.length ? output : true;
  6400. };
  6401. //////////// Pagination Functions ////////////
  6402. Tabulator.prototype.setMaxPage = function (max) {
  6403. if (this.options.pagination && this.modExists("page")) {
  6404. this.modules.page.setMaxPage(max);
  6405. } else {
  6406. return false;
  6407. }
  6408. };
  6409. Tabulator.prototype.setPage = function (page) {
  6410. if (this.options.pagination && this.modExists("page")) {
  6411. return this.modules.page.setPage(page);
  6412. } else {
  6413. return new Promise(function (resolve, reject) {
  6414. reject();
  6415. });
  6416. }
  6417. };
  6418. Tabulator.prototype.setPageToRow = function (row) {
  6419. var _this39 = this;
  6420. return new Promise(function (resolve, reject) {
  6421. if (_this39.options.pagination && _this39.modExists("page")) {
  6422. row = _this39.rowManager.findRow(row);
  6423. if (row) {
  6424. _this39.modules.page.setPageToRow(row).then(function () {
  6425. resolve();
  6426. }).catch(function () {
  6427. reject();
  6428. });
  6429. } else {
  6430. reject();
  6431. }
  6432. } else {
  6433. reject();
  6434. }
  6435. });
  6436. };
  6437. Tabulator.prototype.setPageSize = function (size) {
  6438. if (this.options.pagination && this.modExists("page")) {
  6439. this.modules.page.setPageSize(size);
  6440. this.modules.page.setPage(1).then(function () {}).catch(function () {});
  6441. } else {
  6442. return false;
  6443. }
  6444. };
  6445. Tabulator.prototype.getPageSize = function () {
  6446. if (this.options.pagination && this.modExists("page", true)) {
  6447. return this.modules.page.getPageSize();
  6448. }
  6449. };
  6450. Tabulator.prototype.previousPage = function () {
  6451. if (this.options.pagination && this.modExists("page")) {
  6452. this.modules.page.previousPage();
  6453. } else {
  6454. return false;
  6455. }
  6456. };
  6457. Tabulator.prototype.nextPage = function () {
  6458. if (this.options.pagination && this.modExists("page")) {
  6459. this.modules.page.nextPage();
  6460. } else {
  6461. return false;
  6462. }
  6463. };
  6464. Tabulator.prototype.getPage = function () {
  6465. if (this.options.pagination && this.modExists("page")) {
  6466. return this.modules.page.getPage();
  6467. } else {
  6468. return false;
  6469. }
  6470. };
  6471. Tabulator.prototype.getPageMax = function () {
  6472. if (this.options.pagination && this.modExists("page")) {
  6473. return this.modules.page.getPageMax();
  6474. } else {
  6475. return false;
  6476. }
  6477. };
  6478. ///////////////// Grouping Functions ///////////////
  6479. Tabulator.prototype.setGroupBy = function (groups) {
  6480. if (this.modExists("groupRows", true)) {
  6481. this.options.groupBy = groups;
  6482. this.modules.groupRows.initialize();
  6483. this.rowManager.refreshActiveData("display");
  6484. if (this.options.persistence && this.modExists("persistence", true) && this.modules.persistence.config.group) {
  6485. this.modules.persistence.save("group");
  6486. }
  6487. } else {
  6488. return false;
  6489. }
  6490. };
  6491. Tabulator.prototype.setGroupValues = function (groupValues) {
  6492. if (this.modExists("groupRows", true)) {
  6493. this.options.groupValues = groupValues;
  6494. this.modules.groupRows.initialize();
  6495. this.rowManager.refreshActiveData("display");
  6496. if (this.options.persistence && this.modExists("persistence", true) && this.modules.persistence.config.group) {
  6497. this.modules.persistence.save("group");
  6498. }
  6499. } else {
  6500. return false;
  6501. }
  6502. };
  6503. Tabulator.prototype.setGroupStartOpen = function (values) {
  6504. if (this.modExists("groupRows", true)) {
  6505. this.options.groupStartOpen = values;
  6506. this.modules.groupRows.initialize();
  6507. if (this.options.groupBy) {
  6508. this.rowManager.refreshActiveData("group");
  6509. if (this.options.persistence && this.modExists("persistence", true) && this.modules.persistence.config.group) {
  6510. this.modules.persistence.save("group");
  6511. }
  6512. } else {
  6513. console.warn("Grouping Update - cant refresh view, no groups have been set");
  6514. }
  6515. } else {
  6516. return false;
  6517. }
  6518. };
  6519. Tabulator.prototype.setGroupHeader = function (values) {
  6520. if (this.modExists("groupRows", true)) {
  6521. this.options.groupHeader = values;
  6522. this.modules.groupRows.initialize();
  6523. if (this.options.groupBy) {
  6524. this.rowManager.refreshActiveData("group");
  6525. if (this.options.persistence && this.modExists("persistence", true) && this.modules.persistence.config.group) {
  6526. this.modules.persistence.save("group");
  6527. }
  6528. } else {
  6529. console.warn("Grouping Update - cant refresh view, no groups have been set");
  6530. }
  6531. } else {
  6532. return false;
  6533. }
  6534. };
  6535. Tabulator.prototype.getGroups = function (values) {
  6536. if (this.modExists("groupRows", true)) {
  6537. return this.modules.groupRows.getGroups(true);
  6538. } else {
  6539. return false;
  6540. }
  6541. };
  6542. // get grouped table data in the same format as getData()
  6543. Tabulator.prototype.getGroupedData = function () {
  6544. if (this.modExists("groupRows", true)) {
  6545. return this.options.groupBy ? this.modules.groupRows.getGroupedData() : this.getData();
  6546. }
  6547. };
  6548. Tabulator.prototype.getEditedCells = function () {
  6549. if (this.modExists("edit", true)) {
  6550. return this.modules.edit.getEditedCells();
  6551. }
  6552. };
  6553. Tabulator.prototype.clearCellEdited = function (cells) {
  6554. var _this40 = this;
  6555. if (this.modExists("edit", true)) {
  6556. if (!cells) {
  6557. cells = this.modules.edit.getEditedCells();
  6558. }
  6559. if (!Array.isArray(cells)) {
  6560. cells = [cells];
  6561. }
  6562. cells.forEach(function (cell) {
  6563. _this40.modules.edit.clearEdited(cell._getSelf());
  6564. });
  6565. }
  6566. };
  6567. ///////////////// Column Calculation Functions ///////////////
  6568. Tabulator.prototype.getCalcResults = function () {
  6569. if (this.modExists("columnCalcs", true)) {
  6570. return this.modules.columnCalcs.getResults();
  6571. } else {
  6572. return false;
  6573. }
  6574. };
  6575. Tabulator.prototype.recalc = function () {
  6576. if (this.modExists("columnCalcs", true)) {
  6577. this.modules.columnCalcs.recalcAll(this.rowManager.activeRows);
  6578. }
  6579. };
  6580. /////////////// Navigation Management //////////////
  6581. Tabulator.prototype.navigatePrev = function () {
  6582. var cell = false;
  6583. if (this.modExists("edit", true)) {
  6584. cell = this.modules.edit.currentCell;
  6585. if (cell) {
  6586. return cell.nav().prev();
  6587. }
  6588. }
  6589. return false;
  6590. };
  6591. Tabulator.prototype.navigateNext = function () {
  6592. var cell = false;
  6593. if (this.modExists("edit", true)) {
  6594. cell = this.modules.edit.currentCell;
  6595. if (cell) {
  6596. return cell.nav().next();
  6597. }
  6598. }
  6599. return false;
  6600. };
  6601. Tabulator.prototype.navigateLeft = function () {
  6602. var cell = false;
  6603. if (this.modExists("edit", true)) {
  6604. cell = this.modules.edit.currentCell;
  6605. if (cell) {
  6606. e.preventDefault();
  6607. return cell.nav().left();
  6608. }
  6609. }
  6610. return false;
  6611. };
  6612. Tabulator.prototype.navigateRight = function () {
  6613. var cell = false;
  6614. if (this.modExists("edit", true)) {
  6615. cell = this.modules.edit.currentCell;
  6616. if (cell) {
  6617. e.preventDefault();
  6618. return cell.nav().right();
  6619. }
  6620. }
  6621. return false;
  6622. };
  6623. Tabulator.prototype.navigateUp = function () {
  6624. var cell = false;
  6625. if (this.modExists("edit", true)) {
  6626. cell = this.modules.edit.currentCell;
  6627. if (cell) {
  6628. e.preventDefault();
  6629. return cell.nav().up();
  6630. }
  6631. }
  6632. return false;
  6633. };
  6634. Tabulator.prototype.navigateDown = function () {
  6635. var cell = false;
  6636. if (this.modExists("edit", true)) {
  6637. cell = this.modules.edit.currentCell;
  6638. if (cell) {
  6639. e.preventDefault();
  6640. return cell.nav().down();
  6641. }
  6642. }
  6643. return false;
  6644. };
  6645. /////////////// History Management //////////////
  6646. Tabulator.prototype.undo = function () {
  6647. if (this.options.history && this.modExists("history", true)) {
  6648. return this.modules.history.undo();
  6649. } else {
  6650. return false;
  6651. }
  6652. };
  6653. Tabulator.prototype.redo = function () {
  6654. if (this.options.history && this.modExists("history", true)) {
  6655. return this.modules.history.redo();
  6656. } else {
  6657. return false;
  6658. }
  6659. };
  6660. Tabulator.prototype.getHistoryUndoSize = function () {
  6661. if (this.options.history && this.modExists("history", true)) {
  6662. return this.modules.history.getHistoryUndoSize();
  6663. } else {
  6664. return false;
  6665. }
  6666. };
  6667. Tabulator.prototype.getHistoryRedoSize = function () {
  6668. if (this.options.history && this.modExists("history", true)) {
  6669. return this.modules.history.getHistoryRedoSize();
  6670. } else {
  6671. return false;
  6672. }
  6673. };
  6674. /////////////// Download Management //////////////
  6675. Tabulator.prototype.download = function (type, filename, options, active) {
  6676. if (this.modExists("download", true)) {
  6677. this.modules.download.download(type, filename, options, active);
  6678. }
  6679. };
  6680. Tabulator.prototype.downloadToTab = function (type, filename, options, active) {
  6681. if (this.modExists("download", true)) {
  6682. this.modules.download.download(type, filename, options, active, true);
  6683. }
  6684. };
  6685. /////////// Inter Table Communications ///////////
  6686. Tabulator.prototype.tableComms = function (table, module, action, data) {
  6687. this.modules.comms.receive(table, module, action, data);
  6688. };
  6689. ////////////// Extension Management //////////////
  6690. //object to hold module
  6691. Tabulator.prototype.moduleBindings = {};
  6692. //extend module
  6693. Tabulator.prototype.extendModule = function (name, property, values) {
  6694. if (Tabulator.prototype.moduleBindings[name]) {
  6695. var source = Tabulator.prototype.moduleBindings[name].prototype[property];
  6696. if (source) {
  6697. if ((typeof values === 'undefined' ? 'undefined' : _typeof(values)) == "object") {
  6698. for (var key in values) {
  6699. source[key] = values[key];
  6700. }
  6701. } else {
  6702. console.warn("Module Error - Invalid value type, it must be an object");
  6703. }
  6704. } else {
  6705. console.warn("Module Error - property does not exist:", property);
  6706. }
  6707. } else {
  6708. console.warn("Module Error - module does not exist:", name);
  6709. }
  6710. };
  6711. //add module to tabulator
  6712. Tabulator.prototype.registerModule = function (name, module) {
  6713. var self = this;
  6714. Tabulator.prototype.moduleBindings[name] = module;
  6715. };
  6716. //ensure that module are bound to instantiated function
  6717. Tabulator.prototype.bindModules = function () {
  6718. this.modules = {};
  6719. for (var name in Tabulator.prototype.moduleBindings) {
  6720. this.modules[name] = new Tabulator.prototype.moduleBindings[name](this);
  6721. }
  6722. };
  6723. //Check for module
  6724. Tabulator.prototype.modExists = function (plugin, required) {
  6725. if (this.modules[plugin]) {
  6726. return true;
  6727. } else {
  6728. if (required) {
  6729. console.error("Tabulator Module Not Installed: " + plugin);
  6730. }
  6731. return false;
  6732. }
  6733. };
  6734. Tabulator.prototype.helpers = {
  6735. elVisible: function elVisible(el) {
  6736. return !(el.offsetWidth <= 0 && el.offsetHeight <= 0);
  6737. },
  6738. elOffset: function elOffset(el) {
  6739. var box = el.getBoundingClientRect();
  6740. return {
  6741. top: box.top + window.pageYOffset - document.documentElement.clientTop,
  6742. left: box.left + window.pageXOffset - document.documentElement.clientLeft
  6743. };
  6744. },
  6745. deepClone: function deepClone(obj) {
  6746. var clone = Object.assign(Array.isArray(obj) ? [] : {}, obj);
  6747. for (var i in obj) {
  6748. if (obj[i] != null && _typeof(obj[i]) === "object") {
  6749. if (obj[i] instanceof Date) {
  6750. clone[i] = new Date(obj[i]);
  6751. } else {
  6752. clone[i] = this.deepClone(obj[i]);
  6753. }
  6754. }
  6755. }
  6756. return clone;
  6757. }
  6758. };
  6759. Tabulator.prototype.comms = {
  6760. tables: [],
  6761. register: function register(table) {
  6762. Tabulator.prototype.comms.tables.push(table);
  6763. },
  6764. deregister: function deregister(table) {
  6765. var index = Tabulator.prototype.comms.tables.indexOf(table);
  6766. if (index > -1) {
  6767. Tabulator.prototype.comms.tables.splice(index, 1);
  6768. }
  6769. },
  6770. lookupTable: function lookupTable(query, silent) {
  6771. var results = [],
  6772. matches,
  6773. match;
  6774. if (typeof query === "string") {
  6775. matches = document.querySelectorAll(query);
  6776. if (matches.length) {
  6777. for (var i = 0; i < matches.length; i++) {
  6778. match = Tabulator.prototype.comms.matchElement(matches[i]);
  6779. if (match) {
  6780. results.push(match);
  6781. }
  6782. }
  6783. }
  6784. } else if (typeof HTMLElement !== "undefined" && query instanceof HTMLElement || query instanceof Tabulator) {
  6785. match = Tabulator.prototype.comms.matchElement(query);
  6786. if (match) {
  6787. results.push(match);
  6788. }
  6789. } else if (Array.isArray(query)) {
  6790. query.forEach(function (item) {
  6791. results = results.concat(Tabulator.prototype.comms.lookupTable(item));
  6792. });
  6793. } else {
  6794. if (!silent) {
  6795. console.warn("Table Connection Error - Invalid Selector", query);
  6796. }
  6797. }
  6798. return results;
  6799. },
  6800. matchElement: function matchElement(element) {
  6801. return Tabulator.prototype.comms.tables.find(function (table) {
  6802. return element instanceof Tabulator ? table === element : table.element === element;
  6803. });
  6804. }
  6805. };
  6806. Tabulator.prototype.findTable = function (query) {
  6807. var results = Tabulator.prototype.comms.lookupTable(query, true);
  6808. return Array.isArray(results) && !results.length ? false : results;
  6809. };
  6810. var Layout = function Layout(table) {
  6811. this.table = table;
  6812. this.mode = null;
  6813. };
  6814. //initialize layout system
  6815. Layout.prototype.initialize = function (layout) {
  6816. if (this.modes[layout]) {
  6817. this.mode = layout;
  6818. } else {
  6819. console.warn("Layout Error - invalid mode set, defaulting to 'fitData' : " + layout);
  6820. this.mode = 'fitData';
  6821. }
  6822. this.table.element.setAttribute("tabulator-layout", this.mode);
  6823. };
  6824. Layout.prototype.getMode = function () {
  6825. return this.mode;
  6826. };
  6827. //trigger table layout
  6828. Layout.prototype.layout = function () {
  6829. this.modes[this.mode].call(this, this.table.columnManager.columnsByIndex);
  6830. };
  6831. //layout render functions
  6832. Layout.prototype.modes = {
  6833. //resize columns to fit data they contain
  6834. "fitData": function fitData(columns) {
  6835. if (this.table.options.virtualDomHoz) {
  6836. this.table.vdomHoz.fitDataLayoutOverride();
  6837. } else {
  6838. columns.forEach(function (column) {
  6839. column.reinitializeWidth();
  6840. });
  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 and stretch row to fill table
  6847. "fitDataFill": function fitDataFill(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 they contain
  6856. "fitDataTable": function fitDataTable(columns) {
  6857. columns.forEach(function (column) {
  6858. column.reinitializeWidth();
  6859. });
  6860. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  6861. this.table.modules.responsiveLayout.update();
  6862. }
  6863. },
  6864. //resize columns to fit data the contain and stretch last column to fill table
  6865. "fitDataStretch": function fitDataStretch(columns) {
  6866. var _this41 = this;
  6867. var colsWidth = 0,
  6868. tableWidth = this.table.rowManager.element.clientWidth,
  6869. gap = 0,
  6870. lastCol = false;
  6871. columns.forEach(function (column, i) {
  6872. if (!column.widthFixed) {
  6873. column.reinitializeWidth();
  6874. }
  6875. if (_this41.table.options.responsiveLayout ? column.modules.responsive.visible : column.visible) {
  6876. lastCol = column;
  6877. }
  6878. if (column.visible) {
  6879. colsWidth += column.getWidth();
  6880. }
  6881. });
  6882. if (lastCol) {
  6883. gap = tableWidth - colsWidth + lastCol.getWidth();
  6884. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  6885. lastCol.setWidth(0);
  6886. this.table.modules.responsiveLayout.update();
  6887. }
  6888. if (gap > 0) {
  6889. lastCol.setWidth(gap);
  6890. } else {
  6891. lastCol.reinitializeWidth();
  6892. }
  6893. } else {
  6894. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  6895. this.table.modules.responsiveLayout.update();
  6896. }
  6897. }
  6898. },
  6899. //resize columns to fit
  6900. "fitColumns": function fitColumns(columns) {
  6901. var self = this;
  6902. var totalWidth = self.table.element.clientWidth; //table element width
  6903. var fixedWidth = 0; //total width of columns with a defined width
  6904. var flexWidth = 0; //total width available to flexible columns
  6905. var flexGrowUnits = 0; //total number of widthGrow blocks accross all columns
  6906. var flexColWidth = 0; //desired width of flexible columns
  6907. var flexColumns = []; //array of flexible width columns
  6908. var fixedShrinkColumns = []; //array of fixed width columns that can shrink
  6909. var flexShrinkUnits = 0; //total number of widthShrink blocks accross all columns
  6910. var overflowWidth = 0; //horizontal overflow width
  6911. var gapFill = 0; //number of pixels to be added to final column to close and half pixel gaps
  6912. function calcWidth(width) {
  6913. var colWidth;
  6914. if (typeof width == "string") {
  6915. if (width.indexOf("%") > -1) {
  6916. colWidth = totalWidth / 100 * parseInt(width);
  6917. } else {
  6918. colWidth = parseInt(width);
  6919. }
  6920. } else {
  6921. colWidth = width;
  6922. }
  6923. return colWidth;
  6924. }
  6925. //ensure columns resize to take up the correct amount of space
  6926. function scaleColumns(columns, freeSpace, colWidth, shrinkCols) {
  6927. var oversizeCols = [],
  6928. oversizeSpace = 0,
  6929. remainingSpace = 0,
  6930. nextColWidth = 0,
  6931. gap = 0,
  6932. changeUnits = 0,
  6933. undersizeCols = [];
  6934. function calcGrow(col) {
  6935. return colWidth * (col.column.definition.widthGrow || 1);
  6936. }
  6937. function calcShrink(col) {
  6938. return calcWidth(col.width) - colWidth * (col.column.definition.widthShrink || 0);
  6939. }
  6940. columns.forEach(function (col, i) {
  6941. var width = shrinkCols ? calcShrink(col) : calcGrow(col);
  6942. if (col.column.minWidth >= width) {
  6943. oversizeCols.push(col);
  6944. } else {
  6945. undersizeCols.push(col);
  6946. changeUnits += shrinkCols ? col.column.definition.widthShrink || 1 : col.column.definition.widthGrow || 1;
  6947. }
  6948. });
  6949. if (oversizeCols.length) {
  6950. oversizeCols.forEach(function (col) {
  6951. oversizeSpace += shrinkCols ? col.width - col.column.minWidth : col.column.minWidth;
  6952. col.width = col.column.minWidth;
  6953. });
  6954. remainingSpace = freeSpace - oversizeSpace;
  6955. nextColWidth = changeUnits ? Math.floor(remainingSpace / changeUnits) : remainingSpace;
  6956. gap = remainingSpace - nextColWidth * changeUnits;
  6957. gap += scaleColumns(undersizeCols, remainingSpace, nextColWidth, shrinkCols);
  6958. } else {
  6959. gap = changeUnits ? freeSpace - Math.floor(freeSpace / changeUnits) * changeUnits : freeSpace;
  6960. undersizeCols.forEach(function (column) {
  6961. column.width = shrinkCols ? calcShrink(column) : calcGrow(column);
  6962. });
  6963. }
  6964. return gap;
  6965. }
  6966. if (this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
  6967. this.table.modules.responsiveLayout.update();
  6968. }
  6969. //adjust for vertical scrollbar if present
  6970. if (this.table.rowManager.element.scrollHeight > this.table.rowManager.element.clientHeight) {
  6971. totalWidth -= this.table.rowManager.element.offsetWidth - this.table.rowManager.element.clientWidth;
  6972. }
  6973. columns.forEach(function (column) {
  6974. var width, minWidth, colWidth;
  6975. if (column.visible) {
  6976. width = column.definition.width;
  6977. minWidth = parseInt(column.minWidth);
  6978. if (width) {
  6979. colWidth = calcWidth(width);
  6980. fixedWidth += colWidth > minWidth ? colWidth : minWidth;
  6981. if (column.definition.widthShrink) {
  6982. fixedShrinkColumns.push({
  6983. column: column,
  6984. width: colWidth > minWidth ? colWidth : minWidth
  6985. });
  6986. flexShrinkUnits += column.definition.widthShrink;
  6987. }
  6988. } else {
  6989. flexColumns.push({
  6990. column: column,
  6991. width: 0
  6992. });
  6993. flexGrowUnits += column.definition.widthGrow || 1;
  6994. }
  6995. }
  6996. });
  6997. //calculate available space
  6998. flexWidth = totalWidth - fixedWidth;
  6999. //calculate correct column size
  7000. flexColWidth = Math.floor(flexWidth / flexGrowUnits);
  7001. //generate column widths
  7002. var gapFill = scaleColumns(flexColumns, flexWidth, flexColWidth, false);
  7003. //increase width of last column to account for rounding errors
  7004. if (flexColumns.length && gapFill > 0) {
  7005. flexColumns[flexColumns.length - 1].width += +gapFill;
  7006. }
  7007. //caculate space for columns to be shrunk into
  7008. flexColumns.forEach(function (col) {
  7009. flexWidth -= col.width;
  7010. });
  7011. overflowWidth = Math.abs(gapFill) + flexWidth;
  7012. //shrink oversize columns if there is no available space
  7013. if (overflowWidth > 0 && flexShrinkUnits) {
  7014. gapFill = scaleColumns(fixedShrinkColumns, overflowWidth, Math.floor(overflowWidth / flexShrinkUnits), true);
  7015. }
  7016. //decrease width of last column to account for rounding errors
  7017. if (fixedShrinkColumns.length) {
  7018. fixedShrinkColumns[fixedShrinkColumns.length - 1].width -= gapFill;
  7019. }
  7020. flexColumns.forEach(function (col) {
  7021. col.column.setWidth(col.width);
  7022. });
  7023. fixedShrinkColumns.forEach(function (col) {
  7024. col.column.setWidth(col.width);
  7025. });
  7026. }
  7027. };
  7028. Tabulator.prototype.registerModule("layout", Layout);
  7029. var Localize = function Localize(table) {
  7030. this.table = table; //hold Tabulator object
  7031. this.locale = "default"; //current locale
  7032. this.lang = false; //current language
  7033. this.bindings = {}; //update events to call when locale is changed
  7034. this.langList = {};
  7035. };
  7036. Localize.prototype.initialize = function () {
  7037. this.langList = Tabulator.prototype.helpers.deepClone(this.langs);
  7038. };
  7039. //set header placehoder
  7040. Localize.prototype.setHeaderFilterPlaceholder = function (placeholder) {
  7041. this.langList.default.headerFilters.default = placeholder;
  7042. };
  7043. //set header filter placeholder by column
  7044. Localize.prototype.setHeaderFilterColumnPlaceholder = function (column, placeholder) {
  7045. this.langList.default.headerFilters.columns[column] = placeholder;
  7046. if (this.lang && !this.lang.headerFilters.columns[column]) {
  7047. this.lang.headerFilters.columns[column] = placeholder;
  7048. }
  7049. };
  7050. //setup a lang description object
  7051. Localize.prototype.installLang = function (locale, lang) {
  7052. if (this.langList[locale]) {
  7053. this._setLangProp(this.langList[locale], lang);
  7054. } else {
  7055. this.langList[locale] = lang;
  7056. }
  7057. };
  7058. Localize.prototype._setLangProp = function (lang, values) {
  7059. for (var key in values) {
  7060. if (lang[key] && _typeof(lang[key]) == "object") {
  7061. this._setLangProp(lang[key], values[key]);
  7062. } else {
  7063. lang[key] = values[key];
  7064. }
  7065. }
  7066. };
  7067. //set current locale
  7068. Localize.prototype.setLocale = function (desiredLocale) {
  7069. var self = this;
  7070. desiredLocale = desiredLocale || "default";
  7071. //fill in any matching languge values
  7072. function traverseLang(trans, path) {
  7073. for (var prop in trans) {
  7074. if (_typeof(trans[prop]) == "object") {
  7075. if (!path[prop]) {
  7076. path[prop] = {};
  7077. }
  7078. traverseLang(trans[prop], path[prop]);
  7079. } else {
  7080. path[prop] = trans[prop];
  7081. }
  7082. }
  7083. }
  7084. //determing correct locale to load
  7085. if (desiredLocale === true && navigator.language) {
  7086. //get local from system
  7087. desiredLocale = navigator.language.toLowerCase();
  7088. }
  7089. if (desiredLocale) {
  7090. //if locale is not set, check for matching top level locale else use default
  7091. if (!self.langList[desiredLocale]) {
  7092. var prefix = desiredLocale.split("-")[0];
  7093. if (self.langList[prefix]) {
  7094. console.warn("Localization Error - Exact matching locale not found, using closest match: ", desiredLocale, prefix);
  7095. desiredLocale = prefix;
  7096. } else {
  7097. console.warn("Localization Error - Matching locale not found, using default: ", desiredLocale);
  7098. desiredLocale = "default";
  7099. }
  7100. }
  7101. }
  7102. self.locale = desiredLocale;
  7103. //load default lang template
  7104. self.lang = Tabulator.prototype.helpers.deepClone(self.langList.default || {});
  7105. if (desiredLocale != "default") {
  7106. traverseLang(self.langList[desiredLocale], self.lang);
  7107. }
  7108. self.table.options.localized.call(self.table, self.locale, self.lang);
  7109. self._executeBindings();
  7110. };
  7111. //get current locale
  7112. Localize.prototype.getLocale = function (locale) {
  7113. return self.locale;
  7114. };
  7115. //get lang object for given local or current if none provided
  7116. Localize.prototype.getLang = function (locale) {
  7117. return locale ? this.langList[locale] : this.lang;
  7118. };
  7119. //get text for current locale
  7120. Localize.prototype.getText = function (path, value) {
  7121. var path = value ? path + "|" + value : path,
  7122. pathArray = path.split("|"),
  7123. text = this._getLangElement(pathArray, this.locale);
  7124. // if(text === false){
  7125. // console.warn("Localization Error - Matching localized text not found for given path: ", path);
  7126. // }
  7127. return text || "";
  7128. };
  7129. //traverse langs object and find localized copy
  7130. Localize.prototype._getLangElement = function (path, locale) {
  7131. var self = this;
  7132. var root = self.lang;
  7133. path.forEach(function (level) {
  7134. var rootPath;
  7135. if (root) {
  7136. rootPath = root[level];
  7137. if (typeof rootPath != "undefined") {
  7138. root = rootPath;
  7139. } else {
  7140. root = false;
  7141. }
  7142. }
  7143. });
  7144. return root;
  7145. };
  7146. //set update binding
  7147. Localize.prototype.bind = function (path, callback) {
  7148. if (!this.bindings[path]) {
  7149. this.bindings[path] = [];
  7150. }
  7151. this.bindings[path].push(callback);
  7152. callback(this.getText(path), this.lang);
  7153. };
  7154. //itterate through bindings and trigger updates
  7155. Localize.prototype._executeBindings = function () {
  7156. var self = this;
  7157. var _loop = function _loop(path) {
  7158. self.bindings[path].forEach(function (binding) {
  7159. binding(self.getText(path), self.lang);
  7160. });
  7161. };
  7162. for (var path in self.bindings) {
  7163. _loop(path);
  7164. }
  7165. };
  7166. //Localized text listings
  7167. Localize.prototype.langs = {
  7168. "default": { //hold default locale text
  7169. "groups": {
  7170. "item": "item",
  7171. "items": "items"
  7172. },
  7173. "columns": {},
  7174. "ajax": {
  7175. "loading": "Loading",
  7176. "error": "Error"
  7177. },
  7178. "pagination": {
  7179. "page_size": "Page Size",
  7180. "page_title": "Show Page",
  7181. "first": "First",
  7182. "first_title": "First Page",
  7183. "last": "Last",
  7184. "last_title": "Last Page",
  7185. "prev": "Prev",
  7186. "prev_title": "Prev Page",
  7187. "next": "Next",
  7188. "next_title": "Next Page",
  7189. "all": "All"
  7190. },
  7191. "headerFilters": {
  7192. "default": "filter column...",
  7193. "columns": {}
  7194. }
  7195. }
  7196. };
  7197. Tabulator.prototype.registerModule("localize", Localize);
  7198. var Comms = function Comms(table) {
  7199. this.table = table;
  7200. };
  7201. Comms.prototype.getConnections = function (selectors) {
  7202. var self = this,
  7203. connections = [],
  7204. connection;
  7205. connection = Tabulator.prototype.comms.lookupTable(selectors);
  7206. connection.forEach(function (con) {
  7207. if (self.table !== con) {
  7208. connections.push(con);
  7209. }
  7210. });
  7211. return connections;
  7212. };
  7213. Comms.prototype.send = function (selectors, module, action, data) {
  7214. var self = this,
  7215. connections = this.getConnections(selectors);
  7216. connections.forEach(function (connection) {
  7217. connection.tableComms(self.table.element, module, action, data);
  7218. });
  7219. if (!connections.length && selectors) {
  7220. console.warn("Table Connection Error - No tables matching selector found", selectors);
  7221. }
  7222. };
  7223. Comms.prototype.receive = function (table, module, action, data) {
  7224. if (this.table.modExists(module)) {
  7225. return this.table.modules[module].commsReceived(table, action, data);
  7226. } else {
  7227. console.warn("Inter-table Comms Error - no such module:", module);
  7228. }
  7229. };
  7230. Tabulator.prototype.registerModule("comms", Comms);
  7231. var Accessor = function Accessor(table) {
  7232. this.table = table; //hold Tabulator object
  7233. this.allowedTypes = ["", "data", "download", "clipboard", "print", "htmlOutput"]; //list of accessor types
  7234. };
  7235. //initialize column accessor
  7236. Accessor.prototype.initializeColumn = function (column) {
  7237. var self = this,
  7238. match = false,
  7239. config = {};
  7240. this.allowedTypes.forEach(function (type) {
  7241. var key = "accessor" + (type.charAt(0).toUpperCase() + type.slice(1)),
  7242. accessor;
  7243. if (column.definition[key]) {
  7244. accessor = self.lookupAccessor(column.definition[key]);
  7245. if (accessor) {
  7246. match = true;
  7247. config[key] = {
  7248. accessor: accessor,
  7249. params: column.definition[key + "Params"] || {}
  7250. };
  7251. }
  7252. }
  7253. });
  7254. if (match) {
  7255. column.modules.accessor = config;
  7256. }
  7257. };
  7258. Accessor.prototype.lookupAccessor = function (value) {
  7259. var accessor = false;
  7260. //set column accessor
  7261. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  7262. case "string":
  7263. if (this.accessors[value]) {
  7264. accessor = this.accessors[value];
  7265. } else {
  7266. console.warn("Accessor Error - No such accessor found, ignoring: ", value);
  7267. }
  7268. break;
  7269. case "function":
  7270. accessor = value;
  7271. break;
  7272. }
  7273. return accessor;
  7274. };
  7275. //apply accessor to row
  7276. Accessor.prototype.transformRow = function (row, type) {
  7277. var key = "accessor" + (type.charAt(0).toUpperCase() + type.slice(1)),
  7278. rowComponent = row.getComponent();
  7279. //clone data object with deep copy to isolate internal data from returned result
  7280. var data = Tabulator.prototype.helpers.deepClone(row.data || {});
  7281. this.table.columnManager.traverse(function (column) {
  7282. var value, accessor, params, colCompnent;
  7283. if (column.modules.accessor) {
  7284. accessor = column.modules.accessor[key] || column.modules.accessor.accessor || false;
  7285. if (accessor) {
  7286. value = column.getFieldValue(data);
  7287. if (value != "undefined") {
  7288. colCompnent = column.getComponent();
  7289. params = typeof accessor.params === "function" ? accessor.params(value, data, type, colCompnent, rowComponent) : accessor.params;
  7290. column.setFieldValue(data, accessor.accessor(value, data, type, params, colCompnent, rowComponent));
  7291. }
  7292. }
  7293. }
  7294. });
  7295. return data;
  7296. },
  7297. //default accessors
  7298. Accessor.prototype.accessors = {};
  7299. Tabulator.prototype.registerModule("accessor", Accessor);
  7300. var Ajax = function Ajax(table) {
  7301. this.table = table; //hold Tabulator object
  7302. this.config = false; //hold config object for ajax request
  7303. this.url = ""; //request URL
  7304. this.urlGenerator = false;
  7305. this.params = false; //request parameters
  7306. this.loaderElement = this.createLoaderElement(); //loader message div
  7307. this.msgElement = this.createMsgElement(); //message element
  7308. this.loadingElement = false;
  7309. this.errorElement = false;
  7310. this.loaderPromise = false;
  7311. this.progressiveLoad = false;
  7312. this.loading = false;
  7313. this.requestOrder = 0; //prevent requests comming out of sequence if overridden by another load request
  7314. };
  7315. //initialize setup options
  7316. Ajax.prototype.initialize = function () {
  7317. var template;
  7318. this.loaderElement.appendChild(this.msgElement);
  7319. if (this.table.options.ajaxLoaderLoading) {
  7320. if (typeof this.table.options.ajaxLoaderLoading == "string") {
  7321. template = document.createElement('template');
  7322. template.innerHTML = this.table.options.ajaxLoaderLoading.trim();
  7323. this.loadingElement = template.content.firstChild;
  7324. } else {
  7325. this.loadingElement = this.table.options.ajaxLoaderLoading;
  7326. }
  7327. }
  7328. this.loaderPromise = this.table.options.ajaxRequestFunc || this.defaultLoaderPromise;
  7329. this.urlGenerator = this.table.options.ajaxURLGenerator || this.defaultURLGenerator;
  7330. if (this.table.options.ajaxLoaderError) {
  7331. if (typeof this.table.options.ajaxLoaderError == "string") {
  7332. template = document.createElement('template');
  7333. template.innerHTML = this.table.options.ajaxLoaderError.trim();
  7334. this.errorElement = template.content.firstChild;
  7335. } else {
  7336. this.errorElement = this.table.options.ajaxLoaderError;
  7337. }
  7338. }
  7339. if (this.table.options.ajaxParams) {
  7340. this.setParams(this.table.options.ajaxParams);
  7341. }
  7342. if (this.table.options.ajaxConfig) {
  7343. this.setConfig(this.table.options.ajaxConfig);
  7344. }
  7345. if (this.table.options.ajaxURL) {
  7346. this.setUrl(this.table.options.ajaxURL);
  7347. }
  7348. if (this.table.options.ajaxProgressiveLoad) {
  7349. if (this.table.options.pagination) {
  7350. this.progressiveLoad = false;
  7351. console.error("Progressive Load Error - Pagination and progressive load cannot be used at the same time");
  7352. } else {
  7353. if (this.table.modExists("page")) {
  7354. this.progressiveLoad = this.table.options.ajaxProgressiveLoad;
  7355. this.table.modules.page.initializeProgressive(this.progressiveLoad);
  7356. } else {
  7357. console.error("Pagination plugin is required for progressive ajax loading");
  7358. }
  7359. }
  7360. }
  7361. };
  7362. Ajax.prototype.createLoaderElement = function () {
  7363. var el = document.createElement("div");
  7364. el.classList.add("tabulator-loader");
  7365. return el;
  7366. };
  7367. Ajax.prototype.createMsgElement = function () {
  7368. var el = document.createElement("div");
  7369. el.classList.add("tabulator-loader-msg");
  7370. el.setAttribute("role", "alert");
  7371. return el;
  7372. };
  7373. //set ajax params
  7374. Ajax.prototype.setParams = function (params, update) {
  7375. if (update) {
  7376. this.params = this.params || {};
  7377. for (var key in params) {
  7378. this.params[key] = params[key];
  7379. }
  7380. } else {
  7381. this.params = params;
  7382. }
  7383. };
  7384. Ajax.prototype.getParams = function () {
  7385. return this.params || {};
  7386. };
  7387. //load config object
  7388. Ajax.prototype.setConfig = function (config) {
  7389. this._loadDefaultConfig();
  7390. if (typeof config == "string") {
  7391. this.config.method = config;
  7392. } else {
  7393. for (var key in config) {
  7394. this.config[key] = config[key];
  7395. }
  7396. }
  7397. };
  7398. //create config object from default
  7399. Ajax.prototype._loadDefaultConfig = function (force) {
  7400. var self = this;
  7401. if (!self.config || force) {
  7402. self.config = {};
  7403. //load base config from defaults
  7404. for (var key in self.defaultConfig) {
  7405. self.config[key] = self.defaultConfig[key];
  7406. }
  7407. }
  7408. };
  7409. //set request url
  7410. Ajax.prototype.setUrl = function (url) {
  7411. this.url = url;
  7412. };
  7413. //get request url
  7414. Ajax.prototype.getUrl = function () {
  7415. return this.url;
  7416. };
  7417. //lstandard loading function
  7418. Ajax.prototype.loadData = function (inPosition, columnsChanged) {
  7419. var self = this;
  7420. if (this.progressiveLoad) {
  7421. return this._loadDataProgressive();
  7422. } else {
  7423. return this._loadDataStandard(inPosition, columnsChanged);
  7424. }
  7425. };
  7426. Ajax.prototype.nextPage = function (diff) {
  7427. var margin;
  7428. if (!this.loading) {
  7429. margin = this.table.options.ajaxProgressiveLoadScrollMargin || this.table.rowManager.getElement().clientHeight * 2;
  7430. if (diff < margin) {
  7431. this.table.modules.page.nextPage().then(function () {}).catch(function () {});
  7432. }
  7433. }
  7434. };
  7435. Ajax.prototype.blockActiveRequest = function () {
  7436. this.requestOrder++;
  7437. };
  7438. Ajax.prototype._loadDataProgressive = function () {
  7439. this.table.rowManager.setData([]);
  7440. return this.table.modules.page.setPage(1);
  7441. };
  7442. Ajax.prototype._loadDataStandard = function (inPosition, columnsChanged) {
  7443. var _this42 = this;
  7444. return new Promise(function (resolve, reject) {
  7445. _this42.sendRequest(inPosition).then(function (data) {
  7446. _this42.table.rowManager.setData(data, inPosition, columnsChanged).then(function () {
  7447. resolve();
  7448. }).catch(function (e) {
  7449. reject(e);
  7450. });
  7451. }).catch(function (e) {
  7452. reject(e);
  7453. });
  7454. });
  7455. };
  7456. Ajax.prototype.generateParamsList = function (data, prefix) {
  7457. var self = this,
  7458. output = [];
  7459. prefix = prefix || "";
  7460. if (Array.isArray(data)) {
  7461. data.forEach(function (item, i) {
  7462. output = output.concat(self.generateParamsList(item, prefix ? prefix + "[" + i + "]" : i));
  7463. });
  7464. } else if ((typeof data === 'undefined' ? 'undefined' : _typeof(data)) === "object") {
  7465. for (var key in data) {
  7466. output = output.concat(self.generateParamsList(data[key], prefix ? prefix + "[" + key + "]" : key));
  7467. }
  7468. } else {
  7469. output.push({ key: prefix, value: data });
  7470. }
  7471. return output;
  7472. };
  7473. Ajax.prototype.serializeParams = function (params) {
  7474. var output = this.generateParamsList(params),
  7475. encoded = [];
  7476. output.forEach(function (item) {
  7477. encoded.push(encodeURIComponent(item.key) + "=" + encodeURIComponent(item.value));
  7478. });
  7479. return encoded.join("&");
  7480. };
  7481. //send ajax request
  7482. Ajax.prototype.sendRequest = function (silent) {
  7483. var _this43 = this;
  7484. var self = this,
  7485. url = self.url,
  7486. requestNo,
  7487. esc,
  7488. query;
  7489. self.requestOrder++;
  7490. requestNo = self.requestOrder;
  7491. self._loadDefaultConfig();
  7492. return new Promise(function (resolve, reject) {
  7493. if (self.table.options.ajaxRequesting.call(_this43.table, self.url, self.params) !== false) {
  7494. self.loading = true;
  7495. if (!silent) {
  7496. self.showLoader();
  7497. }
  7498. _this43.loaderPromise(url, self.config, self.params).then(function (data) {
  7499. if (requestNo === self.requestOrder) {
  7500. if (self.table.options.ajaxResponse) {
  7501. data = self.table.options.ajaxResponse.call(self.table, self.url, self.params, data);
  7502. }
  7503. resolve(data);
  7504. self.hideLoader();
  7505. self.loading = false;
  7506. } else {
  7507. console.warn("Ajax Response Blocked - An active ajax request was blocked by an attempt to change table data while the request was being made");
  7508. }
  7509. }).catch(function (error) {
  7510. console.error("Ajax Load Error: ", error);
  7511. self.table.options.ajaxError.call(self.table, error);
  7512. self.showError();
  7513. setTimeout(function () {
  7514. self.hideLoader();
  7515. }, 3000);
  7516. self.loading = false;
  7517. reject();
  7518. });
  7519. } else {
  7520. reject();
  7521. }
  7522. });
  7523. };
  7524. Ajax.prototype.showLoader = function () {
  7525. var shouldLoad = typeof this.table.options.ajaxLoader === "function" ? this.table.options.ajaxLoader() : this.table.options.ajaxLoader;
  7526. if (shouldLoad) {
  7527. this.hideLoader();
  7528. while (this.msgElement.firstChild) {
  7529. this.msgElement.removeChild(this.msgElement.firstChild);
  7530. }this.msgElement.classList.remove("tabulator-error");
  7531. this.msgElement.classList.add("tabulator-loading");
  7532. if (this.loadingElement) {
  7533. this.msgElement.appendChild(this.loadingElement);
  7534. } else {
  7535. this.msgElement.innerHTML = this.table.modules.localize.getText("ajax|loading");
  7536. }
  7537. this.table.element.appendChild(this.loaderElement);
  7538. }
  7539. };
  7540. Ajax.prototype.showError = function () {
  7541. this.hideLoader();
  7542. while (this.msgElement.firstChild) {
  7543. this.msgElement.removeChild(this.msgElement.firstChild);
  7544. }this.msgElement.classList.remove("tabulator-loading");
  7545. this.msgElement.classList.add("tabulator-error");
  7546. if (this.errorElement) {
  7547. this.msgElement.appendChild(this.errorElement);
  7548. } else {
  7549. this.msgElement.innerHTML = this.table.modules.localize.getText("ajax|error");
  7550. }
  7551. this.table.element.appendChild(this.loaderElement);
  7552. };
  7553. Ajax.prototype.hideLoader = function () {
  7554. if (this.loaderElement.parentNode) {
  7555. this.loaderElement.parentNode.removeChild(this.loaderElement);
  7556. }
  7557. };
  7558. //default ajax config object
  7559. Ajax.prototype.defaultConfig = {
  7560. method: "GET"
  7561. };
  7562. Ajax.prototype.defaultURLGenerator = function (url, config, params) {
  7563. if (url) {
  7564. if (params && Object.keys(params).length) {
  7565. if (!config.method || config.method.toLowerCase() == "get") {
  7566. config.method = "get";
  7567. url += (url.includes("?") ? "&" : "?") + this.serializeParams(params);
  7568. }
  7569. }
  7570. }
  7571. return url;
  7572. };
  7573. Ajax.prototype.defaultLoaderPromise = function (url, config, params) {
  7574. var self = this,
  7575. contentType;
  7576. return new Promise(function (resolve, reject) {
  7577. //set url
  7578. url = self.urlGenerator(url, config, params);
  7579. //set body content if not GET request
  7580. if (config.method.toUpperCase() != "GET") {
  7581. contentType = _typeof(self.table.options.ajaxContentType) === "object" ? self.table.options.ajaxContentType : self.contentTypeFormatters[self.table.options.ajaxContentType];
  7582. if (contentType) {
  7583. for (var key in contentType.headers) {
  7584. if (!config.headers) {
  7585. config.headers = {};
  7586. }
  7587. if (typeof config.headers[key] === "undefined") {
  7588. config.headers[key] = contentType.headers[key];
  7589. }
  7590. }
  7591. config.body = contentType.body.call(self, url, config, params);
  7592. } else {
  7593. console.warn("Ajax Error - Invalid ajaxContentType value:", self.table.options.ajaxContentType);
  7594. }
  7595. }
  7596. if (url) {
  7597. //configure headers
  7598. if (typeof config.headers === "undefined") {
  7599. config.headers = {};
  7600. }
  7601. if (typeof config.headers.Accept === "undefined") {
  7602. config.headers.Accept = "application/json";
  7603. }
  7604. if (typeof config.headers["X-Requested-With"] === "undefined") {
  7605. config.headers["X-Requested-With"] = "XMLHttpRequest";
  7606. }
  7607. if (typeof config.mode === "undefined") {
  7608. config.mode = "cors";
  7609. }
  7610. if (config.mode == "cors") {
  7611. if (typeof config.headers["Access-Control-Allow-Origin"] === "undefined") {
  7612. config.headers["Access-Control-Allow-Origin"] = window.location.origin;
  7613. }
  7614. if (typeof config.credentials === "undefined") {
  7615. config.credentials = 'same-origin';
  7616. }
  7617. } else {
  7618. if (typeof config.credentials === "undefined") {
  7619. config.credentials = 'include';
  7620. }
  7621. }
  7622. //send request
  7623. fetch(url, config).then(function (response) {
  7624. if (response.ok) {
  7625. response.json().then(function (data) {
  7626. resolve(data);
  7627. }).catch(function (error) {
  7628. reject(error);
  7629. console.warn("Ajax Load Error - Invalid JSON returned", error);
  7630. });
  7631. } else {
  7632. console.error("Ajax Load Error - Connection Error: " + response.status, response.statusText);
  7633. reject(response);
  7634. }
  7635. }).catch(function (error) {
  7636. console.error("Ajax Load Error - Connection Error: ", error);
  7637. reject(error);
  7638. });
  7639. } else {
  7640. console.warn("Ajax Load Error - No URL Set");
  7641. resolve([]);
  7642. }
  7643. });
  7644. };
  7645. Ajax.prototype.contentTypeFormatters = {
  7646. "json": {
  7647. headers: {
  7648. 'Content-Type': 'application/json'
  7649. },
  7650. body: function body(url, config, params) {
  7651. return JSON.stringify(params);
  7652. }
  7653. },
  7654. "form": {
  7655. headers: {},
  7656. body: function body(url, config, params) {
  7657. var output = this.generateParamsList(params),
  7658. form = new FormData();
  7659. output.forEach(function (item) {
  7660. form.append(item.key, item.value);
  7661. });
  7662. return form;
  7663. }
  7664. }
  7665. };
  7666. Tabulator.prototype.registerModule("ajax", Ajax);
  7667. //public calc object
  7668. var CalcComponent = function CalcComponent(row) {
  7669. this._row = row;
  7670. };
  7671. CalcComponent.prototype.getData = function (transform) {
  7672. return this._row.getData(transform);
  7673. };
  7674. CalcComponent.prototype.getElement = function () {
  7675. return this._row.getElement();
  7676. };
  7677. CalcComponent.prototype.getTable = function () {
  7678. return this._row.table;
  7679. };
  7680. CalcComponent.prototype.getCells = function () {
  7681. var cells = [];
  7682. this._row.getCells().forEach(function (cell) {
  7683. cells.push(cell.getComponent());
  7684. });
  7685. return cells;
  7686. };
  7687. CalcComponent.prototype.getCell = function (column) {
  7688. var cell = this._row.getCell(column);
  7689. return cell ? cell.getComponent() : false;
  7690. };
  7691. CalcComponent.prototype._getSelf = function () {
  7692. return this._row;
  7693. };
  7694. var ColumnCalcs = function ColumnCalcs(table) {
  7695. this.table = table; //hold Tabulator object
  7696. this.topCalcs = [];
  7697. this.botCalcs = [];
  7698. this.genColumn = false;
  7699. this.topElement = this.createElement();
  7700. this.botElement = this.createElement();
  7701. this.topRow = false;
  7702. this.botRow = false;
  7703. this.topInitialized = false;
  7704. this.botInitialized = false;
  7705. this.initialize();
  7706. };
  7707. ColumnCalcs.prototype.createElement = function () {
  7708. var el = document.createElement("div");
  7709. el.classList.add("tabulator-calcs-holder");
  7710. return el;
  7711. };
  7712. ColumnCalcs.prototype.initialize = function () {
  7713. this.genColumn = new Column({ field: "value" }, this);
  7714. };
  7715. //dummy functions to handle being mock column manager
  7716. ColumnCalcs.prototype.registerColumnField = function () {};
  7717. //initialize column calcs
  7718. ColumnCalcs.prototype.initializeColumn = function (column) {
  7719. var def = column.definition;
  7720. var config = {
  7721. topCalcParams: def.topCalcParams || {},
  7722. botCalcParams: def.bottomCalcParams || {}
  7723. };
  7724. if (def.topCalc) {
  7725. switch (_typeof(def.topCalc)) {
  7726. case "string":
  7727. if (this.calculations[def.topCalc]) {
  7728. config.topCalc = this.calculations[def.topCalc];
  7729. } else {
  7730. console.warn("Column Calc Error - No such calculation found, ignoring: ", def.topCalc);
  7731. }
  7732. break;
  7733. case "function":
  7734. config.topCalc = def.topCalc;
  7735. break;
  7736. }
  7737. if (config.topCalc) {
  7738. column.modules.columnCalcs = config;
  7739. this.topCalcs.push(column);
  7740. if (this.table.options.columnCalcs != "group") {
  7741. this.initializeTopRow();
  7742. }
  7743. }
  7744. }
  7745. if (def.bottomCalc) {
  7746. switch (_typeof(def.bottomCalc)) {
  7747. case "string":
  7748. if (this.calculations[def.bottomCalc]) {
  7749. config.botCalc = this.calculations[def.bottomCalc];
  7750. } else {
  7751. console.warn("Column Calc Error - No such calculation found, ignoring: ", def.bottomCalc);
  7752. }
  7753. break;
  7754. case "function":
  7755. config.botCalc = def.bottomCalc;
  7756. break;
  7757. }
  7758. if (config.botCalc) {
  7759. column.modules.columnCalcs = config;
  7760. this.botCalcs.push(column);
  7761. if (this.table.options.columnCalcs != "group") {
  7762. this.initializeBottomRow();
  7763. }
  7764. }
  7765. }
  7766. };
  7767. ColumnCalcs.prototype.removeCalcs = function () {
  7768. var changed = false;
  7769. if (this.topInitialized) {
  7770. this.topInitialized = false;
  7771. this.topElement.parentNode.removeChild(this.topElement);
  7772. changed = true;
  7773. }
  7774. if (this.botInitialized) {
  7775. this.botInitialized = false;
  7776. this.table.footerManager.remove(this.botElement);
  7777. changed = true;
  7778. }
  7779. if (changed) {
  7780. this.table.rowManager.adjustTableSize();
  7781. }
  7782. };
  7783. ColumnCalcs.prototype.initializeTopRow = function () {
  7784. if (!this.topInitialized) {
  7785. // this.table.columnManager.headersElement.after(this.topElement);
  7786. this.table.columnManager.getElement().insertBefore(this.topElement, this.table.columnManager.headersElement.nextSibling);
  7787. this.topInitialized = true;
  7788. }
  7789. };
  7790. ColumnCalcs.prototype.initializeBottomRow = function () {
  7791. if (!this.botInitialized) {
  7792. this.table.footerManager.prepend(this.botElement);
  7793. this.botInitialized = true;
  7794. }
  7795. };
  7796. ColumnCalcs.prototype.scrollHorizontal = function (left) {
  7797. var hozAdjust = 0,
  7798. scrollWidth = this.table.columnManager.getElement().scrollWidth - this.table.element.clientWidth;
  7799. if (this.botInitialized && this.botRow) {
  7800. this.botRow.getElement().style.marginLeft = -left + "px";
  7801. }
  7802. };
  7803. ColumnCalcs.prototype.recalc = function (rows) {
  7804. var data, row;
  7805. if (this.topInitialized || this.botInitialized) {
  7806. data = this.rowsToData(rows);
  7807. if (this.topInitialized) {
  7808. if (this.topRow) {
  7809. this.topRow.deleteCells();
  7810. }
  7811. row = this.generateRow("top", this.rowsToData(rows));
  7812. this.topRow = row;
  7813. while (this.topElement.firstChild) {
  7814. this.topElement.removeChild(this.topElement.firstChild);
  7815. }this.topElement.appendChild(row.getElement());
  7816. row.initialize(true);
  7817. }
  7818. if (this.botInitialized) {
  7819. if (this.botRow) {
  7820. this.botRow.deleteCells();
  7821. }
  7822. row = this.generateRow("bottom", this.rowsToData(rows));
  7823. this.botRow = row;
  7824. while (this.botElement.firstChild) {
  7825. this.botElement.removeChild(this.botElement.firstChild);
  7826. }this.botElement.appendChild(row.getElement());
  7827. row.initialize(true);
  7828. }
  7829. this.table.rowManager.adjustTableSize();
  7830. //set resizable handles
  7831. if (this.table.modExists("frozenColumns")) {
  7832. this.table.modules.frozenColumns.layout();
  7833. }
  7834. }
  7835. };
  7836. ColumnCalcs.prototype.recalcRowGroup = function (row) {
  7837. this.recalcGroup(this.table.modules.groupRows.getRowGroup(row));
  7838. };
  7839. ColumnCalcs.prototype.recalcAll = function () {
  7840. var _this44 = this;
  7841. if (this.topCalcs.length || this.botCalcs.length) {
  7842. if (this.table.options.columnCalcs !== "group") {
  7843. this.recalc(this.table.rowManager.activeRows);
  7844. }
  7845. if (this.table.options.groupBy && this.table.options.columnCalcs !== "table") {
  7846. var groups = table.modules.groupRows.getChildGroups();
  7847. groups.forEach(function (group) {
  7848. _this44.recalcGroup(group);
  7849. });
  7850. }
  7851. }
  7852. };
  7853. ColumnCalcs.prototype.recalcGroup = function (group) {
  7854. var data, rowData;
  7855. if (group) {
  7856. if (group.calcs) {
  7857. if (group.calcs.bottom) {
  7858. data = this.rowsToData(group.rows);
  7859. rowData = this.generateRowData("bottom", data);
  7860. group.calcs.bottom.updateData(rowData);
  7861. group.calcs.bottom.reinitialize();
  7862. }
  7863. if (group.calcs.top) {
  7864. data = this.rowsToData(group.rows);
  7865. rowData = this.generateRowData("top", data);
  7866. group.calcs.top.updateData(rowData);
  7867. group.calcs.top.reinitialize();
  7868. }
  7869. }
  7870. }
  7871. };
  7872. //generate top stats row
  7873. ColumnCalcs.prototype.generateTopRow = function (rows) {
  7874. return this.generateRow("top", this.rowsToData(rows));
  7875. };
  7876. //generate bottom stats row
  7877. ColumnCalcs.prototype.generateBottomRow = function (rows) {
  7878. return this.generateRow("bottom", this.rowsToData(rows));
  7879. };
  7880. ColumnCalcs.prototype.rowsToData = function (rows) {
  7881. var _this45 = this;
  7882. var data = [];
  7883. rows.forEach(function (row) {
  7884. data.push(row.getData());
  7885. if (_this45.table.options.dataTree && _this45.table.options.dataTreeChildColumnCalcs) {
  7886. if (row.modules.dataTree.open) {
  7887. var children = _this45.rowsToData(_this45.table.modules.dataTree.getFilteredTreeChildren(row));
  7888. data = data.concat(children);
  7889. }
  7890. }
  7891. });
  7892. return data;
  7893. };
  7894. //generate stats row
  7895. ColumnCalcs.prototype.generateRow = function (pos, data) {
  7896. var self = this,
  7897. rowData = this.generateRowData(pos, data),
  7898. row;
  7899. if (self.table.modExists("mutator")) {
  7900. self.table.modules.mutator.disable();
  7901. }
  7902. row = new Row(rowData, this, "calc");
  7903. if (self.table.modExists("mutator")) {
  7904. self.table.modules.mutator.enable();
  7905. }
  7906. row.getElement().classList.add("tabulator-calcs", "tabulator-calcs-" + pos);
  7907. row.component = false;
  7908. row.getComponent = function () {
  7909. if (!this.component) {
  7910. this.component = new CalcComponent(this);
  7911. }
  7912. return this.component;
  7913. };
  7914. row.generateCells = function () {
  7915. var cells = [];
  7916. self.table.columnManager.columnsByIndex.forEach(function (column) {
  7917. //set field name of mock column
  7918. self.genColumn.setField(column.getField());
  7919. self.genColumn.hozAlign = column.hozAlign;
  7920. if (column.definition[pos + "CalcFormatter"] && self.table.modExists("format")) {
  7921. self.genColumn.modules.format = {
  7922. formatter: self.table.modules.format.getFormatter(column.definition[pos + "CalcFormatter"]),
  7923. params: column.definition[pos + "CalcFormatterParams"] || {}
  7924. };
  7925. } else {
  7926. self.genColumn.modules.format = {
  7927. formatter: self.table.modules.format.getFormatter("plaintext"),
  7928. params: {}
  7929. };
  7930. }
  7931. //ensure css class defintion is replicated to calculation cell
  7932. self.genColumn.definition.cssClass = column.definition.cssClass;
  7933. //generate cell and assign to correct column
  7934. var cell = new Cell(self.genColumn, row);
  7935. cell.getElement();
  7936. cell.column = column;
  7937. cell.setWidth();
  7938. column.cells.push(cell);
  7939. cells.push(cell);
  7940. if (!column.visible) {
  7941. cell.hide();
  7942. }
  7943. });
  7944. this.cells = cells;
  7945. };
  7946. return row;
  7947. };
  7948. //generate stats row
  7949. ColumnCalcs.prototype.generateRowData = function (pos, data) {
  7950. var rowData = {},
  7951. calcs = pos == "top" ? this.topCalcs : this.botCalcs,
  7952. type = pos == "top" ? "topCalc" : "botCalc",
  7953. params,
  7954. paramKey;
  7955. calcs.forEach(function (column) {
  7956. var values = [];
  7957. if (column.modules.columnCalcs && column.modules.columnCalcs[type]) {
  7958. data.forEach(function (item) {
  7959. values.push(column.getFieldValue(item));
  7960. });
  7961. paramKey = type + "Params";
  7962. params = typeof column.modules.columnCalcs[paramKey] === "function" ? column.modules.columnCalcs[paramKey](values, data) : column.modules.columnCalcs[paramKey];
  7963. column.setFieldValue(rowData, column.modules.columnCalcs[type](values, data, params));
  7964. }
  7965. });
  7966. return rowData;
  7967. };
  7968. ColumnCalcs.prototype.hasTopCalcs = function () {
  7969. return !!this.topCalcs.length;
  7970. };
  7971. ColumnCalcs.prototype.hasBottomCalcs = function () {
  7972. return !!this.botCalcs.length;
  7973. };
  7974. //handle table redraw
  7975. ColumnCalcs.prototype.redraw = function () {
  7976. if (this.topRow) {
  7977. this.topRow.normalizeHeight(true);
  7978. }
  7979. if (this.botRow) {
  7980. this.botRow.normalizeHeight(true);
  7981. }
  7982. };
  7983. //return the calculated
  7984. ColumnCalcs.prototype.getResults = function () {
  7985. var self = this,
  7986. results = {},
  7987. groups;
  7988. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  7989. groups = this.table.modules.groupRows.getGroups(true);
  7990. groups.forEach(function (group) {
  7991. results[group.getKey()] = self.getGroupResults(group);
  7992. });
  7993. } else {
  7994. results = {
  7995. top: this.topRow ? this.topRow.getData() : {},
  7996. bottom: this.botRow ? this.botRow.getData() : {}
  7997. };
  7998. }
  7999. return results;
  8000. };
  8001. //get results from a group
  8002. ColumnCalcs.prototype.getGroupResults = function (group) {
  8003. var self = this,
  8004. groupObj = group._getSelf(),
  8005. subGroups = group.getSubGroups(),
  8006. subGroupResults = {},
  8007. results = {};
  8008. subGroups.forEach(function (subgroup) {
  8009. subGroupResults[subgroup.getKey()] = self.getGroupResults(subgroup);
  8010. });
  8011. results = {
  8012. top: groupObj.calcs.top ? groupObj.calcs.top.getData() : {},
  8013. bottom: groupObj.calcs.bottom ? groupObj.calcs.bottom.getData() : {},
  8014. groups: subGroupResults
  8015. };
  8016. return results;
  8017. };
  8018. //default calculations
  8019. ColumnCalcs.prototype.calculations = {
  8020. "avg": function avg(values, data, calcParams) {
  8021. var output = 0,
  8022. precision = typeof calcParams.precision !== "undefined" ? calcParams.precision : 2;
  8023. if (values.length) {
  8024. output = values.reduce(function (sum, value) {
  8025. value = Number(value);
  8026. return sum + value;
  8027. });
  8028. output = output / values.length;
  8029. output = precision !== false ? output.toFixed(precision) : output;
  8030. }
  8031. return parseFloat(output).toString();
  8032. },
  8033. "max": function max(values, data, calcParams) {
  8034. var output = null,
  8035. precision = typeof calcParams.precision !== "undefined" ? calcParams.precision : false;
  8036. values.forEach(function (value) {
  8037. value = Number(value);
  8038. if (value > output || output === null) {
  8039. output = value;
  8040. }
  8041. });
  8042. return output !== null ? precision !== false ? output.toFixed(precision) : output : "";
  8043. },
  8044. "min": function min(values, data, calcParams) {
  8045. var output = null,
  8046. precision = typeof calcParams.precision !== "undefined" ? calcParams.precision : false;
  8047. values.forEach(function (value) {
  8048. value = Number(value);
  8049. if (value < output || output === null) {
  8050. output = value;
  8051. }
  8052. });
  8053. return output !== null ? precision !== false ? output.toFixed(precision) : output : "";
  8054. },
  8055. "sum": function sum(values, data, calcParams) {
  8056. var output = 0,
  8057. precision = typeof calcParams.precision !== "undefined" ? calcParams.precision : false;
  8058. if (values.length) {
  8059. values.forEach(function (value) {
  8060. value = Number(value);
  8061. output += !isNaN(value) ? Number(value) : 0;
  8062. });
  8063. }
  8064. return precision !== false ? output.toFixed(precision) : output;
  8065. },
  8066. "concat": function concat(values, data, calcParams) {
  8067. var output = 0;
  8068. if (values.length) {
  8069. output = values.reduce(function (sum, value) {
  8070. return String(sum) + String(value);
  8071. });
  8072. }
  8073. return output;
  8074. },
  8075. "count": function count(values, data, calcParams) {
  8076. var output = 0;
  8077. if (values.length) {
  8078. values.forEach(function (value) {
  8079. if (value) {
  8080. output++;
  8081. }
  8082. });
  8083. }
  8084. return output;
  8085. }
  8086. };
  8087. Tabulator.prototype.registerModule("columnCalcs", ColumnCalcs);
  8088. var Clipboard = function Clipboard(table) {
  8089. this.table = table;
  8090. this.mode = true;
  8091. this.pasteParser = function () {};
  8092. this.pasteAction = function () {};
  8093. this.customSelection = false;
  8094. this.rowRange = false;
  8095. this.blocked = true; //block copy actions not originating from this command
  8096. };
  8097. Clipboard.prototype.initialize = function () {
  8098. var _this46 = this;
  8099. this.mode = this.table.options.clipboard;
  8100. this.rowRange = this.table.options.clipboardCopyRowRange;
  8101. if (this.mode === true || this.mode === "copy") {
  8102. this.table.element.addEventListener("copy", function (e) {
  8103. var plain, html, list;
  8104. if (!_this46.blocked) {
  8105. e.preventDefault();
  8106. if (_this46.customSelection) {
  8107. plain = _this46.customSelection;
  8108. if (_this46.table.options.clipboardCopyFormatter) {
  8109. plain = _this46.table.options.clipboardCopyFormatter("plain", plain);
  8110. }
  8111. } else {
  8112. var list = _this46.table.modules.export.generateExportList(_this46.rowRange, _this46.table.options.clipboardCopyStyled, _this46.table.options.clipboardCopyConfig, "clipboard");
  8113. html = _this46.table.modules.export.genereateHTMLTable(list);
  8114. plain = html ? _this46.generatePlainContent(list) : "";
  8115. if (_this46.table.options.clipboardCopyFormatter) {
  8116. plain = _this46.table.options.clipboardCopyFormatter("plain", plain);
  8117. html = _this46.table.options.clipboardCopyFormatter("html", html);
  8118. }
  8119. }
  8120. if (window.clipboardData && window.clipboardData.setData) {
  8121. window.clipboardData.setData('Text', plain);
  8122. } else if (e.clipboardData && e.clipboardData.setData) {
  8123. e.clipboardData.setData('text/plain', plain);
  8124. if (html) {
  8125. e.clipboardData.setData('text/html', html);
  8126. }
  8127. } else if (e.originalEvent && e.originalEvent.clipboardData.setData) {
  8128. e.originalEvent.clipboardData.setData('text/plain', plain);
  8129. if (html) {
  8130. e.originalEvent.clipboardData.setData('text/html', html);
  8131. }
  8132. }
  8133. _this46.table.options.clipboardCopied.call(_this46.table, plain, html);
  8134. _this46.reset();
  8135. }
  8136. });
  8137. }
  8138. if (this.mode === true || this.mode === "paste") {
  8139. this.table.element.addEventListener("paste", function (e) {
  8140. _this46.paste(e);
  8141. });
  8142. }
  8143. this.setPasteParser(this.table.options.clipboardPasteParser);
  8144. this.setPasteAction(this.table.options.clipboardPasteAction);
  8145. };
  8146. Clipboard.prototype.reset = function () {
  8147. this.blocked = false;
  8148. this.originalSelectionText = "";
  8149. };
  8150. Clipboard.prototype.generatePlainContent = function (list) {
  8151. var output = [];
  8152. list.forEach(function (row) {
  8153. var rowData = [];
  8154. row.columns.forEach(function (col) {
  8155. var value = "";
  8156. if (col) {
  8157. if (row.type === "group") {
  8158. col.value = col.component.getKey();
  8159. }
  8160. if (col.value === null) {
  8161. value = "";
  8162. } else {
  8163. switch (_typeof(col.value)) {
  8164. case "object":
  8165. value = JSON.stringify(col.value);
  8166. break;
  8167. case "undefined":
  8168. value = "";
  8169. break;
  8170. default:
  8171. value = col.value;
  8172. }
  8173. }
  8174. }
  8175. rowData.push(value);
  8176. });
  8177. output.push(rowData.join("\t"));
  8178. });
  8179. return output.join("\n");
  8180. };
  8181. Clipboard.prototype.copy = function (range, internal) {
  8182. var range, sel, textRange;
  8183. this.blocked = false;
  8184. this.customSelection = false;
  8185. if (this.mode === true || this.mode === "copy") {
  8186. this.rowRange = range || this.table.options.clipboardCopyRowRange;
  8187. if (typeof window.getSelection != "undefined" && typeof document.createRange != "undefined") {
  8188. range = document.createRange();
  8189. range.selectNodeContents(this.table.element);
  8190. sel = window.getSelection();
  8191. if (sel.toString() && internal) {
  8192. this.customSelection = sel.toString();
  8193. }
  8194. sel.removeAllRanges();
  8195. sel.addRange(range);
  8196. } else if (typeof document.selection != "undefined" && typeof document.body.createTextRange != "undefined") {
  8197. textRange = document.body.createTextRange();
  8198. textRange.moveToElementText(this.table.element);
  8199. textRange.select();
  8200. }
  8201. document.execCommand('copy');
  8202. if (sel) {
  8203. sel.removeAllRanges();
  8204. }
  8205. }
  8206. };
  8207. //PASTE EVENT HANDLING
  8208. Clipboard.prototype.setPasteAction = function (action) {
  8209. switch (typeof action === 'undefined' ? 'undefined' : _typeof(action)) {
  8210. case "string":
  8211. this.pasteAction = this.pasteActions[action];
  8212. if (!this.pasteAction) {
  8213. console.warn("Clipboard Error - No such paste action found:", action);
  8214. }
  8215. break;
  8216. case "function":
  8217. this.pasteAction = action;
  8218. break;
  8219. }
  8220. };
  8221. Clipboard.prototype.setPasteParser = function (parser) {
  8222. switch (typeof parser === 'undefined' ? 'undefined' : _typeof(parser)) {
  8223. case "string":
  8224. this.pasteParser = this.pasteParsers[parser];
  8225. if (!this.pasteParser) {
  8226. console.warn("Clipboard Error - No such paste parser found:", parser);
  8227. }
  8228. break;
  8229. case "function":
  8230. this.pasteParser = parser;
  8231. break;
  8232. }
  8233. };
  8234. Clipboard.prototype.paste = function (e) {
  8235. var data, rowData, rows;
  8236. if (this.checkPaseOrigin(e)) {
  8237. data = this.getPasteData(e);
  8238. rowData = this.pasteParser.call(this, data);
  8239. if (rowData) {
  8240. e.preventDefault();
  8241. if (this.table.modExists("mutator")) {
  8242. rowData = this.mutateData(rowData);
  8243. }
  8244. rows = this.pasteAction.call(this, rowData);
  8245. this.table.options.clipboardPasted.call(this.table, data, rowData, rows);
  8246. } else {
  8247. this.table.options.clipboardPasteError.call(this.table, data);
  8248. }
  8249. }
  8250. };
  8251. Clipboard.prototype.mutateData = function (data) {
  8252. var self = this,
  8253. output = [];
  8254. if (Array.isArray(data)) {
  8255. data.forEach(function (row) {
  8256. output.push(self.table.modules.mutator.transformRow(row, "clipboard"));
  8257. });
  8258. } else {
  8259. output = data;
  8260. }
  8261. return output;
  8262. };
  8263. Clipboard.prototype.checkPaseOrigin = function (e) {
  8264. var valid = true;
  8265. if (e.target.tagName != "DIV" || this.table.modules.edit.currentCell) {
  8266. valid = false;
  8267. }
  8268. return valid;
  8269. };
  8270. Clipboard.prototype.getPasteData = function (e) {
  8271. var data;
  8272. if (window.clipboardData && window.clipboardData.getData) {
  8273. data = window.clipboardData.getData('Text');
  8274. } else if (e.clipboardData && e.clipboardData.getData) {
  8275. data = e.clipboardData.getData('text/plain');
  8276. } else if (e.originalEvent && e.originalEvent.clipboardData.getData) {
  8277. data = e.originalEvent.clipboardData.getData('text/plain');
  8278. }
  8279. return data;
  8280. };
  8281. Clipboard.prototype.pasteParsers = {
  8282. table: function table(clipboard) {
  8283. var data = [],
  8284. success = false,
  8285. headerFindSuccess = true,
  8286. columns = this.table.columnManager.columns,
  8287. columnMap = [],
  8288. rows = [];
  8289. //get data from clipboard into array of columns and rows.
  8290. clipboard = clipboard.split("\n");
  8291. clipboard.forEach(function (row) {
  8292. data.push(row.split("\t"));
  8293. });
  8294. if (data.length && !(data.length === 1 && data[0].length < 2)) {
  8295. success = true;
  8296. //check if headers are present by title
  8297. data[0].forEach(function (value) {
  8298. var column = columns.find(function (column) {
  8299. return value && column.definition.title && value.trim() && column.definition.title.trim() === value.trim();
  8300. });
  8301. if (column) {
  8302. columnMap.push(column);
  8303. } else {
  8304. headerFindSuccess = false;
  8305. }
  8306. });
  8307. //check if column headers are present by field
  8308. if (!headerFindSuccess) {
  8309. headerFindSuccess = true;
  8310. columnMap = [];
  8311. data[0].forEach(function (value) {
  8312. var column = columns.find(function (column) {
  8313. return value && column.field && value.trim() && column.field.trim() === value.trim();
  8314. });
  8315. if (column) {
  8316. columnMap.push(column);
  8317. } else {
  8318. headerFindSuccess = false;
  8319. }
  8320. });
  8321. if (!headerFindSuccess) {
  8322. columnMap = this.table.columnManager.columnsByIndex;
  8323. }
  8324. }
  8325. //remove header row if found
  8326. if (headerFindSuccess) {
  8327. data.shift();
  8328. }
  8329. data.forEach(function (item) {
  8330. var row = {};
  8331. item.forEach(function (value, i) {
  8332. if (columnMap[i]) {
  8333. row[columnMap[i].field] = value;
  8334. }
  8335. });
  8336. rows.push(row);
  8337. });
  8338. return rows;
  8339. } else {
  8340. return false;
  8341. }
  8342. }
  8343. };
  8344. Clipboard.prototype.pasteActions = {
  8345. replace: function replace(rows) {
  8346. return this.table.setData(rows);
  8347. },
  8348. update: function update(rows) {
  8349. return this.table.updateOrAddData(rows);
  8350. },
  8351. insert: function insert(rows) {
  8352. return this.table.addData(rows);
  8353. }
  8354. };
  8355. Tabulator.prototype.registerModule("clipboard", Clipboard);
  8356. var DataTree = function DataTree(table) {
  8357. this.table = table;
  8358. this.indent = 10;
  8359. this.field = "";
  8360. this.collapseEl = null;
  8361. this.expandEl = null;
  8362. this.branchEl = null;
  8363. this.elementField = false;
  8364. this.startOpen = function () {};
  8365. this.displayIndex = 0;
  8366. };
  8367. DataTree.prototype.initialize = function () {
  8368. var dummyEl = null,
  8369. firstCol = this.table.columnManager.getFirstVisibileColumn(),
  8370. options = this.table.options;
  8371. this.field = options.dataTreeChildField;
  8372. this.indent = options.dataTreeChildIndent;
  8373. this.elementField = options.dataTreeElementColumn || (firstCol ? firstCol.field : false);
  8374. if (options.dataTreeBranchElement) {
  8375. if (options.dataTreeBranchElement === true) {
  8376. this.branchEl = document.createElement("div");
  8377. this.branchEl.classList.add("tabulator-data-tree-branch");
  8378. } else {
  8379. if (typeof options.dataTreeBranchElement === "string") {
  8380. dummyEl = document.createElement("div");
  8381. dummyEl.innerHTML = options.dataTreeBranchElement;
  8382. this.branchEl = dummyEl.firstChild;
  8383. } else {
  8384. this.branchEl = options.dataTreeBranchElement;
  8385. }
  8386. }
  8387. }
  8388. if (options.dataTreeCollapseElement) {
  8389. if (typeof options.dataTreeCollapseElement === "string") {
  8390. dummyEl = document.createElement("div");
  8391. dummyEl.innerHTML = options.dataTreeCollapseElement;
  8392. this.collapseEl = dummyEl.firstChild;
  8393. } else {
  8394. this.collapseEl = options.dataTreeCollapseElement;
  8395. }
  8396. } else {
  8397. this.collapseEl = document.createElement("div");
  8398. this.collapseEl.classList.add("tabulator-data-tree-control");
  8399. this.collapseEl.tabIndex = 0;
  8400. this.collapseEl.innerHTML = "<div class='tabulator-data-tree-control-collapse'></div>";
  8401. }
  8402. if (options.dataTreeExpandElement) {
  8403. if (typeof options.dataTreeExpandElement === "string") {
  8404. dummyEl = document.createElement("div");
  8405. dummyEl.innerHTML = options.dataTreeExpandElement;
  8406. this.expandEl = dummyEl.firstChild;
  8407. } else {
  8408. this.expandEl = options.dataTreeExpandElement;
  8409. }
  8410. } else {
  8411. this.expandEl = document.createElement("div");
  8412. this.expandEl.classList.add("tabulator-data-tree-control");
  8413. this.expandEl.tabIndex = 0;
  8414. this.expandEl.innerHTML = "<div class='tabulator-data-tree-control-expand'></div>";
  8415. }
  8416. switch (_typeof(options.dataTreeStartExpanded)) {
  8417. case "boolean":
  8418. this.startOpen = function (row, index) {
  8419. return options.dataTreeStartExpanded;
  8420. };
  8421. break;
  8422. case "function":
  8423. this.startOpen = options.dataTreeStartExpanded;
  8424. break;
  8425. default:
  8426. this.startOpen = function (row, index) {
  8427. return options.dataTreeStartExpanded[index];
  8428. };
  8429. break;
  8430. }
  8431. };
  8432. DataTree.prototype.initializeRow = function (row) {
  8433. var childArray = row.getData()[this.field];
  8434. var isArray = Array.isArray(childArray);
  8435. var children = isArray || !isArray && (typeof childArray === 'undefined' ? 'undefined' : _typeof(childArray)) === "object" && childArray !== null;
  8436. if (!children && row.modules.dataTree && row.modules.dataTree.branchEl) {
  8437. row.modules.dataTree.branchEl.parentNode.removeChild(row.modules.dataTree.branchEl);
  8438. }
  8439. if (!children && row.modules.dataTree && row.modules.dataTree.controlEl) {
  8440. row.modules.dataTree.controlEl.parentNode.removeChild(row.modules.dataTree.controlEl);
  8441. }
  8442. row.modules.dataTree = {
  8443. index: row.modules.dataTree ? row.modules.dataTree.index : 0,
  8444. open: children ? row.modules.dataTree ? row.modules.dataTree.open : this.startOpen(row.getComponent(), 0) : false,
  8445. controlEl: row.modules.dataTree && children ? row.modules.dataTree.controlEl : false,
  8446. branchEl: row.modules.dataTree && children ? row.modules.dataTree.branchEl : false,
  8447. parent: row.modules.dataTree ? row.modules.dataTree.parent : false,
  8448. children: children
  8449. };
  8450. };
  8451. DataTree.prototype.layoutRow = function (row) {
  8452. var cell = this.elementField ? row.getCell(this.elementField) : row.getCells()[0],
  8453. el = cell.getElement(),
  8454. config = row.modules.dataTree;
  8455. if (config.branchEl) {
  8456. if (config.branchEl.parentNode) {
  8457. config.branchEl.parentNode.removeChild(config.branchEl);
  8458. }
  8459. config.branchEl = false;
  8460. }
  8461. if (config.controlEl) {
  8462. if (config.controlEl.parentNode) {
  8463. config.controlEl.parentNode.removeChild(config.controlEl);
  8464. }
  8465. config.controlEl = false;
  8466. }
  8467. this.generateControlElement(row, el);
  8468. row.element.classList.add("tabulator-tree-level-" + config.index);
  8469. if (config.index) {
  8470. if (this.branchEl) {
  8471. config.branchEl = this.branchEl.cloneNode(true);
  8472. el.insertBefore(config.branchEl, el.firstChild);
  8473. if (this.table.rtl) {
  8474. config.branchEl.style.marginRight = (config.branchEl.offsetWidth + config.branchEl.style.marginLeft) * (config.index - 1) + config.index * this.indent + "px";
  8475. } else {
  8476. config.branchEl.style.marginLeft = (config.branchEl.offsetWidth + config.branchEl.style.marginRight) * (config.index - 1) + config.index * this.indent + "px";
  8477. }
  8478. } else {
  8479. if (this.table.rtl) {
  8480. el.style.paddingRight = parseInt(window.getComputedStyle(el, null).getPropertyValue('padding-right')) + config.index * this.indent + "px";
  8481. } else {
  8482. el.style.paddingLeft = parseInt(window.getComputedStyle(el, null).getPropertyValue('padding-left')) + config.index * this.indent + "px";
  8483. }
  8484. }
  8485. }
  8486. };
  8487. DataTree.prototype.generateControlElement = function (row, el) {
  8488. var _this47 = this;
  8489. var config = row.modules.dataTree,
  8490. el = el || row.getCells()[0].getElement(),
  8491. oldControl = config.controlEl;
  8492. if (config.children !== false) {
  8493. if (config.open) {
  8494. config.controlEl = this.collapseEl.cloneNode(true);
  8495. config.controlEl.addEventListener("click", function (e) {
  8496. e.stopPropagation();
  8497. _this47.collapseRow(row);
  8498. });
  8499. } else {
  8500. config.controlEl = this.expandEl.cloneNode(true);
  8501. config.controlEl.addEventListener("click", function (e) {
  8502. e.stopPropagation();
  8503. _this47.expandRow(row);
  8504. });
  8505. }
  8506. config.controlEl.addEventListener("mousedown", function (e) {
  8507. e.stopPropagation();
  8508. });
  8509. if (oldControl && oldControl.parentNode === el) {
  8510. oldControl.parentNode.replaceChild(config.controlEl, oldControl);
  8511. } else {
  8512. el.insertBefore(config.controlEl, el.firstChild);
  8513. }
  8514. }
  8515. };
  8516. DataTree.prototype.setDisplayIndex = function (index) {
  8517. this.displayIndex = index;
  8518. };
  8519. DataTree.prototype.getDisplayIndex = function () {
  8520. return this.displayIndex;
  8521. };
  8522. DataTree.prototype.getRows = function (rows) {
  8523. var _this48 = this;
  8524. var output = [];
  8525. rows.forEach(function (row, i) {
  8526. var config, children;
  8527. output.push(row);
  8528. if (row instanceof Row) {
  8529. config = row.modules.dataTree.children;
  8530. if (!config.index && config.children !== false) {
  8531. children = _this48.getChildren(row);
  8532. children.forEach(function (child) {
  8533. output.push(child);
  8534. });
  8535. }
  8536. }
  8537. });
  8538. return output;
  8539. };
  8540. DataTree.prototype.getChildren = function (row) {
  8541. var _this49 = this;
  8542. var config = row.modules.dataTree,
  8543. children = [],
  8544. output = [];
  8545. if (config.children !== false && config.open) {
  8546. if (!Array.isArray(config.children)) {
  8547. config.children = this.generateChildren(row);
  8548. }
  8549. if (this.table.modExists("filter") && this.table.options.dataTreeFilter) {
  8550. children = this.table.modules.filter.filter(config.children);
  8551. } else {
  8552. children = config.children;
  8553. }
  8554. if (this.table.modExists("sort") && this.table.options.dataTreeSort) {
  8555. this.table.modules.sort.sort(children);
  8556. }
  8557. children.forEach(function (child) {
  8558. output.push(child);
  8559. var subChildren = _this49.getChildren(child);
  8560. subChildren.forEach(function (sub) {
  8561. output.push(sub);
  8562. });
  8563. });
  8564. }
  8565. return output;
  8566. };
  8567. DataTree.prototype.generateChildren = function (row) {
  8568. var _this50 = this;
  8569. var children = [];
  8570. var childArray = row.getData()[this.field];
  8571. if (!Array.isArray(childArray)) {
  8572. childArray = [childArray];
  8573. }
  8574. childArray.forEach(function (childData) {
  8575. var childRow = new Row(childData || {}, _this50.table.rowManager);
  8576. childRow.modules.dataTree.index = row.modules.dataTree.index + 1;
  8577. childRow.modules.dataTree.parent = row;
  8578. if (childRow.modules.dataTree.children) {
  8579. childRow.modules.dataTree.open = _this50.startOpen(childRow.getComponent(), childRow.modules.dataTree.index);
  8580. }
  8581. children.push(childRow);
  8582. });
  8583. return children;
  8584. };
  8585. DataTree.prototype.expandRow = function (row, silent) {
  8586. var config = row.modules.dataTree;
  8587. if (config.children !== false) {
  8588. config.open = true;
  8589. row.reinitialize();
  8590. this.table.rowManager.refreshActiveData("tree", false, true);
  8591. this.table.options.dataTreeRowExpanded(row.getComponent(), row.modules.dataTree.index);
  8592. }
  8593. };
  8594. DataTree.prototype.collapseRow = function (row) {
  8595. var config = row.modules.dataTree;
  8596. if (config.children !== false) {
  8597. config.open = false;
  8598. row.reinitialize();
  8599. this.table.rowManager.refreshActiveData("tree", false, true);
  8600. this.table.options.dataTreeRowCollapsed(row.getComponent(), row.modules.dataTree.index);
  8601. }
  8602. };
  8603. DataTree.prototype.toggleRow = function (row) {
  8604. var config = row.modules.dataTree;
  8605. if (config.children !== false) {
  8606. if (config.open) {
  8607. this.collapseRow(row);
  8608. } else {
  8609. this.expandRow(row);
  8610. }
  8611. }
  8612. };
  8613. DataTree.prototype.getTreeParent = function (row) {
  8614. return row.modules.dataTree.parent ? row.modules.dataTree.parent.getComponent() : false;
  8615. };
  8616. DataTree.prototype.getFilteredTreeChildren = function (row) {
  8617. var config = row.modules.dataTree,
  8618. output = [],
  8619. children;
  8620. if (config.children) {
  8621. if (!Array.isArray(config.children)) {
  8622. config.children = this.generateChildren(row);
  8623. }
  8624. if (this.table.modExists("filter") && this.table.options.dataTreeFilter) {
  8625. children = this.table.modules.filter.filter(config.children);
  8626. } else {
  8627. children = config.children;
  8628. }
  8629. children.forEach(function (childRow) {
  8630. if (childRow instanceof Row) {
  8631. output.push(childRow);
  8632. }
  8633. });
  8634. }
  8635. return output;
  8636. };
  8637. DataTree.prototype.rowDelete = function (row) {
  8638. var parent = row.modules.dataTree.parent,
  8639. childIndex;
  8640. if (parent) {
  8641. childIndex = this.findChildIndex(row, parent);
  8642. if (childIndex !== false) {
  8643. parent.data[this.field].splice(childIndex, 1);
  8644. }
  8645. if (!parent.data[this.field].length) {
  8646. delete parent.data[this.field];
  8647. }
  8648. this.initializeRow(parent);
  8649. this.layoutRow(parent);
  8650. }
  8651. this.table.rowManager.refreshActiveData("tree", false, true);
  8652. };
  8653. DataTree.prototype.addTreeChildRow = function (row, data, top, index) {
  8654. var childIndex = false;
  8655. if (typeof data === "string") {
  8656. data = JSON.parse(data);
  8657. }
  8658. if (!Array.isArray(row.data[this.field])) {
  8659. row.data[this.field] = [];
  8660. row.modules.dataTree.open = this.startOpen(row.getComponent(), row.modules.dataTree.index);
  8661. }
  8662. if (typeof index !== "undefined") {
  8663. childIndex = this.findChildIndex(index, row);
  8664. if (childIndex !== false) {
  8665. row.data[this.field].splice(top ? childIndex : childIndex + 1, 0, data);
  8666. }
  8667. }
  8668. if (childIndex === false) {
  8669. if (top) {
  8670. row.data[this.field].unshift(data);
  8671. } else {
  8672. row.data[this.field].push(data);
  8673. }
  8674. }
  8675. this.initializeRow(row);
  8676. this.layoutRow(row);
  8677. this.table.rowManager.refreshActiveData("tree", false, true);
  8678. };
  8679. DataTree.prototype.findChildIndex = function (subject, parent) {
  8680. var _this51 = this;
  8681. var match = false;
  8682. if ((typeof subject === 'undefined' ? 'undefined' : _typeof(subject)) == "object") {
  8683. if (subject instanceof Row) {
  8684. //subject is row element
  8685. match = subject.data;
  8686. } else if (subject instanceof RowComponent) {
  8687. //subject is public row component
  8688. match = subject._getSelf().data;
  8689. } else if (typeof HTMLElement !== "undefined" && subject instanceof HTMLElement) {
  8690. if (parent.modules.dataTree) {
  8691. match = parent.modules.dataTree.children.find(function (childRow) {
  8692. return childRow instanceof Row ? childRow.element === subject : false;
  8693. });
  8694. if (match) {
  8695. match = match.data;
  8696. }
  8697. }
  8698. }
  8699. } else if (typeof subject == "undefined" || subject === null) {
  8700. match = false;
  8701. } else {
  8702. //subject should be treated as the index of the row
  8703. match = parent.data[this.field].find(function (row) {
  8704. return row.data[_this51.table.options.index] == subject;
  8705. });
  8706. }
  8707. if (match) {
  8708. if (Array.isArray(parent.data[this.field])) {
  8709. match = parent.data[this.field].indexOf(match);
  8710. }
  8711. if (match == -1) {
  8712. match = false;
  8713. }
  8714. }
  8715. //catch all for any other type of input
  8716. return match;
  8717. };
  8718. DataTree.prototype.getTreeChildren = function (row, component, recurse) {
  8719. var _this52 = this;
  8720. var config = row.modules.dataTree,
  8721. output = [];
  8722. if (config.children) {
  8723. if (!Array.isArray(config.children)) {
  8724. config.children = this.generateChildren(row);
  8725. }
  8726. config.children.forEach(function (childRow) {
  8727. if (childRow instanceof Row) {
  8728. output.push(component ? childRow.getComponent() : childRow);
  8729. if (recurse) {
  8730. output = output.concat(_this52.getTreeChildren(childRow, component, recurse));
  8731. }
  8732. }
  8733. });
  8734. }
  8735. return output;
  8736. };
  8737. DataTree.prototype.checkForRestyle = function (cell) {
  8738. if (!cell.row.cells.indexOf(cell)) {
  8739. cell.row.reinitialize();
  8740. }
  8741. };
  8742. DataTree.prototype.getChildField = function () {
  8743. return this.field;
  8744. };
  8745. DataTree.prototype.redrawNeeded = function (data) {
  8746. return (this.field ? typeof data[this.field] !== "undefined" : false) || (this.elementField ? typeof data[this.elementField] !== "undefined" : false);
  8747. };
  8748. Tabulator.prototype.registerModule("dataTree", DataTree);
  8749. var Download = function Download(table) {
  8750. this.table = table; //hold Tabulator object
  8751. };
  8752. //trigger file download
  8753. Download.prototype.download = function (type, filename, options, range, interceptCallback) {
  8754. var self = this,
  8755. downloadFunc = false;
  8756. function buildLink(data, mime) {
  8757. if (interceptCallback) {
  8758. if (interceptCallback === true) {
  8759. self.triggerDownload(data, mime, type, filename, true);
  8760. } else {
  8761. interceptCallback(data);
  8762. }
  8763. } else {
  8764. self.triggerDownload(data, mime, type, filename);
  8765. }
  8766. }
  8767. if (typeof type == "function") {
  8768. downloadFunc = type;
  8769. } else {
  8770. if (self.downloaders[type]) {
  8771. downloadFunc = self.downloaders[type];
  8772. } else {
  8773. console.warn("Download Error - No such download type found: ", type);
  8774. }
  8775. }
  8776. if (downloadFunc) {
  8777. var list = this.generateExportList(range);
  8778. downloadFunc.call(this.table, list, options || {}, buildLink);
  8779. }
  8780. };
  8781. Download.prototype.generateExportList = function (range) {
  8782. var list = this.table.modules.export.generateExportList(this.table.options.downloadConfig, false, range || this.table.options.downloadRowRange, "download");
  8783. //assign group header formatter
  8784. var groupHeader = this.table.options.groupHeaderDownload;
  8785. if (groupHeader && !Array.isArray(groupHeader)) {
  8786. groupHeader = [groupHeader];
  8787. }
  8788. list.forEach(function (row) {
  8789. var group;
  8790. if (row.type === "group") {
  8791. group = row.columns[0];
  8792. if (groupHeader && groupHeader[row.indent]) {
  8793. group.value = groupHeader[row.indent](group.value, row.component._group.getRowCount(), row.component._group.getData(), row.component);
  8794. }
  8795. }
  8796. });
  8797. return list;
  8798. };
  8799. Download.prototype.triggerDownload = function (data, mime, type, filename, newTab) {
  8800. var element = document.createElement('a'),
  8801. blob = new Blob([data], { type: mime }),
  8802. filename = filename || "Tabulator." + (typeof type === "function" ? "txt" : type);
  8803. blob = this.table.options.downloadReady.call(this.table, data, blob);
  8804. if (blob) {
  8805. if (newTab) {
  8806. window.open(window.URL.createObjectURL(blob));
  8807. } else {
  8808. if (navigator.msSaveOrOpenBlob) {
  8809. navigator.msSaveOrOpenBlob(blob, filename);
  8810. } else {
  8811. element.setAttribute('href', window.URL.createObjectURL(blob));
  8812. //set file title
  8813. element.setAttribute('download', filename);
  8814. //trigger download
  8815. element.style.display = 'none';
  8816. document.body.appendChild(element);
  8817. element.click();
  8818. //remove temporary link element
  8819. document.body.removeChild(element);
  8820. }
  8821. }
  8822. if (this.table.options.downloadComplete) {
  8823. this.table.options.downloadComplete();
  8824. }
  8825. }
  8826. };
  8827. Download.prototype.commsReceived = function (table, action, data) {
  8828. switch (action) {
  8829. case "intercept":
  8830. this.download(data.type, "", data.options, data.active, data.intercept);
  8831. break;
  8832. }
  8833. };
  8834. //downloaders
  8835. Download.prototype.downloaders = {
  8836. csv: function csv(list, options, setFileContents) {
  8837. var delimiter = options && options.delimiter ? options.delimiter : ",",
  8838. fileContents = [],
  8839. headers = [];
  8840. list.forEach(function (row) {
  8841. var item = [];
  8842. switch (row.type) {
  8843. case "group":
  8844. console.warn("Download Warning - CSV downloader cannot process row groups");
  8845. break;
  8846. case "calc":
  8847. console.warn("Download Warning - CSV downloader cannot process column calculations");
  8848. break;
  8849. case "header":
  8850. row.columns.forEach(function (col, i) {
  8851. if (col && col.depth === 1) {
  8852. headers[i] = typeof col.value == "undefined" || col.value === null ? "" : '"' + String(col.value).split('"').join('""') + '"';
  8853. }
  8854. });
  8855. break;
  8856. case "row":
  8857. row.columns.forEach(function (col) {
  8858. if (col) {
  8859. switch (_typeof(col.value)) {
  8860. case "object":
  8861. col.value = JSON.stringify(col.value);
  8862. break;
  8863. case "undefined":
  8864. case "null":
  8865. col.value = "";
  8866. break;
  8867. }
  8868. item.push('"' + String(col.value).split('"').join('""') + '"');
  8869. }
  8870. });
  8871. fileContents.push(item.join(delimiter));
  8872. break;
  8873. }
  8874. });
  8875. if (headers.length) {
  8876. fileContents.unshift(headers.join(delimiter));
  8877. }
  8878. fileContents = fileContents.join("\n");
  8879. if (options.bom) {
  8880. fileContents = '\uFEFF' + fileContents;
  8881. }
  8882. setFileContents(fileContents, "text/csv");
  8883. },
  8884. json: function json(list, options, setFileContents) {
  8885. var fileContents = [];
  8886. list.forEach(function (row) {
  8887. var item = {};
  8888. switch (row.type) {
  8889. case "header":
  8890. break;
  8891. case "group":
  8892. console.warn("Download Warning - JSON downloader cannot process row groups");
  8893. break;
  8894. case "calc":
  8895. console.warn("Download Warning - JSON downloader cannot process column calculations");
  8896. break;
  8897. case "row":
  8898. row.columns.forEach(function (col) {
  8899. if (col) {
  8900. item[col.component.getField()] = col.value;
  8901. }
  8902. });
  8903. fileContents.push(item);
  8904. break;
  8905. }
  8906. });
  8907. fileContents = JSON.stringify(fileContents, null, '\t');
  8908. setFileContents(fileContents, "application/json");
  8909. },
  8910. pdf: function pdf(list, options, setFileContents) {
  8911. var header = [],
  8912. body = [],
  8913. autoTableParams = {},
  8914. rowGroupStyles = options.rowGroupStyles || {
  8915. fontStyle: "bold",
  8916. fontSize: 12,
  8917. cellPadding: 6,
  8918. fillColor: 220
  8919. },
  8920. rowCalcStyles = options.rowCalcStyles || {
  8921. fontStyle: "bold",
  8922. fontSize: 10,
  8923. cellPadding: 4,
  8924. fillColor: 232
  8925. },
  8926. jsPDFParams = options.jsPDF || {},
  8927. title = options && options.title ? options.title : "";
  8928. if (!jsPDFParams.orientation) {
  8929. jsPDFParams.orientation = options.orientation || "landscape";
  8930. }
  8931. if (!jsPDFParams.unit) {
  8932. jsPDFParams.unit = "pt";
  8933. }
  8934. //parse row list
  8935. list.forEach(function (row) {
  8936. var item = {};
  8937. switch (row.type) {
  8938. case "header":
  8939. header.push(parseRow(row));
  8940. break;
  8941. case "group":
  8942. body.push(parseRow(row, rowGroupStyles));
  8943. break;
  8944. case "calc":
  8945. body.push(parseRow(row, rowCalcStyles));
  8946. break;
  8947. case "row":
  8948. body.push(parseRow(row));
  8949. break;
  8950. }
  8951. });
  8952. function parseRow(row, styles) {
  8953. var rowData = [];
  8954. row.columns.forEach(function (col) {
  8955. var cell;
  8956. if (col) {
  8957. switch (_typeof(col.value)) {
  8958. case "object":
  8959. col.value = JSON.stringify(col.value);
  8960. break;
  8961. case "undefined":
  8962. case "null":
  8963. col.value = "";
  8964. break;
  8965. }
  8966. cell = {
  8967. content: col.value,
  8968. colSpan: col.width,
  8969. rowSpan: col.height
  8970. };
  8971. if (styles) {
  8972. cell.styles = styles;
  8973. }
  8974. rowData.push(cell);
  8975. } else {
  8976. rowData.push("");
  8977. }
  8978. });
  8979. return rowData;
  8980. }
  8981. //configure PDF
  8982. var doc = new jsPDF(jsPDFParams); //set document to landscape, better for most tables
  8983. if (options && options.autoTable) {
  8984. if (typeof options.autoTable === "function") {
  8985. autoTableParams = options.autoTable(doc) || {};
  8986. } else {
  8987. autoTableParams = options.autoTable;
  8988. }
  8989. }
  8990. if (title) {
  8991. autoTableParams.addPageContent = function (data) {
  8992. doc.text(title, 40, 30);
  8993. };
  8994. }
  8995. autoTableParams.head = header;
  8996. autoTableParams.body = body;
  8997. doc.autoTable(autoTableParams);
  8998. if (options && options.documentProcessing) {
  8999. options.documentProcessing(doc);
  9000. }
  9001. setFileContents(doc.output("arraybuffer"), "application/pdf");
  9002. },
  9003. xlsx: function xlsx(list, options, setFileContents) {
  9004. var self = this,
  9005. sheetName = options.sheetName || "Sheet1",
  9006. workbook = XLSX.utils.book_new(),
  9007. output;
  9008. workbook.SheetNames = [];
  9009. workbook.Sheets = {};
  9010. function generateSheet() {
  9011. var rows = [],
  9012. merges = [],
  9013. worksheet = {},
  9014. range = { s: { c: 0, r: 0 }, e: { c: list[0] ? list[0].columns.reduce(function (a, b) {
  9015. return a + (b && b.width ? b.width : 1);
  9016. }, 0) : 0, r: list.length } };
  9017. //parse row list
  9018. list.forEach(function (row, i) {
  9019. var rowData = [];
  9020. row.columns.forEach(function (col, j) {
  9021. if (col) {
  9022. rowData.push(!(col.value instanceof Date) && _typeof(col.value) === "object" ? JSON.stringify(col.value) : col.value);
  9023. if (col.width > 1 || col.height > -1) {
  9024. merges.push({ s: { r: i, c: j }, e: { r: i + col.height - 1, c: j + col.width - 1 } });
  9025. }
  9026. } else {
  9027. rowData.push("");
  9028. }
  9029. });
  9030. rows.push(rowData);
  9031. });
  9032. //convert rows to worksheet
  9033. XLSX.utils.sheet_add_aoa(worksheet, rows);
  9034. worksheet['!ref'] = XLSX.utils.encode_range(range);
  9035. if (merges.length) {
  9036. worksheet["!merges"] = merges;
  9037. }
  9038. return worksheet;
  9039. }
  9040. if (options.sheetOnly) {
  9041. setFileContents(generateSheet());
  9042. return;
  9043. }
  9044. if (options.sheets) {
  9045. for (var sheet in options.sheets) {
  9046. if (options.sheets[sheet] === true) {
  9047. workbook.SheetNames.push(sheet);
  9048. workbook.Sheets[sheet] = generateSheet();
  9049. } else {
  9050. workbook.SheetNames.push(sheet);
  9051. this.modules.comms.send(options.sheets[sheet], "download", "intercept", {
  9052. type: "xlsx",
  9053. options: { sheetOnly: true },
  9054. active: self.active,
  9055. intercept: function intercept(data) {
  9056. workbook.Sheets[sheet] = data;
  9057. }
  9058. });
  9059. }
  9060. }
  9061. } else {
  9062. workbook.SheetNames.push(sheetName);
  9063. workbook.Sheets[sheetName] = generateSheet();
  9064. }
  9065. if (options.documentProcessing) {
  9066. workbook = options.documentProcessing(workbook);
  9067. }
  9068. //convert workbook to binary array
  9069. function s2ab(s) {
  9070. var buf = new ArrayBuffer(s.length);
  9071. var view = new Uint8Array(buf);
  9072. for (var i = 0; i != s.length; ++i) {
  9073. view[i] = s.charCodeAt(i) & 0xFF;
  9074. }return buf;
  9075. }
  9076. output = XLSX.write(workbook, { bookType: 'xlsx', bookSST: true, type: 'binary' });
  9077. setFileContents(s2ab(output), "application/octet-stream");
  9078. },
  9079. html: function html(list, options, setFileContents) {
  9080. if (this.modExists("export", true)) {
  9081. setFileContents(this.modules.export.genereateHTMLTable(list), "text/html");
  9082. }
  9083. }
  9084. };
  9085. Tabulator.prototype.registerModule("download", Download);
  9086. var Edit = function Edit(table) {
  9087. this.table = table; //hold Tabulator object
  9088. this.currentCell = false; //hold currently editing cell
  9089. this.mouseClick = false; //hold mousedown state to prevent click binding being overriden by editor opening
  9090. this.recursionBlock = false; //prevent focus recursion
  9091. this.invalidEdit = false;
  9092. this.editedCells = [];
  9093. };
  9094. //initialize column editor
  9095. Edit.prototype.initializeColumn = function (column) {
  9096. var self = this,
  9097. config = {
  9098. editor: false,
  9099. blocked: false,
  9100. check: column.definition.editable,
  9101. params: column.definition.editorParams || {}
  9102. };
  9103. //set column editor
  9104. switch (_typeof(column.definition.editor)) {
  9105. case "string":
  9106. if (column.definition.editor === "tick") {
  9107. column.definition.editor = "tickCross";
  9108. console.warn("DEPRECATION WARNING - the tick editor has been deprecated, please use the tickCross editor");
  9109. }
  9110. if (self.editors[column.definition.editor]) {
  9111. config.editor = self.editors[column.definition.editor];
  9112. } else {
  9113. console.warn("Editor Error - No such editor found: ", column.definition.editor);
  9114. }
  9115. break;
  9116. case "function":
  9117. config.editor = column.definition.editor;
  9118. break;
  9119. case "boolean":
  9120. if (column.definition.editor === true) {
  9121. if (typeof column.definition.formatter !== "function") {
  9122. if (column.definition.formatter === "tick") {
  9123. column.definition.formatter = "tickCross";
  9124. console.warn("DEPRECATION WARNING - the tick editor has been deprecated, please use the tickCross editor");
  9125. }
  9126. if (self.editors[column.definition.formatter]) {
  9127. config.editor = self.editors[column.definition.formatter];
  9128. } else {
  9129. config.editor = self.editors["input"];
  9130. }
  9131. } else {
  9132. console.warn("Editor Error - Cannot auto lookup editor for a custom formatter: ", column.definition.formatter);
  9133. }
  9134. }
  9135. break;
  9136. }
  9137. if (config.editor) {
  9138. column.modules.edit = config;
  9139. }
  9140. };
  9141. Edit.prototype.getCurrentCell = function () {
  9142. return this.currentCell ? this.currentCell.getComponent() : false;
  9143. };
  9144. Edit.prototype.clearEditor = function (cancel) {
  9145. var cell = this.currentCell,
  9146. cellEl;
  9147. this.invalidEdit = false;
  9148. if (cell) {
  9149. this.currentCell = false;
  9150. cellEl = cell.getElement();
  9151. if (cancel) {
  9152. cell.validate();
  9153. } else {
  9154. cellEl.classList.remove("tabulator-validation-fail");
  9155. }
  9156. cellEl.classList.remove("tabulator-editing");
  9157. while (cellEl.firstChild) {
  9158. cellEl.removeChild(cellEl.firstChild);
  9159. }cell.row.getElement().classList.remove("tabulator-row-editing");
  9160. }
  9161. };
  9162. Edit.prototype.cancelEdit = function () {
  9163. if (this.currentCell) {
  9164. var cell = this.currentCell;
  9165. var component = this.currentCell.getComponent();
  9166. this.clearEditor(true);
  9167. cell.setValueActual(cell.getValue());
  9168. cell.cellRendered();
  9169. if (cell.column.definition.editor == "textarea" || cell.column.definition.variableHeight) {
  9170. cell.row.normalizeHeight(true);
  9171. }
  9172. if (cell.column.cellEvents.cellEditCancelled) {
  9173. cell.column.cellEvents.cellEditCancelled.call(this.table, component);
  9174. }
  9175. this.table.options.cellEditCancelled.call(this.table, component);
  9176. }
  9177. };
  9178. //return a formatted value for a cell
  9179. Edit.prototype.bindEditor = function (cell) {
  9180. var self = this,
  9181. element = cell.getElement();
  9182. element.setAttribute("tabindex", 0);
  9183. element.addEventListener("click", function (e) {
  9184. if (!element.classList.contains("tabulator-editing")) {
  9185. element.focus({ preventScroll: true });
  9186. }
  9187. });
  9188. element.addEventListener("mousedown", function (e) {
  9189. if (e.button === 2) {
  9190. e.preventDefault();
  9191. } else {
  9192. self.mouseClick = true;
  9193. }
  9194. });
  9195. element.addEventListener("focus", function (e) {
  9196. if (!self.recursionBlock) {
  9197. self.edit(cell, e, false);
  9198. }
  9199. });
  9200. };
  9201. Edit.prototype.focusCellNoEvent = function (cell, block) {
  9202. this.recursionBlock = true;
  9203. if (!(block && this.table.browser === "ie")) {
  9204. cell.getElement().focus({ preventScroll: true });
  9205. }
  9206. this.recursionBlock = false;
  9207. };
  9208. Edit.prototype.editCell = function (cell, forceEdit) {
  9209. this.focusCellNoEvent(cell);
  9210. this.edit(cell, false, forceEdit);
  9211. };
  9212. Edit.prototype.focusScrollAdjust = function (cell) {
  9213. if (this.table.rowManager.getRenderMode() == "virtual") {
  9214. var topEdge = this.table.rowManager.element.scrollTop,
  9215. bottomEdge = this.table.rowManager.element.clientHeight + this.table.rowManager.element.scrollTop,
  9216. rowEl = cell.row.getElement(),
  9217. offset = rowEl.offsetTop;
  9218. if (rowEl.offsetTop < topEdge) {
  9219. this.table.rowManager.element.scrollTop -= topEdge - rowEl.offsetTop;
  9220. } else {
  9221. if (rowEl.offsetTop + rowEl.offsetHeight > bottomEdge) {
  9222. this.table.rowManager.element.scrollTop += rowEl.offsetTop + rowEl.offsetHeight - bottomEdge;
  9223. }
  9224. }
  9225. var leftEdge = this.table.rowManager.element.scrollLeft,
  9226. rightEdge = this.table.rowManager.element.clientWidth + this.table.rowManager.element.scrollLeft,
  9227. cellEl = cell.getElement(),
  9228. offset = cellEl.offsetLeft;
  9229. if (this.table.modExists("frozenColumns")) {
  9230. leftEdge += parseInt(this.table.modules.frozenColumns.leftMargin);
  9231. rightEdge -= parseInt(this.table.modules.frozenColumns.rightMargin);
  9232. }
  9233. if (cellEl.offsetLeft < leftEdge) {
  9234. this.table.rowManager.element.scrollLeft -= leftEdge - cellEl.offsetLeft;
  9235. } else {
  9236. if (cellEl.offsetLeft + cellEl.offsetWidth > rightEdge) {
  9237. this.table.rowManager.element.scrollLeft += cellEl.offsetLeft + cellEl.offsetWidth - rightEdge;
  9238. }
  9239. }
  9240. }
  9241. };
  9242. Edit.prototype.edit = function (cell, e, forceEdit) {
  9243. var self = this,
  9244. allowEdit = true,
  9245. rendered = function rendered() {},
  9246. element = cell.getElement(),
  9247. cellEditor,
  9248. component,
  9249. params;
  9250. //prevent editing if another cell is refusing to leave focus (eg. validation fail)
  9251. if (this.currentCell) {
  9252. if (!this.invalidEdit) {
  9253. this.cancelEdit();
  9254. }
  9255. return;
  9256. }
  9257. //handle successfull value change
  9258. function success(value) {
  9259. if (self.currentCell === cell) {
  9260. var valid = true;
  9261. if (cell.column.modules.validate && self.table.modExists("validate") && self.table.options.validationMode != "manual") {
  9262. valid = self.table.modules.validate.validate(cell.column.modules.validate, cell, value);
  9263. }
  9264. if (valid === true || self.table.options.validationMode === "highlight") {
  9265. self.clearEditor();
  9266. if (!cell.modules.edit) {
  9267. cell.modules.edit = {};
  9268. }
  9269. cell.modules.edit.edited = true;
  9270. if (self.editedCells.indexOf(cell) == -1) {
  9271. self.editedCells.push(cell);
  9272. }
  9273. cell.setValue(value, true);
  9274. if (self.table.options.dataTree && self.table.modExists("dataTree")) {
  9275. self.table.modules.dataTree.checkForRestyle(cell);
  9276. }
  9277. if (valid !== true) {
  9278. element.classList.add("tabulator-validation-fail");
  9279. self.table.options.validationFailed.call(self.table, cell.getComponent(), value, valid);
  9280. return false;
  9281. }
  9282. return true;
  9283. } else {
  9284. self.invalidEdit = true;
  9285. element.classList.add("tabulator-validation-fail");
  9286. self.focusCellNoEvent(cell, true);
  9287. rendered();
  9288. self.table.options.validationFailed.call(self.table, cell.getComponent(), value, valid);
  9289. return false;
  9290. }
  9291. } else {
  9292. // console.warn("Edit Success Error - cannot call success on a cell that is no longer being edited");
  9293. }
  9294. }
  9295. //handle aborted edit
  9296. function cancel() {
  9297. if (self.currentCell === cell) {
  9298. self.cancelEdit();
  9299. if (self.table.options.dataTree && self.table.modExists("dataTree")) {
  9300. self.table.modules.dataTree.checkForRestyle(cell);
  9301. }
  9302. } else {
  9303. // console.warn("Edit Success Error - cannot call cancel on a cell that is no longer being edited");
  9304. }
  9305. }
  9306. function onRendered(callback) {
  9307. rendered = callback;
  9308. }
  9309. if (!cell.column.modules.edit.blocked) {
  9310. if (e) {
  9311. e.stopPropagation();
  9312. }
  9313. switch (_typeof(cell.column.modules.edit.check)) {
  9314. case "function":
  9315. allowEdit = cell.column.modules.edit.check(cell.getComponent());
  9316. break;
  9317. case "boolean":
  9318. allowEdit = cell.column.modules.edit.check;
  9319. break;
  9320. }
  9321. if (allowEdit || forceEdit) {
  9322. self.cancelEdit();
  9323. self.currentCell = cell;
  9324. this.focusScrollAdjust(cell);
  9325. component = cell.getComponent();
  9326. if (this.mouseClick) {
  9327. this.mouseClick = false;
  9328. if (cell.column.cellEvents.cellClick) {
  9329. cell.column.cellEvents.cellClick.call(this.table, e, component);
  9330. }
  9331. }
  9332. if (cell.column.cellEvents.cellEditing) {
  9333. cell.column.cellEvents.cellEditing.call(this.table, component);
  9334. }
  9335. self.table.options.cellEditing.call(this.table, component);
  9336. params = typeof cell.column.modules.edit.params === "function" ? cell.column.modules.edit.params(component) : cell.column.modules.edit.params;
  9337. cellEditor = cell.column.modules.edit.editor.call(self, component, onRendered, success, cancel, params);
  9338. //if editor returned, add to DOM, if false, abort edit
  9339. if (cellEditor !== false) {
  9340. if (cellEditor instanceof Node) {
  9341. element.classList.add("tabulator-editing");
  9342. cell.row.getElement().classList.add("tabulator-row-editing");
  9343. while (element.firstChild) {
  9344. element.removeChild(element.firstChild);
  9345. }element.appendChild(cellEditor);
  9346. //trigger onRendered Callback
  9347. rendered();
  9348. //prevent editing from triggering rowClick event
  9349. var children = element.children;
  9350. for (var i = 0; i < children.length; i++) {
  9351. children[i].addEventListener("click", function (e) {
  9352. e.stopPropagation();
  9353. });
  9354. }
  9355. } else {
  9356. console.warn("Edit Error - Editor should return an instance of Node, the editor returned:", cellEditor);
  9357. element.blur();
  9358. return false;
  9359. }
  9360. } else {
  9361. element.blur();
  9362. return false;
  9363. }
  9364. return true;
  9365. } else {
  9366. this.mouseClick = false;
  9367. element.blur();
  9368. return false;
  9369. }
  9370. } else {
  9371. this.mouseClick = false;
  9372. element.blur();
  9373. return false;
  9374. }
  9375. };
  9376. Edit.prototype.maskInput = function (el, options) {
  9377. var mask = options.mask,
  9378. maskLetter = typeof options.maskLetterChar !== "undefined" ? options.maskLetterChar : "A",
  9379. maskNumber = typeof options.maskNumberChar !== "undefined" ? options.maskNumberChar : "9",
  9380. maskWildcard = typeof options.maskWildcardChar !== "undefined" ? options.maskWildcardChar : "*",
  9381. success = false;
  9382. function fillSymbols(index) {
  9383. var symbol = mask[index];
  9384. if (typeof symbol !== "undefined" && symbol !== maskWildcard && symbol !== maskLetter && symbol !== maskNumber) {
  9385. el.value = el.value + "" + symbol;
  9386. fillSymbols(index + 1);
  9387. }
  9388. }
  9389. el.addEventListener("keydown", function (e) {
  9390. var index = el.value.length,
  9391. char = e.key;
  9392. if (e.keyCode > 46) {
  9393. if (index >= mask.length) {
  9394. e.preventDefault();
  9395. e.stopPropagation();
  9396. success = false;
  9397. return false;
  9398. } else {
  9399. switch (mask[index]) {
  9400. case maskLetter:
  9401. if (char.toUpperCase() == char.toLowerCase()) {
  9402. e.preventDefault();
  9403. e.stopPropagation();
  9404. success = false;
  9405. return false;
  9406. }
  9407. break;
  9408. case maskNumber:
  9409. if (isNaN(char)) {
  9410. e.preventDefault();
  9411. e.stopPropagation();
  9412. success = false;
  9413. return false;
  9414. }
  9415. break;
  9416. case maskWildcard:
  9417. break;
  9418. default:
  9419. if (char !== mask[index]) {
  9420. e.preventDefault();
  9421. e.stopPropagation();
  9422. success = false;
  9423. return false;
  9424. }
  9425. }
  9426. }
  9427. success = true;
  9428. }
  9429. return;
  9430. });
  9431. el.addEventListener("keyup", function (e) {
  9432. if (e.keyCode > 46) {
  9433. if (options.maskAutoFill) {
  9434. fillSymbols(el.value.length);
  9435. }
  9436. }
  9437. });
  9438. if (!el.placeholder) {
  9439. el.placeholder = mask;
  9440. }
  9441. if (options.maskAutoFill) {
  9442. fillSymbols(el.value.length);
  9443. }
  9444. };
  9445. Edit.prototype.getEditedCells = function () {
  9446. var output = [];
  9447. this.editedCells.forEach(function (cell) {
  9448. output.push(cell.getComponent());
  9449. });
  9450. return output;
  9451. };
  9452. Edit.prototype.clearEdited = function (cell) {
  9453. var editIndex;
  9454. if (cell.modules.validate && cell.modules.edit && cell.modules.edit.edited) {
  9455. cell.modules.validate.invalid = false;
  9456. editIndex = this.editedCells.indexOf(cell);
  9457. if (editIndex > -1) {
  9458. this.editedCells.splice(editIndex, 1);
  9459. }
  9460. }
  9461. };
  9462. //default data editors
  9463. Edit.prototype.editors = {
  9464. //input element
  9465. input: function input(cell, onRendered, success, cancel, editorParams) {
  9466. //create and style input
  9467. var cellValue = cell.getValue(),
  9468. input = document.createElement("input");
  9469. input.setAttribute("type", editorParams.search ? "search" : "text");
  9470. input.style.padding = "4px";
  9471. input.style.width = "100%";
  9472. input.style.boxSizing = "border-box";
  9473. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  9474. for (var key in editorParams.elementAttributes) {
  9475. if (key.charAt(0) == "+") {
  9476. key = key.slice(1);
  9477. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  9478. } else {
  9479. input.setAttribute(key, editorParams.elementAttributes[key]);
  9480. }
  9481. }
  9482. }
  9483. input.value = typeof cellValue !== "undefined" ? cellValue : "";
  9484. onRendered(function () {
  9485. input.focus({ preventScroll: true });
  9486. input.style.height = "100%";
  9487. });
  9488. function onChange(e) {
  9489. if ((cellValue === null || typeof cellValue === "undefined") && input.value !== "" || input.value !== cellValue) {
  9490. if (success(input.value)) {
  9491. cellValue = input.value; //persist value if successfully validated incase editor is used as header filter
  9492. }
  9493. } else {
  9494. cancel();
  9495. }
  9496. }
  9497. //submit new value on blur or change
  9498. input.addEventListener("change", onChange);
  9499. input.addEventListener("blur", onChange);
  9500. //submit new value on enter
  9501. input.addEventListener("keydown", function (e) {
  9502. switch (e.keyCode) {
  9503. // case 9:
  9504. case 13:
  9505. onChange(e);
  9506. break;
  9507. case 27:
  9508. cancel();
  9509. break;
  9510. case 35:
  9511. case 36:
  9512. e.stopPropagation();
  9513. break;
  9514. }
  9515. });
  9516. if (editorParams.mask) {
  9517. this.table.modules.edit.maskInput(input, editorParams);
  9518. }
  9519. return input;
  9520. },
  9521. //resizable text area element
  9522. textarea: function textarea(cell, onRendered, success, cancel, editorParams) {
  9523. var self = this,
  9524. cellValue = cell.getValue(),
  9525. vertNav = editorParams.verticalNavigation || "hybrid",
  9526. value = String(cellValue !== null && typeof cellValue !== "undefined" ? cellValue : ""),
  9527. count = (value.match(/(?:\r\n|\r|\n)/g) || []).length + 1,
  9528. input = document.createElement("textarea"),
  9529. scrollHeight = 0;
  9530. //create and style input
  9531. input.style.display = "block";
  9532. input.style.padding = "2px";
  9533. input.style.height = "100%";
  9534. input.style.width = "100%";
  9535. input.style.boxSizing = "border-box";
  9536. input.style.whiteSpace = "pre-wrap";
  9537. input.style.resize = "none";
  9538. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  9539. for (var key in editorParams.elementAttributes) {
  9540. if (key.charAt(0) == "+") {
  9541. key = key.slice(1);
  9542. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  9543. } else {
  9544. input.setAttribute(key, editorParams.elementAttributes[key]);
  9545. }
  9546. }
  9547. }
  9548. input.value = value;
  9549. onRendered(function () {
  9550. input.focus({ preventScroll: true });
  9551. input.style.height = "100%";
  9552. input.scrollHeight;
  9553. input.style.height = input.scrollHeight + "px";
  9554. cell.getRow().normalizeHeight();
  9555. });
  9556. function onChange(e) {
  9557. if ((cellValue === null || typeof cellValue === "undefined") && input.value !== "" || input.value !== cellValue) {
  9558. if (success(input.value)) {
  9559. cellValue = input.value; //persist value if successfully validated incase editor is used as header filter
  9560. }
  9561. setTimeout(function () {
  9562. cell.getRow().normalizeHeight();
  9563. }, 300);
  9564. } else {
  9565. cancel();
  9566. }
  9567. }
  9568. //submit new value on blur or change
  9569. input.addEventListener("change", onChange);
  9570. input.addEventListener("blur", onChange);
  9571. input.addEventListener("keyup", function () {
  9572. input.style.height = "";
  9573. var heightNow = input.scrollHeight;
  9574. input.style.height = heightNow + "px";
  9575. if (heightNow != scrollHeight) {
  9576. scrollHeight = heightNow;
  9577. cell.getRow().normalizeHeight();
  9578. }
  9579. });
  9580. input.addEventListener("keydown", function (e) {
  9581. switch (e.keyCode) {
  9582. case 27:
  9583. cancel();
  9584. break;
  9585. case 38:
  9586. //up arrow
  9587. if (vertNav == "editor" || vertNav == "hybrid" && input.selectionStart) {
  9588. e.stopImmediatePropagation();
  9589. e.stopPropagation();
  9590. }
  9591. break;
  9592. case 40:
  9593. //down arrow
  9594. if (vertNav == "editor" || vertNav == "hybrid" && input.selectionStart !== input.value.length) {
  9595. e.stopImmediatePropagation();
  9596. e.stopPropagation();
  9597. }
  9598. break;
  9599. case 35:
  9600. case 36:
  9601. e.stopPropagation();
  9602. break;
  9603. }
  9604. });
  9605. if (editorParams.mask) {
  9606. this.table.modules.edit.maskInput(input, editorParams);
  9607. }
  9608. return input;
  9609. },
  9610. //input element with type of number
  9611. number: function number(cell, onRendered, success, cancel, editorParams) {
  9612. var cellValue = cell.getValue(),
  9613. vertNav = editorParams.verticalNavigation || "editor",
  9614. input = document.createElement("input");
  9615. input.setAttribute("type", "number");
  9616. if (typeof editorParams.max != "undefined") {
  9617. input.setAttribute("max", editorParams.max);
  9618. }
  9619. if (typeof editorParams.min != "undefined") {
  9620. input.setAttribute("min", editorParams.min);
  9621. }
  9622. if (typeof editorParams.step != "undefined") {
  9623. input.setAttribute("step", editorParams.step);
  9624. }
  9625. //create and style input
  9626. input.style.padding = "4px";
  9627. input.style.width = "100%";
  9628. input.style.boxSizing = "border-box";
  9629. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  9630. for (var key in editorParams.elementAttributes) {
  9631. if (key.charAt(0) == "+") {
  9632. key = key.slice(1);
  9633. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  9634. } else {
  9635. input.setAttribute(key, editorParams.elementAttributes[key]);
  9636. }
  9637. }
  9638. }
  9639. input.value = cellValue;
  9640. var blurFunc = function blurFunc(e) {
  9641. onChange();
  9642. };
  9643. onRendered(function () {
  9644. //submit new value on blur
  9645. input.removeEventListener("blur", blurFunc);
  9646. input.focus({ preventScroll: true });
  9647. input.style.height = "100%";
  9648. //submit new value on blur
  9649. input.addEventListener("blur", blurFunc);
  9650. });
  9651. function onChange() {
  9652. var value = input.value;
  9653. if (!isNaN(value) && value !== "") {
  9654. value = Number(value);
  9655. }
  9656. if (value !== cellValue) {
  9657. if (success(value)) {
  9658. cellValue = value; //persist value if successfully validated incase editor is used as header filter
  9659. }
  9660. } else {
  9661. cancel();
  9662. }
  9663. }
  9664. //submit new value on enter
  9665. input.addEventListener("keydown", function (e) {
  9666. switch (e.keyCode) {
  9667. case 13:
  9668. // case 9:
  9669. onChange();
  9670. break;
  9671. case 27:
  9672. cancel();
  9673. break;
  9674. case 38: //up arrow
  9675. case 40:
  9676. //down arrow
  9677. if (vertNav == "editor") {
  9678. e.stopImmediatePropagation();
  9679. e.stopPropagation();
  9680. }
  9681. break;
  9682. case 35:
  9683. case 36:
  9684. e.stopPropagation();
  9685. break;
  9686. }
  9687. });
  9688. if (editorParams.mask) {
  9689. this.table.modules.edit.maskInput(input, editorParams);
  9690. }
  9691. return input;
  9692. },
  9693. //input element with type of number
  9694. range: function range(cell, onRendered, success, cancel, editorParams) {
  9695. var cellValue = cell.getValue(),
  9696. input = document.createElement("input");
  9697. input.setAttribute("type", "range");
  9698. if (typeof editorParams.max != "undefined") {
  9699. input.setAttribute("max", editorParams.max);
  9700. }
  9701. if (typeof editorParams.min != "undefined") {
  9702. input.setAttribute("min", editorParams.min);
  9703. }
  9704. if (typeof editorParams.step != "undefined") {
  9705. input.setAttribute("step", editorParams.step);
  9706. }
  9707. //create and style input
  9708. input.style.padding = "4px";
  9709. input.style.width = "100%";
  9710. input.style.boxSizing = "border-box";
  9711. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  9712. for (var key in editorParams.elementAttributes) {
  9713. if (key.charAt(0) == "+") {
  9714. key = key.slice(1);
  9715. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  9716. } else {
  9717. input.setAttribute(key, editorParams.elementAttributes[key]);
  9718. }
  9719. }
  9720. }
  9721. input.value = cellValue;
  9722. onRendered(function () {
  9723. input.focus({ preventScroll: true });
  9724. input.style.height = "100%";
  9725. });
  9726. function onChange() {
  9727. var value = input.value;
  9728. if (!isNaN(value) && value !== "") {
  9729. value = Number(value);
  9730. }
  9731. if (value != cellValue) {
  9732. if (success(value)) {
  9733. cellValue = value; //persist value if successfully validated incase editor is used as header filter
  9734. }
  9735. } else {
  9736. cancel();
  9737. }
  9738. }
  9739. //submit new value on blur
  9740. input.addEventListener("blur", function (e) {
  9741. onChange();
  9742. });
  9743. //submit new value on enter
  9744. input.addEventListener("keydown", function (e) {
  9745. switch (e.keyCode) {
  9746. case 13:
  9747. // case 9:
  9748. onChange();
  9749. break;
  9750. case 27:
  9751. cancel();
  9752. break;
  9753. }
  9754. });
  9755. return input;
  9756. },
  9757. //select
  9758. select: function select(cell, onRendered, success, cancel, editorParams) {
  9759. var _this53 = this;
  9760. var self = this,
  9761. cellEl = cell.getElement(),
  9762. initialValue = cell.getValue(),
  9763. vertNav = editorParams.verticalNavigation || "editor",
  9764. initialDisplayValue = typeof initialValue !== "undefined" || initialValue === null ? Array.isArray(initialValue) ? initialValue : [initialValue] : typeof editorParams.defaultValue !== "undefined" ? editorParams.defaultValue : [],
  9765. input = document.createElement("input"),
  9766. listEl = document.createElement("div"),
  9767. multiselect = editorParams.multiselect,
  9768. dataItems = [],
  9769. currentItem = {},
  9770. displayItems = [],
  9771. currentItems = [],
  9772. blurable = true,
  9773. blockListShow = false;
  9774. if (Array.isArray(editorParams) || !Array.isArray(editorParams) && (typeof editorParams === 'undefined' ? 'undefined' : _typeof(editorParams)) === "object" && !editorParams.values) {
  9775. 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");
  9776. editorParams = { values: editorParams };
  9777. }
  9778. function getUniqueColumnValues(field) {
  9779. var output = {},
  9780. data = self.table.getData(),
  9781. column;
  9782. if (field) {
  9783. column = self.table.columnManager.getColumnByField(field);
  9784. } else {
  9785. column = cell.getColumn()._getSelf();
  9786. }
  9787. if (column) {
  9788. data.forEach(function (row) {
  9789. var val = column.getFieldValue(row);
  9790. if (val !== null && typeof val !== "undefined" && val !== "") {
  9791. output[val] = true;
  9792. }
  9793. });
  9794. if (editorParams.sortValuesList) {
  9795. if (editorParams.sortValuesList == "asc") {
  9796. output = Object.keys(output).sort();
  9797. } else {
  9798. output = Object.keys(output).sort().reverse();
  9799. }
  9800. } else {
  9801. output = Object.keys(output);
  9802. }
  9803. } else {
  9804. console.warn("unable to find matching column to create select lookup list:", field);
  9805. }
  9806. return output;
  9807. }
  9808. function parseItems(inputValues, curentValues) {
  9809. var dataList = [];
  9810. var displayList = [];
  9811. function processComplexListItem(item) {
  9812. var item = {
  9813. label: item.label,
  9814. value: item.value,
  9815. itemParams: item.itemParams,
  9816. elementAttributes: item.elementAttributes,
  9817. element: false
  9818. };
  9819. // if(item.value === curentValue || (!isNaN(parseFloat(item.value)) && !isNaN(parseFloat(item.value)) && parseFloat(item.value) === parseFloat(curentValue))){
  9820. // setCurrentItem(item);
  9821. // }
  9822. if (curentValues.indexOf(item.value) > -1) {
  9823. setItem(item);
  9824. }
  9825. dataList.push(item);
  9826. displayList.push(item);
  9827. return item;
  9828. }
  9829. if (typeof inputValues == "function") {
  9830. inputValues = inputValues(cell);
  9831. }
  9832. if (Array.isArray(inputValues)) {
  9833. inputValues.forEach(function (value) {
  9834. var item;
  9835. if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === "object") {
  9836. if (value.options) {
  9837. item = {
  9838. label: value.label,
  9839. group: true,
  9840. itemParams: value.itemParams,
  9841. elementAttributes: value.elementAttributes,
  9842. element: false
  9843. };
  9844. displayList.push(item);
  9845. value.options.forEach(function (item) {
  9846. processComplexListItem(item);
  9847. });
  9848. } else {
  9849. processComplexListItem(value);
  9850. }
  9851. } else {
  9852. item = {
  9853. label: value,
  9854. value: value,
  9855. element: false
  9856. };
  9857. // if(item.value === curentValue || (!isNaN(parseFloat(item.value)) && !isNaN(parseFloat(item.value)) && parseFloat(item.value) === parseFloat(curentValue))){
  9858. // setCurrentItem(item);
  9859. // }
  9860. if (curentValues.indexOf(item.value) > -1) {
  9861. setItem(item);
  9862. }
  9863. dataList.push(item);
  9864. displayList.push(item);
  9865. }
  9866. });
  9867. } else {
  9868. for (var key in inputValues) {
  9869. var item = {
  9870. label: inputValues[key],
  9871. value: key,
  9872. element: false
  9873. };
  9874. // if(item.value === curentValue || (!isNaN(parseFloat(item.value)) && !isNaN(parseFloat(item.value)) && parseFloat(item.value) === parseFloat(curentValue))){
  9875. // setCurrentItem(item);
  9876. // }
  9877. if (curentValues.indexOf(item.value) > -1) {
  9878. setItem(item);
  9879. }
  9880. dataList.push(item);
  9881. displayList.push(item);
  9882. }
  9883. }
  9884. dataItems = dataList;
  9885. displayItems = displayList;
  9886. fillList();
  9887. }
  9888. function fillList() {
  9889. while (listEl.firstChild) {
  9890. listEl.removeChild(listEl.firstChild);
  9891. }displayItems.forEach(function (item) {
  9892. var el = item.element;
  9893. if (!el) {
  9894. el = document.createElement("div");
  9895. item.label = editorParams.listItemFormatter ? editorParams.listItemFormatter(item.value, item.label, cell, el, item.itemParams) : item.label;
  9896. if (item.group) {
  9897. el.classList.add("tabulator-edit-select-list-group");
  9898. el.tabIndex = 0;
  9899. el.innerHTML = item.label === "" ? "&nbsp;" : item.label;
  9900. } else {
  9901. el.classList.add("tabulator-edit-select-list-item");
  9902. el.tabIndex = 0;
  9903. el.innerHTML = item.label === "" ? "&nbsp;" : item.label;
  9904. el.addEventListener("click", function () {
  9905. blockListShow = true;
  9906. setTimeout(function () {
  9907. blockListShow = false;
  9908. }, 10);
  9909. // setCurrentItem(item);
  9910. // chooseItem();
  9911. if (multiselect) {
  9912. toggleItem(item);
  9913. input.focus();
  9914. } else {
  9915. chooseItem(item);
  9916. }
  9917. });
  9918. // if(item === currentItem){
  9919. // el.classList.add("active");
  9920. // }
  9921. if (currentItems.indexOf(item) > -1) {
  9922. el.classList.add("active");
  9923. }
  9924. }
  9925. if (item.elementAttributes && _typeof(item.elementAttributes) == "object") {
  9926. for (var key in item.elementAttributes) {
  9927. if (key.charAt(0) == "+") {
  9928. key = key.slice(1);
  9929. el.setAttribute(key, input.getAttribute(key) + item.elementAttributes["+" + key]);
  9930. } else {
  9931. el.setAttribute(key, item.elementAttributes[key]);
  9932. }
  9933. }
  9934. }
  9935. el.addEventListener("mousedown", function () {
  9936. blurable = false;
  9937. setTimeout(function () {
  9938. blurable = true;
  9939. }, 10);
  9940. });
  9941. item.element = el;
  9942. }
  9943. listEl.appendChild(el);
  9944. });
  9945. }
  9946. function setCurrentItem(item, active) {
  9947. if (!multiselect && currentItem && currentItem.element) {
  9948. currentItem.element.classList.remove("active");
  9949. }
  9950. if (currentItem && currentItem.element) {
  9951. currentItem.element.classList.remove("focused");
  9952. }
  9953. currentItem = item;
  9954. if (item.element) {
  9955. item.element.classList.add("focused");
  9956. if (active) {
  9957. item.element.classList.add("active");
  9958. }
  9959. }
  9960. }
  9961. // function chooseItem(){
  9962. // hideList();
  9963. // if(initialValue !== currentItem.value){
  9964. // initialValue = currentItem.value;
  9965. // success(currentItem.value);
  9966. // }else{
  9967. // cancel();
  9968. // }
  9969. // }
  9970. function setItem(item) {
  9971. var index = currentItems.indexOf(item);
  9972. if (index == -1) {
  9973. currentItems.push(item);
  9974. setCurrentItem(item, true);
  9975. }
  9976. fillInput();
  9977. }
  9978. function unsetItem(index) {
  9979. var item = currentItems[index];
  9980. if (index > -1) {
  9981. currentItems.splice(index, 1);
  9982. if (item.element) {
  9983. item.element.classList.remove("active");
  9984. }
  9985. }
  9986. }
  9987. function toggleItem(item) {
  9988. if (!item) {
  9989. item = currentItem;
  9990. }
  9991. var index = currentItems.indexOf(item);
  9992. if (index > -1) {
  9993. unsetItem(index);
  9994. } else {
  9995. if (multiselect !== true && currentItems.length >= multiselect) {
  9996. unsetItem(0);
  9997. }
  9998. setItem(item);
  9999. }
  10000. fillInput();
  10001. }
  10002. function chooseItem(item) {
  10003. hideList();
  10004. if (!item) {
  10005. item = currentItem;
  10006. }
  10007. if (item) {
  10008. input.value = item.label;
  10009. success(item.value);
  10010. }
  10011. initialDisplayValue = input.value;
  10012. }
  10013. function chooseItems(silent) {
  10014. if (!silent) {
  10015. hideList();
  10016. }
  10017. var output = [];
  10018. currentItems.forEach(function (item) {
  10019. output.push(item.value);
  10020. });
  10021. initialDisplayValue = input.value;
  10022. success(output);
  10023. }
  10024. function fillInput() {
  10025. var output = [];
  10026. currentItems.forEach(function (item) {
  10027. output.push(item.label);
  10028. });
  10029. input.value = output.join(", ");
  10030. if (self.currentCell === false) {
  10031. chooseItems(true);
  10032. }
  10033. }
  10034. function unsetItems() {
  10035. var len = currentItems.length;
  10036. for (var _i9 = 0; _i9 < len; _i9++) {
  10037. unsetItem(0);
  10038. }
  10039. }
  10040. function cancelItem() {
  10041. hideList();
  10042. cancel();
  10043. }
  10044. function showList() {
  10045. currentItems = [];
  10046. if (!listEl.parentNode) {
  10047. if (editorParams.values === true) {
  10048. parseItems(getUniqueColumnValues(), initialDisplayValue);
  10049. } else if (typeof editorParams.values === "string") {
  10050. parseItems(getUniqueColumnValues(editorParams.values), initialDisplayValue);
  10051. } else {
  10052. parseItems(editorParams.values || [], initialDisplayValue);
  10053. }
  10054. var offset = Tabulator.prototype.helpers.elOffset(cellEl);
  10055. listEl.style.minWidth = cellEl.offsetWidth + "px";
  10056. listEl.style.top = offset.top + cellEl.offsetHeight + "px";
  10057. listEl.style.left = offset.left + "px";
  10058. listEl.addEventListener("mousedown", function (e) {
  10059. blurable = false;
  10060. setTimeout(function () {
  10061. blurable = true;
  10062. }, 10);
  10063. });
  10064. document.body.appendChild(listEl);
  10065. }
  10066. }
  10067. function hideList() {
  10068. if (listEl.parentNode) {
  10069. listEl.parentNode.removeChild(listEl);
  10070. }
  10071. removeScrollListener();
  10072. }
  10073. function removeScrollListener() {
  10074. self.table.rowManager.element.removeEventListener("scroll", cancelItem);
  10075. }
  10076. //style input
  10077. input.setAttribute("type", "text");
  10078. input.style.padding = "4px";
  10079. input.style.width = "100%";
  10080. input.style.boxSizing = "border-box";
  10081. input.style.cursor = "default";
  10082. input.readOnly = this.currentCell != false;
  10083. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  10084. for (var key in editorParams.elementAttributes) {
  10085. if (key.charAt(0) == "+") {
  10086. key = key.slice(1);
  10087. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  10088. } else {
  10089. input.setAttribute(key, editorParams.elementAttributes[key]);
  10090. }
  10091. }
  10092. }
  10093. input.value = typeof initialValue !== "undefined" || initialValue === null ? initialValue : "";
  10094. // if(editorParams.values === true){
  10095. // parseItems(getUniqueColumnValues(), initialValue);
  10096. // }else if(typeof editorParams.values === "string"){
  10097. // parseItems(getUniqueColumnValues(editorParams.values), initialValue);
  10098. // }else{
  10099. // parseItems(editorParams.values || [], initialValue);
  10100. // }
  10101. input.addEventListener("search", function (e) {
  10102. if (!input.value) {
  10103. unsetItems();
  10104. chooseItems();
  10105. }
  10106. });
  10107. //allow key based navigation
  10108. input.addEventListener("keydown", function (e) {
  10109. var index;
  10110. switch (e.keyCode) {
  10111. case 38:
  10112. //up arrow
  10113. index = dataItems.indexOf(currentItem);
  10114. if (vertNav == "editor" || vertNav == "hybrid" && index) {
  10115. e.stopImmediatePropagation();
  10116. e.stopPropagation();
  10117. e.preventDefault();
  10118. if (index > 0) {
  10119. setCurrentItem(dataItems[index - 1], !multiselect);
  10120. }
  10121. }
  10122. break;
  10123. case 40:
  10124. //down arrow
  10125. index = dataItems.indexOf(currentItem);
  10126. if (vertNav == "editor" || vertNav == "hybrid" && index < dataItems.length - 1) {
  10127. e.stopImmediatePropagation();
  10128. e.stopPropagation();
  10129. e.preventDefault();
  10130. if (index < dataItems.length - 1) {
  10131. if (index == -1) {
  10132. setCurrentItem(dataItems[0], !multiselect);
  10133. } else {
  10134. setCurrentItem(dataItems[index + 1], !multiselect);
  10135. }
  10136. }
  10137. }
  10138. break;
  10139. case 37: //left arrow
  10140. case 39:
  10141. //right arrow
  10142. e.stopImmediatePropagation();
  10143. e.stopPropagation();
  10144. e.preventDefault();
  10145. break;
  10146. case 13:
  10147. //enter
  10148. // chooseItem();
  10149. if (multiselect) {
  10150. toggleItem();
  10151. } else {
  10152. chooseItem();
  10153. }
  10154. break;
  10155. case 27:
  10156. //escape
  10157. cancelItem();
  10158. break;
  10159. case 9:
  10160. //tab
  10161. break;
  10162. default:
  10163. if (self.currentCell === false) {
  10164. e.preventDefault();
  10165. }
  10166. }
  10167. });
  10168. input.addEventListener("blur", function (e) {
  10169. if (blurable) {
  10170. if (multiselect) {
  10171. chooseItems();
  10172. } else {
  10173. cancelItem();
  10174. }
  10175. }
  10176. });
  10177. input.addEventListener("focus", function (e) {
  10178. if (!blockListShow) {
  10179. showList();
  10180. }
  10181. });
  10182. //style list element
  10183. listEl = document.createElement("div");
  10184. listEl.classList.add("tabulator-edit-select-list");
  10185. onRendered(function () {
  10186. input.style.height = "100%";
  10187. input.focus({ preventScroll: true });
  10188. });
  10189. setTimeout(function () {
  10190. _this53.table.rowManager.element.addEventListener("scroll", cancelItem);
  10191. }, 10);
  10192. return input;
  10193. },
  10194. //autocomplete
  10195. autocomplete: function autocomplete(cell, onRendered, success, cancel, editorParams) {
  10196. var _this54 = this;
  10197. var self = this,
  10198. cellEl = cell.getElement(),
  10199. initialValue = cell.getValue(),
  10200. vertNav = editorParams.verticalNavigation || "editor",
  10201. initialDisplayValue = typeof initialValue !== "undefined" || initialValue === null ? initialValue : typeof editorParams.defaultValue !== "undefined" ? editorParams.defaultValue : "",
  10202. input = document.createElement("input"),
  10203. listEl = document.createElement("div"),
  10204. allItems = [],
  10205. displayItems = [],
  10206. values = [],
  10207. currentItem = false,
  10208. blurable = true,
  10209. uniqueColumnValues = false;
  10210. //style input
  10211. input.setAttribute("type", "search");
  10212. input.style.padding = "4px";
  10213. input.style.width = "100%";
  10214. input.style.boxSizing = "border-box";
  10215. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  10216. for (var key in editorParams.elementAttributes) {
  10217. if (key.charAt(0) == "+") {
  10218. key = key.slice(1);
  10219. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  10220. } else {
  10221. input.setAttribute(key, editorParams.elementAttributes[key]);
  10222. }
  10223. }
  10224. }
  10225. //style list element
  10226. listEl.classList.add("tabulator-edit-select-list");
  10227. listEl.addEventListener("mousedown", function (e) {
  10228. blurable = false;
  10229. setTimeout(function () {
  10230. blurable = true;
  10231. }, 10);
  10232. });
  10233. function genUniqueColumnValues() {
  10234. if (editorParams.values === true) {
  10235. uniqueColumnValues = getUniqueColumnValues();
  10236. } else if (typeof editorParams.values === "string") {
  10237. uniqueColumnValues = getUniqueColumnValues(editorParams.values);
  10238. }
  10239. }
  10240. function getUniqueColumnValues(field) {
  10241. var output = {},
  10242. data = self.table.getData(),
  10243. column;
  10244. if (field) {
  10245. column = self.table.columnManager.getColumnByField(field);
  10246. } else {
  10247. column = cell.getColumn()._getSelf();
  10248. }
  10249. if (column) {
  10250. data.forEach(function (row) {
  10251. var val = column.getFieldValue(row);
  10252. if (val !== null && typeof val !== "undefined" && val !== "") {
  10253. output[val] = true;
  10254. }
  10255. });
  10256. if (editorParams.sortValuesList) {
  10257. if (editorParams.sortValuesList == "asc") {
  10258. output = Object.keys(output).sort();
  10259. } else {
  10260. output = Object.keys(output).sort().reverse();
  10261. }
  10262. } else {
  10263. output = Object.keys(output);
  10264. }
  10265. } else {
  10266. console.warn("unable to find matching column to create autocomplete lookup list:", field);
  10267. }
  10268. return output;
  10269. }
  10270. function filterList(term, intialLoad) {
  10271. var matches = [],
  10272. values,
  10273. items,
  10274. searchEl;
  10275. //lookup base values list
  10276. if (uniqueColumnValues) {
  10277. values = uniqueColumnValues;
  10278. } else {
  10279. values = editorParams.values || [];
  10280. }
  10281. if (editorParams.searchFunc) {
  10282. matches = editorParams.searchFunc(term, values);
  10283. if (matches instanceof Promise) {
  10284. addNotice(typeof editorParams.searchingPlaceholder !== "undefined" ? editorParams.searchingPlaceholder : "Searching...");
  10285. matches.then(function (result) {
  10286. fillListIfNotEmpty(parseItems(result), intialLoad);
  10287. }).catch(function (err) {
  10288. console.err("error in autocomplete search promise:", err);
  10289. });
  10290. } else {
  10291. fillListIfNotEmpty(parseItems(matches), intialLoad);
  10292. }
  10293. } else {
  10294. items = parseItems(values);
  10295. if (term === "") {
  10296. if (editorParams.showListOnEmpty) {
  10297. matches = items;
  10298. }
  10299. } else {
  10300. items.forEach(function (item) {
  10301. if (item.value !== null || typeof item.value !== "undefined") {
  10302. if (String(item.value).toLowerCase().indexOf(String(term).toLowerCase()) > -1 || String(item.title).toLowerCase().indexOf(String(term).toLowerCase()) > -1) {
  10303. matches.push(item);
  10304. }
  10305. }
  10306. });
  10307. }
  10308. fillListIfNotEmpty(matches, intialLoad);
  10309. }
  10310. }
  10311. function addNotice(notice) {
  10312. var searchEl = document.createElement("div");
  10313. clearList();
  10314. if (notice !== false) {
  10315. searchEl.classList.add("tabulator-edit-select-list-notice");
  10316. searchEl.tabIndex = 0;
  10317. if (notice instanceof Node) {
  10318. searchEl.appendChild(notice);
  10319. } else {
  10320. searchEl.innerHTML = notice;
  10321. }
  10322. listEl.appendChild(searchEl);
  10323. }
  10324. }
  10325. function parseItems(inputValues) {
  10326. var itemList = [];
  10327. if (Array.isArray(inputValues)) {
  10328. inputValues.forEach(function (value) {
  10329. var item = {};
  10330. if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === "object") {
  10331. item.title = editorParams.listItemFormatter ? editorParams.listItemFormatter(value.value, value.label) : value.label;
  10332. item.value = value.value;
  10333. } else {
  10334. item.title = editorParams.listItemFormatter ? editorParams.listItemFormatter(value, value) : value;
  10335. item.value = value;
  10336. }
  10337. itemList.push(item);
  10338. });
  10339. } else {
  10340. for (var key in inputValues) {
  10341. var item = {
  10342. title: editorParams.listItemFormatter ? editorParams.listItemFormatter(key, inputValues[key]) : inputValues[key],
  10343. value: key
  10344. };
  10345. itemList.push(item);
  10346. }
  10347. }
  10348. return itemList;
  10349. }
  10350. function clearList() {
  10351. while (listEl.firstChild) {
  10352. listEl.removeChild(listEl.firstChild);
  10353. }
  10354. }
  10355. function fillListIfNotEmpty(items, intialLoad) {
  10356. if (items.length) {
  10357. fillList(items, intialLoad);
  10358. } else {
  10359. if (editorParams.emptyPlaceholder) {
  10360. addNotice(editorParams.emptyPlaceholder);
  10361. }
  10362. }
  10363. }
  10364. function fillList(items, intialLoad) {
  10365. var current = false;
  10366. clearList();
  10367. displayItems = items;
  10368. displayItems.forEach(function (item) {
  10369. var el = item.element;
  10370. if (!el) {
  10371. el = document.createElement("div");
  10372. el.classList.add("tabulator-edit-select-list-item");
  10373. el.tabIndex = 0;
  10374. el.innerHTML = item.title;
  10375. el.addEventListener("click", function (e) {
  10376. setCurrentItem(item);
  10377. chooseItem();
  10378. });
  10379. el.addEventListener("mousedown", function (e) {
  10380. blurable = false;
  10381. setTimeout(function () {
  10382. blurable = true;
  10383. }, 10);
  10384. });
  10385. item.element = el;
  10386. if (intialLoad && item.value == initialValue) {
  10387. input.value = item.title;
  10388. item.element.classList.add("active");
  10389. current = true;
  10390. }
  10391. if (item === currentItem) {
  10392. item.element.classList.add("active");
  10393. current = true;
  10394. }
  10395. }
  10396. listEl.appendChild(el);
  10397. });
  10398. if (!current) {
  10399. setCurrentItem(false);
  10400. }
  10401. }
  10402. function chooseItem() {
  10403. hideList();
  10404. if (currentItem) {
  10405. if (initialValue !== currentItem.value) {
  10406. initialValue = currentItem.value;
  10407. input.value = currentItem.title;
  10408. success(currentItem.value);
  10409. } else {
  10410. cancel();
  10411. }
  10412. } else {
  10413. if (editorParams.freetext) {
  10414. initialValue = input.value;
  10415. success(input.value);
  10416. } else {
  10417. if (editorParams.allowEmpty && input.value === "") {
  10418. initialValue = input.value;
  10419. success(input.value);
  10420. } else {
  10421. cancel();
  10422. }
  10423. }
  10424. }
  10425. }
  10426. function showList() {
  10427. if (!listEl.parentNode) {
  10428. while (listEl.firstChild) {
  10429. listEl.removeChild(listEl.firstChild);
  10430. }var offset = Tabulator.prototype.helpers.elOffset(cellEl);
  10431. listEl.style.minWidth = cellEl.offsetWidth + "px";
  10432. listEl.style.top = offset.top + cellEl.offsetHeight + "px";
  10433. listEl.style.left = offset.left + "px";
  10434. document.body.appendChild(listEl);
  10435. }
  10436. }
  10437. function setCurrentItem(item, showInputValue) {
  10438. if (currentItem && currentItem.element) {
  10439. currentItem.element.classList.remove("active");
  10440. }
  10441. currentItem = item;
  10442. if (item && item.element) {
  10443. item.element.classList.add("active");
  10444. }
  10445. }
  10446. function hideList() {
  10447. if (listEl.parentNode) {
  10448. listEl.parentNode.removeChild(listEl);
  10449. }
  10450. removeScrollListener();
  10451. }
  10452. function cancelItem() {
  10453. hideList();
  10454. cancel();
  10455. }
  10456. function removeScrollListener() {
  10457. self.table.rowManager.element.removeEventListener("scroll", cancelItem);
  10458. }
  10459. //allow key based navigation
  10460. input.addEventListener("keydown", function (e) {
  10461. var index;
  10462. switch (e.keyCode) {
  10463. case 38:
  10464. //up arrow
  10465. index = displayItems.indexOf(currentItem);
  10466. if (vertNav == "editor" || vertNav == "hybrid" && index) {
  10467. e.stopImmediatePropagation();
  10468. e.stopPropagation();
  10469. e.preventDefault();
  10470. if (index > 0) {
  10471. setCurrentItem(displayItems[index - 1]);
  10472. } else {
  10473. setCurrentItem(false);
  10474. }
  10475. }
  10476. break;
  10477. case 40:
  10478. //down arrow
  10479. index = displayItems.indexOf(currentItem);
  10480. if (vertNav == "editor" || vertNav == "hybrid" && index < displayItems.length - 1) {
  10481. e.stopImmediatePropagation();
  10482. e.stopPropagation();
  10483. e.preventDefault();
  10484. if (index < displayItems.length - 1) {
  10485. if (index == -1) {
  10486. setCurrentItem(displayItems[0]);
  10487. } else {
  10488. setCurrentItem(displayItems[index + 1]);
  10489. }
  10490. }
  10491. }
  10492. break;
  10493. case 37: //left arrow
  10494. case 39:
  10495. //right arrow
  10496. e.stopImmediatePropagation();
  10497. e.stopPropagation();
  10498. // e.preventDefault();
  10499. break;
  10500. case 13:
  10501. //enter
  10502. chooseItem();
  10503. break;
  10504. case 27:
  10505. //escape
  10506. cancelItem();
  10507. break;
  10508. case 36: //home
  10509. case 35:
  10510. //end
  10511. //prevent table navigation while using input element
  10512. e.stopImmediatePropagation();
  10513. break;
  10514. }
  10515. });
  10516. input.addEventListener("keyup", function (e) {
  10517. switch (e.keyCode) {
  10518. case 38: //up arrow
  10519. case 37: //left arrow
  10520. case 39: //up arrow
  10521. case 40: //right arrow
  10522. case 13: //enter
  10523. case 27:
  10524. //escape
  10525. break;
  10526. default:
  10527. filterList(input.value);
  10528. }
  10529. });
  10530. input.addEventListener("search", function (e) {
  10531. filterList(input.value);
  10532. });
  10533. input.addEventListener("blur", function (e) {
  10534. if (blurable) {
  10535. chooseItem();
  10536. }
  10537. });
  10538. input.addEventListener("focus", function (e) {
  10539. var value = initialDisplayValue;
  10540. genUniqueColumnValues();
  10541. showList();
  10542. input.value = value;
  10543. filterList(value, true);
  10544. });
  10545. onRendered(function () {
  10546. input.style.height = "100%";
  10547. input.focus({ preventScroll: true });
  10548. });
  10549. if (editorParams.mask) {
  10550. this.table.modules.edit.maskInput(input, editorParams);
  10551. }
  10552. setTimeout(function () {
  10553. _this54.table.rowManager.element.addEventListener("scroll", cancelItem);
  10554. }, 10);
  10555. genUniqueColumnValues();
  10556. input.value = initialDisplayValue;
  10557. filterList(initialDisplayValue, true);
  10558. return input;
  10559. },
  10560. //star rating
  10561. star: function star(cell, onRendered, success, cancel, editorParams) {
  10562. var self = this,
  10563. element = cell.getElement(),
  10564. value = cell.getValue(),
  10565. maxStars = element.getElementsByTagName("svg").length || 5,
  10566. size = element.getElementsByTagName("svg")[0] ? element.getElementsByTagName("svg")[0].getAttribute("width") : 14,
  10567. stars = [],
  10568. starsHolder = document.createElement("div"),
  10569. star = document.createElementNS('http://www.w3.org/2000/svg', "svg");
  10570. //change star type
  10571. function starChange(val) {
  10572. stars.forEach(function (star, i) {
  10573. if (i < val) {
  10574. if (self.table.browser == "ie") {
  10575. star.setAttribute("class", "tabulator-star-active");
  10576. } else {
  10577. star.classList.replace("tabulator-star-inactive", "tabulator-star-active");
  10578. }
  10579. 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 "/>';
  10580. } else {
  10581. if (self.table.browser == "ie") {
  10582. star.setAttribute("class", "tabulator-star-inactive");
  10583. } else {
  10584. star.classList.replace("tabulator-star-active", "tabulator-star-inactive");
  10585. }
  10586. 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 "/>';
  10587. }
  10588. });
  10589. }
  10590. //build stars
  10591. function buildStar(i) {
  10592. var starHolder = document.createElement("span");
  10593. var nextStar = star.cloneNode(true);
  10594. stars.push(nextStar);
  10595. starHolder.addEventListener("mouseenter", function (e) {
  10596. e.stopPropagation();
  10597. e.stopImmediatePropagation();
  10598. starChange(i);
  10599. });
  10600. starHolder.addEventListener("mousemove", function (e) {
  10601. e.stopPropagation();
  10602. e.stopImmediatePropagation();
  10603. });
  10604. starHolder.addEventListener("click", function (e) {
  10605. e.stopPropagation();
  10606. e.stopImmediatePropagation();
  10607. success(i);
  10608. element.blur();
  10609. });
  10610. starHolder.appendChild(nextStar);
  10611. starsHolder.appendChild(starHolder);
  10612. }
  10613. //handle keyboard navigation value change
  10614. function changeValue(val) {
  10615. value = val;
  10616. starChange(val);
  10617. }
  10618. //style cell
  10619. element.style.whiteSpace = "nowrap";
  10620. element.style.overflow = "hidden";
  10621. element.style.textOverflow = "ellipsis";
  10622. //style holding element
  10623. starsHolder.style.verticalAlign = "middle";
  10624. starsHolder.style.display = "inline-block";
  10625. starsHolder.style.padding = "4px";
  10626. //style star
  10627. star.setAttribute("width", size);
  10628. star.setAttribute("height", size);
  10629. star.setAttribute("viewBox", "0 0 512 512");
  10630. star.setAttribute("xml:space", "preserve");
  10631. star.style.padding = "0 1px";
  10632. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  10633. for (var key in editorParams.elementAttributes) {
  10634. if (key.charAt(0) == "+") {
  10635. key = key.slice(1);
  10636. starsHolder.setAttribute(key, starsHolder.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  10637. } else {
  10638. starsHolder.setAttribute(key, editorParams.elementAttributes[key]);
  10639. }
  10640. }
  10641. }
  10642. //create correct number of stars
  10643. for (var i = 1; i <= maxStars; i++) {
  10644. buildStar(i);
  10645. }
  10646. //ensure value does not exceed number of stars
  10647. value = Math.min(parseInt(value), maxStars);
  10648. // set initial styling of stars
  10649. starChange(value);
  10650. starsHolder.addEventListener("mousemove", function (e) {
  10651. starChange(0);
  10652. });
  10653. starsHolder.addEventListener("click", function (e) {
  10654. success(0);
  10655. });
  10656. element.addEventListener("blur", function (e) {
  10657. cancel();
  10658. });
  10659. //allow key based navigation
  10660. element.addEventListener("keydown", function (e) {
  10661. switch (e.keyCode) {
  10662. case 39:
  10663. //right arrow
  10664. changeValue(value + 1);
  10665. break;
  10666. case 37:
  10667. //left arrow
  10668. changeValue(value - 1);
  10669. break;
  10670. case 13:
  10671. //enter
  10672. success(value);
  10673. break;
  10674. case 27:
  10675. //escape
  10676. cancel();
  10677. break;
  10678. }
  10679. });
  10680. return starsHolder;
  10681. },
  10682. //draggable progress bar
  10683. progress: function progress(cell, onRendered, success, cancel, editorParams) {
  10684. var element = cell.getElement(),
  10685. max = typeof editorParams.max === "undefined" ? element.getElementsByTagName("div")[0].getAttribute("max") || 100 : editorParams.max,
  10686. min = typeof editorParams.min === "undefined" ? element.getElementsByTagName("div")[0].getAttribute("min") || 0 : editorParams.min,
  10687. percent = (max - min) / 100,
  10688. value = cell.getValue() || 0,
  10689. handle = document.createElement("div"),
  10690. bar = document.createElement("div"),
  10691. mouseDrag,
  10692. mouseDragWidth;
  10693. //set new value
  10694. function updateValue() {
  10695. var calcVal = percent * Math.round(bar.offsetWidth / (element.clientWidth / 100)) + min;
  10696. success(calcVal);
  10697. element.setAttribute("aria-valuenow", calcVal);
  10698. element.setAttribute("aria-label", value);
  10699. }
  10700. //style handle
  10701. handle.style.position = "absolute";
  10702. handle.style.right = "0";
  10703. handle.style.top = "0";
  10704. handle.style.bottom = "0";
  10705. handle.style.width = "5px";
  10706. handle.classList.add("tabulator-progress-handle");
  10707. //style bar
  10708. bar.style.display = "inline-block";
  10709. bar.style.position = "relative";
  10710. // bar.style.top = "8px";
  10711. // bar.style.bottom = "8px";
  10712. // bar.style.left = "4px";
  10713. // bar.style.marginRight = "4px";
  10714. bar.style.height = "100%";
  10715. bar.style.backgroundColor = "#488CE9";
  10716. bar.style.maxWidth = "100%";
  10717. bar.style.minWidth = "0%";
  10718. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  10719. for (var key in editorParams.elementAttributes) {
  10720. if (key.charAt(0) == "+") {
  10721. key = key.slice(1);
  10722. bar.setAttribute(key, bar.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  10723. } else {
  10724. bar.setAttribute(key, editorParams.elementAttributes[key]);
  10725. }
  10726. }
  10727. }
  10728. //style cell
  10729. element.style.padding = "4px 4px";
  10730. //make sure value is in range
  10731. value = Math.min(parseFloat(value), max);
  10732. value = Math.max(parseFloat(value), min);
  10733. //workout percentage
  10734. value = Math.round((value - min) / percent);
  10735. // bar.style.right = value + "%";
  10736. bar.style.width = value + "%";
  10737. element.setAttribute("aria-valuemin", min);
  10738. element.setAttribute("aria-valuemax", max);
  10739. bar.appendChild(handle);
  10740. handle.addEventListener("mousedown", function (e) {
  10741. mouseDrag = e.screenX;
  10742. mouseDragWidth = bar.offsetWidth;
  10743. });
  10744. handle.addEventListener("mouseover", function () {
  10745. handle.style.cursor = "ew-resize";
  10746. });
  10747. element.addEventListener("mousemove", function (e) {
  10748. if (mouseDrag) {
  10749. bar.style.width = mouseDragWidth + e.screenX - mouseDrag + "px";
  10750. }
  10751. });
  10752. element.addEventListener("mouseup", function (e) {
  10753. if (mouseDrag) {
  10754. e.stopPropagation();
  10755. e.stopImmediatePropagation();
  10756. mouseDrag = false;
  10757. mouseDragWidth = false;
  10758. updateValue();
  10759. }
  10760. });
  10761. //allow key based navigation
  10762. element.addEventListener("keydown", function (e) {
  10763. switch (e.keyCode) {
  10764. case 39:
  10765. //right arrow
  10766. e.preventDefault();
  10767. bar.style.width = bar.clientWidth + element.clientWidth / 100 + "px";
  10768. break;
  10769. case 37:
  10770. //left arrow
  10771. e.preventDefault();
  10772. bar.style.width = bar.clientWidth - element.clientWidth / 100 + "px";
  10773. break;
  10774. case 9: //tab
  10775. case 13:
  10776. //enter
  10777. updateValue();
  10778. break;
  10779. case 27:
  10780. //escape
  10781. cancel();
  10782. break;
  10783. }
  10784. });
  10785. element.addEventListener("blur", function () {
  10786. cancel();
  10787. });
  10788. return bar;
  10789. },
  10790. //checkbox
  10791. tickCross: function tickCross(cell, onRendered, success, cancel, editorParams) {
  10792. var value = cell.getValue(),
  10793. input = document.createElement("input"),
  10794. tristate = editorParams.tristate,
  10795. indetermValue = typeof editorParams.indeterminateValue === "undefined" ? null : editorParams.indeterminateValue,
  10796. indetermState = false;
  10797. input.setAttribute("type", "checkbox");
  10798. input.style.marginTop = "5px";
  10799. input.style.boxSizing = "border-box";
  10800. if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
  10801. for (var key in editorParams.elementAttributes) {
  10802. if (key.charAt(0) == "+") {
  10803. key = key.slice(1);
  10804. input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
  10805. } else {
  10806. input.setAttribute(key, editorParams.elementAttributes[key]);
  10807. }
  10808. }
  10809. }
  10810. input.value = value;
  10811. if (tristate && (typeof value === "undefined" || value === indetermValue || value === "")) {
  10812. indetermState = true;
  10813. input.indeterminate = true;
  10814. }
  10815. if (this.table.browser != "firefox") {
  10816. //prevent blur issue on mac firefox
  10817. onRendered(function () {
  10818. input.focus({ preventScroll: true });
  10819. });
  10820. }
  10821. input.checked = value === true || value === "true" || value === "True" || value === 1;
  10822. onRendered(function () {
  10823. input.focus();
  10824. });
  10825. function setValue(blur) {
  10826. if (tristate) {
  10827. if (!blur) {
  10828. if (input.checked && !indetermState) {
  10829. input.checked = false;
  10830. input.indeterminate = true;
  10831. indetermState = true;
  10832. return indetermValue;
  10833. } else {
  10834. indetermState = false;
  10835. return input.checked;
  10836. }
  10837. } else {
  10838. if (indetermState) {
  10839. return indetermValue;
  10840. } else {
  10841. return input.checked;
  10842. }
  10843. }
  10844. } else {
  10845. return input.checked;
  10846. }
  10847. }
  10848. //submit new value on blur
  10849. input.addEventListener("change", function (e) {
  10850. success(setValue());
  10851. });
  10852. input.addEventListener("blur", function (e) {
  10853. success(setValue(true));
  10854. });
  10855. //submit new value on enter
  10856. input.addEventListener("keydown", function (e) {
  10857. if (e.keyCode == 13) {
  10858. success(setValue());
  10859. }
  10860. if (e.keyCode == 27) {
  10861. cancel();
  10862. }
  10863. });
  10864. return input;
  10865. }
  10866. };
  10867. Tabulator.prototype.registerModule("edit", Edit);
  10868. var ExportRow = function ExportRow(type, columns, component, indent) {
  10869. this.type = type;
  10870. this.columns = columns;
  10871. this.component = component || false;
  10872. this.indent = indent || 0;
  10873. };
  10874. var ExportColumn = function ExportColumn(value, component, width, height, depth) {
  10875. this.value = value;
  10876. this.component = component || false;
  10877. this.width = width;
  10878. this.height = height;
  10879. this.depth = depth;
  10880. };
  10881. var Export = function Export(table) {
  10882. this.table = table; //hold Tabulator object
  10883. this.config = {};
  10884. this.cloneTableStyle = true;
  10885. this.colVisProp = "";
  10886. };
  10887. Export.prototype.generateExportList = function (config, style, range, colVisProp) {
  10888. this.cloneTableStyle = style;
  10889. this.config = config || {};
  10890. this.colVisProp = colVisProp;
  10891. var headers = this.config.columnHeaders !== false ? this.headersToExportRows(this.generateColumnGroupHeaders()) : [];
  10892. var body = this.bodyToExportRows(this.rowLookup(range));
  10893. return headers.concat(body);
  10894. };
  10895. Export.prototype.genereateTable = function (config, style, range, colVisProp) {
  10896. var list = this.generateExportList(config, style, range, colVisProp);
  10897. return this.genereateTableElement(list);
  10898. };
  10899. Export.prototype.rowLookup = function (range) {
  10900. var _this55 = this;
  10901. var rows = [];
  10902. if (typeof range == "function") {
  10903. range.call(this.table).forEach(function (row) {
  10904. row = _this55.table.rowManager.findRow(row);
  10905. if (row) {
  10906. rows.push(row);
  10907. }
  10908. });
  10909. } else {
  10910. switch (range) {
  10911. case true:
  10912. case "visible":
  10913. rows = this.table.rowManager.getVisibleRows(true);
  10914. break;
  10915. case "all":
  10916. rows = this.table.rowManager.rows;
  10917. break;
  10918. case "selected":
  10919. rows = this.table.modules.selectRow.selectedRows;
  10920. break;
  10921. case "active":
  10922. default:
  10923. if (this.table.options.pagination) {
  10924. rows = this.table.rowManager.getDisplayRows(this.table.rowManager.displayRows.length - 2);
  10925. } else {
  10926. rows = this.table.rowManager.getDisplayRows();
  10927. }
  10928. }
  10929. }
  10930. return Object.assign([], rows);
  10931. };
  10932. Export.prototype.generateColumnGroupHeaders = function () {
  10933. var _this56 = this;
  10934. var output = [];
  10935. var columns = this.config.columnGroups !== false ? this.table.columnManager.columns : this.table.columnManager.columnsByIndex;
  10936. columns.forEach(function (column) {
  10937. var colData = _this56.processColumnGroup(column);
  10938. if (colData) {
  10939. output.push(colData);
  10940. }
  10941. });
  10942. return output;
  10943. };
  10944. Export.prototype.processColumnGroup = function (column) {
  10945. var _this57 = this;
  10946. var subGroups = column.columns,
  10947. maxDepth = 0,
  10948. title = column.definition["title" + (this.colVisProp.charAt(0).toUpperCase() + this.colVisProp.slice(1))] || column.definition.title;
  10949. var groupData = {
  10950. title: title,
  10951. column: column,
  10952. depth: 1
  10953. };
  10954. if (subGroups.length) {
  10955. groupData.subGroups = [];
  10956. groupData.width = 0;
  10957. subGroups.forEach(function (subGroup) {
  10958. var subGroupData = _this57.processColumnGroup(subGroup);
  10959. if (subGroupData) {
  10960. groupData.width += subGroupData.width;
  10961. groupData.subGroups.push(subGroupData);
  10962. if (subGroupData.depth > maxDepth) {
  10963. maxDepth = subGroupData.depth;
  10964. }
  10965. }
  10966. });
  10967. groupData.depth += maxDepth;
  10968. if (!groupData.width) {
  10969. return false;
  10970. }
  10971. } else {
  10972. if (this.columnVisCheck(column)) {
  10973. groupData.width = 1;
  10974. } else {
  10975. return false;
  10976. }
  10977. }
  10978. return groupData;
  10979. };
  10980. Export.prototype.columnVisCheck = function (column) {
  10981. return column.definition[this.colVisProp] !== false && (column.visible || !column.visible && column.definition[this.colVisProp]);
  10982. };
  10983. Export.prototype.headersToExportRows = function (columns) {
  10984. var headers = [],
  10985. headerDepth = 0,
  10986. exportRows = [];
  10987. function parseColumnGroup(column, level) {
  10988. var depth = headerDepth - level;
  10989. if (typeof headers[level] === "undefined") {
  10990. headers[level] = [];
  10991. }
  10992. column.height = column.subGroups ? 1 : depth - column.depth + 1;
  10993. headers[level].push(column);
  10994. if (column.height > 1) {
  10995. for (var _i10 = 1; _i10 < column.height; _i10++) {
  10996. if (typeof headers[level + _i10] === "undefined") {
  10997. headers[level + _i10] = [];
  10998. }
  10999. headers[level + _i10].push(false);
  11000. }
  11001. }
  11002. if (column.width > 1) {
  11003. for (var _i11 = 1; _i11 < column.width; _i11++) {
  11004. headers[level].push(false);
  11005. }
  11006. }
  11007. if (column.subGroups) {
  11008. column.subGroups.forEach(function (subGroup) {
  11009. parseColumnGroup(subGroup, level + 1);
  11010. });
  11011. }
  11012. }
  11013. //calculate maximum header debth
  11014. columns.forEach(function (column) {
  11015. if (column.depth > headerDepth) {
  11016. headerDepth = column.depth;
  11017. }
  11018. });
  11019. columns.forEach(function (column) {
  11020. parseColumnGroup(column, 0);
  11021. });
  11022. headers.forEach(function (header) {
  11023. var columns = [];
  11024. header.forEach(function (col) {
  11025. if (col) {
  11026. columns.push(new ExportColumn(col.title, col.column.getComponent(), col.width, col.height, col.depth));
  11027. } else {
  11028. columns.push(null);
  11029. }
  11030. });
  11031. exportRows.push(new ExportRow("header", columns));
  11032. });
  11033. return exportRows;
  11034. };
  11035. Export.prototype.bodyToExportRows = function (rows) {
  11036. var _this58 = this;
  11037. var columns = [];
  11038. var exportRows = [];
  11039. this.table.columnManager.columnsByIndex.forEach(function (column) {
  11040. if (_this58.columnVisCheck(column)) {
  11041. columns.push(column.getComponent());
  11042. }
  11043. });
  11044. if (this.config.columnCalcs !== false && this.table.modExists("columnCalcs")) {
  11045. if (this.table.modules.columnCalcs.topInitialized) {
  11046. rows.unshift(this.table.modules.columnCalcs.topRow);
  11047. }
  11048. if (this.table.modules.columnCalcs.botInitialized) {
  11049. rows.push(this.table.modules.columnCalcs.botRow);
  11050. }
  11051. }
  11052. rows = rows.filter(function (row) {
  11053. switch (row.type) {
  11054. case "group":
  11055. return _this58.config.rowGroups !== false;
  11056. break;
  11057. case "calc":
  11058. return _this58.config.columnCalcs !== false;
  11059. break;
  11060. case "row":
  11061. return !(_this58.table.options.dataTree && _this58.config.dataTree === false && row.modules.dataTree.parent);
  11062. break;
  11063. }
  11064. return true;
  11065. });
  11066. rows.forEach(function (row, i) {
  11067. var rowData = row.getData(_this58.colVisProp);
  11068. var exportCols = [];
  11069. var indent = 0;
  11070. switch (row.type) {
  11071. case "group":
  11072. indent = row.level;
  11073. exportCols.push(new ExportColumn(row.key, row.getComponent(), columns.length, 1));
  11074. break;
  11075. case "calc":
  11076. case "row":
  11077. columns.forEach(function (col) {
  11078. exportCols.push(new ExportColumn(col._column.getFieldValue(rowData), col, 1, 1));
  11079. });
  11080. if (_this58.table.options.dataTree && _this58.config.dataTree !== false) {
  11081. indent = row.modules.dataTree.index;
  11082. }
  11083. break;
  11084. }
  11085. exportRows.push(new ExportRow(row.type, exportCols, row.getComponent(), indent));
  11086. });
  11087. return exportRows;
  11088. };
  11089. Export.prototype.genereateTableElement = function (list) {
  11090. var _this59 = this;
  11091. var table = document.createElement("table"),
  11092. headerEl = document.createElement("thead"),
  11093. bodyEl = document.createElement("tbody"),
  11094. styles = this.lookupTableStyles(),
  11095. rowFormatter = this.table.options["rowFormatter" + (this.colVisProp.charAt(0).toUpperCase() + this.colVisProp.slice(1))],
  11096. setup = {};
  11097. setup.rowFormatter = rowFormatter !== null ? rowFormatter : this.table.options.rowFormatter;
  11098. if (this.table.options.dataTree && this.config.dataTree !== false && this.table.modExists("columnCalcs")) {
  11099. setup.treeElementField = this.table.modules.dataTree.elementField;
  11100. }
  11101. //assign group header formatter
  11102. setup.groupHeader = this.table.options["groupHeader" + (this.colVisProp.charAt(0).toUpperCase() + this.colVisProp.slice(1))];
  11103. if (setup.groupHeader && !Array.isArray(setup.groupHeader)) {
  11104. setup.groupHeader = [setup.groupHeader];
  11105. }
  11106. table.classList.add("tabulator-print-table");
  11107. this.mapElementStyles(this.table.columnManager.getHeadersElement(), headerEl, ["border-top", "border-left", "border-right", "border-bottom", "background-color", "color", "font-weight", "font-family", "font-size"]);
  11108. if (list.length > 1000) {
  11109. console.warn("It may take a long time to render an HTML table with more than 1000 rows");
  11110. }
  11111. list.forEach(function (row, i) {
  11112. switch (row.type) {
  11113. case "header":
  11114. headerEl.appendChild(_this59.genereateHeaderElement(row, setup, styles));
  11115. break;
  11116. case "group":
  11117. bodyEl.appendChild(_this59.genereateGroupElement(row, setup, styles));
  11118. break;
  11119. case "calc":
  11120. bodyEl.appendChild(_this59.genereateCalcElement(row, setup, styles));
  11121. break;
  11122. case "row":
  11123. var rowEl = _this59.genereateRowElement(row, setup, styles);
  11124. _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"]);
  11125. bodyEl.appendChild(rowEl);
  11126. break;
  11127. }
  11128. });
  11129. if (headerEl.innerHTML) {
  11130. table.appendChild(headerEl);
  11131. }
  11132. table.appendChild(bodyEl);
  11133. this.mapElementStyles(this.table.element, table, ["border-top", "border-left", "border-right", "border-bottom"]);
  11134. return table;
  11135. };
  11136. Export.prototype.lookupTableStyles = function () {
  11137. var styles = {};
  11138. //lookup row styles
  11139. if (this.cloneTableStyle && window.getComputedStyle) {
  11140. styles.oddRow = this.table.element.querySelector(".tabulator-row-odd:not(.tabulator-group):not(.tabulator-calcs)");
  11141. styles.evenRow = this.table.element.querySelector(".tabulator-row-even:not(.tabulator-group):not(.tabulator-calcs)");
  11142. styles.calcRow = this.table.element.querySelector(".tabulator-row.tabulator-calcs");
  11143. styles.firstRow = this.table.element.querySelector(".tabulator-row:not(.tabulator-group):not(.tabulator-calcs)");
  11144. styles.firstGroup = this.table.element.getElementsByClassName("tabulator-group")[0];
  11145. if (styles.firstRow) {
  11146. styles.styleCells = styles.firstRow.getElementsByClassName("tabulator-cell");
  11147. styles.firstCell = styles.styleCells[0];
  11148. styles.lastCell = styles.styleCells[styles.styleCells.length - 1];
  11149. }
  11150. }
  11151. return styles;
  11152. };
  11153. Export.prototype.genereateHeaderElement = function (row, setup, styles) {
  11154. var _this60 = this;
  11155. var rowEl = document.createElement("tr");
  11156. row.columns.forEach(function (column) {
  11157. if (column) {
  11158. var cellEl = document.createElement("th");
  11159. var classNames = column.component._column.definition.cssClass ? column.component._column.definition.cssClass.split(" ") : [];
  11160. cellEl.colSpan = column.width;
  11161. cellEl.rowSpan = column.height;
  11162. cellEl.innerHTML = column.value;
  11163. if (_this60.cloneTableStyle) {
  11164. cellEl.style.boxSizing = "border-box";
  11165. }
  11166. classNames.forEach(function (className) {
  11167. cellEl.classList.add(className);
  11168. });
  11169. _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"]);
  11170. _this60.mapElementStyles(column.component._column.contentElement, cellEl, ["padding-top", "padding-left", "padding-right", "padding-bottom"]);
  11171. if (column.component._column.visible) {
  11172. _this60.mapElementStyles(column.component.getElement(), cellEl, ["width"]);
  11173. } else {
  11174. if (column.component._column.definition.width) {
  11175. cellEl.style.width = column.component._column.definition.width + "px";
  11176. }
  11177. }
  11178. if (column.component._column.parent) {
  11179. _this60.mapElementStyles(column.component._column.parent.groupElement, cellEl, ["border-top"]);
  11180. }
  11181. rowEl.appendChild(cellEl);
  11182. }
  11183. });
  11184. return rowEl;
  11185. };
  11186. Export.prototype.genereateGroupElement = function (row, setup, styles) {
  11187. var rowEl = document.createElement("tr"),
  11188. cellEl = document.createElement("td"),
  11189. group = row.columns[0];
  11190. rowEl.classList.add("tabulator-print-table-row");
  11191. if (setup.groupHeader && setup.groupHeader[row.indent]) {
  11192. group.value = setup.groupHeader[row.indent](group.value, row.component._group.getRowCount(), row.component._group.getData(), row.component);
  11193. } else {
  11194. if (setup.groupHeader === false) {
  11195. group.value = group.value;
  11196. } else {
  11197. group.value = row.component._group.generator(group.value, row.component._group.getRowCount(), row.component._group.getData(), row.component);
  11198. }
  11199. }
  11200. cellEl.colSpan = group.width;
  11201. cellEl.innerHTML = group.value;
  11202. rowEl.classList.add("tabulator-print-table-group");
  11203. rowEl.classList.add("tabulator-group-level-" + row.indent);
  11204. if (group.component.isVisible()) {
  11205. rowEl.classList.add("tabulator-group-visible");
  11206. }
  11207. this.mapElementStyles(styles.firstGroup, rowEl, ["border-top", "border-left", "border-right", "border-bottom", "color", "font-weight", "font-family", "font-size", "background-color"]);
  11208. this.mapElementStyles(styles.firstGroup, cellEl, ["padding-top", "padding-left", "padding-right", "padding-bottom"]);
  11209. rowEl.appendChild(cellEl);
  11210. return rowEl;
  11211. };
  11212. Export.prototype.genereateCalcElement = function (row, setup, styles) {
  11213. var rowEl = this.genereateRowElement(row, setup, styles);
  11214. rowEl.classList.add("tabulator-print-table-calcs");
  11215. this.mapElementStyles(styles.calcRow, rowEl, ["border-top", "border-left", "border-right", "border-bottom", "color", "font-weight", "font-family", "font-size", "background-color"]);
  11216. return rowEl;
  11217. };
  11218. Export.prototype.genereateRowElement = function (row, setup, styles) {
  11219. var _this61 = this;
  11220. var rowEl = document.createElement("tr");
  11221. rowEl.classList.add("tabulator-print-table-row");
  11222. row.columns.forEach(function (col) {
  11223. if (col) {
  11224. var cellEl = document.createElement("td"),
  11225. column = col.component._column,
  11226. value = col.value;
  11227. var cellWrapper = {
  11228. modules: {},
  11229. getValue: function getValue() {
  11230. return value;
  11231. },
  11232. getField: function getField() {
  11233. return column.definition.field;
  11234. },
  11235. getElement: function getElement() {
  11236. return cellEl;
  11237. },
  11238. getColumn: function getColumn() {
  11239. return column.getComponent();
  11240. },
  11241. getData: function getData() {
  11242. return row.component.getData();
  11243. },
  11244. getRow: function getRow() {
  11245. return row.component;
  11246. },
  11247. getComponent: function getComponent() {
  11248. return cellWrapper;
  11249. },
  11250. column: column
  11251. };
  11252. var classNames = column.definition.cssClass ? column.definition.cssClass.split(" ") : [];
  11253. classNames.forEach(function (className) {
  11254. cellEl.classList.add(className);
  11255. });
  11256. if (_this61.table.modExists("format") && _this61.config.formatCells !== false) {
  11257. value = _this61.table.modules.format.formatExportValue(cellWrapper, _this61.colVisProp);
  11258. } else {
  11259. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  11260. case "object":
  11261. value = JSON.stringify(value);
  11262. break;
  11263. case "undefined":
  11264. case "null":
  11265. value = "";
  11266. break;
  11267. default:
  11268. value = value;
  11269. }
  11270. }
  11271. if (value instanceof Node) {
  11272. cellEl.appendChild(value);
  11273. } else {
  11274. cellEl.innerHTML = value;
  11275. }
  11276. if (styles.firstCell) {
  11277. _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"]);
  11278. if (column.definition.align) {
  11279. cellEl.style.textAlign = column.definition.align;
  11280. }
  11281. }
  11282. if (_this61.table.options.dataTree && _this61.config.dataTree !== false) {
  11283. if (setup.treeElementField && setup.treeElementField == column.field || !setup.treeElementField && i == 0) {
  11284. if (row.component._row.modules.dataTree.controlEl) {
  11285. cellEl.insertBefore(row.component._row.modules.dataTree.controlEl.cloneNode(true), cellEl.firstChild);
  11286. }
  11287. if (row.component._row.modules.dataTree.branchEl) {
  11288. cellEl.insertBefore(row.component._row.modules.dataTree.branchEl.cloneNode(true), cellEl.firstChild);
  11289. }
  11290. }
  11291. }
  11292. rowEl.appendChild(cellEl);
  11293. if (cellWrapper.modules.format && cellWrapper.modules.format.renderedCallback) {
  11294. cellWrapper.modules.format.renderedCallback();
  11295. }
  11296. if (setup.rowFormatter && _this61.config.formatCells !== false) {
  11297. setup.rowFormatter(row.component);
  11298. }
  11299. }
  11300. });
  11301. return rowEl;
  11302. };
  11303. Export.prototype.genereateHTMLTable = function (list) {
  11304. var holder = document.createElement("div");
  11305. holder.appendChild(this.genereateTableElement(list));
  11306. return holder.innerHTML;
  11307. };
  11308. Export.prototype.getHtml = function (visible, style, config, colVisProp) {
  11309. var list = this.generateExportList(config || this.table.options.htmlOutputConfig, style, visible, colVisProp || "htmlOutput");
  11310. return this.genereateHTMLTable(list);
  11311. };
  11312. Export.prototype.mapElementStyles = function (from, to, props) {
  11313. if (this.cloneTableStyle && from && to) {
  11314. var lookup = {
  11315. "background-color": "backgroundColor",
  11316. "color": "fontColor",
  11317. "width": "width",
  11318. "font-weight": "fontWeight",
  11319. "font-family": "fontFamily",
  11320. "font-size": "fontSize",
  11321. "text-align": "textAlign",
  11322. "border-top": "borderTop",
  11323. "border-left": "borderLeft",
  11324. "border-right": "borderRight",
  11325. "border-bottom": "borderBottom",
  11326. "padding-top": "paddingTop",
  11327. "padding-left": "paddingLeft",
  11328. "padding-right": "paddingRight",
  11329. "padding-bottom": "paddingBottom"
  11330. };
  11331. if (window.getComputedStyle) {
  11332. var fromStyle = window.getComputedStyle(from);
  11333. props.forEach(function (prop) {
  11334. to.style[lookup[prop]] = fromStyle.getPropertyValue(prop);
  11335. });
  11336. }
  11337. }
  11338. };
  11339. Tabulator.prototype.registerModule("export", Export);
  11340. var Filter = function Filter(table) {
  11341. this.table = table; //hold Tabulator object
  11342. this.filterList = []; //hold filter list
  11343. this.headerFilters = {}; //hold column filters
  11344. this.headerFilterColumns = []; //hold columns that use header filters
  11345. this.prevHeaderFilterChangeCheck = "";
  11346. this.prevHeaderFilterChangeCheck = "{}";
  11347. this.changed = false; //has filtering changed since last render
  11348. };
  11349. //initialize column header filter
  11350. Filter.prototype.initializeColumn = function (column, value) {
  11351. var self = this,
  11352. field = column.getField(),
  11353. params;
  11354. //handle successfull value change
  11355. function success(value) {
  11356. var filterType = column.modules.filter.tagType == "input" && column.modules.filter.attrType == "text" || column.modules.filter.tagType == "textarea" ? "partial" : "match",
  11357. type = "",
  11358. filterChangeCheck = "",
  11359. filterFunc;
  11360. if (typeof column.modules.filter.prevSuccess === "undefined" || column.modules.filter.prevSuccess !== value) {
  11361. column.modules.filter.prevSuccess = value;
  11362. if (!column.modules.filter.emptyFunc(value)) {
  11363. column.modules.filter.value = value;
  11364. switch (_typeof(column.definition.headerFilterFunc)) {
  11365. case "string":
  11366. if (self.filters[column.definition.headerFilterFunc]) {
  11367. type = column.definition.headerFilterFunc;
  11368. filterFunc = function filterFunc(data) {
  11369. var params = column.definition.headerFilterFuncParams || {};
  11370. var fieldVal = column.getFieldValue(data);
  11371. params = typeof params === "function" ? params(value, fieldVal, data) : params;
  11372. return self.filters[column.definition.headerFilterFunc](value, fieldVal, data, params);
  11373. };
  11374. } else {
  11375. console.warn("Header Filter Error - Matching filter function not found: ", column.definition.headerFilterFunc);
  11376. }
  11377. break;
  11378. case "function":
  11379. filterFunc = function filterFunc(data) {
  11380. var params = column.definition.headerFilterFuncParams || {};
  11381. var fieldVal = column.getFieldValue(data);
  11382. params = typeof params === "function" ? params(value, fieldVal, data) : params;
  11383. return column.definition.headerFilterFunc(value, fieldVal, data, params);
  11384. };
  11385. type = filterFunc;
  11386. break;
  11387. }
  11388. if (!filterFunc) {
  11389. switch (filterType) {
  11390. case "partial":
  11391. filterFunc = function filterFunc(data) {
  11392. var colVal = column.getFieldValue(data);
  11393. if (typeof colVal !== 'undefined' && colVal !== null) {
  11394. return String(colVal).toLowerCase().indexOf(String(value).toLowerCase()) > -1;
  11395. } else {
  11396. return false;
  11397. }
  11398. };
  11399. type = "like";
  11400. break;
  11401. default:
  11402. filterFunc = function filterFunc(data) {
  11403. return column.getFieldValue(data) == value;
  11404. };
  11405. type = "=";
  11406. }
  11407. }
  11408. self.headerFilters[field] = { value: value, func: filterFunc, type: type, params: params || {} };
  11409. } else {
  11410. delete self.headerFilters[field];
  11411. }
  11412. filterChangeCheck = JSON.stringify(self.headerFilters);
  11413. if (self.prevHeaderFilterChangeCheck !== filterChangeCheck) {
  11414. self.prevHeaderFilterChangeCheck = filterChangeCheck;
  11415. self.changed = true;
  11416. self.table.rowManager.filterRefresh();
  11417. }
  11418. }
  11419. return true;
  11420. }
  11421. column.modules.filter = {
  11422. success: success,
  11423. attrType: false,
  11424. tagType: false,
  11425. emptyFunc: false
  11426. };
  11427. this.generateHeaderFilterElement(column);
  11428. };
  11429. Filter.prototype.generateHeaderFilterElement = function (column, initialValue, reinitialize) {
  11430. var _this62 = this;
  11431. var self = this,
  11432. success = column.modules.filter.success,
  11433. field = column.getField(),
  11434. filterElement,
  11435. editor,
  11436. editorElement,
  11437. cellWrapper,
  11438. typingTimer,
  11439. searchTrigger,
  11440. params;
  11441. //handle aborted edit
  11442. function cancel() {}
  11443. if (column.modules.filter.headerElement && column.modules.filter.headerElement.parentNode) {
  11444. column.contentElement.removeChild(column.modules.filter.headerElement.parentNode);
  11445. }
  11446. if (field) {
  11447. //set empty value function
  11448. column.modules.filter.emptyFunc = column.definition.headerFilterEmptyCheck || function (value) {
  11449. return !value && value !== "0";
  11450. };
  11451. filterElement = document.createElement("div");
  11452. filterElement.classList.add("tabulator-header-filter");
  11453. //set column editor
  11454. switch (_typeof(column.definition.headerFilter)) {
  11455. case "string":
  11456. if (self.table.modules.edit.editors[column.definition.headerFilter]) {
  11457. editor = self.table.modules.edit.editors[column.definition.headerFilter];
  11458. if ((column.definition.headerFilter === "tick" || column.definition.headerFilter === "tickCross") && !column.definition.headerFilterEmptyCheck) {
  11459. column.modules.filter.emptyFunc = function (value) {
  11460. return value !== true && value !== false;
  11461. };
  11462. }
  11463. } else {
  11464. console.warn("Filter Error - Cannot build header filter, No such editor found: ", column.definition.editor);
  11465. }
  11466. break;
  11467. case "function":
  11468. editor = column.definition.headerFilter;
  11469. break;
  11470. case "boolean":
  11471. if (column.modules.edit && column.modules.edit.editor) {
  11472. editor = column.modules.edit.editor;
  11473. } else {
  11474. if (column.definition.formatter && self.table.modules.edit.editors[column.definition.formatter]) {
  11475. editor = self.table.modules.edit.editors[column.definition.formatter];
  11476. if ((column.definition.formatter === "tick" || column.definition.formatter === "tickCross") && !column.definition.headerFilterEmptyCheck) {
  11477. column.modules.filter.emptyFunc = function (value) {
  11478. return value !== true && value !== false;
  11479. };
  11480. }
  11481. } else {
  11482. editor = self.table.modules.edit.editors["input"];
  11483. }
  11484. }
  11485. break;
  11486. }
  11487. if (editor) {
  11488. cellWrapper = {
  11489. getValue: function getValue() {
  11490. return typeof initialValue !== "undefined" ? initialValue : "";
  11491. },
  11492. getField: function getField() {
  11493. return column.definition.field;
  11494. },
  11495. getElement: function getElement() {
  11496. return filterElement;
  11497. },
  11498. getColumn: function getColumn() {
  11499. return column.getComponent();
  11500. },
  11501. getRow: function getRow() {
  11502. return {
  11503. normalizeHeight: function normalizeHeight() {}
  11504. };
  11505. }
  11506. };
  11507. params = column.definition.headerFilterParams || {};
  11508. params = typeof params === "function" ? params.call(self.table) : params;
  11509. editorElement = editor.call(this.table.modules.edit, cellWrapper, function () {}, success, cancel, params);
  11510. if (!editorElement) {
  11511. console.warn("Filter Error - Cannot add filter to " + field + " column, editor returned a value of false");
  11512. return;
  11513. }
  11514. if (!(editorElement instanceof Node)) {
  11515. console.warn("Filter Error - Cannot add filter to " + field + " column, editor should return an instance of Node, the editor returned:", editorElement);
  11516. return;
  11517. }
  11518. //set Placeholder Text
  11519. if (field) {
  11520. self.table.modules.localize.bind("headerFilters|columns|" + column.definition.field, function (value) {
  11521. editorElement.setAttribute("placeholder", typeof value !== "undefined" && value ? value : self.table.modules.localize.getText("headerFilters|default"));
  11522. });
  11523. } else {
  11524. self.table.modules.localize.bind("headerFilters|default", function (value) {
  11525. editorElement.setAttribute("placeholder", typeof self.column.definition.headerFilterPlaceholder !== "undefined" && self.column.definition.headerFilterPlaceholder ? self.column.definition.headerFilterPlaceholder : value);
  11526. });
  11527. }
  11528. //focus on element on click
  11529. editorElement.addEventListener("click", function (e) {
  11530. e.stopPropagation();
  11531. editorElement.focus();
  11532. });
  11533. editorElement.addEventListener("focus", function (e) {
  11534. var left = _this62.table.columnManager.element.scrollLeft;
  11535. if (left !== _this62.table.rowManager.element.scrollLeft) {
  11536. _this62.table.rowManager.scrollHorizontal(left);
  11537. _this62.table.columnManager.scrollHorizontal(left);
  11538. }
  11539. });
  11540. //live update filters as user types
  11541. typingTimer = false;
  11542. searchTrigger = function searchTrigger(e) {
  11543. if (typingTimer) {
  11544. clearTimeout(typingTimer);
  11545. }
  11546. typingTimer = setTimeout(function () {
  11547. success(editorElement.value);
  11548. }, self.table.options.headerFilterLiveFilterDelay);
  11549. };
  11550. column.modules.filter.headerElement = editorElement;
  11551. column.modules.filter.attrType = editorElement.hasAttribute("type") ? editorElement.getAttribute("type").toLowerCase() : "";
  11552. column.modules.filter.tagType = editorElement.tagName.toLowerCase();
  11553. if (column.definition.headerFilterLiveFilter !== false) {
  11554. if (!(column.definition.headerFilter === 'autocomplete' || column.definition.headerFilter === 'tickCross' || (column.definition.editor === 'autocomplete' || column.definition.editor === 'tickCross') && column.definition.headerFilter === true)) {
  11555. editorElement.addEventListener("keyup", searchTrigger);
  11556. editorElement.addEventListener("search", searchTrigger);
  11557. //update number filtered columns on change
  11558. if (column.modules.filter.attrType == "number") {
  11559. editorElement.addEventListener("change", function (e) {
  11560. success(editorElement.value);
  11561. });
  11562. }
  11563. //change text inputs to search inputs to allow for clearing of field
  11564. if (column.modules.filter.attrType == "text" && this.table.browser !== "ie") {
  11565. editorElement.setAttribute("type", "search");
  11566. // editorElement.off("change blur"); //prevent blur from triggering filter and preventing selection click
  11567. }
  11568. }
  11569. //prevent input and select elements from propegating click to column sorters etc
  11570. if (column.modules.filter.tagType == "input" || column.modules.filter.tagType == "select" || column.modules.filter.tagType == "textarea") {
  11571. editorElement.addEventListener("mousedown", function (e) {
  11572. e.stopPropagation();
  11573. });
  11574. }
  11575. }
  11576. filterElement.appendChild(editorElement);
  11577. column.contentElement.appendChild(filterElement);
  11578. if (!reinitialize) {
  11579. self.headerFilterColumns.push(column);
  11580. }
  11581. }
  11582. } else {
  11583. console.warn("Filter Error - Cannot add header filter, column has no field set:", column.definition.title);
  11584. }
  11585. };
  11586. //hide all header filter elements (used to ensure correct column widths in "fitData" layout mode)
  11587. Filter.prototype.hideHeaderFilterElements = function () {
  11588. this.headerFilterColumns.forEach(function (column) {
  11589. if (column.modules.filter && column.modules.filter.headerElement) {
  11590. column.modules.filter.headerElement.style.display = 'none';
  11591. }
  11592. });
  11593. };
  11594. //show all header filter elements (used to ensure correct column widths in "fitData" layout mode)
  11595. Filter.prototype.showHeaderFilterElements = function () {
  11596. this.headerFilterColumns.forEach(function (column) {
  11597. if (column.modules.filter && column.modules.filter.headerElement) {
  11598. column.modules.filter.headerElement.style.display = '';
  11599. }
  11600. });
  11601. };
  11602. //programatically set focus of header filter
  11603. Filter.prototype.setHeaderFilterFocus = function (column) {
  11604. if (column.modules.filter && column.modules.filter.headerElement) {
  11605. column.modules.filter.headerElement.focus();
  11606. } else {
  11607. console.warn("Column Filter Focus Error - No header filter set on column:", column.getField());
  11608. }
  11609. };
  11610. //programmatically get value of header filter
  11611. Filter.prototype.getHeaderFilterValue = function (column) {
  11612. if (column.modules.filter && column.modules.filter.headerElement) {
  11613. return column.modules.filter.headerElement.value;
  11614. } else {
  11615. console.warn("Column Filter Error - No header filter set on column:", column.getField());
  11616. }
  11617. };
  11618. //programatically set value of header filter
  11619. Filter.prototype.setHeaderFilterValue = function (column, value) {
  11620. if (column) {
  11621. if (column.modules.filter && column.modules.filter.headerElement) {
  11622. this.generateHeaderFilterElement(column, value, true);
  11623. column.modules.filter.success(value);
  11624. } else {
  11625. console.warn("Column Filter Error - No header filter set on column:", column.getField());
  11626. }
  11627. }
  11628. };
  11629. Filter.prototype.reloadHeaderFilter = function (column) {
  11630. if (column) {
  11631. if (column.modules.filter && column.modules.filter.headerElement) {
  11632. this.generateHeaderFilterElement(column, column.modules.filter.value, true);
  11633. } else {
  11634. console.warn("Column Filter Error - No header filter set on column:", column.getField());
  11635. }
  11636. }
  11637. };
  11638. //check if the filters has changed since last use
  11639. Filter.prototype.hasChanged = function () {
  11640. var changed = this.changed;
  11641. this.changed = false;
  11642. return changed;
  11643. };
  11644. //set standard filters
  11645. Filter.prototype.setFilter = function (field, type, value, params) {
  11646. var self = this;
  11647. self.filterList = [];
  11648. if (!Array.isArray(field)) {
  11649. field = [{ field: field, type: type, value: value, params: params }];
  11650. }
  11651. self.addFilter(field);
  11652. };
  11653. //add filter to array
  11654. Filter.prototype.addFilter = function (field, type, value, params) {
  11655. var self = this;
  11656. if (!Array.isArray(field)) {
  11657. field = [{ field: field, type: type, value: value, params: params }];
  11658. }
  11659. field.forEach(function (filter) {
  11660. filter = self.findFilter(filter);
  11661. if (filter) {
  11662. self.filterList.push(filter);
  11663. self.changed = true;
  11664. }
  11665. });
  11666. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.filter) {
  11667. this.table.modules.persistence.save("filter");
  11668. }
  11669. };
  11670. Filter.prototype.findFilter = function (filter) {
  11671. var self = this,
  11672. column;
  11673. if (Array.isArray(filter)) {
  11674. return this.findSubFilters(filter);
  11675. }
  11676. var filterFunc = false;
  11677. if (typeof filter.field == "function") {
  11678. filterFunc = function filterFunc(data) {
  11679. return filter.field(data, filter.type || {}); // pass params to custom filter function
  11680. };
  11681. } else {
  11682. if (self.filters[filter.type]) {
  11683. column = self.table.columnManager.getColumnByField(filter.field);
  11684. if (column) {
  11685. filterFunc = function filterFunc(data) {
  11686. return self.filters[filter.type](filter.value, column.getFieldValue(data), data, filter.params || {});
  11687. };
  11688. } else {
  11689. filterFunc = function filterFunc(data) {
  11690. return self.filters[filter.type](filter.value, data[filter.field], data, filter.params || {});
  11691. };
  11692. }
  11693. } else {
  11694. console.warn("Filter Error - No such filter type found, ignoring: ", filter.type);
  11695. }
  11696. }
  11697. filter.func = filterFunc;
  11698. return filter.func ? filter : false;
  11699. };
  11700. Filter.prototype.findSubFilters = function (filters) {
  11701. var self = this,
  11702. output = [];
  11703. filters.forEach(function (filter) {
  11704. filter = self.findFilter(filter);
  11705. if (filter) {
  11706. output.push(filter);
  11707. }
  11708. });
  11709. return output.length ? output : false;
  11710. };
  11711. //get all filters
  11712. Filter.prototype.getFilters = function (all, ajax) {
  11713. var output = [];
  11714. if (all) {
  11715. output = this.getHeaderFilters();
  11716. }
  11717. if (ajax) {
  11718. output.forEach(function (item) {
  11719. if (typeof item.type == "function") {
  11720. item.type = "function";
  11721. }
  11722. });
  11723. }
  11724. output = output.concat(this.filtersToArray(this.filterList, ajax));
  11725. return output;
  11726. };
  11727. //filter to Object
  11728. Filter.prototype.filtersToArray = function (filterList, ajax) {
  11729. var _this63 = this;
  11730. var output = [];
  11731. filterList.forEach(function (filter) {
  11732. var item;
  11733. if (Array.isArray(filter)) {
  11734. output.push(_this63.filtersToArray(filter, ajax));
  11735. } else {
  11736. item = { field: filter.field, type: filter.type, value: filter.value };
  11737. if (ajax) {
  11738. if (typeof item.type == "function") {
  11739. item.type = "function";
  11740. }
  11741. }
  11742. output.push(item);
  11743. }
  11744. });
  11745. return output;
  11746. };
  11747. //get all filters
  11748. Filter.prototype.getHeaderFilters = function () {
  11749. var self = this,
  11750. output = [];
  11751. for (var key in this.headerFilters) {
  11752. output.push({ field: key, type: this.headerFilters[key].type, value: this.headerFilters[key].value });
  11753. }
  11754. return output;
  11755. };
  11756. //remove filter from array
  11757. Filter.prototype.removeFilter = function (field, type, value) {
  11758. var self = this;
  11759. if (!Array.isArray(field)) {
  11760. field = [{ field: field, type: type, value: value }];
  11761. }
  11762. field.forEach(function (filter) {
  11763. var index = -1;
  11764. if (_typeof(filter.field) == "object") {
  11765. index = self.filterList.findIndex(function (element) {
  11766. return filter === element;
  11767. });
  11768. } else {
  11769. index = self.filterList.findIndex(function (element) {
  11770. return filter.field === element.field && filter.type === element.type && filter.value === element.value;
  11771. });
  11772. }
  11773. if (index > -1) {
  11774. self.filterList.splice(index, 1);
  11775. self.changed = true;
  11776. } else {
  11777. console.warn("Filter Error - No matching filter type found, ignoring: ", filter.type);
  11778. }
  11779. });
  11780. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.filter) {
  11781. this.table.modules.persistence.save("filter");
  11782. }
  11783. };
  11784. //clear filters
  11785. Filter.prototype.clearFilter = function (all) {
  11786. this.filterList = [];
  11787. if (all) {
  11788. this.clearHeaderFilter();
  11789. }
  11790. this.changed = true;
  11791. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.filter) {
  11792. this.table.modules.persistence.save("filter");
  11793. }
  11794. };
  11795. //clear header filters
  11796. Filter.prototype.clearHeaderFilter = function () {
  11797. var self = this;
  11798. this.headerFilters = {};
  11799. self.prevHeaderFilterChangeCheck = "{}";
  11800. this.headerFilterColumns.forEach(function (column) {
  11801. column.modules.filter.value = null;
  11802. column.modules.filter.prevSuccess = undefined;
  11803. self.reloadHeaderFilter(column);
  11804. });
  11805. this.changed = true;
  11806. };
  11807. //search data and return matching rows
  11808. Filter.prototype.search = function (searchType, field, type, value) {
  11809. var self = this,
  11810. activeRows = [],
  11811. filterList = [];
  11812. if (!Array.isArray(field)) {
  11813. field = [{ field: field, type: type, value: value }];
  11814. }
  11815. field.forEach(function (filter) {
  11816. filter = self.findFilter(filter);
  11817. if (filter) {
  11818. filterList.push(filter);
  11819. }
  11820. });
  11821. this.table.rowManager.rows.forEach(function (row) {
  11822. var match = true;
  11823. filterList.forEach(function (filter) {
  11824. if (!self.filterRecurse(filter, row.getData())) {
  11825. match = false;
  11826. }
  11827. });
  11828. if (match) {
  11829. activeRows.push(searchType === "data" ? row.getData("data") : row.getComponent());
  11830. }
  11831. });
  11832. return activeRows;
  11833. };
  11834. //filter row array
  11835. Filter.prototype.filter = function (rowList, filters) {
  11836. var self = this,
  11837. activeRows = [],
  11838. activeRowComponents = [];
  11839. if (self.table.options.dataFiltering) {
  11840. self.table.options.dataFiltering.call(self.table, self.getFilters());
  11841. }
  11842. if (!self.table.options.ajaxFiltering && (self.filterList.length || Object.keys(self.headerFilters).length)) {
  11843. rowList.forEach(function (row) {
  11844. if (self.filterRow(row)) {
  11845. activeRows.push(row);
  11846. }
  11847. });
  11848. } else {
  11849. activeRows = rowList.slice(0);
  11850. }
  11851. if (self.table.options.dataFiltered) {
  11852. activeRows.forEach(function (row) {
  11853. activeRowComponents.push(row.getComponent());
  11854. });
  11855. self.table.options.dataFiltered.call(self.table, self.getFilters(), activeRowComponents);
  11856. }
  11857. return activeRows;
  11858. };
  11859. //filter individual row
  11860. Filter.prototype.filterRow = function (row, filters) {
  11861. var self = this,
  11862. match = true,
  11863. data = row.getData();
  11864. self.filterList.forEach(function (filter) {
  11865. if (!self.filterRecurse(filter, data)) {
  11866. match = false;
  11867. }
  11868. });
  11869. for (var field in self.headerFilters) {
  11870. if (!self.headerFilters[field].func(data)) {
  11871. match = false;
  11872. }
  11873. }
  11874. return match;
  11875. };
  11876. Filter.prototype.filterRecurse = function (filter, data) {
  11877. var self = this,
  11878. match = false;
  11879. if (Array.isArray(filter)) {
  11880. filter.forEach(function (subFilter) {
  11881. if (self.filterRecurse(subFilter, data)) {
  11882. match = true;
  11883. }
  11884. });
  11885. } else {
  11886. match = filter.func(data);
  11887. }
  11888. return match;
  11889. };
  11890. //list of available filters
  11891. Filter.prototype.filters = {
  11892. //equal to
  11893. "=": function _(filterVal, rowVal, rowData, filterParams) {
  11894. return rowVal == filterVal ? true : false;
  11895. },
  11896. //less than
  11897. "<": function _(filterVal, rowVal, rowData, filterParams) {
  11898. return rowVal < filterVal ? true : false;
  11899. },
  11900. //less than or equal to
  11901. "<=": function _(filterVal, rowVal, rowData, filterParams) {
  11902. return rowVal <= filterVal ? true : false;
  11903. },
  11904. //greater than
  11905. ">": function _(filterVal, rowVal, rowData, filterParams) {
  11906. return rowVal > filterVal ? true : false;
  11907. },
  11908. //greater than or equal to
  11909. ">=": function _(filterVal, rowVal, rowData, filterParams) {
  11910. return rowVal >= filterVal ? true : false;
  11911. },
  11912. //not equal to
  11913. "!=": function _(filterVal, rowVal, rowData, filterParams) {
  11914. return rowVal != filterVal ? true : false;
  11915. },
  11916. "regex": function regex(filterVal, rowVal, rowData, filterParams) {
  11917. if (typeof filterVal == "string") {
  11918. filterVal = new RegExp(filterVal);
  11919. }
  11920. return filterVal.test(rowVal);
  11921. },
  11922. //contains the string
  11923. "like": function like(filterVal, rowVal, rowData, filterParams) {
  11924. if (filterVal === null || typeof filterVal === "undefined") {
  11925. return rowVal === filterVal ? true : false;
  11926. } else {
  11927. if (typeof rowVal !== 'undefined' && rowVal !== null) {
  11928. return String(rowVal).toLowerCase().indexOf(filterVal.toLowerCase()) > -1;
  11929. } else {
  11930. return false;
  11931. }
  11932. }
  11933. },
  11934. //contains the keywords
  11935. "keywords": function keywords(filterVal, rowVal, rowData, filterParams) {
  11936. var keywords = filterVal.toLowerCase().split(typeof filterParams.separator === "undefined" ? " " : filterParams.separator),
  11937. value = String(rowVal === null || typeof rowVal === "undefined" ? "" : rowVal).toLowerCase(),
  11938. matches = [];
  11939. keywords.forEach(function (keyword) {
  11940. if (value.includes(keyword)) {
  11941. matches.push(true);
  11942. }
  11943. });
  11944. return filterParams.matchAll ? matches.length === keywords.length : !!matches.length;
  11945. },
  11946. //starts with the string
  11947. "starts": function starts(filterVal, rowVal, rowData, filterParams) {
  11948. if (filterVal === null || typeof filterVal === "undefined") {
  11949. return rowVal === filterVal ? true : false;
  11950. } else {
  11951. if (typeof rowVal !== 'undefined' && rowVal !== null) {
  11952. return String(rowVal).toLowerCase().startsWith(filterVal.toLowerCase());
  11953. } else {
  11954. return false;
  11955. }
  11956. }
  11957. },
  11958. //ends with the string
  11959. "ends": function ends(filterVal, rowVal, rowData, filterParams) {
  11960. if (filterVal === null || typeof filterVal === "undefined") {
  11961. return rowVal === filterVal ? true : false;
  11962. } else {
  11963. if (typeof rowVal !== 'undefined' && rowVal !== null) {
  11964. return String(rowVal).toLowerCase().endsWith(filterVal.toLowerCase());
  11965. } else {
  11966. return false;
  11967. }
  11968. }
  11969. },
  11970. //in array
  11971. "in": function _in(filterVal, rowVal, rowData, filterParams) {
  11972. if (Array.isArray(filterVal)) {
  11973. return filterVal.length ? filterVal.indexOf(rowVal) > -1 : true;
  11974. } else {
  11975. console.warn("Filter Error - filter value is not an array:", filterVal);
  11976. return false;
  11977. }
  11978. }
  11979. };
  11980. Tabulator.prototype.registerModule("filter", Filter);
  11981. var Format = function Format(table) {
  11982. this.table = table; //hold Tabulator object
  11983. };
  11984. //initialize column formatter
  11985. Format.prototype.initializeColumn = function (column) {
  11986. column.modules.format = this.lookupFormatter(column, "");
  11987. if (typeof column.definition.formatterPrint !== "undefined") {
  11988. column.modules.format.print = this.lookupFormatter(column, "Print");
  11989. }
  11990. if (typeof column.definition.formatterClipboard !== "undefined") {
  11991. column.modules.format.clipboard = this.lookupFormatter(column, "Clipboard");
  11992. }
  11993. if (typeof column.definition.formatterHtmlOutput !== "undefined") {
  11994. column.modules.format.htmlOutput = this.lookupFormatter(column, "HtmlOutput");
  11995. }
  11996. };
  11997. Format.prototype.lookupFormatter = function (column, type) {
  11998. var config = { params: column.definition["formatter" + type + "Params"] || {} },
  11999. formatter = column.definition["formatter" + type];
  12000. //set column formatter
  12001. switch (typeof formatter === 'undefined' ? 'undefined' : _typeof(formatter)) {
  12002. case "string":
  12003. if (formatter === "tick") {
  12004. formatter = "tickCross";
  12005. if (typeof config.params.crossElement == "undefined") {
  12006. config.params.crossElement = false;
  12007. }
  12008. console.warn("DEPRECATION WARNING - the tick formatter has been deprecated, please use the tickCross formatter with the crossElement param set to false");
  12009. }
  12010. if (this.formatters[formatter]) {
  12011. config.formatter = this.formatters[formatter];
  12012. } else {
  12013. console.warn("Formatter Error - No such formatter found: ", formatter);
  12014. config.formatter = this.formatters.plaintext;
  12015. }
  12016. break;
  12017. case "function":
  12018. config.formatter = formatter;
  12019. break;
  12020. default:
  12021. config.formatter = this.formatters.plaintext;
  12022. break;
  12023. }
  12024. return config;
  12025. };
  12026. Format.prototype.cellRendered = function (cell) {
  12027. if (cell.modules.format && cell.modules.format.renderedCallback && !cell.modules.format.rendered) {
  12028. cell.modules.format.renderedCallback();
  12029. cell.modules.format.rendered = true;
  12030. }
  12031. };
  12032. //return a formatted value for a cell
  12033. Format.prototype.formatValue = function (cell) {
  12034. var component = cell.getComponent(),
  12035. params = typeof cell.column.modules.format.params === "function" ? cell.column.modules.format.params(component) : cell.column.modules.format.params;
  12036. function onRendered(callback) {
  12037. if (!cell.modules.format) {
  12038. cell.modules.format = {};
  12039. }
  12040. cell.modules.format.renderedCallback = callback;
  12041. cell.modules.format.rendered = false;
  12042. }
  12043. return cell.column.modules.format.formatter.call(this, component, params, onRendered);
  12044. };
  12045. Format.prototype.formatExportValue = function (cell, type) {
  12046. var formatter = cell.column.modules.format[type],
  12047. params;
  12048. if (formatter) {
  12049. var onRendered = function onRendered(callback) {
  12050. if (!cell.modules.format) {
  12051. cell.modules.format = {};
  12052. }
  12053. cell.modules.format.renderedCallback = callback;
  12054. cell.modules.format.rendered = false;
  12055. };
  12056. params = typeof formatter.params === "function" ? formatter.params(component) : formatter.params;
  12057. return formatter.formatter.call(this, cell.getComponent(), params, onRendered);
  12058. } else {
  12059. return this.formatValue(cell);
  12060. }
  12061. };
  12062. Format.prototype.sanitizeHTML = function (value) {
  12063. if (value) {
  12064. var entityMap = {
  12065. '&': '&amp;',
  12066. '<': '&lt;',
  12067. '>': '&gt;',
  12068. '"': '&quot;',
  12069. "'": '&#39;',
  12070. '/': '&#x2F;',
  12071. '`': '&#x60;',
  12072. '=': '&#x3D;'
  12073. };
  12074. return String(value).replace(/[&<>"'`=\/]/g, function (s) {
  12075. return entityMap[s];
  12076. });
  12077. } else {
  12078. return value;
  12079. }
  12080. };
  12081. Format.prototype.emptyToSpace = function (value) {
  12082. return value === null || typeof value === "undefined" || value === "" ? "&nbsp;" : value;
  12083. };
  12084. //get formatter for cell
  12085. Format.prototype.getFormatter = function (formatter) {
  12086. var formatter;
  12087. switch (typeof formatter === 'undefined' ? 'undefined' : _typeof(formatter)) {
  12088. case "string":
  12089. if (this.formatters[formatter]) {
  12090. formatter = this.formatters[formatter];
  12091. } else {
  12092. console.warn("Formatter Error - No such formatter found: ", formatter);
  12093. formatter = this.formatters.plaintext;
  12094. }
  12095. break;
  12096. case "function":
  12097. formatter = formatter;
  12098. break;
  12099. default:
  12100. formatter = this.formatters.plaintext;
  12101. break;
  12102. }
  12103. return formatter;
  12104. };
  12105. //default data formatters
  12106. Format.prototype.formatters = {
  12107. //plain text value
  12108. plaintext: function plaintext(cell, formatterParams, onRendered) {
  12109. return this.emptyToSpace(this.sanitizeHTML(cell.getValue()));
  12110. },
  12111. //html text value
  12112. html: function html(cell, formatterParams, onRendered) {
  12113. return cell.getValue();
  12114. },
  12115. //multiline text area
  12116. textarea: function textarea(cell, formatterParams, onRendered) {
  12117. cell.getElement().style.whiteSpace = "pre-wrap";
  12118. return this.emptyToSpace(this.sanitizeHTML(cell.getValue()));
  12119. },
  12120. //currency formatting
  12121. money: function money(cell, formatterParams, onRendered) {
  12122. var floatVal = parseFloat(cell.getValue()),
  12123. number,
  12124. integer,
  12125. decimal,
  12126. rgx;
  12127. var decimalSym = formatterParams.decimal || ".";
  12128. var thousandSym = formatterParams.thousand || ",";
  12129. var symbol = formatterParams.symbol || "";
  12130. var after = !!formatterParams.symbolAfter;
  12131. var precision = typeof formatterParams.precision !== "undefined" ? formatterParams.precision : 2;
  12132. if (isNaN(floatVal)) {
  12133. return this.emptyToSpace(this.sanitizeHTML(cell.getValue()));
  12134. }
  12135. number = precision !== false ? floatVal.toFixed(precision) : floatVal;
  12136. number = String(number).split(".");
  12137. integer = number[0];
  12138. decimal = number.length > 1 ? decimalSym + number[1] : "";
  12139. rgx = /(\d+)(\d{3})/;
  12140. while (rgx.test(integer)) {
  12141. integer = integer.replace(rgx, "$1" + thousandSym + "$2");
  12142. }
  12143. return after ? integer + decimal + symbol : symbol + integer + decimal;
  12144. },
  12145. //clickable anchor tag
  12146. link: function link(cell, formatterParams, onRendered) {
  12147. var value = cell.getValue(),
  12148. urlPrefix = formatterParams.urlPrefix || "",
  12149. download = formatterParams.download,
  12150. label = value,
  12151. el = document.createElement("a"),
  12152. data;
  12153. if (formatterParams.labelField) {
  12154. data = cell.getData();
  12155. label = data[formatterParams.labelField];
  12156. }
  12157. if (formatterParams.label) {
  12158. switch (_typeof(formatterParams.label)) {
  12159. case "string":
  12160. label = formatterParams.label;
  12161. break;
  12162. case "function":
  12163. label = formatterParams.label(cell);
  12164. break;
  12165. }
  12166. }
  12167. if (label) {
  12168. if (formatterParams.urlField) {
  12169. data = cell.getData();
  12170. value = data[formatterParams.urlField];
  12171. }
  12172. if (formatterParams.url) {
  12173. switch (_typeof(formatterParams.url)) {
  12174. case "string":
  12175. value = formatterParams.url;
  12176. break;
  12177. case "function":
  12178. value = formatterParams.url(cell);
  12179. break;
  12180. }
  12181. }
  12182. el.setAttribute("href", urlPrefix + value);
  12183. if (formatterParams.target) {
  12184. el.setAttribute("target", formatterParams.target);
  12185. }
  12186. if (formatterParams.download) {
  12187. if (typeof download == "function") {
  12188. download = download(cell);
  12189. } else {
  12190. download = download === true ? "" : download;
  12191. }
  12192. el.setAttribute("download", download);
  12193. }
  12194. el.innerHTML = this.emptyToSpace(this.sanitizeHTML(label));
  12195. return el;
  12196. } else {
  12197. return "&nbsp;";
  12198. }
  12199. },
  12200. //image element
  12201. image: function image(cell, formatterParams, onRendered) {
  12202. var el = document.createElement("img");
  12203. el.setAttribute("src", cell.getValue());
  12204. switch (_typeof(formatterParams.height)) {
  12205. case "number":
  12206. el.style.height = formatterParams.height + "px";
  12207. break;
  12208. case "string":
  12209. el.style.height = formatterParams.height;
  12210. break;
  12211. }
  12212. switch (_typeof(formatterParams.width)) {
  12213. case "number":
  12214. el.style.width = formatterParams.width + "px";
  12215. break;
  12216. case "string":
  12217. el.style.width = formatterParams.width;
  12218. break;
  12219. }
  12220. el.addEventListener("load", function () {
  12221. cell.getRow().normalizeHeight();
  12222. });
  12223. return el;
  12224. },
  12225. //tick or cross
  12226. tickCross: function tickCross(cell, formatterParams, onRendered) {
  12227. var value = cell.getValue(),
  12228. element = cell.getElement(),
  12229. empty = formatterParams.allowEmpty,
  12230. truthy = formatterParams.allowTruthy,
  12231. 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>',
  12232. 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>';
  12233. if (truthy && value || value === true || value === "true" || value === "True" || value === 1 || value === "1") {
  12234. element.setAttribute("aria-checked", true);
  12235. return tick || "";
  12236. } else {
  12237. if (empty && (value === "null" || value === "" || value === null || typeof value === "undefined")) {
  12238. element.setAttribute("aria-checked", "mixed");
  12239. return "";
  12240. } else {
  12241. element.setAttribute("aria-checked", false);
  12242. return cross || "";
  12243. }
  12244. }
  12245. },
  12246. datetime: function datetime(cell, formatterParams, onRendered) {
  12247. var inputFormat = formatterParams.inputFormat || "YYYY-MM-DD hh:mm:ss";
  12248. var outputFormat = formatterParams.outputFormat || "DD/MM/YYYY hh:mm:ss";
  12249. var invalid = typeof formatterParams.invalidPlaceholder !== "undefined" ? formatterParams.invalidPlaceholder : "";
  12250. var value = cell.getValue();
  12251. var newDatetime = moment(value, inputFormat);
  12252. if (newDatetime.isValid()) {
  12253. return formatterParams.timezone ? newDatetime.tz(formatterParams.timezone).format(outputFormat) : newDatetime.format(outputFormat);
  12254. } else {
  12255. if (invalid === true) {
  12256. return value;
  12257. } else if (typeof invalid === "function") {
  12258. return invalid(value);
  12259. } else {
  12260. return invalid;
  12261. }
  12262. }
  12263. },
  12264. datetimediff: function datetime(cell, formatterParams, onRendered) {
  12265. var inputFormat = formatterParams.inputFormat || "YYYY-MM-DD hh:mm:ss";
  12266. var invalid = typeof formatterParams.invalidPlaceholder !== "undefined" ? formatterParams.invalidPlaceholder : "";
  12267. var suffix = typeof formatterParams.suffix !== "undefined" ? formatterParams.suffix : false;
  12268. var unit = typeof formatterParams.unit !== "undefined" ? formatterParams.unit : undefined;
  12269. var humanize = typeof formatterParams.humanize !== "undefined" ? formatterParams.humanize : false;
  12270. var date = typeof formatterParams.date !== "undefined" ? formatterParams.date : moment();
  12271. var value = cell.getValue();
  12272. var newDatetime = moment(value, inputFormat);
  12273. if (newDatetime.isValid()) {
  12274. if (humanize) {
  12275. return moment.duration(newDatetime.diff(date)).humanize(suffix);
  12276. } else {
  12277. return newDatetime.diff(date, unit) + (suffix ? " " + suffix : "");
  12278. }
  12279. } else {
  12280. if (invalid === true) {
  12281. return value;
  12282. } else if (typeof invalid === "function") {
  12283. return invalid(value);
  12284. } else {
  12285. return invalid;
  12286. }
  12287. }
  12288. },
  12289. //select
  12290. lookup: function lookup(cell, formatterParams, onRendered) {
  12291. var value = cell.getValue();
  12292. if (typeof formatterParams[value] === "undefined") {
  12293. console.warn('Missing display value for ' + value);
  12294. return value;
  12295. }
  12296. return formatterParams[value];
  12297. },
  12298. //star rating
  12299. star: function star(cell, formatterParams, onRendered) {
  12300. var value = cell.getValue(),
  12301. element = cell.getElement(),
  12302. maxStars = formatterParams && formatterParams.stars ? formatterParams.stars : 5,
  12303. stars = document.createElement("span"),
  12304. star = document.createElementNS('http://www.w3.org/2000/svg', "svg"),
  12305. 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 "/>',
  12306. 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 "/>';
  12307. //style stars holder
  12308. stars.style.verticalAlign = "middle";
  12309. //style star
  12310. star.setAttribute("width", "14");
  12311. star.setAttribute("height", "14");
  12312. star.setAttribute("viewBox", "0 0 512 512");
  12313. star.setAttribute("xml:space", "preserve");
  12314. star.style.padding = "0 1px";
  12315. value = value && !isNaN(value) ? parseInt(value) : 0;
  12316. value = Math.max(0, Math.min(value, maxStars));
  12317. for (var i = 1; i <= maxStars; i++) {
  12318. var nextStar = star.cloneNode(true);
  12319. nextStar.innerHTML = i <= value ? starActive : starInactive;
  12320. stars.appendChild(nextStar);
  12321. }
  12322. element.style.whiteSpace = "nowrap";
  12323. element.style.overflow = "hidden";
  12324. element.style.textOverflow = "ellipsis";
  12325. element.setAttribute("aria-label", value);
  12326. return stars;
  12327. },
  12328. traffic: function traffic(cell, formatterParams, onRendered) {
  12329. var value = this.sanitizeHTML(cell.getValue()) || 0,
  12330. el = document.createElement("span"),
  12331. max = formatterParams && formatterParams.max ? formatterParams.max : 100,
  12332. min = formatterParams && formatterParams.min ? formatterParams.min : 0,
  12333. colors = formatterParams && typeof formatterParams.color !== "undefined" ? formatterParams.color : ["red", "orange", "green"],
  12334. color = "#666666",
  12335. percent,
  12336. percentValue;
  12337. if (isNaN(value) || typeof cell.getValue() === "undefined") {
  12338. return;
  12339. }
  12340. el.classList.add("tabulator-traffic-light");
  12341. //make sure value is in range
  12342. percentValue = parseFloat(value) <= max ? parseFloat(value) : max;
  12343. percentValue = parseFloat(percentValue) >= min ? parseFloat(percentValue) : min;
  12344. //workout percentage
  12345. percent = (max - min) / 100;
  12346. percentValue = Math.round((percentValue - min) / percent);
  12347. //set color
  12348. switch (typeof colors === 'undefined' ? 'undefined' : _typeof(colors)) {
  12349. case "string":
  12350. color = colors;
  12351. break;
  12352. case "function":
  12353. color = colors(value);
  12354. break;
  12355. case "object":
  12356. if (Array.isArray(colors)) {
  12357. var unit = 100 / colors.length;
  12358. var index = Math.floor(percentValue / unit);
  12359. index = Math.min(index, colors.length - 1);
  12360. index = Math.max(index, 0);
  12361. color = colors[index];
  12362. break;
  12363. }
  12364. }
  12365. el.style.backgroundColor = color;
  12366. return el;
  12367. },
  12368. //progress bar
  12369. progress: function progress(cell, formatterParams, onRendered) {
  12370. //progress bar
  12371. var value = this.sanitizeHTML(cell.getValue()) || 0,
  12372. element = cell.getElement(),
  12373. max = formatterParams && formatterParams.max ? formatterParams.max : 100,
  12374. min = formatterParams && formatterParams.min ? formatterParams.min : 0,
  12375. legendAlign = formatterParams && formatterParams.legendAlign ? formatterParams.legendAlign : "center",
  12376. percent,
  12377. percentValue,
  12378. color,
  12379. legend,
  12380. legendColor,
  12381. top,
  12382. left,
  12383. right,
  12384. bottom;
  12385. //make sure value is in range
  12386. percentValue = parseFloat(value) <= max ? parseFloat(value) : max;
  12387. percentValue = parseFloat(percentValue) >= min ? parseFloat(percentValue) : min;
  12388. //workout percentage
  12389. percent = (max - min) / 100;
  12390. percentValue = Math.round((percentValue - min) / percent);
  12391. //set bar color
  12392. switch (_typeof(formatterParams.color)) {
  12393. case "string":
  12394. color = formatterParams.color;
  12395. break;
  12396. case "function":
  12397. color = formatterParams.color(value);
  12398. break;
  12399. case "object":
  12400. if (Array.isArray(formatterParams.color)) {
  12401. var unit = 100 / formatterParams.color.length;
  12402. var index = Math.floor(percentValue / unit);
  12403. index = Math.min(index, formatterParams.color.length - 1);
  12404. index = Math.max(index, 0);
  12405. color = formatterParams.color[index];
  12406. break;
  12407. }
  12408. default:
  12409. color = "#2DC214";
  12410. }
  12411. //generate legend
  12412. switch (_typeof(formatterParams.legend)) {
  12413. case "string":
  12414. legend = formatterParams.legend;
  12415. break;
  12416. case "function":
  12417. legend = formatterParams.legend(value);
  12418. break;
  12419. case "boolean":
  12420. legend = value;
  12421. break;
  12422. default:
  12423. legend = false;
  12424. }
  12425. //set legend color
  12426. switch (_typeof(formatterParams.legendColor)) {
  12427. case "string":
  12428. legendColor = formatterParams.legendColor;
  12429. break;
  12430. case "function":
  12431. legendColor = formatterParams.legendColor(value);
  12432. break;
  12433. case "object":
  12434. if (Array.isArray(formatterParams.legendColor)) {
  12435. var unit = 100 / formatterParams.legendColor.length;
  12436. var index = Math.floor(percentValue / unit);
  12437. index = Math.min(index, formatterParams.legendColor.length - 1);
  12438. index = Math.max(index, 0);
  12439. legendColor = formatterParams.legendColor[index];
  12440. }
  12441. break;
  12442. default:
  12443. legendColor = "#000";
  12444. }
  12445. element.style.minWidth = "30px";
  12446. element.style.position = "relative";
  12447. element.setAttribute("aria-label", percentValue);
  12448. var barEl = document.createElement("div");
  12449. barEl.style.display = "inline-block";
  12450. barEl.style.position = "relative";
  12451. barEl.style.width = percentValue + "%";
  12452. barEl.style.backgroundColor = color;
  12453. barEl.style.height = "100%";
  12454. barEl.setAttribute('data-max', max);
  12455. barEl.setAttribute('data-min', min);
  12456. if (legend) {
  12457. var legendEl = document.createElement("div");
  12458. legendEl.style.position = "absolute";
  12459. legendEl.style.top = "4px";
  12460. legendEl.style.left = 0;
  12461. legendEl.style.textAlign = legendAlign;
  12462. legendEl.style.width = "100%";
  12463. legendEl.style.color = legendColor;
  12464. legendEl.innerHTML = legend;
  12465. }
  12466. onRendered(function () {
  12467. //handle custom element needed if formatter is to be included in printed/downloaded output
  12468. if (!(cell instanceof CellComponent)) {
  12469. var holderEl = document.createElement("div");
  12470. holderEl.style.position = "absolute";
  12471. holderEl.style.top = "4px";
  12472. holderEl.style.bottom = "4px";
  12473. holderEl.style.left = "4px";
  12474. holderEl.style.right = "4px";
  12475. element.appendChild(holderEl);
  12476. element = holderEl;
  12477. }
  12478. element.appendChild(barEl);
  12479. if (legend) {
  12480. element.appendChild(legendEl);
  12481. }
  12482. });
  12483. return "";
  12484. },
  12485. //background color
  12486. color: function color(cell, formatterParams, onRendered) {
  12487. cell.getElement().style.backgroundColor = this.sanitizeHTML(cell.getValue());
  12488. return "";
  12489. },
  12490. //tick icon
  12491. buttonTick: function buttonTick(cell, formatterParams, onRendered) {
  12492. 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>';
  12493. },
  12494. //cross icon
  12495. buttonCross: function buttonCross(cell, formatterParams, onRendered) {
  12496. 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>';
  12497. },
  12498. //current row number
  12499. rownum: function rownum(cell, formatterParams, onRendered) {
  12500. return this.table.rowManager.activeRows.indexOf(cell.getRow()._getSelf()) + 1;
  12501. },
  12502. //row handle
  12503. handle: function handle(cell, formatterParams, onRendered) {
  12504. cell.getElement().classList.add("tabulator-row-handle");
  12505. 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>";
  12506. },
  12507. responsiveCollapse: function responsiveCollapse(cell, formatterParams, onRendered) {
  12508. var self = this,
  12509. open = false,
  12510. el = document.createElement("div"),
  12511. config = cell.getRow()._row.modules.responsiveLayout;
  12512. el.classList.add("tabulator-responsive-collapse-toggle");
  12513. el.innerHTML = "<span class='tabulator-responsive-collapse-toggle-open'>+</span><span class='tabulator-responsive-collapse-toggle-close'>-</span>";
  12514. cell.getElement().classList.add("tabulator-row-handle");
  12515. function toggleList(isOpen) {
  12516. var collapseEl = config.element;
  12517. config.open = isOpen;
  12518. if (collapseEl) {
  12519. if (config.open) {
  12520. el.classList.add("open");
  12521. collapseEl.style.display = '';
  12522. } else {
  12523. el.classList.remove("open");
  12524. collapseEl.style.display = 'none';
  12525. }
  12526. }
  12527. }
  12528. el.addEventListener("click", function (e) {
  12529. e.stopImmediatePropagation();
  12530. toggleList(!config.open);
  12531. });
  12532. toggleList(config.open);
  12533. return el;
  12534. },
  12535. rowSelection: function rowSelection(cell, formatterParams, onRendered) {
  12536. var _this64 = this;
  12537. var checkbox = document.createElement("input");
  12538. checkbox.type = 'checkbox';
  12539. if (this.table.modExists("selectRow", true)) {
  12540. checkbox.addEventListener("click", function (e) {
  12541. e.stopPropagation();
  12542. });
  12543. if (typeof cell.getRow == 'function') {
  12544. var row = cell.getRow();
  12545. if (row instanceof RowComponent) {
  12546. checkbox.addEventListener("change", function (e) {
  12547. row.toggleSelect();
  12548. });
  12549. checkbox.checked = row.isSelected && row.isSelected();
  12550. this.table.modules.selectRow.registerRowSelectCheckbox(row, checkbox);
  12551. } else {
  12552. checkbox = "";
  12553. }
  12554. } else {
  12555. checkbox.addEventListener("change", function (e) {
  12556. if (_this64.table.modules.selectRow.selectedRows.length) {
  12557. _this64.table.deselectRow();
  12558. } else {
  12559. _this64.table.selectRow(formatterParams.rowRange);
  12560. }
  12561. });
  12562. this.table.modules.selectRow.registerHeaderSelectCheckbox(checkbox);
  12563. }
  12564. }
  12565. return checkbox;
  12566. }
  12567. };
  12568. Tabulator.prototype.registerModule("format", Format);
  12569. var FrozenColumns = function FrozenColumns(table) {
  12570. this.table = table; //hold Tabulator object
  12571. this.leftColumns = [];
  12572. this.rightColumns = [];
  12573. this.leftMargin = 0;
  12574. this.rightMargin = 0;
  12575. this.rightPadding = 0;
  12576. this.initializationMode = "left";
  12577. this.active = false;
  12578. this.scrollEndTimer = false;
  12579. };
  12580. //reset initial state
  12581. FrozenColumns.prototype.reset = function () {
  12582. this.initializationMode = "left";
  12583. this.leftColumns = [];
  12584. this.rightColumns = [];
  12585. this.leftMargin = 0;
  12586. this.rightMargin = 0;
  12587. this.rightMargin = 0;
  12588. this.active = false;
  12589. this.table.columnManager.headersElement.style.marginLeft = 0;
  12590. this.table.columnManager.element.style.paddingRight = 0;
  12591. };
  12592. //initialize specific column
  12593. FrozenColumns.prototype.initializeColumn = function (column) {
  12594. var config = { margin: 0, edge: false };
  12595. if (!column.isGroup) {
  12596. if (this.frozenCheck(column)) {
  12597. config.position = this.initializationMode;
  12598. if (this.initializationMode == "left") {
  12599. this.leftColumns.push(column);
  12600. } else {
  12601. this.rightColumns.unshift(column);
  12602. }
  12603. this.active = true;
  12604. column.modules.frozen = config;
  12605. } else {
  12606. this.initializationMode = "right";
  12607. }
  12608. }
  12609. };
  12610. FrozenColumns.prototype.frozenCheck = function (column) {
  12611. var frozen = false;
  12612. if (column.parent.isGroup && column.definition.frozen) {
  12613. console.warn("Frozen Column Error - Parent column group must be frozen, not individual columns or sub column groups");
  12614. }
  12615. if (column.parent.isGroup) {
  12616. return this.frozenCheck(column.parent);
  12617. } else {
  12618. return column.definition.frozen;
  12619. }
  12620. return frozen;
  12621. };
  12622. //quick layout to smooth horizontal scrolling
  12623. FrozenColumns.prototype.scrollHorizontal = function () {
  12624. var _this65 = this;
  12625. var rows;
  12626. if (this.active) {
  12627. clearTimeout(this.scrollEndTimer);
  12628. //layout all rows after scroll is complete
  12629. this.scrollEndTimer = setTimeout(function () {
  12630. _this65.layout();
  12631. }, 100);
  12632. rows = this.table.rowManager.getVisibleRows();
  12633. this.calcMargins();
  12634. this.layoutColumnPosition();
  12635. this.layoutCalcRows();
  12636. rows.forEach(function (row) {
  12637. if (row.type === "row") {
  12638. _this65.layoutRow(row);
  12639. }
  12640. });
  12641. this.table.rowManager.tableElement.style.marginRight = this.rightMargin;
  12642. }
  12643. };
  12644. //calculate margins for rows
  12645. FrozenColumns.prototype.calcMargins = function () {
  12646. this.leftMargin = this._calcSpace(this.leftColumns, this.leftColumns.length) + "px";
  12647. this.table.columnManager.headersElement.style.marginLeft = this.leftMargin;
  12648. this.rightMargin = this._calcSpace(this.rightColumns, this.rightColumns.length) + "px";
  12649. this.table.columnManager.element.style.paddingRight = this.rightMargin;
  12650. //calculate right frozen columns
  12651. this.rightPadding = this.table.rowManager.element.clientWidth + this.table.columnManager.scrollLeft;
  12652. };
  12653. //layout calculation rows
  12654. FrozenColumns.prototype.layoutCalcRows = function () {
  12655. if (this.table.modExists("columnCalcs")) {
  12656. if (this.table.modules.columnCalcs.topInitialized && this.table.modules.columnCalcs.topRow) {
  12657. this.layoutRow(this.table.modules.columnCalcs.topRow);
  12658. }
  12659. if (this.table.modules.columnCalcs.botInitialized && this.table.modules.columnCalcs.botRow) {
  12660. this.layoutRow(this.table.modules.columnCalcs.botRow);
  12661. }
  12662. }
  12663. };
  12664. //calculate column positions and layout headers
  12665. FrozenColumns.prototype.layoutColumnPosition = function (allCells) {
  12666. var _this66 = this;
  12667. var leftParents = [];
  12668. this.leftColumns.forEach(function (column, i) {
  12669. column.modules.frozen.margin = _this66._calcSpace(_this66.leftColumns, i) + _this66.table.columnManager.scrollLeft + "px";
  12670. if (i == _this66.leftColumns.length - 1) {
  12671. column.modules.frozen.edge = true;
  12672. } else {
  12673. column.modules.frozen.edge = false;
  12674. }
  12675. if (column.parent.isGroup) {
  12676. var parentEl = _this66.getColGroupParentElement(column);
  12677. if (!leftParents.includes(parentEl)) {
  12678. _this66.layoutElement(parentEl, column);
  12679. leftParents.push(parentEl);
  12680. }
  12681. if (column.modules.frozen.edge) {
  12682. parentEl.classList.add("tabulator-frozen-" + column.modules.frozen.position);
  12683. }
  12684. } else {
  12685. _this66.layoutElement(column.getElement(), column);
  12686. }
  12687. if (allCells) {
  12688. column.cells.forEach(function (cell) {
  12689. _this66.layoutElement(cell.getElement(), column);
  12690. });
  12691. }
  12692. });
  12693. this.rightColumns.forEach(function (column, i) {
  12694. column.modules.frozen.margin = _this66.rightPadding - _this66._calcSpace(_this66.rightColumns, i + 1) + "px";
  12695. if (i == _this66.rightColumns.length - 1) {
  12696. column.modules.frozen.edge = true;
  12697. } else {
  12698. column.modules.frozen.edge = false;
  12699. }
  12700. if (column.parent.isGroup) {
  12701. _this66.layoutElement(_this66.getColGroupParentElement(column), column);
  12702. } else {
  12703. _this66.layoutElement(column.getElement(), column);
  12704. }
  12705. if (allCells) {
  12706. column.cells.forEach(function (cell) {
  12707. _this66.layoutElement(cell.getElement(), column);
  12708. });
  12709. }
  12710. });
  12711. };
  12712. FrozenColumns.prototype.getColGroupParentElement = function (column) {
  12713. return column.parent.isGroup ? this.getColGroupParentElement(column.parent) : column.getElement();
  12714. };
  12715. //layout columns appropropriatly
  12716. FrozenColumns.prototype.layout = function () {
  12717. var self = this,
  12718. rightMargin = 0;
  12719. if (self.active) {
  12720. //calculate row padding
  12721. this.calcMargins();
  12722. // self.table.rowManager.activeRows.forEach(function(row){
  12723. // self.layoutRow(row);
  12724. // });
  12725. // if(self.table.options.dataTree){
  12726. self.table.rowManager.getDisplayRows().forEach(function (row) {
  12727. if (row.type === "row") {
  12728. self.layoutRow(row);
  12729. }
  12730. });
  12731. // }
  12732. this.layoutCalcRows();
  12733. //calculate left columns
  12734. this.layoutColumnPosition(true);
  12735. // if(tableHolder.scrollHeight > tableHolder.clientHeight){
  12736. // rightMargin -= tableHolder.offsetWidth - tableHolder.clientWidth;
  12737. // }
  12738. this.table.rowManager.tableElement.style.marginRight = this.rightMargin;
  12739. }
  12740. };
  12741. FrozenColumns.prototype.layoutRow = function (row) {
  12742. var _this67 = this;
  12743. var rowEl = row.getElement();
  12744. rowEl.style.paddingLeft = this.leftMargin;
  12745. // rowEl.style.paddingRight = this.rightMargin + "px";
  12746. this.leftColumns.forEach(function (column) {
  12747. var cell = row.getCell(column);
  12748. if (cell) {
  12749. _this67.layoutElement(cell.getElement(), column);
  12750. }
  12751. });
  12752. this.rightColumns.forEach(function (column) {
  12753. var cell = row.getCell(column);
  12754. if (cell) {
  12755. _this67.layoutElement(cell.getElement(), column);
  12756. }
  12757. });
  12758. };
  12759. FrozenColumns.prototype.layoutElement = function (element, column) {
  12760. if (column.modules.frozen) {
  12761. element.style.position = "absolute";
  12762. element.style.left = column.modules.frozen.margin;
  12763. element.classList.add("tabulator-frozen");
  12764. if (column.modules.frozen.edge) {
  12765. element.classList.add("tabulator-frozen-" + column.modules.frozen.position);
  12766. }
  12767. }
  12768. };
  12769. FrozenColumns.prototype._calcSpace = function (columns, index) {
  12770. var width = 0;
  12771. for (var _i12 = 0; _i12 < index; _i12++) {
  12772. if (columns[_i12].visible) {
  12773. width += columns[_i12].getWidth();
  12774. }
  12775. }
  12776. return width;
  12777. };
  12778. Tabulator.prototype.registerModule("frozenColumns", FrozenColumns);
  12779. var FrozenRows = function FrozenRows(table) {
  12780. this.table = table; //hold Tabulator object
  12781. this.topElement = document.createElement("div");
  12782. this.rows = [];
  12783. this.displayIndex = 0; //index in display pipeline
  12784. };
  12785. FrozenRows.prototype.initialize = function () {
  12786. this.rows = [];
  12787. this.topElement.classList.add("tabulator-frozen-rows-holder");
  12788. // this.table.columnManager.element.append(this.topElement);
  12789. this.table.columnManager.getElement().insertBefore(this.topElement, this.table.columnManager.headersElement.nextSibling);
  12790. };
  12791. FrozenRows.prototype.setDisplayIndex = function (index) {
  12792. this.displayIndex = index;
  12793. };
  12794. FrozenRows.prototype.getDisplayIndex = function () {
  12795. return this.displayIndex;
  12796. };
  12797. FrozenRows.prototype.isFrozen = function () {
  12798. return !!this.rows.length;
  12799. };
  12800. //filter frozen rows out of display data
  12801. FrozenRows.prototype.getRows = function (rows) {
  12802. var self = this,
  12803. frozen = [],
  12804. output = rows.slice(0);
  12805. this.rows.forEach(function (row) {
  12806. var index = output.indexOf(row);
  12807. if (index > -1) {
  12808. output.splice(index, 1);
  12809. }
  12810. });
  12811. return output;
  12812. };
  12813. FrozenRows.prototype.freezeRow = function (row) {
  12814. if (!row.modules.frozen) {
  12815. row.modules.frozen = true;
  12816. this.topElement.appendChild(row.getElement());
  12817. row.initialize();
  12818. row.normalizeHeight();
  12819. this.table.rowManager.adjustTableSize();
  12820. this.rows.push(row);
  12821. this.table.rowManager.refreshActiveData("display");
  12822. this.styleRows();
  12823. } else {
  12824. console.warn("Freeze Error - Row is already frozen");
  12825. }
  12826. };
  12827. FrozenRows.prototype.unfreezeRow = function (row) {
  12828. var index = this.rows.indexOf(row);
  12829. if (row.modules.frozen) {
  12830. row.modules.frozen = false;
  12831. this.detachRow(row);
  12832. this.table.rowManager.adjustTableSize();
  12833. this.table.rowManager.refreshActiveData("display");
  12834. if (this.rows.length) {
  12835. this.styleRows();
  12836. }
  12837. } else {
  12838. console.warn("Freeze Error - Row is already unfrozen");
  12839. }
  12840. };
  12841. FrozenRows.prototype.detachRow = function (row) {
  12842. var index = this.rows.indexOf(row);
  12843. if (index > -1) {
  12844. var rowEl = row.getElement();
  12845. rowEl.parentNode.removeChild(rowEl);
  12846. this.rows.splice(index, 1);
  12847. }
  12848. };
  12849. FrozenRows.prototype.styleRows = function (row) {
  12850. var self = this;
  12851. this.rows.forEach(function (row, i) {
  12852. self.table.rowManager.styleRow(row, i);
  12853. });
  12854. };
  12855. Tabulator.prototype.registerModule("frozenRows", FrozenRows);
  12856. //public group object
  12857. var GroupComponent = function GroupComponent(group) {
  12858. this._group = group;
  12859. this.type = "GroupComponent";
  12860. };
  12861. GroupComponent.prototype.getKey = function () {
  12862. return this._group.key;
  12863. };
  12864. GroupComponent.prototype.getField = function () {
  12865. return this._group.field;
  12866. };
  12867. GroupComponent.prototype.getElement = function () {
  12868. return this._group.element;
  12869. };
  12870. GroupComponent.prototype.getRows = function () {
  12871. return this._group.getRows(true);
  12872. };
  12873. GroupComponent.prototype.getSubGroups = function () {
  12874. return this._group.getSubGroups(true);
  12875. };
  12876. GroupComponent.prototype.getParentGroup = function () {
  12877. return this._group.parent ? this._group.parent.getComponent() : false;
  12878. };
  12879. GroupComponent.prototype.getVisibility = function () {
  12880. console.warn("getVisibility function is deprecated, you should now use the isVisible function");
  12881. return this._group.visible;
  12882. };
  12883. GroupComponent.prototype.isVisible = function () {
  12884. return this._group.visible;
  12885. };
  12886. GroupComponent.prototype.show = function () {
  12887. this._group.show();
  12888. };
  12889. GroupComponent.prototype.hide = function () {
  12890. this._group.hide();
  12891. };
  12892. GroupComponent.prototype.toggle = function () {
  12893. this._group.toggleVisibility();
  12894. };
  12895. GroupComponent.prototype._getSelf = function () {
  12896. return this._group;
  12897. };
  12898. GroupComponent.prototype.getTable = function () {
  12899. return this._group.groupManager.table;
  12900. };
  12901. //////////////////////////////////////////////////
  12902. //////////////// Group Functions /////////////////
  12903. //////////////////////////////////////////////////
  12904. var Group = function Group(groupManager, parent, level, key, field, generator, oldGroup) {
  12905. this.groupManager = groupManager;
  12906. this.parent = parent;
  12907. this.key = key;
  12908. this.level = level;
  12909. this.field = field;
  12910. this.hasSubGroups = level < groupManager.groupIDLookups.length - 1;
  12911. this.addRow = this.hasSubGroups ? this._addRowToGroup : this._addRow;
  12912. this.type = "group"; //type of element
  12913. this.old = oldGroup;
  12914. this.rows = [];
  12915. this.groups = [];
  12916. this.groupList = [];
  12917. this.generator = generator;
  12918. this.elementContents = false;
  12919. this.height = 0;
  12920. this.outerHeight = 0;
  12921. this.initialized = false;
  12922. this.calcs = {};
  12923. this.initialized = false;
  12924. this.modules = {};
  12925. this.arrowElement = false;
  12926. this.visible = oldGroup ? oldGroup.visible : typeof groupManager.startOpen[level] !== "undefined" ? groupManager.startOpen[level] : groupManager.startOpen[0];
  12927. this.component = null;
  12928. this.createElements();
  12929. this.addBindings();
  12930. this.createValueGroups();
  12931. };
  12932. Group.prototype.wipe = function () {
  12933. if (this.groupList.length) {
  12934. this.groupList.forEach(function (group) {
  12935. group.wipe();
  12936. });
  12937. } else {
  12938. this.element = false;
  12939. this.arrowElement = false;
  12940. this.elementContents = false;
  12941. }
  12942. };
  12943. Group.prototype.createElements = function () {
  12944. var arrow = document.createElement("div");
  12945. arrow.classList.add("tabulator-arrow");
  12946. this.element = document.createElement("div");
  12947. this.element.classList.add("tabulator-row");
  12948. this.element.classList.add("tabulator-group");
  12949. this.element.classList.add("tabulator-group-level-" + this.level);
  12950. this.element.setAttribute("role", "rowgroup");
  12951. this.arrowElement = document.createElement("div");
  12952. this.arrowElement.classList.add("tabulator-group-toggle");
  12953. this.arrowElement.appendChild(arrow);
  12954. //setup movable rows
  12955. if (this.groupManager.table.options.movableRows !== false && this.groupManager.table.modExists("moveRow")) {
  12956. this.groupManager.table.modules.moveRow.initializeGroupHeader(this);
  12957. }
  12958. };
  12959. Group.prototype.createValueGroups = function () {
  12960. var _this68 = this;
  12961. var level = this.level + 1;
  12962. if (this.groupManager.allowedValues && this.groupManager.allowedValues[level]) {
  12963. this.groupManager.allowedValues[level].forEach(function (value) {
  12964. _this68._createGroup(value, level);
  12965. });
  12966. }
  12967. };
  12968. Group.prototype.addBindings = function () {
  12969. var self = this,
  12970. dblTap,
  12971. tapHold,
  12972. tap,
  12973. toggleElement;
  12974. //handle group click events
  12975. if (self.groupManager.table.options.groupClick) {
  12976. self.element.addEventListener("click", function (e) {
  12977. self.groupManager.table.options.groupClick.call(self.groupManager.table, e, self.getComponent());
  12978. });
  12979. }
  12980. if (self.groupManager.table.options.groupDblClick) {
  12981. self.element.addEventListener("dblclick", function (e) {
  12982. self.groupManager.table.options.groupDblClick.call(self.groupManager.table, e, self.getComponent());
  12983. });
  12984. }
  12985. if (self.groupManager.table.options.groupContext) {
  12986. self.element.addEventListener("contextmenu", function (e) {
  12987. self.groupManager.table.options.groupContext.call(self.groupManager.table, e, self.getComponent());
  12988. });
  12989. }
  12990. if ((self.groupManager.table.options.groupContextMenu || self.groupManager.table.options.groupClickMenu) && self.groupManager.table.modExists("menu")) {
  12991. self.groupManager.table.modules.menu.initializeGroup.call(self.groupManager.table.modules.menu, self);
  12992. }
  12993. if (self.groupManager.table.options.groupTap) {
  12994. tap = false;
  12995. self.element.addEventListener("touchstart", function (e) {
  12996. tap = true;
  12997. }, { passive: true });
  12998. self.element.addEventListener("touchend", function (e) {
  12999. if (tap) {
  13000. self.groupManager.table.options.groupTap(e, self.getComponent());
  13001. }
  13002. tap = false;
  13003. });
  13004. }
  13005. if (self.groupManager.table.options.groupDblTap) {
  13006. dblTap = null;
  13007. self.element.addEventListener("touchend", function (e) {
  13008. if (dblTap) {
  13009. clearTimeout(dblTap);
  13010. dblTap = null;
  13011. self.groupManager.table.options.groupDblTap(e, self.getComponent());
  13012. } else {
  13013. dblTap = setTimeout(function () {
  13014. clearTimeout(dblTap);
  13015. dblTap = null;
  13016. }, 300);
  13017. }
  13018. });
  13019. }
  13020. if (self.groupManager.table.options.groupTapHold) {
  13021. tapHold = null;
  13022. self.element.addEventListener("touchstart", function (e) {
  13023. clearTimeout(tapHold);
  13024. tapHold = setTimeout(function () {
  13025. clearTimeout(tapHold);
  13026. tapHold = null;
  13027. tap = false;
  13028. self.groupManager.table.options.groupTapHold(e, self.getComponent());
  13029. }, 1000);
  13030. }, { passive: true });
  13031. self.element.addEventListener("touchend", function (e) {
  13032. clearTimeout(tapHold);
  13033. tapHold = null;
  13034. });
  13035. }
  13036. if (self.groupManager.table.options.groupToggleElement) {
  13037. toggleElement = self.groupManager.table.options.groupToggleElement == "arrow" ? self.arrowElement : self.element;
  13038. toggleElement.addEventListener("click", function (e) {
  13039. e.stopPropagation();
  13040. e.stopImmediatePropagation();
  13041. self.toggleVisibility();
  13042. });
  13043. }
  13044. };
  13045. Group.prototype._createGroup = function (groupID, level) {
  13046. var groupKey = level + "_" + groupID;
  13047. 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);
  13048. this.groups[groupKey] = group;
  13049. this.groupList.push(group);
  13050. };
  13051. Group.prototype._addRowToGroup = function (row) {
  13052. var level = this.level + 1;
  13053. if (this.hasSubGroups) {
  13054. var groupID = this.groupManager.groupIDLookups[level].func(row.getData()),
  13055. groupKey = level + "_" + groupID;
  13056. if (this.groupManager.allowedValues && this.groupManager.allowedValues[level]) {
  13057. if (this.groups[groupKey]) {
  13058. this.groups[groupKey].addRow(row);
  13059. }
  13060. } else {
  13061. if (!this.groups[groupKey]) {
  13062. this._createGroup(groupID, level);
  13063. }
  13064. this.groups[groupKey].addRow(row);
  13065. }
  13066. }
  13067. };
  13068. Group.prototype._addRow = function (row) {
  13069. this.rows.push(row);
  13070. row.modules.group = this;
  13071. };
  13072. Group.prototype.insertRow = function (row, to, after) {
  13073. var data = this.conformRowData({});
  13074. row.updateData(data);
  13075. var toIndex = this.rows.indexOf(to);
  13076. if (toIndex > -1) {
  13077. if (after) {
  13078. this.rows.splice(toIndex + 1, 0, row);
  13079. } else {
  13080. this.rows.splice(toIndex, 0, row);
  13081. }
  13082. } else {
  13083. if (after) {
  13084. this.rows.push(row);
  13085. } else {
  13086. this.rows.unshift(row);
  13087. }
  13088. }
  13089. row.modules.group = this;
  13090. this.generateGroupHeaderContents();
  13091. if (this.groupManager.table.modExists("columnCalcs") && this.groupManager.table.options.columnCalcs != "table") {
  13092. this.groupManager.table.modules.columnCalcs.recalcGroup(this);
  13093. }
  13094. this.groupManager.updateGroupRows(true);
  13095. };
  13096. Group.prototype.scrollHeader = function (left) {
  13097. this.arrowElement.style.marginLeft = left;
  13098. this.groupList.forEach(function (child) {
  13099. child.scrollHeader(left);
  13100. });
  13101. };
  13102. Group.prototype.getRowIndex = function (row) {};
  13103. //update row data to match grouping contraints
  13104. Group.prototype.conformRowData = function (data) {
  13105. if (this.field) {
  13106. data[this.field] = this.key;
  13107. } else {
  13108. console.warn("Data Conforming Error - Cannot conform row data to match new group as groupBy is a function");
  13109. }
  13110. if (this.parent) {
  13111. data = this.parent.conformRowData(data);
  13112. }
  13113. return data;
  13114. };
  13115. Group.prototype.removeRow = function (row) {
  13116. var index = this.rows.indexOf(row);
  13117. var el = row.getElement();
  13118. if (index > -1) {
  13119. this.rows.splice(index, 1);
  13120. }
  13121. if (!this.groupManager.table.options.groupValues && !this.rows.length) {
  13122. if (this.parent) {
  13123. this.parent.removeGroup(this);
  13124. } else {
  13125. this.groupManager.removeGroup(this);
  13126. }
  13127. this.groupManager.updateGroupRows(true);
  13128. } else {
  13129. if (el.parentNode) {
  13130. el.parentNode.removeChild(el);
  13131. }
  13132. this.generateGroupHeaderContents();
  13133. if (this.groupManager.table.modExists("columnCalcs") && this.groupManager.table.options.columnCalcs != "table") {
  13134. this.groupManager.table.modules.columnCalcs.recalcGroup(this);
  13135. }
  13136. }
  13137. };
  13138. Group.prototype.removeGroup = function (group) {
  13139. var groupKey = group.level + "_" + group.key,
  13140. index;
  13141. if (this.groups[groupKey]) {
  13142. delete this.groups[groupKey];
  13143. index = this.groupList.indexOf(group);
  13144. if (index > -1) {
  13145. this.groupList.splice(index, 1);
  13146. }
  13147. if (!this.groupList.length) {
  13148. if (this.parent) {
  13149. this.parent.removeGroup(this);
  13150. } else {
  13151. this.groupManager.removeGroup(this);
  13152. }
  13153. }
  13154. }
  13155. };
  13156. Group.prototype.getHeadersAndRows = function (noCalc) {
  13157. var output = [];
  13158. output.push(this);
  13159. this._visSet();
  13160. if (this.visible) {
  13161. if (this.groupList.length) {
  13162. this.groupList.forEach(function (group) {
  13163. output = output.concat(group.getHeadersAndRows(noCalc));
  13164. });
  13165. } else {
  13166. if (!noCalc && this.groupManager.table.options.columnCalcs != "table" && this.groupManager.table.modExists("columnCalcs") && this.groupManager.table.modules.columnCalcs.hasTopCalcs()) {
  13167. if (this.calcs.top) {
  13168. this.calcs.top.detachElement();
  13169. this.calcs.top.deleteCells();
  13170. }
  13171. this.calcs.top = this.groupManager.table.modules.columnCalcs.generateTopRow(this.rows);
  13172. output.push(this.calcs.top);
  13173. }
  13174. output = output.concat(this.rows);
  13175. if (!noCalc && this.groupManager.table.options.columnCalcs != "table" && this.groupManager.table.modExists("columnCalcs") && this.groupManager.table.modules.columnCalcs.hasBottomCalcs()) {
  13176. if (this.calcs.bottom) {
  13177. this.calcs.bottom.detachElement();
  13178. this.calcs.bottom.deleteCells();
  13179. }
  13180. this.calcs.bottom = this.groupManager.table.modules.columnCalcs.generateBottomRow(this.rows);
  13181. output.push(this.calcs.bottom);
  13182. }
  13183. }
  13184. } else {
  13185. if (!this.groupList.length && this.groupManager.table.options.columnCalcs != "table") {
  13186. if (this.groupManager.table.modExists("columnCalcs")) {
  13187. if (!noCalc && this.groupManager.table.modules.columnCalcs.hasTopCalcs()) {
  13188. if (this.calcs.top) {
  13189. this.calcs.top.detachElement();
  13190. this.calcs.top.deleteCells();
  13191. }
  13192. if (this.groupManager.table.options.groupClosedShowCalcs) {
  13193. this.calcs.top = this.groupManager.table.modules.columnCalcs.generateTopRow(this.rows);
  13194. output.push(this.calcs.top);
  13195. }
  13196. }
  13197. if (!noCalc && this.groupManager.table.modules.columnCalcs.hasBottomCalcs()) {
  13198. if (this.calcs.bottom) {
  13199. this.calcs.bottom.detachElement();
  13200. this.calcs.bottom.deleteCells();
  13201. }
  13202. if (this.groupManager.table.options.groupClosedShowCalcs) {
  13203. this.calcs.bottom = this.groupManager.table.modules.columnCalcs.generateBottomRow(this.rows);
  13204. output.push(this.calcs.bottom);
  13205. }
  13206. }
  13207. }
  13208. }
  13209. }
  13210. return output;
  13211. };
  13212. Group.prototype.getData = function (visible, transform) {
  13213. var self = this,
  13214. output = [];
  13215. this._visSet();
  13216. if (!visible || visible && this.visible) {
  13217. this.rows.forEach(function (row) {
  13218. output.push(row.getData(transform || "data"));
  13219. });
  13220. }
  13221. return output;
  13222. };
  13223. // Group.prototype.getRows = function(){
  13224. // this._visSet();
  13225. // return this.visible ? this.rows : [];
  13226. // };
  13227. Group.prototype.getRowCount = function () {
  13228. var count = 0;
  13229. if (this.groupList.length) {
  13230. this.groupList.forEach(function (group) {
  13231. count += group.getRowCount();
  13232. });
  13233. } else {
  13234. count = this.rows.length;
  13235. }
  13236. return count;
  13237. };
  13238. Group.prototype.toggleVisibility = function () {
  13239. if (this.visible) {
  13240. this.hide();
  13241. } else {
  13242. this.show();
  13243. }
  13244. };
  13245. Group.prototype.hide = function () {
  13246. this.visible = false;
  13247. if (this.groupManager.table.rowManager.getRenderMode() == "classic" && !this.groupManager.table.options.pagination) {
  13248. this.element.classList.remove("tabulator-group-visible");
  13249. if (this.groupList.length) {
  13250. this.groupList.forEach(function (group) {
  13251. var rows = group.getHeadersAndRows();
  13252. rows.forEach(function (row) {
  13253. row.detachElement();
  13254. });
  13255. });
  13256. } else {
  13257. this.rows.forEach(function (row) {
  13258. var rowEl = row.getElement();
  13259. rowEl.parentNode.removeChild(rowEl);
  13260. });
  13261. }
  13262. this.groupManager.table.rowManager.setDisplayRows(this.groupManager.updateGroupRows(), this.groupManager.getDisplayIndex());
  13263. this.groupManager.table.rowManager.checkClassicModeGroupHeaderWidth();
  13264. } else {
  13265. this.groupManager.updateGroupRows(true);
  13266. }
  13267. this.groupManager.table.options.groupVisibilityChanged.call(this.table, this.getComponent(), false);
  13268. };
  13269. Group.prototype.show = function () {
  13270. var self = this;
  13271. self.visible = true;
  13272. if (this.groupManager.table.rowManager.getRenderMode() == "classic" && !this.groupManager.table.options.pagination) {
  13273. this.element.classList.add("tabulator-group-visible");
  13274. var prev = self.getElement();
  13275. if (this.groupList.length) {
  13276. this.groupList.forEach(function (group) {
  13277. var rows = group.getHeadersAndRows();
  13278. rows.forEach(function (row) {
  13279. var rowEl = row.getElement();
  13280. prev.parentNode.insertBefore(rowEl, prev.nextSibling);
  13281. row.initialize();
  13282. prev = rowEl;
  13283. });
  13284. });
  13285. } else {
  13286. self.rows.forEach(function (row) {
  13287. var rowEl = row.getElement();
  13288. prev.parentNode.insertBefore(rowEl, prev.nextSibling);
  13289. row.initialize();
  13290. prev = rowEl;
  13291. });
  13292. }
  13293. this.groupManager.table.rowManager.setDisplayRows(this.groupManager.updateGroupRows(), this.groupManager.getDisplayIndex());
  13294. this.groupManager.table.rowManager.checkClassicModeGroupHeaderWidth();
  13295. } else {
  13296. this.groupManager.updateGroupRows(true);
  13297. }
  13298. this.groupManager.table.options.groupVisibilityChanged.call(this.table, this.getComponent(), true);
  13299. };
  13300. Group.prototype._visSet = function () {
  13301. var data = [];
  13302. if (typeof this.visible == "function") {
  13303. this.rows.forEach(function (row) {
  13304. data.push(row.getData());
  13305. });
  13306. this.visible = this.visible(this.key, this.getRowCount(), data, this.getComponent());
  13307. }
  13308. };
  13309. Group.prototype.getRowGroup = function (row) {
  13310. var match = false;
  13311. if (this.groupList.length) {
  13312. this.groupList.forEach(function (group) {
  13313. var result = group.getRowGroup(row);
  13314. if (result) {
  13315. match = result;
  13316. }
  13317. });
  13318. } else {
  13319. if (this.rows.find(function (item) {
  13320. return item === row;
  13321. })) {
  13322. match = this;
  13323. }
  13324. }
  13325. return match;
  13326. };
  13327. Group.prototype.getSubGroups = function (component) {
  13328. var output = [];
  13329. this.groupList.forEach(function (child) {
  13330. output.push(component ? child.getComponent() : child);
  13331. });
  13332. return output;
  13333. };
  13334. Group.prototype.getRows = function (compoment) {
  13335. var output = [];
  13336. this.rows.forEach(function (row) {
  13337. output.push(compoment ? row.getComponent() : row);
  13338. });
  13339. return output;
  13340. };
  13341. Group.prototype.generateGroupHeaderContents = function () {
  13342. var data = [];
  13343. this.rows.forEach(function (row) {
  13344. data.push(row.getData());
  13345. });
  13346. this.elementContents = this.generator(this.key, this.getRowCount(), data, this.getComponent());
  13347. while (this.element.firstChild) {
  13348. this.element.removeChild(this.element.firstChild);
  13349. }if (typeof this.elementContents === "string") {
  13350. this.element.innerHTML = this.elementContents;
  13351. } else {
  13352. this.element.appendChild(this.elementContents);
  13353. }
  13354. this.element.insertBefore(this.arrowElement, this.element.firstChild);
  13355. };
  13356. Group.prototype.getPath = function () {
  13357. var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  13358. path.unshift(this.key);
  13359. if (this.parent) {
  13360. this.parent.getPath(path);
  13361. }
  13362. return path;
  13363. };
  13364. ////////////// Standard Row Functions //////////////
  13365. Group.prototype.getElement = function () {
  13366. this.addBindingsd = false;
  13367. this._visSet();
  13368. if (this.visible) {
  13369. this.element.classList.add("tabulator-group-visible");
  13370. } else {
  13371. this.element.classList.remove("tabulator-group-visible");
  13372. }
  13373. for (var i = 0; i < this.element.childNodes.length; ++i) {
  13374. this.element.childNodes[i].parentNode.removeChild(this.element.childNodes[i]);
  13375. }
  13376. this.generateGroupHeaderContents();
  13377. // this.addBindings();
  13378. return this.element;
  13379. };
  13380. Group.prototype.detachElement = function () {
  13381. if (this.element && this.element.parentNode) {
  13382. this.element.parentNode.removeChild(this.element);
  13383. }
  13384. };
  13385. //normalize the height of elements in the row
  13386. Group.prototype.normalizeHeight = function () {
  13387. this.setHeight(this.element.clientHeight);
  13388. };
  13389. Group.prototype.initialize = function (force) {
  13390. if (!this.initialized || force) {
  13391. this.normalizeHeight();
  13392. this.initialized = true;
  13393. }
  13394. };
  13395. Group.prototype.reinitialize = function () {
  13396. this.initialized = false;
  13397. this.height = 0;
  13398. if (Tabulator.prototype.helpers.elVisible(this.element)) {
  13399. this.initialize(true);
  13400. }
  13401. };
  13402. Group.prototype.setHeight = function (height) {
  13403. if (this.height != height) {
  13404. this.height = height;
  13405. this.outerHeight = this.element.offsetHeight;
  13406. }
  13407. };
  13408. //return rows outer height
  13409. Group.prototype.getHeight = function () {
  13410. return this.outerHeight;
  13411. };
  13412. Group.prototype.getGroup = function () {
  13413. return this;
  13414. };
  13415. Group.prototype.reinitializeHeight = function () {};
  13416. Group.prototype.calcHeight = function () {};
  13417. Group.prototype.setCellHeight = function () {};
  13418. Group.prototype.clearCellHeight = function () {};
  13419. //////////////// Object Generation /////////////////
  13420. Group.prototype.getComponent = function () {
  13421. if (!this.component) {
  13422. this.component = new GroupComponent(this);
  13423. }
  13424. return this.component;
  13425. };
  13426. //////////////////////////////////////////////////
  13427. ////////////// Group Row Extension ///////////////
  13428. //////////////////////////////////////////////////
  13429. var GroupRows = function GroupRows(table) {
  13430. this.table = table; //hold Tabulator object
  13431. this.groupIDLookups = false; //enable table grouping and set field to group by
  13432. this.startOpen = [function () {
  13433. return false;
  13434. }]; //starting state of group
  13435. this.headerGenerator = [function () {
  13436. return "";
  13437. }];
  13438. this.groupList = []; //ordered list of groups
  13439. this.allowedValues = false;
  13440. this.groups = {}; //hold row groups
  13441. this.displayIndex = 0; //index in display pipeline
  13442. };
  13443. //initialize group configuration
  13444. GroupRows.prototype.initialize = function () {
  13445. var self = this,
  13446. groupBy = self.table.options.groupBy,
  13447. startOpen = self.table.options.groupStartOpen,
  13448. groupHeader = self.table.options.groupHeader;
  13449. this.allowedValues = self.table.options.groupValues;
  13450. if (Array.isArray(groupBy) && Array.isArray(groupHeader) && groupBy.length > groupHeader.length) {
  13451. console.warn("Error creating group headers, groupHeader array is shorter than groupBy array");
  13452. }
  13453. self.headerGenerator = [function () {
  13454. return "";
  13455. }];
  13456. this.startOpen = [function () {
  13457. return false;
  13458. }]; //starting state of group
  13459. self.table.modules.localize.bind("groups|item", function (langValue, lang) {
  13460. self.headerGenerator[0] = function (value, count, data) {
  13461. //header layout function
  13462. return (typeof value === "undefined" ? "" : value) + "<span>(" + count + " " + (count === 1 ? langValue : lang.groups.items) + ")</span>";
  13463. };
  13464. });
  13465. this.groupIDLookups = [];
  13466. if (Array.isArray(groupBy) || groupBy) {
  13467. if (this.table.modExists("columnCalcs") && this.table.options.columnCalcs != "table" && this.table.options.columnCalcs != "both") {
  13468. this.table.modules.columnCalcs.removeCalcs();
  13469. }
  13470. } else {
  13471. if (this.table.modExists("columnCalcs") && this.table.options.columnCalcs != "group") {
  13472. var cols = this.table.columnManager.getRealColumns();
  13473. cols.forEach(function (col) {
  13474. if (col.definition.topCalc) {
  13475. self.table.modules.columnCalcs.initializeTopRow();
  13476. }
  13477. if (col.definition.bottomCalc) {
  13478. self.table.modules.columnCalcs.initializeBottomRow();
  13479. }
  13480. });
  13481. }
  13482. }
  13483. if (!Array.isArray(groupBy)) {
  13484. groupBy = [groupBy];
  13485. }
  13486. groupBy.forEach(function (group, i) {
  13487. var lookupFunc, column;
  13488. if (typeof group == "function") {
  13489. lookupFunc = group;
  13490. } else {
  13491. column = self.table.columnManager.getColumnByField(group);
  13492. if (column) {
  13493. lookupFunc = function lookupFunc(data) {
  13494. return column.getFieldValue(data);
  13495. };
  13496. } else {
  13497. lookupFunc = function lookupFunc(data) {
  13498. return data[group];
  13499. };
  13500. }
  13501. }
  13502. self.groupIDLookups.push({
  13503. field: typeof group === "function" ? false : group,
  13504. func: lookupFunc,
  13505. values: self.allowedValues ? self.allowedValues[i] : false
  13506. });
  13507. });
  13508. if (startOpen) {
  13509. if (!Array.isArray(startOpen)) {
  13510. startOpen = [startOpen];
  13511. }
  13512. startOpen.forEach(function (level) {
  13513. level = typeof level == "function" ? level : function () {
  13514. return true;
  13515. };
  13516. });
  13517. self.startOpen = startOpen;
  13518. }
  13519. if (groupHeader) {
  13520. self.headerGenerator = Array.isArray(groupHeader) ? groupHeader : [groupHeader];
  13521. }
  13522. this.initialized = true;
  13523. };
  13524. GroupRows.prototype.setDisplayIndex = function (index) {
  13525. this.displayIndex = index;
  13526. };
  13527. GroupRows.prototype.getDisplayIndex = function () {
  13528. return this.displayIndex;
  13529. };
  13530. //return appropriate rows with group headers
  13531. GroupRows.prototype.getRows = function (rows) {
  13532. if (this.groupIDLookups.length) {
  13533. this.table.options.dataGrouping.call(this.table);
  13534. this.generateGroups(rows);
  13535. if (this.table.options.dataGrouped) {
  13536. this.table.options.dataGrouped.call(this.table, this.getGroups(true));
  13537. }
  13538. return this.updateGroupRows();
  13539. } else {
  13540. return rows.slice(0);
  13541. }
  13542. };
  13543. GroupRows.prototype.getGroups = function (compoment) {
  13544. var groupComponents = [];
  13545. this.groupList.forEach(function (group) {
  13546. groupComponents.push(compoment ? group.getComponent() : group);
  13547. });
  13548. return groupComponents;
  13549. };
  13550. GroupRows.prototype.getChildGroups = function (group) {
  13551. var _this69 = this;
  13552. var groupComponents = [];
  13553. if (!group) {
  13554. group = this;
  13555. }
  13556. group.groupList.forEach(function (child) {
  13557. if (child.groupList.length) {
  13558. groupComponents = groupComponents.concat(_this69.getChildGroups(child));
  13559. } else {
  13560. groupComponents.push(child);
  13561. }
  13562. });
  13563. return groupComponents;
  13564. };
  13565. GroupRows.prototype.wipe = function () {
  13566. this.groupList.forEach(function (group) {
  13567. group.wipe();
  13568. });
  13569. };
  13570. GroupRows.prototype.pullGroupListData = function (groupList) {
  13571. var self = this;
  13572. var groupListData = [];
  13573. groupList.forEach(function (group) {
  13574. var groupHeader = {};
  13575. groupHeader.level = 0;
  13576. groupHeader.rowCount = 0;
  13577. groupHeader.headerContent = "";
  13578. var childData = [];
  13579. if (group.hasSubGroups) {
  13580. childData = self.pullGroupListData(group.groupList);
  13581. groupHeader.level = group.level;
  13582. groupHeader.rowCount = childData.length - group.groupList.length; // data length minus number of sub-headers
  13583. groupHeader.headerContent = group.generator(group.key, groupHeader.rowCount, group.rows, group);
  13584. groupListData.push(groupHeader);
  13585. groupListData = groupListData.concat(childData);
  13586. } else {
  13587. groupHeader.level = group.level;
  13588. groupHeader.headerContent = group.generator(group.key, group.rows.length, group.rows, group);
  13589. groupHeader.rowCount = group.getRows().length;
  13590. groupListData.push(groupHeader);
  13591. group.getRows().forEach(function (row) {
  13592. groupListData.push(row.getData("data"));
  13593. });
  13594. }
  13595. });
  13596. return groupListData;
  13597. };
  13598. GroupRows.prototype.getGroupedData = function () {
  13599. return this.pullGroupListData(this.groupList);
  13600. };
  13601. GroupRows.prototype.getRowGroup = function (row) {
  13602. var match = false;
  13603. this.groupList.forEach(function (group) {
  13604. var result = group.getRowGroup(row);
  13605. if (result) {
  13606. match = result;
  13607. }
  13608. });
  13609. return match;
  13610. };
  13611. GroupRows.prototype.countGroups = function () {
  13612. return this.groupList.length;
  13613. };
  13614. GroupRows.prototype.generateGroups = function (rows) {
  13615. var self = this,
  13616. oldGroups = self.groups;
  13617. self.groups = {};
  13618. self.groupList = [];
  13619. if (this.allowedValues && this.allowedValues[0]) {
  13620. this.allowedValues[0].forEach(function (value) {
  13621. self.createGroup(value, 0, oldGroups);
  13622. });
  13623. rows.forEach(function (row) {
  13624. self.assignRowToExistingGroup(row, oldGroups);
  13625. });
  13626. } else {
  13627. rows.forEach(function (row) {
  13628. self.assignRowToGroup(row, oldGroups);
  13629. });
  13630. }
  13631. };
  13632. GroupRows.prototype.createGroup = function (groupID, level, oldGroups) {
  13633. var groupKey = level + "_" + groupID,
  13634. group;
  13635. oldGroups = oldGroups || [];
  13636. group = new Group(this, false, level, groupID, this.groupIDLookups[0].field, this.headerGenerator[0], oldGroups[groupKey]);
  13637. this.groups[groupKey] = group;
  13638. this.groupList.push(group);
  13639. };
  13640. // GroupRows.prototype.assignRowToGroup = function(row, oldGroups){
  13641. // var groupID = this.groupIDLookups[0].func(row.getData()),
  13642. // groupKey = "0_" + groupID;
  13643. // if(!this.groups[groupKey]){
  13644. // this.createGroup(groupID, 0, oldGroups);
  13645. // }
  13646. // this.groups[groupKey].addRow(row);
  13647. // };
  13648. GroupRows.prototype.assignRowToExistingGroup = function (row, oldGroups) {
  13649. var groupID = this.groupIDLookups[0].func(row.getData()),
  13650. groupKey = "0_" + groupID;
  13651. if (this.groups[groupKey]) {
  13652. this.groups[groupKey].addRow(row);
  13653. }
  13654. };
  13655. GroupRows.prototype.assignRowToGroup = function (row, oldGroups) {
  13656. var groupID = this.groupIDLookups[0].func(row.getData()),
  13657. newGroupNeeded = !this.groups["0_" + groupID];
  13658. if (newGroupNeeded) {
  13659. this.createGroup(groupID, 0, oldGroups);
  13660. }
  13661. this.groups["0_" + groupID].addRow(row);
  13662. return !newGroupNeeded;
  13663. };
  13664. GroupRows.prototype.reassignRowToGroup = function (row) {
  13665. var oldRowGroup = row.getGroup(),
  13666. oldGroupPath = oldRowGroup.getPath(),
  13667. newGroupPath = this.getExpectedPath(row),
  13668. samePath = true;
  13669. // figure out if new group path is the same as old group path
  13670. var samePath = oldGroupPath.length == newGroupPath.length && oldGroupPath.every(function (element, index) {
  13671. return element === newGroupPath[index];
  13672. });
  13673. // refresh if they new path and old path aren't the same (aka the row's groupings have changed)
  13674. if (!samePath) {
  13675. oldRowGroup.removeRow(row);
  13676. this.assignRowToGroup(row, self.groups);
  13677. this.table.rowManager.refreshActiveData("group", false, true);
  13678. }
  13679. };
  13680. GroupRows.prototype.getExpectedPath = function (row) {
  13681. var groupPath = [],
  13682. rowData = row.getData();
  13683. this.groupIDLookups.forEach(function (groupId) {
  13684. groupPath.push(groupId.func(rowData));
  13685. });
  13686. return groupPath;
  13687. };
  13688. GroupRows.prototype.updateGroupRows = function (force) {
  13689. var self = this,
  13690. output = [],
  13691. oldRowCount;
  13692. self.groupList.forEach(function (group) {
  13693. output = output.concat(group.getHeadersAndRows());
  13694. });
  13695. //force update of table display
  13696. if (force) {
  13697. var displayIndex = self.table.rowManager.setDisplayRows(output, this.getDisplayIndex());
  13698. if (displayIndex !== true) {
  13699. this.setDisplayIndex(displayIndex);
  13700. }
  13701. self.table.rowManager.refreshActiveData("group", true, true);
  13702. }
  13703. return output;
  13704. };
  13705. GroupRows.prototype.scrollHeaders = function (left) {
  13706. if (this.table.options.virtualDomHoz) {
  13707. left -= this.table.vdomHoz.vDomPadLeft;
  13708. }
  13709. left = left + "px";
  13710. this.groupList.forEach(function (group) {
  13711. group.scrollHeader(left);
  13712. });
  13713. };
  13714. GroupRows.prototype.removeGroup = function (group) {
  13715. var groupKey = group.level + "_" + group.key,
  13716. index;
  13717. if (this.groups[groupKey]) {
  13718. delete this.groups[groupKey];
  13719. index = this.groupList.indexOf(group);
  13720. if (index > -1) {
  13721. this.groupList.splice(index, 1);
  13722. }
  13723. }
  13724. };
  13725. Tabulator.prototype.registerModule("groupRows", GroupRows);
  13726. var History = function History(table) {
  13727. this.table = table; //hold Tabulator object
  13728. this.history = [];
  13729. this.index = -1;
  13730. };
  13731. History.prototype.clear = function () {
  13732. this.history = [];
  13733. this.index = -1;
  13734. };
  13735. History.prototype.action = function (type, component, data) {
  13736. this.history = this.history.slice(0, this.index + 1);
  13737. this.history.push({
  13738. type: type,
  13739. component: component,
  13740. data: data
  13741. });
  13742. this.index++;
  13743. };
  13744. History.prototype.getHistoryUndoSize = function () {
  13745. return this.index + 1;
  13746. };
  13747. History.prototype.getHistoryRedoSize = function () {
  13748. return this.history.length - (this.index + 1);
  13749. };
  13750. History.prototype.clearComponentHistory = function (component) {
  13751. var index = this.history.findIndex(function (item) {
  13752. return item.component === component;
  13753. });
  13754. if (index > -1) {
  13755. this.history.splice(index, 1);
  13756. if (index <= this.index) {
  13757. this.index--;
  13758. }
  13759. this.clearComponentHistory(component);
  13760. }
  13761. };
  13762. History.prototype.undo = function () {
  13763. if (this.index > -1) {
  13764. var action = this.history[this.index];
  13765. this.undoers[action.type].call(this, action);
  13766. this.index--;
  13767. this.table.options.historyUndo.call(this.table, action.type, action.component.getComponent(), action.data);
  13768. return true;
  13769. } else {
  13770. console.warn("History Undo Error - No more history to undo");
  13771. return false;
  13772. }
  13773. };
  13774. History.prototype.redo = function () {
  13775. if (this.history.length - 1 > this.index) {
  13776. this.index++;
  13777. var action = this.history[this.index];
  13778. this.redoers[action.type].call(this, action);
  13779. this.table.options.historyRedo.call(this.table, action.type, action.component.getComponent(), action.data);
  13780. return true;
  13781. } else {
  13782. console.warn("History Redo Error - No more history to redo");
  13783. return false;
  13784. }
  13785. };
  13786. History.prototype.undoers = {
  13787. cellEdit: function cellEdit(action) {
  13788. action.component.setValueProcessData(action.data.oldValue);
  13789. },
  13790. rowAdd: function rowAdd(action) {
  13791. action.component.deleteActual();
  13792. },
  13793. rowDelete: function rowDelete(action) {
  13794. var newRow = this.table.rowManager.addRowActual(action.data.data, action.data.pos, action.data.index);
  13795. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  13796. this.table.modules.groupRows.updateGroupRows(true);
  13797. }
  13798. this._rebindRow(action.component, newRow);
  13799. },
  13800. rowMove: function rowMove(action) {
  13801. this.table.rowManager.moveRowActual(action.component, this.table.rowManager.rows[action.data.posFrom], !action.data.after);
  13802. this.table.rowManager.redraw();
  13803. }
  13804. };
  13805. History.prototype.redoers = {
  13806. cellEdit: function cellEdit(action) {
  13807. action.component.setValueProcessData(action.data.newValue);
  13808. },
  13809. rowAdd: function rowAdd(action) {
  13810. var newRow = this.table.rowManager.addRowActual(action.data.data, action.data.pos, action.data.index);
  13811. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  13812. this.table.modules.groupRows.updateGroupRows(true);
  13813. }
  13814. this._rebindRow(action.component, newRow);
  13815. },
  13816. rowDelete: function rowDelete(action) {
  13817. action.component.deleteActual();
  13818. },
  13819. rowMove: function rowMove(action) {
  13820. this.table.rowManager.moveRowActual(action.component, this.table.rowManager.rows[action.data.posTo], action.data.after);
  13821. this.table.rowManager.redraw();
  13822. }
  13823. };
  13824. //rebind rows to new element after deletion
  13825. History.prototype._rebindRow = function (oldRow, newRow) {
  13826. this.history.forEach(function (action) {
  13827. if (action.component instanceof Row) {
  13828. if (action.component === oldRow) {
  13829. action.component = newRow;
  13830. }
  13831. } else if (action.component instanceof Cell) {
  13832. if (action.component.row === oldRow) {
  13833. var field = action.component.column.getField();
  13834. if (field) {
  13835. action.component = newRow.getCell(field);
  13836. }
  13837. }
  13838. }
  13839. });
  13840. };
  13841. Tabulator.prototype.registerModule("history", History);
  13842. var HtmlTableImport = function HtmlTableImport(table) {
  13843. this.table = table; //hold Tabulator object
  13844. this.fieldIndex = [];
  13845. this.hasIndex = false;
  13846. };
  13847. HtmlTableImport.prototype.parseTable = function () {
  13848. var self = this,
  13849. element = self.table.element,
  13850. options = self.table.options,
  13851. columns = options.columns,
  13852. headers = element.getElementsByTagName("th"),
  13853. rows = element.getElementsByTagName("tbody")[0],
  13854. data = [],
  13855. newTable;
  13856. self.hasIndex = false;
  13857. self.table.options.htmlImporting.call(this.table);
  13858. rows = rows ? rows.getElementsByTagName("tr") : [];
  13859. //check for tablator inline options
  13860. self._extractOptions(element, options);
  13861. if (headers.length) {
  13862. self._extractHeaders(headers, rows);
  13863. } else {
  13864. self._generateBlankHeaders(headers, rows);
  13865. }
  13866. //iterate through table rows and build data set
  13867. for (var index = 0; index < rows.length; index++) {
  13868. var row = rows[index],
  13869. cells = row.getElementsByTagName("td"),
  13870. item = {};
  13871. //create index if the dont exist in table
  13872. if (!self.hasIndex) {
  13873. item[options.index] = index;
  13874. }
  13875. for (var i = 0; i < cells.length; i++) {
  13876. var cell = cells[i];
  13877. if (typeof this.fieldIndex[i] !== "undefined") {
  13878. item[this.fieldIndex[i]] = cell.innerHTML;
  13879. }
  13880. }
  13881. //add row data to item
  13882. data.push(item);
  13883. }
  13884. //create new element
  13885. var newElement = document.createElement("div");
  13886. //transfer attributes to new element
  13887. var attributes = element.attributes;
  13888. // loop through attributes and apply them on div
  13889. for (var i in attributes) {
  13890. if (_typeof(attributes[i]) == "object") {
  13891. newElement.setAttribute(attributes[i].name, attributes[i].value);
  13892. }
  13893. }
  13894. // replace table with div element
  13895. element.parentNode.replaceChild(newElement, element);
  13896. options.data = data;
  13897. self.table.options.htmlImported.call(this.table);
  13898. // // newElement.tabulator(options);
  13899. this.table.element = newElement;
  13900. };
  13901. //extract tabulator attribute options
  13902. HtmlTableImport.prototype._extractOptions = function (element, options, defaultOptions) {
  13903. var attributes = element.attributes;
  13904. var optionsArr = defaultOptions ? Object.assign([], defaultOptions) : Object.keys(options);
  13905. var optionsList = {};
  13906. optionsArr.forEach(function (item) {
  13907. optionsList[item.toLowerCase()] = item;
  13908. });
  13909. for (var index in attributes) {
  13910. var attrib = attributes[index];
  13911. var name;
  13912. if (attrib && (typeof attrib === 'undefined' ? 'undefined' : _typeof(attrib)) == "object" && attrib.name && attrib.name.indexOf("tabulator-") === 0) {
  13913. name = attrib.name.replace("tabulator-", "");
  13914. if (typeof optionsList[name] !== "undefined") {
  13915. options[optionsList[name]] = this._attribValue(attrib.value);
  13916. }
  13917. }
  13918. }
  13919. };
  13920. //get value of attribute
  13921. HtmlTableImport.prototype._attribValue = function (value) {
  13922. if (value === "true") {
  13923. return true;
  13924. }
  13925. if (value === "false") {
  13926. return false;
  13927. }
  13928. return value;
  13929. };
  13930. //find column if it has already been defined
  13931. HtmlTableImport.prototype._findCol = function (title) {
  13932. var match = this.table.options.columns.find(function (column) {
  13933. return column.title === title;
  13934. });
  13935. return match || false;
  13936. };
  13937. //extract column from headers
  13938. HtmlTableImport.prototype._extractHeaders = function (headers, rows) {
  13939. for (var index = 0; index < headers.length; index++) {
  13940. var header = headers[index],
  13941. exists = false,
  13942. col = this._findCol(header.textContent),
  13943. width,
  13944. attributes;
  13945. if (col) {
  13946. exists = true;
  13947. } else {
  13948. col = { title: header.textContent.trim() };
  13949. }
  13950. if (!col.field) {
  13951. col.field = header.textContent.trim().toLowerCase().replace(" ", "_");
  13952. }
  13953. width = header.getAttribute("width");
  13954. if (width && !col.width) {
  13955. col.width = width;
  13956. }
  13957. //check for tablator inline options
  13958. attributes = header.attributes;
  13959. // //check for tablator inline options
  13960. this._extractOptions(header, col, Column.prototype.defaultOptionList);
  13961. this.fieldIndex[index] = col.field;
  13962. if (col.field == this.table.options.index) {
  13963. this.hasIndex = true;
  13964. }
  13965. if (!exists) {
  13966. this.table.options.columns.push(col);
  13967. }
  13968. }
  13969. };
  13970. //generate blank headers
  13971. HtmlTableImport.prototype._generateBlankHeaders = function (headers, rows) {
  13972. for (var index = 0; index < headers.length; index++) {
  13973. var header = headers[index],
  13974. col = { title: "", field: "col" + index };
  13975. this.fieldIndex[index] = col.field;
  13976. var width = header.getAttribute("width");
  13977. if (width) {
  13978. col.width = width;
  13979. }
  13980. this.table.options.columns.push(col);
  13981. }
  13982. };
  13983. Tabulator.prototype.registerModule("htmlTableImport", HtmlTableImport);
  13984. var Keybindings = function Keybindings(table) {
  13985. this.table = table; //hold Tabulator object
  13986. this.watchKeys = null;
  13987. this.pressedKeys = null;
  13988. this.keyupBinding = false;
  13989. this.keydownBinding = false;
  13990. };
  13991. Keybindings.prototype.initialize = function () {
  13992. var bindings = this.table.options.keybindings,
  13993. mergedBindings = {};
  13994. this.watchKeys = {};
  13995. this.pressedKeys = [];
  13996. if (bindings !== false) {
  13997. for (var key in this.bindings) {
  13998. mergedBindings[key] = this.bindings[key];
  13999. }
  14000. if (Object.keys(bindings).length) {
  14001. for (var _key in bindings) {
  14002. mergedBindings[_key] = bindings[_key];
  14003. }
  14004. }
  14005. this.mapBindings(mergedBindings);
  14006. this.bindEvents();
  14007. }
  14008. };
  14009. Keybindings.prototype.mapBindings = function (bindings) {
  14010. var _this70 = this;
  14011. var self = this;
  14012. var _loop2 = function _loop2(key) {
  14013. if (_this70.actions[key]) {
  14014. if (bindings[key]) {
  14015. if (_typeof(bindings[key]) !== "object") {
  14016. bindings[key] = [bindings[key]];
  14017. }
  14018. bindings[key].forEach(function (binding) {
  14019. self.mapBinding(key, binding);
  14020. });
  14021. }
  14022. } else {
  14023. console.warn("Key Binding Error - no such action:", key);
  14024. }
  14025. };
  14026. for (var key in bindings) {
  14027. _loop2(key);
  14028. }
  14029. };
  14030. Keybindings.prototype.mapBinding = function (action, symbolsList) {
  14031. var self = this;
  14032. var binding = {
  14033. action: this.actions[action],
  14034. keys: [],
  14035. ctrl: false,
  14036. shift: false,
  14037. meta: false
  14038. };
  14039. var symbols = symbolsList.toString().toLowerCase().split(" ").join("").split("+");
  14040. symbols.forEach(function (symbol) {
  14041. switch (symbol) {
  14042. case "ctrl":
  14043. binding.ctrl = true;
  14044. break;
  14045. case "shift":
  14046. binding.shift = true;
  14047. break;
  14048. case "meta":
  14049. binding.meta = true;
  14050. break;
  14051. default:
  14052. symbol = parseInt(symbol);
  14053. binding.keys.push(symbol);
  14054. if (!self.watchKeys[symbol]) {
  14055. self.watchKeys[symbol] = [];
  14056. }
  14057. self.watchKeys[symbol].push(binding);
  14058. }
  14059. });
  14060. };
  14061. Keybindings.prototype.bindEvents = function () {
  14062. var self = this;
  14063. this.keyupBinding = function (e) {
  14064. var code = e.keyCode;
  14065. var bindings = self.watchKeys[code];
  14066. if (bindings) {
  14067. self.pressedKeys.push(code);
  14068. bindings.forEach(function (binding) {
  14069. self.checkBinding(e, binding);
  14070. });
  14071. }
  14072. };
  14073. this.keydownBinding = function (e) {
  14074. var code = e.keyCode;
  14075. var bindings = self.watchKeys[code];
  14076. if (bindings) {
  14077. var index = self.pressedKeys.indexOf(code);
  14078. if (index > -1) {
  14079. self.pressedKeys.splice(index, 1);
  14080. }
  14081. }
  14082. };
  14083. this.table.element.addEventListener("keydown", this.keyupBinding);
  14084. this.table.element.addEventListener("keyup", this.keydownBinding);
  14085. };
  14086. Keybindings.prototype.clearBindings = function () {
  14087. if (this.keyupBinding) {
  14088. this.table.element.removeEventListener("keydown", this.keyupBinding);
  14089. }
  14090. if (this.keydownBinding) {
  14091. this.table.element.removeEventListener("keyup", this.keydownBinding);
  14092. }
  14093. };
  14094. Keybindings.prototype.checkBinding = function (e, binding) {
  14095. var self = this,
  14096. match = true;
  14097. if (e.ctrlKey == binding.ctrl && e.shiftKey == binding.shift && e.metaKey == binding.meta) {
  14098. binding.keys.forEach(function (key) {
  14099. var index = self.pressedKeys.indexOf(key);
  14100. if (index == -1) {
  14101. match = false;
  14102. }
  14103. });
  14104. if (match) {
  14105. binding.action.call(self, e);
  14106. }
  14107. return true;
  14108. }
  14109. return false;
  14110. };
  14111. //default bindings
  14112. Keybindings.prototype.bindings = {
  14113. navPrev: "shift + 9",
  14114. navNext: 9,
  14115. navUp: 38,
  14116. navDown: 40,
  14117. scrollPageUp: 33,
  14118. scrollPageDown: 34,
  14119. scrollToStart: 36,
  14120. scrollToEnd: 35,
  14121. undo: "ctrl + 90",
  14122. redo: "ctrl + 89",
  14123. copyToClipboard: "ctrl + 67"
  14124. };
  14125. //default actions
  14126. Keybindings.prototype.actions = {
  14127. keyBlock: function keyBlock(e) {
  14128. e.stopPropagation();
  14129. e.preventDefault();
  14130. },
  14131. scrollPageUp: function scrollPageUp(e) {
  14132. var rowManager = this.table.rowManager,
  14133. newPos = rowManager.scrollTop - rowManager.height,
  14134. scrollMax = rowManager.element.scrollHeight;
  14135. e.preventDefault();
  14136. if (rowManager.displayRowsCount) {
  14137. if (newPos >= 0) {
  14138. rowManager.element.scrollTop = newPos;
  14139. } else {
  14140. rowManager.scrollToRow(rowManager.getDisplayRows()[0]);
  14141. }
  14142. }
  14143. this.table.element.focus();
  14144. },
  14145. scrollPageDown: function scrollPageDown(e) {
  14146. var rowManager = this.table.rowManager,
  14147. newPos = rowManager.scrollTop + rowManager.height,
  14148. scrollMax = rowManager.element.scrollHeight;
  14149. e.preventDefault();
  14150. if (rowManager.displayRowsCount) {
  14151. if (newPos <= scrollMax) {
  14152. rowManager.element.scrollTop = newPos;
  14153. } else {
  14154. rowManager.scrollToRow(rowManager.getDisplayRows()[rowManager.displayRowsCount - 1]);
  14155. }
  14156. }
  14157. this.table.element.focus();
  14158. },
  14159. scrollToStart: function scrollToStart(e) {
  14160. var rowManager = this.table.rowManager;
  14161. e.preventDefault();
  14162. if (rowManager.displayRowsCount) {
  14163. rowManager.scrollToRow(rowManager.getDisplayRows()[0]);
  14164. }
  14165. this.table.element.focus();
  14166. },
  14167. scrollToEnd: function scrollToEnd(e) {
  14168. var rowManager = this.table.rowManager;
  14169. e.preventDefault();
  14170. if (rowManager.displayRowsCount) {
  14171. rowManager.scrollToRow(rowManager.getDisplayRows()[rowManager.displayRowsCount - 1]);
  14172. }
  14173. this.table.element.focus();
  14174. },
  14175. navPrev: function navPrev(e) {
  14176. var cell = false;
  14177. if (this.table.modExists("edit")) {
  14178. cell = this.table.modules.edit.currentCell;
  14179. if (cell) {
  14180. e.preventDefault();
  14181. cell.nav().prev();
  14182. }
  14183. }
  14184. },
  14185. navNext: function navNext(e) {
  14186. var cell = false;
  14187. var newRow = this.table.options.tabEndNewRow;
  14188. var nav;
  14189. if (this.table.modExists("edit")) {
  14190. cell = this.table.modules.edit.currentCell;
  14191. if (cell) {
  14192. e.preventDefault();
  14193. nav = cell.nav();
  14194. if (!nav.next()) {
  14195. if (newRow) {
  14196. cell.getElement().firstChild.blur();
  14197. if (newRow === true) {
  14198. newRow = this.table.addRow({});
  14199. } else {
  14200. if (typeof newRow == "function") {
  14201. newRow = this.table.addRow(newRow(cell.row.getComponent()));
  14202. } else {
  14203. newRow = this.table.addRow(Object.assign({}, newRow));
  14204. }
  14205. }
  14206. newRow.then(function () {
  14207. setTimeout(function () {
  14208. nav.next();
  14209. });
  14210. });
  14211. }
  14212. }
  14213. }
  14214. }
  14215. },
  14216. navLeft: function navLeft(e) {
  14217. var cell = false;
  14218. if (this.table.modExists("edit")) {
  14219. cell = this.table.modules.edit.currentCell;
  14220. if (cell) {
  14221. e.preventDefault();
  14222. cell.nav().left();
  14223. }
  14224. }
  14225. },
  14226. navRight: function navRight(e) {
  14227. var cell = false;
  14228. if (this.table.modExists("edit")) {
  14229. cell = this.table.modules.edit.currentCell;
  14230. if (cell) {
  14231. e.preventDefault();
  14232. cell.nav().right();
  14233. }
  14234. }
  14235. },
  14236. navUp: function navUp(e) {
  14237. var cell = false;
  14238. if (this.table.modExists("edit")) {
  14239. cell = this.table.modules.edit.currentCell;
  14240. if (cell) {
  14241. e.preventDefault();
  14242. cell.nav().up();
  14243. }
  14244. }
  14245. },
  14246. navDown: function navDown(e) {
  14247. var cell = false;
  14248. if (this.table.modExists("edit")) {
  14249. cell = this.table.modules.edit.currentCell;
  14250. if (cell) {
  14251. e.preventDefault();
  14252. cell.nav().down();
  14253. }
  14254. }
  14255. },
  14256. undo: function undo(e) {
  14257. var cell = false;
  14258. if (this.table.options.history && this.table.modExists("history") && this.table.modExists("edit")) {
  14259. cell = this.table.modules.edit.currentCell;
  14260. if (!cell) {
  14261. e.preventDefault();
  14262. this.table.modules.history.undo();
  14263. }
  14264. }
  14265. },
  14266. redo: function redo(e) {
  14267. var cell = false;
  14268. if (this.table.options.history && this.table.modExists("history") && this.table.modExists("edit")) {
  14269. cell = this.table.modules.edit.currentCell;
  14270. if (!cell) {
  14271. e.preventDefault();
  14272. this.table.modules.history.redo();
  14273. }
  14274. }
  14275. },
  14276. copyToClipboard: function copyToClipboard(e) {
  14277. if (!this.table.modules.edit.currentCell) {
  14278. if (this.table.modExists("clipboard", true)) {
  14279. this.table.modules.clipboard.copy(false, true);
  14280. }
  14281. }
  14282. }
  14283. };
  14284. Tabulator.prototype.registerModule("keybindings", Keybindings);
  14285. var Menu = function Menu(table) {
  14286. this.table = table; //hold Tabulator object
  14287. this.menuEl = false;
  14288. this.blurEvent = this.hideMenu.bind(this);
  14289. this.escEvent = this.escMenu.bind(this);
  14290. this.nestedMenuBlock = false;
  14291. };
  14292. Menu.prototype.initializeColumnHeader = function (column) {
  14293. var _this71 = this;
  14294. var headerMenuEl;
  14295. if (column.definition.headerContextMenu) {
  14296. column.getElement().addEventListener("contextmenu", this.LoadMenuEvent.bind(this, column, column.definition.headerContextMenu));
  14297. this.tapHold(column, column.definition.headerContextMenu);
  14298. }
  14299. // if(column.definition.headerClickMenu){
  14300. // column.getElement().addEventListener("click", this.LoadMenuEvent.bind(this, column, column.definition.headerClickMenu));
  14301. // }
  14302. if (column.definition.headerMenu) {
  14303. headerMenuEl = document.createElement("span");
  14304. headerMenuEl.classList.add("tabulator-header-menu-button");
  14305. headerMenuEl.innerHTML = "&vellip;";
  14306. headerMenuEl.addEventListener("click", function (e) {
  14307. var menu = typeof column.definition.headerMenu == "function" ? column.definition.headerMenu(column.getComponent(), e) : column.definition.headerMenu;
  14308. e.stopPropagation();
  14309. e.preventDefault();
  14310. _this71.loadMenu(e, column, menu);
  14311. });
  14312. column.titleElement.insertBefore(headerMenuEl, column.titleElement.firstChild);
  14313. }
  14314. };
  14315. Menu.prototype.LoadMenuEvent = function (component, menu, e) {
  14316. menu = typeof menu == "function" ? menu(component.getComponent(), e) : menu;
  14317. // if(component instanceof Cell){
  14318. // e.stopImmediatePropagation();
  14319. // }
  14320. this.loadMenu(e, component, menu);
  14321. };
  14322. Menu.prototype.tapHold = function (component, menu) {
  14323. var _this72 = this;
  14324. var element = component.getElement(),
  14325. tapHold = null,
  14326. loaded = false;
  14327. element.addEventListener("touchstart", function (e) {
  14328. clearTimeout(tapHold);
  14329. loaded = false;
  14330. tapHold = setTimeout(function () {
  14331. clearTimeout(tapHold);
  14332. tapHold = null;
  14333. loaded = true;
  14334. _this72.LoadMenuEvent(component, menu, e);
  14335. }, 1000);
  14336. }, { passive: true });
  14337. element.addEventListener("touchend", function (e) {
  14338. clearTimeout(tapHold);
  14339. tapHold = null;
  14340. if (loaded) {
  14341. e.preventDefault();
  14342. }
  14343. });
  14344. };
  14345. Menu.prototype.initializeCell = function (cell) {
  14346. if (cell.column.definition.contextMenu) {
  14347. cell.getElement().addEventListener("contextmenu", this.LoadMenuEvent.bind(this, cell, cell.column.definition.contextMenu));
  14348. this.tapHold(cell, cell.column.definition.contextMenu);
  14349. }
  14350. if (cell.column.definition.clickMenu) {
  14351. cell.getElement().addEventListener("click", this.LoadMenuEvent.bind(this, cell, cell.column.definition.clickMenu));
  14352. }
  14353. };
  14354. Menu.prototype.initializeRow = function (row) {
  14355. if (this.table.options.rowContextMenu) {
  14356. row.getElement().addEventListener("contextmenu", this.LoadMenuEvent.bind(this, row, this.table.options.rowContextMenu));
  14357. this.tapHold(row, this.table.options.rowContextMenu);
  14358. }
  14359. if (this.table.options.rowClickMenu) {
  14360. row.getElement().addEventListener("click", this.LoadMenuEvent.bind(this, row, this.table.options.rowClickMenu));
  14361. }
  14362. };
  14363. Menu.prototype.initializeGroup = function (group) {
  14364. if (this.table.options.groupContextMenu) {
  14365. group.getElement().addEventListener("contextmenu", this.LoadMenuEvent.bind(this, group, this.table.options.groupContextMenu));
  14366. this.tapHold(group, this.table.options.groupContextMenu);
  14367. }
  14368. if (this.table.options.groupClickMenu) {
  14369. group.getElement().addEventListener("click", this.LoadMenuEvent.bind(this, group, this.table.options.groupClickMenu));
  14370. }
  14371. };
  14372. Menu.prototype.loadMenu = function (e, component, menu) {
  14373. var _this73 = this;
  14374. var docHeight = Math.max(document.body.offsetHeight, window.innerHeight),
  14375. touch = !(e instanceof MouseEvent);
  14376. if (!touch) {
  14377. e.preventDefault();
  14378. }
  14379. //abort if no menu set
  14380. if (!menu || !menu.length) {
  14381. return;
  14382. }
  14383. if (this.nestedMenuBlock) {
  14384. //abort if child menu already open
  14385. if (this.isOpen()) {
  14386. return;
  14387. }
  14388. } else {
  14389. this.nestedMenuBlock = setTimeout(function () {
  14390. _this73.nestedMenuBlock = false;
  14391. }, 100);
  14392. }
  14393. this.hideMenu();
  14394. this.menuEl = document.createElement("div");
  14395. this.menuEl.classList.add("tabulator-menu");
  14396. menu.forEach(function (item) {
  14397. var itemEl = document.createElement("div");
  14398. var label = item.label;
  14399. var disabled = item.disabled;
  14400. if (item.separator) {
  14401. itemEl.classList.add("tabulator-menu-separator");
  14402. } else {
  14403. itemEl.classList.add("tabulator-menu-item");
  14404. if (typeof label == "function") {
  14405. label = label(component.getComponent());
  14406. }
  14407. if (label instanceof Node) {
  14408. itemEl.appendChild(label);
  14409. } else {
  14410. itemEl.innerHTML = label;
  14411. }
  14412. if (typeof disabled == "function") {
  14413. disabled = disabled(component.getComponent());
  14414. }
  14415. if (disabled) {
  14416. itemEl.classList.add("tabulator-menu-item-disabled");
  14417. itemEl.addEventListener("click", function (e) {
  14418. e.stopPropagation();
  14419. });
  14420. } else {
  14421. itemEl.addEventListener("click", function (e) {
  14422. _this73.hideMenu();
  14423. item.action(e, component.getComponent());
  14424. });
  14425. }
  14426. }
  14427. _this73.menuEl.appendChild(itemEl);
  14428. });
  14429. this.menuEl.style.top = (touch ? e.touches[0].pageY : e.pageY) + "px";
  14430. this.menuEl.style.left = (touch ? e.touches[0].pageX : e.pageX) + "px";
  14431. setTimeout(function () {
  14432. _this73.table.rowManager.element.addEventListener("scroll", _this73.blurEvent);
  14433. document.body.addEventListener("click", _this73.blurEvent);
  14434. document.body.addEventListener("contextmenu", _this73.blurEvent);
  14435. document.body.addEventListener("keydown", _this73.escEvent);
  14436. }, 100);
  14437. document.body.appendChild(this.menuEl);
  14438. //move menu to start on right edge if it is too close to the edge of the screen
  14439. if (e.pageX + this.menuEl.offsetWidth >= document.body.offsetWidth) {
  14440. this.menuEl.style.left = "";
  14441. this.menuEl.style.right = document.body.offsetWidth - e.pageX + "px";
  14442. }
  14443. //move menu to start on bottom edge if it is too close to the edge of the screen
  14444. if (e.pageY + this.menuEl.offsetHeight >= docHeight) {
  14445. this.menuEl.style.top = "";
  14446. this.menuEl.style.bottom = docHeight - e.pageY + "px";
  14447. }
  14448. };
  14449. Menu.prototype.isOpen = function () {
  14450. return !!this.menuEl.parentNode;
  14451. };
  14452. Menu.prototype.escMenu = function (e) {
  14453. if (e.keyCode == 27) {
  14454. this.hideMenu();
  14455. }
  14456. };
  14457. Menu.prototype.hideMenu = function () {
  14458. if (this.menuEl.parentNode) {
  14459. this.menuEl.parentNode.removeChild(this.menuEl);
  14460. }
  14461. if (this.escEvent) {
  14462. document.body.removeEventListener("keydown", this.escEvent);
  14463. }
  14464. if (this.blurEvent) {
  14465. document.body.removeEventListener("click", this.blurEvent);
  14466. document.body.removeEventListener("contextmenu", this.blurEvent);
  14467. this.table.rowManager.element.removeEventListener("scroll", this.blurEvent);
  14468. }
  14469. };
  14470. //default accessors
  14471. Menu.prototype.menus = {};
  14472. Tabulator.prototype.registerModule("menu", Menu);
  14473. var MoveColumns = function MoveColumns(table) {
  14474. this.table = table; //hold Tabulator object
  14475. this.placeholderElement = this.createPlaceholderElement();
  14476. this.hoverElement = false; //floating column header element
  14477. this.checkTimeout = false; //click check timeout holder
  14478. this.checkPeriod = 250; //period to wait on mousedown to consider this a move and not a click
  14479. this.moving = false; //currently moving column
  14480. this.toCol = false; //destination column
  14481. this.toColAfter = false; //position of moving column relative to the desitnation column
  14482. this.startX = 0; //starting position within header element
  14483. this.autoScrollMargin = 40; //auto scroll on edge when within margin
  14484. this.autoScrollStep = 5; //auto scroll distance in pixels
  14485. this.autoScrollTimeout = false; //auto scroll timeout
  14486. this.touchMove = false;
  14487. this.moveHover = this.moveHover.bind(this);
  14488. this.endMove = this.endMove.bind(this);
  14489. };
  14490. MoveColumns.prototype.createPlaceholderElement = function () {
  14491. var el = document.createElement("div");
  14492. el.classList.add("tabulator-col");
  14493. el.classList.add("tabulator-col-placeholder");
  14494. return el;
  14495. };
  14496. MoveColumns.prototype.initializeColumn = function (column) {
  14497. var self = this,
  14498. config = {},
  14499. colEl;
  14500. if (!column.modules.frozen) {
  14501. colEl = column.getElement();
  14502. config.mousemove = function (e) {
  14503. if (column.parent === self.moving.parent) {
  14504. if ((self.touchMove ? e.touches[0].pageX : e.pageX) - Tabulator.prototype.helpers.elOffset(colEl).left + self.table.columnManager.element.scrollLeft > column.getWidth() / 2) {
  14505. if (self.toCol !== column || !self.toColAfter) {
  14506. colEl.parentNode.insertBefore(self.placeholderElement, colEl.nextSibling);
  14507. self.moveColumn(column, true);
  14508. }
  14509. } else {
  14510. if (self.toCol !== column || self.toColAfter) {
  14511. colEl.parentNode.insertBefore(self.placeholderElement, colEl);
  14512. self.moveColumn(column, false);
  14513. }
  14514. }
  14515. }
  14516. }.bind(self);
  14517. colEl.addEventListener("mousedown", function (e) {
  14518. self.touchMove = false;
  14519. if (e.which === 1) {
  14520. self.checkTimeout = setTimeout(function () {
  14521. self.startMove(e, column);
  14522. }, self.checkPeriod);
  14523. }
  14524. });
  14525. colEl.addEventListener("mouseup", function (e) {
  14526. if (e.which === 1) {
  14527. if (self.checkTimeout) {
  14528. clearTimeout(self.checkTimeout);
  14529. }
  14530. }
  14531. });
  14532. self.bindTouchEvents(column);
  14533. }
  14534. column.modules.moveColumn = config;
  14535. };
  14536. MoveColumns.prototype.bindTouchEvents = function (column) {
  14537. var self = this,
  14538. colEl = column.getElement(),
  14539. startXMove = false,
  14540. //shifting center position of the cell
  14541. dir = false,
  14542. currentCol,
  14543. nextCol,
  14544. prevCol,
  14545. nextColWidth,
  14546. prevColWidth,
  14547. nextColWidthLast,
  14548. prevColWidthLast;
  14549. colEl.addEventListener("touchstart", function (e) {
  14550. self.checkTimeout = setTimeout(function () {
  14551. self.touchMove = true;
  14552. currentCol = column;
  14553. nextCol = column.nextColumn();
  14554. nextColWidth = nextCol ? nextCol.getWidth() / 2 : 0;
  14555. prevCol = column.prevColumn();
  14556. prevColWidth = prevCol ? prevCol.getWidth() / 2 : 0;
  14557. nextColWidthLast = 0;
  14558. prevColWidthLast = 0;
  14559. startXMove = false;
  14560. self.startMove(e, column);
  14561. }, self.checkPeriod);
  14562. }, { passive: true });
  14563. colEl.addEventListener("touchmove", function (e) {
  14564. var halfCol, diff, moveToCol;
  14565. if (self.moving) {
  14566. self.moveHover(e);
  14567. if (!startXMove) {
  14568. startXMove = e.touches[0].pageX;
  14569. }
  14570. diff = e.touches[0].pageX - startXMove;
  14571. if (diff > 0) {
  14572. if (nextCol && diff - nextColWidthLast > nextColWidth) {
  14573. moveToCol = nextCol;
  14574. if (moveToCol !== column) {
  14575. startXMove = e.touches[0].pageX;
  14576. moveToCol.getElement().parentNode.insertBefore(self.placeholderElement, moveToCol.getElement().nextSibling);
  14577. self.moveColumn(moveToCol, true);
  14578. }
  14579. }
  14580. } else {
  14581. if (prevCol && -diff - prevColWidthLast > prevColWidth) {
  14582. moveToCol = prevCol;
  14583. if (moveToCol !== column) {
  14584. startXMove = e.touches[0].pageX;
  14585. moveToCol.getElement().parentNode.insertBefore(self.placeholderElement, moveToCol.getElement());
  14586. self.moveColumn(moveToCol, false);
  14587. }
  14588. }
  14589. }
  14590. if (moveToCol) {
  14591. currentCol = moveToCol;
  14592. nextCol = moveToCol.nextColumn();
  14593. nextColWidthLast = nextColWidth;
  14594. nextColWidth = nextCol ? nextCol.getWidth() / 2 : 0;
  14595. prevCol = moveToCol.prevColumn();
  14596. prevColWidthLast = prevColWidth;
  14597. prevColWidth = prevCol ? prevCol.getWidth() / 2 : 0;
  14598. }
  14599. }
  14600. }, { passive: true });
  14601. colEl.addEventListener("touchend", function (e) {
  14602. if (self.checkTimeout) {
  14603. clearTimeout(self.checkTimeout);
  14604. }
  14605. if (self.moving) {
  14606. self.endMove(e);
  14607. }
  14608. });
  14609. };
  14610. MoveColumns.prototype.startMove = function (e, column) {
  14611. var element = column.getElement();
  14612. this.moving = column;
  14613. this.startX = (this.touchMove ? e.touches[0].pageX : e.pageX) - Tabulator.prototype.helpers.elOffset(element).left;
  14614. this.table.element.classList.add("tabulator-block-select");
  14615. //create placeholder
  14616. this.placeholderElement.style.width = column.getWidth() + "px";
  14617. this.placeholderElement.style.height = column.getHeight() + "px";
  14618. element.parentNode.insertBefore(this.placeholderElement, element);
  14619. element.parentNode.removeChild(element);
  14620. //create hover element
  14621. this.hoverElement = element.cloneNode(true);
  14622. this.hoverElement.classList.add("tabulator-moving");
  14623. this.table.columnManager.getElement().appendChild(this.hoverElement);
  14624. this.hoverElement.style.left = "0";
  14625. this.hoverElement.style.bottom = "0";
  14626. if (!this.touchMove) {
  14627. this._bindMouseMove();
  14628. document.body.addEventListener("mousemove", this.moveHover);
  14629. document.body.addEventListener("mouseup", this.endMove);
  14630. }
  14631. this.moveHover(e);
  14632. };
  14633. MoveColumns.prototype._bindMouseMove = function () {
  14634. this.table.columnManager.columnsByIndex.forEach(function (column) {
  14635. if (column.modules.moveColumn.mousemove) {
  14636. column.getElement().addEventListener("mousemove", column.modules.moveColumn.mousemove);
  14637. }
  14638. });
  14639. };
  14640. MoveColumns.prototype._unbindMouseMove = function () {
  14641. this.table.columnManager.columnsByIndex.forEach(function (column) {
  14642. if (column.modules.moveColumn.mousemove) {
  14643. column.getElement().removeEventListener("mousemove", column.modules.moveColumn.mousemove);
  14644. }
  14645. });
  14646. };
  14647. MoveColumns.prototype.moveColumn = function (column, after) {
  14648. var movingCells = this.moving.getCells();
  14649. this.toCol = column;
  14650. this.toColAfter = after;
  14651. if (after) {
  14652. column.getCells().forEach(function (cell, i) {
  14653. var cellEl = cell.getElement();
  14654. cellEl.parentNode.insertBefore(movingCells[i].getElement(), cellEl.nextSibling);
  14655. });
  14656. } else {
  14657. column.getCells().forEach(function (cell, i) {
  14658. var cellEl = cell.getElement();
  14659. cellEl.parentNode.insertBefore(movingCells[i].getElement(), cellEl);
  14660. });
  14661. }
  14662. };
  14663. MoveColumns.prototype.endMove = function (e) {
  14664. if (e.which === 1 || this.touchMove) {
  14665. this._unbindMouseMove();
  14666. this.placeholderElement.parentNode.insertBefore(this.moving.getElement(), this.placeholderElement.nextSibling);
  14667. this.placeholderElement.parentNode.removeChild(this.placeholderElement);
  14668. this.hoverElement.parentNode.removeChild(this.hoverElement);
  14669. this.table.element.classList.remove("tabulator-block-select");
  14670. if (this.toCol) {
  14671. this.table.columnManager.moveColumnActual(this.moving, this.toCol, this.toColAfter);
  14672. }
  14673. this.moving = false;
  14674. this.toCol = false;
  14675. this.toColAfter = false;
  14676. if (!this.touchMove) {
  14677. document.body.removeEventListener("mousemove", this.moveHover);
  14678. document.body.removeEventListener("mouseup", this.endMove);
  14679. }
  14680. }
  14681. };
  14682. MoveColumns.prototype.moveHover = function (e) {
  14683. var self = this,
  14684. columnHolder = self.table.columnManager.getElement(),
  14685. scrollLeft = columnHolder.scrollLeft,
  14686. xPos = (self.touchMove ? e.touches[0].pageX : e.pageX) - Tabulator.prototype.helpers.elOffset(columnHolder).left + scrollLeft,
  14687. scrollPos;
  14688. self.hoverElement.style.left = xPos - self.startX + "px";
  14689. if (xPos - scrollLeft < self.autoScrollMargin) {
  14690. if (!self.autoScrollTimeout) {
  14691. self.autoScrollTimeout = setTimeout(function () {
  14692. scrollPos = Math.max(0, scrollLeft - 5);
  14693. self.table.rowManager.getElement().scrollLeft = scrollPos;
  14694. self.autoScrollTimeout = false;
  14695. }, 1);
  14696. }
  14697. }
  14698. if (scrollLeft + columnHolder.clientWidth - xPos < self.autoScrollMargin) {
  14699. if (!self.autoScrollTimeout) {
  14700. self.autoScrollTimeout = setTimeout(function () {
  14701. scrollPos = Math.min(columnHolder.clientWidth, scrollLeft + 5);
  14702. self.table.rowManager.getElement().scrollLeft = scrollPos;
  14703. self.autoScrollTimeout = false;
  14704. }, 1);
  14705. }
  14706. }
  14707. };
  14708. Tabulator.prototype.registerModule("moveColumn", MoveColumns);
  14709. var MoveRows = function MoveRows(table) {
  14710. this.table = table; //hold Tabulator object
  14711. this.placeholderElement = this.createPlaceholderElement();
  14712. this.hoverElement = false; //floating row header element
  14713. this.checkTimeout = false; //click check timeout holder
  14714. this.checkPeriod = 150; //period to wait on mousedown to consider this a move and not a click
  14715. this.moving = false; //currently moving row
  14716. this.toRow = false; //destination row
  14717. this.toRowAfter = false; //position of moving row relative to the desitnation row
  14718. this.hasHandle = false; //row has handle instead of fully movable row
  14719. this.startY = 0; //starting Y position within header element
  14720. this.startX = 0; //starting X position within header element
  14721. this.moveHover = this.moveHover.bind(this);
  14722. this.endMove = this.endMove.bind(this);
  14723. this.tableRowDropEvent = false;
  14724. this.touchMove = false;
  14725. this.connection = false;
  14726. this.connectionSelectorsTables = false;
  14727. this.connectionSelectorsElements = false;
  14728. this.connectionElements = [];
  14729. this.connections = [];
  14730. this.connectedTable = false;
  14731. this.connectedRow = false;
  14732. };
  14733. MoveRows.prototype.createPlaceholderElement = function () {
  14734. var el = document.createElement("div");
  14735. el.classList.add("tabulator-row");
  14736. el.classList.add("tabulator-row-placeholder");
  14737. return el;
  14738. };
  14739. MoveRows.prototype.initialize = function (handle) {
  14740. this.connectionSelectorsTables = this.table.options.movableRowsConnectedTables;
  14741. this.connectionSelectorsElements = this.table.options.movableRowsConnectedElements;
  14742. this.connection = this.connectionSelectorsTables || this.connectionSelectorsElements;
  14743. };
  14744. MoveRows.prototype.setHandle = function (handle) {
  14745. this.hasHandle = handle;
  14746. };
  14747. MoveRows.prototype.initializeGroupHeader = function (group) {
  14748. var self = this,
  14749. config = {},
  14750. rowEl;
  14751. //inter table drag drop
  14752. config.mouseup = function (e) {
  14753. self.tableRowDrop(e, row);
  14754. }.bind(self);
  14755. //same table drag drop
  14756. config.mousemove = function (e) {
  14757. if (e.pageY - Tabulator.prototype.helpers.elOffset(group.element).top + self.table.rowManager.element.scrollTop > group.getHeight() / 2) {
  14758. if (self.toRow !== group || !self.toRowAfter) {
  14759. var rowEl = group.getElement();
  14760. rowEl.parentNode.insertBefore(self.placeholderElement, rowEl.nextSibling);
  14761. self.moveRow(group, true);
  14762. }
  14763. } else {
  14764. if (self.toRow !== group || self.toRowAfter) {
  14765. var rowEl = group.getElement();
  14766. if (rowEl.previousSibling) {
  14767. rowEl.parentNode.insertBefore(self.placeholderElement, rowEl);
  14768. self.moveRow(group, false);
  14769. }
  14770. }
  14771. }
  14772. }.bind(self);
  14773. group.modules.moveRow = config;
  14774. };
  14775. MoveRows.prototype.initializeRow = function (row) {
  14776. var self = this,
  14777. config = {},
  14778. rowEl;
  14779. //inter table drag drop
  14780. config.mouseup = function (e) {
  14781. self.tableRowDrop(e, row);
  14782. }.bind(self);
  14783. //same table drag drop
  14784. config.mousemove = function (e) {
  14785. if (e.pageY - Tabulator.prototype.helpers.elOffset(row.element).top + self.table.rowManager.element.scrollTop > row.getHeight() / 2) {
  14786. if (self.toRow !== row || !self.toRowAfter) {
  14787. var rowEl = row.getElement();
  14788. rowEl.parentNode.insertBefore(self.placeholderElement, rowEl.nextSibling);
  14789. self.moveRow(row, true);
  14790. }
  14791. } else {
  14792. if (self.toRow !== row || self.toRowAfter) {
  14793. var rowEl = row.getElement();
  14794. rowEl.parentNode.insertBefore(self.placeholderElement, rowEl);
  14795. self.moveRow(row, false);
  14796. }
  14797. }
  14798. }.bind(self);
  14799. if (!this.hasHandle) {
  14800. rowEl = row.getElement();
  14801. rowEl.addEventListener("mousedown", function (e) {
  14802. if (e.which === 1) {
  14803. self.checkTimeout = setTimeout(function () {
  14804. self.startMove(e, row);
  14805. }, self.checkPeriod);
  14806. }
  14807. });
  14808. rowEl.addEventListener("mouseup", function (e) {
  14809. if (e.which === 1) {
  14810. if (self.checkTimeout) {
  14811. clearTimeout(self.checkTimeout);
  14812. }
  14813. }
  14814. });
  14815. this.bindTouchEvents(row, row.getElement());
  14816. }
  14817. row.modules.moveRow = config;
  14818. };
  14819. MoveRows.prototype.initializeCell = function (cell) {
  14820. var self = this,
  14821. cellEl = cell.getElement();
  14822. cellEl.addEventListener("mousedown", function (e) {
  14823. if (e.which === 1) {
  14824. self.checkTimeout = setTimeout(function () {
  14825. self.startMove(e, cell.row);
  14826. }, self.checkPeriod);
  14827. }
  14828. });
  14829. cellEl.addEventListener("mouseup", function (e) {
  14830. if (e.which === 1) {
  14831. if (self.checkTimeout) {
  14832. clearTimeout(self.checkTimeout);
  14833. }
  14834. }
  14835. });
  14836. this.bindTouchEvents(cell.row, cell.getElement());
  14837. };
  14838. MoveRows.prototype.bindTouchEvents = function (row, element) {
  14839. var self = this,
  14840. startYMove = false,
  14841. //shifting center position of the cell
  14842. dir = false,
  14843. currentRow,
  14844. nextRow,
  14845. prevRow,
  14846. nextRowHeight,
  14847. prevRowHeight,
  14848. nextRowHeightLast,
  14849. prevRowHeightLast;
  14850. element.addEventListener("touchstart", function (e) {
  14851. self.checkTimeout = setTimeout(function () {
  14852. self.touchMove = true;
  14853. currentRow = row;
  14854. nextRow = row.nextRow();
  14855. nextRowHeight = nextRow ? nextRow.getHeight() / 2 : 0;
  14856. prevRow = row.prevRow();
  14857. prevRowHeight = prevRow ? prevRow.getHeight() / 2 : 0;
  14858. nextRowHeightLast = 0;
  14859. prevRowHeightLast = 0;
  14860. startYMove = false;
  14861. self.startMove(e, row);
  14862. }, self.checkPeriod);
  14863. }, { passive: true });
  14864. this.moving, this.toRow, this.toRowAfter;
  14865. element.addEventListener("touchmove", function (e) {
  14866. var halfCol, diff, moveToRow;
  14867. if (self.moving) {
  14868. e.preventDefault();
  14869. self.moveHover(e);
  14870. if (!startYMove) {
  14871. startYMove = e.touches[0].pageY;
  14872. }
  14873. diff = e.touches[0].pageY - startYMove;
  14874. if (diff > 0) {
  14875. if (nextRow && diff - nextRowHeightLast > nextRowHeight) {
  14876. moveToRow = nextRow;
  14877. if (moveToRow !== row) {
  14878. startYMove = e.touches[0].pageY;
  14879. moveToRow.getElement().parentNode.insertBefore(self.placeholderElement, moveToRow.getElement().nextSibling);
  14880. self.moveRow(moveToRow, true);
  14881. }
  14882. }
  14883. } else {
  14884. if (prevRow && -diff - prevRowHeightLast > prevRowHeight) {
  14885. moveToRow = prevRow;
  14886. if (moveToRow !== row) {
  14887. startYMove = e.touches[0].pageY;
  14888. moveToRow.getElement().parentNode.insertBefore(self.placeholderElement, moveToRow.getElement());
  14889. self.moveRow(moveToRow, false);
  14890. }
  14891. }
  14892. }
  14893. if (moveToRow) {
  14894. currentRow = moveToRow;
  14895. nextRow = moveToRow.nextRow();
  14896. nextRowHeightLast = nextRowHeight;
  14897. nextRowHeight = nextRow ? nextRow.getHeight() / 2 : 0;
  14898. prevRow = moveToRow.prevRow();
  14899. prevRowHeightLast = prevRowHeight;
  14900. prevRowHeight = prevRow ? prevRow.getHeight() / 2 : 0;
  14901. }
  14902. }
  14903. });
  14904. element.addEventListener("touchend", function (e) {
  14905. if (self.checkTimeout) {
  14906. clearTimeout(self.checkTimeout);
  14907. }
  14908. if (self.moving) {
  14909. self.endMove(e);
  14910. self.touchMove = false;
  14911. }
  14912. });
  14913. };
  14914. MoveRows.prototype._bindMouseMove = function () {
  14915. var self = this;
  14916. self.table.rowManager.getDisplayRows().forEach(function (row) {
  14917. if ((row.type === "row" || row.type === "group") && row.modules.moveRow.mousemove) {
  14918. row.getElement().addEventListener("mousemove", row.modules.moveRow.mousemove);
  14919. }
  14920. });
  14921. };
  14922. MoveRows.prototype._unbindMouseMove = function () {
  14923. var self = this;
  14924. self.table.rowManager.getDisplayRows().forEach(function (row) {
  14925. if ((row.type === "row" || row.type === "group") && row.modules.moveRow.mousemove) {
  14926. row.getElement().removeEventListener("mousemove", row.modules.moveRow.mousemove);
  14927. }
  14928. });
  14929. };
  14930. MoveRows.prototype.startMove = function (e, row) {
  14931. var element = row.getElement();
  14932. this.setStartPosition(e, row);
  14933. this.moving = row;
  14934. this.table.element.classList.add("tabulator-block-select");
  14935. //create placeholder
  14936. this.placeholderElement.style.width = row.getWidth() + "px";
  14937. this.placeholderElement.style.height = row.getHeight() + "px";
  14938. if (!this.connection) {
  14939. element.parentNode.insertBefore(this.placeholderElement, element);
  14940. element.parentNode.removeChild(element);
  14941. } else {
  14942. this.table.element.classList.add("tabulator-movingrow-sending");
  14943. this.connectToTables(row);
  14944. }
  14945. //create hover element
  14946. this.hoverElement = element.cloneNode(true);
  14947. this.hoverElement.classList.add("tabulator-moving");
  14948. if (this.connection) {
  14949. document.body.appendChild(this.hoverElement);
  14950. this.hoverElement.style.left = "0";
  14951. this.hoverElement.style.top = "0";
  14952. this.hoverElement.style.width = this.table.element.clientWidth + "px";
  14953. this.hoverElement.style.whiteSpace = "nowrap";
  14954. this.hoverElement.style.overflow = "hidden";
  14955. this.hoverElement.style.pointerEvents = "none";
  14956. } else {
  14957. this.table.rowManager.getTableElement().appendChild(this.hoverElement);
  14958. this.hoverElement.style.left = "0";
  14959. this.hoverElement.style.top = "0";
  14960. this._bindMouseMove();
  14961. }
  14962. document.body.addEventListener("mousemove", this.moveHover);
  14963. document.body.addEventListener("mouseup", this.endMove);
  14964. this.moveHover(e);
  14965. };
  14966. MoveRows.prototype.setStartPosition = function (e, row) {
  14967. var pageX = this.touchMove ? e.touches[0].pageX : e.pageX,
  14968. pageY = this.touchMove ? e.touches[0].pageY : e.pageY,
  14969. element,
  14970. position;
  14971. element = row.getElement();
  14972. if (this.connection) {
  14973. position = element.getBoundingClientRect();
  14974. this.startX = position.left - pageX + window.pageXOffset;
  14975. this.startY = position.top - pageY + window.pageYOffset;
  14976. } else {
  14977. this.startY = pageY - element.getBoundingClientRect().top;
  14978. }
  14979. };
  14980. MoveRows.prototype.endMove = function (e) {
  14981. if (!e || e.which === 1 || this.touchMove) {
  14982. this._unbindMouseMove();
  14983. if (!this.connection) {
  14984. this.placeholderElement.parentNode.insertBefore(this.moving.getElement(), this.placeholderElement.nextSibling);
  14985. this.placeholderElement.parentNode.removeChild(this.placeholderElement);
  14986. }
  14987. this.hoverElement.parentNode.removeChild(this.hoverElement);
  14988. this.table.element.classList.remove("tabulator-block-select");
  14989. if (this.toRow) {
  14990. this.table.rowManager.moveRow(this.moving, this.toRow, this.toRowAfter);
  14991. }
  14992. this.moving = false;
  14993. this.toRow = false;
  14994. this.toRowAfter = false;
  14995. document.body.removeEventListener("mousemove", this.moveHover);
  14996. document.body.removeEventListener("mouseup", this.endMove);
  14997. if (this.connection) {
  14998. this.table.element.classList.remove("tabulator-movingrow-sending");
  14999. this.disconnectFromTables();
  15000. }
  15001. }
  15002. };
  15003. MoveRows.prototype.moveRow = function (row, after) {
  15004. this.toRow = row;
  15005. this.toRowAfter = after;
  15006. };
  15007. MoveRows.prototype.moveHover = function (e) {
  15008. if (this.connection) {
  15009. this.moveHoverConnections.call(this, e);
  15010. } else {
  15011. this.moveHoverTable.call(this, e);
  15012. }
  15013. };
  15014. MoveRows.prototype.moveHoverTable = function (e) {
  15015. var rowHolder = this.table.rowManager.getElement(),
  15016. scrollTop = rowHolder.scrollTop,
  15017. yPos = (this.touchMove ? e.touches[0].pageY : e.pageY) - rowHolder.getBoundingClientRect().top + scrollTop,
  15018. scrollPos;
  15019. this.hoverElement.style.top = yPos - this.startY + "px";
  15020. };
  15021. MoveRows.prototype.moveHoverConnections = function (e) {
  15022. this.hoverElement.style.left = this.startX + (this.touchMove ? e.touches[0].pageX : e.pageX) + "px";
  15023. this.hoverElement.style.top = this.startY + (this.touchMove ? e.touches[0].pageY : e.pageY) + "px";
  15024. };
  15025. MoveRows.prototype.elementRowDrop = function (e, element, row) {
  15026. if (this.table.options.movableRowsElementDrop) {
  15027. this.table.options.movableRowsElementDrop(e, element, row ? row.getComponent() : false);
  15028. }
  15029. };
  15030. //establish connection with other tables
  15031. MoveRows.prototype.connectToTables = function (row) {
  15032. var _this74 = this;
  15033. var connectionTables;
  15034. if (this.connectionSelectorsTables) {
  15035. connectionTables = this.table.modules.comms.getConnections(this.connectionSelectorsTables);
  15036. this.table.options.movableRowsSendingStart.call(this.table, connectionTables);
  15037. this.table.modules.comms.send(this.connectionSelectorsTables, "moveRow", "connect", {
  15038. row: row
  15039. });
  15040. }
  15041. if (this.connectionSelectorsElements) {
  15042. this.connectionElements = [];
  15043. if (!Array.isArray(this.connectionSelectorsElements)) {
  15044. this.connectionSelectorsElements = [this.connectionSelectorsElements];
  15045. }
  15046. this.connectionSelectorsElements.forEach(function (query) {
  15047. if (typeof query === "string") {
  15048. _this74.connectionElements = _this74.connectionElements.concat(Array.prototype.slice.call(document.querySelectorAll(query)));
  15049. } else {
  15050. _this74.connectionElements.push(query);
  15051. }
  15052. });
  15053. this.connectionElements.forEach(function (element) {
  15054. var dropEvent = function dropEvent(e) {
  15055. _this74.elementRowDrop(e, element, _this74.moving);
  15056. };
  15057. element.addEventListener("mouseup", dropEvent);
  15058. element.tabulatorElementDropEvent = dropEvent;
  15059. element.classList.add("tabulator-movingrow-receiving");
  15060. });
  15061. }
  15062. };
  15063. //disconnect from other tables
  15064. MoveRows.prototype.disconnectFromTables = function () {
  15065. var connectionTables;
  15066. if (this.connectionSelectorsTables) {
  15067. connectionTables = this.table.modules.comms.getConnections(this.connectionSelectorsTables);
  15068. this.table.options.movableRowsSendingStop.call(this.table, connectionTables);
  15069. this.table.modules.comms.send(this.connectionSelectorsTables, "moveRow", "disconnect");
  15070. }
  15071. this.connectionElements.forEach(function (element) {
  15072. element.classList.remove("tabulator-movingrow-receiving");
  15073. element.removeEventListener("mouseup", element.tabulatorElementDropEvent);
  15074. delete element.tabulatorElementDropEvent;
  15075. });
  15076. };
  15077. //accept incomming connection
  15078. MoveRows.prototype.connect = function (table, row) {
  15079. var self = this;
  15080. if (!this.connectedTable) {
  15081. this.connectedTable = table;
  15082. this.connectedRow = row;
  15083. this.table.element.classList.add("tabulator-movingrow-receiving");
  15084. self.table.rowManager.getDisplayRows().forEach(function (row) {
  15085. if (row.type === "row" && row.modules.moveRow && row.modules.moveRow.mouseup) {
  15086. row.getElement().addEventListener("mouseup", row.modules.moveRow.mouseup);
  15087. }
  15088. });
  15089. self.tableRowDropEvent = self.tableRowDrop.bind(self);
  15090. self.table.element.addEventListener("mouseup", self.tableRowDropEvent);
  15091. this.table.options.movableRowsReceivingStart.call(this.table, row, table);
  15092. return true;
  15093. } else {
  15094. console.warn("Move Row Error - Table cannot accept connection, already connected to table:", this.connectedTable);
  15095. return false;
  15096. }
  15097. };
  15098. //close incomming connection
  15099. MoveRows.prototype.disconnect = function (table) {
  15100. var self = this;
  15101. if (table === this.connectedTable) {
  15102. this.connectedTable = false;
  15103. this.connectedRow = false;
  15104. this.table.element.classList.remove("tabulator-movingrow-receiving");
  15105. self.table.rowManager.getDisplayRows().forEach(function (row) {
  15106. if (row.type === "row" && row.modules.moveRow && row.modules.moveRow.mouseup) {
  15107. row.getElement().removeEventListener("mouseup", row.modules.moveRow.mouseup);
  15108. }
  15109. });
  15110. self.table.element.removeEventListener("mouseup", self.tableRowDropEvent);
  15111. this.table.options.movableRowsReceivingStop.call(this.table, table);
  15112. } else {
  15113. console.warn("Move Row Error - trying to disconnect from non connected table");
  15114. }
  15115. };
  15116. MoveRows.prototype.dropComplete = function (table, row, success) {
  15117. var sender = false;
  15118. if (success) {
  15119. switch (_typeof(this.table.options.movableRowsSender)) {
  15120. case "string":
  15121. sender = this.senders[this.table.options.movableRowsSender];
  15122. break;
  15123. case "function":
  15124. sender = this.table.options.movableRowsSender;
  15125. break;
  15126. }
  15127. if (sender) {
  15128. sender.call(this, this.moving.getComponent(), row ? row.getComponent() : undefined, table);
  15129. } else {
  15130. if (this.table.options.movableRowsSender) {
  15131. console.warn("Mover Row Error - no matching sender found:", this.table.options.movableRowsSender);
  15132. }
  15133. }
  15134. this.table.options.movableRowsSent.call(this.table, this.moving.getComponent(), row ? row.getComponent() : undefined, table);
  15135. } else {
  15136. this.table.options.movableRowsSentFailed.call(this.table, this.moving.getComponent(), row ? row.getComponent() : undefined, table);
  15137. }
  15138. this.endMove();
  15139. };
  15140. MoveRows.prototype.tableRowDrop = function (e, row) {
  15141. var receiver = false,
  15142. success = false;
  15143. console.trace("drop");
  15144. e.stopImmediatePropagation();
  15145. switch (_typeof(this.table.options.movableRowsReceiver)) {
  15146. case "string":
  15147. receiver = this.receivers[this.table.options.movableRowsReceiver];
  15148. break;
  15149. case "function":
  15150. receiver = this.table.options.movableRowsReceiver;
  15151. break;
  15152. }
  15153. if (receiver) {
  15154. success = receiver.call(this, this.connectedRow.getComponent(), row ? row.getComponent() : undefined, this.connectedTable);
  15155. } else {
  15156. console.warn("Mover Row Error - no matching receiver found:", this.table.options.movableRowsReceiver);
  15157. }
  15158. if (success) {
  15159. this.table.options.movableRowsReceived.call(this.table, this.connectedRow.getComponent(), row ? row.getComponent() : undefined, this.connectedTable);
  15160. } else {
  15161. this.table.options.movableRowsReceivedFailed.call(this.table, this.connectedRow.getComponent(), row ? row.getComponent() : undefined, this.connectedTable);
  15162. }
  15163. this.table.modules.comms.send(this.connectedTable, "moveRow", "dropcomplete", {
  15164. row: row,
  15165. success: success
  15166. });
  15167. };
  15168. MoveRows.prototype.receivers = {
  15169. insert: function insert(fromRow, toRow, fromTable) {
  15170. this.table.addRow(fromRow.getData(), undefined, toRow);
  15171. return true;
  15172. },
  15173. add: function add(fromRow, toRow, fromTable) {
  15174. this.table.addRow(fromRow.getData());
  15175. return true;
  15176. },
  15177. update: function update(fromRow, toRow, fromTable) {
  15178. if (toRow) {
  15179. toRow.update(fromRow.getData());
  15180. return true;
  15181. }
  15182. return false;
  15183. },
  15184. replace: function replace(fromRow, toRow, fromTable) {
  15185. if (toRow) {
  15186. this.table.addRow(fromRow.getData(), undefined, toRow);
  15187. toRow.delete();
  15188. return true;
  15189. }
  15190. return false;
  15191. }
  15192. };
  15193. MoveRows.prototype.senders = {
  15194. delete: function _delete(fromRow, toRow, toTable) {
  15195. fromRow.delete();
  15196. }
  15197. };
  15198. MoveRows.prototype.commsReceived = function (table, action, data) {
  15199. switch (action) {
  15200. case "connect":
  15201. return this.connect(table, data.row);
  15202. break;
  15203. case "disconnect":
  15204. return this.disconnect(table);
  15205. break;
  15206. case "dropcomplete":
  15207. return this.dropComplete(table, data.row, data.success);
  15208. break;
  15209. }
  15210. };
  15211. Tabulator.prototype.registerModule("moveRow", MoveRows);
  15212. var Mutator = function Mutator(table) {
  15213. this.table = table; //hold Tabulator object
  15214. this.allowedTypes = ["", "data", "edit", "clipboard"]; //list of muatation types
  15215. this.enabled = true;
  15216. };
  15217. //initialize column mutator
  15218. Mutator.prototype.initializeColumn = function (column) {
  15219. var self = this,
  15220. match = false,
  15221. config = {};
  15222. this.allowedTypes.forEach(function (type) {
  15223. var key = "mutator" + (type.charAt(0).toUpperCase() + type.slice(1)),
  15224. mutator;
  15225. if (column.definition[key]) {
  15226. mutator = self.lookupMutator(column.definition[key]);
  15227. if (mutator) {
  15228. match = true;
  15229. config[key] = {
  15230. mutator: mutator,
  15231. params: column.definition[key + "Params"] || {}
  15232. };
  15233. }
  15234. }
  15235. });
  15236. if (match) {
  15237. column.modules.mutate = config;
  15238. }
  15239. };
  15240. Mutator.prototype.lookupMutator = function (value) {
  15241. var mutator = false;
  15242. //set column mutator
  15243. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  15244. case "string":
  15245. if (this.mutators[value]) {
  15246. mutator = this.mutators[value];
  15247. } else {
  15248. console.warn("Mutator Error - No such mutator found, ignoring: ", value);
  15249. }
  15250. break;
  15251. case "function":
  15252. mutator = value;
  15253. break;
  15254. }
  15255. return mutator;
  15256. };
  15257. //apply mutator to row
  15258. Mutator.prototype.transformRow = function (data, type, updatedData) {
  15259. var self = this,
  15260. key = "mutator" + (type.charAt(0).toUpperCase() + type.slice(1)),
  15261. value;
  15262. if (this.enabled) {
  15263. self.table.columnManager.traverse(function (column) {
  15264. var mutator, params, component;
  15265. if (column.modules.mutate) {
  15266. mutator = column.modules.mutate[key] || column.modules.mutate.mutator || false;
  15267. if (mutator) {
  15268. value = column.getFieldValue(typeof updatedData !== "undefined" ? updatedData : data);
  15269. if (type == "data" || typeof value !== "undefined") {
  15270. component = column.getComponent();
  15271. params = typeof mutator.params === "function" ? mutator.params(value, data, type, component) : mutator.params;
  15272. column.setFieldValue(data, mutator.mutator(value, data, type, params, component));
  15273. }
  15274. }
  15275. }
  15276. });
  15277. }
  15278. return data;
  15279. };
  15280. //apply mutator to new cell value
  15281. Mutator.prototype.transformCell = function (cell, value) {
  15282. var mutator = cell.column.modules.mutate.mutatorEdit || cell.column.modules.mutate.mutator || false,
  15283. tempData = {};
  15284. if (mutator) {
  15285. tempData = Object.assign(tempData, cell.row.getData());
  15286. cell.column.setFieldValue(tempData, value);
  15287. return mutator.mutator(value, tempData, "edit", mutator.params, cell.getComponent());
  15288. } else {
  15289. return value;
  15290. }
  15291. };
  15292. Mutator.prototype.enable = function () {
  15293. this.enabled = true;
  15294. };
  15295. Mutator.prototype.disable = function () {
  15296. this.enabled = false;
  15297. };
  15298. //default mutators
  15299. Mutator.prototype.mutators = {};
  15300. Tabulator.prototype.registerModule("mutator", Mutator);
  15301. var Page = function Page(table) {
  15302. this.table = table; //hold Tabulator object
  15303. this.mode = "local";
  15304. this.progressiveLoad = false;
  15305. this.size = 0;
  15306. this.page = 1;
  15307. this.count = 5;
  15308. this.max = 1;
  15309. this.displayIndex = 0; //index in display pipeline
  15310. this.initialLoad = true;
  15311. this.pageSizes = [];
  15312. this.dataReceivedNames = {};
  15313. this.dataSentNames = {};
  15314. this.createElements();
  15315. };
  15316. Page.prototype.createElements = function () {
  15317. var button;
  15318. this.element = document.createElement("span");
  15319. this.element.classList.add("tabulator-paginator");
  15320. this.pagesElement = document.createElement("span");
  15321. this.pagesElement.classList.add("tabulator-pages");
  15322. button = document.createElement("button");
  15323. button.classList.add("tabulator-page");
  15324. button.setAttribute("type", "button");
  15325. button.setAttribute("role", "button");
  15326. button.setAttribute("aria-label", "");
  15327. button.setAttribute("title", "");
  15328. this.firstBut = button.cloneNode(true);
  15329. this.firstBut.setAttribute("data-page", "first");
  15330. this.prevBut = button.cloneNode(true);
  15331. this.prevBut.setAttribute("data-page", "prev");
  15332. this.nextBut = button.cloneNode(true);
  15333. this.nextBut.setAttribute("data-page", "next");
  15334. this.lastBut = button.cloneNode(true);
  15335. this.lastBut.setAttribute("data-page", "last");
  15336. if (this.table.options.paginationSizeSelector) {
  15337. this.pageSizeSelect = document.createElement("select");
  15338. this.pageSizeSelect.classList.add("tabulator-page-size");
  15339. }
  15340. };
  15341. Page.prototype.generatePageSizeSelectList = function () {
  15342. var _this75 = this;
  15343. var pageSizes = [];
  15344. if (this.pageSizeSelect) {
  15345. if (Array.isArray(this.table.options.paginationSizeSelector)) {
  15346. pageSizes = this.table.options.paginationSizeSelector;
  15347. this.pageSizes = pageSizes;
  15348. if (this.pageSizes.indexOf(this.size) == -1) {
  15349. pageSizes.unshift(this.size);
  15350. }
  15351. } else {
  15352. if (this.pageSizes.indexOf(this.size) == -1) {
  15353. pageSizes = [];
  15354. for (var _i13 = 1; _i13 < 5; _i13++) {
  15355. pageSizes.push(this.size * _i13);
  15356. }
  15357. this.pageSizes = pageSizes;
  15358. } else {
  15359. pageSizes = this.pageSizes;
  15360. }
  15361. }
  15362. while (this.pageSizeSelect.firstChild) {
  15363. this.pageSizeSelect.removeChild(this.pageSizeSelect.firstChild);
  15364. }pageSizes.forEach(function (item) {
  15365. var itemEl = document.createElement("option");
  15366. itemEl.value = item;
  15367. if (item === true) {
  15368. _this75.table.modules.localize.bind("pagination|all", function (value) {
  15369. itemEl.innerHTML = value;
  15370. });
  15371. } else {
  15372. itemEl.innerHTML = item;
  15373. }
  15374. _this75.pageSizeSelect.appendChild(itemEl);
  15375. });
  15376. this.pageSizeSelect.value = this.size;
  15377. }
  15378. };
  15379. //setup pageination
  15380. Page.prototype.initialize = function (hidden) {
  15381. var self = this,
  15382. pageSelectLabel,
  15383. testElRow,
  15384. testElCell;
  15385. //update param names
  15386. this.dataSentNames = Object.assign({}, this.paginationDataSentNames);
  15387. this.dataSentNames = Object.assign(this.dataSentNames, this.table.options.paginationDataSent);
  15388. this.dataReceivedNames = Object.assign({}, this.paginationDataReceivedNames);
  15389. this.dataReceivedNames = Object.assign(this.dataReceivedNames, this.table.options.paginationDataReceived);
  15390. //build pagination element
  15391. //bind localizations
  15392. self.table.modules.localize.bind("pagination|first", function (value) {
  15393. self.firstBut.innerHTML = value;
  15394. });
  15395. self.table.modules.localize.bind("pagination|first_title", function (value) {
  15396. self.firstBut.setAttribute("aria-label", value);
  15397. self.firstBut.setAttribute("title", value);
  15398. });
  15399. self.table.modules.localize.bind("pagination|prev", function (value) {
  15400. self.prevBut.innerHTML = value;
  15401. });
  15402. self.table.modules.localize.bind("pagination|prev_title", function (value) {
  15403. self.prevBut.setAttribute("aria-label", value);
  15404. self.prevBut.setAttribute("title", value);
  15405. });
  15406. self.table.modules.localize.bind("pagination|next", function (value) {
  15407. self.nextBut.innerHTML = value;
  15408. });
  15409. self.table.modules.localize.bind("pagination|next_title", function (value) {
  15410. self.nextBut.setAttribute("aria-label", value);
  15411. self.nextBut.setAttribute("title", value);
  15412. });
  15413. self.table.modules.localize.bind("pagination|last", function (value) {
  15414. self.lastBut.innerHTML = value;
  15415. });
  15416. self.table.modules.localize.bind("pagination|last_title", function (value) {
  15417. self.lastBut.setAttribute("aria-label", value);
  15418. self.lastBut.setAttribute("title", value);
  15419. });
  15420. //click bindings
  15421. self.firstBut.addEventListener("click", function () {
  15422. self.setPage(1).then(function () {}).catch(function () {});
  15423. });
  15424. self.prevBut.addEventListener("click", function () {
  15425. self.previousPage().then(function () {}).catch(function () {});
  15426. });
  15427. self.nextBut.addEventListener("click", function () {
  15428. self.nextPage().then(function () {}).catch(function () {});
  15429. });
  15430. self.lastBut.addEventListener("click", function () {
  15431. self.setPage(self.max).then(function () {}).catch(function () {});
  15432. });
  15433. if (self.table.options.paginationElement) {
  15434. self.element = self.table.options.paginationElement;
  15435. }
  15436. if (this.pageSizeSelect) {
  15437. pageSelectLabel = document.createElement("label");
  15438. self.table.modules.localize.bind("pagination|page_size", function (value) {
  15439. self.pageSizeSelect.setAttribute("aria-label", value);
  15440. self.pageSizeSelect.setAttribute("title", value);
  15441. pageSelectLabel.innerHTML = value;
  15442. });
  15443. self.element.appendChild(pageSelectLabel);
  15444. self.element.appendChild(self.pageSizeSelect);
  15445. self.pageSizeSelect.addEventListener("change", function (e) {
  15446. self.setPageSize(self.pageSizeSelect.value == "true" ? true : self.pageSizeSelect.value);
  15447. self.setPage(1).then(function () {}).catch(function () {});
  15448. });
  15449. }
  15450. //append to DOM
  15451. self.element.appendChild(self.firstBut);
  15452. self.element.appendChild(self.prevBut);
  15453. self.element.appendChild(self.pagesElement);
  15454. self.element.appendChild(self.nextBut);
  15455. self.element.appendChild(self.lastBut);
  15456. if (!self.table.options.paginationElement && !hidden) {
  15457. self.table.footerManager.append(self.element, self);
  15458. }
  15459. //set default values
  15460. self.mode = self.table.options.pagination;
  15461. if (self.table.options.paginationSize) {
  15462. self.size = self.table.options.paginationSize;
  15463. } else {
  15464. testElRow = document.createElement("div");
  15465. testElRow.classList.add("tabulator-row");
  15466. testElRow.style.visibility = hidden;
  15467. testElCell = document.createElement("div");
  15468. testElCell.classList.add("tabulator-cell");
  15469. testElCell.innerHTML = "Page Row Test";
  15470. testElRow.appendChild(testElCell);
  15471. self.table.rowManager.getTableElement().appendChild(testElRow);
  15472. self.size = Math.floor(self.table.rowManager.getElement().clientHeight / testElRow.offsetHeight);
  15473. self.table.rowManager.getTableElement().removeChild(testElRow);
  15474. }
  15475. // self.page = self.table.options.paginationInitialPage || 1;
  15476. self.count = self.table.options.paginationButtonCount;
  15477. self.generatePageSizeSelectList();
  15478. };
  15479. Page.prototype.initializeProgressive = function (mode) {
  15480. this.initialize(true);
  15481. this.mode = "progressive_" + mode;
  15482. this.progressiveLoad = true;
  15483. };
  15484. Page.prototype.setDisplayIndex = function (index) {
  15485. this.displayIndex = index;
  15486. };
  15487. Page.prototype.getDisplayIndex = function () {
  15488. return this.displayIndex;
  15489. };
  15490. //calculate maximum page from number of rows
  15491. Page.prototype.setMaxRows = function (rowCount) {
  15492. if (!rowCount) {
  15493. this.max = 1;
  15494. } else {
  15495. this.max = this.size === true ? 1 : Math.ceil(rowCount / this.size);
  15496. }
  15497. if (this.page > this.max) {
  15498. this.page = this.max;
  15499. }
  15500. };
  15501. //reset to first page without triggering action
  15502. Page.prototype.reset = function (force, columnsChanged) {
  15503. if (this.mode == "local" || force) {
  15504. this.page = 1;
  15505. }
  15506. if (columnsChanged) {
  15507. this.initialLoad = true;
  15508. }
  15509. return true;
  15510. };
  15511. //set the maxmum page
  15512. Page.prototype.setMaxPage = function (max) {
  15513. max = parseInt(max);
  15514. this.max = max || 1;
  15515. if (this.page > this.max) {
  15516. this.page = this.max;
  15517. this.trigger();
  15518. }
  15519. };
  15520. //set current page number
  15521. Page.prototype.setPage = function (page) {
  15522. var _this76 = this;
  15523. var self = this;
  15524. switch (page) {
  15525. case "first":
  15526. return this.setPage(1);
  15527. break;
  15528. case "prev":
  15529. return this.previousPage();
  15530. break;
  15531. case "next":
  15532. return this.nextPage();
  15533. break;
  15534. case "last":
  15535. return this.setPage(this.max);
  15536. break;
  15537. }
  15538. return new Promise(function (resolve, reject) {
  15539. page = parseInt(page);
  15540. if (page > 0 && page <= _this76.max) {
  15541. _this76.page = page;
  15542. _this76.trigger().then(function () {
  15543. resolve();
  15544. }).catch(function () {
  15545. reject();
  15546. });
  15547. if (self.table.options.persistence && self.table.modExists("persistence", true) && self.table.modules.persistence.config.page) {
  15548. self.table.modules.persistence.save("page");
  15549. }
  15550. } else {
  15551. console.warn("Pagination Error - Requested page is out of range of 1 - " + _this76.max + ":", page);
  15552. reject();
  15553. }
  15554. });
  15555. };
  15556. Page.prototype.setPageToRow = function (row) {
  15557. var _this77 = this;
  15558. return new Promise(function (resolve, reject) {
  15559. var rows = _this77.table.rowManager.getDisplayRows(_this77.displayIndex - 1);
  15560. var index = rows.indexOf(row);
  15561. if (index > -1) {
  15562. var page = _this77.size === true ? 1 : Math.ceil((index + 1) / _this77.size);
  15563. _this77.setPage(page).then(function () {
  15564. resolve();
  15565. }).catch(function () {
  15566. reject();
  15567. });
  15568. } else {
  15569. console.warn("Pagination Error - Requested row is not visible");
  15570. reject();
  15571. }
  15572. });
  15573. };
  15574. Page.prototype.setPageSize = function (size) {
  15575. if (size !== true) {
  15576. size = parseInt(size);
  15577. }
  15578. if (size > 0) {
  15579. this.size = size;
  15580. }
  15581. if (this.pageSizeSelect) {
  15582. // this.pageSizeSelect.value = size;
  15583. this.generatePageSizeSelectList();
  15584. }
  15585. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.page) {
  15586. this.table.modules.persistence.save("page");
  15587. }
  15588. };
  15589. //setup the pagination buttons
  15590. Page.prototype._setPageButtons = function () {
  15591. var self = this;
  15592. var leftSize = Math.floor((this.count - 1) / 2);
  15593. var rightSize = Math.ceil((this.count - 1) / 2);
  15594. var min = this.max - this.page + leftSize + 1 < this.count ? this.max - this.count + 1 : Math.max(this.page - leftSize, 1);
  15595. var max = this.page <= rightSize ? Math.min(this.count, this.max) : Math.min(this.page + rightSize, this.max);
  15596. while (self.pagesElement.firstChild) {
  15597. self.pagesElement.removeChild(self.pagesElement.firstChild);
  15598. }if (self.page == 1) {
  15599. self.firstBut.disabled = true;
  15600. self.prevBut.disabled = true;
  15601. } else {
  15602. self.firstBut.disabled = false;
  15603. self.prevBut.disabled = false;
  15604. }
  15605. if (self.page == self.max) {
  15606. self.lastBut.disabled = true;
  15607. self.nextBut.disabled = true;
  15608. } else {
  15609. self.lastBut.disabled = false;
  15610. self.nextBut.disabled = false;
  15611. }
  15612. for (var _i14 = min; _i14 <= max; _i14++) {
  15613. if (_i14 > 0 && _i14 <= self.max) {
  15614. self.pagesElement.appendChild(self._generatePageButton(_i14));
  15615. }
  15616. }
  15617. this.footerRedraw();
  15618. };
  15619. Page.prototype._generatePageButton = function (page) {
  15620. var self = this,
  15621. button = document.createElement("button");
  15622. button.classList.add("tabulator-page");
  15623. if (page == self.page) {
  15624. button.classList.add("active");
  15625. }
  15626. button.setAttribute("type", "button");
  15627. button.setAttribute("role", "button");
  15628. self.table.modules.localize.bind("pagination|page_title", function (value) {
  15629. button.setAttribute("aria-label", value + " " + page);
  15630. button.setAttribute("title", value + " " + page);
  15631. });
  15632. button.setAttribute("data-page", page);
  15633. button.textContent = page;
  15634. button.addEventListener("click", function (e) {
  15635. self.setPage(page).then(function () {}).catch(function () {});
  15636. });
  15637. return button;
  15638. };
  15639. //previous page
  15640. Page.prototype.previousPage = function () {
  15641. var _this78 = this;
  15642. return new Promise(function (resolve, reject) {
  15643. if (_this78.page > 1) {
  15644. _this78.page--;
  15645. _this78.trigger().then(function () {
  15646. resolve();
  15647. }).catch(function () {
  15648. reject();
  15649. });
  15650. if (_this78.table.options.persistence && _this78.table.modExists("persistence", true) && _this78.table.modules.persistence.config.page) {
  15651. _this78.table.modules.persistence.save("page");
  15652. }
  15653. } else {
  15654. console.warn("Pagination Error - Previous page would be less than page 1:", 0);
  15655. reject();
  15656. }
  15657. });
  15658. };
  15659. //next page
  15660. Page.prototype.nextPage = function () {
  15661. var _this79 = this;
  15662. return new Promise(function (resolve, reject) {
  15663. if (_this79.page < _this79.max) {
  15664. _this79.page++;
  15665. _this79.trigger().then(function () {
  15666. resolve();
  15667. }).catch(function () {
  15668. reject();
  15669. });
  15670. if (_this79.table.options.persistence && _this79.table.modExists("persistence", true) && _this79.table.modules.persistence.config.page) {
  15671. _this79.table.modules.persistence.save("page");
  15672. }
  15673. } else {
  15674. if (!_this79.progressiveLoad) {
  15675. console.warn("Pagination Error - Next page would be greater than maximum page of " + _this79.max + ":", _this79.max + 1);
  15676. }
  15677. reject();
  15678. }
  15679. });
  15680. };
  15681. //return current page number
  15682. Page.prototype.getPage = function () {
  15683. return this.page;
  15684. };
  15685. //return max page number
  15686. Page.prototype.getPageMax = function () {
  15687. return this.max;
  15688. };
  15689. Page.prototype.getPageSize = function (size) {
  15690. return this.size;
  15691. };
  15692. Page.prototype.getMode = function () {
  15693. return this.mode;
  15694. };
  15695. //return appropriate rows for current page
  15696. Page.prototype.getRows = function (data) {
  15697. var output, start, end;
  15698. if (this.mode == "local") {
  15699. output = [];
  15700. if (this.size === true) {
  15701. start = 0;
  15702. end = data.length;
  15703. } else {
  15704. start = this.size * (this.page - 1);
  15705. end = start + parseInt(this.size);
  15706. }
  15707. this._setPageButtons();
  15708. for (var _i15 = start; _i15 < end; _i15++) {
  15709. if (data[_i15]) {
  15710. output.push(data[_i15]);
  15711. }
  15712. }
  15713. return output;
  15714. } else {
  15715. this._setPageButtons();
  15716. return data.slice(0);
  15717. }
  15718. };
  15719. Page.prototype.trigger = function () {
  15720. var _this80 = this;
  15721. var left;
  15722. return new Promise(function (resolve, reject) {
  15723. switch (_this80.mode) {
  15724. case "local":
  15725. left = _this80.table.rowManager.scrollLeft;
  15726. _this80.table.rowManager.refreshActiveData("page");
  15727. _this80.table.rowManager.scrollHorizontal(left);
  15728. _this80.table.options.pageLoaded.call(_this80.table, _this80.getPage());
  15729. resolve();
  15730. break;
  15731. case "remote":
  15732. case "progressive_load":
  15733. case "progressive_scroll":
  15734. _this80.table.modules.ajax.blockActiveRequest();
  15735. _this80._getRemotePage().then(function () {
  15736. resolve();
  15737. }).catch(function () {
  15738. reject();
  15739. });
  15740. break;
  15741. default:
  15742. console.warn("Pagination Error - no such pagination mode:", _this80.mode);
  15743. reject();
  15744. }
  15745. });
  15746. };
  15747. Page.prototype._getRemotePage = function () {
  15748. var _this81 = this;
  15749. var self = this,
  15750. oldParams,
  15751. pageParams;
  15752. return new Promise(function (resolve, reject) {
  15753. if (!self.table.modExists("ajax", true)) {
  15754. reject();
  15755. }
  15756. //record old params and restore after request has been made
  15757. oldParams = Tabulator.prototype.helpers.deepClone(self.table.modules.ajax.getParams() || {});
  15758. pageParams = self.table.modules.ajax.getParams();
  15759. //configure request params
  15760. pageParams[_this81.dataSentNames.page] = self.page;
  15761. //set page size if defined
  15762. if (_this81.size) {
  15763. pageParams[_this81.dataSentNames.size] = _this81.size;
  15764. }
  15765. //set sort data if defined
  15766. if (_this81.table.options.ajaxSorting && _this81.table.modExists("sort")) {
  15767. var sorters = self.table.modules.sort.getSort();
  15768. sorters.forEach(function (item) {
  15769. delete item.column;
  15770. });
  15771. pageParams[_this81.dataSentNames.sorters] = sorters;
  15772. }
  15773. //set filter data if defined
  15774. if (_this81.table.options.ajaxFiltering && _this81.table.modExists("filter")) {
  15775. var filters = self.table.modules.filter.getFilters(true, true);
  15776. pageParams[_this81.dataSentNames.filters] = filters;
  15777. }
  15778. self.table.modules.ajax.setParams(pageParams);
  15779. self.table.modules.ajax.sendRequest(_this81.progressiveLoad).then(function (data) {
  15780. self._parseRemoteData(data);
  15781. resolve();
  15782. }).catch(function (e) {
  15783. reject();
  15784. });
  15785. self.table.modules.ajax.setParams(oldParams);
  15786. });
  15787. };
  15788. Page.prototype._parseRemoteData = function (data) {
  15789. var self = this,
  15790. left,
  15791. data,
  15792. margin;
  15793. if (typeof data[this.dataReceivedNames.last_page] === "undefined") {
  15794. console.warn("Remote Pagination Error - Server response missing '" + this.dataReceivedNames.last_page + "' property");
  15795. }
  15796. if (data[this.dataReceivedNames.data]) {
  15797. this.max = parseInt(data[this.dataReceivedNames.last_page]) || 1;
  15798. if (this.progressiveLoad) {
  15799. switch (this.mode) {
  15800. case "progressive_load":
  15801. if (this.page == 1) {
  15802. this.table.rowManager.setData(data[this.dataReceivedNames.data], false, this.initialLoad && this.page == 1);
  15803. } else {
  15804. this.table.rowManager.addRows(data[this.dataReceivedNames.data]);
  15805. }
  15806. if (this.page < this.max) {
  15807. setTimeout(function () {
  15808. self.nextPage().then(function () {}).catch(function () {});
  15809. }, self.table.options.ajaxProgressiveLoadDelay);
  15810. }
  15811. break;
  15812. case "progressive_scroll":
  15813. data = this.table.rowManager.getData().concat(data[this.dataReceivedNames.data]);
  15814. this.table.rowManager.setData(data, true, this.initialLoad && this.page == 1);
  15815. margin = this.table.options.ajaxProgressiveLoadScrollMargin || this.table.rowManager.element.clientHeight * 2;
  15816. if (self.table.rowManager.element.scrollHeight <= self.table.rowManager.element.clientHeight + margin) {
  15817. self.nextPage().then(function () {}).catch(function () {});
  15818. }
  15819. break;
  15820. }
  15821. } else {
  15822. left = this.table.rowManager.scrollLeft;
  15823. this.table.rowManager.setData(data[this.dataReceivedNames.data], false, this.initialLoad && this.page == 1);
  15824. this.table.rowManager.scrollHorizontal(left);
  15825. this.table.columnManager.scrollHorizontal(left);
  15826. this.table.options.pageLoaded.call(this.table, this.getPage());
  15827. }
  15828. this.initialLoad = false;
  15829. } else {
  15830. console.warn("Remote Pagination Error - Server response missing '" + this.dataReceivedNames.data + "' property");
  15831. }
  15832. };
  15833. //handle the footer element being redrawn
  15834. Page.prototype.footerRedraw = function () {
  15835. var footer = this.table.footerManager.element;
  15836. if (Math.ceil(footer.clientWidth) - footer.scrollWidth < 0) {
  15837. this.pagesElement.style.display = 'none';
  15838. } else {
  15839. this.pagesElement.style.display = '';
  15840. if (Math.ceil(footer.clientWidth) - footer.scrollWidth < 0) {
  15841. this.pagesElement.style.display = 'none';
  15842. }
  15843. }
  15844. };
  15845. //set the paramter names for pagination requests
  15846. Page.prototype.paginationDataSentNames = {
  15847. "page": "page",
  15848. "size": "size",
  15849. "sorters": "sorters",
  15850. // "sort_dir":"sort_dir",
  15851. "filters": "filters"
  15852. // "filter_value":"filter_value",
  15853. // "filter_type":"filter_type",
  15854. };
  15855. //set the property names for pagination responses
  15856. Page.prototype.paginationDataReceivedNames = {
  15857. "current_page": "current_page",
  15858. "last_page": "last_page",
  15859. "data": "data"
  15860. };
  15861. Tabulator.prototype.registerModule("page", Page);
  15862. var Persistence = function Persistence(table) {
  15863. this.table = table; //hold Tabulator object
  15864. this.mode = "";
  15865. this.id = "";
  15866. // this.persistProps = ["field", "width", "visible"];
  15867. this.defWatcherBlock = false;
  15868. this.config = {};
  15869. this.readFunc = false;
  15870. this.writeFunc = false;
  15871. };
  15872. // Test for whether localStorage is available for use.
  15873. Persistence.prototype.localStorageTest = function () {
  15874. var testKey = "_tabulator_test";
  15875. try {
  15876. window.localStorage.setItem(testKey, testKey);
  15877. window.localStorage.removeItem(testKey);
  15878. return true;
  15879. } catch (e) {
  15880. return false;
  15881. }
  15882. };
  15883. //setup parameters
  15884. Persistence.prototype.initialize = function () {
  15885. //determine persistent layout storage type
  15886. var mode = this.table.options.persistenceMode,
  15887. id = this.table.options.persistenceID,
  15888. retreivedData;
  15889. this.mode = mode !== true ? mode : this.localStorageTest() ? "local" : "cookie";
  15890. if (this.table.options.persistenceReaderFunc) {
  15891. if (typeof this.table.options.persistenceReaderFunc === "function") {
  15892. this.readFunc = this.table.options.persistenceReaderFunc;
  15893. } else {
  15894. if (this.readers[this.table.options.persistenceReaderFunc]) {
  15895. this.readFunc = this.readers[this.table.options.persistenceReaderFunc];
  15896. } else {
  15897. console.warn("Persistence Read Error - invalid reader set", this.table.options.persistenceReaderFunc);
  15898. }
  15899. }
  15900. } else {
  15901. if (this.readers[this.mode]) {
  15902. this.readFunc = this.readers[this.mode];
  15903. } else {
  15904. console.warn("Persistence Read Error - invalid reader set", this.mode);
  15905. }
  15906. }
  15907. if (this.table.options.persistenceWriterFunc) {
  15908. if (typeof this.table.options.persistenceWriterFunc === "function") {
  15909. this.writeFunc = this.table.options.persistenceWriterFunc;
  15910. } else {
  15911. if (this.readers[this.table.options.persistenceWriterFunc]) {
  15912. this.writeFunc = this.readers[this.table.options.persistenceWriterFunc];
  15913. } else {
  15914. console.warn("Persistence Write Error - invalid reader set", this.table.options.persistenceWriterFunc);
  15915. }
  15916. }
  15917. } else {
  15918. if (this.writers[this.mode]) {
  15919. this.writeFunc = this.writers[this.mode];
  15920. } else {
  15921. console.warn("Persistence Write Error - invalid writer set", this.mode);
  15922. }
  15923. }
  15924. //set storage tag
  15925. this.id = "tabulator-" + (id || this.table.element.getAttribute("id") || "");
  15926. this.config = {
  15927. sort: this.table.options.persistence === true || this.table.options.persistence.sort,
  15928. filter: this.table.options.persistence === true || this.table.options.persistence.filter,
  15929. group: this.table.options.persistence === true || this.table.options.persistence.group,
  15930. page: this.table.options.persistence === true || this.table.options.persistence.page,
  15931. columns: this.table.options.persistence === true ? ["title", "width", "visible"] : this.table.options.persistence.columns
  15932. };
  15933. //load pagination data if needed
  15934. if (this.config.page) {
  15935. retreivedData = this.retreiveData("page");
  15936. if (retreivedData) {
  15937. if (typeof retreivedData.paginationSize !== "undefined" && (this.config.page === true || this.config.page.size)) {
  15938. this.table.options.paginationSize = retreivedData.paginationSize;
  15939. }
  15940. if (typeof retreivedData.paginationInitialPage !== "undefined" && (this.config.page === true || this.config.page.page)) {
  15941. this.table.options.paginationInitialPage = retreivedData.paginationInitialPage;
  15942. }
  15943. }
  15944. }
  15945. //load group data if needed
  15946. if (this.config.group) {
  15947. retreivedData = this.retreiveData("group");
  15948. if (retreivedData) {
  15949. if (typeof retreivedData.groupBy !== "undefined" && (this.config.group === true || this.config.group.groupBy)) {
  15950. this.table.options.groupBy = retreivedData.groupBy;
  15951. }
  15952. if (typeof retreivedData.groupStartOpen !== "undefined" && (this.config.group === true || this.config.group.groupStartOpen)) {
  15953. this.table.options.groupStartOpen = retreivedData.groupStartOpen;
  15954. }
  15955. if (typeof retreivedData.groupHeader !== "undefined" && (this.config.group === true || this.config.group.groupHeader)) {
  15956. this.table.options.groupHeader = retreivedData.groupHeader;
  15957. }
  15958. }
  15959. }
  15960. };
  15961. Persistence.prototype.initializeColumn = function (column) {
  15962. var self = this,
  15963. def,
  15964. keys;
  15965. if (this.config.columns) {
  15966. this.defWatcherBlock = true;
  15967. def = column.getDefinition();
  15968. keys = this.config.columns === true ? Object.keys(def) : this.config.columns;
  15969. keys.forEach(function (key) {
  15970. var props = Object.getOwnPropertyDescriptor(def, key);
  15971. var value = def[key];
  15972. if (props) {
  15973. Object.defineProperty(def, key, {
  15974. set: function set(newValue) {
  15975. value = newValue;
  15976. if (!self.defWatcherBlock) {
  15977. self.save("columns");
  15978. }
  15979. if (props.set) {
  15980. props.set(newValue);
  15981. }
  15982. },
  15983. get: function get() {
  15984. if (props.get) {
  15985. props.get();
  15986. }
  15987. return value;
  15988. }
  15989. });
  15990. }
  15991. });
  15992. this.defWatcherBlock = false;
  15993. }
  15994. };
  15995. //load saved definitions
  15996. Persistence.prototype.load = function (type, current) {
  15997. var data = this.retreiveData(type);
  15998. if (current) {
  15999. data = data ? this.mergeDefinition(current, data) : current;
  16000. }
  16001. return data;
  16002. };
  16003. //retreive data from memory
  16004. Persistence.prototype.retreiveData = function (type) {
  16005. return this.readFunc ? this.readFunc(this.id, type) : false;
  16006. };
  16007. //merge old and new column definitions
  16008. Persistence.prototype.mergeDefinition = function (oldCols, newCols) {
  16009. var self = this,
  16010. output = [];
  16011. // oldCols = oldCols || [];
  16012. newCols = newCols || [];
  16013. newCols.forEach(function (column, to) {
  16014. var from = self._findColumn(oldCols, column),
  16015. keys;
  16016. if (from) {
  16017. if (self.config.columns === true || self.config.columns == undefined) {
  16018. keys = Object.keys(from);
  16019. keys.push("width");
  16020. } else {
  16021. keys = self.config.columns;
  16022. }
  16023. keys.forEach(function (key) {
  16024. if (typeof column[key] !== "undefined") {
  16025. from[key] = column[key];
  16026. }
  16027. });
  16028. if (from.columns) {
  16029. from.columns = self.mergeDefinition(from.columns, column.columns);
  16030. }
  16031. output.push(from);
  16032. }
  16033. });
  16034. oldCols.forEach(function (column, i) {
  16035. var from = self._findColumn(newCols, column);
  16036. if (!from) {
  16037. if (output.length > i) {
  16038. output.splice(i, 0, column);
  16039. } else {
  16040. output.push(column);
  16041. }
  16042. }
  16043. });
  16044. return output;
  16045. };
  16046. //find matching columns
  16047. Persistence.prototype._findColumn = function (columns, subject) {
  16048. var type = subject.columns ? "group" : subject.field ? "field" : "object";
  16049. return columns.find(function (col) {
  16050. switch (type) {
  16051. case "group":
  16052. return col.title === subject.title && col.columns.length === subject.columns.length;
  16053. break;
  16054. case "field":
  16055. return col.field === subject.field;
  16056. break;
  16057. case "object":
  16058. return col === subject;
  16059. break;
  16060. }
  16061. });
  16062. };
  16063. //save data
  16064. Persistence.prototype.save = function (type) {
  16065. var data = {};
  16066. switch (type) {
  16067. case "columns":
  16068. data = this.parseColumns(this.table.columnManager.getColumns());
  16069. break;
  16070. case "filter":
  16071. data = this.table.modules.filter.getFilters();
  16072. break;
  16073. case "sort":
  16074. data = this.validateSorters(this.table.modules.sort.getSort());
  16075. break;
  16076. case "group":
  16077. data = this.getGroupConfig();
  16078. break;
  16079. case "page":
  16080. data = this.getPageConfig();
  16081. break;
  16082. }
  16083. if (this.writeFunc) {
  16084. this.writeFunc(this.id, type, data);
  16085. }
  16086. };
  16087. //ensure sorters contain no function data
  16088. Persistence.prototype.validateSorters = function (data) {
  16089. data.forEach(function (item) {
  16090. item.column = item.field;
  16091. delete item.field;
  16092. });
  16093. return data;
  16094. };
  16095. Persistence.prototype.getGroupConfig = function () {
  16096. var data = {};
  16097. if (this.config.group) {
  16098. if (this.config.group === true || this.config.group.groupBy) {
  16099. data.groupBy = this.table.options.groupBy;
  16100. }
  16101. if (this.config.group === true || this.config.group.groupStartOpen) {
  16102. data.groupStartOpen = this.table.options.groupStartOpen;
  16103. }
  16104. if (this.config.group === true || this.config.group.groupHeader) {
  16105. data.groupHeader = this.table.options.groupHeader;
  16106. }
  16107. }
  16108. return data;
  16109. };
  16110. Persistence.prototype.getPageConfig = function () {
  16111. var data = {};
  16112. if (this.config.page) {
  16113. if (this.config.page === true || this.config.page.size) {
  16114. data.paginationSize = this.table.modules.page.getPageSize();
  16115. }
  16116. if (this.config.page === true || this.config.page.page) {
  16117. data.paginationInitialPage = this.table.modules.page.getPage();
  16118. }
  16119. }
  16120. return data;
  16121. };
  16122. //parse columns for data to store
  16123. Persistence.prototype.parseColumns = function (columns) {
  16124. var self = this,
  16125. definitions = [],
  16126. excludedKeys = ["headerContextMenu", "headerMenu", "contextMenu", "clickMenu"];
  16127. columns.forEach(function (column) {
  16128. var defStore = {},
  16129. colDef = column.getDefinition(),
  16130. keys;
  16131. if (column.isGroup) {
  16132. defStore.title = colDef.title;
  16133. defStore.columns = self.parseColumns(column.getColumns());
  16134. } else {
  16135. defStore.field = column.getField();
  16136. if (self.config.columns === true || self.config.columns == undefined) {
  16137. keys = Object.keys(colDef);
  16138. keys.push("width");
  16139. } else {
  16140. keys = self.config.columns;
  16141. }
  16142. keys.forEach(function (key) {
  16143. switch (key) {
  16144. case "width":
  16145. defStore.width = column.getWidth();
  16146. break;
  16147. case "visible":
  16148. defStore.visible = column.visible;
  16149. break;
  16150. default:
  16151. if (typeof colDef[key] !== "function" && excludedKeys.indexOf(key) === -1) {
  16152. defStore[key] = colDef[key];
  16153. }
  16154. }
  16155. });
  16156. }
  16157. definitions.push(defStore);
  16158. });
  16159. return definitions;
  16160. };
  16161. // read peristence information from storage
  16162. Persistence.prototype.readers = {
  16163. local: function local(id, type) {
  16164. var data = localStorage.getItem(id + "-" + type);
  16165. return data ? JSON.parse(data) : false;
  16166. },
  16167. cookie: function cookie(id, type) {
  16168. var cookie = document.cookie,
  16169. key = id + "-" + type,
  16170. cookiePos = cookie.indexOf(key + "="),
  16171. end,
  16172. data;
  16173. //if cookie exists, decode and load column data into tabulator
  16174. if (cookiePos > -1) {
  16175. cookie = cookie.substr(cookiePos);
  16176. end = cookie.indexOf(";");
  16177. if (end > -1) {
  16178. cookie = cookie.substr(0, end);
  16179. }
  16180. data = cookie.replace(key + "=", "");
  16181. }
  16182. return data ? JSON.parse(data) : false;
  16183. }
  16184. };
  16185. //write persistence information to storage
  16186. Persistence.prototype.writers = {
  16187. local: function local(id, type, data) {
  16188. localStorage.setItem(id + "-" + type, JSON.stringify(data));
  16189. },
  16190. cookie: function cookie(id, type, data) {
  16191. var expireDate = new Date();
  16192. expireDate.setDate(expireDate.getDate() + 10000);
  16193. document.cookie = id + "-" + type + "=" + JSON.stringify(data) + "; expires=" + expireDate.toUTCString();
  16194. }
  16195. };
  16196. Tabulator.prototype.registerModule("persistence", Persistence);
  16197. var Print = function Print(table) {
  16198. this.table = table; //hold Tabulator object
  16199. this.element = false;
  16200. this.manualBlock = false;
  16201. };
  16202. Print.prototype.initialize = function () {
  16203. window.addEventListener("beforeprint", this.replaceTable.bind(this));
  16204. window.addEventListener("afterprint", this.cleanup.bind(this));
  16205. };
  16206. Print.prototype.replaceTable = function () {
  16207. if (!this.manualBlock) {
  16208. this.element = document.createElement("div");
  16209. this.element.classList.add("tabulator-print-table");
  16210. this.element.appendChild(this.table.modules.export.genereateTable(this.table.options.printConfig, this.table.options.printStyled, this.table.options.printRowRange, "print"));
  16211. this.table.element.style.display = "none";
  16212. this.table.element.parentNode.insertBefore(this.element, this.table.element);
  16213. }
  16214. };
  16215. Print.prototype.cleanup = function () {
  16216. document.body.classList.remove("tabulator-print-fullscreen-hide");
  16217. if (this.element && this.element.parentNode) {
  16218. this.element.parentNode.removeChild(this.element);
  16219. this.table.element.style.display = "";
  16220. }
  16221. };
  16222. Print.prototype.printFullscreen = function (visible, style, config) {
  16223. var scrollX = window.scrollX,
  16224. scrollY = window.scrollY,
  16225. headerEl = document.createElement("div"),
  16226. footerEl = document.createElement("div"),
  16227. tableEl = this.table.modules.export.genereateTable(typeof config != "undefined" ? config : this.table.options.printConfig, typeof style != "undefined" ? style : this.table.options.printStyled, visible, "print"),
  16228. headerContent,
  16229. footerContent;
  16230. this.manualBlock = true;
  16231. this.element = document.createElement("div");
  16232. this.element.classList.add("tabulator-print-fullscreen");
  16233. if (this.table.options.printHeader) {
  16234. headerEl.classList.add("tabulator-print-header");
  16235. headerContent = typeof this.table.options.printHeader == "function" ? this.table.options.printHeader.call(this.table) : this.table.options.printHeader;
  16236. if (typeof headerContent == "string") {
  16237. headerEl.innerHTML = headerContent;
  16238. } else {
  16239. headerEl.appendChild(headerContent);
  16240. }
  16241. this.element.appendChild(headerEl);
  16242. }
  16243. this.element.appendChild(tableEl);
  16244. if (this.table.options.printFooter) {
  16245. footerEl.classList.add("tabulator-print-footer");
  16246. footerContent = typeof this.table.options.printFooter == "function" ? this.table.options.printFooter.call(this.table) : this.table.options.printFooter;
  16247. if (typeof footerContent == "string") {
  16248. footerEl.innerHTML = footerContent;
  16249. } else {
  16250. footerEl.appendChild(footerContent);
  16251. }
  16252. this.element.appendChild(footerEl);
  16253. }
  16254. document.body.classList.add("tabulator-print-fullscreen-hide");
  16255. document.body.appendChild(this.element);
  16256. if (this.table.options.printFormatter) {
  16257. this.table.options.printFormatter(this.element, tableEl);
  16258. }
  16259. window.print();
  16260. this.cleanup();
  16261. window.scrollTo(scrollX, scrollY);
  16262. this.manualBlock = false;
  16263. };
  16264. Tabulator.prototype.registerModule("print", Print);
  16265. var ReactiveData = function ReactiveData(table) {
  16266. this.table = table; //hold Tabulator object
  16267. this.data = false;
  16268. this.blocked = false; //block reactivity while performing update
  16269. this.origFuncs = {}; // hold original data array functions to allow replacement after data is done with
  16270. this.currentVersion = 0;
  16271. };
  16272. ReactiveData.prototype.watchData = function (data) {
  16273. var self = this,
  16274. pushFunc,
  16275. version;
  16276. this.currentVersion++;
  16277. version = this.currentVersion;
  16278. self.unwatchData();
  16279. self.data = data;
  16280. //override array push function
  16281. self.origFuncs.push = data.push;
  16282. Object.defineProperty(self.data, "push", {
  16283. enumerable: false,
  16284. configurable: true,
  16285. value: function value() {
  16286. var args = Array.from(arguments);
  16287. if (!self.blocked && version === self.currentVersion) {
  16288. args.forEach(function (arg) {
  16289. self.table.rowManager.addRowActual(arg, false);
  16290. });
  16291. }
  16292. return self.origFuncs.push.apply(data, arguments);
  16293. }
  16294. });
  16295. //override array unshift function
  16296. self.origFuncs.unshift = data.unshift;
  16297. Object.defineProperty(self.data, "unshift", {
  16298. enumerable: false,
  16299. configurable: true,
  16300. value: function value() {
  16301. var args = Array.from(arguments);
  16302. if (!self.blocked && version === self.currentVersion) {
  16303. args.forEach(function (arg) {
  16304. self.table.rowManager.addRowActual(arg, true);
  16305. });
  16306. }
  16307. return self.origFuncs.unshift.apply(data, arguments);
  16308. }
  16309. });
  16310. //override array shift function
  16311. self.origFuncs.shift = data.shift;
  16312. Object.defineProperty(self.data, "shift", {
  16313. enumerable: false,
  16314. configurable: true,
  16315. value: function value() {
  16316. var row;
  16317. if (!self.blocked && version === self.currentVersion) {
  16318. if (self.data.length) {
  16319. row = self.table.rowManager.getRowFromDataObject(self.data[0]);
  16320. if (row) {
  16321. row.deleteActual();
  16322. }
  16323. }
  16324. }
  16325. return self.origFuncs.shift.call(data);
  16326. }
  16327. });
  16328. //override array pop function
  16329. self.origFuncs.pop = data.pop;
  16330. Object.defineProperty(self.data, "pop", {
  16331. enumerable: false,
  16332. configurable: true,
  16333. value: function value() {
  16334. var row;
  16335. if (!self.blocked && version === self.currentVersion) {
  16336. if (self.data.length) {
  16337. row = self.table.rowManager.getRowFromDataObject(self.data[self.data.length - 1]);
  16338. if (row) {
  16339. row.deleteActual();
  16340. }
  16341. }
  16342. }
  16343. return self.origFuncs.pop.call(data);
  16344. }
  16345. });
  16346. //override array splice function
  16347. self.origFuncs.splice = data.splice;
  16348. Object.defineProperty(self.data, "splice", {
  16349. enumerable: false,
  16350. configurable: true,
  16351. value: function value() {
  16352. var args = Array.from(arguments),
  16353. start = args[0] < 0 ? data.length + args[0] : args[0],
  16354. end = args[1],
  16355. newRows = args[2] ? args.slice(2) : false,
  16356. startRow;
  16357. if (!self.blocked && version === self.currentVersion) {
  16358. //add new rows
  16359. if (newRows) {
  16360. startRow = data[start] ? self.table.rowManager.getRowFromDataObject(data[start]) : false;
  16361. if (startRow) {
  16362. newRows.forEach(function (rowData) {
  16363. self.table.rowManager.addRowActual(rowData, true, startRow, true);
  16364. });
  16365. } else {
  16366. newRows = newRows.slice().reverse();
  16367. newRows.forEach(function (rowData) {
  16368. self.table.rowManager.addRowActual(rowData, true, false, true);
  16369. });
  16370. }
  16371. }
  16372. //delete removed rows
  16373. if (end !== 0) {
  16374. var oldRows = data.slice(start, typeof args[1] === "undefined" ? args[1] : start + end);
  16375. oldRows.forEach(function (rowData, i) {
  16376. var row = self.table.rowManager.getRowFromDataObject(rowData);
  16377. if (row) {
  16378. row.deleteActual(i !== oldRows.length - 1);
  16379. }
  16380. });
  16381. }
  16382. if (newRows || end !== 0) {
  16383. self.table.rowManager.reRenderInPosition();
  16384. }
  16385. }
  16386. return self.origFuncs.splice.apply(data, arguments);
  16387. }
  16388. });
  16389. };
  16390. ReactiveData.prototype.unwatchData = function () {
  16391. if (this.data !== false) {
  16392. for (var key in this.origFuncs) {
  16393. Object.defineProperty(this.data, key, {
  16394. enumerable: true,
  16395. configurable: true,
  16396. writable: true,
  16397. value: this.origFuncs.key
  16398. });
  16399. }
  16400. }
  16401. };
  16402. ReactiveData.prototype.watchRow = function (row) {
  16403. var data = row.getData();
  16404. this.blocked = true;
  16405. for (var key in data) {
  16406. this.watchKey(row, data, key);
  16407. }
  16408. if (this.table.options.dataTree) {
  16409. this.watchTreeChildren(row);
  16410. }
  16411. this.blocked = false;
  16412. };
  16413. ReactiveData.prototype.watchTreeChildren = function (row) {
  16414. var self = this,
  16415. childField = row.getData()[this.table.options.dataTreeChildField],
  16416. origFuncs = {};
  16417. function rebuildTree() {
  16418. self.table.modules.dataTree.initializeRow(row);
  16419. self.table.modules.dataTree.layoutRow(row);
  16420. self.table.rowManager.refreshActiveData("tree", false, true);
  16421. }
  16422. if (childField) {
  16423. origFuncs.push = childField.push;
  16424. Object.defineProperty(childField, "push", {
  16425. enumerable: false,
  16426. configurable: true,
  16427. value: function value() {
  16428. var result = origFuncs.push.apply(childField, arguments);
  16429. rebuildTree();
  16430. return result;
  16431. }
  16432. });
  16433. origFuncs.unshift = childField.unshift;
  16434. Object.defineProperty(childField, "unshift", {
  16435. enumerable: false,
  16436. configurable: true,
  16437. value: function value() {
  16438. var result = origFuncs.unshift.apply(childField, arguments);
  16439. rebuildTree();
  16440. return result;
  16441. }
  16442. });
  16443. origFuncs.shift = childField.shift;
  16444. Object.defineProperty(childField, "shift", {
  16445. enumerable: false,
  16446. configurable: true,
  16447. value: function value() {
  16448. var result = origFuncs.shift.call(childField);
  16449. rebuildTree();
  16450. return result;
  16451. }
  16452. });
  16453. origFuncs.pop = childField.pop;
  16454. Object.defineProperty(childField, "pop", {
  16455. enumerable: false,
  16456. configurable: true,
  16457. value: function value() {
  16458. var result = origFuncs.pop.call(childField);
  16459. rebuildTree();
  16460. return result;
  16461. }
  16462. });
  16463. origFuncs.splice = childField.splice;
  16464. Object.defineProperty(childField, "splice", {
  16465. enumerable: false,
  16466. configurable: true,
  16467. value: function value() {
  16468. var result = origFuncs.splice.apply(childField, arguments);
  16469. rebuildTree();
  16470. return result;
  16471. }
  16472. });
  16473. }
  16474. };
  16475. ReactiveData.prototype.watchKey = function (row, data, key) {
  16476. var self = this,
  16477. props = Object.getOwnPropertyDescriptor(data, key),
  16478. value = data[key],
  16479. version = this.currentVersion;
  16480. Object.defineProperty(data, key, {
  16481. set: function set(newValue) {
  16482. value = newValue;
  16483. if (!self.blocked && version === self.currentVersion) {
  16484. var update = {};
  16485. update[key] = newValue;
  16486. row.updateData(update);
  16487. }
  16488. if (props.set) {
  16489. props.set(newValue);
  16490. }
  16491. },
  16492. get: function get() {
  16493. if (props.get) {
  16494. props.get();
  16495. }
  16496. return value;
  16497. }
  16498. });
  16499. };
  16500. ReactiveData.prototype.unwatchRow = function (row) {
  16501. var data = row.getData();
  16502. for (var key in data) {
  16503. Object.defineProperty(data, key, {
  16504. value: data[key]
  16505. });
  16506. }
  16507. };
  16508. ReactiveData.prototype.block = function () {
  16509. this.blocked = true;
  16510. };
  16511. ReactiveData.prototype.unblock = function () {
  16512. this.blocked = false;
  16513. };
  16514. Tabulator.prototype.registerModule("reactiveData", ReactiveData);
  16515. var ResizeColumns = function ResizeColumns(table) {
  16516. this.table = table; //hold Tabulator object
  16517. this.startColumn = false;
  16518. this.startX = false;
  16519. this.startWidth = false;
  16520. this.handle = null;
  16521. this.prevHandle = null;
  16522. };
  16523. ResizeColumns.prototype.initializeColumn = function (type, column, element) {
  16524. var self = this,
  16525. variableHeight = false,
  16526. mode = this.table.options.resizableColumns;
  16527. //set column resize mode
  16528. if (type === "header") {
  16529. variableHeight = column.definition.formatter == "textarea" || column.definition.variableHeight;
  16530. column.modules.resize = { variableHeight: variableHeight };
  16531. }
  16532. if (mode === true || mode == type) {
  16533. var handle = document.createElement('div');
  16534. handle.className = "tabulator-col-resize-handle";
  16535. var prevHandle = document.createElement('div');
  16536. prevHandle.className = "tabulator-col-resize-handle prev";
  16537. handle.addEventListener("click", function (e) {
  16538. e.stopPropagation();
  16539. });
  16540. var handleDown = function handleDown(e) {
  16541. var nearestColumn = column.getLastColumn();
  16542. if (nearestColumn && self._checkResizability(nearestColumn)) {
  16543. self.startColumn = column;
  16544. self._mouseDown(e, nearestColumn, handle);
  16545. }
  16546. };
  16547. handle.addEventListener("mousedown", handleDown);
  16548. handle.addEventListener("touchstart", handleDown, { passive: true });
  16549. //reszie column on double click
  16550. handle.addEventListener("dblclick", function (e) {
  16551. var col = column.getLastColumn();
  16552. if (col && self._checkResizability(col)) {
  16553. e.stopPropagation();
  16554. col.reinitializeWidth(true);
  16555. }
  16556. });
  16557. prevHandle.addEventListener("click", function (e) {
  16558. e.stopPropagation();
  16559. });
  16560. var prevHandleDown = function prevHandleDown(e) {
  16561. var nearestColumn, colIndex, prevColumn;
  16562. nearestColumn = column.getFirstColumn();
  16563. if (nearestColumn) {
  16564. colIndex = self.table.columnManager.findColumnIndex(nearestColumn);
  16565. prevColumn = colIndex > 0 ? self.table.columnManager.getColumnByIndex(colIndex - 1) : false;
  16566. if (prevColumn && self._checkResizability(prevColumn)) {
  16567. self.startColumn = column;
  16568. self._mouseDown(e, prevColumn, prevHandle);
  16569. }
  16570. }
  16571. };
  16572. prevHandle.addEventListener("mousedown", prevHandleDown);
  16573. prevHandle.addEventListener("touchstart", prevHandleDown, { passive: true });
  16574. //resize column on double click
  16575. prevHandle.addEventListener("dblclick", function (e) {
  16576. var nearestColumn, colIndex, prevColumn;
  16577. nearestColumn = column.getFirstColumn();
  16578. if (nearestColumn) {
  16579. colIndex = self.table.columnManager.findColumnIndex(nearestColumn);
  16580. prevColumn = colIndex > 0 ? self.table.columnManager.getColumnByIndex(colIndex - 1) : false;
  16581. if (prevColumn && self._checkResizability(prevColumn)) {
  16582. e.stopPropagation();
  16583. prevColumn.reinitializeWidth(true);
  16584. }
  16585. }
  16586. });
  16587. element.appendChild(handle);
  16588. element.appendChild(prevHandle);
  16589. }
  16590. };
  16591. ResizeColumns.prototype._checkResizability = function (column) {
  16592. return typeof column.definition.resizable != "undefined" ? column.definition.resizable : this.table.options.resizableColumns;
  16593. };
  16594. ResizeColumns.prototype._mouseDown = function (e, column, handle) {
  16595. var self = this;
  16596. self.table.element.classList.add("tabulator-block-select");
  16597. function mouseMove(e) {
  16598. // self.table.columnManager.tempScrollBlock();
  16599. if (self.table.rtl) {
  16600. column.setWidth(self.startWidth - ((typeof e.screenX === "undefined" ? e.touches[0].screenX : e.screenX) - self.startX));
  16601. } else {
  16602. column.setWidth(self.startWidth + ((typeof e.screenX === "undefined" ? e.touches[0].screenX : e.screenX) - self.startX));
  16603. }
  16604. if (self.table.options.virtualDomHoz) {
  16605. self.table.vdomHoz.reinitialize(true);
  16606. }
  16607. if (!self.table.browserSlow && column.modules.resize && column.modules.resize.variableHeight) {
  16608. column.checkCellHeights();
  16609. }
  16610. }
  16611. function mouseUp(e) {
  16612. //block editor from taking action while resizing is taking place
  16613. if (self.startColumn.modules.edit) {
  16614. self.startColumn.modules.edit.blocked = false;
  16615. }
  16616. if (self.table.browserSlow && column.modules.resize && column.modules.resize.variableHeight) {
  16617. column.checkCellHeights();
  16618. }
  16619. document.body.removeEventListener("mouseup", mouseUp);
  16620. document.body.removeEventListener("mousemove", mouseMove);
  16621. handle.removeEventListener("touchmove", mouseMove);
  16622. handle.removeEventListener("touchend", mouseUp);
  16623. self.table.element.classList.remove("tabulator-block-select");
  16624. if (self.table.options.persistence && self.table.modExists("persistence", true) && self.table.modules.persistence.config.columns) {
  16625. self.table.modules.persistence.save("columns");
  16626. }
  16627. self.table.options.columnResized.call(self.table, column.getComponent());
  16628. }
  16629. e.stopPropagation(); //prevent resize from interfereing with movable columns
  16630. //block editor from taking action while resizing is taking place
  16631. if (self.startColumn.modules.edit) {
  16632. self.startColumn.modules.edit.blocked = true;
  16633. }
  16634. self.startX = typeof e.screenX === "undefined" ? e.touches[0].screenX : e.screenX;
  16635. self.startWidth = column.getWidth();
  16636. document.body.addEventListener("mousemove", mouseMove);
  16637. document.body.addEventListener("mouseup", mouseUp);
  16638. handle.addEventListener("touchmove", mouseMove, { passive: true });
  16639. handle.addEventListener("touchend", mouseUp);
  16640. };
  16641. Tabulator.prototype.registerModule("resizeColumns", ResizeColumns);
  16642. var ResizeRows = function ResizeRows(table) {
  16643. this.table = table; //hold Tabulator object
  16644. this.startColumn = false;
  16645. this.startY = false;
  16646. this.startHeight = false;
  16647. this.handle = null;
  16648. this.prevHandle = null;
  16649. };
  16650. ResizeRows.prototype.initializeRow = function (row) {
  16651. var self = this,
  16652. rowEl = row.getElement();
  16653. var handle = document.createElement('div');
  16654. handle.className = "tabulator-row-resize-handle";
  16655. var prevHandle = document.createElement('div');
  16656. prevHandle.className = "tabulator-row-resize-handle prev";
  16657. handle.addEventListener("click", function (e) {
  16658. e.stopPropagation();
  16659. });
  16660. var handleDown = function handleDown(e) {
  16661. self.startRow = row;
  16662. self._mouseDown(e, row, handle);
  16663. };
  16664. handle.addEventListener("mousedown", handleDown);
  16665. handle.addEventListener("touchstart", handleDown, { passive: true });
  16666. prevHandle.addEventListener("click", function (e) {
  16667. e.stopPropagation();
  16668. });
  16669. var prevHandleDown = function prevHandleDown(e) {
  16670. var prevRow = self.table.rowManager.prevDisplayRow(row);
  16671. if (prevRow) {
  16672. self.startRow = prevRow;
  16673. self._mouseDown(e, prevRow, prevHandle);
  16674. }
  16675. };
  16676. prevHandle.addEventListener("mousedown", prevHandleDown);
  16677. prevHandle.addEventListener("touchstart", prevHandleDown, { passive: true });
  16678. rowEl.appendChild(handle);
  16679. rowEl.appendChild(prevHandle);
  16680. };
  16681. ResizeRows.prototype._mouseDown = function (e, row, handle) {
  16682. var self = this;
  16683. self.table.element.classList.add("tabulator-block-select");
  16684. function mouseMove(e) {
  16685. row.setHeight(self.startHeight + ((typeof e.screenY === "undefined" ? e.touches[0].screenY : e.screenY) - self.startY));
  16686. }
  16687. function mouseUp(e) {
  16688. // //block editor from taking action while resizing is taking place
  16689. // if(self.startColumn.modules.edit){
  16690. // self.startColumn.modules.edit.blocked = false;
  16691. // }
  16692. document.body.removeEventListener("mouseup", mouseMove);
  16693. document.body.removeEventListener("mousemove", mouseMove);
  16694. handle.removeEventListener("touchmove", mouseMove);
  16695. handle.removeEventListener("touchend", mouseUp);
  16696. self.table.element.classList.remove("tabulator-block-select");
  16697. self.table.options.rowResized.call(this.table, row.getComponent());
  16698. }
  16699. e.stopPropagation(); //prevent resize from interfereing with movable columns
  16700. //block editor from taking action while resizing is taking place
  16701. // if(self.startColumn.modules.edit){
  16702. // self.startColumn.modules.edit.blocked = true;
  16703. // }
  16704. self.startY = typeof e.screenY === "undefined" ? e.touches[0].screenY : e.screenY;
  16705. self.startHeight = row.getHeight();
  16706. document.body.addEventListener("mousemove", mouseMove);
  16707. document.body.addEventListener("mouseup", mouseUp);
  16708. handle.addEventListener("touchmove", mouseMove, { passive: true });
  16709. handle.addEventListener("touchend", mouseUp);
  16710. };
  16711. Tabulator.prototype.registerModule("resizeRows", ResizeRows);
  16712. var ResizeTable = function ResizeTable(table) {
  16713. this.table = table; //hold Tabulator object
  16714. this.binding = false;
  16715. this.observer = false;
  16716. this.containerObserver = false;
  16717. this.tableHeight = 0;
  16718. this.tableWidth = 0;
  16719. this.containerHeight = 0;
  16720. this.containerWidth = 0;
  16721. this.autoResize = false;
  16722. };
  16723. ResizeTable.prototype.initialize = function (row) {
  16724. var _this82 = this;
  16725. var table = this.table,
  16726. tableStyle;
  16727. this.tableHeight = table.element.clientHeight;
  16728. this.tableWidth = table.element.clientWidth;
  16729. if (table.element.parentNode) {
  16730. this.containerHeight = table.element.parentNode.clientHeight;
  16731. this.containerWidth = table.element.parentNode.clientWidth;
  16732. }
  16733. if (typeof ResizeObserver !== "undefined" && table.rowManager.getRenderMode() === "virtual") {
  16734. this.autoResize = true;
  16735. this.observer = new ResizeObserver(function (entry) {
  16736. if (!table.browserMobile || table.browserMobile && !table.modules.edit.currentCell) {
  16737. var nodeHeight = Math.floor(entry[0].contentRect.height);
  16738. var nodeWidth = Math.floor(entry[0].contentRect.width);
  16739. if (_this82.tableHeight != nodeHeight || _this82.tableWidth != nodeWidth) {
  16740. _this82.tableHeight = nodeHeight;
  16741. _this82.tableWidth = nodeWidth;
  16742. if (table.element.parentNode) {
  16743. _this82.containerHeight = table.element.parentNode.clientHeight;
  16744. _this82.containerWidth = table.element.parentNode.clientWidth;
  16745. }
  16746. if (table.options.virtualDomHoz) {
  16747. table.vdomHoz.reinitialize(true);
  16748. }
  16749. table.redraw();
  16750. }
  16751. }
  16752. });
  16753. this.observer.observe(table.element);
  16754. tableStyle = window.getComputedStyle(table.element);
  16755. if (this.table.element.parentNode && !this.table.rowManager.fixedHeight && (tableStyle.getPropertyValue("max-height") || tableStyle.getPropertyValue("min-height"))) {
  16756. this.containerObserver = new ResizeObserver(function (entry) {
  16757. if (!table.browserMobile || table.browserMobile && !table.modules.edit.currentCell) {
  16758. var nodeHeight = Math.floor(entry[0].contentRect.height);
  16759. var nodeWidth = Math.floor(entry[0].contentRect.width);
  16760. if (_this82.containerHeight != nodeHeight || _this82.containerWidth != nodeWidth) {
  16761. _this82.containerHeight = nodeHeight;
  16762. _this82.containerWidth = nodeWidth;
  16763. _this82.tableHeight = table.element.clientHeight;
  16764. _this82.tableWidth = table.element.clientWidth;
  16765. }
  16766. if (table.options.virtualDomHoz) {
  16767. table.vdomHoz.reinitialize(true);
  16768. }
  16769. table.redraw();
  16770. }
  16771. });
  16772. this.containerObserver.observe(this.table.element.parentNode);
  16773. }
  16774. } else {
  16775. this.binding = function () {
  16776. if (!table.browserMobile || table.browserMobile && !table.modules.edit.currentCell) {
  16777. if (table.options.virtualDomHoz) {
  16778. table.vdomHoz.reinitialize(true);
  16779. }
  16780. table.redraw();
  16781. }
  16782. };
  16783. window.addEventListener("resize", this.binding);
  16784. }
  16785. };
  16786. ResizeTable.prototype.clearBindings = function (row) {
  16787. if (this.binding) {
  16788. window.removeEventListener("resize", this.binding);
  16789. }
  16790. if (this.observer) {
  16791. this.observer.unobserve(this.table.element);
  16792. }
  16793. if (this.containerObserver) {
  16794. this.containerObserver.unobserve(this.table.element.parentNode);
  16795. }
  16796. };
  16797. Tabulator.prototype.registerModule("resizeTable", ResizeTable);
  16798. var ResponsiveLayout = function ResponsiveLayout(table) {
  16799. this.table = table; //hold Tabulator object
  16800. this.columns = [];
  16801. this.hiddenColumns = [];
  16802. this.mode = "";
  16803. this.index = 0;
  16804. this.collapseFormatter = [];
  16805. this.collapseStartOpen = true;
  16806. this.collapseHandleColumn = false;
  16807. };
  16808. //generate resposive columns list
  16809. ResponsiveLayout.prototype.initialize = function () {
  16810. var self = this,
  16811. columns = [];
  16812. this.mode = this.table.options.responsiveLayout;
  16813. this.collapseFormatter = this.table.options.responsiveLayoutCollapseFormatter || this.formatCollapsedData;
  16814. this.collapseStartOpen = this.table.options.responsiveLayoutCollapseStartOpen;
  16815. this.hiddenColumns = [];
  16816. //detemine level of responsivity for each column
  16817. this.table.columnManager.columnsByIndex.forEach(function (column, i) {
  16818. if (column.modules.responsive) {
  16819. if (column.modules.responsive.order && column.modules.responsive.visible) {
  16820. column.modules.responsive.index = i;
  16821. columns.push(column);
  16822. if (!column.visible && self.mode === "collapse") {
  16823. self.hiddenColumns.push(column);
  16824. }
  16825. }
  16826. }
  16827. });
  16828. //sort list by responsivity
  16829. columns = columns.reverse();
  16830. columns = columns.sort(function (a, b) {
  16831. var diff = b.modules.responsive.order - a.modules.responsive.order;
  16832. return diff || b.modules.responsive.index - a.modules.responsive.index;
  16833. });
  16834. this.columns = columns;
  16835. if (this.mode === "collapse") {
  16836. this.generateCollapsedContent();
  16837. }
  16838. //assign collapse column
  16839. for (var _iterator = this.table.columnManager.columnsByIndex, _isArray = Array.isArray(_iterator), _i16 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
  16840. var _ref;
  16841. if (_isArray) {
  16842. if (_i16 >= _iterator.length) break;
  16843. _ref = _iterator[_i16++];
  16844. } else {
  16845. _i16 = _iterator.next();
  16846. if (_i16.done) break;
  16847. _ref = _i16.value;
  16848. }
  16849. var col = _ref;
  16850. if (col.definition.formatter == "responsiveCollapse") {
  16851. this.collapseHandleColumn = col;
  16852. break;
  16853. }
  16854. }
  16855. if (this.collapseHandleColumn) {
  16856. if (this.hiddenColumns.length) {
  16857. this.collapseHandleColumn.show();
  16858. } else {
  16859. this.collapseHandleColumn.hide();
  16860. }
  16861. }
  16862. };
  16863. //define layout information
  16864. ResponsiveLayout.prototype.initializeColumn = function (column) {
  16865. var def = column.getDefinition();
  16866. column.modules.responsive = { order: typeof def.responsive === "undefined" ? 1 : def.responsive, visible: def.visible === false ? false : true };
  16867. };
  16868. ResponsiveLayout.prototype.initializeRow = function (row) {
  16869. var el;
  16870. if (row.type !== "calc") {
  16871. el = document.createElement("div");
  16872. el.classList.add("tabulator-responsive-collapse");
  16873. row.modules.responsiveLayout = {
  16874. element: el,
  16875. open: this.collapseStartOpen
  16876. };
  16877. if (!this.collapseStartOpen) {
  16878. el.style.display = 'none';
  16879. }
  16880. }
  16881. };
  16882. ResponsiveLayout.prototype.layoutRow = function (row) {
  16883. var rowEl = row.getElement();
  16884. if (row.modules.responsiveLayout) {
  16885. rowEl.appendChild(row.modules.responsiveLayout.element);
  16886. this.generateCollapsedRowContent(row);
  16887. }
  16888. };
  16889. //update column visibility
  16890. ResponsiveLayout.prototype.updateColumnVisibility = function (column, visible) {
  16891. var index;
  16892. if (column.modules.responsive) {
  16893. column.modules.responsive.visible = visible;
  16894. this.initialize();
  16895. }
  16896. };
  16897. ResponsiveLayout.prototype.hideColumn = function (column) {
  16898. var colCount = this.hiddenColumns.length;
  16899. column.hide(false, true);
  16900. if (this.mode === "collapse") {
  16901. this.hiddenColumns.unshift(column);
  16902. this.generateCollapsedContent();
  16903. if (this.collapseHandleColumn && !colCount) {
  16904. this.collapseHandleColumn.show();
  16905. }
  16906. }
  16907. };
  16908. ResponsiveLayout.prototype.showColumn = function (column) {
  16909. var index;
  16910. column.show(false, true);
  16911. //set column width to prevent calculation loops on uninitialized columns
  16912. column.setWidth(column.getWidth());
  16913. if (this.mode === "collapse") {
  16914. index = this.hiddenColumns.indexOf(column);
  16915. if (index > -1) {
  16916. this.hiddenColumns.splice(index, 1);
  16917. }
  16918. this.generateCollapsedContent();
  16919. if (this.collapseHandleColumn && !this.hiddenColumns.length) {
  16920. this.collapseHandleColumn.hide();
  16921. }
  16922. }
  16923. };
  16924. //redraw columns to fit space
  16925. ResponsiveLayout.prototype.update = function () {
  16926. var self = this,
  16927. working = true;
  16928. while (working) {
  16929. var width = self.table.modules.layout.getMode() == "fitColumns" ? self.table.columnManager.getFlexBaseWidth() : self.table.columnManager.getWidth();
  16930. var diff = (self.table.options.headerVisible ? self.table.columnManager.element.clientWidth : self.table.element.clientWidth) - width;
  16931. if (diff < 0) {
  16932. //table is too wide
  16933. var column = self.columns[self.index];
  16934. if (column) {
  16935. self.hideColumn(column);
  16936. self.index++;
  16937. } else {
  16938. working = false;
  16939. }
  16940. } else {
  16941. //table has spare space
  16942. var _column = self.columns[self.index - 1];
  16943. if (_column) {
  16944. if (diff > 0) {
  16945. if (diff >= _column.getWidth()) {
  16946. self.showColumn(_column);
  16947. self.index--;
  16948. } else {
  16949. working = false;
  16950. }
  16951. } else {
  16952. working = false;
  16953. }
  16954. } else {
  16955. working = false;
  16956. }
  16957. }
  16958. if (!self.table.rowManager.activeRowsCount) {
  16959. self.table.rowManager.renderEmptyScroll();
  16960. }
  16961. }
  16962. };
  16963. ResponsiveLayout.prototype.generateCollapsedContent = function () {
  16964. var self = this,
  16965. rows = this.table.rowManager.getDisplayRows();
  16966. rows.forEach(function (row) {
  16967. self.generateCollapsedRowContent(row);
  16968. });
  16969. };
  16970. ResponsiveLayout.prototype.generateCollapsedRowContent = function (row) {
  16971. var el, contents;
  16972. if (row.modules.responsiveLayout) {
  16973. el = row.modules.responsiveLayout.element;
  16974. while (el.firstChild) {
  16975. el.removeChild(el.firstChild);
  16976. }contents = this.collapseFormatter(this.generateCollapsedRowData(row));
  16977. if (contents) {
  16978. el.appendChild(contents);
  16979. }
  16980. }
  16981. };
  16982. ResponsiveLayout.prototype.generateCollapsedRowData = function (row) {
  16983. var self = this,
  16984. data = row.getData(),
  16985. output = [],
  16986. mockCellComponent;
  16987. this.hiddenColumns.forEach(function (column) {
  16988. var value = column.getFieldValue(data);
  16989. if (column.definition.title && column.field) {
  16990. if (column.modules.format && self.table.options.responsiveLayoutCollapseUseFormatters) {
  16991. mockCellComponent = {
  16992. value: false,
  16993. data: {},
  16994. getValue: function getValue() {
  16995. return value;
  16996. },
  16997. getData: function getData() {
  16998. return data;
  16999. },
  17000. getElement: function getElement() {
  17001. return document.createElement("div");
  17002. },
  17003. getRow: function getRow() {
  17004. return row.getComponent();
  17005. },
  17006. getColumn: function getColumn() {
  17007. return column.getComponent();
  17008. }
  17009. };
  17010. output.push({
  17011. title: column.definition.title,
  17012. value: column.modules.format.formatter.call(self.table.modules.format, mockCellComponent, column.modules.format.params)
  17013. });
  17014. } else {
  17015. output.push({
  17016. title: column.definition.title,
  17017. value: value
  17018. });
  17019. }
  17020. }
  17021. });
  17022. return output;
  17023. };
  17024. ResponsiveLayout.prototype.formatCollapsedData = function (data) {
  17025. var list = document.createElement("table"),
  17026. listContents = "";
  17027. data.forEach(function (item) {
  17028. var div = document.createElement("div");
  17029. if (item.value instanceof Node) {
  17030. div.appendChild(item.value);
  17031. item.value = div.innerHTML;
  17032. }
  17033. listContents += "<tr><td><strong>" + item.title + "</strong></td><td>" + item.value + "</td></tr>";
  17034. });
  17035. list.innerHTML = listContents;
  17036. return Object.keys(data).length ? list : "";
  17037. };
  17038. Tabulator.prototype.registerModule("responsiveLayout", ResponsiveLayout);
  17039. var SelectRow = function SelectRow(table) {
  17040. this.table = table; //hold Tabulator object
  17041. this.selecting = false; //flag selecting in progress
  17042. this.lastClickedRow = false; //last clicked row
  17043. this.selectPrev = []; //hold previously selected element for drag drop selection
  17044. this.selectedRows = []; //hold selected rows
  17045. this.headerCheckboxElement = null; // hold header select element
  17046. };
  17047. SelectRow.prototype.clearSelectionData = function (silent) {
  17048. this.selecting = false;
  17049. this.lastClickedRow = false;
  17050. this.selectPrev = [];
  17051. this.selectedRows = [];
  17052. if (!silent) {
  17053. this._rowSelectionChanged();
  17054. }
  17055. };
  17056. SelectRow.prototype.initializeRow = function (row) {
  17057. var self = this,
  17058. element = row.getElement();
  17059. // trigger end of row selection
  17060. var endSelect = function endSelect() {
  17061. setTimeout(function () {
  17062. self.selecting = false;
  17063. }, 50);
  17064. document.body.removeEventListener("mouseup", endSelect);
  17065. };
  17066. row.modules.select = { selected: false };
  17067. //set row selection class
  17068. if (self.table.options.selectableCheck.call(this.table, row.getComponent())) {
  17069. element.classList.add("tabulator-selectable");
  17070. element.classList.remove("tabulator-unselectable");
  17071. if (self.table.options.selectable && self.table.options.selectable != "highlight") {
  17072. if (self.table.options.selectableRangeMode === "click") {
  17073. element.addEventListener("click", function (e) {
  17074. if (e.shiftKey) {
  17075. self.table._clearSelection();
  17076. self.lastClickedRow = self.lastClickedRow || row;
  17077. var lastClickedRowIdx = self.table.rowManager.getDisplayRowIndex(self.lastClickedRow);
  17078. var rowIdx = self.table.rowManager.getDisplayRowIndex(row);
  17079. var fromRowIdx = lastClickedRowIdx <= rowIdx ? lastClickedRowIdx : rowIdx;
  17080. var toRowIdx = lastClickedRowIdx >= rowIdx ? lastClickedRowIdx : rowIdx;
  17081. var rows = self.table.rowManager.getDisplayRows().slice(0);
  17082. var toggledRows = rows.splice(fromRowIdx, toRowIdx - fromRowIdx + 1);
  17083. if (e.ctrlKey || e.metaKey) {
  17084. toggledRows.forEach(function (toggledRow) {
  17085. if (toggledRow !== self.lastClickedRow) {
  17086. if (self.table.options.selectable !== true && !self.isRowSelected(row)) {
  17087. if (self.selectedRows.length < self.table.options.selectable) {
  17088. self.toggleRow(toggledRow);
  17089. }
  17090. } else {
  17091. self.toggleRow(toggledRow);
  17092. }
  17093. }
  17094. });
  17095. self.lastClickedRow = row;
  17096. } else {
  17097. self.deselectRows(undefined, true);
  17098. if (self.table.options.selectable !== true) {
  17099. if (toggledRows.length > self.table.options.selectable) {
  17100. toggledRows = toggledRows.slice(0, self.table.options.selectable);
  17101. }
  17102. }
  17103. self.selectRows(toggledRows);
  17104. }
  17105. self.table._clearSelection();
  17106. } else if (e.ctrlKey || e.metaKey) {
  17107. self.toggleRow(row);
  17108. self.lastClickedRow = row;
  17109. } else {
  17110. self.deselectRows(undefined, true);
  17111. self.selectRows(row);
  17112. self.lastClickedRow = row;
  17113. }
  17114. });
  17115. } else {
  17116. element.addEventListener("click", function (e) {
  17117. if (!self.table.modExists("edit") || !self.table.modules.edit.getCurrentCell()) {
  17118. self.table._clearSelection();
  17119. }
  17120. if (!self.selecting) {
  17121. self.toggleRow(row);
  17122. }
  17123. });
  17124. element.addEventListener("mousedown", function (e) {
  17125. if (e.shiftKey) {
  17126. self.table._clearSelection();
  17127. self.selecting = true;
  17128. self.selectPrev = [];
  17129. document.body.addEventListener("mouseup", endSelect);
  17130. document.body.addEventListener("keyup", endSelect);
  17131. self.toggleRow(row);
  17132. return false;
  17133. }
  17134. });
  17135. element.addEventListener("mouseenter", function (e) {
  17136. if (self.selecting) {
  17137. self.table._clearSelection();
  17138. self.toggleRow(row);
  17139. if (self.selectPrev[1] == row) {
  17140. self.toggleRow(self.selectPrev[0]);
  17141. }
  17142. }
  17143. });
  17144. element.addEventListener("mouseout", function (e) {
  17145. if (self.selecting) {
  17146. self.table._clearSelection();
  17147. self.selectPrev.unshift(row);
  17148. }
  17149. });
  17150. }
  17151. }
  17152. } else {
  17153. element.classList.add("tabulator-unselectable");
  17154. element.classList.remove("tabulator-selectable");
  17155. }
  17156. };
  17157. //toggle row selection
  17158. SelectRow.prototype.toggleRow = function (row) {
  17159. if (this.table.options.selectableCheck.call(this.table, row.getComponent())) {
  17160. if (row.modules.select && row.modules.select.selected) {
  17161. this._deselectRow(row);
  17162. } else {
  17163. this._selectRow(row);
  17164. }
  17165. }
  17166. };
  17167. //select a number of rows
  17168. SelectRow.prototype.selectRows = function (rows) {
  17169. var _this83 = this;
  17170. var rowMatch;
  17171. switch (typeof rows === 'undefined' ? 'undefined' : _typeof(rows)) {
  17172. case "undefined":
  17173. this.table.rowManager.rows.forEach(function (row) {
  17174. _this83._selectRow(row, true, true);
  17175. });
  17176. this._rowSelectionChanged();
  17177. break;
  17178. case "string":
  17179. rowMatch = this.table.rowManager.findRow(rows);
  17180. if (rowMatch) {
  17181. this._selectRow(rowMatch, true, true);
  17182. } else {
  17183. this.table.rowManager.getRows(rows).forEach(function (row) {
  17184. _this83._selectRow(row, true, true);
  17185. });
  17186. }
  17187. this._rowSelectionChanged();
  17188. break;
  17189. default:
  17190. if (Array.isArray(rows)) {
  17191. rows.forEach(function (row) {
  17192. _this83._selectRow(row, true, true);
  17193. });
  17194. this._rowSelectionChanged();
  17195. } else {
  17196. this._selectRow(rows, false, true);
  17197. }
  17198. break;
  17199. }
  17200. };
  17201. //select an individual row
  17202. SelectRow.prototype._selectRow = function (rowInfo, silent, force) {
  17203. var index;
  17204. //handle max row count
  17205. if (!isNaN(this.table.options.selectable) && this.table.options.selectable !== true && !force) {
  17206. if (this.selectedRows.length >= this.table.options.selectable) {
  17207. if (this.table.options.selectableRollingSelection) {
  17208. this._deselectRow(this.selectedRows[0]);
  17209. } else {
  17210. return false;
  17211. }
  17212. }
  17213. }
  17214. var row = this.table.rowManager.findRow(rowInfo);
  17215. if (row) {
  17216. if (this.selectedRows.indexOf(row) == -1) {
  17217. if (!row.modules.select) {
  17218. row.modules.select = {};
  17219. }
  17220. row.modules.select.selected = true;
  17221. if (row.modules.select.checkboxEl) {
  17222. row.modules.select.checkboxEl.checked = true;
  17223. }
  17224. row.getElement().classList.add("tabulator-selected");
  17225. this.selectedRows.push(row);
  17226. if (this.table.options.dataTreeSelectPropagate) {
  17227. this.childRowSelection(row, true);
  17228. }
  17229. if (!silent) {
  17230. this.table.options.rowSelected.call(this.table, row.getComponent());
  17231. }
  17232. this._rowSelectionChanged(silent);
  17233. }
  17234. } else {
  17235. if (!silent) {
  17236. console.warn("Selection Error - No such row found, ignoring selection:" + rowInfo);
  17237. }
  17238. }
  17239. };
  17240. SelectRow.prototype.isRowSelected = function (row) {
  17241. return this.selectedRows.indexOf(row) !== -1;
  17242. };
  17243. //deselect a number of rows
  17244. SelectRow.prototype.deselectRows = function (rows, silent) {
  17245. var self = this,
  17246. rowCount;
  17247. if (typeof rows == "undefined") {
  17248. rowCount = self.selectedRows.length;
  17249. for (var _i17 = 0; _i17 < rowCount; _i17++) {
  17250. self._deselectRow(self.selectedRows[0], true);
  17251. }
  17252. self._rowSelectionChanged(silent);
  17253. } else {
  17254. if (Array.isArray(rows)) {
  17255. rows.forEach(function (row) {
  17256. self._deselectRow(row, true);
  17257. });
  17258. self._rowSelectionChanged(silent);
  17259. } else {
  17260. self._deselectRow(rows, silent);
  17261. }
  17262. }
  17263. };
  17264. //deselect an individual row
  17265. SelectRow.prototype._deselectRow = function (rowInfo, silent) {
  17266. var self = this,
  17267. row = self.table.rowManager.findRow(rowInfo),
  17268. index;
  17269. if (row) {
  17270. index = self.selectedRows.findIndex(function (selectedRow) {
  17271. return selectedRow == row;
  17272. });
  17273. if (index > -1) {
  17274. if (!row.modules.select) {
  17275. row.modules.select = {};
  17276. }
  17277. row.modules.select.selected = false;
  17278. if (row.modules.select.checkboxEl) {
  17279. row.modules.select.checkboxEl.checked = false;
  17280. }
  17281. row.getElement().classList.remove("tabulator-selected");
  17282. self.selectedRows.splice(index, 1);
  17283. if (this.table.options.dataTreeSelectPropagate) {
  17284. this.childRowSelection(row, false);
  17285. }
  17286. if (!silent) {
  17287. self.table.options.rowDeselected.call(this.table, row.getComponent());
  17288. }
  17289. self._rowSelectionChanged(silent);
  17290. }
  17291. } else {
  17292. if (!silent) {
  17293. console.warn("Deselection Error - No such row found, ignoring selection:" + rowInfo);
  17294. }
  17295. }
  17296. };
  17297. SelectRow.prototype.getSelectedData = function () {
  17298. var data = [];
  17299. this.selectedRows.forEach(function (row) {
  17300. data.push(row.getData());
  17301. });
  17302. return data;
  17303. };
  17304. SelectRow.prototype.getSelectedRows = function () {
  17305. var rows = [];
  17306. this.selectedRows.forEach(function (row) {
  17307. rows.push(row.getComponent());
  17308. });
  17309. return rows;
  17310. };
  17311. SelectRow.prototype._rowSelectionChanged = function (silent) {
  17312. if (this.headerCheckboxElement) {
  17313. if (this.selectedRows.length === 0) {
  17314. this.headerCheckboxElement.checked = false;
  17315. this.headerCheckboxElement.indeterminate = false;
  17316. } else if (this.table.rowManager.rows.length === this.selectedRows.length) {
  17317. this.headerCheckboxElement.checked = true;
  17318. this.headerCheckboxElement.indeterminate = false;
  17319. } else {
  17320. this.headerCheckboxElement.indeterminate = true;
  17321. this.headerCheckboxElement.checked = false;
  17322. }
  17323. }
  17324. if (!silent) {
  17325. this.table.options.rowSelectionChanged.call(this.table, this.getSelectedData(), this.getSelectedRows());
  17326. }
  17327. };
  17328. SelectRow.prototype.registerRowSelectCheckbox = function (row, element) {
  17329. if (!row._row.modules.select) {
  17330. row._row.modules.select = {};
  17331. }
  17332. row._row.modules.select.checkboxEl = element;
  17333. };
  17334. SelectRow.prototype.registerHeaderSelectCheckbox = function (element) {
  17335. this.headerCheckboxElement = element;
  17336. };
  17337. SelectRow.prototype.childRowSelection = function (row, select) {
  17338. var children = this.table.modules.dataTree.getChildren(row);
  17339. if (select) {
  17340. for (var _iterator2 = children, _isArray2 = Array.isArray(_iterator2), _i18 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
  17341. var _ref2;
  17342. if (_isArray2) {
  17343. if (_i18 >= _iterator2.length) break;
  17344. _ref2 = _iterator2[_i18++];
  17345. } else {
  17346. _i18 = _iterator2.next();
  17347. if (_i18.done) break;
  17348. _ref2 = _i18.value;
  17349. }
  17350. var child = _ref2;
  17351. this._selectRow(child, true);
  17352. }
  17353. } else {
  17354. for (var _iterator3 = children, _isArray3 = Array.isArray(_iterator3), _i19 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
  17355. var _ref3;
  17356. if (_isArray3) {
  17357. if (_i19 >= _iterator3.length) break;
  17358. _ref3 = _iterator3[_i19++];
  17359. } else {
  17360. _i19 = _iterator3.next();
  17361. if (_i19.done) break;
  17362. _ref3 = _i19.value;
  17363. }
  17364. var _child = _ref3;
  17365. this._deselectRow(_child, true);
  17366. }
  17367. }
  17368. };
  17369. Tabulator.prototype.registerModule("selectRow", SelectRow);
  17370. var Sort = function Sort(table) {
  17371. this.table = table; //hold Tabulator object
  17372. this.sortList = []; //holder current sort
  17373. this.changed = false; //has the sort changed since last render
  17374. };
  17375. //initialize column header for sorting
  17376. Sort.prototype.initializeColumn = function (column, content) {
  17377. var self = this,
  17378. sorter = false,
  17379. colEl,
  17380. arrowEl;
  17381. switch (_typeof(column.definition.sorter)) {
  17382. case "string":
  17383. if (self.sorters[column.definition.sorter]) {
  17384. sorter = self.sorters[column.definition.sorter];
  17385. } else {
  17386. console.warn("Sort Error - No such sorter found: ", column.definition.sorter);
  17387. }
  17388. break;
  17389. case "function":
  17390. sorter = column.definition.sorter;
  17391. break;
  17392. }
  17393. column.modules.sort = {
  17394. sorter: sorter, dir: "none",
  17395. params: column.definition.sorterParams || {},
  17396. startingDir: column.definition.headerSortStartingDir || "asc",
  17397. tristate: typeof column.definition.headerSortTristate !== "undefined" ? column.definition.headerSortTristate : this.table.options.headerSortTristate
  17398. };
  17399. if (typeof column.definition.headerSort === "undefined" ? this.table.options.headerSort !== false : column.definition.headerSort !== false) {
  17400. colEl = column.getElement();
  17401. colEl.classList.add("tabulator-sortable");
  17402. arrowEl = document.createElement("div");
  17403. arrowEl.classList.add("tabulator-col-sorter");
  17404. if (_typeof(this.table.options.headerSortElement) == "object") {
  17405. arrowEl.appendChild(this.table.options.headerSortElement);
  17406. } else {
  17407. arrowEl.innerHTML = this.table.options.headerSortElement;
  17408. }
  17409. //create sorter arrow
  17410. content.appendChild(arrowEl);
  17411. column.modules.sort.element = arrowEl;
  17412. //sort on click
  17413. colEl.addEventListener("click", function (e) {
  17414. var dir = "",
  17415. sorters = [],
  17416. match = false;
  17417. if (column.modules.sort) {
  17418. if (column.modules.sort.tristate) {
  17419. if (column.modules.sort.dir == "none") {
  17420. dir = column.modules.sort.startingDir;
  17421. } else {
  17422. if (column.modules.sort.dir == column.modules.sort.startingDir) {
  17423. dir = column.modules.sort.dir == "asc" ? "desc" : "asc";
  17424. } else {
  17425. dir = "none";
  17426. }
  17427. }
  17428. } else {
  17429. switch (column.modules.sort.dir) {
  17430. case "asc":
  17431. dir = "desc";
  17432. break;
  17433. case "desc":
  17434. dir = "asc";
  17435. break;
  17436. default:
  17437. dir = column.modules.sort.startingDir;
  17438. }
  17439. }
  17440. if (self.table.options.columnHeaderSortMulti && (e.shiftKey || e.ctrlKey)) {
  17441. sorters = self.getSort();
  17442. match = sorters.findIndex(function (sorter) {
  17443. return sorter.field === column.getField();
  17444. });
  17445. if (match > -1) {
  17446. sorters[match].dir = dir;
  17447. if (match != sorters.length - 1) {
  17448. match = sorters.splice(match, 1)[0];
  17449. if (dir != "none") {
  17450. sorters.push(match);
  17451. }
  17452. }
  17453. } else {
  17454. if (dir != "none") {
  17455. sorters.push({ column: column, dir: dir });
  17456. }
  17457. }
  17458. //add to existing sort
  17459. self.setSort(sorters);
  17460. } else {
  17461. if (dir == "none") {
  17462. self.clear();
  17463. } else {
  17464. //sort by column only
  17465. self.setSort(column, dir);
  17466. }
  17467. }
  17468. self.table.rowManager.sorterRefresh(!self.sortList.length);
  17469. }
  17470. });
  17471. }
  17472. };
  17473. //check if the sorters have changed since last use
  17474. Sort.prototype.hasChanged = function () {
  17475. var changed = this.changed;
  17476. this.changed = false;
  17477. return changed;
  17478. };
  17479. //return current sorters
  17480. Sort.prototype.getSort = function () {
  17481. var self = this,
  17482. sorters = [];
  17483. self.sortList.forEach(function (item) {
  17484. if (item.column) {
  17485. sorters.push({ column: item.column.getComponent(), field: item.column.getField(), dir: item.dir });
  17486. }
  17487. });
  17488. return sorters;
  17489. };
  17490. //change sort list and trigger sort
  17491. Sort.prototype.setSort = function (sortList, dir) {
  17492. var self = this,
  17493. newSortList = [];
  17494. if (!Array.isArray(sortList)) {
  17495. sortList = [{ column: sortList, dir: dir }];
  17496. }
  17497. sortList.forEach(function (item) {
  17498. var column;
  17499. column = self.table.columnManager.findColumn(item.column);
  17500. if (column) {
  17501. item.column = column;
  17502. newSortList.push(item);
  17503. self.changed = true;
  17504. } else {
  17505. console.warn("Sort Warning - Sort field does not exist and is being ignored: ", item.column);
  17506. }
  17507. });
  17508. self.sortList = newSortList;
  17509. if (this.table.options.persistence && this.table.modExists("persistence", true) && this.table.modules.persistence.config.sort) {
  17510. this.table.modules.persistence.save("sort");
  17511. }
  17512. };
  17513. //clear sorters
  17514. Sort.prototype.clear = function () {
  17515. this.setSort([]);
  17516. };
  17517. //find appropriate sorter for column
  17518. Sort.prototype.findSorter = function (column) {
  17519. var row = this.table.rowManager.activeRows[0],
  17520. sorter = "string",
  17521. field,
  17522. value;
  17523. if (row) {
  17524. row = row.getData();
  17525. field = column.getField();
  17526. if (field) {
  17527. value = column.getFieldValue(row);
  17528. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  17529. case "undefined":
  17530. sorter = "string";
  17531. break;
  17532. case "boolean":
  17533. sorter = "boolean";
  17534. break;
  17535. default:
  17536. if (!isNaN(value) && value !== "") {
  17537. sorter = "number";
  17538. } else {
  17539. if (value.match(/((^[0-9]+[a-z]+)|(^[a-z]+[0-9]+))+$/i)) {
  17540. sorter = "alphanum";
  17541. }
  17542. }
  17543. break;
  17544. }
  17545. }
  17546. }
  17547. return this.sorters[sorter];
  17548. };
  17549. //work through sort list sorting data
  17550. Sort.prototype.sort = function (data) {
  17551. var self = this,
  17552. sortList = this.table.options.sortOrderReverse ? self.sortList.slice().reverse() : self.sortList,
  17553. sortListActual = [],
  17554. rowComponents = [],
  17555. lastSort;
  17556. if (self.table.options.dataSorting) {
  17557. self.table.options.dataSorting.call(self.table, self.getSort());
  17558. }
  17559. self.clearColumnHeaders();
  17560. if (!self.table.options.ajaxSorting) {
  17561. //build list of valid sorters and trigger column specific callbacks before sort begins
  17562. sortList.forEach(function (item, i) {
  17563. var sortObj = item.column.modules.sort;
  17564. if (item.column && sortObj) {
  17565. //if no sorter has been defined, take a guess
  17566. if (!sortObj.sorter) {
  17567. sortObj.sorter = self.findSorter(item.column);
  17568. }
  17569. item.params = typeof sortObj.params === "function" ? sortObj.params(item.column.getComponent(), item.dir) : sortObj.params;
  17570. sortListActual.push(item);
  17571. }
  17572. self.setColumnHeader(item.column, item.dir);
  17573. });
  17574. //sort data
  17575. if (sortListActual.length) {
  17576. self._sortItems(data, sortListActual);
  17577. }
  17578. } else {
  17579. sortList.forEach(function (item, i) {
  17580. self.setColumnHeader(item.column, item.dir);
  17581. });
  17582. }
  17583. if (self.table.options.dataSorted) {
  17584. data.forEach(function (row) {
  17585. rowComponents.push(row.getComponent());
  17586. });
  17587. self.table.options.dataSorted.call(self.table, self.getSort(), rowComponents);
  17588. }
  17589. };
  17590. //clear sort arrows on columns
  17591. Sort.prototype.clearColumnHeaders = function () {
  17592. this.table.columnManager.getRealColumns().forEach(function (column) {
  17593. if (column.modules.sort) {
  17594. column.modules.sort.dir = "none";
  17595. column.getElement().setAttribute("aria-sort", "none");
  17596. }
  17597. });
  17598. };
  17599. //set the column header sort direction
  17600. Sort.prototype.setColumnHeader = function (column, dir) {
  17601. column.modules.sort.dir = dir;
  17602. column.getElement().setAttribute("aria-sort", dir);
  17603. };
  17604. //sort each item in sort list
  17605. Sort.prototype._sortItems = function (data, sortList) {
  17606. var _this84 = this;
  17607. var sorterCount = sortList.length - 1;
  17608. data.sort(function (a, b) {
  17609. var result;
  17610. for (var i = sorterCount; i >= 0; i--) {
  17611. var sortItem = sortList[i];
  17612. result = _this84._sortRow(a, b, sortItem.column, sortItem.dir, sortItem.params);
  17613. if (result !== 0) {
  17614. break;
  17615. }
  17616. }
  17617. return result;
  17618. });
  17619. };
  17620. //process individual rows for a sort function on active data
  17621. Sort.prototype._sortRow = function (a, b, column, dir, params) {
  17622. var el1Comp, el2Comp, colComp;
  17623. //switch elements depending on search direction
  17624. var el1 = dir == "asc" ? a : b;
  17625. var el2 = dir == "asc" ? b : a;
  17626. a = column.getFieldValue(el1.getData());
  17627. b = column.getFieldValue(el2.getData());
  17628. a = typeof a !== "undefined" ? a : "";
  17629. b = typeof b !== "undefined" ? b : "";
  17630. el1Comp = el1.getComponent();
  17631. el2Comp = el2.getComponent();
  17632. return column.modules.sort.sorter.call(this, a, b, el1Comp, el2Comp, column.getComponent(), dir, params);
  17633. };
  17634. //default data sorters
  17635. Sort.prototype.sorters = {
  17636. //sort numbers
  17637. number: function number(a, b, aRow, bRow, column, dir, params) {
  17638. var alignEmptyValues = params.alignEmptyValues;
  17639. var decimal = params.decimalSeparator || ".";
  17640. var thousand = params.thousandSeparator || ",";
  17641. var emptyAlign = 0;
  17642. a = parseFloat(String(a).split(thousand).join("").split(decimal).join("."));
  17643. b = parseFloat(String(b).split(thousand).join("").split(decimal).join("."));
  17644. //handle non numeric values
  17645. if (isNaN(a)) {
  17646. emptyAlign = isNaN(b) ? 0 : -1;
  17647. } else if (isNaN(b)) {
  17648. emptyAlign = 1;
  17649. } else {
  17650. //compare valid values
  17651. return a - b;
  17652. }
  17653. //fix empty values in position
  17654. if (alignEmptyValues === "top" && dir === "desc" || alignEmptyValues === "bottom" && dir === "asc") {
  17655. emptyAlign *= -1;
  17656. }
  17657. return emptyAlign;
  17658. },
  17659. //sort strings
  17660. string: function string(a, b, aRow, bRow, column, dir, params) {
  17661. var alignEmptyValues = params.alignEmptyValues;
  17662. var emptyAlign = 0;
  17663. var locale;
  17664. //handle empty values
  17665. if (!a) {
  17666. emptyAlign = !b ? 0 : -1;
  17667. } else if (!b) {
  17668. emptyAlign = 1;
  17669. } else {
  17670. //compare valid values
  17671. switch (_typeof(params.locale)) {
  17672. case "boolean":
  17673. if (params.locale) {
  17674. locale = this.table.modules.localize.getLocale();
  17675. }
  17676. break;
  17677. case "string":
  17678. locale = params.locale;
  17679. break;
  17680. }
  17681. return String(a).toLowerCase().localeCompare(String(b).toLowerCase(), locale);
  17682. }
  17683. //fix empty values in position
  17684. if (alignEmptyValues === "top" && dir === "desc" || alignEmptyValues === "bottom" && dir === "asc") {
  17685. emptyAlign *= -1;
  17686. }
  17687. return emptyAlign;
  17688. },
  17689. //sort date
  17690. date: function date(a, b, aRow, bRow, column, dir, params) {
  17691. if (!params.format) {
  17692. params.format = "DD/MM/YYYY";
  17693. }
  17694. return this.sorters.datetime.call(this, a, b, aRow, bRow, column, dir, params);
  17695. },
  17696. //sort HH:mm formatted times
  17697. time: function time(a, b, aRow, bRow, column, dir, params) {
  17698. if (!params.format) {
  17699. params.format = "HH:mm";
  17700. }
  17701. return this.sorters.datetime.call(this, a, b, aRow, bRow, column, dir, params);
  17702. },
  17703. //sort datetime
  17704. datetime: function datetime(a, b, aRow, bRow, column, dir, params) {
  17705. var format = params.format || "DD/MM/YYYY HH:mm:ss",
  17706. alignEmptyValues = params.alignEmptyValues,
  17707. emptyAlign = 0;
  17708. if (typeof moment != "undefined") {
  17709. a = moment(a, format);
  17710. b = moment(b, format);
  17711. if (!a.isValid()) {
  17712. emptyAlign = !b.isValid() ? 0 : -1;
  17713. } else if (!b.isValid()) {
  17714. emptyAlign = 1;
  17715. } else {
  17716. //compare valid values
  17717. return a - b;
  17718. }
  17719. //fix empty values in position
  17720. if (alignEmptyValues === "top" && dir === "desc" || alignEmptyValues === "bottom" && dir === "asc") {
  17721. emptyAlign *= -1;
  17722. }
  17723. return emptyAlign;
  17724. } else {
  17725. console.error("Sort Error - 'datetime' sorter is dependant on moment.js");
  17726. }
  17727. },
  17728. //sort booleans
  17729. boolean: function boolean(a, b, aRow, bRow, column, dir, params) {
  17730. var el1 = a === true || a === "true" || a === "True" || a === 1 ? 1 : 0;
  17731. var el2 = b === true || b === "true" || b === "True" || b === 1 ? 1 : 0;
  17732. return el1 - el2;
  17733. },
  17734. //sort if element contains any data
  17735. array: function array(a, b, aRow, bRow, column, dir, params) {
  17736. var el1 = 0;
  17737. var el2 = 0;
  17738. var type = params.type || "length";
  17739. var alignEmptyValues = params.alignEmptyValues;
  17740. var emptyAlign = 0;
  17741. function calc(value) {
  17742. switch (type) {
  17743. case "length":
  17744. return value.length;
  17745. break;
  17746. case "sum":
  17747. return value.reduce(function (c, d) {
  17748. return c + d;
  17749. });
  17750. break;
  17751. case "max":
  17752. return Math.max.apply(null, value);
  17753. break;
  17754. case "min":
  17755. return Math.min.apply(null, value);
  17756. break;
  17757. case "avg":
  17758. return value.reduce(function (c, d) {
  17759. return c + d;
  17760. }) / value.length;
  17761. break;
  17762. }
  17763. }
  17764. //handle non array values
  17765. if (!Array.isArray(a)) {
  17766. alignEmptyValues = !Array.isArray(b) ? 0 : -1;
  17767. } else if (!Array.isArray(b)) {
  17768. alignEmptyValues = 1;
  17769. } else {
  17770. //compare valid values
  17771. el1 = a ? calc(a) : 0;
  17772. el2 = b ? calc(b) : 0;
  17773. return el1 - el2;
  17774. }
  17775. //fix empty values in position
  17776. if (alignEmptyValues === "top" && dir === "desc" || alignEmptyValues === "bottom" && dir === "asc") {
  17777. emptyAlign *= -1;
  17778. }
  17779. return emptyAlign;
  17780. },
  17781. //sort if element contains any data
  17782. exists: function exists(a, b, aRow, bRow, column, dir, params) {
  17783. var el1 = typeof a == "undefined" ? 0 : 1;
  17784. var el2 = typeof b == "undefined" ? 0 : 1;
  17785. return el1 - el2;
  17786. },
  17787. //sort alpha numeric strings
  17788. alphanum: function alphanum(as, bs, aRow, bRow, column, dir, params) {
  17789. var a,
  17790. b,
  17791. a1,
  17792. b1,
  17793. i = 0,
  17794. L,
  17795. rx = /(\d+)|(\D+)/g,
  17796. rd = /\d/;
  17797. var alignEmptyValues = params.alignEmptyValues;
  17798. var emptyAlign = 0;
  17799. //handle empty values
  17800. if (!as && as !== 0) {
  17801. emptyAlign = !bs && bs !== 0 ? 0 : -1;
  17802. } else if (!bs && bs !== 0) {
  17803. emptyAlign = 1;
  17804. } else {
  17805. if (isFinite(as) && isFinite(bs)) return as - bs;
  17806. a = String(as).toLowerCase();
  17807. b = String(bs).toLowerCase();
  17808. if (a === b) return 0;
  17809. if (!(rd.test(a) && rd.test(b))) return a > b ? 1 : -1;
  17810. a = a.match(rx);
  17811. b = b.match(rx);
  17812. L = a.length > b.length ? b.length : a.length;
  17813. while (i < L) {
  17814. a1 = a[i];
  17815. b1 = b[i++];
  17816. if (a1 !== b1) {
  17817. if (isFinite(a1) && isFinite(b1)) {
  17818. if (a1.charAt(0) === "0") a1 = "." + a1;
  17819. if (b1.charAt(0) === "0") b1 = "." + b1;
  17820. return a1 - b1;
  17821. } else return a1 > b1 ? 1 : -1;
  17822. }
  17823. }
  17824. return a.length > b.length;
  17825. }
  17826. //fix empty values in position
  17827. if (alignEmptyValues === "top" && dir === "desc" || alignEmptyValues === "bottom" && dir === "asc") {
  17828. emptyAlign *= -1;
  17829. }
  17830. return emptyAlign;
  17831. }
  17832. };
  17833. Tabulator.prototype.registerModule("sort", Sort);
  17834. var Validate = function Validate(table) {
  17835. this.table = table;
  17836. this.invalidCells = [];
  17837. };
  17838. //validate
  17839. Validate.prototype.initializeColumn = function (column) {
  17840. var self = this,
  17841. config = [],
  17842. validator;
  17843. if (column.definition.validator) {
  17844. if (Array.isArray(column.definition.validator)) {
  17845. column.definition.validator.forEach(function (item) {
  17846. validator = self._extractValidator(item);
  17847. if (validator) {
  17848. config.push(validator);
  17849. }
  17850. });
  17851. } else {
  17852. validator = this._extractValidator(column.definition.validator);
  17853. if (validator) {
  17854. config.push(validator);
  17855. }
  17856. }
  17857. column.modules.validate = config.length ? config : false;
  17858. }
  17859. };
  17860. Validate.prototype._extractValidator = function (value) {
  17861. var type, params, pos;
  17862. switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) {
  17863. case "string":
  17864. pos = value.indexOf(':');
  17865. if (pos > -1) {
  17866. type = value.substring(0, pos);
  17867. params = value.substring(pos + 1);
  17868. } else {
  17869. type = value;
  17870. }
  17871. return this._buildValidator(type, params);
  17872. break;
  17873. case "function":
  17874. return this._buildValidator(value);
  17875. break;
  17876. case "object":
  17877. return this._buildValidator(value.type, value.parameters);
  17878. break;
  17879. }
  17880. };
  17881. Validate.prototype._buildValidator = function (type, params) {
  17882. var func = typeof type == "function" ? type : this.validators[type];
  17883. if (!func) {
  17884. console.warn("Validator Setup Error - No matching validator found:", type);
  17885. return false;
  17886. } else {
  17887. return {
  17888. type: typeof type == "function" ? "function" : type,
  17889. func: func,
  17890. params: params
  17891. };
  17892. }
  17893. };
  17894. Validate.prototype.validate = function (validators, cell, value) {
  17895. var self = this,
  17896. valid = [],
  17897. invalidIndex = this.invalidCells.indexOf(cell);
  17898. if (validators) {
  17899. validators.forEach(function (item) {
  17900. if (!item.func.call(self, cell.getComponent(), value, item.params)) {
  17901. valid.push({
  17902. type: item.type,
  17903. parameters: item.params
  17904. });
  17905. }
  17906. });
  17907. }
  17908. valid = valid.length ? valid : true;
  17909. if (!cell.modules.validate) {
  17910. cell.modules.validate = {};
  17911. }
  17912. if (valid === true) {
  17913. cell.modules.validate.invalid = false;
  17914. cell.getElement().classList.remove("tabulator-validation-fail");
  17915. if (invalidIndex > -1) {
  17916. this.invalidCells.splice(invalidIndex, 1);
  17917. }
  17918. } else {
  17919. cell.modules.validate.invalid = true;
  17920. if (this.table.options.validationMode !== "manual") {
  17921. cell.getElement().classList.add("tabulator-validation-fail");
  17922. }
  17923. if (invalidIndex == -1) {
  17924. this.invalidCells.push(cell);
  17925. }
  17926. }
  17927. return valid;
  17928. };
  17929. Validate.prototype.getInvalidCells = function () {
  17930. var output = [];
  17931. this.invalidCells.forEach(function (cell) {
  17932. output.push(cell.getComponent());
  17933. });
  17934. return output;
  17935. };
  17936. Validate.prototype.clearValidation = function (cell) {
  17937. var invalidIndex;
  17938. if (cell.modules.validate && cell.modules.validate.invalid) {
  17939. cell.getElement().classList.remove("tabulator-validation-fail");
  17940. cell.modules.validate.invalid = false;
  17941. invalidIndex = this.invalidCells.indexOf(cell);
  17942. if (invalidIndex > -1) {
  17943. this.invalidCells.splice(invalidIndex, 1);
  17944. }
  17945. }
  17946. };
  17947. Validate.prototype.validators = {
  17948. //is integer
  17949. integer: function integer(cell, value, parameters) {
  17950. if (value === "" || value === null || typeof value === "undefined") {
  17951. return true;
  17952. }
  17953. value = Number(value);
  17954. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  17955. },
  17956. //is float
  17957. float: function float(cell, value, parameters) {
  17958. if (value === "" || value === null || typeof value === "undefined") {
  17959. return true;
  17960. }
  17961. value = Number(value);
  17962. return typeof value === 'number' && isFinite(value) && value % 1 !== 0;
  17963. },
  17964. //must be a number
  17965. numeric: function numeric(cell, value, parameters) {
  17966. if (value === "" || value === null || typeof value === "undefined") {
  17967. return true;
  17968. }
  17969. return !isNaN(value);
  17970. },
  17971. //must be a string
  17972. string: function string(cell, value, parameters) {
  17973. if (value === "" || value === null || typeof value === "undefined") {
  17974. return true;
  17975. }
  17976. return isNaN(value);
  17977. },
  17978. //maximum value
  17979. max: function max(cell, value, parameters) {
  17980. if (value === "" || value === null || typeof value === "undefined") {
  17981. return true;
  17982. }
  17983. return parseFloat(value) <= parameters;
  17984. },
  17985. //minimum value
  17986. min: function min(cell, value, parameters) {
  17987. if (value === "" || value === null || typeof value === "undefined") {
  17988. return true;
  17989. }
  17990. return parseFloat(value) >= parameters;
  17991. },
  17992. //starts with value
  17993. starts: function starts(cell, value, parameters) {
  17994. if (value === "" || value === null || typeof value === "undefined") {
  17995. return true;
  17996. }
  17997. return String(value).toLowerCase().startsWith(String(parameters).toLowerCase());
  17998. },
  17999. //ends with value
  18000. ends: function ends(cell, value, parameters) {
  18001. if (value === "" || value === null || typeof value === "undefined") {
  18002. return true;
  18003. }
  18004. return String(value).toLowerCase().endsWith(String(parameters).toLowerCase());
  18005. },
  18006. //minimum string length
  18007. minLength: function minLength(cell, value, parameters) {
  18008. if (value === "" || value === null || typeof value === "undefined") {
  18009. return true;
  18010. }
  18011. return String(value).length >= parameters;
  18012. },
  18013. //maximum string length
  18014. maxLength: function maxLength(cell, value, parameters) {
  18015. if (value === "" || value === null || typeof value === "undefined") {
  18016. return true;
  18017. }
  18018. return String(value).length <= parameters;
  18019. },
  18020. //in provided value list
  18021. in: function _in(cell, value, parameters) {
  18022. if (value === "" || value === null || typeof value === "undefined") {
  18023. return true;
  18024. }
  18025. if (typeof parameters == "string") {
  18026. parameters = parameters.split("|");
  18027. }
  18028. return value === "" || parameters.indexOf(value) > -1;
  18029. },
  18030. //must match provided regex
  18031. regex: function regex(cell, value, parameters) {
  18032. if (value === "" || value === null || typeof value === "undefined") {
  18033. return true;
  18034. }
  18035. var reg = new RegExp(parameters);
  18036. return reg.test(value);
  18037. },
  18038. //value must be unique in this column
  18039. unique: function unique(cell, value, parameters) {
  18040. if (value === "" || value === null || typeof value === "undefined") {
  18041. return true;
  18042. }
  18043. var unique = true;
  18044. var cellData = cell.getData();
  18045. var column = cell.getColumn()._getSelf();
  18046. this.table.rowManager.rows.forEach(function (row) {
  18047. var data = row.getData();
  18048. if (data !== cellData) {
  18049. if (value == column.getFieldValue(data)) {
  18050. unique = false;
  18051. }
  18052. }
  18053. });
  18054. return unique;
  18055. },
  18056. //must have a value
  18057. required: function required(cell, value, parameters) {
  18058. return value !== "" && value !== null && typeof value !== "undefined";
  18059. }
  18060. };
  18061. Tabulator.prototype.registerModule("validate", Validate);
  18062. return Tabulator;
  18063. });