Нема описа

jquery.dataTables.mjs 428KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649
  1. /*! DataTables 1.13.5
  2. * ©2008-2023 SpryMedia Ltd - datatables.net/license
  3. */
  4. import jQuery from 'jquery';
  5. // DataTables code uses $ internally, but we want to be able to
  6. // reassign $ with the `use` method, so it is a regular var.
  7. var $ = jQuery;
  8. var DataTable = function ( selector, options )
  9. {
  10. // Check if called with a window or jQuery object for DOM less applications
  11. // This is for backwards compatibility
  12. if (DataTable.factory(selector, options)) {
  13. return DataTable;
  14. }
  15. // When creating with `new`, create a new DataTable, returning the API instance
  16. if (this instanceof DataTable) {
  17. return $(selector).DataTable(options);
  18. }
  19. else {
  20. // Argument switching
  21. options = selector;
  22. }
  23. /**
  24. * Perform a jQuery selector action on the table's TR elements (from the tbody) and
  25. * return the resulting jQuery object.
  26. * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
  27. * @param {object} [oOpts] Optional parameters for modifying the rows to be included
  28. * @param {string} [oOpts.filter=none] Select TR elements that meet the current filter
  29. * criterion ("applied") or all TR elements (i.e. no filter).
  30. * @param {string} [oOpts.order=current] Order of the TR elements in the processed array.
  31. * Can be either 'current', whereby the current sorting of the table is used, or
  32. * 'original' whereby the original order the data was read into the table is used.
  33. * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
  34. * ("current") or not ("all"). If 'current' is given, then order is assumed to be
  35. * 'current' and filter is 'applied', regardless of what they might be given as.
  36. * @returns {object} jQuery object, filtered by the given selector.
  37. * @dtopt API
  38. * @deprecated Since v1.10
  39. *
  40. * @example
  41. * $(document).ready(function() {
  42. * var oTable = $('#example').dataTable();
  43. *
  44. * // Highlight every second row
  45. * oTable.$('tr:odd').css('backgroundColor', 'blue');
  46. * } );
  47. *
  48. * @example
  49. * $(document).ready(function() {
  50. * var oTable = $('#example').dataTable();
  51. *
  52. * // Filter to rows with 'Webkit' in them, add a background colour and then
  53. * // remove the filter, thus highlighting the 'Webkit' rows only.
  54. * oTable.fnFilter('Webkit');
  55. * oTable.$('tr', {"search": "applied"}).css('backgroundColor', 'blue');
  56. * oTable.fnFilter('');
  57. * } );
  58. */
  59. this.$ = function ( sSelector, oOpts )
  60. {
  61. return this.api(true).$( sSelector, oOpts );
  62. };
  63. /**
  64. * Almost identical to $ in operation, but in this case returns the data for the matched
  65. * rows - as such, the jQuery selector used should match TR row nodes or TD/TH cell nodes
  66. * rather than any descendants, so the data can be obtained for the row/cell. If matching
  67. * rows are found, the data returned is the original data array/object that was used to
  68. * create the row (or a generated array if from a DOM source).
  69. *
  70. * This method is often useful in-combination with $ where both functions are given the
  71. * same parameters and the array indexes will match identically.
  72. * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
  73. * @param {object} [oOpts] Optional parameters for modifying the rows to be included
  74. * @param {string} [oOpts.filter=none] Select elements that meet the current filter
  75. * criterion ("applied") or all elements (i.e. no filter).
  76. * @param {string} [oOpts.order=current] Order of the data in the processed array.
  77. * Can be either 'current', whereby the current sorting of the table is used, or
  78. * 'original' whereby the original order the data was read into the table is used.
  79. * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
  80. * ("current") or not ("all"). If 'current' is given, then order is assumed to be
  81. * 'current' and filter is 'applied', regardless of what they might be given as.
  82. * @returns {array} Data for the matched elements. If any elements, as a result of the
  83. * selector, were not TR, TD or TH elements in the DataTable, they will have a null
  84. * entry in the array.
  85. * @dtopt API
  86. * @deprecated Since v1.10
  87. *
  88. * @example
  89. * $(document).ready(function() {
  90. * var oTable = $('#example').dataTable();
  91. *
  92. * // Get the data from the first row in the table
  93. * var data = oTable._('tr:first');
  94. *
  95. * // Do something useful with the data
  96. * alert( "First cell is: "+data[0] );
  97. * } );
  98. *
  99. * @example
  100. * $(document).ready(function() {
  101. * var oTable = $('#example').dataTable();
  102. *
  103. * // Filter to 'Webkit' and get all data for
  104. * oTable.fnFilter('Webkit');
  105. * var data = oTable._('tr', {"search": "applied"});
  106. *
  107. * // Do something with the data
  108. * alert( data.length+" rows matched the search" );
  109. * } );
  110. */
  111. this._ = function ( sSelector, oOpts )
  112. {
  113. return this.api(true).rows( sSelector, oOpts ).data();
  114. };
  115. /**
  116. * Create a DataTables Api instance, with the currently selected tables for
  117. * the Api's context.
  118. * @param {boolean} [traditional=false] Set the API instance's context to be
  119. * only the table referred to by the `DataTable.ext.iApiIndex` option, as was
  120. * used in the API presented by DataTables 1.9- (i.e. the traditional mode),
  121. * or if all tables captured in the jQuery object should be used.
  122. * @return {DataTables.Api}
  123. */
  124. this.api = function ( traditional )
  125. {
  126. return traditional ?
  127. new _Api(
  128. _fnSettingsFromNode( this[ _ext.iApiIndex ] )
  129. ) :
  130. new _Api( this );
  131. };
  132. /**
  133. * Add a single new row or multiple rows of data to the table. Please note
  134. * that this is suitable for client-side processing only - if you are using
  135. * server-side processing (i.e. "bServerSide": true), then to add data, you
  136. * must add it to the data source, i.e. the server-side, through an Ajax call.
  137. * @param {array|object} data The data to be added to the table. This can be:
  138. * <ul>
  139. * <li>1D array of data - add a single row with the data provided</li>
  140. * <li>2D array of arrays - add multiple rows in a single call</li>
  141. * <li>object - data object when using <i>mData</i></li>
  142. * <li>array of objects - multiple data objects when using <i>mData</i></li>
  143. * </ul>
  144. * @param {bool} [redraw=true] redraw the table or not
  145. * @returns {array} An array of integers, representing the list of indexes in
  146. * <i>aoData</i> ({@link DataTable.models.oSettings}) that have been added to
  147. * the table.
  148. * @dtopt API
  149. * @deprecated Since v1.10
  150. *
  151. * @example
  152. * // Global var for counter
  153. * var giCount = 2;
  154. *
  155. * $(document).ready(function() {
  156. * $('#example').dataTable();
  157. * } );
  158. *
  159. * function fnClickAddRow() {
  160. * $('#example').dataTable().fnAddData( [
  161. * giCount+".1",
  162. * giCount+".2",
  163. * giCount+".3",
  164. * giCount+".4" ]
  165. * );
  166. *
  167. * giCount++;
  168. * }
  169. */
  170. this.fnAddData = function( data, redraw )
  171. {
  172. var api = this.api( true );
  173. /* Check if we want to add multiple rows or not */
  174. var rows = Array.isArray(data) && ( Array.isArray(data[0]) || $.isPlainObject(data[0]) ) ?
  175. api.rows.add( data ) :
  176. api.row.add( data );
  177. if ( redraw === undefined || redraw ) {
  178. api.draw();
  179. }
  180. return rows.flatten().toArray();
  181. };
  182. /**
  183. * This function will make DataTables recalculate the column sizes, based on the data
  184. * contained in the table and the sizes applied to the columns (in the DOM, CSS or
  185. * through the sWidth parameter). This can be useful when the width of the table's
  186. * parent element changes (for example a window resize).
  187. * @param {boolean} [bRedraw=true] Redraw the table or not, you will typically want to
  188. * @dtopt API
  189. * @deprecated Since v1.10
  190. *
  191. * @example
  192. * $(document).ready(function() {
  193. * var oTable = $('#example').dataTable( {
  194. * "sScrollY": "200px",
  195. * "bPaginate": false
  196. * } );
  197. *
  198. * $(window).on('resize', function () {
  199. * oTable.fnAdjustColumnSizing();
  200. * } );
  201. * } );
  202. */
  203. this.fnAdjustColumnSizing = function ( bRedraw )
  204. {
  205. var api = this.api( true ).columns.adjust();
  206. var settings = api.settings()[0];
  207. var scroll = settings.oScroll;
  208. if ( bRedraw === undefined || bRedraw ) {
  209. api.draw( false );
  210. }
  211. else if ( scroll.sX !== "" || scroll.sY !== "" ) {
  212. /* If not redrawing, but scrolling, we want to apply the new column sizes anyway */
  213. _fnScrollDraw( settings );
  214. }
  215. };
  216. /**
  217. * Quickly and simply clear a table
  218. * @param {bool} [bRedraw=true] redraw the table or not
  219. * @dtopt API
  220. * @deprecated Since v1.10
  221. *
  222. * @example
  223. * $(document).ready(function() {
  224. * var oTable = $('#example').dataTable();
  225. *
  226. * // Immediately 'nuke' the current rows (perhaps waiting for an Ajax callback...)
  227. * oTable.fnClearTable();
  228. * } );
  229. */
  230. this.fnClearTable = function( bRedraw )
  231. {
  232. var api = this.api( true ).clear();
  233. if ( bRedraw === undefined || bRedraw ) {
  234. api.draw();
  235. }
  236. };
  237. /**
  238. * The exact opposite of 'opening' a row, this function will close any rows which
  239. * are currently 'open'.
  240. * @param {node} nTr the table row to 'close'
  241. * @returns {int} 0 on success, or 1 if failed (can't find the row)
  242. * @dtopt API
  243. * @deprecated Since v1.10
  244. *
  245. * @example
  246. * $(document).ready(function() {
  247. * var oTable;
  248. *
  249. * // 'open' an information row when a row is clicked on
  250. * $('#example tbody tr').click( function () {
  251. * if ( oTable.fnIsOpen(this) ) {
  252. * oTable.fnClose( this );
  253. * } else {
  254. * oTable.fnOpen( this, "Temporary row opened", "info_row" );
  255. * }
  256. * } );
  257. *
  258. * oTable = $('#example').dataTable();
  259. * } );
  260. */
  261. this.fnClose = function( nTr )
  262. {
  263. this.api( true ).row( nTr ).child.hide();
  264. };
  265. /**
  266. * Remove a row for the table
  267. * @param {mixed} target The index of the row from aoData to be deleted, or
  268. * the TR element you want to delete
  269. * @param {function|null} [callBack] Callback function
  270. * @param {bool} [redraw=true] Redraw the table or not
  271. * @returns {array} The row that was deleted
  272. * @dtopt API
  273. * @deprecated Since v1.10
  274. *
  275. * @example
  276. * $(document).ready(function() {
  277. * var oTable = $('#example').dataTable();
  278. *
  279. * // Immediately remove the first row
  280. * oTable.fnDeleteRow( 0 );
  281. * } );
  282. */
  283. this.fnDeleteRow = function( target, callback, redraw )
  284. {
  285. var api = this.api( true );
  286. var rows = api.rows( target );
  287. var settings = rows.settings()[0];
  288. var data = settings.aoData[ rows[0][0] ];
  289. rows.remove();
  290. if ( callback ) {
  291. callback.call( this, settings, data );
  292. }
  293. if ( redraw === undefined || redraw ) {
  294. api.draw();
  295. }
  296. return data;
  297. };
  298. /**
  299. * Restore the table to it's original state in the DOM by removing all of DataTables
  300. * enhancements, alterations to the DOM structure of the table and event listeners.
  301. * @param {boolean} [remove=false] Completely remove the table from the DOM
  302. * @dtopt API
  303. * @deprecated Since v1.10
  304. *
  305. * @example
  306. * $(document).ready(function() {
  307. * // This example is fairly pointless in reality, but shows how fnDestroy can be used
  308. * var oTable = $('#example').dataTable();
  309. * oTable.fnDestroy();
  310. * } );
  311. */
  312. this.fnDestroy = function ( remove )
  313. {
  314. this.api( true ).destroy( remove );
  315. };
  316. /**
  317. * Redraw the table
  318. * @param {bool} [complete=true] Re-filter and resort (if enabled) the table before the draw.
  319. * @dtopt API
  320. * @deprecated Since v1.10
  321. *
  322. * @example
  323. * $(document).ready(function() {
  324. * var oTable = $('#example').dataTable();
  325. *
  326. * // Re-draw the table - you wouldn't want to do it here, but it's an example :-)
  327. * oTable.fnDraw();
  328. * } );
  329. */
  330. this.fnDraw = function( complete )
  331. {
  332. // Note that this isn't an exact match to the old call to _fnDraw - it takes
  333. // into account the new data, but can hold position.
  334. this.api( true ).draw( complete );
  335. };
  336. /**
  337. * Filter the input based on data
  338. * @param {string} sInput String to filter the table on
  339. * @param {int|null} [iColumn] Column to limit filtering to
  340. * @param {bool} [bRegex=false] Treat as regular expression or not
  341. * @param {bool} [bSmart=true] Perform smart filtering or not
  342. * @param {bool} [bShowGlobal=true] Show the input global filter in it's input box(es)
  343. * @param {bool} [bCaseInsensitive=true] Do case-insensitive matching (true) or not (false)
  344. * @dtopt API
  345. * @deprecated Since v1.10
  346. *
  347. * @example
  348. * $(document).ready(function() {
  349. * var oTable = $('#example').dataTable();
  350. *
  351. * // Sometime later - filter...
  352. * oTable.fnFilter( 'test string' );
  353. * } );
  354. */
  355. this.fnFilter = function( sInput, iColumn, bRegex, bSmart, bShowGlobal, bCaseInsensitive )
  356. {
  357. var api = this.api( true );
  358. if ( iColumn === null || iColumn === undefined ) {
  359. api.search( sInput, bRegex, bSmart, bCaseInsensitive );
  360. }
  361. else {
  362. api.column( iColumn ).search( sInput, bRegex, bSmart, bCaseInsensitive );
  363. }
  364. api.draw();
  365. };
  366. /**
  367. * Get the data for the whole table, an individual row or an individual cell based on the
  368. * provided parameters.
  369. * @param {int|node} [src] A TR row node, TD/TH cell node or an integer. If given as
  370. * a TR node then the data source for the whole row will be returned. If given as a
  371. * TD/TH cell node then iCol will be automatically calculated and the data for the
  372. * cell returned. If given as an integer, then this is treated as the aoData internal
  373. * data index for the row (see fnGetPosition) and the data for that row used.
  374. * @param {int} [col] Optional column index that you want the data of.
  375. * @returns {array|object|string} If mRow is undefined, then the data for all rows is
  376. * returned. If mRow is defined, just data for that row, and is iCol is
  377. * defined, only data for the designated cell is returned.
  378. * @dtopt API
  379. * @deprecated Since v1.10
  380. *
  381. * @example
  382. * // Row data
  383. * $(document).ready(function() {
  384. * oTable = $('#example').dataTable();
  385. *
  386. * oTable.$('tr').click( function () {
  387. * var data = oTable.fnGetData( this );
  388. * // ... do something with the array / object of data for the row
  389. * } );
  390. * } );
  391. *
  392. * @example
  393. * // Individual cell data
  394. * $(document).ready(function() {
  395. * oTable = $('#example').dataTable();
  396. *
  397. * oTable.$('td').click( function () {
  398. * var sData = oTable.fnGetData( this );
  399. * alert( 'The cell clicked on had the value of '+sData );
  400. * } );
  401. * } );
  402. */
  403. this.fnGetData = function( src, col )
  404. {
  405. var api = this.api( true );
  406. if ( src !== undefined ) {
  407. var type = src.nodeName ? src.nodeName.toLowerCase() : '';
  408. return col !== undefined || type == 'td' || type == 'th' ?
  409. api.cell( src, col ).data() :
  410. api.row( src ).data() || null;
  411. }
  412. return api.data().toArray();
  413. };
  414. /**
  415. * Get an array of the TR nodes that are used in the table's body. Note that you will
  416. * typically want to use the '$' API method in preference to this as it is more
  417. * flexible.
  418. * @param {int} [iRow] Optional row index for the TR element you want
  419. * @returns {array|node} If iRow is undefined, returns an array of all TR elements
  420. * in the table's body, or iRow is defined, just the TR element requested.
  421. * @dtopt API
  422. * @deprecated Since v1.10
  423. *
  424. * @example
  425. * $(document).ready(function() {
  426. * var oTable = $('#example').dataTable();
  427. *
  428. * // Get the nodes from the table
  429. * var nNodes = oTable.fnGetNodes( );
  430. * } );
  431. */
  432. this.fnGetNodes = function( iRow )
  433. {
  434. var api = this.api( true );
  435. return iRow !== undefined ?
  436. api.row( iRow ).node() :
  437. api.rows().nodes().flatten().toArray();
  438. };
  439. /**
  440. * Get the array indexes of a particular cell from it's DOM element
  441. * and column index including hidden columns
  442. * @param {node} node this can either be a TR, TD or TH in the table's body
  443. * @returns {int} If nNode is given as a TR, then a single index is returned, or
  444. * if given as a cell, an array of [row index, column index (visible),
  445. * column index (all)] is given.
  446. * @dtopt API
  447. * @deprecated Since v1.10
  448. *
  449. * @example
  450. * $(document).ready(function() {
  451. * $('#example tbody td').click( function () {
  452. * // Get the position of the current data from the node
  453. * var aPos = oTable.fnGetPosition( this );
  454. *
  455. * // Get the data array for this row
  456. * var aData = oTable.fnGetData( aPos[0] );
  457. *
  458. * // Update the data array and return the value
  459. * aData[ aPos[1] ] = 'clicked';
  460. * this.innerHTML = 'clicked';
  461. * } );
  462. *
  463. * // Init DataTables
  464. * oTable = $('#example').dataTable();
  465. * } );
  466. */
  467. this.fnGetPosition = function( node )
  468. {
  469. var api = this.api( true );
  470. var nodeName = node.nodeName.toUpperCase();
  471. if ( nodeName == 'TR' ) {
  472. return api.row( node ).index();
  473. }
  474. else if ( nodeName == 'TD' || nodeName == 'TH' ) {
  475. var cell = api.cell( node ).index();
  476. return [
  477. cell.row,
  478. cell.columnVisible,
  479. cell.column
  480. ];
  481. }
  482. return null;
  483. };
  484. /**
  485. * Check to see if a row is 'open' or not.
  486. * @param {node} nTr the table row to check
  487. * @returns {boolean} true if the row is currently open, false otherwise
  488. * @dtopt API
  489. * @deprecated Since v1.10
  490. *
  491. * @example
  492. * $(document).ready(function() {
  493. * var oTable;
  494. *
  495. * // 'open' an information row when a row is clicked on
  496. * $('#example tbody tr').click( function () {
  497. * if ( oTable.fnIsOpen(this) ) {
  498. * oTable.fnClose( this );
  499. * } else {
  500. * oTable.fnOpen( this, "Temporary row opened", "info_row" );
  501. * }
  502. * } );
  503. *
  504. * oTable = $('#example').dataTable();
  505. * } );
  506. */
  507. this.fnIsOpen = function( nTr )
  508. {
  509. return this.api( true ).row( nTr ).child.isShown();
  510. };
  511. /**
  512. * This function will place a new row directly after a row which is currently
  513. * on display on the page, with the HTML contents that is passed into the
  514. * function. This can be used, for example, to ask for confirmation that a
  515. * particular record should be deleted.
  516. * @param {node} nTr The table row to 'open'
  517. * @param {string|node|jQuery} mHtml The HTML to put into the row
  518. * @param {string} sClass Class to give the new TD cell
  519. * @returns {node} The row opened. Note that if the table row passed in as the
  520. * first parameter, is not found in the table, this method will silently
  521. * return.
  522. * @dtopt API
  523. * @deprecated Since v1.10
  524. *
  525. * @example
  526. * $(document).ready(function() {
  527. * var oTable;
  528. *
  529. * // 'open' an information row when a row is clicked on
  530. * $('#example tbody tr').click( function () {
  531. * if ( oTable.fnIsOpen(this) ) {
  532. * oTable.fnClose( this );
  533. * } else {
  534. * oTable.fnOpen( this, "Temporary row opened", "info_row" );
  535. * }
  536. * } );
  537. *
  538. * oTable = $('#example').dataTable();
  539. * } );
  540. */
  541. this.fnOpen = function( nTr, mHtml, sClass )
  542. {
  543. return this.api( true )
  544. .row( nTr )
  545. .child( mHtml, sClass )
  546. .show()
  547. .child()[0];
  548. };
  549. /**
  550. * Change the pagination - provides the internal logic for pagination in a simple API
  551. * function. With this function you can have a DataTables table go to the next,
  552. * previous, first or last pages.
  553. * @param {string|int} mAction Paging action to take: "first", "previous", "next" or "last"
  554. * or page number to jump to (integer), note that page 0 is the first page.
  555. * @param {bool} [bRedraw=true] Redraw the table or not
  556. * @dtopt API
  557. * @deprecated Since v1.10
  558. *
  559. * @example
  560. * $(document).ready(function() {
  561. * var oTable = $('#example').dataTable();
  562. * oTable.fnPageChange( 'next' );
  563. * } );
  564. */
  565. this.fnPageChange = function ( mAction, bRedraw )
  566. {
  567. var api = this.api( true ).page( mAction );
  568. if ( bRedraw === undefined || bRedraw ) {
  569. api.draw(false);
  570. }
  571. };
  572. /**
  573. * Show a particular column
  574. * @param {int} iCol The column whose display should be changed
  575. * @param {bool} bShow Show (true) or hide (false) the column
  576. * @param {bool} [bRedraw=true] Redraw the table or not
  577. * @dtopt API
  578. * @deprecated Since v1.10
  579. *
  580. * @example
  581. * $(document).ready(function() {
  582. * var oTable = $('#example').dataTable();
  583. *
  584. * // Hide the second column after initialisation
  585. * oTable.fnSetColumnVis( 1, false );
  586. * } );
  587. */
  588. this.fnSetColumnVis = function ( iCol, bShow, bRedraw )
  589. {
  590. var api = this.api( true ).column( iCol ).visible( bShow );
  591. if ( bRedraw === undefined || bRedraw ) {
  592. api.columns.adjust().draw();
  593. }
  594. };
  595. /**
  596. * Get the settings for a particular table for external manipulation
  597. * @returns {object} DataTables settings object. See
  598. * {@link DataTable.models.oSettings}
  599. * @dtopt API
  600. * @deprecated Since v1.10
  601. *
  602. * @example
  603. * $(document).ready(function() {
  604. * var oTable = $('#example').dataTable();
  605. * var oSettings = oTable.fnSettings();
  606. *
  607. * // Show an example parameter from the settings
  608. * alert( oSettings._iDisplayStart );
  609. * } );
  610. */
  611. this.fnSettings = function()
  612. {
  613. return _fnSettingsFromNode( this[_ext.iApiIndex] );
  614. };
  615. /**
  616. * Sort the table by a particular column
  617. * @param {int} iCol the data index to sort on. Note that this will not match the
  618. * 'display index' if you have hidden data entries
  619. * @dtopt API
  620. * @deprecated Since v1.10
  621. *
  622. * @example
  623. * $(document).ready(function() {
  624. * var oTable = $('#example').dataTable();
  625. *
  626. * // Sort immediately with columns 0 and 1
  627. * oTable.fnSort( [ [0,'asc'], [1,'asc'] ] );
  628. * } );
  629. */
  630. this.fnSort = function( aaSort )
  631. {
  632. this.api( true ).order( aaSort ).draw();
  633. };
  634. /**
  635. * Attach a sort listener to an element for a given column
  636. * @param {node} nNode the element to attach the sort listener to
  637. * @param {int} iColumn the column that a click on this node will sort on
  638. * @param {function} [fnCallback] callback function when sort is run
  639. * @dtopt API
  640. * @deprecated Since v1.10
  641. *
  642. * @example
  643. * $(document).ready(function() {
  644. * var oTable = $('#example').dataTable();
  645. *
  646. * // Sort on column 1, when 'sorter' is clicked on
  647. * oTable.fnSortListener( document.getElementById('sorter'), 1 );
  648. * } );
  649. */
  650. this.fnSortListener = function( nNode, iColumn, fnCallback )
  651. {
  652. this.api( true ).order.listener( nNode, iColumn, fnCallback );
  653. };
  654. /**
  655. * Update a table cell or row - this method will accept either a single value to
  656. * update the cell with, an array of values with one element for each column or
  657. * an object in the same format as the original data source. The function is
  658. * self-referencing in order to make the multi column updates easier.
  659. * @param {object|array|string} mData Data to update the cell/row with
  660. * @param {node|int} mRow TR element you want to update or the aoData index
  661. * @param {int} [iColumn] The column to update, give as null or undefined to
  662. * update a whole row.
  663. * @param {bool} [bRedraw=true] Redraw the table or not
  664. * @param {bool} [bAction=true] Perform pre-draw actions or not
  665. * @returns {int} 0 on success, 1 on error
  666. * @dtopt API
  667. * @deprecated Since v1.10
  668. *
  669. * @example
  670. * $(document).ready(function() {
  671. * var oTable = $('#example').dataTable();
  672. * oTable.fnUpdate( 'Example update', 0, 0 ); // Single cell
  673. * oTable.fnUpdate( ['a', 'b', 'c', 'd', 'e'], $('tbody tr')[0] ); // Row
  674. * } );
  675. */
  676. this.fnUpdate = function( mData, mRow, iColumn, bRedraw, bAction )
  677. {
  678. var api = this.api( true );
  679. if ( iColumn === undefined || iColumn === null ) {
  680. api.row( mRow ).data( mData );
  681. }
  682. else {
  683. api.cell( mRow, iColumn ).data( mData );
  684. }
  685. if ( bAction === undefined || bAction ) {
  686. api.columns.adjust();
  687. }
  688. if ( bRedraw === undefined || bRedraw ) {
  689. api.draw();
  690. }
  691. return 0;
  692. };
  693. /**
  694. * Provide a common method for plug-ins to check the version of DataTables being used, in order
  695. * to ensure compatibility.
  696. * @param {string} sVersion Version string to check for, in the format "X.Y.Z". Note that the
  697. * formats "X" and "X.Y" are also acceptable.
  698. * @returns {boolean} true if this version of DataTables is greater or equal to the required
  699. * version, or false if this version of DataTales is not suitable
  700. * @method
  701. * @dtopt API
  702. * @deprecated Since v1.10
  703. *
  704. * @example
  705. * $(document).ready(function() {
  706. * var oTable = $('#example').dataTable();
  707. * alert( oTable.fnVersionCheck( '1.9.0' ) );
  708. * } );
  709. */
  710. this.fnVersionCheck = _ext.fnVersionCheck;
  711. var _that = this;
  712. var emptyInit = options === undefined;
  713. var len = this.length;
  714. if ( emptyInit ) {
  715. options = {};
  716. }
  717. this.oApi = this.internal = _ext.internal;
  718. // Extend with old style plug-in API methods
  719. for ( var fn in DataTable.ext.internal ) {
  720. if ( fn ) {
  721. this[fn] = _fnExternApiFunc(fn);
  722. }
  723. }
  724. this.each(function() {
  725. // For each initialisation we want to give it a clean initialisation
  726. // object that can be bashed around
  727. var o = {};
  728. var oInit = len > 1 ? // optimisation for single table case
  729. _fnExtend( o, options, true ) :
  730. options;
  731. /*global oInit,_that,emptyInit*/
  732. var i=0, iLen, j, jLen, k, kLen;
  733. var sId = this.getAttribute( 'id' );
  734. var bInitHandedOff = false;
  735. var defaults = DataTable.defaults;
  736. var $this = $(this);
  737. /* Sanity check */
  738. if ( this.nodeName.toLowerCase() != 'table' )
  739. {
  740. _fnLog( null, 0, 'Non-table node initialisation ('+this.nodeName+')', 2 );
  741. return;
  742. }
  743. /* Backwards compatibility for the defaults */
  744. _fnCompatOpts( defaults );
  745. _fnCompatCols( defaults.column );
  746. /* Convert the camel-case defaults to Hungarian */
  747. _fnCamelToHungarian( defaults, defaults, true );
  748. _fnCamelToHungarian( defaults.column, defaults.column, true );
  749. /* Setting up the initialisation object */
  750. _fnCamelToHungarian( defaults, $.extend( oInit, $this.data() ), true );
  751. /* Check to see if we are re-initialising a table */
  752. var allSettings = DataTable.settings;
  753. for ( i=0, iLen=allSettings.length ; i<iLen ; i++ )
  754. {
  755. var s = allSettings[i];
  756. /* Base check on table node */
  757. if (
  758. s.nTable == this ||
  759. (s.nTHead && s.nTHead.parentNode == this) ||
  760. (s.nTFoot && s.nTFoot.parentNode == this)
  761. ) {
  762. var bRetrieve = oInit.bRetrieve !== undefined ? oInit.bRetrieve : defaults.bRetrieve;
  763. var bDestroy = oInit.bDestroy !== undefined ? oInit.bDestroy : defaults.bDestroy;
  764. if ( emptyInit || bRetrieve )
  765. {
  766. return s.oInstance;
  767. }
  768. else if ( bDestroy )
  769. {
  770. s.oInstance.fnDestroy();
  771. break;
  772. }
  773. else
  774. {
  775. _fnLog( s, 0, 'Cannot reinitialise DataTable', 3 );
  776. return;
  777. }
  778. }
  779. /* If the element we are initialising has the same ID as a table which was previously
  780. * initialised, but the table nodes don't match (from before) then we destroy the old
  781. * instance by simply deleting it. This is under the assumption that the table has been
  782. * destroyed by other methods. Anyone using non-id selectors will need to do this manually
  783. */
  784. if ( s.sTableId == this.id )
  785. {
  786. allSettings.splice( i, 1 );
  787. break;
  788. }
  789. }
  790. /* Ensure the table has an ID - required for accessibility */
  791. if ( sId === null || sId === "" )
  792. {
  793. sId = "DataTables_Table_"+(DataTable.ext._unique++);
  794. this.id = sId;
  795. }
  796. /* Create the settings object for this table and set some of the default parameters */
  797. var oSettings = $.extend( true, {}, DataTable.models.oSettings, {
  798. "sDestroyWidth": $this[0].style.width,
  799. "sInstance": sId,
  800. "sTableId": sId
  801. } );
  802. oSettings.nTable = this;
  803. oSettings.oApi = _that.internal;
  804. oSettings.oInit = oInit;
  805. allSettings.push( oSettings );
  806. // Need to add the instance after the instance after the settings object has been added
  807. // to the settings array, so we can self reference the table instance if more than one
  808. oSettings.oInstance = (_that.length===1) ? _that : $this.dataTable();
  809. // Backwards compatibility, before we apply all the defaults
  810. _fnCompatOpts( oInit );
  811. _fnLanguageCompat( oInit.oLanguage );
  812. // If the length menu is given, but the init display length is not, use the length menu
  813. if ( oInit.aLengthMenu && ! oInit.iDisplayLength )
  814. {
  815. oInit.iDisplayLength = Array.isArray( oInit.aLengthMenu[0] ) ?
  816. oInit.aLengthMenu[0][0] : oInit.aLengthMenu[0];
  817. }
  818. // Apply the defaults and init options to make a single init object will all
  819. // options defined from defaults and instance options.
  820. oInit = _fnExtend( $.extend( true, {}, defaults ), oInit );
  821. // Map the initialisation options onto the settings object
  822. _fnMap( oSettings.oFeatures, oInit, [
  823. "bPaginate",
  824. "bLengthChange",
  825. "bFilter",
  826. "bSort",
  827. "bSortMulti",
  828. "bInfo",
  829. "bProcessing",
  830. "bAutoWidth",
  831. "bSortClasses",
  832. "bServerSide",
  833. "bDeferRender"
  834. ] );
  835. _fnMap( oSettings, oInit, [
  836. "asStripeClasses",
  837. "ajax",
  838. "fnServerData",
  839. "fnFormatNumber",
  840. "sServerMethod",
  841. "aaSorting",
  842. "aaSortingFixed",
  843. "aLengthMenu",
  844. "sPaginationType",
  845. "sAjaxSource",
  846. "sAjaxDataProp",
  847. "iStateDuration",
  848. "sDom",
  849. "bSortCellsTop",
  850. "iTabIndex",
  851. "fnStateLoadCallback",
  852. "fnStateSaveCallback",
  853. "renderer",
  854. "searchDelay",
  855. "rowId",
  856. [ "iCookieDuration", "iStateDuration" ], // backwards compat
  857. [ "oSearch", "oPreviousSearch" ],
  858. [ "aoSearchCols", "aoPreSearchCols" ],
  859. [ "iDisplayLength", "_iDisplayLength" ]
  860. ] );
  861. _fnMap( oSettings.oScroll, oInit, [
  862. [ "sScrollX", "sX" ],
  863. [ "sScrollXInner", "sXInner" ],
  864. [ "sScrollY", "sY" ],
  865. [ "bScrollCollapse", "bCollapse" ]
  866. ] );
  867. _fnMap( oSettings.oLanguage, oInit, "fnInfoCallback" );
  868. /* Callback functions which are array driven */
  869. _fnCallbackReg( oSettings, 'aoDrawCallback', oInit.fnDrawCallback, 'user' );
  870. _fnCallbackReg( oSettings, 'aoServerParams', oInit.fnServerParams, 'user' );
  871. _fnCallbackReg( oSettings, 'aoStateSaveParams', oInit.fnStateSaveParams, 'user' );
  872. _fnCallbackReg( oSettings, 'aoStateLoadParams', oInit.fnStateLoadParams, 'user' );
  873. _fnCallbackReg( oSettings, 'aoStateLoaded', oInit.fnStateLoaded, 'user' );
  874. _fnCallbackReg( oSettings, 'aoRowCallback', oInit.fnRowCallback, 'user' );
  875. _fnCallbackReg( oSettings, 'aoRowCreatedCallback', oInit.fnCreatedRow, 'user' );
  876. _fnCallbackReg( oSettings, 'aoHeaderCallback', oInit.fnHeaderCallback, 'user' );
  877. _fnCallbackReg( oSettings, 'aoFooterCallback', oInit.fnFooterCallback, 'user' );
  878. _fnCallbackReg( oSettings, 'aoInitComplete', oInit.fnInitComplete, 'user' );
  879. _fnCallbackReg( oSettings, 'aoPreDrawCallback', oInit.fnPreDrawCallback, 'user' );
  880. oSettings.rowIdFn = _fnGetObjectDataFn( oInit.rowId );
  881. /* Browser support detection */
  882. _fnBrowserDetect( oSettings );
  883. var oClasses = oSettings.oClasses;
  884. $.extend( oClasses, DataTable.ext.classes, oInit.oClasses );
  885. $this.addClass( oClasses.sTable );
  886. if ( oSettings.iInitDisplayStart === undefined )
  887. {
  888. /* Display start point, taking into account the save saving */
  889. oSettings.iInitDisplayStart = oInit.iDisplayStart;
  890. oSettings._iDisplayStart = oInit.iDisplayStart;
  891. }
  892. if ( oInit.iDeferLoading !== null )
  893. {
  894. oSettings.bDeferLoading = true;
  895. var tmp = Array.isArray( oInit.iDeferLoading );
  896. oSettings._iRecordsDisplay = tmp ? oInit.iDeferLoading[0] : oInit.iDeferLoading;
  897. oSettings._iRecordsTotal = tmp ? oInit.iDeferLoading[1] : oInit.iDeferLoading;
  898. }
  899. /* Language definitions */
  900. var oLanguage = oSettings.oLanguage;
  901. $.extend( true, oLanguage, oInit.oLanguage );
  902. if ( oLanguage.sUrl )
  903. {
  904. /* Get the language definitions from a file - because this Ajax call makes the language
  905. * get async to the remainder of this function we use bInitHandedOff to indicate that
  906. * _fnInitialise will be fired by the returned Ajax handler, rather than the constructor
  907. */
  908. $.ajax( {
  909. dataType: 'json',
  910. url: oLanguage.sUrl,
  911. success: function ( json ) {
  912. _fnCamelToHungarian( defaults.oLanguage, json );
  913. _fnLanguageCompat( json );
  914. $.extend( true, oLanguage, json, oSettings.oInit.oLanguage );
  915. _fnCallbackFire( oSettings, null, 'i18n', [oSettings]);
  916. _fnInitialise( oSettings );
  917. },
  918. error: function () {
  919. // Error occurred loading language file, continue on as best we can
  920. _fnInitialise( oSettings );
  921. }
  922. } );
  923. bInitHandedOff = true;
  924. }
  925. else {
  926. _fnCallbackFire( oSettings, null, 'i18n', [oSettings]);
  927. }
  928. /*
  929. * Stripes
  930. */
  931. if ( oInit.asStripeClasses === null )
  932. {
  933. oSettings.asStripeClasses =[
  934. oClasses.sStripeOdd,
  935. oClasses.sStripeEven
  936. ];
  937. }
  938. /* Remove row stripe classes if they are already on the table row */
  939. var stripeClasses = oSettings.asStripeClasses;
  940. var rowOne = $this.children('tbody').find('tr').eq(0);
  941. if ( $.inArray( true, $.map( stripeClasses, function(el, i) {
  942. return rowOne.hasClass(el);
  943. } ) ) !== -1 ) {
  944. $('tbody tr', this).removeClass( stripeClasses.join(' ') );
  945. oSettings.asDestroyStripes = stripeClasses.slice();
  946. }
  947. /*
  948. * Columns
  949. * See if we should load columns automatically or use defined ones
  950. */
  951. var anThs = [];
  952. var aoColumnsInit;
  953. var nThead = this.getElementsByTagName('thead');
  954. if ( nThead.length !== 0 )
  955. {
  956. _fnDetectHeader( oSettings.aoHeader, nThead[0] );
  957. anThs = _fnGetUniqueThs( oSettings );
  958. }
  959. /* If not given a column array, generate one with nulls */
  960. if ( oInit.aoColumns === null )
  961. {
  962. aoColumnsInit = [];
  963. for ( i=0, iLen=anThs.length ; i<iLen ; i++ )
  964. {
  965. aoColumnsInit.push( null );
  966. }
  967. }
  968. else
  969. {
  970. aoColumnsInit = oInit.aoColumns;
  971. }
  972. /* Add the columns */
  973. for ( i=0, iLen=aoColumnsInit.length ; i<iLen ; i++ )
  974. {
  975. _fnAddColumn( oSettings, anThs ? anThs[i] : null );
  976. }
  977. /* Apply the column definitions */
  978. _fnApplyColumnDefs( oSettings, oInit.aoColumnDefs, aoColumnsInit, function (iCol, oDef) {
  979. _fnColumnOptions( oSettings, iCol, oDef );
  980. } );
  981. /* HTML5 attribute detection - build an mData object automatically if the
  982. * attributes are found
  983. */
  984. if ( rowOne.length ) {
  985. var a = function ( cell, name ) {
  986. return cell.getAttribute( 'data-'+name ) !== null ? name : null;
  987. };
  988. $( rowOne[0] ).children('th, td').each( function (i, cell) {
  989. var col = oSettings.aoColumns[i];
  990. if (! col) {
  991. _fnLog( oSettings, 0, 'Incorrect column count', 18 );
  992. }
  993. if ( col.mData === i ) {
  994. var sort = a( cell, 'sort' ) || a( cell, 'order' );
  995. var filter = a( cell, 'filter' ) || a( cell, 'search' );
  996. if ( sort !== null || filter !== null ) {
  997. col.mData = {
  998. _: i+'.display',
  999. sort: sort !== null ? i+'.@data-'+sort : undefined,
  1000. type: sort !== null ? i+'.@data-'+sort : undefined,
  1001. filter: filter !== null ? i+'.@data-'+filter : undefined
  1002. };
  1003. col._isArrayHost = true;
  1004. _fnColumnOptions( oSettings, i );
  1005. }
  1006. }
  1007. } );
  1008. }
  1009. var features = oSettings.oFeatures;
  1010. var loadedInit = function () {
  1011. /*
  1012. * Sorting
  1013. * @todo For modularisation (1.11) this needs to do into a sort start up handler
  1014. */
  1015. // If aaSorting is not defined, then we use the first indicator in asSorting
  1016. // in case that has been altered, so the default sort reflects that option
  1017. if ( oInit.aaSorting === undefined ) {
  1018. var sorting = oSettings.aaSorting;
  1019. for ( i=0, iLen=sorting.length ; i<iLen ; i++ ) {
  1020. sorting[i][1] = oSettings.aoColumns[ i ].asSorting[0];
  1021. }
  1022. }
  1023. /* Do a first pass on the sorting classes (allows any size changes to be taken into
  1024. * account, and also will apply sorting disabled classes if disabled
  1025. */
  1026. _fnSortingClasses( oSettings );
  1027. if ( features.bSort ) {
  1028. _fnCallbackReg( oSettings, 'aoDrawCallback', function () {
  1029. if ( oSettings.bSorted ) {
  1030. var aSort = _fnSortFlatten( oSettings );
  1031. var sortedColumns = {};
  1032. $.each( aSort, function (i, val) {
  1033. sortedColumns[ val.src ] = val.dir;
  1034. } );
  1035. _fnCallbackFire( oSettings, null, 'order', [oSettings, aSort, sortedColumns] );
  1036. _fnSortAria( oSettings );
  1037. }
  1038. } );
  1039. }
  1040. _fnCallbackReg( oSettings, 'aoDrawCallback', function () {
  1041. if ( oSettings.bSorted || _fnDataSource( oSettings ) === 'ssp' || features.bDeferRender ) {
  1042. _fnSortingClasses( oSettings );
  1043. }
  1044. }, 'sc' );
  1045. /*
  1046. * Final init
  1047. * Cache the header, body and footer as required, creating them if needed
  1048. */
  1049. // Work around for Webkit bug 83867 - store the caption-side before removing from doc
  1050. var captions = $this.children('caption').each( function () {
  1051. this._captionSide = $(this).css('caption-side');
  1052. } );
  1053. var thead = $this.children('thead');
  1054. if ( thead.length === 0 ) {
  1055. thead = $('<thead/>').appendTo($this);
  1056. }
  1057. oSettings.nTHead = thead[0];
  1058. var tbody = $this.children('tbody');
  1059. if ( tbody.length === 0 ) {
  1060. tbody = $('<tbody/>').insertAfter(thead);
  1061. }
  1062. oSettings.nTBody = tbody[0];
  1063. var tfoot = $this.children('tfoot');
  1064. if ( tfoot.length === 0 && captions.length > 0 && (oSettings.oScroll.sX !== "" || oSettings.oScroll.sY !== "") ) {
  1065. // If we are a scrolling table, and no footer has been given, then we need to create
  1066. // a tfoot element for the caption element to be appended to
  1067. tfoot = $('<tfoot/>').appendTo($this);
  1068. }
  1069. if ( tfoot.length === 0 || tfoot.children().length === 0 ) {
  1070. $this.addClass( oClasses.sNoFooter );
  1071. }
  1072. else if ( tfoot.length > 0 ) {
  1073. oSettings.nTFoot = tfoot[0];
  1074. _fnDetectHeader( oSettings.aoFooter, oSettings.nTFoot );
  1075. }
  1076. /* Check if there is data passing into the constructor */
  1077. if ( oInit.aaData ) {
  1078. for ( i=0 ; i<oInit.aaData.length ; i++ ) {
  1079. _fnAddData( oSettings, oInit.aaData[ i ] );
  1080. }
  1081. }
  1082. else if ( oSettings.bDeferLoading || _fnDataSource( oSettings ) == 'dom' ) {
  1083. /* Grab the data from the page - only do this when deferred loading or no Ajax
  1084. * source since there is no point in reading the DOM data if we are then going
  1085. * to replace it with Ajax data
  1086. */
  1087. _fnAddTr( oSettings, $(oSettings.nTBody).children('tr') );
  1088. }
  1089. /* Copy the data index array */
  1090. oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
  1091. /* Initialisation complete - table can be drawn */
  1092. oSettings.bInitialised = true;
  1093. /* Check if we need to initialise the table (it might not have been handed off to the
  1094. * language processor)
  1095. */
  1096. if ( bInitHandedOff === false ) {
  1097. _fnInitialise( oSettings );
  1098. }
  1099. };
  1100. /* Must be done after everything which can be overridden by the state saving! */
  1101. _fnCallbackReg( oSettings, 'aoDrawCallback', _fnSaveState, 'state_save' );
  1102. if ( oInit.bStateSave )
  1103. {
  1104. features.bStateSave = true;
  1105. _fnLoadState( oSettings, oInit, loadedInit );
  1106. }
  1107. else {
  1108. loadedInit();
  1109. }
  1110. } );
  1111. _that = null;
  1112. return this;
  1113. };
  1114. /*
  1115. * It is useful to have variables which are scoped locally so only the
  1116. * DataTables functions can access them and they don't leak into global space.
  1117. * At the same time these functions are often useful over multiple files in the
  1118. * core and API, so we list, or at least document, all variables which are used
  1119. * by DataTables as private variables here. This also ensures that there is no
  1120. * clashing of variable names and that they can easily referenced for reuse.
  1121. */
  1122. // Defined else where
  1123. // _selector_run
  1124. // _selector_opts
  1125. // _selector_first
  1126. // _selector_row_indexes
  1127. var _ext; // DataTable.ext
  1128. var _Api; // DataTable.Api
  1129. var _api_register; // DataTable.Api.register
  1130. var _api_registerPlural; // DataTable.Api.registerPlural
  1131. var _re_dic = {};
  1132. var _re_new_lines = /[\r\n\u2028]/g;
  1133. var _re_html = /<.*?>/g;
  1134. // This is not strict ISO8601 - Date.parse() is quite lax, although
  1135. // implementations differ between browsers.
  1136. var _re_date = /^\d{2,4}[\.\/\-]\d{1,2}[\.\/\-]\d{1,2}([T ]{1}\d{1,2}[:\.]\d{2}([\.:]\d{2})?)?$/;
  1137. // Escape regular expression special characters
  1138. var _re_escape_regex = new RegExp( '(\\' + [ '/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\', '$', '^', '-' ].join('|\\') + ')', 'g' );
  1139. // http://en.wikipedia.org/wiki/Foreign_exchange_market
  1140. // - \u20BD - Russian ruble.
  1141. // - \u20a9 - South Korean Won
  1142. // - \u20BA - Turkish Lira
  1143. // - \u20B9 - Indian Rupee
  1144. // - R - Brazil (R$) and South Africa
  1145. // - fr - Swiss Franc
  1146. // - kr - Swedish krona, Norwegian krone and Danish krone
  1147. // - \u2009 is thin space and \u202F is narrow no-break space, both used in many
  1148. // - Ƀ - Bitcoin
  1149. // - Ξ - Ethereum
  1150. // standards as thousands separators.
  1151. var _re_formatted_numeric = /['\u00A0,$£€¥%\u2009\u202F\u20BD\u20a9\u20BArfkɃΞ]/gi;
  1152. var _empty = function ( d ) {
  1153. return !d || d === true || d === '-' ? true : false;
  1154. };
  1155. var _intVal = function ( s ) {
  1156. var integer = parseInt( s, 10 );
  1157. return !isNaN(integer) && isFinite(s) ? integer : null;
  1158. };
  1159. // Convert from a formatted number with characters other than `.` as the
  1160. // decimal place, to a Javascript number
  1161. var _numToDecimal = function ( num, decimalPoint ) {
  1162. // Cache created regular expressions for speed as this function is called often
  1163. if ( ! _re_dic[ decimalPoint ] ) {
  1164. _re_dic[ decimalPoint ] = new RegExp( _fnEscapeRegex( decimalPoint ), 'g' );
  1165. }
  1166. return typeof num === 'string' && decimalPoint !== '.' ?
  1167. num.replace( /\./g, '' ).replace( _re_dic[ decimalPoint ], '.' ) :
  1168. num;
  1169. };
  1170. var _isNumber = function ( d, decimalPoint, formatted ) {
  1171. var type = typeof d;
  1172. var strType = type === 'string';
  1173. if ( type === 'number' || type === 'bigint') {
  1174. return true;
  1175. }
  1176. // If empty return immediately so there must be a number if it is a
  1177. // formatted string (this stops the string "k", or "kr", etc being detected
  1178. // as a formatted number for currency
  1179. if ( _empty( d ) ) {
  1180. return true;
  1181. }
  1182. if ( decimalPoint && strType ) {
  1183. d = _numToDecimal( d, decimalPoint );
  1184. }
  1185. if ( formatted && strType ) {
  1186. d = d.replace( _re_formatted_numeric, '' );
  1187. }
  1188. return !isNaN( parseFloat(d) ) && isFinite( d );
  1189. };
  1190. // A string without HTML in it can be considered to be HTML still
  1191. var _isHtml = function ( d ) {
  1192. return _empty( d ) || typeof d === 'string';
  1193. };
  1194. var _htmlNumeric = function ( d, decimalPoint, formatted ) {
  1195. if ( _empty( d ) ) {
  1196. return true;
  1197. }
  1198. var html = _isHtml( d );
  1199. return ! html ?
  1200. null :
  1201. _isNumber( _stripHtml( d ), decimalPoint, formatted ) ?
  1202. true :
  1203. null;
  1204. };
  1205. var _pluck = function ( a, prop, prop2 ) {
  1206. var out = [];
  1207. var i=0, ien=a.length;
  1208. // Could have the test in the loop for slightly smaller code, but speed
  1209. // is essential here
  1210. if ( prop2 !== undefined ) {
  1211. for ( ; i<ien ; i++ ) {
  1212. if ( a[i] && a[i][ prop ] ) {
  1213. out.push( a[i][ prop ][ prop2 ] );
  1214. }
  1215. }
  1216. }
  1217. else {
  1218. for ( ; i<ien ; i++ ) {
  1219. if ( a[i] ) {
  1220. out.push( a[i][ prop ] );
  1221. }
  1222. }
  1223. }
  1224. return out;
  1225. };
  1226. // Basically the same as _pluck, but rather than looping over `a` we use `order`
  1227. // as the indexes to pick from `a`
  1228. var _pluck_order = function ( a, order, prop, prop2 )
  1229. {
  1230. var out = [];
  1231. var i=0, ien=order.length;
  1232. // Could have the test in the loop for slightly smaller code, but speed
  1233. // is essential here
  1234. if ( prop2 !== undefined ) {
  1235. for ( ; i<ien ; i++ ) {
  1236. if ( a[ order[i] ][ prop ] ) {
  1237. out.push( a[ order[i] ][ prop ][ prop2 ] );
  1238. }
  1239. }
  1240. }
  1241. else {
  1242. for ( ; i<ien ; i++ ) {
  1243. out.push( a[ order[i] ][ prop ] );
  1244. }
  1245. }
  1246. return out;
  1247. };
  1248. var _range = function ( len, start )
  1249. {
  1250. var out = [];
  1251. var end;
  1252. if ( start === undefined ) {
  1253. start = 0;
  1254. end = len;
  1255. }
  1256. else {
  1257. end = start;
  1258. start = len;
  1259. }
  1260. for ( var i=start ; i<end ; i++ ) {
  1261. out.push( i );
  1262. }
  1263. return out;
  1264. };
  1265. var _removeEmpty = function ( a )
  1266. {
  1267. var out = [];
  1268. for ( var i=0, ien=a.length ; i<ien ; i++ ) {
  1269. if ( a[i] ) { // careful - will remove all falsy values!
  1270. out.push( a[i] );
  1271. }
  1272. }
  1273. return out;
  1274. };
  1275. var _stripHtml = function ( d ) {
  1276. return d
  1277. .replace( _re_html, '' ) // Complete tags
  1278. .replace(/<script/i, ''); // Safety for incomplete script tag
  1279. };
  1280. /**
  1281. * Determine if all values in the array are unique. This means we can short
  1282. * cut the _unique method at the cost of a single loop. A sorted array is used
  1283. * to easily check the values.
  1284. *
  1285. * @param {array} src Source array
  1286. * @return {boolean} true if all unique, false otherwise
  1287. * @ignore
  1288. */
  1289. var _areAllUnique = function ( src ) {
  1290. if ( src.length < 2 ) {
  1291. return true;
  1292. }
  1293. var sorted = src.slice().sort();
  1294. var last = sorted[0];
  1295. for ( var i=1, ien=sorted.length ; i<ien ; i++ ) {
  1296. if ( sorted[i] === last ) {
  1297. return false;
  1298. }
  1299. last = sorted[i];
  1300. }
  1301. return true;
  1302. };
  1303. /**
  1304. * Find the unique elements in a source array.
  1305. *
  1306. * @param {array} src Source array
  1307. * @return {array} Array of unique items
  1308. * @ignore
  1309. */
  1310. var _unique = function ( src )
  1311. {
  1312. if ( _areAllUnique( src ) ) {
  1313. return src.slice();
  1314. }
  1315. // A faster unique method is to use object keys to identify used values,
  1316. // but this doesn't work with arrays or objects, which we must also
  1317. // consider. See jsperf.com/compare-array-unique-versions/4 for more
  1318. // information.
  1319. var
  1320. out = [],
  1321. val,
  1322. i, ien=src.length,
  1323. j, k=0;
  1324. again: for ( i=0 ; i<ien ; i++ ) {
  1325. val = src[i];
  1326. for ( j=0 ; j<k ; j++ ) {
  1327. if ( out[j] === val ) {
  1328. continue again;
  1329. }
  1330. }
  1331. out.push( val );
  1332. k++;
  1333. }
  1334. return out;
  1335. };
  1336. // Surprisingly this is faster than [].concat.apply
  1337. // https://jsperf.com/flatten-an-array-loop-vs-reduce/2
  1338. var _flatten = function (out, val) {
  1339. if (Array.isArray(val)) {
  1340. for (var i=0 ; i<val.length ; i++) {
  1341. _flatten(out, val[i]);
  1342. }
  1343. }
  1344. else {
  1345. out.push(val);
  1346. }
  1347. return out;
  1348. }
  1349. var _includes = function (search, start) {
  1350. if (start === undefined) {
  1351. start = 0;
  1352. }
  1353. return this.indexOf(search, start) !== -1;
  1354. };
  1355. // Array.isArray polyfill.
  1356. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
  1357. if (! Array.isArray) {
  1358. Array.isArray = function(arg) {
  1359. return Object.prototype.toString.call(arg) === '[object Array]';
  1360. };
  1361. }
  1362. if (! Array.prototype.includes) {
  1363. Array.prototype.includes = _includes;
  1364. }
  1365. // .trim() polyfill
  1366. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim
  1367. if (!String.prototype.trim) {
  1368. String.prototype.trim = function () {
  1369. return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  1370. };
  1371. }
  1372. if (! String.prototype.includes) {
  1373. String.prototype.includes = _includes;
  1374. }
  1375. /**
  1376. * DataTables utility methods
  1377. *
  1378. * This namespace provides helper methods that DataTables uses internally to
  1379. * create a DataTable, but which are not exclusively used only for DataTables.
  1380. * These methods can be used by extension authors to save the duplication of
  1381. * code.
  1382. *
  1383. * @namespace
  1384. */
  1385. DataTable.util = {
  1386. /**
  1387. * Throttle the calls to a function. Arguments and context are maintained
  1388. * for the throttled function.
  1389. *
  1390. * @param {function} fn Function to be called
  1391. * @param {integer} freq Call frequency in mS
  1392. * @return {function} Wrapped function
  1393. */
  1394. throttle: function ( fn, freq ) {
  1395. var
  1396. frequency = freq !== undefined ? freq : 200,
  1397. last,
  1398. timer;
  1399. return function () {
  1400. var
  1401. that = this,
  1402. now = +new Date(),
  1403. args = arguments;
  1404. if ( last && now < last + frequency ) {
  1405. clearTimeout( timer );
  1406. timer = setTimeout( function () {
  1407. last = undefined;
  1408. fn.apply( that, args );
  1409. }, frequency );
  1410. }
  1411. else {
  1412. last = now;
  1413. fn.apply( that, args );
  1414. }
  1415. };
  1416. },
  1417. /**
  1418. * Escape a string such that it can be used in a regular expression
  1419. *
  1420. * @param {string} val string to escape
  1421. * @returns {string} escaped string
  1422. */
  1423. escapeRegex: function ( val ) {
  1424. return val.replace( _re_escape_regex, '\\$1' );
  1425. },
  1426. /**
  1427. * Create a function that will write to a nested object or array
  1428. * @param {*} source JSON notation string
  1429. * @returns Write function
  1430. */
  1431. set: function ( source ) {
  1432. if ( $.isPlainObject( source ) ) {
  1433. /* Unlike get, only the underscore (global) option is used for for
  1434. * setting data since we don't know the type here. This is why an object
  1435. * option is not documented for `mData` (which is read/write), but it is
  1436. * for `mRender` which is read only.
  1437. */
  1438. return DataTable.util.set( source._ );
  1439. }
  1440. else if ( source === null ) {
  1441. // Nothing to do when the data source is null
  1442. return function () {};
  1443. }
  1444. else if ( typeof source === 'function' ) {
  1445. return function (data, val, meta) {
  1446. source( data, 'set', val, meta );
  1447. };
  1448. }
  1449. else if ( typeof source === 'string' && (source.indexOf('.') !== -1 ||
  1450. source.indexOf('[') !== -1 || source.indexOf('(') !== -1) )
  1451. {
  1452. // Like the get, we need to get data from a nested object
  1453. var setData = function (data, val, src) {
  1454. var a = _fnSplitObjNotation( src ), b;
  1455. var aLast = a[a.length-1];
  1456. var arrayNotation, funcNotation, o, innerSrc;
  1457. for ( var i=0, iLen=a.length-1 ; i<iLen ; i++ ) {
  1458. // Protect against prototype pollution
  1459. if (a[i] === '__proto__' || a[i] === 'constructor') {
  1460. throw new Error('Cannot set prototype values');
  1461. }
  1462. // Check if we are dealing with an array notation request
  1463. arrayNotation = a[i].match(__reArray);
  1464. funcNotation = a[i].match(__reFn);
  1465. if ( arrayNotation ) {
  1466. a[i] = a[i].replace(__reArray, '');
  1467. data[ a[i] ] = [];
  1468. // Get the remainder of the nested object to set so we can recurse
  1469. b = a.slice();
  1470. b.splice( 0, i+1 );
  1471. innerSrc = b.join('.');
  1472. // Traverse each entry in the array setting the properties requested
  1473. if ( Array.isArray( val ) ) {
  1474. for ( var j=0, jLen=val.length ; j<jLen ; j++ ) {
  1475. o = {};
  1476. setData( o, val[j], innerSrc );
  1477. data[ a[i] ].push( o );
  1478. }
  1479. }
  1480. else {
  1481. // We've been asked to save data to an array, but it
  1482. // isn't array data to be saved. Best that can be done
  1483. // is to just save the value.
  1484. data[ a[i] ] = val;
  1485. }
  1486. // The inner call to setData has already traversed through the remainder
  1487. // of the source and has set the data, thus we can exit here
  1488. return;
  1489. }
  1490. else if ( funcNotation ) {
  1491. // Function call
  1492. a[i] = a[i].replace(__reFn, '');
  1493. data = data[ a[i] ]( val );
  1494. }
  1495. // If the nested object doesn't currently exist - since we are
  1496. // trying to set the value - create it
  1497. if ( data[ a[i] ] === null || data[ a[i] ] === undefined ) {
  1498. data[ a[i] ] = {};
  1499. }
  1500. data = data[ a[i] ];
  1501. }
  1502. // Last item in the input - i.e, the actual set
  1503. if ( aLast.match(__reFn ) ) {
  1504. // Function call
  1505. data = data[ aLast.replace(__reFn, '') ]( val );
  1506. }
  1507. else {
  1508. // If array notation is used, we just want to strip it and use the property name
  1509. // and assign the value. If it isn't used, then we get the result we want anyway
  1510. data[ aLast.replace(__reArray, '') ] = val;
  1511. }
  1512. };
  1513. return function (data, val) { // meta is also passed in, but not used
  1514. return setData( data, val, source );
  1515. };
  1516. }
  1517. else {
  1518. // Array or flat object mapping
  1519. return function (data, val) { // meta is also passed in, but not used
  1520. data[source] = val;
  1521. };
  1522. }
  1523. },
  1524. /**
  1525. * Create a function that will read nested objects from arrays, based on JSON notation
  1526. * @param {*} source JSON notation string
  1527. * @returns Value read
  1528. */
  1529. get: function ( source ) {
  1530. if ( $.isPlainObject( source ) ) {
  1531. // Build an object of get functions, and wrap them in a single call
  1532. var o = {};
  1533. $.each( source, function (key, val) {
  1534. if ( val ) {
  1535. o[key] = DataTable.util.get( val );
  1536. }
  1537. } );
  1538. return function (data, type, row, meta) {
  1539. var t = o[type] || o._;
  1540. return t !== undefined ?
  1541. t(data, type, row, meta) :
  1542. data;
  1543. };
  1544. }
  1545. else if ( source === null ) {
  1546. // Give an empty string for rendering / sorting etc
  1547. return function (data) { // type, row and meta also passed, but not used
  1548. return data;
  1549. };
  1550. }
  1551. else if ( typeof source === 'function' ) {
  1552. return function (data, type, row, meta) {
  1553. return source( data, type, row, meta );
  1554. };
  1555. }
  1556. else if ( typeof source === 'string' && (source.indexOf('.') !== -1 ||
  1557. source.indexOf('[') !== -1 || source.indexOf('(') !== -1) )
  1558. {
  1559. /* If there is a . in the source string then the data source is in a
  1560. * nested object so we loop over the data for each level to get the next
  1561. * level down. On each loop we test for undefined, and if found immediately
  1562. * return. This allows entire objects to be missing and sDefaultContent to
  1563. * be used if defined, rather than throwing an error
  1564. */
  1565. var fetchData = function (data, type, src) {
  1566. var arrayNotation, funcNotation, out, innerSrc;
  1567. if ( src !== "" ) {
  1568. var a = _fnSplitObjNotation( src );
  1569. for ( var i=0, iLen=a.length ; i<iLen ; i++ ) {
  1570. // Check if we are dealing with special notation
  1571. arrayNotation = a[i].match(__reArray);
  1572. funcNotation = a[i].match(__reFn);
  1573. if ( arrayNotation ) {
  1574. // Array notation
  1575. a[i] = a[i].replace(__reArray, '');
  1576. // Condition allows simply [] to be passed in
  1577. if ( a[i] !== "" ) {
  1578. data = data[ a[i] ];
  1579. }
  1580. out = [];
  1581. // Get the remainder of the nested object to get
  1582. a.splice( 0, i+1 );
  1583. innerSrc = a.join('.');
  1584. // Traverse each entry in the array getting the properties requested
  1585. if ( Array.isArray( data ) ) {
  1586. for ( var j=0, jLen=data.length ; j<jLen ; j++ ) {
  1587. out.push( fetchData( data[j], type, innerSrc ) );
  1588. }
  1589. }
  1590. // If a string is given in between the array notation indicators, that
  1591. // is used to join the strings together, otherwise an array is returned
  1592. var join = arrayNotation[0].substring(1, arrayNotation[0].length-1);
  1593. data = (join==="") ? out : out.join(join);
  1594. // The inner call to fetchData has already traversed through the remainder
  1595. // of the source requested, so we exit from the loop
  1596. break;
  1597. }
  1598. else if ( funcNotation ) {
  1599. // Function call
  1600. a[i] = a[i].replace(__reFn, '');
  1601. data = data[ a[i] ]();
  1602. continue;
  1603. }
  1604. if (data === null || data[ a[i] ] === null) {
  1605. return null;
  1606. }
  1607. else if ( data === undefined || data[ a[i] ] === undefined ) {
  1608. return undefined;
  1609. }
  1610. data = data[ a[i] ];
  1611. }
  1612. }
  1613. return data;
  1614. };
  1615. return function (data, type) { // row and meta also passed, but not used
  1616. return fetchData( data, type, source );
  1617. };
  1618. }
  1619. else {
  1620. // Array or flat object mapping
  1621. return function (data, type) { // row and meta also passed, but not used
  1622. return data[source];
  1623. };
  1624. }
  1625. }
  1626. };
  1627. /**
  1628. * Create a mapping object that allows camel case parameters to be looked up
  1629. * for their Hungarian counterparts. The mapping is stored in a private
  1630. * parameter called `_hungarianMap` which can be accessed on the source object.
  1631. * @param {object} o
  1632. * @memberof DataTable#oApi
  1633. */
  1634. function _fnHungarianMap ( o )
  1635. {
  1636. var
  1637. hungarian = 'a aa ai ao as b fn i m o s ',
  1638. match,
  1639. newKey,
  1640. map = {};
  1641. $.each( o, function (key, val) {
  1642. match = key.match(/^([^A-Z]+?)([A-Z])/);
  1643. if ( match && hungarian.indexOf(match[1]+' ') !== -1 )
  1644. {
  1645. newKey = key.replace( match[0], match[2].toLowerCase() );
  1646. map[ newKey ] = key;
  1647. if ( match[1] === 'o' )
  1648. {
  1649. _fnHungarianMap( o[key] );
  1650. }
  1651. }
  1652. } );
  1653. o._hungarianMap = map;
  1654. }
  1655. /**
  1656. * Convert from camel case parameters to Hungarian, based on a Hungarian map
  1657. * created by _fnHungarianMap.
  1658. * @param {object} src The model object which holds all parameters that can be
  1659. * mapped.
  1660. * @param {object} user The object to convert from camel case to Hungarian.
  1661. * @param {boolean} force When set to `true`, properties which already have a
  1662. * Hungarian value in the `user` object will be overwritten. Otherwise they
  1663. * won't be.
  1664. * @memberof DataTable#oApi
  1665. */
  1666. function _fnCamelToHungarian ( src, user, force )
  1667. {
  1668. if ( ! src._hungarianMap ) {
  1669. _fnHungarianMap( src );
  1670. }
  1671. var hungarianKey;
  1672. $.each( user, function (key, val) {
  1673. hungarianKey = src._hungarianMap[ key ];
  1674. if ( hungarianKey !== undefined && (force || user[hungarianKey] === undefined) )
  1675. {
  1676. // For objects, we need to buzz down into the object to copy parameters
  1677. if ( hungarianKey.charAt(0) === 'o' )
  1678. {
  1679. // Copy the camelCase options over to the hungarian
  1680. if ( ! user[ hungarianKey ] ) {
  1681. user[ hungarianKey ] = {};
  1682. }
  1683. $.extend( true, user[hungarianKey], user[key] );
  1684. _fnCamelToHungarian( src[hungarianKey], user[hungarianKey], force );
  1685. }
  1686. else {
  1687. user[hungarianKey] = user[ key ];
  1688. }
  1689. }
  1690. } );
  1691. }
  1692. /**
  1693. * Language compatibility - when certain options are given, and others aren't, we
  1694. * need to duplicate the values over, in order to provide backwards compatibility
  1695. * with older language files.
  1696. * @param {object} oSettings dataTables settings object
  1697. * @memberof DataTable#oApi
  1698. */
  1699. function _fnLanguageCompat( lang )
  1700. {
  1701. // Note the use of the Hungarian notation for the parameters in this method as
  1702. // this is called after the mapping of camelCase to Hungarian
  1703. var defaults = DataTable.defaults.oLanguage;
  1704. // Default mapping
  1705. var defaultDecimal = defaults.sDecimal;
  1706. if ( defaultDecimal ) {
  1707. _addNumericSort( defaultDecimal );
  1708. }
  1709. if ( lang ) {
  1710. var zeroRecords = lang.sZeroRecords;
  1711. // Backwards compatibility - if there is no sEmptyTable given, then use the same as
  1712. // sZeroRecords - assuming that is given.
  1713. if ( ! lang.sEmptyTable && zeroRecords &&
  1714. defaults.sEmptyTable === "No data available in table" )
  1715. {
  1716. _fnMap( lang, lang, 'sZeroRecords', 'sEmptyTable' );
  1717. }
  1718. // Likewise with loading records
  1719. if ( ! lang.sLoadingRecords && zeroRecords &&
  1720. defaults.sLoadingRecords === "Loading..." )
  1721. {
  1722. _fnMap( lang, lang, 'sZeroRecords', 'sLoadingRecords' );
  1723. }
  1724. // Old parameter name of the thousands separator mapped onto the new
  1725. if ( lang.sInfoThousands ) {
  1726. lang.sThousands = lang.sInfoThousands;
  1727. }
  1728. var decimal = lang.sDecimal;
  1729. if ( decimal && defaultDecimal !== decimal ) {
  1730. _addNumericSort( decimal );
  1731. }
  1732. }
  1733. }
  1734. /**
  1735. * Map one parameter onto another
  1736. * @param {object} o Object to map
  1737. * @param {*} knew The new parameter name
  1738. * @param {*} old The old parameter name
  1739. */
  1740. var _fnCompatMap = function ( o, knew, old ) {
  1741. if ( o[ knew ] !== undefined ) {
  1742. o[ old ] = o[ knew ];
  1743. }
  1744. };
  1745. /**
  1746. * Provide backwards compatibility for the main DT options. Note that the new
  1747. * options are mapped onto the old parameters, so this is an external interface
  1748. * change only.
  1749. * @param {object} init Object to map
  1750. */
  1751. function _fnCompatOpts ( init )
  1752. {
  1753. _fnCompatMap( init, 'ordering', 'bSort' );
  1754. _fnCompatMap( init, 'orderMulti', 'bSortMulti' );
  1755. _fnCompatMap( init, 'orderClasses', 'bSortClasses' );
  1756. _fnCompatMap( init, 'orderCellsTop', 'bSortCellsTop' );
  1757. _fnCompatMap( init, 'order', 'aaSorting' );
  1758. _fnCompatMap( init, 'orderFixed', 'aaSortingFixed' );
  1759. _fnCompatMap( init, 'paging', 'bPaginate' );
  1760. _fnCompatMap( init, 'pagingType', 'sPaginationType' );
  1761. _fnCompatMap( init, 'pageLength', 'iDisplayLength' );
  1762. _fnCompatMap( init, 'searching', 'bFilter' );
  1763. // Boolean initialisation of x-scrolling
  1764. if ( typeof init.sScrollX === 'boolean' ) {
  1765. init.sScrollX = init.sScrollX ? '100%' : '';
  1766. }
  1767. if ( typeof init.scrollX === 'boolean' ) {
  1768. init.scrollX = init.scrollX ? '100%' : '';
  1769. }
  1770. // Column search objects are in an array, so it needs to be converted
  1771. // element by element
  1772. var searchCols = init.aoSearchCols;
  1773. if ( searchCols ) {
  1774. for ( var i=0, ien=searchCols.length ; i<ien ; i++ ) {
  1775. if ( searchCols[i] ) {
  1776. _fnCamelToHungarian( DataTable.models.oSearch, searchCols[i] );
  1777. }
  1778. }
  1779. }
  1780. }
  1781. /**
  1782. * Provide backwards compatibility for column options. Note that the new options
  1783. * are mapped onto the old parameters, so this is an external interface change
  1784. * only.
  1785. * @param {object} init Object to map
  1786. */
  1787. function _fnCompatCols ( init )
  1788. {
  1789. _fnCompatMap( init, 'orderable', 'bSortable' );
  1790. _fnCompatMap( init, 'orderData', 'aDataSort' );
  1791. _fnCompatMap( init, 'orderSequence', 'asSorting' );
  1792. _fnCompatMap( init, 'orderDataType', 'sortDataType' );
  1793. // orderData can be given as an integer
  1794. var dataSort = init.aDataSort;
  1795. if ( typeof dataSort === 'number' && ! Array.isArray( dataSort ) ) {
  1796. init.aDataSort = [ dataSort ];
  1797. }
  1798. }
  1799. /**
  1800. * Browser feature detection for capabilities, quirks
  1801. * @param {object} settings dataTables settings object
  1802. * @memberof DataTable#oApi
  1803. */
  1804. function _fnBrowserDetect( settings )
  1805. {
  1806. // We don't need to do this every time DataTables is constructed, the values
  1807. // calculated are specific to the browser and OS configuration which we
  1808. // don't expect to change between initialisations
  1809. if ( ! DataTable.__browser ) {
  1810. var browser = {};
  1811. DataTable.__browser = browser;
  1812. // Scrolling feature / quirks detection
  1813. var n = $('<div/>')
  1814. .css( {
  1815. position: 'fixed',
  1816. top: 0,
  1817. left: $(window).scrollLeft()*-1, // allow for scrolling
  1818. height: 1,
  1819. width: 1,
  1820. overflow: 'hidden'
  1821. } )
  1822. .append(
  1823. $('<div/>')
  1824. .css( {
  1825. position: 'absolute',
  1826. top: 1,
  1827. left: 1,
  1828. width: 100,
  1829. overflow: 'scroll'
  1830. } )
  1831. .append(
  1832. $('<div/>')
  1833. .css( {
  1834. width: '100%',
  1835. height: 10
  1836. } )
  1837. )
  1838. )
  1839. .appendTo( 'body' );
  1840. var outer = n.children();
  1841. var inner = outer.children();
  1842. // Numbers below, in order, are:
  1843. // inner.offsetWidth, inner.clientWidth, outer.offsetWidth, outer.clientWidth
  1844. //
  1845. // IE6 XP: 100 100 100 83
  1846. // IE7 Vista: 100 100 100 83
  1847. // IE 8+ Windows: 83 83 100 83
  1848. // Evergreen Windows: 83 83 100 83
  1849. // Evergreen Mac with scrollbars: 85 85 100 85
  1850. // Evergreen Mac without scrollbars: 100 100 100 100
  1851. // Get scrollbar width
  1852. browser.barWidth = outer[0].offsetWidth - outer[0].clientWidth;
  1853. // IE6/7 will oversize a width 100% element inside a scrolling element, to
  1854. // include the width of the scrollbar, while other browsers ensure the inner
  1855. // element is contained without forcing scrolling
  1856. browser.bScrollOversize = inner[0].offsetWidth === 100 && outer[0].clientWidth !== 100;
  1857. // In rtl text layout, some browsers (most, but not all) will place the
  1858. // scrollbar on the left, rather than the right.
  1859. browser.bScrollbarLeft = Math.round( inner.offset().left ) !== 1;
  1860. // IE8- don't provide height and width for getBoundingClientRect
  1861. browser.bBounding = n[0].getBoundingClientRect().width ? true : false;
  1862. n.remove();
  1863. }
  1864. $.extend( settings.oBrowser, DataTable.__browser );
  1865. settings.oScroll.iBarWidth = DataTable.__browser.barWidth;
  1866. }
  1867. /**
  1868. * Array.prototype reduce[Right] method, used for browsers which don't support
  1869. * JS 1.6. Done this way to reduce code size, since we iterate either way
  1870. * @param {object} settings dataTables settings object
  1871. * @memberof DataTable#oApi
  1872. */
  1873. function _fnReduce ( that, fn, init, start, end, inc )
  1874. {
  1875. var
  1876. i = start,
  1877. value,
  1878. isSet = false;
  1879. if ( init !== undefined ) {
  1880. value = init;
  1881. isSet = true;
  1882. }
  1883. while ( i !== end ) {
  1884. if ( ! that.hasOwnProperty(i) ) {
  1885. continue;
  1886. }
  1887. value = isSet ?
  1888. fn( value, that[i], i, that ) :
  1889. that[i];
  1890. isSet = true;
  1891. i += inc;
  1892. }
  1893. return value;
  1894. }
  1895. /**
  1896. * Add a column to the list used for the table with default values
  1897. * @param {object} oSettings dataTables settings object
  1898. * @param {node} nTh The th element for this column
  1899. * @memberof DataTable#oApi
  1900. */
  1901. function _fnAddColumn( oSettings, nTh )
  1902. {
  1903. // Add column to aoColumns array
  1904. var oDefaults = DataTable.defaults.column;
  1905. var iCol = oSettings.aoColumns.length;
  1906. var oCol = $.extend( {}, DataTable.models.oColumn, oDefaults, {
  1907. "nTh": nTh ? nTh : document.createElement('th'),
  1908. "sTitle": oDefaults.sTitle ? oDefaults.sTitle : nTh ? nTh.innerHTML : '',
  1909. "aDataSort": oDefaults.aDataSort ? oDefaults.aDataSort : [iCol],
  1910. "mData": oDefaults.mData ? oDefaults.mData : iCol,
  1911. idx: iCol
  1912. } );
  1913. oSettings.aoColumns.push( oCol );
  1914. // Add search object for column specific search. Note that the `searchCols[ iCol ]`
  1915. // passed into extend can be undefined. This allows the user to give a default
  1916. // with only some of the parameters defined, and also not give a default
  1917. var searchCols = oSettings.aoPreSearchCols;
  1918. searchCols[ iCol ] = $.extend( {}, DataTable.models.oSearch, searchCols[ iCol ] );
  1919. // Use the default column options function to initialise classes etc
  1920. _fnColumnOptions( oSettings, iCol, $(nTh).data() );
  1921. }
  1922. /**
  1923. * Apply options for a column
  1924. * @param {object} oSettings dataTables settings object
  1925. * @param {int} iCol column index to consider
  1926. * @param {object} oOptions object with sType, bVisible and bSearchable etc
  1927. * @memberof DataTable#oApi
  1928. */
  1929. function _fnColumnOptions( oSettings, iCol, oOptions )
  1930. {
  1931. var oCol = oSettings.aoColumns[ iCol ];
  1932. var oClasses = oSettings.oClasses;
  1933. var th = $(oCol.nTh);
  1934. // Try to get width information from the DOM. We can't get it from CSS
  1935. // as we'd need to parse the CSS stylesheet. `width` option can override
  1936. if ( ! oCol.sWidthOrig ) {
  1937. // Width attribute
  1938. oCol.sWidthOrig = th.attr('width') || null;
  1939. // Style attribute
  1940. var t = (th.attr('style') || '').match(/width:\s*(\d+[pxem%]+)/);
  1941. if ( t ) {
  1942. oCol.sWidthOrig = t[1];
  1943. }
  1944. }
  1945. /* User specified column options */
  1946. if ( oOptions !== undefined && oOptions !== null )
  1947. {
  1948. // Backwards compatibility
  1949. _fnCompatCols( oOptions );
  1950. // Map camel case parameters to their Hungarian counterparts
  1951. _fnCamelToHungarian( DataTable.defaults.column, oOptions, true );
  1952. /* Backwards compatibility for mDataProp */
  1953. if ( oOptions.mDataProp !== undefined && !oOptions.mData )
  1954. {
  1955. oOptions.mData = oOptions.mDataProp;
  1956. }
  1957. if ( oOptions.sType )
  1958. {
  1959. oCol._sManualType = oOptions.sType;
  1960. }
  1961. // `class` is a reserved word in Javascript, so we need to provide
  1962. // the ability to use a valid name for the camel case input
  1963. if ( oOptions.className && ! oOptions.sClass )
  1964. {
  1965. oOptions.sClass = oOptions.className;
  1966. }
  1967. if ( oOptions.sClass ) {
  1968. th.addClass( oOptions.sClass );
  1969. }
  1970. var origClass = oCol.sClass;
  1971. $.extend( oCol, oOptions );
  1972. _fnMap( oCol, oOptions, "sWidth", "sWidthOrig" );
  1973. // Merge class from previously defined classes with this one, rather than just
  1974. // overwriting it in the extend above
  1975. if (origClass !== oCol.sClass) {
  1976. oCol.sClass = origClass + ' ' + oCol.sClass;
  1977. }
  1978. /* iDataSort to be applied (backwards compatibility), but aDataSort will take
  1979. * priority if defined
  1980. */
  1981. if ( oOptions.iDataSort !== undefined )
  1982. {
  1983. oCol.aDataSort = [ oOptions.iDataSort ];
  1984. }
  1985. _fnMap( oCol, oOptions, "aDataSort" );
  1986. }
  1987. /* Cache the data get and set functions for speed */
  1988. var mDataSrc = oCol.mData;
  1989. var mData = _fnGetObjectDataFn( mDataSrc );
  1990. var mRender = oCol.mRender ? _fnGetObjectDataFn( oCol.mRender ) : null;
  1991. var attrTest = function( src ) {
  1992. return typeof src === 'string' && src.indexOf('@') !== -1;
  1993. };
  1994. oCol._bAttrSrc = $.isPlainObject( mDataSrc ) && (
  1995. attrTest(mDataSrc.sort) || attrTest(mDataSrc.type) || attrTest(mDataSrc.filter)
  1996. );
  1997. oCol._setter = null;
  1998. oCol.fnGetData = function (rowData, type, meta) {
  1999. var innerData = mData( rowData, type, undefined, meta );
  2000. return mRender && type ?
  2001. mRender( innerData, type, rowData, meta ) :
  2002. innerData;
  2003. };
  2004. oCol.fnSetData = function ( rowData, val, meta ) {
  2005. return _fnSetObjectDataFn( mDataSrc )( rowData, val, meta );
  2006. };
  2007. // Indicate if DataTables should read DOM data as an object or array
  2008. // Used in _fnGetRowElements
  2009. if ( typeof mDataSrc !== 'number' && ! oCol._isArrayHost ) {
  2010. oSettings._rowReadObject = true;
  2011. }
  2012. /* Feature sorting overrides column specific when off */
  2013. if ( !oSettings.oFeatures.bSort )
  2014. {
  2015. oCol.bSortable = false;
  2016. th.addClass( oClasses.sSortableNone ); // Have to add class here as order event isn't called
  2017. }
  2018. /* Check that the class assignment is correct for sorting */
  2019. var bAsc = $.inArray('asc', oCol.asSorting) !== -1;
  2020. var bDesc = $.inArray('desc', oCol.asSorting) !== -1;
  2021. if ( !oCol.bSortable || (!bAsc && !bDesc) )
  2022. {
  2023. oCol.sSortingClass = oClasses.sSortableNone;
  2024. oCol.sSortingClassJUI = "";
  2025. }
  2026. else if ( bAsc && !bDesc )
  2027. {
  2028. oCol.sSortingClass = oClasses.sSortableAsc;
  2029. oCol.sSortingClassJUI = oClasses.sSortJUIAscAllowed;
  2030. }
  2031. else if ( !bAsc && bDesc )
  2032. {
  2033. oCol.sSortingClass = oClasses.sSortableDesc;
  2034. oCol.sSortingClassJUI = oClasses.sSortJUIDescAllowed;
  2035. }
  2036. else
  2037. {
  2038. oCol.sSortingClass = oClasses.sSortable;
  2039. oCol.sSortingClassJUI = oClasses.sSortJUI;
  2040. }
  2041. }
  2042. /**
  2043. * Adjust the table column widths for new data. Note: you would probably want to
  2044. * do a redraw after calling this function!
  2045. * @param {object} settings dataTables settings object
  2046. * @memberof DataTable#oApi
  2047. */
  2048. function _fnAdjustColumnSizing ( settings )
  2049. {
  2050. /* Not interested in doing column width calculation if auto-width is disabled */
  2051. if ( settings.oFeatures.bAutoWidth !== false )
  2052. {
  2053. var columns = settings.aoColumns;
  2054. _fnCalculateColumnWidths( settings );
  2055. for ( var i=0 , iLen=columns.length ; i<iLen ; i++ )
  2056. {
  2057. columns[i].nTh.style.width = columns[i].sWidth;
  2058. }
  2059. }
  2060. var scroll = settings.oScroll;
  2061. if ( scroll.sY !== '' || scroll.sX !== '')
  2062. {
  2063. _fnScrollDraw( settings );
  2064. }
  2065. _fnCallbackFire( settings, null, 'column-sizing', [settings] );
  2066. }
  2067. /**
  2068. * Convert the index of a visible column to the index in the data array (take account
  2069. * of hidden columns)
  2070. * @param {object} oSettings dataTables settings object
  2071. * @param {int} iMatch Visible column index to lookup
  2072. * @returns {int} i the data index
  2073. * @memberof DataTable#oApi
  2074. */
  2075. function _fnVisibleToColumnIndex( oSettings, iMatch )
  2076. {
  2077. var aiVis = _fnGetColumns( oSettings, 'bVisible' );
  2078. return typeof aiVis[iMatch] === 'number' ?
  2079. aiVis[iMatch] :
  2080. null;
  2081. }
  2082. /**
  2083. * Convert the index of an index in the data array and convert it to the visible
  2084. * column index (take account of hidden columns)
  2085. * @param {int} iMatch Column index to lookup
  2086. * @param {object} oSettings dataTables settings object
  2087. * @returns {int} i the data index
  2088. * @memberof DataTable#oApi
  2089. */
  2090. function _fnColumnIndexToVisible( oSettings, iMatch )
  2091. {
  2092. var aiVis = _fnGetColumns( oSettings, 'bVisible' );
  2093. var iPos = $.inArray( iMatch, aiVis );
  2094. return iPos !== -1 ? iPos : null;
  2095. }
  2096. /**
  2097. * Get the number of visible columns
  2098. * @param {object} oSettings dataTables settings object
  2099. * @returns {int} i the number of visible columns
  2100. * @memberof DataTable#oApi
  2101. */
  2102. function _fnVisbleColumns( oSettings )
  2103. {
  2104. var vis = 0;
  2105. // No reduce in IE8, use a loop for now
  2106. $.each( oSettings.aoColumns, function ( i, col ) {
  2107. if ( col.bVisible && $(col.nTh).css('display') !== 'none' ) {
  2108. vis++;
  2109. }
  2110. } );
  2111. return vis;
  2112. }
  2113. /**
  2114. * Get an array of column indexes that match a given property
  2115. * @param {object} oSettings dataTables settings object
  2116. * @param {string} sParam Parameter in aoColumns to look for - typically
  2117. * bVisible or bSearchable
  2118. * @returns {array} Array of indexes with matched properties
  2119. * @memberof DataTable#oApi
  2120. */
  2121. function _fnGetColumns( oSettings, sParam )
  2122. {
  2123. var a = [];
  2124. $.map( oSettings.aoColumns, function(val, i) {
  2125. if ( val[sParam] ) {
  2126. a.push( i );
  2127. }
  2128. } );
  2129. return a;
  2130. }
  2131. /**
  2132. * Calculate the 'type' of a column
  2133. * @param {object} settings dataTables settings object
  2134. * @memberof DataTable#oApi
  2135. */
  2136. function _fnColumnTypes ( settings )
  2137. {
  2138. var columns = settings.aoColumns;
  2139. var data = settings.aoData;
  2140. var types = DataTable.ext.type.detect;
  2141. var i, ien, j, jen, k, ken;
  2142. var col, cell, detectedType, cache;
  2143. // For each column, spin over the
  2144. for ( i=0, ien=columns.length ; i<ien ; i++ ) {
  2145. col = columns[i];
  2146. cache = [];
  2147. if ( ! col.sType && col._sManualType ) {
  2148. col.sType = col._sManualType;
  2149. }
  2150. else if ( ! col.sType ) {
  2151. for ( j=0, jen=types.length ; j<jen ; j++ ) {
  2152. for ( k=0, ken=data.length ; k<ken ; k++ ) {
  2153. // Use a cache array so we only need to get the type data
  2154. // from the formatter once (when using multiple detectors)
  2155. if ( cache[k] === undefined ) {
  2156. cache[k] = _fnGetCellData( settings, k, i, 'type' );
  2157. }
  2158. detectedType = types[j]( cache[k], settings );
  2159. // If null, then this type can't apply to this column, so
  2160. // rather than testing all cells, break out. There is an
  2161. // exception for the last type which is `html`. We need to
  2162. // scan all rows since it is possible to mix string and HTML
  2163. // types
  2164. if ( ! detectedType && j !== types.length-1 ) {
  2165. break;
  2166. }
  2167. // Only a single match is needed for html type since it is
  2168. // bottom of the pile and very similar to string - but it
  2169. // must not be empty
  2170. if ( detectedType === 'html' && ! _empty(cache[k]) ) {
  2171. break;
  2172. }
  2173. }
  2174. // Type is valid for all data points in the column - use this
  2175. // type
  2176. if ( detectedType ) {
  2177. col.sType = detectedType;
  2178. break;
  2179. }
  2180. }
  2181. // Fall back - if no type was detected, always use string
  2182. if ( ! col.sType ) {
  2183. col.sType = 'string';
  2184. }
  2185. }
  2186. }
  2187. }
  2188. /**
  2189. * Take the column definitions and static columns arrays and calculate how
  2190. * they relate to column indexes. The callback function will then apply the
  2191. * definition found for a column to a suitable configuration object.
  2192. * @param {object} oSettings dataTables settings object
  2193. * @param {array} aoColDefs The aoColumnDefs array that is to be applied
  2194. * @param {array} aoCols The aoColumns array that defines columns individually
  2195. * @param {function} fn Callback function - takes two parameters, the calculated
  2196. * column index and the definition for that column.
  2197. * @memberof DataTable#oApi
  2198. */
  2199. function _fnApplyColumnDefs( oSettings, aoColDefs, aoCols, fn )
  2200. {
  2201. var i, iLen, j, jLen, k, kLen, def;
  2202. var columns = oSettings.aoColumns;
  2203. // Column definitions with aTargets
  2204. if ( aoColDefs )
  2205. {
  2206. /* Loop over the definitions array - loop in reverse so first instance has priority */
  2207. for ( i=aoColDefs.length-1 ; i>=0 ; i-- )
  2208. {
  2209. def = aoColDefs[i];
  2210. /* Each definition can target multiple columns, as it is an array */
  2211. var aTargets = def.target !== undefined
  2212. ? def.target
  2213. : def.targets !== undefined
  2214. ? def.targets
  2215. : def.aTargets;
  2216. if ( ! Array.isArray( aTargets ) )
  2217. {
  2218. aTargets = [ aTargets ];
  2219. }
  2220. for ( j=0, jLen=aTargets.length ; j<jLen ; j++ )
  2221. {
  2222. if ( typeof aTargets[j] === 'number' && aTargets[j] >= 0 )
  2223. {
  2224. /* Add columns that we don't yet know about */
  2225. while( columns.length <= aTargets[j] )
  2226. {
  2227. _fnAddColumn( oSettings );
  2228. }
  2229. /* Integer, basic index */
  2230. fn( aTargets[j], def );
  2231. }
  2232. else if ( typeof aTargets[j] === 'number' && aTargets[j] < 0 )
  2233. {
  2234. /* Negative integer, right to left column counting */
  2235. fn( columns.length+aTargets[j], def );
  2236. }
  2237. else if ( typeof aTargets[j] === 'string' )
  2238. {
  2239. /* Class name matching on TH element */
  2240. for ( k=0, kLen=columns.length ; k<kLen ; k++ )
  2241. {
  2242. if ( aTargets[j] == "_all" ||
  2243. $(columns[k].nTh).hasClass( aTargets[j] ) )
  2244. {
  2245. fn( k, def );
  2246. }
  2247. }
  2248. }
  2249. }
  2250. }
  2251. }
  2252. // Statically defined columns array
  2253. if ( aoCols )
  2254. {
  2255. for ( i=0, iLen=aoCols.length ; i<iLen ; i++ )
  2256. {
  2257. fn( i, aoCols[i] );
  2258. }
  2259. }
  2260. }
  2261. /**
  2262. * Add a data array to the table, creating DOM node etc. This is the parallel to
  2263. * _fnGatherData, but for adding rows from a Javascript source, rather than a
  2264. * DOM source.
  2265. * @param {object} oSettings dataTables settings object
  2266. * @param {array} aData data array to be added
  2267. * @param {node} [nTr] TR element to add to the table - optional. If not given,
  2268. * DataTables will create a row automatically
  2269. * @param {array} [anTds] Array of TD|TH elements for the row - must be given
  2270. * if nTr is.
  2271. * @returns {int} >=0 if successful (index of new aoData entry), -1 if failed
  2272. * @memberof DataTable#oApi
  2273. */
  2274. function _fnAddData ( oSettings, aDataIn, nTr, anTds )
  2275. {
  2276. /* Create the object for storing information about this new row */
  2277. var iRow = oSettings.aoData.length;
  2278. var oData = $.extend( true, {}, DataTable.models.oRow, {
  2279. src: nTr ? 'dom' : 'data',
  2280. idx: iRow
  2281. } );
  2282. oData._aData = aDataIn;
  2283. oSettings.aoData.push( oData );
  2284. /* Create the cells */
  2285. var nTd, sThisType;
  2286. var columns = oSettings.aoColumns;
  2287. // Invalidate the column types as the new data needs to be revalidated
  2288. for ( var i=0, iLen=columns.length ; i<iLen ; i++ )
  2289. {
  2290. columns[i].sType = null;
  2291. }
  2292. /* Add to the display array */
  2293. oSettings.aiDisplayMaster.push( iRow );
  2294. var id = oSettings.rowIdFn( aDataIn );
  2295. if ( id !== undefined ) {
  2296. oSettings.aIds[ id ] = oData;
  2297. }
  2298. /* Create the DOM information, or register it if already present */
  2299. if ( nTr || ! oSettings.oFeatures.bDeferRender )
  2300. {
  2301. _fnCreateTr( oSettings, iRow, nTr, anTds );
  2302. }
  2303. return iRow;
  2304. }
  2305. /**
  2306. * Add one or more TR elements to the table. Generally we'd expect to
  2307. * use this for reading data from a DOM sourced table, but it could be
  2308. * used for an TR element. Note that if a TR is given, it is used (i.e.
  2309. * it is not cloned).
  2310. * @param {object} settings dataTables settings object
  2311. * @param {array|node|jQuery} trs The TR element(s) to add to the table
  2312. * @returns {array} Array of indexes for the added rows
  2313. * @memberof DataTable#oApi
  2314. */
  2315. function _fnAddTr( settings, trs )
  2316. {
  2317. var row;
  2318. // Allow an individual node to be passed in
  2319. if ( ! (trs instanceof $) ) {
  2320. trs = $(trs);
  2321. }
  2322. return trs.map( function (i, el) {
  2323. row = _fnGetRowElements( settings, el );
  2324. return _fnAddData( settings, row.data, el, row.cells );
  2325. } );
  2326. }
  2327. /**
  2328. * Take a TR element and convert it to an index in aoData
  2329. * @param {object} oSettings dataTables settings object
  2330. * @param {node} n the TR element to find
  2331. * @returns {int} index if the node is found, null if not
  2332. * @memberof DataTable#oApi
  2333. */
  2334. function _fnNodeToDataIndex( oSettings, n )
  2335. {
  2336. return (n._DT_RowIndex!==undefined) ? n._DT_RowIndex : null;
  2337. }
  2338. /**
  2339. * Take a TD element and convert it into a column data index (not the visible index)
  2340. * @param {object} oSettings dataTables settings object
  2341. * @param {int} iRow The row number the TD/TH can be found in
  2342. * @param {node} n The TD/TH element to find
  2343. * @returns {int} index if the node is found, -1 if not
  2344. * @memberof DataTable#oApi
  2345. */
  2346. function _fnNodeToColumnIndex( oSettings, iRow, n )
  2347. {
  2348. return $.inArray( n, oSettings.aoData[ iRow ].anCells );
  2349. }
  2350. /**
  2351. * Get the data for a given cell from the internal cache, taking into account data mapping
  2352. * @param {object} settings dataTables settings object
  2353. * @param {int} rowIdx aoData row id
  2354. * @param {int} colIdx Column index
  2355. * @param {string} type data get type ('display', 'type' 'filter|search' 'sort|order')
  2356. * @returns {*} Cell data
  2357. * @memberof DataTable#oApi
  2358. */
  2359. function _fnGetCellData( settings, rowIdx, colIdx, type )
  2360. {
  2361. if (type === 'search') {
  2362. type = 'filter';
  2363. }
  2364. else if (type === 'order') {
  2365. type = 'sort';
  2366. }
  2367. var draw = settings.iDraw;
  2368. var col = settings.aoColumns[colIdx];
  2369. var rowData = settings.aoData[rowIdx]._aData;
  2370. var defaultContent = col.sDefaultContent;
  2371. var cellData = col.fnGetData( rowData, type, {
  2372. settings: settings,
  2373. row: rowIdx,
  2374. col: colIdx
  2375. } );
  2376. if ( cellData === undefined ) {
  2377. if ( settings.iDrawError != draw && defaultContent === null ) {
  2378. _fnLog( settings, 0, "Requested unknown parameter "+
  2379. (typeof col.mData=='function' ? '{function}' : "'"+col.mData+"'")+
  2380. " for row "+rowIdx+", column "+colIdx, 4 );
  2381. settings.iDrawError = draw;
  2382. }
  2383. return defaultContent;
  2384. }
  2385. // When the data source is null and a specific data type is requested (i.e.
  2386. // not the original data), we can use default column data
  2387. if ( (cellData === rowData || cellData === null) && defaultContent !== null && type !== undefined ) {
  2388. cellData = defaultContent;
  2389. }
  2390. else if ( typeof cellData === 'function' ) {
  2391. // If the data source is a function, then we run it and use the return,
  2392. // executing in the scope of the data object (for instances)
  2393. return cellData.call( rowData );
  2394. }
  2395. if ( cellData === null && type === 'display' ) {
  2396. return '';
  2397. }
  2398. if ( type === 'filter' ) {
  2399. var fomatters = DataTable.ext.type.search;
  2400. if ( fomatters[ col.sType ] ) {
  2401. cellData = fomatters[ col.sType ]( cellData );
  2402. }
  2403. }
  2404. return cellData;
  2405. }
  2406. /**
  2407. * Set the value for a specific cell, into the internal data cache
  2408. * @param {object} settings dataTables settings object
  2409. * @param {int} rowIdx aoData row id
  2410. * @param {int} colIdx Column index
  2411. * @param {*} val Value to set
  2412. * @memberof DataTable#oApi
  2413. */
  2414. function _fnSetCellData( settings, rowIdx, colIdx, val )
  2415. {
  2416. var col = settings.aoColumns[colIdx];
  2417. var rowData = settings.aoData[rowIdx]._aData;
  2418. col.fnSetData( rowData, val, {
  2419. settings: settings,
  2420. row: rowIdx,
  2421. col: colIdx
  2422. } );
  2423. }
  2424. // Private variable that is used to match action syntax in the data property object
  2425. var __reArray = /\[.*?\]$/;
  2426. var __reFn = /\(\)$/;
  2427. /**
  2428. * Split string on periods, taking into account escaped periods
  2429. * @param {string} str String to split
  2430. * @return {array} Split string
  2431. */
  2432. function _fnSplitObjNotation( str )
  2433. {
  2434. return $.map( str.match(/(\\.|[^\.])+/g) || [''], function ( s ) {
  2435. return s.replace(/\\\./g, '.');
  2436. } );
  2437. }
  2438. /**
  2439. * Return a function that can be used to get data from a source object, taking
  2440. * into account the ability to use nested objects as a source
  2441. * @param {string|int|function} mSource The data source for the object
  2442. * @returns {function} Data get function
  2443. * @memberof DataTable#oApi
  2444. */
  2445. var _fnGetObjectDataFn = DataTable.util.get;
  2446. /**
  2447. * Return a function that can be used to set data from a source object, taking
  2448. * into account the ability to use nested objects as a source
  2449. * @param {string|int|function} mSource The data source for the object
  2450. * @returns {function} Data set function
  2451. * @memberof DataTable#oApi
  2452. */
  2453. var _fnSetObjectDataFn = DataTable.util.set;
  2454. /**
  2455. * Return an array with the full table data
  2456. * @param {object} oSettings dataTables settings object
  2457. * @returns array {array} aData Master data array
  2458. * @memberof DataTable#oApi
  2459. */
  2460. function _fnGetDataMaster ( settings )
  2461. {
  2462. return _pluck( settings.aoData, '_aData' );
  2463. }
  2464. /**
  2465. * Nuke the table
  2466. * @param {object} oSettings dataTables settings object
  2467. * @memberof DataTable#oApi
  2468. */
  2469. function _fnClearTable( settings )
  2470. {
  2471. settings.aoData.length = 0;
  2472. settings.aiDisplayMaster.length = 0;
  2473. settings.aiDisplay.length = 0;
  2474. settings.aIds = {};
  2475. }
  2476. /**
  2477. * Take an array of integers (index array) and remove a target integer (value - not
  2478. * the key!)
  2479. * @param {array} a Index array to target
  2480. * @param {int} iTarget value to find
  2481. * @memberof DataTable#oApi
  2482. */
  2483. function _fnDeleteIndex( a, iTarget, splice )
  2484. {
  2485. var iTargetIndex = -1;
  2486. for ( var i=0, iLen=a.length ; i<iLen ; i++ )
  2487. {
  2488. if ( a[i] == iTarget )
  2489. {
  2490. iTargetIndex = i;
  2491. }
  2492. else if ( a[i] > iTarget )
  2493. {
  2494. a[i]--;
  2495. }
  2496. }
  2497. if ( iTargetIndex != -1 && splice === undefined )
  2498. {
  2499. a.splice( iTargetIndex, 1 );
  2500. }
  2501. }
  2502. /**
  2503. * Mark cached data as invalid such that a re-read of the data will occur when
  2504. * the cached data is next requested. Also update from the data source object.
  2505. *
  2506. * @param {object} settings DataTables settings object
  2507. * @param {int} rowIdx Row index to invalidate
  2508. * @param {string} [src] Source to invalidate from: undefined, 'auto', 'dom'
  2509. * or 'data'
  2510. * @param {int} [colIdx] Column index to invalidate. If undefined the whole
  2511. * row will be invalidated
  2512. * @memberof DataTable#oApi
  2513. *
  2514. * @todo For the modularisation of v1.11 this will need to become a callback, so
  2515. * the sort and filter methods can subscribe to it. That will required
  2516. * initialisation options for sorting, which is why it is not already baked in
  2517. */
  2518. function _fnInvalidate( settings, rowIdx, src, colIdx )
  2519. {
  2520. var row = settings.aoData[ rowIdx ];
  2521. var i, ien;
  2522. var cellWrite = function ( cell, col ) {
  2523. // This is very frustrating, but in IE if you just write directly
  2524. // to innerHTML, and elements that are overwritten are GC'ed,
  2525. // even if there is a reference to them elsewhere
  2526. while ( cell.childNodes.length ) {
  2527. cell.removeChild( cell.firstChild );
  2528. }
  2529. cell.innerHTML = _fnGetCellData( settings, rowIdx, col, 'display' );
  2530. };
  2531. // Are we reading last data from DOM or the data object?
  2532. if ( src === 'dom' || ((! src || src === 'auto') && row.src === 'dom') ) {
  2533. // Read the data from the DOM
  2534. row._aData = _fnGetRowElements(
  2535. settings, row, colIdx, colIdx === undefined ? undefined : row._aData
  2536. )
  2537. .data;
  2538. }
  2539. else {
  2540. // Reading from data object, update the DOM
  2541. var cells = row.anCells;
  2542. if ( cells ) {
  2543. if ( colIdx !== undefined ) {
  2544. cellWrite( cells[colIdx], colIdx );
  2545. }
  2546. else {
  2547. for ( i=0, ien=cells.length ; i<ien ; i++ ) {
  2548. cellWrite( cells[i], i );
  2549. }
  2550. }
  2551. }
  2552. }
  2553. // For both row and cell invalidation, the cached data for sorting and
  2554. // filtering is nulled out
  2555. row._aSortData = null;
  2556. row._aFilterData = null;
  2557. // Invalidate the type for a specific column (if given) or all columns since
  2558. // the data might have changed
  2559. var cols = settings.aoColumns;
  2560. if ( colIdx !== undefined ) {
  2561. cols[ colIdx ].sType = null;
  2562. }
  2563. else {
  2564. for ( i=0, ien=cols.length ; i<ien ; i++ ) {
  2565. cols[i].sType = null;
  2566. }
  2567. // Update DataTables special `DT_*` attributes for the row
  2568. _fnRowAttributes( settings, row );
  2569. }
  2570. }
  2571. /**
  2572. * Build a data source object from an HTML row, reading the contents of the
  2573. * cells that are in the row.
  2574. *
  2575. * @param {object} settings DataTables settings object
  2576. * @param {node|object} TR element from which to read data or existing row
  2577. * object from which to re-read the data from the cells
  2578. * @param {int} [colIdx] Optional column index
  2579. * @param {array|object} [d] Data source object. If `colIdx` is given then this
  2580. * parameter should also be given and will be used to write the data into.
  2581. * Only the column in question will be written
  2582. * @returns {object} Object with two parameters: `data` the data read, in
  2583. * document order, and `cells` and array of nodes (they can be useful to the
  2584. * caller, so rather than needing a second traversal to get them, just return
  2585. * them from here).
  2586. * @memberof DataTable#oApi
  2587. */
  2588. function _fnGetRowElements( settings, row, colIdx, d )
  2589. {
  2590. var
  2591. tds = [],
  2592. td = row.firstChild,
  2593. name, col, o, i=0, contents,
  2594. columns = settings.aoColumns,
  2595. objectRead = settings._rowReadObject;
  2596. // Allow the data object to be passed in, or construct
  2597. d = d !== undefined ?
  2598. d :
  2599. objectRead ?
  2600. {} :
  2601. [];
  2602. var attr = function ( str, td ) {
  2603. if ( typeof str === 'string' ) {
  2604. var idx = str.indexOf('@');
  2605. if ( idx !== -1 ) {
  2606. var attr = str.substring( idx+1 );
  2607. var setter = _fnSetObjectDataFn( str );
  2608. setter( d, td.getAttribute( attr ) );
  2609. }
  2610. }
  2611. };
  2612. // Read data from a cell and store into the data object
  2613. var cellProcess = function ( cell ) {
  2614. if ( colIdx === undefined || colIdx === i ) {
  2615. col = columns[i];
  2616. contents = (cell.innerHTML).trim();
  2617. if ( col && col._bAttrSrc ) {
  2618. var setter = _fnSetObjectDataFn( col.mData._ );
  2619. setter( d, contents );
  2620. attr( col.mData.sort, cell );
  2621. attr( col.mData.type, cell );
  2622. attr( col.mData.filter, cell );
  2623. }
  2624. else {
  2625. // Depending on the `data` option for the columns the data can
  2626. // be read to either an object or an array.
  2627. if ( objectRead ) {
  2628. if ( ! col._setter ) {
  2629. // Cache the setter function
  2630. col._setter = _fnSetObjectDataFn( col.mData );
  2631. }
  2632. col._setter( d, contents );
  2633. }
  2634. else {
  2635. d[i] = contents;
  2636. }
  2637. }
  2638. }
  2639. i++;
  2640. };
  2641. if ( td ) {
  2642. // `tr` element was passed in
  2643. while ( td ) {
  2644. name = td.nodeName.toUpperCase();
  2645. if ( name == "TD" || name == "TH" ) {
  2646. cellProcess( td );
  2647. tds.push( td );
  2648. }
  2649. td = td.nextSibling;
  2650. }
  2651. }
  2652. else {
  2653. // Existing row object passed in
  2654. tds = row.anCells;
  2655. for ( var j=0, jen=tds.length ; j<jen ; j++ ) {
  2656. cellProcess( tds[j] );
  2657. }
  2658. }
  2659. // Read the ID from the DOM if present
  2660. var rowNode = row.firstChild ? row : row.nTr;
  2661. if ( rowNode ) {
  2662. var id = rowNode.getAttribute( 'id' );
  2663. if ( id ) {
  2664. _fnSetObjectDataFn( settings.rowId )( d, id );
  2665. }
  2666. }
  2667. return {
  2668. data: d,
  2669. cells: tds
  2670. };
  2671. }
  2672. /**
  2673. * Create a new TR element (and it's TD children) for a row
  2674. * @param {object} oSettings dataTables settings object
  2675. * @param {int} iRow Row to consider
  2676. * @param {node} [nTrIn] TR element to add to the table - optional. If not given,
  2677. * DataTables will create a row automatically
  2678. * @param {array} [anTds] Array of TD|TH elements for the row - must be given
  2679. * if nTr is.
  2680. * @memberof DataTable#oApi
  2681. */
  2682. function _fnCreateTr ( oSettings, iRow, nTrIn, anTds )
  2683. {
  2684. var
  2685. row = oSettings.aoData[iRow],
  2686. rowData = row._aData,
  2687. cells = [],
  2688. nTr, nTd, oCol,
  2689. i, iLen, create;
  2690. if ( row.nTr === null )
  2691. {
  2692. nTr = nTrIn || document.createElement('tr');
  2693. row.nTr = nTr;
  2694. row.anCells = cells;
  2695. /* Use a private property on the node to allow reserve mapping from the node
  2696. * to the aoData array for fast look up
  2697. */
  2698. nTr._DT_RowIndex = iRow;
  2699. /* Special parameters can be given by the data source to be used on the row */
  2700. _fnRowAttributes( oSettings, row );
  2701. /* Process each column */
  2702. for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
  2703. {
  2704. oCol = oSettings.aoColumns[i];
  2705. create = nTrIn ? false : true;
  2706. nTd = create ? document.createElement( oCol.sCellType ) : anTds[i];
  2707. if (! nTd) {
  2708. _fnLog( oSettings, 0, 'Incorrect column count', 18 );
  2709. }
  2710. nTd._DT_CellIndex = {
  2711. row: iRow,
  2712. column: i
  2713. };
  2714. cells.push( nTd );
  2715. // Need to create the HTML if new, or if a rendering function is defined
  2716. if ( create || ((oCol.mRender || oCol.mData !== i) &&
  2717. (!$.isPlainObject(oCol.mData) || oCol.mData._ !== i+'.display')
  2718. )) {
  2719. nTd.innerHTML = _fnGetCellData( oSettings, iRow, i, 'display' );
  2720. }
  2721. /* Add user defined class */
  2722. if ( oCol.sClass )
  2723. {
  2724. nTd.className += ' '+oCol.sClass;
  2725. }
  2726. // Visibility - add or remove as required
  2727. if ( oCol.bVisible && ! nTrIn )
  2728. {
  2729. nTr.appendChild( nTd );
  2730. }
  2731. else if ( ! oCol.bVisible && nTrIn )
  2732. {
  2733. nTd.parentNode.removeChild( nTd );
  2734. }
  2735. if ( oCol.fnCreatedCell )
  2736. {
  2737. oCol.fnCreatedCell.call( oSettings.oInstance,
  2738. nTd, _fnGetCellData( oSettings, iRow, i ), rowData, iRow, i
  2739. );
  2740. }
  2741. }
  2742. _fnCallbackFire( oSettings, 'aoRowCreatedCallback', null, [nTr, rowData, iRow, cells] );
  2743. }
  2744. }
  2745. /**
  2746. * Add attributes to a row based on the special `DT_*` parameters in a data
  2747. * source object.
  2748. * @param {object} settings DataTables settings object
  2749. * @param {object} DataTables row object for the row to be modified
  2750. * @memberof DataTable#oApi
  2751. */
  2752. function _fnRowAttributes( settings, row )
  2753. {
  2754. var tr = row.nTr;
  2755. var data = row._aData;
  2756. if ( tr ) {
  2757. var id = settings.rowIdFn( data );
  2758. if ( id ) {
  2759. tr.id = id;
  2760. }
  2761. if ( data.DT_RowClass ) {
  2762. // Remove any classes added by DT_RowClass before
  2763. var a = data.DT_RowClass.split(' ');
  2764. row.__rowc = row.__rowc ?
  2765. _unique( row.__rowc.concat( a ) ) :
  2766. a;
  2767. $(tr)
  2768. .removeClass( row.__rowc.join(' ') )
  2769. .addClass( data.DT_RowClass );
  2770. }
  2771. if ( data.DT_RowAttr ) {
  2772. $(tr).attr( data.DT_RowAttr );
  2773. }
  2774. if ( data.DT_RowData ) {
  2775. $(tr).data( data.DT_RowData );
  2776. }
  2777. }
  2778. }
  2779. /**
  2780. * Create the HTML header for the table
  2781. * @param {object} oSettings dataTables settings object
  2782. * @memberof DataTable#oApi
  2783. */
  2784. function _fnBuildHead( oSettings )
  2785. {
  2786. var i, ien, cell, row, column;
  2787. var thead = oSettings.nTHead;
  2788. var tfoot = oSettings.nTFoot;
  2789. var createHeader = $('th, td', thead).length === 0;
  2790. var classes = oSettings.oClasses;
  2791. var columns = oSettings.aoColumns;
  2792. if ( createHeader ) {
  2793. row = $('<tr/>').appendTo( thead );
  2794. }
  2795. for ( i=0, ien=columns.length ; i<ien ; i++ ) {
  2796. column = columns[i];
  2797. cell = $( column.nTh ).addClass( column.sClass );
  2798. if ( createHeader ) {
  2799. cell.appendTo( row );
  2800. }
  2801. // 1.11 move into sorting
  2802. if ( oSettings.oFeatures.bSort ) {
  2803. cell.addClass( column.sSortingClass );
  2804. if ( column.bSortable !== false ) {
  2805. cell
  2806. .attr( 'tabindex', oSettings.iTabIndex )
  2807. .attr( 'aria-controls', oSettings.sTableId );
  2808. _fnSortAttachListener( oSettings, column.nTh, i );
  2809. }
  2810. }
  2811. if ( column.sTitle != cell[0].innerHTML ) {
  2812. cell.html( column.sTitle );
  2813. }
  2814. _fnRenderer( oSettings, 'header' )(
  2815. oSettings, cell, column, classes
  2816. );
  2817. }
  2818. if ( createHeader ) {
  2819. _fnDetectHeader( oSettings.aoHeader, thead );
  2820. }
  2821. /* Deal with the footer - add classes if required */
  2822. $(thead).children('tr').children('th, td').addClass( classes.sHeaderTH );
  2823. $(tfoot).children('tr').children('th, td').addClass( classes.sFooterTH );
  2824. // Cache the footer cells. Note that we only take the cells from the first
  2825. // row in the footer. If there is more than one row the user wants to
  2826. // interact with, they need to use the table().foot() method. Note also this
  2827. // allows cells to be used for multiple columns using colspan
  2828. if ( tfoot !== null ) {
  2829. var cells = oSettings.aoFooter[0];
  2830. for ( i=0, ien=cells.length ; i<ien ; i++ ) {
  2831. column = columns[i];
  2832. if (column) {
  2833. column.nTf = cells[i].cell;
  2834. if ( column.sClass ) {
  2835. $(column.nTf).addClass( column.sClass );
  2836. }
  2837. }
  2838. else {
  2839. _fnLog( oSettings, 0, 'Incorrect column count', 18 );
  2840. }
  2841. }
  2842. }
  2843. }
  2844. /**
  2845. * Draw the header (or footer) element based on the column visibility states. The
  2846. * methodology here is to use the layout array from _fnDetectHeader, modified for
  2847. * the instantaneous column visibility, to construct the new layout. The grid is
  2848. * traversed over cell at a time in a rows x columns grid fashion, although each
  2849. * cell insert can cover multiple elements in the grid - which is tracks using the
  2850. * aApplied array. Cell inserts in the grid will only occur where there isn't
  2851. * already a cell in that position.
  2852. * @param {object} oSettings dataTables settings object
  2853. * @param array {objects} aoSource Layout array from _fnDetectHeader
  2854. * @param {boolean} [bIncludeHidden=false] If true then include the hidden columns in the calc,
  2855. * @memberof DataTable#oApi
  2856. */
  2857. function _fnDrawHead( oSettings, aoSource, bIncludeHidden )
  2858. {
  2859. var i, iLen, j, jLen, k, kLen, n, nLocalTr;
  2860. var aoLocal = [];
  2861. var aApplied = [];
  2862. var iColumns = oSettings.aoColumns.length;
  2863. var iRowspan, iColspan;
  2864. if ( ! aoSource )
  2865. {
  2866. return;
  2867. }
  2868. if ( bIncludeHidden === undefined )
  2869. {
  2870. bIncludeHidden = false;
  2871. }
  2872. /* Make a copy of the master layout array, but without the visible columns in it */
  2873. for ( i=0, iLen=aoSource.length ; i<iLen ; i++ )
  2874. {
  2875. aoLocal[i] = aoSource[i].slice();
  2876. aoLocal[i].nTr = aoSource[i].nTr;
  2877. /* Remove any columns which are currently hidden */
  2878. for ( j=iColumns-1 ; j>=0 ; j-- )
  2879. {
  2880. if ( !oSettings.aoColumns[j].bVisible && !bIncludeHidden )
  2881. {
  2882. aoLocal[i].splice( j, 1 );
  2883. }
  2884. }
  2885. /* Prep the applied array - it needs an element for each row */
  2886. aApplied.push( [] );
  2887. }
  2888. for ( i=0, iLen=aoLocal.length ; i<iLen ; i++ )
  2889. {
  2890. nLocalTr = aoLocal[i].nTr;
  2891. /* All cells are going to be replaced, so empty out the row */
  2892. if ( nLocalTr )
  2893. {
  2894. while( (n = nLocalTr.firstChild) )
  2895. {
  2896. nLocalTr.removeChild( n );
  2897. }
  2898. }
  2899. for ( j=0, jLen=aoLocal[i].length ; j<jLen ; j++ )
  2900. {
  2901. iRowspan = 1;
  2902. iColspan = 1;
  2903. /* Check to see if there is already a cell (row/colspan) covering our target
  2904. * insert point. If there is, then there is nothing to do.
  2905. */
  2906. if ( aApplied[i][j] === undefined )
  2907. {
  2908. nLocalTr.appendChild( aoLocal[i][j].cell );
  2909. aApplied[i][j] = 1;
  2910. /* Expand the cell to cover as many rows as needed */
  2911. while ( aoLocal[i+iRowspan] !== undefined &&
  2912. aoLocal[i][j].cell == aoLocal[i+iRowspan][j].cell )
  2913. {
  2914. aApplied[i+iRowspan][j] = 1;
  2915. iRowspan++;
  2916. }
  2917. /* Expand the cell to cover as many columns as needed */
  2918. while ( aoLocal[i][j+iColspan] !== undefined &&
  2919. aoLocal[i][j].cell == aoLocal[i][j+iColspan].cell )
  2920. {
  2921. /* Must update the applied array over the rows for the columns */
  2922. for ( k=0 ; k<iRowspan ; k++ )
  2923. {
  2924. aApplied[i+k][j+iColspan] = 1;
  2925. }
  2926. iColspan++;
  2927. }
  2928. /* Do the actual expansion in the DOM */
  2929. $(aoLocal[i][j].cell)
  2930. .attr('rowspan', iRowspan)
  2931. .attr('colspan', iColspan);
  2932. }
  2933. }
  2934. }
  2935. }
  2936. /**
  2937. * Insert the required TR nodes into the table for display
  2938. * @param {object} oSettings dataTables settings object
  2939. * @param ajaxComplete true after ajax call to complete rendering
  2940. * @memberof DataTable#oApi
  2941. */
  2942. function _fnDraw( oSettings, ajaxComplete )
  2943. {
  2944. // Allow for state saving and a custom start position
  2945. _fnStart( oSettings );
  2946. /* Provide a pre-callback function which can be used to cancel the draw is false is returned */
  2947. var aPreDraw = _fnCallbackFire( oSettings, 'aoPreDrawCallback', 'preDraw', [oSettings] );
  2948. if ( $.inArray( false, aPreDraw ) !== -1 )
  2949. {
  2950. _fnProcessingDisplay( oSettings, false );
  2951. return;
  2952. }
  2953. var anRows = [];
  2954. var iRowCount = 0;
  2955. var asStripeClasses = oSettings.asStripeClasses;
  2956. var iStripes = asStripeClasses.length;
  2957. var oLang = oSettings.oLanguage;
  2958. var bServerSide = _fnDataSource( oSettings ) == 'ssp';
  2959. var aiDisplay = oSettings.aiDisplay;
  2960. var iDisplayStart = oSettings._iDisplayStart;
  2961. var iDisplayEnd = oSettings.fnDisplayEnd();
  2962. oSettings.bDrawing = true;
  2963. /* Server-side processing draw intercept */
  2964. if ( oSettings.bDeferLoading )
  2965. {
  2966. oSettings.bDeferLoading = false;
  2967. oSettings.iDraw++;
  2968. _fnProcessingDisplay( oSettings, false );
  2969. }
  2970. else if ( !bServerSide )
  2971. {
  2972. oSettings.iDraw++;
  2973. }
  2974. else if ( !oSettings.bDestroying && !ajaxComplete)
  2975. {
  2976. _fnAjaxUpdate( oSettings );
  2977. return;
  2978. }
  2979. if ( aiDisplay.length !== 0 )
  2980. {
  2981. var iStart = bServerSide ? 0 : iDisplayStart;
  2982. var iEnd = bServerSide ? oSettings.aoData.length : iDisplayEnd;
  2983. for ( var j=iStart ; j<iEnd ; j++ )
  2984. {
  2985. var iDataIndex = aiDisplay[j];
  2986. var aoData = oSettings.aoData[ iDataIndex ];
  2987. if ( aoData.nTr === null )
  2988. {
  2989. _fnCreateTr( oSettings, iDataIndex );
  2990. }
  2991. var nRow = aoData.nTr;
  2992. /* Remove the old striping classes and then add the new one */
  2993. if ( iStripes !== 0 )
  2994. {
  2995. var sStripe = asStripeClasses[ iRowCount % iStripes ];
  2996. if ( aoData._sRowStripe != sStripe )
  2997. {
  2998. $(nRow).removeClass( aoData._sRowStripe ).addClass( sStripe );
  2999. aoData._sRowStripe = sStripe;
  3000. }
  3001. }
  3002. // Row callback functions - might want to manipulate the row
  3003. // iRowCount and j are not currently documented. Are they at all
  3004. // useful?
  3005. _fnCallbackFire( oSettings, 'aoRowCallback', null,
  3006. [nRow, aoData._aData, iRowCount, j, iDataIndex] );
  3007. anRows.push( nRow );
  3008. iRowCount++;
  3009. }
  3010. }
  3011. else
  3012. {
  3013. /* Table is empty - create a row with an empty message in it */
  3014. var sZero = oLang.sZeroRecords;
  3015. if ( oSettings.iDraw == 1 && _fnDataSource( oSettings ) == 'ajax' )
  3016. {
  3017. sZero = oLang.sLoadingRecords;
  3018. }
  3019. else if ( oLang.sEmptyTable && oSettings.fnRecordsTotal() === 0 )
  3020. {
  3021. sZero = oLang.sEmptyTable;
  3022. }
  3023. anRows[ 0 ] = $( '<tr/>', { 'class': iStripes ? asStripeClasses[0] : '' } )
  3024. .append( $('<td />', {
  3025. 'valign': 'top',
  3026. 'colSpan': _fnVisbleColumns( oSettings ),
  3027. 'class': oSettings.oClasses.sRowEmpty
  3028. } ).html( sZero ) )[0];
  3029. }
  3030. /* Header and footer callbacks */
  3031. _fnCallbackFire( oSettings, 'aoHeaderCallback', 'header', [ $(oSettings.nTHead).children('tr')[0],
  3032. _fnGetDataMaster( oSettings ), iDisplayStart, iDisplayEnd, aiDisplay ] );
  3033. _fnCallbackFire( oSettings, 'aoFooterCallback', 'footer', [ $(oSettings.nTFoot).children('tr')[0],
  3034. _fnGetDataMaster( oSettings ), iDisplayStart, iDisplayEnd, aiDisplay ] );
  3035. var body = $(oSettings.nTBody);
  3036. body.children().detach();
  3037. body.append( $(anRows) );
  3038. /* Call all required callback functions for the end of a draw */
  3039. _fnCallbackFire( oSettings, 'aoDrawCallback', 'draw', [oSettings] );
  3040. /* Draw is complete, sorting and filtering must be as well */
  3041. oSettings.bSorted = false;
  3042. oSettings.bFiltered = false;
  3043. oSettings.bDrawing = false;
  3044. }
  3045. /**
  3046. * Redraw the table - taking account of the various features which are enabled
  3047. * @param {object} oSettings dataTables settings object
  3048. * @param {boolean} [holdPosition] Keep the current paging position. By default
  3049. * the paging is reset to the first page
  3050. * @memberof DataTable#oApi
  3051. */
  3052. function _fnReDraw( settings, holdPosition )
  3053. {
  3054. var
  3055. features = settings.oFeatures,
  3056. sort = features.bSort,
  3057. filter = features.bFilter;
  3058. if ( sort ) {
  3059. _fnSort( settings );
  3060. }
  3061. if ( filter ) {
  3062. _fnFilterComplete( settings, settings.oPreviousSearch );
  3063. }
  3064. else {
  3065. // No filtering, so we want to just use the display master
  3066. settings.aiDisplay = settings.aiDisplayMaster.slice();
  3067. }
  3068. if ( holdPosition !== true ) {
  3069. settings._iDisplayStart = 0;
  3070. }
  3071. // Let any modules know about the draw hold position state (used by
  3072. // scrolling internally)
  3073. settings._drawHold = holdPosition;
  3074. _fnDraw( settings );
  3075. settings._drawHold = false;
  3076. }
  3077. /**
  3078. * Add the options to the page HTML for the table
  3079. * @param {object} oSettings dataTables settings object
  3080. * @memberof DataTable#oApi
  3081. */
  3082. function _fnAddOptionsHtml ( oSettings )
  3083. {
  3084. var classes = oSettings.oClasses;
  3085. var table = $(oSettings.nTable);
  3086. var holding = $('<div/>').insertBefore( table ); // Holding element for speed
  3087. var features = oSettings.oFeatures;
  3088. // All DataTables are wrapped in a div
  3089. var insert = $('<div/>', {
  3090. id: oSettings.sTableId+'_wrapper',
  3091. 'class': classes.sWrapper + (oSettings.nTFoot ? '' : ' '+classes.sNoFooter)
  3092. } );
  3093. oSettings.nHolding = holding[0];
  3094. oSettings.nTableWrapper = insert[0];
  3095. oSettings.nTableReinsertBefore = oSettings.nTable.nextSibling;
  3096. /* Loop over the user set positioning and place the elements as needed */
  3097. var aDom = oSettings.sDom.split('');
  3098. var featureNode, cOption, nNewNode, cNext, sAttr, j;
  3099. for ( var i=0 ; i<aDom.length ; i++ )
  3100. {
  3101. featureNode = null;
  3102. cOption = aDom[i];
  3103. if ( cOption == '<' )
  3104. {
  3105. /* New container div */
  3106. nNewNode = $('<div/>')[0];
  3107. /* Check to see if we should append an id and/or a class name to the container */
  3108. cNext = aDom[i+1];
  3109. if ( cNext == "'" || cNext == '"' )
  3110. {
  3111. sAttr = "";
  3112. j = 2;
  3113. while ( aDom[i+j] != cNext )
  3114. {
  3115. sAttr += aDom[i+j];
  3116. j++;
  3117. }
  3118. /* Replace jQuery UI constants @todo depreciated */
  3119. if ( sAttr == "H" )
  3120. {
  3121. sAttr = classes.sJUIHeader;
  3122. }
  3123. else if ( sAttr == "F" )
  3124. {
  3125. sAttr = classes.sJUIFooter;
  3126. }
  3127. /* The attribute can be in the format of "#id.class", "#id" or "class" This logic
  3128. * breaks the string into parts and applies them as needed
  3129. */
  3130. if ( sAttr.indexOf('.') != -1 )
  3131. {
  3132. var aSplit = sAttr.split('.');
  3133. nNewNode.id = aSplit[0].substr(1, aSplit[0].length-1);
  3134. nNewNode.className = aSplit[1];
  3135. }
  3136. else if ( sAttr.charAt(0) == "#" )
  3137. {
  3138. nNewNode.id = sAttr.substr(1, sAttr.length-1);
  3139. }
  3140. else
  3141. {
  3142. nNewNode.className = sAttr;
  3143. }
  3144. i += j; /* Move along the position array */
  3145. }
  3146. insert.append( nNewNode );
  3147. insert = $(nNewNode);
  3148. }
  3149. else if ( cOption == '>' )
  3150. {
  3151. /* End container div */
  3152. insert = insert.parent();
  3153. }
  3154. // @todo Move options into their own plugins?
  3155. else if ( cOption == 'l' && features.bPaginate && features.bLengthChange )
  3156. {
  3157. /* Length */
  3158. featureNode = _fnFeatureHtmlLength( oSettings );
  3159. }
  3160. else if ( cOption == 'f' && features.bFilter )
  3161. {
  3162. /* Filter */
  3163. featureNode = _fnFeatureHtmlFilter( oSettings );
  3164. }
  3165. else if ( cOption == 'r' && features.bProcessing )
  3166. {
  3167. /* pRocessing */
  3168. featureNode = _fnFeatureHtmlProcessing( oSettings );
  3169. }
  3170. else if ( cOption == 't' )
  3171. {
  3172. /* Table */
  3173. featureNode = _fnFeatureHtmlTable( oSettings );
  3174. }
  3175. else if ( cOption == 'i' && features.bInfo )
  3176. {
  3177. /* Info */
  3178. featureNode = _fnFeatureHtmlInfo( oSettings );
  3179. }
  3180. else if ( cOption == 'p' && features.bPaginate )
  3181. {
  3182. /* Pagination */
  3183. featureNode = _fnFeatureHtmlPaginate( oSettings );
  3184. }
  3185. else if ( DataTable.ext.feature.length !== 0 )
  3186. {
  3187. /* Plug-in features */
  3188. var aoFeatures = DataTable.ext.feature;
  3189. for ( var k=0, kLen=aoFeatures.length ; k<kLen ; k++ )
  3190. {
  3191. if ( cOption == aoFeatures[k].cFeature )
  3192. {
  3193. featureNode = aoFeatures[k].fnInit( oSettings );
  3194. break;
  3195. }
  3196. }
  3197. }
  3198. /* Add to the 2D features array */
  3199. if ( featureNode )
  3200. {
  3201. var aanFeatures = oSettings.aanFeatures;
  3202. if ( ! aanFeatures[cOption] )
  3203. {
  3204. aanFeatures[cOption] = [];
  3205. }
  3206. aanFeatures[cOption].push( featureNode );
  3207. insert.append( featureNode );
  3208. }
  3209. }
  3210. /* Built our DOM structure - replace the holding div with what we want */
  3211. holding.replaceWith( insert );
  3212. oSettings.nHolding = null;
  3213. }
  3214. /**
  3215. * Use the DOM source to create up an array of header cells. The idea here is to
  3216. * create a layout grid (array) of rows x columns, which contains a reference
  3217. * to the cell that that point in the grid (regardless of col/rowspan), such that
  3218. * any column / row could be removed and the new grid constructed
  3219. * @param array {object} aLayout Array to store the calculated layout in
  3220. * @param {node} nThead The header/footer element for the table
  3221. * @memberof DataTable#oApi
  3222. */
  3223. function _fnDetectHeader ( aLayout, nThead )
  3224. {
  3225. var nTrs = $(nThead).children('tr');
  3226. var nTr, nCell;
  3227. var i, k, l, iLen, jLen, iColShifted, iColumn, iColspan, iRowspan;
  3228. var bUnique;
  3229. var fnShiftCol = function ( a, i, j ) {
  3230. var k = a[i];
  3231. while ( k[j] ) {
  3232. j++;
  3233. }
  3234. return j;
  3235. };
  3236. aLayout.splice( 0, aLayout.length );
  3237. /* We know how many rows there are in the layout - so prep it */
  3238. for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
  3239. {
  3240. aLayout.push( [] );
  3241. }
  3242. /* Calculate a layout array */
  3243. for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
  3244. {
  3245. nTr = nTrs[i];
  3246. iColumn = 0;
  3247. /* For every cell in the row... */
  3248. nCell = nTr.firstChild;
  3249. while ( nCell ) {
  3250. if ( nCell.nodeName.toUpperCase() == "TD" ||
  3251. nCell.nodeName.toUpperCase() == "TH" )
  3252. {
  3253. /* Get the col and rowspan attributes from the DOM and sanitise them */
  3254. iColspan = nCell.getAttribute('colspan') * 1;
  3255. iRowspan = nCell.getAttribute('rowspan') * 1;
  3256. iColspan = (!iColspan || iColspan===0 || iColspan===1) ? 1 : iColspan;
  3257. iRowspan = (!iRowspan || iRowspan===0 || iRowspan===1) ? 1 : iRowspan;
  3258. /* There might be colspan cells already in this row, so shift our target
  3259. * accordingly
  3260. */
  3261. iColShifted = fnShiftCol( aLayout, i, iColumn );
  3262. /* Cache calculation for unique columns */
  3263. bUnique = iColspan === 1 ? true : false;
  3264. /* If there is col / rowspan, copy the information into the layout grid */
  3265. for ( l=0 ; l<iColspan ; l++ )
  3266. {
  3267. for ( k=0 ; k<iRowspan ; k++ )
  3268. {
  3269. aLayout[i+k][iColShifted+l] = {
  3270. "cell": nCell,
  3271. "unique": bUnique
  3272. };
  3273. aLayout[i+k].nTr = nTr;
  3274. }
  3275. }
  3276. }
  3277. nCell = nCell.nextSibling;
  3278. }
  3279. }
  3280. }
  3281. /**
  3282. * Get an array of unique th elements, one for each column
  3283. * @param {object} oSettings dataTables settings object
  3284. * @param {node} nHeader automatically detect the layout from this node - optional
  3285. * @param {array} aLayout thead/tfoot layout from _fnDetectHeader - optional
  3286. * @returns array {node} aReturn list of unique th's
  3287. * @memberof DataTable#oApi
  3288. */
  3289. function _fnGetUniqueThs ( oSettings, nHeader, aLayout )
  3290. {
  3291. var aReturn = [];
  3292. if ( !aLayout )
  3293. {
  3294. aLayout = oSettings.aoHeader;
  3295. if ( nHeader )
  3296. {
  3297. aLayout = [];
  3298. _fnDetectHeader( aLayout, nHeader );
  3299. }
  3300. }
  3301. for ( var i=0, iLen=aLayout.length ; i<iLen ; i++ )
  3302. {
  3303. for ( var j=0, jLen=aLayout[i].length ; j<jLen ; j++ )
  3304. {
  3305. if ( aLayout[i][j].unique &&
  3306. (!aReturn[j] || !oSettings.bSortCellsTop) )
  3307. {
  3308. aReturn[j] = aLayout[i][j].cell;
  3309. }
  3310. }
  3311. }
  3312. return aReturn;
  3313. }
  3314. /**
  3315. * Set the start position for draw
  3316. * @param {object} oSettings dataTables settings object
  3317. */
  3318. function _fnStart( oSettings )
  3319. {
  3320. var bServerSide = _fnDataSource( oSettings ) == 'ssp';
  3321. var iInitDisplayStart = oSettings.iInitDisplayStart;
  3322. // Check and see if we have an initial draw position from state saving
  3323. if ( iInitDisplayStart !== undefined && iInitDisplayStart !== -1 )
  3324. {
  3325. oSettings._iDisplayStart = bServerSide ?
  3326. iInitDisplayStart :
  3327. iInitDisplayStart >= oSettings.fnRecordsDisplay() ?
  3328. 0 :
  3329. iInitDisplayStart;
  3330. oSettings.iInitDisplayStart = -1;
  3331. }
  3332. }
  3333. /**
  3334. * Create an Ajax call based on the table's settings, taking into account that
  3335. * parameters can have multiple forms, and backwards compatibility.
  3336. *
  3337. * @param {object} oSettings dataTables settings object
  3338. * @param {array} data Data to send to the server, required by
  3339. * DataTables - may be augmented by developer callbacks
  3340. * @param {function} fn Callback function to run when data is obtained
  3341. */
  3342. function _fnBuildAjax( oSettings, data, fn )
  3343. {
  3344. // Compatibility with 1.9-, allow fnServerData and event to manipulate
  3345. _fnCallbackFire( oSettings, 'aoServerParams', 'serverParams', [data] );
  3346. // Convert to object based for 1.10+ if using the old array scheme which can
  3347. // come from server-side processing or serverParams
  3348. if ( data && Array.isArray(data) ) {
  3349. var tmp = {};
  3350. var rbracket = /(.*?)\[\]$/;
  3351. $.each( data, function (key, val) {
  3352. var match = val.name.match(rbracket);
  3353. if ( match ) {
  3354. // Support for arrays
  3355. var name = match[0];
  3356. if ( ! tmp[ name ] ) {
  3357. tmp[ name ] = [];
  3358. }
  3359. tmp[ name ].push( val.value );
  3360. }
  3361. else {
  3362. tmp[val.name] = val.value;
  3363. }
  3364. } );
  3365. data = tmp;
  3366. }
  3367. var ajaxData;
  3368. var ajax = oSettings.ajax;
  3369. var instance = oSettings.oInstance;
  3370. var callback = function ( json ) {
  3371. var status = oSettings.jqXHR
  3372. ? oSettings.jqXHR.status
  3373. : null;
  3374. if ( json === null || (typeof status === 'number' && status == 204 ) ) {
  3375. json = {};
  3376. _fnAjaxDataSrc( oSettings, json, [] );
  3377. }
  3378. var error = json.error || json.sError;
  3379. if ( error ) {
  3380. _fnLog( oSettings, 0, error );
  3381. }
  3382. oSettings.json = json;
  3383. _fnCallbackFire( oSettings, null, 'xhr', [oSettings, json, oSettings.jqXHR] );
  3384. fn( json );
  3385. };
  3386. if ( $.isPlainObject( ajax ) && ajax.data )
  3387. {
  3388. ajaxData = ajax.data;
  3389. var newData = typeof ajaxData === 'function' ?
  3390. ajaxData( data, oSettings ) : // fn can manipulate data or return
  3391. ajaxData; // an object object or array to merge
  3392. // If the function returned something, use that alone
  3393. data = typeof ajaxData === 'function' && newData ?
  3394. newData :
  3395. $.extend( true, data, newData );
  3396. // Remove the data property as we've resolved it already and don't want
  3397. // jQuery to do it again (it is restored at the end of the function)
  3398. delete ajax.data;
  3399. }
  3400. var baseAjax = {
  3401. "data": data,
  3402. "success": callback,
  3403. "dataType": "json",
  3404. "cache": false,
  3405. "type": oSettings.sServerMethod,
  3406. "error": function (xhr, error, thrown) {
  3407. var ret = _fnCallbackFire( oSettings, null, 'xhr', [oSettings, null, oSettings.jqXHR] );
  3408. if ( $.inArray( true, ret ) === -1 ) {
  3409. if ( error == "parsererror" ) {
  3410. _fnLog( oSettings, 0, 'Invalid JSON response', 1 );
  3411. }
  3412. else if ( xhr.readyState === 4 ) {
  3413. _fnLog( oSettings, 0, 'Ajax error', 7 );
  3414. }
  3415. }
  3416. _fnProcessingDisplay( oSettings, false );
  3417. }
  3418. };
  3419. // Store the data submitted for the API
  3420. oSettings.oAjaxData = data;
  3421. // Allow plug-ins and external processes to modify the data
  3422. _fnCallbackFire( oSettings, null, 'preXhr', [oSettings, data] );
  3423. if ( oSettings.fnServerData )
  3424. {
  3425. // DataTables 1.9- compatibility
  3426. oSettings.fnServerData.call( instance,
  3427. oSettings.sAjaxSource,
  3428. $.map( data, function (val, key) { // Need to convert back to 1.9 trad format
  3429. return { name: key, value: val };
  3430. } ),
  3431. callback,
  3432. oSettings
  3433. );
  3434. }
  3435. else if ( oSettings.sAjaxSource || typeof ajax === 'string' )
  3436. {
  3437. // DataTables 1.9- compatibility
  3438. oSettings.jqXHR = $.ajax( $.extend( baseAjax, {
  3439. url: ajax || oSettings.sAjaxSource
  3440. } ) );
  3441. }
  3442. else if ( typeof ajax === 'function' )
  3443. {
  3444. // Is a function - let the caller define what needs to be done
  3445. oSettings.jqXHR = ajax.call( instance, data, callback, oSettings );
  3446. }
  3447. else
  3448. {
  3449. // Object to extend the base settings
  3450. oSettings.jqXHR = $.ajax( $.extend( baseAjax, ajax ) );
  3451. // Restore for next time around
  3452. ajax.data = ajaxData;
  3453. }
  3454. }
  3455. /**
  3456. * Update the table using an Ajax call
  3457. * @param {object} settings dataTables settings object
  3458. * @returns {boolean} Block the table drawing or not
  3459. * @memberof DataTable#oApi
  3460. */
  3461. function _fnAjaxUpdate( settings )
  3462. {
  3463. settings.iDraw++;
  3464. _fnProcessingDisplay( settings, true );
  3465. // Keep track of drawHold state to handle scrolling after the Ajax call
  3466. var drawHold = settings._drawHold;
  3467. _fnBuildAjax(
  3468. settings,
  3469. _fnAjaxParameters( settings ),
  3470. function(json) {
  3471. settings._drawHold = drawHold;
  3472. _fnAjaxUpdateDraw( settings, json );
  3473. settings._drawHold = false;
  3474. }
  3475. );
  3476. }
  3477. /**
  3478. * Build up the parameters in an object needed for a server-side processing
  3479. * request. Note that this is basically done twice, is different ways - a modern
  3480. * method which is used by default in DataTables 1.10 which uses objects and
  3481. * arrays, or the 1.9- method with is name / value pairs. 1.9 method is used if
  3482. * the sAjaxSource option is used in the initialisation, or the legacyAjax
  3483. * option is set.
  3484. * @param {object} oSettings dataTables settings object
  3485. * @returns {bool} block the table drawing or not
  3486. * @memberof DataTable#oApi
  3487. */
  3488. function _fnAjaxParameters( settings )
  3489. {
  3490. var
  3491. columns = settings.aoColumns,
  3492. columnCount = columns.length,
  3493. features = settings.oFeatures,
  3494. preSearch = settings.oPreviousSearch,
  3495. preColSearch = settings.aoPreSearchCols,
  3496. i, data = [], dataProp, column, columnSearch,
  3497. sort = _fnSortFlatten( settings ),
  3498. displayStart = settings._iDisplayStart,
  3499. displayLength = features.bPaginate !== false ?
  3500. settings._iDisplayLength :
  3501. -1;
  3502. var param = function ( name, value ) {
  3503. data.push( { 'name': name, 'value': value } );
  3504. };
  3505. // DataTables 1.9- compatible method
  3506. param( 'sEcho', settings.iDraw );
  3507. param( 'iColumns', columnCount );
  3508. param( 'sColumns', _pluck( columns, 'sName' ).join(',') );
  3509. param( 'iDisplayStart', displayStart );
  3510. param( 'iDisplayLength', displayLength );
  3511. // DataTables 1.10+ method
  3512. var d = {
  3513. draw: settings.iDraw,
  3514. columns: [],
  3515. order: [],
  3516. start: displayStart,
  3517. length: displayLength,
  3518. search: {
  3519. value: preSearch.sSearch,
  3520. regex: preSearch.bRegex
  3521. }
  3522. };
  3523. for ( i=0 ; i<columnCount ; i++ ) {
  3524. column = columns[i];
  3525. columnSearch = preColSearch[i];
  3526. dataProp = typeof column.mData=="function" ? 'function' : column.mData ;
  3527. d.columns.push( {
  3528. data: dataProp,
  3529. name: column.sName,
  3530. searchable: column.bSearchable,
  3531. orderable: column.bSortable,
  3532. search: {
  3533. value: columnSearch.sSearch,
  3534. regex: columnSearch.bRegex
  3535. }
  3536. } );
  3537. param( "mDataProp_"+i, dataProp );
  3538. if ( features.bFilter ) {
  3539. param( 'sSearch_'+i, columnSearch.sSearch );
  3540. param( 'bRegex_'+i, columnSearch.bRegex );
  3541. param( 'bSearchable_'+i, column.bSearchable );
  3542. }
  3543. if ( features.bSort ) {
  3544. param( 'bSortable_'+i, column.bSortable );
  3545. }
  3546. }
  3547. if ( features.bFilter ) {
  3548. param( 'sSearch', preSearch.sSearch );
  3549. param( 'bRegex', preSearch.bRegex );
  3550. }
  3551. if ( features.bSort ) {
  3552. $.each( sort, function ( i, val ) {
  3553. d.order.push( { column: val.col, dir: val.dir } );
  3554. param( 'iSortCol_'+i, val.col );
  3555. param( 'sSortDir_'+i, val.dir );
  3556. } );
  3557. param( 'iSortingCols', sort.length );
  3558. }
  3559. // If the legacy.ajax parameter is null, then we automatically decide which
  3560. // form to use, based on sAjaxSource
  3561. var legacy = DataTable.ext.legacy.ajax;
  3562. if ( legacy === null ) {
  3563. return settings.sAjaxSource ? data : d;
  3564. }
  3565. // Otherwise, if legacy has been specified then we use that to decide on the
  3566. // form
  3567. return legacy ? data : d;
  3568. }
  3569. /**
  3570. * Data the data from the server (nuking the old) and redraw the table
  3571. * @param {object} oSettings dataTables settings object
  3572. * @param {object} json json data return from the server.
  3573. * @param {string} json.sEcho Tracking flag for DataTables to match requests
  3574. * @param {int} json.iTotalRecords Number of records in the data set, not accounting for filtering
  3575. * @param {int} json.iTotalDisplayRecords Number of records in the data set, accounting for filtering
  3576. * @param {array} json.aaData The data to display on this page
  3577. * @param {string} [json.sColumns] Column ordering (sName, comma separated)
  3578. * @memberof DataTable#oApi
  3579. */
  3580. function _fnAjaxUpdateDraw ( settings, json )
  3581. {
  3582. // v1.10 uses camelCase variables, while 1.9 uses Hungarian notation.
  3583. // Support both
  3584. var compat = function ( old, modern ) {
  3585. return json[old] !== undefined ? json[old] : json[modern];
  3586. };
  3587. var data = _fnAjaxDataSrc( settings, json );
  3588. var draw = compat( 'sEcho', 'draw' );
  3589. var recordsTotal = compat( 'iTotalRecords', 'recordsTotal' );
  3590. var recordsFiltered = compat( 'iTotalDisplayRecords', 'recordsFiltered' );
  3591. if ( draw !== undefined ) {
  3592. // Protect against out of sequence returns
  3593. if ( draw*1 < settings.iDraw ) {
  3594. return;
  3595. }
  3596. settings.iDraw = draw * 1;
  3597. }
  3598. // No data in returned object, so rather than an array, we show an empty table
  3599. if ( ! data ) {
  3600. data = [];
  3601. }
  3602. _fnClearTable( settings );
  3603. settings._iRecordsTotal = parseInt(recordsTotal, 10);
  3604. settings._iRecordsDisplay = parseInt(recordsFiltered, 10);
  3605. for ( var i=0, ien=data.length ; i<ien ; i++ ) {
  3606. _fnAddData( settings, data[i] );
  3607. }
  3608. settings.aiDisplay = settings.aiDisplayMaster.slice();
  3609. _fnDraw( settings, true );
  3610. if ( ! settings._bInitComplete ) {
  3611. _fnInitComplete( settings, json );
  3612. }
  3613. _fnProcessingDisplay( settings, false );
  3614. }
  3615. /**
  3616. * Get the data from the JSON data source to use for drawing a table. Using
  3617. * `_fnGetObjectDataFn` allows the data to be sourced from a property of the
  3618. * source object, or from a processing function.
  3619. * @param {object} oSettings dataTables settings object
  3620. * @param {object} json Data source object / array from the server
  3621. * @return {array} Array of data to use
  3622. */
  3623. function _fnAjaxDataSrc ( oSettings, json, write )
  3624. {
  3625. var dataSrc = $.isPlainObject( oSettings.ajax ) && oSettings.ajax.dataSrc !== undefined ?
  3626. oSettings.ajax.dataSrc :
  3627. oSettings.sAjaxDataProp; // Compatibility with 1.9-.
  3628. if ( ! write ) {
  3629. if ( dataSrc === 'data' ) {
  3630. // If the default, then we still want to support the old style, and safely ignore
  3631. // it if possible
  3632. return json.aaData || json[dataSrc];
  3633. }
  3634. return dataSrc !== "" ?
  3635. _fnGetObjectDataFn( dataSrc )( json ) :
  3636. json;
  3637. }
  3638. // set
  3639. _fnSetObjectDataFn( dataSrc )( json, write );
  3640. }
  3641. /**
  3642. * Generate the node required for filtering text
  3643. * @returns {node} Filter control element
  3644. * @param {object} oSettings dataTables settings object
  3645. * @memberof DataTable#oApi
  3646. */
  3647. function _fnFeatureHtmlFilter ( settings )
  3648. {
  3649. var classes = settings.oClasses;
  3650. var tableId = settings.sTableId;
  3651. var language = settings.oLanguage;
  3652. var previousSearch = settings.oPreviousSearch;
  3653. var features = settings.aanFeatures;
  3654. var input = '<input type="search" class="'+classes.sFilterInput+'"/>';
  3655. var str = language.sSearch;
  3656. str = str.match(/_INPUT_/) ?
  3657. str.replace('_INPUT_', input) :
  3658. str+input;
  3659. var filter = $('<div/>', {
  3660. 'id': ! features.f ? tableId+'_filter' : null,
  3661. 'class': classes.sFilter
  3662. } )
  3663. .append( $('<label/>' ).append( str ) );
  3664. var searchFn = function(event) {
  3665. /* Update all other filter input elements for the new display */
  3666. var n = features.f;
  3667. var val = !this.value ? "" : this.value; // mental IE8 fix :-(
  3668. if(previousSearch.return && event.key !== "Enter") {
  3669. return;
  3670. }
  3671. /* Now do the filter */
  3672. if ( val != previousSearch.sSearch ) {
  3673. _fnFilterComplete( settings, {
  3674. "sSearch": val,
  3675. "bRegex": previousSearch.bRegex,
  3676. "bSmart": previousSearch.bSmart ,
  3677. "bCaseInsensitive": previousSearch.bCaseInsensitive,
  3678. "return": previousSearch.return
  3679. } );
  3680. // Need to redraw, without resorting
  3681. settings._iDisplayStart = 0;
  3682. _fnDraw( settings );
  3683. }
  3684. };
  3685. var searchDelay = settings.searchDelay !== null ?
  3686. settings.searchDelay :
  3687. _fnDataSource( settings ) === 'ssp' ?
  3688. 400 :
  3689. 0;
  3690. var jqFilter = $('input', filter)
  3691. .val( previousSearch.sSearch )
  3692. .attr( 'placeholder', language.sSearchPlaceholder )
  3693. .on(
  3694. 'keyup.DT search.DT input.DT paste.DT cut.DT',
  3695. searchDelay ?
  3696. _fnThrottle( searchFn, searchDelay ) :
  3697. searchFn
  3698. )
  3699. .on( 'mouseup.DT', function(e) {
  3700. // Edge fix! Edge 17 does not trigger anything other than mouse events when clicking
  3701. // on the clear icon (Edge bug 17584515). This is safe in other browsers as `searchFn`
  3702. // checks the value to see if it has changed. In other browsers it won't have.
  3703. setTimeout( function () {
  3704. searchFn.call(jqFilter[0], e);
  3705. }, 10);
  3706. } )
  3707. .on( 'keypress.DT', function(e) {
  3708. /* Prevent form submission */
  3709. if ( e.keyCode == 13 ) {
  3710. return false;
  3711. }
  3712. } )
  3713. .attr('aria-controls', tableId);
  3714. // Update the input elements whenever the table is filtered
  3715. $(settings.nTable).on( 'search.dt.DT', function ( ev, s ) {
  3716. if ( settings === s ) {
  3717. // IE9 throws an 'unknown error' if document.activeElement is used
  3718. // inside an iframe or frame...
  3719. try {
  3720. if ( jqFilter[0] !== document.activeElement ) {
  3721. jqFilter.val( previousSearch.sSearch );
  3722. }
  3723. }
  3724. catch ( e ) {}
  3725. }
  3726. } );
  3727. return filter[0];
  3728. }
  3729. /**
  3730. * Filter the table using both the global filter and column based filtering
  3731. * @param {object} oSettings dataTables settings object
  3732. * @param {object} oSearch search information
  3733. * @param {int} [iForce] force a research of the master array (1) or not (undefined or 0)
  3734. * @memberof DataTable#oApi
  3735. */
  3736. function _fnFilterComplete ( oSettings, oInput, iForce )
  3737. {
  3738. var oPrevSearch = oSettings.oPreviousSearch;
  3739. var aoPrevSearch = oSettings.aoPreSearchCols;
  3740. var fnSaveFilter = function ( oFilter ) {
  3741. /* Save the filtering values */
  3742. oPrevSearch.sSearch = oFilter.sSearch;
  3743. oPrevSearch.bRegex = oFilter.bRegex;
  3744. oPrevSearch.bSmart = oFilter.bSmart;
  3745. oPrevSearch.bCaseInsensitive = oFilter.bCaseInsensitive;
  3746. oPrevSearch.return = oFilter.return;
  3747. };
  3748. var fnRegex = function ( o ) {
  3749. // Backwards compatibility with the bEscapeRegex option
  3750. return o.bEscapeRegex !== undefined ? !o.bEscapeRegex : o.bRegex;
  3751. };
  3752. // Resolve any column types that are unknown due to addition or invalidation
  3753. // @todo As per sort - can this be moved into an event handler?
  3754. _fnColumnTypes( oSettings );
  3755. /* In server-side processing all filtering is done by the server, so no point hanging around here */
  3756. if ( _fnDataSource( oSettings ) != 'ssp' )
  3757. {
  3758. /* Global filter */
  3759. _fnFilter( oSettings, oInput.sSearch, iForce, fnRegex(oInput), oInput.bSmart, oInput.bCaseInsensitive );
  3760. fnSaveFilter( oInput );
  3761. /* Now do the individual column filter */
  3762. for ( var i=0 ; i<aoPrevSearch.length ; i++ )
  3763. {
  3764. _fnFilterColumn( oSettings, aoPrevSearch[i].sSearch, i, fnRegex(aoPrevSearch[i]),
  3765. aoPrevSearch[i].bSmart, aoPrevSearch[i].bCaseInsensitive );
  3766. }
  3767. /* Custom filtering */
  3768. _fnFilterCustom( oSettings );
  3769. }
  3770. else
  3771. {
  3772. fnSaveFilter( oInput );
  3773. }
  3774. /* Tell the draw function we have been filtering */
  3775. oSettings.bFiltered = true;
  3776. _fnCallbackFire( oSettings, null, 'search', [oSettings] );
  3777. }
  3778. /**
  3779. * Apply custom filtering functions
  3780. * @param {object} oSettings dataTables settings object
  3781. * @memberof DataTable#oApi
  3782. */
  3783. function _fnFilterCustom( settings )
  3784. {
  3785. var filters = DataTable.ext.search;
  3786. var displayRows = settings.aiDisplay;
  3787. var row, rowIdx;
  3788. for ( var i=0, ien=filters.length ; i<ien ; i++ ) {
  3789. var rows = [];
  3790. // Loop over each row and see if it should be included
  3791. for ( var j=0, jen=displayRows.length ; j<jen ; j++ ) {
  3792. rowIdx = displayRows[ j ];
  3793. row = settings.aoData[ rowIdx ];
  3794. if ( filters[i]( settings, row._aFilterData, rowIdx, row._aData, j ) ) {
  3795. rows.push( rowIdx );
  3796. }
  3797. }
  3798. // So the array reference doesn't break set the results into the
  3799. // existing array
  3800. displayRows.length = 0;
  3801. $.merge( displayRows, rows );
  3802. }
  3803. }
  3804. /**
  3805. * Filter the table on a per-column basis
  3806. * @param {object} oSettings dataTables settings object
  3807. * @param {string} sInput string to filter on
  3808. * @param {int} iColumn column to filter
  3809. * @param {bool} bRegex treat search string as a regular expression or not
  3810. * @param {bool} bSmart use smart filtering or not
  3811. * @param {bool} bCaseInsensitive Do case insensitive matching or not
  3812. * @memberof DataTable#oApi
  3813. */
  3814. function _fnFilterColumn ( settings, searchStr, colIdx, regex, smart, caseInsensitive )
  3815. {
  3816. if ( searchStr === '' ) {
  3817. return;
  3818. }
  3819. var data;
  3820. var out = [];
  3821. var display = settings.aiDisplay;
  3822. var rpSearch = _fnFilterCreateSearch( searchStr, regex, smart, caseInsensitive );
  3823. for ( var i=0 ; i<display.length ; i++ ) {
  3824. data = settings.aoData[ display[i] ]._aFilterData[ colIdx ];
  3825. if ( rpSearch.test( data ) ) {
  3826. out.push( display[i] );
  3827. }
  3828. }
  3829. settings.aiDisplay = out;
  3830. }
  3831. /**
  3832. * Filter the data table based on user input and draw the table
  3833. * @param {object} settings dataTables settings object
  3834. * @param {string} input string to filter on
  3835. * @param {int} force optional - force a research of the master array (1) or not (undefined or 0)
  3836. * @param {bool} regex treat as a regular expression or not
  3837. * @param {bool} smart perform smart filtering or not
  3838. * @param {bool} caseInsensitive Do case insensitive matching or not
  3839. * @memberof DataTable#oApi
  3840. */
  3841. function _fnFilter( settings, input, force, regex, smart, caseInsensitive )
  3842. {
  3843. var rpSearch = _fnFilterCreateSearch( input, regex, smart, caseInsensitive );
  3844. var prevSearch = settings.oPreviousSearch.sSearch;
  3845. var displayMaster = settings.aiDisplayMaster;
  3846. var display, invalidated, i;
  3847. var filtered = [];
  3848. // Need to take account of custom filtering functions - always filter
  3849. if ( DataTable.ext.search.length !== 0 ) {
  3850. force = true;
  3851. }
  3852. // Check if any of the rows were invalidated
  3853. invalidated = _fnFilterData( settings );
  3854. // If the input is blank - we just want the full data set
  3855. if ( input.length <= 0 ) {
  3856. settings.aiDisplay = displayMaster.slice();
  3857. }
  3858. else {
  3859. // New search - start from the master array
  3860. if ( invalidated ||
  3861. force ||
  3862. regex ||
  3863. prevSearch.length > input.length ||
  3864. input.indexOf(prevSearch) !== 0 ||
  3865. settings.bSorted // On resort, the display master needs to be
  3866. // re-filtered since indexes will have changed
  3867. ) {
  3868. settings.aiDisplay = displayMaster.slice();
  3869. }
  3870. // Search the display array
  3871. display = settings.aiDisplay;
  3872. for ( i=0 ; i<display.length ; i++ ) {
  3873. if ( rpSearch.test( settings.aoData[ display[i] ]._sFilterRow ) ) {
  3874. filtered.push( display[i] );
  3875. }
  3876. }
  3877. settings.aiDisplay = filtered;
  3878. }
  3879. }
  3880. /**
  3881. * Build a regular expression object suitable for searching a table
  3882. * @param {string} sSearch string to search for
  3883. * @param {bool} bRegex treat as a regular expression or not
  3884. * @param {bool} bSmart perform smart filtering or not
  3885. * @param {bool} bCaseInsensitive Do case insensitive matching or not
  3886. * @returns {RegExp} constructed object
  3887. * @memberof DataTable#oApi
  3888. */
  3889. function _fnFilterCreateSearch( search, regex, smart, caseInsensitive )
  3890. {
  3891. search = regex ?
  3892. search :
  3893. _fnEscapeRegex( search );
  3894. if ( smart ) {
  3895. /* For smart filtering we want to allow the search to work regardless of
  3896. * word order. We also want double quoted text to be preserved, so word
  3897. * order is important - a la google. So this is what we want to
  3898. * generate:
  3899. *
  3900. * ^(?=.*?\bone\b)(?=.*?\btwo three\b)(?=.*?\bfour\b).*$
  3901. */
  3902. var a = $.map( search.match( /["\u201C][^"\u201D]+["\u201D]|[^ ]+/g ) || [''], function ( word ) {
  3903. if ( word.charAt(0) === '"' ) {
  3904. var m = word.match( /^"(.*)"$/ );
  3905. word = m ? m[1] : word;
  3906. }
  3907. else if ( word.charAt(0) === '\u201C' ) {
  3908. var m = word.match( /^\u201C(.*)\u201D$/ );
  3909. word = m ? m[1] : word;
  3910. }
  3911. return word.replace('"', '');
  3912. } );
  3913. search = '^(?=.*?'+a.join( ')(?=.*?' )+').*$';
  3914. }
  3915. return new RegExp( search, caseInsensitive ? 'i' : '' );
  3916. }
  3917. /**
  3918. * Escape a string such that it can be used in a regular expression
  3919. * @param {string} sVal string to escape
  3920. * @returns {string} escaped string
  3921. * @memberof DataTable#oApi
  3922. */
  3923. var _fnEscapeRegex = DataTable.util.escapeRegex;
  3924. var __filter_div = $('<div>')[0];
  3925. var __filter_div_textContent = __filter_div.textContent !== undefined;
  3926. // Update the filtering data for each row if needed (by invalidation or first run)
  3927. function _fnFilterData ( settings )
  3928. {
  3929. var columns = settings.aoColumns;
  3930. var column;
  3931. var i, j, ien, jen, filterData, cellData, row;
  3932. var wasInvalidated = false;
  3933. for ( i=0, ien=settings.aoData.length ; i<ien ; i++ ) {
  3934. row = settings.aoData[i];
  3935. if ( ! row._aFilterData ) {
  3936. filterData = [];
  3937. for ( j=0, jen=columns.length ; j<jen ; j++ ) {
  3938. column = columns[j];
  3939. if ( column.bSearchable ) {
  3940. cellData = _fnGetCellData( settings, i, j, 'filter' );
  3941. // Search in DataTables 1.10 is string based. In 1.11 this
  3942. // should be altered to also allow strict type checking.
  3943. if ( cellData === null ) {
  3944. cellData = '';
  3945. }
  3946. if ( typeof cellData !== 'string' && cellData.toString ) {
  3947. cellData = cellData.toString();
  3948. }
  3949. }
  3950. else {
  3951. cellData = '';
  3952. }
  3953. // If it looks like there is an HTML entity in the string,
  3954. // attempt to decode it so sorting works as expected. Note that
  3955. // we could use a single line of jQuery to do this, but the DOM
  3956. // method used here is much faster http://jsperf.com/html-decode
  3957. if ( cellData.indexOf && cellData.indexOf('&') !== -1 ) {
  3958. __filter_div.innerHTML = cellData;
  3959. cellData = __filter_div_textContent ?
  3960. __filter_div.textContent :
  3961. __filter_div.innerText;
  3962. }
  3963. if ( cellData.replace ) {
  3964. cellData = cellData.replace(/[\r\n\u2028]/g, '');
  3965. }
  3966. filterData.push( cellData );
  3967. }
  3968. row._aFilterData = filterData;
  3969. row._sFilterRow = filterData.join(' ');
  3970. wasInvalidated = true;
  3971. }
  3972. }
  3973. return wasInvalidated;
  3974. }
  3975. /**
  3976. * Convert from the internal Hungarian notation to camelCase for external
  3977. * interaction
  3978. * @param {object} obj Object to convert
  3979. * @returns {object} Inverted object
  3980. * @memberof DataTable#oApi
  3981. */
  3982. function _fnSearchToCamel ( obj )
  3983. {
  3984. return {
  3985. search: obj.sSearch,
  3986. smart: obj.bSmart,
  3987. regex: obj.bRegex,
  3988. caseInsensitive: obj.bCaseInsensitive
  3989. };
  3990. }
  3991. /**
  3992. * Convert from camelCase notation to the internal Hungarian. We could use the
  3993. * Hungarian convert function here, but this is cleaner
  3994. * @param {object} obj Object to convert
  3995. * @returns {object} Inverted object
  3996. * @memberof DataTable#oApi
  3997. */
  3998. function _fnSearchToHung ( obj )
  3999. {
  4000. return {
  4001. sSearch: obj.search,
  4002. bSmart: obj.smart,
  4003. bRegex: obj.regex,
  4004. bCaseInsensitive: obj.caseInsensitive
  4005. };
  4006. }
  4007. /**
  4008. * Generate the node required for the info display
  4009. * @param {object} oSettings dataTables settings object
  4010. * @returns {node} Information element
  4011. * @memberof DataTable#oApi
  4012. */
  4013. function _fnFeatureHtmlInfo ( settings )
  4014. {
  4015. var
  4016. tid = settings.sTableId,
  4017. nodes = settings.aanFeatures.i,
  4018. n = $('<div/>', {
  4019. 'class': settings.oClasses.sInfo,
  4020. 'id': ! nodes ? tid+'_info' : null
  4021. } );
  4022. if ( ! nodes ) {
  4023. // Update display on each draw
  4024. settings.aoDrawCallback.push( {
  4025. "fn": _fnUpdateInfo,
  4026. "sName": "information"
  4027. } );
  4028. n
  4029. .attr( 'role', 'status' )
  4030. .attr( 'aria-live', 'polite' );
  4031. // Table is described by our info div
  4032. $(settings.nTable).attr( 'aria-describedby', tid+'_info' );
  4033. }
  4034. return n[0];
  4035. }
  4036. /**
  4037. * Update the information elements in the display
  4038. * @param {object} settings dataTables settings object
  4039. * @memberof DataTable#oApi
  4040. */
  4041. function _fnUpdateInfo ( settings )
  4042. {
  4043. /* Show information about the table */
  4044. var nodes = settings.aanFeatures.i;
  4045. if ( nodes.length === 0 ) {
  4046. return;
  4047. }
  4048. var
  4049. lang = settings.oLanguage,
  4050. start = settings._iDisplayStart+1,
  4051. end = settings.fnDisplayEnd(),
  4052. max = settings.fnRecordsTotal(),
  4053. total = settings.fnRecordsDisplay(),
  4054. out = total ?
  4055. lang.sInfo :
  4056. lang.sInfoEmpty;
  4057. if ( total !== max ) {
  4058. /* Record set after filtering */
  4059. out += ' ' + lang.sInfoFiltered;
  4060. }
  4061. // Convert the macros
  4062. out += lang.sInfoPostFix;
  4063. out = _fnInfoMacros( settings, out );
  4064. var callback = lang.fnInfoCallback;
  4065. if ( callback !== null ) {
  4066. out = callback.call( settings.oInstance,
  4067. settings, start, end, max, total, out
  4068. );
  4069. }
  4070. $(nodes).html( out );
  4071. }
  4072. function _fnInfoMacros ( settings, str )
  4073. {
  4074. // When infinite scrolling, we are always starting at 1. _iDisplayStart is used only
  4075. // internally
  4076. var
  4077. formatter = settings.fnFormatNumber,
  4078. start = settings._iDisplayStart+1,
  4079. len = settings._iDisplayLength,
  4080. vis = settings.fnRecordsDisplay(),
  4081. all = len === -1;
  4082. return str.
  4083. replace(/_START_/g, formatter.call( settings, start ) ).
  4084. replace(/_END_/g, formatter.call( settings, settings.fnDisplayEnd() ) ).
  4085. replace(/_MAX_/g, formatter.call( settings, settings.fnRecordsTotal() ) ).
  4086. replace(/_TOTAL_/g, formatter.call( settings, vis ) ).
  4087. replace(/_PAGE_/g, formatter.call( settings, all ? 1 : Math.ceil( start / len ) ) ).
  4088. replace(/_PAGES_/g, formatter.call( settings, all ? 1 : Math.ceil( vis / len ) ) );
  4089. }
  4090. /**
  4091. * Draw the table for the first time, adding all required features
  4092. * @param {object} settings dataTables settings object
  4093. * @memberof DataTable#oApi
  4094. */
  4095. function _fnInitialise ( settings )
  4096. {
  4097. var i, iLen, iAjaxStart=settings.iInitDisplayStart;
  4098. var columns = settings.aoColumns, column;
  4099. var features = settings.oFeatures;
  4100. var deferLoading = settings.bDeferLoading; // value modified by the draw
  4101. /* Ensure that the table data is fully initialised */
  4102. if ( ! settings.bInitialised ) {
  4103. setTimeout( function(){ _fnInitialise( settings ); }, 200 );
  4104. return;
  4105. }
  4106. /* Show the display HTML options */
  4107. _fnAddOptionsHtml( settings );
  4108. /* Build and draw the header / footer for the table */
  4109. _fnBuildHead( settings );
  4110. _fnDrawHead( settings, settings.aoHeader );
  4111. _fnDrawHead( settings, settings.aoFooter );
  4112. /* Okay to show that something is going on now */
  4113. _fnProcessingDisplay( settings, true );
  4114. /* Calculate sizes for columns */
  4115. if ( features.bAutoWidth ) {
  4116. _fnCalculateColumnWidths( settings );
  4117. }
  4118. for ( i=0, iLen=columns.length ; i<iLen ; i++ ) {
  4119. column = columns[i];
  4120. if ( column.sWidth ) {
  4121. column.nTh.style.width = _fnStringToCss( column.sWidth );
  4122. }
  4123. }
  4124. _fnCallbackFire( settings, null, 'preInit', [settings] );
  4125. // If there is default sorting required - let's do it. The sort function
  4126. // will do the drawing for us. Otherwise we draw the table regardless of the
  4127. // Ajax source - this allows the table to look initialised for Ajax sourcing
  4128. // data (show 'loading' message possibly)
  4129. _fnReDraw( settings );
  4130. // Server-side processing init complete is done by _fnAjaxUpdateDraw
  4131. var dataSrc = _fnDataSource( settings );
  4132. if ( dataSrc != 'ssp' || deferLoading ) {
  4133. // if there is an ajax source load the data
  4134. if ( dataSrc == 'ajax' ) {
  4135. _fnBuildAjax( settings, [], function(json) {
  4136. var aData = _fnAjaxDataSrc( settings, json );
  4137. // Got the data - add it to the table
  4138. for ( i=0 ; i<aData.length ; i++ ) {
  4139. _fnAddData( settings, aData[i] );
  4140. }
  4141. // Reset the init display for cookie saving. We've already done
  4142. // a filter, and therefore cleared it before. So we need to make
  4143. // it appear 'fresh'
  4144. settings.iInitDisplayStart = iAjaxStart;
  4145. _fnReDraw( settings );
  4146. _fnProcessingDisplay( settings, false );
  4147. _fnInitComplete( settings, json );
  4148. }, settings );
  4149. }
  4150. else {
  4151. _fnProcessingDisplay( settings, false );
  4152. _fnInitComplete( settings );
  4153. }
  4154. }
  4155. }
  4156. /**
  4157. * Draw the table for the first time, adding all required features
  4158. * @param {object} oSettings dataTables settings object
  4159. * @param {object} [json] JSON from the server that completed the table, if using Ajax source
  4160. * with client-side processing (optional)
  4161. * @memberof DataTable#oApi
  4162. */
  4163. function _fnInitComplete ( settings, json )
  4164. {
  4165. settings._bInitComplete = true;
  4166. // When data was added after the initialisation (data or Ajax) we need to
  4167. // calculate the column sizing
  4168. if ( json || settings.oInit.aaData ) {
  4169. _fnAdjustColumnSizing( settings );
  4170. }
  4171. _fnCallbackFire( settings, null, 'plugin-init', [settings, json] );
  4172. _fnCallbackFire( settings, 'aoInitComplete', 'init', [settings, json] );
  4173. }
  4174. function _fnLengthChange ( settings, val )
  4175. {
  4176. var len = parseInt( val, 10 );
  4177. settings._iDisplayLength = len;
  4178. _fnLengthOverflow( settings );
  4179. // Fire length change event
  4180. _fnCallbackFire( settings, null, 'length', [settings, len] );
  4181. }
  4182. /**
  4183. * Generate the node required for user display length changing
  4184. * @param {object} settings dataTables settings object
  4185. * @returns {node} Display length feature node
  4186. * @memberof DataTable#oApi
  4187. */
  4188. function _fnFeatureHtmlLength ( settings )
  4189. {
  4190. var
  4191. classes = settings.oClasses,
  4192. tableId = settings.sTableId,
  4193. menu = settings.aLengthMenu,
  4194. d2 = Array.isArray( menu[0] ),
  4195. lengths = d2 ? menu[0] : menu,
  4196. language = d2 ? menu[1] : menu;
  4197. var select = $('<select/>', {
  4198. 'name': tableId+'_length',
  4199. 'aria-controls': tableId,
  4200. 'class': classes.sLengthSelect
  4201. } );
  4202. for ( var i=0, ien=lengths.length ; i<ien ; i++ ) {
  4203. select[0][ i ] = new Option(
  4204. typeof language[i] === 'number' ?
  4205. settings.fnFormatNumber( language[i] ) :
  4206. language[i],
  4207. lengths[i]
  4208. );
  4209. }
  4210. var div = $('<div><label/></div>').addClass( classes.sLength );
  4211. if ( ! settings.aanFeatures.l ) {
  4212. div[0].id = tableId+'_length';
  4213. }
  4214. div.children().append(
  4215. settings.oLanguage.sLengthMenu.replace( '_MENU_', select[0].outerHTML )
  4216. );
  4217. // Can't use `select` variable as user might provide their own and the
  4218. // reference is broken by the use of outerHTML
  4219. $('select', div)
  4220. .val( settings._iDisplayLength )
  4221. .on( 'change.DT', function(e) {
  4222. _fnLengthChange( settings, $(this).val() );
  4223. _fnDraw( settings );
  4224. } );
  4225. // Update node value whenever anything changes the table's length
  4226. $(settings.nTable).on( 'length.dt.DT', function (e, s, len) {
  4227. if ( settings === s ) {
  4228. $('select', div).val( len );
  4229. }
  4230. } );
  4231. return div[0];
  4232. }
  4233. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  4234. * Note that most of the paging logic is done in
  4235. * DataTable.ext.pager
  4236. */
  4237. /**
  4238. * Generate the node required for default pagination
  4239. * @param {object} oSettings dataTables settings object
  4240. * @returns {node} Pagination feature node
  4241. * @memberof DataTable#oApi
  4242. */
  4243. function _fnFeatureHtmlPaginate ( settings )
  4244. {
  4245. var
  4246. type = settings.sPaginationType,
  4247. plugin = DataTable.ext.pager[ type ],
  4248. modern = typeof plugin === 'function',
  4249. redraw = function( settings ) {
  4250. _fnDraw( settings );
  4251. },
  4252. node = $('<div/>').addClass( settings.oClasses.sPaging + type )[0],
  4253. features = settings.aanFeatures;
  4254. if ( ! modern ) {
  4255. plugin.fnInit( settings, node, redraw );
  4256. }
  4257. /* Add a draw callback for the pagination on first instance, to update the paging display */
  4258. if ( ! features.p )
  4259. {
  4260. node.id = settings.sTableId+'_paginate';
  4261. settings.aoDrawCallback.push( {
  4262. "fn": function( settings ) {
  4263. if ( modern ) {
  4264. var
  4265. start = settings._iDisplayStart,
  4266. len = settings._iDisplayLength,
  4267. visRecords = settings.fnRecordsDisplay(),
  4268. all = len === -1,
  4269. page = all ? 0 : Math.ceil( start / len ),
  4270. pages = all ? 1 : Math.ceil( visRecords / len ),
  4271. buttons = plugin(page, pages),
  4272. i, ien;
  4273. for ( i=0, ien=features.p.length ; i<ien ; i++ ) {
  4274. _fnRenderer( settings, 'pageButton' )(
  4275. settings, features.p[i], i, buttons, page, pages
  4276. );
  4277. }
  4278. }
  4279. else {
  4280. plugin.fnUpdate( settings, redraw );
  4281. }
  4282. },
  4283. "sName": "pagination"
  4284. } );
  4285. }
  4286. return node;
  4287. }
  4288. /**
  4289. * Alter the display settings to change the page
  4290. * @param {object} settings DataTables settings object
  4291. * @param {string|int} action Paging action to take: "first", "previous",
  4292. * "next" or "last" or page number to jump to (integer)
  4293. * @param [bool] redraw Automatically draw the update or not
  4294. * @returns {bool} true page has changed, false - no change
  4295. * @memberof DataTable#oApi
  4296. */
  4297. function _fnPageChange ( settings, action, redraw )
  4298. {
  4299. var
  4300. start = settings._iDisplayStart,
  4301. len = settings._iDisplayLength,
  4302. records = settings.fnRecordsDisplay();
  4303. if ( records === 0 || len === -1 )
  4304. {
  4305. start = 0;
  4306. }
  4307. else if ( typeof action === "number" )
  4308. {
  4309. start = action * len;
  4310. if ( start > records )
  4311. {
  4312. start = 0;
  4313. }
  4314. }
  4315. else if ( action == "first" )
  4316. {
  4317. start = 0;
  4318. }
  4319. else if ( action == "previous" )
  4320. {
  4321. start = len >= 0 ?
  4322. start - len :
  4323. 0;
  4324. if ( start < 0 )
  4325. {
  4326. start = 0;
  4327. }
  4328. }
  4329. else if ( action == "next" )
  4330. {
  4331. if ( start + len < records )
  4332. {
  4333. start += len;
  4334. }
  4335. }
  4336. else if ( action == "last" )
  4337. {
  4338. start = Math.floor( (records-1) / len) * len;
  4339. }
  4340. else
  4341. {
  4342. _fnLog( settings, 0, "Unknown paging action: "+action, 5 );
  4343. }
  4344. var changed = settings._iDisplayStart !== start;
  4345. settings._iDisplayStart = start;
  4346. if ( changed ) {
  4347. _fnCallbackFire( settings, null, 'page', [settings] );
  4348. if ( redraw ) {
  4349. _fnDraw( settings );
  4350. }
  4351. }
  4352. else {
  4353. // No change event - paging was called, but no change
  4354. _fnCallbackFire( settings, null, 'page-nc', [settings] );
  4355. }
  4356. return changed;
  4357. }
  4358. /**
  4359. * Generate the node required for the processing node
  4360. * @param {object} settings dataTables settings object
  4361. * @returns {node} Processing element
  4362. * @memberof DataTable#oApi
  4363. */
  4364. function _fnFeatureHtmlProcessing ( settings )
  4365. {
  4366. return $('<div/>', {
  4367. 'id': ! settings.aanFeatures.r ? settings.sTableId+'_processing' : null,
  4368. 'class': settings.oClasses.sProcessing,
  4369. 'role': 'status'
  4370. } )
  4371. .html( settings.oLanguage.sProcessing )
  4372. .append('<div><div></div><div></div><div></div><div></div></div>')
  4373. .insertBefore( settings.nTable )[0];
  4374. }
  4375. /**
  4376. * Display or hide the processing indicator
  4377. * @param {object} settings dataTables settings object
  4378. * @param {bool} show Show the processing indicator (true) or not (false)
  4379. * @memberof DataTable#oApi
  4380. */
  4381. function _fnProcessingDisplay ( settings, show )
  4382. {
  4383. if ( settings.oFeatures.bProcessing ) {
  4384. $(settings.aanFeatures.r).css( 'display', show ? 'block' : 'none' );
  4385. }
  4386. _fnCallbackFire( settings, null, 'processing', [settings, show] );
  4387. }
  4388. /**
  4389. * Add any control elements for the table - specifically scrolling
  4390. * @param {object} settings dataTables settings object
  4391. * @returns {node} Node to add to the DOM
  4392. * @memberof DataTable#oApi
  4393. */
  4394. function _fnFeatureHtmlTable ( settings )
  4395. {
  4396. var table = $(settings.nTable);
  4397. // Scrolling from here on in
  4398. var scroll = settings.oScroll;
  4399. if ( scroll.sX === '' && scroll.sY === '' ) {
  4400. return settings.nTable;
  4401. }
  4402. var scrollX = scroll.sX;
  4403. var scrollY = scroll.sY;
  4404. var classes = settings.oClasses;
  4405. var caption = table.children('caption');
  4406. var captionSide = caption.length ? caption[0]._captionSide : null;
  4407. var headerClone = $( table[0].cloneNode(false) );
  4408. var footerClone = $( table[0].cloneNode(false) );
  4409. var footer = table.children('tfoot');
  4410. var _div = '<div/>';
  4411. var size = function ( s ) {
  4412. return !s ? null : _fnStringToCss( s );
  4413. };
  4414. if ( ! footer.length ) {
  4415. footer = null;
  4416. }
  4417. /*
  4418. * The HTML structure that we want to generate in this function is:
  4419. * div - scroller
  4420. * div - scroll head
  4421. * div - scroll head inner
  4422. * table - scroll head table
  4423. * thead - thead
  4424. * div - scroll body
  4425. * table - table (master table)
  4426. * thead - thead clone for sizing
  4427. * tbody - tbody
  4428. * div - scroll foot
  4429. * div - scroll foot inner
  4430. * table - scroll foot table
  4431. * tfoot - tfoot
  4432. */
  4433. var scroller = $( _div, { 'class': classes.sScrollWrapper } )
  4434. .append(
  4435. $(_div, { 'class': classes.sScrollHead } )
  4436. .css( {
  4437. overflow: 'hidden',
  4438. position: 'relative',
  4439. border: 0,
  4440. width: scrollX ? size(scrollX) : '100%'
  4441. } )
  4442. .append(
  4443. $(_div, { 'class': classes.sScrollHeadInner } )
  4444. .css( {
  4445. 'box-sizing': 'content-box',
  4446. width: scroll.sXInner || '100%'
  4447. } )
  4448. .append(
  4449. headerClone
  4450. .removeAttr('id')
  4451. .css( 'margin-left', 0 )
  4452. .append( captionSide === 'top' ? caption : null )
  4453. .append(
  4454. table.children('thead')
  4455. )
  4456. )
  4457. )
  4458. )
  4459. .append(
  4460. $(_div, { 'class': classes.sScrollBody } )
  4461. .css( {
  4462. position: 'relative',
  4463. overflow: 'auto',
  4464. width: size( scrollX )
  4465. } )
  4466. .append( table )
  4467. );
  4468. if ( footer ) {
  4469. scroller.append(
  4470. $(_div, { 'class': classes.sScrollFoot } )
  4471. .css( {
  4472. overflow: 'hidden',
  4473. border: 0,
  4474. width: scrollX ? size(scrollX) : '100%'
  4475. } )
  4476. .append(
  4477. $(_div, { 'class': classes.sScrollFootInner } )
  4478. .append(
  4479. footerClone
  4480. .removeAttr('id')
  4481. .css( 'margin-left', 0 )
  4482. .append( captionSide === 'bottom' ? caption : null )
  4483. .append(
  4484. table.children('tfoot')
  4485. )
  4486. )
  4487. )
  4488. );
  4489. }
  4490. var children = scroller.children();
  4491. var scrollHead = children[0];
  4492. var scrollBody = children[1];
  4493. var scrollFoot = footer ? children[2] : null;
  4494. // When the body is scrolled, then we also want to scroll the headers
  4495. if ( scrollX ) {
  4496. $(scrollBody).on( 'scroll.DT', function (e) {
  4497. var scrollLeft = this.scrollLeft;
  4498. scrollHead.scrollLeft = scrollLeft;
  4499. if ( footer ) {
  4500. scrollFoot.scrollLeft = scrollLeft;
  4501. }
  4502. } );
  4503. }
  4504. $(scrollBody).css('max-height', scrollY);
  4505. if (! scroll.bCollapse) {
  4506. $(scrollBody).css('height', scrollY);
  4507. }
  4508. settings.nScrollHead = scrollHead;
  4509. settings.nScrollBody = scrollBody;
  4510. settings.nScrollFoot = scrollFoot;
  4511. // On redraw - align columns
  4512. settings.aoDrawCallback.push( {
  4513. "fn": _fnScrollDraw,
  4514. "sName": "scrolling"
  4515. } );
  4516. return scroller[0];
  4517. }
  4518. /**
  4519. * Update the header, footer and body tables for resizing - i.e. column
  4520. * alignment.
  4521. *
  4522. * Welcome to the most horrible function DataTables. The process that this
  4523. * function follows is basically:
  4524. * 1. Re-create the table inside the scrolling div
  4525. * 2. Take live measurements from the DOM
  4526. * 3. Apply the measurements to align the columns
  4527. * 4. Clean up
  4528. *
  4529. * @param {object} settings dataTables settings object
  4530. * @memberof DataTable#oApi
  4531. */
  4532. function _fnScrollDraw ( settings )
  4533. {
  4534. // Given that this is such a monster function, a lot of variables are use
  4535. // to try and keep the minimised size as small as possible
  4536. var
  4537. scroll = settings.oScroll,
  4538. scrollX = scroll.sX,
  4539. scrollXInner = scroll.sXInner,
  4540. scrollY = scroll.sY,
  4541. barWidth = scroll.iBarWidth,
  4542. divHeader = $(settings.nScrollHead),
  4543. divHeaderStyle = divHeader[0].style,
  4544. divHeaderInner = divHeader.children('div'),
  4545. divHeaderInnerStyle = divHeaderInner[0].style,
  4546. divHeaderTable = divHeaderInner.children('table'),
  4547. divBodyEl = settings.nScrollBody,
  4548. divBody = $(divBodyEl),
  4549. divBodyStyle = divBodyEl.style,
  4550. divFooter = $(settings.nScrollFoot),
  4551. divFooterInner = divFooter.children('div'),
  4552. divFooterTable = divFooterInner.children('table'),
  4553. header = $(settings.nTHead),
  4554. table = $(settings.nTable),
  4555. tableEl = table[0],
  4556. tableStyle = tableEl.style,
  4557. footer = settings.nTFoot ? $(settings.nTFoot) : null,
  4558. browser = settings.oBrowser,
  4559. ie67 = browser.bScrollOversize,
  4560. dtHeaderCells = _pluck( settings.aoColumns, 'nTh' ),
  4561. headerTrgEls, footerTrgEls,
  4562. headerSrcEls, footerSrcEls,
  4563. headerCopy, footerCopy,
  4564. headerWidths=[], footerWidths=[],
  4565. headerContent=[], footerContent=[],
  4566. idx, correction, sanityWidth,
  4567. zeroOut = function(nSizer) {
  4568. var style = nSizer.style;
  4569. style.paddingTop = "0";
  4570. style.paddingBottom = "0";
  4571. style.borderTopWidth = "0";
  4572. style.borderBottomWidth = "0";
  4573. style.height = 0;
  4574. };
  4575. // If the scrollbar visibility has changed from the last draw, we need to
  4576. // adjust the column sizes as the table width will have changed to account
  4577. // for the scrollbar
  4578. var scrollBarVis = divBodyEl.scrollHeight > divBodyEl.clientHeight;
  4579. if ( settings.scrollBarVis !== scrollBarVis && settings.scrollBarVis !== undefined ) {
  4580. settings.scrollBarVis = scrollBarVis;
  4581. _fnAdjustColumnSizing( settings );
  4582. return; // adjust column sizing will call this function again
  4583. }
  4584. else {
  4585. settings.scrollBarVis = scrollBarVis;
  4586. }
  4587. /*
  4588. * 1. Re-create the table inside the scrolling div
  4589. */
  4590. // Remove the old minimised thead and tfoot elements in the inner table
  4591. table.children('thead, tfoot').remove();
  4592. if ( footer ) {
  4593. footerCopy = footer.clone().prependTo( table );
  4594. footerTrgEls = footer.find('tr'); // the original tfoot is in its own table and must be sized
  4595. footerSrcEls = footerCopy.find('tr');
  4596. footerCopy.find('[id]').removeAttr('id');
  4597. }
  4598. // Clone the current header and footer elements and then place it into the inner table
  4599. headerCopy = header.clone().prependTo( table );
  4600. headerTrgEls = header.find('tr'); // original header is in its own table
  4601. headerSrcEls = headerCopy.find('tr');
  4602. headerCopy.find('th, td').removeAttr('tabindex');
  4603. headerCopy.find('[id]').removeAttr('id');
  4604. /*
  4605. * 2. Take live measurements from the DOM - do not alter the DOM itself!
  4606. */
  4607. // Remove old sizing and apply the calculated column widths
  4608. // Get the unique column headers in the newly created (cloned) header. We want to apply the
  4609. // calculated sizes to this header
  4610. if ( ! scrollX )
  4611. {
  4612. divBodyStyle.width = '100%';
  4613. divHeader[0].style.width = '100%';
  4614. }
  4615. $.each( _fnGetUniqueThs( settings, headerCopy ), function ( i, el ) {
  4616. idx = _fnVisibleToColumnIndex( settings, i );
  4617. el.style.width = settings.aoColumns[idx].sWidth;
  4618. } );
  4619. if ( footer ) {
  4620. _fnApplyToChildren( function(n) {
  4621. n.style.width = "";
  4622. }, footerSrcEls );
  4623. }
  4624. // Size the table as a whole
  4625. sanityWidth = table.outerWidth();
  4626. if ( scrollX === "" ) {
  4627. // No x scrolling
  4628. tableStyle.width = "100%";
  4629. // IE7 will make the width of the table when 100% include the scrollbar
  4630. // - which is shouldn't. When there is a scrollbar we need to take this
  4631. // into account.
  4632. if ( ie67 && (table.find('tbody').height() > divBodyEl.offsetHeight ||
  4633. divBody.css('overflow-y') == "scroll")
  4634. ) {
  4635. tableStyle.width = _fnStringToCss( table.outerWidth() - barWidth);
  4636. }
  4637. // Recalculate the sanity width
  4638. sanityWidth = table.outerWidth();
  4639. }
  4640. else if ( scrollXInner !== "" ) {
  4641. // legacy x scroll inner has been given - use it
  4642. tableStyle.width = _fnStringToCss(scrollXInner);
  4643. // Recalculate the sanity width
  4644. sanityWidth = table.outerWidth();
  4645. }
  4646. // Hidden header should have zero height, so remove padding and borders. Then
  4647. // set the width based on the real headers
  4648. // Apply all styles in one pass
  4649. _fnApplyToChildren( zeroOut, headerSrcEls );
  4650. // Read all widths in next pass
  4651. _fnApplyToChildren( function(nSizer) {
  4652. var style = window.getComputedStyle ?
  4653. window.getComputedStyle(nSizer).width :
  4654. _fnStringToCss( $(nSizer).width() );
  4655. headerContent.push( nSizer.innerHTML );
  4656. headerWidths.push( style );
  4657. }, headerSrcEls );
  4658. // Apply all widths in final pass
  4659. _fnApplyToChildren( function(nToSize, i) {
  4660. nToSize.style.width = headerWidths[i];
  4661. }, headerTrgEls );
  4662. $(headerSrcEls).css('height', 0);
  4663. /* Same again with the footer if we have one */
  4664. if ( footer )
  4665. {
  4666. _fnApplyToChildren( zeroOut, footerSrcEls );
  4667. _fnApplyToChildren( function(nSizer) {
  4668. footerContent.push( nSizer.innerHTML );
  4669. footerWidths.push( _fnStringToCss( $(nSizer).css('width') ) );
  4670. }, footerSrcEls );
  4671. _fnApplyToChildren( function(nToSize, i) {
  4672. nToSize.style.width = footerWidths[i];
  4673. }, footerTrgEls );
  4674. $(footerSrcEls).height(0);
  4675. }
  4676. /*
  4677. * 3. Apply the measurements
  4678. */
  4679. // "Hide" the header and footer that we used for the sizing. We need to keep
  4680. // the content of the cell so that the width applied to the header and body
  4681. // both match, but we want to hide it completely. We want to also fix their
  4682. // width to what they currently are
  4683. _fnApplyToChildren( function(nSizer, i) {
  4684. nSizer.innerHTML = '<div class="dataTables_sizing">'+headerContent[i]+'</div>';
  4685. nSizer.childNodes[0].style.height = "0";
  4686. nSizer.childNodes[0].style.overflow = "hidden";
  4687. nSizer.style.width = headerWidths[i];
  4688. }, headerSrcEls );
  4689. if ( footer )
  4690. {
  4691. _fnApplyToChildren( function(nSizer, i) {
  4692. nSizer.innerHTML = '<div class="dataTables_sizing">'+footerContent[i]+'</div>';
  4693. nSizer.childNodes[0].style.height = "0";
  4694. nSizer.childNodes[0].style.overflow = "hidden";
  4695. nSizer.style.width = footerWidths[i];
  4696. }, footerSrcEls );
  4697. }
  4698. // Sanity check that the table is of a sensible width. If not then we are going to get
  4699. // misalignment - try to prevent this by not allowing the table to shrink below its min width
  4700. if ( Math.round(table.outerWidth()) < Math.round(sanityWidth) )
  4701. {
  4702. // The min width depends upon if we have a vertical scrollbar visible or not */
  4703. correction = ((divBodyEl.scrollHeight > divBodyEl.offsetHeight ||
  4704. divBody.css('overflow-y') == "scroll")) ?
  4705. sanityWidth+barWidth :
  4706. sanityWidth;
  4707. // IE6/7 are a law unto themselves...
  4708. if ( ie67 && (divBodyEl.scrollHeight >
  4709. divBodyEl.offsetHeight || divBody.css('overflow-y') == "scroll")
  4710. ) {
  4711. tableStyle.width = _fnStringToCss( correction-barWidth );
  4712. }
  4713. // And give the user a warning that we've stopped the table getting too small
  4714. if ( scrollX === "" || scrollXInner !== "" ) {
  4715. _fnLog( settings, 1, 'Possible column misalignment', 6 );
  4716. }
  4717. }
  4718. else
  4719. {
  4720. correction = '100%';
  4721. }
  4722. // Apply to the container elements
  4723. divBodyStyle.width = _fnStringToCss( correction );
  4724. divHeaderStyle.width = _fnStringToCss( correction );
  4725. if ( footer ) {
  4726. settings.nScrollFoot.style.width = _fnStringToCss( correction );
  4727. }
  4728. /*
  4729. * 4. Clean up
  4730. */
  4731. if ( ! scrollY ) {
  4732. /* IE7< puts a vertical scrollbar in place (when it shouldn't be) due to subtracting
  4733. * the scrollbar height from the visible display, rather than adding it on. We need to
  4734. * set the height in order to sort this. Don't want to do it in any other browsers.
  4735. */
  4736. if ( ie67 ) {
  4737. divBodyStyle.height = _fnStringToCss( tableEl.offsetHeight+barWidth );
  4738. }
  4739. }
  4740. /* Finally set the width's of the header and footer tables */
  4741. var iOuterWidth = table.outerWidth();
  4742. divHeaderTable[0].style.width = _fnStringToCss( iOuterWidth );
  4743. divHeaderInnerStyle.width = _fnStringToCss( iOuterWidth );
  4744. // Figure out if there are scrollbar present - if so then we need a the header and footer to
  4745. // provide a bit more space to allow "overflow" scrolling (i.e. past the scrollbar)
  4746. var bScrolling = table.height() > divBodyEl.clientHeight || divBody.css('overflow-y') == "scroll";
  4747. var padding = 'padding' + (browser.bScrollbarLeft ? 'Left' : 'Right' );
  4748. divHeaderInnerStyle[ padding ] = bScrolling ? barWidth+"px" : "0px";
  4749. if ( footer ) {
  4750. divFooterTable[0].style.width = _fnStringToCss( iOuterWidth );
  4751. divFooterInner[0].style.width = _fnStringToCss( iOuterWidth );
  4752. divFooterInner[0].style[padding] = bScrolling ? barWidth+"px" : "0px";
  4753. }
  4754. // Correct DOM ordering for colgroup - comes before the thead
  4755. table.children('colgroup').insertBefore( table.children('thead') );
  4756. /* Adjust the position of the header in case we loose the y-scrollbar */
  4757. divBody.trigger('scroll');
  4758. // If sorting or filtering has occurred, jump the scrolling back to the top
  4759. // only if we aren't holding the position
  4760. if ( (settings.bSorted || settings.bFiltered) && ! settings._drawHold ) {
  4761. divBodyEl.scrollTop = 0;
  4762. }
  4763. }
  4764. /**
  4765. * Apply a given function to the display child nodes of an element array (typically
  4766. * TD children of TR rows
  4767. * @param {function} fn Method to apply to the objects
  4768. * @param array {nodes} an1 List of elements to look through for display children
  4769. * @param array {nodes} an2 Another list (identical structure to the first) - optional
  4770. * @memberof DataTable#oApi
  4771. */
  4772. function _fnApplyToChildren( fn, an1, an2 )
  4773. {
  4774. var index=0, i=0, iLen=an1.length;
  4775. var nNode1, nNode2;
  4776. while ( i < iLen ) {
  4777. nNode1 = an1[i].firstChild;
  4778. nNode2 = an2 ? an2[i].firstChild : null;
  4779. while ( nNode1 ) {
  4780. if ( nNode1.nodeType === 1 ) {
  4781. if ( an2 ) {
  4782. fn( nNode1, nNode2, index );
  4783. }
  4784. else {
  4785. fn( nNode1, index );
  4786. }
  4787. index++;
  4788. }
  4789. nNode1 = nNode1.nextSibling;
  4790. nNode2 = an2 ? nNode2.nextSibling : null;
  4791. }
  4792. i++;
  4793. }
  4794. }
  4795. var __re_html_remove = /<.*?>/g;
  4796. /**
  4797. * Calculate the width of columns for the table
  4798. * @param {object} oSettings dataTables settings object
  4799. * @memberof DataTable#oApi
  4800. */
  4801. function _fnCalculateColumnWidths ( oSettings )
  4802. {
  4803. var
  4804. table = oSettings.nTable,
  4805. columns = oSettings.aoColumns,
  4806. scroll = oSettings.oScroll,
  4807. scrollY = scroll.sY,
  4808. scrollX = scroll.sX,
  4809. scrollXInner = scroll.sXInner,
  4810. columnCount = columns.length,
  4811. visibleColumns = _fnGetColumns( oSettings, 'bVisible' ),
  4812. headerCells = $('th', oSettings.nTHead),
  4813. tableWidthAttr = table.getAttribute('width'), // from DOM element
  4814. tableContainer = table.parentNode,
  4815. userInputs = false,
  4816. i, column, columnIdx, width, outerWidth,
  4817. browser = oSettings.oBrowser,
  4818. ie67 = browser.bScrollOversize;
  4819. var styleWidth = table.style.width;
  4820. if ( styleWidth && styleWidth.indexOf('%') !== -1 ) {
  4821. tableWidthAttr = styleWidth;
  4822. }
  4823. /* Convert any user input sizes into pixel sizes */
  4824. for ( i=0 ; i<visibleColumns.length ; i++ ) {
  4825. column = columns[ visibleColumns[i] ];
  4826. if ( column.sWidth !== null ) {
  4827. column.sWidth = _fnConvertToWidth( column.sWidthOrig, tableContainer );
  4828. userInputs = true;
  4829. }
  4830. }
  4831. /* If the number of columns in the DOM equals the number that we have to
  4832. * process in DataTables, then we can use the offsets that are created by
  4833. * the web- browser. No custom sizes can be set in order for this to happen,
  4834. * nor scrolling used
  4835. */
  4836. if ( ie67 || ! userInputs && ! scrollX && ! scrollY &&
  4837. columnCount == _fnVisbleColumns( oSettings ) &&
  4838. columnCount == headerCells.length
  4839. ) {
  4840. for ( i=0 ; i<columnCount ; i++ ) {
  4841. var colIdx = _fnVisibleToColumnIndex( oSettings, i );
  4842. if ( colIdx !== null ) {
  4843. columns[ colIdx ].sWidth = _fnStringToCss( headerCells.eq(i).width() );
  4844. }
  4845. }
  4846. }
  4847. else
  4848. {
  4849. // Otherwise construct a single row, worst case, table with the widest
  4850. // node in the data, assign any user defined widths, then insert it into
  4851. // the DOM and allow the browser to do all the hard work of calculating
  4852. // table widths
  4853. var tmpTable = $(table).clone() // don't use cloneNode - IE8 will remove events on the main table
  4854. .css( 'visibility', 'hidden' )
  4855. .removeAttr( 'id' );
  4856. // Clean up the table body
  4857. tmpTable.find('tbody tr').remove();
  4858. var tr = $('<tr/>').appendTo( tmpTable.find('tbody') );
  4859. // Clone the table header and footer - we can't use the header / footer
  4860. // from the cloned table, since if scrolling is active, the table's
  4861. // real header and footer are contained in different table tags
  4862. tmpTable.find('thead, tfoot').remove();
  4863. tmpTable
  4864. .append( $(oSettings.nTHead).clone() )
  4865. .append( $(oSettings.nTFoot).clone() );
  4866. // Remove any assigned widths from the footer (from scrolling)
  4867. tmpTable.find('tfoot th, tfoot td').css('width', '');
  4868. // Apply custom sizing to the cloned header
  4869. headerCells = _fnGetUniqueThs( oSettings, tmpTable.find('thead')[0] );
  4870. for ( i=0 ; i<visibleColumns.length ; i++ ) {
  4871. column = columns[ visibleColumns[i] ];
  4872. headerCells[i].style.width = column.sWidthOrig !== null && column.sWidthOrig !== '' ?
  4873. _fnStringToCss( column.sWidthOrig ) :
  4874. '';
  4875. // For scrollX we need to force the column width otherwise the
  4876. // browser will collapse it. If this width is smaller than the
  4877. // width the column requires, then it will have no effect
  4878. if ( column.sWidthOrig && scrollX ) {
  4879. $( headerCells[i] ).append( $('<div/>').css( {
  4880. width: column.sWidthOrig,
  4881. margin: 0,
  4882. padding: 0,
  4883. border: 0,
  4884. height: 1
  4885. } ) );
  4886. }
  4887. }
  4888. // Find the widest cell for each column and put it into the table
  4889. if ( oSettings.aoData.length ) {
  4890. for ( i=0 ; i<visibleColumns.length ; i++ ) {
  4891. columnIdx = visibleColumns[i];
  4892. column = columns[ columnIdx ];
  4893. $( _fnGetWidestNode( oSettings, columnIdx ) )
  4894. .clone( false )
  4895. .append( column.sContentPadding )
  4896. .appendTo( tr );
  4897. }
  4898. }
  4899. // Tidy the temporary table - remove name attributes so there aren't
  4900. // duplicated in the dom (radio elements for example)
  4901. $('[name]', tmpTable).removeAttr('name');
  4902. // Table has been built, attach to the document so we can work with it.
  4903. // A holding element is used, positioned at the top of the container
  4904. // with minimal height, so it has no effect on if the container scrolls
  4905. // or not. Otherwise it might trigger scrolling when it actually isn't
  4906. // needed
  4907. var holder = $('<div/>').css( scrollX || scrollY ?
  4908. {
  4909. position: 'absolute',
  4910. top: 0,
  4911. left: 0,
  4912. height: 1,
  4913. right: 0,
  4914. overflow: 'hidden'
  4915. } :
  4916. {}
  4917. )
  4918. .append( tmpTable )
  4919. .appendTo( tableContainer );
  4920. // When scrolling (X or Y) we want to set the width of the table as
  4921. // appropriate. However, when not scrolling leave the table width as it
  4922. // is. This results in slightly different, but I think correct behaviour
  4923. if ( scrollX && scrollXInner ) {
  4924. tmpTable.width( scrollXInner );
  4925. }
  4926. else if ( scrollX ) {
  4927. tmpTable.css( 'width', 'auto' );
  4928. tmpTable.removeAttr('width');
  4929. // If there is no width attribute or style, then allow the table to
  4930. // collapse
  4931. if ( tmpTable.width() < tableContainer.clientWidth && tableWidthAttr ) {
  4932. tmpTable.width( tableContainer.clientWidth );
  4933. }
  4934. }
  4935. else if ( scrollY ) {
  4936. tmpTable.width( tableContainer.clientWidth );
  4937. }
  4938. else if ( tableWidthAttr ) {
  4939. tmpTable.width( tableWidthAttr );
  4940. }
  4941. // Get the width of each column in the constructed table - we need to
  4942. // know the inner width (so it can be assigned to the other table's
  4943. // cells) and the outer width so we can calculate the full width of the
  4944. // table. This is safe since DataTables requires a unique cell for each
  4945. // column, but if ever a header can span multiple columns, this will
  4946. // need to be modified.
  4947. var total = 0;
  4948. for ( i=0 ; i<visibleColumns.length ; i++ ) {
  4949. var cell = $(headerCells[i]);
  4950. var border = cell.outerWidth() - cell.width();
  4951. // Use getBounding... where possible (not IE8-) because it can give
  4952. // sub-pixel accuracy, which we then want to round up!
  4953. var bounding = browser.bBounding ?
  4954. Math.ceil( headerCells[i].getBoundingClientRect().width ) :
  4955. cell.outerWidth();
  4956. // Total is tracked to remove any sub-pixel errors as the outerWidth
  4957. // of the table might not equal the total given here (IE!).
  4958. total += bounding;
  4959. // Width for each column to use
  4960. columns[ visibleColumns[i] ].sWidth = _fnStringToCss( bounding - border );
  4961. }
  4962. table.style.width = _fnStringToCss( total );
  4963. // Finished with the table - ditch it
  4964. holder.remove();
  4965. }
  4966. // If there is a width attr, we want to attach an event listener which
  4967. // allows the table sizing to automatically adjust when the window is
  4968. // resized. Use the width attr rather than CSS, since we can't know if the
  4969. // CSS is a relative value or absolute - DOM read is always px.
  4970. if ( tableWidthAttr ) {
  4971. table.style.width = _fnStringToCss( tableWidthAttr );
  4972. }
  4973. if ( (tableWidthAttr || scrollX) && ! oSettings._reszEvt ) {
  4974. var bindResize = function () {
  4975. $(window).on('resize.DT-'+oSettings.sInstance, _fnThrottle( function () {
  4976. _fnAdjustColumnSizing( oSettings );
  4977. } ) );
  4978. };
  4979. // IE6/7 will crash if we bind a resize event handler on page load.
  4980. // To be removed in 1.11 which drops IE6/7 support
  4981. if ( ie67 ) {
  4982. setTimeout( bindResize, 1000 );
  4983. }
  4984. else {
  4985. bindResize();
  4986. }
  4987. oSettings._reszEvt = true;
  4988. }
  4989. }
  4990. /**
  4991. * Throttle the calls to a function. Arguments and context are maintained for
  4992. * the throttled function
  4993. * @param {function} fn Function to be called
  4994. * @param {int} [freq=200] call frequency in mS
  4995. * @returns {function} wrapped function
  4996. * @memberof DataTable#oApi
  4997. */
  4998. var _fnThrottle = DataTable.util.throttle;
  4999. /**
  5000. * Convert a CSS unit width to pixels (e.g. 2em)
  5001. * @param {string} width width to be converted
  5002. * @param {node} parent parent to get the with for (required for relative widths) - optional
  5003. * @returns {int} width in pixels
  5004. * @memberof DataTable#oApi
  5005. */
  5006. function _fnConvertToWidth ( width, parent )
  5007. {
  5008. if ( ! width ) {
  5009. return 0;
  5010. }
  5011. var n = $('<div/>')
  5012. .css( 'width', _fnStringToCss( width ) )
  5013. .appendTo( parent || document.body );
  5014. var val = n[0].offsetWidth;
  5015. n.remove();
  5016. return val;
  5017. }
  5018. /**
  5019. * Get the widest node
  5020. * @param {object} settings dataTables settings object
  5021. * @param {int} colIdx column of interest
  5022. * @returns {node} widest table node
  5023. * @memberof DataTable#oApi
  5024. */
  5025. function _fnGetWidestNode( settings, colIdx )
  5026. {
  5027. var idx = _fnGetMaxLenString( settings, colIdx );
  5028. if ( idx < 0 ) {
  5029. return null;
  5030. }
  5031. var data = settings.aoData[ idx ];
  5032. return ! data.nTr ? // Might not have been created when deferred rendering
  5033. $('<td/>').html( _fnGetCellData( settings, idx, colIdx, 'display' ) )[0] :
  5034. data.anCells[ colIdx ];
  5035. }
  5036. /**
  5037. * Get the maximum strlen for each data column
  5038. * @param {object} settings dataTables settings object
  5039. * @param {int} colIdx column of interest
  5040. * @returns {string} max string length for each column
  5041. * @memberof DataTable#oApi
  5042. */
  5043. function _fnGetMaxLenString( settings, colIdx )
  5044. {
  5045. var s, max=-1, maxIdx = -1;
  5046. for ( var i=0, ien=settings.aoData.length ; i<ien ; i++ ) {
  5047. s = _fnGetCellData( settings, i, colIdx, 'display' )+'';
  5048. s = s.replace( __re_html_remove, '' );
  5049. s = s.replace( /&nbsp;/g, ' ' );
  5050. if ( s.length > max ) {
  5051. max = s.length;
  5052. maxIdx = i;
  5053. }
  5054. }
  5055. return maxIdx;
  5056. }
  5057. /**
  5058. * Append a CSS unit (only if required) to a string
  5059. * @param {string} value to css-ify
  5060. * @returns {string} value with css unit
  5061. * @memberof DataTable#oApi
  5062. */
  5063. function _fnStringToCss( s )
  5064. {
  5065. if ( s === null ) {
  5066. return '0px';
  5067. }
  5068. if ( typeof s == 'number' ) {
  5069. return s < 0 ?
  5070. '0px' :
  5071. s+'px';
  5072. }
  5073. // Check it has a unit character already
  5074. return s.match(/\d$/) ?
  5075. s+'px' :
  5076. s;
  5077. }
  5078. function _fnSortFlatten ( settings )
  5079. {
  5080. var
  5081. i, iLen, k, kLen,
  5082. aSort = [],
  5083. aiOrig = [],
  5084. aoColumns = settings.aoColumns,
  5085. aDataSort, iCol, sType, srcCol,
  5086. fixed = settings.aaSortingFixed,
  5087. fixedObj = $.isPlainObject( fixed ),
  5088. nestedSort = [],
  5089. add = function ( a ) {
  5090. if ( a.length && ! Array.isArray( a[0] ) ) {
  5091. // 1D array
  5092. nestedSort.push( a );
  5093. }
  5094. else {
  5095. // 2D array
  5096. $.merge( nestedSort, a );
  5097. }
  5098. };
  5099. // Build the sort array, with pre-fix and post-fix options if they have been
  5100. // specified
  5101. if ( Array.isArray( fixed ) ) {
  5102. add( fixed );
  5103. }
  5104. if ( fixedObj && fixed.pre ) {
  5105. add( fixed.pre );
  5106. }
  5107. add( settings.aaSorting );
  5108. if (fixedObj && fixed.post ) {
  5109. add( fixed.post );
  5110. }
  5111. for ( i=0 ; i<nestedSort.length ; i++ )
  5112. {
  5113. srcCol = nestedSort[i][0];
  5114. aDataSort = aoColumns[ srcCol ].aDataSort;
  5115. for ( k=0, kLen=aDataSort.length ; k<kLen ; k++ )
  5116. {
  5117. iCol = aDataSort[k];
  5118. sType = aoColumns[ iCol ].sType || 'string';
  5119. if ( nestedSort[i]._idx === undefined ) {
  5120. nestedSort[i]._idx = $.inArray( nestedSort[i][1], aoColumns[iCol].asSorting );
  5121. }
  5122. aSort.push( {
  5123. src: srcCol,
  5124. col: iCol,
  5125. dir: nestedSort[i][1],
  5126. index: nestedSort[i]._idx,
  5127. type: sType,
  5128. formatter: DataTable.ext.type.order[ sType+"-pre" ]
  5129. } );
  5130. }
  5131. }
  5132. return aSort;
  5133. }
  5134. /**
  5135. * Change the order of the table
  5136. * @param {object} oSettings dataTables settings object
  5137. * @memberof DataTable#oApi
  5138. * @todo This really needs split up!
  5139. */
  5140. function _fnSort ( oSettings )
  5141. {
  5142. var
  5143. i, ien, iLen, j, jLen, k, kLen,
  5144. sDataType, nTh,
  5145. aiOrig = [],
  5146. oExtSort = DataTable.ext.type.order,
  5147. aoData = oSettings.aoData,
  5148. aoColumns = oSettings.aoColumns,
  5149. aDataSort, data, iCol, sType, oSort,
  5150. formatters = 0,
  5151. sortCol,
  5152. displayMaster = oSettings.aiDisplayMaster,
  5153. aSort;
  5154. // Resolve any column types that are unknown due to addition or invalidation
  5155. // @todo Can this be moved into a 'data-ready' handler which is called when
  5156. // data is going to be used in the table?
  5157. _fnColumnTypes( oSettings );
  5158. aSort = _fnSortFlatten( oSettings );
  5159. for ( i=0, ien=aSort.length ; i<ien ; i++ ) {
  5160. sortCol = aSort[i];
  5161. // Track if we can use the fast sort algorithm
  5162. if ( sortCol.formatter ) {
  5163. formatters++;
  5164. }
  5165. // Load the data needed for the sort, for each cell
  5166. _fnSortData( oSettings, sortCol.col );
  5167. }
  5168. /* No sorting required if server-side or no sorting array */
  5169. if ( _fnDataSource( oSettings ) != 'ssp' && aSort.length !== 0 )
  5170. {
  5171. // Create a value - key array of the current row positions such that we can use their
  5172. // current position during the sort, if values match, in order to perform stable sorting
  5173. for ( i=0, iLen=displayMaster.length ; i<iLen ; i++ ) {
  5174. aiOrig[ displayMaster[i] ] = i;
  5175. }
  5176. /* Do the sort - here we want multi-column sorting based on a given data source (column)
  5177. * and sorting function (from oSort) in a certain direction. It's reasonably complex to
  5178. * follow on it's own, but this is what we want (example two column sorting):
  5179. * fnLocalSorting = function(a,b){
  5180. * var iTest;
  5181. * iTest = oSort['string-asc']('data11', 'data12');
  5182. * if (iTest !== 0)
  5183. * return iTest;
  5184. * iTest = oSort['numeric-desc']('data21', 'data22');
  5185. * if (iTest !== 0)
  5186. * return iTest;
  5187. * return oSort['numeric-asc']( aiOrig[a], aiOrig[b] );
  5188. * }
  5189. * Basically we have a test for each sorting column, if the data in that column is equal,
  5190. * test the next column. If all columns match, then we use a numeric sort on the row
  5191. * positions in the original data array to provide a stable sort.
  5192. *
  5193. * Note - I know it seems excessive to have two sorting methods, but the first is around
  5194. * 15% faster, so the second is only maintained for backwards compatibility with sorting
  5195. * methods which do not have a pre-sort formatting function.
  5196. */
  5197. if ( formatters === aSort.length ) {
  5198. // All sort types have formatting functions
  5199. displayMaster.sort( function ( a, b ) {
  5200. var
  5201. x, y, k, test, sort,
  5202. len=aSort.length,
  5203. dataA = aoData[a]._aSortData,
  5204. dataB = aoData[b]._aSortData;
  5205. for ( k=0 ; k<len ; k++ ) {
  5206. sort = aSort[k];
  5207. x = dataA[ sort.col ];
  5208. y = dataB[ sort.col ];
  5209. test = x<y ? -1 : x>y ? 1 : 0;
  5210. if ( test !== 0 ) {
  5211. return sort.dir === 'asc' ? test : -test;
  5212. }
  5213. }
  5214. x = aiOrig[a];
  5215. y = aiOrig[b];
  5216. return x<y ? -1 : x>y ? 1 : 0;
  5217. } );
  5218. }
  5219. else {
  5220. // Depreciated - remove in 1.11 (providing a plug-in option)
  5221. // Not all sort types have formatting methods, so we have to call their sorting
  5222. // methods.
  5223. displayMaster.sort( function ( a, b ) {
  5224. var
  5225. x, y, k, l, test, sort, fn,
  5226. len=aSort.length,
  5227. dataA = aoData[a]._aSortData,
  5228. dataB = aoData[b]._aSortData;
  5229. for ( k=0 ; k<len ; k++ ) {
  5230. sort = aSort[k];
  5231. x = dataA[ sort.col ];
  5232. y = dataB[ sort.col ];
  5233. fn = oExtSort[ sort.type+"-"+sort.dir ] || oExtSort[ "string-"+sort.dir ];
  5234. test = fn( x, y );
  5235. if ( test !== 0 ) {
  5236. return test;
  5237. }
  5238. }
  5239. x = aiOrig[a];
  5240. y = aiOrig[b];
  5241. return x<y ? -1 : x>y ? 1 : 0;
  5242. } );
  5243. }
  5244. }
  5245. /* Tell the draw function that we have sorted the data */
  5246. oSettings.bSorted = true;
  5247. }
  5248. function _fnSortAria ( settings )
  5249. {
  5250. var label;
  5251. var nextSort;
  5252. var columns = settings.aoColumns;
  5253. var aSort = _fnSortFlatten( settings );
  5254. var oAria = settings.oLanguage.oAria;
  5255. // ARIA attributes - need to loop all columns, to update all (removing old
  5256. // attributes as needed)
  5257. for ( var i=0, iLen=columns.length ; i<iLen ; i++ )
  5258. {
  5259. var col = columns[i];
  5260. var asSorting = col.asSorting;
  5261. var sTitle = col.ariaTitle || col.sTitle.replace( /<.*?>/g, "" );
  5262. var th = col.nTh;
  5263. // IE7 is throwing an error when setting these properties with jQuery's
  5264. // attr() and removeAttr() methods...
  5265. th.removeAttribute('aria-sort');
  5266. /* In ARIA only the first sorting column can be marked as sorting - no multi-sort option */
  5267. if ( col.bSortable ) {
  5268. if ( aSort.length > 0 && aSort[0].col == i ) {
  5269. th.setAttribute('aria-sort', aSort[0].dir=="asc" ? "ascending" : "descending" );
  5270. nextSort = asSorting[ aSort[0].index+1 ] || asSorting[0];
  5271. }
  5272. else {
  5273. nextSort = asSorting[0];
  5274. }
  5275. label = sTitle + ( nextSort === "asc" ?
  5276. oAria.sSortAscending :
  5277. oAria.sSortDescending
  5278. );
  5279. }
  5280. else {
  5281. label = sTitle;
  5282. }
  5283. th.setAttribute('aria-label', label);
  5284. }
  5285. }
  5286. /**
  5287. * Function to run on user sort request
  5288. * @param {object} settings dataTables settings object
  5289. * @param {node} attachTo node to attach the handler to
  5290. * @param {int} colIdx column sorting index
  5291. * @param {boolean} [append=false] Append the requested sort to the existing
  5292. * sort if true (i.e. multi-column sort)
  5293. * @param {function} [callback] callback function
  5294. * @memberof DataTable#oApi
  5295. */
  5296. function _fnSortListener ( settings, colIdx, append, callback )
  5297. {
  5298. var col = settings.aoColumns[ colIdx ];
  5299. var sorting = settings.aaSorting;
  5300. var asSorting = col.asSorting;
  5301. var nextSortIdx;
  5302. var next = function ( a, overflow ) {
  5303. var idx = a._idx;
  5304. if ( idx === undefined ) {
  5305. idx = $.inArray( a[1], asSorting );
  5306. }
  5307. return idx+1 < asSorting.length ?
  5308. idx+1 :
  5309. overflow ?
  5310. null :
  5311. 0;
  5312. };
  5313. // Convert to 2D array if needed
  5314. if ( typeof sorting[0] === 'number' ) {
  5315. sorting = settings.aaSorting = [ sorting ];
  5316. }
  5317. // If appending the sort then we are multi-column sorting
  5318. if ( append && settings.oFeatures.bSortMulti ) {
  5319. // Are we already doing some kind of sort on this column?
  5320. var sortIdx = $.inArray( colIdx, _pluck(sorting, '0') );
  5321. if ( sortIdx !== -1 ) {
  5322. // Yes, modify the sort
  5323. nextSortIdx = next( sorting[sortIdx], true );
  5324. if ( nextSortIdx === null && sorting.length === 1 ) {
  5325. nextSortIdx = 0; // can't remove sorting completely
  5326. }
  5327. if ( nextSortIdx === null ) {
  5328. sorting.splice( sortIdx, 1 );
  5329. }
  5330. else {
  5331. sorting[sortIdx][1] = asSorting[ nextSortIdx ];
  5332. sorting[sortIdx]._idx = nextSortIdx;
  5333. }
  5334. }
  5335. else {
  5336. // No sort on this column yet
  5337. sorting.push( [ colIdx, asSorting[0], 0 ] );
  5338. sorting[sorting.length-1]._idx = 0;
  5339. }
  5340. }
  5341. else if ( sorting.length && sorting[0][0] == colIdx ) {
  5342. // Single column - already sorting on this column, modify the sort
  5343. nextSortIdx = next( sorting[0] );
  5344. sorting.length = 1;
  5345. sorting[0][1] = asSorting[ nextSortIdx ];
  5346. sorting[0]._idx = nextSortIdx;
  5347. }
  5348. else {
  5349. // Single column - sort only on this column
  5350. sorting.length = 0;
  5351. sorting.push( [ colIdx, asSorting[0] ] );
  5352. sorting[0]._idx = 0;
  5353. }
  5354. // Run the sort by calling a full redraw
  5355. _fnReDraw( settings );
  5356. // callback used for async user interaction
  5357. if ( typeof callback == 'function' ) {
  5358. callback( settings );
  5359. }
  5360. }
  5361. /**
  5362. * Attach a sort handler (click) to a node
  5363. * @param {object} settings dataTables settings object
  5364. * @param {node} attachTo node to attach the handler to
  5365. * @param {int} colIdx column sorting index
  5366. * @param {function} [callback] callback function
  5367. * @memberof DataTable#oApi
  5368. */
  5369. function _fnSortAttachListener ( settings, attachTo, colIdx, callback )
  5370. {
  5371. var col = settings.aoColumns[ colIdx ];
  5372. _fnBindAction( attachTo, {}, function (e) {
  5373. /* If the column is not sortable - don't to anything */
  5374. if ( col.bSortable === false ) {
  5375. return;
  5376. }
  5377. // If processing is enabled use a timeout to allow the processing
  5378. // display to be shown - otherwise to it synchronously
  5379. if ( settings.oFeatures.bProcessing ) {
  5380. _fnProcessingDisplay( settings, true );
  5381. setTimeout( function() {
  5382. _fnSortListener( settings, colIdx, e.shiftKey, callback );
  5383. // In server-side processing, the draw callback will remove the
  5384. // processing display
  5385. if ( _fnDataSource( settings ) !== 'ssp' ) {
  5386. _fnProcessingDisplay( settings, false );
  5387. }
  5388. }, 0 );
  5389. }
  5390. else {
  5391. _fnSortListener( settings, colIdx, e.shiftKey, callback );
  5392. }
  5393. } );
  5394. }
  5395. /**
  5396. * Set the sorting classes on table's body, Note: it is safe to call this function
  5397. * when bSort and bSortClasses are false
  5398. * @param {object} oSettings dataTables settings object
  5399. * @memberof DataTable#oApi
  5400. */
  5401. function _fnSortingClasses( settings )
  5402. {
  5403. var oldSort = settings.aLastSort;
  5404. var sortClass = settings.oClasses.sSortColumn;
  5405. var sort = _fnSortFlatten( settings );
  5406. var features = settings.oFeatures;
  5407. var i, ien, colIdx;
  5408. if ( features.bSort && features.bSortClasses ) {
  5409. // Remove old sorting classes
  5410. for ( i=0, ien=oldSort.length ; i<ien ; i++ ) {
  5411. colIdx = oldSort[i].src;
  5412. // Remove column sorting
  5413. $( _pluck( settings.aoData, 'anCells', colIdx ) )
  5414. .removeClass( sortClass + (i<2 ? i+1 : 3) );
  5415. }
  5416. // Add new column sorting
  5417. for ( i=0, ien=sort.length ; i<ien ; i++ ) {
  5418. colIdx = sort[i].src;
  5419. $( _pluck( settings.aoData, 'anCells', colIdx ) )
  5420. .addClass( sortClass + (i<2 ? i+1 : 3) );
  5421. }
  5422. }
  5423. settings.aLastSort = sort;
  5424. }
  5425. // Get the data to sort a column, be it from cache, fresh (populating the
  5426. // cache), or from a sort formatter
  5427. function _fnSortData( settings, idx )
  5428. {
  5429. // Custom sorting function - provided by the sort data type
  5430. var column = settings.aoColumns[ idx ];
  5431. var customSort = DataTable.ext.order[ column.sSortDataType ];
  5432. var customData;
  5433. if ( customSort ) {
  5434. customData = customSort.call( settings.oInstance, settings, idx,
  5435. _fnColumnIndexToVisible( settings, idx )
  5436. );
  5437. }
  5438. // Use / populate cache
  5439. var row, cellData;
  5440. var formatter = DataTable.ext.type.order[ column.sType+"-pre" ];
  5441. for ( var i=0, ien=settings.aoData.length ; i<ien ; i++ ) {
  5442. row = settings.aoData[i];
  5443. if ( ! row._aSortData ) {
  5444. row._aSortData = [];
  5445. }
  5446. if ( ! row._aSortData[idx] || customSort ) {
  5447. cellData = customSort ?
  5448. customData[i] : // If there was a custom sort function, use data from there
  5449. _fnGetCellData( settings, i, idx, 'sort' );
  5450. row._aSortData[ idx ] = formatter ?
  5451. formatter( cellData ) :
  5452. cellData;
  5453. }
  5454. }
  5455. }
  5456. /**
  5457. * Save the state of a table
  5458. * @param {object} oSettings dataTables settings object
  5459. * @memberof DataTable#oApi
  5460. */
  5461. function _fnSaveState ( settings )
  5462. {
  5463. if (settings._bLoadingState) {
  5464. return;
  5465. }
  5466. /* Store the interesting variables */
  5467. var state = {
  5468. time: +new Date(),
  5469. start: settings._iDisplayStart,
  5470. length: settings._iDisplayLength,
  5471. order: $.extend( true, [], settings.aaSorting ),
  5472. search: _fnSearchToCamel( settings.oPreviousSearch ),
  5473. columns: $.map( settings.aoColumns, function ( col, i ) {
  5474. return {
  5475. visible: col.bVisible,
  5476. search: _fnSearchToCamel( settings.aoPreSearchCols[i] )
  5477. };
  5478. } )
  5479. };
  5480. settings.oSavedState = state;
  5481. _fnCallbackFire( settings, "aoStateSaveParams", 'stateSaveParams', [settings, state] );
  5482. if ( settings.oFeatures.bStateSave && !settings.bDestroying )
  5483. {
  5484. settings.fnStateSaveCallback.call( settings.oInstance, settings, state );
  5485. }
  5486. }
  5487. /**
  5488. * Attempt to load a saved table state
  5489. * @param {object} oSettings dataTables settings object
  5490. * @param {object} oInit DataTables init object so we can override settings
  5491. * @param {function} callback Callback to execute when the state has been loaded
  5492. * @memberof DataTable#oApi
  5493. */
  5494. function _fnLoadState ( settings, oInit, callback )
  5495. {
  5496. if ( ! settings.oFeatures.bStateSave ) {
  5497. callback();
  5498. return;
  5499. }
  5500. var loaded = function(state) {
  5501. _fnImplementState(settings, state, callback);
  5502. }
  5503. var state = settings.fnStateLoadCallback.call( settings.oInstance, settings, loaded );
  5504. if ( state !== undefined ) {
  5505. _fnImplementState( settings, state, callback );
  5506. }
  5507. // otherwise, wait for the loaded callback to be executed
  5508. return true;
  5509. }
  5510. function _fnImplementState ( settings, s, callback) {
  5511. var i, ien;
  5512. var columns = settings.aoColumns;
  5513. settings._bLoadingState = true;
  5514. // When StateRestore was introduced the state could now be implemented at any time
  5515. // Not just initialisation. To do this an api instance is required in some places
  5516. var api = settings._bInitComplete ? new DataTable.Api(settings) : null;
  5517. if ( ! s || ! s.time ) {
  5518. settings._bLoadingState = false;
  5519. callback();
  5520. return;
  5521. }
  5522. // Allow custom and plug-in manipulation functions to alter the saved data set and
  5523. // cancelling of loading by returning false
  5524. var abStateLoad = _fnCallbackFire( settings, 'aoStateLoadParams', 'stateLoadParams', [settings, s] );
  5525. if ( $.inArray( false, abStateLoad ) !== -1 ) {
  5526. settings._bLoadingState = false;
  5527. callback();
  5528. return;
  5529. }
  5530. // Reject old data
  5531. var duration = settings.iStateDuration;
  5532. if ( duration > 0 && s.time < +new Date() - (duration*1000) ) {
  5533. settings._bLoadingState = false;
  5534. callback();
  5535. return;
  5536. }
  5537. // Number of columns have changed - all bets are off, no restore of settings
  5538. if ( s.columns && columns.length !== s.columns.length ) {
  5539. settings._bLoadingState = false;
  5540. callback();
  5541. return;
  5542. }
  5543. // Store the saved state so it might be accessed at any time
  5544. settings.oLoadedState = $.extend( true, {}, s );
  5545. // Page Length
  5546. if ( s.length !== undefined ) {
  5547. // If already initialised just set the value directly so that the select element is also updated
  5548. if (api) {
  5549. api.page.len(s.length)
  5550. }
  5551. else {
  5552. settings._iDisplayLength = s.length;
  5553. }
  5554. }
  5555. // Restore key features - todo - for 1.11 this needs to be done by
  5556. // subscribed events
  5557. if ( s.start !== undefined ) {
  5558. if(api === null) {
  5559. settings._iDisplayStart = s.start;
  5560. settings.iInitDisplayStart = s.start;
  5561. }
  5562. else {
  5563. _fnPageChange(settings, s.start/settings._iDisplayLength);
  5564. }
  5565. }
  5566. // Order
  5567. if ( s.order !== undefined ) {
  5568. settings.aaSorting = [];
  5569. $.each( s.order, function ( i, col ) {
  5570. settings.aaSorting.push( col[0] >= columns.length ?
  5571. [ 0, col[1] ] :
  5572. col
  5573. );
  5574. } );
  5575. }
  5576. // Search
  5577. if ( s.search !== undefined ) {
  5578. $.extend( settings.oPreviousSearch, _fnSearchToHung( s.search ) );
  5579. }
  5580. // Columns
  5581. if ( s.columns ) {
  5582. for ( i=0, ien=s.columns.length ; i<ien ; i++ ) {
  5583. var col = s.columns[i];
  5584. // Visibility
  5585. if ( col.visible !== undefined ) {
  5586. // If the api is defined, the table has been initialised so we need to use it rather than internal settings
  5587. if (api) {
  5588. // Don't redraw the columns on every iteration of this loop, we will do this at the end instead
  5589. api.column(i).visible(col.visible, false);
  5590. }
  5591. else {
  5592. columns[i].bVisible = col.visible;
  5593. }
  5594. }
  5595. // Search
  5596. if ( col.search !== undefined ) {
  5597. $.extend( settings.aoPreSearchCols[i], _fnSearchToHung( col.search ) );
  5598. }
  5599. }
  5600. // If the api is defined then we need to adjust the columns once the visibility has been changed
  5601. if (api) {
  5602. api.columns.adjust();
  5603. }
  5604. }
  5605. settings._bLoadingState = false;
  5606. _fnCallbackFire( settings, 'aoStateLoaded', 'stateLoaded', [settings, s] );
  5607. callback();
  5608. };
  5609. /**
  5610. * Return the settings object for a particular table
  5611. * @param {node} table table we are using as a dataTable
  5612. * @returns {object} Settings object - or null if not found
  5613. * @memberof DataTable#oApi
  5614. */
  5615. function _fnSettingsFromNode ( table )
  5616. {
  5617. var settings = DataTable.settings;
  5618. var idx = $.inArray( table, _pluck( settings, 'nTable' ) );
  5619. return idx !== -1 ?
  5620. settings[ idx ] :
  5621. null;
  5622. }
  5623. /**
  5624. * Log an error message
  5625. * @param {object} settings dataTables settings object
  5626. * @param {int} level log error messages, or display them to the user
  5627. * @param {string} msg error message
  5628. * @param {int} tn Technical note id to get more information about the error.
  5629. * @memberof DataTable#oApi
  5630. */
  5631. function _fnLog( settings, level, msg, tn )
  5632. {
  5633. msg = 'DataTables warning: '+
  5634. (settings ? 'table id='+settings.sTableId+' - ' : '')+msg;
  5635. if ( tn ) {
  5636. msg += '. For more information about this error, please see '+
  5637. 'http://datatables.net/tn/'+tn;
  5638. }
  5639. if ( ! level ) {
  5640. // Backwards compatibility pre 1.10
  5641. var ext = DataTable.ext;
  5642. var type = ext.sErrMode || ext.errMode;
  5643. if ( settings ) {
  5644. _fnCallbackFire( settings, null, 'error', [ settings, tn, msg ] );
  5645. }
  5646. if ( type == 'alert' ) {
  5647. alert( msg );
  5648. }
  5649. else if ( type == 'throw' ) {
  5650. throw new Error(msg);
  5651. }
  5652. else if ( typeof type == 'function' ) {
  5653. type( settings, tn, msg );
  5654. }
  5655. }
  5656. else if ( window.console && console.log ) {
  5657. console.log( msg );
  5658. }
  5659. }
  5660. /**
  5661. * See if a property is defined on one object, if so assign it to the other object
  5662. * @param {object} ret target object
  5663. * @param {object} src source object
  5664. * @param {string} name property
  5665. * @param {string} [mappedName] name to map too - optional, name used if not given
  5666. * @memberof DataTable#oApi
  5667. */
  5668. function _fnMap( ret, src, name, mappedName )
  5669. {
  5670. if ( Array.isArray( name ) ) {
  5671. $.each( name, function (i, val) {
  5672. if ( Array.isArray( val ) ) {
  5673. _fnMap( ret, src, val[0], val[1] );
  5674. }
  5675. else {
  5676. _fnMap( ret, src, val );
  5677. }
  5678. } );
  5679. return;
  5680. }
  5681. if ( mappedName === undefined ) {
  5682. mappedName = name;
  5683. }
  5684. if ( src[name] !== undefined ) {
  5685. ret[mappedName] = src[name];
  5686. }
  5687. }
  5688. /**
  5689. * Extend objects - very similar to jQuery.extend, but deep copy objects, and
  5690. * shallow copy arrays. The reason we need to do this, is that we don't want to
  5691. * deep copy array init values (such as aaSorting) since the dev wouldn't be
  5692. * able to override them, but we do want to deep copy arrays.
  5693. * @param {object} out Object to extend
  5694. * @param {object} extender Object from which the properties will be applied to
  5695. * out
  5696. * @param {boolean} breakRefs If true, then arrays will be sliced to take an
  5697. * independent copy with the exception of the `data` or `aaData` parameters
  5698. * if they are present. This is so you can pass in a collection to
  5699. * DataTables and have that used as your data source without breaking the
  5700. * references
  5701. * @returns {object} out Reference, just for convenience - out === the return.
  5702. * @memberof DataTable#oApi
  5703. * @todo This doesn't take account of arrays inside the deep copied objects.
  5704. */
  5705. function _fnExtend( out, extender, breakRefs )
  5706. {
  5707. var val;
  5708. for ( var prop in extender ) {
  5709. if ( extender.hasOwnProperty(prop) ) {
  5710. val = extender[prop];
  5711. if ( $.isPlainObject( val ) ) {
  5712. if ( ! $.isPlainObject( out[prop] ) ) {
  5713. out[prop] = {};
  5714. }
  5715. $.extend( true, out[prop], val );
  5716. }
  5717. else if ( breakRefs && prop !== 'data' && prop !== 'aaData' && Array.isArray(val) ) {
  5718. out[prop] = val.slice();
  5719. }
  5720. else {
  5721. out[prop] = val;
  5722. }
  5723. }
  5724. }
  5725. return out;
  5726. }
  5727. /**
  5728. * Bind an event handers to allow a click or return key to activate the callback.
  5729. * This is good for accessibility since a return on the keyboard will have the
  5730. * same effect as a click, if the element has focus.
  5731. * @param {element} n Element to bind the action to
  5732. * @param {object} oData Data object to pass to the triggered function
  5733. * @param {function} fn Callback function for when the event is triggered
  5734. * @memberof DataTable#oApi
  5735. */
  5736. function _fnBindAction( n, oData, fn )
  5737. {
  5738. $(n)
  5739. .on( 'click.DT', oData, function (e) {
  5740. $(n).trigger('blur'); // Remove focus outline for mouse users
  5741. fn(e);
  5742. } )
  5743. .on( 'keypress.DT', oData, function (e){
  5744. if ( e.which === 13 ) {
  5745. e.preventDefault();
  5746. fn(e);
  5747. }
  5748. } )
  5749. .on( 'selectstart.DT', function () {
  5750. /* Take the brutal approach to cancelling text selection */
  5751. return false;
  5752. } );
  5753. }
  5754. /**
  5755. * Register a callback function. Easily allows a callback function to be added to
  5756. * an array store of callback functions that can then all be called together.
  5757. * @param {object} oSettings dataTables settings object
  5758. * @param {string} sStore Name of the array storage for the callbacks in oSettings
  5759. * @param {function} fn Function to be called back
  5760. * @param {string} sName Identifying name for the callback (i.e. a label)
  5761. * @memberof DataTable#oApi
  5762. */
  5763. function _fnCallbackReg( oSettings, sStore, fn, sName )
  5764. {
  5765. if ( fn )
  5766. {
  5767. oSettings[sStore].push( {
  5768. "fn": fn,
  5769. "sName": sName
  5770. } );
  5771. }
  5772. }
  5773. /**
  5774. * Fire callback functions and trigger events. Note that the loop over the
  5775. * callback array store is done backwards! Further note that you do not want to
  5776. * fire off triggers in time sensitive applications (for example cell creation)
  5777. * as its slow.
  5778. * @param {object} settings dataTables settings object
  5779. * @param {string} callbackArr Name of the array storage for the callbacks in
  5780. * oSettings
  5781. * @param {string} eventName Name of the jQuery custom event to trigger. If
  5782. * null no trigger is fired
  5783. * @param {array} args Array of arguments to pass to the callback function /
  5784. * trigger
  5785. * @memberof DataTable#oApi
  5786. */
  5787. function _fnCallbackFire( settings, callbackArr, eventName, args )
  5788. {
  5789. var ret = [];
  5790. if ( callbackArr ) {
  5791. ret = $.map( settings[callbackArr].slice().reverse(), function (val, i) {
  5792. return val.fn.apply( settings.oInstance, args );
  5793. } );
  5794. }
  5795. if ( eventName !== null ) {
  5796. var e = $.Event( eventName+'.dt' );
  5797. var table = $(settings.nTable);
  5798. table.trigger( e, args );
  5799. // If not yet attached to the document, trigger the event
  5800. // on the body directly to sort of simulate the bubble
  5801. if (table.parents('body').length === 0) {
  5802. $('body').trigger( e, args );
  5803. }
  5804. ret.push( e.result );
  5805. }
  5806. return ret;
  5807. }
  5808. function _fnLengthOverflow ( settings )
  5809. {
  5810. var
  5811. start = settings._iDisplayStart,
  5812. end = settings.fnDisplayEnd(),
  5813. len = settings._iDisplayLength;
  5814. /* If we have space to show extra rows (backing up from the end point - then do so */
  5815. if ( start >= end )
  5816. {
  5817. start = end - len;
  5818. }
  5819. // Keep the start record on the current page
  5820. start -= (start % len);
  5821. if ( len === -1 || start < 0 )
  5822. {
  5823. start = 0;
  5824. }
  5825. settings._iDisplayStart = start;
  5826. }
  5827. function _fnRenderer( settings, type )
  5828. {
  5829. var renderer = settings.renderer;
  5830. var host = DataTable.ext.renderer[type];
  5831. if ( $.isPlainObject( renderer ) && renderer[type] ) {
  5832. // Specific renderer for this type. If available use it, otherwise use
  5833. // the default.
  5834. return host[renderer[type]] || host._;
  5835. }
  5836. else if ( typeof renderer === 'string' ) {
  5837. // Common renderer - if there is one available for this type use it,
  5838. // otherwise use the default
  5839. return host[renderer] || host._;
  5840. }
  5841. // Use the default
  5842. return host._;
  5843. }
  5844. /**
  5845. * Detect the data source being used for the table. Used to simplify the code
  5846. * a little (ajax) and to make it compress a little smaller.
  5847. *
  5848. * @param {object} settings dataTables settings object
  5849. * @returns {string} Data source
  5850. * @memberof DataTable#oApi
  5851. */
  5852. function _fnDataSource ( settings )
  5853. {
  5854. if ( settings.oFeatures.bServerSide ) {
  5855. return 'ssp';
  5856. }
  5857. else if ( settings.ajax || settings.sAjaxSource ) {
  5858. return 'ajax';
  5859. }
  5860. return 'dom';
  5861. }
  5862. /**
  5863. * Computed structure of the DataTables API, defined by the options passed to
  5864. * `DataTable.Api.register()` when building the API.
  5865. *
  5866. * The structure is built in order to speed creation and extension of the Api
  5867. * objects since the extensions are effectively pre-parsed.
  5868. *
  5869. * The array is an array of objects with the following structure, where this
  5870. * base array represents the Api prototype base:
  5871. *
  5872. * [
  5873. * {
  5874. * name: 'data' -- string - Property name
  5875. * val: function () {}, -- function - Api method (or undefined if just an object
  5876. * methodExt: [ ... ], -- array - Array of Api object definitions to extend the method result
  5877. * propExt: [ ... ] -- array - Array of Api object definitions to extend the property
  5878. * },
  5879. * {
  5880. * name: 'row'
  5881. * val: {},
  5882. * methodExt: [ ... ],
  5883. * propExt: [
  5884. * {
  5885. * name: 'data'
  5886. * val: function () {},
  5887. * methodExt: [ ... ],
  5888. * propExt: [ ... ]
  5889. * },
  5890. * ...
  5891. * ]
  5892. * }
  5893. * ]
  5894. *
  5895. * @type {Array}
  5896. * @ignore
  5897. */
  5898. var __apiStruct = [];
  5899. /**
  5900. * `Array.prototype` reference.
  5901. *
  5902. * @type object
  5903. * @ignore
  5904. */
  5905. var __arrayProto = Array.prototype;
  5906. /**
  5907. * Abstraction for `context` parameter of the `Api` constructor to allow it to
  5908. * take several different forms for ease of use.
  5909. *
  5910. * Each of the input parameter types will be converted to a DataTables settings
  5911. * object where possible.
  5912. *
  5913. * @param {string|node|jQuery|object} mixed DataTable identifier. Can be one
  5914. * of:
  5915. *
  5916. * * `string` - jQuery selector. Any DataTables' matching the given selector
  5917. * with be found and used.
  5918. * * `node` - `TABLE` node which has already been formed into a DataTable.
  5919. * * `jQuery` - A jQuery object of `TABLE` nodes.
  5920. * * `object` - DataTables settings object
  5921. * * `DataTables.Api` - API instance
  5922. * @return {array|null} Matching DataTables settings objects. `null` or
  5923. * `undefined` is returned if no matching DataTable is found.
  5924. * @ignore
  5925. */
  5926. var _toSettings = function ( mixed )
  5927. {
  5928. var idx, jq;
  5929. var settings = DataTable.settings;
  5930. var tables = $.map( settings, function (el, i) {
  5931. return el.nTable;
  5932. } );
  5933. if ( ! mixed ) {
  5934. return [];
  5935. }
  5936. else if ( mixed.nTable && mixed.oApi ) {
  5937. // DataTables settings object
  5938. return [ mixed ];
  5939. }
  5940. else if ( mixed.nodeName && mixed.nodeName.toLowerCase() === 'table' ) {
  5941. // Table node
  5942. idx = $.inArray( mixed, tables );
  5943. return idx !== -1 ? [ settings[idx] ] : null;
  5944. }
  5945. else if ( mixed && typeof mixed.settings === 'function' ) {
  5946. return mixed.settings().toArray();
  5947. }
  5948. else if ( typeof mixed === 'string' ) {
  5949. // jQuery selector
  5950. jq = $(mixed);
  5951. }
  5952. else if ( mixed instanceof $ ) {
  5953. // jQuery object (also DataTables instance)
  5954. jq = mixed;
  5955. }
  5956. if ( jq ) {
  5957. return jq.map( function(i) {
  5958. idx = $.inArray( this, tables );
  5959. return idx !== -1 ? settings[idx] : null;
  5960. } ).toArray();
  5961. }
  5962. };
  5963. /**
  5964. * DataTables API class - used to control and interface with one or more
  5965. * DataTables enhanced tables.
  5966. *
  5967. * The API class is heavily based on jQuery, presenting a chainable interface
  5968. * that you can use to interact with tables. Each instance of the API class has
  5969. * a "context" - i.e. the tables that it will operate on. This could be a single
  5970. * table, all tables on a page or a sub-set thereof.
  5971. *
  5972. * Additionally the API is designed to allow you to easily work with the data in
  5973. * the tables, retrieving and manipulating it as required. This is done by
  5974. * presenting the API class as an array like interface. The contents of the
  5975. * array depend upon the actions requested by each method (for example
  5976. * `rows().nodes()` will return an array of nodes, while `rows().data()` will
  5977. * return an array of objects or arrays depending upon your table's
  5978. * configuration). The API object has a number of array like methods (`push`,
  5979. * `pop`, `reverse` etc) as well as additional helper methods (`each`, `pluck`,
  5980. * `unique` etc) to assist your working with the data held in a table.
  5981. *
  5982. * Most methods (those which return an Api instance) are chainable, which means
  5983. * the return from a method call also has all of the methods available that the
  5984. * top level object had. For example, these two calls are equivalent:
  5985. *
  5986. * // Not chained
  5987. * api.row.add( {...} );
  5988. * api.draw();
  5989. *
  5990. * // Chained
  5991. * api.row.add( {...} ).draw();
  5992. *
  5993. * @class DataTable.Api
  5994. * @param {array|object|string|jQuery} context DataTable identifier. This is
  5995. * used to define which DataTables enhanced tables this API will operate on.
  5996. * Can be one of:
  5997. *
  5998. * * `string` - jQuery selector. Any DataTables' matching the given selector
  5999. * with be found and used.
  6000. * * `node` - `TABLE` node which has already been formed into a DataTable.
  6001. * * `jQuery` - A jQuery object of `TABLE` nodes.
  6002. * * `object` - DataTables settings object
  6003. * @param {array} [data] Data to initialise the Api instance with.
  6004. *
  6005. * @example
  6006. * // Direct initialisation during DataTables construction
  6007. * var api = $('#example').DataTable();
  6008. *
  6009. * @example
  6010. * // Initialisation using a DataTables jQuery object
  6011. * var api = $('#example').dataTable().api();
  6012. *
  6013. * @example
  6014. * // Initialisation as a constructor
  6015. * var api = new $.fn.DataTable.Api( 'table.dataTable' );
  6016. */
  6017. _Api = function ( context, data )
  6018. {
  6019. if ( ! (this instanceof _Api) ) {
  6020. return new _Api( context, data );
  6021. }
  6022. var settings = [];
  6023. var ctxSettings = function ( o ) {
  6024. var a = _toSettings( o );
  6025. if ( a ) {
  6026. settings.push.apply( settings, a );
  6027. }
  6028. };
  6029. if ( Array.isArray( context ) ) {
  6030. for ( var i=0, ien=context.length ; i<ien ; i++ ) {
  6031. ctxSettings( context[i] );
  6032. }
  6033. }
  6034. else {
  6035. ctxSettings( context );
  6036. }
  6037. // Remove duplicates
  6038. this.context = _unique( settings );
  6039. // Initial data
  6040. if ( data ) {
  6041. $.merge( this, data );
  6042. }
  6043. // selector
  6044. this.selector = {
  6045. rows: null,
  6046. cols: null,
  6047. opts: null
  6048. };
  6049. _Api.extend( this, this, __apiStruct );
  6050. };
  6051. DataTable.Api = _Api;
  6052. // Don't destroy the existing prototype, just extend it. Required for jQuery 2's
  6053. // isPlainObject.
  6054. $.extend( _Api.prototype, {
  6055. any: function ()
  6056. {
  6057. return this.count() !== 0;
  6058. },
  6059. concat: __arrayProto.concat,
  6060. context: [], // array of table settings objects
  6061. count: function ()
  6062. {
  6063. return this.flatten().length;
  6064. },
  6065. each: function ( fn )
  6066. {
  6067. for ( var i=0, ien=this.length ; i<ien; i++ ) {
  6068. fn.call( this, this[i], i, this );
  6069. }
  6070. return this;
  6071. },
  6072. eq: function ( idx )
  6073. {
  6074. var ctx = this.context;
  6075. return ctx.length > idx ?
  6076. new _Api( ctx[idx], this[idx] ) :
  6077. null;
  6078. },
  6079. filter: function ( fn )
  6080. {
  6081. var a = [];
  6082. if ( __arrayProto.filter ) {
  6083. a = __arrayProto.filter.call( this, fn, this );
  6084. }
  6085. else {
  6086. // Compatibility for browsers without EMCA-252-5 (JS 1.6)
  6087. for ( var i=0, ien=this.length ; i<ien ; i++ ) {
  6088. if ( fn.call( this, this[i], i, this ) ) {
  6089. a.push( this[i] );
  6090. }
  6091. }
  6092. }
  6093. return new _Api( this.context, a );
  6094. },
  6095. flatten: function ()
  6096. {
  6097. var a = [];
  6098. return new _Api( this.context, a.concat.apply( a, this.toArray() ) );
  6099. },
  6100. join: __arrayProto.join,
  6101. indexOf: __arrayProto.indexOf || function (obj, start)
  6102. {
  6103. for ( var i=(start || 0), ien=this.length ; i<ien ; i++ ) {
  6104. if ( this[i] === obj ) {
  6105. return i;
  6106. }
  6107. }
  6108. return -1;
  6109. },
  6110. iterator: function ( flatten, type, fn, alwaysNew ) {
  6111. var
  6112. a = [], ret,
  6113. i, ien, j, jen,
  6114. context = this.context,
  6115. rows, items, item,
  6116. selector = this.selector;
  6117. // Argument shifting
  6118. if ( typeof flatten === 'string' ) {
  6119. alwaysNew = fn;
  6120. fn = type;
  6121. type = flatten;
  6122. flatten = false;
  6123. }
  6124. for ( i=0, ien=context.length ; i<ien ; i++ ) {
  6125. var apiInst = new _Api( context[i] );
  6126. if ( type === 'table' ) {
  6127. ret = fn.call( apiInst, context[i], i );
  6128. if ( ret !== undefined ) {
  6129. a.push( ret );
  6130. }
  6131. }
  6132. else if ( type === 'columns' || type === 'rows' ) {
  6133. // this has same length as context - one entry for each table
  6134. ret = fn.call( apiInst, context[i], this[i], i );
  6135. if ( ret !== undefined ) {
  6136. a.push( ret );
  6137. }
  6138. }
  6139. else if ( type === 'column' || type === 'column-rows' || type === 'row' || type === 'cell' ) {
  6140. // columns and rows share the same structure.
  6141. // 'this' is an array of column indexes for each context
  6142. items = this[i];
  6143. if ( type === 'column-rows' ) {
  6144. rows = _selector_row_indexes( context[i], selector.opts );
  6145. }
  6146. for ( j=0, jen=items.length ; j<jen ; j++ ) {
  6147. item = items[j];
  6148. if ( type === 'cell' ) {
  6149. ret = fn.call( apiInst, context[i], item.row, item.column, i, j );
  6150. }
  6151. else {
  6152. ret = fn.call( apiInst, context[i], item, i, j, rows );
  6153. }
  6154. if ( ret !== undefined ) {
  6155. a.push( ret );
  6156. }
  6157. }
  6158. }
  6159. }
  6160. if ( a.length || alwaysNew ) {
  6161. var api = new _Api( context, flatten ? a.concat.apply( [], a ) : a );
  6162. var apiSelector = api.selector;
  6163. apiSelector.rows = selector.rows;
  6164. apiSelector.cols = selector.cols;
  6165. apiSelector.opts = selector.opts;
  6166. return api;
  6167. }
  6168. return this;
  6169. },
  6170. lastIndexOf: __arrayProto.lastIndexOf || function (obj, start)
  6171. {
  6172. // Bit cheeky...
  6173. return this.indexOf.apply( this.toArray.reverse(), arguments );
  6174. },
  6175. length: 0,
  6176. map: function ( fn )
  6177. {
  6178. var a = [];
  6179. if ( __arrayProto.map ) {
  6180. a = __arrayProto.map.call( this, fn, this );
  6181. }
  6182. else {
  6183. // Compatibility for browsers without EMCA-252-5 (JS 1.6)
  6184. for ( var i=0, ien=this.length ; i<ien ; i++ ) {
  6185. a.push( fn.call( this, this[i], i ) );
  6186. }
  6187. }
  6188. return new _Api( this.context, a );
  6189. },
  6190. pluck: function ( prop )
  6191. {
  6192. var fn = DataTable.util.get(prop);
  6193. return this.map( function ( el ) {
  6194. return fn(el);
  6195. } );
  6196. },
  6197. pop: __arrayProto.pop,
  6198. push: __arrayProto.push,
  6199. // Does not return an API instance
  6200. reduce: __arrayProto.reduce || function ( fn, init )
  6201. {
  6202. return _fnReduce( this, fn, init, 0, this.length, 1 );
  6203. },
  6204. reduceRight: __arrayProto.reduceRight || function ( fn, init )
  6205. {
  6206. return _fnReduce( this, fn, init, this.length-1, -1, -1 );
  6207. },
  6208. reverse: __arrayProto.reverse,
  6209. // Object with rows, columns and opts
  6210. selector: null,
  6211. shift: __arrayProto.shift,
  6212. slice: function () {
  6213. return new _Api( this.context, this );
  6214. },
  6215. sort: __arrayProto.sort, // ? name - order?
  6216. splice: __arrayProto.splice,
  6217. toArray: function ()
  6218. {
  6219. return __arrayProto.slice.call( this );
  6220. },
  6221. to$: function ()
  6222. {
  6223. return $( this );
  6224. },
  6225. toJQuery: function ()
  6226. {
  6227. return $( this );
  6228. },
  6229. unique: function ()
  6230. {
  6231. return new _Api( this.context, _unique(this) );
  6232. },
  6233. unshift: __arrayProto.unshift
  6234. } );
  6235. _Api.extend = function ( scope, obj, ext )
  6236. {
  6237. // Only extend API instances and static properties of the API
  6238. if ( ! ext.length || ! obj || ( ! (obj instanceof _Api) && ! obj.__dt_wrapper ) ) {
  6239. return;
  6240. }
  6241. var
  6242. i, ien,
  6243. struct,
  6244. methodScoping = function ( scope, fn, struc ) {
  6245. return function () {
  6246. var ret = fn.apply( scope, arguments );
  6247. // Method extension
  6248. _Api.extend( ret, ret, struc.methodExt );
  6249. return ret;
  6250. };
  6251. };
  6252. for ( i=0, ien=ext.length ; i<ien ; i++ ) {
  6253. struct = ext[i];
  6254. // Value
  6255. obj[ struct.name ] = struct.type === 'function' ?
  6256. methodScoping( scope, struct.val, struct ) :
  6257. struct.type === 'object' ?
  6258. {} :
  6259. struct.val;
  6260. obj[ struct.name ].__dt_wrapper = true;
  6261. // Property extension
  6262. _Api.extend( scope, obj[ struct.name ], struct.propExt );
  6263. }
  6264. };
  6265. // @todo - Is there need for an augment function?
  6266. // _Api.augment = function ( inst, name )
  6267. // {
  6268. // // Find src object in the structure from the name
  6269. // var parts = name.split('.');
  6270. // _Api.extend( inst, obj );
  6271. // };
  6272. // [
  6273. // {
  6274. // name: 'data' -- string - Property name
  6275. // val: function () {}, -- function - Api method (or undefined if just an object
  6276. // methodExt: [ ... ], -- array - Array of Api object definitions to extend the method result
  6277. // propExt: [ ... ] -- array - Array of Api object definitions to extend the property
  6278. // },
  6279. // {
  6280. // name: 'row'
  6281. // val: {},
  6282. // methodExt: [ ... ],
  6283. // propExt: [
  6284. // {
  6285. // name: 'data'
  6286. // val: function () {},
  6287. // methodExt: [ ... ],
  6288. // propExt: [ ... ]
  6289. // },
  6290. // ...
  6291. // ]
  6292. // }
  6293. // ]
  6294. _Api.register = _api_register = function ( name, val )
  6295. {
  6296. if ( Array.isArray( name ) ) {
  6297. for ( var j=0, jen=name.length ; j<jen ; j++ ) {
  6298. _Api.register( name[j], val );
  6299. }
  6300. return;
  6301. }
  6302. var
  6303. i, ien,
  6304. heir = name.split('.'),
  6305. struct = __apiStruct,
  6306. key, method;
  6307. var find = function ( src, name ) {
  6308. for ( var i=0, ien=src.length ; i<ien ; i++ ) {
  6309. if ( src[i].name === name ) {
  6310. return src[i];
  6311. }
  6312. }
  6313. return null;
  6314. };
  6315. for ( i=0, ien=heir.length ; i<ien ; i++ ) {
  6316. method = heir[i].indexOf('()') !== -1;
  6317. key = method ?
  6318. heir[i].replace('()', '') :
  6319. heir[i];
  6320. var src = find( struct, key );
  6321. if ( ! src ) {
  6322. src = {
  6323. name: key,
  6324. val: {},
  6325. methodExt: [],
  6326. propExt: [],
  6327. type: 'object'
  6328. };
  6329. struct.push( src );
  6330. }
  6331. if ( i === ien-1 ) {
  6332. src.val = val;
  6333. src.type = typeof val === 'function' ?
  6334. 'function' :
  6335. $.isPlainObject( val ) ?
  6336. 'object' :
  6337. 'other';
  6338. }
  6339. else {
  6340. struct = method ?
  6341. src.methodExt :
  6342. src.propExt;
  6343. }
  6344. }
  6345. };
  6346. _Api.registerPlural = _api_registerPlural = function ( pluralName, singularName, val ) {
  6347. _Api.register( pluralName, val );
  6348. _Api.register( singularName, function () {
  6349. var ret = val.apply( this, arguments );
  6350. if ( ret === this ) {
  6351. // Returned item is the API instance that was passed in, return it
  6352. return this;
  6353. }
  6354. else if ( ret instanceof _Api ) {
  6355. // New API instance returned, want the value from the first item
  6356. // in the returned array for the singular result.
  6357. return ret.length ?
  6358. Array.isArray( ret[0] ) ?
  6359. new _Api( ret.context, ret[0] ) : // Array results are 'enhanced'
  6360. ret[0] :
  6361. undefined;
  6362. }
  6363. // Non-API return - just fire it back
  6364. return ret;
  6365. } );
  6366. };
  6367. /**
  6368. * Selector for HTML tables. Apply the given selector to the give array of
  6369. * DataTables settings objects.
  6370. *
  6371. * @param {string|integer} [selector] jQuery selector string or integer
  6372. * @param {array} Array of DataTables settings objects to be filtered
  6373. * @return {array}
  6374. * @ignore
  6375. */
  6376. var __table_selector = function ( selector, a )
  6377. {
  6378. if ( Array.isArray(selector) ) {
  6379. return $.map( selector, function (item) {
  6380. return __table_selector(item, a);
  6381. } );
  6382. }
  6383. // Integer is used to pick out a table by index
  6384. if ( typeof selector === 'number' ) {
  6385. return [ a[ selector ] ];
  6386. }
  6387. // Perform a jQuery selector on the table nodes
  6388. var nodes = $.map( a, function (el, i) {
  6389. return el.nTable;
  6390. } );
  6391. return $(nodes)
  6392. .filter( selector )
  6393. .map( function (i) {
  6394. // Need to translate back from the table node to the settings
  6395. var idx = $.inArray( this, nodes );
  6396. return a[ idx ];
  6397. } )
  6398. .toArray();
  6399. };
  6400. /**
  6401. * Context selector for the API's context (i.e. the tables the API instance
  6402. * refers to.
  6403. *
  6404. * @name DataTable.Api#tables
  6405. * @param {string|integer} [selector] Selector to pick which tables the iterator
  6406. * should operate on. If not given, all tables in the current context are
  6407. * used. This can be given as a jQuery selector (for example `':gt(0)'`) to
  6408. * select multiple tables or as an integer to select a single table.
  6409. * @returns {DataTable.Api} Returns a new API instance if a selector is given.
  6410. */
  6411. _api_register( 'tables()', function ( selector ) {
  6412. // A new instance is created if there was a selector specified
  6413. return selector !== undefined && selector !== null ?
  6414. new _Api( __table_selector( selector, this.context ) ) :
  6415. this;
  6416. } );
  6417. _api_register( 'table()', function ( selector ) {
  6418. var tables = this.tables( selector );
  6419. var ctx = tables.context;
  6420. // Truncate to the first matched table
  6421. return ctx.length ?
  6422. new _Api( ctx[0] ) :
  6423. tables;
  6424. } );
  6425. _api_registerPlural( 'tables().nodes()', 'table().node()' , function () {
  6426. return this.iterator( 'table', function ( ctx ) {
  6427. return ctx.nTable;
  6428. }, 1 );
  6429. } );
  6430. _api_registerPlural( 'tables().body()', 'table().body()' , function () {
  6431. return this.iterator( 'table', function ( ctx ) {
  6432. return ctx.nTBody;
  6433. }, 1 );
  6434. } );
  6435. _api_registerPlural( 'tables().header()', 'table().header()' , function () {
  6436. return this.iterator( 'table', function ( ctx ) {
  6437. return ctx.nTHead;
  6438. }, 1 );
  6439. } );
  6440. _api_registerPlural( 'tables().footer()', 'table().footer()' , function () {
  6441. return this.iterator( 'table', function ( ctx ) {
  6442. return ctx.nTFoot;
  6443. }, 1 );
  6444. } );
  6445. _api_registerPlural( 'tables().containers()', 'table().container()' , function () {
  6446. return this.iterator( 'table', function ( ctx ) {
  6447. return ctx.nTableWrapper;
  6448. }, 1 );
  6449. } );
  6450. /**
  6451. * Redraw the tables in the current context.
  6452. */
  6453. _api_register( 'draw()', function ( paging ) {
  6454. return this.iterator( 'table', function ( settings ) {
  6455. if ( paging === 'page' ) {
  6456. _fnDraw( settings );
  6457. }
  6458. else {
  6459. if ( typeof paging === 'string' ) {
  6460. paging = paging === 'full-hold' ?
  6461. false :
  6462. true;
  6463. }
  6464. _fnReDraw( settings, paging===false );
  6465. }
  6466. } );
  6467. } );
  6468. /**
  6469. * Get the current page index.
  6470. *
  6471. * @return {integer} Current page index (zero based)
  6472. *//**
  6473. * Set the current page.
  6474. *
  6475. * Note that if you attempt to show a page which does not exist, DataTables will
  6476. * not throw an error, but rather reset the paging.
  6477. *
  6478. * @param {integer|string} action The paging action to take. This can be one of:
  6479. * * `integer` - The page index to jump to
  6480. * * `string` - An action to take:
  6481. * * `first` - Jump to first page.
  6482. * * `next` - Jump to the next page
  6483. * * `previous` - Jump to previous page
  6484. * * `last` - Jump to the last page.
  6485. * @returns {DataTables.Api} this
  6486. */
  6487. _api_register( 'page()', function ( action ) {
  6488. if ( action === undefined ) {
  6489. return this.page.info().page; // not an expensive call
  6490. }
  6491. // else, have an action to take on all tables
  6492. return this.iterator( 'table', function ( settings ) {
  6493. _fnPageChange( settings, action );
  6494. } );
  6495. } );
  6496. /**
  6497. * Paging information for the first table in the current context.
  6498. *
  6499. * If you require paging information for another table, use the `table()` method
  6500. * with a suitable selector.
  6501. *
  6502. * @return {object} Object with the following properties set:
  6503. * * `page` - Current page index (zero based - i.e. the first page is `0`)
  6504. * * `pages` - Total number of pages
  6505. * * `start` - Display index for the first record shown on the current page
  6506. * * `end` - Display index for the last record shown on the current page
  6507. * * `length` - Display length (number of records). Note that generally `start
  6508. * + length = end`, but this is not always true, for example if there are
  6509. * only 2 records to show on the final page, with a length of 10.
  6510. * * `recordsTotal` - Full data set length
  6511. * * `recordsDisplay` - Data set length once the current filtering criterion
  6512. * are applied.
  6513. */
  6514. _api_register( 'page.info()', function ( action ) {
  6515. if ( this.context.length === 0 ) {
  6516. return undefined;
  6517. }
  6518. var
  6519. settings = this.context[0],
  6520. start = settings._iDisplayStart,
  6521. len = settings.oFeatures.bPaginate ? settings._iDisplayLength : -1,
  6522. visRecords = settings.fnRecordsDisplay(),
  6523. all = len === -1;
  6524. return {
  6525. "page": all ? 0 : Math.floor( start / len ),
  6526. "pages": all ? 1 : Math.ceil( visRecords / len ),
  6527. "start": start,
  6528. "end": settings.fnDisplayEnd(),
  6529. "length": len,
  6530. "recordsTotal": settings.fnRecordsTotal(),
  6531. "recordsDisplay": visRecords,
  6532. "serverSide": _fnDataSource( settings ) === 'ssp'
  6533. };
  6534. } );
  6535. /**
  6536. * Get the current page length.
  6537. *
  6538. * @return {integer} Current page length. Note `-1` indicates that all records
  6539. * are to be shown.
  6540. *//**
  6541. * Set the current page length.
  6542. *
  6543. * @param {integer} Page length to set. Use `-1` to show all records.
  6544. * @returns {DataTables.Api} this
  6545. */
  6546. _api_register( 'page.len()', function ( len ) {
  6547. // Note that we can't call this function 'length()' because `length`
  6548. // is a Javascript property of functions which defines how many arguments
  6549. // the function expects.
  6550. if ( len === undefined ) {
  6551. return this.context.length !== 0 ?
  6552. this.context[0]._iDisplayLength :
  6553. undefined;
  6554. }
  6555. // else, set the page length
  6556. return this.iterator( 'table', function ( settings ) {
  6557. _fnLengthChange( settings, len );
  6558. } );
  6559. } );
  6560. var __reload = function ( settings, holdPosition, callback ) {
  6561. // Use the draw event to trigger a callback
  6562. if ( callback ) {
  6563. var api = new _Api( settings );
  6564. api.one( 'draw', function () {
  6565. callback( api.ajax.json() );
  6566. } );
  6567. }
  6568. if ( _fnDataSource( settings ) == 'ssp' ) {
  6569. _fnReDraw( settings, holdPosition );
  6570. }
  6571. else {
  6572. _fnProcessingDisplay( settings, true );
  6573. // Cancel an existing request
  6574. var xhr = settings.jqXHR;
  6575. if ( xhr && xhr.readyState !== 4 ) {
  6576. xhr.abort();
  6577. }
  6578. // Trigger xhr
  6579. _fnBuildAjax( settings, [], function( json ) {
  6580. _fnClearTable( settings );
  6581. var data = _fnAjaxDataSrc( settings, json );
  6582. for ( var i=0, ien=data.length ; i<ien ; i++ ) {
  6583. _fnAddData( settings, data[i] );
  6584. }
  6585. _fnReDraw( settings, holdPosition );
  6586. _fnProcessingDisplay( settings, false );
  6587. } );
  6588. }
  6589. };
  6590. /**
  6591. * Get the JSON response from the last Ajax request that DataTables made to the
  6592. * server. Note that this returns the JSON from the first table in the current
  6593. * context.
  6594. *
  6595. * @return {object} JSON received from the server.
  6596. */
  6597. _api_register( 'ajax.json()', function () {
  6598. var ctx = this.context;
  6599. if ( ctx.length > 0 ) {
  6600. return ctx[0].json;
  6601. }
  6602. // else return undefined;
  6603. } );
  6604. /**
  6605. * Get the data submitted in the last Ajax request
  6606. */
  6607. _api_register( 'ajax.params()', function () {
  6608. var ctx = this.context;
  6609. if ( ctx.length > 0 ) {
  6610. return ctx[0].oAjaxData;
  6611. }
  6612. // else return undefined;
  6613. } );
  6614. /**
  6615. * Reload tables from the Ajax data source. Note that this function will
  6616. * automatically re-draw the table when the remote data has been loaded.
  6617. *
  6618. * @param {boolean} [reset=true] Reset (default) or hold the current paging
  6619. * position. A full re-sort and re-filter is performed when this method is
  6620. * called, which is why the pagination reset is the default action.
  6621. * @returns {DataTables.Api} this
  6622. */
  6623. _api_register( 'ajax.reload()', function ( callback, resetPaging ) {
  6624. return this.iterator( 'table', function (settings) {
  6625. __reload( settings, resetPaging===false, callback );
  6626. } );
  6627. } );
  6628. /**
  6629. * Get the current Ajax URL. Note that this returns the URL from the first
  6630. * table in the current context.
  6631. *
  6632. * @return {string} Current Ajax source URL
  6633. *//**
  6634. * Set the Ajax URL. Note that this will set the URL for all tables in the
  6635. * current context.
  6636. *
  6637. * @param {string} url URL to set.
  6638. * @returns {DataTables.Api} this
  6639. */
  6640. _api_register( 'ajax.url()', function ( url ) {
  6641. var ctx = this.context;
  6642. if ( url === undefined ) {
  6643. // get
  6644. if ( ctx.length === 0 ) {
  6645. return undefined;
  6646. }
  6647. ctx = ctx[0];
  6648. return ctx.ajax ?
  6649. $.isPlainObject( ctx.ajax ) ?
  6650. ctx.ajax.url :
  6651. ctx.ajax :
  6652. ctx.sAjaxSource;
  6653. }
  6654. // set
  6655. return this.iterator( 'table', function ( settings ) {
  6656. if ( $.isPlainObject( settings.ajax ) ) {
  6657. settings.ajax.url = url;
  6658. }
  6659. else {
  6660. settings.ajax = url;
  6661. }
  6662. // No need to consider sAjaxSource here since DataTables gives priority
  6663. // to `ajax` over `sAjaxSource`. So setting `ajax` here, renders any
  6664. // value of `sAjaxSource` redundant.
  6665. } );
  6666. } );
  6667. /**
  6668. * Load data from the newly set Ajax URL. Note that this method is only
  6669. * available when `ajax.url()` is used to set a URL. Additionally, this method
  6670. * has the same effect as calling `ajax.reload()` but is provided for
  6671. * convenience when setting a new URL. Like `ajax.reload()` it will
  6672. * automatically redraw the table once the remote data has been loaded.
  6673. *
  6674. * @returns {DataTables.Api} this
  6675. */
  6676. _api_register( 'ajax.url().load()', function ( callback, resetPaging ) {
  6677. // Same as a reload, but makes sense to present it for easy access after a
  6678. // url change
  6679. return this.iterator( 'table', function ( ctx ) {
  6680. __reload( ctx, resetPaging===false, callback );
  6681. } );
  6682. } );
  6683. var _selector_run = function ( type, selector, selectFn, settings, opts )
  6684. {
  6685. var
  6686. out = [], res,
  6687. a, i, ien, j, jen,
  6688. selectorType = typeof selector;
  6689. // Can't just check for isArray here, as an API or jQuery instance might be
  6690. // given with their array like look
  6691. if ( ! selector || selectorType === 'string' || selectorType === 'function' || selector.length === undefined ) {
  6692. selector = [ selector ];
  6693. }
  6694. for ( i=0, ien=selector.length ; i<ien ; i++ ) {
  6695. // Only split on simple strings - complex expressions will be jQuery selectors
  6696. a = selector[i] && selector[i].split && ! selector[i].match(/[\[\(:]/) ?
  6697. selector[i].split(',') :
  6698. [ selector[i] ];
  6699. for ( j=0, jen=a.length ; j<jen ; j++ ) {
  6700. res = selectFn( typeof a[j] === 'string' ? (a[j]).trim() : a[j] );
  6701. if ( res && res.length ) {
  6702. out = out.concat( res );
  6703. }
  6704. }
  6705. }
  6706. // selector extensions
  6707. var ext = _ext.selector[ type ];
  6708. if ( ext.length ) {
  6709. for ( i=0, ien=ext.length ; i<ien ; i++ ) {
  6710. out = ext[i]( settings, opts, out );
  6711. }
  6712. }
  6713. return _unique( out );
  6714. };
  6715. var _selector_opts = function ( opts )
  6716. {
  6717. if ( ! opts ) {
  6718. opts = {};
  6719. }
  6720. // Backwards compatibility for 1.9- which used the terminology filter rather
  6721. // than search
  6722. if ( opts.filter && opts.search === undefined ) {
  6723. opts.search = opts.filter;
  6724. }
  6725. return $.extend( {
  6726. search: 'none',
  6727. order: 'current',
  6728. page: 'all'
  6729. }, opts );
  6730. };
  6731. var _selector_first = function ( inst )
  6732. {
  6733. // Reduce the API instance to the first item found
  6734. for ( var i=0, ien=inst.length ; i<ien ; i++ ) {
  6735. if ( inst[i].length > 0 ) {
  6736. // Assign the first element to the first item in the instance
  6737. // and truncate the instance and context
  6738. inst[0] = inst[i];
  6739. inst[0].length = 1;
  6740. inst.length = 1;
  6741. inst.context = [ inst.context[i] ];
  6742. return inst;
  6743. }
  6744. }
  6745. // Not found - return an empty instance
  6746. inst.length = 0;
  6747. return inst;
  6748. };
  6749. var _selector_row_indexes = function ( settings, opts )
  6750. {
  6751. var
  6752. i, ien, tmp, a=[],
  6753. displayFiltered = settings.aiDisplay,
  6754. displayMaster = settings.aiDisplayMaster;
  6755. var
  6756. search = opts.search, // none, applied, removed
  6757. order = opts.order, // applied, current, index (original - compatibility with 1.9)
  6758. page = opts.page; // all, current
  6759. if ( _fnDataSource( settings ) == 'ssp' ) {
  6760. // In server-side processing mode, most options are irrelevant since
  6761. // rows not shown don't exist and the index order is the applied order
  6762. // Removed is a special case - for consistency just return an empty
  6763. // array
  6764. return search === 'removed' ?
  6765. [] :
  6766. _range( 0, displayMaster.length );
  6767. }
  6768. else if ( page == 'current' ) {
  6769. // Current page implies that order=current and filter=applied, since it is
  6770. // fairly senseless otherwise, regardless of what order and search actually
  6771. // are
  6772. for ( i=settings._iDisplayStart, ien=settings.fnDisplayEnd() ; i<ien ; i++ ) {
  6773. a.push( displayFiltered[i] );
  6774. }
  6775. }
  6776. else if ( order == 'current' || order == 'applied' ) {
  6777. if ( search == 'none') {
  6778. a = displayMaster.slice();
  6779. }
  6780. else if ( search == 'applied' ) {
  6781. a = displayFiltered.slice();
  6782. }
  6783. else if ( search == 'removed' ) {
  6784. // O(n+m) solution by creating a hash map
  6785. var displayFilteredMap = {};
  6786. for ( var i=0, ien=displayFiltered.length ; i<ien ; i++ ) {
  6787. displayFilteredMap[displayFiltered[i]] = null;
  6788. }
  6789. a = $.map( displayMaster, function (el) {
  6790. return ! displayFilteredMap.hasOwnProperty(el) ?
  6791. el :
  6792. null;
  6793. } );
  6794. }
  6795. }
  6796. else if ( order == 'index' || order == 'original' ) {
  6797. for ( i=0, ien=settings.aoData.length ; i<ien ; i++ ) {
  6798. if ( search == 'none' ) {
  6799. a.push( i );
  6800. }
  6801. else { // applied | removed
  6802. tmp = $.inArray( i, displayFiltered );
  6803. if ((tmp === -1 && search == 'removed') ||
  6804. (tmp >= 0 && search == 'applied') )
  6805. {
  6806. a.push( i );
  6807. }
  6808. }
  6809. }
  6810. }
  6811. return a;
  6812. };
  6813. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  6814. * Rows
  6815. *
  6816. * {} - no selector - use all available rows
  6817. * {integer} - row aoData index
  6818. * {node} - TR node
  6819. * {string} - jQuery selector to apply to the TR elements
  6820. * {array} - jQuery array of nodes, or simply an array of TR nodes
  6821. *
  6822. */
  6823. var __row_selector = function ( settings, selector, opts )
  6824. {
  6825. var rows;
  6826. var run = function ( sel ) {
  6827. var selInt = _intVal( sel );
  6828. var i, ien;
  6829. var aoData = settings.aoData;
  6830. // Short cut - selector is a number and no options provided (default is
  6831. // all records, so no need to check if the index is in there, since it
  6832. // must be - dev error if the index doesn't exist).
  6833. if ( selInt !== null && ! opts ) {
  6834. return [ selInt ];
  6835. }
  6836. if ( ! rows ) {
  6837. rows = _selector_row_indexes( settings, opts );
  6838. }
  6839. if ( selInt !== null && $.inArray( selInt, rows ) !== -1 ) {
  6840. // Selector - integer
  6841. return [ selInt ];
  6842. }
  6843. else if ( sel === null || sel === undefined || sel === '' ) {
  6844. // Selector - none
  6845. return rows;
  6846. }
  6847. // Selector - function
  6848. if ( typeof sel === 'function' ) {
  6849. return $.map( rows, function (idx) {
  6850. var row = aoData[ idx ];
  6851. return sel( idx, row._aData, row.nTr ) ? idx : null;
  6852. } );
  6853. }
  6854. // Selector - node
  6855. if ( sel.nodeName ) {
  6856. var rowIdx = sel._DT_RowIndex; // Property added by DT for fast lookup
  6857. var cellIdx = sel._DT_CellIndex;
  6858. if ( rowIdx !== undefined ) {
  6859. // Make sure that the row is actually still present in the table
  6860. return aoData[ rowIdx ] && aoData[ rowIdx ].nTr === sel ?
  6861. [ rowIdx ] :
  6862. [];
  6863. }
  6864. else if ( cellIdx ) {
  6865. return aoData[ cellIdx.row ] && aoData[ cellIdx.row ].nTr === sel.parentNode ?
  6866. [ cellIdx.row ] :
  6867. [];
  6868. }
  6869. else {
  6870. var host = $(sel).closest('*[data-dt-row]');
  6871. return host.length ?
  6872. [ host.data('dt-row') ] :
  6873. [];
  6874. }
  6875. }
  6876. // ID selector. Want to always be able to select rows by id, regardless
  6877. // of if the tr element has been created or not, so can't rely upon
  6878. // jQuery here - hence a custom implementation. This does not match
  6879. // Sizzle's fast selector or HTML4 - in HTML5 the ID can be anything,
  6880. // but to select it using a CSS selector engine (like Sizzle or
  6881. // querySelect) it would need to need to be escaped for some characters.
  6882. // DataTables simplifies this for row selectors since you can select
  6883. // only a row. A # indicates an id any anything that follows is the id -
  6884. // unescaped.
  6885. if ( typeof sel === 'string' && sel.charAt(0) === '#' ) {
  6886. // get row index from id
  6887. var rowObj = settings.aIds[ sel.replace( /^#/, '' ) ];
  6888. if ( rowObj !== undefined ) {
  6889. return [ rowObj.idx ];
  6890. }
  6891. // need to fall through to jQuery in case there is DOM id that
  6892. // matches
  6893. }
  6894. // Get nodes in the order from the `rows` array with null values removed
  6895. var nodes = _removeEmpty(
  6896. _pluck_order( settings.aoData, rows, 'nTr' )
  6897. );
  6898. // Selector - jQuery selector string, array of nodes or jQuery object/
  6899. // As jQuery's .filter() allows jQuery objects to be passed in filter,
  6900. // it also allows arrays, so this will cope with all three options
  6901. return $(nodes)
  6902. .filter( sel )
  6903. .map( function () {
  6904. return this._DT_RowIndex;
  6905. } )
  6906. .toArray();
  6907. };
  6908. return _selector_run( 'row', selector, run, settings, opts );
  6909. };
  6910. _api_register( 'rows()', function ( selector, opts ) {
  6911. // argument shifting
  6912. if ( selector === undefined ) {
  6913. selector = '';
  6914. }
  6915. else if ( $.isPlainObject( selector ) ) {
  6916. opts = selector;
  6917. selector = '';
  6918. }
  6919. opts = _selector_opts( opts );
  6920. var inst = this.iterator( 'table', function ( settings ) {
  6921. return __row_selector( settings, selector, opts );
  6922. }, 1 );
  6923. // Want argument shifting here and in __row_selector?
  6924. inst.selector.rows = selector;
  6925. inst.selector.opts = opts;
  6926. return inst;
  6927. } );
  6928. _api_register( 'rows().nodes()', function () {
  6929. return this.iterator( 'row', function ( settings, row ) {
  6930. return settings.aoData[ row ].nTr || undefined;
  6931. }, 1 );
  6932. } );
  6933. _api_register( 'rows().data()', function () {
  6934. return this.iterator( true, 'rows', function ( settings, rows ) {
  6935. return _pluck_order( settings.aoData, rows, '_aData' );
  6936. }, 1 );
  6937. } );
  6938. _api_registerPlural( 'rows().cache()', 'row().cache()', function ( type ) {
  6939. return this.iterator( 'row', function ( settings, row ) {
  6940. var r = settings.aoData[ row ];
  6941. return type === 'search' ? r._aFilterData : r._aSortData;
  6942. }, 1 );
  6943. } );
  6944. _api_registerPlural( 'rows().invalidate()', 'row().invalidate()', function ( src ) {
  6945. return this.iterator( 'row', function ( settings, row ) {
  6946. _fnInvalidate( settings, row, src );
  6947. } );
  6948. } );
  6949. _api_registerPlural( 'rows().indexes()', 'row().index()', function () {
  6950. return this.iterator( 'row', function ( settings, row ) {
  6951. return row;
  6952. }, 1 );
  6953. } );
  6954. _api_registerPlural( 'rows().ids()', 'row().id()', function ( hash ) {
  6955. var a = [];
  6956. var context = this.context;
  6957. // `iterator` will drop undefined values, but in this case we want them
  6958. for ( var i=0, ien=context.length ; i<ien ; i++ ) {
  6959. for ( var j=0, jen=this[i].length ; j<jen ; j++ ) {
  6960. var id = context[i].rowIdFn( context[i].aoData[ this[i][j] ]._aData );
  6961. a.push( (hash === true ? '#' : '' )+ id );
  6962. }
  6963. }
  6964. return new _Api( context, a );
  6965. } );
  6966. _api_registerPlural( 'rows().remove()', 'row().remove()', function () {
  6967. var that = this;
  6968. this.iterator( 'row', function ( settings, row, thatIdx ) {
  6969. var data = settings.aoData;
  6970. var rowData = data[ row ];
  6971. var i, ien, j, jen;
  6972. var loopRow, loopCells;
  6973. data.splice( row, 1 );
  6974. // Update the cached indexes
  6975. for ( i=0, ien=data.length ; i<ien ; i++ ) {
  6976. loopRow = data[i];
  6977. loopCells = loopRow.anCells;
  6978. // Rows
  6979. if ( loopRow.nTr !== null ) {
  6980. loopRow.nTr._DT_RowIndex = i;
  6981. }
  6982. // Cells
  6983. if ( loopCells !== null ) {
  6984. for ( j=0, jen=loopCells.length ; j<jen ; j++ ) {
  6985. loopCells[j]._DT_CellIndex.row = i;
  6986. }
  6987. }
  6988. }
  6989. // Delete from the display arrays
  6990. _fnDeleteIndex( settings.aiDisplayMaster, row );
  6991. _fnDeleteIndex( settings.aiDisplay, row );
  6992. _fnDeleteIndex( that[ thatIdx ], row, false ); // maintain local indexes
  6993. // For server-side processing tables - subtract the deleted row from the count
  6994. if ( settings._iRecordsDisplay > 0 ) {
  6995. settings._iRecordsDisplay--;
  6996. }
  6997. // Check for an 'overflow' they case for displaying the table
  6998. _fnLengthOverflow( settings );
  6999. // Remove the row's ID reference if there is one
  7000. var id = settings.rowIdFn( rowData._aData );
  7001. if ( id !== undefined ) {
  7002. delete settings.aIds[ id ];
  7003. }
  7004. } );
  7005. this.iterator( 'table', function ( settings ) {
  7006. for ( var i=0, ien=settings.aoData.length ; i<ien ; i++ ) {
  7007. settings.aoData[i].idx = i;
  7008. }
  7009. } );
  7010. return this;
  7011. } );
  7012. _api_register( 'rows.add()', function ( rows ) {
  7013. var newRows = this.iterator( 'table', function ( settings ) {
  7014. var row, i, ien;
  7015. var out = [];
  7016. for ( i=0, ien=rows.length ; i<ien ; i++ ) {
  7017. row = rows[i];
  7018. if ( row.nodeName && row.nodeName.toUpperCase() === 'TR' ) {
  7019. out.push( _fnAddTr( settings, row )[0] );
  7020. }
  7021. else {
  7022. out.push( _fnAddData( settings, row ) );
  7023. }
  7024. }
  7025. return out;
  7026. }, 1 );
  7027. // Return an Api.rows() extended instance, so rows().nodes() etc can be used
  7028. var modRows = this.rows( -1 );
  7029. modRows.pop();
  7030. $.merge( modRows, newRows );
  7031. return modRows;
  7032. } );
  7033. /**
  7034. *
  7035. */
  7036. _api_register( 'row()', function ( selector, opts ) {
  7037. return _selector_first( this.rows( selector, opts ) );
  7038. } );
  7039. _api_register( 'row().data()', function ( data ) {
  7040. var ctx = this.context;
  7041. if ( data === undefined ) {
  7042. // Get
  7043. return ctx.length && this.length ?
  7044. ctx[0].aoData[ this[0] ]._aData :
  7045. undefined;
  7046. }
  7047. // Set
  7048. var row = ctx[0].aoData[ this[0] ];
  7049. row._aData = data;
  7050. // If the DOM has an id, and the data source is an array
  7051. if ( Array.isArray( data ) && row.nTr && row.nTr.id ) {
  7052. _fnSetObjectDataFn( ctx[0].rowId )( data, row.nTr.id );
  7053. }
  7054. // Automatically invalidate
  7055. _fnInvalidate( ctx[0], this[0], 'data' );
  7056. return this;
  7057. } );
  7058. _api_register( 'row().node()', function () {
  7059. var ctx = this.context;
  7060. return ctx.length && this.length ?
  7061. ctx[0].aoData[ this[0] ].nTr || null :
  7062. null;
  7063. } );
  7064. _api_register( 'row.add()', function ( row ) {
  7065. // Allow a jQuery object to be passed in - only a single row is added from
  7066. // it though - the first element in the set
  7067. if ( row instanceof $ && row.length ) {
  7068. row = row[0];
  7069. }
  7070. var rows = this.iterator( 'table', function ( settings ) {
  7071. if ( row.nodeName && row.nodeName.toUpperCase() === 'TR' ) {
  7072. return _fnAddTr( settings, row )[0];
  7073. }
  7074. return _fnAddData( settings, row );
  7075. } );
  7076. // Return an Api.rows() extended instance, with the newly added row selected
  7077. return this.row( rows[0] );
  7078. } );
  7079. $(document).on('plugin-init.dt', function (e, context) {
  7080. var api = new _Api( context );
  7081. var namespace = 'on-plugin-init';
  7082. var stateSaveParamsEvent = 'stateSaveParams.' + namespace;
  7083. var destroyEvent = 'destroy. ' + namespace;
  7084. api.on( stateSaveParamsEvent, function ( e, settings, d ) {
  7085. // This could be more compact with the API, but it is a lot faster as a simple
  7086. // internal loop
  7087. var idFn = settings.rowIdFn;
  7088. var data = settings.aoData;
  7089. var ids = [];
  7090. for (var i=0 ; i<data.length ; i++) {
  7091. if (data[i]._detailsShow) {
  7092. ids.push( '#' + idFn(data[i]._aData) );
  7093. }
  7094. }
  7095. d.childRows = ids;
  7096. });
  7097. api.on( destroyEvent, function () {
  7098. api.off(stateSaveParamsEvent + ' ' + destroyEvent);
  7099. });
  7100. var loaded = api.state.loaded();
  7101. if ( loaded && loaded.childRows ) {
  7102. api
  7103. .rows( $.map(loaded.childRows, function (id){
  7104. return id.replace(/:/g, '\\:')
  7105. }) )
  7106. .every( function () {
  7107. _fnCallbackFire( context, null, 'requestChild', [ this ] )
  7108. });
  7109. }
  7110. });
  7111. var __details_add = function ( ctx, row, data, klass )
  7112. {
  7113. // Convert to array of TR elements
  7114. var rows = [];
  7115. var addRow = function ( r, k ) {
  7116. // Recursion to allow for arrays of jQuery objects
  7117. if ( Array.isArray( r ) || r instanceof $ ) {
  7118. for ( var i=0, ien=r.length ; i<ien ; i++ ) {
  7119. addRow( r[i], k );
  7120. }
  7121. return;
  7122. }
  7123. // If we get a TR element, then just add it directly - up to the dev
  7124. // to add the correct number of columns etc
  7125. if ( r.nodeName && r.nodeName.toLowerCase() === 'tr' ) {
  7126. rows.push( r );
  7127. }
  7128. else {
  7129. // Otherwise create a row with a wrapper
  7130. var created = $('<tr><td></td></tr>').addClass( k );
  7131. $('td', created)
  7132. .addClass( k )
  7133. .html( r )
  7134. [0].colSpan = _fnVisbleColumns( ctx );
  7135. rows.push( created[0] );
  7136. }
  7137. };
  7138. addRow( data, klass );
  7139. if ( row._details ) {
  7140. row._details.detach();
  7141. }
  7142. row._details = $(rows);
  7143. // If the children were already shown, that state should be retained
  7144. if ( row._detailsShow ) {
  7145. row._details.insertAfter( row.nTr );
  7146. }
  7147. };
  7148. // Make state saving of child row details async to allow them to be batch processed
  7149. var __details_state = DataTable.util.throttle(
  7150. function (ctx) {
  7151. _fnSaveState( ctx[0] )
  7152. },
  7153. 500
  7154. );
  7155. var __details_remove = function ( api, idx )
  7156. {
  7157. var ctx = api.context;
  7158. if ( ctx.length ) {
  7159. var row = ctx[0].aoData[ idx !== undefined ? idx : api[0] ];
  7160. if ( row && row._details ) {
  7161. row._details.remove();
  7162. row._detailsShow = undefined;
  7163. row._details = undefined;
  7164. $( row.nTr ).removeClass( 'dt-hasChild' );
  7165. __details_state( ctx );
  7166. }
  7167. }
  7168. };
  7169. var __details_display = function ( api, show ) {
  7170. var ctx = api.context;
  7171. if ( ctx.length && api.length ) {
  7172. var row = ctx[0].aoData[ api[0] ];
  7173. if ( row._details ) {
  7174. row._detailsShow = show;
  7175. if ( show ) {
  7176. row._details.insertAfter( row.nTr );
  7177. $( row.nTr ).addClass( 'dt-hasChild' );
  7178. }
  7179. else {
  7180. row._details.detach();
  7181. $( row.nTr ).removeClass( 'dt-hasChild' );
  7182. }
  7183. _fnCallbackFire( ctx[0], null, 'childRow', [ show, api.row( api[0] ) ] )
  7184. __details_events( ctx[0] );
  7185. __details_state( ctx );
  7186. }
  7187. }
  7188. };
  7189. var __details_events = function ( settings )
  7190. {
  7191. var api = new _Api( settings );
  7192. var namespace = '.dt.DT_details';
  7193. var drawEvent = 'draw'+namespace;
  7194. var colvisEvent = 'column-sizing'+namespace;
  7195. var destroyEvent = 'destroy'+namespace;
  7196. var data = settings.aoData;
  7197. api.off( drawEvent +' '+ colvisEvent +' '+ destroyEvent );
  7198. if ( _pluck( data, '_details' ).length > 0 ) {
  7199. // On each draw, insert the required elements into the document
  7200. api.on( drawEvent, function ( e, ctx ) {
  7201. if ( settings !== ctx ) {
  7202. return;
  7203. }
  7204. api.rows( {page:'current'} ).eq(0).each( function (idx) {
  7205. // Internal data grab
  7206. var row = data[ idx ];
  7207. if ( row._detailsShow ) {
  7208. row._details.insertAfter( row.nTr );
  7209. }
  7210. } );
  7211. } );
  7212. // Column visibility change - update the colspan
  7213. api.on( colvisEvent, function ( e, ctx, idx, vis ) {
  7214. if ( settings !== ctx ) {
  7215. return;
  7216. }
  7217. // Update the colspan for the details rows (note, only if it already has
  7218. // a colspan)
  7219. var row, visible = _fnVisbleColumns( ctx );
  7220. for ( var i=0, ien=data.length ; i<ien ; i++ ) {
  7221. row = data[i];
  7222. if ( row._details ) {
  7223. row._details.children('td[colspan]').attr('colspan', visible );
  7224. }
  7225. }
  7226. } );
  7227. // Table destroyed - nuke any child rows
  7228. api.on( destroyEvent, function ( e, ctx ) {
  7229. if ( settings !== ctx ) {
  7230. return;
  7231. }
  7232. for ( var i=0, ien=data.length ; i<ien ; i++ ) {
  7233. if ( data[i]._details ) {
  7234. __details_remove( api, i );
  7235. }
  7236. }
  7237. } );
  7238. }
  7239. };
  7240. // Strings for the method names to help minification
  7241. var _emp = '';
  7242. var _child_obj = _emp+'row().child';
  7243. var _child_mth = _child_obj+'()';
  7244. // data can be:
  7245. // tr
  7246. // string
  7247. // jQuery or array of any of the above
  7248. _api_register( _child_mth, function ( data, klass ) {
  7249. var ctx = this.context;
  7250. if ( data === undefined ) {
  7251. // get
  7252. return ctx.length && this.length ?
  7253. ctx[0].aoData[ this[0] ]._details :
  7254. undefined;
  7255. }
  7256. else if ( data === true ) {
  7257. // show
  7258. this.child.show();
  7259. }
  7260. else if ( data === false ) {
  7261. // remove
  7262. __details_remove( this );
  7263. }
  7264. else if ( ctx.length && this.length ) {
  7265. // set
  7266. __details_add( ctx[0], ctx[0].aoData[ this[0] ], data, klass );
  7267. }
  7268. return this;
  7269. } );
  7270. _api_register( [
  7271. _child_obj+'.show()',
  7272. _child_mth+'.show()' // only when `child()` was called with parameters (without
  7273. ], function ( show ) { // it returns an object and this method is not executed)
  7274. __details_display( this, true );
  7275. return this;
  7276. } );
  7277. _api_register( [
  7278. _child_obj+'.hide()',
  7279. _child_mth+'.hide()' // only when `child()` was called with parameters (without
  7280. ], function () { // it returns an object and this method is not executed)
  7281. __details_display( this, false );
  7282. return this;
  7283. } );
  7284. _api_register( [
  7285. _child_obj+'.remove()',
  7286. _child_mth+'.remove()' // only when `child()` was called with parameters (without
  7287. ], function () { // it returns an object and this method is not executed)
  7288. __details_remove( this );
  7289. return this;
  7290. } );
  7291. _api_register( _child_obj+'.isShown()', function () {
  7292. var ctx = this.context;
  7293. if ( ctx.length && this.length ) {
  7294. // _detailsShown as false or undefined will fall through to return false
  7295. return ctx[0].aoData[ this[0] ]._detailsShow || false;
  7296. }
  7297. return false;
  7298. } );
  7299. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  7300. * Columns
  7301. *
  7302. * {integer} - column index (>=0 count from left, <0 count from right)
  7303. * "{integer}:visIdx" - visible column index (i.e. translate to column index) (>=0 count from left, <0 count from right)
  7304. * "{integer}:visible" - alias for {integer}:visIdx (>=0 count from left, <0 count from right)
  7305. * "{string}:name" - column name
  7306. * "{string}" - jQuery selector on column header nodes
  7307. *
  7308. */
  7309. // can be an array of these items, comma separated list, or an array of comma
  7310. // separated lists
  7311. var __re_column_selector = /^([^:]+):(name|visIdx|visible)$/;
  7312. // r1 and r2 are redundant - but it means that the parameters match for the
  7313. // iterator callback in columns().data()
  7314. var __columnData = function ( settings, column, r1, r2, rows ) {
  7315. var a = [];
  7316. for ( var row=0, ien=rows.length ; row<ien ; row++ ) {
  7317. a.push( _fnGetCellData( settings, rows[row], column ) );
  7318. }
  7319. return a;
  7320. };
  7321. var __column_selector = function ( settings, selector, opts )
  7322. {
  7323. var
  7324. columns = settings.aoColumns,
  7325. names = _pluck( columns, 'sName' ),
  7326. nodes = _pluck( columns, 'nTh' );
  7327. var run = function ( s ) {
  7328. var selInt = _intVal( s );
  7329. // Selector - all
  7330. if ( s === '' ) {
  7331. return _range( columns.length );
  7332. }
  7333. // Selector - index
  7334. if ( selInt !== null ) {
  7335. return [ selInt >= 0 ?
  7336. selInt : // Count from left
  7337. columns.length + selInt // Count from right (+ because its a negative value)
  7338. ];
  7339. }
  7340. // Selector = function
  7341. if ( typeof s === 'function' ) {
  7342. var rows = _selector_row_indexes( settings, opts );
  7343. return $.map( columns, function (col, idx) {
  7344. return s(
  7345. idx,
  7346. __columnData( settings, idx, 0, 0, rows ),
  7347. nodes[ idx ]
  7348. ) ? idx : null;
  7349. } );
  7350. }
  7351. // jQuery or string selector
  7352. var match = typeof s === 'string' ?
  7353. s.match( __re_column_selector ) :
  7354. '';
  7355. if ( match ) {
  7356. switch( match[2] ) {
  7357. case 'visIdx':
  7358. case 'visible':
  7359. var idx = parseInt( match[1], 10 );
  7360. // Visible index given, convert to column index
  7361. if ( idx < 0 ) {
  7362. // Counting from the right
  7363. var visColumns = $.map( columns, function (col,i) {
  7364. return col.bVisible ? i : null;
  7365. } );
  7366. return [ visColumns[ visColumns.length + idx ] ];
  7367. }
  7368. // Counting from the left
  7369. return [ _fnVisibleToColumnIndex( settings, idx ) ];
  7370. case 'name':
  7371. // match by name. `names` is column index complete and in order
  7372. return $.map( names, function (name, i) {
  7373. return name === match[1] ? i : null;
  7374. } );
  7375. default:
  7376. return [];
  7377. }
  7378. }
  7379. // Cell in the table body
  7380. if ( s.nodeName && s._DT_CellIndex ) {
  7381. return [ s._DT_CellIndex.column ];
  7382. }
  7383. // jQuery selector on the TH elements for the columns
  7384. var jqResult = $( nodes )
  7385. .filter( s )
  7386. .map( function () {
  7387. return $.inArray( this, nodes ); // `nodes` is column index complete and in order
  7388. } )
  7389. .toArray();
  7390. if ( jqResult.length || ! s.nodeName ) {
  7391. return jqResult;
  7392. }
  7393. // Otherwise a node which might have a `dt-column` data attribute, or be
  7394. // a child or such an element
  7395. var host = $(s).closest('*[data-dt-column]');
  7396. return host.length ?
  7397. [ host.data('dt-column') ] :
  7398. [];
  7399. };
  7400. return _selector_run( 'column', selector, run, settings, opts );
  7401. };
  7402. var __setColumnVis = function ( settings, column, vis ) {
  7403. var
  7404. cols = settings.aoColumns,
  7405. col = cols[ column ],
  7406. data = settings.aoData,
  7407. row, cells, i, ien, tr;
  7408. // Get
  7409. if ( vis === undefined ) {
  7410. return col.bVisible;
  7411. }
  7412. // Set
  7413. // No change
  7414. if ( col.bVisible === vis ) {
  7415. return;
  7416. }
  7417. if ( vis ) {
  7418. // Insert column
  7419. // Need to decide if we should use appendChild or insertBefore
  7420. var insertBefore = $.inArray( true, _pluck(cols, 'bVisible'), column+1 );
  7421. for ( i=0, ien=data.length ; i<ien ; i++ ) {
  7422. tr = data[i].nTr;
  7423. cells = data[i].anCells;
  7424. if ( tr ) {
  7425. // insertBefore can act like appendChild if 2nd arg is null
  7426. tr.insertBefore( cells[ column ], cells[ insertBefore ] || null );
  7427. }
  7428. }
  7429. }
  7430. else {
  7431. // Remove column
  7432. $( _pluck( settings.aoData, 'anCells', column ) ).detach();
  7433. }
  7434. // Common actions
  7435. col.bVisible = vis;
  7436. };
  7437. _api_register( 'columns()', function ( selector, opts ) {
  7438. // argument shifting
  7439. if ( selector === undefined ) {
  7440. selector = '';
  7441. }
  7442. else if ( $.isPlainObject( selector ) ) {
  7443. opts = selector;
  7444. selector = '';
  7445. }
  7446. opts = _selector_opts( opts );
  7447. var inst = this.iterator( 'table', function ( settings ) {
  7448. return __column_selector( settings, selector, opts );
  7449. }, 1 );
  7450. // Want argument shifting here and in _row_selector?
  7451. inst.selector.cols = selector;
  7452. inst.selector.opts = opts;
  7453. return inst;
  7454. } );
  7455. _api_registerPlural( 'columns().header()', 'column().header()', function ( selector, opts ) {
  7456. return this.iterator( 'column', function ( settings, column ) {
  7457. return settings.aoColumns[column].nTh;
  7458. }, 1 );
  7459. } );
  7460. _api_registerPlural( 'columns().footer()', 'column().footer()', function ( selector, opts ) {
  7461. return this.iterator( 'column', function ( settings, column ) {
  7462. return settings.aoColumns[column].nTf;
  7463. }, 1 );
  7464. } );
  7465. _api_registerPlural( 'columns().data()', 'column().data()', function () {
  7466. return this.iterator( 'column-rows', __columnData, 1 );
  7467. } );
  7468. _api_registerPlural( 'columns().dataSrc()', 'column().dataSrc()', function () {
  7469. return this.iterator( 'column', function ( settings, column ) {
  7470. return settings.aoColumns[column].mData;
  7471. }, 1 );
  7472. } );
  7473. _api_registerPlural( 'columns().cache()', 'column().cache()', function ( type ) {
  7474. return this.iterator( 'column-rows', function ( settings, column, i, j, rows ) {
  7475. return _pluck_order( settings.aoData, rows,
  7476. type === 'search' ? '_aFilterData' : '_aSortData', column
  7477. );
  7478. }, 1 );
  7479. } );
  7480. _api_registerPlural( 'columns().nodes()', 'column().nodes()', function () {
  7481. return this.iterator( 'column-rows', function ( settings, column, i, j, rows ) {
  7482. return _pluck_order( settings.aoData, rows, 'anCells', column ) ;
  7483. }, 1 );
  7484. } );
  7485. _api_registerPlural( 'columns().visible()', 'column().visible()', function ( vis, calc ) {
  7486. var that = this;
  7487. var ret = this.iterator( 'column', function ( settings, column ) {
  7488. if ( vis === undefined ) {
  7489. return settings.aoColumns[ column ].bVisible;
  7490. } // else
  7491. __setColumnVis( settings, column, vis );
  7492. } );
  7493. // Group the column visibility changes
  7494. if ( vis !== undefined ) {
  7495. this.iterator( 'table', function ( settings ) {
  7496. // Redraw the header after changes
  7497. _fnDrawHead( settings, settings.aoHeader );
  7498. _fnDrawHead( settings, settings.aoFooter );
  7499. // Update colspan for no records display. Child rows and extensions will use their own
  7500. // listeners to do this - only need to update the empty table item here
  7501. if ( ! settings.aiDisplay.length ) {
  7502. $(settings.nTBody).find('td[colspan]').attr('colspan', _fnVisbleColumns(settings));
  7503. }
  7504. _fnSaveState( settings );
  7505. // Second loop once the first is done for events
  7506. that.iterator( 'column', function ( settings, column ) {
  7507. _fnCallbackFire( settings, null, 'column-visibility', [settings, column, vis, calc] );
  7508. } );
  7509. if ( calc === undefined || calc ) {
  7510. that.columns.adjust();
  7511. }
  7512. });
  7513. }
  7514. return ret;
  7515. } );
  7516. _api_registerPlural( 'columns().indexes()', 'column().index()', function ( type ) {
  7517. return this.iterator( 'column', function ( settings, column ) {
  7518. return type === 'visible' ?
  7519. _fnColumnIndexToVisible( settings, column ) :
  7520. column;
  7521. }, 1 );
  7522. } );
  7523. _api_register( 'columns.adjust()', function () {
  7524. return this.iterator( 'table', function ( settings ) {
  7525. _fnAdjustColumnSizing( settings );
  7526. }, 1 );
  7527. } );
  7528. _api_register( 'column.index()', function ( type, idx ) {
  7529. if ( this.context.length !== 0 ) {
  7530. var ctx = this.context[0];
  7531. if ( type === 'fromVisible' || type === 'toData' ) {
  7532. return _fnVisibleToColumnIndex( ctx, idx );
  7533. }
  7534. else if ( type === 'fromData' || type === 'toVisible' ) {
  7535. return _fnColumnIndexToVisible( ctx, idx );
  7536. }
  7537. }
  7538. } );
  7539. _api_register( 'column()', function ( selector, opts ) {
  7540. return _selector_first( this.columns( selector, opts ) );
  7541. } );
  7542. var __cell_selector = function ( settings, selector, opts )
  7543. {
  7544. var data = settings.aoData;
  7545. var rows = _selector_row_indexes( settings, opts );
  7546. var cells = _removeEmpty( _pluck_order( data, rows, 'anCells' ) );
  7547. var allCells = $(_flatten( [], cells ));
  7548. var row;
  7549. var columns = settings.aoColumns.length;
  7550. var a, i, ien, j, o, host;
  7551. var run = function ( s ) {
  7552. var fnSelector = typeof s === 'function';
  7553. if ( s === null || s === undefined || fnSelector ) {
  7554. // All cells and function selectors
  7555. a = [];
  7556. for ( i=0, ien=rows.length ; i<ien ; i++ ) {
  7557. row = rows[i];
  7558. for ( j=0 ; j<columns ; j++ ) {
  7559. o = {
  7560. row: row,
  7561. column: j
  7562. };
  7563. if ( fnSelector ) {
  7564. // Selector - function
  7565. host = data[ row ];
  7566. if ( s( o, _fnGetCellData(settings, row, j), host.anCells ? host.anCells[j] : null ) ) {
  7567. a.push( o );
  7568. }
  7569. }
  7570. else {
  7571. // Selector - all
  7572. a.push( o );
  7573. }
  7574. }
  7575. }
  7576. return a;
  7577. }
  7578. // Selector - index
  7579. if ( $.isPlainObject( s ) ) {
  7580. // Valid cell index and its in the array of selectable rows
  7581. return s.column !== undefined && s.row !== undefined && $.inArray( s.row, rows ) !== -1 ?
  7582. [s] :
  7583. [];
  7584. }
  7585. // Selector - jQuery filtered cells
  7586. var jqResult = allCells
  7587. .filter( s )
  7588. .map( function (i, el) {
  7589. return { // use a new object, in case someone changes the values
  7590. row: el._DT_CellIndex.row,
  7591. column: el._DT_CellIndex.column
  7592. };
  7593. } )
  7594. .toArray();
  7595. if ( jqResult.length || ! s.nodeName ) {
  7596. return jqResult;
  7597. }
  7598. // Otherwise the selector is a node, and there is one last option - the
  7599. // element might be a child of an element which has dt-row and dt-column
  7600. // data attributes
  7601. host = $(s).closest('*[data-dt-row]');
  7602. return host.length ?
  7603. [ {
  7604. row: host.data('dt-row'),
  7605. column: host.data('dt-column')
  7606. } ] :
  7607. [];
  7608. };
  7609. return _selector_run( 'cell', selector, run, settings, opts );
  7610. };
  7611. _api_register( 'cells()', function ( rowSelector, columnSelector, opts ) {
  7612. // Argument shifting
  7613. if ( $.isPlainObject( rowSelector ) ) {
  7614. // Indexes
  7615. if ( rowSelector.row === undefined ) {
  7616. // Selector options in first parameter
  7617. opts = rowSelector;
  7618. rowSelector = null;
  7619. }
  7620. else {
  7621. // Cell index objects in first parameter
  7622. opts = columnSelector;
  7623. columnSelector = null;
  7624. }
  7625. }
  7626. if ( $.isPlainObject( columnSelector ) ) {
  7627. opts = columnSelector;
  7628. columnSelector = null;
  7629. }
  7630. // Cell selector
  7631. if ( columnSelector === null || columnSelector === undefined ) {
  7632. return this.iterator( 'table', function ( settings ) {
  7633. return __cell_selector( settings, rowSelector, _selector_opts( opts ) );
  7634. } );
  7635. }
  7636. // The default built in options need to apply to row and columns
  7637. var internalOpts = opts ? {
  7638. page: opts.page,
  7639. order: opts.order,
  7640. search: opts.search
  7641. } : {};
  7642. // Row + column selector
  7643. var columns = this.columns( columnSelector, internalOpts );
  7644. var rows = this.rows( rowSelector, internalOpts );
  7645. var i, ien, j, jen;
  7646. var cellsNoOpts = this.iterator( 'table', function ( settings, idx ) {
  7647. var a = [];
  7648. for ( i=0, ien=rows[idx].length ; i<ien ; i++ ) {
  7649. for ( j=0, jen=columns[idx].length ; j<jen ; j++ ) {
  7650. a.push( {
  7651. row: rows[idx][i],
  7652. column: columns[idx][j]
  7653. } );
  7654. }
  7655. }
  7656. return a;
  7657. }, 1 );
  7658. // There is currently only one extension which uses a cell selector extension
  7659. // It is a _major_ performance drag to run this if it isn't needed, so this is
  7660. // an extension specific check at the moment
  7661. var cells = opts && opts.selected ?
  7662. this.cells( cellsNoOpts, opts ) :
  7663. cellsNoOpts;
  7664. $.extend( cells.selector, {
  7665. cols: columnSelector,
  7666. rows: rowSelector,
  7667. opts: opts
  7668. } );
  7669. return cells;
  7670. } );
  7671. _api_registerPlural( 'cells().nodes()', 'cell().node()', function () {
  7672. return this.iterator( 'cell', function ( settings, row, column ) {
  7673. var data = settings.aoData[ row ];
  7674. return data && data.anCells ?
  7675. data.anCells[ column ] :
  7676. undefined;
  7677. }, 1 );
  7678. } );
  7679. _api_register( 'cells().data()', function () {
  7680. return this.iterator( 'cell', function ( settings, row, column ) {
  7681. return _fnGetCellData( settings, row, column );
  7682. }, 1 );
  7683. } );
  7684. _api_registerPlural( 'cells().cache()', 'cell().cache()', function ( type ) {
  7685. type = type === 'search' ? '_aFilterData' : '_aSortData';
  7686. return this.iterator( 'cell', function ( settings, row, column ) {
  7687. return settings.aoData[ row ][ type ][ column ];
  7688. }, 1 );
  7689. } );
  7690. _api_registerPlural( 'cells().render()', 'cell().render()', function ( type ) {
  7691. return this.iterator( 'cell', function ( settings, row, column ) {
  7692. return _fnGetCellData( settings, row, column, type );
  7693. }, 1 );
  7694. } );
  7695. _api_registerPlural( 'cells().indexes()', 'cell().index()', function () {
  7696. return this.iterator( 'cell', function ( settings, row, column ) {
  7697. return {
  7698. row: row,
  7699. column: column,
  7700. columnVisible: _fnColumnIndexToVisible( settings, column )
  7701. };
  7702. }, 1 );
  7703. } );
  7704. _api_registerPlural( 'cells().invalidate()', 'cell().invalidate()', function ( src ) {
  7705. return this.iterator( 'cell', function ( settings, row, column ) {
  7706. _fnInvalidate( settings, row, src, column );
  7707. } );
  7708. } );
  7709. _api_register( 'cell()', function ( rowSelector, columnSelector, opts ) {
  7710. return _selector_first( this.cells( rowSelector, columnSelector, opts ) );
  7711. } );
  7712. _api_register( 'cell().data()', function ( data ) {
  7713. var ctx = this.context;
  7714. var cell = this[0];
  7715. if ( data === undefined ) {
  7716. // Get
  7717. return ctx.length && cell.length ?
  7718. _fnGetCellData( ctx[0], cell[0].row, cell[0].column ) :
  7719. undefined;
  7720. }
  7721. // Set
  7722. _fnSetCellData( ctx[0], cell[0].row, cell[0].column, data );
  7723. _fnInvalidate( ctx[0], cell[0].row, 'data', cell[0].column );
  7724. return this;
  7725. } );
  7726. /**
  7727. * Get current ordering (sorting) that has been applied to the table.
  7728. *
  7729. * @returns {array} 2D array containing the sorting information for the first
  7730. * table in the current context. Each element in the parent array represents
  7731. * a column being sorted upon (i.e. multi-sorting with two columns would have
  7732. * 2 inner arrays). The inner arrays may have 2 or 3 elements. The first is
  7733. * the column index that the sorting condition applies to, the second is the
  7734. * direction of the sort (`desc` or `asc`) and, optionally, the third is the
  7735. * index of the sorting order from the `column.sorting` initialisation array.
  7736. *//**
  7737. * Set the ordering for the table.
  7738. *
  7739. * @param {integer} order Column index to sort upon.
  7740. * @param {string} direction Direction of the sort to be applied (`asc` or `desc`)
  7741. * @returns {DataTables.Api} this
  7742. *//**
  7743. * Set the ordering for the table.
  7744. *
  7745. * @param {array} order 1D array of sorting information to be applied.
  7746. * @param {array} [...] Optional additional sorting conditions
  7747. * @returns {DataTables.Api} this
  7748. *//**
  7749. * Set the ordering for the table.
  7750. *
  7751. * @param {array} order 2D array of sorting information to be applied.
  7752. * @returns {DataTables.Api} this
  7753. */
  7754. _api_register( 'order()', function ( order, dir ) {
  7755. var ctx = this.context;
  7756. if ( order === undefined ) {
  7757. // get
  7758. return ctx.length !== 0 ?
  7759. ctx[0].aaSorting :
  7760. undefined;
  7761. }
  7762. // set
  7763. if ( typeof order === 'number' ) {
  7764. // Simple column / direction passed in
  7765. order = [ [ order, dir ] ];
  7766. }
  7767. else if ( order.length && ! Array.isArray( order[0] ) ) {
  7768. // Arguments passed in (list of 1D arrays)
  7769. order = Array.prototype.slice.call( arguments );
  7770. }
  7771. // otherwise a 2D array was passed in
  7772. return this.iterator( 'table', function ( settings ) {
  7773. settings.aaSorting = order.slice();
  7774. } );
  7775. } );
  7776. /**
  7777. * Attach a sort listener to an element for a given column
  7778. *
  7779. * @param {node|jQuery|string} node Identifier for the element(s) to attach the
  7780. * listener to. This can take the form of a single DOM node, a jQuery
  7781. * collection of nodes or a jQuery selector which will identify the node(s).
  7782. * @param {integer} column the column that a click on this node will sort on
  7783. * @param {function} [callback] callback function when sort is run
  7784. * @returns {DataTables.Api} this
  7785. */
  7786. _api_register( 'order.listener()', function ( node, column, callback ) {
  7787. return this.iterator( 'table', function ( settings ) {
  7788. _fnSortAttachListener( settings, node, column, callback );
  7789. } );
  7790. } );
  7791. _api_register( 'order.fixed()', function ( set ) {
  7792. if ( ! set ) {
  7793. var ctx = this.context;
  7794. var fixed = ctx.length ?
  7795. ctx[0].aaSortingFixed :
  7796. undefined;
  7797. return Array.isArray( fixed ) ?
  7798. { pre: fixed } :
  7799. fixed;
  7800. }
  7801. return this.iterator( 'table', function ( settings ) {
  7802. settings.aaSortingFixed = $.extend( true, {}, set );
  7803. } );
  7804. } );
  7805. // Order by the selected column(s)
  7806. _api_register( [
  7807. 'columns().order()',
  7808. 'column().order()'
  7809. ], function ( dir ) {
  7810. var that = this;
  7811. return this.iterator( 'table', function ( settings, i ) {
  7812. var sort = [];
  7813. $.each( that[i], function (j, col) {
  7814. sort.push( [ col, dir ] );
  7815. } );
  7816. settings.aaSorting = sort;
  7817. } );
  7818. } );
  7819. _api_register( 'search()', function ( input, regex, smart, caseInsen ) {
  7820. var ctx = this.context;
  7821. if ( input === undefined ) {
  7822. // get
  7823. return ctx.length !== 0 ?
  7824. ctx[0].oPreviousSearch.sSearch :
  7825. undefined;
  7826. }
  7827. // set
  7828. return this.iterator( 'table', function ( settings ) {
  7829. if ( ! settings.oFeatures.bFilter ) {
  7830. return;
  7831. }
  7832. _fnFilterComplete( settings, $.extend( {}, settings.oPreviousSearch, {
  7833. "sSearch": input+"",
  7834. "bRegex": regex === null ? false : regex,
  7835. "bSmart": smart === null ? true : smart,
  7836. "bCaseInsensitive": caseInsen === null ? true : caseInsen
  7837. } ), 1 );
  7838. } );
  7839. } );
  7840. _api_registerPlural(
  7841. 'columns().search()',
  7842. 'column().search()',
  7843. function ( input, regex, smart, caseInsen ) {
  7844. return this.iterator( 'column', function ( settings, column ) {
  7845. var preSearch = settings.aoPreSearchCols;
  7846. if ( input === undefined ) {
  7847. // get
  7848. return preSearch[ column ].sSearch;
  7849. }
  7850. // set
  7851. if ( ! settings.oFeatures.bFilter ) {
  7852. return;
  7853. }
  7854. $.extend( preSearch[ column ], {
  7855. "sSearch": input+"",
  7856. "bRegex": regex === null ? false : regex,
  7857. "bSmart": smart === null ? true : smart,
  7858. "bCaseInsensitive": caseInsen === null ? true : caseInsen
  7859. } );
  7860. _fnFilterComplete( settings, settings.oPreviousSearch, 1 );
  7861. } );
  7862. }
  7863. );
  7864. /*
  7865. * State API methods
  7866. */
  7867. _api_register( 'state()', function () {
  7868. return this.context.length ?
  7869. this.context[0].oSavedState :
  7870. null;
  7871. } );
  7872. _api_register( 'state.clear()', function () {
  7873. return this.iterator( 'table', function ( settings ) {
  7874. // Save an empty object
  7875. settings.fnStateSaveCallback.call( settings.oInstance, settings, {} );
  7876. } );
  7877. } );
  7878. _api_register( 'state.loaded()', function () {
  7879. return this.context.length ?
  7880. this.context[0].oLoadedState :
  7881. null;
  7882. } );
  7883. _api_register( 'state.save()', function () {
  7884. return this.iterator( 'table', function ( settings ) {
  7885. _fnSaveState( settings );
  7886. } );
  7887. } );
  7888. /**
  7889. * Set the jQuery or window object to be used by DataTables
  7890. *
  7891. * @param {*} module Library / container object
  7892. * @param {string} [type] Library or container type `lib`, `win` or `datetime`.
  7893. * If not provided, automatic detection is attempted.
  7894. */
  7895. DataTable.use = function (module, type) {
  7896. if (type === 'lib' || module.fn) {
  7897. $ = module;
  7898. }
  7899. else if (type == 'win' || module.document) {
  7900. window = module;
  7901. document = module.document;
  7902. }
  7903. else if (type === 'datetime' || module.type === 'DateTime') {
  7904. DataTable.DateTime = module;
  7905. }
  7906. }
  7907. /**
  7908. * CommonJS factory function pass through. This will check if the arguments
  7909. * given are a window object or a jQuery object. If so they are set
  7910. * accordingly.
  7911. * @param {*} root Window
  7912. * @param {*} jq jQUery
  7913. * @returns {boolean} Indicator
  7914. */
  7915. DataTable.factory = function (root, jq) {
  7916. var is = false;
  7917. // Test if the first parameter is a window object
  7918. if (root && root.document) {
  7919. window = root;
  7920. document = root.document;
  7921. }
  7922. // Test if the second parameter is a jQuery object
  7923. if (jq && jq.fn && jq.fn.jquery) {
  7924. $ = jq;
  7925. is = true;
  7926. }
  7927. return is;
  7928. }
  7929. /**
  7930. * Provide a common method for plug-ins to check the version of DataTables being
  7931. * used, in order to ensure compatibility.
  7932. *
  7933. * @param {string} version Version string to check for, in the format "X.Y.Z".
  7934. * Note that the formats "X" and "X.Y" are also acceptable.
  7935. * @returns {boolean} true if this version of DataTables is greater or equal to
  7936. * the required version, or false if this version of DataTales is not
  7937. * suitable
  7938. * @static
  7939. * @dtopt API-Static
  7940. *
  7941. * @example
  7942. * alert( $.fn.dataTable.versionCheck( '1.9.0' ) );
  7943. */
  7944. DataTable.versionCheck = DataTable.fnVersionCheck = function( version )
  7945. {
  7946. var aThis = DataTable.version.split('.');
  7947. var aThat = version.split('.');
  7948. var iThis, iThat;
  7949. for ( var i=0, iLen=aThat.length ; i<iLen ; i++ ) {
  7950. iThis = parseInt( aThis[i], 10 ) || 0;
  7951. iThat = parseInt( aThat[i], 10 ) || 0;
  7952. // Parts are the same, keep comparing
  7953. if (iThis === iThat) {
  7954. continue;
  7955. }
  7956. // Parts are different, return immediately
  7957. return iThis > iThat;
  7958. }
  7959. return true;
  7960. };
  7961. /**
  7962. * Check if a `<table>` node is a DataTable table already or not.
  7963. *
  7964. * @param {node|jquery|string} table Table node, jQuery object or jQuery
  7965. * selector for the table to test. Note that if more than more than one
  7966. * table is passed on, only the first will be checked
  7967. * @returns {boolean} true the table given is a DataTable, or false otherwise
  7968. * @static
  7969. * @dtopt API-Static
  7970. *
  7971. * @example
  7972. * if ( ! $.fn.DataTable.isDataTable( '#example' ) ) {
  7973. * $('#example').dataTable();
  7974. * }
  7975. */
  7976. DataTable.isDataTable = DataTable.fnIsDataTable = function ( table )
  7977. {
  7978. var t = $(table).get(0);
  7979. var is = false;
  7980. if ( table instanceof DataTable.Api ) {
  7981. return true;
  7982. }
  7983. $.each( DataTable.settings, function (i, o) {
  7984. var head = o.nScrollHead ? $('table', o.nScrollHead)[0] : null;
  7985. var foot = o.nScrollFoot ? $('table', o.nScrollFoot)[0] : null;
  7986. if ( o.nTable === t || head === t || foot === t ) {
  7987. is = true;
  7988. }
  7989. } );
  7990. return is;
  7991. };
  7992. /**
  7993. * Get all DataTable tables that have been initialised - optionally you can
  7994. * select to get only currently visible tables.
  7995. *
  7996. * @param {boolean} [visible=false] Flag to indicate if you want all (default)
  7997. * or visible tables only.
  7998. * @returns {array} Array of `table` nodes (not DataTable instances) which are
  7999. * DataTables
  8000. * @static
  8001. * @dtopt API-Static
  8002. *
  8003. * @example
  8004. * $.each( $.fn.dataTable.tables(true), function () {
  8005. * $(table).DataTable().columns.adjust();
  8006. * } );
  8007. */
  8008. DataTable.tables = DataTable.fnTables = function ( visible )
  8009. {
  8010. var api = false;
  8011. if ( $.isPlainObject( visible ) ) {
  8012. api = visible.api;
  8013. visible = visible.visible;
  8014. }
  8015. var a = $.map( DataTable.settings, function (o) {
  8016. if ( !visible || (visible && $(o.nTable).is(':visible')) ) {
  8017. return o.nTable;
  8018. }
  8019. } );
  8020. return api ?
  8021. new _Api( a ) :
  8022. a;
  8023. };
  8024. /**
  8025. * Convert from camel case parameters to Hungarian notation. This is made public
  8026. * for the extensions to provide the same ability as DataTables core to accept
  8027. * either the 1.9 style Hungarian notation, or the 1.10+ style camelCase
  8028. * parameters.
  8029. *
  8030. * @param {object} src The model object which holds all parameters that can be
  8031. * mapped.
  8032. * @param {object} user The object to convert from camel case to Hungarian.
  8033. * @param {boolean} force When set to `true`, properties which already have a
  8034. * Hungarian value in the `user` object will be overwritten. Otherwise they
  8035. * won't be.
  8036. */
  8037. DataTable.camelToHungarian = _fnCamelToHungarian;
  8038. /**
  8039. *
  8040. */
  8041. _api_register( '$()', function ( selector, opts ) {
  8042. var
  8043. rows = this.rows( opts ).nodes(), // Get all rows
  8044. jqRows = $(rows);
  8045. return $( [].concat(
  8046. jqRows.filter( selector ).toArray(),
  8047. jqRows.find( selector ).toArray()
  8048. ) );
  8049. } );
  8050. // jQuery functions to operate on the tables
  8051. $.each( [ 'on', 'one', 'off' ], function (i, key) {
  8052. _api_register( key+'()', function ( /* event, handler */ ) {
  8053. var args = Array.prototype.slice.call(arguments);
  8054. // Add the `dt` namespace automatically if it isn't already present
  8055. args[0] = $.map( args[0].split( /\s/ ), function ( e ) {
  8056. return ! e.match(/\.dt\b/) ?
  8057. e+'.dt' :
  8058. e;
  8059. } ).join( ' ' );
  8060. var inst = $( this.tables().nodes() );
  8061. inst[key].apply( inst, args );
  8062. return this;
  8063. } );
  8064. } );
  8065. _api_register( 'clear()', function () {
  8066. return this.iterator( 'table', function ( settings ) {
  8067. _fnClearTable( settings );
  8068. } );
  8069. } );
  8070. _api_register( 'settings()', function () {
  8071. return new _Api( this.context, this.context );
  8072. } );
  8073. _api_register( 'init()', function () {
  8074. var ctx = this.context;
  8075. return ctx.length ? ctx[0].oInit : null;
  8076. } );
  8077. _api_register( 'data()', function () {
  8078. return this.iterator( 'table', function ( settings ) {
  8079. return _pluck( settings.aoData, '_aData' );
  8080. } ).flatten();
  8081. } );
  8082. _api_register( 'destroy()', function ( remove ) {
  8083. remove = remove || false;
  8084. return this.iterator( 'table', function ( settings ) {
  8085. var classes = settings.oClasses;
  8086. var table = settings.nTable;
  8087. var tbody = settings.nTBody;
  8088. var thead = settings.nTHead;
  8089. var tfoot = settings.nTFoot;
  8090. var jqTable = $(table);
  8091. var jqTbody = $(tbody);
  8092. var jqWrapper = $(settings.nTableWrapper);
  8093. var rows = $.map( settings.aoData, function (r) { return r.nTr; } );
  8094. var i, ien;
  8095. // Flag to note that the table is currently being destroyed - no action
  8096. // should be taken
  8097. settings.bDestroying = true;
  8098. // Fire off the destroy callbacks for plug-ins etc
  8099. _fnCallbackFire( settings, "aoDestroyCallback", "destroy", [settings] );
  8100. // If not being removed from the document, make all columns visible
  8101. if ( ! remove ) {
  8102. new _Api( settings ).columns().visible( true );
  8103. }
  8104. // Blitz all `DT` namespaced events (these are internal events, the
  8105. // lowercase, `dt` events are user subscribed and they are responsible
  8106. // for removing them
  8107. jqWrapper.off('.DT').find(':not(tbody *)').off('.DT');
  8108. $(window).off('.DT-'+settings.sInstance);
  8109. // When scrolling we had to break the table up - restore it
  8110. if ( table != thead.parentNode ) {
  8111. jqTable.children('thead').detach();
  8112. jqTable.append( thead );
  8113. }
  8114. if ( tfoot && table != tfoot.parentNode ) {
  8115. jqTable.children('tfoot').detach();
  8116. jqTable.append( tfoot );
  8117. }
  8118. settings.aaSorting = [];
  8119. settings.aaSortingFixed = [];
  8120. _fnSortingClasses( settings );
  8121. $( rows ).removeClass( settings.asStripeClasses.join(' ') );
  8122. $('th, td', thead).removeClass( classes.sSortable+' '+
  8123. classes.sSortableAsc+' '+classes.sSortableDesc+' '+classes.sSortableNone
  8124. );
  8125. // Add the TR elements back into the table in their original order
  8126. jqTbody.children().detach();
  8127. jqTbody.append( rows );
  8128. var orig = settings.nTableWrapper.parentNode;
  8129. // Remove the DataTables generated nodes, events and classes
  8130. var removedMethod = remove ? 'remove' : 'detach';
  8131. jqTable[ removedMethod ]();
  8132. jqWrapper[ removedMethod ]();
  8133. // If we need to reattach the table to the document
  8134. if ( ! remove && orig ) {
  8135. // insertBefore acts like appendChild if !arg[1]
  8136. orig.insertBefore( table, settings.nTableReinsertBefore );
  8137. // Restore the width of the original table - was read from the style property,
  8138. // so we can restore directly to that
  8139. jqTable
  8140. .css( 'width', settings.sDestroyWidth )
  8141. .removeClass( classes.sTable );
  8142. // If the were originally stripe classes - then we add them back here.
  8143. // Note this is not fool proof (for example if not all rows had stripe
  8144. // classes - but it's a good effort without getting carried away
  8145. ien = settings.asDestroyStripes.length;
  8146. if ( ien ) {
  8147. jqTbody.children().each( function (i) {
  8148. $(this).addClass( settings.asDestroyStripes[i % ien] );
  8149. } );
  8150. }
  8151. }
  8152. /* Remove the settings object from the settings array */
  8153. var idx = $.inArray( settings, DataTable.settings );
  8154. if ( idx !== -1 ) {
  8155. DataTable.settings.splice( idx, 1 );
  8156. }
  8157. } );
  8158. } );
  8159. // Add the `every()` method for rows, columns and cells in a compact form
  8160. $.each( [ 'column', 'row', 'cell' ], function ( i, type ) {
  8161. _api_register( type+'s().every()', function ( fn ) {
  8162. var opts = this.selector.opts;
  8163. var api = this;
  8164. return this.iterator( type, function ( settings, arg1, arg2, arg3, arg4 ) {
  8165. // Rows and columns:
  8166. // arg1 - index
  8167. // arg2 - table counter
  8168. // arg3 - loop counter
  8169. // arg4 - undefined
  8170. // Cells:
  8171. // arg1 - row index
  8172. // arg2 - column index
  8173. // arg3 - table counter
  8174. // arg4 - loop counter
  8175. fn.call(
  8176. api[ type ](
  8177. arg1,
  8178. type==='cell' ? arg2 : opts,
  8179. type==='cell' ? opts : undefined
  8180. ),
  8181. arg1, arg2, arg3, arg4
  8182. );
  8183. } );
  8184. } );
  8185. } );
  8186. // i18n method for extensions to be able to use the language object from the
  8187. // DataTable
  8188. _api_register( 'i18n()', function ( token, def, plural ) {
  8189. var ctx = this.context[0];
  8190. var resolved = _fnGetObjectDataFn( token )( ctx.oLanguage );
  8191. if ( resolved === undefined ) {
  8192. resolved = def;
  8193. }
  8194. if ( plural !== undefined && $.isPlainObject( resolved ) ) {
  8195. resolved = resolved[ plural ] !== undefined ?
  8196. resolved[ plural ] :
  8197. resolved._;
  8198. }
  8199. return typeof resolved === 'string'
  8200. ? resolved.replace( '%d', plural ) // nb: plural might be undefined,
  8201. : resolved;
  8202. } );
  8203. /**
  8204. * Version string for plug-ins to check compatibility. Allowed format is
  8205. * `a.b.c-d` where: a:int, b:int, c:int, d:string(dev|beta|alpha). `d` is used
  8206. * only for non-release builds. See http://semver.org/ for more information.
  8207. * @member
  8208. * @type string
  8209. * @default Version number
  8210. */
  8211. DataTable.version = "1.13.5";
  8212. /**
  8213. * Private data store, containing all of the settings objects that are
  8214. * created for the tables on a given page.
  8215. *
  8216. * Note that the `DataTable.settings` object is aliased to
  8217. * `jQuery.fn.dataTableExt` through which it may be accessed and
  8218. * manipulated, or `jQuery.fn.dataTable.settings`.
  8219. * @member
  8220. * @type array
  8221. * @default []
  8222. * @private
  8223. */
  8224. DataTable.settings = [];
  8225. /**
  8226. * Object models container, for the various models that DataTables has
  8227. * available to it. These models define the objects that are used to hold
  8228. * the active state and configuration of the table.
  8229. * @namespace
  8230. */
  8231. DataTable.models = {};
  8232. /**
  8233. * Template object for the way in which DataTables holds information about
  8234. * search information for the global filter and individual column filters.
  8235. * @namespace
  8236. */
  8237. DataTable.models.oSearch = {
  8238. /**
  8239. * Flag to indicate if the filtering should be case insensitive or not
  8240. * @type boolean
  8241. * @default true
  8242. */
  8243. "bCaseInsensitive": true,
  8244. /**
  8245. * Applied search term
  8246. * @type string
  8247. * @default <i>Empty string</i>
  8248. */
  8249. "sSearch": "",
  8250. /**
  8251. * Flag to indicate if the search term should be interpreted as a
  8252. * regular expression (true) or not (false) and therefore and special
  8253. * regex characters escaped.
  8254. * @type boolean
  8255. * @default false
  8256. */
  8257. "bRegex": false,
  8258. /**
  8259. * Flag to indicate if DataTables is to use its smart filtering or not.
  8260. * @type boolean
  8261. * @default true
  8262. */
  8263. "bSmart": true,
  8264. /**
  8265. * Flag to indicate if DataTables should only trigger a search when
  8266. * the return key is pressed.
  8267. * @type boolean
  8268. * @default false
  8269. */
  8270. "return": false
  8271. };
  8272. /**
  8273. * Template object for the way in which DataTables holds information about
  8274. * each individual row. This is the object format used for the settings
  8275. * aoData array.
  8276. * @namespace
  8277. */
  8278. DataTable.models.oRow = {
  8279. /**
  8280. * TR element for the row
  8281. * @type node
  8282. * @default null
  8283. */
  8284. "nTr": null,
  8285. /**
  8286. * Array of TD elements for each row. This is null until the row has been
  8287. * created.
  8288. * @type array nodes
  8289. * @default []
  8290. */
  8291. "anCells": null,
  8292. /**
  8293. * Data object from the original data source for the row. This is either
  8294. * an array if using the traditional form of DataTables, or an object if
  8295. * using mData options. The exact type will depend on the passed in
  8296. * data from the data source, or will be an array if using DOM a data
  8297. * source.
  8298. * @type array|object
  8299. * @default []
  8300. */
  8301. "_aData": [],
  8302. /**
  8303. * Sorting data cache - this array is ostensibly the same length as the
  8304. * number of columns (although each index is generated only as it is
  8305. * needed), and holds the data that is used for sorting each column in the
  8306. * row. We do this cache generation at the start of the sort in order that
  8307. * the formatting of the sort data need be done only once for each cell
  8308. * per sort. This array should not be read from or written to by anything
  8309. * other than the master sorting methods.
  8310. * @type array
  8311. * @default null
  8312. * @private
  8313. */
  8314. "_aSortData": null,
  8315. /**
  8316. * Per cell filtering data cache. As per the sort data cache, used to
  8317. * increase the performance of the filtering in DataTables
  8318. * @type array
  8319. * @default null
  8320. * @private
  8321. */
  8322. "_aFilterData": null,
  8323. /**
  8324. * Filtering data cache. This is the same as the cell filtering cache, but
  8325. * in this case a string rather than an array. This is easily computed with
  8326. * a join on `_aFilterData`, but is provided as a cache so the join isn't
  8327. * needed on every search (memory traded for performance)
  8328. * @type array
  8329. * @default null
  8330. * @private
  8331. */
  8332. "_sFilterRow": null,
  8333. /**
  8334. * Cache of the class name that DataTables has applied to the row, so we
  8335. * can quickly look at this variable rather than needing to do a DOM check
  8336. * on className for the nTr property.
  8337. * @type string
  8338. * @default <i>Empty string</i>
  8339. * @private
  8340. */
  8341. "_sRowStripe": "",
  8342. /**
  8343. * Denote if the original data source was from the DOM, or the data source
  8344. * object. This is used for invalidating data, so DataTables can
  8345. * automatically read data from the original source, unless uninstructed
  8346. * otherwise.
  8347. * @type string
  8348. * @default null
  8349. * @private
  8350. */
  8351. "src": null,
  8352. /**
  8353. * Index in the aoData array. This saves an indexOf lookup when we have the
  8354. * object, but want to know the index
  8355. * @type integer
  8356. * @default -1
  8357. * @private
  8358. */
  8359. "idx": -1
  8360. };
  8361. /**
  8362. * Template object for the column information object in DataTables. This object
  8363. * is held in the settings aoColumns array and contains all the information that
  8364. * DataTables needs about each individual column.
  8365. *
  8366. * Note that this object is related to {@link DataTable.defaults.column}
  8367. * but this one is the internal data store for DataTables's cache of columns.
  8368. * It should NOT be manipulated outside of DataTables. Any configuration should
  8369. * be done through the initialisation options.
  8370. * @namespace
  8371. */
  8372. DataTable.models.oColumn = {
  8373. /**
  8374. * Column index. This could be worked out on-the-fly with $.inArray, but it
  8375. * is faster to just hold it as a variable
  8376. * @type integer
  8377. * @default null
  8378. */
  8379. "idx": null,
  8380. /**
  8381. * A list of the columns that sorting should occur on when this column
  8382. * is sorted. That this property is an array allows multi-column sorting
  8383. * to be defined for a column (for example first name / last name columns
  8384. * would benefit from this). The values are integers pointing to the
  8385. * columns to be sorted on (typically it will be a single integer pointing
  8386. * at itself, but that doesn't need to be the case).
  8387. * @type array
  8388. */
  8389. "aDataSort": null,
  8390. /**
  8391. * Define the sorting directions that are applied to the column, in sequence
  8392. * as the column is repeatedly sorted upon - i.e. the first value is used
  8393. * as the sorting direction when the column if first sorted (clicked on).
  8394. * Sort it again (click again) and it will move on to the next index.
  8395. * Repeat until loop.
  8396. * @type array
  8397. */
  8398. "asSorting": null,
  8399. /**
  8400. * Flag to indicate if the column is searchable, and thus should be included
  8401. * in the filtering or not.
  8402. * @type boolean
  8403. */
  8404. "bSearchable": null,
  8405. /**
  8406. * Flag to indicate if the column is sortable or not.
  8407. * @type boolean
  8408. */
  8409. "bSortable": null,
  8410. /**
  8411. * Flag to indicate if the column is currently visible in the table or not
  8412. * @type boolean
  8413. */
  8414. "bVisible": null,
  8415. /**
  8416. * Store for manual type assignment using the `column.type` option. This
  8417. * is held in store so we can manipulate the column's `sType` property.
  8418. * @type string
  8419. * @default null
  8420. * @private
  8421. */
  8422. "_sManualType": null,
  8423. /**
  8424. * Flag to indicate if HTML5 data attributes should be used as the data
  8425. * source for filtering or sorting. True is either are.
  8426. * @type boolean
  8427. * @default false
  8428. * @private
  8429. */
  8430. "_bAttrSrc": false,
  8431. /**
  8432. * Developer definable function that is called whenever a cell is created (Ajax source,
  8433. * etc) or processed for input (DOM source). This can be used as a compliment to mRender
  8434. * allowing you to modify the DOM element (add background colour for example) when the
  8435. * element is available.
  8436. * @type function
  8437. * @param {element} nTd The TD node that has been created
  8438. * @param {*} sData The Data for the cell
  8439. * @param {array|object} oData The data for the whole row
  8440. * @param {int} iRow The row index for the aoData data store
  8441. * @default null
  8442. */
  8443. "fnCreatedCell": null,
  8444. /**
  8445. * Function to get data from a cell in a column. You should <b>never</b>
  8446. * access data directly through _aData internally in DataTables - always use
  8447. * the method attached to this property. It allows mData to function as
  8448. * required. This function is automatically assigned by the column
  8449. * initialisation method
  8450. * @type function
  8451. * @param {array|object} oData The data array/object for the array
  8452. * (i.e. aoData[]._aData)
  8453. * @param {string} sSpecific The specific data type you want to get -
  8454. * 'display', 'type' 'filter' 'sort'
  8455. * @returns {*} The data for the cell from the given row's data
  8456. * @default null
  8457. */
  8458. "fnGetData": null,
  8459. /**
  8460. * Function to set data for a cell in the column. You should <b>never</b>
  8461. * set the data directly to _aData internally in DataTables - always use
  8462. * this method. It allows mData to function as required. This function
  8463. * is automatically assigned by the column initialisation method
  8464. * @type function
  8465. * @param {array|object} oData The data array/object for the array
  8466. * (i.e. aoData[]._aData)
  8467. * @param {*} sValue Value to set
  8468. * @default null
  8469. */
  8470. "fnSetData": null,
  8471. /**
  8472. * Property to read the value for the cells in the column from the data
  8473. * source array / object. If null, then the default content is used, if a
  8474. * function is given then the return from the function is used.
  8475. * @type function|int|string|null
  8476. * @default null
  8477. */
  8478. "mData": null,
  8479. /**
  8480. * Partner property to mData which is used (only when defined) to get
  8481. * the data - i.e. it is basically the same as mData, but without the
  8482. * 'set' option, and also the data fed to it is the result from mData.
  8483. * This is the rendering method to match the data method of mData.
  8484. * @type function|int|string|null
  8485. * @default null
  8486. */
  8487. "mRender": null,
  8488. /**
  8489. * Unique header TH/TD element for this column - this is what the sorting
  8490. * listener is attached to (if sorting is enabled.)
  8491. * @type node
  8492. * @default null
  8493. */
  8494. "nTh": null,
  8495. /**
  8496. * Unique footer TH/TD element for this column (if there is one). Not used
  8497. * in DataTables as such, but can be used for plug-ins to reference the
  8498. * footer for each column.
  8499. * @type node
  8500. * @default null
  8501. */
  8502. "nTf": null,
  8503. /**
  8504. * The class to apply to all TD elements in the table's TBODY for the column
  8505. * @type string
  8506. * @default null
  8507. */
  8508. "sClass": null,
  8509. /**
  8510. * When DataTables calculates the column widths to assign to each column,
  8511. * it finds the longest string in each column and then constructs a
  8512. * temporary table and reads the widths from that. The problem with this
  8513. * is that "mmm" is much wider then "iiii", but the latter is a longer
  8514. * string - thus the calculation can go wrong (doing it properly and putting
  8515. * it into an DOM object and measuring that is horribly(!) slow). Thus as
  8516. * a "work around" we provide this option. It will append its value to the
  8517. * text that is found to be the longest string for the column - i.e. padding.
  8518. * @type string
  8519. */
  8520. "sContentPadding": null,
  8521. /**
  8522. * Allows a default value to be given for a column's data, and will be used
  8523. * whenever a null data source is encountered (this can be because mData
  8524. * is set to null, or because the data source itself is null).
  8525. * @type string
  8526. * @default null
  8527. */
  8528. "sDefaultContent": null,
  8529. /**
  8530. * Name for the column, allowing reference to the column by name as well as
  8531. * by index (needs a lookup to work by name).
  8532. * @type string
  8533. */
  8534. "sName": null,
  8535. /**
  8536. * Custom sorting data type - defines which of the available plug-ins in
  8537. * afnSortData the custom sorting will use - if any is defined.
  8538. * @type string
  8539. * @default std
  8540. */
  8541. "sSortDataType": 'std',
  8542. /**
  8543. * Class to be applied to the header element when sorting on this column
  8544. * @type string
  8545. * @default null
  8546. */
  8547. "sSortingClass": null,
  8548. /**
  8549. * Class to be applied to the header element when sorting on this column -
  8550. * when jQuery UI theming is used.
  8551. * @type string
  8552. * @default null
  8553. */
  8554. "sSortingClassJUI": null,
  8555. /**
  8556. * Title of the column - what is seen in the TH element (nTh).
  8557. * @type string
  8558. */
  8559. "sTitle": null,
  8560. /**
  8561. * Column sorting and filtering type
  8562. * @type string
  8563. * @default null
  8564. */
  8565. "sType": null,
  8566. /**
  8567. * Width of the column
  8568. * @type string
  8569. * @default null
  8570. */
  8571. "sWidth": null,
  8572. /**
  8573. * Width of the column when it was first "encountered"
  8574. * @type string
  8575. * @default null
  8576. */
  8577. "sWidthOrig": null
  8578. };
  8579. /*
  8580. * Developer note: The properties of the object below are given in Hungarian
  8581. * notation, that was used as the interface for DataTables prior to v1.10, however
  8582. * from v1.10 onwards the primary interface is camel case. In order to avoid
  8583. * breaking backwards compatibility utterly with this change, the Hungarian
  8584. * version is still, internally the primary interface, but is is not documented
  8585. * - hence the @name tags in each doc comment. This allows a Javascript function
  8586. * to create a map from Hungarian notation to camel case (going the other direction
  8587. * would require each property to be listed, which would add around 3K to the size
  8588. * of DataTables, while this method is about a 0.5K hit).
  8589. *
  8590. * Ultimately this does pave the way for Hungarian notation to be dropped
  8591. * completely, but that is a massive amount of work and will break current
  8592. * installs (therefore is on-hold until v2).
  8593. */
  8594. /**
  8595. * Initialisation options that can be given to DataTables at initialisation
  8596. * time.
  8597. * @namespace
  8598. */
  8599. DataTable.defaults = {
  8600. /**
  8601. * An array of data to use for the table, passed in at initialisation which
  8602. * will be used in preference to any data which is already in the DOM. This is
  8603. * particularly useful for constructing tables purely in Javascript, for
  8604. * example with a custom Ajax call.
  8605. * @type array
  8606. * @default null
  8607. *
  8608. * @dtopt Option
  8609. * @name DataTable.defaults.data
  8610. *
  8611. * @example
  8612. * // Using a 2D array data source
  8613. * $(document).ready( function () {
  8614. * $('#example').dataTable( {
  8615. * "data": [
  8616. * ['Trident', 'Internet Explorer 4.0', 'Win 95+', 4, 'X'],
  8617. * ['Trident', 'Internet Explorer 5.0', 'Win 95+', 5, 'C'],
  8618. * ],
  8619. * "columns": [
  8620. * { "title": "Engine" },
  8621. * { "title": "Browser" },
  8622. * { "title": "Platform" },
  8623. * { "title": "Version" },
  8624. * { "title": "Grade" }
  8625. * ]
  8626. * } );
  8627. * } );
  8628. *
  8629. * @example
  8630. * // Using an array of objects as a data source (`data`)
  8631. * $(document).ready( function () {
  8632. * $('#example').dataTable( {
  8633. * "data": [
  8634. * {
  8635. * "engine": "Trident",
  8636. * "browser": "Internet Explorer 4.0",
  8637. * "platform": "Win 95+",
  8638. * "version": 4,
  8639. * "grade": "X"
  8640. * },
  8641. * {
  8642. * "engine": "Trident",
  8643. * "browser": "Internet Explorer 5.0",
  8644. * "platform": "Win 95+",
  8645. * "version": 5,
  8646. * "grade": "C"
  8647. * }
  8648. * ],
  8649. * "columns": [
  8650. * { "title": "Engine", "data": "engine" },
  8651. * { "title": "Browser", "data": "browser" },
  8652. * { "title": "Platform", "data": "platform" },
  8653. * { "title": "Version", "data": "version" },
  8654. * { "title": "Grade", "data": "grade" }
  8655. * ]
  8656. * } );
  8657. * } );
  8658. */
  8659. "aaData": null,
  8660. /**
  8661. * If ordering is enabled, then DataTables will perform a first pass sort on
  8662. * initialisation. You can define which column(s) the sort is performed
  8663. * upon, and the sorting direction, with this variable. The `sorting` array
  8664. * should contain an array for each column to be sorted initially containing
  8665. * the column's index and a direction string ('asc' or 'desc').
  8666. * @type array
  8667. * @default [[0,'asc']]
  8668. *
  8669. * @dtopt Option
  8670. * @name DataTable.defaults.order
  8671. *
  8672. * @example
  8673. * // Sort by 3rd column first, and then 4th column
  8674. * $(document).ready( function() {
  8675. * $('#example').dataTable( {
  8676. * "order": [[2,'asc'], [3,'desc']]
  8677. * } );
  8678. * } );
  8679. *
  8680. * // No initial sorting
  8681. * $(document).ready( function() {
  8682. * $('#example').dataTable( {
  8683. * "order": []
  8684. * } );
  8685. * } );
  8686. */
  8687. "aaSorting": [[0,'asc']],
  8688. /**
  8689. * This parameter is basically identical to the `sorting` parameter, but
  8690. * cannot be overridden by user interaction with the table. What this means
  8691. * is that you could have a column (visible or hidden) which the sorting
  8692. * will always be forced on first - any sorting after that (from the user)
  8693. * will then be performed as required. This can be useful for grouping rows
  8694. * together.
  8695. * @type array
  8696. * @default null
  8697. *
  8698. * @dtopt Option
  8699. * @name DataTable.defaults.orderFixed
  8700. *
  8701. * @example
  8702. * $(document).ready( function() {
  8703. * $('#example').dataTable( {
  8704. * "orderFixed": [[0,'asc']]
  8705. * } );
  8706. * } )
  8707. */
  8708. "aaSortingFixed": [],
  8709. /**
  8710. * DataTables can be instructed to load data to display in the table from a
  8711. * Ajax source. This option defines how that Ajax call is made and where to.
  8712. *
  8713. * The `ajax` property has three different modes of operation, depending on
  8714. * how it is defined. These are:
  8715. *
  8716. * * `string` - Set the URL from where the data should be loaded from.
  8717. * * `object` - Define properties for `jQuery.ajax`.
  8718. * * `function` - Custom data get function
  8719. *
  8720. * `string`
  8721. * --------
  8722. *
  8723. * As a string, the `ajax` property simply defines the URL from which
  8724. * DataTables will load data.
  8725. *
  8726. * `object`
  8727. * --------
  8728. *
  8729. * As an object, the parameters in the object are passed to
  8730. * [jQuery.ajax](http://api.jquery.com/jQuery.ajax/) allowing fine control
  8731. * of the Ajax request. DataTables has a number of default parameters which
  8732. * you can override using this option. Please refer to the jQuery
  8733. * documentation for a full description of the options available, although
  8734. * the following parameters provide additional options in DataTables or
  8735. * require special consideration:
  8736. *
  8737. * * `data` - As with jQuery, `data` can be provided as an object, but it
  8738. * can also be used as a function to manipulate the data DataTables sends
  8739. * to the server. The function takes a single parameter, an object of
  8740. * parameters with the values that DataTables has readied for sending. An
  8741. * object may be returned which will be merged into the DataTables
  8742. * defaults, or you can add the items to the object that was passed in and
  8743. * not return anything from the function. This supersedes `fnServerParams`
  8744. * from DataTables 1.9-.
  8745. *
  8746. * * `dataSrc` - By default DataTables will look for the property `data` (or
  8747. * `aaData` for compatibility with DataTables 1.9-) when obtaining data
  8748. * from an Ajax source or for server-side processing - this parameter
  8749. * allows that property to be changed. You can use Javascript dotted
  8750. * object notation to get a data source for multiple levels of nesting, or
  8751. * it my be used as a function. As a function it takes a single parameter,
  8752. * the JSON returned from the server, which can be manipulated as
  8753. * required, with the returned value being that used by DataTables as the
  8754. * data source for the table. This supersedes `sAjaxDataProp` from
  8755. * DataTables 1.9-.
  8756. *
  8757. * * `success` - Should not be overridden it is used internally in
  8758. * DataTables. To manipulate / transform the data returned by the server
  8759. * use `ajax.dataSrc`, or use `ajax` as a function (see below).
  8760. *
  8761. * `function`
  8762. * ----------
  8763. *
  8764. * As a function, making the Ajax call is left up to yourself allowing
  8765. * complete control of the Ajax request. Indeed, if desired, a method other
  8766. * than Ajax could be used to obtain the required data, such as Web storage
  8767. * or an AIR database.
  8768. *
  8769. * The function is given four parameters and no return is required. The
  8770. * parameters are:
  8771. *
  8772. * 1. _object_ - Data to send to the server
  8773. * 2. _function_ - Callback function that must be executed when the required
  8774. * data has been obtained. That data should be passed into the callback
  8775. * as the only parameter
  8776. * 3. _object_ - DataTables settings object for the table
  8777. *
  8778. * Note that this supersedes `fnServerData` from DataTables 1.9-.
  8779. *
  8780. * @type string|object|function
  8781. * @default null
  8782. *
  8783. * @dtopt Option
  8784. * @name DataTable.defaults.ajax
  8785. * @since 1.10.0
  8786. *
  8787. * @example
  8788. * // Get JSON data from a file via Ajax.
  8789. * // Note DataTables expects data in the form `{ data: [ ...data... ] }` by default).
  8790. * $('#example').dataTable( {
  8791. * "ajax": "data.json"
  8792. * } );
  8793. *
  8794. * @example
  8795. * // Get JSON data from a file via Ajax, using `dataSrc` to change
  8796. * // `data` to `tableData` (i.e. `{ tableData: [ ...data... ] }`)
  8797. * $('#example').dataTable( {
  8798. * "ajax": {
  8799. * "url": "data.json",
  8800. * "dataSrc": "tableData"
  8801. * }
  8802. * } );
  8803. *
  8804. * @example
  8805. * // Get JSON data from a file via Ajax, using `dataSrc` to read data
  8806. * // from a plain array rather than an array in an object
  8807. * $('#example').dataTable( {
  8808. * "ajax": {
  8809. * "url": "data.json",
  8810. * "dataSrc": ""
  8811. * }
  8812. * } );
  8813. *
  8814. * @example
  8815. * // Manipulate the data returned from the server - add a link to data
  8816. * // (note this can, should, be done using `render` for the column - this
  8817. * // is just a simple example of how the data can be manipulated).
  8818. * $('#example').dataTable( {
  8819. * "ajax": {
  8820. * "url": "data.json",
  8821. * "dataSrc": function ( json ) {
  8822. * for ( var i=0, ien=json.length ; i<ien ; i++ ) {
  8823. * json[i][0] = '<a href="/message/'+json[i][0]+'>View message</a>';
  8824. * }
  8825. * return json;
  8826. * }
  8827. * }
  8828. * } );
  8829. *
  8830. * @example
  8831. * // Add data to the request
  8832. * $('#example').dataTable( {
  8833. * "ajax": {
  8834. * "url": "data.json",
  8835. * "data": function ( d ) {
  8836. * return {
  8837. * "extra_search": $('#extra').val()
  8838. * };
  8839. * }
  8840. * }
  8841. * } );
  8842. *
  8843. * @example
  8844. * // Send request as POST
  8845. * $('#example').dataTable( {
  8846. * "ajax": {
  8847. * "url": "data.json",
  8848. * "type": "POST"
  8849. * }
  8850. * } );
  8851. *
  8852. * @example
  8853. * // Get the data from localStorage (could interface with a form for
  8854. * // adding, editing and removing rows).
  8855. * $('#example').dataTable( {
  8856. * "ajax": function (data, callback, settings) {
  8857. * callback(
  8858. * JSON.parse( localStorage.getItem('dataTablesData') )
  8859. * );
  8860. * }
  8861. * } );
  8862. */
  8863. "ajax": null,
  8864. /**
  8865. * This parameter allows you to readily specify the entries in the length drop
  8866. * down menu that DataTables shows when pagination is enabled. It can be
  8867. * either a 1D array of options which will be used for both the displayed
  8868. * option and the value, or a 2D array which will use the array in the first
  8869. * position as the value, and the array in the second position as the
  8870. * displayed options (useful for language strings such as 'All').
  8871. *
  8872. * Note that the `pageLength` property will be automatically set to the
  8873. * first value given in this array, unless `pageLength` is also provided.
  8874. * @type array
  8875. * @default [ 10, 25, 50, 100 ]
  8876. *
  8877. * @dtopt Option
  8878. * @name DataTable.defaults.lengthMenu
  8879. *
  8880. * @example
  8881. * $(document).ready( function() {
  8882. * $('#example').dataTable( {
  8883. * "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
  8884. * } );
  8885. * } );
  8886. */
  8887. "aLengthMenu": [ 10, 25, 50, 100 ],
  8888. /**
  8889. * The `columns` option in the initialisation parameter allows you to define
  8890. * details about the way individual columns behave. For a full list of
  8891. * column options that can be set, please see
  8892. * {@link DataTable.defaults.column}. Note that if you use `columns` to
  8893. * define your columns, you must have an entry in the array for every single
  8894. * column that you have in your table (these can be null if you don't which
  8895. * to specify any options).
  8896. * @member
  8897. *
  8898. * @name DataTable.defaults.column
  8899. */
  8900. "aoColumns": null,
  8901. /**
  8902. * Very similar to `columns`, `columnDefs` allows you to target a specific
  8903. * column, multiple columns, or all columns, using the `targets` property of
  8904. * each object in the array. This allows great flexibility when creating
  8905. * tables, as the `columnDefs` arrays can be of any length, targeting the
  8906. * columns you specifically want. `columnDefs` may use any of the column
  8907. * options available: {@link DataTable.defaults.column}, but it _must_
  8908. * have `targets` defined in each object in the array. Values in the `targets`
  8909. * array may be:
  8910. * <ul>
  8911. * <li>a string - class name will be matched on the TH for the column</li>
  8912. * <li>0 or a positive integer - column index counting from the left</li>
  8913. * <li>a negative integer - column index counting from the right</li>
  8914. * <li>the string "_all" - all columns (i.e. assign a default)</li>
  8915. * </ul>
  8916. * @member
  8917. *
  8918. * @name DataTable.defaults.columnDefs
  8919. */
  8920. "aoColumnDefs": null,
  8921. /**
  8922. * Basically the same as `search`, this parameter defines the individual column
  8923. * filtering state at initialisation time. The array must be of the same size
  8924. * as the number of columns, and each element be an object with the parameters
  8925. * `search` and `escapeRegex` (the latter is optional). 'null' is also
  8926. * accepted and the default will be used.
  8927. * @type array
  8928. * @default []
  8929. *
  8930. * @dtopt Option
  8931. * @name DataTable.defaults.searchCols
  8932. *
  8933. * @example
  8934. * $(document).ready( function() {
  8935. * $('#example').dataTable( {
  8936. * "searchCols": [
  8937. * null,
  8938. * { "search": "My filter" },
  8939. * null,
  8940. * { "search": "^[0-9]", "escapeRegex": false }
  8941. * ]
  8942. * } );
  8943. * } )
  8944. */
  8945. "aoSearchCols": [],
  8946. /**
  8947. * An array of CSS classes that should be applied to displayed rows. This
  8948. * array may be of any length, and DataTables will apply each class
  8949. * sequentially, looping when required.
  8950. * @type array
  8951. * @default null <i>Will take the values determined by the `oClasses.stripe*`
  8952. * options</i>
  8953. *
  8954. * @dtopt Option
  8955. * @name DataTable.defaults.stripeClasses
  8956. *
  8957. * @example
  8958. * $(document).ready( function() {
  8959. * $('#example').dataTable( {
  8960. * "stripeClasses": [ 'strip1', 'strip2', 'strip3' ]
  8961. * } );
  8962. * } )
  8963. */
  8964. "asStripeClasses": null,
  8965. /**
  8966. * Enable or disable automatic column width calculation. This can be disabled
  8967. * as an optimisation (it takes some time to calculate the widths) if the
  8968. * tables widths are passed in using `columns`.
  8969. * @type boolean
  8970. * @default true
  8971. *
  8972. * @dtopt Features
  8973. * @name DataTable.defaults.autoWidth
  8974. *
  8975. * @example
  8976. * $(document).ready( function () {
  8977. * $('#example').dataTable( {
  8978. * "autoWidth": false
  8979. * } );
  8980. * } );
  8981. */
  8982. "bAutoWidth": true,
  8983. /**
  8984. * Deferred rendering can provide DataTables with a huge speed boost when you
  8985. * are using an Ajax or JS data source for the table. This option, when set to
  8986. * true, will cause DataTables to defer the creation of the table elements for
  8987. * each row until they are needed for a draw - saving a significant amount of
  8988. * time.
  8989. * @type boolean
  8990. * @default false
  8991. *
  8992. * @dtopt Features
  8993. * @name DataTable.defaults.deferRender
  8994. *
  8995. * @example
  8996. * $(document).ready( function() {
  8997. * $('#example').dataTable( {
  8998. * "ajax": "sources/arrays.txt",
  8999. * "deferRender": true
  9000. * } );
  9001. * } );
  9002. */
  9003. "bDeferRender": false,
  9004. /**
  9005. * Replace a DataTable which matches the given selector and replace it with
  9006. * one which has the properties of the new initialisation object passed. If no
  9007. * table matches the selector, then the new DataTable will be constructed as
  9008. * per normal.
  9009. * @type boolean
  9010. * @default false
  9011. *
  9012. * @dtopt Options
  9013. * @name DataTable.defaults.destroy
  9014. *
  9015. * @example
  9016. * $(document).ready( function() {
  9017. * $('#example').dataTable( {
  9018. * "srollY": "200px",
  9019. * "paginate": false
  9020. * } );
  9021. *
  9022. * // Some time later....
  9023. * $('#example').dataTable( {
  9024. * "filter": false,
  9025. * "destroy": true
  9026. * } );
  9027. * } );
  9028. */
  9029. "bDestroy": false,
  9030. /**
  9031. * Enable or disable filtering of data. Filtering in DataTables is "smart" in
  9032. * that it allows the end user to input multiple words (space separated) and
  9033. * will match a row containing those words, even if not in the order that was
  9034. * specified (this allow matching across multiple columns). Note that if you
  9035. * wish to use filtering in DataTables this must remain 'true' - to remove the
  9036. * default filtering input box and retain filtering abilities, please use
  9037. * {@link DataTable.defaults.dom}.
  9038. * @type boolean
  9039. * @default true
  9040. *
  9041. * @dtopt Features
  9042. * @name DataTable.defaults.searching
  9043. *
  9044. * @example
  9045. * $(document).ready( function () {
  9046. * $('#example').dataTable( {
  9047. * "searching": false
  9048. * } );
  9049. * } );
  9050. */
  9051. "bFilter": true,
  9052. /**
  9053. * Enable or disable the table information display. This shows information
  9054. * about the data that is currently visible on the page, including information
  9055. * about filtered data if that action is being performed.
  9056. * @type boolean
  9057. * @default true
  9058. *
  9059. * @dtopt Features
  9060. * @name DataTable.defaults.info
  9061. *
  9062. * @example
  9063. * $(document).ready( function () {
  9064. * $('#example').dataTable( {
  9065. * "info": false
  9066. * } );
  9067. * } );
  9068. */
  9069. "bInfo": true,
  9070. /**
  9071. * Allows the end user to select the size of a formatted page from a select
  9072. * menu (sizes are 10, 25, 50 and 100). Requires pagination (`paginate`).
  9073. * @type boolean
  9074. * @default true
  9075. *
  9076. * @dtopt Features
  9077. * @name DataTable.defaults.lengthChange
  9078. *
  9079. * @example
  9080. * $(document).ready( function () {
  9081. * $('#example').dataTable( {
  9082. * "lengthChange": false
  9083. * } );
  9084. * } );
  9085. */
  9086. "bLengthChange": true,
  9087. /**
  9088. * Enable or disable pagination.
  9089. * @type boolean
  9090. * @default true
  9091. *
  9092. * @dtopt Features
  9093. * @name DataTable.defaults.paging
  9094. *
  9095. * @example
  9096. * $(document).ready( function () {
  9097. * $('#example').dataTable( {
  9098. * "paging": false
  9099. * } );
  9100. * } );
  9101. */
  9102. "bPaginate": true,
  9103. /**
  9104. * Enable or disable the display of a 'processing' indicator when the table is
  9105. * being processed (e.g. a sort). This is particularly useful for tables with
  9106. * large amounts of data where it can take a noticeable amount of time to sort
  9107. * the entries.
  9108. * @type boolean
  9109. * @default false
  9110. *
  9111. * @dtopt Features
  9112. * @name DataTable.defaults.processing
  9113. *
  9114. * @example
  9115. * $(document).ready( function () {
  9116. * $('#example').dataTable( {
  9117. * "processing": true
  9118. * } );
  9119. * } );
  9120. */
  9121. "bProcessing": false,
  9122. /**
  9123. * Retrieve the DataTables object for the given selector. Note that if the
  9124. * table has already been initialised, this parameter will cause DataTables
  9125. * to simply return the object that has already been set up - it will not take
  9126. * account of any changes you might have made to the initialisation object
  9127. * passed to DataTables (setting this parameter to true is an acknowledgement
  9128. * that you understand this). `destroy` can be used to reinitialise a table if
  9129. * you need.
  9130. * @type boolean
  9131. * @default false
  9132. *
  9133. * @dtopt Options
  9134. * @name DataTable.defaults.retrieve
  9135. *
  9136. * @example
  9137. * $(document).ready( function() {
  9138. * initTable();
  9139. * tableActions();
  9140. * } );
  9141. *
  9142. * function initTable ()
  9143. * {
  9144. * return $('#example').dataTable( {
  9145. * "scrollY": "200px",
  9146. * "paginate": false,
  9147. * "retrieve": true
  9148. * } );
  9149. * }
  9150. *
  9151. * function tableActions ()
  9152. * {
  9153. * var table = initTable();
  9154. * // perform API operations with oTable
  9155. * }
  9156. */
  9157. "bRetrieve": false,
  9158. /**
  9159. * When vertical (y) scrolling is enabled, DataTables will force the height of
  9160. * the table's viewport to the given height at all times (useful for layout).
  9161. * However, this can look odd when filtering data down to a small data set,
  9162. * and the footer is left "floating" further down. This parameter (when
  9163. * enabled) will cause DataTables to collapse the table's viewport down when
  9164. * the result set will fit within the given Y height.
  9165. * @type boolean
  9166. * @default false
  9167. *
  9168. * @dtopt Options
  9169. * @name DataTable.defaults.scrollCollapse
  9170. *
  9171. * @example
  9172. * $(document).ready( function() {
  9173. * $('#example').dataTable( {
  9174. * "scrollY": "200",
  9175. * "scrollCollapse": true
  9176. * } );
  9177. * } );
  9178. */
  9179. "bScrollCollapse": false,
  9180. /**
  9181. * Configure DataTables to use server-side processing. Note that the
  9182. * `ajax` parameter must also be given in order to give DataTables a
  9183. * source to obtain the required data for each draw.
  9184. * @type boolean
  9185. * @default false
  9186. *
  9187. * @dtopt Features
  9188. * @dtopt Server-side
  9189. * @name DataTable.defaults.serverSide
  9190. *
  9191. * @example
  9192. * $(document).ready( function () {
  9193. * $('#example').dataTable( {
  9194. * "serverSide": true,
  9195. * "ajax": "xhr.php"
  9196. * } );
  9197. * } );
  9198. */
  9199. "bServerSide": false,
  9200. /**
  9201. * Enable or disable sorting of columns. Sorting of individual columns can be
  9202. * disabled by the `sortable` option for each column.
  9203. * @type boolean
  9204. * @default true
  9205. *
  9206. * @dtopt Features
  9207. * @name DataTable.defaults.ordering
  9208. *
  9209. * @example
  9210. * $(document).ready( function () {
  9211. * $('#example').dataTable( {
  9212. * "ordering": false
  9213. * } );
  9214. * } );
  9215. */
  9216. "bSort": true,
  9217. /**
  9218. * Enable or display DataTables' ability to sort multiple columns at the
  9219. * same time (activated by shift-click by the user).
  9220. * @type boolean
  9221. * @default true
  9222. *
  9223. * @dtopt Options
  9224. * @name DataTable.defaults.orderMulti
  9225. *
  9226. * @example
  9227. * // Disable multiple column sorting ability
  9228. * $(document).ready( function () {
  9229. * $('#example').dataTable( {
  9230. * "orderMulti": false
  9231. * } );
  9232. * } );
  9233. */
  9234. "bSortMulti": true,
  9235. /**
  9236. * Allows control over whether DataTables should use the top (true) unique
  9237. * cell that is found for a single column, or the bottom (false - default).
  9238. * This is useful when using complex headers.
  9239. * @type boolean
  9240. * @default false
  9241. *
  9242. * @dtopt Options
  9243. * @name DataTable.defaults.orderCellsTop
  9244. *
  9245. * @example
  9246. * $(document).ready( function() {
  9247. * $('#example').dataTable( {
  9248. * "orderCellsTop": true
  9249. * } );
  9250. * } );
  9251. */
  9252. "bSortCellsTop": false,
  9253. /**
  9254. * Enable or disable the addition of the classes `sorting\_1`, `sorting\_2` and
  9255. * `sorting\_3` to the columns which are currently being sorted on. This is
  9256. * presented as a feature switch as it can increase processing time (while
  9257. * classes are removed and added) so for large data sets you might want to
  9258. * turn this off.
  9259. * @type boolean
  9260. * @default true
  9261. *
  9262. * @dtopt Features
  9263. * @name DataTable.defaults.orderClasses
  9264. *
  9265. * @example
  9266. * $(document).ready( function () {
  9267. * $('#example').dataTable( {
  9268. * "orderClasses": false
  9269. * } );
  9270. * } );
  9271. */
  9272. "bSortClasses": true,
  9273. /**
  9274. * Enable or disable state saving. When enabled HTML5 `localStorage` will be
  9275. * used to save table display information such as pagination information,
  9276. * display length, filtering and sorting. As such when the end user reloads
  9277. * the page the display display will match what thy had previously set up.
  9278. *
  9279. * Due to the use of `localStorage` the default state saving is not supported
  9280. * in IE6 or 7. If state saving is required in those browsers, use
  9281. * `stateSaveCallback` to provide a storage solution such as cookies.
  9282. * @type boolean
  9283. * @default false
  9284. *
  9285. * @dtopt Features
  9286. * @name DataTable.defaults.stateSave
  9287. *
  9288. * @example
  9289. * $(document).ready( function () {
  9290. * $('#example').dataTable( {
  9291. * "stateSave": true
  9292. * } );
  9293. * } );
  9294. */
  9295. "bStateSave": false,
  9296. /**
  9297. * This function is called when a TR element is created (and all TD child
  9298. * elements have been inserted), or registered if using a DOM source, allowing
  9299. * manipulation of the TR element (adding classes etc).
  9300. * @type function
  9301. * @param {node} row "TR" element for the current row
  9302. * @param {array} data Raw data array for this row
  9303. * @param {int} dataIndex The index of this row in the internal aoData array
  9304. *
  9305. * @dtopt Callbacks
  9306. * @name DataTable.defaults.createdRow
  9307. *
  9308. * @example
  9309. * $(document).ready( function() {
  9310. * $('#example').dataTable( {
  9311. * "createdRow": function( row, data, dataIndex ) {
  9312. * // Bold the grade for all 'A' grade browsers
  9313. * if ( data[4] == "A" )
  9314. * {
  9315. * $('td:eq(4)', row).html( '<b>A</b>' );
  9316. * }
  9317. * }
  9318. * } );
  9319. * } );
  9320. */
  9321. "fnCreatedRow": null,
  9322. /**
  9323. * This function is called on every 'draw' event, and allows you to
  9324. * dynamically modify any aspect you want about the created DOM.
  9325. * @type function
  9326. * @param {object} settings DataTables settings object
  9327. *
  9328. * @dtopt Callbacks
  9329. * @name DataTable.defaults.drawCallback
  9330. *
  9331. * @example
  9332. * $(document).ready( function() {
  9333. * $('#example').dataTable( {
  9334. * "drawCallback": function( settings ) {
  9335. * alert( 'DataTables has redrawn the table' );
  9336. * }
  9337. * } );
  9338. * } );
  9339. */
  9340. "fnDrawCallback": null,
  9341. /**
  9342. * Identical to fnHeaderCallback() but for the table footer this function
  9343. * allows you to modify the table footer on every 'draw' event.
  9344. * @type function
  9345. * @param {node} foot "TR" element for the footer
  9346. * @param {array} data Full table data (as derived from the original HTML)
  9347. * @param {int} start Index for the current display starting point in the
  9348. * display array
  9349. * @param {int} end Index for the current display ending point in the
  9350. * display array
  9351. * @param {array int} display Index array to translate the visual position
  9352. * to the full data array
  9353. *
  9354. * @dtopt Callbacks
  9355. * @name DataTable.defaults.footerCallback
  9356. *
  9357. * @example
  9358. * $(document).ready( function() {
  9359. * $('#example').dataTable( {
  9360. * "footerCallback": function( tfoot, data, start, end, display ) {
  9361. * tfoot.getElementsByTagName('th')[0].innerHTML = "Starting index is "+start;
  9362. * }
  9363. * } );
  9364. * } )
  9365. */
  9366. "fnFooterCallback": null,
  9367. /**
  9368. * When rendering large numbers in the information element for the table
  9369. * (i.e. "Showing 1 to 10 of 57 entries") DataTables will render large numbers
  9370. * to have a comma separator for the 'thousands' units (e.g. 1 million is
  9371. * rendered as "1,000,000") to help readability for the end user. This
  9372. * function will override the default method DataTables uses.
  9373. * @type function
  9374. * @member
  9375. * @param {int} toFormat number to be formatted
  9376. * @returns {string} formatted string for DataTables to show the number
  9377. *
  9378. * @dtopt Callbacks
  9379. * @name DataTable.defaults.formatNumber
  9380. *
  9381. * @example
  9382. * // Format a number using a single quote for the separator (note that
  9383. * // this can also be done with the language.thousands option)
  9384. * $(document).ready( function() {
  9385. * $('#example').dataTable( {
  9386. * "formatNumber": function ( toFormat ) {
  9387. * return toFormat.toString().replace(
  9388. * /\B(?=(\d{3})+(?!\d))/g, "'"
  9389. * );
  9390. * };
  9391. * } );
  9392. * } );
  9393. */
  9394. "fnFormatNumber": function ( toFormat ) {
  9395. return toFormat.toString().replace(
  9396. /\B(?=(\d{3})+(?!\d))/g,
  9397. this.oLanguage.sThousands
  9398. );
  9399. },
  9400. /**
  9401. * This function is called on every 'draw' event, and allows you to
  9402. * dynamically modify the header row. This can be used to calculate and
  9403. * display useful information about the table.
  9404. * @type function
  9405. * @param {node} head "TR" element for the header
  9406. * @param {array} data Full table data (as derived from the original HTML)
  9407. * @param {int} start Index for the current display starting point in the
  9408. * display array
  9409. * @param {int} end Index for the current display ending point in the
  9410. * display array
  9411. * @param {array int} display Index array to translate the visual position
  9412. * to the full data array
  9413. *
  9414. * @dtopt Callbacks
  9415. * @name DataTable.defaults.headerCallback
  9416. *
  9417. * @example
  9418. * $(document).ready( function() {
  9419. * $('#example').dataTable( {
  9420. * "fheaderCallback": function( head, data, start, end, display ) {
  9421. * head.getElementsByTagName('th')[0].innerHTML = "Displaying "+(end-start)+" records";
  9422. * }
  9423. * } );
  9424. * } )
  9425. */
  9426. "fnHeaderCallback": null,
  9427. /**
  9428. * The information element can be used to convey information about the current
  9429. * state of the table. Although the internationalisation options presented by
  9430. * DataTables are quite capable of dealing with most customisations, there may
  9431. * be times where you wish to customise the string further. This callback
  9432. * allows you to do exactly that.
  9433. * @type function
  9434. * @param {object} oSettings DataTables settings object
  9435. * @param {int} start Starting position in data for the draw
  9436. * @param {int} end End position in data for the draw
  9437. * @param {int} max Total number of rows in the table (regardless of
  9438. * filtering)
  9439. * @param {int} total Total number of rows in the data set, after filtering
  9440. * @param {string} pre The string that DataTables has formatted using it's
  9441. * own rules
  9442. * @returns {string} The string to be displayed in the information element.
  9443. *
  9444. * @dtopt Callbacks
  9445. * @name DataTable.defaults.infoCallback
  9446. *
  9447. * @example
  9448. * $('#example').dataTable( {
  9449. * "infoCallback": function( settings, start, end, max, total, pre ) {
  9450. * return start +" to "+ end;
  9451. * }
  9452. * } );
  9453. */
  9454. "fnInfoCallback": null,
  9455. /**
  9456. * Called when the table has been initialised. Normally DataTables will
  9457. * initialise sequentially and there will be no need for this function,
  9458. * however, this does not hold true when using external language information
  9459. * since that is obtained using an async XHR call.
  9460. * @type function
  9461. * @param {object} settings DataTables settings object
  9462. * @param {object} json The JSON object request from the server - only
  9463. * present if client-side Ajax sourced data is used
  9464. *
  9465. * @dtopt Callbacks
  9466. * @name DataTable.defaults.initComplete
  9467. *
  9468. * @example
  9469. * $(document).ready( function() {
  9470. * $('#example').dataTable( {
  9471. * "initComplete": function(settings, json) {
  9472. * alert( 'DataTables has finished its initialisation.' );
  9473. * }
  9474. * } );
  9475. * } )
  9476. */
  9477. "fnInitComplete": null,
  9478. /**
  9479. * Called at the very start of each table draw and can be used to cancel the
  9480. * draw by returning false, any other return (including undefined) results in
  9481. * the full draw occurring).
  9482. * @type function
  9483. * @param {object} settings DataTables settings object
  9484. * @returns {boolean} False will cancel the draw, anything else (including no
  9485. * return) will allow it to complete.
  9486. *
  9487. * @dtopt Callbacks
  9488. * @name DataTable.defaults.preDrawCallback
  9489. *
  9490. * @example
  9491. * $(document).ready( function() {
  9492. * $('#example').dataTable( {
  9493. * "preDrawCallback": function( settings ) {
  9494. * if ( $('#test').val() == 1 ) {
  9495. * return false;
  9496. * }
  9497. * }
  9498. * } );
  9499. * } );
  9500. */
  9501. "fnPreDrawCallback": null,
  9502. /**
  9503. * This function allows you to 'post process' each row after it have been
  9504. * generated for each table draw, but before it is rendered on screen. This
  9505. * function might be used for setting the row class name etc.
  9506. * @type function
  9507. * @param {node} row "TR" element for the current row
  9508. * @param {array} data Raw data array for this row
  9509. * @param {int} displayIndex The display index for the current table draw
  9510. * @param {int} displayIndexFull The index of the data in the full list of
  9511. * rows (after filtering)
  9512. *
  9513. * @dtopt Callbacks
  9514. * @name DataTable.defaults.rowCallback
  9515. *
  9516. * @example
  9517. * $(document).ready( function() {
  9518. * $('#example').dataTable( {
  9519. * "rowCallback": function( row, data, displayIndex, displayIndexFull ) {
  9520. * // Bold the grade for all 'A' grade browsers
  9521. * if ( data[4] == "A" ) {
  9522. * $('td:eq(4)', row).html( '<b>A</b>' );
  9523. * }
  9524. * }
  9525. * } );
  9526. * } );
  9527. */
  9528. "fnRowCallback": null,
  9529. /**
  9530. * __Deprecated__ The functionality provided by this parameter has now been
  9531. * superseded by that provided through `ajax`, which should be used instead.
  9532. *
  9533. * This parameter allows you to override the default function which obtains
  9534. * the data from the server so something more suitable for your application.
  9535. * For example you could use POST data, or pull information from a Gears or
  9536. * AIR database.
  9537. * @type function
  9538. * @member
  9539. * @param {string} source HTTP source to obtain the data from (`ajax`)
  9540. * @param {array} data A key/value pair object containing the data to send
  9541. * to the server
  9542. * @param {function} callback to be called on completion of the data get
  9543. * process that will draw the data on the page.
  9544. * @param {object} settings DataTables settings object
  9545. *
  9546. * @dtopt Callbacks
  9547. * @dtopt Server-side
  9548. * @name DataTable.defaults.serverData
  9549. *
  9550. * @deprecated 1.10. Please use `ajax` for this functionality now.
  9551. */
  9552. "fnServerData": null,
  9553. /**
  9554. * __Deprecated__ The functionality provided by this parameter has now been
  9555. * superseded by that provided through `ajax`, which should be used instead.
  9556. *
  9557. * It is often useful to send extra data to the server when making an Ajax
  9558. * request - for example custom filtering information, and this callback
  9559. * function makes it trivial to send extra information to the server. The
  9560. * passed in parameter is the data set that has been constructed by
  9561. * DataTables, and you can add to this or modify it as you require.
  9562. * @type function
  9563. * @param {array} data Data array (array of objects which are name/value
  9564. * pairs) that has been constructed by DataTables and will be sent to the
  9565. * server. In the case of Ajax sourced data with server-side processing
  9566. * this will be an empty array, for server-side processing there will be a
  9567. * significant number of parameters!
  9568. * @returns {undefined} Ensure that you modify the data array passed in,
  9569. * as this is passed by reference.
  9570. *
  9571. * @dtopt Callbacks
  9572. * @dtopt Server-side
  9573. * @name DataTable.defaults.serverParams
  9574. *
  9575. * @deprecated 1.10. Please use `ajax` for this functionality now.
  9576. */
  9577. "fnServerParams": null,
  9578. /**
  9579. * Load the table state. With this function you can define from where, and how, the
  9580. * state of a table is loaded. By default DataTables will load from `localStorage`
  9581. * but you might wish to use a server-side database or cookies.
  9582. * @type function
  9583. * @member
  9584. * @param {object} settings DataTables settings object
  9585. * @param {object} callback Callback that can be executed when done. It
  9586. * should be passed the loaded state object.
  9587. * @return {object} The DataTables state object to be loaded
  9588. *
  9589. * @dtopt Callbacks
  9590. * @name DataTable.defaults.stateLoadCallback
  9591. *
  9592. * @example
  9593. * $(document).ready( function() {
  9594. * $('#example').dataTable( {
  9595. * "stateSave": true,
  9596. * "stateLoadCallback": function (settings, callback) {
  9597. * $.ajax( {
  9598. * "url": "/state_load",
  9599. * "dataType": "json",
  9600. * "success": function (json) {
  9601. * callback( json );
  9602. * }
  9603. * } );
  9604. * }
  9605. * } );
  9606. * } );
  9607. */
  9608. "fnStateLoadCallback": function ( settings ) {
  9609. try {
  9610. return JSON.parse(
  9611. (settings.iStateDuration === -1 ? sessionStorage : localStorage).getItem(
  9612. 'DataTables_'+settings.sInstance+'_'+location.pathname
  9613. )
  9614. );
  9615. } catch (e) {
  9616. return {};
  9617. }
  9618. },
  9619. /**
  9620. * Callback which allows modification of the saved state prior to loading that state.
  9621. * This callback is called when the table is loading state from the stored data, but
  9622. * prior to the settings object being modified by the saved state. Note that for
  9623. * plug-in authors, you should use the `stateLoadParams` event to load parameters for
  9624. * a plug-in.
  9625. * @type function
  9626. * @param {object} settings DataTables settings object
  9627. * @param {object} data The state object that is to be loaded
  9628. *
  9629. * @dtopt Callbacks
  9630. * @name DataTable.defaults.stateLoadParams
  9631. *
  9632. * @example
  9633. * // Remove a saved filter, so filtering is never loaded
  9634. * $(document).ready( function() {
  9635. * $('#example').dataTable( {
  9636. * "stateSave": true,
  9637. * "stateLoadParams": function (settings, data) {
  9638. * data.oSearch.sSearch = "";
  9639. * }
  9640. * } );
  9641. * } );
  9642. *
  9643. * @example
  9644. * // Disallow state loading by returning false
  9645. * $(document).ready( function() {
  9646. * $('#example').dataTable( {
  9647. * "stateSave": true,
  9648. * "stateLoadParams": function (settings, data) {
  9649. * return false;
  9650. * }
  9651. * } );
  9652. * } );
  9653. */
  9654. "fnStateLoadParams": null,
  9655. /**
  9656. * Callback that is called when the state has been loaded from the state saving method
  9657. * and the DataTables settings object has been modified as a result of the loaded state.
  9658. * @type function
  9659. * @param {object} settings DataTables settings object
  9660. * @param {object} data The state object that was loaded
  9661. *
  9662. * @dtopt Callbacks
  9663. * @name DataTable.defaults.stateLoaded
  9664. *
  9665. * @example
  9666. * // Show an alert with the filtering value that was saved
  9667. * $(document).ready( function() {
  9668. * $('#example').dataTable( {
  9669. * "stateSave": true,
  9670. * "stateLoaded": function (settings, data) {
  9671. * alert( 'Saved filter was: '+data.oSearch.sSearch );
  9672. * }
  9673. * } );
  9674. * } );
  9675. */
  9676. "fnStateLoaded": null,
  9677. /**
  9678. * Save the table state. This function allows you to define where and how the state
  9679. * information for the table is stored By default DataTables will use `localStorage`
  9680. * but you might wish to use a server-side database or cookies.
  9681. * @type function
  9682. * @member
  9683. * @param {object} settings DataTables settings object
  9684. * @param {object} data The state object to be saved
  9685. *
  9686. * @dtopt Callbacks
  9687. * @name DataTable.defaults.stateSaveCallback
  9688. *
  9689. * @example
  9690. * $(document).ready( function() {
  9691. * $('#example').dataTable( {
  9692. * "stateSave": true,
  9693. * "stateSaveCallback": function (settings, data) {
  9694. * // Send an Ajax request to the server with the state object
  9695. * $.ajax( {
  9696. * "url": "/state_save",
  9697. * "data": data,
  9698. * "dataType": "json",
  9699. * "method": "POST"
  9700. * "success": function () {}
  9701. * } );
  9702. * }
  9703. * } );
  9704. * } );
  9705. */
  9706. "fnStateSaveCallback": function ( settings, data ) {
  9707. try {
  9708. (settings.iStateDuration === -1 ? sessionStorage : localStorage).setItem(
  9709. 'DataTables_'+settings.sInstance+'_'+location.pathname,
  9710. JSON.stringify( data )
  9711. );
  9712. } catch (e) {}
  9713. },
  9714. /**
  9715. * Callback which allows modification of the state to be saved. Called when the table
  9716. * has changed state a new state save is required. This method allows modification of
  9717. * the state saving object prior to actually doing the save, including addition or
  9718. * other state properties or modification. Note that for plug-in authors, you should
  9719. * use the `stateSaveParams` event to save parameters for a plug-in.
  9720. * @type function
  9721. * @param {object} settings DataTables settings object
  9722. * @param {object} data The state object to be saved
  9723. *
  9724. * @dtopt Callbacks
  9725. * @name DataTable.defaults.stateSaveParams
  9726. *
  9727. * @example
  9728. * // Remove a saved filter, so filtering is never saved
  9729. * $(document).ready( function() {
  9730. * $('#example').dataTable( {
  9731. * "stateSave": true,
  9732. * "stateSaveParams": function (settings, data) {
  9733. * data.oSearch.sSearch = "";
  9734. * }
  9735. * } );
  9736. * } );
  9737. */
  9738. "fnStateSaveParams": null,
  9739. /**
  9740. * Duration for which the saved state information is considered valid. After this period
  9741. * has elapsed the state will be returned to the default.
  9742. * Value is given in seconds.
  9743. * @type int
  9744. * @default 7200 <i>(2 hours)</i>
  9745. *
  9746. * @dtopt Options
  9747. * @name DataTable.defaults.stateDuration
  9748. *
  9749. * @example
  9750. * $(document).ready( function() {
  9751. * $('#example').dataTable( {
  9752. * "stateDuration": 60*60*24; // 1 day
  9753. * } );
  9754. * } )
  9755. */
  9756. "iStateDuration": 7200,
  9757. /**
  9758. * When enabled DataTables will not make a request to the server for the first
  9759. * page draw - rather it will use the data already on the page (no sorting etc
  9760. * will be applied to it), thus saving on an XHR at load time. `deferLoading`
  9761. * is used to indicate that deferred loading is required, but it is also used
  9762. * to tell DataTables how many records there are in the full table (allowing
  9763. * the information element and pagination to be displayed correctly). In the case
  9764. * where a filtering is applied to the table on initial load, this can be
  9765. * indicated by giving the parameter as an array, where the first element is
  9766. * the number of records available after filtering and the second element is the
  9767. * number of records without filtering (allowing the table information element
  9768. * to be shown correctly).
  9769. * @type int | array
  9770. * @default null
  9771. *
  9772. * @dtopt Options
  9773. * @name DataTable.defaults.deferLoading
  9774. *
  9775. * @example
  9776. * // 57 records available in the table, no filtering applied
  9777. * $(document).ready( function() {
  9778. * $('#example').dataTable( {
  9779. * "serverSide": true,
  9780. * "ajax": "scripts/server_processing.php",
  9781. * "deferLoading": 57
  9782. * } );
  9783. * } );
  9784. *
  9785. * @example
  9786. * // 57 records after filtering, 100 without filtering (an initial filter applied)
  9787. * $(document).ready( function() {
  9788. * $('#example').dataTable( {
  9789. * "serverSide": true,
  9790. * "ajax": "scripts/server_processing.php",
  9791. * "deferLoading": [ 57, 100 ],
  9792. * "search": {
  9793. * "search": "my_filter"
  9794. * }
  9795. * } );
  9796. * } );
  9797. */
  9798. "iDeferLoading": null,
  9799. /**
  9800. * Number of rows to display on a single page when using pagination. If
  9801. * feature enabled (`lengthChange`) then the end user will be able to override
  9802. * this to a custom setting using a pop-up menu.
  9803. * @type int
  9804. * @default 10
  9805. *
  9806. * @dtopt Options
  9807. * @name DataTable.defaults.pageLength
  9808. *
  9809. * @example
  9810. * $(document).ready( function() {
  9811. * $('#example').dataTable( {
  9812. * "pageLength": 50
  9813. * } );
  9814. * } )
  9815. */
  9816. "iDisplayLength": 10,
  9817. /**
  9818. * Define the starting point for data display when using DataTables with
  9819. * pagination. Note that this parameter is the number of records, rather than
  9820. * the page number, so if you have 10 records per page and want to start on
  9821. * the third page, it should be "20".
  9822. * @type int
  9823. * @default 0
  9824. *
  9825. * @dtopt Options
  9826. * @name DataTable.defaults.displayStart
  9827. *
  9828. * @example
  9829. * $(document).ready( function() {
  9830. * $('#example').dataTable( {
  9831. * "displayStart": 20
  9832. * } );
  9833. * } )
  9834. */
  9835. "iDisplayStart": 0,
  9836. /**
  9837. * By default DataTables allows keyboard navigation of the table (sorting, paging,
  9838. * and filtering) by adding a `tabindex` attribute to the required elements. This
  9839. * allows you to tab through the controls and press the enter key to activate them.
  9840. * The tabindex is default 0, meaning that the tab follows the flow of the document.
  9841. * You can overrule this using this parameter if you wish. Use a value of -1 to
  9842. * disable built-in keyboard navigation.
  9843. * @type int
  9844. * @default 0
  9845. *
  9846. * @dtopt Options
  9847. * @name DataTable.defaults.tabIndex
  9848. *
  9849. * @example
  9850. * $(document).ready( function() {
  9851. * $('#example').dataTable( {
  9852. * "tabIndex": 1
  9853. * } );
  9854. * } );
  9855. */
  9856. "iTabIndex": 0,
  9857. /**
  9858. * Classes that DataTables assigns to the various components and features
  9859. * that it adds to the HTML table. This allows classes to be configured
  9860. * during initialisation in addition to through the static
  9861. * {@link DataTable.ext.oStdClasses} object).
  9862. * @namespace
  9863. * @name DataTable.defaults.classes
  9864. */
  9865. "oClasses": {},
  9866. /**
  9867. * All strings that DataTables uses in the user interface that it creates
  9868. * are defined in this object, allowing you to modified them individually or
  9869. * completely replace them all as required.
  9870. * @namespace
  9871. * @name DataTable.defaults.language
  9872. */
  9873. "oLanguage": {
  9874. /**
  9875. * Strings that are used for WAI-ARIA labels and controls only (these are not
  9876. * actually visible on the page, but will be read by screenreaders, and thus
  9877. * must be internationalised as well).
  9878. * @namespace
  9879. * @name DataTable.defaults.language.aria
  9880. */
  9881. "oAria": {
  9882. /**
  9883. * ARIA label that is added to the table headers when the column may be
  9884. * sorted ascending by activing the column (click or return when focused).
  9885. * Note that the column header is prefixed to this string.
  9886. * @type string
  9887. * @default : activate to sort column ascending
  9888. *
  9889. * @dtopt Language
  9890. * @name DataTable.defaults.language.aria.sortAscending
  9891. *
  9892. * @example
  9893. * $(document).ready( function() {
  9894. * $('#example').dataTable( {
  9895. * "language": {
  9896. * "aria": {
  9897. * "sortAscending": " - click/return to sort ascending"
  9898. * }
  9899. * }
  9900. * } );
  9901. * } );
  9902. */
  9903. "sSortAscending": ": activate to sort column ascending",
  9904. /**
  9905. * ARIA label that is added to the table headers when the column may be
  9906. * sorted descending by activing the column (click or return when focused).
  9907. * Note that the column header is prefixed to this string.
  9908. * @type string
  9909. * @default : activate to sort column ascending
  9910. *
  9911. * @dtopt Language
  9912. * @name DataTable.defaults.language.aria.sortDescending
  9913. *
  9914. * @example
  9915. * $(document).ready( function() {
  9916. * $('#example').dataTable( {
  9917. * "language": {
  9918. * "aria": {
  9919. * "sortDescending": " - click/return to sort descending"
  9920. * }
  9921. * }
  9922. * } );
  9923. * } );
  9924. */
  9925. "sSortDescending": ": activate to sort column descending"
  9926. },
  9927. /**
  9928. * Pagination string used by DataTables for the built-in pagination
  9929. * control types.
  9930. * @namespace
  9931. * @name DataTable.defaults.language.paginate
  9932. */
  9933. "oPaginate": {
  9934. /**
  9935. * Text to use when using the 'full_numbers' type of pagination for the
  9936. * button to take the user to the first page.
  9937. * @type string
  9938. * @default First
  9939. *
  9940. * @dtopt Language
  9941. * @name DataTable.defaults.language.paginate.first
  9942. *
  9943. * @example
  9944. * $(document).ready( function() {
  9945. * $('#example').dataTable( {
  9946. * "language": {
  9947. * "paginate": {
  9948. * "first": "First page"
  9949. * }
  9950. * }
  9951. * } );
  9952. * } );
  9953. */
  9954. "sFirst": "First",
  9955. /**
  9956. * Text to use when using the 'full_numbers' type of pagination for the
  9957. * button to take the user to the last page.
  9958. * @type string
  9959. * @default Last
  9960. *
  9961. * @dtopt Language
  9962. * @name DataTable.defaults.language.paginate.last
  9963. *
  9964. * @example
  9965. * $(document).ready( function() {
  9966. * $('#example').dataTable( {
  9967. * "language": {
  9968. * "paginate": {
  9969. * "last": "Last page"
  9970. * }
  9971. * }
  9972. * } );
  9973. * } );
  9974. */
  9975. "sLast": "Last",
  9976. /**
  9977. * Text to use for the 'next' pagination button (to take the user to the
  9978. * next page).
  9979. * @type string
  9980. * @default Next
  9981. *
  9982. * @dtopt Language
  9983. * @name DataTable.defaults.language.paginate.next
  9984. *
  9985. * @example
  9986. * $(document).ready( function() {
  9987. * $('#example').dataTable( {
  9988. * "language": {
  9989. * "paginate": {
  9990. * "next": "Next page"
  9991. * }
  9992. * }
  9993. * } );
  9994. * } );
  9995. */
  9996. "sNext": "Next",
  9997. /**
  9998. * Text to use for the 'previous' pagination button (to take the user to
  9999. * the previous page).
  10000. * @type string
  10001. * @default Previous
  10002. *
  10003. * @dtopt Language
  10004. * @name DataTable.defaults.language.paginate.previous
  10005. *
  10006. * @example
  10007. * $(document).ready( function() {
  10008. * $('#example').dataTable( {
  10009. * "language": {
  10010. * "paginate": {
  10011. * "previous": "Previous page"
  10012. * }
  10013. * }
  10014. * } );
  10015. * } );
  10016. */
  10017. "sPrevious": "Previous"
  10018. },
  10019. /**
  10020. * This string is shown in preference to `zeroRecords` when the table is
  10021. * empty of data (regardless of filtering). Note that this is an optional
  10022. * parameter - if it is not given, the value of `zeroRecords` will be used
  10023. * instead (either the default or given value).
  10024. * @type string
  10025. * @default No data available in table
  10026. *
  10027. * @dtopt Language
  10028. * @name DataTable.defaults.language.emptyTable
  10029. *
  10030. * @example
  10031. * $(document).ready( function() {
  10032. * $('#example').dataTable( {
  10033. * "language": {
  10034. * "emptyTable": "No data available in table"
  10035. * }
  10036. * } );
  10037. * } );
  10038. */
  10039. "sEmptyTable": "No data available in table",
  10040. /**
  10041. * This string gives information to the end user about the information
  10042. * that is current on display on the page. The following tokens can be
  10043. * used in the string and will be dynamically replaced as the table
  10044. * display updates. This tokens can be placed anywhere in the string, or
  10045. * removed as needed by the language requires:
  10046. *
  10047. * * `\_START\_` - Display index of the first record on the current page
  10048. * * `\_END\_` - Display index of the last record on the current page
  10049. * * `\_TOTAL\_` - Number of records in the table after filtering
  10050. * * `\_MAX\_` - Number of records in the table without filtering
  10051. * * `\_PAGE\_` - Current page number
  10052. * * `\_PAGES\_` - Total number of pages of data in the table
  10053. *
  10054. * @type string
  10055. * @default Showing _START_ to _END_ of _TOTAL_ entries
  10056. *
  10057. * @dtopt Language
  10058. * @name DataTable.defaults.language.info
  10059. *
  10060. * @example
  10061. * $(document).ready( function() {
  10062. * $('#example').dataTable( {
  10063. * "language": {
  10064. * "info": "Showing page _PAGE_ of _PAGES_"
  10065. * }
  10066. * } );
  10067. * } );
  10068. */
  10069. "sInfo": "Showing _START_ to _END_ of _TOTAL_ entries",
  10070. /**
  10071. * Display information string for when the table is empty. Typically the
  10072. * format of this string should match `info`.
  10073. * @type string
  10074. * @default Showing 0 to 0 of 0 entries
  10075. *
  10076. * @dtopt Language
  10077. * @name DataTable.defaults.language.infoEmpty
  10078. *
  10079. * @example
  10080. * $(document).ready( function() {
  10081. * $('#example').dataTable( {
  10082. * "language": {
  10083. * "infoEmpty": "No entries to show"
  10084. * }
  10085. * } );
  10086. * } );
  10087. */
  10088. "sInfoEmpty": "Showing 0 to 0 of 0 entries",
  10089. /**
  10090. * When a user filters the information in a table, this string is appended
  10091. * to the information (`info`) to give an idea of how strong the filtering
  10092. * is. The variable _MAX_ is dynamically updated.
  10093. * @type string
  10094. * @default (filtered from _MAX_ total entries)
  10095. *
  10096. * @dtopt Language
  10097. * @name DataTable.defaults.language.infoFiltered
  10098. *
  10099. * @example
  10100. * $(document).ready( function() {
  10101. * $('#example').dataTable( {
  10102. * "language": {
  10103. * "infoFiltered": " - filtering from _MAX_ records"
  10104. * }
  10105. * } );
  10106. * } );
  10107. */
  10108. "sInfoFiltered": "(filtered from _MAX_ total entries)",
  10109. /**
  10110. * If can be useful to append extra information to the info string at times,
  10111. * and this variable does exactly that. This information will be appended to
  10112. * the `info` (`infoEmpty` and `infoFiltered` in whatever combination they are
  10113. * being used) at all times.
  10114. * @type string
  10115. * @default <i>Empty string</i>
  10116. *
  10117. * @dtopt Language
  10118. * @name DataTable.defaults.language.infoPostFix
  10119. *
  10120. * @example
  10121. * $(document).ready( function() {
  10122. * $('#example').dataTable( {
  10123. * "language": {
  10124. * "infoPostFix": "All records shown are derived from real information."
  10125. * }
  10126. * } );
  10127. * } );
  10128. */
  10129. "sInfoPostFix": "",
  10130. /**
  10131. * This decimal place operator is a little different from the other
  10132. * language options since DataTables doesn't output floating point
  10133. * numbers, so it won't ever use this for display of a number. Rather,
  10134. * what this parameter does is modify the sort methods of the table so
  10135. * that numbers which are in a format which has a character other than
  10136. * a period (`.`) as a decimal place will be sorted numerically.
  10137. *
  10138. * Note that numbers with different decimal places cannot be shown in
  10139. * the same table and still be sortable, the table must be consistent.
  10140. * However, multiple different tables on the page can use different
  10141. * decimal place characters.
  10142. * @type string
  10143. * @default
  10144. *
  10145. * @dtopt Language
  10146. * @name DataTable.defaults.language.decimal
  10147. *
  10148. * @example
  10149. * $(document).ready( function() {
  10150. * $('#example').dataTable( {
  10151. * "language": {
  10152. * "decimal": ","
  10153. * "thousands": "."
  10154. * }
  10155. * } );
  10156. * } );
  10157. */
  10158. "sDecimal": "",
  10159. /**
  10160. * DataTables has a build in number formatter (`formatNumber`) which is
  10161. * used to format large numbers that are used in the table information.
  10162. * By default a comma is used, but this can be trivially changed to any
  10163. * character you wish with this parameter.
  10164. * @type string
  10165. * @default ,
  10166. *
  10167. * @dtopt Language
  10168. * @name DataTable.defaults.language.thousands
  10169. *
  10170. * @example
  10171. * $(document).ready( function() {
  10172. * $('#example').dataTable( {
  10173. * "language": {
  10174. * "thousands": "'"
  10175. * }
  10176. * } );
  10177. * } );
  10178. */
  10179. "sThousands": ",",
  10180. /**
  10181. * Detail the action that will be taken when the drop down menu for the
  10182. * pagination length option is changed. The '_MENU_' variable is replaced
  10183. * with a default select list of 10, 25, 50 and 100, and can be replaced
  10184. * with a custom select box if required.
  10185. * @type string
  10186. * @default Show _MENU_ entries
  10187. *
  10188. * @dtopt Language
  10189. * @name DataTable.defaults.language.lengthMenu
  10190. *
  10191. * @example
  10192. * // Language change only
  10193. * $(document).ready( function() {
  10194. * $('#example').dataTable( {
  10195. * "language": {
  10196. * "lengthMenu": "Display _MENU_ records"
  10197. * }
  10198. * } );
  10199. * } );
  10200. *
  10201. * @example
  10202. * // Language and options change
  10203. * $(document).ready( function() {
  10204. * $('#example').dataTable( {
  10205. * "language": {
  10206. * "lengthMenu": 'Display <select>'+
  10207. * '<option value="10">10</option>'+
  10208. * '<option value="20">20</option>'+
  10209. * '<option value="30">30</option>'+
  10210. * '<option value="40">40</option>'+
  10211. * '<option value="50">50</option>'+
  10212. * '<option value="-1">All</option>'+
  10213. * '</select> records'
  10214. * }
  10215. * } );
  10216. * } );
  10217. */
  10218. "sLengthMenu": "Show _MENU_ entries",
  10219. /**
  10220. * When using Ajax sourced data and during the first draw when DataTables is
  10221. * gathering the data, this message is shown in an empty row in the table to
  10222. * indicate to the end user the the data is being loaded. Note that this
  10223. * parameter is not used when loading data by server-side processing, just
  10224. * Ajax sourced data with client-side processing.
  10225. * @type string
  10226. * @default Loading...
  10227. *
  10228. * @dtopt Language
  10229. * @name DataTable.defaults.language.loadingRecords
  10230. *
  10231. * @example
  10232. * $(document).ready( function() {
  10233. * $('#example').dataTable( {
  10234. * "language": {
  10235. * "loadingRecords": "Please wait - loading..."
  10236. * }
  10237. * } );
  10238. * } );
  10239. */
  10240. "sLoadingRecords": "Loading...",
  10241. /**
  10242. * Text which is displayed when the table is processing a user action
  10243. * (usually a sort command or similar).
  10244. * @type string
  10245. *
  10246. * @dtopt Language
  10247. * @name DataTable.defaults.language.processing
  10248. *
  10249. * @example
  10250. * $(document).ready( function() {
  10251. * $('#example').dataTable( {
  10252. * "language": {
  10253. * "processing": "DataTables is currently busy"
  10254. * }
  10255. * } );
  10256. * } );
  10257. */
  10258. "sProcessing": "",
  10259. /**
  10260. * Details the actions that will be taken when the user types into the
  10261. * filtering input text box. The variable "_INPUT_", if used in the string,
  10262. * is replaced with the HTML text box for the filtering input allowing
  10263. * control over where it appears in the string. If "_INPUT_" is not given
  10264. * then the input box is appended to the string automatically.
  10265. * @type string
  10266. * @default Search:
  10267. *
  10268. * @dtopt Language
  10269. * @name DataTable.defaults.language.search
  10270. *
  10271. * @example
  10272. * // Input text box will be appended at the end automatically
  10273. * $(document).ready( function() {
  10274. * $('#example').dataTable( {
  10275. * "language": {
  10276. * "search": "Filter records:"
  10277. * }
  10278. * } );
  10279. * } );
  10280. *
  10281. * @example
  10282. * // Specify where the filter should appear
  10283. * $(document).ready( function() {
  10284. * $('#example').dataTable( {
  10285. * "language": {
  10286. * "search": "Apply filter _INPUT_ to table"
  10287. * }
  10288. * } );
  10289. * } );
  10290. */
  10291. "sSearch": "Search:",
  10292. /**
  10293. * Assign a `placeholder` attribute to the search `input` element
  10294. * @type string
  10295. * @default
  10296. *
  10297. * @dtopt Language
  10298. * @name DataTable.defaults.language.searchPlaceholder
  10299. */
  10300. "sSearchPlaceholder": "",
  10301. /**
  10302. * All of the language information can be stored in a file on the
  10303. * server-side, which DataTables will look up if this parameter is passed.
  10304. * It must store the URL of the language file, which is in a JSON format,
  10305. * and the object has the same properties as the oLanguage object in the
  10306. * initialiser object (i.e. the above parameters). Please refer to one of
  10307. * the example language files to see how this works in action.
  10308. * @type string
  10309. * @default <i>Empty string - i.e. disabled</i>
  10310. *
  10311. * @dtopt Language
  10312. * @name DataTable.defaults.language.url
  10313. *
  10314. * @example
  10315. * $(document).ready( function() {
  10316. * $('#example').dataTable( {
  10317. * "language": {
  10318. * "url": "http://www.sprymedia.co.uk/dataTables/lang.txt"
  10319. * }
  10320. * } );
  10321. * } );
  10322. */
  10323. "sUrl": "",
  10324. /**
  10325. * Text shown inside the table records when the is no information to be
  10326. * displayed after filtering. `emptyTable` is shown when there is simply no
  10327. * information in the table at all (regardless of filtering).
  10328. * @type string
  10329. * @default No matching records found
  10330. *
  10331. * @dtopt Language
  10332. * @name DataTable.defaults.language.zeroRecords
  10333. *
  10334. * @example
  10335. * $(document).ready( function() {
  10336. * $('#example').dataTable( {
  10337. * "language": {
  10338. * "zeroRecords": "No records to display"
  10339. * }
  10340. * } );
  10341. * } );
  10342. */
  10343. "sZeroRecords": "No matching records found"
  10344. },
  10345. /**
  10346. * This parameter allows you to have define the global filtering state at
  10347. * initialisation time. As an object the `search` parameter must be
  10348. * defined, but all other parameters are optional. When `regex` is true,
  10349. * the search string will be treated as a regular expression, when false
  10350. * (default) it will be treated as a straight string. When `smart`
  10351. * DataTables will use it's smart filtering methods (to word match at
  10352. * any point in the data), when false this will not be done.
  10353. * @namespace
  10354. * @extends DataTable.models.oSearch
  10355. *
  10356. * @dtopt Options
  10357. * @name DataTable.defaults.search
  10358. *
  10359. * @example
  10360. * $(document).ready( function() {
  10361. * $('#example').dataTable( {
  10362. * "search": {"search": "Initial search"}
  10363. * } );
  10364. * } )
  10365. */
  10366. "oSearch": $.extend( {}, DataTable.models.oSearch ),
  10367. /**
  10368. * __Deprecated__ The functionality provided by this parameter has now been
  10369. * superseded by that provided through `ajax`, which should be used instead.
  10370. *
  10371. * By default DataTables will look for the property `data` (or `aaData` for
  10372. * compatibility with DataTables 1.9-) when obtaining data from an Ajax
  10373. * source or for server-side processing - this parameter allows that
  10374. * property to be changed. You can use Javascript dotted object notation to
  10375. * get a data source for multiple levels of nesting.
  10376. * @type string
  10377. * @default data
  10378. *
  10379. * @dtopt Options
  10380. * @dtopt Server-side
  10381. * @name DataTable.defaults.ajaxDataProp
  10382. *
  10383. * @deprecated 1.10. Please use `ajax` for this functionality now.
  10384. */
  10385. "sAjaxDataProp": "data",
  10386. /**
  10387. * __Deprecated__ The functionality provided by this parameter has now been
  10388. * superseded by that provided through `ajax`, which should be used instead.
  10389. *
  10390. * You can instruct DataTables to load data from an external
  10391. * source using this parameter (use aData if you want to pass data in you
  10392. * already have). Simply provide a url a JSON object can be obtained from.
  10393. * @type string
  10394. * @default null
  10395. *
  10396. * @dtopt Options
  10397. * @dtopt Server-side
  10398. * @name DataTable.defaults.ajaxSource
  10399. *
  10400. * @deprecated 1.10. Please use `ajax` for this functionality now.
  10401. */
  10402. "sAjaxSource": null,
  10403. /**
  10404. * This initialisation variable allows you to specify exactly where in the
  10405. * DOM you want DataTables to inject the various controls it adds to the page
  10406. * (for example you might want the pagination controls at the top of the
  10407. * table). DIV elements (with or without a custom class) can also be added to
  10408. * aid styling. The follow syntax is used:
  10409. * <ul>
  10410. * <li>The following options are allowed:
  10411. * <ul>
  10412. * <li>'l' - Length changing</li>
  10413. * <li>'f' - Filtering input</li>
  10414. * <li>'t' - The table!</li>
  10415. * <li>'i' - Information</li>
  10416. * <li>'p' - Pagination</li>
  10417. * <li>'r' - pRocessing</li>
  10418. * </ul>
  10419. * </li>
  10420. * <li>The following constants are allowed:
  10421. * <ul>
  10422. * <li>'H' - jQueryUI theme "header" classes ('fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix')</li>
  10423. * <li>'F' - jQueryUI theme "footer" classes ('fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix')</li>
  10424. * </ul>
  10425. * </li>
  10426. * <li>The following syntax is expected:
  10427. * <ul>
  10428. * <li>'&lt;' and '&gt;' - div elements</li>
  10429. * <li>'&lt;"class" and '&gt;' - div with a class</li>
  10430. * <li>'&lt;"#id" and '&gt;' - div with an ID</li>
  10431. * </ul>
  10432. * </li>
  10433. * <li>Examples:
  10434. * <ul>
  10435. * <li>'&lt;"wrapper"flipt&gt;'</li>
  10436. * <li>'&lt;lf&lt;t&gt;ip&gt;'</li>
  10437. * </ul>
  10438. * </li>
  10439. * </ul>
  10440. * @type string
  10441. * @default lfrtip <i>(when `jQueryUI` is false)</i> <b>or</b>
  10442. * <"H"lfr>t<"F"ip> <i>(when `jQueryUI` is true)</i>
  10443. *
  10444. * @dtopt Options
  10445. * @name DataTable.defaults.dom
  10446. *
  10447. * @example
  10448. * $(document).ready( function() {
  10449. * $('#example').dataTable( {
  10450. * "dom": '&lt;"top"i&gt;rt&lt;"bottom"flp&gt;&lt;"clear"&gt;'
  10451. * } );
  10452. * } );
  10453. */
  10454. "sDom": "lfrtip",
  10455. /**
  10456. * Search delay option. This will throttle full table searches that use the
  10457. * DataTables provided search input element (it does not effect calls to
  10458. * `dt-api search()`, providing a delay before the search is made.
  10459. * @type integer
  10460. * @default 0
  10461. *
  10462. * @dtopt Options
  10463. * @name DataTable.defaults.searchDelay
  10464. *
  10465. * @example
  10466. * $(document).ready( function() {
  10467. * $('#example').dataTable( {
  10468. * "searchDelay": 200
  10469. * } );
  10470. * } )
  10471. */
  10472. "searchDelay": null,
  10473. /**
  10474. * DataTables features six different built-in options for the buttons to
  10475. * display for pagination control:
  10476. *
  10477. * * `numbers` - Page number buttons only
  10478. * * `simple` - 'Previous' and 'Next' buttons only
  10479. * * 'simple_numbers` - 'Previous' and 'Next' buttons, plus page numbers
  10480. * * `full` - 'First', 'Previous', 'Next' and 'Last' buttons
  10481. * * `full_numbers` - 'First', 'Previous', 'Next' and 'Last' buttons, plus page numbers
  10482. * * `first_last_numbers` - 'First' and 'Last' buttons, plus page numbers
  10483. *
  10484. * Further methods can be added using {@link DataTable.ext.oPagination}.
  10485. * @type string
  10486. * @default simple_numbers
  10487. *
  10488. * @dtopt Options
  10489. * @name DataTable.defaults.pagingType
  10490. *
  10491. * @example
  10492. * $(document).ready( function() {
  10493. * $('#example').dataTable( {
  10494. * "pagingType": "full_numbers"
  10495. * } );
  10496. * } )
  10497. */
  10498. "sPaginationType": "simple_numbers",
  10499. /**
  10500. * Enable horizontal scrolling. When a table is too wide to fit into a
  10501. * certain layout, or you have a large number of columns in the table, you
  10502. * can enable x-scrolling to show the table in a viewport, which can be
  10503. * scrolled. This property can be `true` which will allow the table to
  10504. * scroll horizontally when needed, or any CSS unit, or a number (in which
  10505. * case it will be treated as a pixel measurement). Setting as simply `true`
  10506. * is recommended.
  10507. * @type boolean|string
  10508. * @default <i>blank string - i.e. disabled</i>
  10509. *
  10510. * @dtopt Features
  10511. * @name DataTable.defaults.scrollX
  10512. *
  10513. * @example
  10514. * $(document).ready( function() {
  10515. * $('#example').dataTable( {
  10516. * "scrollX": true,
  10517. * "scrollCollapse": true
  10518. * } );
  10519. * } );
  10520. */
  10521. "sScrollX": "",
  10522. /**
  10523. * This property can be used to force a DataTable to use more width than it
  10524. * might otherwise do when x-scrolling is enabled. For example if you have a
  10525. * table which requires to be well spaced, this parameter is useful for
  10526. * "over-sizing" the table, and thus forcing scrolling. This property can by
  10527. * any CSS unit, or a number (in which case it will be treated as a pixel
  10528. * measurement).
  10529. * @type string
  10530. * @default <i>blank string - i.e. disabled</i>
  10531. *
  10532. * @dtopt Options
  10533. * @name DataTable.defaults.scrollXInner
  10534. *
  10535. * @example
  10536. * $(document).ready( function() {
  10537. * $('#example').dataTable( {
  10538. * "scrollX": "100%",
  10539. * "scrollXInner": "110%"
  10540. * } );
  10541. * } );
  10542. */
  10543. "sScrollXInner": "",
  10544. /**
  10545. * Enable vertical scrolling. Vertical scrolling will constrain the DataTable
  10546. * to the given height, and enable scrolling for any data which overflows the
  10547. * current viewport. This can be used as an alternative to paging to display
  10548. * a lot of data in a small area (although paging and scrolling can both be
  10549. * enabled at the same time). This property can be any CSS unit, or a number
  10550. * (in which case it will be treated as a pixel measurement).
  10551. * @type string
  10552. * @default <i>blank string - i.e. disabled</i>
  10553. *
  10554. * @dtopt Features
  10555. * @name DataTable.defaults.scrollY
  10556. *
  10557. * @example
  10558. * $(document).ready( function() {
  10559. * $('#example').dataTable( {
  10560. * "scrollY": "200px",
  10561. * "paginate": false
  10562. * } );
  10563. * } );
  10564. */
  10565. "sScrollY": "",
  10566. /**
  10567. * __Deprecated__ The functionality provided by this parameter has now been
  10568. * superseded by that provided through `ajax`, which should be used instead.
  10569. *
  10570. * Set the HTTP method that is used to make the Ajax call for server-side
  10571. * processing or Ajax sourced data.
  10572. * @type string
  10573. * @default GET
  10574. *
  10575. * @dtopt Options
  10576. * @dtopt Server-side
  10577. * @name DataTable.defaults.serverMethod
  10578. *
  10579. * @deprecated 1.10. Please use `ajax` for this functionality now.
  10580. */
  10581. "sServerMethod": "GET",
  10582. /**
  10583. * DataTables makes use of renderers when displaying HTML elements for
  10584. * a table. These renderers can be added or modified by plug-ins to
  10585. * generate suitable mark-up for a site. For example the Bootstrap
  10586. * integration plug-in for DataTables uses a paging button renderer to
  10587. * display pagination buttons in the mark-up required by Bootstrap.
  10588. *
  10589. * For further information about the renderers available see
  10590. * DataTable.ext.renderer
  10591. * @type string|object
  10592. * @default null
  10593. *
  10594. * @name DataTable.defaults.renderer
  10595. *
  10596. */
  10597. "renderer": null,
  10598. /**
  10599. * Set the data property name that DataTables should use to get a row's id
  10600. * to set as the `id` property in the node.
  10601. * @type string
  10602. * @default DT_RowId
  10603. *
  10604. * @name DataTable.defaults.rowId
  10605. */
  10606. "rowId": "DT_RowId"
  10607. };
  10608. _fnHungarianMap( DataTable.defaults );
  10609. /*
  10610. * Developer note - See note in model.defaults.js about the use of Hungarian
  10611. * notation and camel case.
  10612. */
  10613. /**
  10614. * Column options that can be given to DataTables at initialisation time.
  10615. * @namespace
  10616. */
  10617. DataTable.defaults.column = {
  10618. /**
  10619. * Define which column(s) an order will occur on for this column. This
  10620. * allows a column's ordering to take multiple columns into account when
  10621. * doing a sort or use the data from a different column. For example first
  10622. * name / last name columns make sense to do a multi-column sort over the
  10623. * two columns.
  10624. * @type array|int
  10625. * @default null <i>Takes the value of the column index automatically</i>
  10626. *
  10627. * @name DataTable.defaults.column.orderData
  10628. * @dtopt Columns
  10629. *
  10630. * @example
  10631. * // Using `columnDefs`
  10632. * $(document).ready( function() {
  10633. * $('#example').dataTable( {
  10634. * "columnDefs": [
  10635. * { "orderData": [ 0, 1 ], "targets": [ 0 ] },
  10636. * { "orderData": [ 1, 0 ], "targets": [ 1 ] },
  10637. * { "orderData": 2, "targets": [ 2 ] }
  10638. * ]
  10639. * } );
  10640. * } );
  10641. *
  10642. * @example
  10643. * // Using `columns`
  10644. * $(document).ready( function() {
  10645. * $('#example').dataTable( {
  10646. * "columns": [
  10647. * { "orderData": [ 0, 1 ] },
  10648. * { "orderData": [ 1, 0 ] },
  10649. * { "orderData": 2 },
  10650. * null,
  10651. * null
  10652. * ]
  10653. * } );
  10654. * } );
  10655. */
  10656. "aDataSort": null,
  10657. "iDataSort": -1,
  10658. /**
  10659. * You can control the default ordering direction, and even alter the
  10660. * behaviour of the sort handler (i.e. only allow ascending ordering etc)
  10661. * using this parameter.
  10662. * @type array
  10663. * @default [ 'asc', 'desc' ]
  10664. *
  10665. * @name DataTable.defaults.column.orderSequence
  10666. * @dtopt Columns
  10667. *
  10668. * @example
  10669. * // Using `columnDefs`
  10670. * $(document).ready( function() {
  10671. * $('#example').dataTable( {
  10672. * "columnDefs": [
  10673. * { "orderSequence": [ "asc" ], "targets": [ 1 ] },
  10674. * { "orderSequence": [ "desc", "asc", "asc" ], "targets": [ 2 ] },
  10675. * { "orderSequence": [ "desc" ], "targets": [ 3 ] }
  10676. * ]
  10677. * } );
  10678. * } );
  10679. *
  10680. * @example
  10681. * // Using `columns`
  10682. * $(document).ready( function() {
  10683. * $('#example').dataTable( {
  10684. * "columns": [
  10685. * null,
  10686. * { "orderSequence": [ "asc" ] },
  10687. * { "orderSequence": [ "desc", "asc", "asc" ] },
  10688. * { "orderSequence": [ "desc" ] },
  10689. * null
  10690. * ]
  10691. * } );
  10692. * } );
  10693. */
  10694. "asSorting": [ 'asc', 'desc' ],
  10695. /**
  10696. * Enable or disable filtering on the data in this column.
  10697. * @type boolean
  10698. * @default true
  10699. *
  10700. * @name DataTable.defaults.column.searchable
  10701. * @dtopt Columns
  10702. *
  10703. * @example
  10704. * // Using `columnDefs`
  10705. * $(document).ready( function() {
  10706. * $('#example').dataTable( {
  10707. * "columnDefs": [
  10708. * { "searchable": false, "targets": [ 0 ] }
  10709. * ] } );
  10710. * } );
  10711. *
  10712. * @example
  10713. * // Using `columns`
  10714. * $(document).ready( function() {
  10715. * $('#example').dataTable( {
  10716. * "columns": [
  10717. * { "searchable": false },
  10718. * null,
  10719. * null,
  10720. * null,
  10721. * null
  10722. * ] } );
  10723. * } );
  10724. */
  10725. "bSearchable": true,
  10726. /**
  10727. * Enable or disable ordering on this column.
  10728. * @type boolean
  10729. * @default true
  10730. *
  10731. * @name DataTable.defaults.column.orderable
  10732. * @dtopt Columns
  10733. *
  10734. * @example
  10735. * // Using `columnDefs`
  10736. * $(document).ready( function() {
  10737. * $('#example').dataTable( {
  10738. * "columnDefs": [
  10739. * { "orderable": false, "targets": [ 0 ] }
  10740. * ] } );
  10741. * } );
  10742. *
  10743. * @example
  10744. * // Using `columns`
  10745. * $(document).ready( function() {
  10746. * $('#example').dataTable( {
  10747. * "columns": [
  10748. * { "orderable": false },
  10749. * null,
  10750. * null,
  10751. * null,
  10752. * null
  10753. * ] } );
  10754. * } );
  10755. */
  10756. "bSortable": true,
  10757. /**
  10758. * Enable or disable the display of this column.
  10759. * @type boolean
  10760. * @default true
  10761. *
  10762. * @name DataTable.defaults.column.visible
  10763. * @dtopt Columns
  10764. *
  10765. * @example
  10766. * // Using `columnDefs`
  10767. * $(document).ready( function() {
  10768. * $('#example').dataTable( {
  10769. * "columnDefs": [
  10770. * { "visible": false, "targets": [ 0 ] }
  10771. * ] } );
  10772. * } );
  10773. *
  10774. * @example
  10775. * // Using `columns`
  10776. * $(document).ready( function() {
  10777. * $('#example').dataTable( {
  10778. * "columns": [
  10779. * { "visible": false },
  10780. * null,
  10781. * null,
  10782. * null,
  10783. * null
  10784. * ] } );
  10785. * } );
  10786. */
  10787. "bVisible": true,
  10788. /**
  10789. * Developer definable function that is called whenever a cell is created (Ajax source,
  10790. * etc) or processed for input (DOM source). This can be used as a compliment to mRender
  10791. * allowing you to modify the DOM element (add background colour for example) when the
  10792. * element is available.
  10793. * @type function
  10794. * @param {element} td The TD node that has been created
  10795. * @param {*} cellData The Data for the cell
  10796. * @param {array|object} rowData The data for the whole row
  10797. * @param {int} row The row index for the aoData data store
  10798. * @param {int} col The column index for aoColumns
  10799. *
  10800. * @name DataTable.defaults.column.createdCell
  10801. * @dtopt Columns
  10802. *
  10803. * @example
  10804. * $(document).ready( function() {
  10805. * $('#example').dataTable( {
  10806. * "columnDefs": [ {
  10807. * "targets": [3],
  10808. * "createdCell": function (td, cellData, rowData, row, col) {
  10809. * if ( cellData == "1.7" ) {
  10810. * $(td).css('color', 'blue')
  10811. * }
  10812. * }
  10813. * } ]
  10814. * });
  10815. * } );
  10816. */
  10817. "fnCreatedCell": null,
  10818. /**
  10819. * This parameter has been replaced by `data` in DataTables to ensure naming
  10820. * consistency. `dataProp` can still be used, as there is backwards
  10821. * compatibility in DataTables for this option, but it is strongly
  10822. * recommended that you use `data` in preference to `dataProp`.
  10823. * @name DataTable.defaults.column.dataProp
  10824. */
  10825. /**
  10826. * This property can be used to read data from any data source property,
  10827. * including deeply nested objects / properties. `data` can be given in a
  10828. * number of different ways which effect its behaviour:
  10829. *
  10830. * * `integer` - treated as an array index for the data source. This is the
  10831. * default that DataTables uses (incrementally increased for each column).
  10832. * * `string` - read an object property from the data source. There are
  10833. * three 'special' options that can be used in the string to alter how
  10834. * DataTables reads the data from the source object:
  10835. * * `.` - Dotted Javascript notation. Just as you use a `.` in
  10836. * Javascript to read from nested objects, so to can the options
  10837. * specified in `data`. For example: `browser.version` or
  10838. * `browser.name`. If your object parameter name contains a period, use
  10839. * `\\` to escape it - i.e. `first\\.name`.
  10840. * * `[]` - Array notation. DataTables can automatically combine data
  10841. * from and array source, joining the data with the characters provided
  10842. * between the two brackets. For example: `name[, ]` would provide a
  10843. * comma-space separated list from the source array. If no characters
  10844. * are provided between the brackets, the original array source is
  10845. * returned.
  10846. * * `()` - Function notation. Adding `()` to the end of a parameter will
  10847. * execute a function of the name given. For example: `browser()` for a
  10848. * simple function on the data source, `browser.version()` for a
  10849. * function in a nested property or even `browser().version` to get an
  10850. * object property if the function called returns an object. Note that
  10851. * function notation is recommended for use in `render` rather than
  10852. * `data` as it is much simpler to use as a renderer.
  10853. * * `null` - use the original data source for the row rather than plucking
  10854. * data directly from it. This action has effects on two other
  10855. * initialisation options:
  10856. * * `defaultContent` - When null is given as the `data` option and
  10857. * `defaultContent` is specified for the column, the value defined by
  10858. * `defaultContent` will be used for the cell.
  10859. * * `render` - When null is used for the `data` option and the `render`
  10860. * option is specified for the column, the whole data source for the
  10861. * row is used for the renderer.
  10862. * * `function` - the function given will be executed whenever DataTables
  10863. * needs to set or get the data for a cell in the column. The function
  10864. * takes three parameters:
  10865. * * Parameters:
  10866. * * `{array|object}` The data source for the row
  10867. * * `{string}` The type call data requested - this will be 'set' when
  10868. * setting data or 'filter', 'display', 'type', 'sort' or undefined
  10869. * when gathering data. Note that when `undefined` is given for the
  10870. * type DataTables expects to get the raw data for the object back<
  10871. * * `{*}` Data to set when the second parameter is 'set'.
  10872. * * Return:
  10873. * * The return value from the function is not required when 'set' is
  10874. * the type of call, but otherwise the return is what will be used
  10875. * for the data requested.
  10876. *
  10877. * Note that `data` is a getter and setter option. If you just require
  10878. * formatting of data for output, you will likely want to use `render` which
  10879. * is simply a getter and thus simpler to use.
  10880. *
  10881. * Note that prior to DataTables 1.9.2 `data` was called `mDataProp`. The
  10882. * name change reflects the flexibility of this property and is consistent
  10883. * with the naming of mRender. If 'mDataProp' is given, then it will still
  10884. * be used by DataTables, as it automatically maps the old name to the new
  10885. * if required.
  10886. *
  10887. * @type string|int|function|null
  10888. * @default null <i>Use automatically calculated column index</i>
  10889. *
  10890. * @name DataTable.defaults.column.data
  10891. * @dtopt Columns
  10892. *
  10893. * @example
  10894. * // Read table data from objects
  10895. * // JSON structure for each row:
  10896. * // {
  10897. * // "engine": {value},
  10898. * // "browser": {value},
  10899. * // "platform": {value},
  10900. * // "version": {value},
  10901. * // "grade": {value}
  10902. * // }
  10903. * $(document).ready( function() {
  10904. * $('#example').dataTable( {
  10905. * "ajaxSource": "sources/objects.txt",
  10906. * "columns": [
  10907. * { "data": "engine" },
  10908. * { "data": "browser" },
  10909. * { "data": "platform" },
  10910. * { "data": "version" },
  10911. * { "data": "grade" }
  10912. * ]
  10913. * } );
  10914. * } );
  10915. *
  10916. * @example
  10917. * // Read information from deeply nested objects
  10918. * // JSON structure for each row:
  10919. * // {
  10920. * // "engine": {value},
  10921. * // "browser": {value},
  10922. * // "platform": {
  10923. * // "inner": {value}
  10924. * // },
  10925. * // "details": [
  10926. * // {value}, {value}
  10927. * // ]
  10928. * // }
  10929. * $(document).ready( function() {
  10930. * $('#example').dataTable( {
  10931. * "ajaxSource": "sources/deep.txt",
  10932. * "columns": [
  10933. * { "data": "engine" },
  10934. * { "data": "browser" },
  10935. * { "data": "platform.inner" },
  10936. * { "data": "details.0" },
  10937. * { "data": "details.1" }
  10938. * ]
  10939. * } );
  10940. * } );
  10941. *
  10942. * @example
  10943. * // Using `data` as a function to provide different information for
  10944. * // sorting, filtering and display. In this case, currency (price)
  10945. * $(document).ready( function() {
  10946. * $('#example').dataTable( {
  10947. * "columnDefs": [ {
  10948. * "targets": [ 0 ],
  10949. * "data": function ( source, type, val ) {
  10950. * if (type === 'set') {
  10951. * source.price = val;
  10952. * // Store the computed display and filter values for efficiency
  10953. * source.price_display = val=="" ? "" : "$"+numberFormat(val);
  10954. * source.price_filter = val=="" ? "" : "$"+numberFormat(val)+" "+val;
  10955. * return;
  10956. * }
  10957. * else if (type === 'display') {
  10958. * return source.price_display;
  10959. * }
  10960. * else if (type === 'filter') {
  10961. * return source.price_filter;
  10962. * }
  10963. * // 'sort', 'type' and undefined all just use the integer
  10964. * return source.price;
  10965. * }
  10966. * } ]
  10967. * } );
  10968. * } );
  10969. *
  10970. * @example
  10971. * // Using default content
  10972. * $(document).ready( function() {
  10973. * $('#example').dataTable( {
  10974. * "columnDefs": [ {
  10975. * "targets": [ 0 ],
  10976. * "data": null,
  10977. * "defaultContent": "Click to edit"
  10978. * } ]
  10979. * } );
  10980. * } );
  10981. *
  10982. * @example
  10983. * // Using array notation - outputting a list from an array
  10984. * $(document).ready( function() {
  10985. * $('#example').dataTable( {
  10986. * "columnDefs": [ {
  10987. * "targets": [ 0 ],
  10988. * "data": "name[, ]"
  10989. * } ]
  10990. * } );
  10991. * } );
  10992. *
  10993. */
  10994. "mData": null,
  10995. /**
  10996. * This property is the rendering partner to `data` and it is suggested that
  10997. * when you want to manipulate data for display (including filtering,
  10998. * sorting etc) without altering the underlying data for the table, use this
  10999. * property. `render` can be considered to be the the read only companion to
  11000. * `data` which is read / write (then as such more complex). Like `data`
  11001. * this option can be given in a number of different ways to effect its
  11002. * behaviour:
  11003. *
  11004. * * `integer` - treated as an array index for the data source. This is the
  11005. * default that DataTables uses (incrementally increased for each column).
  11006. * * `string` - read an object property from the data source. There are
  11007. * three 'special' options that can be used in the string to alter how
  11008. * DataTables reads the data from the source object:
  11009. * * `.` - Dotted Javascript notation. Just as you use a `.` in
  11010. * Javascript to read from nested objects, so to can the options
  11011. * specified in `data`. For example: `browser.version` or
  11012. * `browser.name`. If your object parameter name contains a period, use
  11013. * `\\` to escape it - i.e. `first\\.name`.
  11014. * * `[]` - Array notation. DataTables can automatically combine data
  11015. * from and array source, joining the data with the characters provided
  11016. * between the two brackets. For example: `name[, ]` would provide a
  11017. * comma-space separated list from the source array. If no characters
  11018. * are provided between the brackets, the original array source is
  11019. * returned.
  11020. * * `()` - Function notation. Adding `()` to the end of a parameter will
  11021. * execute a function of the name given. For example: `browser()` for a
  11022. * simple function on the data source, `browser.version()` for a
  11023. * function in a nested property or even `browser().version` to get an
  11024. * object property if the function called returns an object.
  11025. * * `object` - use different data for the different data types requested by
  11026. * DataTables ('filter', 'display', 'type' or 'sort'). The property names
  11027. * of the object is the data type the property refers to and the value can
  11028. * defined using an integer, string or function using the same rules as
  11029. * `render` normally does. Note that an `_` option _must_ be specified.
  11030. * This is the default value to use if you haven't specified a value for
  11031. * the data type requested by DataTables.
  11032. * * `function` - the function given will be executed whenever DataTables
  11033. * needs to set or get the data for a cell in the column. The function
  11034. * takes three parameters:
  11035. * * Parameters:
  11036. * * {array|object} The data source for the row (based on `data`)
  11037. * * {string} The type call data requested - this will be 'filter',
  11038. * 'display', 'type' or 'sort'.
  11039. * * {array|object} The full data source for the row (not based on
  11040. * `data`)
  11041. * * Return:
  11042. * * The return value from the function is what will be used for the
  11043. * data requested.
  11044. *
  11045. * @type string|int|function|object|null
  11046. * @default null Use the data source value.
  11047. *
  11048. * @name DataTable.defaults.column.render
  11049. * @dtopt Columns
  11050. *
  11051. * @example
  11052. * // Create a comma separated list from an array of objects
  11053. * $(document).ready( function() {
  11054. * $('#example').dataTable( {
  11055. * "ajaxSource": "sources/deep.txt",
  11056. * "columns": [
  11057. * { "data": "engine" },
  11058. * { "data": "browser" },
  11059. * {
  11060. * "data": "platform",
  11061. * "render": "[, ].name"
  11062. * }
  11063. * ]
  11064. * } );
  11065. * } );
  11066. *
  11067. * @example
  11068. * // Execute a function to obtain data
  11069. * $(document).ready( function() {
  11070. * $('#example').dataTable( {
  11071. * "columnDefs": [ {
  11072. * "targets": [ 0 ],
  11073. * "data": null, // Use the full data source object for the renderer's source
  11074. * "render": "browserName()"
  11075. * } ]
  11076. * } );
  11077. * } );
  11078. *
  11079. * @example
  11080. * // As an object, extracting different data for the different types
  11081. * // This would be used with a data source such as:
  11082. * // { "phone": 5552368, "phone_filter": "5552368 555-2368", "phone_display": "555-2368" }
  11083. * // Here the `phone` integer is used for sorting and type detection, while `phone_filter`
  11084. * // (which has both forms) is used for filtering for if a user inputs either format, while
  11085. * // the formatted phone number is the one that is shown in the table.
  11086. * $(document).ready( function() {
  11087. * $('#example').dataTable( {
  11088. * "columnDefs": [ {
  11089. * "targets": [ 0 ],
  11090. * "data": null, // Use the full data source object for the renderer's source
  11091. * "render": {
  11092. * "_": "phone",
  11093. * "filter": "phone_filter",
  11094. * "display": "phone_display"
  11095. * }
  11096. * } ]
  11097. * } );
  11098. * } );
  11099. *
  11100. * @example
  11101. * // Use as a function to create a link from the data source
  11102. * $(document).ready( function() {
  11103. * $('#example').dataTable( {
  11104. * "columnDefs": [ {
  11105. * "targets": [ 0 ],
  11106. * "data": "download_link",
  11107. * "render": function ( data, type, full ) {
  11108. * return '<a href="'+data+'">Download</a>';
  11109. * }
  11110. * } ]
  11111. * } );
  11112. * } );
  11113. */
  11114. "mRender": null,
  11115. /**
  11116. * Change the cell type created for the column - either TD cells or TH cells. This
  11117. * can be useful as TH cells have semantic meaning in the table body, allowing them
  11118. * to act as a header for a row (you may wish to add scope='row' to the TH elements).
  11119. * @type string
  11120. * @default td
  11121. *
  11122. * @name DataTable.defaults.column.cellType
  11123. * @dtopt Columns
  11124. *
  11125. * @example
  11126. * // Make the first column use TH cells
  11127. * $(document).ready( function() {
  11128. * $('#example').dataTable( {
  11129. * "columnDefs": [ {
  11130. * "targets": [ 0 ],
  11131. * "cellType": "th"
  11132. * } ]
  11133. * } );
  11134. * } );
  11135. */
  11136. "sCellType": "td",
  11137. /**
  11138. * Class to give to each cell in this column.
  11139. * @type string
  11140. * @default <i>Empty string</i>
  11141. *
  11142. * @name DataTable.defaults.column.class
  11143. * @dtopt Columns
  11144. *
  11145. * @example
  11146. * // Using `columnDefs`
  11147. * $(document).ready( function() {
  11148. * $('#example').dataTable( {
  11149. * "columnDefs": [
  11150. * { "class": "my_class", "targets": [ 0 ] }
  11151. * ]
  11152. * } );
  11153. * } );
  11154. *
  11155. * @example
  11156. * // Using `columns`
  11157. * $(document).ready( function() {
  11158. * $('#example').dataTable( {
  11159. * "columns": [
  11160. * { "class": "my_class" },
  11161. * null,
  11162. * null,
  11163. * null,
  11164. * null
  11165. * ]
  11166. * } );
  11167. * } );
  11168. */
  11169. "sClass": "",
  11170. /**
  11171. * When DataTables calculates the column widths to assign to each column,
  11172. * it finds the longest string in each column and then constructs a
  11173. * temporary table and reads the widths from that. The problem with this
  11174. * is that "mmm" is much wider then "iiii", but the latter is a longer
  11175. * string - thus the calculation can go wrong (doing it properly and putting
  11176. * it into an DOM object and measuring that is horribly(!) slow). Thus as
  11177. * a "work around" we provide this option. It will append its value to the
  11178. * text that is found to be the longest string for the column - i.e. padding.
  11179. * Generally you shouldn't need this!
  11180. * @type string
  11181. * @default <i>Empty string<i>
  11182. *
  11183. * @name DataTable.defaults.column.contentPadding
  11184. * @dtopt Columns
  11185. *
  11186. * @example
  11187. * // Using `columns`
  11188. * $(document).ready( function() {
  11189. * $('#example').dataTable( {
  11190. * "columns": [
  11191. * null,
  11192. * null,
  11193. * null,
  11194. * {
  11195. * "contentPadding": "mmm"
  11196. * }
  11197. * ]
  11198. * } );
  11199. * } );
  11200. */
  11201. "sContentPadding": "",
  11202. /**
  11203. * Allows a default value to be given for a column's data, and will be used
  11204. * whenever a null data source is encountered (this can be because `data`
  11205. * is set to null, or because the data source itself is null).
  11206. * @type string
  11207. * @default null
  11208. *
  11209. * @name DataTable.defaults.column.defaultContent
  11210. * @dtopt Columns
  11211. *
  11212. * @example
  11213. * // Using `columnDefs`
  11214. * $(document).ready( function() {
  11215. * $('#example').dataTable( {
  11216. * "columnDefs": [
  11217. * {
  11218. * "data": null,
  11219. * "defaultContent": "Edit",
  11220. * "targets": [ -1 ]
  11221. * }
  11222. * ]
  11223. * } );
  11224. * } );
  11225. *
  11226. * @example
  11227. * // Using `columns`
  11228. * $(document).ready( function() {
  11229. * $('#example').dataTable( {
  11230. * "columns": [
  11231. * null,
  11232. * null,
  11233. * null,
  11234. * {
  11235. * "data": null,
  11236. * "defaultContent": "Edit"
  11237. * }
  11238. * ]
  11239. * } );
  11240. * } );
  11241. */
  11242. "sDefaultContent": null,
  11243. /**
  11244. * This parameter is only used in DataTables' server-side processing. It can
  11245. * be exceptionally useful to know what columns are being displayed on the
  11246. * client side, and to map these to database fields. When defined, the names
  11247. * also allow DataTables to reorder information from the server if it comes
  11248. * back in an unexpected order (i.e. if you switch your columns around on the
  11249. * client-side, your server-side code does not also need updating).
  11250. * @type string
  11251. * @default <i>Empty string</i>
  11252. *
  11253. * @name DataTable.defaults.column.name
  11254. * @dtopt Columns
  11255. *
  11256. * @example
  11257. * // Using `columnDefs`
  11258. * $(document).ready( function() {
  11259. * $('#example').dataTable( {
  11260. * "columnDefs": [
  11261. * { "name": "engine", "targets": [ 0 ] },
  11262. * { "name": "browser", "targets": [ 1 ] },
  11263. * { "name": "platform", "targets": [ 2 ] },
  11264. * { "name": "version", "targets": [ 3 ] },
  11265. * { "name": "grade", "targets": [ 4 ] }
  11266. * ]
  11267. * } );
  11268. * } );
  11269. *
  11270. * @example
  11271. * // Using `columns`
  11272. * $(document).ready( function() {
  11273. * $('#example').dataTable( {
  11274. * "columns": [
  11275. * { "name": "engine" },
  11276. * { "name": "browser" },
  11277. * { "name": "platform" },
  11278. * { "name": "version" },
  11279. * { "name": "grade" }
  11280. * ]
  11281. * } );
  11282. * } );
  11283. */
  11284. "sName": "",
  11285. /**
  11286. * Defines a data source type for the ordering which can be used to read
  11287. * real-time information from the table (updating the internally cached
  11288. * version) prior to ordering. This allows ordering to occur on user
  11289. * editable elements such as form inputs.
  11290. * @type string
  11291. * @default std
  11292. *
  11293. * @name DataTable.defaults.column.orderDataType
  11294. * @dtopt Columns
  11295. *
  11296. * @example
  11297. * // Using `columnDefs`
  11298. * $(document).ready( function() {
  11299. * $('#example').dataTable( {
  11300. * "columnDefs": [
  11301. * { "orderDataType": "dom-text", "targets": [ 2, 3 ] },
  11302. * { "type": "numeric", "targets": [ 3 ] },
  11303. * { "orderDataType": "dom-select", "targets": [ 4 ] },
  11304. * { "orderDataType": "dom-checkbox", "targets": [ 5 ] }
  11305. * ]
  11306. * } );
  11307. * } );
  11308. *
  11309. * @example
  11310. * // Using `columns`
  11311. * $(document).ready( function() {
  11312. * $('#example').dataTable( {
  11313. * "columns": [
  11314. * null,
  11315. * null,
  11316. * { "orderDataType": "dom-text" },
  11317. * { "orderDataType": "dom-text", "type": "numeric" },
  11318. * { "orderDataType": "dom-select" },
  11319. * { "orderDataType": "dom-checkbox" }
  11320. * ]
  11321. * } );
  11322. * } );
  11323. */
  11324. "sSortDataType": "std",
  11325. /**
  11326. * The title of this column.
  11327. * @type string
  11328. * @default null <i>Derived from the 'TH' value for this column in the
  11329. * original HTML table.</i>
  11330. *
  11331. * @name DataTable.defaults.column.title
  11332. * @dtopt Columns
  11333. *
  11334. * @example
  11335. * // Using `columnDefs`
  11336. * $(document).ready( function() {
  11337. * $('#example').dataTable( {
  11338. * "columnDefs": [
  11339. * { "title": "My column title", "targets": [ 0 ] }
  11340. * ]
  11341. * } );
  11342. * } );
  11343. *
  11344. * @example
  11345. * // Using `columns`
  11346. * $(document).ready( function() {
  11347. * $('#example').dataTable( {
  11348. * "columns": [
  11349. * { "title": "My column title" },
  11350. * null,
  11351. * null,
  11352. * null,
  11353. * null
  11354. * ]
  11355. * } );
  11356. * } );
  11357. */
  11358. "sTitle": null,
  11359. /**
  11360. * The type allows you to specify how the data for this column will be
  11361. * ordered. Four types (string, numeric, date and html (which will strip
  11362. * HTML tags before ordering)) are currently available. Note that only date
  11363. * formats understood by Javascript's Date() object will be accepted as type
  11364. * date. For example: "Mar 26, 2008 5:03 PM". May take the values: 'string',
  11365. * 'numeric', 'date' or 'html' (by default). Further types can be adding
  11366. * through plug-ins.
  11367. * @type string
  11368. * @default null <i>Auto-detected from raw data</i>
  11369. *
  11370. * @name DataTable.defaults.column.type
  11371. * @dtopt Columns
  11372. *
  11373. * @example
  11374. * // Using `columnDefs`
  11375. * $(document).ready( function() {
  11376. * $('#example').dataTable( {
  11377. * "columnDefs": [
  11378. * { "type": "html", "targets": [ 0 ] }
  11379. * ]
  11380. * } );
  11381. * } );
  11382. *
  11383. * @example
  11384. * // Using `columns`
  11385. * $(document).ready( function() {
  11386. * $('#example').dataTable( {
  11387. * "columns": [
  11388. * { "type": "html" },
  11389. * null,
  11390. * null,
  11391. * null,
  11392. * null
  11393. * ]
  11394. * } );
  11395. * } );
  11396. */
  11397. "sType": null,
  11398. /**
  11399. * Defining the width of the column, this parameter may take any CSS value
  11400. * (3em, 20px etc). DataTables applies 'smart' widths to columns which have not
  11401. * been given a specific width through this interface ensuring that the table
  11402. * remains readable.
  11403. * @type string
  11404. * @default null <i>Automatic</i>
  11405. *
  11406. * @name DataTable.defaults.column.width
  11407. * @dtopt Columns
  11408. *
  11409. * @example
  11410. * // Using `columnDefs`
  11411. * $(document).ready( function() {
  11412. * $('#example').dataTable( {
  11413. * "columnDefs": [
  11414. * { "width": "20%", "targets": [ 0 ] }
  11415. * ]
  11416. * } );
  11417. * } );
  11418. *
  11419. * @example
  11420. * // Using `columns`
  11421. * $(document).ready( function() {
  11422. * $('#example').dataTable( {
  11423. * "columns": [
  11424. * { "width": "20%" },
  11425. * null,
  11426. * null,
  11427. * null,
  11428. * null
  11429. * ]
  11430. * } );
  11431. * } );
  11432. */
  11433. "sWidth": null
  11434. };
  11435. _fnHungarianMap( DataTable.defaults.column );
  11436. /**
  11437. * DataTables settings object - this holds all the information needed for a
  11438. * given table, including configuration, data and current application of the
  11439. * table options. DataTables does not have a single instance for each DataTable
  11440. * with the settings attached to that instance, but rather instances of the
  11441. * DataTable "class" are created on-the-fly as needed (typically by a
  11442. * $().dataTable() call) and the settings object is then applied to that
  11443. * instance.
  11444. *
  11445. * Note that this object is related to {@link DataTable.defaults} but this
  11446. * one is the internal data store for DataTables's cache of columns. It should
  11447. * NOT be manipulated outside of DataTables. Any configuration should be done
  11448. * through the initialisation options.
  11449. * @namespace
  11450. * @todo Really should attach the settings object to individual instances so we
  11451. * don't need to create new instances on each $().dataTable() call (if the
  11452. * table already exists). It would also save passing oSettings around and
  11453. * into every single function. However, this is a very significant
  11454. * architecture change for DataTables and will almost certainly break
  11455. * backwards compatibility with older installations. This is something that
  11456. * will be done in 2.0.
  11457. */
  11458. DataTable.models.oSettings = {
  11459. /**
  11460. * Primary features of DataTables and their enablement state.
  11461. * @namespace
  11462. */
  11463. "oFeatures": {
  11464. /**
  11465. * Flag to say if DataTables should automatically try to calculate the
  11466. * optimum table and columns widths (true) or not (false).
  11467. * Note that this parameter will be set by the initialisation routine. To
  11468. * set a default use {@link DataTable.defaults}.
  11469. * @type boolean
  11470. */
  11471. "bAutoWidth": null,
  11472. /**
  11473. * Delay the creation of TR and TD elements until they are actually
  11474. * needed by a driven page draw. This can give a significant speed
  11475. * increase for Ajax source and Javascript source data, but makes no
  11476. * difference at all for DOM and server-side processing tables.
  11477. * Note that this parameter will be set by the initialisation routine. To
  11478. * set a default use {@link DataTable.defaults}.
  11479. * @type boolean
  11480. */
  11481. "bDeferRender": null,
  11482. /**
  11483. * Enable filtering on the table or not. Note that if this is disabled
  11484. * then there is no filtering at all on the table, including fnFilter.
  11485. * To just remove the filtering input use sDom and remove the 'f' option.
  11486. * Note that this parameter will be set by the initialisation routine. To
  11487. * set a default use {@link DataTable.defaults}.
  11488. * @type boolean
  11489. */
  11490. "bFilter": null,
  11491. /**
  11492. * Table information element (the 'Showing x of y records' div) enable
  11493. * flag.
  11494. * Note that this parameter will be set by the initialisation routine. To
  11495. * set a default use {@link DataTable.defaults}.
  11496. * @type boolean
  11497. */
  11498. "bInfo": null,
  11499. /**
  11500. * Present a user control allowing the end user to change the page size
  11501. * when pagination is enabled.
  11502. * Note that this parameter will be set by the initialisation routine. To
  11503. * set a default use {@link DataTable.defaults}.
  11504. * @type boolean
  11505. */
  11506. "bLengthChange": null,
  11507. /**
  11508. * Pagination enabled or not. Note that if this is disabled then length
  11509. * changing must also be disabled.
  11510. * Note that this parameter will be set by the initialisation routine. To
  11511. * set a default use {@link DataTable.defaults}.
  11512. * @type boolean
  11513. */
  11514. "bPaginate": null,
  11515. /**
  11516. * Processing indicator enable flag whenever DataTables is enacting a
  11517. * user request - typically an Ajax request for server-side processing.
  11518. * Note that this parameter will be set by the initialisation routine. To
  11519. * set a default use {@link DataTable.defaults}.
  11520. * @type boolean
  11521. */
  11522. "bProcessing": null,
  11523. /**
  11524. * Server-side processing enabled flag - when enabled DataTables will
  11525. * get all data from the server for every draw - there is no filtering,
  11526. * sorting or paging done on the client-side.
  11527. * Note that this parameter will be set by the initialisation routine. To
  11528. * set a default use {@link DataTable.defaults}.
  11529. * @type boolean
  11530. */
  11531. "bServerSide": null,
  11532. /**
  11533. * Sorting enablement flag.
  11534. * Note that this parameter will be set by the initialisation routine. To
  11535. * set a default use {@link DataTable.defaults}.
  11536. * @type boolean
  11537. */
  11538. "bSort": null,
  11539. /**
  11540. * Multi-column sorting
  11541. * Note that this parameter will be set by the initialisation routine. To
  11542. * set a default use {@link DataTable.defaults}.
  11543. * @type boolean
  11544. */
  11545. "bSortMulti": null,
  11546. /**
  11547. * Apply a class to the columns which are being sorted to provide a
  11548. * visual highlight or not. This can slow things down when enabled since
  11549. * there is a lot of DOM interaction.
  11550. * Note that this parameter will be set by the initialisation routine. To
  11551. * set a default use {@link DataTable.defaults}.
  11552. * @type boolean
  11553. */
  11554. "bSortClasses": null,
  11555. /**
  11556. * State saving enablement flag.
  11557. * Note that this parameter will be set by the initialisation routine. To
  11558. * set a default use {@link DataTable.defaults}.
  11559. * @type boolean
  11560. */
  11561. "bStateSave": null
  11562. },
  11563. /**
  11564. * Scrolling settings for a table.
  11565. * @namespace
  11566. */
  11567. "oScroll": {
  11568. /**
  11569. * When the table is shorter in height than sScrollY, collapse the
  11570. * table container down to the height of the table (when true).
  11571. * Note that this parameter will be set by the initialisation routine. To
  11572. * set a default use {@link DataTable.defaults}.
  11573. * @type boolean
  11574. */
  11575. "bCollapse": null,
  11576. /**
  11577. * Width of the scrollbar for the web-browser's platform. Calculated
  11578. * during table initialisation.
  11579. * @type int
  11580. * @default 0
  11581. */
  11582. "iBarWidth": 0,
  11583. /**
  11584. * Viewport width for horizontal scrolling. Horizontal scrolling is
  11585. * disabled if an empty string.
  11586. * Note that this parameter will be set by the initialisation routine. To
  11587. * set a default use {@link DataTable.defaults}.
  11588. * @type string
  11589. */
  11590. "sX": null,
  11591. /**
  11592. * Width to expand the table to when using x-scrolling. Typically you
  11593. * should not need to use this.
  11594. * Note that this parameter will be set by the initialisation routine. To
  11595. * set a default use {@link DataTable.defaults}.
  11596. * @type string
  11597. * @deprecated
  11598. */
  11599. "sXInner": null,
  11600. /**
  11601. * Viewport height for vertical scrolling. Vertical scrolling is disabled
  11602. * if an empty string.
  11603. * Note that this parameter will be set by the initialisation routine. To
  11604. * set a default use {@link DataTable.defaults}.
  11605. * @type string
  11606. */
  11607. "sY": null
  11608. },
  11609. /**
  11610. * Language information for the table.
  11611. * @namespace
  11612. * @extends DataTable.defaults.oLanguage
  11613. */
  11614. "oLanguage": {
  11615. /**
  11616. * Information callback function. See
  11617. * {@link DataTable.defaults.fnInfoCallback}
  11618. * @type function
  11619. * @default null
  11620. */
  11621. "fnInfoCallback": null
  11622. },
  11623. /**
  11624. * Browser support parameters
  11625. * @namespace
  11626. */
  11627. "oBrowser": {
  11628. /**
  11629. * Indicate if the browser incorrectly calculates width:100% inside a
  11630. * scrolling element (IE6/7)
  11631. * @type boolean
  11632. * @default false
  11633. */
  11634. "bScrollOversize": false,
  11635. /**
  11636. * Determine if the vertical scrollbar is on the right or left of the
  11637. * scrolling container - needed for rtl language layout, although not
  11638. * all browsers move the scrollbar (Safari).
  11639. * @type boolean
  11640. * @default false
  11641. */
  11642. "bScrollbarLeft": false,
  11643. /**
  11644. * Flag for if `getBoundingClientRect` is fully supported or not
  11645. * @type boolean
  11646. * @default false
  11647. */
  11648. "bBounding": false,
  11649. /**
  11650. * Browser scrollbar width
  11651. * @type integer
  11652. * @default 0
  11653. */
  11654. "barWidth": 0
  11655. },
  11656. "ajax": null,
  11657. /**
  11658. * Array referencing the nodes which are used for the features. The
  11659. * parameters of this object match what is allowed by sDom - i.e.
  11660. * <ul>
  11661. * <li>'l' - Length changing</li>
  11662. * <li>'f' - Filtering input</li>
  11663. * <li>'t' - The table!</li>
  11664. * <li>'i' - Information</li>
  11665. * <li>'p' - Pagination</li>
  11666. * <li>'r' - pRocessing</li>
  11667. * </ul>
  11668. * @type array
  11669. * @default []
  11670. */
  11671. "aanFeatures": [],
  11672. /**
  11673. * Store data information - see {@link DataTable.models.oRow} for detailed
  11674. * information.
  11675. * @type array
  11676. * @default []
  11677. */
  11678. "aoData": [],
  11679. /**
  11680. * Array of indexes which are in the current display (after filtering etc)
  11681. * @type array
  11682. * @default []
  11683. */
  11684. "aiDisplay": [],
  11685. /**
  11686. * Array of indexes for display - no filtering
  11687. * @type array
  11688. * @default []
  11689. */
  11690. "aiDisplayMaster": [],
  11691. /**
  11692. * Map of row ids to data indexes
  11693. * @type object
  11694. * @default {}
  11695. */
  11696. "aIds": {},
  11697. /**
  11698. * Store information about each column that is in use
  11699. * @type array
  11700. * @default []
  11701. */
  11702. "aoColumns": [],
  11703. /**
  11704. * Store information about the table's header
  11705. * @type array
  11706. * @default []
  11707. */
  11708. "aoHeader": [],
  11709. /**
  11710. * Store information about the table's footer
  11711. * @type array
  11712. * @default []
  11713. */
  11714. "aoFooter": [],
  11715. /**
  11716. * Store the applied global search information in case we want to force a
  11717. * research or compare the old search to a new one.
  11718. * Note that this parameter will be set by the initialisation routine. To
  11719. * set a default use {@link DataTable.defaults}.
  11720. * @namespace
  11721. * @extends DataTable.models.oSearch
  11722. */
  11723. "oPreviousSearch": {},
  11724. /**
  11725. * Store the applied search for each column - see
  11726. * {@link DataTable.models.oSearch} for the format that is used for the
  11727. * filtering information for each column.
  11728. * @type array
  11729. * @default []
  11730. */
  11731. "aoPreSearchCols": [],
  11732. /**
  11733. * Sorting that is applied to the table. Note that the inner arrays are
  11734. * used in the following manner:
  11735. * <ul>
  11736. * <li>Index 0 - column number</li>
  11737. * <li>Index 1 - current sorting direction</li>
  11738. * </ul>
  11739. * Note that this parameter will be set by the initialisation routine. To
  11740. * set a default use {@link DataTable.defaults}.
  11741. * @type array
  11742. * @todo These inner arrays should really be objects
  11743. */
  11744. "aaSorting": null,
  11745. /**
  11746. * Sorting that is always applied to the table (i.e. prefixed in front of
  11747. * aaSorting).
  11748. * Note that this parameter will be set by the initialisation routine. To
  11749. * set a default use {@link DataTable.defaults}.
  11750. * @type array
  11751. * @default []
  11752. */
  11753. "aaSortingFixed": [],
  11754. /**
  11755. * Classes to use for the striping of a table.
  11756. * Note that this parameter will be set by the initialisation routine. To
  11757. * set a default use {@link DataTable.defaults}.
  11758. * @type array
  11759. * @default []
  11760. */
  11761. "asStripeClasses": null,
  11762. /**
  11763. * If restoring a table - we should restore its striping classes as well
  11764. * @type array
  11765. * @default []
  11766. */
  11767. "asDestroyStripes": [],
  11768. /**
  11769. * If restoring a table - we should restore its width
  11770. * @type int
  11771. * @default 0
  11772. */
  11773. "sDestroyWidth": 0,
  11774. /**
  11775. * Callback functions array for every time a row is inserted (i.e. on a draw).
  11776. * @type array
  11777. * @default []
  11778. */
  11779. "aoRowCallback": [],
  11780. /**
  11781. * Callback functions for the header on each draw.
  11782. * @type array
  11783. * @default []
  11784. */
  11785. "aoHeaderCallback": [],
  11786. /**
  11787. * Callback function for the footer on each draw.
  11788. * @type array
  11789. * @default []
  11790. */
  11791. "aoFooterCallback": [],
  11792. /**
  11793. * Array of callback functions for draw callback functions
  11794. * @type array
  11795. * @default []
  11796. */
  11797. "aoDrawCallback": [],
  11798. /**
  11799. * Array of callback functions for row created function
  11800. * @type array
  11801. * @default []
  11802. */
  11803. "aoRowCreatedCallback": [],
  11804. /**
  11805. * Callback functions for just before the table is redrawn. A return of
  11806. * false will be used to cancel the draw.
  11807. * @type array
  11808. * @default []
  11809. */
  11810. "aoPreDrawCallback": [],
  11811. /**
  11812. * Callback functions for when the table has been initialised.
  11813. * @type array
  11814. * @default []
  11815. */
  11816. "aoInitComplete": [],
  11817. /**
  11818. * Callbacks for modifying the settings to be stored for state saving, prior to
  11819. * saving state.
  11820. * @type array
  11821. * @default []
  11822. */
  11823. "aoStateSaveParams": [],
  11824. /**
  11825. * Callbacks for modifying the settings that have been stored for state saving
  11826. * prior to using the stored values to restore the state.
  11827. * @type array
  11828. * @default []
  11829. */
  11830. "aoStateLoadParams": [],
  11831. /**
  11832. * Callbacks for operating on the settings object once the saved state has been
  11833. * loaded
  11834. * @type array
  11835. * @default []
  11836. */
  11837. "aoStateLoaded": [],
  11838. /**
  11839. * Cache the table ID for quick access
  11840. * @type string
  11841. * @default <i>Empty string</i>
  11842. */
  11843. "sTableId": "",
  11844. /**
  11845. * The TABLE node for the main table
  11846. * @type node
  11847. * @default null
  11848. */
  11849. "nTable": null,
  11850. /**
  11851. * Permanent ref to the thead element
  11852. * @type node
  11853. * @default null
  11854. */
  11855. "nTHead": null,
  11856. /**
  11857. * Permanent ref to the tfoot element - if it exists
  11858. * @type node
  11859. * @default null
  11860. */
  11861. "nTFoot": null,
  11862. /**
  11863. * Permanent ref to the tbody element
  11864. * @type node
  11865. * @default null
  11866. */
  11867. "nTBody": null,
  11868. /**
  11869. * Cache the wrapper node (contains all DataTables controlled elements)
  11870. * @type node
  11871. * @default null
  11872. */
  11873. "nTableWrapper": null,
  11874. /**
  11875. * Indicate if when using server-side processing the loading of data
  11876. * should be deferred until the second draw.
  11877. * Note that this parameter will be set by the initialisation routine. To
  11878. * set a default use {@link DataTable.defaults}.
  11879. * @type boolean
  11880. * @default false
  11881. */
  11882. "bDeferLoading": false,
  11883. /**
  11884. * Indicate if all required information has been read in
  11885. * @type boolean
  11886. * @default false
  11887. */
  11888. "bInitialised": false,
  11889. /**
  11890. * Information about open rows. Each object in the array has the parameters
  11891. * 'nTr' and 'nParent'
  11892. * @type array
  11893. * @default []
  11894. */
  11895. "aoOpenRows": [],
  11896. /**
  11897. * Dictate the positioning of DataTables' control elements - see
  11898. * {@link DataTable.model.oInit.sDom}.
  11899. * Note that this parameter will be set by the initialisation routine. To
  11900. * set a default use {@link DataTable.defaults}.
  11901. * @type string
  11902. * @default null
  11903. */
  11904. "sDom": null,
  11905. /**
  11906. * Search delay (in mS)
  11907. * @type integer
  11908. * @default null
  11909. */
  11910. "searchDelay": null,
  11911. /**
  11912. * Which type of pagination should be used.
  11913. * Note that this parameter will be set by the initialisation routine. To
  11914. * set a default use {@link DataTable.defaults}.
  11915. * @type string
  11916. * @default two_button
  11917. */
  11918. "sPaginationType": "two_button",
  11919. /**
  11920. * The state duration (for `stateSave`) in seconds.
  11921. * Note that this parameter will be set by the initialisation routine. To
  11922. * set a default use {@link DataTable.defaults}.
  11923. * @type int
  11924. * @default 0
  11925. */
  11926. "iStateDuration": 0,
  11927. /**
  11928. * Array of callback functions for state saving. Each array element is an
  11929. * object with the following parameters:
  11930. * <ul>
  11931. * <li>function:fn - function to call. Takes two parameters, oSettings
  11932. * and the JSON string to save that has been thus far created. Returns
  11933. * a JSON string to be inserted into a json object
  11934. * (i.e. '"param": [ 0, 1, 2]')</li>
  11935. * <li>string:sName - name of callback</li>
  11936. * </ul>
  11937. * @type array
  11938. * @default []
  11939. */
  11940. "aoStateSave": [],
  11941. /**
  11942. * Array of callback functions for state loading. Each array element is an
  11943. * object with the following parameters:
  11944. * <ul>
  11945. * <li>function:fn - function to call. Takes two parameters, oSettings
  11946. * and the object stored. May return false to cancel state loading</li>
  11947. * <li>string:sName - name of callback</li>
  11948. * </ul>
  11949. * @type array
  11950. * @default []
  11951. */
  11952. "aoStateLoad": [],
  11953. /**
  11954. * State that was saved. Useful for back reference
  11955. * @type object
  11956. * @default null
  11957. */
  11958. "oSavedState": null,
  11959. /**
  11960. * State that was loaded. Useful for back reference
  11961. * @type object
  11962. * @default null
  11963. */
  11964. "oLoadedState": null,
  11965. /**
  11966. * Source url for AJAX data for the table.
  11967. * Note that this parameter will be set by the initialisation routine. To
  11968. * set a default use {@link DataTable.defaults}.
  11969. * @type string
  11970. * @default null
  11971. */
  11972. "sAjaxSource": null,
  11973. /**
  11974. * Property from a given object from which to read the table data from. This
  11975. * can be an empty string (when not server-side processing), in which case
  11976. * it is assumed an an array is given directly.
  11977. * Note that this parameter will be set by the initialisation routine. To
  11978. * set a default use {@link DataTable.defaults}.
  11979. * @type string
  11980. */
  11981. "sAjaxDataProp": null,
  11982. /**
  11983. * The last jQuery XHR object that was used for server-side data gathering.
  11984. * This can be used for working with the XHR information in one of the
  11985. * callbacks
  11986. * @type object
  11987. * @default null
  11988. */
  11989. "jqXHR": null,
  11990. /**
  11991. * JSON returned from the server in the last Ajax request
  11992. * @type object
  11993. * @default undefined
  11994. */
  11995. "json": undefined,
  11996. /**
  11997. * Data submitted as part of the last Ajax request
  11998. * @type object
  11999. * @default undefined
  12000. */
  12001. "oAjaxData": undefined,
  12002. /**
  12003. * Function to get the server-side data.
  12004. * Note that this parameter will be set by the initialisation routine. To
  12005. * set a default use {@link DataTable.defaults}.
  12006. * @type function
  12007. */
  12008. "fnServerData": null,
  12009. /**
  12010. * Functions which are called prior to sending an Ajax request so extra
  12011. * parameters can easily be sent to the server
  12012. * @type array
  12013. * @default []
  12014. */
  12015. "aoServerParams": [],
  12016. /**
  12017. * Send the XHR HTTP method - GET or POST (could be PUT or DELETE if
  12018. * required).
  12019. * Note that this parameter will be set by the initialisation routine. To
  12020. * set a default use {@link DataTable.defaults}.
  12021. * @type string
  12022. */
  12023. "sServerMethod": null,
  12024. /**
  12025. * Format numbers for display.
  12026. * Note that this parameter will be set by the initialisation routine. To
  12027. * set a default use {@link DataTable.defaults}.
  12028. * @type function
  12029. */
  12030. "fnFormatNumber": null,
  12031. /**
  12032. * List of options that can be used for the user selectable length menu.
  12033. * Note that this parameter will be set by the initialisation routine. To
  12034. * set a default use {@link DataTable.defaults}.
  12035. * @type array
  12036. * @default []
  12037. */
  12038. "aLengthMenu": null,
  12039. /**
  12040. * Counter for the draws that the table does. Also used as a tracker for
  12041. * server-side processing
  12042. * @type int
  12043. * @default 0
  12044. */
  12045. "iDraw": 0,
  12046. /**
  12047. * Indicate if a redraw is being done - useful for Ajax
  12048. * @type boolean
  12049. * @default false
  12050. */
  12051. "bDrawing": false,
  12052. /**
  12053. * Draw index (iDraw) of the last error when parsing the returned data
  12054. * @type int
  12055. * @default -1
  12056. */
  12057. "iDrawError": -1,
  12058. /**
  12059. * Paging display length
  12060. * @type int
  12061. * @default 10
  12062. */
  12063. "_iDisplayLength": 10,
  12064. /**
  12065. * Paging start point - aiDisplay index
  12066. * @type int
  12067. * @default 0
  12068. */
  12069. "_iDisplayStart": 0,
  12070. /**
  12071. * Server-side processing - number of records in the result set
  12072. * (i.e. before filtering), Use fnRecordsTotal rather than
  12073. * this property to get the value of the number of records, regardless of
  12074. * the server-side processing setting.
  12075. * @type int
  12076. * @default 0
  12077. * @private
  12078. */
  12079. "_iRecordsTotal": 0,
  12080. /**
  12081. * Server-side processing - number of records in the current display set
  12082. * (i.e. after filtering). Use fnRecordsDisplay rather than
  12083. * this property to get the value of the number of records, regardless of
  12084. * the server-side processing setting.
  12085. * @type boolean
  12086. * @default 0
  12087. * @private
  12088. */
  12089. "_iRecordsDisplay": 0,
  12090. /**
  12091. * The classes to use for the table
  12092. * @type object
  12093. * @default {}
  12094. */
  12095. "oClasses": {},
  12096. /**
  12097. * Flag attached to the settings object so you can check in the draw
  12098. * callback if filtering has been done in the draw. Deprecated in favour of
  12099. * events.
  12100. * @type boolean
  12101. * @default false
  12102. * @deprecated
  12103. */
  12104. "bFiltered": false,
  12105. /**
  12106. * Flag attached to the settings object so you can check in the draw
  12107. * callback if sorting has been done in the draw. Deprecated in favour of
  12108. * events.
  12109. * @type boolean
  12110. * @default false
  12111. * @deprecated
  12112. */
  12113. "bSorted": false,
  12114. /**
  12115. * Indicate that if multiple rows are in the header and there is more than
  12116. * one unique cell per column, if the top one (true) or bottom one (false)
  12117. * should be used for sorting / title by DataTables.
  12118. * Note that this parameter will be set by the initialisation routine. To
  12119. * set a default use {@link DataTable.defaults}.
  12120. * @type boolean
  12121. */
  12122. "bSortCellsTop": null,
  12123. /**
  12124. * Initialisation object that is used for the table
  12125. * @type object
  12126. * @default null
  12127. */
  12128. "oInit": null,
  12129. /**
  12130. * Destroy callback functions - for plug-ins to attach themselves to the
  12131. * destroy so they can clean up markup and events.
  12132. * @type array
  12133. * @default []
  12134. */
  12135. "aoDestroyCallback": [],
  12136. /**
  12137. * Get the number of records in the current record set, before filtering
  12138. * @type function
  12139. */
  12140. "fnRecordsTotal": function ()
  12141. {
  12142. return _fnDataSource( this ) == 'ssp' ?
  12143. this._iRecordsTotal * 1 :
  12144. this.aiDisplayMaster.length;
  12145. },
  12146. /**
  12147. * Get the number of records in the current record set, after filtering
  12148. * @type function
  12149. */
  12150. "fnRecordsDisplay": function ()
  12151. {
  12152. return _fnDataSource( this ) == 'ssp' ?
  12153. this._iRecordsDisplay * 1 :
  12154. this.aiDisplay.length;
  12155. },
  12156. /**
  12157. * Get the display end point - aiDisplay index
  12158. * @type function
  12159. */
  12160. "fnDisplayEnd": function ()
  12161. {
  12162. var
  12163. len = this._iDisplayLength,
  12164. start = this._iDisplayStart,
  12165. calc = start + len,
  12166. records = this.aiDisplay.length,
  12167. features = this.oFeatures,
  12168. paginate = features.bPaginate;
  12169. if ( features.bServerSide ) {
  12170. return paginate === false || len === -1 ?
  12171. start + records :
  12172. Math.min( start+len, this._iRecordsDisplay );
  12173. }
  12174. else {
  12175. return ! paginate || calc>records || len===-1 ?
  12176. records :
  12177. calc;
  12178. }
  12179. },
  12180. /**
  12181. * The DataTables object for this table
  12182. * @type object
  12183. * @default null
  12184. */
  12185. "oInstance": null,
  12186. /**
  12187. * Unique identifier for each instance of the DataTables object. If there
  12188. * is an ID on the table node, then it takes that value, otherwise an
  12189. * incrementing internal counter is used.
  12190. * @type string
  12191. * @default null
  12192. */
  12193. "sInstance": null,
  12194. /**
  12195. * tabindex attribute value that is added to DataTables control elements, allowing
  12196. * keyboard navigation of the table and its controls.
  12197. */
  12198. "iTabIndex": 0,
  12199. /**
  12200. * DIV container for the footer scrolling table if scrolling
  12201. */
  12202. "nScrollHead": null,
  12203. /**
  12204. * DIV container for the footer scrolling table if scrolling
  12205. */
  12206. "nScrollFoot": null,
  12207. /**
  12208. * Last applied sort
  12209. * @type array
  12210. * @default []
  12211. */
  12212. "aLastSort": [],
  12213. /**
  12214. * Stored plug-in instances
  12215. * @type object
  12216. * @default {}
  12217. */
  12218. "oPlugins": {},
  12219. /**
  12220. * Function used to get a row's id from the row's data
  12221. * @type function
  12222. * @default null
  12223. */
  12224. "rowIdFn": null,
  12225. /**
  12226. * Data location where to store a row's id
  12227. * @type string
  12228. * @default null
  12229. */
  12230. "rowId": null
  12231. };
  12232. /**
  12233. * Extension object for DataTables that is used to provide all extension
  12234. * options.
  12235. *
  12236. * Note that the `DataTable.ext` object is available through
  12237. * `jQuery.fn.dataTable.ext` where it may be accessed and manipulated. It is
  12238. * also aliased to `jQuery.fn.dataTableExt` for historic reasons.
  12239. * @namespace
  12240. * @extends DataTable.models.ext
  12241. */
  12242. /**
  12243. * DataTables extensions
  12244. *
  12245. * This namespace acts as a collection area for plug-ins that can be used to
  12246. * extend DataTables capabilities. Indeed many of the build in methods
  12247. * use this method to provide their own capabilities (sorting methods for
  12248. * example).
  12249. *
  12250. * Note that this namespace is aliased to `jQuery.fn.dataTableExt` for legacy
  12251. * reasons
  12252. *
  12253. * @namespace
  12254. */
  12255. DataTable.ext = _ext = {
  12256. /**
  12257. * Buttons. For use with the Buttons extension for DataTables. This is
  12258. * defined here so other extensions can define buttons regardless of load
  12259. * order. It is _not_ used by DataTables core.
  12260. *
  12261. * @type object
  12262. * @default {}
  12263. */
  12264. buttons: {},
  12265. /**
  12266. * Element class names
  12267. *
  12268. * @type object
  12269. * @default {}
  12270. */
  12271. classes: {},
  12272. /**
  12273. * DataTables build type (expanded by the download builder)
  12274. *
  12275. * @type string
  12276. */
  12277. builder: "-source-",
  12278. /**
  12279. * Error reporting.
  12280. *
  12281. * How should DataTables report an error. Can take the value 'alert',
  12282. * 'throw', 'none' or a function.
  12283. *
  12284. * @type string|function
  12285. * @default alert
  12286. */
  12287. errMode: "alert",
  12288. /**
  12289. * Feature plug-ins.
  12290. *
  12291. * This is an array of objects which describe the feature plug-ins that are
  12292. * available to DataTables. These feature plug-ins are then available for
  12293. * use through the `dom` initialisation option.
  12294. *
  12295. * Each feature plug-in is described by an object which must have the
  12296. * following properties:
  12297. *
  12298. * * `fnInit` - function that is used to initialise the plug-in,
  12299. * * `cFeature` - a character so the feature can be enabled by the `dom`
  12300. * instillation option. This is case sensitive.
  12301. *
  12302. * The `fnInit` function has the following input parameters:
  12303. *
  12304. * 1. `{object}` DataTables settings object: see
  12305. * {@link DataTable.models.oSettings}
  12306. *
  12307. * And the following return is expected:
  12308. *
  12309. * * {node|null} The element which contains your feature. Note that the
  12310. * return may also be void if your plug-in does not require to inject any
  12311. * DOM elements into DataTables control (`dom`) - for example this might
  12312. * be useful when developing a plug-in which allows table control via
  12313. * keyboard entry
  12314. *
  12315. * @type array
  12316. *
  12317. * @example
  12318. * $.fn.dataTable.ext.features.push( {
  12319. * "fnInit": function( oSettings ) {
  12320. * return new TableTools( { "oDTSettings": oSettings } );
  12321. * },
  12322. * "cFeature": "T"
  12323. * } );
  12324. */
  12325. feature: [],
  12326. /**
  12327. * Row searching.
  12328. *
  12329. * This method of searching is complimentary to the default type based
  12330. * searching, and a lot more comprehensive as it allows you complete control
  12331. * over the searching logic. Each element in this array is a function
  12332. * (parameters described below) that is called for every row in the table,
  12333. * and your logic decides if it should be included in the searching data set
  12334. * or not.
  12335. *
  12336. * Searching functions have the following input parameters:
  12337. *
  12338. * 1. `{object}` DataTables settings object: see
  12339. * {@link DataTable.models.oSettings}
  12340. * 2. `{array|object}` Data for the row to be processed (same as the
  12341. * original format that was passed in as the data source, or an array
  12342. * from a DOM data source
  12343. * 3. `{int}` Row index ({@link DataTable.models.oSettings.aoData}), which
  12344. * can be useful to retrieve the `TR` element if you need DOM interaction.
  12345. *
  12346. * And the following return is expected:
  12347. *
  12348. * * {boolean} Include the row in the searched result set (true) or not
  12349. * (false)
  12350. *
  12351. * Note that as with the main search ability in DataTables, technically this
  12352. * is "filtering", since it is subtractive. However, for consistency in
  12353. * naming we call it searching here.
  12354. *
  12355. * @type array
  12356. * @default []
  12357. *
  12358. * @example
  12359. * // The following example shows custom search being applied to the
  12360. * // fourth column (i.e. the data[3] index) based on two input values
  12361. * // from the end-user, matching the data in a certain range.
  12362. * $.fn.dataTable.ext.search.push(
  12363. * function( settings, data, dataIndex ) {
  12364. * var min = document.getElementById('min').value * 1;
  12365. * var max = document.getElementById('max').value * 1;
  12366. * var version = data[3] == "-" ? 0 : data[3]*1;
  12367. *
  12368. * if ( min == "" && max == "" ) {
  12369. * return true;
  12370. * }
  12371. * else if ( min == "" && version < max ) {
  12372. * return true;
  12373. * }
  12374. * else if ( min < version && "" == max ) {
  12375. * return true;
  12376. * }
  12377. * else if ( min < version && version < max ) {
  12378. * return true;
  12379. * }
  12380. * return false;
  12381. * }
  12382. * );
  12383. */
  12384. search: [],
  12385. /**
  12386. * Selector extensions
  12387. *
  12388. * The `selector` option can be used to extend the options available for the
  12389. * selector modifier options (`selector-modifier` object data type) that
  12390. * each of the three built in selector types offer (row, column and cell +
  12391. * their plural counterparts). For example the Select extension uses this
  12392. * mechanism to provide an option to select only rows, columns and cells
  12393. * that have been marked as selected by the end user (`{selected: true}`),
  12394. * which can be used in conjunction with the existing built in selector
  12395. * options.
  12396. *
  12397. * Each property is an array to which functions can be pushed. The functions
  12398. * take three attributes:
  12399. *
  12400. * * Settings object for the host table
  12401. * * Options object (`selector-modifier` object type)
  12402. * * Array of selected item indexes
  12403. *
  12404. * The return is an array of the resulting item indexes after the custom
  12405. * selector has been applied.
  12406. *
  12407. * @type object
  12408. */
  12409. selector: {
  12410. cell: [],
  12411. column: [],
  12412. row: []
  12413. },
  12414. /**
  12415. * Internal functions, exposed for used in plug-ins.
  12416. *
  12417. * Please note that you should not need to use the internal methods for
  12418. * anything other than a plug-in (and even then, try to avoid if possible).
  12419. * The internal function may change between releases.
  12420. *
  12421. * @type object
  12422. * @default {}
  12423. */
  12424. internal: {},
  12425. /**
  12426. * Legacy configuration options. Enable and disable legacy options that
  12427. * are available in DataTables.
  12428. *
  12429. * @type object
  12430. */
  12431. legacy: {
  12432. /**
  12433. * Enable / disable DataTables 1.9 compatible server-side processing
  12434. * requests
  12435. *
  12436. * @type boolean
  12437. * @default null
  12438. */
  12439. ajax: null
  12440. },
  12441. /**
  12442. * Pagination plug-in methods.
  12443. *
  12444. * Each entry in this object is a function and defines which buttons should
  12445. * be shown by the pagination rendering method that is used for the table:
  12446. * {@link DataTable.ext.renderer.pageButton}. The renderer addresses how the
  12447. * buttons are displayed in the document, while the functions here tell it
  12448. * what buttons to display. This is done by returning an array of button
  12449. * descriptions (what each button will do).
  12450. *
  12451. * Pagination types (the four built in options and any additional plug-in
  12452. * options defined here) can be used through the `paginationType`
  12453. * initialisation parameter.
  12454. *
  12455. * The functions defined take two parameters:
  12456. *
  12457. * 1. `{int} page` The current page index
  12458. * 2. `{int} pages` The number of pages in the table
  12459. *
  12460. * Each function is expected to return an array where each element of the
  12461. * array can be one of:
  12462. *
  12463. * * `first` - Jump to first page when activated
  12464. * * `last` - Jump to last page when activated
  12465. * * `previous` - Show previous page when activated
  12466. * * `next` - Show next page when activated
  12467. * * `{int}` - Show page of the index given
  12468. * * `{array}` - A nested array containing the above elements to add a
  12469. * containing 'DIV' element (might be useful for styling).
  12470. *
  12471. * Note that DataTables v1.9- used this object slightly differently whereby
  12472. * an object with two functions would be defined for each plug-in. That
  12473. * ability is still supported by DataTables 1.10+ to provide backwards
  12474. * compatibility, but this option of use is now decremented and no longer
  12475. * documented in DataTables 1.10+.
  12476. *
  12477. * @type object
  12478. * @default {}
  12479. *
  12480. * @example
  12481. * // Show previous, next and current page buttons only
  12482. * $.fn.dataTableExt.oPagination.current = function ( page, pages ) {
  12483. * return [ 'previous', page, 'next' ];
  12484. * };
  12485. */
  12486. pager: {},
  12487. renderer: {
  12488. pageButton: {},
  12489. header: {}
  12490. },
  12491. /**
  12492. * Ordering plug-ins - custom data source
  12493. *
  12494. * The extension options for ordering of data available here is complimentary
  12495. * to the default type based ordering that DataTables typically uses. It
  12496. * allows much greater control over the the data that is being used to
  12497. * order a column, but is necessarily therefore more complex.
  12498. *
  12499. * This type of ordering is useful if you want to do ordering based on data
  12500. * live from the DOM (for example the contents of an 'input' element) rather
  12501. * than just the static string that DataTables knows of.
  12502. *
  12503. * The way these plug-ins work is that you create an array of the values you
  12504. * wish to be ordering for the column in question and then return that
  12505. * array. The data in the array much be in the index order of the rows in
  12506. * the table (not the currently ordering order!). Which order data gathering
  12507. * function is run here depends on the `dt-init columns.orderDataType`
  12508. * parameter that is used for the column (if any).
  12509. *
  12510. * The functions defined take two parameters:
  12511. *
  12512. * 1. `{object}` DataTables settings object: see
  12513. * {@link DataTable.models.oSettings}
  12514. * 2. `{int}` Target column index
  12515. *
  12516. * Each function is expected to return an array:
  12517. *
  12518. * * `{array}` Data for the column to be ordering upon
  12519. *
  12520. * @type array
  12521. *
  12522. * @example
  12523. * // Ordering using `input` node values
  12524. * $.fn.dataTable.ext.order['dom-text'] = function ( settings, col )
  12525. * {
  12526. * return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
  12527. * return $('input', td).val();
  12528. * } );
  12529. * }
  12530. */
  12531. order: {},
  12532. /**
  12533. * Type based plug-ins.
  12534. *
  12535. * Each column in DataTables has a type assigned to it, either by automatic
  12536. * detection or by direct assignment using the `type` option for the column.
  12537. * The type of a column will effect how it is ordering and search (plug-ins
  12538. * can also make use of the column type if required).
  12539. *
  12540. * @namespace
  12541. */
  12542. type: {
  12543. /**
  12544. * Type detection functions.
  12545. *
  12546. * The functions defined in this object are used to automatically detect
  12547. * a column's type, making initialisation of DataTables super easy, even
  12548. * when complex data is in the table.
  12549. *
  12550. * The functions defined take two parameters:
  12551. *
  12552. * 1. `{*}` Data from the column cell to be analysed
  12553. * 2. `{settings}` DataTables settings object. This can be used to
  12554. * perform context specific type detection - for example detection
  12555. * based on language settings such as using a comma for a decimal
  12556. * place. Generally speaking the options from the settings will not
  12557. * be required
  12558. *
  12559. * Each function is expected to return:
  12560. *
  12561. * * `{string|null}` Data type detected, or null if unknown (and thus
  12562. * pass it on to the other type detection functions.
  12563. *
  12564. * @type array
  12565. *
  12566. * @example
  12567. * // Currency type detection plug-in:
  12568. * $.fn.dataTable.ext.type.detect.push(
  12569. * function ( data, settings ) {
  12570. * // Check the numeric part
  12571. * if ( ! data.substring(1).match(/[0-9]/) ) {
  12572. * return null;
  12573. * }
  12574. *
  12575. * // Check prefixed by currency
  12576. * if ( data.charAt(0) == '$' || data.charAt(0) == '&pound;' ) {
  12577. * return 'currency';
  12578. * }
  12579. * return null;
  12580. * }
  12581. * );
  12582. */
  12583. detect: [],
  12584. /**
  12585. * Type based search formatting.
  12586. *
  12587. * The type based searching functions can be used to pre-format the
  12588. * data to be search on. For example, it can be used to strip HTML
  12589. * tags or to de-format telephone numbers for numeric only searching.
  12590. *
  12591. * Note that is a search is not defined for a column of a given type,
  12592. * no search formatting will be performed.
  12593. *
  12594. * Pre-processing of searching data plug-ins - When you assign the sType
  12595. * for a column (or have it automatically detected for you by DataTables
  12596. * or a type detection plug-in), you will typically be using this for
  12597. * custom sorting, but it can also be used to provide custom searching
  12598. * by allowing you to pre-processing the data and returning the data in
  12599. * the format that should be searched upon. This is done by adding
  12600. * functions this object with a parameter name which matches the sType
  12601. * for that target column. This is the corollary of <i>afnSortData</i>
  12602. * for searching data.
  12603. *
  12604. * The functions defined take a single parameter:
  12605. *
  12606. * 1. `{*}` Data from the column cell to be prepared for searching
  12607. *
  12608. * Each function is expected to return:
  12609. *
  12610. * * `{string|null}` Formatted string that will be used for the searching.
  12611. *
  12612. * @type object
  12613. * @default {}
  12614. *
  12615. * @example
  12616. * $.fn.dataTable.ext.type.search['title-numeric'] = function ( d ) {
  12617. * return d.replace(/\n/g," ").replace( /<.*?>/g, "" );
  12618. * }
  12619. */
  12620. search: {},
  12621. /**
  12622. * Type based ordering.
  12623. *
  12624. * The column type tells DataTables what ordering to apply to the table
  12625. * when a column is sorted upon. The order for each type that is defined,
  12626. * is defined by the functions available in this object.
  12627. *
  12628. * Each ordering option can be described by three properties added to
  12629. * this object:
  12630. *
  12631. * * `{type}-pre` - Pre-formatting function
  12632. * * `{type}-asc` - Ascending order function
  12633. * * `{type}-desc` - Descending order function
  12634. *
  12635. * All three can be used together, only `{type}-pre` or only
  12636. * `{type}-asc` and `{type}-desc` together. It is generally recommended
  12637. * that only `{type}-pre` is used, as this provides the optimal
  12638. * implementation in terms of speed, although the others are provided
  12639. * for compatibility with existing Javascript sort functions.
  12640. *
  12641. * `{type}-pre`: Functions defined take a single parameter:
  12642. *
  12643. * 1. `{*}` Data from the column cell to be prepared for ordering
  12644. *
  12645. * And return:
  12646. *
  12647. * * `{*}` Data to be sorted upon
  12648. *
  12649. * `{type}-asc` and `{type}-desc`: Functions are typical Javascript sort
  12650. * functions, taking two parameters:
  12651. *
  12652. * 1. `{*}` Data to compare to the second parameter
  12653. * 2. `{*}` Data to compare to the first parameter
  12654. *
  12655. * And returning:
  12656. *
  12657. * * `{*}` Ordering match: <0 if first parameter should be sorted lower
  12658. * than the second parameter, ===0 if the two parameters are equal and
  12659. * >0 if the first parameter should be sorted height than the second
  12660. * parameter.
  12661. *
  12662. * @type object
  12663. * @default {}
  12664. *
  12665. * @example
  12666. * // Numeric ordering of formatted numbers with a pre-formatter
  12667. * $.extend( $.fn.dataTable.ext.type.order, {
  12668. * "string-pre": function(x) {
  12669. * a = (a === "-" || a === "") ? 0 : a.replace( /[^\d\-\.]/g, "" );
  12670. * return parseFloat( a );
  12671. * }
  12672. * } );
  12673. *
  12674. * @example
  12675. * // Case-sensitive string ordering, with no pre-formatting method
  12676. * $.extend( $.fn.dataTable.ext.order, {
  12677. * "string-case-asc": function(x,y) {
  12678. * return ((x < y) ? -1 : ((x > y) ? 1 : 0));
  12679. * },
  12680. * "string-case-desc": function(x,y) {
  12681. * return ((x < y) ? 1 : ((x > y) ? -1 : 0));
  12682. * }
  12683. * } );
  12684. */
  12685. order: {}
  12686. },
  12687. /**
  12688. * Unique DataTables instance counter
  12689. *
  12690. * @type int
  12691. * @private
  12692. */
  12693. _unique: 0,
  12694. //
  12695. // Depreciated
  12696. // The following properties are retained for backwards compatibility only.
  12697. // The should not be used in new projects and will be removed in a future
  12698. // version
  12699. //
  12700. /**
  12701. * Version check function.
  12702. * @type function
  12703. * @depreciated Since 1.10
  12704. */
  12705. fnVersionCheck: DataTable.fnVersionCheck,
  12706. /**
  12707. * Index for what 'this' index API functions should use
  12708. * @type int
  12709. * @deprecated Since v1.10
  12710. */
  12711. iApiIndex: 0,
  12712. /**
  12713. * jQuery UI class container
  12714. * @type object
  12715. * @deprecated Since v1.10
  12716. */
  12717. oJUIClasses: {},
  12718. /**
  12719. * Software version
  12720. * @type string
  12721. * @deprecated Since v1.10
  12722. */
  12723. sVersion: DataTable.version
  12724. };
  12725. //
  12726. // Backwards compatibility. Alias to pre 1.10 Hungarian notation counter parts
  12727. //
  12728. $.extend( _ext, {
  12729. afnFiltering: _ext.search,
  12730. aTypes: _ext.type.detect,
  12731. ofnSearch: _ext.type.search,
  12732. oSort: _ext.type.order,
  12733. afnSortData: _ext.order,
  12734. aoFeatures: _ext.feature,
  12735. oApi: _ext.internal,
  12736. oStdClasses: _ext.classes,
  12737. oPagination: _ext.pager
  12738. } );
  12739. $.extend( DataTable.ext.classes, {
  12740. "sTable": "dataTable",
  12741. "sNoFooter": "no-footer",
  12742. /* Paging buttons */
  12743. "sPageButton": "paginate_button",
  12744. "sPageButtonActive": "current",
  12745. "sPageButtonDisabled": "disabled",
  12746. /* Striping classes */
  12747. "sStripeOdd": "odd",
  12748. "sStripeEven": "even",
  12749. /* Empty row */
  12750. "sRowEmpty": "dataTables_empty",
  12751. /* Features */
  12752. "sWrapper": "dataTables_wrapper",
  12753. "sFilter": "dataTables_filter",
  12754. "sInfo": "dataTables_info",
  12755. "sPaging": "dataTables_paginate paging_", /* Note that the type is postfixed */
  12756. "sLength": "dataTables_length",
  12757. "sProcessing": "dataTables_processing",
  12758. /* Sorting */
  12759. "sSortAsc": "sorting_asc",
  12760. "sSortDesc": "sorting_desc",
  12761. "sSortable": "sorting", /* Sortable in both directions */
  12762. "sSortableAsc": "sorting_desc_disabled",
  12763. "sSortableDesc": "sorting_asc_disabled",
  12764. "sSortableNone": "sorting_disabled",
  12765. "sSortColumn": "sorting_", /* Note that an int is postfixed for the sorting order */
  12766. /* Filtering */
  12767. "sFilterInput": "",
  12768. /* Page length */
  12769. "sLengthSelect": "",
  12770. /* Scrolling */
  12771. "sScrollWrapper": "dataTables_scroll",
  12772. "sScrollHead": "dataTables_scrollHead",
  12773. "sScrollHeadInner": "dataTables_scrollHeadInner",
  12774. "sScrollBody": "dataTables_scrollBody",
  12775. "sScrollFoot": "dataTables_scrollFoot",
  12776. "sScrollFootInner": "dataTables_scrollFootInner",
  12777. /* Misc */
  12778. "sHeaderTH": "",
  12779. "sFooterTH": "",
  12780. // Deprecated
  12781. "sSortJUIAsc": "",
  12782. "sSortJUIDesc": "",
  12783. "sSortJUI": "",
  12784. "sSortJUIAscAllowed": "",
  12785. "sSortJUIDescAllowed": "",
  12786. "sSortJUIWrapper": "",
  12787. "sSortIcon": "",
  12788. "sJUIHeader": "",
  12789. "sJUIFooter": ""
  12790. } );
  12791. var extPagination = DataTable.ext.pager;
  12792. function _numbers ( page, pages ) {
  12793. var
  12794. numbers = [],
  12795. buttons = extPagination.numbers_length,
  12796. half = Math.floor( buttons / 2 ),
  12797. i = 1;
  12798. if ( pages <= buttons ) {
  12799. numbers = _range( 0, pages );
  12800. }
  12801. else if ( page <= half ) {
  12802. numbers = _range( 0, buttons-2 );
  12803. numbers.push( 'ellipsis' );
  12804. numbers.push( pages-1 );
  12805. }
  12806. else if ( page >= pages - 1 - half ) {
  12807. numbers = _range( pages-(buttons-2), pages );
  12808. numbers.splice( 0, 0, 'ellipsis' ); // no unshift in ie6
  12809. numbers.splice( 0, 0, 0 );
  12810. }
  12811. else {
  12812. numbers = _range( page-half+2, page+half-1 );
  12813. numbers.push( 'ellipsis' );
  12814. numbers.push( pages-1 );
  12815. numbers.splice( 0, 0, 'ellipsis' );
  12816. numbers.splice( 0, 0, 0 );
  12817. }
  12818. numbers.DT_el = 'span';
  12819. return numbers;
  12820. }
  12821. $.extend( extPagination, {
  12822. simple: function ( page, pages ) {
  12823. return [ 'previous', 'next' ];
  12824. },
  12825. full: function ( page, pages ) {
  12826. return [ 'first', 'previous', 'next', 'last' ];
  12827. },
  12828. numbers: function ( page, pages ) {
  12829. return [ _numbers(page, pages) ];
  12830. },
  12831. simple_numbers: function ( page, pages ) {
  12832. return [ 'previous', _numbers(page, pages), 'next' ];
  12833. },
  12834. full_numbers: function ( page, pages ) {
  12835. return [ 'first', 'previous', _numbers(page, pages), 'next', 'last' ];
  12836. },
  12837. first_last_numbers: function (page, pages) {
  12838. return ['first', _numbers(page, pages), 'last'];
  12839. },
  12840. // For testing and plug-ins to use
  12841. _numbers: _numbers,
  12842. // Number of number buttons (including ellipsis) to show. _Must be odd!_
  12843. numbers_length: 7
  12844. } );
  12845. $.extend( true, DataTable.ext.renderer, {
  12846. pageButton: {
  12847. _: function ( settings, host, idx, buttons, page, pages ) {
  12848. var classes = settings.oClasses;
  12849. var lang = settings.oLanguage.oPaginate;
  12850. var aria = settings.oLanguage.oAria.paginate || {};
  12851. var btnDisplay, btnClass;
  12852. var attach = function( container, buttons ) {
  12853. var i, ien, node, button, tabIndex;
  12854. var disabledClass = classes.sPageButtonDisabled;
  12855. var clickHandler = function ( e ) {
  12856. _fnPageChange( settings, e.data.action, true );
  12857. };
  12858. for ( i=0, ien=buttons.length ; i<ien ; i++ ) {
  12859. button = buttons[i];
  12860. if ( Array.isArray( button ) ) {
  12861. var inner = $( '<'+(button.DT_el || 'div')+'/>' )
  12862. .appendTo( container );
  12863. attach( inner, button );
  12864. }
  12865. else {
  12866. btnDisplay = null;
  12867. btnClass = button;
  12868. tabIndex = settings.iTabIndex;
  12869. switch ( button ) {
  12870. case 'ellipsis':
  12871. container.append('<span class="ellipsis">&#x2026;</span>');
  12872. break;
  12873. case 'first':
  12874. btnDisplay = lang.sFirst;
  12875. if ( page === 0 ) {
  12876. tabIndex = -1;
  12877. btnClass += ' ' + disabledClass;
  12878. }
  12879. break;
  12880. case 'previous':
  12881. btnDisplay = lang.sPrevious;
  12882. if ( page === 0 ) {
  12883. tabIndex = -1;
  12884. btnClass += ' ' + disabledClass;
  12885. }
  12886. break;
  12887. case 'next':
  12888. btnDisplay = lang.sNext;
  12889. if ( pages === 0 || page === pages-1 ) {
  12890. tabIndex = -1;
  12891. btnClass += ' ' + disabledClass;
  12892. }
  12893. break;
  12894. case 'last':
  12895. btnDisplay = lang.sLast;
  12896. if ( pages === 0 || page === pages-1 ) {
  12897. tabIndex = -1;
  12898. btnClass += ' ' + disabledClass;
  12899. }
  12900. break;
  12901. default:
  12902. btnDisplay = settings.fnFormatNumber( button + 1 );
  12903. btnClass = page === button ?
  12904. classes.sPageButtonActive : '';
  12905. break;
  12906. }
  12907. if ( btnDisplay !== null ) {
  12908. var tag = settings.oInit.pagingTag || 'a';
  12909. var disabled = btnClass.indexOf(disabledClass) !== -1;
  12910. node = $('<'+tag+'>', {
  12911. 'class': classes.sPageButton+' '+btnClass,
  12912. 'aria-controls': settings.sTableId,
  12913. 'aria-disabled': disabled ? 'true' : null,
  12914. 'aria-label': aria[ button ],
  12915. 'role': 'link',
  12916. 'aria-current': btnClass === classes.sPageButtonActive ? 'page' : null,
  12917. 'data-dt-idx': button,
  12918. 'tabindex': tabIndex,
  12919. 'id': idx === 0 && typeof button === 'string' ?
  12920. settings.sTableId +'_'+ button :
  12921. null
  12922. } )
  12923. .html( btnDisplay )
  12924. .appendTo( container );
  12925. _fnBindAction(
  12926. node, {action: button}, clickHandler
  12927. );
  12928. }
  12929. }
  12930. }
  12931. };
  12932. // IE9 throws an 'unknown error' if document.activeElement is used
  12933. // inside an iframe or frame. Try / catch the error. Not good for
  12934. // accessibility, but neither are frames.
  12935. var activeEl;
  12936. try {
  12937. // Because this approach is destroying and recreating the paging
  12938. // elements, focus is lost on the select button which is bad for
  12939. // accessibility. So we want to restore focus once the draw has
  12940. // completed
  12941. activeEl = $(host).find(document.activeElement).data('dt-idx');
  12942. }
  12943. catch (e) {}
  12944. attach( $(host).empty(), buttons );
  12945. if ( activeEl !== undefined ) {
  12946. $(host).find( '[data-dt-idx='+activeEl+']' ).trigger('focus');
  12947. }
  12948. }
  12949. }
  12950. } );
  12951. // Built in type detection. See model.ext.aTypes for information about
  12952. // what is required from this methods.
  12953. $.extend( DataTable.ext.type.detect, [
  12954. // Plain numbers - first since V8 detects some plain numbers as dates
  12955. // e.g. Date.parse('55') (but not all, e.g. Date.parse('22')...).
  12956. function ( d, settings )
  12957. {
  12958. var decimal = settings.oLanguage.sDecimal;
  12959. return _isNumber( d, decimal ) ? 'num'+decimal : null;
  12960. },
  12961. // Dates (only those recognised by the browser's Date.parse)
  12962. function ( d, settings )
  12963. {
  12964. // V8 tries _very_ hard to make a string passed into `Date.parse()`
  12965. // valid, so we need to use a regex to restrict date formats. Use a
  12966. // plug-in for anything other than ISO8601 style strings
  12967. if ( d && !(d instanceof Date) && ! _re_date.test(d) ) {
  12968. return null;
  12969. }
  12970. var parsed = Date.parse(d);
  12971. return (parsed !== null && !isNaN(parsed)) || _empty(d) ? 'date' : null;
  12972. },
  12973. // Formatted numbers
  12974. function ( d, settings )
  12975. {
  12976. var decimal = settings.oLanguage.sDecimal;
  12977. return _isNumber( d, decimal, true ) ? 'num-fmt'+decimal : null;
  12978. },
  12979. // HTML numeric
  12980. function ( d, settings )
  12981. {
  12982. var decimal = settings.oLanguage.sDecimal;
  12983. return _htmlNumeric( d, decimal ) ? 'html-num'+decimal : null;
  12984. },
  12985. // HTML numeric, formatted
  12986. function ( d, settings )
  12987. {
  12988. var decimal = settings.oLanguage.sDecimal;
  12989. return _htmlNumeric( d, decimal, true ) ? 'html-num-fmt'+decimal : null;
  12990. },
  12991. // HTML (this is strict checking - there must be html)
  12992. function ( d, settings )
  12993. {
  12994. return _empty( d ) || (typeof d === 'string' && d.indexOf('<') !== -1) ?
  12995. 'html' : null;
  12996. }
  12997. ] );
  12998. // Filter formatting functions. See model.ext.ofnSearch for information about
  12999. // what is required from these methods.
  13000. //
  13001. // Note that additional search methods are added for the html numbers and
  13002. // html formatted numbers by `_addNumericSort()` when we know what the decimal
  13003. // place is
  13004. $.extend( DataTable.ext.type.search, {
  13005. html: function ( data ) {
  13006. return _empty(data) ?
  13007. data :
  13008. typeof data === 'string' ?
  13009. data
  13010. .replace( _re_new_lines, " " )
  13011. .replace( _re_html, "" ) :
  13012. '';
  13013. },
  13014. string: function ( data ) {
  13015. return _empty(data) ?
  13016. data :
  13017. typeof data === 'string' ?
  13018. data.replace( _re_new_lines, " " ) :
  13019. data;
  13020. }
  13021. } );
  13022. var __numericReplace = function ( d, decimalPlace, re1, re2 ) {
  13023. if ( d !== 0 && (!d || d === '-') ) {
  13024. return -Infinity;
  13025. }
  13026. var type = typeof d;
  13027. if (type === 'number' || type === 'bigint') {
  13028. return d;
  13029. }
  13030. // If a decimal place other than `.` is used, it needs to be given to the
  13031. // function so we can detect it and replace with a `.` which is the only
  13032. // decimal place Javascript recognises - it is not locale aware.
  13033. if ( decimalPlace ) {
  13034. d = _numToDecimal( d, decimalPlace );
  13035. }
  13036. if ( d.replace ) {
  13037. if ( re1 ) {
  13038. d = d.replace( re1, '' );
  13039. }
  13040. if ( re2 ) {
  13041. d = d.replace( re2, '' );
  13042. }
  13043. }
  13044. return d * 1;
  13045. };
  13046. // Add the numeric 'deformatting' functions for sorting and search. This is done
  13047. // in a function to provide an easy ability for the language options to add
  13048. // additional methods if a non-period decimal place is used.
  13049. function _addNumericSort ( decimalPlace ) {
  13050. $.each(
  13051. {
  13052. // Plain numbers
  13053. "num": function ( d ) {
  13054. return __numericReplace( d, decimalPlace );
  13055. },
  13056. // Formatted numbers
  13057. "num-fmt": function ( d ) {
  13058. return __numericReplace( d, decimalPlace, _re_formatted_numeric );
  13059. },
  13060. // HTML numeric
  13061. "html-num": function ( d ) {
  13062. return __numericReplace( d, decimalPlace, _re_html );
  13063. },
  13064. // HTML numeric, formatted
  13065. "html-num-fmt": function ( d ) {
  13066. return __numericReplace( d, decimalPlace, _re_html, _re_formatted_numeric );
  13067. }
  13068. },
  13069. function ( key, fn ) {
  13070. // Add the ordering method
  13071. _ext.type.order[ key+decimalPlace+'-pre' ] = fn;
  13072. // For HTML types add a search formatter that will strip the HTML
  13073. if ( key.match(/^html\-/) ) {
  13074. _ext.type.search[ key+decimalPlace ] = _ext.type.search.html;
  13075. }
  13076. }
  13077. );
  13078. }
  13079. // Default sort methods
  13080. $.extend( _ext.type.order, {
  13081. // Dates
  13082. "date-pre": function ( d ) {
  13083. var ts = Date.parse( d );
  13084. return isNaN(ts) ? -Infinity : ts;
  13085. },
  13086. // html
  13087. "html-pre": function ( a ) {
  13088. return _empty(a) ?
  13089. '' :
  13090. a.replace ?
  13091. a.replace( /<.*?>/g, "" ).toLowerCase() :
  13092. a+'';
  13093. },
  13094. // string
  13095. "string-pre": function ( a ) {
  13096. // This is a little complex, but faster than always calling toString,
  13097. // http://jsperf.com/tostring-v-check
  13098. return _empty(a) ?
  13099. '' :
  13100. typeof a === 'string' ?
  13101. a.toLowerCase() :
  13102. ! a.toString ?
  13103. '' :
  13104. a.toString();
  13105. },
  13106. // string-asc and -desc are retained only for compatibility with the old
  13107. // sort methods
  13108. "string-asc": function ( x, y ) {
  13109. return ((x < y) ? -1 : ((x > y) ? 1 : 0));
  13110. },
  13111. "string-desc": function ( x, y ) {
  13112. return ((x < y) ? 1 : ((x > y) ? -1 : 0));
  13113. }
  13114. } );
  13115. // Numeric sorting types - order doesn't matter here
  13116. _addNumericSort( '' );
  13117. $.extend( true, DataTable.ext.renderer, {
  13118. header: {
  13119. _: function ( settings, cell, column, classes ) {
  13120. // No additional mark-up required
  13121. // Attach a sort listener to update on sort - note that using the
  13122. // `DT` namespace will allow the event to be removed automatically
  13123. // on destroy, while the `dt` namespaced event is the one we are
  13124. // listening for
  13125. $(settings.nTable).on( 'order.dt.DT', function ( e, ctx, sorting, columns ) {
  13126. if ( settings !== ctx ) { // need to check this this is the host
  13127. return; // table, not a nested one
  13128. }
  13129. var colIdx = column.idx;
  13130. cell
  13131. .removeClass(
  13132. classes.sSortAsc +' '+
  13133. classes.sSortDesc
  13134. )
  13135. .addClass( columns[ colIdx ] == 'asc' ?
  13136. classes.sSortAsc : columns[ colIdx ] == 'desc' ?
  13137. classes.sSortDesc :
  13138. column.sSortingClass
  13139. );
  13140. } );
  13141. },
  13142. jqueryui: function ( settings, cell, column, classes ) {
  13143. $('<div/>')
  13144. .addClass( classes.sSortJUIWrapper )
  13145. .append( cell.contents() )
  13146. .append( $('<span/>')
  13147. .addClass( classes.sSortIcon+' '+column.sSortingClassJUI )
  13148. )
  13149. .appendTo( cell );
  13150. // Attach a sort listener to update on sort
  13151. $(settings.nTable).on( 'order.dt.DT', function ( e, ctx, sorting, columns ) {
  13152. if ( settings !== ctx ) {
  13153. return;
  13154. }
  13155. var colIdx = column.idx;
  13156. cell
  13157. .removeClass( classes.sSortAsc +" "+classes.sSortDesc )
  13158. .addClass( columns[ colIdx ] == 'asc' ?
  13159. classes.sSortAsc : columns[ colIdx ] == 'desc' ?
  13160. classes.sSortDesc :
  13161. column.sSortingClass
  13162. );
  13163. cell
  13164. .find( 'span.'+classes.sSortIcon )
  13165. .removeClass(
  13166. classes.sSortJUIAsc +" "+
  13167. classes.sSortJUIDesc +" "+
  13168. classes.sSortJUI +" "+
  13169. classes.sSortJUIAscAllowed +" "+
  13170. classes.sSortJUIDescAllowed
  13171. )
  13172. .addClass( columns[ colIdx ] == 'asc' ?
  13173. classes.sSortJUIAsc : columns[ colIdx ] == 'desc' ?
  13174. classes.sSortJUIDesc :
  13175. column.sSortingClassJUI
  13176. );
  13177. } );
  13178. }
  13179. }
  13180. } );
  13181. /*
  13182. * Public helper functions. These aren't used internally by DataTables, or
  13183. * called by any of the options passed into DataTables, but they can be used
  13184. * externally by developers working with DataTables. They are helper functions
  13185. * to make working with DataTables a little bit easier.
  13186. */
  13187. var __htmlEscapeEntities = function ( d ) {
  13188. if (Array.isArray(d)) {
  13189. d = d.join(',');
  13190. }
  13191. return typeof d === 'string' ?
  13192. d
  13193. .replace(/&/g, '&amp;')
  13194. .replace(/</g, '&lt;')
  13195. .replace(/>/g, '&gt;')
  13196. .replace(/"/g, '&quot;') :
  13197. d;
  13198. };
  13199. // Common logic for moment, luxon or a date action
  13200. function __mld( dt, momentFn, luxonFn, dateFn, arg1 ) {
  13201. if (window.moment) {
  13202. return dt[momentFn]( arg1 );
  13203. }
  13204. else if (window.luxon) {
  13205. return dt[luxonFn]( arg1 );
  13206. }
  13207. return dateFn ? dt[dateFn]( arg1 ) : dt;
  13208. }
  13209. var __mlWarning = false;
  13210. function __mldObj (d, format, locale) {
  13211. var dt;
  13212. if (window.moment) {
  13213. dt = window.moment.utc( d, format, locale, true );
  13214. if (! dt.isValid()) {
  13215. return null;
  13216. }
  13217. }
  13218. else if (window.luxon) {
  13219. dt = format && typeof d === 'string'
  13220. ? window.luxon.DateTime.fromFormat( d, format )
  13221. : window.luxon.DateTime.fromISO( d );
  13222. if (! dt.isValid) {
  13223. return null;
  13224. }
  13225. dt.setLocale(locale);
  13226. }
  13227. else if (! format) {
  13228. // No format given, must be ISO
  13229. dt = new Date(d);
  13230. }
  13231. else {
  13232. if (! __mlWarning) {
  13233. alert('DataTables warning: Formatted date without Moment.js or Luxon - https://datatables.net/tn/17');
  13234. }
  13235. __mlWarning = true;
  13236. }
  13237. return dt;
  13238. }
  13239. // Wrapper for date, datetime and time which all operate the same way with the exception of
  13240. // the output string for auto locale support
  13241. function __mlHelper (localeString) {
  13242. return function ( from, to, locale, def ) {
  13243. // Luxon and Moment support
  13244. // Argument shifting
  13245. if ( arguments.length === 0 ) {
  13246. locale = 'en';
  13247. to = null; // means toLocaleString
  13248. from = null; // means iso8601
  13249. }
  13250. else if ( arguments.length === 1 ) {
  13251. locale = 'en';
  13252. to = from;
  13253. from = null;
  13254. }
  13255. else if ( arguments.length === 2 ) {
  13256. locale = to;
  13257. to = from;
  13258. from = null;
  13259. }
  13260. var typeName = 'datetime-' + to;
  13261. // Add type detection and sorting specific to this date format - we need to be able to identify
  13262. // date type columns as such, rather than as numbers in extensions. Hence the need for this.
  13263. if (! DataTable.ext.type.order[typeName]) {
  13264. // The renderer will give the value to type detect as the type!
  13265. DataTable.ext.type.detect.unshift(function (d) {
  13266. return d === typeName ? typeName : false;
  13267. });
  13268. // The renderer gives us Moment, Luxon or Date obects for the sorting, all of which have a
  13269. // `valueOf` which gives milliseconds epoch
  13270. DataTable.ext.type.order[typeName + '-asc'] = function (a, b) {
  13271. var x = a.valueOf();
  13272. var y = b.valueOf();
  13273. return x === y
  13274. ? 0
  13275. : x < y
  13276. ? -1
  13277. : 1;
  13278. }
  13279. DataTable.ext.type.order[typeName + '-desc'] = function (a, b) {
  13280. var x = a.valueOf();
  13281. var y = b.valueOf();
  13282. return x === y
  13283. ? 0
  13284. : x > y
  13285. ? -1
  13286. : 1;
  13287. }
  13288. }
  13289. return function ( d, type ) {
  13290. // Allow for a default value
  13291. if (d === null || d === undefined) {
  13292. if (def === '--now') {
  13293. // We treat everything as UTC further down, so no changes are
  13294. // made, as such need to get the local date / time as if it were
  13295. // UTC
  13296. var local = new Date();
  13297. d = new Date( Date.UTC(
  13298. local.getFullYear(), local.getMonth(), local.getDate(),
  13299. local.getHours(), local.getMinutes(), local.getSeconds()
  13300. ) );
  13301. }
  13302. else {
  13303. d = '';
  13304. }
  13305. }
  13306. if (type === 'type') {
  13307. // Typing uses the type name for fast matching
  13308. return typeName;
  13309. }
  13310. if (d === '') {
  13311. return type !== 'sort'
  13312. ? ''
  13313. : __mldObj('0000-01-01 00:00:00', null, locale);
  13314. }
  13315. // Shortcut. If `from` and `to` are the same, we are using the renderer to
  13316. // format for ordering, not display - its already in the display format.
  13317. if ( to !== null && from === to && type !== 'sort' && type !== 'type' && ! (d instanceof Date) ) {
  13318. return d;
  13319. }
  13320. var dt = __mldObj(d, from, locale);
  13321. if (dt === null) {
  13322. return d;
  13323. }
  13324. if (type === 'sort') {
  13325. return dt;
  13326. }
  13327. var formatted = to === null
  13328. ? __mld(dt, 'toDate', 'toJSDate', '')[localeString]()
  13329. : __mld(dt, 'format', 'toFormat', 'toISOString', to);
  13330. // XSS protection
  13331. return type === 'display' ?
  13332. __htmlEscapeEntities( formatted ) :
  13333. formatted;
  13334. };
  13335. }
  13336. }
  13337. // Based on locale, determine standard number formatting
  13338. // Fallback for legacy browsers is US English
  13339. var __thousands = ',';
  13340. var __decimal = '.';
  13341. if (window.Intl !== undefined) {
  13342. try {
  13343. var num = new Intl.NumberFormat().formatToParts(100000.1);
  13344. for (var i=0 ; i<num.length ; i++) {
  13345. if (num[i].type === 'group') {
  13346. __thousands = num[i].value;
  13347. }
  13348. else if (num[i].type === 'decimal') {
  13349. __decimal = num[i].value;
  13350. }
  13351. }
  13352. }
  13353. catch (e) {
  13354. // noop
  13355. }
  13356. }
  13357. // Formatted date time detection - use by declaring the formats you are going to use
  13358. DataTable.datetime = function ( format, locale ) {
  13359. var typeName = 'datetime-detect-' + format;
  13360. if (! locale) {
  13361. locale = 'en';
  13362. }
  13363. if (! DataTable.ext.type.order[typeName]) {
  13364. DataTable.ext.type.detect.unshift(function (d) {
  13365. var dt = __mldObj(d, format, locale);
  13366. return d === '' || dt ? typeName : false;
  13367. });
  13368. DataTable.ext.type.order[typeName + '-pre'] = function (d) {
  13369. return __mldObj(d, format, locale) || 0;
  13370. }
  13371. }
  13372. }
  13373. /**
  13374. * Helpers for `columns.render`.
  13375. *
  13376. * The options defined here can be used with the `columns.render` initialisation
  13377. * option to provide a display renderer. The following functions are defined:
  13378. *
  13379. * * `number` - Will format numeric data (defined by `columns.data`) for
  13380. * display, retaining the original unformatted data for sorting and filtering.
  13381. * It takes 5 parameters:
  13382. * * `string` - Thousands grouping separator
  13383. * * `string` - Decimal point indicator
  13384. * * `integer` - Number of decimal points to show
  13385. * * `string` (optional) - Prefix.
  13386. * * `string` (optional) - Postfix (/suffix).
  13387. * * `text` - Escape HTML to help prevent XSS attacks. It has no optional
  13388. * parameters.
  13389. *
  13390. * @example
  13391. * // Column definition using the number renderer
  13392. * {
  13393. * data: "salary",
  13394. * render: $.fn.dataTable.render.number( '\'', '.', 0, '$' )
  13395. * }
  13396. *
  13397. * @namespace
  13398. */
  13399. DataTable.render = {
  13400. date: __mlHelper('toLocaleDateString'),
  13401. datetime: __mlHelper('toLocaleString'),
  13402. time: __mlHelper('toLocaleTimeString'),
  13403. number: function ( thousands, decimal, precision, prefix, postfix ) {
  13404. // Auto locale detection
  13405. if (thousands === null || thousands === undefined) {
  13406. thousands = __thousands;
  13407. }
  13408. if (decimal === null || decimal === undefined) {
  13409. decimal = __decimal;
  13410. }
  13411. return {
  13412. display: function ( d ) {
  13413. if ( typeof d !== 'number' && typeof d !== 'string' ) {
  13414. return d;
  13415. }
  13416. if (d === '' || d === null) {
  13417. return d;
  13418. }
  13419. var negative = d < 0 ? '-' : '';
  13420. var flo = parseFloat( d );
  13421. // If NaN then there isn't much formatting that we can do - just
  13422. // return immediately, escaping any HTML (this was supposed to
  13423. // be a number after all)
  13424. if ( isNaN( flo ) ) {
  13425. return __htmlEscapeEntities( d );
  13426. }
  13427. flo = flo.toFixed( precision );
  13428. d = Math.abs( flo );
  13429. var intPart = parseInt( d, 10 );
  13430. var floatPart = precision ?
  13431. decimal+(d - intPart).toFixed( precision ).substring( 2 ):
  13432. '';
  13433. // If zero, then can't have a negative prefix
  13434. if (intPart === 0 && parseFloat(floatPart) === 0) {
  13435. negative = '';
  13436. }
  13437. return negative + (prefix||'') +
  13438. intPart.toString().replace(
  13439. /\B(?=(\d{3})+(?!\d))/g, thousands
  13440. ) +
  13441. floatPart +
  13442. (postfix||'');
  13443. }
  13444. };
  13445. },
  13446. text: function () {
  13447. return {
  13448. display: __htmlEscapeEntities,
  13449. filter: __htmlEscapeEntities
  13450. };
  13451. }
  13452. };
  13453. /*
  13454. * This is really a good bit rubbish this method of exposing the internal methods
  13455. * publicly... - To be fixed in 2.0 using methods on the prototype
  13456. */
  13457. /**
  13458. * Create a wrapper function for exporting an internal functions to an external API.
  13459. * @param {string} fn API function name
  13460. * @returns {function} wrapped function
  13461. * @memberof DataTable#internal
  13462. */
  13463. function _fnExternApiFunc (fn)
  13464. {
  13465. return function() {
  13466. var args = [_fnSettingsFromNode( this[DataTable.ext.iApiIndex] )].concat(
  13467. Array.prototype.slice.call(arguments)
  13468. );
  13469. return DataTable.ext.internal[fn].apply( this, args );
  13470. };
  13471. }
  13472. /**
  13473. * Reference to internal functions for use by plug-in developers. Note that
  13474. * these methods are references to internal functions and are considered to be
  13475. * private. If you use these methods, be aware that they are liable to change
  13476. * between versions.
  13477. * @namespace
  13478. */
  13479. $.extend( DataTable.ext.internal, {
  13480. _fnExternApiFunc: _fnExternApiFunc,
  13481. _fnBuildAjax: _fnBuildAjax,
  13482. _fnAjaxUpdate: _fnAjaxUpdate,
  13483. _fnAjaxParameters: _fnAjaxParameters,
  13484. _fnAjaxUpdateDraw: _fnAjaxUpdateDraw,
  13485. _fnAjaxDataSrc: _fnAjaxDataSrc,
  13486. _fnAddColumn: _fnAddColumn,
  13487. _fnColumnOptions: _fnColumnOptions,
  13488. _fnAdjustColumnSizing: _fnAdjustColumnSizing,
  13489. _fnVisibleToColumnIndex: _fnVisibleToColumnIndex,
  13490. _fnColumnIndexToVisible: _fnColumnIndexToVisible,
  13491. _fnVisbleColumns: _fnVisbleColumns,
  13492. _fnGetColumns: _fnGetColumns,
  13493. _fnColumnTypes: _fnColumnTypes,
  13494. _fnApplyColumnDefs: _fnApplyColumnDefs,
  13495. _fnHungarianMap: _fnHungarianMap,
  13496. _fnCamelToHungarian: _fnCamelToHungarian,
  13497. _fnLanguageCompat: _fnLanguageCompat,
  13498. _fnBrowserDetect: _fnBrowserDetect,
  13499. _fnAddData: _fnAddData,
  13500. _fnAddTr: _fnAddTr,
  13501. _fnNodeToDataIndex: _fnNodeToDataIndex,
  13502. _fnNodeToColumnIndex: _fnNodeToColumnIndex,
  13503. _fnGetCellData: _fnGetCellData,
  13504. _fnSetCellData: _fnSetCellData,
  13505. _fnSplitObjNotation: _fnSplitObjNotation,
  13506. _fnGetObjectDataFn: _fnGetObjectDataFn,
  13507. _fnSetObjectDataFn: _fnSetObjectDataFn,
  13508. _fnGetDataMaster: _fnGetDataMaster,
  13509. _fnClearTable: _fnClearTable,
  13510. _fnDeleteIndex: _fnDeleteIndex,
  13511. _fnInvalidate: _fnInvalidate,
  13512. _fnGetRowElements: _fnGetRowElements,
  13513. _fnCreateTr: _fnCreateTr,
  13514. _fnBuildHead: _fnBuildHead,
  13515. _fnDrawHead: _fnDrawHead,
  13516. _fnDraw: _fnDraw,
  13517. _fnReDraw: _fnReDraw,
  13518. _fnAddOptionsHtml: _fnAddOptionsHtml,
  13519. _fnDetectHeader: _fnDetectHeader,
  13520. _fnGetUniqueThs: _fnGetUniqueThs,
  13521. _fnFeatureHtmlFilter: _fnFeatureHtmlFilter,
  13522. _fnFilterComplete: _fnFilterComplete,
  13523. _fnFilterCustom: _fnFilterCustom,
  13524. _fnFilterColumn: _fnFilterColumn,
  13525. _fnFilter: _fnFilter,
  13526. _fnFilterCreateSearch: _fnFilterCreateSearch,
  13527. _fnEscapeRegex: _fnEscapeRegex,
  13528. _fnFilterData: _fnFilterData,
  13529. _fnFeatureHtmlInfo: _fnFeatureHtmlInfo,
  13530. _fnUpdateInfo: _fnUpdateInfo,
  13531. _fnInfoMacros: _fnInfoMacros,
  13532. _fnInitialise: _fnInitialise,
  13533. _fnInitComplete: _fnInitComplete,
  13534. _fnLengthChange: _fnLengthChange,
  13535. _fnFeatureHtmlLength: _fnFeatureHtmlLength,
  13536. _fnFeatureHtmlPaginate: _fnFeatureHtmlPaginate,
  13537. _fnPageChange: _fnPageChange,
  13538. _fnFeatureHtmlProcessing: _fnFeatureHtmlProcessing,
  13539. _fnProcessingDisplay: _fnProcessingDisplay,
  13540. _fnFeatureHtmlTable: _fnFeatureHtmlTable,
  13541. _fnScrollDraw: _fnScrollDraw,
  13542. _fnApplyToChildren: _fnApplyToChildren,
  13543. _fnCalculateColumnWidths: _fnCalculateColumnWidths,
  13544. _fnThrottle: _fnThrottle,
  13545. _fnConvertToWidth: _fnConvertToWidth,
  13546. _fnGetWidestNode: _fnGetWidestNode,
  13547. _fnGetMaxLenString: _fnGetMaxLenString,
  13548. _fnStringToCss: _fnStringToCss,
  13549. _fnSortFlatten: _fnSortFlatten,
  13550. _fnSort: _fnSort,
  13551. _fnSortAria: _fnSortAria,
  13552. _fnSortListener: _fnSortListener,
  13553. _fnSortAttachListener: _fnSortAttachListener,
  13554. _fnSortingClasses: _fnSortingClasses,
  13555. _fnSortData: _fnSortData,
  13556. _fnSaveState: _fnSaveState,
  13557. _fnLoadState: _fnLoadState,
  13558. _fnImplementState: _fnImplementState,
  13559. _fnSettingsFromNode: _fnSettingsFromNode,
  13560. _fnLog: _fnLog,
  13561. _fnMap: _fnMap,
  13562. _fnBindAction: _fnBindAction,
  13563. _fnCallbackReg: _fnCallbackReg,
  13564. _fnCallbackFire: _fnCallbackFire,
  13565. _fnLengthOverflow: _fnLengthOverflow,
  13566. _fnRenderer: _fnRenderer,
  13567. _fnDataSource: _fnDataSource,
  13568. _fnRowAttributes: _fnRowAttributes,
  13569. _fnExtend: _fnExtend,
  13570. _fnCalculateEnd: function () {} // Used by a lot of plug-ins, but redundant
  13571. // in 1.10, so this dead-end function is
  13572. // added to prevent errors
  13573. } );
  13574. // jQuery access
  13575. $.fn.dataTable = DataTable;
  13576. // Provide access to the host jQuery object (circular reference)
  13577. DataTable.$ = $;
  13578. // Legacy aliases
  13579. $.fn.dataTableSettings = DataTable.settings;
  13580. $.fn.dataTableExt = DataTable.ext;
  13581. // With a capital `D` we return a DataTables API instance rather than a
  13582. // jQuery object
  13583. $.fn.DataTable = function ( opts ) {
  13584. return $(this).dataTable( opts ).api();
  13585. };
  13586. // All properties that are available to $.fn.dataTable should also be
  13587. // available on $.fn.DataTable
  13588. $.each( DataTable, function ( prop, val ) {
  13589. $.fn.DataTable[ prop ] = val;
  13590. } );
  13591. export default DataTable;